@pie-qti/item-player 0.1.9 → 0.1.10
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 +17 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
- package/dist/catalog/glossaryAction.d.ts +4 -2
- package/dist/catalog/glossaryAction.d.ts.map +1 -1
- package/dist/components/utils/index.d.ts +1 -2
- package/dist/components/utils/index.d.ts.map +1 -1
- package/dist/components/utils/index.js +1 -2
- package/dist/core/ComponentRegistry.d.ts +10 -1
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +42 -1
- package/dist/core/Player.d.ts +10 -2
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +54 -46
- package/dist/document/AssessmentItemDocument.d.ts +1 -1
- package/dist/element.d.ts +15 -0
- package/dist/element.js +1817 -1625
- package/dist/element.js.map +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +1 -1
- package/dist/extraction/createContext.d.ts +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
- package/dist/extraction/interactionSecurity.d.ts +1 -1
- package/dist/extraction/types.d.ts +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +54 -0
- package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
- package/dist/presentation/itemPresentationPlan.js +98 -0
- package/dist/types/index.d.ts +17 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -3
- package/dist/web-components/QTIInteractionBase.d.ts +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +1 -1
- package/package.json +7 -14
- package/src/__tests__/catalog.test.ts +0 -267
- package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
- package/src/__tests__/pci.test.ts +0 -353
- package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
- package/src/__tests__/qti3-debug.test.ts +0 -140
- package/src/__tests__/qti3-extraction.test.ts +0 -309
- package/src/catalog/applyGlossaryTriggers.ts +0 -372
- package/src/catalog/catalogExtractor.ts +0 -130
- package/src/catalog/catalogLookup.ts +0 -53
- package/src/catalog/glossaryAction.ts +0 -38
- package/src/catalog/types.ts +0 -37
- package/src/components/ItemBody.svelte +0 -363
- package/src/components/ItemPlayer.svelte +0 -163
- package/src/components/ModalFeedbackDisplay.svelte +0 -97
- package/src/components/actions/typesetAction.ts +0 -74
- package/src/components/index.ts +0 -22
- package/src/components/utils/assignProps.ts +0 -2
- package/src/components/utils/feedbackUtils.ts +0 -140
- package/src/components/utils/index.ts +0 -13
- package/src/components/utils/stimulusRender.ts +0 -93
- package/src/components/utils/stylesheetRender.ts +0 -58
- package/src/core/ComponentRegistry.ts +0 -248
- package/src/core/Player.ts +0 -1618
- package/src/core/Plugin.ts +0 -123
- package/src/core/PluginManager.ts +0 -182
- package/src/core/constants.ts +0 -117
- package/src/core/declarations.ts +0 -171
- package/src/core/parsingLimits.ts +0 -62
- package/src/core/random.ts +0 -24
- package/src/core/rolePolicy.ts +0 -34
- package/src/core/sanitizer.ts +0 -305
- package/src/core/trustedTypes.ts +0 -63
- package/src/core/urlPolicy.ts +0 -98
- package/src/document/AssessmentItemDocument.ts +0 -247
- package/src/element.ts +0 -128
- package/src/extensions/MathLiveEditor.ts +0 -313
- package/src/extraction/ExtractionRegistry.ts +0 -335
- package/src/extraction/createContext.ts +0 -52
- package/src/extraction/extractors/associateExtractor.ts +0 -1
- package/src/extraction/extractors/choiceExtractor.ts +0 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
- package/src/extraction/extractors/conformance.test.ts +0 -208
- package/src/extraction/extractors/customExtractor.ts +0 -1
- package/src/extraction/extractors/drawingExtractor.ts +0 -1
- package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
- package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
- package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
- package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
- package/src/extraction/extractors/hotspotExtractor.ts +0 -1
- package/src/extraction/extractors/hottextExtractor.ts +0 -1
- package/src/extraction/extractors/index.ts +0 -9
- package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
- package/src/extraction/extractors/matchExtractor.ts +0 -1
- package/src/extraction/extractors/mediaExtractor.ts +0 -1
- package/src/extraction/extractors/orderExtractor.ts +0 -1
- package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
- package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
- package/src/extraction/extractors/selectPointExtractor.ts +0 -1
- package/src/extraction/extractors/sliderExtractor.ts +0 -1
- package/src/extraction/extractors/textEntryExtractor.ts +0 -1
- package/src/extraction/extractors/uploadExtractor.ts +0 -1
- package/src/extraction/index.ts +0 -108
- package/src/extraction/interactionExtractionPipeline.ts +0 -70
- package/src/extraction/interactionSecurity.ts +0 -60
- package/src/extraction/types.ts +0 -246
- package/src/extraction/utils.ts +0 -243
- package/src/iframe/IFramePlayerHost.ts +0 -265
- package/src/iframe/index.ts +0 -11
- package/src/iframe/protocol.ts +0 -137
- package/src/index.ts +0 -101
- package/src/interactions/associate/extractor.ts +0 -133
- package/src/interactions/associate/index.ts +0 -2
- package/src/interactions/associate/types.ts +0 -1
- package/src/interactions/choice/extractor.ts +0 -121
- package/src/interactions/choice/index.ts +0 -2
- package/src/interactions/choice/types.ts +0 -1
- package/src/interactions/custom/extractor.ts +0 -72
- package/src/interactions/custom/index.ts +0 -2
- package/src/interactions/custom/types.ts +0 -1
- package/src/interactions/drawing/extractor.ts +0 -113
- package/src/interactions/drawing/index.ts +0 -2
- package/src/interactions/drawing/types.ts +0 -1
- package/src/interactions/end-attempt/extractor.ts +0 -74
- package/src/interactions/end-attempt/index.ts +0 -2
- package/src/interactions/end-attempt/types.ts +0 -1
- package/src/interactions/extended-text/extractor.ts +0 -92
- package/src/interactions/extended-text/index.ts +0 -2
- package/src/interactions/extended-text/types.ts +0 -1
- package/src/interactions/gap-match/extractor.ts +0 -193
- package/src/interactions/gap-match/index.ts +0 -2
- package/src/interactions/gap-match/types.ts +0 -1
- package/src/interactions/graphic-associate/extractor.ts +0 -192
- package/src/interactions/graphic-associate/index.ts +0 -2
- package/src/interactions/graphic-associate/types.ts +0 -1
- package/src/interactions/graphic-gap-match/extractor.ts +0 -257
- package/src/interactions/graphic-gap-match/index.ts +0 -2
- package/src/interactions/graphic-gap-match/types.ts +0 -1
- package/src/interactions/graphic-order/extractor.ts +0 -162
- package/src/interactions/graphic-order/index.ts +0 -2
- package/src/interactions/graphic-order/types.ts +0 -1
- package/src/interactions/hotspot/extractor.ts +0 -208
- package/src/interactions/hotspot/index.ts +0 -2
- package/src/interactions/hotspot/types.ts +0 -1
- package/src/interactions/hottext/extractor.ts +0 -163
- package/src/interactions/hottext/index.ts +0 -2
- package/src/interactions/hottext/types.ts +0 -1
- package/src/interactions/index.ts +0 -52
- package/src/interactions/inline/index.ts +0 -1
- package/src/interactions/inline/render-plan.ts +0 -105
- package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
- package/src/interactions/inline-choice/extractor.ts +0 -105
- package/src/interactions/inline-choice/index.ts +0 -2
- package/src/interactions/inline-choice/types.ts +0 -1
- package/src/interactions/match/extractor.ts +0 -187
- package/src/interactions/match/index.ts +0 -2
- package/src/interactions/match/types.ts +0 -1
- package/src/interactions/media/extractor.ts +0 -168
- package/src/interactions/media/index.ts +0 -2
- package/src/interactions/media/types.ts +0 -1
- package/src/interactions/modules.ts +0 -111
- package/src/interactions/order/extractor.ts +0 -120
- package/src/interactions/order/index.ts +0 -2
- package/src/interactions/order/types.ts +0 -1
- package/src/interactions/portable-custom/extractor.ts +0 -122
- package/src/interactions/portable-custom/index.ts +0 -2
- package/src/interactions/portable-custom/types.ts +0 -1
- package/src/interactions/position-object/extractor.ts +0 -243
- package/src/interactions/position-object/index.ts +0 -2
- package/src/interactions/position-object/types.ts +0 -1
- package/src/interactions/select-point/extractor.ts +0 -143
- package/src/interactions/select-point/index.ts +0 -2
- package/src/interactions/select-point/types.ts +0 -1
- package/src/interactions/shared/index.ts +0 -1
- package/src/interactions/shared/types.ts +0 -430
- package/src/interactions/slider/extractor.ts +0 -102
- package/src/interactions/slider/index.ts +0 -2
- package/src/interactions/slider/types.ts +0 -1
- package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
- package/src/interactions/text-entry/extractor.ts +0 -79
- package/src/interactions/text-entry/index.ts +0 -2
- package/src/interactions/text-entry/types.ts +0 -1
- package/src/interactions/upload/extractor.ts +0 -81
- package/src/interactions/upload/index.ts +0 -2
- package/src/interactions/upload/types.ts +0 -1
- package/src/pci/PciHost.ts +0 -138
- package/src/pci/types.ts +0 -70
- package/src/pnp/applyPnp.ts +0 -29
- package/src/pnp/parsePnpXml.ts +0 -215
- package/src/pnp/types.ts +0 -75
- package/src/server.ts +0 -14
- package/src/types/index.ts +0 -388
- package/src/types/interactions.ts +0 -8
- package/src/types/responseValidation.ts +0 -29
- package/src/types/xmldom.d.ts +0 -12
- package/src/utils/PerformanceMonitor.ts +0 -335
- package/src/utils/drawingUtils.ts +0 -73
- package/src/utils/responseUtils.ts +0 -51
- package/src/utils/touchDragHelper.ts +0 -1
- package/src/web-components/QTIInteractionBase.ts +0 -303
- package/src/web-components/QTIInteractionElement.ts +0 -125
- package/src/web-components/index.ts +0 -22
package/src/core/Plugin.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin System for QTI 2.2 Item Player
|
|
3
|
-
*
|
|
4
|
-
* Provides extensible plugin architecture for custom extractors
|
|
5
|
-
* and interaction rendering.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
9
|
-
import type { PlayerConfig, QTIRole } from '../types/index.js';
|
|
10
|
-
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
11
|
-
import type { Player } from './Player.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* QTI element type (from node-html-parser or browser DOM)
|
|
15
|
-
*/
|
|
16
|
-
export type QTIElement = any;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* QTI Plugin interface
|
|
20
|
-
*
|
|
21
|
-
* Plugins can register custom extractors and web components to handle vendor-specific QTI extensions.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const myPlugin: QTIPlugin = {
|
|
26
|
-
* name: '@vendor/my-qti-plugin',
|
|
27
|
-
* version: '1.0.0',
|
|
28
|
-
* description: 'Custom QTI extensions',
|
|
29
|
-
*
|
|
30
|
-
* registerExtractors(registry: ExtractionRegistry) {
|
|
31
|
-
* // Register custom element extractors
|
|
32
|
-
* registry.register(myCustomExtractor);
|
|
33
|
-
* },
|
|
34
|
-
*
|
|
35
|
-
* registerComponents(registry: ComponentRegistry) {
|
|
36
|
-
* // Register custom web components
|
|
37
|
-
* registry.register('choiceInteraction', {
|
|
38
|
-
* name: 'my-choice',
|
|
39
|
-
* priority: 100,
|
|
40
|
-
* canHandle: (data) => data.interactionClasses?.includes('my-custom'),
|
|
41
|
-
* tagName: 'my-custom-choice'
|
|
42
|
-
* });
|
|
43
|
-
* }
|
|
44
|
-
* };
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export interface QTIPlugin {
|
|
48
|
-
/** Unique plugin identifier */
|
|
49
|
-
name: string;
|
|
50
|
-
|
|
51
|
-
/** Semantic version */
|
|
52
|
-
version: string;
|
|
53
|
-
|
|
54
|
-
/** Optional plugin description */
|
|
55
|
-
description?: string;
|
|
56
|
-
|
|
57
|
-
/** Dependencies on other plugins (by name) */
|
|
58
|
-
dependencies?: string[];
|
|
59
|
-
|
|
60
|
-
/** Lifecycle hooks */
|
|
61
|
-
lifecycle?: PluginLifecycle;
|
|
62
|
-
|
|
63
|
-
/** Register custom extractors with the extraction registry */
|
|
64
|
-
registerExtractors?(registry: ExtractionRegistry): void;
|
|
65
|
-
|
|
66
|
-
/** Register custom web components with the component registry */
|
|
67
|
-
registerComponents?(registry: ComponentRegistry): void;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Plugin lifecycle hooks
|
|
72
|
-
*/
|
|
73
|
-
export interface PluginLifecycle {
|
|
74
|
-
/** Called when plugin is registered */
|
|
75
|
-
onRegister?(context: PluginContext): void | Promise<void>;
|
|
76
|
-
|
|
77
|
-
/** Called before item rendering starts */
|
|
78
|
-
onBeforeRender?(context: RenderContext): void | Promise<void>;
|
|
79
|
-
|
|
80
|
-
/** Called after item rendering completes */
|
|
81
|
-
onAfterRender?(context: RenderContext): void | Promise<void>;
|
|
82
|
-
|
|
83
|
-
/** Called when plugin is unregistered */
|
|
84
|
-
onUnregister?(): void | Promise<void>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Context provided to plugins during registration
|
|
89
|
-
*
|
|
90
|
-
* Note: Player reference is NOT available during registration to avoid circular dependencies.
|
|
91
|
-
* Use RenderContext for lifecycle hooks that need Player access.
|
|
92
|
-
*/
|
|
93
|
-
export interface PluginContext {
|
|
94
|
-
/** Extraction registry for custom extractors */
|
|
95
|
-
extractionRegistry: ExtractionRegistry;
|
|
96
|
-
|
|
97
|
-
/** Component registry for custom web components */
|
|
98
|
-
componentRegistry: ComponentRegistry;
|
|
99
|
-
|
|
100
|
-
/** Item document (if loaded) - can be browser Document or node-html-parser HTMLElement */
|
|
101
|
-
dom?: QTIElement;
|
|
102
|
-
|
|
103
|
-
/** Player configuration */
|
|
104
|
-
config: PlayerConfig;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Context provided during rendering lifecycle hooks
|
|
109
|
-
* Extends PluginContext with Player instance access
|
|
110
|
-
*/
|
|
111
|
-
export interface RenderContext extends PluginContext {
|
|
112
|
-
/** Player instance (available during render hooks) */
|
|
113
|
-
player: Player;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Rendering context (minimal and stable).
|
|
117
|
-
* Note: rendering is via web components; this config is primarily for lifecycle hooks.
|
|
118
|
-
*/
|
|
119
|
-
config: {
|
|
120
|
-
role: QTIRole;
|
|
121
|
-
options?: Record<string, any>;
|
|
122
|
-
};
|
|
123
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin Manager
|
|
3
|
-
*
|
|
4
|
-
* Manages plugin registration, dependency resolution, and lifecycle.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type {
|
|
8
|
-
PluginContext,
|
|
9
|
-
QTIPlugin,
|
|
10
|
-
RenderContext
|
|
11
|
-
} from './Plugin.js';
|
|
12
|
-
|
|
13
|
-
export class PluginManager {
|
|
14
|
-
private plugins = new Map<string, QTIPlugin>();
|
|
15
|
-
private initialized = new Set<string>();
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Register a plugin
|
|
19
|
-
* @throws Error if plugin is invalid or dependencies are missing
|
|
20
|
-
*/
|
|
21
|
-
async register(plugin: QTIPlugin, context: PluginContext): Promise<void> {
|
|
22
|
-
// Validate plugin
|
|
23
|
-
this.validatePlugin(plugin);
|
|
24
|
-
|
|
25
|
-
// Check if already registered
|
|
26
|
-
if (this.plugins.has(plugin.name)) {
|
|
27
|
-
throw new Error(`Plugin '${plugin.name}' is already registered`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Check dependencies
|
|
31
|
-
await this.checkDependencies(plugin);
|
|
32
|
-
|
|
33
|
-
// Store plugin
|
|
34
|
-
this.plugins.set(plugin.name, plugin);
|
|
35
|
-
|
|
36
|
-
// Call lifecycle hook
|
|
37
|
-
try {
|
|
38
|
-
await plugin.lifecycle?.onRegister?.(context);
|
|
39
|
-
this.initialized.add(plugin.name);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
// Rollback on error
|
|
42
|
-
this.plugins.delete(plugin.name);
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Failed to initialize plugin '${plugin.name}': ${error instanceof Error ? error.message : String(error)}`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Unregister a plugin
|
|
51
|
-
*/
|
|
52
|
-
async unregister(pluginName: string): Promise<void> {
|
|
53
|
-
const plugin = this.plugins.get(pluginName);
|
|
54
|
-
if (!plugin) return;
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
// Call lifecycle hook
|
|
58
|
-
await plugin.lifecycle?.onUnregister?.();
|
|
59
|
-
} finally {
|
|
60
|
-
// Remove plugin even if hook fails
|
|
61
|
-
this.plugins.delete(pluginName);
|
|
62
|
-
this.initialized.delete(pluginName);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get all registered plugins
|
|
68
|
-
*/
|
|
69
|
-
getAll(): QTIPlugin[] {
|
|
70
|
-
return Array.from(this.plugins.values());
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get plugin by name
|
|
75
|
-
*/
|
|
76
|
-
get(name: string): QTIPlugin | undefined {
|
|
77
|
-
return this.plugins.get(name);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Check if plugin is registered
|
|
82
|
-
*/
|
|
83
|
-
has(name: string): boolean {
|
|
84
|
-
return this.plugins.has(name);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Check if plugin is initialized
|
|
89
|
-
*/
|
|
90
|
-
isInitialized(name: string): boolean {
|
|
91
|
-
return this.initialized.has(name);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Legacy getRendererRegistrations() method removed
|
|
95
|
-
// Plugins now register components via ComponentRegistry instead
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Call onBeforeRender hooks for all plugins
|
|
99
|
-
*/
|
|
100
|
-
async callBeforeRenderHooks(context: RenderContext): Promise<void> {
|
|
101
|
-
for (const plugin of this.plugins.values()) {
|
|
102
|
-
try {
|
|
103
|
-
await plugin.lifecycle?.onBeforeRender?.(context);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error(
|
|
106
|
-
`Plugin '${plugin.name}' onBeforeRender hook failed:`,
|
|
107
|
-
error
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Call onAfterRender hooks for all plugins
|
|
115
|
-
*/
|
|
116
|
-
async callAfterRenderHooks(context: RenderContext): Promise<void> {
|
|
117
|
-
for (const plugin of this.plugins.values()) {
|
|
118
|
-
try {
|
|
119
|
-
await plugin.lifecycle?.onAfterRender?.(context);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error(
|
|
122
|
-
`Plugin '${plugin.name}' onAfterRender hook failed:`,
|
|
123
|
-
error
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Validate plugin structure
|
|
131
|
-
*/
|
|
132
|
-
private validatePlugin(plugin: QTIPlugin): void {
|
|
133
|
-
if (!plugin.name || typeof plugin.name !== 'string') {
|
|
134
|
-
throw new Error('Plugin must have a valid name');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!plugin.version || typeof plugin.version !== 'string') {
|
|
138
|
-
throw new Error(`Plugin '${plugin.name}' must have a valid version`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Validate semantic version format (basic check)
|
|
142
|
-
if (!/^\d+\.\d+\.\d+/.test(plugin.version)) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
`Plugin '${plugin.name}' has invalid version format: ${plugin.version}`
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Check if plugin dependencies are satisfied
|
|
151
|
-
*/
|
|
152
|
-
private async checkDependencies(plugin: QTIPlugin): Promise<void> {
|
|
153
|
-
if (!plugin.dependencies || plugin.dependencies.length === 0) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const missing: string[] = [];
|
|
158
|
-
|
|
159
|
-
for (const dep of plugin.dependencies) {
|
|
160
|
-
if (!this.plugins.has(dep)) {
|
|
161
|
-
missing.push(dep);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (missing.length > 0) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`Plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Clear all plugins
|
|
174
|
-
*/
|
|
175
|
-
async clear(): Promise<void> {
|
|
176
|
-
const plugins = Array.from(this.plugins.keys());
|
|
177
|
-
|
|
178
|
-
for (const pluginName of plugins) {
|
|
179
|
-
await this.unregister(pluginName);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
package/src/core/constants.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI constants and configuration
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { VariableDeclaration } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
// Prefix for data attributes and CSS classes
|
|
8
|
-
export const PREFIX = 'pie-qti';
|
|
9
|
-
|
|
10
|
-
// Data attributes
|
|
11
|
-
export const ID = `data-${PREFIX}-identifier`;
|
|
12
|
-
export const RESPONSE_ID = `data-${PREFIX}-response-identifier`;
|
|
13
|
-
export const TAG = `data-${PREFIX}-tag`;
|
|
14
|
-
export const NAVMODE = `data-${PREFIX}-navigation-mode`;
|
|
15
|
-
export const SHOWHIDE = `data-${PREFIX}-show-hide`;
|
|
16
|
-
|
|
17
|
-
// CSS class names
|
|
18
|
-
export const ANSWERED = `${PREFIX}-answered`;
|
|
19
|
-
export const ASSOCIABLE = `${PREFIX}-associable`;
|
|
20
|
-
export const ASSOCIATION = `${PREFIX}-association`;
|
|
21
|
-
export const CHOICES = `${PREFIX}-choices`;
|
|
22
|
-
export const CLICKED = `${PREFIX}-clicked`;
|
|
23
|
-
export const CURRENT = `${PREFIX}-current`;
|
|
24
|
-
export const DRAGGING = `${PREFIX}-dragging`;
|
|
25
|
-
export const DRAGOVER = `${PREFIX}-dragover`;
|
|
26
|
-
export const GAP = `${PREFIX}-gap`;
|
|
27
|
-
export const GHOST = `${PREFIX}-ghost`;
|
|
28
|
-
export const HOTSPOT = `${PREFIX}-hotspot`;
|
|
29
|
-
export const INTERACTION = `${PREFIX}-interaction`;
|
|
30
|
-
export const MATCH = `${PREFIX}-match`;
|
|
31
|
-
export const MATCHED = `${PREFIX}-matched`;
|
|
32
|
-
export const MODAL = `${PREFIX}-modal`;
|
|
33
|
-
export const NAVIGATION = `${PREFIX}-navigation`;
|
|
34
|
-
export const PIVOTABLE = `${PREFIX}-pivotable`;
|
|
35
|
-
export const SELECTED = `${PREFIX}-selected`;
|
|
36
|
-
|
|
37
|
-
// CSS selectors
|
|
38
|
-
export const ASSOCIABLE_SEL = `.${ASSOCIABLE}`;
|
|
39
|
-
export const ASSOCIATION_SEL = `.${ASSOCIATION}`;
|
|
40
|
-
export const CHOICES_SEL = `.${CHOICES}`;
|
|
41
|
-
export const CLICKED_SEL = `.${CLICKED}`;
|
|
42
|
-
export const DRAGGING_SEL = `.${DRAGGING}`;
|
|
43
|
-
export const DRAGOVER_SEL = `.${DRAGOVER}`;
|
|
44
|
-
export const GAP_IMG_SEL = `[${TAG}="gapImg"]`;
|
|
45
|
-
export const GAP_SEL = `.${GAP}`;
|
|
46
|
-
export const GAP_TEXT_SEL = `[${TAG}="gapText"]`;
|
|
47
|
-
export const GHOST_SEL = `.${GHOST}`;
|
|
48
|
-
export const HOTSPOT_SEL = `.${HOTSPOT}`;
|
|
49
|
-
export const INTERACTION_SEL = `.${INTERACTION}`;
|
|
50
|
-
export const ITEM_SEL = `[${TAG}="assessmentItem"]`;
|
|
51
|
-
export const SIMPLECHOICE_SEL = `[${TAG}="simpleChoice"]`;
|
|
52
|
-
|
|
53
|
-
// Message identifiers
|
|
54
|
-
export const MSG_OK = `${PREFIX}-msg-ok`;
|
|
55
|
-
export const MSG_NONE = `${PREFIX}-msg-none`;
|
|
56
|
-
export const MSG_NO_SKIP = `${PREFIX}-msg-no-skip`;
|
|
57
|
-
export const MSG_TOO_MANY = `${PREFIX}-msg-too-many`;
|
|
58
|
-
export const MSG_TOO_FEW = `${PREFIX}-msg-too-few`;
|
|
59
|
-
export const MSG_MISMATCH = `${PREFIX}-msg-match-not-allowed`;
|
|
60
|
-
|
|
61
|
-
// Built-in QTI variable declarations
|
|
62
|
-
export const BUILTIN_DECLARATIONS: Record<string, VariableDeclaration> = {
|
|
63
|
-
numAttempts: {
|
|
64
|
-
identifier: 'numAttempts',
|
|
65
|
-
value: 0,
|
|
66
|
-
baseType: 'integer',
|
|
67
|
-
cardinality: 'single',
|
|
68
|
-
},
|
|
69
|
-
duration: {
|
|
70
|
-
identifier: 'duration',
|
|
71
|
-
value: null,
|
|
72
|
-
baseType: 'duration',
|
|
73
|
-
cardinality: 'single',
|
|
74
|
-
},
|
|
75
|
-
completionStatus: {
|
|
76
|
-
identifier: 'completionStatus',
|
|
77
|
-
value: 'not_attempted',
|
|
78
|
-
baseType: 'string',
|
|
79
|
-
cardinality: 'single',
|
|
80
|
-
},
|
|
81
|
-
$comment: {
|
|
82
|
-
identifier: '$comment',
|
|
83
|
-
value: null,
|
|
84
|
-
baseType: 'string',
|
|
85
|
-
cardinality: 'single',
|
|
86
|
-
},
|
|
87
|
-
$dirty: {
|
|
88
|
-
identifier: '$dirty',
|
|
89
|
-
value: false,
|
|
90
|
-
baseType: 'boolean',
|
|
91
|
-
cardinality: 'single',
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// Namespaces
|
|
96
|
-
/**
|
|
97
|
-
* QTI 2.2 Response Processing Templates namespace.
|
|
98
|
-
* Note: Template resolution is namespace-agnostic - only the template filename is used.
|
|
99
|
-
* Templates from v2p0, v2p1, and v2p2 namespaces are all supported.
|
|
100
|
-
*/
|
|
101
|
-
export const RPTEMPLATES = 'http://www.imsglobal.org/question/qti_v2p2/rptemplates';
|
|
102
|
-
export const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
103
|
-
export const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
104
|
-
export const XML_NS = 'http://www.w3.org/XML/1998/namespace';
|
|
105
|
-
|
|
106
|
-
// UI constants
|
|
107
|
-
export const DEFAULT_THEME = 'theme';
|
|
108
|
-
export const MAX_TABLE_COLS = 4;
|
|
109
|
-
|
|
110
|
-
// Localization (English defaults)
|
|
111
|
-
export const EN = {
|
|
112
|
-
UPLOAD: 'Upload file',
|
|
113
|
-
COMMENT: 'Comment on this question if you wish.',
|
|
114
|
-
EXPECTED_CHARS: (len: number) => `expected: ${len} chars`,
|
|
115
|
-
EXPECTED_LINES: (lines: number) => `expected: ${lines} lines`,
|
|
116
|
-
END_TEST: '<p>You have reached the end of the test</p>',
|
|
117
|
-
};
|
package/src/core/declarations.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI variable declarations management
|
|
3
|
-
* Ported from an earlier implementation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { AreaMapping, Mapping, VariableDeclaration } from '../types/index.js';
|
|
7
|
-
import { BUILTIN_DECLARATIONS } from './constants.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Declarations storage for an item or section
|
|
11
|
-
*/
|
|
12
|
-
export interface DeclarationsContext {
|
|
13
|
-
declarations: Record<string, VariableDeclaration>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Initialize declarations for an element
|
|
18
|
-
*/
|
|
19
|
-
export function initializeDeclarations(declarations: Record<string, VariableDeclaration>): void {
|
|
20
|
-
// Clone built-in declarations
|
|
21
|
-
Object.keys(BUILTIN_DECLARATIONS).forEach((id) => {
|
|
22
|
-
const builtinDecl = BUILTIN_DECLARATIONS[id];
|
|
23
|
-
declarations[id] = { ...builtinDecl };
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Add a response or outcome declaration
|
|
29
|
-
*/
|
|
30
|
-
export function addDeclaration(
|
|
31
|
-
declarations: Record<string, VariableDeclaration>,
|
|
32
|
-
identifier: string,
|
|
33
|
-
baseType: VariableDeclaration['baseType'],
|
|
34
|
-
cardinality: VariableDeclaration['cardinality'],
|
|
35
|
-
defaultValue?: any
|
|
36
|
-
): void {
|
|
37
|
-
const value = cardinality === 'multiple' ? [] : null;
|
|
38
|
-
|
|
39
|
-
declarations[identifier] = {
|
|
40
|
-
identifier,
|
|
41
|
-
baseType,
|
|
42
|
-
cardinality,
|
|
43
|
-
value: defaultValue ?? value,
|
|
44
|
-
defaultValue,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Add a mapping to a response declaration
|
|
50
|
-
*/
|
|
51
|
-
export function addMapping(
|
|
52
|
-
declarations: Record<string, VariableDeclaration>,
|
|
53
|
-
identifier: string,
|
|
54
|
-
mapping: Mapping
|
|
55
|
-
): void {
|
|
56
|
-
const decl = declarations[identifier];
|
|
57
|
-
if (decl) {
|
|
58
|
-
decl.mapping = mapping;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Add an area mapping to a response declaration
|
|
64
|
-
*/
|
|
65
|
-
export function addAreaMapping(
|
|
66
|
-
declarations: Record<string, VariableDeclaration>,
|
|
67
|
-
identifier: string,
|
|
68
|
-
areaMapping: AreaMapping
|
|
69
|
-
): void {
|
|
70
|
-
const decl = declarations[identifier];
|
|
71
|
-
if (decl) {
|
|
72
|
-
decl.areaMapping = areaMapping;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get a variable value from declarations
|
|
78
|
-
* @returns {any} QTI variables can hold any type
|
|
79
|
-
*/
|
|
80
|
-
export function getVariableValue(
|
|
81
|
-
declarations: Record<string, VariableDeclaration>,
|
|
82
|
-
identifier: string
|
|
83
|
-
): any {
|
|
84
|
-
const decl = declarations[identifier];
|
|
85
|
-
return decl ? decl.value : null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Set a variable value in declarations
|
|
90
|
-
*/
|
|
91
|
-
export function setVariableValue(
|
|
92
|
-
declarations: Record<string, VariableDeclaration>,
|
|
93
|
-
identifier: string,
|
|
94
|
-
value: any
|
|
95
|
-
): void {
|
|
96
|
-
const decl = declarations[identifier];
|
|
97
|
-
if (decl) {
|
|
98
|
-
const coerceScalar = (v: any) => {
|
|
99
|
-
if (v === null || v === undefined) return v;
|
|
100
|
-
const baseType = decl.baseType;
|
|
101
|
-
if (baseType === 'integer' || baseType === 'float') {
|
|
102
|
-
const n = Number(v);
|
|
103
|
-
return Number.isNaN(n) ? v : n;
|
|
104
|
-
}
|
|
105
|
-
if (baseType === 'boolean') {
|
|
106
|
-
if (typeof v === 'boolean') return v;
|
|
107
|
-
if (typeof v === 'number') return v !== 0;
|
|
108
|
-
if (typeof v === 'string') return v.trim().toLowerCase() === 'true';
|
|
109
|
-
return Boolean(v);
|
|
110
|
-
}
|
|
111
|
-
if (
|
|
112
|
-
baseType === 'string' ||
|
|
113
|
-
baseType === 'identifier' ||
|
|
114
|
-
baseType === 'uri' ||
|
|
115
|
-
baseType === 'pair' ||
|
|
116
|
-
baseType === 'directedPair' ||
|
|
117
|
-
baseType === 'point'
|
|
118
|
-
) {
|
|
119
|
-
return typeof v === 'string' ? v.trim() : String(v);
|
|
120
|
-
}
|
|
121
|
-
return v;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
|
|
125
|
-
if (Array.isArray(value)) {
|
|
126
|
-
decl.value = value.map(coerceScalar);
|
|
127
|
-
} else if (value === null || value === undefined) {
|
|
128
|
-
decl.value = [];
|
|
129
|
-
} else {
|
|
130
|
-
decl.value = [coerceScalar(value)];
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
decl.value = coerceScalar(value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Reset declarations to default values
|
|
140
|
-
*/
|
|
141
|
-
export function resetDeclarations(declarations: Record<string, VariableDeclaration>): void {
|
|
142
|
-
Object.values(declarations).forEach((decl) => {
|
|
143
|
-
if (decl.defaultValue !== undefined) {
|
|
144
|
-
decl.value = decl.defaultValue;
|
|
145
|
-
} else if (decl.cardinality === 'multiple') {
|
|
146
|
-
decl.value = [];
|
|
147
|
-
} else {
|
|
148
|
-
decl.value = null;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Clone declarations (useful for creating new sessions)
|
|
155
|
-
*/
|
|
156
|
-
export function cloneDeclarations(
|
|
157
|
-
source: Record<string, VariableDeclaration>
|
|
158
|
-
): Record<string, VariableDeclaration> {
|
|
159
|
-
const result: Record<string, VariableDeclaration> = {};
|
|
160
|
-
|
|
161
|
-
Object.keys(source).forEach((id) => {
|
|
162
|
-
const decl = source[id];
|
|
163
|
-
result[id] = {
|
|
164
|
-
...decl,
|
|
165
|
-
value:
|
|
166
|
-
decl.cardinality === 'multiple' && Array.isArray(decl.value) ? [...decl.value] : decl.value,
|
|
167
|
-
};
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { PlayerSecurityConfig } from '../types/index.js';
|
|
2
|
-
|
|
3
|
-
export type NormalizedParsingLimits = {
|
|
4
|
-
enabled: boolean;
|
|
5
|
-
rejectDoctype: boolean;
|
|
6
|
-
maxItemXmlBytes: number;
|
|
7
|
-
maxHtmlBytes: number;
|
|
8
|
-
maxHtmlNodes: number;
|
|
9
|
-
maxHtmlDepth: number;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const DEFAULTS: Omit<NormalizedParsingLimits, 'enabled'> = {
|
|
13
|
-
rejectDoctype: true,
|
|
14
|
-
maxItemXmlBytes: 10_000_000,
|
|
15
|
-
maxHtmlBytes: 5_000_000,
|
|
16
|
-
maxHtmlNodes: 200_000,
|
|
17
|
-
maxHtmlDepth: 200,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
function getByteLengthUtf8(s: string): number {
|
|
21
|
-
// TextEncoder is available in modern runtimes (browser + Bun/node 20+).
|
|
22
|
-
// Fall back to a conservative approximation if unavailable.
|
|
23
|
-
const TE: typeof TextEncoder | undefined = (globalThis as any).TextEncoder;
|
|
24
|
-
if (!TE) return s.length * 2;
|
|
25
|
-
return new TE().encode(s).byteLength;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function normalizeParsingLimits(security?: PlayerSecurityConfig): NormalizedParsingLimits {
|
|
29
|
-
const cfg = security?.parsingLimits;
|
|
30
|
-
const enabled = cfg?.enabled === true;
|
|
31
|
-
if (!enabled) {
|
|
32
|
-
return { enabled: false, ...DEFAULTS };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
enabled: true,
|
|
37
|
-
rejectDoctype: cfg?.rejectDoctype ?? DEFAULTS.rejectDoctype,
|
|
38
|
-
maxItemXmlBytes: cfg?.maxItemXmlBytes ?? DEFAULTS.maxItemXmlBytes,
|
|
39
|
-
maxHtmlBytes: cfg?.maxHtmlBytes ?? DEFAULTS.maxHtmlBytes,
|
|
40
|
-
maxHtmlNodes: cfg?.maxHtmlNodes ?? DEFAULTS.maxHtmlNodes,
|
|
41
|
-
maxHtmlDepth: cfg?.maxHtmlDepth ?? DEFAULTS.maxHtmlDepth,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function enforceItemXmlLimits(itemXml: string, security?: PlayerSecurityConfig): void {
|
|
46
|
-
const limits = normalizeParsingLimits(security);
|
|
47
|
-
if (!limits.enabled) return;
|
|
48
|
-
|
|
49
|
-
const bytes = getByteLengthUtf8(String(itemXml ?? ''));
|
|
50
|
-
if (bytes > limits.maxItemXmlBytes) {
|
|
51
|
-
throw new Error(`itemXml exceeds maxItemXmlBytes (${bytes} > ${limits.maxItemXmlBytes})`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (limits.rejectDoctype) {
|
|
55
|
-
// Case-insensitive and tolerant of whitespace: "<!DOCTYPE"
|
|
56
|
-
if (/<!\s*doctype/i.test(itemXml)) {
|
|
57
|
-
throw new Error('itemXml contains <!DOCTYPE>, which is rejected by parsingLimits');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
package/src/core/random.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deterministic pseudo-random number generator helpers.
|
|
3
|
-
*
|
|
4
|
-
* We keep this tiny and dependency-free so tests (and optionally consumers)
|
|
5
|
-
* can run template processing deterministically.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mulberry32 PRNG.
|
|
10
|
-
* Returns a function that yields a float in [0, 1).
|
|
11
|
-
*/
|
|
12
|
-
export function createSeededRng(seed: number): () => number {
|
|
13
|
-
// Ensure 32-bit unsigned int
|
|
14
|
-
let a = seed >>> 0;
|
|
15
|
-
return () => {
|
|
16
|
-
a = (a + 0x6d2b79f5) >>> 0;
|
|
17
|
-
let t = a;
|
|
18
|
-
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
19
|
-
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
20
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|