@pie-qti/item-player 1.0.0-beta.3 → 1.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -5
- package/dist/catalog/applyGlossaryTriggers.js +14 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +2 -4
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/sessionCatalog.d.ts +46 -0
- package/dist/catalog/sessionCatalog.js +87 -0
- package/dist/catalog/sessionCatalog.js.map +1 -0
- package/dist/components/utils/endAttempt.d.ts +16 -0
- package/dist/components/utils/endAttempt.js +28 -0
- package/dist/components/utils/endAttempt.js.map +1 -0
- package/dist/components/utils/focus.d.ts +19 -0
- package/dist/components/utils/focus.js +67 -0
- package/dist/components/utils/focus.js.map +1 -0
- package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
- package/dist/components/utils/itemBodyRenderer.js +177 -0
- package/dist/components/utils/itemBodyRenderer.js.map +1 -0
- package/dist/components/utils/sentenceContext.d.ts +6 -0
- package/dist/components/utils/sentenceContext.js +16 -0
- package/dist/components/utils/sentenceContext.js.map +1 -0
- package/dist/core/AssessmentItemDefinition.d.ts +20 -1
- package/dist/core/AssessmentItemDefinition.js +12 -31
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ComponentRegistry.d.ts +92 -0
- package/dist/core/ComponentRegistry.js +7 -1
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +18 -1
- package/dist/core/ItemSession.js +79 -41
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +118 -141
- package/dist/core/Player.js +387 -1233
- package/dist/core/Player.js.map +1 -1
- package/dist/core/compliance.d.ts +72 -0
- package/dist/core/compliance.js +147 -0
- package/dist/core/compliance.js.map +1 -0
- package/dist/core/declarations/declarationBuilder.d.ts +29 -0
- package/dist/core/declarations/declarationBuilder.js +284 -0
- package/dist/core/declarations/declarationBuilder.js.map +1 -0
- package/dist/core/declarations/declarationValues.d.ts +11 -0
- package/dist/core/declarations/declarationValues.js +168 -0
- package/dist/core/declarations/declarationValues.js.map +1 -0
- package/dist/core/matchGroups.d.ts +36 -0
- package/dist/core/matchGroups.js +100 -0
- package/dist/core/matchGroups.js.map +1 -0
- package/dist/core/nameMappers.d.ts +35 -0
- package/dist/core/nameMappers.js +47 -0
- package/dist/core/nameMappers.js.map +1 -0
- package/dist/core/parsingLimits.d.ts +4 -0
- package/dist/core/parsingLimits.js +5 -2
- package/dist/core/parsingLimits.js.map +1 -1
- package/dist/core/processing/responseProcessing.d.ts +88 -0
- package/dist/core/processing/responseProcessing.js +317 -0
- package/dist/core/processing/responseProcessing.js.map +1 -0
- package/dist/core/processing/responseValidation.d.ts +55 -0
- package/dist/core/processing/responseValidation.js +335 -0
- package/dist/core/processing/responseValidation.js.map +1 -0
- package/dist/core/rendering/contentPass.d.ts +31 -0
- package/dist/core/rendering/contentPass.js +152 -0
- package/dist/core/rendering/contentPass.js.map +1 -0
- package/dist/core/rendering/htmlRender.d.ts +21 -0
- package/dist/core/rendering/htmlRender.js +56 -0
- package/dist/core/rendering/htmlRender.js.map +1 -0
- package/dist/core/responseProcessingTemplates.d.ts +23 -0
- package/dist/core/responseProcessingTemplates.js +45 -0
- package/dist/core/responseProcessingTemplates.js.map +1 -0
- package/dist/core/rolePolicy.d.ts +5 -0
- package/dist/core/rolePolicy.js +21 -0
- package/dist/core/rolePolicy.js.map +1 -1
- package/dist/core/sanitizer.js +8 -14
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/serialization/sessionState.d.ts +56 -0
- package/dist/core/serialization/sessionState.js +139 -0
- package/dist/core/serialization/sessionState.js.map +1 -0
- package/dist/core/serialization/valueForms.d.ts +32 -0
- package/dist/core/serialization/valueForms.js +112 -0
- package/dist/core/serialization/valueForms.js.map +1 -0
- package/dist/document/AssessmentItemDocument.d.ts +27 -1
- package/dist/document/AssessmentItemDocument.js +67 -31
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/element-class-BbF4Dj7F.js +3773 -0
- package/dist/element-class-BbF4Dj7F.js.map +1 -0
- package/dist/element-class.d.ts +34 -1
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.js +6 -12
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionCoverage.d.ts +31 -0
- package/dist/extraction/interactionCoverage.js +40 -0
- package/dist/extraction/interactionCoverage.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.js +5 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.js +1 -28
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
- package/dist/extraction/mergeDeliveryFields.js +17 -0
- package/dist/extraction/mergeDeliveryFields.js.map +1 -0
- package/dist/extraction/responseIdentifier.d.ts +19 -0
- package/dist/extraction/responseIdentifier.js +29 -0
- package/dist/extraction/responseIdentifier.js.map +1 -0
- package/dist/extraction/types.d.ts +11 -18
- package/dist/extraction/types.js +0 -12
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.d.ts +14 -0
- package/dist/extraction/utils.js +35 -5
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.d.ts +1 -0
- package/dist/interactions/associate/extractor.js +10 -12
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +6 -13
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.d.ts +6 -0
- package/dist/interactions/drawing/extractor.js +30 -9
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -1
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -1
- package/dist/interactions/extended-text/extractor.js +10 -5
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/response.js +18 -18
- package/dist/interactions/extended-text/response.js.map +1 -1
- package/dist/interactions/gap-match/extractor.d.ts +40 -2
- package/dist/interactions/gap-match/extractor.js +197 -39
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
- package/dist/interactions/graphic-associate/extractor.js +35 -24
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
- package/dist/interactions/graphic-gap-match/extractor.js +79 -43
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.d.ts +15 -0
- package/dist/interactions/graphic-order/extractor.js +39 -24
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.d.ts +6 -0
- package/dist/interactions/hotspot/extractor.js +31 -16
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/hottext/extractor.js +2 -12
- package/dist/interactions/hottext/extractor.js.map +1 -1
- package/dist/interactions/inline/accessibleName.d.ts +29 -0
- package/dist/interactions/inline/accessibleName.js +35 -0
- package/dist/interactions/inline/accessibleName.js.map +1 -0
- package/dist/interactions/inline/render-plan.d.ts +5 -14
- package/dist/interactions/inline/render-plan.js +5 -56
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.d.ts +4 -0
- package/dist/interactions/inline-choice/extractor.js +13 -12
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.d.ts +2 -0
- package/dist/interactions/match/extractor.js +14 -28
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/media/extractor.d.ts +5 -11
- package/dist/interactions/media/extractor.js +100 -36
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.js +8 -2
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.d.ts +2 -0
- package/dist/interactions/order/extractor.js +8 -12
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/order/limits.d.ts +29 -0
- package/dist/interactions/order/limits.js +28 -0
- package/dist/interactions/order/limits.js.map +1 -0
- package/dist/interactions/portable-custom/extractor.js +4 -2
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +18 -1
- package/dist/interactions/position-object/extractor.js +81 -22
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.d.ts +6 -0
- package/dist/interactions/select-point/extractor.js +31 -19
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/imageAlt.d.ts +54 -0
- package/dist/interactions/shared/imageAlt.js +84 -0
- package/dist/interactions/shared/imageAlt.js.map +1 -0
- package/dist/interactions/shared/interactionImage.d.ts +32 -0
- package/dist/interactions/shared/interactionImage.js +39 -0
- package/dist/interactions/shared/interactionImage.js.map +1 -0
- package/dist/interactions/shared/specDefaults.d.ts +20 -0
- package/dist/interactions/shared/specDefaults.js +25 -0
- package/dist/interactions/shared/specDefaults.js.map +1 -0
- package/dist/interactions/shared/types.d.ts +212 -40
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/text-entry/extractor.d.ts +9 -0
- package/dist/interactions/text-entry/extractor.js +9 -0
- package/dist/interactions/text-entry/extractor.js.map +1 -1
- package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
- package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
- package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
- package/dist/interactions/text-entry/inputMode.d.ts +35 -0
- package/dist/interactions/text-entry/inputMode.js +134 -0
- package/dist/interactions/text-entry/inputMode.js.map +1 -0
- package/dist/interactions/text-entry/response.d.ts +15 -0
- package/dist/interactions/text-entry/response.js +25 -0
- package/dist/interactions/text-entry/response.js.map +1 -0
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/PciHost.d.ts +1 -1
- package/dist/pci/PciHost.js +11 -11
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +1 -0
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/modulePaths.d.ts +16 -0
- package/dist/pci/modulePaths.js +33 -0
- package/dist/pci/modulePaths.js.map +1 -0
- package/dist/pci/pageRealmSession.js +3 -15
- package/dist/pci/pageRealmSession.js.map +1 -1
- package/dist/pci/qtiVariableJson.d.ts +46 -3
- package/dist/pci/qtiVariableJson.js +247 -53
- package/dist/pci/qtiVariableJson.js.map +1 -1
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
- package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
- package/dist/pci/sandbox/iframeConnector.js +35 -6
- package/dist/pci/sandbox/iframeConnector.js.map +1 -1
- package/dist/pci/sandbox/protocol.d.ts +14 -0
- package/dist/pci/sandbox/protocol.js.map +1 -1
- package/dist/pci/sessionHosts.d.ts +47 -0
- package/dist/pci/sessionHosts.js +66 -0
- package/dist/pci/sessionHosts.js.map +1 -0
- package/dist/pci/types.d.ts +7 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +20 -3
- package/dist/pnp/applyPnp.js +84 -9
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.js +2 -0
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +16 -8
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
- package/dist/presentation/feedbackAnnouncement.js +150 -0
- package/dist/presentation/feedbackAnnouncement.js.map +1 -0
- package/dist/presentation/interactionSlots.d.ts +31 -0
- package/dist/presentation/interactionSlots.js +101 -0
- package/dist/presentation/interactionSlots.js.map +1 -0
- package/dist/presentation/itemPresentationPlan.d.ts +69 -6
- package/dist/presentation/itemPresentationPlan.js +93 -81
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
- package/dist/presentation/stimulusRender.js.map +1 -0
- package/dist/presentation/stylesheetRender.js.map +1 -0
- package/dist/security/escapeHtml.d.ts +15 -0
- package/dist/security/escapeHtml.js +22 -0
- package/dist/security/escapeHtml.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/server.d.ts +8 -1
- package/dist/server.js.map +1 -1
- package/dist/session-inputs.d.ts +108 -0
- package/dist/session-inputs.js +130 -0
- package/dist/session-inputs.js.map +1 -0
- package/dist/types/index.d.ts +67 -35
- package/dist/types/index.js.map +1 -1
- package/dist/utils/cloneFreeze.d.ts +52 -0
- package/dist/utils/cloneFreeze.js +113 -0
- package/dist/utils/cloneFreeze.js.map +1 -0
- package/dist/utils/htmlAttributes.d.ts +13 -0
- package/dist/utils/htmlAttributes.js +22 -0
- package/dist/utils/htmlAttributes.js.map +1 -0
- package/dist/web-components/QTIInteractionElement.d.ts +0 -29
- package/dist/web-components/QTIInteractionElement.js +0 -32
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/dist/web-components/index.d.ts +1 -2
- package/dist/web-components/index.js +2 -3
- package/dist/web-components/index.js.map +1 -1
- package/package.json +15 -18
- package/dist/components/utils/feedbackUtils.d.ts +0 -77
- package/dist/components/utils/feedbackUtils.js +0 -138
- package/dist/components/utils/feedbackUtils.js.map +0 -1
- package/dist/components/utils/index.d.ts +0 -4
- package/dist/components/utils/index.js +0 -5
- package/dist/components/utils/index.js.map +0 -1
- 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-X2XXDa29.js +0 -9299
- package/dist/element-class-X2XXDa29.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,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response, template and outcome processing execution: the evaluator environment,
|
|
3
|
+
* the compiled program runs, the standard response-processing templates, the variable
|
|
4
|
+
* resets a new template instance starts from, and the scoring result assembly.
|
|
5
|
+
*/
|
|
6
|
+
import { evalExpr, execProgram, isNullValue, qtiNull, qtiValue, toBoolean, toNumber, } from '@pie-qti/qti-processing';
|
|
7
|
+
import { resolveResponseProcessingTemplate, UnsupportedResponseProcessingTemplateError, } from '../responseProcessingTemplates.js';
|
|
8
|
+
import { cloneValue } from '../../utils/cloneFreeze.js';
|
|
9
|
+
/**
|
|
10
|
+
* The evaluator's environment, which reads responses in the item's content language and
|
|
11
|
+
* compares strings with the host's string comparison folds.
|
|
12
|
+
*/
|
|
13
|
+
export function processingEnv(host) {
|
|
14
|
+
return {
|
|
15
|
+
ctx: host.ctx,
|
|
16
|
+
rng: host.rng,
|
|
17
|
+
language: host.getContentLanguage(),
|
|
18
|
+
stringComparison: host.config.stringComparison,
|
|
19
|
+
customOperators: host.config.customOperators,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function execTemplateProcessingProgram(host) {
|
|
23
|
+
if (!host.templateProcessingProgram)
|
|
24
|
+
return;
|
|
25
|
+
execProgram(processingEnv(host), host.templateProcessingProgram);
|
|
26
|
+
}
|
|
27
|
+
export function execResponseProcessingProgram(host) {
|
|
28
|
+
if (!host.responseProcessingProgram)
|
|
29
|
+
return;
|
|
30
|
+
execProgram(processingEnv(host), host.responseProcessingProgram);
|
|
31
|
+
}
|
|
32
|
+
export function execOutcomeProcessingProgram(host) {
|
|
33
|
+
if (!host.outcomeProcessingProgram)
|
|
34
|
+
return;
|
|
35
|
+
execProgram(processingEnv(host), host.outcomeProcessingProgram);
|
|
36
|
+
}
|
|
37
|
+
export function execResponseProcessingTemplate(host, templateUrl) {
|
|
38
|
+
const name = resolveResponseProcessingTemplate(templateUrl);
|
|
39
|
+
// Compilation rejects unsupported templates; this guards a hand-built prepared definition.
|
|
40
|
+
if (!name)
|
|
41
|
+
throw unsupportedTemplateError(host, templateUrl);
|
|
42
|
+
const responseMatchesCorrect = () => {
|
|
43
|
+
const expression = {
|
|
44
|
+
kind: 'expr.match',
|
|
45
|
+
id: 'fixed-template-match',
|
|
46
|
+
a: { kind: 'expr.variable', id: 'fixed-template-response', identifier: 'RESPONSE' },
|
|
47
|
+
b: { kind: 'expr.correct', id: 'fixed-template-correct', identifier: 'RESPONSE' },
|
|
48
|
+
};
|
|
49
|
+
return toBoolean(evalExpr(processingEnv(host), expression));
|
|
50
|
+
};
|
|
51
|
+
const setScore = (value) => {
|
|
52
|
+
host.ctx.setValue('SCORE', qtiValue('float', 'single', value));
|
|
53
|
+
};
|
|
54
|
+
const setIdentifierOutcome = (identifier, value) => {
|
|
55
|
+
host.ctx.setValue(identifier, qtiValue('identifier', 'single', value));
|
|
56
|
+
};
|
|
57
|
+
const mapResponse = (point) => {
|
|
58
|
+
const response = host.ctx.getValue('RESPONSE');
|
|
59
|
+
// The official templates guard with isNull, which reads an empty container or empty string
|
|
60
|
+
// as NULL too (QTI ASI §5): a cleared response scores 0, rather than being mapped, whose
|
|
61
|
+
// result the mapping's bounds could clamp away from 0.
|
|
62
|
+
if (isNullValue(response))
|
|
63
|
+
return 0;
|
|
64
|
+
const mapped = evalExpr(processingEnv(host), {
|
|
65
|
+
kind: point ? 'expr.mapResponsePoint' : 'expr.mapResponse',
|
|
66
|
+
id: point ? 'fixed-template-map-response-point' : 'fixed-template-map-response',
|
|
67
|
+
identifier: 'RESPONSE',
|
|
68
|
+
});
|
|
69
|
+
const value = toNumber(mapped);
|
|
70
|
+
return Number.isFinite(value) ? value : 0;
|
|
71
|
+
};
|
|
72
|
+
switch (name) {
|
|
73
|
+
case 'match_correct':
|
|
74
|
+
case 'cc2_match': {
|
|
75
|
+
setScore(responseMatchesCorrect() ? 1 : 0);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
case 'cc2_match_basic': {
|
|
79
|
+
if (responseMatchesCorrect()) {
|
|
80
|
+
const maxScore = toNumber(host.ctx.getValue('MAXSCORE'));
|
|
81
|
+
host.ctx.setValue('SCORE', Number.isFinite(maxScore) ? qtiValue('float', 'single', maxScore) : qtiNull('float', 'single'));
|
|
82
|
+
setIdentifierOutcome('FEEDBACKBASIC', 'correct');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
setIdentifierOutcome('FEEDBACKBASIC', 'incorrect');
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
case 'match_nothing':
|
|
90
|
+
case 'cc2_match_nothing': { // Official IMS QTI 3.0 rptemplate
|
|
91
|
+
const isEmptyResponse = (v) => {
|
|
92
|
+
if (!v)
|
|
93
|
+
return true;
|
|
94
|
+
if (v.kind === 'null')
|
|
95
|
+
return true;
|
|
96
|
+
if (v.kind === 'invalid')
|
|
97
|
+
return false;
|
|
98
|
+
if (v.value === null || v.value === undefined)
|
|
99
|
+
return true;
|
|
100
|
+
if (Array.isArray(v.value))
|
|
101
|
+
return v.value.length === 0;
|
|
102
|
+
if (typeof v.value === 'string')
|
|
103
|
+
return v.value.trim().length === 0;
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
const allEmpty = isEmptyResponse(host.ctx.getValue('RESPONSE'));
|
|
107
|
+
const max = toNumber(host.ctx.getValue('MAXSCORE'));
|
|
108
|
+
host.ctx.setValue('SCORE', qtiValue('float', 'single', allEmpty ? (Number.isFinite(max) ? max : 1) : 0));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
case 'map_response': {
|
|
112
|
+
setScore(mapResponse(false));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
case 'cc2_map_response': {
|
|
116
|
+
const score = mapResponse(false);
|
|
117
|
+
setScore(score);
|
|
118
|
+
const maxScore = toNumber(host.ctx.getValue('MAXSCORE'));
|
|
119
|
+
setIdentifierOutcome('FEEDBACK', Number.isFinite(maxScore) && score === maxScore ? 'correct' : 'incorrect');
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
case 'map_response_point':
|
|
123
|
+
case 'cc2_map_response_point': { // Official IMS QTI 3.0 rptemplate
|
|
124
|
+
setScore(mapResponse(true));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
case 'no_response_processing': {
|
|
128
|
+
// The standard empty template: outcomes keep their defaults (unscored item).
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A template reference is the item's only scoring rule when responseProcessing has no rules of
|
|
135
|
+
* its own. Without a built-in program for that template the item would score its defaults
|
|
136
|
+
* silently, so compilation fails instead (docs/SPEC-GAPS-PLAN.md G-19).
|
|
137
|
+
*/
|
|
138
|
+
export function assertSupportedResponseProcessing(host) {
|
|
139
|
+
const { present, hasStatements, template } = host.responseProcessing;
|
|
140
|
+
if (!present || hasStatements || !template)
|
|
141
|
+
return;
|
|
142
|
+
if (resolveResponseProcessingTemplate(template))
|
|
143
|
+
return;
|
|
144
|
+
throw unsupportedTemplateError(host, template);
|
|
145
|
+
}
|
|
146
|
+
export function unsupportedTemplateError(host, templateUri) {
|
|
147
|
+
return new UnsupportedResponseProcessingTemplateError(templateUri, host.itemDocument.getAssessmentItemAttribute('identifier') ?? undefined);
|
|
148
|
+
}
|
|
149
|
+
export function resetOutcomesToDefault(host) {
|
|
150
|
+
for (const d of Object.values(host.decls)) {
|
|
151
|
+
if (d.__kind !== 'outcome')
|
|
152
|
+
continue;
|
|
153
|
+
// Built-in stateful variables must survive across processing runs.
|
|
154
|
+
// They are updated by the runtime (adaptive attempt tracking), not by outcome defaults.
|
|
155
|
+
if (d.identifier === 'numAttempts' || d.identifier === 'completionStatus' || d.identifier === 'duration')
|
|
156
|
+
continue;
|
|
157
|
+
host.ctx.resetToDefault(d.identifier);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export function resetResponsesToDefault(host) {
|
|
161
|
+
host.endAttemptActivations.clear();
|
|
162
|
+
for (const d of Object.values(host.decls)) {
|
|
163
|
+
if (d.__kind !== 'response')
|
|
164
|
+
continue;
|
|
165
|
+
host.ctx.resetToDefault(d.identifier);
|
|
166
|
+
host.restorePciResponse(d.identifier, host.qtiValueToPci(d.value));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export function resetTemplatesToDefault(host) {
|
|
170
|
+
for (const d of Object.values(host.decls)) {
|
|
171
|
+
if (!d.isTemplate)
|
|
172
|
+
continue;
|
|
173
|
+
host.ctx.resetToDefault(d.identifier);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* QTI ASI §10.3 with §5.1: template processing runs on a fresh instance of the item, so a new
|
|
178
|
+
* template instance starts from the declarations, not from the instance before it. The
|
|
179
|
+
* template rules setDefaultValue and setCorrectResponse change response and outcome
|
|
180
|
+
* declarations for one instance; their declared defaults and correct responses come back
|
|
181
|
+
* here, before the variables reset and template processing runs again. Template variables
|
|
182
|
+
* keep their defaults: template rules do not change them, and they hold the
|
|
183
|
+
* assessmentItemRef's templateDefault values (applied at session start, carried by a
|
|
184
|
+
* snapshot), which apply to every instance.
|
|
185
|
+
*/
|
|
186
|
+
export function restoreDeclaredTemplateRuleTargets(host) {
|
|
187
|
+
for (const d of Object.values(host.decls)) {
|
|
188
|
+
const kind = d.__kind;
|
|
189
|
+
if (kind !== 'response' && kind !== 'outcome')
|
|
190
|
+
continue;
|
|
191
|
+
const declared = host.sourceDeclarations[d.identifier];
|
|
192
|
+
if (!declared)
|
|
193
|
+
continue;
|
|
194
|
+
const fields = d;
|
|
195
|
+
if (declared.defaultValue)
|
|
196
|
+
fields.defaultValue = cloneValue(declared.defaultValue);
|
|
197
|
+
else
|
|
198
|
+
delete fields.defaultValue;
|
|
199
|
+
if (kind !== 'response')
|
|
200
|
+
continue;
|
|
201
|
+
if (declared.correctResponse)
|
|
202
|
+
fields.correctResponse = cloneValue(declared.correctResponse);
|
|
203
|
+
else
|
|
204
|
+
delete fields.correctResponse;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
export function runResponseProcessing(host, options) {
|
|
208
|
+
host.updateDuration();
|
|
209
|
+
// QTI ASI §5.1: numAttempts starts at 0 and is incremented at the start of each attempt,
|
|
210
|
+
// so the response processing that ends a counted attempt reads that attempt's own
|
|
211
|
+
// number (1 on the first). The adaptive path counts in runAdaptiveSubmitAttempt; an
|
|
212
|
+
// uncounted attempt (countAttempt=false) and a scoring pass (scoreAttempt) do not count.
|
|
213
|
+
const countsAttempt = options.finalizeNonAdaptiveAttempt && (options.countAttempt ?? true);
|
|
214
|
+
if (!host.isAdaptive() && countsAttempt) {
|
|
215
|
+
host.ctx.setValue('numAttempts', qtiValue('integer', 'single', host.getNumAttempts() + 1));
|
|
216
|
+
}
|
|
217
|
+
// QTI ASI §5.2: for a non-adaptive item, outcome variables are reset to their defaults
|
|
218
|
+
// before each invocation of response processing. An adaptive item's outcomes "retain the
|
|
219
|
+
// values that were assigned to them during the previous invocation" (§5.2, §8), so they
|
|
220
|
+
// carry across attempts — and across a save/restore, which restores them as saved. They
|
|
221
|
+
// start from their defaults only at session start and on newTemplate.
|
|
222
|
+
if (!host.isAdaptive()) {
|
|
223
|
+
resetOutcomesToDefault(host);
|
|
224
|
+
}
|
|
225
|
+
// Execute response processing if present
|
|
226
|
+
if (host.responseProcessing.present) {
|
|
227
|
+
// If responseProcessing has explicit statements, run the compiled program.
|
|
228
|
+
// Otherwise, fall back to template-based processing (responseProcessing@template).
|
|
229
|
+
if (host.responseProcessing.hasStatements) {
|
|
230
|
+
execResponseProcessingProgram(host);
|
|
231
|
+
}
|
|
232
|
+
else if (host.responseProcessing.template) {
|
|
233
|
+
execResponseProcessingTemplate(host, host.responseProcessing.template);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Execute outcome processing if present (runs after responseProcessing)
|
|
237
|
+
execOutcomeProcessingProgram(host);
|
|
238
|
+
// Compatibility: processResponses() has historically finalized non-adaptive items.
|
|
239
|
+
// New scoreAttempt() uses this same engine with finalization disabled.
|
|
240
|
+
// QTI ASI §5.2.1: submitting a non-adaptive item's attempt completes it — response
|
|
241
|
+
// processing "completes" the item session, so completionStatus moves to `completed`
|
|
242
|
+
// here even when the item has no rules of its own (an unscored item still completed
|
|
243
|
+
// its attempt). An adaptive item's completionStatus is its response processing's
|
|
244
|
+
// decision; a `completed` assignment authored in rules (as above for non-adaptive)
|
|
245
|
+
// stays whatever the rules made it. `incomplete` is never engine-assigned: rules set
|
|
246
|
+
// it, or the session stays `unknown`. See Player.beginAttempt for the earlier
|
|
247
|
+
// transitions of this variable.
|
|
248
|
+
if (!host.isAdaptive() && options.finalizeNonAdaptiveAttempt) {
|
|
249
|
+
host.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'completed'));
|
|
250
|
+
}
|
|
251
|
+
const outcomes = collectOutcomes(host);
|
|
252
|
+
warnOnceOnImpliedZeroMaxScore(host, outcomes);
|
|
253
|
+
const score = Number(outcomes.SCORE ?? 0);
|
|
254
|
+
const maxScore = Number(outcomes.MAXSCORE ?? 1);
|
|
255
|
+
const completionStatus = outcomes.completionStatus ?? 'not_attempted';
|
|
256
|
+
const completed = completionStatus === 'completed' || (!host.isAdaptive() && options.finalizeNonAdaptiveAttempt);
|
|
257
|
+
return {
|
|
258
|
+
score,
|
|
259
|
+
maxScore,
|
|
260
|
+
completed,
|
|
261
|
+
outcomeValues: outcomes,
|
|
262
|
+
correct: responsesMatchCorrect(host),
|
|
263
|
+
modalFeedback: host.getModalFeedback(outcomes),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* QTI item correctness, as test-level `numberCorrect` reads it: every declared response matches
|
|
268
|
+
* its correct response. Undefined when the item has no response or one declares no correct
|
|
269
|
+
* response.
|
|
270
|
+
*/
|
|
271
|
+
export function responsesMatchCorrect(host) {
|
|
272
|
+
const responses = Object.values(host.decls).filter((d) => d.__kind === 'response');
|
|
273
|
+
if (responses.length === 0 || responses.some((d) => d.correctResponse?.kind !== 'value'))
|
|
274
|
+
return undefined;
|
|
275
|
+
const env = processingEnv(host);
|
|
276
|
+
return responses.every((d) => toBoolean(evalExpr(env, {
|
|
277
|
+
kind: 'expr.match',
|
|
278
|
+
id: `correct-${d.identifier}`,
|
|
279
|
+
a: { kind: 'expr.variable', id: `correct-${d.identifier}-response`, identifier: d.identifier },
|
|
280
|
+
b: { kind: 'expr.correct', id: `correct-${d.identifier}-correct`, identifier: d.identifier },
|
|
281
|
+
})));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* A MAXSCORE declared without a <defaultValue> is 0 per the numeric outcome rule, so an item
|
|
285
|
+
* that never assigns it scores against a maximum of zero. That is the spec-correct reading of
|
|
286
|
+
* under-specified content, and silently substituting 1 would make this engine disagree with a
|
|
287
|
+
* conformant one — so surface the authoring gap instead of masking it.
|
|
288
|
+
*/
|
|
289
|
+
function warnOnceOnImpliedZeroMaxScore(host, outcomes) {
|
|
290
|
+
if (host.warnedImpliedZeroMaxScore)
|
|
291
|
+
return;
|
|
292
|
+
if (!host.decls.MAXSCORE?.impliedNumericDefault)
|
|
293
|
+
return;
|
|
294
|
+
if (outcomes.MAXSCORE !== 0)
|
|
295
|
+
return;
|
|
296
|
+
host.warnedImpliedZeroMaxScore = true;
|
|
297
|
+
console.warn(`[QTI Player] MAXSCORE is 0 for item "${host.itemDocument.getAssessmentItemAttribute('identifier') ?? 'unknown'}": its outcomeDeclaration ` +
|
|
298
|
+
'has no <defaultValue>, so QTI initializes it to 0 and response processing never assigned it. ' +
|
|
299
|
+
'Declare <defaultValue> on the MAXSCORE outcomeDeclaration to score against a real maximum.');
|
|
300
|
+
}
|
|
301
|
+
export function collectOutcomes(host) {
|
|
302
|
+
const out = {};
|
|
303
|
+
for (const d of Object.values(host.decls)) {
|
|
304
|
+
if (d.__kind !== 'outcome')
|
|
305
|
+
continue;
|
|
306
|
+
if (d.value.kind === 'value')
|
|
307
|
+
out[d.identifier] = host.qtiValueToPublic(d.value);
|
|
308
|
+
else if (d.value.kind === 'null')
|
|
309
|
+
out[d.identifier] = null;
|
|
310
|
+
}
|
|
311
|
+
// Ensure MAXSCORE always has a value (fallback to 1.0 if null or missing)
|
|
312
|
+
if (out.MAXSCORE === null || out.MAXSCORE === undefined) {
|
|
313
|
+
out.MAXSCORE = 1.0;
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=responseProcessing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseProcessing.js","sourceRoot":"","sources":["../../../src/core/processing/responseProcessing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAGN,QAAQ,EACR,WAAW,EACX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IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,qBAAqB;QAAE,OAAO;IACxD,IAAI,QAAQ,CAAC,QAAQ,KAAK,CAAC;QAAE,OAAO;IACpC,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,IAAI,CACX,wCAAwC,IAAI,CAAC,YAAY,CAAC,0BAA0B,CAAC,YAAY,CAAC,IAAI,SAAS,4BAA4B;QAC1I,+FAA+F;QAC/F,4FAA4F,CAC7F,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAA4B;IAC3D,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAK,CAAS,CAAC,MAAM,KAAK,SAAS;YAAE,SAAS;QAC9C,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;aAC5E,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IAC5D,CAAC;IACD,0EAA0E;IAC1E,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzD,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["/**\n * Response, template and outcome processing execution: the evaluator environment,\n * the compiled program runs, the standard response-processing templates, the variable\n * resets a new template instance starts from, and the scoring result assembly.\n */\nimport {\n\ttype DeclarationMap,\n\tDeclarationContext,\n\tevalExpr,\n\texecProgram,\n\tisNullValue,\n\ttype ProcessingProgram,\n\ttype QtiValue,\n\tqtiNull,\n\tqtiValue,\n\ttoBoolean,\n\ttoNumber,\n} from '@pie-qti/qti-processing';\nimport type { AssessmentItemDocument, ResponseProcessingDescriptor } from '../../document/AssessmentItemDocument.js';\nimport {\n\tresolveResponseProcessingTemplate,\n\tUnsupportedResponseProcessingTemplateError,\n} from '../responseProcessingTemplates.js';\nimport type { CompletionStatus, ItemSessionEngineConfig, ModalFeedback, ScoringResult } from '../../types/index.js';\nimport { cloneValue } from '../../utils/cloneFreeze.js';\n\n/** What response processing execution reads from the session engine. */\nexport interface ResponseProcessingHost {\n\treadonly itemDocument: AssessmentItemDocument;\n\treadonly config: ItemSessionEngineConfig;\n\treadonly decls: DeclarationMap;\n\t/** The declarations as compiled from the item source, before any template rule changed them. */\n\treadonly sourceDeclarations: DeclarationMap;\n\treadonly ctx: DeclarationContext;\n\treadonly rng: () => number;\n\treadonly responseProcessing: ResponseProcessingDescriptor;\n\treadonly responseProcessingProgram: ProcessingProgram | null;\n\treadonly templateProcessingProgram: ProcessingProgram | null;\n\treadonly outcomeProcessingProgram: ProcessingProgram | null;\n\t/**\n\t * End-attempt responses the candidate turned true since the attempt last ended; a response\n\t * reset to its default also deactivates (see resetResponsesToDefault).\n\t */\n\treadonly endAttemptActivations: Set<string>;\n\t/** Set once the implied-zero MAXSCORE warning has fired. */\n\twarnedImpliedZeroMaxScore: boolean;\n\tisAdaptive(): boolean;\n\tgetNumAttempts(): number;\n\tgetContentLanguage(): string | undefined;\n\tupdateDuration(): void;\n\trestorePciResponse(responseIdentifier: string, value: unknown): void;\n\tqtiValueToPci(value: QtiValue | undefined): unknown;\n\tqtiValueToPublic(value: QtiValue | undefined): any;\n\tgetModalFeedback(outcomes: Record<string, any>): ModalFeedback[];\n}\n\n/**\n * The evaluator's environment, which reads responses in the item's content language and\n * compares strings with the host's string comparison folds.\n */\nexport function processingEnv(host: ResponseProcessingHost) {\n\treturn {\n\t\tctx: host.ctx,\n\t\trng: host.rng,\n\t\tlanguage: host.getContentLanguage(),\n\t\tstringComparison: host.config.stringComparison,\n\t\tcustomOperators: host.config.customOperators,\n\t};\n}\n\nexport function execTemplateProcessingProgram(host: ResponseProcessingHost): void {\n\tif (!host.templateProcessingProgram) return;\n\texecProgram(\n\t\tprocessingEnv(host),\n\t\thost.templateProcessingProgram\n\t);\n}\n\nexport function execResponseProcessingProgram(host: ResponseProcessingHost): void {\n\tif (!host.responseProcessingProgram) return;\n\texecProgram(\n\t\tprocessingEnv(host),\n\t\thost.responseProcessingProgram\n\t);\n}\n\nexport function execOutcomeProcessingProgram(host: ResponseProcessingHost): void {\n\tif (!host.outcomeProcessingProgram) return;\n\texecProgram(\n\t\tprocessingEnv(host),\n\t\thost.outcomeProcessingProgram\n\t);\n}\n\nexport function execResponseProcessingTemplate(host: ResponseProcessingHost, templateUrl: string): void {\n\tconst name = resolveResponseProcessingTemplate(templateUrl);\n\t// Compilation rejects unsupported templates; this guards a hand-built prepared definition.\n\tif (!name) throw unsupportedTemplateError(host, templateUrl);\n\n\tconst responseMatchesCorrect = (): boolean => {\n\t\tconst expression = {\n\t\t\tkind: 'expr.match',\n\t\t\tid: 'fixed-template-match',\n\t\t\ta: { kind: 'expr.variable', id: 'fixed-template-response', identifier: 'RESPONSE' },\n\t\t\tb: { kind: 'expr.correct', id: 'fixed-template-correct', identifier: 'RESPONSE' },\n\t\t} as any;\n\t\treturn toBoolean(\n\t\t\tevalExpr(\n\t\t\t\tprocessingEnv(host),\n\t\t\t\texpression,\n\t\t\t),\n\t\t);\n\t};\n\n\tconst setScore = (value: number): void => {\n\t\thost.ctx.setValue('SCORE', qtiValue('float', 'single', value));\n\t};\n\n\tconst setIdentifierOutcome = (identifier: string, value: string): void => {\n\t\thost.ctx.setValue(identifier, qtiValue('identifier', 'single', value));\n\t};\n\n\tconst mapResponse = (point: boolean): number => {\n\t\tconst response = host.ctx.getValue('RESPONSE');\n\t\t// The official templates guard with isNull, which reads an empty container or empty string\n\t\t// as NULL too (QTI ASI §5): a cleared response scores 0, rather than being mapped, whose\n\t\t// result the mapping's bounds could clamp away from 0.\n\t\tif (isNullValue(response)) return 0;\n\t\tconst mapped = evalExpr(\n\t\t\tprocessingEnv(host),\n\t\t\t{\n\t\t\t\tkind: point ? 'expr.mapResponsePoint' : 'expr.mapResponse',\n\t\t\t\tid: point ? 'fixed-template-map-response-point' : 'fixed-template-map-response',\n\t\t\t\tidentifier: 'RESPONSE',\n\t\t\t} as any,\n\t\t);\n\t\tconst value = toNumber(mapped);\n\t\treturn Number.isFinite(value) ? value : 0;\n\t};\n\n\tswitch (name) {\n\t\tcase 'match_correct':\n\t\tcase 'cc2_match': {\n\t\t\tsetScore(responseMatchesCorrect() ? 1 : 0);\n\t\t\treturn;\n\t\t}\n\t\tcase 'cc2_match_basic': {\n\t\t\tif (responseMatchesCorrect()) {\n\t\t\t\tconst maxScore = toNumber(host.ctx.getValue('MAXSCORE'));\n\t\t\t\thost.ctx.setValue(\n\t\t\t\t\t'SCORE',\n\t\t\t\t\tNumber.isFinite(maxScore) ? qtiValue('float', 'single', maxScore) : qtiNull('float', 'single'),\n\t\t\t\t);\n\t\t\t\tsetIdentifierOutcome('FEEDBACKBASIC', 'correct');\n\t\t\t} else {\n\t\t\t\tsetIdentifierOutcome('FEEDBACKBASIC', 'incorrect');\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase 'match_nothing':\n\t\tcase 'cc2_match_nothing': { // Official IMS QTI 3.0 rptemplate\n\t\t\tconst isEmptyResponse = (v: QtiValue | undefined): boolean => {\n\t\t\t\tif (!v) return true;\n\t\t\t\tif (v.kind === 'null') return true;\n\t\t\t\tif (v.kind === 'invalid') return false;\n\t\t\t\tif (v.value === null || v.value === undefined) return true;\n\t\t\t\tif (Array.isArray(v.value)) return v.value.length === 0;\n\t\t\t\tif (typeof v.value === 'string') return v.value.trim().length === 0;\n\t\t\t\treturn false;\n\t\t\t};\n\n\t\t\tconst allEmpty = isEmptyResponse(host.ctx.getValue('RESPONSE'));\n\t\t\tconst max = toNumber(host.ctx.getValue('MAXSCORE'));\n\t\t\thost.ctx.setValue('SCORE', qtiValue('float', 'single', allEmpty ? (Number.isFinite(max) ? max : 1) : 0));\n\t\t\treturn;\n\t\t}\n\t\tcase 'map_response': {\n\t\t\tsetScore(mapResponse(false));\n\t\t\treturn;\n\t\t}\n\t\tcase 'cc2_map_response': {\n\t\t\tconst score = mapResponse(false);\n\t\t\tsetScore(score);\n\t\t\tconst maxScore = toNumber(host.ctx.getValue('MAXSCORE'));\n\t\t\tsetIdentifierOutcome(\n\t\t\t\t'FEEDBACK',\n\t\t\t\tNumber.isFinite(maxScore) && score === maxScore ? 'correct' : 'incorrect',\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tcase 'map_response_point':\n\t\tcase 'cc2_map_response_point': { // Official IMS QTI 3.0 rptemplate\n\t\t\tsetScore(mapResponse(true));\n\t\t\treturn;\n\t\t}\n\t\tcase 'no_response_processing': {\n\t\t\t// The standard empty template: outcomes keep their defaults (unscored item).\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n/**\n * A template reference is the item's only scoring rule when responseProcessing has no rules of\n * its own. Without a built-in program for that template the item would score its defaults\n * silently, so compilation fails instead (docs/SPEC-GAPS-PLAN.md G-19).\n */\nexport function assertSupportedResponseProcessing(host: ResponseProcessingHost): void {\n\tconst { present, hasStatements, template } = host.responseProcessing;\n\tif (!present || hasStatements || !template) return;\n\tif (resolveResponseProcessingTemplate(template)) return;\n\tthrow unsupportedTemplateError(host, template);\n}\n\nexport function unsupportedTemplateError(host: ResponseProcessingHost, templateUri: string): UnsupportedResponseProcessingTemplateError {\n\treturn new UnsupportedResponseProcessingTemplateError(\n\t\ttemplateUri,\n\t\thost.itemDocument.getAssessmentItemAttribute('identifier') ?? undefined,\n\t);\n}\n\nexport function resetOutcomesToDefault(host: ResponseProcessingHost): void {\n\tfor (const d of Object.values(host.decls)) {\n\t\tif ((d as any).__kind !== 'outcome') continue;\n\t\t// Built-in stateful variables must survive across processing runs.\n\t\t// They are updated by the runtime (adaptive attempt tracking), not by outcome defaults.\n\t\tif (d.identifier === 'numAttempts' || d.identifier === 'completionStatus' || d.identifier === 'duration') continue;\n\t\thost.ctx.resetToDefault(d.identifier);\n\t}\n}\n\nexport function resetResponsesToDefault(host: ResponseProcessingHost): void {\n\thost.endAttemptActivations.clear();\n\tfor (const d of Object.values(host.decls)) {\n\t\tif ((d as any).__kind !== 'response') continue;\n\t\thost.ctx.resetToDefault(d.identifier);\n\t\thost.restorePciResponse(d.identifier, host.qtiValueToPci(d.value));\n\t}\n}\n\nexport function resetTemplatesToDefault(host: ResponseProcessingHost): void {\n\tfor (const d of Object.values(host.decls)) {\n\t\tif (!d.isTemplate) continue;\n\t\thost.ctx.resetToDefault(d.identifier);\n\t}\n}\n\n/**\n * QTI ASI §10.3 with §5.1: template processing runs on a fresh instance of the item, so a new\n * template instance starts from the declarations, not from the instance before it. The\n * template rules setDefaultValue and setCorrectResponse change response and outcome\n * declarations for one instance; their declared defaults and correct responses come back\n * here, before the variables reset and template processing runs again. Template variables\n * keep their defaults: template rules do not change them, and they hold the\n * assessmentItemRef's templateDefault values (applied at session start, carried by a\n * snapshot), which apply to every instance.\n */\nexport function restoreDeclaredTemplateRuleTargets(host: ResponseProcessingHost): void {\n\tfor (const d of Object.values(host.decls)) {\n\t\tconst kind = (d as any).__kind as 'response' | 'outcome' | 'template' | 'context' | undefined;\n\t\tif (kind !== 'response' && kind !== 'outcome') continue;\n\t\tconst declared = host.sourceDeclarations[d.identifier];\n\t\tif (!declared) continue;\n\t\tconst fields = d as { defaultValue?: QtiValue; correctResponse?: QtiValue };\n\t\tif (declared.defaultValue) fields.defaultValue = cloneValue(declared.defaultValue);\n\t\telse delete fields.defaultValue;\n\t\tif (kind !== 'response') continue;\n\t\tif (declared.correctResponse) fields.correctResponse = cloneValue(declared.correctResponse);\n\t\telse delete fields.correctResponse;\n\t}\n}\n\nexport function runResponseProcessing(\n\thost: ResponseProcessingHost,\n\toptions: {\n\t\tfinalizeNonAdaptiveAttempt: boolean;\n\t\tcountAttempt?: boolean;\n\t},\n): ScoringResult {\n\thost.updateDuration();\n\t// QTI ASI §5.1: numAttempts starts at 0 and is incremented at the start of each attempt,\n\t// so the response processing that ends a counted attempt reads that attempt's own\n\t// number (1 on the first). The adaptive path counts in runAdaptiveSubmitAttempt; an\n\t// uncounted attempt (countAttempt=false) and a scoring pass (scoreAttempt) do not count.\n\tconst countsAttempt = options.finalizeNonAdaptiveAttempt && (options.countAttempt ?? true);\n\tif (!host.isAdaptive() && countsAttempt) {\n\t\thost.ctx.setValue('numAttempts', qtiValue('integer', 'single', host.getNumAttempts() + 1));\n\t}\n\t// QTI ASI §5.2: for a non-adaptive item, outcome variables are reset to their defaults\n\t// before each invocation of response processing. An adaptive item's outcomes \"retain the\n\t// values that were assigned to them during the previous invocation\" (§5.2, §8), so they\n\t// carry across attempts — and across a save/restore, which restores them as saved. They\n\t// start from their defaults only at session start and on newTemplate.\n\tif (!host.isAdaptive()) {\n\t\tresetOutcomesToDefault(host);\n\t}\n\n\t// Execute response processing if present\n\tif (host.responseProcessing.present) {\n\t\t// If responseProcessing has explicit statements, run the compiled program.\n\t\t// Otherwise, fall back to template-based processing (responseProcessing@template).\n\t\tif (host.responseProcessing.hasStatements) {\n\t\t\texecResponseProcessingProgram(host);\n\t\t} else if (host.responseProcessing.template) {\n\t\t\texecResponseProcessingTemplate(host, host.responseProcessing.template);\n\t\t}\n\t}\n\n\t// Execute outcome processing if present (runs after responseProcessing)\n\texecOutcomeProcessingProgram(host);\n\n\t// Compatibility: processResponses() has historically finalized non-adaptive items.\n\t// New scoreAttempt() uses this same engine with finalization disabled.\n\t// QTI ASI §5.2.1: submitting a non-adaptive item's attempt completes it — response\n\t// processing \"completes\" the item session, so completionStatus moves to `completed`\n\t// here even when the item has no rules of its own (an unscored item still completed\n\t// its attempt). An adaptive item's completionStatus is its response processing's\n\t// decision; a `completed` assignment authored in rules (as above for non-adaptive)\n\t// stays whatever the rules made it. `incomplete` is never engine-assigned: rules set\n\t// it, or the session stays `unknown`. See Player.beginAttempt for the earlier\n\t// transitions of this variable.\n\tif (!host.isAdaptive() && options.finalizeNonAdaptiveAttempt) {\n\t\thost.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'completed'));\n\t}\n\n\tconst outcomes = collectOutcomes(host);\n\n\twarnOnceOnImpliedZeroMaxScore(host, outcomes);\n\n\tconst score = Number(outcomes.SCORE ?? 0);\n\tconst maxScore = Number(outcomes.MAXSCORE ?? 1);\n\tconst completionStatus = (outcomes.completionStatus as CompletionStatus | undefined) ?? 'not_attempted';\n\tconst completed = completionStatus === 'completed' || (!host.isAdaptive() && options.finalizeNonAdaptiveAttempt);\n\n\treturn {\n\t\tscore,\n\t\tmaxScore,\n\t\tcompleted,\n\t\toutcomeValues: outcomes,\n\t\tcorrect: responsesMatchCorrect(host),\n\t\tmodalFeedback: host.getModalFeedback(outcomes),\n\t};\n}\n\n/**\n * QTI item correctness, as test-level `numberCorrect` reads it: every declared response matches\n * its correct response. Undefined when the item has no response or one declares no correct\n * response.\n */\nexport function responsesMatchCorrect(host: ResponseProcessingHost): boolean | undefined {\n\tconst responses = Object.values(host.decls).filter((d) => (d as any).__kind === 'response');\n\tif (responses.length === 0 || responses.some((d) => d.correctResponse?.kind !== 'value')) return undefined;\n\tconst env = processingEnv(host);\n\treturn responses.every((d) =>\n\t\ttoBoolean(\n\t\t\tevalExpr(env, {\n\t\t\t\tkind: 'expr.match',\n\t\t\t\tid: `correct-${d.identifier}`,\n\t\t\t\ta: { kind: 'expr.variable', id: `correct-${d.identifier}-response`, identifier: d.identifier },\n\t\t\t\tb: { kind: 'expr.correct', id: `correct-${d.identifier}-correct`, identifier: d.identifier },\n\t\t\t} as any),\n\t\t),\n\t);\n}\n\n/**\n * A MAXSCORE declared without a <defaultValue> is 0 per the numeric outcome rule, so an item\n * that never assigns it scores against a maximum of zero. That is the spec-correct reading of\n * under-specified content, and silently substituting 1 would make this engine disagree with a\n * conformant one — so surface the authoring gap instead of masking it.\n */\nfunction warnOnceOnImpliedZeroMaxScore(host: ResponseProcessingHost, outcomes: Record<string, unknown>): void {\n\tif (host.warnedImpliedZeroMaxScore) return;\n\tif (!host.decls.MAXSCORE?.impliedNumericDefault) return;\n\tif (outcomes.MAXSCORE !== 0) return;\n\thost.warnedImpliedZeroMaxScore = true;\n\tconsole.warn(\n\t\t`[QTI Player] MAXSCORE is 0 for item \"${host.itemDocument.getAssessmentItemAttribute('identifier') ?? 'unknown'}\": its outcomeDeclaration ` +\n\t\t\t'has no <defaultValue>, so QTI initializes it to 0 and response processing never assigned it. ' +\n\t\t\t'Declare <defaultValue> on the MAXSCORE outcomeDeclaration to score against a real maximum.',\n\t);\n}\n\nexport function collectOutcomes(host: ResponseProcessingHost): Record<string, unknown> {\n\tconst out: Record<string, unknown> = {};\n\tfor (const d of Object.values(host.decls)) {\n\t\tif ((d as any).__kind !== 'outcome') continue;\n\t\tif (d.value.kind === 'value') out[d.identifier] = host.qtiValueToPublic(d.value);\n\t\telse if (d.value.kind === 'null') out[d.identifier] = null;\n\t}\n\t// Ensure MAXSCORE always has a value (fallback to 1.0 if null or missing)\n\tif (out.MAXSCORE === null || out.MAXSCORE === undefined) {\n\t\tout.MAXSCORE = 1.0;\n\t}\n\treturn out;\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response validation: the field checks every interaction's response must satisfy, and
|
|
3
|
+
* the end-attempt gate that additionally rejects incomplete required responses.
|
|
4
|
+
*
|
|
5
|
+
* The generic checks run for every interaction, reading the interaction-shaped fields
|
|
6
|
+
* (minChoices, matchMin, requiredGaps, patternMask, matchGroup) from the delivered
|
|
7
|
+
* interaction data. The per-type entries below (TYPE_VALIDATION_ENTRIES) only restate
|
|
8
|
+
* today's special cases — media minPlays, endAttempt never-required, extendedText
|
|
9
|
+
* maxStrings — keyed on the delivered interaction type (the extractor's output type, so
|
|
10
|
+
* vendor overrides such as acme-likert delivering `choiceInteraction` keep the generic
|
|
11
|
+
* checks); no entry adds a constraint.
|
|
12
|
+
*/
|
|
13
|
+
import { type DeclarationMap } from '@pie-qti/qti-processing';
|
|
14
|
+
import type { MatchGroupConstraints } from '../matchGroups.js';
|
|
15
|
+
import type { ResponseValidationResult } from '../../types/responseValidation.js';
|
|
16
|
+
/** What response validation reads from the session engine. */
|
|
17
|
+
export interface ResponseValidationHost {
|
|
18
|
+
readonly decls: DeclarationMap;
|
|
19
|
+
/** matchGroup constraints of the item's pairing interactions, by response identifier. */
|
|
20
|
+
readonly matchGroupConstraints: ReadonlyMap<string, MatchGroupConstraints>;
|
|
21
|
+
getInteractions(): Array<{
|
|
22
|
+
type: string;
|
|
23
|
+
responseIdentifier: string;
|
|
24
|
+
} & Record<string, any>>;
|
|
25
|
+
getResponseInteractions(): Array<{
|
|
26
|
+
type: string;
|
|
27
|
+
responseIdentifier: string;
|
|
28
|
+
} & Record<string, any>>;
|
|
29
|
+
}
|
|
30
|
+
export declare function validateResponses(host: ResponseValidationHost, responses: Record<string, any>): ResponseValidationResult;
|
|
31
|
+
/**
|
|
32
|
+
* The validation the end attempt with `validateResponses` gates on (QTI ASI §4
|
|
33
|
+
* itemSessionControl validateResponses). An invalid response "does not satisfy the
|
|
34
|
+
* constraints imposed by the interaction": beyond a malformed value or a matchGroup
|
|
35
|
+
* pairing (`validateResponses`), an interaction that requires input — minChoices,
|
|
36
|
+
* minAssociations, minStrings, minPlays, matchMin — rejects an incomplete one. Those
|
|
37
|
+
* entries turn invalid with an `incomplete` issue, so the result reads invalid through
|
|
38
|
+
* the same channel as every other rejection.
|
|
39
|
+
*
|
|
40
|
+
* An item with no response at all is a skip, which allowSkipping governs ("delivery
|
|
41
|
+
* engines must ensure that the candidate can choose to submit no response" when it is
|
|
42
|
+
* true). The item cannot see allowSkipping, so completeness applies only once the
|
|
43
|
+
* candidate has responded and a skip is the caller's decision.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateAttemptResponses(host: ResponseValidationHost, responses: Record<string, any>): ResponseValidationResult;
|
|
46
|
+
export declare function isAttempted(host: ResponseValidationHost, responses: Record<string, any>): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* True when a response entry carries meaningful learner input. Extended-text items
|
|
49
|
+
* authored as XHTML are stripped to plain text first, so markup-only answers do not
|
|
50
|
+
* count as "answered". Shared by response validation and attempted-state tracking.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isMeaningfulResponseEntry(entry: unknown, interaction: {
|
|
53
|
+
type?: string;
|
|
54
|
+
format?: string;
|
|
55
|
+
}): boolean;
|