@qti-components/delivery 0.1.0-next.13 → 0.1.0-next.14

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.
@@ -99,11 +99,17 @@ export interface ItemLifecycleSeedInput extends Pick<ItemLifecycleInput, 'sessio
99
99
  presented: boolean;
100
100
  /** The item comes before the current one in a linear part: the candidate has left it for good. */
101
101
  passed: boolean;
102
+ /**
103
+ * A time limit over the item is up: its own, or its section's, part's or test's, without
104
+ * `allow-late-submission` (`closedByTimeUp`, roadmap 1 T5). Its session ends and never opens again.
105
+ */
106
+ timeUp?: boolean;
102
107
  }
103
108
  /**
104
109
  * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
105
- * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
106
- * with individual submission has passed it; interacting when it is on screen; initial before its
107
- * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
110
+ * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left, a linear part
111
+ * with individual submission has passed it or its time is up; interacting when it is on screen;
112
+ * initial before its first ended attempt (in a simultaneous part: never opened); else suspended.
113
+ * Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
108
114
  */
109
115
  export declare function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState;
@@ -146,15 +146,16 @@ export function itemLifecycleGuards(input) {
146
146
  }
147
147
  /**
148
148
  * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
149
- * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
150
- * with individual submission has passed it; interacting when it is on screen; initial before its
151
- * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
149
+ * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left, a linear part
150
+ * with individual submission has passed it or its time is up; interacting when it is on screen;
151
+ * initial before its first ended attempt (in a simultaneous part: never opened); else suspended.
152
+ * Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
152
153
  */
153
154
  export function seedItemLifecycle(input) {
154
155
  // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): passing an
155
- // item in a linear one does not close it; submitting the part does.
156
+ // item in a linear one does not close it; submitting the part does. Time-up closes in any part.
156
157
  const closedByPassing = input.passed && input.submissionMode !== 'simultaneous';
157
- if (!hasAttemptsLeft(input) || closedByPassing)
158
+ if (!hasAttemptsLeft(input) || closedByPassing || input.timeUp)
158
159
  return 'closed';
159
160
  if (input.passed)
160
161
  return input.completionStatus === 'not_attempted' ? 'initial' : 'suspended';
@@ -1 +1 @@
1
- {"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/item-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,aAAa;IACb,eAAe;IACf,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,uBAAuB;IACvB,gBAAgB;IAChB,aAAa;IACb,WAAW;IACX,eAAe;IACf,aAAa;CACL,CAAC;AAIX,gGAAgG;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,sBAAsB;IACtB,eAAe;IACf,WAAW;IACX,aAAa;IACb,cAAc;CACN,CAAC;AAgBX,gEAAgE;AAChE,MAAM,CAAC,MAAM,cAAc,GAEvB;IACF,OAAO,EAAE;QACP,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7D,cAAc,EAAE,QAAQ;KACzB;IACD,WAAW,EAAE;QACX,iFAAiF;QACjF,UAAU,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C7D,mGAAmG;IACnG,oEAAoE;IACpE,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,cAAc,CAAC;IAChF,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,eAAe;QAAE,OAAO,QAAQ,CAAC;IAChE,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9F,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,aAAa,CAAC;IAC1C,OAAO,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3D,CAAC","sourcesContent":["import type { SessionControl, TestPartModel } from '../model/test-model.js';\n\n/**\n * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per\n * item instance: every item session is in exactly one of these states, and only the transitions in\n * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.\n *\n * ```mermaid\n * stateDiagram-v2\n * [*] --> initial\n * initial --> interacting: beginAttempt [attemptsLeft]\n * initial --> closed: endItemSession\n * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]\n * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]\n * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]\n * interacting --> suspended: endCandidateSession\n * interacting --> closed: endItemSession\n * modalFeedback --> interacting: beginAttempt [attemptsLeft]\n * modalFeedback --> suspended: endCandidateSession\n * modalFeedback --> closed: endItemSession\n * suspended --> interacting: beginCandidateSession [mayResume]\n * suspended --> closed: endItemSession\n * closed --> review: beginReview [allowReview]\n * review --> closed: endReview\n * closed --> solution: beginSolution [showSolution]\n * solution --> closed: endSolution\n * ```\n *\n * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and\n * `review` the responses show but are fixed; in `solution` the correct responses show instead. An\n * item that goes from `initial` straight to `closed` keeps NULL responses.\n *\n * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this\n * plan reads it): the item after an attempt whose response processing set modal feedback, with\n * attempts left (\"modal feedback is shown to the candidate directly following response\n * processing\", §2.6). The candidate reads it before trying again.\n *\n * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.\n */\nexport const ITEM_LIFECYCLE_STATES = [\n 'initial',\n 'interacting',\n 'modalFeedback',\n 'suspended',\n 'closed',\n 'review',\n 'solution'\n] as const;\n\nexport type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];\n\n/**\n * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands\n * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.\n */\nexport const ITEM_LIFECYCLE_EVENTS = [\n 'beginAttempt',\n 'endAttempt',\n 'endCandidateSession',\n 'beginCandidateSession',\n 'endItemSession',\n 'beginReview',\n 'endReview',\n 'beginSolution',\n 'endSolution'\n] as const;\n\nexport type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];\n\n/** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */\nexport const ITEM_LIFECYCLE_GUARDS = [\n 'attemptsLeft',\n 'individualSubmission',\n 'modalFeedback',\n 'mayResume',\n 'allowReview',\n 'showSolution'\n] as const;\n\nexport type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];\n\nexport type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;\n\n/** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */\nexport interface ItemLifecycleBranch {\n readonly to: ItemLifecycleState;\n readonly when?: readonly ItemLifecycleGuard[];\n readonly unless?: readonly ItemLifecycleGuard[];\n}\n\n/** A state with no guard, or branches tried in order, the first that holds taken. */\nexport type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];\n\n/** The transition table: a pair it does not list is refused. */\nexport const ITEM_LIFECYCLE: Readonly<\n Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>\n> = {\n initial: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endItemSession: 'closed'\n },\n interacting: {\n // The guards are read after response processing, with the ended attempt counted.\n endAttempt: [\n { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },\n { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },\n { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }\n ],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n modalFeedback: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n suspended: {\n beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],\n endItemSession: 'closed'\n },\n closed: {\n beginReview: [{ to: 'review', when: ['allowReview'] }],\n beginSolution: [{ to: 'solution', when: ['showSolution'] }]\n },\n review: {\n endReview: 'closed'\n },\n solution: {\n endSolution: 'closed'\n }\n};\n\n/**\n * The state an item session goes to on `event`, or null when the table refuses it: the pair is not\n * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer\n * on every runtime.\n */\nexport function transition(\n state: ItemLifecycleState,\n event: ItemLifecycleEvent,\n guards: ItemLifecycleGuards\n): ItemLifecycleState | null {\n const target = ITEM_LIFECYCLE[state][event];\n if (target === undefined) return null;\n if (typeof target === 'string') return target;\n const branch = target.find(\n ({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard])\n );\n return branch?.to ?? null;\n}\n\n/** What the guards of one item session are read from. */\nexport interface ItemLifecycleInput {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;\n /** From the item's facts (`ItemFacts.adaptive`). */\n adaptive: boolean;\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).\n */\n numAttempts: number;\n /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */\n completionStatus: string | null;\n /** The candidate has moved on from the item; in a linear part there is no way back. */\n left: boolean;\n /** The last response processing set modal feedback to show. */\n modalFeedback: boolean;\n}\n\n/**\n * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it\n * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its\n * response processing set `completionStatus` to `completed`. In a part with simultaneous submission\n * every item has \"one and only one attempt\" (§4.1), used when the part is submitted.\n */\nexport function hasAttemptsLeft({\n sessionControl: { maxAttempts },\n adaptive,\n numAttempts,\n completionStatus,\n submissionMode\n}: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> &\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>>): boolean {\n if (submissionMode === 'simultaneous') return numAttempts === 0;\n if (adaptive) return completionStatus !== 'completed';\n return maxAttempts === 0 || numAttempts < maxAttempts;\n}\n\n/** The guards of one item session, from its session control, its facts, its part and its variables. */\nexport function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards {\n return {\n attemptsLeft: hasAttemptsLeft(input),\n // In a simultaneous part every response is processed when the part is submitted (§4.1).\n individualSubmission: input.submissionMode === 'individual',\n modalFeedback: input.modalFeedback,\n // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).\n mayResume: input.navigationMode === 'nonlinear' || !input.left,\n allowReview: input.sessionControl.allowReview,\n showSolution: input.sessionControl.showSolution\n };\n}\n\n/** What a version 1 state, or a test restored from one, tells about an item session. */\nexport interface ItemLifecycleSeedInput\n extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>,\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>> {\n /** The item is on screen: the current item, or one of the section on screen with `navigate=\"section\"`. */\n presented: boolean;\n /** The item comes before the current one in a linear part: the candidate has left it for good. */\n passed: boolean;\n}\n\n/**\n * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored\n * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part\n * with individual submission has passed it; interacting when it is on screen; initial before its\n * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.\n */\nexport function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState {\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): passing an\n // item in a linear one does not close it; submitting the part does.\n const closedByPassing = input.passed && input.submissionMode !== 'simultaneous';\n if (!hasAttemptsLeft(input) || closedByPassing) return 'closed';\n if (input.passed) return input.completionStatus === 'not_attempted' ? 'initial' : 'suspended';\n if (input.presented) return 'interacting';\n return input.numAttempts === 0 ? 'initial' : 'suspended';\n}\n"]}
1
+ {"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/item-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,aAAa;IACb,eAAe;IACf,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,uBAAuB;IACvB,gBAAgB;IAChB,aAAa;IACb,WAAW;IACX,eAAe;IACf,aAAa;CACL,CAAC;AAIX,gGAAgG;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,sBAAsB;IACtB,eAAe;IACf,WAAW;IACX,aAAa;IACb,cAAc;CACN,CAAC;AAgBX,gEAAgE;AAChE,M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WAAW,IAAI,CAAC,KAAK,CAAC,IAAI;QAC9D,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW;QAC7C,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY;KAChD,CAAC;AACJ,CAAC;AAiBD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,mGAAmG;IACnG,gGAAgG;IAChG,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,cAAc,CAAC;IAChF,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,eAAe,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC;IAChF,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9F,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,aAAa,CAAC;IAC1C,OAAO,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3D,CAAC","sourcesContent":["import type { SessionControl, TestPartModel } from '../model/test-model.js';\n\n/**\n * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per\n * item instance: every item session is in exactly one of these states, and only the transitions in\n * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.\n *\n * ```mermaid\n * stateDiagram-v2\n * [*] --> initial\n * initial --> interacting: beginAttempt [attemptsLeft]\n * initial --> closed: endItemSession\n * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]\n * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]\n * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]\n * interacting --> suspended: endCandidateSession\n * interacting --> closed: endItemSession\n * modalFeedback --> interacting: beginAttempt [attemptsLeft]\n * modalFeedback --> suspended: endCandidateSession\n * modalFeedback --> closed: endItemSession\n * suspended --> interacting: beginCandidateSession [mayResume]\n * suspended --> closed: endItemSession\n * closed --> review: beginReview [allowReview]\n * review --> closed: endReview\n * closed --> solution: beginSolution [showSolution]\n * solution --> closed: endSolution\n * ```\n *\n * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and\n * `review` the responses show but are fixed; in `solution` the correct responses show instead. An\n * item that goes from `initial` straight to `closed` keeps NULL responses.\n *\n * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this\n * plan reads it): the item after an attempt whose response processing set modal feedback, with\n * attempts left (\"modal feedback is shown to the candidate directly following response\n * processing\", §2.6). The candidate reads it before trying again.\n *\n * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.\n */\nexport const ITEM_LIFECYCLE_STATES = [\n 'initial',\n 'interacting',\n 'modalFeedback',\n 'suspended',\n 'closed',\n 'review',\n 'solution'\n] as const;\n\nexport type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];\n\n/**\n * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands\n * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.\n */\nexport const ITEM_LIFECYCLE_EVENTS = [\n 'beginAttempt',\n 'endAttempt',\n 'endCandidateSession',\n 'beginCandidateSession',\n 'endItemSession',\n 'beginReview',\n 'endReview',\n 'beginSolution',\n 'endSolution'\n] as const;\n\nexport type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];\n\n/** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */\nexport const ITEM_LIFECYCLE_GUARDS = [\n 'attemptsLeft',\n 'individualSubmission',\n 'modalFeedback',\n 'mayResume',\n 'allowReview',\n 'showSolution'\n] as const;\n\nexport type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];\n\nexport type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;\n\n/** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */\nexport interface ItemLifecycleBranch {\n readonly to: ItemLifecycleState;\n readonly when?: readonly ItemLifecycleGuard[];\n readonly unless?: readonly ItemLifecycleGuard[];\n}\n\n/** A state with no guard, or branches tried in order, the first that holds taken. */\nexport type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];\n\n/** The transition table: a pair it does not list is refused. */\nexport const ITEM_LIFECYCLE: Readonly<\n Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>\n> = {\n initial: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endItemSession: 'closed'\n },\n interacting: {\n // The guards are read after response processing, with the ended attempt counted.\n endAttempt: [\n { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },\n { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },\n { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }\n ],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n modalFeedback: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n suspended: {\n beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],\n endItemSession: 'closed'\n },\n closed: {\n beginReview: [{ to: 'review', when: ['allowReview'] }],\n beginSolution: [{ to: 'solution', when: ['showSolution'] }]\n },\n review: {\n endReview: 'closed'\n },\n solution: {\n endSolution: 'closed'\n }\n};\n\n/**\n * The state an item session goes to on `event`, or null when the table refuses it: the pair is not\n * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer\n * on every runtime.\n */\nexport function transition(\n state: ItemLifecycleState,\n event: ItemLifecycleEvent,\n guards: ItemLifecycleGuards\n): ItemLifecycleState | null {\n const target = ITEM_LIFECYCLE[state][event];\n if (target === undefined) return null;\n if (typeof target === 'string') return target;\n const branch = target.find(\n ({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard])\n );\n return branch?.to ?? null;\n}\n\n/** What the guards of one item session are read from. */\nexport interface ItemLifecycleInput {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;\n /** From the item's facts (`ItemFacts.adaptive`). */\n adaptive: boolean;\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).\n */\n numAttempts: number;\n /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */\n completionStatus: string | null;\n /** The candidate has moved on from the item; in a linear part there is no way back. */\n left: boolean;\n /** The last response processing set modal feedback to show. */\n modalFeedback: boolean;\n}\n\n/**\n * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it\n * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its\n * response processing set `completionStatus` to `completed`. In a part with simultaneous submission\n * every item has \"one and only one attempt\" (§4.1), used when the part is submitted.\n */\nexport function hasAttemptsLeft({\n sessionControl: { maxAttempts },\n adaptive,\n numAttempts,\n completionStatus,\n submissionMode\n}: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> &\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>>): boolean {\n if (submissionMode === 'simultaneous') return numAttempts === 0;\n if (adaptive) return completionStatus !== 'completed';\n return maxAttempts === 0 || numAttempts < maxAttempts;\n}\n\n/** The guards of one item session, from its session control, its facts, its part and its variables. */\nexport function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards {\n return {\n attemptsLeft: hasAttemptsLeft(input),\n // In a simultaneous part every response is processed when the part is submitted (§4.1).\n individualSubmission: input.submissionMode === 'individual',\n modalFeedback: input.modalFeedback,\n // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).\n mayResume: input.navigationMode === 'nonlinear' || !input.left,\n allowReview: input.sessionControl.allowReview,\n showSolution: input.sessionControl.showSolution\n };\n}\n\n/** What a version 1 state, or a test restored from one, tells about an item session. */\nexport interface ItemLifecycleSeedInput\n extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>,\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>> {\n /** The item is on screen: the current item, or one of the section on screen with `navigate=\"section\"`. */\n presented: boolean;\n /** The item comes before the current one in a linear part: the candidate has left it for good. */\n passed: boolean;\n /**\n * A time limit over the item is up: its own, or its section's, part's or test's, without\n * `allow-late-submission` (`closedByTimeUp`, roadmap 1 T5). Its session ends and never opens again.\n */\n timeUp?: boolean;\n}\n\n/**\n * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored\n * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left, a linear part\n * with individual submission has passed it or its time is up; interacting when it is on screen;\n * initial before its first ended attempt (in a simultaneous part: never opened); else suspended.\n * Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.\n */\nexport function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState {\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): passing an\n // item in a linear one does not close it; submitting the part does. Time-up closes in any part.\n const closedByPassing = input.passed && input.submissionMode !== 'simultaneous';\n if (!hasAttemptsLeft(input) || closedByPassing || input.timeUp) return 'closed';\n if (input.passed) return input.completionStatus === 'not_attempted' ? 'initial' : 'suspended';\n if (input.presented) return 'interacting';\n return input.numAttempts === 0 ? 'initial' : 'suspended';\n}\n"]}
@@ -15,14 +15,14 @@ export interface ItemSessionFacts extends ItemLifecycleSeedInput, Pick<ItemLifec
15
15
  /**
16
16
  * The session after the candidate moved (or a state was restored), through the lifecycle table: an
17
17
  * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
18
- * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside
18
+ * linear part with individual submission has passed, or whose time is up, is closed. A session not seen before, or whose attempts changed outside
19
19
  * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
20
20
  * later), is seeded again with `seedItemLifecycle`.
21
21
  */
22
22
  export declare function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession;
23
23
  /**
24
24
  * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes
25
- * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery
25
+ * through the table's `endAttempt`, and then `endItemSession` when its time is up; one in any other state had its attempt ended before this delivery
26
26
  * saw it begin, so it is seeded as an item on screen.
27
27
  */
28
28
  export declare function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession;
@@ -6,7 +6,7 @@ const OVER = ['closed', 'review', 'solution'];
6
6
  /**
7
7
  * The session after the candidate moved (or a state was restored), through the lifecycle table: an
8
8
  * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
9
- * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside
9
+ * linear part with individual submission has passed, or whose time is up, is closed. A session not seen before, or whose attempts changed outside
10
10
  * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
11
11
  * later), is seeded again with `seedItemLifecycle`.
12
12
  */
@@ -18,8 +18,9 @@ export function followItemSession(previous, facts) {
18
18
  const guards = guardsFor(facts);
19
19
  let state = previous.state;
20
20
  // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): a passed
21
- // item is suspended like any item off screen, and closes when the part is submitted.
22
- const closes = facts.passed && facts.submissionMode !== 'simultaneous';
21
+ // item is suspended like any item off screen, and closes when the part is submitted. Time-up closes
22
+ // in any part.
23
+ const closes = (facts.passed && facts.submissionMode !== 'simultaneous') || facts.timeUp;
23
24
  if (closes) {
24
25
  if (!OVER.includes(state))
25
26
  state = transition(state, 'endItemSession', guards) ?? state;
@@ -37,7 +38,7 @@ export function followItemSession(previous, facts) {
37
38
  }
38
39
  /**
39
40
  * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes
40
- * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery
41
+ * through the table's `endAttempt`, and then `endItemSession` when its time is up; one in any other state had its attempt ended before this delivery
41
42
  * saw it begin, so it is seeded as an item on screen.
42
43
  */
43
44
  export function endItemAttempt(previous, facts) {
@@ -45,6 +46,11 @@ export function endItemAttempt(previous, facts) {
45
46
  if (previous?.state !== 'interacting') {
46
47
  return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };
47
48
  }
48
- return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };
49
+ const ended = transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting';
50
+ // The attempt scored when time ran out is the last: the session ends whatever attempts are left.
51
+ if (facts.timeUp && !OVER.includes(ended)) {
52
+ return { state: transition(ended, 'endItemSession', guardsFor(facts)) ?? 'closed', numAttempts, adaptive };
53
+ }
54
+ return { state: ended, numAttempts, adaptive };
49
55
  }
50
56
  //# sourceMappingURL=item-session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"item-session.js","sourceRoot":"","sources":["../../src/lifecycle/item-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAqBzF,MAAM,SAAS,GAAG,CAAC,KAAuB,EAAE,EAAE;AAC5C,uGAAuG;AACvG,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;AAE9E,MAAM,IAAI,GAAkC,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiC,EAAE,KAAuB;IAC1F,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,CAAC,Q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,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,QAAQ,EAAE,KAAK,KAAK,aAAa,EAAE,CAAC;QACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAC5F,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACtH,CAAC","sourcesContent":["import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';\n\nimport type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */\nexport interface ItemSession {\n readonly state: ItemLifecycleState;\n /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */\n readonly numAttempts: number;\n /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */\n readonly adaptive: boolean;\n}\n\n/** What a delivery knows about an item session at an update. */\nexport interface ItemSessionFacts\n extends ItemLifecycleSeedInput,\n Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {\n sessionControl: ItemLifecycleInput['sessionControl'];\n submissionMode: ItemLifecycleInput['submissionMode'];\n}\n\nconst guardsFor = (facts: ItemSessionFacts) =>\n // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.\n itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n\nconst OVER: readonly ItemLifecycleState[] = ['closed', 'review', 'solution'];\n\n/**\n * The session after the candidate moved (or a state was restored), through the lifecycle table: an\n * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a\n * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside\n * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came\n * later), is seeded again with `seedItemLifecycle`.\n */\nexport function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {\n return { state: seedItemLifecycle(facts), numAttempts, adaptive };\n }\n const guards = guardsFor(facts);\n let state = previous.state;\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): a passed\n // item is suspended like any item off screen, and closes when the part is submitted.\n const closes = facts.passed && facts.submissionMode !== 'simultaneous';\n if (closes) {\n if (!OVER.includes(state)) state = transition(state, 'endItemSession', guards) ?? state;\n } else if (facts.presented && !facts.passed) {\n if (state === 'initial') state = transition(state, 'beginAttempt', guards) ?? state;\n else if (state === 'suspended') state = transition(state, 'beginCandidateSession', guards) ?? state;\n } else if (state === 'interacting' || state === 'modalFeedback') {\n state = transition(state, 'endCandidateSession', guards) ?? state;\n }\n return { state, numAttempts, adaptive };\n}\n\n/**\n * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes\n * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery\n * saw it begin, so it is seeded as an item on screen.\n */\nexport function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (previous?.state !== 'interacting') {\n return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };\n }\n return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };\n}\n"]}
1
+ {"version":3,"file":"item-session.js","sourceRoot":"","sources":["../../src/lifecycle/item-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAqBzF,MAAM,SAAS,GAAG,CAAC,KAAuB,EAAE,EAAE;AAC5C,uGAAuG;AACvG,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAA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K,CAAC;IACtG,CAAC;SAAM,IAAI,KAAK,KAAK,aAAa,IAAI,KAAK,KAAK,eAAe,EAAE,CAAC;QAChE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,qBAAqB,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAiC,EAAE,KAAuB;IACvF,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,QAAQ,EAAE,KAAK,KAAK,aAAa,EAAE,CAAC;QACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAC5F,CAAC;IACD,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,aAAa,CAAC;IACzF,iGAAiG;IACjG,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAC7G,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';\n\nimport type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */\nexport interface ItemSession {\n readonly state: ItemLifecycleState;\n /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */\n readonly numAttempts: number;\n /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */\n readonly adaptive: boolean;\n}\n\n/** What a delivery knows about an item session at an update. */\nexport interface ItemSessionFacts\n extends ItemLifecycleSeedInput,\n Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {\n sessionControl: ItemLifecycleInput['sessionControl'];\n submissionMode: ItemLifecycleInput['submissionMode'];\n}\n\nconst guardsFor = (facts: ItemSessionFacts) =>\n // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.\n itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n\nconst OVER: readonly ItemLifecycleState[] = ['closed', 'review', 'solution'];\n\n/**\n * The session after the candidate moved (or a state was restored), through the lifecycle table: an\n * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a\n * linear part with individual submission has passed, or whose time is up, is closed. A session not seen before, or whose attempts changed outside\n * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came\n * later), is seeded again with `seedItemLifecycle`.\n */\nexport function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {\n return { state: seedItemLifecycle(facts), numAttempts, adaptive };\n }\n const guards = guardsFor(facts);\n let state = previous.state;\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): a passed\n // item is suspended like any item off screen, and closes when the part is submitted. Time-up closes\n // in any part.\n const closes = (facts.passed && facts.submissionMode !== 'simultaneous') || facts.timeUp;\n if (closes) {\n if (!OVER.includes(state)) state = transition(state, 'endItemSession', guards) ?? state;\n } else if (facts.presented && !facts.passed) {\n if (state === 'initial') state = transition(state, 'beginAttempt', guards) ?? state;\n else if (state === 'suspended') state = transition(state, 'beginCandidateSession', guards) ?? state;\n } else if (state === 'interacting' || state === 'modalFeedback') {\n state = transition(state, 'endCandidateSession', guards) ?? state;\n }\n return { state, numAttempts, adaptive };\n}\n\n/**\n * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes\n * through the table's `endAttempt`, and then `endItemSession` when its time is up; one in any other state had its attempt ended before this delivery\n * saw it begin, so it is seeded as an item on screen.\n */\nexport function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (previous?.state !== 'interacting') {\n return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };\n }\n const ended = transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting';\n // The attempt scored when time ran out is the last: the session ends whatever attempts are left.\n if (facts.timeUp && !OVER.includes(ended)) {\n return { state: transition(ended, 'endItemSession', guardsFor(facts)) ?? 'closed', numAttempts, adaptive };\n }\n return { state: ended, numAttempts, adaptive };\n}\n"]}
@@ -10,3 +10,10 @@ export interface Clock {
10
10
  export declare const systemClock: Clock;
11
11
  /** A clock that always answers `time`; for specs and test vectors. */
12
12
  export declare const fixedClock: (time: number) => Clock;
13
+ /**
14
+ * A clock that ticks with `local` but reads the server's time: `serverNow` is the server's time
15
+ * (milliseconds since the epoch) at the moment this is called, read for instance from the response
16
+ * that delivered the test. A host whose server is the authority on time passes it to `qtiTest.clock`
17
+ * (decided 2026-12-03, roadmap 1 T5). The offset is fixed at the call; call it again to resync.
18
+ */
19
+ export declare function syncedClock(serverNow: number, local?: Clock): Clock;
@@ -2,4 +2,14 @@
2
2
  export const systemClock = { now: () => Date.now() };
3
3
  /** A clock that always answers `time`; for specs and test vectors. */
4
4
  export const fixedClock = (time) => ({ now: () => time });
5
+ /**
6
+ * A clock that ticks with `local` but reads the server's time: `serverNow` is the server's time
7
+ * (milliseconds since the epoch) at the moment this is called, read for instance from the response
8
+ * that delivered the test. A host whose server is the authority on time passes it to `qtiTest.clock`
9
+ * (decided 2026-12-03, roadmap 1 T5). The offset is fixed at the call; call it again to resync.
10
+ */
11
+ export function syncedClock(serverNow, local = systemClock) {
12
+ const offset = serverNow - local.now();
13
+ return { now: () => local.now() + offset };
14
+ }
5
15
  //# sourceMappingURL=clock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/state/clock.ts"],"names":[],"mappings":"AASA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAU,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAE5D,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC","sourcesContent":["/**\n * Where `delivery` reads the time. Passed in, never read from the runtime, so a server can be the\n * only clock a high-stakes test trusts, and a spec can fix the time.\n */\nexport interface Clock {\n /** Milliseconds since the epoch. */\n now(): number;\n}\n\n/** The runtime's own clock, for a browser or server that trusts itself. */\nexport const systemClock: Clock = { now: () => Date.now() };\n\n/** A clock that always answers `time`; for specs and test vectors. */\nexport const fixedClock = (time: number): Clock => ({ now: () => time });\n"]}
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/state/clock.ts"],"names":[],"mappings":"AASA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAU,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AAE5D,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,QAAe,WAAW;IACvE,MAAM,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;IACvC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["/**\n * Where `delivery` reads the time. Passed in, never read from the runtime, so a server can be the\n * only clock a high-stakes test trusts, and a spec can fix the time.\n */\nexport interface Clock {\n /** Milliseconds since the epoch. */\n now(): number;\n}\n\n/** The runtime's own clock, for a browser or server that trusts itself. */\nexport const systemClock: Clock = { now: () => Date.now() };\n\n/** A clock that always answers `time`; for specs and test vectors. */\nexport const fixedClock = (time: number): Clock => ({ now: () => time });\n\n/**\n * A clock that ticks with `local` but reads the server's time: `serverNow` is the server's time\n * (milliseconds since the epoch) at the moment this is called, read for instance from the response\n * that delivered the test. A host whose server is the authority on time passes it to `qtiTest.clock`\n * (decided 2026-12-03, roadmap 1 T5). The offset is fixed at the call; call it again to resync.\n */\nexport function syncedClock(serverNow: number, local: Clock = systemClock): Clock {\n const offset = serverNow - local.now();\n return { now: () => local.now() + offset };\n}\n"]}
@@ -1,5 +1,13 @@
1
1
  import type { TestModel } from '../model/test-model.js';
2
- import type { DeliveryState } from '../state/delivery-state.js';
2
+ import type { ItemInstanceId } from '../state/delivery-state.js';
3
+ import type { TimedItem, TimingState } from './timing.js';
4
+ /** What `timeLimitRules` reads: the stopwatches, and each instance's item-ref in the order of the test. */
5
+ export interface TimeLimitInput {
6
+ timing: TimingState['timing'];
7
+ /** Every item instance, in the order of the test. */
8
+ order: readonly ItemInstanceId[];
9
+ items: Record<ItemInstanceId, Pick<TimedItem, 'itemRefIdentifier' | 'duration'>>;
10
+ }
3
11
  /**
4
12
  * Where one level stands against its `qti-time-limits` (QTI 3 info model §7.40, §2.8.5), in seconds.
5
13
  * Derived from the model and the state at a moment, never stored.
@@ -47,4 +55,30 @@ export interface TimeLimitAnswers {
47
55
  * Each declared time limit against the time spent at `now`. `min-time` applies always on the test
48
56
  * and a part, and on a section or item-ref only in a linear part (info model §2.8.5). Pure.
49
57
  */
50
- export declare function timeLimitRules(model: TestModel, state: DeliveryState, now: number): TimeLimitAnswers;
58
+ export declare function timeLimitRules(model: TestModel, state: TimeLimitInput, now: number): TimeLimitAnswers;
59
+ /** What the time-up functions read of the answers: only whether each level's time is up. */
60
+ export interface TimeUpAnswers {
61
+ test?: Pick<TimeLimitState, 'timeUp'>;
62
+ testParts: Record<string, Pick<TimeLimitState, 'timeUp'>>;
63
+ sections: Record<string, Pick<TimeLimitState, 'timeUp'>>;
64
+ items: Record<string, Pick<TimeLimitState, 'timeUp'>>;
65
+ }
66
+ /** One level whose time is up: the test, a test part, a section or an item instance. */
67
+ export interface TimeUp {
68
+ scope: 'test' | 'testPart' | 'section' | 'item';
69
+ /** The test's, the part's or the section's identifier, or the item instance. */
70
+ identifier: string;
71
+ }
72
+ /** Each level whose time is up (`timeUp`: expired without `allow-late-submission`), the test first. Pure. */
73
+ export declare function timeUps(model: TestModel, answers: TimeUpAnswers): TimeUp[];
74
+ /**
75
+ * The item instances, in `order`, whose session a time-up ends (QTI 3 info model §7.40, §2.2.2.2):
76
+ * every instance under the test, part or section whose time is up, with the sections nested in it,
77
+ * and an instance whose own item-ref limit is up. The other instances of that item-ref keep their own
78
+ * time. A delivery ends each one's session (`endItemSession`): the attempt on screen is scored as it
79
+ * stands first, and an ended session is never opened again. Pure.
80
+ */
81
+ export declare function closedByTimeUp(model: TestModel, state: {
82
+ order: readonly ItemInstanceId[];
83
+ items: Record<ItemInstanceId, Pick<TimedItem, 'itemRefIdentifier'>>;
84
+ }, answers: TimeUpAnswers): ItemInstanceId[];
@@ -1,5 +1,5 @@
1
1
  import { itemRefsInOrder, sectionsInOrder } from '../model/test-model.js';
2
- import { elapsed } from './timing.js';
2
+ import { elapsed, placeOfItemRef } from './timing.js';
3
3
  const NOT_RUN = { spent: 0, since: null };
4
4
  function answer(limits, stopwatch, now, minTimeApplies) {
5
5
  const spentMs = elapsed(stopwatch, now);
@@ -48,4 +48,35 @@ export function timeLimitRules(model, state, now) {
48
48
  }
49
49
  return answers;
50
50
  }
51
+ /** Each level whose time is up (`timeUp`: expired without `allow-late-submission`), the test first. Pure. */
52
+ export function timeUps(model, answers) {
53
+ const up = (record, scope) => Object.entries(record).flatMap(([identifier, answer]) => (answer.timeUp ? [{ scope, identifier }] : []));
54
+ return [
55
+ ...(answers.test?.timeUp ? [{ scope: 'test', identifier: model.identifier }] : []),
56
+ ...up(answers.testParts, 'testPart'),
57
+ ...up(answers.sections, 'section'),
58
+ ...up(answers.items, 'item')
59
+ ];
60
+ }
61
+ /**
62
+ * The item instances, in `order`, whose session a time-up ends (QTI 3 info model §7.40, §2.2.2.2):
63
+ * every instance under the test, part or section whose time is up, with the sections nested in it,
64
+ * and an instance whose own item-ref limit is up. The other instances of that item-ref keep their own
65
+ * time. A delivery ends each one's session (`endItemSession`): the attempt on screen is scored as it
66
+ * stands first, and an ended session is never opened again. Pure.
67
+ */
68
+ export function closedByTimeUp(model, state, answers) {
69
+ if (answers.test?.timeUp)
70
+ return [...state.order];
71
+ return state.order.filter(id => {
72
+ if (answers.items[id]?.timeUp)
73
+ return true;
74
+ const item = state.items[id];
75
+ const place = item && placeOfItemRef(model, item.itemRefIdentifier);
76
+ if (!place)
77
+ return false;
78
+ return (Boolean(answers.testParts[place.testPart.identifier]?.timeUp) ||
79
+ place.sections.some(section => answers.sections[section.identifier]?.timeUp));
80
+ });
81
+ }
51
82
  //# sourceMappingURL=time-limits.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"time-limits.js","sourceRoot":"","sources":["../../src/timing/time-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAkDtC,MAAM,OAAO,GAAc,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAErD,SAAS,MAAM,CAAC,MAAkB,EAAE,SAAoB,EAAE,GAAW,EAAE,cAAuB;IAC5F,MAAM,OAA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EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { itemRefsInOrder, sectionsInOrder } from '../model/test-model.js';\nimport { elapsed } from './timing.js';\n\nimport type { TestModel, TimeLimits } from '../model/test-model.js';\nimport type { DeliveryState, Stopwatch } from '../state/delivery-state.js';\n\n/**\n * Where one level stands against its `qti-time-limits` (QTI 3 info model §7.40, §2.8.5), in seconds.\n * Derived from the model and the state at a moment, never stored.\n *\n * Experimental (0.x): roadmap 1 T5.\n */\nexport interface TimeLimitState {\n /**\n * The minimum time, or null when none is declared or it does not apply: on a section or an\n * item-ref only in a linear part (§2.8.5). Reported only; nothing is refused (decided 2026-12-01).\n */\n minTime: number | null;\n maxTime: number | null;\n allowLateSubmission: boolean;\n /** The time spent so far: an item's `duration`, or all the time spent in a section, part or test. */\n spent: number;\n /** Seconds left before `maxTime`, never below 0; null without `maxTime`. */\n remaining: number | null;\n /** `spent` has reached `maxTime`. */\n expired: boolean;\n /**\n * Expired without `allow-late-submission`: what it limits ends (the item session, or every item\n * session in the section, part or test).\n */\n timeUp: boolean;\n /**\n * Expired with `allow-late-submission`: nothing ends, and a response given now is late (decided\n * 2026-12-01); the host decides what that means.\n */\n late: boolean;\n /** `spent` has reached `minTime`, or there is no `minTime` that applies. */\n minTimeMet: boolean;\n}\n\n/** The answers for each level that declares `qti-time-limits`; a level without one has no entry. */\nexport interface TimeLimitAnswers {\n test?: TimeLimitState;\n /** By test part identifier. */\n testParts: Record<string, TimeLimitState>;\n /** By section identifier. */\n sections: Record<string, TimeLimitState>;\n /** By item instance: each instance of an item-ref selected more than once has a limit of its own. */\n items: Record<string, TimeLimitState>;\n}\n\nconst NOT_RUN: Stopwatch = { spent: 0, since: null };\n\nfunction answer(limits: TimeLimits, stopwatch: Stopwatch, now: number, minTimeApplies: boolean): TimeLimitState {\n const spentMs = elapsed(stopwatch, now);\n const minTime = minTimeApplies ? limits.minTime : null;\n const { maxTime, allowLateSubmission } = limits;\n const expired = maxTime !== null && spentMs >= maxTime * 1000;\n return {\n minTime,\n maxTime,\n allowLateSubmission,\n spent: spentMs / 1000,\n remaining: maxTime === null ? null : Math.max(0, maxTime * 1000 - spentMs) / 1000,\n expired,\n timeUp: expired && !allowLateSubmission,\n late: expired && allowLateSubmission,\n minTimeMet: minTime === null || spentMs >= minTime * 1000\n };\n}\n\n/**\n * Each declared time limit against the time spent at `now`. `min-time` applies always on the test\n * and a part, and on a section or item-ref only in a linear part (info model §2.8.5). Pure.\n */\nexport function timeLimitRules(model: TestModel, state: DeliveryState, now: number): TimeLimitAnswers {\n const answers: TimeLimitAnswers = { testParts: {}, sections: {}, items: {} };\n if (model.timeLimits) answers.test = answer(model.timeLimits, state.timing.test, now, true);\n for (const testPart of model.testParts) {\n const linear = testPart.navigationMode === 'linear';\n if (testPart.timeLimits) {\n const stopwatch = state.timing.testParts[testPart.identifier] ?? NOT_RUN;\n answers.testParts[testPart.identifier] = answer(testPart.timeLimits, stopwatch, now, true);\n }\n for (const section of sectionsInOrder(testPart.sections)) {\n if (!section.timeLimits) continue;\n const stopwatch = state.timing.sections[section.identifier] ?? NOT_RUN;\n answers.sections[section.identifier] = answer(section.timeLimits, stopwatch, now, linear);\n }\n const limitedItemRefs = new Map(\n itemRefsInOrder(testPart.sections).flatMap(itemRef =>\n itemRef.timeLimits ? [[itemRef.identifier, itemRef.timeLimits] as const] : []\n )\n );\n for (const id of state.order) {\n const item = state.items[id];\n const limits = item && limitedItemRefs.get(item.itemRefIdentifier);\n if (limits) answers.items[id] = answer(limits, item.duration, now, linear);\n }\n }\n return answers;\n}\n"]}
1
+ {"version":3,"file":"time-limits.js","sourceRoot":"","sources":["../../src/timing/time-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,cAAc,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,KAAK,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QAC7B,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM;YAAE,OAAO,IAAI,CAAC;QAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACpE,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,OAAO,CACL,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;YAC7D,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAC7E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { itemRefsInOrder, sectionsInOrder } from '../model/test-model.js';\nimport { elapsed, placeOfItemRef } from './timing.js';\n\nimport type { TestModel, TimeLimits } from '../model/test-model.js';\nimport type { ItemInstanceId, Stopwatch } from '../state/delivery-state.js';\nimport type { TimedItem, TimingState } from './timing.js';\n\n/** What `timeLimitRules` reads: the stopwatches, and each instance's item-ref in the order of the test. */\nexport interface TimeLimitInput {\n timing: TimingState['timing'];\n /** Every item instance, in the order of the test. */\n order: readonly ItemInstanceId[];\n items: Record<ItemInstanceId, Pick<TimedItem, 'itemRefIdentifier' | 'duration'>>;\n}\n\n/**\n * Where one level stands against its `qti-time-limits` (QTI 3 info model §7.40, §2.8.5), in seconds.\n * Derived from the model and the state at a moment, never stored.\n *\n * Experimental (0.x): roadmap 1 T5.\n */\nexport interface TimeLimitState {\n /**\n * The minimum time, or null when none is declared or it does not apply: on a section or an\n * item-ref only in a linear part (§2.8.5). Reported only; nothing is refused (decided 2026-12-01).\n */\n minTime: number | null;\n maxTime: number | null;\n allowLateSubmission: boolean;\n /** The time spent so far: an item's `duration`, or all the time spent in a section, part or test. */\n spent: number;\n /** Seconds left before `maxTime`, never below 0; null without `maxTime`. */\n remaining: number | null;\n /** `spent` has reached `maxTime`. */\n expired: boolean;\n /**\n * Expired without `allow-late-submission`: what it limits ends (the item session, or every item\n * session in the section, part or test).\n */\n timeUp: boolean;\n /**\n * Expired with `allow-late-submission`: nothing ends, and a response given now is late (decided\n * 2026-12-01); the host decides what that means.\n */\n late: boolean;\n /** `spent` has reached `minTime`, or there is no `minTime` that applies. */\n minTimeMet: boolean;\n}\n\n/** The answers for each level that declares `qti-time-limits`; a level without one has no entry. */\nexport interface TimeLimitAnswers {\n test?: TimeLimitState;\n /** By test part identifier. */\n testParts: Record<string, TimeLimitState>;\n /** By section identifier. */\n sections: Record<string, TimeLimitState>;\n /** By item instance: each instance of an item-ref selected more than once has a limit of its own. */\n items: Record<string, TimeLimitState>;\n}\n\nconst NOT_RUN: Stopwatch = { spent: 0, since: null };\n\nfunction answer(limits: TimeLimits, stopwatch: Stopwatch, now: number, minTimeApplies: boolean): TimeLimitState {\n const spentMs = elapsed(stopwatch, now);\n const minTime = minTimeApplies ? limits.minTime : null;\n const { maxTime, allowLateSubmission } = limits;\n const expired = maxTime !== null && spentMs >= maxTime * 1000;\n return {\n minTime,\n maxTime,\n allowLateSubmission,\n spent: spentMs / 1000,\n remaining: maxTime === null ? null : Math.max(0, maxTime * 1000 - spentMs) / 1000,\n expired,\n timeUp: expired && !allowLateSubmission,\n late: expired && allowLateSubmission,\n minTimeMet: minTime === null || spentMs >= minTime * 1000\n };\n}\n\n/**\n * Each declared time limit against the time spent at `now`. `min-time` applies always on the test\n * and a part, and on a section or item-ref only in a linear part (info model §2.8.5). Pure.\n */\nexport function timeLimitRules(model: TestModel, state: TimeLimitInput, now: number): TimeLimitAnswers {\n const answers: TimeLimitAnswers = { testParts: {}, sections: {}, items: {} };\n if (model.timeLimits) answers.test = answer(model.timeLimits, state.timing.test, now, true);\n for (const testPart of model.testParts) {\n const linear = testPart.navigationMode === 'linear';\n if (testPart.timeLimits) {\n const stopwatch = state.timing.testParts[testPart.identifier] ?? NOT_RUN;\n answers.testParts[testPart.identifier] = answer(testPart.timeLimits, stopwatch, now, true);\n }\n for (const section of sectionsInOrder(testPart.sections)) {\n if (!section.timeLimits) continue;\n const stopwatch = state.timing.sections[section.identifier] ?? NOT_RUN;\n answers.sections[section.identifier] = answer(section.timeLimits, stopwatch, now, linear);\n }\n const limitedItemRefs = new Map(\n itemRefsInOrder(testPart.sections).flatMap(itemRef =>\n itemRef.timeLimits ? [[itemRef.identifier, itemRef.timeLimits] as const] : []\n )\n );\n for (const id of state.order) {\n const item = state.items[id];\n const limits = item && limitedItemRefs.get(item.itemRefIdentifier);\n if (limits) answers.items[id] = answer(limits, item.duration, now, linear);\n }\n }\n return answers;\n}\n\n/** What the time-up functions read of the answers: only whether each level's time is up. */\nexport interface TimeUpAnswers {\n test?: Pick<TimeLimitState, 'timeUp'>;\n testParts: Record<string, Pick<TimeLimitState, 'timeUp'>>;\n sections: Record<string, Pick<TimeLimitState, 'timeUp'>>;\n items: Record<string, Pick<TimeLimitState, 'timeUp'>>;\n}\n\n/** One level whose time is up: the test, a test part, a section or an item instance. */\nexport interface TimeUp {\n scope: 'test' | 'testPart' | 'section' | 'item';\n /** The test's, the part's or the section's identifier, or the item instance. */\n identifier: string;\n}\n\n/** Each level whose time is up (`timeUp`: expired without `allow-late-submission`), the test first. Pure. */\nexport function timeUps(model: TestModel, answers: TimeUpAnswers): TimeUp[] {\n const up = (record: Record<string, Pick<TimeLimitState, 'timeUp'>>, scope: TimeUp['scope']) =>\n Object.entries(record).flatMap(([identifier, answer]) => (answer.timeUp ? [{ scope, identifier }] : []));\n return [\n ...(answers.test?.timeUp ? [{ scope: 'test' as const, identifier: model.identifier }] : []),\n ...up(answers.testParts, 'testPart'),\n ...up(answers.sections, 'section'),\n ...up(answers.items, 'item')\n ];\n}\n\n/**\n * The item instances, in `order`, whose session a time-up ends (QTI 3 info model §7.40, §2.2.2.2):\n * every instance under the test, part or section whose time is up, with the sections nested in it,\n * and an instance whose own item-ref limit is up. The other instances of that item-ref keep their own\n * time. A delivery ends each one's session (`endItemSession`): the attempt on screen is scored as it\n * stands first, and an ended session is never opened again. Pure.\n */\nexport function closedByTimeUp(\n model: TestModel,\n state: { order: readonly ItemInstanceId[]; items: Record<ItemInstanceId, Pick<TimedItem, 'itemRefIdentifier'>> },\n answers: TimeUpAnswers\n): ItemInstanceId[] {\n if (answers.test?.timeUp) return [...state.order];\n return state.order.filter(id => {\n if (answers.items[id]?.timeUp) return true;\n const item = state.items[id];\n const place = item && placeOfItemRef(model, item.itemRefIdentifier);\n if (!place) return false;\n return (\n Boolean(answers.testParts[place.testPart.identifier]?.timeUp) ||\n place.sections.some(section => answers.sections[section.identifier]?.timeUp)\n );\n });\n}\n"]}
@@ -1,5 +1,6 @@
1
+ import type { ItemLifecycleState } from '../lifecycle/item-lifecycle.js';
1
2
  import type { SectionModel, TestModel, TestPartModel } from '../model/test-model.js';
2
- import type { DeliveryState, Stopwatch } from '../state/delivery-state.js';
3
+ import type { DeliveryTiming, ItemInstanceId, Stopwatch } from '../state/delivery-state.js';
3
4
  /**
4
5
  * The time spent in the test, its parts, its sections and each item session (roadmap 1 T5; QTI 3
5
6
  * info model §2.8.5 and §2.2.2.2), measured, never counted: each level keeps a `Stopwatch`, and a
@@ -17,6 +18,29 @@ export interface ItemRefPlace {
17
18
  }
18
19
  /** The part and the sections around an item-ref, or null when the model has no such item-ref. */
19
20
  export declare function placeOfItemRef(model: TestModel, itemRefIdentifier: string): ItemRefPlace | null;
21
+ /** What an item session contributes to the timing: a `DeliveryState` item has it, and so has a runtime's own. */
22
+ export interface TimedItem {
23
+ itemRefIdentifier: string;
24
+ lifecycle: ItemLifecycleState;
25
+ duration: Stopwatch;
26
+ }
27
+ /**
28
+ * The part of a state the timing functions read and write: a `DeliveryState` is one, and so is a
29
+ * runtime's own record until it keeps a `DeliveryState` (roadmap 1 T8). Each function returns the
30
+ * same shape it was given, with only the stopwatches changed.
31
+ */
32
+ export interface TimingState<I extends TimedItem = TimedItem> {
33
+ current: ItemInstanceId | null;
34
+ timing: DeliveryTiming;
35
+ items: Record<ItemInstanceId, I>;
36
+ }
37
+ /** What `checkpointTiming` and `resumeTiming` read: the stopwatches alone. */
38
+ export interface StoredTiming {
39
+ timing: DeliveryTiming;
40
+ items: Record<ItemInstanceId, {
41
+ duration: Stopwatch;
42
+ }>;
43
+ }
20
44
  /** What a delivery knows at an update, besides its state. */
21
45
  export interface FollowTimingInput {
22
46
  /** Milliseconds since the epoch, from the injected clock. */
@@ -35,14 +59,14 @@ export interface FollowTimingInput {
35
59
  * `modalFeedback`). A stopwatch that should stop gets its stretch added; one that should run starts
36
60
  * at `now`; the rest are untouched, so following twice changes nothing. Pure.
37
61
  */
38
- export declare function followTiming(state: DeliveryState, model: TestModel, { now, running }: FollowTimingInput): DeliveryState;
62
+ export declare function followTiming<S extends TimingState>(state: S, model: TestModel, { now, running }: FollowTimingInput): S;
39
63
  /**
40
64
  * The state to store at `now`: every running stretch added to its time and started again at `now`.
41
65
  * Read back with `resumeTiming`, a state stored this way loses at most the time since it was stored.
42
66
  */
43
- export declare function checkpointTiming(state: DeliveryState, now: number): DeliveryState;
67
+ export declare function checkpointTiming<S extends StoredTiming>(state: S, now: number): S;
44
68
  /**
45
69
  * A stored state, read back: each running stretch ends where it was stored, so the time the test was
46
70
  * closed never counts (decided 2026-12-01). `followTiming` starts what runs now.
47
71
  */
48
- export declare function resumeTiming(state: DeliveryState): DeliveryState;
72
+ export declare function resumeTiming<S extends StoredTiming>(state: S): S;
@@ -61,7 +61,7 @@ export function followTiming(state, model, { now, running }) {
61
61
  testParts: followAll(state.timing.testParts, runningParts),
62
62
  sections: followAll(state.timing.sections, runningSections)
63
63
  };
64
- const items = mapItems(state, item => ({
64
+ const items = mapItems(state.items, item => ({
65
65
  ...item,
66
66
  duration: follow(item.duration, running && item.lifecycle === 'interacting')
67
67
  }));
@@ -91,10 +91,10 @@ function mapStopwatches(state, map) {
91
91
  testParts: mapRecord(state.timing.testParts),
92
92
  sections: mapRecord(state.timing.sections)
93
93
  },
94
- items: mapItems(state, item => ({ ...item, duration: map(item.duration) }))
94
+ items: mapItems(state.items, item => ({ ...item, duration: map(item.duration) }))
95
95
  };
96
96
  }
97
- function mapItems(state, map) {
98
- return Object.fromEntries(Object.entries(state.items).map(([id, item]) => [id, map(item)]));
97
+ function mapItems(items, map) {
98
+ return Object.fromEntries(Object.entries(items).map(([id, item]) => [id, map(item)]));
99
99
  }
100
100
  //# sourceMappingURL=timing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/timing/timing.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAa,EAAE,GAAW,EAAU,EAAE,CAC1E,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;AAE5D,MAAM,KAAK,GAAG,CAAC,SAAoB,EAAE,GAAW,EAAa,EAAE,CAC7D,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhF,MAAM,IAAI,GAAG,CAAC,SAAoB,EAAE,GAAW,EAAa,EAAE,CAC5D,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,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M,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5G,OAAO;QACL,GAAG,KAAK;QACR,MAAM,EAAE;YACN,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;YAC5B,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;YAC5C,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC3C;QACD,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,KAAoB,EACpB,GAA6F;IAE7F,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import type { SectionContent, SectionModel, TestModel, TestPartModel } from '../model/test-model.js';\nimport type { DeliveryState, DeliveryTiming, ItemInstanceId, Stopwatch } from '../state/delivery-state.js';\n\n/**\n * The time spent in the test, its parts, its sections and each item session (roadmap 1 T5; QTI 3\n * info model §2.8.5 and §2.2.2.2), measured, never counted: each level keeps a `Stopwatch`, and a\n * stretch is added from the injected clock when it ends. A timer only checks the limits and repaints\n * the time left, so a throttled tab or a reload neither loses nor doubles time.\n *\n * Experimental (0.x): see `plans/delivery-state.md`.\n */\n\n/** The time on a stopwatch at `now`, in milliseconds; a clock that went back adds nothing. */\nexport const elapsed = ({ spent, since }: Stopwatch, now: number): number =>\n since === null ? spent : spent + Math.max(0, now - since);\n\nconst start = (stopwatch: Stopwatch, now: number): Stopwatch =>\n stopwatch.since === null ? { spent: stopwatch.spent, since: now } : stopwatch;\n\nconst stop = (stopwatch: Stopwatch, now: number): Stopwatch =>\n stopwatch.since === null ? stopwatch : { spent: elapsed(stopwatch, now), since: null };\n\nconst NOT_RUN: Stopwatch = Object.freeze({ spent: 0, since: null });\n\n/** Where an item-ref sits: its test part and its sections, the outermost first. */\nexport interface ItemRefPlace {\n testPart: TestPartModel;\n sections: SectionModel[];\n}\n\n/** The part and the sections around an item-ref, or null when the model has no such item-ref. */\nexport function placeOfItemRef(model: TestModel, itemRefIdentifier: string): ItemRefPlace | null {\n const find = (content: SectionContent[], around: SectionModel[]): SectionModel[] | null => {\n for (const child of content) {\n if (child.kind === 'itemRef') {\n if (child.identifier === itemRefIdentifier) return around;\n } else {\n const found = find(child.content, [...around, child]);\n if (found) return found;\n }\n }\n return null;\n };\n for (const testPart of model.testParts) {\n const sections = find(testPart.sections, []);\n if (sections) return { testPart, sections };\n }\n return null;\n}\n\n/** What a delivery knows at an update, besides its state. */\nexport interface FollowTimingInput {\n /** Milliseconds since the epoch, from the injected clock. */\n now: number;\n /**\n * The candidate session runs: the test is open in front of the candidate. False once it ends\n * (the window closed, the test suspended); test, part and section time pause then, as an item's\n * `duration` does (decided 2026-12-01).\n */\n running: boolean;\n}\n\n/**\n * The state with each stopwatch running exactly when it should, at `now`: the test, the current\n * item's test part and every section around it while the candidate session runs and an item is\n * current; each item's `duration` while its session is `interacting` (decided 2026-12-01: not in\n * `modalFeedback`). A stopwatch that should stop gets its stretch added; one that should run starts\n * at `now`; the rest are untouched, so following twice changes nothing. Pure.\n */\nexport function followTiming(\n state: DeliveryState,\n model: TestModel,\n { now, running }: FollowTimingInput\n): DeliveryState {\n const current = state.current === null ? undefined : state.items[state.current];\n const place = running && current ? placeOfItemRef(model, current.itemRefIdentifier) : null;\n const inTest = running && current !== undefined;\n const runningParts = new Set(place ? [place.testPart.identifier] : []);\n const runningSections = new Set(place?.sections.map(section => section.identifier) ?? []);\n\n const follow = (stopwatch: Stopwatch, run: boolean) => (run ? start(stopwatch, now) : stop(stopwatch, now));\n const followAll = (record: Record<string, Stopwatch>, run: ReadonlySet<string>) => {\n const followed: Record<string, Stopwatch> = {};\n for (const [identifier, stopwatch] of Object.entries(record))\n followed[identifier] = follow(stopwatch, run.has(identifier));\n for (const identifier of run) followed[identifier] ??= start(NOT_RUN, now);\n return followed;\n };\n\n const timing: DeliveryTiming = {\n test: follow(state.timing.test, inTest),\n testParts: followAll(state.timing.testParts, runningParts),\n sections: followAll(state.timing.sections, runningSections)\n };\n const items = mapItems(state, item => ({\n ...item,\n duration: follow(item.duration, running && item.lifecycle === 'interacting')\n }));\n return { ...state, timing, items };\n}\n\n/**\n * The state to store at `now`: every running stretch added to its time and started again at `now`.\n * Read back with `resumeTiming`, a state stored this way loses at most the time since it was stored.\n */\nexport function checkpointTiming(state: DeliveryState, now: number): DeliveryState {\n const checkpoint = (stopwatch: Stopwatch) =>\n stopwatch.since === null ? stopwatch : { spent: elapsed(stopwatch, now), since: now };\n return mapStopwatches(state, checkpoint);\n}\n\n/**\n * A stored state, read back: each running stretch ends where it was stored, so the time the test was\n * closed never counts (decided 2026-12-01). `followTiming` starts what runs now.\n */\nexport function resumeTiming(state: DeliveryState): DeliveryState {\n return mapStopwatches(state, ({ spent }) => ({ spent, since: null }));\n}\n\nfunction mapStopwatches(state: DeliveryState, map: (stopwatch: Stopwatch) => Stopwatch): DeliveryState {\n const mapRecord = (record: Record<string, Stopwatch>) =>\n Object.fromEntries(Object.entries(record).map(([identifier, stopwatch]) => [identifier, map(stopwatch)]));\n return {\n ...state,\n timing: {\n test: map(state.timing.test),\n testParts: mapRecord(state.timing.testParts),\n sections: mapRecord(state.timing.sections)\n },\n items: mapItems(state, item => ({ ...item, duration: map(item.duration) }))\n };\n}\n\nfunction mapItems(\n state: DeliveryState,\n map: (item: DeliveryState['items'][ItemInstanceId]) => DeliveryState['items'][ItemInstanceId]\n): DeliveryState['items'] {\n return Object.fromEntries(Object.entries(state.items).map(([id, item]) => [id, map(item)]));\n}\n"]}
1
+ {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/timing/timing.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAa,EAAE,GAAW,EAAU,EAAE,CAC1E,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;AAE5D,MAAM,KAAK,GAAG,CAAC,SAAoB,EAAE,GAAW,EAAa,EAAE,CAC7D,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAEhF,MAAM,IAAI,GAAG,CAAC,SAAoB,EAAE,GAAW,EAAa,EAAE,CAC5D,SAAS,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAEzF,MAAM,OAAO,GAAc,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAQpE,iGAAiG;AACjG,MAAM,UAAU,cAAc,CAAC,KAAgB,EAAE,iBAAyB;IACxE,MAAM,IAAI,GAAG,CAAC,OAAyB,EAAE,MAAsB,EAAyB,EAAE;QACxF,KAAK,MAAM,KAAK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C,SAAS,CAAC;YAC5C,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC3C;QACD,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;KAClF,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,KAAgC,EAChC,GAAmB;IAEnB,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC","sourcesContent":["import type { ItemLifecycleState } from '../lifecycle/item-lifecycle.js';\nimport type { SectionContent, SectionModel, TestModel, TestPartModel } from '../model/test-model.js';\nimport type { DeliveryTiming, ItemInstanceId, Stopwatch } from '../state/delivery-state.js';\n\n/**\n * The time spent in the test, its parts, its sections and each item session (roadmap 1 T5; QTI 3\n * info model §2.8.5 and §2.2.2.2), measured, never counted: each level keeps a `Stopwatch`, and a\n * stretch is added from the injected clock when it ends. A timer only checks the limits and repaints\n * the time left, so a throttled tab or a reload neither loses nor doubles time.\n *\n * Experimental (0.x): see `plans/delivery-state.md`.\n */\n\n/** The time on a stopwatch at `now`, in milliseconds; a clock that went back adds nothing. */\nexport const elapsed = ({ spent, since }: Stopwatch, now: number): number =>\n since === null ? spent : spent + Math.max(0, now - since);\n\nconst start = (stopwatch: Stopwatch, now: number): Stopwatch =>\n stopwatch.since === null ? { spent: stopwatch.spent, since: now } : stopwatch;\n\nconst stop = (stopwatch: Stopwatch, now: number): Stopwatch =>\n stopwatch.since === null ? stopwatch : { spent: elapsed(stopwatch, now), since: null };\n\nconst NOT_RUN: Stopwatch = Object.freeze({ spent: 0, since: null });\n\n/** Where an item-ref sits: its test part and its sections, the outermost first. */\nexport interface ItemRefPlace {\n testPart: TestPartModel;\n sections: SectionModel[];\n}\n\n/** The part and the sections around an item-ref, or null when the model has no such item-ref. */\nexport function placeOfItemRef(model: TestModel, itemRefIdentifier: string): ItemRefPlace | null {\n const find = (content: SectionContent[], around: SectionModel[]): SectionModel[] | null => {\n for (const child of content) {\n if (child.kind === 'itemRef') {\n if (child.identifier === itemRefIdentifier) return around;\n } else {\n const found = find(child.content, [...around, child]);\n if (found) return found;\n }\n }\n return null;\n };\n for (const testPart of model.testParts) {\n const sections = find(testPart.sections, []);\n if (sections) return { testPart, sections };\n }\n return null;\n}\n\n/** What an item session contributes to the timing: a `DeliveryState` item has it, and so has a runtime's own. */\nexport interface TimedItem {\n itemRefIdentifier: string;\n lifecycle: ItemLifecycleState;\n duration: Stopwatch;\n}\n\n/**\n * The part of a state the timing functions read and write: a `DeliveryState` is one, and so is a\n * runtime's own record until it keeps a `DeliveryState` (roadmap 1 T8). Each function returns the\n * same shape it was given, with only the stopwatches changed.\n */\nexport interface TimingState<I extends TimedItem = TimedItem> {\n current: ItemInstanceId | null;\n timing: DeliveryTiming;\n items: Record<ItemInstanceId, I>;\n}\n\n/** What `checkpointTiming` and `resumeTiming` read: the stopwatches alone. */\nexport interface StoredTiming {\n timing: DeliveryTiming;\n items: Record<ItemInstanceId, { duration: Stopwatch }>;\n}\n\n/** What a delivery knows at an update, besides its state. */\nexport interface FollowTimingInput {\n /** Milliseconds since the epoch, from the injected clock. */\n now: number;\n /**\n * The candidate session runs: the test is open in front of the candidate. False once it ends\n * (the window closed, the test suspended); test, part and section time pause then, as an item's\n * `duration` does (decided 2026-12-01).\n */\n running: boolean;\n}\n\n/**\n * The state with each stopwatch running exactly when it should, at `now`: the test, the current\n * item's test part and every section around it while the candidate session runs and an item is\n * current; each item's `duration` while its session is `interacting` (decided 2026-12-01: not in\n * `modalFeedback`). A stopwatch that should stop gets its stretch added; one that should run starts\n * at `now`; the rest are untouched, so following twice changes nothing. Pure.\n */\nexport function followTiming<S extends TimingState>(\n state: S,\n model: TestModel,\n { now, running }: FollowTimingInput\n): S {\n const current = state.current === null ? undefined : state.items[state.current];\n const place = running && current ? placeOfItemRef(model, current.itemRefIdentifier) : null;\n const inTest = running && current !== undefined;\n const runningParts = new Set(place ? [place.testPart.identifier] : []);\n const runningSections = new Set(place?.sections.map(section => section.identifier) ?? []);\n\n const follow = (stopwatch: Stopwatch, run: boolean) => (run ? start(stopwatch, now) : stop(stopwatch, now));\n const followAll = (record: Record<string, Stopwatch>, run: ReadonlySet<string>) => {\n const followed: Record<string, Stopwatch> = {};\n for (const [identifier, stopwatch] of Object.entries(record))\n followed[identifier] = follow(stopwatch, run.has(identifier));\n for (const identifier of run) followed[identifier] ??= start(NOT_RUN, now);\n return followed;\n };\n\n const timing: DeliveryTiming = {\n test: follow(state.timing.test, inTest),\n testParts: followAll(state.timing.testParts, runningParts),\n sections: followAll(state.timing.sections, runningSections)\n };\n const items = mapItems(state.items, item => ({\n ...item,\n duration: follow(item.duration, running && item.lifecycle === 'interacting')\n }));\n return { ...state, timing, items };\n}\n\n/**\n * The state to store at `now`: every running stretch added to its time and started again at `now`.\n * Read back with `resumeTiming`, a state stored this way loses at most the time since it was stored.\n */\nexport function checkpointTiming<S extends StoredTiming>(state: S, now: number): S {\n const checkpoint = (stopwatch: Stopwatch) =>\n stopwatch.since === null ? stopwatch : { spent: elapsed(stopwatch, now), since: now };\n return mapStopwatches(state, checkpoint);\n}\n\n/**\n * A stored state, read back: each running stretch ends where it was stored, so the time the test was\n * closed never counts (decided 2026-12-01). `followTiming` starts what runs now.\n */\nexport function resumeTiming<S extends StoredTiming>(state: S): S {\n return mapStopwatches(state, ({ spent }) => ({ spent, since: null }));\n}\n\nfunction mapStopwatches<S extends StoredTiming>(state: S, map: (stopwatch: Stopwatch) => Stopwatch): S {\n const mapRecord = (record: Record<string, Stopwatch>) =>\n Object.fromEntries(Object.entries(record).map(([identifier, stopwatch]) => [identifier, map(stopwatch)]));\n return {\n ...state,\n timing: {\n test: map(state.timing.test),\n testParts: mapRecord(state.timing.testParts),\n sections: mapRecord(state.timing.sections)\n },\n items: mapItems(state.items, item => ({ ...item, duration: map(item.duration) }))\n };\n}\n\nfunction mapItems<I extends { duration: Stopwatch }>(\n items: Record<ItemInstanceId, I>,\n map: (item: I) => I\n): Record<ItemInstanceId, I> {\n return Object.fromEntries(Object.entries(items).map(([id, item]) => [id, map(item)]));\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qti-components/delivery",
3
3
  "description": "The QTI 3 delivery engine: test model, item session lifecycle, sequencing and session state, with no browser globals",
4
- "version": "0.1.0-next.13",
4
+ "version": "0.1.0-next.14",
5
5
  "author": "",
6
6
  "keywords": [
7
7
  "qti",