@pie-qti/item-player 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.md +17 -0
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  4. package/dist/catalog/glossaryAction.d.ts +4 -2
  5. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  6. package/dist/components/utils/index.d.ts +1 -2
  7. package/dist/components/utils/index.d.ts.map +1 -1
  8. package/dist/components/utils/index.js +1 -2
  9. package/dist/core/ComponentRegistry.d.ts +10 -1
  10. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  11. package/dist/core/ComponentRegistry.js +42 -1
  12. package/dist/core/Player.d.ts +10 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +54 -46
  15. package/dist/document/AssessmentItemDocument.d.ts +1 -1
  16. package/dist/element.d.ts +15 -0
  17. package/dist/element.js +1921 -1785
  18. package/dist/element.js.map +1 -1
  19. package/dist/extraction/ExtractionRegistry.d.ts +1 -1
  20. package/dist/extraction/createContext.d.ts +1 -1
  21. package/dist/extraction/index.d.ts +2 -2
  22. package/dist/extraction/index.d.ts.map +1 -1
  23. package/dist/extraction/index.js +1 -1
  24. package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
  25. package/dist/extraction/interactionSecurity.d.ts +1 -1
  26. package/dist/extraction/types.d.ts +1 -1
  27. package/dist/presentation/itemPresentationPlan.d.ts +54 -0
  28. package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
  29. package/dist/presentation/itemPresentationPlan.js +98 -0
  30. package/dist/types/index.d.ts +17 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/index.js +0 -3
  33. package/dist/web-components/QTIInteractionBase.d.ts +1 -1
  34. package/dist/web-components/QTIInteractionElement.d.ts +1 -1
  35. package/package.json +10 -12
  36. package/src/__tests__/catalog.test.ts +0 -267
  37. package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
  38. package/src/__tests__/pci.test.ts +0 -353
  39. package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
  40. package/src/__tests__/qti3-debug.test.ts +0 -140
  41. package/src/__tests__/qti3-extraction.test.ts +0 -309
  42. package/src/catalog/applyGlossaryTriggers.ts +0 -372
  43. package/src/catalog/catalogExtractor.ts +0 -130
  44. package/src/catalog/catalogLookup.ts +0 -53
  45. package/src/catalog/glossaryAction.ts +0 -38
  46. package/src/catalog/types.ts +0 -37
  47. package/src/components/ItemBody.svelte +0 -363
  48. package/src/components/ItemPlayer.svelte +0 -163
  49. package/src/components/ModalFeedbackDisplay.svelte +0 -97
  50. package/src/components/actions/typesetAction.ts +0 -74
  51. package/src/components/index.ts +0 -22
  52. package/src/components/utils/assignProps.ts +0 -2
  53. package/src/components/utils/feedbackUtils.ts +0 -140
  54. package/src/components/utils/index.ts +0 -13
  55. package/src/components/utils/stimulusRender.ts +0 -93
  56. package/src/components/utils/stylesheetRender.ts +0 -58
  57. package/src/core/ComponentRegistry.ts +0 -248
  58. package/src/core/Player.ts +0 -1618
  59. package/src/core/Plugin.ts +0 -123
  60. package/src/core/PluginManager.ts +0 -182
  61. package/src/core/constants.ts +0 -117
  62. package/src/core/declarations.ts +0 -171
  63. package/src/core/parsingLimits.ts +0 -62
  64. package/src/core/random.ts +0 -24
  65. package/src/core/rolePolicy.ts +0 -34
  66. package/src/core/sanitizer.ts +0 -305
  67. package/src/core/trustedTypes.ts +0 -63
  68. package/src/core/urlPolicy.ts +0 -98
  69. package/src/document/AssessmentItemDocument.ts +0 -247
  70. package/src/element.ts +0 -128
  71. package/src/extensions/MathLiveEditor.ts +0 -313
  72. package/src/extraction/ExtractionRegistry.ts +0 -335
  73. package/src/extraction/createContext.ts +0 -52
  74. package/src/extraction/extractors/associateExtractor.ts +0 -1
  75. package/src/extraction/extractors/choiceExtractor.ts +0 -1
  76. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
  77. package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
  78. package/src/extraction/extractors/conformance.test.ts +0 -208
  79. package/src/extraction/extractors/customExtractor.ts +0 -1
  80. package/src/extraction/extractors/drawingExtractor.ts +0 -1
  81. package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
  82. package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
  83. package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
  84. package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
  85. package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
  86. package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
  87. package/src/extraction/extractors/hotspotExtractor.ts +0 -1
  88. package/src/extraction/extractors/hottextExtractor.ts +0 -1
  89. package/src/extraction/extractors/index.ts +0 -9
  90. package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
  91. package/src/extraction/extractors/matchExtractor.ts +0 -1
  92. package/src/extraction/extractors/mediaExtractor.ts +0 -1
  93. package/src/extraction/extractors/orderExtractor.ts +0 -1
  94. package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
  95. package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
  96. package/src/extraction/extractors/selectPointExtractor.ts +0 -1
  97. package/src/extraction/extractors/sliderExtractor.ts +0 -1
  98. package/src/extraction/extractors/textEntryExtractor.ts +0 -1
  99. package/src/extraction/extractors/uploadExtractor.ts +0 -1
  100. package/src/extraction/index.ts +0 -108
  101. package/src/extraction/interactionExtractionPipeline.ts +0 -70
  102. package/src/extraction/interactionSecurity.ts +0 -60
  103. package/src/extraction/types.ts +0 -246
  104. package/src/extraction/utils.ts +0 -243
  105. package/src/iframe/IFramePlayerHost.ts +0 -265
  106. package/src/iframe/index.ts +0 -11
  107. package/src/iframe/protocol.ts +0 -137
  108. package/src/index.ts +0 -101
  109. package/src/interactions/associate/extractor.ts +0 -133
  110. package/src/interactions/associate/index.ts +0 -2
  111. package/src/interactions/associate/types.ts +0 -1
  112. package/src/interactions/choice/extractor.ts +0 -121
  113. package/src/interactions/choice/index.ts +0 -2
  114. package/src/interactions/choice/types.ts +0 -1
  115. package/src/interactions/custom/extractor.ts +0 -72
  116. package/src/interactions/custom/index.ts +0 -2
  117. package/src/interactions/custom/types.ts +0 -1
  118. package/src/interactions/drawing/extractor.ts +0 -113
  119. package/src/interactions/drawing/index.ts +0 -2
  120. package/src/interactions/drawing/types.ts +0 -1
  121. package/src/interactions/end-attempt/extractor.ts +0 -74
  122. package/src/interactions/end-attempt/index.ts +0 -2
  123. package/src/interactions/end-attempt/types.ts +0 -1
  124. package/src/interactions/extended-text/extractor.ts +0 -92
  125. package/src/interactions/extended-text/index.ts +0 -2
  126. package/src/interactions/extended-text/types.ts +0 -1
  127. package/src/interactions/gap-match/extractor.ts +0 -193
  128. package/src/interactions/gap-match/index.ts +0 -2
  129. package/src/interactions/gap-match/types.ts +0 -1
  130. package/src/interactions/graphic-associate/extractor.ts +0 -192
  131. package/src/interactions/graphic-associate/index.ts +0 -2
  132. package/src/interactions/graphic-associate/types.ts +0 -1
  133. package/src/interactions/graphic-gap-match/extractor.ts +0 -257
  134. package/src/interactions/graphic-gap-match/index.ts +0 -2
  135. package/src/interactions/graphic-gap-match/types.ts +0 -1
  136. package/src/interactions/graphic-order/extractor.ts +0 -162
  137. package/src/interactions/graphic-order/index.ts +0 -2
  138. package/src/interactions/graphic-order/types.ts +0 -1
  139. package/src/interactions/hotspot/extractor.ts +0 -208
  140. package/src/interactions/hotspot/index.ts +0 -2
  141. package/src/interactions/hotspot/types.ts +0 -1
  142. package/src/interactions/hottext/extractor.ts +0 -163
  143. package/src/interactions/hottext/index.ts +0 -2
  144. package/src/interactions/hottext/types.ts +0 -1
  145. package/src/interactions/index.ts +0 -52
  146. package/src/interactions/inline/index.ts +0 -1
  147. package/src/interactions/inline/render-plan.ts +0 -105
  148. package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
  149. package/src/interactions/inline-choice/extractor.ts +0 -105
  150. package/src/interactions/inline-choice/index.ts +0 -2
  151. package/src/interactions/inline-choice/types.ts +0 -1
  152. package/src/interactions/match/extractor.ts +0 -187
  153. package/src/interactions/match/index.ts +0 -2
  154. package/src/interactions/match/types.ts +0 -1
  155. package/src/interactions/media/extractor.ts +0 -168
  156. package/src/interactions/media/index.ts +0 -2
  157. package/src/interactions/media/types.ts +0 -1
  158. package/src/interactions/modules.ts +0 -111
  159. package/src/interactions/order/extractor.ts +0 -120
  160. package/src/interactions/order/index.ts +0 -2
  161. package/src/interactions/order/types.ts +0 -1
  162. package/src/interactions/portable-custom/extractor.ts +0 -122
  163. package/src/interactions/portable-custom/index.ts +0 -2
  164. package/src/interactions/portable-custom/types.ts +0 -1
  165. package/src/interactions/position-object/extractor.ts +0 -243
  166. package/src/interactions/position-object/index.ts +0 -2
  167. package/src/interactions/position-object/types.ts +0 -1
  168. package/src/interactions/select-point/extractor.ts +0 -143
  169. package/src/interactions/select-point/index.ts +0 -2
  170. package/src/interactions/select-point/types.ts +0 -1
  171. package/src/interactions/shared/index.ts +0 -1
  172. package/src/interactions/shared/types.ts +0 -430
  173. package/src/interactions/slider/extractor.ts +0 -102
  174. package/src/interactions/slider/index.ts +0 -2
  175. package/src/interactions/slider/types.ts +0 -1
  176. package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
  177. package/src/interactions/text-entry/extractor.ts +0 -79
  178. package/src/interactions/text-entry/index.ts +0 -2
  179. package/src/interactions/text-entry/types.ts +0 -1
  180. package/src/interactions/upload/extractor.ts +0 -81
  181. package/src/interactions/upload/index.ts +0 -2
  182. package/src/interactions/upload/types.ts +0 -1
  183. package/src/pci/PciHost.ts +0 -138
  184. package/src/pci/types.ts +0 -70
  185. package/src/pnp/applyPnp.ts +0 -29
  186. package/src/pnp/parsePnpXml.ts +0 -215
  187. package/src/pnp/types.ts +0 -75
  188. package/src/server.ts +0 -14
  189. package/src/types/index.ts +0 -388
  190. package/src/types/interactions.ts +0 -8
  191. package/src/types/responseValidation.ts +0 -29
  192. package/src/types/xmldom.d.ts +0 -12
  193. package/src/utils/PerformanceMonitor.ts +0 -335
  194. package/src/utils/drawingUtils.ts +0 -73
  195. package/src/utils/responseUtils.ts +0 -51
  196. package/src/utils/touchDragHelper.ts +0 -1
  197. package/src/web-components/QTIInteractionBase.ts +0 -303
  198. package/src/web-components/QTIInteractionElement.ts +0 -125
  199. package/src/web-components/index.ts +0 -22
@@ -1,335 +0,0 @@
1
- /**
2
- * ExtractionRegistry for priority-based element extraction
3
- *
4
- * Manages a collection of ElementExtractor instances with:
5
- * - Priority-based dispatch (highest priority checked first)
6
- * - Type-based indexing for O(M) lookup instead of O(N) scanning
7
- * - WeakMap caching for O(1) repeat lookups
8
- * - Validation and error handling
9
- */
10
-
11
- import { Qti2xElementNameMapper, type ElementNameMapper } from '@pie-qti/qti-common';
12
- import type { QTIElement } from '../types/interactions.js';
13
- import type {
14
- ElementExtractor,
15
- ExtractionContext,
16
- ExtractionResult,
17
- ValidationResult,
18
- } from './types.js';
19
- import { ExtractionError, isSuccessResult } from './types.js';
20
-
21
- /**
22
- * Registry for element extractors with priority-based dispatch
23
- */
24
- export class ExtractionRegistry {
25
- /** All registered extractors by ID */
26
- private extractorsById = new Map<string, ElementExtractor>();
27
-
28
- /** Extractors indexed by element type for fast lookup */
29
- private extractorsByType = new Map<string, ElementExtractor[]>();
30
-
31
- /** Cache for element -> extractor lookups (WeakMap for automatic GC) */
32
- private extractorCache = new WeakMap<QTIElement, ElementExtractor>();
33
-
34
- /** Optional element name mapper for QTI version handling */
35
- private elementNameMapper?: ElementNameMapper;
36
-
37
- /** QTI 2.x mapper for converting canonical names to extractor registry keys */
38
- private qti2xMapper = new Qti2xElementNameMapper();
39
-
40
- constructor(elementNameMapper?: ElementNameMapper) {
41
- this.elementNameMapper = elementNameMapper;
42
- }
43
-
44
- /**
45
- * Register an extractor with the registry
46
- *
47
- * @param extractor - The extractor to register
48
- * @throws Error if extractor ID is already registered
49
- *
50
- * @example
51
- * registry.register({
52
- * id: 'qti:choice',
53
- * name: 'QTI Standard Choice',
54
- * priority: 10,
55
- * elementTypes: ['choiceInteraction'],
56
- * canHandle: (element) => utils.hasChildWithTag(element, 'simpleChoice'),
57
- * extract: (element, context) => ({ choices: [...] })
58
- * });
59
- */
60
- register<TData, TContext extends ExtractionContext = ExtractionContext>(
61
- extractor: ElementExtractor<TData, TContext>
62
- ): void {
63
- // Check for duplicate ID
64
- if (this.extractorsById.has(extractor.id)) {
65
- throw new Error(
66
- `Extractor with ID '${extractor.id}' is already registered. ` +
67
- `Each extractor must have a unique ID.`
68
- );
69
- }
70
-
71
- // Validate extractor configuration
72
- if (!extractor.id || typeof extractor.id !== 'string') {
73
- throw new Error(`Extractor must have a valid string ID`);
74
- }
75
-
76
- if (!extractor.elementTypes || extractor.elementTypes.length === 0) {
77
- throw new Error(
78
- `Extractor '${extractor.id}' must specify at least one element type`
79
- );
80
- }
81
-
82
- if (typeof extractor.priority !== 'number') {
83
- throw new Error(`Extractor '${extractor.id}' must have a numeric priority`);
84
- }
85
-
86
- // Register by ID
87
- this.extractorsById.set(extractor.id, extractor as ElementExtractor);
88
-
89
- // Register by type for fast lookup
90
- // Normalize element types to canonical (lowercase) form for version-agnostic lookup
91
- for (const type of extractor.elementTypes) {
92
- // Convert to canonical form - extractors specify QTI 2.x names (e.g., 'choiceInteraction')
93
- // but we store them in canonical form (e.g., 'choiceinteraction') for QTI version independence
94
- const canonicalType = this.qti2xMapper.toCanonical(type);
95
-
96
- let extractors = this.extractorsByType.get(canonicalType);
97
- if (!extractors) {
98
- extractors = [];
99
- this.extractorsByType.set(canonicalType, extractors);
100
- }
101
-
102
- extractors.push(extractor as ElementExtractor);
103
-
104
- // Keep sorted by priority (highest first)
105
- extractors.sort((a, b) => b.priority - a.priority);
106
- }
107
- }
108
-
109
- /**
110
- * Unregister an extractor by ID
111
- *
112
- * @param id - The extractor ID to unregister
113
- * @returns true if extractor was found and removed, false otherwise
114
- */
115
- unregister(id: string): boolean {
116
- const extractor = this.extractorsById.get(id);
117
- if (!extractor) return false;
118
-
119
- // Remove from ID map
120
- this.extractorsById.delete(id);
121
-
122
- // Remove from type maps (using canonical form)
123
- for (const type of extractor.elementTypes) {
124
- const canonicalType = this.qti2xMapper.toCanonical(type);
125
- const extractors = this.extractorsByType.get(canonicalType);
126
- if (extractors) {
127
- const index = extractors.findIndex((e) => e.id === id);
128
- if (index !== -1) {
129
- extractors.splice(index, 1);
130
- }
131
- // Clean up empty arrays
132
- if (extractors.length === 0) {
133
- this.extractorsByType.delete(canonicalType);
134
- }
135
- }
136
- }
137
-
138
- return true;
139
- }
140
-
141
- /**
142
- * Find an extractor that can handle the given element
143
- * Uses type-based indexing and caching for performance
144
- *
145
- * @param element - The element to find an extractor for
146
- * @param context - Extraction context
147
- * @returns The matching extractor, or null if none found
148
- */
149
- findExtractor(
150
- element: QTIElement,
151
- context: ExtractionContext
152
- ): ElementExtractor | null {
153
- // Check cache first (O(1) lookup)
154
- const cached = this.extractorCache.get(element);
155
- if (cached) return cached;
156
-
157
- // Get element type - normalize using mapper for QTI version handling
158
- // Extractors are registered in canonical (lowercase) form for version independence.
159
- // Convert any QTI version element name to canonical form for lookup.
160
- //
161
- // Example for QTI 3.0:
162
- // 'qti-choice-interaction' → 'choiceinteraction' (canonical)
163
- // Example for QTI 2.x:
164
- // 'choiceInteraction' → 'choiceinteraction' (canonical)
165
- let lookupKey = element.rawTagName || '';
166
- const originalKey = lookupKey;
167
-
168
- if (lookupKey && this.elementNameMapper) {
169
- // Convert element's raw tag to canonical form using the document's mapper
170
- lookupKey = this.elementNameMapper.toCanonical(lookupKey);
171
- }
172
-
173
- // Get extractors for this element type (O(1) map lookup)
174
- const extractors = this.extractorsByType.get(lookupKey);
175
- if (!extractors || extractors.length === 0) {
176
- return null;
177
- }
178
-
179
- // Evaluate canHandle in priority order (O(M) where M = extractors for this type)
180
- for (const extractor of extractors) {
181
- try {
182
- const canHandle = extractor.canHandle(element, context);
183
- const typeMatchedThroughMapper = !!this.elementNameMapper && extractor.elementTypes.some(
184
- (type) => this.qti2xMapper.toCanonical(type) === lookupKey
185
- );
186
- if (canHandle || typeMatchedThroughMapper) {
187
- // Cache the result
188
- this.extractorCache.set(element, extractor);
189
- return extractor;
190
- }
191
- } catch (error) {
192
- // Log but continue to next extractor
193
- console.warn(
194
- `canHandle() failed for extractor '${extractor.id}' (${extractor.name}):`,
195
- error
196
- );
197
- }
198
- }
199
-
200
- return null;
201
- }
202
-
203
- /**
204
- * Extract data from an element using the appropriate extractor
205
- *
206
- * @param element - The element to extract data from
207
- * @param context - Extraction context
208
- * @returns Extraction result with data or error
209
- *
210
- * @example
211
- * const result = registry.extract<ChoiceData>(element, context);
212
- * if (result.success) {
213
- * console.log('Extracted:', result.data);
214
- * if (result.warnings) console.warn('Warnings:', result.warnings);
215
- * } else {
216
- * console.error('Extraction failed:', result.error.message);
217
- * }
218
- */
219
- extract<TData>(
220
- element: QTIElement,
221
- context: ExtractionContext
222
- ): ExtractionResult<TData> {
223
- // Find appropriate extractor
224
- const extractor = this.findExtractor(element, context);
225
-
226
- if (!extractor) {
227
- const elementType = element.rawTagName || 'unknown';
228
- const error = new ExtractionError(
229
- `No extractor available for element '${elementType}'. ` +
230
- `Registered types: ${Array.from(this.extractorsByType.keys()).join(', ')}`,
231
- 'none',
232
- elementType
233
- );
234
- return { success: false, error };
235
- }
236
-
237
- try {
238
- // Extract data
239
- const data = extractor.extract(element, context) as TData;
240
-
241
- // Validate if validator provided
242
- if (extractor.validate) {
243
- const validation = extractor.validate(data);
244
- if (!validation.valid) {
245
- const error = new ExtractionError(
246
- `Validation failed for extractor '${extractor.id}': ${validation.errors?.join(', ')}`,
247
- extractor.id,
248
- element.rawTagName || 'unknown'
249
- );
250
- return { success: false, error };
251
- }
252
-
253
- // Return with warnings if present
254
- if (validation.warnings && validation.warnings.length > 0) {
255
- return { success: true, data, warnings: validation.warnings };
256
- }
257
- }
258
-
259
- return { success: true, data };
260
- } catch (error) {
261
- const elementType = element.rawTagName || 'unknown';
262
- const extractionError =
263
- error instanceof ExtractionError
264
- ? error
265
- : new ExtractionError(
266
- `Extraction failed for '${elementType}': ${error instanceof Error ? error.message : String(error)}`,
267
- extractor.id,
268
- elementType,
269
- error instanceof Error ? error : undefined
270
- );
271
-
272
- return { success: false, error: extractionError };
273
- }
274
- }
275
-
276
- /**
277
- * Get all registered extractors
278
- * @returns Read-only array of extractors sorted by priority (highest first)
279
- */
280
- getExtractors(): ReadonlyArray<ElementExtractor> {
281
- const all = Array.from(this.extractorsById.values());
282
- all.sort((a, b) => b.priority - a.priority);
283
- return all;
284
- }
285
-
286
- /**
287
- * Get extractors for a specific element type
288
- * @param elementType - The element type (e.g., 'choiceInteraction')
289
- * @returns Read-only array of extractors for this type, sorted by priority
290
- */
291
- getExtractorsForType(elementType: string): ReadonlyArray<ElementExtractor> {
292
- // Convert to canonical form for lookup
293
- const canonicalType = this.qti2xMapper.toCanonical(elementType);
294
- return this.extractorsByType.get(canonicalType) || [];
295
- }
296
-
297
- /**
298
- * Check if an extractor is registered by ID
299
- * @param id - The extractor ID
300
- * @returns true if extractor exists
301
- */
302
- hasExtractor(id: string): boolean {
303
- return this.extractorsById.has(id);
304
- }
305
-
306
- /**
307
- * Clear all registered extractors
308
- * Useful for testing or resetting the registry
309
- */
310
- clear(): void {
311
- this.extractorsById.clear();
312
- this.extractorsByType.clear();
313
- }
314
-
315
- /**
316
- * Clone this registry with all extractors
317
- * @returns New registry with same extractors
318
- */
319
- clone(): ExtractionRegistry {
320
- const cloned = new ExtractionRegistry(this.elementNameMapper);
321
- for (const extractor of this.extractorsById.values()) {
322
- cloned.register(extractor);
323
- }
324
- return cloned;
325
- }
326
- }
327
-
328
- /**
329
- * Create a new extraction registry
330
- * @param elementNameMapper - Optional element name mapper for QTI version handling
331
- * @returns Empty registry ready for extractor registration
332
- */
333
- export function createExtractionRegistry(elementNameMapper?: ElementNameMapper): ExtractionRegistry {
334
- return new ExtractionRegistry(elementNameMapper);
335
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * Context factory for element extraction
3
- *
4
- * Creates ExtractionContext instances with utilities and metadata
5
- */
6
-
7
- import type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';
8
- import type { PlayerConfig } from '../types/index.js';
9
- import type { QTIElement } from '../types/interactions.js';
10
- import type { ExtractionContext, VariableDeclaration } from './types.js';
11
- import { createExtractionUtils } from './utils.js';
12
-
13
- /**
14
- * Create an extraction context for an element
15
- *
16
- * @param element - The element being extracted
17
- * @param responseId - Response identifier for this interaction
18
- * @param dom - Root DOM element for document-wide queries
19
- * @param declarations - Variable declarations from QTI
20
- * @param config - Player configuration
21
- * @returns Complete extraction context with utilities
22
- *
23
- * @example
24
- * const context = createExtractionContext(
25
- * element,
26
- * 'RESPONSE',
27
- * rootElement,
28
- * declarations,
29
- * playerConfig
30
- * );
31
- * const result = registry.extract<ChoiceData>(element, context);
32
- */
33
- export function createExtractionContext(
34
- element: QTIElement,
35
- responseId: string,
36
- dom: QTIElement,
37
- declarations: Map<string, VariableDeclaration>,
38
- config: PlayerConfig
39
- ): ExtractionContext {
40
- // Pass both element and attribute name mappers for QTI version handling
41
- const elementMapper = config.elementNameMapper as ElementNameMapper | undefined;
42
- const attributeMapper = config.attributeNameMapper as AttributeNameMapper | undefined;
43
-
44
- return {
45
- element,
46
- responseId,
47
- dom,
48
- declarations,
49
- utils: createExtractionUtils(config.security, elementMapper, attributeMapper),
50
- config,
51
- };
52
- }
@@ -1 +0,0 @@
1
- export * from '../../interactions/associate/extractor.js';
@@ -1 +0,0 @@
1
- export * from '../../interactions/choice/extractor.js';
@@ -1,239 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { Player } from '../../core/Player.js';
3
-
4
- const qti3Item = (identifier: string, body: string, declarations = '') => `<?xml version="1.0" encoding="UTF-8"?>
5
- <qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
6
- identifier="${identifier}" title="${identifier}" adaptive="false" time-dependent="false">
7
- ${declarations}
8
- <qti-item-body>${body}</qti-item-body>
9
- </qti-assessment-item>`;
10
-
11
- describe('QTI 3.0 Advanced clean-room item extraction', () => {
12
- it('Q6: extracts gap match selection messages and gap choices', () => {
13
- const xml = qti3Item(
14
- 'qti3-gap-match',
15
- `<qti-gap-match-interaction response-identifier="RESPONSE"
16
- class="qti-choices-top"
17
- data-max-selections-message="You have used all labels."
18
- data-min-selections-message="Use at least one label.">
19
- <qti-prompt>Complete the sentence.</qti-prompt>
20
- <qti-gap-text identifier="producer" match-max="1">producer</qti-gap-text>
21
- <qti-gap-text identifier="consumer" match-max="1">consumer</qti-gap-text>
22
- <p>A plant is a <qti-gap identifier="gap_1"/>.</p>
23
- </qti-gap-match-interaction>`,
24
- '<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
25
- );
26
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
27
-
28
- expect(interaction.type).toBe('gapMatchInteraction');
29
- expect(interaction.interactionClasses).toContain('qti-choices-top');
30
- expect(interaction.maxSelectionsMessage).toBe('You have used all labels.');
31
- expect(interaction.minSelectionsMessage).toBe('Use at least one label.');
32
- expect(interaction.gaps).toHaveLength(1);
33
- });
34
-
35
- it('Q8: extracts graphic gap match choices and hotspots', () => {
36
- const xml = qti3Item(
37
- 'qti3-graphic-gap',
38
- `<qti-graphic-gap-match-interaction response-identifier="RESPONSE">
39
- <qti-object data="images/food-web.svg" type="image/svg+xml" width="500" height="300">Food web</qti-object>
40
- <qti-gap-text identifier="grass" match-max="1">Grass</qti-gap-text>
41
- <qti-gap-img identifier="hawk" match-max="1" src="images/hawk.svg"/>
42
- <qti-associable-hotspot identifier="A" match-max="1" shape="rect" coords="20,20,120,80"/>
43
- <qti-associable-hotspot identifier="B" match-max="1" shape="circle" coords="350,140,32"/>
44
- </qti-graphic-gap-match-interaction>`,
45
- '<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
46
- );
47
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
48
-
49
- expect(interaction.type).toBe('graphicGapMatchInteraction');
50
- expect(interaction.imageData.src).toBe('images/food-web.svg');
51
- expect(interaction.gapTexts).toHaveLength(1);
52
- expect(interaction.gapImages).toHaveLength(1);
53
- expect(interaction.hotspots).toHaveLength(2);
54
- });
55
-
56
- it('Q10: extracts hotspot shapes from QTI 3.0 element names', () => {
57
- const xml = qti3Item(
58
- 'qti3-hotspot',
59
- `<qti-hotspot-interaction response-identifier="RESPONSE" max-choices="1">
60
- <qti-object data="images/water-cycle.svg" type="image/svg+xml" width="400" height="300">Water cycle</qti-object>
61
- <qti-hotspot-choice identifier="evaporation" shape="circle" coords="100,200,35"/>
62
- <qti-hotspot-choice identifier="condensation" shape="poly" coords="210,60,260,70,250,120,205,115"/>
63
- </qti-hotspot-interaction>`,
64
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
65
- );
66
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
67
-
68
- expect(interaction.type).toBe('hotspotInteraction');
69
- expect(interaction.maxChoices).toBe(1);
70
- expect(interaction.hotspotChoices.map((h: any) => h.shape)).toEqual(['circle', 'poly']);
71
- });
72
-
73
- it('Q11: extracts hottext choices from QTI 3.0 markup', () => {
74
- const xml = qti3Item(
75
- 'qti3-hottext',
76
- `<qti-hottext-interaction response-identifier="RESPONSE" max-choices="1">
77
- <qti-prompt>Select the adjective.</qti-prompt>
78
- <p>The <qti-hottext identifier="word_1">bright</qti-hottext> star <qti-hottext identifier="word_2">shines</qti-hottext>.</p>
79
- </qti-hottext-interaction>`,
80
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
81
- );
82
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
83
-
84
- expect(interaction.type).toBe('hottextInteraction');
85
- expect(interaction.hottextChoices.map((h: any) => h.identifier)).toEqual(['word_1', 'word_2']);
86
- });
87
-
88
- it('Q12: extracts inline choices with MathML content', () => {
89
- const xml = qti3Item(
90
- 'qti3-inline-choice',
91
- `<p>The value of
92
- <math xmlns="http://www.w3.org/1998/Math/MathML"><mn>2</mn><mo>+</mo><mn>3</mn></math>
93
- is <qti-inline-choice-interaction response-identifier="RESPONSE">
94
- <qti-inline-choice identifier="five">5</qti-inline-choice>
95
- <qti-inline-choice identifier="six">6</qti-inline-choice>
96
- </qti-inline-choice-interaction>.
97
- </p>`,
98
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
99
- );
100
- const player = new Player({ itemXml: xml });
101
- const interaction = player.getInteractionData()[0] as any;
102
-
103
- expect(interaction.type).toBe('inlineChoiceInteraction');
104
- expect(interaction.choices).toHaveLength(2);
105
- expect(player.getItemBodyHtml()).toContain('<math');
106
- });
107
-
108
- it('Q13: extracts tabular match shared vocabulary classes', () => {
109
- const xml = qti3Item(
110
- 'qti3-match',
111
- `<qti-match-interaction response-identifier="RESPONSE" max-associations="2"
112
- class="qti-match-tabular qti-header-hidden">
113
- <qti-simple-match-set>
114
- <qti-simple-associable-choice identifier="herbivore" match-max="1">Herbivore</qti-simple-associable-choice>
115
- <qti-simple-associable-choice identifier="carnivore" match-max="1">Carnivore</qti-simple-associable-choice>
116
- </qti-simple-match-set>
117
- <qti-simple-match-set>
118
- <qti-simple-associable-choice identifier="eats_plants" match-max="1">Eats plants</qti-simple-associable-choice>
119
- <qti-simple-associable-choice identifier="eats_animals" match-max="1">Eats animals</qti-simple-associable-choice>
120
- </qti-simple-match-set>
121
- </qti-match-interaction>`,
122
- '<qti-response-declaration identifier="RESPONSE" cardinality="multiple" base-type="directedPair"/>'
123
- );
124
- const interaction = new Player({ itemXml: xml }).getInteractionData()[0] as any;
125
-
126
- expect(interaction.type).toBe('matchInteraction');
127
- expect(interaction.interactionClasses).toContain('qti-match-tabular');
128
- expect(interaction.interactionClasses).toContain('qti-header-hidden');
129
- });
130
-
131
- it('I17: extracts composite QTI 3.0 items with multiple interactions', () => {
132
- const xml = qti3Item(
133
- 'qti3-composite',
134
- `<qti-choice-interaction response-identifier="CHOICE" max-choices="1">
135
- <qti-simple-choice identifier="A">A</qti-simple-choice>
136
- <qti-simple-choice identifier="B">B</qti-simple-choice>
137
- </qti-choice-interaction>
138
- <p>Short answer: <qti-text-entry-interaction response-identifier="TEXT" expected-length="12"/></p>
139
- <qti-extended-text-interaction response-identifier="ESSAY" expected-lines="4"/>`,
140
- `<qti-response-declaration identifier="CHOICE" cardinality="single" base-type="identifier"/>
141
- <qti-response-declaration identifier="TEXT" cardinality="single" base-type="string"/>
142
- <qti-response-declaration identifier="ESSAY" cardinality="single" base-type="string"/>`
143
- );
144
- const types = new Player({ itemXml: xml }).getInteractionData().map((i) => i.type).sort();
145
-
146
- expect(types).toEqual(['choiceInteraction', 'extendedTextInteraction', 'textEntryInteraction']);
147
- });
148
- });
149
-
150
- describe('QTI 3.0 Advanced clean-room content preservation', () => {
151
- it('I4: preserves shared stimulus references for package-level stimulus loading', () => {
152
- const xml = qti3Item(
153
- 'qti3-shared-stimulus',
154
- `<qti-assessment-stimulus-ref identifier="stimulus_1" href="../stimuli/river-study.xml" data-stimulus-idref="stimulus_1"/>
155
- <p data-stimulus-idref="stimulus_1"></p>
156
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
157
- <qti-simple-choice identifier="A">Erosion</qti-simple-choice>
158
- <qti-simple-choice identifier="B">Condensation</qti-simple-choice>
159
- </qti-choice-interaction>`,
160
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
161
- );
162
- const html = new Player({ itemXml: xml }).getItemBodyHtml();
163
-
164
- expect(html).toContain('qti-assessment-stimulus-ref');
165
- expect(html).toContain('data-stimulus-idref="stimulus_1"');
166
- expect(html).toContain('../stimuli/river-study.xml');
167
- });
168
-
169
- it('I19b/I20: preserves full Shared Vocabulary classes in item body HTML', () => {
170
- const xml = qti3Item(
171
- 'qti3-shared-vocabulary',
172
- `<div class="qti-align-center qti-fullwidth">
173
- <p class="qti-underline qti-italic">Observe the emphasized vocabulary.</p>
174
- </div>
175
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
176
- <qti-simple-choice identifier="A">Kept</qti-simple-choice>
177
- </qti-choice-interaction>`,
178
- '<qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>'
179
- );
180
- const html = new Player({ itemXml: xml }).getItemBodyHtml();
181
-
182
- expect(html).toContain('qti-underline');
183
- expect(html).toContain('qti-italic');
184
- expect(html).toContain('qti-align-center');
185
- expect(html).toContain('qti-fullwidth');
186
- });
187
-
188
- it('P7: tolerates QTI metadata while delivering item content', () => {
189
- const xml = `<?xml version="1.0" encoding="UTF-8"?>
190
- <qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
191
- xmlns:lom="http://ltsc.ieee.org/xsd/LOM"
192
- identifier="qti3-metadata" title="Metadata Item" adaptive="false" time-dependent="false">
193
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
194
- <lom:lom><lom:general><lom:title><lom:string>Clean-room metadata</lom:string></lom:title></lom:general></lom:lom>
195
- <qti-item-body>
196
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
197
- <qti-simple-choice identifier="A">Metadata is not candidate-visible.</qti-simple-choice>
198
- </qti-choice-interaction>
199
- </qti-item-body>
200
- </qti-assessment-item>`;
201
- const player = new Player({ itemXml: xml });
202
-
203
- expect(player.getInteractionData()).toHaveLength(1);
204
- expect(player.getItemBodyHtml()).toContain('Metadata is not candidate-visible');
205
- });
206
-
207
- it('A13/A15: preserves caption tracks and glossary catalog references', () => {
208
- const xml = `<?xml version="1.0" encoding="UTF-8"?>
209
- <qti-assessment-item xmlns="http://www.imsglobal.org/xsd/imsqtiasi_v3p0"
210
- identifier="qti3-captions-glossary" title="Captions and Glossary" adaptive="false" time-dependent="false">
211
- <qti-response-declaration identifier="RESPONSE" cardinality="single" base-type="identifier"/>
212
- <qti-catalog-info>
213
- <qti-card identifier="word-delta">
214
- <qti-card-entry usage="glossary-on-screen">
215
- <qti-html-content>A landform where a river divides before entering a larger body of water.</qti-html-content>
216
- </qti-card-entry>
217
- </qti-card>
218
- </qti-catalog-info>
219
- <qti-item-body>
220
- <video controls="controls" width="320">
221
- <source src="media/river-delta.mp4" type="video/mp4"/>
222
- <track kind="captions" srclang="en" src="media/river-delta-captions.vtt" label="English captions"/>
223
- </video>
224
- <p>The <span data-catalog-idref="word-delta">delta</span> changes over time.</p>
225
- <qti-choice-interaction response-identifier="RESPONSE" max-choices="1">
226
- <qti-simple-choice identifier="A">True</qti-simple-choice>
227
- </qti-choice-interaction>
228
- </qti-item-body>
229
- </qti-assessment-item>`;
230
- const player = new Player({ itemXml: xml });
231
- const html = player.getItemBodyHtml();
232
-
233
- expect(html).toContain('<video');
234
- expect(html).toContain('<track');
235
- expect(html).toContain('kind="captions"');
236
- expect(html).toContain('data-catalog-idref="word-delta"');
237
- expect(player.getCatalogEntry('word-delta', 'glossary-on-screen')).toContain('river divides');
238
- });
239
- });