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

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 +33 -5
  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 +387 -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-BbF4Dj7F.js +3773 -0
  81. package/dist/element-class-BbF4Dj7F.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 +1 -1
  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 +4 -2
  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 +7 -1
  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 +15 -14
  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
@@ -1,243 +0,0 @@
1
- /**
2
- * Performance Monitor Utility
3
- *
4
- * Provides lightweight performance monitoring for QTI player operations
5
- * without requiring external dependencies. Useful for debugging, optimization,
6
- * and tracking performance metrics in production.
7
- *
8
- * Features:
9
- * - Measure operation durations
10
- * - Track custom metrics
11
- * - Export performance data
12
- * - Memory-efficient (circular buffer for metrics)
13
- *
14
- * Usage:
15
- * ```typescript
16
- * import { PerformanceMonitor } from './utils/PerformanceMonitor';
17
- *
18
- * const monitor = new PerformanceMonitor({ enabled: true, maxEntries: 100 });
19
- *
20
- * // Measure an operation
21
- * const stopTimer = monitor.startTimer('render-item');
22
- * // ... do work
23
- * stopTimer(); // Records duration
24
- *
25
- * // Track custom metrics
26
- * monitor.recordMetric('item-response-time', 245);
27
- *
28
- * // Get performance report
29
- * const report = monitor.getReport();
30
- * console.log(report);
31
- * ```
32
- */
33
- export class PerformanceMonitor {
34
- constructor(config = {}) {
35
- this.entries = [];
36
- this.totalRecorded = 0;
37
- this.startTimes = new Map();
38
- this.enabled = config.enabled ?? false;
39
- this.maxEntries = config.maxEntries ?? 100;
40
- this.autoExport = config.autoExport ?? false;
41
- this.onExport = config.onExport;
42
- this.logWarnings = config.logWarnings ?? false;
43
- }
44
- /**
45
- * Enable performance monitoring
46
- */
47
- enable() {
48
- this.enabled = true;
49
- }
50
- /**
51
- * Disable performance monitoring
52
- */
53
- disable() {
54
- this.enabled = false;
55
- }
56
- /**
57
- * Check if monitoring is enabled
58
- */
59
- isEnabled() {
60
- return this.enabled;
61
- }
62
- /**
63
- * Start a timer for an operation
64
- *
65
- * @param name - Name of the operation
66
- * @param metadata - Optional metadata to attach
67
- * @returns Function to stop the timer and record duration
68
- *
69
- * @example
70
- * const stop = monitor.startTimer('render-item', { itemId: 'item-001' });
71
- * // ... do work
72
- * stop(); // Records duration automatically
73
- */
74
- startTimer(name, metadata) {
75
- if (!this.enabled) {
76
- return () => { }; // No-op
77
- }
78
- const startTime = performance.now();
79
- const timerKey = `${name}:${startTime}`;
80
- this.startTimes.set(timerKey, startTime);
81
- return () => {
82
- const endTime = performance.now();
83
- const duration = endTime - startTime;
84
- this.startTimes.delete(timerKey);
85
- this.recordEntry({
86
- name,
87
- timestamp: Date.now(),
88
- duration,
89
- metadata,
90
- });
91
- };
92
- }
93
- /**
94
- * Record a custom metric value
95
- *
96
- * @param name - Name of the metric
97
- * @param value - Numeric value
98
- * @param metadata - Optional metadata
99
- *
100
- * @example
101
- * monitor.recordMetric('item-count', 25);
102
- * monitor.recordMetric('memory-usage', process.memoryUsage().heapUsed);
103
- */
104
- recordMetric(name, value, metadata) {
105
- if (!this.enabled)
106
- return;
107
- this.recordEntry({
108
- name,
109
- timestamp: Date.now(),
110
- value,
111
- metadata,
112
- });
113
- }
114
- /**
115
- * Record a performance entry
116
- */
117
- recordEntry(entry) {
118
- this.totalRecorded++;
119
- // Add to circular buffer
120
- if (this.entries.length >= this.maxEntries) {
121
- // Remove oldest entry
122
- this.entries.shift();
123
- // Auto-export if configured
124
- if (this.autoExport && this.onExport) {
125
- try {
126
- this.onExport(this.getReport());
127
- }
128
- catch (error) {
129
- if (this.logWarnings) {
130
- console.warn('Performance monitor auto-export failed:', error);
131
- }
132
- }
133
- }
134
- }
135
- this.entries.push(entry);
136
- }
137
- /**
138
- * Get performance report with statistics
139
- */
140
- getReport() {
141
- const metrics = {};
142
- // Calculate statistics for each metric
143
- for (const entry of this.entries) {
144
- const value = entry.duration ?? entry.value ?? 0;
145
- if (!metrics[entry.name]) {
146
- metrics[entry.name] = {
147
- count: 0,
148
- min: Infinity,
149
- max: -Infinity,
150
- avg: 0,
151
- total: 0,
152
- };
153
- }
154
- const stats = metrics[entry.name];
155
- stats.count++;
156
- stats.total += value;
157
- stats.min = Math.min(stats.min, value);
158
- stats.max = Math.max(stats.max, value);
159
- }
160
- // Calculate averages
161
- for (const stats of Object.values(metrics)) {
162
- stats.avg = stats.total / stats.count;
163
- }
164
- return {
165
- totalEntries: this.totalRecorded,
166
- storedEntries: this.entries.length,
167
- metrics,
168
- recentEntries: [...this.entries],
169
- };
170
- }
171
- /**
172
- * Get entries for a specific metric name
173
- */
174
- getEntriesByName(name) {
175
- return this.entries.filter((entry) => entry.name === name);
176
- }
177
- /**
178
- * Clear all stored entries
179
- */
180
- clear() {
181
- this.entries = [];
182
- this.totalRecorded = 0;
183
- this.startTimes.clear();
184
- }
185
- /**
186
- * Export report as JSON string
187
- */
188
- exportJSON() {
189
- return JSON.stringify(this.getReport(), null, 2);
190
- }
191
- /**
192
- * Export report to console
193
- */
194
- exportToConsole() {
195
- const report = this.getReport();
196
- console.group('📊 Performance Report');
197
- console.log(`Total Entries: ${report.totalEntries}`);
198
- console.log(`Stored Entries: ${report.storedEntries}`);
199
- console.log('\nMetrics:');
200
- for (const [name, stats] of Object.entries(report.metrics)) {
201
- console.group(` ${name}`);
202
- console.log(` Count: ${stats.count}`);
203
- console.log(` Min: ${stats.min.toFixed(2)}ms`);
204
- console.log(` Max: ${stats.max.toFixed(2)}ms`);
205
- console.log(` Avg: ${stats.avg.toFixed(2)}ms`);
206
- console.log(` Total: ${stats.total.toFixed(2)}ms`);
207
- console.groupEnd();
208
- }
209
- console.groupEnd();
210
- }
211
- /**
212
- * Get performance marks for Web Performance API integration
213
- *
214
- * If using browser's Performance API, this exports entries
215
- * in a compatible format.
216
- */
217
- getPerformanceMarks() {
218
- return this.entries.map((entry) => ({
219
- name: entry.name,
220
- startTime: entry.timestamp,
221
- duration: entry.duration,
222
- }));
223
- }
224
- }
225
- /**
226
- * Singleton instance for global performance monitoring
227
- *
228
- * Usage:
229
- * ```typescript
230
- * import { globalPerformanceMonitor } from './utils/PerformanceMonitor';
231
- *
232
- * globalPerformanceMonitor.enable();
233
- * const stop = globalPerformanceMonitor.startTimer('operation');
234
- * // ... work
235
- * stop();
236
- * ```
237
- */
238
- export const globalPerformanceMonitor = new PerformanceMonitor({
239
- enabled: false, // Disabled by default, enable explicitly
240
- maxEntries: 100,
241
- logWarnings: false,
242
- });
243
- //# sourceMappingURL=PerformanceMonitor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PerformanceMonitor.js","sourceRoot":"","sources":["../../src/utils/PerformanceMonitor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAgDH,MAAM,OAAO,kBAAkB;IAW9B,YAAY,SAAmC,EAAE;QAJzC,YAAO,GAAuB,EAAE,CAAC;QACjC,kBAAa,GAAG,CAAC,CAAC;QAClB,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAG9C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,GAAG,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,KAAK,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,MAAM;QACL,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,SAAS;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,IAAY,EAAE,QAAkC;QAC1D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,QAAQ;QAC1B,CAAC;QAED,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,SAAS,EAAE,CAAC;Q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YAClD,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACtD,OAAO,CAAC,QAAQ,EAAE,CAAC;QACpB,CAAC;QAED,OAAO,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,mBAAmB;QAKlB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACnC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACxB,CAAC,CAAC,CAAC;IACL,CAAC;CACD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,kBAAkB,CAAC;IAC9D,OAAO,EAAE,KAAK,EAAE,yCAAyC;IACzD,UAAU,EAAE,GAAG;IACf,WAAW,EAAE,KAAK;CAClB,CAAC,CAAC","sourcesContent":["/**\n * Performance Monitor Utility\n *\n * Provides lightweight performance monitoring for QTI player operations\n * without requiring external dependencies. Useful for debugging, optimization,\n * and tracking performance metrics in production.\n *\n * Features:\n * - Measure operation durations\n * - Track custom metrics\n * - Export performance data\n * - Memory-efficient (circular buffer for metrics)\n *\n * Usage:\n * ```typescript\n * import { PerformanceMonitor } from './utils/PerformanceMonitor';\n *\n * const monitor = new PerformanceMonitor({ enabled: true, maxEntries: 100 });\n *\n * // Measure an operation\n * const stopTimer = monitor.startTimer('render-item');\n * // ... do work\n * stopTimer(); // Records duration\n *\n * // Track custom metrics\n * monitor.recordMetric('item-response-time', 245);\n *\n * // Get performance report\n * const report = monitor.getReport();\n * console.log(report);\n * ```\n */\n\nexport interface PerformanceEntry {\n\t/** Metric name */\n\tname: string;\n\t/** Timestamp when metric was recorded (ms since epoch) */\n\ttimestamp: number;\n\t/** Duration in milliseconds (for timers) */\n\tduration?: number;\n\t/** Custom value (for non-timer metrics) */\n\tvalue?: number;\n\t/** Additional metadata */\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface PerformanceReport {\n\t/** Total number of metrics recorded */\n\ttotalEntries: number;\n\t/** Number of entries currently stored (may be less due to circular buffer) */\n\tstoredEntries: number;\n\t/** Summary statistics by metric name */\n\tmetrics: Record<\n\t\tstring,\n\t\t{\n\t\t\tcount: number;\n\t\t\tmin: number;\n\t\t\tmax: number;\n\t\t\tavg: number;\n\t\t\ttotal: number;\n\t\t}\n\t>;\n\t/** Recent entries (last N based on buffer size) */\n\trecentEntries: PerformanceEntry[];\n}\n\nexport interface PerformanceMonitorConfig {\n\t/** Enable/disable monitoring (default: false) */\n\tenabled?: boolean;\n\t/** Maximum entries to store (circular buffer, default: 100) */\n\tmaxEntries?: number;\n\t/** Auto-export metrics when buffer is full (default: false) */\n\tautoExport?: boolean;\n\t/** Callback for auto-export */\n\tonExport?: (report: PerformanceReport) => void;\n\t/** Log warnings to console (default: false) */\n\tlogWarnings?: boolean;\n}\n\nexport class PerformanceMonitor {\n\tprivate enabled: boolean;\n\tprivate maxEntries: number;\n\tprivate autoExport: boolean;\n\tprivate onExport?: (report: PerformanceReport) => void;\n\tprivate logWarnings: boolean;\n\n\tprivate entries: PerformanceEntry[] = [];\n\tprivate totalRecorded = 0;\n\tprivate startTimes = new Map<string, number>();\n\n\tconstructor(config: PerformanceMonitorConfig = {}) {\n\t\tthis.enabled = config.enabled ?? false;\n\t\tthis.maxEntries = config.maxEntries ?? 100;\n\t\tthis.autoExport = config.autoExport ?? false;\n\t\tthis.onExport = config.onExport;\n\t\tthis.logWarnings = config.logWarnings ?? false;\n\t}\n\n\t/**\n\t * Enable performance monitoring\n\t */\n\tenable(): void {\n\t\tthis.enabled = true;\n\t}\n\n\t/**\n\t * Disable performance monitoring\n\t */\n\tdisable(): void {\n\t\tthis.enabled = false;\n\t}\n\n\t/**\n\t * Check if monitoring is enabled\n\t */\n\tisEnabled(): boolean {\n\t\treturn this.enabled;\n\t}\n\n\t/**\n\t * Start a timer for an operation\n\t *\n\t * @param name - Name of the operation\n\t * @param metadata - Optional metadata to attach\n\t * @returns Function to stop the timer and record duration\n\t *\n\t * @example\n\t * const stop = monitor.startTimer('render-item', { itemId: 'item-001' });\n\t * // ... do work\n\t * stop(); // Records duration automatically\n\t */\n\tstartTimer(name: string, metadata?: Record<string, unknown>): () => void {\n\t\tif (!this.enabled) {\n\t\t\treturn () => {}; // No-op\n\t\t}\n\n\t\tconst startTime = performance.now();\n\t\tconst timerKey = `${name}:${startTime}`;\n\t\tthis.startTimes.set(timerKey, startTime);\n\n\t\treturn () => {\n\t\t\tconst endTime = performance.now();\n\t\t\tconst duration = endTime - startTime;\n\t\t\tthis.startTimes.delete(timerKey);\n\n\t\t\tthis.recordEntry({\n\t\t\t\tname,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tduration,\n\t\t\t\tmetadata,\n\t\t\t});\n\t\t};\n\t}\n\n\t/**\n\t * Record a custom metric value\n\t *\n\t * @param name - Name of the metric\n\t * @param value - Numeric value\n\t * @param metadata - Optional metadata\n\t *\n\t * @example\n\t * monitor.recordMetric('item-count', 25);\n\t * monitor.recordMetric('memory-usage', process.memoryUsage().heapUsed);\n\t */\n\trecordMetric(name: string, value: number, metadata?: Record<string, unknown>): void {\n\t\tif (!this.enabled) return;\n\n\t\tthis.recordEntry({\n\t\t\tname,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue,\n\t\t\tmetadata,\n\t\t});\n\t}\n\n\t/**\n\t * Record a performance entry\n\t */\n\tprivate recordEntry(entry: PerformanceEntry): void {\n\t\tthis.totalRecorded++;\n\n\t\t// Add to circular buffer\n\t\tif (this.entries.length >= this.maxEntries) {\n\t\t\t// Remove oldest entry\n\t\t\tthis.entries.shift();\n\n\t\t\t// Auto-export if configured\n\t\t\tif (this.autoExport && this.onExport) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.onExport(this.getReport());\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.logWarnings) {\n\t\t\t\t\t\tconsole.warn('Performance monitor auto-export failed:', error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.entries.push(entry);\n\t}\n\n\t/**\n\t * Get performance report with statistics\n\t */\n\tgetReport(): PerformanceReport {\n\t\tconst metrics: Record<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tcount: number;\n\t\t\t\tmin: number;\n\t\t\t\tmax: number;\n\t\t\t\tavg: number;\n\t\t\t\ttotal: number;\n\t\t\t}\n\t\t> = {};\n\n\t\t// Calculate statistics for each metric\n\t\tfor (const entry of this.entries) {\n\t\t\tconst value = entry.duration ?? entry.value ?? 0;\n\n\t\t\tif (!metrics[entry.name]) {\n\t\t\t\tmetrics[entry.name] = {\n\t\t\t\t\tcount: 0,\n\t\t\t\t\tmin: Infinity,\n\t\t\t\t\tmax: -Infinity,\n\t\t\t\t\tavg: 0,\n\t\t\t\t\ttotal: 0,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst stats = metrics[entry.name];\n\t\t\tstats.count++;\n\t\t\tstats.total += value;\n\t\t\tstats.min = Math.min(stats.min, value);\n\t\t\tstats.max = Math.max(stats.max, value);\n\t\t}\n\n\t\t// Calculate averages\n\t\tfor (const stats of Object.values(metrics)) {\n\t\t\tstats.avg = stats.total / stats.count;\n\t\t}\n\n\t\treturn {\n\t\t\ttotalEntries: this.totalRecorded,\n\t\t\tstoredEntries: this.entries.length,\n\t\t\tmetrics,\n\t\t\trecentEntries: [...this.entries],\n\t\t};\n\t}\n\n\t/**\n\t * Get entries for a specific metric name\n\t */\n\tgetEntriesByName(name: string): PerformanceEntry[] {\n\t\treturn this.entries.filter((entry) => entry.name === name);\n\t}\n\n\t/**\n\t * Clear all stored entries\n\t */\n\tclear(): void {\n\t\tthis.entries = [];\n\t\tthis.totalRecorded = 0;\n\t\tthis.startTimes.clear();\n\t}\n\n\t/**\n\t * Export report as JSON string\n\t */\n\texportJSON(): string {\n\t\treturn JSON.stringify(this.getReport(), null, 2);\n\t}\n\n\t/**\n\t * Export report to console\n\t */\n\texportToConsole(): void {\n\t\tconst report = this.getReport();\n\n\t\tconsole.group('📊 Performance Report');\n\t\tconsole.log(`Total Entries: ${report.totalEntries}`);\n\t\tconsole.log(`Stored Entries: ${report.storedEntries}`);\n\t\tconsole.log('\\nMetrics:');\n\n\t\tfor (const [name, stats] of Object.entries(report.metrics)) {\n\t\t\tconsole.group(` ${name}`);\n\t\t\tconsole.log(` Count: ${stats.count}`);\n\t\t\tconsole.log(` Min: ${stats.min.toFixed(2)}ms`);\n\t\t\tconsole.log(` Max: ${stats.max.toFixed(2)}ms`);\n\t\t\tconsole.log(` Avg: ${stats.avg.toFixed(2)}ms`);\n\t\t\tconsole.log(` Total: ${stats.total.toFixed(2)}ms`);\n\t\t\tconsole.groupEnd();\n\t\t}\n\n\t\tconsole.groupEnd();\n\t}\n\n\t/**\n\t * Get performance marks for Web Performance API integration\n\t *\n\t * If using browser's Performance API, this exports entries\n\t * in a compatible format.\n\t */\n\tgetPerformanceMarks(): Array<{\n\t\tname: string;\n\t\tstartTime: number;\n\t\tduration?: number;\n\t}> {\n\t\treturn this.entries.map((entry) => ({\n\t\t\tname: entry.name,\n\t\t\tstartTime: entry.timestamp,\n\t\t\tduration: entry.duration,\n\t\t}));\n\t}\n}\n\n/**\n * Singleton instance for global performance monitoring\n *\n * Usage:\n * ```typescript\n * import { globalPerformanceMonitor } from './utils/PerformanceMonitor';\n *\n * globalPerformanceMonitor.enable();\n * const stop = globalPerformanceMonitor.startTimer('operation');\n * // ... work\n * stop();\n * ```\n */\nexport const globalPerformanceMonitor = new PerformanceMonitor({\n\tenabled: false, // Disabled by default, enable explicitly\n\tmaxEntries: 100,\n\tlogWarnings: false,\n});\n"]}
@@ -1,15 +0,0 @@
1
- /**
2
- * Generic response/value helpers.
3
- *
4
- * These are UI-agnostic utilities intended to keep "is this answered?"
5
- * logic consistent across apps (example, assessment player, etc).
6
- */
7
- /**
8
- * Returns true when a response value should be treated as "no response / unanswered".
9
- *
10
- * Notes:
11
- * - `0` and `false` are valid answers in some interactions, so they are NOT empty.
12
- * - Empty objects are treated as empty, and objects whose values are all empty are treated as empty.
13
- */
14
- export declare function isResponseEmpty(value: unknown): boolean;
15
- export declare function countAnsweredForResponseIds(responses: Record<string, unknown>, responseIds: readonly string[]): number;
@@ -1,46 +0,0 @@
1
- /**
2
- * Generic response/value helpers.
3
- *
4
- * These are UI-agnostic utilities intended to keep "is this answered?"
5
- * logic consistent across apps (example, assessment player, etc).
6
- */
7
- /**
8
- * Returns true when a response value should be treated as "no response / unanswered".
9
- *
10
- * Notes:
11
- * - `0` and `false` are valid answers in some interactions, so they are NOT empty.
12
- * - Empty objects are treated as empty, and objects whose values are all empty are treated as empty.
13
- */
14
- export function isResponseEmpty(value) {
15
- if (value === null || value === undefined)
16
- return true;
17
- if (typeof value === 'string')
18
- return value.trim() === '';
19
- if (Array.isArray(value)) {
20
- if (value.length === 0)
21
- return true;
22
- // Some interactions may emit arrays with empty members; treat "all empty" as empty.
23
- return value.every((v) => isResponseEmpty(v));
24
- }
25
- // Files/blobs are valid user responses (upload interactions).
26
- if (typeof Blob !== 'undefined' && value instanceof Blob)
27
- return false;
28
- if (typeof value === 'object') {
29
- const obj = value;
30
- const keys = Object.keys(obj);
31
- if (keys.length === 0)
32
- return true;
33
- return keys.every((k) => isResponseEmpty(obj[k]));
34
- }
35
- // numbers, booleans, symbols, functions -> treat as "has a response"
36
- return false;
37
- }
38
- export function countAnsweredForResponseIds(responses, responseIds) {
39
- let count = 0;
40
- for (const id of responseIds) {
41
- if (!isResponseEmpty(responses[id]))
42
- count++;
43
- }
44
- return count;
45
- }
46
- //# sourceMappingURL=responseUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"responseUtils.js","sourceRoot":"","sources":["../../src/utils/responseUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEvD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;IAE1D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACpC,oFAAoF;QACpF,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,8DAA8D;IAC9D,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI;QAAE,OAAO,KAAK,CAAC;IAEvE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,qEAAqE;IACrE,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,2BAA2B,CAC1C,SAAkC,EAClC,WAA8B;IAE9B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * Generic response/value helpers.\n *\n * These are UI-agnostic utilities intended to keep \"is this answered?\"\n * logic consistent across apps (example, assessment player, etc).\n */\n\n/**\n * Returns true when a response value should be treated as \"no response / unanswered\".\n *\n * Notes:\n * - `0` and `false` are valid answers in some interactions, so they are NOT empty.\n * - Empty objects are treated as empty, and objects whose values are all empty are treated as empty.\n */\nexport function isResponseEmpty(value: unknown): boolean {\n\tif (value === null || value === undefined) return true;\n\n\tif (typeof value === 'string') return value.trim() === '';\n\n\tif (Array.isArray(value)) {\n\t\tif (value.length === 0) return true;\n\t\t// Some interactions may emit arrays with empty members; treat \"all empty\" as empty.\n\t\treturn value.every((v) => isResponseEmpty(v));\n\t}\n\n\t// Files/blobs are valid user responses (upload interactions).\n\tif (typeof Blob !== 'undefined' && value instanceof Blob) return false;\n\n\tif (typeof value === 'object') {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst keys = Object.keys(obj);\n\t\tif (keys.length === 0) return true;\n\t\treturn keys.every((k) => isResponseEmpty(obj[k]));\n\t}\n\n\t// numbers, booleans, symbols, functions -> treat as \"has a response\"\n\treturn false;\n}\n\nexport function countAnsweredForResponseIds(\n\tresponses: Record<string, unknown>,\n\tresponseIds: readonly string[]\n): number {\n\tlet count = 0;\n\tfor (const id of responseIds) {\n\t\tif (!isResponseEmpty(responses[id])) count++;\n\t}\n\treturn count;\n}\n\n\n"]}
@@ -1,119 +0,0 @@
1
- /**
2
- * Abstract base class for all QTI interaction web components
3
- *
4
- * Provides common functionality including:
5
- * - Reactive property system
6
- * - Shadow DOM management
7
- * - Event emission helpers
8
- * - Update scheduling
9
- * - Lifecycle management
10
- *
11
- * @example
12
- * ```typescript
13
- * export class QTIChoiceInteraction extends QTIInteractionBase<ChoiceInteractionData> {
14
- * protected render(): void {
15
- * this.shadowRoot.innerHTML = `...`;
16
- * this.attachEventListeners();
17
- * }
18
- *
19
- * protected cleanup(): void {
20
- * // Optional cleanup
21
- * }
22
- * }
23
- * ```
24
- */
25
- import type { HtmlContent } from '../types/index.js';
26
- import type { BaseInteractionData } from '../interactions/shared/types.js';
27
- import { type InteractionResponseValue, type QTIInteractionElement } from './QTIInteractionElement.js';
28
- export declare abstract class QTIInteractionBase<TData extends BaseInteractionData = BaseInteractionData> extends HTMLElement implements QTIInteractionElement<TData> {
29
- private _interaction;
30
- private _response;
31
- private _disabled;
32
- private _typeset?;
33
- shadowRoot: ShadowRoot;
34
- private updateScheduled;
35
- private isInitialized;
36
- constructor();
37
- /**
38
- * The processed interaction data from QTI XML
39
- * Required property - throws if accessed before being set
40
- */
41
- get interaction(): TData;
42
- set interaction(value: TData);
43
- /**
44
- * Current response value (type depends on interaction type)
45
- * May be null if no response has been provided yet
46
- */
47
- get response(): InteractionResponseValue<TData> | null;
48
- set response(value: InteractionResponseValue<TData> | null);
49
- /**
50
- * Whether the interaction is in read-only/disabled mode
51
- */
52
- get disabled(): boolean;
53
- set disabled(value: boolean);
54
- /**
55
- * Optional function to apply math typesetting (e.g., KaTeX, MathJax)
56
- */
57
- get typeset(): ((element: HTMLElement) => void) | undefined;
58
- set typeset(value: ((element: HTMLElement) => void) | undefined);
59
- /**
60
- * Called when the element is connected to the DOM
61
- */
62
- connectedCallback(): void;
63
- /**
64
- * Called when the element is disconnected from the DOM
65
- */
66
- disconnectedCallback(): void;
67
- /**
68
- * Called once when the element is first connected
69
- * Override this to perform one-time initialization
70
- */
71
- protected init(): void;
72
- /**
73
- * Schedule a re-render on the next microtask
74
- * Multiple calls within the same tick are batched
75
- */
76
- protected requestUpdate(): void;
77
- /**
78
- * Render the component's UI
79
- * Called automatically when properties change
80
- * Must be implemented by subclasses
81
- */
82
- protected abstract render(): void;
83
- /**
84
- * Clean up resources when component is removed from DOM
85
- * Override this to remove event listeners, cancel timers, etc.
86
- */
87
- protected abstract cleanup(): void;
88
- /**
89
- * Emit a qti-change event when the user response changes
90
- * @param value - The new response value
91
- */
92
- protected emitChange(value: InteractionResponseValue<TData> | null): void;
93
- /**
94
- * Emit a qti-ready event when component is initialized
95
- */
96
- private emitReady;
97
- /**
98
- * Emit a qti-error event when an error occurs
99
- */
100
- protected emitError(error: Error, context: string): void;
101
- /**
102
- * Apply math typesetting to the shadow root
103
- * Call this after updating the DOM with math content
104
- */
105
- protected applyTypesetting(): void;
106
- /**
107
- * Get base styles for all interaction components
108
- * Override and call super.getStyles() to extend these styles
109
- */
110
- protected getStyles(): string;
111
- /**
112
- * Safely set innerHTML with error handling
113
- */
114
- protected safeSetInnerHTML(element: HTMLElement | ShadowRoot, html: HtmlContent): void;
115
- /**
116
- * Create an element with classes
117
- */
118
- protected createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, classes?: string[]): HTMLElementTagNameMap[K];
119
- }