@pie-element/element-player 0.1.2-next.1 → 0.1.2-next.11
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 +26 -25
- package/dist/index.d.ts +1 -1
- package/dist/lib/element-loader.d.ts +1 -1
- package/dist/lib/math-rendering-types.d.ts +0 -6
- package/dist/lib/types.d.ts +0 -6
- package/dist/lib/unified-player-loader.d.ts +4 -4
- package/dist/math-mathjax-iaHklMFp.js +172 -0
- package/dist/pie-element-player.css +1 -1
- package/dist/pie-element-player.js +960 -957
- package/package.json +2 -2
- package/dist/math-mathjax-YIPQGZlD.js +0 -59
package/README.md
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
# PIE Element Player
|
|
2
2
|
|
|
3
|
-
Self-contained web components for rendering PIE elements, following the same architecture as `@pie-framework/pie-players
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## ⚠️ IMPORTANT: NOT FOR PUBLISHING
|
|
8
|
-
|
|
9
|
-
**This package is currently marked as `private` and should NOT be published to npm.**
|
|
10
|
-
|
|
11
|
-
### Build Issue
|
|
12
|
-
|
|
13
|
-
The package has a dependency resolution issue that prevents it from building as a standalone library:
|
|
14
|
-
|
|
15
|
-
- [element-loader.ts](src/lib/element-loader.ts) imports `$lib/element-imports` for local development mode
|
|
16
|
-
- This import only exists in the element-demo app, not in this package
|
|
17
|
-
- The import is marked as external in the build config as a workaround
|
|
18
|
-
- For production use, this architecture needs to be refactored
|
|
19
|
-
|
|
20
|
-
**Before publishing this package**, the following must be resolved:
|
|
21
|
-
|
|
22
|
-
1. Refactor the element-loader to not depend on app-specific imports
|
|
23
|
-
2. Either remove local development mode from the library OR provide a proper abstraction
|
|
24
|
-
3. Ensure the build completes successfully without external dependencies on non-existent modules
|
|
25
|
-
4. Remove the `"private": true` field from package.json
|
|
26
|
-
|
|
27
|
-
**Issue tracked in**: Build fails with "Rollup failed to resolve import '$lib/element-imports'"
|
|
3
|
+
Self-contained web components for rendering PIE elements, following the same architecture as the `@pie-players/*` players in [pie-players](https://github.com/pie-framework/pie-players).
|
|
28
4
|
|
|
29
5
|
---
|
|
30
6
|
|
|
@@ -126,6 +102,31 @@ For elements with import maps:
|
|
|
126
102
|
- Handle math rendering automatically
|
|
127
103
|
- Support for both React and Svelte elements
|
|
128
104
|
|
|
105
|
+
### Events
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
| Event | When | `detail` |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `session-changed` | delivery: the learner changes the session, or the element re-reports a session the player set (below) | the element's detail, with `session` the new session |
|
|
112
|
+
| `model-changed` | author: the author edits the model | the whole model |
|
|
113
|
+
| `load-complete` | the element is mounted | `strategy`, `view`, `tagName` |
|
|
114
|
+
| `load-cancelled` | a newer load supersedes this one, or the load fails with an abort error (below) | `reason`, `strategy`, `view` |
|
|
115
|
+
| `player-error` | the load fails | `error`, `strategy`, `view`, `retry` |
|
|
116
|
+
| `build-state` | the load changes stage | `loading`, `error`, `stage`, and `strategy`, `view`, `retry` where known |
|
|
117
|
+
| `bundle-retry-status` | IIFE: a bundle build is polled; any strategy: the load fails with an abort error | the retry state |
|
|
118
|
+
| `bundle-meta` | IIFE: the bundle loads | the bundle's metadata |
|
|
119
|
+
| `controller-load` | a load completes, except a `preloaded` one that finds its tag defined (below) | `status`, `source`, `packageName`, `strategy`, `view`, `message` |
|
|
120
|
+
| `controller-changed` | IIFE delivery: the bundle's controller loads | the controller |
|
|
121
|
+
|
|
122
|
+
`session-changed` also fires with no learner action. Once the element has a model, the player sets `session` on it, and sets it again whenever the host assigns a different session. A report the element dispatches while that setter runs is dropped; one it dispatches after the setter returns is forwarded.
|
|
123
|
+
|
|
124
|
+
An abort error is a load error whose message contains `aborted`, whatever the strategy. The player then emits `bundle-retry-status` with state `cancelled`, `build-state` with stage `cancelled` and `load-cancelled`, in place of `player-error`.
|
|
125
|
+
|
|
126
|
+
`controller-load` reports `status` `loaded` in delivery view, where any other status fails the load. Author view can also report `missing` or `failed`, and print view reports `not-required` unless an IIFE bundle carries a controller.
|
|
127
|
+
|
|
128
|
+
A player removed from the document mid-load emits nothing more from that load, and re-attaching it starts a new one; a synchronous move keeps the load.
|
|
129
|
+
|
|
129
130
|
## Testing Elements Locally
|
|
130
131
|
|
|
131
132
|
Use the existing demo commands to test elements:
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import './app.css';
|
|
12
12
|
import './players/index.js';
|
|
13
|
-
export type { ElementPlayerProps, PieController
|
|
13
|
+
export type { ElementPlayerProps, PieController } from './lib/types.js';
|
|
14
14
|
export type { ElementPlayerStrategy, ElementPlayerView } from './lib/player-strategy.js';
|
|
15
15
|
export type { RuntimeSupportCheck, RuntimeSupportStrategy, RuntimeSupportView, PieElementRuntimeSupport, } from './lib/runtime-support.js';
|
|
16
16
|
export { normalizeRuntimeSupportCheck } from './lib/runtime-support.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Dynamically loads PIE elements from CDN and registers them as custom elements.
|
|
5
5
|
* Based on the ESM loader pattern from pie-players.
|
|
6
6
|
*/
|
|
7
|
-
import type { PieElementRuntimeSupport } from './runtime-support';
|
|
7
|
+
import type { PieElementRuntimeSupport } from './runtime-support.js';
|
|
8
8
|
export type ElementModuleKind = 'delivery' | 'author' | 'print' | 'controller' | 'runtime-support';
|
|
9
9
|
export interface ElementModuleResolveRequest {
|
|
10
10
|
packagePath: string;
|
|
@@ -1,7 +1 @@
|
|
|
1
1
|
export type MathRenderer = (element: HTMLElement) => void | Promise<void>;
|
|
2
|
-
export interface MathRenderingAPI {
|
|
3
|
-
renderMath: MathRenderer;
|
|
4
|
-
wrapMath?: (latex: string) => string;
|
|
5
|
-
unWrapMath?: (wrapped: string) => string;
|
|
6
|
-
mmlToLatex?: (mathml: string) => string;
|
|
7
|
-
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -18,9 +18,3 @@ export interface PieController {
|
|
|
18
18
|
outcome?: (model: any, session: any, env: any) => Promise<any>;
|
|
19
19
|
createCorrectResponseSession?: (model: any, env: any) => Promise<any>;
|
|
20
20
|
}
|
|
21
|
-
export interface Tab {
|
|
22
|
-
id: string;
|
|
23
|
-
label: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
disabled?: boolean;
|
|
26
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ElementModuleResolver } from './element-loader';
|
|
2
|
-
import { type IifeBundleRetryConfig, type IifeBundleRetryStatus, type IifeBundleLoadError, type LocalBundleMeta } from './iife-bundle-loader';
|
|
3
|
-
import { type ElementPlayerStrategy, type ElementPlayerView } from './player-strategy';
|
|
4
|
-
import { type PieElementRuntimeSupport, type RuntimeSupportCheck } from './runtime-support';
|
|
1
|
+
import { type ElementModuleResolver } from './element-loader.js';
|
|
2
|
+
import { type IifeBundleRetryConfig, type IifeBundleRetryStatus, type IifeBundleLoadError, type LocalBundleMeta } from './iife-bundle-loader.js';
|
|
3
|
+
import { type ElementPlayerStrategy, type ElementPlayerView } from './player-strategy.js';
|
|
4
|
+
import { type PieElementRuntimeSupport, type RuntimeSupportCheck } from './runtime-support.js';
|
|
5
5
|
export interface UnifiedPlayerLoadRequest {
|
|
6
6
|
strategy: string | null | undefined;
|
|
7
7
|
view: string | null | undefined;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
//#region ../shared/math-rendering-mathjax/dist/index.js
|
|
2
|
+
var e = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page", t = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
|
|
3
|
+
function n(n, r) {
|
|
4
|
+
if (typeof window > "u") return;
|
|
5
|
+
let i = globalThis;
|
|
6
|
+
i[t] ??= {
|
|
7
|
+
logged: !1,
|
|
8
|
+
conditions: []
|
|
9
|
+
};
|
|
10
|
+
let a = i[t];
|
|
11
|
+
if (a.conditions.includes(n)) return;
|
|
12
|
+
a.conditions.push(n);
|
|
13
|
+
let o = `[math-rendering] Unsupported page (${n}): ${r}. 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
|
+
a.logged || (a.logged = !0, console.error(o)), window.dispatchEvent(new CustomEvent("pie-mathjax-version-conflict", { detail: {
|
|
15
|
+
condition: n,
|
|
16
|
+
message: o,
|
|
17
|
+
docsUrl: e
|
|
18
|
+
} }));
|
|
19
|
+
}
|
|
20
|
+
function r() {
|
|
21
|
+
let e = window.MathJax?.version;
|
|
22
|
+
return typeof e == "string" && e.startsWith("3.") ? e : void 0;
|
|
23
|
+
}
|
|
24
|
+
var i = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", a = {
|
|
25
|
+
parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
|
|
26
|
+
overarc: "\\overparen",
|
|
27
|
+
napprox: "\\not\\approx",
|
|
28
|
+
longdiv: "\\enclose{longdiv}",
|
|
29
|
+
abs: ["\\left|#1\\right|", 1]
|
|
30
|
+
}, o = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)", s = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/, c = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/, l = /\\embed\{newLine\}\[\]/g, u = [
|
|
31
|
+
["$$", "$$"],
|
|
32
|
+
["$", "$"],
|
|
33
|
+
["\\[", "\\]"],
|
|
34
|
+
["\\(", "\\)"]
|
|
35
|
+
], d = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading"), f = "PIE-MJX-CHTML-styles", p = "MJX-CHTML-styles", m = [p, "MJX-SVG-styles"], h = 201;
|
|
36
|
+
function g(e) {
|
|
37
|
+
let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
|
|
38
|
+
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");
|
|
39
|
+
}
|
|
40
|
+
function _() {
|
|
41
|
+
return window.MathJax;
|
|
42
|
+
}
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
function y(e) {
|
|
49
|
+
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");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function b(e, t) {
|
|
56
|
+
for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
|
|
57
|
+
return (t ? c : s).test(e.textContent ?? "");
|
|
58
|
+
}
|
|
59
|
+
function x(e) {
|
|
60
|
+
return new Promise((t, n) => {
|
|
61
|
+
let { useSingleDollar: r = !1, accessibility: s = !0, loadFonts: c = !0, srcUrl: l } = e, u = {
|
|
62
|
+
loader: {
|
|
63
|
+
load: s ? ["a11y/assistive-mml"] : [],
|
|
64
|
+
failed: (e) => n(e)
|
|
65
|
+
},
|
|
66
|
+
startup: {
|
|
67
|
+
typeset: !1,
|
|
68
|
+
ready: () => {
|
|
69
|
+
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);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
tex: { macros: { ...a } },
|
|
74
|
+
options: {
|
|
75
|
+
enableMenu: s,
|
|
76
|
+
menuOptions: { settings: {
|
|
77
|
+
assistiveMml: s,
|
|
78
|
+
enrich: !1,
|
|
79
|
+
inTabOrder: !1
|
|
80
|
+
} }
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
r && u.tex && (console.warn(o), u.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], u.tex.processEscapes = !0), c || (u.chtml = { fontURL: "" }), window.MathJax = u;
|
|
84
|
+
let d = document.createElement("script");
|
|
85
|
+
d.src = l || i, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function S(e) {
|
|
89
|
+
let t = e?._?.output?.chtml_ts?.CHTML;
|
|
90
|
+
t && (t.STYLESHEETID = f);
|
|
91
|
+
}
|
|
92
|
+
function C(e) {
|
|
93
|
+
if (!e) return;
|
|
94
|
+
let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
|
|
95
|
+
let n = e.typesetRoot;
|
|
96
|
+
!n || t.has(n) || (g(n), t.add(n));
|
|
97
|
+
};
|
|
98
|
+
e.addRenderAction?.("pie-strip-latex", h, (e) => {
|
|
99
|
+
for (let t of e.math ?? []) n(t);
|
|
100
|
+
return !1;
|
|
101
|
+
}, (e) => {
|
|
102
|
+
let t = e.typesetRoot;
|
|
103
|
+
return t && g(t), !1;
|
|
104
|
+
});
|
|
105
|
+
let r = e.outputJax?.chtmlStyles;
|
|
106
|
+
r?.id === p && (r.id = f), E();
|
|
107
|
+
}
|
|
108
|
+
function w(e) {
|
|
109
|
+
return e instanceof HTMLStyleElement && m.includes(e.id);
|
|
110
|
+
}
|
|
111
|
+
function T(e) {
|
|
112
|
+
n("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
|
|
113
|
+
}
|
|
114
|
+
function E() {
|
|
115
|
+
let e = document.head, t = [...e.children].find(w);
|
|
116
|
+
if (t) {
|
|
117
|
+
T(t);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let n = new MutationObserver((e) => {
|
|
121
|
+
for (let t of e) {
|
|
122
|
+
let e = [...t.addedNodes].find(w);
|
|
123
|
+
if (e) {
|
|
124
|
+
T(e), n.disconnect();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
n.observe(e, { childList: !0 });
|
|
130
|
+
}
|
|
131
|
+
function D(e) {
|
|
132
|
+
return new Promise((t, n) => {
|
|
133
|
+
let r = e.startup ?? {};
|
|
134
|
+
e.startup = r;
|
|
135
|
+
let i = r.ready;
|
|
136
|
+
r.ready = () => {
|
|
137
|
+
let e = _()?.startup;
|
|
138
|
+
i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function O(e) {
|
|
143
|
+
let t = _();
|
|
144
|
+
return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : D(t) : x(e);
|
|
145
|
+
}
|
|
146
|
+
function k(e) {
|
|
147
|
+
return O(e).then(() => {
|
|
148
|
+
typeof _()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function A(e) {
|
|
152
|
+
let t = globalThis, n = t[d];
|
|
153
|
+
return n || (n = k(e), t[d] = n), n;
|
|
154
|
+
}
|
|
155
|
+
function j(e = {}) {
|
|
156
|
+
let t = e.useSingleDollar ?? !1;
|
|
157
|
+
return async (i) => {
|
|
158
|
+
if (typeof window > "u") return;
|
|
159
|
+
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)) {
|
|
163
|
+
o.catch(() => {});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await o;
|
|
167
|
+
let s = _();
|
|
168
|
+
await s?.startup?.promise, typeof s?.typesetPromise == "function" && (await s.typesetPromise([i]), g(i));
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { j as t };
|