@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
@@ -17,9 +17,9 @@ const TEXT_APPEARANCE_PROPERTIES = [
17
17
  ['wordSpacing', 'word-spacing', 'em'],
18
18
  ];
19
19
  /**
20
- * Apply a PNP profile to the player root element as attributes and custom properties,
21
- * which the default runtime stylesheet renders: color scheme, magnification, inverted
22
- * polarity, single-column layout and text appearance.
20
+ * Apply a PNP profile to the player root element as attributes and custom properties. The
21
+ * default runtime stylesheet renders color scheme, inverted polarity, single-column layout and
22
+ * text appearance; magnification is set for host stylesheets only.
23
23
  */
24
24
  export function applyPnpToRoot(rootEl, pnp) {
25
25
  const display = pnp?.display;
@@ -40,20 +40,31 @@ export function applyPnpToRoot(rootEl, pnp) {
40
40
  setProperty(rootEl, '--qti-magnification', undefined);
41
41
  }
42
42
  const polarity = display?.invertPolarity;
43
- if (polarity)
44
- rootEl.setAttribute(INVERT_POLARITY_ATTR, polarity.foreground || polarity.background ? 'colors' : 'invert');
45
- else
43
+ const polarityForeground = validColor(polarity?.foreground, 'display.invertPolarity.foreground');
44
+ const polarityBackground = validColor(polarity?.background, 'display.invertPolarity.background');
45
+ if (polarity) {
46
+ rootEl.setAttribute(INVERT_POLARITY_ATTR, polarityForeground || polarityBackground ? 'colors' : 'invert');
47
+ }
48
+ else {
46
49
  rootEl.removeAttribute(INVERT_POLARITY_ATTR);
47
- setProperty(rootEl, '--qti-invert-foreground', polarity?.foreground);
48
- setProperty(rootEl, '--qti-invert-background', polarity?.background);
50
+ }
51
+ setProperty(rootEl, '--qti-invert-foreground', polarityForeground);
52
+ setProperty(rootEl, '--qti-invert-background', polarityBackground);
49
53
  if (display?.singleColumn)
50
54
  rootEl.setAttribute(LAYOUT_ATTR, 'single-column');
51
55
  else
52
56
  rootEl.removeAttribute(LAYOUT_ATTR);
53
57
  const appearance = display?.textAppearance;
58
+ const appearanceValue = (key) => {
59
+ const value = appearance?.[key];
60
+ if (COLOR_APPEARANCE_FIELDS.has(key)) {
61
+ return validColor(typeof value === 'string' ? value : undefined, `display.textAppearance.${key}`);
62
+ }
63
+ return value;
64
+ };
54
65
  const tokens = [];
55
66
  for (const [key, token, unit] of TEXT_APPEARANCE_PROPERTIES) {
56
- const value = appearance?.[key];
67
+ const value = appearanceValue(key);
57
68
  const css = value === undefined || value === '' ? undefined : `${value}${unit}`;
58
69
  if (css !== undefined)
59
70
  tokens.push(token);
@@ -64,10 +75,74 @@ export function applyPnpToRoot(rootEl, pnp) {
64
75
  else
65
76
  rootEl.removeAttribute(TEXT_APPEARANCE_ATTR);
66
77
  }
78
+ /**
79
+ * Marks a PNP surface: an element that applies the candidate's display needs to
80
+ * everything it renders, its item players included (a section player's layout).
81
+ */
82
+ export const PNP_SURFACE_ATTRIBUTE = 'data-qti-pnp-surface';
83
+ /**
84
+ * Apply a profile's display needs to a surface that renders more than one item's
85
+ * content — passages, rubrics, tool bars and items. Everything inside takes them
86
+ * from the surface: an item body inside one applies none of its own, so the surface
87
+ * decides one colour scheme, text appearance and polarity for all of it (and an
88
+ * inverting filter is never applied twice). Nothing outside the surface changes.
89
+ */
90
+ export function applyPnpToSurface(surfaceEl, pnp) {
91
+ surfaceEl.setAttribute(PNP_SURFACE_ATTRIBUTE, '');
92
+ applyPnpToRoot(surfaceEl, pnp);
93
+ }
94
+ /** Stop being a PNP surface: its display attributes go, and items inside apply their own again. */
95
+ export function clearPnpSurface(surfaceEl) {
96
+ surfaceEl.removeAttribute(PNP_SURFACE_ATTRIBUTE);
97
+ applyPnpToRoot(surfaceEl, undefined);
98
+ }
99
+ /** Whether an ancestor of `el`, looking through shadow roots, is a PNP surface. */
100
+ export function isWithinPnpSurface(el) {
101
+ let node = el.parentElement ?? shadowHostOf(el);
102
+ while (node) {
103
+ if (node.closest(`[${PNP_SURFACE_ATTRIBUTE}]`))
104
+ return true;
105
+ node = shadowHostOf(node);
106
+ }
107
+ return false;
108
+ }
109
+ /** The host of the shadow root `node` sits in, if any. */
110
+ function shadowHostOf(node) {
111
+ const root = node.getRootNode?.();
112
+ return root?.host ?? null;
113
+ }
67
114
  function setProperty(rootEl, property, value) {
68
115
  if (value === undefined)
69
116
  rootEl.style?.removeProperty?.(property);
70
117
  else
71
118
  rootEl.style?.setProperty?.(property, value);
72
119
  }
120
+ /** The text-appearance fields whose value is a CSS colour. */
121
+ const COLOR_APPEARANCE_FIELDS = new Set(['fontColor', 'backgroundColor']);
122
+ /**
123
+ * A colour from the profile, or `undefined` when CSS cannot parse it. A host
124
+ * delivers the JSON profile directly, so a typo reaches here unfiltered — and
125
+ * an invalid colour wipes whatever the custom property styles (focus outlines,
126
+ * control borders). `CSS.supports('color', …)` filters it; without a CSS engine
127
+ * (SSR, tests) there is nothing to ask and every value applies.
128
+ */
129
+ function validColor(value, field) {
130
+ if (value === undefined || value === '')
131
+ return undefined;
132
+ if (colorIsSupported(value))
133
+ return value;
134
+ console.warn(`[@pie-qti/item-player] PNP ${field} "${value}" is not a colour CSS understands and is ignored.`);
135
+ return undefined;
136
+ }
137
+ /** `CSS.supports('color', value)` where the environment exposes it; otherwise true. */
138
+ function colorIsSupported(value) {
139
+ if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function')
140
+ return true;
141
+ try {
142
+ return CSS.supports('color', value);
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ }
73
148
  //# sourceMappingURL=applyPnp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"applyPnp.js","sourceRoot":"","sources":["../../src/pnp/applyPnp.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AACpD,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AACxD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD;;;GAGG;AACH,MAAM,0BAA0B,GAA6D;IAC5F,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC;IAC/B,CAAC,YAAY,EAA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AAE,QAAgB,EAAE,KAAyB;IACpF,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,QAAQ,CAAC,CAAC;;QAC7D,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { PnpProfile, PnpTextAppearance } from './types.js';\n\nconst ATTR = 'data-qti-colorscheme';\nconst MAGNIFICATION_ATTR = 'data-qti-magnification';\nconst INVERT_POLARITY_ATTR = 'data-qti-invert-polarity';\nconst LAYOUT_ATTR = 'data-qti-layout';\nconst TEXT_APPEARANCE_ATTR = 'data-qti-text-appearance';\n\n/**\n * Each text-appearance field, its token in `data-qti-text-appearance`, the custom property\n * it sets (`--qti-<token>`) and its CSS unit.\n */\nconst TEXT_APPEARANCE_PROPERTIES: ReadonlyArray<[keyof PnpTextAppearance, string, string]> = [\n\t['fontSize', 'font-size', 'pt'],\n\t['fontFamily', 'font-family', ''],\n\t['fontColor', 'font-color', ''],\n\t['backgroundColor', 'background-color', ''],\n\t['lineHeight', 'line-height', ''],\n\t['letterSpacing', 'letter-spacing', 'em'],\n\t['wordSpacing', 'word-spacing', 'em'],\n];\n\n/**\n * Apply a PNP profile to the player root element as attributes and custom properties,\n * which the default runtime stylesheet renders: color scheme, magnification, inverted\n * polarity, single-column layout and text appearance.\n */\nexport function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {\n\tconst display = pnp?.display;\n\tconst scheme = display?.colorScheme;\n\n\tif (!scheme || scheme === 'default') {\n\t\trootEl.removeAttribute(ATTR);\n\t} else {\n\t\trootEl.setAttribute(ATTR, scheme);\n\t}\n\n\tconst magnification = display?.magnification;\n\tif (magnification !== undefined && Number.isFinite(magnification) && magnification > 0) {\n\t\trootEl.setAttribute(MAGNIFICATION_ATTR, String(magnification));\n\t\tsetProperty(rootEl, '--qti-magnification', String(magnification));\n\t} else {\n\t\trootEl.removeAttribute(MAGNIFICATION_ATTR);\n\t\tsetProperty(rootEl, '--qti-magnification', undefined);\n\t}\n\n\tconst polarity = display?.invertPolarity;\n\tif (polarity) rootEl.setAttribute(INVERT_POLARITY_ATTR, polarity.foreground || polarity.background ? 'colors' : 'invert');\n\telse rootEl.removeAttribute(INVERT_POLARITY_ATTR);\n\tsetProperty(rootEl, '--qti-invert-foreground', polarity?.foreground);\n\tsetProperty(rootEl, '--qti-invert-background', polarity?.background);\n\n\tif (display?.singleColumn) rootEl.setAttribute(LAYOUT_ATTR, 'single-column');\n\telse rootEl.removeAttribute(LAYOUT_ATTR);\n\n\tconst appearance = display?.textAppearance;\n\tconst tokens: string[] = [];\n\tfor (const [key, token, unit] of TEXT_APPEARANCE_PROPERTIES) {\n\t\tconst value = appearance?.[key];\n\t\tconst css = value === undefined || value === '' ? undefined : `${value}${unit}`;\n\t\tif (css !== undefined) tokens.push(token);\n\t\tsetProperty(rootEl, `--qti-${token}`, css);\n\t}\n\tif (tokens.length > 0) rootEl.setAttribute(TEXT_APPEARANCE_ATTR, tokens.join(' '));\n\telse rootEl.removeAttribute(TEXT_APPEARANCE_ATTR);\n}\n\nfunction setProperty(rootEl: HTMLElement, property: string, value: string | undefined): void {\n\tif (value === undefined) rootEl.style?.removeProperty?.(property);\n\telse rootEl.style?.setProperty?.(property, value);\n}\n"]}
1
+ {"version":3,"file":"applyPnp.js","sourceRoot":"","sources":["../../src/pnp/applyPnp.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AACpD,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AACxD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD;;;GAGG;AACH,MAAM,0BAA0B,GAA6D;IAC5F,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC;IAC/B,CAAC,YAAY,EAAE,aA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-colorscheme';\nconst MAGNIFICATION_ATTR = 'data-qti-magnification';\nconst INVERT_POLARITY_ATTR = 'data-qti-invert-polarity';\nconst LAYOUT_ATTR = 'data-qti-layout';\nconst TEXT_APPEARANCE_ATTR = 'data-qti-text-appearance';\n\n/**\n * Each text-appearance field, its token in `data-qti-text-appearance`, the custom property\n * it sets (`--qti-<token>`) and its CSS unit.\n */\nconst TEXT_APPEARANCE_PROPERTIES: ReadonlyArray<[keyof PnpTextAppearance, string, string]> = [\n\t['fontSize', 'font-size', 'pt'],\n\t['fontFamily', 'font-family', ''],\n\t['fontColor', 'font-color', ''],\n\t['backgroundColor', 'background-color', ''],\n\t['lineHeight', 'line-height', ''],\n\t['letterSpacing', 'letter-spacing', 'em'],\n\t['wordSpacing', 'word-spacing', 'em'],\n];\n\n/**\n * Apply a PNP profile to the player root element as attributes and custom properties. The\n * default runtime stylesheet renders color scheme, inverted polarity, single-column layout and\n * text appearance; magnification is set for host stylesheets only.\n */\nexport function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {\n\tconst display = pnp?.display;\n\tconst scheme = display?.colorScheme;\n\n\tif (!scheme || scheme === 'default') {\n\t\trootEl.removeAttribute(ATTR);\n\t} else {\n\t\trootEl.setAttribute(ATTR, scheme);\n\t}\n\n\tconst magnification = display?.magnification;\n\tif (magnification !== undefined && Number.isFinite(magnification) && magnification > 0) {\n\t\trootEl.setAttribute(MAGNIFICATION_ATTR, String(magnification));\n\t\tsetProperty(rootEl, '--qti-magnification', String(magnification));\n\t} else {\n\t\trootEl.removeAttribute(MAGNIFICATION_ATTR);\n\t\tsetProperty(rootEl, '--qti-magnification', undefined);\n\t}\n\n\tconst polarity = display?.invertPolarity;\n\tconst polarityForeground = validColor(polarity?.foreground, 'display.invertPolarity.foreground');\n\tconst polarityBackground = validColor(polarity?.background, 'display.invertPolarity.background');\n\tif (polarity) {\n\t\trootEl.setAttribute(INVERT_POLARITY_ATTR, polarityForeground || polarityBackground ? 'colors' : 'invert');\n\t} else {\n\t\trootEl.removeAttribute(INVERT_POLARITY_ATTR);\n\t}\n\tsetProperty(rootEl, '--qti-invert-foreground', polarityForeground);\n\tsetProperty(rootEl, '--qti-invert-background', polarityBackground);\n\n\tif (display?.singleColumn) rootEl.setAttribute(LAYOUT_ATTR, 'single-column');\n\telse rootEl.removeAttribute(LAYOUT_ATTR);\n\n\tconst appearance = display?.textAppearance;\n\tconst appearanceValue = (key: keyof PnpTextAppearance): string | number | undefined => {\n\t\tconst value = appearance?.[key];\n\t\tif (COLOR_APPEARANCE_FIELDS.has(key)) {\n\t\t\treturn validColor(typeof value === 'string' ? value : undefined, `display.textAppearance.${key}`);\n\t\t}\n\t\treturn value;\n\t};\n\tconst tokens: string[] = [];\n\tfor (const [key, token, unit] of TEXT_APPEARANCE_PROPERTIES) {\n\t\tconst value = appearanceValue(key);\n\t\tconst css = value === undefined || value === '' ? undefined : `${value}${unit}`;\n\t\tif (css !== undefined) tokens.push(token);\n\t\tsetProperty(rootEl, `--qti-${token}`, css);\n\t}\n\tif (tokens.length > 0) rootEl.setAttribute(TEXT_APPEARANCE_ATTR, tokens.join(' '));\n\telse rootEl.removeAttribute(TEXT_APPEARANCE_ATTR);\n}\n\n/**\n * Marks a PNP surface: an element that applies the candidate's display needs to\n * everything it renders, its item players included (a section player's layout).\n */\nexport const PNP_SURFACE_ATTRIBUTE = 'data-qti-pnp-surface';\n\n/**\n * Apply a profile's display needs to a surface that renders more than one item's\n * content — passages, rubrics, tool bars and items. Everything inside takes them\n * from the surface: an item body inside one applies none of its own, so the surface\n * decides one colour scheme, text appearance and polarity for all of it (and an\n * inverting filter is never applied twice). Nothing outside the surface changes.\n */\nexport function applyPnpToSurface(surfaceEl: HTMLElement, pnp: PnpProfile | undefined): void {\n\tsurfaceEl.setAttribute(PNP_SURFACE_ATTRIBUTE, '');\n\tapplyPnpToRoot(surfaceEl, pnp);\n}\n\n/** Stop being a PNP surface: its display attributes go, and items inside apply their own again. */\nexport function clearPnpSurface(surfaceEl: HTMLElement): void {\n\tsurfaceEl.removeAttribute(PNP_SURFACE_ATTRIBUTE);\n\tapplyPnpToRoot(surfaceEl, undefined);\n}\n\n/** Whether an ancestor of `el`, looking through shadow roots, is a PNP surface. */\nexport function isWithinPnpSurface(el: Element): boolean {\n\tlet node: Element | null | undefined = el.parentElement ?? shadowHostOf(el);\n\twhile (node) {\n\t\tif (node.closest(`[${PNP_SURFACE_ATTRIBUTE}]`)) return true;\n\t\tnode = shadowHostOf(node);\n\t}\n\treturn false;\n}\n\n/** The host of the shadow root `node` sits in, if any. */\nfunction shadowHostOf(node: Node): Element | null {\n\tconst root = node.getRootNode?.() as { host?: Element } | undefined;\n\treturn root?.host ?? null;\n}\n\nfunction setProperty(rootEl: HTMLElement, property: string, value: string | undefined): void {\n\tif (value === undefined) rootEl.style?.removeProperty?.(property);\n\telse rootEl.style?.setProperty?.(property, value);\n}\n\n/** The text-appearance fields whose value is a CSS colour. */\nconst COLOR_APPEARANCE_FIELDS = new Set<string>(['fontColor', 'backgroundColor']);\n\n/**\n * A colour from the profile, or `undefined` when CSS cannot parse it. A host\n * delivers the JSON profile directly, so a typo reaches here unfiltered — and\n * an invalid colour wipes whatever the custom property styles (focus outlines,\n * control borders). `CSS.supports('color', …)` filters it; without a CSS engine\n * (SSR, tests) there is nothing to ask and every value applies.\n */\nfunction validColor(value: string | undefined, field: string): string | undefined {\n\tif (value === undefined || value === '') return undefined;\n\tif (colorIsSupported(value)) return value;\n\tconsole.warn(`[@pie-qti/item-player] PNP ${field} \"${value}\" is not a colour CSS understands and is ignored.`);\n\treturn undefined;\n}\n\n/** `CSS.supports('color', value)` where the environment exposes it; otherwise true. */\nfunction colorIsSupported(value: string): boolean {\n\tif (typeof CSS === 'undefined' || typeof CSS.supports !== 'function') return true;\n\ttry {\n\t\treturn CSS.supports('color', value);\n\t} catch {\n\t\treturn false;\n\t}\n}\n"]}
@@ -186,6 +186,8 @@ export function pnpProfileFromAfa(record) {
186
186
  const cognitive = {};
187
187
  if (granted('answer-masking'))
188
188
  cognitive.answerMasking = true;
189
+ if (granted('spell-checker-on-screen'))
190
+ cognitive.spellChecker = true;
189
191
  const tools = toolSupportsOf(record, granted, prohibited);
190
192
  const profile = {};
191
193
  if (Object.keys(display).length > 0)
@@ -1 +1 @@
1
- {"version":3,"file":"parsePnpXml.js","sourceRoot":"","sources":["../../src/pnp/parsePnpXml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAItD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,wDAAwD,CAAC;AAmB1F,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,gCAAgC,EAAE,wBAAwB,EAAE,cAAc,CAAC,CAAC,CAAC;AAE3G;;;;GAIG;AACH,MAAM,wBAAwB,GAAG;IAChC,uBAAuB;IACvB,mBAAmB;IACnB,SAAS;IACT,eAAe;IACf,qBAAqB;IACrB,qBAAqB;IACrB,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,8BAA8B;IAC9B,QAAQ;IACR,SAAS;IACT,YAAY;CACH,CAAC;AAEX;;;;GAIG;AACH,MAAM,yBAAyB,GAAiF;IAC/G,OAAO,EAAE,aAAa;IACtB,eAAe,EAAE,mBAAmB;CACpC,CAAC;AAEF,iEAAiE;AACjE,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAIpE;;;;GAIG;AACH,MAAM,YAAY,GAA0C;IAC3D,OAAO,EAAE,SAAS;IAClB,iBAAiB,EAAE,gBAAgB;IACnC,eAAe,EAAE,YAAY;IAC7B,uBAAuB,EAAE,YAAY;IACrC,YAAY,EAAE,WAAW;IACzB,YAAY,EAAE,WAAW;IACzB,aAAa,EAAE,YAAY;IAC3B,aAAa,EAAE,YAAY;IAC3B,kBAAkB,EAAE,YAAY;IAChC,kBAAkB,EAAE,YAAY;IAChC,YAAY,EAAE,WAAW;IACzB,YAAY,EAAE,WAAW;IACzB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AAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxG,OAAO,qCAAqC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,uCAAuC,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,SAAS,CAAC;IAClF,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { parse as parseHtml } from 'node-html-parser';\nimport type { HTMLElement as NhpElement } from 'node-html-parser';\nimport type { CatalogSupportPreference, PnpProfile, PnpTextAppearance, PnpToolSupports } from './types.js';\n\n/** QTI 3's profile of Access for All Personal Needs and Preferences 3.0. */\nexport const AFA_PNP_NAMESPACE = 'http://www.imsglobal.org/xsd/qtiv3p0/imsafa3p0pnp_v1p0';\n\n/**\n * An AfA PNP 3.0 profile as JSON keyed by the spec's kebab-case terms, the shape\n * pie-players' `createPersonalNeedsProfileFromAfa` takes.\n *\n * An empty element is `{}`, an element holding only text is that text (a number or\n * boolean when it reads as one), `xml:lang` is `language`, a repeated element is an\n * array, and a feature set is the list of feature names it holds. Elements of another\n * namespace, AfA's extension mechanism, sit under `extensions` by local name.\n */\nexport interface AfaPnpRecord {\n\t'activate-at-initialization-set'?: string[];\n\t'activate-as-option-set'?: string[];\n\t'prohibit-set'?: string[];\n\textensions?: Record<string, unknown>;\n\t[feature: string]: unknown;\n}\n\nconst FEATURE_SETS = new Set(['activate-at-initialization-set', 'activate-as-option-set', 'prohibit-set']);\n\n/**\n * QTI 3's predefined catalog card supports, less `glossary-on-screen` and\n * `keyword-translation`, which have popups of their own. A granted one enables the\n * catalog support of that name.\n */\nconst CATALOG_SUPPORT_FEATURES = [\n\t'additional-directions',\n\t'audio-description',\n\t'braille',\n\t'high-contrast',\n\t'keyboard-directions',\n\t'linguistic-guidance',\n\t'long-description',\n\t'sign-language',\n\t'simplified-graphics',\n\t'simplified-language-portions',\n\t'spoken',\n\t'tactile',\n\t'transcript',\n] as const;\n\n/**\n * AfA features the player routes itself, recorded under the platform preference key\n * (`CatalogSupportPreferences` flag) rather than the AfA feature name, so the granted\n * support reaches the platform routing instead of falling through as host-defined.\n */\nconst PLATFORM_CATALOG_FEATURES: Readonly<Partial<Record<(typeof CATALOG_SUPPORT_FEATURES)[number], string>>> = {\n\tbraille: 'brailleText',\n\t'sign-language': 'signingDefinition',\n};\n\n/** The extension SBAC requests its illustrated glossary with. */\nconst ILLUSTRATED_GLOSSARY_EXTENSION = 'sbac-glossary-illustration';\n\ntype ColorScheme = NonNullable<NonNullable<PnpProfile['display']>['colorScheme']>;\n\n/**\n * AfA `color-theme` terms onto the player's scheme names. The spec leaves a theme's\n * exact colors to the delivery system, so `high-contrast` takes black on white and\n * its reverse white on black.\n */\nconst COLOR_THEMES: Readonly<Record<string, ColorScheme>> = {\n\tdefault: 'default',\n\t'default-reverse': 'defaultreverse',\n\t'high-contrast': 'blackwhite',\n\t'high-contrast-reverse': 'whiteblack',\n\t'black-rose': 'blackrose',\n\t'rose-black': 'roseblack',\n\t'yellow-blue': 'yellowblue',\n\t'blue-yellow': 'blueyellow',\n\t'medgray-darkgray': 'mgraydgray',\n\t'darkgray-medgray': 'dgraymgray',\n\t'black-cyan': 'blackcyan',\n\t'cyan-black': 'cyanblack',\n\t'black-cream': 'blackcream',\n\t'cream-black': 'creamblack',\n};\n\n/** AfA `generic-font-face` terms onto CSS generic families. */\nconst GENERIC_FONT_FACES: Readonly<Record<string, string>> = {\n\tserif: 'serif',\n\t'sans serif': 'sans-serif',\n\tmonospaced: 'monospace',\n\tcursive: 'cursive',\n\tfantasy: 'fantasy',\n};\n\n/** AfA's speech rate when the profile gives none, in words per minute. */\nconst AFA_DEFAULT_SPEECH_RATE = 180;\n\n/**\n * AfA tool features onto pie-players support ids, the ids its\n * `createPersonalNeedsProfileFromAfa` gives them. `spoken` resolves by reading type.\n */\nconst TOOL_FEATURES: Readonly<Record<string, string>> = {\n\t'calculator-on-screen': 'calculator',\n\t'line-reader': 'lineReader',\n\t'dictionary-on-screen': 'dictionary',\n};\n\n/**\n * Parse an AfA PNP 3.0 document into its record: an `access-for-all-pnp` element, or\n * the first one inside an `access-for-all-pnp-record`. A bulk records file holds one\n * profile per candidate, so pass the candidate's record. Returns `null` when the input\n * holds no profile.\n */\nexport function parseAfaPnpXml(xml: string | Element): AfaPnpRecord | null {\n\tconst source = typeof xml === 'string' ? xml : ((xml as Element).outerHTML ?? '');\n\tconst trimmed = source.replace(/<\\?xml[^>]*\\?>/g, '').trim();\n\tif (!trimmed) return null;\n\n\tconst doc = parseHtml(`<root>${trimmed}</root>`, { lowerCaseTagName: false });\n\tconst root = findProfile(doc);\n\tif (!root) return null;\n\n\tconst afaPrefixes = collectAfaPrefixes(root);\n\tconst record: AfaPnpRecord = {};\n\tfor (const child of elementChildren(root)) {\n\t\tconst { prefix, local } = splitName(child.rawTagName);\n\t\tif (prefix && !afaPrefixes.has(prefix)) {\n\t\t\trecord.extensions ??= {};\n\t\t\taddValue(record.extensions, local, elementValue(child));\n\t\t} else if (FEATURE_SETS.has(local)) {\n\t\t\trecord[local] = elementChildren(child).map((feature) => splitName(feature.rawTagName).local);\n\t\t} else {\n\t\t\taddValue(record, local, elementValue(child));\n\t\t}\n\t}\n\treturn record;\n}\n\n/**\n * The part of an AfA record the item player renders. A feature counts when the record\n * names it or one of its activation sets lists it, unless `prohibit-set` lists it.\n * Features with no `PnpProfile` field stay in the record for the host: `ext:` color\n * themes, and the tool supports `tools` does not name.\n */\nexport function pnpProfileFromAfa(record: AfaPnpRecord): PnpProfile {\n\tconst prohibited = new Set(record['prohibit-set'] ?? []);\n\tconst listed = new Set([\n\t\t...(record['activate-at-initialization-set'] ?? []),\n\t\t...(record['activate-as-option-set'] ?? []),\n\t]);\n\tconst granted = (feature: string): boolean =>\n\t\t!prohibited.has(feature) && (isPresent(record[feature]) || listed.has(feature));\n\n\tconst display: NonNullable<PnpProfile['display']> = {};\n\tconst theme = granted('text-appearance')\n\t\t? field(record['text-appearance'], 'color-theme')\n\t\t: granted('color-theme')\n\t\t\t? record['color-theme']\n\t\t\t: undefined;\n\tif (typeof theme === 'string' && COLOR_THEMES[theme]) display.colorScheme = COLOR_THEMES[theme];\n\tif (granted('magnification')) {\n\t\tconst magnification = record.magnification;\n\t\tconst zoom =\n\t\t\tfiniteNumber(field(field(magnification, 'all-content'), 'zoom-amount')) ??\n\t\t\tfiniteNumber(field(field(magnification, 'text'), 'zoom-amount'));\n\t\tif (zoom !== undefined && zoom > 0) display.magnification = zoom;\n\t}\n\tif (granted('language-of-interface')) {\n\t\tconst interfaceLanguage = normalizeLanguageCode(field(record['language-of-interface'], 'language'));\n\t\tif (interfaceLanguage) display.interfaceLanguage = interfaceLanguage;\n\t}\n\tif (granted('invert-display-polarity')) {\n\t\tconst polarity = record['invert-display-polarity'];\n\t\tconst foreground = hexColor(field(polarity, 'foreground'));\n\t\tconst background = hexColor(field(polarity, 'background'));\n\t\tdisplay.invertPolarity = { ...(foreground ? { foreground } : {}), ...(background ? { background } : {}) };\n\t}\n\tif (granted('layout-single-column')) display.singleColumn = true;\n\tif (granted('text-appearance')) {\n\t\tconst textAppearance = textAppearanceOf(record['text-appearance']);\n\t\tif (textAppearance) display.textAppearance = textAppearance;\n\t}\n\n\tconst content: NonNullable<PnpProfile['content']> = {};\n\tif (granted('glossary-on-screen')) content.glossaryOnScreen = true;\n\tif (granted('keyword-translation')) {\n\t\tconst languageCode = normalizeLanguageCode(field(record['keyword-translation'], 'language'));\n\t\tif (languageCode) content.keywordTranslation = { active: true, languageCode };\n\t}\n\tif (\n\t\t!prohibited.has(ILLUSTRATED_GLOSSARY_EXTENSION) &&\n\t\tisPresent(record.extensions?.[ILLUSTRATED_GLOSSARY_EXTENSION])\n\t) {\n\t\tcontent.illustratedGlossary = true;\n\t}\n\tfor (const feature of CATALOG_SUPPORT_FEATURES) {\n\t\tif (!granted(feature)) continue;\n\t\tconst languageCode = normalizeLanguageCode(field(record[feature], 'language'));\n\t\tconst preference: CatalogSupportPreference = languageCode ? { active: true, languageCode } : true;\n\t\tcontent.catalogSupports ??= {};\n\t\tcontent.catalogSupports[PLATFORM_CATALOG_FEATURES[feature] ?? feature] = preference;\n\t}\n\tif (granted('additional-testing-time')) {\n\t\tconst testingTime = record['additional-testing-time'];\n\t\tconst multiplier = isPresent(field(testingTime, 'unlimited'))\n\t\t\t? Infinity\n\t\t\t: finiteNumber(field(testingTime, 'time-multiplier'));\n\t\tconst fixedMinutes = finiteNumber(field(testingTime, 'fixed-minutes'));\n\t\tif (multiplier !== undefined && multiplier > 0) content.extendedTime = { active: true, multiplier };\n\t\telse if (fixedMinutes !== undefined && fixedMinutes > 0) {\n\t\t\tcontent.extendedTime = { active: true, multiplier: 1, fixedMinutes };\n\t\t}\n\t}\n\n\tconst cognitive: NonNullable<PnpProfile['cognitive']> = {};\n\tif (granted('answer-masking')) cognitive.answerMasking = true;\n\n\tconst tools = toolSupportsOf(record, granted, prohibited);\n\n\tconst profile: PnpProfile = {};\n\tif (Object.keys(display).length > 0) profile.display = display;\n\tif (Object.keys(content).length > 0) profile.content = content;\n\tif (Object.keys(cognitive).length > 0) profile.cognitive = cognitive;\n\tif (tools) profile.tools = tools;\n\treturn profile;\n}\n\n/** The tool supports an AfA record grants or withdraws, as pie-players support ids. */\nfunction toolSupportsOf(\n\trecord: AfaPnpRecord,\n\tgranted: (feature: string) => boolean,\n\tprohibited: ReadonlySet<string>,\n): PnpToolSupports | undefined {\n\tconst atInit = new Set(record['activate-at-initialization-set'] ?? []);\n\tconst supports: string[] = [];\n\tconst prohibitedSupports: string[] = [];\n\tconst activateAtInit: string[] = [];\n\tconst toolParameters: Record<string, Record<string, unknown>> = {};\n\tconst add = (feature: string, toolId: string, parameters?: Record<string, unknown>) => {\n\t\tif (prohibited.has(feature)) {\n\t\t\tprohibitedSupports.push(toolId);\n\t\t\treturn;\n\t\t}\n\t\tif (!granted(feature)) return;\n\t\tsupports.push(toolId);\n\t\tif (atInit.has(feature)) activateAtInit.push(toolId);\n\t\tif (parameters && Object.keys(parameters).length > 0) toolParameters[toolId] = parameters;\n\t};\n\n\tfor (const [feature, toolId] of Object.entries(TOOL_FEATURES)) {\n\t\tconst calculatorType = feature === 'calculator-on-screen' ? field(record[feature], 'calculator-type') : undefined;\n\t\tadd(\n\t\t\tfeature,\n\t\t\ttoolId,\n\t\t\ttypeof calculatorType === 'string' && ['basic', 'scientific', 'graphing'].includes(calculatorType)\n\t\t\t\t? { type: calculatorType }\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tconst spoken = record.spoken;\n\tif (prohibited.has('spoken')) prohibitedSupports.push('textToSpeech');\n\telse if (field(spoken, 'reading-type') === 'computer-read-aloud') {\n\t\tconst rate = finiteNumber(field(spoken, 'speech-rate'));\n\t\tconst pitch = finiteNumber(field(spoken, 'pitch'));\n\t\tconst volume = finiteNumber(field(spoken, 'volume'));\n\t\tadd('spoken', 'textToSpeech', {\n\t\t\t...(rate !== undefined && rate > 0 ? { rate: rate / AFA_DEFAULT_SPEECH_RATE } : {}),\n\t\t\t...(pitch !== undefined ? { pitch: pitch * 2 } : {}),\n\t\t\t...(volume !== undefined ? { volume } : {}),\n\t\t});\n\t} else add('spoken', 'screenReader');\n\n\tif (supports.length === 0 && prohibitedSupports.length === 0) return undefined;\n\treturn {\n\t\t...(supports.length > 0 ? { supports } : {}),\n\t\t...(prohibitedSupports.length > 0 ? { prohibitedSupports } : {}),\n\t\t...(activateAtInit.length > 0 ? { activateAtInit } : {}),\n\t\t...(Object.keys(toolParameters).length > 0 ? { toolParameters } : {}),\n\t};\n}\n\n/** AfA `text-appearance` as the player applies it; undefined when it sets nothing. */\nfunction textAppearanceOf(value: unknown): PnpTextAppearance | undefined {\n\tconst appearance: PnpTextAppearance = {};\n\tconst fontSize = finiteNumber(field(value, 'font-size'));\n\tif (fontSize !== undefined && fontSize > 0) appearance.fontSize = fontSize;\n\tconst fontFace = field(value, 'font-face');\n\tconst names = [field(fontFace, 'font-name')].flat().filter((name): name is string => typeof name === 'string');\n\tconst generic = GENERIC_FONT_FACES[String(field(fontFace, 'generic-font-face') ?? '')];\n\tconst families = [...names.map((name) => JSON.stringify(name.trim())), ...(generic ? [generic] : [])];\n\tif (families.length > 0) appearance.fontFamily = families.join(', ');\n\tconst fontColor = hexColor(field(value, 'font-color'));\n\tif (fontColor) appearance.fontColor = fontColor;\n\tconst backgroundColor = hexColor(field(value, 'background-color'));\n\tif (backgroundColor) appearance.backgroundColor = backgroundColor;\n\tconst lineHeight = finiteNumber(field(value, 'line-height')) ?? finiteNumber(field(value, 'line-spacing'));\n\tif (lineHeight !== undefined && lineHeight > 0) appearance.lineHeight = lineHeight;\n\tconst letterSpacing = finiteNumber(field(value, 'letter-spacing'));\n\tif (letterSpacing !== undefined) appearance.letterSpacing = letterSpacing;\n\tconst wordSpacing = finiteNumber(field(value, 'word-spacing'));\n\tif (wordSpacing !== undefined) appearance.wordSpacing = wordSpacing;\n\treturn Object.keys(appearance).length > 0 ? appearance : undefined;\n}\n\n/**\n * Parse an AfA PNP 3.0 document into the `PnpProfile` the item player renders. Returns\n * an empty profile when the input holds none. `parseAfaPnpXml` returns the whole record.\n */\nexport function parsePnpXml(xml: string | Element): PnpProfile {\n\tconst record = parseAfaPnpXml(xml);\n\treturn record ? pnpProfileFromAfa(record) : {};\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction findProfile(parent: NhpElement): NhpElement | null {\n\tfor (const child of elementChildren(parent)) {\n\t\tif (splitName(child.rawTagName).local === 'access-for-all-pnp') return child;\n\t\tconst nested = findProfile(child);\n\t\tif (nested) return nested;\n\t}\n\treturn null;\n}\n\n/** Prefixes bound to an AfA PNP namespace on the profile or its ancestors. */\nfunction collectAfaPrefixes(root: NhpElement): Set<string> {\n\tconst prefixes = new Set<string>();\n\tfor (let el: NhpElement | null = root; el; el = el.parentNode as NhpElement | null) {\n\t\tfor (const [name, value] of Object.entries(el.rawAttributes ?? {})) {\n\t\t\tif (name.startsWith('xmlns:') && value.includes('imsafa3p0pnp')) prefixes.add(name.slice(6));\n\t\t}\n\t}\n\treturn prefixes;\n}\n\nfunction elementChildren(parent: NhpElement): NhpElement[] {\n\treturn parent.childNodes.filter((child): child is NhpElement => child.nodeType === 1);\n}\n\nfunction splitName(name: string | undefined): { prefix?: string; local: string } {\n\tconst raw = name ?? '';\n\tconst colon = raw.indexOf(':');\n\treturn colon < 0 ? { local: raw } : { prefix: raw.slice(0, colon), local: raw.slice(colon + 1) };\n}\n\nfunction elementValue(el: NhpElement): unknown {\n\tconst value: Record<string, unknown> = {};\n\tfor (const [name, raw] of Object.entries(el.rawAttributes ?? {})) {\n\t\tif (name === 'xmlns' || name.startsWith('xmlns:') || name.startsWith('xsi:')) continue;\n\t\taddValue(value, name === 'xml:lang' ? 'language' : splitName(name).local, scalar(raw));\n\t}\n\tconst children = elementChildren(el);\n\tfor (const child of children) {\n\t\taddValue(value, splitName(child.rawTagName).local, elementValue(child));\n\t}\n\tif (children.length > 0 || Object.keys(value).length > 0) return value;\n\tconst text = el.text.trim();\n\treturn text ? scalar(text) : {};\n}\n\nfunction addValue(target: Record<string, unknown>, key: string, value: unknown): void {\n\tif (!(key in target)) {\n\t\ttarget[key] = value;\n\t\treturn;\n\t}\n\tconst existing = target[key];\n\ttarget[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];\n}\n\nfunction scalar(raw: string): string | number | boolean {\n\tconst value = raw.trim();\n\tif (value === 'true') return true;\n\tif (value === 'false') return false;\n\tif (/^-?\\d+(?:\\.\\d+)?$/.test(value)) return Number(value);\n\treturn value;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)[key]\n\t\t: undefined;\n}\n\nfunction isPresent(value: unknown): boolean {\n\treturn value !== undefined && value !== null && value !== false;\n}\n\nfunction finiteNumber(value: unknown): number | undefined {\n\treturn typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\n/**\n * An AfA hex colour (`#fff`, `ffffff`) as CSS; undefined for anything else. An all-digit\n * colour reaches here as the number the record read it as, so it is padded back to six.\n */\nfunction hexColor(value: unknown): string | undefined {\n\tif (typeof value !== 'string' && typeof value !== 'number') return undefined;\n\tconst hex = typeof value === 'number' ? String(value).padStart(6, '0') : value.trim().replace(/^#/, '');\n\treturn /^(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex) ? `#${hex.toLowerCase()}` : undefined;\n}\n\nfunction normalizeLanguageCode(value: unknown): string | undefined {\n\tif (typeof value !== 'string') return undefined;\n\tconst languageCode = value.trim();\n\tif (!/^[a-zA-Z]{2,8}(?:-[a-zA-Z0-9]{1,8})*$/.test(languageCode)) return undefined;\n\treturn languageCode;\n}\n"]}
1
+ {"version":3,"file":"parsePnpXml.js","sourceRoot":"","sources":["../../src/pnp/parsePnpXml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAItD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,wDAAwD,CAAC;AAmB1F,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,gCAAgC,EAAE,wBAAwB,EAAE,cAAc,CAAC,CAAC,CAAC;AAE3G;;;;GAIG;AACH,MAAM,wBAAwB,GAAG;IAChC,uBAAuB;IACvB,mBAAmB;IACnB,SAAS;IACT,eAAe;IACf,qBAAqB;IACrB,qBAAqB;IACrB,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,8BAA8B;IAC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C,CAAE,KAAiC,CAAC,GAAG,CAAC;QACzC,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC;AACjE,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC;AAED;;;GAGG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC7E,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACxG,OAAO,qCAAqC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,uCAAuC,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,OAAO,SAAS,CAAC;IAClF,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { parse as parseHtml } from 'node-html-parser';\nimport type { HTMLElement as NhpElement } from 'node-html-parser';\nimport type { CatalogSupportPreference, PnpProfile, PnpTextAppearance, PnpToolSupports } from './types.js';\n\n/** QTI 3's profile of Access for All Personal Needs and Preferences 3.0. */\nexport const AFA_PNP_NAMESPACE = 'http://www.imsglobal.org/xsd/qtiv3p0/imsafa3p0pnp_v1p0';\n\n/**\n * An AfA PNP 3.0 profile as JSON keyed by the spec's kebab-case terms, the shape\n * pie-players' `createPersonalNeedsProfileFromAfa` takes.\n *\n * An empty element is `{}`, an element holding only text is that text (a number or\n * boolean when it reads as one), `xml:lang` is `language`, a repeated element is an\n * array, and a feature set is the list of feature names it holds. Elements of another\n * namespace, AfA's extension mechanism, sit under `extensions` by local name.\n */\nexport interface AfaPnpRecord {\n\t'activate-at-initialization-set'?: string[];\n\t'activate-as-option-set'?: string[];\n\t'prohibit-set'?: string[];\n\textensions?: Record<string, unknown>;\n\t[feature: string]: unknown;\n}\n\nconst FEATURE_SETS = new Set(['activate-at-initialization-set', 'activate-as-option-set', 'prohibit-set']);\n\n/**\n * QTI 3's predefined catalog card supports, less `glossary-on-screen` and\n * `keyword-translation`, which have popups of their own. A granted one enables the\n * catalog support of that name.\n */\nconst CATALOG_SUPPORT_FEATURES = [\n\t'additional-directions',\n\t'audio-description',\n\t'braille',\n\t'high-contrast',\n\t'keyboard-directions',\n\t'linguistic-guidance',\n\t'long-description',\n\t'sign-language',\n\t'simplified-graphics',\n\t'simplified-language-portions',\n\t'spoken',\n\t'tactile',\n\t'transcript',\n] as const;\n\n/**\n * AfA features the player routes itself, recorded under the platform preference key\n * (`CatalogSupportPreferences` flag) rather than the AfA feature name, so the granted\n * support reaches the platform routing instead of falling through as host-defined.\n */\nconst PLATFORM_CATALOG_FEATURES: Readonly<Partial<Record<(typeof CATALOG_SUPPORT_FEATURES)[number], string>>> = {\n\tbraille: 'brailleText',\n\t'sign-language': 'signingDefinition',\n};\n\n/** The extension SBAC requests its illustrated glossary with. */\nconst ILLUSTRATED_GLOSSARY_EXTENSION = 'sbac-glossary-illustration';\n\ntype ColorScheme = NonNullable<NonNullable<PnpProfile['display']>['colorScheme']>;\n\n/**\n * AfA `color-theme` terms onto the player's scheme names. The spec leaves a theme's\n * exact colors to the delivery system, so `high-contrast` takes black on white and\n * its reverse white on black.\n */\nconst COLOR_THEMES: Readonly<Record<string, ColorScheme>> = {\n\tdefault: 'default',\n\t'default-reverse': 'defaultreverse',\n\t'high-contrast': 'blackwhite',\n\t'high-contrast-reverse': 'whiteblack',\n\t'black-rose': 'blackrose',\n\t'rose-black': 'roseblack',\n\t'yellow-blue': 'yellowblue',\n\t'blue-yellow': 'blueyellow',\n\t'medgray-darkgray': 'mgraydgray',\n\t'darkgray-medgray': 'dgraymgray',\n\t'black-cyan': 'blackcyan',\n\t'cyan-black': 'cyanblack',\n\t'black-cream': 'blackcream',\n\t'cream-black': 'creamblack',\n};\n\n/** AfA `generic-font-face` terms onto CSS generic families. */\nconst GENERIC_FONT_FACES: Readonly<Record<string, string>> = {\n\tserif: 'serif',\n\t'sans serif': 'sans-serif',\n\tmonospaced: 'monospace',\n\tcursive: 'cursive',\n\tfantasy: 'fantasy',\n};\n\n/** AfA's speech rate when the profile gives none, in words per minute. */\nconst AFA_DEFAULT_SPEECH_RATE = 180;\n\n/**\n * AfA tool features onto pie-players support ids, the ids its\n * `createPersonalNeedsProfileFromAfa` gives them. `spoken` resolves by reading type.\n */\nconst TOOL_FEATURES: Readonly<Record<string, string>> = {\n\t'calculator-on-screen': 'calculator',\n\t'line-reader': 'lineReader',\n\t'dictionary-on-screen': 'dictionary',\n};\n\n/**\n * Parse an AfA PNP 3.0 document into its record: an `access-for-all-pnp` element, or\n * the first one inside an `access-for-all-pnp-record`. A bulk records file holds one\n * profile per candidate, so pass the candidate's record. Returns `null` when the input\n * holds no profile.\n */\nexport function parseAfaPnpXml(xml: string | Element): AfaPnpRecord | null {\n\tconst source = typeof xml === 'string' ? xml : ((xml as Element).outerHTML ?? '');\n\tconst trimmed = source.replace(/<\\?xml[^>]*\\?>/g, '').trim();\n\tif (!trimmed) return null;\n\n\tconst doc = parseHtml(`<root>${trimmed}</root>`, { lowerCaseTagName: false });\n\tconst root = findProfile(doc);\n\tif (!root) return null;\n\n\tconst afaPrefixes = collectAfaPrefixes(root);\n\tconst record: AfaPnpRecord = {};\n\tfor (const child of elementChildren(root)) {\n\t\tconst { prefix, local } = splitName(child.rawTagName);\n\t\tif (prefix && !afaPrefixes.has(prefix)) {\n\t\t\trecord.extensions ??= {};\n\t\t\taddValue(record.extensions, local, elementValue(child));\n\t\t} else if (FEATURE_SETS.has(local)) {\n\t\t\trecord[local] = elementChildren(child).map((feature) => splitName(feature.rawTagName).local);\n\t\t} else {\n\t\t\taddValue(record, local, elementValue(child));\n\t\t}\n\t}\n\treturn record;\n}\n\n/**\n * The part of an AfA record the item player renders. A feature counts when the record\n * names it or one of its activation sets lists it, unless `prohibit-set` lists it.\n * Features with no `PnpProfile` field stay in the record for the host: `ext:` color\n * themes, and the tool supports `tools` does not name.\n */\nexport function pnpProfileFromAfa(record: AfaPnpRecord): PnpProfile {\n\tconst prohibited = new Set(record['prohibit-set'] ?? []);\n\tconst listed = new Set([\n\t\t...(record['activate-at-initialization-set'] ?? []),\n\t\t...(record['activate-as-option-set'] ?? []),\n\t]);\n\tconst granted = (feature: string): boolean =>\n\t\t!prohibited.has(feature) && (isPresent(record[feature]) || listed.has(feature));\n\n\tconst display: NonNullable<PnpProfile['display']> = {};\n\tconst theme = granted('text-appearance')\n\t\t? field(record['text-appearance'], 'color-theme')\n\t\t: granted('color-theme')\n\t\t\t? record['color-theme']\n\t\t\t: undefined;\n\tif (typeof theme === 'string' && COLOR_THEMES[theme]) display.colorScheme = COLOR_THEMES[theme];\n\tif (granted('magnification')) {\n\t\tconst magnification = record.magnification;\n\t\tconst zoom =\n\t\t\tfiniteNumber(field(field(magnification, 'all-content'), 'zoom-amount')) ??\n\t\t\tfiniteNumber(field(field(magnification, 'text'), 'zoom-amount'));\n\t\tif (zoom !== undefined && zoom > 0) display.magnification = zoom;\n\t}\n\tif (granted('language-of-interface')) {\n\t\tconst interfaceLanguage = normalizeLanguageCode(field(record['language-of-interface'], 'language'));\n\t\tif (interfaceLanguage) display.interfaceLanguage = interfaceLanguage;\n\t}\n\tif (granted('invert-display-polarity')) {\n\t\tconst polarity = record['invert-display-polarity'];\n\t\tconst foreground = hexColor(field(polarity, 'foreground'));\n\t\tconst background = hexColor(field(polarity, 'background'));\n\t\tdisplay.invertPolarity = { ...(foreground ? { foreground } : {}), ...(background ? { background } : {}) };\n\t}\n\tif (granted('layout-single-column')) display.singleColumn = true;\n\tif (granted('text-appearance')) {\n\t\tconst textAppearance = textAppearanceOf(record['text-appearance']);\n\t\tif (textAppearance) display.textAppearance = textAppearance;\n\t}\n\n\tconst content: NonNullable<PnpProfile['content']> = {};\n\tif (granted('glossary-on-screen')) content.glossaryOnScreen = true;\n\tif (granted('keyword-translation')) {\n\t\tconst languageCode = normalizeLanguageCode(field(record['keyword-translation'], 'language'));\n\t\tif (languageCode) content.keywordTranslation = { active: true, languageCode };\n\t}\n\tif (\n\t\t!prohibited.has(ILLUSTRATED_GLOSSARY_EXTENSION) &&\n\t\tisPresent(record.extensions?.[ILLUSTRATED_GLOSSARY_EXTENSION])\n\t) {\n\t\tcontent.illustratedGlossary = true;\n\t}\n\tfor (const feature of CATALOG_SUPPORT_FEATURES) {\n\t\tif (!granted(feature)) continue;\n\t\tconst languageCode = normalizeLanguageCode(field(record[feature], 'language'));\n\t\tconst preference: CatalogSupportPreference = languageCode ? { active: true, languageCode } : true;\n\t\tcontent.catalogSupports ??= {};\n\t\tcontent.catalogSupports[PLATFORM_CATALOG_FEATURES[feature] ?? feature] = preference;\n\t}\n\tif (granted('additional-testing-time')) {\n\t\tconst testingTime = record['additional-testing-time'];\n\t\tconst multiplier = isPresent(field(testingTime, 'unlimited'))\n\t\t\t? Infinity\n\t\t\t: finiteNumber(field(testingTime, 'time-multiplier'));\n\t\tconst fixedMinutes = finiteNumber(field(testingTime, 'fixed-minutes'));\n\t\tif (multiplier !== undefined && multiplier > 0) content.extendedTime = { active: true, multiplier };\n\t\telse if (fixedMinutes !== undefined && fixedMinutes > 0) {\n\t\t\tcontent.extendedTime = { active: true, multiplier: 1, fixedMinutes };\n\t\t}\n\t}\n\n\tconst cognitive: NonNullable<PnpProfile['cognitive']> = {};\n\tif (granted('answer-masking')) cognitive.answerMasking = true;\n\tif (granted('spell-checker-on-screen')) cognitive.spellChecker = true;\n\n\tconst tools = toolSupportsOf(record, granted, prohibited);\n\n\tconst profile: PnpProfile = {};\n\tif (Object.keys(display).length > 0) profile.display = display;\n\tif (Object.keys(content).length > 0) profile.content = content;\n\tif (Object.keys(cognitive).length > 0) profile.cognitive = cognitive;\n\tif (tools) profile.tools = tools;\n\treturn profile;\n}\n\n/** The tool supports an AfA record grants or withdraws, as pie-players support ids. */\nfunction toolSupportsOf(\n\trecord: AfaPnpRecord,\n\tgranted: (feature: string) => boolean,\n\tprohibited: ReadonlySet<string>,\n): PnpToolSupports | undefined {\n\tconst atInit = new Set(record['activate-at-initialization-set'] ?? []);\n\tconst supports: string[] = [];\n\tconst prohibitedSupports: string[] = [];\n\tconst activateAtInit: string[] = [];\n\tconst toolParameters: Record<string, Record<string, unknown>> = {};\n\tconst add = (feature: string, toolId: string, parameters?: Record<string, unknown>) => {\n\t\tif (prohibited.has(feature)) {\n\t\t\tprohibitedSupports.push(toolId);\n\t\t\treturn;\n\t\t}\n\t\tif (!granted(feature)) return;\n\t\tsupports.push(toolId);\n\t\tif (atInit.has(feature)) activateAtInit.push(toolId);\n\t\tif (parameters && Object.keys(parameters).length > 0) toolParameters[toolId] = parameters;\n\t};\n\n\tfor (const [feature, toolId] of Object.entries(TOOL_FEATURES)) {\n\t\tconst calculatorType = feature === 'calculator-on-screen' ? field(record[feature], 'calculator-type') : undefined;\n\t\tadd(\n\t\t\tfeature,\n\t\t\ttoolId,\n\t\t\ttypeof calculatorType === 'string' && ['basic', 'scientific', 'graphing'].includes(calculatorType)\n\t\t\t\t? { type: calculatorType }\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\tconst spoken = record.spoken;\n\tif (prohibited.has('spoken')) prohibitedSupports.push('textToSpeech');\n\telse if (field(spoken, 'reading-type') === 'computer-read-aloud') {\n\t\tconst rate = finiteNumber(field(spoken, 'speech-rate'));\n\t\tconst pitch = finiteNumber(field(spoken, 'pitch'));\n\t\tconst volume = finiteNumber(field(spoken, 'volume'));\n\t\tadd('spoken', 'textToSpeech', {\n\t\t\t...(rate !== undefined && rate > 0 ? { rate: rate / AFA_DEFAULT_SPEECH_RATE } : {}),\n\t\t\t...(pitch !== undefined ? { pitch: pitch * 2 } : {}),\n\t\t\t...(volume !== undefined ? { volume } : {}),\n\t\t});\n\t} else add('spoken', 'screenReader');\n\n\tif (supports.length === 0 && prohibitedSupports.length === 0) return undefined;\n\treturn {\n\t\t...(supports.length > 0 ? { supports } : {}),\n\t\t...(prohibitedSupports.length > 0 ? { prohibitedSupports } : {}),\n\t\t...(activateAtInit.length > 0 ? { activateAtInit } : {}),\n\t\t...(Object.keys(toolParameters).length > 0 ? { toolParameters } : {}),\n\t};\n}\n\n/** AfA `text-appearance` as the player applies it; undefined when it sets nothing. */\nfunction textAppearanceOf(value: unknown): PnpTextAppearance | undefined {\n\tconst appearance: PnpTextAppearance = {};\n\tconst fontSize = finiteNumber(field(value, 'font-size'));\n\tif (fontSize !== undefined && fontSize > 0) appearance.fontSize = fontSize;\n\tconst fontFace = field(value, 'font-face');\n\tconst names = [field(fontFace, 'font-name')].flat().filter((name): name is string => typeof name === 'string');\n\tconst generic = GENERIC_FONT_FACES[String(field(fontFace, 'generic-font-face') ?? '')];\n\tconst families = [...names.map((name) => JSON.stringify(name.trim())), ...(generic ? [generic] : [])];\n\tif (families.length > 0) appearance.fontFamily = families.join(', ');\n\tconst fontColor = hexColor(field(value, 'font-color'));\n\tif (fontColor) appearance.fontColor = fontColor;\n\tconst backgroundColor = hexColor(field(value, 'background-color'));\n\tif (backgroundColor) appearance.backgroundColor = backgroundColor;\n\tconst lineHeight = finiteNumber(field(value, 'line-height')) ?? finiteNumber(field(value, 'line-spacing'));\n\tif (lineHeight !== undefined && lineHeight > 0) appearance.lineHeight = lineHeight;\n\tconst letterSpacing = finiteNumber(field(value, 'letter-spacing'));\n\tif (letterSpacing !== undefined) appearance.letterSpacing = letterSpacing;\n\tconst wordSpacing = finiteNumber(field(value, 'word-spacing'));\n\tif (wordSpacing !== undefined) appearance.wordSpacing = wordSpacing;\n\treturn Object.keys(appearance).length > 0 ? appearance : undefined;\n}\n\n/**\n * Parse an AfA PNP 3.0 document into the `PnpProfile` the item player renders. Returns\n * an empty profile when the input holds none. `parseAfaPnpXml` returns the whole record.\n */\nexport function parsePnpXml(xml: string | Element): PnpProfile {\n\tconst record = parseAfaPnpXml(xml);\n\treturn record ? pnpProfileFromAfa(record) : {};\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction findProfile(parent: NhpElement): NhpElement | null {\n\tfor (const child of elementChildren(parent)) {\n\t\tif (splitName(child.rawTagName).local === 'access-for-all-pnp') return child;\n\t\tconst nested = findProfile(child);\n\t\tif (nested) return nested;\n\t}\n\treturn null;\n}\n\n/** Prefixes bound to an AfA PNP namespace on the profile or its ancestors. */\nfunction collectAfaPrefixes(root: NhpElement): Set<string> {\n\tconst prefixes = new Set<string>();\n\tfor (let el: NhpElement | null = root; el; el = el.parentNode as NhpElement | null) {\n\t\tfor (const [name, value] of Object.entries(el.rawAttributes ?? {})) {\n\t\t\tif (name.startsWith('xmlns:') && value.includes('imsafa3p0pnp')) prefixes.add(name.slice(6));\n\t\t}\n\t}\n\treturn prefixes;\n}\n\nfunction elementChildren(parent: NhpElement): NhpElement[] {\n\treturn parent.childNodes.filter((child): child is NhpElement => child.nodeType === 1);\n}\n\nfunction splitName(name: string | undefined): { prefix?: string; local: string } {\n\tconst raw = name ?? '';\n\tconst colon = raw.indexOf(':');\n\treturn colon < 0 ? { local: raw } : { prefix: raw.slice(0, colon), local: raw.slice(colon + 1) };\n}\n\nfunction elementValue(el: NhpElement): unknown {\n\tconst value: Record<string, unknown> = {};\n\tfor (const [name, raw] of Object.entries(el.rawAttributes ?? {})) {\n\t\tif (name === 'xmlns' || name.startsWith('xmlns:') || name.startsWith('xsi:')) continue;\n\t\taddValue(value, name === 'xml:lang' ? 'language' : splitName(name).local, scalar(raw));\n\t}\n\tconst children = elementChildren(el);\n\tfor (const child of children) {\n\t\taddValue(value, splitName(child.rawTagName).local, elementValue(child));\n\t}\n\tif (children.length > 0 || Object.keys(value).length > 0) return value;\n\tconst text = el.text.trim();\n\treturn text ? scalar(text) : {};\n}\n\nfunction addValue(target: Record<string, unknown>, key: string, value: unknown): void {\n\tif (!(key in target)) {\n\t\ttarget[key] = value;\n\t\treturn;\n\t}\n\tconst existing = target[key];\n\ttarget[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];\n}\n\nfunction scalar(raw: string): string | number | boolean {\n\tconst value = raw.trim();\n\tif (value === 'true') return true;\n\tif (value === 'false') return false;\n\tif (/^-?\\d+(?:\\.\\d+)?$/.test(value)) return Number(value);\n\treturn value;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)[key]\n\t\t: undefined;\n}\n\nfunction isPresent(value: unknown): boolean {\n\treturn value !== undefined && value !== null && value !== false;\n}\n\nfunction finiteNumber(value: unknown): number | undefined {\n\treturn typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n}\n\n/**\n * An AfA hex colour (`#fff`, `ffffff`) as CSS; undefined for anything else. An all-digit\n * colour reaches here as the number the record read it as, so it is padded back to six.\n */\nfunction hexColor(value: unknown): string | undefined {\n\tif (typeof value !== 'string' && typeof value !== 'number') return undefined;\n\tconst hex = typeof value === 'number' ? String(value).padStart(6, '0') : value.trim().replace(/^#/, '');\n\treturn /^(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex) ? `#${hex.toLowerCase()}` : undefined;\n}\n\nfunction normalizeLanguageCode(value: unknown): string | undefined {\n\tif (typeof value !== 'string') return undefined;\n\tconst languageCode = value.trim();\n\tif (!/^[a-zA-Z]{2,8}(?:-[a-zA-Z0-9]{1,8})*$/.test(languageCode)) return undefined;\n\treturn languageCode;\n}\n"]}
@@ -10,8 +10,9 @@ export interface PnpProfile {
10
10
  */
11
11
  colorScheme?: 'default' | 'defaultreverse' | 'blackwhite' | 'whiteblack' | 'blackrose' | 'roseblack' | 'yellowblue' | 'blueyellow' | 'mgraydgray' | 'dgraymgray' | 'blackcyan' | 'cyanblack' | 'blackcream' | 'creamblack' | 'whitenav' | 'medgray';
12
12
  /**
13
- * CSS zoom factor (1.0 = 100%). Deferred — set by browser zoom or host stylesheet.
14
- * Stored here for forward-compatibility but not yet applied by the player.
13
+ * AfA `magnification`: CSS zoom factor (1.0 = 100%). Set on the player root as
14
+ * `data-qti-magnification` and `--qti-magnification` for host stylesheets; the default
15
+ * stylesheet does not render it, leaving zoom to the browser or operating system.
15
16
  */
16
17
  magnification?: number;
17
18
  /** AfA `language-of-interface`: the language the host renders the player's own text in. */
@@ -29,12 +30,14 @@ export interface PnpProfile {
29
30
  /** AfA `text-appearance`, applied as custom properties on the player root. */
30
31
  textAppearance?: PnpTextAppearance;
31
32
  /**
32
- * Present each interaction's answer set as a labelled ARIA group for assistive
33
- * technology: the choice and match interactions wrap their answers in a
34
- * `role="group"` labelled by the interaction prompt, and the match columns get
35
- * visible, programmatically associated sub-labels. Neither APIP 1.0 nor AfA PNP
36
- * 3.0 defines a structured-label term; this is a player extension, so hosts set
37
- * it in the JSON profile (it has no AfA XML feature).
33
+ * Present the match interaction's answer set as a labelled ARIA group for
34
+ * assistive technology: match wraps its answers in a `role="group"` labelled
35
+ * by the interaction prompt, and its columns get visible, programmatically
36
+ * associated sub-labels. (Choice always names its group by the prompt, so
37
+ * the flag does not affect it.)
38
+ * Neither APIP 1.0 nor AfA PNP 3.0 defines a structured-label term; this is
39
+ * a player extension, so hosts set it in the JSON profile (it has no AfA
40
+ * XML feature).
38
41
  */
39
42
  structuredLabelSupport?: boolean;
40
43
  };
@@ -66,6 +69,11 @@ export interface PnpProfile {
66
69
  eliminationTool?: boolean;
67
70
  /** AfA `answer-masking`: each choice of a choiceInteraction stays masked until the candidate reveals it. */
68
71
  answerMasking?: boolean;
72
+ /**
73
+ * AfA `spell-checker-on-screen`: the browser's spell check and autocorrect are
74
+ * allowed in the candidate's response fields (the extended text interaction).
75
+ */
76
+ spellChecker?: boolean;
69
77
  };
70
78
  /**
71
79
  * Tool supports in pie-players' `PersonalNeedsProfile` terms, from AfA `calculator-on-screen`,
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pnp/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The candidate needs the item player renders, from a per-candidate AfA PNP 3.0\n * profile (`pnpProfileFromAfa`). All fields are optional; absent means \"use platform default\".\n */\nexport interface PnpProfile {\n\tdisplay?: {\n\t\t/**\n\t\t * Named color scheme. Maps to the data-qti-colorscheme attribute on the player root.\n\t\t * 'default' or undefined → attribute removed (browser/host default).\n\t\t */\n\t\tcolorScheme?:\n\t\t\t| 'default'\n\t\t\t| 'defaultreverse'\n\t\t\t| 'blackwhite'\n\t\t\t| 'whiteblack'\n\t\t\t| 'blackrose'\n\t\t\t| 'roseblack'\n\t\t\t| 'yellowblue'\n\t\t\t| 'blueyellow'\n\t\t\t| 'mgraydgray'\n\t\t\t| 'dgraymgray'\n\t\t\t| 'blackcyan'\n\t\t\t| 'cyanblack'\n\t\t\t| 'blackcream'\n\t\t\t| 'creamblack'\n\t\t\t| 'whitenav'\n\t\t\t| 'medgray';\n\t\t/**\n\t\t * CSS zoom factor (1.0 = 100%). Deferred — set by browser zoom or host stylesheet.\n\t\t * Stored here for forward-compatibility but not yet applied by the player.\n\t\t */\n\t\tmagnification?: number;\n\t\t/** AfA `language-of-interface`: the language the host renders the player's own text in. */\n\t\tinterfaceLanguage?: string;\n\t\t/**\n\t\t * AfA `invert-display-polarity`: light content on a dark ground. The colours, when given,\n\t\t * replace the inverted ones. Sets `data-qti-invert-polarity` on the player root.\n\t\t */\n\t\tinvertPolarity?: { foreground?: string; background?: string };\n\t\t/** AfA `layout-single-column`: layout grids stack. Sets `data-qti-layout=\"single-column\"`. */\n\t\tsingleColumn?: boolean;\n\t\t/** AfA `text-appearance`, applied as custom properties on the player root. */\n\t\ttextAppearance?: PnpTextAppearance;\n\t\t/**\n\t\t * Present each interaction's answer set as a labelled ARIA group for assistive\n\t\t * technology: the choice and match interactions wrap their answers in a\n\t\t * `role=\"group\"` labelled by the interaction prompt, and the match columns get\n\t\t * visible, programmatically associated sub-labels. Neither APIP 1.0 nor AfA PNP\n\t\t * 3.0 defines a structured-label term; this is a player extension, so hosts set\n\t\t * it in the JSON profile (it has no AfA XML feature).\n\t\t */\n\t\tstructuredLabelSupport?: boolean;\n\t};\n\tcontent?: {\n\t\t/** Show glossary trigger buttons on [data-catalog-idref] terms (G-10). */\n\t\tglossaryOnScreen?: boolean;\n\t\t/** Show keyword-translation trigger buttons using the given language code. */\n\t\tkeywordTranslation?: { active: boolean; languageCode: string };\n\t\t/** Show illustrated glossary supports when catalog entries provide them. */\n\t\tillustratedGlossary?: boolean;\n\t\t/** Enable user-initiated host-routed catalog supports. */\n\t\tcatalogSupports?: CatalogSupportPreferences;\n\t\t/**\n\t\t * Scale assessment time limits. multiplier: 1.5 means 50% extra time.\n\t\t * multiplier: Infinity removes the time limit entirely.\n\t\t */\n\t\textendedTime?: {\n\t\t\tactive: boolean;\n\t\t\tmultiplier: number;\n\t\t\t/** AfA `fixed-minutes`: minutes added to each time limit, with `multiplier` 1. */\n\t\t\tfixedMinutes?: number;\n\t\t};\n\t};\n\tcognitive?: {\n\t\t/** Render per-choice elimination toggle buttons in choiceInteraction and orderInteraction. */\n\t\teliminationTool?: boolean;\n\t\t/** AfA `answer-masking`: each choice of a choiceInteraction stays masked until the candidate reveals it. */\n\t\tanswerMasking?: boolean;\n\t};\n\t/**\n\t * Tool supports in pie-players' `PersonalNeedsProfile` terms, from AfA `calculator-on-screen`,\n\t * `spoken`, `line-reader` and `dictionary-on-screen`. The section player enables the tools it\n\t * offers from them; a host passes them to its own toolkit.\n\t */\n\ttools?: PnpToolSupports;\n}\n\nexport interface PnpTextAppearance {\n\t/** Font size in points. */\n\tfontSize?: number;\n\t/** A CSS font-family list: the named fonts, then the generic face. */\n\tfontFamily?: string;\n\tfontColor?: string;\n\tbackgroundColor?: string;\n\t/** Unitless line height, from AfA `line-height`, else `line-spacing`. */\n\tlineHeight?: number;\n\t/** Letter spacing in em. */\n\tletterSpacing?: number;\n\t/** Word spacing in em. */\n\twordSpacing?: number;\n}\n\nexport interface PnpToolSupports {\n\t/** Tool ids granted to the candidate. */\n\tsupports?: string[];\n\t/** Tool ids withdrawn from the candidate. */\n\tprohibitedSupports?: string[];\n\t/** Granted tool ids turned on at start. */\n\tactivateAtInit?: string[];\n\t/** The candidate's settings per tool id. */\n\ttoolParameters?: Record<string, Record<string, unknown>>;\n}\n\nexport interface CatalogSupportPreferences {\n\tttsPronunciation?: CatalogSupportPreference;\n\tsigningDefinition?: CatalogSupportPreference;\n\tbrailleText?: CatalogSupportPreference;\n\taudioDescription?: CatalogSupportPreference;\n\textendedDescription?: CatalogSupportPreference;\n\t/**\n\t * Host-defined catalog usage names. Use QTI/catalog usage strings such as\n\t * \"custom-audio\" rather than DOM event names or implementation-specific APIs.\n\t */\n\t[usage: string]: CatalogSupportPreference | undefined;\n}\n\nexport type CatalogSupportPreference = boolean | CatalogSupportPreferenceOptions;\n\nexport interface CatalogSupportPreferenceOptions {\n\t/** Defaults to true when omitted. */\n\tactive?: boolean;\n\t/** Preferred catalog entry language for this support, such as \"en-US\" or \"es\". */\n\tlanguageCode?: string;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pnp/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The candidate needs the item player renders, from a per-candidate AfA PNP 3.0\n * profile (`pnpProfileFromAfa`). All fields are optional; absent means \"use platform default\".\n */\nexport interface PnpProfile {\n\tdisplay?: {\n\t\t/**\n\t\t * Named color scheme. Maps to the data-qti-colorscheme attribute on the player root.\n\t\t * 'default' or undefined → attribute removed (browser/host default).\n\t\t */\n\t\tcolorScheme?:\n\t\t\t| 'default'\n\t\t\t| 'defaultreverse'\n\t\t\t| 'blackwhite'\n\t\t\t| 'whiteblack'\n\t\t\t| 'blackrose'\n\t\t\t| 'roseblack'\n\t\t\t| 'yellowblue'\n\t\t\t| 'blueyellow'\n\t\t\t| 'mgraydgray'\n\t\t\t| 'dgraymgray'\n\t\t\t| 'blackcyan'\n\t\t\t| 'cyanblack'\n\t\t\t| 'blackcream'\n\t\t\t| 'creamblack'\n\t\t\t| 'whitenav'\n\t\t\t| 'medgray';\n\t\t/**\n\t\t * AfA `magnification`: CSS zoom factor (1.0 = 100%). Set on the player root as\n\t\t * `data-qti-magnification` and `--qti-magnification` for host stylesheets; the default\n\t\t * stylesheet does not render it, leaving zoom to the browser or operating system.\n\t\t */\n\t\tmagnification?: number;\n\t\t/** AfA `language-of-interface`: the language the host renders the player's own text in. */\n\t\tinterfaceLanguage?: string;\n\t\t/**\n\t\t * AfA `invert-display-polarity`: light content on a dark ground. The colours, when given,\n\t\t * replace the inverted ones. Sets `data-qti-invert-polarity` on the player root.\n\t\t */\n\t\tinvertPolarity?: { foreground?: string; background?: string };\n\t\t/** AfA `layout-single-column`: layout grids stack. Sets `data-qti-layout=\"single-column\"`. */\n\t\tsingleColumn?: boolean;\n\t\t/** AfA `text-appearance`, applied as custom properties on the player root. */\n\t\ttextAppearance?: PnpTextAppearance;\n\t\t/**\n\t\t * Present the match interaction's answer set as a labelled ARIA group for\n\t\t * assistive technology: match wraps its answers in a `role=\"group\"` labelled\n\t\t * by the interaction prompt, and its columns get visible, programmatically\n\t\t * associated sub-labels. (Choice always names its group by the prompt, so\n\t\t * the flag does not affect it.)\n\t\t * Neither APIP 1.0 nor AfA PNP 3.0 defines a structured-label term; this is\n\t\t * a player extension, so hosts set it in the JSON profile (it has no AfA\n\t\t * XML feature).\n\t\t */\n\t\tstructuredLabelSupport?: boolean;\n\t};\n\tcontent?: {\n\t\t/** Show glossary trigger buttons on [data-catalog-idref] terms (G-10). */\n\t\tglossaryOnScreen?: boolean;\n\t\t/** Show keyword-translation trigger buttons using the given language code. */\n\t\tkeywordTranslation?: { active: boolean; languageCode: string };\n\t\t/** Show illustrated glossary supports when catalog entries provide them. */\n\t\tillustratedGlossary?: boolean;\n\t\t/** Enable user-initiated host-routed catalog supports. */\n\t\tcatalogSupports?: CatalogSupportPreferences;\n\t\t/**\n\t\t * Scale assessment time limits. multiplier: 1.5 means 50% extra time.\n\t\t * multiplier: Infinity removes the time limit entirely.\n\t\t */\n\t\textendedTime?: {\n\t\t\tactive: boolean;\n\t\t\tmultiplier: number;\n\t\t\t/** AfA `fixed-minutes`: minutes added to each time limit, with `multiplier` 1. */\n\t\t\tfixedMinutes?: number;\n\t\t};\n\t};\n\tcognitive?: {\n\t\t/** Render per-choice elimination toggle buttons in choiceInteraction and orderInteraction. */\n\t\teliminationTool?: boolean;\n\t\t/** AfA `answer-masking`: each choice of a choiceInteraction stays masked until the candidate reveals it. */\n\t\tanswerMasking?: boolean;\n\t\t/**\n\t\t * AfA `spell-checker-on-screen`: the browser's spell check and autocorrect are\n\t\t * allowed in the candidate's response fields (the extended text interaction).\n\t\t */\n\t\tspellChecker?: boolean;\n\t};\n\t/**\n\t * Tool supports in pie-players' `PersonalNeedsProfile` terms, from AfA `calculator-on-screen`,\n\t * `spoken`, `line-reader` and `dictionary-on-screen`. The section player enables the tools it\n\t * offers from them; a host passes them to its own toolkit.\n\t */\n\ttools?: PnpToolSupports;\n}\n\nexport interface PnpTextAppearance {\n\t/** Font size in points. */\n\tfontSize?: number;\n\t/** A CSS font-family list: the named fonts, then the generic face. */\n\tfontFamily?: string;\n\tfontColor?: string;\n\tbackgroundColor?: string;\n\t/** Unitless line height, from AfA `line-height`, else `line-spacing`. */\n\tlineHeight?: number;\n\t/** Letter spacing in em. */\n\tletterSpacing?: number;\n\t/** Word spacing in em. */\n\twordSpacing?: number;\n}\n\nexport interface PnpToolSupports {\n\t/** Tool ids granted to the candidate. */\n\tsupports?: string[];\n\t/** Tool ids withdrawn from the candidate. */\n\tprohibitedSupports?: string[];\n\t/** Granted tool ids turned on at start. */\n\tactivateAtInit?: string[];\n\t/** The candidate's settings per tool id. */\n\ttoolParameters?: Record<string, Record<string, unknown>>;\n}\n\nexport interface CatalogSupportPreferences {\n\tttsPronunciation?: CatalogSupportPreference;\n\tsigningDefinition?: CatalogSupportPreference;\n\tbrailleText?: CatalogSupportPreference;\n\taudioDescription?: CatalogSupportPreference;\n\textendedDescription?: CatalogSupportPreference;\n\t/**\n\t * Host-defined catalog usage names. Use QTI/catalog usage strings such as\n\t * \"custom-audio\" rather than DOM event names or implementation-specific APIs.\n\t */\n\t[usage: string]: CatalogSupportPreference | undefined;\n}\n\nexport type CatalogSupportPreference = boolean | CatalogSupportPreferenceOptions;\n\nexport interface CatalogSupportPreferenceOptions {\n\t/** Defaults to true when omitted. */\n\tactive?: boolean;\n\t/** Preferred catalog entry language for this support, such as \"en-US\" or \"es\". */\n\tlanguageCode?: string;\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Screen-reader announcement of integrated feedback (WCAG 4.1.3 Status Messages).
3
+ *
4
+ * The presentation plan splices the feedbackInline and feedbackBlock that an attempt shows into
5
+ * the item body HTML, with no marker left behind. They appear without moving focus and without
6
+ * any other change assistive technology can detect. The item body therefore announces them
7
+ * through one persistent polite live region. This module holds the pure rules behind that:
8
+ * what the shown feedback says, which session transitions announce it, and how an identical
9
+ * repeat still reaches a screen reader.
10
+ */
11
+ import type { ItemSessionTransition } from '../core/ItemSession.js';
12
+ import type { QTIRole } from '../types/index.js';
13
+ /** The integrated feedback an item body shows. */
14
+ export interface ShownFeedback {
15
+ /** Whether any feedbackInline or feedbackBlock with content is shown. */
16
+ readonly shown: boolean;
17
+ /**
18
+ * Accessible text of the shown feedback in document order: visible text plus image `alt` text,
19
+ * markup removed and whitespace collapsed. Empty when nothing is shown, or when what is shown
20
+ * has no text, such as an image with no alt. A shown feedback with no text is announced as a
21
+ * localized "Feedback is shown." instead.
22
+ */
23
+ readonly text: string;
24
+ }
25
+ export interface ExtractShownFeedbackOptions {
26
+ /** Show no feedback whatever the outcomes, as a test-level `showFeedback="false"` requires. */
27
+ readonly hideAll?: boolean;
28
+ /** The authoring heuristics the plan applies to shown feedback (`cleanFeedbackText`). */
29
+ readonly transform?: (html: string) => string;
30
+ }
31
+ /**
32
+ * The feedback that `outcomeValues` show in an item body, read as text in document order.
33
+ *
34
+ * Runs on the body HTML *before* the plan splices the feedback in, while every element still
35
+ * carries its `outcomeIdentifier` and `identifier`. Visibility follows the shared rule
36
+ * (`isShownByIdentifier`, including `showHide="hide"` and container membership). Nested feedback
37
+ * resolves inside shown feedback, and hidden feedback contributes nothing, not even what is
38
+ * nested inside it. Separate feedback elements are joined with a space.
39
+ */
40
+ export declare function extractShownFeedback(bodyHtml: string, outcomeValues: Readonly<Record<string, unknown>>, options?: ExtractShownFeedbackOptions): ShownFeedback;
41
+ /**
42
+ * Whether a session transition is the candidate's own attempt ending: a submit or end-attempt,
43
+ * which covers every attempt of an adaptive item, including an uncounted `countAttempt="false"`
44
+ * one. Feedback is the result of the attempt, so only an attempt announces it. Initial render and
45
+ * restore dispatch nothing. Review and scorer renders dispatch no attempt, because a scorer is
46
+ * excluded by role and an ended session refuses attempt commands. All of them therefore stay
47
+ * silent, however often they re-render.
48
+ */
49
+ export declare function isCandidateAttemptFeedback(transition: Pick<ItemSessionTransition, 'command'>, role: QTIRole): boolean;
50
+ /**
51
+ * The live-region text for `message`, given the text it holds now. Repeating identical text would
52
+ * leave the region unchanged, and assistive technology does not announce an unchanged region. A
53
+ * repeat therefore toggles a trailing zero-width space, which a screen reader does not read but
54
+ * which still changes the region. The interaction components use the same toggle for refusals.
55
+ */
56
+ export declare function nextFeedbackAnnouncement(previous: string | null | undefined, message: string): string;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Screen-reader announcement of integrated feedback (WCAG 4.1.3 Status Messages).
3
+ *
4
+ * The presentation plan splices the feedbackInline and feedbackBlock that an attempt shows into
5
+ * the item body HTML, with no marker left behind. They appear without moving focus and without
6
+ * any other change assistive technology can detect. The item body therefore announces them
7
+ * through one persistent polite live region. This module holds the pure rules behind that:
8
+ * what the shown feedback says, which session transitions announce it, and how an identical
9
+ * repeat still reaches a screen reader.
10
+ */
11
+ import { isShownByIdentifier } from '@pie-qti/qti-common';
12
+ import { readHtmlAttribute } from '../utils/htmlAttributes.js';
13
+ const NOTHING_SHOWN = Object.freeze({ shown: false, text: '' });
14
+ const FEEDBACK_TAG = /<(\/?)(feedbackInline|qti-feedback-inline|feedbackBlock|qti-feedback-block)\b([^>]*?)(\/?)>/gi;
15
+ /**
16
+ * The top-level feedback elements in `html`, each with the feedback nested inside it. Parsed as
17
+ * `processFeedbackInline` in `@pie-qti/qti-common` parses them, so the announcement covers exactly
18
+ * the elements the plan shows or drops. An unclosed element is left as written, as it is there.
19
+ */
20
+ function feedbackElements(html) {
21
+ const roots = [];
22
+ const open = [];
23
+ const add = (element) => (open[open.length - 1]?.children ?? roots).push(element);
24
+ for (const match of html.matchAll(FEEDBACK_TAG)) {
25
+ const [tag, closing, , attrs = '', selfClosing] = match;
26
+ const start = match.index;
27
+ const end = start + tag.length;
28
+ if (closing) {
29
+ const element = open.pop();
30
+ if (!element)
31
+ continue;
32
+ element.closeStart = start;
33
+ element.closeEnd = end;
34
+ add(element);
35
+ }
36
+ else {
37
+ const element = { attrs, openStart: start, openEnd: end, closeStart: end, closeEnd: end, children: [] };
38
+ if (selfClosing)
39
+ add(element);
40
+ else
41
+ open.push(element);
42
+ }
43
+ }
44
+ return roots;
45
+ }
46
+ function isShown(element, outcomeValues) {
47
+ const outcomeId = readHtmlAttribute(element.attrs, 'outcomeIdentifier');
48
+ const feedbackId = readHtmlAttribute(element.attrs, 'identifier');
49
+ if (outcomeId === null || feedbackId === null)
50
+ return false;
51
+ return isShownByIdentifier(outcomeValues[outcomeId], feedbackId, readHtmlAttribute(element.attrs, 'showHide'));
52
+ }
53
+ /** A shown element's content as the plan renders it: nested feedback resolved, hidden feedback dropped. */
54
+ function shownContent(html, element, outcomeValues) {
55
+ let out = '';
56
+ let position = element.openEnd;
57
+ for (const child of element.children) {
58
+ out += html.slice(position, child.openStart);
59
+ position = child.closeEnd;
60
+ if (isShown(child, outcomeValues))
61
+ out += shownContent(html, child, outcomeValues);
62
+ }
63
+ return out + html.slice(position, element.closeStart);
64
+ }
65
+ /** Phrasing elements: their text runs on with the text around them ("<strong>sum</strong>." reads "sum."). */
66
+ const PHRASING_ELEMENTS = new Set([
67
+ 'a', 'abbr', 'b', 'bdi', 'bdo', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'font', 'i', 'ins', 'kbd',
68
+ 'label', 'mark', 'q', 'rb', 'rp', 'rt', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup',
69
+ 'time', 'u', 'var', 'wbr',
70
+ ]);
71
+ const NAMED_CHARACTERS = {
72
+ amp: '&',
73
+ lt: '<',
74
+ gt: '>',
75
+ quot: '"',
76
+ apos: "'",
77
+ nbsp: '\u00a0',
78
+ };
79
+ function decodeCharacterReferences(text) {
80
+ return text.replace(/&(#[xX][0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (reference, body) => {
81
+ if (body[0] !== '#')
82
+ return NAMED_CHARACTERS[body.toLowerCase()] ?? reference;
83
+ const code = body[1] === 'x' || body[1] === 'X' ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);
84
+ return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : reference;
85
+ });
86
+ }
87
+ /** HTML as a screen reader reads it: images by their alt text, inert content skipped, whitespace collapsed. */
88
+ function accessibleText(html) {
89
+ const text = html
90
+ .replace(/<!--[\s\S]*?-->/g, '')
91
+ .replace(/<(script|style|template|noscript)\b[^>]*>[\s\S]*?<\/\1\s*>/gi, ' ')
92
+ .replace(/<img\b[^>]*>/gi, (tag) => ` ${readHtmlAttribute(tag.slice(4, -1), 'alt') ?? ''} `)
93
+ .replace(/<\/?([a-zA-Z][\w:-]*)\b[^>]*>/g, (_tag, name) => (PHRASING_ELEMENTS.has(name.toLowerCase()) ? '' : ' '))
94
+ .replace(/<[^>]*>/g, ' ');
95
+ // Character references are decoded last, so an encoded `&lt;` is never mistaken for markup.
96
+ return decodeCharacterReferences(text).replace(/\s+/g, ' ').trim();
97
+ }
98
+ /** Content that renders something: any text or element, comments aside. */
99
+ function rendersSomething(html) {
100
+ return /\S/.test(html.replace(/<!--[\s\S]*?-->/g, ''));
101
+ }
102
+ /**
103
+ * The feedback that `outcomeValues` show in an item body, read as text in document order.
104
+ *
105
+ * Runs on the body HTML *before* the plan splices the feedback in, while every element still
106
+ * carries its `outcomeIdentifier` and `identifier`. Visibility follows the shared rule
107
+ * (`isShownByIdentifier`, including `showHide="hide"` and container membership). Nested feedback
108
+ * resolves inside shown feedback, and hidden feedback contributes nothing, not even what is
109
+ * nested inside it. Separate feedback elements are joined with a space.
110
+ */
111
+ export function extractShownFeedback(bodyHtml, outcomeValues, options = {}) {
112
+ if (!bodyHtml || options.hideAll)
113
+ return NOTHING_SHOWN;
114
+ const texts = [];
115
+ let shown = false;
116
+ for (const root of feedbackElements(bodyHtml)) {
117
+ if (!isShown(root, outcomeValues))
118
+ continue;
119
+ const content = shownContent(bodyHtml, root, outcomeValues);
120
+ if (!rendersSomething(content))
121
+ continue;
122
+ shown = true;
123
+ const text = accessibleText(options.transform ? options.transform(content) : content);
124
+ if (text)
125
+ texts.push(text);
126
+ }
127
+ return shown ? { shown, text: texts.join(' ') } : NOTHING_SHOWN;
128
+ }
129
+ /**
130
+ * Whether a session transition is the candidate's own attempt ending: a submit or end-attempt,
131
+ * which covers every attempt of an adaptive item, including an uncounted `countAttempt="false"`
132
+ * one. Feedback is the result of the attempt, so only an attempt announces it. Initial render and
133
+ * restore dispatch nothing. Review and scorer renders dispatch no attempt, because a scorer is
134
+ * excluded by role and an ended session refuses attempt commands. All of them therefore stay
135
+ * silent, however often they re-render.
136
+ */
137
+ export function isCandidateAttemptFeedback(transition, role) {
138
+ const { action } = transition.command;
139
+ return role === 'candidate' && (action === 'endAttempt' || action === 'submitAttempt');
140
+ }
141
+ /**
142
+ * The live-region text for `message`, given the text it holds now. Repeating identical text would
143
+ * leave the region unchanged, and assistive technology does not announce an unchanged region. A
144
+ * repeat therefore toggles a trailing zero-width space, which a screen reader does not read but
145
+ * which still changes the region. The interaction components use the same toggle for refusals.
146
+ */
147
+ export function nextFeedbackAnnouncement(previous, message) {
148
+ return previous === message ? `${message}\u200b` : message;
149
+ }
150
+ //# sourceMappingURL=feedbackAnnouncement.js.map