@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen-reader announcement of integrated feedback (WCAG 4.1.3 Status Messages).
|
|
3
|
+
*
|
|
4
|
+
* The presentation plan splices the feedbackInline and feedbackBlock that an attempt shows into
|
|
5
|
+
* the item body HTML, with no marker left behind. They appear without moving focus and without
|
|
6
|
+
* any other change assistive technology can detect. The item body therefore announces them
|
|
7
|
+
* through one persistent polite live region. This module holds the pure rules behind that:
|
|
8
|
+
* what the shown feedback says, which session transitions announce it, and how an identical
|
|
9
|
+
* repeat still reaches a screen reader.
|
|
10
|
+
*/
|
|
11
|
+
import { isShownByIdentifier } from '@pie-qti/qti-common';
|
|
12
|
+
import { readHtmlAttribute } from '../utils/htmlAttributes.js';
|
|
13
|
+
const NOTHING_SHOWN = Object.freeze({ shown: false, text: '' });
|
|
14
|
+
const FEEDBACK_TAG = /<(\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\b([^>]*?)(\/?)>/gi;
|
|
15
|
+
/**
|
|
16
|
+
* The top-level feedback elements in `html`, each with the feedback nested inside it. Parsed as
|
|
17
|
+
* `processFeedbackInline` in `@pie-qti/qti-common` parses them, so the announcement covers exactly
|
|
18
|
+
* the elements the plan shows or drops. An unclosed element is left as written, as it is there.
|
|
19
|
+
*/
|
|
20
|
+
function feedbackElements(html) {
|
|
21
|
+
const roots = [];
|
|
22
|
+
const open = [];
|
|
23
|
+
const add = (element) => (open[open.length - 1]?.children ?? roots).push(element);
|
|
24
|
+
for (const match of html.matchAll(FEEDBACK_TAG)) {
|
|
25
|
+
const [tag, closing, , attrs = '', selfClosing] = match;
|
|
26
|
+
const start = match.index;
|
|
27
|
+
const end = start + tag.length;
|
|
28
|
+
if (closing) {
|
|
29
|
+
const element = open.pop();
|
|
30
|
+
if (!element)
|
|
31
|
+
continue;
|
|
32
|
+
element.closeStart = start;
|
|
33
|
+
element.closeEnd = end;
|
|
34
|
+
add(element);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const element = { attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };
|
|
38
|
+
if (selfClosing)
|
|
39
|
+
add(element);
|
|
40
|
+
else
|
|
41
|
+
open.push(element);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return roots;
|
|
45
|
+
}
|
|
46
|
+
function isShown(element, outcomeValues) {
|
|
47
|
+
const outcomeId = readHtmlAttribute(element.attrs, 'outcomeIdentifier');
|
|
48
|
+
const feedbackId = readHtmlAttribute(element.attrs, 'identifier');
|
|
49
|
+
if (outcomeId === null || feedbackId === null)
|
|
50
|
+
return false;
|
|
51
|
+
return isShownByIdentifier(outcomeValues[outcomeId], feedbackId, readHtmlAttribute(element.attrs, 'showHide'));
|
|
52
|
+
}
|
|
53
|
+
/** A shown element's content as the plan renders it: nested feedback resolved, hidden feedback dropped. */
|
|
54
|
+
function shownContent(html, element, outcomeValues) {
|
|
55
|
+
let out = '';
|
|
56
|
+
let position = element.openEnd;
|
|
57
|
+
for (const child of element.children) {
|
|
58
|
+
out += html.slice(position, child.openStart);
|
|
59
|
+
position = child.closeEnd;
|
|
60
|
+
if (isShown(child, outcomeValues))
|
|
61
|
+
out += shownContent(html, child, outcomeValues);
|
|
62
|
+
}
|
|
63
|
+
return out + html.slice(position, element.closeStart);
|
|
64
|
+
}
|
|
65
|
+
/** Phrasing elements: their text runs on with the text around them ("<strong>sum</strong>." reads "sum."). */
|
|
66
|
+
const PHRASING_ELEMENTS = new Set([
|
|
67
|
+
'a', 'abbr', 'b', 'bdi', 'bdo', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd',
|
|
68
|
+
'label', 'mark', 'q', 'rb', 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup',
|
|
69
|
+
'time', 'u', 'var', 'wbr',
|
|
70
|
+
]);
|
|
71
|
+
const NAMED_CHARACTERS = {
|
|
72
|
+
amp: '&',
|
|
73
|
+
lt: '<',
|
|
74
|
+
gt: '>',
|
|
75
|
+
quot: '"',
|
|
76
|
+
apos: "'",
|
|
77
|
+
nbsp: '\u00a0',
|
|
78
|
+
};
|
|
79
|
+
function decodeCharacterReferences(text) {
|
|
80
|
+
return text.replace(/&(#[xX][0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (reference, body) => {
|
|
81
|
+
if (body[0] !== '#')
|
|
82
|
+
return NAMED_CHARACTERS[body.toLowerCase()] ?? reference;
|
|
83
|
+
const code = body[1] === 'x' || body[1] === 'X' ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);
|
|
84
|
+
return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : reference;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** HTML as a screen reader reads it: images by their alt text, inert content skipped, whitespace collapsed. */
|
|
88
|
+
function accessibleText(html) {
|
|
89
|
+
const text = html
|
|
90
|
+
.replace(/<!--[\s\S]*?-->/g, '')
|
|
91
|
+
.replace(/<(script|style|template|noscript)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
|
|
92
|
+
.replace(/<img\b[^>]*>/gi, (tag) => ` ${readHtmlAttribute(tag.slice(4, -1), 'alt') ?? ''} `)
|
|
93
|
+
.replace(/<\/?([a-zA-Z][\w:-]*)\b[^>]*>/g, (_tag, name) => (PHRASING_ELEMENTS.has(name.toLowerCase()) ? '' : ' '))
|
|
94
|
+
.replace(/<[^>]*>/g, ' ');
|
|
95
|
+
// Character references are decoded last, so an encoded `<` is never mistaken for markup.
|
|
96
|
+
return decodeCharacterReferences(text).replace(/\s+/g, ' ').trim();
|
|
97
|
+
}
|
|
98
|
+
/** Content that renders something: any text or element, comments aside. */
|
|
99
|
+
function rendersSomething(html) {
|
|
100
|
+
return /\S/.test(html.replace(/<!--[\s\S]*?-->/g, ''));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The feedback that `outcomeValues` show in an item body, read as text in document order.
|
|
104
|
+
*
|
|
105
|
+
* Runs on the body HTML *before* the plan splices the feedback in, while every element still
|
|
106
|
+
* carries its `outcomeIdentifier` and `identifier`. Visibility follows the shared rule
|
|
107
|
+
* (`isShownByIdentifier`, including `showHide="hide"` and container membership). Nested feedback
|
|
108
|
+
* resolves inside shown feedback, and hidden feedback contributes nothing, not even what is
|
|
109
|
+
* nested inside it. Separate feedback elements are joined with a space.
|
|
110
|
+
*/
|
|
111
|
+
export function extractShownFeedback(bodyHtml, outcomeValues, options = {}) {
|
|
112
|
+
if (!bodyHtml || options.hideAll)
|
|
113
|
+
return NOTHING_SHOWN;
|
|
114
|
+
const texts = [];
|
|
115
|
+
let shown = false;
|
|
116
|
+
for (const root of feedbackElements(bodyHtml)) {
|
|
117
|
+
if (!isShown(root, outcomeValues))
|
|
118
|
+
continue;
|
|
119
|
+
const content = shownContent(bodyHtml, root, outcomeValues);
|
|
120
|
+
if (!rendersSomething(content))
|
|
121
|
+
continue;
|
|
122
|
+
shown = true;
|
|
123
|
+
const text = accessibleText(options.transform ? options.transform(content) : content);
|
|
124
|
+
if (text)
|
|
125
|
+
texts.push(text);
|
|
126
|
+
}
|
|
127
|
+
return shown ? { shown, text: texts.join(' ') } : NOTHING_SHOWN;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Whether a session transition is the candidate's own attempt ending: a submit or end-attempt,
|
|
131
|
+
* which covers every attempt of an adaptive item, including an uncounted `countAttempt="false"`
|
|
132
|
+
* one. Feedback is the result of the attempt, so only an attempt announces it. Initial render and
|
|
133
|
+
* restore dispatch nothing. Review and scorer renders dispatch no attempt, because a scorer is
|
|
134
|
+
* excluded by role and an ended session refuses attempt commands. All of them therefore stay
|
|
135
|
+
* silent, however often they re-render.
|
|
136
|
+
*/
|
|
137
|
+
export function isCandidateAttemptFeedback(transition, role) {
|
|
138
|
+
const { action } = transition.command;
|
|
139
|
+
return role === 'candidate' && (action === 'endAttempt' || action === 'submitAttempt');
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The live-region text for `message`, given the text it holds now. Repeating identical text would
|
|
143
|
+
* leave the region unchanged, and assistive technology does not announce an unchanged region. A
|
|
144
|
+
* repeat therefore toggles a trailing zero-width space, which a screen reader does not read but
|
|
145
|
+
* which still changes the region. The interaction components use the same toggle for refusals.
|
|
146
|
+
*/
|
|
147
|
+
export function nextFeedbackAnnouncement(previous, message) {
|
|
148
|
+
return previous === message ? `${message}\u200b` : message;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=feedbackAnnouncement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedbackAnnouncement.js","sourceRoot":"","sources":["../../src/presentation/feedbackAnnouncement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAe/D,MAAM,aAAa,GAAkB,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,E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,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAC5D,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAAE,SAAS;QACzC,KAAK,GAAG,IAAI,CAAC;QACb,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACtF,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;AACjE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAAkD,EAAE,IAAa;IAC3G,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC;IACtC,OAAO,IAAI,KAAK,WAAW,IAAI,CAAC,MAAM,KAAK,YAAY,IAAI,MAAM,KAAK,eAAe,CAAC,CAAC;AACxF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAmC,EAAE,OAAe;IAC5F,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * Screen-reader announcement of integrated feedback (WCAG 4.1.3 Status Messages).\n *\n * The presentation plan splices the feedbackInline and feedbackBlock that an attempt shows into\n * the item body HTML, with no marker left behind. They appear without moving focus and without\n * any other change assistive technology can detect. The item body therefore announces them\n * through one persistent polite live region. This module holds the pure rules behind that:\n * what the shown feedback says, which session transitions announce it, and how an identical\n * repeat still reaches a screen reader.\n */\n\nimport { isShownByIdentifier } from '@pie-qti/qti-common';\nimport type { ItemSessionTransition } from '../core/ItemSession.js';\nimport type { QTIRole } from '../types/index.js';\nimport { readHtmlAttribute } from '../utils/htmlAttributes.js';\n\n/** The integrated feedback an item body shows. */\nexport interface ShownFeedback {\n\t/** Whether any feedbackInline or feedbackBlock with content is shown. */\n\treadonly shown: boolean;\n\t/**\n\t * Accessible text of the shown feedback in document order: visible text plus image `alt` text,\n\t * markup removed and whitespace collapsed. Empty when nothing is shown, or when what is shown\n\t * has no text, such as an image with no alt. A shown feedback with no text is announced as a\n\t * localized \"Feedback is shown.\" instead.\n\t */\n\treadonly text: string;\n}\n\nconst NOTHING_SHOWN: ShownFeedback = Object.freeze({ shown: false, text: '' });\n\nexport interface ExtractShownFeedbackOptions {\n\t/** Show no feedback whatever the outcomes, as a test-level `showFeedback=\"false\"` requires. */\n\treadonly hideAll?: boolean;\n\t/** The authoring heuristics the plan applies to shown feedback (`cleanFeedbackText`). */\n\treadonly transform?: (html: string) => string;\n}\n\nconst FEEDBACK_TAG =\n\t/<(\\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\\b([^>]*?)(\\/?)>/gi;\n\ninterface FeedbackElement {\n\treadonly attrs: string;\n\treadonly openStart: number;\n\treadonly openEnd: number;\n\tcloseStart: number;\n\tcloseEnd: number;\n\treadonly children: FeedbackElement[];\n}\n\n/**\n * The top-level feedback elements in `html`, each with the feedback nested inside it. Parsed as\n * `processFeedbackInline` in `@pie-qti/qti-common` parses them, so the announcement covers exactly\n * the elements the plan shows or drops. An unclosed element is left as written, as it is there.\n */\nfunction feedbackElements(html: string): FeedbackElement[] {\n\tconst roots: FeedbackElement[] = [];\n\tconst open: FeedbackElement[] = [];\n\tconst add = (element: FeedbackElement) => (open[open.length - 1]?.children ?? roots).push(element);\n\tfor (const match of html.matchAll(FEEDBACK_TAG)) {\n\t\tconst [tag, closing, , attrs = '', selfClosing] = match;\n\t\tconst start = match.index;\n\t\tconst end = start + tag.length;\n\t\tif (closing) {\n\t\t\tconst element = open.pop();\n\t\t\tif (!element) continue;\n\t\t\telement.closeStart = start;\n\t\t\telement.closeEnd = end;\n\t\t\tadd(element);\n\t\t} else {\n\t\t\tconst element: FeedbackElement = { attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };\n\t\t\tif (selfClosing) add(element);\n\t\t\telse open.push(element);\n\t\t}\n\t}\n\treturn roots;\n}\n\nfunction isShown(element: FeedbackElement, outcomeValues: Readonly<Record<string, unknown>>): boolean {\n\tconst outcomeId = readHtmlAttribute(element.attrs, 'outcomeIdentifier');\n\tconst feedbackId = readHtmlAttribute(element.attrs, 'identifier');\n\tif (outcomeId === null || feedbackId === null) return false;\n\treturn isShownByIdentifier(outcomeValues[outcomeId], feedbackId, readHtmlAttribute(element.attrs, 'showHide'));\n}\n\n/** A shown element's content as the plan renders it: nested feedback resolved, hidden feedback dropped. */\nfunction shownContent(html: string, element: FeedbackElement, outcomeValues: Readonly<Record<string, unknown>>): string {\n\tlet out = '';\n\tlet position = element.openEnd;\n\tfor (const child of element.children) {\n\t\tout += html.slice(position, child.openStart);\n\t\tposition = child.closeEnd;\n\t\tif (isShown(child, outcomeValues)) out += shownContent(html, child, outcomeValues);\n\t}\n\treturn out + html.slice(position, element.closeStart);\n}\n\n/** Phrasing elements: their text runs on with the text around them (\"<strong>sum</strong>.\" reads \"sum.\"). */\nconst PHRASING_ELEMENTS = new Set([\n\t'a', 'abbr', 'b', 'bdi', 'bdo', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd',\n\t'label', 'mark', 'q', 'rb', 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup',\n\t'time', 'u', 'var', 'wbr',\n]);\n\nconst NAMED_CHARACTERS: Readonly<Record<string, string>> = {\n\tamp: '&',\n\tlt: '<',\n\tgt: '>',\n\tquot: '\"',\n\tapos: \"'\",\n\tnbsp: '\\u00a0',\n};\n\nfunction decodeCharacterReferences(text: string): string {\n\treturn text.replace(/&(#[xX][0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (reference, body: string) => {\n\t\tif (body[0] !== '#') return NAMED_CHARACTERS[body.toLowerCase()] ?? reference;\n\t\tconst code = body[1] === 'x' || body[1] === 'X' ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);\n\t\treturn code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : reference;\n\t});\n}\n\n/** HTML as a screen reader reads it: images by their alt text, inert content skipped, whitespace collapsed. */\nfunction accessibleText(html: string): string {\n\tconst text = html\n\t\t.replace(/<!--[\\s\\S]*?-->/g, '')\n\t\t.replace(/<(script|style|template|noscript)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi, ' ')\n\t\t.replace(/<img\\b[^>]*>/gi, (tag) => ` ${readHtmlAttribute(tag.slice(4, -1), 'alt') ?? ''} `)\n\t\t.replace(/<\\/?([a-zA-Z][\\w:-]*)\\b[^>]*>/g, (_tag, name: string) => (PHRASING_ELEMENTS.has(name.toLowerCase()) ? '' : ' '))\n\t\t.replace(/<[^>]*>/g, ' ');\n\t// Character references are decoded last, so an encoded `<` is never mistaken for markup.\n\treturn decodeCharacterReferences(text).replace(/\\s+/g, ' ').trim();\n}\n\n/** Content that renders something: any text or element, comments aside. */\nfunction rendersSomething(html: string): boolean {\n\treturn /\\S/.test(html.replace(/<!--[\\s\\S]*?-->/g, ''));\n}\n\n/**\n * The feedback that `outcomeValues` show in an item body, read as text in document order.\n *\n * Runs on the body HTML *before* the plan splices the feedback in, while every element still\n * carries its `outcomeIdentifier` and `identifier`. Visibility follows the shared rule\n * (`isShownByIdentifier`, including `showHide=\"hide\"` and container membership). Nested feedback\n * resolves inside shown feedback, and hidden feedback contributes nothing, not even what is\n * nested inside it. Separate feedback elements are joined with a space.\n */\nexport function extractShownFeedback(\n\tbodyHtml: string,\n\toutcomeValues: Readonly<Record<string, unknown>>,\n\toptions: ExtractShownFeedbackOptions = {},\n): ShownFeedback {\n\tif (!bodyHtml || options.hideAll) return NOTHING_SHOWN;\n\tconst texts: string[] = [];\n\tlet shown = false;\n\tfor (const root of feedbackElements(bodyHtml)) {\n\t\tif (!isShown(root, outcomeValues)) continue;\n\t\tconst content = shownContent(bodyHtml, root, outcomeValues);\n\t\tif (!rendersSomething(content)) continue;\n\t\tshown = true;\n\t\tconst text = accessibleText(options.transform ? options.transform(content) : content);\n\t\tif (text) texts.push(text);\n\t}\n\treturn shown ? { shown, text: texts.join(' ') } : NOTHING_SHOWN;\n}\n\n/**\n * Whether a session transition is the candidate's own attempt ending: a submit or end-attempt,\n * which covers every attempt of an adaptive item, including an uncounted `countAttempt=\"false\"`\n * one. Feedback is the result of the attempt, so only an attempt announces it. Initial render and\n * restore dispatch nothing. Review and scorer renders dispatch no attempt, because a scorer is\n * excluded by role and an ended session refuses attempt commands. All of them therefore stay\n * silent, however often they re-render.\n */\nexport function isCandidateAttemptFeedback(transition: Pick<ItemSessionTransition, 'command'>, role: QTIRole): boolean {\n\tconst { action } = transition.command;\n\treturn role === 'candidate' && (action === 'endAttempt' || action === 'submitAttempt');\n}\n\n/**\n * The live-region text for `message`, given the text it holds now. Repeating identical text would\n * leave the region unchanged, and assistive technology does not announce an unchanged region. A\n * repeat therefore toggles a trailing zero-width space, which a screen reader does not read but\n * which still changes the region. The interaction components use the same toggle for refusals.\n */\nexport function nextFeedbackAnnouncement(previous: string | null | undefined, message: string): string {\n\treturn previous === message ? `${message}\\u200b` : message;\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BaseInteractionData } from '../interactions/shared/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The attribute on the empty placeholder that marks where an interaction was authored in the
|
|
4
|
+
* item body. A renderer mounts the interaction into the element carrying it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const INTERACTION_SLOT_ATTRIBUTE = "data-qti-interaction-slot";
|
|
7
|
+
/** How a slot lays out: `inline` stays in sentence flow, `block` takes its own line. */
|
|
8
|
+
export type InteractionSlotPlacement = 'block' | 'inline';
|
|
9
|
+
export interface PlacedInteractionSlots {
|
|
10
|
+
/** The body HTML with each located interaction element replaced by its empty slot. */
|
|
11
|
+
readonly html: string;
|
|
12
|
+
/**
|
|
13
|
+
* The slot id per index into the interactions, numbered in document order. An interaction
|
|
14
|
+
* whose element is not in the body has no entry.
|
|
15
|
+
*/
|
|
16
|
+
readonly slots: ReadonlyMap<number, string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Replace every interaction element in the item body with an empty slot element at the same
|
|
20
|
+
* position, so the interaction renders where it was authored: between paragraphs, after the
|
|
21
|
+
* text that introduces it, inside layout rows and columns, table cells and other containers.
|
|
22
|
+
*
|
|
23
|
+
* An element is matched to the interaction data by its response identifier, in document order.
|
|
24
|
+
* A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,
|
|
25
|
+
* because its renderer draws the stage background as well. Interaction elements that match no
|
|
26
|
+
* interaction data are hidden rather than shown as raw markup, and authored slot attributes are
|
|
27
|
+
* removed so content cannot redirect where an interaction mounts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function placeInteractionSlots(html: string, interactions: readonly BaseInteractionData[], placementOf: (interaction: BaseInteractionData) => InteractionSlotPlacement): PlacedInteractionSlots;
|
|
30
|
+
/** Whether the final body markup still carries `slot`, after sanitation has run over it. */
|
|
31
|
+
export declare function hasInteractionSlot(html: string, slot: string): boolean;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { NodeType, parse } from 'node-html-parser';
|
|
2
|
+
import { readResponseIdentifier } from '../extraction/responseIdentifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* The attribute on the empty placeholder that marks where an interaction was authored in the
|
|
5
|
+
* item body. A renderer mounts the interaction into the element carrying it.
|
|
6
|
+
*/
|
|
7
|
+
export const INTERACTION_SLOT_ATTRIBUTE = 'data-qti-interaction-slot';
|
|
8
|
+
/** Element names of interactions in either QTI spelling: `choiceInteraction`, `qti-choice-interaction`. */
|
|
9
|
+
const INTERACTION_TAG = /(?:^[a-z]+interaction$|^qti-[a-z-]+-interaction$)/i;
|
|
10
|
+
const POSITION_OBJECT_STAGE = /^(?:positionobjectstage|qti-position-object-stage)$/i;
|
|
11
|
+
/** Cheap pre-check: markup without any of these needs no structural pass. */
|
|
12
|
+
const NEEDS_SLOT_PASS = /interaction|positionobjectstage|position-object-stage|data-qti-interaction-slot/i;
|
|
13
|
+
/**
|
|
14
|
+
* Replace every interaction element in the item body with an empty slot element at the same
|
|
15
|
+
* position, so the interaction renders where it was authored: between paragraphs, after the
|
|
16
|
+
* text that introduces it, inside layout rows and columns, table cells and other containers.
|
|
17
|
+
*
|
|
18
|
+
* An element is matched to the interaction data by its response identifier, in document order.
|
|
19
|
+
* A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,
|
|
20
|
+
* because its renderer draws the stage background as well. Interaction elements that match no
|
|
21
|
+
* interaction data are hidden rather than shown as raw markup, and authored slot attributes are
|
|
22
|
+
* removed so content cannot redirect where an interaction mounts.
|
|
23
|
+
*/
|
|
24
|
+
export function placeInteractionSlots(html, interactions, placementOf) {
|
|
25
|
+
const slots = new Map();
|
|
26
|
+
if (!html || !NEEDS_SLOT_PASS.test(html))
|
|
27
|
+
return { html, slots };
|
|
28
|
+
const pending = new Map();
|
|
29
|
+
interactions.forEach((interaction, index) => {
|
|
30
|
+
const queue = pending.get(interaction.responseId);
|
|
31
|
+
if (queue)
|
|
32
|
+
queue.push(index);
|
|
33
|
+
else
|
|
34
|
+
pending.set(interaction.responseId, [index]);
|
|
35
|
+
});
|
|
36
|
+
const takeInteraction = (element) => {
|
|
37
|
+
const responseId = responseIdentifierOf(element);
|
|
38
|
+
return responseId ? pending.get(responseId)?.shift() : undefined;
|
|
39
|
+
};
|
|
40
|
+
const slotMarkup = (index) => {
|
|
41
|
+
const id = String(slots.size);
|
|
42
|
+
slots.set(index, id);
|
|
43
|
+
const placement = placementOf(interactions[index]);
|
|
44
|
+
return `<span class="qti-interaction-slot qti-interaction-slot--${placement}" ${INTERACTION_SLOT_ATTRIBUTE}="${id}"></span>`;
|
|
45
|
+
};
|
|
46
|
+
const collectStageInteractions = (element, found) => {
|
|
47
|
+
for (const child of elementChildren(element)) {
|
|
48
|
+
const index = takeInteraction(child);
|
|
49
|
+
if (index !== undefined)
|
|
50
|
+
found.push(index);
|
|
51
|
+
else
|
|
52
|
+
collectStageInteractions(child, found);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const visit = (parent) => {
|
|
56
|
+
for (const child of elementChildren(parent)) {
|
|
57
|
+
if (child.hasAttribute(INTERACTION_SLOT_ATTRIBUTE)) {
|
|
58
|
+
child.removeAttribute(INTERACTION_SLOT_ATTRIBUTE);
|
|
59
|
+
}
|
|
60
|
+
const tagName = child.rawTagName ?? '';
|
|
61
|
+
if (POSITION_OBJECT_STAGE.test(tagName)) {
|
|
62
|
+
const found = [];
|
|
63
|
+
collectStageInteractions(child, found);
|
|
64
|
+
child.replaceWith(found.length > 0 ? found.map(slotMarkup).join('') : hiddenMarkup(child));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const index = takeInteraction(child);
|
|
68
|
+
if (index !== undefined) {
|
|
69
|
+
child.replaceWith(slotMarkup(index));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (INTERACTION_TAG.test(tagName)) {
|
|
73
|
+
child.replaceWith(hiddenMarkup(child));
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
visit(child);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const root = parse(html, { lowerCaseTagName: false, comment: false });
|
|
80
|
+
visit(root);
|
|
81
|
+
return { html: root.toString(), slots };
|
|
82
|
+
}
|
|
83
|
+
/** Whether the final body markup still carries `slot`, after sanitation has run over it. */
|
|
84
|
+
export function hasInteractionSlot(html, slot) {
|
|
85
|
+
return html.includes(`${INTERACTION_SLOT_ATTRIBUTE}="${slot}"`);
|
|
86
|
+
}
|
|
87
|
+
function elementChildren(element) {
|
|
88
|
+
return element.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE);
|
|
89
|
+
}
|
|
90
|
+
/** Slot hiding reads the binding on the HTML tree, without a mapper. */
|
|
91
|
+
function responseIdentifierOf(element) {
|
|
92
|
+
return readResponseIdentifier(element);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Interaction markup with no interaction data behind it is kept hidden in the body, never shown
|
|
96
|
+
* as raw prompt and choice text.
|
|
97
|
+
*/
|
|
98
|
+
function hiddenMarkup(element) {
|
|
99
|
+
return `<span class="qti-hidden-interaction">${element.toString()}</span>`;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=interactionSlots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactionSlots.js","sourceRoot":"","sources":["../../src/presentation/interactionSlots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAG7E;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,2BAA2B,CAAC;AAetE,2GAA2G;AAC3G,MAAM,eAAe,GAAG,oDAAoD,CAAC;AAC7E,MAAM,qBAAqB,GAAG,sDAAsD,CAAC;AACrF,6EAA6E;AAC7E,MAAM,eAAe,GAAG,kFAAkF,CAAC;AAE3G;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,YAA4C,EAC5C,WAA2E;IAE3E,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAEjE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC5C,YAAY,CAAC,OAAO,CAAC,CAAC,WA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E,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC;AACzC,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,IAAY;IAC5D,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,0BAA0B,KAAK,IAAI,GAAG,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,eAAe,CAAC,OAA0B;IAClD,OAAQ,OAAO,CAAC,UAA6C,CAAC,MAAM,CACnE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,YAAY,CACjD,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,SAAS,oBAAoB,CAAC,OAA0B;IACvD,OAAO,sBAAsB,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,OAA0B;IAC/C,OAAO,wCAAwC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;AAC5E,CAAC","sourcesContent":["import { type HTMLElement as ParsedHtmlElement, NodeType, parse } from 'node-html-parser';\nimport { readResponseIdentifier } from '../extraction/responseIdentifier.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\n\n/**\n * The attribute on the empty placeholder that marks where an interaction was authored in the\n * item body. A renderer mounts the interaction into the element carrying it.\n */\nexport const INTERACTION_SLOT_ATTRIBUTE = 'data-qti-interaction-slot';\n\n/** How a slot lays out: `inline` stays in sentence flow, `block` takes its own line. */\nexport type InteractionSlotPlacement = 'block' | 'inline';\n\nexport interface PlacedInteractionSlots {\n\t/** The body HTML with each located interaction element replaced by its empty slot. */\n\treadonly html: string;\n\t/**\n\t * The slot id per index into the interactions, numbered in document order. An interaction\n\t * whose element is not in the body has no entry.\n\t */\n\treadonly slots: ReadonlyMap<number, string>;\n}\n\n/** Element names of interactions in either QTI spelling: `choiceInteraction`, `qti-choice-interaction`. */\nconst INTERACTION_TAG = /(?:^[a-z]+interaction$|^qti-[a-z-]+-interaction$)/i;\nconst POSITION_OBJECT_STAGE = /^(?:positionobjectstage|qti-position-object-stage)$/i;\n/** Cheap pre-check: markup without any of these needs no structural pass. */\nconst NEEDS_SLOT_PASS = /interaction|positionobjectstage|position-object-stage|data-qti-interaction-slot/i;\n\n/**\n * Replace every interaction element in the item body with an empty slot element at the same\n * position, so the interaction renders where it was authored: between paragraphs, after the\n * text that introduces it, inside layout rows and columns, table cells and other containers.\n *\n * An element is matched to the interaction data by its response identifier, in document order.\n * A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,\n * because its renderer draws the stage background as well. Interaction elements that match no\n * interaction data are hidden rather than shown as raw markup, and authored slot attributes are\n * removed so content cannot redirect where an interaction mounts.\n */\nexport function placeInteractionSlots(\n\thtml: string,\n\tinteractions: readonly BaseInteractionData[],\n\tplacementOf: (interaction: BaseInteractionData) => InteractionSlotPlacement,\n): PlacedInteractionSlots {\n\tconst slots = new Map<number, string>();\n\tif (!html || !NEEDS_SLOT_PASS.test(html)) return { html, slots };\n\n\tconst pending = new Map<string, number[]>();\n\tinteractions.forEach((interaction, index) => {\n\t\tconst queue = pending.get(interaction.responseId);\n\t\tif (queue) queue.push(index);\n\t\telse pending.set(interaction.responseId, [index]);\n\t});\n\n\tconst takeInteraction = (element: ParsedHtmlElement): number | undefined => {\n\t\tconst responseId = responseIdentifierOf(element);\n\t\treturn responseId ? pending.get(responseId)?.shift() : undefined;\n\t};\n\n\tconst slotMarkup = (index: number): string => {\n\t\tconst id = String(slots.size);\n\t\tslots.set(index, id);\n\t\tconst placement = placementOf(interactions[index]);\n\t\treturn `<span class=\"qti-interaction-slot qti-interaction-slot--${placement}\" ${INTERACTION_SLOT_ATTRIBUTE}=\"${id}\"></span>`;\n\t};\n\n\tconst collectStageInteractions = (element: ParsedHtmlElement, found: number[]): void => {\n\t\tfor (const child of elementChildren(element)) {\n\t\t\tconst index = takeInteraction(child);\n\t\t\tif (index !== undefined) found.push(index);\n\t\t\telse collectStageInteractions(child, found);\n\t\t}\n\t};\n\n\tconst visit = (parent: ParsedHtmlElement): void => {\n\t\tfor (const child of elementChildren(parent)) {\n\t\t\tif (child.hasAttribute(INTERACTION_SLOT_ATTRIBUTE)) {\n\t\t\t\tchild.removeAttribute(INTERACTION_SLOT_ATTRIBUTE);\n\t\t\t}\n\t\t\tconst tagName = child.rawTagName ?? '';\n\n\t\t\tif (POSITION_OBJECT_STAGE.test(tagName)) {\n\t\t\t\tconst found: number[] = [];\n\t\t\t\tcollectStageInteractions(child, found);\n\t\t\t\tchild.replaceWith(found.length > 0 ? found.map(slotMarkup).join('') : hiddenMarkup(child));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst index = takeInteraction(child);\n\t\t\tif (index !== undefined) {\n\t\t\t\tchild.replaceWith(slotMarkup(index));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (INTERACTION_TAG.test(tagName)) {\n\t\t\t\tchild.replaceWith(hiddenMarkup(child));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvisit(child);\n\t\t}\n\t};\n\n\tconst root = parse(html, { lowerCaseTagName: false, comment: false });\n\tvisit(root as unknown as ParsedHtmlElement);\n\treturn { html: root.toString(), slots };\n}\n\n/** Whether the final body markup still carries `slot`, after sanitation has run over it. */\nexport function hasInteractionSlot(html: string, slot: string): boolean {\n\treturn html.includes(`${INTERACTION_SLOT_ATTRIBUTE}=\"${slot}\"`);\n}\n\nfunction elementChildren(element: ParsedHtmlElement): ParsedHtmlElement[] {\n\treturn (element.childNodes as unknown as ParsedHtmlElement[]).filter(\n\t\t(node) => node.nodeType === NodeType.ELEMENT_NODE,\n\t);\n}\n\n/** Slot hiding reads the binding on the HTML tree, without a mapper. */\nfunction responseIdentifierOf(element: ParsedHtmlElement): string | undefined {\n\treturn readResponseIdentifier(element);\n}\n\n/**\n * Interaction markup with no interaction data behind it is kept hidden in the body, never shown\n * as raw prompt and choice text.\n */\nfunction hiddenMarkup(element: ParsedHtmlElement): string {\n\treturn `<span class=\"qti-hidden-interaction\">${element.toString()}</span>`;\n}\n"]}
|
|
@@ -4,7 +4,9 @@ import type { ComponentRegistry } from '../core/ComponentRegistry.js';
|
|
|
4
4
|
import type { PnpProfile } from '../pnp/types.js';
|
|
5
5
|
import { type RoleCapabilities } from '../core/rolePolicy.js';
|
|
6
6
|
import type { HtmlContent, PlayerSecurityConfig, QTIRole, RubricBlock } from '../types/index.js';
|
|
7
|
+
import { type ShownFeedback } from './feedbackAnnouncement.js';
|
|
7
8
|
import type { BaseInteractionData, InlineChoiceInteractionData, TextEntryInteractionData } from '../interactions/shared/types.js';
|
|
9
|
+
export { INTERACTION_SLOT_ATTRIBUTE } from './interactionSlots.js';
|
|
8
10
|
export type ItemPresentationResponseValue = unknown;
|
|
9
11
|
export type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;
|
|
10
12
|
/**
|
|
@@ -48,6 +50,12 @@ export interface BlockInteractionMount {
|
|
|
48
50
|
readonly interaction: BaseInteractionData;
|
|
49
51
|
readonly tagName: string;
|
|
50
52
|
readonly key: string;
|
|
53
|
+
/**
|
|
54
|
+
* The slot this interaction mounts into: the `data-qti-interaction-slot` value of the empty
|
|
55
|
+
* placeholder at its authored position in the body HTML. Null when the interaction's element
|
|
56
|
+
* is not in the body; the interaction then renders after the body.
|
|
57
|
+
*/
|
|
58
|
+
readonly slot: string | null;
|
|
51
59
|
readonly response: ItemPresentationResponseValue | null;
|
|
52
60
|
/** Lexical companion value used by extendedTextInteraction stringIdentifier. */
|
|
53
61
|
readonly stringResponse?: ItemPresentationResponseValue | null;
|
|
@@ -60,16 +68,51 @@ export interface BlockInteractionMount {
|
|
|
60
68
|
readonly disabled: boolean;
|
|
61
69
|
readonly componentRole: 'scorer' | undefined;
|
|
62
70
|
}
|
|
63
|
-
|
|
71
|
+
/** Where an inline interaction sits among the item's inline interactions, in document order. */
|
|
72
|
+
export interface InlineInteractionPosition {
|
|
73
|
+
/** 1-based. */
|
|
74
|
+
readonly index: number;
|
|
75
|
+
readonly count: number;
|
|
76
|
+
}
|
|
77
|
+
interface InlineInteractionMountBase {
|
|
64
78
|
readonly placement: 'inline';
|
|
79
|
+
readonly key: string;
|
|
80
|
+
/** As for {@link BlockInteractionMount.slot}; the slot stays in its sentence. */
|
|
81
|
+
readonly slot: string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Its position among the item's inline interactions, which names it for assistive
|
|
84
|
+
* technology ("Blank 2 of 4") when no label is authored. The response identifier never
|
|
85
|
+
* does: it is author data and can hint at the answer.
|
|
86
|
+
*/
|
|
87
|
+
readonly position: InlineInteractionPosition;
|
|
88
|
+
}
|
|
89
|
+
export type InlineInteractionMount = (InlineInteractionMountBase & {
|
|
65
90
|
readonly renderer: 'text-entry';
|
|
66
91
|
readonly interaction: TextEntryInteractionData;
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
/**
|
|
93
|
+
* The text the candidate entered, held by the response the interaction's
|
|
94
|
+
* stringIdentifier names: the field shows it while it is present, so "3.50" is restored
|
|
95
|
+
* as typed rather than as the numeric response's 3.5.
|
|
96
|
+
*/
|
|
97
|
+
readonly stringResponse?: ItemPresentationResponseValue | null;
|
|
98
|
+
}) | (InlineInteractionMountBase & {
|
|
69
99
|
readonly renderer: 'inline-choice';
|
|
70
100
|
readonly interaction: InlineChoiceInteractionData;
|
|
71
|
-
};
|
|
101
|
+
});
|
|
72
102
|
export type ItemInteractionMount = InlineInteractionMount | BlockInteractionMount;
|
|
103
|
+
/**
|
|
104
|
+
* An interaction whose web component the registry could not resolve: it has no mount in
|
|
105
|
+
* `flow`, the body keeps rendering around it, and it still owns its slot. The presenter
|
|
106
|
+
* stands the render-failed `role="alert"` placeholder — the same one a mount that throws
|
|
107
|
+
* gets — in that slot.
|
|
108
|
+
*/
|
|
109
|
+
export interface FailedInteractionMount {
|
|
110
|
+
/** Unique key, drawn from the same keying the mounts use. */
|
|
111
|
+
readonly key: string;
|
|
112
|
+
/** As for {@link BlockInteractionMount.slot}. */
|
|
113
|
+
readonly slot: string | null;
|
|
114
|
+
readonly interaction: BaseInteractionData;
|
|
115
|
+
}
|
|
73
116
|
declare const finalItemBodyHtmlBrand: unique symbol;
|
|
74
117
|
/** HTML that has completed every body transform, sanitation, and Trusted Types finalization. */
|
|
75
118
|
export type FinalItemBodyHtml = HtmlContent & {
|
|
@@ -90,11 +133,31 @@ export interface ItemPresentation {
|
|
|
90
133
|
readonly correctResponses: Readonly<Record<string, unknown>>;
|
|
91
134
|
/** Direct assessmentItem rubrics that remain outside the item-body flow. */
|
|
92
135
|
readonly directRubrics: readonly RubricBlock[];
|
|
93
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* Ordered, render-neutral body flow: one `html` node holding the whole item body, then every
|
|
138
|
+
* interaction mount in document order. The body keeps each interaction's authored position as
|
|
139
|
+
* an empty slot element (`[data-qti-interaction-slot]`); render the body once and mount each
|
|
140
|
+
* interaction into the slot its `slot` names, which keeps block interactions between the
|
|
141
|
+
* paragraphs, layout columns and table cells they were authored in and inline interactions in
|
|
142
|
+
* their sentence. A mount whose `slot` is null renders after the body.
|
|
143
|
+
*/
|
|
94
144
|
readonly flow: readonly ItemPresentationFlowNode[];
|
|
145
|
+
/**
|
|
146
|
+
* Interactions whose component the registry failed to resolve (no component renders the
|
|
147
|
+
* type), with the slot each authored. The host heard each failure once through
|
|
148
|
+
* `onComponentError`; the presenter keeps the candidate-facing half of that contract —
|
|
149
|
+
* the visible placeholder — in place while the failure stands.
|
|
150
|
+
*/
|
|
151
|
+
readonly failedInteractions: readonly FailedInteractionMount[];
|
|
95
152
|
/** Policy-checked CSS is kept out of the HTML/Trusted Types pipeline. */
|
|
96
153
|
readonly scopedCss: string;
|
|
154
|
+
/**
|
|
155
|
+
* The feedbackInline and feedbackBlock this body shows, read as accessible text in document
|
|
156
|
+
* order. The plan splices shown feedback into the body and leaves no marker behind, so this is
|
|
157
|
+
* the one place the shown feedback survives as data — the item body announces it while the
|
|
158
|
+
* candidate can still hear it (WCAG 4.1.3 Status Messages).
|
|
159
|
+
*/
|
|
160
|
+
readonly shownFeedback: ShownFeedback;
|
|
97
161
|
}
|
|
98
162
|
export declare function createItemPresentation({ source, responses, disabled, role, outcomeValues, heuristicsConfig, itemBodyScopeSelector, renderItemBodyRubrics, showFeedback, showSolution, onComponentError, }: CreateItemPresentationOptions): ItemPresentation;
|
|
99
163
|
export declare function interactionKey(interaction: BaseInteractionData): string;
|
|
100
|
-
export {};
|