@pie-qti/item-player 0.1.1 → 0.1.4
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 +1 -1
- 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 +119 -0
- package/dist/core/ComponentRegistry.d.ts.map +1 -0
- package/dist/core/ComponentRegistry.js +123 -0
- package/dist/core/ItemRenderer.d.ts +91 -0
- package/dist/core/ItemRenderer.d.ts.map +1 -0
- package/dist/core/ItemRenderer.js +258 -0
- package/dist/core/Player.d.ts +143 -0
- package/dist/core/Player.d.ts.map +1 -0
- package/dist/core/Player.js +1081 -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/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 +87 -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 +258 -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 +28 -0
- package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/associateExtractor.js +94 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts +25 -0
- package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/choiceExtractor.js +83 -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 +57 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts +28 -0
- package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/gapMatchExtractor.js +142 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +40 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/graphicAssociateExtractor.js +140 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +42 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/graphicGapMatchExtractor.js +144 -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 +140 -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 +120 -0
- package/dist/extraction/extractors/index.d.ts +62 -0
- package/dist/extraction/extractors/index.d.ts.map +1 -0
- package/dist/extraction/extractors/index.js +84 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +22 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/inlineChoiceExtractor.js +67 -0
- package/dist/extraction/extractors/matchExtractor.d.ts +32 -0
- package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/matchExtractor.js +134 -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 +26 -0
- package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/orderExtractor.js +86 -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 +20 -0
- package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -0
- package/dist/extraction/extractors/textEntryExtractor.js +48 -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 +52 -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 +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -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 +290 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/interactions.d.ts +323 -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 +94 -76
- 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/components/ItemBody.svelte +3 -1
- package/src/components/utils/assignProps.ts +1 -23
- package/src/core/Player.ts +138 -34
- package/src/core/parsingLimits.ts +1 -1
- package/src/extensions/MathLiveEditor.ts +6 -3
- package/src/extraction/ExtractionRegistry.ts +46 -10
- package/src/extraction/createContext.ts +6 -1
- package/src/extraction/extractors/extendedTextExtractor.ts +5 -2
- package/src/extraction/extractors/matchExtractor.ts +2 -2
- package/src/extraction/extractors/textEntryExtractor.ts +4 -2
- package/src/extraction/utils.ts +99 -16
- package/src/index.ts +2 -0
- package/src/types/index.ts +28 -8
- 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,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QTI variable declarations management
|
|
3
|
+
* Ported from an earlier implementation
|
|
4
|
+
*/
|
|
5
|
+
import { BUILTIN_DECLARATIONS } from './constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Initialize declarations for an element
|
|
8
|
+
*/
|
|
9
|
+
export function initializeDeclarations(declarations) {
|
|
10
|
+
// Clone built-in declarations
|
|
11
|
+
Object.keys(BUILTIN_DECLARATIONS).forEach((id) => {
|
|
12
|
+
const builtinDecl = BUILTIN_DECLARATIONS[id];
|
|
13
|
+
declarations[id] = { ...builtinDecl };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Add a response or outcome declaration
|
|
18
|
+
*/
|
|
19
|
+
export function addDeclaration(declarations, identifier, baseType, cardinality, defaultValue) {
|
|
20
|
+
const value = cardinality === 'multiple' ? [] : null;
|
|
21
|
+
declarations[identifier] = {
|
|
22
|
+
identifier,
|
|
23
|
+
baseType,
|
|
24
|
+
cardinality,
|
|
25
|
+
value: defaultValue ?? value,
|
|
26
|
+
defaultValue,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add a mapping to a response declaration
|
|
31
|
+
*/
|
|
32
|
+
export function addMapping(declarations, identifier, mapping) {
|
|
33
|
+
const decl = declarations[identifier];
|
|
34
|
+
if (decl) {
|
|
35
|
+
decl.mapping = mapping;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add an area mapping to a response declaration
|
|
40
|
+
*/
|
|
41
|
+
export function addAreaMapping(declarations, identifier, areaMapping) {
|
|
42
|
+
const decl = declarations[identifier];
|
|
43
|
+
if (decl) {
|
|
44
|
+
decl.areaMapping = areaMapping;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a variable value from declarations
|
|
49
|
+
* @returns {any} QTI variables can hold any type
|
|
50
|
+
*/
|
|
51
|
+
export function getVariableValue(declarations, identifier) {
|
|
52
|
+
const decl = declarations[identifier];
|
|
53
|
+
return decl ? decl.value : null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set a variable value in declarations
|
|
57
|
+
*/
|
|
58
|
+
export function setVariableValue(declarations, identifier, value) {
|
|
59
|
+
const decl = declarations[identifier];
|
|
60
|
+
if (decl) {
|
|
61
|
+
const coerceScalar = (v) => {
|
|
62
|
+
if (v === null || v === undefined)
|
|
63
|
+
return v;
|
|
64
|
+
const baseType = decl.baseType;
|
|
65
|
+
if (baseType === 'integer' || baseType === 'float') {
|
|
66
|
+
const n = Number(v);
|
|
67
|
+
return Number.isNaN(n) ? v : n;
|
|
68
|
+
}
|
|
69
|
+
if (baseType === 'boolean') {
|
|
70
|
+
if (typeof v === 'boolean')
|
|
71
|
+
return v;
|
|
72
|
+
if (typeof v === 'number')
|
|
73
|
+
return v !== 0;
|
|
74
|
+
if (typeof v === 'string')
|
|
75
|
+
return v.trim().toLowerCase() === 'true';
|
|
76
|
+
return Boolean(v);
|
|
77
|
+
}
|
|
78
|
+
if (baseType === 'string' ||
|
|
79
|
+
baseType === 'identifier' ||
|
|
80
|
+
baseType === 'uri' ||
|
|
81
|
+
baseType === 'pair' ||
|
|
82
|
+
baseType === 'directedPair' ||
|
|
83
|
+
baseType === 'point') {
|
|
84
|
+
return typeof v === 'string' ? v.trim() : String(v);
|
|
85
|
+
}
|
|
86
|
+
return v;
|
|
87
|
+
};
|
|
88
|
+
if (decl.cardinality === 'multiple' || decl.cardinality === 'ordered') {
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
decl.value = value.map(coerceScalar);
|
|
91
|
+
}
|
|
92
|
+
else if (value === null || value === undefined) {
|
|
93
|
+
decl.value = [];
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
decl.value = [coerceScalar(value)];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
decl.value = coerceScalar(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reset declarations to default values
|
|
106
|
+
*/
|
|
107
|
+
export function resetDeclarations(declarations) {
|
|
108
|
+
Object.values(declarations).forEach((decl) => {
|
|
109
|
+
if (decl.defaultValue !== undefined) {
|
|
110
|
+
decl.value = decl.defaultValue;
|
|
111
|
+
}
|
|
112
|
+
else if (decl.cardinality === 'multiple') {
|
|
113
|
+
decl.value = [];
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
decl.value = null;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clone declarations (useful for creating new sessions)
|
|
122
|
+
*/
|
|
123
|
+
export function cloneDeclarations(source) {
|
|
124
|
+
const result = {};
|
|
125
|
+
Object.keys(source).forEach((id) => {
|
|
126
|
+
const decl = source[id];
|
|
127
|
+
result[id] = {
|
|
128
|
+
...decl,
|
|
129
|
+
value: decl.cardinality === 'multiple' && Array.isArray(decl.value) ? [...decl.value] : decl.value,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PlayerSecurityConfig } from '../types/index.js';
|
|
2
|
+
export type NormalizedParsingLimits = {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
rejectDoctype: boolean;
|
|
5
|
+
maxItemXmlBytes: number;
|
|
6
|
+
maxHtmlBytes: number;
|
|
7
|
+
maxHtmlNodes: number;
|
|
8
|
+
maxHtmlDepth: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function normalizeParsingLimits(security?: PlayerSecurityConfig): NormalizedParsingLimits;
|
|
11
|
+
export declare function enforceItemXmlLimits(itemXml: string, security?: PlayerSecurityConfig): void;
|
|
12
|
+
//# sourceMappingURL=parsingLimits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsingLimits.d.ts","sourceRoot":"","sources":["../../src/core/parsingLimits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,MAAM,uBAAuB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAkBF,wBAAgB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,uBAAuB,CAe/F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAe3F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const DEFAULTS = {
|
|
2
|
+
rejectDoctype: true,
|
|
3
|
+
maxItemXmlBytes: 10000000,
|
|
4
|
+
maxHtmlBytes: 5000000,
|
|
5
|
+
maxHtmlNodes: 200000,
|
|
6
|
+
maxHtmlDepth: 200,
|
|
7
|
+
};
|
|
8
|
+
function getByteLengthUtf8(s) {
|
|
9
|
+
// TextEncoder is available in modern runtimes (browser + Bun/node 20+).
|
|
10
|
+
// Fall back to a conservative approximation if unavailable.
|
|
11
|
+
const TE = globalThis.TextEncoder;
|
|
12
|
+
if (!TE)
|
|
13
|
+
return s.length * 2;
|
|
14
|
+
return new TE().encode(s).byteLength;
|
|
15
|
+
}
|
|
16
|
+
export function normalizeParsingLimits(security) {
|
|
17
|
+
const cfg = security?.parsingLimits;
|
|
18
|
+
const enabled = cfg?.enabled === true;
|
|
19
|
+
if (!enabled) {
|
|
20
|
+
return { enabled: false, ...DEFAULTS };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
enabled: true,
|
|
24
|
+
rejectDoctype: cfg?.rejectDoctype ?? DEFAULTS.rejectDoctype,
|
|
25
|
+
maxItemXmlBytes: cfg?.maxItemXmlBytes ?? DEFAULTS.maxItemXmlBytes,
|
|
26
|
+
maxHtmlBytes: cfg?.maxHtmlBytes ?? DEFAULTS.maxHtmlBytes,
|
|
27
|
+
maxHtmlNodes: cfg?.maxHtmlNodes ?? DEFAULTS.maxHtmlNodes,
|
|
28
|
+
maxHtmlDepth: cfg?.maxHtmlDepth ?? DEFAULTS.maxHtmlDepth,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function enforceItemXmlLimits(itemXml, security) {
|
|
32
|
+
const limits = normalizeParsingLimits(security);
|
|
33
|
+
if (!limits.enabled)
|
|
34
|
+
return;
|
|
35
|
+
const bytes = getByteLengthUtf8(String(itemXml ?? ''));
|
|
36
|
+
if (bytes > limits.maxItemXmlBytes) {
|
|
37
|
+
throw new Error(`itemXml exceeds maxItemXmlBytes (${bytes} > ${limits.maxItemXmlBytes})`);
|
|
38
|
+
}
|
|
39
|
+
if (limits.rejectDoctype) {
|
|
40
|
+
// Case-insensitive and tolerant of whitespace: "<!DOCTYPE"
|
|
41
|
+
if (/<!\s*doctype/i.test(itemXml)) {
|
|
42
|
+
throw new Error('itemXml contains <!DOCTYPE>, which is rejected by parsingLimits');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic pseudo-random number generator helpers.
|
|
3
|
+
*
|
|
4
|
+
* We keep this tiny and dependency-free so tests (and optionally consumers)
|
|
5
|
+
* can run template processing deterministically.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Mulberry32 PRNG.
|
|
9
|
+
* Returns a function that yields a float in [0, 1).
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSeededRng(seed: number): () => number;
|
|
12
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/core/random.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,MAAM,CAU1D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic pseudo-random number generator helpers.
|
|
3
|
+
*
|
|
4
|
+
* We keep this tiny and dependency-free so tests (and optionally consumers)
|
|
5
|
+
* can run template processing deterministically.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Mulberry32 PRNG.
|
|
9
|
+
* Returns a function that yields a float in [0, 1).
|
|
10
|
+
*/
|
|
11
|
+
export function createSeededRng(seed) {
|
|
12
|
+
// Ensure 32-bit unsigned int
|
|
13
|
+
let a = seed >>> 0;
|
|
14
|
+
return () => {
|
|
15
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
16
|
+
let t = a;
|
|
17
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
18
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
19
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML Sanitizer for QTI Content
|
|
3
|
+
*
|
|
4
|
+
* Removes dangerous HTML/scripts while preserving safe educational content.
|
|
5
|
+
* Protects against XSS attacks via:
|
|
6
|
+
* - Script tags
|
|
7
|
+
* - Event handlers (onclick, onerror, onload, etc.)
|
|
8
|
+
* - Dangerous protocols (javascript:, data:text/html)
|
|
9
|
+
* - Unsafe iframe/object sources
|
|
10
|
+
*/
|
|
11
|
+
import type { PlayerSecurityConfig } from '../types/index.js';
|
|
12
|
+
export interface SanitizeHtmlOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Security config (URL policy and tag allowances).
|
|
15
|
+
* Defaults are conservative for same-DOM embedding.
|
|
16
|
+
*/
|
|
17
|
+
security?: PlayerSecurityConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sanitize HTML string by removing XSS vectors
|
|
21
|
+
*
|
|
22
|
+
* @param html - HTML string to sanitize
|
|
23
|
+
* @returns Sanitized HTML string safe for rendering
|
|
24
|
+
*/
|
|
25
|
+
export declare function sanitizeHtml(html: string, options?: SanitizeHtmlOptions): string;
|
|
26
|
+
/**
|
|
27
|
+
* Sanitize text content in choice labels, prompts, etc.
|
|
28
|
+
* This is for content that gets serialized to JSON and displayed in UI.
|
|
29
|
+
*
|
|
30
|
+
* @param text - Text content that may contain HTML
|
|
31
|
+
* @returns Sanitized text
|
|
32
|
+
*/
|
|
33
|
+
export declare function sanitizeTextContent(text: string, options?: SanitizeHtmlOptions): string;
|
|
34
|
+
//# sourceMappingURL=sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.d.ts","sourceRoot":"","sources":["../../src/core/sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAmB,MAAM,mBAAmB,CAAC;AAI/E,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CAChC;AA+ID;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CA0ChF;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAYvF"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML Sanitizer for QTI Content
|
|
3
|
+
*
|
|
4
|
+
* Removes dangerous HTML/scripts while preserving safe educational content.
|
|
5
|
+
* Protects against XSS attacks via:
|
|
6
|
+
* - Script tags
|
|
7
|
+
* - Event handlers (onclick, onerror, onload, etc.)
|
|
8
|
+
* - Dangerous protocols (javascript:, data:text/html)
|
|
9
|
+
* - Unsafe iframe/object sources
|
|
10
|
+
*/
|
|
11
|
+
import { parse } from 'node-html-parser';
|
|
12
|
+
import { normalizeParsingLimits } from './parsingLimits.js';
|
|
13
|
+
import { sanitizeResourceUrl } from './urlPolicy.js';
|
|
14
|
+
class HtmlLimitExceeded extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function policyFromOptions(options) {
|
|
20
|
+
return options?.security?.urlPolicy;
|
|
21
|
+
}
|
|
22
|
+
function allowObjectEmbeds(options) {
|
|
23
|
+
return options?.security?.allowObjectEmbeds === true;
|
|
24
|
+
}
|
|
25
|
+
function allowIframes(options) {
|
|
26
|
+
return options?.security?.allowIframes === true;
|
|
27
|
+
}
|
|
28
|
+
function sanitizeUrlAttr(value, policy, kind) {
|
|
29
|
+
return sanitizeResourceUrl(value, policy, kind) ?? '#';
|
|
30
|
+
}
|
|
31
|
+
function sanitizeSrcset(value, policy) {
|
|
32
|
+
// srcset grammar is complex; we implement a conservative filter:
|
|
33
|
+
// split by commas into candidate strings; sanitize the URL portion of each candidate.
|
|
34
|
+
const parts = value
|
|
35
|
+
.split(',')
|
|
36
|
+
.map((p) => p.trim())
|
|
37
|
+
.filter(Boolean);
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const part of parts) {
|
|
40
|
+
// URL is the first token; the rest are descriptors (e.g., 1x, 320w).
|
|
41
|
+
const tokens = part.split(/\s+/).filter(Boolean);
|
|
42
|
+
if (tokens.length === 0)
|
|
43
|
+
continue;
|
|
44
|
+
const url = tokens[0];
|
|
45
|
+
const sanitized = sanitizeResourceUrl(url, policy, 'img');
|
|
46
|
+
if (!sanitized)
|
|
47
|
+
continue;
|
|
48
|
+
out.push([sanitized, ...tokens.slice(1)].join(' '));
|
|
49
|
+
}
|
|
50
|
+
return out.join(', ');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Recursively sanitize an HTML element and its children
|
|
54
|
+
*/
|
|
55
|
+
function sanitizeElement(element, options, limitsState, depth) {
|
|
56
|
+
if (limitsState.enabled) {
|
|
57
|
+
if (depth > limitsState.maxDepth) {
|
|
58
|
+
throw new HtmlLimitExceeded(`HTML depth exceeds maxHtmlDepth (${depth} > ${limitsState.maxDepth})`);
|
|
59
|
+
}
|
|
60
|
+
limitsState.nodes++;
|
|
61
|
+
if (limitsState.nodes > limitsState.maxNodes) {
|
|
62
|
+
throw new HtmlLimitExceeded(`HTML node count exceeds maxHtmlNodes (${limitsState.nodes} > ${limitsState.maxNodes})`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const tagName = element.rawTagName?.toLowerCase();
|
|
66
|
+
// Remove script tags entirely
|
|
67
|
+
if (tagName === 'script') {
|
|
68
|
+
element.remove();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Remove high-risk elements by default (same-DOM embedding).
|
|
72
|
+
if (tagName === 'iframe' && !allowIframes(options)) {
|
|
73
|
+
element.remove();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if ((tagName === 'object' || tagName === 'embed') && !allowObjectEmbeds(options)) {
|
|
77
|
+
element.remove();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (tagName === 'base' || tagName === 'meta' || tagName === 'link' || tagName === 'style' || tagName === 'foreignobject') {
|
|
81
|
+
element.remove();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Remove dangerous event handler attributes (case-insensitive).
|
|
85
|
+
const attrs = element.attributes || {};
|
|
86
|
+
for (const attrName of Object.keys(attrs)) {
|
|
87
|
+
if (attrName.toLowerCase().startsWith('on')) {
|
|
88
|
+
element.removeAttribute(attrName);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Sanitize URL attributes
|
|
92
|
+
const policy = policyFromOptions(options);
|
|
93
|
+
for (const attrName of Object.keys(attrs)) {
|
|
94
|
+
const lower = attrName.toLowerCase();
|
|
95
|
+
const value = element.getAttribute(attrName);
|
|
96
|
+
if (!value)
|
|
97
|
+
continue;
|
|
98
|
+
// Block srcdoc everywhere (HTML document string).
|
|
99
|
+
if (lower === 'srcdoc') {
|
|
100
|
+
element.removeAttribute(attrName);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (lower === 'srcset') {
|
|
104
|
+
const sanitized = sanitizeSrcset(value, policy);
|
|
105
|
+
if (!sanitized)
|
|
106
|
+
element.removeAttribute(attrName);
|
|
107
|
+
else if (sanitized !== value)
|
|
108
|
+
element.setAttribute(attrName, sanitized);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
// URL-bearing attributes (include SVG xlink:href).
|
|
112
|
+
if (lower === 'href' ||
|
|
113
|
+
lower === 'xlink:href' ||
|
|
114
|
+
lower === 'src' ||
|
|
115
|
+
lower === 'data' ||
|
|
116
|
+
lower === 'action' ||
|
|
117
|
+
lower === 'formaction' ||
|
|
118
|
+
lower === 'poster') {
|
|
119
|
+
const kind = tagName === 'img' ? 'img' :
|
|
120
|
+
tagName === 'audio' || tagName === 'video' || tagName === 'source' ? 'media' :
|
|
121
|
+
tagName === 'object' || tagName === 'embed' ? 'object' :
|
|
122
|
+
tagName === 'a' ? 'link' :
|
|
123
|
+
'any';
|
|
124
|
+
const sanitized = sanitizeUrlAttr(value, policy, kind);
|
|
125
|
+
if (sanitized !== value)
|
|
126
|
+
element.setAttribute(attrName, sanitized);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Recursively sanitize children
|
|
130
|
+
const children = element.childNodes.filter((n) => n.rawTagName);
|
|
131
|
+
for (const child of children) {
|
|
132
|
+
sanitizeElement(child, options, limitsState, depth + 1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Sanitize HTML string by removing XSS vectors
|
|
137
|
+
*
|
|
138
|
+
* @param html - HTML string to sanitize
|
|
139
|
+
* @returns Sanitized HTML string safe for rendering
|
|
140
|
+
*/
|
|
141
|
+
export function sanitizeHtml(html, options) {
|
|
142
|
+
if (!html || typeof html !== 'string') {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const limits = normalizeParsingLimits(options?.security);
|
|
147
|
+
if (limits.enabled) {
|
|
148
|
+
const TE = globalThis.TextEncoder;
|
|
149
|
+
const bytes = TE ? new TE().encode(html).byteLength : html.length * 2;
|
|
150
|
+
if (bytes > limits.maxHtmlBytes) {
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Parse HTML
|
|
155
|
+
const root = parse(html, {
|
|
156
|
+
comment: false, // Remove comments (potential XSS vector)
|
|
157
|
+
});
|
|
158
|
+
// Sanitize all elements
|
|
159
|
+
const elements = root.childNodes.filter((n) => n.rawTagName);
|
|
160
|
+
const limitsState = {
|
|
161
|
+
enabled: limits.enabled,
|
|
162
|
+
nodes: 0,
|
|
163
|
+
maxNodes: limits.maxHtmlNodes,
|
|
164
|
+
maxDepth: limits.maxHtmlDepth,
|
|
165
|
+
};
|
|
166
|
+
for (const element of elements) {
|
|
167
|
+
sanitizeElement(element, options, limitsState, 1);
|
|
168
|
+
}
|
|
169
|
+
// Return sanitized HTML
|
|
170
|
+
return root.toString();
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof HtmlLimitExceeded) {
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
// If parsing fails, return empty string (safer than returning potentially malicious content)
|
|
177
|
+
console.error('HTML sanitization failed:', error);
|
|
178
|
+
return '';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sanitize text content in choice labels, prompts, etc.
|
|
183
|
+
* This is for content that gets serialized to JSON and displayed in UI.
|
|
184
|
+
*
|
|
185
|
+
* @param text - Text content that may contain HTML
|
|
186
|
+
* @returns Sanitized text
|
|
187
|
+
*/
|
|
188
|
+
export function sanitizeTextContent(text, options) {
|
|
189
|
+
if (!text || typeof text !== 'string') {
|
|
190
|
+
return '';
|
|
191
|
+
}
|
|
192
|
+
// If it looks like HTML (contains tags), sanitize it
|
|
193
|
+
if (/<[^>]+>/.test(text)) {
|
|
194
|
+
return sanitizeHtml(text, options);
|
|
195
|
+
}
|
|
196
|
+
// Plain text - return as-is
|
|
197
|
+
return text;
|
|
198
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HtmlContent } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a sanitized HTML string into a Trusted Types HTML value when:
|
|
4
|
+
* - the host configured a policy name, and
|
|
5
|
+
* - the browser supports Trusted Types, and
|
|
6
|
+
* - CSP allows creating/using that policy.
|
|
7
|
+
*
|
|
8
|
+
* Otherwise returns the original string.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toTrustedHtml(html: string, policyName?: string): HtmlContent;
|
|
11
|
+
/**
|
|
12
|
+
* Normalize HtmlContent back to a string.
|
|
13
|
+
* Useful when you need to perform string operations (replace/substr/etc) before re-wrapping.
|
|
14
|
+
*/
|
|
15
|
+
export declare function htmlToString(html: HtmlContent): string;
|
|
16
|
+
//# sourceMappingURL=trustedTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trustedTypes.d.ts","sourceRoot":"","sources":["../../src/core/trustedTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAgCvE;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,CAY5E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function getTrustedTypesGlobal() {
|
|
2
|
+
return globalThis.trustedTypes;
|
|
3
|
+
}
|
|
4
|
+
const policyCache = new Map();
|
|
5
|
+
function getOrCreatePolicy(policyName) {
|
|
6
|
+
const existing = policyCache.get(policyName);
|
|
7
|
+
if (existing)
|
|
8
|
+
return existing;
|
|
9
|
+
const tt = getTrustedTypesGlobal();
|
|
10
|
+
if (!tt?.createPolicy)
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const policy = tt.createPolicy(policyName, {
|
|
14
|
+
createHTML: (s) => s,
|
|
15
|
+
});
|
|
16
|
+
// Policy may be blocked/throw depending on CSP allowlist.
|
|
17
|
+
if (!policy?.createHTML)
|
|
18
|
+
return null;
|
|
19
|
+
policyCache.set(policyName, policy);
|
|
20
|
+
return policy;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Convert a sanitized HTML string into a Trusted Types HTML value when:
|
|
28
|
+
* - the host configured a policy name, and
|
|
29
|
+
* - the browser supports Trusted Types, and
|
|
30
|
+
* - CSP allows creating/using that policy.
|
|
31
|
+
*
|
|
32
|
+
* Otherwise returns the original string.
|
|
33
|
+
*/
|
|
34
|
+
export function toTrustedHtml(html, policyName) {
|
|
35
|
+
if (!policyName)
|
|
36
|
+
return html;
|
|
37
|
+
if (!html)
|
|
38
|
+
return '';
|
|
39
|
+
const policy = getOrCreatePolicy(policyName);
|
|
40
|
+
if (!policy)
|
|
41
|
+
return html;
|
|
42
|
+
try {
|
|
43
|
+
return policy.createHTML(html);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return html;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Normalize HtmlContent back to a string.
|
|
51
|
+
* Useful when you need to perform string operations (replace/substr/etc) before re-wrapping.
|
|
52
|
+
*/
|
|
53
|
+
export function htmlToString(html) {
|
|
54
|
+
return typeof html === 'string' ? html : String(html);
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UrlPolicyConfig } from '../types/index.js';
|
|
2
|
+
export type UrlKind = 'img' | 'media' | 'object' | 'link' | 'any';
|
|
3
|
+
/**
|
|
4
|
+
* Sanitize a URL used for embedding resources (img/audio/video/object/link).
|
|
5
|
+
* Returns null when the URL should be blocked.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sanitizeResourceUrl(raw: string, policy?: UrlPolicyConfig, kind?: UrlKind): string | null;
|
|
8
|
+
//# sourceMappingURL=urlPolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlPolicy.d.ts","sourceRoot":"","sources":["../../src/core/urlPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AA0ClE;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,EAAE,IAAI,GAAE,OAAe,GAAG,MAAM,GAAG,IAAI,CA4C/G"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const DEFAULT_POLICY = {
|
|
2
|
+
allowHttps: true,
|
|
3
|
+
allowHttp: false,
|
|
4
|
+
allowProtocolRelative: false,
|
|
5
|
+
allowDataImages: true,
|
|
6
|
+
allowSvgDataImages: false,
|
|
7
|
+
};
|
|
8
|
+
function normalizePolicy(policy) {
|
|
9
|
+
return { ...DEFAULT_POLICY, ...(policy ?? {}) };
|
|
10
|
+
}
|
|
11
|
+
function isDangerousScheme(u) {
|
|
12
|
+
const s = u.toLowerCase().trim();
|
|
13
|
+
return s.startsWith('javascript:') || s.startsWith('vbscript:') || s.startsWith('data:text/html');
|
|
14
|
+
}
|
|
15
|
+
function allowHost(hostname, policy) {
|
|
16
|
+
const allow = policy.allowedHosts;
|
|
17
|
+
if (!allow || allow.length === 0)
|
|
18
|
+
return true;
|
|
19
|
+
return allow.includes(hostname);
|
|
20
|
+
}
|
|
21
|
+
function sanitizeDataUrl(raw, kind, policy) {
|
|
22
|
+
const s = raw.toLowerCase().trim();
|
|
23
|
+
if (!s.startsWith('data:'))
|
|
24
|
+
return null;
|
|
25
|
+
if (kind !== 'img')
|
|
26
|
+
return null;
|
|
27
|
+
if (!policy.allowDataImages)
|
|
28
|
+
return null;
|
|
29
|
+
if (!s.startsWith('data:image/'))
|
|
30
|
+
return null;
|
|
31
|
+
if (!policy.allowSvgDataImages && s.startsWith('data:image/svg+xml'))
|
|
32
|
+
return null;
|
|
33
|
+
return raw.trim();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Sanitize a URL used for embedding resources (img/audio/video/object/link).
|
|
37
|
+
* Returns null when the URL should be blocked.
|
|
38
|
+
*/
|
|
39
|
+
export function sanitizeResourceUrl(raw, policy, kind = 'any') {
|
|
40
|
+
const p = normalizePolicy(policy);
|
|
41
|
+
const s = String(raw ?? '').trim();
|
|
42
|
+
if (!s)
|
|
43
|
+
return null;
|
|
44
|
+
if (isDangerousScheme(s))
|
|
45
|
+
return null;
|
|
46
|
+
// data: URLs (context-sensitive)
|
|
47
|
+
const dataOk = sanitizeDataUrl(s, kind, p);
|
|
48
|
+
if (dataOk)
|
|
49
|
+
return dataOk;
|
|
50
|
+
if (s.toLowerCase().trim().startsWith('data:'))
|
|
51
|
+
return null;
|
|
52
|
+
// Protocol-relative URLs are treated as network loads and blocked by default.
|
|
53
|
+
if (s.startsWith('//'))
|
|
54
|
+
return p.allowProtocolRelative ? `https:${s}` : null;
|
|
55
|
+
// Relative/absolute-path URLs: allow and optionally resolve.
|
|
56
|
+
if (s.startsWith('/') || s.startsWith('./') || s.startsWith('../')) {
|
|
57
|
+
if (p.assetBaseUrl) {
|
|
58
|
+
try {
|
|
59
|
+
// Strip leading '/' to make URL constructor resolve relative to base path, not origin
|
|
60
|
+
const relativePath = s.startsWith('/') ? s.slice(1) : s;
|
|
61
|
+
return new URL(relativePath, p.assetBaseUrl).toString();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return s;
|
|
68
|
+
}
|
|
69
|
+
// Absolute URLs: allow only http/https (by policy) and optional host allowlist.
|
|
70
|
+
let u;
|
|
71
|
+
try {
|
|
72
|
+
u = new URL(s);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const proto = u.protocol.toLowerCase();
|
|
78
|
+
if (proto === 'https:' && !p.allowHttps)
|
|
79
|
+
return null;
|
|
80
|
+
if (proto === 'http:' && !p.allowHttp)
|
|
81
|
+
return null;
|
|
82
|
+
if (proto !== 'https:' && proto !== 'http:')
|
|
83
|
+
return null;
|
|
84
|
+
if (!allowHost(u.hostname, p))
|
|
85
|
+
return null;
|
|
86
|
+
return u.toString();
|
|
87
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MathLive Editor Extension for TipTap
|
|
3
|
+
*
|
|
4
|
+
* Integrates MathLive (visual math editor) with TipTap's Mathematics extension.
|
|
5
|
+
* Provides a modal dialog with MathLive mathfield for editing LaTeX formulas.
|
|
6
|
+
*
|
|
7
|
+
* Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.
|
|
8
|
+
*/
|
|
9
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
10
|
+
import 'mathlive/mathlive-static.css';
|
|
11
|
+
export interface MathLiveEditorOptions {
|
|
12
|
+
/** Called when user confirms the LaTeX input */
|
|
13
|
+
onConfirm: (latex: string) => void;
|
|
14
|
+
/** Called when user cancels */
|
|
15
|
+
onCancel: () => void;
|
|
16
|
+
/** Initial LaTeX value */
|
|
17
|
+
initialLatex?: string;
|
|
18
|
+
/** Whether this is inline or block math */
|
|
19
|
+
isBlock?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Optional MathLive stylesheet URL. Defaults to jsdelivr CDN.
|
|
22
|
+
* Useful for CSP-restricted deployments (serve from your own domain).
|
|
23
|
+
*/
|
|
24
|
+
cssUrl?: string;
|
|
25
|
+
/** Optional i18n provider for translations */
|
|
26
|
+
i18n?: I18nProvider;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Opens a modal dialog with MathLive editor for LaTeX input
|
|
30
|
+
*/
|
|
31
|
+
export declare function openMathLiveEditor(options: MathLiveEditorOptions): Promise<() => void>;
|
|
32
|
+
//# sourceMappingURL=MathLiveEditor.d.ts.map
|