@pie-qti/assessment-player 0.1.10 → 0.1.11
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.
- package/README.md +22 -82
- package/dist/core/AssessmentPlayer.d.ts +0 -1
- package/dist/core/AssessmentPlayer.js +1 -0
- package/dist/core/AssessmentPlayer.js.map +1 -0
- package/dist/core/AssessmentSessionCoordinator.d.ts +0 -1
- package/dist/core/AssessmentSessionCoordinator.js +1 -0
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +0 -1
- package/dist/core/ItemSessionController.js +1 -0
- package/dist/core/ItemSessionController.js.map +1 -0
- package/dist/core/NavigationManager.d.ts +0 -1
- package/dist/core/NavigationManager.js +1 -0
- package/dist/core/NavigationManager.js.map +1 -0
- package/dist/core/StatePersistenceManager.d.ts +0 -1
- package/dist/core/StatePersistenceManager.js +1 -0
- package/dist/core/StatePersistenceManager.js.map +1 -0
- package/dist/core/TimeManager.d.ts +0 -1
- package/dist/core/TimeManager.js +1 -0
- package/dist/core/TimeManager.js.map +1 -0
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -0
- package/dist/integration/ReferenceBackendAdapter.d.ts +0 -1
- package/dist/integration/ReferenceBackendAdapter.js +1 -0
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -0
- package/dist/integration/api-contract.d.ts +0 -1
- package/dist/integration/api-contract.js +1 -0
- package/dist/integration/api-contract.js.map +1 -0
- package/dist/integration/assessment-item-scorer.d.ts +0 -1
- package/dist/integration/assessment-item-scorer.js +1 -0
- package/dist/integration/assessment-item-scorer.js.map +1 -0
- package/dist/integration/index.d.ts +0 -1
- package/dist/integration/index.js +1 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/PerformanceMonitor.d.ts +0 -1
- package/dist/utils/PerformanceMonitor.js +1 -0
- package/dist/utils/PerformanceMonitor.js.map +1 -0
- package/package.json +8 -37
- package/dist/core/AssessmentPlayer.d.ts.map +0 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts.map +0 -1
- package/dist/core/ItemSessionController.d.ts.map +0 -1
- package/dist/core/NavigationManager.d.ts.map +0 -1
- package/dist/core/StatePersistenceManager.d.ts.map +0 -1
- package/dist/core/TimeManager.d.ts.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +0 -1
- package/dist/integration/api-contract.d.ts.map +0 -1
- package/dist/integration/assessment-item-scorer.d.ts.map +0 -1
- package/dist/integration/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts.map +0 -1
- package/src/ambient.d.ts +0 -55
- package/src/components/AccessibilityAnnouncer.svelte +0 -113
- package/src/components/AssessmentHeader.svelte +0 -76
- package/src/components/AssessmentShell.svelte +0 -468
- package/src/components/AssessmentTimer.svelte +0 -251
- package/src/components/ItemRenderer.svelte +0 -156
- package/src/components/ItemSessionInfo.svelte +0 -241
- package/src/components/NavigationBar.svelte +0 -146
- package/src/components/RubricDisplay.svelte +0 -185
- package/src/components/SectionMenu.svelte +0 -273
- package/src/components/SplitPaneResizer.svelte +0 -288
- package/src/components/TestFeedback.svelte +0 -147
- package/src/components/index.ts +0 -19
- package/src/core/AssessmentPlayer.ts +0 -952
- package/src/core/AssessmentSessionCoordinator.ts +0 -274
- package/src/core/ItemSessionController.ts +0 -287
- package/src/core/NavigationManager.ts +0 -126
- package/src/core/StatePersistenceManager.ts +0 -344
- package/src/core/TimeManager.ts +0 -306
- package/src/core/index.ts +0 -15
- package/src/index.ts +0 -13
- package/src/integration/ReferenceBackendAdapter.ts +0 -1382
- package/src/integration/api-contract.ts +0 -480
- package/src/integration/assessment-item-scorer.ts +0 -58
- package/src/integration/index.ts +0 -77
- package/src/svelte-shims.d.ts +0 -7
- package/src/types/index.ts +0 -59
- package/src/utils/PerformanceMonitor.ts +0 -222
|
@@ -1,344 +0,0 @@
|
|
|
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
|
-
|
|
15
|
-
export interface PersistableState {
|
|
16
|
-
/** Assessment identifier */
|
|
17
|
-
assessmentId: string;
|
|
18
|
-
/** Current item index */
|
|
19
|
-
currentItemIndex: number;
|
|
20
|
-
/** Visited item indices */
|
|
21
|
-
visitedItems: number[];
|
|
22
|
-
/** Response data per item */
|
|
23
|
-
responses: Record<string, unknown>;
|
|
24
|
-
/** Item session states (attempts, submission status) */
|
|
25
|
-
itemSessionStates: Record<string, {
|
|
26
|
-
attemptCount: number;
|
|
27
|
-
isAnswered: boolean;
|
|
28
|
-
isSubmitted: boolean;
|
|
29
|
-
lastSubmissionTime?: number;
|
|
30
|
-
}>;
|
|
31
|
-
/** Time tracking data */
|
|
32
|
-
timeTracking?: {
|
|
33
|
-
startedAt: number;
|
|
34
|
-
totalElapsed: number;
|
|
35
|
-
itemTimes: Record<string, number>;
|
|
36
|
-
sectionTimes: Record<string, number>;
|
|
37
|
-
};
|
|
38
|
-
/** Last saved timestamp */
|
|
39
|
-
savedAt: number;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface PersistenceConfig {
|
|
43
|
-
/** Unique session identifier */
|
|
44
|
-
sessionId: string;
|
|
45
|
-
/** Assessment identifier */
|
|
46
|
-
assessmentId: string;
|
|
47
|
-
/** Auto-save enabled (default: true) */
|
|
48
|
-
autoSave?: boolean;
|
|
49
|
-
/** Auto-save debounce delay in ms (default: 2000) */
|
|
50
|
-
autoSaveDelay?: number;
|
|
51
|
-
/** Storage strategy */
|
|
52
|
-
storage?: 'localStorage' | 'sessionStorage' | 'memory';
|
|
53
|
-
/** Optional backend save callback */
|
|
54
|
-
onBackendSave?: (state: PersistableState) => Promise<void>;
|
|
55
|
-
/** Optional save success callback */
|
|
56
|
-
onSaveSuccess?: (state: PersistableState) => void;
|
|
57
|
-
/** Optional save error callback */
|
|
58
|
-
onSaveError?: (error: Error) => void;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class StatePersistenceManager {
|
|
62
|
-
private config: PersistenceConfig;
|
|
63
|
-
private currentState: PersistableState | null = null;
|
|
64
|
-
private autoSaveTimer: ReturnType<typeof setTimeout> | null = null;
|
|
65
|
-
private isSaving = false;
|
|
66
|
-
private memoryStorage: Map<string, string> = new Map();
|
|
67
|
-
|
|
68
|
-
constructor(config: PersistenceConfig) {
|
|
69
|
-
this.config = {
|
|
70
|
-
autoSave: true,
|
|
71
|
-
autoSaveDelay: 2000,
|
|
72
|
-
storage: 'localStorage',
|
|
73
|
-
...config,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Update state and trigger auto-save
|
|
79
|
-
*/
|
|
80
|
-
updateState(state: Partial<PersistableState>): void {
|
|
81
|
-
// Merge with existing state
|
|
82
|
-
this.currentState = {
|
|
83
|
-
...this.currentState,
|
|
84
|
-
assessmentId: this.config.assessmentId,
|
|
85
|
-
savedAt: Date.now(),
|
|
86
|
-
...state,
|
|
87
|
-
} as PersistableState;
|
|
88
|
-
|
|
89
|
-
// Trigger auto-save
|
|
90
|
-
if (this.config.autoSave) {
|
|
91
|
-
this.scheduleAutoSave();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Schedule auto-save with debouncing
|
|
97
|
-
*/
|
|
98
|
-
private scheduleAutoSave(): void {
|
|
99
|
-
// Clear existing timer
|
|
100
|
-
if (this.autoSaveTimer) {
|
|
101
|
-
clearTimeout(this.autoSaveTimer);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Schedule new save
|
|
105
|
-
this.autoSaveTimer = setTimeout(() => {
|
|
106
|
-
this.save().catch((error) => {
|
|
107
|
-
console.error('[StatePersistenceManager] Auto-save failed:', error);
|
|
108
|
-
this.config.onSaveError?.(error);
|
|
109
|
-
});
|
|
110
|
-
}, this.config.autoSaveDelay);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Manually save current state
|
|
115
|
-
*/
|
|
116
|
-
async save(): Promise<void> {
|
|
117
|
-
if (!this.currentState) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (this.isSaving) {
|
|
122
|
-
console.warn('[StatePersistenceManager] Save already in progress');
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.isSaving = true;
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
// Update timestamp
|
|
130
|
-
this.currentState.savedAt = Date.now();
|
|
131
|
-
|
|
132
|
-
// Try backend save first (if configured)
|
|
133
|
-
if (this.config.onBackendSave) {
|
|
134
|
-
try {
|
|
135
|
-
await this.config.onBackendSave(this.currentState);
|
|
136
|
-
} catch (backendError) {
|
|
137
|
-
console.warn('[StatePersistenceManager] Backend save failed, falling back to local:', backendError);
|
|
138
|
-
// Continue to local save as fallback
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Save to local storage
|
|
143
|
-
this.saveToStorage(this.currentState);
|
|
144
|
-
|
|
145
|
-
// Success callback
|
|
146
|
-
this.config.onSaveSuccess?.(this.currentState);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.error('[StatePersistenceManager] Save failed:', error);
|
|
149
|
-
this.config.onSaveError?.(error as Error);
|
|
150
|
-
throw error;
|
|
151
|
-
} finally {
|
|
152
|
-
this.isSaving = false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Save to configured storage
|
|
158
|
-
*/
|
|
159
|
-
private saveToStorage(state: PersistableState): void {
|
|
160
|
-
const key = this.getStorageKey();
|
|
161
|
-
const data = JSON.stringify(state);
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
switch (this.config.storage) {
|
|
165
|
-
case 'localStorage':
|
|
166
|
-
if (typeof localStorage !== 'undefined') {
|
|
167
|
-
localStorage.setItem(key, data);
|
|
168
|
-
} else {
|
|
169
|
-
this.memoryStorage.set(key, data);
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'sessionStorage':
|
|
174
|
-
if (typeof sessionStorage !== 'undefined') {
|
|
175
|
-
sessionStorage.setItem(key, data);
|
|
176
|
-
} else {
|
|
177
|
-
this.memoryStorage.set(key, data);
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
|
|
181
|
-
case 'memory':
|
|
182
|
-
this.memoryStorage.set(key, data);
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
} catch (error) {
|
|
186
|
-
// Storage quota exceeded or other storage error
|
|
187
|
-
console.error('[StatePersistenceManager] Storage save failed:', error);
|
|
188
|
-
// Fallback to memory storage
|
|
189
|
-
this.memoryStorage.set(key, data);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Load state from storage
|
|
195
|
-
*/
|
|
196
|
-
async load(): Promise<PersistableState | null> {
|
|
197
|
-
const key = this.getStorageKey();
|
|
198
|
-
let data: string | null = null;
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
switch (this.config.storage) {
|
|
202
|
-
case 'localStorage':
|
|
203
|
-
data = typeof localStorage !== 'undefined'
|
|
204
|
-
? localStorage.getItem(key)
|
|
205
|
-
: this.memoryStorage.get(key) || null;
|
|
206
|
-
break;
|
|
207
|
-
|
|
208
|
-
case 'sessionStorage':
|
|
209
|
-
data = typeof sessionStorage !== 'undefined'
|
|
210
|
-
? sessionStorage.getItem(key)
|
|
211
|
-
: this.memoryStorage.get(key) || null;
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case 'memory':
|
|
215
|
-
data = this.memoryStorage.get(key) || null;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (!data) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const state = JSON.parse(data) as PersistableState;
|
|
224
|
-
this.currentState = state;
|
|
225
|
-
return state;
|
|
226
|
-
} catch (error) {
|
|
227
|
-
console.error('[StatePersistenceManager] Failed to load state:', error);
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Check if saved state exists
|
|
234
|
-
*/
|
|
235
|
-
async hasSavedState(): Promise<boolean> {
|
|
236
|
-
const state = await this.load();
|
|
237
|
-
return state !== null;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Clear saved state
|
|
242
|
-
*/
|
|
243
|
-
async clear(): Promise<void> {
|
|
244
|
-
const key = this.getStorageKey();
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
switch (this.config.storage) {
|
|
248
|
-
case 'localStorage':
|
|
249
|
-
if (typeof localStorage !== 'undefined') {
|
|
250
|
-
localStorage.removeItem(key);
|
|
251
|
-
}
|
|
252
|
-
this.memoryStorage.delete(key);
|
|
253
|
-
break;
|
|
254
|
-
|
|
255
|
-
case 'sessionStorage':
|
|
256
|
-
if (typeof sessionStorage !== 'undefined') {
|
|
257
|
-
sessionStorage.removeItem(key);
|
|
258
|
-
}
|
|
259
|
-
this.memoryStorage.delete(key);
|
|
260
|
-
break;
|
|
261
|
-
|
|
262
|
-
case 'memory':
|
|
263
|
-
this.memoryStorage.delete(key);
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
this.currentState = null;
|
|
268
|
-
} catch (error) {
|
|
269
|
-
console.error('[StatePersistenceManager] Failed to clear state:', error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Get current state without saving
|
|
275
|
-
*/
|
|
276
|
-
getCurrentState(): PersistableState | null {
|
|
277
|
-
return this.currentState ? { ...this.currentState } : null;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Get storage key for this session
|
|
282
|
-
*/
|
|
283
|
-
private getStorageKey(): string {
|
|
284
|
-
return `qti-assessment-${this.config.assessmentId}-${this.config.sessionId}`;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Force immediate save (bypasses debounce)
|
|
289
|
-
*/
|
|
290
|
-
async forceSave(): Promise<void> {
|
|
291
|
-
// Clear any pending auto-save
|
|
292
|
-
if (this.autoSaveTimer) {
|
|
293
|
-
clearTimeout(this.autoSaveTimer);
|
|
294
|
-
this.autoSaveTimer = null;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
await this.save();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Pause auto-save (useful during navigation transitions)
|
|
302
|
-
*/
|
|
303
|
-
pauseAutoSave(): void {
|
|
304
|
-
if (this.autoSaveTimer) {
|
|
305
|
-
clearTimeout(this.autoSaveTimer);
|
|
306
|
-
this.autoSaveTimer = null;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Resume auto-save
|
|
312
|
-
*/
|
|
313
|
-
resumeAutoSave(): void {
|
|
314
|
-
if (this.config.autoSave && this.currentState) {
|
|
315
|
-
this.scheduleAutoSave();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Get last save timestamp
|
|
321
|
-
*/
|
|
322
|
-
getLastSaveTime(): number | null {
|
|
323
|
-
return this.currentState?.savedAt || null;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Check if state has been modified since last save
|
|
328
|
-
*/
|
|
329
|
-
isDirty(): boolean {
|
|
330
|
-
// Simple check - could be enhanced with deep comparison
|
|
331
|
-
return this.autoSaveTimer !== null;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Cleanup
|
|
336
|
-
*/
|
|
337
|
-
destroy(): void {
|
|
338
|
-
if (this.autoSaveTimer) {
|
|
339
|
-
clearTimeout(this.autoSaveTimer);
|
|
340
|
-
this.autoSaveTimer = null;
|
|
341
|
-
}
|
|
342
|
-
this.currentState = null;
|
|
343
|
-
}
|
|
344
|
-
}
|
package/src/core/TimeManager.ts
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
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
|
-
|
|
15
|
-
import type { TimeLimits } from '../types/index.js';
|
|
16
|
-
|
|
17
|
-
export interface TimeManagerConfig {
|
|
18
|
-
/** Assessment-level time limits */
|
|
19
|
-
assessmentTimeLimits?: TimeLimits;
|
|
20
|
-
/** Warning threshold (seconds before expiry) */
|
|
21
|
-
warningThreshold?: number;
|
|
22
|
-
/** Callback when time warning is triggered */
|
|
23
|
-
onWarning?: (remainingSeconds: number) => void;
|
|
24
|
-
/** Callback when time expires */
|
|
25
|
-
onExpired?: () => void;
|
|
26
|
-
/** Callback for time updates (fires every second) */
|
|
27
|
-
onTick?: (remainingSeconds: number, elapsedSeconds: number) => void;
|
|
28
|
-
/**
|
|
29
|
-
* QTI 3.0 PNP extended time accommodation.
|
|
30
|
-
* When active, multiplies assessmentTimeLimits.maxTime by the given multiplier.
|
|
31
|
-
* multiplier: Infinity removes the time limit entirely.
|
|
32
|
-
*/
|
|
33
|
-
extendedTime?: { active: boolean; multiplier: number };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface TimeTrackingState {
|
|
37
|
-
/** Total elapsed time (ms) */
|
|
38
|
-
totalElapsed: number;
|
|
39
|
-
/** Time spent per item identifier (ms) */
|
|
40
|
-
itemTimes: Record<string, number>;
|
|
41
|
-
/** Time spent per section identifier (ms) */
|
|
42
|
-
sectionTimes: Record<string, number>;
|
|
43
|
-
/** Session start timestamp */
|
|
44
|
-
startedAt: number;
|
|
45
|
-
/** Current item start time (for tracking) */
|
|
46
|
-
currentItemStartTime?: number;
|
|
47
|
-
/** Current section identifier */
|
|
48
|
-
currentSectionId?: string;
|
|
49
|
-
/** Is timer currently paused */
|
|
50
|
-
isPaused: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class TimeManager {
|
|
54
|
-
private config: TimeManagerConfig;
|
|
55
|
-
private state: TimeTrackingState;
|
|
56
|
-
|
|
57
|
-
// Timer internals
|
|
58
|
-
private intervalId: ReturnType<typeof setInterval> | null = null;
|
|
59
|
-
private maxTimeSeconds: number | null = null;
|
|
60
|
-
private warningTriggered = false;
|
|
61
|
-
|
|
62
|
-
constructor(config: TimeManagerConfig) {
|
|
63
|
-
this.config = config;
|
|
64
|
-
this.state = {
|
|
65
|
-
totalElapsed: 0,
|
|
66
|
-
itemTimes: {},
|
|
67
|
-
sectionTimes: {},
|
|
68
|
-
startedAt: Date.now(),
|
|
69
|
-
isPaused: false,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.
|
|
73
|
-
if (config.assessmentTimeLimits?.maxTime) {
|
|
74
|
-
const base = config.assessmentTimeLimits.maxTime;
|
|
75
|
-
const et = config.extendedTime;
|
|
76
|
-
if (et?.active && et.multiplier === Infinity) {
|
|
77
|
-
// multiplier: Infinity → unlimited time (no countdown)
|
|
78
|
-
this.maxTimeSeconds = null;
|
|
79
|
-
} else if (et?.active && et.multiplier > 0) {
|
|
80
|
-
this.maxTimeSeconds = base * et.multiplier;
|
|
81
|
-
} else {
|
|
82
|
-
this.maxTimeSeconds = base;
|
|
83
|
-
}
|
|
84
|
-
if (this.maxTimeSeconds !== null) {
|
|
85
|
-
this.startTimer();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Start or resume the timer
|
|
92
|
-
*/
|
|
93
|
-
private startTimer(): void {
|
|
94
|
-
if (this.intervalId) {
|
|
95
|
-
return; // Already running
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.state.isPaused = false;
|
|
99
|
-
|
|
100
|
-
this.intervalId = setInterval(() => {
|
|
101
|
-
if (this.state.isPaused) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.state.totalElapsed += 1000; // Increment by 1 second
|
|
106
|
-
|
|
107
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
108
|
-
|
|
109
|
-
// Track item time if active
|
|
110
|
-
if (this.state.currentItemStartTime) {
|
|
111
|
-
// Item tracking handled by startItem/endItem
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Calculate remaining time
|
|
115
|
-
if (this.maxTimeSeconds) {
|
|
116
|
-
const remainingSeconds = this.maxTimeSeconds - elapsedSeconds;
|
|
117
|
-
|
|
118
|
-
// Trigger warning
|
|
119
|
-
const warningThreshold = this.config.warningThreshold || 60;
|
|
120
|
-
if (!this.warningTriggered && remainingSeconds <= warningThreshold && remainingSeconds > 0) {
|
|
121
|
-
this.warningTriggered = true;
|
|
122
|
-
this.config.onWarning?.(remainingSeconds);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Trigger expiration
|
|
126
|
-
if (remainingSeconds <= 0) {
|
|
127
|
-
this.handleExpiration();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Tick callback
|
|
132
|
-
this.config.onTick?.(remainingSeconds, elapsedSeconds);
|
|
133
|
-
} else {
|
|
134
|
-
// No limit - just count up
|
|
135
|
-
this.config.onTick?.(0, elapsedSeconds);
|
|
136
|
-
}
|
|
137
|
-
}, 1000);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Handle time expiration
|
|
142
|
-
*/
|
|
143
|
-
private handleExpiration(): void {
|
|
144
|
-
this.stopTimer();
|
|
145
|
-
this.config.onExpired?.();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Stop the timer
|
|
150
|
-
*/
|
|
151
|
-
stopTimer(): void {
|
|
152
|
-
if (this.intervalId) {
|
|
153
|
-
clearInterval(this.intervalId);
|
|
154
|
-
this.intervalId = null;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Pause the timer
|
|
160
|
-
*/
|
|
161
|
-
pause(): void {
|
|
162
|
-
this.state.isPaused = true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Resume the timer
|
|
167
|
-
*/
|
|
168
|
-
resume(): void {
|
|
169
|
-
this.state.isPaused = false;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Start tracking time for an item
|
|
174
|
-
*/
|
|
175
|
-
startItem(_itemIdentifier: string): void {
|
|
176
|
-
// End previous item if any
|
|
177
|
-
if (this.state.currentItemStartTime) {
|
|
178
|
-
this.endCurrentItem();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this.state.currentItemStartTime = Date.now();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* End tracking time for current item
|
|
186
|
-
*/
|
|
187
|
-
private endCurrentItem(): void {
|
|
188
|
-
if (!this.state.currentItemStartTime) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const timeSpent = Date.now() - this.state.currentItemStartTime;
|
|
193
|
-
// Note: We need the item identifier, which should be tracked separately
|
|
194
|
-
// For now, we'll handle this in the endItem method
|
|
195
|
-
this.state.currentItemStartTime = undefined;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* End tracking time for an item
|
|
200
|
-
*/
|
|
201
|
-
endItem(itemIdentifier: string): void {
|
|
202
|
-
if (!this.state.currentItemStartTime) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const timeSpent = Date.now() - this.state.currentItemStartTime;
|
|
207
|
-
this.state.itemTimes[itemIdentifier] = (this.state.itemTimes[itemIdentifier] || 0) + timeSpent;
|
|
208
|
-
this.state.currentItemStartTime = undefined;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Start tracking time for a section
|
|
213
|
-
*/
|
|
214
|
-
startSection(sectionIdentifier: string): void {
|
|
215
|
-
this.state.currentSectionId = sectionIdentifier;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Get remaining time in seconds (null if no limit)
|
|
220
|
-
*/
|
|
221
|
-
getRemainingSeconds(): number | null {
|
|
222
|
-
if (!this.maxTimeSeconds) {
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
227
|
-
return Math.max(0, this.maxTimeSeconds - elapsedSeconds);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Get elapsed time in seconds
|
|
232
|
-
*/
|
|
233
|
-
getElapsedSeconds(): number {
|
|
234
|
-
return Math.floor(this.state.totalElapsed / 1000);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Get time spent on a specific item (ms)
|
|
239
|
-
*/
|
|
240
|
-
getItemTime(itemIdentifier: string): number {
|
|
241
|
-
return this.state.itemTimes[itemIdentifier] || 0;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Get current tracking state (for persistence)
|
|
246
|
-
*/
|
|
247
|
-
getState(): TimeTrackingState {
|
|
248
|
-
return { ...this.state };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Restore tracking state (for resume)
|
|
253
|
-
*/
|
|
254
|
-
restoreState(state: TimeTrackingState): void {
|
|
255
|
-
this.state = { ...state };
|
|
256
|
-
|
|
257
|
-
// Restart timer if not expired
|
|
258
|
-
if (this.maxTimeSeconds) {
|
|
259
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
260
|
-
if (elapsedSeconds < this.maxTimeSeconds) {
|
|
261
|
-
this.startTimer();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Check if time has expired
|
|
268
|
-
*/
|
|
269
|
-
isExpired(): boolean {
|
|
270
|
-
if (!this.maxTimeSeconds) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);
|
|
275
|
-
return elapsedSeconds >= this.maxTimeSeconds;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Check if late submission is allowed
|
|
280
|
-
*/
|
|
281
|
-
allowsLateSubmission(): boolean {
|
|
282
|
-
return this.config.assessmentTimeLimits?.allowLateSubmission || false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Format time as MM:SS or HH:MM:SS
|
|
287
|
-
*/
|
|
288
|
-
static formatTime(seconds: number): string {
|
|
289
|
-
const hours = Math.floor(seconds / 3600);
|
|
290
|
-
const minutes = Math.floor((seconds % 3600) / 60);
|
|
291
|
-
const secs = seconds % 60;
|
|
292
|
-
|
|
293
|
-
if (hours > 0) {
|
|
294
|
-
return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return `${minutes}:${secs.toString().padStart(2, '0')}`;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Cleanup - stop all timers
|
|
302
|
-
*/
|
|
303
|
-
destroy(): void {
|
|
304
|
-
this.stopTimer();
|
|
305
|
-
}
|
|
306
|
-
}
|
package/src/core/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { AssessmentPlayer } from './AssessmentPlayer.js';
|
|
2
|
-
export type {
|
|
3
|
-
ItemSessionControlSettings,
|
|
4
|
-
ItemSessionState,
|
|
5
|
-
} from './ItemSessionController.js';
|
|
6
|
-
export { ItemSessionController } from './ItemSessionController.js';
|
|
7
|
-
export type { NavigationMode } from './NavigationManager.js';
|
|
8
|
-
export { NavigationManager } from './NavigationManager.js';
|
|
9
|
-
export type {
|
|
10
|
-
PersistableState,
|
|
11
|
-
PersistenceConfig,
|
|
12
|
-
} from './StatePersistenceManager.js';
|
|
13
|
-
export { StatePersistenceManager } from './StatePersistenceManager.js';
|
|
14
|
-
export type { TimeManagerConfig, TimeTrackingState } from './TimeManager.js';
|
|
15
|
-
export { TimeManager } from './TimeManager.js';
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Core classes
|
|
2
|
-
|
|
3
|
-
export type { BackendAssessmentPlayerConfig } from './core/AssessmentPlayer.js';
|
|
4
|
-
export type { NavigationMode } from './core/index.js';
|
|
5
|
-
export { AssessmentPlayer, NavigationManager } from './core/index.js';
|
|
6
|
-
// Backend integration API + reference adapter
|
|
7
|
-
export * from './integration/index.js';
|
|
8
|
-
// Public UI/data types
|
|
9
|
-
export type { AssessmentResults, ItemRef, ItemResult, NavigationState, QTIRole } from './types/index.js';
|
|
10
|
-
|
|
11
|
-
// Components are exported via package.json "exports" field
|
|
12
|
-
// Users can import them like:
|
|
13
|
-
// import AssessmentShell from '@pie-qti/assessment-player/components/AssessmentShell.svelte';
|