@pie-qti/item-player 1.0.0-beta.4 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -5
- package/dist/catalog/applyGlossaryTriggers.js +14 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +2 -4
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/sessionCatalog.d.ts +46 -0
- package/dist/catalog/sessionCatalog.js +87 -0
- package/dist/catalog/sessionCatalog.js.map +1 -0
- package/dist/components/utils/endAttempt.d.ts +16 -0
- package/dist/components/utils/endAttempt.js +28 -0
- package/dist/components/utils/endAttempt.js.map +1 -0
- package/dist/components/utils/focus.d.ts +19 -0
- package/dist/components/utils/focus.js +67 -0
- package/dist/components/utils/focus.js.map +1 -0
- package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
- package/dist/components/utils/itemBodyRenderer.js +177 -0
- package/dist/components/utils/itemBodyRenderer.js.map +1 -0
- package/dist/components/utils/sentenceContext.d.ts +6 -0
- package/dist/components/utils/sentenceContext.js +16 -0
- package/dist/components/utils/sentenceContext.js.map +1 -0
- package/dist/core/AssessmentItemDefinition.d.ts +20 -1
- package/dist/core/AssessmentItemDefinition.js +12 -31
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ComponentRegistry.d.ts +92 -0
- package/dist/core/ComponentRegistry.js +7 -1
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +18 -1
- package/dist/core/ItemSession.js +79 -41
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +118 -141
- package/dist/core/Player.js +387 -1233
- package/dist/core/Player.js.map +1 -1
- package/dist/core/compliance.d.ts +72 -0
- package/dist/core/compliance.js +147 -0
- package/dist/core/compliance.js.map +1 -0
- package/dist/core/declarations/declarationBuilder.d.ts +29 -0
- package/dist/core/declarations/declarationBuilder.js +284 -0
- package/dist/core/declarations/declarationBuilder.js.map +1 -0
- package/dist/core/declarations/declarationValues.d.ts +11 -0
- package/dist/core/declarations/declarationValues.js +168 -0
- package/dist/core/declarations/declarationValues.js.map +1 -0
- package/dist/core/matchGroups.d.ts +36 -0
- package/dist/core/matchGroups.js +100 -0
- package/dist/core/matchGroups.js.map +1 -0
- package/dist/core/nameMappers.d.ts +35 -0
- package/dist/core/nameMappers.js +47 -0
- package/dist/core/nameMappers.js.map +1 -0
- package/dist/core/parsingLimits.d.ts +4 -0
- package/dist/core/parsingLimits.js +5 -2
- package/dist/core/parsingLimits.js.map +1 -1
- package/dist/core/processing/responseProcessing.d.ts +88 -0
- package/dist/core/processing/responseProcessing.js +317 -0
- package/dist/core/processing/responseProcessing.js.map +1 -0
- package/dist/core/processing/responseValidation.d.ts +55 -0
- package/dist/core/processing/responseValidation.js +335 -0
- package/dist/core/processing/responseValidation.js.map +1 -0
- package/dist/core/rendering/contentPass.d.ts +31 -0
- package/dist/core/rendering/contentPass.js +152 -0
- package/dist/core/rendering/contentPass.js.map +1 -0
- package/dist/core/rendering/htmlRender.d.ts +21 -0
- package/dist/core/rendering/htmlRender.js +56 -0
- package/dist/core/rendering/htmlRender.js.map +1 -0
- package/dist/core/responseProcessingTemplates.d.ts +23 -0
- package/dist/core/responseProcessingTemplates.js +45 -0
- package/dist/core/responseProcessingTemplates.js.map +1 -0
- package/dist/core/rolePolicy.d.ts +5 -0
- package/dist/core/rolePolicy.js +21 -0
- package/dist/core/rolePolicy.js.map +1 -1
- package/dist/core/sanitizer.js +8 -14
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/serialization/sessionState.d.ts +56 -0
- package/dist/core/serialization/sessionState.js +139 -0
- package/dist/core/serialization/sessionState.js.map +1 -0
- package/dist/core/serialization/valueForms.d.ts +32 -0
- package/dist/core/serialization/valueForms.js +112 -0
- package/dist/core/serialization/valueForms.js.map +1 -0
- package/dist/document/AssessmentItemDocument.d.ts +27 -1
- package/dist/document/AssessmentItemDocument.js +67 -31
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/element-class-BbF4Dj7F.js +3773 -0
- package/dist/element-class-BbF4Dj7F.js.map +1 -0
- package/dist/element-class.d.ts +34 -1
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.js +6 -12
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionCoverage.d.ts +31 -0
- package/dist/extraction/interactionCoverage.js +40 -0
- package/dist/extraction/interactionCoverage.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.js +5 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.js +1 -28
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
- package/dist/extraction/mergeDeliveryFields.js +17 -0
- package/dist/extraction/mergeDeliveryFields.js.map +1 -0
- package/dist/extraction/responseIdentifier.d.ts +19 -0
- package/dist/extraction/responseIdentifier.js +29 -0
- package/dist/extraction/responseIdentifier.js.map +1 -0
- package/dist/extraction/types.d.ts +11 -18
- package/dist/extraction/types.js +0 -12
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.d.ts +14 -0
- package/dist/extraction/utils.js +35 -5
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.d.ts +1 -0
- package/dist/interactions/associate/extractor.js +10 -12
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +6 -13
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.d.ts +6 -0
- package/dist/interactions/drawing/extractor.js +30 -9
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -1
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -1
- package/dist/interactions/extended-text/extractor.js +10 -5
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/response.js +18 -18
- package/dist/interactions/extended-text/response.js.map +1 -1
- package/dist/interactions/gap-match/extractor.d.ts +40 -2
- package/dist/interactions/gap-match/extractor.js +197 -39
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
- package/dist/interactions/graphic-associate/extractor.js +35 -24
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
- package/dist/interactions/graphic-gap-match/extractor.js +79 -43
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.d.ts +15 -0
- package/dist/interactions/graphic-order/extractor.js +39 -24
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.d.ts +6 -0
- package/dist/interactions/hotspot/extractor.js +31 -16
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/hottext/extractor.js +2 -12
- package/dist/interactions/hottext/extractor.js.map +1 -1
- package/dist/interactions/inline/accessibleName.d.ts +29 -0
- package/dist/interactions/inline/accessibleName.js +35 -0
- package/dist/interactions/inline/accessibleName.js.map +1 -0
- package/dist/interactions/inline/render-plan.d.ts +5 -14
- package/dist/interactions/inline/render-plan.js +5 -56
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.d.ts +4 -0
- package/dist/interactions/inline-choice/extractor.js +13 -12
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.d.ts +2 -0
- package/dist/interactions/match/extractor.js +14 -28
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/media/extractor.d.ts +5 -11
- package/dist/interactions/media/extractor.js +100 -36
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.js +8 -2
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.d.ts +2 -0
- package/dist/interactions/order/extractor.js +8 -12
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/order/limits.d.ts +29 -0
- package/dist/interactions/order/limits.js +28 -0
- package/dist/interactions/order/limits.js.map +1 -0
- package/dist/interactions/portable-custom/extractor.js +4 -2
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +18 -1
- package/dist/interactions/position-object/extractor.js +81 -22
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.d.ts +6 -0
- package/dist/interactions/select-point/extractor.js +31 -19
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/imageAlt.d.ts +54 -0
- package/dist/interactions/shared/imageAlt.js +84 -0
- package/dist/interactions/shared/imageAlt.js.map +1 -0
- package/dist/interactions/shared/interactionImage.d.ts +32 -0
- package/dist/interactions/shared/interactionImage.js +39 -0
- package/dist/interactions/shared/interactionImage.js.map +1 -0
- package/dist/interactions/shared/specDefaults.d.ts +20 -0
- package/dist/interactions/shared/specDefaults.js +25 -0
- package/dist/interactions/shared/specDefaults.js.map +1 -0
- package/dist/interactions/shared/types.d.ts +212 -40
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/text-entry/extractor.d.ts +9 -0
- package/dist/interactions/text-entry/extractor.js +9 -0
- package/dist/interactions/text-entry/extractor.js.map +1 -1
- package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
- package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
- package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
- package/dist/interactions/text-entry/inputMode.d.ts +35 -0
- package/dist/interactions/text-entry/inputMode.js +134 -0
- package/dist/interactions/text-entry/inputMode.js.map +1 -0
- package/dist/interactions/text-entry/response.d.ts +15 -0
- package/dist/interactions/text-entry/response.js +25 -0
- package/dist/interactions/text-entry/response.js.map +1 -0
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/PciHost.d.ts +1 -1
- package/dist/pci/PciHost.js +11 -11
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +1 -0
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/modulePaths.d.ts +16 -0
- package/dist/pci/modulePaths.js +33 -0
- package/dist/pci/modulePaths.js.map +1 -0
- package/dist/pci/pageRealmSession.js +3 -15
- package/dist/pci/pageRealmSession.js.map +1 -1
- package/dist/pci/qtiVariableJson.d.ts +46 -3
- package/dist/pci/qtiVariableJson.js +247 -53
- package/dist/pci/qtiVariableJson.js.map +1 -1
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
- package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
- package/dist/pci/sandbox/iframeConnector.js +35 -6
- package/dist/pci/sandbox/iframeConnector.js.map +1 -1
- package/dist/pci/sandbox/protocol.d.ts +14 -0
- package/dist/pci/sandbox/protocol.js.map +1 -1
- package/dist/pci/sessionHosts.d.ts +47 -0
- package/dist/pci/sessionHosts.js +66 -0
- package/dist/pci/sessionHosts.js.map +1 -0
- package/dist/pci/types.d.ts +7 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +20 -3
- package/dist/pnp/applyPnp.js +84 -9
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.js +2 -0
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +16 -8
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
- package/dist/presentation/feedbackAnnouncement.js +150 -0
- package/dist/presentation/feedbackAnnouncement.js.map +1 -0
- package/dist/presentation/interactionSlots.d.ts +31 -0
- package/dist/presentation/interactionSlots.js +101 -0
- package/dist/presentation/interactionSlots.js.map +1 -0
- package/dist/presentation/itemPresentationPlan.d.ts +69 -6
- package/dist/presentation/itemPresentationPlan.js +93 -81
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
- package/dist/presentation/stimulusRender.js.map +1 -0
- package/dist/presentation/stylesheetRender.js.map +1 -0
- package/dist/security/escapeHtml.d.ts +15 -0
- package/dist/security/escapeHtml.js +22 -0
- package/dist/security/escapeHtml.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/server.d.ts +8 -1
- package/dist/server.js.map +1 -1
- package/dist/session-inputs.d.ts +108 -0
- package/dist/session-inputs.js +130 -0
- package/dist/session-inputs.js.map +1 -0
- package/dist/types/index.d.ts +67 -35
- package/dist/types/index.js.map +1 -1
- package/dist/utils/cloneFreeze.d.ts +52 -0
- package/dist/utils/cloneFreeze.js +113 -0
- package/dist/utils/cloneFreeze.js.map +1 -0
- package/dist/utils/htmlAttributes.d.ts +13 -0
- package/dist/utils/htmlAttributes.js +22 -0
- package/dist/utils/htmlAttributes.js.map +1 -0
- package/dist/web-components/QTIInteractionElement.d.ts +0 -29
- package/dist/web-components/QTIInteractionElement.js +0 -32
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/dist/web-components/index.d.ts +1 -2
- package/dist/web-components/index.js +2 -3
- package/dist/web-components/index.js.map +1 -1
- package/package.json +15 -14
- package/dist/components/utils/stimulusRender.js.map +0 -1
- package/dist/components/utils/stylesheetRender.js.map +0 -1
- package/dist/core/constants.d.ts +0 -65
- package/dist/core/constants.js +0 -74
- package/dist/core/constants.js.map +0 -1
- package/dist/element-class-DdpiTalY.js +0 -9226
- package/dist/element-class-DdpiTalY.js.map +0 -1
- package/dist/extensions/MathLiveEditor.d.ts +0 -31
- package/dist/extensions/MathLiveEditor.js +0 -248
- package/dist/extensions/MathLiveEditor.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -169
- package/dist/utils/PerformanceMonitor.js +0 -243
- package/dist/utils/PerformanceMonitor.js.map +0 -1
- package/dist/utils/responseUtils.d.ts +0 -15
- package/dist/utils/responseUtils.js +0 -46
- package/dist/utils/responseUtils.js.map +0 -1
- package/dist/web-components/QTIInteractionBase.d.ts +0 -119
- package/dist/web-components/QTIInteractionBase.js +0 -244
- package/dist/web-components/QTIInteractionBase.js.map +0 -1
- /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
|
@@ -1,50 +1,139 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Standard QTI gapMatchInteraction extractor
|
|
3
3
|
*
|
|
4
|
-
* Extracts data from gapMatchInteraction elements (drag words into gaps)
|
|
4
|
+
* Extracts data from gapMatchInteraction elements (drag words or images into gaps)
|
|
5
5
|
*/
|
|
6
|
+
import { validateUniqueIdentifiers } from '../../extraction/utils.js';
|
|
6
7
|
import { maybeShuffle } from '../../core/shuffle.js';
|
|
7
|
-
import {
|
|
8
|
+
import { readHtmlAttribute } from '../../utils/htmlAttributes.js';
|
|
9
|
+
import { normalizeCssPixelLength, normalizePixelDimension } from '../../security/styleValues.js';
|
|
10
|
+
import { findInteractionImage } from '../shared/interactionImage.js';
|
|
11
|
+
import { predatesQti22 } from '../shared/specDefaults.js';
|
|
8
12
|
const GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\s/>])([^>]*)\/?>/gi;
|
|
9
13
|
const GAP_CLOSE_PATTERN = /<\/(?:qti-gap|gap)>/gi;
|
|
10
14
|
const GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\b[\s\S]*?<\/(?:qti-gap-text|gapText)>/gi;
|
|
15
|
+
const GAP_IMG_PATTERN = /<(?:qti-gap-img|gapImg)\b[\s\S]*?<\/(?:qti-gap-img|gapImg)>/gi;
|
|
11
16
|
const GAP_MATCH_OPEN_PATTERN = /<(?:qti-gap-match-interaction|gapMatchInteraction)\b[^>]*>/i;
|
|
12
17
|
const GAP_MATCH_CLOSE_PATTERN = /<\/(?:qti-gap-match-interaction|gapMatchInteraction)>/i;
|
|
13
18
|
const PROMPT_PATTERN = /<(?:qti-prompt|prompt)\b[\s\S]*?<\/(?:qti-prompt|prompt)>/gi;
|
|
14
|
-
function extractAttribute(attrs, name) {
|
|
15
|
-
const match = new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, 'i').exec(attrs);
|
|
16
|
-
return (match?.[1] ?? match?.[2] ?? '').trim();
|
|
17
|
-
}
|
|
18
19
|
function promptTextFromInteractionBody(interactionHtml) {
|
|
19
20
|
return interactionHtml
|
|
20
21
|
.replace(GAP_MATCH_OPEN_PATTERN, '')
|
|
21
22
|
.replace(GAP_MATCH_CLOSE_PATTERN, '')
|
|
22
23
|
.replace(PROMPT_PATTERN, '')
|
|
23
24
|
.replace(GAP_TEXT_PATTERN, '')
|
|
25
|
+
.replace(GAP_IMG_PATTERN, '')
|
|
24
26
|
.replace(GAP_ELEMENT_PATTERN, (_match, attrs) => {
|
|
25
|
-
const id =
|
|
27
|
+
const id = readHtmlAttribute(attrs, 'identifier');
|
|
26
28
|
return id ? `[GAP:${id}]` : '';
|
|
27
29
|
})
|
|
28
30
|
.replace(GAP_CLOSE_PATTERN, '')
|
|
29
31
|
.trim();
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Compile-time proof that what this extractor delivers satisfies the canonical
|
|
35
|
+
* `GapMatchInteractionData` contract: `gaps` are the plain identifiers the
|
|
36
|
+
* pipeline delivers (an object shape here would silently disagree at runtime).
|
|
37
|
+
*/
|
|
38
|
+
const DELIVERED_MATCHES_CONTRACT = true;
|
|
39
|
+
void DELIVERED_MATCHES_CONTRACT;
|
|
40
|
+
/**
|
|
41
|
+
* Put each fixed choice back at its authored index; the others keep the order
|
|
42
|
+
* the (combined) shuffle left them in. No authored `fixed` means no repair and
|
|
43
|
+
* the shuffle result stands unchanged.
|
|
44
|
+
*/
|
|
45
|
+
function restoreFixedPositions(shuffled, authored) {
|
|
46
|
+
if (!authored.some((choice) => choice.fixed))
|
|
47
|
+
return [...shuffled];
|
|
48
|
+
const movable = shuffled.filter((choice) => !choice.fixed);
|
|
49
|
+
const restored = [];
|
|
50
|
+
let next = 0;
|
|
51
|
+
for (const choice of authored) {
|
|
52
|
+
restored.push(choice.fixed ? choice : movable[next++]);
|
|
53
|
+
}
|
|
54
|
+
return restored;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Extracts one draggable image choice from gapImg/qti-gap-img content.
|
|
58
|
+
*
|
|
59
|
+
* `readsFixed` is true for QTI 2.1 content only: `fixed` exists on gapImg (and
|
|
60
|
+
* gapText) in the QTI 2.1 schema alone (fixed.GapImg.Attr / fixed.GapText.Attr);
|
|
61
|
+
* QTI 2.2 and 3.0 define none, so an authored one there is not an attribute of
|
|
62
|
+
* the element and is not read.
|
|
63
|
+
*/
|
|
64
|
+
function extractGapImage(gapImg, utils, readsFixed) {
|
|
65
|
+
const classes = utils.getClasses(gapImg);
|
|
66
|
+
const matchMax = utils.getNumberAttribute(gapImg, 'matchMax', 1);
|
|
67
|
+
const matchMin = utils.getNumberAttribute(gapImg, 'matchMin', 0);
|
|
68
|
+
const matchGroupRaw = utils.getAttribute(gapImg, 'matchGroup', '');
|
|
69
|
+
const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
|
|
70
|
+
const objectLabel = utils.getAttribute(gapImg, 'objectLabel', '').trim();
|
|
71
|
+
const fixed = readsFixed && utils.getBooleanAttribute(gapImg, 'fixed');
|
|
72
|
+
let src = '';
|
|
73
|
+
let alt = '';
|
|
74
|
+
let width;
|
|
75
|
+
let height;
|
|
76
|
+
// QTI 2.x: <gapImg><object data="…" width height>alt text</object></gapImg>.
|
|
77
|
+
// QTI 3.0 allows an <img> or a <picture> (delivered via its <img> fallback):
|
|
78
|
+
// <qti-gap-img><img src="…" alt="…" /></qti-gap-img>
|
|
79
|
+
const image = findInteractionImage(gapImg, utils);
|
|
80
|
+
if (image?.kind === 'object') {
|
|
81
|
+
const obj = image.element;
|
|
82
|
+
src = utils.getAttribute(obj, 'data', '');
|
|
83
|
+
alt = utils.getTextContent(obj);
|
|
84
|
+
const w = normalizePixelDimension(utils.getAttribute(obj, 'width', ''));
|
|
85
|
+
const h = normalizePixelDimension(utils.getAttribute(obj, 'height', ''));
|
|
86
|
+
if (w)
|
|
87
|
+
width = Number(w);
|
|
88
|
+
if (h)
|
|
89
|
+
height = Number(h);
|
|
90
|
+
}
|
|
91
|
+
else if (image) {
|
|
92
|
+
const img = image.element;
|
|
93
|
+
src = utils.getAttribute(img, 'src', '');
|
|
94
|
+
alt = utils.getAttribute(img, 'alt', '');
|
|
95
|
+
const w = normalizePixelDimension(utils.getAttribute(img, 'width', ''));
|
|
96
|
+
const h = normalizePixelDimension(utils.getAttribute(img, 'height', ''));
|
|
97
|
+
if (w)
|
|
98
|
+
width = Number(w);
|
|
99
|
+
if (h)
|
|
100
|
+
height = Number(h);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
identifier: utils.getAttribute(gapImg, 'identifier', ''),
|
|
104
|
+
src,
|
|
105
|
+
alt,
|
|
106
|
+
matchMax,
|
|
107
|
+
...(matchMin > 0 ? { matchMin } : {}),
|
|
108
|
+
...(matchGroup.length > 0 ? { matchGroup } : {}),
|
|
109
|
+
...(objectLabel ? { objectLabel } : {}),
|
|
110
|
+
...(fixed ? { fixed } : {}),
|
|
111
|
+
...(classes.length > 0 ? { classes } : {}),
|
|
112
|
+
...(width !== undefined ? { width } : {}),
|
|
113
|
+
...(height !== undefined ? { height } : {}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
31
116
|
/**
|
|
32
117
|
* Standard QTI gap match interaction extractor
|
|
33
|
-
* Handles gapMatchInteraction elements (drag words into gaps in text)
|
|
118
|
+
* Handles gapMatchInteraction elements (drag words or images into gaps in text)
|
|
34
119
|
*/
|
|
35
120
|
export const standardGapMatchExtractor = {
|
|
36
121
|
id: 'qti:gap-match-interaction',
|
|
37
122
|
name: 'QTI Standard Gap Match Interaction',
|
|
38
123
|
priority: 10,
|
|
39
124
|
elementTypes: ['gapMatchInteraction'],
|
|
40
|
-
description: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',
|
|
125
|
+
description: 'Extracts standard QTI gapMatchInteraction (drag words or images into gaps)',
|
|
41
126
|
canHandle(element, context) {
|
|
42
127
|
// All gapMatchInteraction elements are standard
|
|
43
128
|
return context.utils.matchesTag(element, 'gapMatchInteraction');
|
|
44
129
|
},
|
|
45
130
|
extract(element, context) {
|
|
46
131
|
const { utils } = context;
|
|
47
|
-
//
|
|
132
|
+
// `fixed` exists on gapText and gapImg in the QTI 2.1 schema alone
|
|
133
|
+
// (fixed.GapText.Attr / fixed.GapImg.Attr); QTI 2.2 and 3.0 define none on
|
|
134
|
+
// gap choices, so it is read for QTI 2.1 content only.
|
|
135
|
+
const readsFixed = predatesQti22(context);
|
|
136
|
+
// Extract gapText children (draggable text items)
|
|
48
137
|
const gapTextElements = utils.getChildrenByTag(element, 'gapText');
|
|
49
138
|
const gapTexts = gapTextElements.map((gapText) => {
|
|
50
139
|
const classes = utils.getClasses(gapText);
|
|
@@ -52,15 +141,50 @@ export const standardGapMatchExtractor = {
|
|
|
52
141
|
const matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);
|
|
53
142
|
const matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');
|
|
54
143
|
const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
|
|
144
|
+
const fixed = readsFixed && utils.getBooleanAttribute(gapText, 'fixed');
|
|
55
145
|
return {
|
|
56
146
|
identifier: utils.getAttribute(gapText, 'identifier', ''),
|
|
57
147
|
text: utils.getTextContent(gapText),
|
|
58
148
|
matchMax,
|
|
59
149
|
...(matchMin > 0 ? { matchMin } : {}),
|
|
60
150
|
...(matchGroup.length > 0 ? { matchGroup } : {}),
|
|
151
|
+
...(fixed ? { fixed } : {}),
|
|
61
152
|
...(classes.length > 0 ? { classes } : {}),
|
|
62
153
|
};
|
|
63
154
|
});
|
|
155
|
+
// Extract gapImg children (draggable image items; QTI 2.x gapImg / QTI 3.0 qti-gap-img)
|
|
156
|
+
const gapImgElements = utils.getChildrenByTag(element, 'gapImg');
|
|
157
|
+
const gapImages = gapImgElements.map((gapImg) => extractGapImage(gapImg, utils, readsFixed));
|
|
158
|
+
// Extract attributes
|
|
159
|
+
const shuffle = utils.getBooleanAttribute(element, 'shuffle');
|
|
160
|
+
// Absent maxAssociations: "1" in QTI 2.2 (Table 5.38.3) and QTI 3.0 (Table 5.57.3),
|
|
161
|
+
// 0 = no restriction. QTI 2.2 added the attribute, so QTI 2.1 content sets no
|
|
162
|
+
// interaction cap. An explicit value is honoured in every version as leniency.
|
|
163
|
+
const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', predatesQti22(context) ? 0 : 1);
|
|
164
|
+
// minAssociations (QTI 2.2; QTI 3.0 §5.57.2): "the minimum number of associations that the
|
|
165
|
+
// candidate is required to make to form a valid response"; 0 requires none.
|
|
166
|
+
const minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);
|
|
167
|
+
// Shuffle the combined choice pool so words and images interleave, then
|
|
168
|
+
// restore the split view the renderer consumes.
|
|
169
|
+
if (gapTexts.length > 0 || gapImages.length > 0) {
|
|
170
|
+
const authoredTexts = [...gapTexts];
|
|
171
|
+
const authoredImages = [...gapImages];
|
|
172
|
+
const combined = [...gapTexts.map((choice) => ({ type: 'text', choice })), ...gapImages.map((choice) => ({ type: 'image', choice }))];
|
|
173
|
+
const shuffled = maybeShuffle(combined, shuffle, context.shuffleRng);
|
|
174
|
+
gapTexts.length = 0;
|
|
175
|
+
gapImages.length = 0;
|
|
176
|
+
for (const entry of shuffled) {
|
|
177
|
+
if (entry.type === 'text')
|
|
178
|
+
gapTexts.push(entry.choice);
|
|
179
|
+
else
|
|
180
|
+
gapImages.push(entry.choice);
|
|
181
|
+
}
|
|
182
|
+
// A fixed choice keeps the position it has unshuffled. The pool is
|
|
183
|
+
// presented words first, then images, so that position is its authored
|
|
184
|
+
// index among the choices of its kind.
|
|
185
|
+
gapTexts.splice(0, gapTexts.length, ...restoreFixedPositions(gapTexts, authoredTexts));
|
|
186
|
+
gapImages.splice(0, gapImages.length, ...restoreFixedPositions(gapImages, authoredImages));
|
|
187
|
+
}
|
|
64
188
|
// Extract prompt (optional) and process gap placeholders.
|
|
65
189
|
// NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)
|
|
66
190
|
// rather than inside a `<prompt>` element. Support both patterns.
|
|
@@ -82,7 +206,7 @@ export const standardGapMatchExtractor = {
|
|
|
82
206
|
// getHtmlContent deliberately removed.
|
|
83
207
|
promptText = prompt
|
|
84
208
|
.replace(GAP_ELEMENT_PATTERN, (_match, attrs) => {
|
|
85
|
-
const id =
|
|
209
|
+
const id = readHtmlAttribute(attrs, 'identifier');
|
|
86
210
|
return id ? `[GAP:${id}]` : '';
|
|
87
211
|
})
|
|
88
212
|
.replace(GAP_CLOSE_PATTERN, '')
|
|
@@ -95,7 +219,7 @@ export const standardGapMatchExtractor = {
|
|
|
95
219
|
const interactionHtml = utils.getHtmlContent(element);
|
|
96
220
|
const gapIdMatches = Array.from(interactionHtml.matchAll(GAP_ELEMENT_PATTERN));
|
|
97
221
|
for (const m of gapIdMatches) {
|
|
98
|
-
const id =
|
|
222
|
+
const id = readHtmlAttribute(m[1] ?? '', 'identifier');
|
|
99
223
|
if (id)
|
|
100
224
|
gaps.push(id);
|
|
101
225
|
}
|
|
@@ -104,15 +228,43 @@ export const standardGapMatchExtractor = {
|
|
|
104
228
|
promptText = promptTextFromInteractionBody(interactionHtml);
|
|
105
229
|
}
|
|
106
230
|
}
|
|
107
|
-
//
|
|
108
|
-
|
|
231
|
+
// Each gap's authored matchGroup (QTI 2.2/3.0: the identifiers of the choices that may be
|
|
232
|
+
// matched with it), read from the parsed source wherever the gap sits, with
|
|
233
|
+
// version-aware attribute names (matchGroup / match-group). A gap authored `required`
|
|
234
|
+
// "must be filled by the candidate in order to form a valid response" (QTI 2.1 gap;
|
|
235
|
+
// QTI 3.0 §5.55.5).
|
|
236
|
+
const gapMatchGroups = {};
|
|
237
|
+
const requiredGaps = [];
|
|
238
|
+
const visitGaps = (node) => {
|
|
239
|
+
for (const child of node.childNodes ?? []) {
|
|
240
|
+
const candidate = child;
|
|
241
|
+
if (!candidate.rawTagName)
|
|
242
|
+
continue;
|
|
243
|
+
if (utils.matchesTag(candidate, 'gap')) {
|
|
244
|
+
const identifier = utils.getAttribute(candidate, 'identifier', '');
|
|
245
|
+
const tokens = utils.getAttribute(candidate, 'matchGroup', '').split(/\s+/).filter(Boolean);
|
|
246
|
+
if (identifier && tokens.length > 0)
|
|
247
|
+
gapMatchGroups[identifier] = tokens;
|
|
248
|
+
if (identifier && utils.getBooleanAttribute(candidate, 'required', false))
|
|
249
|
+
requiredGaps.push(identifier);
|
|
250
|
+
}
|
|
251
|
+
visitGaps(candidate);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
visitGaps(element);
|
|
255
|
+
// Extract interaction-level classes and attributes
|
|
109
256
|
const interactionClasses = utils.getClasses(element);
|
|
110
257
|
const choicesContainerWidth = normalizeCssPixelLength(utils.getAttribute(element, 'data-choices-container-width', ''));
|
|
111
258
|
const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
|
|
112
259
|
const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
|
|
113
260
|
return {
|
|
114
|
-
gapTexts
|
|
261
|
+
gapTexts,
|
|
262
|
+
gapImages,
|
|
115
263
|
gaps,
|
|
264
|
+
maxAssociations,
|
|
265
|
+
...(minAssociations > 0 ? { minAssociations } : {}),
|
|
266
|
+
...(Object.keys(gapMatchGroups).length > 0 ? { gapMatchGroups } : {}),
|
|
267
|
+
...(requiredGaps.length > 0 ? { requiredGaps } : {}),
|
|
116
268
|
shuffle,
|
|
117
269
|
prompt,
|
|
118
270
|
promptText,
|
|
@@ -124,48 +276,54 @@ export const standardGapMatchExtractor = {
|
|
|
124
276
|
},
|
|
125
277
|
validate(data) {
|
|
126
278
|
const errors = [];
|
|
127
|
-
// Validate
|
|
128
|
-
if (!data.gapTexts || data.gapTexts.length === 0) {
|
|
129
|
-
errors.push('gapMatchInteraction must have at least one gapText');
|
|
279
|
+
// Validate draggable choices exist (gapText or gapImg — QTI 2.1/2.2/3.0 allow both)
|
|
280
|
+
if ((!data.gapTexts || data.gapTexts.length === 0) && (!data.gapImages || data.gapImages.length === 0)) {
|
|
281
|
+
errors.push('gapMatchInteraction must have at least one gapText or gapImg');
|
|
130
282
|
}
|
|
131
283
|
// Validate gaps exist
|
|
132
284
|
if (!data.gaps || data.gaps.length === 0) {
|
|
133
285
|
errors.push('gapMatchInteraction must have at least one gap in the prompt');
|
|
134
286
|
}
|
|
287
|
+
// Identifiers of gapText and gapImg choices share one response-identifier space:
|
|
288
|
+
// a collision would make "wordId gapId" response pairs ambiguous.
|
|
289
|
+
const choiceIdentifiers = new Set();
|
|
290
|
+
const validateChoiceIdentifier = (identifier, kind) => {
|
|
291
|
+
if (!identifier) {
|
|
292
|
+
errors.push(`All ${kind} choices must have an identifier`);
|
|
293
|
+
}
|
|
294
|
+
else if (choiceIdentifiers.has(identifier)) {
|
|
295
|
+
errors.push(`Duplicate choice identifier: ${identifier}`);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
choiceIdentifiers.add(identifier);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
135
301
|
// Validate gapText identifiers
|
|
136
302
|
if (data.gapTexts) {
|
|
137
|
-
const identifiers = new Set();
|
|
138
303
|
for (const gapText of data.gapTexts) {
|
|
139
|
-
|
|
140
|
-
errors.push('All gapTexts must have an identifier');
|
|
141
|
-
}
|
|
142
|
-
else if (identifiers.has(gapText.identifier)) {
|
|
143
|
-
errors.push(`Duplicate gapText identifier: ${gapText.identifier}`);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
identifiers.add(gapText.identifier);
|
|
147
|
-
}
|
|
304
|
+
validateChoiceIdentifier(gapText.identifier, 'gapText');
|
|
148
305
|
// Validate matchMax
|
|
149
306
|
if (gapText.matchMax < 0) {
|
|
150
307
|
errors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);
|
|
151
308
|
}
|
|
152
309
|
}
|
|
153
310
|
}
|
|
154
|
-
// Validate
|
|
155
|
-
if (data.
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
errors.push(
|
|
311
|
+
// Validate gapImg identifiers and image sources
|
|
312
|
+
if (data.gapImages) {
|
|
313
|
+
for (const gapImage of data.gapImages) {
|
|
314
|
+
validateChoiceIdentifier(gapImage.identifier, 'gapImg');
|
|
315
|
+
if (gapImage.matchMax < 0) {
|
|
316
|
+
errors.push(`matchMax must be non-negative for gapImg ${gapImage.identifier}`);
|
|
160
317
|
}
|
|
161
|
-
|
|
162
|
-
errors.push(`
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
identifiers.add(gap);
|
|
318
|
+
if (!gapImage.src) {
|
|
319
|
+
errors.push(`gapImg ${gapImage.identifier} must reference an image source`);
|
|
166
320
|
}
|
|
167
321
|
}
|
|
168
322
|
}
|
|
323
|
+
// Validate gap identifiers
|
|
324
|
+
if (data.gaps) {
|
|
325
|
+
validateUniqueIdentifiers(data.gaps, errors, { plural: 'gaps', noun: 'gap' });
|
|
326
|
+
}
|
|
169
327
|
return {
|
|
170
328
|
valid: errors.length === 0,
|
|
171
329
|
errors: errors.length > 0 ? errors : undefined,
|
|
@@ -1 +1 @@
|
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AC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI gapMatchInteraction extractor\n *\n * Extracts data from gapMatchInteraction elements (drag words into gaps)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\nimport { normalizeCssPixelLength } from '../../security/styleValues.js';\n\nconst GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\\s/>])([^>]*)\\/?>/gi;\nconst GAP_CLOSE_PATTERN = /<\\/(?:qti-gap|gap)>/gi;\nconst GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\\b[\\s\\S]*?<\\/(?:qti-gap-text|gapText)>/gi;\nconst GAP_MATCH_OPEN_PATTERN = /<(?:qti-gap-match-interaction|gapMatchInteraction)\\b[^>]*>/i;\nconst GAP_MATCH_CLOSE_PATTERN = /<\\/(?:qti-gap-match-interaction|gapMatchInteraction)>/i;\nconst PROMPT_PATTERN = /<(?:qti-prompt|prompt)\\b[\\s\\S]*?<\\/(?:qti-prompt|prompt)>/gi;\n\nfunction extractAttribute(attrs: string, name: string): string {\n\tconst match = new RegExp(`\\\\b${name}\\\\s*=\\\\s*(?:\"([^\"]*)\"|'([^']*)')`, 'i').exec(attrs);\n\treturn (match?.[1] ?? match?.[2] ?? '').trim();\n}\n\nfunction promptTextFromInteractionBody(interactionHtml: string): string {\n\treturn interactionHtml\n\t\t.replace(GAP_MATCH_OPEN_PATTERN, '')\n\t\t.replace(GAP_MATCH_CLOSE_PATTERN, '')\n\t\t.replace(PROMPT_PATTERN, '')\n\t\t.replace(GAP_TEXT_PATTERN, '')\n\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t})\n\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t.trim();\n}\n\n/**\n * Gap match data extracted from gapMatchInteraction elements\n */\nexport interface GapMatchData {\n\tgapTexts: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tgaps: string[];\n\tshuffle: boolean;\n\tprompt: string | null;\n\tpromptText: string;\n}\n\n/**\n * Standard QTI gap match interaction extractor\n * Handles gapMatchInteraction elements (drag words into gaps in text)\n */\nexport const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {\n\tid: 'qti:gap-match-interaction',\n\tname: 'QTI Standard Gap Match Interaction',\n\tpriority: 10,\n\telementTypes: ['gapMatchInteraction'],\n\tdescription: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',\n\n\tcanHandle(element, context) {\n\t\t// All gapMatchInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'gapMatchInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract gapText children (draggable items)\n\t\tconst gapTextElements = utils.getChildrenByTag(element, 'gapText');\n\t\tconst gapTexts = gapTextElements.map((gapText) => {\n\t\t\tconst classes = utils.getClasses(gapText);\n\t\t\tconst matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(gapText, 'identifier', ''),\n\t\t\t\ttext: utils.getTextContent(gapText),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt (optional) and process gap placeholders.\n\t\t// NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)\n\t\t// rather than inside a `<prompt>` element. Support both patterns.\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tlet prompt: string | null = null;\n\t\tlet promptText = '';\n\t\tconst gaps: string[] = [];\n\n\t\tif (promptElements.length > 0) {\n\t\t\tconst promptElement = promptElements[0];\n\t\t\tprompt = utils.getHtmlContent(promptElement);\n\n\t\t\t// Extract gap elements from prompt children\n\t\t\tconst gapElements = utils.getChildrenByTag(promptElement, 'gap');\n\t\t\tfor (const gap of gapElements) {\n\t\t\t\tgaps.push(utils.getAttribute(gap, 'identifier', ''));\n\t\t\t}\n\n\t\t\t// Replace gap elements with placeholders in the text\n\t\t\t// Derive renderable content only from the already-sanitized prompt. Using\n\t\t\t// outerHTML here would reintroduce event handlers and unsafe URLs that\n\t\t\t// getHtmlContent deliberately removed.\n\t\t\tpromptText = prompt\n\t\t\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t\t\t})\n\t\t\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t\t\t.trim();\n\t\t}\n\n\t\t// If gaps were not found inside a <prompt>, search the full interaction body.\n\t\t// This handles items where <gap> elements appear in <p>/<blockquote> siblings of <prompt>.\n\t\tif (gaps.length === 0) {\n\t\t\t// Keep the fallback on the same sanitization boundary as prompt content.\n\t\t\tconst interactionHtml = utils.getHtmlContent(element);\n\t\t\tconst gapIdMatches = Array.from(interactionHtml.matchAll(GAP_ELEMENT_PATTERN));\n\t\t\tfor (const m of gapIdMatches) {\n\t\t\t\tconst id = extractAttribute(m[1] ?? '', 'identifier');\n\t\t\t\tif (id) gaps.push(id);\n\t\t\t}\n\n\t\t\tif (gaps.length > 0 && (!promptText || !promptText.includes('[GAP:'))) {\n\t\t\t\t// Build promptText from the interaction body when gaps are authored outside the prompt.\n\t\t\t\tpromptText = promptTextFromInteractionBody(interactionHtml);\n\t\t\t}\n\t\t}\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\tconst choicesContainerWidth = normalizeCssPixelLength(\n\t\t\tutils.getAttribute(element, 'data-choices-container-width', ''),\n\t\t);\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tgapTexts: maybeShuffle(gapTexts, shuffle, context.shuffleRng),\n\t\t\tgaps,\n\t\t\tshuffle,\n\t\t\tprompt,\n\t\t\tpromptText,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(choicesContainerWidth ? { choicesContainerWidth } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate gapTexts exist\n\t\tif (!data.gapTexts || data.gapTexts.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gapText');\n\t\t}\n\n\t\t// Validate gaps exist\n\t\tif (!data.gaps || data.gaps.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gap in the prompt');\n\t\t}\n\n\t\t// Validate gapText identifiers\n\t\tif (data.gapTexts) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gapText of data.gapTexts) {\n\t\t\t\tif (!gapText.identifier) {\n\t\t\t\t\terrors.push('All gapTexts must have an identifier');\n\t\t\t\t} else if (identifiers.has(gapText.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate gapText identifier: ${gapText.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gapText.identifier);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (gapText.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate gap identifiers\n\t\tif (data.gaps) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gap of data.gaps) {\n\t\t\t\tif (!gap) {\n\t\t\t\t\terrors.push('All gaps must have an identifier');\n\t\t\t\t} else if (identifiers.has(gap)) {\n\t\t\t\t\terrors.push(`Duplicate gap identifier: ${gap}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gap);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/gap-match/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACjG,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,mBAAmB,GAAG,yCAAyC,CAAC;AACtE,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAClD,MAAM,gBAAgB,GAAG,mEAAmE,CAAC;AAC7F,MAAM,eAAe,GAAG,+DAA+D,CAAC;AACxF,MAAM,sBAAsB,GAAG,6DAA6D,CA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CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;oBAC1B,MAAM,CAAC,IAAI,CAAC,6CAA6C,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBAChF,CAAC;YACF,CAAC;QACF,CAAC;QAED,gDAAgD;QAChD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACvC,wBAAwB,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBAExD,IAAI,QAAQ,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;oBAC3B,MAAM,CAAC,IAAI,CAAC,4CAA4C,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;gBAChF,CAAC;gBACD,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;oBACnB,MAAM,CAAC,IAAI,CAAC,UAAU,QAAQ,CAAC,UAAU,iCAAiC,CAAC,CAAC;gBAC7E,CAAC;YACF,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,yBAAyB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI gapMatchInteraction extractor\n *\n * Extracts data from gapMatchInteraction elements (drag words or images into gaps)\n */\n\nimport type { ElementExtractor, ExtractionUtils } from '../../extraction/types.js';\nimport { validateUniqueIdentifiers } from '../../extraction/utils.js';\nimport type { DeliveredInteraction, GapMatchInteractionData, QTIElement } from '../../interactions/shared/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\nimport { readHtmlAttribute } from '../../utils/htmlAttributes.js';\nimport { normalizeCssPixelLength, normalizePixelDimension } from '../../security/styleValues.js';\nimport { findInteractionImage } from '../shared/interactionImage.js';\nimport { predatesQti22 } from '../shared/specDefaults.js';\n\nconst GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\\s/>])([^>]*)\\/?>/gi;\nconst GAP_CLOSE_PATTERN = /<\\/(?:qti-gap|gap)>/gi;\nconst GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\\b[\\s\\S]*?<\\/(?:qti-gap-text|gapText)>/gi;\nconst GAP_IMG_PATTERN = /<(?:qti-gap-img|gapImg)\\b[\\s\\S]*?<\\/(?:qti-gap-img|gapImg)>/gi;\nconst GAP_MATCH_OPEN_PATTERN = /<(?:qti-gap-match-interaction|gapMatchInteraction)\\b[^>]*>/i;\nconst GAP_MATCH_CLOSE_PATTERN = /<\\/(?:qti-gap-match-interaction|gapMatchInteraction)>/i;\nconst PROMPT_PATTERN = /<(?:qti-prompt|prompt)\\b[\\s\\S]*?<\\/(?:qti-prompt|prompt)>/gi;\n\nfunction promptTextFromInteractionBody(interactionHtml: string): string {\n\treturn interactionHtml\n\t\t.replace(GAP_MATCH_OPEN_PATTERN, '')\n\t\t.replace(GAP_MATCH_CLOSE_PATTERN, '')\n\t\t.replace(PROMPT_PATTERN, '')\n\t\t.replace(GAP_TEXT_PATTERN, '')\n\t\t.replace(GAP_IMG_PATTERN, '')\n\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\tconst id = readHtmlAttribute(attrs, 'identifier');\n\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t})\n\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t.trim();\n}\n\n/**\n * An image choice extracted from a gapImg (QTI 2.x) or qti-gap-img (QTI 3.0)\n * element. QTI 2.x wraps the image in an <object data=\"…\" …>fallback alt</object>;\n * QTI 3.0 allows a plain <img src alt> as well.\n */\nexport interface GapMatchImage {\n\tidentifier: string;\n\tsrc: string;\n\talt: string;\n\tmatchMax: number;\n\tmatchMin?: number;\n\tmatchGroup?: string[];\n\t/**\n\t * The gapImg's authored `objectLabel` (QTI 2.1 `objectLabel.GapImg.Attr`,\n\t * QTI 3.0 `object-label`). Names the label for assistive technology when\n\t * the image itself carries no text alternative.\n\t */\n\tobjectLabel?: string;\n\t/**\n\t * Authored `fixed` (a QTI 2.1 attribute on gapImg): pins the choice at its\n\t * authored position when `shuffle` is true.\n\t */\n\tfixed?: boolean;\n\tclasses?: string[];\n\twidth?: number;\n\theight?: number;\n}\n\n/**\n * Gap match data extracted from gapMatchInteraction elements\n */\nexport interface GapMatchData {\n\tgapTexts: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\t/** Authored `fixed` (a QTI 2.1 attribute on gapText): pins the choice under shuffle. */\n\t\tfixed?: boolean;\n\t\tclasses?: string[];\n\t}>;\n\tgapImages: GapMatchImage[];\n\tgaps: string[];\n\t/** QTI `maxAssociations`, with the per-version default for an absent attribute; 0 = no cap. */\n\tmaxAssociations: number;\n\t/** QTI `minAssociations`, the associations a valid response makes; omitted when 0. */\n\tminAssociations?: number;\n\t/** Authored `matchGroup` tokens per gap identifier; present only when a gap authors one. */\n\tgapMatchGroups?: Record<string, string[]>;\n\t/** Gaps authored `required`, which a valid response must fill; present only when one is. */\n\trequiredGaps?: string[];\n\tshuffle: boolean;\n\tprompt: string | null;\n\tpromptText: string;\n}\n\n/**\n * Compile-time proof that what this extractor delivers satisfies the canonical\n * `GapMatchInteractionData` contract: `gaps` are the plain identifiers the\n * pipeline delivers (an object shape here would silently disagree at runtime).\n */\nconst DELIVERED_MATCHES_CONTRACT: DeliveredInteraction<'gapMatchInteraction', GapMatchData> extends GapMatchInteractionData\n\t? true\n\t: false = true;\nvoid DELIVERED_MATCHES_CONTRACT;\n\n/**\n * Put each fixed choice back at its authored index; the others keep the order\n * the (combined) shuffle left them in. No authored `fixed` means no repair and\n * the shuffle result stands unchanged.\n */\nfunction restoreFixedPositions<T extends { fixed?: boolean }>(shuffled: readonly T[], authored: readonly T[]): T[] {\n\tif (!authored.some((choice) => choice.fixed)) return [...shuffled];\n\tconst movable = shuffled.filter((choice) => !choice.fixed);\n\tconst restored: T[] = [];\n\tlet next = 0;\n\tfor (const choice of authored) {\n\t\trestored.push(choice.fixed ? choice : movable[next++]);\n\t}\n\treturn restored;\n}\n\n/**\n * Extracts one draggable image choice from gapImg/qti-gap-img content.\n *\n * `readsFixed` is true for QTI 2.1 content only: `fixed` exists on gapImg (and\n * gapText) in the QTI 2.1 schema alone (fixed.GapImg.Attr / fixed.GapText.Attr);\n * QTI 2.2 and 3.0 define none, so an authored one there is not an attribute of\n * the element and is not read.\n */\nfunction extractGapImage(\n\tgapImg: QTIElement,\n\tutils: Pick<\n\t\tExtractionUtils,\n\t\t| 'getClasses'\n\t\t| 'getNumberAttribute'\n\t\t| 'getBooleanAttribute'\n\t\t| 'getAttribute'\n\t\t| 'getChildrenByTag'\n\t\t| 'getTextContent'\n\t>,\n\treadsFixed: boolean,\n): GapMatchImage {\n\tconst classes = utils.getClasses(gapImg);\n\tconst matchMax = utils.getNumberAttribute(gapImg, 'matchMax', 1);\n\tconst matchMin = utils.getNumberAttribute(gapImg, 'matchMin', 0);\n\tconst matchGroupRaw = utils.getAttribute(gapImg, 'matchGroup', '');\n\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\tconst objectLabel = utils.getAttribute(gapImg, 'objectLabel', '').trim();\n\tconst fixed = readsFixed && utils.getBooleanAttribute(gapImg, 'fixed');\n\n\tlet src = '';\n\tlet alt = '';\n\tlet width: number | undefined;\n\tlet height: number | undefined;\n\n\t// QTI 2.x: <gapImg><object data=\"…\" width height>alt text</object></gapImg>.\n\t// QTI 3.0 allows an <img> or a <picture> (delivered via its <img> fallback):\n\t// <qti-gap-img><img src=\"…\" alt=\"…\" /></qti-gap-img>\n\tconst image = findInteractionImage(gapImg, utils);\n\tif (image?.kind === 'object') {\n\t\tconst obj = image.element;\n\t\tsrc = utils.getAttribute(obj, 'data', '');\n\t\talt = utils.getTextContent(obj);\n\t\tconst w = normalizePixelDimension(utils.getAttribute(obj, 'width', ''));\n\t\tconst h = normalizePixelDimension(utils.getAttribute(obj, 'height', ''));\n\t\tif (w) width = Number(w);\n\t\tif (h) height = Number(h);\n\t} else if (image) {\n\t\tconst img = image.element;\n\t\tsrc = utils.getAttribute(img, 'src', '');\n\t\talt = utils.getAttribute(img, 'alt', '');\n\t\tconst w = normalizePixelDimension(utils.getAttribute(img, 'width', ''));\n\t\tconst h = normalizePixelDimension(utils.getAttribute(img, 'height', ''));\n\t\tif (w) width = Number(w);\n\t\tif (h) height = Number(h);\n\t}\n\n\treturn {\n\t\tidentifier: utils.getAttribute(gapImg, 'identifier', ''),\n\t\tsrc,\n\t\talt,\n\t\tmatchMax,\n\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t...(objectLabel ? { objectLabel } : {}),\n\t\t...(fixed ? { fixed } : {}),\n\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t...(width !== undefined ? { width } : {}),\n\t\t...(height !== undefined ? { height } : {}),\n\t};\n}\n\n/**\n * Standard QTI gap match interaction extractor\n * Handles gapMatchInteraction elements (drag words or images into gaps in text)\n */\nexport const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {\n\tid: 'qti:gap-match-interaction',\n\tname: 'QTI Standard Gap Match Interaction',\n\tpriority: 10,\n\telementTypes: ['gapMatchInteraction'],\n\tdescription: 'Extracts standard QTI gapMatchInteraction (drag words or images into gaps)',\n\n\tcanHandle(element, context) {\n\t\t// All gapMatchInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'gapMatchInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// `fixed` exists on gapText and gapImg in the QTI 2.1 schema alone\n\t\t// (fixed.GapText.Attr / fixed.GapImg.Attr); QTI 2.2 and 3.0 define none on\n\t\t// gap choices, so it is read for QTI 2.1 content only.\n\t\tconst readsFixed = predatesQti22(context);\n\n\t\t// Extract gapText children (draggable text items)\n\t\tconst gapTextElements = utils.getChildrenByTag(element, 'gapText');\n\t\tconst gapTexts = gapTextElements.map((gapText) => {\n\t\t\tconst classes = utils.getClasses(gapText);\n\t\t\tconst matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\t\t\tconst fixed = readsFixed && utils.getBooleanAttribute(gapText, 'fixed');\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(gapText, 'identifier', ''),\n\t\t\t\ttext: utils.getTextContent(gapText),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract gapImg children (draggable image items; QTI 2.x gapImg / QTI 3.0 qti-gap-img)\n\t\tconst gapImgElements = utils.getChildrenByTag(element, 'gapImg');\n\t\tconst gapImages = gapImgElements.map((gapImg) => extractGapImage(gapImg, utils, readsFixed));\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\t// Absent maxAssociations: \"1\" in QTI 2.2 (Table 5.38.3) and QTI 3.0 (Table 5.57.3),\n\t\t// 0 = no restriction. QTI 2.2 added the attribute, so QTI 2.1 content sets no\n\t\t// interaction cap. An explicit value is honoured in every version as leniency.\n\t\tconst maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', predatesQti22(context) ? 0 : 1);\n\t\t// minAssociations (QTI 2.2; QTI 3.0 §5.57.2): \"the minimum number of associations that the\n\t\t// candidate is required to make to form a valid response\"; 0 requires none.\n\t\tconst minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);\n\n\t\t// Shuffle the combined choice pool so words and images interleave, then\n\t\t// restore the split view the renderer consumes.\n\t\tif (gapTexts.length > 0 || gapImages.length > 0) {\n\t\t\tconst authoredTexts = [...gapTexts];\n\t\t\tconst authoredImages = [...gapImages];\n\t\t\tconst combined: Array<\n\t\t\t\t{ type: 'text'; choice: (typeof gapTexts)[number] } | { type: 'image'; choice: GapMatchImage }\n\t\t\t> = [...gapTexts.map((choice) => ({ type: 'text' as const, choice })), ...gapImages.map((choice) => ({ type: 'image' as const, choice }))];\n\t\t\tconst shuffled = maybeShuffle(combined, shuffle, context.shuffleRng);\n\t\t\tgapTexts.length = 0;\n\t\t\tgapImages.length = 0;\n\t\t\tfor (const entry of shuffled) {\n\t\t\t\tif (entry.type === 'text') gapTexts.push(entry.choice);\n\t\t\t\telse gapImages.push(entry.choice);\n\t\t\t}\n\t\t\t// A fixed choice keeps the position it has unshuffled. The pool is\n\t\t\t// presented words first, then images, so that position is its authored\n\t\t\t// index among the choices of its kind.\n\t\t\tgapTexts.splice(0, gapTexts.length, ...restoreFixedPositions(gapTexts, authoredTexts));\n\t\t\tgapImages.splice(0, gapImages.length, ...restoreFixedPositions(gapImages, authoredImages));\n\t\t}\n\n\t\t// Extract prompt (optional) and process gap placeholders.\n\t\t// NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)\n\t\t// rather than inside a `<prompt>` element. Support both patterns.\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tlet prompt: string | null = null;\n\t\tlet promptText = '';\n\t\tconst gaps: string[] = [];\n\n\t\tif (promptElements.length > 0) {\n\t\t\tconst promptElement = promptElements[0];\n\t\t\tprompt = utils.getHtmlContent(promptElement);\n\n\t\t\t// Extract gap elements from prompt children\n\t\t\tconst gapElements = utils.getChildrenByTag(promptElement, 'gap');\n\t\t\tfor (const gap of gapElements) {\n\t\t\t\tgaps.push(utils.getAttribute(gap, 'identifier', ''));\n\t\t\t}\n\n\t\t\t// Replace gap elements with placeholders in the text\n\t\t\t// Derive renderable content only from the already-sanitized prompt. Using\n\t\t\t// outerHTML here would reintroduce event handlers and unsafe URLs that\n\t\t\t// getHtmlContent deliberately removed.\n\t\t\tpromptText = prompt\n\t\t\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\t\t\tconst id = readHtmlAttribute(attrs, 'identifier');\n\t\t\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t\t\t})\n\t\t\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t\t\t.trim();\n\t\t}\n\n\t\t// If gaps were not found inside a <prompt>, search the full interaction body.\n\t\t// This handles items where <gap> elements appear in <p>/<blockquote> siblings of <prompt>.\n\t\tif (gaps.length === 0) {\n\t\t\t// Keep the fallback on the same sanitization boundary as prompt content.\n\t\t\tconst interactionHtml = utils.getHtmlContent(element);\n\t\t\tconst gapIdMatches = Array.from(interactionHtml.matchAll(GAP_ELEMENT_PATTERN));\n\t\t\tfor (const m of gapIdMatches) {\n\t\t\t\tconst id = readHtmlAttribute(m[1] ?? '', 'identifier');\n\t\t\t\tif (id) gaps.push(id);\n\t\t\t}\n\n\t\t\tif (gaps.length > 0 && (!promptText || !promptText.includes('[GAP:'))) {\n\t\t\t\t// Build promptText from the interaction body when gaps are authored outside the prompt.\n\t\t\t\tpromptText = promptTextFromInteractionBody(interactionHtml);\n\t\t\t}\n\t\t}\n\n\t\t// Each gap's authored matchGroup (QTI 2.2/3.0: the identifiers of the choices that may be\n\t\t// matched with it), read from the parsed source wherever the gap sits, with\n\t\t// version-aware attribute names (matchGroup / match-group). A gap authored `required`\n\t\t// \"must be filled by the candidate in order to form a valid response\" (QTI 2.1 gap;\n\t\t// QTI 3.0 §5.55.5).\n\t\tconst gapMatchGroups: Record<string, string[]> = {};\n\t\tconst requiredGaps: string[] = [];\n\t\tconst visitGaps = (node: QTIElement): void => {\n\t\t\tfor (const child of node.childNodes ?? []) {\n\t\t\t\tconst candidate = child as QTIElement;\n\t\t\t\tif (!candidate.rawTagName) continue;\n\t\t\t\tif (utils.matchesTag(candidate, 'gap')) {\n\t\t\t\t\tconst identifier = utils.getAttribute(candidate, 'identifier', '');\n\t\t\t\t\tconst tokens = utils.getAttribute(candidate, 'matchGroup', '').split(/\\s+/).filter(Boolean);\n\t\t\t\t\tif (identifier && tokens.length > 0) gapMatchGroups[identifier] = tokens;\n\t\t\t\t\tif (identifier && utils.getBooleanAttribute(candidate, 'required', false)) requiredGaps.push(identifier);\n\t\t\t\t}\n\t\t\t\tvisitGaps(candidate);\n\t\t\t}\n\t\t};\n\t\tvisitGaps(element);\n\n\t\t// Extract interaction-level classes and attributes\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\tconst choicesContainerWidth = normalizeCssPixelLength(\n\t\t\tutils.getAttribute(element, 'data-choices-container-width', ''),\n\t\t);\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tgapTexts,\n\t\t\tgapImages,\n\t\t\tgaps,\n\t\t\tmaxAssociations,\n\t\t\t...(minAssociations > 0 ? { minAssociations } : {}),\n\t\t\t...(Object.keys(gapMatchGroups).length > 0 ? { gapMatchGroups } : {}),\n\t\t\t...(requiredGaps.length > 0 ? { requiredGaps } : {}),\n\t\t\tshuffle,\n\t\t\tprompt,\n\t\t\tpromptText,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(choicesContainerWidth ? { choicesContainerWidth } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate draggable choices exist (gapText or gapImg — QTI 2.1/2.2/3.0 allow both)\n\t\tif ((!data.gapTexts || data.gapTexts.length === 0) && (!data.gapImages || data.gapImages.length === 0)) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gapText or gapImg');\n\t\t}\n\n\t\t// Validate gaps exist\n\t\tif (!data.gaps || data.gaps.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gap in the prompt');\n\t\t}\n\n\t\t// Identifiers of gapText and gapImg choices share one response-identifier space:\n\t\t// a collision would make \"wordId gapId\" response pairs ambiguous.\n\t\tconst choiceIdentifiers = new Set<string>();\n\t\tconst validateChoiceIdentifier = (identifier: string, kind: string): void => {\n\t\t\tif (!identifier) {\n\t\t\t\terrors.push(`All ${kind} choices must have an identifier`);\n\t\t\t} else if (choiceIdentifiers.has(identifier)) {\n\t\t\t\terrors.push(`Duplicate choice identifier: ${identifier}`);\n\t\t\t} else {\n\t\t\t\tchoiceIdentifiers.add(identifier);\n\t\t\t}\n\t\t};\n\n\t\t// Validate gapText identifiers\n\t\tif (data.gapTexts) {\n\t\t\tfor (const gapText of data.gapTexts) {\n\t\t\t\tvalidateChoiceIdentifier(gapText.identifier, 'gapText');\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (gapText.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate gapImg identifiers and image sources\n\t\tif (data.gapImages) {\n\t\t\tfor (const gapImage of data.gapImages) {\n\t\t\t\tvalidateChoiceIdentifier(gapImage.identifier, 'gapImg');\n\n\t\t\t\tif (gapImage.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for gapImg ${gapImage.identifier}`);\n\t\t\t\t}\n\t\t\t\tif (!gapImage.src) {\n\t\t\t\t\terrors.push(`gapImg ${gapImage.identifier} must reference an image source`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate gap identifiers\n\t\tif (data.gaps) {\n\t\t\tvalidateUniqueIdentifiers(data.gaps, errors, { plural: 'gaps', noun: 'gap' });\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -13,6 +13,12 @@ export interface ImageData {
|
|
|
13
13
|
content?: string;
|
|
14
14
|
width?: string;
|
|
15
15
|
height?: string;
|
|
16
|
+
/** Short text alternative extracted from the QTI source. */
|
|
17
|
+
alt?: string;
|
|
18
|
+
/** Longer description for complex images (SVG <desc>, aria description). */
|
|
19
|
+
altDescription?: string;
|
|
20
|
+
/** True only when the author explicitly marked the image decorative (`<img alt="">`). */
|
|
21
|
+
decorative?: boolean;
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* Graphic associate data extracted from graphicAssociateInteraction elements
|
|
@@ -21,6 +27,11 @@ export interface GraphicAssociateData {
|
|
|
21
27
|
imageData: ImageData | null;
|
|
22
28
|
associableHotspots: Array<{
|
|
23
29
|
identifier: string;
|
|
30
|
+
/**
|
|
31
|
+
* The hotspot's authored text (`hotspotLabel` or element text). Empty when
|
|
32
|
+
* the author gave none: the renderer then names it by position. Never the
|
|
33
|
+
* identifier, which can leak the answer key to assistive technology.
|
|
34
|
+
*/
|
|
24
35
|
label: string;
|
|
25
36
|
shape: string;
|
|
26
37
|
coords: string;
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracts data from graphicAssociateInteraction elements (associate items on image)
|
|
5
5
|
*/
|
|
6
|
+
import { validateUniqueIdentifiers } from '../../extraction/utils.js';
|
|
6
7
|
import { normalizePixelDimension } from '../../security/styleValues.js';
|
|
8
|
+
import { extractImageAlternative, imgAlternativeSource } from '../shared/imageAlt.js';
|
|
9
|
+
import { findInteractionImage } from '../shared/interactionImage.js';
|
|
7
10
|
/**
|
|
8
11
|
* Standard QTI graphic associate interaction extractor
|
|
9
12
|
* Handles graphicAssociateInteraction elements (creating associations between hotspots)
|
|
@@ -19,36 +22,53 @@ export const standardGraphicAssociateExtractor = {
|
|
|
19
22
|
return context.utils.matchesTag(element, 'graphicAssociateInteraction');
|
|
20
23
|
},
|
|
21
24
|
extract(element, context) {
|
|
22
|
-
const { utils } = context;
|
|
23
|
-
// Extract image data from object element
|
|
24
|
-
|
|
25
|
+
const { utils, dom } = context;
|
|
26
|
+
// Extract image data from the object element (QTI 2.x) or an img element
|
|
27
|
+
// (QTI 3.0, plain or as a <picture>'s fallback img)
|
|
28
|
+
const interactionImage = findInteractionImage(element, utils);
|
|
25
29
|
let imageData = null;
|
|
26
|
-
if (
|
|
27
|
-
const objectElement =
|
|
30
|
+
if (interactionImage?.kind === 'object') {
|
|
31
|
+
const objectElement = interactionImage.element;
|
|
28
32
|
const type = utils.getAttribute(objectElement, 'type', '');
|
|
29
33
|
const data = utils.getAttribute(objectElement, 'data', '');
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
// The stage's pixel space: the authored width/height, when declared. Without
|
|
35
|
+
// them the renderer stages the raster at its natural size; a default here
|
|
36
|
+
// would silently place hotspots in a guessed space.
|
|
37
|
+
const width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''));
|
|
38
|
+
const height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''));
|
|
39
|
+
const content = type.startsWith('image/svg') ? utils.getHtmlContent(objectElement) : '';
|
|
40
|
+
if (/<svg[\s>]/i.test(content)) {
|
|
41
|
+
// Inline SVG: <object type="image/svg+xml"><svg>...</svg></object>
|
|
35
42
|
imageData = {
|
|
36
43
|
type: 'svg',
|
|
37
44
|
content,
|
|
38
45
|
width,
|
|
39
46
|
height,
|
|
47
|
+
...extractImageAlternative(objectElement, utils, dom, { inlineSvgContent: content }),
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
else {
|
|
43
|
-
// External image reference
|
|
51
|
+
// External image (or SVG file) reference; the <object>'s text is its alternative
|
|
44
52
|
imageData = {
|
|
45
53
|
type: 'image',
|
|
46
54
|
src: data,
|
|
47
55
|
width,
|
|
48
56
|
height,
|
|
57
|
+
...extractImageAlternative(objectElement, utils, dom),
|
|
49
58
|
};
|
|
50
59
|
}
|
|
51
60
|
}
|
|
61
|
+
else if (interactionImage) {
|
|
62
|
+
// QTI 3.0 <img>: the alt attribute is the text alternative (alt="" = decorative)
|
|
63
|
+
const imgElement = interactionImage.element;
|
|
64
|
+
imageData = {
|
|
65
|
+
type: 'image',
|
|
66
|
+
src: utils.getAttribute(imgElement, 'src', ''),
|
|
67
|
+
width: normalizePixelDimension(utils.getAttribute(imgElement, 'width', '')),
|
|
68
|
+
height: normalizePixelDimension(utils.getAttribute(imgElement, 'height', '')),
|
|
69
|
+
...extractImageAlternative(imgElement, utils, dom, imgAlternativeSource(imgElement)),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
52
72
|
// Extract associableHotspot children
|
|
53
73
|
const hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');
|
|
54
74
|
const associableHotspots = hotspotElements.map((hotspot) => {
|
|
@@ -60,9 +80,9 @@ export const standardGraphicAssociateExtractor = {
|
|
|
60
80
|
const matchMin = utils.getNumberAttribute(hotspot, 'matchMin', 0);
|
|
61
81
|
const matchGroupRaw = utils.getAttribute(hotspot, 'matchGroup', '');
|
|
62
82
|
const matchGroup = matchGroupRaw.split(/\s+/).filter(Boolean);
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
const label =
|
|
83
|
+
// The authored label: hotspotLabel (QTI 2.2 / 3.0), else the hotspot's text.
|
|
84
|
+
// No identifier fallback — identifiers can reveal the answer key.
|
|
85
|
+
const label = utils.getAttribute(hotspot, 'hotspotLabel', '').trim() || utils.getTextContent(hotspot).trim();
|
|
66
86
|
return {
|
|
67
87
|
identifier,
|
|
68
88
|
label,
|
|
@@ -107,17 +127,8 @@ export const standardGraphicAssociateExtractor = {
|
|
|
107
127
|
}
|
|
108
128
|
// Validate hotspot identifiers and coords
|
|
109
129
|
if (data.associableHotspots && data.associableHotspots.length > 0) {
|
|
110
|
-
|
|
130
|
+
validateUniqueIdentifiers(data.associableHotspots, errors, { plural: 'hotspots', noun: 'hotspot' });
|
|
111
131
|
for (const hotspot of data.associableHotspots) {
|
|
112
|
-
if (!hotspot.identifier) {
|
|
113
|
-
errors.push('All hotspots must have an identifier');
|
|
114
|
-
}
|
|
115
|
-
else if (identifiers.has(hotspot.identifier)) {
|
|
116
|
-
errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
identifiers.add(hotspot.identifier);
|
|
120
|
-
}
|
|
121
132
|
if (!hotspot.coords) {
|
|
122
133
|
errors.push(`Hotspot ${hotspot.identifier} must have coords`);
|
|
123
134
|
}
|