@pie-qti/item-player 0.1.8 → 0.1.10

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 (199) hide show
  1. package/README.md +17 -0
  2. package/dist/catalog/applyGlossaryTriggers.d.ts +13 -2
  3. package/dist/catalog/applyGlossaryTriggers.d.ts.map +1 -1
  4. package/dist/catalog/glossaryAction.d.ts +4 -2
  5. package/dist/catalog/glossaryAction.d.ts.map +1 -1
  6. package/dist/components/utils/index.d.ts +1 -2
  7. package/dist/components/utils/index.d.ts.map +1 -1
  8. package/dist/components/utils/index.js +1 -2
  9. package/dist/core/ComponentRegistry.d.ts +10 -1
  10. package/dist/core/ComponentRegistry.d.ts.map +1 -1
  11. package/dist/core/ComponentRegistry.js +42 -1
  12. package/dist/core/Player.d.ts +10 -2
  13. package/dist/core/Player.d.ts.map +1 -1
  14. package/dist/core/Player.js +54 -46
  15. package/dist/document/AssessmentItemDocument.d.ts +1 -1
  16. package/dist/element.d.ts +15 -0
  17. package/dist/element.js +1921 -1785
  18. package/dist/element.js.map +1 -1
  19. package/dist/extraction/ExtractionRegistry.d.ts +1 -1
  20. package/dist/extraction/createContext.d.ts +1 -1
  21. package/dist/extraction/index.d.ts +2 -2
  22. package/dist/extraction/index.d.ts.map +1 -1
  23. package/dist/extraction/index.js +1 -1
  24. package/dist/extraction/interactionExtractionPipeline.d.ts +1 -1
  25. package/dist/extraction/interactionSecurity.d.ts +1 -1
  26. package/dist/extraction/types.d.ts +1 -1
  27. package/dist/presentation/itemPresentationPlan.d.ts +54 -0
  28. package/dist/presentation/itemPresentationPlan.d.ts.map +1 -0
  29. package/dist/presentation/itemPresentationPlan.js +98 -0
  30. package/dist/types/index.d.ts +17 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/index.js +0 -3
  33. package/dist/web-components/QTIInteractionBase.d.ts +1 -1
  34. package/dist/web-components/QTIInteractionElement.d.ts +1 -1
  35. package/package.json +10 -12
  36. package/src/__tests__/catalog.test.ts +0 -267
  37. package/src/__tests__/fixtures/pci/echo-pci.js +0 -49
  38. package/src/__tests__/pci.test.ts +0 -353
  39. package/src/__tests__/qti3-attribute-extraction.test.ts +0 -174
  40. package/src/__tests__/qti3-debug.test.ts +0 -140
  41. package/src/__tests__/qti3-extraction.test.ts +0 -309
  42. package/src/catalog/applyGlossaryTriggers.ts +0 -372
  43. package/src/catalog/catalogExtractor.ts +0 -130
  44. package/src/catalog/catalogLookup.ts +0 -53
  45. package/src/catalog/glossaryAction.ts +0 -38
  46. package/src/catalog/types.ts +0 -37
  47. package/src/components/ItemBody.svelte +0 -363
  48. package/src/components/ItemPlayer.svelte +0 -163
  49. package/src/components/ModalFeedbackDisplay.svelte +0 -97
  50. package/src/components/actions/typesetAction.ts +0 -74
  51. package/src/components/index.ts +0 -22
  52. package/src/components/utils/assignProps.ts +0 -2
  53. package/src/components/utils/feedbackUtils.ts +0 -140
  54. package/src/components/utils/index.ts +0 -13
  55. package/src/components/utils/stimulusRender.ts +0 -93
  56. package/src/components/utils/stylesheetRender.ts +0 -58
  57. package/src/core/ComponentRegistry.ts +0 -248
  58. package/src/core/Player.ts +0 -1618
  59. package/src/core/Plugin.ts +0 -123
  60. package/src/core/PluginManager.ts +0 -182
  61. package/src/core/constants.ts +0 -117
  62. package/src/core/declarations.ts +0 -171
  63. package/src/core/parsingLimits.ts +0 -62
  64. package/src/core/random.ts +0 -24
  65. package/src/core/rolePolicy.ts +0 -34
  66. package/src/core/sanitizer.ts +0 -305
  67. package/src/core/trustedTypes.ts +0 -63
  68. package/src/core/urlPolicy.ts +0 -98
  69. package/src/document/AssessmentItemDocument.ts +0 -247
  70. package/src/element.ts +0 -128
  71. package/src/extensions/MathLiveEditor.ts +0 -313
  72. package/src/extraction/ExtractionRegistry.ts +0 -335
  73. package/src/extraction/createContext.ts +0 -52
  74. package/src/extraction/extractors/associateExtractor.ts +0 -1
  75. package/src/extraction/extractors/choiceExtractor.ts +0 -1
  76. package/src/extraction/extractors/conformance-qti3-advanced.test.ts +0 -239
  77. package/src/extraction/extractors/conformance-qti3-basic.test.ts +0 -82
  78. package/src/extraction/extractors/conformance.test.ts +0 -208
  79. package/src/extraction/extractors/customExtractor.ts +0 -1
  80. package/src/extraction/extractors/drawingExtractor.ts +0 -1
  81. package/src/extraction/extractors/endAttemptExtractor.ts +0 -1
  82. package/src/extraction/extractors/extendedTextExtractor.ts +0 -1
  83. package/src/extraction/extractors/gapMatchExtractor.ts +0 -1
  84. package/src/extraction/extractors/graphicAssociateExtractor.ts +0 -1
  85. package/src/extraction/extractors/graphicGapMatchExtractor.ts +0 -1
  86. package/src/extraction/extractors/graphicOrderExtractor.ts +0 -1
  87. package/src/extraction/extractors/hotspotExtractor.ts +0 -1
  88. package/src/extraction/extractors/hottextExtractor.ts +0 -1
  89. package/src/extraction/extractors/index.ts +0 -9
  90. package/src/extraction/extractors/inlineChoiceExtractor.ts +0 -1
  91. package/src/extraction/extractors/matchExtractor.ts +0 -1
  92. package/src/extraction/extractors/mediaExtractor.ts +0 -1
  93. package/src/extraction/extractors/orderExtractor.ts +0 -1
  94. package/src/extraction/extractors/portableCustomExtractor.ts +0 -1
  95. package/src/extraction/extractors/positionObjectExtractor.ts +0 -1
  96. package/src/extraction/extractors/selectPointExtractor.ts +0 -1
  97. package/src/extraction/extractors/sliderExtractor.ts +0 -1
  98. package/src/extraction/extractors/textEntryExtractor.ts +0 -1
  99. package/src/extraction/extractors/uploadExtractor.ts +0 -1
  100. package/src/extraction/index.ts +0 -108
  101. package/src/extraction/interactionExtractionPipeline.ts +0 -70
  102. package/src/extraction/interactionSecurity.ts +0 -60
  103. package/src/extraction/types.ts +0 -246
  104. package/src/extraction/utils.ts +0 -243
  105. package/src/iframe/IFramePlayerHost.ts +0 -265
  106. package/src/iframe/index.ts +0 -11
  107. package/src/iframe/protocol.ts +0 -137
  108. package/src/index.ts +0 -101
  109. package/src/interactions/associate/extractor.ts +0 -133
  110. package/src/interactions/associate/index.ts +0 -2
  111. package/src/interactions/associate/types.ts +0 -1
  112. package/src/interactions/choice/extractor.ts +0 -121
  113. package/src/interactions/choice/index.ts +0 -2
  114. package/src/interactions/choice/types.ts +0 -1
  115. package/src/interactions/custom/extractor.ts +0 -72
  116. package/src/interactions/custom/index.ts +0 -2
  117. package/src/interactions/custom/types.ts +0 -1
  118. package/src/interactions/drawing/extractor.ts +0 -113
  119. package/src/interactions/drawing/index.ts +0 -2
  120. package/src/interactions/drawing/types.ts +0 -1
  121. package/src/interactions/end-attempt/extractor.ts +0 -74
  122. package/src/interactions/end-attempt/index.ts +0 -2
  123. package/src/interactions/end-attempt/types.ts +0 -1
  124. package/src/interactions/extended-text/extractor.ts +0 -92
  125. package/src/interactions/extended-text/index.ts +0 -2
  126. package/src/interactions/extended-text/types.ts +0 -1
  127. package/src/interactions/gap-match/extractor.ts +0 -193
  128. package/src/interactions/gap-match/index.ts +0 -2
  129. package/src/interactions/gap-match/types.ts +0 -1
  130. package/src/interactions/graphic-associate/extractor.ts +0 -192
  131. package/src/interactions/graphic-associate/index.ts +0 -2
  132. package/src/interactions/graphic-associate/types.ts +0 -1
  133. package/src/interactions/graphic-gap-match/extractor.ts +0 -257
  134. package/src/interactions/graphic-gap-match/index.ts +0 -2
  135. package/src/interactions/graphic-gap-match/types.ts +0 -1
  136. package/src/interactions/graphic-order/extractor.ts +0 -162
  137. package/src/interactions/graphic-order/index.ts +0 -2
  138. package/src/interactions/graphic-order/types.ts +0 -1
  139. package/src/interactions/hotspot/extractor.ts +0 -208
  140. package/src/interactions/hotspot/index.ts +0 -2
  141. package/src/interactions/hotspot/types.ts +0 -1
  142. package/src/interactions/hottext/extractor.ts +0 -163
  143. package/src/interactions/hottext/index.ts +0 -2
  144. package/src/interactions/hottext/types.ts +0 -1
  145. package/src/interactions/index.ts +0 -52
  146. package/src/interactions/inline/index.ts +0 -1
  147. package/src/interactions/inline/render-plan.ts +0 -105
  148. package/src/interactions/inline-choice/InlineChoice.svelte +0 -57
  149. package/src/interactions/inline-choice/extractor.ts +0 -105
  150. package/src/interactions/inline-choice/index.ts +0 -2
  151. package/src/interactions/inline-choice/types.ts +0 -1
  152. package/src/interactions/match/extractor.ts +0 -187
  153. package/src/interactions/match/index.ts +0 -2
  154. package/src/interactions/match/types.ts +0 -1
  155. package/src/interactions/media/extractor.ts +0 -168
  156. package/src/interactions/media/index.ts +0 -2
  157. package/src/interactions/media/types.ts +0 -1
  158. package/src/interactions/modules.ts +0 -111
  159. package/src/interactions/order/extractor.ts +0 -120
  160. package/src/interactions/order/index.ts +0 -2
  161. package/src/interactions/order/types.ts +0 -1
  162. package/src/interactions/portable-custom/extractor.ts +0 -122
  163. package/src/interactions/portable-custom/index.ts +0 -2
  164. package/src/interactions/portable-custom/types.ts +0 -1
  165. package/src/interactions/position-object/extractor.ts +0 -243
  166. package/src/interactions/position-object/index.ts +0 -2
  167. package/src/interactions/position-object/types.ts +0 -1
  168. package/src/interactions/select-point/extractor.ts +0 -143
  169. package/src/interactions/select-point/index.ts +0 -2
  170. package/src/interactions/select-point/types.ts +0 -1
  171. package/src/interactions/shared/index.ts +0 -1
  172. package/src/interactions/shared/types.ts +0 -430
  173. package/src/interactions/slider/extractor.ts +0 -102
  174. package/src/interactions/slider/index.ts +0 -2
  175. package/src/interactions/slider/types.ts +0 -1
  176. package/src/interactions/text-entry/InlineTextEntry.svelte +0 -75
  177. package/src/interactions/text-entry/extractor.ts +0 -79
  178. package/src/interactions/text-entry/index.ts +0 -2
  179. package/src/interactions/text-entry/types.ts +0 -1
  180. package/src/interactions/upload/extractor.ts +0 -81
  181. package/src/interactions/upload/index.ts +0 -2
  182. package/src/interactions/upload/types.ts +0 -1
  183. package/src/pci/PciHost.ts +0 -138
  184. package/src/pci/types.ts +0 -70
  185. package/src/pnp/applyPnp.ts +0 -29
  186. package/src/pnp/parsePnpXml.ts +0 -215
  187. package/src/pnp/types.ts +0 -75
  188. package/src/server.ts +0 -14
  189. package/src/types/index.ts +0 -388
  190. package/src/types/interactions.ts +0 -8
  191. package/src/types/responseValidation.ts +0 -29
  192. package/src/types/xmldom.d.ts +0 -12
  193. package/src/utils/PerformanceMonitor.ts +0 -335
  194. package/src/utils/drawingUtils.ts +0 -73
  195. package/src/utils/responseUtils.ts +0 -51
  196. package/src/utils/touchDragHelper.ts +0 -1
  197. package/src/web-components/QTIInteractionBase.ts +0 -303
  198. package/src/web-components/QTIInteractionElement.ts +0 -125
  199. package/src/web-components/index.ts +0 -22
@@ -1,29 +0,0 @@
1
- export type ResponseValidationSeverity = 'error' | 'warning';
2
-
3
- export interface ResponseValidationIssue {
4
- responseId: string;
5
- code: string;
6
- message: string;
7
- severity: ResponseValidationSeverity;
8
- }
9
-
10
- export interface ResponseValidationEntry {
11
- responseId: string;
12
- interactionType: string;
13
- /** Whether this interaction is required for submission purposes (derived from constraints like minPlays/minChoices). */
14
- required: boolean;
15
- /** Whether the interaction is complete for submission purposes. */
16
- complete: boolean;
17
- /** Whether the response value is valid (shape + constraints). */
18
- valid: boolean;
19
- errors: string[];
20
- warnings: string[];
21
- }
22
-
23
- export interface ResponseValidationResult {
24
- valid: boolean;
25
- entries: Record<string, ResponseValidationEntry>;
26
- issues: ResponseValidationIssue[];
27
- }
28
-
29
-
@@ -1,12 +0,0 @@
1
- declare module '@xmldom/xmldom' {
2
- export class DOMParser {
3
- constructor(options?: any);
4
- parseFromString(xml: string, mimeType: string): Document;
5
- }
6
-
7
- export class XMLSerializer {
8
- serializeToString(node: Node): string;
9
- }
10
- }
11
-
12
-
@@ -1,335 +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
-
34
- export interface PerformanceEntry {
35
- /** Metric name */
36
- name: string;
37
- /** Timestamp when metric was recorded (ms since epoch) */
38
- timestamp: number;
39
- /** Duration in milliseconds (for timers) */
40
- duration?: number;
41
- /** Custom value (for non-timer metrics) */
42
- value?: number;
43
- /** Additional metadata */
44
- metadata?: Record<string, unknown>;
45
- }
46
-
47
- export interface PerformanceReport {
48
- /** Total number of metrics recorded */
49
- totalEntries: number;
50
- /** Number of entries currently stored (may be less due to circular buffer) */
51
- storedEntries: number;
52
- /** Summary statistics by metric name */
53
- metrics: Record<
54
- string,
55
- {
56
- count: number;
57
- min: number;
58
- max: number;
59
- avg: number;
60
- total: number;
61
- }
62
- >;
63
- /** Recent entries (last N based on buffer size) */
64
- recentEntries: PerformanceEntry[];
65
- }
66
-
67
- export interface PerformanceMonitorConfig {
68
- /** Enable/disable monitoring (default: false) */
69
- enabled?: boolean;
70
- /** Maximum entries to store (circular buffer, default: 100) */
71
- maxEntries?: number;
72
- /** Auto-export metrics when buffer is full (default: false) */
73
- autoExport?: boolean;
74
- /** Callback for auto-export */
75
- onExport?: (report: PerformanceReport) => void;
76
- /** Log warnings to console (default: false) */
77
- logWarnings?: boolean;
78
- }
79
-
80
- export class PerformanceMonitor {
81
- private enabled: boolean;
82
- private maxEntries: number;
83
- private autoExport: boolean;
84
- private onExport?: (report: PerformanceReport) => void;
85
- private logWarnings: boolean;
86
-
87
- private entries: PerformanceEntry[] = [];
88
- private totalRecorded = 0;
89
- private startTimes = new Map<string, number>();
90
-
91
- constructor(config: PerformanceMonitorConfig = {}) {
92
- this.enabled = config.enabled ?? false;
93
- this.maxEntries = config.maxEntries ?? 100;
94
- this.autoExport = config.autoExport ?? false;
95
- this.onExport = config.onExport;
96
- this.logWarnings = config.logWarnings ?? false;
97
- }
98
-
99
- /**
100
- * Enable performance monitoring
101
- */
102
- enable(): void {
103
- this.enabled = true;
104
- }
105
-
106
- /**
107
- * Disable performance monitoring
108
- */
109
- disable(): void {
110
- this.enabled = false;
111
- }
112
-
113
- /**
114
- * Check if monitoring is enabled
115
- */
116
- isEnabled(): boolean {
117
- return this.enabled;
118
- }
119
-
120
- /**
121
- * Start a timer for an operation
122
- *
123
- * @param name - Name of the operation
124
- * @param metadata - Optional metadata to attach
125
- * @returns Function to stop the timer and record duration
126
- *
127
- * @example
128
- * const stop = monitor.startTimer('render-item', { itemId: 'item-001' });
129
- * // ... do work
130
- * stop(); // Records duration automatically
131
- */
132
- startTimer(name: string, metadata?: Record<string, unknown>): () => void {
133
- if (!this.enabled) {
134
- return () => {}; // No-op
135
- }
136
-
137
- const startTime = performance.now();
138
- const timerKey = `${name}:${startTime}`;
139
- this.startTimes.set(timerKey, startTime);
140
-
141
- return () => {
142
- const endTime = performance.now();
143
- const duration = endTime - startTime;
144
- this.startTimes.delete(timerKey);
145
-
146
- this.recordEntry({
147
- name,
148
- timestamp: Date.now(),
149
- duration,
150
- metadata,
151
- });
152
- };
153
- }
154
-
155
- /**
156
- * Record a custom metric value
157
- *
158
- * @param name - Name of the metric
159
- * @param value - Numeric value
160
- * @param metadata - Optional metadata
161
- *
162
- * @example
163
- * monitor.recordMetric('item-count', 25);
164
- * monitor.recordMetric('memory-usage', process.memoryUsage().heapUsed);
165
- */
166
- recordMetric(name: string, value: number, metadata?: Record<string, unknown>): void {
167
- if (!this.enabled) return;
168
-
169
- this.recordEntry({
170
- name,
171
- timestamp: Date.now(),
172
- value,
173
- metadata,
174
- });
175
- }
176
-
177
- /**
178
- * Record a performance entry
179
- */
180
- private recordEntry(entry: PerformanceEntry): void {
181
- this.totalRecorded++;
182
-
183
- // Add to circular buffer
184
- if (this.entries.length >= this.maxEntries) {
185
- // Remove oldest entry
186
- this.entries.shift();
187
-
188
- // Auto-export if configured
189
- if (this.autoExport && this.onExport) {
190
- try {
191
- this.onExport(this.getReport());
192
- } catch (error) {
193
- if (this.logWarnings) {
194
- console.warn('Performance monitor auto-export failed:', error);
195
- }
196
- }
197
- }
198
- }
199
-
200
- this.entries.push(entry);
201
- }
202
-
203
- /**
204
- * Get performance report with statistics
205
- */
206
- getReport(): PerformanceReport {
207
- const metrics: Record<
208
- string,
209
- {
210
- count: number;
211
- min: number;
212
- max: number;
213
- avg: number;
214
- total: number;
215
- }
216
- > = {};
217
-
218
- // Calculate statistics for each metric
219
- for (const entry of this.entries) {
220
- const value = entry.duration ?? entry.value ?? 0;
221
-
222
- if (!metrics[entry.name]) {
223
- metrics[entry.name] = {
224
- count: 0,
225
- min: Infinity,
226
- max: -Infinity,
227
- avg: 0,
228
- total: 0,
229
- };
230
- }
231
-
232
- const stats = metrics[entry.name];
233
- stats.count++;
234
- stats.total += value;
235
- stats.min = Math.min(stats.min, value);
236
- stats.max = Math.max(stats.max, value);
237
- }
238
-
239
- // Calculate averages
240
- for (const stats of Object.values(metrics)) {
241
- stats.avg = stats.total / stats.count;
242
- }
243
-
244
- return {
245
- totalEntries: this.totalRecorded,
246
- storedEntries: this.entries.length,
247
- metrics,
248
- recentEntries: [...this.entries],
249
- };
250
- }
251
-
252
- /**
253
- * Get entries for a specific metric name
254
- */
255
- getEntriesByName(name: string): PerformanceEntry[] {
256
- return this.entries.filter((entry) => entry.name === name);
257
- }
258
-
259
- /**
260
- * Clear all stored entries
261
- */
262
- clear(): void {
263
- this.entries = [];
264
- this.totalRecorded = 0;
265
- this.startTimes.clear();
266
- }
267
-
268
- /**
269
- * Export report as JSON string
270
- */
271
- exportJSON(): string {
272
- return JSON.stringify(this.getReport(), null, 2);
273
- }
274
-
275
- /**
276
- * Export report to console
277
- */
278
- exportToConsole(): void {
279
- const report = this.getReport();
280
-
281
- console.group('📊 Performance Report');
282
- console.log(`Total Entries: ${report.totalEntries}`);
283
- console.log(`Stored Entries: ${report.storedEntries}`);
284
- console.log('\nMetrics:');
285
-
286
- for (const [name, stats] of Object.entries(report.metrics)) {
287
- console.group(` ${name}`);
288
- console.log(` Count: ${stats.count}`);
289
- console.log(` Min: ${stats.min.toFixed(2)}ms`);
290
- console.log(` Max: ${stats.max.toFixed(2)}ms`);
291
- console.log(` Avg: ${stats.avg.toFixed(2)}ms`);
292
- console.log(` Total: ${stats.total.toFixed(2)}ms`);
293
- console.groupEnd();
294
- }
295
-
296
- console.groupEnd();
297
- }
298
-
299
- /**
300
- * Get performance marks for Web Performance API integration
301
- *
302
- * If using browser's Performance API, this exports entries
303
- * in a compatible format.
304
- */
305
- getPerformanceMarks(): Array<{
306
- name: string;
307
- startTime: number;
308
- duration?: number;
309
- }> {
310
- return this.entries.map((entry) => ({
311
- name: entry.name,
312
- startTime: entry.timestamp,
313
- duration: entry.duration,
314
- }));
315
- }
316
- }
317
-
318
- /**
319
- * Singleton instance for global performance monitoring
320
- *
321
- * Usage:
322
- * ```typescript
323
- * import { globalPerformanceMonitor } from './utils/PerformanceMonitor';
324
- *
325
- * globalPerformanceMonitor.enable();
326
- * const stop = globalPerformanceMonitor.startTimer('operation');
327
- * // ... work
328
- * stop();
329
- * ```
330
- */
331
- export const globalPerformanceMonitor = new PerformanceMonitor({
332
- enabled: false, // Disabled by default, enable explicitly
333
- maxEntries: 100,
334
- logWarnings: false,
335
- });
@@ -1,73 +0,0 @@
1
- /**
2
- * Drawing analysis utilities for QTI drawing interactions
3
- *
4
- * These utilities help analyze drawing content for scoring purposes.
5
- * They work with ImageData extracted from canvas elements.
6
- */
7
-
8
- import type { QTIFileResponse } from '../types/index.js';
9
-
10
- /**
11
- * Check if a drawing contains at least some drawn content (non-white pixels)
12
- *
13
- * @param imageData - ImageData from canvas (RGBA format, 4 bytes per pixel)
14
- * @param threshold - Minimum number of non-white pixels to consider a line drawn (default: 50)
15
- * @returns true if the drawing contains at least threshold non-white pixels
16
- */
17
- export function hasLine(
18
- imageData: { data: Uint8ClampedArray; width: number; height: number },
19
- threshold: number = 50
20
- ): boolean {
21
- const { data } = imageData;
22
- let nonWhitePixels = 0;
23
-
24
- // Check each pixel (RGBA format: 4 bytes per pixel)
25
- for (let i = 0; i < data.length; i += 4) {
26
- const r = data[i];
27
- const g = data[i + 1];
28
- const b = data[i + 2];
29
- const a = data[i + 3];
30
-
31
- // Consider pixel non-white if:
32
- // - Alpha is significant (> 10)
33
- // - AND color is not white/very light (any channel < 240)
34
- if (a > 10 && (r < 240 || g < 240 || b < 240)) {
35
- nonWhitePixels++;
36
- }
37
- }
38
-
39
- return nonWhitePixels >= threshold;
40
- }
41
-
42
- /**
43
- * Get ImageData from a QTIFileResponse if available
44
- *
45
- * @param fileResponse - QTIFileResponse object (may contain imageData)
46
- * @returns ImageData if available, null otherwise
47
- */
48
- export function getImageDataFromResponse(
49
- fileResponse: QTIFileResponse | null | undefined
50
- ): { data: Uint8ClampedArray; width: number; height: number } | null {
51
- if (!fileResponse?.imageData) {
52
- return null;
53
- }
54
- return fileResponse.imageData;
55
- }
56
-
57
- /**
58
- * Analyze a drawing response to determine if it contains drawn content
59
- *
60
- * @param fileResponse - QTIFileResponse from drawing interaction
61
- * @param threshold - Minimum number of non-white pixels (default: 50)
62
- * @returns true if drawing contains content, false otherwise
63
- */
64
- export function analyzeDrawing(
65
- fileResponse: QTIFileResponse | null | undefined,
66
- threshold: number = 50
67
- ): boolean {
68
- const imageData = getImageDataFromResponse(fileResponse);
69
- if (!imageData) {
70
- return false;
71
- }
72
- return hasLine(imageData, threshold);
73
- }
@@ -1,51 +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
- /**
9
- * Returns true when a response value should be treated as "no response / unanswered".
10
- *
11
- * Notes:
12
- * - `0` and `false` are valid answers in some interactions, so they are NOT empty.
13
- * - Empty objects are treated as empty, and objects whose values are all empty are treated as empty.
14
- */
15
- export function isResponseEmpty(value: unknown): boolean {
16
- if (value === null || value === undefined) return true;
17
-
18
- if (typeof value === 'string') return value.trim() === '';
19
-
20
- if (Array.isArray(value)) {
21
- if (value.length === 0) 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
-
26
- // Files/blobs are valid user responses (upload interactions).
27
- if (typeof Blob !== 'undefined' && value instanceof Blob) return false;
28
-
29
- if (typeof value === 'object') {
30
- const obj = value as Record<string, unknown>;
31
- const keys = Object.keys(obj);
32
- if (keys.length === 0) return true;
33
- return keys.every((k) => isResponseEmpty(obj[k]));
34
- }
35
-
36
- // numbers, booleans, symbols, functions -> treat as "has a response"
37
- return false;
38
- }
39
-
40
- export function countAnsweredForResponseIds(
41
- responses: Record<string, unknown>,
42
- responseIds: readonly string[]
43
- ): number {
44
- let count = 0;
45
- for (const id of responseIds) {
46
- if (!isResponseEmpty(responses[id])) count++;
47
- }
48
- return count;
49
- }
50
-
51
-
@@ -1 +0,0 @@
1
- export { touchDrag, touchDragStyles } from '@pie-qti/qti-common';