@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
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-qti/item-player",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Modern QTI player supporting QTI 2.x and 3.0 - Client-side with optional backend hooks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"test": "bun test",
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"check": "../assessment-player/node_modules/.bin/svelte-check --tsconfig ./tsconfig.svelte.json",
|
|
14
|
+
"lint": "biome check .",
|
|
15
|
+
"lint:fix": "biome check --write .",
|
|
16
|
+
"format": "biome format --write ."
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"qti",
|
|
20
|
+
"qti2",
|
|
21
|
+
"qti3",
|
|
22
|
+
"qti 2.x",
|
|
23
|
+
"qti 3.0",
|
|
24
|
+
"assessment",
|
|
25
|
+
"player",
|
|
26
|
+
"e-learning"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@pie-qti/ims-cp-core": "workspace:*",
|
|
31
|
+
"@pie-qti/qti-common": "workspace:*",
|
|
32
|
+
"@pie-qti/i18n": "workspace:*",
|
|
33
|
+
"@pie-qti/qti-processing": "workspace:*",
|
|
34
|
+
"@tiptap/core": "^3.15.3",
|
|
35
|
+
"@tiptap/extension-mathematics": "^3.15.3",
|
|
36
|
+
"@tiptap/extension-placeholder": "^3.15.3",
|
|
37
|
+
"@tiptap/starter-kit": "^3.15.3",
|
|
38
|
+
"@xmldom/xmldom": "^0.8.11",
|
|
39
|
+
"decimal.js": "^10.6.0",
|
|
40
|
+
"katex": "^0.16.27",
|
|
41
|
+
"mathlive": "^0.108.2",
|
|
42
|
+
"node-html-parser": "^7.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@biomejs/biome": "^2.3.11",
|
|
46
|
+
"@types/node": "^25.0.3",
|
|
47
|
+
"svelte": "^5.46.1",
|
|
48
|
+
"svelte-check": "^4.3.5",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
},
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
54
|
+
"import": "./dist/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./server": {
|
|
57
|
+
"types": "./dist/server.d.ts",
|
|
58
|
+
"import": "./dist/server.js"
|
|
59
|
+
},
|
|
60
|
+
"./web-components": {
|
|
61
|
+
"types": "./dist/web-components/index.d.ts",
|
|
62
|
+
"import": "./dist/web-components/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./iframe": {
|
|
65
|
+
"types": "./dist/iframe/index.d.ts",
|
|
66
|
+
"import": "./dist/iframe/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./components": {
|
|
69
|
+
"types": "./dist/components/index.d.ts",
|
|
70
|
+
"svelte": "./src/components/index.ts",
|
|
71
|
+
"import": "./dist/components/index.js"
|
|
72
|
+
},
|
|
73
|
+
"./components/utils": {
|
|
74
|
+
"types": "./dist/components/utils/index.d.ts",
|
|
75
|
+
"import": "./dist/components/utils/index.js"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { InteractionData } from '../types';
|
|
3
|
+
import type { Player } from '../core/Player';
|
|
4
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
5
|
+
import { normalizeHeuristicsConfig, type QtiHeuristicsConfig } from '@pie-qti/ims-cp-core';
|
|
6
|
+
import { processFeedbackInline } from './utils/feedbackUtils';
|
|
7
|
+
import { typesetAction } from './actions/typesetAction';
|
|
8
|
+
import { assignProps } from './utils/assignProps';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
player: Player;
|
|
12
|
+
responses?: Record<string, any>;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
role?: 'candidate' | 'scorer' | 'author' | 'tutor' | 'proctor' | 'testConstructor';
|
|
15
|
+
i18n?: I18nProvider;
|
|
16
|
+
typeset?: (element: HTMLElement) => void;
|
|
17
|
+
onResponseChange?: (responseId: string, value: any) => void;
|
|
18
|
+
outcomeValues?: Record<string, any>; // Needed for feedbackInline visibility
|
|
19
|
+
heuristicsConfig?: QtiHeuristicsConfig; // Optional heuristics configuration
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
player,
|
|
24
|
+
responses = {},
|
|
25
|
+
disabled = false,
|
|
26
|
+
role = 'candidate',
|
|
27
|
+
i18n,
|
|
28
|
+
typeset,
|
|
29
|
+
onResponseChange = () => {},
|
|
30
|
+
outcomeValues = {},
|
|
31
|
+
heuristicsConfig,
|
|
32
|
+
}: Props = $props();
|
|
33
|
+
|
|
34
|
+
// Normalize heuristics configuration with defaults
|
|
35
|
+
const heuristics = $derived(normalizeHeuristicsConfig(heuristicsConfig));
|
|
36
|
+
|
|
37
|
+
// Get the component registry from the player
|
|
38
|
+
const componentRegistry = $derived(player.getComponentRegistry());
|
|
39
|
+
|
|
40
|
+
// Process interactions
|
|
41
|
+
const interactions = $derived<InteractionData[]>(player.getInteractionData());
|
|
42
|
+
|
|
43
|
+
// Get correct responses when role is scorer
|
|
44
|
+
const correctResponses = $derived.by(() => {
|
|
45
|
+
return role === 'scorer' ? player.getCorrectResponses() : {};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Get components for block-level interactions only (not inline interactions)
|
|
49
|
+
// Inline interactions (textEntry, inlineChoice) are rendered within the HTML via InlineInteractionRenderer
|
|
50
|
+
const interactionComponents = $derived(
|
|
51
|
+
interactions
|
|
52
|
+
.filter(
|
|
53
|
+
(interaction) =>
|
|
54
|
+
interaction.type !== 'textEntryInteraction' &&
|
|
55
|
+
interaction.type !== 'inlineChoiceInteraction'
|
|
56
|
+
)
|
|
57
|
+
.map((interaction) => {
|
|
58
|
+
try {
|
|
59
|
+
// Get the web component tag name from the registry
|
|
60
|
+
const tagName = componentRegistry.getTagName(interaction);
|
|
61
|
+
return {
|
|
62
|
+
interaction,
|
|
63
|
+
tagName,
|
|
64
|
+
};
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`Failed to get tag name for ${interaction.type}:`, error);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.filter((item): item is NonNullable<typeof item> => item !== null)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Get item body HTML and process interactions
|
|
74
|
+
// Block interactions are kept in HTML but wrapped with a hidden marker (see styles below)
|
|
75
|
+
// Inline interactions are replaced with placeholders
|
|
76
|
+
const itemBodyHtml = $derived.by(() => {
|
|
77
|
+
let html = player.getItemBodyHtml();
|
|
78
|
+
|
|
79
|
+
// Replace inline interactions with placeholders (they need to be rendered in-flow)
|
|
80
|
+
html = html
|
|
81
|
+
.replace(
|
|
82
|
+
/<textEntryInteraction[^>]*responseIdentifier="([^"]+)"[^>]*?(?:\/>|><\/textEntryInteraction>)/gi,
|
|
83
|
+
'[TEXTENTRY:$1]'
|
|
84
|
+
)
|
|
85
|
+
.replace(
|
|
86
|
+
/<inlineChoiceInteraction[^>]*responseIdentifier="([^"]+)"[^>]*>[\s\S]*?<\/inlineChoiceInteraction>/gi,
|
|
87
|
+
'[INLINECHOICE:$1]'
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Process feedbackInline elements - conditionally show/hide based on outcome values
|
|
91
|
+
html = processFeedbackInline(html, {
|
|
92
|
+
outcomeValues,
|
|
93
|
+
applyHeuristics: heuristics.feedbackTextFormatting,
|
|
94
|
+
wrapWithSpan: false
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Wrap all block-level *Interaction elements with a hidden marker
|
|
98
|
+
// This is extensible - any element ending in "Interaction" will be hidden
|
|
99
|
+
html = html.replace(
|
|
100
|
+
/<(\w+Interaction)(\s[^>]*)?>[\s\S]*?<\/\1>/gi,
|
|
101
|
+
(match, tagName) => {
|
|
102
|
+
// Skip inline interactions (already handled above)
|
|
103
|
+
if (tagName.toLowerCase() === 'textentryinteraction' ||
|
|
104
|
+
tagName.toLowerCase() === 'inlinechoiceinteraction') {
|
|
105
|
+
return match;
|
|
106
|
+
}
|
|
107
|
+
// Wrap block interactions with a hidden span
|
|
108
|
+
return `<span class="qti-hidden-interaction">${match}</span>`;
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return html;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Inline interaction parsing (textEntry, inlineChoice) — kept local to avoid TS issues
|
|
116
|
+
// around component props inference in runes mode.
|
|
117
|
+
interface ParsedSegment {
|
|
118
|
+
type: 'html' | 'textEntry' | 'inlineChoice';
|
|
119
|
+
content?: string;
|
|
120
|
+
interaction?: any;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const inlineSegments = $derived.by(() => {
|
|
124
|
+
const html = itemBodyHtml;
|
|
125
|
+
const result: ParsedSegment[] = [];
|
|
126
|
+
|
|
127
|
+
let lastIndex = 0;
|
|
128
|
+
let match: RegExpExecArray | null;
|
|
129
|
+
|
|
130
|
+
// Find placeholders in order.
|
|
131
|
+
const combinedPattern = /\[TEXTENTRY:([^\]]+)\]|\[INLINECHOICE:([^\]]+)\]/g;
|
|
132
|
+
|
|
133
|
+
while ((match = combinedPattern.exec(html)) !== null) {
|
|
134
|
+
if (match.index > lastIndex) {
|
|
135
|
+
result.push({ type: 'html', content: html.substring(lastIndex, match.index) });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (match[0].startsWith('[TEXTENTRY:')) {
|
|
139
|
+
const responseId = match[1];
|
|
140
|
+
const interaction = (interactions as any[]).find((i) => i.responseId === responseId);
|
|
141
|
+
if (interaction) result.push({ type: 'textEntry', interaction });
|
|
142
|
+
} else if (match[0].startsWith('[INLINECHOICE:')) {
|
|
143
|
+
const responseId = match[2];
|
|
144
|
+
const interaction = (interactions as any[]).find((i) => i.responseId === responseId);
|
|
145
|
+
if (interaction) result.push({ type: 'inlineChoice', interaction });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
lastIndex = match.index + match[0].length;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (lastIndex < html.length) {
|
|
152
|
+
result.push({ type: 'html', content: html.substring(lastIndex) });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (result.length === 0) {
|
|
156
|
+
result.push({ type: 'html', content: html });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
function handleResponseChange(responseId: string, value: any) {
|
|
163
|
+
onResponseChange(responseId, value);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function handleTextEntryInput(responseId: string, e: Event) {
|
|
167
|
+
const value = (e.currentTarget as HTMLInputElement | null)?.value ?? '';
|
|
168
|
+
handleResponseChange(responseId, value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function handleInlineChoiceChange(responseId: string, e: Event) {
|
|
172
|
+
const value = (e.currentTarget as HTMLSelectElement | null)?.value ?? '';
|
|
173
|
+
handleResponseChange(responseId, value);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Helper to find correct choice for inline choice interactions
|
|
177
|
+
function findCorrectChoice(choices: any[], correctAnswer: string | null): any {
|
|
178
|
+
if (!correctAnswer) return null;
|
|
179
|
+
return choices.find((c: any) => c.identifier === correctAnswer) || null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Handle qti:change events from web components
|
|
183
|
+
function handleQtiChange(event: CustomEvent) {
|
|
184
|
+
const { responseId, value } = event.detail;
|
|
185
|
+
handleResponseChange(responseId, value);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// In runes mode, prefer explicit DOM listener wiring to avoid edge cases with
|
|
189
|
+
// custom events bubbling out of shadow DOM (and to keep typing sane for dynamic elements).
|
|
190
|
+
let rootEl: HTMLDivElement | null = $state(null);
|
|
191
|
+
$effect(() => {
|
|
192
|
+
if (!rootEl) return;
|
|
193
|
+
const handler = (e: Event) => handleQtiChange(e as CustomEvent);
|
|
194
|
+
const el = rootEl; // Capture reference for cleanup
|
|
195
|
+
el.addEventListener('qti-change', handler as EventListener);
|
|
196
|
+
return () => {
|
|
197
|
+
el.removeEventListener('qti-change', handler as EventListener);
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Ensure web-component instances are not accidentally reused across items when
|
|
202
|
+
// different items share the same responseId (common in QTI demos: "RESPONSE").
|
|
203
|
+
function interactionKey(interaction: InteractionData): string {
|
|
204
|
+
const anyInteraction = interaction as any;
|
|
205
|
+
const ids =
|
|
206
|
+
Array.isArray(anyInteraction?.choices) && anyInteraction.choices.length > 0
|
|
207
|
+
? anyInteraction.choices.map((c: any) => c?.identifier).filter(Boolean).join(',')
|
|
208
|
+
: '';
|
|
209
|
+
// Include prompt if present to further reduce accidental reuse.
|
|
210
|
+
const prompt = typeof anyInteraction?.prompt === 'string' ? anyInteraction.prompt : '';
|
|
211
|
+
return `${interaction.type}|${interaction.responseId}|${ids}|${prompt}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Action to set typeset and i18n on web components when they mount
|
|
215
|
+
function setWebComponentProps(
|
|
216
|
+
node: HTMLElement,
|
|
217
|
+
params: {
|
|
218
|
+
i18n?: I18nProvider;
|
|
219
|
+
typeset?: (el: HTMLElement) => void;
|
|
220
|
+
[key: string]: unknown;
|
|
221
|
+
}
|
|
222
|
+
) {
|
|
223
|
+
// Use microtask to ensure custom element is fully initialized
|
|
224
|
+
queueMicrotask(() => {
|
|
225
|
+
if (!node) return;
|
|
226
|
+
assignProps(node, params);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
update(
|
|
231
|
+
newParams: {
|
|
232
|
+
i18n?: I18nProvider;
|
|
233
|
+
typeset?: (el: HTMLElement) => void;
|
|
234
|
+
[key: string]: unknown;
|
|
235
|
+
}
|
|
236
|
+
) {
|
|
237
|
+
assignProps(node, newParams);
|
|
238
|
+
},
|
|
239
|
+
destroy() {}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
</script>
|
|
243
|
+
|
|
244
|
+
<div bind:this={rootEl} class="qti-item-body" use:typesetAction={{ typeset }}>
|
|
245
|
+
<!-- Item body with inline interactions -->
|
|
246
|
+
<div class="prose max-w-none mb-4">
|
|
247
|
+
<div class="inline-interaction-container">
|
|
248
|
+
{#each inlineSegments as segment}
|
|
249
|
+
{#if segment.type === 'html'}
|
|
250
|
+
{@html segment.content}
|
|
251
|
+
{:else if segment.type === 'textEntry'}
|
|
252
|
+
{@const correctAnswer = role === 'scorer' ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
253
|
+
{@const displayValue = role === 'scorer' && correctAnswer !== null ? correctAnswer : (responses[segment.interaction.responseId] || '')}
|
|
254
|
+
<input
|
|
255
|
+
type="text"
|
|
256
|
+
class="input input-bordered input-sm inline-input"
|
|
257
|
+
class:border-success={correctAnswer !== null}
|
|
258
|
+
class:bg-success={correctAnswer !== null}
|
|
259
|
+
class:bg-opacity-10={correctAnswer !== null}
|
|
260
|
+
style="width: {segment.interaction.expectedLength * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;"
|
|
261
|
+
placeholder="..."
|
|
262
|
+
aria-label={`Text entry ${segment.interaction.responseId}${correctAnswer ? '. Correct answer: ' + correctAnswer : ''}`}
|
|
263
|
+
value={displayValue}
|
|
264
|
+
oninput={(e) => handleTextEntryInput(segment.interaction.responseId, e)}
|
|
265
|
+
{disabled}
|
|
266
|
+
/>
|
|
267
|
+
{:else if segment.type === 'inlineChoice'}
|
|
268
|
+
{@const correctAnswer = role === 'scorer' ? (correctResponses[segment.interaction.responseId] ?? null) : null}
|
|
269
|
+
{@const userResponse = responses[segment.interaction.responseId] || ''}
|
|
270
|
+
{@const displayValue = role === 'scorer' && correctAnswer !== null ? correctAnswer : userResponse}
|
|
271
|
+
{@const correctChoice = findCorrectChoice(segment.interaction.choices, correctAnswer)}
|
|
272
|
+
<span class="inline-choice-wrapper" style="display: inline-block; position: relative;">
|
|
273
|
+
<select
|
|
274
|
+
class="select select-bordered select-sm inline-select"
|
|
275
|
+
class:border-success={correctAnswer !== null}
|
|
276
|
+
class:bg-success={correctAnswer !== null}
|
|
277
|
+
class:bg-opacity-10={correctAnswer !== null}
|
|
278
|
+
style="display: inline-block; margin: 0 4px; width: auto; min-width: 120px;"
|
|
279
|
+
aria-label={`Inline choice ${segment.interaction.responseId}${correctAnswer && correctChoice ? '. Correct answer: ' + (correctChoice as any).text : ''}`}
|
|
280
|
+
value={displayValue}
|
|
281
|
+
onchange={(e) => handleInlineChoiceChange(segment.interaction.responseId, e)}
|
|
282
|
+
{disabled}
|
|
283
|
+
>
|
|
284
|
+
<option value="">{i18n?.t('interactions.inline.selectPlaceholder', 'Select...')}</option>
|
|
285
|
+
{#each segment.interaction.choices as choice}
|
|
286
|
+
{@const isCorrect = correctAnswer === choice.identifier}
|
|
287
|
+
<option value={choice.identifier}>
|
|
288
|
+
{choice.text}{isCorrect ? ' ✓' : ''}
|
|
289
|
+
</option>
|
|
290
|
+
{/each}
|
|
291
|
+
</select>
|
|
292
|
+
{#if correctAnswer !== null && correctChoice}
|
|
293
|
+
<span class="badge badge-success badge-sm" style="position: absolute; top: -1.5rem; left: 0; white-space: nowrap; font-size: 0.7rem;">
|
|
294
|
+
{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}: {(correctChoice as any).text}
|
|
295
|
+
</span>
|
|
296
|
+
{/if}
|
|
297
|
+
</span>
|
|
298
|
+
{/if}
|
|
299
|
+
{/each}
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
|
|
303
|
+
<!-- Block interactions rendered dynamically as web components -->
|
|
304
|
+
{#each interactionComponents as { interaction, tagName } (interactionKey(interaction))}
|
|
305
|
+
{@const correctRespForInteraction = correctResponses[interaction.responseId] ?? null}
|
|
306
|
+
<svelte:element
|
|
307
|
+
this={tagName}
|
|
308
|
+
use:setWebComponentProps={{
|
|
309
|
+
i18n,
|
|
310
|
+
typeset,
|
|
311
|
+
interaction,
|
|
312
|
+
response: responses[interaction.responseId] ?? null,
|
|
313
|
+
correctResponse: role === 'scorer' ? correctRespForInteraction : null,
|
|
314
|
+
disabled,
|
|
315
|
+
role,
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
{/each}
|
|
319
|
+
</div>
|
|
320
|
+
|
|
321
|
+
<style>
|
|
322
|
+
/* Allow the whole item body to shrink inside flex/grid layouts (prevents overflow). */
|
|
323
|
+
.qti-item-body {
|
|
324
|
+
max-width: 100%;
|
|
325
|
+
min-width: 0;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/*
|
|
329
|
+
* Custom elements default to inline; force them to be block-level and width-contained.
|
|
330
|
+
* This prevents wide interactions (SVGs, tables, canvases) from spilling outside panels.
|
|
331
|
+
*/
|
|
332
|
+
:global(.qti-item-body :is(
|
|
333
|
+
pie-qti-choice,
|
|
334
|
+
pie-qti-slider,
|
|
335
|
+
pie-qti-order,
|
|
336
|
+
pie-qti-match,
|
|
337
|
+
pie-qti-associate,
|
|
338
|
+
pie-qti-gap-match,
|
|
339
|
+
pie-qti-hotspot,
|
|
340
|
+
pie-qti-hottext,
|
|
341
|
+
pie-qti-media,
|
|
342
|
+
pie-qti-custom,
|
|
343
|
+
pie-qti-end-attempt,
|
|
344
|
+
pie-qti-position-object,
|
|
345
|
+
pie-qti-graphic-gap-match,
|
|
346
|
+
pie-qti-graphic-order,
|
|
347
|
+
pie-qti-graphic-associate,
|
|
348
|
+
pie-qti-select-point,
|
|
349
|
+
pie-qti-extended-text
|
|
350
|
+
)) {
|
|
351
|
+
display: block;
|
|
352
|
+
max-width: 100%;
|
|
353
|
+
min-width: 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* Keep inline interactions from breaking paragraph flow */
|
|
357
|
+
.inline-interaction-container :global(p) {
|
|
358
|
+
display: inline;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/*
|
|
362
|
+
* Hide all QTI interaction elements wrapped with qti-hidden-interaction.
|
|
363
|
+
* These are rendered separately as web components above.
|
|
364
|
+
* Keeping them in the HTML (but hidden) makes debugging easier and is fully extensible.
|
|
365
|
+
* Any *Interaction element will be automatically wrapped and hidden - no hardcoded list needed!
|
|
366
|
+
*/
|
|
367
|
+
:global(.qti-item-body .qti-hidden-interaction) {
|
|
368
|
+
display: none !important;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/*
|
|
372
|
+
* Style for inline feedback elements that appear within choice text or other content.
|
|
373
|
+
* Provides visual distinction and spacing for feedback that appears inline with content.
|
|
374
|
+
*/
|
|
375
|
+
:global(.qti-feedback-inline) {
|
|
376
|
+
display: inline-block;
|
|
377
|
+
margin-left: 0.5rem;
|
|
378
|
+
padding-left: 0.5rem;
|
|
379
|
+
border-left: 2px solid var(--color-base-content, currentColor);
|
|
380
|
+
opacity: 0.8;
|
|
381
|
+
}
|
|
382
|
+
</style>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Player } from '../core/Player';
|
|
3
|
+
import type { AdaptiveAttemptResult, ModalFeedback, PlayerSecurityConfig, QTIRole } from '../types';
|
|
4
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
5
|
+
import ItemBody from './ItemBody.svelte';
|
|
6
|
+
import ModalFeedbackDisplay from './ModalFeedbackDisplay.svelte';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
itemXml: string;
|
|
10
|
+
role?: QTIRole;
|
|
11
|
+
/** Optional security config (URL policy, embed allowances, Trusted Types). */
|
|
12
|
+
security?: PlayerSecurityConfig;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
typeset?: (element: HTMLElement) => void;
|
|
15
|
+
i18n?: I18nProvider;
|
|
16
|
+
onResponseChange?: (responseId: string, value: any) => void;
|
|
17
|
+
onSubmit?: (responses: Record<string, any>, scoringResult: any) => void;
|
|
18
|
+
/** Called when adaptive item completes (all attempts exhausted) */
|
|
19
|
+
onComplete?: (finalResult: AdaptiveAttemptResult) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
itemXml,
|
|
24
|
+
role = 'candidate',
|
|
25
|
+
security,
|
|
26
|
+
disabled = false,
|
|
27
|
+
typeset,
|
|
28
|
+
i18n,
|
|
29
|
+
onResponseChange,
|
|
30
|
+
onSubmit,
|
|
31
|
+
onComplete,
|
|
32
|
+
}: Props = $props();
|
|
33
|
+
|
|
34
|
+
// Create player instance
|
|
35
|
+
let player = $state<Player | null>(null);
|
|
36
|
+
let responses = $state<Record<string, any>>({});
|
|
37
|
+
let error = $state<string | null>(null);
|
|
38
|
+
let modalFeedback = $state<ModalFeedback[]>([]);
|
|
39
|
+
let outcomeValues = $state<Record<string, any>>({});
|
|
40
|
+
let isAdaptive = $state(false);
|
|
41
|
+
let isCompleted = $state(false);
|
|
42
|
+
let numAttempts = $state(0);
|
|
43
|
+
|
|
44
|
+
// Initialize player when XML changes
|
|
45
|
+
$effect(() => {
|
|
46
|
+
try {
|
|
47
|
+
player = new Player({ itemXml, role, security });
|
|
48
|
+
error = null;
|
|
49
|
+
// Reset state when XML changes
|
|
50
|
+
responses = {};
|
|
51
|
+
modalFeedback = [];
|
|
52
|
+
outcomeValues = {};
|
|
53
|
+
isAdaptive = player.isAdaptive();
|
|
54
|
+
isCompleted = player.isCompleted();
|
|
55
|
+
numAttempts = player.getNumAttempts();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
error = e instanceof Error ? e.message : (i18n?.t('item.parsingError') ?? 'item.parsingError');
|
|
58
|
+
player = null;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function handleResponseChange(responseId: string, value: any) {
|
|
63
|
+
responses = { ...responses, [responseId]: value };
|
|
64
|
+
onResponseChange?.(responseId, value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handleSubmit(countAttempt: boolean = true) {
|
|
68
|
+
if (!player) return;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
// Set responses in player
|
|
72
|
+
player.setResponses(responses);
|
|
73
|
+
|
|
74
|
+
// For adaptive items, use submitAttempt()
|
|
75
|
+
if (isAdaptive && !isCompleted) {
|
|
76
|
+
const result = player.submitAttempt(countAttempt);
|
|
77
|
+
|
|
78
|
+
// Update state
|
|
79
|
+
numAttempts = result.numAttempts;
|
|
80
|
+
isCompleted = result.completed;
|
|
81
|
+
modalFeedback = result.modalFeedback || [];
|
|
82
|
+
outcomeValues = result.outcomeValues || {};
|
|
83
|
+
|
|
84
|
+
// Notify parent
|
|
85
|
+
onSubmit?.(responses, result);
|
|
86
|
+
|
|
87
|
+
// If completed, notify parent
|
|
88
|
+
if (result.completed && onComplete) {
|
|
89
|
+
onComplete(result);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// Non-adaptive item: use standard processResponses()
|
|
93
|
+
const result = player.processResponses();
|
|
94
|
+
modalFeedback = result.modalFeedback || [];
|
|
95
|
+
outcomeValues = result.outcomeValues || {};
|
|
96
|
+
onSubmit?.(responses, result);
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
error = e instanceof Error ? e.message : (i18n?.t('item.processingError') ?? 'item.processingError');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function closeFeedback() {
|
|
104
|
+
modalFeedback = [];
|
|
105
|
+
}
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<div class="qti-item-player">
|
|
109
|
+
{#if error}
|
|
110
|
+
<div class="alert alert-error">
|
|
111
|
+
<span>{error}</span>
|
|
112
|
+
</div>
|
|
113
|
+
{:else if player}
|
|
114
|
+
<ItemBody
|
|
115
|
+
{player}
|
|
116
|
+
{responses}
|
|
117
|
+
{disabled}
|
|
118
|
+
{role}
|
|
119
|
+
{typeset}
|
|
120
|
+
{i18n}
|
|
121
|
+
{outcomeValues}
|
|
122
|
+
onResponseChange={handleResponseChange}
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
{#if role === 'candidate' && !disabled && onSubmit}
|
|
126
|
+
{@const canSubmit = player.canSubmitResponses(responses)}
|
|
127
|
+
<div class="mt-6 flex items-center gap-4">
|
|
128
|
+
<button
|
|
129
|
+
class="btn btn-primary"
|
|
130
|
+
onclick={() => handleSubmit(true)}
|
|
131
|
+
disabled={isCompleted || !canSubmit}
|
|
132
|
+
>
|
|
133
|
+
{isAdaptive && isCompleted ? (i18n?.t('item.completed') ?? 'item.completed') : (i18n?.t('item.submit') ?? 'item.submit')}
|
|
134
|
+
</button>
|
|
135
|
+
|
|
136
|
+
{#if isAdaptive}
|
|
137
|
+
<div class="text-sm text-base-content/70">
|
|
138
|
+
{#if isCompleted}
|
|
139
|
+
<span class="badge badge-success">{i18n?.t('item.complete') ?? 'item.complete'}</span>
|
|
140
|
+
{:else}
|
|
141
|
+
<span>{i18n?.t('item.attempt', { numAttempts: numAttempts + 1 }) ?? `item.attempt (${numAttempts + 1})`}</span>
|
|
142
|
+
{/if}
|
|
143
|
+
</div>
|
|
144
|
+
{/if}
|
|
145
|
+
</div>
|
|
146
|
+
{/if}
|
|
147
|
+
|
|
148
|
+
<!-- Modal feedback display -->
|
|
149
|
+
<ModalFeedbackDisplay feedback={modalFeedback} onClose={closeFeedback} {typeset} {i18n} />
|
|
150
|
+
{:else}
|
|
151
|
+
<div class="alert alert-info">
|
|
152
|
+
<span>{i18n?.t('item.loading') ?? 'item.loading'}</span>
|
|
153
|
+
</div>
|
|
154
|
+
{/if}
|
|
155
|
+
</div>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ModalFeedback } from '../types';
|
|
3
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
4
|
+
import { typesetAction } from './actions/typesetAction';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
feedback: ModalFeedback[];
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
typeset?: (element: HTMLElement) => void;
|
|
10
|
+
i18n?: I18nProvider;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let { feedback = [], onClose, typeset, i18n }: Props = $props();
|
|
14
|
+
|
|
15
|
+
// Show modal if there's feedback
|
|
16
|
+
const hasActiveFeedback = $derived(feedback.length > 0);
|
|
17
|
+
|
|
18
|
+
function handleClose() {
|
|
19
|
+
onClose?.();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function handleBackdropClick(e: MouseEvent) {
|
|
23
|
+
// Close when clicking the backdrop (outside the modal content)
|
|
24
|
+
if (e.target === e.currentTarget) {
|
|
25
|
+
handleClose();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if hasActiveFeedback}
|
|
31
|
+
<!-- DaisyUI Modal -->
|
|
32
|
+
<dialog class="modal modal-open" onclick={handleBackdropClick}>
|
|
33
|
+
<div class="modal-box max-w-3xl">
|
|
34
|
+
<!-- Close button -->
|
|
35
|
+
<button
|
|
36
|
+
class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
|
|
37
|
+
onclick={handleClose}
|
|
38
|
+
aria-label={i18n?.t('feedback.closeFeedback') ?? 'feedback.closeFeedback'}
|
|
39
|
+
>
|
|
40
|
+
✕
|
|
41
|
+
</button>
|
|
42
|
+
|
|
43
|
+
<!-- Feedback content -->
|
|
44
|
+
{#each feedback as item, index}
|
|
45
|
+
<div class="mb-4 {index < feedback.length - 1 ? 'border-b pb-4' : ''}">
|
|
46
|
+
{#if item.title}
|
|
47
|
+
<h3 class="font-bold text-lg mb-2">{item.title}</h3>
|
|
48
|
+
{/if}
|
|
49
|
+
|
|
50
|
+
<!-- Render HTML content with MathJax support -->
|
|
51
|
+
{#if typeset}
|
|
52
|
+
<div
|
|
53
|
+
class="prose max-w-none"
|
|
54
|
+
use:typesetAction={{ typeset }}
|
|
55
|
+
>
|
|
56
|
+
{@html item.content}
|
|
57
|
+
</div>
|
|
58
|
+
{:else}
|
|
59
|
+
<div class="prose max-w-none">
|
|
60
|
+
{@html item.content}
|
|
61
|
+
</div>
|
|
62
|
+
{/if}
|
|
63
|
+
</div>
|
|
64
|
+
{/each}
|
|
65
|
+
|
|
66
|
+
<!-- Action buttons -->
|
|
67
|
+
<div class="modal-action">
|
|
68
|
+
<button class="btn btn-primary" onclick={handleClose}>
|
|
69
|
+
{i18n?.t('common.continue') ?? 'common.continue'}
|
|
70
|
+
</button>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</dialog>
|
|
74
|
+
{/if}
|
|
75
|
+
|
|
76
|
+
<style>
|
|
77
|
+
/* Ensure modal is accessible */
|
|
78
|
+
dialog {
|
|
79
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* Ensure feedback content is readable */
|
|
83
|
+
.modal-box {
|
|
84
|
+
max-height: 80vh;
|
|
85
|
+
overflow-y: auto;
|
|
86
|
+
}
|
|
87
|
+
</style>
|