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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/README.md +34 -6
  2. package/dist/catalog/applyGlossaryTriggers.js +14 -2
  3. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  4. package/dist/catalog/catalogExtractor.js +2 -4
  5. package/dist/catalog/catalogExtractor.js.map +1 -1
  6. package/dist/catalog/sessionCatalog.d.ts +46 -0
  7. package/dist/catalog/sessionCatalog.js +87 -0
  8. package/dist/catalog/sessionCatalog.js.map +1 -0
  9. package/dist/components/utils/endAttempt.d.ts +16 -0
  10. package/dist/components/utils/endAttempt.js +28 -0
  11. package/dist/components/utils/endAttempt.js.map +1 -0
  12. package/dist/components/utils/focus.d.ts +19 -0
  13. package/dist/components/utils/focus.js +67 -0
  14. package/dist/components/utils/focus.js.map +1 -0
  15. package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
  16. package/dist/components/utils/itemBodyRenderer.js +177 -0
  17. package/dist/components/utils/itemBodyRenderer.js.map +1 -0
  18. package/dist/components/utils/sentenceContext.d.ts +6 -0
  19. package/dist/components/utils/sentenceContext.js +16 -0
  20. package/dist/components/utils/sentenceContext.js.map +1 -0
  21. package/dist/core/AssessmentItemDefinition.d.ts +20 -1
  22. package/dist/core/AssessmentItemDefinition.js +12 -31
  23. package/dist/core/AssessmentItemDefinition.js.map +1 -1
  24. package/dist/core/ComponentRegistry.d.ts +92 -0
  25. package/dist/core/ComponentRegistry.js +7 -1
  26. package/dist/core/ComponentRegistry.js.map +1 -1
  27. package/dist/core/ItemSession.d.ts +18 -1
  28. package/dist/core/ItemSession.js +79 -41
  29. package/dist/core/ItemSession.js.map +1 -1
  30. package/dist/core/Player.d.ts +118 -141
  31. package/dist/core/Player.js +390 -1233
  32. package/dist/core/Player.js.map +1 -1
  33. package/dist/core/compliance.d.ts +72 -0
  34. package/dist/core/compliance.js +147 -0
  35. package/dist/core/compliance.js.map +1 -0
  36. package/dist/core/declarations/declarationBuilder.d.ts +29 -0
  37. package/dist/core/declarations/declarationBuilder.js +284 -0
  38. package/dist/core/declarations/declarationBuilder.js.map +1 -0
  39. package/dist/core/declarations/declarationValues.d.ts +11 -0
  40. package/dist/core/declarations/declarationValues.js +168 -0
  41. package/dist/core/declarations/declarationValues.js.map +1 -0
  42. package/dist/core/matchGroups.d.ts +36 -0
  43. package/dist/core/matchGroups.js +100 -0
  44. package/dist/core/matchGroups.js.map +1 -0
  45. package/dist/core/nameMappers.d.ts +35 -0
  46. package/dist/core/nameMappers.js +47 -0
  47. package/dist/core/nameMappers.js.map +1 -0
  48. package/dist/core/parsingLimits.d.ts +4 -0
  49. package/dist/core/parsingLimits.js +5 -2
  50. package/dist/core/parsingLimits.js.map +1 -1
  51. package/dist/core/processing/responseProcessing.d.ts +88 -0
  52. package/dist/core/processing/responseProcessing.js +317 -0
  53. package/dist/core/processing/responseProcessing.js.map +1 -0
  54. package/dist/core/processing/responseValidation.d.ts +55 -0
  55. package/dist/core/processing/responseValidation.js +335 -0
  56. package/dist/core/processing/responseValidation.js.map +1 -0
  57. package/dist/core/rendering/contentPass.d.ts +31 -0
  58. package/dist/core/rendering/contentPass.js +152 -0
  59. package/dist/core/rendering/contentPass.js.map +1 -0
  60. package/dist/core/rendering/htmlRender.d.ts +21 -0
  61. package/dist/core/rendering/htmlRender.js +56 -0
  62. package/dist/core/rendering/htmlRender.js.map +1 -0
  63. package/dist/core/responseProcessingTemplates.d.ts +23 -0
  64. package/dist/core/responseProcessingTemplates.js +45 -0
  65. package/dist/core/responseProcessingTemplates.js.map +1 -0
  66. package/dist/core/rolePolicy.d.ts +5 -0
  67. package/dist/core/rolePolicy.js +21 -0
  68. package/dist/core/rolePolicy.js.map +1 -1
  69. package/dist/core/sanitizer.js +8 -14
  70. package/dist/core/sanitizer.js.map +1 -1
  71. package/dist/core/serialization/sessionState.d.ts +56 -0
  72. package/dist/core/serialization/sessionState.js +139 -0
  73. package/dist/core/serialization/sessionState.js.map +1 -0
  74. package/dist/core/serialization/valueForms.d.ts +32 -0
  75. package/dist/core/serialization/valueForms.js +112 -0
  76. package/dist/core/serialization/valueForms.js.map +1 -0
  77. package/dist/document/AssessmentItemDocument.d.ts +27 -1
  78. package/dist/document/AssessmentItemDocument.js +67 -31
  79. package/dist/document/AssessmentItemDocument.js.map +1 -1
  80. package/dist/element-class-BUFpUrJP.js +3792 -0
  81. package/dist/element-class-BUFpUrJP.js.map +1 -0
  82. package/dist/element-class.d.ts +34 -1
  83. package/dist/element-class.js +1 -1
  84. package/dist/element.js +2 -3
  85. package/dist/extraction/ExtractionRegistry.js +6 -12
  86. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  87. package/dist/extraction/createContext.d.ts +2 -2
  88. package/dist/extraction/createContext.js.map +1 -1
  89. package/dist/extraction/index.d.ts +2 -2
  90. package/dist/extraction/index.js +1 -1
  91. package/dist/extraction/index.js.map +1 -1
  92. package/dist/extraction/interactionCoverage.d.ts +31 -0
  93. package/dist/extraction/interactionCoverage.js +40 -0
  94. package/dist/extraction/interactionCoverage.js.map +1 -0
  95. package/dist/extraction/interactionExtractionPipeline.js +5 -10
  96. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  97. package/dist/extraction/interactionSecurity.js +1 -28
  98. package/dist/extraction/interactionSecurity.js.map +1 -1
  99. package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
  100. package/dist/extraction/mergeDeliveryFields.js +17 -0
  101. package/dist/extraction/mergeDeliveryFields.js.map +1 -0
  102. package/dist/extraction/responseIdentifier.d.ts +19 -0
  103. package/dist/extraction/responseIdentifier.js +29 -0
  104. package/dist/extraction/responseIdentifier.js.map +1 -0
  105. package/dist/extraction/types.d.ts +11 -18
  106. package/dist/extraction/types.js +0 -12
  107. package/dist/extraction/types.js.map +1 -1
  108. package/dist/extraction/utils.d.ts +14 -0
  109. package/dist/extraction/utils.js +35 -5
  110. package/dist/extraction/utils.js.map +1 -1
  111. package/dist/index.d.ts +16 -10
  112. package/dist/index.js +19 -8
  113. package/dist/index.js.map +1 -1
  114. package/dist/interactions/associate/extractor.d.ts +1 -0
  115. package/dist/interactions/associate/extractor.js +10 -12
  116. package/dist/interactions/associate/extractor.js.map +1 -1
  117. package/dist/interactions/choice/extractor.js +6 -13
  118. package/dist/interactions/choice/extractor.js.map +1 -1
  119. package/dist/interactions/drawing/extractor.d.ts +6 -0
  120. package/dist/interactions/drawing/extractor.js +30 -9
  121. package/dist/interactions/drawing/extractor.js.map +1 -1
  122. package/dist/interactions/end-attempt/extractor.js +2 -1
  123. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  124. package/dist/interactions/extended-text/extractor.d.ts +6 -1
  125. package/dist/interactions/extended-text/extractor.js +10 -5
  126. package/dist/interactions/extended-text/extractor.js.map +1 -1
  127. package/dist/interactions/extended-text/response.js +18 -18
  128. package/dist/interactions/extended-text/response.js.map +1 -1
  129. package/dist/interactions/gap-match/extractor.d.ts +40 -2
  130. package/dist/interactions/gap-match/extractor.js +197 -39
  131. package/dist/interactions/gap-match/extractor.js.map +1 -1
  132. package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
  133. package/dist/interactions/graphic-associate/extractor.js +35 -24
  134. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  135. package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
  136. package/dist/interactions/graphic-gap-match/extractor.js +79 -43
  137. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  138. package/dist/interactions/graphic-order/extractor.d.ts +15 -0
  139. package/dist/interactions/graphic-order/extractor.js +39 -24
  140. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  141. package/dist/interactions/hotspot/extractor.d.ts +6 -0
  142. package/dist/interactions/hotspot/extractor.js +31 -16
  143. package/dist/interactions/hotspot/extractor.js.map +1 -1
  144. package/dist/interactions/hottext/extractor.js +2 -12
  145. package/dist/interactions/hottext/extractor.js.map +1 -1
  146. package/dist/interactions/inline/accessibleName.d.ts +29 -0
  147. package/dist/interactions/inline/accessibleName.js +35 -0
  148. package/dist/interactions/inline/accessibleName.js.map +1 -0
  149. package/dist/interactions/inline/render-plan.d.ts +5 -14
  150. package/dist/interactions/inline/render-plan.js +5 -56
  151. package/dist/interactions/inline/render-plan.js.map +1 -1
  152. package/dist/interactions/inline-choice/extractor.d.ts +4 -0
  153. package/dist/interactions/inline-choice/extractor.js +13 -12
  154. package/dist/interactions/inline-choice/extractor.js.map +1 -1
  155. package/dist/interactions/match/extractor.d.ts +2 -0
  156. package/dist/interactions/match/extractor.js +14 -28
  157. package/dist/interactions/match/extractor.js.map +1 -1
  158. package/dist/interactions/media/extractor.d.ts +5 -11
  159. package/dist/interactions/media/extractor.js +100 -36
  160. package/dist/interactions/media/extractor.js.map +1 -1
  161. package/dist/interactions/modules.js +8 -2
  162. package/dist/interactions/modules.js.map +1 -1
  163. package/dist/interactions/order/extractor.d.ts +2 -0
  164. package/dist/interactions/order/extractor.js +8 -12
  165. package/dist/interactions/order/extractor.js.map +1 -1
  166. package/dist/interactions/order/limits.d.ts +29 -0
  167. package/dist/interactions/order/limits.js +28 -0
  168. package/dist/interactions/order/limits.js.map +1 -0
  169. package/dist/interactions/portable-custom/extractor.js +18 -14
  170. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  171. package/dist/interactions/position-object/extractor.d.ts +18 -1
  172. package/dist/interactions/position-object/extractor.js +81 -22
  173. package/dist/interactions/position-object/extractor.js.map +1 -1
  174. package/dist/interactions/select-point/extractor.d.ts +6 -0
  175. package/dist/interactions/select-point/extractor.js +31 -19
  176. package/dist/interactions/select-point/extractor.js.map +1 -1
  177. package/dist/interactions/shared/imageAlt.d.ts +54 -0
  178. package/dist/interactions/shared/imageAlt.js +84 -0
  179. package/dist/interactions/shared/imageAlt.js.map +1 -0
  180. package/dist/interactions/shared/interactionImage.d.ts +32 -0
  181. package/dist/interactions/shared/interactionImage.js +39 -0
  182. package/dist/interactions/shared/interactionImage.js.map +1 -0
  183. package/dist/interactions/shared/specDefaults.d.ts +20 -0
  184. package/dist/interactions/shared/specDefaults.js +25 -0
  185. package/dist/interactions/shared/specDefaults.js.map +1 -0
  186. package/dist/interactions/shared/types.d.ts +212 -40
  187. package/dist/interactions/shared/types.js.map +1 -1
  188. package/dist/interactions/text-entry/extractor.d.ts +9 -0
  189. package/dist/interactions/text-entry/extractor.js +9 -0
  190. package/dist/interactions/text-entry/extractor.js.map +1 -1
  191. package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
  192. package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
  193. package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
  194. package/dist/interactions/text-entry/inputMode.d.ts +35 -0
  195. package/dist/interactions/text-entry/inputMode.js +134 -0
  196. package/dist/interactions/text-entry/inputMode.js.map +1 -0
  197. package/dist/interactions/text-entry/response.d.ts +15 -0
  198. package/dist/interactions/text-entry/response.js +25 -0
  199. package/dist/interactions/text-entry/response.js.map +1 -0
  200. package/dist/interactions/upload/extractor.js +2 -2
  201. package/dist/interactions/upload/extractor.js.map +1 -1
  202. package/dist/pci/PciHost.d.ts +1 -1
  203. package/dist/pci/PciHost.js +11 -11
  204. package/dist/pci/PciHost.js.map +1 -1
  205. package/dist/pci/index.d.ts +1 -0
  206. package/dist/pci/index.js.map +1 -1
  207. package/dist/pci/modulePaths.d.ts +16 -0
  208. package/dist/pci/modulePaths.js +33 -0
  209. package/dist/pci/modulePaths.js.map +1 -0
  210. package/dist/pci/pageRealmSession.js +3 -15
  211. package/dist/pci/pageRealmSession.js.map +1 -1
  212. package/dist/pci/qtiVariableJson.d.ts +46 -3
  213. package/dist/pci/qtiVariableJson.js +247 -53
  214. package/dist/pci/qtiVariableJson.js.map +1 -1
  215. package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
  216. package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
  217. package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
  218. package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
  219. package/dist/pci/sandbox/iframeConnector.js +35 -6
  220. package/dist/pci/sandbox/iframeConnector.js.map +1 -1
  221. package/dist/pci/sandbox/protocol.d.ts +14 -0
  222. package/dist/pci/sandbox/protocol.js.map +1 -1
  223. package/dist/pci/sessionHosts.d.ts +47 -0
  224. package/dist/pci/sessionHosts.js +66 -0
  225. package/dist/pci/sessionHosts.js.map +1 -0
  226. package/dist/pci/types.d.ts +9 -3
  227. package/dist/pci/types.js.map +1 -1
  228. package/dist/pnp/applyPnp.d.ts +20 -3
  229. package/dist/pnp/applyPnp.js +84 -9
  230. package/dist/pnp/applyPnp.js.map +1 -1
  231. package/dist/pnp/parsePnpXml.js +2 -0
  232. package/dist/pnp/parsePnpXml.js.map +1 -1
  233. package/dist/pnp/types.d.ts +16 -8
  234. package/dist/pnp/types.js.map +1 -1
  235. package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
  236. package/dist/presentation/feedbackAnnouncement.js +150 -0
  237. package/dist/presentation/feedbackAnnouncement.js.map +1 -0
  238. package/dist/presentation/interactionSlots.d.ts +31 -0
  239. package/dist/presentation/interactionSlots.js +101 -0
  240. package/dist/presentation/interactionSlots.js.map +1 -0
  241. package/dist/presentation/itemPresentationPlan.d.ts +69 -6
  242. package/dist/presentation/itemPresentationPlan.js +93 -81
  243. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  244. package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
  245. package/dist/presentation/stimulusRender.js.map +1 -0
  246. package/dist/presentation/stylesheetRender.js.map +1 -0
  247. package/dist/security/escapeHtml.d.ts +15 -0
  248. package/dist/security/escapeHtml.js +22 -0
  249. package/dist/security/escapeHtml.js.map +1 -0
  250. package/dist/security/index.d.ts +1 -0
  251. package/dist/security/index.js +1 -0
  252. package/dist/security/index.js.map +1 -1
  253. package/dist/server.d.ts +8 -1
  254. package/dist/server.js.map +1 -1
  255. package/dist/session-inputs.d.ts +108 -0
  256. package/dist/session-inputs.js +130 -0
  257. package/dist/session-inputs.js.map +1 -0
  258. package/dist/types/index.d.ts +67 -35
  259. package/dist/types/index.js.map +1 -1
  260. package/dist/utils/cloneFreeze.d.ts +52 -0
  261. package/dist/utils/cloneFreeze.js +113 -0
  262. package/dist/utils/cloneFreeze.js.map +1 -0
  263. package/dist/utils/htmlAttributes.d.ts +13 -0
  264. package/dist/utils/htmlAttributes.js +22 -0
  265. package/dist/utils/htmlAttributes.js.map +1 -0
  266. package/dist/web-components/QTIInteractionElement.d.ts +0 -29
  267. package/dist/web-components/QTIInteractionElement.js +0 -32
  268. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  269. package/dist/web-components/index.d.ts +1 -2
  270. package/dist/web-components/index.js +2 -3
  271. package/dist/web-components/index.js.map +1 -1
  272. package/package.json +20 -19
  273. package/dist/components/utils/stimulusRender.js.map +0 -1
  274. package/dist/components/utils/stylesheetRender.js.map +0 -1
  275. package/dist/core/constants.d.ts +0 -65
  276. package/dist/core/constants.js +0 -74
  277. package/dist/core/constants.js.map +0 -1
  278. package/dist/element-class-DdpiTalY.js +0 -9226
  279. package/dist/element-class-DdpiTalY.js.map +0 -1
  280. package/dist/extensions/MathLiveEditor.d.ts +0 -31
  281. package/dist/extensions/MathLiveEditor.js +0 -248
  282. package/dist/extensions/MathLiveEditor.js.map +0 -1
  283. package/dist/utils/PerformanceMonitor.d.ts +0 -169
  284. package/dist/utils/PerformanceMonitor.js +0 -243
  285. package/dist/utils/PerformanceMonitor.js.map +0 -1
  286. package/dist/utils/responseUtils.d.ts +0 -15
  287. package/dist/utils/responseUtils.js +0 -46
  288. package/dist/utils/responseUtils.js.map +0 -1
  289. package/dist/web-components/QTIInteractionBase.d.ts +0 -119
  290. package/dist/web-components/QTIInteractionBase.js +0 -244
  291. package/dist/web-components/QTIInteractionBase.js.map +0 -1
  292. /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
  293. /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
  294. /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Extracts data from orderInteraction elements (ordering/ranking tasks)
5
5
  */
6
+ import { validateUniqueIdentifiers } from '../../extraction/utils.js';
6
7
  import { maybeShuffle } from '../../core/shuffle.js';
7
8
  /**
8
9
  * Standard QTI order interaction extractor
@@ -41,6 +42,10 @@ export const standardOrderExtractor = {
41
42
  const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
42
43
  const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);
43
44
  const interactionClasses = utils.getClasses(element);
45
+ // QTI 3.0 defines both messages on orderInteraction (XSD: data-min-selections-message,
46
+ // data-max-selections-message); the max one states the subset cap when an add is refused.
47
+ const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
48
+ const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
44
49
  return {
45
50
  choices: maybeShuffle(choices, shuffle, context.shuffleRng),
46
51
  shuffle,
@@ -49,6 +54,8 @@ export const standardOrderExtractor = {
49
54
  maxChoices,
50
55
  prompt,
51
56
  ...(interactionClasses.length > 0 ? { interactionClasses } : {}),
57
+ ...(minSelectionsMessage ? { minSelectionsMessage } : {}),
58
+ ...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),
52
59
  };
53
60
  },
54
61
  validate(data) {
@@ -64,18 +71,7 @@ export const standardOrderExtractor = {
64
71
  }
65
72
  // Validate choice identifiers
66
73
  if (data.choices) {
67
- const identifiers = new Set();
68
- for (const choice of data.choices) {
69
- if (!choice.identifier) {
70
- errors.push('All choices must have an identifier');
71
- }
72
- else if (identifiers.has(choice.identifier)) {
73
- errors.push(`Duplicate choice identifier: ${choice.identifier}`);
74
- }
75
- else {
76
- identifiers.add(choice.identifier);
77
- }
78
- }
74
+ validateUniqueIdentifiers(data.choices, errors, { plural: 'choices', noun: 'choice' });
79
75
  }
80
76
  // Validate orientation (only if provided)
81
77
  if (data.orientation) {
@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AAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI orderInteraction extractor\n *\n * Extracts data from orderInteraction elements (ordering/ranking tasks)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Order data extracted from orderInteraction elements\n */\nexport interface OrderData {\n\tchoices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;\n\tshuffle: boolean;\n\tminChoices: number;\n\tmaxChoices: number;\n\torientation?: string;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI order interaction extractor\n * Handles orderInteraction elements with simpleChoice children\n */\nexport const standardOrderExtractor: ElementExtractor<OrderData> = {\n\tid: 'qti:order-interaction',\n\tname: 'QTI Standard Order Interaction',\n\tpriority: 10,\n\telementTypes: ['orderInteraction'],\n\tdescription: 'Extracts standard QTI orderInteraction (ordering/ranking tasks)',\n\n\tcanHandle(element, context) {\n\t\t// Standard QTI order interactions have simpleChoice children\n\t\treturn context.utils.hasChildWithTag(element, 'simpleChoice');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract choices\n\t\tconst simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');\n\t\tconst choices = simpleChoices.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst fixed = utils.getBooleanAttribute(choice, 'fixed');\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt\n\t\tconst promptElement = utils.querySelector(element, 'prompt');\n\t\tconst prompt = promptElement ? utils.getHtmlContent(promptElement) : null;\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst orientation = utils.getAttribute(element, 'orientation', 'vertical');\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);\n\t\tconst interactionClasses = utils.getClasses(element);\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\torientation,\n\t\t\tminChoices,\n\t\t\tmaxChoices,\n\t\t\tprompt,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('orderInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Warn if too many choices (difficult to order)\n\t\tif (data.choices && data.choices.length > 10) {\n\t\t\twarnings.push(\n\t\t\t\t`orderInteraction has ${data.choices.length} choices - this may be difficult for users to order`\n\t\t\t);\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate orientation (only if provided)\n\t\tif (data.orientation) {\n\t\t\tconst validOrientations = ['vertical', 'horizontal'];\n\t\t\tif (!validOrientations.includes(data.orientation)) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`orientation '${data.orientation}' is not standard (expected: ${validOrientations.join(', ')})`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/order/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAgBrD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAgC;IAClE,EAAE,EAAE,uBAAuB;IAC3B,IAAI,EAAE,gCAAgC;IACtC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,kBAAkB,CAAC;IAClC,WAAW,EAAE,iEAAiE;IAE9E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,6DAA6D;QAC7D,OAAO,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,kBAAkB;QAClB,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAEzD,OAAO;gBACN,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,EA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YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBACnD,QAAQ,CAAC,IAAI,CACZ,gBAAgB,IAAI,CAAC,WAAW,gCAAgC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC/F,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI orderInteraction extractor\n *\n * Extracts data from orderInteraction elements (ordering/ranking tasks)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { validateUniqueIdentifiers } from '../../extraction/utils.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Order data extracted from orderInteraction elements\n */\nexport interface OrderData {\n\tchoices: Array<{ identifier: string; text: string; fixed?: boolean; classes?: string[] }>;\n\tshuffle: boolean;\n\tminChoices: number;\n\tmaxChoices: number;\n\torientation?: string;\n\tprompt: string | null;\n\t/** Message shown while the response orders fewer than minChoices (data-min-selections-message) */\n\tminSelectionsMessage?: string;\n}\n\n/**\n * Standard QTI order interaction extractor\n * Handles orderInteraction elements with simpleChoice children\n */\nexport const standardOrderExtractor: ElementExtractor<OrderData> = {\n\tid: 'qti:order-interaction',\n\tname: 'QTI Standard Order Interaction',\n\tpriority: 10,\n\telementTypes: ['orderInteraction'],\n\tdescription: 'Extracts standard QTI orderInteraction (ordering/ranking tasks)',\n\n\tcanHandle(element, context) {\n\t\t// Standard QTI order interactions have simpleChoice children\n\t\treturn context.utils.hasChildWithTag(element, 'simpleChoice');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract choices\n\t\tconst simpleChoices = utils.getChildrenByTag(element, 'simpleChoice');\n\t\tconst choices = simpleChoices.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst fixed = utils.getBooleanAttribute(choice, 'fixed');\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\t...(fixed ? { fixed } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt\n\t\tconst promptElement = utils.querySelector(element, 'prompt');\n\t\tconst prompt = promptElement ? utils.getHtmlContent(promptElement) : null;\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst orientation = utils.getAttribute(element, 'orientation', 'vertical');\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 0);\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\t// QTI 3.0 defines both messages on orderInteraction (XSD: data-min-selections-message,\n\t\t// data-max-selections-message); the max one states the subset cap when an add is refused.\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\torientation,\n\t\t\tminChoices,\n\t\t\tmaxChoices,\n\t\t\tprompt,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('orderInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Warn if too many choices (difficult to order)\n\t\tif (data.choices && data.choices.length > 10) {\n\t\t\twarnings.push(\n\t\t\t\t`orderInteraction has ${data.choices.length} choices - this may be difficult for users to order`\n\t\t\t);\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tvalidateUniqueIdentifiers(data.choices, errors, { plural: 'choices', noun: 'choice' });\n\t\t}\n\n\t\t// Validate orientation (only if provided)\n\t\tif (data.orientation) {\n\t\t\tconst validOrientations = ['vertical', 'horizontal'];\n\t\t\tif (!validOrientations.includes(data.orientation)) {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`orientation '${data.orientation}' is not standard (expected: ${validOrientations.join(', ')})`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The order-subset rule (QTI 2.2 ASI §5.73 orderInteraction, §5.42 graphicOrderInteraction,
3
+ * §2.4.1.2; QTI 3.0 `min-choices` / `max-choices` mean the same). Response validation and the
4
+ * delivered UI both read it, so the UI can never produce a response validation rejects nor
5
+ * refuse one it accepts.
6
+ *
7
+ * - `minChoices` unspecified: "all of the choices must be ordered and maxChoices is ignored".
8
+ * - `minChoices` from 1 up to fewer than the choices: "the candidate must select a subset of
9
+ * the choices and impose an ordering on them" — at least `minChoices`, at most the cap,
10
+ * which is `maxChoices` (0 = no limit) clamped to the number of choices.
11
+ * - `minChoices` at or above the number of choices: every choice, as in the default.
12
+ */
13
+ export interface OrderSubsetInteraction {
14
+ /** The authored minChoices; absent, 0 or not a number means unspecified. */
15
+ minChoices?: number | null;
16
+ /** The authored maxChoices; absent, 0 or not a number means no limit. */
17
+ maxChoices?: number | null;
18
+ /** How many choices the interaction offers (simpleChoice / hotspotChoice). */
19
+ choiceCount: number;
20
+ }
21
+ export interface OrderChoiceLimits {
22
+ /** True when the candidate selects which choices to order: a subset is requested. */
23
+ subset: boolean;
24
+ /** The fewest choices a complete response orders: every choice unless a subset is requested. */
25
+ minOrdered: number;
26
+ /** The most choices a response may order: every choice unless a subset is requested. */
27
+ maxOrdered: number;
28
+ }
29
+ export declare function orderChoiceLimits({ minChoices, maxChoices, choiceCount }: OrderSubsetInteraction): OrderChoiceLimits;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The order-subset rule (QTI 2.2 ASI §5.73 orderInteraction, §5.42 graphicOrderInteraction,
3
+ * §2.4.1.2; QTI 3.0 `min-choices` / `max-choices` mean the same). Response validation and the
4
+ * delivered UI both read it, so the UI can never produce a response validation rejects nor
5
+ * refuse one it accepts.
6
+ *
7
+ * - `minChoices` unspecified: "all of the choices must be ordered and maxChoices is ignored".
8
+ * - `minChoices` from 1 up to fewer than the choices: "the candidate must select a subset of
9
+ * the choices and impose an ordering on them" — at least `minChoices`, at most the cap,
10
+ * which is `maxChoices` (0 = no limit) clamped to the number of choices.
11
+ * - `minChoices` at or above the number of choices: every choice, as in the default.
12
+ */
13
+ function positiveCount(value) {
14
+ const n = Math.floor(Number(value ?? 0));
15
+ return Number.isFinite(n) && n > 0 ? n : 0;
16
+ }
17
+ export function orderChoiceLimits({ minChoices, maxChoices, choiceCount }) {
18
+ const total = positiveCount(choiceCount);
19
+ const min = positiveCount(minChoices);
20
+ if (min === 0 || min >= total)
21
+ return { subset: false, minOrdered: total, maxOrdered: total };
22
+ const max = positiveCount(maxChoices);
23
+ // maxChoices "must be greater than or equal to minChoices"; one authored below it would make
24
+ // the item unanswerable, so the minimum wins.
25
+ const cap = max > 0 ? Math.min(max, total) : total;
26
+ return { subset: true, minOrdered: min, maxOrdered: Math.max(cap, min) };
27
+ }
28
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/interactions/order/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoBH,SAAS,aAAa,CAAC,KAAgC;IACtD,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAA0B;IAChG,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IACtC,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,KAAK;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC9F,MAAM,GAAG,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IACtC,6FAA6F;IAC7F,8CAA8C;IAC9C,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["/**\n * The order-subset rule (QTI 2.2 ASI §5.73 orderInteraction, §5.42 graphicOrderInteraction,\n * §2.4.1.2; QTI 3.0 `min-choices` / `max-choices` mean the same). Response validation and the\n * delivered UI both read it, so the UI can never produce a response validation rejects nor\n * refuse one it accepts.\n *\n * - `minChoices` unspecified: \"all of the choices must be ordered and maxChoices is ignored\".\n * - `minChoices` from 1 up to fewer than the choices: \"the candidate must select a subset of\n * the choices and impose an ordering on them\" — at least `minChoices`, at most the cap,\n * which is `maxChoices` (0 = no limit) clamped to the number of choices.\n * - `minChoices` at or above the number of choices: every choice, as in the default.\n */\n\nexport interface OrderSubsetInteraction {\n\t/** The authored minChoices; absent, 0 or not a number means unspecified. */\n\tminChoices?: number | null;\n\t/** The authored maxChoices; absent, 0 or not a number means no limit. */\n\tmaxChoices?: number | null;\n\t/** How many choices the interaction offers (simpleChoice / hotspotChoice). */\n\tchoiceCount: number;\n}\n\nexport interface OrderChoiceLimits {\n\t/** True when the candidate selects which choices to order: a subset is requested. */\n\tsubset: boolean;\n\t/** The fewest choices a complete response orders: every choice unless a subset is requested. */\n\tminOrdered: number;\n\t/** The most choices a response may order: every choice unless a subset is requested. */\n\tmaxOrdered: number;\n}\n\nfunction positiveCount(value: number | null | undefined): number {\n\tconst n = Math.floor(Number(value ?? 0));\n\treturn Number.isFinite(n) && n > 0 ? n : 0;\n}\n\nexport function orderChoiceLimits({ minChoices, maxChoices, choiceCount }: OrderSubsetInteraction): OrderChoiceLimits {\n\tconst total = positiveCount(choiceCount);\n\tconst min = positiveCount(minChoices);\n\tif (min === 0 || min >= total) return { subset: false, minOrdered: total, maxOrdered: total };\n\tconst max = positiveCount(maxChoices);\n\t// maxChoices \"must be greater than or equal to minChoices\"; one authored below it would make\n\t// the item unanswerable, so the minimum wins.\n\tconst cap = max > 0 ? Math.min(max, total) : total;\n\treturn { subset: true, minOrdered: min, maxOrdered: Math.max(cap, min) };\n}\n"]}
@@ -39,10 +39,12 @@ export const portableCustomExtractor = {
39
39
  utils.getAttribute(element, 'response-identifier') ||
40
40
  context.responseId ||
41
41
  '';
42
+ // The schema-defined name only: `customInteractionTypeIdentifier` (QTI 2.x
43
+ // camelCase) and its QTI 3.0 kebab form. No QTI or PCI version defines the
44
+ // `customInteractionIdentifierType` spellings some earlier content used;
45
+ // hosts passing those must use the schema name.
42
46
  const customInteractionTypeIdentifier = utils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||
43
47
  utils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||
44
- utils.getAttribute(pciElement, 'customInteractionIdentifierType') ||
45
- utils.getAttribute(pciElement, 'custom-interaction-identifier-type') ||
46
48
  '';
47
49
  // --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---
48
50
  // These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.
@@ -87,19 +89,14 @@ export const portableCustomExtractor = {
87
89
  // the authored DOM scaffold that the resolved module initializes.
88
90
  const markupSource = markupEl ?? instanceEl;
89
91
  const markup = markupSource ? utils.getHtmlContent(markupSource) : '';
90
- // --- Config from <qti-pci-properties>/<qti-pci-property> ---
91
- // qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the
92
- // native node-html-parser querySelector (available as element.querySelector on the raw element).
92
+ // --- Config ---
93
+ // QTI 3.0 carries PCI configuration as data-* attributes on the interaction element, named
94
+ // as HTMLElement.dataset names them.
93
95
  const config = {};
94
- const propsEl = findDescendant(pciElement, ['pciproperties', 'qti-pci-properties']);
95
- if (propsEl) {
96
- const propEls = findDescendants(propsEl, ['pciproperty', 'qti-pci-property']);
97
- for (const propEl of propEls) {
98
- const key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';
99
- const value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';
100
- if (key)
101
- config[key] = value;
102
- }
96
+ for (const [name, value] of Object.entries(pciElement.attributes ?? {})) {
97
+ const key = datasetKey(name);
98
+ if (key)
99
+ config[key] = value;
103
100
  }
104
101
  return {
105
102
  responseIdentifier,
@@ -148,6 +145,13 @@ function pickEntryModule(modules, customInteractionTypeIdentifier) {
148
145
  }
149
146
  return modules[modules.length - 1];
150
147
  }
148
+ /** The HTMLElement.dataset key for a `data-*` attribute name, or undefined for any other attribute. */
149
+ function datasetKey(attributeName) {
150
+ const name = attributeName.toLowerCase();
151
+ if (!name.startsWith('data-') || name.length === 5)
152
+ return undefined;
153
+ return name.slice(5).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
154
+ }
151
155
  function localTagName(element) {
152
156
  const raw = element.rawTagName?.toLowerCase() ?? '';
153
157
  return raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE;QACb,mBAAmB;QACnB,2BAA2B;QAC3B,iCAAiC;KACjC;IACD,WAAW,EAAE,mFAAmF;IAEhG,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CACN,GAAG,KAAK,2BAA2B;YACnC,GAAG,KAAK,iCAAiC;YACzC,CAAC,GAAG,KAAK,mBAAmB,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAC,KAAK,IAAI,CAAC,CAChG,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1B,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,UAAU,GACf,QAAQ,KAAK,mBAAmB;YAC/B,CAAC,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAC;YACxD,CAAC,CAAC,OAAO,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O,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\tutils.getAttribute(pciElement, 'customInteractionIdentifierType') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-identifier-type') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\t// Every authored entry is kept; the entry module — the one whose id matches the\n\t\t// customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.\n\t\tconst modules: ExtractedPci['modules'] = [];\n\t\tlet resolutionConfigPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst configuration =\n\t\t\t\tutils.getAttribute(modulesEl, 'primaryConfiguration') ||\n\t\t\t\tutils.getAttribute(modulesEl, 'primary-configuration') ||\n\t\t\t\t'';\n\t\t\tif (configuration) resolutionConfigPath = configuration;\n\n\t\t\tfor (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {\n\t\t\t\tconst primary =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') ||\n\t\t\t\t\t'';\n\t\t\t\tconst fallback =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') ||\n\t\t\t\t\t'';\n\t\t\t\tmodules.push({\n\t\t\t\t\tid: utils.getAttribute(moduleEl, 'id') || '',\n\t\t\t\t\tprimaryPath: primary,\n\t\t\t\t\t...(fallback ? { fallbackPath: fallback } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst entry = pickEntryModule(modules, customInteractionTypeIdentifier);\n\t\tlet primaryPath = entry?.primaryPath ?? '';\n\t\tlet fallbackPath = entry?.fallbackPath;\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config from <qti-pci-properties>/<qti-pci-property> ---\n\t\t// qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the\n\t\t// native node-html-parser querySelector (available as element.querySelector on the raw element).\n\t\tconst config: Record<string, string> = {};\n\n\t\tconst propsEl = findDescendant(pciElement, ['pciproperties', 'qti-pci-properties']);\n\n\t\tif (propsEl) {\n\t\t\tconst propEls = findDescendants(propsEl, ['pciproperty', 'qti-pci-property']);\n\t\t\tfor (const propEl of propEls) {\n\t\t\t\tconst key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';\n\t\t\t\tconst value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';\n\t\t\t\tif (key) config[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmodules,\n\t\t\t...(resolutionConfigPath ? { resolutionConfigPath } : {}),\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\n/**\n * The entry module: the one whose id matches the customInteractionTypeIdentifier's\n * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else\n * the last entry. Only the id match is specified; the rest keeps single-module\n * content authored without ids loading.\n */\nfunction pickEntryModule(\n\tmodules: ExtractedPci['modules'],\n\tcustomInteractionTypeIdentifier: string\n): ExtractedPci['modules'][number] | undefined {\n\tif (modules.length === 0) return undefined;\n\tconst tail = customInteractionTypeIdentifier.split(':').pop()?.trim();\n\tif (tail) {\n\t\tconst byId = modules.find((module) => module.id === tail);\n\t\tif (byId) return byId;\n\t}\n\tfor (let index = modules.length - 1; index >= 0; index -= 1) {\n\t\tif (modules[index].primaryPath) return modules[index];\n\t}\n\treturn modules[modules.length - 1];\n}\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE;QACb,mBAAmB;QACnB,2BAA2B;QAC3B,iCAAiC;KACjC;IACD,WAAW,EAAE,mFAAmF;IAEhG,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CACN,GAAG,KAAK,2BAA2B;YACnC,GAAG,KAAK,iCAAiC;YACzC,CAAC,GAAG,KAAK,mBAAmB,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAC,KAAK,IAAI,CAAC,CAChG,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1B,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,UAAU,GACf,QAAQ,KAAK,mBAAmB;YAC/B,CAAC,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAC;YACxD,CAAC,CAAC,OAAO,CAAC;QAEZ,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC3F,CAAC;QAED,MAAM,kBAAkB,GACvB,KAAK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,OAAO,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IACpD,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACtE,CAAC;AAED,SAAS,cAAc,CACtB,OAA2B,EAC3B,UAA6B;IAE7B,OAAO,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACxD,CAAC;AAED,SAAS,eAAe,CACvB,OAA2B,EAC3B,UAA6B;IAE7B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,CAAC,MAA0B,EAAE,EAAE;QAC5C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,KAA2B,CAAC;YAC9C,IAAI,CAAC,SAAS,CAAC,UAAU;gBAAE,SAAS;YACpC,IAAI,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\t// The schema-defined name only: `customInteractionTypeIdentifier` (QTI 2.x\n\t\t// camelCase) and its QTI 3.0 kebab form. No QTI or PCI version defines the\n\t\t// `customInteractionIdentifierType` spellings some earlier content used;\n\t\t// hosts passing those must use the schema name.\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\t// Every authored entry is kept; the entry module — the one whose id matches the\n\t\t// customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.\n\t\tconst modules: ExtractedPci['modules'] = [];\n\t\tlet resolutionConfigPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst configuration =\n\t\t\t\tutils.getAttribute(modulesEl, 'primaryConfiguration') ||\n\t\t\t\tutils.getAttribute(modulesEl, 'primary-configuration') ||\n\t\t\t\t'';\n\t\t\tif (configuration) resolutionConfigPath = configuration;\n\n\t\t\tfor (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {\n\t\t\t\tconst primary =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') ||\n\t\t\t\t\t'';\n\t\t\t\tconst fallback =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') ||\n\t\t\t\t\t'';\n\t\t\t\tmodules.push({\n\t\t\t\t\tid: utils.getAttribute(moduleEl, 'id') || '',\n\t\t\t\t\tprimaryPath: primary,\n\t\t\t\t\t...(fallback ? { fallbackPath: fallback } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst entry = pickEntryModule(modules, customInteractionTypeIdentifier);\n\t\tlet primaryPath = entry?.primaryPath ?? '';\n\t\tlet fallbackPath = entry?.fallbackPath;\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config ---\n\t\t// QTI 3.0 carries PCI configuration as data-* attributes on the interaction element, named\n\t\t// as HTMLElement.dataset names them.\n\t\tconst config: Record<string, string> = {};\n\t\tfor (const [name, value] of Object.entries(pciElement.attributes ?? {})) {\n\t\t\tconst key = datasetKey(name);\n\t\t\tif (key) config[key] = value;\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmodules,\n\t\t\t...(resolutionConfigPath ? { resolutionConfigPath } : {}),\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\n/**\n * The entry module: the one whose id matches the customInteractionTypeIdentifier's\n * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else\n * the last entry. Only the id match is specified; the rest keeps single-module\n * content authored without ids loading.\n */\nfunction pickEntryModule(\n\tmodules: ExtractedPci['modules'],\n\tcustomInteractionTypeIdentifier: string\n): ExtractedPci['modules'][number] | undefined {\n\tif (modules.length === 0) return undefined;\n\tconst tail = customInteractionTypeIdentifier.split(':').pop()?.trim();\n\tif (tail) {\n\t\tconst byId = modules.find((module) => module.id === tail);\n\t\tif (byId) return byId;\n\t}\n\tfor (let index = modules.length - 1; index >= 0; index -= 1) {\n\t\tif (modules[index].primaryPath) return modules[index];\n\t}\n\treturn modules[modules.length - 1];\n}\n\n/** The HTMLElement.dataset key for a `data-*` attribute name, or undefined for any other attribute. */\nfunction datasetKey(attributeName: string): string | undefined {\n\tconst name = attributeName.toLowerCase();\n\tif (!name.startsWith('data-') || name.length === 5) return undefined;\n\treturn name.slice(5).replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase());\n}\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}
@@ -1,10 +1,17 @@
1
1
  import type { ElementExtractor } from '../../extraction/types.js';
2
+ import type { PositionObjectCenterPoint } from '../shared/types.js';
2
3
  export interface ImageData {
3
4
  type: 'image' | 'svg';
4
5
  src?: string;
5
6
  content?: string;
6
7
  width?: string;
7
8
  height?: string;
9
+ /** Short text alternative extracted from the QTI source. */
10
+ alt?: string;
11
+ /** Longer description for complex images (SVG <desc>, aria description). */
12
+ altDescription?: string;
13
+ /** True only when the author explicitly marked the image decorative. */
14
+ decorative?: boolean;
8
15
  }
9
16
  export interface PositionObjectData {
10
17
  imageData: ImageData | null;
@@ -15,12 +22,22 @@ export interface PositionObjectData {
15
22
  */
16
23
  positionObjectStages: Array<{
17
24
  identifier: string;
25
+ /**
26
+ * The draggable object's authored text alternative. Empty when the author
27
+ * gave none: the renderer then names it generically. Never the response
28
+ * identifier, which can leak the answer key to assistive technology.
29
+ */
18
30
  label: string;
19
31
  matchMax: number;
20
32
  objectData: ImageData | null;
21
33
  classes?: string[];
22
34
  }>;
23
- centerPoint: boolean;
35
+ /**
36
+ * The point on the draggable object image treated as its position, as an
37
+ * offset from the object image's top-left corner in its own pixels. `null`
38
+ * when unauthored: the QTI default is the centre of its bounding rectangle.
39
+ */
40
+ centerPoint: PositionObjectCenterPoint | null;
24
41
  maxChoices: number;
25
42
  minChoices: number;
26
43
  prompt: string | null;
@@ -1,16 +1,65 @@
1
1
  import { normalizePixelDimension } from '../../security/styleValues.js';
2
- function imageDataFromObject(objectElement, utils, defaultWidth, defaultHeight) {
3
- if (!objectElement)
2
+ import { extractImageAlternative, imgAlternativeSource } from '../shared/imageAlt.js';
3
+ import { findInteractionImage } from '../shared/interactionImage.js';
4
+ /**
5
+ * Read the authored reference point. QTI 2.2 spells the attribute `centerPoint`
6
+ * and the QTI 2.1 schema `centrePoint`; the attribute mapper resolves the QTI 3.0
7
+ * kebab-case form of either. The value is two numbers, horizontal then vertical,
8
+ * whitespace-separated (a comma is tolerated, as in `coords`). Anything else
9
+ * counts as unauthored, so the object falls back to the QTI default, its centre.
10
+ */
11
+ function readCenterPoint(element, { utils }) {
12
+ const authored = utils.getAttribute(element, 'centerPoint') || utils.getAttribute(element, 'centrePoint');
13
+ const parts = authored.trim().split(/[\s,]+/);
14
+ if (parts.length !== 2 || !parts.every((part) => /^[+-]?\d+(\.\d+)?$/.test(part)))
4
15
  return null;
5
- const type = utils.getAttribute(objectElement, 'type', '');
6
- const data = utils.getAttribute(objectElement, 'data', '');
7
- const width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''), defaultWidth);
8
- const height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''), defaultHeight);
9
- const content = utils.getHtmlContent(objectElement);
16
+ return { x: Number(parts[0]), y: Number(parts[1]) };
17
+ }
18
+ /**
19
+ * The image data of one resolved interaction image. QTI 2.x authors an
20
+ * `<object data=… width height>`; the QTI 3.0 schema gives the stage background
21
+ * and the draggable a choice of `object`, `img` or `picture` (delivered via the
22
+ * `<picture>`'s `<img>` fallback).
23
+ */
24
+ function imageDataFromInteractionImage(image, context, fallback) {
25
+ if (!image)
26
+ return null;
27
+ const imageElement = image.element;
28
+ const { utils, dom } = context;
29
+ // The pixel space is the authored width/height, when declared (the stage's
30
+ // natural size stands in when it is not). A `fallback` keeps a box size that
31
+ // is not a scoring space (the draggable object's 50×50).
32
+ const width = normalizePixelDimension(utils.getAttribute(imageElement, 'width', ''), fallback?.width);
33
+ const height = normalizePixelDimension(utils.getAttribute(imageElement, 'height', ''), fallback?.height);
34
+ if (image.kind === 'img') {
35
+ // QTI 3.0 <img>: the alt attribute is the text alternative (alt="" = decorative)
36
+ return {
37
+ type: 'image',
38
+ src: utils.getAttribute(imageElement, 'src', ''),
39
+ width,
40
+ height,
41
+ ...extractImageAlternative(imageElement, utils, dom, imgAlternativeSource(imageElement)),
42
+ };
43
+ }
44
+ const type = utils.getAttribute(imageElement, 'type', '');
45
+ const data = utils.getAttribute(imageElement, 'data', '');
46
+ const content = utils.getHtmlContent(imageElement);
10
47
  if (type.startsWith('image/svg') && /<svg[\s>]/i.test(content)) {
11
- return { type: 'svg', content, width, height };
48
+ return {
49
+ type: 'svg',
50
+ content,
51
+ width,
52
+ height,
53
+ ...extractImageAlternative(imageElement, utils, dom, { inlineSvgContent: content }),
54
+ };
12
55
  }
13
- return { type: 'image', src: data, width, height };
56
+ return {
57
+ type: 'image',
58
+ src: data,
59
+ width,
60
+ height,
61
+ ...extractImageAlternative(imageElement, utils, dom),
62
+ };
14
63
  }
15
64
  export const standardPositionObjectExtractor = {
16
65
  id: 'qti:position-object-interaction',
@@ -30,13 +79,15 @@ export const standardPositionObjectExtractor = {
30
79
  const stage = parent && isPositionObjectStage && utils.getChildrenByTag(parent, 'positionObjectInteraction').includes(element)
31
80
  ? parent
32
81
  : undefined;
33
- const backgroundObject = stage ? utils.getChildrenByTag(stage, 'object')[0] : undefined;
34
- const draggableObject = utils.getChildrenByTag(element, 'object')[0];
35
- const imageData = imageDataFromObject(backgroundObject, utils, '500', '300');
36
- const objectData = imageDataFromObject(draggableObject, utils, '50', '50');
82
+ const backgroundImage = stage ? findInteractionImage(stage, utils) : undefined;
83
+ const draggableImage = findInteractionImage(element, utils);
84
+ const imageData = imageDataFromInteractionImage(backgroundImage, context);
85
+ const objectData = imageDataFromInteractionImage(draggableImage, context, { width: '50', height: '50' });
37
86
  const maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);
38
87
  const minChoices = utils.getNumberAttribute(element, 'minChoices', 0);
39
- const label = utils.getTextContent(draggableObject).trim() || responseId;
88
+ // The draggable object's authored alternative names it. No identifier
89
+ // fallback: the renderer substitutes a localized generic name instead.
90
+ const label = objectData?.alt ?? '';
40
91
  const classes = utils.getClasses(element);
41
92
  const prompt = utils.getPrompt(element);
42
93
  return {
@@ -50,9 +101,9 @@ export const standardPositionObjectExtractor = {
50
101
  ...(classes.length > 0 ? { classes } : {}),
51
102
  },
52
103
  ],
53
- // The renderer currently represents the QTI default (the object's centre)
54
- // as a boolean. Explicit centre coordinates remain a follow-up API change.
55
- centerPoint: true,
104
+ // The point on the draggable object recorded as its position; null keeps
105
+ // the QTI default (the centre of the object's bounding rectangle).
106
+ centerPoint: readCenterPoint(element, context),
56
107
  maxChoices,
57
108
  minChoices,
58
109
  prompt,
@@ -62,20 +113,20 @@ export const standardPositionObjectExtractor = {
62
113
  const errors = [];
63
114
  const warnings = [];
64
115
  if (!data.imageData) {
65
- errors.push('positionObjectInteraction must have a parent positionObjectStage with a background object');
116
+ errors.push('positionObjectInteraction must have a parent positionObjectStage with a background image');
66
117
  }
67
118
  else if (data.imageData.type === 'image' && !data.imageData.src) {
68
- errors.push('positionObjectStage background object must have a data URL');
119
+ errors.push('positionObjectStage background image must have a data URL');
69
120
  }
70
121
  else if (data.imageData.type === 'svg' && !data.imageData.content) {
71
- errors.push('positionObjectStage background object must have SVG content');
122
+ errors.push('positionObjectStage background image must have SVG content');
72
123
  }
73
124
  const draggable = data.positionObjectStages[0];
74
125
  if (!draggable?.objectData) {
75
- errors.push('positionObjectInteraction must contain one draggable object');
126
+ errors.push('positionObjectInteraction must contain one draggable image');
76
127
  }
77
128
  else if (draggable.objectData.type === 'image' && !draggable.objectData.src) {
78
- errors.push('positionObjectInteraction draggable object must have a data URL');
129
+ errors.push('positionObjectInteraction draggable image must have a data URL');
79
130
  }
80
131
  if (data.maxChoices < 0)
81
132
  errors.push('maxChoices must be non-negative');
@@ -84,6 +135,14 @@ export const standardPositionObjectExtractor = {
84
135
  if (data.maxChoices > 0 && data.minChoices > data.maxChoices) {
85
136
  errors.push('minChoices cannot exceed maxChoices');
86
137
  }
138
+ const objectWidth = Number(draggable?.objectData?.width);
139
+ const objectHeight = Number(draggable?.objectData?.height);
140
+ if (data.centerPoint &&
141
+ objectWidth > 0 &&
142
+ objectHeight > 0 &&
143
+ (data.centerPoint.x < 0 || data.centerPoint.y < 0 || data.centerPoint.x > objectWidth || data.centerPoint.y > objectHeight)) {
144
+ warnings.push(`centerPoint ${data.centerPoint.x} ${data.centerPoint.y} lies outside the ${objectWidth}×${objectHeight} object image`);
145
+ }
87
146
  if (data.imageData?.type === 'image') {
88
147
  warnings.push('Ensure the declared positionObjectStage width/height match the image dimensions. ' +
89
148
  `Declared: ${data.imageData.width || 'unspecified'}×${data.imageData.height || 'unspecified'}`);
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/position-object/extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AA+BxE,SAAS,mBAAmB,CAC3B,aAAqC,EACrC,KAA8E,EAC9E,YAAoB,EACpB,aAAqB;IAErB,IAAI,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC;IAEhC,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,uBAAuB,CACpC,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,CAAC,EAC9C,YAAY,CACZ,CAAC;IACF,MAAM,MAAM,GAAG,uBAAuB,CACrC,KAAK,CAAC,YAAY,CAAC,aAAa,EAAE,QAAQ,EAAE,EAAE,CAAC,EAC/C,aAAa,CACb,CAAC;IACF,MAAM,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IAEpD,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACpD,CAAC;AAED,M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S;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\nimport type { QTIElement } from '../shared/types.js';\n\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n}\n\nexport interface PositionObjectData {\n\timageData: ImageData | null;\n\t/**\n\t * Compatibility shape consumed by the existing renderer. Each extracted\n\t * interaction contributes its one draggable object here; the actual QTI\n\t * positionObjectStage is the interaction's parent and supplies imageData.\n\t */\n\tpositionObjectStages: Array<{\n\t\tidentifier: string;\n\t\tlabel: string;\n\t\tmatchMax: number;\n\t\tobjectData: ImageData | null;\n\t\tclasses?: string[];\n\t}>;\n\tcenterPoint: boolean;\n\tmaxChoices: number;\n\tminChoices: number;\n\tprompt: string | null;\n}\n\nfunction imageDataFromObject(\n\tobjectElement: QTIElement | undefined,\n\tutils: Parameters<ElementExtractor<PositionObjectData>['extract']>[1]['utils'],\n\tdefaultWidth: string,\n\tdefaultHeight: string,\n): ImageData | null {\n\tif (!objectElement) return null;\n\n\tconst type = utils.getAttribute(objectElement, 'type', '');\n\tconst data = utils.getAttribute(objectElement, 'data', '');\n\tconst width = normalizePixelDimension(\n\t\tutils.getAttribute(objectElement, 'width', ''),\n\t\tdefaultWidth,\n\t);\n\tconst height = normalizePixelDimension(\n\t\tutils.getAttribute(objectElement, 'height', ''),\n\t\tdefaultHeight,\n\t);\n\tconst content = utils.getHtmlContent(objectElement);\n\n\tif (type.startsWith('image/svg') && /<svg[\\s>]/i.test(content)) {\n\t\treturn { type: 'svg', content, width, height };\n\t}\n\n\treturn { type: 'image', src: data, width, height };\n}\n\nexport const standardPositionObjectExtractor: ElementExtractor<PositionObjectData> = {\n\tid: 'qti:position-object-interaction',\n\tname: 'QTI Standard Position Object Interaction',\n\tpriority: 10,\n\telementTypes: ['positionObjectInteraction'],\n\tdescription: 'Extracts a positionObjectInteraction from its parent positionObjectStage',\n\n\tcanHandle(element) {\n\t\tconst tagName = element.rawTagName?.toLowerCase();\n\t\treturn tagName === 'positionobjectinteraction' || tagName === 'qti-position-object-interaction';\n\t},\n\n\textract(element, context) {\n\t\tconst { utils, responseId } = context;\n\t\tconst parent = element.parentNode as QTIElement | undefined;\n\t\tconst parentTagName = parent?.rawTagName?.toLowerCase();\n\t\tconst isPositionObjectStage =\n\t\t\tparentTagName === 'positionobjectstage' || parentTagName === 'qti-position-object-stage';\n\t\tconst stage = parent && isPositionObjectStage && utils.getChildrenByTag(parent, 'positionObjectInteraction').includes(element)\n\t\t\t? parent\n\t\t\t: undefined;\n\n\t\tconst backgroundObject = stage ? utils.getChildrenByTag(stage, 'object')[0] : undefined;\n\t\tconst draggableObject = utils.getChildrenByTag(element, 'object')[0];\n\t\tconst imageData = imageDataFromObject(backgroundObject, utils, '500', '300');\n\t\tconst objectData = imageDataFromObject(draggableObject, utils, '50', '50');\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\tconst label = utils.getTextContent(draggableObject).trim() || responseId;\n\t\tconst classes = utils.getClasses(element);\n\t\tconst prompt = utils.getPrompt(element);\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tpositionObjectStages: [\n\t\t\t\t{\n\t\t\t\t\tidentifier: responseId,\n\t\t\t\t\tlabel,\n\t\t\t\t\tmatchMax: maxChoices,\n\t\t\t\t\tobjectData,\n\t\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t\t},\n\t\t\t],\n\t\t\t// The renderer currently represents the QTI default (the object's centre)\n\t\t\t// as a boolean. Explicit centre coordinates remain a follow-up API change.\n\t\t\tcenterPoint: true,\n\t\t\tmaxChoices,\n\t\t\tminChoices,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.imageData) {\n\t\t\terrors.push('positionObjectInteraction must have a parent positionObjectStage with a background object');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('positionObjectStage background object must have a data URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('positionObjectStage background object must have SVG content');\n\t\t}\n\n\t\tconst draggable = data.positionObjectStages[0];\n\t\tif (!draggable?.objectData) {\n\t\t\terrors.push('positionObjectInteraction must contain one draggable object');\n\t\t} else if (draggable.objectData.type === 'image' && !draggable.objectData.src) {\n\t\t\terrors.push('positionObjectInteraction draggable object must have a data URL');\n\t\t}\n\n\t\tif (data.maxChoices < 0) errors.push('maxChoices must be non-negative');\n\t\tif (data.minChoices < 0) errors.push('minChoices must be non-negative');\n\t\tif (data.maxChoices > 0 && data.minChoices > data.maxChoices) {\n\t\t\terrors.push('minChoices cannot exceed maxChoices');\n\t\t}\n\n\t\tif (data.imageData?.type === 'image') {\n\t\t\twarnings.push(\n\t\t\t\t'Ensure the declared positionObjectStage width/height match the image dimensions. ' +\n\t\t\t\t\t`Declared: ${data.imageData.width || 'unspecified'}×${data.imageData.height || 'unspecified'}`,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/position-object/extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAyB,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;A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AC;YACtC,QAAQ,CAAC,IAAI,CACZ,mFAAmF;gBAClF,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,aAAa,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,aAAa,EAAE,CAC/F,CAAC;QACH,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\nimport { extractImageAlternative, imgAlternativeSource } from '../shared/imageAlt.js';\nimport { type InteractionImage, findInteractionImage } from '../shared/interactionImage.js';\nimport type { PositionObjectCenterPoint, QTIElement } from '../shared/types.js';\n\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n\t/** Short text alternative extracted from the QTI source. */\n\talt?: string;\n\t/** Longer description for complex images (SVG <desc>, aria description). */\n\taltDescription?: string;\n\t/** True only when the author explicitly marked the image decorative. */\n\tdecorative?: boolean;\n}\n\nexport interface PositionObjectData {\n\timageData: ImageData | null;\n\t/**\n\t * Compatibility shape consumed by the existing renderer. Each extracted\n\t * interaction contributes its one draggable object here; the actual QTI\n\t * positionObjectStage is the interaction's parent and supplies imageData.\n\t */\n\tpositionObjectStages: Array<{\n\t\tidentifier: string;\n\t\t/**\n\t\t * The draggable object's authored text alternative. Empty when the author\n\t\t * gave none: the renderer then names it generically. Never the response\n\t\t * identifier, which can leak the answer key to assistive technology.\n\t\t */\n\t\tlabel: string;\n\t\tmatchMax: number;\n\t\tobjectData: ImageData | null;\n\t\tclasses?: string[];\n\t}>;\n\t/**\n\t * The point on the draggable object image treated as its position, as an\n\t * offset from the object image's top-left corner in its own pixels. `null`\n\t * when unauthored: the QTI default is the centre of its bounding rectangle.\n\t */\n\tcenterPoint: PositionObjectCenterPoint | null;\n\tmaxChoices: number;\n\tminChoices: number;\n\tprompt: string | null;\n}\n\n/**\n * Read the authored reference point. QTI 2.2 spells the attribute `centerPoint`\n * and the QTI 2.1 schema `centrePoint`; the attribute mapper resolves the QTI 3.0\n * kebab-case form of either. The value is two numbers, horizontal then vertical,\n * whitespace-separated (a comma is tolerated, as in `coords`). Anything else\n * counts as unauthored, so the object falls back to the QTI default, its centre.\n */\nfunction readCenterPoint(\n\telement: QTIElement,\n\t{ utils }: Parameters<ElementExtractor<PositionObjectData>['extract']>[1],\n): PositionObjectCenterPoint | null {\n\tconst authored = utils.getAttribute(element, 'centerPoint') || utils.getAttribute(element, 'centrePoint');\n\tconst parts = authored.trim().split(/[\\s,]+/);\n\tif (parts.length !== 2 || !parts.every((part) => /^[+-]?\\d+(\\.\\d+)?$/.test(part))) return null;\n\treturn { x: Number(parts[0]), y: Number(parts[1]) };\n}\n\n/**\n * The image data of one resolved interaction image. QTI 2.x authors an\n * `<object data=… width height>`; the QTI 3.0 schema gives the stage background\n * and the draggable a choice of `object`, `img` or `picture` (delivered via the\n * `<picture>`'s `<img>` fallback).\n */\nfunction imageDataFromInteractionImage(\n\timage: InteractionImage | null | undefined,\n\tcontext: Parameters<ElementExtractor<PositionObjectData>['extract']>[1],\n\tfallback?: { width: string; height: string },\n): ImageData | null {\n\tif (!image) return null;\n\tconst imageElement = image.element;\n\tconst { utils, dom } = context;\n\t// The pixel space is the authored width/height, when declared (the stage's\n\t// natural size stands in when it is not). A `fallback` keeps a box size that\n\t// is not a scoring space (the draggable object's 50×50).\n\tconst width = normalizePixelDimension(utils.getAttribute(imageElement, 'width', ''), fallback?.width);\n\tconst height = normalizePixelDimension(utils.getAttribute(imageElement, 'height', ''), fallback?.height);\n\n\tif (image.kind === 'img') {\n\t\t// QTI 3.0 <img>: the alt attribute is the text alternative (alt=\"\" = decorative)\n\t\treturn {\n\t\t\ttype: 'image',\n\t\t\tsrc: utils.getAttribute(imageElement, 'src', ''),\n\t\t\twidth,\n\t\t\theight,\n\t\t\t...extractImageAlternative(imageElement, utils, dom, imgAlternativeSource(imageElement)),\n\t\t};\n\t}\n\n\tconst type = utils.getAttribute(imageElement, 'type', '');\n\tconst data = utils.getAttribute(imageElement, 'data', '');\n\tconst content = utils.getHtmlContent(imageElement);\n\n\tif (type.startsWith('image/svg') && /<svg[\\s>]/i.test(content)) {\n\t\treturn {\n\t\t\ttype: 'svg',\n\t\t\tcontent,\n\t\t\twidth,\n\t\t\theight,\n\t\t\t...extractImageAlternative(imageElement, utils, dom, { inlineSvgContent: content }),\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'image',\n\t\tsrc: data,\n\t\twidth,\n\t\theight,\n\t\t...extractImageAlternative(imageElement, utils, dom),\n\t};\n}\n\nexport const standardPositionObjectExtractor: ElementExtractor<PositionObjectData> = {\n\tid: 'qti:position-object-interaction',\n\tname: 'QTI Standard Position Object Interaction',\n\tpriority: 10,\n\telementTypes: ['positionObjectInteraction'],\n\tdescription: 'Extracts a positionObjectInteraction from its parent positionObjectStage',\n\n\tcanHandle(element) {\n\t\tconst tagName = element.rawTagName?.toLowerCase();\n\t\treturn tagName === 'positionobjectinteraction' || tagName === 'qti-position-object-interaction';\n\t},\n\n\textract(element, context) {\n\t\tconst { utils, responseId } = context;\n\t\tconst parent = element.parentNode as QTIElement | undefined;\n\t\tconst parentTagName = parent?.rawTagName?.toLowerCase();\n\t\tconst isPositionObjectStage =\n\t\t\tparentTagName === 'positionobjectstage' || parentTagName === 'qti-position-object-stage';\n\t\tconst stage = parent && isPositionObjectStage && utils.getChildrenByTag(parent, 'positionObjectInteraction').includes(element)\n\t\t\t? parent\n\t\t\t: undefined;\n\n\t\tconst backgroundImage = stage ? findInteractionImage(stage, utils) : undefined;\n\t\tconst draggableImage = findInteractionImage(element, utils);\n\t\tconst imageData = imageDataFromInteractionImage(backgroundImage, context);\n\t\tconst objectData = imageDataFromInteractionImage(draggableImage, context, { width: '50', height: '50' });\n\t\tconst maxChoices = utils.getNumberAttribute(element, 'maxChoices', 1);\n\t\tconst minChoices = utils.getNumberAttribute(element, 'minChoices', 0);\n\t\t// The draggable object's authored alternative names it. No identifier\n\t\t// fallback: the renderer substitutes a localized generic name instead.\n\t\tconst label = objectData?.alt ?? '';\n\t\tconst classes = utils.getClasses(element);\n\t\tconst prompt = utils.getPrompt(element);\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tpositionObjectStages: [\n\t\t\t\t{\n\t\t\t\t\tidentifier: responseId,\n\t\t\t\t\tlabel,\n\t\t\t\t\tmatchMax: maxChoices,\n\t\t\t\t\tobjectData,\n\t\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t\t},\n\t\t\t],\n\t\t\t// The point on the draggable object recorded as its position; null keeps\n\t\t\t// the QTI default (the centre of the object's bounding rectangle).\n\t\t\tcenterPoint: readCenterPoint(element, context),\n\t\t\tmaxChoices,\n\t\t\tminChoices,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.imageData) {\n\t\t\terrors.push('positionObjectInteraction must have a parent positionObjectStage with a background image');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('positionObjectStage background image must have a data URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('positionObjectStage background image must have SVG content');\n\t\t}\n\n\t\tconst draggable = data.positionObjectStages[0];\n\t\tif (!draggable?.objectData) {\n\t\t\terrors.push('positionObjectInteraction must contain one draggable image');\n\t\t} else if (draggable.objectData.type === 'image' && !draggable.objectData.src) {\n\t\t\terrors.push('positionObjectInteraction draggable image must have a data URL');\n\t\t}\n\n\t\tif (data.maxChoices < 0) errors.push('maxChoices must be non-negative');\n\t\tif (data.minChoices < 0) errors.push('minChoices must be non-negative');\n\t\tif (data.maxChoices > 0 && data.minChoices > data.maxChoices) {\n\t\t\terrors.push('minChoices cannot exceed maxChoices');\n\t\t}\n\n\t\tconst objectWidth = Number(draggable?.objectData?.width);\n\t\tconst objectHeight = Number(draggable?.objectData?.height);\n\t\tif (\n\t\t\tdata.centerPoint &&\n\t\t\tobjectWidth > 0 &&\n\t\t\tobjectHeight > 0 &&\n\t\t\t(data.centerPoint.x < 0 || data.centerPoint.y < 0 || data.centerPoint.x > objectWidth || data.centerPoint.y > objectHeight)\n\t\t) {\n\t\t\twarnings.push(\n\t\t\t\t`centerPoint ${data.centerPoint.x} ${data.centerPoint.y} lies outside the ${objectWidth}×${objectHeight} object image`,\n\t\t\t);\n\t\t}\n\n\t\tif (data.imageData?.type === 'image') {\n\t\t\twarnings.push(\n\t\t\t\t'Ensure the declared positionObjectStage width/height match the image dimensions. ' +\n\t\t\t\t\t`Declared: ${data.imageData.width || 'unspecified'}×${data.imageData.height || 'unspecified'}`,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
@@ -13,6 +13,12 @@ export interface ImageData {
13
13
  content?: string;
14
14
  width?: string;
15
15
  height?: string;
16
+ /** Short text alternative extracted from the QTI source. */
17
+ alt?: string;
18
+ /** Longer description for complex images (SVG <desc>, aria description). */
19
+ altDescription?: string;
20
+ /** True only when the author explicitly marked the image decorative (`<img alt="">`). */
21
+ decorative?: boolean;
16
22
  }
17
23
  /**
18
24
  * Select point data extracted from selectPointInteraction elements