@pie-qti/item-player 1.0.0-beta.4 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/README.md +33 -5
  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 +387 -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-BbF4Dj7F.js +3773 -0
  81. package/dist/element-class-BbF4Dj7F.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 +1 -1
  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 +4 -2
  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 +7 -1
  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 +15 -14
  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 @@
1
+ {"version":3,"file":"feedbackAnnouncement.js","sourceRoot":"","sources":["../../src/presentation/feedbackAnnouncement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAe/D,MAAM,aAAa,GAAkB,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AAS/E,MAAM,YAAY,GACjB,+FAA+F,CAAC;AAWjG;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,IAAY;IACrC,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,MAAM,IAAI,GAAsB,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,CAAC,OAAwB,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,QAAQ,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnG,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,AAAD,EAAG,KAAK,GAAG,EAAE,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC;QACxD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC1B,MAAM,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC;QAC/B,IAAI,OAAO,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO;gBAAE,SAAS;YACvB,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC;YAC3B,OAAO,CAAC,QAAQ,GAAG,GAAG,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O,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * Screen-reader announcement of integrated feedback (WCAG 4.1.3 Status Messages).\n *\n * The presentation plan splices the feedbackInline and feedbackBlock that an attempt shows into\n * the item body HTML, with no marker left behind. They appear without moving focus and without\n * any other change assistive technology can detect. The item body therefore announces them\n * through one persistent polite live region. This module holds the pure rules behind that:\n * what the shown feedback says, which session transitions announce it, and how an identical\n * repeat still reaches a screen reader.\n */\n\nimport { isShownByIdentifier } from '@pie-qti/qti-common';\nimport type { ItemSessionTransition } from '../core/ItemSession.js';\nimport type { QTIRole } from '../types/index.js';\nimport { readHtmlAttribute } from '../utils/htmlAttributes.js';\n\n/** The integrated feedback an item body shows. */\nexport interface ShownFeedback {\n\t/** Whether any feedbackInline or feedbackBlock with content is shown. */\n\treadonly shown: boolean;\n\t/**\n\t * Accessible text of the shown feedback in document order: visible text plus image `alt` text,\n\t * markup removed and whitespace collapsed. Empty when nothing is shown, or when what is shown\n\t * has no text, such as an image with no alt. A shown feedback with no text is announced as a\n\t * localized \"Feedback is shown.\" instead.\n\t */\n\treadonly text: string;\n}\n\nconst NOTHING_SHOWN: ShownFeedback = Object.freeze({ shown: false, text: '' });\n\nexport interface ExtractShownFeedbackOptions {\n\t/** Show no feedback whatever the outcomes, as a test-level `showFeedback=\"false\"` requires. */\n\treadonly hideAll?: boolean;\n\t/** The authoring heuristics the plan applies to shown feedback (`cleanFeedbackText`). */\n\treadonly transform?: (html: string) => string;\n}\n\nconst FEEDBACK_TAG =\n\t/<(\\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\\b([^>]*?)(\\/?)>/gi;\n\ninterface FeedbackElement {\n\treadonly attrs: string;\n\treadonly openStart: number;\n\treadonly openEnd: number;\n\tcloseStart: number;\n\tcloseEnd: number;\n\treadonly children: FeedbackElement[];\n}\n\n/**\n * The top-level feedback elements in `html`, each with the feedback nested inside it. Parsed as\n * `processFeedbackInline` in `@pie-qti/qti-common` parses them, so the announcement covers exactly\n * the elements the plan shows or drops. An unclosed element is left as written, as it is there.\n */\nfunction feedbackElements(html: string): FeedbackElement[] {\n\tconst roots: FeedbackElement[] = [];\n\tconst open: FeedbackElement[] = [];\n\tconst add = (element: FeedbackElement) => (open[open.length - 1]?.children ?? roots).push(element);\n\tfor (const match of html.matchAll(FEEDBACK_TAG)) {\n\t\tconst [tag, closing, , attrs = '', selfClosing] = match;\n\t\tconst start = match.index;\n\t\tconst end = start + tag.length;\n\t\tif (closing) {\n\t\t\tconst element = open.pop();\n\t\t\tif (!element) continue;\n\t\t\telement.closeStart = start;\n\t\t\telement.closeEnd = end;\n\t\t\tadd(element);\n\t\t} else {\n\t\t\tconst element: FeedbackElement = { attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };\n\t\t\tif (selfClosing) add(element);\n\t\t\telse open.push(element);\n\t\t}\n\t}\n\treturn roots;\n}\n\nfunction isShown(element: FeedbackElement, outcomeValues: Readonly<Record<string, unknown>>): boolean {\n\tconst outcomeId = readHtmlAttribute(element.attrs, 'outcomeIdentifier');\n\tconst feedbackId = readHtmlAttribute(element.attrs, 'identifier');\n\tif (outcomeId === null || feedbackId === null) return false;\n\treturn isShownByIdentifier(outcomeValues[outcomeId], feedbackId, readHtmlAttribute(element.attrs, 'showHide'));\n}\n\n/** A shown element's content as the plan renders it: nested feedback resolved, hidden feedback dropped. */\nfunction shownContent(html: string, element: FeedbackElement, outcomeValues: Readonly<Record<string, unknown>>): string {\n\tlet out = '';\n\tlet position = element.openEnd;\n\tfor (const child of element.children) {\n\t\tout += html.slice(position, child.openStart);\n\t\tposition = child.closeEnd;\n\t\tif (isShown(child, outcomeValues)) out += shownContent(html, child, outcomeValues);\n\t}\n\treturn out + html.slice(position, element.closeStart);\n}\n\n/** Phrasing elements: their text runs on with the text around them (\"<strong>sum</strong>.\" reads \"sum.\"). */\nconst PHRASING_ELEMENTS = new Set([\n\t'a', 'abbr', 'b', 'bdi', 'bdo', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd',\n\t'label', 'mark', 'q', 'rb', 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup',\n\t'time', 'u', 'var', 'wbr',\n]);\n\nconst NAMED_CHARACTERS: Readonly<Record<string, string>> = {\n\tamp: '&',\n\tlt: '<',\n\tgt: '>',\n\tquot: '\"',\n\tapos: \"'\",\n\tnbsp: '\\u00a0',\n};\n\nfunction decodeCharacterReferences(text: string): string {\n\treturn text.replace(/&(#[xX][0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (reference, body: string) => {\n\t\tif (body[0] !== '#') return NAMED_CHARACTERS[body.toLowerCase()] ?? reference;\n\t\tconst code = body[1] === 'x' || body[1] === 'X' ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);\n\t\treturn code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : reference;\n\t});\n}\n\n/** HTML as a screen reader reads it: images by their alt text, inert content skipped, whitespace collapsed. */\nfunction accessibleText(html: string): string {\n\tconst text = html\n\t\t.replace(/<!--[\\s\\S]*?-->/g, '')\n\t\t.replace(/<(script|style|template|noscript)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi, ' ')\n\t\t.replace(/<img\\b[^>]*>/gi, (tag) => ` ${readHtmlAttribute(tag.slice(4, -1), 'alt') ?? ''} `)\n\t\t.replace(/<\\/?([a-zA-Z][\\w:-]*)\\b[^>]*>/g, (_tag, name: string) => (PHRASING_ELEMENTS.has(name.toLowerCase()) ? '' : ' '))\n\t\t.replace(/<[^>]*>/g, ' ');\n\t// Character references are decoded last, so an encoded `&lt;` is never mistaken for markup.\n\treturn decodeCharacterReferences(text).replace(/\\s+/g, ' ').trim();\n}\n\n/** Content that renders something: any text or element, comments aside. */\nfunction rendersSomething(html: string): boolean {\n\treturn /\\S/.test(html.replace(/<!--[\\s\\S]*?-->/g, ''));\n}\n\n/**\n * The feedback that `outcomeValues` show in an item body, read as text in document order.\n *\n * Runs on the body HTML *before* the plan splices the feedback in, while every element still\n * carries its `outcomeIdentifier` and `identifier`. Visibility follows the shared rule\n * (`isShownByIdentifier`, including `showHide=\"hide\"` and container membership). Nested feedback\n * resolves inside shown feedback, and hidden feedback contributes nothing, not even what is\n * nested inside it. Separate feedback elements are joined with a space.\n */\nexport function extractShownFeedback(\n\tbodyHtml: string,\n\toutcomeValues: Readonly<Record<string, unknown>>,\n\toptions: ExtractShownFeedbackOptions = {},\n): ShownFeedback {\n\tif (!bodyHtml || options.hideAll) return NOTHING_SHOWN;\n\tconst texts: string[] = [];\n\tlet shown = false;\n\tfor (const root of feedbackElements(bodyHtml)) {\n\t\tif (!isShown(root, outcomeValues)) continue;\n\t\tconst content = shownContent(bodyHtml, root, outcomeValues);\n\t\tif (!rendersSomething(content)) continue;\n\t\tshown = true;\n\t\tconst text = accessibleText(options.transform ? options.transform(content) : content);\n\t\tif (text) texts.push(text);\n\t}\n\treturn shown ? { shown, text: texts.join(' ') } : NOTHING_SHOWN;\n}\n\n/**\n * Whether a session transition is the candidate's own attempt ending: a submit or end-attempt,\n * which covers every attempt of an adaptive item, including an uncounted `countAttempt=\"false\"`\n * one. Feedback is the result of the attempt, so only an attempt announces it. Initial render and\n * restore dispatch nothing. Review and scorer renders dispatch no attempt, because a scorer is\n * excluded by role and an ended session refuses attempt commands. All of them therefore stay\n * silent, however often they re-render.\n */\nexport function isCandidateAttemptFeedback(transition: Pick<ItemSessionTransition, 'command'>, role: QTIRole): boolean {\n\tconst { action } = transition.command;\n\treturn role === 'candidate' && (action === 'endAttempt' || action === 'submitAttempt');\n}\n\n/**\n * The live-region text for `message`, given the text it holds now. Repeating identical text would\n * leave the region unchanged, and assistive technology does not announce an unchanged region. A\n * repeat therefore toggles a trailing zero-width space, which a screen reader does not read but\n * which still changes the region. The interaction components use the same toggle for refusals.\n */\nexport function nextFeedbackAnnouncement(previous: string | null | undefined, message: string): string {\n\treturn previous === message ? `${message}\\u200b` : message;\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { BaseInteractionData } from '../interactions/shared/types.js';
2
+ /**
3
+ * The attribute on the empty placeholder that marks where an interaction was authored in the
4
+ * item body. A renderer mounts the interaction into the element carrying it.
5
+ */
6
+ export declare const INTERACTION_SLOT_ATTRIBUTE = "data-qti-interaction-slot";
7
+ /** How a slot lays out: `inline` stays in sentence flow, `block` takes its own line. */
8
+ export type InteractionSlotPlacement = 'block' | 'inline';
9
+ export interface PlacedInteractionSlots {
10
+ /** The body HTML with each located interaction element replaced by its empty slot. */
11
+ readonly html: string;
12
+ /**
13
+ * The slot id per index into the interactions, numbered in document order. An interaction
14
+ * whose element is not in the body has no entry.
15
+ */
16
+ readonly slots: ReadonlyMap<number, string>;
17
+ }
18
+ /**
19
+ * Replace every interaction element in the item body with an empty slot element at the same
20
+ * position, so the interaction renders where it was authored: between paragraphs, after the
21
+ * text that introduces it, inside layout rows and columns, table cells and other containers.
22
+ *
23
+ * An element is matched to the interaction data by its response identifier, in document order.
24
+ * A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,
25
+ * because its renderer draws the stage background as well. Interaction elements that match no
26
+ * interaction data are hidden rather than shown as raw markup, and authored slot attributes are
27
+ * removed so content cannot redirect where an interaction mounts.
28
+ */
29
+ export declare function placeInteractionSlots(html: string, interactions: readonly BaseInteractionData[], placementOf: (interaction: BaseInteractionData) => InteractionSlotPlacement): PlacedInteractionSlots;
30
+ /** Whether the final body markup still carries `slot`, after sanitation has run over it. */
31
+ export declare function hasInteractionSlot(html: string, slot: string): boolean;
@@ -0,0 +1,101 @@
1
+ import { NodeType, parse } from 'node-html-parser';
2
+ import { readResponseIdentifier } from '../extraction/responseIdentifier.js';
3
+ /**
4
+ * The attribute on the empty placeholder that marks where an interaction was authored in the
5
+ * item body. A renderer mounts the interaction into the element carrying it.
6
+ */
7
+ export const INTERACTION_SLOT_ATTRIBUTE = 'data-qti-interaction-slot';
8
+ /** Element names of interactions in either QTI spelling: `choiceInteraction`, `qti-choice-interaction`. */
9
+ const INTERACTION_TAG = /(?:^[a-z]+interaction$|^qti-[a-z-]+-interaction$)/i;
10
+ const POSITION_OBJECT_STAGE = /^(?:positionobjectstage|qti-position-object-stage)$/i;
11
+ /** Cheap pre-check: markup without any of these needs no structural pass. */
12
+ const NEEDS_SLOT_PASS = /interaction|positionobjectstage|position-object-stage|data-qti-interaction-slot/i;
13
+ /**
14
+ * Replace every interaction element in the item body with an empty slot element at the same
15
+ * position, so the interaction renders where it was authored: between paragraphs, after the
16
+ * text that introduces it, inside layout rows and columns, table cells and other containers.
17
+ *
18
+ * An element is matched to the interaction data by its response identifier, in document order.
19
+ * A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,
20
+ * because its renderer draws the stage background as well. Interaction elements that match no
21
+ * interaction data are hidden rather than shown as raw markup, and authored slot attributes are
22
+ * removed so content cannot redirect where an interaction mounts.
23
+ */
24
+ export function placeInteractionSlots(html, interactions, placementOf) {
25
+ const slots = new Map();
26
+ if (!html || !NEEDS_SLOT_PASS.test(html))
27
+ return { html, slots };
28
+ const pending = new Map();
29
+ interactions.forEach((interaction, index) => {
30
+ const queue = pending.get(interaction.responseId);
31
+ if (queue)
32
+ queue.push(index);
33
+ else
34
+ pending.set(interaction.responseId, [index]);
35
+ });
36
+ const takeInteraction = (element) => {
37
+ const responseId = responseIdentifierOf(element);
38
+ return responseId ? pending.get(responseId)?.shift() : undefined;
39
+ };
40
+ const slotMarkup = (index) => {
41
+ const id = String(slots.size);
42
+ slots.set(index, id);
43
+ const placement = placementOf(interactions[index]);
44
+ return `<span class="qti-interaction-slot qti-interaction-slot--${placement}" ${INTERACTION_SLOT_ATTRIBUTE}="${id}"></span>`;
45
+ };
46
+ const collectStageInteractions = (element, found) => {
47
+ for (const child of elementChildren(element)) {
48
+ const index = takeInteraction(child);
49
+ if (index !== undefined)
50
+ found.push(index);
51
+ else
52
+ collectStageInteractions(child, found);
53
+ }
54
+ };
55
+ const visit = (parent) => {
56
+ for (const child of elementChildren(parent)) {
57
+ if (child.hasAttribute(INTERACTION_SLOT_ATTRIBUTE)) {
58
+ child.removeAttribute(INTERACTION_SLOT_ATTRIBUTE);
59
+ }
60
+ const tagName = child.rawTagName ?? '';
61
+ if (POSITION_OBJECT_STAGE.test(tagName)) {
62
+ const found = [];
63
+ collectStageInteractions(child, found);
64
+ child.replaceWith(found.length > 0 ? found.map(slotMarkup).join('') : hiddenMarkup(child));
65
+ continue;
66
+ }
67
+ const index = takeInteraction(child);
68
+ if (index !== undefined) {
69
+ child.replaceWith(slotMarkup(index));
70
+ continue;
71
+ }
72
+ if (INTERACTION_TAG.test(tagName)) {
73
+ child.replaceWith(hiddenMarkup(child));
74
+ continue;
75
+ }
76
+ visit(child);
77
+ }
78
+ };
79
+ const root = parse(html, { lowerCaseTagName: false, comment: false });
80
+ visit(root);
81
+ return { html: root.toString(), slots };
82
+ }
83
+ /** Whether the final body markup still carries `slot`, after sanitation has run over it. */
84
+ export function hasInteractionSlot(html, slot) {
85
+ return html.includes(`${INTERACTION_SLOT_ATTRIBUTE}="${slot}"`);
86
+ }
87
+ function elementChildren(element) {
88
+ return element.childNodes.filter((node) => node.nodeType === NodeType.ELEMENT_NODE);
89
+ }
90
+ /** Slot hiding reads the binding on the HTML tree, without a mapper. */
91
+ function responseIdentifierOf(element) {
92
+ return readResponseIdentifier(element);
93
+ }
94
+ /**
95
+ * Interaction markup with no interaction data behind it is kept hidden in the body, never shown
96
+ * as raw prompt and choice text.
97
+ */
98
+ function hiddenMarkup(element) {
99
+ return `<span class="qti-hidden-interaction">${element.toString()}</span>`;
100
+ }
101
+ //# sourceMappingURL=interactionSlots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactionSlots.js","sourceRoot":"","sources":["../../src/presentation/interactionSlots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1F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AC;AAC5E,CAAC","sourcesContent":["import { type HTMLElement as ParsedHtmlElement, NodeType, parse } from 'node-html-parser';\nimport { readResponseIdentifier } from '../extraction/responseIdentifier.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\n\n/**\n * The attribute on the empty placeholder that marks where an interaction was authored in the\n * item body. A renderer mounts the interaction into the element carrying it.\n */\nexport const INTERACTION_SLOT_ATTRIBUTE = 'data-qti-interaction-slot';\n\n/** How a slot lays out: `inline` stays in sentence flow, `block` takes its own line. */\nexport type InteractionSlotPlacement = 'block' | 'inline';\n\nexport interface PlacedInteractionSlots {\n\t/** The body HTML with each located interaction element replaced by its empty slot. */\n\treadonly html: string;\n\t/**\n\t * The slot id per index into the interactions, numbered in document order. An interaction\n\t * whose element is not in the body has no entry.\n\t */\n\treadonly slots: ReadonlyMap<number, string>;\n}\n\n/** Element names of interactions in either QTI spelling: `choiceInteraction`, `qti-choice-interaction`. */\nconst INTERACTION_TAG = /(?:^[a-z]+interaction$|^qti-[a-z-]+-interaction$)/i;\nconst POSITION_OBJECT_STAGE = /^(?:positionobjectstage|qti-position-object-stage)$/i;\n/** Cheap pre-check: markup without any of these needs no structural pass. */\nconst NEEDS_SLOT_PASS = /interaction|positionobjectstage|position-object-stage|data-qti-interaction-slot/i;\n\n/**\n * Replace every interaction element in the item body with an empty slot element at the same\n * position, so the interaction renders where it was authored: between paragraphs, after the\n * text that introduces it, inside layout rows and columns, table cells and other containers.\n *\n * An element is matched to the interaction data by its response identifier, in document order.\n * A `positionObjectStage` is replaced as a unit by the slots of the interactions inside it,\n * because its renderer draws the stage background as well. Interaction elements that match no\n * interaction data are hidden rather than shown as raw markup, and authored slot attributes are\n * removed so content cannot redirect where an interaction mounts.\n */\nexport function placeInteractionSlots(\n\thtml: string,\n\tinteractions: readonly BaseInteractionData[],\n\tplacementOf: (interaction: BaseInteractionData) => InteractionSlotPlacement,\n): PlacedInteractionSlots {\n\tconst slots = new Map<number, string>();\n\tif (!html || !NEEDS_SLOT_PASS.test(html)) return { html, slots };\n\n\tconst pending = new Map<string, number[]>();\n\tinteractions.forEach((interaction, index) => {\n\t\tconst queue = pending.get(interaction.responseId);\n\t\tif (queue) queue.push(index);\n\t\telse pending.set(interaction.responseId, [index]);\n\t});\n\n\tconst takeInteraction = (element: ParsedHtmlElement): number | undefined => {\n\t\tconst responseId = responseIdentifierOf(element);\n\t\treturn responseId ? pending.get(responseId)?.shift() : undefined;\n\t};\n\n\tconst slotMarkup = (index: number): string => {\n\t\tconst id = String(slots.size);\n\t\tslots.set(index, id);\n\t\tconst placement = placementOf(interactions[index]);\n\t\treturn `<span class=\"qti-interaction-slot qti-interaction-slot--${placement}\" ${INTERACTION_SLOT_ATTRIBUTE}=\"${id}\"></span>`;\n\t};\n\n\tconst collectStageInteractions = (element: ParsedHtmlElement, found: number[]): void => {\n\t\tfor (const child of elementChildren(element)) {\n\t\t\tconst index = takeInteraction(child);\n\t\t\tif (index !== undefined) found.push(index);\n\t\t\telse collectStageInteractions(child, found);\n\t\t}\n\t};\n\n\tconst visit = (parent: ParsedHtmlElement): void => {\n\t\tfor (const child of elementChildren(parent)) {\n\t\t\tif (child.hasAttribute(INTERACTION_SLOT_ATTRIBUTE)) {\n\t\t\t\tchild.removeAttribute(INTERACTION_SLOT_ATTRIBUTE);\n\t\t\t}\n\t\t\tconst tagName = child.rawTagName ?? '';\n\n\t\t\tif (POSITION_OBJECT_STAGE.test(tagName)) {\n\t\t\t\tconst found: number[] = [];\n\t\t\t\tcollectStageInteractions(child, found);\n\t\t\t\tchild.replaceWith(found.length > 0 ? found.map(slotMarkup).join('') : hiddenMarkup(child));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst index = takeInteraction(child);\n\t\t\tif (index !== undefined) {\n\t\t\t\tchild.replaceWith(slotMarkup(index));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (INTERACTION_TAG.test(tagName)) {\n\t\t\t\tchild.replaceWith(hiddenMarkup(child));\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tvisit(child);\n\t\t}\n\t};\n\n\tconst root = parse(html, { lowerCaseTagName: false, comment: false });\n\tvisit(root as unknown as ParsedHtmlElement);\n\treturn { html: root.toString(), slots };\n}\n\n/** Whether the final body markup still carries `slot`, after sanitation has run over it. */\nexport function hasInteractionSlot(html: string, slot: string): boolean {\n\treturn html.includes(`${INTERACTION_SLOT_ATTRIBUTE}=\"${slot}\"`);\n}\n\nfunction elementChildren(element: ParsedHtmlElement): ParsedHtmlElement[] {\n\treturn (element.childNodes as unknown as ParsedHtmlElement[]).filter(\n\t\t(node) => node.nodeType === NodeType.ELEMENT_NODE,\n\t);\n}\n\n/** Slot hiding reads the binding on the HTML tree, without a mapper. */\nfunction responseIdentifierOf(element: ParsedHtmlElement): string | undefined {\n\treturn readResponseIdentifier(element);\n}\n\n/**\n * Interaction markup with no interaction data behind it is kept hidden in the body, never shown\n * as raw prompt and choice text.\n */\nfunction hiddenMarkup(element: ParsedHtmlElement): string {\n\treturn `<span class=\"qti-hidden-interaction\">${element.toString()}</span>`;\n}\n"]}
@@ -4,7 +4,9 @@ import type { ComponentRegistry } from '../core/ComponentRegistry.js';
4
4
  import type { PnpProfile } from '../pnp/types.js';
5
5
  import { type RoleCapabilities } from '../core/rolePolicy.js';
6
6
  import type { HtmlContent, PlayerSecurityConfig, QTIRole, RubricBlock } from '../types/index.js';
7
+ import { type ShownFeedback } from './feedbackAnnouncement.js';
7
8
  import type { BaseInteractionData, InlineChoiceInteractionData, TextEntryInteractionData } from '../interactions/shared/types.js';
9
+ export { INTERACTION_SLOT_ATTRIBUTE } from './interactionSlots.js';
8
10
  export type ItemPresentationResponseValue = unknown;
9
11
  export type ItemPresentationResponseMap = Record<string, ItemPresentationResponseValue>;
10
12
  /**
@@ -48,6 +50,12 @@ export interface BlockInteractionMount {
48
50
  readonly interaction: BaseInteractionData;
49
51
  readonly tagName: string;
50
52
  readonly key: string;
53
+ /**
54
+ * The slot this interaction mounts into: the `data-qti-interaction-slot` value of the empty
55
+ * placeholder at its authored position in the body HTML. Null when the interaction's element
56
+ * is not in the body; the interaction then renders after the body.
57
+ */
58
+ readonly slot: string | null;
51
59
  readonly response: ItemPresentationResponseValue | null;
52
60
  /** Lexical companion value used by extendedTextInteraction stringIdentifier. */
53
61
  readonly stringResponse?: ItemPresentationResponseValue | null;
@@ -60,16 +68,51 @@ export interface BlockInteractionMount {
60
68
  readonly disabled: boolean;
61
69
  readonly componentRole: 'scorer' | undefined;
62
70
  }
63
- export type InlineInteractionMount = {
71
+ /** Where an inline interaction sits among the item's inline interactions, in document order. */
72
+ export interface InlineInteractionPosition {
73
+ /** 1-based. */
74
+ readonly index: number;
75
+ readonly count: number;
76
+ }
77
+ interface InlineInteractionMountBase {
64
78
  readonly placement: 'inline';
79
+ readonly key: string;
80
+ /** As for {@link BlockInteractionMount.slot}; the slot stays in its sentence. */
81
+ readonly slot: string | null;
82
+ /**
83
+ * Its position among the item's inline interactions, which names it for assistive
84
+ * technology ("Blank 2 of 4") when no label is authored. The response identifier never
85
+ * does: it is author data and can hint at the answer.
86
+ */
87
+ readonly position: InlineInteractionPosition;
88
+ }
89
+ export type InlineInteractionMount = (InlineInteractionMountBase & {
65
90
  readonly renderer: 'text-entry';
66
91
  readonly interaction: TextEntryInteractionData;
67
- } | {
68
- readonly placement: 'inline';
92
+ /**
93
+ * The text the candidate entered, held by the response the interaction's
94
+ * stringIdentifier names: the field shows it while it is present, so "3.50" is restored
95
+ * as typed rather than as the numeric response's 3.5.
96
+ */
97
+ readonly stringResponse?: ItemPresentationResponseValue | null;
98
+ }) | (InlineInteractionMountBase & {
69
99
  readonly renderer: 'inline-choice';
70
100
  readonly interaction: InlineChoiceInteractionData;
71
- };
101
+ });
72
102
  export type ItemInteractionMount = InlineInteractionMount | BlockInteractionMount;
103
+ /**
104
+ * An interaction whose web component the registry could not resolve: it has no mount in
105
+ * `flow`, the body keeps rendering around it, and it still owns its slot. The presenter
106
+ * stands the render-failed `role="alert"` placeholder — the same one a mount that throws
107
+ * gets — in that slot.
108
+ */
109
+ export interface FailedInteractionMount {
110
+ /** Unique key, drawn from the same keying the mounts use. */
111
+ readonly key: string;
112
+ /** As for {@link BlockInteractionMount.slot}. */
113
+ readonly slot: string | null;
114
+ readonly interaction: BaseInteractionData;
115
+ }
73
116
  declare const finalItemBodyHtmlBrand: unique symbol;
74
117
  /** HTML that has completed every body transform, sanitation, and Trusted Types finalization. */
75
118
  export type FinalItemBodyHtml = HtmlContent & {
@@ -90,11 +133,31 @@ export interface ItemPresentation {
90
133
  readonly correctResponses: Readonly<Record<string, unknown>>;
91
134
  /** Direct assessmentItem rubrics that remain outside the item-body flow. */
92
135
  readonly directRubrics: readonly RubricBlock[];
93
- /** Ordered, render-neutral body flow. Block mounts follow the authored body HTML. */
136
+ /**
137
+ * Ordered, render-neutral body flow: one `html` node holding the whole item body, then every
138
+ * interaction mount in document order. The body keeps each interaction's authored position as
139
+ * an empty slot element (`[data-qti-interaction-slot]`); render the body once and mount each
140
+ * interaction into the slot its `slot` names, which keeps block interactions between the
141
+ * paragraphs, layout columns and table cells they were authored in and inline interactions in
142
+ * their sentence. A mount whose `slot` is null renders after the body.
143
+ */
94
144
  readonly flow: readonly ItemPresentationFlowNode[];
145
+ /**
146
+ * Interactions whose component the registry failed to resolve (no component renders the
147
+ * type), with the slot each authored. The host heard each failure once through
148
+ * `onComponentError`; the presenter keeps the candidate-facing half of that contract —
149
+ * the visible placeholder — in place while the failure stands.
150
+ */
151
+ readonly failedInteractions: readonly FailedInteractionMount[];
95
152
  /** Policy-checked CSS is kept out of the HTML/Trusted Types pipeline. */
96
153
  readonly scopedCss: string;
154
+ /**
155
+ * The feedbackInline and feedbackBlock this body shows, read as accessible text in document
156
+ * order. The plan splices shown feedback into the body and leaves no marker behind, so this is
157
+ * the one place the shown feedback survives as data — the item body announces it while the
158
+ * candidate can still hear it (WCAG 4.1.3 Status Messages).
159
+ */
160
+ readonly shownFeedback: ShownFeedback;
97
161
  }
98
162
  export declare function createItemPresentation({ source, responses, disabled, role, outcomeValues, heuristicsConfig, itemBodyScopeSelector, renderItemBodyRubrics, showFeedback, showSolution, onComponentError, }: CreateItemPresentationOptions): ItemPresentation;
99
163
  export declare function interactionKey(interaction: BaseInteractionData): string;
100
- export {};
@@ -3,10 +3,16 @@ import { parse } from 'node-html-parser';
3
3
  import { sanitizeHtml } from '../core/sanitizer.js';
4
4
  import { htmlToString, toTrustedHtml } from '../core/trustedTypes.js';
5
5
  import { getRoleCapabilities } from '../core/rolePolicy.js';
6
- import { processFeedbackInline } from '@pie-qti/qti-common';
7
- import { buildScopedStylesheetCss } from '../components/utils/stylesheetRender.js';
8
- import { buildEffectiveStimulusContent, injectStimulusContent } from '../components/utils/stimulusRender.js';
9
- import { createInlineRenderPlan, isInlineInteractionTagName, isInlineInteractionType, } from '../interactions/inline/render-plan.js';
6
+ import { escapeHtmlAttribute } from '../security/escapeHtml.js';
7
+ import { deepFreezeInPlace } from '../utils/cloneFreeze.js';
8
+ import { cleanFeedbackText, processFeedbackInline } from '@pie-qti/qti-common';
9
+ import { extractShownFeedback } from './feedbackAnnouncement.js';
10
+ import { buildScopedStylesheetCss } from './stylesheetRender.js';
11
+ import { buildEffectiveStimulusContent, injectStimulusContent } from './stimulusRender.js';
12
+ import { isInlineInteractionType } from '../interactions/inline/render-plan.js';
13
+ import { textEntryStringIdentifier } from '../interactions/text-entry/response.js';
14
+ import { hasInteractionSlot, placeInteractionSlots } from './interactionSlots.js';
15
+ export { INTERACTION_SLOT_ATTRIBUTE } from './interactionSlots.js';
10
16
  export function createItemPresentation({ source, responses = {}, disabled = false, role = 'candidate', outcomeValues = {}, heuristicsConfig, itemBodyScopeSelector = '[data-qti-item-body-scope]', renderItemBodyRubrics = true, showFeedback = true, showSolution = false, onComponentError, }) {
11
17
  const baseCapabilities = getRoleCapabilities(role);
12
18
  const roleCapabilities = showSolution
@@ -14,7 +20,7 @@ export function createItemPresentation({ source, responses = {}, disabled = fals
14
20
  : baseCapabilities;
15
21
  const effectiveDisabled = disabled || roleCapabilities.isReadOnly;
16
22
  const correctResponses = roleCapabilities.canViewCorrectResponses ? source.correctResponses : {};
17
- const { html, scopedCss } = buildItemBodyPresentation({
23
+ const { html, scopedCss, shownFeedback } = buildItemBodyPresentation({
18
24
  source,
19
25
  role,
20
26
  outcomeValues,
@@ -23,69 +29,36 @@ export function createItemPresentation({ source, responses = {}, disabled = fals
23
29
  renderItemBodyRubrics,
24
30
  showFeedback,
25
31
  });
26
- const inlineFlow = createInlineRenderPlan(html, source.interactions).map((segment) => {
27
- if (segment.type === 'html') {
28
- // Inline planning parses and reserializes the composed body, so sanitation
29
- // belongs after that final string transform and immediately before TT.
30
- const sanitized = sanitizeHtml(segment.content, { security: source.security });
31
- return {
32
- kind: 'html',
33
- html: finalizeItemBodyHtml(sanitized, source.security),
34
- };
35
- }
36
- if (segment.type === 'textEntry') {
37
- return {
38
- kind: 'interaction',
39
- mount: {
40
- placement: 'inline',
41
- renderer: 'text-entry',
42
- interaction: segment.interaction,
43
- },
44
- };
45
- }
46
- return {
47
- kind: 'interaction',
48
- mount: {
49
- placement: 'inline',
50
- renderer: 'inline-choice',
51
- interaction: segment.interaction,
52
- },
53
- };
54
- });
55
- const blockFlow = createBlockInteractionMounts({
32
+ const placed = placeInteractionSlots(html, source.interactions, (interaction) => isInlineInteractionType(interaction.type) ? 'inline' : 'block');
33
+ // Slot placement is the last string transform of the body, so sanitation runs once over the
34
+ // composed body, immediately before Trusted Types finalization.
35
+ const sanitized = sanitizeHtml(placed.html, { security: source.security });
36
+ const slots = new Map([...placed.slots].filter(([, slot]) => hasInteractionSlot(sanitized, slot)));
37
+ const { mounts, failedInteractions } = createInteractionMounts({
56
38
  interactions: source.interactions,
39
+ slots,
57
40
  source,
58
41
  responses,
59
42
  correctResponses,
60
43
  roleCapabilities,
61
44
  effectiveDisabled,
62
45
  onComponentError,
63
- }).map((mount) => ({
64
- kind: 'interaction',
65
- mount,
66
- }));
67
- return freezePresentation({
46
+ });
47
+ return deepFreezeInPlace({
68
48
  capabilities: roleCapabilities,
69
49
  disabled: effectiveDisabled,
70
50
  ...(source.contentLanguage ? { contentLanguage: source.contentLanguage } : {}),
71
51
  correctResponses,
72
52
  directRubrics: source.directRubrics ?? [],
73
- flow: [...inlineFlow, ...blockFlow],
53
+ flow: [
54
+ { kind: 'html', html: finalizeItemBodyHtml(sanitized, source.security) },
55
+ ...mounts.map((mount) => ({ kind: 'interaction', mount })),
56
+ ],
57
+ failedInteractions,
74
58
  scopedCss,
59
+ shownFeedback,
75
60
  });
76
61
  }
77
- function freezePresentation(value) {
78
- if (!value || typeof value !== 'object' || Object.isFrozen(value))
79
- return value;
80
- const prototype = Object.getPrototypeOf(value);
81
- if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
82
- return value;
83
- Object.freeze(value);
84
- for (const child of Object.values(value)) {
85
- freezePresentation(child);
86
- }
87
- return value;
88
- }
89
62
  function buildItemBodyPresentation({ source, role, outcomeValues, heuristicsConfig, itemBodyScopeSelector, renderItemBodyRubrics, showFeedback, }) {
90
63
  let html = htmlToString(source.itemBodyHtml);
91
64
  const scopedCss = buildScopedStylesheetCss(source.deliveryContext, itemBodyScopeSelector);
@@ -93,13 +66,20 @@ function buildItemBodyPresentation({ source, role, outcomeValues, heuristicsConf
93
66
  html = injectStimulusContent(html, effectiveStimulusContent);
94
67
  html = renderRubricBlocksForRole(html, role, { renderRubrics: renderItemBodyRubrics });
95
68
  const heuristics = normalizeHeuristicsConfig(heuristicsConfig);
69
+ // While every feedback element is still in the HTML, read which of them the outcomes show and
70
+ // what they say, with the same text heuristics, so the body can announce it (WCAG 4.1.3) once
71
+ // this presentation renders it.
72
+ const shownFeedback = extractShownFeedback(html, outcomeValues, {
73
+ hideAll: !showFeedback,
74
+ transform: heuristics.feedbackTextFormatting ? (content) => cleanFeedbackText(content) : undefined,
75
+ });
96
76
  html = processFeedbackInline(html, {
97
77
  outcomeValues,
98
78
  applyHeuristics: heuristics.feedbackTextFormatting,
99
79
  wrapWithSpan: false,
100
80
  hideAll: !showFeedback,
101
81
  });
102
- return { html: hideBlockInteractionMarkup(html), scopedCss };
82
+ return { html, scopedCss, shownFeedback };
103
83
  }
104
84
  function finalizeItemBodyHtml(html, security) {
105
85
  return toTrustedHtml(html, security?.trustedTypesPolicyName);
@@ -165,28 +145,57 @@ function serializeHtmlChildren(element) {
165
145
  .map((child) => child.toString())
166
146
  .join('');
167
147
  }
168
- function escapeHtmlAttribute(value) {
169
- return value
170
- .replace(/&/g, '&amp;')
171
- .replace(/"/g, '&quot;')
172
- .replace(/</g, '&lt;')
173
- .replace(/>/g, '&gt;');
174
- }
175
- function hideBlockInteractionMarkup(html) {
176
- // positionObjectStage is hidden as a unit: it owns the background object and wraps its
177
- // interactions, all of which the component renders. Matching only the interaction inside it
178
- // would leave the stage's background image visible in the item body as well.
179
- return html.replace(/<(\w+Interaction|qti-[\w-]+-interaction|positionObjectStage|qti-position-object-stage)(\s[^>]*)?>[\s\S]*?<\/\1>/gi, (match, tagName) => {
180
- const lower = tagName.toLowerCase();
181
- if (isInlineInteractionTagName(lower))
182
- return match;
183
- return `<span class="qti-hidden-interaction">${match}</span>`;
184
- });
185
- }
186
- function createBlockInteractionMounts({ interactions, source, responses, correctResponses, roleCapabilities, effectiveDisabled, onComponentError, }) {
187
- return interactions
188
- .filter((interaction) => !isInlineInteractionType(interaction.type))
189
- .map((interaction) => {
148
+ /**
149
+ * One mount per interaction that resolves, in document order: slotted interactions in slot
150
+ * order, then any whose element is not in the body, in extraction order. An interaction whose
151
+ * component the registry cannot resolve gets no mount — the host hears the failure once
152
+ * through `onComponentError` — and is returned in `failedInteractions` with the slot it
153
+ * owned, so the presenter can stand the render-failed placeholder where it was authored.
154
+ */
155
+ function createInteractionMounts({ interactions, slots, source, responses, correctResponses, roleCapabilities, effectiveDisabled, onComponentError, }) {
156
+ const slotRank = (index) => {
157
+ const slot = slots.get(index);
158
+ return slot === undefined ? Number.POSITIVE_INFINITY : Number(slot);
159
+ };
160
+ const order = interactions.map((_, index) => index).sort((a, b) => slotRank(a) - slotRank(b));
161
+ const inlineCount = interactions.filter((interaction) => isInlineInteractionType(interaction.type)).length;
162
+ const usedKeys = new Map();
163
+ const uniqueKey = (interaction) => {
164
+ const key = interactionKey(interaction);
165
+ const seen = usedKeys.get(key) ?? 0;
166
+ usedKeys.set(key, seen + 1);
167
+ // Keyed rendering needs distinct keys even for (invalid) duplicate interactions.
168
+ return seen === 0 ? key : `${key}#${seen}`;
169
+ };
170
+ const mounts = [];
171
+ const failedInteractions = [];
172
+ let inlineIndex = 0;
173
+ for (const index of order) {
174
+ const interaction = interactions[index];
175
+ const slot = slots.get(index) ?? null;
176
+ if (isInlineInteractionType(interaction.type)) {
177
+ inlineIndex += 1;
178
+ const inline = {
179
+ placement: 'inline',
180
+ key: uniqueKey(interaction),
181
+ slot,
182
+ position: { index: inlineIndex, count: inlineCount },
183
+ };
184
+ if (interaction.type === 'textEntryInteraction') {
185
+ const textEntry = interaction;
186
+ const stringIdentifier = textEntryStringIdentifier(textEntry);
187
+ mounts.push({
188
+ ...inline,
189
+ renderer: 'text-entry',
190
+ interaction: textEntry,
191
+ ...(stringIdentifier ? { stringResponse: responses[stringIdentifier] ?? null } : {}),
192
+ });
193
+ }
194
+ else {
195
+ mounts.push({ ...inline, renderer: 'inline-choice', interaction: interaction });
196
+ }
197
+ continue;
198
+ }
190
199
  try {
191
200
  const stringIdentifier = 'stringIdentifier' in interaction && typeof interaction.stringIdentifier === 'string'
192
201
  ? interaction.stringIdentifier
@@ -196,7 +205,8 @@ function createBlockInteractionMounts({ interactions, source, responses, correct
196
205
  renderer: 'web-component',
197
206
  interaction,
198
207
  tagName: source.componentRegistry.getTagName(interaction),
199
- key: interactionKey(interaction),
208
+ key: uniqueKey(interaction),
209
+ slot,
200
210
  response: responses[interaction.responseId] ?? null,
201
211
  ...(stringIdentifier
202
212
  ? { stringResponse: responses[stringIdentifier] ?? null }
@@ -211,14 +221,16 @@ function createBlockInteractionMounts({ interactions, source, responses, correct
211
221
  disabled: effectiveDisabled,
212
222
  componentRole: roleCapabilities.canViewCorrectResponses ? 'scorer' : undefined,
213
223
  };
214
- return block;
224
+ mounts.push(block);
215
225
  }
216
226
  catch (error) {
227
+ // No component renders the type: the interaction has no mount, the body keeps
228
+ // rendering around it, and the slot it owned stays reserved for the placeholder.
217
229
  onComponentError?.(interaction, error);
218
- return null;
230
+ failedInteractions.push({ key: uniqueKey(interaction), slot, interaction });
219
231
  }
220
- })
221
- .filter((item) => item !== null);
232
+ }
233
+ return { mounts, failedInteractions };
222
234
  }
223
235
  export function interactionKey(interaction) {
224
236
  const anyInteraction = interaction;