@pie-element/shared-math-rendering-mathjax 0.1.4-next.20261007175429 → 0.1.4-next.20261007201108

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
@@ -133,75 +133,75 @@ function ae(e, t) {
133
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
134
  })) : (_("untypeset"), Promise.resolve(!1));
135
135
  }
136
- var oe = globalThis, b = "PIE-MJX-CHTML-styles", se = ["MJX-CHTML-styles", "MJX-SVG-styles"], ce = re, x = "http://www.w3.org/1998/Math/MathML", le = /^([a-z_][\w.-]*):math$/, ue = /^[a-z][a-z0-9-]*$/;
137
- function de(e) {
136
+ var oe = globalThis, b = "PIE-MJX-CHTML-styles", se = ["MJX-CHTML-styles", "MJX-SVG-styles"], ce = re, le = "http://www.w3.org/1998/Math/MathML", ue = /^([a-z_][\w.-]*):math$/, de = /^[a-z][a-z0-9-]*$/;
137
+ function fe(e) {
138
138
  for (let t of e.querySelectorAll("*")) {
139
- let n = le.exec(t.tagName.toLowerCase())?.[1];
140
- !n || !e.contains(t) || t.closest("mjx-container") || t.replaceWith(S(t, `${n}:`));
139
+ let n = ue.exec(t.tagName.toLowerCase())?.[1];
140
+ !n || !e.contains(t) || t.closest("mjx-container") || t.replaceWith(pe(t, `${n}:`));
141
141
  }
142
142
  }
143
- function S(e, t) {
143
+ function pe(e, t) {
144
144
  let n = e.tagName.toLowerCase().slice(t.length);
145
- if (!ue.test(n)) return e;
146
- let r = e.ownerDocument.createElementNS(x, n);
145
+ if (!de.test(n)) return e;
146
+ let r = e.ownerDocument.createElementNS(le, n);
147
147
  for (let t of e.attributes) r.setAttribute(t.name, t.value);
148
148
  for (let n of [...e.childNodes]) {
149
149
  let e = n instanceof Element && n.tagName.toLowerCase().startsWith(t);
150
- r.appendChild(e ? S(n, t) : n);
150
+ r.appendChild(e ? pe(n, t) : n);
151
151
  }
152
152
  return r;
153
153
  }
154
154
  //#endregion
155
155
  //#region src/elementary-math.ts
156
- var fe = /* @__PURE__ */ new Set([
156
+ var me = /* @__PURE__ */ new Set([
157
157
  "updiagonalstrike",
158
158
  "downdiagonalstrike",
159
159
  "verticalstrike",
160
160
  "horizontalstrike"
161
- ]), pe = {
161
+ ]), he = {
162
162
  thin: "0.035em",
163
163
  medium: "0.07em",
164
164
  thick: "0.14em"
165
- }, me = {
165
+ }, ge = {
166
166
  tight: "0em",
167
167
  medium: "0.1em",
168
168
  loose: "0.2em"
169
- }, he = /^(\d+(\.\d*)?|\.\d+)(em|ex|px|pt|pc|in|cm|mm)$/, ge = /^(#[0-9a-f]{3,8}|[a-z]+)$/i, _e = /^(\d+(\.\d*)?|\.\d+)$/, ve = /* @__PURE__ */ new Set([
169
+ }, _e = /^(\d+(\.\d*)?|\.\d+)(em|ex|px|pt|pc|in|cm|mm)$/, ve = /^(#[0-9a-f]{3,8}|[a-z]+)$/i, ye = /^(\d+(\.\d*)?|\.\d+)$/, be = /* @__PURE__ */ new Set([
170
170
  "mn",
171
171
  "mo",
172
172
  "mi",
173
173
  "mtext"
174
- ]), ye = /* @__PURE__ */ new Set([
174
+ ]), xe = /* @__PURE__ */ new Set([
175
175
  "stackalign",
176
176
  "charalign",
177
177
  "charspacing",
178
178
  "longdivstyle"
179
179
  ]);
180
- function C(e, t, n = [], r = {}) {
181
- let i = e.createElementNS(x, t);
180
+ function x(e, t, n = [], r = {}) {
181
+ let i = e.createElementNS(le, t);
182
182
  for (let [e, t] of Object.entries(r)) i.setAttribute(e, t);
183
183
  for (let e of n) e && i.appendChild(e);
184
184
  return i;
185
185
  }
186
- function w(e, t) {
187
- let n = C(e.document, "mo");
186
+ function S(e, t) {
187
+ let n = x(e.document, "mo");
188
188
  return n.textContent = t, n;
189
189
  }
190
- function be(e) {
191
- let t = C(e.document, "mn");
192
- return t.textContent = "0", C(e.document, "mphantom", [t]);
190
+ function Se(e) {
191
+ let t = x(e.document, "mn");
192
+ return t.textContent = "0", x(e.document, "mphantom", [t]);
193
193
  }
194
- function T(e, t) {
194
+ function C(e, t) {
195
195
  return e.getAttribute(t)?.trim().toLowerCase() || void 0;
196
196
  }
197
- function E(e, t) {
197
+ function w(e, t) {
198
198
  let n = Number.parseInt(e.getAttribute(t) ?? "", 10);
199
199
  return Number.isFinite(n) ? n : 0;
200
200
  }
201
- function D(e) {
201
+ function T(e) {
202
202
  return e.localName === "none" || e.localName === "mrow" && e.children.length === 0 && !e.textContent?.trim();
203
203
  }
204
- function O(e, t, n = e) {
204
+ function E(e, t, n = e) {
205
205
  switch (t) {
206
206
  case "left": return 0;
207
207
  case "center": return Math.floor(e / 2);
@@ -209,14 +209,14 @@ function O(e, t, n = e) {
209
209
  default: return n;
210
210
  }
211
211
  }
212
- function k(e, t, n) {
212
+ function D(e, t, n) {
213
213
  let r = [], i, a, o = (e, t) => {
214
214
  let s = (e) => t.reduceRight((e, t) => {
215
215
  let n = t.cloneNode(!1);
216
216
  return n.appendChild(e), n;
217
217
  }, e);
218
218
  if (e.localName === "mstyle") for (let n of [...e.children]) o(n, [...t, e]);
219
- else if (D(e)) r.push(null);
219
+ else if (T(e)) r.push(null);
220
220
  else if (e.localName === "mn" && e.children.length === 0) {
221
221
  let t = [...(e.textContent ?? "").trim()];
222
222
  for (let a of t) {
@@ -225,28 +225,28 @@ function k(e, t, n) {
225
225
  t.textContent = a, r.push(s(t));
226
226
  }
227
227
  t.length && (a ??= r.length);
228
- } else ve.has(e.localName) && e.textContent?.trim() === n.decimalPoint && (i ??= r.length), r.push(s(e));
228
+ } else be.has(e.localName) && e.textContent?.trim() === n.decimalPoint && (i ??= r.length), r.push(s(e));
229
229
  };
230
230
  for (let t of e) o(t, []);
231
231
  return {
232
232
  kind: "digits",
233
233
  cells: r,
234
- anchor: O(r.length, n.stackAlign, i ?? a),
234
+ anchor: E(r.length, n.stackAlign, i ?? a),
235
235
  position: t
236
236
  };
237
237
  }
238
- function xe(e) {
239
- return (e ?? "").toLowerCase().split(/\s+/).filter((e) => fe.has(e));
238
+ function O(e) {
239
+ return (e ?? "").toLowerCase().split(/\s+/).filter((e) => me.has(e));
240
240
  }
241
- function Se(e, t) {
242
- let n = [...e.children].filter((e) => !D(e));
243
- return n.length <= 1 ? n[0] ?? null : C(t.document, "mrow", n);
241
+ function Ce(e, t) {
242
+ let n = [...e.children].filter((e) => !T(e));
243
+ return n.length <= 1 ? n[0] ?? null : x(t.document, "mrow", n);
244
244
  }
245
- function Ce(e, t, n) {
246
- let r = T(e, "location") ?? "n", i = xe(e.getAttribute("crossout")), a = [...e.children].map((e) => D(e) ? null : e.localName === "mscarry" ? {
247
- content: Se(e, n),
248
- location: T(e, "location") ?? r,
249
- crossout: e.hasAttribute("crossout") ? xe(e.getAttribute("crossout")) : i
245
+ function we(e, t, n) {
246
+ let r = C(e, "location") ?? "n", i = O(e.getAttribute("crossout")), a = [...e.children].map((e) => T(e) ? null : e.localName === "mscarry" ? {
247
+ content: Ce(e, n),
248
+ location: C(e, "location") ?? r,
249
+ crossout: e.hasAttribute("crossout") ? O(e.getAttribute("crossout")) : i
250
250
  } : {
251
251
  content: e,
252
252
  location: r,
@@ -255,60 +255,60 @@ function Ce(e, t, n) {
255
255
  return {
256
256
  kind: "carries",
257
257
  carries: a,
258
- anchor: O(a.length, n.stackAlign),
258
+ anchor: E(a.length, n.stackAlign),
259
259
  position: t,
260
- scale: _e.test(o) ? o : "0.6"
260
+ scale: ye.test(o) ? o : "0.6"
261
261
  };
262
262
  }
263
- function we(e) {
264
- let t = T(e, "mslinethickness") ?? "medium", n = pe[t] ?? (he.test(t) ? t : "0.07em"), r = e.getAttribute("mathcolor")?.trim() ?? "";
265
- return `${n} solid ${ge.test(r) ? r : "currentColor"}`;
263
+ function k(e) {
264
+ let t = C(e, "mslinethickness") ?? "medium", n = he[t] ?? (_e.test(t) ? t : "0.07em"), r = e.getAttribute("mathcolor")?.trim() ?? "";
265
+ return `${n} solid ${ve.test(r) ? r : "currentColor"}`;
266
266
  }
267
267
  function Te(e, t, n) {
268
- let r = Math.max(0, E(e, "length"));
268
+ let r = Math.max(0, w(e, "length"));
269
269
  return {
270
270
  kind: "line",
271
271
  length: r,
272
- anchor: O(r, n.stackAlign),
272
+ anchor: E(r, n.stackAlign),
273
273
  position: t,
274
- border: we(e)
274
+ border: k(e)
275
275
  };
276
276
  }
277
277
  function A(e, t, n, r, i) {
278
278
  e.forEach((e, a) => {
279
- let o = t + a * n + E(e, "position");
279
+ let o = t + a * n + w(e, "position");
280
280
  switch (e.localName) {
281
281
  case "msgroup":
282
- A([...e.children], o, E(e, "shift"), r, i);
282
+ A([...e.children], o, w(e, "shift"), r, i);
283
283
  break;
284
284
  case "msline":
285
285
  i.push(Te(e, o, r));
286
286
  break;
287
287
  case "mscarries":
288
- i.push(Ce(e, o, r));
288
+ i.push(we(e, o, r));
289
289
  break;
290
290
  case "msrow":
291
291
  case "mrow":
292
- i.push(k([...e.children], o, r));
292
+ i.push(D([...e.children], o, r));
293
293
  break;
294
- default: i.push(k([e], o, r));
294
+ default: i.push(D([e], o, r));
295
295
  }
296
296
  });
297
297
  }
298
298
  function j(e) {
299
299
  return -e.anchor - e.position;
300
300
  }
301
- function Ee(e) {
301
+ function M(e) {
302
302
  return e.kind === "digits" ? e.cells.length : e.kind === "carries" ? e.carries.length : e.length;
303
303
  }
304
- function De(e) {
305
- return j(e) + Ee(e) - 1;
304
+ function N(e) {
305
+ return j(e) + M(e) - 1;
306
306
  }
307
- function Oe(e, t, n, r) {
308
- let i = (e) => C(r.document, "mpadded", [t], {
307
+ function Ee(e, t, n, r) {
308
+ let i = (e) => x(r.document, "mpadded", [t], {
309
309
  width: "0",
310
310
  ...e ? { lspace: e } : {}
311
- }), a = (e, t) => C(r.document, e, t);
311
+ }), a = (e, t) => x(r.document, e, t);
312
312
  switch (n) {
313
313
  case "s": return a("munder", [e, i("-0.5width")]);
314
314
  case "ne": return a("msup", [e, i()]);
@@ -330,41 +330,41 @@ function Oe(e, t, n, r) {
330
330
  default: return a("mover", [e, i("-0.5width")]);
331
331
  }
332
332
  }
333
- function ke(e, t, n) {
334
- let r = C(n.document, "menclose", [e], {
333
+ function De(e, t, n) {
334
+ let r = x(n.document, "menclose", [e], {
335
335
  notation: t.join(" "),
336
336
  "data-padding": "0.1em",
337
337
  "data-thickness": "0.067em"
338
338
  }), i = t.some((e) => e.endsWith("diagonalstrike")) ? .167 : t.includes("horizontalstrike") ? .1 : 0;
339
- return i ? C(n.document, "mpadded", [r], {
339
+ return i ? x(n.document, "mpadded", [r], {
340
340
  lspace: `-${i}em`,
341
341
  width: `-${2 * i}em`
342
342
  }) : r;
343
343
  }
344
- function Ae(e, t, n, r, i) {
345
- let a = e && t.crossout.length ? ke(e, t.crossout, i) : e;
344
+ function Oe(e, t, n, r, i) {
345
+ let a = e && t.crossout.length ? De(e, t.crossout, i) : e;
346
346
  if (!t.content) return a;
347
- let o = C(i.document, "mstyle", [t.content], { scriptsizemultiplier: r });
348
- return Oe(a ?? be(i), o, n, i);
347
+ let o = x(i.document, "mstyle", [t.content], { scriptsizemultiplier: r });
348
+ return Ee(a ?? Se(i), o, n, i);
349
349
  }
350
- function je(e, t) {
350
+ function P(e, t) {
351
351
  return e.carries[t - j(e)] ?? null;
352
352
  }
353
- function Me(e, t, n, r) {
353
+ function ke(e, t, n, r) {
354
354
  let i = e.content;
355
355
  n.forEach((e, a) => {
356
- let o = n.length - 1 - a, s = n[o], c = je(s, t), l = n.slice(0, o).some((e) => je(e, t));
356
+ let o = n.length - 1 - a, s = n[o], c = P(s, t), l = n.slice(0, o).some((e) => P(e, t));
357
357
  if (!c && !l) return;
358
358
  let u = c ?? {
359
- content: be(r),
359
+ content: Se(r),
360
360
  location: "n",
361
361
  crossout: []
362
362
  }, d = a === 0 ? u.location : "n";
363
- i = Ae(i, u, d, s.scale, r);
363
+ i = Oe(i, u, d, s.scale, r);
364
364
  }), e.content = i;
365
365
  }
366
- function Ne(e, t) {
367
- let n = e.filter((e) => Ee(e) > 0), r = Math.min(0, ...n.map(j)), i = Math.max(r, ...n.map(De)) - r + 1, a = -r, o = [], s = /* @__PURE__ */ new Map(), c = () => Array.from({ length: i }, () => ({
366
+ function F(e, t) {
367
+ 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 }, () => ({
368
368
  content: null,
369
369
  borders: {}
370
370
  })), 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) => {
@@ -372,7 +372,7 @@ function Ne(e, t) {
372
372
  e.cells.forEach((t, r) => {
373
373
  n[a + j(e) + r].content = t;
374
374
  }), u.length && n.forEach((e, n) => {
375
- Me(e, n - a, u, t);
375
+ ke(e, n - a, u, t);
376
376
  });
377
377
  for (let e of d) for (let t of l(e)) n[t].borders.top = e.border;
378
378
  u = [], d = [], s.set(e, o.length), o.push(n);
@@ -392,43 +392,43 @@ function Ne(e, t) {
392
392
  origin: a
393
393
  };
394
394
  }
395
- function Pe(e, { rows: t }, n) {
396
- let r = C(n.document, "mtable", t.map((e) => C(n.document, "mtr", e.map((e) => {
395
+ function Ae(e, { rows: t }, n) {
396
+ let r = x(n.document, "mtable", t.map((e) => x(n.document, "mtr", e.map((e) => {
397
397
  let t = Object.entries(e.borders).map(([e, t]) => `border-${e}:${t}`).join(";");
398
- return C(n.document, "mtd", [e.content], {
398
+ return x(n.document, "mtd", [e.content], {
399
399
  ...t ? { style: t } : {},
400
400
  ...e.align ? { columnalign: e.align } : {}
401
401
  });
402
402
  }))));
403
- for (let { name: t, value: n } of [...e.attributes]) ye.has(t) || r.setAttribute(t, n);
404
- let i = T(e, "charspacing") ?? "medium", a = T(e, "charalign");
405
- return r.setAttribute("columnspacing", me[i] ?? (he.test(i) ? i : me.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]) xe.has(t) || r.setAttribute(t, n);
404
+ let i = C(e, "charspacing") ?? "medium", a = C(e, "charalign");
405
+ return r.setAttribute("columnspacing", ge[i] ?? (_e.test(i) ? i : ge.medium)), r.setAttribute("columnalign", a === "left" || a === "center" ? a : "right"), r.setAttribute("rowspacing", "0"), r.setAttribute("align", e.getAttribute("align") ?? "baseline"), r;
406
406
  }
407
- function Fe(e) {
407
+ function je(e) {
408
408
  return {
409
409
  document: e.ownerDocument,
410
- stackAlign: T(e, "stackalign") ?? "decimalpoint",
410
+ stackAlign: C(e, "stackalign") ?? "decimalpoint",
411
411
  decimalPoint: e.closest("[decimalpoint]")?.getAttribute("decimalpoint")?.trim().charAt(0) || "."
412
412
  };
413
413
  }
414
- function Ie(e) {
415
- let t = Fe(e), n = [];
416
- return A([...e.children], 0, 0, t, n), Pe(e, Ne(n, t), t);
414
+ function Me(e) {
415
+ let t = je(e), n = [];
416
+ return A([...e.children], 0, 0, t, n), Ae(e, F(n, t), t);
417
417
  }
418
- function M(e, t, n, r, i, a) {
418
+ function I(e, t, n, r, i, a) {
419
419
  for (let o = n; o <= r; o++) e[t][o].borders[i] = a;
420
420
  }
421
- function Le(e, t) {
422
- let n = w(t, ")");
423
- return n.setAttribute("minsize", "1.2em"), [C(t.document, "mrow", [e, C(t.document, "mspace", [], { width: "0.2em" })]), C(t.document, "mpadded", [n], {
421
+ function Ne(e, t) {
422
+ let n = S(t, ")");
423
+ return n.setAttribute("minsize", "1.2em"), [x(t.document, "mrow", [e, x(t.document, "mspace", [], { width: "0.2em" })]), x(t.document, "mpadded", [n], {
424
424
  voffset: "0.1em",
425
425
  lspace: "-0.15em",
426
426
  depth: "-0.2em",
427
427
  height: "-0.2em"
428
428
  })];
429
429
  }
430
- function Re(e) {
431
- let t = Fe(e), [n, r, ...i] = [...e.children], a = n && !D(n) ? n : null, o = r && !D(r) ? r : null, s = T(e, "longdivstyle") ?? "lefttop", c = we(e), l = [];
430
+ function Pe(e) {
431
+ let t = je(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 = [];
432
432
  A(i, 0, 0, t, l);
433
433
  let u = l.find((e) => e.kind === "digits");
434
434
  u || (u = {
@@ -441,51 +441,51 @@ function Re(e) {
441
441
  u.cells.unshift(...e), u.anchor += e.length;
442
442
  }, p = (...e) => {
443
443
  let n = e.flatMap((e) => e ? e.localName === "mrow" ? [...e.children] : [e] : []);
444
- u.cells.push(...k(n, 0, t).cells);
444
+ u.cells.push(...D(n, 0, t).cells);
445
445
  };
446
446
  switch (s) {
447
447
  case "left/\\right":
448
- f(a, w(t, "/")), p(w(t, "\\"), o);
448
+ f(a, S(t, "/")), p(S(t, "\\"), o);
449
449
  break;
450
450
  case "left)(right":
451
- f(a, w(t, ")")), p(w(t, "("), o);
451
+ f(a, S(t, ")")), p(S(t, "("), o);
452
452
  break;
453
453
  case ":right=right":
454
- p(w(t, ":"), a, w(t, "="), o);
454
+ p(S(t, ":"), a, S(t, "="), o);
455
455
  break;
456
456
  case "righttop":
457
457
  case "stackedleftlinetop":
458
458
  case "lefttop":
459
- o && A([o], 0, 0, t, d), l.splice(l.indexOf(u), 0, ...d), s === "righttop" ? p(a) : s === "stackedleftlinetop" ? f(a) : f(...Le(a, t));
459
+ o && A([o], 0, 0, t, d), l.splice(l.indexOf(u), 0, ...d), s === "righttop" ? p(a) : s === "stackedleftlinetop" ? f(a) : f(...Ne(a, t));
460
460
  break;
461
461
  }
462
- let m = Ne(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 + De(e)));
462
+ 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)));
463
463
  switch (s) {
464
464
  case "left/\\right":
465
465
  case "left)(right":
466
466
  case ":right=right": break;
467
467
  case "righttop": {
468
468
  let e = h[g][_(u.cells.length - 1)];
469
- e.borders.left = c, e.borders.bottom = c, M(h, g, _(0), _(u.cells.length - 1), "top", c);
469
+ e.borders.left = c, e.borders.bottom = c, I(h, g, _(0), _(u.cells.length - 1), "top", c);
470
470
  break;
471
471
  }
472
472
  case "stackedleftlinetop": {
473
473
  let e = h[g][_(0)];
474
- e.borders.right = c, e.borders.bottom = c, M(h, g, _(1), v, "top", c);
474
+ e.borders.right = c, e.borders.bottom = c, I(h, g, _(1), v, "top", c);
475
475
  break;
476
476
  }
477
477
  case "stackedrightright":
478
478
  case "mediumstackedrightright":
479
479
  case "shortstackedrightright":
480
480
  case "stackedleftleft":
481
- ze(h, g, s, a, o, c, t);
481
+ Fe(h, g, s, a, o, c, t);
482
482
  break;
483
- default: M(h, g, _(1), v, "top", c);
483
+ default: I(h, g, _(1), v, "top", c);
484
484
  }
485
- return Pe(e, m, t);
485
+ return Ae(e, m, t);
486
486
  }
487
- function ze(e, t, n, r, i, a, o) {
488
- let s = n === "stackedleftleft", c = s ? "right" : "left", l = (e) => e && C(o.document, "mpadded", [e], {
487
+ function Fe(e, t, n, r, i, a, o) {
488
+ let s = n === "stackedleftleft", c = s ? "right" : "left", l = (e) => e && x(o.document, "mpadded", [e], {
489
489
  lspace: "0.2em",
490
490
  width: "+0.4em"
491
491
  });
@@ -504,312 +504,81 @@ function ze(e, t, n, r, i, a, o) {
504
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);
505
505
  });
506
506
  }
507
- function Be(e) {
508
- for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? Ie(t) : Re(t));
507
+ function Ie(e) {
508
+ for (let t of [...e.querySelectorAll("mstack, mlongdiv")]) !t.closest("math") || t.closest("mjx-container") || t.replaceWith(t.localName === "mstack" ? Me(t) : Pe(t));
509
509
  }
510
510
  //#endregion
511
511
  //#region src/explorer-styles.ts
512
- var Ve = "PIE-MJX-explorer-styles", N = "var(--pie-text, black)", He = "var(--pie-background, #ffffff)", Ue = "var(--pie-border-dark, #66686A)", P = "var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0)))", F = `color-mix(in srgb, ${P} 15%, transparent)`, We = `
512
+ var Le = "PIE-MJX-explorer-styles", L = "var(--pie-text, black)", Re = "var(--pie-background, #ffffff)", ze = "var(--pie-border-dark, #66686A)", R = "var(--pie-focus-outline, var(--pie-button-focus-outline, var(--pie-focus-checked-border, #1565C0)))", z = `color-mix(in srgb, ${R} 15%, transparent)`, Be = `
513
513
  :root mjx-container [data-sre-highlight-1]:not([data-mjx-collapsed], rect) {
514
- color: ${N} !important;
515
- fill: ${N} !important;
514
+ color: ${L} !important;
515
+ fill: ${L} !important;
516
516
  }
517
517
  :root mjx-container:not([data-mjx-clone-container]) [data-sre-highlight-1]:not([data-sre-enclosed], rect) {
518
- background-color: ${F} !important;
518
+ background-color: ${z} !important;
519
519
  }
520
520
  :root mjx-container rect[data-sre-highlight-1]:not([data-sre-enclosed]) {
521
- fill: ${F} !important;
521
+ fill: ${z} !important;
522
522
  }
523
523
  :root mjx-container .mjx-selected {
524
- outline: 2px solid ${P} !important;
524
+ outline: 2px solid ${R} !important;
525
525
  }
526
526
  :root mjx-container [data-sre-highlight-2] {
527
- color: ${N} !important;
527
+ color: ${L} !important;
528
528
  background-color: transparent !important;
529
- fill: ${N} !important;
530
- outline: 2px dashed ${P} !important;
529
+ fill: ${L} !important;
530
+ outline: 2px dashed ${R} !important;
531
531
  }
532
532
  :root mjx-container rect[data-sre-highlight-2] {
533
533
  fill: transparent !important;
534
- stroke: ${P} !important;
534
+ stroke: ${R} !important;
535
535
  stroke-width: 2px !important;
536
536
  vector-effect: non-scaling-stroke;
537
537
  }
538
538
  :root .MJX_LiveRegion, :root .MJX_HoverRegion, :root .MJX_ToolTip {
539
- color: ${N} !important;
540
- background-color: ${He} !important;
541
- border-color: ${Ue} !important;
539
+ color: ${L} !important;
540
+ background-color: ${Re} !important;
541
+ border-color: ${ze} !important;
542
542
  }
543
543
  :root .MJX_LiveRegion > div, :root .MJX_HoverRegion > div {
544
- color: ${N} !important;
545
- background-color: ${F} !important;
544
+ color: ${L} !important;
545
+ background-color: ${z} !important;
546
546
  }
547
547
  `;
548
- function Ge(e = document) {
548
+ function Ve(e = document) {
549
549
  if (e.getElementById("PIE-MJX-explorer-styles")) return;
550
550
  let t = e.createElement("style");
551
- t.id = Ve, t.textContent = We, e.head.appendChild(t);
552
- }
553
- //#endregion
554
- //#region src/speech-worker.ts
555
- var I = Symbol.for("@pie-element/shared-math-rendering-mathjax/speech-worker-failed");
556
- function Ke() {
557
- let e = globalThis;
558
- e[I] || (e[I] = !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 qe(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(), Ke();
566
- }
567
- function Je(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", () => qe(e), { once: !0 }), a;
572
- });
573
- }
574
- `${i}`;
575
- //#endregion
576
- //#region src/adapter.ts
577
- var Ye = {
578
- parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
579
- overarc: "\\overparen",
580
- napprox: "\\not\\approx",
581
- longdiv: "\\enclose{longdiv}",
582
- abs: ["\\left|#1\\right|", 1]
583
- }, Xe = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", Ze = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, Qe = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, $e = /\\embed\{newLine\}\[\]/g, et = [
584
- ["$$", "$$"],
585
- ["$", "$"],
586
- ["\\[", "\\]"],
587
- ["\\(", "\\)"]
588
- ], L = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), tt = "MJX-CHTML-styles", nt = "PIE-MJX-SVG-styles", R = "PIE-MathJax-Menu-Settings", rt = { "mjx-container[overflow=\"linebreak\"][display]": {
589
- overflow: "auto clip",
590
- "min-width": "initial !important"
591
- } }, it = 200, at = 201;
592
- function z(e) {
593
- let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
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");
595
- }
596
- function B(e) {
597
- for (let [t, n] of et) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
598
- return e;
599
- }
600
- function ot(e) {
601
- return B(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
602
- }
603
- var st = "mathjax_ignore", V = "mathjax_process";
604
- function ct(e, t) {
605
- let n = e.closest(`.${st}, .${V}`);
606
- return n !== null && t.contains(n) && !n.classList.contains(V);
607
- }
608
- function lt(e) {
609
- for (let t of e.querySelectorAll("[data-latex]")) {
610
- if (t.dataset.mathHandled || t.closest("mjx-container") || ct(t, e)) continue;
611
- let n = t.textContent;
612
- n && (t.textContent = `\\(${ot(n)}\\)`.replace($e, "\\newline "), t.dataset.mathHandled = "true");
613
- }
614
- }
615
- function ut(e) {
616
- for (let t of e.querySelectorAll("math")) t.closest("mjx-container") || t.setAttribute("displaystyle", "true");
617
- }
618
- function dt(e, t) {
619
- for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
620
- return (t ? Qe : Ze).test(e.textContent ?? "");
621
- }
622
- function ft(e) {
623
- return new Promise((t, n) => {
624
- let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = e, s = d(e, import.meta.url), c = {
625
- loader: {
626
- load: i ? ["a11y/assistive-mml"] : [],
627
- failed: (e) => n(e),
628
- "output/svg": { ready: (e) => {
629
- let t = y();
630
- return pt(t) && mt(t), e;
631
- } }
632
- },
633
- startup: {
634
- typeset: !1,
635
- ready: () => {
636
- let e = y(), r = e?.startup, i = pt(e);
637
- i && (mt(e), ht(e, s.speechLocales), f(e?._?.a11y?.sre_ts?.locales, s.speechLocales)), r?.defaultReady?.(), i && (gt(r?.document), r?.document?.addStyles?.(rt), Je(r?.document)), Promise.resolve(r?.promise).then(() => t(), n);
638
- }
639
- },
640
- tex: { macros: { ...Ye } },
641
- output: { displayOverflow: "linebreak" },
642
- options: {
643
- enableMenu: i,
644
- menuOptions: { settings: {
645
- assistiveMml: i,
646
- enrich: !1,
647
- inTabOrder: !1
648
- } },
649
- a11y: { inTabOrder: !1 }
650
- }
651
- };
652
- r && c.tex && (console.warn(Xe), 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 }), ae(c, {
655
- ...s,
656
- srcUrl: o
657
- }).then((e) => {
658
- e || t();
659
- }, n);
660
- });
661
- }
662
- function pt(e) {
663
- return !!e?.version?.startsWith("4.");
664
- }
665
- function mt(e) {
666
- let t = e?._?.output, n = t?.chtml_ts?.CHTML;
667
- n && (n.STYLESHEETID = b);
668
- let r = t?.svg_ts?.SVG;
669
- r && (r.STYLESHEETID = nt);
670
- }
671
- function ht(e, t) {
672
- let n = e?._?.ui?.menu?.Menu?.Menu;
673
- if (n) {
674
- n.MENU_STORAGE = R;
675
- try {
676
- let e = localStorage.getItem(R);
677
- if (!e) return;
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(R, JSON.stringify(i)) : localStorage.removeItem(R);
681
- } catch {}
682
- }
683
- }
684
- function gt(e) {
685
- if (!e) return;
686
- let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
687
- let n = e.typesetRoot;
688
- !n || t.has(n) || (z(n), t.add(n));
689
- };
690
- e.addRenderAction?.("pie-strip-latex", at, (e) => {
691
- for (let t of e.math ?? []) n(t);
692
- return !1;
693
- }, (e) => {
694
- let t = e.typesetRoot;
695
- return t && z(t), !1;
696
- });
697
- let r = e.outputJax?.chtmlStyles;
698
- r?.id === tt && (r.id = b), yt();
699
- }
700
- function _t(e) {
701
- return e instanceof HTMLStyleElement && se.includes(e.id);
702
- }
703
- function vt(e) {
704
- ne("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
705
- }
706
- function yt() {
707
- let e = document.head, t = [...e.children].find(_t);
708
- if (t) {
709
- vt(t);
710
- return;
711
- }
712
- let n = new MutationObserver((e) => {
713
- for (let t of e) {
714
- let e = [...t.addedNodes].find(_t);
715
- if (e) {
716
- vt(e), n.disconnect();
717
- return;
718
- }
719
- }
720
- });
721
- n.observe(e, { childList: !0 });
722
- }
723
- function bt(e) {
724
- let t = e?.math;
725
- if (!t?.remove) return;
726
- let n = [...t].filter((e) => (e.state?.() ?? 0) >= it && e.typesetRoot?.isConnected === !1);
727
- if (n.length !== 0) {
728
- for (let e of [...n].reverse()) e.clear?.();
729
- t.remove(...n);
730
- }
731
- }
732
- function xt(e) {
733
- return new Promise((t, n) => {
734
- let r = e.startup ?? {};
735
- e.startup = r;
736
- let i = r.ready;
737
- r.ready = () => {
738
- let e = y()?.startup;
739
- i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
740
- };
741
- });
742
- }
743
- function St(e) {
744
- let t = y();
745
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : xt(t) : ft(e);
746
- }
747
- function Ct(e) {
748
- return St(e).then(() => {
749
- let e = y();
750
- e && typeof e.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
751
- });
752
- }
753
- function wt(e) {
754
- let t = oe, n = t[L];
755
- return n || (n = Ct(e), t[L] = n), n;
756
- }
757
- function Tt(e = {}) {
758
- let t = e.useSingleDollar ?? !1;
759
- return async (n) => {
760
- if (typeof window > "u") return;
761
- let r = ce();
762
- r && ne("mathjax-3-global", `window.MathJax is MathJax ${r}`), lt(n), de(n), ut(n), Be(n);
763
- let i = wt(e);
764
- if (!dt(n, t)) {
765
- i.catch(() => {});
766
- return;
767
- }
768
- await i;
769
- let a = y();
770
- if (await a?.startup?.promise, typeof a?.typesetPromise == "function") {
771
- Ge(), bt(a.startup?.document);
772
- try {
773
- await a.typesetPromise([n]);
774
- } catch (e) {
775
- throw a.typesetClear?.([n]), e;
776
- }
777
- z(n);
778
- }
779
- };
780
- }
781
- function Et() {
782
- return [];
551
+ t.id = Le, t.textContent = Be, e.head.appendChild(t);
783
552
  }
784
553
  //#endregion
785
554
  //#region src/math-speech.ts
786
- var Dt = /[⁡-⁤]/g, Ot = {
555
+ var He = /[⁡-⁤]/g, Ue = {
787
556
  "+": "positive",
788
557
  "-": "negative",
789
558
  "−": "negative",
790
559
  "±": "plus or minus",
791
560
  "∓": "minus or plus"
792
- }, kt = {
561
+ }, We = {
793
562
  "(": "open parenthesis",
794
563
  "[": "open bracket",
795
564
  "{": "open brace",
796
565
  "⟨": "open angle bracket",
797
566
  "⌊": "open floor",
798
567
  "⌈": "open ceiling"
799
- }, At = {
568
+ }, Ge = {
800
569
  ")": "close parenthesis",
801
570
  "]": "close bracket",
802
571
  "}": "close brace",
803
572
  "⟩": "close angle bracket",
804
573
  "⌋": "close floor",
805
574
  "⌉": "close ceiling"
806
- }, H = {
575
+ }, B = {
807
576
  "!": "factorial",
808
577
  "%": "percent",
809
578
  "°": "degrees",
810
579
  "′": "prime",
811
580
  "″": "double prime"
812
- }, jt = {
581
+ }, Ke = {
813
582
  "+": "plus",
814
583
  "-": "minus",
815
584
  "−": "minus",
@@ -853,16 +622,16 @@ var Dt = /[⁡-⁤]/g, Ot = {
853
622
  ":": "colon",
854
623
  "|": "vertical bar",
855
624
  "‖": "double vertical bar",
856
- ...kt,
857
- ...At,
858
- ...H
859
- }, Mt = /* @__PURE__ */ new Set(["|", "‖"]), Nt = /* @__PURE__ */ new Set([
625
+ ...We,
626
+ ...Ge,
627
+ ...B
628
+ }, qe = /* @__PURE__ */ new Set(["|", "‖"]), Je = /* @__PURE__ */ new Set([
860
629
  "∑",
861
630
  "∏",
862
631
  "∫",
863
632
  "∪",
864
633
  "∩"
865
- ]), Pt = {
634
+ ]), Ye = {
866
635
  α: "alpha",
867
636
  β: "beta",
868
637
  γ: "gamma",
@@ -889,7 +658,7 @@ var Dt = /[⁡-⁤]/g, Ot = {
889
658
  cot: "cotangent",
890
659
  ln: "natural log",
891
660
  lim: "limit"
892
- }, Ft = {
661
+ }, Xe = {
893
662
  "¯": "bar",
894
663
  "‾": "bar",
895
664
  "―": "bar",
@@ -900,211 +669,441 @@ var Dt = /[⁡-⁤]/g, Ot = {
900
669
  "→": "vector",
901
670
  "⃗": "vector",
902
671
  "˙": "dot"
903
- }, It = {
904
- 2: ["half", "halves"],
905
- 3: ["third", "thirds"],
906
- 4: ["quarter", "quarters"],
907
- 5: ["fifth", "fifths"],
908
- 6: ["sixth", "sixths"],
909
- 7: ["seventh", "sevenths"],
910
- 8: ["eighth", "eighths"],
911
- 9: ["ninth", "ninths"],
912
- 10: ["tenth", "tenths"]
913
- }, U = (e) => (e.textContent ?? "").replace(Dt, "").replace(/\s+/g, " ").trim(), W = (e) => e.replace(/\s+/g, " ").trim(), G = (e) => [...e.children];
914
- function K(e) {
672
+ }, V = (e) => (e.textContent ?? "").replace(He, "").replace(/\s+/g, " ").trim(), H = (e) => e.replace(/\s+/g, " ").trim(), U = (e) => [...e.children];
673
+ function W(e) {
915
674
  return !e || [
916
675
  "mn",
917
676
  "mi",
918
677
  "mtext",
919
678
  "mo"
920
- ].includes(e.localName) ? !0 : ["mrow", "mstyle"].includes(e.localName) && e.children.length === 1 ? K(e.children[0]) : !1;
679
+ ].includes(e.localName) ? !0 : ["mrow", "mstyle"].includes(e.localName) && e.children.length === 1 ? W(e.children[0]) : !1;
921
680
  }
922
- function q(e) {
923
- let t = e ? U(e) : "";
681
+ function Ze(e) {
682
+ let t = e ? V(e) : "";
924
683
  return /^\d{1,3}$/.test(t) ? Number(t) : void 0;
925
684
  }
926
- function Lt(e) {
685
+ function Qe(e) {
927
686
  return `${e}${e % 100 >= 11 && e % 100 <= 13 ? "th" : {
928
687
  1: "st",
929
688
  2: "nd",
930
689
  3: "rd"
931
690
  }[e % 10] ?? "th"}`;
932
691
  }
933
- function Rt(e) {
934
- return Pt[e] ?? e;
692
+ function $e(e) {
693
+ return Ye[e] ?? e;
935
694
  }
936
- function J(e) {
937
- return jt[e] ?? e;
695
+ function G(e) {
696
+ return Ke[e] ?? e;
938
697
  }
939
- function Y(e) {
698
+ function K(e) {
940
699
  let t = [], n = !1;
941
700
  for (let r of e) {
942
701
  if (r.localName !== "mo") {
943
- t.push(X(r)), n = !0;
702
+ t.push(q(r)), n = !0;
944
703
  continue;
945
704
  }
946
- let e = U(r);
947
- e && (!n && Ot[e] ? t.push(Ot[e]) : e in H ? t.push(H[e]) : (t.push(J(e)), n = e in At || Mt.has(e) && n));
705
+ let e = V(r);
706
+ e && (!n && Ue[e] ? t.push(Ue[e]) : e in B ? t.push(B[e]) : (t.push(G(e)), n = e in Ge || qe.has(e) && n));
948
707
  }
949
708
  return t.filter(Boolean).join(" ");
950
709
  }
951
- function zt(e) {
952
- let [t, ...n] = e, r = n[n.length - 1], i = (e) => e?.localName === "mo" && ["|", "‖"].includes(U(e)), a = n.slice(0, -1);
953
- if (a.length && i(t) && i(r) && U(t) === U(r) && !a.some(i)) {
954
- let e = W(Y(a));
955
- return U(t) === "|" ? `absolute value of ${e} end absolute value` : `norm of ${e} end norm`;
710
+ function et(e) {
711
+ let [t, ...n] = e, r = n[n.length - 1], i = (e) => e?.localName === "mo" && ["|", "‖"].includes(V(e)), a = n.slice(0, -1);
712
+ if (a.length && i(t) && i(r) && V(t) === V(r) && !a.some(i)) {
713
+ let e = H(K(a));
714
+ return V(t) === "|" ? `absolute value of ${e} end absolute value` : `norm of ${e} end norm`;
956
715
  }
957
- return Y(e);
716
+ return K(e);
958
717
  }
959
- function Bt(e, t) {
960
- let n = q(e), r = q(t), i = r === void 0 ? void 0 : It[r];
961
- if (n !== void 0 && i) return `${n} ${n === 1 ? i[0] : i[1]}`;
962
- let a = e ? X(e) : "", o = t ? X(t) : "";
963
- return K(e) && K(t) ? `${a} over ${o}` : `the fraction with numerator ${a} and denominator ${o}`;
718
+ function tt(e, t) {
719
+ let n = e ? q(e) : "", r = t ? q(t) : "";
720
+ return W(e) && W(t) ? `${n} over ${r}` : `the fraction with numerator ${n} and denominator ${r}`;
964
721
  }
965
- function Vt(e, t, n) {
722
+ function nt(e, t, n) {
966
723
  return n ? `${t} of ${e}` : `${t} of ${e} end root`;
967
724
  }
968
- function Ht(e, t) {
969
- let n = t ? U(t) : "";
970
- if (t && K(t)) {
725
+ function rt(e, t) {
726
+ let n = t ? V(t) : "";
727
+ if (t && W(t)) {
971
728
  if (n === "2") return `${e} squared`;
972
729
  if (n === "3") return `${e} cubed`;
973
- if (n in H) return `${e} ${H[n]}`;
730
+ if (n in B) return `${e} ${B[n]}`;
974
731
  }
975
- let r = t ? X(t) : "";
976
- return K(t) ? `${e} to the power of ${r}` : `${e} to the power of ${r} end power`;
732
+ let r = t ? q(t) : "";
733
+ return W(t) ? `${e} to the power of ${r}` : `${e} to the power of ${r} end power`;
977
734
  }
978
- function Ut(e, t) {
979
- let n = t ? X(t) : "";
980
- return K(t) ? `${e} sub ${n}` : `${e} sub ${n} end sub`;
735
+ function it(e, t) {
736
+ let n = t ? q(t) : "";
737
+ return W(t) ? `${e} sub ${n}` : `${e} sub ${n} end sub`;
981
738
  }
982
- function Wt(e, t, n) {
983
- let r = U(e);
984
- if (r === "lim") return `limit as ${t ? X(t) : ""} of`;
985
- if (!Nt.has(r)) return;
986
- let i = t ? `from ${X(t)}` : "", a = n ? `to ${X(n)}` : "";
987
- return `${J(r)} ${i} ${a} of`;
739
+ function at(e, t, n) {
740
+ let r = V(e);
741
+ if (r === "lim") return `limit as ${t ? q(t) : ""} of`;
742
+ if (!Je.has(r)) return;
743
+ let i = t ? `from ${q(t)}` : "", a = n ? `to ${q(n)}` : "";
744
+ return `${G(r)} ${i} ${a} of`;
988
745
  }
989
- function Gt(e) {
990
- let t = G(e).filter((e) => ["mtr", "mlabeledtr"].includes(e.localName)), n = t.map((e) => G(e).filter((e) => e.localName === "mtd")), r = Math.max(0, ...n.map((e) => e.length)), i = n.map((e, t) => `row ${t + 1}: ${e.map((e) => W(Y(G(e)))).join(", ")}`);
746
+ function ot(e) {
747
+ let t = U(e).filter((e) => ["mtr", "mlabeledtr"].includes(e.localName)), n = t.map((e) => U(e).filter((e) => e.localName === "mtd")), r = Math.max(0, ...n.map((e) => e.length)), i = n.map((e, t) => `row ${t + 1}: ${e.map((e) => H(K(U(e)))).join(", ")}`);
991
748
  return `table with ${t.length} ${t.length === 1 ? "row" : "rows"} and ${r} ${r === 1 ? "column" : "columns"}. ${i.join(". ")}`;
992
749
  }
993
- function Kt(e) {
994
- let t = e.getAttribute("open") ?? "(", n = e.getAttribute("close") ?? ")", r = (e.getAttribute("separators") ?? ",").replace(/\s+/g, "").split(""), i = G(e).map((e, t, n) => t < n.length - 1 ? `${X(e)} ${J(r[Math.min(t, r.length - 1)] ?? ",")}` : X(e));
750
+ function st(e) {
751
+ let t = e.getAttribute("open") ?? "(", n = e.getAttribute("close") ?? ")", r = (e.getAttribute("separators") ?? ",").replace(/\s+/g, "").split(""), i = U(e).map((e, t, n) => t < n.length - 1 ? `${q(e)} ${G(r[Math.min(t, r.length - 1)] ?? ",")}` : q(e));
995
752
  return [
996
- J(t),
753
+ G(t),
997
754
  ...i,
998
- J(n)
755
+ G(n)
999
756
  ].filter(Boolean).join(" ");
1000
757
  }
1001
- function X(e) {
1002
- let t = G(e);
758
+ function q(e) {
759
+ let t = U(e);
1003
760
  switch (e.localName) {
1004
- case "mi": return Rt(U(e));
761
+ case "mi": return $e(V(e));
1005
762
  case "mn":
1006
763
  case "mtext":
1007
- case "ms": return U(e);
1008
- case "mo": return J(U(e));
764
+ case "ms": return V(e);
765
+ case "mo": return G(V(e));
1009
766
  case "mspace":
1010
767
  case "mphantom":
1011
768
  case "annotation":
1012
769
  case "annotation-xml": return "";
1013
- case "semantics": return t[0] ? X(t[0]) : "";
1014
- case "mfrac": return Bt(t[0], t[1]);
1015
- case "msqrt": return Vt(W(Y(t)), "square root", t.length === 1 && K(t[0]));
770
+ case "semantics": return t[0] ? q(t[0]) : "";
771
+ case "mfrac": return tt(t[0], t[1]);
772
+ case "msqrt": return nt(H(K(t)), "square root", t.length === 1 && W(t[0]));
1016
773
  case "mroot": {
1017
- let e = q(t[1]), n = e === 2 ? "square root" : e === 3 ? "cube root" : e ? `${Lt(e)} root` : `root with index ${t[1] ? X(t[1]) : ""}`;
1018
- return Vt(t[0] ? X(t[0]) : "", n, K(t[0]));
774
+ let e = Ze(t[1]), n = e === 2 ? "square root" : e === 3 ? "cube root" : e ? `${Qe(e)} root` : `root with index ${t[1] ? q(t[1]) : ""}`;
775
+ return nt(t[0] ? q(t[0]) : "", n, W(t[0]));
1019
776
  }
1020
- case "msup": return Ht(t[0] ? X(t[0]) : "", t[1]);
1021
- case "msub": return Ut(t[0] ? X(t[0]) : "", t[1]);
1022
- case "msubsup": return (t[0] ? Wt(t[0], t[1], t[2]) : void 0) || Ht(Ut(t[0] ? X(t[0]) : "", t[1]), t[2]);
777
+ case "msup": return rt(t[0] ? q(t[0]) : "", t[1]);
778
+ case "msub": return it(t[0] ? q(t[0]) : "", t[1]);
779
+ case "msubsup": return (t[0] ? at(t[0], t[1], t[2]) : void 0) || rt(it(t[0] ? q(t[0]) : "", t[1]), t[2]);
1023
780
  case "munder":
1024
781
  case "mover":
1025
782
  case "munderover": {
1026
- let [n, r, i] = t, a = e.localName === "mover" ? void 0 : r, o = e.localName === "munder" ? void 0 : e.localName === "mover" ? r : i, s = n ? Wt(n, a, o) : void 0;
783
+ let [n, r, i] = t, a = e.localName === "mover" ? void 0 : r, o = e.localName === "munder" ? void 0 : e.localName === "mover" ? r : i, s = n ? at(n, a, o) : void 0;
1027
784
  if (s) return s;
1028
- let c = n ? X(n) : "", l = e.localName === "mover" && r ? Ft[U(r)] : void 0;
785
+ let c = n ? q(n) : "", l = e.localName === "mover" && r ? Xe[V(r)] : void 0;
1029
786
  return l ? l === "vector" ? `vector ${c}` : `${c} ${l}` : [
1030
787
  c,
1031
- a ? `with ${X(a)} below` : "",
1032
- o ? `with ${X(o)} above` : ""
788
+ a ? `with ${q(a)} below` : "",
789
+ o ? `with ${q(o)} above` : ""
1033
790
  ].filter(Boolean).join(" ");
1034
791
  }
1035
- case "mfenced": return Kt(e);
1036
- case "mtable": return Gt(e);
792
+ case "mfenced": return st(e);
793
+ case "mtable": return ot(e);
1037
794
  case "mrow":
1038
- case "math": return zt(t);
1039
- default: return t.length ? Y(t) : U(e);
795
+ case "math": return et(t);
796
+ default: return t.length ? K(t) : V(e);
1040
797
  }
1041
798
  }
1042
- function qt(e) {
1043
- return W(X(e));
799
+ function ct(e) {
800
+ return H(q(e));
1044
801
  }
1045
802
  //#endregion
1046
803
  //#region src/math-name.ts
1047
- var Jt = /* @__PURE__ */ new Set(/* @__PURE__ */ "address.article.aside.blockquote.br.dd.div.dl.dt.fieldset.figure.footer.h1.h2.h3.h4.h5.h6.header.hr.li.ol.p.pre.section.table.td.th.tr.ul".split(".")), Yt = (e) => e.replace(/\s+/g, " ").trim();
1048
- function Xt(e) {
1049
- return e.getAttribute("aria-hidden") === "true" || e.hidden === !0 || e.style?.display === "none";
1050
- }
1051
- function Zt(e) {
1052
- return e.localName === "math" ? e : e.querySelector("math");
1053
- }
1054
- function Z(e, t, n) {
1055
- if (e.nodeType === 3) return e.textContent ?? "";
1056
- if (!(e instanceof Element) || Xt(e)) return "";
1057
- let r = e.localName === "mjx-container" || e.localName === "math" ? Zt(e) : null;
1058
- if (r) {
1059
- let e = Yt(t(r) ?? r.textContent ?? "");
1060
- return e && (n.math = !0), ` ${e} `;
804
+ var lt = [
805
+ "a[href]",
806
+ "button",
807
+ "label",
808
+ "summary",
809
+ ...[
810
+ "button",
811
+ "checkbox",
812
+ "combobox",
813
+ "link",
814
+ "menuitem",
815
+ "menuitemcheckbox",
816
+ "menuitemradio",
817
+ "option",
818
+ "radio",
819
+ "switch",
820
+ "tab",
821
+ "treeitem"
822
+ ].map((e) => `[role="${e}"]`)
823
+ ].join(", ");
824
+ function ut(e) {
825
+ if (e.hasAttribute("aria-label") || !e.closest(lt)) return;
826
+ let t = e.querySelector("math"), n = t ? ct(t) : "";
827
+ n && e.setAttribute("aria-label", n);
828
+ }
829
+ function J(e) {
830
+ for (let t of e.querySelectorAll("mjx-container")) ut(t);
831
+ }
832
+ //#endregion
833
+ //#region src/speech-worker.ts
834
+ var dt = Symbol.for("@pie-element/shared-math-rendering-mathjax/speech-worker-failed");
835
+ function ft() {
836
+ let e = globalThis;
837
+ e[dt] || (e[dt] = !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}`));
838
+ }
839
+ function pt(e) {
840
+ let t = e.webworker;
841
+ if (!t || t.ready) return;
842
+ e.options ??= {};
843
+ let n = e.options;
844
+ n.enableSpeech = !1, n.enableBraille = !1, n.speechError = () => {}, t.Post = () => Promise.reject(/* @__PURE__ */ Error("The speech worker did not start")), t.Terminate(), ft();
845
+ }
846
+ function mt(e) {
847
+ let t = e?.adaptor, n = t?.createWorker;
848
+ !e || !t || !n || (t.createWorker = async (r, i) => {
849
+ let a = await n.call(t, r, i);
850
+ return a.addEventListener("error", () => pt(e), { once: !0 }), a;
851
+ });
852
+ }
853
+ `${i}`;
854
+ //#endregion
855
+ //#region src/adapter.ts
856
+ var ht = {
857
+ parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
858
+ overarc: "\\overparen",
859
+ napprox: "\\not\\approx",
860
+ longdiv: "\\enclose{longdiv}",
861
+ abs: ["\\left|#1\\right|", 1]
862
+ }, gt = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", _t = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, vt = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, yt = /\\embed\{newLine\}\[\]/g, bt = [
863
+ ["$$", "$$"],
864
+ ["$", "$"],
865
+ ["\\[", "\\]"],
866
+ ["\\(", "\\)"]
867
+ ], xt = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), St = "MJX-CHTML-styles", Ct = "PIE-MJX-SVG-styles", Y = "PIE-MathJax-Menu-Settings", wt = { "mjx-container[overflow=\"linebreak\"][display]": {
868
+ overflow: "auto clip",
869
+ "min-width": "initial !important"
870
+ } }, Tt = 200, Et = 201, Dt = 202;
871
+ function X(e) {
872
+ let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
873
+ 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");
874
+ }
875
+ function Ot(e) {
876
+ for (let [t, n] of bt) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
877
+ return e;
878
+ }
879
+ function kt(e) {
880
+ return Ot(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
881
+ }
882
+ var At = "mathjax_ignore", jt = "mathjax_process";
883
+ function Mt(e, t) {
884
+ let n = e.closest(`.${At}, .${jt}`);
885
+ return n !== null && t.contains(n) && !n.classList.contains(jt);
886
+ }
887
+ function Nt(e) {
888
+ for (let t of e.querySelectorAll("[data-latex]")) {
889
+ if (t.dataset.mathHandled || t.closest("mjx-container") || Mt(t, e)) continue;
890
+ let n = t.textContent;
891
+ n && (t.textContent = `\\(${kt(n)}\\)`.replace(yt, "\\newline "), t.dataset.mathHandled = "true");
892
+ }
893
+ }
894
+ function Pt(e) {
895
+ for (let t of e.querySelectorAll("math")) t.closest("mjx-container") || t.setAttribute("displaystyle", "true");
896
+ }
897
+ function Ft(e, t) {
898
+ for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
899
+ return (t ? vt : _t).test(e.textContent ?? "");
900
+ }
901
+ function It(e) {
902
+ return new Promise((t, n) => {
903
+ let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = e, s = d(e, import.meta.url), c = {
904
+ loader: {
905
+ load: i ? ["a11y/assistive-mml"] : [],
906
+ failed: (e) => n(e),
907
+ "output/svg": { ready: (e) => {
908
+ let t = y();
909
+ return Lt(t) && Rt(t), e;
910
+ } }
911
+ },
912
+ startup: {
913
+ typeset: !1,
914
+ ready: () => {
915
+ let e = y(), r = e?.startup, i = Lt(e);
916
+ i && (Rt(e), zt(e, s.speechLocales), f(e?._?.a11y?.sre_ts?.locales, s.speechLocales)), r?.defaultReady?.(), i && (Bt(r?.document), Vt(r?.document), r?.document?.addStyles?.(wt), mt(r?.document)), Promise.resolve(r?.promise).then(() => t(), n);
917
+ }
918
+ },
919
+ tex: { macros: { ...ht } },
920
+ output: { displayOverflow: "linebreak" },
921
+ options: {
922
+ enableMenu: i,
923
+ menuOptions: { settings: {
924
+ assistiveMml: i,
925
+ enrich: !1,
926
+ inTabOrder: !1
927
+ } },
928
+ a11y: { inTabOrder: !1 }
929
+ }
930
+ };
931
+ r && c.tex && (console.warn(gt), c.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], c.tex.processEscapes = !0), a || (c.chtml = { fontURL: "" });
932
+ let l = p(s.speechLocales);
933
+ l && c.options && (c.options.sre = { locale: l }), ae(c, {
934
+ ...s,
935
+ srcUrl: o
936
+ }).then((e) => {
937
+ e || t();
938
+ }, n);
939
+ });
940
+ }
941
+ function Lt(e) {
942
+ return !!e?.version?.startsWith("4.");
943
+ }
944
+ function Rt(e) {
945
+ let t = e?._?.output, n = t?.chtml_ts?.CHTML;
946
+ n && (n.STYLESHEETID = b);
947
+ let r = t?.svg_ts?.SVG;
948
+ r && (r.STYLESHEETID = Ct);
949
+ }
950
+ function zt(e, t) {
951
+ let n = e?._?.ui?.menu?.Menu?.Menu;
952
+ if (n) {
953
+ n.MENU_STORAGE = Y;
954
+ try {
955
+ let e = localStorage.getItem(Y);
956
+ if (!e) return;
957
+ let { assistiveMml: n, locale: r, ...i } = JSON.parse(e), a = r === void 0 || !t || t.has(r);
958
+ if (n === void 0 && a) return;
959
+ a && r !== void 0 && (i.locale = r), Object.keys(i).length ? localStorage.setItem(Y, JSON.stringify(i)) : localStorage.removeItem(Y);
960
+ } catch {}
1061
961
  }
1062
- if (e.localName === "mjx-container") return " ";
1063
- let i = e.getAttribute("aria-label")?.trim();
1064
- if (i) return ` ${i} `;
1065
- if (e.localName === "img") return ` ${e.getAttribute("alt") ?? ""} `;
1066
- let a = [...e.childNodes].map((e) => Z(e, t, n)).join("");
1067
- return Jt.has(e.localName) ? ` ${a} ` : a;
1068
962
  }
1069
- function Qt(e, t = {}) {
1070
- let n = t.speak ?? qt, r = { math: !1 }, i = Yt([...e.childNodes].map((e) => Z(e, n, r)).join(""));
1071
- return r.math && i ? i : void 0;
963
+ function Bt(e) {
964
+ if (!e) return;
965
+ let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
966
+ let n = e.typesetRoot;
967
+ !n || t.has(n) || (X(n), t.add(n));
968
+ };
969
+ e.addRenderAction?.("pie-strip-latex", Et, (e) => {
970
+ for (let t of e.math ?? []) n(t);
971
+ return !1;
972
+ }, (e) => {
973
+ let t = e.typesetRoot;
974
+ return t && X(t), !1;
975
+ });
976
+ let r = e.outputJax?.chtmlStyles;
977
+ r?.id === St && (r.id = b), Ut();
978
+ }
979
+ function Vt(e) {
980
+ let t = (e) => {
981
+ e.typesetRoot && ut(e.typesetRoot);
982
+ };
983
+ e?.addRenderAction?.("pie-name-math", Dt, (e) => {
984
+ for (let n of e.math ?? []) t(n);
985
+ return !1;
986
+ }, (e) => (t(e), !1));
987
+ }
988
+ function Z(e) {
989
+ return e instanceof HTMLStyleElement && se.includes(e.id);
990
+ }
991
+ function Ht(e) {
992
+ ne("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
993
+ }
994
+ function Ut() {
995
+ let e = document.head, t = [...e.children].find(Z);
996
+ if (t) {
997
+ Ht(t);
998
+ return;
999
+ }
1000
+ let n = new MutationObserver((e) => {
1001
+ for (let t of e) {
1002
+ let e = [...t.addedNodes].find(Z);
1003
+ if (e) {
1004
+ Ht(e), n.disconnect();
1005
+ return;
1006
+ }
1007
+ }
1008
+ });
1009
+ n.observe(e, { childList: !0 });
1010
+ }
1011
+ function Wt(e) {
1012
+ let t = e?.math;
1013
+ if (!t?.remove) return;
1014
+ let n = [...t].filter((e) => (e.state?.() ?? 0) >= Tt && e.typesetRoot?.isConnected === !1);
1015
+ if (n.length !== 0) {
1016
+ for (let e of [...n].reverse()) e.clear?.();
1017
+ t.remove(...n);
1018
+ }
1019
+ }
1020
+ function Gt(e) {
1021
+ return new Promise((t, n) => {
1022
+ let r = e.startup ?? {};
1023
+ e.startup = r;
1024
+ let i = r.ready;
1025
+ r.ready = () => {
1026
+ let e = y()?.startup;
1027
+ i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
1028
+ };
1029
+ });
1030
+ }
1031
+ function Kt(e) {
1032
+ let t = y();
1033
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : Gt(t) : It(e);
1034
+ }
1035
+ function qt(e) {
1036
+ return Kt(e).then(() => {
1037
+ let e = y();
1038
+ e && typeof e.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
1039
+ });
1040
+ }
1041
+ function Jt(e) {
1042
+ let t = oe, n = t[xt];
1043
+ return n || (n = qt(e), t[xt] = n), n;
1044
+ }
1045
+ function Yt(e = {}) {
1046
+ let t = e.useSingleDollar ?? !1;
1047
+ return async (n) => {
1048
+ if (typeof window > "u") return;
1049
+ let r = ce();
1050
+ r && ne("mathjax-3-global", `window.MathJax is MathJax ${r}`), Nt(n), fe(n), Pt(n), Ie(n);
1051
+ let i = Jt(e);
1052
+ if (!Ft(n, t)) {
1053
+ i.catch(() => {});
1054
+ return;
1055
+ }
1056
+ await i;
1057
+ let a = y();
1058
+ if (await a?.startup?.promise, typeof a?.typesetPromise == "function") {
1059
+ Ve(), Wt(a.startup?.document);
1060
+ try {
1061
+ await a.typesetPromise([n]);
1062
+ } catch (e) {
1063
+ throw a.typesetClear?.([n]), e;
1064
+ }
1065
+ X(n), J(n);
1066
+ }
1067
+ };
1068
+ }
1069
+ function Xt() {
1070
+ return [];
1072
1071
  }
1073
1072
  //#endregion
1074
1073
  //#region src/render-math.ts
1075
- var $t = "@pie-lib/math-rendering", en = "@pie-lib/math-rendering@2", tn = "pie-print", nn = 50, rn = 1e4, an = null;
1076
- function on() {
1077
- return !!window[en]?.opts?.useSingleDollar;
1074
+ var Zt = "@pie-lib/math-rendering", Qt = "@pie-lib/math-rendering@2", $t = "pie-print", en = 50, tn = 1e4, nn = null;
1075
+ function rn() {
1076
+ return !!window[Qt]?.opts?.useSingleDollar;
1078
1077
  }
1079
- function sn() {
1080
- return an ||= Tt({ useSingleDollar: on() }), an;
1078
+ function an() {
1079
+ return nn ||= Yt({ useSingleDollar: rn() }), nn;
1081
1080
  }
1082
1081
  function Q() {
1083
1082
  if (typeof window > "u") return null;
1084
- let e = window[$t];
1083
+ let e = window[Zt];
1085
1084
  return typeof e?.renderMath == "function" && e.renderMath !== $ ? e : null;
1086
1085
  }
1087
- function cn(e) {
1086
+ function on(e) {
1088
1087
  let t = e;
1089
1088
  for (; t;) {
1090
- if (t instanceof Element && t.localName === tn) return t;
1089
+ if (t instanceof Element && t.localName === $t) return t;
1091
1090
  t = t instanceof ShadowRoot ? t.host : t.parentNode;
1092
1091
  }
1093
1092
  return null;
1094
1093
  }
1095
- function ln() {
1094
+ function sn() {
1096
1095
  let e = window.renderMath;
1097
1096
  return typeof e == "function" ? e : null;
1098
1097
  }
1099
- async function un(e) {
1100
- let t = cn(e);
1098
+ async function cn(e) {
1099
+ let t = on(e);
1101
1100
  if (!t) return null;
1102
- let n = ln();
1101
+ let n = sn();
1103
1102
  if (n || t.mathRenderingModuleUrlImported !== !0) return n;
1104
- let r = Date.now() + rn;
1103
+ let r = Date.now() + tn;
1105
1104
  for (; Date.now() < r;) {
1106
- await new Promise((e) => setTimeout(e, nn));
1107
- let e = ln();
1105
+ await new Promise((e) => setTimeout(e, en));
1106
+ let e = sn();
1108
1107
  if (e) return e;
1109
1108
  }
1110
1109
  return null;
@@ -1113,14 +1112,14 @@ var $ = async (e) => {
1113
1112
  if (typeof window > "u") return;
1114
1113
  let t = typeof e == "string", n;
1115
1114
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
1116
- let r = Q(), i = r || t ? null : await un(n);
1117
- return r ? await r.renderMath?.(n) : i && i !== $ ? await i(n) : await sn()(n), t ? n.innerHTML : void 0;
1118
- }, dn = (e, t) => {
1115
+ let r = Q(), i = r || t ? null : await cn(n);
1116
+ return r ? (await r.renderMath?.(n), J(n)) : i && i !== $ ? (await i(n), J(n)) : await an()(n), t ? n.innerHTML : void 0;
1117
+ }, ln = (e, t) => {
1119
1118
  let n = Q()?.wrapMath?.(e, t);
1120
1119
  if (n != null) return n;
1121
1120
  let [r, i] = t === "dollar" || t === "double_dollar" ? ["$", "$"] : ["\\(", "\\)"];
1122
- return `${r}${B(e)}${i}`;
1123
- }, fn = (e) => {
1121
+ return `${r}${Ot(e)}${i}`;
1122
+ }, un = (e) => {
1124
1123
  let t = e.trim();
1125
1124
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
1126
1125
  unwrapped: t.slice(2, -2).trim(),
@@ -1147,6 +1146,6 @@ var $ = async (e) => {
1147
1146
  close: "$"
1148
1147
  }
1149
1148
  } : { unwrapped: t };
1150
- }, pn = (e) => Q()?.mmlToLatex?.(e) ?? e;
1149
+ }, dn = (e) => Q()?.mmlToLatex?.(e) ?? e;
1151
1150
  //#endregion
1152
- export { ee as MATHJAX_CONFLICT_EVENT, m as NO_ASSET_ROOT_EVENT, v as UNSUPPORTED_PAGE_DOCS_URL, Tt as createMathjaxRenderer, Et as getMathjaxCssUrls, Qt as mathContentName, pn as mmlToLatex, $ as renderMath, qt as speakMathml, fn as unWrapMath, dn as wrapMath };
1151
+ export { ee as MATHJAX_CONFLICT_EVENT, m as NO_ASSET_ROOT_EVENT, v as UNSUPPORTED_PAGE_DOCS_URL, Yt as createMathjaxRenderer, Xt as getMathjaxCssUrls, dn as mmlToLatex, $ as renderMath, ct as speakMathml, un as unWrapMath, ln as wrapMath };