@pie-players/pie-players-shared 0.2.0
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/dist/config/profile.d.ts +15 -0
- package/dist/config/profile.d.ts.map +1 -0
- package/dist/config/profile.js +27 -0
- package/dist/config/profile.js.map +1 -0
- package/dist/i18n/index.d.ts +13 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +12 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/loader.d.ts +36 -0
- package/dist/i18n/loader.d.ts.map +1 -0
- package/dist/i18n/loader.js +133 -0
- package/dist/i18n/loader.js.map +1 -0
- package/dist/i18n/scripts/check-coverage.d.ts +16 -0
- package/dist/i18n/scripts/check-coverage.d.ts.map +1 -0
- package/dist/i18n/scripts/check-coverage.js +262 -0
- package/dist/i18n/scripts/check-coverage.js.map +1 -0
- package/dist/i18n/scripts/scan-hardcoded.d.ts +16 -0
- package/dist/i18n/scripts/scan-hardcoded.d.ts.map +1 -0
- package/dist/i18n/scripts/scan-hardcoded.js +266 -0
- package/dist/i18n/scripts/scan-hardcoded.js.map +1 -0
- package/dist/i18n/simple-i18n.d.ts +69 -0
- package/dist/i18n/simple-i18n.d.ts.map +1 -0
- package/dist/i18n/simple-i18n.js +199 -0
- package/dist/i18n/simple-i18n.js.map +1 -0
- package/dist/i18n/translations/ar/common.json +36 -0
- package/dist/i18n/translations/ar/toolkit.json +48 -0
- package/dist/i18n/translations/ar/tools.json +109 -0
- package/dist/i18n/translations/en/common.json +36 -0
- package/dist/i18n/translations/en/toolkit.json +48 -0
- package/dist/i18n/translations/en/tools.json +109 -0
- package/dist/i18n/translations/es/common.json +36 -0
- package/dist/i18n/translations/es/toolkit.json +48 -0
- package/dist/i18n/translations/es/tools.json +109 -0
- package/dist/i18n/translations/zh/common.json +36 -0
- package/dist/i18n/translations/zh/toolkit.json +48 -0
- package/dist/i18n/translations/zh/tools.json +109 -0
- package/dist/i18n/types.d.ts +58 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +8 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/i18n/use-i18n-standalone.svelte.d.ts +87 -0
- package/dist/i18n/use-i18n-standalone.svelte.d.ts.map +1 -0
- package/dist/i18n/use-i18n-standalone.svelte.js +151 -0
- package/dist/i18n/use-i18n-standalone.svelte.js.map +1 -0
- package/dist/i18n/use-i18n.svelte.d.ts +67 -0
- package/dist/i18n/use-i18n.svelte.d.ts.map +1 -0
- package/dist/i18n/use-i18n.svelte.js +144 -0
- package/dist/i18n/use-i18n.svelte.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +53 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +53 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/providers/BaseInstrumentationProvider.d.ts +197 -0
- package/dist/instrumentation/providers/BaseInstrumentationProvider.d.ts.map +1 -0
- package/dist/instrumentation/providers/BaseInstrumentationProvider.js +267 -0
- package/dist/instrumentation/providers/BaseInstrumentationProvider.js.map +1 -0
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.d.ts +106 -0
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.d.ts.map +1 -0
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.js +182 -0
- package/dist/instrumentation/providers/ConsoleInstrumentationProvider.js.map +1 -0
- package/dist/instrumentation/providers/DataDogInstrumentationProvider.d.ts +170 -0
- package/dist/instrumentation/providers/DataDogInstrumentationProvider.d.ts.map +1 -0
- package/dist/instrumentation/providers/DataDogInstrumentationProvider.js +183 -0
- package/dist/instrumentation/providers/DataDogInstrumentationProvider.js.map +1 -0
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.d.ts +86 -0
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.d.ts.map +1 -0
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.js +135 -0
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.js.map +1 -0
- package/dist/instrumentation/providers/index.d.ts +12 -0
- package/dist/instrumentation/providers/index.d.ts.map +1 -0
- package/dist/instrumentation/providers/index.js +12 -0
- package/dist/instrumentation/providers/index.js.map +1 -0
- package/dist/instrumentation/types.d.ts +348 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +9 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/dist/loader-config.d.ts +76 -0
- package/dist/loader-config.d.ts.map +1 -0
- package/dist/loader-config.js +12 -0
- package/dist/loader-config.js.map +1 -0
- package/dist/loaders/ElementLoader.d.ts +72 -0
- package/dist/loaders/ElementLoader.d.ts.map +1 -0
- package/dist/loaders/ElementLoader.js +52 -0
- package/dist/loaders/ElementLoader.js.map +1 -0
- package/dist/loaders/EsmElementLoader.d.ts +67 -0
- package/dist/loaders/EsmElementLoader.d.ts.map +1 -0
- package/dist/loaders/EsmElementLoader.js +71 -0
- package/dist/loaders/EsmElementLoader.js.map +1 -0
- package/dist/loaders/IifeElementLoader.d.ts +61 -0
- package/dist/loaders/IifeElementLoader.d.ts.map +1 -0
- package/dist/loaders/IifeElementLoader.js +63 -0
- package/dist/loaders/IifeElementLoader.js.map +1 -0
- package/dist/loaders/index.d.ts +28 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +25 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/object/index.d.ts +12 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/index.js +40 -0
- package/dist/object/index.js.map +1 -0
- package/dist/pie/asset-handler.d.ts +64 -0
- package/dist/pie/asset-handler.d.ts.map +1 -0
- package/dist/pie/asset-handler.js +238 -0
- package/dist/pie/asset-handler.js.map +1 -0
- package/dist/pie/component-context.d.ts +22 -0
- package/dist/pie/component-context.d.ts.map +1 -0
- package/dist/pie/component-context.js +30 -0
- package/dist/pie/component-context.js.map +1 -0
- package/dist/pie/config.d.ts +39 -0
- package/dist/pie/config.d.ts.map +1 -0
- package/dist/pie/config.js +174 -0
- package/dist/pie/config.js.map +1 -0
- package/dist/pie/configure-initialization.d.ts +35 -0
- package/dist/pie/configure-initialization.d.ts.map +1 -0
- package/dist/pie/configure-initialization.js +141 -0
- package/dist/pie/configure-initialization.js.map +1 -0
- package/dist/pie/esm-loader.d.ts +93 -0
- package/dist/pie/esm-loader.d.ts.map +1 -0
- package/dist/pie/esm-loader.js +308 -0
- package/dist/pie/esm-loader.js.map +1 -0
- package/dist/pie/iife-loader.d.ts +76 -0
- package/dist/pie/iife-loader.d.ts.map +1 -0
- package/dist/pie/iife-loader.js +303 -0
- package/dist/pie/iife-loader.js.map +1 -0
- package/dist/pie/index.d.ts +31 -0
- package/dist/pie/index.d.ts.map +1 -0
- package/dist/pie/index.js +34 -0
- package/dist/pie/index.js.map +1 -0
- package/dist/pie/initialization.d.ts +40 -0
- package/dist/pie/initialization.d.ts.map +1 -0
- package/dist/pie/initialization.js +349 -0
- package/dist/pie/initialization.js.map +1 -0
- package/dist/pie/logger.d.ts +64 -0
- package/dist/pie/logger.d.ts.map +1 -0
- package/dist/pie/logger.js +45 -0
- package/dist/pie/logger.js.map +1 -0
- package/dist/pie/math-rendering.d.ts +69 -0
- package/dist/pie/math-rendering.d.ts.map +1 -0
- package/dist/pie/math-rendering.js +98 -0
- package/dist/pie/math-rendering.js.map +1 -0
- package/dist/pie/overrides.d.ts +43 -0
- package/dist/pie/overrides.d.ts.map +1 -0
- package/dist/pie/overrides.js +146 -0
- package/dist/pie/overrides.js.map +1 -0
- package/dist/pie/player-initializer.d.ts +55 -0
- package/dist/pie/player-initializer.d.ts.map +1 -0
- package/dist/pie/player-initializer.js +123 -0
- package/dist/pie/player-initializer.js.map +1 -0
- package/dist/pie/registry.d.ts +11 -0
- package/dist/pie/registry.d.ts.map +1 -0
- package/dist/pie/registry.js +21 -0
- package/dist/pie/registry.js.map +1 -0
- package/dist/pie/resource-monitor.d.ts +208 -0
- package/dist/pie/resource-monitor.d.ts.map +1 -0
- package/dist/pie/resource-monitor.js +969 -0
- package/dist/pie/resource-monitor.js.map +1 -0
- package/dist/pie/scoring.d.ts +17 -0
- package/dist/pie/scoring.d.ts.map +1 -0
- package/dist/pie/scoring.js +84 -0
- package/dist/pie/scoring.js.map +1 -0
- package/dist/pie/types.d.ts +136 -0
- package/dist/pie/types.d.ts.map +1 -0
- package/dist/pie/types.js +52 -0
- package/dist/pie/types.js.map +1 -0
- package/dist/pie/updates.d.ts +20 -0
- package/dist/pie/updates.d.ts.map +1 -0
- package/dist/pie/updates.js +175 -0
- package/dist/pie/updates.js.map +1 -0
- package/dist/pie/use-resource-monitor.svelte.d.ts +56 -0
- package/dist/pie/use-resource-monitor.svelte.d.ts.map +1 -0
- package/dist/pie/use-resource-monitor.svelte.js +117 -0
- package/dist/pie/use-resource-monitor.svelte.js.map +1 -0
- package/dist/pie/utils.d.ts +44 -0
- package/dist/pie/utils.d.ts.map +1 -0
- package/dist/pie/utils.js +74 -0
- package/dist/pie/utils.js.map +1 -0
- package/dist/types/custom-elements.d.ts +183 -0
- package/dist/types/custom-elements.d.ts.map +1 -0
- package/dist/types/custom-elements.js +8 -0
- package/dist/types/custom-elements.js.map +1 -0
- package/dist/types/index.d.ts +761 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +120 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/search.d.ts +105 -0
- package/dist/types/search.d.ts.map +1 -0
- package/dist/types/search.js +12 -0
- package/dist/types/search.js.map +1 -0
- package/dist/types/transform.d.ts +48 -0
- package/dist/types/transform.d.ts.map +1 -0
- package/dist/types/transform.js +21 -0
- package/dist/types/transform.js.map +1 -0
- package/dist/ui/focus-trap.d.ts +10 -0
- package/dist/ui/focus-trap.d.ts.map +1 -0
- package/dist/ui/focus-trap.js +30 -0
- package/dist/ui/focus-trap.js.map +1 -0
- package/dist/ui/safe-storage.d.ts +3 -0
- package/dist/ui/safe-storage.d.ts.map +1 -0
- package/dist/ui/safe-storage.js +21 -0
- package/dist/ui/safe-storage.js.map +1 -0
- package/package.json +118 -0
- package/src/components/PieItemPlayer.svelte +604 -0
- package/src/components/PiePreviewLayout.svelte +144 -0
- package/src/components/PiePreviewToggle.svelte +110 -0
- package/src/components/PieSpinner.svelte +85 -0
- package/src/components/ToolSettingsButton.svelte +31 -0
- package/src/components/ToolSettingsPanel.svelte +90 -0
- package/src/components/index.ts +6 -0
- package/src/i18n/README.md +223 -0
- package/src/i18n/index.ts +26 -0
- package/src/i18n/loader.ts +156 -0
- package/src/i18n/scripts/check-coverage.ts +345 -0
- package/src/i18n/scripts/scan-hardcoded.ts +342 -0
- package/src/i18n/simple-i18n.ts +236 -0
- package/src/i18n/translations/ar/common.json +36 -0
- package/src/i18n/translations/ar/toolkit.json +48 -0
- package/src/i18n/translations/ar/tools.json +109 -0
- package/src/i18n/translations/en/common.json +36 -0
- package/src/i18n/translations/en/toolkit.json +48 -0
- package/src/i18n/translations/en/tools.json +109 -0
- package/src/i18n/translations/es/common.json +36 -0
- package/src/i18n/translations/es/toolkit.json +48 -0
- package/src/i18n/translations/es/tools.json +109 -0
- package/src/i18n/translations/zh/common.json +36 -0
- package/src/i18n/translations/zh/toolkit.json +48 -0
- package/src/i18n/translations/zh/tools.json +109 -0
- package/src/i18n/types.ts +66 -0
- package/src/i18n/use-i18n-standalone.svelte.ts +184 -0
- package/src/i18n/use-i18n.svelte.ts +163 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIE Initialization Module
|
|
3
|
+
*
|
|
4
|
+
* Bundle loading and element initialization logic.
|
|
5
|
+
* This is the core of the PIE player system.
|
|
6
|
+
*/
|
|
7
|
+
import { BUILDER_BUNDLE_URL } from "../config/profile";
|
|
8
|
+
import { mergeObjectsIgnoringNullUndefined } from "../object";
|
|
9
|
+
import { editorPostFix } from "../types";
|
|
10
|
+
import { createPieLogger, isGlobalDebugEnabled } from "./logger";
|
|
11
|
+
import { initializeMathRendering } from "./math-rendering";
|
|
12
|
+
import { pieRegistry } from "./registry";
|
|
13
|
+
import { findPieController } from "./scoring";
|
|
14
|
+
import { BundleType, isCustomElementConstructor, isPieAvailable, Status, } from "./types";
|
|
15
|
+
import { updatePieElement } from "./updates";
|
|
16
|
+
import { findOrAddSession, getPackageWithoutVersion, getPieElementBundlesUrl, } from "./utils";
|
|
17
|
+
// Create module-level logger (respects global debug flag - pass function for dynamic checking)
|
|
18
|
+
const logger = createPieLogger("pie-initialization", () => isGlobalDebugEnabled());
|
|
19
|
+
// Default options for loading PIE elements
|
|
20
|
+
const defaultOptions = {
|
|
21
|
+
buildServiceBase: BUILDER_BUNDLE_URL,
|
|
22
|
+
bundleType: BundleType.player, // Default to player.js (no controllers, server-processed models)
|
|
23
|
+
env: { mode: "gather", role: "student" },
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to initialize a PIE element
|
|
27
|
+
*/
|
|
28
|
+
const initializePieElement = (element, options) => {
|
|
29
|
+
const { config, session, env, eventListeners } = options;
|
|
30
|
+
const tagName = element.tagName.toLowerCase();
|
|
31
|
+
logger.debug(`[initializePieElement] Initializing ${tagName}#${element.id}`);
|
|
32
|
+
// Find model for this element
|
|
33
|
+
let model = config?.models?.find((m) => m.id === element.id);
|
|
34
|
+
if (!model) {
|
|
35
|
+
// Only warn if this element is from a client-player.js bundle (where models are expected)
|
|
36
|
+
// player.js bundles use server-processed models, so missing models are expected there
|
|
37
|
+
const registry = pieRegistry();
|
|
38
|
+
const registryEntry = registry[tagName];
|
|
39
|
+
if (registryEntry && registryEntry.bundleType === BundleType.clientPlayer) {
|
|
40
|
+
logger.warn(`[initializePieElement] Model not found for PIE element ${tagName}#${element.id} (client-player.js bundle)`);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Set session (with element property for updateSession callback)
|
|
45
|
+
const elementSession = findOrAddSession(session, model.id, model.element);
|
|
46
|
+
element.session = elementSession;
|
|
47
|
+
logger.debug(`[initializePieElement] Session set for ${tagName}#${element.id}:`, elementSession);
|
|
48
|
+
// Set model - use controller if available (client-player.js), or use server-processed model (player.js)
|
|
49
|
+
const controller = findPieController(tagName);
|
|
50
|
+
if (!env) {
|
|
51
|
+
logger.error(`[initializePieElement] ❌ FATAL: No env provided for ${tagName}`);
|
|
52
|
+
throw new Error(`No env provided for ${tagName}. PIE elements require an env object with mode and role.`);
|
|
53
|
+
}
|
|
54
|
+
if (!controller) {
|
|
55
|
+
// No controller available - using server-processed model (player.js bundle)
|
|
56
|
+
logger.debug(`[initializePieElement] ℹ️ No controller for ${tagName}, using server-processed model`);
|
|
57
|
+
logger.debug(`[initializePieElement] Model already processed by server:`, {
|
|
58
|
+
id: model.id,
|
|
59
|
+
element: model.element,
|
|
60
|
+
hasCorrectResponse: "correctResponse" in model,
|
|
61
|
+
mode: env.mode,
|
|
62
|
+
role: env.role,
|
|
63
|
+
});
|
|
64
|
+
// Set model directly - server already processed it
|
|
65
|
+
element.model = model;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Controller available - run client-side processing (client-player.js bundle)
|
|
69
|
+
// Note: updatePieElementWithRef handles controller invocation
|
|
70
|
+
logger.debug(`[initializePieElement] Controller found for ${tagName}, will invoke model() function`);
|
|
71
|
+
}
|
|
72
|
+
// Add event listeners
|
|
73
|
+
if (eventListeners) {
|
|
74
|
+
Object.entries(eventListeners).forEach(([evt, fn]) => {
|
|
75
|
+
element.addEventListener(evt, fn);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Shared element registration logic
|
|
81
|
+
* Extracted from initializePiesFromLoadedBundle and loadPieModule to eliminate ~200 lines of duplication
|
|
82
|
+
* Also fixes MutationObserver memory leak by storing latest config/session in window context
|
|
83
|
+
*/
|
|
84
|
+
const registerPieElementsFromBundle = (elementModule, config, session, registry, options) => {
|
|
85
|
+
const promises = [];
|
|
86
|
+
logger.debug("[registerPieElementsFromBundle] Available packages in bundle:", Object.keys(elementModule));
|
|
87
|
+
logger.debug("[registerPieElementsFromBundle] config.elements:", config.elements);
|
|
88
|
+
// Store latest config/session in window so MutationObserver can access current values
|
|
89
|
+
if (typeof window !== "undefined") {
|
|
90
|
+
window._pieCurrentContext = { config, session, env: options.env };
|
|
91
|
+
}
|
|
92
|
+
Object.entries(config.elements).forEach(([elName, pkg]) => {
|
|
93
|
+
logger.debug(`[registerPieElementsFromBundle] Processing element: ${elName} -> ${pkg}`);
|
|
94
|
+
const pkgStripped = getPackageWithoutVersion(pkg);
|
|
95
|
+
logger.debug(`[registerPieElementsFromBundle] Package without version: "${pkgStripped}"`);
|
|
96
|
+
const elementData = elementModule[pkgStripped];
|
|
97
|
+
logger.debug(`[registerPieElementsFromBundle] elementData result:`, elementData ? "FOUND" : "UNDEFINED");
|
|
98
|
+
if (!elementData) {
|
|
99
|
+
logger.error(`[registerPieElementsFromBundle] ❌ Package "${pkgStripped}" not found in bundle!`);
|
|
100
|
+
logger.error(`[registerPieElementsFromBundle] Lookup key: "${pkgStripped}"`);
|
|
101
|
+
logger.error(`[registerPieElementsFromBundle] Available packages:`, Object.keys(elementModule));
|
|
102
|
+
throw new Error(`pie ${pkgStripped} not found in ${Object.keys(elementModule)}`);
|
|
103
|
+
}
|
|
104
|
+
logger.debug(`[registerPieElementsFromBundle] elementData for ${pkgStripped}:`, {
|
|
105
|
+
hasController: !!elementData.controller,
|
|
106
|
+
hasElement: !!elementData.Element,
|
|
107
|
+
hasConfig: !!elementData.config,
|
|
108
|
+
controllerKeys: elementData.controller
|
|
109
|
+
? Object.keys(elementData.controller)
|
|
110
|
+
: [],
|
|
111
|
+
bundleType: options.bundleType,
|
|
112
|
+
});
|
|
113
|
+
// Validate controller presence based on bundle type
|
|
114
|
+
if (!elementData.controller) {
|
|
115
|
+
if (options.bundleType === BundleType.clientPlayer) {
|
|
116
|
+
logger.error(`[registerPieElementsFromBundle] ❌ CRITICAL: No controller found for ${pkgStripped}!`);
|
|
117
|
+
logger.error(`[registerPieElementsFromBundle] Bundle type: ${options.bundleType} (controllers required)`);
|
|
118
|
+
throw new Error(`No controller found for ${pkgStripped}. client-player.js bundles MUST include controllers!`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
logger.debug(`[registerPieElementsFromBundle] ℹ️ No controller found for ${pkgStripped} - using server-processed models (player.js bundle)`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!customElements.get(elName)) {
|
|
125
|
+
// Register the element in our registry
|
|
126
|
+
logger.debug(`[registerPieElementsFromBundle] Registering ${elName} in registry${elementData.controller
|
|
127
|
+
? " with controller"
|
|
128
|
+
: " (no controller - server-processed models)"}`);
|
|
129
|
+
registry[elName] = {
|
|
130
|
+
package: pkg,
|
|
131
|
+
status: Status.loading,
|
|
132
|
+
tagName: elName,
|
|
133
|
+
controller: elementData.controller || null,
|
|
134
|
+
config: elementData.config,
|
|
135
|
+
bundleType: options.bundleType,
|
|
136
|
+
};
|
|
137
|
+
if (isCustomElementConstructor(elementData.Element)) {
|
|
138
|
+
customElements.define(elName, elementData.Element);
|
|
139
|
+
// Initialize existing elements
|
|
140
|
+
const elements = document.querySelectorAll(elName);
|
|
141
|
+
logger.debug(`[registerPieElementsFromBundle] Found ${elements.length} elements for tag '${elName}'`);
|
|
142
|
+
elements.forEach((el) => {
|
|
143
|
+
initializePieElement(el, {
|
|
144
|
+
config,
|
|
145
|
+
session,
|
|
146
|
+
env: options.env,
|
|
147
|
+
eventListeners: options.eventListeners?.[elName],
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
// Update registry status
|
|
151
|
+
registry[elName] = {
|
|
152
|
+
...registry[elName],
|
|
153
|
+
status: Status.loaded,
|
|
154
|
+
};
|
|
155
|
+
promises.push(customElements.whenDefined(elName).then(() => {
|
|
156
|
+
logger.debug("[registerPieElementsFromBundle] defined custom PIE element: %s", elName);
|
|
157
|
+
}));
|
|
158
|
+
// Setup MutationObserver that uses current context (only once)
|
|
159
|
+
if (!window._pieElementObserver) {
|
|
160
|
+
window._pieElementObserver = new MutationObserver((mutations) => {
|
|
161
|
+
// Use current context from window instead of stale closure
|
|
162
|
+
const context = window._pieCurrentContext;
|
|
163
|
+
if (!context) {
|
|
164
|
+
logger.warn("[MutationObserver] No current context available");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
mutations.forEach((mutation) => {
|
|
168
|
+
if (mutation.type === "childList") {
|
|
169
|
+
mutation.addedNodes.forEach((node) => {
|
|
170
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
171
|
+
const tagName = node.tagName.toLowerCase();
|
|
172
|
+
if (registry[tagName]) {
|
|
173
|
+
initializePieElement(node, {
|
|
174
|
+
config: context.config,
|
|
175
|
+
session: context.session,
|
|
176
|
+
env: context.env,
|
|
177
|
+
eventListeners: options.eventListeners?.[tagName],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// Check children of added nodes
|
|
181
|
+
node
|
|
182
|
+
.querySelectorAll("*")
|
|
183
|
+
.forEach((childNode) => {
|
|
184
|
+
const childTagName = childNode.tagName.toLowerCase();
|
|
185
|
+
if (registry[childTagName]) {
|
|
186
|
+
initializePieElement(childNode, {
|
|
187
|
+
config: context.config,
|
|
188
|
+
session: context.session,
|
|
189
|
+
env: context.env,
|
|
190
|
+
eventListeners: options.eventListeners?.[childTagName],
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
window._pieElementObserver.observe(document.body, {
|
|
200
|
+
childList: true,
|
|
201
|
+
subtree: true,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// Handle editor elements if needed
|
|
205
|
+
if (options.bundleType === BundleType.editor) {
|
|
206
|
+
if (isCustomElementConstructor(elementData.Configure)) {
|
|
207
|
+
const editorElName = elName + editorPostFix;
|
|
208
|
+
customElements.define(editorElName, elementData.Configure);
|
|
209
|
+
promises.push(customElements.whenDefined(editorElName).then(() => {
|
|
210
|
+
logger.debug(`[registerPieElementsFromBundle] defined custom PIE editor element: ${editorElName}`);
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
logger.error(`[registerPieElementsFromBundle] pie.Configure for ${pkgStripped} is not a valid custom element constructor.`, elementData.configure);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
logger.error(`[registerPieElementsFromBundle] pie.Element for ${pkgStripped} is not a valid custom element constructor.`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// Element already defined, just update it
|
|
224
|
+
updatePieElement(elName, {
|
|
225
|
+
config,
|
|
226
|
+
session,
|
|
227
|
+
env: options.env,
|
|
228
|
+
container: options.container,
|
|
229
|
+
...(options.eventListeners?.[elName] && {
|
|
230
|
+
eventListeners: options.eventListeners[elName],
|
|
231
|
+
}),
|
|
232
|
+
});
|
|
233
|
+
if (options.bundleType === BundleType.editor) {
|
|
234
|
+
const editorElName = elName + editorPostFix;
|
|
235
|
+
updatePieElement(editorElName, {
|
|
236
|
+
config,
|
|
237
|
+
session,
|
|
238
|
+
container: options.container,
|
|
239
|
+
...(options.eventListeners?.[editorElName] && {
|
|
240
|
+
eventListeners: options.eventListeners[editorElName],
|
|
241
|
+
}),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return promises;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Initialize PIE elements from a bundle already loaded into window.pie
|
|
250
|
+
*/
|
|
251
|
+
export const initializePiesFromLoadedBundle = (config, session, opts = {}) => {
|
|
252
|
+
const registry = pieRegistry();
|
|
253
|
+
const options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);
|
|
254
|
+
if (isPieAvailable(window)) {
|
|
255
|
+
logger.debug("[initializePiesFromLoadedBundle] window.pie available");
|
|
256
|
+
const elementModule = window.pie.default;
|
|
257
|
+
// Use shared registration logic
|
|
258
|
+
registerPieElementsFromBundle(elementModule, config, session, registry, options);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
logger.error("[initializePiesFromLoadedBundle] window.pie not found; was the bundle inlined correctly?");
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Load a PIE bundle from a URL and initialize elements
|
|
266
|
+
*/
|
|
267
|
+
export const loadPieModule = async (config, session, opts = {}) => {
|
|
268
|
+
if (!session) {
|
|
269
|
+
throw new Error("session is required");
|
|
270
|
+
}
|
|
271
|
+
// Initialize math-rendering module (required by PIE elements)
|
|
272
|
+
await initializeMathRendering();
|
|
273
|
+
const registry = pieRegistry();
|
|
274
|
+
const options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);
|
|
275
|
+
const url = opts.bundleUrl || getPieElementBundlesUrl(config, options);
|
|
276
|
+
const script = document.createElement("script");
|
|
277
|
+
script.src = url;
|
|
278
|
+
script.defer = true;
|
|
279
|
+
script.onerror = () => {
|
|
280
|
+
throw new Error(`failed to load script: ${url}`);
|
|
281
|
+
};
|
|
282
|
+
const loadPromise = new Promise((loadResolve) => {
|
|
283
|
+
script.addEventListener("load", () => {
|
|
284
|
+
logger.debug("[loadPieModule] Script loaded from:", url);
|
|
285
|
+
if (isPieAvailable(window)) {
|
|
286
|
+
logger.debug("[loadPieModule] window.pie available");
|
|
287
|
+
const elementModule = window.pie.default;
|
|
288
|
+
// Use shared registration logic (returns array of promises)
|
|
289
|
+
const registrationPromises = registerPieElementsFromBundle(elementModule, config, session, registry, options);
|
|
290
|
+
// Wait for all element definitions to complete
|
|
291
|
+
Promise.all(registrationPromises).then(() => loadResolve());
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
logger.error("[loadPieModule] pie var not found; is %s a proper PIE IIFE module?", url);
|
|
295
|
+
loadResolve();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
document.head.appendChild(script);
|
|
300
|
+
await loadPromise;
|
|
301
|
+
return { session };
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Load a PIE bundle from a JavaScript string into window.pie (IIFE bundles only)
|
|
305
|
+
* This only registers elements and controllers - does NOT initialize them.
|
|
306
|
+
* For initialization, use initializePiesFromLoadedBundle after loading.
|
|
307
|
+
*/
|
|
308
|
+
export const loadBundleFromString = async (bundleJs) => {
|
|
309
|
+
// Strip sourceMappingURL comment to prevent 404 errors for .map files
|
|
310
|
+
const cleanedJs = bundleJs.replace(/\/\/# sourceMappingURL=.*$/m, "");
|
|
311
|
+
// Create a blob URL for the bundle JavaScript
|
|
312
|
+
const blob = new Blob([cleanedJs], { type: "application/javascript" });
|
|
313
|
+
const bundleUrl = URL.createObjectURL(blob);
|
|
314
|
+
try {
|
|
315
|
+
// Create a script tag to execute the bundle
|
|
316
|
+
const script = document.createElement("script");
|
|
317
|
+
script.src = bundleUrl;
|
|
318
|
+
script.type = "text/javascript"; // IIFE bundles are standard JS
|
|
319
|
+
// Wait for script to load
|
|
320
|
+
await new Promise((resolve, reject) => {
|
|
321
|
+
script.onload = () => resolve();
|
|
322
|
+
script.onerror = () => reject(new Error("Failed to load bundle"));
|
|
323
|
+
document.head.appendChild(script);
|
|
324
|
+
});
|
|
325
|
+
logger.debug("[loadBundleFromString] Bundle loaded into window.pie");
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
// Clean up the blob URL
|
|
329
|
+
URL.revokeObjectURL(bundleUrl);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Load a PIE bundle from a JavaScript string and initialize elements
|
|
334
|
+
* Convenience wrapper around loadBundleFromString + loadPieModule
|
|
335
|
+
*/
|
|
336
|
+
export const loadPieModuleFromString = async (bundleJs, config, session, opts = {}) => {
|
|
337
|
+
// Create a blob URL for the bundle JavaScript
|
|
338
|
+
const blob = new Blob([bundleJs], { type: "application/javascript" });
|
|
339
|
+
const bundleUrl = URL.createObjectURL(blob);
|
|
340
|
+
try {
|
|
341
|
+
// Use existing loadPieModule with the blob URL
|
|
342
|
+
await loadPieModule(config, session, { ...opts, bundleUrl });
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
// Always clean up the blob URL
|
|
346
|
+
URL.revokeObjectURL(bundleUrl);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
//# sourceMappingURL=initialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialization.js","sourceRoot":"","sources":["../../src/pie/initialization.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C,OAAO,EACN,UAAU,EACV,0BAA0B,EAC1B,cAAc,EACd,MAAM,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,SAAS,CAAC;AAEjB,+FAA+F;AAC/F,MAAM,MAAM,GAAG,eAAe,CAAC,oBAAoB,EAAE,GAAG,EAAE,CACzD,oBAAoB,EAAE,CACtB,CAAC;AAEF,2CAA2C;AAC3C,MAAM,cAAc,GAA2B;IAC9C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C;AACF,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC3C,QAAgB,EAChB,MAAoB,EACpB,OAAc,EACd,OAA+B,EAAE,EACjB,EAAE;IAClB,8CAA8C;IAC9C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAE5C,IAAI,CAAC;QACJ,+CAA+C;QAC/C,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC9D,CAAC;YAAS,CAAC;QACV,+BAA+B;QAC/B,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIE Logger Utility
|
|
3
|
+
*
|
|
4
|
+
* Simple, efficient logging for PIE players with debug mode support.
|
|
5
|
+
* Uses browser console methods (debug, info, warn, error) which can be
|
|
6
|
+
* filtered natively in browser dev tools.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const logger = createPieLogger('pie-fixed-player', debug);
|
|
11
|
+
* logger.debug('Detailed debug info', data); // Only shown if debug=true
|
|
12
|
+
* logger.info('Important production info'); // Always shown
|
|
13
|
+
* logger.warn('Warning message'); // Always shown
|
|
14
|
+
* logger.error('Error occurred', error); // Always shown
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export interface PieLogger {
|
|
18
|
+
/**
|
|
19
|
+
* Debug-level logging - only shown when debug mode is enabled
|
|
20
|
+
* Use for: detailed initialization steps, data transformations, internal state
|
|
21
|
+
*/
|
|
22
|
+
debug: (message: string, ...args: any[]) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Info-level logging - always shown
|
|
25
|
+
* Use for: successful operations, lifecycle events, important milestones
|
|
26
|
+
*/
|
|
27
|
+
info: (message: string, ...args: any[]) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Warning-level logging - always shown
|
|
30
|
+
* Use for: recoverable errors, deprecated features, potential issues
|
|
31
|
+
*/
|
|
32
|
+
warn: (message: string, ...args: any[]) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Error-level logging - always shown
|
|
35
|
+
* Use for: errors, exceptions, failures
|
|
36
|
+
*/
|
|
37
|
+
error: (message: string, ...args: any[]) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a PIE logger instance
|
|
41
|
+
*
|
|
42
|
+
* @param namespace - Component name for log prefixing (e.g., 'pie-fixed-player')
|
|
43
|
+
* @param debugEnabledFn - Function that returns whether debug logs should be shown (checked dynamically on each call)
|
|
44
|
+
* @returns Logger instance with debug, info, warn, error methods
|
|
45
|
+
*/
|
|
46
|
+
export declare function createPieLogger(namespace: string, debugEnabledFn: () => boolean): PieLogger;
|
|
47
|
+
/**
|
|
48
|
+
* Global debug flag - can be set via window for runtime debugging
|
|
49
|
+
*
|
|
50
|
+
* Usage in browser console:
|
|
51
|
+
* ```javascript
|
|
52
|
+
* window.PIE_DEBUG = true; // Enable debug logging
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
PIE_DEBUG?: boolean;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if debug mode is enabled globally
|
|
62
|
+
*/
|
|
63
|
+
export declare function isGlobalDebugEnabled(): boolean;
|
|
64
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/pie/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,WAAW,SAAS;IACzB;;;OAGG;IACH,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAEjD;;;OAGG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAEhD;;;OAGG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAEhD;;;OAGG;IACH,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,OAAO,GAC3B,SAAS,CAqBX;AAED;;;;;;;GAOG;AACH,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,SAAS,CAAC,EAAE,OAAO,CAAC;KACpB;CACD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIE Logger Utility
|
|
3
|
+
*
|
|
4
|
+
* Simple, efficient logging for PIE players with debug mode support.
|
|
5
|
+
* Uses browser console methods (debug, info, warn, error) which can be
|
|
6
|
+
* filtered natively in browser dev tools.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const logger = createPieLogger('pie-fixed-player', debug);
|
|
11
|
+
* logger.debug('Detailed debug info', data); // Only shown if debug=true
|
|
12
|
+
* logger.info('Important production info'); // Always shown
|
|
13
|
+
* logger.warn('Warning message'); // Always shown
|
|
14
|
+
* logger.error('Error occurred', error); // Always shown
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Create a PIE logger instance
|
|
19
|
+
*
|
|
20
|
+
* @param namespace - Component name for log prefixing (e.g., 'pie-fixed-player')
|
|
21
|
+
* @param debugEnabledFn - Function that returns whether debug logs should be shown (checked dynamically on each call)
|
|
22
|
+
* @returns Logger instance with debug, info, warn, error methods
|
|
23
|
+
*/
|
|
24
|
+
export function createPieLogger(namespace, debugEnabledFn) {
|
|
25
|
+
const prefix = `[${namespace}]`;
|
|
26
|
+
return {
|
|
27
|
+
// Only debug method checks debugEnabledFn - it's checked dynamically on every call
|
|
28
|
+
debug: (message, ...args) => {
|
|
29
|
+
if (debugEnabledFn()) {
|
|
30
|
+
console.debug(prefix, message, ...args);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
// info, warn, error always log (not gated by debug flag)
|
|
34
|
+
info: (message, ...args) => console.info(prefix, message, ...args),
|
|
35
|
+
warn: (message, ...args) => console.warn(prefix, message, ...args),
|
|
36
|
+
error: (message, ...args) => console.error(prefix, message, ...args),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if debug mode is enabled globally
|
|
41
|
+
*/
|
|
42
|
+
export function isGlobalDebugEnabled() {
|
|
43
|
+
return typeof window !== "undefined" && window.PIE_DEBUG === true;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/pie/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4BH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC9B,SAAiB,EACjB,cAA6B;IAE7B,MAAM,MAAM,GAAG,IAAI,SAAS,GAAG,CAAC;IAEhC,OAAO;QACN,mFAAmF;QACnF,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAW,EAAE,EAAE;YAC1C,IAAI,cAAc,EAAE,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;QAED,yDAAyD;QACzD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAW,EAAE,EAAE,CACzC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEvC,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAW,EAAE,EAAE,CACzC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEvC,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAW,EAAE,EAAE,CAC1C,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;KACxC,CAAC;AACH,CAAC;AAgBD;;GAEG;AACH,MAAM,UAAU,oBAAoB;IACnC,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable math rendering for PIE players
|
|
3
|
+
*
|
|
4
|
+
* PIE elements expect @pie-lib/math-rendering to be available on window.
|
|
5
|
+
* This module provides a pluggable provider pattern that allows switching
|
|
6
|
+
* between MathJax, KaTeX, or custom renderers.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: Uses dynamic import to avoid SSR issues - the module is browser-only.
|
|
9
|
+
*/
|
|
10
|
+
import { type MathRenderingAPI } from "@pie-players/math-renderer-core";
|
|
11
|
+
/**
|
|
12
|
+
* Initialize math rendering with optional custom renderer
|
|
13
|
+
*
|
|
14
|
+
* If no custom renderer is provided, defaults to MathJax for backward compatibility.
|
|
15
|
+
* For custom renderers, use setMathRenderer() before calling this function.
|
|
16
|
+
*
|
|
17
|
+
* Sets TWO window globals that PIE elements expect:
|
|
18
|
+
* - window["@pie-lib/math-rendering"] (standard key)
|
|
19
|
+
* - window["_dll_pie_lib__math_rendering"] (SystemJS/DLL key for IIFE bundles)
|
|
20
|
+
*
|
|
21
|
+
* @param customRenderer - Optional custom renderer to use instead of default MathJax
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Default MathJax (backward compatible)
|
|
26
|
+
* await initializeMathRendering();
|
|
27
|
+
*
|
|
28
|
+
* // Custom renderer
|
|
29
|
+
* import { createKatexRenderer } from '@pie-players/math-renderer-katex';
|
|
30
|
+
* const katexRenderer = await createKatexRenderer();
|
|
31
|
+
* await initializeMathRendering(katexRenderer);
|
|
32
|
+
*
|
|
33
|
+
* // Or use setMathRenderer first
|
|
34
|
+
* setMathRenderer(katexRenderer);
|
|
35
|
+
* await initializeMathRendering();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function initializeMathRendering(customRenderer?: MathRenderingAPI): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Set custom math renderer programmatically
|
|
41
|
+
*
|
|
42
|
+
* Call this BEFORE initializeMathRendering() or any loader.load() calls
|
|
43
|
+
* to override the default MathJax renderer.
|
|
44
|
+
*
|
|
45
|
+
* @param renderer - The renderer to use
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { createKatexRenderer } from '@pie-players/math-renderer-katex';
|
|
50
|
+
* import { setMathRenderer } from '@pie-players/pie-players-shared/pie';
|
|
51
|
+
*
|
|
52
|
+
* const katexRenderer = await createKatexRenderer({ throwOnError: false });
|
|
53
|
+
* setMathRenderer(katexRenderer);
|
|
54
|
+
*
|
|
55
|
+
* // Now load PIE elements - they'll use KaTeX
|
|
56
|
+
* await loader.load(config, document, needsControllers);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function setMathRenderer(renderer: MathRenderingAPI): void;
|
|
60
|
+
/**
|
|
61
|
+
* Render math in the given element
|
|
62
|
+
*
|
|
63
|
+
* Convenience wrapper that calls the active renderer's renderMath() function.
|
|
64
|
+
* Typically called after PIE elements are rendered.
|
|
65
|
+
*
|
|
66
|
+
* @param element - The element to render math within
|
|
67
|
+
*/
|
|
68
|
+
export declare function renderMath(element: HTMLElement): void;
|
|
69
|
+
//# sourceMappingURL=math-rendering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-rendering.d.ts","sourceRoot":"","sources":["../../src/pie/math-rendering.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,KAAK,gBAAgB,EAErB,MAAM,iCAAiC,CAAC;AAGzC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,uBAAuB,CAC5C,cAAc,CAAC,EAAE,gBAAgB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA4Bf;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAMrD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable math rendering for PIE players
|
|
3
|
+
*
|
|
4
|
+
* PIE elements expect @pie-lib/math-rendering to be available on window.
|
|
5
|
+
* This module provides a pluggable provider pattern that allows switching
|
|
6
|
+
* between MathJax, KaTeX, or custom renderers.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: Uses dynamic import to avoid SSR issues - the module is browser-only.
|
|
9
|
+
*/
|
|
10
|
+
/// <reference path="../shims.d.ts" />
|
|
11
|
+
import { mathRendererProvider, } from "@pie-players/math-renderer-core";
|
|
12
|
+
import { createMathjaxRenderer } from "@pie-players/math-renderer-mathjax";
|
|
13
|
+
/**
|
|
14
|
+
* Initialize math rendering with optional custom renderer
|
|
15
|
+
*
|
|
16
|
+
* If no custom renderer is provided, defaults to MathJax for backward compatibility.
|
|
17
|
+
* For custom renderers, use setMathRenderer() before calling this function.
|
|
18
|
+
*
|
|
19
|
+
* Sets TWO window globals that PIE elements expect:
|
|
20
|
+
* - window["@pie-lib/math-rendering"] (standard key)
|
|
21
|
+
* - window["_dll_pie_lib__math_rendering"] (SystemJS/DLL key for IIFE bundles)
|
|
22
|
+
*
|
|
23
|
+
* @param customRenderer - Optional custom renderer to use instead of default MathJax
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Default MathJax (backward compatible)
|
|
28
|
+
* await initializeMathRendering();
|
|
29
|
+
*
|
|
30
|
+
* // Custom renderer
|
|
31
|
+
* import { createKatexRenderer } from '@pie-players/math-renderer-katex';
|
|
32
|
+
* const katexRenderer = await createKatexRenderer();
|
|
33
|
+
* await initializeMathRendering(katexRenderer);
|
|
34
|
+
*
|
|
35
|
+
* // Or use setMathRenderer first
|
|
36
|
+
* setMathRenderer(katexRenderer);
|
|
37
|
+
* await initializeMathRendering();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export async function initializeMathRendering(customRenderer) {
|
|
41
|
+
// Only run in browser
|
|
42
|
+
if (typeof window === "undefined") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Already initialized - skip
|
|
46
|
+
if (mathRendererProvider.isInitialized()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
// Use custom renderer or default to MathJax for backward compatibility
|
|
51
|
+
const renderer = customRenderer ?? (await createMathjaxRenderer());
|
|
52
|
+
// Set in provider (automatically updates window globals)
|
|
53
|
+
mathRendererProvider.setRenderer(renderer);
|
|
54
|
+
console.log("[MathRendering] ✅ Math rendering module initialized (both globals set)");
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("[MathRendering] ❌ Failed to initialize math rendering:", error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set custom math renderer programmatically
|
|
63
|
+
*
|
|
64
|
+
* Call this BEFORE initializeMathRendering() or any loader.load() calls
|
|
65
|
+
* to override the default MathJax renderer.
|
|
66
|
+
*
|
|
67
|
+
* @param renderer - The renderer to use
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { createKatexRenderer } from '@pie-players/math-renderer-katex';
|
|
72
|
+
* import { setMathRenderer } from '@pie-players/pie-players-shared/pie';
|
|
73
|
+
*
|
|
74
|
+
* const katexRenderer = await createKatexRenderer({ throwOnError: false });
|
|
75
|
+
* setMathRenderer(katexRenderer);
|
|
76
|
+
*
|
|
77
|
+
* // Now load PIE elements - they'll use KaTeX
|
|
78
|
+
* await loader.load(config, document, needsControllers);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function setMathRenderer(renderer) {
|
|
82
|
+
mathRendererProvider.setRenderer(renderer);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Render math in the given element
|
|
86
|
+
*
|
|
87
|
+
* Convenience wrapper that calls the active renderer's renderMath() function.
|
|
88
|
+
* Typically called after PIE elements are rendered.
|
|
89
|
+
*
|
|
90
|
+
* @param element - The element to render math within
|
|
91
|
+
*/
|
|
92
|
+
export function renderMath(element) {
|
|
93
|
+
const renderer = mathRendererProvider.getRenderer();
|
|
94
|
+
if (renderer && typeof renderer.renderMath === "function") {
|
|
95
|
+
renderer.renderMath(element);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=math-rendering.js.map
|