@pie-element/shared-math-rendering-mathjax 0.1.1-next.5 → 0.1.1-next.7

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
@@ -175,29 +175,50 @@ function N() {
175
175
  }
176
176
  //#endregion
177
177
  //#region src/render-math.ts
178
- var P = "@pie-lib/math-rendering", F = "@pie-lib/math-rendering@2", I = null;
179
- function L() {
178
+ var P = "@pie-lib/math-rendering", F = "@pie-lib/math-rendering@2", I = "pie-print", L = 50, R = 1e4, z = null;
179
+ function B() {
180
180
  return !!window[F]?.opts?.useSingleDollar;
181
181
  }
182
- function R() {
183
- return I ||= M({ useSingleDollar: L() }), I;
182
+ function V() {
183
+ return z ||= M({ useSingleDollar: B() }), z;
184
184
  }
185
- function z() {
185
+ function H() {
186
186
  if (typeof window > "u") return null;
187
187
  let e = window[P];
188
188
  return typeof e?.renderMath == "function" ? e : null;
189
189
  }
190
- function B() {
191
- let e = i();
192
- e && r("legacy-renderer-delegation", `window['${P}'] renders this element's math with MathJax ${e}`);
190
+ function U(e) {
191
+ let t = e;
192
+ for (; t;) {
193
+ if (t instanceof Element && t.localName === I) return t;
194
+ t = t instanceof ShadowRoot ? t.host : t.parentNode;
195
+ }
196
+ return null;
197
+ }
198
+ function W() {
199
+ let e = window.renderMath;
200
+ return typeof e == "function" ? e : null;
201
+ }
202
+ async function G(e) {
203
+ let t = U(e);
204
+ if (!t) return null;
205
+ let n = W();
206
+ if (n || t.mathRenderingModuleUrlImported !== !0) return n;
207
+ let r = Date.now() + R;
208
+ for (; Date.now() < r;) {
209
+ await new Promise((e) => setTimeout(e, L));
210
+ let e = W();
211
+ if (e) return e;
212
+ }
213
+ return null;
193
214
  }
194
- var V = async (e) => {
215
+ var K = async (e) => {
195
216
  if (typeof window > "u") return;
196
217
  let t = typeof e == "string", n;
197
218
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
198
- let r = z();
199
- return r ? (B(), await r.renderMath?.(n)) : await R()(n), t ? n.innerHTML : void 0;
200
- }, H = (e) => z()?.wrapMath?.(e) ?? e, U = (e) => {
219
+ let r = H(), i = r || t ? null : await G(n);
220
+ return r ? await r.renderMath?.(n) : i ? await i(n) : await V()(n), t ? n.innerHTML : void 0;
221
+ }, q = (e) => H()?.wrapMath?.(e) ?? e, J = (e) => {
201
222
  let t = e.trim();
202
223
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
203
224
  unwrapped: t.slice(2, -2).trim(),
@@ -224,6 +245,6 @@ var V = async (e) => {
224
245
  close: "$"
225
246
  }
226
247
  } : { unwrapped: t };
227
- }, W = (e) => z()?.mmlToLatex?.(e) ?? e;
248
+ }, Y = (e) => H()?.mmlToLatex?.(e) ?? e;
228
249
  //#endregion
229
- export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, M as createMathjaxRenderer, N as getMathjaxCssUrls, W as mmlToLatex, V as renderMath, U as unWrapMath, H as wrapMath };
250
+ export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, M as createMathjaxRenderer, N as getMathjaxCssUrls, Y as mmlToLatex, K as renderMath, J as unWrapMath, q as wrapMath };
@@ -13,9 +13,7 @@ export type MathjaxConflictCondition =
13
13
  /** `window.MathJax` is a MathJax 3 build. */
14
14
  'mathjax-3-global'
15
15
  /** Another MathJax output stylesheet was added to `<head>` beside this adapter's. */
16
- | 'foreign-output-stylesheet'
17
- /** `window['@pie-lib/math-rendering']` routes ESM element math to MathJax 3. */
18
- | 'legacy-renderer-delegation';
16
+ | 'foreign-output-stylesheet';
19
17
  export interface MathjaxConflictDetail {
20
18
  condition: MathjaxConflictCondition;
21
19
  message: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-math-rendering-mathjax",
3
- "version": "0.1.1-next.5",
3
+ "version": "0.1.1-next.7",
4
4
  "description": "MathJax adapter for PIE math rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",