@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,267 @@
1
+ /**
2
+ * StatePersistenceManager
3
+ *
4
+ * Manages automatic state persistence for assessment sessions.
5
+ * Supports both client-side (localStorage) and server-side persistence.
6
+ *
7
+ * Features:
8
+ * - Auto-save on state changes (debounced)
9
+ * - Manual save triggers
10
+ * - State restoration
11
+ * - Optional backend integration
12
+ * - Fallback to localStorage when backend unavailable
13
+ */
14
+ export class StatePersistenceManager {
15
+ constructor(config) {
16
+ this.currentState = null;
17
+ this.autoSaveTimer = null;
18
+ this.isSaving = false;
19
+ this.memoryStorage = new Map();
20
+ this.config = {
21
+ autoSave: true,
22
+ autoSaveDelay: 2000,
23
+ storage: 'localStorage',
24
+ ...config,
25
+ };
26
+ }
27
+ /**
28
+ * Update state and trigger auto-save
29
+ */
30
+ updateState(state) {
31
+ // Merge with existing state
32
+ this.currentState = {
33
+ ...this.currentState,
34
+ assessmentId: this.config.assessmentId,
35
+ savedAt: Date.now(),
36
+ ...state,
37
+ };
38
+ // Trigger auto-save
39
+ if (this.config.autoSave) {
40
+ this.scheduleAutoSave();
41
+ }
42
+ }
43
+ /**
44
+ * Schedule auto-save with debouncing
45
+ */
46
+ scheduleAutoSave() {
47
+ // Clear existing timer
48
+ if (this.autoSaveTimer) {
49
+ clearTimeout(this.autoSaveTimer);
50
+ }
51
+ // Schedule new save
52
+ this.autoSaveTimer = setTimeout(() => {
53
+ this.save().catch((error) => {
54
+ console.error('[StatePersistenceManager] Auto-save failed:', error);
55
+ this.config.onSaveError?.(error);
56
+ });
57
+ }, this.config.autoSaveDelay);
58
+ }
59
+ /**
60
+ * Manually save current state
61
+ */
62
+ async save() {
63
+ if (!this.currentState) {
64
+ return;
65
+ }
66
+ if (this.isSaving) {
67
+ console.warn('[StatePersistenceManager] Save already in progress');
68
+ return;
69
+ }
70
+ this.isSaving = true;
71
+ try {
72
+ // Update timestamp
73
+ this.currentState.savedAt = Date.now();
74
+ // Try backend save first (if configured)
75
+ if (this.config.onBackendSave) {
76
+ try {
77
+ await this.config.onBackendSave(this.currentState);
78
+ }
79
+ catch (backendError) {
80
+ console.warn('[StatePersistenceManager] Backend save failed, falling back to local:', backendError);
81
+ // Continue to local save as fallback
82
+ }
83
+ }
84
+ // Save to local storage
85
+ this.saveToStorage(this.currentState);
86
+ // Success callback
87
+ this.config.onSaveSuccess?.(this.currentState);
88
+ }
89
+ catch (error) {
90
+ console.error('[StatePersistenceManager] Save failed:', error);
91
+ this.config.onSaveError?.(error);
92
+ throw error;
93
+ }
94
+ finally {
95
+ this.isSaving = false;
96
+ }
97
+ }
98
+ /**
99
+ * Save to configured storage
100
+ */
101
+ saveToStorage(state) {
102
+ const key = this.getStorageKey();
103
+ const data = JSON.stringify(state);
104
+ try {
105
+ switch (this.config.storage) {
106
+ case 'localStorage':
107
+ if (typeof localStorage !== 'undefined') {
108
+ localStorage.setItem(key, data);
109
+ }
110
+ else {
111
+ this.memoryStorage.set(key, data);
112
+ }
113
+ break;
114
+ case 'sessionStorage':
115
+ if (typeof sessionStorage !== 'undefined') {
116
+ sessionStorage.setItem(key, data);
117
+ }
118
+ else {
119
+ this.memoryStorage.set(key, data);
120
+ }
121
+ break;
122
+ case 'memory':
123
+ this.memoryStorage.set(key, data);
124
+ break;
125
+ }
126
+ }
127
+ catch (error) {
128
+ // Storage quota exceeded or other storage error
129
+ console.error('[StatePersistenceManager] Storage save failed:', error);
130
+ // Fallback to memory storage
131
+ this.memoryStorage.set(key, data);
132
+ }
133
+ }
134
+ /**
135
+ * Load state from storage
136
+ */
137
+ async load() {
138
+ const key = this.getStorageKey();
139
+ let data = null;
140
+ try {
141
+ switch (this.config.storage) {
142
+ case 'localStorage':
143
+ data = typeof localStorage !== 'undefined'
144
+ ? localStorage.getItem(key)
145
+ : this.memoryStorage.get(key) || null;
146
+ break;
147
+ case 'sessionStorage':
148
+ data = typeof sessionStorage !== 'undefined'
149
+ ? sessionStorage.getItem(key)
150
+ : this.memoryStorage.get(key) || null;
151
+ break;
152
+ case 'memory':
153
+ data = this.memoryStorage.get(key) || null;
154
+ break;
155
+ }
156
+ if (!data) {
157
+ return null;
158
+ }
159
+ const state = JSON.parse(data);
160
+ this.currentState = state;
161
+ return state;
162
+ }
163
+ catch (error) {
164
+ console.error('[StatePersistenceManager] Failed to load state:', error);
165
+ return null;
166
+ }
167
+ }
168
+ /**
169
+ * Check if saved state exists
170
+ */
171
+ async hasSavedState() {
172
+ const state = await this.load();
173
+ return state !== null;
174
+ }
175
+ /**
176
+ * Clear saved state
177
+ */
178
+ async clear() {
179
+ const key = this.getStorageKey();
180
+ try {
181
+ switch (this.config.storage) {
182
+ case 'localStorage':
183
+ if (typeof localStorage !== 'undefined') {
184
+ localStorage.removeItem(key);
185
+ }
186
+ this.memoryStorage.delete(key);
187
+ break;
188
+ case 'sessionStorage':
189
+ if (typeof sessionStorage !== 'undefined') {
190
+ sessionStorage.removeItem(key);
191
+ }
192
+ this.memoryStorage.delete(key);
193
+ break;
194
+ case 'memory':
195
+ this.memoryStorage.delete(key);
196
+ break;
197
+ }
198
+ this.currentState = null;
199
+ }
200
+ catch (error) {
201
+ console.error('[StatePersistenceManager] Failed to clear state:', error);
202
+ }
203
+ }
204
+ /**
205
+ * Get current state without saving
206
+ */
207
+ getCurrentState() {
208
+ return this.currentState ? { ...this.currentState } : null;
209
+ }
210
+ /**
211
+ * Get storage key for this session
212
+ */
213
+ getStorageKey() {
214
+ return `qti-assessment-${this.config.assessmentId}-${this.config.sessionId}`;
215
+ }
216
+ /**
217
+ * Force immediate save (bypasses debounce)
218
+ */
219
+ async forceSave() {
220
+ // Clear any pending auto-save
221
+ if (this.autoSaveTimer) {
222
+ clearTimeout(this.autoSaveTimer);
223
+ this.autoSaveTimer = null;
224
+ }
225
+ await this.save();
226
+ }
227
+ /**
228
+ * Pause auto-save (useful during navigation transitions)
229
+ */
230
+ pauseAutoSave() {
231
+ if (this.autoSaveTimer) {
232
+ clearTimeout(this.autoSaveTimer);
233
+ this.autoSaveTimer = null;
234
+ }
235
+ }
236
+ /**
237
+ * Resume auto-save
238
+ */
239
+ resumeAutoSave() {
240
+ if (this.config.autoSave && this.currentState) {
241
+ this.scheduleAutoSave();
242
+ }
243
+ }
244
+ /**
245
+ * Get last save timestamp
246
+ */
247
+ getLastSaveTime() {
248
+ return this.currentState?.savedAt || null;
249
+ }
250
+ /**
251
+ * Check if state has been modified since last save
252
+ */
253
+ isDirty() {
254
+ // Simple check - could be enhanced with deep comparison
255
+ return this.autoSaveTimer !== null;
256
+ }
257
+ /**
258
+ * Cleanup
259
+ */
260
+ destroy() {
261
+ if (this.autoSaveTimer) {
262
+ clearTimeout(this.autoSaveTimer);
263
+ this.autoSaveTimer = null;
264
+ }
265
+ this.currentState = null;
266
+ }
267
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * TimeManager
3
+ *
4
+ * Manages time limits and tracking for QTI assessments.
5
+ * Supports test-level, section-level, and item-level time limits.
6
+ *
7
+ * Features:
8
+ * - Countdown timers with warnings
9
+ * - Auto-submission when time expires
10
+ * - Time spent tracking per item
11
+ * - Pause/resume support
12
+ * - Late submission handling
13
+ */
14
+ import type { TimeLimits } from '../types/index.js';
15
+ export interface TimeManagerConfig {
16
+ /** Assessment-level time limits */
17
+ assessmentTimeLimits?: TimeLimits;
18
+ /** Warning threshold (seconds before expiry) */
19
+ warningThreshold?: number;
20
+ /** Callback when time warning is triggered */
21
+ onWarning?: (remainingSeconds: number) => void;
22
+ /** Callback when time expires */
23
+ onExpired?: () => void;
24
+ /** Callback for time updates (fires every second) */
25
+ onTick?: (remainingSeconds: number, elapsedSeconds: number) => void;
26
+ }
27
+ export interface TimeTrackingState {
28
+ /** Total elapsed time (ms) */
29
+ totalElapsed: number;
30
+ /** Time spent per item identifier (ms) */
31
+ itemTimes: Record<string, number>;
32
+ /** Time spent per section identifier (ms) */
33
+ sectionTimes: Record<string, number>;
34
+ /** Session start timestamp */
35
+ startedAt: number;
36
+ /** Current item start time (for tracking) */
37
+ currentItemStartTime?: number;
38
+ /** Current section identifier */
39
+ currentSectionId?: string;
40
+ /** Is timer currently paused */
41
+ isPaused: boolean;
42
+ }
43
+ export declare class TimeManager {
44
+ private config;
45
+ private state;
46
+ private intervalId;
47
+ private maxTimeSeconds;
48
+ private warningTriggered;
49
+ constructor(config: TimeManagerConfig);
50
+ /**
51
+ * Start or resume the timer
52
+ */
53
+ private startTimer;
54
+ /**
55
+ * Handle time expiration
56
+ */
57
+ private handleExpiration;
58
+ /**
59
+ * Stop the timer
60
+ */
61
+ stopTimer(): void;
62
+ /**
63
+ * Pause the timer
64
+ */
65
+ pause(): void;
66
+ /**
67
+ * Resume the timer
68
+ */
69
+ resume(): void;
70
+ /**
71
+ * Start tracking time for an item
72
+ */
73
+ startItem(_itemIdentifier: string): void;
74
+ /**
75
+ * End tracking time for current item
76
+ */
77
+ private endCurrentItem;
78
+ /**
79
+ * End tracking time for an item
80
+ */
81
+ endItem(itemIdentifier: string): void;
82
+ /**
83
+ * Start tracking time for a section
84
+ */
85
+ startSection(sectionIdentifier: string): void;
86
+ /**
87
+ * Get remaining time in seconds (null if no limit)
88
+ */
89
+ getRemainingSeconds(): number | null;
90
+ /**
91
+ * Get elapsed time in seconds
92
+ */
93
+ getElapsedSeconds(): number;
94
+ /**
95
+ * Get time spent on a specific item (ms)
96
+ */
97
+ getItemTime(itemIdentifier: string): number;
98
+ /**
99
+ * Get current tracking state (for persistence)
100
+ */
101
+ getState(): TimeTrackingState;
102
+ /**
103
+ * Restore tracking state (for resume)
104
+ */
105
+ restoreState(state: TimeTrackingState): void;
106
+ /**
107
+ * Check if time has expired
108
+ */
109
+ isExpired(): boolean;
110
+ /**
111
+ * Check if late submission is allowed
112
+ */
113
+ allowsLateSubmission(): boolean;
114
+ /**
115
+ * Format time as MM:SS or HH:MM:SS
116
+ */
117
+ static formatTime(seconds: number): string;
118
+ /**
119
+ * Cleanup - stop all timers
120
+ */
121
+ destroy(): void;
122
+ }
123
+ //# sourceMappingURL=TimeManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeManager.d.ts","sourceRoot":"","sources":["../../src/core/TimeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,iBAAiB;IACjC,mCAAmC;IACnC,oBAAoB,CAAC,EAAE,UAAU,CAAC;IAClC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,8CAA8C;IAC9C,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,qDAAqD;IACrD,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;CACpE;AAED,MAAM,WAAW,iBAAiB;IACjC,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IAChC,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,WAAW;IACvB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAAoB;IAGjC,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,gBAAgB,CAAS;gBAErB,MAAM,EAAE,iBAAiB;IAiBrC;;OAEG;IACH,OAAO,CAAC,UAAU;IA+ClB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;OAEG;IACH,SAAS,IAAI,IAAI;IAOjB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;IASxC;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAUrC;;OAEG;IACH,YAAY,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IAI7C;;OAEG;IACH,mBAAmB,IAAI,MAAM,GAAG,IAAI;IASpC;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAI3B;;OAEG;IACH,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM;IAI3C;;OAEG;IACH,QAAQ,IAAI,iBAAiB;IAI7B;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAY5C;;OAEG;IACH,SAAS,IAAI,OAAO;IASpB;;OAEG;IACH,oBAAoB,IAAI,OAAO;IAI/B;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAY1C;;OAEG;IACH,OAAO,IAAI,IAAI;CAGf"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * TimeManager
3
+ *
4
+ * Manages time limits and tracking for QTI assessments.
5
+ * Supports test-level, section-level, and item-level time limits.
6
+ *
7
+ * Features:
8
+ * - Countdown timers with warnings
9
+ * - Auto-submission when time expires
10
+ * - Time spent tracking per item
11
+ * - Pause/resume support
12
+ * - Late submission handling
13
+ */
14
+ export class TimeManager {
15
+ constructor(config) {
16
+ // Timer internals
17
+ this.intervalId = null;
18
+ this.maxTimeSeconds = null;
19
+ this.warningTriggered = false;
20
+ this.config = config;
21
+ this.state = {
22
+ totalElapsed: 0,
23
+ itemTimes: {},
24
+ sectionTimes: {},
25
+ startedAt: Date.now(),
26
+ isPaused: false,
27
+ };
28
+ // Initialize timer if time limit exists
29
+ if (config.assessmentTimeLimits?.maxTime) {
30
+ this.maxTimeSeconds = config.assessmentTimeLimits.maxTime;
31
+ this.startTimer();
32
+ }
33
+ }
34
+ /**
35
+ * Start or resume the timer
36
+ */
37
+ startTimer() {
38
+ if (this.intervalId) {
39
+ return; // Already running
40
+ }
41
+ this.state.isPaused = false;
42
+ this.intervalId = setInterval(() => {
43
+ if (this.state.isPaused) {
44
+ return;
45
+ }
46
+ this.state.totalElapsed += 1000; // Increment by 1 second
47
+ const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
48
+ // Track item time if active
49
+ if (this.state.currentItemStartTime) {
50
+ // Item tracking handled by startItem/endItem
51
+ }
52
+ // Calculate remaining time
53
+ if (this.maxTimeSeconds) {
54
+ const remainingSeconds = this.maxTimeSeconds - elapsedSeconds;
55
+ // Trigger warning
56
+ const warningThreshold = this.config.warningThreshold || 60;
57
+ if (!this.warningTriggered && remainingSeconds <= warningThreshold && remainingSeconds > 0) {
58
+ this.warningTriggered = true;
59
+ this.config.onWarning?.(remainingSeconds);
60
+ }
61
+ // Trigger expiration
62
+ if (remainingSeconds <= 0) {
63
+ this.handleExpiration();
64
+ return;
65
+ }
66
+ // Tick callback
67
+ this.config.onTick?.(remainingSeconds, elapsedSeconds);
68
+ }
69
+ else {
70
+ // No limit - just count up
71
+ this.config.onTick?.(0, elapsedSeconds);
72
+ }
73
+ }, 1000);
74
+ }
75
+ /**
76
+ * Handle time expiration
77
+ */
78
+ handleExpiration() {
79
+ this.stopTimer();
80
+ this.config.onExpired?.();
81
+ }
82
+ /**
83
+ * Stop the timer
84
+ */
85
+ stopTimer() {
86
+ if (this.intervalId) {
87
+ clearInterval(this.intervalId);
88
+ this.intervalId = null;
89
+ }
90
+ }
91
+ /**
92
+ * Pause the timer
93
+ */
94
+ pause() {
95
+ this.state.isPaused = true;
96
+ }
97
+ /**
98
+ * Resume the timer
99
+ */
100
+ resume() {
101
+ this.state.isPaused = false;
102
+ }
103
+ /**
104
+ * Start tracking time for an item
105
+ */
106
+ startItem(_itemIdentifier) {
107
+ // End previous item if any
108
+ if (this.state.currentItemStartTime) {
109
+ this.endCurrentItem();
110
+ }
111
+ this.state.currentItemStartTime = Date.now();
112
+ }
113
+ /**
114
+ * End tracking time for current item
115
+ */
116
+ endCurrentItem() {
117
+ if (!this.state.currentItemStartTime) {
118
+ return;
119
+ }
120
+ const timeSpent = Date.now() - this.state.currentItemStartTime;
121
+ // Note: We need the item identifier, which should be tracked separately
122
+ // For now, we'll handle this in the endItem method
123
+ this.state.currentItemStartTime = undefined;
124
+ }
125
+ /**
126
+ * End tracking time for an item
127
+ */
128
+ endItem(itemIdentifier) {
129
+ if (!this.state.currentItemStartTime) {
130
+ return;
131
+ }
132
+ const timeSpent = Date.now() - this.state.currentItemStartTime;
133
+ this.state.itemTimes[itemIdentifier] = (this.state.itemTimes[itemIdentifier] || 0) + timeSpent;
134
+ this.state.currentItemStartTime = undefined;
135
+ }
136
+ /**
137
+ * Start tracking time for a section
138
+ */
139
+ startSection(sectionIdentifier) {
140
+ this.state.currentSectionId = sectionIdentifier;
141
+ }
142
+ /**
143
+ * Get remaining time in seconds (null if no limit)
144
+ */
145
+ getRemainingSeconds() {
146
+ if (!this.maxTimeSeconds) {
147
+ return null;
148
+ }
149
+ const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
150
+ return Math.max(0, this.maxTimeSeconds - elapsedSeconds);
151
+ }
152
+ /**
153
+ * Get elapsed time in seconds
154
+ */
155
+ getElapsedSeconds() {
156
+ return Math.floor(this.state.totalElapsed / 1000);
157
+ }
158
+ /**
159
+ * Get time spent on a specific item (ms)
160
+ */
161
+ getItemTime(itemIdentifier) {
162
+ return this.state.itemTimes[itemIdentifier] || 0;
163
+ }
164
+ /**
165
+ * Get current tracking state (for persistence)
166
+ */
167
+ getState() {
168
+ return { ...this.state };
169
+ }
170
+ /**
171
+ * Restore tracking state (for resume)
172
+ */
173
+ restoreState(state) {
174
+ this.state = { ...state };
175
+ // Restart timer if not expired
176
+ if (this.maxTimeSeconds) {
177
+ const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
178
+ if (elapsedSeconds < this.maxTimeSeconds) {
179
+ this.startTimer();
180
+ }
181
+ }
182
+ }
183
+ /**
184
+ * Check if time has expired
185
+ */
186
+ isExpired() {
187
+ if (!this.maxTimeSeconds) {
188
+ return false;
189
+ }
190
+ const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
191
+ return elapsedSeconds >= this.maxTimeSeconds;
192
+ }
193
+ /**
194
+ * Check if late submission is allowed
195
+ */
196
+ allowsLateSubmission() {
197
+ return this.config.assessmentTimeLimits?.allowLateSubmission || false;
198
+ }
199
+ /**
200
+ * Format time as MM:SS or HH:MM:SS
201
+ */
202
+ static formatTime(seconds) {
203
+ const hours = Math.floor(seconds / 3600);
204
+ const minutes = Math.floor((seconds % 3600) / 60);
205
+ const secs = seconds % 60;
206
+ if (hours > 0) {
207
+ return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
208
+ }
209
+ return `${minutes}:${secs.toString().padStart(2, '0')}`;
210
+ }
211
+ /**
212
+ * Cleanup - stop all timers
213
+ */
214
+ destroy() {
215
+ this.stopTimer();
216
+ }
217
+ }
@@ -0,0 +1,10 @@
1
+ export { AssessmentPlayer } from './AssessmentPlayer.js';
2
+ export type { ItemSessionControlSettings, ItemSessionState, } from './ItemSessionController.js';
3
+ export { ItemSessionController } from './ItemSessionController.js';
4
+ export type { NavigationMode } from './NavigationManager.js';
5
+ export { NavigationManager } from './NavigationManager.js';
6
+ export type { PersistableState, PersistenceConfig, } from './StatePersistenceManager.js';
7
+ export { StatePersistenceManager } from './StatePersistenceManager.js';
8
+ export type { TimeManagerConfig, TimeTrackingState } from './TimeManager.js';
9
+ export { TimeManager } from './TimeManager.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACX,0BAA0B,EAC1B,gBAAgB,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACX,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { AssessmentPlayer } from './AssessmentPlayer.js';
2
+ export { ItemSessionController } from './ItemSessionController.js';
3
+ export { NavigationManager } from './NavigationManager.js';
4
+ export { StatePersistenceManager } from './StatePersistenceManager.js';
5
+ export { TimeManager } from './TimeManager.js';
@@ -0,0 +1,6 @@
1
+ export type { BackendAssessmentPlayerConfig } from './core/AssessmentPlayer.js';
2
+ export type { NavigationMode } from './core/index.js';
3
+ export { AssessmentPlayer, NavigationManager } from './core/index.js';
4
+ export * from './integration/index.js';
5
+ export type { AssessmentResults, ItemResult, NavigationState, QTIRole, QuestionRef } from './types/index.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAChF,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,cAAc,wBAAwB,CAAC;AAEvC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Core classes
2
+ export { AssessmentPlayer, NavigationManager } from './core/index.js';
3
+ // Backend integration API + reference adapter
4
+ export * from './integration/index.js';
5
+ // Components are exported via package.json "exports" field
6
+ // Users can import them like:
7
+ // import AssessmentShell from '@pie-qti/assessment-player/components/AssessmentShell.svelte';