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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/README.md +33 -5
  2. package/dist/catalog/applyGlossaryTriggers.js +14 -2
  3. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  4. package/dist/catalog/catalogExtractor.js +2 -4
  5. package/dist/catalog/catalogExtractor.js.map +1 -1
  6. package/dist/catalog/sessionCatalog.d.ts +46 -0
  7. package/dist/catalog/sessionCatalog.js +87 -0
  8. package/dist/catalog/sessionCatalog.js.map +1 -0
  9. package/dist/components/utils/endAttempt.d.ts +16 -0
  10. package/dist/components/utils/endAttempt.js +28 -0
  11. package/dist/components/utils/endAttempt.js.map +1 -0
  12. package/dist/components/utils/focus.d.ts +19 -0
  13. package/dist/components/utils/focus.js +67 -0
  14. package/dist/components/utils/focus.js.map +1 -0
  15. package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
  16. package/dist/components/utils/itemBodyRenderer.js +177 -0
  17. package/dist/components/utils/itemBodyRenderer.js.map +1 -0
  18. package/dist/components/utils/sentenceContext.d.ts +6 -0
  19. package/dist/components/utils/sentenceContext.js +16 -0
  20. package/dist/components/utils/sentenceContext.js.map +1 -0
  21. package/dist/core/AssessmentItemDefinition.d.ts +20 -1
  22. package/dist/core/AssessmentItemDefinition.js +12 -31
  23. package/dist/core/AssessmentItemDefinition.js.map +1 -1
  24. package/dist/core/ComponentRegistry.d.ts +92 -0
  25. package/dist/core/ComponentRegistry.js +7 -1
  26. package/dist/core/ComponentRegistry.js.map +1 -1
  27. package/dist/core/ItemSession.d.ts +18 -1
  28. package/dist/core/ItemSession.js +79 -41
  29. package/dist/core/ItemSession.js.map +1 -1
  30. package/dist/core/Player.d.ts +118 -141
  31. package/dist/core/Player.js +387 -1233
  32. package/dist/core/Player.js.map +1 -1
  33. package/dist/core/compliance.d.ts +72 -0
  34. package/dist/core/compliance.js +147 -0
  35. package/dist/core/compliance.js.map +1 -0
  36. package/dist/core/declarations/declarationBuilder.d.ts +29 -0
  37. package/dist/core/declarations/declarationBuilder.js +284 -0
  38. package/dist/core/declarations/declarationBuilder.js.map +1 -0
  39. package/dist/core/declarations/declarationValues.d.ts +11 -0
  40. package/dist/core/declarations/declarationValues.js +168 -0
  41. package/dist/core/declarations/declarationValues.js.map +1 -0
  42. package/dist/core/matchGroups.d.ts +36 -0
  43. package/dist/core/matchGroups.js +100 -0
  44. package/dist/core/matchGroups.js.map +1 -0
  45. package/dist/core/nameMappers.d.ts +35 -0
  46. package/dist/core/nameMappers.js +47 -0
  47. package/dist/core/nameMappers.js.map +1 -0
  48. package/dist/core/parsingLimits.d.ts +4 -0
  49. package/dist/core/parsingLimits.js +5 -2
  50. package/dist/core/parsingLimits.js.map +1 -1
  51. package/dist/core/processing/responseProcessing.d.ts +88 -0
  52. package/dist/core/processing/responseProcessing.js +317 -0
  53. package/dist/core/processing/responseProcessing.js.map +1 -0
  54. package/dist/core/processing/responseValidation.d.ts +55 -0
  55. package/dist/core/processing/responseValidation.js +335 -0
  56. package/dist/core/processing/responseValidation.js.map +1 -0
  57. package/dist/core/rendering/contentPass.d.ts +31 -0
  58. package/dist/core/rendering/contentPass.js +152 -0
  59. package/dist/core/rendering/contentPass.js.map +1 -0
  60. package/dist/core/rendering/htmlRender.d.ts +21 -0
  61. package/dist/core/rendering/htmlRender.js +56 -0
  62. package/dist/core/rendering/htmlRender.js.map +1 -0
  63. package/dist/core/responseProcessingTemplates.d.ts +23 -0
  64. package/dist/core/responseProcessingTemplates.js +45 -0
  65. package/dist/core/responseProcessingTemplates.js.map +1 -0
  66. package/dist/core/rolePolicy.d.ts +5 -0
  67. package/dist/core/rolePolicy.js +21 -0
  68. package/dist/core/rolePolicy.js.map +1 -1
  69. package/dist/core/sanitizer.js +8 -14
  70. package/dist/core/sanitizer.js.map +1 -1
  71. package/dist/core/serialization/sessionState.d.ts +56 -0
  72. package/dist/core/serialization/sessionState.js +139 -0
  73. package/dist/core/serialization/sessionState.js.map +1 -0
  74. package/dist/core/serialization/valueForms.d.ts +32 -0
  75. package/dist/core/serialization/valueForms.js +112 -0
  76. package/dist/core/serialization/valueForms.js.map +1 -0
  77. package/dist/document/AssessmentItemDocument.d.ts +27 -1
  78. package/dist/document/AssessmentItemDocument.js +67 -31
  79. package/dist/document/AssessmentItemDocument.js.map +1 -1
  80. package/dist/element-class-BbF4Dj7F.js +3773 -0
  81. package/dist/element-class-BbF4Dj7F.js.map +1 -0
  82. package/dist/element-class.d.ts +34 -1
  83. package/dist/element-class.js +1 -1
  84. package/dist/element.js +1 -1
  85. package/dist/extraction/ExtractionRegistry.js +6 -12
  86. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  87. package/dist/extraction/createContext.d.ts +2 -2
  88. package/dist/extraction/createContext.js.map +1 -1
  89. package/dist/extraction/index.d.ts +2 -2
  90. package/dist/extraction/index.js +1 -1
  91. package/dist/extraction/index.js.map +1 -1
  92. package/dist/extraction/interactionCoverage.d.ts +31 -0
  93. package/dist/extraction/interactionCoverage.js +40 -0
  94. package/dist/extraction/interactionCoverage.js.map +1 -0
  95. package/dist/extraction/interactionExtractionPipeline.js +5 -10
  96. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  97. package/dist/extraction/interactionSecurity.js +1 -28
  98. package/dist/extraction/interactionSecurity.js.map +1 -1
  99. package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
  100. package/dist/extraction/mergeDeliveryFields.js +17 -0
  101. package/dist/extraction/mergeDeliveryFields.js.map +1 -0
  102. package/dist/extraction/responseIdentifier.d.ts +19 -0
  103. package/dist/extraction/responseIdentifier.js +29 -0
  104. package/dist/extraction/responseIdentifier.js.map +1 -0
  105. package/dist/extraction/types.d.ts +11 -18
  106. package/dist/extraction/types.js +0 -12
  107. package/dist/extraction/types.js.map +1 -1
  108. package/dist/extraction/utils.d.ts +14 -0
  109. package/dist/extraction/utils.js +35 -5
  110. package/dist/extraction/utils.js.map +1 -1
  111. package/dist/index.d.ts +16 -10
  112. package/dist/index.js +19 -8
  113. package/dist/index.js.map +1 -1
  114. package/dist/interactions/associate/extractor.d.ts +1 -0
  115. package/dist/interactions/associate/extractor.js +10 -12
  116. package/dist/interactions/associate/extractor.js.map +1 -1
  117. package/dist/interactions/choice/extractor.js +6 -13
  118. package/dist/interactions/choice/extractor.js.map +1 -1
  119. package/dist/interactions/drawing/extractor.d.ts +6 -0
  120. package/dist/interactions/drawing/extractor.js +30 -9
  121. package/dist/interactions/drawing/extractor.js.map +1 -1
  122. package/dist/interactions/end-attempt/extractor.js +2 -1
  123. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  124. package/dist/interactions/extended-text/extractor.d.ts +6 -1
  125. package/dist/interactions/extended-text/extractor.js +10 -5
  126. package/dist/interactions/extended-text/extractor.js.map +1 -1
  127. package/dist/interactions/extended-text/response.js +18 -18
  128. package/dist/interactions/extended-text/response.js.map +1 -1
  129. package/dist/interactions/gap-match/extractor.d.ts +40 -2
  130. package/dist/interactions/gap-match/extractor.js +197 -39
  131. package/dist/interactions/gap-match/extractor.js.map +1 -1
  132. package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
  133. package/dist/interactions/graphic-associate/extractor.js +35 -24
  134. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  135. package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
  136. package/dist/interactions/graphic-gap-match/extractor.js +79 -43
  137. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  138. package/dist/interactions/graphic-order/extractor.d.ts +15 -0
  139. package/dist/interactions/graphic-order/extractor.js +39 -24
  140. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  141. package/dist/interactions/hotspot/extractor.d.ts +6 -0
  142. package/dist/interactions/hotspot/extractor.js +31 -16
  143. package/dist/interactions/hotspot/extractor.js.map +1 -1
  144. package/dist/interactions/hottext/extractor.js +2 -12
  145. package/dist/interactions/hottext/extractor.js.map +1 -1
  146. package/dist/interactions/inline/accessibleName.d.ts +29 -0
  147. package/dist/interactions/inline/accessibleName.js +35 -0
  148. package/dist/interactions/inline/accessibleName.js.map +1 -0
  149. package/dist/interactions/inline/render-plan.d.ts +5 -14
  150. package/dist/interactions/inline/render-plan.js +5 -56
  151. package/dist/interactions/inline/render-plan.js.map +1 -1
  152. package/dist/interactions/inline-choice/extractor.d.ts +4 -0
  153. package/dist/interactions/inline-choice/extractor.js +13 -12
  154. package/dist/interactions/inline-choice/extractor.js.map +1 -1
  155. package/dist/interactions/match/extractor.d.ts +2 -0
  156. package/dist/interactions/match/extractor.js +14 -28
  157. package/dist/interactions/match/extractor.js.map +1 -1
  158. package/dist/interactions/media/extractor.d.ts +5 -11
  159. package/dist/interactions/media/extractor.js +100 -36
  160. package/dist/interactions/media/extractor.js.map +1 -1
  161. package/dist/interactions/modules.js +8 -2
  162. package/dist/interactions/modules.js.map +1 -1
  163. package/dist/interactions/order/extractor.d.ts +2 -0
  164. package/dist/interactions/order/extractor.js +8 -12
  165. package/dist/interactions/order/extractor.js.map +1 -1
  166. package/dist/interactions/order/limits.d.ts +29 -0
  167. package/dist/interactions/order/limits.js +28 -0
  168. package/dist/interactions/order/limits.js.map +1 -0
  169. package/dist/interactions/portable-custom/extractor.js +4 -2
  170. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  171. package/dist/interactions/position-object/extractor.d.ts +18 -1
  172. package/dist/interactions/position-object/extractor.js +81 -22
  173. package/dist/interactions/position-object/extractor.js.map +1 -1
  174. package/dist/interactions/select-point/extractor.d.ts +6 -0
  175. package/dist/interactions/select-point/extractor.js +31 -19
  176. package/dist/interactions/select-point/extractor.js.map +1 -1
  177. package/dist/interactions/shared/imageAlt.d.ts +54 -0
  178. package/dist/interactions/shared/imageAlt.js +84 -0
  179. package/dist/interactions/shared/imageAlt.js.map +1 -0
  180. package/dist/interactions/shared/interactionImage.d.ts +32 -0
  181. package/dist/interactions/shared/interactionImage.js +39 -0
  182. package/dist/interactions/shared/interactionImage.js.map +1 -0
  183. package/dist/interactions/shared/specDefaults.d.ts +20 -0
  184. package/dist/interactions/shared/specDefaults.js +25 -0
  185. package/dist/interactions/shared/specDefaults.js.map +1 -0
  186. package/dist/interactions/shared/types.d.ts +212 -40
  187. package/dist/interactions/shared/types.js.map +1 -1
  188. package/dist/interactions/text-entry/extractor.d.ts +9 -0
  189. package/dist/interactions/text-entry/extractor.js +9 -0
  190. package/dist/interactions/text-entry/extractor.js.map +1 -1
  191. package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
  192. package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
  193. package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
  194. package/dist/interactions/text-entry/inputMode.d.ts +35 -0
  195. package/dist/interactions/text-entry/inputMode.js +134 -0
  196. package/dist/interactions/text-entry/inputMode.js.map +1 -0
  197. package/dist/interactions/text-entry/response.d.ts +15 -0
  198. package/dist/interactions/text-entry/response.js +25 -0
  199. package/dist/interactions/text-entry/response.js.map +1 -0
  200. package/dist/interactions/upload/extractor.js +2 -2
  201. package/dist/interactions/upload/extractor.js.map +1 -1
  202. package/dist/pci/PciHost.d.ts +1 -1
  203. package/dist/pci/PciHost.js +11 -11
  204. package/dist/pci/PciHost.js.map +1 -1
  205. package/dist/pci/index.d.ts +1 -0
  206. package/dist/pci/index.js.map +1 -1
  207. package/dist/pci/modulePaths.d.ts +16 -0
  208. package/dist/pci/modulePaths.js +33 -0
  209. package/dist/pci/modulePaths.js.map +1 -0
  210. package/dist/pci/pageRealmSession.js +3 -15
  211. package/dist/pci/pageRealmSession.js.map +1 -1
  212. package/dist/pci/qtiVariableJson.d.ts +46 -3
  213. package/dist/pci/qtiVariableJson.js +247 -53
  214. package/dist/pci/qtiVariableJson.js.map +1 -1
  215. package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
  216. package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
  217. package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
  218. package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
  219. package/dist/pci/sandbox/iframeConnector.js +35 -6
  220. package/dist/pci/sandbox/iframeConnector.js.map +1 -1
  221. package/dist/pci/sandbox/protocol.d.ts +14 -0
  222. package/dist/pci/sandbox/protocol.js.map +1 -1
  223. package/dist/pci/sessionHosts.d.ts +47 -0
  224. package/dist/pci/sessionHosts.js +66 -0
  225. package/dist/pci/sessionHosts.js.map +1 -0
  226. package/dist/pci/types.d.ts +7 -1
  227. package/dist/pci/types.js.map +1 -1
  228. package/dist/pnp/applyPnp.d.ts +20 -3
  229. package/dist/pnp/applyPnp.js +84 -9
  230. package/dist/pnp/applyPnp.js.map +1 -1
  231. package/dist/pnp/parsePnpXml.js +2 -0
  232. package/dist/pnp/parsePnpXml.js.map +1 -1
  233. package/dist/pnp/types.d.ts +16 -8
  234. package/dist/pnp/types.js.map +1 -1
  235. package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
  236. package/dist/presentation/feedbackAnnouncement.js +150 -0
  237. package/dist/presentation/feedbackAnnouncement.js.map +1 -0
  238. package/dist/presentation/interactionSlots.d.ts +31 -0
  239. package/dist/presentation/interactionSlots.js +101 -0
  240. package/dist/presentation/interactionSlots.js.map +1 -0
  241. package/dist/presentation/itemPresentationPlan.d.ts +69 -6
  242. package/dist/presentation/itemPresentationPlan.js +93 -81
  243. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  244. package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
  245. package/dist/presentation/stimulusRender.js.map +1 -0
  246. package/dist/presentation/stylesheetRender.js.map +1 -0
  247. package/dist/security/escapeHtml.d.ts +15 -0
  248. package/dist/security/escapeHtml.js +22 -0
  249. package/dist/security/escapeHtml.js.map +1 -0
  250. package/dist/security/index.d.ts +1 -0
  251. package/dist/security/index.js +1 -0
  252. package/dist/security/index.js.map +1 -1
  253. package/dist/server.d.ts +8 -1
  254. package/dist/server.js.map +1 -1
  255. package/dist/session-inputs.d.ts +108 -0
  256. package/dist/session-inputs.js +130 -0
  257. package/dist/session-inputs.js.map +1 -0
  258. package/dist/types/index.d.ts +67 -35
  259. package/dist/types/index.js.map +1 -1
  260. package/dist/utils/cloneFreeze.d.ts +52 -0
  261. package/dist/utils/cloneFreeze.js +113 -0
  262. package/dist/utils/cloneFreeze.js.map +1 -0
  263. package/dist/utils/htmlAttributes.d.ts +13 -0
  264. package/dist/utils/htmlAttributes.js +22 -0
  265. package/dist/utils/htmlAttributes.js.map +1 -0
  266. package/dist/web-components/QTIInteractionElement.d.ts +0 -29
  267. package/dist/web-components/QTIInteractionElement.js +0 -32
  268. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  269. package/dist/web-components/index.d.ts +1 -2
  270. package/dist/web-components/index.js +2 -3
  271. package/dist/web-components/index.js.map +1 -1
  272. package/package.json +15 -14
  273. package/dist/components/utils/stimulusRender.js.map +0 -1
  274. package/dist/components/utils/stylesheetRender.js.map +0 -1
  275. package/dist/core/constants.d.ts +0 -65
  276. package/dist/core/constants.js +0 -74
  277. package/dist/core/constants.js.map +0 -1
  278. package/dist/element-class-DdpiTalY.js +0 -9226
  279. package/dist/element-class-DdpiTalY.js.map +0 -1
  280. package/dist/extensions/MathLiveEditor.d.ts +0 -31
  281. package/dist/extensions/MathLiveEditor.js +0 -248
  282. package/dist/extensions/MathLiveEditor.js.map +0 -1
  283. package/dist/utils/PerformanceMonitor.d.ts +0 -169
  284. package/dist/utils/PerformanceMonitor.js +0 -243
  285. package/dist/utils/PerformanceMonitor.js.map +0 -1
  286. package/dist/utils/responseUtils.d.ts +0 -15
  287. package/dist/utils/responseUtils.js +0 -46
  288. package/dist/utils/responseUtils.js.map +0 -1
  289. package/dist/web-components/QTIInteractionBase.d.ts +0 -119
  290. package/dist/web-components/QTIInteractionBase.js +0 -244
  291. package/dist/web-components/QTIInteractionBase.js.map +0 -1
  292. /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
  293. /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
  294. /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The canonical descriptor of the definition-fixed session inputs of
3
+ * `<pie-qti-item-player>` and the `ItemPlayer` component.
4
+ *
5
+ * A change to any input listed here re-opens the item session the player owns; every
6
+ * other property write — disabled, i18n, typeset, responses, a no-op — must leave the
7
+ * session alone. Two implementations must agree on this list, so both consume this
8
+ * descriptor and nothing else may maintain it:
9
+ *
10
+ * - `element-class.ts`: each input's setter stores through `SESSION_INPUTS[key].store`
11
+ * and retires the owned session when `SESSION_INPUTS[key].changed` reports a new
12
+ * definition.
13
+ * - `components/ItemPlayer.svelte`: each input has an equality-guarded `$derived`
14
+ * normalizing the prop through `SESSION_INPUTS[key].sessionValue` (the
15
+ * `sessionInputGuards` map there names them), so no-op writes never re-run the
16
+ * session effect.
17
+ *
18
+ * Svelte's `$derived` expressions cannot be generated at runtime, so the component
19
+ * side is written out by hand; the `sessionInputGuards` map pins it to this
20
+ * descriptor at compile time, and
21
+ * `tests/component/element-session-stability.vitest.ts` enforces the lockstep
22
+ * behaviorally by flipping every input here against the mounted element and watching
23
+ * the session. A definition-fixed input is added in this file and on both sides —
24
+ * nowhere else.
25
+ */
26
+ import { parseQtiRole } from './core/rolePolicy.js';
27
+ // The role list and its parser live in core/rolePolicy.ts — the one copy every
28
+ // player element shares.
29
+ /** Shallow list equality, so re-assigning an equal list is not a new definition. */
30
+ function sameList(a, b) {
31
+ if (a === b)
32
+ return true;
33
+ if (!a || !b || a.length !== b.length)
34
+ return false;
35
+ return a.every((entry, index) => entry === b[index]);
36
+ }
37
+ /** Shallow record equality for flat option objects. */
38
+ function sameRecord(a, b) {
39
+ if (a === b)
40
+ return true;
41
+ if (!a || !b)
42
+ return false;
43
+ const keys = Object.keys(a);
44
+ return (keys.length === Object.keys(b).length &&
45
+ keys.every((key) => a[key] === b[key]));
46
+ }
47
+ /**
48
+ * The definition-fixed session inputs, keyed by property name. The semantics entries
49
+ * carry the per-input change decisions both consuming sides share:
50
+ *
51
+ * - Reference inputs (`security`, `pnp`, `deliveryContext`, `pci`,
52
+ * `resolveProcessingFragment`, `processingFragmentLimits`): any newly created
53
+ * object, array or function the host assigns is a new definition.
54
+ * - `itemXml`: the empty string and `undefined` are the same definition (no item).
55
+ * - `role`: parsed first — unknown values render as `candidate` — so two unknown
56
+ * values are one definition.
57
+ * - `stringComparison` and `plugins`: equal option records / plugin lists stored as a
58
+ * frozen copy keep the session; only different content is a new definition.
59
+ * - `showFeedback` / `showSolution`: `undefined` and `false` are the same policy, so
60
+ * the guard compares `?? false` on both sides.
61
+ */
62
+ export const SESSION_INPUTS = {
63
+ itemXml: {
64
+ store: (value) => value ?? '',
65
+ changed: (previous, next) => previous !== next,
66
+ sessionValue: (value) => value,
67
+ },
68
+ role: {
69
+ store: (value) => parseQtiRole(value ?? undefined),
70
+ changed: (previous, next) => previous !== next,
71
+ sessionValue: (value) => value,
72
+ },
73
+ security: {
74
+ store: (value) => value,
75
+ changed: (previous, next) => previous !== next,
76
+ sessionValue: (value) => value,
77
+ },
78
+ pnp: {
79
+ store: (value) => value,
80
+ changed: (previous, next) => previous !== next,
81
+ sessionValue: (value) => value,
82
+ },
83
+ deliveryContext: {
84
+ store: (value) => value,
85
+ changed: (previous, next) => previous !== next,
86
+ sessionValue: (value) => value,
87
+ },
88
+ resolveProcessingFragment: {
89
+ store: (value) => value,
90
+ changed: (previous, next) => previous !== next,
91
+ sessionValue: (value) => value,
92
+ },
93
+ processingFragmentLimits: {
94
+ store: (value) => value,
95
+ changed: (previous, next) => previous !== next,
96
+ sessionValue: (value) => value,
97
+ },
98
+ pci: {
99
+ store: (value) => value,
100
+ changed: (previous, next) => previous !== next,
101
+ sessionValue: (value) => value,
102
+ },
103
+ stringComparison: {
104
+ // Keep the frozen copy when the options are unchanged: a re-assigned equal object
105
+ // is not a new definition and must not re-open the session.
106
+ store: (value) => (value ? Object.freeze({ ...value }) : undefined),
107
+ changed: (previous, next) => !sameRecord(previous, next),
108
+ sessionValue: (value) => value,
109
+ },
110
+ plugins: {
111
+ // Keep the frozen copy when the same plugins are re-assigned: an equal list is not
112
+ // a new definition and must not re-open the session.
113
+ store: (value) => (value ? Object.freeze([...value]) : undefined),
114
+ changed: (previous, next) => !sameList(previous, next),
115
+ sessionValue: (value) => value,
116
+ },
117
+ showFeedback: {
118
+ store: (value) => value,
119
+ changed: (previous, next) => (previous ?? false) !== (next ?? false),
120
+ sessionValue: (value) => value ?? false,
121
+ },
122
+ showSolution: {
123
+ store: (value) => value,
124
+ changed: (previous, next) => (previous ?? false) !== (next ?? false),
125
+ sessionValue: (value) => value ?? false,
126
+ },
127
+ };
128
+ /** The definition-fixed session inputs as a stable, iterable list of property names. */
129
+ export const SESSION_INPUT_KEYS = Object.keys(SESSION_INPUTS);
130
+ //# sourceMappingURL=session-inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-inputs.js","sourceRoot":"","sources":["../src/session-inputs.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * The canonical descriptor of the definition-fixed session inputs of\n * `<pie-qti-item-player>` and the `ItemPlayer` component.\n *\n * A change to any input listed here re-opens the item session the player owns; every\n * other property write — disabled, i18n, typeset, responses, a no-op — must leave the\n * session alone. Two implementations must agree on this list, so both consume this\n * descriptor and nothing else may maintain it:\n *\n * - `element-class.ts`: each input's setter stores through `SESSION_INPUTS[key].store`\n * and retires the owned session when `SESSION_INPUTS[key].changed` reports a new\n * definition.\n * - `components/ItemPlayer.svelte`: each input has an equality-guarded `$derived`\n * normalizing the prop through `SESSION_INPUTS[key].sessionValue` (the\n * `sessionInputGuards` map there names them), so no-op writes never re-run the\n * session effect.\n *\n * Svelte's `$derived` expressions cannot be generated at runtime, so the component\n * side is written out by hand; the `sessionInputGuards` map pins it to this\n * descriptor at compile time, and\n * `tests/component/element-session-stability.vitest.ts` enforces the lockstep\n * behaviorally by flipping every input here against the mounted element and watching\n * the session. A definition-fixed input is added in this file and on both sides —\n * nowhere else.\n */\n\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { ProcessingFragmentResolver } from '@pie-qti/qti-processing';\nimport type {\n\tAssessmentItemDefinitionConfig,\n\tAssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nimport { parseQtiRole } from './core/rolePolicy.js';\nimport type { PnpProfile } from './pnp/types.js';\nimport type { PlayerSecurityConfig, QTIRole } from './types/index.js';\n\n/** The stored shape of each session input, as the element's getters report it. */\nexport interface SessionInputValues {\n\titemXml: string;\n\trole: QTIRole;\n\tsecurity: PlayerSecurityConfig | undefined;\n\tpnp: PnpProfile | undefined;\n\tdeliveryContext: ResolvedItemDeliveryContext | undefined;\n\tresolveProcessingFragment: AssessmentItemDefinitionConfig['resolveProcessingFragment'];\n\tprocessingFragmentLimits: AssessmentItemDefinitionConfig['processingFragmentLimits'];\n\tpci: AssessmentItemDefinitionConfig['pci'];\n\tstringComparison: AssessmentItemDefinitionConfig['stringComparison'];\n\tplugins: readonly AssessmentItemDefinitionPlugin[] | undefined;\n\tshowFeedback: boolean | undefined;\n\tshowSolution: boolean | undefined;\n}\n\n/** The value shapes the element's setters accept, before `store` normalizes them. */\nexport interface SessionInputRawValues {\n\titemXml: string | undefined;\n\trole: QTIRole | null;\n\tsecurity: PlayerSecurityConfig | undefined;\n\tpnp: PnpProfile | undefined;\n\tdeliveryContext: ResolvedItemDeliveryContext | undefined;\n\tresolveProcessingFragment: AssessmentItemDefinitionConfig['resolveProcessingFragment'];\n\tprocessingFragmentLimits: AssessmentItemDefinitionConfig['processingFragmentLimits'];\n\tpci: AssessmentItemDefinitionConfig['pci'];\n\tstringComparison: AssessmentItemDefinitionConfig['stringComparison'];\n\tplugins: readonly AssessmentItemDefinitionPlugin[] | undefined;\n\tshowFeedback: boolean | undefined;\n\tshowSolution: boolean | undefined;\n}\n\nexport type SessionInputKey = keyof SessionInputValues;\nexport type SessionInputValue<K extends SessionInputKey> = SessionInputValues[K];\nexport type SessionInputRaw<K extends SessionInputKey> = SessionInputRawValues[K];\n\n/**\n * The values the player's session-guard deriveds yield. They narrow the stored value\n * where the session only consumes a normalized form: the standalone session applies\n * `showFeedback` / `showSolution` as QTI `itemSessionControl` does, where `undefined`\n * and `false` are the same policy, so the guarded value is a plain `boolean`.\n */\nexport type SessionInputGuardValues = {\n\t[K in Exclude<SessionInputKey, 'showFeedback' | 'showSolution'>]: SessionInputValues[K];\n} & {\n\tshowFeedback: boolean;\n\tshowSolution: boolean;\n};\n\n/**\n * The change semantics of one definition-fixed input. `store` normalizes an incoming\n * value so equal definitions are stored identically where possible; `changed` decides\n * whether a stored value and a stored next value are different definitions (retire /\n * re-open) or the same one (keep the session); `sessionValue` is the value the\n * component's session-guard derived yields, which must be identical across no-op\n * writes so the session effect does not re-run.\n */\nexport interface SessionInputSemantics<TValue, TRaw, TGuarded = TValue> {\n\tstore(value: TRaw): TValue;\n\tchanged(previous: TValue, next: TValue): boolean;\n\tsessionValue(value: TValue): TGuarded;\n}\n\nexport type SessionInputDescriptor = {\n\t[K in SessionInputKey]: SessionInputSemantics<\n\t\tSessionInputValues[K],\n\t\tSessionInputRawValues[K],\n\t\tSessionInputGuardValues[K]\n\t>;\n};\n\n// The role list and its parser live in core/rolePolicy.ts — the one copy every\n// player element shares.\n\n/** Shallow list equality, so re-assigning an equal list is not a new definition. */\nfunction sameList(a: readonly unknown[] | undefined, b: readonly unknown[] | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b || a.length !== b.length) return false;\n\treturn a.every((entry, index) => entry === b[index]);\n}\n\n/** Shallow record equality for flat option objects. */\nfunction sameRecord(a: object | undefined, b: object | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\tconst keys = Object.keys(a);\n\treturn (\n\t\tkeys.length === Object.keys(b).length &&\n\t\tkeys.every((key) => (a as Record<string, unknown>)[key] === (b as Record<string, unknown>)[key])\n\t);\n}\n\n/**\n * The definition-fixed session inputs, keyed by property name. The semantics entries\n * carry the per-input change decisions both consuming sides share:\n *\n * - Reference inputs (`security`, `pnp`, `deliveryContext`, `pci`,\n * `resolveProcessingFragment`, `processingFragmentLimits`): any newly created\n * object, array or function the host assigns is a new definition.\n * - `itemXml`: the empty string and `undefined` are the same definition (no item).\n * - `role`: parsed first — unknown values render as `candidate` — so two unknown\n * values are one definition.\n * - `stringComparison` and `plugins`: equal option records / plugin lists stored as a\n * frozen copy keep the session; only different content is a new definition.\n * - `showFeedback` / `showSolution`: `undefined` and `false` are the same policy, so\n * the guard compares `?? false` on both sides.\n */\nexport const SESSION_INPUTS: SessionInputDescriptor = {\n\titemXml: {\n\t\tstore: (value) => value ?? '',\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\trole: {\n\t\tstore: (value) => parseQtiRole(value ?? undefined),\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tsecurity: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tpnp: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tdeliveryContext: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tresolveProcessingFragment: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tprocessingFragmentLimits: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tpci: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => previous !== next,\n\t\tsessionValue: (value) => value,\n\t},\n\tstringComparison: {\n\t\t// Keep the frozen copy when the options are unchanged: a re-assigned equal object\n\t\t// is not a new definition and must not re-open the session.\n\t\tstore: (value) => (value ? Object.freeze({ ...value }) : undefined),\n\t\tchanged: (previous, next) => !sameRecord(previous, next),\n\t\tsessionValue: (value) => value,\n\t},\n\tplugins: {\n\t\t// Keep the frozen copy when the same plugins are re-assigned: an equal list is not\n\t\t// a new definition and must not re-open the session.\n\t\tstore: (value) => (value ? Object.freeze([...value]) : undefined),\n\t\tchanged: (previous, next) => !sameList(previous, next),\n\t\tsessionValue: (value) => value,\n\t},\n\tshowFeedback: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => (previous ?? false) !== (next ?? false),\n\t\tsessionValue: (value) => value ?? false,\n\t},\n\tshowSolution: {\n\t\tstore: (value) => value,\n\t\tchanged: (previous, next) => (previous ?? false) !== (next ?? false),\n\t\tsessionValue: (value) => value ?? false,\n\t},\n};\n\n/** The definition-fixed session inputs as a stable, iterable list of property names. */\nexport const SESSION_INPUT_KEYS = Object.keys(SESSION_INPUTS) as SessionInputKey[];\n"]}
@@ -27,11 +27,6 @@ export interface Mapping {
27
27
  defaultValue?: number;
28
28
  lowerBound?: number;
29
29
  upperBound?: number;
30
- /**
31
- * QTI attribute on <mapping>. When "false", string mappings are case-insensitive by default.
32
- * Stored as raw string to match XML attribute values ("true"/"false").
33
- */
34
- caseSensitive?: string;
35
30
  entries: Record<string, MapEntry>;
36
31
  }
37
32
  export interface MapEntry {
@@ -53,14 +48,6 @@ export interface AreaMapEntry {
53
48
  export interface ResponseDeclaration extends VariableDeclaration {
54
49
  correctResponse?: any;
55
50
  }
56
- export interface OutcomeDeclaration extends VariableDeclaration {
57
- interpretation?: string;
58
- longInterpretation?: string;
59
- normalMaximum?: number;
60
- normalMinimum?: number;
61
- masteryValue?: number;
62
- views?: string[];
63
- }
64
51
  export type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';
65
52
  export type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';
66
53
  export interface SerializedItemSessionVariable {
@@ -70,7 +57,23 @@ export interface SerializedItemSessionVariable {
70
57
  baseType?: VariableBaseType;
71
58
  cardinality: VariableCardinality;
72
59
  value: any;
73
- defaultValue?: any;
60
+ /**
61
+ * The variable's default value for this session, which a setDefaultValue
62
+ * template rule can change (QTI 2.1 ASI §8 / QTI 3.0 ASI §10: template-rule
63
+ * effects are fixed for the session); null when the variable has no default
64
+ * value. Restore applies it as-is, so null restores a NULL default rather
65
+ * than the default parsed from the item XML.
66
+ */
67
+ defaultValue: any;
68
+ /**
69
+ * The response declaration's correct response for this session, including one
70
+ * computed by a setCorrectResponse template rule (QTI 2.1 ASI §8 / QTI 3.0 ASI
71
+ * §10: template-rule effects are fixed for the session). Present on every
72
+ * response variable that has or had a correct response, with null meaning the
73
+ * correct response is NULL; absent when the variable has no correct response.
74
+ * Restore applies it as-is when present.
75
+ */
76
+ correctResponse?: any;
74
77
  }
75
78
  export interface SerializedItemSessionState {
76
79
  itemIdentifier?: string;
@@ -79,7 +82,8 @@ export interface SerializedItemSessionState {
79
82
  completionStatus: CompletionStatus;
80
83
  numAttempts: number;
81
84
  /**
82
- * Time-on-task in milliseconds, stored as the QTI built-in duration variable value.
85
+ * Time on task in milliseconds. The QTI built-in `duration` variable (in
86
+ * `contextVariables.duration`) holds the same time in seconds, as QTI defines it.
83
87
  */
84
88
  duration: number;
85
89
  responseVariables: Record<string, SerializedItemSessionVariable>;
@@ -110,6 +114,7 @@ export interface ItemSessionActionResult {
110
114
  lifecycleStatus: ItemLifecycleStatus;
111
115
  completionStatus: CompletionStatus;
112
116
  numAttempts: number;
117
+ /** Time on task in milliseconds; the QTI `duration` variable holds it in seconds. */
113
118
  duration: number;
114
119
  completed: boolean;
115
120
  sessionState: SerializedItemSessionState;
@@ -188,6 +193,29 @@ export interface AdaptiveAttemptResult extends ScoringResult {
188
193
  * policy layered on top of these roles.
189
194
  */
190
195
  export type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';
196
+ /**
197
+ * Why an item player reported a failure, as `error.code`. The `message` is raw engine or
198
+ * parser text for host logs only — never render it to candidates.
199
+ */
200
+ export type ItemPlayerErrorCode = 'item-load-failed' | 'response-processing-failed' | 'response-dispatch-failed' | 'submission-failed' | 'render-failed';
201
+ /** A player failure as hosts receive it: a stable `code`, the raw `message`, and the item when known. */
202
+ export interface ItemPlayerErrorDetail {
203
+ code: ItemPlayerErrorCode;
204
+ /** Raw message, for logs and host diagnostics — never render it to candidates. */
205
+ message: string;
206
+ itemIdentifier?: string;
207
+ }
208
+ /**
209
+ * A failure the item body reports to its player: the stable `code` the element's
210
+ * `error` event carries, plus the raw cause for host logs. `render-failed` covers
211
+ * interaction mount/update and component-registry failures; the item keeps
212
+ * rendering with a visible placeholder for the failed interaction.
213
+ * `response-dispatch-failed` covers a rejected response write.
214
+ */
215
+ export interface ItemBodyError {
216
+ code: Extract<ItemPlayerErrorCode, 'render-failed' | 'response-dispatch-failed'>;
217
+ cause: unknown;
218
+ }
191
219
  export type RubricBlockScope = 'direct' | 'itemBody';
192
220
  export interface RubricBlock {
193
221
  view: string[];
@@ -196,15 +224,25 @@ export interface RubricBlock {
196
224
  use?: string;
197
225
  }
198
226
  /**
199
- * QTI specification compliance configuration.
200
- * Controls whether the player enforces strict QTI 2.2 spec or allows vendor extensions.
227
+ * QTI compliance checks run once, when the item compiles. They are not an XSD validator: they check
228
+ * the version's namespace, every element name against the XSD-verified QTI 2.2 / 3.0 vocabulary
229
+ * (unknown QTI-namespace elements, and unknown `qti-` elements in QTI 3.0), interactions whose
230
+ * `responseIdentifier` names no responseDeclaration, QTI interactions with no
231
+ * `responseIdentifier`, and response-bound elements no registered extractor renders.
232
+ *
233
+ * Findings are listed on `AssessmentItemDefinition.diagnostics`: warnings by default, errors in
234
+ * strict mode. An unsupported `responseProcessing@template` always fails compilation with an
235
+ * `UnsupportedResponseProcessingTemplateError`, strict or not.
201
236
  */
202
237
  export interface QTIComplianceConfig {
203
- /** Enable strict QTI 2.2 compliance mode. Default: false (lenient) */
238
+ /**
239
+ * Strict mode: findings are errors, and items in versions other than QTI 2.2 and 3.0 (the
240
+ * certifiable versions) are findings too. Default: false (findings are warnings).
241
+ */
204
242
  enabled?: boolean;
205
- /** Reject items with unknown or non-standard elements. Default: false */
243
+ /** In strict mode, throw a `QtiComplianceError` listing every finding instead of compiling. Default: false */
206
244
  rejectUnknownExtensions?: boolean;
207
- /** Log warnings for spec deviations and vendor extensions. Default: true */
245
+ /** Write findings to the console (errors in strict mode, warnings otherwise). Default: true */
208
246
  logDeviations?: boolean;
209
247
  }
210
248
  export interface UrlPolicyConfig {
@@ -247,8 +285,8 @@ export interface PlayerSecurityConfig {
247
285
  /** Allow <iframe> usage (default false) */
248
286
  allowIframes?: boolean;
249
287
  /**
250
- * Optional parsing/processing guardrails to reduce DoS risk from untrusted QTI.
251
- * Disabled by default for compatibility.
288
+ * Parsing/processing guardrails that reduce DoS risk from untrusted QTI. On by default;
289
+ * `parsingLimits.enabled: false` opts out.
252
290
  */
253
291
  parsingLimits?: ParsingLimitsConfig;
254
292
  /**
@@ -261,36 +299,30 @@ export interface PlayerSecurityConfig {
261
299
  }
262
300
  export interface ParsingLimitsConfig {
263
301
  /**
264
- * Enables parsing limits. When false/undefined, the player behaves exactly as before (compat default).
302
+ * The limits apply unless this is `false`. Opt out only for trusted content that needs more
303
+ * than the limits allow (or a DOCTYPE), never to accept untrusted QTI.
265
304
  */
266
305
  enabled?: boolean;
267
306
  /**
268
- * Reject any XML containing <!DOCTYPE ...> (case-insensitive) when enabled.
307
+ * Reject any XML containing <!DOCTYPE ...> (case-insensitive). Default true.
269
308
  * Helps reduce entity-expansion and other parser edge-case risks.
270
309
  */
271
310
  rejectDoctype?: boolean;
272
311
  /**
273
- * Maximum bytes for `itemXml` input (UTF-8). Enforced when enabled.
312
+ * Maximum bytes for `itemXml` input (UTF-8). Default 10,000,000.
274
313
  */
275
314
  maxItemXmlBytes?: number;
276
315
  /**
277
- * Maximum bytes for HTML strings passed to sanitizer (UTF-8). Enforced when enabled.
316
+ * Maximum bytes for HTML strings passed to the sanitizer (UTF-8). Default 5,000,000.
278
317
  */
279
318
  maxHtmlBytes?: number;
280
319
  /**
281
- * Maximum number of element nodes sanitized per HTML input. Enforced when enabled.
320
+ * Maximum number of element nodes sanitized per HTML input. Default 200,000.
282
321
  */
283
322
  maxHtmlNodes?: number;
284
323
  /**
285
- * Maximum element depth sanitized per HTML input. Enforced when enabled.
324
+ * Maximum element depth sanitized per HTML input. Default 200.
286
325
  */
287
326
  maxHtmlDepth?: number;
288
327
  }
289
- export interface InteractionContext {
290
- responseIdentifier: string;
291
- maxChoices?: number;
292
- minChoices?: number;
293
- shuffle?: boolean;
294
- orientation?: 'horizontal' | 'vertical';
295
- }
296
328
  export * from './responseValidation.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgcH,cAAc,yBAAyB,CAAC","sourcesContent":["/**\n * Core QTI types for the player\n */\n\nimport type {\n\tBaseType as ProcessingBaseType,\n\tCardinality as ProcessingCardinality,\n\tProcessingFragmentResolver,\n\tQtiValue,\n} from '@pie-qti/qti-processing';\nimport type {\n\tAttributeNameMapper,\n\tElementNameMapper,\n} from '@pie-qti/qti-common';\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { ComponentRegistry } from '../core/ComponentRegistry.js';\nimport type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';\nimport type { ResponseValidationResult } from './responseValidation.js';\n\n/**\n * QTI base type identifier\n * Extensible string type allows custom base types\n */\nexport type VariableBaseType = ProcessingBaseType;\n\n/**\n * QTI cardinality identifier\n * Extensible string type allows custom cardinality values\n */\nexport type VariableCardinality = ProcessingCardinality;\n\nexport interface VariableDeclaration {\n\tidentifier: string;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n\tmapping?: Mapping;\n\tareaMapping?: AreaMapping;\n}\n\nexport interface Mapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\t/**\n\t * QTI attribute on <mapping>. When \"false\", string mappings are case-insensitive by default.\n\t * Stored as raw string to match XML attribute values (\"true\"/\"false\").\n\t */\n\tcaseSensitive?: string;\n\tentries: Record<string, MapEntry>;\n}\n\nexport interface MapEntry {\n\tmapKey: string;\n\tmappedValue: number;\n\tcaseSensitive?: string;\n}\n\nexport interface AreaMapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\tentries: AreaMapEntry[];\n}\n\nexport interface AreaMapEntry {\n\tshape: 'circle' | 'rect' | 'poly' | 'ellipse' | 'default';\n\tcoords: string;\n\tmappedValue: number;\n}\n\nexport interface ResponseDeclaration extends VariableDeclaration {\n\tcorrectResponse?: any;\n}\n\nexport interface OutcomeDeclaration extends VariableDeclaration {\n\tinterpretation?: string;\n\tlongInterpretation?: string;\n\tnormalMaximum?: number;\n\tnormalMinimum?: number;\n\tmasteryValue?: number;\n\tviews?: string[];\n}\n\n/** @internal Private engine snapshot shape; use SerializedItemSessionState. */\nexport interface ItemSessionState {\n\t[variableId: string]: any;\n}\n\nexport type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';\n\nexport type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';\n\nexport interface SerializedItemSessionVariable {\n\tidentifier: string;\n\tkind: SerializedVariableKind;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n}\n\nexport interface SerializedItemSessionState {\n\titemIdentifier?: string;\n\tsessionGuid: string;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\t/**\n\t * Time-on-task in milliseconds, stored as the QTI built-in duration variable value.\n\t */\n\tduration: number;\n\tresponseVariables: Record<string, SerializedItemSessionVariable>;\n\toutcomeVariables: Record<string, SerializedItemSessionVariable>;\n\ttemplateVariables: Record<string, SerializedItemSessionVariable>;\n\tcontextVariables: Record<string, SerializedItemSessionVariable>;\n\tvalidationMessages: ResponseValidationResult['issues'];\n\tsavedAt: string;\n}\n\nexport type ItemSessionAction =\n\t| 'suspendAttempt'\n\t| 'endAttempt'\n\t| 'scoreAttempt'\n\t| 'newTemplate'\n\t| 'submitAttempt';\n\nexport type ItemSessionActionCommand =\n\t| { action: 'suspendAttempt' }\n\t| { action: 'endAttempt'; countAttempt?: boolean; validateResponses?: boolean }\n\t| { action: 'scoreAttempt' }\n\t| { action: 'newTemplate'; resetResponses?: boolean }\n\t| { action: 'submitAttempt'; countAttempt?: boolean };\n\nexport interface ItemSessionActionResult {\n\taction: ItemSessionAction;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\tduration: number;\n\tcompleted: boolean;\n\tsessionState: SerializedItemSessionState;\n\tvalidation?: ResponseValidationResult;\n\tscoring?: ScoringResult;\n}\n\n/** @internal Private engine response map. */\nexport interface InteractionResponse {\n\t[responseId: string]: any;\n}\n\n/**\n * Serializable representation of a QTI baseType=\"file\" response.\n * (We cannot store a browser File object in session state / JSON exports.)\n */\nexport interface QTIFileResponse {\n\tname: string;\n\ttype: string;\n\tsize: number;\n\tlastModified: number;\n\t/** Base64 data URL, e.g. data:application/pdf;base64,... */\n\tdataUrl: string;\n\t/**\n\t * Optional ImageData extracted from canvas (for drawing interactions).\n\t * This allows custom operators to analyze drawing content synchronously\n\t * without needing to decode the dataUrl asynchronously.\n\t */\n\timageData?: {\n\t\tdata: Uint8ClampedArray;\n\t\twidth: number;\n\t\theight: number;\n\t};\n}\n\nexport interface ModalFeedback {\n\t/** Unique identifier for this feedback block */\n\tidentifier: string;\n\t/** Outcome variable identifier this feedback is tied to */\n\toutcomeIdentifier: string;\n\t/** When to show: 'show' means display when outcome matches identifier */\n\tshowHide: 'show' | 'hide';\n\t/** HTML content to display */\n\tcontent: HtmlContent;\n\t/** Optional title for the feedback */\n\ttitle?: string;\n}\n\nexport interface ScoringResult {\n\tscore: number;\n\tmaxScore: number;\n\tcompleted: boolean;\n\toutcomeValues: Record<string, any>;\n\t/**\n\t * Whether every declared response matches its correct response; absent when the item has no\n\t * response or one declares no correct response.\n\t */\n\tcorrect?: boolean;\n\t/** Modal feedback elements that should be displayed based on outcome values */\n\tmodalFeedback?: ModalFeedback[];\n}\n\n/**\n * QTI 2.2 completionStatus values for adaptive items\n * - not_attempted: No interaction has occurred yet\n * - unknown: Response exists but hasn't been scored/evaluated\n * - incomplete: Item has been scored but is still active (can submit again)\n * - completed: Item is finished (final state)\n */\nexport type CompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';\n\n/**\n * Extended scoring result for adaptive items with multi-attempt support\n */\nexport interface AdaptiveAttemptResult extends ScoringResult {\n\t/** Number of attempts made so far */\n\tnumAttempts: number;\n\t/** Current completion status of the item */\n\tcompletionStatus: CompletionStatus;\n\t/** Whether the item can accept more submissions */\n\tcanContinue: boolean;\n}\n\n/**\n * QTI role/view actors used for audience filtering (for example rubric/outcome visibility).\n * Runtime interaction behavior (readonly vs editable, correct-answer visibility) is a player\n * policy layered on top of these roles.\n */\nexport type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';\n\nexport type RubricBlockScope = 'direct' | 'itemBody';\n\n/** @internal Private engine rubric query. */\nexport interface RubricBlockOptions {\n\t/**\n\t * `direct` rubrics are assessment-item children and are intended for host placement.\n\t * `itemBody` rubrics are authored in the visible item body flow.\n\t */\n\tscope?: RubricBlockScope | 'all';\n}\n\nexport interface RubricBlock {\n\tview: string[]; // Array of role strings that can see this rubric\n\thtml: HtmlContent; // HTML content of the rubric\n\tscope: RubricBlockScope;\n\tuse?: string;\n}\n\n/**\n * QTI specification compliance configuration.\n * Controls whether the player enforces strict QTI 2.2 spec or allows vendor extensions.\n */\nexport interface QTIComplianceConfig {\n\t/** Enable strict QTI 2.2 compliance mode. Default: false (lenient) */\n\tenabled?: boolean;\n\n\t/** Reject items with unknown or non-standard elements. Default: false */\n\trejectUnknownExtensions?: boolean;\n\n\t/** Log warnings for spec deviations and vendor extensions. Default: true */\n\tlogDeviations?: boolean;\n}\n\n/** @internal Configuration for the private item-session engine. */\nexport interface ItemSessionEngineConfig {\n\titemXml: string;\n\t/**\n\t * QTI 3.0 §6.2 Personal Needs and Preferences profile.\n\t * Display needs are applied as attributes and custom properties on the player root.\n\t * Use player.updatePnp() to change mid-session without re-parsing the item.\n\t */\n\tpnp?: import('../pnp/types.js').PnpProfile;\n\t/**\n\t * Optional shared catalog XML string (QTI 3.0 §6.3).\n\t * Parsed and merged with any catalog embedded in the item XML.\n\t * Item-level catalog entries take precedence over shared entries with the same identifier.\n\t * Deferred: external catalog files from IMS manifest (G-15) are not yet supported.\n\t */\n\tcatalogXml?: string;\n\t/**\n\t * Optional resolved delivery context produced by IMS package/assessment layers.\n\t * This is additive to catalogXml: shared catalog sources are merged first, then\n\t * catalogXml, then item-embedded catalog entries so item-local entries win.\n\t */\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\trole?: QTIRole;\n\t/**\n\t * Values for the item's context variables, set before template processing: `QTI_CONTEXT`, a\n\t * record, and any declared by `contextDeclaration` (`qti-context-declaration`).\n\t */\n\tcontextVariables?: Readonly<Record<string, unknown>>;\n\t/**\n\t * Default values for template variables, set before template processing and kept by\n\t * `newTemplate`, as an assessmentItemRef's `templateDefault` requires.\n\t */\n\ttemplateDefaults?: Readonly<Record<string, unknown>>;\n\t/** Optional seed for deterministic random operations (e.g. templateProcessing randomInteger) */\n\tseed?: number;\n\t/** Optional RNG override (takes precedence over seed if provided) */\n\trng?: () => number;\n\t/**\n\t * Optional element name mapper for handling different QTI versions.\n\t * Defaults to Qti2xElementNameMapper (primary supported QTI format).\n\t * @since 0.2.0\n\t */\n\telementNameMapper?: ElementNameMapper;\n\t/**\n\t * Optional attribute name mapper for handling different QTI versions.\n\t * Defaults to Qti2xAttributeNameMapper (primary supported QTI format).\n\t * @since 0.3.0\n\t */\n\tattributeNameMapper?: AttributeNameMapper;\n\t/** Optional web component registry for custom interaction components */\n\tcomponentRegistry?: ComponentRegistry;\n\t/** Optional extraction registry for custom element extractors */\n\textractionRegistry?: ExtractionRegistry;\n\t/**\n\t * Optional i18n provider for internationalization.\n\t * If not provided, defaults to DefaultI18nProvider with English messages.\n\t */\n\ti18nProvider?: I18nProvider;\n\t/**\n\t * Optional registry for executing QTI <customOperator> expressions.\n\t * Keyed by operator `class` (preferred) or `definition` URI.\n\t */\n\tcustomOperators?: Record<string, (args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue>;\n\t/**\n\t * Host-controlled resolver for xi:include processing fragments.\n\t * The player never fetches an authored href directly; package hosts must resolve\n\t * and containment-check it, then return XML synchronously.\n\t */\n\tresolveProcessingFragment?: ProcessingFragmentResolver;\n\t/** Resource limits applied cumulatively while compiling external processing fragments. */\n\tprocessingFragmentLimits?: {\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t};\n\t/**\n\t * Portable Custom Interaction runtime configuration.\n\t * A moduleResolver is required before any authored PCI code can execute.\n\t */\n\tpci?: PciConfiguration;\n\t/**\n\t * Security-related controls for untrusted QTI rendered into the host DOM.\n\t * Defaults are conservative for same-DOM embedding.\n\t */\n\tsecurity?: PlayerSecurityConfig;\n\n\t/**\n\t * QTI specification compliance settings.\n\t * Set strictQtiCompliance.enabled = true for strict QTI 2.2 validation.\n\t */\n\tstrictQtiCompliance?: QTIComplianceConfig;\n}\n\nexport interface UrlPolicyConfig {\n\t/**\n\t * Optional base URL used to resolve relative asset URLs (e.g. images/media).\n\t * If omitted, relative URLs are preserved as-is.\n\t */\n\tassetBaseUrl?: string;\n\t/** Allow https: URLs */\n\tallowHttps?: boolean;\n\t/** Allow http: URLs (default false; prefer https) */\n\tallowHttp?: boolean;\n\t/** Allow protocol-relative URLs (e.g. //cdn.example/asset). Default false. */\n\tallowProtocolRelative?: boolean;\n\t/** Allow data:image/* for <img src>. */\n\tallowDataImages?: boolean;\n\t/** Allow data:image/svg+xml (default false) */\n\tallowSvgDataImages?: boolean;\n\t/** Allow blob: URLs for package-resolved images (default false). */\n\tallowBlobImages?: boolean;\n\t/** Allow blob: URLs for package-resolved audio/video media (default false). */\n\tallowBlobMedia?: boolean;\n\t/** Optional allowlist of hostnames for absolute URLs (exact match). */\n\tallowedHosts?: string[];\n}\n\n/**\n * Trusted Types support:\n * - When enabled and supported by the host browser + CSP, HTML-returning APIs may return TrustedHTML instead of string.\n * - When not enabled (default), APIs return plain strings as before.\n */\nexport type TrustedTypesHtml = typeof globalThis extends { TrustedHTML: infer T } ? T : never;\nexport type HtmlContent = string | TrustedTypesHtml;\n\nexport interface PlayerSecurityConfig {\n\t/** URL policy applied to extracted URL fields and HTML attribute URLs */\n\turlPolicy?: UrlPolicyConfig;\n\t/** Allow <object>/<embed> usage (default false) */\n\tallowObjectEmbeds?: boolean;\n\t/** Allow <iframe> usage (default false) */\n\tallowIframes?: boolean;\n\t/**\n\t * Optional parsing/processing guardrails to reduce DoS risk from untrusted QTI.\n\t * Disabled by default for compatibility.\n\t */\n\tparsingLimits?: ParsingLimitsConfig;\n\t/**\n\t * Optional Trusted Types policy name (host-controlled).\n\t * When set, and Trusted Types is available, the player will produce TrustedHTML for HTML injection sinks.\n\t *\n\t * Note: this is only effective when the host enables Trusted Types via CSP.\n\t */\n\ttrustedTypesPolicyName?: string;\n}\n\nexport interface ParsingLimitsConfig {\n\t/**\n\t * Enables parsing limits. When false/undefined, the player behaves exactly as before (compat default).\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Reject any XML containing <!DOCTYPE ...> (case-insensitive) when enabled.\n\t * Helps reduce entity-expansion and other parser edge-case risks.\n\t */\n\trejectDoctype?: boolean;\n\t/**\n\t * Maximum bytes for `itemXml` input (UTF-8). Enforced when enabled.\n\t */\n\tmaxItemXmlBytes?: number;\n\t/**\n\t * Maximum bytes for HTML strings passed to sanitizer (UTF-8). Enforced when enabled.\n\t */\n\tmaxHtmlBytes?: number;\n\t/**\n\t * Maximum number of element nodes sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlNodes?: number;\n\t/**\n\t * Maximum element depth sanitized per HTML input. Enforced when enabled.\n\t */\n\tmaxHtmlDepth?: number;\n}\n\nexport interface InteractionContext {\n\tresponseIdentifier: string;\n\tmaxChoices?: number;\n\tminChoices?: number;\n\tshuffle?: boolean;\n\torientation?: 'horizontal' | 'vertical';\n}\n\nexport * from './responseValidation.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0eH,cAAc,yBAAyB,CAAC","sourcesContent":["/**\n * Core QTI types for the player\n */\n\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type {\n\tBaseType as ProcessingBaseType,\n\tCardinality as ProcessingCardinality,\n\tProcessingFragmentResolver,\n\tQtiValue,\n\tStringComparisonOptions,\n} from '@pie-qti/qti-processing';\nimport type {\n\tAttributeNameMapper,\n\tElementNameMapper,\n\tQtiVersion,\n} from '@pie-qti/qti-common';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { ComponentRegistry } from '../core/ComponentRegistry.js';\nimport type { ExtractionRegistry } from '../extraction/ExtractionRegistry.js';\nimport type { ResponseValidationResult } from './responseValidation.js';\n\n/**\n * QTI base type identifier\n * Extensible string type allows custom base types\n */\nexport type VariableBaseType = ProcessingBaseType;\n\n/**\n * QTI cardinality identifier\n * Extensible string type allows custom cardinality values\n */\nexport type VariableCardinality = ProcessingCardinality;\n\nexport interface VariableDeclaration {\n\tidentifier: string;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\tdefaultValue?: any;\n\tmapping?: Mapping;\n\tareaMapping?: AreaMapping;\n}\n\nexport interface Mapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\tentries: Record<string, MapEntry>;\n}\n\nexport interface MapEntry {\n\tmapKey: string;\n\tmappedValue: number;\n\tcaseSensitive?: string;\n}\n\nexport interface AreaMapping {\n\tdefaultValue?: number;\n\tlowerBound?: number;\n\tupperBound?: number;\n\tentries: AreaMapEntry[];\n}\n\nexport interface AreaMapEntry {\n\tshape: 'circle' | 'rect' | 'poly' | 'ellipse' | 'default';\n\tcoords: string;\n\tmappedValue: number;\n}\n\nexport interface ResponseDeclaration extends VariableDeclaration {\n\tcorrectResponse?: any;\n}\n\n/** @internal Private engine snapshot shape; use SerializedItemSessionState. */\nexport interface ItemSessionState {\n\t[variableId: string]: any;\n}\n\nexport type ItemLifecycleStatus = 'initial' | 'interacting' | 'suspended' | 'closed' | 'review' | 'solution' | 'answer';\n\nexport type SerializedVariableKind = 'response' | 'outcome' | 'template' | 'context';\n\nexport interface SerializedItemSessionVariable {\n\tidentifier: string;\n\tkind: SerializedVariableKind;\n\t/** Omitted for record cardinality. */\n\tbaseType?: VariableBaseType;\n\tcardinality: VariableCardinality;\n\tvalue: any;\n\t/**\n\t * The variable's default value for this session, which a setDefaultValue\n\t * template rule can change (QTI 2.1 ASI §8 / QTI 3.0 ASI §10: template-rule\n\t * effects are fixed for the session); null when the variable has no default\n\t * value. Restore applies it as-is, so null restores a NULL default rather\n\t * than the default parsed from the item XML.\n\t */\n\tdefaultValue: any;\n\t/**\n\t * The response declaration's correct response for this session, including one\n\t * computed by a setCorrectResponse template rule (QTI 2.1 ASI §8 / QTI 3.0 ASI\n\t * §10: template-rule effects are fixed for the session). Present on every\n\t * response variable that has or had a correct response, with null meaning the\n\t * correct response is NULL; absent when the variable has no correct response.\n\t * Restore applies it as-is when present.\n\t */\n\tcorrectResponse?: any;\n}\n\nexport interface SerializedItemSessionState {\n\titemIdentifier?: string;\n\tsessionGuid: string;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\t/**\n\t * Time on task in milliseconds. The QTI built-in `duration` variable (in\n\t * `contextVariables.duration`) holds the same time in seconds, as QTI defines it.\n\t */\n\tduration: number;\n\tresponseVariables: Record<string, SerializedItemSessionVariable>;\n\toutcomeVariables: Record<string, SerializedItemSessionVariable>;\n\ttemplateVariables: Record<string, SerializedItemSessionVariable>;\n\tcontextVariables: Record<string, SerializedItemSessionVariable>;\n\tvalidationMessages: ResponseValidationResult['issues'];\n\tsavedAt: string;\n}\n\nexport type ItemSessionAction =\n\t| 'suspendAttempt'\n\t| 'endAttempt'\n\t| 'scoreAttempt'\n\t| 'newTemplate'\n\t| 'submitAttempt';\n\nexport type ItemSessionActionCommand =\n\t| { action: 'suspendAttempt' }\n\t| { action: 'endAttempt'; countAttempt?: boolean; validateResponses?: boolean }\n\t| { action: 'scoreAttempt' }\n\t| { action: 'newTemplate'; resetResponses?: boolean }\n\t| { action: 'submitAttempt'; countAttempt?: boolean };\n\nexport interface ItemSessionActionResult {\n\taction: ItemSessionAction;\n\tlifecycleStatus: ItemLifecycleStatus;\n\tcompletionStatus: CompletionStatus;\n\tnumAttempts: number;\n\t/** Time on task in milliseconds; the QTI `duration` variable holds it in seconds. */\n\tduration: number;\n\tcompleted: boolean;\n\tsessionState: SerializedItemSessionState;\n\tvalidation?: ResponseValidationResult;\n\tscoring?: ScoringResult;\n}\n\n/**\n * Serializable representation of a QTI baseType=\"file\" response.\n * (We cannot store a browser File object in session state / JSON exports.)\n */\nexport interface QTIFileResponse {\n\tname: string;\n\ttype: string;\n\tsize: number;\n\tlastModified: number;\n\t/** Base64 data URL, e.g. data:application/pdf;base64,... */\n\tdataUrl: string;\n\t/**\n\t * Optional ImageData extracted from canvas (for drawing interactions).\n\t * This allows custom operators to analyze drawing content synchronously\n\t * without needing to decode the dataUrl asynchronously.\n\t */\n\timageData?: {\n\t\tdata: Uint8ClampedArray;\n\t\twidth: number;\n\t\theight: number;\n\t};\n}\n\nexport interface ModalFeedback {\n\t/** Unique identifier for this feedback block */\n\tidentifier: string;\n\t/** Outcome variable identifier this feedback is tied to */\n\toutcomeIdentifier: string;\n\t/** When to show: 'show' means display when outcome matches identifier */\n\tshowHide: 'show' | 'hide';\n\t/** HTML content to display */\n\tcontent: HtmlContent;\n\t/** Optional title for the feedback */\n\ttitle?: string;\n}\n\nexport interface ScoringResult {\n\tscore: number;\n\tmaxScore: number;\n\tcompleted: boolean;\n\toutcomeValues: Record<string, any>;\n\t/**\n\t * Whether every declared response matches its correct response; absent when the item has no\n\t * response or one declares no correct response.\n\t */\n\tcorrect?: boolean;\n\t/** Modal feedback elements that should be displayed based on outcome values */\n\tmodalFeedback?: ModalFeedback[];\n}\n\n/**\n * QTI 2.2 completionStatus values for adaptive items\n * - not_attempted: No interaction has occurred yet\n * - unknown: Response exists but hasn't been scored/evaluated\n * - incomplete: Item has been scored but is still active (can submit again)\n * - completed: Item is finished (final state)\n */\nexport type CompletionStatus = 'not_attempted' | 'unknown' | 'incomplete' | 'completed';\n\n/**\n * Extended scoring result for adaptive items with multi-attempt support\n */\nexport interface AdaptiveAttemptResult extends ScoringResult {\n\t/** Number of attempts made so far */\n\tnumAttempts: number;\n\t/** Current completion status of the item */\n\tcompletionStatus: CompletionStatus;\n\t/** Whether the item can accept more submissions */\n\tcanContinue: boolean;\n}\n\n/**\n * QTI role/view actors used for audience filtering (for example rubric/outcome visibility).\n * Runtime interaction behavior (readonly vs editable, correct-answer visibility) is a player\n * policy layered on top of these roles.\n */\nexport type QTIRole = 'candidate' | 'scorer' | 'proctor' | 'testConstructor' | 'tutor' | 'author';\n\n/**\n * Why an item player reported a failure, as `error.code`. The `message` is raw engine or\n * parser text for host logs only — never render it to candidates.\n */\nexport type ItemPlayerErrorCode =\n\t| 'item-load-failed'\n\t| 'response-processing-failed'\n\t| 'response-dispatch-failed'\n\t| 'submission-failed'\n\t| 'render-failed';\n\n/** A player failure as hosts receive it: a stable `code`, the raw `message`, and the item when known. */\nexport interface ItemPlayerErrorDetail {\n\tcode: ItemPlayerErrorCode;\n\t/** Raw message, for logs and host diagnostics — never render it to candidates. */\n\tmessage: string;\n\titemIdentifier?: string;\n}\n\n/**\n * A failure the item body reports to its player: the stable `code` the element's\n * `error` event carries, plus the raw cause for host logs. `render-failed` covers\n * interaction mount/update and component-registry failures; the item keeps\n * rendering with a visible placeholder for the failed interaction.\n * `response-dispatch-failed` covers a rejected response write.\n */\nexport interface ItemBodyError {\n\tcode: Extract<ItemPlayerErrorCode, 'render-failed' | 'response-dispatch-failed'>;\n\tcause: unknown;\n}\n\nexport type RubricBlockScope = 'direct' | 'itemBody';\n\n/** @internal Private engine rubric query. */\nexport interface RubricBlockOptions {\n\t/**\n\t * `direct` rubrics are assessment-item children and are intended for host placement.\n\t * `itemBody` rubrics are authored in the visible item body flow.\n\t */\n\tscope?: RubricBlockScope | 'all';\n}\n\nexport interface RubricBlock {\n\tview: string[]; // Array of role strings that can see this rubric\n\thtml: HtmlContent; // HTML content of the rubric\n\tscope: RubricBlockScope;\n\tuse?: string;\n}\n\n/**\n * QTI compliance checks run once, when the item compiles. They are not an XSD validator: they check\n * the version's namespace, every element name against the XSD-verified QTI 2.2 / 3.0 vocabulary\n * (unknown QTI-namespace elements, and unknown `qti-` elements in QTI 3.0), interactions whose\n * `responseIdentifier` names no responseDeclaration, QTI interactions with no\n * `responseIdentifier`, and response-bound elements no registered extractor renders.\n *\n * Findings are listed on `AssessmentItemDefinition.diagnostics`: warnings by default, errors in\n * strict mode. An unsupported `responseProcessing@template` always fails compilation with an\n * `UnsupportedResponseProcessingTemplateError`, strict or not.\n */\nexport interface QTIComplianceConfig {\n\t/**\n\t * Strict mode: findings are errors, and items in versions other than QTI 2.2 and 3.0 (the\n\t * certifiable versions) are findings too. Default: false (findings are warnings).\n\t */\n\tenabled?: boolean;\n\n\t/** In strict mode, throw a `QtiComplianceError` listing every finding instead of compiling. Default: false */\n\trejectUnknownExtensions?: boolean;\n\n\t/** Write findings to the console (errors in strict mode, warnings otherwise). Default: true */\n\tlogDeviations?: boolean;\n}\n\n/** @internal Configuration for the private item-session engine. */\nexport interface ItemSessionEngineConfig {\n\titemXml: string;\n\t/**\n\t * QTI 3.0 §6.2 Personal Needs and Preferences profile.\n\t * Display needs are applied as attributes and custom properties on the player root.\n\t * Use player.updatePnp() to change mid-session without re-parsing the item.\n\t */\n\tpnp?: import('../pnp/types.js').PnpProfile;\n\t/**\n\t * Optional shared catalog XML string (QTI 3.0 §6.3).\n\t * Parsed and merged with any catalog embedded in the item XML.\n\t * Item-level catalog entries take precedence over shared entries with the same identifier.\n\t * Deferred: external catalog files from IMS manifest (G-15) are not yet supported.\n\t */\n\tcatalogXml?: string;\n\t/**\n\t * Optional resolved delivery context produced by IMS package/assessment layers.\n\t * This is additive to catalogXml: shared catalog sources are merged first, then\n\t * catalogXml, then item-embedded catalog entries so item-local entries win.\n\t */\n\tdeliveryContext?: ResolvedItemDeliveryContext;\n\trole?: QTIRole;\n\t/**\n\t * Values for the item's context variables, set before template processing: `QTI_CONTEXT`, a\n\t * record, and any declared by `contextDeclaration` (`qti-context-declaration`).\n\t */\n\tcontextVariables?: Readonly<Record<string, unknown>>;\n\t/**\n\t * Default values for template variables, set before template processing and kept by\n\t * `newTemplate`, as an assessmentItemRef's `templateDefault` requires.\n\t */\n\ttemplateDefaults?: Readonly<Record<string, unknown>>;\n\t/** Optional seed for deterministic random operations (e.g. templateProcessing randomInteger) */\n\tseed?: number;\n\t/** Optional RNG override (takes precedence over seed if provided) */\n\trng?: () => number;\n\t/**\n\t * Optional element name mapper for handling different QTI versions.\n\t * Defaults to Qti2xElementNameMapper (primary supported QTI format).\n\t * @since 0.2.0\n\t */\n\telementNameMapper?: ElementNameMapper;\n\t/**\n\t * Optional attribute name mapper for handling different QTI versions.\n\t * Defaults to Qti2xAttributeNameMapper (primary supported QTI format).\n\t * @since 0.3.0\n\t */\n\tattributeNameMapper?: AttributeNameMapper;\n\t/**\n\t * The item's detected QTI version, applied by extractors that carry per-version spec\n\t * defaults (e.g. graphicGapMatchInteraction maxAssociations). Detected from the item\n\t * XML when not supplied.\n\t */\n\tqtiVersion?: QtiVersion;\n\t/** Optional web component registry for custom interaction components */\n\tcomponentRegistry?: ComponentRegistry;\n\t/** Optional extraction registry for custom element extractors */\n\textractionRegistry?: ExtractionRegistry;\n\t/**\n\t * Optional i18n provider for internationalization.\n\t * If not provided, defaults to DefaultI18nProvider with English messages.\n\t */\n\ti18nProvider?: I18nProvider;\n\t/**\n\t * Optional registry for executing QTI <customOperator> expressions.\n\t * Keyed by operator `class` (preferred) or `definition` URI.\n\t */\n\tcustomOperators?: Record<string, (args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue>;\n\t/** String comparison folds beyond QTI's equality; see `AssessmentItemDefinitionConfig.stringComparison`. */\n\tstringComparison?: StringComparisonOptions;\n\t/**\n\t * Host-controlled resolver for xi:include processing fragments.\n\t * The player never fetches an authored href directly; package hosts must resolve\n\t * and containment-check it, then return XML synchronously.\n\t */\n\tresolveProcessingFragment?: ProcessingFragmentResolver;\n\t/** Resource limits applied cumulatively while compiling external processing fragments. */\n\tprocessingFragmentLimits?: {\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t};\n\t/**\n\t * Portable Custom Interaction runtime configuration.\n\t * A moduleResolver is required before any authored PCI code can execute.\n\t */\n\tpci?: PciConfiguration;\n\t/**\n\t * Security-related controls for untrusted QTI rendered into the host DOM.\n\t * Defaults are conservative for same-DOM embedding.\n\t */\n\tsecurity?: PlayerSecurityConfig;\n\n\t/**\n\t * QTI compliance checks; see `QTIComplianceConfig`. Set `enabled` for strict mode.\n\t */\n\tstrictQtiCompliance?: QTIComplianceConfig;\n}\n\nexport interface UrlPolicyConfig {\n\t/**\n\t * Optional base URL used to resolve relative asset URLs (e.g. images/media).\n\t * If omitted, relative URLs are preserved as-is.\n\t */\n\tassetBaseUrl?: string;\n\t/** Allow https: URLs */\n\tallowHttps?: boolean;\n\t/** Allow http: URLs (default false; prefer https) */\n\tallowHttp?: boolean;\n\t/** Allow protocol-relative URLs (e.g. //cdn.example/asset). Default false. */\n\tallowProtocolRelative?: boolean;\n\t/** Allow data:image/* for <img src>. */\n\tallowDataImages?: boolean;\n\t/** Allow data:image/svg+xml (default false) */\n\tallowSvgDataImages?: boolean;\n\t/** Allow blob: URLs for package-resolved images (default false). */\n\tallowBlobImages?: boolean;\n\t/** Allow blob: URLs for package-resolved audio/video media (default false). */\n\tallowBlobMedia?: boolean;\n\t/** Optional allowlist of hostnames for absolute URLs (exact match). */\n\tallowedHosts?: string[];\n}\n\n/**\n * Trusted Types support:\n * - When enabled and supported by the host browser + CSP, HTML-returning APIs may return TrustedHTML instead of string.\n * - When not enabled (default), APIs return plain strings as before.\n */\nexport type TrustedTypesHtml = typeof globalThis extends { TrustedHTML: infer T } ? T : never;\nexport type HtmlContent = string | TrustedTypesHtml;\n\nexport interface PlayerSecurityConfig {\n\t/** URL policy applied to extracted URL fields and HTML attribute URLs */\n\turlPolicy?: UrlPolicyConfig;\n\t/** Allow <object>/<embed> usage (default false) */\n\tallowObjectEmbeds?: boolean;\n\t/** Allow <iframe> usage (default false) */\n\tallowIframes?: boolean;\n\t/**\n\t * Parsing/processing guardrails that reduce DoS risk from untrusted QTI. On by default;\n\t * `parsingLimits.enabled: false` opts out.\n\t */\n\tparsingLimits?: ParsingLimitsConfig;\n\t/**\n\t * Optional Trusted Types policy name (host-controlled).\n\t * When set, and Trusted Types is available, the player will produce TrustedHTML for HTML injection sinks.\n\t *\n\t * Note: this is only effective when the host enables Trusted Types via CSP.\n\t */\n\ttrustedTypesPolicyName?: string;\n}\n\nexport interface ParsingLimitsConfig {\n\t/**\n\t * The limits apply unless this is `false`. Opt out only for trusted content that needs more\n\t * than the limits allow (or a DOCTYPE), never to accept untrusted QTI.\n\t */\n\tenabled?: boolean;\n\t/**\n\t * Reject any XML containing <!DOCTYPE ...> (case-insensitive). Default true.\n\t * Helps reduce entity-expansion and other parser edge-case risks.\n\t */\n\trejectDoctype?: boolean;\n\t/**\n\t * Maximum bytes for `itemXml` input (UTF-8). Default 10,000,000.\n\t */\n\tmaxItemXmlBytes?: number;\n\t/**\n\t * Maximum bytes for HTML strings passed to the sanitizer (UTF-8). Default 5,000,000.\n\t */\n\tmaxHtmlBytes?: number;\n\t/**\n\t * Maximum number of element nodes sanitized per HTML input. Default 200,000.\n\t */\n\tmaxHtmlNodes?: number;\n\t/**\n\t * Maximum element depth sanitized per HTML input. Default 200.\n\t */\n\tmaxHtmlDepth?: number;\n}\n\nexport * from './responseValidation.js';\n"]}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The player's one clone/freeze family.
3
+ *
4
+ * Everything the player snapshots (session views, transitions, serialized
5
+ * state, delivered interaction data, definition configuration, presentation
6
+ * plans) goes through these helpers, so the treatment of the shapes that make
7
+ * deep-copying hazardous is defined once:
8
+ *
9
+ * - Plain objects and arrays are structurally deep-copied.
10
+ * - ArrayBuffers and typed arrays are copied and never frozen: a response's
11
+ * drawing `imageData` (`Uint8ClampedArray`) cannot be frozen — `Object.freeze`
12
+ * throws on a non-empty integer-indexed exotic object — and callers must stay
13
+ * able to read it after `state()`, serialize and restore.
14
+ * - TrustedHTML, `File`, `Blob` and every other non-plain object keep their
15
+ * identity as terminal leaves. `structuredClone` would throw `DataCloneError`
16
+ * on a TrustedHTML value, so presentation and extraction data — which carry
17
+ * TrustedHTML once a Trusted Types policy is configured — are never handed to
18
+ * it; a host-owned object a plugin supplied deliberately must survive
19
+ * delivery as the same object.
20
+ */
21
+ /**
22
+ * Structural deep copy of plain data. Typed arrays and buffers are copied;
23
+ * non-plain objects keep their identity; nothing is frozen.
24
+ */
25
+ export declare function cloneValue<T>(value: T): T;
26
+ /**
27
+ * In-place deep freeze of a data graph. Plain objects and arrays are frozen;
28
+ * non-plain leaves (TrustedHTML, File, Blob, typed arrays, host objects) are
29
+ * returned untouched — freezing a browser-owned object can throw and freezing
30
+ * a typed array always would. An already-frozen node short-circuits its subtree.
31
+ */
32
+ export declare function deepFreezeInPlace<T>(value: T): T;
33
+ /**
34
+ * Clone and freeze plain data without mutating values owned by the caller or a
35
+ * PCI module: `cloneValue`'s copy, deeply frozen.
36
+ */
37
+ export declare function frozenSnapshot<T>(value: T): T;
38
+ /**
39
+ * A hand-out copy of an ALREADY deeply frozen snapshot for one recipient. The frozen plain
40
+ * structure is shared as-is — freezing makes it unobservable to mutation — but every
41
+ * typed-array leaf, which the platform cannot freeze, is re-copied, so recipients never
42
+ * share the snapshot's mutable unfrozen data (listeners pin that isolation, see
43
+ * tests/core/assessment-item-definition.test.ts "detaches drawing response data"). Non-plain
44
+ * leaves keep their identity, as everywhere in this family. A snapshot with nothing to
45
+ * isolate returns unchanged, so the common dispatch shares one frozen object with every
46
+ * listener and pays no copies at all.
47
+ *
48
+ * Precondition: the value was produced by frozenSnapshot/deepFreezeInPlace. A shallow-walk
49
+ * finding of nothing to copy returns the input; a rebuilt branch is re-frozen in place, so
50
+ * the result satisfies the same deep-freeze invariant as the input.
51
+ */
52
+ export declare function withFreshTypedArrays<T>(value: T): T;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The player's one clone/freeze family.
3
+ *
4
+ * Everything the player snapshots (session views, transitions, serialized
5
+ * state, delivered interaction data, definition configuration, presentation
6
+ * plans) goes through these helpers, so the treatment of the shapes that make
7
+ * deep-copying hazardous is defined once:
8
+ *
9
+ * - Plain objects and arrays are structurally deep-copied.
10
+ * - ArrayBuffers and typed arrays are copied and never frozen: a response's
11
+ * drawing `imageData` (`Uint8ClampedArray`) cannot be frozen — `Object.freeze`
12
+ * throws on a non-empty integer-indexed exotic object — and callers must stay
13
+ * able to read it after `state()`, serialize and restore.
14
+ * - TrustedHTML, `File`, `Blob` and every other non-plain object keep their
15
+ * identity as terminal leaves. `structuredClone` would throw `DataCloneError`
16
+ * on a TrustedHTML value, so presentation and extraction data — which carry
17
+ * TrustedHTML once a Trusted Types policy is configured — are never handed to
18
+ * it; a host-owned object a plugin supplied deliberately must survive
19
+ * delivery as the same object.
20
+ */
21
+ /**
22
+ * Structural deep copy of plain data. Typed arrays and buffers are copied;
23
+ * non-plain objects keep their identity; nothing is frozen.
24
+ */
25
+ export function cloneValue(value) {
26
+ if (Array.isArray(value)) {
27
+ return value.map((entry) => cloneValue(entry));
28
+ }
29
+ if (!value || typeof value !== 'object')
30
+ return value;
31
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
32
+ return structuredClone(value);
33
+ }
34
+ // TrustedHTML, File, Blob and other class instances are terminal leaves (see
35
+ // the module doc): not structured-cloned, not recreated, identity preserved.
36
+ const prototype = Object.getPrototypeOf(value);
37
+ if (prototype !== Object.prototype && prototype !== null)
38
+ return value;
39
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
40
+ key,
41
+ cloneValue(entry),
42
+ ]));
43
+ }
44
+ /**
45
+ * In-place deep freeze of a data graph. Plain objects and arrays are frozen;
46
+ * non-plain leaves (TrustedHTML, File, Blob, typed arrays, host objects) are
47
+ * returned untouched — freezing a browser-owned object can throw and freezing
48
+ * a typed array always would. An already-frozen node short-circuits its subtree.
49
+ */
50
+ export function deepFreezeInPlace(value) {
51
+ if (!value || typeof value !== 'object' || Object.isFrozen(value))
52
+ return value;
53
+ const prototype = Object.getPrototypeOf(value);
54
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
55
+ return value;
56
+ Object.freeze(value);
57
+ for (const child of Object.values(value)) {
58
+ deepFreezeInPlace(child);
59
+ }
60
+ return value;
61
+ }
62
+ /**
63
+ * Clone and freeze plain data without mutating values owned by the caller or a
64
+ * PCI module: `cloneValue`'s copy, deeply frozen.
65
+ */
66
+ export function frozenSnapshot(value) {
67
+ return deepFreezeInPlace(cloneValue(value));
68
+ }
69
+ /**
70
+ * A hand-out copy of an ALREADY deeply frozen snapshot for one recipient. The frozen plain
71
+ * structure is shared as-is — freezing makes it unobservable to mutation — but every
72
+ * typed-array leaf, which the platform cannot freeze, is re-copied, so recipients never
73
+ * share the snapshot's mutable unfrozen data (listeners pin that isolation, see
74
+ * tests/core/assessment-item-definition.test.ts "detaches drawing response data"). Non-plain
75
+ * leaves keep their identity, as everywhere in this family. A snapshot with nothing to
76
+ * isolate returns unchanged, so the common dispatch shares one frozen object with every
77
+ * listener and pays no copies at all.
78
+ *
79
+ * Precondition: the value was produced by frozenSnapshot/deepFreezeInPlace. A shallow-walk
80
+ * finding of nothing to copy returns the input; a rebuilt branch is re-frozen in place, so
81
+ * the result satisfies the same deep-freeze invariant as the input.
82
+ */
83
+ export function withFreshTypedArrays(value) {
84
+ return isolateTypedArrays(value);
85
+ }
86
+ function isolateTypedArrays(value) {
87
+ if (Array.isArray(value)) {
88
+ let changed = false;
89
+ const copy = value.map((entry) => {
90
+ const next = isolateTypedArrays(entry);
91
+ changed || (changed = next !== entry);
92
+ return next;
93
+ });
94
+ return changed ? deepFreezeInPlace(copy) : value;
95
+ }
96
+ if (!value || typeof value !== 'object')
97
+ return value;
98
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer)
99
+ return structuredClone(value);
100
+ const prototype = Object.getPrototypeOf(value);
101
+ // TrustedHTML, File, Blob and other class instances are terminal leaves (see the
102
+ // module doc): identity preserved, nothing to isolate.
103
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
104
+ return value;
105
+ let changed = false;
106
+ const entries = Object.entries(value).map(([key, entry]) => {
107
+ const next = isolateTypedArrays(entry);
108
+ changed || (changed = next !== entry);
109
+ return [key, next];
110
+ });
111
+ return changed ? deepFreezeInPlace(Object.fromEntries(entries)) : value;
112
+ }
113
+ //# sourceMappingURL=cloneFreeze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloneFreeze.js","sourceRoot":"","sources":["../../src/utils/cloneFreeze.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * The player's one clone/freeze family.\n *\n * Everything the player snapshots (session views, transitions, serialized\n * state, delivered interaction data, definition configuration, presentation\n * plans) goes through these helpers, so the treatment of the shapes that make\n * deep-copying hazardous is defined once:\n *\n * - Plain objects and arrays are structurally deep-copied.\n * - ArrayBuffers and typed arrays are copied and never frozen: a response's\n * drawing `imageData` (`Uint8ClampedArray`) cannot be frozen — `Object.freeze`\n * throws on a non-empty integer-indexed exotic object — and callers must stay\n * able to read it after `state()`, serialize and restore.\n * - TrustedHTML, `File`, `Blob` and every other non-plain object keep their\n * identity as terminal leaves. `structuredClone` would throw `DataCloneError`\n * on a TrustedHTML value, so presentation and extraction data — which carry\n * TrustedHTML once a Trusted Types policy is configured — are never handed to\n * it; a host-owned object a plugin supplied deliberately must survive\n * delivery as the same object.\n */\n\n/**\n * Structural deep copy of plain data. Typed arrays and buffers are copied;\n * non-plain objects keep their identity; nothing is frozen.\n */\nexport function cloneValue<T>(value: T): T {\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => cloneValue(entry)) as unknown as T;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n\t\treturn structuredClone(value);\n\t}\n\t// TrustedHTML, File, Blob and other class instances are terminal leaves (see\n\t// the module doc): not structured-cloned, not recreated, identity preserved.\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return value;\n\treturn Object.fromEntries(\n\t\tObject.entries(value as Record<string, unknown>).map(([key, entry]) => [\n\t\t\tkey,\n\t\t\tcloneValue(entry),\n\t\t]),\n\t) as T;\n}\n\n/**\n * In-place deep freeze of a data graph. Plain objects and arrays are frozen;\n * non-plain leaves (TrustedHTML, File, Blob, typed arrays, host objects) are\n * returned untouched — freezing a browser-owned object can throw and freezing\n * a typed array always would. An already-frozen node short-circuits its subtree.\n */\nexport function deepFreezeInPlace<T>(value: T): T {\n\tif (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return value;\n\tObject.freeze(value);\n\tfor (const child of Object.values(value as Record<string, unknown>)) {\n\t\tdeepFreezeInPlace(child);\n\t}\n\treturn value;\n}\n\n/**\n * Clone and freeze plain data without mutating values owned by the caller or a\n * PCI module: `cloneValue`'s copy, deeply frozen.\n */\nexport function frozenSnapshot<T>(value: T): T {\n\treturn deepFreezeInPlace(cloneValue(value));\n}\n\n/**\n * A hand-out copy of an ALREADY deeply frozen snapshot for one recipient. The frozen plain\n * structure is shared as-is — freezing makes it unobservable to mutation — but every\n * typed-array leaf, which the platform cannot freeze, is re-copied, so recipients never\n * share the snapshot's mutable unfrozen data (listeners pin that isolation, see\n * tests/core/assessment-item-definition.test.ts \"detaches drawing response data\"). Non-plain\n * leaves keep their identity, as everywhere in this family. A snapshot with nothing to\n * isolate returns unchanged, so the common dispatch shares one frozen object with every\n * listener and pays no copies at all.\n *\n * Precondition: the value was produced by frozenSnapshot/deepFreezeInPlace. A shallow-walk\n * finding of nothing to copy returns the input; a rebuilt branch is re-frozen in place, so\n * the result satisfies the same deep-freeze invariant as the input.\n */\nexport function withFreshTypedArrays<T>(value: T): T {\n\treturn isolateTypedArrays(value) as T;\n}\n\nfunction isolateTypedArrays(value: unknown): unknown {\n\tif (Array.isArray(value)) {\n\t\tlet changed = false;\n\t\tconst copy = value.map((entry) => {\n\t\t\tconst next = isolateTypedArrays(entry);\n\t\t\tchanged ||= next !== entry;\n\t\t\treturn next;\n\t\t});\n\t\treturn changed ? deepFreezeInPlace(copy) : value;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return structuredClone(value);\n\tconst prototype = Object.getPrototypeOf(value);\n\t// TrustedHTML, File, Blob and other class instances are terminal leaves (see the\n\t// module doc): identity preserved, nothing to isolate.\n\tif (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return value;\n\tlet changed = false;\n\tconst entries = Object.entries(value as Record<string, unknown>).map(([key, entry]) => {\n\t\tconst next = isolateTypedArrays(entry);\n\t\tchanged ||= next !== entry;\n\t\treturn [key, next];\n\t});\n\treturn changed ? deepFreezeInPlace(Object.fromEntries(entries)) : value;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Reads one attribute out of a serialized HTML attribute string — the attribute text of a matched
3
+ * tag (e.g. a regex capture of `<gap identifier="g1">`), not a DOM element. This is the one reader
4
+ * for markup the player handles as text: the gap-match extractor's prompt rewriting, the
5
+ * presentation pass's stimulus docking, and the feedback announcement's feedback tags.
6
+ *
7
+ * Quote pairs must match, an empty value is a value (`identifier=""` is present and empty, not
8
+ * absent), and a camelCase name also tries its kebab spelling (`outcomeIdentifier` or
9
+ * `outcome-identifier`), since QTI 2.x and QTI 3.0 spell attributes differently. Only whitespace
10
+ * may precede the name, so `data-identifier` does not read as `identifier`. Returns null when the
11
+ * attribute is absent; otherwise its value, untrimmed.
12
+ */
13
+ export declare function readHtmlAttribute(attrs: string, name: string): string | null;