@pie-qti/item-player 0.1.1 → 0.1.5
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 +22 -19
- package/dist/catalog/applyGlossaryTriggers.d.ts +15 -0
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -0
- package/dist/catalog/applyGlossaryTriggers.js +193 -0
- package/dist/catalog/catalogExtractor.d.ts +18 -0
- package/dist/catalog/catalogExtractor.d.ts.map +1 -0
- package/dist/catalog/catalogExtractor.js +114 -0
- package/dist/catalog/catalogLookup.d.ts +18 -0
- package/dist/catalog/catalogLookup.d.ts.map +1 -0
- package/dist/catalog/catalogLookup.js +44 -0
- package/dist/catalog/glossaryAction.d.ts +17 -0
- package/dist/catalog/glossaryAction.d.ts.map +1 -0
- package/dist/catalog/glossaryAction.js +21 -0
- package/dist/catalog/types.d.ts +26 -0
- package/dist/catalog/types.d.ts.map +1 -0
- package/dist/catalog/types.js +6 -0
- package/dist/components/actions/typesetAction.d.ts +24 -0
- package/dist/components/actions/typesetAction.d.ts.map +1 -0
- package/dist/components/actions/typesetAction.js +59 -0
- package/dist/components/utils/assignProps.d.ts +2 -0
- package/dist/components/utils/assignProps.d.ts.map +1 -0
- package/dist/components/utils/assignProps.js +1 -0
- package/dist/components/utils/feedbackUtils.d.ts +73 -0
- package/dist/components/utils/feedbackUtils.d.ts.map +1 -0
- package/dist/components/utils/feedbackUtils.js +93 -0
- package/dist/components/utils/index.d.ts +6 -0
- package/dist/components/utils/index.d.ts.map +1 -0
- package/dist/components/utils/index.js +5 -0
- package/dist/core/ComponentRegistry.d.ts +128 -0
- package/dist/core/ComponentRegistry.d.ts.map +1 -0
- package/dist/core/ComponentRegistry.js +137 -0
- package/dist/core/ItemRenderer.d.ts +91 -0
- package/dist/core/ItemRenderer.d.ts.map +1 -0
- package/dist/core/ItemRenderer.js +261 -0
- package/dist/core/Player.d.ts +195 -0
- package/dist/core/Player.d.ts.map +1 -0
- package/dist/core/Player.js +1235 -0
- package/dist/core/Plugin.d.ts +105 -0
- package/dist/core/Plugin.d.ts.map +1 -0
- package/dist/core/Plugin.js +7 -0
- package/dist/core/PluginManager.d.ts +56 -0
- package/dist/core/PluginManager.d.ts.map +1 -0
- package/dist/core/PluginManager.js +147 -0
- package/dist/core/constants.d.ts +68 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +106 -0
- package/dist/core/declarations.d.ts +45 -0
- package/dist/core/declarations.d.ts.map +1 -0
- package/dist/core/declarations.js +133 -0
- package/dist/core/parsingLimits.d.ts +12 -0
- package/dist/core/parsingLimits.d.ts.map +1 -0
- package/dist/core/parsingLimits.js +45 -0
- package/dist/core/random.d.ts +12 -0
- package/dist/core/random.d.ts.map +1 -0
- package/dist/core/random.js +21 -0
- package/dist/core/rolePolicy.d.ts +16 -0
- package/dist/core/rolePolicy.d.ts.map +1 -0
- package/dist/core/rolePolicy.js +15 -0
- package/dist/core/sanitizer.d.ts +34 -0
- package/dist/core/sanitizer.d.ts.map +1 -0
- package/dist/core/sanitizer.js +198 -0
- package/dist/core/trustedTypes.d.ts +16 -0
- package/dist/core/trustedTypes.d.ts.map +1 -0
- package/dist/core/trustedTypes.js +55 -0
- package/dist/core/urlPolicy.d.ts +8 -0
- package/dist/core/urlPolicy.d.ts.map +1 -0
- package/dist/core/urlPolicy.js +90 -0
- package/dist/element.d.ts +22 -0
- package/dist/element.js +5327 -0
- package/dist/element.js.map +1 -0
- package/dist/extensions/MathLiveEditor.d.ts +32 -0
- package/dist/extensions/MathLiveEditor.d.ts.map +1 -0
- package/dist/extensions/MathLiveEditor.js +249 -0
- package/dist/extraction/ExtractionRegistry.d.ts +112 -0
- package/dist/extraction/ExtractionRegistry.d.ts.map +1 -0
- package/dist/extraction/ExtractionRegistry.js +260 -0
- package/dist/extraction/createContext.d.ts +30 -0
- package/dist/extraction/createContext.d.ts.map +1 -0
- package/dist/extraction/createContext.js +39 -0
- package/dist/extraction/extractors/associateExtractor.d.ts +29 -0
- package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/associateExtractor.js +97 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts +27 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/choiceExtractor.js +93 -0
- package/dist/extraction/extractors/customExtractor.d.ts +20 -0
- package/dist/extraction/extractors/customExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/customExtractor.js +51 -0
- package/dist/extraction/extractors/drawingExtractor.d.ts +30 -0
- package/dist/extraction/extractors/drawingExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/drawingExtractor.js +78 -0
- package/dist/extraction/extractors/endAttemptExtractor.d.ts +20 -0
- package/dist/extraction/extractors/endAttemptExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/endAttemptExtractor.js +53 -0
- package/dist/extraction/extractors/extendedTextExtractor.d.ts +21 -0
- package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/extendedTextExtractor.js +63 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts +29 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/gapMatchExtractor.js +155 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +41 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.js +143 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +53 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.js +205 -0
- package/dist/extraction/extractors/graphicOrderExtractor.d.ts +37 -0
- package/dist/extraction/extractors/graphicOrderExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/graphicOrderExtractor.js +121 -0
- package/dist/extraction/extractors/hotspotExtractor.d.ts +38 -0
- package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/hotspotExtractor.js +159 -0
- package/dist/extraction/extractors/hottextExtractor.d.ts +26 -0
- package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/hottextExtractor.js +128 -0
- package/dist/extraction/extractors/index.d.ts +63 -0
- package/dist/extraction/extractors/index.d.ts.map +1 -0
- package/dist/extraction/extractors/index.js +88 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +25 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.js +80 -0
- package/dist/extraction/extractors/matchExtractor.d.ts +37 -0
- package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/matchExtractor.js +160 -0
- package/dist/extraction/extractors/mediaExtractor.d.ts +33 -0
- package/dist/extraction/extractors/mediaExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/mediaExtractor.js +125 -0
- package/dist/extraction/extractors/orderExtractor.d.ts +28 -0
- package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/orderExtractor.js +90 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts +14 -0
- package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/portableCustomExtractor.js +96 -0
- package/dist/extraction/extractors/positionObjectExtractor.d.ts +59 -0
- package/dist/extraction/extractors/positionObjectExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/positionObjectExtractor.js +191 -0
- package/dist/extraction/extractors/selectPointExtractor.d.ts +31 -0
- package/dist/extraction/extractors/selectPointExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/selectPointExtractor.js +109 -0
- package/dist/extraction/extractors/sliderExtractor.d.ts +24 -0
- package/dist/extraction/extractors/sliderExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/sliderExtractor.js +73 -0
- package/dist/extraction/extractors/textEntryExtractor.d.ts +21 -0
- package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/textEntryExtractor.js +54 -0
- package/dist/extraction/extractors/uploadExtractor.d.ts +20 -0
- package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/uploadExtractor.js +59 -0
- package/dist/extraction/index.d.ts +49 -0
- package/dist/extraction/index.d.ts.map +1 -0
- package/dist/extraction/index.js +49 -0
- package/dist/extraction/types.d.ts +209 -0
- package/dist/extraction/types.d.ts.map +1 -0
- package/dist/extraction/types.js +30 -0
- package/dist/extraction/utils.d.ts +15 -0
- package/dist/extraction/utils.d.ts.map +1 -0
- package/dist/extraction/utils.js +178 -0
- package/dist/iframe/IFramePlayerHost.d.ts +122 -0
- package/dist/iframe/IFramePlayerHost.d.ts.map +1 -0
- package/dist/iframe/IFramePlayerHost.js +172 -0
- package/dist/iframe/index.d.ts +9 -0
- package/dist/iframe/index.d.ts.map +1 -0
- package/dist/iframe/index.js +8 -0
- package/dist/iframe/protocol.d.ts +75 -0
- package/dist/iframe/protocol.d.ts.map +1 -0
- package/dist/iframe/protocol.js +53 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/pci/PciHost.d.ts +53 -0
- package/dist/pci/PciHost.d.ts.map +1 -0
- package/dist/pci/PciHost.js +116 -0
- package/dist/pci/types.d.ts +57 -0
- package/dist/pci/types.d.ts.map +1 -0
- package/dist/pci/types.js +19 -0
- package/dist/pnp/applyPnp.d.ts +9 -0
- package/dist/pnp/applyPnp.d.ts.map +1 -0
- package/dist/pnp/applyPnp.js +19 -0
- package/dist/pnp/parsePnpXml.d.ts +9 -0
- package/dist/pnp/parsePnpXml.d.ts.map +1 -0
- package/dist/pnp/parsePnpXml.js +101 -0
- package/dist/pnp/types.d.ts +40 -0
- package/dist/pnp/types.d.ts.map +1 -0
- package/dist/pnp/types.js +1 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +10 -0
- package/dist/types/index.d.ts +304 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/interactions.d.ts +412 -0
- package/dist/types/interactions.d.ts.map +1 -0
- package/dist/types/interactions.js +7 -0
- package/dist/types/responseValidation.d.ts +25 -0
- package/dist/types/responseValidation.d.ts.map +1 -0
- package/dist/types/responseValidation.js +1 -0
- package/dist/utils/PerformanceMonitor.d.ts +170 -0
- package/dist/utils/PerformanceMonitor.d.ts.map +1 -0
- package/dist/utils/PerformanceMonitor.js +242 -0
- package/dist/utils/drawingUtils.d.ts +39 -0
- package/dist/utils/drawingUtils.d.ts.map +1 -0
- package/dist/utils/drawingUtils.js +57 -0
- package/dist/utils/responseUtils.d.ts +16 -0
- package/dist/utils/responseUtils.d.ts.map +1 -0
- package/dist/utils/responseUtils.js +45 -0
- package/dist/utils/touchDragHelper.d.ts +2 -0
- package/dist/utils/touchDragHelper.d.ts.map +1 -0
- package/dist/utils/touchDragHelper.js +1 -0
- package/dist/web-components/QTIInteractionBase.d.ts +120 -0
- package/dist/web-components/QTIInteractionBase.d.ts.map +1 -0
- package/dist/web-components/QTIInteractionBase.js +243 -0
- package/dist/web-components/QTIInteractionElement.d.ts +77 -0
- package/dist/web-components/QTIInteractionElement.d.ts.map +1 -0
- package/dist/web-components/QTIInteractionElement.js +61 -0
- package/dist/web-components/index.d.ts +8 -0
- package/dist/web-components/index.d.ts.map +1 -0
- package/dist/web-components/index.js +10 -0
- package/package.json +104 -76
- package/src/__tests__/catalog.test.ts +267 -0
- package/src/__tests__/fixtures/pci/echo-pci.js +49 -0
- package/src/__tests__/glossaryTriggers.test.ts +411 -0
- package/src/__tests__/pci.test.ts +353 -0
- package/src/__tests__/pnp.test.ts +250 -0
- package/src/__tests__/qti3-attribute-extraction.test.ts +174 -0
- package/src/__tests__/qti3-debug.test.ts +140 -0
- package/src/__tests__/qti3-extraction.test.ts +309 -0
- package/src/catalog/applyGlossaryTriggers.ts +232 -0
- package/src/catalog/catalogExtractor.ts +130 -0
- package/src/catalog/catalogLookup.ts +53 -0
- package/src/catalog/glossaryAction.ts +28 -0
- package/src/catalog/types.ts +37 -0
- package/src/components/ItemBody.svelte +136 -26
- package/src/components/ItemPlayer.svelte +6 -2
- package/src/components/index.ts +3 -0
- package/src/components/utils/assignProps.ts +1 -23
- package/src/core/ComponentRegistry.ts +14 -0
- package/src/core/ItemRenderer.ts +4 -0
- package/src/core/Player.ts +312 -38
- package/src/core/parsingLimits.ts +1 -1
- package/src/core/rolePolicy.ts +34 -0
- package/src/core/urlPolicy.ts +5 -2
- package/src/element.ts +128 -0
- package/src/extensions/MathLiveEditor.ts +6 -3
- package/src/extraction/ExtractionRegistry.ts +51 -11
- package/src/extraction/createContext.ts +6 -1
- package/src/extraction/extractors/associateExtractor.ts +4 -0
- package/src/extraction/extractors/choiceExtractor.ts +12 -1
- package/src/extraction/extractors/conformance-qti3-advanced.test.ts +239 -0
- package/src/extraction/extractors/conformance-qti3-basic.test.ts +82 -0
- package/src/extraction/extractors/conformance.test.ts +208 -0
- package/src/extraction/extractors/extendedTextExtractor.ts +11 -2
- package/src/extraction/extractors/gapMatchExtractor.ts +36 -21
- package/src/extraction/extractors/graphicAssociateExtractor.ts +4 -0
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +82 -10
- package/src/extraction/extractors/hotspotExtractor.ts +26 -8
- package/src/extraction/extractors/hottextExtractor.ts +15 -5
- package/src/extraction/extractors/index.ts +4 -0
- package/src/extraction/extractors/inlineChoiceExtractor.ts +22 -5
- package/src/extraction/extractors/matchExtractor.ts +33 -6
- package/src/extraction/extractors/orderExtractor.ts +6 -0
- package/src/extraction/extractors/portableCustomExtractor.ts +122 -0
- package/src/extraction/extractors/selectPointExtractor.ts +5 -5
- package/src/extraction/extractors/textEntryExtractor.ts +11 -2
- package/src/extraction/extractors/uploadExtractor.ts +10 -2
- package/src/extraction/utils.ts +99 -16
- package/src/index.ts +19 -1
- package/src/pci/PciHost.ts +138 -0
- package/src/pci/types.ts +70 -0
- package/src/pnp/applyPnp.ts +23 -0
- package/src/pnp/parsePnpXml.ts +118 -0
- package/src/pnp/types.ts +33 -0
- package/src/types/index.ts +50 -16
- package/src/types/interactions.ts +81 -6
- package/src/types/xmldom.d.ts +12 -0
- package/src/utils/drawingUtils.ts +73 -0
- package/src/utils/touchDragHelper.ts +1 -211
- package/.turbo/turbo-build.log +0 -1
- package/CHANGELOG.md +0 -9
- package/docs/QTI-COMPLIANCE.md +0 -197
- package/docs/WCAG-2.2-COMPLIANCE.md +0 -466
- package/docs/custom-extractors.md +0 -679
- package/docs/iframe-mode.md +0 -78
- package/docs/security-audit.md +0 -236
- package/docs/server-api.md +0 -691
- package/tests/conformance/FIXTURE_POLICY.md +0 -29
- package/tests/conformance/README.md +0 -70
- package/tests/conformance/fixtures/baseTypes_all/cases.json +0 -61
- package/tests/conformance/fixtures/baseTypes_all/item.xml +0 -131
- package/tests/conformance/fixtures/baseTypes_all/manifest.json +0 -7
- package/tests/conformance/fixtures/choice_match_correct/cases.json +0 -17
- package/tests/conformance/fixtures/choice_match_correct/item.xml +0 -55
- package/tests/conformance/fixtures/choice_match_correct/manifest.json +0 -14
- package/tests/conformance/fixtures/contains_multiple/cases.json +0 -12
- package/tests/conformance/fixtures/contains_multiple/item.xml +0 -37
- package/tests/conformance/fixtures/contains_multiple/manifest.json +0 -13
- package/tests/conformance/fixtures/isNull_isNotNull/cases.json +0 -9
- package/tests/conformance/fixtures/isNull_isNotNull/item.xml +0 -41
- package/tests/conformance/fixtures/isNull_isNotNull/manifest.json +0 -23
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/cases.json +0 -27
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/item.xml +0 -30
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/manifest.json +0 -15
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/cases.json +0 -11
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/item.xml +0 -26
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/manifest.json +0 -13
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/cases.json +0 -27
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/item.xml +0 -32
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/manifest.json +0 -7
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/cases.json +0 -9
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/item.xml +0 -25
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/manifest.json +0 -12
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/cases.json +0 -12
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/item.xml +0 -35
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/manifest.json +0 -11
- package/tests/conformance/fixtures/mapping_bounds_upperLower/cases.json +0 -12
- package/tests/conformance/fixtures/mapping_bounds_upperLower/item.xml +0 -37
- package/tests/conformance/fixtures/mapping_bounds_upperLower/manifest.json +0 -11
- package/tests/conformance/fixtures/mapping_mapResponse/cases.json +0 -22
- package/tests/conformance/fixtures/mapping_mapResponse/item.xml +0 -53
- package/tests/conformance/fixtures/mapping_mapResponse/manifest.json +0 -16
- package/tests/conformance/fixtures/member_multiple/cases.json +0 -12
- package/tests/conformance/fixtures/member_multiple/item.xml +0 -37
- package/tests/conformance/fixtures/member_multiple/manifest.json +0 -13
- package/tests/conformance/fixtures/modalFeedback_basic/cases.json +0 -17
- package/tests/conformance/fixtures/modalFeedback_basic/item.xml +0 -52
- package/tests/conformance/fixtures/modalFeedback_basic/manifest.json +0 -13
- package/tests/conformance/fixtures/multiple_unordered_match/cases.json +0 -17
- package/tests/conformance/fixtures/multiple_unordered_match/item.xml +0 -44
- package/tests/conformance/fixtures/multiple_unordered_match/manifest.json +0 -11
- package/tests/conformance/fixtures/ordered_match/cases.json +0 -17
- package/tests/conformance/fixtures/ordered_match/item.xml +0 -48
- package/tests/conformance/fixtures/ordered_match/manifest.json +0 -13
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/cases.json +0 -27
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/item.xml +0 -103
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/manifest.json +0 -7
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/cases.json +0 -15
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/item.xml +0 -33
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/manifest.json +0 -10
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/cases.json +0 -14
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/item.xml +0 -26
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/manifest.json +0 -8
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/cases.json +0 -17
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/item.xml +0 -43
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/manifest.json +0 -16
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/cases.json +0 -27
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/item.xml +0 -37
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/manifest.json +0 -16
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/cases.json +0 -14
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/item.xml +0 -35
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/manifest.json +0 -8
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/cases.json +0 -14
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/item.xml +0 -35
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/manifest.json +0 -8
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/cases.json +0 -15
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/item.xml +0 -39
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/manifest.json +0 -11
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/cases.json +0 -14
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/item.xml +0 -35
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/manifest.json +0 -8
- package/tests/conformance/fixtures/pair_unordered_match/cases.json +0 -22
- package/tests/conformance/fixtures/pair_unordered_match/item.xml +0 -44
- package/tests/conformance/fixtures/pair_unordered_match/manifest.json +0 -13
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/cases.json +0 -95
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/item.xml +0 -53
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/cases.json +0 -115
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/item.xml +0 -45
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/cases.json +0 -29
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/item.xml +0 -40
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/cases.json +0 -10
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/item.xml +0 -49
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/manifest.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_anyN/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_anyN/item.xml +0 -47
- package/tests/conformance/fixtures/responseProcessing_anyN/manifest.json +0 -16
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/item.xml +0 -69
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/manifest.json +0 -23
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/cases.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/item.xml +0 -58
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/manifest.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/cases.json +0 -37
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/item.xml +0 -94
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/manifest.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/cases.json +0 -33
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/item.xml +0 -79
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/manifest.json +0 -16
- package/tests/conformance/fixtures/responseProcessing_customOperator/cases.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_customOperator/item.xml +0 -30
- package/tests/conformance/fixtures/responseProcessing_customOperator/manifest.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_default_expression/cases.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_default_expression/item.xml +0 -48
- package/tests/conformance/fixtures/responseProcessing_default_expression/manifest.json +0 -13
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/cases.json +0 -29
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/item.xml +0 -68
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/manifest.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/cases.json +0 -39
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/item.xml +0 -39
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/manifest.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_exitResponse/cases.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_exitResponse/item.xml +0 -25
- package/tests/conformance/fixtures/responseProcessing_exitResponse/manifest.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/cases.json +0 -26
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/item.xml +0 -134
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/manifest.json +0 -16
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/item.xml +0 -33
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/manifest.json +0 -13
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/item.xml +0 -33
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/manifest.json +0 -13
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/item.xml +0 -40
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/manifest.json +0 -18
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/item.xml +0 -33
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/manifest.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/cases.json +0 -29
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/item.xml +0 -26
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/manifest.json +0 -7
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/cases.json +0 -23
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/item.xml +0 -28
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/manifest.json +0 -11
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/cases.json +0 -29
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/item.xml +0 -26
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/manifest.json +0 -7
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/cases.json +0 -31
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/item.xml +0 -102
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/manifest.json +0 -18
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/item.xml +0 -45
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/manifest.json +0 -21
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/cases.json +0 -26
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/item.xml +0 -157
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/manifest.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/item.xml +0 -39
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/manifest.json +0 -18
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/item.xml +0 -51
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/manifest.json +0 -19
- package/tests/conformance/fixtures/responseProcessing_preCondition/cases.json +0 -31
- package/tests/conformance/fixtures/responseProcessing_preCondition/item.xml +0 -44
- package/tests/conformance/fixtures/responseProcessing_preCondition/manifest.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/item.xml +0 -42
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/manifest.json +0 -14
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/cases.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/item.xml +0 -40
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/manifest.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/cases.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/item.xml +0 -63
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/manifest.json +0 -9
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/cases.json +0 -12
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/item.xml +0 -40
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/manifest.json +0 -13
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/cases.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/item.xml +0 -67
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/manifest.json +0 -9
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/cases.json +0 -27
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/item.xml +0 -69
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/manifest.json +0 -10
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/cases.json +0 -15
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/item.xml +0 -35
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/manifest.json +0 -11
- package/tests/conformance/fixtures/responseProcessing_template_map_response/cases.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_template_map_response/item.xml +0 -31
- package/tests/conformance/fixtures/responseProcessing_template_map_response/manifest.json +0 -8
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/item.xml +0 -27
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/manifest.json +0 -8
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/cases.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/item.xml +0 -34
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/manifest.json +0 -8
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/cases.json +0 -22
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/item.xml +0 -30
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/manifest.json +0 -7
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/cases.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/item.xml +0 -30
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/manifest.json +0 -9
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/cases.json +0 -17
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/item.xml +0 -30
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/manifest.json +0 -8
- package/tests/conformance/fixtures/responseProcessing_xiInclude/cases.json +0 -14
- package/tests/conformance/fixtures/responseProcessing_xiInclude/item.xml +0 -25
- package/tests/conformance/fixtures/responseProcessing_xiInclude/manifest.json +0 -9
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/cases.json +0 -12
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/item.xml +0 -52
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/manifest.json +0 -14
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/cases.json +0 -12
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/item.xml +0 -48
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/manifest.json +0 -13
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/cases.json +0 -27
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/item.xml +0 -74
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/manifest.json +0 -22
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/cases.json +0 -17
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/item.xml +0 -133
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/manifest.json +0 -22
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/cases.json +0 -12
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/item.xml +0 -107
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/manifest.json +0 -16
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/cases.json +0 -15
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/item.xml +0 -52
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/manifest.json +0 -14
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/cases.json +0 -16
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/item.xml +0 -49
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/manifest.json +0 -15
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/cases.json +0 -16
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/item.xml +0 -38
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/manifest.json +0 -13
- package/tests/conformance/harness.ts +0 -84
- package/tests/conformance/run-fixtures.test.ts +0 -127
- package/tests/conformance/scripts/normalize-covers.ts +0 -152
- package/tests/conformance/types.ts +0 -53
- package/tests/core/Player.test.ts +0 -563
- package/tests/core/adaptiveItems.test.ts +0 -442
- package/tests/core/correctResponse.test.ts +0 -280
- package/tests/core/interaction-plumbing.test.ts +0 -141
- package/tests/core/modalFeedback.test.ts +0 -308
- package/tests/core/outcome-reset.test.ts +0 -43
- package/tests/extraction/extractors/associateExtractor.test.ts +0 -182
- package/tests/extraction/extractors/choiceExtractor.test.ts +0 -239
- package/tests/extraction/extractors/customExtractor.test.ts +0 -83
- package/tests/extraction/extractors/drawingExtractor.test.ts +0 -94
- package/tests/extraction/extractors/endAttemptExtractor.test.ts +0 -188
- package/tests/extraction/extractors/extendedTextExtractor.test.ts +0 -178
- package/tests/extraction/extractors/gapMatchExtractor.test.ts +0 -318
- package/tests/extraction/extractors/graphicAssociateExtractor.test.ts +0 -260
- package/tests/extraction/extractors/graphicGapMatchExtractor.test.ts +0 -320
- package/tests/extraction/extractors/graphicOrderExtractor.test.ts +0 -223
- package/tests/extraction/extractors/hotspotExtractor.test.ts +0 -298
- package/tests/extraction/extractors/hottextExtractor.test.ts +0 -240
- package/tests/extraction/extractors/inlineChoiceExtractor.test.ts +0 -292
- package/tests/extraction/extractors/matchExtractor.test.ts +0 -241
- package/tests/extraction/extractors/mediaExtractor.test.ts +0 -295
- package/tests/extraction/extractors/orderExtractor.test.ts +0 -212
- package/tests/extraction/extractors/positionObjectExtractor.test.ts +0 -363
- package/tests/extraction/extractors/selectPointExtractor.test.ts +0 -214
- package/tests/extraction/extractors/sliderExtractor.test.ts +0 -293
- package/tests/extraction/extractors/textEntryExtractor.test.ts +0 -133
- package/tests/extraction/extractors/uploadExtractor.test.ts +0 -119
- package/tests/extraction/test-utils.ts +0 -57
- package/tests/iframe/host.test.ts +0 -145
- package/tests/iframe/protocol.test.ts +0 -42
- package/tests/performance/player-benchmarks.bench.ts +0 -191
- package/tests/security/dos-limits.test.ts +0 -56
- package/tests/security/xss-prevention.test.ts +0 -522
- package/tsconfig.json +0 -20
- package/tsconfig.svelte.json +0 -14
package/src/extraction/utils.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Provides DOM manipulation and content extraction helpers for extractors
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';
|
|
8
|
+
import { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';
|
|
7
9
|
import { sanitizeTextContent } from '../core/sanitizer.js';
|
|
8
10
|
import type { PlayerSecurityConfig } from '../types/index.js';
|
|
9
11
|
import type { QTIElement } from '../types/interactions.js';
|
|
@@ -27,6 +29,7 @@ function getHtmlContent(element: QTIElement | null | undefined): string {
|
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Get children by tag name from QTI elements
|
|
32
|
+
* Note: This version does NOT handle QTI version mapping - use the one in ExtractionUtils instead
|
|
30
33
|
*/
|
|
31
34
|
function getChildrenByTag(
|
|
32
35
|
element: QTIElement | null | undefined,
|
|
@@ -35,36 +38,82 @@ function getChildrenByTag(
|
|
|
35
38
|
return (element?.childNodes?.filter((n) => n.rawTagName === tagName) as QTIElement[]) || [];
|
|
36
39
|
}
|
|
37
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Get children by tag name with QTI version awareness
|
|
43
|
+
*/
|
|
44
|
+
function getChildrenByTagWithMapper(
|
|
45
|
+
element: QTIElement | null | undefined,
|
|
46
|
+
tagName: string,
|
|
47
|
+
mapper: ElementNameMapper
|
|
48
|
+
): QTIElement[] {
|
|
49
|
+
if (!element?.childNodes) return [];
|
|
50
|
+
return element.childNodes.filter((n) =>
|
|
51
|
+
matchesTagName((n as QTIElement).rawTagName, tagName, mapper)
|
|
52
|
+
) as QTIElement[];
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
/**
|
|
39
56
|
* Extract a boolean attribute from a QTI element
|
|
57
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
40
58
|
*/
|
|
41
59
|
function getBooleanAttribute(
|
|
42
60
|
element: QTIElement,
|
|
43
61
|
name: string,
|
|
44
|
-
defaultValue = false
|
|
62
|
+
defaultValue = false,
|
|
63
|
+
attributeMapper?: AttributeNameMapper
|
|
45
64
|
): boolean {
|
|
46
|
-
|
|
65
|
+
let value = element.getAttribute(name);
|
|
66
|
+
|
|
67
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
68
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
69
|
+
const nativeName = attributeMapper.toNative(name);
|
|
70
|
+
value = element.getAttribute(nativeName);
|
|
71
|
+
}
|
|
72
|
+
|
|
47
73
|
if (value === null || value === undefined) return defaultValue;
|
|
48
74
|
return value === 'true';
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
/**
|
|
52
78
|
* Extract a number attribute from a QTI element
|
|
79
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
53
80
|
*/
|
|
54
81
|
function getNumberAttribute(
|
|
55
82
|
element: QTIElement,
|
|
56
83
|
name: string,
|
|
57
|
-
defaultValue: number
|
|
84
|
+
defaultValue: number,
|
|
85
|
+
attributeMapper?: AttributeNameMapper
|
|
58
86
|
): number {
|
|
59
|
-
|
|
87
|
+
let value = element.getAttribute(name);
|
|
88
|
+
|
|
89
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
90
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
91
|
+
const nativeName = attributeMapper.toNative(name);
|
|
92
|
+
value = element.getAttribute(nativeName);
|
|
93
|
+
}
|
|
94
|
+
|
|
60
95
|
return value ? Number(value) : defaultValue;
|
|
61
96
|
}
|
|
62
97
|
|
|
63
98
|
/**
|
|
64
99
|
* Extract a string attribute from a QTI element
|
|
100
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
65
101
|
*/
|
|
66
|
-
function getStringAttribute(
|
|
67
|
-
|
|
102
|
+
function getStringAttribute(
|
|
103
|
+
element: QTIElement,
|
|
104
|
+
name: string,
|
|
105
|
+
defaultValue = '',
|
|
106
|
+
attributeMapper?: AttributeNameMapper
|
|
107
|
+
): string {
|
|
108
|
+
let value = element.getAttribute(name);
|
|
109
|
+
|
|
110
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
111
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
112
|
+
const nativeName = attributeMapper.toNative(name);
|
|
113
|
+
value = element.getAttribute(nativeName);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return value || defaultValue;
|
|
68
117
|
}
|
|
69
118
|
|
|
70
119
|
/**
|
|
@@ -75,14 +124,48 @@ function getClasses(element: QTIElement): string[] {
|
|
|
75
124
|
return classAttr ? classAttr.split(/\s+/).filter(Boolean) : [];
|
|
76
125
|
}
|
|
77
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Helper to check if an element's tag name matches a given QTI element name.
|
|
129
|
+
* Handles both QTI 2.x and QTI 3.0 element naming conventions.
|
|
130
|
+
*
|
|
131
|
+
* @param rawTagName - The element's raw tag name from the HTML
|
|
132
|
+
* @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')
|
|
133
|
+
* @param mapper - Optional element name mapper for QTI version handling
|
|
134
|
+
* @returns true if the tag name matches
|
|
135
|
+
*/
|
|
136
|
+
function matchesTagName(
|
|
137
|
+
rawTagName: string | undefined,
|
|
138
|
+
expectedTagName: string,
|
|
139
|
+
mapper: ElementNameMapper
|
|
140
|
+
): boolean {
|
|
141
|
+
if (!rawTagName) return false;
|
|
142
|
+
|
|
143
|
+
// Convert expected tag name to canonical form (lowercase)
|
|
144
|
+
const canonical = expectedTagName.toLowerCase();
|
|
145
|
+
|
|
146
|
+
// Get the native form for this QTI version
|
|
147
|
+
const native = mapper.toNative(canonical);
|
|
148
|
+
|
|
149
|
+
// Check if raw tag name matches the native form (case-insensitive)
|
|
150
|
+
return rawTagName.toLowerCase() === native.toLowerCase();
|
|
151
|
+
}
|
|
152
|
+
|
|
78
153
|
/**
|
|
79
154
|
* Create extraction utilities instance
|
|
80
|
-
* Provides standard helpers for extracting data from QTI elements
|
|
155
|
+
* Provides standard helpers for extracting data from QTI elements.
|
|
156
|
+
* Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.
|
|
81
157
|
*/
|
|
82
|
-
export function createExtractionUtils(
|
|
158
|
+
export function createExtractionUtils(
|
|
159
|
+
security?: PlayerSecurityConfig,
|
|
160
|
+
mapper?: ElementNameMapper,
|
|
161
|
+
attributeMapper?: AttributeNameMapper
|
|
162
|
+
): ExtractionUtils {
|
|
163
|
+
// Default to QTI 2.x mappers (primary supported QTI format)
|
|
164
|
+
const elementMapper = mapper || new Qti2xElementNameMapper();
|
|
165
|
+
const attrMapper = attributeMapper || new Qti2xAttributeNameMapper();
|
|
83
166
|
return {
|
|
84
167
|
getChildrenByTag(element: QTIElement, tagName: string): QTIElement[] {
|
|
85
|
-
return
|
|
168
|
+
return getChildrenByTagWithMapper(element, tagName, elementMapper);
|
|
86
169
|
},
|
|
87
170
|
|
|
88
171
|
querySelectorAll(element: QTIElement, selector: string): QTIElement[] {
|
|
@@ -93,12 +176,12 @@ export function createExtractionUtils(security?: PlayerSecurityConfig): Extracti
|
|
|
93
176
|
for (const part of parts) {
|
|
94
177
|
const nextResults: QTIElement[] = [];
|
|
95
178
|
for (const current of results) {
|
|
96
|
-
if (current.rawTagName
|
|
179
|
+
if (matchesTagName(current.rawTagName, part, elementMapper)) {
|
|
97
180
|
nextResults.push(current);
|
|
98
181
|
}
|
|
99
182
|
if (current.childNodes) {
|
|
100
183
|
for (const child of current.childNodes) {
|
|
101
|
-
if (typeof child !== 'string' && (child as QTIElement).rawTagName
|
|
184
|
+
if (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, part, elementMapper)) {
|
|
102
185
|
nextResults.push(child as QTIElement);
|
|
103
186
|
}
|
|
104
187
|
}
|
|
@@ -120,7 +203,7 @@ export function createExtractionUtils(security?: PlayerSecurityConfig): Extracti
|
|
|
120
203
|
if (!element.childNodes) return false;
|
|
121
204
|
|
|
122
205
|
for (const child of element.childNodes) {
|
|
123
|
-
if (typeof child !== 'string' && (child as QTIElement).rawTagName
|
|
206
|
+
if (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, tagName, elementMapper)) {
|
|
124
207
|
return true;
|
|
125
208
|
}
|
|
126
209
|
}
|
|
@@ -137,19 +220,19 @@ export function createExtractionUtils(security?: PlayerSecurityConfig): Extracti
|
|
|
137
220
|
},
|
|
138
221
|
|
|
139
222
|
getAttribute(element: QTIElement, name: string, defaultValue = ''): string {
|
|
140
|
-
return getStringAttribute(element, name, defaultValue);
|
|
223
|
+
return getStringAttribute(element, name, defaultValue, attrMapper);
|
|
141
224
|
},
|
|
142
225
|
|
|
143
226
|
getBooleanAttribute(element: QTIElement, name: string, defaultValue = false): boolean {
|
|
144
|
-
return getBooleanAttribute(element, name, defaultValue);
|
|
227
|
+
return getBooleanAttribute(element, name, defaultValue, attrMapper);
|
|
145
228
|
},
|
|
146
229
|
|
|
147
230
|
getNumberAttribute(element: QTIElement, name: string, defaultValue = 0): number {
|
|
148
|
-
return getNumberAttribute(element, name, defaultValue);
|
|
231
|
+
return getNumberAttribute(element, name, defaultValue, attrMapper);
|
|
149
232
|
},
|
|
150
233
|
|
|
151
234
|
getPrompt(element: QTIElement): string | null {
|
|
152
|
-
const promptElement =
|
|
235
|
+
const promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];
|
|
153
236
|
return promptElement ? getHtmlContent(promptElement) : null;
|
|
154
237
|
},
|
|
155
238
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @pie-qti/item-player
|
|
3
|
-
* Modern QTI 2.2
|
|
3
|
+
* Modern QTI player (2.2/3.0) - Framework-agnostic with web components
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -13,6 +13,8 @@ export {
|
|
|
13
13
|
} from './core/ComponentRegistry.js';
|
|
14
14
|
export * from './core/constants.js';
|
|
15
15
|
export * from './core/declarations.js';
|
|
16
|
+
// Export drawing utilities
|
|
17
|
+
export * from './utils/drawingUtils.js';
|
|
16
18
|
// Export ItemRenderer for framework-agnostic rendering
|
|
17
19
|
export {
|
|
18
20
|
createItemRenderer,
|
|
@@ -20,6 +22,7 @@ export {
|
|
|
20
22
|
type ItemRendererConfig,
|
|
21
23
|
} from './core/ItemRenderer.js';
|
|
22
24
|
export { Player } from './core/Player.js';
|
|
25
|
+
export { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';
|
|
23
26
|
// Plugin system (new extraction-based plugins)
|
|
24
27
|
export {
|
|
25
28
|
type PluginContext,
|
|
@@ -62,6 +65,21 @@ export {
|
|
|
62
65
|
|
|
63
66
|
export { isResponseEmpty } from './utils/responseUtils.js';
|
|
64
67
|
|
|
68
|
+
// PNP profile (QTI 3.0 §6.2)
|
|
69
|
+
export type { PnpProfile } from './pnp/types.js';
|
|
70
|
+
export { applyPnpToRoot } from './pnp/applyPnp.js';
|
|
71
|
+
export { parsePnpXml } from './pnp/parsePnpXml.js';
|
|
72
|
+
|
|
73
|
+
// Catalog (QTI 3.0 §6.3)
|
|
74
|
+
export type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';
|
|
75
|
+
export { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';
|
|
76
|
+
export { getCatalogEntry } from './catalog/catalogLookup.js';
|
|
77
|
+
|
|
78
|
+
// PCI — Portable Custom Interaction (QTI 3.0 §6.1)
|
|
79
|
+
export type { PciModule, PciBoundTo, ExtractedPci } from './pci/types.js';
|
|
80
|
+
export { PciLoadError } from './pci/types.js';
|
|
81
|
+
export { PciHost } from './pci/PciHost.js';
|
|
82
|
+
|
|
65
83
|
// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience
|
|
66
84
|
// (heuristics are now in the shared ingestion layer)
|
|
67
85
|
export {
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { ExtractedPci, PciBoundTo, PciModule } from './types.js';
|
|
2
|
+
import { PciLoadError } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loads, initializes, and manages the lifecycle of a single PCI module.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const host = new PciHost(extractedData, baseUrl);
|
|
9
|
+
* await host.load();
|
|
10
|
+
* host.initialize(domNode);
|
|
11
|
+
* host.getResponse(); // returns current response
|
|
12
|
+
* host.destroy(); // cleanup on player teardown
|
|
13
|
+
*/
|
|
14
|
+
export class PciHost {
|
|
15
|
+
private readonly data: ExtractedPci;
|
|
16
|
+
private readonly baseUrl: string;
|
|
17
|
+
private module: PciModule | null = null;
|
|
18
|
+
private _response: unknown = null;
|
|
19
|
+
private _onResponseChange: ((responseId: string, value: unknown) => void) | null = null;
|
|
20
|
+
|
|
21
|
+
constructor(data: ExtractedPci, baseUrl: string) {
|
|
22
|
+
this.data = data;
|
|
23
|
+
this.baseUrl = baseUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Register a callback to fire when the PCI's response changes.
|
|
28
|
+
* The player calls this to wire the PCI into its internal response map.
|
|
29
|
+
*/
|
|
30
|
+
public onResponseChange(callback: (responseId: string, value: unknown) => void): void {
|
|
31
|
+
this._onResponseChange = callback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load the PCI module from primaryPath, falling back to fallbackPath.
|
|
36
|
+
* Throws PciLoadError if both fail.
|
|
37
|
+
*/
|
|
38
|
+
public async load(): Promise<void> {
|
|
39
|
+
const primary = this.resolveUrl(this.data.primaryPath);
|
|
40
|
+
try {
|
|
41
|
+
const mod = await this.dynamicImport(primary);
|
|
42
|
+
this.module = this.extractPciInterface(mod);
|
|
43
|
+
return;
|
|
44
|
+
} catch (primaryErr) {
|
|
45
|
+
if (!this.data.fallbackPath) {
|
|
46
|
+
throw new PciLoadError(this.data.primaryPath, undefined, primaryErr as Error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const fallback = this.resolveUrl(this.data.fallbackPath!);
|
|
51
|
+
try {
|
|
52
|
+
const mod = await this.dynamicImport(fallback);
|
|
53
|
+
this.module = this.extractPciInterface(mod);
|
|
54
|
+
} catch (fallbackErr) {
|
|
55
|
+
throw new PciLoadError(
|
|
56
|
+
this.data.primaryPath,
|
|
57
|
+
this.data.fallbackPath,
|
|
58
|
+
fallbackErr as Error
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Initialize the PCI inside the given DOM element.
|
|
65
|
+
* Must be called after load() resolves.
|
|
66
|
+
*/
|
|
67
|
+
public initialize(dom: HTMLElement): void {
|
|
68
|
+
if (!this.module) return;
|
|
69
|
+
|
|
70
|
+
const boundTo: PciBoundTo = {
|
|
71
|
+
onReady: () => {},
|
|
72
|
+
onResponseChange: (value: unknown) => {
|
|
73
|
+
this._response = value;
|
|
74
|
+
this._onResponseChange?.(this.data.responseIdentifier, value);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
this.module.initialize(dom, this.data.config, boundTo);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Return the current response value from the PCI module. */
|
|
82
|
+
public getResponse(): unknown {
|
|
83
|
+
return this.module ? this.module.getResponse() : this._response;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Restore a response value into the PCI module (e.g. from session state). */
|
|
87
|
+
public setResponse(value: unknown): void {
|
|
88
|
+
this._response = value;
|
|
89
|
+
this.module?.setResponse(value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Disable the PCI (e.g. when role is not candidate, or after final submission). */
|
|
93
|
+
public disable(): void {
|
|
94
|
+
this.module?.disable();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Re-enable the PCI. */
|
|
98
|
+
public enable(): void {
|
|
99
|
+
this.module?.enable();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Tear down the PCI and release all resources. */
|
|
103
|
+
public destroy(): void {
|
|
104
|
+
this.module?.destroy();
|
|
105
|
+
this.module = null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Private helpers
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
/** Thin wrapper around dynamic import — overridable in tests. */
|
|
113
|
+
protected dynamicImport(url: string): Promise<any> {
|
|
114
|
+
return import(/* @vite-ignore */ url);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private resolveUrl(path: string): string {
|
|
118
|
+
if (/^https?:\/\//.test(path) || path.startsWith('/')) return path;
|
|
119
|
+
// Relative path: resolve against baseUrl
|
|
120
|
+
const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';
|
|
121
|
+
return base + path;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Extract a PciModule from a dynamic import result.
|
|
126
|
+
* Supports: default export, named `getInstance` export, or the module itself.
|
|
127
|
+
*/
|
|
128
|
+
private extractPciInterface(mod: any): PciModule {
|
|
129
|
+
const candidate = mod?.default ?? mod?.getInstance?.() ?? mod;
|
|
130
|
+
if (typeof candidate?.initialize !== 'function') {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`PCI module at '${this.data.primaryPath}' does not export a valid PciModule interface ` +
|
|
133
|
+
'(expected .initialize, .getResponse, .setResponse, .disable, .enable, .destroy)'
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return candidate as PciModule;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/src/pci/types.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI 3.0 Portable Custom Interaction (PCI) types.
|
|
3
|
+
* Based on IMS QTI 3.0 Portable Custom Interaction specification.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Callbacks the player provides to a PCI module so it can signal state changes.
|
|
8
|
+
*/
|
|
9
|
+
export interface PciBoundTo {
|
|
10
|
+
/** Called when the PCI has finished initializing and is ready to accept responses. */
|
|
11
|
+
onReady(): void;
|
|
12
|
+
/** Called whenever the candidate's response changes. */
|
|
13
|
+
onResponseChange(value: unknown): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Contract that every PCI module must fulfill.
|
|
18
|
+
* The module's default export (or named `getInstance` export) must implement this interface.
|
|
19
|
+
*/
|
|
20
|
+
export interface PciModule {
|
|
21
|
+
/** Initialize the PCI inside the given DOM element. */
|
|
22
|
+
initialize(dom: HTMLElement, config: Record<string, string>, boundTo: PciBoundTo): void;
|
|
23
|
+
/** Return the current response value. */
|
|
24
|
+
getResponse(): unknown;
|
|
25
|
+
/** Restore a previously-captured response value. */
|
|
26
|
+
setResponse(value: unknown): void;
|
|
27
|
+
/** Disable candidate interaction (e.g. after submission or when role is not candidate). */
|
|
28
|
+
disable(): void;
|
|
29
|
+
/** Re-enable candidate interaction. */
|
|
30
|
+
enable(): void;
|
|
31
|
+
/** Tear down: remove event listeners, cancel timers, free resources. */
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Extracted data from a <qti-portable-custom-interaction> element.
|
|
37
|
+
*/
|
|
38
|
+
export interface ExtractedPci {
|
|
39
|
+
/** responseIdentifier attribute value. */
|
|
40
|
+
responseIdentifier: string;
|
|
41
|
+
/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */
|
|
42
|
+
customInteractionTypeIdentifier: string;
|
|
43
|
+
/** Primary JS module path (required). */
|
|
44
|
+
primaryPath: string;
|
|
45
|
+
/** Fallback JS module path (optional). */
|
|
46
|
+
fallbackPath?: string;
|
|
47
|
+
/** Inner HTML of the <qti-interaction-markup> element. */
|
|
48
|
+
markup: string;
|
|
49
|
+
/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */
|
|
50
|
+
config: Record<string, string>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Thrown when a PCI module fails to load from both primary and fallback paths.
|
|
55
|
+
*/
|
|
56
|
+
export class PciLoadError extends Error {
|
|
57
|
+
constructor(
|
|
58
|
+
public readonly primaryPath: string,
|
|
59
|
+
public readonly fallbackPath: string | undefined,
|
|
60
|
+
cause?: Error
|
|
61
|
+
) {
|
|
62
|
+
super(
|
|
63
|
+
fallbackPath
|
|
64
|
+
? `PCI module failed to load from '${primaryPath}' and fallback '${fallbackPath}'`
|
|
65
|
+
: `PCI module failed to load from '${primaryPath}'`
|
|
66
|
+
);
|
|
67
|
+
this.name = 'PciLoadError';
|
|
68
|
+
if (cause) Object.defineProperty(this, 'cause', { value: cause, writable: true, configurable: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PnpProfile } from './types.js';
|
|
2
|
+
|
|
3
|
+
const ATTR = 'data-qti-colorscheme';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Apply a PNP profile to the player root element.
|
|
7
|
+
*
|
|
8
|
+
* Currently handles color scheme (data-qti-colorscheme attribute).
|
|
9
|
+
* Magnification is intentionally deferred — host stylesheets / browser zoom are sufficient for now.
|
|
10
|
+
*/
|
|
11
|
+
export function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {
|
|
12
|
+
const scheme = pnp?.display?.colorScheme;
|
|
13
|
+
|
|
14
|
+
if (!scheme || scheme === 'default') {
|
|
15
|
+
rootEl.removeAttribute(ATTR);
|
|
16
|
+
} else {
|
|
17
|
+
rootEl.setAttribute(ATTR, scheme);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (pnp?.display?.magnification !== undefined) {
|
|
21
|
+
console.warn('[QTI Player] PnpProfile.display.magnification is not yet applied by the player. Use browser zoom or a host stylesheet instead.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { parse as parseHtml } from 'node-html-parser';
|
|
2
|
+
import type { HTMLElement as NhpElement } from 'node-html-parser';
|
|
3
|
+
import type { PnpProfile } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse a QTI 3.0 <personalNeedsProfile> element (or legacy <pnp> element) into a PnpProfile.
|
|
7
|
+
*
|
|
8
|
+
* Accepts either an XML/HTML string containing the profile element, or a live DOM Element.
|
|
9
|
+
* Unknown child elements are silently ignored for forward-compatibility.
|
|
10
|
+
*/
|
|
11
|
+
export function parsePnpXml(xml: string | Element): PnpProfile {
|
|
12
|
+
if (typeof xml !== 'string') {
|
|
13
|
+
// Live DOM Element — serialise to string and re-parse via node-html-parser
|
|
14
|
+
return parsePnpXml((xml as Element).outerHTML ?? '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const trimmed = xml.trim();
|
|
18
|
+
if (!trimmed) return {};
|
|
19
|
+
|
|
20
|
+
// Wrap so node-html-parser treats the outer tag as the root
|
|
21
|
+
const doc = parseHtml(`<root>${trimmed}</root>`, { lowerCaseTagName: true });
|
|
22
|
+
const root = doc.querySelector('personalneedsprofile') ?? doc.querySelector('pnp');
|
|
23
|
+
if (!root) return {};
|
|
24
|
+
|
|
25
|
+
return extractProfile(root);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function extractProfile(root: NhpElement): PnpProfile {
|
|
29
|
+
const profile: PnpProfile = {};
|
|
30
|
+
|
|
31
|
+
// <display>
|
|
32
|
+
const displayEl = findChild(root, ['display']);
|
|
33
|
+
if (displayEl) {
|
|
34
|
+
profile.display = {};
|
|
35
|
+
|
|
36
|
+
const colorSchemeEl = findChild(displayEl, ['colorscheme', 'color-scheme']);
|
|
37
|
+
if (colorSchemeEl) {
|
|
38
|
+
const val = (colorSchemeEl.getAttribute('value') ?? colorSchemeEl.text ?? '').trim().toLowerCase();
|
|
39
|
+
if (isColorScheme(val)) profile.display.colorScheme = val;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const magEl = findChild(displayEl, ['magnification']);
|
|
43
|
+
if (magEl) {
|
|
44
|
+
const val = parseFloat(magEl.getAttribute('value') ?? magEl.text ?? '');
|
|
45
|
+
if (Number.isFinite(val) && val > 0) profile.display.magnification = val;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// <content>
|
|
50
|
+
const contentEl = findChild(root, ['content']);
|
|
51
|
+
if (contentEl) {
|
|
52
|
+
profile.content = {};
|
|
53
|
+
|
|
54
|
+
const glossaryEl = findChild(contentEl, ['glossaryonscreen', 'glossary-on-screen']);
|
|
55
|
+
if (glossaryEl) {
|
|
56
|
+
profile.content.glossaryOnScreen = parseBool(glossaryEl.getAttribute('enabled') ?? glossaryEl.text ?? 'true');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const kwEl = findChild(contentEl, ['keywordtranslation', 'keyword-translation']);
|
|
60
|
+
if (kwEl) {
|
|
61
|
+
const active = parseBool(kwEl.getAttribute('active') ?? 'true');
|
|
62
|
+
const languageCode = (kwEl.getAttribute('languagecode') ?? kwEl.getAttribute('language-code') ?? kwEl.getAttribute('lang') ?? '').trim();
|
|
63
|
+
if (languageCode) profile.content.keywordTranslation = { active, languageCode };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const etEl = findChild(contentEl, ['extendedtime', 'extended-time']);
|
|
67
|
+
if (etEl) {
|
|
68
|
+
const active = parseBool(etEl.getAttribute('active') ?? 'true');
|
|
69
|
+
const rawMultiplier = etEl.getAttribute('multiplier') ?? etEl.text ?? '';
|
|
70
|
+
const multiplier = rawMultiplier.trim().toLowerCase() === 'infinity'
|
|
71
|
+
? Infinity
|
|
72
|
+
: parseFloat(rawMultiplier);
|
|
73
|
+
if (Number.isFinite(multiplier) || multiplier === Infinity) {
|
|
74
|
+
profile.content.extendedTime = { active, multiplier };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// <cognitive>
|
|
80
|
+
const cogEl = findChild(root, ['cognitive']);
|
|
81
|
+
if (cogEl) {
|
|
82
|
+
profile.cognitive = {};
|
|
83
|
+
|
|
84
|
+
const elTool = findChild(cogEl, ['eliminationtool', 'elimination-tool']);
|
|
85
|
+
if (elTool) {
|
|
86
|
+
profile.cognitive.eliminationTool = parseBool(
|
|
87
|
+
elTool.getAttribute('enabled') ?? elTool.getAttribute('active') ?? elTool.text ?? 'true'
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return profile;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Helpers
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
function findChild(parent: NhpElement, names: string[]): NhpElement | null {
|
|
100
|
+
for (const child of parent.childNodes) {
|
|
101
|
+
if (child.nodeType !== 1) continue; // element nodes only
|
|
102
|
+
const el = child as NhpElement;
|
|
103
|
+
const tag = (el.rawTagName ?? '').toLowerCase();
|
|
104
|
+
if (names.includes(tag)) return el;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseBool(value: string): boolean {
|
|
110
|
+
const v = (value ?? '').trim().toLowerCase();
|
|
111
|
+
return v !== 'false' && v !== '0' && v !== 'no';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type ColorScheme = PnpProfile['display'] extends { colorScheme?: infer C } ? Exclude<C, undefined> : never;
|
|
115
|
+
const COLOR_SCHEMES = new Set<string>(['default', 'blackwhite', 'whitenav', 'blackcream', 'yellowblue', 'medgray']);
|
|
116
|
+
function isColorScheme(v: string): v is ColorScheme {
|
|
117
|
+
return COLOR_SCHEMES.has(v);
|
|
118
|
+
}
|
package/src/pnp/types.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI 3.0 §6.2 Personal Needs and Preferences profile.
|
|
3
|
+
* All fields are optional; absent means "use platform default".
|
|
4
|
+
*/
|
|
5
|
+
export interface PnpProfile {
|
|
6
|
+
display?: {
|
|
7
|
+
/**
|
|
8
|
+
* Named color scheme. Maps to the data-qti-colorscheme attribute on the player root.
|
|
9
|
+
* 'default' or undefined → attribute removed (browser/host default).
|
|
10
|
+
*/
|
|
11
|
+
colorScheme?: 'default' | 'blackwhite' | 'whitenav' | 'blackcream' | 'yellowblue' | 'medgray';
|
|
12
|
+
/**
|
|
13
|
+
* CSS zoom factor (1.0 = 100%). Deferred — set by browser zoom or host stylesheet.
|
|
14
|
+
* Stored here for forward-compatibility but not yet applied by the player.
|
|
15
|
+
*/
|
|
16
|
+
magnification?: number;
|
|
17
|
+
};
|
|
18
|
+
content?: {
|
|
19
|
+
/** Show glossary trigger buttons on [data-catalog-idref] terms (G-10). */
|
|
20
|
+
glossaryOnScreen?: boolean;
|
|
21
|
+
/** Show keyword-translation trigger buttons using the given language code. */
|
|
22
|
+
keywordTranslation?: { active: boolean; languageCode: string };
|
|
23
|
+
/**
|
|
24
|
+
* Scale assessment time limits. multiplier: 1.5 means 50% extra time.
|
|
25
|
+
* multiplier: Infinity removes the time limit entirely.
|
|
26
|
+
*/
|
|
27
|
+
extendedTime?: { active: boolean; multiplier: number };
|
|
28
|
+
};
|
|
29
|
+
cognitive?: {
|
|
30
|
+
/** Render per-choice elimination toggle buttons in choiceInteraction and orderInteraction. */
|
|
31
|
+
eliminationTool?: boolean;
|
|
32
|
+
};
|
|
33
|
+
}
|