@pie-qti/item-player 0.1.1

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 (335) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +466 -0
  4. package/docs/QTI-COMPLIANCE.md +197 -0
  5. package/docs/WCAG-2.2-COMPLIANCE.md +466 -0
  6. package/docs/custom-extractors.md +679 -0
  7. package/docs/iframe-mode.md +78 -0
  8. package/docs/security-audit.md +236 -0
  9. package/docs/server-api.md +691 -0
  10. package/package.json +78 -0
  11. package/src/components/ItemBody.svelte +382 -0
  12. package/src/components/ItemPlayer.svelte +155 -0
  13. package/src/components/ModalFeedbackDisplay.svelte +87 -0
  14. package/src/components/actions/typesetAction.ts +74 -0
  15. package/src/components/index.ts +19 -0
  16. package/src/components/utils/assignProps.ts +24 -0
  17. package/src/components/utils/feedbackUtils.ts +140 -0
  18. package/src/components/utils/index.ts +13 -0
  19. package/src/core/ComponentRegistry.ts +219 -0
  20. package/src/core/ItemRenderer.ts +367 -0
  21. package/src/core/Player.ts +1152 -0
  22. package/src/core/Plugin.ts +123 -0
  23. package/src/core/PluginManager.ts +182 -0
  24. package/src/core/constants.ts +117 -0
  25. package/src/core/declarations.ts +171 -0
  26. package/src/core/parsingLimits.ts +62 -0
  27. package/src/core/random.ts +24 -0
  28. package/src/core/sanitizer.ts +235 -0
  29. package/src/core/trustedTypes.ts +63 -0
  30. package/src/core/urlPolicy.ts +95 -0
  31. package/src/extensions/MathLiveEditor.ts +310 -0
  32. package/src/extraction/ExtractionRegistry.ts +295 -0
  33. package/src/extraction/createContext.ts +47 -0
  34. package/src/extraction/extractors/associateExtractor.ts +129 -0
  35. package/src/extraction/extractors/choiceExtractor.ts +110 -0
  36. package/src/extraction/extractors/customExtractor.ts +72 -0
  37. package/src/extraction/extractors/drawingExtractor.ts +113 -0
  38. package/src/extraction/extractors/endAttemptExtractor.ts +74 -0
  39. package/src/extraction/extractors/extendedTextExtractor.ts +80 -0
  40. package/src/extraction/extractors/gapMatchExtractor.ts +178 -0
  41. package/src/extraction/extractors/graphicAssociateExtractor.ts +188 -0
  42. package/src/extraction/extractors/graphicGapMatchExtractor.ts +185 -0
  43. package/src/extraction/extractors/graphicOrderExtractor.ts +162 -0
  44. package/src/extraction/extractors/hotspotExtractor.ts +190 -0
  45. package/src/extraction/extractors/hottextExtractor.ts +153 -0
  46. package/src/extraction/extractors/index.ts +111 -0
  47. package/src/extraction/extractors/inlineChoiceExtractor.ts +88 -0
  48. package/src/extraction/extractors/matchExtractor.ts +160 -0
  49. package/src/extraction/extractors/mediaExtractor.ts +168 -0
  50. package/src/extraction/extractors/orderExtractor.ts +114 -0
  51. package/src/extraction/extractors/positionObjectExtractor.ts +243 -0
  52. package/src/extraction/extractors/selectPointExtractor.ts +143 -0
  53. package/src/extraction/extractors/sliderExtractor.ts +102 -0
  54. package/src/extraction/extractors/textEntryExtractor.ts +70 -0
  55. package/src/extraction/extractors/uploadExtractor.ts +73 -0
  56. package/src/extraction/index.ts +109 -0
  57. package/src/extraction/types.ts +246 -0
  58. package/src/extraction/utils.ts +160 -0
  59. package/src/iframe/IFramePlayerHost.ts +265 -0
  60. package/src/iframe/index.ts +11 -0
  61. package/src/iframe/protocol.ts +137 -0
  62. package/src/index.ts +87 -0
  63. package/src/server.ts +14 -0
  64. package/src/types/index.ts +301 -0
  65. package/src/types/interactions.ts +354 -0
  66. package/src/types/responseValidation.ts +29 -0
  67. package/src/utils/PerformanceMonitor.ts +335 -0
  68. package/src/utils/responseUtils.ts +51 -0
  69. package/src/utils/touchDragHelper.ts +211 -0
  70. package/src/web-components/QTIInteractionBase.ts +302 -0
  71. package/src/web-components/QTIInteractionElement.ts +118 -0
  72. package/src/web-components/index.ts +21 -0
  73. package/tests/conformance/FIXTURE_POLICY.md +29 -0
  74. package/tests/conformance/README.md +70 -0
  75. package/tests/conformance/fixtures/baseTypes_all/cases.json +61 -0
  76. package/tests/conformance/fixtures/baseTypes_all/item.xml +131 -0
  77. package/tests/conformance/fixtures/baseTypes_all/manifest.json +7 -0
  78. package/tests/conformance/fixtures/choice_match_correct/cases.json +17 -0
  79. package/tests/conformance/fixtures/choice_match_correct/item.xml +55 -0
  80. package/tests/conformance/fixtures/choice_match_correct/manifest.json +14 -0
  81. package/tests/conformance/fixtures/contains_multiple/cases.json +12 -0
  82. package/tests/conformance/fixtures/contains_multiple/item.xml +37 -0
  83. package/tests/conformance/fixtures/contains_multiple/manifest.json +13 -0
  84. package/tests/conformance/fixtures/isNull_isNotNull/cases.json +9 -0
  85. package/tests/conformance/fixtures/isNull_isNotNull/item.xml +41 -0
  86. package/tests/conformance/fixtures/isNull_isNotNull/manifest.json +23 -0
  87. package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/cases.json +27 -0
  88. package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/item.xml +30 -0
  89. package/tests/conformance/fixtures/mapResponse_bounds_default_duplicates/manifest.json +15 -0
  90. package/tests/conformance/fixtures/mapResponse_integer_mapKey/cases.json +11 -0
  91. package/tests/conformance/fixtures/mapResponse_integer_mapKey/item.xml +26 -0
  92. package/tests/conformance/fixtures/mapResponse_integer_mapKey/manifest.json +13 -0
  93. package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/cases.json +27 -0
  94. package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/item.xml +32 -0
  95. package/tests/conformance/fixtures/mapResponse_mapEntry_caseSensitive_override/manifest.json +7 -0
  96. package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/cases.json +9 -0
  97. package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/item.xml +25 -0
  98. package/tests/conformance/fixtures/mapResponse_mapping_caseSensitive_defaultValue/manifest.json +12 -0
  99. package/tests/conformance/fixtures/mapResponse_multiple_cardinality/cases.json +12 -0
  100. package/tests/conformance/fixtures/mapResponse_multiple_cardinality/item.xml +35 -0
  101. package/tests/conformance/fixtures/mapResponse_multiple_cardinality/manifest.json +11 -0
  102. package/tests/conformance/fixtures/mapping_bounds_upperLower/cases.json +12 -0
  103. package/tests/conformance/fixtures/mapping_bounds_upperLower/item.xml +37 -0
  104. package/tests/conformance/fixtures/mapping_bounds_upperLower/manifest.json +11 -0
  105. package/tests/conformance/fixtures/mapping_mapResponse/cases.json +22 -0
  106. package/tests/conformance/fixtures/mapping_mapResponse/item.xml +53 -0
  107. package/tests/conformance/fixtures/mapping_mapResponse/manifest.json +16 -0
  108. package/tests/conformance/fixtures/member_multiple/cases.json +12 -0
  109. package/tests/conformance/fixtures/member_multiple/item.xml +37 -0
  110. package/tests/conformance/fixtures/member_multiple/manifest.json +13 -0
  111. package/tests/conformance/fixtures/modalFeedback_basic/cases.json +17 -0
  112. package/tests/conformance/fixtures/modalFeedback_basic/item.xml +52 -0
  113. package/tests/conformance/fixtures/modalFeedback_basic/manifest.json +13 -0
  114. package/tests/conformance/fixtures/multiple_unordered_match/cases.json +17 -0
  115. package/tests/conformance/fixtures/multiple_unordered_match/item.xml +44 -0
  116. package/tests/conformance/fixtures/multiple_unordered_match/manifest.json +11 -0
  117. package/tests/conformance/fixtures/ordered_match/cases.json +17 -0
  118. package/tests/conformance/fixtures/ordered_match/item.xml +48 -0
  119. package/tests/conformance/fixtures/ordered_match/manifest.json +13 -0
  120. package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/cases.json +27 -0
  121. package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/item.xml +103 -0
  122. package/tests/conformance/fixtures/outcomeProcessing_derive_percent_passfail/manifest.json +7 -0
  123. package/tests/conformance/fixtures/outcomeProcessing_exitTest/cases.json +15 -0
  124. package/tests/conformance/fixtures/outcomeProcessing_exitTest/item.xml +33 -0
  125. package/tests/conformance/fixtures/outcomeProcessing_exitTest/manifest.json +10 -0
  126. package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/cases.json +14 -0
  127. package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/item.xml +26 -0
  128. package/tests/conformance/fixtures/outcomeProcessing_numberExpressions/manifest.json +8 -0
  129. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/cases.json +17 -0
  130. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/item.xml +43 -0
  131. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_equal/manifest.json +16 -0
  132. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/cases.json +27 -0
  133. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/item.xml +37 -0
  134. package/tests/conformance/fixtures/outcomeProcessing_outcomeCondition_toBoolean/manifest.json +16 -0
  135. package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/cases.json +14 -0
  136. package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/item.xml +35 -0
  137. package/tests/conformance/fixtures/outcomeProcessing_outcomeMaximum/manifest.json +8 -0
  138. package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/cases.json +14 -0
  139. package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/item.xml +35 -0
  140. package/tests/conformance/fixtures/outcomeProcessing_outcomeMinimum/manifest.json +8 -0
  141. package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/cases.json +15 -0
  142. package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/item.xml +39 -0
  143. package/tests/conformance/fixtures/outcomeProcessing_outcomeProcessingFragment/manifest.json +11 -0
  144. package/tests/conformance/fixtures/outcomeProcessing_testVariables/cases.json +14 -0
  145. package/tests/conformance/fixtures/outcomeProcessing_testVariables/item.xml +35 -0
  146. package/tests/conformance/fixtures/outcomeProcessing_testVariables/manifest.json +8 -0
  147. package/tests/conformance/fixtures/pair_unordered_match/cases.json +22 -0
  148. package/tests/conformance/fixtures/pair_unordered_match/item.xml +44 -0
  149. package/tests/conformance/fixtures/pair_unordered_match/manifest.json +13 -0
  150. package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/cases.json +95 -0
  151. package/tests/conformance/fixtures/positionObject_coordinateSystem_aspectRatio/item.xml +53 -0
  152. package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/cases.json +115 -0
  153. package/tests/conformance/fixtures/positionObject_mapResponsePoint_scoring/item.xml +45 -0
  154. package/tests/conformance/fixtures/positionObject_mapResponse_wrong/cases.json +29 -0
  155. package/tests/conformance/fixtures/positionObject_mapResponse_wrong/item.xml +40 -0
  156. package/tests/conformance/fixtures/responseCondition_elseIf_chain/cases.json +10 -0
  157. package/tests/conformance/fixtures/responseCondition_elseIf_chain/item.xml +49 -0
  158. package/tests/conformance/fixtures/responseCondition_elseIf_chain/manifest.json +15 -0
  159. package/tests/conformance/fixtures/responseProcessing_anyN/cases.json +27 -0
  160. package/tests/conformance/fixtures/responseProcessing_anyN/item.xml +47 -0
  161. package/tests/conformance/fixtures/responseProcessing_anyN/manifest.json +16 -0
  162. package/tests/conformance/fixtures/responseProcessing_anyN_allN/cases.json +27 -0
  163. package/tests/conformance/fixtures/responseProcessing_anyN_allN/item.xml +69 -0
  164. package/tests/conformance/fixtures/responseProcessing_anyN_allN/manifest.json +23 -0
  165. package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/cases.json +15 -0
  166. package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/item.xml +58 -0
  167. package/tests/conformance/fixtures/responseProcessing_arithmetic_nulls/manifest.json +15 -0
  168. package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/cases.json +37 -0
  169. package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/item.xml +94 -0
  170. package/tests/conformance/fixtures/responseProcessing_boolean_compare_ops/manifest.json +27 -0
  171. package/tests/conformance/fixtures/responseProcessing_containerSize_index/cases.json +33 -0
  172. package/tests/conformance/fixtures/responseProcessing_containerSize_index/item.xml +79 -0
  173. package/tests/conformance/fixtures/responseProcessing_containerSize_index/manifest.json +16 -0
  174. package/tests/conformance/fixtures/responseProcessing_customOperator/cases.json +15 -0
  175. package/tests/conformance/fixtures/responseProcessing_customOperator/item.xml +30 -0
  176. package/tests/conformance/fixtures/responseProcessing_customOperator/manifest.json +12 -0
  177. package/tests/conformance/fixtures/responseProcessing_default_expression/cases.json +12 -0
  178. package/tests/conformance/fixtures/responseProcessing_default_expression/item.xml +48 -0
  179. package/tests/conformance/fixtures/responseProcessing_default_expression/manifest.json +13 -0
  180. package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/cases.json +29 -0
  181. package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/item.xml +68 -0
  182. package/tests/conformance/fixtures/responseProcessing_deleteValue_repeat/manifest.json +17 -0
  183. package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/cases.json +39 -0
  184. package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/item.xml +39 -0
  185. package/tests/conformance/fixtures/responseProcessing_equalRounded_tolerance/manifest.json +17 -0
  186. package/tests/conformance/fixtures/responseProcessing_exitResponse/cases.json +12 -0
  187. package/tests/conformance/fixtures/responseProcessing_exitResponse/item.xml +25 -0
  188. package/tests/conformance/fixtures/responseProcessing_exitResponse/manifest.json +12 -0
  189. package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/cases.json +26 -0
  190. package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/item.xml +134 -0
  191. package/tests/conformance/fixtures/responseProcessing_inside_duration_statsOperator/manifest.json +16 -0
  192. package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/cases.json +27 -0
  193. package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/item.xml +33 -0
  194. package/tests/conformance/fixtures/responseProcessing_lookupTable_interpolationTable/manifest.json +13 -0
  195. package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/cases.json +22 -0
  196. package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/item.xml +33 -0
  197. package/tests/conformance/fixtures/responseProcessing_lookupTable_matchTable/manifest.json +13 -0
  198. package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/cases.json +27 -0
  199. package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/item.xml +40 -0
  200. package/tests/conformance/fixtures/responseProcessing_mapOutcome_basic/manifest.json +18 -0
  201. package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/cases.json +22 -0
  202. package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/item.xml +33 -0
  203. package/tests/conformance/fixtures/responseProcessing_mapResponsePoint_basic/manifest.json +12 -0
  204. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/cases.json +29 -0
  205. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/item.xml +26 -0
  206. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_ordered/manifest.json +7 -0
  207. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/cases.json +23 -0
  208. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/item.xml +28 -0
  209. package/tests/conformance/fixtures/responseProcessing_mapResponse_directedPair_whitespace/manifest.json +11 -0
  210. package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/cases.json +29 -0
  211. package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/item.xml +26 -0
  212. package/tests/conformance/fixtures/responseProcessing_mapResponse_pair_unordered/manifest.json +7 -0
  213. package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/cases.json +31 -0
  214. package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/item.xml +102 -0
  215. package/tests/conformance/fixtures/responseProcessing_mathOperator_integerUtils/manifest.json +18 -0
  216. package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/cases.json +22 -0
  217. package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/item.xml +45 -0
  218. package/tests/conformance/fixtures/responseProcessing_math_max_min_round_truncate/manifest.json +21 -0
  219. package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/cases.json +26 -0
  220. package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/item.xml +157 -0
  221. package/tests/conformance/fixtures/responseProcessing_misc_math_string_stats/manifest.json +22 -0
  222. package/tests/conformance/fixtures/responseProcessing_notEqual_basic/cases.json +22 -0
  223. package/tests/conformance/fixtures/responseProcessing_notEqual_basic/item.xml +39 -0
  224. package/tests/conformance/fixtures/responseProcessing_notEqual_basic/manifest.json +18 -0
  225. package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/cases.json +22 -0
  226. package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/item.xml +51 -0
  227. package/tests/conformance/fixtures/responseProcessing_patternMatch_caseSensitive/manifest.json +19 -0
  228. package/tests/conformance/fixtures/responseProcessing_preCondition/cases.json +31 -0
  229. package/tests/conformance/fixtures/responseProcessing_preCondition/item.xml +44 -0
  230. package/tests/conformance/fixtures/responseProcessing_preCondition/manifest.json +12 -0
  231. package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/cases.json +27 -0
  232. package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/item.xml +42 -0
  233. package/tests/conformance/fixtures/responseProcessing_random_lookupOutcomeValue/manifest.json +14 -0
  234. package/tests/conformance/fixtures/responseProcessing_record_fieldValue/cases.json +12 -0
  235. package/tests/conformance/fixtures/responseProcessing_record_fieldValue/item.xml +40 -0
  236. package/tests/conformance/fixtures/responseProcessing_record_fieldValue/manifest.json +17 -0
  237. package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/cases.json +17 -0
  238. package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/item.xml +63 -0
  239. package/tests/conformance/fixtures/responseProcessing_responseCondition_toBoolean/manifest.json +9 -0
  240. package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/cases.json +12 -0
  241. package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/item.xml +40 -0
  242. package/tests/conformance/fixtures/responseProcessing_responseProcessingFragment/manifest.json +13 -0
  243. package/tests/conformance/fixtures/responseProcessing_setDefaultValue/cases.json +15 -0
  244. package/tests/conformance/fixtures/responseProcessing_setDefaultValue/item.xml +67 -0
  245. package/tests/conformance/fixtures/responseProcessing_setDefaultValue/manifest.json +9 -0
  246. package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/cases.json +27 -0
  247. package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/item.xml +69 -0
  248. package/tests/conformance/fixtures/responseProcessing_setResponseValue_setDefaultValue/manifest.json +10 -0
  249. package/tests/conformance/fixtures/responseProcessing_subtract_divide/cases.json +15 -0
  250. package/tests/conformance/fixtures/responseProcessing_subtract_divide/item.xml +35 -0
  251. package/tests/conformance/fixtures/responseProcessing_subtract_divide/manifest.json +11 -0
  252. package/tests/conformance/fixtures/responseProcessing_template_map_response/cases.json +17 -0
  253. package/tests/conformance/fixtures/responseProcessing_template_map_response/item.xml +31 -0
  254. package/tests/conformance/fixtures/responseProcessing_template_map_response/manifest.json +8 -0
  255. package/tests/conformance/fixtures/responseProcessing_template_map_response_point/cases.json +22 -0
  256. package/tests/conformance/fixtures/responseProcessing_template_map_response_point/item.xml +27 -0
  257. package/tests/conformance/fixtures/responseProcessing_template_map_response_point/manifest.json +8 -0
  258. package/tests/conformance/fixtures/responseProcessing_template_match_correct/cases.json +17 -0
  259. package/tests/conformance/fixtures/responseProcessing_template_match_correct/item.xml +34 -0
  260. package/tests/conformance/fixtures/responseProcessing_template_match_correct/manifest.json +8 -0
  261. package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/cases.json +22 -0
  262. package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/item.xml +30 -0
  263. package/tests/conformance/fixtures/responseProcessing_template_match_correct_directedPair/manifest.json +7 -0
  264. package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/cases.json +17 -0
  265. package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/item.xml +30 -0
  266. package/tests/conformance/fixtures/responseProcessing_template_match_correct_two_responses/manifest.json +9 -0
  267. package/tests/conformance/fixtures/responseProcessing_template_match_nothing/cases.json +17 -0
  268. package/tests/conformance/fixtures/responseProcessing_template_match_nothing/item.xml +30 -0
  269. package/tests/conformance/fixtures/responseProcessing_template_match_nothing/manifest.json +8 -0
  270. package/tests/conformance/fixtures/responseProcessing_xiInclude/cases.json +14 -0
  271. package/tests/conformance/fixtures/responseProcessing_xiInclude/item.xml +25 -0
  272. package/tests/conformance/fixtures/responseProcessing_xiInclude/manifest.json +9 -0
  273. package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/cases.json +12 -0
  274. package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/item.xml +52 -0
  275. package/tests/conformance/fixtures/stringMatch_caseSensitive_substring/manifest.json +14 -0
  276. package/tests/conformance/fixtures/templateProcessing_exitTemplate/cases.json +12 -0
  277. package/tests/conformance/fixtures/templateProcessing_exitTemplate/item.xml +48 -0
  278. package/tests/conformance/fixtures/templateProcessing_exitTemplate/manifest.json +13 -0
  279. package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/cases.json +27 -0
  280. package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/item.xml +74 -0
  281. package/tests/conformance/fixtures/templateProcessing_setCorrectResponse/manifest.json +22 -0
  282. package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/cases.json +17 -0
  283. package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/item.xml +133 -0
  284. package/tests/conformance/fixtures/templateProcessing_templateCondition_branching/manifest.json +22 -0
  285. package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/cases.json +12 -0
  286. package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/item.xml +107 -0
  287. package/tests/conformance/fixtures/templateProcessing_templateCondition_toBoolean/manifest.json +16 -0
  288. package/tests/conformance/fixtures/templateProcessing_templateConstraint/cases.json +15 -0
  289. package/tests/conformance/fixtures/templateProcessing_templateConstraint/item.xml +52 -0
  290. package/tests/conformance/fixtures/templateProcessing_templateConstraint/manifest.json +14 -0
  291. package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/cases.json +16 -0
  292. package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/item.xml +49 -0
  293. package/tests/conformance/fixtures/template_randomFloat_roundTo_mathConstant/manifest.json +15 -0
  294. package/tests/conformance/fixtures/template_randomInteger_printedVariable/cases.json +16 -0
  295. package/tests/conformance/fixtures/template_randomInteger_printedVariable/item.xml +38 -0
  296. package/tests/conformance/fixtures/template_randomInteger_printedVariable/manifest.json +13 -0
  297. package/tests/conformance/harness.ts +84 -0
  298. package/tests/conformance/run-fixtures.test.ts +127 -0
  299. package/tests/conformance/scripts/normalize-covers.ts +152 -0
  300. package/tests/conformance/types.ts +53 -0
  301. package/tests/core/Player.test.ts +563 -0
  302. package/tests/core/adaptiveItems.test.ts +442 -0
  303. package/tests/core/correctResponse.test.ts +280 -0
  304. package/tests/core/interaction-plumbing.test.ts +141 -0
  305. package/tests/core/modalFeedback.test.ts +308 -0
  306. package/tests/core/outcome-reset.test.ts +43 -0
  307. package/tests/extraction/extractors/associateExtractor.test.ts +182 -0
  308. package/tests/extraction/extractors/choiceExtractor.test.ts +239 -0
  309. package/tests/extraction/extractors/customExtractor.test.ts +83 -0
  310. package/tests/extraction/extractors/drawingExtractor.test.ts +94 -0
  311. package/tests/extraction/extractors/endAttemptExtractor.test.ts +188 -0
  312. package/tests/extraction/extractors/extendedTextExtractor.test.ts +178 -0
  313. package/tests/extraction/extractors/gapMatchExtractor.test.ts +318 -0
  314. package/tests/extraction/extractors/graphicAssociateExtractor.test.ts +260 -0
  315. package/tests/extraction/extractors/graphicGapMatchExtractor.test.ts +320 -0
  316. package/tests/extraction/extractors/graphicOrderExtractor.test.ts +223 -0
  317. package/tests/extraction/extractors/hotspotExtractor.test.ts +298 -0
  318. package/tests/extraction/extractors/hottextExtractor.test.ts +240 -0
  319. package/tests/extraction/extractors/inlineChoiceExtractor.test.ts +292 -0
  320. package/tests/extraction/extractors/matchExtractor.test.ts +241 -0
  321. package/tests/extraction/extractors/mediaExtractor.test.ts +295 -0
  322. package/tests/extraction/extractors/orderExtractor.test.ts +212 -0
  323. package/tests/extraction/extractors/positionObjectExtractor.test.ts +363 -0
  324. package/tests/extraction/extractors/selectPointExtractor.test.ts +214 -0
  325. package/tests/extraction/extractors/sliderExtractor.test.ts +293 -0
  326. package/tests/extraction/extractors/textEntryExtractor.test.ts +133 -0
  327. package/tests/extraction/extractors/uploadExtractor.test.ts +119 -0
  328. package/tests/extraction/test-utils.ts +57 -0
  329. package/tests/iframe/host.test.ts +145 -0
  330. package/tests/iframe/protocol.test.ts +42 -0
  331. package/tests/performance/player-benchmarks.bench.ts +191 -0
  332. package/tests/security/dos-limits.test.ts +56 -0
  333. package/tests/security/xss-prevention.test.ts +522 -0
  334. package/tsconfig.json +20 -0
  335. package/tsconfig.svelte.json +14 -0
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Standard QTI drawingInteraction extractor
3
+ *
4
+ * Extracts data from drawingInteraction elements (drawing on canvas)
5
+ */
6
+
7
+ import type { ElementExtractor } from '../types.js';
8
+
9
+ /**
10
+ * Image data for drawing interaction
11
+ */
12
+ export interface ImageData {
13
+ type: 'image' | 'svg';
14
+ src?: string;
15
+ content?: string;
16
+ width?: string;
17
+ height?: string;
18
+ }
19
+
20
+ /**
21
+ * Drawing data extracted from drawingInteraction elements
22
+ */
23
+ export interface DrawingData {
24
+ imageData: ImageData | null;
25
+ rawAttributes: Record<string, string>;
26
+ prompt: string | null;
27
+ }
28
+
29
+ /**
30
+ * Standard QTI drawing interaction extractor
31
+ * Handles drawingInteraction elements (drawing on a canvas)
32
+ */
33
+ export const standardDrawingExtractor: ElementExtractor<DrawingData> = {
34
+ id: 'qti:drawing-interaction',
35
+ name: 'QTI Standard Drawing Interaction',
36
+ priority: 10,
37
+ elementTypes: ['drawingInteraction'],
38
+ description: 'Extracts standard QTI drawingInteraction (drawing on canvas)',
39
+
40
+ canHandle(element, _context) {
41
+ // All drawingInteraction elements are standard
42
+ return element.rawTagName === 'drawingInteraction';
43
+ },
44
+
45
+ extract(element, context) {
46
+ const { utils } = context;
47
+
48
+ // Extract background image data from object element (optional)
49
+ const objectElements = utils.getChildrenByTag(element, 'object');
50
+ let imageData: ImageData | null = null;
51
+
52
+ if (objectElements.length > 0) {
53
+ const objectElement = objectElements[0];
54
+ const type = utils.getAttribute(objectElement, 'type', '');
55
+ const data = utils.getAttribute(objectElement, 'data', '');
56
+ const width = utils.getAttribute(objectElement, 'width', '');
57
+ const height = utils.getAttribute(objectElement, 'height', '');
58
+
59
+ if (type.startsWith('image/svg')) {
60
+ // Extract inline SVG content
61
+ const content = utils.getHtmlContent(objectElement);
62
+ imageData = {
63
+ type: 'svg',
64
+ content,
65
+ ...(width ? { width } : {}),
66
+ ...(height ? { height } : {}),
67
+ };
68
+ } else if (data) {
69
+ // External image reference
70
+ imageData = {
71
+ type: 'image',
72
+ src: data,
73
+ ...(width ? { width } : {}),
74
+ ...(height ? { height } : {}),
75
+ };
76
+ }
77
+ }
78
+
79
+ // Extract all attributes
80
+ const rawAttributes: Record<string, string> = {};
81
+ if (element.attributes) {
82
+ for (const [key, value] of Object.entries(element.attributes)) {
83
+ rawAttributes[key] = String(value);
84
+ }
85
+ }
86
+
87
+ // Extract prompt (optional)
88
+ const promptElements = utils.getChildrenByTag(element, 'prompt');
89
+ const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
90
+
91
+ return {
92
+ imageData,
93
+ rawAttributes,
94
+ prompt,
95
+ };
96
+ },
97
+
98
+ validate(data) {
99
+ const warnings: string[] = [];
100
+
101
+ // Warn if no background image
102
+ if (!data.imageData) {
103
+ warnings.push(
104
+ 'drawingInteraction has no background image - students will draw on a blank canvas'
105
+ );
106
+ }
107
+
108
+ return {
109
+ valid: true,
110
+ warnings: warnings.length > 0 ? warnings : undefined,
111
+ };
112
+ },
113
+ };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Standard QTI endAttemptInteraction extractor
3
+ *
4
+ * Extracts data from endAttemptInteraction elements (end attempt button)
5
+ */
6
+
7
+ import type { ElementExtractor } from '../types.js';
8
+
9
+ /**
10
+ * End attempt data extracted from endAttemptInteraction elements
11
+ */
12
+ export interface EndAttemptData {
13
+ title?: string;
14
+ countAttempt?: boolean;
15
+ prompt: string | null;
16
+ }
17
+
18
+ /**
19
+ * Standard QTI end attempt interaction extractor
20
+ * Handles endAttemptInteraction elements (button to end the attempt)
21
+ */
22
+ export const standardEndAttemptExtractor: ElementExtractor<EndAttemptData> = {
23
+ id: 'qti:end-attempt-interaction',
24
+ name: 'QTI Standard End Attempt Interaction',
25
+ priority: 10,
26
+ elementTypes: ['endAttemptInteraction'],
27
+ description: 'Extracts standard QTI endAttemptInteraction (end attempt button)',
28
+
29
+ canHandle(element, _context) {
30
+ // All endAttemptInteraction elements are standard
31
+ return element.rawTagName === 'endAttemptInteraction';
32
+ },
33
+
34
+ extract(element, context) {
35
+ const { utils } = context;
36
+
37
+ // Extract attributes with defaults
38
+ const title = utils.getAttribute(element, 'title', 'End Attempt');
39
+ const countAttempt = element.hasAttribute('countAttempt')
40
+ ? utils.getBooleanAttribute(element, 'countAttempt')
41
+ : true;
42
+
43
+ // Extract prompt (optional)
44
+ const promptElements = utils.getChildrenByTag(element, 'prompt');
45
+ const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
46
+
47
+ return {
48
+ title,
49
+ countAttempt,
50
+ prompt,
51
+ };
52
+ },
53
+
54
+ validate(data) {
55
+ const errors: string[] = [];
56
+ const warnings: string[] = [];
57
+
58
+ // Validate title is not empty
59
+ if (!data.title || data.title.trim() === '') {
60
+ errors.push('endAttemptInteraction must have a title');
61
+ }
62
+
63
+ // Warn if countAttempt is false (uncommon usage)
64
+ if (data.countAttempt === false) {
65
+ warnings.push('endAttemptInteraction has countAttempt=false - make sure this is intentional');
66
+ }
67
+
68
+ return {
69
+ valid: errors.length === 0,
70
+ errors: errors.length > 0 ? errors : undefined,
71
+ warnings: warnings.length > 0 ? warnings : undefined,
72
+ };
73
+ },
74
+ };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Standard QTI extendedTextInteraction extractor
3
+ *
4
+ * Extracts data from extendedTextInteraction elements (multi-line text input)
5
+ */
6
+
7
+ import type { ElementExtractor } from '../types.js';
8
+
9
+ /**
10
+ * Extended text data extracted from extendedTextInteraction elements
11
+ */
12
+ export interface ExtendedTextData {
13
+ expectedLines: number;
14
+ expectedLength: number;
15
+ placeholderText: string;
16
+ format: string;
17
+ }
18
+
19
+ /**
20
+ * Standard QTI extended text interaction extractor
21
+ * Handles extendedTextInteraction elements (multi-line text input)
22
+ */
23
+ export const standardExtendedTextExtractor: ElementExtractor<ExtendedTextData> = {
24
+ id: 'qti:extended-text-interaction',
25
+ name: 'QTI Standard Extended Text Interaction',
26
+ priority: 10,
27
+ elementTypes: ['extendedTextInteraction'],
28
+ description: 'Extracts standard QTI extendedTextInteraction (multi-line text input)',
29
+
30
+ canHandle(element, _context) {
31
+ // All extendedTextInteraction elements are standard
32
+ return element.rawTagName === 'extendedTextInteraction';
33
+ },
34
+
35
+ extract(element, context) {
36
+ const { utils } = context;
37
+
38
+ // Extract attributes
39
+ const expectedLines = utils.getNumberAttribute(element, 'expectedLines', 3);
40
+ const expectedLength = utils.getNumberAttribute(element, 'expectedLength', 200);
41
+ const placeholderText = utils.getAttribute(element, 'placeholderText', '');
42
+ const format = utils.getAttribute(element, 'format', 'plain');
43
+
44
+ return {
45
+ expectedLines,
46
+ expectedLength,
47
+ placeholderText,
48
+ format,
49
+ };
50
+ },
51
+
52
+ validate(data) {
53
+ const errors: string[] = [];
54
+ const warnings: string[] = [];
55
+
56
+ // Validate expectedLines
57
+ if (data.expectedLines < 1) {
58
+ errors.push('expectedLines must be at least 1');
59
+ }
60
+
61
+ // Validate expectedLength
62
+ if (data.expectedLength < 1) {
63
+ errors.push('expectedLength must be positive');
64
+ }
65
+
66
+ // Validate format
67
+ const validFormats = ['plain', 'preFormatted', 'xhtml'];
68
+ if (!validFormats.includes(data.format)) {
69
+ warnings.push(
70
+ `Unrecognized format "${data.format}" - expected plain, preFormatted, or xhtml`
71
+ );
72
+ }
73
+
74
+ return {
75
+ valid: errors.length === 0,
76
+ errors: errors.length > 0 ? errors : undefined,
77
+ warnings: warnings.length > 0 ? warnings : undefined,
78
+ };
79
+ },
80
+ };
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Standard QTI gapMatchInteraction extractor
3
+ *
4
+ * Extracts data from gapMatchInteraction elements (drag words into gaps)
5
+ */
6
+
7
+ import type { ElementExtractor } from '../types.js';
8
+
9
+ /**
10
+ * Gap match data extracted from gapMatchInteraction elements
11
+ */
12
+ export interface GapMatchData {
13
+ gapTexts: Array<{
14
+ identifier: string;
15
+ text: string;
16
+ matchMax: number;
17
+ matchMin?: number;
18
+ classes?: string[];
19
+ }>;
20
+ gaps: string[];
21
+ shuffle: boolean;
22
+ prompt: string | null;
23
+ promptText: string;
24
+ }
25
+
26
+ /**
27
+ * Standard QTI gap match interaction extractor
28
+ * Handles gapMatchInteraction elements (drag words into gaps in text)
29
+ */
30
+ export const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {
31
+ id: 'qti:gap-match-interaction',
32
+ name: 'QTI Standard Gap Match Interaction',
33
+ priority: 10,
34
+ elementTypes: ['gapMatchInteraction'],
35
+ description: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',
36
+
37
+ canHandle(element, _context) {
38
+ // All gapMatchInteraction elements are standard
39
+ return element.rawTagName === 'gapMatchInteraction';
40
+ },
41
+
42
+ extract(element, context) {
43
+ const { utils } = context;
44
+
45
+ // Extract gapText children (draggable items)
46
+ const gapTextElements = utils.getChildrenByTag(element, 'gapText');
47
+ const gapTexts = gapTextElements.map((gapText) => {
48
+ const classes = utils.getClasses(gapText);
49
+ const matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);
50
+ const matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);
51
+
52
+ return {
53
+ identifier: utils.getAttribute(gapText, 'identifier', ''),
54
+ text: utils.getTextContent(gapText),
55
+ matchMax,
56
+ ...(matchMin > 0 ? { matchMin } : {}),
57
+ ...(classes.length > 0 ? { classes } : {}),
58
+ };
59
+ });
60
+
61
+ // Extract prompt (optional) and process gap placeholders.
62
+ // NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)
63
+ // rather than inside a `<prompt>` element. Support both patterns.
64
+ const promptElements = utils.getChildrenByTag(element, 'prompt');
65
+ let prompt: string | null = null;
66
+ let promptText = '';
67
+ const gaps: string[] = [];
68
+
69
+ if (promptElements.length > 0) {
70
+ const promptElement = promptElements[0];
71
+ prompt = utils.getHtmlContent(promptElement);
72
+
73
+ // Get the raw HTML content and extract gaps
74
+ const promptHtml = promptElement.outerHTML || promptElement.toString();
75
+
76
+ // Extract gap elements from prompt
77
+ const gapElements = utils.getChildrenByTag(promptElement, 'gap');
78
+ for (const gap of gapElements) {
79
+ gaps.push(utils.getAttribute(gap, 'identifier', ''));
80
+ }
81
+
82
+ // Replace gap elements with placeholders in the text
83
+ promptText = promptHtml
84
+ .replace(/<prompt[^>]*>/, '')
85
+ .replace(/<\/prompt>/, '')
86
+ .replace(/<gap\s+identifier="([^"]+)"[^>]*>/g, '[GAP:$1]')
87
+ .replace(/<gap\s+identifier='([^']+)'[^>]*>/g, '[GAP:$1]')
88
+ .replace(/<\/gap>/g, '')
89
+ .trim();
90
+ } else {
91
+ // No <prompt> element: derive promptText from the interaction content excluding <gapText> blocks.
92
+ const interactionHtml = element.outerHTML || element.toString();
93
+
94
+ // Extract gap identifiers from anywhere in the interaction body.
95
+ const gapIdMatches = Array.from(
96
+ interactionHtml.matchAll(/<gap\s+identifier=(?:"([^"]+)"|'([^']+)')[^>]*\/?>/g)
97
+ );
98
+ for (const m of gapIdMatches) {
99
+ const id = (m[1] || m[2] || '').trim();
100
+ if (id) gaps.push(id);
101
+ }
102
+
103
+ promptText = interactionHtml
104
+ .replace(/<gapMatchInteraction[^>]*>/, '')
105
+ .replace(/<\/gapMatchInteraction>/, '')
106
+ // Remove draggable palette entries (gapText)
107
+ .replace(/<gapText[\s\S]*?<\/gapText>/g, '')
108
+ // Replace gap tags with placeholders
109
+ .replace(/<gap\s+identifier="([^"]+)"[^>]*\/?>/g, '[GAP:$1]')
110
+ .replace(/<gap\s+identifier='([^']+)'[^>]*\/?>/g, '[GAP:$1]')
111
+ .replace(/<\/gap>/g, '')
112
+ .trim();
113
+ }
114
+
115
+ // Extract attributes
116
+ const shuffle = utils.getBooleanAttribute(element, 'shuffle');
117
+
118
+ return {
119
+ gapTexts,
120
+ gaps,
121
+ shuffle,
122
+ prompt,
123
+ promptText,
124
+ };
125
+ },
126
+
127
+ validate(data) {
128
+ const errors: string[] = [];
129
+
130
+ // Validate gapTexts exist
131
+ if (!data.gapTexts || data.gapTexts.length === 0) {
132
+ errors.push('gapMatchInteraction must have at least one gapText');
133
+ }
134
+
135
+ // Validate gaps exist
136
+ if (!data.gaps || data.gaps.length === 0) {
137
+ errors.push('gapMatchInteraction must have at least one gap in the prompt');
138
+ }
139
+
140
+ // Validate gapText identifiers
141
+ if (data.gapTexts) {
142
+ const identifiers = new Set<string>();
143
+ for (const gapText of data.gapTexts) {
144
+ if (!gapText.identifier) {
145
+ errors.push('All gapTexts must have an identifier');
146
+ } else if (identifiers.has(gapText.identifier)) {
147
+ errors.push(`Duplicate gapText identifier: ${gapText.identifier}`);
148
+ } else {
149
+ identifiers.add(gapText.identifier);
150
+ }
151
+
152
+ // Validate matchMax
153
+ if (gapText.matchMax < 0) {
154
+ errors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);
155
+ }
156
+ }
157
+ }
158
+
159
+ // Validate gap identifiers
160
+ if (data.gaps) {
161
+ const identifiers = new Set<string>();
162
+ for (const gap of data.gaps) {
163
+ if (!gap) {
164
+ errors.push('All gaps must have an identifier');
165
+ } else if (identifiers.has(gap)) {
166
+ errors.push(`Duplicate gap identifier: ${gap}`);
167
+ } else {
168
+ identifiers.add(gap);
169
+ }
170
+ }
171
+ }
172
+
173
+ return {
174
+ valid: errors.length === 0,
175
+ errors: errors.length > 0 ? errors : undefined,
176
+ };
177
+ },
178
+ };
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Standard QTI graphicAssociateInteraction extractor
3
+ *
4
+ * Extracts data from graphicAssociateInteraction elements (associate items on image)
5
+ */
6
+
7
+ import type { ElementExtractor } from '../types.js';
8
+
9
+ /**
10
+ * Image data for graphic associate interaction
11
+ */
12
+ export interface ImageData {
13
+ type: 'image' | 'svg';
14
+ src?: string;
15
+ content?: string;
16
+ width?: string;
17
+ height?: string;
18
+ }
19
+
20
+ /**
21
+ * Graphic associate data extracted from graphicAssociateInteraction elements
22
+ */
23
+ export interface GraphicAssociateData {
24
+ imageData: ImageData | null;
25
+ associableHotspots: Array<{
26
+ identifier: string;
27
+ label: string;
28
+ shape: string;
29
+ coords: string;
30
+ matchMax: number;
31
+ matchMin?: number;
32
+ classes?: string[];
33
+ }>;
34
+ maxAssociations: number;
35
+ minAssociations: number;
36
+ prompt: string | null;
37
+ }
38
+
39
+ /**
40
+ * Standard QTI graphic associate interaction extractor
41
+ * Handles graphicAssociateInteraction elements (creating associations between hotspots)
42
+ */
43
+ export const standardGraphicAssociateExtractor: ElementExtractor<GraphicAssociateData> = {
44
+ id: 'qti:graphic-associate-interaction',
45
+ name: 'QTI Standard Graphic Associate Interaction',
46
+ priority: 10,
47
+ elementTypes: ['graphicAssociateInteraction'],
48
+ description: 'Extracts standard QTI graphicAssociateInteraction (associate items on image)',
49
+
50
+ canHandle(element, _context) {
51
+ // All graphicAssociateInteraction elements are standard
52
+ return element.rawTagName === 'graphicAssociateInteraction';
53
+ },
54
+
55
+ extract(element, context) {
56
+ const { utils } = context;
57
+
58
+ // Extract image data from object element
59
+ const objectElements = utils.getChildrenByTag(element, 'object');
60
+ let imageData: ImageData | null = null;
61
+
62
+ if (objectElements.length > 0) {
63
+ const objectElement = objectElements[0];
64
+ const type = utils.getAttribute(objectElement, 'type', '');
65
+ const data = utils.getAttribute(objectElement, 'data', '');
66
+ const width = utils.getAttribute(objectElement, 'width', '500');
67
+ const height = utils.getAttribute(objectElement, 'height', '300');
68
+
69
+ if (type.startsWith('image/svg')) {
70
+ // Extract inline SVG content - get full content including <svg> tag
71
+ const content = utils.getHtmlContent(objectElement);
72
+ imageData = {
73
+ type: 'svg',
74
+ content,
75
+ width,
76
+ height,
77
+ };
78
+ } else {
79
+ // External image reference
80
+ imageData = {
81
+ type: 'image',
82
+ src: data,
83
+ width,
84
+ height,
85
+ };
86
+ }
87
+ }
88
+
89
+ // Extract associableHotspot children
90
+ const hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');
91
+ const associableHotspots = hotspotElements.map((hotspot) => {
92
+ const classes = utils.getClasses(hotspot);
93
+ const identifier = utils.getAttribute(hotspot, 'identifier', '');
94
+ const shape = utils.getAttribute(hotspot, 'shape', 'rect');
95
+ const coords = utils.getAttribute(hotspot, 'coords', '0,0,50,50');
96
+ const matchMax = utils.getNumberAttribute(hotspot, 'matchMax', 1);
97
+ const matchMin = utils.getNumberAttribute(hotspot, 'matchMin', 0);
98
+
99
+ // Get text content as label, use identifier as fallback
100
+ const textContent = utils.getTextContent(hotspot).trim();
101
+ const label = textContent || identifier;
102
+
103
+ return {
104
+ identifier,
105
+ label,
106
+ shape,
107
+ coords,
108
+ matchMax,
109
+ ...(matchMin > 0 ? { matchMin } : {}),
110
+ ...(classes.length > 0 ? { classes } : {}),
111
+ };
112
+ });
113
+
114
+ // Extract attributes with proper defaults
115
+ const maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 1);
116
+ const minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);
117
+
118
+ // Extract prompt (optional)
119
+ const promptElements = utils.getChildrenByTag(element, 'prompt');
120
+ const prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;
121
+
122
+ return {
123
+ imageData,
124
+ associableHotspots,
125
+ maxAssociations,
126
+ minAssociations,
127
+ prompt,
128
+ };
129
+ },
130
+
131
+ validate(data) {
132
+ const errors: string[] = [];
133
+ const warnings: string[] = [];
134
+
135
+ // Validate image data
136
+ if (!data.imageData) {
137
+ warnings.push('graphicAssociateInteraction has no image data');
138
+ } else if (data.imageData.type === 'image' && !data.imageData.src) {
139
+ errors.push('graphicAssociateInteraction must have an image URL');
140
+ } else if (data.imageData.type === 'svg' && !data.imageData.content) {
141
+ errors.push('graphicAssociateInteraction must have SVG content');
142
+ }
143
+
144
+ // Validate hotspots exist
145
+ if (!data.associableHotspots || data.associableHotspots.length < 2) {
146
+ errors.push('graphicAssociateInteraction must have at least 2 hotspots');
147
+ }
148
+
149
+ // Validate hotspot identifiers and coords
150
+ if (data.associableHotspots && data.associableHotspots.length > 0) {
151
+ const identifiers = new Set<string>();
152
+ for (const hotspot of data.associableHotspots) {
153
+ if (!hotspot.identifier) {
154
+ errors.push('All hotspots must have an identifier');
155
+ } else if (identifiers.has(hotspot.identifier)) {
156
+ errors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);
157
+ } else {
158
+ identifiers.add(hotspot.identifier);
159
+ }
160
+
161
+ if (!hotspot.coords) {
162
+ errors.push(`Hotspot ${hotspot.identifier} must have coords`);
163
+ }
164
+
165
+ // Validate matchMax
166
+ if (hotspot.matchMax < 0) {
167
+ errors.push(`matchMax must be non-negative for hotspot ${hotspot.identifier}`);
168
+ }
169
+ }
170
+ }
171
+
172
+ // Validate maxAssociations
173
+ if (data.maxAssociations < 0) {
174
+ errors.push('maxAssociations must be non-negative');
175
+ }
176
+
177
+ // Validate minAssociations
178
+ if (data.minAssociations < 0) {
179
+ errors.push('minAssociations must be non-negative');
180
+ }
181
+
182
+ return {
183
+ valid: errors.length === 0,
184
+ errors: errors.length > 0 ? errors : undefined,
185
+ warnings: warnings.length > 0 ? warnings : undefined,
186
+ };
187
+ },
188
+ };