@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
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the plugin-based element extraction system
|
|
3
|
+
*
|
|
4
|
+
* Provides interfaces for extracting data from QTI XML elements with
|
|
5
|
+
* priority-based dispatch, validation, and type safety.
|
|
6
|
+
*/
|
|
7
|
+
import type { PlayerConfig } from '../types/index.js';
|
|
8
|
+
import type { QTIElement } from '../types/interactions.js';
|
|
9
|
+
/**
|
|
10
|
+
* Context provided to extractors during extraction
|
|
11
|
+
* Contains DOM reference, utilities, and metadata
|
|
12
|
+
*/
|
|
13
|
+
export interface ExtractionContext {
|
|
14
|
+
/** The element being extracted */
|
|
15
|
+
element: QTIElement;
|
|
16
|
+
/** Response identifier for this interaction */
|
|
17
|
+
responseId: string;
|
|
18
|
+
/** Root DOM element for document-wide queries */
|
|
19
|
+
dom: QTIElement;
|
|
20
|
+
/** Variable declarations from responseDeclaration/outcomeDeclaration */
|
|
21
|
+
declarations: Map<string, VariableDeclaration>;
|
|
22
|
+
/** Utility functions for DOM manipulation and extraction */
|
|
23
|
+
utils: ExtractionUtils;
|
|
24
|
+
/** Player configuration (role, typesetting, etc.) */
|
|
25
|
+
config: PlayerConfig;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Variable declaration from QTI responseDeclaration/outcomeDeclaration
|
|
29
|
+
*/
|
|
30
|
+
export interface VariableDeclaration {
|
|
31
|
+
identifier: string;
|
|
32
|
+
cardinality: 'single' | 'multiple' | 'ordered' | 'record';
|
|
33
|
+
baseType?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Utility functions available to extractors
|
|
37
|
+
* Provides safe, consistent DOM manipulation and content extraction
|
|
38
|
+
*/
|
|
39
|
+
export interface ExtractionUtils {
|
|
40
|
+
/**
|
|
41
|
+
* Get direct children with a specific tag name
|
|
42
|
+
* @example utils.getChildrenByTag(element, 'simpleChoice')
|
|
43
|
+
*/
|
|
44
|
+
getChildrenByTag(element: QTIElement, tagName: string): QTIElement[];
|
|
45
|
+
/**
|
|
46
|
+
* Query all descendants matching a selector
|
|
47
|
+
* @example utils.querySelectorAll(element, 'choiceInteraction simpleChoice')
|
|
48
|
+
*/
|
|
49
|
+
querySelectorAll(element: QTIElement, selector: string): QTIElement[];
|
|
50
|
+
/**
|
|
51
|
+
* Query first descendant matching a selector
|
|
52
|
+
* @example utils.querySelector(element, 'prompt')
|
|
53
|
+
*/
|
|
54
|
+
querySelector(element: QTIElement, selector: string): QTIElement | null;
|
|
55
|
+
/**
|
|
56
|
+
* Check if element has a child with specific tag (fast boolean check)
|
|
57
|
+
* @example utils.hasChildWithTag(element, 'ratingChoice')
|
|
58
|
+
*/
|
|
59
|
+
hasChildWithTag(element: QTIElement, tagName: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get sanitized HTML content from element
|
|
62
|
+
* @example utils.getHtmlContent(element) // '<p>Question <math>...</math></p>'
|
|
63
|
+
*/
|
|
64
|
+
getHtmlContent(element: QTIElement): string;
|
|
65
|
+
/**
|
|
66
|
+
* Get plain text content (strips HTML tags)
|
|
67
|
+
* @example utils.getTextContent(element) // 'Question text'
|
|
68
|
+
*/
|
|
69
|
+
getTextContent(element: QTIElement): string;
|
|
70
|
+
/**
|
|
71
|
+
* Get attribute value with optional default
|
|
72
|
+
* @example utils.getAttribute(element, 'identifier', '')
|
|
73
|
+
*/
|
|
74
|
+
getAttribute(element: QTIElement, name: string, defaultValue?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Get boolean attribute value with optional default
|
|
77
|
+
* @example utils.getBooleanAttribute(element, 'shuffle', false) // true
|
|
78
|
+
*/
|
|
79
|
+
getBooleanAttribute(element: QTIElement, name: string, defaultValue?: boolean): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get numeric attribute value with optional default
|
|
82
|
+
* @example utils.getNumberAttribute(element, 'maxChoices', 1) // 1
|
|
83
|
+
*/
|
|
84
|
+
getNumberAttribute(element: QTIElement, name: string, defaultValue?: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Get CSS classes from element
|
|
87
|
+
* @example utils.getClasses(element) // ['rating-interaction', 'custom']
|
|
88
|
+
*/
|
|
89
|
+
getClasses(element: QTIElement): string[];
|
|
90
|
+
/**
|
|
91
|
+
* Extract prompt element text from an interaction
|
|
92
|
+
* @example utils.getPrompt(element) // '<p>Select the correct answer</p>'
|
|
93
|
+
*/
|
|
94
|
+
getPrompt(element: QTIElement): string | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Result of validation
|
|
98
|
+
*/
|
|
99
|
+
export interface ValidationResult {
|
|
100
|
+
/** Whether validation passed */
|
|
101
|
+
valid: boolean;
|
|
102
|
+
/** Error messages if validation failed */
|
|
103
|
+
errors?: string[];
|
|
104
|
+
/** Warning messages (non-fatal) */
|
|
105
|
+
warnings?: string[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Error thrown during extraction
|
|
109
|
+
*/
|
|
110
|
+
export declare class ExtractionError extends Error {
|
|
111
|
+
readonly extractorId: string;
|
|
112
|
+
readonly elementType: string;
|
|
113
|
+
readonly cause?: Error | undefined;
|
|
114
|
+
constructor(message: string, extractorId: string, elementType: string, cause?: Error | undefined);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Result of extraction operation
|
|
118
|
+
*/
|
|
119
|
+
export type ExtractionResult<TData> = {
|
|
120
|
+
success: true;
|
|
121
|
+
data: TData;
|
|
122
|
+
warnings?: string[];
|
|
123
|
+
} | {
|
|
124
|
+
success: false;
|
|
125
|
+
error: ExtractionError;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Element extractor with priority-based dispatch
|
|
129
|
+
*
|
|
130
|
+
* @template TData - The extracted data type (e.g., ChoiceData, TextEntryData)
|
|
131
|
+
* @template TContext - The extraction context type (defaults to ExtractionContext)
|
|
132
|
+
*/
|
|
133
|
+
export interface ElementExtractor<TData = unknown, TContext extends ExtractionContext = ExtractionContext> {
|
|
134
|
+
/**
|
|
135
|
+
* Unique identifier for this extractor
|
|
136
|
+
* Convention: 'namespace:element-type' (e.g., 'qti:choice', 'renaissance:rating-choice')
|
|
137
|
+
*/
|
|
138
|
+
id: string;
|
|
139
|
+
/**
|
|
140
|
+
* Human-readable name for debugging/error messages
|
|
141
|
+
* @example 'QTI Standard Choice Interaction'
|
|
142
|
+
*/
|
|
143
|
+
name: string;
|
|
144
|
+
/**
|
|
145
|
+
* Priority for extractor evaluation (higher = checked first)
|
|
146
|
+
* - 1000+: Critical system extractors (error handlers, etc.)
|
|
147
|
+
* - 500-999: Vendor-specific extractors (Renaissance, custom content)
|
|
148
|
+
* - 100-499: Third-party plugin extractors
|
|
149
|
+
* - 1-99: Standard QTI extractors with variations
|
|
150
|
+
* - 0: Fallback/default extractors
|
|
151
|
+
*/
|
|
152
|
+
priority: number;
|
|
153
|
+
/**
|
|
154
|
+
* Element types this extractor handles (for type-based indexing)
|
|
155
|
+
* Used for O(M) lookup instead of O(N) scanning
|
|
156
|
+
* @example ['choiceInteraction', 'inlineChoiceInteraction']
|
|
157
|
+
*/
|
|
158
|
+
elementTypes: string[];
|
|
159
|
+
/**
|
|
160
|
+
* Optional description for debugging/error messages
|
|
161
|
+
* @example 'Handles Renaissance rating choice interactions with star/face icons'
|
|
162
|
+
*/
|
|
163
|
+
description?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Predicate to determine if this extractor can handle the element
|
|
166
|
+
* Evaluated in priority order (highest first)
|
|
167
|
+
*
|
|
168
|
+
* IMPORTANT: Must be FAST - use quick checks first
|
|
169
|
+
* @example
|
|
170
|
+
* canHandle(element, context) {
|
|
171
|
+
* // Fast checks first
|
|
172
|
+
* if (!context.utils.hasChildWithTag(element, 'ratingChoice')) return false;
|
|
173
|
+
* // Expensive checks only if fast checks pass
|
|
174
|
+
* return validateRatingStructure(element);
|
|
175
|
+
* }
|
|
176
|
+
*/
|
|
177
|
+
canHandle(element: QTIElement, context: TContext): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Extract data from the element
|
|
180
|
+
* Called only if canHandle() returns true
|
|
181
|
+
*
|
|
182
|
+
* @throws ExtractionError if extraction fails
|
|
183
|
+
* @returns Extracted data structure
|
|
184
|
+
*/
|
|
185
|
+
extract(element: QTIElement, context: TContext): TData;
|
|
186
|
+
/**
|
|
187
|
+
* Validate extracted data (optional)
|
|
188
|
+
* Called after extract() succeeds
|
|
189
|
+
*
|
|
190
|
+
* @returns Validation result with errors/warnings
|
|
191
|
+
*/
|
|
192
|
+
validate?(data: TData): ValidationResult;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Type guard for successful extraction result
|
|
196
|
+
*/
|
|
197
|
+
export declare function isSuccessResult<TData>(result: ExtractionResult<TData>): result is {
|
|
198
|
+
success: true;
|
|
199
|
+
data: TData;
|
|
200
|
+
warnings?: string[];
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Type guard for failed extraction result
|
|
204
|
+
*/
|
|
205
|
+
export declare function isErrorResult<TData>(result: ExtractionResult<TData>): result is {
|
|
206
|
+
success: false;
|
|
207
|
+
error: ExtractionError;
|
|
208
|
+
};
|
|
209
|
+
//# sourceM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
|
3
|
+
*
|
|
4
|
+
* Provides interfaces for extracting data from QTI XML elements with
|
|
5
|
+
* priority-based dispatch, validation, and type safety.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown during extraction
|
|
9
|
+
*/
|
|
10
|
+
export class ExtractionError extends Error {
|
|
11
|
+
constructor(message, extractorId, elementType, cause) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.extractorId = extractorId;
|
|
14
|
+
this.elementType = elementType;
|
|
15
|
+
this.cause = cause;
|
|
16
|
+
this.name = 'ExtractionError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Type guard for successful extraction result
|
|
21
|
+
*/
|
|
22
|
+
export function isSuccessResult(result) {
|
|
23
|
+
return result.success === true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard for failed extraction result
|
|
27
|
+
*/
|
|
28
|
+
export function isErrorResult(result) {
|
|
29
|
+
return result.success === false;
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction utilities implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides DOM manipulation and content extraction helpers for extractors
|
|
5
|
+
*/
|
|
6
|
+
import type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';
|
|
7
|
+
import type { PlayerSecurityConfig } from '../types/index.js';
|
|
8
|
+
import type { ExtractionUtils } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create extraction utilities instance
|
|
11
|
+
* Provides standard helpers for extracting data from QTI elements.
|
|
12
|
+
* Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createExtractionUtils(security?: PlayerSecurityConfig, mapper?: ElementNameMapper, attributeMapper?: AttributeNameMapper): ExtractionUtils;
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/extraction/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGlF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA6IlD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,CAAC,EAAE,oBAAoB,EAC/B,MAAM,CAAC,EAAE,iBAAiB,EAC1B,eAAe,CAAC,EAAE,mBAAmB,GACnC,eAAe,CAiFjB"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction utilities implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides DOM manipulation and content extraction helpers for extractors
|
|
5
|
+
*/
|
|
6
|
+
import { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';
|
|
7
|
+
import { sanitizeTextContent } from '../core/sanitizer.js';
|
|
8
|
+
/**
|
|
9
|
+
* Extract text content from QTI elements
|
|
10
|
+
*/
|
|
11
|
+
function getTextContent(element) {
|
|
12
|
+
return element?.textContent?.trim() || '';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extract HTML content from QTI elements (preserves MathML and other markup)
|
|
16
|
+
* Content is sanitized to prevent XSS attacks
|
|
17
|
+
*/
|
|
18
|
+
function getHtmlContent(element) {
|
|
19
|
+
const html = element?.innerHTML?.trim() || '';
|
|
20
|
+
return sanitizeTextContent(html);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get children by tag name from QTI elements
|
|
24
|
+
* Note: This version does NOT handle QTI version mapping - use the one in ExtractionUtils instead
|
|
25
|
+
*/
|
|
26
|
+
function getChildrenByTag(element, tagName) {
|
|
27
|
+
return element?.childNodes?.filter((n) => n.rawTagName === tagName) || [];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get children by tag name with QTI version awareness
|
|
31
|
+
*/
|
|
32
|
+
function getChildrenByTagWithMapper(element, tagName, mapper) {
|
|
33
|
+
if (!element?.childNodes)
|
|
34
|
+
return [];
|
|
35
|
+
return element.childNodes.filter((n) => matchesTagName(n.rawTagName, tagName, mapper));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Extract a boolean attribute from a QTI element
|
|
39
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
40
|
+
*/
|
|
41
|
+
function getBooleanAttribute(element, name, defaultValue = false, attributeMapper) {
|
|
42
|
+
let value = element.getAttribute(name);
|
|
43
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
44
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
45
|
+
const nativeName = attributeMapper.toNative(name);
|
|
46
|
+
value = element.getAttribute(nativeName);
|
|
47
|
+
}
|
|
48
|
+
if (value === null || value === undefined)
|
|
49
|
+
return defaultValue;
|
|
50
|
+
return value === 'true';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extract a number attribute from a QTI element
|
|
54
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
55
|
+
*/
|
|
56
|
+
function getNumberAttribute(element, name, defaultValue, attributeMapper) {
|
|
57
|
+
let value = element.getAttribute(name);
|
|
58
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
59
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
60
|
+
const nativeName = attributeMapper.toNative(name);
|
|
61
|
+
value = element.getAttribute(nativeName);
|
|
62
|
+
}
|
|
63
|
+
return value ? Number(value) : defaultValue;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Extract a string attribute from a QTI element
|
|
67
|
+
* Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes
|
|
68
|
+
*/
|
|
69
|
+
function getStringAttribute(element, name, defaultValue = '', attributeMapper) {
|
|
70
|
+
let value = element.getAttribute(name);
|
|
71
|
+
// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)
|
|
72
|
+
if ((value === null || value === undefined) && attributeMapper) {
|
|
73
|
+
const nativeName = attributeMapper.toNative(name);
|
|
74
|
+
value = element.getAttribute(nativeName);
|
|
75
|
+
}
|
|
76
|
+
return value || defaultValue;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract CSS classes from an element
|
|
80
|
+
*/
|
|
81
|
+
function getClasses(element) {
|
|
82
|
+
const classAttr = element.getAttribute('class');
|
|
83
|
+
return classAttr ? classAttr.split(/\s+/).filter(Boolean) : [];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Helper to check if an element's tag name matches a given QTI element name.
|
|
87
|
+
* Handles both QTI 2.x and QTI 3.0 element naming conventions.
|
|
88
|
+
*
|
|
89
|
+
* @param rawTagName - The element's raw tag name from the HTML
|
|
90
|
+
* @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')
|
|
91
|
+
* @param mapper - Optional element name mapper for QTI version handling
|
|
92
|
+
* @returns true if the tag name matches
|
|
93
|
+
*/
|
|
94
|
+
function matchesTagName(rawTagName, expectedTagName, mapper) {
|
|
95
|
+
if (!rawTagName)
|
|
96
|
+
return false;
|
|
97
|
+
// Convert expected tag name to canonical form (lowercase)
|
|
98
|
+
const canonical = expectedTagName.toLowerCase();
|
|
99
|
+
// Get the native form for this QTI version
|
|
100
|
+
const native = mapper.toNative(canonical);
|
|
101
|
+
// Check if raw tag name matches the native form (case-insensitive)
|
|
102
|
+
return rawTagName.toLowerCase() === native.toLowerCase();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create extraction utilities instance
|
|
106
|
+
* Provides standard helpers for extracting data from QTI elements.
|
|
107
|
+
* Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.
|
|
108
|
+
*/
|
|
109
|
+
export function createExtractionUtils(security, mapper, attributeMapper) {
|
|
110
|
+
// Default to QTI 2.x mappers (primary supported QTI format)
|
|
111
|
+
const elementMapper = mapper || new Qti2xElementNameMapper();
|
|
112
|
+
const attrMapper = attributeMapper || new Qti2xAttributeNameMapper();
|
|
113
|
+
return {
|
|
114
|
+
getChildrenByTag(element, tagName) {
|
|
115
|
+
return getChildrenByTagWithMapper(element, tagName, elementMapper);
|
|
116
|
+
},
|
|
117
|
+
querySelectorAll(element, selector) {
|
|
118
|
+
// Parse simple selectors like "choiceInteraction simpleChoice"
|
|
119
|
+
const parts = selector.split(/\s+/);
|
|
120
|
+
let results = [element];
|
|
121
|
+
for (const part of parts) {
|
|
122
|
+
const nextResults = [];
|
|
123
|
+
for (const current of results) {
|
|
124
|
+
if (matchesTagName(current.rawTagName, part, elementMapper)) {
|
|
125
|
+
nextResults.push(current);
|
|
126
|
+
}
|
|
127
|
+
if (current.childNodes) {
|
|
128
|
+
for (const child of current.childNodes) {
|
|
129
|
+
if (typeof child !== 'string' && matchesTagName(child.rawTagName, part, elementMapper)) {
|
|
130
|
+
nextResults.push(child);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
results = nextResults;
|
|
136
|
+
}
|
|
137
|
+
return results;
|
|
138
|
+
},
|
|
139
|
+
querySelector(element, selector) {
|
|
140
|
+
const results = this.querySelectorAll(element, selector);
|
|
141
|
+
return results.length > 0 ? results[0] : null;
|
|
142
|
+
},
|
|
143
|
+
hasChildWithTag(element, tagName) {
|
|
144
|
+
// Fast boolean check without allocation
|
|
145
|
+
if (!element.childNodes)
|
|
146
|
+
return false;
|
|
147
|
+
for (const child of element.childNodes) {
|
|
148
|
+
if (typeof child !== 'string' && matchesTagName(child.rawTagName, tagName, elementMapper)) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
},
|
|
154
|
+
getHtmlContent(element) {
|
|
155
|
+
const html = element?.innerHTML?.trim() || '';
|
|
156
|
+
return sanitizeTextContent(html, { security });
|
|
157
|
+
},
|
|
158
|
+
getTextContent(element) {
|
|
159
|
+
return getTextContent(element);
|
|
160
|
+
},
|
|
161
|
+
getAttribute(element, name, defaultValue = '') {
|
|
162
|
+
return getStringAttribute(element, name, defaultValue, attrMapper);
|
|
163
|
+
},
|
|
164
|
+
getBooleanAttribute(element, name, defaultValue = false) {
|
|
165
|
+
return getBooleanAttribute(element, name, defaultValue, attrMapper);
|
|
166
|
+
},
|
|
167
|
+
getNumberAttribute(element, name, defaultValue = 0) {
|
|
168
|
+
return getNumberAttribute(element, name, defaultValue, attrMapper);
|
|
169
|
+
},
|
|
170
|
+
getPrompt(element) {
|
|
171
|
+
const promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];
|
|
172
|
+
return promptElement ? getHtmlContent(promptElement) : null;
|
|
173
|
+
},
|
|
174
|
+
getClasses(element) {
|
|
175
|
+
return getClasses(element);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-only iframe host helper.
|
|
3
|
+
*
|
|
4
|
+
* This intentionally depends on DOM globals and must be imported via the subpath:
|
|
5
|
+
* - `@pie-qti/item-player/iframe`
|
|
6
|
+
*
|
|
7
|
+
* Do NOT export from the main entrypoint to keep SSR safe.
|
|
8
|
+
*/
|
|
9
|
+
import type { PlayerSecurityConfig, QTIRole } from '../types/index.js';
|
|
10
|
+
import { type QtiIframeProtocolVersion } from './protocol.js';
|
|
11
|
+
export interface IFramePlayerHostConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The URL to load inside the iframe (the integrator-hosted runtime page).
|
|
14
|
+
* For best isolation, host this on a separate origin.
|
|
15
|
+
*/
|
|
16
|
+
iframeUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Allowed runtime origins. Incoming messages from other origins are ignored.
|
|
19
|
+
*
|
|
20
|
+
* Examples:
|
|
21
|
+
* - `['https://player-runtime.example']`
|
|
22
|
+
* - `['http://localhost:5173']`
|
|
23
|
+
*/
|
|
24
|
+
allowedOrigins: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Either provide an existing iframe, or provide a container and the host will create one.
|
|
27
|
+
*/
|
|
28
|
+
iframe?: HTMLIFrameElement;
|
|
29
|
+
container?: HTMLElement;
|
|
30
|
+
/**
|
|
31
|
+
* Sandbox attribute value. If not provided, defaults to a safe baseline.
|
|
32
|
+
*
|
|
33
|
+
* Default: `allow-scripts` (no allow-same-origin).
|
|
34
|
+
*/
|
|
35
|
+
sandbox?: string;
|
|
36
|
+
/**
|
|
37
|
+
* When true, automatically sets `iframe.style.height` on RESIZE messages.
|
|
38
|
+
* Default: true.
|
|
39
|
+
*/
|
|
40
|
+
autoResize?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Default: `no-referrer` to reduce leakage when loading assets.
|
|
43
|
+
*/
|
|
44
|
+
referrerPolicy?: HTMLIFrameElement['referrerPolicy'];
|
|
45
|
+
/**
|
|
46
|
+
* Milliseconds to wait for READY before rejecting init/commands.
|
|
47
|
+
* Default: 10s.
|
|
48
|
+
*/
|
|
49
|
+
readyTimeoutMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export type IFramePlayerHostEvent = {
|
|
52
|
+
type: 'ready';
|
|
53
|
+
payload: {
|
|
54
|
+
origin: string;
|
|
55
|
+
version: QtiIframeProtocolVersion;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
type: 'resize';
|
|
59
|
+
payload: {
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
62
|
+
} | {
|
|
63
|
+
type: 'responseChange';
|
|
64
|
+
payload: {
|
|
65
|
+
responses: Record<string, unknown>;
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
type: 'submitResult';
|
|
69
|
+
payload: {
|
|
70
|
+
result: unknown;
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
type: 'error';
|
|
74
|
+
payload: {
|
|
75
|
+
message: string;
|
|
76
|
+
code?: string;
|
|
77
|
+
details?: unknown;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export declare class IFramePlayerHost {
|
|
81
|
+
private readonly config;
|
|
82
|
+
private readonly iframe;
|
|
83
|
+
private readonly pendingReady;
|
|
84
|
+
private resolveReady;
|
|
85
|
+
private rejectReady;
|
|
86
|
+
private lockedOrigin;
|
|
87
|
+
private destroyed;
|
|
88
|
+
private readonly listeners;
|
|
89
|
+
private readonly onMessageBound;
|
|
90
|
+
constructor(config: IFramePlayerHostConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to host events.
|
|
93
|
+
* Returns an unsubscribe function.
|
|
94
|
+
*/
|
|
95
|
+
on(listener: (event: IFramePlayerHostEvent) => void): () => void;
|
|
96
|
+
private emit;
|
|
97
|
+
getIFrameElement(): HTMLIFrameElement;
|
|
98
|
+
/**
|
|
99
|
+
* Resolves once the runtime has sent READY and origin is locked.
|
|
100
|
+
*/
|
|
101
|
+
ready(): Promise<{
|
|
102
|
+
origin: string;
|
|
103
|
+
version: QtiIframeProtocolVersion;
|
|
104
|
+
}>;
|
|
105
|
+
init(params: {
|
|
106
|
+
itemXml: string;
|
|
107
|
+
role?: QTIRole;
|
|
108
|
+
seed?: number;
|
|
109
|
+
security?: PlayerSecurityConfig;
|
|
110
|
+
responses?: Record<string, unknown>;
|
|
111
|
+
runtimeConfig?: Record<string, unknown>;
|
|
112
|
+
}): Promise<void>;
|
|
113
|
+
setResponses(responses: Record<string, unknown>): Promise<void>;
|
|
114
|
+
submit(): Promise<void>;
|
|
115
|
+
reset(): Promise<void>;
|
|
116
|
+
destroy(): void;
|
|
117
|
+
private post;
|
|
118
|
+
private onMessage;
|
|
119
|
+
private isAllowedOrigin;
|
|
120
|
+
private handleMessage;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=IFramePlayerHost.d.ts.map
|
|
@@ -0,0 +1 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