@pie-players/pie-section-player 0.2.12 → 0.2.13
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 +28 -568
- package/dist/component-definitions.d.ts +0 -3
- package/dist/component-definitions.d.ts.map +1 -1
- package/dist/components/section-player-vertical-element.d.ts +2 -0
- package/dist/components/section-player-vertical-element.d.ts.map +1 -0
- package/dist/components/shared/composition.d.ts +9 -0
- package/dist/components/shared/composition.d.ts.map +1 -0
- package/dist/components/shared/player-action.d.ts +18 -0
- package/dist/components/shared/player-action.d.ts.map +1 -0
- package/dist/components/shared/player-preload.d.ts +37 -0
- package/dist/components/shared/player-preload.d.ts.map +1 -0
- package/dist/components/shared/section-player-runtime.d.ts +104 -0
- package/dist/components/shared/section-player-runtime.d.ts.map +1 -0
- package/dist/components/shared/section-player-view-state.d.ts +24 -0
- package/dist/components/shared/section-player-view-state.d.ts.map +1 -0
- package/dist/controllers/SectionContentService.d.ts.map +1 -1
- package/dist/controllers/SectionController.d.ts +5 -1
- package/dist/controllers/SectionController.d.ts.map +1 -1
- package/dist/controllers/SectionSessionService.d.ts +0 -1
- package/dist/controllers/SectionSessionService.d.ts.map +1 -1
- package/dist/controllers/toolkit-section-contracts.d.ts +2 -28
- package/dist/controllers/toolkit-section-contracts.d.ts.map +1 -1
- package/dist/controllers/types.d.ts +28 -1
- package/dist/controllers/types.d.ts.map +1 -1
- package/dist/pie-item-player-B1iGN63e.js +6189 -0
- package/dist/pie-section-player.d.ts +0 -8
- package/dist/pie-section-player.d.ts.map +1 -1
- package/dist/pie-section-player.js +56558 -11
- package/dist/player-preload-CQVG0Bih.js +705 -0
- package/dist/utils/player-preload.d.ts +2 -0
- package/dist/utils/player-preload.d.ts.map +1 -0
- package/dist/utils/player-preload.js +8 -0
- package/package.json +23 -32
- package/src/components/ItemShellElement.svelte +10 -1
- package/src/components/PieSectionPlayerBaseElement.svelte +21 -78
- package/src/components/PieSectionPlayerSplitPaneElement.svelte +236 -295
- package/src/components/PieSectionPlayerVerticalElement.svelte +424 -0
- package/src/components/shared/SectionItemCard.svelte +92 -0
- package/src/components/shared/SectionPassageCard.svelte +88 -0
- package/dist/ItemRenderer-MsjF_Beu.js +0 -467
- package/dist/PieItemModeLayoutElement-D7oTzA9T.js +0 -316
- package/dist/PieSplitPanelLayoutElement-GUtJ_NlF.js +0 -246
- package/dist/PieVerticalLayoutElement-BoA3FO5g.js +0 -194
- package/dist/controllers/SectionToolkitService.d.ts +0 -24
- package/dist/controllers/SectionToolkitService.d.ts.map +0 -1
- package/dist/controllers/SessionPersistenceStrategy.d.ts +0 -15
- package/dist/controllers/SessionPersistenceStrategy.d.ts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/pie-section-player-DJ5NcwdT.js +0 -17078
- package/dist/runtime/runtime-event-guards.d.ts +0 -4
- package/dist/runtime/runtime-event-guards.d.ts.map +0 -1
- package/src/PieSectionPlayer.svelte +0 -826
- package/src/components/ItemModeLayout.svelte +0 -172
- package/src/components/ItemNavigation.svelte +0 -96
- package/src/components/ItemPlayerBridge.svelte +0 -110
- package/src/components/ItemRenderer.svelte +0 -248
- package/src/components/ItemShell.svelte +0 -86
- package/src/components/layout-elements/PieItemModeLayoutElement.svelte +0 -47
- package/src/components/layout-elements/PieSplitPanelLayoutElement.svelte +0 -62
- package/src/components/layout-elements/PieVerticalLayoutElement.svelte +0 -41
- package/src/components/layouts/SplitPanelLayout.svelte +0 -385
- package/src/components/layouts/VerticalLayout.svelte +0 -193
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var M = (t, e, r) => e in t ? H(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var p = (t, e, r) => M(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
const O = /* @__PURE__ */ new Set([
|
|
5
|
+
"annotation-xml",
|
|
6
|
+
"color-profile",
|
|
7
|
+
"font-face",
|
|
8
|
+
"font-face-src",
|
|
9
|
+
"font-face-uri",
|
|
10
|
+
"font-face-format",
|
|
11
|
+
"font-face-name",
|
|
12
|
+
"missing-glyph"
|
|
13
|
+
]), F = /^[a-z][a-z0-9._-]*-[a-z0-9._-]*$/, R = (t, e = "custom element tag") => {
|
|
14
|
+
if (!t || typeof t != "string")
|
|
15
|
+
throw new Error(`Invalid ${e}: expected a non-empty string`);
|
|
16
|
+
const r = t.trim();
|
|
17
|
+
if (!r)
|
|
18
|
+
throw new Error(`Invalid ${e}: tag is empty`);
|
|
19
|
+
if (r !== r.toLowerCase())
|
|
20
|
+
throw new Error(`Invalid ${e} "${r}": custom element names must be lowercase`);
|
|
21
|
+
if (!r.includes("-"))
|
|
22
|
+
throw new Error(`Invalid ${e} "${r}": custom element names must include a hyphen`);
|
|
23
|
+
if (O.has(r))
|
|
24
|
+
throw new Error(`Invalid ${e} "${r}": this name is reserved by the HTML spec`);
|
|
25
|
+
if (!F.test(r))
|
|
26
|
+
throw new Error(`Invalid ${e} "${r}": allowed characters are lowercase letters, numbers, ".", "_" and "-"`);
|
|
27
|
+
return r;
|
|
28
|
+
}, j = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, B = "https://proxy.pie-api.com", x = `${B}/bundles/`;
|
|
29
|
+
function D(t) {
|
|
30
|
+
try {
|
|
31
|
+
const e = j?.[t];
|
|
32
|
+
if (typeof e == "string" && e.length > 0)
|
|
33
|
+
return e;
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
typeof window < "u" && window.PIE_BUILDER_ORIGIN_URL || D("PUBLIC_BUILDER_ORIGIN_URL");
|
|
38
|
+
typeof window < "u" && window.PIE_BUILDER_BUNDLE_URL || D("PUBLIC_BUILDER_BUNDLE_URL");
|
|
39
|
+
function T(t) {
|
|
40
|
+
const e = {};
|
|
41
|
+
return t.forEach((r) => {
|
|
42
|
+
const n = r.config?.elements || {};
|
|
43
|
+
Object.entries(n).forEach(([o, i]) => {
|
|
44
|
+
if (!e[o])
|
|
45
|
+
e[o] = i;
|
|
46
|
+
else if (e[o] !== i)
|
|
47
|
+
throw new Error(`Element version conflict: ${o} requires both ${e[o]} and ${i}. All items in a section must use the same version of each element.`);
|
|
48
|
+
});
|
|
49
|
+
}), e;
|
|
50
|
+
}
|
|
51
|
+
function N(t, e) {
|
|
52
|
+
const r = `[${t}]`;
|
|
53
|
+
return {
|
|
54
|
+
// Only debug method checks debugEnabledFn - it's checked dynamically on every call
|
|
55
|
+
debug: (n, ...o) => {
|
|
56
|
+
e() && console.debug(r, n, ...o);
|
|
57
|
+
},
|
|
58
|
+
// info, warn, error always log (not gated by debug flag)
|
|
59
|
+
info: (n, ...o) => console.info(r, n, ...o),
|
|
60
|
+
warn: (n, ...o) => console.warn(r, n, ...o),
|
|
61
|
+
error: (n, ...o) => console.error(r, n, ...o)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
class G {
|
|
65
|
+
constructor() {
|
|
66
|
+
p(this, "currentRenderer", null);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set the active math renderer
|
|
70
|
+
*
|
|
71
|
+
* This will update the window globals that PIE elements expect:
|
|
72
|
+
* - window["@pie-lib/math-rendering"]
|
|
73
|
+
* - window["_dll_pie_lib__math_rendering"]
|
|
74
|
+
*
|
|
75
|
+
* @param renderer - The renderer to use
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { createKatexRenderer } from '@pie-players/math-renderer-katex';
|
|
80
|
+
* import { mathRendererProvider } from '@pie-players/math-renderer-core';
|
|
81
|
+
*
|
|
82
|
+
* const renderer = await createKatexRenderer();
|
|
83
|
+
* mathRendererProvider.setRenderer(renderer);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
setRenderer(e) {
|
|
87
|
+
this.currentRenderer = e, this.updateWindowGlobals();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the current renderer
|
|
91
|
+
*
|
|
92
|
+
* @returns The active renderer, or null if none set
|
|
93
|
+
*/
|
|
94
|
+
getRenderer() {
|
|
95
|
+
return this.currentRenderer;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if a renderer has been initialized
|
|
99
|
+
*
|
|
100
|
+
* @returns true if a renderer is set
|
|
101
|
+
*/
|
|
102
|
+
isInitialized() {
|
|
103
|
+
return this.currentRenderer !== null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Update window globals for PIE element compatibility
|
|
107
|
+
*
|
|
108
|
+
* PIE elements expect to find math rendering on these two globals:
|
|
109
|
+
* - window["@pie-lib/math-rendering"] - Standard key
|
|
110
|
+
* - window["_dll_pie_lib__math_rendering"] - SystemJS/DLL key for IIFE bundles
|
|
111
|
+
*
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
updateWindowGlobals() {
|
|
115
|
+
if (typeof window > "u")
|
|
116
|
+
return;
|
|
117
|
+
const e = "@pie-lib/math-rendering", r = "_dll_pie_lib__math_rendering";
|
|
118
|
+
this.currentRenderer && (window[e] = this.currentRenderer, window[r] = this.currentRenderer);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const I = new G();
|
|
122
|
+
async function W(t = {}) {
|
|
123
|
+
const { _dll_pie_lib__math_rendering: e } = await import("./index-C1goqVqV.js");
|
|
124
|
+
return e;
|
|
125
|
+
}
|
|
126
|
+
async function k(t) {
|
|
127
|
+
if (!(typeof window > "u") && !I.isInitialized())
|
|
128
|
+
try {
|
|
129
|
+
const e = t ?? await W();
|
|
130
|
+
I.setRenderer(e), console.log("[MathRendering] ✅ Math rendering module initialized (both globals set)");
|
|
131
|
+
} catch (e) {
|
|
132
|
+
throw console.error("[MathRendering] ❌ Failed to initialize math rendering:", e), e;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
var E;
|
|
136
|
+
(function(t) {
|
|
137
|
+
t.player = "player.js", t.clientPlayer = "client-player.js", t.editor = "editor.js";
|
|
138
|
+
})(E || (E = {}));
|
|
139
|
+
var b;
|
|
140
|
+
(function(t) {
|
|
141
|
+
t.loading = "loading", t.loaded = "loaded";
|
|
142
|
+
})(b || (b = {}));
|
|
143
|
+
function C(t) {
|
|
144
|
+
return typeof t == "function" && "prototype" in t && t.prototype instanceof HTMLElement;
|
|
145
|
+
}
|
|
146
|
+
function V(t) {
|
|
147
|
+
return t && typeof t.PIE_REGISTRY == "object";
|
|
148
|
+
}
|
|
149
|
+
const $ = () => {
|
|
150
|
+
let t;
|
|
151
|
+
return V(window) ? t = window.PIE_REGISTRY : (t = {}, window.PIE_REGISTRY = t), t;
|
|
152
|
+
};
|
|
153
|
+
let u;
|
|
154
|
+
const h = {
|
|
155
|
+
delivery: {
|
|
156
|
+
subpath: "",
|
|
157
|
+
tagSuffix: ""
|
|
158
|
+
},
|
|
159
|
+
author: {
|
|
160
|
+
subpath: "/author",
|
|
161
|
+
tagSuffix: "-config",
|
|
162
|
+
fallback: "delivery"
|
|
163
|
+
// Fall back to delivery if author doesn't exist
|
|
164
|
+
},
|
|
165
|
+
print: {
|
|
166
|
+
subpath: "/print",
|
|
167
|
+
tagSuffix: "-print",
|
|
168
|
+
fallback: "delivery"
|
|
169
|
+
}
|
|
170
|
+
// Custom views can follow patterns like:
|
|
171
|
+
// 'delivery-mobile': { subpath: '/delivery-mobile', tagSuffix: '', fallback: 'delivery' }
|
|
172
|
+
// 'delivery-a11y': { subpath: '/delivery-a11y', tagSuffix: '', fallback: 'delivery' }
|
|
173
|
+
// 'delivery-simple': { subpath: '/delivery-simple', tagSuffix: '', fallback: 'delivery' }
|
|
174
|
+
};
|
|
175
|
+
class z {
|
|
176
|
+
constructor(e) {
|
|
177
|
+
p(this, "cdnBaseUrl");
|
|
178
|
+
p(this, "importMapInjected", !1);
|
|
179
|
+
this.cdnBaseUrl = e.cdnBaseUrl, u = N("esm-loader", e.debugEnabled || (() => !1));
|
|
180
|
+
}
|
|
181
|
+
extractPackageName(e) {
|
|
182
|
+
const r = e.split("@");
|
|
183
|
+
return r.length >= 3 ? `@${r[1]}` : r[0];
|
|
184
|
+
}
|
|
185
|
+
generateImportMap(e, r) {
|
|
186
|
+
const n = {}, o = r.viewConfig || h[r.view] || h.delivery;
|
|
187
|
+
for (const [i, a] of Object.entries(e)) {
|
|
188
|
+
const l = this.extractPackageName(a);
|
|
189
|
+
if (n[l] = this.resolvePackageUrl(a), o.subpath && (n[`${l}${o.subpath}`] = this.resolveSubpathUrl(a, o.subpath)), r.loadControllers && (n[`${l}/controller`] = this.resolveControllerUrl(a)), o.fallback) {
|
|
190
|
+
const m = h[o.fallback];
|
|
191
|
+
m?.subpath && (n[`${l}${m.subpath}`] = this.resolveSubpathUrl(a, m.subpath));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { imports: n };
|
|
195
|
+
}
|
|
196
|
+
isJsDelivrNpm() {
|
|
197
|
+
return this.cdnBaseUrl.includes("cdn.jsdelivr.net/npm");
|
|
198
|
+
}
|
|
199
|
+
resolvePackageUrl(e) {
|
|
200
|
+
return this.isJsDelivrNpm() ? `${this.cdnBaseUrl}/${e}/+esm` : `${this.cdnBaseUrl}/${e}`;
|
|
201
|
+
}
|
|
202
|
+
resolveControllerUrl(e) {
|
|
203
|
+
return this.isJsDelivrNpm() ? `${this.cdnBaseUrl}/${e}/controller/+esm` : `${this.cdnBaseUrl}/${e}/controller`;
|
|
204
|
+
}
|
|
205
|
+
resolveSubpathUrl(e, r) {
|
|
206
|
+
const n = r.startsWith("/") ? r.slice(1) : r;
|
|
207
|
+
return this.isJsDelivrNpm() ? `${this.cdnBaseUrl}/${e}/${n}/+esm` : `${this.cdnBaseUrl}/${e}/${n}`;
|
|
208
|
+
}
|
|
209
|
+
injectImportMap(e, r) {
|
|
210
|
+
const n = r.createElement("script");
|
|
211
|
+
n.type = "importmap", n.textContent = JSON.stringify(e, null, 2), r.head.appendChild(n);
|
|
212
|
+
}
|
|
213
|
+
async loadElement(e, r, n) {
|
|
214
|
+
const o = $(), i = n.viewConfig || h[n.view] || h.delivery;
|
|
215
|
+
try {
|
|
216
|
+
const a = this.extractPackageName(r), l = R(`${e}${i.tagSuffix}`, `element tag for ${a}`);
|
|
217
|
+
u.debug(`Loading element ${l} from ${a} (${r})`), u.debug(`View: ${n.view}, subpath: ${i.subpath}`);
|
|
218
|
+
const m = i.subpath ? `${a}${i.subpath}` : a;
|
|
219
|
+
let d, c;
|
|
220
|
+
try {
|
|
221
|
+
d = await import(
|
|
222
|
+
/* @vite-ignore */
|
|
223
|
+
m
|
|
224
|
+
), u.debug(`Module loaded for ${l}:`, d), u.debug("Module exports:", Object.keys(d)), n.view === "author" ? c = d.default || d.Configure || d.Element : n.view === "print" ? c = d.default || d.Print || d.Element : c = d.default || d.Element;
|
|
225
|
+
} catch (g) {
|
|
226
|
+
if (i.fallback) {
|
|
227
|
+
u.warn(`Failed to load ${m}, trying fallback: ${i.fallback}`);
|
|
228
|
+
const y = h[i.fallback];
|
|
229
|
+
let f;
|
|
230
|
+
y.subpath ? f = `${a}${y.subpath}` : f = a, d = await import(
|
|
231
|
+
/* @vite-ignore */
|
|
232
|
+
f
|
|
233
|
+
), c = d.default || d.Element, u.debug(`Loaded fallback view for ${l}`);
|
|
234
|
+
} else
|
|
235
|
+
throw g;
|
|
236
|
+
}
|
|
237
|
+
if (!c)
|
|
238
|
+
throw new Error(`No suitable element class found in ${m} for view ${n.view}`);
|
|
239
|
+
let w = null;
|
|
240
|
+
if (n.loadControllers)
|
|
241
|
+
try {
|
|
242
|
+
const g = await import(
|
|
243
|
+
/* @vite-ignore */
|
|
244
|
+
`${a}/controller`
|
|
245
|
+
);
|
|
246
|
+
u.debug(`Controller module loaded for ${l}:`, g), w = g.default || g, w ? u.debug(`Controller registered for ${l}`) : u.warn(`No controller export found for ${l}`);
|
|
247
|
+
} catch (g) {
|
|
248
|
+
u.warn(`Failed to load controller for ${l}:`, g);
|
|
249
|
+
}
|
|
250
|
+
o[l] = {
|
|
251
|
+
package: r,
|
|
252
|
+
status: b.loading,
|
|
253
|
+
tagName: l,
|
|
254
|
+
element: c,
|
|
255
|
+
controller: w,
|
|
256
|
+
config: null,
|
|
257
|
+
bundleType: "esm"
|
|
258
|
+
// Mark as ESM-loaded
|
|
259
|
+
}, customElements.get(l) ? (u.debug(`Element ${l} already registered`), o[l] = {
|
|
260
|
+
...o[l],
|
|
261
|
+
status: b.loaded
|
|
262
|
+
}) : C(c) ? (customElements.define(l, class extends c {
|
|
263
|
+
}), u.debug(`Registered custom element: ${l}`), o[l] = {
|
|
264
|
+
...o[l],
|
|
265
|
+
status: b.loaded
|
|
266
|
+
}) : u.warn("No Element export found in module");
|
|
267
|
+
} catch (a) {
|
|
268
|
+
throw u.error(`Failed to load element ${e}:`, a), a;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
getController(e) {
|
|
272
|
+
return $()[e]?.controller || null;
|
|
273
|
+
}
|
|
274
|
+
async elementsHaveLoaded(e) {
|
|
275
|
+
const r = e.map((n) => (u.debug(`Waiting for ${n.tag} to be defined`), customElements.whenDefined(n.tag)));
|
|
276
|
+
return await Promise.all(r), { elements: e, val: !0 };
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Load PIE elements with specified view/variant
|
|
280
|
+
*
|
|
281
|
+
* @param contentConfig - Item config with elements
|
|
282
|
+
* @param doc - Document to inject import maps into
|
|
283
|
+
* @param options - Loading options (view, controllers, etc.)
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* // Load delivery view with controllers
|
|
287
|
+
* await loader.load(config, document, { view: 'delivery', loadControllers: true });
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* // Load author view (configuration UI)
|
|
291
|
+
* await loader.load(config, document, { view: 'author', loadControllers: false });
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* // Load custom mobile-optimized view with fallback
|
|
295
|
+
* await loader.load(config, document, {
|
|
296
|
+
* view: 'delivery-mobile',
|
|
297
|
+
* viewConfig: { subpath: '/delivery-mobile', tagSuffix: '', fallback: 'delivery' },
|
|
298
|
+
* loadControllers: true
|
|
299
|
+
* });
|
|
300
|
+
*/
|
|
301
|
+
async load(e, r, n) {
|
|
302
|
+
if (u.debug("load() called with options:", n), u.debug("contentConfig:", e), !e?.elements) {
|
|
303
|
+
u.warn("No elements in config");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const o = n.viewConfig || h[n.view] || h.delivery;
|
|
307
|
+
if (await k(), this.importMapInjected)
|
|
308
|
+
u.debug("Import map already injected, skipping");
|
|
309
|
+
else {
|
|
310
|
+
u.debug("Generating import map for view:", n.view);
|
|
311
|
+
const l = this.generateImportMap(e.elements, n);
|
|
312
|
+
u.debug("Import map:", l), this.injectImportMap(l, r), this.importMapInjected = !0, u.debug("Import map injected");
|
|
313
|
+
}
|
|
314
|
+
const i = Object.keys(e.elements);
|
|
315
|
+
u.debug("Loading elements:", i), await Promise.all(i.map((l) => this.loadElement(l, e.elements[l], n))), u.debug("All elements loaded"), u.debug("Waiting for custom elements to be defined");
|
|
316
|
+
const a = i.map((l) => R(`${l}${o.tagSuffix}`, `element tag for view "${n.view}"`));
|
|
317
|
+
await Promise.all(a.map((l) => customElements.whenDefined(l))), u.debug("All custom elements defined");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
class J {
|
|
321
|
+
constructor(e) {
|
|
322
|
+
p(this, "loader");
|
|
323
|
+
this.loader = new z({
|
|
324
|
+
cdnBaseUrl: e.esmCdnUrl,
|
|
325
|
+
debugEnabled: e.debugEnabled
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Load elements directly from an element map
|
|
330
|
+
*
|
|
331
|
+
* @param elements - Map of element tag names to package versions
|
|
332
|
+
* @param options - Loading options
|
|
333
|
+
*/
|
|
334
|
+
async loadElements(e, r) {
|
|
335
|
+
await this.loader.load({ elements: e }, document, {
|
|
336
|
+
view: r?.view || "delivery",
|
|
337
|
+
loadControllers: r?.needsControllers ?? !0
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Extract and load elements from items
|
|
342
|
+
*
|
|
343
|
+
* Automatically aggregates unique elements from all items and loads them once.
|
|
344
|
+
*
|
|
345
|
+
* @param items - Array of items to extract elements from
|
|
346
|
+
* @param options - Loading options
|
|
347
|
+
* @throws Error if element version conflicts are detected
|
|
348
|
+
*/
|
|
349
|
+
async loadFromItems(e, r) {
|
|
350
|
+
const n = T(e);
|
|
351
|
+
await this.loadElements(n, r);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const Y = (t) => {
|
|
355
|
+
if (!t)
|
|
356
|
+
throw new Error("Parameter is required: input");
|
|
357
|
+
const e = t.charAt(0) === "@" ? t.match(/^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/) : t.match(/^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/);
|
|
358
|
+
if (!e)
|
|
359
|
+
throw new Error(`[parse-package-name] "${t}" is not a valid string`);
|
|
360
|
+
return {
|
|
361
|
+
name: e[1],
|
|
362
|
+
path: e[2] || "",
|
|
363
|
+
version: e[3] || ""
|
|
364
|
+
};
|
|
365
|
+
}, q = (t) => t.split("+").map((e) => Y(e).name).join("+");
|
|
366
|
+
let s;
|
|
367
|
+
const K = "https://proxy.pie-api.com/bundles/";
|
|
368
|
+
typeof window < "u" && !window.pieHelpers && (window.pieHelpers = {
|
|
369
|
+
loadingScripts: {},
|
|
370
|
+
loadingPromises: {}
|
|
371
|
+
});
|
|
372
|
+
class Q {
|
|
373
|
+
constructor(e) {
|
|
374
|
+
p(this, "config");
|
|
375
|
+
this.config = e, s = N("iife-loader", e.debugEnabled || (() => !1));
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Get the bundle URL based on config elements
|
|
379
|
+
*/
|
|
380
|
+
getBundleUrl(e, r, n) {
|
|
381
|
+
const o = Object.keys(e || {}).sort().join(",");
|
|
382
|
+
if (n?.url) {
|
|
383
|
+
const d = n.url.includes("?") ? "&" : "?", c = o ? `${n.url}${d}elements=${encodeURIComponent(o)}` : n.url;
|
|
384
|
+
return s.debug("Using explicit bundle URL from config:", c), c;
|
|
385
|
+
}
|
|
386
|
+
const i = Object.values(e).join("+");
|
|
387
|
+
let a = this.config.bundleHost || K;
|
|
388
|
+
a = a.trim(), a = a.replace(/\/+$/, "") + "/";
|
|
389
|
+
const l = `${a}${encodeURI(i)}/${r}`, m = o ? `${l}?elements=${encodeURIComponent(o)}` : l;
|
|
390
|
+
return s.debug("Using bundle host URL:", m), m;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Load an IIFE bundle from the specified URL
|
|
394
|
+
*/
|
|
395
|
+
async loadBundleScript(e, r) {
|
|
396
|
+
return new Promise((n, o) => {
|
|
397
|
+
const i = r.createElement("script");
|
|
398
|
+
i.src = e, i.defer = !0, i.setAttribute("data-pie-bundle", "true"), i.onload = () => {
|
|
399
|
+
s.debug("Bundle loaded successfully from:", e), n();
|
|
400
|
+
}, i.onerror = () => {
|
|
401
|
+
const a = `Failed to load IIFE bundle from: ${e}`;
|
|
402
|
+
s.error(a), o(new Error(a));
|
|
403
|
+
}, r.head.appendChild(i);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
whenDefinedWithTimeout(e) {
|
|
407
|
+
const r = this.config.whenDefinedTimeoutMs ?? 5e3;
|
|
408
|
+
return Promise.race([
|
|
409
|
+
customElements.whenDefined(e).then(() => {
|
|
410
|
+
}),
|
|
411
|
+
new Promise((n, o) => setTimeout(() => o(new Error(`Timeout waiting for ${e}`)), r))
|
|
412
|
+
]);
|
|
413
|
+
}
|
|
414
|
+
createEmptyConfigure() {
|
|
415
|
+
return class extends HTMLElement {
|
|
416
|
+
constructor() {
|
|
417
|
+
super(...arguments);
|
|
418
|
+
p(this, "_model");
|
|
419
|
+
p(this, "_configuration");
|
|
420
|
+
}
|
|
421
|
+
set model(n) {
|
|
422
|
+
this._model = n;
|
|
423
|
+
}
|
|
424
|
+
get model() {
|
|
425
|
+
return this._model;
|
|
426
|
+
}
|
|
427
|
+
set configuration(n) {
|
|
428
|
+
this._configuration = n;
|
|
429
|
+
}
|
|
430
|
+
get configuration() {
|
|
431
|
+
return this._configuration;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Register elements from the loaded IIFE bundle into the PIE registry
|
|
437
|
+
*/
|
|
438
|
+
async registerElementsFromBundle(e, r, n) {
|
|
439
|
+
const o = $();
|
|
440
|
+
if (!window.pie || !window.pie.default)
|
|
441
|
+
throw new Error("window.pie not found - IIFE bundle did not load correctly");
|
|
442
|
+
const i = window.pie.default;
|
|
443
|
+
s.debug("Found window.pie.default with packages:", Object.keys(i)), s.debug("Elements to register:", e), s.debug("Bundle type:", n);
|
|
444
|
+
const a = [], l = n === E.editor;
|
|
445
|
+
for (const [m, d] of Object.entries(e))
|
|
446
|
+
try {
|
|
447
|
+
const c = q(d);
|
|
448
|
+
s.debug(`Registering element ${m} from package ${c} (full: ${d})`);
|
|
449
|
+
const w = i[c];
|
|
450
|
+
if (!w)
|
|
451
|
+
throw new Error(`Package "${c}" not found in IIFE bundle. Available: ${Object.keys(i).join(", ")}`);
|
|
452
|
+
const g = l ? w.Configure || this.createEmptyConfigure() : w.Element, y = r ? w.controller : null, f = R(l ? `${m}-config` : m, `element tag for ${c}`);
|
|
453
|
+
if (!g) {
|
|
454
|
+
const v = l ? "Configure" : "Element";
|
|
455
|
+
throw new Error(`No ${v} class found in package ${c}`);
|
|
456
|
+
}
|
|
457
|
+
if (o[f] = {
|
|
458
|
+
package: d,
|
|
459
|
+
status: b.loading,
|
|
460
|
+
tagName: f,
|
|
461
|
+
element: g,
|
|
462
|
+
controller: y,
|
|
463
|
+
config: w.config || null,
|
|
464
|
+
bundleType: n || "iife"
|
|
465
|
+
// Mark bundle type
|
|
466
|
+
}, customElements.get(f))
|
|
467
|
+
s.debug(`Element ${f} already registered`), o[f] = {
|
|
468
|
+
...o[f],
|
|
469
|
+
status: b.loaded
|
|
470
|
+
};
|
|
471
|
+
else if (C(g)) {
|
|
472
|
+
customElements.define(f, class extends g {
|
|
473
|
+
}), s.debug(`Registered custom element: ${f}`);
|
|
474
|
+
const v = this.whenDefinedWithTimeout(f).then(() => {
|
|
475
|
+
o[f] = {
|
|
476
|
+
...o[f],
|
|
477
|
+
status: b.loaded
|
|
478
|
+
}, s.debug(`Element ${f} fully loaded`);
|
|
479
|
+
}).catch((A) => {
|
|
480
|
+
s.error(`Failed to define element ${f}:`, A);
|
|
481
|
+
});
|
|
482
|
+
a.push(v);
|
|
483
|
+
} else
|
|
484
|
+
s.warn(`Element class for ${c} is not a valid custom element constructor`);
|
|
485
|
+
} catch (c) {
|
|
486
|
+
throw s.error(`Failed to register element ${m}:`, c), c;
|
|
487
|
+
}
|
|
488
|
+
await Promise.all(a), s.debug("All elements registered and defined");
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Load PIE elements from IIFE bundle
|
|
492
|
+
*
|
|
493
|
+
* @param contentConfig - Item config with elements
|
|
494
|
+
* @param doc - Document to inject script into
|
|
495
|
+
* @param bundleType - Type of bundle (BundleType.player, BundleType.clientPlayer, or BundleType.editor)
|
|
496
|
+
* @param needsControllers - Whether controllers are needed
|
|
497
|
+
*/
|
|
498
|
+
async load(e, r, n, o) {
|
|
499
|
+
if (s.debug("load() called"), s.debug("Bundle type:", n), s.debug("Needs controllers:", o), s.debug("Content config:", e), !e?.elements) {
|
|
500
|
+
s.warn("No elements in config");
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
await k();
|
|
504
|
+
const i = this.getBundleUrl(e.elements, n, e.bundle), a = r.querySelector(`script[src="${i}"]`), l = Array.from(r.querySelectorAll('script[data-pie-bundle="true"]')).find((d) => d.getAttribute("src") !== i);
|
|
505
|
+
if (l && (s.debug("Removing previously loaded bundle:", l.getAttribute("src")), l.remove(), window.pie && delete window.pie), a && window.pie && window.pie.default) {
|
|
506
|
+
s.debug("Exact bundle already loaded, registering elements"), await this.registerElementsFromBundle(e.elements, o, n), s.debug("✅ Elements registered from existing bundle");
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (window.pieHelpers?.loadingPromises?.[i]) {
|
|
510
|
+
s.debug("Bundle is already loading, waiting for existing load:", i), await window.pieHelpers.loadingPromises[i], s.debug("Existing bundle load completed, registering elements"), await this.registerElementsFromBundle(e.elements, o, n), s.debug("✅ Elements registered from already-loading bundle");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
window.pieHelpers && (window.pieHelpers.loadingScripts[i] = !0);
|
|
514
|
+
const m = (async () => {
|
|
515
|
+
try {
|
|
516
|
+
s.debug("Loading IIFE bundle from:", i);
|
|
517
|
+
try {
|
|
518
|
+
await this.loadBundleScript(i, r);
|
|
519
|
+
} catch (d) {
|
|
520
|
+
if (this.config.reFetchBundle) {
|
|
521
|
+
const c = i + (i.includes("?") ? "&" : "?") + `t=${Date.now()}`;
|
|
522
|
+
s.warn("[IifePieLoader] Initial bundle load failed, retrying with cache bust:", c), await this.loadBundleScript(c, r);
|
|
523
|
+
} else
|
|
524
|
+
throw d;
|
|
525
|
+
}
|
|
526
|
+
s.debug("Registering elements from loaded bundle"), await this.registerElementsFromBundle(e.elements, o, n), s.debug("✅ IIFE bundle loaded and elements registered");
|
|
527
|
+
} catch (d) {
|
|
528
|
+
throw s.error("Failed to load IIFE bundle:", d), window.pieHelpers && (delete window.pieHelpers.loadingPromises[i], delete window.pieHelpers.loadingScripts[i]), d;
|
|
529
|
+
} finally {
|
|
530
|
+
window.pieHelpers?.loadingPromises?.[i] && delete window.pieHelpers.loadingPromises[i];
|
|
531
|
+
}
|
|
532
|
+
})();
|
|
533
|
+
window.pieHelpers && (window.pieHelpers.loadingPromises[i] = m), await m;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Get controller for a specific element tag
|
|
537
|
+
*/
|
|
538
|
+
getController(e) {
|
|
539
|
+
return $()[e]?.controller || null;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Wait for elements to be fully loaded
|
|
543
|
+
*/
|
|
544
|
+
async elementsHaveLoaded(e) {
|
|
545
|
+
const r = e.map((n) => (s.debug(`Waiting for ${n.tag} to be defined`), this.whenDefinedWithTimeout(n.tag)));
|
|
546
|
+
return await Promise.all(r), { elements: e, val: !0 };
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
class X {
|
|
550
|
+
constructor(e) {
|
|
551
|
+
p(this, "loader");
|
|
552
|
+
this.loader = new Q({
|
|
553
|
+
bundleHost: e.bundleHost,
|
|
554
|
+
debugEnabled: e.debugEnabled
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Load elements directly from an element map
|
|
559
|
+
*
|
|
560
|
+
* @param elements - Map of element tag names to package versions
|
|
561
|
+
* @param options - Loading options
|
|
562
|
+
*/
|
|
563
|
+
async loadElements(e, r) {
|
|
564
|
+
await this.loader.load({ elements: e }, document, r?.bundleType || E.clientPlayer, r?.needsControllers ?? !0);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Extract and load elements from items
|
|
568
|
+
*
|
|
569
|
+
* Automatically aggregates unique elements from all items and loads them once.
|
|
570
|
+
*
|
|
571
|
+
* @param items - Array of items to extract elements from
|
|
572
|
+
* @param options - Loading options
|
|
573
|
+
* @throws Error if element version conflicts are detected
|
|
574
|
+
*/
|
|
575
|
+
async loadFromItems(e, r) {
|
|
576
|
+
const n = T(e);
|
|
577
|
+
await this.loadElements(n, r);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
var U;
|
|
581
|
+
(function(t) {
|
|
582
|
+
t.SAVE = "save", t.MODEL = "model", t.SCORE = "score", t.MANUAL_SCORE = "manual-score";
|
|
583
|
+
})(U || (U = {}));
|
|
584
|
+
var _;
|
|
585
|
+
(function(t) {
|
|
586
|
+
t.AUTO = "auto", t.MANUAL = "manual";
|
|
587
|
+
})(_ || (_ = {}));
|
|
588
|
+
var L;
|
|
589
|
+
(function(t) {
|
|
590
|
+
t.GATHER = "gather", t.VIEW = "view", t.EVALUATE = "evaluate";
|
|
591
|
+
})(L || (L = {}));
|
|
592
|
+
var P;
|
|
593
|
+
(function(t) {
|
|
594
|
+
t.PENDING = "pending", t.IN_PROGRESS = "in_progress", t.COMPLETED = "completed", t.FAILED = "failed";
|
|
595
|
+
})(P || (P = {}));
|
|
596
|
+
var S;
|
|
597
|
+
(function(t) {
|
|
598
|
+
t[t.ROOT = 0] = "ROOT", t[t.SUBJECT = 1] = "SUBJECT", t[t.LEVEL = 2] = "LEVEL", t[t.STANDARD = 3] = "STANDARD";
|
|
599
|
+
})(S || (S = {}));
|
|
600
|
+
E.player;
|
|
601
|
+
const Z = 15e3;
|
|
602
|
+
function ie(t) {
|
|
603
|
+
return t.map((e, r) => {
|
|
604
|
+
const n = e?.entity || {}, o = typeof n.id == "string" && n.id || `renderable-${r}`, i = typeof n.version == "string" && n.version || (typeof n.version == "number" ? String(n.version) : "") || (typeof n.config?.version == "string" ? n.config.version : "");
|
|
605
|
+
return `${o}:${i}`;
|
|
606
|
+
}).join("|");
|
|
607
|
+
}
|
|
608
|
+
function ee(t) {
|
|
609
|
+
return t?.mode === "author" ? "author" : "delivery";
|
|
610
|
+
}
|
|
611
|
+
function te(t) {
|
|
612
|
+
return [
|
|
613
|
+
t.strategy,
|
|
614
|
+
t.loaderView,
|
|
615
|
+
t.strategy === "esm" ? t.esmCdnUrl : t.bundleHost,
|
|
616
|
+
t.renderablesSignature
|
|
617
|
+
].join("|");
|
|
618
|
+
}
|
|
619
|
+
async function re(t) {
|
|
620
|
+
if (t.renderables.length === 0 || t.strategy === "preloaded")
|
|
621
|
+
return;
|
|
622
|
+
let e = null;
|
|
623
|
+
if (t.strategy === "esm")
|
|
624
|
+
e = new J({
|
|
625
|
+
esmCdnUrl: t.esmCdnUrl,
|
|
626
|
+
debugEnabled: () => !1
|
|
627
|
+
});
|
|
628
|
+
else {
|
|
629
|
+
if (!t.bundleHost)
|
|
630
|
+
throw new Error("Missing iife bundleHost");
|
|
631
|
+
e = new X({
|
|
632
|
+
bundleHost: t.bundleHost,
|
|
633
|
+
debugEnabled: () => !1
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
const r = window.setTimeout(
|
|
637
|
+
() => t.onTimeout(),
|
|
638
|
+
t.timeoutMs || Z
|
|
639
|
+
);
|
|
640
|
+
try {
|
|
641
|
+
await e.loadFromItems(t.renderables, {
|
|
642
|
+
view: t.loaderView,
|
|
643
|
+
needsControllers: !0
|
|
644
|
+
});
|
|
645
|
+
} finally {
|
|
646
|
+
window.clearTimeout(r);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function le(t) {
|
|
650
|
+
const e = String(
|
|
651
|
+
t.resolvedPlayerProps?.loaderOptions?.esmCdnUrl || "https://esm.sh"
|
|
652
|
+
), r = String(
|
|
653
|
+
t.resolvedPlayerProps?.loaderOptions?.bundleHost || t.iifeBundleHost || ""
|
|
654
|
+
).trim(), n = ee(t.resolvedPlayerEnv), o = te({
|
|
655
|
+
strategy: t.strategy,
|
|
656
|
+
loaderView: n,
|
|
657
|
+
esmCdnUrl: e,
|
|
658
|
+
bundleHost: r,
|
|
659
|
+
renderablesSignature: t.renderablesSignature
|
|
660
|
+
}), i = t.getState();
|
|
661
|
+
if (o === i.lastPreloadSignature)
|
|
662
|
+
return;
|
|
663
|
+
if (t.setState({ lastPreloadSignature: o }), t.renderables.length === 0) {
|
|
664
|
+
t.setState({ elementsLoaded: !0 });
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const a = i.preloadRunToken + 1;
|
|
668
|
+
if (t.setState({
|
|
669
|
+
preloadRunToken: a,
|
|
670
|
+
elementsLoaded: !1
|
|
671
|
+
}), t.strategy === "preloaded") {
|
|
672
|
+
t.setState({ elementsLoaded: !0 });
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (t.strategy !== "esm" && !r) {
|
|
676
|
+
console.warn(
|
|
677
|
+
`[${t.componentTag}] Missing iifeBundleHost for element preloading; rendering without preload.`
|
|
678
|
+
), t.setState({ elementsLoaded: !0 });
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
re({
|
|
682
|
+
strategy: t.strategy,
|
|
683
|
+
renderables: t.renderables,
|
|
684
|
+
loaderView: n,
|
|
685
|
+
esmCdnUrl: e,
|
|
686
|
+
bundleHost: r,
|
|
687
|
+
onTimeout: () => {
|
|
688
|
+
a === t.getState().preloadRunToken && (console.warn(
|
|
689
|
+
`[${t.componentTag}] Element preloading timed out; continuing render without preload.`
|
|
690
|
+
), t.setState({ elementsLoaded: !0 }));
|
|
691
|
+
}
|
|
692
|
+
}).then(() => {
|
|
693
|
+
a === t.getState().preloadRunToken && t.setState({ elementsLoaded: !0 });
|
|
694
|
+
}).catch((l) => {
|
|
695
|
+
console.error(`[${t.componentTag}] Failed to preload PIE elements:`, l), a === t.getState().preloadRunToken && t.setState({ elementsLoaded: !0 });
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
export {
|
|
699
|
+
ee as a,
|
|
700
|
+
te as b,
|
|
701
|
+
ie as g,
|
|
702
|
+
le as o,
|
|
703
|
+
re as p,
|
|
704
|
+
R as v
|
|
705
|
+
};
|