@pie-qti/item-player 0.1.19 → 0.1.20

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 (257) hide show
  1. package/README.md +137 -427
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
  3. package/dist/catalog/applyGlossaryTriggers.js +4 -2
  4. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  5. package/dist/components/utils/stimulusRender.d.ts +1 -2
  6. package/dist/components/utils/stimulusRender.js +2 -5
  7. package/dist/components/utils/stimulusRender.js.map +1 -1
  8. package/dist/core/AssessmentItemDefinition.d.ts +69 -0
  9. package/dist/core/AssessmentItemDefinition.js +149 -0
  10. package/dist/core/AssessmentItemDefinition.js.map +1 -0
  11. package/dist/core/ComponentRegistry.d.ts +11 -5
  12. package/dist/core/ComponentRegistry.js +44 -17
  13. package/dist/core/ComponentRegistry.js.map +1 -1
  14. package/dist/core/ItemSession.d.ts +58 -0
  15. package/dist/core/ItemSession.js +286 -0
  16. package/dist/core/ItemSession.js.map +1 -0
  17. package/dist/core/Player.d.ts +9 -8
  18. package/dist/core/Player.js +182 -163
  19. package/dist/core/Player.js.map +1 -1
  20. package/dist/document/AssessmentItemDocument.d.ts +32 -10
  21. package/dist/document/AssessmentItemDocument.js +80 -23
  22. package/dist/document/AssessmentItemDocument.js.map +1 -1
  23. package/dist/{element-class-BEpwHdcP.js → element-class-CILJ4Ls7.js} +3572 -2783
  24. package/dist/element-class-CILJ4Ls7.js.map +1 -0
  25. package/dist/element-class.d.ts +17 -13
  26. package/dist/element-class.js +1 -1
  27. package/dist/element.js +1 -1
  28. package/dist/extraction/ExtractionRegistry.d.ts +34 -11
  29. package/dist/extraction/ExtractionRegistry.js +122 -19
  30. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  31. package/dist/extraction/createContext.d.ts +5 -6
  32. package/dist/extraction/createContext.js +2 -2
  33. package/dist/extraction/createContext.js.map +1 -1
  34. package/dist/extraction/deliveryTypes.d.ts +26 -0
  35. package/dist/extraction/deliveryTypes.js +7 -0
  36. package/dist/extraction/deliveryTypes.js.map +1 -0
  37. package/dist/extraction/index.d.ts +3 -3
  38. package/dist/extraction/index.js +1 -2
  39. package/dist/extraction/index.js.map +1 -1
  40. package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
  41. package/dist/extraction/interactionExtractionPipeline.js +27 -10
  42. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  43. package/dist/extraction/interactionSecurity.d.ts +11 -2
  44. package/dist/extraction/interactionSecurity.js +105 -40
  45. package/dist/extraction/interactionSecurity.js.map +1 -1
  46. package/dist/extraction/types.d.ts +44 -7
  47. package/dist/extraction/types.js.map +1 -1
  48. package/dist/extraction/utils.js +4 -16
  49. package/dist/extraction/utils.js.map +1 -1
  50. package/dist/index.d.ts +9 -8
  51. package/dist/index.js +5 -7
  52. package/dist/index.js.map +1 -1
  53. package/dist/interactions/associate/extractor.js +1 -1
  54. package/dist/interactions/associate/extractor.js.map +1 -1
  55. package/dist/interactions/drawing/extractor.js +5 -4
  56. package/dist/interactions/drawing/extractor.js.map +1 -1
  57. package/dist/interactions/end-attempt/extractor.js +2 -2
  58. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  59. package/dist/interactions/gap-match/extractor.js +4 -3
  60. package/dist/interactions/gap-match/extractor.js.map +1 -1
  61. package/dist/interactions/graphic-associate/extractor.js +5 -4
  62. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  63. package/dist/interactions/graphic-gap-match/extractor.js +20 -17
  64. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  65. package/dist/interactions/graphic-order/extractor.js +5 -4
  66. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  67. package/dist/interactions/hotspot/extractor.js +11 -10
  68. package/dist/interactions/hotspot/extractor.js.map +1 -1
  69. package/dist/interactions/inline/render-plan.d.ts +3 -5
  70. package/dist/interactions/inline/render-plan.js.map +1 -1
  71. package/dist/interactions/media/extractor.js +2 -2
  72. package/dist/interactions/media/extractor.js.map +1 -1
  73. package/dist/interactions/modules.d.ts +11 -91
  74. package/dist/interactions/modules.js +185 -45
  75. package/dist/interactions/modules.js.map +1 -1
  76. package/dist/interactions/portable-custom/extractor.d.ts +1 -1
  77. package/dist/interactions/portable-custom/extractor.js +1 -1
  78. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  79. package/dist/interactions/position-object/extractor.js +3 -2
  80. package/dist/interactions/position-object/extractor.js.map +1 -1
  81. package/dist/interactions/select-point/extractor.js +7 -6
  82. package/dist/interactions/select-point/extractor.js.map +1 -1
  83. package/dist/interactions/shared/types.d.ts +59 -70
  84. package/dist/interactions/shared/types.js.map +1 -1
  85. package/dist/interactions/slider/extractor.js +2 -2
  86. package/dist/interactions/slider/extractor.js.map +1 -1
  87. package/dist/interactions/upload/extractor.js +2 -2
  88. package/dist/interactions/upload/extractor.js.map +1 -1
  89. package/dist/pci/types.d.ts +2 -3
  90. package/dist/pci/types.js.map +1 -1
  91. package/dist/presentation/itemPresentationPlan.d.ts +71 -38
  92. package/dist/presentation/itemPresentationPlan.js +78 -34
  93. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  94. package/dist/security/index.d.ts +1 -1
  95. package/dist/security/index.js +1 -1
  96. package/dist/security/index.js.map +1 -1
  97. package/dist/security/styleValues.d.ts +20 -0
  98. package/dist/security/styleValues.js +49 -0
  99. package/dist/security/styleValues.js.map +1 -0
  100. package/dist/server.d.ts +188 -9
  101. package/dist/server.js +32 -7
  102. package/dist/server.js.map +1 -1
  103. package/dist/types/index.d.ts +1 -110
  104. package/dist/types/index.js.map +1 -1
  105. package/dist/web-components/QTIInteractionBase.d.ts +2 -2
  106. package/dist/web-components/QTIInteractionBase.js.map +1 -1
  107. package/dist/web-components/QTIInteractionElement.d.ts +3 -3
  108. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  109. package/package.json +11 -11
  110. package/dist/core/Plugin.d.ts +0 -104
  111. package/dist/core/Plugin.js +0 -8
  112. package/dist/core/Plugin.js.map +0 -1
  113. package/dist/core/PluginManager.d.ts +0 -55
  114. package/dist/core/PluginManager.js +0 -148
  115. package/dist/core/PluginManager.js.map +0 -1
  116. package/dist/element-class-BEpwHdcP.js.map +0 -1
  117. package/dist/interactions/associate/index.d.ts +0 -2
  118. package/dist/interactions/associate/index.js +0 -2
  119. package/dist/interactions/associate/index.js.map +0 -1
  120. package/dist/interactions/associate/types.d.ts +0 -1
  121. package/dist/interactions/associate/types.js +0 -2
  122. package/dist/interactions/associate/types.js.map +0 -1
  123. package/dist/interactions/choice/index.d.ts +0 -2
  124. package/dist/interactions/choice/index.js +0 -2
  125. package/dist/interactions/choice/index.js.map +0 -1
  126. package/dist/interactions/choice/types.d.ts +0 -1
  127. package/dist/interactions/choice/types.js +0 -2
  128. package/dist/interactions/choice/types.js.map +0 -1
  129. package/dist/interactions/custom/index.d.ts +0 -2
  130. package/dist/interactions/custom/index.js +0 -2
  131. package/dist/interactions/custom/index.js.map +0 -1
  132. package/dist/interactions/custom/types.d.ts +0 -1
  133. package/dist/interactions/custom/types.js +0 -2
  134. package/dist/interactions/custom/types.js.map +0 -1
  135. package/dist/interactions/drawing/index.d.ts +0 -2
  136. package/dist/interactions/drawing/index.js +0 -2
  137. package/dist/interactions/drawing/index.js.map +0 -1
  138. package/dist/interactions/drawing/types.d.ts +0 -1
  139. package/dist/interactions/drawing/types.js +0 -2
  140. package/dist/interactions/drawing/types.js.map +0 -1
  141. package/dist/interactions/end-attempt/index.d.ts +0 -2
  142. package/dist/interactions/end-attempt/index.js +0 -2
  143. package/dist/interactions/end-attempt/index.js.map +0 -1
  144. package/dist/interactions/end-attempt/types.d.ts +0 -1
  145. package/dist/interactions/end-attempt/types.js +0 -2
  146. package/dist/interactions/end-attempt/types.js.map +0 -1
  147. package/dist/interactions/extended-text/index.d.ts +0 -3
  148. package/dist/interactions/extended-text/index.js +0 -3
  149. package/dist/interactions/extended-text/index.js.map +0 -1
  150. package/dist/interactions/extended-text/types.d.ts +0 -1
  151. package/dist/interactions/extended-text/types.js +0 -2
  152. package/dist/interactions/extended-text/types.js.map +0 -1
  153. package/dist/interactions/gap-match/index.d.ts +0 -2
  154. package/dist/interactions/gap-match/index.js +0 -2
  155. package/dist/interactions/gap-match/index.js.map +0 -1
  156. package/dist/interactions/gap-match/types.d.ts +0 -1
  157. package/dist/interactions/gap-match/types.js +0 -2
  158. package/dist/interactions/gap-match/types.js.map +0 -1
  159. package/dist/interactions/graphic-associate/index.d.ts +0 -2
  160. package/dist/interactions/graphic-associate/index.js +0 -2
  161. package/dist/interactions/graphic-associate/index.js.map +0 -1
  162. package/dist/interactions/graphic-associate/types.d.ts +0 -1
  163. package/dist/interactions/graphic-associate/types.js +0 -2
  164. package/dist/interactions/graphic-associate/types.js.map +0 -1
  165. package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
  166. package/dist/interactions/graphic-gap-match/index.js +0 -2
  167. package/dist/interactions/graphic-gap-match/index.js.map +0 -1
  168. package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
  169. package/dist/interactions/graphic-gap-match/types.js +0 -2
  170. package/dist/interactions/graphic-gap-match/types.js.map +0 -1
  171. package/dist/interactions/graphic-order/index.d.ts +0 -2
  172. package/dist/interactions/graphic-order/index.js +0 -2
  173. package/dist/interactions/graphic-order/index.js.map +0 -1
  174. package/dist/interactions/graphic-order/types.d.ts +0 -1
  175. package/dist/interactions/graphic-order/types.js +0 -2
  176. package/dist/interactions/graphic-order/types.js.map +0 -1
  177. package/dist/interactions/hotspot/index.d.ts +0 -2
  178. package/dist/interactions/hotspot/index.js +0 -2
  179. package/dist/interactions/hotspot/index.js.map +0 -1
  180. package/dist/interactions/hotspot/types.d.ts +0 -1
  181. package/dist/interactions/hotspot/types.js +0 -2
  182. package/dist/interactions/hotspot/types.js.map +0 -1
  183. package/dist/interactions/hottext/index.d.ts +0 -2
  184. package/dist/interactions/hottext/index.js +0 -2
  185. package/dist/interactions/hottext/index.js.map +0 -1
  186. package/dist/interactions/hottext/types.d.ts +0 -1
  187. package/dist/interactions/hottext/types.js +0 -2
  188. package/dist/interactions/hottext/types.js.map +0 -1
  189. package/dist/interactions/index.d.ts +0 -32
  190. package/dist/interactions/index.js +0 -31
  191. package/dist/interactions/index.js.map +0 -1
  192. package/dist/interactions/inline/index.d.ts +0 -1
  193. package/dist/interactions/inline/index.js +0 -2
  194. package/dist/interactions/inline/index.js.map +0 -1
  195. package/dist/interactions/inline-choice/index.d.ts +0 -2
  196. package/dist/interactions/inline-choice/index.js +0 -2
  197. package/dist/interactions/inline-choice/index.js.map +0 -1
  198. package/dist/interactions/inline-choice/types.d.ts +0 -1
  199. package/dist/interactions/inline-choice/types.js +0 -2
  200. package/dist/interactions/inline-choice/types.js.map +0 -1
  201. package/dist/interactions/match/index.d.ts +0 -2
  202. package/dist/interactions/match/index.js +0 -2
  203. package/dist/interactions/match/index.js.map +0 -1
  204. package/dist/interactions/match/types.d.ts +0 -1
  205. package/dist/interactions/match/types.js +0 -2
  206. package/dist/interactions/match/types.js.map +0 -1
  207. package/dist/interactions/media/index.d.ts +0 -2
  208. package/dist/interactions/media/index.js +0 -2
  209. package/dist/interactions/media/index.js.map +0 -1
  210. package/dist/interactions/media/types.d.ts +0 -1
  211. package/dist/interactions/media/types.js +0 -2
  212. package/dist/interactions/media/types.js.map +0 -1
  213. package/dist/interactions/order/index.d.ts +0 -2
  214. package/dist/interactions/order/index.js +0 -2
  215. package/dist/interactions/order/index.js.map +0 -1
  216. package/dist/interactions/order/types.d.ts +0 -1
  217. package/dist/interactions/order/types.js +0 -2
  218. package/dist/interactions/order/types.js.map +0 -1
  219. package/dist/interactions/portable-custom/index.d.ts +0 -2
  220. package/dist/interactions/portable-custom/index.js +0 -2
  221. package/dist/interactions/portable-custom/index.js.map +0 -1
  222. package/dist/interactions/portable-custom/types.d.ts +0 -1
  223. package/dist/interactions/portable-custom/types.js +0 -2
  224. package/dist/interactions/portable-custom/types.js.map +0 -1
  225. package/dist/interactions/position-object/index.d.ts +0 -2
  226. package/dist/interactions/position-object/index.js +0 -2
  227. package/dist/interactions/position-object/index.js.map +0 -1
  228. package/dist/interactions/position-object/types.d.ts +0 -1
  229. package/dist/interactions/position-object/types.js +0 -2
  230. package/dist/interactions/position-object/types.js.map +0 -1
  231. package/dist/interactions/select-point/index.d.ts +0 -2
  232. package/dist/interactions/select-point/index.js +0 -2
  233. package/dist/interactions/select-point/index.js.map +0 -1
  234. package/dist/interactions/select-point/types.d.ts +0 -1
  235. package/dist/interactions/select-point/types.js +0 -2
  236. package/dist/interactions/select-point/types.js.map +0 -1
  237. package/dist/interactions/shared/index.d.ts +0 -1
  238. package/dist/interactions/shared/index.js +0 -2
  239. package/dist/interactions/shared/index.js.map +0 -1
  240. package/dist/interactions/slider/index.d.ts +0 -2
  241. package/dist/interactions/slider/index.js +0 -2
  242. package/dist/interactions/slider/index.js.map +0 -1
  243. package/dist/interactions/slider/types.d.ts +0 -1
  244. package/dist/interactions/slider/types.js +0 -2
  245. package/dist/interactions/slider/types.js.map +0 -1
  246. package/dist/interactions/text-entry/index.d.ts +0 -2
  247. package/dist/interactions/text-entry/index.js +0 -2
  248. package/dist/interactions/text-entry/index.js.map +0 -1
  249. package/dist/interactions/text-entry/types.d.ts +0 -1
  250. package/dist/interactions/text-entry/types.js +0 -2
  251. package/dist/interactions/text-entry/types.js.map +0 -1
  252. package/dist/interactions/upload/index.d.ts +0 -2
  253. package/dist/interactions/upload/index.js +0 -2
  254. package/dist/interactions/upload/index.js.map +0 -1
  255. package/dist/interactions/upload/types.d.ts +0 -1
  256. package/dist/interactions/upload/types.js +0 -2
  257. package/dist/interactions/upload/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"applyGlossaryTriggers.js","sourceRoot":"","sources":["../../src/catalog/applyGlossaryTriggers.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG;IACvB,EAAE,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,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AAQ,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC3D,CAAC,CAAC,cAAc,EAAE,CAAC;gBACnB,KAAK,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;QACF,CAAC;IACF,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACjD,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAElD,6BAA6B;IAC7B,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IAEtC,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { CatalogSupportPreference } from '../pnp/types.js';\nimport type { PnpProfile } from '../pnp/types.js';\n\nconst PLATFORM_USAGES = [\n\t{ usage: 'tts-pronunciation', flag: 'ttsPronunciation', label: 'Request pronunciation', text: 'P' },\n\t{ usage: 'signing-definition', flag: 'signingDefinition', label: 'Request signing definition', text: 'S' },\n\t{ usage: 'braille-text', flag: 'brailleText', label: 'Request braille text', text: 'B' },\n\t{ usage: 'audio-description', flag: 'audioDescription', label: 'Request audio description', text: 'A' },\n\t{ usage: 'extended-description', flag: 'extendedDescription', label: 'Request extended description', text: 'D' },\n] as const;\nconst ILLUSTRATED_GLOSSARY_USAGE = 'illustrated-glossary';\nconst BUILT_IN_POPUP_USAGES = new Set<string>([\n\t'glossary-on-screen',\n\t'keyword-translation',\n\tILLUSTRATED_GLOSSARY_USAGE,\n]);\nconst RESERVED_PLATFORM_FLAGS = new Set<string>(PLATFORM_USAGES.map((support) => support.flag));\nconst RESERVED_PLATFORM_USAGES = new Set<string>(PLATFORM_USAGES.map((support) => support.usage));\nconst SAFE_CATALOG_USAGE = /^[a-z][a-z0-9._-]*$/;\n\ninterface HostCatalogSupport {\n\tusage: string;\n\tlabel: string;\n\ttext: string;\n\tlanguageCode?: string;\n}\n\ninterface CatalogComponentRegistry {\n\tgetTagNameForType(type: string): string | null;\n}\n\nexport interface GlossaryPlayer {\n\tgetPnp(): PnpProfile | undefined;\n\tgetCatalogEntry(\n\t\tidref: string,\n\t\tusage: string,\n\t\tlang?: string,\n\t\toptions?: { stimulusIdentifier?: string }\n\t): string | null;\n\tgetComponentRegistry(): CatalogComponentRegistry;\n}\n\n/**\n * Inject glossary/keyword-translation trigger buttons into a rendered item container.\n *\n * When pnp.content.glossaryOnScreen is true, each [data-catalog-idref] element gets a\n * trigger button. Clicking the button looks up the catalog entry and shows a floating\n * popup rendered by the 'catalogPopup' component from the registry (defaults to\n * pie-qti-catalog-popup). Clicking again or pressing Escape closes it.\n *\n * For platform-level usages (tts-pronunciation, signing-definition, braille-text,\n * audio-description) the player fires a `qti-catalog-lookup` CustomEvent instead of\n * mounting a popup — the host application handles those usages.\n */\nexport function applyGlossaryTriggers(container: HTMLElement, player: GlossaryPlayer): () => void {\n\tcleanupGlossaryTriggers(container);\n\tconst pnp = player.getPnp();\n\tif (!pnp) return () => cleanupGlossaryTriggers(container);\n\n\tconst glossaryOn = pnp.content?.glossaryOnScreen === true;\n\tconst kwTranslation = pnp.content?.keywordTranslation;\n\tconst kwOn = kwTranslation?.active === true && !!kwTranslation.languageCode;\n\tconst illustratedOn = pnp.content?.illustratedGlossary === true;\n\tconst platformSupports = pnp.content?.catalogSupports ?? {};\n\tconst hostSupports = getHostCatalogSupports(platformSupports);\n\n\tconst anyPlatformOn = PLATFORM_USAGES.some((support) => isSupportActive(getPlatformSupportPreference(platformSupports, support)));\n\tif (!glossaryOn && !kwOn && !illustratedOn && !anyPlatformOn && hostSupports.length === 0) return () => cleanupGlossaryTriggers(container);\n\n\tconst terms = container.querySelectorAll<HTMLElement>('[data-catalog-idref]');\n\tif (terms.length === 0) return () => cleanupGlossaryTriggers(container);\n\n\t// Track open popup so only one is open at a time\n\tlet currentCleanup: (() => void) | null = null;\n\n\tfor (const termEl of Array.from(terms)) {\n\t\tconst idref = termEl.getAttribute('data-catalog-idref');\n\t\tif (!idref) continue;\n\t\tconst stimulusIdentifier = getStimulusIdentifier(termEl);\n\n\t\t// Wrap term in a relative-positioned span so we can position popup against it\n\t\tconst wrapper = document.createElement('span');\n\t\twrapper.className = 'qti-catalog-term';\n\t\twrapper.style.cssText = 'position:relative;display:inline';\n\n\t\ttermEl.parentNode?.insertBefore(wrapper, termEl);\n\t\twrapper.appendChild(termEl);\n\n\t\tif (glossaryOn) {\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, 'glossary-on-screen', 'Show definition');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, 'glossary-on-screen', undefined, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (kwOn) {\n\t\t\tconst lang = kwTranslation!.languageCode;\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, 'keyword-translation', 'Show translation');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, 'keyword-translation', lang, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (illustratedOn) {\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, ILLUSTRATED_GLOSSARY_USAGE, 'Show illustrated glossary');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, ILLUSTRATED_GLOSSARY_USAGE, undefined, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tfor (const support of PLATFORM_USAGES) {\n\t\t\tconst preference = getPlatformSupportPreference(platformSupports, support);\n\t\t\tif (!isSupportActive(preference)) continue;\n\t\t\taddHostCatalogSupportButton(wrapper, termEl, idref, {\n\t\t\t\t...support,\n\t\t\t\tlanguageCode: getSupportLanguageCode(preference),\n\t\t\t}, player, stimulusIdentifier);\n\t\t}\n\n\t\tfor (const support of hostSupports) {\n\t\t\taddHostCatalogSupportButton(wrapper, termEl, idref, support, player, stimulusIdentifier);\n\t\t}\n\t}\n\n\treturn () => {\n\t\tcurrentCleanup?.();\n\t\tcleanupGlossaryTriggers(container);\n\t};\n}\n\nexport function cleanupGlossaryTriggers(container: HTMLElement): void {\n\tfor (const wrapper of Array.from(container.querySelectorAll<HTMLElement>('.qti-catalog-term'))) {\n\t\tconst term = Array.from(wrapper.children).find((child) =>\n\t\t\t(child as HTMLElement).getAttribute?.('data-catalog-idref') !== null\n\t\t) as HTMLElement | undefined;\n\t\tif (term && wrapper.parentNode) {\n\t\t\twrapper.parentNode.insertBefore(term, wrapper);\n\t\t}\n\t\twrapper.remove();\n\t}\n}\n\nfunction createTriggerButton(termText: string, usage: string, labelPrefix: string, text?: string): HTMLButtonElement {\n\tconst btn = document.createElement('button');\n\tbtn.type = 'button';\n\tbtn.className = 'qti-catalog-trigger';\n\tbtn.style.cssText =\n\t\t'display:inline-flex;align-items:center;justify-content:center;min-width:1.75rem;min-height:1.75rem;margin-inline:0.25rem;line-height:1;';\n\tbtn.setAttribute('aria-label', `${labelPrefix}: ${termText}`);\n\tbtn.setAttribute('data-catalog-usage', usage);\n\tbtn.textContent = text ?? (usage === 'keyword-translation' ? 'T' : usage === ILLUSTRATED_GLOSSARY_USAGE ? 'I' : '?');\n\treturn btn;\n}\n\nfunction addHostCatalogSupportButton(\n\twrapper: HTMLElement,\n\ttermEl: HTMLElement,\n\tidref: string,\n\tsupport: HostCatalogSupport,\n\tplayer: GlossaryPlayer,\n\tstimulusIdentifier?: string\n): void {\n\tconst html = player.getCatalogEntry(idref, support.usage, support.languageCode, { stimulusIdentifier });\n\tif (html === null) return;\n\tconst btn = createTriggerButton(termEl.textContent ?? idref, support.usage, support.label, support.text);\n\twrapper.appendChild(btn);\n\tbtn.addEventListener('click', () => {\n\t\tbtn.dispatchEvent(\n\t\t\tnew CustomEvent('qti-catalog-lookup', {\n\t\t\t\tbubbles: true,\n\t\t\t\tcomposed: true,\n\t\t\t\tdetail: { idref, usage: support.usage, html, content: html, languageCode: support.languageCode },\n\t\t\t})\n\t\t);\n\t});\n}\n\nfunction getStimulusIdentifier(termEl: HTMLElement): string | undefined {\n\tconst scopeEl = termEl.closest?.('[data-stimulus-idref]');\n\tconst identifier = scopeEl?.getAttribute?.('data-stimulus-idref')?.trim();\n\treturn identifier || undefined;\n}\n\nfunction getHostCatalogSupports(platformSupports: Record<string, CatalogSupportPreference | undefined>): HostCatalogSupport[] {\n\treturn Object.entries(platformSupports)\n\t\t.map(([usage, preference]) => ({ usage: normalizeCatalogUsage(usage), preference }))\n\t\t.filter(({ usage, preference }) => usage !== null && isSupportActive(preference) && !isReservedCatalogUsage(usage))\n\t\t.map(({ usage, preference }) => ({\n\t\t\tusage: usage!,\n\t\t\tlabel: `Request ${usage!.replace(/[-_]+/g, ' ')}`,\n\t\t\ttext: usage!.slice(0, 1).toUpperCase(),\n\t\t\tlanguageCode: getSupportLanguageCode(preference),\n\t\t}));\n}\n\nfunction getPlatformSupportPreference(\n\tplatformSupports: Record<string, CatalogSupportPreference | undefined>,\n\tsupport: (typeof PLATFORM_USAGES)[number]\n): CatalogSupportPreference | undefined {\n\treturn platformSupports[support.flag] ?? platformSupports[support.usage];\n}\n\nfunction isSupportActive(preference: CatalogSupportPreference | undefined): boolean {\n\tif (preference === undefined) return false;\n\tif (typeof preference === 'boolean') return preference;\n\treturn preference.active !== false;\n}\n\nfunction getSupportLanguageCode(preference: CatalogSupportPreference | undefined): string | undefined {\n\tif (!preference || typeof preference === 'boolean') return undefined;\n\tconst languageCode = preference.languageCode?.trim();\n\tif (!languageCode || !/^[a-zA-Z]{2,8}(?:-[a-zA-Z0-9]{1,8})*$/.test(languageCode)) return undefined;\n\treturn languageCode;\n}\n\nfunction normalizeCatalogUsage(value: string): string | null {\n\tconst usage = value.trim().toLowerCase();\n\tif (!SAFE_CATALOG_USAGE.test(usage)) return null;\n\treturn usage;\n}\n\nfunction isReservedCatalogUsage(usage: string): boolean {\n\treturn RESERVED_PLATFORM_FLAGS.has(usage) || RESERVED_PLATFORM_USAGES.has(usage) || BUILT_IN_POPUP_USAGES.has(usage);\n}\n\n/**\n * Mount a catalog popup via the component registry. Falls back to a minimal\n * vanilla-JS popup if no 'catalogPopup' component is registered (e.g. in tests\n * that don't load default-components). Returns a cleanup function.\n */\nfunction mountPopup(\n\tanchor: HTMLElement,\n\tlabel: string,\n\thtml: string,\n\ttriggerBtn: HTMLButtonElement,\n\tplayer: GlossaryPlayer,\n\tonClose: () => void\n): () => void {\n\tconst registry = player.getComponentRegistry();\n\n\tlet popupEl: HTMLElement;\n\tlet closed = false;\n\n\tfunction cleanup() {\n\t\tif (closed) return;\n\t\tclosed = true;\n\t\tpopupEl.remove();\n\t\ttriggerBtn.focus();\n\t\tonClose();\n\t}\n\n\tconst catalogPopupTag = registry.getTagNameForType('catalogPopup');\n\tif (catalogPopupTag !== null) {\n\t\tconst el = document.createElement(catalogPopupTag) as HTMLElement & {\n\t\t\tcontent: string;\n\t\t\tlabel: string;\n\t\t\tonClose: () => void;\n\t\t};\n\t\tel.content = html;\n\t\tel.label = label;\n\t\tel.onClose = cleanup;\n\t\tanchor.appendChild(el);\n\t\tpopupEl = el;\n\t} else {\n\t\t// Minimal fallback for environments without default-components\n\t\tpopupEl = buildFallbackPopup(label, html, cleanup);\n\t\tanchor.appendChild(popupEl);\n\t}\n\n\treturn cleanup;\n}\n\n/**\n * Minimal accessible fallback popup used when no catalogPopup component is registered.\n * Uses DaisyUI card classes where available; degrades gracefully without them.\n */\nfunction buildFallbackPopup(label: string, html: string, close: () => void): HTMLElement {\n\tconst popup = document.createElement('div');\n\tpopup.className = 'card card-bordered bg-base-100 shadow-lg qti-catalog-popup';\n\tpopup.setAttribute('role', 'dialog');\n\tpopup.setAttribute('aria-label', label);\n\tpopup.setAttribute('aria-modal', 'true');\n\tpopup.style.cssText = 'position:absolute;z-index:1000;min-width:16rem;max-width:24rem';\n\n\tconst header = document.createElement('div');\n\theader.className = 'card-title flex justify-between items-center px-3 py-2 border-b border-base-300 bg-base-200';\n\n\tconst title = document.createElement('span');\n\ttitle.className = 'text-sm font-semibold';\n\ttitle.textContent = label;\n\n\tconst closeBtn = document.createElement('button');\n\tcloseBtn.type = 'button';\n\tcloseBtn.className = 'btn btn-ghost btn-xs';\n\tcloseBtn.setAttribute('aria-label', 'Close');\n\tcloseBtn.textContent = '✕';\n\n\theader.appendChild(title);\n\theader.appendChild(closeBtn);\n\n\tconst body = document.createElement('div');\n\tbody.className = 'card-body p-3';\n\n\tconst isUrl = /^(https?:\\/\\/|\\/)/i.test(html.trim());\n\tif (isUrl) {\n\t\tconst img = document.createElement('img');\n\t\timg.src = html.trim();\n\t\timg.alt = label;\n\t\timg.className = 'max-w-full h-auto block mx-auto';\n\t\tbody.appendChild(img);\n\t} else {\n\t\tbody.innerHTML = html;\n\t}\n\n\tpopup.appendChild(header);\n\tpopup.appendChild(body);\n\n\t// Focus trap + Escape\n\tconst focusableSelector = 'a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n\tfunction handleKeyDown(e: KeyboardEvent) {\n\t\tif (e.key === 'Escape') {\n\t\t\te.preventDefault();\n\t\t\tcloseBtn.click();\n\t\t\treturn;\n\t\t}\n\t\tif (e.key === 'Tab') {\n\t\t\tconst focusable = Array.from(popup.querySelectorAll<HTMLElement>(focusableSelector)).filter(\n\t\t\t\t(el) => el.offsetParent !== null\n\t\t\t);\n\t\t\tif (focusable.length === 0) { e.preventDefault(); return; }\n\t\t\tconst first = focusable[0];\n\t\t\tconst last = focusable[focusable.length - 1];\n\t\t\tif (e.shiftKey && document.activeElement === first) {\n\t\t\t\te.preventDefault();\n\t\t\t\tlast.focus();\n\t\t\t} else if (!e.shiftKey && document.activeElement === last) {\n\t\t\t\te.preventDefault();\n\t\t\t\tfirst.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tpopup.addEventListener('keydown', handleKeyDown);\n\tcloseBtn.addEventListener('click', () => close());\n\n\t// Move focus in on next tick\n\tsetTimeout(() => closeBtn.focus(), 0);\n\n\treturn popup;\n}\n"]}
1
+ {"version":3,"file":"applyGlossaryTriggers.js","sourceRoot":"","sources":["../../src/catalog/applyGlossaryTriggers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,MAAM,eAAe,GAAG;IACvB,EAAE,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,GAAG,EAAE;IACnG,EAAE,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,4BAA4B,EAAE,IAAI,EAAE,GAAG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B,KAAK,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;QACF,CAAC;IACF,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACjD,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAElD,6BAA6B;IAC7B,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IAEtC,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { CatalogSupportPreference } from '../pnp/types.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport { htmlToString } from '../core/trustedTypes.js';\nimport type { HtmlContent } from '../types/index.js';\n\nconst PLATFORM_USAGES = [\n\t{ usage: 'tts-pronunciation', flag: 'ttsPronunciation', label: 'Request pronunciation', text: 'P' },\n\t{ usage: 'signing-definition', flag: 'signingDefinition', label: 'Request signing definition', text: 'S' },\n\t{ usage: 'braille-text', flag: 'brailleText', label: 'Request braille text', text: 'B' },\n\t{ usage: 'audio-description', flag: 'audioDescription', label: 'Request audio description', text: 'A' },\n\t{ usage: 'extended-description', flag: 'extendedDescription', label: 'Request extended description', text: 'D' },\n] as const;\nconst ILLUSTRATED_GLOSSARY_USAGE = 'illustrated-glossary';\nconst BUILT_IN_POPUP_USAGES = new Set<string>([\n\t'glossary-on-screen',\n\t'keyword-translation',\n\tILLUSTRATED_GLOSSARY_USAGE,\n]);\nconst RESERVED_PLATFORM_FLAGS = new Set<string>(PLATFORM_USAGES.map((support) => support.flag));\nconst RESERVED_PLATFORM_USAGES = new Set<string>(PLATFORM_USAGES.map((support) => support.usage));\nconst SAFE_CATALOG_USAGE = /^[a-z][a-z0-9._-]*$/;\n\ninterface HostCatalogSupport {\n\tusage: string;\n\tlabel: string;\n\ttext: string;\n\tlanguageCode?: string;\n}\n\ninterface CatalogComponentRegistry {\n\tgetTagNameForType(type: string): string | null;\n}\n\nexport interface GlossaryPlayer {\n\tgetPnp(): PnpProfile | undefined;\n\tgetCatalogEntry(\n\t\tidref: string,\n\t\tusage: string,\n\t\tlang?: string,\n\t\toptions?: { stimulusIdentifier?: string }\n\t): HtmlContent | null;\n\tgetComponentRegistry(): CatalogComponentRegistry;\n}\n\n/**\n * Inject glossary/keyword-translation trigger buttons into a rendered item container.\n *\n * When pnp.content.glossaryOnScreen is true, each [data-catalog-idref] element gets a\n * trigger button. Clicking the button looks up the catalog entry and shows a floating\n * popup rendered by the 'catalogPopup' component from the registry (defaults to\n * pie-qti-catalog-popup). Clicking again or pressing Escape closes it.\n *\n * For platform-level usages (tts-pronunciation, signing-definition, braille-text,\n * audio-description) the player fires a `qti-catalog-lookup` CustomEvent instead of\n * mounting a popup — the host application handles those usages.\n */\nexport function applyGlossaryTriggers(container: HTMLElement, player: GlossaryPlayer): () => void {\n\tcleanupGlossaryTriggers(container);\n\tconst pnp = player.getPnp();\n\tif (!pnp) return () => cleanupGlossaryTriggers(container);\n\n\tconst glossaryOn = pnp.content?.glossaryOnScreen === true;\n\tconst kwTranslation = pnp.content?.keywordTranslation;\n\tconst kwOn = kwTranslation?.active === true && !!kwTranslation.languageCode;\n\tconst illustratedOn = pnp.content?.illustratedGlossary === true;\n\tconst platformSupports = pnp.content?.catalogSupports ?? {};\n\tconst hostSupports = getHostCatalogSupports(platformSupports);\n\n\tconst anyPlatformOn = PLATFORM_USAGES.some((support) => isSupportActive(getPlatformSupportPreference(platformSupports, support)));\n\tif (!glossaryOn && !kwOn && !illustratedOn && !anyPlatformOn && hostSupports.length === 0) return () => cleanupGlossaryTriggers(container);\n\n\tconst terms = container.querySelectorAll<HTMLElement>('[data-catalog-idref]');\n\tif (terms.length === 0) return () => cleanupGlossaryTriggers(container);\n\n\t// Track open popup so only one is open at a time\n\tlet currentCleanup: (() => void) | null = null;\n\n\tfor (const termEl of Array.from(terms)) {\n\t\tconst idref = termEl.getAttribute('data-catalog-idref');\n\t\tif (!idref) continue;\n\t\tconst stimulusIdentifier = getStimulusIdentifier(termEl);\n\n\t\t// Wrap term in a relative-positioned span so we can position popup against it\n\t\tconst wrapper = document.createElement('span');\n\t\twrapper.className = 'qti-catalog-term';\n\t\twrapper.style.cssText = 'position:relative;display:inline';\n\n\t\ttermEl.parentNode?.insertBefore(wrapper, termEl);\n\t\twrapper.appendChild(termEl);\n\n\t\tif (glossaryOn) {\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, 'glossary-on-screen', 'Show definition');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, 'glossary-on-screen', undefined, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (kwOn) {\n\t\t\tconst lang = kwTranslation!.languageCode;\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, 'keyword-translation', 'Show translation');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, 'keyword-translation', lang, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (illustratedOn) {\n\t\t\tconst btn = createTriggerButton(termEl.textContent ?? idref, ILLUSTRATED_GLOSSARY_USAGE, 'Show illustrated glossary');\n\t\t\twrapper.appendChild(btn);\n\n\t\t\tbtn.addEventListener('click', () => {\n\t\t\t\tif (currentCleanup) {\n\t\t\t\t\tcurrentCleanup();\n\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst html = player.getCatalogEntry(idref, ILLUSTRATED_GLOSSARY_USAGE, undefined, { stimulusIdentifier });\n\t\t\t\tif (html !== null) {\n\t\t\t\t\tcurrentCleanup = mountPopup(wrapper, termEl.textContent ?? idref, html, btn, player, () => {\n\t\t\t\t\t\tcurrentCleanup = null;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tfor (const support of PLATFORM_USAGES) {\n\t\t\tconst preference = getPlatformSupportPreference(platformSupports, support);\n\t\t\tif (!isSupportActive(preference)) continue;\n\t\t\taddHostCatalogSupportButton(wrapper, termEl, idref, {\n\t\t\t\t...support,\n\t\t\t\tlanguageCode: getSupportLanguageCode(preference),\n\t\t\t}, player, stimulusIdentifier);\n\t\t}\n\n\t\tfor (const support of hostSupports) {\n\t\t\taddHostCatalogSupportButton(wrapper, termEl, idref, support, player, stimulusIdentifier);\n\t\t}\n\t}\n\n\treturn () => {\n\t\tcurrentCleanup?.();\n\t\tcleanupGlossaryTriggers(container);\n\t};\n}\n\nexport function cleanupGlossaryTriggers(container: HTMLElement): void {\n\tfor (const wrapper of Array.from(container.querySelectorAll<HTMLElement>('.qti-catalog-term'))) {\n\t\tconst term = Array.from(wrapper.children).find((child) =>\n\t\t\t(child as HTMLElement).getAttribute?.('data-catalog-idref') !== null\n\t\t) as HTMLElement | undefined;\n\t\tif (term && wrapper.parentNode) {\n\t\t\twrapper.parentNode.insertBefore(term, wrapper);\n\t\t}\n\t\twrapper.remove();\n\t}\n}\n\nfunction createTriggerButton(termText: string, usage: string, labelPrefix: string, text?: string): HTMLButtonElement {\n\tconst btn = document.createElement('button');\n\tbtn.type = 'button';\n\tbtn.className = 'qti-catalog-trigger';\n\tbtn.style.cssText =\n\t\t'display:inline-flex;align-items:center;justify-content:center;min-width:1.75rem;min-height:1.75rem;margin-inline:0.25rem;line-height:1;';\n\tbtn.setAttribute('aria-label', `${labelPrefix}: ${termText}`);\n\tbtn.setAttribute('data-catalog-usage', usage);\n\tbtn.textContent = text ?? (usage === 'keyword-translation' ? 'T' : usage === ILLUSTRATED_GLOSSARY_USAGE ? 'I' : '?');\n\treturn btn;\n}\n\nfunction addHostCatalogSupportButton(\n\twrapper: HTMLElement,\n\ttermEl: HTMLElement,\n\tidref: string,\n\tsupport: HostCatalogSupport,\n\tplayer: GlossaryPlayer,\n\tstimulusIdentifier?: string\n): void {\n\tconst html = player.getCatalogEntry(idref, support.usage, support.languageCode, { stimulusIdentifier });\n\tif (html === null) return;\n\tconst btn = createTriggerButton(termEl.textContent ?? idref, support.usage, support.label, support.text);\n\twrapper.appendChild(btn);\n\tbtn.addEventListener('click', () => {\n\t\tbtn.dispatchEvent(\n\t\t\tnew CustomEvent('qti-catalog-lookup', {\n\t\t\t\tbubbles: true,\n\t\t\t\tcomposed: true,\n\t\t\t\tdetail: { idref, usage: support.usage, html, content: html, languageCode: support.languageCode },\n\t\t\t})\n\t\t);\n\t});\n}\n\nfunction getStimulusIdentifier(termEl: HTMLElement): string | undefined {\n\tconst scopeEl = termEl.closest?.('[data-stimulus-idref]');\n\tconst identifier = scopeEl?.getAttribute?.('data-stimulus-idref')?.trim();\n\treturn identifier || undefined;\n}\n\nfunction getHostCatalogSupports(platformSupports: Record<string, CatalogSupportPreference | undefined>): HostCatalogSupport[] {\n\treturn Object.entries(platformSupports)\n\t\t.map(([usage, preference]) => ({ usage: normalizeCatalogUsage(usage), preference }))\n\t\t.filter(({ usage, preference }) => usage !== null && isSupportActive(preference) && !isReservedCatalogUsage(usage))\n\t\t.map(({ usage, preference }) => ({\n\t\t\tusage: usage!,\n\t\t\tlabel: `Request ${usage!.replace(/[-_]+/g, ' ')}`,\n\t\t\ttext: usage!.slice(0, 1).toUpperCase(),\n\t\t\tlanguageCode: getSupportLanguageCode(preference),\n\t\t}));\n}\n\nfunction getPlatformSupportPreference(\n\tplatformSupports: Record<string, CatalogSupportPreference | undefined>,\n\tsupport: (typeof PLATFORM_USAGES)[number]\n): CatalogSupportPreference | undefined {\n\treturn platformSupports[support.flag] ?? platformSupports[support.usage];\n}\n\nfunction isSupportActive(preference: CatalogSupportPreference | undefined): boolean {\n\tif (preference === undefined) return false;\n\tif (typeof preference === 'boolean') return preference;\n\treturn preference.active !== false;\n}\n\nfunction getSupportLanguageCode(preference: CatalogSupportPreference | undefined): string | undefined {\n\tif (!preference || typeof preference === 'boolean') return undefined;\n\tconst languageCode = preference.languageCode?.trim();\n\tif (!languageCode || !/^[a-zA-Z]{2,8}(?:-[a-zA-Z0-9]{1,8})*$/.test(languageCode)) return undefined;\n\treturn languageCode;\n}\n\nfunction normalizeCatalogUsage(value: string): string | null {\n\tconst usage = value.trim().toLowerCase();\n\tif (!SAFE_CATALOG_USAGE.test(usage)) return null;\n\treturn usage;\n}\n\nfunction isReservedCatalogUsage(usage: string): boolean {\n\treturn RESERVED_PLATFORM_FLAGS.has(usage) || RESERVED_PLATFORM_USAGES.has(usage) || BUILT_IN_POPUP_USAGES.has(usage);\n}\n\n/**\n * Mount a catalog popup via the component registry. Falls back to a minimal\n * vanilla-JS popup if no 'catalogPopup' component is registered (e.g. in tests\n * that don't load default-components). Returns a cleanup function.\n */\nfunction mountPopup(\n\tanchor: HTMLElement,\n\tlabel: string,\n\thtml: HtmlContent,\n\ttriggerBtn: HTMLButtonElement,\n\tplayer: GlossaryPlayer,\n\tonClose: () => void\n): () => void {\n\tconst registry = player.getComponentRegistry();\n\n\tlet popupEl: HTMLElement;\n\tlet closed = false;\n\n\tfunction cleanup() {\n\t\tif (closed) return;\n\t\tclosed = true;\n\t\tpopupEl.remove();\n\t\ttriggerBtn.focus();\n\t\tonClose();\n\t}\n\n\tconst catalogPopupTag = registry.getTagNameForType('catalogPopup');\n\tif (catalogPopupTag !== null) {\n\t\tconst el = document.createElement(catalogPopupTag) as HTMLElement & {\n\t\t\tcontent: HtmlContent;\n\t\t\tlabel: string;\n\t\t\tonClose: () => void;\n\t\t};\n\t\tel.content = html;\n\t\tel.label = label;\n\t\tel.onClose = cleanup;\n\t\tanchor.appendChild(el);\n\t\tpopupEl = el;\n\t} else {\n\t\t// Minimal fallback for environments without default-components\n\t\tpopupEl = buildFallbackPopup(label, html, cleanup);\n\t\tanchor.appendChild(popupEl);\n\t}\n\n\treturn cleanup;\n}\n\n/**\n * Minimal accessible fallback popup used when no catalogPopup component is registered.\n * Uses DaisyUI card classes where available; degrades gracefully without them.\n */\nfunction buildFallbackPopup(label: string, html: HtmlContent, close: () => void): HTMLElement {\n\tconst popup = document.createElement('div');\n\tpopup.className = 'card card-bordered bg-base-100 shadow-lg qti-catalog-popup';\n\tpopup.setAttribute('role', 'dialog');\n\tpopup.setAttribute('aria-label', label);\n\tpopup.setAttribute('aria-modal', 'true');\n\tpopup.style.cssText = 'position:absolute;z-index:1000;min-width:16rem;max-width:24rem';\n\n\tconst header = document.createElement('div');\n\theader.className = 'card-title flex justify-between items-center px-3 py-2 border-b border-base-300 bg-base-200';\n\n\tconst title = document.createElement('span');\n\ttitle.className = 'text-sm font-semibold';\n\ttitle.textContent = label;\n\n\tconst closeBtn = document.createElement('button');\n\tcloseBtn.type = 'button';\n\tcloseBtn.className = 'btn btn-ghost btn-xs';\n\tcloseBtn.setAttribute('aria-label', 'Close');\n\tcloseBtn.textContent = '✕';\n\n\theader.appendChild(title);\n\theader.appendChild(closeBtn);\n\n\tconst body = document.createElement('div');\n\tbody.className = 'card-body p-3';\n\n\tconst htmlString = htmlToString(html);\n\tconst isUrl = /^(https?:\\/\\/|\\/)/i.test(htmlString.trim());\n\tif (isUrl) {\n\t\tconst img = document.createElement('img');\n\t\timg.src = htmlString.trim();\n\t\timg.alt = label;\n\t\timg.className = 'max-w-full h-auto block mx-auto';\n\t\tbody.appendChild(img);\n\t} else {\n\t\tbody.innerHTML = html as any;\n\t}\n\n\tpopup.appendChild(header);\n\tpopup.appendChild(body);\n\n\t// Focus trap + Escape\n\tconst focusableSelector = 'a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n\tfunction handleKeyDown(e: KeyboardEvent) {\n\t\tif (e.key === 'Escape') {\n\t\t\te.preventDefault();\n\t\t\tcloseBtn.click();\n\t\t\treturn;\n\t\t}\n\t\tif (e.key === 'Tab') {\n\t\t\tconst focusable = Array.from(popup.querySelectorAll<HTMLElement>(focusableSelector)).filter(\n\t\t\t\t(el) => el.offsetParent !== null\n\t\t\t);\n\t\t\tif (focusable.length === 0) { e.preventDefault(); return; }\n\t\t\tconst first = focusable[0];\n\t\t\tconst last = focusable[focusable.length - 1];\n\t\t\tif (e.shiftKey && document.activeElement === first) {\n\t\t\t\te.preventDefault();\n\t\t\t\tlast.focus();\n\t\t\t} else if (!e.shiftKey && document.activeElement === last) {\n\t\t\t\te.preventDefault();\n\t\t\t\tfirst.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tpopup.addEventListener('keydown', handleKeyDown);\n\tcloseBtn.addEventListener('click', () => close());\n\n\t// Move focus in on next tick\n\tsetTimeout(() => closeBtn.focus(), 0);\n\n\treturn popup;\n}\n"]}
@@ -4,9 +4,8 @@ export type StimulusSanitizer = (html: string) => string;
4
4
  * Build the effective stimulus content map for an item render.
5
5
  *
6
6
  * Resolved delivery-context content is the package/assessment source of truth.
7
- * Explicit content remains as a compatibility override for older host wiring.
8
7
  */
9
- export declare function buildEffectiveStimulusContent(deliveryContext: ResolvedItemDeliveryContext | undefined, explicitStimulusContent: Record<string, string>, sanitize: StimulusSanitizer): Record<string, string>;
8
+ export declare function buildEffectiveStimulusContent(deliveryContext: ResolvedItemDeliveryContext | undefined, sanitize: StimulusSanitizer): Record<string, string>;
10
9
  /**
11
10
  * Inject shared stimulus bodies at QTI refs or host-authored docking points.
12
11
  *
@@ -2,15 +2,12 @@
2
2
  * Build the effective stimulus content map for an item render.
3
3
  *
4
4
  * Resolved delivery-context content is the package/assessment source of truth.
5
- * Explicit content remains as a compatibility override for older host wiring.
6
5
  */
7
- export function buildEffectiveStimulusContent(deliveryContext, explicitStimulusContent, sanitize) {
8
- const resolved = Object.fromEntries(Object.entries(deliveryContext?.stimuli ?? {}).map(([identifier, stimulus]) => [
6
+ export function buildEffectiveStimulusContent(deliveryContext, sanitize) {
7
+ return Object.fromEntries(Object.entries(deliveryContext?.stimuli ?? {}).map(([identifier, stimulus]) => [
9
8
  identifier,
10
9
  sanitize(stimulus.bodyHtml),
11
10
  ]));
12
- const explicit = Object.fromEntries(Object.entries(explicitStimulusContent).map(([identifier, content]) => [identifier, sanitize(content)]));
13
- return { ...resolved, ...explicit };
14
11
  }
15
12
  /**
16
13
  * Inject shared stimulus bodies at QTI refs or host-authored docking points.
@@ -1 +1 @@
1
- {"version":3,"file":"stimulusRender.js","sourceRoot":"","sources":["../../../src/components/utils/stimulusRender.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC5C,eAAwD,EACxD,uBAA+C,EAC/C,QAA2B;IAE3B,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAClC,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC;QAC9E,UAAU;QACV,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;KAC3B,CAAC,CACF,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAClC,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ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AO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;AAC/F,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACzC,OAAO,KAAK;SACV,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\nexport type StimulusSanitizer = (html: string) => string;\n\n/**\n * Build the effective stimulus content map for an item render.\n *\n * Resolved delivery-context content is the package/assessment source of truth.\n * Explicit content remains as a compatibility override for older host wiring.\n */\nexport function buildEffectiveStimulusContent(\n\tdeliveryContext: ResolvedItemDeliveryContext | undefined,\n\texplicitStimulusContent: Record<string, string>,\n\tsanitize: StimulusSanitizer\n): Record<string, string> {\n\tconst resolved = Object.fromEntries(\n\t\tObject.entries(deliveryContext?.stimuli ?? {}).map(([identifier, stimulus]) => [\n\t\t\tidentifier,\n\t\t\tsanitize(stimulus.bodyHtml),\n\t\t])\n\t);\n\tconst explicit = Object.fromEntries(\n\t\tObject.entries(explicitStimulusContent).map(([identifier, content]) => [identifier, sanitize(content)])\n\t);\n\treturn { ...resolved, ...explicit };\n}\n\n/**\n * Inject shared stimulus bodies at QTI refs or host-authored docking points.\n *\n * Any resolved stimulus that has no matching docking point is prepended in\n * delivery-context order so undocked package content is still visible.\n */\nexport function injectStimulusContent(itemBodyHtml: string, stimulusContent: Record<string, string>): string {\n\tif (Object.keys(stimulusContent).length === 0) return itemBodyHtml;\n\n\tconst docked = new Set<string>();\n\tlet html = itemBodyHtml.replace(\n\t\t/<([a-z][\\w:-]*)([^>]*\\bdata-stimulus-idref=([\"'])([^\"']+)\\3[^>]*)>\\s*<\\/\\1>/gi,\n\t\t(match, tagName, attrs, _quote, identifier) => {\n\t\t\tconst content = stimulusContent[identifier];\n\t\t\tif (!content) return match;\n\t\t\tdocked.add(identifier);\n\t\t\treturn `<${tagName}${mergeClassAttribute(attrs, 'qti-stimulus-dock')}>${content}</${tagName}>`;\n\t\t}\n\t);\n\n\thtml = html.replace(\n\t\t/<qti-assessment-stimulus-ref\\b([^>]*)\\/?>\\s*(?:<\\/qti-assessment-stimulus-ref>)?/gi,\n\t\t(match, attrs) => {\n\t\t\tconst identifier = extractAttribute(attrs, 'identifier');\n\t\t\tif (!identifier) return match;\n\t\t\tif (docked.has(identifier)) return '';\n\t\t\tconst content = stimulusContent[identifier];\n\t\t\tif (!content) return match;\n\t\t\tdocked.add(identifier);\n\t\t\treturn `<div data-stimulus-idref=\"${escapeHtmlAttribute(identifier)}\" class=\"qti-stimulus-dock\">${content}</div>`;\n\t\t}\n\t);\n\n\tconst undocked = Object.entries(stimulusContent)\n\t\t.filter(([identifier]) => !docked.has(identifier))\n\t\t.map(\n\t\t\t([identifier, content]) =>\n\t\t\t\t`<div data-stimulus-idref=\"${escapeHtmlAttribute(identifier)}\" class=\"qti-stimulus-block\">${content}</div>`\n\t\t)\n\t\t.join('');\n\n\treturn undocked ? undocked + html : html;\n}\n\nfunction extractAttribute(attrs: string, name: string): string | null {\n\tconst match = attrs.match(new RegExp(`\\\\b${name}\\\\s*=\\\\s*[\"']([^\"']+)[\"']`, 'i'));\n\treturn match?.[1] ?? null;\n}\n\nfunction mergeClassAttribute(attrs: string, className: string): string {\n\tconst classMatch = attrs.match(/\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/i);\n\tif (!classMatch) return `${attrs} class=\"${className}\"`;\n\tconst quote = classMatch[1]!;\n\tconst existing = classMatch[2] ?? '';\n\tconst classes = new Set(existing.split(/\\s+/).filter(Boolean));\n\tclasses.add(className);\n\treturn attrs.replace(classMatch[0], `class=${quote}${Array.from(classes).join(' ')}${quote}`);\n}\n\nfunction escapeHtmlAttribute(value: string): string {\n\treturn value\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;');\n}\n"]}
1
+ {"version":3,"file":"stimulusRender.js","sourceRoot":"","sources":["../../../src/components/utils/stimulusRender.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAC5C,eAAwD,EACxD,QAA2B;IAE3B,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC;QAC9E,UAAU;QACV,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;KAC3B,CAAC,CACF,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAoB,EAAE,eAAuC;IAClG,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,YAAY,CAAC;IAEnE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,IAAI,IAAI,GAAG,YAAY,CAAC,OAAO,CAC9B,+EAA+E,EAC/E,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvB,OAAO,IAAI,OAAO,GAAG,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,CAAC,IAAI,OAAO,KAAK,OAAO,GAAG,CAAC;IAChG,CAAC,CACD,CAAC;IA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Aa,EAAE,SAAiB;IAC5D,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAClE,IAAI,CAAC,UAAU;QAAE,OAAO,GAAG,KAAK,WAAW,SAAS,GAAG,CAAC;IACxD,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvB,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;AAC/F,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACzC,OAAO,KAAK;SACV,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\nexport type StimulusSanitizer = (html: string) => string;\n\n/**\n * Build the effective stimulus content map for an item render.\n *\n * Resolved delivery-context content is the package/assessment source of truth.\n */\nexport function buildEffectiveStimulusContent(\n\tdeliveryContext: ResolvedItemDeliveryContext | undefined,\n\tsanitize: StimulusSanitizer\n): Record<string, string> {\n\treturn Object.fromEntries(\n\t\tObject.entries(deliveryContext?.stimuli ?? {}).map(([identifier, stimulus]) => [\n\t\t\tidentifier,\n\t\t\tsanitize(stimulus.bodyHtml),\n\t\t])\n\t);\n}\n\n/**\n * Inject shared stimulus bodies at QTI refs or host-authored docking points.\n *\n * Any resolved stimulus that has no matching docking point is prepended in\n * delivery-context order so undocked package content is still visible.\n */\nexport function injectStimulusContent(itemBodyHtml: string, stimulusContent: Record<string, string>): string {\n\tif (Object.keys(stimulusContent).length === 0) return itemBodyHtml;\n\n\tconst docked = new Set<string>();\n\tlet html = itemBodyHtml.replace(\n\t\t/<([a-z][\\w:-]*)([^>]*\\bdata-stimulus-idref=([\"'])([^\"']+)\\3[^>]*)>\\s*<\\/\\1>/gi,\n\t\t(match, tagName, attrs, _quote, identifier) => {\n\t\t\tconst content = stimulusContent[identifier];\n\t\t\tif (!content) return match;\n\t\t\tdocked.add(identifier);\n\t\t\treturn `<${tagName}${mergeClassAttribute(attrs, 'qti-stimulus-dock')}>${content}</${tagName}>`;\n\t\t}\n\t);\n\n\thtml = html.replace(\n\t\t/<qti-assessment-stimulus-ref\\b([^>]*)\\/?>\\s*(?:<\\/qti-assessment-stimulus-ref>)?/gi,\n\t\t(match, attrs) => {\n\t\t\tconst identifier = extractAttribute(attrs, 'identifier');\n\t\t\tif (!identifier) return match;\n\t\t\tif (docked.has(identifier)) return '';\n\t\t\tconst content = stimulusContent[identifier];\n\t\t\tif (!content) return match;\n\t\t\tdocked.add(identifier);\n\t\t\treturn `<div data-stimulus-idref=\"${escapeHtmlAttribute(identifier)}\" class=\"qti-stimulus-dock\">${content}</div>`;\n\t\t}\n\t);\n\n\tconst undocked = Object.entries(stimulusContent)\n\t\t.filter(([identifier]) => !docked.has(identifier))\n\t\t.map(\n\t\t\t([identifier, content]) =>\n\t\t\t\t`<div data-stimulus-idref=\"${escapeHtmlAttribute(identifier)}\" class=\"qti-stimulus-block\">${content}</div>`\n\t\t)\n\t\t.join('');\n\n\treturn undocked ? undocked + html : html;\n}\n\nfunction extractAttribute(attrs: string, name: string): string | null {\n\tconst match = attrs.match(new RegExp(`\\\\b${name}\\\\s*=\\\\s*[\"']([^\"']+)[\"']`, 'i'));\n\treturn match?.[1] ?? null;\n}\n\nfunction mergeClassAttribute(attrs: string, className: string): string {\n\tconst classMatch = attrs.match(/\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/i);\n\tif (!classMatch) return `${attrs} class=\"${className}\"`;\n\tconst quote = classMatch[1]!;\n\tconst existing = classMatch[2] ?? '';\n\tconst classes = new Set(existing.split(/\\s+/).filter(Boolean));\n\tclasses.add(className);\n\treturn attrs.replace(classMatch[0], `class=${quote}${Array.from(classes).join(' ')}${quote}`);\n}\n\nfunction escapeHtmlAttribute(value: string): string {\n\treturn value\n\t\t.replace(/&/g, '&amp;')\n\t\t.replace(/\"/g, '&quot;')\n\t\t.replace(/</g, '&lt;')\n\t\t.replace(/>/g, '&gt;');\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import { type AttributeNameMapper, type ElementNameMapper } from '@pie-qti/qti-common';
2
+ import type { I18nProvider } from '@pie-qti/i18n';
3
+ import type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';
4
+ import type { ProcessingFragmentResolver, QtiValue } from '@pie-qti/qti-processing';
5
+ import { type ExtractionRegistry } from '../extraction/ExtractionRegistry.js';
6
+ import type { PciConfiguration } from '../pci/types.js';
7
+ import type { PnpProfile } from '../pnp/types.js';
8
+ import type { PlayerSecurityConfig, QTIComplianceConfig, QTIRole } from '../types/index.js';
9
+ import type { ComponentRegistry } from './ComponentRegistry.js';
10
+ import { type ItemSession, type OpenItemSessionOptions } from './ItemSession.js';
11
+ /**
12
+ * Synchronous, definition-lifetime extension contract.
13
+ *
14
+ * Definition plugins describe immutable extraction and rendering extensions. Any
15
+ * asynchronous setup must finish before definition construction.
16
+ */
17
+ export interface AssessmentItemDefinitionPlugin {
18
+ readonly kind: 'assessment-item-definition-plugin';
19
+ readonly name: string;
20
+ readonly version: string;
21
+ readonly description?: string;
22
+ readonly dependencies?: readonly string[];
23
+ registerExtractors?(registry: ExtractionRegistry): void;
24
+ registerComponents?(registry: ComponentRegistry): void;
25
+ }
26
+ /**
27
+ * Configuration compiled into an immutable assessment-item definition.
28
+ *
29
+ * Mutable registry instances are deliberately not accepted here. Extensions are
30
+ * described as plugins, applied once to definition-owned registries, then sealed
31
+ * before those registries are shared by live sessions.
32
+ */
33
+ export interface AssessmentItemDefinitionConfig {
34
+ readonly itemXml: string;
35
+ readonly pnp?: PnpProfile;
36
+ readonly catalogXml?: string;
37
+ readonly deliveryContext?: ResolvedItemDeliveryContext;
38
+ readonly role?: QTIRole;
39
+ /** Optional seed for deterministic template-processing random operations. */
40
+ readonly seed?: number;
41
+ readonly elementNameMapper?: ElementNameMapper;
42
+ readonly attributeNameMapper?: AttributeNameMapper;
43
+ readonly i18nProvider?: I18nProvider;
44
+ readonly customOperators?: Readonly<Record<string, (args: QtiValue[], meta: {
45
+ class?: string;
46
+ definition?: string;
47
+ }) => QtiValue>>;
48
+ readonly resolveProcessingFragment?: ProcessingFragmentResolver;
49
+ readonly processingFragmentLimits?: Readonly<{
50
+ /** Maximum nested xi:include depth. Default: 16. */
51
+ maxDepth?: number;
52
+ /** Maximum cumulative XML characters. Default: 2 MiB. */
53
+ maxCharacters?: number;
54
+ }>;
55
+ readonly pci?: PciConfiguration;
56
+ readonly security?: PlayerSecurityConfig;
57
+ readonly strictQtiCompliance?: QTIComplianceConfig;
58
+ readonly plugins?: readonly AssessmentItemDefinitionPlugin[];
59
+ /** Creates an independent random stream for each opened live session. */
60
+ readonly rngFactory?: () => () => number;
61
+ }
62
+ export interface AssessmentItemDefinition {
63
+ readonly identifier: string;
64
+ openSession(options?: OpenItemSessionOptions): ItemSession;
65
+ }
66
+ /**
67
+ * Compile QTI source and immutable delivery configuration into a reusable item definition.
68
+ */
69
+ export declare function createAssessmentItemDefinition(input: AssessmentItemDefinitionConfig): AssessmentItemDefinition;
@@ -0,0 +1,149 @@
1
+ import { Qti2xAttributeNameMapper, Qti2xElementNameMapper, Qti3AttributeNameMapper, Qti3ElementNameMapper, detectQtiVersion, } from '@pie-qti/qti-common';
2
+ import { createExtractionRegistry, registerFrameworkDeliveryFields, } from '../extraction/ExtractionRegistry.js';
3
+ import { getStandardInteractionModules } from '../interactions/modules.js';
4
+ import { createComponentRegistry } from './ComponentRegistry.js';
5
+ import { preparePlayerDefinitionInternal } from './Player.js';
6
+ import { LiveItemSession, } from './ItemSession.js';
7
+ /**
8
+ * Compile QTI source and immutable delivery configuration into a reusable item definition.
9
+ */
10
+ export function createAssessmentItemDefinition(input) {
11
+ return new CompiledAssessmentItemDefinition(input);
12
+ }
13
+ class CompiledAssessmentItemDefinition {
14
+ constructor(input) {
15
+ if (!input.itemXml.trim()) {
16
+ throw new Error('AssessmentItemDefinition requires non-empty itemXml');
17
+ }
18
+ this.rngFactory = input.rngFactory;
19
+ const plugins = input.plugins ? Object.freeze([...input.plugins]) : Object.freeze([]);
20
+ const snapshot = snapshotDefinitionConfig(input);
21
+ const { elementNameMapper, attributeNameMapper } = resolveNameMappers(snapshot);
22
+ const config = compileDefinitionConfig(snapshot, {
23
+ elementNameMapper,
24
+ attributeNameMapper,
25
+ }, plugins);
26
+ this.prepared = preparePlayerDefinitionInternal({ ...config });
27
+ this.identifier = readPreparedIdentifier(this.prepared);
28
+ this.playerConfig = config;
29
+ Object.freeze(this);
30
+ }
31
+ openSession(options = {}) {
32
+ if (options.restore?.itemIdentifier &&
33
+ this.identifier &&
34
+ options.restore.itemIdentifier !== this.identifier) {
35
+ throw new Error(`Cannot restore item session for '${options.restore.itemIdentifier}' into '${this.identifier}'`);
36
+ }
37
+ return new LiveItemSession(this.identifier, createSessionPlayerConfig(this.playerConfig, this.rngFactory), options, this.prepared);
38
+ }
39
+ }
40
+ function readPreparedIdentifier(prepared) {
41
+ if (!prepared ||
42
+ typeof prepared !== 'object' ||
43
+ !('identifier' in prepared) ||
44
+ typeof prepared.identifier !== 'string') {
45
+ throw new Error('AssessmentItemDefinition compilation did not produce an identifier');
46
+ }
47
+ return prepared.identifier;
48
+ }
49
+ function resolveNameMappers(config) {
50
+ if (config.elementNameMapper && config.attributeNameMapper) {
51
+ return {
52
+ elementNameMapper: config.elementNameMapper,
53
+ attributeNameMapper: config.attributeNameMapper,
54
+ };
55
+ }
56
+ const qti3 = detectQtiVersion(config.itemXml ?? '') === '3.0';
57
+ return {
58
+ elementNameMapper: config.elementNameMapper ?? (qti3 ? new Qti3ElementNameMapper() : new Qti2xElementNameMapper()),
59
+ attributeNameMapper: config.attributeNameMapper ??
60
+ (qti3 ? new Qti3AttributeNameMapper() : new Qti2xAttributeNameMapper()),
61
+ };
62
+ }
63
+ function snapshotDefinitionConfig(input) {
64
+ const { plugins, rngFactory, ...baseConfig } = input;
65
+ void plugins;
66
+ void rngFactory;
67
+ const config = {
68
+ ...baseConfig,
69
+ itemXml: input.itemXml,
70
+ ...(input.processingFragmentLimits
71
+ ? { processingFragmentLimits: Object.freeze({ ...input.processingFragmentLimits }) }
72
+ : {}),
73
+ ...(input.pci ? { pci: Object.freeze({ ...input.pci }) } : {}),
74
+ ...(input.customOperators
75
+ ? { customOperators: Object.freeze({ ...input.customOperators }) }
76
+ : {}),
77
+ ...(input.security ? { security: freezePlainSnapshot(input.security) } : {}),
78
+ ...(input.pnp ? { pnp: freezePlainSnapshot(input.pnp) } : {}),
79
+ ...(input.deliveryContext
80
+ ? { deliveryContext: freezePlainSnapshot(input.deliveryContext) }
81
+ : {}),
82
+ };
83
+ return Object.freeze(config);
84
+ }
85
+ function compileDefinitionConfig(config, mappers, plugins) {
86
+ const extractionRegistry = createExtractionRegistry(mappers.elementNameMapper);
87
+ for (const module of getStandardInteractionModules()) {
88
+ extractionRegistry.register(module.extractor);
89
+ registerFrameworkDeliveryFields(extractionRegistry, module.type, module.delivery);
90
+ }
91
+ const componentRegistry = createComponentRegistry();
92
+ const registeredPluginNames = new Set();
93
+ for (const plugin of plugins) {
94
+ validateDefinitionPlugin(plugin, registeredPluginNames);
95
+ plugin.registerExtractors?.(extractionRegistry);
96
+ plugin.registerComponents?.(componentRegistry);
97
+ registeredPluginNames.add(plugin.name);
98
+ }
99
+ extractionRegistry.seal();
100
+ componentRegistry.seal();
101
+ return Object.freeze({
102
+ ...config,
103
+ elementNameMapper: mappers.elementNameMapper,
104
+ attributeNameMapper: mappers.attributeNameMapper,
105
+ extractionRegistry,
106
+ componentRegistry,
107
+ });
108
+ }
109
+ function validateDefinitionPlugin(plugin, registeredPluginNames) {
110
+ if (plugin.kind !== 'assessment-item-definition-plugin') {
111
+ throw new Error(`Definition plugin '${plugin.name || '<unnamed>'}' must declare kind 'assessment-item-definition-plugin'`);
112
+ }
113
+ if (!plugin.name || typeof plugin.name !== 'string') {
114
+ throw new Error('AssessmentItemDefinition plugin must have a valid name');
115
+ }
116
+ if (!/^\d+\.\d+\.\d+/.test(plugin.version)) {
117
+ throw new Error(`Definition plugin '${plugin.name}' has invalid version format: ${plugin.version}`);
118
+ }
119
+ if (registeredPluginNames.has(plugin.name)) {
120
+ throw new Error(`Definition plugin '${plugin.name}' is registered more than once`);
121
+ }
122
+ const missing = (plugin.dependencies ?? []).filter((dependency) => !registeredPluginNames.has(dependency));
123
+ if (missing.length > 0) {
124
+ throw new Error(`Definition plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`);
125
+ }
126
+ }
127
+ function createSessionPlayerConfig(config, rngFactory) {
128
+ return {
129
+ ...config,
130
+ ...(rngFactory ? { rng: rngFactory() } : {}),
131
+ // Give each session a private top-level object while the compiled definition
132
+ // and its sealed extension registries remain shared and immutable.
133
+ };
134
+ }
135
+ function freezePlainSnapshot(value) {
136
+ if (Array.isArray(value)) {
137
+ return Object.freeze(value.map((entry) => freezePlainSnapshot(entry)));
138
+ }
139
+ if (!value || typeof value !== 'object')
140
+ return value;
141
+ if (Object.getPrototypeOf(value) !== Object.prototype)
142
+ return value;
143
+ const snapshot = Object.fromEntries(Object.entries(value).map(([key, entry]) => [
144
+ key,
145
+ freezePlainSnapshot(entry),
146
+ ]));
147
+ return Object.freeze(snapshot);
148
+ }
149
+ //# sourceMappingURL=AssessmentItemDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AssessmentItemDefinition.js","sourceRoot":"","sources":["../../src/core/AssessmentItemDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACN,wBAAwB,EACxB,+BAA+B,GAE/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAS3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACN,eAAe,GAGf,MAAM,kBAAkB,CAAC;AA8D1B;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAC7C,KAAqC;IAErC,OAAO,IAAI,gCAAgC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,gCAAgC;IAMrC,YAAY,KAAqC;QAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QAEnC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACtF,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACjD,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAChF,MAAM,MAAM,GAAG,uBAAuB,CACrC,QAAQ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ributeNameMapper,\n\tQti3ElementNameMapper,\n\tdetectQtiVersion,\n} from '@pie-qti/qti-common';\nimport type { I18nProvider } from '@pie-qti/i18n';\nimport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\nimport type { ProcessingFragmentResolver, QtiValue } from '@pie-qti/qti-processing';\nimport {\n\tcreateExtractionRegistry,\n\tregisterFrameworkDeliveryFields,\n\ttype ExtractionRegistry,\n} from '../extraction/ExtractionRegistry.js';\nimport { getStandardInteractionModules } from '../interactions/modules.js';\nimport type { PciConfiguration } from '../pci/types.js';\nimport type { PnpProfile } from '../pnp/types.js';\nimport type {\n\tItemSessionEngineConfig,\n\tPlayerSecurityConfig,\n\tQTIComplianceConfig,\n\tQTIRole,\n} from '../types/index.js';\nimport { createComponentRegistry } from './ComponentRegistry.js';\nimport type { ComponentRegistry } from './ComponentRegistry.js';\nimport { preparePlayerDefinitionInternal } from './Player.js';\nimport {\n\tLiveItemSession,\n\ttype ItemSession,\n\ttype OpenItemSessionOptions,\n} from './ItemSession.js';\n\n/**\n * Synchronous, definition-lifetime extension contract.\n *\n * Definition plugins describe immutable extraction and rendering extensions. Any\n * asynchronous setup must finish before definition construction.\n */\nexport interface AssessmentItemDefinitionPlugin {\n\treadonly kind: 'assessment-item-definition-plugin';\n\treadonly name: string;\n\treadonly version: string;\n\treadonly description?: string;\n\treadonly dependencies?: readonly string[];\n\tregisterExtractors?(registry: ExtractionRegistry): void;\n\tregisterComponents?(registry: ComponentRegistry): void;\n}\n\n/**\n * Configuration compiled into an immutable assessment-item definition.\n *\n * Mutable registry instances are deliberately not accepted here. Extensions are\n * described as plugins, applied once to definition-owned registries, then sealed\n * before those registries are shared by live sessions.\n */\nexport interface AssessmentItemDefinitionConfig {\n\treadonly itemXml: string;\n\treadonly pnp?: PnpProfile;\n\treadonly catalogXml?: string;\n\treadonly deliveryContext?: ResolvedItemDeliveryContext;\n\treadonly role?: QTIRole;\n\t/** Optional seed for deterministic template-processing random operations. */\n\treadonly seed?: number;\n\treadonly elementNameMapper?: ElementNameMapper;\n\treadonly attributeNameMapper?: AttributeNameMapper;\n\treadonly i18nProvider?: I18nProvider;\n\treadonly customOperators?: Readonly<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t(args: QtiValue[], meta: { class?: string; definition?: string }) => QtiValue\n\t\t>\n\t>;\n\treadonly resolveProcessingFragment?: ProcessingFragmentResolver;\n\treadonly processingFragmentLimits?: Readonly<{\n\t\t/** Maximum nested xi:include depth. Default: 16. */\n\t\tmaxDepth?: number;\n\t\t/** Maximum cumulative XML characters. Default: 2 MiB. */\n\t\tmaxCharacters?: number;\n\t}>;\n\treadonly pci?: PciConfiguration;\n\treadonly security?: PlayerSecurityConfig;\n\treadonly strictQtiCompliance?: QTIComplianceConfig;\n\treadonly plugins?: readonly AssessmentItemDefinitionPlugin[];\n\t/** Creates an independent random stream for each opened live session. */\n\treadonly rngFactory?: () => () => number;\n}\n\nexport interface AssessmentItemDefinition {\n\treadonly identifier: string;\n\topenSession(options?: OpenItemSessionOptions): ItemSession;\n}\n\n/**\n * Compile QTI source and immutable delivery configuration into a reusable item definition.\n */\nexport function createAssessmentItemDefinition(\n\tinput: AssessmentItemDefinitionConfig\n): AssessmentItemDefinition {\n\treturn new CompiledAssessmentItemDefinition(input);\n}\n\nclass CompiledAssessmentItemDefinition implements AssessmentItemDefinition {\n\treadonly identifier: string;\n\tprivate readonly playerConfig: Readonly<ItemSessionEngineConfig>;\n\tprivate readonly prepared: unknown;\n\tprivate readonly rngFactory?: () => () => number;\n\n\tconstructor(input: AssessmentItemDefinitionConfig) {\n\t\tif (!input.itemXml.trim()) {\n\t\t\tthrow new Error('AssessmentItemDefinition requires non-empty itemXml');\n\t\t}\n\t\tthis.rngFactory = input.rngFactory;\n\n\t\tconst plugins = input.plugins ? Object.freeze([...input.plugins]) : Object.freeze([]);\n\t\tconst snapshot = snapshotDefinitionConfig(input);\n\t\tconst { elementNameMapper, attributeNameMapper } = resolveNameMappers(snapshot);\n\t\tconst config = compileDefinitionConfig(\n\t\t\tsnapshot,\n\t\t\t{\n\t\t\t\telementNameMapper,\n\t\t\t\tattributeNameMapper,\n\t\t\t},\n\t\t\tplugins,\n\t\t);\n\t\tthis.prepared = preparePlayerDefinitionInternal({ ...config });\n\t\tthis.identifier = readPreparedIdentifier(this.prepared);\n\t\tthis.playerConfig = config;\n\t\tObject.freeze(this);\n\t}\n\n\topenSession(options: OpenItemSessionOptions = {}): ItemSession {\n\t\tif (\n\t\t\toptions.restore?.itemIdentifier &&\n\t\t\tthis.identifier &&\n\t\t\toptions.restore.itemIdentifier !== this.identifier\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot restore item session for '${options.restore.itemIdentifier}' into '${this.identifier}'`\n\t\t\t);\n\t\t}\n\n\t\treturn new LiveItemSession(\n\t\t\tthis.identifier,\n\t\t\tcreateSessionPlayerConfig(this.playerConfig, this.rngFactory),\n\t\t\toptions,\n\t\t\tthis.prepared,\n\t\t);\n\t}\n}\n\nfunction readPreparedIdentifier(prepared: unknown): string {\n\tif (\n\t\t!prepared ||\n\t\ttypeof prepared !== 'object' ||\n\t\t!('identifier' in prepared) ||\n\t\ttypeof prepared.identifier !== 'string'\n\t) {\n\t\tthrow new Error('AssessmentItemDefinition compilation did not produce an identifier');\n\t}\n\treturn prepared.identifier;\n}\n\nfunction resolveNameMappers(config: Readonly<ItemSessionEngineConfig>) {\n\tif (config.elementNameMapper && config.attributeNameMapper) {\n\t\treturn {\n\t\t\telementNameMapper: config.elementNameMapper,\n\t\t\tattributeNameMapper: config.attributeNameMapper,\n\t\t};\n\t}\n\n\tconst qti3 = detectQtiVersion(config.itemXml ?? '') === '3.0';\n\treturn {\n\t\telementNameMapper:\n\t\t\tconfig.elementNameMapper ?? (qti3 ? new Qti3ElementNameMapper() : new Qti2xElementNameMapper()),\n\t\tattributeNameMapper:\n\t\t\tconfig.attributeNameMapper ??\n\t\t\t(qti3 ? new Qti3AttributeNameMapper() : new Qti2xAttributeNameMapper()),\n\t};\n}\n\nfunction snapshotDefinitionConfig(input: AssessmentItemDefinitionConfig): Readonly<ItemSessionEngineConfig> {\n\tconst { plugins, rngFactory, ...baseConfig } = input;\n\tvoid plugins;\n\tvoid rngFactory;\n\tconst config: ItemSessionEngineConfig = {\n\t\t...baseConfig,\n\t\titemXml: input.itemXml,\n\t\t...(input.processingFragmentLimits\n\t\t\t? { processingFragmentLimits: Object.freeze({ ...input.processingFragmentLimits }) }\n\t\t\t: {}),\n\t\t...(input.pci ? { pci: Object.freeze({ ...input.pci }) } : {}),\n\t\t...(input.customOperators\n\t\t\t? { customOperators: Object.freeze({ ...input.customOperators }) }\n\t\t\t: {}),\n\t\t...(input.security ? { security: freezePlainSnapshot(input.security) } : {}),\n\t\t...(input.pnp ? { pnp: freezePlainSnapshot(input.pnp) } : {}),\n\t\t...(input.deliveryContext\n\t\t\t? { deliveryContext: freezePlainSnapshot(input.deliveryContext) }\n\t\t\t: {}),\n\t};\n\treturn Object.freeze(config);\n}\n\nfunction compileDefinitionConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\tmappers: ReturnType<typeof resolveNameMappers>,\n\tplugins: readonly AssessmentItemDefinitionPlugin[],\n): Readonly<ItemSessionEngineConfig> {\n\tconst extractionRegistry = createExtractionRegistry(mappers.elementNameMapper);\n\tfor (const module of getStandardInteractionModules()) {\n\t\textractionRegistry.register(module.extractor);\n\t\tregisterFrameworkDeliveryFields(extractionRegistry, module.type, module.delivery);\n\t}\n\tconst componentRegistry = createComponentRegistry();\n\n\tconst registeredPluginNames = new Set<string>();\n\tfor (const plugin of plugins) {\n\t\tvalidateDefinitionPlugin(plugin, registeredPluginNames);\n\t\tplugin.registerExtractors?.(extractionRegistry);\n\t\tplugin.registerComponents?.(componentRegistry);\n\t\tregisteredPluginNames.add(plugin.name);\n\t}\n\n\textractionRegistry.seal();\n\tcomponentRegistry.seal();\n\treturn Object.freeze({\n\t\t...config,\n\t\telementNameMapper: mappers.elementNameMapper,\n\t\tattributeNameMapper: mappers.attributeNameMapper,\n\t\textractionRegistry,\n\t\tcomponentRegistry,\n\t});\n}\n\nfunction validateDefinitionPlugin(\n\tplugin: AssessmentItemDefinitionPlugin,\n\tregisteredPluginNames: ReadonlySet<string>,\n): void {\n\tif (plugin.kind !== 'assessment-item-definition-plugin') {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name || '<unnamed>'}' must declare kind 'assessment-item-definition-plugin'`,\n\t\t);\n\t}\n\tif (!plugin.name || typeof plugin.name !== 'string') {\n\t\tthrow new Error('AssessmentItemDefinition plugin must have a valid name');\n\t}\n\tif (!/^\\d+\\.\\d+\\.\\d+/.test(plugin.version)) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has invalid version format: ${plugin.version}`,\n\t\t);\n\t}\n\tif (registeredPluginNames.has(plugin.name)) {\n\t\tthrow new Error(`Definition plugin '${plugin.name}' is registered more than once`);\n\t}\n\tconst missing = (plugin.dependencies ?? []).filter(\n\t\t(dependency) => !registeredPluginNames.has(dependency),\n\t);\n\tif (missing.length > 0) {\n\t\tthrow new Error(\n\t\t\t`Definition plugin '${plugin.name}' has missing dependencies: ${missing.join(', ')}`,\n\t\t);\n\t}\n}\n\nfunction createSessionPlayerConfig(\n\tconfig: Readonly<ItemSessionEngineConfig>,\n\trngFactory?: () => () => number,\n): ItemSessionEngineConfig {\n\treturn {\n\t\t...config,\n\t\t...(rngFactory ? { rng: rngFactory() } : {}),\n\t\t// Give each session a private top-level object while the compiled definition\n\t\t// and its sealed extension registries remain shared and immutable.\n\t};\n}\n\nfunction freezePlainSnapshot<T>(value: T): T {\n\tif (Array.isArray(value)) {\n\t\treturn Object.freeze(value.map((entry) => freezePlainSnapshot(entry))) as T;\n\t}\n\tif (!value || typeof value !== 'object') return value;\n\tif (Object.getPrototypeOf(value) !== Object.prototype) return value;\n\n\tconst snapshot = Object.fromEntries(\n\t\tObject.entries(value as Record<string, unknown>).map(([key, entry]) => [\n\t\t\tkey,\n\t\t\tfreezePlainSnapshot(entry),\n\t\t])\n\t);\n\treturn Object.freeze(snapshot) as T;\n}\n"]}
@@ -5,11 +5,11 @@
5
5
  * different QTI interaction types. Uses priority-based dispatch similar to the
6
6
  * ExtractionRegistry, but for framework-agnostic web components.
7
7
  */
8
- import type { InteractionData } from '../interactions/index.js';
8
+ import type { BaseInteractionData } from '../interactions/shared/types.js';
9
9
  /**
10
10
  * Configuration for registering a web component renderer
11
11
  */
12
- export interface ComponentConfig<TData extends InteractionData = InteractionData> {
12
+ export interface ComponentConfig<TData extends BaseInteractionData = BaseInteractionData> {
13
13
  /** Unique name for this renderer (e.g., 'rating-choice', 'standard-choice') */
14
14
  name: string;
15
15
  /**
@@ -52,6 +52,7 @@ export interface ComponentConfig<TData extends InteractionData = InteractionData
52
52
  export declare class ComponentRegistry {
53
53
  private components;
54
54
  private definedElements;
55
+ private sealed;
55
56
  /**
56
57
  * Register a web component for an interaction type with priority-based dispatch
57
58
  *
@@ -76,8 +77,9 @@ export declare class ComponentRegistry {
76
77
  * tagName: 'qti-choice-interaction'
77
78
  * });
78
79
  */
79
- register<TData extends InteractionData>(type: string, config: ComponentConfig<TData>): void;
80
+ register<TData extends BaseInteractionData>(type: string, config: ComponentConfig<TData>): void;
80
81
  private createRegisteredComponent;
82
+ private ensureCustomElementDefined;
81
83
  /**
82
84
  * Get a web component tag name for an interaction type
83
85
  * Evaluates canHandle predicates in priority order
@@ -86,7 +88,7 @@ export declare class ComponentRegistry {
86
88
  * @returns Web component tag name (e.g., 'qti-choice-interaction')
87
89
  * @throws Error if no component matches
88
90
  */
89
- getTagName<TData extends InteractionData>(data: TData): string;
91
+ getTagName<TData extends BaseInteractionData>(data: TData): string;
90
92
  /**
91
93
  * Get all registered interaction types
92
94
  * @returns Array of registered interaction type names
@@ -99,12 +101,16 @@ export declare class ComponentRegistry {
99
101
  /**
100
102
  * Get the tag name for a registered type by name (no canHandle evaluation).
101
103
  * Useful for non-interaction components like catalogPopup where the type string
102
- * is known and there is no InteractionData object to pass.
104
+ * is known and there is no delivered interaction object to pass.
103
105
  *
104
106
  * Returns the highest-priority registered tag name for the type, or null if
105
107
  * the type is not registered.
106
108
  */
107
109
  getTagNameForType(type: string): string | null;
110
+ /** Freeze renderer selection for a compiled AssessmentItem definition. */
111
+ seal(): this;
112
+ isSealed(): boolean;
113
+ private assertMutable;
108
114
  }
109
115
  /**
110
116
  * Create a new component registry
@@ -35,6 +35,7 @@ export class ComponentRegistry {
35
35
  constructor() {
36
36
  this.components = new Map();
37
37
  this.definedElements = new Set();
38
+ this.sealed = false;
38
39
  }
39
40
  /**
40
41
  * Register a web component for an interaction type with priority-based dispatch
@@ -61,20 +62,16 @@ export class ComponentRegistry {
61
62
  * });
62
63
  */
63
64
  register(type, config) {
65
+ this.assertMutable();
64
66
  // Validate tag name
65
67
  if (!config.tagName.includes('-')) {
66
68
  throw new Error(`Invalid tag name '${config.tagName}'. ` +
67
69
  `Web component tag names must contain a hyphen.`);
68
70
  }
69
- // Auto-register custom element if requested
70
- if (config.componentClass && config.autoRegister !== false) {
71
- if (!this.definedElements.has(config.tagName)) {
72
- if (!customElements.get(config.tagName)) {
73
- customElements.define(config.tagName, config.componentClass);
74
- }
75
- this.definedElements.add(config.tagName);
76
- }
77
- }
71
+ const registered = this.createRegisteredComponent(config);
72
+ // Define eagerly in a browser. In a headless compiler there is no custom
73
+ // element registry, so registration is deferred until the renderer is used.
74
+ this.ensureCustomElementDefined(registered.config);
78
75
  // Get or create component array for this type
79
76
  let components = this.components.get(type);
80
77
  if (!components) {
@@ -82,17 +79,31 @@ export class ComponentRegistry {
82
79
  this.components.set(type, components);
83
80
  }
84
81
  // Add normalized component and sort by priority (highest first)
85
- components.push(this.createRegisteredComponent(config));
82
+ components.push(registered);
86
83
  components.sort((a, b) => b.config.priority - a.config.priority);
87
84
  }
88
85
  createRegisteredComponent(config) {
89
- return {
90
- config: {
86
+ return Object.freeze({
87
+ config: Object.freeze({
91
88
  ...config,
92
89
  priority: config.priority ?? 0,
93
- canHandle: config.canHandle ?? (() => true),
94
- },
95
- };
90
+ canHandle: config.canHandle?.bind(config) ?? (() => true),
91
+ }),
92
+ });
93
+ }
94
+ ensureCustomElementDefined(config) {
95
+ if (!config.componentClass ||
96
+ config.autoRegister === false ||
97
+ this.definedElements.has(config.tagName)) {
98
+ return;
99
+ }
100
+ const registry = globalThis.customElements;
101
+ if (!registry)
102
+ return;
103
+ if (!registry.get(config.tagName)) {
104
+ registry.define(config.tagName, config.componentClass);
105
+ }
106
+ this.definedElements.add(config.tagName);
96
107
  }
97
108
  /**
98
109
  * Get a web component tag name for an interaction type
@@ -112,6 +123,7 @@ export class ComponentRegistry {
112
123
  for (const { config } of components) {
113
124
  try {
114
125
  if (config.canHandle(data)) {
126
+ this.ensureCustomElementDefined(config);
115
127
  return config.tagName;
116
128
  }
117
129
  }
@@ -147,7 +159,7 @@ export class ComponentRegistry {
147
159
  /**
148
160
  * Get the tag name for a registered type by name (no canHandle evaluation).
149
161
  * Useful for non-interaction components like catalogPopup where the type string
150
- * is known and there is no InteractionData object to pass.
162
+ * is known and there is no delivered interaction object to pass.
151
163
  *
152
164
  * Returns the highest-priority registered tag name for the type, or null if
153
165
  * the type is not registered.
@@ -156,7 +168,22 @@ export class ComponentRegistry {
156
168
  const components = this.components.get(type);
157
169
  if (!components || components.length === 0)
158
170
  return null;
159
- return components[0].config.tagName;
171
+ const config = components[0].config;
172
+ this.ensureCustomElementDefined(config);
173
+ return config.tagName;
174
+ }
175
+ /** Freeze renderer selection for a compiled AssessmentItem definition. */
176
+ seal() {
177
+ this.sealed = true;
178
+ return this;
179
+ }
180
+ isSealed() {
181
+ return this.sealed;
182
+ }
183
+ assertMutable() {
184
+ if (this.sealed) {
185
+ throw new Error('ComponentRegistry is sealed for this AssessmentItem; create a new definition to change renderers');
186
+ }
160
187
  }
161
188
  }
162
189
  /**