@pie-element/shared-math-rendering-mathjax 0.1.1-next.6 → 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.
Files changed (2) hide show
  1. package/dist/index.js +36 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -175,25 +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
- var B = async (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;
214
+ }
215
+ var K = async (e) => {
191
216
  if (typeof window > "u") return;
192
217
  let t = typeof e == "string", n;
193
218
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
194
- let r = z();
195
- return r ? await r.renderMath?.(n) : await R()(n), t ? n.innerHTML : void 0;
196
- }, V = (e) => z()?.wrapMath?.(e) ?? e, H = (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) => {
197
222
  let t = e.trim();
198
223
  return t.startsWith("\\[") && t.endsWith("\\]") ? {
199
224
  unwrapped: t.slice(2, -2).trim(),
@@ -220,6 +245,6 @@ var B = async (e) => {
220
245
  close: "$"
221
246
  }
222
247
  } : { unwrapped: t };
223
- }, U = (e) => z()?.mmlToLatex?.(e) ?? e;
248
+ }, Y = (e) => H()?.mmlToLatex?.(e) ?? e;
224
249
  //#endregion
225
- export { t as MATHJAX_CONFLICT_EVENT, e as UNSUPPORTED_PAGE_DOCS_URL, M as createMathjaxRenderer, N as getMathjaxCssUrls, U as mmlToLatex, B as renderMath, H as unWrapMath, V 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 };
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.6",
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",