@pie-qti/item-player 0.1.14 → 0.1.16
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 +18 -6
- package/dist/components/utils/feedbackUtils.js +19 -8
- package/dist/components/utils/feedbackUtils.js.map +1 -1
- package/dist/core/ComponentRegistry.js +1 -0
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/Player.d.ts +4 -0
- package/dist/core/Player.js +296 -89
- package/dist/core/Player.js.map +1 -1
- package/dist/core/declarations.js +11 -4
- package/dist/core/declarations.js.map +1 -1
- package/dist/core/sanitizer.js +119 -1
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/shuffle.d.ts +42 -0
- package/dist/core/shuffle.js +83 -0
- package/dist/core/shuffle.js.map +1 -0
- package/dist/core/urlPolicy.js +34 -23
- package/dist/core/urlPolicy.js.map +1 -1
- package/dist/element-class-hT-bDysz.js +6808 -0
- package/dist/element-class-hT-bDysz.js.map +1 -0
- package/dist/element-class.d.ts +73 -0
- package/dist/element-class.js +2 -0
- package/dist/element.d.ts +6 -40
- package/dist/element.js +4 -6296
- package/dist/element.js.map +1 -1
- package/dist/extraction/ExtractionRegistry.js +1 -1
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +1 -1
- package/dist/extraction/createContext.js +5 -1
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +6 -1
- package/dist/extraction/interactionExtractionPipeline.js +6 -3
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/types.d.ts +10 -0
- package/dist/extraction/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.js +2 -1
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +2 -1
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/custom/extractor.js +22 -2
- package/dist/interactions/custom/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -0
- package/dist/interactions/extended-text/extractor.js +40 -6
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/index.d.ts +1 -0
- package/dist/interactions/extended-text/index.js +1 -0
- package/dist/interactions/extended-text/index.js.map +1 -1
- package/dist/interactions/extended-text/response.d.ts +31 -0
- package/dist/interactions/extended-text/response.js +193 -0
- package/dist/interactions/extended-text/response.js.map +1 -0
- package/dist/interactions/gap-match/extractor.js +8 -7
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.js +2 -1
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.js +3 -2
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/modules.d.ts +4 -0
- package/dist/interactions/modules.js +2 -0
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.js +2 -1
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.d.ts +3 -2
- package/dist/interactions/portable-custom/extractor.js +66 -25
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/index.d.ts +1 -1
- package/dist/interactions/portable-custom/index.js.map +1 -1
- package/dist/interactions/portable-custom/types.d.ts +1 -1
- package/dist/interactions/portable-custom/types.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +5 -35
- package/dist/interactions/position-object/extractor.js +58 -153
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +15 -1
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/pci/PciHost.d.ts +14 -9
- package/dist/pci/PciHost.js +89 -22
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +3 -0
- package/dist/pci/index.js +3 -0
- package/dist/pci/index.js.map +1 -0
- package/dist/pci/types.d.ts +72 -0
- package/dist/pci/types.js +12 -0
- package/dist/pci/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +2 -0
- package/dist/presentation/itemPresentationPlan.js +6 -0
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/types/index.d.ts +26 -5
- package/dist/types/index.js.map +1 -1
- package/package.json +15 -7
|
@@ -139,7 +139,7 @@ export class ExtractionRegistry {
|
|
|
139
139
|
for (const extractor of extractors) {
|
|
140
140
|
try {
|
|
141
141
|
const canHandle = extractor.canHandle(element, context);
|
|
142
|
-
const typeMatchedThroughMapper = !!this.elementNameMapper && extractor.elementTypes.some((type) => this.qti2xMapper.toCanonical(type) === lookupKey);
|
|
142
|
+
const typeMatchedThroughMapper = extractors.length === 1 && !!this.elementNameMapper && extractor.elementTypes.some((type) => this.qti2xMapper.toCanonical(type) === lookupKey);
|
|
143
143
|
if (canHandle || typeMatchedThroughMapper) {
|
|
144
144
|
// Cache the result
|
|
145
145
|
this.extractorCache.set(element, extractor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtractionRegistry.js","sourceRoot":"","sources":["../../src/extraction/ExtractionRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,sBAAsB,EAA0B,MAAM,qBAAqB,CAAC;AAQrF,OAAO,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAgB9B,YAAY,iBAAqC;QAfjD,sCAAsC;QAC9B,mBAAc,GAAG,IAAI,GAAG,EAA4B,CAAC;QAE7D,yDAAyD;QACjD,qBAAgB,GAAG,IAAI,GAAG,EAA8B,CAAC;QAEjE,wEAAwE;QAChE,mBAAc,GAAG,IAAI,OAAO,EAAgC,CAAC;QAKrE,+EAA+E;QACvE,gBAAW,GAAG,IAAI,sBAAsB,EAAE,CAAC;QAGlD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,CAAC;IAED;;;;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,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,CAAC;IACZ,CAAC;IAED;;;;OAIG;IACH,oBAAoB,CAAC,WAAmB;QACvC,uCAAuC;QACvC,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,EAAU;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,KAAK;QACJ,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK;QACJ,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC9D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YACtD,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,iBAAqC;IAC7E,OAAO,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * ExtractionRegistry for priority-based element extraction\n *\n * Manages a collection of ElementExtractor instances with:\n * - Priority-based dispatch (highest priority checked first)\n * - Type-based indexing for O(M) lookup instead of O(N) scanning\n * - WeakMap caching for O(1) repeat lookups\n * - Validation and error handling\n */\n\nimport { Qti2xElementNameMapper, type ElementNameMapper } from '@pie-qti/qti-common';\nimport type { QTIElement } from '../interactions/index.js';\nimport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionResult,\n\tValidationResult,\n} from './types.js';\nimport { ExtractionError, isSuccessResult } from './types.js';\n\n/**\n * Registry for element extractors with priority-based dispatch\n */\nexport class ExtractionRegistry {\n\t/** All registered extractors by ID */\n\tprivate extractorsById = new Map<string, ElementExtractor>();\n\n\t/** Extractors indexed by element type for fast lookup */\n\tprivate extractorsByType = new Map<string, ElementExtractor[]>();\n\n\t/** Cache for element -> extractor lookups (WeakMap for automatic GC) */\n\tprivate extractorCache = new WeakMap<QTIElement, ElementExtractor>();\n\n\t/** Optional element name mapper for QTI version handling */\n\tprivate elementNameMapper?: ElementNameMapper;\n\n\t/** QTI 2.x mapper for converting canonical names to extractor registry keys */\n\tprivate qti2xMapper = new Qti2xElementNameMapper();\n\n\tconstructor(elementNameMapper?: ElementNameMapper) {\n\t\tthis.elementNameMapper = elementNameMapper;\n\t}\n\n\t/**\n\t * Register an extractor with the registry\n\t *\n\t * @param extractor - The extractor to register\n\t * @throws Error if extractor ID is already registered\n\t *\n\t * @example\n\t * registry.register({\n\t * id: 'qti:choice',\n\t * name: 'QTI Standard Choice',\n\t * priority: 10,\n\t * elementTypes: ['choiceInteraction'],\n\t * canHandle: (element) => utils.hasChildWithTag(element, 'simpleChoice'),\n\t * extract: (element, context) => ({ choices: [...] })\n\t * });\n\t */\n\tregister<TData, TContext extends ExtractionContext = ExtractionContext>(\n\t\textractor: ElementExtractor<TData, TContext>\n\t): void {\n\t\t// Check for duplicate ID\n\t\tif (this.extractorsById.has(extractor.id)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Extractor with ID '${extractor.id}' is already registered. ` +\n\t\t\t\t\t`Each extractor must have a unique ID.`\n\t\t\t);\n\t\t}\n\n\t\t// Validate extractor configuration\n\t\tif (!extractor.id || typeof extractor.id !== 'string') {\n\t\t\tthrow new Error(`Extractor must have a valid string ID`);\n\t\t}\n\n\t\tif (!extractor.elementTypes || extractor.elementTypes.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Extractor '${extractor.id}' must specify at least one element type`\n\t\t\t);\n\t\t}\n\n\t\tif (typeof extractor.priority !== 'number') {\n\t\t\tthrow new Error(`Extractor '${extractor.id}' must have a numeric priority`);\n\t\t}\n\n\t\t// Register by ID\n\t\tthis.extractorsById.set(extractor.id, extractor as ElementExtractor);\n\n\t\t// Register by type for fast lookup\n\t\t// Normalize element types to canonical (lowercase) form for version-agnostic lookup\n\t\tfor (const type of extractor.elementTypes) {\n\t\t\t// Convert to canonical form - extractors specify QTI 2.x names (e.g., 'choiceInteraction')\n\t\t\t// but we store them in canonical form (e.g., 'choiceinteraction') for QTI version independence\n\t\t\tconst canonicalType = this.qti2xMapper.toCanonical(type);\n\n\t\t\tlet extractors = this.extractorsByType.get(canonicalType);\n\t\t\tif (!extractors) {\n\t\t\t\textractors = [];\n\t\t\t\tthis.extractorsByType.set(canonicalType, extractors);\n\t\t\t}\n\n\t\t\textractors.push(extractor as ElementExtractor);\n\n\t\t\t// Keep sorted by priority (highest first)\n\t\t\textractors.sort((a, b) => b.priority - a.priority);\n\t\t}\n\t}\n\n\t/**\n\t * Unregister an extractor by ID\n\t *\n\t * @param id - The extractor ID to unregister\n\t * @returns true if extractor was found and removed, false otherwise\n\t */\n\tunregister(id: string): boolean {\n\t\tconst extractor = this.extractorsById.get(id);\n\t\tif (!extractor) return false;\n\n\t\t// Remove from ID map\n\t\tthis.extractorsById.delete(id);\n\n\t\t// Remove from type maps (using canonical form)\n\t\tfor (const type of extractor.elementTypes) {\n\t\t\tconst canonicalType = this.qti2xMapper.toCanonical(type);\n\t\t\tconst extractors = this.extractorsByType.get(canonicalType);\n\t\t\tif (extractors) {\n\t\t\t\tconst index = extractors.findIndex((e) => e.id === id);\n\t\t\t\tif (index !== -1) {\n\t\t\t\t\textractors.splice(index, 1);\n\t\t\t\t}\n\t\t\t\t// Clean up empty arrays\n\t\t\t\tif (extractors.length === 0) {\n\t\t\t\t\tthis.extractorsByType.delete(canonicalType);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Find an extractor that can handle the given element\n\t * Uses type-based indexing and caching for performance\n\t *\n\t * @param element - The element to find an extractor for\n\t * @param context - Extraction context\n\t * @returns The matching extractor, or null if none found\n\t */\n\tfindExtractor(\n\t\telement: QTIElement,\n\t\tcontext: ExtractionContext\n\t): ElementExtractor | null {\n\t\t// Check cache first (O(1) lookup)\n\t\tconst cached = this.extractorCache.get(element);\n\t\tif (cached) return cached;\n\n\t\t// Get element type - normalize using mapper for QTI version handling\n\t\t// Extractors are registered in canonical (lowercase) form for version independence.\n\t\t// Convert any QTI version element name to canonical form for lookup.\n\t\t//\n\t\t// Example for QTI 3.0:\n\t\t// 'qti-choice-interaction' → 'choiceinteraction' (canonical)\n\t\t// Example for QTI 2.x:\n\t\t// 'choiceInteraction' → 'choiceinteraction' (canonical)\n\t\tlet lookupKey = element.rawTagName || '';\n\t\tconst originalKey = lookupKey;\n\n\t\tif (lookupKey && this.elementNameMapper) {\n\t\t\t// Convert element's raw tag to canonical form using the document's mapper\n\t\t\tlookupKey = this.elementNameMapper.toCanonical(lookupKey);\n\t\t}\n\n\t\t// Get extractors for this element type (O(1) map lookup)\n\t\tconst extractors = this.extractorsByType.get(lookupKey);\n\t\tif (!extractors || extractors.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Evaluate canHandle in priority order (O(M) where M = extractors for this type)\n\t\tfor (const extractor of extractors) {\n\t\t\ttry {\n\t\t\t\tconst canHandle = extractor.canHandle(element, context);\n\t\t\t\tconst typeMatchedThroughMapper = !!this.elementNameMapper && extractor.elementTypes.some(\n\t\t\t\t\t(type) => this.qti2xMapper.toCanonical(type) === lookupKey\n\t\t\t\t);\n\t\t\t\tif (canHandle || typeMatchedThroughMapper) {\n\t\t\t\t\t// Cache the result\n\t\t\t\t\tthis.extractorCache.set(element, extractor);\n\t\t\t\t\treturn extractor;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next extractor\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for extractor '${extractor.id}' (${extractor.name}):`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t/**\n\t * Extract data from an element using the appropriate extractor\n\t *\n\t * @param element - The element to extract data from\n\t * @param context - Extraction context\n\t * @returns Extraction result with data or error\n\t *\n\t * @example\n\t * const result = registry.extract<ChoiceData>(element, context);\n\t * if (result.success) {\n\t * console.log('Extracted:', result.data);\n\t * if (result.warnings) console.warn('Warnings:', result.warnings);\n\t * } else {\n\t * console.error('Extraction failed:', result.error.message);\n\t * }\n\t */\n\textract<TData>(\n\t\telement: QTIElement,\n\t\tcontext: ExtractionContext\n\t): ExtractionResult<TData> {\n\t\t// Find appropriate extractor\n\t\tconst extractor = this.findExtractor(element, context);\n\n\t\tif (!extractor) {\n\t\t\tconst elementType = element.rawTagName || 'unknown';\n\t\t\tconst error = new ExtractionError(\n\t\t\t\t`No extractor available for element '${elementType}'. ` +\n\t\t\t\t\t`Registered types: ${Array.from(this.extractorsByType.keys()).join(', ')}`,\n\t\t\t\t'none',\n\t\t\t\telementType\n\t\t\t);\n\t\t\treturn { success: false, error };\n\t\t}\n\n\t\ttry {\n\t\t\t// Extract data\n\t\t\tconst data = extractor.extract(element, context) as TData;\n\n\t\t\t// Validate if validator provided\n\t\t\tif (extractor.validate) {\n\t\t\t\tconst validation = extractor.validate(data);\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst error = new ExtractionError(\n\t\t\t\t\t\t`Validation failed for extractor '${extractor.id}': ${validation.errors?.join(', ')}`,\n\t\t\t\t\t\textractor.id,\n\t\t\t\t\t\telement.rawTagName || 'unknown'\n\t\t\t\t\t);\n\t\t\t\t\treturn { success: false, error };\n\t\t\t\t}\n\n\t\t\t\t// Return with warnings if present\n\t\t\t\tif (validation.warnings && validation.warnings.length > 0) {\n\t\t\t\t\treturn { success: true, data, warnings: validation.warnings };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { success: true, data };\n\t\t} catch (error) {\n\t\t\tconst elementType = element.rawTagName || 'unknown';\n\t\t\tconst extractionError =\n\t\t\t\terror instanceof ExtractionError\n\t\t\t\t\t? error\n\t\t\t\t\t: new ExtractionError(\n\t\t\t\t\t\t\t`Extraction failed for '${elementType}': ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\textractor.id,\n\t\t\t\t\t\t\telementType,\n\t\t\t\t\t\t\terror instanceof Error ? error : undefined\n\t\t\t\t\t\t);\n\n\t\t\treturn { success: false, error: extractionError };\n\t\t}\n\t}\n\n\t/**\n\t * Get all registered extractors\n\t * @returns Read-only array of extractors sorted by priority (highest first)\n\t */\n\tgetExtractors(): ReadonlyArray<ElementExtractor> {\n\t\tconst all = Array.from(this.extractorsById.values());\n\t\tall.sort((a, b) => b.priority - a.priority);\n\t\treturn all;\n\t}\n\n\t/**\n\t * Get extractors for a specific element type\n\t * @param elementType - The element type (e.g., 'choiceInteraction')\n\t * @returns Read-only array of extractors for this type, sorted by priority\n\t */\n\tgetExtractorsForType(elementType: string): ReadonlyArray<ElementExtractor> {\n\t\t// Convert to canonical form for lookup\n\t\tconst canonicalType = this.qti2xMapper.toCanonical(elementType);\n\t\treturn this.extractorsByType.get(canonicalType) || [];\n\t}\n\n\t/**\n\t * Check if an extractor is registered by ID\n\t * @param id - The extractor ID\n\t * @returns true if extractor exists\n\t */\n\thasExtractor(id: string): boolean {\n\t\treturn this.extractorsById.has(id);\n\t}\n\n\t/**\n\t * Clear all registered extractors\n\t * Useful for testing or resetting the registry\n\t */\n\tclear(): void {\n\t\tthis.extractorsById.clear();\n\t\tthis.extractorsByType.clear();\n\t}\n\n\t/**\n\t * Clone this registry with all extractors\n\t * @returns New registry with same extractors\n\t */\n\tclone(): ExtractionRegistry {\n\t\tconst cloned = new ExtractionRegistry(this.elementNameMapper);\n\t\tfor (const extractor of this.extractorsById.values()) {\n\t\t\tcloned.register(extractor);\n\t\t}\n\t\treturn cloned;\n\t}\n}\n\n/**\n * Create a new extraction registry\n * @param elementNameMapper - Optional element name mapper for QTI version handling\n * @returns Empty registry ready for extractor registration\n */\nexport function createExtractionRegistry(elementNameMapper?: ElementNameMapper): ExtractionRegistry {\n\treturn new ExtractionRegistry(elementNameMapper);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExtractionRegistry.js","sourceRoot":"","sources":["../../src/extraction/ExtractionRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,sBAAsB,EAA0B,MAAM,qBAAqB,CAAC;AAQrF,OAAO,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAgB9B,YAAY,iBAAqC;QAfjD,sCAAsC;QAC9B,mBAAc,GAAG,IAAI,GAAG,EAA4B,CAAC;QAE7D,yDAAyD;QACjD,qBAAgB,GAAG,IAAI,GAAG,EAA8B,CAAC;QAEjE,wEAAwE;QAChE,mBAAc,GAAG,IAAI,OAAO,EAAgC,CAAC;QAKrE,+EAA+E;QACvE,gBAAW,GAAG,IAAI,sBAAsB,EAAE,CAAC;QAGlD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CACP,SAA4C;QAE5C,yBAAyB;QACzB,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CACd,sBAAsB,SAAS,CAAC,EAAE,2BAA2B;gBAC5D,uCAAuC,CACxC,CAAC;QACH,CAAC;QAED,mCAAmC;QACnC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,OAAO,SAAS,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,YAAY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ACH,KAAK;QACJ,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK;QACJ,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC9D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC;YACtD,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,iBAAqC;IAC7E,OAAO,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * ExtractionRegistry for priority-based element extraction\n *\n * Manages a collection of ElementExtractor instances with:\n * - Priority-based dispatch (highest priority checked first)\n * - Type-based indexing for O(M) lookup instead of O(N) scanning\n * - WeakMap caching for O(1) repeat lookups\n * - Validation and error handling\n */\n\nimport { Qti2xElementNameMapper, type ElementNameMapper } from '@pie-qti/qti-common';\nimport type { QTIElement } from '../interactions/index.js';\nimport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionResult,\n\tValidationResult,\n} from './types.js';\nimport { ExtractionError, isSuccessResult } from './types.js';\n\n/**\n * Registry for element extractors with priority-based dispatch\n */\nexport class ExtractionRegistry {\n\t/** All registered extractors by ID */\n\tprivate extractorsById = new Map<string, ElementExtractor>();\n\n\t/** Extractors indexed by element type for fast lookup */\n\tprivate extractorsByType = new Map<string, ElementExtractor[]>();\n\n\t/** Cache for element -> extractor lookups (WeakMap for automatic GC) */\n\tprivate extractorCache = new WeakMap<QTIElement, ElementExtractor>();\n\n\t/** Optional element name mapper for QTI version handling */\n\tprivate elementNameMapper?: ElementNameMapper;\n\n\t/** QTI 2.x mapper for converting canonical names to extractor registry keys */\n\tprivate qti2xMapper = new Qti2xElementNameMapper();\n\n\tconstructor(elementNameMapper?: ElementNameMapper) {\n\t\tthis.elementNameMapper = elementNameMapper;\n\t}\n\n\t/**\n\t * Register an extractor with the registry\n\t *\n\t * @param extractor - The extractor to register\n\t * @throws Error if extractor ID is already registered\n\t *\n\t * @example\n\t * registry.register({\n\t * id: 'qti:choice',\n\t * name: 'QTI Standard Choice',\n\t * priority: 10,\n\t * elementTypes: ['choiceInteraction'],\n\t * canHandle: (element) => utils.hasChildWithTag(element, 'simpleChoice'),\n\t * extract: (element, context) => ({ choices: [...] })\n\t * });\n\t */\n\tregister<TData, TContext extends ExtractionContext = ExtractionContext>(\n\t\textractor: ElementExtractor<TData, TContext>\n\t): void {\n\t\t// Check for duplicate ID\n\t\tif (this.extractorsById.has(extractor.id)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Extractor with ID '${extractor.id}' is already registered. ` +\n\t\t\t\t\t`Each extractor must have a unique ID.`\n\t\t\t);\n\t\t}\n\n\t\t// Validate extractor configuration\n\t\tif (!extractor.id || typeof extractor.id !== 'string') {\n\t\t\tthrow new Error(`Extractor must have a valid string ID`);\n\t\t}\n\n\t\tif (!extractor.elementTypes || extractor.elementTypes.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Extractor '${extractor.id}' must specify at least one element type`\n\t\t\t);\n\t\t}\n\n\t\tif (typeof extractor.priority !== 'number') {\n\t\t\tthrow new Error(`Extractor '${extractor.id}' must have a numeric priority`);\n\t\t}\n\n\t\t// Register by ID\n\t\tthis.extractorsById.set(extractor.id, extractor as ElementExtractor);\n\n\t\t// Register by type for fast lookup\n\t\t// Normalize element types to canonical (lowercase) form for version-agnostic lookup\n\t\tfor (const type of extractor.elementTypes) {\n\t\t\t// Convert to canonical form - extractors specify QTI 2.x names (e.g., 'choiceInteraction')\n\t\t\t// but we store them in canonical form (e.g., 'choiceinteraction') for QTI version independence\n\t\t\tconst canonicalType = this.qti2xMapper.toCanonical(type);\n\n\t\t\tlet extractors = this.extractorsByType.get(canonicalType);\n\t\t\tif (!extractors) {\n\t\t\t\textractors = [];\n\t\t\t\tthis.extractorsByType.set(canonicalType, extractors);\n\t\t\t}\n\n\t\t\textractors.push(extractor as ElementExtractor);\n\n\t\t\t// Keep sorted by priority (highest first)\n\t\t\textractors.sort((a, b) => b.priority - a.priority);\n\t\t}\n\t}\n\n\t/**\n\t * Unregister an extractor by ID\n\t *\n\t * @param id - The extractor ID to unregister\n\t * @returns true if extractor was found and removed, false otherwise\n\t */\n\tunregister(id: string): boolean {\n\t\tconst extractor = this.extractorsById.get(id);\n\t\tif (!extractor) return false;\n\n\t\t// Remove from ID map\n\t\tthis.extractorsById.delete(id);\n\n\t\t// Remove from type maps (using canonical form)\n\t\tfor (const type of extractor.elementTypes) {\n\t\t\tconst canonicalType = this.qti2xMapper.toCanonical(type);\n\t\t\tconst extractors = this.extractorsByType.get(canonicalType);\n\t\t\tif (extractors) {\n\t\t\t\tconst index = extractors.findIndex((e) => e.id === id);\n\t\t\t\tif (index !== -1) {\n\t\t\t\t\textractors.splice(index, 1);\n\t\t\t\t}\n\t\t\t\t// Clean up empty arrays\n\t\t\t\tif (extractors.length === 0) {\n\t\t\t\t\tthis.extractorsByType.delete(canonicalType);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Find an extractor that can handle the given element\n\t * Uses type-based indexing and caching for performance\n\t *\n\t * @param element - The element to find an extractor for\n\t * @param context - Extraction context\n\t * @returns The matching extractor, or null if none found\n\t */\n\tfindExtractor(\n\t\telement: QTIElement,\n\t\tcontext: ExtractionContext\n\t): ElementExtractor | null {\n\t\t// Check cache first (O(1) lookup)\n\t\tconst cached = this.extractorCache.get(element);\n\t\tif (cached) return cached;\n\n\t\t// Get element type - normalize using mapper for QTI version handling\n\t\t// Extractors are registered in canonical (lowercase) form for version independence.\n\t\t// Convert any QTI version element name to canonical form for lookup.\n\t\t//\n\t\t// Example for QTI 3.0:\n\t\t// 'qti-choice-interaction' → 'choiceinteraction' (canonical)\n\t\t// Example for QTI 2.x:\n\t\t// 'choiceInteraction' → 'choiceinteraction' (canonical)\n\t\tlet lookupKey = element.rawTagName || '';\n\t\tconst originalKey = lookupKey;\n\n\t\tif (lookupKey && this.elementNameMapper) {\n\t\t\t// Convert element's raw tag to canonical form using the document's mapper\n\t\t\tlookupKey = this.elementNameMapper.toCanonical(lookupKey);\n\t\t}\n\n\t\t// Get extractors for this element type (O(1) map lookup)\n\t\tconst extractors = this.extractorsByType.get(lookupKey);\n\t\tif (!extractors || extractors.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Evaluate canHandle in priority order (O(M) where M = extractors for this type)\n\t\tfor (const extractor of extractors) {\n\t\t\ttry {\n\t\t\t\tconst canHandle = extractor.canHandle(element, context);\n\t\t\t\tconst typeMatchedThroughMapper = extractors.length === 1 && !!this.elementNameMapper && extractor.elementTypes.some(\n\t\t\t\t\t(type) => this.qti2xMapper.toCanonical(type) === lookupKey\n\t\t\t\t);\n\t\t\t\tif (canHandle || typeMatchedThroughMapper) {\n\t\t\t\t\t// Cache the result\n\t\t\t\t\tthis.extractorCache.set(element, extractor);\n\t\t\t\t\treturn extractor;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next extractor\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for extractor '${extractor.id}' (${extractor.name}):`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t/**\n\t * Extract data from an element using the appropriate extractor\n\t *\n\t * @param element - The element to extract data from\n\t * @param context - Extraction context\n\t * @returns Extraction result with data or error\n\t *\n\t * @example\n\t * const result = registry.extract<ChoiceData>(element, context);\n\t * if (result.success) {\n\t * console.log('Extracted:', result.data);\n\t * if (result.warnings) console.warn('Warnings:', result.warnings);\n\t * } else {\n\t * console.error('Extraction failed:', result.error.message);\n\t * }\n\t */\n\textract<TData>(\n\t\telement: QTIElement,\n\t\tcontext: ExtractionContext\n\t): ExtractionResult<TData> {\n\t\t// Find appropriate extractor\n\t\tconst extractor = this.findExtractor(element, context);\n\n\t\tif (!extractor) {\n\t\t\tconst elementType = element.rawTagName || 'unknown';\n\t\t\tconst error = new ExtractionError(\n\t\t\t\t`No extractor available for element '${elementType}'. ` +\n\t\t\t\t\t`Registered types: ${Array.from(this.extractorsByType.keys()).join(', ')}`,\n\t\t\t\t'none',\n\t\t\t\telementType\n\t\t\t);\n\t\t\treturn { success: false, error };\n\t\t}\n\n\t\ttry {\n\t\t\t// Extract data\n\t\t\tconst data = extractor.extract(element, context) as TData;\n\n\t\t\t// Validate if validator provided\n\t\t\tif (extractor.validate) {\n\t\t\t\tconst validation = extractor.validate(data);\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst error = new ExtractionError(\n\t\t\t\t\t\t`Validation failed for extractor '${extractor.id}': ${validation.errors?.join(', ')}`,\n\t\t\t\t\t\textractor.id,\n\t\t\t\t\t\telement.rawTagName || 'unknown'\n\t\t\t\t\t);\n\t\t\t\t\treturn { success: false, error };\n\t\t\t\t}\n\n\t\t\t\t// Return with warnings if present\n\t\t\t\tif (validation.warnings && validation.warnings.length > 0) {\n\t\t\t\t\treturn { success: true, data, warnings: validation.warnings };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { success: true, data };\n\t\t} catch (error) {\n\t\t\tconst elementType = element.rawTagName || 'unknown';\n\t\t\tconst extractionError =\n\t\t\t\terror instanceof ExtractionError\n\t\t\t\t\t? error\n\t\t\t\t\t: new ExtractionError(\n\t\t\t\t\t\t\t`Extraction failed for '${elementType}': ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\textractor.id,\n\t\t\t\t\t\t\telementType,\n\t\t\t\t\t\t\terror instanceof Error ? error : undefined\n\t\t\t\t\t\t);\n\n\t\t\treturn { success: false, error: extractionError };\n\t\t}\n\t}\n\n\t/**\n\t * Get all registered extractors\n\t * @returns Read-only array of extractors sorted by priority (highest first)\n\t */\n\tgetExtractors(): ReadonlyArray<ElementExtractor> {\n\t\tconst all = Array.from(this.extractorsById.values());\n\t\tall.sort((a, b) => b.priority - a.priority);\n\t\treturn all;\n\t}\n\n\t/**\n\t * Get extractors for a specific element type\n\t * @param elementType - The element type (e.g., 'choiceInteraction')\n\t * @returns Read-only array of extractors for this type, sorted by priority\n\t */\n\tgetExtractorsForType(elementType: string): ReadonlyArray<ElementExtractor> {\n\t\t// Convert to canonical form for lookup\n\t\tconst canonicalType = this.qti2xMapper.toCanonical(elementType);\n\t\treturn this.extractorsByType.get(canonicalType) || [];\n\t}\n\n\t/**\n\t * Check if an extractor is registered by ID\n\t * @param id - The extractor ID\n\t * @returns true if extractor exists\n\t */\n\thasExtractor(id: string): boolean {\n\t\treturn this.extractorsById.has(id);\n\t}\n\n\t/**\n\t * Clear all registered extractors\n\t * Useful for testing or resetting the registry\n\t */\n\tclear(): void {\n\t\tthis.extractorsById.clear();\n\t\tthis.extractorsByType.clear();\n\t}\n\n\t/**\n\t * Clone this registry with all extractors\n\t * @returns New registry with same extractors\n\t */\n\tclone(): ExtractionRegistry {\n\t\tconst cloned = new ExtractionRegistry(this.elementNameMapper);\n\t\tfor (const extractor of this.extractorsById.values()) {\n\t\t\tcloned.register(extractor);\n\t\t}\n\t\treturn cloned;\n\t}\n}\n\n/**\n * Create a new extraction registry\n * @param elementNameMapper - Optional element name mapper for QTI version handling\n * @returns Empty registry ready for extractor registration\n */\nexport function createExtractionRegistry(elementNameMapper?: ElementNameMapper): ExtractionRegistry {\n\treturn new ExtractionRegistry(elementNameMapper);\n}\n"]}
|
|
@@ -26,4 +26,4 @@ import type { ExtractionContext, VariableDeclaration } from './types.js';
|
|
|
26
26
|
* );
|
|
27
27
|
* const result = registry.extract<ChoiceData>(element, context);
|
|
28
28
|
*/
|
|
29
|
-
export declare function createExtractionContext(element: QTIElement, responseId: string, dom: QTIElement, declarations: Map<string, VariableDeclaration>, config: PlayerConfig): ExtractionContext;
|
|
29
|
+
export declare function createExtractionContext(element: QTIElement, responseId: string, dom: QTIElement, declarations: Map<string, VariableDeclaration>, config: PlayerConfig, sessionGuid?: string): ExtractionContext;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Creates ExtractionContext instances with utilities and metadata
|
|
5
5
|
*/
|
|
6
6
|
import { createExtractionUtils } from './utils.js';
|
|
7
|
+
import { createShuffleRng } from '../core/shuffle.js';
|
|
7
8
|
/**
|
|
8
9
|
* Create an extraction context for an element
|
|
9
10
|
*
|
|
@@ -24,7 +25,7 @@ import { createExtractionUtils } from './utils.js';
|
|
|
24
25
|
* );
|
|
25
26
|
* const result = registry.extract<ChoiceData>(element, context);
|
|
26
27
|
*/
|
|
27
|
-
export function createExtractionContext(element, responseId, dom, declarations, config) {
|
|
28
|
+
export function createExtractionContext(element, responseId, dom, declarations, config, sessionGuid) {
|
|
28
29
|
// Pass both element and attribute name mappers for QTI version handling
|
|
29
30
|
const elementMapper = config.elementNameMapper;
|
|
30
31
|
const attributeMapper = config.attributeNameMapper;
|
|
@@ -35,6 +36,9 @@ export function createExtractionContext(element, responseId, dom, declarations,
|
|
|
35
36
|
declarations,
|
|
36
37
|
utils: createExtractionUtils(config.security, elementMapper, attributeMapper),
|
|
37
38
|
config,
|
|
39
|
+
// Without a session GUID there is nothing stable to seed from, so leave the RNG
|
|
40
|
+
// unset and let extractors keep the authored order.
|
|
41
|
+
...(sessionGuid ? { shuffleRng: createShuffleRng(sessionGuid, responseId) } : {}),
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
44
|
//# sourceMappingURL=createContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../src/extraction/createContext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../src/extraction/createContext.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,uBAAuB,CACtC,OAAmB,EACnB,UAAkB,EAClB,GAAe,EACf,YAA8C,EAC9C,MAAoB,EACpB,WAAoB;IAEpB,wEAAwE;IACxE,MAAM,aAAa,GAAG,MAAM,CAAC,iBAAkD,CAAC;IAChF,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAsD,CAAC;IAEtF,OAAO;QACN,OAAO;QACP,UAAU;QACV,GAAG;QACH,YAAY;QACZ,KAAK,EAAE,qBAAqB,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,eAAe,CAAC;QAC7E,MAAM;QACN,gFAAgF;QAChF,oDAAoD;QACpD,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjF,CAAC;AACH,CAAC","sourcesContent":["/**\n * Context factory for element extraction\n *\n * Creates ExtractionContext instances with utilities and metadata\n */\n\nimport type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';\nimport type { PlayerConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/index.js';\nimport type { ExtractionContext, VariableDeclaration } from './types.js';\nimport { createExtractionUtils } from './utils.js';\nimport { createShuffleRng } from '../core/shuffle.js';\n\n/**\n * Create an extraction context for an element\n *\n * @param element - The element being extracted\n * @param responseId - Response identifier for this interaction\n * @param dom - Root DOM element for document-wide queries\n * @param declarations - Variable declarations from QTI\n * @param config - Player configuration\n * @returns Complete extraction context with utilities\n *\n * @example\n * const context = createExtractionContext(\n * element,\n * 'RESPONSE',\n * rootElement,\n * declarations,\n * playerConfig\n * );\n * const result = registry.extract<ChoiceData>(element, context);\n */\nexport function createExtractionContext(\n\telement: QTIElement,\n\tresponseId: string,\n\tdom: QTIElement,\n\tdeclarations: Map<string, VariableDeclaration>,\n\tconfig: PlayerConfig,\n\tsessionGuid?: string\n): ExtractionContext {\n\t// Pass both element and attribute name mappers for QTI version handling\n\tconst elementMapper = config.elementNameMapper as ElementNameMapper | undefined;\n\tconst attributeMapper = config.attributeNameMapper as AttributeNameMapper | undefined;\n\n\treturn {\n\t\telement,\n\t\tresponseId,\n\t\tdom,\n\t\tdeclarations,\n\t\tutils: createExtractionUtils(config.security, elementMapper, attributeMapper),\n\t\tconfig,\n\t\t// Without a session GUID there is nothing stable to seed from, so leave the RNG\n\t\t// unset and let extractors keep the authored order.\n\t\t...(sessionGuid ? { shuffleRng: createShuffleRng(sessionGuid, responseId) } : {}),\n\t};\n}\n"]}
|
|
@@ -8,5 +8,10 @@ export interface InteractionExtractionPipelineInput {
|
|
|
8
8
|
extractionRegistry: ExtractionRegistry;
|
|
9
9
|
declarations: DeclarationMap;
|
|
10
10
|
config: PlayerConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Item session GUID, used to seed `shuffle` for the interactions that support it.
|
|
13
|
+
* Omit to keep the authored order.
|
|
14
|
+
*/
|
|
15
|
+
sessionGuid?: string;
|
|
11
16
|
}
|
|
12
|
-
export declare function extractInteractionData({ document, extractionRegistry, declarations, config, }: InteractionExtractionPipelineInput): InteractionData[];
|
|
17
|
+
export declare function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, }: InteractionExtractionPipelineInput): InteractionData[];
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { createExtractionContext } from './createContext.js';
|
|
2
2
|
import { applyInteractionSecurity } from './interactionSecurity.js';
|
|
3
|
-
export function extractInteractionData({ document, extractionRegistry, declarations, config, }) {
|
|
3
|
+
export function extractInteractionData({ document, extractionRegistry, declarations, config, sessionGuid, }) {
|
|
4
4
|
const declMap = projectDeclarationsForExtraction(declarations);
|
|
5
5
|
const elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry));
|
|
6
6
|
const interactions = [];
|
|
7
7
|
for (const discovered of elements) {
|
|
8
|
-
const context = createExtractionContext(discovered.element, discovered.responseIdentifier, discovered.contextRoot, declMap, config);
|
|
8
|
+
const context = createExtractionContext(discovered.element, discovered.responseIdentifier, discovered.contextRoot, declMap, config, sessionGuid);
|
|
9
9
|
const result = extractionRegistry.extract(discovered.element, context);
|
|
10
10
|
if (!result.success)
|
|
11
11
|
continue;
|
|
12
12
|
interactions.push({
|
|
13
|
-
|
|
13
|
+
// A QTI 2.x portableCustomInteraction is nested in customInteraction. Its
|
|
14
|
+
// extractor supplies the canonical renderer type so it does not hit the
|
|
15
|
+
// generic unsupported-custom fallback.
|
|
16
|
+
type: (result.data?.type ?? discovered.normalizedType),
|
|
14
17
|
responseId: discovered.responseIdentifier,
|
|
15
18
|
...result.data,
|
|
16
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionExtractionPipeline.js","sourceRoot":"","sources":["../../src/extraction/interactionExtractionPipeline.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"interactionExtractionPipeline.js","sourceRoot":"","sources":["../../src/extraction/interactionExtractionPipeline.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAkBpE,MAAM,UAAU,sBAAsB,CAAC,EACtC,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,WAAW,GACyB;IACpC,MAAM,OAAO,GAAG,gCAAgC,CAAC,YAAY,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,CAAC,yBAAyB,CAAC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CAAC,EAAE,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE;YACnC,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,WAAW,EAAE,WAAW,CAAC,WAAkB;YAC3C,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC9B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';\nimport type { ExtractionRegistry } from './ExtractionRegistry.js';\nimport { createExtractionContext } from './createContext.js';\nimport { applyInteractionSecurity } from './interactionSecurity.js';\nimport type { VariableDeclaration as ExtractionVariableDeclaration } from './types.js';\nimport type { DeclarationMap } from '@pie-qti/qti-processing';\nimport type { PlayerConfig } from '../types/index.js';\nimport type { InteractionData } from '../interactions/index.js';\n\nexport interface InteractionExtractionPipelineInput {\n\tdocument: AssessmentItemDocument;\n\textractionRegistry: ExtractionRegistry;\n\tdeclarations: DeclarationMap;\n\tconfig: PlayerConfig;\n\t/**\n\t * Item session GUID, used to seed `shuffle` for the interactions that support it.\n\t * Omit to keep the authored order.\n\t */\n\tsessionGuid?: string;\n}\n\nexport function extractInteractionData({\n\tdocument,\n\textractionRegistry,\n\tdeclarations,\n\tconfig,\n\tsessionGuid,\n}: InteractionExtractionPipelineInput): InteractionData[] {\n\tconst declMap = projectDeclarationsForExtraction(declarations);\n\tconst elements = document.findExtractionElements(getRegisteredElementTypes(extractionRegistry));\n\n\tconst interactions: InteractionData[] = [];\n\tfor (const discovered of elements) {\n\t\tconst context = createExtractionContext(\n\t\t\tdiscovered.element,\n\t\t\tdiscovered.responseIdentifier,\n\t\t\tdiscovered.contextRoot,\n\t\t\tdeclMap,\n\t\t\tconfig,\n\t\t\tsessionGuid\n\t\t);\n\t\tconst result = extractionRegistry.extract<any>(discovered.element, context);\n\t\tif (!result.success) continue;\n\n\t\tinteractions.push({\n\t\t\t// A QTI 2.x portableCustomInteraction is nested in customInteraction. Its\n\t\t\t// extractor supplies the canonical renderer type so it does not hit the\n\t\t\t// generic unsupported-custom fallback.\n\t\t\ttype: (result.data?.type ?? discovered.normalizedType) as any,\n\t\t\tresponseId: discovered.responseIdentifier,\n\t\t\t...result.data,\n\t\t});\n\t}\n\n\treturn applyInteractionSecurity(interactions, config.security);\n}\n\nfunction getRegisteredElementTypes(extractionRegistry: ExtractionRegistry): string[] {\n\tconst elementTypes = new Set<string>();\n\tfor (const extractor of extractionRegistry.getExtractors()) {\n\t\tfor (const elementType of extractor.elementTypes) {\n\t\t\telementTypes.add(elementType);\n\t\t}\n\t}\n\treturn [...elementTypes];\n}\n\nfunction projectDeclarationsForExtraction(\n\tdeclarations: DeclarationMap\n): Map<string, ExtractionVariableDeclaration> {\n\tconst declMap = new Map<string, ExtractionVariableDeclaration>();\n\tfor (const declaration of Object.values(declarations)) {\n\t\tdeclMap.set(declaration.identifier, {\n\t\t\tidentifier: declaration.identifier,\n\t\t\tcardinality: declaration.cardinality as any,\n\t\t\tbaseType: declaration.baseType,\n\t\t});\n\t}\n\treturn declMap;\n}\n"]}
|
|
@@ -23,6 +23,16 @@ export interface ExtractionContext {
|
|
|
23
23
|
utils: ExtractionUtils;
|
|
24
24
|
/** Player configuration (role, typesetting, etc.) */
|
|
25
25
|
config: PlayerConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Seeded RNG for interactions honouring the QTI `shuffle` attribute, keyed to the
|
|
28
|
+
* item session and this `responseId`. Stateful: successive calls advance the
|
|
29
|
+
* sequence, so an extractor with two choice sets (e.g. `matchInteraction`) gets an
|
|
30
|
+
* independent permutation for each set.
|
|
31
|
+
*
|
|
32
|
+
* Optional so that a hand-built context remains valid; extractors that find it
|
|
33
|
+
* absent keep the authored order.
|
|
34
|
+
*/
|
|
35
|
+
shuffleRng?: () => number;
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
38
|
* Variable declaration from QTI responseDeclaration/outcomeDeclaration
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/extraction/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/extraction/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuIH;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACzC,YACC,OAAe,EACC,WAAmB,EACnB,WAAmB,EACnB,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,gBAAW,GAAX,WAAW,CAAQ;QACnB,gBAAW,GAAX,WAAW,CAAQ;QACnB,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD;AAuFD;;GAEG;AACH,MAAM,UAAU,eAAe,CAC9B,MAA+B;IAE/B,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC5B,MAA+B;IAE/B,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC;AACjC,CAAC","sourcesContent":["/**\n * Core types for the plugin-based element extraction system\n *\n * Provides interfaces for extracting data from QTI XML elements with\n * priority-based dispatch, validation, and type safety.\n */\n\nimport type { PlayerConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/index.js';\n\n/**\n * Context provided to extractors during extraction\n * Contains DOM reference, utilities, and metadata\n */\nexport interface ExtractionContext {\n\t/** The element being extracted */\n\telement: QTIElement;\n\n\t/** Response identifier for this interaction */\n\tresponseId: string;\n\n\t/** Root DOM element for document-wide queries */\n\tdom: QTIElement;\n\n\t/** Variable declarations from responseDeclaration/outcomeDeclaration */\n\tdeclarations: Map<string, VariableDeclaration>;\n\n\t/** Utility functions for DOM manipulation and extraction */\n\tutils: ExtractionUtils;\n\n\t/** Player configuration (role, typesetting, etc.) */\n\tconfig: PlayerConfig;\n\n\t/**\n\t * Seeded RNG for interactions honouring the QTI `shuffle` attribute, keyed to the\n\t * item session and this `responseId`. Stateful: successive calls advance the\n\t * sequence, so an extractor with two choice sets (e.g. `matchInteraction`) gets an\n\t * independent permutation for each set.\n\t *\n\t * Optional so that a hand-built context remains valid; extractors that find it\n\t * absent keep the authored order.\n\t */\n\tshuffleRng?: () => number;\n}\n\n/**\n * Variable declaration from QTI responseDeclaration/outcomeDeclaration\n */\nexport interface VariableDeclaration {\n\tidentifier: string;\n\tcardinality: 'single' | 'multiple' | 'ordered' | 'record';\n\tbaseType?: string;\n}\n\n/**\n * Utility functions available to extractors\n * Provides safe, consistent DOM manipulation and content extraction\n */\nexport interface ExtractionUtils {\n\t/**\n\t * Get direct children with a specific tag name\n\t * @example utils.getChildrenByTag(element, 'simpleChoice')\n\t */\n\tgetChildrenByTag(element: QTIElement, tagName: string): QTIElement[];\n\n\t/**\n\t * Query all descendants matching a selector\n\t * @example utils.querySelectorAll(element, 'choiceInteraction simpleChoice')\n\t */\n\tquerySelectorAll(element: QTIElement, selector: string): QTIElement[];\n\n\t/**\n\t * Query first descendant matching a selector\n\t * @example utils.querySelector(element, 'prompt')\n\t */\n\tquerySelector(element: QTIElement, selector: string): QTIElement | null;\n\n\t/**\n\t * Check if element has a child with specific tag (fast boolean check)\n\t * @example utils.hasChildWithTag(element, 'ratingChoice')\n\t */\n\thasChildWithTag(element: QTIElement, tagName: string): boolean;\n\n\t/**\n\t * Get sanitized HTML content from element\n\t * @example utils.getHtmlContent(element) // '<p>Question <math>...</math></p>'\n\t */\n\tgetHtmlContent(element: QTIElement): string;\n\n\t/**\n\t * Get plain text content (strips HTML tags)\n\t * @example utils.getTextContent(element) // 'Question text'\n\t */\n\tgetTextContent(element: QTIElement): string;\n\n\t/**\n\t * Get attribute value with optional default\n\t * @example utils.getAttribute(element, 'identifier', '')\n\t */\n\tgetAttribute(element: QTIElement, name: string, defaultValue?: string): string;\n\n\t/**\n\t * Get boolean attribute value with optional default\n\t * @example utils.getBooleanAttribute(element, 'shuffle', false) // true\n\t */\n\tgetBooleanAttribute(element: QTIElement, name: string, defaultValue?: boolean): boolean;\n\n\t/**\n\t * Get numeric attribute value with optional default\n\t * @example utils.getNumberAttribute(element, 'maxChoices', 1) // 1\n\t */\n\tgetNumberAttribute(element: QTIElement, name: string, defaultValue?: number): number;\n\n\t/**\n\t * Get CSS classes from element\n\t * @example utils.getClasses(element) // ['rating-interaction', 'custom']\n\t */\n\tgetClasses(element: QTIElement): string[];\n\n\t/**\n\t * Extract prompt element text from an interaction\n\t * @example utils.getPrompt(element) // '<p>Select the correct answer</p>'\n\t */\n\tgetPrompt(element: QTIElement): string | null;\n}\n\n/**\n * Result of validation\n */\nexport interface ValidationResult {\n\t/** Whether validation passed */\n\tvalid: boolean;\n\n\t/** Error messages if validation failed */\n\terrors?: string[];\n\n\t/** Warning messages (non-fatal) */\n\twarnings?: string[];\n}\n\n/**\n * Error thrown during extraction\n */\nexport class ExtractionError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly extractorId: string,\n\t\tpublic readonly elementType: string,\n\t\tpublic readonly cause?: Error\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'ExtractionError';\n\t}\n}\n\n/**\n * Result of extraction operation\n */\nexport type ExtractionResult<TData> =\n\t| { success: true; data: TData; warnings?: string[] }\n\t| { success: false; error: ExtractionError };\n\n/**\n * Element extractor with priority-based dispatch\n *\n * @template TData - The extracted data type (e.g., ChoiceData, TextEntryData)\n * @template TContext - The extraction context type (defaults to ExtractionContext)\n */\nexport interface ElementExtractor<\n\tTData = unknown,\n\tTContext extends ExtractionContext = ExtractionContext,\n> {\n\t/**\n\t * Unique identifier for this extractor\n\t * Convention: 'namespace:element-type' (e.g., 'qti:choice', 'renaissance:rating-choice')\n\t */\n\tid: string;\n\n\t/**\n\t * Human-readable name for debugging/error messages\n\t * @example 'QTI Standard Choice Interaction'\n\t */\n\tname: string;\n\n\t/**\n\t * Priority for extractor evaluation (higher = checked first)\n\t * - 1000+: Critical system extractors (error handlers, etc.)\n\t * - 500-999: Vendor-specific extractors (Renaissance, custom content)\n\t * - 100-499: Third-party plugin extractors\n\t * - 1-99: Standard QTI extractors with variations\n\t * - 0: Fallback/default extractors\n\t */\n\tpriority: number;\n\n\t/**\n\t * Element types this extractor handles (for type-based indexing)\n\t * Used for O(M) lookup instead of O(N) scanning\n\t * @example ['choiceInteraction', 'inlineChoiceInteraction']\n\t */\n\telementTypes: string[];\n\n\t/**\n\t * Optional description for debugging/error messages\n\t * @example 'Handles Renaissance rating choice interactions with star/face icons'\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Predicate to determine if this extractor can handle the element\n\t * Evaluated in priority order (highest first)\n\t *\n\t * IMPORTANT: Must be FAST - use quick checks first\n\t * @example\n\t * canHandle(element, context) {\n\t * // Fast checks first\n\t * if (!context.utils.hasChildWithTag(element, 'ratingChoice')) return false;\n\t * // Expensive checks only if fast checks pass\n\t * return validateRatingStructure(element);\n\t * }\n\t */\n\tcanHandle(element: QTIElement, context: TContext): boolean;\n\n\t/**\n\t * Extract data from the element\n\t * Called only if canHandle() returns true\n\t *\n\t * @throws ExtractionError if extraction fails\n\t * @returns Extracted data structure\n\t */\n\textract(element: QTIElement, context: TContext): TData;\n\n\t/**\n\t * Validate extracted data (optional)\n\t * Called after extract() succeeds\n\t *\n\t * @returns Validation result with errors/warnings\n\t */\n\tvalidate?(data: TData): ValidationResult;\n}\n\n/**\n * Type guard for successful extraction result\n */\nexport function isSuccessResult<TData>(\n\tresult: ExtractionResult<TData>\n): result is { success: true; data: TData; warnings?: string[] } {\n\treturn result.success === true;\n}\n\n/**\n * Type guard for failed extraction result\n */\nexport function isErrorResult<TData>(\n\tresult: ExtractionResult<TData>\n): result is { success: false; error: ExtractionError } {\n\treturn result.success === false;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js
|
|
|
23
23
|
export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
|
|
24
24
|
export { getCatalogEntry } from './catalog/catalogLookup.js';
|
|
25
25
|
export type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
26
|
-
export type {
|
|
27
|
-
export { PciLoadError } from './pci/types.js';
|
|
26
|
+
export type { ExtractedPci, PciBoundTo, PciConfiguration, PciHostController, PciHostOptions, PciModule, PciModulePathKind, PciModuleResolutionContext, PciModuleResolver, } from './pci/types.js';
|
|
27
|
+
export { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';
|
|
28
28
|
export { PciHost } from './pci/PciHost.js';
|
|
29
29
|
export { normalizeHeuristicsConfig, applyFeedbackTextHeuristics, shouldUseLenientImagePaths, shouldAutoPopulateFeedbackOutcome, DEFAULT_HEURISTICS_CONFIG, STRICT_QTI_CONFIG, FEEDBACK_TEXT_TRANSFORMS, type QtiHeuristicsConfig, type TextTransform, } from '@pie-qti/ims-cp-core';
|
|
30
30
|
/**
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ export { applyPnpToRoot } from './pnp/applyPnp.js';
|
|
|
26
26
|
export { parsePnpXml } from './pnp/parsePnpXml.js';
|
|
27
27
|
export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
|
|
28
28
|
export { getCatalogEntry } from './catalog/catalogLookup.js';
|
|
29
|
-
export { PciLoadError } from './pci/types.js';
|
|
29
|
+
export { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';
|
|
30
30
|
export { PciHost } from './pci/PciHost.js';
|
|
31
31
|
// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience
|
|
32
32
|
// (heuristics are now in the shared ingestion layer)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAAiB,EACjB,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E,mBAAmB,EAAyB,MAAM,sBAAsB,CAAC;AAQlF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,wCAAwC;AACxC,cAAc,yBAAyB,CAAC;AASxC,OAAO,EACN,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,eAAe,GACf,MAAM,uBAAuB,CAAC;AAC/B,QAAQ;AACR,qGAAqG;AACrG,mGAAmG;AACnG,iDAAiD;AACjD,cAAc,kBAAkB,CAAC;AACjC,mBAAmB;AACnB,OAAO,EACN,wBAAwB,EAExB,kBAAkB,GAGlB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAI3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACzG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAe7D,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qEAAqE;AACrE,qDAAqD;AACrD,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,iCAAiC,EACjC,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GAGxB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\nexport * from './core/declarations.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport { Player } from './core/Player.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Plugin system (new extraction-based plugins)\nexport {\n\ttype PluginContext,\n\ttype PluginLifecycle,\n\ttype QTIPlugin,\n\ttype RenderContext,\n} from './core/Plugin.js';\nexport { PluginManager } from './core/PluginManager.js';\n// Export extraction system (PUBLIC API)\nexport * from './interactions/index.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionResult,\n\tExtractionUtils,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\tisErrorResult,\n\tisSuccessResult,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (QTI 3.0 §6.2)\nexport type { PnpProfile } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport { parsePnpXml } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint, otherwise server-side imports of `{ Player }`\n * will crash under SSR/Node.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracts data from associateInteraction elements (associating items)
|
|
5
5
|
*/
|
|
6
|
+
import { maybeShuffle } from '../../core/shuffle.js';
|
|
6
7
|
/**
|
|
7
8
|
* Standard QTI associate interaction extractor
|
|
8
9
|
* Handles associateInteraction elements (creating associations between items)
|
|
@@ -45,7 +46,7 @@ export const standardAssociateExtractor = {
|
|
|
45
46
|
const promptElements = utils.getChildrenByTag(element, 'prompt');
|
|
46
47
|
const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
|
|
47
48
|
return {
|
|
48
|
-
choices,
|
|
49
|
+
choices: maybeShuffle(choices, shuffle, context.shuffleRng),
|
|
49
50
|
shuffle,
|
|
50
51
|
maxAssociations,
|
|
51
52
|
...(minAssociations > 0 ? { minAssociations } : {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAoBrD;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAoC;IAC1E,EAAE,EAAE,2BAA2B;IAC/B,IAAI,EAAE,oCAAoC;IAC1C,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,sBAAsB,CAAC;IACtC,WAAW,EAAE,gEAAgE;IAE7E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,6EAA6E;QAC7E,OAAO,CACN,OAAO,CAAC,UAAU,KAAK,sBAAsB;YAC7C,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAChE,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,0CAA0C;QAC1C,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC;QACjF,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YACjE,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,CAA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oBAC1D,MAAM,CAAC,IAAI,CAAC,4CAA4C,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;gBAC9E,CAAC;YACF,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACrD,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YACpE,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI associateInteraction extractor\n *\n * Extracts data from associateInteraction elements (associating items)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Associate data extracted from associateInteraction elements\n */\nexport interface AssociateData {\n\tchoices: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tshuffle: boolean;\n\tmaxAssociations: number;\n\tminAssociations?: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI associate interaction extractor\n * Handles associateInteraction elements (creating associations between items)\n */\nexport const standardAssociateExtractor: ElementExtractor<AssociateData> = {\n\tid: 'qti:associate-interaction',\n\tname: 'QTI Standard Associate Interaction',\n\tpriority: 10,\n\telementTypes: ['associateInteraction'],\n\tdescription: 'Extracts standard QTI associateInteraction (associating items)',\n\n\tcanHandle(element, context) {\n\t\t// All associateInteraction elements with simpleAssociableChoice are standard\n\t\treturn (\n\t\t\telement.rawTagName === 'associateInteraction' &&\n\t\t\tcontext.utils.hasChildWithTag(element, 'simpleAssociableChoice')\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract simpleAssociableChoice children\n\t\tconst choiceElements = utils.getChildrenByTag(element, 'simpleAssociableChoice');\n\t\tconst choices = choiceElements.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract attributes with proper defaults\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 0);\n\t\tconst minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\tmaxAssociations,\n\t\t\t...(minAssociations > 0 ? { minAssociations } : {}),\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('associateInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (choice.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for choice ${choice.identifier}`);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMin\n\t\t\t\tif (choice.matchMin !== undefined && choice.matchMin < 0) {\n\t\t\t\t\terrors.push(`matchMin must be non-negative for choice ${choice.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate maxAssociations\n\t\tif (data.maxAssociations < 0) {\n\t\t\terrors.push('maxAssociations must be non-negative');\n\t\t}\n\n\t\t// Validate minAssociations\n\t\tif (data.minAssociations !== undefined && data.minAssociations < 0) {\n\t\t\terrors.push('minAssociations must be non-negative');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracts data from choiceInteraction elements with simpleChoice children
|
|
5
5
|
*/
|
|
6
|
+
import { maybeShuffle } from '../../core/shuffle.js';
|
|
6
7
|
/**
|
|
7
8
|
* Standard QTI choice interaction extractor
|
|
8
9
|
* Handles choiceInteraction elements with simpleChoice children
|
|
@@ -42,7 +43,7 @@ export const standardChoiceExtractor = {
|
|
|
42
43
|
const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
|
|
43
44
|
const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
|
|
44
45
|
return {
|
|
45
|
-
choices,
|
|
46
|
+
choices: maybeShuffle(choices, shuffle, context.shuffleRng),
|
|
46
47
|
shuffle,
|
|
47
48
|
maxChoices,
|
|
48
49
|
minChoices,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/choice/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/choice/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAarD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAiC;IACpE,EAAE,EAAE,wBAAwB;IAC5B,IAAI,EAAE,iCAAiC;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,mBAAmB,CAAC;IACnC,WAAW,EAAE,oEAAoE;IAEjF,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,8DAA8D;QAC9D,OAAO,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,kBAAkB;QAClB,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACzD,O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tB,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;YAC3B,QAAQ,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAC3C,QAAQ,CAAC,IAAI,CACZ,eAAe,IAAI,CAAC,UAAU,4CAA4C,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAChG,CAAC;QACH,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI choiceInteraction extractor\n *\n * Extracts data from choiceInteraction elements with simpleChoice children\n */\n\nimport type { ChoiceInteractionData } from '../shared/types.js';\nimport type { ElementExtractor, ExtractionContext } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Choice data extracted from simpleChoice elements\n */\nexport interface ChoiceData {\n\tchoices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;\n\tshuffle: boolean;\n\tmaxChoices: number;\n\tminChoices: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI choice interaction extractor\n * Handles choiceInteraction elements with simpleChoice children\n */\nexport const standardChoiceExtractor: ElementExtractor<ChoiceData> = {\n\tid: 'qti:choice-interaction',\n\tname: 'QTI Standard Choice Interaction',\n\tpriority: 10,\n\telementTypes: ['choiceInteraction'],\n\tdescription: 'Extracts standard QTI choiceInteraction with simpleChoice elements',\n\n\tcanHandle(element, context) {\n\t\t// Standard QTI choice interactions have simpleChoice children\n\t\treturn context.utils.hasChildWithTag(element, 'simpleChoice');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract choices\n\t\tconst simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');\n\t\tconst choices = simpleChoices.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst fixed = utils.getBooleanAttribute(choice, 'fixed');\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt\n\t\tconst promptElement = utils.querySelector(element, 'prompt');\n\t\tconst prompt = promptElement ? utils.getHtmlContent(promptElement) : null;\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\tmaxChoices,\n\t\t\tminChoices,\n\t\t\tprompt,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length === 0) {\n\t\t\terrors.push('choiceInteraction must have at least one choice');\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate maxChoices\n\t\tif (data.maxChoices < 0) {\n\t\t\terrors.push('maxChoices must be non-negative');\n\t\t}\n\n\t\tif (data.maxChoices === 0) {\n\t\t\twarnings.push('maxChoices=0 means unlimited selections');\n\t\t}\n\n\t\tif (data.maxChoices > data.choices.length) {\n\t\t\twarnings.push(\n\t\t\t\t`maxChoices (${data.maxChoices}) is greater than the number of choices (${data.choices.length})`\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -14,8 +14,12 @@ export const standardCustomExtractor = {
|
|
|
14
14
|
elementTypes: ['customInteraction'],
|
|
15
15
|
description: 'Extracts standard QTI customInteraction (custom/portable interactions)',
|
|
16
16
|
canHandle(element, _context) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const tag = element.rawTagName?.toLowerCase() ?? '';
|
|
18
|
+
if (tag !== 'custominteraction' && tag !== 'qti-custom-interaction')
|
|
19
|
+
return false;
|
|
20
|
+
// A QTI 2.x customInteraction containing a namespaced PCI payload is handled
|
|
21
|
+
// by portableCustomExtractor. All other custom interactions keep this fallback.
|
|
22
|
+
return !containsPortableCustomInteraction(element);
|
|
19
23
|
},
|
|
20
24
|
extract(element, context) {
|
|
21
25
|
const { utils } = context;
|
|
@@ -49,4 +53,20 @@ export const standardCustomExtractor = {
|
|
|
49
53
|
};
|
|
50
54
|
},
|
|
51
55
|
};
|
|
56
|
+
function containsPortableCustomInteraction(element) {
|
|
57
|
+
const visit = (parent) => {
|
|
58
|
+
for (const child of parent.childNodes ?? []) {
|
|
59
|
+
const candidate = child;
|
|
60
|
+
const rawTag = candidate.rawTagName?.toLowerCase() ?? '';
|
|
61
|
+
const localTag = rawTag.includes(':') ? rawTag.slice(rawTag.lastIndexOf(':') + 1) : rawTag;
|
|
62
|
+
if (localTag === 'portablecustominteraction' || localTag === 'qti-portable-custom-interaction') {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if (candidate.rawTagName && visit(candidate))
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
return visit(element);
|
|
71
|
+
}
|
|
52
72
|
//# sourceMappingURL=extractor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/custom/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAiC;IACpE,EAAE,EAAE,wBAAwB;IAC5B,IAAI,EAAE,iCAAiC;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,mBAAmB,CAAC;IACnC,WAAW,EAAE,wEAAwE;IAErF,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/custom/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAiC;IACpE,EAAE,EAAE,wBAAwB;IAC5B,IAAI,EAAE,iCAAiC;IACvC,QA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;QAE9B,yBAAyB;QACzB,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3C,QAAQ,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO;YACN,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC;AAEF,SAAS,iCAAiC,CAAC,OAAgE;IAC1G,MAAM,KAAK,GAAG,CAAC,MAAsB,EAAW,EAAE;QACjD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,KAAuB,CAAC;YAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;YACzD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC3F,IAAI,QAAQ,KAAK,2BAA2B,IAAI,QAAQ,KAAK,iCAAiC,EAAE,CAAC;gBAChG,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,SAAS,CAAC,UAAU,IAAI,KAAK,CAAC,SAAS,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC3D,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC;IACF,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Standard QTI customInteraction extractor\n *\n * Extracts data from customInteraction elements (custom/portable interactions)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\n\n/**\n * Custom interaction data extracted from customInteraction elements\n */\nexport interface CustomData {\n\txml: string;\n\trawAttributes: Record<string, string>;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI custom interaction extractor\n * Handles customInteraction elements (vendor-specific or portable custom interactions)\n */\nexport const standardCustomExtractor: ElementExtractor<CustomData> = {\n\tid: 'qti:custom-interaction',\n\tname: 'QTI Standard Custom Interaction',\n\tpriority: 10,\n\telementTypes: ['customInteraction'],\n\tdescription: 'Extracts standard QTI customInteraction (custom/portable interactions)',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = element.rawTagName?.toLowerCase() ?? '';\n\t\tif (tag !== 'custominteraction' && tag !== 'qti-custom-interaction') return false;\n\n\t\t// A QTI 2.x customInteraction containing a namespaced PCI payload is handled\n\t\t// by portableCustomExtractor. All other custom interactions keep this fallback.\n\t\treturn !containsPortableCustomInteraction(element);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Capture the raw XML for the custom interaction\n\t\tconst xml = element.outerHTML || element.toString();\n\n\t\t// Extract all attributes\n\t\tconst rawAttributes: Record<string, string> = {};\n\t\tif (element.attributes) {\n\t\t\tfor (const [key, value] of Object.entries(element.attributes)) {\n\t\t\t\trawAttributes[key] = String(value);\n\t\t\t}\n\t\t}\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\txml,\n\t\t\trawAttributes,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(_data) {\n\t\tconst warnings: string[] = [];\n\n\t\t// Warn if no XML content\n\t\tif (!_data.xml || _data.xml.trim() === '') {\n\t\t\twarnings.push('customInteraction has no XML content');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n\nfunction containsPortableCustomInteraction(element: Parameters<typeof standardCustomExtractor.canHandle>[0]): boolean {\n\tconst visit = (parent: typeof element): boolean => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as typeof element;\n\t\t\tconst rawTag = candidate.rawTagName?.toLowerCase() ?? '';\n\t\t\tconst localTag = rawTag.includes(':') ? rawTag.slice(rawTag.lastIndexOf(':') + 1) : rawTag;\n\t\t\tif (localTag === 'portablecustominteraction' || localTag === 'qti-portable-custom-interaction') {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (candidate.rawTagName && visit(candidate)) return true;\n\t\t}\n\t\treturn false;\n\t};\n\treturn visit(element);\n}\n"]}
|
|
@@ -8,6 +8,12 @@ import type { ElementExtractor } from '../../extraction/types.js';
|
|
|
8
8
|
* Extended text data extracted from extendedTextInteraction elements
|
|
9
9
|
*/
|
|
10
10
|
export interface ExtendedTextData {
|
|
11
|
+
cardinality: 'single' | 'multiple' | 'ordered' | 'record';
|
|
12
|
+
baseType?: string;
|
|
13
|
+
base: number;
|
|
14
|
+
stringIdentifier?: string;
|
|
15
|
+
minStrings: number;
|
|
16
|
+
maxStrings: number;
|
|
11
17
|
expectedLines: number;
|
|
12
18
|
expectedLength: number;
|
|
13
19
|
prompt: string | null;
|
|
@@ -20,7 +20,13 @@ export const standardExtendedTextExtractor = {
|
|
|
20
20
|
},
|
|
21
21
|
extract(element, context) {
|
|
22
22
|
const { utils } = context;
|
|
23
|
+
const declaration = context.declarations.get(context.responseId);
|
|
23
24
|
// Extract attributes
|
|
25
|
+
const cardinality = declaration?.cardinality ?? 'single';
|
|
26
|
+
const base = utils.getNumberAttribute(element, 'base', 10);
|
|
27
|
+
const stringIdentifier = utils.getAttribute(element, 'stringIdentifier', '') || undefined;
|
|
28
|
+
const minStrings = utils.getNumberAttribute(element, 'minStrings', 0);
|
|
29
|
+
const maxStrings = utils.getNumberAttribute(element, 'maxStrings', cardinality === 'single' || cardinality === 'record' ? 1 : 0);
|
|
24
30
|
const expectedLines = utils.getNumberAttribute(element, 'expectedLines', 3);
|
|
25
31
|
const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 200);
|
|
26
32
|
const placeholderText = utils.getAttribute(element, 'placeholderText', '');
|
|
@@ -30,6 +36,12 @@ export const standardExtendedTextExtractor = {
|
|
|
30
36
|
const interactionClasses = utils.getClasses(element);
|
|
31
37
|
const prompt = utils.getPrompt(element);
|
|
32
38
|
return {
|
|
39
|
+
cardinality,
|
|
40
|
+
baseType: declaration?.baseType,
|
|
41
|
+
base,
|
|
42
|
+
...(stringIdentifier ? { stringIdentifier } : {}),
|
|
43
|
+
minStrings,
|
|
44
|
+
maxStrings,
|
|
33
45
|
expectedLines,
|
|
34
46
|
expectedLength,
|
|
35
47
|
prompt,
|
|
@@ -43,18 +55,40 @@ export const standardExtendedTextExtractor = {
|
|
|
43
55
|
validate(data) {
|
|
44
56
|
const errors = [];
|
|
45
57
|
const warnings = [];
|
|
58
|
+
if (data.cardinality === 'record') {
|
|
59
|
+
if (data.baseType)
|
|
60
|
+
errors.push('record cardinality must not declare a baseType');
|
|
61
|
+
if (data.minStrings > 1 || data.maxStrings > 1) {
|
|
62
|
+
errors.push('record cardinality captures exactly one numeric string');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (!['string', 'integer', 'float'].includes(data.baseType ?? '')) {
|
|
66
|
+
errors.push('extendedTextInteraction baseType must be string, integer, or float');
|
|
67
|
+
}
|
|
68
|
+
if (!Number.isInteger(data.base) || data.base < 2 || data.base > 36) {
|
|
69
|
+
errors.push('base must be an integer from 2 through 36');
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isInteger(data.minStrings) || data.minStrings < 0) {
|
|
72
|
+
errors.push('minStrings must be a non-negative integer');
|
|
73
|
+
}
|
|
74
|
+
if (!Number.isInteger(data.maxStrings) || data.maxStrings < 0) {
|
|
75
|
+
errors.push('maxStrings must be a non-negative integer');
|
|
76
|
+
}
|
|
77
|
+
if (data.maxStrings > 0 && data.minStrings > data.maxStrings) {
|
|
78
|
+
errors.push('minStrings must not exceed maxStrings');
|
|
79
|
+
}
|
|
46
80
|
// Validate expectedLines
|
|
47
|
-
if (data.expectedLines <
|
|
48
|
-
errors.push('expectedLines must be
|
|
81
|
+
if (!Number.isInteger(data.expectedLines) || data.expectedLines < 0) {
|
|
82
|
+
errors.push('expectedLines must be a non-negative integer');
|
|
49
83
|
}
|
|
50
84
|
// Validate expectedLength
|
|
51
|
-
if (data.expectedLength <
|
|
52
|
-
errors.push('expectedLength must be
|
|
85
|
+
if (!Number.isInteger(data.expectedLength) || data.expectedLength < 0) {
|
|
86
|
+
errors.push('expectedLength must be a non-negative integer');
|
|
53
87
|
}
|
|
54
88
|
// Validate format
|
|
55
|
-
const validFormats = ['plain', 'preFormatted', 'xhtml'];
|
|
89
|
+
const validFormats = ['plain', 'preFormatted', 'preformatted', 'xhtml'];
|
|
56
90
|
if (!validFormats.includes(data.format)) {
|
|
57
|
-
warnings.push(`Unrecognized format "${data.format}" - expected plain, preFormatted, or xhtml`);
|
|
91
|
+
warnings.push(`Unrecognized format "${data.format}" - expected plain, preformatted, preFormatted, or xhtml`);
|
|
58
92
|
}
|
|
59
93
|
return {
|
|
60
94
|
valid: errors.length === 0,
|