@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.
Files changed (134) hide show
  1. package/README.md +28 -7
  2. package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
  3. package/dist/components/createPlayerConnection.svelte.js +151 -0
  4. package/dist/components/createPlayerConnection.svelte.js.map +1 -0
  5. package/dist/components/displaySettings.svelte.d.ts +23 -0
  6. package/dist/components/displaySettings.svelte.js +40 -0
  7. package/dist/components/displaySettings.svelte.js.map +1 -0
  8. package/dist/components/srOnly.d.ts +29 -0
  9. package/dist/components/srOnly.js +55 -0
  10. package/dist/components/srOnly.js.map +1 -0
  11. package/dist/components/submitDialogAction.d.ts +25 -0
  12. package/dist/components/submitDialogAction.js +89 -0
  13. package/dist/components/submitDialogAction.js.map +1 -0
  14. package/dist/core/AssessmentPlayer.d.ts +1102 -53
  15. package/dist/core/AssessmentPlayer.js +2836 -457
  16. package/dist/core/AssessmentPlayer.js.map +1 -1
  17. package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
  18. package/dist/core/AssessmentSessionCoordinator.js +185 -10
  19. package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
  20. package/dist/core/AutosaveManager.d.ts +104 -0
  21. package/dist/core/AutosaveManager.js +181 -0
  22. package/dist/core/AutosaveManager.js.map +1 -0
  23. package/dist/core/ItemSessionController.d.ts +17 -26
  24. package/dist/core/ItemSessionController.js +33 -73
  25. package/dist/core/ItemSessionController.js.map +1 -1
  26. package/dist/core/NavigationManager.d.ts +18 -50
  27. package/dist/core/NavigationManager.js +21 -83
  28. package/dist/core/NavigationManager.js.map +1 -1
  29. package/dist/core/TimeManager.d.ts +62 -16
  30. package/dist/core/TimeManager.js +148 -57
  31. package/dist/core/TimeManager.js.map +1 -1
  32. package/dist/core/autosave.d.ts +44 -0
  33. package/dist/core/autosave.js +46 -0
  34. package/dist/core/autosave.js.map +1 -0
  35. package/dist/core/deliveryStructure.d.ts +54 -0
  36. package/dist/core/deliveryStructure.js +72 -0
  37. package/dist/core/deliveryStructure.js.map +1 -0
  38. package/dist/core/errors.d.ts +116 -0
  39. package/dist/core/errors.js +77 -0
  40. package/dist/core/errors.js.map +1 -0
  41. package/dist/core/exitBoundaries.d.ts +64 -0
  42. package/dist/core/exitBoundaries.js +98 -0
  43. package/dist/core/exitBoundaries.js.map +1 -0
  44. package/dist/core/feedback.d.ts +46 -0
  45. package/dist/core/feedback.js +47 -0
  46. package/dist/core/feedback.js.map +1 -0
  47. package/dist/core/formatTime.d.ts +8 -0
  48. package/dist/core/formatTime.js +20 -0
  49. package/dist/core/formatTime.js.map +1 -0
  50. package/dist/core/index.d.ts +7 -4
  51. package/dist/core/index.js +4 -1
  52. package/dist/core/index.js.map +1 -1
  53. package/dist/core/navigationPolicy.d.ts +46 -0
  54. package/dist/core/navigationPolicy.js +66 -0
  55. package/dist/core/navigationPolicy.js.map +1 -0
  56. package/dist/core/pause.d.ts +58 -0
  57. package/dist/core/pause.js +101 -0
  58. package/dist/core/pause.js.map +1 -0
  59. package/dist/core/playerEvents.d.ts +51 -0
  60. package/dist/core/playerEvents.js +66 -0
  61. package/dist/core/playerEvents.js.map +1 -0
  62. package/dist/core/reviewState.d.ts +81 -0
  63. package/dist/core/reviewState.js +113 -0
  64. package/dist/core/reviewState.js.map +1 -0
  65. package/dist/core/reviewViews.d.ts +43 -0
  66. package/dist/core/reviewViews.js +88 -0
  67. package/dist/core/reviewViews.js.map +1 -0
  68. package/dist/core/scopeLocks.d.ts +36 -0
  69. package/dist/core/scopeLocks.js +78 -0
  70. package/dist/core/scopeLocks.js.map +1 -0
  71. package/dist/core/sessionRecords.d.ts +31 -0
  72. package/dist/core/sessionRecords.js +74 -0
  73. package/dist/core/sessionRecords.js.map +1 -0
  74. package/dist/core/submissionPolicy.d.ts +65 -0
  75. package/dist/core/submissionPolicy.js +71 -0
  76. package/dist/core/submissionPolicy.js.map +1 -0
  77. package/dist/core/templateDefaults.d.ts +26 -0
  78. package/dist/core/templateDefaults.js +54 -0
  79. package/dist/core/templateDefaults.js.map +1 -0
  80. package/dist/core/testStructure.d.ts +118 -3
  81. package/dist/core/testStructure.js +255 -6
  82. package/dist/core/testStructure.js.map +1 -1
  83. package/dist/core/timePolicy.d.ts +40 -0
  84. package/dist/core/timePolicy.js +106 -0
  85. package/dist/core/timePolicy.js.map +1 -0
  86. package/dist/index.d.ts +7 -4
  87. package/dist/index.js +5 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
  90. package/dist/integration/ReferenceBackendAdapter.js +214 -1033
  91. package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
  92. package/dist/integration/api-contract.d.ts +175 -10
  93. package/dist/integration/api-contract.js.map +1 -1
  94. package/dist/integration/assessment-item-scorer.d.ts +56 -5
  95. package/dist/integration/assessment-item-scorer.js +116 -13
  96. package/dist/integration/assessment-item-scorer.js.map +1 -1
  97. package/dist/integration/index.d.ts +2 -2
  98. package/dist/integration/index.js +1 -1
  99. package/dist/integration/index.js.map +1 -1
  100. package/dist/integration/qti-test-parser.d.ts +44 -0
  101. package/dist/integration/qti-test-parser.js +558 -0
  102. package/dist/integration/qti-test-parser.js.map +1 -0
  103. package/dist/integration/session-store.d.ts +54 -0
  104. package/dist/integration/session-store.js +75 -0
  105. package/dist/integration/session-store.js.map +1 -0
  106. package/dist/integration/test-navigation.d.ts +23 -0
  107. package/dist/integration/test-navigation.js +32 -0
  108. package/dist/integration/test-navigation.js.map +1 -0
  109. package/dist/integration/toSectionComposition.js +8 -1
  110. package/dist/integration/toSectionComposition.js.map +1 -1
  111. package/dist/reporting/index.d.ts +3 -0
  112. package/dist/reporting/index.js +3 -0
  113. package/dist/reporting/index.js.map +1 -0
  114. package/dist/reporting/inferBaseType.d.ts +13 -0
  115. package/dist/reporting/inferBaseType.js +26 -0
  116. package/dist/reporting/inferBaseType.js.map +1 -0
  117. package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
  118. package/dist/reporting/serializeAssessmentResult.js +377 -0
  119. package/dist/reporting/serializeAssessmentResult.js.map +1 -0
  120. package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
  121. package/dist/reporting/toAssessmentResultXml.js +304 -0
  122. package/dist/reporting/toAssessmentResultXml.js.map +1 -0
  123. package/dist/reporting/types.d.ts +85 -0
  124. package/dist/reporting/types.js +8 -0
  125. package/dist/reporting/types.js.map +1 -0
  126. package/dist/types/index.d.ts +96 -9
  127. package/dist/types/index.js.map +1 -1
  128. package/package.json +19 -13
  129. package/dist/core/StatePersistenceManager.d.ts +0 -125
  130. package/dist/core/StatePersistenceManager.js +0 -268
  131. package/dist/core/StatePersistenceManager.js.map +0 -1
  132. package/dist/utils/PerformanceMonitor.d.ts +0 -114
  133. package/dist/utils/PerformanceMonitor.js +0 -172
  134. package/dist/utils/PerformanceMonitor.js.map +0 -1
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The proctor pause state machine.
3
+ *
4
+ * A pause freezes every clock (assessment, test part, section, item) and the live
5
+ * attempt, and candidate actions are rejected with a coded `assessmentPaused` error
6
+ * until resume. A pause requested while a navigation or submission transition is in
7
+ * flight applies once that transition settles. While already paused, a new reason
8
+ * replaces the shown one.
9
+ *
10
+ * Extracted from `AssessmentPlayer.ts` as an independent piece (pure code motion):
11
+ * the controller owns the paused/reason pair; the orchestrator supplies the effects
12
+ * (freeze and unfreeze the clocks and the live attempt) and hears `changed` to fire
13
+ * its `pauseChange` notifications. It never takes the transition lock itself.
14
+ */
15
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
16
+ if (kind === "m") throw new TypeError("Private method is not writable");
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
18
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
19
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
20
+ };
21
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
24
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25
+ };
26
+ var _PauseController_paused, _PauseController_reason, _PauseController_options;
27
+ export class PauseController {
28
+ constructor(options) {
29
+ _PauseController_paused.set(this, false);
30
+ _PauseController_reason.set(this, void 0);
31
+ _PauseController_options.set(this, void 0);
32
+ __classPrivateFieldSet(this, _PauseController_options, options, "f");
33
+ }
34
+ /** Whether a proctor pause is in force. */
35
+ get paused() {
36
+ return __classPrivateFieldGet(this, _PauseController_paused, "f");
37
+ }
38
+ /** The candidate-facing reason given for the current pause, if any. */
39
+ get reason() {
40
+ return __classPrivateFieldGet(this, _PauseController_paused, "f") ? __classPrivateFieldGet(this, _PauseController_reason, "f") : undefined;
41
+ }
42
+ /**
43
+ * Start (or re-reason) a pause. `reason` is host-supplied, candidate-facing text
44
+ * shown with the pause (localize it in the host).
45
+ */
46
+ pause(reason) {
47
+ const nextReason = reason?.trim() || undefined;
48
+ if (__classPrivateFieldGet(this, _PauseController_paused, "f")) {
49
+ if (nextReason !== __classPrivateFieldGet(this, _PauseController_reason, "f")) {
50
+ __classPrivateFieldSet(this, _PauseController_reason, nextReason, "f");
51
+ __classPrivateFieldGet(this, _PauseController_options, "f").changed(__classPrivateFieldGet(this, _PauseController_paused, "f"), this.reason);
52
+ }
53
+ return;
54
+ }
55
+ if (__classPrivateFieldGet(this, _PauseController_options, "f").isBusy()) {
56
+ const off = __classPrivateFieldGet(this, _PauseController_options, "f").onTransitionActivity(() => {
57
+ if (__classPrivateFieldGet(this, _PauseController_options, "f").isBusy())
58
+ return;
59
+ off();
60
+ this.pause(reason);
61
+ });
62
+ return;
63
+ }
64
+ __classPrivateFieldSet(this, _PauseController_paused, true, "f");
65
+ __classPrivateFieldSet(this, _PauseController_reason, nextReason, "f");
66
+ __classPrivateFieldGet(this, _PauseController_options, "f").freeze();
67
+ __classPrivateFieldGet(this, _PauseController_options, "f").changed(__classPrivateFieldGet(this, _PauseController_paused, "f"), this.reason);
68
+ }
69
+ /** End a proctor pause: the clocks continue and the live attempt reopens where it stood. */
70
+ resume() {
71
+ if (!__classPrivateFieldGet(this, _PauseController_paused, "f") || __classPrivateFieldGet(this, _PauseController_options, "f").isDestroyed())
72
+ return;
73
+ __classPrivateFieldSet(this, _PauseController_paused, false, "f");
74
+ __classPrivateFieldSet(this, _PauseController_reason, undefined, "f");
75
+ if (__classPrivateFieldGet(this, _PauseController_options, "f").unfreezeAllowed())
76
+ __classPrivateFieldGet(this, _PauseController_options, "f").unfreeze();
77
+ __classPrivateFieldGet(this, _PauseController_options, "f").changed(__classPrivateFieldGet(this, _PauseController_paused, "f"), this.reason);
78
+ __classPrivateFieldGet(this, _PauseController_options, "f").afterResume();
79
+ }
80
+ /**
81
+ * Adopt a pause carried by a snapshot (a session saved during a pause reopens
82
+ * paused, its clocks frozen). Returns whether the paused state changed, so the
83
+ * caller reports it once.
84
+ */
85
+ setFromRestore(paused, rawReason) {
86
+ const wasPaused = __classPrivateFieldGet(this, _PauseController_paused, "f");
87
+ __classPrivateFieldSet(this, _PauseController_paused, paused, "f");
88
+ __classPrivateFieldSet(this, _PauseController_reason, paused ? rawReason : undefined, "f");
89
+ return wasPaused !== paused;
90
+ }
91
+ /**
92
+ * The session reached its terminal state: the pause no longer holds anything
93
+ * (no pause event — the end of the test is it).
94
+ */
95
+ clearSilently() {
96
+ __classPrivateFieldSet(this, _PauseController_paused, false, "f");
97
+ __classPrivateFieldSet(this, _PauseController_reason, undefined, "f");
98
+ }
99
+ }
100
+ _PauseController_paused = new WeakMap(), _PauseController_reason = new WeakMap(), _PauseController_options = new WeakMap();
101
+ //# sourceMappingURL=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AAC;QACD,uBAAA,IAAI,2BAAW,IAAI,MAAA,CAAC;QACpB,uBAAA,IAAI,2BAAW,UAAU,MAAA,CAAC;QAC1B,uBAAA,IAAI,gCAAS,CAAC,MAAM,EAAE,CAAC;QACvB,uBAAA,IAAI,gCAAS,CAAC,OAAO,CAAC,uBAAA,IAAI,+BAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED,4FAA4F;IAC5F,MAAM;QACL,IAAI,CAAC,uBAAA,IAAI,+BAAQ,IAAI,uBAAA,IAAI,gCAAS,CAAC,WAAW,EAAE;YAAE,OAAO;QACzD,uBAAA,IAAI,2BAAW,KAAK,MAAA,CAAC;QACrB,uBAAA,IAAI,2BAAW,SAAS,MAAA,CAAC;QACzB,IAAI,uBAAA,IAAI,gCAAS,CAAC,eAAe,EAAE;YAAE,uBAAA,IAAI,gCAAS,CAAC,QAAQ,EAAE,CAAC;QAC9D,uBAAA,IAAI,gCAAS,CAAC,OAAO,CAAC,uBAAA,IAAI,+BAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,uBAAA,IAAI,gCAAS,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,MAAe,EAAE,SAA6B;QAC5D,MAAM,SAAS,GAAG,uBAAA,IAAI,+BAAQ,CAAC;QAC/B,uBAAA,IAAI,2BAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAW,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,MAAA,CAAC;QAC9C,OAAO,SAAS,KAAK,MAAM,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,aAAa;QACZ,uBAAA,IAAI,2BAAW,KAAK,MAAA,CAAC;QACrB,uBAAA,IAAI,2BAAW,SAAS,MAAA,CAAC;IAC1B,CAAC;CACD","sourcesContent":["/**\n * The proctor pause state machine.\n *\n * A pause freezes every clock (assessment, test part, section, item) and the live\n * attempt, and candidate actions are rejected with a coded `assessmentPaused` error\n * until resume. A pause requested while a navigation or submission transition is in\n * flight applies once that transition settles. While already paused, a new reason\n * replaces the shown one.\n *\n * Extracted from `AssessmentPlayer.ts` as an independent piece (pure code motion):\n * the controller owns the paused/reason pair; the orchestrator supplies the effects\n * (freeze and unfreeze the clocks and the live attempt) and hears `changed` to fire\n * its `pauseChange` notifications. It never takes the transition lock itself.\n */\n\nexport interface PauseControllerOptions {\n\t/** Whether a navigation or submission transition is in flight right now. */\n\tisBusy: () => boolean;\n\t/** Subscribe to transition activity (used to apply a pause once a transition settles). */\n\tonTransitionActivity: (listener: () => void) => () => void;\n\t/** Freeze every clock and suspend the live attempt. */\n\tfreeze: () => void;\n\t/** Continue the clocks and reopen the live attempt (only when `unfreezeAllowed`). */\n\tunfreeze: () => void;\n\t/** Whether delivery may continue the clocks now (begun, not finalized). */\n\tunfreezeAllowed: () => boolean;\n\t/** The pause started or ended (or, while paused, its reason changed). */\n\tchanged: (paused: boolean, reason?: string) => void;\n\t/** Fires after a resume settled (the player re-checks a restored expiry finalization). */\n\tafterResume: () => void;\n\t/** True once the player is destroyed (resume is a no-op). */\n\tisDestroyed: () => boolean;\n}\n\nexport class PauseController {\n\t#paused = false;\n\t#reason: string | undefined;\n\treadonly #options: PauseControllerOptions;\n\n\tconstructor(options: PauseControllerOptions) {\n\t\tthis.#options = options;\n\t}\n\n\t/** Whether a proctor pause is in force. */\n\tget paused(): boolean {\n\t\treturn this.#paused;\n\t}\n\n\t/** The candidate-facing reason given for the current pause, if any. */\n\tget reason(): string | undefined {\n\t\treturn this.#paused ? this.#reason : undefined;\n\t}\n\n\t/**\n\t * Start (or re-reason) a pause. `reason` is host-supplied, candidate-facing text\n\t * shown with the pause (localize it in the host).\n\t */\n\tpause(reason?: string): void {\n\t\tconst nextReason = reason?.trim() || undefined;\n\t\tif (this.#paused) {\n\t\t\tif (nextReason !== this.#reason) {\n\t\t\t\tthis.#reason = nextReason;\n\t\t\t\tthis.#options.changed(this.#paused, this.reason);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.#options.isBusy()) {\n\t\t\tconst off = this.#options.onTransitionActivity(() => {\n\t\t\t\tif (this.#options.isBusy()) return;\n\t\t\t\toff();\n\t\t\t\tthis.pause(reason);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tthis.#paused = true;\n\t\tthis.#reason = nextReason;\n\t\tthis.#options.freeze();\n\t\tthis.#options.changed(this.#paused, this.reason);\n\t}\n\n\t/** End a proctor pause: the clocks continue and the live attempt reopens where it stood. */\n\tresume(): void {\n\t\tif (!this.#paused || this.#options.isDestroyed()) return;\n\t\tthis.#paused = false;\n\t\tthis.#reason = undefined;\n\t\tif (this.#options.unfreezeAllowed()) this.#options.unfreeze();\n\t\tthis.#options.changed(this.#paused, this.reason);\n\t\tthis.#options.afterResume();\n\t}\n\n\t/**\n\t * Adopt a pause carried by a snapshot (a session saved during a pause reopens\n\t * paused, its clocks frozen). Returns whether the paused state changed, so the\n\t * caller reports it once.\n\t */\n\tsetFromRestore(paused: boolean, rawReason: string | undefined): boolean {\n\t\tconst wasPaused = this.#paused;\n\t\tthis.#paused = paused;\n\t\tthis.#reason = paused ? rawReason : undefined;\n\t\treturn wasPaused !== paused;\n\t}\n\n\t/**\n\t * The session reached its terminal state: the pause no longer holds anything\n\t * (no pause event — the end of the test is it).\n\t */\n\tclearSilently(): void {\n\t\tthis.#paused = false;\n\t\tthis.#reason = undefined;\n\t}\n}\n"]}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Typed event emitter for the assessment player's notifications.
3
+ *
4
+ * Replaces the thirteen per-event listener `Set`s AssessmentPlayer used to hold:
5
+ * insertion-order, synchronous dispatch — listeners run in the order they subscribed,
6
+ * each notification happens in the same synchronous block as before, and a listener
7
+ * that unsubscribes itself (or another not-yet-visited listener) during dispatch takes
8
+ * effect for the remaining listeners, because iteration walks the live set.
9
+ *
10
+ * One listener's exception is isolated (the ItemSession subscriber pattern): it is
11
+ * logged and the remaining listeners still run, and `emit` returns normally — a
12
+ * throwing host callback must never abort the player's own transition (an expiry hop
13
+ * that dies mid-notify would leave its scope locked and the move lost), nor take
14
+ * down unrelated listeners.
15
+ *
16
+ * The player's public `on*` subscription methods keep their exact signatures;
17
+ * the host-config callbacks (`config.onItemChange` &c.) stay in the player's
18
+ * notify helpers, which fire after the listener set exactly as before.
19
+ */
20
+ export type Listener<Args extends unknown[]> = (...args: Args) => void;
21
+ export declare class TypedEventEmitter<Events extends {
22
+ [K in keyof Events]: unknown[];
23
+ }> {
24
+ #private;
25
+ /** Subscribe; returns the unsubscribe function (idempotent). */
26
+ on<K extends keyof Events & string>(event: K, listener: Listener<Events[K]>): () => void;
27
+ /**
28
+ * Call every current listener of `event` with `args`, in subscription order. A
29
+ * throwing listener is logged and skipped: the rest still run and `emit` returns
30
+ * normally.
31
+ */
32
+ emit<K extends keyof Events & string>(event: K, ...args: Events[K]): void;
33
+ /** Drop every listener of every event (teardown). */
34
+ clear(): void;
35
+ }
36
+ /** The player's notification contract: one entry per public `on*` subscription. */
37
+ export interface AssessmentPlayerEventMap {
38
+ itemChange: [index: number, total: number];
39
+ sectionChange: [index: number, totalSections: number];
40
+ responseChange: [responses: Record<string, unknown>];
41
+ complete: [results: import('../types/index.js').AssessmentResults];
42
+ busyChange: [busy: boolean];
43
+ testFeedbackChange: [];
44
+ timeWarning: [remainingSeconds: number];
45
+ timeExpired: [event: import('./AssessmentPlayer.js').AssessmentTimeExpiryEvent];
46
+ scopeTimeExpired: [event: import('./AssessmentPlayer.js').ScopeTimeExpiryEvent];
47
+ pauseChange: [paused: boolean, reason?: string];
48
+ timeTick: [remainingSeconds: number, elapsedSeconds: number];
49
+ flagChange: [itemIdentifier: string, flagged: boolean];
50
+ autosaveChange: [state: import('./AutosaveManager.js').AutosaveState];
51
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Typed event emitter for the assessment player's notifications.
3
+ *
4
+ * Replaces the thirteen per-event listener `Set`s AssessmentPlayer used to hold:
5
+ * insertion-order, synchronous dispatch — listeners run in the order they subscribed,
6
+ * each notification happens in the same synchronous block as before, and a listener
7
+ * that unsubscribes itself (or another not-yet-visited listener) during dispatch takes
8
+ * effect for the remaining listeners, because iteration walks the live set.
9
+ *
10
+ * One listener's exception is isolated (the ItemSession subscriber pattern): it is
11
+ * logged and the remaining listeners still run, and `emit` returns normally — a
12
+ * throwing host callback must never abort the player's own transition (an expiry hop
13
+ * that dies mid-notify would leave its scope locked and the move lost), nor take
14
+ * down unrelated listeners.
15
+ *
16
+ * The player's public `on*` subscription methods keep their exact signatures;
17
+ * the host-config callbacks (`config.onItemChange` &c.) stay in the player's
18
+ * notify helpers, which fire after the listener set exactly as before.
19
+ */
20
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
21
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
22
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
23
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
24
+ };
25
+ var _TypedEventEmitter_sets;
26
+ export class TypedEventEmitter {
27
+ constructor() {
28
+ _TypedEventEmitter_sets.set(this, new Map());
29
+ }
30
+ /** Subscribe; returns the unsubscribe function (idempotent). */
31
+ on(event, listener) {
32
+ let set = __classPrivateFieldGet(this, _TypedEventEmitter_sets, "f").get(event);
33
+ if (!set) {
34
+ set = new Set();
35
+ __classPrivateFieldGet(this, _TypedEventEmitter_sets, "f").set(event, set);
36
+ }
37
+ set.add(listener);
38
+ return () => {
39
+ set.delete(listener);
40
+ };
41
+ }
42
+ /**
43
+ * Call every current listener of `event` with `args`, in subscription order. A
44
+ * throwing listener is logged and skipped: the rest still run and `emit` returns
45
+ * normally.
46
+ */
47
+ emit(event, ...args) {
48
+ const set = __classPrivateFieldGet(this, _TypedEventEmitter_sets, "f").get(event);
49
+ if (!set)
50
+ return;
51
+ for (const listener of set) {
52
+ try {
53
+ listener(...args);
54
+ }
55
+ catch (error) {
56
+ console.error(`[AssessmentPlayer] ${event} listener failed:`, error);
57
+ }
58
+ }
59
+ }
60
+ /** Drop every listener of every event (teardown). */
61
+ clear() {
62
+ __classPrivateFieldGet(this, _TypedEventEmitter_sets, "f").clear();
63
+ }
64
+ }
65
+ _TypedEventEmitter_sets = new WeakMap();
66
+ //# sourceMappingURL=playerEvents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playerEvents.js","sourceRoot":"","sources":["../../src/core/playerEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;;;;;AAIH,MAAM,OAAO,iBAAiB;IAA9B;QACC,kCAAQ,IAAI,GAAG,EAA+C,EAAC;IAoChE,CAAC;IAlCA,gEAAgE;IAChE,EAAE,CAAkC,KAAQ,EAAE,QAA6B;QAC1E,IAAI,GAAG,GAAG,uBAAA,IAAI,+BAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACV,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;YAChB,uBAAA,IAAI,+BAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,QAA2B,CAAC,CAAC;QACrC,OAAO,GAAG,EAAE;YACX,GAAG,CAAC,MAAM,CAAC,QAA2B,CAAC,CAAC;QACzC,CAAC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAkC,KAAQ,EAAE,GAAG,IAAe;QACjE,MAAM,GAAG,GAAG,uBAAA,IAAI,+BAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,KAAK,MAAM,QAAQ,IAAI,GAAG,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,QAAgC,CAAC,GAAG,IAAI,CAAC,CAAC;YAC5C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,sBAAsB,KAAK,mBAAmB,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;QACF,CAAC;IACF,CAAC;IAED,qDAAqD;IACrD,KAAK;QACJ,uBAAA,IAAI,+BAAM,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACD","sourcesContent":["/**\n * Typed event emitter for the assessment player's notifications.\n *\n * Replaces the thirteen per-event listener `Set`s AssessmentPlayer used to hold:\n * insertion-order, synchronous dispatch — listeners run in the order they subscribed,\n * each notification happens in the same synchronous block as before, and a listener\n * that unsubscribes itself (or another not-yet-visited listener) during dispatch takes\n * effect for the remaining listeners, because iteration walks the live set.\n *\n * One listener's exception is isolated (the ItemSession subscriber pattern): it is\n * logged and the remaining listeners still run, and `emit` returns normally — a\n * throwing host callback must never abort the player's own transition (an expiry hop\n * that dies mid-notify would leave its scope locked and the move lost), nor take\n * down unrelated listeners.\n *\n * The player's public `on*` subscription methods keep their exact signatures;\n * the host-config callbacks (`config.onItemChange` &c.) stay in the player's\n * notify helpers, which fire after the listener set exactly as before.\n */\n\nexport type Listener<Args extends unknown[]> = (...args: Args) => void;\n\nexport class TypedEventEmitter<Events extends { [K in keyof Events]: unknown[] }> {\n\t#sets = new Map<keyof Events & string, Set<Listener<never>>>();\n\n\t/** Subscribe; returns the unsubscribe function (idempotent). */\n\ton<K extends keyof Events & string>(event: K, listener: Listener<Events[K]>): () => void {\n\t\tlet set = this.#sets.get(event);\n\t\tif (!set) {\n\t\t\tset = new Set();\n\t\t\tthis.#sets.set(event, set);\n\t\t}\n\t\tset.add(listener as Listener<never>);\n\t\treturn () => {\n\t\t\tset.delete(listener as Listener<never>);\n\t\t};\n\t}\n\n\t/**\n\t * Call every current listener of `event` with `args`, in subscription order. A\n\t * throwing listener is logged and skipped: the rest still run and `emit` returns\n\t * normally.\n\t */\n\temit<K extends keyof Events & string>(event: K, ...args: Events[K]): void {\n\t\tconst set = this.#sets.get(event);\n\t\tif (!set) return;\n\t\tfor (const listener of set) {\n\t\t\ttry {\n\t\t\t\t(listener as Listener<Events[K]>)(...args);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`[AssessmentPlayer] ${event} listener failed:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Drop every listener of every event (teardown). */\n\tclear(): void {\n\t\tthis.#sets.clear();\n\t}\n}\n\n/** The player's notification contract: one entry per public `on*` subscription. */\nexport interface AssessmentPlayerEventMap {\n\titemChange: [index: number, total: number];\n\tsectionChange: [index: number, totalSections: number];\n\tresponseChange: [responses: Record<string, unknown>];\n\tcomplete: [results: import('../types/index.js').AssessmentResults];\n\tbusyChange: [busy: boolean];\n\ttestFeedbackChange: [];\n\ttimeWarning: [remainingSeconds: number];\n\ttimeExpired: [event: import('./AssessmentPlayer.js').AssessmentTimeExpiryEvent];\n\tscopeTimeExpired: [event: import('./AssessmentPlayer.js').ScopeTimeExpiryEvent];\n\tpauseChange: [paused: boolean, reason?: string];\n\ttimeTick: [remainingSeconds: number, elapsedSeconds: number];\n\tflagChange: [itemIdentifier: string, flagged: boolean];\n\tautosaveChange: [state: import('./AutosaveManager.js').AutosaveState];\n}\n"]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Candidate review state: per-item answered status, flag-for-review state, and the
3
+ * review-screen views the shell renders.
4
+ *
5
+ * One place decides what "answered" means so the review screen, the item palette, the
6
+ * section menu and the submit confirmation always agree: a response counts when it is
7
+ * non-null and non-empty (per interaction for composite items, giving
8
+ * answered / partially answered / unanswered).
9
+ */
10
+ /** Candidate-facing answer state of one delivered item. */
11
+ export type ItemAnswerStatus = 'answered' | 'partiallyAnswered' | 'unanswered';
12
+ /** True when a candidate response value carries learner input. */
13
+ export declare function isAnsweredValue(value: unknown): boolean;
14
+ /**
15
+ * Answer state of one item from its responses and its declared interaction response
16
+ * identifiers. A single-interaction item is answered or unanswered; a composite item
17
+ * (several interactions) can also be partially answered.
18
+ */
19
+ export declare function itemAnswerStatus(responses: Record<string, unknown>, responseIdentifiers: readonly string[]): ItemAnswerStatus;
20
+ /**
21
+ * Response identifiers the item's interactions bind to (`responseIdentifier` in QTI 2.x,
22
+ * `response-identifier` in QTI 3.0), in document order, de-duplicated. Non-interaction
23
+ * response declarations (for example template or state variables) are not included.
24
+ * Item XML that fails to parse yields no identifiers — the review facts are display
25
+ * data and must never throw into navigation or shell rendering.
26
+ */
27
+ export declare function interactionResponseIdentifiers(itemXml: string): string[];
28
+ /** The item root's `title` attribute, if any (used by the review screen). */
29
+ export declare function itemTitleFromXml(itemXml: string): string | undefined;
30
+ /**
31
+ * What an interaction asks of its response before it is complete, read from its QTI
32
+ * constraint attributes (QTI 2.x camelCase or QTI 3.0 kebab-case): a minimum number of
33
+ * selections (`minChoices`), text entries (`minStrings`), associations (`minAssociations`)
34
+ * or media plays (`minPlays`). Shells turn it into "Question 2: select at least 2".
35
+ */
36
+ export interface InteractionRequirement {
37
+ kind: 'minChoices' | 'minStrings' | 'minAssociations' | 'minPlays';
38
+ count: number;
39
+ }
40
+ /**
41
+ * The constraint the interaction bound to `responseIdentifier` puts on its response, or
42
+ * undefined when it declares no positive minimum (or the XML does not parse — this is
43
+ * display data and must never throw into delivery).
44
+ */
45
+ export declare function interactionRequirementFromXml(itemXml: string, responseIdentifier: string): InteractionRequirement | undefined;
46
+ /** One delivered item as the review screen and submit confirmation list it. */
47
+ export interface ReviewItemView {
48
+ identifier: string;
49
+ /** Flat delivery index — the argument to `AssessmentPlayer.navigateTo()`. */
50
+ index: number;
51
+ /** 1-based question number across the delivered test. */
52
+ number: number;
53
+ /** Presented (candidate-visible) section; `null` when no enclosing section is visible. */
54
+ sectionId: string | null;
55
+ /** Item title from the item XML root, if any. */
56
+ title?: string;
57
+ /** Answered / partially answered / unanswered. */
58
+ status: ItemAnswerStatus;
59
+ /** Whether the candidate flagged this item for review. */
60
+ flagged: boolean;
61
+ /** Whether the candidate has been presented this item. */
62
+ visited: boolean;
63
+ /**
64
+ * Whether jumping to this item is legal right now (navigationMode, test-part locks,
65
+ * time locks and review policy). Illegal targets render status-only.
66
+ */
67
+ jumpAllowed: boolean;
68
+ /** True for the item currently on screen. */
69
+ isCurrent: boolean;
70
+ }
71
+ /**
72
+ * What the candidate's next forward step would do, so the shell can warn before an
73
+ * irreversible move: QTI test parts are delivered in sequence and, once left, cannot be
74
+ * re-entered — in linear parts nothing can be revisited at all.
75
+ */
76
+ export interface ForwardTransitionInfo {
77
+ /** Flat index of the next reachable item; `null` when no item follows. */
78
+ nextIndex: number | null;
79
+ /** True when the forward step leaves the current test part (parts cannot be re-entered). */
80
+ leavesTestPart: boolean;
81
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Candidate review state: per-item answered status, flag-for-review state, and the
3
+ * review-screen views the shell renders.
4
+ *
5
+ * One place decides what "answered" means so the review screen, the item palette, the
6
+ * section menu and the submit confirmation always agree: a response counts when it is
7
+ * non-null and non-empty (per interaction for composite items, giving
8
+ * answered / partially answered / unanswered).
9
+ */
10
+ import { parseXml } from '@pie-qti/qti-processing';
11
+ /** True when a candidate response value carries learner input. */
12
+ export function isAnsweredValue(value) {
13
+ if (value == null)
14
+ return false;
15
+ if (typeof value === 'string')
16
+ return value.trim().length > 0;
17
+ if (Array.isArray(value))
18
+ return value.some((entry) => isAnsweredValue(entry));
19
+ if (typeof value === 'object') {
20
+ return Object.values(value).some((entry) => isAnsweredValue(entry));
21
+ }
22
+ return true;
23
+ }
24
+ /**
25
+ * Answer state of one item from its responses and its declared interaction response
26
+ * identifiers. A single-interaction item is answered or unanswered; a composite item
27
+ * (several interactions) can also be partially answered.
28
+ */
29
+ export function itemAnswerStatus(responses, responseIdentifiers) {
30
+ const ids = responseIdentifiers.length > 0 ? responseIdentifiers : Object.keys(responses);
31
+ if (ids.length === 0)
32
+ return 'unanswered';
33
+ let answeredCount = 0;
34
+ for (const id of ids) {
35
+ if (isAnsweredValue(responses[id]))
36
+ answeredCount += 1;
37
+ }
38
+ if (answeredCount === 0)
39
+ return 'unanswered';
40
+ if (ids.length > 1 && answeredCount < ids.length)
41
+ return 'partiallyAnswered';
42
+ return 'answered';
43
+ }
44
+ /**
45
+ * Response identifiers the item's interactions bind to (`responseIdentifier` in QTI 2.x,
46
+ * `response-identifier` in QTI 3.0), in document order, de-duplicated. Non-interaction
47
+ * response declarations (for example template or state variables) are not included.
48
+ * Item XML that fails to parse yields no identifiers — the review facts are display
49
+ * data and must never throw into navigation or shell rendering.
50
+ */
51
+ export function interactionResponseIdentifiers(itemXml) {
52
+ let doc;
53
+ try {
54
+ doc = parseXml(itemXml);
55
+ }
56
+ catch {
57
+ return [];
58
+ }
59
+ const seen = new Set();
60
+ const ids = [];
61
+ // Array.from: xmldom's lists are array-like, not iterable.
62
+ for (const element of Array.from(doc.getElementsByTagName('*'))) {
63
+ for (const attribute of ['responseIdentifier', 'response-identifier']) {
64
+ const value = element.getAttribute?.(attribute);
65
+ if (value && !seen.has(value)) {
66
+ seen.add(value);
67
+ ids.push(value);
68
+ }
69
+ }
70
+ }
71
+ return ids;
72
+ }
73
+ const ITEM_ROOT_TITLE = /<(?:[\w-]+:)?(?:qti-assessment-item|assessmentItem)\b[^>]*?\btitle\s*=\s*(?:"([^"]*)"|'([^']*)')/;
74
+ /** The item root's `title` attribute, if any (used by the review screen). */
75
+ export function itemTitleFromXml(itemXml) {
76
+ const match = ITEM_ROOT_TITLE.exec(itemXml);
77
+ const title = (match?.[1] ?? match?.[2] ?? '').trim();
78
+ return title || undefined;
79
+ }
80
+ const REQUIREMENT_ATTRIBUTES = [
81
+ { kind: 'minChoices', names: ['minChoices', 'min-choices'] },
82
+ { kind: 'minAssociations', names: ['minAssociations', 'min-associations'] },
83
+ { kind: 'minStrings', names: ['minStrings', 'min-strings'] },
84
+ { kind: 'minPlays', names: ['minPlays', 'min-plays'] },
85
+ ];
86
+ /**
87
+ * The constraint the interaction bound to `responseIdentifier` puts on its response, or
88
+ * undefined when it declares no positive minimum (or the XML does not parse — this is
89
+ * display data and must never throw into delivery).
90
+ */
91
+ export function interactionRequirementFromXml(itemXml, responseIdentifier) {
92
+ let doc;
93
+ try {
94
+ doc = parseXml(itemXml);
95
+ }
96
+ catch {
97
+ return undefined;
98
+ }
99
+ for (const element of Array.from(doc.getElementsByTagName('*'))) {
100
+ const bound = element.getAttribute?.('responseIdentifier') ?? element.getAttribute?.('response-identifier');
101
+ if (bound !== responseIdentifier)
102
+ continue;
103
+ for (const { kind, names } of REQUIREMENT_ATTRIBUTES) {
104
+ for (const name of names) {
105
+ const count = Number.parseInt(element.getAttribute?.(name) ?? '', 10);
106
+ if (Number.isFinite(count) && count > 0)
107
+ return { kind, count };
108
+ }
109
+ }
110
+ }
111
+ return undefined;
112
+ }
113
+ //# sourceMappingURL=reviewState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewState.js","sourceRoot":"","sources":["../../src/core/reviewState.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAKnD,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAgC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,IAAI,CAA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AAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACjE,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,oBAAoB,CAAC,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,qBAAqB,CAAC,CAAC;QAC5G,IAAI,KAAK,KAAK,kBAAkB;YAAE,SAAS;QAC3C,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,sBAAsB,EAAE,CAAC;YACtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBACtE,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;oBAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YACjE,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Candidate review state: per-item answered status, flag-for-review state, and the\n * review-screen views the shell renders.\n *\n * One place decides what \"answered\" means so the review screen, the item palette, the\n * section menu and the submit confirmation always agree: a response counts when it is\n * non-null and non-empty (per interaction for composite items, giving\n * answered / partially answered / unanswered).\n */\n\nimport { parseXml } from '@pie-qti/qti-processing';\n\n/** Candidate-facing answer state of one delivered item. */\nexport type ItemAnswerStatus = 'answered' | 'partiallyAnswered' | 'unanswered';\n\n/** True when a candidate response value carries learner input. */\nexport function isAnsweredValue(value: unknown): boolean {\n\tif (value == null) return false;\n\tif (typeof value === 'string') return value.trim().length > 0;\n\tif (Array.isArray(value)) return value.some((entry) => isAnsweredValue(entry));\n\tif (typeof value === 'object') {\n\t\treturn Object.values(value as Record<string, unknown>).some((entry) => isAnsweredValue(entry));\n\t}\n\treturn true;\n}\n\n/**\n * Answer state of one item from its responses and its declared interaction response\n * identifiers. A single-interaction item is answered or unanswered; a composite item\n * (several interactions) can also be partially answered.\n */\nexport function itemAnswerStatus(\n\tresponses: Record<string, unknown>,\n\tresponseIdentifiers: readonly string[],\n): ItemAnswerStatus {\n\tconst ids = responseIdentifiers.length > 0 ? responseIdentifiers : Object.keys(responses);\n\tif (ids.length === 0) return 'unanswered';\n\tlet answeredCount = 0;\n\tfor (const id of ids) {\n\t\tif (isAnsweredValue(responses[id])) answeredCount += 1;\n\t}\n\tif (answeredCount === 0) return 'unanswered';\n\tif (ids.length > 1 && answeredCount < ids.length) return 'partiallyAnswered';\n\treturn 'answered';\n}\n\n/**\n * Response identifiers the item's interactions bind to (`responseIdentifier` in QTI 2.x,\n * `response-identifier` in QTI 3.0), in document order, de-duplicated. Non-interaction\n * response declarations (for example template or state variables) are not included.\n * Item XML that fails to parse yields no identifiers — the review facts are display\n * data and must never throw into navigation or shell rendering.\n */\nexport function interactionResponseIdentifiers(itemXml: string): string[] {\n\tlet doc: ReturnType<typeof parseXml>;\n\ttry {\n\t\tdoc = parseXml(itemXml);\n\t} catch {\n\t\treturn [];\n\t}\n\tconst seen = new Set<string>();\n\tconst ids: string[] = [];\n\t// Array.from: xmldom's lists are array-like, not iterable.\n\tfor (const element of Array.from(doc.getElementsByTagName('*'))) {\n\t\tfor (const attribute of ['responseIdentifier', 'response-identifier']) {\n\t\t\tconst value = element.getAttribute?.(attribute);\n\t\t\tif (value && !seen.has(value)) {\n\t\t\t\tseen.add(value);\n\t\t\t\tids.push(value);\n\t\t\t}\n\t\t}\n\t}\n\treturn ids;\n}\n\nconst ITEM_ROOT_TITLE =\n\t/<(?:[\\w-]+:)?(?:qti-assessment-item|assessmentItem)\\b[^>]*?\\btitle\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/;\n\n/** The item root's `title` attribute, if any (used by the review screen). */\nexport function itemTitleFromXml(itemXml: string): string | undefined {\n\tconst match = ITEM_ROOT_TITLE.exec(itemXml);\n\tconst title = (match?.[1] ?? match?.[2] ?? '').trim();\n\treturn title || undefined;\n}\n\n/**\n * What an interaction asks of its response before it is complete, read from its QTI\n * constraint attributes (QTI 2.x camelCase or QTI 3.0 kebab-case): a minimum number of\n * selections (`minChoices`), text entries (`minStrings`), associations (`minAssociations`)\n * or media plays (`minPlays`). Shells turn it into \"Question 2: select at least 2\".\n */\nexport interface InteractionRequirement {\n\tkind: 'minChoices' | 'minStrings' | 'minAssociations' | 'minPlays';\n\tcount: number;\n}\n\nconst REQUIREMENT_ATTRIBUTES: ReadonlyArray<{ kind: InteractionRequirement['kind']; names: readonly string[] }> = [\n\t{ kind: 'minChoices', names: ['minChoices', 'min-choices'] },\n\t{ kind: 'minAssociations', names: ['minAssociations', 'min-associations'] },\n\t{ kind: 'minStrings', names: ['minStrings', 'min-strings'] },\n\t{ kind: 'minPlays', names: ['minPlays', 'min-plays'] },\n];\n\n/**\n * The constraint the interaction bound to `responseIdentifier` puts on its response, or\n * undefined when it declares no positive minimum (or the XML does not parse — this is\n * display data and must never throw into delivery).\n */\nexport function interactionRequirementFromXml(\n\titemXml: string,\n\tresponseIdentifier: string,\n): InteractionRequirement | undefined {\n\tlet doc: ReturnType<typeof parseXml>;\n\ttry {\n\t\tdoc = parseXml(itemXml);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tfor (const element of Array.from(doc.getElementsByTagName('*'))) {\n\t\tconst bound = element.getAttribute?.('responseIdentifier') ?? element.getAttribute?.('response-identifier');\n\t\tif (bound !== responseIdentifier) continue;\n\t\tfor (const { kind, names } of REQUIREMENT_ATTRIBUTES) {\n\t\t\tfor (const name of names) {\n\t\t\t\tconst count = Number.parseInt(element.getAttribute?.(name) ?? '', 10);\n\t\t\t\tif (Number.isFinite(count) && count > 0) return { kind, count };\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** One delivered item as the review screen and submit confirmation list it. */\nexport interface ReviewItemView {\n\tidentifier: string;\n\t/** Flat delivery index — the argument to `AssessmentPlayer.navigateTo()`. */\n\tindex: number;\n\t/** 1-based question number across the delivered test. */\n\tnumber: number;\n\t/** Presented (candidate-visible) section; `null` when no enclosing section is visible. */\n\tsectionId: string | null;\n\t/** Item title from the item XML root, if any. */\n\ttitle?: string;\n\t/** Answered / partially answered / unanswered. */\n\tstatus: ItemAnswerStatus;\n\t/** Whether the candidate flagged this item for review. */\n\tflagged: boolean;\n\t/** Whether the candidate has been presented this item. */\n\tvisited: boolean;\n\t/**\n\t * Whether jumping to this item is legal right now (navigationMode, test-part locks,\n\t * time locks and review policy). Illegal targets render status-only.\n\t */\n\tjumpAllowed: boolean;\n\t/** True for the item currently on screen. */\n\tisCurrent: boolean;\n}\n\n/**\n * What the candidate's next forward step would do, so the shell can warn before an\n * irreversible move: QTI test parts are delivered in sequence and, once left, cannot be\n * re-entered — in linear parts nothing can be revisited at all.\n */\nexport interface ForwardTransitionInfo {\n\t/** Flat index of the next reachable item; `null` when no item follows. */\n\tnextIndex: number | null;\n\t/** True when the forward step leaves the current test part (parts cannot be re-entered). */\n\tleavesTestPart: boolean;\n}\n"]}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Review views: the facts the review screen, section menu and submit confirmation
3
+ * share, assembled from per-item facts the orchestrator resolves.
4
+ *
5
+ * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): the item-XML
6
+ * derived review info cache, the review-list row shape and the completion-summary
7
+ * assembly. "Answered" itself is decided once in `reviewState.itemAnswerStatus`;
8
+ * jump legality comes from `navigationPolicy`. None of this takes the lock.
9
+ */
10
+ import type { FlatItem } from './deliveryStructure.js';
11
+ import { type ItemAnswerStatus, type ReviewItemView } from './reviewState.js';
12
+ import type { AssessmentResults, ResultsSummary } from '../types/index.js';
13
+ /** Item XML–derived review facts (interaction response ids, item title) per item identifier. */
14
+ export declare class ReviewInfoCache {
15
+ #private;
16
+ constructor(items: readonly FlatItem[]);
17
+ for(itemIdentifier: string): {
18
+ responseIds: string[];
19
+ title?: string;
20
+ };
21
+ clear(): void;
22
+ }
23
+ /** One delivered item as the review screen lists it: status, flag, visited, jump legality. */
24
+ export declare function reviewItemRow(item: FlatItem, facts: {
25
+ title?: string;
26
+ status: ItemAnswerStatus;
27
+ flagged: boolean;
28
+ visited: boolean;
29
+ jumpAllowed: boolean;
30
+ isCurrent: boolean;
31
+ }): ReviewItemView;
32
+ /**
33
+ * Candidate-facing results for a shell's opt-in completion summary: per delivered
34
+ * item the answered status and — when the backend returned one — its score, plus the
35
+ * finalized totals. Null until the assessment has been finalized; high-stakes hosts
36
+ * simply never render it (the shell's `showResultsSummary` stays off by default).
37
+ */
38
+ export declare function resultsSummaryOf(options: {
39
+ items: readonly FlatItem[];
40
+ results: AssessmentResults;
41
+ titleOf: (itemIdentifier: string) => string | undefined;
42
+ statusOf: (itemIdentifier: string) => ItemAnswerStatus;
43
+ }): ResultsSummary | null;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Review views: the facts the review screen, section menu and submit confirmation
3
+ * share, assembled from per-item facts the orchestrator resolves.
4
+ *
5
+ * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): the item-XML
6
+ * derived review info cache, the review-list row shape and the completion-summary
7
+ * assembly. "Answered" itself is decided once in `reviewState.itemAnswerStatus`;
8
+ * jump legality comes from `navigationPolicy`. None of this takes the lock.
9
+ */
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ var _ReviewInfoCache_cache, _ReviewInfoCache_items;
22
+ import { interactionResponseIdentifiers, itemTitleFromXml, } from './reviewState.js';
23
+ /** Item XML–derived review facts (interaction response ids, item title) per item identifier. */
24
+ export class ReviewInfoCache {
25
+ constructor(items) {
26
+ _ReviewInfoCache_cache.set(this, new Map());
27
+ _ReviewInfoCache_items.set(this, void 0);
28
+ __classPrivateFieldSet(this, _ReviewInfoCache_items, items, "f");
29
+ }
30
+ for(itemIdentifier) {
31
+ const cached = __classPrivateFieldGet(this, _ReviewInfoCache_cache, "f").get(itemIdentifier);
32
+ if (cached)
33
+ return cached;
34
+ const flat = __classPrivateFieldGet(this, _ReviewInfoCache_items, "f").find((item) => item.identifier === itemIdentifier);
35
+ const info = flat
36
+ ? {
37
+ responseIds: interactionResponseIdentifiers(flat.item.itemXml),
38
+ title: itemTitleFromXml(flat.item.itemXml),
39
+ }
40
+ : { responseIds: [] };
41
+ __classPrivateFieldGet(this, _ReviewInfoCache_cache, "f").set(itemIdentifier, info);
42
+ return info;
43
+ }
44
+ clear() {
45
+ __classPrivateFieldGet(this, _ReviewInfoCache_cache, "f").clear();
46
+ }
47
+ }
48
+ _ReviewInfoCache_cache = new WeakMap(), _ReviewInfoCache_items = new WeakMap();
49
+ /** One delivered item as the review screen lists it: status, flag, visited, jump legality. */
50
+ export function reviewItemRow(item, facts) {
51
+ return {
52
+ identifier: item.identifier,
53
+ index: item.index,
54
+ number: item.index + 1,
55
+ sectionId: item.presentedSection?.identifier ?? null,
56
+ title: facts.title,
57
+ status: facts.status,
58
+ flagged: facts.flagged,
59
+ visited: facts.visited,
60
+ jumpAllowed: facts.jumpAllowed,
61
+ isCurrent: facts.isCurrent,
62
+ };
63
+ }
64
+ /**
65
+ * Candidate-facing results for a shell's opt-in completion summary: per delivered
66
+ * item the answered status and — when the backend returned one — its score, plus the
67
+ * finalized totals. Null until the assessment has been finalized; high-stakes hosts
68
+ * simply never render it (the shell's `showResultsSummary` stays off by default).
69
+ */
70
+ export function resultsSummaryOf(options) {
71
+ const { items, results, titleOf, statusOf } = options;
72
+ const scoreByItem = new Map(results.itemResults.map((result) => [result.itemIdentifier, result]));
73
+ return {
74
+ totalScore: results.totalScore,
75
+ maxScore: results.maxScore,
76
+ items: items.map((item) => {
77
+ const result = scoreByItem.get(item.identifier);
78
+ return {
79
+ identifier: item.identifier,
80
+ number: item.index + 1,
81
+ title: titleOf(item.identifier),
82
+ status: statusOf(item.identifier),
83
+ ...(result ? { score: result.score, maxScore: result.maxScore } : {}),
84
+ };
85
+ }),
86
+ };
87
+ }
88
+ //# sourceMappingURL=reviewViews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewViews.js","sourceRoot":"","sources":["../../src/core/reviewViews.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;;;;;;;;;;;;;AAGH,OAAO,EACN,8BAA8B,EAC9B,gBAAgB,GAGhB,MAAM,kBAAkB,CAAC;AAG1B,gGAAgG;AAChG,MAAM,OAAO,eAAe;IAI3B,YAAY,KAA0B;QAH7B,iCAAS,IAAI,GAAG,EAAqD,EAAC;QACtE,yCAA4B;QAGpC,uBAAA,IAAI,0BAAU,KAAK,MAAA,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,cAAsB;QACzB,MAAM,MAAM,GAAG,uBAAA,IAAI,8BAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC/C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAC1B,MAAM,IAAI,GAAG,uBAAA,IAAI,8BAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,KAAK,cAAc,CAAC,CAAC;QAC5E,MAAM,IAAI,GAAG,IAAI;YAChB,CAAC,CAAC;gBACA,WAAW,EAAE,8BA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,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACzB,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAChD,OAAO;gBACN,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,MAAM,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC;gBACtB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;gBAC/B,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;gBACjC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACrE,CAAC;QACH,CAAC,CAAC;KACF,CAAC;AACH,CAAC","sourcesContent":["/**\n * Review views: the facts the review screen, section menu and submit confirmation\n * share, assembled from per-item facts the orchestrator resolves.\n *\n * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): the item-XML\n * derived review info cache, the review-list row shape and the completion-summary\n * assembly. \"Answered\" itself is decided once in `reviewState.itemAnswerStatus`;\n * jump legality comes from `navigationPolicy`. None of this takes the lock.\n */\n\nimport type { FlatItem } from './deliveryStructure.js';\nimport {\n\tinteractionResponseIdentifiers,\n\titemTitleFromXml,\n\ttype ItemAnswerStatus,\n\ttype ReviewItemView,\n} from './reviewState.js';\nimport type { AssessmentResults, ResultsSummary } from '../types/index.js';\n\n/** Item XML–derived review facts (interaction response ids, item title) per item identifier. */\nexport class ReviewInfoCache {\n\treadonly #cache = new Map<string, { responseIds: string[]; title?: string }>();\n\treadonly #items: readonly FlatItem[];\n\n\tconstructor(items: readonly FlatItem[]) {\n\t\tthis.#items = items;\n\t}\n\n\tfor(itemIdentifier: string): { responseIds: string[]; title?: string } {\n\t\tconst cached = this.#cache.get(itemIdentifier);\n\t\tif (cached) return cached;\n\t\tconst flat = this.#items.find((item) => item.identifier === itemIdentifier);\n\t\tconst info = flat\n\t\t\t? {\n\t\t\t\t\tresponseIds: interactionResponseIdentifiers(flat.item.itemXml),\n\t\t\t\t\ttitle: itemTitleFromXml(flat.item.itemXml),\n\t\t\t\t}\n\t\t\t: { responseIds: [] };\n\t\tthis.#cache.set(itemIdentifier, info);\n\t\treturn info;\n\t}\n\n\tclear(): void {\n\t\tthis.#cache.clear();\n\t}\n}\n\n/** One delivered item as the review screen lists it: status, flag, visited, jump legality. */\nexport function reviewItemRow(\n\titem: FlatItem,\n\tfacts: {\n\t\ttitle?: string;\n\t\tstatus: ItemAnswerStatus;\n\t\tflagged: boolean;\n\t\tvisited: boolean;\n\t\tjumpAllowed: boolean;\n\t\tisCurrent: boolean;\n\t},\n): ReviewItemView {\n\treturn {\n\t\tidentifier: item.identifier,\n\t\tindex: item.index,\n\t\tnumber: item.index + 1,\n\t\tsectionId: item.presentedSection?.identifier ?? null,\n\t\ttitle: facts.title,\n\t\tstatus: facts.status,\n\t\tflagged: facts.flagged,\n\t\tvisited: facts.visited,\n\t\tjumpAllowed: facts.jumpAllowed,\n\t\tisCurrent: facts.isCurrent,\n\t};\n}\n\n/**\n * Candidate-facing results for a shell's opt-in completion summary: per delivered\n * item the answered status and — when the backend returned one — its score, plus the\n * finalized totals. Null until the assessment has been finalized; high-stakes hosts\n * simply never render it (the shell's `showResultsSummary` stays off by default).\n */\nexport function resultsSummaryOf(options: {\n\titems: readonly FlatItem[];\n\tresults: AssessmentResults;\n\ttitleOf: (itemIdentifier: string) => string | undefined;\n\tstatusOf: (itemIdentifier: string) => ItemAnswerStatus;\n}): ResultsSummary | null {\n\tconst { items, results, titleOf, statusOf } = options;\n\tconst scoreByItem = new Map(results.itemResults.map((result) => [result.itemIdentifier, result]));\n\treturn {\n\t\ttotalScore: results.totalScore,\n\t\tmaxScore: results.maxScore,\n\t\titems: items.map((item) => {\n\t\t\tconst result = scoreByItem.get(item.identifier);\n\t\t\treturn {\n\t\t\t\tidentifier: item.identifier,\n\t\t\t\tnumber: item.index + 1,\n\t\t\t\ttitle: titleOf(item.identifier),\n\t\t\t\tstatus: statusOf(item.identifier),\n\t\t\t\t...(result ? { score: result.score, maxScore: result.maxScore } : {}),\n\t\t\t};\n\t\t}),\n\t};\n}\n"]}