@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,119 @@
1
+ /**
2
+ * ItemSessionController
3
+ *
4
+ * Manages QTI itemSessionControl rules for individual items.
5
+ * Enforces attempt limits, feedback visibility, review/skip controls, and validation.
6
+ *
7
+ * QTI 2.2 itemSessionControl attributes:
8
+ * - maxAttempts: Maximum number of submission attempts (0 = unlimited)
9
+ * - showFeedback: Whether to show feedback after responses
10
+ * - showSolution: Whether to show correct answers
11
+ * - allowReview: Allow returning to already-answered items
12
+ * - allowSkipping: Allow skipping items without answering
13
+ * - validateResponses: Require valid responses before moving on
14
+ * - allowComment: Allow candidate comments (not implemented yet)
15
+ */
16
+ export interface ItemSessionControlSettings {
17
+ maxAttempts?: number;
18
+ showFeedback?: boolean;
19
+ allowReview?: boolean;
20
+ showSolution?: boolean;
21
+ allowComment?: boolean;
22
+ allowSkipping?: boolean;
23
+ validateResponses?: boolean;
24
+ }
25
+ export interface ItemSessionState {
26
+ itemIdentifier: string;
27
+ attemptCount: number;
28
+ isAnswered: boolean;
29
+ isSubmitted: boolean;
30
+ lastSubmissionTime?: number;
31
+ }
32
+ export declare class ItemSessionController {
33
+ private settings;
34
+ private sessionStates;
35
+ constructor(settings?: ItemSessionControlSettings);
36
+ /**
37
+ * Initialize session state for an item
38
+ */
39
+ initializeItem(itemIdentifier: string): void;
40
+ /**
41
+ * Get session state for an item
42
+ */
43
+ getItemState(itemIdentifier: string): ItemSessionState | null;
44
+ /**
45
+ * Record a submission attempt for an item
46
+ */
47
+ recordAttempt(itemIdentifier: string): void;
48
+ /**
49
+ * Mark item as answered (has responses)
50
+ */
51
+ markAnswered(itemIdentifier: string, hasResponses: boolean): void;
52
+ /**
53
+ * Check if item can be submitted
54
+ */
55
+ canSubmit(itemIdentifier: string): boolean;
56
+ /**
57
+ * Get remaining attempts for an item
58
+ */
59
+ getRemainingAttempts(itemIdentifier: string): number | null;
60
+ /**
61
+ * Check if feedback should be shown for an item
62
+ */
63
+ shouldShowFeedback(itemIdentifier: string): boolean;
64
+ /**
65
+ * Check if solution should be shown for an item
66
+ */
67
+ shouldShowSolution(itemIdentifier: string): boolean;
68
+ /**
69
+ * Check if candidate can navigate to a previously answered item
70
+ */
71
+ canReview(itemIdentifier: string): boolean;
72
+ /**
73
+ * Check if candidate can skip an item without answering
74
+ */
75
+ canSkip(_itemIdentifier: string): boolean;
76
+ /**
77
+ * Check if responses must be validated before navigation
78
+ */
79
+ mustValidateResponses(): boolean;
80
+ /**
81
+ * Validate that an item has valid responses (if validation is required)
82
+ */
83
+ validateItem(itemIdentifier: string, hasValidResponses: boolean): {
84
+ isValid: boolean;
85
+ error?: string;
86
+ };
87
+ /**
88
+ * Check if navigation away from current item is allowed
89
+ */
90
+ canNavigateAway(itemIdentifier: string, hasValidResponses: boolean): {
91
+ allowed: boolean;
92
+ reason?: string;
93
+ };
94
+ /**
95
+ * Get full settings
96
+ */
97
+ getSettings(): ItemSessionControlSettings;
98
+ /**
99
+ * Update settings (useful for different sections with different controls)
100
+ */
101
+ updateSettings(settings: Partial<ItemSessionControlSettings>): void;
102
+ /**
103
+ * Get all session states (for persistence)
104
+ */
105
+ getAllStates(): Map<string, ItemSessionState>;
106
+ /**
107
+ * Restore session states (from persistence)
108
+ */
109
+ restoreStates(states: Map<string, ItemSessionState>): void;
110
+ /**
111
+ * Reset session state for an item (useful for practice/retry scenarios)
112
+ */
113
+ resetItem(itemIdentifier: string): void;
114
+ /**
115
+ * Clear all session states
116
+ */
117
+ clear(): void;
118
+ }
119
+ //# sourceMappingURL=ItemSessionController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ItemSessionController.d.ts","sourceRoot":"","sources":["../../src/core/ItemSessionController.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,0BAA0B;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WA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G;QACpE,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB;IAyBD;;OAEG;IACH,WAAW,IAAI,0BAA0B;IAIzC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAAG,IAAI;IAInE;;OAEG;IACH,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAI7C;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,IAAI;IAI1D;;OAEG;IACH,SAAS,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAUvC;;OAEG;IACH,KAAK,IAAI,IAAI;CAGb"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * ItemSessionController
3
+ *
4
+ * Manages QTI itemSessionControl rules for individual items.
5
+ * Enforces attempt limits, feedback visibility, review/skip controls, and validation.
6
+ *
7
+ * QTI 2.2 itemSessionControl attributes:
8
+ * - maxAttempts: Maximum number of submission attempts (0 = unlimited)
9
+ * - showFeedback: Whether to show feedback after responses
10
+ * - showSolution: Whether to show correct answers
11
+ * - allowReview: Allow returning to already-answered items
12
+ * - allowSkipping: Allow skipping items without answering
13
+ * - validateResponses: Require valid responses before moving on
14
+ * - allowComment: Allow candidate comments (not implemented yet)
15
+ */
16
+ export class ItemSessionController {
17
+ constructor(settings = {}) {
18
+ this.sessionStates = new Map();
19
+ // Apply defaults per QTI 2.2 spec
20
+ this.settings = {
21
+ maxAttempts: settings.maxAttempts ?? 0, // 0 = unlimited
22
+ showFeedback: settings.showFeedback ?? false,
23
+ allowReview: settings.allowReview ?? true,
24
+ showSolution: settings.showSolution ?? false,
25
+ allowComment: settings.allowComment ?? false,
26
+ allowSkipping: settings.allowSkipping ?? true,
27
+ validateResponses: settings.validateResponses ?? false,
28
+ };
29
+ }
30
+ /**
31
+ * Initialize session state for an item
32
+ */
33
+ initializeItem(itemIdentifier) {
34
+ if (!this.sessionStates.has(itemIdentifier)) {
35
+ this.sessionStates.set(itemIdentifier, {
36
+ itemIdentifier,
37
+ attemptCount: 0,
38
+ isAnswered: false,
39
+ isSubmitted: false,
40
+ });
41
+ }
42
+ }
43
+ /**
44
+ * Get session state for an item
45
+ */
46
+ getItemState(itemIdentifier) {
47
+ return this.sessionStates.get(itemIdentifier) ?? null;
48
+ }
49
+ /**
50
+ * Record a submission attempt for an item
51
+ */
52
+ recordAttempt(itemIdentifier) {
53
+ const state = this.sessionStates.get(itemIdentifier);
54
+ if (!state) {
55
+ throw new Error(`Item session not initialized: ${itemIdentifier}`);
56
+ }
57
+ state.attemptCount++;
58
+ state.isSubmitted = true;
59
+ state.lastSubmissionTime = Date.now();
60
+ }
61
+ /**
62
+ * Mark item as answered (has responses)
63
+ */
64
+ markAnswered(itemIdentifier, hasResponses) {
65
+ const state = this.sessionStates.get(itemIdentifier);
66
+ if (state) {
67
+ state.isAnswered = hasResponses;
68
+ }
69
+ }
70
+ /**
71
+ * Check if item can be submitted
72
+ */
73
+ canSubmit(itemIdentifier) {
74
+ const state = this.sessionStates.get(itemIdentifier);
75
+ if (!state) {
76
+ return false;
77
+ }
78
+ // Check maxAttempts
79
+ const maxAttempts = this.settings.maxAttempts ?? 0;
80
+ if (maxAttempts > 0 && state.attemptCount >= maxAttempts) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ /**
86
+ * Get remaining attempts for an item
87
+ */
88
+ getRemainingAttempts(itemIdentifier) {
89
+ const state = this.sessionStates.get(itemIdentifier);
90
+ if (!state) {
91
+ return null;
92
+ }
93
+ const maxAttempts = this.settings.maxAttempts ?? 0;
94
+ if (maxAttempts === 0) {
95
+ return null; // Unlimited
96
+ }
97
+ return Math.max(0, maxAttempts - state.attemptCount);
98
+ }
99
+ /**
100
+ * Check if feedback should be shown for an item
101
+ */
102
+ shouldShowFeedback(itemIdentifier) {
103
+ const state = this.sessionStates.get(itemIdentifier);
104
+ if (!state || !state.isSubmitted) {
105
+ return false;
106
+ }
107
+ return this.settings.showFeedback ?? false;
108
+ }
109
+ /**
110
+ * Check if solution should be shown for an item
111
+ */
112
+ shouldShowSolution(itemIdentifier) {
113
+ const state = this.sessionStates.get(itemIdentifier);
114
+ if (!state || !state.isSubmitted) {
115
+ return false;
116
+ }
117
+ return this.settings.showSolution ?? false;
118
+ }
119
+ /**
120
+ * Check if candidate can navigate to a previously answered item
121
+ */
122
+ canReview(itemIdentifier) {
123
+ const state = this.sessionStates.get(itemIdentifier);
124
+ if (!state || !state.isSubmitted) {
125
+ return true; // Can always navigate to unsubmitted items
126
+ }
127
+ return this.settings.allowReview ?? true;
128
+ }
129
+ /**
130
+ * Check if candidate can skip an item without answering
131
+ */
132
+ canSkip(_itemIdentifier) {
133
+ return this.settings.allowSkipping ?? true;
134
+ }
135
+ /**
136
+ * Check if responses must be validated before navigation
137
+ */
138
+ mustValidateResponses() {
139
+ return this.settings.validateResponses ?? false;
140
+ }
141
+ /**
142
+ * Validate that an item has valid responses (if validation is required)
143
+ */
144
+ validateItem(itemIdentifier, hasValidResponses) {
145
+ if (!this.mustValidateResponses()) {
146
+ return { isValid: true };
147
+ }
148
+ const state = this.sessionStates.get(itemIdentifier);
149
+ if (!state) {
150
+ return { isValid: true };
151
+ }
152
+ // If item is required and has no valid responses, fail validation
153
+ if (!hasValidResponses) {
154
+ return {
155
+ isValid: false,
156
+ error: 'This item requires a valid response before continuing.',
157
+ };
158
+ }
159
+ return { isValid: true };
160
+ }
161
+ /**
162
+ * Check if navigation away from current item is allowed
163
+ */
164
+ canNavigateAway(itemIdentifier, hasValidResponses) {
165
+ const state = this.sessionStates.get(itemIdentifier);
166
+ if (!state) {
167
+ return { allowed: true };
168
+ }
169
+ // Check if skipping is allowed when item is unanswered
170
+ if (!state.isAnswered && !this.canSkip(itemIdentifier)) {
171
+ return {
172
+ allowed: false,
173
+ reason: 'You must answer this item before continuing.',
174
+ };
175
+ }
176
+ // Check validation requirements
177
+ if (this.mustValidateResponses() && state.isAnswered && !hasValidResponses) {
178
+ return {
179
+ allowed: false,
180
+ reason: 'Please provide valid responses before continuing.',
181
+ };
182
+ }
183
+ return { allowed: true };
184
+ }
185
+ /**
186
+ * Get full settings
187
+ */
188
+ getSettings() {
189
+ return { ...this.settings };
190
+ }
191
+ /**
192
+ * Update settings (useful for different sections with different controls)
193
+ */
194
+ updateSettings(settings) {
195
+ this.settings = { ...this.settings, ...settings };
196
+ }
197
+ /**
198
+ * Get all session states (for persistence)
199
+ */
200
+ getAllStates() {
201
+ return new Map(this.sessionStates);
202
+ }
203
+ /**
204
+ * Restore session states (from persistence)
205
+ */
206
+ restoreStates(states) {
207
+ this.sessionStates = new Map(states);
208
+ }
209
+ /**
210
+ * Reset session state for an item (useful for practice/retry scenarios)
211
+ */
212
+ resetItem(itemIdentifier) {
213
+ const state = this.sessionStates.get(itemIdentifier);
214
+ if (state) {
215
+ state.attemptCount = 0;
216
+ state.isAnswered = false;
217
+ state.isSubmitted = false;
218
+ state.lastSubmissionTime = undefined;
219
+ }
220
+ }
221
+ /**
222
+ * Clear all session states
223
+ */
224
+ clear() {
225
+ this.sessionStates.clear();
226
+ }
227
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * NavigationManager
3
+ *
4
+ * Handles navigation logic for linear and nonlinear assessment modes.
5
+ * - Linear: Sequential navigation only (can go back, but can't skip forward)
6
+ * - Nonlinear: Free navigation (can jump to any item)
7
+ */
8
+ export type NavigationMode = 'linear' | 'nonlinear';
9
+ export declare class NavigationManager {
10
+ private mode;
11
+ private totalItems;
12
+ private visitedItems;
13
+ constructor(mode: NavigationMode, totalItems: number);
14
+ /**
15
+ * Check if navigation to a specific index is allowed
16
+ */
17
+ canNavigateTo(targetIndex: number, currentIndex: number): boolean;
18
+ /**
19
+ * Check if "next" navigation is allowed
20
+ */
21
+ canNext(currentIndex: number): boolean;
22
+ /**
23
+ * Check if "previous" navigation is allowed
24
+ */
25
+ canPrevious(currentIndex: number): boolean;
26
+ /**
27
+ * Get the next valid index
28
+ */
29
+ getNextIndex(currentIndex: number): number | null;
30
+ /**
31
+ * Get the previous valid index
32
+ */
33
+ getPreviousIndex(currentIndex: number): number | null;
34
+ /**
35
+ * Mark an item as visited
36
+ */
37
+ markVisited(index: number): void;
38
+ /**
39
+ * Check if an item has been visited
40
+ */
41
+ isVisited(index: number): boolean;
42
+ /**
43
+ * Get all visited item indices
44
+ */
45
+ getVisitedItems(): number[];
46
+ /**
47
+ * Get navigation mode
48
+ */
49
+ getMode(): NavigationMode;
50
+ /**
51
+ * Reset visited items (e.g., for retaking assessment)
52
+ */
53
+ reset(): void;
54
+ /**
55
+ * Restore state (for save/resume)
56
+ */
57
+ restoreState(visitedItems: number[]): void;
58
+ }
59
+ //# sourceMappingURL=NavigationManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavigationManager.d.ts","sourceRoot":"","sources":["../../src/core/NavigationManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEpD,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAc;gBAEtB,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM;IAMpD;;OAEG;IACH,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;IA0BjE;;OAEG;IACH,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAItC;;OAEG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAI1C;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOjD;;OAEG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOrD;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIhC;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,OAAO,IAAI,cAAc;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;CAG1C"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * NavigationManager
3
+ *
4
+ * Handles navigation logic for linear and nonlinear assessment modes.
5
+ * - Linear: Sequential navigation only (can go back, but can't skip forward)
6
+ * - Nonlinear: Free navigation (can jump to any item)
7
+ */
8
+ export class NavigationManager {
9
+ constructor(mode, totalItems) {
10
+ this.mode = mode;
11
+ this.totalItems = totalItems;
12
+ this.visitedItems = new Set();
13
+ }
14
+ /**
15
+ * Check if navigation to a specific index is allowed
16
+ */
17
+ canNavigateTo(targetIndex, currentIndex) {
18
+ // Out of bounds check
19
+ if (targetIndex < 0 || targetIndex >= this.totalItems) {
20
+ return false;
21
+ }
22
+ // In nonlinear mode, can navigate anywhere
23
+ if (this.mode === 'nonlinear') {
24
+ return true;
25
+ }
26
+ // In linear mode:
27
+ // - Can go back to any visited item
28
+ // - Can only go forward to the next unvisited item
29
+ if (targetIndex <= currentIndex) {
30
+ return true; // Can always go back
31
+ }
32
+ if (targetIndex === currentIndex + 1) {
33
+ return true; // Can advance to next item
34
+ }
35
+ // Can't skip ahead in linear mode
36
+ return false;
37
+ }
38
+ /**
39
+ * Check if "next" navigation is allowed
40
+ */
41
+ canNext(currentIndex) {
42
+ return currentIndex < this.totalItems - 1;
43
+ }
44
+ /**
45
+ * Check if "previous" navigation is allowed
46
+ */
47
+ canPrevious(currentIndex) {
48
+ return currentIndex > 0;
49
+ }
50
+ /**
51
+ * Get the next valid index
52
+ */
53
+ getNextIndex(currentIndex) {
54
+ if (!this.canNext(currentIndex)) {
55
+ return null;
56
+ }
57
+ return currentIndex + 1;
58
+ }
59
+ /**
60
+ * Get the previous valid index
61
+ */
62
+ getPreviousIndex(currentIndex) {
63
+ if (!this.canPrevious(currentIndex)) {
64
+ return null;
65
+ }
66
+ return currentIndex - 1;
67
+ }
68
+ /**
69
+ * Mark an item as visited
70
+ */
71
+ markVisited(index) {
72
+ this.visitedItems.add(index);
73
+ }
74
+ /**
75
+ * Check if an item has been visited
76
+ */
77
+ isVisited(index) {
78
+ return this.visitedItems.has(index);
79
+ }
80
+ /**
81
+ * Get all visited item indices
82
+ */
83
+ getVisitedItems() {
84
+ return Array.from(this.visitedItems).sort((a, b) => a - b);
85
+ }
86
+ /**
87
+ * Get navigation mode
88
+ */
89
+ getMode() {
90
+ return this.mode;
91
+ }
92
+ /**
93
+ * Reset visited items (e.g., for retaking assessment)
94
+ */
95
+ reset() {
96
+ this.visitedItems.clear();
97
+ }
98
+ /**
99
+ * Restore state (for save/resume)
100
+ */
101
+ restoreState(visitedItems) {
102
+ this.visitedItems = new Set(visitedItems);
103
+ }
104
+ }
@@ -0,0 +1,126 @@
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 interface PersistableState {
15
+ /** Assessment identifier */
16
+ assessmentId: string;
17
+ /** Current item index */
18
+ currentItemIndex: number;
19
+ /** Visited item indices */
20
+ visitedItems: number[];
21
+ /** Response data per item */
22
+ responses: Record<string, unknown>;
23
+ /** Item session states (attempts, submission status) */
24
+ itemSessionStates: Record<string, {
25
+ attemptCount: number;
26
+ isAnswered: boolean;
27
+ isSubmitted: boolean;
28
+ lastSubmissionTime?: number;
29
+ }>;
30
+ /** Time tracking data */
31
+ timeTracking?: {
32
+ startedAt: number;
33
+ totalElapsed: number;
34
+ itemTimes: Record<string, number>;
35
+ sectionTimes: Record<string, number>;
36
+ };
37
+ /** Last saved timestamp */
38
+ savedAt: number;
39
+ }
40
+ export interface PersistenceConfig {
41
+ /** Unique session identifier */
42
+ sessionId: string;
43
+ /** Assessment identifier */
44
+ assessmentId: string;
45
+ /** Auto-save enabled (default: true) */
46
+ autoSave?: boolean;
47
+ /** Auto-save debounce delay in ms (default: 2000) */
48
+ autoSaveDelay?: number;
49
+ /** Storage strategy */
50
+ storage?: 'localStorage' | 'sessionStorage' | 'memory';
51
+ /** Optional backend save callback */
52
+ onBackendSave?: (state: PersistableState) => Promise<void>;
53
+ /** Optional save success callback */
54
+ onSaveSuccess?: (state: PersistableState) => void;
55
+ /** Optional save error callback */
56
+ onSaveError?: (error: Error) => void;
57
+ }
58
+ export declare class StatePersistenceManager {
59
+ private config;
60
+ private currentState;
61
+ private autoSaveTimer;
62
+ private isSaving;
63
+ private memoryStorage;
64
+ constructor(config: PersistenceConfig);
65
+ /**
66
+ * Update state and trigger auto-save
67
+ */
68
+ updateState(state: Partial<PersistableState>): void;
69
+ /**
70
+ * Schedule auto-save with debouncing
71
+ */
72
+ private scheduleAutoSave;
73
+ /**
74
+ * Manually save current state
75
+ */
76
+ save(): Promise<void>;
77
+ /**
78
+ * Save to configured storage
79
+ */
80
+ private saveToStorage;
81
+ /**
82
+ * Load state from storage
83
+ */
84
+ load(): Promise<PersistableState | null>;
85
+ /**
86
+ * Check if saved state exists
87
+ */
88
+ hasSavedState(): Promise<boolean>;
89
+ /**
90
+ * Clear saved state
91
+ */
92
+ clear(): Promise<void>;
93
+ /**
94
+ * Get current state without saving
95
+ */
96
+ getCurrentState(): PersistableState | null;
97
+ /**
98
+ * Get storage key for this session
99
+ */
100
+ private getStorageKey;
101
+ /**
102
+ * Force immediate save (bypasses debounce)
103
+ */
104
+ forceSave(): Promise<void>;
105
+ /**
106
+ * Pause auto-save (useful during navigation transitions)
107
+ */
108
+ pauseAutoSave(): void;
109
+ /**
110
+ * Resume auto-save
111
+ */
112
+ resumeAutoSave(): void;
113
+ /**
114
+ * Get last save timestamp
115
+ */
116
+ getLastSaveTime(): number | null;
117
+ /**
118
+ * Check if state has been modified since last save
119
+ */
120
+ isDirty(): boolean;
121
+ /**
122
+ * Cleanup
123
+ */
124
+ destroy(): void;
125
+ }
126
+ //# sourceMappingURL=StatePersistenceManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatePersistenceManager.d.ts","sourceRoot":"","sources":["../../src/core/StatePersistenceManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,gBAAgB;IAChC,4BAA4B;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,2BAA2B;IAC3B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wDAAwD;IACxD,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE;QACjC,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC,CAAC;IACH,yBAAyB;IACzB,YAAY,CAAC,EAAE;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACrC,CAAC;IACF,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IACjC,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,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