@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.5
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 +28 -7
- package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
- package/dist/components/createPlayerConnection.svelte.js +151 -0
- package/dist/components/createPlayerConnection.svelte.js.map +1 -0
- package/dist/components/displaySettings.svelte.d.ts +23 -0
- package/dist/components/displaySettings.svelte.js +40 -0
- package/dist/components/displaySettings.svelte.js.map +1 -0
- package/dist/components/srOnly.d.ts +29 -0
- package/dist/components/srOnly.js +55 -0
- package/dist/components/srOnly.js.map +1 -0
- package/dist/components/submitDialogAction.d.ts +25 -0
- package/dist/components/submitDialogAction.js +89 -0
- package/dist/components/submitDialogAction.js.map +1 -0
- package/dist/core/AssessmentPlayer.d.ts +1102 -53
- package/dist/core/AssessmentPlayer.js +2836 -457
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
- package/dist/core/AssessmentSessionCoordinator.js +185 -10
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/AutosaveManager.d.ts +104 -0
- package/dist/core/AutosaveManager.js +181 -0
- package/dist/core/AutosaveManager.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +17 -26
- package/dist/core/ItemSessionController.js +33 -73
- package/dist/core/ItemSessionController.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +18 -50
- package/dist/core/NavigationManager.js +21 -83
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +62 -16
- package/dist/core/TimeManager.js +148 -57
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/core/autosave.d.ts +44 -0
- package/dist/core/autosave.js +46 -0
- package/dist/core/autosave.js.map +1 -0
- package/dist/core/deliveryStructure.d.ts +54 -0
- package/dist/core/deliveryStructure.js +72 -0
- package/dist/core/deliveryStructure.js.map +1 -0
- package/dist/core/errors.d.ts +116 -0
- package/dist/core/errors.js +77 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exitBoundaries.d.ts +64 -0
- package/dist/core/exitBoundaries.js +98 -0
- package/dist/core/exitBoundaries.js.map +1 -0
- package/dist/core/feedback.d.ts +46 -0
- package/dist/core/feedback.js +47 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/formatTime.d.ts +8 -0
- package/dist/core/formatTime.js +20 -0
- package/dist/core/formatTime.js.map +1 -0
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/navigationPolicy.d.ts +46 -0
- package/dist/core/navigationPolicy.js +66 -0
- package/dist/core/navigationPolicy.js.map +1 -0
- package/dist/core/pause.d.ts +58 -0
- package/dist/core/pause.js +101 -0
- package/dist/core/pause.js.map +1 -0
- package/dist/core/playerEvents.d.ts +51 -0
- package/dist/core/playerEvents.js +66 -0
- package/dist/core/playerEvents.js.map +1 -0
- package/dist/core/reviewState.d.ts +81 -0
- package/dist/core/reviewState.js +113 -0
- package/dist/core/reviewState.js.map +1 -0
- package/dist/core/reviewViews.d.ts +43 -0
- package/dist/core/reviewViews.js +88 -0
- package/dist/core/reviewViews.js.map +1 -0
- package/dist/core/scopeLocks.d.ts +36 -0
- package/dist/core/scopeLocks.js +78 -0
- package/dist/core/scopeLocks.js.map +1 -0
- package/dist/core/sessionRecords.d.ts +31 -0
- package/dist/core/sessionRecords.js +74 -0
- package/dist/core/sessionRecords.js.map +1 -0
- package/dist/core/submissionPolicy.d.ts +65 -0
- package/dist/core/submissionPolicy.js +71 -0
- package/dist/core/submissionPolicy.js.map +1 -0
- package/dist/core/templateDefaults.d.ts +26 -0
- package/dist/core/templateDefaults.js +54 -0
- package/dist/core/templateDefaults.js.map +1 -0
- package/dist/core/testStructure.d.ts +118 -3
- package/dist/core/testStructure.js +255 -6
- package/dist/core/testStructure.js.map +1 -1
- package/dist/core/timePolicy.d.ts +40 -0
- package/dist/core/timePolicy.js +106 -0
- package/dist/core/timePolicy.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
- package/dist/integration/ReferenceBackendAdapter.js +214 -1033
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +175 -10
- package/dist/integration/api-contract.js.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +56 -5
- package/dist/integration/assessment-item-scorer.js +116 -13
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/qti-test-parser.d.ts +44 -0
- package/dist/integration/qti-test-parser.js +558 -0
- package/dist/integration/qti-test-parser.js.map +1 -0
- package/dist/integration/session-store.d.ts +54 -0
- package/dist/integration/session-store.js +75 -0
- package/dist/integration/session-store.js.map +1 -0
- package/dist/integration/test-navigation.d.ts +23 -0
- package/dist/integration/test-navigation.js +32 -0
- package/dist/integration/test-navigation.js.map +1 -0
- package/dist/integration/toSectionComposition.js +8 -1
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/dist/reporting/index.d.ts +3 -0
- package/dist/reporting/index.js +3 -0
- package/dist/reporting/index.js.map +1 -0
- package/dist/reporting/inferBaseType.d.ts +13 -0
- package/dist/reporting/inferBaseType.js +26 -0
- package/dist/reporting/inferBaseType.js.map +1 -0
- package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
- package/dist/reporting/serializeAssessmentResult.js +377 -0
- package/dist/reporting/serializeAssessmentResult.js.map +1 -0
- package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
- package/dist/reporting/toAssessmentResultXml.js +304 -0
- package/dist/reporting/toAssessmentResultXml.js.map +1 -0
- package/dist/reporting/types.d.ts +85 -0
- package/dist/reporting/types.js +8 -0
- package/dist/reporting/types.js.map +1 -0
- package/dist/types/index.d.ts +96 -9
- package/dist/types/index.js.map +1 -1
- package/package.json +19 -13
- package/dist/core/StatePersistenceManager.d.ts +0 -125
- package/dist/core/StatePersistenceManager.js +0 -268
- package/dist/core/StatePersistenceManager.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -114
- package/dist/utils/PerformanceMonitor.js +0 -172
- package/dist/utils/PerformanceMonitor.js.map +0 -1
|
@@ -1,97 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The presented-items record for the assessment player's navigation UI hints:
|
|
3
|
+
* every item delivery has shown (the review screen's visited marks ride it).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Deliberately kept separate from the backend contract's `state.visitedItems`
|
|
6
|
+
* (the session state the coordinator owns): the two records coincide only where
|
|
7
|
+
* a submission happened, and merging them is `getState()`'s job, not this
|
|
8
|
+
* class's. Deliberately NOT a navigation decision-maker either: QTI's real
|
|
9
|
+
* navigation rules (testPart sequencing, time locks, review-after-submit, branch
|
|
10
|
+
* targets) live in `AssessmentPlayer`'s navigation policy, which reads session
|
|
11
|
+
* state this class knows nothing about. Keeping only presentation tracking here
|
|
12
|
+
* avoids a second, divergent source of navigation truth.
|
|
7
13
|
*/
|
|
8
14
|
export class NavigationManager {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
11
|
-
this.totalItems = totalItems;
|
|
12
|
-
this.visitedItems = new Set();
|
|
15
|
+
constructor() {
|
|
16
|
+
this.presentedIndexes = new Set();
|
|
13
17
|
}
|
|
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
|
-
// Linear mode permits staying on the current item or advancing exactly
|
|
27
|
-
// one item. QTI forbids returning after the candidate moves on.
|
|
28
|
-
return targetIndex === currentIndex || targetIndex === currentIndex + 1;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Check if "next" navigation is allowed
|
|
32
|
-
*/
|
|
33
|
-
canNext(currentIndex) {
|
|
34
|
-
return currentIndex < this.totalItems - 1;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Check if "previous" navigation is allowed
|
|
38
|
-
*/
|
|
39
|
-
canPrevious(currentIndex) {
|
|
40
|
-
return this.mode === 'nonlinear' && currentIndex > 0;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Get the next valid index
|
|
44
|
-
*/
|
|
45
|
-
getNextIndex(currentIndex) {
|
|
46
|
-
if (!this.canNext(currentIndex)) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return currentIndex + 1;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Get the previous valid index
|
|
53
|
-
*/
|
|
54
|
-
getPreviousIndex(currentIndex) {
|
|
55
|
-
if (!this.canPrevious(currentIndex)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return currentIndex - 1;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Mark an item as visited
|
|
62
|
-
*/
|
|
18
|
+
/** Mark an item as presented. */
|
|
63
19
|
markVisited(index) {
|
|
64
|
-
this.
|
|
20
|
+
this.presentedIndexes.add(index);
|
|
65
21
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if an item has been visited
|
|
68
|
-
*/
|
|
22
|
+
/** Whether the candidate has been presented this item (by flat index). */
|
|
69
23
|
isVisited(index) {
|
|
70
|
-
return this.
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get all visited item indices
|
|
74
|
-
*/
|
|
75
|
-
getVisitedItems() {
|
|
76
|
-
return Array.from(this.visitedItems).sort((a, b) => a - b);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get navigation mode
|
|
80
|
-
*/
|
|
81
|
-
getMode() {
|
|
82
|
-
return this.mode;
|
|
24
|
+
return this.presentedIndexes.has(index);
|
|
83
25
|
}
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
reset() {
|
|
88
|
-
this.visitedItems.clear();
|
|
26
|
+
/** The presented flat indexes, ascending (for snapshots). */
|
|
27
|
+
getVisited() {
|
|
28
|
+
return [...this.presentedIndexes].sort((a, b) => a - b);
|
|
89
29
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Restore state (for save/resume)
|
|
92
|
-
*/
|
|
30
|
+
/** Restore the presented-index record (for save/resume). */
|
|
93
31
|
restoreState(visitedItems) {
|
|
94
|
-
this.
|
|
32
|
+
this.presentedIndexes = new Set(visitedItems);
|
|
95
33
|
}
|
|
96
34
|
}
|
|
97
35
|
//# sourceMappingURL=NavigationManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationManager.js","sourceRoot":"","sources":["../../src/core/NavigationManager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"NavigationManager.js","sourceRoot":"","sources":["../../src/core/NavigationManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,iBAAiB;IAI7B;QACC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3C,CAAC;IAED,iCAAiC;IACjC,WAAW,CAAC,KAAa;QACxB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,0EAA0E;IAC1E,SAAS,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,6DAA6D;IAC7D,UAAU;QACT,OAAO,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,4DAA4D;IAC5D,YAAY,CAAC,YAAsB;QAClC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;CACD","sourcesContent":["/**\n * The presented-items record for the assessment player's navigation UI hints:\n * every item delivery has shown (the review screen's visited marks ride it).\n *\n * Deliberately kept separate from the backend contract's `state.visitedItems`\n * (the session state the coordinator owns): the two records coincide only where\n * a submission happened, and merging them is `getState()`'s job, not this\n * class's. Deliberately NOT a navigation decision-maker either: QTI's real\n * navigation rules (testPart sequencing, time locks, review-after-submit, branch\n * targets) live in `AssessmentPlayer`'s navigation policy, which reads session\n * state this class knows nothing about. Keeping only presentation tracking here\n * avoids a second, divergent source of navigation truth.\n */\n\nexport class NavigationManager {\n\t/** The flat delivery indexes presented so far. */\n\tprivate presentedIndexes: Set<number>;\n\n\tconstructor() {\n\t\tthis.presentedIndexes = new Set<number>();\n\t}\n\n\t/** Mark an item as presented. */\n\tmarkVisited(index: number): void {\n\t\tthis.presentedIndexes.add(index);\n\t}\n\n\t/** Whether the candidate has been presented this item (by flat index). */\n\tisVisited(index: number): boolean {\n\t\treturn this.presentedIndexes.has(index);\n\t}\n\n\t/** The presented flat indexes, ascending (for snapshots). */\n\tgetVisited(): number[] {\n\t\treturn [...this.presentedIndexes].sort((a, b) => a - b);\n\t}\n\n\t/** Restore the presented-index record (for save/resume). */\n\trestoreState(visitedItems: number[]): void {\n\t\tthis.presentedIndexes = new Set(visitedItems);\n\t}\n}\n"]}
|
|
@@ -15,9 +15,12 @@ import type { TimeLimits } from '../types/index.js';
|
|
|
15
15
|
export interface TimeManagerConfig {
|
|
16
16
|
/** Assessment-level time limits */
|
|
17
17
|
assessmentTimeLimits?: TimeLimits;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Warning thresholds (seconds before expiry). Each fires once per limiting scope when
|
|
20
|
+
* the remaining time first reaches it, largest first. Without any, nothing warns.
|
|
21
|
+
*/
|
|
22
|
+
warningThresholds?: number[];
|
|
23
|
+
/** Callback when a warning threshold is reached */
|
|
21
24
|
onWarning?: (remainingSeconds: number) => void;
|
|
22
25
|
/** Callback when time expires */
|
|
23
26
|
onExpired?: () => void;
|
|
@@ -42,15 +45,35 @@ export interface ActiveTimeScopes {
|
|
|
42
45
|
identifier: string;
|
|
43
46
|
timeLimits?: TimeLimits;
|
|
44
47
|
};
|
|
48
|
+
/** The innermost enclosing section. */
|
|
45
49
|
section?: {
|
|
46
50
|
identifier: string;
|
|
47
51
|
timeLimits?: TimeLimits;
|
|
48
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Every enclosing section, outermost first. Delivery is nested inside all of them, so
|
|
55
|
+
* each runs its own clock and its `timeLimits` expire and gate like any other scope.
|
|
56
|
+
* When set, `section` must be its last entry (kept in sync by the caller).
|
|
57
|
+
*/
|
|
58
|
+
sections?: Array<{
|
|
59
|
+
identifier: string;
|
|
60
|
+
timeLimits?: TimeLimits;
|
|
61
|
+
}>;
|
|
49
62
|
item?: {
|
|
50
63
|
identifier: string;
|
|
51
64
|
timeLimits?: TimeLimits;
|
|
52
65
|
};
|
|
53
66
|
}
|
|
67
|
+
/** The active hard maximum that runs out first: what a countdown UI shows. */
|
|
68
|
+
export interface NearestTimeLimit {
|
|
69
|
+
/** The scope the limit was authored on; `assessment` is the whole test. */
|
|
70
|
+
scope: 'assessment' | 'testPart' | 'section' | 'item';
|
|
71
|
+
/** Scope identifier; undefined for the assessment scope. */
|
|
72
|
+
identifier?: string;
|
|
73
|
+
/** Seconds left (may be fractional; the ticking UI rounds up). */
|
|
74
|
+
remainingSeconds: number;
|
|
75
|
+
allowLateSubmission: boolean;
|
|
76
|
+
}
|
|
54
77
|
export interface TimeTrackingState {
|
|
55
78
|
/** Total elapsed time (ms) */
|
|
56
79
|
totalElapsed: number;
|
|
@@ -68,8 +91,6 @@ export interface TimeTrackingState {
|
|
|
68
91
|
currentItemId?: string;
|
|
69
92
|
/** Current section identifier */
|
|
70
93
|
currentSectionId?: string;
|
|
71
|
-
/** Current section start time */
|
|
72
|
-
currentSectionStartTime?: number;
|
|
73
94
|
/** Current testPart identifier */
|
|
74
95
|
currentTestPartId?: string;
|
|
75
96
|
/** Current testPart start time */
|
|
@@ -96,6 +117,12 @@ export declare class TimeManager {
|
|
|
96
117
|
private warningTriggered;
|
|
97
118
|
private expirationTriggered;
|
|
98
119
|
private activeScopes;
|
|
120
|
+
/**
|
|
121
|
+
* Sections currently being timed (every enclosing scope), identifier → start (ms).
|
|
122
|
+
* Nested sections run alongside each other, so a single "current section" start
|
|
123
|
+
* cannot hold them; completed segments accumulate into `state.sectionTimes`.
|
|
124
|
+
*/
|
|
125
|
+
private readonly sectionStarts;
|
|
99
126
|
private lastTickAt;
|
|
100
127
|
constructor(config: TimeManagerConfig);
|
|
101
128
|
private now;
|
|
@@ -104,8 +131,15 @@ export declare class TimeManager {
|
|
|
104
131
|
* Start or resume the timer
|
|
105
132
|
*/
|
|
106
133
|
private startTimer;
|
|
134
|
+
/** Every configured warning threshold, deduplicated, largest first. */
|
|
135
|
+
private warningThresholdList;
|
|
107
136
|
private getActiveCandidates;
|
|
108
137
|
private nearestRemaining;
|
|
138
|
+
/**
|
|
139
|
+
* The active hard maximum that runs out first — the countdown a shell displays — or
|
|
140
|
+
* null when nothing limits the current scope.
|
|
141
|
+
*/
|
|
142
|
+
getNearestLimit(): NearestTimeLimit | null;
|
|
109
143
|
private getActiveRemaining;
|
|
110
144
|
/**
|
|
111
145
|
* Handle time expiration
|
|
@@ -135,19 +169,38 @@ export declare class TimeManager {
|
|
|
135
169
|
* End tracking time for an item
|
|
136
170
|
*/
|
|
137
171
|
endItem(itemIdentifier: string): void;
|
|
172
|
+
startTestPart(testPartIdentifier: string): void;
|
|
138
173
|
/**
|
|
139
|
-
*
|
|
174
|
+
* Enter a new item's scope chain: every enclosing section runs its own clock, so
|
|
175
|
+
* entering starts the newly enclosed ones and leaving folds the exited ones into
|
|
176
|
+
* their persisted `sectionTimes`. An outer section shared with the previous item
|
|
177
|
+
* keeps its running clock.
|
|
140
178
|
*/
|
|
141
|
-
startSection(sectionIdentifier: string): void;
|
|
142
|
-
startTestPart(testPartIdentifier: string): void;
|
|
143
179
|
activateScopes(scopes: ActiveTimeScopes): void;
|
|
144
|
-
|
|
180
|
+
/** The enclosing section scopes of an activation, outermost first. */
|
|
181
|
+
private activeSectionScopes;
|
|
182
|
+
private activateSections;
|
|
183
|
+
/** Fold every running section clock into `sectionTimes` and stop them. */
|
|
184
|
+
private endRunningSections;
|
|
145
185
|
private endCurrentTestPart;
|
|
146
186
|
private checkpointActiveScopes;
|
|
187
|
+
/**
|
|
188
|
+
* Record limits that already ran out — restored from a snapshot's clocks — so the live
|
|
189
|
+
* timer never fires their expiry a second time. Keys are `assessment` or
|
|
190
|
+
* `scope:identifier` (`testPart:P1`, `section:S1`, `item:I1`).
|
|
191
|
+
*/
|
|
192
|
+
markExpired(keys: Iterable<string>): void;
|
|
193
|
+
/** Forget the fired expiries, before another snapshot's clocks replace these. */
|
|
194
|
+
resetExpiryRecord(): void;
|
|
147
195
|
/**
|
|
148
196
|
* Get remaining time in seconds (null if no limit)
|
|
149
197
|
*/
|
|
150
198
|
getRemainingSeconds(): number | null;
|
|
199
|
+
/**
|
|
200
|
+
* Remaining seconds on the assessment-level limit only (null when the test has no
|
|
201
|
+
* maximum); what a start screen states as "You have N minutes".
|
|
202
|
+
*/
|
|
203
|
+
getAssessmentRemainingSeconds(): number | null;
|
|
151
204
|
/**
|
|
152
205
|
* Get elapsed time in seconds
|
|
153
206
|
*/
|
|
@@ -174,13 +227,6 @@ export declare class TimeManager {
|
|
|
174
227
|
* Check if late submission is allowed
|
|
175
228
|
*/
|
|
176
229
|
allowsLateSubmission(): boolean;
|
|
177
|
-
/**
|
|
178
|
-
* Format time as MM:SS or HH:MM:SS
|
|
179
|
-
*
|
|
180
|
-
* Pass the provider's `formatNumber` to render the locale's digits; without
|
|
181
|
-
* it the digits are Western.
|
|
182
|
-
*/
|
|
183
|
-
static formatTime(seconds: number, formatNumber?: (value: number, options?: Intl.NumberFormatOptions) => string): string;
|
|
184
230
|
/**
|
|
185
231
|
* Cleanup - stop all timers
|
|
186
232
|
*/
|
package/dist/core/TimeManager.js
CHANGED
|
@@ -31,6 +31,12 @@ export class TimeManager {
|
|
|
31
31
|
this.warningTriggered = new Set();
|
|
32
32
|
this.expirationTriggered = new Set();
|
|
33
33
|
this.activeScopes = {};
|
|
34
|
+
/**
|
|
35
|
+
* Sections currently being timed (every enclosing scope), identifier → start (ms).
|
|
36
|
+
* Nested sections run alongside each other, so a single "current section" start
|
|
37
|
+
* cannot hold them; completed segments accumulate into `state.sectionTimes`.
|
|
38
|
+
*/
|
|
39
|
+
this.sectionStarts = new Map();
|
|
34
40
|
this.config = config;
|
|
35
41
|
this.state = {
|
|
36
42
|
totalElapsed: 0,
|
|
@@ -93,11 +99,15 @@ export class TimeManager {
|
|
|
93
99
|
const activeRemaining = this.nearestRemaining(candidates);
|
|
94
100
|
if (activeRemaining) {
|
|
95
101
|
const { key, remainingSeconds } = activeRemaining;
|
|
96
|
-
// Trigger warning
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
this.warningTriggered.
|
|
100
|
-
|
|
102
|
+
// Trigger each configured warning threshold once, largest first, per scope.
|
|
103
|
+
for (const threshold of this.warningThresholdList()) {
|
|
104
|
+
const warningKey = `${key}@${threshold}`;
|
|
105
|
+
if (this.warningTriggered.has(warningKey))
|
|
106
|
+
continue;
|
|
107
|
+
if (remainingSeconds <= threshold && remainingSeconds > 0) {
|
|
108
|
+
this.warningTriggered.add(warningKey);
|
|
109
|
+
this.config.onWarning?.(remainingSeconds);
|
|
110
|
+
}
|
|
101
111
|
}
|
|
102
112
|
// Tick callback
|
|
103
113
|
this.config.onTick?.(remainingSeconds, elapsedSeconds);
|
|
@@ -108,24 +118,53 @@ export class TimeManager {
|
|
|
108
118
|
}
|
|
109
119
|
}, 1000);
|
|
110
120
|
}
|
|
121
|
+
/** Every configured warning threshold, deduplicated, largest first. */
|
|
122
|
+
warningThresholdList() {
|
|
123
|
+
return [...new Set(this.config.warningThresholds ?? [])].sort((a, b) => b - a);
|
|
124
|
+
}
|
|
111
125
|
getActiveCandidates() {
|
|
112
126
|
const candidates = [];
|
|
113
127
|
if (this.maxTimeSeconds !== null) {
|
|
114
128
|
candidates.push({
|
|
115
129
|
key: 'assessment',
|
|
130
|
+
scope: 'assessment',
|
|
116
131
|
remainingSeconds: this.maxTimeSeconds - this.getElapsedSeconds(),
|
|
117
132
|
allowLateSubmission: this.config.assessmentTimeLimits?.allowLateSubmission === true,
|
|
118
133
|
});
|
|
119
134
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
const testPart = this.activeScopes.testPart;
|
|
136
|
+
const testPartMax = this.applyExtendedTime(testPart?.timeLimits?.maxTime);
|
|
137
|
+
if (testPart && testPartMax !== null) {
|
|
138
|
+
candidates.push({
|
|
139
|
+
key: `testPart:${testPart.identifier}`,
|
|
140
|
+
scope: 'testPart',
|
|
141
|
+
identifier: testPart.identifier,
|
|
142
|
+
remainingSeconds: testPartMax - this.getScopeElapsedMs('testPart', testPart.identifier) / 1000,
|
|
143
|
+
allowLateSubmission: testPart.timeLimits?.allowLateSubmission === true,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// Every enclosing section carries its own limit, outermost included.
|
|
147
|
+
for (const section of this.activeSectionScopes()) {
|
|
148
|
+
const max = this.applyExtendedTime(section.timeLimits?.maxTime);
|
|
149
|
+
if (max === null)
|
|
124
150
|
continue;
|
|
125
151
|
candidates.push({
|
|
126
|
-
key:
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
key: `section:${section.identifier}`,
|
|
153
|
+
scope: 'section',
|
|
154
|
+
identifier: section.identifier,
|
|
155
|
+
remainingSeconds: max - this.getScopeElapsedMs('section', section.identifier) / 1000,
|
|
156
|
+
allowLateSubmission: section.timeLimits?.allowLateSubmission === true,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const item = this.activeScopes.item;
|
|
160
|
+
const itemMax = this.applyExtendedTime(item?.timeLimits?.maxTime);
|
|
161
|
+
if (item && itemMax !== null) {
|
|
162
|
+
candidates.push({
|
|
163
|
+
key: `item:${item.identifier}`,
|
|
164
|
+
scope: 'item',
|
|
165
|
+
identifier: item.identifier,
|
|
166
|
+
remainingSeconds: itemMax - this.getScopeElapsedMs('item', item.identifier) / 1000,
|
|
167
|
+
allowLateSubmission: item.timeLimits?.allowLateSubmission === true,
|
|
129
168
|
});
|
|
130
169
|
}
|
|
131
170
|
return candidates;
|
|
@@ -135,6 +174,22 @@ export class TimeManager {
|
|
|
135
174
|
return null;
|
|
136
175
|
return candidates.reduce((nearest, candidate) => candidate.remainingSeconds < nearest.remainingSeconds ? candidate : nearest);
|
|
137
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* The active hard maximum that runs out first — the countdown a shell displays — or
|
|
179
|
+
* null when nothing limits the current scope.
|
|
180
|
+
*/
|
|
181
|
+
getNearestLimit() {
|
|
182
|
+
const candidates = this.getActiveCandidates();
|
|
183
|
+
if (candidates.length === 0)
|
|
184
|
+
return null;
|
|
185
|
+
const nearest = this.nearestRemaining(candidates);
|
|
186
|
+
return {
|
|
187
|
+
scope: nearest.scope,
|
|
188
|
+
identifier: nearest.identifier,
|
|
189
|
+
remainingSeconds: nearest.remainingSeconds,
|
|
190
|
+
allowLateSubmission: nearest.allowLateSubmission,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
138
193
|
getActiveRemaining() {
|
|
139
194
|
return this.nearestRemaining(this.getActiveCandidates());
|
|
140
195
|
}
|
|
@@ -175,10 +230,14 @@ export class TimeManager {
|
|
|
175
230
|
const now = this.now();
|
|
176
231
|
if (this.state.currentItemId)
|
|
177
232
|
this.state.currentItemStartTime = now;
|
|
178
|
-
if (this.state.currentSectionId)
|
|
179
|
-
this.state.currentSectionStartTime = now;
|
|
180
233
|
if (this.state.currentTestPartId)
|
|
181
234
|
this.state.currentTestPartStartTime = now;
|
|
235
|
+
// Every enclosing section the delivery sits in restarts where it froze.
|
|
236
|
+
for (const section of this.activeSectionScopes()) {
|
|
237
|
+
const start = this.sectionStarts.get(section.identifier);
|
|
238
|
+
if (start === undefined || !Number.isFinite(start))
|
|
239
|
+
this.sectionStarts.set(section.identifier, now);
|
|
240
|
+
}
|
|
182
241
|
this.lastTickAt = now;
|
|
183
242
|
}
|
|
184
243
|
/**
|
|
@@ -222,16 +281,6 @@ export class TimeManager {
|
|
|
222
281
|
this.state.currentItemStartTime = undefined;
|
|
223
282
|
this.state.currentItemId = undefined;
|
|
224
283
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Start tracking time for a section
|
|
227
|
-
*/
|
|
228
|
-
startSection(sectionIdentifier) {
|
|
229
|
-
if (this.state.currentSectionId === sectionIdentifier && this.state.currentSectionStartTime)
|
|
230
|
-
return;
|
|
231
|
-
this.endCurrentSection();
|
|
232
|
-
this.state.currentSectionId = sectionIdentifier;
|
|
233
|
-
this.state.currentSectionStartTime = this.state.isPaused ? undefined : this.now();
|
|
234
|
-
}
|
|
235
284
|
startTestPart(testPartIdentifier) {
|
|
236
285
|
if (this.state.currentTestPartId === testPartIdentifier && this.state.currentTestPartStartTime)
|
|
237
286
|
return;
|
|
@@ -239,22 +288,57 @@ export class TimeManager {
|
|
|
239
288
|
this.state.currentTestPartId = testPartIdentifier;
|
|
240
289
|
this.state.currentTestPartStartTime = this.state.isPaused ? undefined : this.now();
|
|
241
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Enter a new item's scope chain: every enclosing section runs its own clock, so
|
|
293
|
+
* entering starts the newly enclosed ones and leaving folds the exited ones into
|
|
294
|
+
* their persisted `sectionTimes`. An outer section shared with the previous item
|
|
295
|
+
* keeps its running clock.
|
|
296
|
+
*/
|
|
242
297
|
activateScopes(scopes) {
|
|
243
298
|
if (scopes.testPart)
|
|
244
299
|
this.startTestPart(scopes.testPart.identifier);
|
|
245
|
-
|
|
246
|
-
this.startSection(scopes.section.identifier);
|
|
300
|
+
this.activateSections(this.activeSectionScopes(scopes));
|
|
247
301
|
if (scopes.item)
|
|
248
302
|
this.startItem(scopes.item.identifier);
|
|
249
303
|
this.activeScopes = scopes;
|
|
250
304
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
305
|
+
/** The enclosing section scopes of an activation, outermost first. */
|
|
306
|
+
activeSectionScopes(scopes = this.activeScopes) {
|
|
307
|
+
if (scopes.sections)
|
|
308
|
+
return scopes.sections;
|
|
309
|
+
return scopes.section ? [scopes.section] : [];
|
|
310
|
+
}
|
|
311
|
+
activateSections(sections) {
|
|
312
|
+
const now = this.now();
|
|
313
|
+
const wanted = new Set(sections.map((section) => section.identifier));
|
|
314
|
+
// Sections delivery left: fold their running time into the persisted clock.
|
|
315
|
+
for (const [identifier, start] of this.sectionStarts) {
|
|
316
|
+
if (wanted.has(identifier))
|
|
317
|
+
continue;
|
|
318
|
+
const elapsed = Math.max(0, now - start);
|
|
319
|
+
this.state.sectionTimes[identifier] = (this.state.sectionTimes[identifier] || 0) + elapsed;
|
|
320
|
+
this.sectionStarts.delete(identifier);
|
|
321
|
+
}
|
|
322
|
+
// Sections delivery entered (or the clocks were checkpointed): start them. While
|
|
323
|
+
// paused the start is recorded but no elapsed time accrues until resume reseeds.
|
|
324
|
+
for (const section of sections) {
|
|
325
|
+
if (this.sectionStarts.has(section.identifier))
|
|
326
|
+
continue;
|
|
327
|
+
this.sectionStarts.set(section.identifier, this.state.isPaused ? Number.NaN : now);
|
|
328
|
+
}
|
|
329
|
+
// The innermost section stays the "current" one for the persisted snapshot.
|
|
330
|
+
this.state.currentSectionId = sections[sections.length - 1]?.identifier;
|
|
331
|
+
}
|
|
332
|
+
/** Fold every running section clock into `sectionTimes` and stop them. */
|
|
333
|
+
endRunningSections() {
|
|
334
|
+
const now = this.now();
|
|
335
|
+
for (const [identifier, start] of this.sectionStarts) {
|
|
336
|
+
if (Number.isFinite(start)) {
|
|
337
|
+
const elapsed = Math.max(0, now - start);
|
|
338
|
+
this.state.sectionTimes[identifier] = (this.state.sectionTimes[identifier] || 0) + elapsed;
|
|
339
|
+
}
|
|
340
|
+
this.sectionStarts.delete(identifier);
|
|
256
341
|
}
|
|
257
|
-
this.state.currentSectionStartTime = undefined;
|
|
258
342
|
}
|
|
259
343
|
endCurrentTestPart() {
|
|
260
344
|
if (this.state.currentTestPartId && this.state.currentTestPartStartTime) {
|
|
@@ -269,7 +353,7 @@ export class TimeManager {
|
|
|
269
353
|
const sectionId = this.state.currentSectionId;
|
|
270
354
|
const testPartId = this.state.currentTestPartId;
|
|
271
355
|
this.endCurrentItem();
|
|
272
|
-
this.
|
|
356
|
+
this.endRunningSections();
|
|
273
357
|
this.endCurrentTestPart();
|
|
274
358
|
this.state.currentItemId = itemId;
|
|
275
359
|
this.state.currentSectionId = sectionId;
|
|
@@ -278,12 +362,25 @@ export class TimeManager {
|
|
|
278
362
|
const now = this.now();
|
|
279
363
|
if (itemId)
|
|
280
364
|
this.state.currentItemStartTime = now;
|
|
281
|
-
|
|
282
|
-
this.
|
|
365
|
+
for (const section of this.activeSectionScopes())
|
|
366
|
+
this.sectionStarts.set(section.identifier, now);
|
|
283
367
|
if (testPartId)
|
|
284
368
|
this.state.currentTestPartStartTime = now;
|
|
285
369
|
}
|
|
286
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Record limits that already ran out — restored from a snapshot's clocks — so the live
|
|
373
|
+
* timer never fires their expiry a second time. Keys are `assessment` or
|
|
374
|
+
* `scope:identifier` (`testPart:P1`, `section:S1`, `item:I1`).
|
|
375
|
+
*/
|
|
376
|
+
markExpired(keys) {
|
|
377
|
+
for (const key of keys)
|
|
378
|
+
this.expirationTriggered.add(key);
|
|
379
|
+
}
|
|
380
|
+
/** Forget the fired expiries, before another snapshot's clocks replace these. */
|
|
381
|
+
resetExpiryRecord() {
|
|
382
|
+
this.expirationTriggered.clear();
|
|
383
|
+
}
|
|
287
384
|
/**
|
|
288
385
|
* Get remaining time in seconds (null if no limit)
|
|
289
386
|
*/
|
|
@@ -291,6 +388,15 @@ export class TimeManager {
|
|
|
291
388
|
const active = this.getActiveRemaining();
|
|
292
389
|
return active ? Math.max(0, Math.ceil(active.remainingSeconds)) : null;
|
|
293
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Remaining seconds on the assessment-level limit only (null when the test has no
|
|
393
|
+
* maximum); what a start screen states as "You have N minutes".
|
|
394
|
+
*/
|
|
395
|
+
getAssessmentRemainingSeconds() {
|
|
396
|
+
if (this.maxTimeSeconds === null)
|
|
397
|
+
return null;
|
|
398
|
+
return Math.max(0, Math.ceil(this.maxTimeSeconds - this.getElapsedSeconds()));
|
|
399
|
+
}
|
|
294
400
|
/**
|
|
295
401
|
* Get elapsed time in seconds
|
|
296
402
|
*/
|
|
@@ -325,8 +431,9 @@ export class TimeManager {
|
|
|
325
431
|
const id = identifier ?? this.state.currentSectionId;
|
|
326
432
|
if (!id)
|
|
327
433
|
return 0;
|
|
328
|
-
const
|
|
329
|
-
|
|
434
|
+
const start = this.sectionStarts.get(id);
|
|
435
|
+
const active = start !== undefined && Number.isFinite(start) && !this.state.isPaused
|
|
436
|
+
? Math.max(0, now - start)
|
|
330
437
|
: 0;
|
|
331
438
|
return (this.state.sectionTimes[id] || 0) + active;
|
|
332
439
|
}
|
|
@@ -364,15 +471,17 @@ export class TimeManager {
|
|
|
364
471
|
sectionTimes: { ...state.sectionTimes },
|
|
365
472
|
testPartTimes: { ...(state.testPartTimes ?? {}) },
|
|
366
473
|
currentItemStartTime: undefined,
|
|
367
|
-
currentSectionStartTime: undefined,
|
|
368
474
|
currentTestPartStartTime: undefined,
|
|
369
475
|
};
|
|
476
|
+
this.sectionStarts.clear();
|
|
370
477
|
if (!this.state.isPaused) {
|
|
371
478
|
const now = this.now();
|
|
372
479
|
if (this.state.currentItemId)
|
|
373
480
|
this.state.currentItemStartTime = now;
|
|
481
|
+
// The innermost section restarts at once; the enclosing scopes start when
|
|
482
|
+
// delivery activates them (the restoring navigation follows immediately).
|
|
374
483
|
if (this.state.currentSectionId)
|
|
375
|
-
this.state.
|
|
484
|
+
this.sectionStarts.set(this.state.currentSectionId, now);
|
|
376
485
|
if (this.state.currentTestPartId)
|
|
377
486
|
this.state.currentTestPartStartTime = now;
|
|
378
487
|
this.lastTickAt = now;
|
|
@@ -403,24 +512,6 @@ export class TimeManager {
|
|
|
403
512
|
}
|
|
404
513
|
return this.nearestRemaining(candidates)?.allowLateSubmission ?? false;
|
|
405
514
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Format time as MM:SS or HH:MM:SS
|
|
408
|
-
*
|
|
409
|
-
* Pass the provider's `formatNumber` to render the locale's digits; without
|
|
410
|
-
* it the digits are Western.
|
|
411
|
-
*/
|
|
412
|
-
static formatTime(seconds, formatNumber) {
|
|
413
|
-
const hours = Math.floor(seconds / 3600);
|
|
414
|
-
const minutes = Math.floor((seconds % 3600) / 60);
|
|
415
|
-
const secs = seconds % 60;
|
|
416
|
-
const format = (value, digits) => formatNumber
|
|
417
|
-
? formatNumber(value, { minimumIntegerDigits: digits, useGrouping: false })
|
|
418
|
-
: value.toString().padStart(digits, '0');
|
|
419
|
-
if (hours > 0) {
|
|
420
|
-
return `${format(hours, 1)}:${format(minutes, 2)}:${format(secs, 2)}`;
|
|
421
|
-
}
|
|
422
|
-
return `${format(minutes, 1)}:${format(secs, 2)}`;
|
|
423
|
-
}
|
|
424
515
|
/**
|
|
425
516
|
* Cleanup - stop all timers
|
|
426
517
|
*/
|