@pie-qti/assessment-player 0.1.1

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 (74) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/BACKEND-INTEGRATION.md +620 -0
  3. package/CHANGELOG.md +11 -0
  4. package/EXTENSIBILITY.md +551 -0
  5. package/README.md +1137 -0
  6. package/dist/core/AssessmentPlayer.d.ts +151 -0
  7. package/dist/core/AssessmentPlayer.d.ts.map +1 -0
  8. package/dist/core/AssessmentPlayer.js +595 -0
  9. package/dist/core/ItemSessionController.d.ts +119 -0
  10. package/dist/core/ItemSessionController.d.ts.map +1 -0
  11. package/dist/core/ItemSessionController.js +227 -0
  12. package/dist/core/NavigationManager.d.ts +59 -0
  13. package/dist/core/NavigationManager.d.ts.map +1 -0
  14. package/dist/core/NavigationManager.js +104 -0
  15. package/dist/core/StatePersistenceManager.d.ts +126 -0
  16. package/dist/core/StatePersistenceManager.d.ts.map +1 -0
  17. package/dist/core/StatePersistenceManager.js +267 -0
  18. package/dist/core/TimeManager.d.ts +123 -0
  19. package/dist/core/TimeManager.d.ts.map +1 -0
  20. package/dist/core/TimeManager.js +217 -0
  21. package/dist/core/index.d.ts +10 -0
  22. package/dist/core/index.d.ts.map +1 -0
  23. package/dist/core/index.js +5 -0
  24. package/dist/index.d.ts +6 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +7 -0
  27. package/dist/integration/ReferenceBackendAdapter.d.ts +128 -0
  28. package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -0
  29. package/dist/integration/ReferenceBackendAdapter.js +735 -0
  30. package/dist/integration/api-contract.d.ts +319 -0
  31. package/dist/integration/api-contract.d.ts.map +1 -0
  32. package/dist/integration/api-contract.js +19 -0
  33. package/dist/integration/index.d.ts +47 -0
  34. package/dist/integration/index.d.ts.map +1 -0
  35. package/dist/integration/index.js +46 -0
  36. package/dist/types/index.d.ts +51 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/index.js +7 -0
  39. package/dist/utils/PerformanceMonitor.d.ts +115 -0
  40. package/dist/utils/PerformanceMonitor.d.ts.map +1 -0
  41. package/dist/utils/PerformanceMonitor.js +171 -0
  42. package/package.json +82 -0
  43. package/src/ambient.d.ts +55 -0
  44. package/src/components/AccessibilityAnnouncer.svelte +102 -0
  45. package/src/components/AssessmentHeader.svelte +76 -0
  46. package/src/components/AssessmentShell.svelte +485 -0
  47. package/src/components/AssessmentTimer.svelte +228 -0
  48. package/src/components/ItemRenderer.svelte +147 -0
  49. package/src/components/ItemSessionInfo.svelte +241 -0
  50. package/src/components/NavigationBar.svelte +142 -0
  51. package/src/components/RubricDisplay.svelte +185 -0
  52. package/src/components/SectionMenu.svelte +206 -0
  53. package/src/components/SplitPaneResizer.svelte +288 -0
  54. package/src/components/TestFeedback.svelte +147 -0
  55. package/src/components/index.ts +19 -0
  56. package/src/core/AssessmentPlayer.ts +720 -0
  57. package/src/core/ItemSessionController.ts +287 -0
  58. package/src/core/NavigationManager.ts +126 -0
  59. package/src/core/StatePersistenceManager.ts +344 -0
  60. package/src/core/TimeManager.ts +289 -0
  61. package/src/core/index.ts +15 -0
  62. package/src/index.ts +13 -0
  63. package/src/integration/ReferenceBackendAdapter.ts +861 -0
  64. package/src/integration/api-contract.ts +377 -0
  65. package/src/integration/index.ts +70 -0
  66. package/src/svelte-shims.d.ts +7 -0
  67. package/src/types/index.ts +56 -0
  68. package/src/utils/PerformanceMonitor.ts +222 -0
  69. package/svelte.config.js +8 -0
  70. package/tests/ReferenceBackendAdapter.spec.ts +309 -0
  71. package/tests/setup.ts +103 -0
  72. package/tests/smoke.test.ts +7 -0
  73. package/tsconfig.json +20 -0
  74. package/tsconfig.svelte.json +10 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Assessment Performance Monitor
3
+ *
4
+ * Tracks assessment-level performance metrics including:
5
+ * - Navigation timing
6
+ * - Response submission latency
7
+ * - Section loading times
8
+ * - Overall assessment duration
9
+ *
10
+ * This extends the base performance monitor from item-player with
11
+ * assessment-specific functionality.
12
+ */
13
+ export { globalPerformanceMonitor, PerformanceMonitor, } from '@pie-qti/item-player';
14
+ /**
15
+ * Assessment Performance Tracker
16
+ *
17
+ * Higher-level wrapper around PerformanceMonitor specifically
18
+ * for tracking assessment-level metrics.
19
+ *
20
+ * Usage:
21
+ * ```typescript
22
+ * import { AssessmentPerformanceTracker } from './utils/PerformanceMonitor';
23
+ *
24
+ * const tracker = new AssessmentPerformanceTracker({ enabled: true });
25
+ *
26
+ * tracker.startAssessment();
27
+ * tracker.trackNavigation('next');
28
+ * tracker.trackItemStart('item-001');
29
+ * tracker.trackItemComplete('item-001');
30
+ * tracker.trackSubmission(125); // Latency in ms
31
+ * tracker.endAssessment();
32
+ *
33
+ * const metrics = tracker.getAssessmentMetrics();
34
+ * console.log(metrics);
35
+ * ```
36
+ */
37
+ export class AssessmentPerformanceTracker {
38
+ constructor(config = {}) {
39
+ this.itemStartTimes = new Map();
40
+ this.itemDurations = [];
41
+ this.navigationCount = 0;
42
+ this.submissionCount = 0;
43
+ this.submissionLatencies = [];
44
+ this.enabled = config.enabled ?? false;
45
+ }
46
+ /**
47
+ * Enable tracking
48
+ */
49
+ enable() {
50
+ this.enabled = true;
51
+ }
52
+ /**
53
+ * Disable tracking
54
+ */
55
+ disable() {
56
+ this.enabled = false;
57
+ }
58
+ /**
59
+ * Mark assessment start
60
+ */
61
+ startAssessment() {
62
+ if (!this.enabled)
63
+ return;
64
+ this.assessmentStartTime = performance.now();
65
+ }
66
+ /**
67
+ * Mark assessment end
68
+ */
69
+ endAssessment() {
70
+ if (!this.enabled || !this.assessmentStartTime)
71
+ return;
72
+ this.assessmentEndTime = performance.now();
73
+ }
74
+ /**
75
+ * Track navigation event
76
+ */
77
+ trackNavigation(_type) {
78
+ if (!this.enabled)
79
+ return;
80
+ this.navigationCount++;
81
+ }
82
+ /**
83
+ * Track item start
84
+ */
85
+ trackItemStart(itemId) {
86
+ if (!this.enabled)
87
+ return;
88
+ this.itemStartTimes.set(itemId, performance.now());
89
+ }
90
+ /**
91
+ * Track item completion
92
+ */
93
+ trackItemComplete(itemId) {
94
+ if (!this.enabled)
95
+ return;
96
+ const startTime = this.itemStartTimes.get(itemId);
97
+ if (startTime) {
98
+ const duration = performance.now() - startTime;
99
+ this.itemDurations.push(duration);
100
+ this.itemStartTimes.delete(itemId);
101
+ }
102
+ }
103
+ /**
104
+ * Track response submission
105
+ */
106
+ trackSubmission(latencyMs) {
107
+ if (!this.enabled)
108
+ return;
109
+ this.submissionCount++;
110
+ this.submissionLatencies.push(latencyMs);
111
+ }
112
+ /**
113
+ * Get aggregated assessment metrics
114
+ */
115
+ getAssessmentMetrics() {
116
+ const metrics = {
117
+ itemsCompleted: this.itemDurations.length,
118
+ navigationCount: this.navigationCount,
119
+ submissionCount: this.submissionCount,
120
+ };
121
+ // Calculate total duration
122
+ if (this.assessmentStartTime && this.assessmentEndTime) {
123
+ metrics.assessmentStartTime = this.assessmentStartTime;
124
+ metrics.assessmentEndTime = this.assessmentEndTime;
125
+ metrics.totalDuration = this.assessmentEndTime - this.assessmentStartTime;
126
+ }
127
+ // Calculate average item time
128
+ if (this.itemDurations.length > 0) {
129
+ const sum = this.itemDurations.reduce((a, b) => a + b, 0);
130
+ metrics.averageItemTime = sum / this.itemDurations.length;
131
+ }
132
+ // Calculate average submission latency
133
+ if (this.submissionLatencies.length > 0) {
134
+ const sum = this.submissionLatencies.reduce((a, b) => a + b, 0);
135
+ metrics.averageSubmissionLatency = sum / this.submissionLatencies.length;
136
+ }
137
+ return metrics;
138
+ }
139
+ /**
140
+ * Reset all metrics
141
+ */
142
+ reset() {
143
+ this.assessmentStartTime = undefined;
144
+ this.assessmentEndTime = undefined;
145
+ this.itemStartTimes.clear();
146
+ this.itemDurations = [];
147
+ this.navigationCount = 0;
148
+ this.submissionCount = 0;
149
+ this.submissionLatencies = [];
150
+ }
151
+ /**
152
+ * Export metrics to console
153
+ */
154
+ exportToConsole() {
155
+ const metrics = this.getAssessmentMetrics();
156
+ console.group('📊 Assessment Performance Metrics');
157
+ if (metrics.totalDuration) {
158
+ console.log(`Total Duration: ${(metrics.totalDuration / 1000).toFixed(1)}s`);
159
+ }
160
+ console.log(`Items Completed: ${metrics.itemsCompleted}`);
161
+ if (metrics.averageItemTime) {
162
+ console.log(`Average Item Time: ${(metrics.averageItemTime / 1000).toFixed(1)}s`);
163
+ }
164
+ console.log(`Navigation Events: ${metrics.navigationCount}`);
165
+ console.log(`Submissions: ${metrics.submissionCount}`);
166
+ if (metrics.averageSubmissionLatency) {
167
+ console.log(`Average Submission Latency: ${metrics.averageSubmissionLatency.toFixed(0)}ms`);
168
+ }
169
+ console.groupEnd();
170
+ }
171
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@pie-qti/assessment-player",
3
+ "version": "0.1.1",
4
+ "description": "QTI Assessment Player supporting QTI 2.x and 3.0 - Multi-item test player with navigation, sections, and rubric blocks",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "bun test --preload ./tests/setup.ts",
11
+ "typecheck": "tsc --noEmit",
12
+ "check": "svelte-check --tsconfig ./tsconfig.svelte.json",
13
+ "lint": "biome check .",
14
+ "lint:fix": "biome check --write .",
15
+ "format": "biome format --write ."
16
+ },
17
+ "keywords": [
18
+ "qti",
19
+ "qti2",
20
+ "qti3",
21
+ "qti 2.x",
22
+ "qti 3.0",
23
+ "assessment",
24
+ "test",
25
+ "player",
26
+ "navigation",
27
+ "e-learning"
28
+ ],
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@pie-qti/qti-processing": "workspace:*",
32
+ "@pie-qti/i18n": "workspace:*",
33
+ "@pie-qti/item-player": "workspace:*",
34
+ "@pie-qti/default-components": "workspace:*",
35
+ "node-html-parser": "^7.0.2"
36
+ },
37
+ "peerDependencies": {
38
+ "svelte": "^5.46.1"
39
+ },
40
+ "devDependencies": {
41
+ "@biomejs/biome": "^2.3.11",
42
+ "@types/node": "^25.0.3",
43
+ "svelte": "^5.46.1",
44
+ "svelte-check": "^4.3.5",
45
+ "typescript": "^5.9.3"
46
+ },
47
+ "exports": {
48
+ ".": {
49
+ "types": "./dist/index.d.ts",
50
+ "import": "./dist/index.js"
51
+ },
52
+ "./integration": {
53
+ "types": "./dist/integration/index.d.ts",
54
+ "import": "./dist/integration/index.js"
55
+ },
56
+ "./components": {
57
+ "types": "./src/components/index.ts",
58
+ "import": "./src/components/index.ts",
59
+ "svelte": "./src/components/index.ts"
60
+ },
61
+ "./components/AssessmentShell.svelte": {
62
+ "import": "./src/components/AssessmentShell.svelte",
63
+ "svelte": "./src/components/AssessmentShell.svelte"
64
+ },
65
+ "./components/NavigationBar.svelte": {
66
+ "import": "./src/components/NavigationBar.svelte",
67
+ "svelte": "./src/components/NavigationBar.svelte"
68
+ },
69
+ "./components/SectionMenu.svelte": {
70
+ "import": "./src/components/SectionMenu.svelte",
71
+ "svelte": "./src/components/SectionMenu.svelte"
72
+ },
73
+ "./components/RubricDisplay.svelte": {
74
+ "import": "./src/components/RubricDisplay.svelte",
75
+ "svelte": "./src/components/RubricDisplay.svelte"
76
+ },
77
+ "./components/ItemRenderer.svelte": {
78
+ "import": "./src/components/ItemRenderer.svelte",
79
+ "svelte": "./src/components/ItemRenderer.svelte"
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,55 @@
1
+ declare namespace svelteHTML {
2
+ interface HTMLAttributes<T> {
3
+ onclick?: (event: MouseEvent) => void;
4
+ onchange?: (event: Event) => void;
5
+ oninput?: (event: Event) => void;
6
+ onsubmit?: (event: Event) => void;
7
+ onkeydown?: (event: KeyboardEvent) => void;
8
+ onkeyup?: (event: KeyboardEvent) => void;
9
+ onmousedown?: (event: MouseEvent) => void;
10
+ onmouseup?: (event: MouseEvent) => void;
11
+ onmousemove?: (event: MouseEvent) => void;
12
+ onmouseenter?: (event: MouseEvent) => void;
13
+ onmouseleave?: (event: MouseEvent) => void;
14
+ onfocus?: (event: FocusEvent) => void;
15
+ onblur?: (event: FocusEvent) => void;
16
+ ondragstart?: (event: DragEvent) => void;
17
+ ondragend?: (event: DragEvent) => void;
18
+ ondragover?: (event: DragEvent) => void;
19
+ ondragleave?: (event: DragEvent) => void;
20
+ ondrop?: (event: DragEvent) => void;
21
+ }
22
+ }
23
+
24
+ declare module 'svelte/elements' {
25
+ interface HTMLButtonAttributes {
26
+ onclick?: (event: MouseEvent) => void;
27
+ onmousedown?: (event: MouseEvent) => void;
28
+ onmouseup?: (event: MouseEvent) => void;
29
+ onmouseenter?: (event: MouseEvent) => void;
30
+ onmouseleave?: (event: MouseEvent) => void;
31
+ onfocus?: (event: FocusEvent) => void;
32
+ onblur?: (event: FocusEvent) => void;
33
+ }
34
+
35
+ interface HTMLAttributes<T = HTMLElement> {
36
+ onclick?: (event: MouseEvent) => void;
37
+ onchange?: (event: Event) => void;
38
+ oninput?: (event: Event) => void;
39
+ onsubmit?: (event: Event) => void;
40
+ onkeydown?: (event: KeyboardEvent) => void;
41
+ onkeyup?: (event: KeyboardEvent) => void;
42
+ onmousedown?: (event: MouseEvent) => void;
43
+ onmouseup?: (event: MouseEvent) => void;
44
+ onmousemove?: (event: MouseEvent) => void;
45
+ onmouseenter?: (event: MouseEvent) => void;
46
+ onmouseleave?: (event: MouseEvent) => void;
47
+ onfocus?: (event: FocusEvent) => void;
48
+ onblur?: (event: FocusEvent) => void;
49
+ ondragstart?: (event: DragEvent) => void;
50
+ ondragend?: (event: DragEvent) => void;
51
+ ondragover?: (event: DragEvent) => void;
52
+ ondragleave?: (event: DragEvent) => void;
53
+ ondrop?: (event: DragEvent) => void;
54
+ }
55
+ }
@@ -0,0 +1,102 @@
1
+ <script lang="ts">
2
+ import { onDestroy } from 'svelte';
3
+
4
+ /**
5
+ * Accessibility Announcer Component
6
+ *
7
+ * Provides ARIA live region for announcing dynamic content changes
8
+ * to screen reader users, particularly for state restoration.
9
+ *
10
+ * Usage:
11
+ * ```svelte
12
+ * <AccessibilityAnnouncer bind:this={announcer} />
13
+ *
14
+ * // Later announce something
15
+ * announcer.announce('Session restored from previous attempt');
16
+ * ```
17
+ */
18
+
19
+ interface Props {
20
+ /** Priority level for announcements */
21
+ priority?: 'polite' | 'assertive';
22
+ }
23
+
24
+ const { priority = 'polite' }: Props = $props();
25
+
26
+ let announcement = $state('');
27
+ let announceTimeout: ReturnType<typeof setTimeout> | null = null;
28
+
29
+ // Clean up timeout on destroy to prevent memory leaks
30
+ onDestroy(() => {
31
+ if (announceTimeout) {
32
+ clearTimeout(announceTimeout);
33
+ announceTimeout = null;
34
+ }
35
+ });
36
+
37
+ /**
38
+ * Announce a message to screen readers
39
+ *
40
+ * @param message - Text to announce
41
+ * @param clearAfter - Milliseconds to wait before clearing (default: 1000)
42
+ */
43
+ export function announce(message: string, clearAfter = 1000): void {
44
+ // Clear any existing announcement timeout
45
+ if (announceTimeout) {
46
+ clearTimeout(announceTimeout);
47
+ announceTimeout = null;
48
+ }
49
+
50
+ // Set the new announcement
51
+ announcement = message;
52
+
53
+ // Clear after delay to allow screen readers to announce
54
+ // and prepare for next announcement
55
+ announceTimeout = setTimeout(() => {
56
+ announcement = '';
57
+ announceTimeout = null;
58
+ }, clearAfter);
59
+ }
60
+
61
+ /**
62
+ * Clear the current announcement immediately
63
+ */
64
+ export function clear(): void {
65
+ if (announceTimeout) {
66
+ clearTimeout(announceTimeout);
67
+ announceTimeout = null;
68
+ }
69
+ announcement = '';
70
+ }
71
+ </script>
72
+
73
+ <!--
74
+ ARIA live region for screen reader announcements
75
+ - visually-hidden: Hide from sighted users but available to screen readers
76
+ - aria-live: Announce changes to this region
77
+ - aria-atomic: Read entire region content when it changes
78
+ - role="status": Indicates this is a status message
79
+ -->
80
+ <div
81
+ class="sr-only"
82
+ role="status"
83
+ aria-live={priority}
84
+ aria-atomic="true"
85
+ >
86
+ {announcement}
87
+ </div>
88
+
89
+ <style>
90
+ /* Screen reader only - visually hidden but accessible */
91
+ .sr-only {
92
+ position: absolute;
93
+ width: 1px;
94
+ height: 1px;
95
+ padding: 0;
96
+ margin: -1px;
97
+ overflow: hidden;
98
+ clip: rect(0, 0, 0, 0);
99
+ white-space: nowrap;
100
+ border-width: 0;
101
+ }
102
+ </style>
@@ -0,0 +1,76 @@
1
+ <script lang="ts">
2
+ import SectionMenu from './SectionMenu.svelte';
3
+
4
+ interface Section {
5
+ id: string;
6
+ title?: string;
7
+ index: number;
8
+ }
9
+
10
+ interface Props {
11
+ /** Assessment title */
12
+ title: string;
13
+ /** Available sections */
14
+ sections?: Section[];
15
+ /** Current section index */
16
+ currentSectionIndex?: number;
17
+ /** Whether to show section menu */
18
+ showSections?: boolean;
19
+ /** Whether section navigation is allowed */
20
+ allowSectionNavigation?: boolean;
21
+ /** Section selection callback */
22
+ onSectionSelect?: (sectionIndex: number) => void;
23
+ }
24
+
25
+ const {
26
+ title,
27
+ sections = [],
28
+ currentSectionIndex,
29
+ showSections = true,
30
+ allowSectionNavigation = true,
31
+ onSectionSelect
32
+ }: Props = $props();
33
+ </script>
34
+
35
+ <div class="assessment-header">
36
+ <div class="assessment-title">
37
+ <h2 class="text-2xl font-bold">{title}</h2>
38
+ </div>
39
+
40
+ {#if showSections && sections.length > 1}
41
+ <SectionMenu
42
+ {sections}
43
+ {currentSectionIndex}
44
+ {onSectionSelect}
45
+ disabled={!allowSectionNavigation}
46
+ />
47
+ {/if}
48
+ </div>
49
+
50
+ <style>
51
+ .assessment-header {
52
+ display: flex;
53
+ justify-content: space-between;
54
+ align-items: center;
55
+ padding: 1.5rem;
56
+ border-bottom: 1px solid var(--color-base-300);
57
+ background: var(--color-base-100);
58
+ position: sticky;
59
+ top: 0;
60
+ z-index: 10;
61
+ }
62
+
63
+ .assessment-title {
64
+ flex: 1;
65
+ }
66
+
67
+ @media (max-width: 768px) {
68
+ .assessment-header {
69
+ padding: 1rem;
70
+ }
71
+
72
+ .assessment-title :global(h2) {
73
+ font-size: 1.25rem;
74
+ }
75
+ }
76
+ </style>