@pie-qti/item-player 1.0.0-beta.4 → 1.0.0-beta.6
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 +34 -6
- 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 +390 -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-BUFpUrJP.js +3792 -0
- package/dist/element-class-BUFpUrJP.js.map +1 -0
- package/dist/element-class.d.ts +34 -1
- package/dist/element-class.js +1 -1
- package/dist/element.js +2 -3
- 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 +18 -14
- 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 +9 -3
- 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 +20 -19
- 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
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* Extracts data from selectPointInteraction elements (click point on image)
|
|
5
5
|
*/
|
|
6
6
|
import { normalizePixelDimension } from '../../security/styleValues.js';
|
|
7
|
+
import { extractImageAlternative, imgAlternativeSource } from '../shared/imageAlt.js';
|
|
8
|
+
import { findInteractionImage } from '../shared/interactionImage.js';
|
|
9
|
+
import { predatesQti22, unrestrictedLimitDefault } from '../shared/specDefaults.js';
|
|
7
10
|
/**
|
|
8
11
|
* Standard QTI select point interaction extractor
|
|
9
12
|
* Handles selectPointInteraction elements (clicking points on an image)
|
|
@@ -19,52 +22,61 @@ export const standardSelectPointExtractor = {
|
|
|
19
22
|
return context.utils.matchesTag(element, 'selectPointInteraction');
|
|
20
23
|
},
|
|
21
24
|
extract(element, context) {
|
|
22
|
-
const { utils } = context;
|
|
23
|
-
// Extract image data from object or img element
|
|
24
|
-
|
|
25
|
-
const
|
|
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);
|
|
26
29
|
let imageData = null;
|
|
27
|
-
if (
|
|
28
|
-
const objectElement =
|
|
30
|
+
if (interactionImage?.kind === 'object') {
|
|
31
|
+
const objectElement = interactionImage.element;
|
|
29
32
|
const type = utils.getAttribute(objectElement, 'type', '');
|
|
30
33
|
const data = utils.getAttribute(objectElement, 'data', '');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 points 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>
|
|
36
42
|
imageData = {
|
|
37
43
|
type: 'svg',
|
|
38
44
|
content,
|
|
39
45
|
width,
|
|
40
46
|
height,
|
|
47
|
+
...extractImageAlternative(objectElement, utils, dom, { inlineSvgContent: content }),
|
|
41
48
|
};
|
|
42
49
|
}
|
|
43
50
|
else {
|
|
44
|
-
// External image reference
|
|
51
|
+
// External image (or SVG file) reference; the <object>'s text is its alternative
|
|
45
52
|
imageData = {
|
|
46
53
|
type: 'image',
|
|
47
54
|
src: data,
|
|
48
55
|
width,
|
|
49
56
|
height,
|
|
57
|
+
...extractImageAlternative(objectElement, utils, dom),
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
|
-
else if (
|
|
54
|
-
//
|
|
55
|
-
const imgElement =
|
|
61
|
+
else if (interactionImage) {
|
|
62
|
+
// QTI 3.0 <img>: the alt attribute is the text alternative (alt="" = decorative)
|
|
63
|
+
const imgElement = interactionImage.element;
|
|
56
64
|
const src = utils.getAttribute(imgElement, 'src', '');
|
|
57
|
-
const width = normalizePixelDimension(utils.getAttribute(imgElement, 'width', '')
|
|
58
|
-
const height = normalizePixelDimension(utils.getAttribute(imgElement, 'height', '')
|
|
65
|
+
const width = normalizePixelDimension(utils.getAttribute(imgElement, 'width', ''));
|
|
66
|
+
const height = normalizePixelDimension(utils.getAttribute(imgElement, 'height', ''));
|
|
59
67
|
imageData = {
|
|
60
68
|
type: 'image',
|
|
61
69
|
src,
|
|
62
70
|
width,
|
|
63
71
|
height,
|
|
72
|
+
...extractImageAlternative(imgElement, utils, dom, imgAlternativeSource(imgElement)),
|
|
64
73
|
};
|
|
65
74
|
}
|
|
66
|
-
// Extract attributes
|
|
67
|
-
|
|
75
|
+
// Extract attributes. Absent maxChoices: "0" (no restriction) in QTI 2.2 (Table 5.95.2)
|
|
76
|
+
// and QTI 3.0 (Table 5.128.2), resolved to 1 for a single-cardinality response, which
|
|
77
|
+
// holds one point. QTI 2.1 keeps 1: its information model (`maxChoices [1] = 1`) and
|
|
78
|
+
// its XSD (default "0") disagree, so 2.1 has no clear default to apply.
|
|
79
|
+
const maxChoices = utils.getNumberAttribute(element, 'maxChoices', predatesQti22(context) ? 1 : unrestrictedLimitDefault(context));
|
|
68
80
|
const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
|
|
69
81
|
// Extract prompt (optional)
|
|
70
82
|
const promptElements = utils.getChildrenByTag(element, 'prompt');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/select-point/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAuBxE;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAsC;IAC9E,EAAE,EAAE,8BAA8B;IAClC,IAAI,EAAE,uCAAuC;IAC7C,QAAQ,EAAE,EAAE;IACZ,YAA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C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI selectPointInteraction extractor\n *\n * Extracts data from selectPointInteraction elements (click point on image)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\n\n/**\n * Image data for select point interaction\n */\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n}\n\n/**\n * Select point data extracted from selectPointInteraction elements\n */\nexport interface SelectPointData {\n\timageData: ImageData | null;\n\tmaxChoices: number;\n\tminChoices: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI select point interaction extractor\n * Handles selectPointInteraction elements (clicking points on an image)\n */\nexport const standardSelectPointExtractor: ElementExtractor<SelectPointData> = {\n\tid: 'qti:select-point-interaction',\n\tname: 'QTI Standard Select Point Interaction',\n\tpriority: 10,\n\telementTypes: ['selectPointInteraction'],\n\tdescription: 'Extracts standard QTI selectPointInteraction (click point on image)',\n\n\tcanHandle(element, context) {\n\t\t// All selectPointInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'selectPointInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract image data from object or img element\n\t\tconst objectElements = utils.getChildrenByTag(element, 'object');\n\t\tconst imgElements = utils.getChildrenByTag(element, 'img');\n\t\tlet imageData: ImageData | null = null;\n\n\t\tif (objectElements.length > 0) {\n\t\t\tconst objectElement = objectElements[0];\n\t\t\tconst type = utils.getAttribute(objectElement, 'type', '');\n\t\t\tconst data = utils.getAttribute(objectElement, 'data', '');\n\t\t\tconst width = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(objectElement, 'width', ''),\n\t\t\t\t'500',\n\t\t\t);\n\t\t\tconst height = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(objectElement, 'height', ''),\n\t\t\t\t'300',\n\t\t\t);\n\n\t\t\tif (type.startsWith('image/svg')) {\n\t\t\t\t// Extract inline SVG content - get full content including <svg> tag\n\t\t\t\tconst content = utils.getHtmlContent(objectElement);\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'svg',\n\t\t\t\t\tcontent,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// External image reference\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'image',\n\t\t\t\t\tsrc: data,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t}\n\t\t} else if (imgElements.length > 0) {\n\t\t\t// Handle img element as fallback\n\t\t\tconst imgElement = imgElements[0];\n\t\t\tconst src = utils.getAttribute(imgElement, 'src', '');\n\t\t\tconst width = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(imgElement, 'width', ''),\n\t\t\t\t'500',\n\t\t\t);\n\t\t\tconst height = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(imgElement, 'height', ''),\n\t\t\t\t'300',\n\t\t\t);\n\t\t\timageData = {\n\t\t\t\ttype: 'image',\n\t\t\t\tsrc,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t};\n\t\t}\n\n\t\t// Extract attributes\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tmaxChoices,\n\t\t\tminChoices,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate image data\n\t\tif (!data.imageData) {\n\t\t\twarnings.push('selectPointInteraction has no image data');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('selectPointInteraction must have an image URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('selectPointInteraction must have SVG content');\n\t\t}\n\n\t\t// Validate maxChoices — 0 means unlimited per QTI spec\n\t\tif (data.maxChoices < 0) {\n\t\t\terrors.push('maxChoices must be non-negative');\n\t\t}\n\n\t\t// Validate minChoices\n\t\tif (data.minChoices < 0) {\n\t\t\terrors.push('minChoices must be non-negative');\n\t\t}\n\n\t\t// Validate minChoices <= maxChoices (skip when maxChoices=0, meaning unlimited)\n\t\tif (data.maxChoices > 0 && data.minChoices > data.maxChoices) {\n\t\t\terrors.push(`minChoices (${data.minChoices}) must be less than or equal to maxChoices (${data.maxChoices})`);\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\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/select-point/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AA6BpF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAsC;IAC9E,EAAE,EAAE,8BAA8B;IAClC,IAAI,EAAE,uCAAuC;IAC7C,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,wBAAwB,CAAC;IACxC,W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CAAC;QAED,gFAAgF;QAChF,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,UAAU,+CAA+C,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QAC9G,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;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI selectPointInteraction extractor\n *\n * Extracts data from selectPointInteraction elements (click point on image)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\nimport { extractImageAlternative, imgAlternativeSource } from '../shared/imageAlt.js';\nimport { findInteractionImage } from '../shared/interactionImage.js';\nimport { predatesQti22, unrestrictedLimitDefault } from '../shared/specDefaults.js';\n\n/**\n * Image data for select point interaction\n */\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n\t/** Short text alternative extracted from the QTI source. */\n\talt?: string;\n\t/** Longer description for complex images (SVG <desc>, aria description). */\n\taltDescription?: string;\n\t/** True only when the author explicitly marked the image decorative (`<img alt=\"\">`). */\n\tdecorative?: boolean;\n}\n\n/**\n * Select point data extracted from selectPointInteraction elements\n */\nexport interface SelectPointData {\n\timageData: ImageData | null;\n\tmaxChoices: number;\n\tminChoices: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI select point interaction extractor\n * Handles selectPointInteraction elements (clicking points on an image)\n */\nexport const standardSelectPointExtractor: ElementExtractor<SelectPointData> = {\n\tid: 'qti:select-point-interaction',\n\tname: 'QTI Standard Select Point Interaction',\n\tpriority: 10,\n\telementTypes: ['selectPointInteraction'],\n\tdescription: 'Extracts standard QTI selectPointInteraction (click point on image)',\n\n\tcanHandle(element, context) {\n\t\t// All selectPointInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'selectPointInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils, dom } = context;\n\n\t\t// Extract image data from the object element (QTI 2.x) or an img element\n\t\t// (QTI 3.0, plain or as a <picture>'s fallback img)\n\t\tconst interactionImage = findInteractionImage(element, utils);\n\t\tlet imageData: ImageData | null = null;\n\n\t\tif (interactionImage?.kind === 'object') {\n\t\t\tconst objectElement = interactionImage.element;\n\t\t\tconst type = utils.getAttribute(objectElement, 'type', '');\n\t\t\tconst data = utils.getAttribute(objectElement, 'data', '');\n\t\t\t// The stage's pixel space: the authored width/height, when declared. Without\n\t\t\t// them the renderer stages the raster at its natural size; a default here\n\t\t\t// would silently place points in a guessed space.\n\t\t\tconst width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''));\n\t\t\tconst height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''));\n\t\t\tconst content = type.startsWith('image/svg') ? utils.getHtmlContent(objectElement) : '';\n\n\t\t\tif (/<svg[\\s>]/i.test(content)) {\n\t\t\t\t// Inline SVG: <object type=\"image/svg+xml\"><svg>...</svg></object>\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'svg',\n\t\t\t\t\tcontent,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\t...extractImageAlternative(objectElement, utils, dom, { inlineSvgContent: content }),\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// External image (or SVG file) reference; the <object>'s text is its alternative\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'image',\n\t\t\t\t\tsrc: data,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\t...extractImageAlternative(objectElement, utils, dom),\n\t\t\t\t};\n\t\t\t}\n\t\t} else if (interactionImage) {\n\t\t\t// QTI 3.0 <img>: the alt attribute is the text alternative (alt=\"\" = decorative)\n\t\t\tconst imgElement = interactionImage.element;\n\t\t\tconst src = utils.getAttribute(imgElement, 'src', '');\n\t\t\tconst width = normalizePixelDimension(utils.getAttribute(imgElement, 'width', ''));\n\t\t\tconst height = normalizePixelDimension(utils.getAttribute(imgElement, 'height', ''));\n\t\t\timageData = {\n\t\t\t\ttype: 'image',\n\t\t\t\tsrc,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\t...extractImageAlternative(imgElement, utils, dom, imgAlternativeSource(imgElement)),\n\t\t\t};\n\t\t}\n\n\t\t// Extract attributes. Absent maxChoices: \"0\" (no restriction) in QTI 2.2 (Table 5.95.2)\n\t\t// and QTI 3.0 (Table 5.128.2), resolved to 1 for a single-cardinality response, which\n\t\t// holds one point. QTI 2.1 keeps 1: its information model (`maxChoices [1] = 1`) and\n\t\t// its XSD (default \"0\") disagree, so 2.1 has no clear default to apply.\n\t\tconst maxChoices = utils.getNumberAttribute(\n\t\t\telement,\n\t\t\t'maxChoices',\n\t\t\tpredatesQti22(context) ? 1 : unrestrictedLimitDefault(context),\n\t\t);\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tmaxChoices,\n\t\t\tminChoices,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate image data\n\t\tif (!data.imageData) {\n\t\t\twarnings.push('selectPointInteraction has no image data');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('selectPointInteraction must have an image URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('selectPointInteraction must have SVG content');\n\t\t}\n\n\t\t// Validate maxChoices — 0 means unlimited per QTI spec\n\t\tif (data.maxChoices < 0) {\n\t\t\terrors.push('maxChoices must be non-negative');\n\t\t}\n\n\t\t// Validate minChoices\n\t\tif (data.minChoices < 0) {\n\t\t\terrors.push('minChoices must be non-negative');\n\t\t}\n\n\t\t// Validate minChoices <= maxChoices (skip when maxChoices=0, meaning unlimited)\n\t\tif (data.maxChoices > 0 && data.minChoices > data.maxChoices) {\n\t\t\terrors.push(`minChoices (${data.minChoices}) must be less than or equal to maxChoices (${data.maxChoices})`);\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\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-alternative extraction for the graphic interactions' image data.
|
|
3
|
+
*
|
|
4
|
+
* Every graphic interaction (hotspot, graphic order/associate/gap match,
|
|
5
|
+
* select point, position object, drawing) draws its response surface on an
|
|
6
|
+
* image authored as an `<object>` (QTI 2.x) or `<img>` (QTI 3.0 content).
|
|
7
|
+
* The alternative text lives in different places per encoding:
|
|
8
|
+
*
|
|
9
|
+
* - `aria-label` / `aria-labelledby` / `aria-describedby` / `aria-description`
|
|
10
|
+
* on the image element itself (labelledby/describedby ids resolve inside the
|
|
11
|
+
* item, mirroring `interactionAccessibility`, because renderers draw in
|
|
12
|
+
* shadow roots that id references cannot cross);
|
|
13
|
+
* - the `<object>` element's fallback text content (QTI 2.x convention), but
|
|
14
|
+
* only for external images — an inline SVG's text content is its drawing;
|
|
15
|
+
* - inline SVG `<title>` (name) and `<desc>` (long description);
|
|
16
|
+
* - the `alt` attribute of an `<img>` (QTI 3.0). An *empty* `alt` attribute is
|
|
17
|
+
* an explicit author statement that the image is decorative.
|
|
18
|
+
*
|
|
19
|
+
* Authored aria naming wins over the other sources, as in accessible name
|
|
20
|
+
* computation. An `<object>` with no alternative is an authoring omission, not
|
|
21
|
+
* a decorative image, so `decorative` is never inferred from it; renderers fall
|
|
22
|
+
* back to a localized generic name (never a QTI identifier).
|
|
23
|
+
*/
|
|
24
|
+
import type { QTIElement } from './types.js';
|
|
25
|
+
export interface ImageAlternative {
|
|
26
|
+
/** Short text alternative for the image. */
|
|
27
|
+
alt?: string;
|
|
28
|
+
/** Longer description for complex images (SVG `<desc>`, aria description). */
|
|
29
|
+
altDescription?: string;
|
|
30
|
+
/** True only when the author explicitly marked the image decorative (`alt=""`). */
|
|
31
|
+
decorative?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ImageAlternativeSource {
|
|
34
|
+
/** The image element's inline SVG markup, when the image is inline SVG. */
|
|
35
|
+
inlineSvgContent?: string;
|
|
36
|
+
/** The `alt` attribute of an `<img>` element; omit for `<object>` elements. */
|
|
37
|
+
explicitAlt?: string;
|
|
38
|
+
}
|
|
39
|
+
type ExtractUtils = {
|
|
40
|
+
getTextContent: (element: QTIElement) => string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The alternative source of a QTI 3.0 `<img>`: its `alt` attribute when present
|
|
44
|
+
* (an empty one marks the image decorative), otherwise nothing authored.
|
|
45
|
+
*/
|
|
46
|
+
export declare function imgAlternativeSource(img: QTIElement): ImageAlternativeSource;
|
|
47
|
+
/**
|
|
48
|
+
* Extract the text alternative for a graphic interaction's image element.
|
|
49
|
+
*
|
|
50
|
+
* `contextRoot` is the element id references (`aria-labelledby` etc.) resolve
|
|
51
|
+
* against — pass the extraction context's `dom`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractImageAlternative(imageElement: QTIElement, utils: ExtractUtils, contextRoot: QTIElement, source?: ImageAlternativeSource): ImageAlternative;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-alternative extraction for the graphic interactions' image data.
|
|
3
|
+
*
|
|
4
|
+
* Every graphic interaction (hotspot, graphic order/associate/gap match,
|
|
5
|
+
* select point, position object, drawing) draws its response surface on an
|
|
6
|
+
* image authored as an `<object>` (QTI 2.x) or `<img>` (QTI 3.0 content).
|
|
7
|
+
* The alternative text lives in different places per encoding:
|
|
8
|
+
*
|
|
9
|
+
* - `aria-label` / `aria-labelledby` / `aria-describedby` / `aria-description`
|
|
10
|
+
* on the image element itself (labelledby/describedby ids resolve inside the
|
|
11
|
+
* item, mirroring `interactionAccessibility`, because renderers draw in
|
|
12
|
+
* shadow roots that id references cannot cross);
|
|
13
|
+
* - the `<object>` element's fallback text content (QTI 2.x convention), but
|
|
14
|
+
* only for external images — an inline SVG's text content is its drawing;
|
|
15
|
+
* - inline SVG `<title>` (name) and `<desc>` (long description);
|
|
16
|
+
* - the `alt` attribute of an `<img>` (QTI 3.0). An *empty* `alt` attribute is
|
|
17
|
+
* an explicit author statement that the image is decorative.
|
|
18
|
+
*
|
|
19
|
+
* Authored aria naming wins over the other sources, as in accessible name
|
|
20
|
+
* computation. An `<object>` with no alternative is an authoring omission, not
|
|
21
|
+
* a decorative image, so `decorative` is never inferred from it; renderers fall
|
|
22
|
+
* back to a localized generic name (never a QTI identifier).
|
|
23
|
+
*/
|
|
24
|
+
import { interactionAccessibility } from '../../extraction/interactionAccessibility.js';
|
|
25
|
+
function normalizeText(text) {
|
|
26
|
+
return (text ?? '').replace(/\s+/g, ' ').trim();
|
|
27
|
+
}
|
|
28
|
+
/** First captured group of `regex` in `content`, tag-stripped and whitespace-collapsed. */
|
|
29
|
+
function markupText(content, regex) {
|
|
30
|
+
const match = regex.exec(content);
|
|
31
|
+
return normalizeText(match?.[1]?.replace(/<[^>]*>/g, ''));
|
|
32
|
+
}
|
|
33
|
+
/** The element's text outside any `<svg>` child: an `<object>`'s fallback text beside inline SVG. */
|
|
34
|
+
function textOutsideSvg(element) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
for (const child of element.childNodes ?? []) {
|
|
37
|
+
if (child.nodeType === 1 && child.rawTagName?.toLowerCase() === 'svg')
|
|
38
|
+
continue;
|
|
39
|
+
parts.push(child.textContent ?? '');
|
|
40
|
+
}
|
|
41
|
+
return normalizeText(parts.join(' '));
|
|
42
|
+
}
|
|
43
|
+
function compact(alt, altDescription) {
|
|
44
|
+
return {
|
|
45
|
+
...(alt ? { alt } : {}),
|
|
46
|
+
...(altDescription ? { altDescription } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The alternative source of a QTI 3.0 `<img>`: its `alt` attribute when present
|
|
51
|
+
* (an empty one marks the image decorative), otherwise nothing authored.
|
|
52
|
+
*/
|
|
53
|
+
export function imgAlternativeSource(img) {
|
|
54
|
+
return img.hasAttribute('alt') ? { explicitAlt: img.getAttribute('alt') ?? '' } : {};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Extract the text alternative for a graphic interaction's image element.
|
|
58
|
+
*
|
|
59
|
+
* `contextRoot` is the element id references (`aria-labelledby` etc.) resolve
|
|
60
|
+
* against — pass the extraction context's `dom`.
|
|
61
|
+
*/
|
|
62
|
+
export function extractImageAlternative(imageElement, utils, contextRoot, source = {}) {
|
|
63
|
+
const accessibility = interactionAccessibility(imageElement, contextRoot);
|
|
64
|
+
if (source.explicitAlt !== undefined) {
|
|
65
|
+
// QTI 3.0 <img>: alt="" is the author's explicit "decorative" marker,
|
|
66
|
+
// unless the author also named the image through aria.
|
|
67
|
+
const alt = accessibility?.label || normalizeText(source.explicitAlt);
|
|
68
|
+
if (!alt)
|
|
69
|
+
return { decorative: true };
|
|
70
|
+
return compact(alt, accessibility?.description);
|
|
71
|
+
}
|
|
72
|
+
if (source.inlineSvgContent !== undefined) {
|
|
73
|
+
// Inline SVG: aria name, else the SVG's <title>, else the <object>'s own
|
|
74
|
+
// fallback text beside the <svg> (never the drawing's internal text).
|
|
75
|
+
const svg = source.inlineSvgContent;
|
|
76
|
+
return compact(accessibility?.label ||
|
|
77
|
+
markupText(svg, /<title\b[^>]*>([\s\S]*?)<\/title>/i) ||
|
|
78
|
+
textOutsideSvg(imageElement), accessibility?.description || markupText(svg, /<desc\b[^>]*>([\s\S]*?)<\/desc>/i));
|
|
79
|
+
}
|
|
80
|
+
// QTI 2.x <object> referencing an external image: aria name, else the
|
|
81
|
+
// element's fallback text content. Nothing found is an omission.
|
|
82
|
+
return compact(accessibility?.label || normalizeText(utils.getTextContent(imageElement)), accessibility?.description);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=imageAlt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageAlt.js","sourceRoot":"","sources":["../../../src/interactions/shared/imageAlt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AAuBxF,SAAS,aAAa,CAAC,IAA+B;IACrD,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACjD,CAAC;AAED,2FAA2F;AAC3F,SAAS,UAAU,CAAC,OAAe,EAAE,KAAa;IACjD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,qGAAqG;AACrG,SAAS,cAAc,CAAC,OAAmB;IAC1C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC9C,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,IAAK,KAAoB,CAAC,UAAU,EAAE,WAAW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,CAAC;QAC3C,yEAAyE;QACzE,sEAAsE;QACtE,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC;QACpC,OAAO,OAAO,CACb,aAAa,EAAE,KAAK;YACnB,UAAU,CAAC,GAAG,EAAE,oCAAoC,CAAC;YACrD,cAAc,CAAC,YAAY,CAAC,EAC7B,aAAa,EAAE,WAAW,IAAI,UAAU,CAAC,GAAG,EAAE,kCAAkC,CAAC,CACjF,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,iEAAiE;IACjE,OAAO,OAAO,CACb,aAAa,EAAE,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,EACzE,aAAa,EAAE,WAAW,CAC1B,CAAC;AACH,CAAC","sourcesContent":["/**\n * Text-alternative extraction for the graphic interactions' image data.\n *\n * Every graphic interaction (hotspot, graphic order/associate/gap match,\n * select point, position object, drawing) draws its response surface on an\n * image authored as an `<object>` (QTI 2.x) or `<img>` (QTI 3.0 content).\n * The alternative text lives in different places per encoding:\n *\n * - `aria-label` / `aria-labelledby` / `aria-describedby` / `aria-description`\n * on the image element itself (labelledby/describedby ids resolve inside the\n * item, mirroring `interactionAccessibility`, because renderers draw in\n * shadow roots that id references cannot cross);\n * - the `<object>` element's fallback text content (QTI 2.x convention), but\n * only for external images — an inline SVG's text content is its drawing;\n * - inline SVG `<title>` (name) and `<desc>` (long description);\n * - the `alt` attribute of an `<img>` (QTI 3.0). An *empty* `alt` attribute is\n * an explicit author statement that the image is decorative.\n *\n * Authored aria naming wins over the other sources, as in accessible name\n * computation. An `<object>` with no alternative is an authoring omission, not\n * a decorative image, so `decorative` is never inferred from it; renderers fall\n * back to a localized generic name (never a QTI identifier).\n */\n\nimport { interactionAccessibility } from '../../extraction/interactionAccessibility.js';\nimport type { QTIElement } from './types.js';\n\nexport interface ImageAlternative {\n\t/** Short text alternative for the image. */\n\talt?: string;\n\t/** Longer description for complex images (SVG `<desc>`, aria description). */\n\taltDescription?: string;\n\t/** True only when the author explicitly marked the image decorative (`alt=\"\"`). */\n\tdecorative?: boolean;\n}\n\nexport interface ImageAlternativeSource {\n\t/** The image element's inline SVG markup, when the image is inline SVG. */\n\tinlineSvgContent?: string;\n\t/** The `alt` attribute of an `<img>` element; omit for `<object>` elements. */\n\texplicitAlt?: string;\n}\n\ntype ExtractUtils = {\n\tgetTextContent: (element: QTIElement) => string;\n};\n\nfunction normalizeText(text: string | null | undefined): string {\n\treturn (text ?? '').replace(/\\s+/g, ' ').trim();\n}\n\n/** First captured group of `regex` in `content`, tag-stripped and whitespace-collapsed. */\nfunction markupText(content: string, regex: RegExp): string {\n\tconst match = regex.exec(content);\n\treturn normalizeText(match?.[1]?.replace(/<[^>]*>/g, ''));\n}\n\n/** The element's text outside any `<svg>` child: an `<object>`'s fallback text beside inline SVG. */\nfunction textOutsideSvg(element: QTIElement): string {\n\tconst parts: string[] = [];\n\tfor (const child of element.childNodes ?? []) {\n\t\tif (child.nodeType === 1 && (child as QTIElement).rawTagName?.toLowerCase() === 'svg') continue;\n\t\tparts.push(child.textContent ?? '');\n\t}\n\treturn normalizeText(parts.join(' '));\n}\n\nfunction compact(alt: string | undefined, altDescription: string | undefined): ImageAlternative {\n\treturn {\n\t\t...(alt ? { alt } : {}),\n\t\t...(altDescription ? { altDescription } : {}),\n\t};\n}\n\n/**\n * The alternative source of a QTI 3.0 `<img>`: its `alt` attribute when present\n * (an empty one marks the image decorative), otherwise nothing authored.\n */\nexport function imgAlternativeSource(img: QTIElement): ImageAlternativeSource {\n\treturn img.hasAttribute('alt') ? { explicitAlt: img.getAttribute('alt') ?? '' } : {};\n}\n\n/**\n * Extract the text alternative for a graphic interaction's image element.\n *\n * `contextRoot` is the element id references (`aria-labelledby` etc.) resolve\n * against — pass the extraction context's `dom`.\n */\nexport function extractImageAlternative(\n\timageElement: QTIElement,\n\tutils: ExtractUtils,\n\tcontextRoot: QTIElement,\n\tsource: ImageAlternativeSource = {},\n): ImageAlternative {\n\tconst accessibility = interactionAccessibility(imageElement, contextRoot);\n\n\tif (source.explicitAlt !== undefined) {\n\t\t// QTI 3.0 <img>: alt=\"\" is the author's explicit \"decorative\" marker,\n\t\t// unless the author also named the image through aria.\n\t\tconst alt = accessibility?.label || normalizeText(source.explicitAlt);\n\t\tif (!alt) return { decorative: true };\n\t\treturn compact(alt, accessibility?.description);\n\t}\n\n\tif (source.inlineSvgContent !== undefined) {\n\t\t// Inline SVG: aria name, else the SVG's <title>, else the <object>'s own\n\t\t// fallback text beside the <svg> (never the drawing's internal text).\n\t\tconst svg = source.inlineSvgContent;\n\t\treturn compact(\n\t\t\taccessibility?.label ||\n\t\t\t\tmarkupText(svg, /<title\\b[^>]*>([\\s\\S]*?)<\\/title>/i) ||\n\t\t\t\ttextOutsideSvg(imageElement),\n\t\t\taccessibility?.description || markupText(svg, /<desc\\b[^>]*>([\\s\\S]*?)<\\/desc>/i),\n\t\t);\n\t}\n\n\t// QTI 2.x <object> referencing an external image: aria name, else the\n\t// element's fallback text content. Nothing found is an omission.\n\treturn compact(\n\t\taccessibility?.label || normalizeText(utils.getTextContent(imageElement)),\n\t\taccessibility?.description,\n\t);\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The image element of the graphic interactions.
|
|
3
|
+
*
|
|
4
|
+
* QTI 2.x content authors every interaction image as an
|
|
5
|
+
* `<object data="…" width height>` with fallback text. The QTI 3.0 schemas give
|
|
6
|
+
* the graphic interactions (hotspot, graphic order/associate/gap match, select
|
|
7
|
+
* point, drawing, position object) and the `qti-gap-img` label a choice of
|
|
8
|
+
* `object`, `img` **or `picture`** (3.0 XSD, e.g. HotspotInteractionDType and
|
|
9
|
+
* GapImgDType), so each of those forms is valid delivered content.
|
|
10
|
+
*
|
|
11
|
+
* A `<picture>` delivers its `<img>` fallback — the child whose `src`, `alt`
|
|
12
|
+
* and dimensions are what renders when no `<source>` matches — so the
|
|
13
|
+
* extracted image data keeps the shape renderers already consume.
|
|
14
|
+
*/
|
|
15
|
+
import type { ExtractionUtils } from '../../extraction/types.js';
|
|
16
|
+
import type { QTIElement } from './types.js';
|
|
17
|
+
/** The resolved interaction image: the element and the authored form it came from. */
|
|
18
|
+
export interface InteractionImage {
|
|
19
|
+
element: QTIElement;
|
|
20
|
+
/** `object` for an `<object>` (QTI 2.x form), `img` for a plain or fallback `<img>` (QTI 3.0). */
|
|
21
|
+
kind: 'object' | 'img';
|
|
22
|
+
}
|
|
23
|
+
type ImageLookup = Pick<ExtractionUtils, 'getChildrenByTag'>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the image an interaction draws on: its `object` child, else its
|
|
26
|
+
* `img` child, else the `img` fallback of its `picture` child. `object` wins
|
|
27
|
+
* over a sibling `img` (a document authoring both satisfies no version) to
|
|
28
|
+
* preserve the QTI 2.x reading order the extractors have always used. `null`
|
|
29
|
+
* when the container authors none of the forms.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findInteractionImage(container: QTIElement, utils: ImageLookup): InteractionImage | null;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The image element of the graphic interactions.
|
|
3
|
+
*
|
|
4
|
+
* QTI 2.x content authors every interaction image as an
|
|
5
|
+
* `<object data="…" width height>` with fallback text. The QTI 3.0 schemas give
|
|
6
|
+
* the graphic interactions (hotspot, graphic order/associate/gap match, select
|
|
7
|
+
* point, drawing, position object) and the `qti-gap-img` label a choice of
|
|
8
|
+
* `object`, `img` **or `picture`** (3.0 XSD, e.g. HotspotInteractionDType and
|
|
9
|
+
* GapImgDType), so each of those forms is valid delivered content.
|
|
10
|
+
*
|
|
11
|
+
* A `<picture>` delivers its `<img>` fallback — the child whose `src`, `alt`
|
|
12
|
+
* and dimensions are what renders when no `<source>` matches — so the
|
|
13
|
+
* extracted image data keeps the shape renderers already consume.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the image an interaction draws on: its `object` child, else its
|
|
17
|
+
* `img` child, else the `img` fallback of its `picture` child. `object` wins
|
|
18
|
+
* over a sibling `img` (a document authoring both satisfies no version) to
|
|
19
|
+
* preserve the QTI 2.x reading order the extractors have always used. `null`
|
|
20
|
+
* when the container authors none of the forms.
|
|
21
|
+
*/
|
|
22
|
+
export function findInteractionImage(container, utils) {
|
|
23
|
+
const objectElement = utils.getChildrenByTag(container, 'object')[0];
|
|
24
|
+
if (objectElement)
|
|
25
|
+
return { element: objectElement, kind: 'object' };
|
|
26
|
+
const imgElement = utils.getChildrenByTag(container, 'img')[0];
|
|
27
|
+
if (imgElement)
|
|
28
|
+
return { element: imgElement, kind: 'img' };
|
|
29
|
+
// QTI 3.0 <picture>: the spec-valid form is (source*, img), and the <img>
|
|
30
|
+
// fallback is required content — an img-less picture delivers no image.
|
|
31
|
+
const pictureElement = utils.getChildrenByTag(container, 'picture')[0];
|
|
32
|
+
if (pictureElement) {
|
|
33
|
+
const fallbackImg = utils.getChildrenByTag(pictureElement, 'img')[0];
|
|
34
|
+
if (fallbackImg)
|
|
35
|
+
return { element: fallbackImg, kind: 'img' };
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=interactionImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionImage.js","sourceRoot":"","sources":["../../../src/interactions/shared/interactionImage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAcH;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAqB,EAAE,KAAkB;IAC7E,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,aAAa;QAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAErE,MAAM,UAAU,GAAG,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,IAAI,UAAU;QAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAE5D,0EAA0E;IAC1E,wEAAwE;IACxE,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,IAAI,cAAc,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,KAAK,CAAC,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAI,WAAW;YAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC/D,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * The image element of the graphic interactions.\n *\n * QTI 2.x content authors every interaction image as an\n * `<object data=\"…\" width height>` with fallback text. The QTI 3.0 schemas give\n * the graphic interactions (hotspot, graphic order/associate/gap match, select\n * point, drawing, position object) and the `qti-gap-img` label a choice of\n * `object`, `img` **or `picture`** (3.0 XSD, e.g. HotspotInteractionDType and\n * GapImgDType), so each of those forms is valid delivered content.\n *\n * A `<picture>` delivers its `<img>` fallback — the child whose `src`, `alt`\n * and dimensions are what renders when no `<source>` matches — so the\n * extracted image data keeps the shape renderers already consume.\n */\n\nimport type { ExtractionUtils } from '../../extraction/types.js';\nimport type { QTIElement } from './types.js';\n\n/** The resolved interaction image: the element and the authored form it came from. */\nexport interface InteractionImage {\n\telement: QTIElement;\n\t/** `object` for an `<object>` (QTI 2.x form), `img` for a plain or fallback `<img>` (QTI 3.0). */\n\tkind: 'object' | 'img';\n}\n\ntype ImageLookup = Pick<ExtractionUtils, 'getChildrenByTag'>;\n\n/**\n * Resolve the image an interaction draws on: its `object` child, else its\n * `img` child, else the `img` fallback of its `picture` child. `object` wins\n * over a sibling `img` (a document authoring both satisfies no version) to\n * preserve the QTI 2.x reading order the extractors have always used. `null`\n * when the container authors none of the forms.\n */\nexport function findInteractionImage(container: QTIElement, utils: ImageLookup): InteractionImage | null {\n\tconst objectElement = utils.getChildrenByTag(container, 'object')[0];\n\tif (objectElement) return { element: objectElement, kind: 'object' };\n\n\tconst imgElement = utils.getChildrenByTag(container, 'img')[0];\n\tif (imgElement) return { element: imgElement, kind: 'img' };\n\n\t// QTI 3.0 <picture>: the spec-valid form is (source*, img), and the <img>\n\t// fallback is required content — an img-less picture delivers no image.\n\tconst pictureElement = utils.getChildrenByTag(container, 'picture')[0];\n\tif (pictureElement) {\n\t\tconst fallbackImg = utils.getChildrenByTag(pictureElement, 'img')[0];\n\t\tif (fallbackImg) return { element: fallbackImg, kind: 'img' };\n\t}\n\n\treturn null;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-version QTI defaults for interaction attributes whose spec default changed between
|
|
3
|
+
* QTI 2.1 and QTI 2.2, or that a response's cardinality constrains. See
|
|
4
|
+
* docs/QTI_attribute_defaults.md for the audited table.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtractionContext } from '../../extraction/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Whether the item predates QTI 2.2, whose information model and XSD changed several
|
|
9
|
+
* interaction defaults (e.g. choiceInteraction `maxChoices` is 0 in 2.1, 1 in 2.2/3.0; the
|
|
10
|
+
* gap match interactions gained `maxAssociations` in 2.2). An unknown or undetected version
|
|
11
|
+
* follows the QTI 2.2 assumption `detectQtiVersion` makes for unversioned items.
|
|
12
|
+
*/
|
|
13
|
+
export declare function predatesQti22(context: Pick<ExtractionContext, 'config'>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The value an absent limit takes when its spec default is 0 (no restriction): 0, unless the
|
|
16
|
+
* interaction is bound to a single-cardinality response, which holds one value. The spec only
|
|
17
|
+
* allows a limit of 0 (or above 1) with a multiple-cardinality binding, so for a single binding
|
|
18
|
+
* the one consistent limit is 1.
|
|
19
|
+
*/
|
|
20
|
+
export declare function unrestrictedLimitDefault(context: Pick<ExtractionContext, 'declarations' | 'responseId'>): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-version QTI defaults for interaction attributes whose spec default changed between
|
|
3
|
+
* QTI 2.1 and QTI 2.2, or that a response's cardinality constrains. See
|
|
4
|
+
* docs/QTI_attribute_defaults.md for the audited table.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether the item predates QTI 2.2, whose information model and XSD changed several
|
|
8
|
+
* interaction defaults (e.g. choiceInteraction `maxChoices` is 0 in 2.1, 1 in 2.2/3.0; the
|
|
9
|
+
* gap match interactions gained `maxAssociations` in 2.2). An unknown or undetected version
|
|
10
|
+
* follows the QTI 2.2 assumption `detectQtiVersion` makes for unversioned items.
|
|
11
|
+
*/
|
|
12
|
+
export function predatesQti22(context) {
|
|
13
|
+
const version = context.config.qtiVersion;
|
|
14
|
+
return version === '2.0' || version === '2.1';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The value an absent limit takes when its spec default is 0 (no restriction): 0, unless the
|
|
18
|
+
* interaction is bound to a single-cardinality response, which holds one value. The spec only
|
|
19
|
+
* allows a limit of 0 (or above 1) with a multiple-cardinality binding, so for a single binding
|
|
20
|
+
* the one consistent limit is 1.
|
|
21
|
+
*/
|
|
22
|
+
export function unrestrictedLimitDefault(context) {
|
|
23
|
+
return context.declarations.get(context.responseId)?.cardinality === 'single' ? 1 : 0;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=specDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specDefaults.js","sourceRoot":"","sources":["../../../src/interactions/shared/specDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAA0C;IACvE,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;IAC1C,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAA+D;IACvG,OAAO,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * Per-version QTI defaults for interaction attributes whose spec default changed between\n * QTI 2.1 and QTI 2.2, or that a response's cardinality constrains. See\n * docs/QTI_attribute_defaults.md for the audited table.\n */\n\nimport type { ExtractionContext } from '../../extraction/types.js';\n\n/**\n * Whether the item predates QTI 2.2, whose information model and XSD changed several\n * interaction defaults (e.g. choiceInteraction `maxChoices` is 0 in 2.1, 1 in 2.2/3.0; the\n * gap match interactions gained `maxAssociations` in 2.2). An unknown or undetected version\n * follows the QTI 2.2 assumption `detectQtiVersion` makes for unversioned items.\n */\nexport function predatesQti22(context: Pick<ExtractionContext, 'config'>): boolean {\n\tconst version = context.config.qtiVersion;\n\treturn version === '2.0' || version === '2.1';\n}\n\n/**\n * The value an absent limit takes when its spec default is 0 (no restriction): 0, unless the\n * interaction is bound to a single-cardinality response, which holds one value. The spec only\n * allows a limit of 0 (or above 1) with a multiple-cardinality binding, so for a single binding\n * the one consistent limit is 1.\n */\nexport function unrestrictedLimitDefault(context: Pick<ExtractionContext, 'declarations' | 'responseId'>): number {\n\treturn context.declarations.get(context.responseId)?.cardinality === 'single' ? 1 : 0;\n}\n"]}
|