@pie-qti/item-player 0.1.19 → 0.1.21

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 (263) hide show
  1. package/README.md +137 -427
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
  3. package/dist/catalog/applyGlossaryTriggers.js +4 -2
  4. package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
  5. package/dist/components/utils/stimulusRender.d.ts +1 -2
  6. package/dist/components/utils/stimulusRender.js +2 -5
  7. package/dist/components/utils/stimulusRender.js.map +1 -1
  8. package/dist/core/AssessmentItemDefinition.d.ts +69 -0
  9. package/dist/core/AssessmentItemDefinition.js +149 -0
  10. package/dist/core/AssessmentItemDefinition.js.map +1 -0
  11. package/dist/core/ComponentRegistry.d.ts +11 -5
  12. package/dist/core/ComponentRegistry.js +44 -17
  13. package/dist/core/ComponentRegistry.js.map +1 -1
  14. package/dist/core/ItemSession.d.ts +58 -0
  15. package/dist/core/ItemSession.js +286 -0
  16. package/dist/core/ItemSession.js.map +1 -0
  17. package/dist/core/Player.d.ts +26 -8
  18. package/dist/core/Player.js +225 -165
  19. package/dist/core/Player.js.map +1 -1
  20. package/dist/core/constants.d.ts +0 -2
  21. package/dist/core/constants.js +0 -33
  22. package/dist/core/constants.js.map +1 -1
  23. package/dist/document/AssessmentItemDocument.d.ts +32 -10
  24. package/dist/document/AssessmentItemDocument.js +80 -23
  25. package/dist/document/AssessmentItemDocument.js.map +1 -1
  26. package/dist/{element-class-BEpwHdcP.js → element-class-iN9MRyjF.js} +3582 -2783
  27. package/dist/element-class-iN9MRyjF.js.map +1 -0
  28. package/dist/element-class.d.ts +17 -13
  29. package/dist/element-class.js +1 -1
  30. package/dist/element.js +1 -1
  31. package/dist/extraction/ExtractionRegistry.d.ts +34 -11
  32. package/dist/extraction/ExtractionRegistry.js +122 -19
  33. package/dist/extraction/ExtractionRegistry.js.map +1 -1
  34. package/dist/extraction/createContext.d.ts +5 -6
  35. package/dist/extraction/createContext.js +2 -2
  36. package/dist/extraction/createContext.js.map +1 -1
  37. package/dist/extraction/deliveryTypes.d.ts +26 -0
  38. package/dist/extraction/deliveryTypes.js +7 -0
  39. package/dist/extraction/deliveryTypes.js.map +1 -0
  40. package/dist/extraction/index.d.ts +3 -3
  41. package/dist/extraction/index.js +1 -2
  42. package/dist/extraction/index.js.map +1 -1
  43. package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
  44. package/dist/extraction/interactionExtractionPipeline.js +27 -10
  45. package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
  46. package/dist/extraction/interactionSecurity.d.ts +11 -2
  47. package/dist/extraction/interactionSecurity.js +105 -40
  48. package/dist/extraction/interactionSecurity.js.map +1 -1
  49. package/dist/extraction/types.d.ts +44 -7
  50. package/dist/extraction/types.js.map +1 -1
  51. package/dist/extraction/utils.js +4 -16
  52. package/dist/extraction/utils.js.map +1 -1
  53. package/dist/index.d.ts +9 -9
  54. package/dist/index.js +5 -8
  55. package/dist/index.js.map +1 -1
  56. package/dist/interactions/associate/extractor.js +1 -1
  57. package/dist/interactions/associate/extractor.js.map +1 -1
  58. package/dist/interactions/drawing/extractor.js +5 -4
  59. package/dist/interactions/drawing/extractor.js.map +1 -1
  60. package/dist/interactions/end-attempt/extractor.js +2 -2
  61. package/dist/interactions/end-attempt/extractor.js.map +1 -1
  62. package/dist/interactions/gap-match/extractor.js +4 -3
  63. package/dist/interactions/gap-match/extractor.js.map +1 -1
  64. package/dist/interactions/graphic-associate/extractor.js +5 -4
  65. package/dist/interactions/graphic-associate/extractor.js.map +1 -1
  66. package/dist/interactions/graphic-gap-match/extractor.js +20 -17
  67. package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
  68. package/dist/interactions/graphic-order/extractor.js +5 -4
  69. package/dist/interactions/graphic-order/extractor.js.map +1 -1
  70. package/dist/interactions/hotspot/extractor.js +11 -10
  71. package/dist/interactions/hotspot/extractor.js.map +1 -1
  72. package/dist/interactions/inline/render-plan.d.ts +3 -5
  73. package/dist/interactions/inline/render-plan.js.map +1 -1
  74. package/dist/interactions/media/extractor.js +2 -2
  75. package/dist/interactions/media/extractor.js.map +1 -1
  76. package/dist/interactions/modules.d.ts +11 -91
  77. package/dist/interactions/modules.js +185 -45
  78. package/dist/interactions/modules.js.map +1 -1
  79. package/dist/interactions/portable-custom/extractor.d.ts +1 -1
  80. package/dist/interactions/portable-custom/extractor.js +1 -1
  81. package/dist/interactions/portable-custom/extractor.js.map +1 -1
  82. package/dist/interactions/position-object/extractor.js +3 -2
  83. package/dist/interactions/position-object/extractor.js.map +1 -1
  84. package/dist/interactions/select-point/extractor.js +7 -6
  85. package/dist/interactions/select-point/extractor.js.map +1 -1
  86. package/dist/interactions/shared/types.d.ts +59 -70
  87. package/dist/interactions/shared/types.js.map +1 -1
  88. package/dist/interactions/slider/extractor.js +2 -2
  89. package/dist/interactions/slider/extractor.js.map +1 -1
  90. package/dist/interactions/upload/extractor.js +2 -2
  91. package/dist/interactions/upload/extractor.js.map +1 -1
  92. package/dist/pci/types.d.ts +2 -3
  93. package/dist/pci/types.js.map +1 -1
  94. package/dist/presentation/itemPresentationPlan.d.ts +71 -38
  95. package/dist/presentation/itemPresentationPlan.js +82 -35
  96. package/dist/presentation/itemPresentationPlan.js.map +1 -1
  97. package/dist/security/index.d.ts +1 -1
  98. package/dist/security/index.js +1 -1
  99. package/dist/security/index.js.map +1 -1
  100. package/dist/security/styleValues.d.ts +20 -0
  101. package/dist/security/styleValues.js +49 -0
  102. package/dist/security/styleValues.js.map +1 -0
  103. package/dist/server.d.ts +188 -9
  104. package/dist/server.js +32 -7
  105. package/dist/server.js.map +1 -1
  106. package/dist/types/index.d.ts +1 -110
  107. package/dist/types/index.js.map +1 -1
  108. package/dist/web-components/QTIInteractionBase.d.ts +2 -2
  109. package/dist/web-components/QTIInteractionBase.js.map +1 -1
  110. package/dist/web-components/QTIInteractionElement.d.ts +3 -3
  111. package/dist/web-components/QTIInteractionElement.js.map +1 -1
  112. package/package.json +11 -11
  113. package/dist/core/Plugin.d.ts +0 -104
  114. package/dist/core/Plugin.js +0 -8
  115. package/dist/core/Plugin.js.map +0 -1
  116. package/dist/core/PluginManager.d.ts +0 -55
  117. package/dist/core/PluginManager.js +0 -148
  118. package/dist/core/PluginManager.js.map +0 -1
  119. package/dist/core/declarations.d.ts +0 -44
  120. package/dist/core/declarations.js +0 -141
  121. package/dist/core/declarations.js.map +0 -1
  122. package/dist/element-class-BEpwHdcP.js.map +0 -1
  123. package/dist/interactions/associate/index.d.ts +0 -2
  124. package/dist/interactions/associate/index.js +0 -2
  125. package/dist/interactions/associate/index.js.map +0 -1
  126. package/dist/interactions/associate/types.d.ts +0 -1
  127. package/dist/interactions/associate/types.js +0 -2
  128. package/dist/interactions/associate/types.js.map +0 -1
  129. package/dist/interactions/choice/index.d.ts +0 -2
  130. package/dist/interactions/choice/index.js +0 -2
  131. package/dist/interactions/choice/index.js.map +0 -1
  132. package/dist/interactions/choice/types.d.ts +0 -1
  133. package/dist/interactions/choice/types.js +0 -2
  134. package/dist/interactions/choice/types.js.map +0 -1
  135. package/dist/interactions/custom/index.d.ts +0 -2
  136. package/dist/interactions/custom/index.js +0 -2
  137. package/dist/interactions/custom/index.js.map +0 -1
  138. package/dist/interactions/custom/types.d.ts +0 -1
  139. package/dist/interactions/custom/types.js +0 -2
  140. package/dist/interactions/custom/types.js.map +0 -1
  141. package/dist/interactions/drawing/index.d.ts +0 -2
  142. package/dist/interactions/drawing/index.js +0 -2
  143. package/dist/interactions/drawing/index.js.map +0 -1
  144. package/dist/interactions/drawing/types.d.ts +0 -1
  145. package/dist/interactions/drawing/types.js +0 -2
  146. package/dist/interactions/drawing/types.js.map +0 -1
  147. package/dist/interactions/end-attempt/index.d.ts +0 -2
  148. package/dist/interactions/end-attempt/index.js +0 -2
  149. package/dist/interactions/end-attempt/index.js.map +0 -1
  150. package/dist/interactions/end-attempt/types.d.ts +0 -1
  151. package/dist/interactions/end-attempt/types.js +0 -2
  152. package/dist/interactions/end-attempt/types.js.map +0 -1
  153. package/dist/interactions/extended-text/index.d.ts +0 -3
  154. package/dist/interactions/extended-text/index.js +0 -3
  155. package/dist/interactions/extended-text/index.js.map +0 -1
  156. package/dist/interactions/extended-text/types.d.ts +0 -1
  157. package/dist/interactions/extended-text/types.js +0 -2
  158. package/dist/interactions/extended-text/types.js.map +0 -1
  159. package/dist/interactions/gap-match/index.d.ts +0 -2
  160. package/dist/interactions/gap-match/index.js +0 -2
  161. package/dist/interactions/gap-match/index.js.map +0 -1
  162. package/dist/interactions/gap-match/types.d.ts +0 -1
  163. package/dist/interactions/gap-match/types.js +0 -2
  164. package/dist/interactions/gap-match/types.js.map +0 -1
  165. package/dist/interactions/graphic-associate/index.d.ts +0 -2
  166. package/dist/interactions/graphic-associate/index.js +0 -2
  167. package/dist/interactions/graphic-associate/index.js.map +0 -1
  168. package/dist/interactions/graphic-associate/types.d.ts +0 -1
  169. package/dist/interactions/graphic-associate/types.js +0 -2
  170. package/dist/interactions/graphic-associate/types.js.map +0 -1
  171. package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
  172. package/dist/interactions/graphic-gap-match/index.js +0 -2
  173. package/dist/interactions/graphic-gap-match/index.js.map +0 -1
  174. package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
  175. package/dist/interactions/graphic-gap-match/types.js +0 -2
  176. package/dist/interactions/graphic-gap-match/types.js.map +0 -1
  177. package/dist/interactions/graphic-order/index.d.ts +0 -2
  178. package/dist/interactions/graphic-order/index.js +0 -2
  179. package/dist/interactions/graphic-order/index.js.map +0 -1
  180. package/dist/interactions/graphic-order/types.d.ts +0 -1
  181. package/dist/interactions/graphic-order/types.js +0 -2
  182. package/dist/interactions/graphic-order/types.js.map +0 -1
  183. package/dist/interactions/hotspot/index.d.ts +0 -2
  184. package/dist/interactions/hotspot/index.js +0 -2
  185. package/dist/interactions/hotspot/index.js.map +0 -1
  186. package/dist/interactions/hotspot/types.d.ts +0 -1
  187. package/dist/interactions/hotspot/types.js +0 -2
  188. package/dist/interactions/hotspot/types.js.map +0 -1
  189. package/dist/interactions/hottext/index.d.ts +0 -2
  190. package/dist/interactions/hottext/index.js +0 -2
  191. package/dist/interactions/hottext/index.js.map +0 -1
  192. package/dist/interactions/hottext/types.d.ts +0 -1
  193. package/dist/interactions/hottext/types.js +0 -2
  194. package/dist/interactions/hottext/types.js.map +0 -1
  195. package/dist/interactions/index.d.ts +0 -32
  196. package/dist/interactions/index.js +0 -31
  197. package/dist/interactions/index.js.map +0 -1
  198. package/dist/interactions/inline/index.d.ts +0 -1
  199. package/dist/interactions/inline/index.js +0 -2
  200. package/dist/interactions/inline/index.js.map +0 -1
  201. package/dist/interactions/inline-choice/index.d.ts +0 -2
  202. package/dist/interactions/inline-choice/index.js +0 -2
  203. package/dist/interactions/inline-choice/index.js.map +0 -1
  204. package/dist/interactions/inline-choice/types.d.ts +0 -1
  205. package/dist/interactions/inline-choice/types.js +0 -2
  206. package/dist/interactions/inline-choice/types.js.map +0 -1
  207. package/dist/interactions/match/index.d.ts +0 -2
  208. package/dist/interactions/match/index.js +0 -2
  209. package/dist/interactions/match/index.js.map +0 -1
  210. package/dist/interactions/match/types.d.ts +0 -1
  211. package/dist/interactions/match/types.js +0 -2
  212. package/dist/interactions/match/types.js.map +0 -1
  213. package/dist/interactions/media/index.d.ts +0 -2
  214. package/dist/interactions/media/index.js +0 -2
  215. package/dist/interactions/media/index.js.map +0 -1
  216. package/dist/interactions/media/types.d.ts +0 -1
  217. package/dist/interactions/media/types.js +0 -2
  218. package/dist/interactions/media/types.js.map +0 -1
  219. package/dist/interactions/order/index.d.ts +0 -2
  220. package/dist/interactions/order/index.js +0 -2
  221. package/dist/interactions/order/index.js.map +0 -1
  222. package/dist/interactions/order/types.d.ts +0 -1
  223. package/dist/interactions/order/types.js +0 -2
  224. package/dist/interactions/order/types.js.map +0 -1
  225. package/dist/interactions/portable-custom/index.d.ts +0 -2
  226. package/dist/interactions/portable-custom/index.js +0 -2
  227. package/dist/interactions/portable-custom/index.js.map +0 -1
  228. package/dist/interactions/portable-custom/types.d.ts +0 -1
  229. package/dist/interactions/portable-custom/types.js +0 -2
  230. package/dist/interactions/portable-custom/types.js.map +0 -1
  231. package/dist/interactions/position-object/index.d.ts +0 -2
  232. package/dist/interactions/position-object/index.js +0 -2
  233. package/dist/interactions/position-object/index.js.map +0 -1
  234. package/dist/interactions/position-object/types.d.ts +0 -1
  235. package/dist/interactions/position-object/types.js +0 -2
  236. package/dist/interactions/position-object/types.js.map +0 -1
  237. package/dist/interactions/select-point/index.d.ts +0 -2
  238. package/dist/interactions/select-point/index.js +0 -2
  239. package/dist/interactions/select-point/index.js.map +0 -1
  240. package/dist/interactions/select-point/types.d.ts +0 -1
  241. package/dist/interactions/select-point/types.js +0 -2
  242. package/dist/interactions/select-point/types.js.map +0 -1
  243. package/dist/interactions/shared/index.d.ts +0 -1
  244. package/dist/interactions/shared/index.js +0 -2
  245. package/dist/interactions/shared/index.js.map +0 -1
  246. package/dist/interactions/slider/index.d.ts +0 -2
  247. package/dist/interactions/slider/index.js +0 -2
  248. package/dist/interactions/slider/index.js.map +0 -1
  249. package/dist/interactions/slider/types.d.ts +0 -1
  250. package/dist/interactions/slider/types.js +0 -2
  251. package/dist/interactions/slider/types.js.map +0 -1
  252. package/dist/interactions/text-entry/index.d.ts +0 -2
  253. package/dist/interactions/text-entry/index.js +0 -2
  254. package/dist/interactions/text-entry/index.js.map +0 -1
  255. package/dist/interactions/text-entry/types.d.ts +0 -1
  256. package/dist/interactions/text-entry/types.js +0 -2
  257. package/dist/interactions/text-entry/types.js.map +0 -1
  258. package/dist/interactions/upload/index.d.ts +0 -2
  259. package/dist/interactions/upload/index.js +0 -2
  260. package/dist/interactions/upload/index.js.map +0 -1
  261. package/dist/interactions/upload/types.d.ts +0 -1
  262. package/dist/interactions/upload/types.js +0 -2
  263. package/dist/interactions/upload/types.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { buildOutcomeProcessingAst, buildResponseProcessingAst, buildTemplateProcessingAst, childElements, coerceBaseValue, DeclarationContext, evalExpr, execProgram, findDescendants, findFirstDescendant, getAttr, OperatorRegistry, qtiNull, qtiValue, toBoolean, toNumber, toStringValue, } from '@pie-qti/qti-processing';
1
+ import { buildOutcomeProcessingAst, buildResponseProcessingAst, buildTemplateProcessingAst, coerceBaseValue, DeclarationContext, evalExpr, execProgram, findDescendants, findFirstDescendant, getAttr, OperatorRegistry, qtiNull, qtiValue, toBoolean, toNumber, toStringValue, } from '@pie-qti/qti-processing';
2
2
  import { Qti2xElementNameMapper, Qti2xAttributeNameMapper, Qti3ElementNameMapper, Qti3AttributeNameMapper, detectQtiVersion, } from '@pie-qti/qti-common';
3
3
  import { parseAssessmentItemDocument } from '../document/AssessmentItemDocument.js';
4
- import { createExtractionRegistry } from '../extraction/ExtractionRegistry.js';
4
+ import { createExtractionRegistry, registerFrameworkDeliveryFields, } from '../extraction/ExtractionRegistry.js';
5
5
  import { extractInteractionData } from '../extraction/interactionExtractionPipeline.js';
6
- import { getStandardInteractionExtractors } from '../interactions/modules.js';
6
+ import { getStandardInteractionModules } from '../interactions/modules.js';
7
7
  import { createComponentRegistry } from './ComponentRegistry.js';
8
8
  import { createSeededRng } from './random.js';
9
9
  import { sanitizeHtml } from './sanitizer.js';
@@ -14,8 +14,26 @@ import { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from '../cat
14
14
  import { getCatalogEntry } from '../catalog/catalogLookup.js';
15
15
  import { PciHost } from '../pci/PciHost.js';
16
16
  import { createExtendedTextNumericRecord, EXTENDED_TEXT_RECORD_FIELD_TYPES, } from '../interactions/extended-text/response.js';
17
+ /** @internal Used by AssessmentItemDefinition; deliberately absent from the package root API. */
18
+ export function preparePlayerDefinitionInternal(config) {
19
+ const compiler = new Player(config, undefined, { compileOnly: true });
20
+ try {
21
+ return compiler.capturePreparedDefinition();
22
+ }
23
+ finally {
24
+ compiler.destroy();
25
+ }
26
+ }
27
+ /** @internal Used by ItemSession; deliberately absent from the package root API. */
28
+ export function createPlayerFromPreparedInternal(config, prepared, skipTemplateProcessing = false) {
29
+ return new Player(config, prepared, {
30
+ skipTemplateProcessing,
31
+ });
32
+ }
17
33
  export class Player {
18
- constructor(config) {
34
+ constructor(config, prepared, construction = {}) {
35
+ this.interactionDataCache = null;
36
+ this.warnedImpliedZeroMaxScore = false;
19
37
  this.responseProcessingProgram = null;
20
38
  this.templateProcessingProgram = null;
21
39
  this.outcomeProcessingProgram = null;
@@ -31,101 +49,100 @@ export class Player {
31
49
  this.sessionGuid = createSessionGuid();
32
50
  this.sessionStartedAt = Date.now();
33
51
  this.rng = config.rng ?? (typeof config.seed === 'number' ? createSeededRng(config.seed) : Math.random);
34
- // Auto-detect QTI version and create appropriate mappers if not provided
35
- if (!config.elementNameMapper) {
52
+ // Resolve QTI-version mappers without mutating caller-owned configuration.
53
+ if (prepared) {
54
+ this.mapper = prepared.mapper;
55
+ }
56
+ else if (!config.elementNameMapper) {
36
57
  const version = detectQtiVersion(this.itemXml);
37
58
  if (version === '3.0') {
38
59
  this.mapper = new Qti3ElementNameMapper();
39
- // Set in config so it's available to extraction utils
40
- config.elementNameMapper = this.mapper;
41
- // Also set attribute mapper if not provided
42
- if (!config.attributeNameMapper) {
43
- config.attributeNameMapper = new Qti3AttributeNameMapper();
44
- }
45
60
  }
46
61
  else {
47
62
  this.mapper = new Qti2xElementNameMapper();
48
- config.elementNameMapper = this.mapper;
49
- if (!config.attributeNameMapper) {
50
- config.attributeNameMapper = new Qti2xAttributeNameMapper();
51
- }
52
63
  }
53
64
  }
54
65
  else {
55
66
  this.mapper = config.elementNameMapper;
56
- if (!config.attributeNameMapper) {
57
- config.attributeNameMapper =
58
- this.mapper.version === '3.0'
59
- ? new Qti3AttributeNameMapper()
60
- : new Qti2xAttributeNameMapper();
61
- }
62
67
  }
63
- this.itemDocument = parseAssessmentItemDocument({
64
- itemXml: this.itemXml,
68
+ const attributeMapper = prepared?.attributeMapper ??
69
+ config.attributeNameMapper ??
70
+ (this.mapper.version === '3.0'
71
+ ? new Qti3AttributeNameMapper()
72
+ : new Qti2xAttributeNameMapper());
73
+ this.config = {
74
+ ...config,
65
75
  elementNameMapper: this.mapper,
66
- attributeNameMapper: config.attributeNameMapper,
67
- security: this.config.security,
68
- });
69
- this.assessmentItem = this.itemDocument.getAssessmentItem();
70
- this.decls = this.buildDeclarations();
71
- this.ensureBuiltinDeclarations(this.decls);
76
+ attributeNameMapper: attributeMapper,
77
+ };
78
+ if (prepared) {
79
+ this.itemDocument = prepared.itemDocument;
80
+ this.decls = cloneDeclarationMap(prepared.declarations);
81
+ }
82
+ else {
83
+ this.itemDocument = parseAssessmentItemDocument({
84
+ itemXml: this.itemXml,
85
+ elementNameMapper: this.mapper,
86
+ attributeNameMapper: attributeMapper,
87
+ security: this.config.security,
88
+ });
89
+ this.decls = this.buildDeclarations();
90
+ this.ensureBuiltinDeclarations(this.decls);
91
+ }
92
+ this.sourceDeclarations = cloneDeclarationMap(this.decls);
72
93
  this.ctx = new DeclarationContext(this.decls);
73
94
  this.ops = new OperatorRegistry();
74
- // Restore session state (outcomes + responses) before running templateProcessing.
75
- if (config.sessionState) {
76
- this.applySessionState(config.sessionState);
77
- }
78
95
  // Extraction + rendering registries (for interaction rendering)
79
96
  // Pass the element name mapper to the extraction registry for QTI version handling
80
- this.extractionRegistry = config.extractionRegistry ?? createExtractionRegistry(this.mapper);
81
- this.componentRegistry = config.componentRegistry ?? createComponentRegistry();
97
+ this.extractionRegistry =
98
+ this.config.extractionRegistry ??
99
+ createExtractionRegistry(this.mapper);
100
+ this.componentRegistry =
101
+ this.config.componentRegistry ??
102
+ createComponentRegistry();
82
103
  // I18n provider (defaults to a simple fallback if not provided)
83
- this.i18nProvider = config.i18nProvider ?? this.createDefaultI18nProvider();
84
- // Register standard interaction extractors (idempotent per-registry instance)
85
- for (const ex of getStandardInteractionExtractors()) {
86
- try {
87
- this.extractionRegistry.register(ex);
88
- }
89
- catch {
90
- // ignore duplicates if a caller pre-registered
91
- }
92
- }
93
- // Plugins can further extend registries
94
- for (const p of (config.plugins ?? [])) {
95
- try {
96
- p?.registerExtractors?.(this.extractionRegistry);
97
- p?.registerComponents?.(this.componentRegistry);
98
- }
99
- catch {
100
- // plugin errors shouldn't prevent core parsing
104
+ this.i18nProvider = this.config.i18nProvider ?? this.createDefaultI18nProvider();
105
+ if (!this.extractionRegistry.isSealed()) {
106
+ // Register standard interaction extractors.
107
+ for (const module of getStandardInteractionModules()) {
108
+ this.extractionRegistry.register(module.extractor);
109
+ registerFrameworkDeliveryFields(this.extractionRegistry, module.type, module.delivery);
101
110
  }
111
+ this.extractionRegistry.seal();
102
112
  }
103
113
  // Build ASTs once.
104
114
  const processingBuildOptions = {
105
115
  elementNameMapper: this.mapper,
106
- resolveProcessingFragment: config.resolveProcessingFragment,
107
- maxProcessingFragmentDepth: config.processingFragmentLimits?.maxDepth,
108
- maxProcessingFragmentCharacters: config.processingFragmentLimits?.maxCharacters,
116
+ resolveProcessingFragment: this.config.resolveProcessingFragment,
117
+ maxProcessingFragmentDepth: this.config.processingFragmentLimits?.maxDepth,
118
+ maxProcessingFragmentCharacters: this.config.processingFragmentLimits?.maxCharacters,
109
119
  };
110
- const templateProcessing = this.itemDocument.getProcessingElement('template');
111
- if (templateProcessing) {
112
- this.templateProcessingProgram = buildTemplateProcessingAst(templateProcessing, processingBuildOptions);
120
+ const templateProcessing = prepared ? null : this.itemDocument.getProcessingElement('template');
121
+ this.templateProcessingProgram =
122
+ prepared?.templateProcessingProgram ??
123
+ (templateProcessing
124
+ ? buildTemplateProcessingAst(templateProcessing, processingBuildOptions)
125
+ : null);
126
+ if (this.templateProcessingProgram &&
127
+ !construction.compileOnly &&
128
+ !construction.skipTemplateProcessing) {
113
129
  this.execTemplateProcessing();
114
130
  }
115
- const responseProcessing = this.itemDocument.getProcessingElement('response');
116
- if (responseProcessing) {
117
- this.responseProcessingProgram = buildResponseProcessingAst(responseProcessing, processingBuildOptions);
118
- }
119
- const outcomeProcessing = this.itemDocument.getProcessingElement('outcome');
120
- if (outcomeProcessing) {
121
- this.outcomeProcessingProgram = buildOutcomeProcessingAst(outcomeProcessing, processingBuildOptions);
122
- }
123
- // Apply initial responses after templateProcessing (so template vars are ready).
124
- if (config.responses) {
125
- this.setResponses(config.responses);
126
- }
131
+ const responseProcessing = prepared ? null : this.itemDocument.getProcessingElement('response');
132
+ this.responseProcessing = prepared?.responseProcessing ?? this.itemDocument.describeResponseProcessing();
133
+ this.responseProcessingProgram =
134
+ prepared?.responseProcessingProgram ??
135
+ (responseProcessing
136
+ ? buildResponseProcessingAst(responseProcessing, processingBuildOptions)
137
+ : null);
138
+ const outcomeProcessing = prepared ? null : this.itemDocument.getProcessingElement('outcome');
139
+ this.outcomeProcessingProgram =
140
+ prepared?.outcomeProcessingProgram ??
141
+ (outcomeProcessing
142
+ ? buildOutcomeProcessingAst(outcomeProcessing, processingBuildOptions)
143
+ : null);
127
144
  // Detect and log QTI version for compatibility awareness
128
- const detectedVersion = this.detectQTIVersion();
145
+ const detectedVersion = prepared ? null : this.detectQTIVersion();
129
146
  if (detectedVersion === 'unknown') {
130
147
  console.warn('[QTI Player] Could not detect QTI version. Assuming QTI 2.2 compatibility.');
131
148
  }
@@ -136,32 +153,58 @@ export class Player {
136
153
  console.info('[QTI Player] QTI 2.1 detected. Using QTI 2.2 compatibility mode with CC2 template support.');
137
154
  }
138
155
  // Store PNP profile for later use (applyPnpToRoot is called once a root element is available).
139
- this._pnp = config.pnp;
140
- // Build catalog index from legacy shared catalog XML, item XML, and resolved delivery context.
156
+ this._pnp = this.config.pnp;
157
+ // Build the catalog index from shared catalog XML, item XML, and resolved delivery context.
141
158
  // Sanitized item-level delivery context entries win over raw item XML on collisions.
142
159
  // Stimulus entries are kept separately so rendered stimulus terms can avoid ID collisions.
143
- let mergedCatalog = new Map();
144
- let deliveryItemCatalog = new Map();
145
- for (const source of config.deliveryContext?.catalogSources ?? []) {
146
- const sourceCatalog = extractCatalog(source.xml);
147
- if (source.scope === 'stimulus' && source.stimulusIdentifier) {
148
- const existing = this._stimulusCatalogIndexes.get(source.stimulusIdentifier) ?? new Map();
149
- this._stimulusCatalogIndexes.set(source.stimulusIdentifier, mergeCatalogs(existing, sourceCatalog));
160
+ if (prepared) {
161
+ this._catalogIndex = prepared.catalogIndex;
162
+ this._stimulusCatalogIndexes = prepared.stimulusCatalogIndexes;
163
+ }
164
+ else {
165
+ let mergedCatalog = new Map();
166
+ let deliveryItemCatalog = new Map();
167
+ for (const source of this.config.deliveryContext?.catalogSources ?? []) {
168
+ const sourceCatalog = extractCatalog(source.xml);
169
+ if (source.scope === 'stimulus' && source.stimulusIdentifier) {
170
+ const existing = this._stimulusCatalogIndexes.get(source.stimulusIdentifier) ?? new Map();
171
+ this._stimulusCatalogIndexes.set(source.stimulusIdentifier, mergeCatalogs(existing, sourceCatalog));
172
+ }
173
+ else {
174
+ deliveryItemCatalog = mergeCatalogs(deliveryItemCatalog, sourceCatalog);
175
+ }
150
176
  }
151
- else {
152
- deliveryItemCatalog = mergeCatalogs(deliveryItemCatalog, sourceCatalog);
177
+ if (this.config.catalogXml) {
178
+ mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(this.config.catalogXml));
153
179
  }
180
+ mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(this.itemXml));
181
+ this._catalogIndex = mergeCatalogs(mergedCatalog, deliveryItemCatalog);
154
182
  }
155
- if (config.catalogXml) {
156
- mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(config.catalogXml));
157
- }
158
- mergedCatalog = mergeCatalogs(mergedCatalog, extractCatalogFromItemXml(this.itemXml));
159
- this._catalogIndex = mergeCatalogs(mergedCatalog, deliveryItemCatalog);
160
183
  // Check strict compliance if enabled
161
- if (this.config.strictQtiCompliance?.enabled) {
184
+ if (!prepared && this.config.strictQtiCompliance?.enabled) {
162
185
  this.validateStrictCompliance();
163
186
  }
164
187
  }
188
+ /** @internal Definition compiler capture; parser artifacts remain module-private. */
189
+ capturePreparedDefinition() {
190
+ const identifier = this.itemDocument.getAssessmentItemAttribute('identifier')?.trim();
191
+ if (!identifier) {
192
+ throw new Error('AssessmentItemDefinition requires an assessment-item identifier');
193
+ }
194
+ return Object.freeze({
195
+ identifier,
196
+ mapper: this.mapper,
197
+ attributeMapper: this.config.attributeNameMapper,
198
+ itemDocument: this.itemDocument,
199
+ declarations: cloneDeclarationMap(this.sourceDeclarations),
200
+ responseProcessing: this.responseProcessing,
201
+ responseProcessingProgram: this.responseProcessingProgram,
202
+ templateProcessingProgram: this.templateProcessingProgram,
203
+ outcomeProcessingProgram: this.outcomeProcessingProgram,
204
+ catalogIndex: this._catalogIndex,
205
+ stimulusCatalogIndexes: this._stimulusCatalogIndexes,
206
+ });
207
+ }
165
208
  /**
166
209
  * Apply the PNP profile to a player root element.
167
210
  * Call this once the root DOM element is available (e.g. after mounting).
@@ -212,7 +255,7 @@ export class Player {
212
255
  if (looksLikeCatalogUrl(html)) {
213
256
  return sanitizeResourceUrl(html.trim(), this.config.security?.urlPolicy, 'img');
214
257
  }
215
- return this.sanitizeHtmlContent(html);
258
+ return toTrustedHtml(this.sanitizeHtmlContent(html), this.config.security?.trustedTypesPolicyName);
216
259
  }
217
260
  /** Sanitize externally resolved item-adjacent HTML before it reaches a rendering sink. */
218
261
  sanitizeHtmlContent(html) {
@@ -225,11 +268,13 @@ export class Player {
225
268
  */
226
269
  createPciHost(data) {
227
270
  const host = new PciHost(data, {
228
- baseUrl: this.config.pci?.baseUrl ?? this.config.pciBaseUrl,
271
+ baseUrl: this.config.pci?.baseUrl,
229
272
  moduleResolver: this.config.pci?.moduleResolver,
230
273
  });
231
274
  // Wire response changes back into the player's declaration context
232
275
  host.onResponseChange((responseId, value) => {
276
+ if (this.lifecycleStatus !== 'initial' && this.lifecycleStatus !== 'interacting')
277
+ return;
233
278
  const d = this.decls[responseId];
234
279
  if (d) {
235
280
  d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, value, d.identifier);
@@ -278,7 +323,7 @@ export class Player {
278
323
  continue;
279
324
  d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, raw, d.identifier);
280
325
  // Push restored responses into any mounted PCI modules
281
- this.setPciResponse(id, raw);
326
+ this.setPciResponse(id, this.qtiValueToPublic(d.value));
282
327
  }
283
328
  }
284
329
  /**
@@ -297,6 +342,7 @@ export class Player {
297
342
  }
298
343
  restoreItemSession(state) {
299
344
  this.sessionGuid = state.sessionGuid;
345
+ this.interactionDataCache = null;
300
346
  this.lifecycleStatus = state.lifecycleStatus;
301
347
  this.accumulatedDurationMs = Math.max(0, Number(state.duration) || 0);
302
348
  this.sessionStartedAt = Date.now();
@@ -306,6 +352,15 @@ export class Player {
306
352
  this.applySerializedVariables(state.contextVariables);
307
353
  this.updateDuration();
308
354
  }
355
+ /** @internal ItemSession uses this to activate a restored delivery handoff. */
356
+ getLifecycleStatus() {
357
+ return this.lifecycleStatus;
358
+ }
359
+ /** @internal ItemSession uses this to resume a suspended delivery handoff. */
360
+ activateAttempt() {
361
+ if (this.lifecycleStatus === 'suspended')
362
+ this.lifecycleStatus = 'interacting';
363
+ }
309
364
  suspendAttempt() {
310
365
  return this.runItemSessionAction({ action: 'suspendAttempt' });
311
366
  }
@@ -451,30 +506,7 @@ export class Player {
451
506
  * @returns QTI version string ('2.0', '2.1', '2.2') or 'unknown'
452
507
  */
453
508
  detectQTIVersion() {
454
- const ns = this.assessmentItem.namespaceURI;
455
- if (ns?.includes('v3p0') || ns?.includes('imsqtiasi_v3p0'))
456
- return '3.0';
457
- if (ns?.includes('v2p2') || ns?.includes('imsqti_v2p2'))
458
- return '2.2';
459
- if (ns?.includes('v2p1') || ns?.includes('imsqti_v2p1'))
460
- return '2.1';
461
- if (ns?.includes('v2p0') || ns?.includes('imsqti_v2p0'))
462
- return '2.0';
463
- // Check element name for QTI 3.0
464
- const localName = this.assessmentItem.localName || this.assessmentItem.tagName;
465
- if (localName === 'qti-assessment-item' || localName === 'qti-assessment-test') {
466
- return '3.0';
467
- }
468
- const versionAttr = getAttr(this.assessmentItem, 'version');
469
- if (versionAttr?.startsWith('3.'))
470
- return '3.0';
471
- if (versionAttr === '2.0')
472
- return '2.0';
473
- if (versionAttr === '2.1')
474
- return '2.1';
475
- if (versionAttr === '2.2')
476
- return '2.2';
477
- return 'unknown';
509
+ return this.itemDocument.detectVersion();
478
510
  }
479
511
  /**
480
512
  * Validates strict QTI 2.2 compliance if enabled in configuration.
@@ -522,24 +554,38 @@ export class Player {
522
554
  this.ctx.resetToDefault(d.identifier);
523
555
  }
524
556
  }
557
+ /**
558
+ * A MAXSCORE declared without a <defaultValue> is 0 per the numeric outcome rule, so an item
559
+ * that never assigns it scores against a maximum of zero. That is the spec-correct reading of
560
+ * under-specified content, and silently substituting 1 would make this engine disagree with a
561
+ * conformant one — so surface the authoring gap instead of masking it.
562
+ */
563
+ warnOnceOnImpliedZeroMaxScore(outcomes) {
564
+ if (this.warnedImpliedZeroMaxScore)
565
+ return;
566
+ if (!this.decls.MAXSCORE?.impliedNumericDefault)
567
+ return;
568
+ if (outcomes.MAXSCORE !== 0)
569
+ return;
570
+ this.warnedImpliedZeroMaxScore = true;
571
+ console.warn(`[QTI Player] MAXSCORE is 0 for item "${this.itemDocument.getAssessmentItemAttribute('identifier') ?? 'unknown'}": its outcomeDeclaration ` +
572
+ 'has no <defaultValue>, so QTI initializes it to 0 and response processing never assigned it. ' +
573
+ 'Declare <defaultValue> on the MAXSCORE outcomeDeclaration to score against a real maximum.');
574
+ }
525
575
  runResponseProcessing(options) {
526
576
  this.updateDuration();
527
577
  // Spec-aligned behavior: each processing run starts from outcome defaults.
528
578
  // This prevents stale outcomes when response/outcome processing doesn't set every variable.
529
579
  this.resetOutcomesToDefault();
530
580
  // Execute response processing if present
531
- const rpEl = this.itemDocument.getProcessingElement('response');
532
- if (rpEl) {
581
+ if (this.responseProcessing.present) {
533
582
  // If responseProcessing has explicit statements, run the compiled program.
534
583
  // Otherwise, fall back to template-based processing (responseProcessing@template).
535
- const hasStatements = childElements(rpEl).length > 0;
536
- if (hasStatements) {
584
+ if (this.responseProcessing.hasStatements) {
537
585
  this.execResponseProcessingProgram();
538
586
  }
539
- else {
540
- const templateUrl = getAttr(rpEl, 'template');
541
- if (templateUrl)
542
- this.execResponseProcessingTemplate(templateUrl);
587
+ else if (this.responseProcessing.template) {
588
+ this.execResponseProcessingTemplate(this.responseProcessing.template);
543
589
  }
544
590
  }
545
591
  // Execute outcome processing if present (runs after responseProcessing)
@@ -554,6 +600,7 @@ export class Player {
554
600
  }
555
601
  }
556
602
  const outcomes = this.collectOutcomes();
603
+ this.warnOnceOnImpliedZeroMaxScore(outcomes);
557
604
  const score = Number(outcomes.SCORE ?? 0);
558
605
  const maxScore = Number(outcomes.MAXSCORE ?? 1);
559
606
  const completionStatus = outcomes.completionStatus ?? 'not_attempted';
@@ -582,25 +629,22 @@ export class Player {
582
629
  */
583
630
  getRubrics(options = {}) {
584
631
  const role = this.role;
585
- const rubricEls = this.itemDocument.findRubricElements();
586
- if (rubricEls.length === 0)
632
+ const rubrics = this.itemDocument.readRubricBlocks();
633
+ if (rubrics.length === 0)
587
634
  return [];
588
635
  const blocks = [];
589
- for (const el of rubricEls) {
590
- const scope = this.itemDocument.rubricElementScope(el);
636
+ for (const rubric of rubrics) {
637
+ const { scope } = rubric;
591
638
  if (options.scope && options.scope !== 'all' && scope !== options.scope)
592
639
  continue;
593
- const viewRaw = (getAttr(el, 'view') || '').trim();
594
- const view = viewRaw ? viewRaw.split(/[\s,]+/).filter(Boolean) : [];
595
- const use = (getAttr(el, 'use') || '').trim() || undefined;
640
+ const view = [...rubric.view];
596
641
  // If view is specified, show only when it includes the current role.
597
642
  if (view.length > 0 && role && !view.includes(role))
598
643
  continue;
599
- const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
600
- const printed = this.renderPrintedVariables(contentRaw);
644
+ const printed = this.renderPrintedVariables(rubric.content);
601
645
  const sanitized = sanitizeHtml(printed, { security: this.config.security });
602
646
  const html = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
603
- blocks.push({ view, html, scope, use });
647
+ blocks.push({ view, html, scope, use: rubric.use });
604
648
  }
605
649
  return blocks;
606
650
  }
@@ -614,7 +658,9 @@ export class Player {
614
658
  * Canonical interaction API (new): extracted, typed interaction data.
615
659
  */
616
660
  getInteractionData() {
617
- return extractInteractionData({
661
+ if (this.interactionDataCache)
662
+ return this.interactionDataCache;
663
+ this.interactionDataCache = extractInteractionData({
618
664
  document: this.itemDocument,
619
665
  extractionRegistry: this.extractionRegistry,
620
666
  declarations: this.decls,
@@ -624,6 +670,7 @@ export class Player {
624
670
  // different candidate or a new attempt gets a different one.
625
671
  sessionGuid: this.sessionGuid,
626
672
  });
673
+ return this.interactionDataCache;
627
674
  }
628
675
  /**
629
676
  * Convenience API (used by tests/bench): returns a minimal interaction list with QTI-ish field names.
@@ -662,10 +709,6 @@ export class Player {
662
709
  isCompleted() {
663
710
  return this.getCompletionStatus() === 'completed';
664
711
  }
665
- submitAttempt(countAttempt = true) {
666
- const result = this.runItemSessionAction({ action: 'submitAttempt', countAttempt });
667
- return result.scoring;
668
- }
669
712
  runAdaptiveSubmitAttempt(countAttempt = true) {
670
713
  if (this.isCompleted()) {
671
714
  throw new Error('Cannot submit: item is already completed');
@@ -1068,7 +1111,9 @@ export class Player {
1068
1111
  : (this.getAttrMapped(el, 'baseType') || 'string');
1069
1112
  if (!identifier)
1070
1113
  return;
1071
- const defaultValue = this.parseDefaultValue(el, baseType, cardinality);
1114
+ const declaredDefault = this.parseDefaultValue(el, baseType, cardinality);
1115
+ const impliedNumericDefault = !declaredDefault && this.hasImpliedNumericDefault(kind, baseType, cardinality);
1116
+ const defaultValue = declaredDefault ?? this.impliedDefaultValue(kind, baseType, cardinality);
1072
1117
  decls[identifier] = {
1073
1118
  identifier,
1074
1119
  ...(baseType ? { baseType } : {}),
@@ -1076,6 +1121,7 @@ export class Player {
1076
1121
  defaultValue,
1077
1122
  value: defaultValue,
1078
1123
  isTemplate: kind === 'template',
1124
+ impliedNumericDefault,
1079
1125
  // @ts-expect-error internal marker for templates
1080
1126
  __kind: kind,
1081
1127
  };
@@ -1229,7 +1275,7 @@ export class Player {
1229
1275
  continue;
1230
1276
  d.value = this.coerceToDeclarationValue(d.baseType, d.cardinality, v.value, d.identifier);
1231
1277
  if (d.__kind === 'response') {
1232
- this.setPciResponse(d.identifier, v.value);
1278
+ this.setPciResponse(d.identifier, this.qtiValueToPublic(d.value));
1233
1279
  }
1234
1280
  }
1235
1281
  }
@@ -1284,7 +1330,7 @@ export class Player {
1284
1330
  if (!value || value.kind !== 'value')
1285
1331
  return null;
1286
1332
  if (value.cardinality !== 'record')
1287
- return value.value;
1333
+ return cloneRuntimeValue(value.value);
1288
1334
  const serialized = {};
1289
1335
  for (const [fieldIdentifier, fieldValue] of Object.entries(value.value)) {
1290
1336
  serialized[fieldIdentifier] = {
@@ -1299,7 +1345,7 @@ export class Player {
1299
1345
  if (!value || value.kind !== 'value')
1300
1346
  return null;
1301
1347
  if (value.cardinality !== 'record')
1302
- return value.value;
1348
+ return cloneRuntimeValue(value.value);
1303
1349
  const record = {};
1304
1350
  for (const [fieldIdentifier, fieldValue] of Object.entries(value.value)) {
1305
1351
  record[fieldIdentifier] = this.qtiValueToPublic(fieldValue);
@@ -1322,10 +1368,28 @@ export class Player {
1322
1368
  const value = this.ctx.getValue('duration');
1323
1369
  return Math.max(0, Math.floor(toNumber(value) || 0));
1324
1370
  }
1371
+ /**
1372
+ * QTI 2.1 §5.2, carried into 2.2 and 3.0: an outcome variable with no declared default is
1373
+ * initialized to NULL unless it is of a numeric type, in which case it is initialized to 0.
1374
+ * Response and template variables keep NULL — an unanswered numeric response must stay
1375
+ * distinguishable from an answered zero.
1376
+ */
1377
+ hasImpliedNumericDefault(kind, baseType, cardinality) {
1378
+ if (kind !== 'outcome' || cardinality !== 'single')
1379
+ return false;
1380
+ return baseType === 'integer' || baseType === 'float';
1381
+ }
1382
+ impliedDefaultValue(kind, baseType, cardinality) {
1383
+ if (this.hasImpliedNumericDefault(kind, baseType, cardinality)) {
1384
+ return qtiValue(baseType, 'single', 0);
1385
+ }
1386
+ return qtiNull(baseType, cardinality);
1387
+ }
1388
+ /** Returns undefined when the declaration carries no <defaultValue> at all. */
1325
1389
  parseDefaultValue(declEl, baseType, cardinality) {
1326
1390
  const defaultEl = findFirstDescendant(declEl, this.mapper.toNative('defaultvalue'));
1327
1391
  if (!defaultEl)
1328
- return qtiNull(baseType, cardinality);
1392
+ return undefined;
1329
1393
  return this.parseDeclarationValues(defaultEl, baseType, cardinality);
1330
1394
  }
1331
1395
  parseCorrectResponse(correctEl, baseType, cardinality) {
@@ -1420,7 +1484,7 @@ export class Player {
1420
1484
  return qtiNull(baseType, cardinality);
1421
1485
  // Allow callers to pass fully-formed QtiValue (e.g. session restore).
1422
1486
  if (typeof raw === 'object' && raw && 'kind' in raw) {
1423
- return raw;
1487
+ return cloneRuntimeValue(raw);
1424
1488
  }
1425
1489
  const extendedTextBase = identifier ? this.getExtendedTextBase(identifier) : undefined;
1426
1490
  if (cardinality === 'record') {
@@ -1432,11 +1496,9 @@ export class Player {
1432
1496
  if (baseType === 'file') {
1433
1497
  if (cardinality === 'multiple' || cardinality === 'ordered') {
1434
1498
  const arr = Array.isArray(raw) ? raw : [raw];
1435
- // For file types, preserve objects (QTIFileResponse) directly
1436
- return qtiValue(baseType, cardinality, arr.filter((v) => v !== null && v !== undefined));
1499
+ return qtiValue(baseType, cardinality, cloneRuntimeValue(arr.filter((v) => v !== null && v !== undefined)));
1437
1500
  }
1438
- // For single file, preserve the object directly
1439
- return qtiValue(baseType, cardinality, raw);
1501
+ return qtiValue(baseType, cardinality, cloneRuntimeValue(raw));
1440
1502
  }
1441
1503
  if (cardinality === 'multiple' || cardinality === 'ordered') {
1442
1504
  const arr = Array.isArray(raw) ? raw : [raw];
@@ -1466,13 +1528,7 @@ export class Player {
1466
1528
  return coerceBaseValue(baseType, t);
1467
1529
  }
1468
1530
  getExtendedTextBase(responseIdentifier) {
1469
- const interaction = this.itemDocument
1470
- .findExtractionElements(['extendedTextInteraction'])
1471
- .find((candidate) => candidate.responseIdentifier === responseIdentifier);
1472
- if (!interaction)
1473
- return undefined;
1474
- const base = Number(interaction.element.getAttribute?.('base') ?? 10);
1475
- return Number.isInteger(base) && base >= 2 && base <= 36 ? base : 10;
1531
+ return this.itemDocument.getExtendedTextBase(responseIdentifier);
1476
1532
  }
1477
1533
  coerceRecordValue(raw, base) {
1478
1534
  let source = raw;
@@ -1573,15 +1629,10 @@ export class Player {
1573
1629
  return toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
1574
1630
  }
1575
1631
  getModalFeedback(outcomes) {
1576
- const feedbackEls = this.itemDocument.findModalFeedbackElements();
1577
1632
  const active = [];
1578
- for (const el of feedbackEls) {
1579
- const identifier = this.getAttrMapped(el, 'identifier') || '';
1580
- const outcomeIdentifier = this.getAttrMapped(el, 'outcomeIdentifier') || '';
1581
- const showHide = (this.getAttrMapped(el, 'showHide') || 'show');
1582
- const title = this.getAttrMapped(el, 'title') || undefined;
1583
- const contentRaw = this.itemDocument.serializeChildren(el) || (el.textContent || '');
1584
- const sanitized = sanitizeHtml(contentRaw, { security: this.config.security });
1633
+ for (const feedback of this.itemDocument.readModalFeedback()) {
1634
+ const { identifier, outcomeIdentifier, showHide, title } = feedback;
1635
+ const sanitized = sanitizeHtml(feedback.content, { security: this.config.security });
1585
1636
  const content = toTrustedHtml(sanitized, this.config.security?.trustedTypesPolicyName);
1586
1637
  const outcomeValue = outcomes[outcomeIdentifier];
1587
1638
  const shouldShow = showHide === 'show' ? outcomeValue === identifier : outcomeValue !== identifier;
@@ -1625,6 +1676,15 @@ function createSessionGuid() {
1625
1676
  'requires crypto.randomUUID or crypto.getRandomValues (present in all supported ' +
1626
1677
  'browsers and in Node >= 20).');
1627
1678
  }
1679
+ function cloneDeclarationMap(declarations) {
1680
+ return structuredClone(declarations);
1681
+ }
1682
+ /** Detach serializable runtime values from caller- and declaration-owned references. */
1683
+ function cloneRuntimeValue(value) {
1684
+ if (!value || typeof value !== 'object')
1685
+ return value;
1686
+ return structuredClone(value);
1687
+ }
1628
1688
  function looksLikeCatalogUrl(value) {
1629
1689
  const trimmed = value.trim();
1630
1690
  return /^(https?:\/\/|\/\/|\/|\.{0,2}\/|data:|blob:)/i.test(trimmed) ||