@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,679 @@
|
|
|
1
|
+
# Custom Extractors Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to create custom extractors for vendor-specific QTI extensions or custom interaction types.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [ElementExtractor Interface](#elementextractor-interface)
|
|
9
|
+
- [Priority System](#priority-system)
|
|
10
|
+
- [Creating a Custom Extractor](#creating-a-custom-extractor)
|
|
11
|
+
- [Validation](#validation)
|
|
12
|
+
- [Plugin Packaging](#plugin-packaging)
|
|
13
|
+
- [Complete Example: ACME Likert Plugin](#complete-example-acme-likert-plugin)
|
|
14
|
+
- [Best Practices](#best-practices)
|
|
15
|
+
- [Testing](#testing)
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
The ExtractionRegistry provides a flexible, priority-based system for extracting data from QTI XML elements. Custom extractors allow you to:
|
|
20
|
+
|
|
21
|
+
- Handle vendor-specific QTI extensions
|
|
22
|
+
- Override standard extraction behavior
|
|
23
|
+
- Add validation logic
|
|
24
|
+
- Support custom interaction types
|
|
25
|
+
|
|
26
|
+
## ElementExtractor Interface
|
|
27
|
+
|
|
28
|
+
Every extractor implements the `ElementExtractor<TData>` interface:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
interface ElementExtractor<TData = any> {
|
|
32
|
+
/** Unique identifier (e.g., 'vendor:custom-choice') */
|
|
33
|
+
id: string;
|
|
34
|
+
|
|
35
|
+
/** Human-readable name */
|
|
36
|
+
name: string;
|
|
37
|
+
|
|
38
|
+
/** Priority for evaluation (higher = checked first) */
|
|
39
|
+
priority: number;
|
|
40
|
+
|
|
41
|
+
/** QTI element types this extractor handles */
|
|
42
|
+
elementTypes: string[];
|
|
43
|
+
|
|
44
|
+
/** Optional description for debugging */
|
|
45
|
+
description?: string;
|
|
46
|
+
|
|
47
|
+
/** Predicate to determine if this extractor can handle the element */
|
|
48
|
+
canHandle(element: QTIElement, context: ExtractionContext): boolean;
|
|
49
|
+
|
|
50
|
+
/** Extract data from the element */
|
|
51
|
+
extract(element: QTIElement, context: ExtractionContext): TData;
|
|
52
|
+
|
|
53
|
+
/** Optional validation of extracted data */
|
|
54
|
+
validate?(data: TData): ValidationResult;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Priority System
|
|
59
|
+
|
|
60
|
+
Extractors are evaluated in priority order (highest first):
|
|
61
|
+
|
|
62
|
+
| Priority Range | Usage | Example |
|
|
63
|
+
|----------------|-------|---------|
|
|
64
|
+
| **1000+** | System-level | Reserved for internal use |
|
|
65
|
+
| **500-999** | Vendor-specific | ACME custom interactions |
|
|
66
|
+
| **100-499** | Third-party plugins | Community plugins |
|
|
67
|
+
| **10-99** | Standard QTI | Built-in QTI 2.2 extractors |
|
|
68
|
+
| **0-9** | Fallback | Generic handlers |
|
|
69
|
+
|
|
70
|
+
**Example:**
|
|
71
|
+
```typescript
|
|
72
|
+
// Vendor extractor (evaluated first)
|
|
73
|
+
const acmeLikertExtractor: ElementExtractor<LikertData> = {
|
|
74
|
+
id: 'acme:likert-choice',
|
|
75
|
+
name: 'ACME Likert Scale',
|
|
76
|
+
priority: 500, // Vendor range
|
|
77
|
+
elementTypes: ['choiceInteraction'],
|
|
78
|
+
canHandle: (element, context) => {
|
|
79
|
+
return context.utils.hasChildWithTag(element, 'acmeLikertScale');
|
|
80
|
+
},
|
|
81
|
+
// ... extract logic
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Standard extractor (evaluated second)
|
|
85
|
+
const standardChoiceExtractor: ElementExtractor<ChoiceData> = {
|
|
86
|
+
id: 'qti:choice-interaction',
|
|
87
|
+
name: 'QTI Standard Choice',
|
|
88
|
+
priority: 10, // Standard range
|
|
89
|
+
elementTypes: ['choiceInteraction'],
|
|
90
|
+
canHandle: (element, context) => {
|
|
91
|
+
return context.utils.hasChildWithTag(element, 'simpleChoice');
|
|
92
|
+
},
|
|
93
|
+
// ... extract logic
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Creating a Custom Extractor
|
|
98
|
+
|
|
99
|
+
### Step 1: Define Your Data Type
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
interface LikertData {
|
|
103
|
+
scale: number; // 1-10
|
|
104
|
+
labels: {
|
|
105
|
+
left: string;
|
|
106
|
+
right: string;
|
|
107
|
+
};
|
|
108
|
+
choices: Array<{
|
|
109
|
+
identifier: string;
|
|
110
|
+
value: number;
|
|
111
|
+
text: string;
|
|
112
|
+
}>;
|
|
113
|
+
prompt: string | null;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Step 2: Implement the Extractor
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import type { ElementExtractor, ExtractionContext, QTIElement } from '@pie-qti/item-player';
|
|
121
|
+
|
|
122
|
+
export const acmeLikertExtractor: ElementExtractor<LikertData> = {
|
|
123
|
+
id: 'acme:likert-choice',
|
|
124
|
+
name: 'ACME Likert Scale',
|
|
125
|
+
priority: 500,
|
|
126
|
+
elementTypes: ['choiceInteraction'],
|
|
127
|
+
description: 'Extracts ACME custom likert scale interactions',
|
|
128
|
+
|
|
129
|
+
canHandle(element: QTIElement, context: ExtractionContext): boolean {
|
|
130
|
+
// Check for vendor-specific element
|
|
131
|
+
return context.utils.hasChildWithTag(element, 'acmeLikertScale');
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
extract(element: QTIElement, context: ExtractionContext): LikertData {
|
|
135
|
+
const { utils } = context;
|
|
136
|
+
|
|
137
|
+
// Extract likert scale configuration
|
|
138
|
+
const likertElement = utils.querySelector(element, 'acmeLikertScale');
|
|
139
|
+
const scale = utils.getNumberAttribute(likertElement, 'scale', 5);
|
|
140
|
+
const leftLabel = utils.getAttribute(likertElement, 'leftLabel', 'Strongly Disagree');
|
|
141
|
+
const rightLabel = utils.getAttribute(likertElement, 'rightLabel', 'Strongly Agree');
|
|
142
|
+
|
|
143
|
+
// Extract choices
|
|
144
|
+
const choiceElements = utils.getChildrenByTag(element, 'simpleChoice');
|
|
145
|
+
const choices = choiceElements.map((choice) => ({
|
|
146
|
+
identifier: utils.getAttribute(choice, 'identifier'),
|
|
147
|
+
value: utils.getNumberAttribute(choice, 'value', 1),
|
|
148
|
+
text: utils.getHtmlContent(choice),
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
// Extract prompt
|
|
152
|
+
const prompt = utils.getPrompt(element);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
scale,
|
|
156
|
+
labels: {
|
|
157
|
+
left: leftLabel,
|
|
158
|
+
right: rightLabel,
|
|
159
|
+
},
|
|
160
|
+
choices,
|
|
161
|
+
prompt,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
validate(data: LikertData) {
|
|
166
|
+
const errors: string[] = [];
|
|
167
|
+
const warnings: string[] = [];
|
|
168
|
+
|
|
169
|
+
// Validate scale
|
|
170
|
+
if (data.scale < 2 || data.scale > 10) {
|
|
171
|
+
errors.push('Likert scale must be between 2 and 10');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Validate choices match scale
|
|
175
|
+
if (data.choices.length !== data.scale) {
|
|
176
|
+
warnings.push(`Number of choices (${data.choices.length}) does not match scale (${data.scale})`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Validate choice values
|
|
180
|
+
for (const choice of data.choices) {
|
|
181
|
+
if (choice.value < 1 || choice.value > data.scale) {
|
|
182
|
+
errors.push(`Choice value ${choice.value} is outside scale range (1-${data.scale})`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
valid: errors.length === 0,
|
|
188
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
189
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Step 3: Register the Extractor
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { createExtractionRegistry } from '@pie-qti/item-player';
|
|
199
|
+
|
|
200
|
+
const registry = createExtractionRegistry();
|
|
201
|
+
|
|
202
|
+
// Register your custom extractor
|
|
203
|
+
registry.register(acmeLikertExtractor);
|
|
204
|
+
|
|
205
|
+
// Now use the registry
|
|
206
|
+
const result = registry.extract(element, context);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Validation
|
|
210
|
+
|
|
211
|
+
The `validate()` method is optional but recommended. It returns a `ValidationResult`:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
interface ValidationResult {
|
|
215
|
+
valid: boolean;
|
|
216
|
+
errors?: string[]; // Blocking errors (extraction failed)
|
|
217
|
+
warnings?: string[]; // Non-blocking issues
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**When to use validation:**
|
|
222
|
+
|
|
223
|
+
- **Errors**: Data is malformed and cannot be used (missing required fields, invalid values)
|
|
224
|
+
- **Warnings**: Data is usable but may have issues (deprecated attributes, unusual values)
|
|
225
|
+
|
|
226
|
+
**Example:**
|
|
227
|
+
```typescript
|
|
228
|
+
validate(data: MyData): ValidationResult {
|
|
229
|
+
const errors: string[] = [];
|
|
230
|
+
const warnings: string[] = [];
|
|
231
|
+
|
|
232
|
+
// Required field check
|
|
233
|
+
if (!data.identifier) {
|
|
234
|
+
errors.push('identifier is required');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Range check
|
|
238
|
+
if (data.maxChoices < 1) {
|
|
239
|
+
errors.push('maxChoices must be at least 1');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Deprecated feature warning
|
|
243
|
+
if (data.usesDeprecatedFeature) {
|
|
244
|
+
warnings.push('This feature is deprecated in QTI 3.0');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
valid: errors.length === 0,
|
|
249
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
250
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Plugin Packaging
|
|
256
|
+
|
|
257
|
+
Package your extractor as a QTI plugin for easy distribution:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
import type { QTIPlugin } from '@pie-qti/item-player';
|
|
261
|
+
|
|
262
|
+
export const acmeLikertPlugin: QTIPlugin = {
|
|
263
|
+
name: '@acme/qti-likert-plugin',
|
|
264
|
+
version: '1.0.0',
|
|
265
|
+
description: 'ACME custom likert scale interactions',
|
|
266
|
+
dependencies: [], // Other plugin names if needed
|
|
267
|
+
|
|
268
|
+
registerExtractors(registry) {
|
|
269
|
+
registry.register(acmeLikertExtractor);
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
registerComponents(registry) {
|
|
273
|
+
// Register web components for rendering
|
|
274
|
+
registry.register('choiceInteraction', {
|
|
275
|
+
name: 'acme-likert-choice',
|
|
276
|
+
priority: 500,
|
|
277
|
+
canHandle: (data) => {
|
|
278
|
+
// Type guard to check if data is LikertData
|
|
279
|
+
return 'scale' in data && 'labels' in data;
|
|
280
|
+
},
|
|
281
|
+
tagName: 'acme-likert-element'
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
lifecycle: {
|
|
286
|
+
onRegister(context) {
|
|
287
|
+
console.log('ACME Likert plugin registered');
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
onBeforeRender(context) {
|
|
291
|
+
// Setup before rendering
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
onAfterRender(context) {
|
|
295
|
+
// Cleanup after rendering
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
onUnregister() {
|
|
299
|
+
console.log('ACME Likert plugin unregistered');
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Using a Plugin
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { Player } from '@pie-qti/item-player';
|
|
309
|
+
import { acmeLikertPlugin } from '@acme/qti-likert-plugin';
|
|
310
|
+
|
|
311
|
+
const player = new Player({
|
|
312
|
+
role: 'candidate',
|
|
313
|
+
plugins: [acmeLikertPlugin]
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
await player.parse(qtiXml);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Complete Example: ACME Likert Plugin
|
|
320
|
+
|
|
321
|
+
Here's a complete, production-ready example:
|
|
322
|
+
|
|
323
|
+
### File Structure
|
|
324
|
+
```
|
|
325
|
+
@acme/qti-likert-plugin/
|
|
326
|
+
├── src/
|
|
327
|
+
│ ├── extractor.ts # Likert extractor
|
|
328
|
+
│ ├── component.ts # Web component
|
|
329
|
+
│ ├── types.ts # TypeScript types
|
|
330
|
+
│ ├── plugin.ts # Plugin definition
|
|
331
|
+
│ └── index.ts # Public API
|
|
332
|
+
├── tests/
|
|
333
|
+
│ ├── extractor.test.ts
|
|
334
|
+
│ └── component.test.ts
|
|
335
|
+
├── package.json
|
|
336
|
+
└── README.md
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### types.ts
|
|
340
|
+
```typescript
|
|
341
|
+
export interface LikertData {
|
|
342
|
+
scale: number;
|
|
343
|
+
labels: {
|
|
344
|
+
left: string;
|
|
345
|
+
right: string;
|
|
346
|
+
};
|
|
347
|
+
choices: Array<{
|
|
348
|
+
identifier: string;
|
|
349
|
+
value: number;
|
|
350
|
+
text: string;
|
|
351
|
+
}>;
|
|
352
|
+
prompt: string | null;
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### extractor.ts
|
|
357
|
+
```typescript
|
|
358
|
+
import type { ElementExtractor, ExtractionContext, QTIElement } from '@pie-qti/item-player';
|
|
359
|
+
import type { LikertData } from './types';
|
|
360
|
+
|
|
361
|
+
export const acmeLikertExtractor: ElementExtractor<LikertData> = {
|
|
362
|
+
id: 'acme:likert-choice',
|
|
363
|
+
name: 'ACME Likert Scale',
|
|
364
|
+
priority: 500,
|
|
365
|
+
elementTypes: ['choiceInteraction'],
|
|
366
|
+
description: 'Extracts ACME custom likert scale interactions',
|
|
367
|
+
|
|
368
|
+
canHandle(element: QTIElement, context: ExtractionContext): boolean {
|
|
369
|
+
return context.utils.hasChildWithTag(element, 'acmeLikertScale');
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
extract(element: QTIElement, context: ExtractionContext): LikertData {
|
|
373
|
+
const { utils } = context;
|
|
374
|
+
|
|
375
|
+
const likertElement = utils.querySelector(element, 'acmeLikertScale')!;
|
|
376
|
+
const scale = utils.getNumberAttribute(likertElement, 'scale', 5);
|
|
377
|
+
|
|
378
|
+
const choiceElements = utils.getChildrenByTag(element, 'simpleChoice');
|
|
379
|
+
const choices = choiceElements.map((choice) => ({
|
|
380
|
+
identifier: utils.getAttribute(choice, 'identifier'),
|
|
381
|
+
value: utils.getNumberAttribute(choice, 'value', 1),
|
|
382
|
+
text: utils.getHtmlContent(choice),
|
|
383
|
+
}));
|
|
384
|
+
|
|
385
|
+
return {
|
|
386
|
+
scale,
|
|
387
|
+
labels: {
|
|
388
|
+
left: utils.getAttribute(likertElement, 'leftLabel', 'Strongly Disagree'),
|
|
389
|
+
right: utils.getAttribute(likertElement, 'rightLabel', 'Strongly Agree'),
|
|
390
|
+
},
|
|
391
|
+
choices,
|
|
392
|
+
prompt: utils.getPrompt(element),
|
|
393
|
+
};
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
validate(data: LikertData) {
|
|
397
|
+
const errors: string[] = [];
|
|
398
|
+
const warnings: string[] = [];
|
|
399
|
+
|
|
400
|
+
if (data.scale < 2 || data.scale > 10) {
|
|
401
|
+
errors.push('Likert scale must be between 2 and 10');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (data.choices.length !== data.scale) {
|
|
405
|
+
warnings.push(`Number of choices (${data.choices.length}) does not match scale (${data.scale})`);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
for (const choice of data.choices) {
|
|
409
|
+
if (choice.value < 1 || choice.value > data.scale) {
|
|
410
|
+
errors.push(`Choice value ${choice.value} is outside scale range`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return {
|
|
415
|
+
valid: errors.length === 0,
|
|
416
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
417
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
418
|
+
};
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### plugin.ts
|
|
424
|
+
```typescript
|
|
425
|
+
import type { QTIPlugin } from '@pie-qti/item-player';
|
|
426
|
+
import { acmeLikertExtractor } from './extractor';
|
|
427
|
+
|
|
428
|
+
export const acmeLikertPlugin: QTIPlugin = {
|
|
429
|
+
name: '@acme/qti-likert-plugin',
|
|
430
|
+
version: '1.0.0',
|
|
431
|
+
description: 'ACME custom likert scale interactions',
|
|
432
|
+
|
|
433
|
+
registerExtractors(registry) {
|
|
434
|
+
registry.register(acmeLikertExtractor);
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
registerComponents(registry) {
|
|
438
|
+
registry.register('choiceInteraction', {
|
|
439
|
+
name: 'acme-likert-choice',
|
|
440
|
+
priority: 500,
|
|
441
|
+
canHandle: (data) => 'scale' in data && 'labels' in data,
|
|
442
|
+
tagName: 'acme-likert-element'
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
lifecycle: {
|
|
447
|
+
onRegister() {
|
|
448
|
+
console.log('[ACME Likert] Plugin registered');
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### index.ts
|
|
455
|
+
```typescript
|
|
456
|
+
export { acmeLikertPlugin } from './plugin';
|
|
457
|
+
export { acmeLikertExtractor } from './extractor';
|
|
458
|
+
export type { LikertData } from './types';
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Usage
|
|
462
|
+
```typescript
|
|
463
|
+
import { Player } from '@pie-qti/item-player';
|
|
464
|
+
import { acmeLikertPlugin } from '@acme/qti-likert-plugin';
|
|
465
|
+
|
|
466
|
+
const player = new Player({
|
|
467
|
+
role: 'candidate',
|
|
468
|
+
plugins: [acmeLikertPlugin]
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
await player.parse(`
|
|
472
|
+
<assessmentItem>
|
|
473
|
+
<itemBody>
|
|
474
|
+
<choiceInteraction responseIdentifier="RESPONSE">
|
|
475
|
+
<acmeLikertScale scale="5" leftLabel="Strongly Disagree" rightLabel="Strongly Agree"/>
|
|
476
|
+
<prompt>Rate your satisfaction with our product:</prompt>
|
|
477
|
+
<simpleChoice identifier="C1" value="1">1</simpleChoice>
|
|
478
|
+
<simpleChoice identifier="C2" value="2">2</simpleChoice>
|
|
479
|
+
<simpleChoice identifier="C3" value="3">3</simpleChoice>
|
|
480
|
+
<simpleChoice identifier="C4" value="4">4</simpleChoice>
|
|
481
|
+
<simpleChoice identifier="C5" value="5">5</simpleChoice>
|
|
482
|
+
</choiceInteraction>
|
|
483
|
+
</itemBody>
|
|
484
|
+
</assessmentItem>
|
|
485
|
+
`);
|
|
486
|
+
|
|
487
|
+
// Render will automatically use ACME likert component
|
|
488
|
+
const renderer = player.createRenderer(document.getElementById('container')!);
|
|
489
|
+
renderer.render();
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
## Best Practices
|
|
493
|
+
|
|
494
|
+
### 1. Use Specific canHandle() Predicates
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
// ❌ BAD - too broad
|
|
498
|
+
canHandle(element, context) {
|
|
499
|
+
return element.rawTagName === 'choiceInteraction';
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ✅ GOOD - specific check
|
|
503
|
+
canHandle(element, context) {
|
|
504
|
+
return (
|
|
505
|
+
element.rawTagName === 'choiceInteraction' &&
|
|
506
|
+
context.utils.hasChildWithTag(element, 'acmeLikertScale')
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### 2. Use Appropriate Priorities
|
|
512
|
+
|
|
513
|
+
- **500-999**: Vendor-specific extractors (your custom QTI extensions)
|
|
514
|
+
- **100-499**: Third-party plugins (community packages)
|
|
515
|
+
- **10-99**: Standard QTI extractors (built-in)
|
|
516
|
+
|
|
517
|
+
### 3. Always Validate Critical Data
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
validate(data) {
|
|
521
|
+
const errors: string[] = [];
|
|
522
|
+
|
|
523
|
+
// Required fields
|
|
524
|
+
if (!data.identifier) {
|
|
525
|
+
errors.push('identifier is required');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// Type checks
|
|
529
|
+
if (typeof data.maxChoices !== 'number') {
|
|
530
|
+
errors.push('maxChoices must be a number');
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Range checks
|
|
534
|
+
if (data.maxChoices < 1) {
|
|
535
|
+
errors.push('maxChoices must be at least 1');
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return {
|
|
539
|
+
valid: errors.length === 0,
|
|
540
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### 4. Use ExtractionUtils Helpers
|
|
546
|
+
|
|
547
|
+
Don't reinvent the wheel - use the provided utilities:
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
extract(element, context) {
|
|
551
|
+
const { utils } = context;
|
|
552
|
+
|
|
553
|
+
// ✅ Use helpers
|
|
554
|
+
const choices = utils.getChildrenByTag(element, 'simpleChoice');
|
|
555
|
+
const prompt = utils.getPrompt(element);
|
|
556
|
+
const shuffle = utils.getBooleanAttribute(element, 'shuffle');
|
|
557
|
+
const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
|
|
558
|
+
|
|
559
|
+
// ❌ Don't manually parse
|
|
560
|
+
const choicesManual = element.childNodes.filter(n => n.rawTagName === 'simpleChoice');
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
### 5. Handle Missing Data Gracefully
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
extract(element, context) {
|
|
568
|
+
const { utils } = context;
|
|
569
|
+
|
|
570
|
+
// ✅ Provide defaults
|
|
571
|
+
const title = utils.getAttribute(element, 'title', 'Untitled');
|
|
572
|
+
const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
|
|
573
|
+
const prompt = utils.getPrompt(element); // Returns null if missing
|
|
574
|
+
|
|
575
|
+
// ✅ Optional fields
|
|
576
|
+
const description = utils.getAttribute(element, 'description', '');
|
|
577
|
+
return {
|
|
578
|
+
title,
|
|
579
|
+
maxChoices,
|
|
580
|
+
prompt,
|
|
581
|
+
...(description ? { description } : {}),
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### 6. Write Comprehensive Tests
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
import { describe, test, expect } from 'bun:test';
|
|
590
|
+
import { acmeLikertExtractor } from './extractor';
|
|
591
|
+
import { createTestContext, parseQTI } from '../test-utils';
|
|
592
|
+
|
|
593
|
+
describe('acmeLikertExtractor', () => {
|
|
594
|
+
test('extracts basic likert scale', () => {
|
|
595
|
+
const xml = `
|
|
596
|
+
<choiceInteraction responseIdentifier="RESPONSE">
|
|
597
|
+
<acmeLikertScale scale="5"/>
|
|
598
|
+
<simpleChoice identifier="C1" value="1">1</simpleChoice>
|
|
599
|
+
<simpleChoice identifier="C2" value="2">2</simpleChoice>
|
|
600
|
+
</choiceInteraction>
|
|
601
|
+
`;
|
|
602
|
+
const element = parseQTI(xml);
|
|
603
|
+
const context = createTestContext(element);
|
|
604
|
+
|
|
605
|
+
const result = acmeLikertExtractor.extract(element, context);
|
|
606
|
+
|
|
607
|
+
expect(result.scale).toBe(5);
|
|
608
|
+
expect(result.choices).toHaveLength(2);
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
test('validates scale range', () => {
|
|
612
|
+
const data = { scale: 15, labels: { left: 'A', right: 'B' }, choices: [], prompt: null };
|
|
613
|
+
const validation = acmeLikertExtractor.validate!(data);
|
|
614
|
+
|
|
615
|
+
expect(validation.valid).toBe(false);
|
|
616
|
+
expect(validation.errors).toContain('Likert scale must be between 2 and 10');
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
## Testing
|
|
622
|
+
|
|
623
|
+
### Unit Tests
|
|
624
|
+
|
|
625
|
+
Test your extractor in isolation:
|
|
626
|
+
|
|
627
|
+
```bash
|
|
628
|
+
bun test tests/extraction/extractors/myExtractor.test.ts
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
### Integration Tests
|
|
632
|
+
|
|
633
|
+
Test with the full registry:
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
import { createExtractionRegistry, createExtractionContext } from '@pie-qti/item-player';
|
|
637
|
+
import { myExtractor } from './myExtractor';
|
|
638
|
+
|
|
639
|
+
test('custom extractor integrates with registry', () => {
|
|
640
|
+
const registry = createExtractionRegistry();
|
|
641
|
+
registry.register(myExtractor);
|
|
642
|
+
|
|
643
|
+
const element = parseQTI('<myInteraction/>');
|
|
644
|
+
const context = createExtractionContext(element, 'RESPONSE', element, new Map(), {});
|
|
645
|
+
|
|
646
|
+
const result = registry.extract(element, context);
|
|
647
|
+
|
|
648
|
+
expect(result.success).toBe(true);
|
|
649
|
+
});
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### End-to-End Tests
|
|
653
|
+
|
|
654
|
+
Test with the full Player:
|
|
655
|
+
|
|
656
|
+
```typescript
|
|
657
|
+
import { Player } from '@pie-qti/item-player';
|
|
658
|
+
import { myPlugin } from './myPlugin';
|
|
659
|
+
|
|
660
|
+
test('plugin works with Player', async () => {
|
|
661
|
+
const player = new Player({
|
|
662
|
+
role: 'candidate',
|
|
663
|
+
plugins: [myPlugin]
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
await player.parse(qtiXml);
|
|
667
|
+
const interactions = player.getInteractions();
|
|
668
|
+
|
|
669
|
+
expect(interactions).toHaveLength(1);
|
|
670
|
+
expect(interactions[0].type).toBe('myInteraction');
|
|
671
|
+
});
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
## Resources
|
|
675
|
+
|
|
676
|
+
- **TypeScript Definitions**: See `src/extraction/types.ts` for all type definitions
|
|
677
|
+
- **Built-in Extractors**: See `src/extraction/extractors/` for 21 examples
|
|
678
|
+
- **Example Plugin**: See `packages/acme-likert-plugin/` for a complete working example
|
|
679
|
+
- **Player API**: See `README.md` for Player documentation
|