@pie-element/element-player 0.1.2-next.13 → 0.1.2-next.15

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/README.md CHANGED
@@ -83,7 +83,6 @@ For elements with import maps:
83
83
 
84
84
  - Loads elements via dynamic ESM imports: `import('@pie-element/hotspot')`
85
85
  - Handles session state and user interactions
86
- - Manages math rendering internally (MathJax)
87
86
  - Emits `session-changed` events
88
87
  - Works with both React and Svelte elements
89
88
 
@@ -92,16 +91,18 @@ For elements with import maps:
92
91
  - Loads print exports: `import('@pie-element/hotspot/print')`
93
92
  - Stateless (no session management)
94
93
  - Optimized for print layouts
95
- - Manages math rendering internally (MathJax)
96
94
  - Role-based rendering (student/instructor)
97
95
 
98
96
  **All views:**
99
97
 
100
98
  - Use import maps for module resolution
101
99
  - Self-contained (no external setup needed)
102
- - Handle math rendering automatically
103
100
  - Support for both React and Svelte elements
104
101
 
102
+ ### Math rendering
103
+
104
+ The player typesets math through `window['@pie-lib/math-rendering'].renderMath`, read on every render. A renderer the host installs there before the player mounts, such as the legacy MathJax 3 one, is used and no MathJax 4 loads. Without one, the player installs a MathJax 4 renderer from `@pie-element/shared-math-rendering-mathjax`, which elements and later players on the page share.
105
+
105
106
  ### Events
106
107
 
107
108
  The player dispatches each event from `<pie-element-player>`, bubbling and composed. A bubble-phase listener on the player, on an ancestor or on `document` hears each event once, with `event.target` the player; a listener outside a shadow root that contains the player sees that root's host instead. The element's own `session-changed` stops at the element, and the player dispatches its copy in its place. A capture-phase listener on the player or above it also hears every `session-changed` the element dispatches, ahead of the player's copy, and should ignore events whose `event.composedPath()[0]` is not the player. That equals `event.target` when no shadow root lies between listener and player. A closed shadow root hides the player from both, so listen in the bubble phase there.
@@ -41,22 +41,29 @@ function _() {
41
41
  return window.MathJax;
42
42
  }
43
43
  function v(e) {
44
- let t = e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e;
45
- for (let [e, n] of u) if (t.startsWith(e) && t.endsWith(n)) return t.substring(e.length, t.length - n.length);
46
- return t;
44
+ for (let [t, n] of u) if (e.startsWith(t) && e.endsWith(n)) return e.substring(t.length, e.length - n.length);
45
+ return e;
47
46
  }
48
47
  function y(e) {
48
+ return v(e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e);
49
+ }
50
+ var b = "mathjax_ignore", x = "mathjax_process";
51
+ function S(e, t) {
52
+ let n = e.closest(`.${b}, .${x}`);
53
+ return n !== null && t.contains(n) && !n.classList.contains(x);
54
+ }
55
+ function C(e) {
49
56
  for (let t of e.querySelectorAll("[data-latex]")) {
50
- if (t.dataset.mathHandled || t.closest("mjx-container")) continue;
51
- let e = t.textContent;
52
- e && (t.textContent = `\\(${v(e)}\\)`.replace(l, "\\newline "), t.dataset.mathHandled = "true");
57
+ if (t.dataset.mathHandled || t.closest("mjx-container") || S(t, e)) continue;
58
+ let n = t.textContent;
59
+ n && (t.textContent = `\\(${y(n)}\\)`.replace(l, "\\newline "), t.dataset.mathHandled = "true");
53
60
  }
54
61
  }
55
- function b(e, t) {
62
+ function w(e, t) {
56
63
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
57
64
  return (t ? c : s).test(e.textContent ?? "");
58
65
  }
59
- function x(e) {
66
+ function T(e) {
60
67
  return new Promise((t, n) => {
61
68
  let { useSingleDollar: r = !1, accessibility: s = !0, loadFonts: c = !0, srcUrl: l } = e, u = {
62
69
  loader: {
@@ -67,7 +74,7 @@ function x(e) {
67
74
  typeset: !1,
68
75
  ready: () => {
69
76
  let e = _(), r = e?.startup, i = !!e?.version?.startsWith("4.");
70
- i && S(e), r?.defaultReady?.(), i && C(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
77
+ i && E(e), r?.defaultReady?.(), i && D(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
71
78
  }
72
79
  },
73
80
  tex: { macros: { ...a } },
@@ -85,11 +92,11 @@ function x(e) {
85
92
  d.src = l || i, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
86
93
  });
87
94
  }
88
- function S(e) {
95
+ function E(e) {
89
96
  let t = e?._?.output?.chtml_ts?.CHTML;
90
97
  t && (t.STYLESHEETID = f);
91
98
  }
92
- function C(e) {
99
+ function D(e) {
93
100
  if (!e) return;
94
101
  let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
95
102
  let n = e.typesetRoot;
@@ -103,32 +110,32 @@ function C(e) {
103
110
  return t && g(t), !1;
104
111
  });
105
112
  let r = e.outputJax?.chtmlStyles;
106
- r?.id === p && (r.id = f), E();
113
+ r?.id === p && (r.id = f), A();
107
114
  }
108
- function w(e) {
115
+ function O(e) {
109
116
  return e instanceof HTMLStyleElement && m.includes(e.id);
110
117
  }
111
- function T(e) {
118
+ function k(e) {
112
119
  n("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
113
120
  }
114
- function E() {
115
- let e = document.head, t = [...e.children].find(w);
121
+ function A() {
122
+ let e = document.head, t = [...e.children].find(O);
116
123
  if (t) {
117
- T(t);
124
+ k(t);
118
125
  return;
119
126
  }
120
127
  let n = new MutationObserver((e) => {
121
128
  for (let t of e) {
122
- let e = [...t.addedNodes].find(w);
129
+ let e = [...t.addedNodes].find(O);
123
130
  if (e) {
124
- T(e), n.disconnect();
131
+ k(e), n.disconnect();
125
132
  return;
126
133
  }
127
134
  }
128
135
  });
129
136
  n.observe(e, { childList: !0 });
130
137
  }
131
- function D(e) {
138
+ function j(e) {
132
139
  return new Promise((t, n) => {
133
140
  let r = e.startup ?? {};
134
141
  e.startup = r;
@@ -139,27 +146,27 @@ function D(e) {
139
146
  };
140
147
  });
141
148
  }
142
- function O(e) {
149
+ function M(e) {
143
150
  let t = _();
144
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : D(t) : x(e);
151
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : j(t) : T(e);
145
152
  }
146
- function k(e) {
147
- return O(e).then(() => {
153
+ function N(e) {
154
+ return M(e).then(() => {
148
155
  typeof _()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
149
156
  });
150
157
  }
151
- function A(e) {
158
+ function P(e) {
152
159
  let t = globalThis, n = t[d];
153
- return n || (n = k(e), t[d] = n), n;
160
+ return n || (n = N(e), t[d] = n), n;
154
161
  }
155
- function j(e = {}) {
162
+ function F(e = {}) {
156
163
  let t = e.useSingleDollar ?? !1;
157
164
  return async (i) => {
158
165
  if (typeof window > "u") return;
159
166
  let a = r();
160
- a && n("mathjax-3-global", `window.MathJax is MathJax ${a}`), y(i);
161
- let o = A(e);
162
- if (!b(i, t)) {
167
+ a && n("mathjax-3-global", `window.MathJax is MathJax ${a}`), C(i);
168
+ let o = P(e);
169
+ if (!w(i, t)) {
163
170
  o.catch(() => {});
164
171
  return;
165
172
  }
@@ -169,4 +176,4 @@ function j(e = {}) {
169
176
  };
170
177
  }
171
178
  //#endregion
172
- export { j as t };
179
+ export { F as t };