@pie-qti/item-player 0.1.19 → 0.1.21
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 +137 -427
- package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
- package/dist/catalog/applyGlossaryTriggers.js +4 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/components/utils/stimulusRender.d.ts +1 -2
- package/dist/components/utils/stimulusRender.js +2 -5
- package/dist/components/utils/stimulusRender.js.map +1 -1
- package/dist/core/AssessmentItemDefinition.d.ts +69 -0
- package/dist/core/AssessmentItemDefinition.js +149 -0
- package/dist/core/AssessmentItemDefinition.js.map +1 -0
- package/dist/core/ComponentRegistry.d.ts +11 -5
- package/dist/core/ComponentRegistry.js +44 -17
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +58 -0
- package/dist/core/ItemSession.js +286 -0
- package/dist/core/ItemSession.js.map +1 -0
- package/dist/core/Player.d.ts +26 -8
- package/dist/core/Player.js +225 -165
- package/dist/core/Player.js.map +1 -1
- package/dist/core/constants.d.ts +0 -2
- package/dist/core/constants.js +0 -33
- package/dist/core/constants.js.map +1 -1
- package/dist/document/AssessmentItemDocument.d.ts +32 -10
- package/dist/document/AssessmentItemDocument.js +80 -23
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/{element-class-BEpwHdcP.js → element-class-iN9MRyjF.js} +3582 -2783
- package/dist/element-class-iN9MRyjF.js.map +1 -0
- package/dist/element-class.d.ts +17 -13
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +34 -11
- package/dist/extraction/ExtractionRegistry.js +122 -19
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +5 -6
- package/dist/extraction/createContext.js +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/deliveryTypes.d.ts +26 -0
- package/dist/extraction/deliveryTypes.js +7 -0
- package/dist/extraction/deliveryTypes.js.map +1 -0
- package/dist/extraction/index.d.ts +3 -3
- package/dist/extraction/index.js +1 -2
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
- package/dist/extraction/interactionExtractionPipeline.js +27 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.d.ts +11 -2
- package/dist/extraction/interactionSecurity.js +105 -40
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/types.d.ts +44 -7
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.js +4 -16
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.js +1 -1
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.js +5 -4
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -2
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/gap-match/extractor.js +4 -3
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.js +5 -4
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.js +20 -17
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.js +5 -4
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.js +11 -10
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/inline/render-plan.d.ts +3 -5
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/media/extractor.js +2 -2
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.d.ts +11 -91
- package/dist/interactions/modules.js +185 -45
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.d.ts +1 -1
- package/dist/interactions/portable-custom/extractor.js +1 -1
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.js +3 -2
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.js +7 -6
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +59 -70
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/slider/extractor.js +2 -2
- package/dist/interactions/slider/extractor.js.map +1 -1
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/types.d.ts +2 -3
- package/dist/pci/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +71 -38
- package/dist/presentation/itemPresentationPlan.js +82 -35
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/security/styleValues.d.ts +20 -0
- package/dist/security/styleValues.js +49 -0
- package/dist/security/styleValues.js.map +1 -0
- package/dist/server.d.ts +188 -9
- package/dist/server.js +32 -7
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +1 -110
- package/dist/types/index.js.map +1 -1
- package/dist/web-components/QTIInteractionBase.d.ts +2 -2
- package/dist/web-components/QTIInteractionBase.js.map +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +3 -3
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/package.json +11 -11
- package/dist/core/Plugin.d.ts +0 -104
- package/dist/core/Plugin.js +0 -8
- package/dist/core/Plugin.js.map +0 -1
- package/dist/core/PluginManager.d.ts +0 -55
- package/dist/core/PluginManager.js +0 -148
- package/dist/core/PluginManager.js.map +0 -1
- package/dist/core/declarations.d.ts +0 -44
- package/dist/core/declarations.js +0 -141
- package/dist/core/declarations.js.map +0 -1
- package/dist/element-class-BEpwHdcP.js.map +0 -1
- package/dist/interactions/associate/index.d.ts +0 -2
- package/dist/interactions/associate/index.js +0 -2
- package/dist/interactions/associate/index.js.map +0 -1
- package/dist/interactions/associate/types.d.ts +0 -1
- package/dist/interactions/associate/types.js +0 -2
- package/dist/interactions/associate/types.js.map +0 -1
- package/dist/interactions/choice/index.d.ts +0 -2
- package/dist/interactions/choice/index.js +0 -2
- package/dist/interactions/choice/index.js.map +0 -1
- package/dist/interactions/choice/types.d.ts +0 -1
- package/dist/interactions/choice/types.js +0 -2
- package/dist/interactions/choice/types.js.map +0 -1
- package/dist/interactions/custom/index.d.ts +0 -2
- package/dist/interactions/custom/index.js +0 -2
- package/dist/interactions/custom/index.js.map +0 -1
- package/dist/interactions/custom/types.d.ts +0 -1
- package/dist/interactions/custom/types.js +0 -2
- package/dist/interactions/custom/types.js.map +0 -1
- package/dist/interactions/drawing/index.d.ts +0 -2
- package/dist/interactions/drawing/index.js +0 -2
- package/dist/interactions/drawing/index.js.map +0 -1
- package/dist/interactions/drawing/types.d.ts +0 -1
- package/dist/interactions/drawing/types.js +0 -2
- package/dist/interactions/drawing/types.js.map +0 -1
- package/dist/interactions/end-attempt/index.d.ts +0 -2
- package/dist/interactions/end-attempt/index.js +0 -2
- package/dist/interactions/end-attempt/index.js.map +0 -1
- package/dist/interactions/end-attempt/types.d.ts +0 -1
- package/dist/interactions/end-attempt/types.js +0 -2
- package/dist/interactions/end-attempt/types.js.map +0 -1
- package/dist/interactions/extended-text/index.d.ts +0 -3
- package/dist/interactions/extended-text/index.js +0 -3
- package/dist/interactions/extended-text/index.js.map +0 -1
- package/dist/interactions/extended-text/types.d.ts +0 -1
- package/dist/interactions/extended-text/types.js +0 -2
- package/dist/interactions/extended-text/types.js.map +0 -1
- package/dist/interactions/gap-match/index.d.ts +0 -2
- package/dist/interactions/gap-match/index.js +0 -2
- package/dist/interactions/gap-match/index.js.map +0 -1
- package/dist/interactions/gap-match/types.d.ts +0 -1
- package/dist/interactions/gap-match/types.js +0 -2
- package/dist/interactions/gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-associate/index.d.ts +0 -2
- package/dist/interactions/graphic-associate/index.js +0 -2
- package/dist/interactions/graphic-associate/index.js.map +0 -1
- package/dist/interactions/graphic-associate/types.d.ts +0 -1
- package/dist/interactions/graphic-associate/types.js +0 -2
- package/dist/interactions/graphic-associate/types.js.map +0 -1
- package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
- package/dist/interactions/graphic-gap-match/index.js +0 -2
- package/dist/interactions/graphic-gap-match/index.js.map +0 -1
- package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
- package/dist/interactions/graphic-gap-match/types.js +0 -2
- package/dist/interactions/graphic-gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-order/index.d.ts +0 -2
- package/dist/interactions/graphic-order/index.js +0 -2
- package/dist/interactions/graphic-order/index.js.map +0 -1
- package/dist/interactions/graphic-order/types.d.ts +0 -1
- package/dist/interactions/graphic-order/types.js +0 -2
- package/dist/interactions/graphic-order/types.js.map +0 -1
- package/dist/interactions/hotspot/index.d.ts +0 -2
- package/dist/interactions/hotspot/index.js +0 -2
- package/dist/interactions/hotspot/index.js.map +0 -1
- package/dist/interactions/hotspot/types.d.ts +0 -1
- package/dist/interactions/hotspot/types.js +0 -2
- package/dist/interactions/hotspot/types.js.map +0 -1
- package/dist/interactions/hottext/index.d.ts +0 -2
- package/dist/interactions/hottext/index.js +0 -2
- package/dist/interactions/hottext/index.js.map +0 -1
- package/dist/interactions/hottext/types.d.ts +0 -1
- package/dist/interactions/hottext/types.js +0 -2
- package/dist/interactions/hottext/types.js.map +0 -1
- package/dist/interactions/index.d.ts +0 -32
- package/dist/interactions/index.js +0 -31
- package/dist/interactions/index.js.map +0 -1
- package/dist/interactions/inline/index.d.ts +0 -1
- package/dist/interactions/inline/index.js +0 -2
- package/dist/interactions/inline/index.js.map +0 -1
- package/dist/interactions/inline-choice/index.d.ts +0 -2
- package/dist/interactions/inline-choice/index.js +0 -2
- package/dist/interactions/inline-choice/index.js.map +0 -1
- package/dist/interactions/inline-choice/types.d.ts +0 -1
- package/dist/interactions/inline-choice/types.js +0 -2
- package/dist/interactions/inline-choice/types.js.map +0 -1
- package/dist/interactions/match/index.d.ts +0 -2
- package/dist/interactions/match/index.js +0 -2
- package/dist/interactions/match/index.js.map +0 -1
- package/dist/interactions/match/types.d.ts +0 -1
- package/dist/interactions/match/types.js +0 -2
- package/dist/interactions/match/types.js.map +0 -1
- package/dist/interactions/media/index.d.ts +0 -2
- package/dist/interactions/media/index.js +0 -2
- package/dist/interactions/media/index.js.map +0 -1
- package/dist/interactions/media/types.d.ts +0 -1
- package/dist/interactions/media/types.js +0 -2
- package/dist/interactions/media/types.js.map +0 -1
- package/dist/interactions/order/index.d.ts +0 -2
- package/dist/interactions/order/index.js +0 -2
- package/dist/interactions/order/index.js.map +0 -1
- package/dist/interactions/order/types.d.ts +0 -1
- package/dist/interactions/order/types.js +0 -2
- package/dist/interactions/order/types.js.map +0 -1
- package/dist/interactions/portable-custom/index.d.ts +0 -2
- package/dist/interactions/portable-custom/index.js +0 -2
- package/dist/interactions/portable-custom/index.js.map +0 -1
- package/dist/interactions/portable-custom/types.d.ts +0 -1
- package/dist/interactions/portable-custom/types.js +0 -2
- package/dist/interactions/portable-custom/types.js.map +0 -1
- package/dist/interactions/position-object/index.d.ts +0 -2
- package/dist/interactions/position-object/index.js +0 -2
- package/dist/interactions/position-object/index.js.map +0 -1
- package/dist/interactions/position-object/types.d.ts +0 -1
- package/dist/interactions/position-object/types.js +0 -2
- package/dist/interactions/position-object/types.js.map +0 -1
- package/dist/interactions/select-point/index.d.ts +0 -2
- package/dist/interactions/select-point/index.js +0 -2
- package/dist/interactions/select-point/index.js.map +0 -1
- package/dist/interactions/select-point/types.d.ts +0 -1
- package/dist/interactions/select-point/types.js +0 -2
- package/dist/interactions/select-point/types.js.map +0 -1
- package/dist/interactions/shared/index.d.ts +0 -1
- package/dist/interactions/shared/index.js +0 -2
- package/dist/interactions/shared/index.js.map +0 -1
- package/dist/interactions/slider/index.d.ts +0 -2
- package/dist/interactions/slider/index.js +0 -2
- package/dist/interactions/slider/index.js.map +0 -1
- package/dist/interactions/slider/types.d.ts +0 -1
- package/dist/interactions/slider/types.js +0 -2
- package/dist/interactions/slider/types.js.map +0 -1
- package/dist/interactions/text-entry/index.d.ts +0 -2
- package/dist/interactions/text-entry/index.js +0 -2
- package/dist/interactions/text-entry/index.js.map +0 -1
- package/dist/interactions/text-entry/types.d.ts +0 -1
- package/dist/interactions/text-entry/types.js +0 -2
- package/dist/interactions/text-entry/types.js.map +0 -1
- package/dist/interactions/upload/index.d.ts +0 -2
- package/dist/interactions/upload/index.js +0 -2
- package/dist/interactions/upload/index.js.map +0 -1
- package/dist/interactions/upload/types.d.ts +0 -1
- package/dist/interactions/upload/types.js +0 -2
- package/dist/interactions/upload/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/item-player",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Modern QTI player supporting QTI 2.2 and 3.0 - Client-side with optional backend hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "vite build && tsc",
|
|
10
10
|
"dev": "tsc --watch",
|
|
11
|
-
"test": "bun test",
|
|
11
|
+
"test": "bun test && tsc -p ./tsconfig.server-types.test.json",
|
|
12
12
|
"typecheck": "tsc --noEmit",
|
|
13
13
|
"check": "svelte-check --tsconfig ./tsconfig.svelte.json",
|
|
14
14
|
"lint": "biome check .",
|
|
@@ -27,22 +27,22 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pie-qti/i18n": "0.1.
|
|
31
|
-
"@pie-qti/ims-cp-core": "0.1.
|
|
32
|
-
"@pie-qti/qti-common": "0.1.
|
|
33
|
-
"@pie-qti/qti-processing": "0.1.
|
|
30
|
+
"@pie-qti/i18n": "0.1.21",
|
|
31
|
+
"@pie-qti/ims-cp-core": "0.1.21",
|
|
32
|
+
"@pie-qti/qti-common": "0.1.21",
|
|
33
|
+
"@pie-qti/qti-processing": "0.1.21",
|
|
34
34
|
"mathlive": "^0.110.0",
|
|
35
35
|
"node-html-parser": "^9.0.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@biomejs/biome": "^2.5.
|
|
39
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
40
|
-
"@types/node": "^
|
|
38
|
+
"@biomejs/biome": "^2.5.7",
|
|
39
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
40
|
+
"@types/node": "^26.2.0",
|
|
41
41
|
"svelte": "^5.56.8",
|
|
42
|
-
"svelte-check": "^4.
|
|
42
|
+
"svelte-check": "^4.7.5",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vite": "^8.0.10",
|
|
45
|
-
"vite-plugin-dts": "^
|
|
45
|
+
"vite-plugin-dts": "^5.0.3"
|
|
46
46
|
},
|
|
47
47
|
"exports": {
|
|
48
48
|
".": {
|
package/dist/core/Plugin.d.ts
DELETED
|
@@ -1,104 +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
|
-
import type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
8
|
-
import type { PlayerConfig, QTIRole } from '../types/index.js';
|
|
9
|
-
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
10
|
-
import type { Player } from './Player.js';
|
|
11
|
-
/**
|
|
12
|
-
* QTI element type (from node-html-parser or browser DOM)
|
|
13
|
-
*/
|
|
14
|
-
export type QTIElement = any;
|
|
15
|
-
/**
|
|
16
|
-
* QTI Plugin interface
|
|
17
|
-
*
|
|
18
|
-
* Plugins can register custom extractors and web components to handle vendor-specific QTI extensions.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const myPlugin: QTIPlugin = {
|
|
23
|
-
* name: '@vendor/my-qti-plugin',
|
|
24
|
-
* version: '1.0.0',
|
|
25
|
-
* description: 'Custom QTI extensions',
|
|
26
|
-
*
|
|
27
|
-
* registerExtractors(registry: ExtractionRegistry) {
|
|
28
|
-
* // Register custom element extractors
|
|
29
|
-
* registry.register(myCustomExtractor);
|
|
30
|
-
* },
|
|
31
|
-
*
|
|
32
|
-
* registerComponents(registry: ComponentRegistry) {
|
|
33
|
-
* // Register custom web components
|
|
34
|
-
* registry.register('choiceInteraction', {
|
|
35
|
-
* name: 'my-choice',
|
|
36
|
-
* priority: 100,
|
|
37
|
-
* canHandle: (data) => data.interactionClasses?.includes('my-custom'),
|
|
38
|
-
* tagName: 'my-custom-choice'
|
|
39
|
-
* });
|
|
40
|
-
* }
|
|
41
|
-
* };
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export interface QTIPlugin {
|
|
45
|
-
/** Unique plugin identifier */
|
|
46
|
-
name: string;
|
|
47
|
-
/** Semantic version */
|
|
48
|
-
version: string;
|
|
49
|
-
/** Optional plugin description */
|
|
50
|
-
description?: string;
|
|
51
|
-
/** Dependencies on other plugins (by name) */
|
|
52
|
-
dependencies?: string[];
|
|
53
|
-
/** Lifecycle hooks */
|
|
54
|
-
lifecycle?: PluginLifecycle;
|
|
55
|
-
/** Register custom extractors with the extraction registry */
|
|
56
|
-
registerExtractors?(registry: ExtractionRegistry): void;
|
|
57
|
-
/** Register custom web components with the component registry */
|
|
58
|
-
registerComponents?(registry: ComponentRegistry): void;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Plugin lifecycle hooks
|
|
62
|
-
*/
|
|
63
|
-
export interface PluginLifecycle {
|
|
64
|
-
/** Called when plugin is registered */
|
|
65
|
-
onRegister?(context: PluginContext): void | Promise<void>;
|
|
66
|
-
/** Called before item rendering starts */
|
|
67
|
-
onBeforeRender?(context: RenderContext): void | Promise<void>;
|
|
68
|
-
/** Called after item rendering completes */
|
|
69
|
-
onAfterRender?(context: RenderContext): void | Promise<void>;
|
|
70
|
-
/** Called when plugin is unregistered */
|
|
71
|
-
onUnregister?(): void | Promise<void>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Context provided to plugins during registration
|
|
75
|
-
*
|
|
76
|
-
* Note: Player reference is NOT available during registration to avoid circular dependencies.
|
|
77
|
-
* Use RenderContext for lifecycle hooks that need Player access.
|
|
78
|
-
*/
|
|
79
|
-
export interface PluginContext {
|
|
80
|
-
/** Extraction registry for custom extractors */
|
|
81
|
-
extractionRegistry: ExtractionRegistry;
|
|
82
|
-
/** Component registry for custom web components */
|
|
83
|
-
componentRegistry: ComponentRegistry;
|
|
84
|
-
/** Item document (if loaded) - can be browser Document or node-html-parser HTMLElement */
|
|
85
|
-
dom?: QTIElement;
|
|
86
|
-
/** Player configuration */
|
|
87
|
-
config: PlayerConfig;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Context provided during rendering lifecycle hooks
|
|
91
|
-
* Extends PluginContext with Player instance access
|
|
92
|
-
*/
|
|
93
|
-
export interface RenderContext extends PluginContext {
|
|
94
|
-
/** Player instance (available during render hooks) */
|
|
95
|
-
player: Player;
|
|
96
|
-
/**
|
|
97
|
-
* Rendering context (minimal and stable).
|
|
98
|
-
* Note: rendering is via web components; this config is primarily for lifecycle hooks.
|
|
99
|
-
*/
|
|
100
|
-
config: {
|
|
101
|
-
role: QTIRole;
|
|
102
|
-
options?: Record<string, any>;
|
|
103
|
-
};
|
|
104
|
-
}
|
package/dist/core/Plugin.js
DELETED
package/dist/core/Plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/core/Plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * Plugin System for QTI 2.2 Item Player\n *\n * Provides extensible plugin architecture for custom extractors\n * and interaction rendering.\n */\n\nimport type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';\nimport type { PlayerConfig, QTIRole } from '../types/index.js';\nimport type { ComponentRegistry } from './ComponentRegistry.js';\nimport type { Player } from './Player.js';\n\n/**\n * QTI element type (from node-html-parser or browser DOM)\n */\nexport type QTIElement = any;\n\n/**\n * QTI Plugin interface\n *\n * Plugins can register custom extractors and web components to handle vendor-specific QTI extensions.\n *\n * @example\n * ```typescript\n * const myPlugin: QTIPlugin = {\n * name: '@vendor/my-qti-plugin',\n * version: '1.0.0',\n * description: 'Custom QTI extensions',\n *\n * registerExtractors(registry: ExtractionRegistry) {\n * // Register custom element extractors\n * registry.register(myCustomExtractor);\n * },\n *\n * registerComponents(registry: ComponentRegistry) {\n * // Register custom web components\n * registry.register('choiceInteraction', {\n * name: 'my-choice',\n * priority: 100,\n * canHandle: (data) => data.interactionClasses?.includes('my-custom'),\n * tagName: 'my-custom-choice'\n * });\n * }\n * };\n * ```\n */\nexport interface QTIPlugin {\n\t/** Unique plugin identifier */\n\tname: string;\n\n\t/** Semantic version */\n\tversion: string;\n\n\t/** Optional plugin description */\n\tdescription?: string;\n\n\t/** Dependencies on other plugins (by name) */\n\tdependencies?: string[];\n\n\t/** Lifecycle hooks */\n\tlifecycle?: PluginLifecycle;\n\n\t/** Register custom extractors with the extraction registry */\n\tregisterExtractors?(registry: ExtractionRegistry): void;\n\n\t/** Register custom web components with the component registry */\n\tregisterComponents?(registry: ComponentRegistry): void;\n}\n\n/**\n * Plugin lifecycle hooks\n */\nexport interface PluginLifecycle {\n\t/** Called when plugin is registered */\n\tonRegister?(context: PluginContext): void | Promise<void>;\n\n\t/** Called before item rendering starts */\n\tonBeforeRender?(context: RenderContext): void | Promise<void>;\n\n\t/** Called after item rendering completes */\n\tonAfterRender?(context: RenderContext): void | Promise<void>;\n\n\t/** Called when plugin is unregistered */\n\tonUnregister?(): void | Promise<void>;\n}\n\n/**\n * Context provided to plugins during registration\n *\n * Note: Player reference is NOT available during registration to avoid circular dependencies.\n * Use RenderContext for lifecycle hooks that need Player access.\n */\nexport interface PluginContext {\n\t/** Extraction registry for custom extractors */\n\textractionRegistry: ExtractionRegistry;\n\n\t/** Component registry for custom web components */\n\tcomponentRegistry: ComponentRegistry;\n\n\t/** Item document (if loaded) - can be browser Document or node-html-parser HTMLElement */\n\tdom?: QTIElement;\n\n\t/** Player configuration */\n\tconfig: PlayerConfig;\n}\n\n/**\n * Context provided during rendering lifecycle hooks\n * Extends PluginContext with Player instance access\n */\nexport interface RenderContext extends PluginContext {\n\t/** Player instance (available during render hooks) */\n\tplayer: Player;\n\n\t/**\n\t * Rendering context (minimal and stable).\n\t * Note: rendering is via web components; this config is primarily for lifecycle hooks.\n\t */\n\tconfig: {\n\t\trole: QTIRole;\n\t\toptions?: Record<string, any>;\n\t};\n}\n"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin Manager
|
|
3
|
-
*
|
|
4
|
-
* Manages plugin registration, dependency resolution, and lifecycle.
|
|
5
|
-
*/
|
|
6
|
-
import type { PluginContext, QTIPlugin, RenderContext } from './Plugin.js';
|
|
7
|
-
export declare class PluginManager {
|
|
8
|
-
private plugins;
|
|
9
|
-
private initialized;
|
|
10
|
-
/**
|
|
11
|
-
* Register a plugin
|
|
12
|
-
* @throws Error if plugin is invalid or dependencies are missing
|
|
13
|
-
*/
|
|
14
|
-
register(plugin: QTIPlugin, context: PluginContext): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Unregister a plugin
|
|
17
|
-
*/
|
|
18
|
-
unregister(pluginName: string): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Get all registered plugins
|
|
21
|
-
*/
|
|
22
|
-
getAll(): QTIPlugin[];
|
|
23
|
-
/**
|
|
24
|
-
* Get plugin by name
|
|
25
|
-
*/
|
|
26
|
-
get(name: string): QTIPlugin | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Check if plugin is registered
|
|
29
|
-
*/
|
|
30
|
-
has(name: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Check if plugin is initialized
|
|
33
|
-
*/
|
|
34
|
-
isInitialized(name: string): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Call onBeforeRender hooks for all plugins
|
|
37
|
-
*/
|
|
38
|
-
callBeforeRenderHooks(context: RenderContext): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Call onAfterRender hooks for all plugins
|
|
41
|
-
*/
|
|
42
|
-
callAfterRenderHooks(context: RenderContext): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Validate plugin structure
|
|
45
|
-
*/
|
|
46
|
-
private validatePlugin;
|
|
47
|
-
/**
|
|
48
|
-
* Check if plugin dependencies are satisfied
|
|
49
|
-
*/
|
|
50
|
-
private checkDependencies;
|
|
51
|
-
/**
|
|
52
|
-
* Clear all plugins
|
|
53
|
-
*/
|
|
54
|
-
clear(): Promise<void>;
|
|
55
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin Manager
|
|
3
|
-
*
|
|
4
|
-
* Manages plugin registration, dependency resolution, and lifecycle.
|
|
5
|
-
*/
|
|
6
|
-
export class PluginManager {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.plugins = new Map();
|
|
9
|
-
this.initialized = new Set();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Register a plugin
|
|
13
|
-
* @throws Error if plugin is invalid or dependencies are missing
|
|
14
|
-
*/
|
|
15
|
-
async register(plugin, context) {
|
|
16
|
-
// Validate plugin
|
|
17
|
-
this.validatePlugin(plugin);
|
|
18
|
-
// Check if already registered
|
|
19
|
-
if (this.plugins.has(plugin.name)) {
|
|
20
|
-
throw new Error(`Plugin '${plugin.name}' is already registered`);
|
|
21
|
-
}
|
|
22
|
-
// Check dependencies
|
|
23
|
-
await this.checkDependencies(plugin);
|
|
24
|
-
// Store plugin
|
|
25
|
-
this.plugins.set(plugin.name, plugin);
|
|
26
|
-
// Call lifecycle hook
|
|
27
|
-
try {
|
|
28
|
-
await plugin.lifecycle?.onRegister?.(context);
|
|
29
|
-
this.initialized.add(plugin.name);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
// Rollback on error
|
|
33
|
-
this.plugins.delete(plugin.name);
|
|
34
|
-
throw new Error(`Failed to initialize plugin '${plugin.name}': ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Unregister a plugin
|
|
39
|
-
*/
|
|
40
|
-
async unregister(pluginName) {
|
|
41
|
-
const plugin = this.plugins.get(pluginName);
|
|
42
|
-
if (!plugin)
|
|
43
|
-
return;
|
|
44
|
-
try {
|
|
45
|
-
// Call lifecycle hook
|
|
46
|
-
await plugin.lifecycle?.onUnregister?.();
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
// Remove plugin even if hook fails
|
|
50
|
-
this.plugins.delete(pluginName);
|
|
51
|
-
this.initialized.delete(pluginName);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get all registered plugins
|
|
56
|
-
*/
|
|
57
|
-
getAll() {
|
|
58
|
-
return Array.from(this.plugins.values());
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get plugin by name
|
|
62
|
-
*/
|
|
63
|
-
get(name) {
|
|
64
|
-
return this.plugins.get(name);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if plugin is registered
|
|
68
|
-
*/
|
|
69
|
-
has(name) {
|
|
70
|
-
return this.plugins.has(name);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check if plugin is initialized
|
|
74
|
-
*/
|
|
75
|
-
isInitialized(name) {
|
|
76
|
-
return this.initialized.has(name);
|
|
77
|
-
}
|
|
78
|
-
// Legacy getRendererRegistrations() method removed
|
|
79
|
-
// Plugins now register components via ComponentRegistry instead
|
|
80
|
-
/**
|
|
81
|
-
* Call onBeforeRender hooks for all plugins
|
|
82
|
-
*/
|
|
83
|
-
async callBeforeRenderHooks(context) {
|
|
84
|
-
for (const plugin of this.plugins.values()) {
|
|
85
|
-
try {
|
|
86
|
-
await plugin.lifecycle?.onBeforeRender?.(context);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
console.error(`Plugin '${plugin.name}' onBeforeRender hook failed:`, error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Call onAfterRender hooks for all plugins
|
|
95
|
-
*/
|
|
96
|
-
async callAfterRenderHooks(context) {
|
|
97
|
-
for (const plugin of this.plugins.values()) {
|
|
98
|
-
try {
|
|
99
|
-
await plugin.lifecycle?.onAfterRender?.(context);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error(`Plugin '${plugin.name}' onAfterRender hook failed:`, error);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Validate plugin structure
|
|
108
|
-
*/
|
|
109
|
-
validatePlugin(plugin) {
|
|
110
|
-
if (!plugin.name || typeof plugin.name !== 'string') {
|
|
111
|
-
throw new Error('Plugin must have a valid name');
|
|
112
|
-
}
|
|
113
|
-
if (!plugin.version || typeof plugin.version !== 'string') {
|
|
114
|
-
throw new Error(`Plugin '${plugin.name}' must have a valid version`);
|
|
115
|
-
}
|
|
116
|
-
// Validate semantic version format (basic check)
|
|
117
|
-
if (!/^\d+\.\d+\.\d+/.test(plugin.version)) {
|
|
118
|
-
throw new Error(`Plugin '${plugin.name}' has invalid version format: ${plugin.version}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Check if plugin dependencies are satisfied
|
|
123
|
-
*/
|
|
124
|
-
async checkDependencies(plugin) {
|
|
125
|
-
if (!plugin.dependencies || plugin.dependencies.length === 0) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const missing = [];
|
|
129
|
-
for (const dep of plugin.dependencies) {
|
|
130
|
-
if (!this.plugins.has(dep)) {
|
|
131
|
-
missing.push(dep);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (missing.length > 0) {
|
|
135
|
-
throw new Error(`Plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Clear all plugins
|
|
140
|
-
*/
|
|
141
|
-
async clear() {
|
|
142
|
-
const plugins = Array.from(this.plugins.keys());
|
|
143
|
-
for (const pluginName of plugins) {
|
|
144
|
-
await this.unregister(pluginName);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//# sourceMappingURL=PluginManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,OAAO,aAAa;IAA1B;QACS,YAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;QACvC,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAuKzC,CAAC;IArKA;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAiB,EAAE,OAAsB;QACvD,kBAAkB;QAClB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAE5B,8BAA8B;QAC9B,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,CAAC,IAAI,yBAAyB,CAAC,CAAC;QAClE,CAAC;QAED,qBAAq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AU,IAAI,OAAO,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\n * Plugin Manager\n *\n * Manages plugin registration, dependency resolution, and lifecycle.\n */\n\nimport type {\n\tPluginContext,\n\tQTIPlugin,\n\tRenderContext\n} from './Plugin.js';\n\nexport class PluginManager {\n\tprivate plugins = new Map<string, QTIPlugin>();\n\tprivate initialized = new Set<string>();\n\n\t/**\n\t * Register a plugin\n\t * @throws Error if plugin is invalid or dependencies are missing\n\t */\n\tasync register(plugin: QTIPlugin, context: PluginContext): Promise<void> {\n\t\t// Validate plugin\n\t\tthis.validatePlugin(plugin);\n\n\t\t// Check if already registered\n\t\tif (this.plugins.has(plugin.name)) {\n\t\t\tthrow new Error(`Plugin '${plugin.name}' is already registered`);\n\t\t}\n\n\t\t// Check dependencies\n\t\tawait this.checkDependencies(plugin);\n\n\t\t// Store plugin\n\t\tthis.plugins.set(plugin.name, plugin);\n\n\t\t// Call lifecycle hook\n\t\ttry {\n\t\t\tawait plugin.lifecycle?.onRegister?.(context);\n\t\t\tthis.initialized.add(plugin.name);\n\t\t} catch (error) {\n\t\t\t// Rollback on error\n\t\t\tthis.plugins.delete(plugin.name);\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to initialize plugin '${plugin.name}': ${error instanceof Error ? error.message : String(error)}`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Unregister a plugin\n\t */\n\tasync unregister(pluginName: string): Promise<void> {\n\t\tconst plugin = this.plugins.get(pluginName);\n\t\tif (!plugin) return;\n\n\t\ttry {\n\t\t\t// Call lifecycle hook\n\t\t\tawait plugin.lifecycle?.onUnregister?.();\n\t\t} finally {\n\t\t\t// Remove plugin even if hook fails\n\t\t\tthis.plugins.delete(pluginName);\n\t\t\tthis.initialized.delete(pluginName);\n\t\t}\n\t}\n\n\t/**\n\t * Get all registered plugins\n\t */\n\tgetAll(): QTIPlugin[] {\n\t\treturn Array.from(this.plugins.values());\n\t}\n\n\t/**\n\t * Get plugin by name\n\t */\n\tget(name: string): QTIPlugin | undefined {\n\t\treturn this.plugins.get(name);\n\t}\n\n\t/**\n\t * Check if plugin is registered\n\t */\n\thas(name: string): boolean {\n\t\treturn this.plugins.has(name);\n\t}\n\n\t/**\n\t * Check if plugin is initialized\n\t */\n\tisInitialized(name: string): boolean {\n\t\treturn this.initialized.has(name);\n\t}\n\n\t// Legacy getRendererRegistrations() method removed\n\t// Plugins now register components via ComponentRegistry instead\n\n\t/**\n\t * Call onBeforeRender hooks for all plugins\n\t */\n\tasync callBeforeRenderHooks(context: RenderContext): Promise<void> {\n\t\tfor (const plugin of this.plugins.values()) {\n\t\t\ttry {\n\t\t\t\tawait plugin.lifecycle?.onBeforeRender?.(context);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Plugin '${plugin.name}' onBeforeRender hook failed:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Call onAfterRender hooks for all plugins\n\t */\n\tasync callAfterRenderHooks(context: RenderContext): Promise<void> {\n\t\tfor (const plugin of this.plugins.values()) {\n\t\t\ttry {\n\t\t\t\tawait plugin.lifecycle?.onAfterRender?.(context);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Plugin '${plugin.name}' onAfterRender hook failed:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Validate plugin structure\n\t */\n\tprivate validatePlugin(plugin: QTIPlugin): void {\n\t\tif (!plugin.name || typeof plugin.name !== 'string') {\n\t\t\tthrow new Error('Plugin must have a valid name');\n\t\t}\n\n\t\tif (!plugin.version || typeof plugin.version !== 'string') {\n\t\t\tthrow new Error(`Plugin '${plugin.name}' must have a valid version`);\n\t\t}\n\n\t\t// Validate semantic version format (basic check)\n\t\tif (!/^\\d+\\.\\d+\\.\\d+/.test(plugin.version)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Plugin '${plugin.name}' has invalid version format: ${plugin.version}`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if plugin dependencies are satisfied\n\t */\n\tprivate async checkDependencies(plugin: QTIPlugin): Promise<void> {\n\t\tif (!plugin.dependencies || plugin.dependencies.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst missing: string[] = [];\n\n\t\tfor (const dep of plugin.dependencies) {\n\t\t\tif (!this.plugins.has(dep)) {\n\t\t\t\tmissing.push(dep);\n\t\t\t}\n\t\t}\n\n\t\tif (missing.length > 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Clear all plugins\n\t */\n\tasync clear(): Promise<void> {\n\t\tconst plugins = Array.from(this.plugins.keys());\n\n\t\tfor (const pluginName of plugins) {\n\t\t\tawait this.unregister(pluginName);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI variable declarations management
|
|
3
|
-
* Ported from an earlier implementation
|
|
4
|
-
*/
|
|
5
|
-
import type { AreaMapping, Mapping, VariableDeclaration } from '../types/index.js';
|
|
6
|
-
/**
|
|
7
|
-
* Declarations storage for an item or section
|
|
8
|
-
*/
|
|
9
|
-
export interface DeclarationsContext {
|
|
10
|
-
declarations: Record<string, VariableDeclaration>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Initialize declarations for an element
|
|
14
|
-
*/
|
|
15
|
-
export declare function initializeDeclarations(declarations: Record<string, VariableDeclaration>): void;
|
|
16
|
-
/**
|
|
17
|
-
* Add a response or outcome declaration
|
|
18
|
-
*/
|
|
19
|
-
export declare function addDeclaration(declarations: Record<string, VariableDeclaration>, identifier: string, baseType: VariableDeclaration['baseType'], cardinality: VariableDeclaration['cardinality'], defaultValue?: any): void;
|
|
20
|
-
/**
|
|
21
|
-
* Add a mapping to a response declaration
|
|
22
|
-
*/
|
|
23
|
-
export declare function addMapping(declarations: Record<string, VariableDeclaration>, identifier: string, mapping: Mapping): void;
|
|
24
|
-
/**
|
|
25
|
-
* Add an area mapping to a response declaration
|
|
26
|
-
*/
|
|
27
|
-
export declare function addAreaMapping(declarations: Record<string, VariableDeclaration>, identifier: string, areaMapping: AreaMapping): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get a variable value from declarations
|
|
30
|
-
* @returns {any} QTI variables can hold any type
|
|
31
|
-
*/
|
|
32
|
-
export declare function getVariableValue(declarations: Record<string, VariableDeclaration>, identifier: string): any;
|
|
33
|
-
/**
|
|
34
|
-
* Set a variable value in declarations
|
|
35
|
-
*/
|
|
36
|
-
export declare function setVariableValue(declarations: Record<string, VariableDeclaration>, identifier: string, value: any): void;
|
|
37
|
-
/**
|
|
38
|
-
* Reset declarations to default values
|
|
39
|
-
*/
|
|
40
|
-
export declare function resetDeclarations(declarations: Record<string, VariableDeclaration>): void;
|
|
41
|
-
/**
|
|
42
|
-
* Clone declarations (useful for creating new sessions)
|
|
43
|
-
*/
|
|
44
|
-
export declare function cloneDeclarations(source: Record<string, VariableDeclaration>): Record<string, VariableDeclaration>;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI variable declarations management
|
|
3
|
-
* Ported from an earlier implementation
|
|
4
|
-
*/
|
|
5
|
-
import { BUILTIN_DECLARATIONS } from './constants.js';
|
|
6
|
-
/**
|
|
7
|
-
* Initialize declarations for an element
|
|
8
|
-
*/
|
|
9
|
-
export function initializeDeclarations(declarations) {
|
|
10
|
-
// Clone built-in declarations
|
|
11
|
-
Object.keys(BUILTIN_DECLARATIONS).forEach((id) => {
|
|
12
|
-
const builtinDecl = BUILTIN_DECLARATIONS[id];
|
|
13
|
-
declarations[id] = { ...builtinDecl };
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Add a response or outcome declaration
|
|
18
|
-
*/
|
|
19
|
-
export function addDeclaration(declarations, identifier, baseType, cardinality, defaultValue) {
|
|
20
|
-
const value = cardinality === 'multiple' || cardinality === 'ordered' ? [] : null;
|
|
21
|
-
declarations[identifier] = {
|
|
22
|
-
identifier,
|
|
23
|
-
baseType,
|
|
24
|
-
cardinality,
|
|
25
|
-
value: defaultValue ?? value,
|
|
26
|
-
defaultValue,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Add a mapping to a response declaration
|
|
31
|
-
*/
|
|
32
|
-
export function addMapping(declarations, identifier, mapping) {
|
|
33
|
-
const decl = declarations[identifier];
|
|
34
|
-
if (decl) {
|
|
35
|
-
decl.mapping = mapping;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Add an area mapping to a response declaration
|
|
40
|
-
*/
|
|
41
|
-
export function addAreaMapping(declarations, identifier, areaMapping) {
|
|
42
|
-
const decl = declarations[identifier];
|
|
43
|
-
if (decl) {
|
|
44
|
-
decl.areaMapping = areaMapping;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get a variable value from declarations
|
|
49
|
-
* @returns {any} QTI variables can hold any type
|
|
50
|
-
*/
|
|
51
|
-
export function getVariableValue(declarations, identifier) {
|
|
52
|
-
const decl = declarations[identifier];
|
|
53
|
-
return decl ? decl.value : null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Set a variable value in declarations
|
|
57
|
-
*/
|
|
58
|
-
export function setVariableValue(declarations, identifier, value) {
|
|
59
|
-
const decl = declarations[identifier];
|
|
60
|
-
if (decl) {
|
|
61
|
-
const coerceScalar = (v) => {
|
|
62
|
-
if (v === null || v === undefined)
|
|
63
|
-
return v;
|
|
64
|
-
const baseType = decl.baseType;
|
|
65
|
-
if (baseType === 'integer' || baseType === 'float') {
|
|
66
|
-
const n = Number(v);
|
|
67
|
-
return Number.isNaN(n) ? v : n;
|
|
68
|
-
}
|
|
69
|
-
if (baseType === 'boolean') {
|
|
70
|
-
if (typeof v === 'boolean')
|
|
71
|
-
return v;
|
|
72
|
-
if (typeof v === 'number')
|
|
73
|
-
return v !== 0;
|
|
74
|
-
if (typeof v === 'string')
|
|
75
|
-
return v.trim().toLowerCase() === 'true';
|
|
76
|
-
return Boolean(v);
|
|
77
|
-
}
|
|
78
|
-
if (baseType === 'string' ||
|
|
79
|
-
baseType === 'identifier' ||
|
|
80
|
-
baseType === 'uri' ||
|
|
81
|
-
baseType === 'pair' ||
|
|
82
|
-
baseType === 'directedPair' ||
|
|
83
|
-
baseType === 'point') {
|
|
84
|
-
return typeof v === 'string' ? v.trim() : String(v);
|
|
85
|
-
}
|
|
86
|
-
return v;
|
|
87
|
-
};
|
|
88
|
-
if (decl.cardinality === 'record') {
|
|
89
|
-
decl.value = value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
90
|
-
}
|
|
91
|
-
else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
|
|
92
|
-
if (Array.isArray(value)) {
|
|
93
|
-
decl.value = value.map(coerceScalar);
|
|
94
|
-
}
|
|
95
|
-
else if (value === null || value === undefined) {
|
|
96
|
-
decl.value = [];
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
decl.value = [coerceScalar(value)];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
decl.value = coerceScalar(value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Reset declarations to default values
|
|
109
|
-
*/
|
|
110
|
-
export function resetDeclarations(declarations) {
|
|
111
|
-
Object.values(declarations).forEach((decl) => {
|
|
112
|
-
if (decl.defaultValue !== undefined) {
|
|
113
|
-
decl.value = decl.defaultValue;
|
|
114
|
-
}
|
|
115
|
-
else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
|
|
116
|
-
decl.value = [];
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
decl.value = null;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Clone declarations (useful for creating new sessions)
|
|
125
|
-
*/
|
|
126
|
-
export function cloneDeclarations(source) {
|
|
127
|
-
const result = {};
|
|
128
|
-
Object.keys(source).forEach((id) => {
|
|
129
|
-
const decl = source[id];
|
|
130
|
-
result[id] = {
|
|
131
|
-
...decl,
|
|
132
|
-
value: (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') && Array.isArray(decl.value)
|
|
133
|
-
? [...decl.value]
|
|
134
|
-
: decl.cardinality === 'record' && decl.value && typeof decl.value === 'object'
|
|
135
|
-
? { ...decl.value }
|
|
136
|
-
: decl.value,
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
//# sourceMappingURL=declarations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../src/core/declarations.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAStD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,YAAiD;IACvF,8BAA8B;IAC9B,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAChD,MAAM,WAAW,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAC;QAC7C,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC7B,YAAiD,EACjD,UAAkB,EAClB,QAAyC,EACzC,WAA+C,EAC/C,YAAkB;IAElB,MAAM,KAAK,GAAG,WAAW,KAAK,UAAU,IAAI,WAAW,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AAC;QACxB,MAAM,CAAC,EAAE,CAAC,GAAG;YACZ,GAAG,IAAI;YACP,KAAK,EACJ,CAAC,IAAI,CAAC,WAAW,KAAK,UAAU,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC/F,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;gBACjB,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;oBAC9E,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE;oBACnB,CAAC,CAAC,IAAI,CAAC,KAAK;SACf,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * QTI variable declarations management\n * Ported from an earlier implementation\n */\n\nimport type { AreaMapping, Mapping, VariableDeclaration } from '../types/index.js';\nimport { BUILTIN_DECLARATIONS } from './constants.js';\n\n/**\n * Declarations storage for an item or section\n */\nexport interface DeclarationsContext {\n\tdeclarations: Record<string, VariableDeclaration>;\n}\n\n/**\n * Initialize declarations for an element\n */\nexport function initializeDeclarations(declarations: Record<string, VariableDeclaration>): void {\n\t// Clone built-in declarations\n\tObject.keys(BUILTIN_DECLARATIONS).forEach((id) => {\n\t\tconst builtinDecl = BUILTIN_DECLARATIONS[id];\n\t\tdeclarations[id] = { ...builtinDecl };\n\t});\n}\n\n/**\n * Add a response or outcome declaration\n */\nexport function addDeclaration(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tbaseType: VariableDeclaration['baseType'],\n\tcardinality: VariableDeclaration['cardinality'],\n\tdefaultValue?: any\n): void {\n\tconst value = cardinality === 'multiple' || cardinality === 'ordered' ? [] : null;\n\n\tdeclarations[identifier] = {\n\t\tidentifier,\n\t\tbaseType,\n\t\tcardinality,\n\t\tvalue: defaultValue ?? value,\n\t\tdefaultValue,\n\t};\n}\n\n/**\n * Add a mapping to a response declaration\n */\nexport function addMapping(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tmapping: Mapping\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tdecl.mapping = mapping;\n\t}\n}\n\n/**\n * Add an area mapping to a response declaration\n */\nexport function addAreaMapping(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tareaMapping: AreaMapping\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tdecl.areaMapping = areaMapping;\n\t}\n}\n\n/**\n * Get a variable value from declarations\n * @returns {any} QTI variables can hold any type\n */\nexport function getVariableValue(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string\n): any {\n\tconst decl = declarations[identifier];\n\treturn decl ? decl.value : null;\n}\n\n/**\n * Set a variable value in declarations\n */\nexport function setVariableValue(\n\tdeclarations: Record<string, VariableDeclaration>,\n\tidentifier: string,\n\tvalue: any\n): void {\n\tconst decl = declarations[identifier];\n\tif (decl) {\n\t\tconst coerceScalar = (v: any) => {\n\t\t\tif (v === null || v === undefined) return v;\n\t\t\tconst baseType = decl.baseType;\n\t\t\tif (baseType === 'integer' || baseType === 'float') {\n\t\t\t\tconst n = Number(v);\n\t\t\t\treturn Number.isNaN(n) ? v : n;\n\t\t\t}\n\t\t\tif (baseType === 'boolean') {\n\t\t\t\tif (typeof v === 'boolean') return v;\n\t\t\t\tif (typeof v === 'number') return v !== 0;\n\t\t\t\tif (typeof v === 'string') return v.trim().toLowerCase() === 'true';\n\t\t\t\treturn Boolean(v);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tbaseType === 'string' ||\n\t\t\t\tbaseType === 'identifier' ||\n\t\t\t\tbaseType === 'uri' ||\n\t\t\t\tbaseType === 'pair' ||\n\t\t\t\tbaseType === 'directedPair' ||\n\t\t\t\tbaseType === 'point'\n\t\t\t) {\n\t\t\t\treturn typeof v === 'string' ? v.trim() : String(v);\n\t\t\t}\n\t\t\treturn v;\n\t\t};\n\n\t\tif (decl.cardinality === 'record') {\n\t\t\tdecl.value = value && typeof value === 'object' && !Array.isArray(value) ? value : null;\n\t\t} else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tdecl.value = value.map(coerceScalar);\n\t\t\t} else if (value === null || value === undefined) {\n\t\t\t\tdecl.value = [];\n\t\t\t} else {\n\t\t\t\tdecl.value = [coerceScalar(value)];\n\t\t\t}\n\t\t} else {\n\t\t\tdecl.value = coerceScalar(value);\n\t\t}\n\t}\n}\n\n/**\n * Reset declarations to default values\n */\nexport function resetDeclarations(declarations: Record<string, VariableDeclaration>): void {\n\tObject.values(declarations).forEach((decl) => {\n\t\tif (decl.defaultValue !== undefined) {\n\t\t\tdecl.value = decl.defaultValue;\n\t\t} else if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {\n\t\t\tdecl.value = [];\n\t\t} else {\n\t\t\tdecl.value = null;\n\t\t}\n\t});\n}\n\n/**\n * Clone declarations (useful for creating new sessions)\n */\nexport function cloneDeclarations(\n\tsource: Record<string, VariableDeclaration>\n): Record<string, VariableDeclaration> {\n\tconst result: Record<string, VariableDeclaration> = {};\n\n\tObject.keys(source).forEach((id) => {\n\t\tconst decl = source[id];\n\t\tresult[id] = {\n\t\t\t...decl,\n\t\t\tvalue:\n\t\t\t\t(decl.cardinality === 'multiple' || decl.cardinality === 'ordered') && Array.isArray(decl.value)\n\t\t\t\t\t? [...decl.value]\n\t\t\t\t\t: decl.cardinality === 'record' && decl.value && typeof decl.value === 'object'\n\t\t\t\t\t\t? { ...decl.value }\n\t\t\t\t\t\t: decl.value,\n\t\t};\n\t});\n\n\treturn result;\n}\n"]}
|