@pie-element/element-player 0.1.1

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 ADDED
@@ -0,0 +1,129 @@
1
+ # PIE Element Player
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'"
28
+
29
+ ---
30
+
31
+ ## Overview
32
+
33
+ The element player is a **standalone web component bundle** (`pie-element-player.js`) that can be dropped into any HTML page with a simple `<script>` tag. It loads PIE elements via dynamic ESM imports.
34
+
35
+ ## Usage
36
+
37
+ ### ESM Player
38
+
39
+ For elements with import maps:
40
+
41
+ ```html
42
+ <!DOCTYPE html>
43
+ <html>
44
+ <head>
45
+ <title>PIE Element Demo</title>
46
+ </head>
47
+ <body>
48
+ <pie-esm-element-player
49
+ id="player"
50
+ element-name="hotspot"
51
+ ></pie-esm-element-player>
52
+
53
+ <!-- Import map for module resolution -->
54
+ <script type="importmap">
55
+ {
56
+ "imports": {
57
+ "@pie-element/": "./packages/elements-svelte/"
58
+ }
59
+ }
60
+ </script>
61
+
62
+ <!-- Load the player bundle -->
63
+ <script type="module" src="/packages/shared/element-player/dist/pie-element-player.js"></script>
64
+
65
+ <script type="module">
66
+ const player = document.getElementById('player');
67
+ player.model = { /* PIE model */ };
68
+ player.session = { /* session data */ };
69
+ </script>
70
+ </body>
71
+ </html>
72
+ ```
73
+
74
+ ## Architecture
75
+
76
+ ### ESM Players
77
+
78
+ **Interactive Player (`<pie-esm-element-player>`):**
79
+
80
+ - Loads elements via dynamic ESM imports: `import('@pie-element/hotspot')`
81
+ - Handles session state and user interactions
82
+ - Manages math rendering internally (MathJax)
83
+ - Emits `session-changed` events
84
+ - Works with both React and Svelte elements
85
+
86
+ **Print Player (`<pie-esm-print-player>`):**
87
+
88
+ - Loads print exports: `import('@pie-element/hotspot/print')`
89
+ - Stateless (no session management)
90
+ - Optimized for print layouts
91
+ - Manages math rendering internally (MathJax)
92
+ - Role-based rendering (student/instructor)
93
+
94
+ **Both players:**
95
+
96
+ - Use import maps for module resolution
97
+ - Self-contained (no external setup needed)
98
+ - Handle math rendering automatically
99
+ - Support for both React and Svelte elements
100
+
101
+ ## Testing Elements Locally
102
+
103
+ Use the existing demo commands to test elements:
104
+
105
+ ```bash
106
+ # Start demo server for Svelte elements
107
+ bun cli dev:demo hotspot
108
+ ```
109
+
110
+ **Prerequisites:**
111
+
112
+ - Element must be built: `bun run turbo build --filter @pie-element/hotspot`
113
+ - Element player must be built: `bun run turbo build --filter @pie-element/element-player`
114
+
115
+ ## Development
116
+
117
+ ### Local Development
118
+
119
+ To test changes to player components:
120
+
121
+ ```bash
122
+ # Build element-player
123
+ cd packages/shared/element-player
124
+ bun run build
125
+
126
+ # Run element demo
127
+ cd ../../../
128
+ bun cli dev:demo hotspot
129
+ ```
@@ -0,0 +1,15 @@
1
+ /**
2
+ * PIE Element Player
3
+ *
4
+ * Self-contained web components for rendering PIE elements.
5
+ * Handles element loading, math rendering, and session management internally.
6
+ *
7
+ * Usage:
8
+ * <pie-esm-element-player element-name="hotspot"></pie-esm-element-player>
9
+ * <pie-esm-print-player element-name="hotspot" role="student"></pie-esm-print-player>
10
+ */
11
+ import './app.css';
12
+ export { EsmElementPlayer, EsmPrintPlayer } from './players';
13
+ import './players';
14
+ export type { ElementPlayerProps, PieController, Tab } from './lib/types';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,WAAW,CAAC;AAGnB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG7D,OAAO,WAAW,CAAC;AAGnB,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * PIE Element Loader
3
+ *
4
+ * Dynamically loads PIE elements from CDN and registers them as custom elements.
5
+ * Based on the ESM loader pattern from pie-players.
6
+ */
7
+ /**
8
+ * Load and register a PIE element as a custom element
9
+ *
10
+ * @param packagePath - Package path (e.g., '@pie-element/hotspot' or '@pie-element/hotspot/configure')
11
+ * @param tagName - Custom element tag name (e.g., 'hotspot-element')
12
+ * @param cdnUrl - Base CDN URL (e.g., 'http://localhost:5179' or 'https://esm.sh')
13
+ * @param debug - Enable debug logging
14
+ * @param optional - If true, suppress error logging (for optional components like configure)
15
+ */
16
+ export declare function loadElement(packagePath: string, tagName: string, cdnUrl: string, debug?: boolean, optional?: boolean): Promise<void>;
17
+ /**
18
+ * Load a PIE controller module
19
+ *
20
+ * @param packageName - Package name (e.g., '@pie-element/hotspot')
21
+ * @param cdnUrl - Base CDN URL
22
+ * @param debug - Enable debug logging
23
+ * @returns Controller object with model/score/outcome methods
24
+ */
25
+ export declare function loadController(packageName: string, cdnUrl: string, debug?: boolean): Promise<any>;
26
+ //# sourceMappingURL=element-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-loader.d.ts","sourceRoot":"","sources":["../../src/lib/element-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,EACtB,QAAQ,GAAE,OAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAiEf;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAe,GACrB,OAAO,CAAC,GAAG,CAAC,CAiDd"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * TypeScript type definitions for PIE Element Player
3
+ */
4
+ export interface ElementPlayerProps {
5
+ elementName: string;
6
+ cdnUrl?: string;
7
+ model?: any;
8
+ session?: any;
9
+ mode?: 'gather' | 'view' | 'evaluate';
10
+ showConfigure?: boolean;
11
+ addCorrectResponse?: boolean;
12
+ debug?: boolean;
13
+ }
14
+ export interface PieController {
15
+ model?: (config: any, session: any, env: any) => Promise<any>;
16
+ score?: (model: any, session: any) => Promise<any>;
17
+ outcome?: (model: any, session: any, env: any) => Promise<any>;
18
+ createCorrectResponseSession?: (model: any, env: any) => Promise<any>;
19
+ }
20
+ export interface Tab {
21
+ id: string;
22
+ label: string;
23
+ description?: string;
24
+ disabled?: boolean;
25
+ }
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACtC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9D,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/D,4BAA4B,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,50 @@
1
+ const c = "https://cdn.jsdelivr.net/npm/mathjax@4/tex-chtml.js";
2
+ let n = null;
3
+ function u(o) {
4
+ return typeof window > "u" || window.MathJax?.version ? Promise.resolve() : n || (n = new Promise((a, s) => {
5
+ const { useSingleDollar: l = !1, accessibility: r = !0, loadFonts: i = !0, srcUrl: d } = o, e = {
6
+ tex: {
7
+ packages: ["base", "ams", "autoload"],
8
+ macros: {
9
+ parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
10
+ overarc: "\\overparen",
11
+ napprox: "\\not\\approx",
12
+ longdiv: "\\enclose{longdiv}"
13
+ }
14
+ },
15
+ options: {
16
+ enableMenu: r,
17
+ enableExplorer: r
18
+ },
19
+ startup: {
20
+ ready: () => {
21
+ window.MathJax?.startup.defaultReady && (window.MathJax.startup.defaultReady(), a());
22
+ },
23
+ defaultReady: () => {
24
+ }
25
+ }
26
+ };
27
+ l && e.tex && (e.tex.inlineMath = [
28
+ ["$", "$"],
29
+ ["\\(", "\\)"]
30
+ ], e.tex.processEscapes = !0), i || (e.chtml = { fontURL: "" }), window.MathJax = e;
31
+ const t = document.createElement("script");
32
+ t.src = d || c, t.async = !0, t.onload = () => {
33
+ setTimeout(a, 100);
34
+ }, t.onerror = () => {
35
+ s(new Error("Failed to load MathJax"));
36
+ }, document.head.appendChild(t);
37
+ }), n);
38
+ }
39
+ function p(o = {}) {
40
+ return async (a) => {
41
+ if (await u(o), !window.MathJax?.typesetPromise) {
42
+ console.warn("[mathjax-renderer] MathJax not loaded or missing typesetPromise.");
43
+ return;
44
+ }
45
+ await window.MathJax.typesetPromise([a]);
46
+ };
47
+ }
48
+ export {
49
+ p as m
50
+ };