@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.
Files changed (294) hide show
  1. package/README.md +34 -6
  2. package/dist/catalog/applyGlossaryTriggers.js +14 -2
  3. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  4. package/dist/catalog/catalogExtractor.js +2 -4
  5. package/dist/catalog/catalogExtractor.js.map +1 -1
  6. package/dist/catalog/sessionCatalog.d.ts +46 -0
  7. package/dist/catalog/sessionCatalog.js +87 -0
  8. package/dist/catalog/sessionCatalog.js.map +1 -0
  9. package/dist/components/utils/endAttempt.d.ts +16 -0
  10. package/dist/components/utils/endAttempt.js +28 -0
  11. package/dist/components/utils/endAttempt.js.map +1 -0
  12. package/dist/components/utils/focus.d.ts +19 -0
  13. package/dist/components/utils/focus.js +67 -0
  14. package/dist/components/utils/focus.js.map +1 -0
  15. package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
  16. package/dist/components/utils/itemBodyRenderer.js +177 -0
  17. package/dist/components/utils/itemBodyRenderer.js.map +1 -0
  18. package/dist/components/utils/sentenceContext.d.ts +6 -0
  19. package/dist/components/utils/sentenceContext.js +16 -0
  20. package/dist/components/utils/sentenceContext.js.map +1 -0
  21. package/dist/core/AssessmentItemDefinition.d.ts +20 -1
  22. package/dist/core/AssessmentItemDefinition.js +12 -31
  23. package/dist/core/AssessmentItemDefinition.js.map +1 -1
  24. package/dist/core/ComponentRegistry.d.ts +92 -0
  25. package/dist/core/ComponentRegistry.js +7 -1
  26. package/dist/core/ComponentRegistry.js.map +1 -1
  27. package/dist/core/ItemSession.d.ts +18 -1
  28. package/dist/core/ItemSession.js +79 -41
  29. package/dist/core/ItemSession.js.map +1 -1
  30. package/dist/core/Player.d.ts +118 -141
  31. package/dist/core/Player.js +390 -1233
  32. package/dist/core/Player.js.map +1 -1
  33. package/dist/core/compliance.d.ts +72 -0
  34. package/dist/core/compliance.js +147 -0
  35. package/dist/core/compliance.js.map +1 -0
  36. package/dist/core/declarations/declarationBuilder.d.ts +29 -0
  37. package/dist/core/declarations/declarationBuilder.js +284 -0
  38. package/dist/core/declarations/declarationBuilder.js.map +1 -0
  39. package/dist/core/declarations/declarationValues.d.ts +11 -0
  40. package/dist/core/declarations/declarationValues.js +168 -0
  41. package/dist/core/declarations/declarationValues.js.map +1 -0
  42. package/dist/core/matchGroups.d.ts +36 -0
  43. package/dist/core/matchGroups.js +100 -0
  44. package/dist/core/matchGroups.js.map +1 -0
  45. package/dist/core/nameMappers.d.ts +35 -0
  46. package/dist/core/nameMappers.js +47 -0
  47. package/dist/core/nameMappers.js.map +1 -0
  48. package/dist/core/parsingLimits.d.ts +4 -0
  49. package/dist/core/parsingLimits.js +5 -2
  50. package/dist/core/parsingLimits.js.map +1 -1
  51. package/dist/core/processing/responseProcessing.d.ts +88 -0
  52. package/dist/core/processing/responseProcessing.js +317 -0
  53. package/dist/core/processing/responseProcessing.js.map +1 -0
  54. package/dist/core/processing/responseValidation.d.ts +55 -0
  55. package/dist/core/processing/responseValidation.js +335 -0
  56. package/dist/core/processing/responseValidation.js.map +1 -0
  57. package/dist/core/rendering/contentPass.d.ts +31 -0
  58. package/dist/core/rendering/contentPass.js +152 -0
  59. package/dist/core/rendering/contentPass.js.map +1 -0
  60. package/dist/core/rendering/htmlRender.d.ts +21 -0
  61. package/dist/core/rendering/htmlRender.js +56 -0
  62. package/dist/core/rendering/htmlRender.js.map +1 -0
  63. package/dist/core/responseProcessingTemplates.d.ts +23 -0
  64. package/dist/core/responseProcessingTemplates.js +45 -0
  65. package/dist/core/responseProcessingTemplates.js.map +1 -0
  66. package/dist/core/rolePolicy.d.ts +5 -0
  67. package/dist/core/rolePolicy.js +21 -0
  68. package/dist/core/rolePolicy.js.map +1 -1
  69. package/dist/core/sanitizer.js +8 -14
  70. package/dist/core/sanitizer.js.map +1 -1
  71. package/dist/core/serialization/sessionState.d.ts +56 -0
  72. package/dist/core/serialization/sessionState.js +139 -0
  73. package/dist/core/serialization/sessionState.js.map +1 -0
  74. package/dist/core/serialization/valueForms.d.ts +32 -0
  75. package/dist/core/serialization/valueForms.js +112 -0
  76. package/dist/core/serialization/valueForms.js.map +1 -0
  77. package/dist/document/AssessmentItemDocument.d.ts +27 -1
  78. package/dist/document/AssessmentItemDocument.js +67 -31
  79. package/dist/document/AssessmentItemDocument.js.map +1 -1
  80. package/dist/element-class-BUFpUrJP.js +3792 -0
  81. package/dist/element-class-BUFpUrJP.js.map +1 -0
  82. package/dist/element-class.d.ts +34 -1
  83. package/dist/element-class.js +1 -1
  84. package/dist/element.js +2 -3
  85. package/dist/extraction/ExtractionRegistry.js +6 -12
  86. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  87. package/dist/extraction/createContext.d.ts +2 -2
  88. package/dist/extraction/createContext.js.map +1 -1
  89. package/dist/extraction/index.d.ts +2 -2
  90. package/dist/extraction/index.js +1 -1
  91. package/dist/extraction/index.js.map +1 -1
  92. package/dist/extraction/interactionCoverage.d.ts +31 -0
  93. package/dist/extraction/interactionCoverage.js +40 -0
  94. package/dist/extraction/interactionCoverage.js.map +1 -0
  95. package/dist/extraction/interactionExtractionPipeline.js +5 -10
  96. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  97. package/dist/extraction/interactionSecurity.js +1 -28
  98. package/dist/extraction/interactionSecurity.js.map +1 -1
  99. package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
  100. package/dist/extraction/mergeDeliveryFields.js +17 -0
  101. package/dist/extraction/mergeDeliveryFields.js.map +1 -0
  102. package/dist/extraction/responseIdentifier.d.ts +19 -0
  103. package/dist/extraction/responseIdentifier.js +29 -0
  104. package/dist/extraction/responseIdentifier.js.map +1 -0
  105. package/dist/extraction/types.d.ts +11 -18
  106. package/dist/extraction/types.js +0 -12
  107. package/dist/extraction/types.js.map +1 -1
  108. package/dist/extraction/utils.d.ts +14 -0
  109. package/dist/extraction/utils.js +35 -5
  110. package/dist/extraction/utils.js.map +1 -1
  111. package/dist/index.d.ts +16 -10
  112. package/dist/index.js +19 -8
  113. package/dist/index.js.map +1 -1
  114. package/dist/interactions/associate/extractor.d.ts +1 -0
  115. package/dist/interactions/associate/extractor.js +10 -12
  116. package/dist/interactions/associate/extractor.js.map +1 -1
  117. package/dist/interactions/choice/extractor.js +6 -13
  118. package/dist/interactions/choice/extractor.js.map +1 -1
  119. package/dist/interactions/drawing/extractor.d.ts +6 -0
  120. package/dist/interactions/drawing/extractor.js +30 -9
  121. package/dist/interactions/drawing/extractor.js.map +1 -1
  122. package/dist/interactions/end-attempt/extractor.js +2 -1
  123. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  124. package/dist/interactions/extended-text/extractor.d.ts +6 -1
  125. package/dist/interactions/extended-text/extractor.js +10 -5
  126. package/dist/interactions/extended-text/extractor.js.map +1 -1
  127. package/dist/interactions/extended-text/response.js +18 -18
  128. package/dist/interactions/extended-text/response.js.map +1 -1
  129. package/dist/interactions/gap-match/extractor.d.ts +40 -2
  130. package/dist/interactions/gap-match/extractor.js +197 -39
  131. package/dist/interactions/gap-match/extractor.js.map +1 -1
  132. package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
  133. package/dist/interactions/graphic-associate/extractor.js +35 -24
  134. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  135. package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
  136. package/dist/interactions/graphic-gap-match/extractor.js +79 -43
  137. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  138. package/dist/interactions/graphic-order/extractor.d.ts +15 -0
  139. package/dist/interactions/graphic-order/extractor.js +39 -24
  140. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  141. package/dist/interactions/hotspot/extractor.d.ts +6 -0
  142. package/dist/interactions/hotspot/extractor.js +31 -16
  143. package/dist/interactions/hotspot/extractor.js.map +1 -1
  144. package/dist/interactions/hottext/extractor.js +2 -12
  145. package/dist/interactions/hottext/extractor.js.map +1 -1
  146. package/dist/interactions/inline/accessibleName.d.ts +29 -0
  147. package/dist/interactions/inline/accessibleName.js +35 -0
  148. package/dist/interactions/inline/accessibleName.js.map +1 -0
  149. package/dist/interactions/inline/render-plan.d.ts +5 -14
  150. package/dist/interactions/inline/render-plan.js +5 -56
  151. package/dist/interactions/inline/render-plan.js.map +1 -1
  152. package/dist/interactions/inline-choice/extractor.d.ts +4 -0
  153. package/dist/interactions/inline-choice/extractor.js +13 -12
  154. package/dist/interactions/inline-choice/extractor.js.map +1 -1
  155. package/dist/interactions/match/extractor.d.ts +2 -0
  156. package/dist/interactions/match/extractor.js +14 -28
  157. package/dist/interactions/match/extractor.js.map +1 -1
  158. package/dist/interactions/media/extractor.d.ts +5 -11
  159. package/dist/interactions/media/extractor.js +100 -36
  160. package/dist/interactions/media/extractor.js.map +1 -1
  161. package/dist/interactions/modules.js +8 -2
  162. package/dist/interactions/modules.js.map +1 -1
  163. package/dist/interactions/order/extractor.d.ts +2 -0
  164. package/dist/interactions/order/extractor.js +8 -12
  165. package/dist/interactions/order/extractor.js.map +1 -1
  166. package/dist/interactions/order/limits.d.ts +29 -0
  167. package/dist/interactions/order/limits.js +28 -0
  168. package/dist/interactions/order/limits.js.map +1 -0
  169. package/dist/interactions/portable-custom/extractor.js +18 -14
  170. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  171. package/dist/interactions/position-object/extractor.d.ts +18 -1
  172. package/dist/interactions/position-object/extractor.js +81 -22
  173. package/dist/interactions/position-object/extractor.js.map +1 -1
  174. package/dist/interactions/select-point/extractor.d.ts +6 -0
  175. package/dist/interactions/select-point/extractor.js +31 -19
  176. package/dist/interactions/select-point/extractor.js.map +1 -1
  177. package/dist/interactions/shared/imageAlt.d.ts +54 -0
  178. package/dist/interactions/shared/imageAlt.js +84 -0
  179. package/dist/interactions/shared/imageAlt.js.map +1 -0
  180. package/dist/interactions/shared/interactionImage.d.ts +32 -0
  181. package/dist/interactions/shared/interactionImage.js +39 -0
  182. package/dist/interactions/shared/interactionImage.js.map +1 -0
  183. package/dist/interactions/shared/specDefaults.d.ts +20 -0
  184. package/dist/interactions/shared/specDefaults.js +25 -0
  185. package/dist/interactions/shared/specDefaults.js.map +1 -0
  186. package/dist/interactions/shared/types.d.ts +212 -40
  187. package/dist/interactions/shared/types.js.map +1 -1
  188. package/dist/interactions/text-entry/extractor.d.ts +9 -0
  189. package/dist/interactions/text-entry/extractor.js +9 -0
  190. package/dist/interactions/text-entry/extractor.js.map +1 -1
  191. package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
  192. package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
  193. package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
  194. package/dist/interactions/text-entry/inputMode.d.ts +35 -0
  195. package/dist/interactions/text-entry/inputMode.js +134 -0
  196. package/dist/interactions/text-entry/inputMode.js.map +1 -0
  197. package/dist/interactions/text-entry/response.d.ts +15 -0
  198. package/dist/interactions/text-entry/response.js +25 -0
  199. package/dist/interactions/text-entry/response.js.map +1 -0
  200. package/dist/interactions/upload/extractor.js +2 -2
  201. package/dist/interactions/upload/extractor.js.map +1 -1
  202. package/dist/pci/PciHost.d.ts +1 -1
  203. package/dist/pci/PciHost.js +11 -11
  204. package/dist/pci/PciHost.js.map +1 -1
  205. package/dist/pci/index.d.ts +1 -0
  206. package/dist/pci/index.js.map +1 -1
  207. package/dist/pci/modulePaths.d.ts +16 -0
  208. package/dist/pci/modulePaths.js +33 -0
  209. package/dist/pci/modulePaths.js.map +1 -0
  210. package/dist/pci/pageRealmSession.js +3 -15
  211. package/dist/pci/pageRealmSession.js.map +1 -1
  212. package/dist/pci/qtiVariableJson.d.ts +46 -3
  213. package/dist/pci/qtiVariableJson.js +247 -53
  214. package/dist/pci/qtiVariableJson.js.map +1 -1
  215. package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
  216. package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
  217. package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
  218. package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
  219. package/dist/pci/sandbox/iframeConnector.js +35 -6
  220. package/dist/pci/sandbox/iframeConnector.js.map +1 -1
  221. package/dist/pci/sandbox/protocol.d.ts +14 -0
  222. package/dist/pci/sandbox/protocol.js.map +1 -1
  223. package/dist/pci/sessionHosts.d.ts +47 -0
  224. package/dist/pci/sessionHosts.js +66 -0
  225. package/dist/pci/sessionHosts.js.map +1 -0
  226. package/dist/pci/types.d.ts +9 -3
  227. package/dist/pci/types.js.map +1 -1
  228. package/dist/pnp/applyPnp.d.ts +20 -3
  229. package/dist/pnp/applyPnp.js +84 -9
  230. package/dist/pnp/applyPnp.js.map +1 -1
  231. package/dist/pnp/parsePnpXml.js +2 -0
  232. package/dist/pnp/parsePnpXml.js.map +1 -1
  233. package/dist/pnp/types.d.ts +16 -8
  234. package/dist/pnp/types.js.map +1 -1
  235. package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
  236. package/dist/presentation/feedbackAnnouncement.js +150 -0
  237. package/dist/presentation/feedbackAnnouncement.js.map +1 -0
  238. package/dist/presentation/interactionSlots.d.ts +31 -0
  239. package/dist/presentation/interactionSlots.js +101 -0
  240. package/dist/presentation/interactionSlots.js.map +1 -0
  241. package/dist/presentation/itemPresentationPlan.d.ts +69 -6
  242. package/dist/presentation/itemPresentationPlan.js +93 -81
  243. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  244. package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
  245. package/dist/presentation/stimulusRender.js.map +1 -0
  246. package/dist/presentation/stylesheetRender.js.map +1 -0
  247. package/dist/security/escapeHtml.d.ts +15 -0
  248. package/dist/security/escapeHtml.js +22 -0
  249. package/dist/security/escapeHtml.js.map +1 -0
  250. package/dist/security/index.d.ts +1 -0
  251. package/dist/security/index.js +1 -0
  252. package/dist/security/index.js.map +1 -1
  253. package/dist/server.d.ts +8 -1
  254. package/dist/server.js.map +1 -1
  255. package/dist/session-inputs.d.ts +108 -0
  256. package/dist/session-inputs.js +130 -0
  257. package/dist/session-inputs.js.map +1 -0
  258. package/dist/types/index.d.ts +67 -35
  259. package/dist/types/index.js.map +1 -1
  260. package/dist/utils/cloneFreeze.d.ts +52 -0
  261. package/dist/utils/cloneFreeze.js +113 -0
  262. package/dist/utils/cloneFreeze.js.map +1 -0
  263. package/dist/utils/htmlAttributes.d.ts +13 -0
  264. package/dist/utils/htmlAttributes.js +22 -0
  265. package/dist/utils/htmlAttributes.js.map +1 -0
  266. package/dist/web-components/QTIInteractionElement.d.ts +0 -29
  267. package/dist/web-components/QTIInteractionElement.js +0 -32
  268. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  269. package/dist/web-components/index.d.ts +1 -2
  270. package/dist/web-components/index.js +2 -3
  271. package/dist/web-components/index.js.map +1 -1
  272. package/package.json +20 -19
  273. package/dist/components/utils/stimulusRender.js.map +0 -1
  274. package/dist/components/utils/stylesheetRender.js.map +0 -1
  275. package/dist/core/constants.d.ts +0 -65
  276. package/dist/core/constants.js +0 -74
  277. package/dist/core/constants.js.map +0 -1
  278. package/dist/element-class-DdpiTalY.js +0 -9226
  279. package/dist/element-class-DdpiTalY.js.map +0 -1
  280. package/dist/extensions/MathLiveEditor.d.ts +0 -31
  281. package/dist/extensions/MathLiveEditor.js +0 -248
  282. package/dist/extensions/MathLiveEditor.js.map +0 -1
  283. package/dist/utils/PerformanceMonitor.d.ts +0 -169
  284. package/dist/utils/PerformanceMonitor.js +0 -243
  285. package/dist/utils/PerformanceMonitor.js.map +0 -1
  286. package/dist/utils/responseUtils.d.ts +0 -15
  287. package/dist/utils/responseUtils.js +0 -46
  288. package/dist/utils/responseUtils.js.map +0 -1
  289. package/dist/web-components/QTIInteractionBase.d.ts +0 -119
  290. package/dist/web-components/QTIInteractionBase.js +0 -244
  291. package/dist/web-components/QTIInteractionBase.js.map +0 -1
  292. /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
  293. /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
  294. /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
@@ -0,0 +1,72 @@
1
+ import { type ElementNameMapper, type QtiVersionDetection } from '@pie-qti/qti-common';
2
+ import type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
3
+ export type QtiItemDiagnosticCode =
4
+ /** Strict mode checks QTI 2.2 and 3.0, the certifiable versions; this item is another version. */
5
+ 'unsupported-version'
6
+ /** The item's QTI version was inferred or assumed rather than declared by its namespace. */
7
+ | 'version-assumed'
8
+ /** An element in the QTI namespace (or a `qti-` element in QTI 3.0) the version does not define. */
9
+ | 'unknown-element'
10
+ /** An interaction's `responseIdentifier` names no `responseDeclaration`. */
11
+ | 'unbound-interaction'
12
+ /** A QTI interaction element without a `responseIdentifier`; it is neither rendered nor scored. */
13
+ | 'missing-response-identifier'
14
+ /** An element binds a response, but no registered extractor handles it; it is not rendered. */
15
+ | 'unregistered-interaction';
16
+ export type QtiItemDiagnosticSeverity = 'error' | 'warning';
17
+ /**
18
+ * A QTI compliance finding about an item, from compiling it. Errors in strict mode, warnings
19
+ * otherwise; see `QTIComplianceConfig`.
20
+ */
21
+ export interface QtiItemDiagnostic {
22
+ readonly code: QtiItemDiagnosticCode;
23
+ readonly severity: QtiItemDiagnosticSeverity;
24
+ readonly message: string;
25
+ /** The element name as authored. */
26
+ readonly element?: string;
27
+ readonly responseIdentifier?: string;
28
+ /** For `unknown-element`: how many elements of that name the item has. */
29
+ readonly occurrences?: number;
30
+ }
31
+ /**
32
+ * Strict QTI compliance (`strictQtiCompliance: { enabled: true, rejectUnknownExtensions: true }`)
33
+ * rejected the item. `diagnostics` lists every finding.
34
+ */
35
+ export declare class QtiComplianceError extends Error {
36
+ readonly code = "qti-compliance";
37
+ readonly diagnostics: readonly QtiItemDiagnostic[];
38
+ readonly itemIdentifier?: string;
39
+ constructor(diagnostics: readonly QtiItemDiagnostic[], itemIdentifier?: string);
40
+ }
41
+ export interface CollectItemDiagnosticsInput {
42
+ /** The item XML as authored. */
43
+ readonly itemXml: string;
44
+ /** `itemXml`'s assessment item element, when the caller has already parsed it. */
45
+ readonly item?: Element;
46
+ /** The item's version detection, when the caller already has it. */
47
+ readonly versionDetection?: QtiVersionDetection;
48
+ /** The mapper the player resolves the item's element names with. */
49
+ readonly elementNameMapper: ElementNameMapper;
50
+ readonly extractionRegistry: ExtractionRegistry;
51
+ /** Identifiers of the item's response declarations. */
52
+ readonly responseIdentifiers: ReadonlySet<string>;
53
+ /** Strict compliance: findings are errors, and versions other than 2.2 and 3.0 are findings. */
54
+ readonly strict: boolean;
55
+ }
56
+ /**
57
+ * The item's compliance findings. Without an XSD engine this checks what a schema-valid,
58
+ * deliverable item needs and the player can verify: the version's namespace, the element
59
+ * vocabulary against the XSD-verified QTI vocabulary of `@pie-qti/qti-common` (the contents of
60
+ * `customInteraction`, and in QTI 3.0 of HTML `template`, admit any element and are not
61
+ * checked), and the response binding and extractability of every interaction.
62
+ */
63
+ export declare function collectItemDiagnostics(input: CollectItemDiagnosticsInput): QtiItemDiagnostic[];
64
+ export interface ReportItemDiagnosticsOptions {
65
+ readonly itemIdentifier?: string;
66
+ /** Throw a `QtiComplianceError` when there is any finding. */
67
+ readonly reject: boolean;
68
+ /** Write the findings to the console. */
69
+ readonly log: boolean;
70
+ }
71
+ /** Rejects or logs the findings, as the compliance configuration asks. */
72
+ export declare function reportItemDiagnostics(diagnostics: readonly QtiItemDiagnostic[], { itemIdentifier, reject, log }: ReportItemDiagnosticsOptions): void;
@@ -0,0 +1,147 @@
1
+ import { detectQtiVersionDetailed, isQtiVocabularyElement, } from '@pie-qti/qti-common';
2
+ import { childElements, findAssessmentItem, findFirstDescendant, parseXml } from '@pie-qti/qti-processing';
3
+ import { findUnextractableInteractions } from '../extraction/interactionCoverage.js';
4
+ import { readResponseIdentifier } from '../extraction/responseIdentifier.js';
5
+ /**
6
+ * Strict QTI compliance (`strictQtiCompliance: { enabled: true, rejectUnknownExtensions: true }`)
7
+ * rejected the item. `diagnostics` lists every finding.
8
+ */
9
+ export class QtiComplianceError extends Error {
10
+ constructor(diagnostics, itemIdentifier) {
11
+ super(`[QTI Player] Item${itemIdentifier ? ` "${itemIdentifier}"` : ''} fails strict QTI compliance:\n` +
12
+ diagnostics.map((diagnostic) => `- ${diagnostic.code}: ${diagnostic.message}`).join('\n'));
13
+ this.code = 'qti-compliance';
14
+ this.name = 'QtiComplianceError';
15
+ this.diagnostics = Object.freeze([...diagnostics]);
16
+ if (itemIdentifier)
17
+ this.itemIdentifier = itemIdentifier;
18
+ }
19
+ }
20
+ /**
21
+ * The item's compliance findings. Without an XSD engine this checks what a schema-valid,
22
+ * deliverable item needs and the player can verify: the version's namespace, the element
23
+ * vocabulary against the XSD-verified QTI vocabulary of `@pie-qti/qti-common` (the contents of
24
+ * `customInteraction`, and in QTI 3.0 of HTML `template`, admit any element and are not
25
+ * checked), and the response binding and extractability of every interaction.
26
+ */
27
+ export function collectItemDiagnostics(input) {
28
+ const severity = input.strict ? 'error' : 'warning';
29
+ const findings = [];
30
+ const detection = input.versionDetection ?? detectQtiVersionDetailed(input.itemXml);
31
+ if (detection.warnings.length > 0) {
32
+ findings.push({ code: 'version-assumed', message: detection.warnings.join(' ') });
33
+ }
34
+ if (detection.version === '2.0' || (input.strict && detection.version === '2.1')) {
35
+ findings.push({
36
+ code: 'unsupported-version',
37
+ message: input.strict
38
+ ? `Strict QTI compliance checks QTI 2.2 and 3.0 items; this item is QTI ${detection.version}.`
39
+ : `QTI ${detection.version} detected. Some features may not be fully supported; QTI 2.2 is recommended.`,
40
+ });
41
+ }
42
+ const item = input.item ?? findAssessmentItem(parseXml(input.itemXml));
43
+ const vocabulary = input.elementNameMapper.version === '3.0' ? '3.0' : '2.x';
44
+ findings.push(...unknownElementFindings(item, vocabulary));
45
+ const itemBody = findFirstDescendant(item, input.elementNameMapper.toNative('itembody'));
46
+ if (itemBody) {
47
+ for (const unextractable of findUnextractableInteractions(itemBody, input)) {
48
+ const tag = describeTag(unextractable.element, unextractable.responseIdentifier);
49
+ findings.push(unextractable.reason === 'unregistered'
50
+ ? {
51
+ code: 'unregistered-interaction',
52
+ message: `${tag} is not rendered: no registered extractor handles <${unextractable.element}>.`,
53
+ element: unextractable.element,
54
+ responseIdentifier: unextractable.responseIdentifier,
55
+ }
56
+ : {
57
+ code: 'missing-response-identifier',
58
+ message: `${tag} has no ${responseIdentifierAttribute(unextractable.element)}, so it is neither rendered nor scored.`,
59
+ element: unextractable.element,
60
+ });
61
+ }
62
+ for (const { element, responseIdentifier } of responseBindings(itemBody, input.elementNameMapper)) {
63
+ if (input.responseIdentifiers.has(responseIdentifier))
64
+ continue;
65
+ findings.push({
66
+ code: 'unbound-interaction',
67
+ message: `${describeTag(element, responseIdentifier)} names no responseDeclaration "${responseIdentifier}".`,
68
+ element,
69
+ responseIdentifier,
70
+ });
71
+ }
72
+ }
73
+ return findings.map((finding) => Object.freeze({ ...withoutUndefined(finding), severity }));
74
+ }
75
+ /** Rejects or logs the findings, as the compliance configuration asks. */
76
+ export function reportItemDiagnostics(diagnostics, { itemIdentifier, reject, log }) {
77
+ if (diagnostics.length === 0)
78
+ return;
79
+ if (reject)
80
+ throw new QtiComplianceError(diagnostics, itemIdentifier);
81
+ if (!log)
82
+ return;
83
+ const errors = diagnostics.filter((diagnostic) => diagnostic.severity === 'error');
84
+ const kind = `compliance ${errors.length > 0 ? 'error' : 'warning'}${diagnostics.length === 1 ? '' : 's'}`;
85
+ const message = `[QTI Player] Item${itemIdentifier ? ` "${itemIdentifier}"` : ''} has ${diagnostics.length} QTI ${kind}:\n` +
86
+ diagnostics.map((diagnostic) => `- ${diagnostic.code}: ${diagnostic.message}`).join('\n');
87
+ if (errors.length > 0)
88
+ console.error(message);
89
+ else
90
+ console.warn(message);
91
+ }
92
+ /** Element names the version's vocabulary does not define, one finding per name. */
93
+ function unknownElementFindings(item, vocabulary) {
94
+ const qtiNamespace = item.namespaceURI ?? null;
95
+ const unknown = new Map();
96
+ const visit = (element) => {
97
+ const name = element.localName;
98
+ const checked = (element.namespaceURI ?? null) === qtiNamespace || (vocabulary === '3.0' && name.startsWith('qti-'));
99
+ if (checked && !isQtiVocabularyElement(name, vocabulary)) {
100
+ unknown.set(element.nodeName, (unknown.get(element.nodeName) ?? 0) + 1);
101
+ }
102
+ // customInteraction (and QTI 3.0's HTML template) admit any content.
103
+ if (checked && (name === 'customInteraction' || name === 'qti-custom-interaction' || (vocabulary === '3.0' && name === 'template'))) {
104
+ return;
105
+ }
106
+ for (const child of childElements(element))
107
+ visit(child);
108
+ };
109
+ visit(item);
110
+ const version = vocabulary === '3.0' ? 'QTI 3.0' : 'QTI 2.2';
111
+ return [...unknown].map(([element, occurrences]) => ({
112
+ code: 'unknown-element',
113
+ message: `<${element}> is not an element of the ${version} vocabulary` +
114
+ `${occurrences > 1 ? ` (${occurrences} occurrences)` : ''}.`,
115
+ element,
116
+ occurrences,
117
+ }));
118
+ }
119
+ /** Every element of the item body binding a response, rubric blocks aside. */
120
+ function responseBindings(itemBody, elementNameMapper) {
121
+ const bindings = [];
122
+ const visit = (element) => {
123
+ if (elementNameMapper.toCanonical(element.nodeName) === 'rubricblock')
124
+ return;
125
+ const responseIdentifier = readResponseIdentifier(element)?.trim();
126
+ if (responseIdentifier)
127
+ bindings.push({ element: element.nodeName, responseIdentifier });
128
+ for (const child of childElements(element))
129
+ visit(child);
130
+ };
131
+ for (const child of childElements(itemBody))
132
+ visit(child);
133
+ return bindings;
134
+ }
135
+ function describeTag(element, responseIdentifier) {
136
+ if (!responseIdentifier)
137
+ return `<${element}>`;
138
+ return `<${element} ${responseIdentifierAttribute(element)}="${responseIdentifier}">`;
139
+ }
140
+ /** The response binding attribute as the element's QTI version spells it. */
141
+ function responseIdentifierAttribute(element) {
142
+ return element.startsWith('qti-') ? 'response-identifier' : 'responseIdentifier';
143
+ }
144
+ function withoutUndefined(value) {
145
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
146
+ }
147
+ //# sourceMappingURL=compliance.js.map
@@ -0,0 +1 @@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abularyVersion,\n} from '@pie-qti/qti-common';\nimport { childElements, findAssessmentItem, findFirstDescendant, parseXml } from '@pie-qti/qti-processing';\nimport type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';\nimport { findUnextractableInteractions } from '../extraction/interactionCoverage.js';\nimport { readResponseIdentifier } from '../extraction/responseIdentifier.js';\n\nexport type QtiItemDiagnosticCode =\n\t/** Strict mode checks QTI 2.2 and 3.0, the certifiable versions; this item is another version. */\n\t| 'unsupported-version'\n\t/** The item's QTI version was inferred or assumed rather than declared by its namespace. */\n\t| 'version-assumed'\n\t/** An element in the QTI namespace (or a `qti-` element in QTI 3.0) the version does not define. */\n\t| 'unknown-element'\n\t/** An interaction's `responseIdentifier` names no `responseDeclaration`. */\n\t| 'unbound-interaction'\n\t/** A QTI interaction element without a `responseIdentifier`; it is neither rendered nor scored. */\n\t| 'missing-response-identifier'\n\t/** An element binds a response, but no registered extractor handles it; it is not rendered. */\n\t| 'unregistered-interaction';\n\nexport type QtiItemDiagnosticSeverity = 'error' | 'warning';\n\n/**\n * A QTI compliance finding about an item, from compiling it. Errors in strict mode, warnings\n * otherwise; see `QTIComplianceConfig`.\n */\nexport interface QtiItemDiagnostic {\n\treadonly code: QtiItemDiagnosticCode;\n\treadonly severity: QtiItemDiagnosticSeverity;\n\treadonly message: string;\n\t/** The element name as authored. */\n\treadonly element?: string;\n\treadonly responseIdentifier?: string;\n\t/** For `unknown-element`: how many elements of that name the item has. */\n\treadonly occurrences?: number;\n}\n\n/**\n * Strict QTI compliance (`strictQtiCompliance: { enabled: true, rejectUnknownExtensions: true }`)\n * rejected the item. `diagnostics` lists every finding.\n */\nexport class QtiComplianceError extends Error {\n\treadonly code = 'qti-compliance';\n\treadonly diagnostics: readonly QtiItemDiagnostic[];\n\treadonly itemIdentifier?: string;\n\n\tconstructor(diagnostics: readonly QtiItemDiagnostic[], itemIdentifier?: string) {\n\t\tsuper(\n\t\t\t`[QTI Player] Item${itemIdentifier ? ` \"${itemIdentifier}\"` : ''} fails strict QTI compliance:\\n` +\n\t\t\t\tdiagnostics.map((diagnostic) => `- ${diagnostic.code}: ${diagnostic.message}`).join('\\n'),\n\t\t);\n\t\tthis.name = 'QtiComplianceError';\n\t\tthis.diagnostics = Object.freeze([...diagnostics]);\n\t\tif (itemIdentifier) this.itemIdentifier = itemIdentifier;\n\t}\n}\n\nexport interface CollectItemDiagnosticsInput {\n\t/** The item XML as authored. */\n\treadonly itemXml: string;\n\t/** `itemXml`'s assessment item element, when the caller has already parsed it. */\n\treadonly item?: Element;\n\t/** The item's version detection, when the caller already has it. */\n\treadonly versionDetection?: QtiVersionDetection;\n\t/** The mapper the player resolves the item's element names with. */\n\treadonly elementNameMapper: ElementNameMapper;\n\treadonly extractionRegistry: ExtractionRegistry;\n\t/** Identifiers of the item's response declarations. */\n\treadonly responseIdentifiers: ReadonlySet<string>;\n\t/** Strict compliance: findings are errors, and versions other than 2.2 and 3.0 are findings. */\n\treadonly strict: boolean;\n}\n\n/**\n * The item's compliance findings. Without an XSD engine this checks what a schema-valid,\n * deliverable item needs and the player can verify: the version's namespace, the element\n * vocabulary against the XSD-verified QTI vocabulary of `@pie-qti/qti-common` (the contents of\n * `customInteraction`, and in QTI 3.0 of HTML `template`, admit any element and are not\n * checked), and the response binding and extractability of every interaction.\n */\nexport function collectItemDiagnostics(input: CollectItemDiagnosticsInput): QtiItemDiagnostic[] {\n\tconst severity: QtiItemDiagnosticSeverity = input.strict ? 'error' : 'warning';\n\tconst findings: Array<Omit<QtiItemDiagnostic, 'severity'>> = [];\n\n\tconst detection = input.versionDetection ?? detectQtiVersionDetailed(input.itemXml);\n\tif (detection.warnings.length > 0) {\n\t\tfindings.push({ code: 'version-assumed', message: detection.warnings.join(' ') });\n\t}\n\tif (detection.version === '2.0' || (input.strict && detection.version === '2.1')) {\n\t\tfindings.push({\n\t\t\tcode: 'unsupported-version',\n\t\t\tmessage: input.strict\n\t\t\t\t? `Strict QTI compliance checks QTI 2.2 and 3.0 items; this item is QTI ${detection.version}.`\n\t\t\t\t: `QTI ${detection.version} detected. Some features may not be fully supported; QTI 2.2 is recommended.`,\n\t\t});\n\t}\n\n\tconst item = input.item ?? findAssessmentItem(parseXml(input.itemXml));\n\tconst vocabulary: QtiVocabularyVersion = input.elementNameMapper.version === '3.0' ? '3.0' : '2.x';\n\tfindings.push(...unknownElementFindings(item, vocabulary));\n\n\tconst itemBody = findFirstDescendant(item, input.elementNameMapper.toNative('itembody'));\n\tif (itemBody) {\n\t\tfor (const unextractable of findUnextractableInteractions(itemBody, input)) {\n\t\t\tconst tag = describeTag(unextractable.element, unextractable.responseIdentifier);\n\t\t\tfindings.push(\n\t\t\t\tunextractable.reason === 'unregistered'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcode: 'unregistered-interaction',\n\t\t\t\t\t\t\tmessage: `${tag} is not rendered: no registered extractor handles <${unextractable.element}>.`,\n\t\t\t\t\t\t\telement: unextractable.element,\n\t\t\t\t\t\t\tresponseIdentifier: unextractable.responseIdentifier,\n\t\t\t\t\t\t}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tcode: 'missing-response-identifier',\n\t\t\t\t\t\t\tmessage: `${tag} has no ${responseIdentifierAttribute(unextractable.element)}, so it is neither rendered nor scored.`,\n\t\t\t\t\t\t\telement: unextractable.element,\n\t\t\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\tfor (const { element, responseIdentifier } of responseBindings(itemBody, input.elementNameMapper)) {\n\t\t\tif (input.responseIdentifiers.has(responseIdentifier)) continue;\n\t\t\tfindings.push({\n\t\t\t\tcode: 'unbound-interaction',\n\t\t\t\tmessage: `${describeTag(element, responseIdentifier)} names no responseDeclaration \"${responseIdentifier}\".`,\n\t\t\t\telement,\n\t\t\t\tresponseIdentifier,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn findings.map((finding) => Object.freeze({ ...withoutUndefined(finding), severity }));\n}\n\nexport interface ReportItemDiagnosticsOptions {\n\treadonly itemIdentifier?: string;\n\t/** Throw a `QtiComplianceError` when there is any finding. */\n\treadonly reject: boolean;\n\t/** Write the findings to the console. */\n\treadonly log: boolean;\n}\n\n/** Rejects or logs the findings, as the compliance configuration asks. */\nexport function reportItemDiagnostics(\n\tdiagnostics: readonly QtiItemDiagnostic[],\n\t{ itemIdentifier, reject, log }: ReportItemDiagnosticsOptions,\n): void {\n\tif (diagnostics.length === 0) return;\n\tif (reject) throw new QtiComplianceError(diagnostics, itemIdentifier);\n\tif (!log) return;\n\tconst errors = diagnostics.filter((diagnostic) => diagnostic.severity === 'error');\n\tconst kind = `compliance ${errors.length > 0 ? 'error' : 'warning'}${diagnostics.length === 1 ? '' : 's'}`;\n\tconst message =\n\t\t`[QTI Player] Item${itemIdentifier ? ` \"${itemIdentifier}\"` : ''} has ${diagnostics.length} QTI ${kind}:\\n` +\n\t\tdiagnostics.map((diagnostic) => `- ${diagnostic.code}: ${diagnostic.message}`).join('\\n');\n\tif (errors.length > 0) console.error(message);\n\telse console.warn(message);\n}\n\n/** Element names the version's vocabulary does not define, one finding per name. */\nfunction unknownElementFindings(\n\titem: Element,\n\tvocabulary: QtiVocabularyVersion,\n): Array<Omit<QtiItemDiagnostic, 'severity'>> {\n\tconst qtiNamespace = item.namespaceURI ?? null;\n\tconst unknown = new Map<string, number>();\n\n\tconst visit = (element: Element): void => {\n\t\tconst name = element.localName;\n\t\tconst checked =\n\t\t\t(element.namespaceURI ?? null) === qtiNamespace || (vocabulary === '3.0' && name.startsWith('qti-'));\n\t\tif (checked && !isQtiVocabularyElement(name, vocabulary)) {\n\t\t\tunknown.set(element.nodeName, (unknown.get(element.nodeName) ?? 0) + 1);\n\t\t}\n\t\t// customInteraction (and QTI 3.0's HTML template) admit any content.\n\t\tif (checked && (name === 'customInteraction' || name === 'qti-custom-interaction' || (vocabulary === '3.0' && name === 'template'))) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const child of childElements(element)) visit(child);\n\t};\n\tvisit(item);\n\n\tconst version = vocabulary === '3.0' ? 'QTI 3.0' : 'QTI 2.2';\n\treturn [...unknown].map(([element, occurrences]) => ({\n\t\tcode: 'unknown-element' as const,\n\t\tmessage:\n\t\t\t`<${element}> is not an element of the ${version} vocabulary` +\n\t\t\t`${occurrences > 1 ? ` (${occurrences} occurrences)` : ''}.`,\n\t\telement,\n\t\toccurrences,\n\t}));\n}\n\n/** Every element of the item body binding a response, rubric blocks aside. */\nfunction responseBindings(\n\titemBody: Element,\n\telementNameMapper: ElementNameMapper,\n): Array<{ element: string; responseIdentifier: string }> {\n\tconst bindings: Array<{ element: string; responseIdentifier: string }> = [];\n\tconst visit = (element: Element): void => {\n\t\tif (elementNameMapper.toCanonical(element.nodeName) === 'rubricblock') return;\n\t\tconst responseIdentifier = readResponseIdentifier(element)?.trim();\n\t\tif (responseIdentifier) bindings.push({ element: element.nodeName, responseIdentifier });\n\t\tfor (const child of childElements(element)) visit(child);\n\t};\n\tfor (const child of childElements(itemBody)) visit(child);\n\treturn bindings;\n}\n\nfunction describeTag(element: string, responseIdentifier?: string): string {\n\tif (!responseIdentifier) return `<${element}>`;\n\treturn `<${element} ${responseIdentifierAttribute(element)}=\"${responseIdentifier}\">`;\n}\n\n/** The response binding attribute as the element's QTI version spells it. */\nfunction responseIdentifierAttribute(element: string): string {\n\treturn element.startsWith('qti-') ? 'response-identifier' : 'responseIdentifier';\n}\n\nfunction withoutUndefined<T extends object>(value: T): T {\n\treturn Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)) as T;\n}\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Compile-time declaration building: the response, outcome, template and context
3
+ * declarations parsed from the item source, with their defaults, correct responses,
4
+ * mappings and lookup tables.
5
+ *
6
+ * Everything here is a pure function of the parsed item document, so the compiled
7
+ * declarations are immutable source-derived artifacts a definition shares between
8
+ * sessions (each session deep-clones them before template rules mutate a copy).
9
+ */
10
+ import { type BaseType, type Cardinality, type DeclarationMap, type QtiValue } from '@pie-qti/qti-processing';
11
+ import type { AttributeNameMapper, ElementNameMapper } from '@pie-qti/qti-common';
12
+ import type { AssessmentItemDocument } from '../../document/AssessmentItemDocument.js';
13
+ export type DeclKind = 'response' | 'outcome' | 'template' | 'context';
14
+ /** The parsed item document a declaration map is compiled from. */
15
+ export interface DeclarationBuildInput {
16
+ readonly itemDocument: AssessmentItemDocument;
17
+ readonly mapper: ElementNameMapper;
18
+ readonly attributeMapper: AttributeNameMapper | undefined;
19
+ }
20
+ export declare function buildDeclarationMap(input: DeclarationBuildInput): DeclarationMap;
21
+ export declare function ensureBuiltinDeclarations(decls: DeclarationMap): void;
22
+ /**
23
+ * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is
24
+ * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.
25
+ * Response and template variables keep NULL — an unanswered numeric response must stay
26
+ * distinguishable from an answered zero.
27
+ */
28
+ export declare function hasImpliedNumericDefault(kind: DeclKind, baseType: BaseType | undefined, cardinality: Cardinality): boolean;
29
+ export declare function impliedDefaultValue(kind: DeclKind, baseType: BaseType | undefined, cardinality: Cardinality): QtiValue;
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Compile-time declaration building: the response, outcome, template and context
3
+ * declarations parsed from the item source, with their defaults, correct responses,
4
+ * mappings and lookup tables.
5
+ *
6
+ * Everything here is a pure function of the parsed item document, so the compiled
7
+ * declarations are immutable source-derived artifacts a definition shares between
8
+ * sessions (each session deep-clones them before template rules mutate a copy).
9
+ */
10
+ import { coerceBaseValue, findDescendants, findFirstDescendant, getAttr, qtiNull, qtiValue, parseInterpolationTableDeclaration, parseMatchTableDeclaration, } from '@pie-qti/qti-processing';
11
+ export function buildDeclarationMap(input) {
12
+ const { itemDocument, mapper, attributeMapper } = input;
13
+ const decls = {};
14
+ const getAttrMapped = (el, canonicalName) => readMappedAttribute(attributeMapper, el, canonicalName);
15
+ const addDecl = (kind, el) => {
16
+ const identifier = getAttrMapped(el, 'identifier');
17
+ const cardinality = (getAttrMapped(el, 'cardinality') || 'single');
18
+ const baseType = cardinality === 'record'
19
+ ? undefined
20
+ : (getAttrMapped(el, 'baseType') || 'string');
21
+ if (!identifier)
22
+ return;
23
+ const declaredDefault = parseDefaultValue(input, el, baseType, cardinality);
24
+ const impliedNumericDefault = !declaredDefault && hasImpliedNumericDefault(kind, baseType, cardinality);
25
+ const defaultValue = declaredDefault ?? impliedDefaultValue(kind, baseType, cardinality);
26
+ decls[identifier] = {
27
+ identifier,
28
+ ...(baseType ? { baseType } : {}),
29
+ cardinality,
30
+ defaultValue,
31
+ value: defaultValue,
32
+ isTemplate: kind === 'template',
33
+ impliedNumericDefault,
34
+ // @ts-expect-error internal marker for templates
35
+ __kind: kind,
36
+ };
37
+ // Only response declarations define a <mapping> (read by mapResponse). QTI's outcome
38
+ // declarations carry no mapping element in any version — their tables are the
39
+ // matchTable/interpolationTable below, read by lookupOutcomeValue.
40
+ if (kind === 'response') {
41
+ const mappingEl = findFirstDescendant(el, mapper.toNative('mapping'));
42
+ if (mappingEl && baseType) {
43
+ decls[identifier].mapping = parseMapping(mappingEl, baseType, mapper, attributeMapper);
44
+ }
45
+ }
46
+ // Outcome declarations may define a lookup table (matchTable or interpolationTable)
47
+ // used by the lookupOutcomeValue rule.
48
+ if (kind === 'outcome') {
49
+ const matchTableEl = findFirstDescendant(el, mapper.toNative('matchtable'));
50
+ const interpolationTableEl = findFirstDescendant(el, mapper.toNative('interpolationtable'));
51
+ if (matchTableEl) {
52
+ decls[identifier].lookupTable = parseMatchTableDeclaration(matchTableEl, mapper);
53
+ }
54
+ else if (interpolationTableEl) {
55
+ decls[identifier].lookupTable = parseInterpolationTableDeclaration(interpolationTableEl, mapper);
56
+ }
57
+ }
58
+ if (kind === 'response') {
59
+ const correctEl = findFirstDescendant(el, mapper.toNative('correctresponse'));
60
+ if (correctEl) {
61
+ decls[identifier].correctResponse = parseCorrectResponse(input, correctEl, baseType, cardinality);
62
+ }
63
+ const areaMappingEl = findFirstDescendant(el, mapper.toNative('areamapping'));
64
+ if (areaMappingEl) {
65
+ decls[identifier].areaMapping = parseAreaMapping(areaMappingEl, mapper);
66
+ }
67
+ }
68
+ };
69
+ for (const el of itemDocument.findDeclarationElements('response'))
70
+ addDecl('response', el);
71
+ for (const el of itemDocument.findDeclarationElements('outcome'))
72
+ addDecl('outcome', el);
73
+ for (const el of itemDocument.findDeclarationElements('template'))
74
+ addDecl('template', el);
75
+ for (const el of itemDocument.findDeclarationElements('context'))
76
+ addDecl('context', el);
77
+ return decls;
78
+ }
79
+ export function ensureBuiltinDeclarations(decls) {
80
+ // completionStatus + numAttempts are defined in QTI (esp. adaptive items) and commonly used
81
+ // without explicit outcomeDeclaration in authoring content.
82
+ if (!decls.completionStatus) {
83
+ decls.completionStatus = {
84
+ identifier: 'completionStatus',
85
+ baseType: 'identifier',
86
+ cardinality: 'single',
87
+ value: qtiValue('identifier', 'single', 'not_attempted'),
88
+ isTemplate: false,
89
+ // @ts-expect-error internal marker
90
+ __kind: 'outcome',
91
+ };
92
+ }
93
+ if (!decls.numAttempts) {
94
+ decls.numAttempts = {
95
+ identifier: 'numAttempts',
96
+ baseType: 'integer',
97
+ cardinality: 'single',
98
+ defaultValue: qtiValue('integer', 'single', 0),
99
+ value: qtiValue('integer', 'single', 0),
100
+ isTemplate: false,
101
+ // @ts-expect-error internal marker
102
+ __kind: 'outcome',
103
+ };
104
+ }
105
+ if (!decls.duration) {
106
+ decls.duration = {
107
+ identifier: 'duration',
108
+ baseType: 'duration',
109
+ cardinality: 'single',
110
+ defaultValue: qtiValue('duration', 'single', 0),
111
+ value: qtiValue('duration', 'single', 0),
112
+ isTemplate: false,
113
+ // @ts-expect-error internal marker
114
+ __kind: 'outcome',
115
+ };
116
+ }
117
+ // QTI 3 built-in context variable, set by the delivery system.
118
+ if (!decls.QTI_CONTEXT) {
119
+ decls.QTI_CONTEXT = {
120
+ identifier: 'QTI_CONTEXT',
121
+ cardinality: 'record',
122
+ defaultValue: qtiNull(undefined, 'record'),
123
+ value: qtiNull(undefined, 'record'),
124
+ isTemplate: false,
125
+ // @ts-expect-error internal marker
126
+ __kind: 'context',
127
+ };
128
+ }
129
+ // Common scoring defaults
130
+ if (!decls.SCORE) {
131
+ decls.SCORE = {
132
+ identifier: 'SCORE',
133
+ baseType: 'float',
134
+ cardinality: 'single',
135
+ value: qtiValue('float', 'single', 0),
136
+ isTemplate: false,
137
+ // @ts-expect-error internal marker
138
+ __kind: 'outcome',
139
+ };
140
+ }
141
+ if (!decls.MAXSCORE) {
142
+ decls.MAXSCORE = {
143
+ identifier: 'MAXSCORE',
144
+ baseType: 'float',
145
+ cardinality: 'single',
146
+ value: qtiValue('float', 'single', 1),
147
+ isTemplate: false,
148
+ // @ts-expect-error internal marker
149
+ __kind: 'outcome',
150
+ };
151
+ }
152
+ }
153
+ /**
154
+ * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is
155
+ * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.
156
+ * Response and template variables keep NULL — an unanswered numeric response must stay
157
+ * distinguishable from an answered zero.
158
+ */
159
+ export function hasImpliedNumericDefault(kind, baseType, cardinality) {
160
+ if (kind !== 'outcome' || cardinality !== 'single')
161
+ return false;
162
+ return baseType === 'integer' || baseType === 'float';
163
+ }
164
+ export function impliedDefaultValue(kind, baseType, cardinality) {
165
+ if (hasImpliedNumericDefault(kind, baseType, cardinality)) {
166
+ return qtiValue(baseType, 'single', 0);
167
+ }
168
+ return qtiNull(baseType, cardinality);
169
+ }
170
+ /** Returns undefined when the declaration carries no <defaultValue> at all. */
171
+ function parseDefaultValue(input, declEl, baseType, cardinality) {
172
+ const defaultEl = findFirstDescendant(declEl, input.mapper.toNative('defaultvalue'));
173
+ if (!defaultEl)
174
+ return undefined;
175
+ return parseDeclarationValues(input, defaultEl, baseType, cardinality);
176
+ }
177
+ function parseCorrectResponse(input, correctEl, baseType, cardinality) {
178
+ return parseDeclarationValues(input, correctEl, baseType, cardinality);
179
+ }
180
+ function parseDeclarationValues(input, container, baseType, cardinality) {
181
+ const { mapper, itemDocument } = input;
182
+ const contentLanguage = itemDocument.getContentLanguage();
183
+ const valueElements = findDescendants(container, mapper.toNative('value'));
184
+ if (cardinality === 'record') {
185
+ const record = {};
186
+ for (const valueElement of valueElements) {
187
+ const fieldIdentifier = readMappedAttribute(input.attributeMapper, valueElement, 'fieldIdentifier');
188
+ const fieldBaseType = readMappedAttribute(input.attributeMapper, valueElement, 'baseType');
189
+ if (!fieldIdentifier || !fieldBaseType)
190
+ continue;
191
+ record[fieldIdentifier] = coerceBaseValue(fieldBaseType, valueElement.textContent || '', contentLanguage);
192
+ }
193
+ return Object.keys(record).length > 0
194
+ ? qtiValue(undefined, 'record', record)
195
+ : qtiNull(undefined, 'record');
196
+ }
197
+ if (!baseType)
198
+ return qtiNull(undefined, cardinality);
199
+ const values = valueElements.map((value) => (value.textContent || '').trim());
200
+ if (cardinality === 'multiple' || cardinality === 'ordered') {
201
+ return qtiValue(baseType, cardinality, values.map((t) => {
202
+ const v = coerceBaseValue(baseType, t, contentLanguage);
203
+ return v.kind === 'value' ? v.value : null;
204
+ }));
205
+ }
206
+ return coerceBaseValue(baseType, values[0] ?? '', contentLanguage);
207
+ }
208
+ /**
209
+ * Get attribute value with QTI version support: the attribute mapper's native form
210
+ * first (e.g., 'mapkey' -> 'map-key' for QTI 3.0), then the canonical name for
211
+ * QTI 2.x compatibility.
212
+ */
213
+ function readMappedAttribute(attributeMapper, el, canonicalName) {
214
+ if (attributeMapper) {
215
+ const nativeName = attributeMapper.toNative(canonicalName);
216
+ const value = el.getAttribute(nativeName);
217
+ if (value !== null)
218
+ return value;
219
+ }
220
+ return getAttr(el, canonicalName);
221
+ }
222
+ function parseMapping(mappingEl, baseType, mapper, attributeMapper) {
223
+ const defaultValue = Number(getAttr(mappingEl, 'defaultValue') || 0);
224
+ const lowerBound = getAttr(mappingEl, 'lowerBound') ? Number(getAttr(mappingEl, 'lowerBound')) : undefined;
225
+ const upperBound = getAttr(mappingEl, 'upperBound') ? Number(getAttr(mappingEl, 'upperBound')) : undefined;
226
+ // mapEntry@caseSensitive defaults to "false" (QTI 2.2 XSD, optional, default "false"):
227
+ // string entries match case-insensitively unless authored "true". The mapping element
228
+ // itself defines no caseSensitive attribute in any QTI version, so none is read.
229
+ const entries = {};
230
+ const normalizePairKey = (k) => {
231
+ const parts = k.trim().split(/\s+/).filter(Boolean);
232
+ if (parts.length === 2)
233
+ return [...parts].sort().join(' ');
234
+ return k.trim();
235
+ };
236
+ const normalizeDirectedPairKey = (k) => {
237
+ const parts = k.trim().split(/\s+/).filter(Boolean);
238
+ if (parts.length >= 2)
239
+ return `${parts[0]} ${parts[1]}`;
240
+ return k.trim();
241
+ };
242
+ for (const e of findDescendants(mappingEl, mapper.toNative('mapentry'))) {
243
+ const mapKey = readMappedAttribute(attributeMapper, e, 'mapKey');
244
+ const mappedValue = readMappedAttribute(attributeMapper, e, 'mappedValue');
245
+ if (!mapKey || mappedValue === null)
246
+ continue;
247
+ // Only string values fold case: identifier and the other base types always match
248
+ // exactly (QTI ASI §17), whatever the entry says.
249
+ const effectiveCaseSensitive = baseType === 'string' ? readMappedAttribute(attributeMapper, e, 'caseSensitive') || 'false' : 'true';
250
+ const storedKey = baseType === 'pair'
251
+ ? normalizePairKey(mapKey)
252
+ : baseType === 'directedPair'
253
+ ? normalizeDirectedPairKey(mapKey)
254
+ : mapKey;
255
+ entries[storedKey] = { mapKey: storedKey, mappedValue: Number(mappedValue), caseSensitive: effectiveCaseSensitive };
256
+ if (effectiveCaseSensitive !== 'true') {
257
+ const lowerKey = storedKey.toLowerCase();
258
+ entries[lowerKey] = {
259
+ mapKey: lowerKey,
260
+ mappedValue: Number(mappedValue),
261
+ caseSensitive: effectiveCaseSensitive,
262
+ };
263
+ }
264
+ }
265
+ return { defaultValue, lowerBound, upperBound, entries };
266
+ }
267
+ function parseAreaMapping(areaMappingEl, mapper) {
268
+ const defaultValue = Number(getAttr(areaMappingEl, 'defaultValue') || 0);
269
+ const lowerBound = getAttr(areaMappingEl, 'lowerBound')
270
+ ? Number(getAttr(areaMappingEl, 'lowerBound'))
271
+ : undefined;
272
+ const upperBound = getAttr(areaMappingEl, 'upperBound')
273
+ ? Number(getAttr(areaMappingEl, 'upperBound'))
274
+ : undefined;
275
+ const entries = [];
276
+ for (const e of findDescendants(areaMappingEl, mapper.toNative('areamapentry'))) {
277
+ const shape = (getAttr(e, 'shape') || 'default');
278
+ const coords = String(getAttr(e, 'coords') || '');
279
+ const mappedValue = Number(getAttr(e, 'mappedValue') || 0);
280
+ entries.push({ shape, coords, mappedValue });
281
+ }
282
+ return { defaultValue, lowerBound, upperBound, entries };
283
+ }
284
+ //# sourceMappingURL=declarationBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarationBuilder.js","sourceRoot":"","sources":["../../../src/core/declarations/declarationBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAMN,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,OAAO,EAEP,OAAO,EACP,QAAQ,EACR,kCAAkC,EAClC,0BAA0B,GAC1B,MAAM,yBAAyB,CAAC;AAajC,MAAM,UAAU,mBAAmB,CAAC,KAA4B;IAC/D,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IACxD,MAAM,KAAK,GAAmB,EAAE,CAAC;IAEjC,MAAM,aAAa,GAAG,CAAC,EAAW,EAAE,aAAqB,EAAiB,EAAE,CAC3E,mBAAmB,CAAC,eAAe,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;IAEzD,MAAM,OAAO,GAAG,CAAC,IAAc,EAAE,EAAW,EAAE,EAAE;QAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QACnD,MAAM,WAAW,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,QAAQ,CAAgB,CAAC;QAClF,MAAM,QAAQ,GAAG,WAAW,KAAK,QAAQ;YACxC,CAAC,CAAC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AAE,CAAC;QACjF,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,SAAS,CAA0B,CAAC;QAC1E,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * Compile-time declaration building: the response, outcome, template and context\n * declarations parsed from the item source, with their defaults, correct responses,\n * mappings and lookup tables.\n *\n * Everything here is a pure function of the parsed item document, so the compiled\n * declarations are immutable source-derived artifacts a definition shares between\n * sessions (each session deep-clones them before template rules mutate a copy).\n */\nimport {\n\ttype AreaMapEntry,\n\ttype AreaMapping,\n\ttype BaseType,\n\ttype Cardinality,\n\ttype DeclarationMap,\n\tcoerceBaseValue,\n\tfindDescendants,\n\tfindFirstDescendant,\n\tgetAttr,\n\ttype QtiValue,\n\tqtiNull,\n\tqtiValue,\n\tparseInterpolationTableDeclaration,\n\tparseMatchTableDeclaration,\n} from '@pie-qti/qti-processing';\nimport type { AttributeNameMapper, ElementNameMapper } from '@pie-qti/qti-common';\nimport type { AssessmentItemDocument } from '../../document/AssessmentItemDocument.js';\n\nexport type DeclKind = 'response' | 'outcome' | 'template' | 'context';\n\n/** The parsed item document a declaration map is compiled from. */\nexport interface DeclarationBuildInput {\n\treadonly itemDocument: AssessmentItemDocument;\n\treadonly mapper: ElementNameMapper;\n\treadonly attributeMapper: AttributeNameMapper | undefined;\n}\n\nexport function buildDeclarationMap(input: DeclarationBuildInput): DeclarationMap {\n\tconst { itemDocument, mapper, attributeMapper } = input;\n\tconst decls: DeclarationMap = {};\n\n\tconst getAttrMapped = (el: Element, canonicalName: string): string | null =>\n\t\treadMappedAttribute(attributeMapper, el, canonicalName);\n\n\tconst addDecl = (kind: DeclKind, el: Element) => {\n\t\tconst identifier = getAttrMapped(el, 'identifier');\n\t\tconst cardinality = (getAttrMapped(el, 'cardinality') || 'single') as Cardinality;\n\t\tconst baseType = cardinality === 'record'\n\t\t\t? undefined\n\t\t\t: (getAttrMapped(el, 'baseType') || 'string') as BaseType;\n\t\tif (!identifier) return;\n\n\t\tconst declaredDefault = parseDefaultValue(input, el, baseType, cardinality);\n\t\tconst impliedNumericDefault = !declaredDefault && hasImpliedNumericDefault(kind, baseType, cardinality);\n\t\tconst defaultValue = declaredDefault ?? impliedDefaultValue(kind, baseType, cardinality);\n\t\tdecls[identifier] = {\n\t\t\tidentifier,\n\t\t\t...(baseType ? { baseType } : {}),\n\t\t\tcardinality,\n\t\t\tdefaultValue,\n\t\t\tvalue: defaultValue,\n\t\t\tisTemplate: kind === 'template',\n\t\t\timpliedNumericDefault,\n\t\t\t// @ts-expect-error internal marker for templates\n\t\t\t__kind: kind,\n\t\t};\n\n\t\t// Only response declarations define a <mapping> (read by mapResponse). QTI's outcome\n\t\t// declarations carry no mapping element in any version — their tables are the\n\t\t// matchTable/interpolationTable below, read by lookupOutcomeValue.\n\t\tif (kind === 'response') {\n\t\t\tconst mappingEl = findFirstDescendant(el, mapper.toNative('mapping'));\n\t\t\tif (mappingEl && baseType) {\n\t\t\t\tdecls[identifier].mapping = parseMapping(mappingEl, baseType, mapper, attributeMapper);\n\t\t\t}\n\t\t}\n\n\t\t// Outcome declarations may define a lookup table (matchTable or interpolationTable)\n\t\t// used by the lookupOutcomeValue rule.\n\t\tif (kind === 'outcome') {\n\t\t\tconst matchTableEl = findFirstDescendant(el, mapper.toNative('matchtable'));\n\t\t\tconst interpolationTableEl = findFirstDescendant(el, mapper.toNative('interpolationtable'));\n\t\t\tif (matchTableEl) {\n\t\t\t\tdecls[identifier].lookupTable = parseMatchTableDeclaration(matchTableEl, mapper);\n\t\t\t} else if (interpolationTableEl) {\n\t\t\t\tdecls[identifier].lookupTable = parseInterpolationTableDeclaration(interpolationTableEl, mapper);\n\t\t\t}\n\t\t}\n\n\t\tif (kind === 'response') {\n\t\t\tconst correctEl = findFirstDescendant(el, mapper.toNative('correctresponse'));\n\t\t\tif (correctEl) {\n\t\t\t\tdecls[identifier].correctResponse = parseCorrectResponse(input, correctEl, baseType, cardinality);\n\t\t\t}\n\t\t\tconst areaMappingEl = findFirstDescendant(el, mapper.toNative('areamapping'));\n\t\t\tif (areaMappingEl) {\n\t\t\t\tdecls[identifier].areaMapping = parseAreaMapping(areaMappingEl, mapper);\n\t\t\t}\n\t\t}\n\t};\n\n\tfor (const el of itemDocument.findDeclarationElements('response')) addDecl('response', el);\n\tfor (const el of itemDocument.findDeclarationElements('outcome')) addDecl('outcome', el);\n\tfor (const el of itemDocument.findDeclarationElements('template')) addDecl('template', el);\n\tfor (const el of itemDocument.findDeclarationElements('context')) addDecl('context', el);\n\n\treturn decls;\n}\n\nexport function ensureBuiltinDeclarations(decls: DeclarationMap): void {\n\t// completionStatus + numAttempts are defined in QTI (esp. adaptive items) and commonly used\n\t// without explicit outcomeDeclaration in authoring content.\n\tif (!decls.completionStatus) {\n\t\tdecls.completionStatus = {\n\t\t\tidentifier: 'completionStatus',\n\t\t\tbaseType: 'identifier',\n\t\t\tcardinality: 'single',\n\t\t\tvalue: qtiValue('identifier', 'single', 'not_attempted'),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'outcome',\n\t\t};\n\t}\n\n\tif (!decls.numAttempts) {\n\t\tdecls.numAttempts = {\n\t\t\tidentifier: 'numAttempts',\n\t\t\tbaseType: 'integer',\n\t\t\tcardinality: 'single',\n\t\t\tdefaultValue: qtiValue('integer', 'single', 0),\n\t\t\tvalue: qtiValue('integer', 'single', 0),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'outcome',\n\t\t};\n\t}\n\n\tif (!decls.duration) {\n\t\tdecls.duration = {\n\t\t\tidentifier: 'duration',\n\t\t\tbaseType: 'duration',\n\t\t\tcardinality: 'single',\n\t\t\tdefaultValue: qtiValue('duration', 'single', 0),\n\t\t\tvalue: qtiValue('duration', 'single', 0),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'outcome',\n\t\t};\n\t}\n\n\t// QTI 3 built-in context variable, set by the delivery system.\n\tif (!decls.QTI_CONTEXT) {\n\t\tdecls.QTI_CONTEXT = {\n\t\t\tidentifier: 'QTI_CONTEXT',\n\t\t\tcardinality: 'record',\n\t\t\tdefaultValue: qtiNull(undefined, 'record'),\n\t\t\tvalue: qtiNull(undefined, 'record'),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'context',\n\t\t};\n\t}\n\n\t// Common scoring defaults\n\tif (!decls.SCORE) {\n\t\tdecls.SCORE = {\n\t\t\tidentifier: 'SCORE',\n\t\t\tbaseType: 'float',\n\t\t\tcardinality: 'single',\n\t\t\tvalue: qtiValue('float', 'single', 0),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'outcome',\n\t\t};\n\t}\n\tif (!decls.MAXSCORE) {\n\t\tdecls.MAXSCORE = {\n\t\t\tidentifier: 'MAXSCORE',\n\t\t\tbaseType: 'float',\n\t\t\tcardinality: 'single',\n\t\t\tvalue: qtiValue('float', 'single', 1),\n\t\t\tisTemplate: false,\n\t\t\t// @ts-expect-error internal marker\n\t\t\t__kind: 'outcome',\n\t\t};\n\t}\n}\n\n/**\n * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is\n * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.\n * Response and template variables keep NULL — an unanswered numeric response must stay\n * distinguishable from an answered zero.\n */\nexport function hasImpliedNumericDefault(\n\tkind: DeclKind,\n\tbaseType: BaseType | undefined,\n\tcardinality: Cardinality,\n): boolean {\n\tif (kind !== 'outcome' || cardinality !== 'single') return false;\n\treturn baseType === 'integer' || baseType === 'float';\n}\n\nexport function impliedDefaultValue(\n\tkind: DeclKind,\n\tbaseType: BaseType | undefined,\n\tcardinality: Cardinality,\n): QtiValue {\n\tif (hasImpliedNumericDefault(kind, baseType, cardinality)) {\n\t\treturn qtiValue(baseType as 'integer' | 'float', 'single', 0);\n\t}\n\treturn qtiNull(baseType, cardinality);\n}\n\n/** Returns undefined when the declaration carries no <defaultValue> at all. */\nfunction parseDefaultValue(\n\tinput: DeclarationBuildInput,\n\tdeclEl: Element,\n\tbaseType: BaseType | undefined,\n\tcardinality: Cardinality,\n): QtiValue | undefined {\n\tconst defaultEl = findFirstDescendant(declEl, input.mapper.toNative('defaultvalue'));\n\tif (!defaultEl) return undefined;\n\treturn parseDeclarationValues(input, defaultEl, baseType, cardinality);\n}\n\nfunction parseCorrectResponse(\n\tinput: DeclarationBuildInput,\n\tcorrectEl: Element,\n\tbaseType: BaseType | undefined,\n\tcardinality: Cardinality,\n): QtiValue {\n\treturn parseDeclarationValues(input, correctEl, baseType, cardinality);\n}\n\nfunction parseDeclarationValues(\n\tinput: DeclarationBuildInput,\n\tcontainer: Element,\n\tbaseType: BaseType | undefined,\n\tcardinality: Cardinality,\n): QtiValue {\n\tconst { mapper, itemDocument } = input;\n\tconst contentLanguage = itemDocument.getContentLanguage();\n\tconst valueElements = findDescendants(container, mapper.toNative('value'));\n\tif (cardinality === 'record') {\n\t\tconst record: Record<string, QtiValue> = {};\n\t\tfor (const valueElement of valueElements) {\n\t\t\tconst fieldIdentifier = readMappedAttribute(input.attributeMapper, valueElement, 'fieldIdentifier');\n\t\t\tconst fieldBaseType = readMappedAttribute(input.attributeMapper, valueElement, 'baseType') as BaseType | null;\n\t\t\tif (!fieldIdentifier || !fieldBaseType) continue;\n\t\t\trecord[fieldIdentifier] = coerceBaseValue(fieldBaseType, valueElement.textContent || '', contentLanguage);\n\t\t}\n\t\treturn Object.keys(record).length > 0\n\t\t\t? qtiValue(undefined, 'record', record)\n\t\t\t: qtiNull(undefined, 'record');\n\t}\n\n\tif (!baseType) return qtiNull(undefined, cardinality);\n\tconst values = valueElements.map((value) => (value.textContent || '').trim());\n\tif (cardinality === 'multiple' || cardinality === 'ordered') {\n\t\treturn qtiValue(\n\t\t\tbaseType,\n\t\t\tcardinality,\n\t\t\tvalues.map((t) => {\n\t\t\t\tconst v = coerceBaseValue(baseType, t, contentLanguage);\n\t\t\t\treturn v.kind === 'value' ? v.value : null;\n\t\t\t})\n\t\t);\n\t}\n\treturn coerceBaseValue(baseType, values[0] ?? '', contentLanguage);\n}\n\n/**\n * Get attribute value with QTI version support: the attribute mapper's native form\n * first (e.g., 'mapkey' -> 'map-key' for QTI 3.0), then the canonical name for\n * QTI 2.x compatibility.\n */\nfunction readMappedAttribute(\n\tattributeMapper: AttributeNameMapper | undefined,\n\tel: Element,\n\tcanonicalName: string,\n): string | null {\n\tif (attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(canonicalName);\n\t\tconst value = el.getAttribute(nativeName);\n\t\tif (value !== null) return value;\n\t}\n\treturn getAttr(el, canonicalName);\n}\n\nfunction parseMapping(mappingEl: Element, baseType: BaseType, mapper: ElementNameMapper, attributeMapper: AttributeNameMapper | undefined) {\n\tconst defaultValue = Number(getAttr(mappingEl, 'defaultValue') || 0);\n\tconst lowerBound = getAttr(mappingEl, 'lowerBound') ? Number(getAttr(mappingEl, 'lowerBound')) : undefined;\n\tconst upperBound = getAttr(mappingEl, 'upperBound') ? Number(getAttr(mappingEl, 'upperBound')) : undefined;\n\t// mapEntry@caseSensitive defaults to \"false\" (QTI 2.2 XSD, optional, default \"false\"):\n\t// string entries match case-insensitively unless authored \"true\". The mapping element\n\t// itself defines no caseSensitive attribute in any QTI version, so none is read.\n\tconst entries: Record<string, any> = {};\n\n\tconst normalizePairKey = (k: string): string => {\n\t\tconst parts = k.trim().split(/\\s+/).filter(Boolean);\n\t\tif (parts.length === 2) return [...parts].sort().join(' ');\n\t\treturn k.trim();\n\t};\n\n\tconst normalizeDirectedPairKey = (k: string): string => {\n\t\tconst parts = k.trim().split(/\\s+/).filter(Boolean);\n\t\tif (parts.length >= 2) return `${parts[0]} ${parts[1]}`;\n\t\treturn k.trim();\n\t};\n\n\tfor (const e of findDescendants(mappingEl, mapper.toNative('mapentry'))) {\n\t\tconst mapKey = readMappedAttribute(attributeMapper, e, 'mapKey');\n\t\tconst mappedValue = readMappedAttribute(attributeMapper, e, 'mappedValue');\n\t\tif (!mapKey || mappedValue === null) continue;\n\t\t// Only string values fold case: identifier and the other base types always match\n\t\t// exactly (QTI ASI §17), whatever the entry says.\n\t\tconst effectiveCaseSensitive = baseType === 'string' ? readMappedAttribute(attributeMapper, e, 'caseSensitive') || 'false' : 'true';\n\t\tconst storedKey =\n\t\t\tbaseType === 'pair'\n\t\t\t\t? normalizePairKey(mapKey)\n\t\t\t\t: baseType === 'directedPair'\n\t\t\t\t\t? normalizeDirectedPairKey(mapKey)\n\t\t\t\t\t: mapKey;\n\t\tentries[storedKey] = { mapKey: storedKey, mappedValue: Number(mappedValue), caseSensitive: effectiveCaseSensitive };\n\t\tif (effectiveCaseSensitive !== 'true') {\n\t\t\tconst lowerKey = storedKey.toLowerCase();\n\t\t\tentries[lowerKey] = {\n\t\t\t\tmapKey: lowerKey,\n\t\t\t\tmappedValue: Number(mappedValue),\n\t\t\t\tcaseSensitive: effectiveCaseSensitive,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn { defaultValue, lowerBound, upperBound, entries };\n}\n\nfunction parseAreaMapping(areaMappingEl: Element, mapper: ElementNameMapper): AreaMapping {\n\tconst defaultValue = Number(getAttr(areaMappingEl, 'defaultValue') || 0);\n\tconst lowerBound = getAttr(areaMappingEl, 'lowerBound')\n\t\t? Number(getAttr(areaMappingEl, 'lowerBound'))\n\t\t: undefined;\n\tconst upperBound = getAttr(areaMappingEl, 'upperBound')\n\t\t? Number(getAttr(areaMappingEl, 'upperBound'))\n\t\t: undefined;\n\n\tconst entries: AreaMapEntry[] = [];\n\tfor (const e of findDescendants(areaMappingEl, mapper.toNative('areamapentry'))) {\n\t\tconst shape = (getAttr(e, 'shape') || 'default') as AreaMapEntry['shape'];\n\t\tconst coords = String(getAttr(e, 'coords') || '');\n\t\tconst mappedValue = Number(getAttr(e, 'mappedValue') || 0);\n\t\tentries.push({ shape, coords, mappedValue });\n\t}\n\n\treturn { defaultValue, lowerBound, upperBound, entries };\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Runtime value coercion: raw host/component/serialized values read as a declaration's
3
+ * QTI base type and cardinality.
4
+ */
5
+ import { type BaseType, type Cardinality, type QtiValue } from '@pie-qti/qti-processing';
6
+ import type { AssessmentItemDocument } from '../../document/AssessmentItemDocument.js';
7
+ /** The parsed item document numeric input bases and the content language are read from. */
8
+ export interface DeclarationValueInput {
9
+ readonly itemDocument: AssessmentItemDocument;
10
+ }
11
+ export declare function coerceToDeclarationValue(input: DeclarationValueInput, baseType: BaseType | undefined, cardinality: Cardinality, raw: unknown, identifier?: string): QtiValue;