@pie-qti/item-player 0.1.5 → 0.1.7

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 (461) hide show
  1. package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
  2. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  3. package/dist/catalog/applyGlossaryTriggers.js +145 -30
  4. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  5. package/dist/catalog/glossaryAction.js +14 -4
  6. package/dist/components/utils/stimulusRender.d.ts +17 -0
  7. package/dist/components/utils/stimulusRender.d.ts.map +1 -0
  8. package/dist/components/utils/stimulusRender.js +70 -0
  9. package/dist/components/utils/stylesheetRender.d.ts +4 -0
  10. package/dist/components/utils/stylesheetRender.d.ts.map +1 -0
  11. package/dist/components/utils/stylesheetRender.js +57 -0
  12. package/dist/core/ComponentRegistry.d.ts +5 -4
  13. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  14. package/dist/core/ComponentRegistry.js +11 -4
  15. package/dist/core/ItemRenderer.d.ts.map +1 -1
  16. package/dist/core/ItemRenderer.js +5 -18
  17. package/dist/core/Player.d.ts +39 -4
  18. package/dist/core/Player.d.ts.map +1 -1
  19. package/dist/core/Player.js +364 -193
  20. package/dist/document/AssessmentItemDocument.d.ts +42 -0
  21. package/dist/document/AssessmentItemDocument.d.ts.map +1 -0
  22. package/dist/document/AssessmentItemDocument.js +116 -0
  23. package/dist/element.js +3318 -2733
  24. package/dist/element.js.map +1 -1
  25. package/dist/extraction/extractors/associateExtractor.d.ts +1 -28
  26. package/dist/extraction/extractors/associateExtractor.d.ts.map +1 -1
  27. package/dist/extraction/extractors/associateExtractor.js +1 -97
  28. package/dist/extraction/extractors/choiceExtractor.d.ts +1 -26
  29. package/dist/extraction/extractors/choiceExtractor.d.ts.map +1 -1
  30. package/dist/extraction/extractors/choiceExtractor.js +1 -93
  31. package/dist/extraction/extractors/customExtractor.d.ts +1 -19
  32. package/dist/extraction/extractors/customExtractor.d.ts.map +1 -1
  33. package/dist/extraction/extractors/customExtractor.js +1 -51
  34. package/dist/extraction/extractors/drawingExtractor.d.ts +1 -29
  35. package/dist/extraction/extractors/drawingExtractor.d.ts.map +1 -1
  36. package/dist/extraction/extractors/drawingExtractor.js +1 -78
  37. package/dist/extraction/extractors/endAttemptExtractor.d.ts +1 -19
  38. package/dist/extraction/extractors/endAttemptExtractor.d.ts.map +1 -1
  39. package/dist/extraction/extractors/endAttemptExtractor.js +1 -53
  40. package/dist/extraction/extractors/extendedTextExtractor.d.ts +1 -20
  41. package/dist/extraction/extractors/extendedTextExtractor.d.ts.map +1 -1
  42. package/dist/extraction/extractors/extendedTextExtractor.js +1 -63
  43. package/dist/extraction/extractors/gapMatchExtractor.d.ts +1 -28
  44. package/dist/extraction/extractors/gapMatchExtractor.d.ts.map +1 -1
  45. package/dist/extraction/extractors/gapMatchExtractor.js +1 -155
  46. package/dist/extraction/extractors/graphicAssociateExtractor.d.ts +1 -40
  47. package/dist/extraction/extractors/graphicAssociateExtractor.d.ts.map +1 -1
  48. package/dist/extraction/extractors/graphicAssociateExtractor.js +1 -143
  49. package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts +1 -52
  50. package/dist/extraction/extractors/graphicGapMatchExtractor.d.ts.map +1 -1
  51. package/dist/extraction/extractors/graphicGapMatchExtractor.js +1 -205
  52. package/dist/extraction/extractors/graphicOrderExtractor.d.ts +1 -36
  53. package/dist/extraction/extractors/graphicOrderExtractor.d.ts.map +1 -1
  54. package/dist/extraction/extractors/graphicOrderExtractor.js +1 -121
  55. package/dist/extraction/extractors/hotspotExtractor.d.ts +1 -37
  56. package/dist/extraction/extractors/hotspotExtractor.d.ts.map +1 -1
  57. package/dist/extraction/extractors/hotspotExtractor.js +1 -159
  58. package/dist/extraction/extractors/hottextExtractor.d.ts +1 -25
  59. package/dist/extraction/extractors/hottextExtractor.d.ts.map +1 -1
  60. package/dist/extraction/extractors/hottextExtractor.js +1 -128
  61. package/dist/extraction/extractors/index.d.ts +5 -59
  62. package/dist/extraction/extractors/index.d.ts.map +1 -1
  63. package/dist/extraction/extractors/index.js +5 -85
  64. package/dist/extraction/extractors/inlineChoiceExtractor.d.ts +1 -24
  65. package/dist/extraction/extractors/inlineChoiceExtractor.d.ts.map +1 -1
  66. package/dist/extraction/extractors/inlineChoiceExtractor.js +1 -80
  67. package/dist/extraction/extractors/matchExtractor.d.ts +1 -36
  68. package/dist/extraction/extractors/matchExtractor.d.ts.map +1 -1
  69. package/dist/extraction/extractors/matchExtractor.js +1 -160
  70. package/dist/extraction/extractors/mediaExtractor.d.ts +1 -32
  71. package/dist/extraction/extractors/mediaExtractor.d.ts.map +1 -1
  72. package/dist/extraction/extractors/mediaExtractor.js +1 -125
  73. package/dist/extraction/extractors/orderExtractor.d.ts +1 -27
  74. package/dist/extraction/extractors/orderExtractor.d.ts.map +1 -1
  75. package/dist/extraction/extractors/orderExtractor.js +1 -90
  76. package/dist/extraction/extractors/portableCustomExtractor.d.ts +1 -13
  77. package/dist/extraction/extractors/portableCustomExtractor.d.ts.map +1 -1
  78. package/dist/extraction/extractors/portableCustomExtractor.js +1 -96
  79. package/dist/extraction/extractors/positionObjectExtractor.d.ts +1 -58
  80. package/dist/extraction/extractors/positionObjectExtractor.d.ts.map +1 -1
  81. package/dist/extraction/extractors/positionObjectExtractor.js +1 -191
  82. package/dist/extraction/extractors/selectPointExtractor.d.ts +1 -30
  83. package/dist/extraction/extractors/selectPointExtractor.d.ts.map +1 -1
  84. package/dist/extraction/extractors/selectPointExtractor.js +1 -109
  85. package/dist/extraction/extractors/sliderExtractor.d.ts +1 -23
  86. package/dist/extraction/extractors/sliderExtractor.d.ts.map +1 -1
  87. package/dist/extraction/extractors/sliderExtractor.js +1 -73
  88. package/dist/extraction/extractors/textEntryExtractor.d.ts +1 -20
  89. package/dist/extraction/extractors/textEntryExtractor.d.ts.map +1 -1
  90. package/dist/extraction/extractors/textEntryExtractor.js +1 -54
  91. package/dist/extraction/extractors/uploadExtractor.d.ts +1 -19
  92. package/dist/extraction/extractors/uploadExtractor.d.ts.map +1 -1
  93. package/dist/extraction/extractors/uploadExtractor.js +1 -59
  94. package/dist/extraction/index.d.ts +1 -1
  95. package/dist/extraction/index.d.ts.map +1 -1
  96. package/dist/extraction/index.js +2 -2
  97. package/dist/extraction/interactionExtractionPipeline.d.ts +13 -0
  98. package/dist/extraction/interactionExtractionPipeline.d.ts.map +1 -0
  99. package/dist/extraction/interactionExtractionPipeline.js +39 -0
  100. package/dist/extraction/interactionSecurity.d.ts +4 -0
  101. package/dist/extraction/interactionSecurity.d.ts.map +1 -0
  102. package/dist/extraction/interactionSecurity.js +48 -0
  103. package/dist/index.d.ts +2 -1
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +3 -3
  106. package/dist/interactions/associate/extractor.d.ts +29 -0
  107. package/dist/interactions/associate/extractor.d.ts.map +1 -0
  108. package/dist/interactions/associate/extractor.js +97 -0
  109. package/dist/interactions/associate/index.d.ts +3 -0
  110. package/dist/interactions/associate/index.d.ts.map +1 -0
  111. package/dist/interactions/associate/index.js +1 -0
  112. package/dist/interactions/associate/types.d.ts +2 -0
  113. package/dist/interactions/associate/types.d.ts.map +1 -0
  114. package/dist/interactions/associate/types.js +1 -0
  115. package/dist/interactions/choice/extractor.d.ts +27 -0
  116. package/dist/interactions/choice/extractor.d.ts.map +1 -0
  117. package/dist/interactions/choice/extractor.js +93 -0
  118. package/dist/interactions/choice/index.d.ts +3 -0
  119. package/dist/interactions/choice/index.d.ts.map +1 -0
  120. package/dist/interactions/choice/index.js +1 -0
  121. package/dist/interactions/choice/types.d.ts +2 -0
  122. package/dist/interactions/choice/types.d.ts.map +1 -0
  123. package/dist/interactions/choice/types.js +1 -0
  124. package/dist/interactions/custom/extractor.d.ts +20 -0
  125. package/dist/interactions/custom/extractor.d.ts.map +1 -0
  126. package/dist/interactions/custom/extractor.js +51 -0
  127. package/dist/interactions/custom/index.d.ts +3 -0
  128. package/dist/interactions/custom/index.d.ts.map +1 -0
  129. package/dist/interactions/custom/index.js +1 -0
  130. package/dist/interactions/custom/types.d.ts +2 -0
  131. package/dist/interactions/custom/types.d.ts.map +1 -0
  132. package/dist/interactions/custom/types.js +1 -0
  133. package/dist/interactions/drawing/extractor.d.ts +30 -0
  134. package/dist/interactions/drawing/extractor.d.ts.map +1 -0
  135. package/dist/interactions/drawing/extractor.js +78 -0
  136. package/dist/interactions/drawing/index.d.ts +3 -0
  137. package/dist/interactions/drawing/index.d.ts.map +1 -0
  138. package/dist/interactions/drawing/index.js +1 -0
  139. package/dist/interactions/drawing/types.d.ts +2 -0
  140. package/dist/interactions/drawing/types.d.ts.map +1 -0
  141. package/dist/interactions/drawing/types.js +1 -0
  142. package/dist/interactions/end-attempt/extractor.d.ts +20 -0
  143. package/dist/interactions/end-attempt/extractor.d.ts.map +1 -0
  144. package/dist/interactions/end-attempt/extractor.js +53 -0
  145. package/dist/interactions/end-attempt/index.d.ts +3 -0
  146. package/dist/interactions/end-attempt/index.d.ts.map +1 -0
  147. package/dist/interactions/end-attempt/index.js +1 -0
  148. package/dist/interactions/end-attempt/types.d.ts +2 -0
  149. package/dist/interactions/end-attempt/types.d.ts.map +1 -0
  150. package/dist/interactions/end-attempt/types.js +1 -0
  151. package/dist/interactions/extended-text/extractor.d.ts +21 -0
  152. package/dist/interactions/extended-text/extractor.d.ts.map +1 -0
  153. package/dist/interactions/extended-text/extractor.js +63 -0
  154. package/dist/interactions/extended-text/index.d.ts +3 -0
  155. package/dist/interactions/extended-text/index.d.ts.map +1 -0
  156. package/dist/interactions/extended-text/index.js +1 -0
  157. package/dist/interactions/extended-text/types.d.ts +2 -0
  158. package/dist/interactions/extended-text/types.d.ts.map +1 -0
  159. package/dist/interactions/extended-text/types.js +1 -0
  160. package/dist/interactions/gap-match/extractor.d.ts +29 -0
  161. package/dist/interactions/gap-match/extractor.d.ts.map +1 -0
  162. package/dist/interactions/gap-match/extractor.js +155 -0
  163. package/dist/interactions/gap-match/index.d.ts +3 -0
  164. package/dist/interactions/gap-match/index.d.ts.map +1 -0
  165. package/dist/interactions/gap-match/index.js +1 -0
  166. package/dist/interactions/gap-match/types.d.ts +2 -0
  167. package/dist/interactions/gap-match/types.d.ts.map +1 -0
  168. package/dist/interactions/gap-match/types.js +1 -0
  169. package/dist/interactions/graphic-associate/extractor.d.ts +41 -0
  170. package/dist/interactions/graphic-associate/extractor.d.ts.map +1 -0
  171. package/dist/interactions/graphic-associate/extractor.js +143 -0
  172. package/dist/interactions/graphic-associate/index.d.ts +3 -0
  173. package/dist/interactions/graphic-associate/index.d.ts.map +1 -0
  174. package/dist/interactions/graphic-associate/index.js +1 -0
  175. package/dist/interactions/graphic-associate/types.d.ts +2 -0
  176. package/dist/interactions/graphic-associate/types.d.ts.map +1 -0
  177. package/dist/interactions/graphic-associate/types.js +1 -0
  178. package/dist/interactions/graphic-gap-match/extractor.d.ts +53 -0
  179. package/dist/interactions/graphic-gap-match/extractor.d.ts.map +1 -0
  180. package/dist/interactions/graphic-gap-match/extractor.js +205 -0
  181. package/dist/interactions/graphic-gap-match/index.d.ts +3 -0
  182. package/dist/interactions/graphic-gap-match/index.d.ts.map +1 -0
  183. package/dist/interactions/graphic-gap-match/index.js +1 -0
  184. package/dist/interactions/graphic-gap-match/types.d.ts +2 -0
  185. package/dist/interactions/graphic-gap-match/types.d.ts.map +1 -0
  186. package/dist/interactions/graphic-gap-match/types.js +1 -0
  187. package/dist/interactions/graphic-order/extractor.d.ts +37 -0
  188. package/dist/interactions/graphic-order/extractor.d.ts.map +1 -0
  189. package/dist/interactions/graphic-order/extractor.js +121 -0
  190. package/dist/interactions/graphic-order/index.d.ts +3 -0
  191. package/dist/interactions/graphic-order/index.d.ts.map +1 -0
  192. package/dist/interactions/graphic-order/index.js +1 -0
  193. package/dist/interactions/graphic-order/types.d.ts +2 -0
  194. package/dist/interactions/graphic-order/types.d.ts.map +1 -0
  195. package/dist/interactions/graphic-order/types.js +1 -0
  196. package/dist/interactions/hotspot/extractor.d.ts +38 -0
  197. package/dist/interactions/hotspot/extractor.d.ts.map +1 -0
  198. package/dist/interactions/hotspot/extractor.js +159 -0
  199. package/dist/interactions/hotspot/index.d.ts +3 -0
  200. package/dist/interactions/hotspot/index.d.ts.map +1 -0
  201. package/dist/interactions/hotspot/index.js +1 -0
  202. package/dist/interactions/hotspot/types.d.ts +2 -0
  203. package/dist/interactions/hotspot/types.d.ts.map +1 -0
  204. package/dist/interactions/hotspot/types.js +1 -0
  205. package/dist/interactions/hottext/extractor.d.ts +26 -0
  206. package/dist/interactions/hottext/extractor.d.ts.map +1 -0
  207. package/dist/interactions/hottext/extractor.js +128 -0
  208. package/dist/interactions/hottext/index.d.ts +3 -0
  209. package/dist/interactions/hottext/index.d.ts.map +1 -0
  210. package/dist/interactions/hottext/index.js +1 -0
  211. package/dist/interactions/hottext/types.d.ts +2 -0
  212. package/dist/interactions/hottext/types.d.ts.map +1 -0
  213. package/dist/interactions/hottext/types.js +1 -0
  214. package/dist/interactions/index.d.ts +33 -0
  215. package/dist/interactions/index.d.ts.map +1 -0
  216. package/dist/interactions/index.js +30 -0
  217. package/dist/interactions/inline/index.d.ts +2 -0
  218. package/dist/interactions/inline/index.d.ts.map +1 -0
  219. package/dist/interactions/inline/index.js +1 -0
  220. package/dist/interactions/inline/render-plan.d.ts +19 -0
  221. package/dist/interactions/inline/render-plan.d.ts.map +1 -0
  222. package/dist/interactions/inline/render-plan.js +59 -0
  223. package/dist/interactions/inline-choice/extractor.d.ts +25 -0
  224. package/dist/interactions/inline-choice/extractor.d.ts.map +1 -0
  225. package/dist/interactions/inline-choice/extractor.js +80 -0
  226. package/dist/interactions/inline-choice/index.d.ts +3 -0
  227. package/dist/interactions/inline-choice/index.d.ts.map +1 -0
  228. package/dist/interactions/inline-choice/index.js +1 -0
  229. package/dist/interactions/inline-choice/types.d.ts +2 -0
  230. package/dist/interactions/inline-choice/types.d.ts.map +1 -0
  231. package/dist/interactions/inline-choice/types.js +1 -0
  232. package/dist/interactions/match/extractor.d.ts +37 -0
  233. package/dist/interactions/match/extractor.d.ts.map +1 -0
  234. package/dist/interactions/match/extractor.js +160 -0
  235. package/dist/interactions/match/index.d.ts +3 -0
  236. package/dist/interactions/match/index.d.ts.map +1 -0
  237. package/dist/interactions/match/index.js +1 -0
  238. package/dist/interactions/match/types.d.ts +2 -0
  239. package/dist/interactions/match/types.d.ts.map +1 -0
  240. package/dist/interactions/match/types.js +1 -0
  241. package/dist/interactions/media/extractor.d.ts +33 -0
  242. package/dist/interactions/media/extractor.d.ts.map +1 -0
  243. package/dist/interactions/media/extractor.js +125 -0
  244. package/dist/interactions/media/index.d.ts +3 -0
  245. package/dist/interactions/media/index.d.ts.map +1 -0
  246. package/dist/interactions/media/index.js +1 -0
  247. package/dist/interactions/media/types.d.ts +2 -0
  248. package/dist/interactions/media/types.d.ts.map +1 -0
  249. package/dist/interactions/media/types.js +1 -0
  250. package/dist/interactions/modules.d.ts +105 -0
  251. package/dist/interactions/modules.d.ts.map +1 -0
  252. package/dist/interactions/modules.js +86 -0
  253. package/dist/interactions/order/extractor.d.ts +28 -0
  254. package/dist/interactions/order/extractor.d.ts.map +1 -0
  255. package/dist/interactions/order/extractor.js +90 -0
  256. package/dist/interactions/order/index.d.ts +3 -0
  257. package/dist/interactions/order/index.d.ts.map +1 -0
  258. package/dist/interactions/order/index.js +1 -0
  259. package/dist/interactions/order/types.d.ts +2 -0
  260. package/dist/interactions/order/types.d.ts.map +1 -0
  261. package/dist/interactions/order/types.js +1 -0
  262. package/dist/interactions/portable-custom/extractor.d.ts +14 -0
  263. package/dist/interactions/portable-custom/extractor.d.ts.map +1 -0
  264. package/dist/interactions/portable-custom/extractor.js +96 -0
  265. package/dist/interactions/portable-custom/index.d.ts +3 -0
  266. package/dist/interactions/portable-custom/index.d.ts.map +1 -0
  267. package/dist/interactions/portable-custom/index.js +1 -0
  268. package/dist/interactions/portable-custom/types.d.ts +2 -0
  269. package/dist/interactions/portable-custom/types.d.ts.map +1 -0
  270. package/dist/interactions/portable-custom/types.js +1 -0
  271. package/dist/interactions/position-object/extractor.d.ts +59 -0
  272. package/dist/interactions/position-object/extractor.d.ts.map +1 -0
  273. package/dist/interactions/position-object/extractor.js +191 -0
  274. package/dist/interactions/position-object/index.d.ts +3 -0
  275. package/dist/interactions/position-object/index.d.ts.map +1 -0
  276. package/dist/interactions/position-object/index.js +1 -0
  277. package/dist/interactions/position-object/types.d.ts +2 -0
  278. package/dist/interactions/position-object/types.d.ts.map +1 -0
  279. package/dist/interactions/position-object/types.js +1 -0
  280. package/dist/interactions/select-point/extractor.d.ts +31 -0
  281. package/dist/interactions/select-point/extractor.d.ts.map +1 -0
  282. package/dist/interactions/select-point/extractor.js +109 -0
  283. package/dist/interactions/select-point/index.d.ts +3 -0
  284. package/dist/interactions/select-point/index.d.ts.map +1 -0
  285. package/dist/interactions/select-point/index.js +1 -0
  286. package/dist/interactions/select-point/types.d.ts +2 -0
  287. package/dist/interactions/select-point/types.d.ts.map +1 -0
  288. package/dist/interactions/select-point/types.js +1 -0
  289. package/dist/interactions/shared/index.d.ts +2 -0
  290. package/dist/interactions/shared/index.d.ts.map +1 -0
  291. package/dist/interactions/shared/index.js +1 -0
  292. package/dist/interactions/shared/types.d.ts +412 -0
  293. package/dist/interactions/shared/types.d.ts.map +1 -0
  294. package/dist/interactions/shared/types.js +7 -0
  295. package/dist/interactions/slider/extractor.d.ts +24 -0
  296. package/dist/interactions/slider/extractor.d.ts.map +1 -0
  297. package/dist/interactions/slider/extractor.js +73 -0
  298. package/dist/interactions/slider/index.d.ts +3 -0
  299. package/dist/interactions/slider/index.d.ts.map +1 -0
  300. package/dist/interactions/slider/index.js +1 -0
  301. package/dist/interactions/slider/types.d.ts +2 -0
  302. package/dist/interactions/slider/types.d.ts.map +1 -0
  303. package/dist/interactions/slider/types.js +1 -0
  304. package/dist/interactions/text-entry/extractor.d.ts +21 -0
  305. package/dist/interactions/text-entry/extractor.d.ts.map +1 -0
  306. package/dist/interactions/text-entry/extractor.js +54 -0
  307. package/dist/interactions/text-entry/index.d.ts +3 -0
  308. package/dist/interactions/text-entry/index.d.ts.map +1 -0
  309. package/dist/interactions/text-entry/index.js +1 -0
  310. package/dist/interactions/text-entry/types.d.ts +2 -0
  311. package/dist/interactions/text-entry/types.d.ts.map +1 -0
  312. package/dist/interactions/text-entry/types.js +1 -0
  313. package/dist/interactions/upload/extractor.d.ts +20 -0
  314. package/dist/interactions/upload/extractor.d.ts.map +1 -0
  315. package/dist/interactions/upload/extractor.js +59 -0
  316. package/dist/interactions/upload/index.d.ts +3 -0
  317. package/dist/interactions/upload/index.d.ts.map +1 -0
  318. package/dist/interactions/upload/index.js +1 -0
  319. package/dist/interactions/upload/types.d.ts +2 -0
  320. package/dist/interactions/upload/types.d.ts.map +1 -0
  321. package/dist/interactions/upload/types.js +1 -0
  322. package/dist/pnp/applyPnp.d.ts.map +1 -1
  323. package/dist/pnp/applyPnp.js +9 -2
  324. package/dist/pnp/parsePnpXml.d.ts.map +1 -1
  325. package/dist/pnp/parsePnpXml.js +91 -3
  326. package/dist/pnp/types.d.ts +24 -1
  327. package/dist/pnp/types.d.ts.map +1 -1
  328. package/dist/types/index.d.ts +47 -0
  329. package/dist/types/index.d.ts.map +1 -1
  330. package/dist/types/interactions.d.ts +4 -408
  331. package/dist/types/interactions.d.ts.map +1 -1
  332. package/dist/types/interactions.js +3 -3
  333. package/dist/web-components/QTIInteractionBase.d.ts +5 -5
  334. package/dist/web-components/QTIInteractionBase.d.ts.map +1 -1
  335. package/dist/web-components/QTIInteractionElement.d.ts +11 -8
  336. package/dist/web-components/QTIInteractionElement.d.ts.map +1 -1
  337. package/dist/web-components/index.d.ts +1 -1
  338. package/dist/web-components/index.d.ts.map +1 -1
  339. package/package.json +6 -6
  340. package/src/catalog/applyGlossaryTriggers.ts +174 -34
  341. package/src/catalog/glossaryAction.ts +14 -4
  342. package/src/components/ItemBody.svelte +71 -200
  343. package/src/components/ItemPlayer.svelte +9 -5
  344. package/src/components/ModalFeedbackDisplay.svelte +15 -5
  345. package/src/components/utils/stimulusRender.ts +93 -0
  346. package/src/components/utils/stylesheetRender.ts +58 -0
  347. package/src/core/ComponentRegistry.ts +22 -7
  348. package/src/core/Player.ts +401 -209
  349. package/src/document/AssessmentItemDocument.ts +178 -0
  350. package/src/extraction/extractors/associateExtractor.ts +1 -133
  351. package/src/extraction/extractors/choiceExtractor.ts +1 -121
  352. package/src/extraction/extractors/customExtractor.ts +1 -72
  353. package/src/extraction/extractors/drawingExtractor.ts +1 -113
  354. package/src/extraction/extractors/endAttemptExtractor.ts +1 -74
  355. package/src/extraction/extractors/extendedTextExtractor.ts +1 -89
  356. package/src/extraction/extractors/gapMatchExtractor.ts +1 -193
  357. package/src/extraction/extractors/graphicAssociateExtractor.ts +1 -192
  358. package/src/extraction/extractors/graphicGapMatchExtractor.ts +1 -257
  359. package/src/extraction/extractors/graphicOrderExtractor.ts +1 -162
  360. package/src/extraction/extractors/hotspotExtractor.ts +1 -208
  361. package/src/extraction/extractors/hottextExtractor.ts +1 -163
  362. package/src/extraction/extractors/index.ts +5 -111
  363. package/src/extraction/extractors/inlineChoiceExtractor.ts +1 -105
  364. package/src/extraction/extractors/matchExtractor.ts +1 -187
  365. package/src/extraction/extractors/mediaExtractor.ts +1 -168
  366. package/src/extraction/extractors/orderExtractor.ts +1 -120
  367. package/src/extraction/extractors/portableCustomExtractor.ts +1 -122
  368. package/src/extraction/extractors/positionObjectExtractor.ts +1 -243
  369. package/src/extraction/extractors/selectPointExtractor.ts +1 -143
  370. package/src/extraction/extractors/sliderExtractor.ts +1 -102
  371. package/src/extraction/extractors/textEntryExtractor.ts +1 -79
  372. package/src/extraction/extractors/uploadExtractor.ts +1 -81
  373. package/src/extraction/index.ts +1 -2
  374. package/src/extraction/interactionExtractionPipeline.ts +70 -0
  375. package/src/extraction/interactionSecurity.ts +60 -0
  376. package/src/index.ts +3 -7
  377. package/src/interactions/associate/extractor.ts +133 -0
  378. package/src/interactions/associate/index.ts +2 -0
  379. package/src/interactions/associate/types.ts +1 -0
  380. package/src/interactions/choice/extractor.ts +121 -0
  381. package/src/interactions/choice/index.ts +2 -0
  382. package/src/interactions/choice/types.ts +1 -0
  383. package/src/interactions/custom/extractor.ts +72 -0
  384. package/src/interactions/custom/index.ts +2 -0
  385. package/src/interactions/custom/types.ts +1 -0
  386. package/src/interactions/drawing/extractor.ts +113 -0
  387. package/src/interactions/drawing/index.ts +2 -0
  388. package/src/interactions/drawing/types.ts +1 -0
  389. package/src/interactions/end-attempt/extractor.ts +74 -0
  390. package/src/interactions/end-attempt/index.ts +2 -0
  391. package/src/interactions/end-attempt/types.ts +1 -0
  392. package/src/interactions/extended-text/extractor.ts +89 -0
  393. package/src/interactions/extended-text/index.ts +2 -0
  394. package/src/interactions/extended-text/types.ts +1 -0
  395. package/src/interactions/gap-match/extractor.ts +193 -0
  396. package/src/interactions/gap-match/index.ts +2 -0
  397. package/src/interactions/gap-match/types.ts +1 -0
  398. package/src/interactions/graphic-associate/extractor.ts +192 -0
  399. package/src/interactions/graphic-associate/index.ts +2 -0
  400. package/src/interactions/graphic-associate/types.ts +1 -0
  401. package/src/interactions/graphic-gap-match/extractor.ts +257 -0
  402. package/src/interactions/graphic-gap-match/index.ts +2 -0
  403. package/src/interactions/graphic-gap-match/types.ts +1 -0
  404. package/src/interactions/graphic-order/extractor.ts +162 -0
  405. package/src/interactions/graphic-order/index.ts +2 -0
  406. package/src/interactions/graphic-order/types.ts +1 -0
  407. package/src/interactions/hotspot/extractor.ts +208 -0
  408. package/src/interactions/hotspot/index.ts +2 -0
  409. package/src/interactions/hotspot/types.ts +1 -0
  410. package/src/interactions/hottext/extractor.ts +163 -0
  411. package/src/interactions/hottext/index.ts +2 -0
  412. package/src/interactions/hottext/types.ts +1 -0
  413. package/src/interactions/index.ts +52 -0
  414. package/src/interactions/inline/index.ts +1 -0
  415. package/src/interactions/inline/render-plan.ts +105 -0
  416. package/src/interactions/inline-choice/InlineChoice.svelte +57 -0
  417. package/src/interactions/inline-choice/extractor.ts +105 -0
  418. package/src/interactions/inline-choice/index.ts +2 -0
  419. package/src/interactions/inline-choice/types.ts +1 -0
  420. package/src/interactions/match/extractor.ts +187 -0
  421. package/src/interactions/match/index.ts +2 -0
  422. package/src/interactions/match/types.ts +1 -0
  423. package/src/interactions/media/extractor.ts +168 -0
  424. package/src/interactions/media/index.ts +2 -0
  425. package/src/interactions/media/types.ts +1 -0
  426. package/src/interactions/modules.ts +111 -0
  427. package/src/interactions/order/extractor.ts +120 -0
  428. package/src/interactions/order/index.ts +2 -0
  429. package/src/interactions/order/types.ts +1 -0
  430. package/src/interactions/portable-custom/extractor.ts +122 -0
  431. package/src/interactions/portable-custom/index.ts +2 -0
  432. package/src/interactions/portable-custom/types.ts +1 -0
  433. package/src/interactions/position-object/extractor.ts +243 -0
  434. package/src/interactions/position-object/index.ts +2 -0
  435. package/src/interactions/position-object/types.ts +1 -0
  436. package/src/interactions/select-point/extractor.ts +143 -0
  437. package/src/interactions/select-point/index.ts +2 -0
  438. package/src/interactions/select-point/types.ts +1 -0
  439. package/src/interactions/shared/index.ts +1 -0
  440. package/src/interactions/shared/types.ts +429 -0
  441. package/src/interactions/slider/extractor.ts +102 -0
  442. package/src/interactions/slider/index.ts +2 -0
  443. package/src/interactions/slider/types.ts +1 -0
  444. package/src/interactions/text-entry/InlineTextEntry.svelte +75 -0
  445. package/src/interactions/text-entry/extractor.ts +79 -0
  446. package/src/interactions/text-entry/index.ts +2 -0
  447. package/src/interactions/text-entry/types.ts +1 -0
  448. package/src/interactions/upload/extractor.ts +81 -0
  449. package/src/interactions/upload/index.ts +2 -0
  450. package/src/interactions/upload/types.ts +1 -0
  451. package/src/pnp/applyPnp.ts +8 -2
  452. package/src/pnp/parsePnpXml.ts +102 -5
  453. package/src/pnp/types.ts +43 -1
  454. package/src/types/index.ts +53 -0
  455. package/src/types/interactions.ts +4 -425
  456. package/src/web-components/QTIInteractionBase.ts +6 -5
  457. package/src/web-components/QTIInteractionElement.ts +15 -8
  458. package/src/web-components/index.ts +1 -0
  459. package/src/__tests__/glossaryTriggers.test.ts +0 -411
  460. package/src/__tests__/pnp.test.ts +0 -250
  461. package/src/core/ItemRenderer.ts +0 -371
@@ -1,16 +1,16 @@
1
- import { buildOutcomeProcessingAst, buildResponseProcessingAst, buildTemplateProcessingAst, childElements, coerceBaseValue, DeclarationContext, evalExpr, execProgram, findAssessmentItem, findDescendants, findFirstDescendant, getAttr, OperatorRegistry, parseXml, qtiNull, qtiValue, serializeXml, toBoolean, toNumber, toStringValue, } from '@pie-qti/qti-processing';
1
+ import { buildOutcomeProcessingAst, buildResponseProcessingAst, buildTemplateProcessingAst, childElements, coerceBaseValue, DeclarationContext, evalExpr, execProgram, findDescendants, findFirstDescendant, getAttr, OperatorRegistry, qtiNull, qtiValue, toBoolean, toNumber, toStringValue, } from '@pie-qti/qti-processing';
2
2
  import { Qti2xElementNameMapper, Qti2xAttributeNameMapper, Qti3ElementNameMapper, Qti3AttributeNameMapper, detectQtiVersion, } from '@pie-qti/qti-common';
3
- import { parse } from 'node-html-parser';
3
+ import { parseAssessmentItemDocument } from '../document/AssessmentItemDocument.js';
4
4
  import { createExtractionRegistry } from '../extraction/ExtractionRegistry.js';
5
- import { ALL_STANDARD_EXTRACTORS, createExtractionContext } from '../extraction/index.js';
5
+ import { extractInteractionData } from '../extraction/interactionExtractionPipeline.js';
6
+ import { getStandardInteractionExtractors } from '../interactions/modules.js';
6
7
  import { createComponentRegistry } from './ComponentRegistry.js';
7
- import { enforceItemXmlLimits } from './parsingLimits.js';
8
8
  import { createSeededRng } from './random.js';
9
9
  import { sanitizeHtml } from './sanitizer.js';
10
10
  import { toTrustedHtml } from './trustedTypes.js';
11
11
  import { sanitizeResourceUrl } from './urlPolicy.js';
12
12
  import { applyPnpToRoot } from '../pnp/applyPnp.js';
13
- import { extractCatalogFromItemXml, mergeCatalogs } from '../catalog/catalogExtractor.js';
13
+ import { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from '../catalog/catalogExtractor.js';
14
14
  import { getCatalogEntry } from '../catalog/catalogLookup.js';
15
15
  import { PciHost } from '../pci/PciHost.js';
16
16
  export class Player {
@@ -19,10 +19,16 @@ export class Player {
19
19
  this.templateProcessingProgram = null;
20
20
  this.outcomeProcessingProgram = null;
21
21
  this._catalogIndex = new Map();
22
+ this._stimulusCatalogIndexes = new Map();
22
23
  this._pciHosts = new Map();
24
+ this._pnpChangeListeners = new Set();
25
+ this.lifecycleStatus = 'initial';
26
+ this.accumulatedDurationMs = 0;
23
27
  this.config = config;
24
28
  this.itemXml = config.itemXml ?? '';
25
29
  this.role = config.role ?? 'candidate';
30
+ this.sessionGuid = createSessionGuid();
31
+ this.sessionStartedAt = Date.now();
26
32
  this.rng = config.rng ?? (typeof config.seed === 'number' ? createSeededRng(config.seed) : Math.random);
27
33
  // Auto-detect QTI version and create appropriate mappers if not provided
28
34
  if (!config.elementNameMapper) {
@@ -46,12 +52,21 @@ export class Player {
46
52
  }
47
53
  else {
48
54
  this.mapper = config.elementNameMapper;
55
+ if (!config.attributeNameMapper) {
56
+ config.attributeNameMapper =
57
+ this.mapper.version === '3.0'
58
+ ? new Qti3AttributeNameMapper()
59
+ : new Qti2xAttributeNameMapper();
60
+ }
49
61
  }
50
- // Optional DoS guardrails for untrusted content (compat-by-default; disabled unless enabled).
51
- enforceItemXmlLimits(this.itemXml, this.config.security);
52
- this.doc = parseXml(this.itemXml);
53
- this.assessmentItem = findAssessmentItem(this.doc);
54
- this.decls = this.buildDeclarations(this.assessmentItem);
62
+ this.itemDocument = parseAssessmentItemDocument({
63
+ itemXml: this.itemXml,
64
+ elementNameMapper: this.mapper,
65
+ attributeNameMapper: config.attributeNameMapper,
66
+ security: this.config.security,
67
+ });
68
+ this.assessmentItem = this.itemDocument.getAssessmentItem();
69
+ this.decls = this.buildDeclarations();
55
70
  this.ensureBuiltinDeclarations(this.decls);
56
71
  this.ctx = new DeclarationContext(this.decls);
57
72
  this.ops = new OperatorRegistry();
@@ -65,8 +80,8 @@ export class Player {
65
80
  this.componentRegistry = config.componentRegistry ?? createComponentRegistry();
66
81
  // I18n provider (defaults to a simple fallback if not provided)
67
82
  this.i18nProvider = config.i18nProvider ?? this.createDefaultI18nProvider();
68
- // Register standard extractors (idempotent per-registry instance)
69
- for (const ex of ALL_STANDARD_EXTRACTORS) {
83
+ // Register standard interaction extractors (idempotent per-registry instance)
84
+ for (const ex of getStandardInteractionExtractors()) {
70
85
  try {
71
86
  this.extractionRegistry.register(ex);
72
87
  }
@@ -85,20 +100,20 @@ export class Player {
85
100
  }
86
101
  }
87
102
  // Build ASTs once.
88
- const templateProcessing = findFirstDescendant(this.assessmentItem, this.mapper.toNative('templateprocessing'));
103
+ const templateProcessing = this.itemDocument.getProcessingElement('template');
89
104
  if (templateProcessing) {
90
105
  this.templateProcessingProgram = buildTemplateProcessingAst(templateProcessing, {
91
106
  elementNameMapper: this.mapper,
92
107
  });
93
108
  this.execTemplateProcessing();
94
109
  }
95
- const responseProcessing = findFirstDescendant(this.assessmentItem, this.mapper.toNative('responseprocessing'));
110
+ const responseProcessing = this.itemDocument.getProcessingElement('response');
96
111
  if (responseProcessing) {
97
112
  this.responseProcessingProgram = buildResponseProcessingAst(responseProcessing, {
98
113
  elementNameMapper: this.mapper,
99
114
  });
100
115
  }
101
- const outcomeProcessing = findFirstDescendant(this.assessmentItem, this.mapper.toNative('outcomeprocessing'));
116
+ const outcomeProcessing = this.itemDocument.getProcessingElement('outcome');
102
117
  if (outcomeProcessing) {
103
118
  this.outcomeProcessingProgram = buildOutcomeProcessingAst(outcomeProcessing, {
104
119
  elementNameMapper: this.mapper,
@@ -121,16 +136,24 @@ export class Player {
121
136
  }
122
137
  // Store PNP profile for later use (applyPnpToRoot is called once a root element is available).
123
138
  this._pnp = config.pnp;
124
- // Build catalog index from item XML and optional shared catalog.
125
- const itemCatalog = extractCatalogFromItemXml(this.itemXml);
126
- if (config.catalogXml) {
127
- const sharedCatalog = extractCatalogFromItemXml(config.catalogXml);
128
- // Item-level wins on collision: merge shared first, then override with item entries.
129
- this._catalogIndex = mergeCatalogs(sharedCatalog, itemCatalog);
139
+ // Build catalog index from resolved delivery context, legacy shared catalog XML, and item XML.
140
+ // Item/global entries are merged first; item-level entries win on global collisions.
141
+ // Stimulus entries are kept separately so rendered stimulus terms can avoid ID collisions.
142
+ let mergedCatalog = new Map();
143
+ for (const source of config.deliveryContext?.catalogSources ?? []) {
144
+ const sourceCatalog = extractCatalog(source.xml);
145
+ if (source.scope === 'stimulus' && source.stimulusIdentifier) {
146
+ const existing = this._stimulusCatalogIndexes.get(source.stimulusIdentifier) ?? new Map();
147
+ this._stimulusCatalogIndexes.set(source.stimulusIdentifier, mergeCatalogs(existing, sourceCatalog));
148
+ }
149
+ else {
150
+ mergedCatalog = mergeCatalogs(mergedCatalog, sourceCatalog);
151
+ }
130
152
  }
131
- else {
132
- this._catalogIndex = itemCatalog;
153
+ if (config.catalogXml) {
154
+ mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(config.catalogXml));
133
155
  }
156
+ this._catalogIndex = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(this.itemXml));
134
157
  // Check strict compliance if enabled
135
158
  if (this.config.strictQtiCompliance?.enabled) {
136
159
  this.validateStrictCompliance();
@@ -154,23 +177,47 @@ export class Player {
154
177
  if (this._rootEl) {
155
178
  applyPnpToRoot(this._rootEl, this._pnp);
156
179
  }
180
+ for (const listener of this._pnpChangeListeners) {
181
+ listener(this._pnp);
182
+ }
157
183
  }
158
184
  /** Return the current resolved PNP profile. */
159
185
  getPnp() {
160
186
  return this._pnp;
161
187
  }
188
+ onPnpChange(listener) {
189
+ this._pnpChangeListeners.add(listener);
190
+ return () => this._pnpChangeListeners.delete(listener);
191
+ }
192
+ /** Return the package/assessment-resolved delivery context, if one was supplied. */
193
+ getDeliveryContext() {
194
+ return this.config.deliveryContext;
195
+ }
162
196
  /**
163
197
  * Look up a catalog entry by card identifier, usage type, and optional language.
164
198
  * Returns the HTML string for the matched entry, or null if not found.
165
199
  *
166
200
  * Language fallback: exact match → prefix match → no-lang entry → null.
167
201
  */
168
- getCatalogEntry(idref, usage, lang) {
169
- return getCatalogEntry(this._catalogIndex, idref, usage, lang);
202
+ getCatalogEntry(idref, usage, lang, options) {
203
+ const stimulusHtml = options?.stimulusIdentifier
204
+ ? getCatalogEntry(this._stimulusCatalogIndexes.get(options.stimulusIdentifier) ?? new Map(), idref, usage, lang)
205
+ : null;
206
+ const html = stimulusHtml ?? getCatalogEntry(this._catalogIndex, idref, usage, lang);
207
+ if (html === null)
208
+ return null;
209
+ if (looksLikeCatalogUrl(html)) {
210
+ return sanitizeResourceUrl(html.trim(), this.config.security?.urlPolicy, 'img');
211
+ }
212
+ return this.sanitizeHtmlContent(html);
213
+ }
214
+ /** Sanitize externally resolved item-adjacent HTML before it reaches a rendering sink. */
215
+ sanitizeHtmlContent(html) {
216
+ return sanitizeHtml(html, { security: this.config.security });
170
217
  }
171
218
  /**
172
219
  * Create a PciHost for an extracted PCI and register it for response tracking.
173
- * The caller (typically ItemRenderer) is responsible for calling host.load() and
220
+ * The caller is responsible for calling host.load() and
174
221
  * host.initialize(domNode) once the DOM element is available.
175
222
  */
176
223
  createPciHost(data) {
@@ -237,45 +284,110 @@ export class Player {
237
284
  this.destroyPciHosts();
238
285
  }
239
286
  processResponses() {
240
- // Spec-aligned behavior: each processing run starts from outcome defaults.
241
- // This prevents stale outcomes when response/outcome processing doesn't set every variable.
242
- this.resetOutcomesToDefault();
243
- // Execute response processing if present
244
- const rpEl = findFirstDescendant(this.assessmentItem, this.mapper.toNative('responseprocessing'));
245
- if (rpEl) {
246
- // If responseProcessing has explicit statements, run the compiled program.
247
- // Otherwise, fall back to template-based processing (responseProcessing@template).
248
- const hasStatements = childElements(rpEl).length > 0;
249
- if (hasStatements) {
250
- this.execResponseProcessingProgram();
251
- }
252
- else {
253
- const templateUrl = getAttr(rpEl, 'template');
254
- if (templateUrl)
255
- this.execResponseProcessingTemplate(templateUrl);
256
- }
287
+ return this.runResponseProcessing({ finalizeNonAdaptiveAttempt: true });
288
+ }
289
+ saveItemSession() {
290
+ this.freezeDuration();
291
+ return this.serializeItemSession();
292
+ }
293
+ restoreItemSession(state) {
294
+ this.sessionGuid = state.sessionGuid;
295
+ this.lifecycleStatus = state.lifecycleStatus;
296
+ this.accumulatedDurationMs = Math.max(0, Number(state.duration) || 0);
297
+ this.sessionStartedAt = Date.now();
298
+ this.applySerializedVariables(state.responseVariables);
299
+ this.applySerializedVariables(state.outcomeVariables);
300
+ this.applySerializedVariables(state.templateVariables);
301
+ this.applySerializedVariables(state.contextVariables);
302
+ this.updateDuration();
303
+ }
304
+ suspendAttempt() {
305
+ const validation = this.validateResponses(this.getResponses());
306
+ this.lifecycleStatus = 'suspended';
307
+ const sessionState = this.saveItemSession();
308
+ return {
309
+ action: 'suspendAttempt',
310
+ lifecycleStatus: this.lifecycleStatus,
311
+ completionStatus: this.getCompletionStatus(),
312
+ numAttempts: this.getNumAttempts(),
313
+ duration: sessionState.duration,
314
+ completed: this.isCompleted(),
315
+ sessionState,
316
+ validation,
317
+ };
318
+ }
319
+ endAttempt(options = {}) {
320
+ const validate = options.validateResponses ?? false;
321
+ const validation = validate ? this.validateResponses(this.getResponses()) : undefined;
322
+ if (validation && !validation.valid) {
323
+ const sessionState = this.saveItemSession();
324
+ return {
325
+ action: 'endAttempt',
326
+ lifecycleStatus: this.lifecycleStatus,
327
+ completionStatus: this.getCompletionStatus(),
328
+ numAttempts: this.getNumAttempts(),
329
+ duration: sessionState.duration,
330
+ completed: this.isCompleted(),
331
+ sessionState,
332
+ validation,
333
+ };
257
334
  }
258
- // Execute outcome processing if present (runs after responseProcessing)
259
- this.execOutcomeProcessingProgram();
260
- // For non-adaptive items, update completionStatus and numAttempts after processing
261
- if (!this.isAdaptive()) {
262
- // Set completionStatus to 'completed' for non-adaptive items (single submission)
263
- this.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'completed'));
264
- // Increment numAttempts for non-adaptive items (tracks total submissions, including retries)
265
- const currentAttempts = this.getNumAttempts();
266
- this.ctx.setValue('numAttempts', qtiValue('integer', 'single', currentAttempts + 1));
335
+ const scoring = this.isAdaptive()
336
+ ? this.submitAttempt(options.countAttempt ?? true)
337
+ : this.runResponseProcessing({
338
+ finalizeNonAdaptiveAttempt: true,
339
+ countAttempt: options.countAttempt ?? true,
340
+ });
341
+ this.lifecycleStatus = scoring.completed ? 'closed' : 'interacting';
342
+ const sessionState = this.saveItemSession();
343
+ return {
344
+ action: 'endAttempt',
345
+ lifecycleStatus: this.lifecycleStatus,
346
+ completionStatus: this.getCompletionStatus(),
347
+ numAttempts: this.getNumAttempts(),
348
+ duration: sessionState.duration,
349
+ completed: scoring.completed,
350
+ sessionState,
351
+ validation,
352
+ scoring,
353
+ };
354
+ }
355
+ scoreAttempt() {
356
+ const scoring = this.runResponseProcessing({ finalizeNonAdaptiveAttempt: false });
357
+ const sessionState = this.saveItemSession();
358
+ return {
359
+ action: 'scoreAttempt',
360
+ lifecycleStatus: this.lifecycleStatus,
361
+ completionStatus: this.getCompletionStatus(),
362
+ numAttempts: this.getNumAttempts(),
363
+ duration: sessionState.duration,
364
+ completed: scoring.completed,
365
+ sessionState,
366
+ scoring,
367
+ };
368
+ }
369
+ newTemplate(options = {}) {
370
+ this.resetOutcomesToDefault();
371
+ if (options.resetResponses ?? true) {
372
+ this.resetResponsesToDefault();
267
373
  }
268
- const outcomes = this.collectOutcomes();
269
- const score = Number(outcomes.SCORE ?? 0);
270
- const maxScore = Number(outcomes.MAXSCORE ?? 1);
271
- const completionStatus = outcomes.completionStatus ?? 'not_attempted';
272
- const completed = completionStatus === 'completed' || !this.isAdaptive();
374
+ this.resetTemplatesToDefault();
375
+ this.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'not_attempted'));
376
+ this.ctx.setValue('numAttempts', qtiValue('integer', 'single', 0));
377
+ this.execTemplateProcessing();
378
+ this.lifecycleStatus = 'initial';
379
+ this.accumulatedDurationMs = 0;
380
+ this.sessionStartedAt = Date.now();
381
+ this.updateDuration();
382
+ const sessionState = this.serializeItemSession();
273
383
  return {
274
- score,
275
- maxScore,
276
- completed,
277
- outcomeValues: outcomes,
278
- modalFeedback: this.getModalFeedback(outcomes),
384
+ action: 'newTemplate',
385
+ lifecycleStatus: this.lifecycleStatus,
386
+ completionStatus: this.getCompletionStatus(),
387
+ numAttempts: this.getNumAttempts(),
388
+ duration: sessionState.duration,
389
+ completed: this.isCompleted(),
390
+ sessionState,
279
391
  };
280
392
  }
281
393
  getSecurityConfig() {
@@ -381,17 +493,74 @@ export class Player {
381
493
  continue;
382
494
  // Built-in stateful variables must survive across processing runs.
383
495
  // They are updated by the runtime (adaptive attempt tracking), not by outcome defaults.
384
- if (d.identifier === 'numAttempts' || d.identifier === 'completionStatus')
496
+ if (d.identifier === 'numAttempts' || d.identifier === 'completionStatus' || d.identifier === 'duration')
497
+ continue;
498
+ this.ctx.resetToDefault(d.identifier);
499
+ }
500
+ }
501
+ resetResponsesToDefault() {
502
+ for (const d of Object.values(this.decls)) {
503
+ if (d.__kind !== 'response')
385
504
  continue;
386
505
  this.ctx.resetToDefault(d.identifier);
506
+ this.setPciResponse(d.identifier, d.value.kind === 'value' ? d.value.value : null);
387
507
  }
388
508
  }
509
+ resetTemplatesToDefault() {
510
+ for (const d of Object.values(this.decls)) {
511
+ if (!d.isTemplate)
512
+ continue;
513
+ this.ctx.resetToDefault(d.identifier);
514
+ }
515
+ }
516
+ runResponseProcessing(options) {
517
+ this.updateDuration();
518
+ // Spec-aligned behavior: each processing run starts from outcome defaults.
519
+ // This prevents stale outcomes when response/outcome processing doesn't set every variable.
520
+ this.resetOutcomesToDefault();
521
+ // Execute response processing if present
522
+ const rpEl = this.itemDocument.getProcessingElement('response');
523
+ if (rpEl) {
524
+ // If responseProcessing has explicit statements, run the compiled program.
525
+ // Otherwise, fall back to template-based processing (responseProcessing@template).
526
+ const hasStatements = childElements(rpEl).length > 0;
527
+ if (hasStatements) {
528
+ this.execResponseProcessingProgram();
529
+ }
530
+ else {
531
+ const templateUrl = getAttr(rpEl, 'template');
532
+ if (templateUrl)
533
+ this.execResponseProcessingTemplate(templateUrl);
534
+ }
535
+ }
536
+ // Execute outcome processing if present (runs after responseProcessing)
537
+ this.execOutcomeProcessingProgram();
538
+ // Compatibility: processResponses() has historically finalized non-adaptive items.
539
+ // New scoreAttempt() uses this same engine with finalization disabled.
540
+ if (!this.isAdaptive() && options.finalizeNonAdaptiveAttempt) {
541
+ this.ctx.setValue('completionStatus', qtiValue('identifier', 'single', 'completed'));
542
+ if (options.countAttempt ?? true) {
543
+ const currentAttempts = this.getNumAttempts();
544
+ this.ctx.setValue('numAttempts', qtiValue('integer', 'single', currentAttempts + 1));
545
+ }
546
+ }
547
+ const outcomes = this.collectOutcomes();
548
+ const score = Number(outcomes.SCORE ?? 0);
549
+ const maxScore = Number(outcomes.MAXSCORE ?? 1);
550
+ const completionStatus = outcomes.completionStatus ?? 'not_attempted';
551
+ const completed = completionStatus === 'completed' || (!this.isAdaptive() && options.finalizeNonAdaptiveAttempt);
552
+ return {
553
+ score,
554
+ maxScore,
555
+ completed,
556
+ outcomeValues: outcomes,
557
+ modalFeedback: this.getModalFeedback(outcomes),
558
+ };
559
+ }
389
560
  getItemBodyHtml() {
390
- const itemBody = findFirstDescendant(this.assessmentItem, this.mapper.toNative('itembody'));
391
- if (!itemBody)
561
+ const inner = this.itemDocument.serializeItemBodyChildren();
562
+ if (!inner)
392
563
  return '';
393
- // Serialize children rather than the container tag itself.
394
- const inner = childElements(itemBody).map((c) => serializeXml(c)).join('');
395
564
  const printed = this.renderPrintedVariables(inner);
396
565
  const sanitized = sanitizeHtml(printed, { security: this.config.security });
397
566
  return toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
@@ -404,7 +573,7 @@ export class Player {
404
573
  */
405
574
  getRubrics() {
406
575
  const role = this.role;
407
- const rubricEls = findDescendants(this.assessmentItem, this.mapper.toNative('rubricblock'));
576
+ const rubricEls = this.itemDocument.findRubricElements();
408
577
  if (rubricEls.length === 0)
409
578
  return [];
410
579
  const blocks = [];
@@ -414,8 +583,7 @@ export class Player {
414
583
  // If view is specified, show only when it includes the current role.
415
584
  if (view.length > 0 && role && !view.includes(role))
416
585
  continue;
417
- // Serialize children rather than the container tag itself.
418
- const contentRaw = childElements(el).map((c) => serializeXml(c)).join('') || (el.textContent || '');
586
+ const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
419
587
  const printed = this.renderPrintedVariables(contentRaw);
420
588
  const sanitized = sanitizeHtml(printed, { security: this.config.security });
421
589
  const html = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
@@ -433,118 +601,12 @@ export class Player {
433
601
  * Canonical interaction API (new): extracted, typed interaction data.
434
602
  */
435
603
  getInteractionData() {
436
- const itemBody = findFirstDescendant(this.assessmentItem, this.mapper.toNative('itembody'));
437
- if (!itemBody)
438
- return [];
439
- // Parse the original item XML with node-html-parser (extractors depend on its HTMLElement API).
440
- // Important: using the original XML avoids namespace/serialization artifacts from XMLSerializer.
441
- enforceItemXmlLimits(this.itemXml, this.config.security);
442
- const docRoot = parse(this.itemXml, { lowerCaseTagName: false, comment: false });
443
- // node-html-parser's CSS selectors match lowercase tag names.
444
- // Search for itemBody in the native form for this QTI version (itembody for 2.x, qti-item-body for 3.0)
445
- const itemBodyTag = this.mapper.toNative('itembody').toLowerCase();
446
- const parsedItemBody = docRoot.querySelector?.(itemBodyTag) ?? null;
447
- const root = parsedItemBody ?? docRoot;
448
- const declMap = new Map();
449
- for (const d of Object.values(this.decls)) {
450
- declMap.set(d.identifier, {
451
- identifier: d.identifier,
452
- cardinality: d.cardinality,
453
- baseType: d.baseType,
454
- });
455
- }
456
- // Discover all elements that match any standard extractor elementType.
457
- // Extractors specify element types in QTI 2.x form (e.g., 'choiceInteraction').
458
- // We use the mapper to convert to the appropriate form for this QTI version
459
- // (e.g., 'choiceInteraction' for QTI 2.x, 'qti-choice-interaction' for QTI 3.0).
460
- const tagSet = new Set();
461
- for (const ex of ALL_STANDARD_EXTRACTORS) {
462
- for (const t of ex.elementTypes ?? []) {
463
- // Convert to canonical form (lowercase), then to native form using mapper
464
- const canonical = t.toLowerCase();
465
- const native = this.mapper.toNative(canonical);
466
- tagSet.add(native.toLowerCase());
467
- }
468
- }
469
- const elements = [];
470
- for (const tag of tagSet) {
471
- try {
472
- elements.push(...root.querySelectorAll(tag));
473
- }
474
- catch {
475
- // ignore selector errors
476
- }
477
- }
478
- const interactions = [];
479
- for (const el of elements) {
480
- // Try both QTI 2.x (responseIdentifier) and QTI 3.0 (response-identifier) attribute names
481
- const responseId = el.getAttribute?.('responseIdentifier') ||
482
- el.getAttribute?.('response-identifier') ||
483
- el.getAttribute?.('responseidentifier') ||
484
- '';
485
- if (!responseId)
486
- continue;
487
- const ctx = createExtractionContext(el, responseId, root, declMap, this.config);
488
- const res = this.extractionRegistry.extract(el, ctx);
489
- if (!res.success)
490
- continue;
491
- // Normalize raw tag to QTI 2.x camelCase for ComponentRegistry compatibility.
492
- // QTI 3.0 elements use kebab-case with 'qti-' prefix:
493
- // 'qti-choice-interaction' → 'choiceInteraction'
494
- const rawTag = el.rawTagName;
495
- const normalizedType = rawTag.startsWith('qti-')
496
- ? rawTag.slice(4).replace(/-([a-z])/g, (_, c) => c.toUpperCase())
497
- : rawTag;
498
- interactions.push({
499
- type: normalizedType,
500
- responseId,
501
- ...res.data,
502
- });
503
- }
504
- // Apply URL policy + embed allowances to standard extracted URL fields.
505
- const policy = this.config.security?.urlPolicy;
506
- const allowObjectEmbeds = this.config.security?.allowObjectEmbeds === true;
507
- const ttPolicyName = this.config.security?.trustedTypesPolicyName;
508
- for (const i of interactions) {
509
- // Wrap known HTML injection fields in TrustedHTML (when enabled).
510
- // Important: do NOT wrap fields that are rendered as plain text in our Svelte components
511
- // (e.g. prompt) to avoid "[object Object]" rendering.
512
- if (i.type === 'choiceInteraction' && Array.isArray(i.choices)) {
513
- for (const c of i.choices) {
514
- if (typeof c?.text === 'string')
515
- c.text = toTrustedHtml(c.text, ttPolicyName);
516
- }
517
- }
518
- // Shared ImageData shape
519
- if (i.imageData?.src) {
520
- i.imageData.src = sanitizeResourceUrl(i.imageData.src, policy, 'img') ?? '';
521
- }
522
- if (i.imageData?.content && typeof i.imageData.content === 'string') {
523
- i.imageData.content = toTrustedHtml(i.imageData.content, ttPolicyName);
524
- }
525
- // positionObject stages
526
- if (Array.isArray(i.positionObjectStages)) {
527
- for (const st of i.positionObjectStages) {
528
- if (st?.objectData?.src) {
529
- st.objectData.src = sanitizeResourceUrl(st.objectData.src, policy, 'img') ?? '';
530
- }
531
- if (st?.objectData?.content && typeof st.objectData.content === 'string') {
532
- st.objectData.content = toTrustedHtml(st.objectData.content, ttPolicyName);
533
- }
534
- }
535
- }
536
- // mediaInteraction
537
- if (i.type === 'mediaInteraction' && i.mediaElement?.src) {
538
- const kind = i.mediaElement.type === 'object' ? 'object' : 'media';
539
- i.mediaElement.src = sanitizeResourceUrl(i.mediaElement.src, policy, kind) ?? '';
540
- i.allowObjectEmbeds = allowObjectEmbeds;
541
- }
542
- // hottextInteraction content is injected via {@html}
543
- if (i.type === 'hottextInteraction' && typeof i.contentHtml === 'string') {
544
- i.contentHtml = toTrustedHtml(i.contentHtml, ttPolicyName);
545
- }
546
- }
547
- return interactions;
604
+ return extractInteractionData({
605
+ document: this.itemDocument,
606
+ extractionRegistry: this.extractionRegistry,
607
+ declarations: this.decls,
608
+ config: this.config,
609
+ });
548
610
  }
549
611
  /**
550
612
  * Convenience API (used by tests/bench): returns a minimal interaction list with QTI-ish field names.
@@ -571,7 +633,7 @@ export class Player {
571
633
  return this.getResponseInteractions().map((i) => i.responseIdentifier);
572
634
  }
573
635
  isAdaptive() {
574
- return (getAttr(this.assessmentItem, 'adaptive') || '').toLowerCase() === 'true';
636
+ return (this.itemDocument.getAssessmentItemAttribute('adaptive') || '').toLowerCase() === 'true';
575
637
  }
576
638
  getNumAttempts() {
577
639
  return Math.max(0, Math.floor(toNumber(this.ctx.getValue('numAttempts')) || 0));
@@ -906,7 +968,7 @@ export class Player {
906
968
  // ----------------------------------------------------------------------------
907
969
  // Declarations
908
970
  // ----------------------------------------------------------------------------
909
- buildDeclarations(root) {
971
+ buildDeclarations() {
910
972
  const decls = {};
911
973
  const addDecl = (kind, el) => {
912
974
  const identifier = this.getAttrMapped(el, 'identifier');
@@ -956,11 +1018,11 @@ export class Player {
956
1018
  }
957
1019
  }
958
1020
  };
959
- for (const el of findDescendants(root, this.mapper.toNative('responsedeclaration')))
1021
+ for (const el of this.itemDocument.findDeclarationElements('response'))
960
1022
  addDecl('response', el);
961
- for (const el of findDescendants(root, this.mapper.toNative('outcomedeclaration')))
1023
+ for (const el of this.itemDocument.findDeclarationElements('outcome'))
962
1024
  addDecl('outcome', el);
963
- for (const el of findDescendants(root, this.mapper.toNative('templatedeclaration')))
1025
+ for (const el of this.itemDocument.findDeclarationElements('template'))
964
1026
  addDecl('template', el);
965
1027
  return decls;
966
1028
  }
@@ -1011,12 +1073,25 @@ export class Player {
1011
1073
  identifier: 'numAttempts',
1012
1074
  baseType: 'integer',
1013
1075
  cardinality: 'single',
1076
+ defaultValue: qtiValue('integer', 'single', 0),
1014
1077
  value: qtiValue('integer', 'single', 0),
1015
1078
  isTemplate: false,
1016
1079
  // @ts-expect-error internal marker
1017
1080
  __kind: 'outcome',
1018
1081
  };
1019
1082
  }
1083
+ if (!decls.duration) {
1084
+ decls.duration = {
1085
+ identifier: 'duration',
1086
+ baseType: 'duration',
1087
+ cardinality: 'single',
1088
+ defaultValue: qtiValue('duration', 'single', 0),
1089
+ value: qtiValue('duration', 'single', 0),
1090
+ isTemplate: false,
1091
+ // @ts-expect-error internal marker
1092
+ __kind: 'outcome',
1093
+ };
1094
+ }
1020
1095
  // Common scoring defaults
1021
1096
  if (!decls.SCORE) {
1022
1097
  decls.SCORE = {
@@ -1048,6 +1123,91 @@ export class Player {
1048
1123
  continue;
1049
1124
  d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, raw);
1050
1125
  }
1126
+ const restoredDuration = Number(state.duration);
1127
+ if (Number.isFinite(restoredDuration) && restoredDuration >= 0) {
1128
+ this.accumulatedDurationMs = restoredDuration;
1129
+ this.sessionStartedAt = Date.now();
1130
+ this.updateDuration();
1131
+ }
1132
+ }
1133
+ applySerializedVariables(vars) {
1134
+ for (const v of Object.values(vars)) {
1135
+ const d = this.decls[v.identifier];
1136
+ if (!d)
1137
+ continue;
1138
+ d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, v.value);
1139
+ if (d.__kind === 'response') {
1140
+ this.setPciResponse(d.identifier, v.value);
1141
+ }
1142
+ }
1143
+ }
1144
+ serializeItemSession() {
1145
+ const responseVariables = {};
1146
+ const outcomeVariables = {};
1147
+ const templateVariables = {};
1148
+ const contextVariables = {};
1149
+ const contextIds = new Set(['completionStatus', 'numAttempts', 'duration']);
1150
+ for (const d of Object.values(this.decls)) {
1151
+ const variable = this.serializeVariable(d);
1152
+ if (d.isTemplate) {
1153
+ templateVariables[d.identifier] = { ...variable, kind: 'template' };
1154
+ }
1155
+ else if (contextIds.has(d.identifier)) {
1156
+ contextVariables[d.identifier] = { ...variable, kind: 'context' };
1157
+ }
1158
+ else if (d.__kind === 'response') {
1159
+ responseVariables[d.identifier] = { ...variable, kind: 'response' };
1160
+ }
1161
+ else if (d.__kind === 'outcome') {
1162
+ outcomeVariables[d.identifier] = { ...variable, kind: 'outcome' };
1163
+ }
1164
+ }
1165
+ const validation = this.validateResponses(this.getResponses());
1166
+ return {
1167
+ itemIdentifier: this.itemDocument.getAssessmentItemAttribute('identifier') ?? undefined,
1168
+ sessionGuid: this.sessionGuid,
1169
+ lifecycleStatus: this.lifecycleStatus,
1170
+ completionStatus: this.getCompletionStatus(),
1171
+ numAttempts: this.getNumAttempts(),
1172
+ duration: this.getDuration(),
1173
+ responseVariables,
1174
+ outcomeVariables,
1175
+ templateVariables,
1176
+ contextVariables,
1177
+ validationMessages: validation.issues,
1178
+ savedAt: new Date().toISOString(),
1179
+ };
1180
+ }
1181
+ serializeVariable(d) {
1182
+ return {
1183
+ identifier: d.identifier,
1184
+ kind: (d.__kind ?? (d.isTemplate ? 'template' : 'context')),
1185
+ baseType: d.baseType,
1186
+ cardinality: d.cardinality,
1187
+ value: this.qtiValueToSerializable(d.value),
1188
+ defaultValue: this.qtiValueToSerializable(d.defaultValue),
1189
+ };
1190
+ }
1191
+ qtiValueToSerializable(value) {
1192
+ if (!value || value.kind !== 'value')
1193
+ return null;
1194
+ return value.value;
1195
+ }
1196
+ updateDuration() {
1197
+ const elapsedMs = Math.max(0, Date.now() - this.sessionStartedAt);
1198
+ const durationMs = this.accumulatedDurationMs + elapsedMs;
1199
+ this.ctx.setValue('duration', qtiValue('duration', 'single', durationMs));
1200
+ }
1201
+ freezeDuration() {
1202
+ this.updateDuration();
1203
+ const duration = this.getDuration();
1204
+ this.accumulatedDurationMs = duration;
1205
+ this.sessionStartedAt = Date.now();
1206
+ return duration;
1207
+ }
1208
+ getDuration() {
1209
+ const value = this.ctx.getValue('duration');
1210
+ return Math.max(0, Math.floor(toNumber(value) || 0));
1051
1211
  }
1052
1212
  parseDefaultValue(declEl, baseType, cardinality) {
1053
1213
  const defaultEl = findFirstDescendant(declEl, this.mapper.toNative('defaultvalue'));
@@ -1204,14 +1364,14 @@ export class Player {
1204
1364
  return out;
1205
1365
  }
1206
1366
  getModalFeedback(outcomes) {
1207
- const feedbackEls = findDescendants(this.assessmentItem, this.mapper.toNative('modalfeedback'));
1367
+ const feedbackEls = this.itemDocument.findModalFeedbackElements();
1208
1368
  const active = [];
1209
1369
  for (const el of feedbackEls) {
1210
- const identifier = getAttr(el, 'identifier') || '';
1211
- const outcomeIdentifier = getAttr(el, 'outcomeIdentifier') || '';
1212
- const showHide = (getAttr(el, 'showHide') || 'show');
1213
- const title = getAttr(el, 'title') || undefined;
1214
- const contentRaw = childElements(el).map((c) => serializeXml(c)).join('') || (el.textContent || '');
1370
+ const identifier = this.getAttrMapped(el, 'identifier') || '';
1371
+ const outcomeIdentifier = this.getAttrMapped(el, 'outcomeIdentifier') || '';
1372
+ const showHide = (this.getAttrMapped(el, 'showHide') || 'show');
1373
+ const title = this.getAttrMapped(el, 'title') || undefined;
1374
+ const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
1215
1375
  const sanitized = sanitizeHtml(contentRaw, { security: this.config.security });
1216
1376
  const content = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
1217
1377
  const outcomeValue = outcomes[outcomeIdentifier];
@@ -1233,3 +1393,14 @@ function mergePnp(base, partial) {
1233
1393
  cognitive: { ...(base?.cognitive ?? {}), ...(partial.cognitive ?? {}) },
1234
1394
  };
1235
1395
  }
1396
+ function createSessionGuid() {
1397
+ if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
1398
+ return crypto.randomUUID();
1399
+ }
1400
+ return `item-session-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
1401
+ }
1402
+ function looksLikeCatalogUrl(value) {
1403
+ const trimmed = value.trim();
1404
+ return /^(https?:\/\/|\/\/|\/|\.{0,2}\/|data:|blob:)/i.test(trimmed) ||
1405
+ /\.(png|jpe?g|gif|webp|svg|mp3|wav|ogg|mp4|webm|pdf)(\?.*)?$/i.test(trimmed);
1406
+ }