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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) 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 -18
  273. package/dist/components/utils/feedbackUtils.d.ts +0 -77
  274. package/dist/components/utils/feedbackUtils.js +0 -138
  275. package/dist/components/utils/feedbackUtils.js.map +0 -1
  276. package/dist/components/utils/index.d.ts +0 -4
  277. package/dist/components/utils/index.js +0 -5
  278. package/dist/components/utils/index.js.map +0 -1
  279. package/dist/components/utils/stimulusRender.js.map +0 -1
  280. package/dist/components/utils/stylesheetRender.js.map +0 -1
  281. package/dist/core/constants.d.ts +0 -65
  282. package/dist/core/constants.js +0 -74
  283. package/dist/core/constants.js.map +0 -1
  284. package/dist/element-class-X2XXDa29.js +0 -9299
  285. package/dist/element-class-X2XXDa29.js.map +0 -1
  286. package/dist/extensions/MathLiveEditor.d.ts +0 -31
  287. package/dist/extensions/MathLiveEditor.js +0 -248
  288. package/dist/extensions/MathLiveEditor.js.map +0 -1
  289. package/dist/utils/PerformanceMonitor.d.ts +0 -169
  290. package/dist/utils/PerformanceMonitor.js +0 -243
  291. package/dist/utils/PerformanceMonitor.js.map +0 -1
  292. package/dist/utils/responseUtils.d.ts +0 -15
  293. package/dist/utils/responseUtils.js +0 -46
  294. package/dist/utils/responseUtils.js.map +0 -1
  295. package/dist/web-components/QTIInteractionBase.d.ts +0 -119
  296. package/dist/web-components/QTIInteractionBase.js +0 -244
  297. package/dist/web-components/QTIInteractionBase.js.map +0 -1
  298. /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
  299. /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
  300. /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
@@ -46,6 +46,98 @@ export interface ComponentConfig<TData extends BaseInteractionData = BaseInterac
46
46
  */
47
47
  autoRegister?: boolean;
48
48
  }
49
+ /**
50
+ * The default custom-element tag for each block interaction type the player renders, plus
51
+ * `catalogPopup`, the glossary popup. `createComponentRegistry` registers them as fallbacks
52
+ * (tag metadata only), and `@pie-qti/default-components` registers the components it ships
53
+ * under the same tags.
54
+ */
55
+ export declare const DEFAULT_COMPONENT_TAGS_BY_TYPE: {
56
+ readonly choiceInteraction: {
57
+ readonly name: "default-choice";
58
+ readonly tagName: "pie-qti-choice";
59
+ };
60
+ readonly sliderInteraction: {
61
+ readonly name: "default-slider";
62
+ readonly tagName: "pie-qti-slider";
63
+ };
64
+ readonly orderInteraction: {
65
+ readonly name: "default-order";
66
+ readonly tagName: "pie-qti-order";
67
+ };
68
+ readonly matchInteraction: {
69
+ readonly name: "default-match";
70
+ readonly tagName: "pie-qti-match";
71
+ };
72
+ readonly associateInteraction: {
73
+ readonly name: "default-associate";
74
+ readonly tagName: "pie-qti-associate";
75
+ };
76
+ readonly gapMatchInteraction: {
77
+ readonly name: "default-gap-match";
78
+ readonly tagName: "pie-qti-gap-match";
79
+ };
80
+ readonly hotspotInteraction: {
81
+ readonly name: "default-hotspot";
82
+ readonly tagName: "pie-qti-hotspot";
83
+ };
84
+ readonly hottextInteraction: {
85
+ readonly name: "default-hottext";
86
+ readonly tagName: "pie-qti-hottext";
87
+ };
88
+ readonly mediaInteraction: {
89
+ readonly name: "default-media";
90
+ readonly tagName: "pie-qti-media";
91
+ };
92
+ readonly customInteraction: {
93
+ readonly name: "default-custom";
94
+ readonly tagName: "pie-qti-custom";
95
+ };
96
+ readonly portableCustomInteraction: {
97
+ readonly name: "default-portable-custom";
98
+ readonly tagName: "pie-qti-portable-custom";
99
+ };
100
+ readonly endAttemptInteraction: {
101
+ readonly name: "default-end-attempt";
102
+ readonly tagName: "pie-qti-end-attempt";
103
+ };
104
+ readonly positionObjectInteraction: {
105
+ readonly name: "default-position-object";
106
+ readonly tagName: "pie-qti-position-object";
107
+ };
108
+ readonly graphicGapMatchInteraction: {
109
+ readonly name: "default-graphic-gap-match";
110
+ readonly tagName: "pie-qti-graphic-gap-match";
111
+ };
112
+ readonly graphicOrderInteraction: {
113
+ readonly name: "default-graphic-order";
114
+ readonly tagName: "pie-qti-graphic-order";
115
+ };
116
+ readonly graphicAssociateInteraction: {
117
+ readonly name: "default-graphic-associate";
118
+ readonly tagName: "pie-qti-graphic-associate";
119
+ };
120
+ readonly selectPointInteraction: {
121
+ readonly name: "default-select-point";
122
+ readonly tagName: "pie-qti-select-point";
123
+ };
124
+ readonly extendedTextInteraction: {
125
+ readonly name: "default-extended-text";
126
+ readonly tagName: "pie-qti-extended-text";
127
+ };
128
+ readonly uploadInteraction: {
129
+ readonly name: "default-upload";
130
+ readonly tagName: "pie-qti-upload";
131
+ };
132
+ readonly drawingInteraction: {
133
+ readonly name: "default-drawing";
134
+ readonly tagName: "pie-qti-drawing";
135
+ };
136
+ readonly catalogPopup: {
137
+ readonly name: "default-catalog-popup";
138
+ readonly tagName: "pie-qti-catalog-popup";
139
+ };
140
+ };
49
141
  /**
50
142
  * Registry for web components that render QTI interactions
51
143
  */
@@ -5,7 +5,13 @@
5
5
  * different QTI interaction types. Uses priority-based dispatch similar to the
6
6
  * ExtractionRegistry, but for framework-agnostic web components.
7
7
  */
8
- const DEFAULT_COMPONENT_TAGS_BY_TYPE = {
8
+ /**
9
+ * The default custom-element tag for each block interaction type the player renders, plus
10
+ * `catalogPopup`, the glossary popup. `createComponentRegistry` registers them as fallbacks
11
+ * (tag metadata only), and `@pie-qti/default-components` registers the components it ships
12
+ * under the same tags.
13
+ */
14
+ export const DEFAULT_COMPONENT_TAGS_BY_TYPE = {
9
15
  choiceInteraction: { name: 'default-choice', tagName: 'pie-qti-choice' },
10
16
  sliderInteraction: { name: 'default-slider', tagName: 'pie-qti-slider' },
11
17
  orderInteraction: { name: 'default-order', tagName: 'pie-qti-order' },
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../../src/core/ComponentRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiEH,MAAM,8BAA8B,GAAG;IACtC,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,oBAAoB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,EAAE;IACjF,mBAAmB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,EAAE;IAChF,kBAAkB,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,EAAE;IAC3E,kBAAkB,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,EAAE;IAC3E,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE;IACrE,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,yBAAyB,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,yBAAyB,EAAE;IAClG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,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAEO,aAAa;QACpB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACd,kGAAkG,CAClG,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACtC,MAAM,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACzC,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAAC,QAA2B;IACvE,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,EAAE,CAAC;QAChF,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;YACvB,GAAG,SAAS;YACZ,WAAW,EAAE,iCAAiC,IAAI,EAAE;YACpD,QAAQ,EAAE,CAAC,GAAG;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/**\n * Component Registry for Web Component-based Interaction Rendering\n *\n * Provides a pluggable system for registering web components to render\n * different QTI interaction types. Uses priority-based dispatch similar to the\n * ExtractionRegistry, but for framework-agnostic web components.\n */\n\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\n\n/**\n * Configuration for registering a web component renderer\n */\nexport interface ComponentConfig<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\t/** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */\n\tname: string;\n\n\t/**\n\t * Priority for renderer evaluation (higher = checked first)\n\t * - 100: Very specific custom renderers\n\t * - 50: Moderately specific custom renderers\n\t * - 10: Generic custom renderers\n\t * - 0: Default fallback renderers\n\t * Default: 0\n\t */\n\tpriority?: number;\n\n\t/** Optional description for debugging/error messages */\n\tdescription?: string;\n\n\t/**\n\t * Predicate to determine if this component can handle the interaction\n\t * Evaluated in priority order (highest first)\n\t * @returns true if this component should be used\n\t * Default: always true\n\t */\n\tcanHandle?: (data: TData) => boolean;\n\n\t/**\n\t * Web component tag name (must contain a hyphen per web component spec)\n\t * e.g., 'qti-choice-interaction', 'custom-rating-choice'\n\t */\n\ttagName: string;\n\n\t/**\n\t * Optional web component class constructor\n\t * If provided, the component will be automatically registered with customElements\n\t */\n\tcomponentClass?: CustomElementConstructor;\n\n\t/**\n\t * Whether to automatically register the component with customElements\n\t * Default: true if componentClass is provided\n\t */\n\tautoRegister?: boolean;\n}\n\n/**\n * Internal registered component with metadata\n */\ninterface RegisteredComponent<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\tconfig: ComponentConfig<TData> & {\n\t\tpriority: number;\n\t\tcanHandle: (data: TData) => boolean;\n\t};\n}\n\nconst DEFAULT_COMPONENT_TAGS_BY_TYPE = {\n\tchoiceInteraction: { name: 'default-choice', tagName: 'pie-qti-choice' },\n\tsliderInteraction: { name: 'default-slider', tagName: 'pie-qti-slider' },\n\torderInteraction: { name: 'default-order', tagName: 'pie-qti-order' },\n\tmatchInteraction: { name: 'default-match', tagName: 'pie-qti-match' },\n\tassociateInteraction: { name: 'default-associate', tagName: 'pie-qti-associate' },\n\tgapMatchInteraction: { name: 'default-gap-match', tagName: 'pie-qti-gap-match' },\n\thotspotInteraction: { name: 'default-hotspot', tagName: 'pie-qti-hotspot' },\n\thottextInteraction: { name: 'default-hottext', tagName: 'pie-qti-hottext' },\n\tmediaInteraction: { name: 'default-media', tagName: 'pie-qti-media' },\n\tcustomInteraction: { name: 'default-custom', tagName: 'pie-qti-custom' },\n\tportableCustomInteraction: { name: 'default-portable-custom', tagName: 'pie-qti-portable-custom' },\n\tendAttemptInteraction: { name: 'default-end-attempt', tagName: 'pie-qti-end-attempt' },\n\tpositionObjectInteraction: { name: 'default-position-object', tagName: 'pie-qti-position-object' },\n\tgraphicGapMatchInteraction: { name: 'default-graphic-gap-match', tagName: 'pie-qti-graphic-gap-match' },\n\tgraphicOrderInteraction: { name: 'default-graphic-order', tagName: 'pie-qti-graphic-order' },\n\tgraphicAssociateInteraction: { name: 'default-graphic-associate', tagName: 'pie-qti-graphic-associate' },\n\tselectPointInteraction: { name: 'default-select-point', tagName: 'pie-qti-select-point' },\n\textendedTextInteraction: { name: 'default-extended-text', tagName: 'pie-qti-extended-text' },\n\tuploadInteraction: { name: 'default-upload', tagName: 'pie-qti-upload' },\n\tdrawingInteraction: { name: 'default-drawing', tagName: 'pie-qti-drawing' },\n\tcatalogPopup: { name: 'default-catalog-popup', tagName: 'pie-qti-catalog-popup' },\n} satisfies Record<string, { name: string; tagName: string }>;\n\n/**\n * Registry for web components that render QTI interactions\n */\nexport class ComponentRegistry {\n\tprivate components = new Map<string, RegisteredComponent<any>[]>();\n\tprivate definedElements = new Set<string>();\n\tprivate sealed = false;\n\n\t/**\n\t * Register a web component for an interaction type with priority-based dispatch\n\t *\n\t * @param type - QTI interaction type (e.g., 'choiceInteraction', 'textEntryInteraction')\n\t * @param config - Component configuration with priority and canHandle predicate\n\t *\n\t * @example\n\t * // Custom rating choice component with high priority\n\t * registry.register('choiceInteraction', {\n\t * name: 'rating-choice',\n\t * priority: 100,\n\t * description: 'Star rating interactions',\n\t * canHandle: (data) => data.interactionClasses?.includes('rating-interaction'),\n\t * tagName: 'custom-rating-choice',\n\t * componentClass: RatingChoiceInteraction,\n\t * autoRegister: true\n\t * });\n\t *\n\t * // Default choice component\n\t * registry.register('choiceInteraction', {\n\t * name: 'standard-choice',\n\t * tagName: 'qti-choice-interaction'\n\t * });\n\t */\n\tregister<TData extends BaseInteractionData>(\n\t\ttype: string,\n\t\tconfig: ComponentConfig<TData>\n\t): void {\n\t\tthis.assertMutable();\n\t\t// Validate tag name\n\t\tif (!config.tagName.includes('-')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tag name '${config.tagName}'. ` +\n\t\t\t\t\t`Web component tag names must contain a hyphen.`\n\t\t\t);\n\t\t}\n\n\t\tconst registered = this.createRegisteredComponent(config);\n\t\t// Define eagerly in a browser. In a headless compiler there is no custom\n\t\t// element registry, so registration is deferred until the renderer is used.\n\t\tthis.ensureCustomElementDefined(registered.config);\n\n\t\t// Get or create component array for this type\n\t\tlet components = this.components.get(type);\n\t\tif (!components) {\n\t\t\tcomponents = [];\n\t\t\tthis.components.set(type, components);\n\t\t}\n\n\t\t// Add normalized component and sort by priority (highest first)\n\t\tcomponents.push(registered as RegisteredComponent);\n\t\tcomponents.sort((a, b) => b.config.priority - a.config.priority);\n\t}\n\n\tprivate createRegisteredComponent<TData extends BaseInteractionData>(\n\t\tconfig: ComponentConfig<TData>\n\t): RegisteredComponent<TData> {\n\t\treturn Object.freeze({\n\t\t\tconfig: Object.freeze({\n\t\t\t\t...config,\n\t\t\t\tpriority: config.priority ?? 0,\n\t\t\t\tcanHandle: config.canHandle?.bind(config) ?? (() => true),\n\t\t\t}),\n\t\t});\n\t}\n\n\tprivate ensureCustomElementDefined<TData extends BaseInteractionData>(\n\t\tconfig: RegisteredComponent<TData>['config'],\n\t): void {\n\t\tif (\n\t\t\t!config.componentClass ||\n\t\t\tconfig.autoRegister === false ||\n\t\t\tthis.definedElements.has(config.tagName)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = globalThis.customElements;\n\t\tif (!registry) return;\n\t\tif (!registry.get(config.tagName)) {\n\t\t\tregistry.define(config.tagName, config.componentClass);\n\t\t}\n\t\tthis.definedElements.add(config.tagName);\n\t}\n\n\t/**\n\t * Get a web component tag name for an interaction type\n\t * Evaluates canHandle predicates in priority order\n\t *\n\t * @param data - Interaction data\n\t * @returns Web component tag name (e.g., 'qti-choice-interaction')\n\t * @throws Error if no component matches\n\t */\n\tgetTagName<TData extends BaseInteractionData>(data: TData): string {\n\t\tconst components = this.components.get(data.type);\n\n\t\tif (!components || components.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`No component registered for '${data.type}' interaction. ` +\n\t\t\t\t\t`Available types: ${Array.from(this.components.keys()).join(', ')}`\n\t\t\t);\n\t\t}\n\n\t\t// Evaluate canHandle in priority order\n\t\tfor (const { config } of components) {\n\t\t\ttry {\n\t\t\t\tif (config.canHandle(data as any)) {\n\t\t\t\t\tthis.ensureCustomElementDefined(config);\n\t\t\t\t\treturn config.tagName;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next component\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for '${config.name}' component:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// No component matched\n\t\tconst componentList = components\n\t\t\t.map((c) => {\n\t\t\t\tconst desc = c.config.description ? ` (${c.config.description})` : '';\n\t\t\t\treturn `${c.config.name}${desc}`;\n\t\t\t})\n\t\t\t.join(', ');\n\n\t\tthrow new Error(\n\t\t\t`No component available for '${data.type}' interaction.\\n` +\n\t\t\t\t`Registered components: ${componentList}.\\n` +\n\t\t\t\t`None of these components matched the current interaction.`\n\t\t);\n\t}\n\n\t/**\n\t * Get all registered interaction types\n\t * @returns Array of registered interaction type names\n\t */\n\tgetRegisteredTypes(): string[] {\n\t\treturn Array.from(this.components.keys());\n\t}\n\n\t/**\n\t * Check if a component is registered for a type\n\t */\n\thasComponent(type: string): boolean {\n\t\treturn this.components.has(type) && this.components.get(type)!.length > 0;\n\t}\n\n\t/**\n\t * Get the tag name for a registered type by name (no canHandle evaluation).\n\t * Useful for non-interaction components like catalogPopup where the type string\n\t * is known and there is no delivered interaction object to pass.\n\t *\n\t * Returns the highest-priority registered tag name for the type, or null if\n\t * the type is not registered.\n\t */\n\tgetTagNameForType(type: string): string | null {\n\t\tconst components = this.components.get(type);\n\t\tif (!components || components.length === 0) return null;\n\t\tconst config = components[0].config;\n\t\tthis.ensureCustomElementDefined(config);\n\t\treturn config.tagName;\n\t}\n\n\t/** Freeze renderer selection for a compiled AssessmentItem definition. */\n\tseal(): this {\n\t\tthis.sealed = true;\n\t\treturn this;\n\t}\n\n\tisSealed(): boolean {\n\t\treturn this.sealed;\n\t}\n\n\tprivate assertMutable(): void {\n\t\tif (this.sealed) {\n\t\t\tthrow new Error(\n\t\t\t\t'ComponentRegistry is sealed for this AssessmentItem; create a new definition to change renderers',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Create a new component registry\n */\nexport function createComponentRegistry(): ComponentRegistry {\n\tconst registry = new ComponentRegistry();\n\tregisterDefaultComponentTags(registry);\n\treturn registry;\n}\n\n/**\n * Register the default QTI interaction tag names without importing their implementations.\n *\n * Hosts still choose the implementation bundle, typically by importing\n * `@pie-qti/default-components/plugins` in the browser. Keeping only tag metadata here lets\n * the item-player custom element remain the public rendering boundary without depending on\n * Svelte-authored default components.\n */\nexport function registerDefaultComponentTags(registry: ComponentRegistry): void {\n\tfor (const [type, component] of Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE)) {\n\t\tregistry.register(type, {\n\t\t\t...component,\n\t\t\tdescription: `Default web component tag for ${type}`,\n\t\t\tpriority: -100,\n\t\t});\n\t}\n}\n\n/**\n * Plugin interface for registering web components\n */\nexport interface ComponentPlugin {\n\t/** Plugin name (e.g., '@renaissance/rating-choice') */\n\tname: string;\n\n\t/** Plugin version (semver) */\n\tversion: string;\n\n\t/** Plugin description */\n\tdescription: string;\n\n\t/**\n\t * Register web components with the registry\n\t * @param registry - ComponentRegistry instance\n\t */\n\tregister(registry: ComponentRegistry): void;\n}\n"]}
1
+ {"version":3,"file":"ComponentRegistry.js","sourceRoot":"","sources":["../../src/core/ComponentRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,iBAAiB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,EAAE;IACxE,gBAAgB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,E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IAAI,EAAE;YACpD,QAAQ,EAAE,CAAC,GAAG;SACd,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/**\n * Component Registry for Web Component-based Interaction Rendering\n *\n * Provides a pluggable system for registering web components to render\n * different QTI interaction types. Uses priority-based dispatch similar to the\n * ExtractionRegistry, but for framework-agnostic web components.\n */\n\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\n\n/**\n * Configuration for registering a web component renderer\n */\nexport interface ComponentConfig<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\t/** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */\n\tname: string;\n\n\t/**\n\t * Priority for renderer evaluation (higher = checked first)\n\t * - 100: Very specific custom renderers\n\t * - 50: Moderately specific custom renderers\n\t * - 10: Generic custom renderers\n\t * - 0: Default fallback renderers\n\t * Default: 0\n\t */\n\tpriority?: number;\n\n\t/** Optional description for debugging/error messages */\n\tdescription?: string;\n\n\t/**\n\t * Predicate to determine if this component can handle the interaction\n\t * Evaluated in priority order (highest first)\n\t * @returns true if this component should be used\n\t * Default: always true\n\t */\n\tcanHandle?: (data: TData) => boolean;\n\n\t/**\n\t * Web component tag name (must contain a hyphen per web component spec)\n\t * e.g., 'qti-choice-interaction', 'custom-rating-choice'\n\t */\n\ttagName: string;\n\n\t/**\n\t * Optional web component class constructor\n\t * If provided, the component will be automatically registered with customElements\n\t */\n\tcomponentClass?: CustomElementConstructor;\n\n\t/**\n\t * Whether to automatically register the component with customElements\n\t * Default: true if componentClass is provided\n\t */\n\tautoRegister?: boolean;\n}\n\n/**\n * Internal registered component with metadata\n */\ninterface RegisteredComponent<\n\tTData extends BaseInteractionData = BaseInteractionData,\n> {\n\tconfig: ComponentConfig<TData> & {\n\t\tpriority: number;\n\t\tcanHandle: (data: TData) => boolean;\n\t};\n}\n\n/**\n * The default custom-element tag for each block interaction type the player renders, plus\n * `catalogPopup`, the glossary popup. `createComponentRegistry` registers them as fallbacks\n * (tag metadata only), and `@pie-qti/default-components` registers the components it ships\n * under the same tags.\n */\nexport const DEFAULT_COMPONENT_TAGS_BY_TYPE = {\n\tchoiceInteraction: { name: 'default-choice', tagName: 'pie-qti-choice' },\n\tsliderInteraction: { name: 'default-slider', tagName: 'pie-qti-slider' },\n\torderInteraction: { name: 'default-order', tagName: 'pie-qti-order' },\n\tmatchInteraction: { name: 'default-match', tagName: 'pie-qti-match' },\n\tassociateInteraction: { name: 'default-associate', tagName: 'pie-qti-associate' },\n\tgapMatchInteraction: { name: 'default-gap-match', tagName: 'pie-qti-gap-match' },\n\thotspotInteraction: { name: 'default-hotspot', tagName: 'pie-qti-hotspot' },\n\thottextInteraction: { name: 'default-hottext', tagName: 'pie-qti-hottext' },\n\tmediaInteraction: { name: 'default-media', tagName: 'pie-qti-media' },\n\tcustomInteraction: { name: 'default-custom', tagName: 'pie-qti-custom' },\n\tportableCustomInteraction: { name: 'default-portable-custom', tagName: 'pie-qti-portable-custom' },\n\tendAttemptInteraction: { name: 'default-end-attempt', tagName: 'pie-qti-end-attempt' },\n\tpositionObjectInteraction: { name: 'default-position-object', tagName: 'pie-qti-position-object' },\n\tgraphicGapMatchInteraction: { name: 'default-graphic-gap-match', tagName: 'pie-qti-graphic-gap-match' },\n\tgraphicOrderInteraction: { name: 'default-graphic-order', tagName: 'pie-qti-graphic-order' },\n\tgraphicAssociateInteraction: { name: 'default-graphic-associate', tagName: 'pie-qti-graphic-associate' },\n\tselectPointInteraction: { name: 'default-select-point', tagName: 'pie-qti-select-point' },\n\textendedTextInteraction: { name: 'default-extended-text', tagName: 'pie-qti-extended-text' },\n\tuploadInteraction: { name: 'default-upload', tagName: 'pie-qti-upload' },\n\tdrawingInteraction: { name: 'default-drawing', tagName: 'pie-qti-drawing' },\n\tcatalogPopup: { name: 'default-catalog-popup', tagName: 'pie-qti-catalog-popup' },\n} as const satisfies Record<string, { readonly name: string; readonly tagName: string }>;\n\n/**\n * Registry for web components that render QTI interactions\n */\nexport class ComponentRegistry {\n\tprivate components = new Map<string, RegisteredComponent<any>[]>();\n\tprivate definedElements = new Set<string>();\n\tprivate sealed = false;\n\n\t/**\n\t * Register a web component for an interaction type with priority-based dispatch\n\t *\n\t * @param type - QTI interaction type (e.g., 'choiceInteraction', 'textEntryInteraction')\n\t * @param config - Component configuration with priority and canHandle predicate\n\t *\n\t * @example\n\t * // Custom rating choice component with high priority\n\t * registry.register('choiceInteraction', {\n\t * name: 'rating-choice',\n\t * priority: 100,\n\t * description: 'Star rating interactions',\n\t * canHandle: (data) => data.interactionClasses?.includes('rating-interaction'),\n\t * tagName: 'custom-rating-choice',\n\t * componentClass: RatingChoiceInteraction,\n\t * autoRegister: true\n\t * });\n\t *\n\t * // Default choice component\n\t * registry.register('choiceInteraction', {\n\t * name: 'standard-choice',\n\t * tagName: 'qti-choice-interaction'\n\t * });\n\t */\n\tregister<TData extends BaseInteractionData>(\n\t\ttype: string,\n\t\tconfig: ComponentConfig<TData>\n\t): void {\n\t\tthis.assertMutable();\n\t\t// Validate tag name\n\t\tif (!config.tagName.includes('-')) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tag name '${config.tagName}'. ` +\n\t\t\t\t\t`Web component tag names must contain a hyphen.`\n\t\t\t);\n\t\t}\n\n\t\tconst registered = this.createRegisteredComponent(config);\n\t\t// Define eagerly in a browser. In a headless compiler there is no custom\n\t\t// element registry, so registration is deferred until the renderer is used.\n\t\tthis.ensureCustomElementDefined(registered.config);\n\n\t\t// Get or create component array for this type\n\t\tlet components = this.components.get(type);\n\t\tif (!components) {\n\t\t\tcomponents = [];\n\t\t\tthis.components.set(type, components);\n\t\t}\n\n\t\t// Add normalized component and sort by priority (highest first)\n\t\tcomponents.push(registered as RegisteredComponent);\n\t\tcomponents.sort((a, b) => b.config.priority - a.config.priority);\n\t}\n\n\tprivate createRegisteredComponent<TData extends BaseInteractionData>(\n\t\tconfig: ComponentConfig<TData>\n\t): RegisteredComponent<TData> {\n\t\treturn Object.freeze({\n\t\t\tconfig: Object.freeze({\n\t\t\t\t...config,\n\t\t\t\tpriority: config.priority ?? 0,\n\t\t\t\tcanHandle: config.canHandle?.bind(config) ?? (() => true),\n\t\t\t}),\n\t\t});\n\t}\n\n\tprivate ensureCustomElementDefined<TData extends BaseInteractionData>(\n\t\tconfig: RegisteredComponent<TData>['config'],\n\t): void {\n\t\tif (\n\t\t\t!config.componentClass ||\n\t\t\tconfig.autoRegister === false ||\n\t\t\tthis.definedElements.has(config.tagName)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = globalThis.customElements;\n\t\tif (!registry) return;\n\t\tif (!registry.get(config.tagName)) {\n\t\t\tregistry.define(config.tagName, config.componentClass);\n\t\t}\n\t\tthis.definedElements.add(config.tagName);\n\t}\n\n\t/**\n\t * Get a web component tag name for an interaction type\n\t * Evaluates canHandle predicates in priority order\n\t *\n\t * @param data - Interaction data\n\t * @returns Web component tag name (e.g., 'qti-choice-interaction')\n\t * @throws Error if no component matches\n\t */\n\tgetTagName<TData extends BaseInteractionData>(data: TData): string {\n\t\tconst components = this.components.get(data.type);\n\n\t\tif (!components || components.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`No component registered for '${data.type}' interaction. ` +\n\t\t\t\t\t`Available types: ${Array.from(this.components.keys()).join(', ')}`\n\t\t\t);\n\t\t}\n\n\t\t// Evaluate canHandle in priority order\n\t\tfor (const { config } of components) {\n\t\t\ttry {\n\t\t\t\tif (config.canHandle(data as any)) {\n\t\t\t\t\tthis.ensureCustomElementDefined(config);\n\t\t\t\t\treturn config.tagName;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\t// Log but continue to next component\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`canHandle() failed for '${config.name}' component:`,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// No component matched\n\t\tconst componentList = components\n\t\t\t.map((c) => {\n\t\t\t\tconst desc = c.config.description ? ` (${c.config.description})` : '';\n\t\t\t\treturn `${c.config.name}${desc}`;\n\t\t\t})\n\t\t\t.join(', ');\n\n\t\tthrow new Error(\n\t\t\t`No component available for '${data.type}' interaction.\\n` +\n\t\t\t\t`Registered components: ${componentList}.\\n` +\n\t\t\t\t`None of these components matched the current interaction.`\n\t\t);\n\t}\n\n\t/**\n\t * Get all registered interaction types\n\t * @returns Array of registered interaction type names\n\t */\n\tgetRegisteredTypes(): string[] {\n\t\treturn Array.from(this.components.keys());\n\t}\n\n\t/**\n\t * Check if a component is registered for a type\n\t */\n\thasComponent(type: string): boolean {\n\t\treturn this.components.has(type) && this.components.get(type)!.length > 0;\n\t}\n\n\t/**\n\t * Get the tag name for a registered type by name (no canHandle evaluation).\n\t * Useful for non-interaction components like catalogPopup where the type string\n\t * is known and there is no delivered interaction object to pass.\n\t *\n\t * Returns the highest-priority registered tag name for the type, or null if\n\t * the type is not registered.\n\t */\n\tgetTagNameForType(type: string): string | null {\n\t\tconst components = this.components.get(type);\n\t\tif (!components || components.length === 0) return null;\n\t\tconst config = components[0].config;\n\t\tthis.ensureCustomElementDefined(config);\n\t\treturn config.tagName;\n\t}\n\n\t/** Freeze renderer selection for a compiled AssessmentItem definition. */\n\tseal(): this {\n\t\tthis.sealed = true;\n\t\treturn this;\n\t}\n\n\tisSealed(): boolean {\n\t\treturn this.sealed;\n\t}\n\n\tprivate assertMutable(): void {\n\t\tif (this.sealed) {\n\t\t\tthrow new Error(\n\t\t\t\t'ComponentRegistry is sealed for this AssessmentItem; create a new definition to change renderers',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Create a new component registry\n */\nexport function createComponentRegistry(): ComponentRegistry {\n\tconst registry = new ComponentRegistry();\n\tregisterDefaultComponentTags(registry);\n\treturn registry;\n}\n\n/**\n * Register the default QTI interaction tag names without importing their implementations.\n *\n * Hosts still choose the implementation bundle, typically by importing\n * `@pie-qti/default-components/plugins` in the browser. Keeping only tag metadata here lets\n * the item-player custom element remain the public rendering boundary without depending on\n * Svelte-authored default components.\n */\nexport function registerDefaultComponentTags(registry: ComponentRegistry): void {\n\tfor (const [type, component] of Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE)) {\n\t\tregistry.register(type, {\n\t\t\t...component,\n\t\t\tdescription: `Default web component tag for ${type}`,\n\t\t\tpriority: -100,\n\t\t});\n\t}\n}\n\n/**\n * Plugin interface for registering web components\n */\nexport interface ComponentPlugin {\n\t/** Plugin name (e.g., '@renaissance/rating-choice') */\n\tname: string;\n\n\t/** Plugin version (semver) */\n\tversion: string;\n\n\t/** Plugin description */\n\tdescription: string;\n\n\t/**\n\t * Register web components with the registry\n\t * @param registry - ComponentRegistry instance\n\t */\n\tregister(registry: ComponentRegistry): void;\n}\n"]}
@@ -22,11 +22,24 @@ export interface OpenItemSessionOptions {
22
22
  presentation?: ItemSessionPresentationPolicy;
23
23
  }
24
24
  export interface ItemSessionPresentationPolicy {
25
- /** False hides integrated feedback (`showFeedback="false"`). Defaults to true. */
25
+ /**
26
+ * False hides integrated feedback (`feedbackInline` / `feedbackBlock`), as
27
+ * `itemSessionControl@showFeedback="false"` requires. An assessment host passes the test's
28
+ * item session control here; standalone delivery through `ItemPlayer` defaults to the QTI
29
+ * default (hidden) unless the host opts in.
30
+ */
26
31
  showFeedback?: boolean;
27
32
  /** True shows correct responses once the attempt has ended (`showSolution="true"`). */
28
33
  showSolution?: boolean;
29
34
  }
35
+ /**
36
+ * Opening a session with responses the item does not declare. Hosts that re-use an item
37
+ * element across items can catch this to drop responses that belonged to the previous item.
38
+ */
39
+ export declare class UnknownResponseIdentifierError extends Error {
40
+ readonly identifier: string;
41
+ constructor(identifier: string);
42
+ }
30
43
  export type ItemSessionCommand = ItemSessionActionCommand | {
31
44
  action: 'setResponse';
32
45
  responseIdentifier: string;
@@ -48,6 +61,10 @@ export interface ItemSessionView {
48
61
  readonly lifecycleStatus: ItemLifecycleStatus;
49
62
  readonly completionStatus: CompletionStatus;
50
63
  readonly numAttempts: number;
64
+ /**
65
+ * Time on task in milliseconds. `context.duration`, the QTI built-in variable, holds the same
66
+ * time in seconds.
67
+ */
51
68
  readonly duration: number;
52
69
  readonly adaptive: boolean;
53
70
  readonly completed: boolean;
@@ -1,5 +1,17 @@
1
1
  import { createItemPresentation, } from '../presentation/itemPresentationPlan.js';
2
- import { createPlayerFromPreparedInternal, Player } from './Player.js';
2
+ import { deepFreezeInPlace, frozenSnapshot, withFreshTypedArrays } from '../utils/cloneFreeze.js';
3
+ import { createPlayerFromPreparedInternal } from './Player.js';
4
+ /**
5
+ * Opening a session with responses the item does not declare. Hosts that re-use an item
6
+ * element across items can catch this to drop responses that belonged to the previous item.
7
+ */
8
+ export class UnknownResponseIdentifierError extends Error {
9
+ constructor(identifier) {
10
+ super(`Unknown response identifier '${identifier}'`);
11
+ this.name = 'UnknownResponseIdentifierError';
12
+ this.identifier = identifier;
13
+ }
14
+ }
3
15
  /**
4
16
  * Browser adapters use this without gaining access to the private session engine.
5
17
  * @internal
@@ -29,9 +41,7 @@ export class LiveItemSession {
29
41
  ...(options.contextVariables ? { contextVariables: options.contextVariables } : {}),
30
42
  ...(options.templateDefaults ? { templateDefaults: options.templateDefaults } : {}),
31
43
  };
32
- this.player = prepared
33
- ? createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore))
34
- : new Player(playerConfig);
44
+ this.player = createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore));
35
45
  try {
36
46
  if (options.responses) {
37
47
  this.assertKnownResponseIdentifiers(Object.keys(options.responses));
@@ -57,7 +67,7 @@ export class LiveItemSession {
57
67
  this.runtimeBinding = this.createBinding();
58
68
  }
59
69
  state() {
60
- return immutableSnapshot(this.currentView);
70
+ return frozenSnapshot(this.currentView);
61
71
  }
62
72
  dispatch(command) {
63
73
  this.assertActive();
@@ -86,7 +96,9 @@ export class LiveItemSession {
86
96
  this.currentView = this.captureView(result?.sessionState);
87
97
  const transition = freezeTransition({ command, previous, current: this.currentView, result });
88
98
  this.notify(transition);
89
- return transition;
99
+ // The returned hand-out isolates the typed-array leaves for the caller, exactly as
100
+ // each listener's copy does (see notify and withFreshTypedArrays).
101
+ return withFreshTypedArrays(transition);
90
102
  }
91
103
  present(view = {}) {
92
104
  this.assertActive();
@@ -108,8 +120,8 @@ export class LiveItemSession {
108
120
  security: this.player.getSecurityConfig(),
109
121
  directRubrics: this.player.getRubrics({ scope: 'direct' }),
110
122
  },
111
- responses: immutableSnapshot(this.currentView.responses),
112
- outcomeValues: immutableSnapshot(this.currentView.outcomes),
123
+ responses: frozenSnapshot(this.currentView.responses),
124
+ outcomeValues: frozenSnapshot(this.currentView.outcomes),
113
125
  role: this.defaultRole,
114
126
  });
115
127
  }
@@ -120,7 +132,7 @@ export class LiveItemSession {
120
132
  }
121
133
  serialize() {
122
134
  this.assertActive();
123
- return immutableSnapshot(this.player.saveItemSession());
135
+ return frozenSnapshot(this.player.saveItemSession());
124
136
  }
125
137
  /**
126
138
  * Browser/runtime capabilities carried by the session across package bundles.
@@ -136,7 +148,9 @@ export class LiveItemSession {
136
148
  const previous = this.currentView;
137
149
  this.disposed = true;
138
150
  this.revision += 1;
139
- this.currentView = immutableSnapshot({
151
+ // The previous view is deeply frozen, so the disposed view can share its variable
152
+ // records; only the new shell needs freezing.
153
+ this.currentView = deepFreezeInPlace({
140
154
  ...previous,
141
155
  revision: this.revision,
142
156
  disposed: true,
@@ -149,9 +163,19 @@ export class LiveItemSession {
149
163
  }));
150
164
  this.listeners.clear();
151
165
  }
166
+ /**
167
+ * Builds the immutable view a dispatch hands out. The variable records come from the
168
+ * serializer, whose values are per-call copies already independent of the engine (see
169
+ * qtiValueToSerializable) — freezing them in place needs no second clone. The shell is
170
+ * frozen around them, which leaves the frozen records untouched.
171
+ *
172
+ * `canSubmit` validates the engine's own response snapshot record: the same record the
173
+ * serializer's validation step used, so within one dispatch the validation memo hits and
174
+ * the responses are walked once.
175
+ */
152
176
  captureView(serialized = this.player.saveItemSession()) {
153
- const responses = valuesOf(serialized.responseVariables);
154
- return immutableSnapshot({
177
+ const responses = frozenValuesOf(serialized.responseVariables);
178
+ return deepFreezeInPlace({
155
179
  revision: this.revision,
156
180
  itemIdentifier: serialized.itemIdentifier || this.itemIdentifier || undefined,
157
181
  role: this.defaultRole,
@@ -161,12 +185,12 @@ export class LiveItemSession {
161
185
  duration: serialized.duration,
162
186
  adaptive: this.player.isAdaptive(),
163
187
  completed: this.player.isCompleted(),
164
- canSubmit: this.player.canSubmitResponses(responses),
188
+ canSubmit: this.player.canSubmitResponses(this.player.responseSnapshot()),
165
189
  disposed: this.disposed,
166
190
  responses,
167
- outcomes: valuesOf(serialized.outcomeVariables),
168
- templates: valuesOf(serialized.templateVariables),
169
- context: valuesOf(serialized.contextVariables),
191
+ outcomes: frozenValuesOf(serialized.outcomeVariables),
192
+ templates: frozenValuesOf(serialized.templateVariables),
193
+ context: frozenValuesOf(serialized.contextVariables),
170
194
  });
171
195
  }
172
196
  createBinding() {
@@ -204,6 +228,14 @@ export class LiveItemSession {
204
228
  this.assertActive();
205
229
  return this.player.getSecurityConfig();
206
230
  },
231
+ getResponseIdentifiersPrintedInContent: () => {
232
+ this.assertActive();
233
+ return this.player.getResponseIdentifiersPrintedInContent();
234
+ },
235
+ getContextIdentifiersPrintedInContent: () => {
236
+ this.assertActive();
237
+ return this.player.getContextIdentifiersPrintedInContent();
238
+ },
207
239
  getI18nProvider: () => {
208
240
  this.assertActive();
209
241
  return this.player.getI18nProvider();
@@ -232,10 +264,19 @@ export class LiveItemSession {
232
264
  },
233
265
  });
234
266
  }
267
+ /**
268
+ * Every listener receives a deeply frozen transition, and one whose unfreezable
269
+ * typed-array leaves are its own: the frozen plain structure is shared across listeners
270
+ * (no listener can observe another's view of it through mutation — freezing forbids it),
271
+ * while each hand-out re-copies the leaves no platform can freeze (withFreshTypedArrays).
272
+ * A dispatch without such leaves — every keystroke on ordinary items — hands the same
273
+ * frozen object to every listener and clones nothing. A listener that must keep an owned
274
+ * copy of the whole view uses `state()`.
275
+ */
235
276
  notify(transition) {
236
277
  for (const listener of [...this.listeners]) {
237
278
  try {
238
- listener(immutableSnapshot(transition));
279
+ listener(withFreshTypedArrays(transition));
239
280
  }
240
281
  catch (error) {
241
282
  console.error('[QTI ItemSession] subscriber failed:', error);
@@ -250,7 +291,7 @@ export class LiveItemSession {
250
291
  const knownIdentifiers = new Set(Object.keys(this.player.getResponses()));
251
292
  const unknown = responseIdentifiers.find((identifier) => !knownIdentifiers.has(identifier));
252
293
  if (unknown)
253
- throw new Error(`Unknown response identifier '${unknown}'`);
294
+ throw new UnknownResponseIdentifierError(unknown);
254
295
  }
255
296
  }
256
297
  function isResponseWritableLifecycle(status) {
@@ -268,33 +309,30 @@ function describeCommand(command) {
268
309
  ? 'update responses'
269
310
  : `run ${command.action}`;
270
311
  }
271
- function valuesOf(variables) {
312
+ /**
313
+ * The view's variable values, frozen for hand-out. The serializer's values are per-call
314
+ * copies independent of the engine, so freezing them in place needs no clone of its own.
315
+ */
316
+ function frozenValuesOf(variables) {
272
317
  return Object.fromEntries(Object.entries(variables).map(([identifier, variable]) => [
273
318
  identifier,
274
- immutableSnapshot(variable.value),
319
+ deepFreezeInPlace(variable.value),
275
320
  ]));
276
321
  }
322
+ /**
323
+ * Freezes a dispatch's transition for hand-out. The previous and current views are deeply
324
+ * frozen already (captureView, dispose) and freeze in place for free. The command and the
325
+ * action result are engine output owned by this dispatch — the command is copied (it is the
326
+ * caller's object and carries the candidate's submitted value), while the result's serialized
327
+ * session state and validation/scoring results are per-call copies that freeze in place;
328
+ * the memoized base-validation result is shared with the engine's memo, which never mutates
329
+ * a result once built. What remains unfrozen are only the leaves no platform can freeze
330
+ * (typed arrays), as everywhere else in the clone/freeze family.
331
+ */
277
332
  function freezeTransition(transition) {
278
- return immutableSnapshot(transition);
279
- }
280
- /** Clone and freeze plain data without mutating values owned by the caller or a PCI module. */
281
- function immutableSnapshot(value) {
282
- if (Array.isArray(value)) {
283
- return Object.freeze(value.map((entry) => immutableSnapshot(entry)));
284
- }
285
- if (!value || typeof value !== 'object')
286
- return value;
287
- if (ArrayBuffer.isView(value))
288
- return structuredClone(value);
289
- if (value instanceof ArrayBuffer)
290
- return value.slice(0);
291
- const prototype = Object.getPrototypeOf(value);
292
- if (prototype !== Object.prototype && prototype !== null)
293
- return value;
294
- const snapshot = Object.fromEntries(Object.entries(value).map(([key, entry]) => [
295
- key,
296
- immutableSnapshot(entry),
297
- ]));
298
- return Object.freeze(snapshot);
333
+ return deepFreezeInPlace({
334
+ ...transition,
335
+ command: frozenSnapshot(transition.command),
336
+ });
299
337
  }
300
338
  //# sourceMappingURL=ItemSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ItemSession.js","sourceRoot":"","sources":["../../src/core/ItemSession.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,sBAAsB,GAGtB,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA6GvE;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAoB;IACzD,MAAM,cAAc,GAAG,OAEtB,CAAC;IACF,IAAI,OAAO,cAAc,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,cAAc,CAAC,iBAAiB,EAAE,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,eAAe;IAU3B,mFAAmF;IACnF,YACkB,cAAsB,EACvC,MAA+B,EAC/B,UAAkC,EAAE,EACpC,QAAkB;QAHD,mBAAc,GAAd,cAAc,CAAQ;QAVvB,cAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;QAGpD,aAAQ,GAAG,CAAC,CAAC;QACb,aAAQ,GAAG,KAAK,CAAC;QAWxB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,WAAW,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QAChD,MAAM,Y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AC,EAAE,EAAE,CAAC;QACtE,GAAG;QACH,iBAAiB,CAAC,KAAK,CAAC;KACxB,CAAC,CACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAM,CAAC;AACrC,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PnpProfile } from '../pnp/types.js';\nimport type { ExtractedPci, PciHostController } from '../pci/types.js';\nimport {\n\tcreateItemPresentation,\n\ttype CreateItemPresentationOptions,\n\ttype ItemPresentation,\n} from '../presentation/itemPresentationPlan.js';\nimport type {\n\tCompletionStatus,\n\tHtmlContent,\n\tItemLifecycleStatus,\n\tItemSessionActionCommand,\n\tItemSessionActionResult,\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIRole,\n\tSerializedItemSessionState,\n\tSerializedItemSessionVariable,\n} from '../types/index.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\nimport { createPlayerFromPreparedInternal, Player } from './Player.js';\n\nexport interface OpenItemSessionOptions {\n\t/** Restore a previously serialized state before applying response overrides. */\n\trestore?: SerializedItemSessionState;\n\t/** Initial responses, or overrides applied after restore. */\n\tresponses?: Readonly<Record<string, unknown>>;\n\t/** Resume a suspended handoff as an active interaction session. */\n\tactivate?: boolean;\n\t/**\n\t * Values for the item's context variables, e.g. `QTI_CONTEXT`, set before template processing.\n\t * A restored session keeps its saved context values.\n\t */\n\tcontextVariables?: Readonly<Record<string, unknown>>;\n\t/**\n\t * Default values for template variables, set before template processing, as an\n\t * assessmentItemRef's `templateDefault` requires. A restored session keeps its saved values.\n\t */\n\ttemplateDefaults?: Readonly<Record<string, unknown>>;\n\t/** Test-level item session control applied by `present()`. */\n\tpresentation?: ItemSessionPresentationPolicy;\n}\n\nexport interface ItemSessionPresentationPolicy {\n\t/** False hides integrated feedback (`showFeedback=\"false\"`). Defaults to true. */\n\tshowFeedback?: boolean;\n\t/** True shows correct responses once the attempt has ended (`showSolution=\"true\"`). */\n\tshowSolution?: boolean;\n}\n\nexport type ItemSessionCommand =\n\t| ItemSessionActionCommand\n\t| { action: 'setResponse'; responseIdentifier: string; value: unknown }\n\t| { action: 'setResponses'; responses: Readonly<Record<string, unknown>> }\n\t| { action: 'updatePnp'; profile: Partial<PnpProfile> };\n\nexport type ItemSessionEventCommand = ItemSessionCommand | { action: 'dispose' };\n\nexport interface ItemSessionView {\n\treadonly revision: number;\n\treadonly itemIdentifier?: string;\n\treadonly role: QTIRole;\n\treadonly lifecycleStatus: ItemLifecycleStatus;\n\treadonly completionStatus: CompletionStatus;\n\treadonly numAttempts: number;\n\treadonly duration: number;\n\treadonly adaptive: boolean;\n\treadonly completed: boolean;\n\treadonly canSubmit: boolean;\n\treadonly disposed: boolean;\n\treadonly responses: Readonly<Record<string, unknown>>;\n\treadonly outcomes: Readonly<Record<string, unknown>>;\n\treadonly templates: Readonly<Record<string, unknown>>;\n\treadonly context: Readonly<Record<string, unknown>>;\n}\n\nexport interface ItemSessionTransition {\n\treadonly command: ItemSessionEventCommand;\n\treadonly previous: ItemSessionView;\n\treadonly current: ItemSessionView;\n\treadonly result?: ItemSessionActionResult;\n}\n\nexport type ItemSessionListener = (transition: ItemSessionTransition) => void;\n\nexport type ItemPresentationView = Omit<\n\tCreateItemPresentationOptions,\n\t'outcomeValues' | 'responses' | 'role' | 'source' | 'showFeedback' | 'showSolution'\n>;\n\nexport interface ItemSession {\n\tstate(): ItemSessionView;\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition;\n\tpresent(view?: ItemPresentationView): ItemPresentation;\n\tsubscribe(listener: ItemSessionListener): () => void;\n\tserialize(): SerializedItemSessionState;\n\tdispose(): void;\n}\n\n/**\n * Narrow browser/runtime capabilities needed after a presentation has been produced.\n * This interface deliberately excludes Player, parser nodes, declarations, and extraction registries.\n * @internal\n */\nexport interface ItemSessionBinding {\n\treadonly role: QTIRole;\n\tapplyPnp(root: HTMLElement): void;\n\tgetPnp(): PnpProfile | undefined;\n\tonPnpChange(listener: () => void): () => void;\n\tgetCatalogEntry(\n\t\tidref: string,\n\t\tusage: string,\n\t\tlang?: string,\n\t\toptions?: { stimulusIdentifier?: string }\n\t): HtmlContent | null;\n\tgetContentLanguage(): string | undefined;\n\tgetComponentRegistry(): ItemSessionComponentRegistry;\n\tgetDeliveryContext(): ResolvedItemDeliveryContext | undefined;\n\tgetSecurityConfig(): PlayerSecurityConfig | undefined;\n\tgetI18nProvider(): unknown;\n\tcreatePciHost(data: ExtractedPci): PciHostController;\n}\n\n/** @internal */\nexport interface ItemSessionComponentRegistry {\n\tgetTagName(interaction: BaseInteractionData): string;\n\tgetTagNameForType(type: string): string | null;\n}\n\n/**\n * Browser adapters use this without gaining access to the private session engine.\n * @internal\n */\nexport function getItemSessionBinding(session: ItemSession): ItemSessionBinding {\n\tconst runtimeSession = session as ItemSession & {\n\t\tgetRuntimeBinding?: () => ItemSessionBinding;\n\t};\n\tif (typeof runtimeSession.getRuntimeBinding !== 'function') {\n\t\tthrow new Error('ItemSession runtime binding is unavailable');\n\t}\n\treturn runtimeSession.getRuntimeBinding();\n}\n\n/**\n * Construct sessions through AssessmentItemDefinition.openSession().\n * @internal\n */\nexport class LiveItemSession implements ItemSession {\n\tprivate readonly player: Player;\n\tprivate readonly listeners = new Set<ItemSessionListener>();\n\tprivate readonly defaultRole: QTIRole;\n\tprivate readonly presentation: ItemSessionPresentationPolicy;\n\tprivate revision = 0;\n\tprivate disposed = false;\n\tprivate currentView: ItemSessionView;\n\tprivate readonly runtimeBinding: ItemSessionBinding;\n\n\t/** @internal Construct sessions through AssessmentItemDefinition.openSession(). */\n\tconstructor(\n\t\tprivate readonly itemIdentifier: string,\n\t\tconfig: ItemSessionEngineConfig,\n\t\toptions: OpenItemSessionOptions = {},\n\t\tprepared?: unknown,\n\t) {\n\t\tthis.defaultRole = config.role ?? 'candidate';\n\t\tthis.presentation = { ...options.presentation };\n\t\tconst playerConfig = {\n\t\t\t...config,\n\t\t\t...(options.contextVariables ? { contextVariables: options.contextVariables } : {}),\n\t\t\t...(options.templateDefaults ? { templateDefaults: options.templateDefaults } : {}),\n\t\t};\n\t\tthis.player = prepared\n\t\t\t? createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore))\n\t\t\t: new Player(playerConfig);\n\n\t\ttry {\n\t\t\tif (options.responses) {\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(options.responses));\n\t\t\t}\n\t\t\tif (options.restore) this.player.restoreItemSession(options.restore);\n\t\t\tif (options.activate && this.player.getLifecycleStatus() === 'suspended') {\n\t\t\t\tthis.player.activateAttempt();\n\t\t\t}\n\t\t\tif (options.responses) {\n\t\t\t\tconst lifecycle = this.player.getLifecycleStatus();\n\t\t\t\tif (!isResponseWritableLifecycle(lifecycle)) {\n\t\t\t\t\tthrow new Error(`Cannot override responses while item session is ${lifecycle}`);\n\t\t\t\t}\n\t\t\t\tthis.player.setResponses({ ...options.responses });\n\t\t\t}\n\t\t\tthis.currentView = this.captureView();\n\t\t} catch (error) {\n\t\t\tthis.player.destroy();\n\t\t\tthrow error;\n\t\t}\n\n\t\tthis.runtimeBinding = this.createBinding();\n\t}\n\n\tstate(): ItemSessionView {\n\t\treturn immutableSnapshot(this.currentView);\n\t}\n\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition {\n\t\tthis.assertActive();\n\t\tif (\n\t\t\tcommandRequiresWritableLifecycle(command) &&\n\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot ${describeCommand(command)} while item session is ${this.currentView.lifecycleStatus}`\n\t\t\t);\n\t\t}\n\t\tconst previous = this.currentView;\n\t\tlet result: ItemSessionActionResult | undefined;\n\n\t\tswitch (command.action) {\n\t\t\tcase 'setResponse':\n\t\t\t\tthis.assertKnownResponseIdentifiers([command.responseIdentifier]);\n\t\t\t\tthis.player.setResponses({ [command.responseIdentifier]: command.value });\n\t\t\t\tbreak;\n\t\t\tcase 'setResponses':\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(command.responses));\n\t\t\t\tthis.player.setResponses({ ...command.responses });\n\t\t\t\tbreak;\n\t\t\tcase 'updatePnp':\n\t\t\t\tthis.player.updatePnp(command.profile);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tresult = this.player.runItemSessionAction(command);\n\t\t}\n\n\t\tthis.revision += 1;\n\t\tthis.currentView = this.captureView(result?.sessionState);\n\t\tconst transition = freezeTransition({ command, previous, current: this.currentView, result });\n\t\tthis.notify(transition);\n\t\treturn transition;\n\t}\n\n\tpresent(view: ItemPresentationView = {}): ItemPresentation {\n\t\tthis.assertActive();\n\t\tconst lifecycle = this.currentView.lifecycleStatus;\n\t\tconst attemptEnded = !isResponseWritableLifecycle(lifecycle) && lifecycle !== 'suspended';\n\t\treturn createItemPresentation({\n\t\t\t...view,\n\t\t\tdisabled: view.disabled === true || !isResponseWritableLifecycle(lifecycle),\n\t\t\tshowFeedback: this.presentation.showFeedback !== false,\n\t\t\tshowSolution: this.presentation.showSolution === true && attemptEnded,\n\t\t\tsource: {\n\t\t\t\titemBodyHtml: this.player.getItemBodyHtml(),\n\t\t\t\tcontentLanguage: this.player.getContentLanguage(),\n\t\t\t\tinteractions: this.player.getInteractionData(),\n\t\t\t\tcorrectResponses: this.player.getCorrectResponses(),\n\t\t\t\tcomponentRegistry: this.player.getComponentRegistry(),\n\t\t\t\tdeliveryContext: this.player.getDeliveryContext(),\n\t\t\t\tpnp: this.player.getPnp(),\n\t\t\t\tsecurity: this.player.getSecurityConfig(),\n\t\t\t\tdirectRubrics: this.player.getRubrics({ scope: 'direct' }),\n\t\t\t},\n\t\t\tresponses: immutableSnapshot(this.currentView.responses),\n\t\t\toutcomeValues: immutableSnapshot(this.currentView.outcomes),\n\t\t\trole: this.defaultRole,\n\t\t});\n\t}\n\n\tsubscribe(listener: ItemSessionListener): () => void {\n\t\tthis.assertActive();\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tserialize(): SerializedItemSessionState {\n\t\tthis.assertActive();\n\t\treturn immutableSnapshot(this.player.saveItemSession());\n\t}\n\n\t/**\n\t * Browser/runtime capabilities carried by the session across package bundles.\n\t * @internal\n\t */\n\tgetRuntimeBinding(): ItemSessionBinding {\n\t\tthis.assertActive();\n\t\treturn this.runtimeBinding;\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tconst previous = this.currentView;\n\t\tthis.disposed = true;\n\t\tthis.revision += 1;\n\t\tthis.currentView = immutableSnapshot({\n\t\t\t...previous,\n\t\t\trevision: this.revision,\n\t\t\tdisposed: true,\n\t\t});\n\t\tthis.player.destroy();\n\t\tthis.notify(\n\t\t\tfreezeTransition({\n\t\t\t\tcommand: { action: 'dispose' },\n\t\t\t\tprevious,\n\t\t\t\tcurrent: this.currentView,\n\t\t\t})\n\t\t);\n\t\tthis.listeners.clear();\n\t}\n\n\tprivate captureView(serialized = this.player.saveItemSession()): ItemSessionView {\n\t\tconst responses = valuesOf(serialized.responseVariables);\n\t\treturn immutableSnapshot({\n\t\t\trevision: this.revision,\n\t\t\titemIdentifier: serialized.itemIdentifier || this.itemIdentifier || undefined,\n\t\t\trole: this.defaultRole,\n\t\t\tlifecycleStatus: serialized.lifecycleStatus,\n\t\t\tcompletionStatus: serialized.completionStatus,\n\t\t\tnumAttempts: serialized.numAttempts,\n\t\t\tduration: serialized.duration,\n\t\t\tadaptive: this.player.isAdaptive(),\n\t\t\tcompleted: this.player.isCompleted(),\n\t\t\tcanSubmit: this.player.canSubmitResponses(responses),\n\t\t\tdisposed: this.disposed,\n\t\t\tresponses,\n\t\t\toutcomes: valuesOf(serialized.outcomeVariables),\n\t\t\ttemplates: valuesOf(serialized.templateVariables),\n\t\t\tcontext: valuesOf(serialized.contextVariables),\n\t\t});\n\t}\n\n\tprivate createBinding(): ItemSessionBinding {\n\t\treturn Object.freeze({\n\t\t\trole: this.defaultRole,\n\t\t\tapplyPnp: (root: HTMLElement) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tthis.player.applyPnp(root);\n\t\t\t},\n\t\t\tgetPnp: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getPnp();\n\t\t\t},\n\t\t\tonPnpChange: (listener: () => void) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.onPnpChange(() => listener());\n\t\t\t},\n\t\t\tgetContentLanguage: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getContentLanguage();\n\t\t\t},\n\t\t\tgetCatalogEntry: (\n\t\t\t\tidref: string,\n\t\t\t\tusage: string,\n\t\t\t\tlang?: string,\n\t\t\t\toptions?: { stimulusIdentifier?: string }\n\t\t\t) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getCatalogEntry(idref, usage, lang, options);\n\t\t\t},\n\t\t\tgetComponentRegistry: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getComponentRegistry();\n\t\t\t},\n\t\t\tgetDeliveryContext: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getDeliveryContext();\n\t\t\t},\n\t\t\tgetSecurityConfig: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getSecurityConfig();\n\t\t\t},\n\t\t\tgetI18nProvider: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getI18nProvider();\n\t\t\t},\n\t\t\tcreatePciHost: (data: ExtractedPci) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tconst host = this.player.createPciHost(data);\n\t\t\t\thost.onResponseChange(() => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.disposed ||\n\t\t\t\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t\t\t\t) return;\n\t\t\t\t\tconst previous = this.currentView;\n\t\t\t\t\tthis.revision += 1;\n\t\t\t\t\tthis.currentView = this.captureView();\n\t\t\t\t\tthis.notify(\n\t\t\t\t\t\tfreezeTransition({\n\t\t\t\t\t\t\tcommand: {\n\t\t\t\t\t\t\t\taction: 'setResponse',\n\t\t\t\t\t\t\t\tresponseIdentifier: data.responseIdentifier,\n\t\t\t\t\t\t\t\tvalue: host.getResponse(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t\tcurrent: this.currentView,\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\treturn host;\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate notify(transition: ItemSessionTransition): void {\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\ttry {\n\t\t\t\tlistener(immutableSnapshot(transition));\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[QTI ItemSession] subscriber failed:', error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertActive(): void {\n\t\tif (this.disposed) throw new Error('ItemSession has been disposed');\n\t}\n\n\tprivate assertKnownResponseIdentifiers(responseIdentifiers: readonly string[]): void {\n\t\tconst knownIdentifiers = new Set(Object.keys(this.player.getResponses()));\n\t\tconst unknown = responseIdentifiers.find((identifier) => !knownIdentifiers.has(identifier));\n\t\tif (unknown) throw new Error(`Unknown response identifier '${unknown}'`);\n\t}\n}\n\nfunction isResponseWritableLifecycle(status: ItemLifecycleStatus): boolean {\n\treturn status === 'initial' || status === 'interacting';\n}\n\nfunction commandRequiresWritableLifecycle(command: ItemSessionCommand): boolean {\n\treturn command.action === 'setResponse' ||\n\t\tcommand.action === 'setResponses' ||\n\t\tcommand.action === 'suspendAttempt' ||\n\t\tcommand.action === 'endAttempt' ||\n\t\tcommand.action === 'submitAttempt';\n}\n\nfunction describeCommand(command: ItemSessionCommand): string {\n\treturn command.action === 'setResponse' || command.action === 'setResponses'\n\t\t? 'update responses'\n\t\t: `run ${command.action}`;\n}\n\nfunction valuesOf(\n\tvariables: Record<string, SerializedItemSessionVariable>\n): Readonly<Record<string, unknown>> {\n\treturn Object.fromEntries(\n\t\tObject.entries(variables).map(([identifier, variable]) => [\n\t\t\tidentifier,\n\t\t\timmutableSnapshot(variable.value),\n\t\t])\n\t);\n}\n\nfunction freezeTransition(transition: ItemSessionTransition): ItemSessionTransition {\n\treturn immutableSnapshot(transition);\n}\n\n/** Clone and freeze plain data without mutating values owned by the caller or a PCI module. */\nfunction immutableSnapshot<T>(value: T): T {\n\tif (Array.isArray(value)) {\n\t\treturn Object.freeze(value.map((entry) => immutableSnapshot(entry))) as T;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (ArrayBuffer.isView(value)) return structuredClone(value);\n\tif (value instanceof ArrayBuffer) return value.slice(0) as T;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return value;\n\tconst snapshot = Object.fromEntries(\n\t\tObject.entries(value as Record<string, unknown>).map(([key, entry]) => [\n\t\t\tkey,\n\t\t\timmutableSnapshot(entry),\n\t\t])\n\t);\n\treturn Object.freeze(snapshot) as T;\n}\n"]}
1
+ {"version":3,"file":"ItemSession.js","sourceRoot":"","sources":["../../src/core/ItemSession.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,sBAAsB,GAGtB,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,gCAAgC,EAAe,MAAM,aAAa,CAAC;AAmC5E;;;GAGG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAExD,YAAY,UAAkB;QAC7B,KAAK,CAAC,gCAAgC,UAAU,GAAG,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAoGD;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAoB;IACzD,MAAM,cAAc,GAAG,OAEtB,CAAC;IACF,IAAI,OAAO,cAAc,CAAC,iBAAiB,KAAK,UAAU,EAAE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AACH,SAAS,gBAAgB,CAAC,UAAiC;IAC1D,OAAO,iBAAiB,CAAC;QACxB,GAAG,UAAU;QACb,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,OAAO,CAAC;KAC3C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { PnpProfile } from '../pnp/types.js';\nimport type { ExtractedPci, PciHostController } from '../pci/types.js';\nimport {\n\tcreateItemPresentation,\n\ttype CreateItemPresentationOptions,\n\ttype ItemPresentation,\n} from '../presentation/itemPresentationPlan.js';\nimport type {\n\tCompletionStatus,\n\tHtmlContent,\n\tItemLifecycleStatus,\n\tItemSessionActionCommand,\n\tItemSessionActionResult,\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIRole,\n\tSerializedItemSessionState,\n\tSerializedItemSessionVariable,\n} from '../types/index.js';\nimport type { BaseInteractionData } from '../interactions/shared/types.js';\nimport { deepFreezeInPlace, frozenSnapshot, withFreshTypedArrays } from '../utils/cloneFreeze.js';\nimport { createPlayerFromPreparedInternal, type Player } from './Player.js';\n\nexport interface OpenItemSessionOptions {\n\t/** Restore a previously serialized state before applying response overrides. */\n\trestore?: SerializedItemSessionState;\n\t/** Initial responses, or overrides applied after restore. */\n\tresponses?: Readonly<Record<string, unknown>>;\n\t/** Resume a suspended handoff as an active interaction session. */\n\tactivate?: boolean;\n\t/**\n\t * Values for the item's context variables, e.g. `QTI_CONTEXT`, set before template processing.\n\t * A restored session keeps its saved context values.\n\t */\n\tcontextVariables?: Readonly<Record<string, unknown>>;\n\t/**\n\t * Default values for template variables, set before template processing, as an\n\t * assessmentItemRef's `templateDefault` requires. A restored session keeps its saved values.\n\t */\n\ttemplateDefaults?: Readonly<Record<string, unknown>>;\n\t/** Test-level item session control applied by `present()`. */\n\tpresentation?: ItemSessionPresentationPolicy;\n}\n\nexport interface ItemSessionPresentationPolicy {\n\t/**\n\t * False hides integrated feedback (`feedbackInline` / `feedbackBlock`), as\n\t * `itemSessionControl@showFeedback=\"false\"` requires. An assessment host passes the test's\n\t * item session control here; standalone delivery through `ItemPlayer` defaults to the QTI\n\t * default (hidden) unless the host opts in.\n\t */\n\tshowFeedback?: boolean;\n\t/** True shows correct responses once the attempt has ended (`showSolution=\"true\"`). */\n\tshowSolution?: boolean;\n}\n\n/**\n * Opening a session with responses the item does not declare. Hosts that re-use an item\n * element across items can catch this to drop responses that belonged to the previous item.\n */\nexport class UnknownResponseIdentifierError extends Error {\n\treadonly identifier: string;\n\tconstructor(identifier: string) {\n\t\tsuper(`Unknown response identifier '${identifier}'`);\n\t\tthis.name = 'UnknownResponseIdentifierError';\n\t\tthis.identifier = identifier;\n\t}\n}\n\nexport type ItemSessionCommand =\n\t| ItemSessionActionCommand\n\t| { action: 'setResponse'; responseIdentifier: string; value: unknown }\n\t| { action: 'setResponses'; responses: Readonly<Record<string, unknown>> }\n\t| { action: 'updatePnp'; profile: Partial<PnpProfile> };\n\nexport type ItemSessionEventCommand = ItemSessionCommand | { action: 'dispose' };\n\nexport interface ItemSessionView {\n\treadonly revision: number;\n\treadonly itemIdentifier?: string;\n\treadonly role: QTIRole;\n\treadonly lifecycleStatus: ItemLifecycleStatus;\n\treadonly completionStatus: CompletionStatus;\n\treadonly numAttempts: number;\n\t/**\n\t * Time on task in milliseconds. `context.duration`, the QTI built-in variable, holds the same\n\t * time in seconds.\n\t */\n\treadonly duration: number;\n\treadonly adaptive: boolean;\n\treadonly completed: boolean;\n\treadonly canSubmit: boolean;\n\treadonly disposed: boolean;\n\treadonly responses: Readonly<Record<string, unknown>>;\n\treadonly outcomes: Readonly<Record<string, unknown>>;\n\treadonly templates: Readonly<Record<string, unknown>>;\n\treadonly context: Readonly<Record<string, unknown>>;\n}\n\nexport interface ItemSessionTransition {\n\treadonly command: ItemSessionEventCommand;\n\treadonly previous: ItemSessionView;\n\treadonly current: ItemSessionView;\n\treadonly result?: ItemSessionActionResult;\n}\n\nexport type ItemSessionListener = (transition: ItemSessionTransition) => void;\n\nexport type ItemPresentationView = Omit<\n\tCreateItemPresentationOptions,\n\t'outcomeValues' | 'responses' | 'role' | 'source' | 'showFeedback' | 'showSolution'\n>;\n\nexport interface ItemSession {\n\tstate(): ItemSessionView;\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition;\n\tpresent(view?: ItemPresentationView): ItemPresentation;\n\tsubscribe(listener: ItemSessionListener): () => void;\n\tserialize(): SerializedItemSessionState;\n\tdispose(): void;\n}\n\n/**\n * Narrow browser/runtime capabilities needed after a presentation has been produced.\n * This interface deliberately excludes Player, parser nodes, declarations, and extraction registries.\n * @internal\n */\nexport interface ItemSessionBinding {\n\treadonly role: QTIRole;\n\tapplyPnp(root: HTMLElement): void;\n\tgetPnp(): PnpProfile | undefined;\n\tonPnpChange(listener: () => void): () => void;\n\tgetCatalogEntry(\n\t\tidref: string,\n\t\tusage: string,\n\t\tlang?: string,\n\t\toptions?: { stimulusIdentifier?: string }\n\t): HtmlContent | null;\n\tgetContentLanguage(): string | undefined;\n\tgetComponentRegistry(): ItemSessionComponentRegistry;\n\tgetDeliveryContext(): ResolvedItemDeliveryContext | undefined;\n\tgetSecurityConfig(): PlayerSecurityConfig | undefined;\n\t/**\n\t * Response identifiers the item's content prints live (`printedVariable` targets declared\n\t * as responses): the part of the response state a presentation's markup actually renders.\n\t * A presentation presenter can key its caching on these — other response changes only\n\t * carry interaction values, which present() reads into mounts, not into markup.\n\t */\n\tgetResponseIdentifiersPrintedInContent(): ReadonlySet<string>;\n\t/**\n\t * Context identifiers the item's content prints live (`printedVariable` targets the session\n\t * reports as context state — the QTI built-ins `duration`, `numAttempts`,\n\t * `completionStatus` and declared context variables): the part of the context state a\n\t * presentation's markup actually renders. A presentation presenter can key its caching on\n\t * these — unprinted context values, `duration` included, never reach the markup.\n\t */\n\tgetContextIdentifiersPrintedInContent(): ReadonlySet<string>;\n\tgetI18nProvider(): unknown;\n\tcreatePciHost(data: ExtractedPci): PciHostController;\n}\n\n/** @internal */\nexport interface ItemSessionComponentRegistry {\n\tgetTagName(interaction: BaseInteractionData): string;\n\tgetTagNameForType(type: string): string | null;\n}\n\n/**\n * Browser adapters use this without gaining access to the private session engine.\n * @internal\n */\nexport function getItemSessionBinding(session: ItemSession): ItemSessionBinding {\n\tconst runtimeSession = session as ItemSession & {\n\t\tgetRuntimeBinding?: () => ItemSessionBinding;\n\t};\n\tif (typeof runtimeSession.getRuntimeBinding !== 'function') {\n\t\tthrow new Error('ItemSession runtime binding is unavailable');\n\t}\n\treturn runtimeSession.getRuntimeBinding();\n}\n\n/**\n * Construct sessions through AssessmentItemDefinition.openSession().\n * @internal\n */\nexport class LiveItemSession implements ItemSession {\n\tprivate readonly player: Player;\n\tprivate readonly listeners = new Set<ItemSessionListener>();\n\tprivate readonly defaultRole: QTIRole;\n\tprivate readonly presentation: ItemSessionPresentationPolicy;\n\tprivate revision = 0;\n\tprivate disposed = false;\n\tprivate currentView: ItemSessionView;\n\tprivate readonly runtimeBinding: ItemSessionBinding;\n\n\t/** @internal Construct sessions through AssessmentItemDefinition.openSession(). */\n\tconstructor(\n\t\tprivate readonly itemIdentifier: string,\n\t\tconfig: ItemSessionEngineConfig,\n\t\toptions: OpenItemSessionOptions = {},\n\t\tprepared: unknown,\n\t) {\n\t\tthis.defaultRole = config.role ?? 'candidate';\n\t\tthis.presentation = { ...options.presentation };\n\t\tconst playerConfig = {\n\t\t\t...config,\n\t\t\t...(options.contextVariables ? { contextVariables: options.contextVariables } : {}),\n\t\t\t...(options.templateDefaults ? { templateDefaults: options.templateDefaults } : {}),\n\t\t};\n\t\tthis.player = createPlayerFromPreparedInternal(playerConfig, prepared, Boolean(options.restore));\n\n\t\ttry {\n\t\t\tif (options.responses) {\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(options.responses));\n\t\t\t}\n\t\t\tif (options.restore) this.player.restoreItemSession(options.restore);\n\t\t\tif (options.activate && this.player.getLifecycleStatus() === 'suspended') {\n\t\t\t\tthis.player.activateAttempt();\n\t\t\t}\n\t\t\tif (options.responses) {\n\t\t\t\tconst lifecycle = this.player.getLifecycleStatus();\n\t\t\t\tif (!isResponseWritableLifecycle(lifecycle)) {\n\t\t\t\t\tthrow new Error(`Cannot override responses while item session is ${lifecycle}`);\n\t\t\t\t}\n\t\t\t\tthis.player.setResponses({ ...options.responses });\n\t\t\t}\n\t\t\tthis.currentView = this.captureView();\n\t\t} catch (error) {\n\t\t\tthis.player.destroy();\n\t\t\tthrow error;\n\t\t}\n\n\t\tthis.runtimeBinding = this.createBinding();\n\t}\n\n\tstate(): ItemSessionView {\n\t\treturn frozenSnapshot(this.currentView);\n\t}\n\n\tdispatch(command: ItemSessionCommand): ItemSessionTransition {\n\t\tthis.assertActive();\n\t\tif (\n\t\t\tcommandRequiresWritableLifecycle(command) &&\n\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot ${describeCommand(command)} while item session is ${this.currentView.lifecycleStatus}`\n\t\t\t);\n\t\t}\n\t\tconst previous = this.currentView;\n\t\tlet result: ItemSessionActionResult | undefined;\n\n\t\tswitch (command.action) {\n\t\t\tcase 'setResponse':\n\t\t\t\tthis.assertKnownResponseIdentifiers([command.responseIdentifier]);\n\t\t\t\tthis.player.setResponses({ [command.responseIdentifier]: command.value });\n\t\t\t\tbreak;\n\t\t\tcase 'setResponses':\n\t\t\t\tthis.assertKnownResponseIdentifiers(Object.keys(command.responses));\n\t\t\t\tthis.player.setResponses({ ...command.responses });\n\t\t\t\tbreak;\n\t\t\tcase 'updatePnp':\n\t\t\t\tthis.player.updatePnp(command.profile);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tresult = this.player.runItemSessionAction(command);\n\t\t}\n\n\t\tthis.revision += 1;\n\t\tthis.currentView = this.captureView(result?.sessionState);\n\t\tconst transition = freezeTransition({ command, previous, current: this.currentView, result });\n\t\tthis.notify(transition);\n\t\t// The returned hand-out isolates the typed-array leaves for the caller, exactly as\n\t\t// each listener's copy does (see notify and withFreshTypedArrays).\n\t\treturn withFreshTypedArrays(transition);\n\t}\n\n\tpresent(view: ItemPresentationView = {}): ItemPresentation {\n\t\tthis.assertActive();\n\t\tconst lifecycle = this.currentView.lifecycleStatus;\n\t\tconst attemptEnded = !isResponseWritableLifecycle(lifecycle) && lifecycle !== 'suspended';\n\t\treturn createItemPresentation({\n\t\t\t...view,\n\t\t\tdisabled: view.disabled === true || !isResponseWritableLifecycle(lifecycle),\n\t\t\tshowFeedback: this.presentation.showFeedback !== false,\n\t\t\tshowSolution: this.presentation.showSolution === true && attemptEnded,\n\t\t\tsource: {\n\t\t\t\titemBodyHtml: this.player.getItemBodyHtml(),\n\t\t\t\tcontentLanguage: this.player.getContentLanguage(),\n\t\t\t\tinteractions: this.player.getInteractionData(),\n\t\t\t\tcorrectResponses: this.player.getCorrectResponses(),\n\t\t\t\tcomponentRegistry: this.player.getComponentRegistry(),\n\t\t\t\tdeliveryContext: this.player.getDeliveryContext(),\n\t\t\t\tpnp: this.player.getPnp(),\n\t\t\t\tsecurity: this.player.getSecurityConfig(),\n\t\t\t\tdirectRubrics: this.player.getRubrics({ scope: 'direct' }),\n\t\t\t},\n\t\t\tresponses: frozenSnapshot(this.currentView.responses),\n\t\t\toutcomeValues: frozenSnapshot(this.currentView.outcomes),\n\t\t\trole: this.defaultRole,\n\t\t});\n\t}\n\n\tsubscribe(listener: ItemSessionListener): () => void {\n\t\tthis.assertActive();\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tserialize(): SerializedItemSessionState {\n\t\tthis.assertActive();\n\t\treturn frozenSnapshot(this.player.saveItemSession());\n\t}\n\n\t/**\n\t * Browser/runtime capabilities carried by the session across package bundles.\n\t * @internal\n\t */\n\tgetRuntimeBinding(): ItemSessionBinding {\n\t\tthis.assertActive();\n\t\treturn this.runtimeBinding;\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tconst previous = this.currentView;\n\t\tthis.disposed = true;\n\t\tthis.revision += 1;\n\t\t// The previous view is deeply frozen, so the disposed view can share its variable\n\t\t// records; only the new shell needs freezing.\n\t\tthis.currentView = deepFreezeInPlace({\n\t\t\t...previous,\n\t\t\trevision: this.revision,\n\t\t\tdisposed: true,\n\t\t});\n\t\tthis.player.destroy();\n\t\tthis.notify(\n\t\t\tfreezeTransition({\n\t\t\t\tcommand: { action: 'dispose' },\n\t\t\t\tprevious,\n\t\t\t\tcurrent: this.currentView,\n\t\t\t})\n\t\t);\n\t\tthis.listeners.clear();\n\t}\n\n\t/**\n\t * Builds the immutable view a dispatch hands out. The variable records come from the\n\t * serializer, whose values are per-call copies already independent of the engine (see\n\t * qtiValueToSerializable) — freezing them in place needs no second clone. The shell is\n\t * frozen around them, which leaves the frozen records untouched.\n\t *\n\t * `canSubmit` validates the engine's own response snapshot record: the same record the\n\t * serializer's validation step used, so within one dispatch the validation memo hits and\n\t * the responses are walked once.\n\t */\n\tprivate captureView(serialized = this.player.saveItemSession()): ItemSessionView {\n\t\tconst responses = frozenValuesOf(serialized.responseVariables);\n\t\treturn deepFreezeInPlace({\n\t\t\trevision: this.revision,\n\t\t\titemIdentifier: serialized.itemIdentifier || this.itemIdentifier || undefined,\n\t\t\trole: this.defaultRole,\n\t\t\tlifecycleStatus: serialized.lifecycleStatus,\n\t\t\tcompletionStatus: serialized.completionStatus,\n\t\t\tnumAttempts: serialized.numAttempts,\n\t\t\tduration: serialized.duration,\n\t\t\tadaptive: this.player.isAdaptive(),\n\t\t\tcompleted: this.player.isCompleted(),\n\t\t\tcanSubmit: this.player.canSubmitResponses(this.player.responseSnapshot()),\n\t\t\tdisposed: this.disposed,\n\t\t\tresponses,\n\t\t\toutcomes: frozenValuesOf(serialized.outcomeVariables),\n\t\t\ttemplates: frozenValuesOf(serialized.templateVariables),\n\t\t\tcontext: frozenValuesOf(serialized.contextVariables),\n\t\t});\n\t}\n\n\tprivate createBinding(): ItemSessionBinding {\n\t\treturn Object.freeze({\n\t\t\trole: this.defaultRole,\n\t\t\tapplyPnp: (root: HTMLElement) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tthis.player.applyPnp(root);\n\t\t\t},\n\t\t\tgetPnp: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getPnp();\n\t\t\t},\n\t\t\tonPnpChange: (listener: () => void) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.onPnpChange(() => listener());\n\t\t\t},\n\t\t\tgetContentLanguage: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getContentLanguage();\n\t\t\t},\n\t\t\tgetCatalogEntry: (\n\t\t\t\tidref: string,\n\t\t\t\tusage: string,\n\t\t\t\tlang?: string,\n\t\t\t\toptions?: { stimulusIdentifier?: string }\n\t\t\t) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getCatalogEntry(idref, usage, lang, options);\n\t\t\t},\n\t\t\tgetComponentRegistry: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getComponentRegistry();\n\t\t\t},\n\t\t\tgetDeliveryContext: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getDeliveryContext();\n\t\t\t},\n\t\t\tgetSecurityConfig: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getSecurityConfig();\n\t\t\t},\n\t\t\tgetResponseIdentifiersPrintedInContent: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getResponseIdentifiersPrintedInContent();\n\t\t\t},\n\t\t\tgetContextIdentifiersPrintedInContent: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getContextIdentifiersPrintedInContent();\n\t\t\t},\n\t\t\tgetI18nProvider: () => {\n\t\t\t\tthis.assertActive();\n\t\t\t\treturn this.player.getI18nProvider();\n\t\t\t},\n\t\t\tcreatePciHost: (data: ExtractedPci) => {\n\t\t\t\tthis.assertActive();\n\t\t\t\tconst host = this.player.createPciHost(data);\n\t\t\t\thost.onResponseChange(() => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.disposed ||\n\t\t\t\t\t\t!isResponseWritableLifecycle(this.currentView.lifecycleStatus)\n\t\t\t\t\t) return;\n\t\t\t\t\tconst previous = this.currentView;\n\t\t\t\t\tthis.revision += 1;\n\t\t\t\t\tthis.currentView = this.captureView();\n\t\t\t\t\tthis.notify(\n\t\t\t\t\t\tfreezeTransition({\n\t\t\t\t\t\t\tcommand: {\n\t\t\t\t\t\t\t\taction: 'setResponse',\n\t\t\t\t\t\t\t\tresponseIdentifier: data.responseIdentifier,\n\t\t\t\t\t\t\t\tvalue: host.getResponse(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t\tcurrent: this.currentView,\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\treturn host;\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Every listener receives a deeply frozen transition, and one whose unfreezable\n\t * typed-array leaves are its own: the frozen plain structure is shared across listeners\n\t * (no listener can observe another's view of it through mutation — freezing forbids it),\n\t * while each hand-out re-copies the leaves no platform can freeze (withFreshTypedArrays).\n\t * A dispatch without such leaves — every keystroke on ordinary items — hands the same\n\t * frozen object to every listener and clones nothing. A listener that must keep an owned\n\t * copy of the whole view uses `state()`.\n\t */\n\tprivate notify(transition: ItemSessionTransition): void {\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\ttry {\n\t\t\t\tlistener(withFreshTypedArrays(transition) as ItemSessionTransition);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[QTI ItemSession] subscriber failed:', error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertActive(): void {\n\t\tif (this.disposed) throw new Error('ItemSession has been disposed');\n\t}\n\n\tprivate assertKnownResponseIdentifiers(responseIdentifiers: readonly string[]): void {\n\t\tconst knownIdentifiers = new Set(Object.keys(this.player.getResponses()));\n\t\tconst unknown = responseIdentifiers.find((identifier) => !knownIdentifiers.has(identifier));\n\t\tif (unknown) throw new UnknownResponseIdentifierError(unknown);\n\t}\n}\n\nfunction isResponseWritableLifecycle(status: ItemLifecycleStatus): boolean {\n\treturn status === 'initial' || status === 'interacting';\n}\n\nfunction commandRequiresWritableLifecycle(command: ItemSessionCommand): boolean {\n\treturn command.action === 'setResponse' ||\n\t\tcommand.action === 'setResponses' ||\n\t\tcommand.action === 'suspendAttempt' ||\n\t\tcommand.action === 'endAttempt' ||\n\t\tcommand.action === 'submitAttempt';\n}\n\nfunction describeCommand(command: ItemSessionCommand): string {\n\treturn command.action === 'setResponse' || command.action === 'setResponses'\n\t\t? 'update responses'\n\t\t: `run ${command.action}`;\n}\n\n/**\n * The view's variable values, frozen for hand-out. The serializer's values are per-call\n * copies independent of the engine, so freezing them in place needs no clone of its own.\n */\nfunction frozenValuesOf(\n\tvariables: Record<string, SerializedItemSessionVariable>\n): Readonly<Record<string, unknown>> {\n\treturn Object.fromEntries(\n\t\tObject.entries(variables).map(([identifier, variable]) => [\n\t\t\tidentifier,\n\t\t\tdeepFreezeInPlace(variable.value),\n\t\t])\n\t);\n}\n\n/**\n * Freezes a dispatch's transition for hand-out. The previous and current views are deeply\n * frozen already (captureView, dispose) and freeze in place for free. The command and the\n * action result are engine output owned by this dispatch — the command is copied (it is the\n * caller's object and carries the candidate's submitted value), while the result's serialized\n * session state and validation/scoring results are per-call copies that freeze in place;\n * the memoized base-validation result is shared with the engine's memo, which never mutates\n * a result once built. What remains unfrozen are only the leaves no platform can freeze\n * (typed arrays), as everywhere else in the clone/freeze family.\n */\nfunction freezeTransition(transition: ItemSessionTransition): ItemSessionTransition {\n\treturn deepFreezeInPlace({\n\t\t...transition,\n\t\tcommand: frozenSnapshot(transition.command),\n\t});\n}\n"]}