@pie-qti/item-player 0.1.1
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/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +9 -0
- package/README.md +466 -0
- package/docs/QTI-COMPLIANCE.md +197 -0
- package/docs/WCAG-2.2-COMPLIANCE.md +466 -0
- package/docs/custom-extractors.md +679 -0
- package/docs/iframe-mode.md +78 -0
- package/docs/security-audit.md +236 -0
- package/docs/server-api.md +691 -0
- package/package.json +78 -0
- package/src/components/ItemBody.svelte +382 -0
- package/src/components/ItemPlayer.svelte +155 -0
- package/src/components/ModalFeedbackDisplay.svelte +87 -0
- package/src/components/actions/typesetAction.ts +74 -0
- package/src/components/index.ts +19 -0
- package/src/components/utils/assignProps.ts +24 -0
- package/src/components/utils/feedbackUtils.ts +140 -0
- package/src/components/utils/index.ts +13 -0
- package/src/core/ComponentRegistry.ts +219 -0
- package/src/core/ItemRenderer.ts +367 -0
- package/src/core/Player.ts +1152 -0
- package/src/core/Plugin.ts +123 -0
- package/src/core/PluginManager.ts +182 -0
- package/src/core/constants.ts +117 -0
- package/src/core/declarations.ts +171 -0
- package/src/core/parsingLimits.ts +62 -0
- package/src/core/random.ts +24 -0
- package/src/core/sanitizer.ts +235 -0
- package/src/core/trustedTypes.ts +63 -0
- package/src/core/urlPolicy.ts +95 -0
- package/src/extensions/MathLiveEditor.ts +310 -0
- package/src/extraction/ExtractionRegistry.ts +295 -0
- package/src/extraction/createContext.ts +47 -0
- package/src/extraction/extractors/associateExtractor.ts +129 -0
- package/src/extraction/extractors/choiceExtractor.ts +110 -0
- package/src/extraction/extractors/customExtractor.ts +72 -0
- package/src/extraction/extractors/drawingExtractor.ts +113 -0
- package/src/extraction/extractors/endAttemptExtractor.ts +74 -0
- package/src/extraction/extractors/extendedTextExtractor.ts +80 -0
- package/src/extraction/extractors/gapMatchExtractor.ts +178 -0
- package/src/extraction/extractors/graphicAssociateExtractor.ts +188 -0
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +185 -0
- package/src/extraction/extractors/graphicOrderExtractor.ts +162 -0
- package/src/extraction/extractors/hotspotExtractor.ts +190 -0
- package/src/extraction/extractors/hottextExtractor.ts +153 -0
- package/src/extraction/extractors/index.ts +111 -0
- package/src/extraction/extractors/inlineChoiceExtractor.ts +88 -0
- package/src/extraction/extractors/matchExtractor.ts +160 -0
- package/src/extraction/extractors/mediaExtractor.ts +168 -0
- package/src/extraction/extractors/orderExtractor.ts +114 -0
- package/src/extraction/extractors/positionObjectExtractor.ts +243 -0
- package/src/extraction/extractors/selectPointExtractor.ts +143 -0
- package/src/extraction/extractors/sliderExtractor.ts +102 -0
- package/src/extraction/extractors/textEntryExtractor.ts +70 -0
- package/src/extraction/extractors/uploadExtractor.ts +73 -0
- package/src/extraction/index.ts +109 -0
- package/src/extraction/types.ts +246 -0
- package/src/extraction/utils.ts +160 -0
- package/src/iframe/IFramePlayerHost.ts +265 -0
- package/src/iframe/index.ts +11 -0
- package/src/iframe/protocol.ts +137 -0
- package/src/index.ts +87 -0
- package/src/server.ts +14 -0
- package/src/types/index.ts +301 -0
- package/src/types/interactions.ts +354 -0
- package/src/types/responseValidation.ts +29 -0
- package/src/utils/PerformanceMonitor.ts +335 -0
- package/src/utils/responseUtils.ts +51 -0
- package/src/utils/touchDragHelper.ts +211 -0
- package/src/web-components/QTIInteractionBase.ts +302 -0
- package/src/web-components/QTIInteractionElement.ts +118 -0
- package/src/web-components/index.ts +21 -0
- package/tests/conformance/FIXTURE_POLICY.md +29 -0
- package/tests/conformance/README.md +70 -0
- package/tests/conformance/fixtures/baseTypes_all/cases.json +61 -0
- package/tests/conformance/fixtures/baseTypes_all/item.xml +131 -0
- package/tests/conformance/fixtures/baseTypes_all/manifest.json +7 -0
- package/tests/conformance/fixtures/choice_match_correct/cases.json +17 -0
- package/tests/conformance/fixtures/choice_match_correct/item.xml +55 -0
- package/tests/conformance/fixtures/choice_match_correct/manifest.json +14 -0
- package/tests/conformance/fixtures/contains_multiple/cases.json +12 -0
- package/tests/conformance/fixtures/contains_multiple/item.xml +37 -0
- package/tests/conformance/fixtures/contains_multiple/manifest.json +13 -0
- package/tests/conformance/fixtures/isNull_isNotNull/cases.json +9 -0
- package/tests/conformance/fixtures/isNull_isNotNull/item.xml +41 -0
- package/tests/conformance/fixtures/isNull_isNotNull/manifest.json +23 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/cases.json +27 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/item.xml +30 -0
- package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/manifest.json +15 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/cases.json +11 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/item.xml +26 -0
- package/tests/conformance/fixtures/mapResponse_integer_mapKey/manifest.json +13 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/cases.json +27 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/item.xml +32 -0
- package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/manifest.json +7 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/cases.json +9 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/item.xml +25 -0
- package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/manifest.json +12 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/cases.json +12 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/item.xml +35 -0
- package/tests/conformance/fixtures/mapResponse_multiple_cardinality/manifest.json +11 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/cases.json +12 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/item.xml +37 -0
- package/tests/conformance/fixtures/mapping_bounds_upperLower/manifest.json +11 -0
- package/tests/conformance/fixtures/mapping_mapResponse/cases.json +22 -0
- package/tests/conformance/fixtures/mapping_mapResponse/item.xml +53 -0
- package/tests/conformance/fixtures/mapping_mapResponse/manifest.json +16 -0
- package/tests/conformance/fixtures/member_multiple/cases.json +12 -0
- package/tests/conformance/fixtures/member_multiple/item.xml +37 -0
- package/tests/conformance/fixtures/member_multiple/manifest.json +13 -0
- package/tests/conformance/fixtures/modalFeedback_basic/cases.json +17 -0
- package/tests/conformance/fixtures/modalFeedback_basic/item.xml +52 -0
- package/tests/conformance/fixtures/modalFeedback_basic/manifest.json +13 -0
- package/tests/conformance/fixtures/multiple_unordered_match/cases.json +17 -0
- package/tests/conformance/fixtures/multiple_unordered_match/item.xml +44 -0
- package/tests/conformance/fixtures/multiple_unordered_match/manifest.json +11 -0
- package/tests/conformance/fixtures/ordered_match/cases.json +17 -0
- package/tests/conformance/fixtures/ordered_match/item.xml +48 -0
- package/tests/conformance/fixtures/ordered_match/manifest.json +13 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/cases.json +27 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/item.xml +103 -0
- package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/manifest.json +7 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/cases.json +15 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/item.xml +33 -0
- package/tests/conformance/fixtures/outcomeProcessing_exitTest/manifest.json +10 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/item.xml +26 -0
- package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/cases.json +17 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/item.xml +43 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/manifest.json +16 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/cases.json +27 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/item.xml +37 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/manifest.json +16 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/manifest.json +8 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/cases.json +15 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/item.xml +39 -0
- package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/manifest.json +11 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/cases.json +14 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/item.xml +35 -0
- package/tests/conformance/fixtures/outcomeProcessing_testVariables/manifest.json +8 -0
- package/tests/conformance/fixtures/pair_unordered_match/cases.json +22 -0
- package/tests/conformance/fixtures/pair_unordered_match/item.xml +44 -0
- package/tests/conformance/fixtures/pair_unordered_match/manifest.json +13 -0
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/cases.json +95 -0
- package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/item.xml +53 -0
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/cases.json +115 -0
- package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/item.xml +45 -0
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/cases.json +29 -0
- package/tests/conformance/fixtures/positionObject_mapResponse_wrong/item.xml +40 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/cases.json +10 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/item.xml +49 -0
- package/tests/conformance/fixtures/responseCondition_elseIf_chain/manifest.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/item.xml +47 -0
- package/tests/conformance/fixtures/responseProcessing_anyN/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/item.xml +69 -0
- package/tests/conformance/fixtures/responseProcessing_anyN_allN/manifest.json +23 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/item.xml +58 -0
- package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/manifest.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/cases.json +37 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/item.xml +94 -0
- package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/manifest.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/cases.json +33 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/item.xml +79 -0
- package/tests/conformance/fixtures/responseProcessing_containerSize_index/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_customOperator/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/item.xml +48 -0
- package/tests/conformance/fixtures/responseProcessing_default_expression/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/item.xml +68 -0
- package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/cases.json +39 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/item.xml +39 -0
- package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/item.xml +25 -0
- package/tests/conformance/fixtures/responseProcessing_exitResponse/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/cases.json +26 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/item.xml +134 -0
- package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/manifest.json +16 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/item.xml +33 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/item.xml +26 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/cases.json +23 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/item.xml +28 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/manifest.json +11 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/cases.json +29 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/item.xml +26 -0
- package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/cases.json +31 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/item.xml +102 -0
- package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/item.xml +45 -0
- package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/manifest.json +21 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/cases.json +26 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/item.xml +157 -0
- package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/manifest.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/item.xml +39 -0
- package/tests/conformance/fixtures/responseProcessing_notEqual_basic/manifest.json +18 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/item.xml +51 -0
- package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/manifest.json +19 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/cases.json +31 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/item.xml +44 -0
- package/tests/conformance/fixtures/responseProcessing_preCondition/manifest.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/item.xml +42 -0
- package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/manifest.json +14 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_record_fieldValue/manifest.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/item.xml +63 -0
- package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/cases.json +12 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/item.xml +40 -0
- package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/manifest.json +13 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/item.xml +67 -0
- package/tests/conformance/fixtures/responseProcessing_setDefaultValue/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/cases.json +27 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/item.xml +69 -0
- package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/manifest.json +10 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/cases.json +15 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/item.xml +35 -0
- package/tests/conformance/fixtures/responseProcessing_subtract_divide/manifest.json +11 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/item.xml +31 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/item.xml +27 -0
- package/tests/conformance/fixtures/responseProcessing_template_map_response_point/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/item.xml +34 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/cases.json +22 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/manifest.json +7 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/manifest.json +9 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/cases.json +17 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/item.xml +30 -0
- package/tests/conformance/fixtures/responseProcessing_template_match_nothing/manifest.json +8 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/cases.json +14 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/item.xml +25 -0
- package/tests/conformance/fixtures/responseProcessing_xiInclude/manifest.json +9 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/cases.json +12 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/item.xml +52 -0
- package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/manifest.json +14 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/cases.json +12 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/item.xml +48 -0
- package/tests/conformance/fixtures/templateProcessing_exitTemplate/manifest.json +13 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/cases.json +27 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/item.xml +74 -0
- package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/manifest.json +22 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/cases.json +17 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/item.xml +133 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/manifest.json +22 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/cases.json +12 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/item.xml +107 -0
- package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/manifest.json +16 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/cases.json +15 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/item.xml +52 -0
- package/tests/conformance/fixtures/templateProcessing_templateConstraint/manifest.json +14 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/cases.json +16 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/item.xml +49 -0
- package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/manifest.json +15 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/cases.json +16 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/item.xml +38 -0
- package/tests/conformance/fixtures/template_randomInteger_printedVariable/manifest.json +13 -0
- package/tests/conformance/harness.ts +84 -0
- package/tests/conformance/run-fixtures.test.ts +127 -0
- package/tests/conformance/scripts/normalize-covers.ts +152 -0
- package/tests/conformance/types.ts +53 -0
- package/tests/core/Player.test.ts +563 -0
- package/tests/core/adaptiveItems.test.ts +442 -0
- package/tests/core/correctResponse.test.ts +280 -0
- package/tests/core/interaction-plumbing.test.ts +141 -0
- package/tests/core/modalFeedback.test.ts +308 -0
- package/tests/core/outcome-reset.test.ts +43 -0
- package/tests/extraction/extractors/associateExtractor.test.ts +182 -0
- package/tests/extraction/extractors/choiceExtractor.test.ts +239 -0
- package/tests/extraction/extractors/customExtractor.test.ts +83 -0
- package/tests/extraction/extractors/drawingExtractor.test.ts +94 -0
- package/tests/extraction/extractors/endAttemptExtractor.test.ts +188 -0
- package/tests/extraction/extractors/extendedTextExtractor.test.ts +178 -0
- package/tests/extraction/extractors/gapMatchExtractor.test.ts +318 -0
- package/tests/extraction/extractors/graphicAssociateExtractor.test.ts +260 -0
- package/tests/extraction/extractors/graphicGapMatchExtractor.test.ts +320 -0
- package/tests/extraction/extractors/graphicOrderExtractor.test.ts +223 -0
- package/tests/extraction/extractors/hotspotExtractor.test.ts +298 -0
- package/tests/extraction/extractors/hottextExtractor.test.ts +240 -0
- package/tests/extraction/extractors/inlineChoiceExtractor.test.ts +292 -0
- package/tests/extraction/extractors/matchExtractor.test.ts +241 -0
- package/tests/extraction/extractors/mediaExtractor.test.ts +295 -0
- package/tests/extraction/extractors/orderExtractor.test.ts +212 -0
- package/tests/extraction/extractors/positionObjectExtractor.test.ts +363 -0
- package/tests/extraction/extractors/selectPointExtractor.test.ts +214 -0
- package/tests/extraction/extractors/sliderExtractor.test.ts +293 -0
- package/tests/extraction/extractors/textEntryExtractor.test.ts +133 -0
- package/tests/extraction/extractors/uploadExtractor.test.ts +119 -0
- package/tests/extraction/test-utils.ts +57 -0
- package/tests/iframe/host.test.ts +145 -0
- package/tests/iframe/protocol.test.ts +42 -0
- package/tests/performance/player-benchmarks.bench.ts +191 -0
- package/tests/security/dos-limits.test.ts +56 -0
- package/tests/security/xss-prevention.test.ts +522 -0
- package/tsconfig.json +20 -0
- package/tsconfig.svelte.json +14 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance Monitor Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides lightweight performance monitoring for QTI player operations
|
|
5
|
+
* without requiring external dependencies. Useful for debugging, optimization,
|
|
6
|
+
* and tracking performance metrics in production.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Measure operation durations
|
|
10
|
+
* - Track custom metrics
|
|
11
|
+
* - Export performance data
|
|
12
|
+
* - Memory-efficient (circular buffer for metrics)
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { PerformanceMonitor } from './utils/PerformanceMonitor';
|
|
17
|
+
*
|
|
18
|
+
* const monitor = new PerformanceMonitor({ enabled: true, maxEntries: 100 });
|
|
19
|
+
*
|
|
20
|
+
* // Measure an operation
|
|
21
|
+
* const stopTimer = monitor.startTimer('render-item');
|
|
22
|
+
* // ... do work
|
|
23
|
+
* stopTimer(); // Records duration
|
|
24
|
+
*
|
|
25
|
+
* // Track custom metrics
|
|
26
|
+
* monitor.recordMetric('item-response-time', 245);
|
|
27
|
+
*
|
|
28
|
+
* // Get performance report
|
|
29
|
+
* const report = monitor.getReport();
|
|
30
|
+
* console.log(report);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export interface PerformanceEntry {
|
|
35
|
+
/** Metric name */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Timestamp when metric was recorded (ms since epoch) */
|
|
38
|
+
timestamp: number;
|
|
39
|
+
/** Duration in milliseconds (for timers) */
|
|
40
|
+
duration?: number;
|
|
41
|
+
/** Custom value (for non-timer metrics) */
|
|
42
|
+
value?: number;
|
|
43
|
+
/** Additional metadata */
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PerformanceReport {
|
|
48
|
+
/** Total number of metrics recorded */
|
|
49
|
+
totalEntries: number;
|
|
50
|
+
/** Number of entries currently stored (may be less due to circular buffer) */
|
|
51
|
+
storedEntries: number;
|
|
52
|
+
/** Summary statistics by metric name */
|
|
53
|
+
metrics: Record<
|
|
54
|
+
string,
|
|
55
|
+
{
|
|
56
|
+
count: number;
|
|
57
|
+
min: number;
|
|
58
|
+
max: number;
|
|
59
|
+
avg: number;
|
|
60
|
+
total: number;
|
|
61
|
+
}
|
|
62
|
+
>;
|
|
63
|
+
/** Recent entries (last N based on buffer size) */
|
|
64
|
+
recentEntries: PerformanceEntry[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface PerformanceMonitorConfig {
|
|
68
|
+
/** Enable/disable monitoring (default: false) */
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
/** Maximum entries to store (circular buffer, default: 100) */
|
|
71
|
+
maxEntries?: number;
|
|
72
|
+
/** Auto-export metrics when buffer is full (default: false) */
|
|
73
|
+
autoExport?: boolean;
|
|
74
|
+
/** Callback for auto-export */
|
|
75
|
+
onExport?: (report: PerformanceReport) => void;
|
|
76
|
+
/** Log warnings to console (default: false) */
|
|
77
|
+
logWarnings?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class PerformanceMonitor {
|
|
81
|
+
private enabled: boolean;
|
|
82
|
+
private maxEntries: number;
|
|
83
|
+
private autoExport: boolean;
|
|
84
|
+
private onExport?: (report: PerformanceReport) => void;
|
|
85
|
+
private logWarnings: boolean;
|
|
86
|
+
|
|
87
|
+
private entries: PerformanceEntry[] = [];
|
|
88
|
+
private totalRecorded = 0;
|
|
89
|
+
private startTimes = new Map<string, number>();
|
|
90
|
+
|
|
91
|
+
constructor(config: PerformanceMonitorConfig = {}) {
|
|
92
|
+
this.enabled = config.enabled ?? false;
|
|
93
|
+
this.maxEntries = config.maxEntries ?? 100;
|
|
94
|
+
this.autoExport = config.autoExport ?? false;
|
|
95
|
+
this.onExport = config.onExport;
|
|
96
|
+
this.logWarnings = config.logWarnings ?? false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Enable performance monitoring
|
|
101
|
+
*/
|
|
102
|
+
enable(): void {
|
|
103
|
+
this.enabled = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Disable performance monitoring
|
|
108
|
+
*/
|
|
109
|
+
disable(): void {
|
|
110
|
+
this.enabled = false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Check if monitoring is enabled
|
|
115
|
+
*/
|
|
116
|
+
isEnabled(): boolean {
|
|
117
|
+
return this.enabled;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Start a timer for an operation
|
|
122
|
+
*
|
|
123
|
+
* @param name - Name of the operation
|
|
124
|
+
* @param metadata - Optional metadata to attach
|
|
125
|
+
* @returns Function to stop the timer and record duration
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const stop = monitor.startTimer('render-item', { itemId: 'item-001' });
|
|
129
|
+
* // ... do work
|
|
130
|
+
* stop(); // Records duration automatically
|
|
131
|
+
*/
|
|
132
|
+
startTimer(name: string, metadata?: Record<string, unknown>): () => void {
|
|
133
|
+
if (!this.enabled) {
|
|
134
|
+
return () => {}; // No-op
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const startTime = performance.now();
|
|
138
|
+
const timerKey = `${name}:${startTime}`;
|
|
139
|
+
this.startTimes.set(timerKey, startTime);
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
const endTime = performance.now();
|
|
143
|
+
const duration = endTime - startTime;
|
|
144
|
+
this.startTimes.delete(timerKey);
|
|
145
|
+
|
|
146
|
+
this.recordEntry({
|
|
147
|
+
name,
|
|
148
|
+
timestamp: Date.now(),
|
|
149
|
+
duration,
|
|
150
|
+
metadata,
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Record a custom metric value
|
|
157
|
+
*
|
|
158
|
+
* @param name - Name of the metric
|
|
159
|
+
* @param value - Numeric value
|
|
160
|
+
* @param metadata - Optional metadata
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* monitor.recordMetric('item-count', 25);
|
|
164
|
+
* monitor.recordMetric('memory-usage', process.memoryUsage().heapUsed);
|
|
165
|
+
*/
|
|
166
|
+
recordMetric(name: string, value: number, metadata?: Record<string, unknown>): void {
|
|
167
|
+
if (!this.enabled) return;
|
|
168
|
+
|
|
169
|
+
this.recordEntry({
|
|
170
|
+
name,
|
|
171
|
+
timestamp: Date.now(),
|
|
172
|
+
value,
|
|
173
|
+
metadata,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Record a performance entry
|
|
179
|
+
*/
|
|
180
|
+
private recordEntry(entry: PerformanceEntry): void {
|
|
181
|
+
this.totalRecorded++;
|
|
182
|
+
|
|
183
|
+
// Add to circular buffer
|
|
184
|
+
if (this.entries.length >= this.maxEntries) {
|
|
185
|
+
// Remove oldest entry
|
|
186
|
+
this.entries.shift();
|
|
187
|
+
|
|
188
|
+
// Auto-export if configured
|
|
189
|
+
if (this.autoExport && this.onExport) {
|
|
190
|
+
try {
|
|
191
|
+
this.onExport(this.getReport());
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (this.logWarnings) {
|
|
194
|
+
console.warn('Performance monitor auto-export failed:', error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.entries.push(entry);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get performance report with statistics
|
|
205
|
+
*/
|
|
206
|
+
getReport(): PerformanceReport {
|
|
207
|
+
const metrics: Record<
|
|
208
|
+
string,
|
|
209
|
+
{
|
|
210
|
+
count: number;
|
|
211
|
+
min: number;
|
|
212
|
+
max: number;
|
|
213
|
+
avg: number;
|
|
214
|
+
total: number;
|
|
215
|
+
}
|
|
216
|
+
> = {};
|
|
217
|
+
|
|
218
|
+
// Calculate statistics for each metric
|
|
219
|
+
for (const entry of this.entries) {
|
|
220
|
+
const value = entry.duration ?? entry.value ?? 0;
|
|
221
|
+
|
|
222
|
+
if (!metrics[entry.name]) {
|
|
223
|
+
metrics[entry.name] = {
|
|
224
|
+
count: 0,
|
|
225
|
+
min: Infinity,
|
|
226
|
+
max: -Infinity,
|
|
227
|
+
avg: 0,
|
|
228
|
+
total: 0,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const stats = metrics[entry.name];
|
|
233
|
+
stats.count++;
|
|
234
|
+
stats.total += value;
|
|
235
|
+
stats.min = Math.min(stats.min, value);
|
|
236
|
+
stats.max = Math.max(stats.max, value);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Calculate averages
|
|
240
|
+
for (const stats of Object.values(metrics)) {
|
|
241
|
+
stats.avg = stats.total / stats.count;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
totalEntries: this.totalRecorded,
|
|
246
|
+
storedEntries: this.entries.length,
|
|
247
|
+
metrics,
|
|
248
|
+
recentEntries: [...this.entries],
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get entries for a specific metric name
|
|
254
|
+
*/
|
|
255
|
+
getEntriesByName(name: string): PerformanceEntry[] {
|
|
256
|
+
return this.entries.filter((entry) => entry.name === name);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Clear all stored entries
|
|
261
|
+
*/
|
|
262
|
+
clear(): void {
|
|
263
|
+
this.entries = [];
|
|
264
|
+
this.totalRecorded = 0;
|
|
265
|
+
this.startTimes.clear();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Export report as JSON string
|
|
270
|
+
*/
|
|
271
|
+
exportJSON(): string {
|
|
272
|
+
return JSON.stringify(this.getReport(), null, 2);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Export report to console
|
|
277
|
+
*/
|
|
278
|
+
exportToConsole(): void {
|
|
279
|
+
const report = this.getReport();
|
|
280
|
+
|
|
281
|
+
console.group('📊 Performance Report');
|
|
282
|
+
console.log(`Total Entries: ${report.totalEntries}`);
|
|
283
|
+
console.log(`Stored Entries: ${report.storedEntries}`);
|
|
284
|
+
console.log('\nMetrics:');
|
|
285
|
+
|
|
286
|
+
for (const [name, stats] of Object.entries(report.metrics)) {
|
|
287
|
+
console.group(` ${name}`);
|
|
288
|
+
console.log(` Count: ${stats.count}`);
|
|
289
|
+
console.log(` Min: ${stats.min.toFixed(2)}ms`);
|
|
290
|
+
console.log(` Max: ${stats.max.toFixed(2)}ms`);
|
|
291
|
+
console.log(` Avg: ${stats.avg.toFixed(2)}ms`);
|
|
292
|
+
console.log(` Total: ${stats.total.toFixed(2)}ms`);
|
|
293
|
+
console.groupEnd();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
console.groupEnd();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Get performance marks for Web Performance API integration
|
|
301
|
+
*
|
|
302
|
+
* If using browser's Performance API, this exports entries
|
|
303
|
+
* in a compatible format.
|
|
304
|
+
*/
|
|
305
|
+
getPerformanceMarks(): Array<{
|
|
306
|
+
name: string;
|
|
307
|
+
startTime: number;
|
|
308
|
+
duration?: number;
|
|
309
|
+
}> {
|
|
310
|
+
return this.entries.map((entry) => ({
|
|
311
|
+
name: entry.name,
|
|
312
|
+
startTime: entry.timestamp,
|
|
313
|
+
duration: entry.duration,
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Singleton instance for global performance monitoring
|
|
320
|
+
*
|
|
321
|
+
* Usage:
|
|
322
|
+
* ```typescript
|
|
323
|
+
* import { globalPerformanceMonitor } from './utils/PerformanceMonitor';
|
|
324
|
+
*
|
|
325
|
+
* globalPerformanceMonitor.enable();
|
|
326
|
+
* const stop = globalPerformanceMonitor.startTimer('operation');
|
|
327
|
+
* // ... work
|
|
328
|
+
* stop();
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export const globalPerformanceMonitor = new PerformanceMonitor({
|
|
332
|
+
enabled: false, // Disabled by default, enable explicitly
|
|
333
|
+
maxEntries: 100,
|
|
334
|
+
logWarnings: false,
|
|
335
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic response/value helpers.
|
|
3
|
+
*
|
|
4
|
+
* These are UI-agnostic utilities intended to keep "is this answered?"
|
|
5
|
+
* logic consistent across apps (example, assessment player, etc).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns true when a response value should be treated as "no response / unanswered".
|
|
10
|
+
*
|
|
11
|
+
* Notes:
|
|
12
|
+
* - `0` and `false` are valid answers in some interactions, so they are NOT empty.
|
|
13
|
+
* - Empty objects are treated as empty, and objects whose values are all empty are treated as empty.
|
|
14
|
+
*/
|
|
15
|
+
export function isResponseEmpty(value: unknown): boolean {
|
|
16
|
+
if (value === null || value === undefined) return true;
|
|
17
|
+
|
|
18
|
+
if (typeof value === 'string') return value.trim() === '';
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
if (value.length === 0) return true;
|
|
22
|
+
// Some interactions may emit arrays with empty members; treat "all empty" as empty.
|
|
23
|
+
return value.every((v) => isResponseEmpty(v));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Files/blobs are valid user responses (upload interactions).
|
|
27
|
+
if (typeof Blob !== 'undefined' && value instanceof Blob) return false;
|
|
28
|
+
|
|
29
|
+
if (typeof value === 'object') {
|
|
30
|
+
const obj = value as Record<string, unknown>;
|
|
31
|
+
const keys = Object.keys(obj);
|
|
32
|
+
if (keys.length === 0) return true;
|
|
33
|
+
return keys.every((k) => isResponseEmpty(obj[k]));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// numbers, booleans, symbols, functions -> treat as "has a response"
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function countAnsweredForResponseIds(
|
|
41
|
+
responses: Record<string, unknown>,
|
|
42
|
+
responseIds: readonly string[]
|
|
43
|
+
): number {
|
|
44
|
+
let count = 0;
|
|
45
|
+
for (const id of responseIds) {
|
|
46
|
+
if (!isResponseEmpty(responses[id])) count++;
|
|
47
|
+
}
|
|
48
|
+
return count;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch-enabled drag helper for making HTML5 drag-and-drop work with touch devices
|
|
3
|
+
*
|
|
4
|
+
* HTML5 drag-and-drop API doesn't work on touch devices by default.
|
|
5
|
+
* This helper translates touch events to pointer events for unified handling.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <div
|
|
10
|
+
* use:touchDrag
|
|
11
|
+
* draggable="true"
|
|
12
|
+
* ondragstart={...}
|
|
13
|
+
* >
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface TouchDragState {
|
|
18
|
+
element: HTMLElement;
|
|
19
|
+
touchId: number | null;
|
|
20
|
+
isDragging: boolean;
|
|
21
|
+
startX: number;
|
|
22
|
+
startY: number;
|
|
23
|
+
currentX: number;
|
|
24
|
+
currentY: number;
|
|
25
|
+
dragThreshold: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Svelte action to enable touch drag on draggable elements
|
|
30
|
+
*/
|
|
31
|
+
export function touchDrag(node: HTMLElement) {
|
|
32
|
+
const state: TouchDragState = {
|
|
33
|
+
element: node,
|
|
34
|
+
touchId: null,
|
|
35
|
+
isDragging: false,
|
|
36
|
+
startX: 0,
|
|
37
|
+
startY: 0,
|
|
38
|
+
currentX: 0,
|
|
39
|
+
currentY: 0,
|
|
40
|
+
dragThreshold: 10 // px movement to initiate drag
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function handleTouchStart(e: TouchEvent) {
|
|
44
|
+
// Only handle single touch
|
|
45
|
+
if (e.touches.length !== 1) return;
|
|
46
|
+
|
|
47
|
+
// Check if element is draggable
|
|
48
|
+
const draggable = node.getAttribute('draggable');
|
|
49
|
+
if (draggable !== 'true') return;
|
|
50
|
+
|
|
51
|
+
const touch = e.touches[0];
|
|
52
|
+
state.touchId = touch.identifier;
|
|
53
|
+
state.startX = touch.clientX;
|
|
54
|
+
state.startY = touch.clientY;
|
|
55
|
+
state.currentX = touch.clientX;
|
|
56
|
+
state.currentY = touch.clientY;
|
|
57
|
+
state.isDragging = false;
|
|
58
|
+
|
|
59
|
+
// Add move and end listeners to document for consistent tracking
|
|
60
|
+
document.addEventListener('touchmove', handleTouchMove, { passive: false });
|
|
61
|
+
document.addEventListener('touchend', handleTouchEnd);
|
|
62
|
+
document.addEventListener('touchcancel', handleTouchCancel);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleTouchMove(e: TouchEvent) {
|
|
66
|
+
if (state.touchId === null) return;
|
|
67
|
+
|
|
68
|
+
// Find the touch we're tracking
|
|
69
|
+
const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
|
|
70
|
+
if (!touch) return;
|
|
71
|
+
|
|
72
|
+
state.currentX = touch.clientX;
|
|
73
|
+
state.currentY = touch.clientY;
|
|
74
|
+
|
|
75
|
+
// Check if we've moved enough to start dragging
|
|
76
|
+
const deltaX = state.currentX - state.startX;
|
|
77
|
+
const deltaY = state.currentY - state.startY;
|
|
78
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
79
|
+
|
|
80
|
+
if (!state.isDragging && distance > state.dragThreshold) {
|
|
81
|
+
// Start drag
|
|
82
|
+
state.isDragging = true;
|
|
83
|
+
|
|
84
|
+
// Trigger dragstart event
|
|
85
|
+
const dragStartEvent = new DragEvent('dragstart', {
|
|
86
|
+
bubbles: true,
|
|
87
|
+
cancelable: true,
|
|
88
|
+
clientX: state.startX,
|
|
89
|
+
clientY: state.startY
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
node.dispatchEvent(dragStartEvent);
|
|
93
|
+
|
|
94
|
+
// Add visual feedback
|
|
95
|
+
node.style.opacity = '0.5';
|
|
96
|
+
e.preventDefault(); // Prevent scrolling
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (state.isDragging) {
|
|
100
|
+
e.preventDefault(); // Prevent scrolling while dragging
|
|
101
|
+
|
|
102
|
+
// Find element under touch point
|
|
103
|
+
const elementUnder = document.elementFromPoint(state.currentX, state.currentY);
|
|
104
|
+
|
|
105
|
+
if (elementUnder && elementUnder !== node) {
|
|
106
|
+
// Trigger dragover on the element under touch
|
|
107
|
+
const dragOverEvent = new DragEvent('dragover', {
|
|
108
|
+
bubbles: true,
|
|
109
|
+
cancelable: true,
|
|
110
|
+
clientX: state.currentX,
|
|
111
|
+
clientY: state.currentY
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
elementUnder.dispatchEvent(dragOverEvent);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function handleTouchEnd(e: TouchEvent) {
|
|
120
|
+
if (state.touchId === null) return;
|
|
121
|
+
|
|
122
|
+
// Find the touch we're tracking
|
|
123
|
+
const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
|
|
124
|
+
if (!touch) return;
|
|
125
|
+
|
|
126
|
+
if (state.isDragging) {
|
|
127
|
+
// Find element under touch point at drop location
|
|
128
|
+
const elementUnder = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
129
|
+
|
|
130
|
+
if (elementUnder) {
|
|
131
|
+
// Trigger drop event
|
|
132
|
+
const dropEvent = new DragEvent('drop', {
|
|
133
|
+
bubbles: true,
|
|
134
|
+
cancelable: true,
|
|
135
|
+
clientX: touch.clientX,
|
|
136
|
+
clientY: touch.clientY
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
elementUnder.dispatchEvent(dropEvent);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Trigger dragend
|
|
143
|
+
const dragEndEvent = new DragEvent('dragend', {
|
|
144
|
+
bubbles: true,
|
|
145
|
+
cancelable: true
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
node.dispatchEvent(dragEndEvent);
|
|
149
|
+
|
|
150
|
+
// Reset visual feedback
|
|
151
|
+
node.style.opacity = '';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
cleanup();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleTouchCancel() {
|
|
158
|
+
if (state.isDragging) {
|
|
159
|
+
// Trigger dragend
|
|
160
|
+
const dragEndEvent = new DragEvent('dragend', {
|
|
161
|
+
bubbles: true,
|
|
162
|
+
cancelable: true
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
node.dispatchEvent(dragEndEvent);
|
|
166
|
+
|
|
167
|
+
// Reset visual feedback
|
|
168
|
+
node.style.opacity = '';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
cleanup();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function cleanup() {
|
|
175
|
+
state.touchId = null;
|
|
176
|
+
state.isDragging = false;
|
|
177
|
+
|
|
178
|
+
document.removeEventListener('touchmove', handleTouchMove);
|
|
179
|
+
document.removeEventListener('touchend', handleTouchEnd);
|
|
180
|
+
document.removeEventListener('touchcancel', handleTouchCancel);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Attach initial touch listener
|
|
184
|
+
node.addEventListener('touchstart', handleTouchStart, { passive: true });
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
destroy() {
|
|
188
|
+
node.removeEventListener('touchstart', handleTouchStart);
|
|
189
|
+
cleanup();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* CSS helper for touch-friendly drag interactions
|
|
196
|
+
* Returns CSS that should be applied to draggable elements
|
|
197
|
+
*/
|
|
198
|
+
export const touchDragStyles = {
|
|
199
|
+
/* Prevent text selection during drag */
|
|
200
|
+
userSelect: 'none',
|
|
201
|
+
webkitUserSelect: 'none',
|
|
202
|
+
|
|
203
|
+
/* Allow touch events */
|
|
204
|
+
touchAction: 'none',
|
|
205
|
+
|
|
206
|
+
/* Cursor feedback */
|
|
207
|
+
cursor: 'grab',
|
|
208
|
+
|
|
209
|
+
/* Smooth transitions */
|
|
210
|
+
transition: 'opacity 0.2s ease'
|
|
211
|
+
} as const;
|