@pie-qti/item-player 0.1.5 → 0.1.7
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/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
- package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
- package/dist/catalog/applyGlossaryTriggers.js +145 -30
- package/dist/catalog/glossaryAction.d.ts.map +1 -1
- package/dist/catalog/glossaryAction.js +14 -4
- package/dist/components/utils/stimulusRender.d.ts +17 -0
- package/dist/components/utils/stimulusRender.d.ts.map +1 -0
- package/dist/components/utils/stimulusRender.js +70 -0
- package/dist/components/utils/stylesheetRender.d.ts +4 -0
- package/dist/components/utils/stylesheetRender.d.ts.map +1 -0
- package/dist/components/utils/stylesheetRender.js +57 -0
- package/dist/core/ComponentRegistry.d.ts +5 -4
- package/dist/core/ComponentRegistry.d.ts.map +1 -1
- package/dist/core/ComponentRegistry.js +11 -4
- package/dist/core/ItemRenderer.d.ts.map +1 -1
- package/dist/core/ItemRenderer.js +5 -18
- package/dist/core/Player.d.ts +39 -4
- package/dist/core/Player.d.ts.map +1 -1
- package/dist/core/Player.js +364 -193
- package/dist/document/AssessmentItemDocument.d.ts +42 -0
- package/dist/document/AssessmentItemDocument.d.ts.map +1 -0
- package/dist/document/AssessmentItemDocument.js +116 -0
- package/dist/element.js +3318 -2733
- package/dist/element.js.map +1 -1
- package/dist/extraction/extractors/associateExtractor.d.ts +1 -28
- package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/associateExtractor.js +1 -97
- package/dist/extraction/extractors/choiceExtractor.d.ts +1 -26
- package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/choiceExtractor.js +1 -93
- package/dist/extraction/extractors/customExtractor.d.ts +1 -19
- package/dist/extraction/extractors/customExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/customExtractor.js +1 -51
- package/dist/extraction/extractors/drawingExtractor.d.ts +1 -29
- package/dist/extraction/extractors/drawingExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/drawingExtractor.js +1 -78
- package/dist/extraction/extractors/endAttemptExtractor.d.ts +1 -19
- package/dist/extraction/extractors/endAttemptExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/endAttemptExtractor.js +1 -53
- package/dist/extraction/extractors/extendedTextExtractor.d.ts +1 -20
- package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/extendedTextExtractor.js +1 -63
- package/dist/extraction/extractors/gapMatchExtractor.d.ts +1 -28
- package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/gapMatchExtractor.js +1 -155
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +1 -40
- package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicAssociateExtractor.js +1 -143
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +1 -52
- package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicGapMatchExtractor.js +1 -205
- package/dist/extraction/extractors/graphicOrderExtractor.d.ts +1 -36
- package/dist/extraction/extractors/graphicOrderExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/graphicOrderExtractor.js +1 -121
- package/dist/extraction/extractors/hotspotExtractor.d.ts +1 -37
- package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hotspotExtractor.js +1 -159
- package/dist/extraction/extractors/hottextExtractor.d.ts +1 -25
- package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/hottextExtractor.js +1 -128
- package/dist/extraction/extractors/index.d.ts +5 -59
- package/dist/extraction/extractors/index.d.ts.map +1 -1
- package/dist/extraction/extractors/index.js +5 -85
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +1 -24
- package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/inlineChoiceExtractor.js +1 -80
- package/dist/extraction/extractors/matchExtractor.d.ts +1 -36
- package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/matchExtractor.js +1 -160
- package/dist/extraction/extractors/mediaExtractor.d.ts +1 -32
- package/dist/extraction/extractors/mediaExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/mediaExtractor.js +1 -125
- package/dist/extraction/extractors/orderExtractor.d.ts +1 -27
- package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/orderExtractor.js +1 -90
- package/dist/extraction/extractors/portableCustomExtractor.d.ts +1 -13
- package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/portableCustomExtractor.js +1 -96
- package/dist/extraction/extractors/positionObjectExtractor.d.ts +1 -58
- package/dist/extraction/extractors/positionObjectExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/positionObjectExtractor.js +1 -191
- package/dist/extraction/extractors/selectPointExtractor.d.ts +1 -30
- package/dist/extraction/extractors/selectPointExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/selectPointExtractor.js +1 -109
- package/dist/extraction/extractors/sliderExtractor.d.ts +1 -23
- package/dist/extraction/extractors/sliderExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/sliderExtractor.js +1 -73
- package/dist/extraction/extractors/textEntryExtractor.d.ts +1 -20
- package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/textEntryExtractor.js +1 -54
- package/dist/extraction/extractors/uploadExtractor.d.ts +1 -19
- package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -1
- package/dist/extraction/extractors/uploadExtractor.js +1 -59
- package/dist/extraction/index.d.ts +1 -1
- package/dist/extraction/index.d.ts.map +1 -1
- package/dist/extraction/index.js +2 -2
- package/dist/extraction/interactionExtractionPipeline.d.ts +13 -0
- package/dist/extraction/interactionExtractionPipeline.d.ts.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.js +39 -0
- package/dist/extraction/interactionSecurity.d.ts +4 -0
- package/dist/extraction/interactionSecurity.d.ts.map +1 -0
- package/dist/extraction/interactionSecurity.js +48 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/interactions/associate/extractor.d.ts +29 -0
- package/dist/interactions/associate/extractor.d.ts.map +1 -0
- package/dist/interactions/associate/extractor.js +97 -0
- package/dist/interactions/associate/index.d.ts +3 -0
- package/dist/interactions/associate/index.d.ts.map +1 -0
- package/dist/interactions/associate/index.js +1 -0
- package/dist/interactions/associate/types.d.ts +2 -0
- package/dist/interactions/associate/types.d.ts.map +1 -0
- package/dist/interactions/associate/types.js +1 -0
- package/dist/interactions/choice/extractor.d.ts +27 -0
- package/dist/interactions/choice/extractor.d.ts.map +1 -0
- package/dist/interactions/choice/extractor.js +93 -0
- package/dist/interactions/choice/index.d.ts +3 -0
- package/dist/interactions/choice/index.d.ts.map +1 -0
- package/dist/interactions/choice/index.js +1 -0
- package/dist/interactions/choice/types.d.ts +2 -0
- package/dist/interactions/choice/types.d.ts.map +1 -0
- package/dist/interactions/choice/types.js +1 -0
- package/dist/interactions/custom/extractor.d.ts +20 -0
- package/dist/interactions/custom/extractor.d.ts.map +1 -0
- package/dist/interactions/custom/extractor.js +51 -0
- package/dist/interactions/custom/index.d.ts +3 -0
- package/dist/interactions/custom/index.d.ts.map +1 -0
- package/dist/interactions/custom/index.js +1 -0
- package/dist/interactions/custom/types.d.ts +2 -0
- package/dist/interactions/custom/types.d.ts.map +1 -0
- package/dist/interactions/custom/types.js +1 -0
- package/dist/interactions/drawing/extractor.d.ts +30 -0
- package/dist/interactions/drawing/extractor.d.ts.map +1 -0
- package/dist/interactions/drawing/extractor.js +78 -0
- package/dist/interactions/drawing/index.d.ts +3 -0
- package/dist/interactions/drawing/index.d.ts.map +1 -0
- package/dist/interactions/drawing/index.js +1 -0
- package/dist/interactions/drawing/types.d.ts +2 -0
- package/dist/interactions/drawing/types.d.ts.map +1 -0
- package/dist/interactions/drawing/types.js +1 -0
- package/dist/interactions/end-attempt/extractor.d.ts +20 -0
- package/dist/interactions/end-attempt/extractor.d.ts.map +1 -0
- package/dist/interactions/end-attempt/extractor.js +53 -0
- package/dist/interactions/end-attempt/index.d.ts +3 -0
- package/dist/interactions/end-attempt/index.d.ts.map +1 -0
- package/dist/interactions/end-attempt/index.js +1 -0
- package/dist/interactions/end-attempt/types.d.ts +2 -0
- package/dist/interactions/end-attempt/types.d.ts.map +1 -0
- package/dist/interactions/end-attempt/types.js +1 -0
- package/dist/interactions/extended-text/extractor.d.ts +21 -0
- package/dist/interactions/extended-text/extractor.d.ts.map +1 -0
- package/dist/interactions/extended-text/extractor.js +63 -0
- package/dist/interactions/extended-text/index.d.ts +3 -0
- package/dist/interactions/extended-text/index.d.ts.map +1 -0
- package/dist/interactions/extended-text/index.js +1 -0
- package/dist/interactions/extended-text/types.d.ts +2 -0
- package/dist/interactions/extended-text/types.d.ts.map +1 -0
- package/dist/interactions/extended-text/types.js +1 -0
- package/dist/interactions/gap-match/extractor.d.ts +29 -0
- package/dist/interactions/gap-match/extractor.d.ts.map +1 -0
- package/dist/interactions/gap-match/extractor.js +155 -0
- package/dist/interactions/gap-match/index.d.ts +3 -0
- package/dist/interactions/gap-match/index.d.ts.map +1 -0
- package/dist/interactions/gap-match/index.js +1 -0
- package/dist/interactions/gap-match/types.d.ts +2 -0
- package/dist/interactions/gap-match/types.d.ts.map +1 -0
- package/dist/interactions/gap-match/types.js +1 -0
- package/dist/interactions/graphic-associate/extractor.d.ts +41 -0
- package/dist/interactions/graphic-associate/extractor.d.ts.map +1 -0
- package/dist/interactions/graphic-associate/extractor.js +143 -0
- package/dist/interactions/graphic-associate/index.d.ts +3 -0
- package/dist/interactions/graphic-associate/index.d.ts.map +1 -0
- package/dist/interactions/graphic-associate/index.js +1 -0
- package/dist/interactions/graphic-associate/types.d.ts +2 -0
- package/dist/interactions/graphic-associate/types.d.ts.map +1 -0
- package/dist/interactions/graphic-associate/types.js +1 -0
- package/dist/interactions/graphic-gap-match/extractor.d.ts +53 -0
- package/dist/interactions/graphic-gap-match/extractor.d.ts.map +1 -0
- package/dist/interactions/graphic-gap-match/extractor.js +205 -0
- package/dist/interactions/graphic-gap-match/index.d.ts +3 -0
- package/dist/interactions/graphic-gap-match/index.d.ts.map +1 -0
- package/dist/interactions/graphic-gap-match/index.js +1 -0
- package/dist/interactions/graphic-gap-match/types.d.ts +2 -0
- package/dist/interactions/graphic-gap-match/types.d.ts.map +1 -0
- package/dist/interactions/graphic-gap-match/types.js +1 -0
- package/dist/interactions/graphic-order/extractor.d.ts +37 -0
- package/dist/interactions/graphic-order/extractor.d.ts.map +1 -0
- package/dist/interactions/graphic-order/extractor.js +121 -0
- package/dist/interactions/graphic-order/index.d.ts +3 -0
- package/dist/interactions/graphic-order/index.d.ts.map +1 -0
- package/dist/interactions/graphic-order/index.js +1 -0
- package/dist/interactions/graphic-order/types.d.ts +2 -0
- package/dist/interactions/graphic-order/types.d.ts.map +1 -0
- package/dist/interactions/graphic-order/types.js +1 -0
- package/dist/interactions/hotspot/extractor.d.ts +38 -0
- package/dist/interactions/hotspot/extractor.d.ts.map +1 -0
- package/dist/interactions/hotspot/extractor.js +159 -0
- package/dist/interactions/hotspot/index.d.ts +3 -0
- package/dist/interactions/hotspot/index.d.ts.map +1 -0
- package/dist/interactions/hotspot/index.js +1 -0
- package/dist/interactions/hotspot/types.d.ts +2 -0
- package/dist/interactions/hotspot/types.d.ts.map +1 -0
- package/dist/interactions/hotspot/types.js +1 -0
- package/dist/interactions/hottext/extractor.d.ts +26 -0
- package/dist/interactions/hottext/extractor.d.ts.map +1 -0
- package/dist/interactions/hottext/extractor.js +128 -0
- package/dist/interactions/hottext/index.d.ts +3 -0
- package/dist/interactions/hottext/index.d.ts.map +1 -0
- package/dist/interactions/hottext/index.js +1 -0
- package/dist/interactions/hottext/types.d.ts +2 -0
- package/dist/interactions/hottext/types.d.ts.map +1 -0
- package/dist/interactions/hottext/types.js +1 -0
- package/dist/interactions/index.d.ts +33 -0
- package/dist/interactions/index.d.ts.map +1 -0
- package/dist/interactions/index.js +30 -0
- package/dist/interactions/inline/index.d.ts +2 -0
- package/dist/interactions/inline/index.d.ts.map +1 -0
- package/dist/interactions/inline/index.js +1 -0
- package/dist/interactions/inline/render-plan.d.ts +19 -0
- package/dist/interactions/inline/render-plan.d.ts.map +1 -0
- package/dist/interactions/inline/render-plan.js +59 -0
- package/dist/interactions/inline-choice/extractor.d.ts +25 -0
- package/dist/interactions/inline-choice/extractor.d.ts.map +1 -0
- package/dist/interactions/inline-choice/extractor.js +80 -0
- package/dist/interactions/inline-choice/index.d.ts +3 -0
- package/dist/interactions/inline-choice/index.d.ts.map +1 -0
- package/dist/interactions/inline-choice/index.js +1 -0
- package/dist/interactions/inline-choice/types.d.ts +2 -0
- package/dist/interactions/inline-choice/types.d.ts.map +1 -0
- package/dist/interactions/inline-choice/types.js +1 -0
- package/dist/interactions/match/extractor.d.ts +37 -0
- package/dist/interactions/match/extractor.d.ts.map +1 -0
- package/dist/interactions/match/extractor.js +160 -0
- package/dist/interactions/match/index.d.ts +3 -0
- package/dist/interactions/match/index.d.ts.map +1 -0
- package/dist/interactions/match/index.js +1 -0
- package/dist/interactions/match/types.d.ts +2 -0
- package/dist/interactions/match/types.d.ts.map +1 -0
- package/dist/interactions/match/types.js +1 -0
- package/dist/interactions/media/extractor.d.ts +33 -0
- package/dist/interactions/media/extractor.d.ts.map +1 -0
- package/dist/interactions/media/extractor.js +125 -0
- package/dist/interactions/media/index.d.ts +3 -0
- package/dist/interactions/media/index.d.ts.map +1 -0
- package/dist/interactions/media/index.js +1 -0
- package/dist/interactions/media/types.d.ts +2 -0
- package/dist/interactions/media/types.d.ts.map +1 -0
- package/dist/interactions/media/types.js +1 -0
- package/dist/interactions/modules.d.ts +105 -0
- package/dist/interactions/modules.d.ts.map +1 -0
- package/dist/interactions/modules.js +86 -0
- package/dist/interactions/order/extractor.d.ts +28 -0
- package/dist/interactions/order/extractor.d.ts.map +1 -0
- package/dist/interactions/order/extractor.js +90 -0
- package/dist/interactions/order/index.d.ts +3 -0
- package/dist/interactions/order/index.d.ts.map +1 -0
- package/dist/interactions/order/index.js +1 -0
- package/dist/interactions/order/types.d.ts +2 -0
- package/dist/interactions/order/types.d.ts.map +1 -0
- package/dist/interactions/order/types.js +1 -0
- package/dist/interactions/portable-custom/extractor.d.ts +14 -0
- package/dist/interactions/portable-custom/extractor.d.ts.map +1 -0
- package/dist/interactions/portable-custom/extractor.js +96 -0
- package/dist/interactions/portable-custom/index.d.ts +3 -0
- package/dist/interactions/portable-custom/index.d.ts.map +1 -0
- package/dist/interactions/portable-custom/index.js +1 -0
- package/dist/interactions/portable-custom/types.d.ts +2 -0
- package/dist/interactions/portable-custom/types.d.ts.map +1 -0
- package/dist/interactions/portable-custom/types.js +1 -0
- package/dist/interactions/position-object/extractor.d.ts +59 -0
- package/dist/interactions/position-object/extractor.d.ts.map +1 -0
- package/dist/interactions/position-object/extractor.js +191 -0
- package/dist/interactions/position-object/index.d.ts +3 -0
- package/dist/interactions/position-object/index.d.ts.map +1 -0
- package/dist/interactions/position-object/index.js +1 -0
- package/dist/interactions/position-object/types.d.ts +2 -0
- package/dist/interactions/position-object/types.d.ts.map +1 -0
- package/dist/interactions/position-object/types.js +1 -0
- package/dist/interactions/select-point/extractor.d.ts +31 -0
- package/dist/interactions/select-point/extractor.d.ts.map +1 -0
- package/dist/interactions/select-point/extractor.js +109 -0
- package/dist/interactions/select-point/index.d.ts +3 -0
- package/dist/interactions/select-point/index.d.ts.map +1 -0
- package/dist/interactions/select-point/index.js +1 -0
- package/dist/interactions/select-point/types.d.ts +2 -0
- package/dist/interactions/select-point/types.d.ts.map +1 -0
- package/dist/interactions/select-point/types.js +1 -0
- package/dist/interactions/shared/index.d.ts +2 -0
- package/dist/interactions/shared/index.d.ts.map +1 -0
- package/dist/interactions/shared/index.js +1 -0
- package/dist/interactions/shared/types.d.ts +412 -0
- package/dist/interactions/shared/types.d.ts.map +1 -0
- package/dist/interactions/shared/types.js +7 -0
- package/dist/interactions/slider/extractor.d.ts +24 -0
- package/dist/interactions/slider/extractor.d.ts.map +1 -0
- package/dist/interactions/slider/extractor.js +73 -0
- package/dist/interactions/slider/index.d.ts +3 -0
- package/dist/interactions/slider/index.d.ts.map +1 -0
- package/dist/interactions/slider/index.js +1 -0
- package/dist/interactions/slider/types.d.ts +2 -0
- package/dist/interactions/slider/types.d.ts.map +1 -0
- package/dist/interactions/slider/types.js +1 -0
- package/dist/interactions/text-entry/extractor.d.ts +21 -0
- package/dist/interactions/text-entry/extractor.d.ts.map +1 -0
- package/dist/interactions/text-entry/extractor.js +54 -0
- package/dist/interactions/text-entry/index.d.ts +3 -0
- package/dist/interactions/text-entry/index.d.ts.map +1 -0
- package/dist/interactions/text-entry/index.js +1 -0
- package/dist/interactions/text-entry/types.d.ts +2 -0
- package/dist/interactions/text-entry/types.d.ts.map +1 -0
- package/dist/interactions/text-entry/types.js +1 -0
- package/dist/interactions/upload/extractor.d.ts +20 -0
- package/dist/interactions/upload/extractor.d.ts.map +1 -0
- package/dist/interactions/upload/extractor.js +59 -0
- package/dist/interactions/upload/index.d.ts +3 -0
- package/dist/interactions/upload/index.d.ts.map +1 -0
- package/dist/interactions/upload/index.js +1 -0
- package/dist/interactions/upload/types.d.ts +2 -0
- package/dist/interactions/upload/types.d.ts.map +1 -0
- package/dist/interactions/upload/types.js +1 -0
- package/dist/pnp/applyPnp.d.ts.map +1 -1
- package/dist/pnp/applyPnp.js +9 -2
- package/dist/pnp/parsePnpXml.d.ts.map +1 -1
- package/dist/pnp/parsePnpXml.js +91 -3
- package/dist/pnp/types.d.ts +24 -1
- package/dist/pnp/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +47 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interactions.d.ts +4 -408
- package/dist/types/interactions.d.ts.map +1 -1
- package/dist/types/interactions.js +3 -3
- package/dist/web-components/QTIInteractionBase.d.ts +5 -5
- package/dist/web-components/QTIInteractionBase.d.ts.map +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +11 -8
- package/dist/web-components/QTIInteractionElement.d.ts.map +1 -1
- package/dist/web-components/index.d.ts +1 -1
- package/dist/web-components/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/catalog/applyGlossaryTriggers.ts +174 -34
- package/src/catalog/glossaryAction.ts +14 -4
- package/src/components/ItemBody.svelte +71 -200
- package/src/components/ItemPlayer.svelte +9 -5
- package/src/components/ModalFeedbackDisplay.svelte +15 -5
- package/src/components/utils/stimulusRender.ts +93 -0
- package/src/components/utils/stylesheetRender.ts +58 -0
- package/src/core/ComponentRegistry.ts +22 -7
- package/src/core/Player.ts +401 -209
- package/src/document/AssessmentItemDocument.ts +178 -0
- package/src/extraction/extractors/associateExtractor.ts +1 -133
- package/src/extraction/extractors/choiceExtractor.ts +1 -121
- package/src/extraction/extractors/customExtractor.ts +1 -72
- package/src/extraction/extractors/drawingExtractor.ts +1 -113
- package/src/extraction/extractors/endAttemptExtractor.ts +1 -74
- package/src/extraction/extractors/extendedTextExtractor.ts +1 -89
- package/src/extraction/extractors/gapMatchExtractor.ts +1 -193
- package/src/extraction/extractors/graphicAssociateExtractor.ts +1 -192
- package/src/extraction/extractors/graphicGapMatchExtractor.ts +1 -257
- package/src/extraction/extractors/graphicOrderExtractor.ts +1 -162
- package/src/extraction/extractors/hotspotExtractor.ts +1 -208
- package/src/extraction/extractors/hottextExtractor.ts +1 -163
- package/src/extraction/extractors/index.ts +5 -111
- package/src/extraction/extractors/inlineChoiceExtractor.ts +1 -105
- package/src/extraction/extractors/matchExtractor.ts +1 -187
- package/src/extraction/extractors/mediaExtractor.ts +1 -168
- package/src/extraction/extractors/orderExtractor.ts +1 -120
- package/src/extraction/extractors/portableCustomExtractor.ts +1 -122
- package/src/extraction/extractors/positionObjectExtractor.ts +1 -243
- package/src/extraction/extractors/selectPointExtractor.ts +1 -143
- package/src/extraction/extractors/sliderExtractor.ts +1 -102
- package/src/extraction/extractors/textEntryExtractor.ts +1 -79
- package/src/extraction/extractors/uploadExtractor.ts +1 -81
- package/src/extraction/index.ts +1 -2
- package/src/extraction/interactionExtractionPipeline.ts +70 -0
- package/src/extraction/interactionSecurity.ts +60 -0
- package/src/index.ts +3 -7
- package/src/interactions/associate/extractor.ts +133 -0
- package/src/interactions/associate/index.ts +2 -0
- package/src/interactions/associate/types.ts +1 -0
- package/src/interactions/choice/extractor.ts +121 -0
- package/src/interactions/choice/index.ts +2 -0
- package/src/interactions/choice/types.ts +1 -0
- package/src/interactions/custom/extractor.ts +72 -0
- package/src/interactions/custom/index.ts +2 -0
- package/src/interactions/custom/types.ts +1 -0
- package/src/interactions/drawing/extractor.ts +113 -0
- package/src/interactions/drawing/index.ts +2 -0
- package/src/interactions/drawing/types.ts +1 -0
- package/src/interactions/end-attempt/extractor.ts +74 -0
- package/src/interactions/end-attempt/index.ts +2 -0
- package/src/interactions/end-attempt/types.ts +1 -0
- package/src/interactions/extended-text/extractor.ts +89 -0
- package/src/interactions/extended-text/index.ts +2 -0
- package/src/interactions/extended-text/types.ts +1 -0
- package/src/interactions/gap-match/extractor.ts +193 -0
- package/src/interactions/gap-match/index.ts +2 -0
- package/src/interactions/gap-match/types.ts +1 -0
- package/src/interactions/graphic-associate/extractor.ts +192 -0
- package/src/interactions/graphic-associate/index.ts +2 -0
- package/src/interactions/graphic-associate/types.ts +1 -0
- package/src/interactions/graphic-gap-match/extractor.ts +257 -0
- package/src/interactions/graphic-gap-match/index.ts +2 -0
- package/src/interactions/graphic-gap-match/types.ts +1 -0
- package/src/interactions/graphic-order/extractor.ts +162 -0
- package/src/interactions/graphic-order/index.ts +2 -0
- package/src/interactions/graphic-order/types.ts +1 -0
- package/src/interactions/hotspot/extractor.ts +208 -0
- package/src/interactions/hotspot/index.ts +2 -0
- package/src/interactions/hotspot/types.ts +1 -0
- package/src/interactions/hottext/extractor.ts +163 -0
- package/src/interactions/hottext/index.ts +2 -0
- package/src/interactions/hottext/types.ts +1 -0
- package/src/interactions/index.ts +52 -0
- package/src/interactions/inline/index.ts +1 -0
- package/src/interactions/inline/render-plan.ts +105 -0
- package/src/interactions/inline-choice/InlineChoice.svelte +57 -0
- package/src/interactions/inline-choice/extractor.ts +105 -0
- package/src/interactions/inline-choice/index.ts +2 -0
- package/src/interactions/inline-choice/types.ts +1 -0
- package/src/interactions/match/extractor.ts +187 -0
- package/src/interactions/match/index.ts +2 -0
- package/src/interactions/match/types.ts +1 -0
- package/src/interactions/media/extractor.ts +168 -0
- package/src/interactions/media/index.ts +2 -0
- package/src/interactions/media/types.ts +1 -0
- package/src/interactions/modules.ts +111 -0
- package/src/interactions/order/extractor.ts +120 -0
- package/src/interactions/order/index.ts +2 -0
- package/src/interactions/order/types.ts +1 -0
- package/src/interactions/portable-custom/extractor.ts +122 -0
- package/src/interactions/portable-custom/index.ts +2 -0
- package/src/interactions/portable-custom/types.ts +1 -0
- package/src/interactions/position-object/extractor.ts +243 -0
- package/src/interactions/position-object/index.ts +2 -0
- package/src/interactions/position-object/types.ts +1 -0
- package/src/interactions/select-point/extractor.ts +143 -0
- package/src/interactions/select-point/index.ts +2 -0
- package/src/interactions/select-point/types.ts +1 -0
- package/src/interactions/shared/index.ts +1 -0
- package/src/interactions/shared/types.ts +429 -0
- package/src/interactions/slider/extractor.ts +102 -0
- package/src/interactions/slider/index.ts +2 -0
- package/src/interactions/slider/types.ts +1 -0
- package/src/interactions/text-entry/InlineTextEntry.svelte +75 -0
- package/src/interactions/text-entry/extractor.ts +79 -0
- package/src/interactions/text-entry/index.ts +2 -0
- package/src/interactions/text-entry/types.ts +1 -0
- package/src/interactions/upload/extractor.ts +81 -0
- package/src/interactions/upload/index.ts +2 -0
- package/src/interactions/upload/types.ts +1 -0
- package/src/pnp/applyPnp.ts +8 -2
- package/src/pnp/parsePnpXml.ts +102 -5
- package/src/pnp/types.ts +43 -1
- package/src/types/index.ts +53 -0
- package/src/types/interactions.ts +4 -425
- package/src/web-components/QTIInteractionBase.ts +6 -5
- package/src/web-components/QTIInteractionElement.ts +15 -8
- package/src/web-components/index.ts +1 -0
- package/src/__tests__/glossaryTriggers.test.ts +0 -411
- package/src/__tests__/pnp.test.ts +0 -250
- package/src/core/ItemRenderer.ts +0 -371
package/src/core/Player.ts
CHANGED
|
@@ -12,22 +12,20 @@ import {
|
|
|
12
12
|
type DeclarationMap,
|
|
13
13
|
evalExpr,
|
|
14
14
|
execProgram,
|
|
15
|
-
findAssessmentItem,
|
|
16
15
|
findDescendants,
|
|
17
16
|
findFirstDescendant,
|
|
18
17
|
getAttr,
|
|
19
18
|
OperatorRegistry,
|
|
20
19
|
type ProcessingProgram,
|
|
21
|
-
parseXml,
|
|
22
20
|
type QtiValue,
|
|
23
21
|
qtiNull,
|
|
24
22
|
qtiValue,
|
|
25
|
-
serializeXml,
|
|
26
23
|
toBoolean,
|
|
27
24
|
toNumber,
|
|
28
25
|
toStringValue,
|
|
29
26
|
} from '@pie-qti/qti-processing';
|
|
30
27
|
import type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';
|
|
28
|
+
import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
|
|
31
29
|
import {
|
|
32
30
|
Qti2xElementNameMapper,
|
|
33
31
|
Qti2xAttributeNameMapper,
|
|
@@ -35,15 +33,18 @@ import {
|
|
|
35
33
|
Qti3AttributeNameMapper,
|
|
36
34
|
detectQtiVersion,
|
|
37
35
|
} from '@pie-qti/qti-common';
|
|
38
|
-
import {
|
|
36
|
+
import type { AssessmentItemDocument } from '../document/AssessmentItemDocument.js';
|
|
37
|
+
import { parseAssessmentItemDocument } from '../document/AssessmentItemDocument.js';
|
|
39
38
|
import type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
40
39
|
import { createExtractionRegistry } from '../extraction/ExtractionRegistry.js';
|
|
41
|
-
import {
|
|
42
|
-
import
|
|
40
|
+
import { extractInteractionData } from '../extraction/interactionExtractionPipeline.js';
|
|
41
|
+
import { getStandardInteractionExtractors } from '../interactions/modules.js';
|
|
43
42
|
import type {
|
|
44
43
|
AdaptiveAttemptResult,
|
|
45
44
|
CompletionStatus,
|
|
46
45
|
HtmlContent,
|
|
46
|
+
ItemLifecycleStatus,
|
|
47
|
+
ItemSessionActionResult,
|
|
47
48
|
ItemSessionState,
|
|
48
49
|
ModalFeedback,
|
|
49
50
|
PlayerConfig,
|
|
@@ -51,12 +52,13 @@ import type {
|
|
|
51
52
|
QTIRole,
|
|
52
53
|
RubricBlock,
|
|
53
54
|
ScoringResult,
|
|
55
|
+
SerializedItemSessionState,
|
|
56
|
+
SerializedItemSessionVariable,
|
|
54
57
|
} from '../types/index.js';
|
|
55
|
-
import type { InteractionData
|
|
58
|
+
import type { InteractionData } from '../types/interactions.js';
|
|
56
59
|
import type { ResponseValidationResult } from '../types/responseValidation.js';
|
|
57
60
|
import type { ComponentRegistry } from './ComponentRegistry.js';
|
|
58
61
|
import { createComponentRegistry } from './ComponentRegistry.js';
|
|
59
|
-
import { enforceItemXmlLimits } from './parsingLimits.js';
|
|
60
62
|
import { createSeededRng } from './random.js';
|
|
61
63
|
import { sanitizeHtml } from './sanitizer.js';
|
|
62
64
|
import { toTrustedHtml } from './trustedTypes.js';
|
|
@@ -64,7 +66,7 @@ import { sanitizeResourceUrl } from './urlPolicy.js';
|
|
|
64
66
|
import type { PnpProfile } from '../pnp/types.js';
|
|
65
67
|
import { applyPnpToRoot } from '../pnp/applyPnp.js';
|
|
66
68
|
import type { CatalogIndex } from '../catalog/types.js';
|
|
67
|
-
import { extractCatalogFromItemXml, mergeCatalogs } from '../catalog/catalogExtractor.js';
|
|
69
|
+
import { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from '../catalog/catalogExtractor.js';
|
|
68
70
|
import { getCatalogEntry } from '../catalog/catalogLookup.js';
|
|
69
71
|
import { PciHost } from '../pci/PciHost.js';
|
|
70
72
|
import type { ExtractedPci } from '../pci/types.js';
|
|
@@ -75,7 +77,7 @@ export class Player {
|
|
|
75
77
|
private role: QTIRole;
|
|
76
78
|
private config: PlayerConfig;
|
|
77
79
|
private itemXml: string;
|
|
78
|
-
private
|
|
80
|
+
private itemDocument: AssessmentItemDocument;
|
|
79
81
|
private assessmentItem: Element;
|
|
80
82
|
private decls: DeclarationMap;
|
|
81
83
|
private ctx: DeclarationContext;
|
|
@@ -92,12 +94,20 @@ export class Player {
|
|
|
92
94
|
private _pnp: PnpProfile | undefined;
|
|
93
95
|
private _rootEl: HTMLElement | undefined;
|
|
94
96
|
private _catalogIndex: CatalogIndex = new Map();
|
|
97
|
+
private _stimulusCatalogIndexes: Map<string, CatalogIndex> = new Map();
|
|
95
98
|
private _pciHosts: Map<string, PciHost> = new Map();
|
|
99
|
+
private _pnpChangeListeners = new Set<(pnp: PnpProfile | undefined) => void>();
|
|
100
|
+
private sessionGuid: string;
|
|
101
|
+
private lifecycleStatus: ItemLifecycleStatus = 'initial';
|
|
102
|
+
private sessionStartedAt: number;
|
|
103
|
+
private accumulatedDurationMs = 0;
|
|
96
104
|
|
|
97
105
|
constructor(config: PlayerConfig) {
|
|
98
106
|
this.config = config;
|
|
99
107
|
this.itemXml = config.itemXml ?? '';
|
|
100
108
|
this.role = config.role ?? 'candidate';
|
|
109
|
+
this.sessionGuid = createSessionGuid();
|
|
110
|
+
this.sessionStartedAt = Date.now();
|
|
101
111
|
this.rng = config.rng ?? (typeof config.seed === 'number' ? createSeededRng(config.seed) : Math.random);
|
|
102
112
|
|
|
103
113
|
// Auto-detect QTI version and create appropriate mappers if not provided
|
|
@@ -120,15 +130,23 @@ export class Player {
|
|
|
120
130
|
}
|
|
121
131
|
} else {
|
|
122
132
|
this.mapper = config.elementNameMapper as ElementNameMapper;
|
|
133
|
+
if (!config.attributeNameMapper) {
|
|
134
|
+
(config as any).attributeNameMapper =
|
|
135
|
+
this.mapper.version === '3.0'
|
|
136
|
+
? new Qti3AttributeNameMapper()
|
|
137
|
+
: new Qti2xAttributeNameMapper();
|
|
138
|
+
}
|
|
123
139
|
}
|
|
124
140
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
this.itemDocument = parseAssessmentItemDocument({
|
|
142
|
+
itemXml: this.itemXml,
|
|
143
|
+
elementNameMapper: this.mapper,
|
|
144
|
+
attributeNameMapper: config.attributeNameMapper as AttributeNameMapper,
|
|
145
|
+
security: this.config.security,
|
|
146
|
+
});
|
|
147
|
+
this.assessmentItem = this.itemDocument.getAssessmentItem();
|
|
130
148
|
|
|
131
|
-
this.decls = this.buildDeclarations(
|
|
149
|
+
this.decls = this.buildDeclarations();
|
|
132
150
|
this.ensureBuiltinDeclarations(this.decls);
|
|
133
151
|
this.ctx = new DeclarationContext(this.decls);
|
|
134
152
|
this.ops = new OperatorRegistry();
|
|
@@ -146,8 +164,8 @@ export class Player {
|
|
|
146
164
|
// I18n provider (defaults to a simple fallback if not provided)
|
|
147
165
|
this.i18nProvider = config.i18nProvider ?? this.createDefaultI18nProvider();
|
|
148
166
|
|
|
149
|
-
// Register standard extractors (idempotent per-registry instance)
|
|
150
|
-
for (const ex of
|
|
167
|
+
// Register standard interaction extractors (idempotent per-registry instance)
|
|
168
|
+
for (const ex of getStandardInteractionExtractors()) {
|
|
151
169
|
try {
|
|
152
170
|
this.extractionRegistry.register(ex as any);
|
|
153
171
|
} catch {
|
|
@@ -166,7 +184,7 @@ export class Player {
|
|
|
166
184
|
}
|
|
167
185
|
|
|
168
186
|
// Build ASTs once.
|
|
169
|
-
const templateProcessing =
|
|
187
|
+
const templateProcessing = this.itemDocument.getProcessingElement('template');
|
|
170
188
|
if (templateProcessing) {
|
|
171
189
|
this.templateProcessingProgram = buildTemplateProcessingAst(templateProcessing, {
|
|
172
190
|
elementNameMapper: this.mapper,
|
|
@@ -174,14 +192,14 @@ export class Player {
|
|
|
174
192
|
this.execTemplateProcessing();
|
|
175
193
|
}
|
|
176
194
|
|
|
177
|
-
const responseProcessing =
|
|
195
|
+
const responseProcessing = this.itemDocument.getProcessingElement('response');
|
|
178
196
|
if (responseProcessing) {
|
|
179
197
|
this.responseProcessingProgram = buildResponseProcessingAst(responseProcessing, {
|
|
180
198
|
elementNameMapper: this.mapper,
|
|
181
199
|
});
|
|
182
200
|
}
|
|
183
201
|
|
|
184
|
-
const outcomeProcessing =
|
|
202
|
+
const outcomeProcessing = this.itemDocument.getProcessingElement('outcome');
|
|
185
203
|
if (outcomeProcessing) {
|
|
186
204
|
this.outcomeProcessingProgram = buildOutcomeProcessingAst(outcomeProcessing, {
|
|
187
205
|
elementNameMapper: this.mapper,
|
|
@@ -210,15 +228,23 @@ export class Player {
|
|
|
210
228
|
// Store PNP profile for later use (applyPnpToRoot is called once a root element is available).
|
|
211
229
|
this._pnp = config.pnp;
|
|
212
230
|
|
|
213
|
-
// Build catalog index from
|
|
214
|
-
|
|
231
|
+
// Build catalog index from resolved delivery context, legacy shared catalog XML, and item XML.
|
|
232
|
+
// Item/global entries are merged first; item-level entries win on global collisions.
|
|
233
|
+
// Stimulus entries are kept separately so rendered stimulus terms can avoid ID collisions.
|
|
234
|
+
let mergedCatalog: CatalogIndex = new Map();
|
|
235
|
+
for (const source of config.deliveryContext?.catalogSources ?? []) {
|
|
236
|
+
const sourceCatalog = extractCatalog(source.xml);
|
|
237
|
+
if (source.scope === 'stimulus' && source.stimulusIdentifier) {
|
|
238
|
+
const existing = this._stimulusCatalogIndexes.get(source.stimulusIdentifier) ?? new Map();
|
|
239
|
+
this._stimulusCatalogIndexes.set(source.stimulusIdentifier, mergeCatalogs(existing, sourceCatalog));
|
|
240
|
+
} else {
|
|
241
|
+
mergedCatalog = mergeCatalogs(mergedCatalog, sourceCatalog);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
215
244
|
if (config.catalogXml) {
|
|
216
|
-
|
|
217
|
-
// Item-level wins on collision: merge shared first, then override with item entries.
|
|
218
|
-
this._catalogIndex = mergeCatalogs(sharedCatalog, itemCatalog);
|
|
219
|
-
} else {
|
|
220
|
-
this._catalogIndex = itemCatalog;
|
|
245
|
+
mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(config.catalogXml));
|
|
221
246
|
}
|
|
247
|
+
this._catalogIndex = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(this.itemXml));
|
|
222
248
|
|
|
223
249
|
// Check strict compliance if enabled
|
|
224
250
|
if (this.config.strictQtiCompliance?.enabled) {
|
|
@@ -245,6 +271,9 @@ export class Player {
|
|
|
245
271
|
if (this._rootEl) {
|
|
246
272
|
applyPnpToRoot(this._rootEl, this._pnp);
|
|
247
273
|
}
|
|
274
|
+
for (const listener of this._pnpChangeListeners) {
|
|
275
|
+
listener(this._pnp);
|
|
276
|
+
}
|
|
248
277
|
}
|
|
249
278
|
|
|
250
279
|
/** Return the current resolved PNP profile. */
|
|
@@ -252,19 +281,47 @@ export class Player {
|
|
|
252
281
|
return this._pnp;
|
|
253
282
|
}
|
|
254
283
|
|
|
284
|
+
public onPnpChange(listener: (pnp: PnpProfile | undefined) => void): () => void {
|
|
285
|
+
this._pnpChangeListeners.add(listener);
|
|
286
|
+
return () => this._pnpChangeListeners.delete(listener);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Return the package/assessment-resolved delivery context, if one was supplied. */
|
|
290
|
+
public getDeliveryContext(): ResolvedItemDeliveryContext | undefined {
|
|
291
|
+
return this.config.deliveryContext;
|
|
292
|
+
}
|
|
293
|
+
|
|
255
294
|
/**
|
|
256
295
|
* Look up a catalog entry by card identifier, usage type, and optional language.
|
|
257
296
|
* Returns the HTML string for the matched entry, or null if not found.
|
|
258
297
|
*
|
|
259
298
|
* Language fallback: exact match → prefix match → no-lang entry → null.
|
|
260
299
|
*/
|
|
261
|
-
public getCatalogEntry(
|
|
262
|
-
|
|
300
|
+
public getCatalogEntry(
|
|
301
|
+
idref: string,
|
|
302
|
+
usage: string,
|
|
303
|
+
lang?: string,
|
|
304
|
+
options?: { stimulusIdentifier?: string }
|
|
305
|
+
): string | null {
|
|
306
|
+
const stimulusHtml = options?.stimulusIdentifier
|
|
307
|
+
? getCatalogEntry(this._stimulusCatalogIndexes.get(options.stimulusIdentifier) ?? new Map(), idref, usage, lang)
|
|
308
|
+
: null;
|
|
309
|
+
const html = stimulusHtml ?? getCatalogEntry(this._catalogIndex, idref, usage, lang);
|
|
310
|
+
if (html === null) return null;
|
|
311
|
+
if (looksLikeCatalogUrl(html)) {
|
|
312
|
+
return sanitizeResourceUrl(html.trim(), this.config.security?.urlPolicy, 'img');
|
|
313
|
+
}
|
|
314
|
+
return this.sanitizeHtmlContent(html);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Sanitize externally resolved item-adjacent HTML before it reaches a rendering sink. */
|
|
318
|
+
public sanitizeHtmlContent(html: string): string {
|
|
319
|
+
return sanitizeHtml(html, { security: this.config.security });
|
|
263
320
|
}
|
|
264
321
|
|
|
265
322
|
/**
|
|
266
323
|
* Create a PciHost for an extracted PCI and register it for response tracking.
|
|
267
|
-
* The caller
|
|
324
|
+
* The caller is responsible for calling host.load() and
|
|
268
325
|
* host.initialize(domNode) once the DOM element is available.
|
|
269
326
|
*/
|
|
270
327
|
public createPciHost(data: ExtractedPci): PciHost {
|
|
@@ -336,50 +393,121 @@ export class Player {
|
|
|
336
393
|
}
|
|
337
394
|
|
|
338
395
|
public processResponses(): ScoringResult {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
this.resetOutcomesToDefault();
|
|
396
|
+
return this.runResponseProcessing({ finalizeNonAdaptiveAttempt: true });
|
|
397
|
+
}
|
|
342
398
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
// Otherwise, fall back to template-based processing (responseProcessing@template).
|
|
348
|
-
const hasStatements = childElements(rpEl).length > 0;
|
|
349
|
-
if (hasStatements) {
|
|
350
|
-
this.execResponseProcessingProgram();
|
|
351
|
-
} else {
|
|
352
|
-
const templateUrl = getAttr(rpEl, 'template');
|
|
353
|
-
if (templateUrl) this.execResponseProcessingTemplate(templateUrl);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
399
|
+
public saveItemSession(): SerializedItemSessionState {
|
|
400
|
+
this.freezeDuration();
|
|
401
|
+
return this.serializeItemSession();
|
|
402
|
+
}
|
|
356
403
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
this.
|
|
404
|
+
public restoreItemSession(state: SerializedItemSessionState): void {
|
|
405
|
+
this.sessionGuid = state.sessionGuid;
|
|
406
|
+
this.lifecycleStatus = state.lifecycleStatus;
|
|
407
|
+
this.accumulatedDurationMs = Math.max(0, Number(state.duration) || 0);
|
|
408
|
+
this.sessionStartedAt = Date.now();
|
|
409
|
+
this.applySerializedVariables(state.responseVariables);
|
|
410
|
+
this.applySerializedVariables(state.outcomeVariables);
|
|
411
|
+
this.applySerializedVariables(state.templateVariables);
|
|
412
|
+
this.applySerializedVariables(state.contextVariables);
|
|
413
|
+
this.updateDuration();
|
|
414
|
+
}
|
|
360
415
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
416
|
+
public suspendAttempt(): ItemSessionActionResult {
|
|
417
|
+
const validation = this.validateResponses(this.getResponses());
|
|
418
|
+
this.lifecycleStatus = 'suspended';
|
|
419
|
+
const sessionState = this.saveItemSession();
|
|
420
|
+
|
|
421
|
+
return {
|
|
422
|
+
action: 'suspendAttempt',
|
|
423
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
424
|
+
completionStatus: this.getCompletionStatus(),
|
|
425
|
+
numAttempts: this.getNumAttempts(),
|
|
426
|
+
duration: sessionState.duration,
|
|
427
|
+
completed: this.isCompleted(),
|
|
428
|
+
sessionState,
|
|
429
|
+
validation,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
public endAttempt(options: { countAttempt?: boolean; validateResponses?: boolean } = {}): ItemSessionActionResult {
|
|
434
|
+
const validate = options.validateResponses ?? false;
|
|
435
|
+
const validation = validate ? this.validateResponses(this.getResponses()) : undefined;
|
|
436
|
+
if (validation && !validation.valid) {
|
|
437
|
+
const sessionState = this.saveItemSession();
|
|
438
|
+
return {
|
|
439
|
+
action: 'endAttempt',
|
|
440
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
441
|
+
completionStatus: this.getCompletionStatus(),
|
|
442
|
+
numAttempts: this.getNumAttempts(),
|
|
443
|
+
duration: sessionState.duration,
|
|
444
|
+
completed: this.isCompleted(),
|
|
445
|
+
sessionState,
|
|
446
|
+
validation,
|
|
447
|
+
};
|
|
368
448
|
}
|
|
369
449
|
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
450
|
+
const scoring = this.isAdaptive()
|
|
451
|
+
? this.submitAttempt(options.countAttempt ?? true)
|
|
452
|
+
: this.runResponseProcessing({
|
|
453
|
+
finalizeNonAdaptiveAttempt: true,
|
|
454
|
+
countAttempt: options.countAttempt ?? true,
|
|
455
|
+
});
|
|
456
|
+
this.lifecycleStatus = scoring.completed ? 'closed' : 'interacting';
|
|
457
|
+
const sessionState = this.saveItemSession();
|
|
376
458
|
|
|
377
459
|
return {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
460
|
+
action: 'endAttempt',
|
|
461
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
462
|
+
completionStatus: this.getCompletionStatus(),
|
|
463
|
+
numAttempts: this.getNumAttempts(),
|
|
464
|
+
duration: sessionState.duration,
|
|
465
|
+
completed: scoring.completed,
|
|
466
|
+
sessionState,
|
|
467
|
+
validation,
|
|
468
|
+
scoring,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
public scoreAttempt(): ItemSessionActionResult {
|
|
473
|
+
const scoring = this.runResponseProcessing({ finalizeNonAdaptiveAttempt: false });
|
|
474
|
+
const sessionState = this.saveItemSession();
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
action: 'scoreAttempt',
|
|
478
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
479
|
+
completionStatus: this.getCompletionStatus(),
|
|
480
|
+
numAttempts: this.getNumAttempts(),
|
|
481
|
+
duration: sessionState.duration,
|
|
482
|
+
completed: scoring.completed,
|
|
483
|
+
sessionState,
|
|
484
|
+
scoring,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
public newTemplate(options: { resetResponses?: boolean } = {}): ItemSessionActionResult {
|
|
489
|
+
this.resetOutcomesToDefault();
|
|
490
|
+
if (options.resetResponses ?? true) {
|
|
491
|
+
this.resetResponsesToDefault();
|
|
492
|
+
}
|
|
493
|
+
this.resetTemplatesToDefault();
|
|
494
|
+
this.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'not_attempted'));
|
|
495
|
+
this.ctx.setValue('numAttempts', qtiValue('integer', 'single', 0));
|
|
496
|
+
this.execTemplateProcessing();
|
|
497
|
+
this.lifecycleStatus = 'initial';
|
|
498
|
+
this.accumulatedDurationMs = 0;
|
|
499
|
+
this.sessionStartedAt = Date.now();
|
|
500
|
+
this.updateDuration();
|
|
501
|
+
const sessionState = this.serializeItemSession();
|
|
502
|
+
|
|
503
|
+
return {
|
|
504
|
+
action: 'newTemplate',
|
|
505
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
506
|
+
completionStatus: this.getCompletionStatus(),
|
|
507
|
+
numAttempts: this.getNumAttempts(),
|
|
508
|
+
duration: sessionState.duration,
|
|
509
|
+
completed: this.isCompleted(),
|
|
510
|
+
sessionState,
|
|
383
511
|
};
|
|
384
512
|
}
|
|
385
513
|
|
|
@@ -486,17 +614,82 @@ export class Player {
|
|
|
486
614
|
if ((d as any).__kind !== 'outcome') continue;
|
|
487
615
|
// Built-in stateful variables must survive across processing runs.
|
|
488
616
|
// They are updated by the runtime (adaptive attempt tracking), not by outcome defaults.
|
|
489
|
-
if (d.identifier === 'numAttempts' || d.identifier === 'completionStatus') continue;
|
|
617
|
+
if (d.identifier === 'numAttempts' || d.identifier === 'completionStatus' || d.identifier === 'duration') continue;
|
|
618
|
+
this.ctx.resetToDefault(d.identifier);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private resetResponsesToDefault(): void {
|
|
623
|
+
for (const d of Object.values(this.decls)) {
|
|
624
|
+
if ((d as any).__kind !== 'response') continue;
|
|
625
|
+
this.ctx.resetToDefault(d.identifier);
|
|
626
|
+
this.setPciResponse(d.identifier, d.value.kind === 'value' ? d.value.value : null);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
private resetTemplatesToDefault(): void {
|
|
631
|
+
for (const d of Object.values(this.decls)) {
|
|
632
|
+
if (!d.isTemplate) continue;
|
|
490
633
|
this.ctx.resetToDefault(d.identifier);
|
|
491
634
|
}
|
|
492
635
|
}
|
|
493
636
|
|
|
637
|
+
private runResponseProcessing(options: {
|
|
638
|
+
finalizeNonAdaptiveAttempt: boolean;
|
|
639
|
+
countAttempt?: boolean;
|
|
640
|
+
}): ScoringResult {
|
|
641
|
+
this.updateDuration();
|
|
642
|
+
// Spec-aligned behavior: each processing run starts from outcome defaults.
|
|
643
|
+
// This prevents stale outcomes when response/outcome processing doesn't set every variable.
|
|
644
|
+
this.resetOutcomesToDefault();
|
|
645
|
+
|
|
646
|
+
// Execute response processing if present
|
|
647
|
+
const rpEl = this.itemDocument.getProcessingElement('response');
|
|
648
|
+
if (rpEl) {
|
|
649
|
+
// If responseProcessing has explicit statements, run the compiled program.
|
|
650
|
+
// Otherwise, fall back to template-based processing (responseProcessing@template).
|
|
651
|
+
const hasStatements = childElements(rpEl).length > 0;
|
|
652
|
+
if (hasStatements) {
|
|
653
|
+
this.execResponseProcessingProgram();
|
|
654
|
+
} else {
|
|
655
|
+
const templateUrl = getAttr(rpEl, 'template');
|
|
656
|
+
if (templateUrl) this.execResponseProcessingTemplate(templateUrl);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Execute outcome processing if present (runs after responseProcessing)
|
|
661
|
+
this.execOutcomeProcessingProgram();
|
|
662
|
+
|
|
663
|
+
// Compatibility: processResponses() has historically finalized non-adaptive items.
|
|
664
|
+
// New scoreAttempt() uses this same engine with finalization disabled.
|
|
665
|
+
if (!this.isAdaptive() && options.finalizeNonAdaptiveAttempt) {
|
|
666
|
+
this.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'completed'));
|
|
667
|
+
if (options.countAttempt ?? true) {
|
|
668
|
+
const currentAttempts = this.getNumAttempts();
|
|
669
|
+
this.ctx.setValue('numAttempts', qtiValue('integer', 'single', currentAttempts + 1));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const outcomes = this.collectOutcomes();
|
|
674
|
+
|
|
675
|
+
const score = Number(outcomes.SCORE ?? 0);
|
|
676
|
+
const maxScore = Number(outcomes.MAXSCORE ?? 1);
|
|
677
|
+
const completionStatus = (outcomes.completionStatus as CompletionStatus | undefined) ?? 'not_attempted';
|
|
678
|
+
const completed = completionStatus === 'completed' || (!this.isAdaptive() && options.finalizeNonAdaptiveAttempt);
|
|
679
|
+
|
|
680
|
+
return {
|
|
681
|
+
score,
|
|
682
|
+
maxScore,
|
|
683
|
+
completed,
|
|
684
|
+
outcomeValues: outcomes,
|
|
685
|
+
modalFeedback: this.getModalFeedback(outcomes),
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
494
689
|
public getItemBodyHtml(): HtmlContent {
|
|
495
|
-
const
|
|
496
|
-
if (!
|
|
690
|
+
const inner = this.itemDocument.serializeItemBodyChildren();
|
|
691
|
+
if (!inner) return '';
|
|
497
692
|
|
|
498
|
-
// Serialize children rather than the container tag itself.
|
|
499
|
-
const inner = childElements(itemBody).map((c) => serializeXml(c)).join('');
|
|
500
693
|
const printed = this.renderPrintedVariables(inner);
|
|
501
694
|
const sanitized = sanitizeHtml(printed, { security: this.config.security });
|
|
502
695
|
return toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
|
|
@@ -510,7 +703,7 @@ export class Player {
|
|
|
510
703
|
*/
|
|
511
704
|
public getRubrics(): RubricBlock[] {
|
|
512
705
|
const role = this.role;
|
|
513
|
-
const rubricEls =
|
|
706
|
+
const rubricEls = this.itemDocument.findRubricElements();
|
|
514
707
|
if (rubricEls.length === 0) return [];
|
|
515
708
|
|
|
516
709
|
const blocks: RubricBlock[] = [];
|
|
@@ -521,8 +714,7 @@ export class Player {
|
|
|
521
714
|
// If view is specified, show only when it includes the current role.
|
|
522
715
|
if (view.length > 0 && role && !view.includes(role)) continue;
|
|
523
716
|
|
|
524
|
-
|
|
525
|
-
const contentRaw = childElements(el).map((c) => serializeXml(c)).join('') || (el.textContent || '');
|
|
717
|
+
const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
|
|
526
718
|
const printed = this.renderPrintedVariables(contentRaw);
|
|
527
719
|
const sanitized = sanitizeHtml(printed, { security: this.config.security });
|
|
528
720
|
const html = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
|
|
@@ -545,128 +737,12 @@ export class Player {
|
|
|
545
737
|
* Canonical interaction API (new): extracted, typed interaction data.
|
|
546
738
|
*/
|
|
547
739
|
public getInteractionData(): InteractionData[] {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const docRoot = parse(this.itemXml, { lowerCaseTagName: false, comment: false }) as any as QTIElement;
|
|
555
|
-
// node-html-parser's CSS selectors match lowercase tag names.
|
|
556
|
-
// Search for itemBody in the native form for this QTI version (itembody for 2.x, qti-item-body for 3.0)
|
|
557
|
-
const itemBodyTag = this.mapper.toNative('itembody').toLowerCase();
|
|
558
|
-
const parsedItemBody = (docRoot.querySelector?.(itemBodyTag) as any as QTIElement | null) ?? null;
|
|
559
|
-
const root = parsedItemBody ?? docRoot;
|
|
560
|
-
|
|
561
|
-
const declMap = new Map<string, ExtractionVariableDeclaration>();
|
|
562
|
-
for (const d of Object.values(this.decls)) {
|
|
563
|
-
declMap.set(d.identifier, {
|
|
564
|
-
identifier: d.identifier,
|
|
565
|
-
cardinality: d.cardinality as any,
|
|
566
|
-
baseType: d.baseType,
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Discover all elements that match any standard extractor elementType.
|
|
571
|
-
// Extractors specify element types in QTI 2.x form (e.g., 'choiceInteraction').
|
|
572
|
-
// We use the mapper to convert to the appropriate form for this QTI version
|
|
573
|
-
// (e.g., 'choiceInteraction' for QTI 2.x, 'qti-choice-interaction' for QTI 3.0).
|
|
574
|
-
const tagSet = new Set<string>();
|
|
575
|
-
for (const ex of ALL_STANDARD_EXTRACTORS) {
|
|
576
|
-
for (const t of ex.elementTypes ?? []) {
|
|
577
|
-
// Convert to canonical form (lowercase), then to native form using mapper
|
|
578
|
-
const canonical = t.toLowerCase();
|
|
579
|
-
const native = this.mapper.toNative(canonical);
|
|
580
|
-
tagSet.add(native.toLowerCase());
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
const elements: QTIElement[] = [];
|
|
585
|
-
for (const tag of tagSet) {
|
|
586
|
-
try {
|
|
587
|
-
elements.push(...(root.querySelectorAll(tag) as any));
|
|
588
|
-
} catch {
|
|
589
|
-
// ignore selector errors
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
const interactions: InteractionData[] = [];
|
|
594
|
-
for (const el of elements) {
|
|
595
|
-
// Try both QTI 2.x (responseIdentifier) and QTI 3.0 (response-identifier) attribute names
|
|
596
|
-
const responseId = el.getAttribute?.('responseIdentifier') ||
|
|
597
|
-
el.getAttribute?.('response-identifier') ||
|
|
598
|
-
el.getAttribute?.('responseidentifier') ||
|
|
599
|
-
'';
|
|
600
|
-
if (!responseId) continue;
|
|
601
|
-
|
|
602
|
-
const ctx = createExtractionContext(el, responseId, root, declMap, this.config);
|
|
603
|
-
const res = this.extractionRegistry.extract<any>(el, ctx);
|
|
604
|
-
if (!res.success) continue;
|
|
605
|
-
|
|
606
|
-
// Normalize raw tag to QTI 2.x camelCase for ComponentRegistry compatibility.
|
|
607
|
-
// QTI 3.0 elements use kebab-case with 'qti-' prefix:
|
|
608
|
-
// 'qti-choice-interaction' → 'choiceInteraction'
|
|
609
|
-
const rawTag = el.rawTagName;
|
|
610
|
-
const normalizedType = rawTag.startsWith('qti-')
|
|
611
|
-
? rawTag.slice(4).replace(/-([a-z])/g, (_: string, c: string) => c.toUpperCase())
|
|
612
|
-
: rawTag;
|
|
613
|
-
|
|
614
|
-
interactions.push({
|
|
615
|
-
type: normalizedType as any,
|
|
616
|
-
responseId,
|
|
617
|
-
...res.data,
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// Apply URL policy + embed allowances to standard extracted URL fields.
|
|
622
|
-
const policy = this.config.security?.urlPolicy;
|
|
623
|
-
const allowObjectEmbeds = this.config.security?.allowObjectEmbeds === true;
|
|
624
|
-
const ttPolicyName = this.config.security?.trustedTypesPolicyName;
|
|
625
|
-
|
|
626
|
-
for (const i of interactions as any[]) {
|
|
627
|
-
// Wrap known HTML injection fields in TrustedHTML (when enabled).
|
|
628
|
-
// Important: do NOT wrap fields that are rendered as plain text in our Svelte components
|
|
629
|
-
// (e.g. prompt) to avoid "[object Object]" rendering.
|
|
630
|
-
if (i.type === 'choiceInteraction' && Array.isArray(i.choices)) {
|
|
631
|
-
for (const c of i.choices) {
|
|
632
|
-
if (typeof c?.text === 'string') c.text = toTrustedHtml(c.text, ttPolicyName);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// Shared ImageData shape
|
|
637
|
-
if (i.imageData?.src) {
|
|
638
|
-
i.imageData.src = sanitizeResourceUrl(i.imageData.src, policy, 'img') ?? '';
|
|
639
|
-
}
|
|
640
|
-
if (i.imageData?.content && typeof i.imageData.content === 'string') {
|
|
641
|
-
i.imageData.content = toTrustedHtml(i.imageData.content, ttPolicyName);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// positionObject stages
|
|
645
|
-
if (Array.isArray(i.positionObjectStages)) {
|
|
646
|
-
for (const st of i.positionObjectStages) {
|
|
647
|
-
if (st?.objectData?.src) {
|
|
648
|
-
st.objectData.src = sanitizeResourceUrl(st.objectData.src, policy, 'img') ?? '';
|
|
649
|
-
}
|
|
650
|
-
if (st?.objectData?.content && typeof st.objectData.content === 'string') {
|
|
651
|
-
st.objectData.content = toTrustedHtml(st.objectData.content, ttPolicyName);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
// mediaInteraction
|
|
657
|
-
if (i.type === 'mediaInteraction' && i.mediaElement?.src) {
|
|
658
|
-
const kind = i.mediaElement.type === 'object' ? 'object' : 'media';
|
|
659
|
-
i.mediaElement.src = sanitizeResourceUrl(i.mediaElement.src, policy, kind) ?? '';
|
|
660
|
-
i.allowObjectEmbeds = allowObjectEmbeds;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// hottextInteraction content is injected via {@html}
|
|
664
|
-
if (i.type === 'hottextInteraction' && typeof i.contentHtml === 'string') {
|
|
665
|
-
i.contentHtml = toTrustedHtml(i.contentHtml, ttPolicyName);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
return interactions;
|
|
740
|
+
return extractInteractionData({
|
|
741
|
+
document: this.itemDocument,
|
|
742
|
+
extractionRegistry: this.extractionRegistry,
|
|
743
|
+
declarations: this.decls,
|
|
744
|
+
config: this.config,
|
|
745
|
+
});
|
|
670
746
|
}
|
|
671
747
|
|
|
672
748
|
/**
|
|
@@ -698,7 +774,7 @@ export class Player {
|
|
|
698
774
|
}
|
|
699
775
|
|
|
700
776
|
public isAdaptive(): boolean {
|
|
701
|
-
return (
|
|
777
|
+
return (this.itemDocument.getAssessmentItemAttribute('adaptive') || '').toLowerCase() === 'true';
|
|
702
778
|
}
|
|
703
779
|
|
|
704
780
|
public getNumAttempts(): number {
|
|
@@ -1065,7 +1141,7 @@ export class Player {
|
|
|
1065
1141
|
// Declarations
|
|
1066
1142
|
// ----------------------------------------------------------------------------
|
|
1067
1143
|
|
|
1068
|
-
private buildDeclarations(
|
|
1144
|
+
private buildDeclarations(): DeclarationMap {
|
|
1069
1145
|
const decls: DeclarationMap = {};
|
|
1070
1146
|
|
|
1071
1147
|
const addDecl = (kind: DeclKind, el: Element) => {
|
|
@@ -1119,9 +1195,9 @@ export class Player {
|
|
|
1119
1195
|
}
|
|
1120
1196
|
};
|
|
1121
1197
|
|
|
1122
|
-
for (const el of
|
|
1123
|
-
for (const el of
|
|
1124
|
-
for (const el of
|
|
1198
|
+
for (const el of this.itemDocument.findDeclarationElements('response')) addDecl('response', el);
|
|
1199
|
+
for (const el of this.itemDocument.findDeclarationElements('outcome')) addDecl('outcome', el);
|
|
1200
|
+
for (const el of this.itemDocument.findDeclarationElements('template')) addDecl('template', el);
|
|
1125
1201
|
|
|
1126
1202
|
return decls;
|
|
1127
1203
|
}
|
|
@@ -1176,6 +1252,7 @@ export class Player {
|
|
|
1176
1252
|
identifier: 'numAttempts',
|
|
1177
1253
|
baseType: 'integer',
|
|
1178
1254
|
cardinality: 'single',
|
|
1255
|
+
defaultValue: qtiValue('integer', 'single', 0),
|
|
1179
1256
|
value: qtiValue('integer', 'single', 0),
|
|
1180
1257
|
isTemplate: false,
|
|
1181
1258
|
// @ts-expect-error internal marker
|
|
@@ -1183,6 +1260,19 @@ export class Player {
|
|
|
1183
1260
|
};
|
|
1184
1261
|
}
|
|
1185
1262
|
|
|
1263
|
+
if (!decls.duration) {
|
|
1264
|
+
decls.duration = {
|
|
1265
|
+
identifier: 'duration',
|
|
1266
|
+
baseType: 'duration',
|
|
1267
|
+
cardinality: 'single',
|
|
1268
|
+
defaultValue: qtiValue('duration', 'single', 0),
|
|
1269
|
+
value: qtiValue('duration', 'single', 0),
|
|
1270
|
+
isTemplate: false,
|
|
1271
|
+
// @ts-expect-error internal marker
|
|
1272
|
+
__kind: 'outcome',
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1186
1276
|
// Common scoring defaults
|
|
1187
1277
|
if (!decls.SCORE) {
|
|
1188
1278
|
decls.SCORE = {
|
|
@@ -1214,6 +1304,95 @@ export class Player {
|
|
|
1214
1304
|
if (!d) continue;
|
|
1215
1305
|
d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, raw);
|
|
1216
1306
|
}
|
|
1307
|
+
const restoredDuration = Number(state.duration);
|
|
1308
|
+
if (Number.isFinite(restoredDuration) && restoredDuration >= 0) {
|
|
1309
|
+
this.accumulatedDurationMs = restoredDuration;
|
|
1310
|
+
this.sessionStartedAt = Date.now();
|
|
1311
|
+
this.updateDuration();
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
private applySerializedVariables(vars: Record<string, SerializedItemSessionVariable>): void {
|
|
1316
|
+
for (const v of Object.values(vars)) {
|
|
1317
|
+
const d = this.decls[v.identifier];
|
|
1318
|
+
if (!d) continue;
|
|
1319
|
+
d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, v.value);
|
|
1320
|
+
if ((d as any).__kind === 'response') {
|
|
1321
|
+
this.setPciResponse(d.identifier, v.value);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
private serializeItemSession(): SerializedItemSessionState {
|
|
1327
|
+
const responseVariables: Record<string, SerializedItemSessionVariable> = {};
|
|
1328
|
+
const outcomeVariables: Record<string, SerializedItemSessionVariable> = {};
|
|
1329
|
+
const templateVariables: Record<string, SerializedItemSessionVariable> = {};
|
|
1330
|
+
const contextVariables: Record<string, SerializedItemSessionVariable> = {};
|
|
1331
|
+
const contextIds = new Set(['completionStatus', 'numAttempts', 'duration']);
|
|
1332
|
+
|
|
1333
|
+
for (const d of Object.values(this.decls)) {
|
|
1334
|
+
const variable = this.serializeVariable(d);
|
|
1335
|
+
if (d.isTemplate) {
|
|
1336
|
+
templateVariables[d.identifier] = { ...variable, kind: 'template' };
|
|
1337
|
+
} else if (contextIds.has(d.identifier)) {
|
|
1338
|
+
contextVariables[d.identifier] = { ...variable, kind: 'context' };
|
|
1339
|
+
} else if ((d as any).__kind === 'response') {
|
|
1340
|
+
responseVariables[d.identifier] = { ...variable, kind: 'response' };
|
|
1341
|
+
} else if ((d as any).__kind === 'outcome') {
|
|
1342
|
+
outcomeVariables[d.identifier] = { ...variable, kind: 'outcome' };
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
const validation = this.validateResponses(this.getResponses());
|
|
1347
|
+
return {
|
|
1348
|
+
itemIdentifier: this.itemDocument.getAssessmentItemAttribute('identifier') ?? undefined,
|
|
1349
|
+
sessionGuid: this.sessionGuid,
|
|
1350
|
+
lifecycleStatus: this.lifecycleStatus,
|
|
1351
|
+
completionStatus: this.getCompletionStatus(),
|
|
1352
|
+
numAttempts: this.getNumAttempts(),
|
|
1353
|
+
duration: this.getDuration(),
|
|
1354
|
+
responseVariables,
|
|
1355
|
+
outcomeVariables,
|
|
1356
|
+
templateVariables,
|
|
1357
|
+
contextVariables,
|
|
1358
|
+
validationMessages: validation.issues,
|
|
1359
|
+
savedAt: new Date().toISOString(),
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
private serializeVariable(d: DeclarationMap[string]): SerializedItemSessionVariable {
|
|
1364
|
+
return {
|
|
1365
|
+
identifier: d.identifier,
|
|
1366
|
+
kind: ((d as any).__kind ?? (d.isTemplate ? 'template' : 'context')) as SerializedItemSessionVariable['kind'],
|
|
1367
|
+
baseType: d.baseType,
|
|
1368
|
+
cardinality: d.cardinality,
|
|
1369
|
+
value: this.qtiValueToSerializable(d.value),
|
|
1370
|
+
defaultValue: this.qtiValueToSerializable(d.defaultValue),
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
private qtiValueToSerializable(value: QtiValue | undefined): any {
|
|
1375
|
+
if (!value || value.kind !== 'value') return null;
|
|
1376
|
+
return value.value;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
private updateDuration(): void {
|
|
1380
|
+
const elapsedMs = Math.max(0, Date.now() - this.sessionStartedAt);
|
|
1381
|
+
const durationMs = this.accumulatedDurationMs + elapsedMs;
|
|
1382
|
+
this.ctx.setValue('duration', qtiValue('duration', 'single', durationMs));
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
private freezeDuration(): number {
|
|
1386
|
+
this.updateDuration();
|
|
1387
|
+
const duration = this.getDuration();
|
|
1388
|
+
this.accumulatedDurationMs = duration;
|
|
1389
|
+
this.sessionStartedAt = Date.now();
|
|
1390
|
+
return duration;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
private getDuration(): number {
|
|
1394
|
+
const value = this.ctx.getValue('duration');
|
|
1395
|
+
return Math.max(0, Math.floor(toNumber(value) || 0));
|
|
1217
1396
|
}
|
|
1218
1397
|
|
|
1219
1398
|
private parseDefaultValue(declEl: Element, baseType: BaseType, cardinality: Cardinality): QtiValue {
|
|
@@ -1390,16 +1569,16 @@ export class Player {
|
|
|
1390
1569
|
}
|
|
1391
1570
|
|
|
1392
1571
|
private getModalFeedback(outcomes: Record<string, any>): ModalFeedback[] {
|
|
1393
|
-
const feedbackEls =
|
|
1572
|
+
const feedbackEls = this.itemDocument.findModalFeedbackElements();
|
|
1394
1573
|
const active: ModalFeedback[] = [];
|
|
1395
1574
|
|
|
1396
1575
|
for (const el of feedbackEls) {
|
|
1397
|
-
const identifier =
|
|
1398
|
-
const outcomeIdentifier =
|
|
1399
|
-
const showHide = (
|
|
1400
|
-
const title =
|
|
1576
|
+
const identifier = this.getAttrMapped(el, 'identifier') || '';
|
|
1577
|
+
const outcomeIdentifier = this.getAttrMapped(el, 'outcomeIdentifier') || '';
|
|
1578
|
+
const showHide = (this.getAttrMapped(el, 'showHide') || 'show') as 'show' | 'hide';
|
|
1579
|
+
const title = this.getAttrMapped(el, 'title') || undefined;
|
|
1401
1580
|
|
|
1402
|
-
const contentRaw =
|
|
1581
|
+
const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
|
|
1403
1582
|
const sanitized = sanitizeHtml(contentRaw, { security: this.config.security });
|
|
1404
1583
|
const content = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
|
|
1405
1584
|
|
|
@@ -1424,3 +1603,16 @@ function mergePnp(base: PnpProfile | undefined, partial: Partial<PnpProfile>): P
|
|
|
1424
1603
|
cognitive: { ...(base?.cognitive ?? {}), ...(partial.cognitive ?? {}) },
|
|
1425
1604
|
};
|
|
1426
1605
|
}
|
|
1606
|
+
|
|
1607
|
+
function createSessionGuid(): string {
|
|
1608
|
+
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
|
|
1609
|
+
return crypto.randomUUID();
|
|
1610
|
+
}
|
|
1611
|
+
return `item-session-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
function looksLikeCatalogUrl(value: string): boolean {
|
|
1615
|
+
const trimmed = value.trim();
|
|
1616
|
+
return /^(https?:\/\/|\/\/|\/|\.{0,2}\/|data:|blob:)/i.test(trimmed) ||
|
|
1617
|
+
/\.(png|jpe?g|gif|webp|svg|mp3|wav|ogg|mp4|webm|pdf)(\?.*)?$/i.test(trimmed);
|
|
1618
|
+
}
|