@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.6

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 +2835 -460
  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 +42 -0
  54. package/dist/core/navigationPolicy.js +62 -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 +62 -0
  75. package/dist/core/submissionPolicy.js +67 -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 +53 -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 +252 -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 +216 -1035
  91. package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
  92. package/dist/integration/api-contract.d.ts +179 -17
  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 +529 -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 +21 -15
  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 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAyEH;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAElF;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAK/C,YACC,IAA+B,EAC/B,OAAe,EACf,SAAsC,EAAE,EACxC,OAA6B;QAE7B,mFAAmF;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,OAAO,EAAE,KAAK,CAAC;QACpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,6BAA6B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,mFAAmF;IACnF,IAAI,OAAO;QACV,OAAO,2BAA2B,IAAI,CAAC,IAAI,EAAE,CAAC;IAC/C,CAAC;CACD;AAED,yEAAyE;AACzE,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACrD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAiC,CAAC,6BAA6B,CAAC,KAAK,IAAI,CAC1E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACtD,OAAO,CACN,uBAAuB,CAAC,KAAK,CAAC;QAC9B,CAAC,KAAK,CAAC,IAAI,KAAK,0BAA0B;YACzC,KAAK,CAAC,IAAI,KAAK,yBAAyB;YACxC,KAAK,CAAC,IAAI,KAAK,2BAA2B;YAC1C,KAAK,CAAC,IAAI,KAAK,0BAA0B,CAAC,CAC3C,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,SAAS,gBAAgB,CAAC,OAAe;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1E,CAAC;AAeD,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACpD,IAAI,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;IAClF,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO;QACN,OAAO,EAAE,8BAA8B;QACvC,MAAM,EAAE,EAAE;QACV,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC;KACtC,CAAC;AACH,CAAC","sourcesContent":["/**\n * Coded errors thrown by the assessment player core.\n *\n * The core must never surface raw English or backend strings to candidates: every\n * candidate-visible failure carries a stable `code` that shells localize through\n * `@pie-qti/i18n` under `assessment.errors.codes.<code>`. The original message is\n * preserved on the Error itself for logs and host callbacks.\n */\n\n/** Stable machine-readable failure codes. Never rename a code; shells key translations on it. */\nexport type AssessmentPlayerErrorCode =\n\t/** A navigation index or section identifier does not resolve to a deliverable item. */\n\t| 'invalidNavigationTarget'\n\t/** Linear navigation mode only permits moving to the next item. */\n\t| 'linearNavigationOnly'\n\t/** The requested jump is not legal for the current navigation mode or test state. */\n\t| 'navigationNotAllowed'\n\t/** A navigation or submission transition is already in flight. */\n\t| 'navigationInFlight'\n\t/** The assessment has already been finalized; navigation is closed. */\n\t| 'testFinalized'\n\t/** A scoped minimum time has not elapsed. */\n\t| 'minTimeNotElapsed'\n\t/** The target item is locked because its time limit expired. */\n\t| 'itemTimeExpired'\n\t/** The item was submitted and its session control forbids review. */\n\t| 'reviewNotAllowed'\n\t/** The item must be answered before navigation away is allowed. */\n\t| 'responseRequired'\n\t/**\n\t * Ending the test was refused: items in individual parts that do not allow skipping\n\t * still have no response (`params.items` lists their numbers).\n\t */\n\t| 'finalizeResponseRequired'\n\t/**\n\t * Ending the test was refused: items in individual parts that validate responses\n\t * hold responses that do not satisfy their interactions (`params.items`).\n\t */\n\t| 'finalizeResponseInvalid'\n\t/**\n\t * Leaving an individual test part was refused (a left part cannot be re-entered):\n\t * questions in the part that do not allow skipping still have no response\n\t * (`params.items` lists their numbers).\n\t */\n\t| 'leavePartResponseRequired'\n\t/**\n\t * Leaving an individual test part was refused: questions in the part that validate\n\t * responses hold responses that do not satisfy their interactions (`params.items`).\n\t */\n\t| 'leavePartResponseInvalid'\n\t/** Ending the attempt failed response validation. */\n\t| 'attemptValidationFailed'\n\t/** The item's maxAttempts are used up; no further attempt can be submitted. */\n\t| 'maxAttemptsReached'\n\t/** The item session lifecycle forbids response updates. */\n\t| 'itemSessionLocked'\n\t/** The item's session control forbids candidate comments. */\n\t| 'commentsNotAllowed'\n\t/** The backend rejected a response submission. */\n\t| 'submitFailed'\n\t/** The backend failed to finalize the assessment. */\n\t| 'finalizeFailed'\n\t/** A proctor (or the host) paused the assessment; candidate actions are unavailable. */\n\t| 'assessmentPaused'\n\t/** Test-level outcome processing failed on the backend. */\n\t| 'outcomeProcessingFailed'\n\t/**\n\t * A test-scope branch rule or preCondition could not be evaluated (it failed to parse\n\t * or evaluate). Delivery proceeds on the default path (the rule reads as false) and the\n\t * host is informed, so a broken rule is never indistinguishable from an authored false.\n\t */\n\t| 'testConditionFailed'\n\t/** Item response processing failed; the item scores 0 and delivery continues. */\n\t| 'itemScoringFailed'\n\t/** Anything else: shells show a generic localized message plus a support code. */\n\t| 'unexpected';\n\n/** Parameters interpolated into the localized message for a coded error. */\nexport type AssessmentPlayerErrorParams = Record<string, string | number>;\n\n/**\n * Brand on every `AssessmentPlayerError`, which `isAssessmentPlayerError` checks instead of\n * `instanceof`: an error often crosses copies of this module (the player-elements bundle\n * carries its own; a host may load this package beside it), and `Symbol.for` gives every\n * copy the same symbol.\n */\nconst ASSESSMENT_PLAYER_ERROR_BRAND = Symbol.for('pie-qti.AssessmentPlayerError');\n\n/**\n * Error thrown (or returned as a typed rejection) by the assessment player core.\n *\n * `message` keeps the original, developer-facing text (including raw backend error\n * strings) for logs and host callbacks; `code` and `params` drive the localized,\n * candidate-safe rendering in the shell. Recognize one with `isAssessmentPlayerError`,\n * not `instanceof`, which fails for an error made by another copy of the package.\n */\nexport class AssessmentPlayerError extends Error {\n\treadonly code: AssessmentPlayerErrorCode;\n\treadonly params: AssessmentPlayerErrorParams;\n\treadonly originalError?: unknown;\n\n\tconstructor(\n\t\tcode: AssessmentPlayerErrorCode,\n\t\tmessage: string,\n\t\tparams: AssessmentPlayerErrorParams = {},\n\t\toptions?: { cause?: unknown },\n\t) {\n\t\t// No ErrorOptions argument: svelte-check's lib config predates ES2022 Error cause.\n\t\tsuper(message);\n\t\tthis.name = 'AssessmentPlayerError';\n\t\tthis.code = code;\n\t\tthis.params = params;\n\t\tthis.originalError = options?.cause;\n\t\tObject.defineProperty(this, ASSESSMENT_PLAYER_ERROR_BRAND, { value: true });\n\t}\n\n\t/** i18n key the shell renders this error through (`assessment.errors.codes.*`). */\n\tget i18nKey(): string {\n\t\treturn `assessment.errors.codes.${this.code}`;\n\t}\n}\n\n/** True for an `AssessmentPlayerError` from any copy of this package. */\nexport function isAssessmentPlayerError(error: unknown): error is AssessmentPlayerError {\n\treturn (\n\t\ttypeof error === 'object' &&\n\t\terror !== null &&\n\t\t(error as Record<symbol, unknown>)[ASSESSMENT_PLAYER_ERROR_BRAND] === true\n\t);\n}\n\n/**\n * The coded refusals that name questions still needing an answer (or a complete one):\n * the end of the test, or leaving an individual test part. They are warnings the\n * candidate resolves by answering, never failures to retry.\n */\nexport function isSubmissionBlockedError(error: unknown): error is AssessmentPlayerError {\n\treturn (\n\t\tisAssessmentPlayerError(error) &&\n\t\t(error.code === 'finalizeResponseRequired' ||\n\t\t\terror.code === 'finalizeResponseInvalid' ||\n\t\t\terror.code === 'leavePartResponseRequired' ||\n\t\t\terror.code === 'leavePartResponseInvalid')\n\t);\n}\n\n/** Deterministic short support code for an arbitrary (non-coded) error message. */\nfunction shortSupportCode(message: string): string {\n\tlet hash = 0;\n\tconst source = message.slice(0, 256);\n\tfor (let i = 0; i < source.length; i++) {\n\t\thash = (hash * 31 + source.charCodeAt(i)) >>> 0;\n\t}\n\treturn `E-${hash.toString(36).toUpperCase().padStart(6, '0').slice(-6)}`;\n}\n\n/**\n * Candidate-safe rendering plan for any error the core (or a backend) produced.\n *\n * `i18nKey`/`params` resolve to a friendly localized message; `supportCode` is a\n * short stable code the shell may append so hosts can correlate reports without\n * ever showing raw backend messages to candidates.\n */\nexport interface AssessmentErrorDisplay {\n\ti18nKey: string;\n\tparams: AssessmentPlayerErrorParams;\n\tsupportCode: string;\n}\n\nexport function assessmentErrorDisplay(error: unknown): AssessmentErrorDisplay {\n\tif (isAssessmentPlayerError(error)) {\n\t\treturn { i18nKey: error.i18nKey, params: error.params, supportCode: error.code };\n\t}\n\tconst message = error instanceof Error ? error.message : String(error);\n\treturn {\n\t\ti18nKey: 'assessment.errors.unexpected',\n\t\tparams: {},\n\t\tsupportCode: shortSupportCode(message),\n\t};\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Exit-boundary resolution for branch decisions.
3
+ *
4
+ * Where a QTI branch rule's `EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION` (or a
5
+ * plain item target) lands in the delivered sequence. Extracted from
6
+ * `AssessmentPlayer.ts` as pure functions over the flat delivery — no lock, no session
7
+ * state; what the orchestrator then *does* with the resolved boundary (flush the part,
8
+ * navigate, end the test) stays with it. No longer a verbatim copy: the literal-target
9
+ * semantics have since been deliberately aligned with the reference backend —
10
+ * forward-only resolution through the shared `firstForwardBranchTarget`, and one
11
+ * landing policy for every consumer (`branchLandingOf`: an EXIT_* is the landing, an
12
+ * unresolvable literal is skipped).
13
+ */
14
+ import type { SecureSection } from '../integration/api-contract.js';
15
+ import type { FlatItem } from './deliveryStructure.js';
16
+ /**
17
+ * The enclosing section a literal EXIT_SECTION leaves: the innermost section, walked
18
+ * outward while the next enclosing one also ends with the current item — a branch rule
19
+ * on an outer section fires at its last item, where the whole outer boundary closes, so
20
+ * the EXIT lands outside the entire outer section, not just outside the innermost one.
21
+ */
22
+ export declare function endedEnclosingSection(current: FlatItem, items: readonly FlatItem[], currentIndex: number): SecureSection;
23
+ /**
24
+ * Where a branch decision lands: an item index, or -1 when it ends the test or resolves to
25
+ * nothing forward. Literal targets resolve forward-only (QTI 2.2 §5.15: the target must refer
26
+ * to an item or section that has not yet been presented — a delivered test never re-enters an
27
+ * earlier one) through the same shared resolver the reference backend uses
28
+ * (`firstForwardBranchTarget`), so identical XML branches identically on the backend path. An
29
+ * unresolvable literal — e.g. a backward target with no later occurrence — is skipped: the
30
+ * delivery rules decide from the next item, as when the backend leaves the rule unfired.
31
+ */
32
+ export declare function branchTargetIndex(q: FlatItem, target: string, items: readonly FlatItem[], currentIndex: number): number;
33
+ /**
34
+ * How a branch decision lands in the delivery once `branchTargetIndex` has resolved it —
35
+ * the one statement of the policy every consumer shares:
36
+ *
37
+ * - `{ kind: 'item', index }` — the decision names a forward item: delivery hops there.
38
+ * - `{ kind: 'exit' }` — an `EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION`: the exit itself
39
+ * is the landing; boundary handling ends the scope or the test (a resolved index of -1
40
+ * never navigates).
41
+ * - `{ kind: 'skipped' }` — a literal target with no forward occurrence: the rule does not
42
+ * fire, and the delivery rules decide from the next item, as when the backend leaves the
43
+ * rule unfired.
44
+ */
45
+ export type BranchLanding = {
46
+ readonly kind: 'item';
47
+ readonly index: number;
48
+ } | {
49
+ readonly kind: 'exit';
50
+ } | {
51
+ readonly kind: 'skipped';
52
+ };
53
+ /** Classify a resolved branch decision (see `BranchLanding`). */
54
+ export declare function branchLandingOf(target: string, resolvedIndex: number): BranchLanding;
55
+ /** Whether a branch decision takes delivery out of the item's test part (or ends the test). */
56
+ export declare function branchExitLeavesPart(q: FlatItem, target: string, items: readonly FlatItem[], currentIndex: number): boolean;
57
+ /**
58
+ * The first delivered item an EXIT_TESTPART / EXIT_SECTION boundary leaves, or -1 when
59
+ * nothing follows (the test ends). The literal resolves over the item's full enclosing
60
+ * chain (like the backend's branch-rule walk), not the innermost section alone: an
61
+ * outer-section EXIT lands outside the whole outer section — and when nothing follows
62
+ * the section inside its test part, the part ends too.
63
+ */
64
+ export declare function resolveExitBoundary(special: 'EXIT_TESTPART' | 'EXIT_SECTION', current: FlatItem, items: readonly FlatItem[], currentIndex: number): number;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Exit-boundary resolution for branch decisions.
3
+ *
4
+ * Where a QTI branch rule's `EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION` (or a
5
+ * plain item target) lands in the delivered sequence. Extracted from
6
+ * `AssessmentPlayer.ts` as pure functions over the flat delivery — no lock, no session
7
+ * state; what the orchestrator then *does* with the resolved boundary (flush the part,
8
+ * navigate, end the test) stays with it. No longer a verbatim copy: the literal-target
9
+ * semantics have since been deliberately aligned with the reference backend —
10
+ * forward-only resolution through the shared `firstForwardBranchTarget`, and one
11
+ * landing policy for every consumer (`branchLandingOf`: an EXIT_* is the landing, an
12
+ * unresolvable literal is skipped).
13
+ */
14
+ import { firstForwardBranchTarget } from './testStructure.js';
15
+ /**
16
+ * The enclosing section a literal EXIT_SECTION leaves: the innermost section, walked
17
+ * outward while the next enclosing one also ends with the current item — a branch rule
18
+ * on an outer section fires at its last item, where the whole outer boundary closes, so
19
+ * the EXIT lands outside the entire outer section, not just outside the innermost one.
20
+ */
21
+ export function endedEnclosingSection(current, items, currentIndex) {
22
+ let ended = current.section;
23
+ for (let level = current.sections.length - 2; level >= 0; level--) {
24
+ const section = current.sections[level];
25
+ const continues = items.some((item, i) => i > currentIndex && item.sections.some((s) => s.identifier === section.identifier));
26
+ if (continues)
27
+ break;
28
+ ended = section;
29
+ }
30
+ return ended;
31
+ }
32
+ /**
33
+ * Where a branch decision lands: an item index, or -1 when it ends the test or resolves to
34
+ * nothing forward. Literal targets resolve forward-only (QTI 2.2 §5.15: the target must refer
35
+ * to an item or section that has not yet been presented — a delivered test never re-enters an
36
+ * earlier one) through the same shared resolver the reference backend uses
37
+ * (`firstForwardBranchTarget`), so identical XML branches identically on the backend path. An
38
+ * unresolvable literal — e.g. a backward target with no later occurrence — is skipped: the
39
+ * delivery rules decide from the next item, as when the backend leaves the rule unfired.
40
+ */
41
+ export function branchTargetIndex(q, target, items, currentIndex) {
42
+ if (target === 'EXIT_TEST')
43
+ return -1;
44
+ if (target === 'EXIT_TESTPART') {
45
+ return items.findIndex((item, i) => i > q.index && item.testPart !== q.testPart);
46
+ }
47
+ if (target === 'EXIT_SECTION') {
48
+ const exited = endedEnclosingSection(q, items, currentIndex);
49
+ const inside = items.findIndex((item, i) => i > q.index && !item.sections.some((section) => section.identifier === exited.identifier));
50
+ return inside >= 0 ? inside : items.findIndex((item, i) => i > q.index && item.testPart !== q.testPart);
51
+ }
52
+ return firstForwardBranchTarget(target, items, q.index) ?? -1;
53
+ }
54
+ /** Classify a resolved branch decision (see `BranchLanding`). */
55
+ export function branchLandingOf(target, resolvedIndex) {
56
+ if (resolvedIndex >= 0)
57
+ return { kind: 'item', index: resolvedIndex };
58
+ return isExitBranchTarget(target) ? { kind: 'exit' } : { kind: 'skipped' };
59
+ }
60
+ /** Whether a branch rule target exits a scope (`EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION`) rather than naming an item. */
61
+ function isExitBranchTarget(target) {
62
+ return target === 'EXIT_TEST' || target === 'EXIT_TESTPART' || target === 'EXIT_SECTION';
63
+ }
64
+ /** Whether a branch decision takes delivery out of the item's test part (or ends the test). */
65
+ export function branchExitLeavesPart(q, target, items, currentIndex) {
66
+ const landing = branchLandingOf(target, branchTargetIndex(q, target, items, currentIndex));
67
+ switch (landing.kind) {
68
+ case 'exit':
69
+ // EXIT_TEST ends the test; an EXIT_* boundary nothing follows ends the part anyway.
70
+ return true;
71
+ case 'item':
72
+ return items[landing.index].testPart !== q.testPart;
73
+ case 'skipped':
74
+ // The rule does not fire (the backend falls through to the next item), so it
75
+ // crosses no part boundary.
76
+ return false;
77
+ }
78
+ }
79
+ /**
80
+ * The first delivered item an EXIT_TESTPART / EXIT_SECTION boundary leaves, or -1 when
81
+ * nothing follows (the test ends). The literal resolves over the item's full enclosing
82
+ * chain (like the backend's branch-rule walk), not the innermost section alone: an
83
+ * outer-section EXIT lands outside the whole outer section — and when nothing follows
84
+ * the section inside its test part, the part ends too.
85
+ */
86
+ export function resolveExitBoundary(special, current, items, currentIndex) {
87
+ const exitedSection = special === 'EXIT_SECTION' ? endedEnclosingSection(current, items, currentIndex) : undefined;
88
+ let nextIdx = items.findIndex((item, i) => i > currentIndex &&
89
+ (exitedSection
90
+ ? !item.sections.some((section) => section.identifier === exitedSection.identifier)
91
+ : item.testPart.identifier !== current.testPart.identifier));
92
+ if (exitedSection && nextIdx < 0) {
93
+ // Nothing follows the section inside this test part: the part ends too.
94
+ nextIdx = items.findIndex((item, i) => i > currentIndex && item.testPart !== current.testPart);
95
+ }
96
+ return nextIdx;
97
+ }
98
+ //# sourceMappingURL=exitBoundaries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitBoundaries.js","sourceRoot":"","sources":["../../src/core/exitBoundaries.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Exit-boundary resolution for branch decisions.\n *\n * Where a QTI branch rule's `EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION` (or a\n * plain item target) lands in the delivered sequence. Extracted from\n * `AssessmentPlayer.ts` as pure functions over the flat delivery — no lock, no session\n * state; what the orchestrator then *does* with the resolved boundary (flush the part,\n * navigate, end the test) stays with it. No longer a verbatim copy: the literal-target\n * semantics have since been deliberately aligned with the reference backend —\n * forward-only resolution through the shared `firstForwardBranchTarget`, and one\n * landing policy for every consumer (`branchLandingOf`: an EXIT_* is the landing, an\n * unresolvable literal is skipped).\n */\n\nimport type { SecureSection } from '../integration/api-contract.js';\nimport type { FlatItem } from './deliveryStructure.js';\nimport { firstForwardBranchTarget } from './testStructure.js';\n\n/**\n * The enclosing section a literal EXIT_SECTION leaves: the innermost section, walked\n * outward while the next enclosing one also ends with the current item — a branch rule\n * on an outer section fires at its last item, where the whole outer boundary closes, so\n * the EXIT lands outside the entire outer section, not just outside the innermost one.\n */\nexport function endedEnclosingSection(\n\tcurrent: FlatItem,\n\titems: readonly FlatItem[],\n\tcurrentIndex: number,\n): SecureSection {\n\tlet ended = current.section;\n\tfor (let level = current.sections.length - 2; level >= 0; level--) {\n\t\tconst section = current.sections[level]!;\n\t\tconst continues = items.some(\n\t\t\t(item, i) => i > currentIndex && item.sections.some((s) => s.identifier === section.identifier),\n\t\t);\n\t\tif (continues) break;\n\t\tended = section;\n\t}\n\treturn ended;\n}\n\n/**\n * Where a branch decision lands: an item index, or -1 when it ends the test or resolves to\n * nothing forward. Literal targets resolve forward-only (QTI 2.2 §5.15: the target must refer\n * to an item or section that has not yet been presented — a delivered test never re-enters an\n * earlier one) through the same shared resolver the reference backend uses\n * (`firstForwardBranchTarget`), so identical XML branches identically on the backend path. An\n * unresolvable literal — e.g. a backward target with no later occurrence — is skipped: the\n * delivery rules decide from the next item, as when the backend leaves the rule unfired.\n */\nexport function branchTargetIndex(\n\tq: FlatItem,\n\ttarget: string,\n\titems: readonly FlatItem[],\n\tcurrentIndex: number,\n): number {\n\tif (target === 'EXIT_TEST') return -1;\n\tif (target === 'EXIT_TESTPART') {\n\t\treturn items.findIndex((item, i) => i > q.index && item.testPart !== q.testPart);\n\t}\n\tif (target === 'EXIT_SECTION') {\n\t\tconst exited = endedEnclosingSection(q, items, currentIndex);\n\t\tconst inside = items.findIndex(\n\t\t\t(item, i) => i > q.index && !item.sections.some((section) => section.identifier === exited.identifier),\n\t\t);\n\t\treturn inside >= 0 ? inside : items.findIndex((item, i) => i > q.index && item.testPart !== q.testPart);\n\t}\n\treturn firstForwardBranchTarget(target, items, q.index) ?? -1;\n}\n\n/**\n * How a branch decision lands in the delivery once `branchTargetIndex` has resolved it —\n * the one statement of the policy every consumer shares:\n *\n * - `{ kind: 'item', index }` — the decision names a forward item: delivery hops there.\n * - `{ kind: 'exit' }` — an `EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION`: the exit itself\n * is the landing; boundary handling ends the scope or the test (a resolved index of -1\n * never navigates).\n * - `{ kind: 'skipped' }` — a literal target with no forward occurrence: the rule does not\n * fire, and the delivery rules decide from the next item, as when the backend leaves the\n * rule unfired.\n */\nexport type BranchLanding =\n\t| { readonly kind: 'item'; readonly index: number }\n\t| { readonly kind: 'exit' }\n\t| { readonly kind: 'skipped' };\n\n/** Classify a resolved branch decision (see `BranchLanding`). */\nexport function branchLandingOf(target: string, resolvedIndex: number): BranchLanding {\n\tif (resolvedIndex >= 0) return { kind: 'item', index: resolvedIndex };\n\treturn isExitBranchTarget(target) ? { kind: 'exit' } : { kind: 'skipped' };\n}\n\n/** Whether a branch rule target exits a scope (`EXIT_TEST` / `EXIT_TESTPART` / `EXIT_SECTION`) rather than naming an item. */\nfunction isExitBranchTarget(target: string): boolean {\n\treturn target === 'EXIT_TEST' || target === 'EXIT_TESTPART' || target === 'EXIT_SECTION';\n}\n\n/** Whether a branch decision takes delivery out of the item's test part (or ends the test). */\nexport function branchExitLeavesPart(\n\tq: FlatItem,\n\ttarget: string,\n\titems: readonly FlatItem[],\n\tcurrentIndex: number,\n): boolean {\n\tconst landing = branchLandingOf(target, branchTargetIndex(q, target, items, currentIndex));\n\tswitch (landing.kind) {\n\t\tcase 'exit':\n\t\t\t// EXIT_TEST ends the test; an EXIT_* boundary nothing follows ends the part anyway.\n\t\t\treturn true;\n\t\tcase 'item':\n\t\t\treturn items[landing.index]!.testPart !== q.testPart;\n\t\tcase 'skipped':\n\t\t\t// The rule does not fire (the backend falls through to the next item), so it\n\t\t\t// crosses no part boundary.\n\t\t\treturn false;\n\t}\n}\n\n/**\n * The first delivered item an EXIT_TESTPART / EXIT_SECTION boundary leaves, or -1 when\n * nothing follows (the test ends). The literal resolves over the item's full enclosing\n * chain (like the backend's branch-rule walk), not the innermost section alone: an\n * outer-section EXIT lands outside the whole outer section — and when nothing follows\n * the section inside its test part, the part ends too.\n */\nexport function resolveExitBoundary(\n\tspecial: 'EXIT_TESTPART' | 'EXIT_SECTION',\n\tcurrent: FlatItem,\n\titems: readonly FlatItem[],\n\tcurrentIndex: number,\n): number {\n\tconst exitedSection = special === 'EXIT_SECTION' ? endedEnclosingSection(current, items, currentIndex) : undefined;\n\tlet nextIdx = items.findIndex((item, i) =>\n\t\ti > currentIndex &&\n\t\t(exitedSection\n\t\t\t? !item.sections.some((section) => section.identifier === exitedSection.identifier)\n\t\t\t: item.testPart.identifier !== current.testPart.identifier),\n\t);\n\tif (exitedSection && nextIdx < 0) {\n\t\t// Nothing follows the section inside this test part: the part ends too.\n\t\tnextIdx = items.findIndex(\n\t\t\t(item, i) => i > currentIndex && item.testPart !== current.testPart,\n\t\t);\n\t}\n\treturn nextIdx;\n}\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * QTI attempt-relative feedback visibility.
3
+ *
4
+ * QTI is attempt-relative here: with more than one attempt allowed (or unlimited
5
+ * attempts, adaptive items), feedback for every non-final attempt must be shown; once
6
+ * the last attempt has ended, `itemSessionControl@showFeedback` governs. An adaptive
7
+ * item always shows its feedback.
8
+ *
9
+ * Two rules in the player apply this shape and feed different outputs, and they differ
10
+ * on purpose (see the table test in `tests/feedback-visibility.test.ts`):
11
+ *
12
+ * 1. `AssessmentPlayer.feedbackVisible` — the live item session's presentation policy
13
+ * and the shell's captured item feedback. This is the semantics these helpers
14
+ * implement: an adaptive item (read from the item XML) or `showFeedback` shows
15
+ * feedback whatever the attempts have done so far, and the caller judges a
16
+ * *projected* attempt count (`attemptsAfter`: the counted attempts once the attempt
17
+ * being judged has ended). Unlimited attempts are represented as `null` maxAttempts.
18
+ * 2. `ItemSessionController.shouldShowFeedback` — `getItemSessionInfo().showFeedback`.
19
+ * It keeps its own wrapper: nothing is visible before the item's first submission,
20
+ * the count is the *live* recorded count, and an adaptive item is unlimited only
21
+ * through its resolved settings (`resolveItemSessionControl` zeroes `maxAttempts`),
22
+ * because the session controller sees settings, never item XML.
23
+ */
24
+ import type { ItemSessionControlSettings } from './ItemSessionController.js';
25
+ /**
26
+ * The item's maximum attempts for the attempt-relative rules: null when unlimited —
27
+ * an adaptive item, or an authored `maxAttempts` of 0 — otherwise at least 1.
28
+ */
29
+ export declare function resolveMaxAttempts(settings: Pick<ItemSessionControlSettings, 'maxAttempts'> | undefined, adaptive: boolean): number | null;
30
+ export interface AttemptFeedbackVisibility {
31
+ /** The item's `itemSessionControl@showFeedback`. */
32
+ showFeedback: boolean | undefined;
33
+ /** From `resolveMaxAttempts`; null when unlimited. */
34
+ maxAttempts: number | null;
35
+ /** The counted attempts of the state being judged. */
36
+ attempts: number;
37
+ /** The item root declares `adaptive="true"`. */
38
+ adaptive: boolean;
39
+ }
40
+ /**
41
+ * QTI feedback visibility for a submission's or a presentation's attempt state:
42
+ * an adaptive item or `showFeedback` shows feedback whatever the attempts; otherwise
43
+ * a non-final attempt does (`attempts` below the maximum, or unlimited) and a final
44
+ * or single attempt does not.
45
+ */
46
+ export declare function attemptFeedbackVisible({ showFeedback, maxAttempts, attempts, adaptive }: AttemptFeedbackVisibility): boolean;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * QTI attempt-relative feedback visibility.
3
+ *
4
+ * QTI is attempt-relative here: with more than one attempt allowed (or unlimited
5
+ * attempts, adaptive items), feedback for every non-final attempt must be shown; once
6
+ * the last attempt has ended, `itemSessionControl@showFeedback` governs. An adaptive
7
+ * item always shows its feedback.
8
+ *
9
+ * Two rules in the player apply this shape and feed different outputs, and they differ
10
+ * on purpose (see the table test in `tests/feedback-visibility.test.ts`):
11
+ *
12
+ * 1. `AssessmentPlayer.feedbackVisible` — the live item session's presentation policy
13
+ * and the shell's captured item feedback. This is the semantics these helpers
14
+ * implement: an adaptive item (read from the item XML) or `showFeedback` shows
15
+ * feedback whatever the attempts have done so far, and the caller judges a
16
+ * *projected* attempt count (`attemptsAfter`: the counted attempts once the attempt
17
+ * being judged has ended). Unlimited attempts are represented as `null` maxAttempts.
18
+ * 2. `ItemSessionController.shouldShowFeedback` — `getItemSessionInfo().showFeedback`.
19
+ * It keeps its own wrapper: nothing is visible before the item's first submission,
20
+ * the count is the *live* recorded count, and an adaptive item is unlimited only
21
+ * through its resolved settings (`resolveItemSessionControl` zeroes `maxAttempts`),
22
+ * because the session controller sees settings, never item XML.
23
+ */
24
+ /**
25
+ * The item's maximum attempts for the attempt-relative rules: null when unlimited —
26
+ * an adaptive item, or an authored `maxAttempts` of 0 — otherwise at least 1.
27
+ */
28
+ export function resolveMaxAttempts(settings, adaptive) {
29
+ if (adaptive)
30
+ return null;
31
+ const maxAttempts = settings?.maxAttempts ?? 1;
32
+ return maxAttempts === 0 ? null : Math.max(1, maxAttempts);
33
+ }
34
+ /**
35
+ * QTI feedback visibility for a submission's or a presentation's attempt state:
36
+ * an adaptive item or `showFeedback` shows feedback whatever the attempts; otherwise
37
+ * a non-final attempt does (`attempts` below the maximum, or unlimited) and a final
38
+ * or single attempt does not.
39
+ */
40
+ export function attemptFeedbackVisible({ showFeedback, maxAttempts, attempts, adaptive }) {
41
+ if (adaptive || showFeedback === true)
42
+ return true;
43
+ if (attempts < 1)
44
+ return false;
45
+ return maxAttempts === null || (maxAttempts > 1 && attempts < maxAttempts);
46
+ }
47
+ //# sourceMappingURL=feedback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback.js","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,QAAqE,EACrE,QAAiB;IAEjB,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1B,MAAM,WAAW,GAAG,QAAQ,EAAE,WAAW,IAAI,CAAC,CAAC;IAC/C,OAAO,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAC5D,CAAC;AAaD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAA6B;IAClH,IAAI,QAAQ,IAAI,YAAY,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,WAAW,KAAK,IAAI,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,QAAQ,GAAG,WAAW,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * QTI attempt-relative feedback visibility.\n *\n * QTI is attempt-relative here: with more than one attempt allowed (or unlimited\n * attempts, adaptive items), feedback for every non-final attempt must be shown; once\n * the last attempt has ended, `itemSessionControl@showFeedback` governs. An adaptive\n * item always shows its feedback.\n *\n * Two rules in the player apply this shape and feed different outputs, and they differ\n * on purpose (see the table test in `tests/feedback-visibility.test.ts`):\n *\n * 1. `AssessmentPlayer.feedbackVisible` — the live item session's presentation policy\n * and the shell's captured item feedback. This is the semantics these helpers\n * implement: an adaptive item (read from the item XML) or `showFeedback` shows\n * feedback whatever the attempts have done so far, and the caller judges a\n * *projected* attempt count (`attemptsAfter`: the counted attempts once the attempt\n * being judged has ended). Unlimited attempts are represented as `null` maxAttempts.\n * 2. `ItemSessionController.shouldShowFeedback` — `getItemSessionInfo().showFeedback`.\n * It keeps its own wrapper: nothing is visible before the item's first submission,\n * the count is the *live* recorded count, and an adaptive item is unlimited only\n * through its resolved settings (`resolveItemSessionControl` zeroes `maxAttempts`),\n * because the session controller sees settings, never item XML.\n */\n\nimport type { ItemSessionControlSettings } from './ItemSessionController.js';\n\n/**\n * The item's maximum attempts for the attempt-relative rules: null when unlimited —\n * an adaptive item, or an authored `maxAttempts` of 0 — otherwise at least 1.\n */\nexport function resolveMaxAttempts(\n\tsettings: Pick<ItemSessionControlSettings, 'maxAttempts'> | undefined,\n\tadaptive: boolean,\n): number | null {\n\tif (adaptive) return null;\n\tconst maxAttempts = settings?.maxAttempts ?? 1;\n\treturn maxAttempts === 0 ? null : Math.max(1, maxAttempts);\n}\n\nexport interface AttemptFeedbackVisibility {\n\t/** The item's `itemSessionControl@showFeedback`. */\n\tshowFeedback: boolean | undefined;\n\t/** From `resolveMaxAttempts`; null when unlimited. */\n\tmaxAttempts: number | null;\n\t/** The counted attempts of the state being judged. */\n\tattempts: number;\n\t/** The item root declares `adaptive=\"true\"`. */\n\tadaptive: boolean;\n}\n\n/**\n * QTI feedback visibility for a submission's or a presentation's attempt state:\n * an adaptive item or `showFeedback` shows feedback whatever the attempts; otherwise\n * a non-final attempt does (`attempts` below the maximum, or unlimited) and a final\n * or single attempt does not.\n */\nexport function attemptFeedbackVisible({ showFeedback, maxAttempts, attempts, adaptive }: AttemptFeedbackVisibility): boolean {\n\tif (adaptive || showFeedback === true) return true;\n\tif (attempts < 1) return false;\n\treturn maxAttempts === null || (maxAttempts > 1 && attempts < maxAttempts);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formats a duration as a clock readout: `MM:SS`, or `HH:MM:SS` once hours are
3
+ * involved (hours unpadded, minutes and seconds padded to two digits).
4
+ *
5
+ * Pass the provider's `formatNumber` to render the locale's digits; without it the
6
+ * digits are Western.
7
+ */
8
+ export declare function formatTime(seconds: number, formatNumber?: (value: number, options?: Intl.NumberFormatOptions) => string): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Formats a duration as a clock readout: `MM:SS`, or `HH:MM:SS` once hours are
3
+ * involved (hours unpadded, minutes and seconds padded to two digits).
4
+ *
5
+ * Pass the provider's `formatNumber` to render the locale's digits; without it the
6
+ * digits are Western.
7
+ */
8
+ export function formatTime(seconds, formatNumber) {
9
+ const hours = Math.floor(seconds / 3600);
10
+ const minutes = Math.floor((seconds % 3600) / 60);
11
+ const secs = seconds % 60;
12
+ const format = (value, digits) => formatNumber
13
+ ? formatNumber(value, { minimumIntegerDigits: digits, useGrouping: false })
14
+ : value.toString().padStart(digits, '0');
15
+ if (hours > 0) {
16
+ return `${format(hours, 1)}:${format(minutes, 2)}:${format(secs, 2)}`;
17
+ }
18
+ return `${format(minutes, 1)}:${format(secs, 2)}`;
19
+ }
20
+ //# sourceMappingURL=formatTime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatTime.js","sourceRoot":"","sources":["../../src/core/formatTime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACzB,OAAe,EACf,YAA4E;IAE5E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,OAAO,GAAG,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,MAAc,EAAE,EAAE,CAChD,YAAY;QACX,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAC3E,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IACvE,CAAC;IAED,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC","sourcesContent":["/**\n * Formats a duration as a clock readout: `MM:SS`, or `HH:MM:SS` once hours are\n * involved (hours unpadded, minutes and seconds padded to two digits).\n *\n * Pass the provider's `formatNumber` to render the locale's digits; without it the\n * digits are Western.\n */\nexport function formatTime(\n\tseconds: number,\n\tformatNumber?: (value: number, options?: Intl.NumberFormatOptions) => string\n): string {\n\tconst hours = Math.floor(seconds / 3600);\n\tconst minutes = Math.floor((seconds % 3600) / 60);\n\tconst secs = seconds % 60;\n\tconst format = (value: number, digits: number) =>\n\t\tformatNumber\n\t\t\t? formatNumber(value, { minimumIntegerDigits: digits, useGrouping: false })\n\t\t\t: value.toString().padStart(digits, '0');\n\n\tif (hours > 0) {\n\t\treturn `${format(hours, 1)}:${format(minutes, 2)}:${format(secs, 2)}`;\n\t}\n\n\treturn `${format(minutes, 1)}:${format(secs, 2)}`;\n}\n"]}
@@ -1,9 +1,12 @@
1
1
  export { AssessmentPlayer } from './AssessmentPlayer.js';
2
- export type { ItemSessionControlSettings, ItemSessionState, } from './ItemSessionController.js';
2
+ export type { AssessmentEndReason, AssessmentFinalizedEvent, AssessmentStartInfo, AssessmentTimeExpiryEvent, AssessmentTimeState, EffectiveItemTimeLimits, ScopeTimeExpiryEvent, SubmissionBlocker, } from './AssessmentPlayer.js';
3
+ export type { AutosaveState, AutosaveStatus } from './AutosaveManager.js';
4
+ export { AutosaveManager } from './AutosaveManager.js';
5
+ export { AssessmentPlayerError, assessmentErrorDisplay, isAssessmentPlayerError, type AssessmentErrorDisplay, type AssessmentPlayerErrorCode, type AssessmentPlayerErrorParams, } from './errors.js';
6
+ export type { ItemSessionControlSettings, ItemSessionState } from './ItemSessionController.js';
3
7
  export { ItemSessionController } from './ItemSessionController.js';
4
- export type { NavigationMode } from './NavigationManager.js';
5
8
  export { NavigationManager } from './NavigationManager.js';
6
- export type { PersistableState, PersistenceConfig, } from './StatePersistenceManager.js';
7
- export { StatePersistenceManager } from './StatePersistenceManager.js';
9
+ export { interactionRequirementFromXml, interactionResponseIdentifiers, isAnsweredValue, itemAnswerStatus, itemTitleFromXml, type ForwardTransitionInfo, type InteractionRequirement, type ItemAnswerStatus, type ReviewItemView, } from './reviewState.js';
8
10
  export type { TimeManagerConfig, TimeTrackingState } from './TimeManager.js';
9
11
  export { TimeManager } from './TimeManager.js';
12
+ export { formatTime } from './formatTime.js';
@@ -1,6 +1,9 @@
1
1
  export { AssessmentPlayer } from './AssessmentPlayer.js';
2
+ export { AutosaveManager } from './AutosaveManager.js';
3
+ export { AssessmentPlayerError, assessmentErrorDisplay, isAssessmentPlayerError, } from './errors.js';
2
4
  export { ItemSessionController } from './ItemSessionController.js';
3
5
  export { NavigationManager } from './NavigationManager.js';
4
- export { StatePersistenceManager } from './StatePersistenceManager.js';
6
+ export { interactionRequirementFromXml, interactionResponseIdentifiers, isAnsweredValue, itemAnswerStatus, itemTitleFromXml, } from './reviewState.js';
5
7
  export { TimeManager } from './TimeManager.js';
8
+ export { formatTime } from './formatTime.js';
6
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAKzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAK3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { AssessmentPlayer } from './AssessmentPlayer.js';\nexport type {\n\tItemSessionControlSettings,\n\tItemSessionState,\n} from './ItemSessionController.js';\nexport { ItemSessionController } from './ItemSessionController.js';\nexport type { NavigationMode } from './NavigationManager.js';\nexport { NavigationManager } from './NavigationManager.js';\nexport type {\n\tPersistableState,\n\tPersistenceConfig,\n} from './StatePersistenceManager.js';\nexport { StatePersistenceManager } from './StatePersistenceManager.js';\nexport type { TimeManagerConfig, TimeTrackingState } from './TimeManager.js';\nexport { TimeManager } from './TimeManager.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAYzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACN,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,GAIvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACN,6BAA6B,EAC7B,8BAA8B,EAC9B,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GAKhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { AssessmentPlayer } from './AssessmentPlayer.js';\nexport type {\n\tAssessmentEndReason,\n\tAssessmentFinalizedEvent,\n\tAssessmentStartInfo,\n\tAssessmentTimeExpiryEvent,\n\tAssessmentTimeState,\n\tEffectiveItemTimeLimits,\n\tScopeTimeExpiryEvent,\n\tSubmissionBlocker,\n} from './AssessmentPlayer.js';\nexport type { AutosaveState, AutosaveStatus } from './AutosaveManager.js';\nexport { AutosaveManager } from './AutosaveManager.js';\nexport {\n\tAssessmentPlayerError,\n\tassessmentErrorDisplay,\n\tisAssessmentPlayerError,\n\ttype AssessmentErrorDisplay,\n\ttype AssessmentPlayerErrorCode,\n\ttype AssessmentPlayerErrorParams,\n} from './errors.js';\nexport type { ItemSessionControlSettings, ItemSessionState } from './ItemSessionController.js';\nexport { ItemSessionController } from './ItemSessionController.js';\nexport { NavigationManager } from './NavigationManager.js';\nexport {\n\tinteractionRequirementFromXml,\n\tinteractionResponseIdentifiers,\n\tisAnsweredValue,\n\titemAnswerStatus,\n\titemTitleFromXml,\n\ttype ForwardTransitionInfo,\n\ttype InteractionRequirement,\n\ttype ItemAnswerStatus,\n\ttype ReviewItemView,\n} from './reviewState.js';\nexport type { TimeManagerConfig, TimeTrackingState } from './TimeManager.js';\nexport { TimeManager } from './TimeManager.js';\nexport { formatTime } from './formatTime.js';\n"]}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Client navigation legality.
3
+ *
4
+ * Whether the navigation *rules* let a candidate move or jump right now: linear
5
+ * versus nonlinear delivery, test-part sequencing, time locks and review policy.
6
+ * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
7
+ * over the delivery structure and predicates the orchestrator supplies — they
8
+ * never take the transition lock, and they are kept separate from the delivery-rules
9
+ * walk (`testStructure.ts`, shared with the backend's `integration/test-navigation.ts`
10
+ * entry), which decides *where* the rules go, not whether a move is legal.
11
+ */
12
+ import type { SecureSection } from '../integration/api-contract.js';
13
+ import type { FlatItem } from './deliveryStructure.js';
14
+ /**
15
+ * Whether jumping to a presented section is legal right now: in linear navigation there
16
+ * is no jumping at all; in nonlinear navigation only sections of the current test part
17
+ * are reachable, never locked items or items review has closed. Finalized tests have no
18
+ * legal targets.
19
+ */
20
+ export declare function isLegalSectionTarget(options: {
21
+ section: SecureSection;
22
+ items: readonly FlatItem[];
23
+ finalized: boolean;
24
+ currentIndex: number;
25
+ isItemLocked: (q: FlatItem) => boolean;
26
+ canReviewItem: (q: FlatItem) => boolean;
27
+ }): boolean;
28
+ /**
29
+ * Whether a candidate-initiated move from `currentIndex` to `targetIndex` follows the
30
+ * navigation rules. Within a nonlinear test part any item is reachable. Otherwise the only
31
+ * forward move is the forward step itself — `forward`, the item the backend's decision kept
32
+ * for the current item or the delivery rules (branch rules, preconditions) deliver next,
33
+ * passing over items an expired limit closed: in a linear part no item is skipped or
34
+ * revisited, and test parts are entered in sequence — never a jump across a part, never
35
+ * one back, never into a part whose precondition fails.
36
+ */
37
+ export declare function canNavigateByTestPart(options: {
38
+ targetIndex: number;
39
+ currentIndex: number;
40
+ items: readonly FlatItem[];
41
+ forward: () => number;
42
+ }): boolean;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Client navigation legality.
3
+ *
4
+ * Whether the navigation *rules* let a candidate move or jump right now: linear
5
+ * versus nonlinear delivery, test-part sequencing, time locks and review policy.
6
+ * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
7
+ * over the delivery structure and predicates the orchestrator supplies — they
8
+ * never take the transition lock, and they are kept separate from the delivery-rules
9
+ * walk (`testStructure.ts`, shared with the backend's `integration/test-navigation.ts`
10
+ * entry), which decides *where* the rules go, not whether a move is legal.
11
+ */
12
+ /**
13
+ * Whether jumping to a presented section is legal right now: in linear navigation there
14
+ * is no jumping at all; in nonlinear navigation only sections of the current test part
15
+ * are reachable, never locked items or items review has closed. Finalized tests have no
16
+ * legal targets.
17
+ */
18
+ export function isLegalSectionTarget(options) {
19
+ const { section, items, finalized, currentIndex, isItemLocked, canReviewItem } = options;
20
+ if (finalized)
21
+ return false;
22
+ const current = items[currentIndex];
23
+ if (!current)
24
+ return false;
25
+ const members = items.filter((q) => q.sections.some((s) => s.identifier === section.identifier));
26
+ if (members.length === 0)
27
+ return false;
28
+ const mode = current.testPart.navigationMode;
29
+ if (mode === 'linear') {
30
+ return members.some((q) => q === current);
31
+ }
32
+ return members.some((q) => q.testPart === current.testPart &&
33
+ !isItemLocked(q) &&
34
+ canReviewItem(q));
35
+ }
36
+ /**
37
+ * Whether a candidate-initiated move from `currentIndex` to `targetIndex` follows the
38
+ * navigation rules. Within a nonlinear test part any item is reachable. Otherwise the only
39
+ * forward move is the forward step itself — `forward`, the item the backend's decision kept
40
+ * for the current item or the delivery rules (branch rules, preconditions) deliver next,
41
+ * passing over items an expired limit closed: in a linear part no item is skipped or
42
+ * revisited, and test parts are entered in sequence — never a jump across a part, never
43
+ * one back, never into a part whose precondition fails.
44
+ */
45
+ export function canNavigateByTestPart(options) {
46
+ const { targetIndex, currentIndex, items, forward } = options;
47
+ if (targetIndex < 0 || targetIndex >= items.length)
48
+ return false;
49
+ const current = items[currentIndex];
50
+ const target = items[targetIndex];
51
+ if (!current || !target)
52
+ return false;
53
+ if (targetIndex === currentIndex)
54
+ return true;
55
+ const mode = current.testPart.navigationMode;
56
+ if (current.testPart === target.testPart && mode === 'nonlinear')
57
+ return true;
58
+ if (targetIndex < currentIndex)
59
+ return false;
60
+ return targetIndex === forward();
61
+ }
62
+ //# sourceMappingURL=navigationPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigationPolicy.js","sourceRoot":"","sources":["../../src/core/navigationPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAOpC;IACA,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACzF,IAAI,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAClC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAC3D,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAC7C,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACvB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAClB,CAAC,CAAC,EAAE,EAAE,CACL,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,QAAQ;QAC/B,CAAC,YAAY,CAAC,CAAC,CAAC;QAChB,aAAa,CAAC,CAAC,CAAC,CACjB,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAKrC;IACA,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9D,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACjE,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;IAClC,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,WAAW,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAC7C,IAAI,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC,QAAQ,IAAI,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9E,IAAI,WAAW,GAAG,YAAY;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,WAAW,KAAK,OAAO,EAAE,CAAC;AAClC,CAAC","sourcesContent":["/**\n * Client navigation legality.\n *\n * Whether the navigation *rules* let a candidate move or jump right now: linear\n * versus nonlinear delivery, test-part sequencing, time locks and review policy.\n * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions\n * over the delivery structure and predicates the orchestrator supplies — they\n * never take the transition lock, and they are kept separate from the delivery-rules\n * walk (`testStructure.ts`, shared with the backend's `integration/test-navigation.ts`\n * entry), which decides *where* the rules go, not whether a move is legal.\n */\n\nimport type { SecureSection } from '../integration/api-contract.js';\nimport type { FlatItem } from './deliveryStructure.js';\n\n/**\n * Whether jumping to a presented section is legal right now: in linear navigation there\n * is no jumping at all; in nonlinear navigation only sections of the current test part\n * are reachable, never locked items or items review has closed. Finalized tests have no\n * legal targets.\n */\nexport function isLegalSectionTarget(options: {\n\tsection: SecureSection;\n\titems: readonly FlatItem[];\n\tfinalized: boolean;\n\tcurrentIndex: number;\n\tisItemLocked: (q: FlatItem) => boolean;\n\tcanReviewItem: (q: FlatItem) => boolean;\n}): boolean {\n\tconst { section, items, finalized, currentIndex, isItemLocked, canReviewItem } = options;\n\tif (finalized) return false;\n\tconst current = items[currentIndex];\n\tif (!current) return false;\n\tconst members = items.filter((q) =>\n\t\tq.sections.some((s) => s.identifier === section.identifier),\n\t);\n\tif (members.length === 0) return false;\n\tconst mode = current.testPart.navigationMode;\n\tif (mode === 'linear') {\n\t\treturn members.some((q) => q === current);\n\t}\n\treturn members.some(\n\t\t(q) =>\n\t\t\tq.testPart === current.testPart &&\n\t\t\t!isItemLocked(q) &&\n\t\t\tcanReviewItem(q),\n\t);\n}\n\n/**\n * Whether a candidate-initiated move from `currentIndex` to `targetIndex` follows the\n * navigation rules. Within a nonlinear test part any item is reachable. Otherwise the only\n * forward move is the forward step itself — `forward`, the item the backend's decision kept\n * for the current item or the delivery rules (branch rules, preconditions) deliver next,\n * passing over items an expired limit closed: in a linear part no item is skipped or\n * revisited, and test parts are entered in sequence — never a jump across a part, never\n * one back, never into a part whose precondition fails.\n */\nexport function canNavigateByTestPart(options: {\n\ttargetIndex: number;\n\tcurrentIndex: number;\n\titems: readonly FlatItem[];\n\tforward: () => number;\n}): boolean {\n\tconst { targetIndex, currentIndex, items, forward } = options;\n\tif (targetIndex < 0 || targetIndex >= items.length) return false;\n\tconst current = items[currentIndex];\n\tconst target = items[targetIndex];\n\tif (!current || !target) return false;\n\tif (targetIndex === currentIndex) return true;\n\tconst mode = current.testPart.navigationMode;\n\tif (current.testPart === target.testPart && mode === 'nonlinear') return true;\n\tif (targetIndex < currentIndex) return false;\n\treturn targetIndex === forward();\n}\n"]}
@@ -0,0 +1,58 @@
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
+ export interface PauseControllerOptions {
16
+ /** Whether a navigation or submission transition is in flight right now. */
17
+ isBusy: () => boolean;
18
+ /** Subscribe to transition activity (used to apply a pause once a transition settles). */
19
+ onTransitionActivity: (listener: () => void) => () => void;
20
+ /** Freeze every clock and suspend the live attempt. */
21
+ freeze: () => void;
22
+ /** Continue the clocks and reopen the live attempt (only when `unfreezeAllowed`). */
23
+ unfreeze: () => void;
24
+ /** Whether delivery may continue the clocks now (begun, not finalized). */
25
+ unfreezeAllowed: () => boolean;
26
+ /** The pause started or ended (or, while paused, its reason changed). */
27
+ changed: (paused: boolean, reason?: string) => void;
28
+ /** Fires after a resume settled (the player re-checks a restored expiry finalization). */
29
+ afterResume: () => void;
30
+ /** True once the player is destroyed (resume is a no-op). */
31
+ isDestroyed: () => boolean;
32
+ }
33
+ export declare class PauseController {
34
+ #private;
35
+ constructor(options: PauseControllerOptions);
36
+ /** Whether a proctor pause is in force. */
37
+ get paused(): boolean;
38
+ /** The candidate-facing reason given for the current pause, if any. */
39
+ get reason(): string | undefined;
40
+ /**
41
+ * Start (or re-reason) a pause. `reason` is host-supplied, candidate-facing text
42
+ * shown with the pause (localize it in the host).
43
+ */
44
+ pause(reason?: string): void;
45
+ /** End a proctor pause: the clocks continue and the live attempt reopens where it stood. */
46
+ resume(): void;
47
+ /**
48
+ * Adopt a pause carried by a snapshot (a session saved during a pause reopens
49
+ * paused, its clocks frozen). Returns whether the paused state changed, so the
50
+ * caller reports it once.
51
+ */
52
+ setFromRestore(paused: boolean, rawReason: string | undefined): boolean;
53
+ /**
54
+ * The session reached its terminal state: the pause no longer holds anything
55
+ * (no pause event — the end of the test is it).
56
+ */
57
+ clearSilently(): void;
58
+ }