@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
@@ -0,0 +1,35 @@
1
+ import type { TextEntryInteractionData } from '../shared/types.js';
2
+ /**
3
+ * Whether an XSD regular expression cannot match any string containing `-`.
4
+ *
5
+ * Phone number pads offer no minus key, so only a patternMask that provably
6
+ * excludes `-` makes it safe to hand an integer or float response a numeric
7
+ * keyboard; every other answer keeps the default text keyboard (see
8
+ * {@link textEntryInputMode}).
9
+ *
10
+ * The scan reads the pattern structurally: a `-` can come from a literal
11
+ * (escaped or not), a character range whose endpoints straddle it, a wildcard
12
+ * `.`, a negated or complemented class, or a complement or Unicode-category
13
+ * escape (`\D`, `\P`, `\p{Pd}`); the digit, word and space classes (`\d`, `\w`,
14
+ * `\s`) hold no `-`. Anything the scan cannot rule out counts as able to
15
+ * produce a `-`.
16
+ */
17
+ export declare function patternExcludesMinus(pattern: string): boolean;
18
+ /**
19
+ * The index just past a character class that cannot match `-`, or `undefined`
20
+ * when the class is unbalanced or holds a member or range that can.
21
+ *
22
+ * Shared with {@link patternExcludesMinus}'s consumers (inline text entry and
23
+ * extended text), which is why it is exported.
24
+ */
25
+ export declare function classExcludesMinus(pattern: string, open: number): number | undefined;
26
+ /**
27
+ * The `inputmode` for a text entry bound to a response: a numeric keyboard only
28
+ * for an integer or float response whose authored patternMask proves the answer
29
+ * cannot be negative, since phone number pads offer no minus key (nor an
30
+ * exponent). A declared non-decimal `base` (e.g. 16 or 2) also keeps the text
31
+ * keyboard: number pads cannot type its digits (hex `A`–`F`). Every other
32
+ * response keeps the default text keyboard, which can enter anything the item
33
+ * accepts.
34
+ */
35
+ export declare function textEntryInputMode(interaction: Pick<TextEntryInteractionData, 'baseType' | 'patternMask' | 'base'>): 'numeric' | 'decimal' | undefined;
@@ -0,0 +1,134 @@
1
+ /** The code point of `-`, the character a negative answer needs. */
2
+ const MINUS = 0x2d;
3
+ /**
4
+ * Whether an XSD regular expression cannot match any string containing `-`.
5
+ *
6
+ * Phone number pads offer no minus key, so only a patternMask that provably
7
+ * excludes `-` makes it safe to hand an integer or float response a numeric
8
+ * keyboard; every other answer keeps the default text keyboard (see
9
+ * {@link textEntryInputMode}).
10
+ *
11
+ * The scan reads the pattern structurally: a `-` can come from a literal
12
+ * (escaped or not), a character range whose endpoints straddle it, a wildcard
13
+ * `.`, a negated or complemented class, or a complement or Unicode-category
14
+ * escape (`\D`, `\P`, `\p{Pd}`); the digit, word and space classes (`\d`, `\w`,
15
+ * `\s`) hold no `-`. Anything the scan cannot rule out counts as able to
16
+ * produce a `-`.
17
+ */
18
+ export function patternExcludesMinus(pattern) {
19
+ let index = 0;
20
+ while (index < pattern.length) {
21
+ const char = pattern[index];
22
+ if (char === '\\') {
23
+ const escaped = pattern[index + 1];
24
+ // A trailing backslash matches nothing: keep the text keyboard.
25
+ if (escaped === undefined)
26
+ return false;
27
+ if ('dsw'.includes(escaped)) {
28
+ index += 2;
29
+ continue;
30
+ }
31
+ if ('DSWP'.includes(escaped) || escaped === 'p' || escaped === '-')
32
+ return false;
33
+ index += 2;
34
+ continue;
35
+ }
36
+ if (char === '[') {
37
+ const after = classExcludesMinus(pattern, index);
38
+ if (after === undefined)
39
+ return false;
40
+ index = after;
41
+ continue;
42
+ }
43
+ // A wildcard matches `-`; a literal `-` matches itself. Quantifiers, groups,
44
+ // anchors and ordinary letters or digits never introduce one.
45
+ if (char === '-' || char === '.')
46
+ return false;
47
+ index += 1;
48
+ }
49
+ return true;
50
+ }
51
+ /**
52
+ * The index just past a character class that cannot match `-`, or `undefined`
53
+ * when the class is unbalanced or holds a member or range that can.
54
+ *
55
+ * Shared with {@link patternExcludesMinus}'s consumers (inline text entry and
56
+ * extended text), which is why it is exported.
57
+ */
58
+ export function classExcludesMinus(pattern, open) {
59
+ let index = open + 1;
60
+ // A negated class matches everything its members do not, `-` included.
61
+ if (pattern[index] === '^')
62
+ return undefined;
63
+ while (index < pattern.length && pattern[index] !== ']') {
64
+ let member;
65
+ const char = pattern[index];
66
+ if (char === '\\') {
67
+ const escaped = pattern[index + 1];
68
+ if (escaped === undefined)
69
+ return undefined;
70
+ // Classes (`\d`, `\w`, `\s`) hold no `-`; ranges from them are out of scope.
71
+ if ('dsw'.includes(escaped)) {
72
+ index += 2;
73
+ continue;
74
+ }
75
+ if ('DSWP'.includes(escaped) || escaped === 'p')
76
+ return undefined;
77
+ member = escaped.charCodeAt(0);
78
+ index += 2;
79
+ }
80
+ else {
81
+ member = char.codePointAt(0);
82
+ index += 1;
83
+ }
84
+ if (member === MINUS)
85
+ return undefined;
86
+ // A range `a-b`, unless the `-` is itself a member (`[a-]`, handled above
87
+ // on the next turn) or the class closes after it.
88
+ if (pattern[index] === '-' && pattern[index + 1] !== ']') {
89
+ index += 1;
90
+ const next = pattern[index];
91
+ if (next === undefined)
92
+ return undefined;
93
+ let end;
94
+ if (next === '\\') {
95
+ const escaped = pattern[index + 1];
96
+ if (escaped === undefined || 'DSWP'.includes(escaped) || escaped === 'p')
97
+ return undefined;
98
+ if ('dsw'.includes(escaped))
99
+ return undefined;
100
+ end = escaped.charCodeAt(0);
101
+ index += 2;
102
+ }
103
+ else {
104
+ end = next.codePointAt(0);
105
+ index += 1;
106
+ }
107
+ if (member <= MINUS && MINUS <= end)
108
+ return undefined;
109
+ }
110
+ }
111
+ // Unbalanced: the class never closes.
112
+ if (index >= pattern.length)
113
+ return undefined;
114
+ return index + 1;
115
+ }
116
+ /**
117
+ * The `inputmode` for a text entry bound to a response: a numeric keyboard only
118
+ * for an integer or float response whose authored patternMask proves the answer
119
+ * cannot be negative, since phone number pads offer no minus key (nor an
120
+ * exponent). A declared non-decimal `base` (e.g. 16 or 2) also keeps the text
121
+ * keyboard: number pads cannot type its digits (hex `A`–`F`). Every other
122
+ * response keeps the default text keyboard, which can enter anything the item
123
+ * accepts.
124
+ */
125
+ export function textEntryInputMode(interaction) {
126
+ if (interaction.baseType !== 'integer' && interaction.baseType !== 'float')
127
+ return undefined;
128
+ if (interaction.base !== undefined && interaction.base !== 10)
129
+ return undefined;
130
+ if (!interaction.patternMask || !patternExcludesMinus(interaction.patternMask))
131
+ return undefined;
132
+ return interaction.baseType === 'integer' ? 'numeric' : 'decimal';
133
+ }
134
+ //# sourceMappingURL=inputMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputMode.js","sourceRoot":"","sources":["../../../src/interactions/text-entry/inputMode.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,MAAM,KAAK,GAAG,IAAI,CAAC;AAEnB;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IACnD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YACnC,gEAAgE;YAChE,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACxC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7B,KAAK,IAAI,CAAC,CAAC;gBACX,SAAS;YACV,CAAC;YACD,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAC;YACjF,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACV,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACtC,KAAK,GAAG,KAAK,CAAC;YACd,SAAS;QACV,CAAC;QACD,6EAA6E;QAC7E,8DAA8D;QAC9D,IAAI,IAAI,KAAK,G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,CAAC,IAAI,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAChF,IAAI,CAAC,WAAW,CAAC,WAAW,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IACjG,OAAO,WAAW,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC","sourcesContent":["import type { TextEntryInteractionData } from '../shared/types.js';\n\n/** The code point of `-`, the character a negative answer needs. */\nconst MINUS = 0x2d;\n\n/**\n * Whether an XSD regular expression cannot match any string containing `-`.\n *\n * Phone number pads offer no minus key, so only a patternMask that provably\n * excludes `-` makes it safe to hand an integer or float response a numeric\n * keyboard; every other answer keeps the default text keyboard (see\n * {@link textEntryInputMode}).\n *\n * The scan reads the pattern structurally: a `-` can come from a literal\n * (escaped or not), a character range whose endpoints straddle it, a wildcard\n * `.`, a negated or complemented class, or a complement or Unicode-category\n * escape (`\\D`, `\\P`, `\\p{Pd}`); the digit, word and space classes (`\\d`, `\\w`,\n * `\\s`) hold no `-`. Anything the scan cannot rule out counts as able to\n * produce a `-`.\n */\nexport function patternExcludesMinus(pattern: string): boolean {\n\tlet index = 0;\n\twhile (index < pattern.length) {\n\t\tconst char = pattern[index];\n\t\tif (char === '\\\\') {\n\t\t\tconst escaped = pattern[index + 1];\n\t\t\t// A trailing backslash matches nothing: keep the text keyboard.\n\t\t\tif (escaped === undefined) return false;\n\t\t\tif ('dsw'.includes(escaped)) {\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ('DSWP'.includes(escaped) || escaped === 'p' || escaped === '-') return false;\n\t\t\tindex += 2;\n\t\t\tcontinue;\n\t\t}\n\t\tif (char === '[') {\n\t\t\tconst after = classExcludesMinus(pattern, index);\n\t\t\tif (after === undefined) return false;\n\t\t\tindex = after;\n\t\t\tcontinue;\n\t\t}\n\t\t// A wildcard matches `-`; a literal `-` matches itself. Quantifiers, groups,\n\t\t// anchors and ordinary letters or digits never introduce one.\n\t\tif (char === '-' || char === '.') return false;\n\t\tindex += 1;\n\t}\n\treturn true;\n}\n\n/**\n * The index just past a character class that cannot match `-`, or `undefined`\n * when the class is unbalanced or holds a member or range that can.\n *\n * Shared with {@link patternExcludesMinus}'s consumers (inline text entry and\n * extended text), which is why it is exported.\n */\nexport function classExcludesMinus(pattern: string, open: number): number | undefined {\n\tlet index = open + 1;\n\t// A negated class matches everything its members do not, `-` included.\n\tif (pattern[index] === '^') return undefined;\n\twhile (index < pattern.length && pattern[index] !== ']') {\n\t\tlet member: number;\n\t\tconst char = pattern[index];\n\t\tif (char === '\\\\') {\n\t\t\tconst escaped = pattern[index + 1];\n\t\t\tif (escaped === undefined) return undefined;\n\t\t\t// Classes (`\\d`, `\\w`, `\\s`) hold no `-`; ranges from them are out of scope.\n\t\t\tif ('dsw'.includes(escaped)) {\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif ('DSWP'.includes(escaped) || escaped === 'p') return undefined;\n\t\t\tmember = escaped.charCodeAt(0);\n\t\t\tindex += 2;\n\t\t} else {\n\t\t\tmember = char.codePointAt(0) as number;\n\t\t\tindex += 1;\n\t\t}\n\t\tif (member === MINUS) return undefined;\n\t\t// A range `a-b`, unless the `-` is itself a member (`[a-]`, handled above\n\t\t// on the next turn) or the class closes after it.\n\t\tif (pattern[index] === '-' && pattern[index + 1] !== ']') {\n\t\t\tindex += 1;\n\t\t\tconst next = pattern[index];\n\t\t\tif (next === undefined) return undefined;\n\t\t\tlet end: number;\n\t\t\tif (next === '\\\\') {\n\t\t\t\tconst escaped = pattern[index + 1];\n\t\t\t\tif (escaped === undefined || 'DSWP'.includes(escaped) || escaped === 'p') return undefined;\n\t\t\t\tif ('dsw'.includes(escaped)) return undefined;\n\t\t\t\tend = escaped.charCodeAt(0);\n\t\t\t\tindex += 2;\n\t\t\t} else {\n\t\t\t\tend = next.codePointAt(0) as number;\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t\tif (member <= MINUS && MINUS <= end) return undefined;\n\t\t}\n\t}\n\t// Unbalanced: the class never closes.\n\tif (index >= pattern.length) return undefined;\n\treturn index + 1;\n}\n\n/**\n * The `inputmode` for a text entry bound to a response: a numeric keyboard only\n * for an integer or float response whose authored patternMask proves the answer\n * cannot be negative, since phone number pads offer no minus key (nor an\n * exponent). A declared non-decimal `base` (e.g. 16 or 2) also keeps the text\n * keyboard: number pads cannot type its digits (hex `A`–`F`). Every other\n * response keeps the default text keyboard, which can enter anything the item\n * accepts.\n */\nexport function textEntryInputMode(\n\tinteraction: Pick<TextEntryInteractionData, 'baseType' | 'patternMask' | 'base'>,\n): 'numeric' | 'decimal' | undefined {\n\tif (interaction.baseType !== 'integer' && interaction.baseType !== 'float') return undefined;\n\tif (interaction.base !== undefined && interaction.base !== 10) return undefined;\n\tif (!interaction.patternMask || !patternExcludesMinus(interaction.patternMask)) return undefined;\n\treturn interaction.baseType === 'integer' ? 'numeric' : 'decimal';\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { TextEntryInteractionData } from '../shared/types.js';
2
+ /**
3
+ * The response a textEntryInteraction's `stringIdentifier` names (QTI ASI §5.122.3,
4
+ * `string-identifier` in QTI 3.0), or undefined when none is authored or it repeats the
5
+ * interaction's own response: the companion cannot be the response it captures text for.
6
+ */
7
+ export declare function textEntryStringIdentifier(interaction: Pick<TextEntryInteractionData, 'responseId' | 'stringIdentifier'>): string | undefined;
8
+ /**
9
+ * The value of the companion response `stringIdentifier` names: the text the candidate entered,
10
+ * before a numeric response reads it — "3.50" where the float response is 3.5, "101" where a
11
+ * base-2 integer response is 5 — or NULL when the field is empty. A value that already is a
12
+ * number (written by a host, not typed) is spelled in the interaction's base, as
13
+ * extendedTextInteraction shows one.
14
+ */
15
+ export declare function createTextEntryStringResponse(value: unknown, interaction: Pick<TextEntryInteractionData, 'base'>): string | null;
@@ -0,0 +1,25 @@
1
+ import { extendedTextResponseToStrings } from '../extended-text/response.js';
2
+ /**
3
+ * The response a textEntryInteraction's `stringIdentifier` names (QTI ASI §5.122.3,
4
+ * `string-identifier` in QTI 3.0), or undefined when none is authored or it repeats the
5
+ * interaction's own response: the companion cannot be the response it captures text for.
6
+ */
7
+ export function textEntryStringIdentifier(interaction) {
8
+ const { stringIdentifier } = interaction;
9
+ return stringIdentifier && stringIdentifier !== interaction.responseId ? stringIdentifier : undefined;
10
+ }
11
+ /**
12
+ * The value of the companion response `stringIdentifier` names: the text the candidate entered,
13
+ * before a numeric response reads it — "3.50" where the float response is 3.5, "101" where a
14
+ * base-2 integer response is 5 — or NULL when the field is empty. A value that already is a
15
+ * number (written by a host, not typed) is spelled in the interaction's base, as
16
+ * extendedTextInteraction shows one.
17
+ */
18
+ export function createTextEntryStringResponse(value, interaction) {
19
+ const [text = ''] = extendedTextResponseToStrings(value, {
20
+ cardinality: 'single',
21
+ base: interaction.base ?? 10,
22
+ });
23
+ return text.trim().length > 0 ? text : null;
24
+ }
25
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/interactions/text-entry/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAG7E;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,WAA8E;IAE9E,MAAM,EAAE,gBAAgB,EAAE,GAAG,WAAW,CAAC;IACzC,OAAO,gBAAgB,IAAI,gBAAgB,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;AACvG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAC5C,KAAc,EACd,WAAmD;IAEnD,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,6BAA6B,CAAC,KAAK,EAAE;QACxD,WAAW,EAAE,QAAQ;QACrB,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,EAAE;KAC5B,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC","sourcesContent":["import { extendedTextResponseToStrings } from '../extended-text/response.js';\nimport type { TextEntryInteractionData } from '../shared/types.js';\n\n/**\n * The response a textEntryInteraction's `stringIdentifier` names (QTI ASI §5.122.3,\n * `string-identifier` in QTI 3.0), or undefined when none is authored or it repeats the\n * interaction's own response: the companion cannot be the response it captures text for.\n */\nexport function textEntryStringIdentifier(\n\tinteraction: Pick<TextEntryInteractionData, 'responseId' | 'stringIdentifier'>,\n): string | undefined {\n\tconst { stringIdentifier } = interaction;\n\treturn stringIdentifier && stringIdentifier !== interaction.responseId ? stringIdentifier : undefined;\n}\n\n/**\n * The value of the companion response `stringIdentifier` names: the text the candidate entered,\n * before a numeric response reads it — \"3.50\" where the float response is 3.5, \"101\" where a\n * base-2 integer response is 5 — or NULL when the field is empty. A value that already is a\n * number (written by a host, not typed) is spelled in the interaction's base, as\n * extendedTextInteraction shows one.\n */\nexport function createTextEntryStringResponse(\n\tvalue: unknown,\n\tinteraction: Pick<TextEntryInteractionData, 'base'>,\n): string | null {\n\tconst [text = ''] = extendedTextResponseToStrings(value, {\n\t\tcardinality: 'single',\n\t\tbase: interaction.base ?? 10,\n\t});\n\treturn text.trim().length > 0 ? text : null;\n}\n"]}
@@ -19,10 +19,10 @@ export const standardUploadExtractor = {
19
19
  },
20
20
  extract(element, context) {
21
21
  const { utils } = context;
22
- // Extract fileType child elements (vendor / QTI 3.0 style)
22
+ // <fileType> children are a vendor form; neither QTI 2.1 nor 3.0 defines them.
23
23
  const fileTypeElements = utils.getChildrenByTag(element, 'fileType');
24
24
  let fileTypes = fileTypeElements.map((el) => utils.getTextContent(el));
25
- // Fall back to QTI 2.x `type` attribute when no <fileType> children are present
25
+ // QTI's own restriction is the `type` attribute: one MIME type in 2.1, a list in 3.0 (§5.165.1).
26
26
  if (fileTypes.length === 0) {
27
27
  const typeAttr = utils.getAttribute(element, 'type', '');
28
28
  if (typeAttr) {
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/upload/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAiC;IACpE,EAAE,EAAE,wBAAwB;IAC5B,IAAI,EAAE,iCAAiC;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,mBAAmB,CAAC;IACnC,WAAW,EAAE,uDAAuD;IAEpE,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,8CAA8C;QAC9C,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,2DAA2D;QAC3D,MAAM,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACrE,IAAI,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;QAEvE,gFAAgF;QAChF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;YACzD,IAAI,QAAQ,EAAE,CAAC;gBACd,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACnD,CAAC;QACF,CAAC;QAED,yBAAyB;QACzB,MAAM,aAAa,GAA2B,EAAE,CAAC;QACjD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/D,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;QAED,4BAA4B;QAC5B,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1F,OAAO;YACN,SAAS;YACT,aAAa;YACb,MAAM;SACN,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI;QACZ,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpD,QAAQ,CAAC,IAAI,CAAC,qEAAqE,CAAC,CAAC;QACtF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,IAAI;YACX,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 uploadInteraction extractor\n *\n * Extracts data from uploadInteraction elements (file upload)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\n\n/**\n * Upload data extracted from uploadInteraction elements\n */\nexport interface UploadData {\n\tfileTypes: string[];\n\trawAttributes: Record<string, string>;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI upload interaction extractor\n * Handles uploadInteraction elements (file upload)\n */\nexport const standardUploadExtractor: ElementExtractor<UploadData> = {\n\tid: 'qti:upload-interaction',\n\tname: 'QTI Standard Upload Interaction',\n\tpriority: 10,\n\telementTypes: ['uploadInteraction'],\n\tdescription: 'Extracts standard QTI uploadInteraction (file upload)',\n\n\tcanHandle(element, context) {\n\t\t// All uploadInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'uploadInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract fileType child elements (vendor / QTI 3.0 style)\n\t\tconst fileTypeElements = utils.getChildrenByTag(element, 'fileType');\n\t\tlet fileTypes = fileTypeElements.map((el) => utils.getTextContent(el));\n\n\t\t// Fall back to QTI 2.x `type` attribute when no <fileType> children are present\n\t\tif (fileTypes.length === 0) {\n\t\t\tconst typeAttr = utils.getAttribute(element, 'type', '');\n\t\t\tif (typeAttr) {\n\t\t\t\tfileTypes = typeAttr.split(/\\s+/).filter(Boolean);\n\t\t\t}\n\t\t}\n\n\t\t// Extract all attributes\n\t\tconst rawAttributes: Record<string, string> = {};\n\t\tif (element.attributes) {\n\t\t\tfor (const [key, value] of Object.entries(element.attributes)) {\n\t\t\t\trawAttributes[key] = String(value);\n\t\t\t}\n\t\t}\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\tfileTypes,\n\t\t\trawAttributes,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst warnings: string[] = [];\n\n\t\t// Warn if no file type restrictions\n\t\tif (!data.fileTypes || data.fileTypes.length === 0) {\n\t\t\twarnings.push('uploadInteraction has no fileTypes - any file type will be accepted');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
1
+ {"version":3,"file":"extractor.js","sourceRoot":"","sources":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,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;QAED,4BAA4B;QAC5B,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1F,OAAO;YACN,SAAS;YACT,aAAa;YACb,MAAM;SACN,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI;QACZ,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpD,QAAQ,CAAC,IAAI,CAAC,qEAAqE,CAAC,CAAC;QACtF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,IAAI;YACX,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 uploadInteraction extractor\n *\n * Extracts data from uploadInteraction elements (file upload)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\n\n/**\n * Upload data extracted from uploadInteraction elements\n */\nexport interface UploadData {\n\tfileTypes: string[];\n\trawAttributes: Record<string, string>;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI upload interaction extractor\n * Handles uploadInteraction elements (file upload)\n */\nexport const standardUploadExtractor: ElementExtractor<UploadData> = {\n\tid: 'qti:upload-interaction',\n\tname: 'QTI Standard Upload Interaction',\n\tpriority: 10,\n\telementTypes: ['uploadInteraction'],\n\tdescription: 'Extracts standard QTI uploadInteraction (file upload)',\n\n\tcanHandle(element, context) {\n\t\t// All uploadInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'uploadInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// <fileType> children are a vendor form; neither QTI 2.1 nor 3.0 defines them.\n\t\tconst fileTypeElements = utils.getChildrenByTag(element, 'fileType');\n\t\tlet fileTypes = fileTypeElements.map((el) => utils.getTextContent(el));\n\n\t\t// QTI's own restriction is the `type` attribute: one MIME type in 2.1, a list in 3.0 (§5.165.1).\n\t\tif (fileTypes.length === 0) {\n\t\t\tconst typeAttr = utils.getAttribute(element, 'type', '');\n\t\t\tif (typeAttr) {\n\t\t\t\tfileTypes = typeAttr.split(/\\s+/).filter(Boolean);\n\t\t\t}\n\t\t}\n\n\t\t// Extract all attributes\n\t\tconst rawAttributes: Record<string, string> = {};\n\t\tif (element.attributes) {\n\t\t\tfor (const [key, value] of Object.entries(element.attributes)) {\n\t\t\t\trawAttributes[key] = String(value);\n\t\t\t}\n\t\t}\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\tfileTypes,\n\t\t\trawAttributes,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst warnings: string[] = [];\n\n\t\t// Warn if no file type restrictions\n\t\tif (!data.fileTypes || data.fileTypes.length === 0) {\n\t\t\twarnings.push('uploadInteraction has no fileTypes - any file type will be accepted');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
@@ -56,7 +56,7 @@ export declare class PciHost implements PciHostController {
56
56
  private readonly _responseChangeListeners;
57
57
  private readonly _remountRequestListeners;
58
58
  private readonly _errorListeners;
59
- constructor(data: ExtractedPci, options?: PciHostOptions | string);
59
+ constructor(data: ExtractedPci, options?: PciHostOptions);
60
60
  /**
61
61
  * Register a callback to fire when the PCI's response changes. The player calls
62
62
  * this to wire the PCI into its internal response map. Values arrive in the
@@ -49,21 +49,21 @@ export class PciHost {
49
49
  this._remountRequestListeners = new Set();
50
50
  this._errorListeners = new Set();
51
51
  this.data = data;
52
- this.baseUrl = typeof options === 'string' ? options : (options.baseUrl ?? '');
53
- this.moduleResolver = typeof options === 'string' ? undefined : options.moduleResolver;
54
- this.sandboxConfig = typeof options === 'string' ? undefined : options.sandbox;
55
- this.responseDeclaration =
56
- typeof options === 'string' ? undefined : options.responseDeclaration;
57
- this.statusSource = typeof options === 'string' ? undefined : options.status;
58
- this.registry = typeof options === 'string' ? getSharedPciRegistry() : (options.registry ?? getSharedPciRegistry());
52
+ this.baseUrl = options.baseUrl ?? '';
53
+ this.moduleResolver = options.moduleResolver;
54
+ this.sandboxConfig = options.sandbox;
55
+ this.responseDeclaration = options.responseDeclaration;
56
+ this.statusSource = options.status;
57
+ this.registry = options.registry ?? getSharedPciRegistry();
59
58
  if (this.sandboxConfig) {
60
59
  this.session = new SandboxedPciSession({
61
60
  sandbox: this.sandboxConfig,
62
61
  data,
63
62
  baseUrl: this.baseUrl,
64
- modulePolicy: typeof options === 'string' ? undefined : options.modulePolicy,
65
- frameConnector: typeof options === 'string' ? undefined : options.frameConnector,
66
- parentOrigin: typeof options === 'string' ? undefined : options.parentOrigin,
63
+ modulePolicy: options.modulePolicy,
64
+ frameConnector: options.frameConnector,
65
+ parentOrigin: options.parentOrigin,
66
+ contentLanguage: options.contentLanguage,
67
67
  });
68
68
  }
69
69
  else {
@@ -72,7 +72,7 @@ export class PciHost {
72
72
  baseUrl: this.baseUrl,
73
73
  moduleResolver: this.moduleResolver,
74
74
  registry: this.registry,
75
- ...(typeof options === 'string' ? {} : { registrationTimeoutMs: options.registrationTimeoutMs }),
75
+ registrationTimeoutMs: options.registrationTimeoutMs,
76
76
  });
77
77
  }
78
78
  this.session.onRemoteReport?.((report) => {
@@ -1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AAC;IAEO,WAAW,CAAC,CAAU,EAAE,CAAU;QACzC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACzB,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAEO,aAAa,CAAC,UAAkB;QACvC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,CAAC;IAC9D,CAAC;CACD;AAED,wFAAwF;AACxF,SAAS,gBAAgB,CAAC,KAAc;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrD,CAAC","sourcesContent":["import type {\n\tExtractedPci,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './types.js';\nimport { PciModuleResolverRequiredError } from './types.js';\nimport { getSharedPciRegistry } from './registry.js';\nimport { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';\nimport { PageRealmPciSession } from './pageRealmSession.js';\nimport { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';\nimport type { PciModuleSession } from './moduleSession.js';\n\n/**\n * Loads, initializes, and manages the lifecycle of a single PCI module under the\n * QTI 3.0 §6.1 contract.\n *\n * The module-facing contract is engine-independent: a module registers itself\n * against `qtiCustomInteractionContext` as its code evaluates, instantiation\n * goes through the registered `getInstance(dom, configuration, state)` factory\n * — state in, `getResponse()` / `getState()` out, no setter — and an\n * authoritative response change re-instantiates the module. What the host\n * chooses is *where that code runs*: by default the page realm behind a host\n * resolver (`moduleResolver`), or, with `sandbox` configured, a cross-origin\n * runner frame whose document has an opaque origin. The response-ownership\n * state machine below is shared by both engines; only the execution backend\n * (`PciModuleSession`) differs.\n *\n * Usage:\n * const host = new PciHost(extractedData, { baseUrl, moduleResolver });\n * await host.load();\n * host.initialize(domNode);\n * host.getResponse(); // current response, in the player's runtime value shape\n * host.destroy(); // cleanup on player teardown\n */\nexport class PciHost implements PciHostController {\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly moduleResolver: PciModuleResolver | undefined;\n\tprivate readonly sandboxConfig: PciHostOptions['sandbox'];\n\tprivate readonly responseDeclaration: PciHostOptions['responseDeclaration'];\n\tprivate readonly statusSource: PciHostOptions['status'];\n\tprivate readonly registry: PciRegistryObservation;\n\tprivate readonly session: PciModuleSession;\n\tprivate instance: QtiPciInstance | null = null;\n\tprivate mountNode: HTMLElement | null = null;\n\tprivate loaded = false;\n\tprivate destroyed = false;\n\tprivate loadGeneration = 0;\n\tprivate _response: unknown = null;\n\tprivate _hasResponse = false;\n\t/**\n\t * True once a mounted module has reported a response (through its own getResponse\n\t * captured at `onready`/`ondone`). While set, the module is the source of truth and\n\t * `offerResponse()` will not overwrite it.\n\t */\n\tprivate _moduleOwnsResponse = false;\n\t/**\n\t * True between an authoritative `restore()` and the rebuild that applies it.\n\t * The mounted module still holds the superseded value during that window, so\n\t * `getResponse()` must report the held one.\n\t */\n\tprivate _restorePending = false;\n\t/** The module's own state snapshot, seeded back at the next `getInstance`. */\n\tprivate _instanceState: unknown;\n\t/** The held value the current instantiation was seeded with, for no-op echo detection. */\n\tprivate _lastSeed: unknown;\n\tprivate readonly _responseChangeListeners = new Set<\n\t\t(responseId: string, value: unknown) => void\n\t>();\n\tprivate readonly _remountRequestListeners = new Set<() => void>();\n\tprivate readonly _errorListeners = new Set<(error: Error) => void>();\n\n\tconstructor(data: ExtractedPci, options: PciHostOptions | string = {}) {\n\t\tthis.data = data;\n\t\tthis.baseUrl = typeof options === 'string' ? options : (options.baseUrl ?? '');\n\t\tthis.moduleResolver = typeof options === 'string' ? undefined : options.moduleResolver;\n\t\tthis.sandboxConfig = typeof options === 'string' ? undefined : options.sandbox;\n\t\tthis.responseDeclaration =\n\t\t\ttypeof options === 'string' ? undefined : options.responseDeclaration;\n\t\tthis.statusSource = typeof options === 'string' ? undefined : options.status;\n\t\tthis.registry = typeof options === 'string' ? getSharedPciRegistry() : (options.registry ?? getSharedPciRegistry());\n\n\t\tif (this.sandboxConfig) {\n\t\t\tthis.session = new SandboxedPciSession({\n\t\t\t\tsandbox: this.sandboxConfig,\n\t\t\t\tdata,\n\t\t\t\tbaseUrl: this.baseUrl,\n\t\t\t\tmodulePolicy: typeof options === 'string' ? undefined : options.modulePolicy,\n\t\t\t\tframeConnector: typeof options === 'string' ? undefined : options.frameConnector,\n\t\t\t\tparentOrigin: typeof options === 'string' ? undefined : options.parentOrigin,\n\t\t\t});\n\t\t} else {\n\t\t\tthis.session = new PageRealmPciSession({\n\t\t\t\tdata,\n\t\t\t\tbaseUrl: this.baseUrl,\n\t\t\t\tmoduleResolver: this.moduleResolver,\n\t\t\t\tregistry: this.registry,\n\t\t\t\t...(typeof options === 'string' ? {} : { registrationTimeoutMs: options.registrationTimeoutMs }),\n\t\t\t});\n\t\t}\n\t\tthis.session.onRemoteReport?.((report) => {\n\t\t\t// The proxy's cache already carries the pushed response; the state\n\t\t\t// joins the instance state and the report counts as the module's own.\n\t\t\tif (report.state !== undefined) this._instanceState = report.state;\n\t\t\tthis.captureInstanceResponse();\n\t\t});\n\t\tthis.session.onError?.((error) => {\n\t\t\tfor (const listener of this._errorListeners) listener(error);\n\t\t});\n\t}\n\n\t/**\n\t * Register a callback to fire when the PCI's response changes. The player calls\n\t * this to wire the PCI into its internal response map. Values arrive in the\n\t * player's runtime shape; QTI variable JSON conversion happened at the boundary.\n\t */\n\tpublic onResponseChange(callback: (responseId: string, value: unknown) => void): () => void {\n\t\tthis._responseChangeListeners.add(callback);\n\t\treturn () => this._responseChangeListeners.delete(callback);\n\t}\n\n\t/**\n\t * Register a callback fired when an authoritative `restore()` lands on a\n\t * mounted module and the module must be rebuilt from the restored value.\n\t *\n\t * The renderer owns the DOM scaffold and its sanitization, so it performs the\n\t * rebuild: reset the sanitized markup into the mount node, then call\n\t * `remount(node)`. A host with no renderer wired here re-instantiates the\n\t * module on the last mount node itself.\n\t */\n\tpublic onRemountRequest(callback: () => void): () => void {\n\t\tthis._remountRequestListeners.add(callback);\n\t\treturn () => this._remountRequestListeners.delete(callback);\n\t}\n\n\t/**\n\t * Register a callback for asynchronous engine failures: the sandboxed\n\t * engine's frame handshake, in-frame module load, or instance errors. The\n\t * page-realm engine rejects `load()` instead and never uses this channel.\n\t */\n\tpublic onError(callback: (error: Error) => void): () => void {\n\t\tthis._errorListeners.add(callback);\n\t\treturn () => this._errorListeners.delete(callback);\n\t}\n\n\t/**\n\t * Bring the module's execution backend up: page-realm hosts evaluate the\n\t * module (primary path, then fallback, through the AMD loader for\n\t * multi-module declarations) and adopt its registration; the sandboxed\n\t * engine prepares the init payload and defers the module load to the runner\n\t * frame, whose failures surface through `onError`. Throws PciLoadError when\n\t * both page-realm paths fail or the module never registers.\n\t */\n\tpublic async load(): Promise<void> {\n\t\tif (this.destroyed) {\n\t\t\tthrow new Error('Cannot load a destroyed PciHost');\n\t\t}\n\t\tconst generation = ++this.loadGeneration;\n\t\tawait this.session.load({ isCurrent: () => this.isCurrentLoad(generation) });\n\t\t// A freshly adopted module has reported nothing yet; its old instance,\n\t\t// from a previous load, is gone with the re-resolution.\n\t\tthis.destroyInstance();\n\t\tthis._moduleOwnsResponse = false;\n\t\tthis.loaded = true;\n\t}\n\n\t/**\n\t * Instantiate the PCI inside the given DOM element through the registered\n\t * `getInstance` factory, seeding it with the held state. Must be called after\n\t * load() resolves. The sandboxed engine mounts its runner frame here instead:\n\t * the frame element replaces the scaffold's markup, because the module renders\n\t * inside the frame, not on the page.\n\t */\n\tpublic initialize(dom: HTMLElement): void {\n\t\tif (!this.loaded) return;\n\t\tthis.mountNode = dom;\n\t\tthis._lastSeed = this.seedValue();\n\n\t\ttry {\n\t\t\tconst returned = this.session.instantiate(dom, this.buildConfiguration(), this.seedValue());\n\t\t\tif (returned && typeof returned === 'object') this.instance = returned;\n\t\t\tthis._restorePending = false;\n\t\t} catch (error) {\n\t\t\tthis.instance = null;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Return the current response value, in the player's runtime value shape. */\n\tpublic getResponse(): unknown {\n\t\tif (this._restorePending) return this._response;\n\t\tif (this.instance) {\n\t\t\ttry {\n\t\t\t\tconst value = fromQtiVariableJson(this.instance.getResponse());\n\t\t\t\tif ((value === null || value === undefined) && this._hasResponse && !this._moduleOwnsResponse) {\n\t\t\t\t\t// A freshly instantiated module that has reported nothing yet: the\n\t\t\t\t\t// held value is what this instantiation was seeded with (the\n\t\t\t\t\t// sandboxed engine's cache stays empty until the frame's first\n\t\t\t\t\t// report crosses the bridge).\n\t\t\t\t\treturn this._response;\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t} catch {\n\t\t\t\treturn this._response;\n\t\t\t}\n\t\t}\n\t\treturn this._response;\n\t}\n\n\t/** The mounted module's state snapshot, when it exposes `getState()`. */\n\tpublic getState(): unknown {\n\t\tconst live = this.instance?.getState?.();\n\t\treturn live === undefined ? this._instanceState : live;\n\t}\n\n\t/**\n\t * Offer a response the player believes to be current.\n\t *\n\t * Declined once a mounted module has reported a response of its own. Under the\n\t * spec contract there is no setter, so an accepted offer before any report is\n\t * either held for the next instantiation or, when the value differs from what\n\t * the mounted module was seeded with, applied by re-instantiating it in place.\n\t *\n\t * @returns `false` when the module retained ownership and the value was not applied.\n\t */\n\tpublic offerResponse(value: unknown): boolean {\n\t\tif (this._moduleOwnsResponse) return false;\n\t\tconst unchanged = this.instance !== null && this.valuesEqual(value, this._lastSeed);\n\t\tthis._response = value;\n\t\tthis._hasResponse = true;\n\t\tif (!this.instance || unchanged) return true;\n\t\tthis.rebuildInPlace();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Authoritatively replace the response, discarding in-progress candidate\n\t * state and returning ownership to the player.\n\t *\n\t * \"Discard candidate state\" is re-instantiation: state is injected at\n\t * `getInstance` and the contract offers no setter. Where a renderer is wired\n\t * to `onRemountRequest` it rebuilds through a scaffold reset; otherwise this\n\t * host re-instantiates the module on the last mount node itself. Until the\n\t * rebuild lands, `getResponse()` reports the restored value rather than the\n\t * module's superseded one.\n\t */\n\tpublic restore(value: unknown): void {\n\t\tthis._response = value;\n\t\tthis._hasResponse = true;\n\t\tthis._moduleOwnsResponse = false;\n\t\tif (!this.instance && !this.mountNode) return;\n\t\tif (this._remountRequestListeners.size > 0) {\n\t\t\tthis._restorePending = true;\n\t\t\tfor (const listener of this._remountRequestListeners) listener();\n\t\t\treturn;\n\t\t}\n\t\tif (this.instance) this.rebuildInPlace();\n\t}\n\n\t/**\n\t * Rebuild the module in place from the currently held response.\n\t *\n\t * The caller must reset the sanitized DOM scaffold into `dom` first: this\n\t * discards the previous module instance, re-resolves the registration, and\n\t * instantiates it with the held state.\n\t */\n\tpublic async remount(dom: HTMLElement): Promise<void> {\n\t\tif (this.destroyed) throw new Error('Cannot remount a destroyed PciHost');\n\t\tthis.destroyInstance();\n\t\tawait this.load();\n\t\tthis.initialize(dom);\n\t}\n\n\t/**\n\t * Nudge the module out of interaction, for hosts whose module exposes the\n\t * optional `disable` method. Conformant modules read their fixed\n\t * `configuration.status` instead.\n\t */\n\tpublic disable(): void {\n\t\t(this.instance as { disable?: () => void } | null)?.disable?.();\n\t}\n\n\t/** The counterpart of `disable()`, for modules that expose it. */\n\tpublic enable(): void {\n\t\t(this.instance as { enable?: () => void } | null)?.enable?.();\n\t}\n\n\t/** Tear down the PCI and release all resources. */\n\tpublic destroy(): void {\n\t\tthis.destroyed = true;\n\t\tthis.loadGeneration++;\n\t\t// Keep the last known module state answerable after teardown.\n\t\tthis._instanceState = this.instance?.getState?.() ?? this._instanceState;\n\t\tthis.destroyInstance();\n\t\tthis.session.dispose();\n\t\tthis._responseChangeListeners.clear();\n\t\tthis._remountRequestListeners.clear();\n\t\tthis._errorListeners.clear();\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate destroyInstance(): void {\n\t\tconst instance = this.instance;\n\t\tthis.instance = null;\n\t\tif (!instance) return;\n\t\tthis.session.destroyInstance(instance);\n\t}\n\n\t/**\n\t * Re-instantiate the current module on the last mount node, discarding the\n\t * previous instance. The DOM scaffold is not reset here — that is the\n\t * renderer's job, and this path exists for hosts that wired none.\n\t */\n\tprivate rebuildInPlace(): void {\n\t\tif (!this.mountNode || !this.loaded || this.destroyed) return;\n\t\tthis.destroyInstance();\n\t\tthis._instanceState = undefined;\n\t\tthis.initialize(this.mountNode);\n\t}\n\n\tprivate buildConfiguration(): QtiPciConfiguration {\n\t\treturn {\n\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\tstatus: typeof this.statusSource === 'function' ? this.statusSource() : (this.statusSource ?? 'interacting'),\n\t\t\tproperties: { ...this.data.config },\n\t\t\tonready: (_instance, state) => {\n\t\t\t\tif (state !== undefined) this._instanceState = state;\n\t\t\t\tthis.captureInstanceResponse();\n\t\t\t},\n\t\t\tondone: (_instance, state) => {\n\t\t\t\tif (state !== undefined) this._instanceState = state;\n\t\t\t\tthis.captureInstanceResponse();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Take the mounted module's response as its own report and publish it. */\n\tprivate captureInstanceResponse(): void {\n\t\tif (!this.instance) return;\n\t\ttry {\n\t\t\tconst value = fromQtiVariableJson(this.instance.getResponse());\n\t\t\tif (value === null && !this._hasResponse) return;\n\t\t\tthis._response = value;\n\t\t\tthis._hasResponse = true;\n\t\t\tthis._moduleOwnsResponse = true;\n\t\t\tthis._restorePending = false;\n\t\t\tfor (const listener of this._responseChangeListeners) {\n\t\t\t\tlistener(this.data.responseIdentifier, value);\n\t\t\t}\n\t\t} catch {\n\t\t\t// A module whose getResponse() throws has reported nothing yet.\n\t\t}\n\t}\n\n\t/** The held response as the `state` a fresh instantiation receives. */\n\tprivate seedValue(): unknown {\n\t\tif (this._instanceState !== undefined) return this._instanceState;\n\t\tif (!this._hasResponse) return undefined;\n\t\tconst cardinality = this.responseDeclaration?.cardinality ?? inferCardinality(this._response);\n\t\treturn toQtiVariableJson(\n\t\t\tthis._response,\n\t\t\tthis.responseDeclaration?.baseType,\n\t\t\tcardinality\n\t\t);\n\t}\n\n\tprivate valuesEqual(a: unknown, b: unknown): boolean {\n\t\tif (a === b) return true;\n\t\ttry {\n\t\t\treturn JSON.stringify(a) === JSON.stringify(b);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate isCurrentLoad(generation: number): boolean {\n\t\treturn !this.destroyed && generation === this.loadGeneration;\n\t}\n}\n\n/** A response's cardinality from its JavaScript shape, when no declaration is known. */\nfunction inferCardinality(value: unknown): 'single' | 'multiple' {\n\treturn Array.isArray(value) ? 'multiple' : 'single';\n}\n"]}
1
+ {"version":3,"file":"PciHost.js","sourceRoot":"","sources":["../../src/pci/PciHost.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAGvE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,OAAO;IAsCnB,YAAY,IAAkB,EAAE,UAA0B,EAAE;QA7BpD,aAAQ,GAA0B,IAAI,CAAC;QACvC,cAAS,GAAuB,IAAI,CAAC;QACrC,WAAM,GAAG,KAAK,CAAC;QACf,cAAS,GAAG,KAAK,CAAC;QAClB,mBAAc,GAAG,CAAC,CAAC;QACnB,cAAS,GAAY,IAAI,CAAC;QAC1B,iBAAY,GAAG,KAAK,CAAC;QAC7B;;;;WAIG;QACK,wBAAmB,GAAG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C,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAEO,aAAa,CAAC,UAAkB;QACvC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,UAAU,KAAK,IAAI,CAAC,cAAc,CAAC;IAC9D,CAAC;CACD;AAED,wFAAwF;AACxF,SAAS,gBAAgB,CAAC,KAAc;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrD,CAAC","sourcesContent":["import type {\n\tExtractedPci,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './types.js';\nimport { PciModuleResolverRequiredError } from './types.js';\nimport { getSharedPciRegistry } from './registry.js';\nimport { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';\nimport { PageRealmPciSession } from './pageRealmSession.js';\nimport { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';\nimport type { PciModuleSession } from './moduleSession.js';\n\n/**\n * Loads, initializes, and manages the lifecycle of a single PCI module under the\n * QTI 3.0 §6.1 contract.\n *\n * The module-facing contract is engine-independent: a module registers itself\n * against `qtiCustomInteractionContext` as its code evaluates, instantiation\n * goes through the registered `getInstance(dom, configuration, state)` factory\n * — state in, `getResponse()` / `getState()` out, no setter — and an\n * authoritative response change re-instantiates the module. What the host\n * chooses is *where that code runs*: by default the page realm behind a host\n * resolver (`moduleResolver`), or, with `sandbox` configured, a cross-origin\n * runner frame whose document has an opaque origin. The response-ownership\n * state machine below is shared by both engines; only the execution backend\n * (`PciModuleSession`) differs.\n *\n * Usage:\n * const host = new PciHost(extractedData, { baseUrl, moduleResolver });\n * await host.load();\n * host.initialize(domNode);\n * host.getResponse(); // current response, in the player's runtime value shape\n * host.destroy(); // cleanup on player teardown\n */\nexport class PciHost implements PciHostController {\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly moduleResolver: PciModuleResolver | undefined;\n\tprivate readonly sandboxConfig: PciHostOptions['sandbox'];\n\tprivate readonly responseDeclaration: PciHostOptions['responseDeclaration'];\n\tprivate readonly statusSource: PciHostOptions['status'];\n\tprivate readonly registry: PciRegistryObservation;\n\tprivate readonly session: PciModuleSession;\n\tprivate instance: QtiPciInstance | null = null;\n\tprivate mountNode: HTMLElement | null = null;\n\tprivate loaded = false;\n\tprivate destroyed = false;\n\tprivate loadGeneration = 0;\n\tprivate _response: unknown = null;\n\tprivate _hasResponse = false;\n\t/**\n\t * True once a mounted module has reported a response (through its own getResponse\n\t * captured at `onready`/`ondone`). While set, the module is the source of truth and\n\t * `offerResponse()` will not overwrite it.\n\t */\n\tprivate _moduleOwnsResponse = false;\n\t/**\n\t * True between an authoritative `restore()` and the rebuild that applies it.\n\t * The mounted module still holds the superseded value during that window, so\n\t * `getResponse()` must report the held one.\n\t */\n\tprivate _restorePending = false;\n\t/** The module's own state snapshot, seeded back at the next `getInstance`. */\n\tprivate _instanceState: unknown;\n\t/** The held value the current instantiation was seeded with, for no-op echo detection. */\n\tprivate _lastSeed: unknown;\n\tprivate readonly _responseChangeListeners = new Set<\n\t\t(responseId: string, value: unknown) => void\n\t>();\n\tprivate readonly _remountRequestListeners = new Set<() => void>();\n\tprivate readonly _errorListeners = new Set<(error: Error) => void>();\n\n\tconstructor(data: ExtractedPci, options: PciHostOptions = {}) {\n\t\tthis.data = data;\n\t\tthis.baseUrl = options.baseUrl ?? '';\n\t\tthis.moduleResolver = options.moduleResolver;\n\t\tthis.sandboxConfig = options.sandbox;\n\t\tthis.responseDeclaration = options.responseDeclaration;\n\t\tthis.statusSource = options.status;\n\t\tthis.registry = options.registry ?? getSharedPciRegistry();\n\n\t\tif (this.sandboxConfig) {\n\t\t\tthis.session = new SandboxedPciSession({\n\t\t\t\tsandbox: this.sandboxConfig,\n\t\t\t\tdata,\n\t\t\t\tbaseUrl: this.baseUrl,\n\t\t\t\tmodulePolicy: options.modulePolicy,\n\t\t\t\tframeConnector: options.frameConnector,\n\t\t\t\tparentOrigin: options.parentOrigin,\n\t\t\t\tcontentLanguage: options.contentLanguage,\n\t\t\t});\n\t\t} else {\n\t\t\tthis.session = new PageRealmPciSession({\n\t\t\t\tdata,\n\t\t\t\tbaseUrl: this.baseUrl,\n\t\t\t\tmoduleResolver: this.moduleResolver,\n\t\t\t\tregistry: this.registry,\n\t\t\t\tregistrationTimeoutMs: options.registrationTimeoutMs,\n\t\t\t});\n\t\t}\n\t\tthis.session.onRemoteReport?.((report) => {\n\t\t\t// The proxy's cache already carries the pushed response; the state\n\t\t\t// joins the instance state and the report counts as the module's own.\n\t\t\tif (report.state !== undefined) this._instanceState = report.state;\n\t\t\tthis.captureInstanceResponse();\n\t\t});\n\t\tthis.session.onError?.((error) => {\n\t\t\tfor (const listener of this._errorListeners) listener(error);\n\t\t});\n\t}\n\n\t/**\n\t * Register a callback to fire when the PCI's response changes. The player calls\n\t * this to wire the PCI into its internal response map. Values arrive in the\n\t * player's runtime shape; QTI variable JSON conversion happened at the boundary.\n\t */\n\tpublic onResponseChange(callback: (responseId: string, value: unknown) => void): () => void {\n\t\tthis._responseChangeListeners.add(callback);\n\t\treturn () => this._responseChangeListeners.delete(callback);\n\t}\n\n\t/**\n\t * Register a callback fired when an authoritative `restore()` lands on a\n\t * mounted module and the module must be rebuilt from the restored value.\n\t *\n\t * The renderer owns the DOM scaffold and its sanitization, so it performs the\n\t * rebuild: reset the sanitized markup into the mount node, then call\n\t * `remount(node)`. A host with no renderer wired here re-instantiates the\n\t * module on the last mount node itself.\n\t */\n\tpublic onRemountRequest(callback: () => void): () => void {\n\t\tthis._remountRequestListeners.add(callback);\n\t\treturn () => this._remountRequestListeners.delete(callback);\n\t}\n\n\t/**\n\t * Register a callback for asynchronous engine failures: the sandboxed\n\t * engine's frame handshake, in-frame module load, or instance errors. The\n\t * page-realm engine rejects `load()` instead and never uses this channel.\n\t */\n\tpublic onError(callback: (error: Error) => void): () => void {\n\t\tthis._errorListeners.add(callback);\n\t\treturn () => this._errorListeners.delete(callback);\n\t}\n\n\t/**\n\t * Bring the module's execution backend up: page-realm hosts evaluate the\n\t * module (primary path, then fallback, through the AMD loader for\n\t * multi-module declarations) and adopt its registration; the sandboxed\n\t * engine prepares the init payload and defers the module load to the runner\n\t * frame, whose failures surface through `onError`. Throws PciLoadError when\n\t * both page-realm paths fail or the module never registers.\n\t */\n\tpublic async load(): Promise<void> {\n\t\tif (this.destroyed) {\n\t\t\tthrow new Error('Cannot load a destroyed PciHost');\n\t\t}\n\t\tconst generation = ++this.loadGeneration;\n\t\tawait this.session.load({ isCurrent: () => this.isCurrentLoad(generation) });\n\t\t// A freshly adopted module has reported nothing yet; its old instance,\n\t\t// from a previous load, is gone with the re-resolution.\n\t\tthis.destroyInstance();\n\t\tthis._moduleOwnsResponse = false;\n\t\tthis.loaded = true;\n\t}\n\n\t/**\n\t * Instantiate the PCI inside the given DOM element through the registered\n\t * `getInstance` factory, seeding it with the held state. Must be called after\n\t * load() resolves. The sandboxed engine mounts its runner frame here instead:\n\t * the frame element replaces the scaffold's markup, because the module renders\n\t * inside the frame, not on the page.\n\t */\n\tpublic initialize(dom: HTMLElement): void {\n\t\tif (!this.loaded) return;\n\t\tthis.mountNode = dom;\n\t\tthis._lastSeed = this.seedValue();\n\n\t\ttry {\n\t\t\tconst returned = this.session.instantiate(dom, this.buildConfiguration(), this.seedValue());\n\t\t\tif (returned && typeof returned === 'object') this.instance = returned;\n\t\t\tthis._restorePending = false;\n\t\t} catch (error) {\n\t\t\tthis.instance = null;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Return the current response value, in the player's runtime value shape. */\n\tpublic getResponse(): unknown {\n\t\tif (this._restorePending) return this._response;\n\t\tif (this.instance) {\n\t\t\ttry {\n\t\t\t\tconst value = fromQtiVariableJson(this.instance.getResponse());\n\t\t\t\tif ((value === null || value === undefined) && this._hasResponse && !this._moduleOwnsResponse) {\n\t\t\t\t\t// A freshly instantiated module that has reported nothing yet: the\n\t\t\t\t\t// held value is what this instantiation was seeded with (the\n\t\t\t\t\t// sandboxed engine's cache stays empty until the frame's first\n\t\t\t\t\t// report crosses the bridge).\n\t\t\t\t\treturn this._response;\n\t\t\t\t}\n\t\t\t\treturn value;\n\t\t\t} catch {\n\t\t\t\treturn this._response;\n\t\t\t}\n\t\t}\n\t\treturn this._response;\n\t}\n\n\t/** The mounted module's state snapshot, when it exposes `getState()`. */\n\tpublic getState(): unknown {\n\t\tconst live = this.instance?.getState?.();\n\t\treturn live === undefined ? this._instanceState : live;\n\t}\n\n\t/**\n\t * Offer a response the player believes to be current.\n\t *\n\t * Declined once a mounted module has reported a response of its own. Under the\n\t * spec contract there is no setter, so an accepted offer before any report is\n\t * either held for the next instantiation or, when the value differs from what\n\t * the mounted module was seeded with, applied by re-instantiating it in place.\n\t *\n\t * @returns `false` when the module retained ownership and the value was not applied.\n\t */\n\tpublic offerResponse(value: unknown): boolean {\n\t\tif (this._moduleOwnsResponse) return false;\n\t\tconst unchanged = this.instance !== null && this.valuesEqual(value, this._lastSeed);\n\t\tthis._response = value;\n\t\tthis._hasResponse = true;\n\t\tif (!this.instance || unchanged) return true;\n\t\tthis.rebuildInPlace();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Authoritatively replace the response, discarding in-progress candidate\n\t * state and returning ownership to the player.\n\t *\n\t * \"Discard candidate state\" is re-instantiation: state is injected at\n\t * `getInstance` and the contract offers no setter. Where a renderer is wired\n\t * to `onRemountRequest` it rebuilds through a scaffold reset; otherwise this\n\t * host re-instantiates the module on the last mount node itself. Until the\n\t * rebuild lands, `getResponse()` reports the restored value rather than the\n\t * module's superseded one.\n\t */\n\tpublic restore(value: unknown): void {\n\t\tthis._response = value;\n\t\tthis._hasResponse = true;\n\t\tthis._moduleOwnsResponse = false;\n\t\tif (!this.instance && !this.mountNode) return;\n\t\tif (this._remountRequestListeners.size > 0) {\n\t\t\tthis._restorePending = true;\n\t\t\tfor (const listener of this._remountRequestListeners) listener();\n\t\t\treturn;\n\t\t}\n\t\tif (this.instance) this.rebuildInPlace();\n\t}\n\n\t/**\n\t * Rebuild the module in place from the currently held response.\n\t *\n\t * The caller must reset the sanitized DOM scaffold into `dom` first: this\n\t * discards the previous module instance, re-resolves the registration, and\n\t * instantiates it with the held state.\n\t */\n\tpublic async remount(dom: HTMLElement): Promise<void> {\n\t\tif (this.destroyed) throw new Error('Cannot remount a destroyed PciHost');\n\t\tthis.destroyInstance();\n\t\tawait this.load();\n\t\tthis.initialize(dom);\n\t}\n\n\t/**\n\t * Nudge the module out of interaction, for hosts whose module exposes the\n\t * optional `disable` method. Conformant modules read their fixed\n\t * `configuration.status` instead.\n\t */\n\tpublic disable(): void {\n\t\t(this.instance as { disable?: () => void } | null)?.disable?.();\n\t}\n\n\t/** The counterpart of `disable()`, for modules that expose it. */\n\tpublic enable(): void {\n\t\t(this.instance as { enable?: () => void } | null)?.enable?.();\n\t}\n\n\t/** Tear down the PCI and release all resources. */\n\tpublic destroy(): void {\n\t\tthis.destroyed = true;\n\t\tthis.loadGeneration++;\n\t\t// Keep the last known module state answerable after teardown.\n\t\tthis._instanceState = this.instance?.getState?.() ?? this._instanceState;\n\t\tthis.destroyInstance();\n\t\tthis.session.dispose();\n\t\tthis._responseChangeListeners.clear();\n\t\tthis._remountRequestListeners.clear();\n\t\tthis._errorListeners.clear();\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate destroyInstance(): void {\n\t\tconst instance = this.instance;\n\t\tthis.instance = null;\n\t\tif (!instance) return;\n\t\tthis.session.destroyInstance(instance);\n\t}\n\n\t/**\n\t * Re-instantiate the current module on the last mount node, discarding the\n\t * previous instance. The DOM scaffold is not reset here — that is the\n\t * renderer's job, and this path exists for hosts that wired none.\n\t */\n\tprivate rebuildInPlace(): void {\n\t\tif (!this.mountNode || !this.loaded || this.destroyed) return;\n\t\tthis.destroyInstance();\n\t\tthis._instanceState = undefined;\n\t\tthis.initialize(this.mountNode);\n\t}\n\n\tprivate buildConfiguration(): QtiPciConfiguration {\n\t\treturn {\n\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\tstatus: typeof this.statusSource === 'function' ? this.statusSource() : (this.statusSource ?? 'interacting'),\n\t\t\tproperties: { ...this.data.config },\n\t\t\tonready: (_instance, state) => {\n\t\t\t\tif (state !== undefined) this._instanceState = state;\n\t\t\t\tthis.captureInstanceResponse();\n\t\t\t},\n\t\t\tondone: (_instance, state) => {\n\t\t\t\tif (state !== undefined) this._instanceState = state;\n\t\t\t\tthis.captureInstanceResponse();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Take the mounted module's response as its own report and publish it. */\n\tprivate captureInstanceResponse(): void {\n\t\tif (!this.instance) return;\n\t\ttry {\n\t\t\tconst value = fromQtiVariableJson(this.instance.getResponse());\n\t\t\tif (value === null && !this._hasResponse) return;\n\t\t\tthis._response = value;\n\t\t\tthis._hasResponse = true;\n\t\t\tthis._moduleOwnsResponse = true;\n\t\t\tthis._restorePending = false;\n\t\t\tfor (const listener of this._responseChangeListeners) {\n\t\t\t\tlistener(this.data.responseIdentifier, value);\n\t\t\t}\n\t\t} catch {\n\t\t\t// A module whose getResponse() throws has reported nothing yet.\n\t\t}\n\t}\n\n\t/** The held response as the `state` a fresh instantiation receives. */\n\tprivate seedValue(): unknown {\n\t\tif (this._instanceState !== undefined) return this._instanceState;\n\t\tif (!this._hasResponse) return undefined;\n\t\tconst cardinality = this.responseDeclaration?.cardinality ?? inferCardinality(this._response);\n\t\treturn toQtiVariableJson(\n\t\t\tthis._response,\n\t\t\tthis.responseDeclaration?.baseType,\n\t\t\tcardinality\n\t\t);\n\t}\n\n\tprivate valuesEqual(a: unknown, b: unknown): boolean {\n\t\tif (a === b) return true;\n\t\ttry {\n\t\t\treturn JSON.stringify(a) === JSON.stringify(b);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate isCurrentLoad(generation: number): boolean {\n\t\treturn !this.destroyed && generation === this.loadGeneration;\n\t}\n}\n\n/** A response's cardinality from its JavaScript shape, when no declaration is known. */\nfunction inferCardinality(value: unknown): 'single' | 'multiple' {\n\treturn Array.isArray(value) ? 'multiple' : 'single';\n}\n"]}
@@ -12,5 +12,6 @@ export { PCI_SANDBOX_PROTOCOL, PCI_SANDBOX_PROTOCOL_VERSION, createSandboxEnvelo
12
12
  export type { PciSandboxEnvelope, PciSandboxHostToRunnerType, PciSandboxInitPayload, PciSandboxInstantiatePayload, PciSandboxMessage, PciSandboxMessageType, PciSandboxModuleEntryPayload, PciSandboxProtocolVersion, PciSandboxRunnerToHostType, } from './sandbox/protocol.js';
13
13
  export type { PciLoadContext, PciModuleSession } from './moduleSession.js';
14
14
  export { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';
15
+ export type { QtiRecordField } from './qtiVariableJson.js';
15
16
  export type { ExtractedPci, PciConfiguration, PciCustomInteractionContext, PciFrameConnection, PciFrameConnector, PciHostController, PciHostOptions, PciInteractionStatus, PciModuleEntry, PciModulePathKind, PciModulePolicy, PciModuleResolutionContext, PciModuleResolver, PciRegistryObservation, PciResponseDeclarationInfo, PciSandboxConfiguration, QtiCustomInteractionRegistration, QtiPciConfiguration, QtiPciInstance, } from './types.js';
16
17
  export { PciLoadError, PciModuleResolverRequiredError } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pci/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,gCAAgC,EAChC,8BAA8B,EAC9B,wBAAwB,GACxB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACN,+BAA+B,EAC/B,qBAAqB,EACrB,2BAA2B,GAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EACN,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,uBAAuB,CAAC;AAa/B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAsB9E,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { PciHost } from './PciHost.js';\nexport {\n\tcreateAllowlistPciModuleResolver,\n\tcreateAllowlistPciModulePolicy,\n\tPciModuleNotAllowedError,\n} from './allowlistResolver.js';\nexport type {\n\tAllowlistPciPolicyOptions,\n\tAllowlistPciResolverOptions,\n} from './allowlistResolver.js';\nexport {\n\tgetSharedPciRegistry,\n\tinstallPciRegistry,\n\tPCI_REGISTRY_GLOBAL,\n} from './registry.js';\nexport { createAmdLoader } from './amdLoader.js';\nexport type { AmdLoader, AmdLoaderOptions } from './amdLoader.js';\nexport {\n\tDEFAULT_RESOLUTION_CONFIG_PATHS,\n\temptyResolutionConfig,\n\tparseModuleResolutionConfig,\n} from './resolutionConfig.js';\nexport type { PciResolutionConfig, PciResolutionShim } from './resolutionConfig.js';\nexport { createIframeFrameConnector } from './sandbox/iframeConnector.js';\nexport { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';\nexport {\n\tPCI_SANDBOX_PROTOCOL,\n\tPCI_SANDBOX_PROTOCOL_VERSION,\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n} from './sandbox/protocol.js';\nexport type {\n\tPciSandboxEnvelope,\n\tPciSandboxHostToRunnerType,\n\tPciSandboxInitPayload,\n\tPciSandboxInstantiatePayload,\n\tPciSandboxMessage,\n\tPciSandboxMessageType,\n\tPciSandboxModuleEntryPayload,\n\tPciSandboxProtocolVersion,\n\tPciSandboxRunnerToHostType,\n} from './sandbox/protocol.js';\nexport type { PciLoadContext, PciModuleSession } from './moduleSession.js';\nexport { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';\nexport type {\n\tExtractedPci,\n\tPciConfiguration,\n\tPciCustomInteractionContext,\n\tPciFrameConnection,\n\tPciFrameConnector,\n\tPciHostController,\n\tPciHostOptions,\n\tPciInteractionStatus,\n\tPciModuleEntry,\n\tPciModulePathKind,\n\tPciModulePolicy,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tPciResponseDeclarationInfo,\n\tPciSandboxConfiguration,\n\tQtiCustomInteractionRegistration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pci/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,gCAAgC,EAChC,8BAA8B,EAC9B,wBAAwB,GACxB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACN,+BAA+B,EAC/B,qBAAqB,EACrB,2BAA2B,GAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EACN,oBAAoB,EACpB,4BAA4B,EAC5B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,uBAAuB,CAAC;AAa/B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAuB9E,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { PciHost } from './PciHost.js';\nexport {\n\tcreateAllowlistPciModuleResolver,\n\tcreateAllowlistPciModulePolicy,\n\tPciModuleNotAllowedError,\n} from './allowlistResolver.js';\nexport type {\n\tAllowlistPciPolicyOptions,\n\tAllowlistPciResolverOptions,\n} from './allowlistResolver.js';\nexport {\n\tgetSharedPciRegistry,\n\tinstallPciRegistry,\n\tPCI_REGISTRY_GLOBAL,\n} from './registry.js';\nexport { createAmdLoader } from './amdLoader.js';\nexport type { AmdLoader, AmdLoaderOptions } from './amdLoader.js';\nexport {\n\tDEFAULT_RESOLUTION_CONFIG_PATHS,\n\temptyResolutionConfig,\n\tparseModuleResolutionConfig,\n} from './resolutionConfig.js';\nexport type { PciResolutionConfig, PciResolutionShim } from './resolutionConfig.js';\nexport { createIframeFrameConnector } from './sandbox/iframeConnector.js';\nexport { SandboxedPciSession } from './sandbox/SandboxedPciSession.js';\nexport {\n\tPCI_SANDBOX_PROTOCOL,\n\tPCI_SANDBOX_PROTOCOL_VERSION,\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n} from './sandbox/protocol.js';\nexport type {\n\tPciSandboxEnvelope,\n\tPciSandboxHostToRunnerType,\n\tPciSandboxInitPayload,\n\tPciSandboxInstantiatePayload,\n\tPciSandboxMessage,\n\tPciSandboxMessageType,\n\tPciSandboxModuleEntryPayload,\n\tPciSandboxProtocolVersion,\n\tPciSandboxRunnerToHostType,\n} from './sandbox/protocol.js';\nexport type { PciLoadContext, PciModuleSession } from './moduleSession.js';\nexport { fromQtiVariableJson, toQtiVariableJson } from './qtiVariableJson.js';\nexport type { QtiRecordField } from './qtiVariableJson.js';\nexport type {\n\tExtractedPci,\n\tPciConfiguration,\n\tPciCustomInteractionContext,\n\tPciFrameConnection,\n\tPciFrameConnector,\n\tPciHostController,\n\tPciHostOptions,\n\tPciInteractionStatus,\n\tPciModuleEntry,\n\tPciModulePathKind,\n\tPciModulePolicy,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n\tPciRegistryObservation,\n\tPciResponseDeclarationInfo,\n\tPciSandboxConfiguration,\n\tQtiCustomInteractionRegistration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from './types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './types.js';\n"]}
@@ -0,0 +1,16 @@
1
+ import type { ExtractedPci, PciModuleEntry } from './types.js';
2
+ /**
3
+ * Resolve one authored PCI module path against the package base URL. Absolute,
4
+ * protocol-relative, scheme-qualified and root-relative paths are kept as
5
+ * authored; anything else is resolved against the base, falling back to string
6
+ * concatenation when the base is not a valid URL.
7
+ *
8
+ * Shared by the page-realm and sandboxed engines; the policy gate and the
9
+ * timeouts around loading stay per engine.
10
+ */
11
+ export declare function resolvePciModuleUrl(path: string, baseUrl: string): string;
12
+ /**
13
+ * The entry module of an extracted PCI: the authored module whose primary path
14
+ * is the interaction's primary reference, else the last authored module.
15
+ */
16
+ export declare function pciEntryModule(data: ExtractedPci): PciModuleEntry | undefined;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Resolve one authored PCI module path against the package base URL. Absolute,
3
+ * protocol-relative, scheme-qualified and root-relative paths are kept as
4
+ * authored; anything else is resolved against the base, falling back to string
5
+ * concatenation when the base is not a valid URL.
6
+ *
7
+ * Shared by the page-realm and sandboxed engines; the policy gate and the
8
+ * timeouts around loading stay per engine.
9
+ */
10
+ export function resolvePciModuleUrl(path, baseUrl) {
11
+ if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {
12
+ return path;
13
+ }
14
+ if (!baseUrl)
15
+ return path;
16
+ // Relative path: resolve against baseUrl
17
+ const base = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/';
18
+ try {
19
+ return new URL(path, base).href;
20
+ }
21
+ catch {
22
+ return base + path;
23
+ }
24
+ }
25
+ /**
26
+ * The entry module of an extracted PCI: the authored module whose primary path
27
+ * is the interaction's primary reference, else the last authored module.
28
+ */
29
+ export function pciEntryModule(data) {
30
+ return (data.modules.find((module) => module.primaryPath === data.primaryPath) ??
31
+ data.modules[data.modules.length - 1]);
32
+ }
33
+ //# sourceMappingURL=modulePaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modulePaths.js","sourceRoot":"","sources":["../../src/pci/modulePaths.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,OAAe;IAChE,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACvF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,yCAAyC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC;IAC7D,IAAI,CAAC;QACJ,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,GAAG,IAAI,CAAC;IACpB,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAkB;IAChD,OAAO,CACN,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;QACtE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CACrC,CAAC;AACH,CAAC","sourcesContent":["import type { ExtractedPci, PciModuleEntry } from './types.js';\n\n/**\n * Resolve one authored PCI module path against the package base URL. Absolute,\n * protocol-relative, scheme-qualified and root-relative paths are kept as\n * authored; anything else is resolved against the base, falling back to string\n * concatenation when the base is not a valid URL.\n *\n * Shared by the page-realm and sandboxed engines; the policy gate and the\n * timeouts around loading stay per engine.\n */\nexport function resolvePciModuleUrl(path: string, baseUrl: string): string {\n\tif (/^[a-z][a-z\\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {\n\t\treturn path;\n\t}\n\tif (!baseUrl) return path;\n\t// Relative path: resolve against baseUrl\n\tconst base = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/';\n\ttry {\n\t\treturn new URL(path, base).href;\n\t} catch {\n\t\treturn base + path;\n\t}\n}\n\n/**\n * The entry module of an extracted PCI: the authored module whose primary path\n * is the interaction's primary reference, else the last authored module.\n */\nexport function pciEntryModule(data: ExtractedPci): PciModuleEntry | undefined {\n\treturn (\n\t\tdata.modules.find((module) => module.primaryPath === data.primaryPath) ??\n\t\tdata.modules[data.modules.length - 1]\n\t);\n}\n"]}
@@ -2,6 +2,7 @@ import { PciLoadError, PciModuleResolverRequiredError } from './types.js';
2
2
  import { getSharedPciRegistry } from './registry.js';
3
3
  import { DEFAULT_RESOLUTION_CONFIG_PATHS, emptyResolutionConfig, parseModuleResolutionConfig, } from './resolutionConfig.js';
4
4
  import { createAmdLoader } from './amdLoader.js';
5
+ import { pciEntryModule, resolvePciModuleUrl } from './modulePaths.js';
5
6
  const DEFAULT_REGISTRATION_TIMEOUT_MS = 5000;
6
7
  /**
7
8
  * The page-realm engine: the host resolver evaluates the module in the page,
@@ -100,8 +101,7 @@ export class PageRealmPciSession {
100
101
  * dependencies wire up before the registration is read.
101
102
  */
102
103
  async loadViaAmd(context) {
103
- const entry = this.data.modules.find((module) => module.primaryPath === this.data.primaryPath) ??
104
- this.data.modules[this.data.modules.length - 1];
104
+ const entry = pciEntryModule(this.data);
105
105
  const entryId = entry?.id || this.data.primaryPath;
106
106
  const attempt = async (entryPath, kind) => {
107
107
  const config = await this.loadResolutionConfig();
@@ -166,19 +166,7 @@ export class PageRealmPciSession {
166
166
  return emptyResolutionConfig();
167
167
  }
168
168
  resolveUrl(path) {
169
- if (/^[a-z][a-z\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {
170
- return path;
171
- }
172
- if (!this.baseUrl)
173
- return path;
174
- // Relative path: resolve against baseUrl
175
- const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';
176
- try {
177
- return new URL(path, base).href;
178
- }
179
- catch {
180
- return base + path;
181
- }
169
+ return resolvePciModuleUrl(path, this.baseUrl);
182
170
  }
183
171
  adoptRegistration(registration, context) {
184
172
  if (!registration || typeof registration.getInstance !== 'function') {