@pie-qti/item-player 0.1.19 → 0.1.20
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 +9 -8
- package/dist/core/Player.js +182 -163
- package/dist/core/Player.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-CILJ4Ls7.js} +3572 -2783
- package/dist/element-class-CILJ4Ls7.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 -8
- package/dist/index.js +5 -7
- 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 +78 -34
- 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/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/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export type ServerQtiRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';
|
|
2
|
+
export type ServerQtiValue = {
|
|
3
|
+
kind: 'null';
|
|
4
|
+
baseType?: string;
|
|
5
|
+
cardinality?: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'value';
|
|
8
|
+
baseType?: string;
|
|
9
|
+
cardinality: string;
|
|
10
|
+
value: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'invalid';
|
|
13
|
+
message: string;
|
|
14
|
+
baseType?: string;
|
|
15
|
+
cardinality?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ServerItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';
|
|
18
|
+
export type ServerCompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';
|
|
19
|
+
export interface ServerSerializedVariable {
|
|
20
|
+
identifier: string;
|
|
21
|
+
kind: 'response' | 'outcome' | 'template' | 'context';
|
|
22
|
+
baseType?: string;
|
|
23
|
+
cardinality: string;
|
|
24
|
+
value: unknown;
|
|
25
|
+
defaultValue?: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface ServerResponseValidationIssue {
|
|
28
|
+
responseId: string;
|
|
29
|
+
code: string;
|
|
30
|
+
message: string;
|
|
31
|
+
severity: 'error' | 'warning';
|
|
32
|
+
}
|
|
33
|
+
export interface ServerResponseValidationEntry {
|
|
34
|
+
responseId: string;
|
|
35
|
+
interactionType: string;
|
|
36
|
+
required: boolean;
|
|
37
|
+
complete: boolean;
|
|
38
|
+
valid: boolean;
|
|
39
|
+
errors: string[];
|
|
40
|
+
warnings: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface ServerResponseValidationResult {
|
|
43
|
+
valid: boolean;
|
|
44
|
+
entries: Record<string, ServerResponseValidationEntry>;
|
|
45
|
+
issues: ServerResponseValidationIssue[];
|
|
46
|
+
}
|
|
47
|
+
export interface ServerSerializedItemSessionState {
|
|
48
|
+
itemIdentifier?: string;
|
|
49
|
+
sessionGuid: string;
|
|
50
|
+
lifecycleStatus: ServerItemLifecycleStatus;
|
|
51
|
+
completionStatus: ServerCompletionStatus;
|
|
52
|
+
numAttempts: number;
|
|
53
|
+
duration: number;
|
|
54
|
+
responseVariables: Record<string, ServerSerializedVariable>;
|
|
55
|
+
outcomeVariables: Record<string, ServerSerializedVariable>;
|
|
56
|
+
templateVariables: Record<string, ServerSerializedVariable>;
|
|
57
|
+
contextVariables: Record<string, ServerSerializedVariable>;
|
|
58
|
+
validationMessages: ServerResponseValidationIssue[];
|
|
59
|
+
savedAt: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ServerModalFeedback {
|
|
62
|
+
identifier: string;
|
|
63
|
+
outcomeIdentifier: string;
|
|
64
|
+
showHide: 'show' | 'hide';
|
|
65
|
+
content: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ServerScoringResult {
|
|
69
|
+
score: number;
|
|
70
|
+
maxScore: number;
|
|
71
|
+
completed: boolean;
|
|
72
|
+
outcomeValues: Record<string, unknown>;
|
|
73
|
+
modalFeedback?: ServerModalFeedback[];
|
|
74
|
+
}
|
|
75
|
+
/** DOM-free description of an authored processing-fragment include request. */
|
|
76
|
+
export interface ServerProcessingFragmentRequest {
|
|
77
|
+
readonly href: string;
|
|
78
|
+
readonly mode: 'template' | 'response' | 'outcome';
|
|
79
|
+
readonly scope: 'item' | 'test';
|
|
80
|
+
readonly depth: number;
|
|
81
|
+
}
|
|
82
|
+
export type ServerItemSessionActionCommand = {
|
|
83
|
+
action: 'setResponse';
|
|
84
|
+
responseIdentifier: string;
|
|
85
|
+
value: unknown;
|
|
86
|
+
} | {
|
|
87
|
+
action: 'setResponses';
|
|
88
|
+
responses: Readonly<Record<string, unknown>>;
|
|
89
|
+
} | {
|
|
90
|
+
action: 'suspendAttempt';
|
|
91
|
+
} | {
|
|
92
|
+
action: 'endAttempt';
|
|
93
|
+
countAttempt?: boolean;
|
|
94
|
+
validateResponses?: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
action: 'scoreAttempt';
|
|
97
|
+
} | {
|
|
98
|
+
action: 'newTemplate';
|
|
99
|
+
resetResponses?: boolean;
|
|
100
|
+
} | {
|
|
101
|
+
action: 'submitAttempt';
|
|
102
|
+
countAttempt?: boolean;
|
|
103
|
+
};
|
|
104
|
+
export interface ServerItemSessionActionResult {
|
|
105
|
+
action: Exclude<ServerItemSessionActionCommand, {
|
|
106
|
+
action: 'setResponse';
|
|
107
|
+
} | {
|
|
108
|
+
action: 'setResponses';
|
|
109
|
+
}>['action'];
|
|
110
|
+
lifecycleStatus: ServerItemLifecycleStatus;
|
|
111
|
+
completionStatus: ServerCompletionStatus;
|
|
112
|
+
numAttempts: number;
|
|
113
|
+
duration: number;
|
|
114
|
+
completed: boolean;
|
|
115
|
+
sessionState: ServerSerializedItemSessionState;
|
|
116
|
+
validation?: ServerResponseValidationResult;
|
|
117
|
+
scoring?: ServerScoringResult;
|
|
118
|
+
}
|
|
119
|
+
export interface ServerItemSessionView {
|
|
120
|
+
readonly revision: number;
|
|
121
|
+
readonly itemIdentifier?: string;
|
|
122
|
+
readonly role: ServerQtiRole;
|
|
123
|
+
readonly lifecycleStatus: ServerItemLifecycleStatus;
|
|
124
|
+
readonly completionStatus: ServerCompletionStatus;
|
|
125
|
+
readonly numAttempts: number;
|
|
126
|
+
readonly duration: number;
|
|
127
|
+
readonly adaptive: boolean;
|
|
128
|
+
readonly completed: boolean;
|
|
129
|
+
readonly canSubmit: boolean;
|
|
130
|
+
readonly disposed: boolean;
|
|
131
|
+
readonly responses: Readonly<Record<string, unknown>>;
|
|
132
|
+
readonly outcomes: Readonly<Record<string, unknown>>;
|
|
133
|
+
readonly templates: Readonly<Record<string, unknown>>;
|
|
134
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
135
|
+
}
|
|
136
|
+
export interface ServerItemSessionTransition {
|
|
137
|
+
readonly command: ServerItemSessionActionCommand;
|
|
138
|
+
readonly previous: ServerItemSessionView;
|
|
139
|
+
readonly current: ServerItemSessionView;
|
|
140
|
+
readonly result?: ServerItemSessionActionResult;
|
|
141
|
+
}
|
|
142
|
+
export interface ServerOpenItemSessionOptions {
|
|
143
|
+
readonly restore?: ServerSerializedItemSessionState;
|
|
144
|
+
readonly responses?: Readonly<Record<string, unknown>>;
|
|
145
|
+
readonly activate?: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface ServerItemSession {
|
|
148
|
+
state(): ServerItemSessionView;
|
|
149
|
+
dispatch(command: ServerItemSessionActionCommand): ServerItemSessionTransition;
|
|
150
|
+
serialize(): ServerSerializedItemSessionState;
|
|
151
|
+
dispose(): void;
|
|
152
|
+
}
|
|
153
|
+
export interface ServerAssessmentItemDefinition {
|
|
154
|
+
readonly identifier: string;
|
|
155
|
+
openSession(options?: ServerOpenItemSessionOptions): ServerItemSession;
|
|
156
|
+
}
|
|
157
|
+
export interface ServerAssessmentItemDefinitionConfig {
|
|
158
|
+
readonly itemXml: string;
|
|
159
|
+
readonly role?: ServerQtiRole;
|
|
160
|
+
readonly seed?: number;
|
|
161
|
+
readonly rngFactory?: () => () => number;
|
|
162
|
+
readonly customOperators?: Readonly<Record<string, (args: ServerQtiValue[], meta: {
|
|
163
|
+
class?: string;
|
|
164
|
+
definition?: string;
|
|
165
|
+
}) => ServerQtiValue>>;
|
|
166
|
+
readonly resolveProcessingFragment?: (request: ServerProcessingFragmentRequest) => string | null | undefined;
|
|
167
|
+
readonly processingFragmentLimits?: Readonly<{
|
|
168
|
+
maxDepth?: number;
|
|
169
|
+
maxCharacters?: number;
|
|
170
|
+
}>;
|
|
171
|
+
readonly security?: Readonly<{
|
|
172
|
+
parsingLimits?: Readonly<{
|
|
173
|
+
enabled?: boolean;
|
|
174
|
+
rejectDoctype?: boolean;
|
|
175
|
+
maxItemXmlBytes?: number;
|
|
176
|
+
maxHtmlBytes?: number;
|
|
177
|
+
maxHtmlNodes?: number;
|
|
178
|
+
maxHtmlDepth?: number;
|
|
179
|
+
}>;
|
|
180
|
+
}>;
|
|
181
|
+
readonly strictQtiCompliance?: Readonly<{
|
|
182
|
+
enabled?: boolean;
|
|
183
|
+
rejectUnknownExtensions?: boolean;
|
|
184
|
+
logDeviations?: boolean;
|
|
185
|
+
}>;
|
|
186
|
+
}
|
|
187
|
+
/** Compile immutable QTI source for one or more independent server item sessions. */
|
|
188
|
+
export declare function createAssessmentItemDefinition(config: ServerAssessmentItemDefinitionConfig): ServerAssessmentItemDefinition;
|
package/dist/server.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* DOM-free definition/session interface for backend scoring and persistence.
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
4
|
+
* This entrypoint deliberately mirrors the package's primary ownership model without
|
|
5
|
+
* exposing browser presentation, custom-element, PNP, PCI, or catalog capabilities.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
7
|
+
import { createAssessmentItemDefinition as createDefinitionInternal, } from './core/AssessmentItemDefinition.js';
|
|
8
|
+
/** Compile immutable QTI source for one or more independent server item sessions. */
|
|
9
|
+
export function createAssessmentItemDefinition(config) {
|
|
10
|
+
const definition = createDefinitionInternal(config);
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
identifier: definition.identifier,
|
|
13
|
+
openSession(options = {}) {
|
|
14
|
+
return new ServerItemSessionAdapter(definition.openSession(options));
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
class ServerItemSessionAdapter {
|
|
19
|
+
constructor(session) {
|
|
20
|
+
this.session = session;
|
|
21
|
+
}
|
|
22
|
+
state() {
|
|
23
|
+
return this.session.state();
|
|
24
|
+
}
|
|
25
|
+
dispatch(command) {
|
|
26
|
+
const transition = this.session.dispatch(command);
|
|
27
|
+
return transition;
|
|
28
|
+
}
|
|
29
|
+
serialize() {
|
|
30
|
+
return this.session.serialize();
|
|
31
|
+
}
|
|
32
|
+
dispose() {
|
|
33
|
+
this.session.dispose();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
11
36
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACN,8BAA8B,IAAI,wBAAwB,GAE1D,MAAM,oCAAoC,CAAC;AA+M5C,qFAAqF;AACrF,MAAM,UAAU,8BAA8B,CAC7C,MAA4C;IAE5C,MAAM,UAAU,GAAG,wBAAwB,CAAC,MAAwC,CAAC,CAAC;IACtF,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,WAAW,CAAC,UAAwC,EAAE;YACrD,OAAO,IAAI,wBAAwB,CAClC,UAAU,CAAC,WAAW,CAAC,OAAuD,CAAC,CAC/E,CAAC;QACH,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,wBAAwB;IAC7B,YAA6B,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;IAAG,CAAC;IAE7D,KAAK;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAA2B,CAAC;IACtD,CAAC;IAED,QAAQ,CAAC,OAAuC;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAqC,CAAC,CAAC;QAChF,OAAO,UAAyC,CAAC;IAClD,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAsC,CAAC;IACrE,CAAC;IAED,OAAO;QACN,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;CACD","sourcesContent":["/**\n * DOM-free definition/session interface for backend scoring and persistence.\n *\n * This entrypoint deliberately mirrors the package's primary ownership model without\n * exposing browser presentation, custom-element, PNP, PCI, or catalog capabilities.\n */\nimport {\n\tcreateAssessmentItemDefinition as createDefinitionInternal,\n\ttype AssessmentItemDefinitionConfig,\n} from './core/AssessmentItemDefinition.js';\nimport type {\n\tItemSession as InternalItemSession,\n\tItemSessionCommand as InternalItemSessionCommand,\n} from './core/ItemSession.js';\nimport type {\n\tItemSessionActionResult as InternalItemSessionActionResult,\n\tSerializedItemSessionState as InternalSerializedItemSessionState,\n} from './types/index.js';\n\nexport type ServerQtiRole =\n\t| 'candidate'\n\t| 'scorer'\n\t| 'proctor'\n\t| 'testConstructor'\n\t| 'tutor'\n\t| 'author';\n\nexport type ServerQtiValue =\n\t| { kind: 'null'; baseType?: string; cardinality?: string }\n\t| { kind: 'value'; baseType?: string; cardinality: string; value: unknown }\n\t| { kind: 'invalid'; message: string; baseType?: string; cardinality?: string };\n\nexport type ServerItemLifecycleStatus =\n\t| 'initial'\n\t| 'interacting'\n\t| 'suspended'\n\t| 'closed'\n\t| 'review'\n\t| 'solution'\n\t| 'answer';\n\nexport type ServerCompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';\n\nexport interface ServerSerializedVariable {\n\tidentifier: string;\n\tkind: 'response' | 'outcome' | 'template' | 'context';\n\tbaseType?: string;\n\tcardinality: string;\n\tvalue: unknown;\n\tdefaultValue?: unknown;\n}\n\nexport interface ServerResponseValidationIssue {\n\tresponseId: string;\n\tcode: string;\n\tmessage: string;\n\tseverity: 'error' | 'warning';\n}\n\nexport interface ServerResponseValidationEntry {\n\tresponseId: string;\n\tinteractionType: string;\n\trequired: boolean;\n\tcomplete: boolean;\n\tvalid: boolean;\n\terrors: string[];\n\twarnings: string[];\n}\n\nexport interface ServerResponseValidationResult {\n\tvalid: boolean;\n\tentries: Record<string, ServerResponseValidationEntry>;\n\tissues: ServerResponseValidationIssue[];\n}\n\nexport interface ServerSerializedItemSessionState {\n\titemIdentifier?: string;\n\tsessionGuid: string;\n\tlifecycleStatus: ServerItemLifecycleStatus;\n\tcompletionStatus: ServerCompletionStatus;\n\tnumAttempts: number;\n\tduration: number;\n\tresponseVariables: Record<string, ServerSerializedVariable>;\n\toutcomeVariables: Record<string, ServerSerializedVariable>;\n\ttemplateVariables: Record<string, ServerSerializedVariable>;\n\tcontextVariables: Record<string, ServerSerializedVariable>;\n\tvalidationMessages: ServerResponseValidationIssue[];\n\tsavedAt: string;\n}\n\nexport interface ServerModalFeedback {\n\tidentifier: string;\n\toutcomeIdentifier: string;\n\tshowHide: 'show' | 'hide';\n\tcontent: string;\n\ttitle?: string;\n}\n\nexport interface ServerScoringResult {\n\tscore: number;\n\tmaxScore: number;\n\tcompleted: boolean;\n\toutcomeValues: Record<string, unknown>;\n\tmodalFeedback?: ServerModalFeedback[];\n}\n\n/** DOM-free description of an authored processing-fragment include request. */\nexport interface ServerProcessingFragmentRequest {\n\treadonly href: string;\n\treadonly mode: 'template' | 'response' | 'outcome';\n\treadonly scope: 'item' | 'test';\n\treadonly depth: number;\n}\n\nexport type ServerItemSessionActionCommand =\n\t| { action: 'setResponse'; responseIdentifier: string; value: unknown }\n\t| { action: 'setResponses'; responses: Readonly<Record<string, unknown>> }\n\t| { action: 'suspendAttempt' }\n\t| { action: 'endAttempt'; countAttempt?: boolean; validateResponses?: boolean }\n\t| { action: 'scoreAttempt' }\n\t| { action: 'newTemplate'; resetResponses?: boolean }\n\t| { action: 'submitAttempt'; countAttempt?: boolean };\n\nexport interface ServerItemSessionActionResult {\n\taction: Exclude<\n\t\tServerItemSessionActionCommand,\n\t\t{ action: 'setResponse' } | { action: 'setResponses' }\n\t>['action'];\n\tlifecycleStatus: ServerItemLifecycleStatus;\n\tcompletionStatus: ServerCompletionStatus;\n\tnumAttempts: number;\n\tduration: number;\n\tcompleted: boolean;\n\tsessionState: ServerSerializedItemSessionState;\n\tvalidation?: ServerResponseValidationResult;\n\tscoring?: ServerScoringResult;\n}\n\nexport interface ServerItemSessionView {\n\treadonly revision: number;\n\treadonly itemIdentifier?: string;\n\treadonly role: ServerQtiRole;\n\treadonly lifecycleStatus: ServerItemLifecycleStatus;\n\treadonly completionStatus: ServerCompletionStatus;\n\treadonly numAttempts: number;\n\treadonly duration: number;\n\treadonly adaptive: boolean;\n\treadonly completed: boolean;\n\treadonly canSubmit: boolean;\n\treadonly disposed: boolean;\n\treadonly responses: Readonly<Record<string, unknown>>;\n\treadonly outcomes: Readonly<Record<string, unknown>>;\n\treadonly templates: Readonly<Record<string, unknown>>;\n\treadonly context: Readonly<Record<string, unknown>>;\n}\n\nexport interface ServerItemSessionTransition {\n\treadonly command: ServerItemSessionActionCommand;\n\treadonly previous: ServerItemSessionView;\n\treadonly current: ServerItemSessionView;\n\treadonly result?: ServerItemSessionActionResult;\n}\n\nexport interface ServerOpenItemSessionOptions {\n\treadonly restore?: ServerSerializedItemSessionState;\n\treadonly responses?: Readonly<Record<string, unknown>>;\n\treadonly activate?: boolean;\n}\n\nexport interface ServerItemSession {\n\tstate(): ServerItemSessionView;\n\tdispatch(command: ServerItemSessionActionCommand): ServerItemSessionTransition;\n\tserialize(): ServerSerializedItemSessionState;\n\tdispose(): void;\n}\n\nexport interface ServerAssessmentItemDefinition {\n\treadonly identifier: string;\n\topenSession(options?: ServerOpenItemSessionOptions): ServerItemSession;\n}\n\nexport interface ServerAssessmentItemDefinitionConfig {\n\treadonly itemXml: string;\n\treadonly role?: ServerQtiRole;\n\treadonly seed?: number;\n\treadonly rngFactory?: () => () => number;\n\treadonly customOperators?: Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t(args: ServerQtiValue[], meta: { class?: string; definition?: string }) => ServerQtiValue\n\t\t>\n\t>;\n\treadonly resolveProcessingFragment?: (\n\t\trequest: ServerProcessingFragmentRequest,\n\t) => string | null | undefined;\n\treadonly processingFragmentLimits?: Readonly<{\n\t\tmaxDepth?: number;\n\t\tmaxCharacters?: number;\n\t}>;\n\treadonly security?: Readonly<{\n\t\tparsingLimits?: Readonly<{\n\t\t\tenabled?: boolean;\n\t\t\trejectDoctype?: boolean;\n\t\t\tmaxItemXmlBytes?: number;\n\t\t\tmaxHtmlBytes?: number;\n\t\t\tmaxHtmlNodes?: number;\n\t\t\tmaxHtmlDepth?: number;\n\t\t}>;\n\t}>;\n\treadonly strictQtiCompliance?: Readonly<{\n\t\tenabled?: boolean;\n\t\trejectUnknownExtensions?: boolean;\n\t\tlogDeviations?: boolean;\n\t}>;\n}\n\n/** Compile immutable QTI source for one or more independent server item sessions. */\nexport function createAssessmentItemDefinition(\n\tconfig: ServerAssessmentItemDefinitionConfig,\n): ServerAssessmentItemDefinition {\n\tconst definition = createDefinitionInternal(config as AssessmentItemDefinitionConfig);\n\treturn Object.freeze({\n\t\tidentifier: definition.identifier,\n\t\topenSession(options: ServerOpenItemSessionOptions = {}) {\n\t\t\treturn new ServerItemSessionAdapter(\n\t\t\t\tdefinition.openSession(options as Parameters<typeof definition.openSession>[0]),\n\t\t\t);\n\t\t},\n\t});\n}\n\nclass ServerItemSessionAdapter implements ServerItemSession {\n\tconstructor(private readonly session: InternalItemSession) {}\n\n\tstate(): ServerItemSessionView {\n\t\treturn this.session.state() as ServerItemSessionView;\n\t}\n\n\tdispatch(command: ServerItemSessionActionCommand): ServerItemSessionTransition {\n\t\tconst transition = this.session.dispatch(command as InternalItemSessionCommand);\n\t\treturn transition as ServerItemSessionTransition;\n\t}\n\n\tserialize(): ServerSerializedItemSessionState {\n\t\treturn this.session.serialize() as ServerSerializedItemSessionState;\n\t}\n\n\tdispose(): void {\n\t\tthis.session.dispose();\n\t}\n}\n\n// Keep the internal result relation checked without exporting DOM-bearing engine types.\ntype _ServerResultCompatibility = InternalItemSessionActionResult extends ServerItemSessionActionResult\n\t? true\n\t: never;\ntype _ServerStateCompatibility = InternalSerializedItemSessionState extends ServerSerializedItemSessionState\n\t? true\n\t: never;\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core QTI types for the player
|
|
3
3
|
*/
|
|
4
|
-
import type { BaseType as ProcessingBaseType, Cardinality as ProcessingCardinality
|
|
5
|
-
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
6
|
-
import type { PciConfiguration } from '../pci/types.js';
|
|
4
|
+
import type { BaseType as ProcessingBaseType, Cardinality as ProcessingCardinality } from '@pie-qti/qti-processing';
|
|
7
5
|
import type { ResponseValidationResult } from './responseValidation.js';
|
|
8
6
|
/**
|
|
9
7
|
* QTI base type identifier
|
|
@@ -63,9 +61,6 @@ export interface OutcomeDeclaration extends VariableDeclaration {
|
|
|
63
61
|
masteryValue?: number;
|
|
64
62
|
views?: string[];
|
|
65
63
|
}
|
|
66
|
-
export interface ItemSessionState {
|
|
67
|
-
[variableId: string]: any;
|
|
68
|
-
}
|
|
69
64
|
export type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';
|
|
70
65
|
export type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';
|
|
71
66
|
export interface SerializedItemSessionVariable {
|
|
@@ -121,9 +116,6 @@ export interface ItemSessionActionResult {
|
|
|
121
116
|
validation?: ResponseValidationResult;
|
|
122
117
|
scoring?: ScoringResult;
|
|
123
118
|
}
|
|
124
|
-
export interface InteractionResponse {
|
|
125
|
-
[responseId: string]: any;
|
|
126
|
-
}
|
|
127
119
|
/**
|
|
128
120
|
* Serializable representation of a QTI baseType="file" response.
|
|
129
121
|
* (We cannot store a browser File object in session state / JSON exports.)
|
|
@@ -192,13 +184,6 @@ export interface AdaptiveAttemptResult extends ScoringResult {
|
|
|
192
184
|
*/
|
|
193
185
|
export type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';
|
|
194
186
|
export type RubricBlockScope = 'direct' | 'itemBody';
|
|
195
|
-
export interface RubricBlockOptions {
|
|
196
|
-
/**
|
|
197
|
-
* `direct` rubrics are assessment-item children and are intended for host placement.
|
|
198
|
-
* `itemBody` rubrics are authored in the visible item body flow.
|
|
199
|
-
*/
|
|
200
|
-
scope?: RubricBlockScope | 'all';
|
|
201
|
-
}
|
|
202
187
|
export interface RubricBlock {
|
|
203
188
|
view: string[];
|
|
204
189
|
html: HtmlContent;
|
|
@@ -217,99 +202,6 @@ export interface QTIComplianceConfig {
|
|
|
217
202
|
/** Log warnings for spec deviations and vendor extensions. Default: true */
|
|
218
203
|
logDeviations?: boolean;
|
|
219
204
|
}
|
|
220
|
-
export interface PlayerConfig {
|
|
221
|
-
itemXml?: string;
|
|
222
|
-
/**
|
|
223
|
-
* QTI 3.0 §6.2 Personal Needs and Preferences profile.
|
|
224
|
-
* Color scheme is applied immediately as data-qti-colorscheme on the player root.
|
|
225
|
-
* Use player.updatePnp() to change mid-session without re-parsing the item.
|
|
226
|
-
*/
|
|
227
|
-
pnp?: import('../pnp/types.js').PnpProfile;
|
|
228
|
-
/**
|
|
229
|
-
* Optional shared catalog XML string (QTI 3.0 §6.3).
|
|
230
|
-
* Parsed and merged with any catalog embedded in the item XML.
|
|
231
|
-
* Item-level catalog entries take precedence over shared entries with the same identifier.
|
|
232
|
-
* Deferred: external catalog files from IMS manifest (G-15) are not yet supported.
|
|
233
|
-
*/
|
|
234
|
-
catalogXml?: string;
|
|
235
|
-
/**
|
|
236
|
-
* Optional resolved delivery context produced by IMS package/assessment layers.
|
|
237
|
-
* This is additive to catalogXml: shared catalog sources are merged first, then
|
|
238
|
-
* catalogXml, then item-embedded catalog entries so item-local entries win.
|
|
239
|
-
*/
|
|
240
|
-
deliveryContext?: ResolvedItemDeliveryContext;
|
|
241
|
-
sessionState?: ItemSessionState;
|
|
242
|
-
responses?: InteractionResponse;
|
|
243
|
-
role?: QTIRole;
|
|
244
|
-
/** Optional seed for deterministic random operations (e.g. templateProcessing randomInteger) */
|
|
245
|
-
seed?: number;
|
|
246
|
-
/** Optional RNG override (takes precedence over seed if provided) */
|
|
247
|
-
rng?: () => number;
|
|
248
|
-
/**
|
|
249
|
-
* Optional element name mapper for handling different QTI versions.
|
|
250
|
-
* Defaults to Qti2xElementNameMapper (primary supported QTI format).
|
|
251
|
-
* @since 0.2.0
|
|
252
|
-
*/
|
|
253
|
-
elementNameMapper?: any;
|
|
254
|
-
/**
|
|
255
|
-
* Optional attribute name mapper for handling different QTI versions.
|
|
256
|
-
* Defaults to Qti2xAttributeNameMapper (primary supported QTI format).
|
|
257
|
-
* @since 0.3.0
|
|
258
|
-
*/
|
|
259
|
-
attributeNameMapper?: any;
|
|
260
|
-
/** Optional web component registry for custom interaction components */
|
|
261
|
-
componentRegistry?: any;
|
|
262
|
-
/** Optional extraction registry for custom element extractors */
|
|
263
|
-
extractionRegistry?: any;
|
|
264
|
-
/** Optional plugins to extend player functionality */
|
|
265
|
-
plugins?: any[];
|
|
266
|
-
/**
|
|
267
|
-
* Optional i18n provider for internationalization.
|
|
268
|
-
* If not provided, defaults to DefaultI18nProvider with English messages.
|
|
269
|
-
*/
|
|
270
|
-
i18nProvider?: any;
|
|
271
|
-
/**
|
|
272
|
-
* Optional registry for executing QTI <customOperator> expressions.
|
|
273
|
-
* Keyed by operator `class` (preferred) or `definition` URI.
|
|
274
|
-
*/
|
|
275
|
-
customOperators?: Record<string, (args: QtiValue[], meta: {
|
|
276
|
-
class?: string;
|
|
277
|
-
definition?: string;
|
|
278
|
-
}) => QtiValue>;
|
|
279
|
-
/**
|
|
280
|
-
* Host-controlled resolver for xi:include processing fragments.
|
|
281
|
-
* The player never fetches an authored href directly; package hosts must resolve
|
|
282
|
-
* and containment-check it, then return XML synchronously.
|
|
283
|
-
*/
|
|
284
|
-
resolveProcessingFragment?: ProcessingFragmentResolver;
|
|
285
|
-
/** Resource limits applied cumulatively while compiling external processing fragments. */
|
|
286
|
-
processingFragmentLimits?: {
|
|
287
|
-
/** Maximum nested xi:include depth. Default: 16. */
|
|
288
|
-
maxDepth?: number;
|
|
289
|
-
/** Maximum cumulative XML characters. Default: 2 MiB. */
|
|
290
|
-
maxCharacters?: number;
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* Portable Custom Interaction runtime configuration.
|
|
294
|
-
* A moduleResolver is required before any authored PCI code can execute.
|
|
295
|
-
*/
|
|
296
|
-
pci?: PciConfiguration;
|
|
297
|
-
/**
|
|
298
|
-
* @deprecated Use pci.baseUrl. Retained as a resolution-only compatibility alias;
|
|
299
|
-
* it never enables module loading without pci.moduleResolver.
|
|
300
|
-
*/
|
|
301
|
-
pciBaseUrl?: string;
|
|
302
|
-
/**
|
|
303
|
-
* Security-related controls for untrusted QTI rendered into the host DOM.
|
|
304
|
-
* Defaults are conservative for same-DOM embedding.
|
|
305
|
-
*/
|
|
306
|
-
security?: PlayerSecurityConfig;
|
|
307
|
-
/**
|
|
308
|
-
* QTI specification compliance settings.
|
|
309
|
-
* Set strictQtiCompliance.enabled = true for strict QTI 2.2 validation.
|
|
310
|
-
*/
|
|
311
|
-
strictQtiCompliance?: QTIComplianceConfig;
|
|
312
|
-
}
|
|
313
205
|
export interface UrlPolicyConfig {
|
|
314
206
|
/**
|
|
315
207
|
* Optional base URL used to resolve relative asset URLs (e.g. images/media).
|
|
@@ -396,5 +288,4 @@ export interface InteractionContext {
|
|
|
396
288
|
shuffle?: boolean;
|
|
397
289
|
orientation?: 'horizontal' | 'vertical';
|
|
398
290
|
}
|
|
399
|
-
export type * from '../interactions/index.js';
|
|
400
291
|
export * from './responseValidation.js';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmbH,cAAc,yBAAyB,CAAC","sourcesContent":["/**\n * Core QTI types for the player\n */\n\nimport type {\n\tBaseType as ProcessingBaseType,\n\tCardinality as ProcessingCardinality,\n\tProcessingFragmentResolver,\n\tQtiValue,\n} from '@pie-qti/qti-processing';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { ResponseValidationResult } from './responseValidation.js';\n\n/**\n * QTI base type identifier\n * Extensible string type allows custom base types\n */\nexport type VariableBaseType = ProcessingBaseType;\n\n/**\n * QTI cardinality identifier\n * Extensible string type allows custom cardinality values\n */\nexport type VariableCardinality = ProcessingCardinality;\n\nexport interface VariableDeclaration {\n\tidentifier: string;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n\tmapping?: Mapping;\n\tareaMapping?: AreaMapping;\n}\n\nexport interface Mapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\t/**\n\t * QTI attribute on <mapping>. When \"false\", string mappings are case-insensitive by default.\n\t * Stored as raw string to match XML attribute values (\"true\"/\"false\").\n\t */\n\tcaseSensitive?: string;\n\tentries: Record<string, MapEntry>;\n}\n\nexport interface MapEntry {\n\tmapKey: string;\n\tmappedValue: number;\n\tcaseSensitive?: string;\n}\n\nexport interface AreaMapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\tentries: AreaMapEntry[];\n}\n\nexport interface AreaMapEntry {\n\tshape: 'circle' | 'rect' | 'poly' | 'ellipse' | 'default';\n\tcoords: string;\n\tmappedValue: number;\n}\n\nexport interface ResponseDeclaration extends VariableDeclaration {\n\tcorrectResponse?: any;\n}\n\nexport interface OutcomeDeclaration extends VariableDeclaration {\n\tinterpretation?: string;\n\tlongInterpretation?: string;\n\tnormalMaximum?: number;\n\tnormalMinimum?: number;\n\tmasteryValue?: number;\n\tviews?: string[];\n}\n\nexport interface ItemSessionState {\n\t[variableId: string]: any;\n}\n\nexport type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';\n\nexport type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';\n\nexport interface SerializedItemSessionVariable {\n\tidentifier: string;\n\tkind: SerializedVariableKind;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n}\n\nexport interface SerializedItemSessionState {\n\titemIdentifier?: string;\n\tsessionGuid: string;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\t/**\n\t * Time-on-task in milliseconds, stored as the QTI built-in duration variable value.\n\t */\n\tduration: number;\n\tresponseVariables: Record<string, SerializedItemSessionVariable>;\n\toutcomeVariables: Record<string, SerializedItemSessionVariable>;\n\ttemplateVariables: Record<string, SerializedItemSessionVariable>;\n\tcontextVariables: Record<string, SerializedItemSessionVariable>;\n\tvalidationMessages: ResponseValidationResult['issues'];\n\tsavedAt: string;\n}\n\nexport type ItemSessionAction =\n\t| 'suspendAttempt'\n\t| 'endAttempt'\n\t| 'scoreAttempt'\n\t| 'newTemplate'\n\t| 'submitAttempt';\n\nexport type ItemSessionActionCommand =\n\t| { action: 'suspendAttempt' }\n\t| { action: 'endAttempt'; countAttempt?: boolean; validateResponses?: boolean }\n\t| { action: 'scoreAttempt' }\n\t| { action: 'newTemplate'; resetResponses?: boolean }\n\t| { action: 'submitAttempt'; countAttempt?: boolean };\n\nexport interface ItemSessionActionResult {\n\taction: ItemSessionAction;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\tduration: number;\n\tcompleted: boolean;\n\tsessionState: SerializedItemSessionState;\n\tvalidation?: ResponseValidationResult;\n\tscoring?: ScoringResult;\n}\n\nexport interface InteractionResponse {\n\t[responseId: string]: any;\n}\n\n/**\n * Serializable representation of a QTI baseType=\"file\" response.\n * (We cannot store a browser File object in session state / JSON exports.)\n */\nexport interface QTIFileResponse {\n\tname: string;\n\ttype: string;\n\tsize: number;\n\tlastModified: number;\n\t/** Base64 data URL, e.g. data:application/pdf;base64,... */\n\tdataUrl: string;\n\t/**\n\t * Optional ImageData extracted from canvas (for drawing interactions).\n\t * This allows custom operators to analyze drawing content synchronously\n\t * without needing to decode the dataUrl asynchronously.\n\t */\n\timageData?: {\n\t\tdata: Uint8ClampedArray;\n\t\twidth: number;\n\t\theight: number;\n\t};\n}\n\nexport interface ModalFeedback {\n\t/** Unique identifier for this feedback block */\n\tidentifier: string;\n\t/** Outcome variable identifier this feedback is tied to */\n\toutcomeIdentifier: string;\n\t/** When to show: 'show' means display when outcome matches identifier */\n\tshowHide: 'show' | 'hide';\n\t/** HTML content to display */\n\tcontent: HtmlContent;\n\t/** Optional title for the feedback */\n\ttitle?: string;\n}\n\nexport interface ScoringResult {\n\tscore: number;\n\tmaxScore: number;\n\tcompleted: boolean;\n\toutcomeValues: Record<string, any>;\n\t/** Modal feedback elements that should be displayed based on outcome values */\n\tmodalFeedback?: ModalFeedback[];\n}\n\n/**\n * QTI 2.2 completionStatus values for adaptive items\n * - not_attempted: No interaction has occurred yet\n * - unknown: Response exists but hasn't been scored/evaluated\n * - incomplete: Item has been scored but is still active (can submit again)\n * - completed: Item is finished (final state)\n */\nexport type CompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';\n\n/**\n * Extended scoring result for adaptive items with multi-attempt support\n */\nexport interface AdaptiveAttemptResult extends ScoringResult {\n\t/** Number of attempts made so far */\n\tnumAttempts: number;\n\t/** Current completion status of the item */\n\tcompletionStatus: CompletionStatus;\n\t/** Whether the item can accept more submissions */\n\tcanContinue: boolean;\n}\n\n/**\n * QTI role/view actors used for audience filtering (for example rubric/outcome visibility).\n * Runtime interaction behavior (readonly vs editable, correct-answer visibility) is a player\n * policy layered on top of these roles.\n */\nexport type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';\n\nexport type RubricBlockScope = 'direct' | 'itemBody';\n\nexport interface RubricBlockOptions {\n\t/**\n\t * `direct` rubrics are assessment-item children and are intended for host placement.\n\t * `itemBody` rubrics are authored in the visible item body flow.\n\t */\n\tscope?: RubricBlockScope | 'all';\n}\n\nexport interface RubricBlock {\n\tview: string[]; // Array of role strings that can see this rubric\n\thtml: HtmlContent; // HTML content of the rubric\n\tscope: RubricBlockScope;\n\tuse?: string;\n}\n\n/**\n * QTI specification compliance configuration.\n * Controls whether the player enforces strict QTI 2.2 spec or allows vendor extensions.\n */\nexport interface QTIComplianceConfig {\n\t/** Enable strict QTI 2.2 compliance mode. Default: false (lenient) */\n\tenabled?: boolean;\n\n\t/** Reject items with unknown or non-standard elements. Default: false */\n\trejectUnknownExtensions?: boolean;\n\n\t/** Log warnings for spec deviations and vendor extensions. Default: true */\n\tlogDeviations?: boolean;\n}\n\nexport interface PlayerConfig {\n\titemXml?: string;\n\t/**\n\t * QTI 3.0 §6.2 Personal Needs and Preferences profile.\n\t * Color scheme is applied immediately as data-qti-colorscheme on the player root.\n\t * Use player.updatePnp() to change mid-session without re-parsing the item.\n\t */\n\tpnp?: import('../pnp/types.js').PnpProfile;\n\t/**\n\t * Optional shared catalog XML string (QTI 3.0 §6.3).\n\t * Parsed and merged with any catalog embedded in the item XML.\n\t * Item-level catalog entries take precedence over shared entries with the same identifier.\n\t * Deferred: external catalog files from IMS manifest (G-15) are not yet supported.\n\t */\n\tcatalogXml?: string;\n\t/**\n\t * Optional resolved delivery context produced by IMS package/assessment layers.\n\t * This is additive to catalogXml: shared catalog sources are merged first, then\n\t * catalogXml, then item-embedded catalog entries so item-local entries win.\n\t */\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\tsessionState?: ItemSessionState;\n\tresponses?: InteractionResponse;\n\trole?: QTIRole;\n\t/** Optional seed for deterministic random operations (e.g. templateProcessing randomInteger) */\n\tseed?: number;\n\t/** Optional RNG override (takes precedence over seed if provided) */\n\trng?: () => number;\n\t/**\n\t * Optional element name mapper for handling different QTI versions.\n\t * Defaults to Qti2xElementNameMapper (primary supported QTI format).\n\t * @since 0.2.0\n\t */\n\telementNameMapper?: any; // Will be ElementNameMapper from @pie-qti/qti-common\n\t/**\n\t * Optional attribute name mapper for handling different QTI versions.\n\t * Defaults to Qti2xAttributeNameMapper (primary supported QTI format).\n\t * @since 0.3.0\n\t */\n\tattributeNameMapper?: any; // Will be AttributeNameMapper from @pie-qti/qti-common\n\t/** Optional web component registry for custom interaction components */\n\tcomponentRegistry?: any; // Will be ComponentRegistry, but avoiding circular dependency\n\t/** Optional extraction registry for custom element extractors */\n\textractionRegistry?: any; // Will be ExtractionRegistry, but avoiding circular dependency\n\t/** Optional plugins to extend player functionality */\n\tplugins?: any[]; // Will be QTIPlugin[], but avoiding circular dependency\n\t/**\n\t * Optional i18n provider for internationalization.\n\t * If not provided, defaults to DefaultI18nProvider with English messages.\n\t */\n\ti18nProvider?: any; // Will be I18nProvider from @pie-qti/i18n\n\t/**\n\t * Optional registry for executing QTI <customOperator> expressions.\n\t * Keyed by operator `class` (preferred) or `definition` URI.\n\t */\n\tcustomOperators?: Record<string, (args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue>;\n\t/**\n\t * Host-controlled resolver for xi:include processing fragments.\n\t * The player never fetches an authored href directly; package hosts must resolve\n\t * and containment-check it, then return XML synchronously.\n\t */\n\tresolveProcessingFragment?: ProcessingFragmentResolver;\n\t/** Resource limits applied cumulatively while compiling external processing fragments. */\n\tprocessingFragmentLimits?: {\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t};\n\t/**\n\t * Portable Custom Interaction runtime configuration.\n\t * A moduleResolver is required before any authored PCI code can execute.\n\t */\n\tpci?: PciConfiguration;\n\t/**\n\t * @deprecated Use pci.baseUrl. Retained as a resolution-only compatibility alias;\n\t * it never enables module loading without pci.moduleResolver.\n\t */\n\tpciBaseUrl?: string;\n\n\t/**\n\t * Security-related controls for untrusted QTI rendered into the host DOM.\n\t * Defaults are conservative for same-DOM embedding.\n\t */\n\tsecurity?: PlayerSecurityConfig;\n\n\t/**\n\t * QTI specification compliance settings.\n\t * Set strictQtiCompliance.enabled = true for strict QTI 2.2 validation.\n\t */\n\tstrictQtiCompliance?: QTIComplianceConfig;\n}\n\nexport interface UrlPolicyConfig {\n\t/**\n\t * Optional base URL used to resolve relative asset URLs (e.g. images/media).\n\t * If omitted, relative URLs are preserved as-is.\n\t */\n\tassetBaseUrl?: string;\n\t/** Allow https: URLs */\n\tallowHttps?: boolean;\n\t/** Allow http: URLs (default false; prefer https) */\n\tallowHttp?: boolean;\n\t/** Allow protocol-relative URLs (e.g. //cdn.example/asset). Default false. */\n\tallowProtocolRelative?: boolean;\n\t/** Allow data:image/* for <img src>. */\n\tallowDataImages?: boolean;\n\t/** Allow data:image/svg+xml (default false) */\n\tallowSvgDataImages?: boolean;\n\t/** Allow blob: URLs for package-resolved images (default false). */\n\tallowBlobImages?: boolean;\n\t/** Allow blob: URLs for package-resolved audio/video media (default false). */\n\tallowBlobMedia?: boolean;\n\t/** Optional allowlist of hostnames for absolute URLs (exact match). */\n\tallowedHosts?: string[];\n}\n\n/**\n * Trusted Types support:\n * - When enabled and supported by the host browser + CSP, HTML-returning APIs may return TrustedHTML instead of string.\n * - When not enabled (default), APIs return plain strings as before.\n */\nexport type TrustedTypesHtml = typeof globalThis extends { TrustedHTML: infer T } ? T : never;\nexport type HtmlContent = string | TrustedTypesHtml;\n\nexport interface PlayerSecurityConfig {\n\t/** URL policy applied to extracted URL fields and HTML attribute URLs */\n\turlPolicy?: UrlPolicyConfig;\n\t/** Allow <object>/<embed> usage (default false) */\n\tallowObjectEmbeds?: boolean;\n\t/** Allow <iframe> usage (default false) */\n\tallowIframes?: boolean;\n\t/**\n\t * Optional parsing/processing guardrails to reduce DoS risk from untrusted QTI.\n\t * Disabled by default for compatibility.\n\t */\n\tparsingLimits?: ParsingLimitsConfig;\n\t/**\n\t * Optional Trusted Types policy name (host-controlled).\n\t * When set, and Trusted Types is available, the player will produce TrustedHTML for HTML injection sinks.\n\t *\n\t * Note: this is only effective when the host enables Trusted Types via CSP.\n\t */\n\ttrustedTypesPolicyName?: string;\n}\n\nexport interface ParsingLimitsConfig {\n\t/**\n\t * Enables parsing limits. When false/undefined, the player behaves exactly as before (compat default).\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Reject any XML containing <!DOCTYPE ...> (case-insensitive) when enabled.\n\t * Helps reduce entity-expansion and other parser edge-case risks.\n\t */\n\trejectDoctype?: boolean;\n\t/**\n\t * Maximum bytes for `itemXml` input (UTF-8). Enforced when enabled.\n\t */\n\tmaxItemXmlBytes?: number;\n\t/**\n\t * Maximum bytes for HTML strings passed to sanitizer (UTF-8). Enforced when enabled.\n\t */\n\tmaxHtmlBytes?: number;\n\t/**\n\t * Maximum number of element nodes sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlNodes?: number;\n\t/**\n\t * Maximum element depth sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlDepth?: number;\n}\n\nexport interface InteractionContext {\n\tresponseIdentifier: string;\n\tmaxChoices?: number;\n\tminChoices?: number;\n\tshuffle?: boolean;\n\torientation?: 'horizontal' | 'vertical';\n}\n\n// Interaction data shapes for the component/plugin system.\n// Exported here so consumers can import them from `@pie-qti/item-player`.\nexport type * from '../interactions/index.js';\nexport * from './responseValidation.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0aH,cAAc,yBAAyB,CAAC","sourcesContent":["/**\n * Core QTI types for the player\n */\n\nimport type {\n\tBaseType as ProcessingBaseType,\n\tCardinality as ProcessingCardinality,\n\tProcessingFragmentResolver,\n\tQtiValue,\n} from '@pie-qti/qti-processing';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { ResponseValidationResult } from './responseValidation.js';\n\n/**\n * QTI base type identifier\n * Extensible string type allows custom base types\n */\nexport type VariableBaseType = ProcessingBaseType;\n\n/**\n * QTI cardinality identifier\n * Extensible string type allows custom cardinality values\n */\nexport type VariableCardinality = ProcessingCardinality;\n\nexport interface VariableDeclaration {\n\tidentifier: string;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n\tmapping?: Mapping;\n\tareaMapping?: AreaMapping;\n}\n\nexport interface Mapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\t/**\n\t * QTI attribute on <mapping>. When \"false\", string mappings are case-insensitive by default.\n\t * Stored as raw string to match XML attribute values (\"true\"/\"false\").\n\t */\n\tcaseSensitive?: string;\n\tentries: Record<string, MapEntry>;\n}\n\nexport interface MapEntry {\n\tmapKey: string;\n\tmappedValue: number;\n\tcaseSensitive?: string;\n}\n\nexport interface AreaMapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\tentries: AreaMapEntry[];\n}\n\nexport interface AreaMapEntry {\n\tshape: 'circle' | 'rect' | 'poly' | 'ellipse' | 'default';\n\tcoords: string;\n\tmappedValue: number;\n}\n\nexport interface ResponseDeclaration extends VariableDeclaration {\n\tcorrectResponse?: any;\n}\n\nexport interface OutcomeDeclaration extends VariableDeclaration {\n\tinterpretation?: string;\n\tlongInterpretation?: string;\n\tnormalMaximum?: number;\n\tnormalMinimum?: number;\n\tmasteryValue?: number;\n\tviews?: string[];\n}\n\n/** @internal Private engine snapshot shape; use SerializedItemSessionState. */\nexport interface ItemSessionState {\n\t[variableId: string]: any;\n}\n\nexport type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';\n\nexport type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';\n\nexport interface SerializedItemSessionVariable {\n\tidentifier: string;\n\tkind: SerializedVariableKind;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n}\n\nexport interface SerializedItemSessionState {\n\titemIdentifier?: string;\n\tsessionGuid: string;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\t/**\n\t * Time-on-task in milliseconds, stored as the QTI built-in duration variable value.\n\t */\n\tduration: number;\n\tresponseVariables: Record<string, SerializedItemSessionVariable>;\n\toutcomeVariables: Record<string, SerializedItemSessionVariable>;\n\ttemplateVariables: Record<string, SerializedItemSessionVariable>;\n\tcontextVariables: Record<string, SerializedItemSessionVariable>;\n\tvalidationMessages: ResponseValidationResult['issues'];\n\tsavedAt: string;\n}\n\nexport type ItemSessionAction =\n\t| 'suspendAttempt'\n\t| 'endAttempt'\n\t| 'scoreAttempt'\n\t| 'newTemplate'\n\t| 'submitAttempt';\n\nexport type ItemSessionActionCommand =\n\t| { action: 'suspendAttempt' }\n\t| { action: 'endAttempt'; countAttempt?: boolean; validateResponses?: boolean }\n\t| { action: 'scoreAttempt' }\n\t| { action: 'newTemplate'; resetResponses?: boolean }\n\t| { action: 'submitAttempt'; countAttempt?: boolean };\n\nexport interface ItemSessionActionResult {\n\taction: ItemSessionAction;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\tduration: number;\n\tcompleted: boolean;\n\tsessionState: SerializedItemSessionState;\n\tvalidation?: ResponseValidationResult;\n\tscoring?: ScoringResult;\n}\n\n/** @internal Private engine response map. */\nexport interface InteractionResponse {\n\t[responseId: string]: any;\n}\n\n/**\n * Serializable representation of a QTI baseType=\"file\" response.\n * (We cannot store a browser File object in session state / JSON exports.)\n */\nexport interface QTIFileResponse {\n\tname: string;\n\ttype: string;\n\tsize: number;\n\tlastModified: number;\n\t/** Base64 data URL, e.g. data:application/pdf;base64,... */\n\tdataUrl: string;\n\t/**\n\t * Optional ImageData extracted from canvas (for drawing interactions).\n\t * This allows custom operators to analyze drawing content synchronously\n\t * without needing to decode the dataUrl asynchronously.\n\t */\n\timageData?: {\n\t\tdata: Uint8ClampedArray;\n\t\twidth: number;\n\t\theight: number;\n\t};\n}\n\nexport interface ModalFeedback {\n\t/** Unique identifier for this feedback block */\n\tidentifier: string;\n\t/** Outcome variable identifier this feedback is tied to */\n\toutcomeIdentifier: string;\n\t/** When to show: 'show' means display when outcome matches identifier */\n\tshowHide: 'show' | 'hide';\n\t/** HTML content to display */\n\tcontent: HtmlContent;\n\t/** Optional title for the feedback */\n\ttitle?: string;\n}\n\nexport interface ScoringResult {\n\tscore: number;\n\tmaxScore: number;\n\tcompleted: boolean;\n\toutcomeValues: Record<string, any>;\n\t/** Modal feedback elements that should be displayed based on outcome values */\n\tmodalFeedback?: ModalFeedback[];\n}\n\n/**\n * QTI 2.2 completionStatus values for adaptive items\n * - not_attempted: No interaction has occurred yet\n * - unknown: Response exists but hasn't been scored/evaluated\n * - incomplete: Item has been scored but is still active (can submit again)\n * - completed: Item is finished (final state)\n */\nexport type CompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';\n\n/**\n * Extended scoring result for adaptive items with multi-attempt support\n */\nexport interface AdaptiveAttemptResult extends ScoringResult {\n\t/** Number of attempts made so far */\n\tnumAttempts: number;\n\t/** Current completion status of the item */\n\tcompletionStatus: CompletionStatus;\n\t/** Whether the item can accept more submissions */\n\tcanContinue: boolean;\n}\n\n/**\n * QTI role/view actors used for audience filtering (for example rubric/outcome visibility).\n * Runtime interaction behavior (readonly vs editable, correct-answer visibility) is a player\n * policy layered on top of these roles.\n */\nexport type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';\n\nexport type RubricBlockScope = 'direct' | 'itemBody';\n\n/** @internal Private engine rubric query. */\nexport interface RubricBlockOptions {\n\t/**\n\t * `direct` rubrics are assessment-item children and are intended for host placement.\n\t * `itemBody` rubrics are authored in the visible item body flow.\n\t */\n\tscope?: RubricBlockScope | 'all';\n}\n\nexport interface RubricBlock {\n\tview: string[]; // Array of role strings that can see this rubric\n\thtml: HtmlContent; // HTML content of the rubric\n\tscope: RubricBlockScope;\n\tuse?: string;\n}\n\n/**\n * QTI specification compliance configuration.\n * Controls whether the player enforces strict QTI 2.2 spec or allows vendor extensions.\n */\nexport interface QTIComplianceConfig {\n\t/** Enable strict QTI 2.2 compliance mode. Default: false (lenient) */\n\tenabled?: boolean;\n\n\t/** Reject items with unknown or non-standard elements. Default: false */\n\trejectUnknownExtensions?: boolean;\n\n\t/** Log warnings for spec deviations and vendor extensions. Default: true */\n\tlogDeviations?: boolean;\n}\n\n/** @internal Configuration for the private item-session engine. */\nexport interface ItemSessionEngineConfig {\n\titemXml: string;\n\t/**\n\t * QTI 3.0 §6.2 Personal Needs and Preferences profile.\n\t * Color scheme is applied immediately as data-qti-colorscheme on the player root.\n\t * Use player.updatePnp() to change mid-session without re-parsing the item.\n\t */\n\tpnp?: import('../pnp/types.js').PnpProfile;\n\t/**\n\t * Optional shared catalog XML string (QTI 3.0 §6.3).\n\t * Parsed and merged with any catalog embedded in the item XML.\n\t * Item-level catalog entries take precedence over shared entries with the same identifier.\n\t * Deferred: external catalog files from IMS manifest (G-15) are not yet supported.\n\t */\n\tcatalogXml?: string;\n\t/**\n\t * Optional resolved delivery context produced by IMS package/assessment layers.\n\t * This is additive to catalogXml: shared catalog sources are merged first, then\n\t * catalogXml, then item-embedded catalog entries so item-local entries win.\n\t */\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\trole?: QTIRole;\n\t/** Optional seed for deterministic random operations (e.g. templateProcessing randomInteger) */\n\tseed?: number;\n\t/** Optional RNG override (takes precedence over seed if provided) */\n\trng?: () => number;\n\t/**\n\t * Optional element name mapper for handling different QTI versions.\n\t * Defaults to Qti2xElementNameMapper (primary supported QTI format).\n\t * @since 0.2.0\n\t */\n\telementNameMapper?: any; // Will be ElementNameMapper from @pie-qti/qti-common\n\t/**\n\t * Optional attribute name mapper for handling different QTI versions.\n\t * Defaults to Qti2xAttributeNameMapper (primary supported QTI format).\n\t * @since 0.3.0\n\t */\n\tattributeNameMapper?: any; // Will be AttributeNameMapper from @pie-qti/qti-common\n\t/** Optional web component registry for custom interaction components */\n\tcomponentRegistry?: any; // Will be ComponentRegistry, but avoiding circular dependency\n\t/** Optional extraction registry for custom element extractors */\n\textractionRegistry?: any; // Will be ExtractionRegistry, but avoiding circular dependency\n\t/**\n\t * Optional i18n provider for internationalization.\n\t * If not provided, defaults to DefaultI18nProvider with English messages.\n\t */\n\ti18nProvider?: any; // Will be I18nProvider from @pie-qti/i18n\n\t/**\n\t * Optional registry for executing QTI <customOperator> expressions.\n\t * Keyed by operator `class` (preferred) or `definition` URI.\n\t */\n\tcustomOperators?: Record<string, (args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue>;\n\t/**\n\t * Host-controlled resolver for xi:include processing fragments.\n\t * The player never fetches an authored href directly; package hosts must resolve\n\t * and containment-check it, then return XML synchronously.\n\t */\n\tresolveProcessingFragment?: ProcessingFragmentResolver;\n\t/** Resource limits applied cumulatively while compiling external processing fragments. */\n\tprocessingFragmentLimits?: {\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t};\n\t/**\n\t * Portable Custom Interaction runtime configuration.\n\t * A moduleResolver is required before any authored PCI code can execute.\n\t */\n\tpci?: PciConfiguration;\n\t/**\n\t * Security-related controls for untrusted QTI rendered into the host DOM.\n\t * Defaults are conservative for same-DOM embedding.\n\t */\n\tsecurity?: PlayerSecurityConfig;\n\n\t/**\n\t * QTI specification compliance settings.\n\t * Set strictQtiCompliance.enabled = true for strict QTI 2.2 validation.\n\t */\n\tstrictQtiCompliance?: QTIComplianceConfig;\n}\n\nexport interface UrlPolicyConfig {\n\t/**\n\t * Optional base URL used to resolve relative asset URLs (e.g. images/media).\n\t * If omitted, relative URLs are preserved as-is.\n\t */\n\tassetBaseUrl?: string;\n\t/** Allow https: URLs */\n\tallowHttps?: boolean;\n\t/** Allow http: URLs (default false; prefer https) */\n\tallowHttp?: boolean;\n\t/** Allow protocol-relative URLs (e.g. //cdn.example/asset). Default false. */\n\tallowProtocolRelative?: boolean;\n\t/** Allow data:image/* for <img src>. */\n\tallowDataImages?: boolean;\n\t/** Allow data:image/svg+xml (default false) */\n\tallowSvgDataImages?: boolean;\n\t/** Allow blob: URLs for package-resolved images (default false). */\n\tallowBlobImages?: boolean;\n\t/** Allow blob: URLs for package-resolved audio/video media (default false). */\n\tallowBlobMedia?: boolean;\n\t/** Optional allowlist of hostnames for absolute URLs (exact match). */\n\tallowedHosts?: string[];\n}\n\n/**\n * Trusted Types support:\n * - When enabled and supported by the host browser + CSP, HTML-returning APIs may return TrustedHTML instead of string.\n * - When not enabled (default), APIs return plain strings as before.\n */\nexport type TrustedTypesHtml = typeof globalThis extends { TrustedHTML: infer T } ? T : never;\nexport type HtmlContent = string | TrustedTypesHtml;\n\nexport interface PlayerSecurityConfig {\n\t/** URL policy applied to extracted URL fields and HTML attribute URLs */\n\turlPolicy?: UrlPolicyConfig;\n\t/** Allow <object>/<embed> usage (default false) */\n\tallowObjectEmbeds?: boolean;\n\t/** Allow <iframe> usage (default false) */\n\tallowIframes?: boolean;\n\t/**\n\t * Optional parsing/processing guardrails to reduce DoS risk from untrusted QTI.\n\t * Disabled by default for compatibility.\n\t */\n\tparsingLimits?: ParsingLimitsConfig;\n\t/**\n\t * Optional Trusted Types policy name (host-controlled).\n\t * When set, and Trusted Types is available, the player will produce TrustedHTML for HTML injection sinks.\n\t *\n\t * Note: this is only effective when the host enables Trusted Types via CSP.\n\t */\n\ttrustedTypesPolicyName?: string;\n}\n\nexport interface ParsingLimitsConfig {\n\t/**\n\t * Enables parsing limits. When false/undefined, the player behaves exactly as before (compat default).\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Reject any XML containing <!DOCTYPE ...> (case-insensitive) when enabled.\n\t * Helps reduce entity-expansion and other parser edge-case risks.\n\t */\n\trejectDoctype?: boolean;\n\t/**\n\t * Maximum bytes for `itemXml` input (UTF-8). Enforced when enabled.\n\t */\n\tmaxItemXmlBytes?: number;\n\t/**\n\t * Maximum bytes for HTML strings passed to sanitizer (UTF-8). Enforced when enabled.\n\t */\n\tmaxHtmlBytes?: number;\n\t/**\n\t * Maximum number of element nodes sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlNodes?: number;\n\t/**\n\t * Maximum element depth sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlDepth?: number;\n}\n\nexport interface InteractionContext {\n\tresponseIdentifier: string;\n\tmaxChoices?: number;\n\tminChoices?: number;\n\tshuffle?: boolean;\n\torientation?: 'horizontal' | 'vertical';\n}\n\nexport * from './responseValidation.js';\n"]}
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
import type { HtmlContent } from '../types/index.js';
|
|
26
|
-
import type {
|
|
26
|
+
import type { BaseInteractionData } from '../interactions/shared/types.js';
|
|
27
27
|
import { type InteractionResponseValue, type QTIInteractionElement } from './QTIInteractionElement.js';
|
|
28
|
-
export declare abstract class QTIInteractionBase<TData extends
|
|
28
|
+
export declare abstract class QTIInteractionBase<TData extends BaseInteractionData = BaseInteractionData> extends HTMLElement implements QTIInteractionElement<TData> {
|
|
29
29
|
private _interaction;
|
|
30
30
|
private _response;
|
|
31
31
|
private _disabled;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QTIInteractionBase.js","sourceRoot":"","sources":["../../src/web-components/QTIInteractionBase.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Abstract base class for all QTI interaction web components\n *\n * Provides common functionality including:\n * - Reactive property system\n * - Shadow DOM management\n * - Event emission helpers\n * - Update scheduling\n * - Lifecycle management\n *\n * @example\n * ```typescript\n * export class QTIChoiceInteraction extends QTIInteractionBase<ChoiceInteractionData> {\n * protected render(): void {\n * this.shadowRoot.innerHTML = `...`;\n * this.attachEventListeners();\n * }\n *\n * protected cleanup(): void {\n * // Optional cleanup\n * }\n * }\n * ```\n */\n\nimport type { HtmlContent } from '../types/index.js';\nimport type { InteractionData } from '../interactions/index.js';\nimport {\n\ttype InteractionResponseValue,\n\tQTIChangeEvent,\n\tQTIErrorEvent,\n\ttype QTIInteractionElement,\n\tQTIReadyEvent,\n} from './QTIInteractionElement.js';\n\nexport abstract class QTIInteractionBase<TData extends InteractionData = InteractionData>\n\textends HTMLElement\n\timplements QTIInteractionElement<TData>\n{\n\tprivate _interaction: TData | null = null;\n\tprivate _response: InteractionResponseValue<TData> | null = null;\n\tprivate _disabled = false;\n\tprivate _typeset?: (element: HTMLElement) => void;\n\n\tdeclare shadowRoot: ShadowRoot; // Override HTMLElement's shadowRoot type\n\tprivate updateScheduled = false;\n\tprivate isInitialized = false;\n\n\tconstructor() {\n\t\tsuper();\n\t\t// attachShadow returns ShadowRoot, and we cast to ensure type compatibility\n\t\t(this as any).shadowRoot = this.attachShadow({ mode: 'open' });\n\t}\n\n\t// ========== Property Getters/Setters ==========\n\n\t/**\n\t * The processed interaction data from QTI XML\n\t * Required property - throws if accessed before being set\n\t */\n\tget interaction(): TData {\n\t\tif (!this._interaction) {\n\t\t\tthrow new Error(\n\t\t\t\t`${this.tagName}: interaction property must be set before use`\n\t\t\t);\n\t\t}\n\t\treturn this._interaction;\n\t}\n\n\tset interaction(value: TData) {\n\t\tif (this._interaction !== value) {\n\t\t\tthis._interaction = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Current response value (type depends on interaction type)\n\t * May be null if no response has been provided yet\n\t */\n\tget response(): InteractionResponseValue<TData> | null {\n\t\treturn this._response;\n\t}\n\n\tset response(value: InteractionResponseValue<TData> | null) {\n\t\tif (this._response !== value) {\n\t\t\tthis._response = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Whether the interaction is in read-only/disabled mode\n\t */\n\tget disabled(): boolean {\n\t\treturn this._disabled;\n\t}\n\n\tset disabled(value: boolean) {\n\t\tconst newValue = Boolean(value);\n\t\tif (this._disabled !== newValue) {\n\t\t\tthis._disabled = newValue;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Optional function to apply math typesetting (e.g., KaTeX, MathJax)\n\t */\n\tget typeset(): ((element: HTMLElement) => void) | undefined {\n\t\treturn this._typeset;\n\t}\n\n\tset typeset(value: ((element: HTMLElement) => void) | undefined) {\n\t\tif (this._typeset !== value) {\n\t\t\tthis._typeset = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t// ========== Lifecycle Hooks ==========\n\n\t/**\n\t * Called when the element is connected to the DOM\n\t */\n\tconnectedCallback(): void {\n\t\tif (!this.isInitialized) {\n\t\t\tthis.isInitialized = true;\n\t\t\tthis.init();\n\t\t}\n\t\tthis.requestUpdate();\n\t}\n\n\t/**\n\t * Called when the element is disconnected from the DOM\n\t */\n\tdisconnectedCallback(): void {\n\t\tthis.cleanup();\n\t}\n\n\t/**\n\t * Called once when the element is first connected\n\t * Override this to perform one-time initialization\n\t */\n\tprotected init(): void {\n\t\t// Override in subclasses if needed\n\t}\n\n\t// ========== Reactive Updates ==========\n\n\t/**\n\t * Schedule a re-render on the next microtask\n\t * Multiple calls within the same tick are batched\n\t */\n\tprotected requestUpdate(): void {\n\t\tif (!this.updateScheduled && this.isConnected) {\n\t\t\tthis.updateScheduled = true;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.updateScheduled = false;\n\t\t\t\ttry {\n\t\t\t\t\tthis.render();\n\t\t\t\t\tif (this.isInitialized) {\n\t\t\t\t\t\tthis.emitReady();\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.emitError(error as Error, 'render');\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// ========== Abstract Methods ==========\n\n\t/**\n\t * Render the component's UI\n\t * Called automatically when properties change\n\t * Must be implemented by subclasses\n\t */\n\tprotected abstract render(): void;\n\n\t/**\n\t * Clean up resources when component is removed from DOM\n\t * Override this to remove event listeners, cancel timers, etc.\n\t */\n\tprotected abstract cleanup(): void;\n\n\t// ========== Event Helpers ==========\n\n\t/**\n\t * Emit a qti-change event when the user response changes\n\t * @param value - The new response value\n\t */\n\tprotected emitChange(value: InteractionResponseValue<TData> | null): void {\n\t\tif (!this._interaction) {\n\t\t\tconsole.warn(`${this.tagName}: Cannot emit change without interaction data`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst event = new QTIChangeEvent({\n\t\t\tresponseId: this._interaction.responseId,\n\t\t\tvalue,\n\t\t\ttimestamp: Date.now(),\n\t\t});\n\n\t\tthis.dispatchEvent(event);\n\t}\n\n\t/**\n\t * Emit a qti-ready event when component is initialized\n\t */\n\tprivate emitReady(): void {\n\t\tthis.dispatchEvent(new QTIReadyEvent());\n\t}\n\n\t/**\n\t * Emit a qti-error event when an error occurs\n\t */\n\tprotected emitError(error: Error, context: string): void {\n\t\tconst event = new QTIErrorEvent({ error, context });\n\t\tthis.dispatchEvent(event);\n\t\tconsole.error(`${this.tagName} error in ${context}:`, error);\n\t}\n\n\t// ========== Utility Methods ==========\n\n\t/**\n\t * Apply math typesetting to the shadow root\n\t * Call this after updating the DOM with math content\n\t */\n\tprotected applyTypesetting(): void {\n\t\tif (this._typeset && this.shadowRoot) {\n\t\t\ttry {\n\t\t\t\tthis._typeset(this.shadowRoot as any);\n\t\t\t} catch (error) {\n\t\t\t\tthis.emitError(error as Error, 'typesetting');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get base styles for all interaction components\n\t * Override and call super.getStyles() to extend these styles\n\t */\n\tprotected getStyles(): string {\n\t\treturn `\n\t\t\t:host {\n\t\t\t\tdisplay: block;\n\t\t\t\tfont-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',\n\t\t\t\t\tRoboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n\t\t\t\tfont-size: 16px;\n\t\t\t\tline-height: 1.5;\n\t\t\t}\n\n\t\t\t:host([disabled]) {\n\t\t\t\topacity: 0.6;\n\t\t\t\tpointer-events: none;\n\t\t\t}\n\n\t\t\t* {\n\t\t\t\tbox-sizing: border-box;\n\t\t\t}\n\n\t\t\t.qti-prompt {\n\t\t\t\tmargin-bottom: 1rem;\n\t\t\t\tfont-weight: 600;\n\t\t\t}\n\n\t\t\t.qti-error {\n\t\t\t\tcolor: #dc2626;\n\t\t\t\tpadding: 0.75rem;\n\t\t\t\tbackground: #fee2e2;\n\t\t\t\tborder-radius: 0.375rem;\n\t\t\t\tmargin: 0.5rem 0;\n\t\t\t}\n\t\t`;\n\t}\n\n\t/**\n\t * Safely set innerHTML with error handling\n\t */\n\tprotected safeSetInnerHTML(element: HTMLElement | ShadowRoot, html: HtmlContent): void {\n\t\ttry {\n\t\t\telement.innerHTML = html as any;\n\t\t} catch (error) {\n\t\t\tthis.emitError(error as Error, 'setInnerHTML');\n\t\t\telement.innerHTML = `<div class=\"qti-error\">Failed to render content</div>`;\n\t\t}\n\t}\n\n\t/**\n\t * Create an element with classes\n\t */\n\tprotected createElement<K extends keyof HTMLElementTagNameMap>(\n\t\ttagName: K,\n\t\tclasses?: string[]\n\t): HTMLElementTagNameMap[K] {\n\t\tconst element = document.createElement(tagName);\n\t\tif (classes && classes.length > 0) {\n\t\t\telement.className = classes.join(' ');\n\t\t}\n\t\treturn element;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QTIInteractionBase.js","sourceRoot":"","sources":["../../src/web-components/QTIInteractionBase.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Abstract base class for all QTI interaction web components\n *\n * Provides common functionality including:\n * - Reactive property system\n * - Shadow DOM management\n * - Event emission helpers\n * - Update scheduling\n * - Lifecycle management\n *\n * @example\n * ```typescript\n * export class QTIChoiceInteraction extends QTIInteractionBase<ChoiceInteractionData> {\n * protected render(): void {\n * this.shadowRoot.innerHTML = `...`;\n * this.attachEventListeners();\n * }\n *\n * protected cleanup(): void {\n * // Optional cleanup\n * }\n * }\n * ```\n */\n\nimport type { HtmlContent } from '../types/index.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\nimport {\n\ttype InteractionResponseValue,\n\tQTIChangeEvent,\n\tQTIErrorEvent,\n\ttype QTIInteractionElement,\n\tQTIReadyEvent,\n} from './QTIInteractionElement.js';\n\nexport abstract class QTIInteractionBase<\n\tTData extends BaseInteractionData = BaseInteractionData,\n>\n\textends HTMLElement\n\timplements QTIInteractionElement<TData>\n{\n\tprivate _interaction: TData | null = null;\n\tprivate _response: InteractionResponseValue<TData> | null = null;\n\tprivate _disabled = false;\n\tprivate _typeset?: (element: HTMLElement) => void;\n\n\tdeclare shadowRoot: ShadowRoot; // Override HTMLElement's shadowRoot type\n\tprivate updateScheduled = false;\n\tprivate isInitialized = false;\n\n\tconstructor() {\n\t\tsuper();\n\t\t// attachShadow returns ShadowRoot, and we cast to ensure type compatibility\n\t\t(this as any).shadowRoot = this.attachShadow({ mode: 'open' });\n\t}\n\n\t// ========== Property Getters/Setters ==========\n\n\t/**\n\t * The processed interaction data from QTI XML\n\t * Required property - throws if accessed before being set\n\t */\n\tget interaction(): TData {\n\t\tif (!this._interaction) {\n\t\t\tthrow new Error(\n\t\t\t\t`${this.tagName}: interaction property must be set before use`\n\t\t\t);\n\t\t}\n\t\treturn this._interaction;\n\t}\n\n\tset interaction(value: TData) {\n\t\tif (this._interaction !== value) {\n\t\t\tthis._interaction = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Current response value (type depends on interaction type)\n\t * May be null if no response has been provided yet\n\t */\n\tget response(): InteractionResponseValue<TData> | null {\n\t\treturn this._response;\n\t}\n\n\tset response(value: InteractionResponseValue<TData> | null) {\n\t\tif (this._response !== value) {\n\t\t\tthis._response = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Whether the interaction is in read-only/disabled mode\n\t */\n\tget disabled(): boolean {\n\t\treturn this._disabled;\n\t}\n\n\tset disabled(value: boolean) {\n\t\tconst newValue = Boolean(value);\n\t\tif (this._disabled !== newValue) {\n\t\t\tthis._disabled = newValue;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t/**\n\t * Optional function to apply math typesetting (e.g., KaTeX, MathJax)\n\t */\n\tget typeset(): ((element: HTMLElement) => void) | undefined {\n\t\treturn this._typeset;\n\t}\n\n\tset typeset(value: ((element: HTMLElement) => void) | undefined) {\n\t\tif (this._typeset !== value) {\n\t\t\tthis._typeset = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t// ========== Lifecycle Hooks ==========\n\n\t/**\n\t * Called when the element is connected to the DOM\n\t */\n\tconnectedCallback(): void {\n\t\tif (!this.isInitialized) {\n\t\t\tthis.isInitialized = true;\n\t\t\tthis.init();\n\t\t}\n\t\tthis.requestUpdate();\n\t}\n\n\t/**\n\t * Called when the element is disconnected from the DOM\n\t */\n\tdisconnectedCallback(): void {\n\t\tthis.cleanup();\n\t}\n\n\t/**\n\t * Called once when the element is first connected\n\t * Override this to perform one-time initialization\n\t */\n\tprotected init(): void {\n\t\t// Override in subclasses if needed\n\t}\n\n\t// ========== Reactive Updates ==========\n\n\t/**\n\t * Schedule a re-render on the next microtask\n\t * Multiple calls within the same tick are batched\n\t */\n\tprotected requestUpdate(): void {\n\t\tif (!this.updateScheduled && this.isConnected) {\n\t\t\tthis.updateScheduled = true;\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tthis.updateScheduled = false;\n\t\t\t\ttry {\n\t\t\t\t\tthis.render();\n\t\t\t\t\tif (this.isInitialized) {\n\t\t\t\t\t\tthis.emitReady();\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.emitError(error as Error, 'render');\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// ========== Abstract Methods ==========\n\n\t/**\n\t * Render the component's UI\n\t * Called automatically when properties change\n\t * Must be implemented by subclasses\n\t */\n\tprotected abstract render(): void;\n\n\t/**\n\t * Clean up resources when component is removed from DOM\n\t * Override this to remove event listeners, cancel timers, etc.\n\t */\n\tprotected abstract cleanup(): void;\n\n\t// ========== Event Helpers ==========\n\n\t/**\n\t * Emit a qti-change event when the user response changes\n\t * @param value - The new response value\n\t */\n\tprotected emitChange(value: InteractionResponseValue<TData> | null): void {\n\t\tif (!this._interaction) {\n\t\t\tconsole.warn(`${this.tagName}: Cannot emit change without interaction data`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst event = new QTIChangeEvent({\n\t\t\tresponseId: this._interaction.responseId,\n\t\t\tvalue,\n\t\t\ttimestamp: Date.now(),\n\t\t});\n\n\t\tthis.dispatchEvent(event);\n\t}\n\n\t/**\n\t * Emit a qti-ready event when component is initialized\n\t */\n\tprivate emitReady(): void {\n\t\tthis.dispatchEvent(new QTIReadyEvent());\n\t}\n\n\t/**\n\t * Emit a qti-error event when an error occurs\n\t */\n\tprotected emitError(error: Error, context: string): void {\n\t\tconst event = new QTIErrorEvent({ error, context });\n\t\tthis.dispatchEvent(event);\n\t\tconsole.error(`${this.tagName} error in ${context}:`, error);\n\t}\n\n\t// ========== Utility Methods ==========\n\n\t/**\n\t * Apply math typesetting to the shadow root\n\t * Call this after updating the DOM with math content\n\t */\n\tprotected applyTypesetting(): void {\n\t\tif (this._typeset && this.shadowRoot) {\n\t\t\ttry {\n\t\t\t\tthis._typeset(this.shadowRoot as any);\n\t\t\t} catch (error) {\n\t\t\t\tthis.emitError(error as Error, 'typesetting');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get base styles for all interaction components\n\t * Override and call super.getStyles() to extend these styles\n\t */\n\tprotected getStyles(): string {\n\t\treturn `\n\t\t\t:host {\n\t\t\t\tdisplay: block;\n\t\t\t\tfont-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',\n\t\t\t\t\tRoboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n\t\t\t\tfont-size: 16px;\n\t\t\t\tline-height: 1.5;\n\t\t\t}\n\n\t\t\t:host([disabled]) {\n\t\t\t\topacity: 0.6;\n\t\t\t\tpointer-events: none;\n\t\t\t}\n\n\t\t\t* {\n\t\t\t\tbox-sizing: border-box;\n\t\t\t}\n\n\t\t\t.qti-prompt {\n\t\t\t\tmargin-bottom: 1rem;\n\t\t\t\tfont-weight: 600;\n\t\t\t}\n\n\t\t\t.qti-error {\n\t\t\t\tcolor: #dc2626;\n\t\t\t\tpadding: 0.75rem;\n\t\t\t\tbackground: #fee2e2;\n\t\t\t\tborder-radius: 0.375rem;\n\t\t\t\tmargin: 0.5rem 0;\n\t\t\t}\n\t\t`;\n\t}\n\n\t/**\n\t * Safely set innerHTML with error handling\n\t */\n\tprotected safeSetInnerHTML(element: HTMLElement | ShadowRoot, html: HtmlContent): void {\n\t\ttry {\n\t\t\telement.innerHTML = html as any;\n\t\t} catch (error) {\n\t\t\tthis.emitError(error as Error, 'setInnerHTML');\n\t\t\telement.innerHTML = `<div class=\"qti-error\">Failed to render content</div>`;\n\t\t}\n\t}\n\n\t/**\n\t * Create an element with classes\n\t */\n\tprotected createElement<K extends keyof HTMLElementTagNameMap>(\n\t\ttagName: K,\n\t\tclasses?: string[]\n\t): HTMLElementTagNameMap[K] {\n\t\tconst element = document.createElement(tagName);\n\t\tif (classes && classes.length > 0) {\n\t\t\telement.className = classes.join(' ');\n\t\t}\n\t\treturn element;\n\t}\n}\n"]}
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
* All QTI interaction web components must implement the QTIInteractionElement
|
|
5
5
|
* interface and emit QTIChangeEvent when the user response changes.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
export type InteractionResponseValue<TData extends
|
|
7
|
+
import type { BaseInteractionData, InteractionValueMap } from '../interactions/shared/types.js';
|
|
8
|
+
export type InteractionResponseValue<TData extends BaseInteractionData = BaseInteractionData> = TData extends {
|
|
9
9
|
type: infer TType;
|
|
10
10
|
} ? TType extends keyof InteractionValueMap ? InteractionValueMap[TType] : unknown : unknown;
|
|
11
11
|
/**
|
|
12
12
|
* Standard interface that all QTI interaction web components must implement
|
|
13
13
|
*/
|
|
14
|
-
export interface QTIInteractionElement<TData extends
|
|
14
|
+
export interface QTIInteractionElement<TData extends BaseInteractionData = BaseInteractionData> extends HTMLElement {
|
|
15
15
|
/** The processed interaction data from the QTI XML */
|
|
16
16
|
interaction: TData;
|
|
17
17
|
/** The current response value (type depends on interaction type) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QTIInteractionElement.js","sourceRoot":"","sources":["../../src/web-components/QTIInteractionElement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"QTIInteractionElement.js","sourceRoot":"","sources":["../../src/web-components/QTIInteractionElement.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4CH;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAyD,SAAQ,WAAyC;IACtH,YAAY,MAAoC;QAC/C,KAAK,CAAC,YAAY,EAAE;YACnB,MAAM;YACN,OAAO,EAAE,IAAI,EAAE,6BAA6B;YAC5C,QAAQ,EAAE,IAAI,EAAE,8BAA8B;YAC9C,UAAU,EAAE,KAAK,EAAE,sBAAsB;SACzC,CAAC,CAAC;IACJ,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAiB;IACnD;QACC,KAAK,CAAC,WAAW,EAAE;YAClB,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;CACD;AAaD,MAAM,OAAO,aAAc,SAAQ,WAAgC;IAClE,YAAY,MAA2B;QACtC,KAAK,CAAC,WAAW,EAAE;YAClB,MAAM;YACN,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;CACD;AAWD,MAAM,OAAO,uBAAwB,SAAQ,WAA0C;IACtF,YAAY,MAAqC;QAChD,KAAK,CAAC,sBAAsB,EAAE;YAC7B,MAAM;YACN,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/**\n * Standard interface and event types for QTI interaction web components\n *\n * All QTI interaction web components must implement the QTIInteractionElement\n * interface and emit QTIChangeEvent when the user response changes.\n */\n\nimport type { BaseInteractionData, InteractionValueMap } from '../interactions/shared/types.js';\n\nexport type InteractionResponseValue<TData extends BaseInteractionData = BaseInteractionData> =\n\tTData extends { type: infer TType }\n\t\t? TType extends keyof InteractionValueMap\n\t\t\t? InteractionValueMap[TType]\n\t\t\t: unknown\n\t\t: unknown;\n\n/**\n * Standard interface that all QTI interaction web components must implement\n */\nexport interface QTIInteractionElement<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> extends HTMLElement {\n\t/** The processed interaction data from the QTI XML */\n\tinteraction: TData;\n\n\t/** The current response value (type depends on interaction type) */\n\tresponse: InteractionResponseValue<TData> | null;\n\n\t/** Whether the interaction is in read-only/disabled mode */\n\tdisabled: boolean;\n\n\t/** Optional function to apply math typesetting (e.g., KaTeX, MathJax) */\n\ttypeset?: (element: HTMLElement) => void;\n}\n\n/**\n * Detail payload for the qti-change event\n */\nexport interface QTIChangeEventDetail<TValue = InteractionResponseValue | null> {\n\t/** The response identifier for this interaction */\n\tresponseId: string;\n\n\t/** The new response value */\n\tvalue: TValue;\n\n\t/** Timestamp when the change occurred */\n\ttimestamp: number;\n}\n\n/**\n * Custom event emitted when an interaction's response changes\n *\n * This event bubbles and can cross shadow DOM boundaries, making it\n * easy to listen for changes at the container level.\n *\n * @example\n * ```typescript\n * element.addEventListener('qti-change', (event: QTIChangeEvent) => {\n * console.log('Response changed:', event.detail.responseId, event.detail.value);\n * });\n * ```\n */\nexport class QTIChangeEvent<TValue = InteractionResponseValue | null> extends CustomEvent<QTIChangeEventDetail<TValue>> {\n\tconstructor(detail: QTIChangeEventDetail<TValue>) {\n\t\tsuper('qti-change', {\n\t\t\tdetail,\n\t\t\tbubbles: true, // Bubble up through DOM tree\n\t\t\tcomposed: true, // Cross shadow DOM boundaries\n\t\t\tcancelable: false, // Cannot be prevented\n\t\t});\n\t}\n}\n\n/**\n * Event emitted when a component is ready (initialized and rendered)\n */\nexport class QTIReadyEvent extends CustomEvent<void> {\n\tconstructor() {\n\t\tsuper('qti-ready', {\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t\tcancelable: false,\n\t\t});\n\t}\n}\n\n/**\n * Event emitted when an error occurs in a component\n */\nexport interface QTIErrorEventDetail {\n\t/** The error that occurred */\n\terror: Error;\n\n\t/** Context about where the error occurred */\n\tcontext: string;\n}\n\nexport class QTIErrorEvent extends CustomEvent<QTIErrorEventDetail> {\n\tconstructor(detail: QTIErrorEventDetail) {\n\t\tsuper('qti-error', {\n\t\t\tdetail,\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t\tcancelable: false,\n\t\t});\n\t}\n}\n\n/**\n * Special event for AssociateInteraction selection state\n * (used for tracking which item is selected for pairing)\n */\nexport interface QTISelectionChangeEventDetail {\n\t/** The identifier of the selected item, or null if deselected */\n\tselected: string | null;\n}\n\nexport class QTISelectionChangeEvent extends CustomEvent<QTISelectionChangeEventDetail> {\n\tconstructor(detail: QTISelectionChangeEventDetail) {\n\t\tsuper('qti-selection-change', {\n\t\t\tdetail,\n\t\t\tbubbles: true,\n\t\t\tcomposed: true,\n\t\t\tcancelable: false,\n\t\t});\n\t}\n}\n"]}
|