@pie-qti/assessment-player 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +19 -16
  2. package/dist/core/AssessmentPlayer.d.ts +30 -8
  3. package/dist/core/AssessmentPlayer.d.ts.map +1 -1
  4. package/dist/core/AssessmentPlayer.js +134 -40
  5. package/dist/core/TimeManager.d.ts +9 -0
  6. package/dist/core/TimeManager.d.ts.map +1 -1
  7. package/dist/core/TimeManager.js +16 -3
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/integration/ReferenceBackendAdapter.d.ts +28 -2
  11. package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
  12. package/dist/integration/ReferenceBackendAdapter.js +385 -15
  13. package/dist/integration/api-contract.d.ts +88 -17
  14. package/dist/integration/api-contract.d.ts.map +1 -1
  15. package/dist/integration/index.d.ts +1 -1
  16. package/dist/integration/index.d.ts.map +1 -1
  17. package/dist/types/index.d.ts +1 -1
  18. package/dist/types/index.d.ts.map +1 -1
  19. package/package.json +100 -80
  20. package/src/components/AssessmentShell.svelte +8 -8
  21. package/src/components/ItemRenderer.svelte +8 -8
  22. package/src/components/NavigationBar.svelte +3 -1
  23. package/src/components/RubricDisplay.svelte +2 -2
  24. package/src/components/index.ts +1 -1
  25. package/src/core/AssessmentPlayer.ts +164 -51
  26. package/src/core/TimeManager.ts +20 -3
  27. package/src/index.ts +1 -1
  28. package/src/integration/ReferenceBackendAdapter.ts +454 -23
  29. package/src/integration/api-contract.ts +89 -17
  30. package/src/integration/index.ts +5 -5
  31. package/src/types/index.ts +1 -1
  32. package/.turbo/turbo-build.log +0 -1
  33. package/BACKEND-INTEGRATION.md +0 -620
  34. package/CHANGELOG.md +0 -11
  35. package/EXTENSIBILITY.md +0 -551
  36. package/svelte.config.js +0 -8
  37. package/tests/ReferenceBackendAdapter.spec.ts +0 -309
  38. package/tests/setup.ts +0 -103
  39. package/tests/smoke.test.ts +0 -7
  40. package/tsconfig.json +0 -20
  41. package/tsconfig.svelte.json +0 -10
@@ -8,20 +8,21 @@
8
8
  * - Apply backend navigation decisions + session state
9
9
  */
10
10
 
11
- import type { QTIRole } from '@pie-qti/item-player';
11
+ import type { QTIRole, PnpProfile } from '@pie-qti/item-player';
12
12
  import { Player } from '@pie-qti/item-player';
13
13
  import type {
14
+ AssessmentRubricBlock,
15
+ AssessmentSessionState,
16
+ AssessmentScoringResult,
14
17
  BackendAdapter,
15
18
  FinalizeAssessmentResponse,
16
19
  InitSessionRequest,
17
20
  InitSessionResponse,
18
- ScoringResult,
19
21
  SecureAssessment,
20
22
  SecureItemRef,
21
23
  SecureSection,
22
24
  SecureTestPart,
23
25
  SessionId,
24
- SessionState,
25
26
  } from '../integration/api-contract.js';
26
27
  import type {
27
28
  AssessmentResults,
@@ -36,6 +37,8 @@ export interface BackendAssessmentPlayerConfig {
36
37
  backend: BackendAdapter;
37
38
  initSession: InitSessionRequest;
38
39
  role?: QTIRole;
40
+ /** Optional RNG for deterministic shuffling in selection/ordering. Defaults to Math.random. */
41
+ rng?: () => number;
39
42
  /**
40
43
  * Optional hint for item renderers that support multiple extended text editors.
41
44
  * (Plumbed through the shell; the item player remains authoritative for behavior.)
@@ -57,6 +60,13 @@ export interface BackendAssessmentPlayerConfig {
57
60
  showProgress?: boolean;
58
61
  // Time management
59
62
  timeWarningThreshold?: number;
63
+ /**
64
+ * QTI 3.0 §6.2 Personal Needs and Preferences profile.
65
+ * Extended time (pnp.content.extendedTime) is applied to assessment timeLimits.
66
+ * The full profile is passed down to each item player for component-level features
67
+ * (color scheme, elimination tool).
68
+ */
69
+ pnp?: PnpProfile;
60
70
  // Callbacks
61
71
  onItemChange?: (itemIndex: number, totalItems: number) => void;
62
72
  onSectionChange?: (sectionIndex: number, totalSections: number) => void;
@@ -64,7 +74,7 @@ export interface BackendAssessmentPlayerConfig {
64
74
  onComplete?: () => void;
65
75
  }
66
76
 
67
- type FlatQuestion = {
77
+ type FlatItem = {
68
78
  identifier: string;
69
79
  item: SecureItemRef;
70
80
  section: SecureSection;
@@ -73,6 +83,13 @@ type FlatQuestion = {
73
83
  sectionIndex: number;
74
84
  };
75
85
 
86
+ type CurrentItemView = {
87
+ identifier: string;
88
+ title?: string;
89
+ required?: boolean;
90
+ itemXml: string;
91
+ };
92
+
76
93
  export class AssessmentPlayer {
77
94
  public static async create(config: BackendAssessmentPlayerConfig): Promise<AssessmentPlayer> {
78
95
  const init = await config.backend.initSession(config.initSession);
@@ -82,14 +99,14 @@ export class AssessmentPlayer {
82
99
  private backend: BackendAdapter;
83
100
  private sessionId: SessionId;
84
101
  private assessment: SecureAssessment;
85
- private state: SessionState;
102
+ private state: AssessmentSessionState;
86
103
  private i18nProvider: any; // I18nProvider from @pie-qti/i18n
87
104
 
88
105
  private navigationManager: NavigationManager;
89
106
  private sessionController: ItemSessionController;
90
107
  private timeManager: TimeManager | null = null;
91
108
 
92
- private questions: FlatQuestion[] = [];
109
+ private items: FlatItem[] = [];
93
110
  private currentItemIndex = -1;
94
111
  private currentItemPlayer: Player | null = null;
95
112
  private responses: Record<string, unknown> = {};
@@ -118,19 +135,20 @@ export class AssessmentPlayer {
118
135
  itemResponses: {},
119
136
  itemScores: {},
120
137
  timing: { startedAt: Date.now(), itemTimes: {}, totalTime: 0 },
121
- } as SessionState);
138
+ } as AssessmentSessionState);
122
139
 
123
- this.questions = this.flattenQuestions(this.assessment);
140
+ this.items = this.flattenItems(this.assessment);
124
141
 
125
142
  const navigationMode = this.assessment.navigationMode || 'nonlinear';
126
- this.navigationManager = new NavigationManager(navigationMode, this.questions.length);
143
+ this.navigationManager = new NavigationManager(navigationMode, this.items.length);
127
144
 
128
145
  // Item session control is a UI hint; backend remains authoritative.
146
+ // Start with testPart-level defaults; section-level overrides are applied per item in navigateTo().
129
147
  const itemSessionControl = this.assessment.testParts?.[0]?.itemSessionControl;
130
148
  this.sessionController = new ItemSessionController(itemSessionControl);
131
149
 
132
150
  // Initialize per-item session state so itemSessionControl checks work immediately.
133
- for (const q of this.questions) {
151
+ for (const q of this.items) {
134
152
  this.sessionController.initializeItem(q.identifier);
135
153
  }
136
154
 
@@ -139,6 +157,7 @@ export class AssessmentPlayer {
139
157
  this.timeManager = new TimeManager({
140
158
  assessmentTimeLimits: this.assessment.timeLimits,
141
159
  warningThreshold: config.timeWarningThreshold || 60,
160
+ extendedTime: config.pnp?.content?.extendedTime,
142
161
  onWarning: (remainingSeconds) => this.notifyTimeWarning(remainingSeconds),
143
162
  onExpired: () => this.notifyTimeExpired(),
144
163
  onTick: (remainingSeconds, elapsedSeconds) => this.notifyTimeTick(remainingSeconds, elapsedSeconds),
@@ -147,12 +166,35 @@ export class AssessmentPlayer {
147
166
 
148
167
  // Restore to backend-provided current item if present
149
168
  const startId = this.state.currentItemIdentifier;
150
- const idx = startId ? this.questions.findIndex((q) => q.identifier === startId) : -1;
169
+ const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
151
170
  if (idx >= 0) {
152
171
  this.navigateTo(idx).catch(() => {});
153
172
  }
154
173
  }
155
174
 
175
+ /**
176
+ * Compute effective itemSessionControl for a given item using three-level fallback:
177
+ * section-level (highest priority) → testPart-level → defaults.
178
+ * Section-level values override testPart-level when present.
179
+ */
180
+ private getEffectiveItemSessionControl(flat: FlatItem): SecureSection['itemSessionControl'] {
181
+ const testPartControl = flat.testPart.itemSessionControl;
182
+ const sectionControl = flat.section.itemSessionControl;
183
+
184
+ if (!sectionControl) return testPartControl;
185
+ if (!testPartControl) return sectionControl;
186
+
187
+ return {
188
+ maxAttempts: sectionControl.maxAttempts ?? testPartControl.maxAttempts,
189
+ showFeedback: sectionControl.showFeedback ?? testPartControl.showFeedback,
190
+ allowReview: sectionControl.allowReview ?? testPartControl.allowReview,
191
+ showSolution: sectionControl.showSolution ?? testPartControl.showSolution,
192
+ allowComment: sectionControl.allowComment ?? testPartControl.allowComment,
193
+ allowSkipping: sectionControl.allowSkipping ?? testPartControl.allowSkipping,
194
+ validateResponses: sectionControl.validateResponses ?? testPartControl.validateResponses,
195
+ };
196
+ }
197
+
156
198
  private hasAnyResponse(responses: Record<string, unknown>): boolean {
157
199
  for (const v of Object.values(responses)) {
158
200
  if (v == null) continue;
@@ -170,15 +212,29 @@ export class AssessmentPlayer {
170
212
  return false;
171
213
  }
172
214
 
173
- private flattenQuestions(assessment: SecureAssessment): FlatQuestion[] {
174
- const out: FlatQuestion[] = [];
215
+ private flattenItems(assessment: SecureAssessment): FlatItem[] {
216
+ const out: FlatItem[] = [];
175
217
  const testParts = assessment.testParts || [];
176
218
  let idx = 0;
177
219
  let secIdx = 0;
220
+ const rng = this.config.rng ?? Math.random;
178
221
 
179
222
  for (const tp of testParts) {
180
223
  for (const section of tp.sections || []) {
181
- for (const item of section.items || []) {
224
+ let refs = [...(section.assessmentItemRefs || [])];
225
+
226
+ // QTI ordering: shuffle items within the section when requested.
227
+ // The server may have already shuffled; if not (e.g. reference adapter), do it client-side.
228
+ if (section.ordering?.shuffle) {
229
+ refs = shuffleArray(refs, rng);
230
+ }
231
+
232
+ // QTI selection: take only `select` items from the (possibly shuffled) list.
233
+ if (section.selection && section.selection.select > 0 && section.selection.select < refs.length) {
234
+ refs = refs.slice(0, section.selection.select);
235
+ }
236
+
237
+ for (const item of refs) {
182
238
  out.push({
183
239
  identifier: item.identifier,
184
240
  item,
@@ -210,10 +266,10 @@ export class AssessmentPlayer {
210
266
  }
211
267
 
212
268
  public getNavigationState(): NavigationState {
213
- const total = this.questions.length;
269
+ const total = this.items.length;
214
270
  const canPrevious = this.canPrevious();
215
271
  const canNext = this.canNext();
216
- const q = this.questions[this.currentItemIndex];
272
+ const q = this.items[this.currentItemIndex];
217
273
  const totalSections = this.getAllSections().length;
218
274
  return {
219
275
  currentIndex: this.currentItemIndex,
@@ -228,10 +284,9 @@ export class AssessmentPlayer {
228
284
  };
229
285
  }
230
286
 
231
- public getCurrentQuestion(): any | null {
232
- const q = this.questions[this.currentItemIndex];
287
+ public getCurrentItem(): CurrentItemView | null {
288
+ const q = this.items[this.currentItemIndex];
233
289
  if (!q) return null;
234
- // Keep the legacy QuestionRef-ish shape expected by ItemRenderer.svelte
235
290
  return {
236
291
  identifier: q.item.identifier,
237
292
  title: q.section.title,
@@ -240,10 +295,10 @@ export class AssessmentPlayer {
240
295
  };
241
296
  }
242
297
 
243
- public getCurrentRubricBlocks(): any[] {
244
- const q = this.questions[this.currentItemIndex];
298
+ public getCurrentRubricBlocks(): AssessmentRubricBlock[] {
299
+ const q = this.items[this.currentItemIndex];
245
300
  if (!q) return [];
246
- return q.section.rubrics || q.testPart.rubrics || [];
301
+ return q.section.rubricBlocks || q.testPart.rubricBlocks || [];
247
302
  }
248
303
 
249
304
  public getVisibleFeedback(): Array<{ identifier: string; content: string; access: string }> {
@@ -252,7 +307,7 @@ export class AssessmentPlayer {
252
307
 
253
308
  public updateResponse(responseId: string, value: unknown): void {
254
309
  this.responses = { ...this.responses, [responseId]: value };
255
- const q = this.questions[this.currentItemIndex];
310
+ const q = this.items[this.currentItemIndex];
256
311
  if (q) {
257
312
  this.state.itemResponses[q.identifier] = this.responses as any;
258
313
  this.sessionController.markAnswered(q.identifier, this.hasAnyResponse(this.responses));
@@ -272,7 +327,7 @@ export class AssessmentPlayer {
272
327
  this.state.itemResponses[itemIdentifier] = next as any;
273
328
 
274
329
  // If this is the active item, keep the live response state + UI hints in sync.
275
- const active = this.questions[this.currentItemIndex];
330
+ const active = this.items[this.currentItemIndex];
276
331
  if (active?.identifier === itemIdentifier) {
277
332
  this.responses = next;
278
333
  this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(this.responses));
@@ -293,7 +348,7 @@ export class AssessmentPlayer {
293
348
  * Get the current session state snapshot (client-side view).
294
349
  * Note: backend remains authoritative; this is intended for simple save/resume.
295
350
  */
296
- public getState(): SessionState {
351
+ public getState(): AssessmentSessionState {
297
352
  // Shallow clone to avoid accidental external mutation.
298
353
  return {
299
354
  ...this.state,
@@ -310,12 +365,12 @@ export class AssessmentPlayer {
310
365
  /**
311
366
  * Restore a previously saved session state.
312
367
  */
313
- public async restoreState(state: SessionState): Promise<void> {
368
+ public async restoreState(state: AssessmentSessionState): Promise<void> {
314
369
  this.state = state;
315
370
 
316
371
  // Restore visited state for UI navigation hints.
317
372
  const visitedIdx = (state.visitedItems || [])
318
- .map((id) => this.questions.findIndex((q) => q.identifier === id))
373
+ .map((id) => this.items.findIndex((q) => q.identifier === id))
319
374
  .filter((i) => i >= 0);
320
375
  this.navigationManager.restoreState(visitedIdx);
321
376
 
@@ -333,16 +388,16 @@ export class AssessmentPlayer {
333
388
  }
334
389
 
335
390
  const currentId = state.currentItemIdentifier;
336
- const idx = currentId ? this.questions.findIndex((q) => q.identifier === currentId) : -1;
391
+ const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
337
392
  if (idx >= 0) {
338
393
  await this.navigateTo(idx);
339
- } else if (this.questions.length > 0) {
394
+ } else if (this.items.length > 0) {
340
395
  await this.navigateTo(0);
341
396
  }
342
397
  }
343
398
 
344
399
  public async navigateTo(index: number): Promise<void> {
345
- if (index < 0 || index >= this.questions.length) throw new Error(`Invalid item index: ${index}`);
400
+ if (index < 0 || index >= this.items.length) throw new Error(`Invalid item index: ${index}`);
346
401
 
347
402
  // Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
348
403
  if (this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
@@ -351,15 +406,21 @@ export class AssessmentPlayer {
351
406
  }
352
407
  throw new Error('Navigation is not allowed.');
353
408
  }
354
- const target = this.questions[index];
409
+ const target = this.items[index];
355
410
  if (target && !this.sessionController.canReview(target.identifier)) {
356
411
  throw new Error('You cannot go back to previous questions in this assessment.');
357
412
  }
358
413
 
359
414
  this.currentItemIndex = index;
360
- const q = this.questions[index]!;
415
+ const q = this.items[index]!;
361
416
  this.state.currentItemIdentifier = q.identifier;
362
417
 
418
+ // Apply three-level itemSessionControl fallback for this item's section (S1).
419
+ const effectiveControl = this.getEffectiveItemSessionControl(q);
420
+ if (effectiveControl) {
421
+ this.sessionController.updateSettings(effectiveControl);
422
+ }
423
+
363
424
  // Restore responses
364
425
  this.responses = { ...(this.state.itemResponses[q.identifier] || {}) };
365
426
 
@@ -376,7 +437,7 @@ export class AssessmentPlayer {
376
437
  }
377
438
 
378
439
  public async navigateToSection(sectionId: string): Promise<void> {
379
- const idx = this.questions.findIndex((q) => q.section.identifier === sectionId);
440
+ const idx = this.items.findIndex((q) => q.section.identifier === sectionId);
380
441
  if (idx >= 0) await this.navigateTo(idx);
381
442
  }
382
443
 
@@ -384,7 +445,7 @@ export class AssessmentPlayer {
384
445
  const state = this.getNavigationState();
385
446
  if (!state.canNext) return;
386
447
 
387
- const q = this.questions[this.currentItemIndex];
448
+ const q = this.items[this.currentItemIndex];
388
449
  if (q) {
389
450
  const hasResponses = this.hasAnyResponse(this.responses);
390
451
  this.sessionController.markAnswered(q.identifier, hasResponses);
@@ -414,7 +475,7 @@ export class AssessmentPlayer {
414
475
 
415
476
  /** Submit current item (server-side scoring) */
416
477
  public async submitCurrentItem(): Promise<ItemResult> {
417
- const q = this.questions[this.currentItemIndex];
478
+ const q = this.items[this.currentItemIndex];
418
479
  if (!q) throw new Error('No current item');
419
480
 
420
481
  const submittedAt = Date.now();
@@ -456,11 +517,36 @@ export class AssessmentPlayer {
456
517
  this.sessionController.markAnswered(q.identifier, this.hasAnyResponse(this.responses));
457
518
  this.navigationManager.markVisited(this.currentItemIndex);
458
519
 
459
- // Apply backend branching decision if provided
520
+ // Apply backend branching decision if provided.
521
+ // Special QTI targets EXIT_TEST / EXIT_TESTPART / EXIT_SECTION trigger finalization.
460
522
  if (res.nextItemIdentifier) {
461
- const nextIdx = this.questions.findIndex((x) => x.identifier === res.nextItemIdentifier);
462
- if (nextIdx >= 0) {
463
- await this.navigateTo(nextIdx);
523
+ const special = res.nextItemIdentifier;
524
+ if (special === 'EXIT_TEST') {
525
+ // Finalize immediately — no further navigation
526
+ for (const l of this.completeListeners) l();
527
+ this.config.onComplete?.();
528
+ } else if (special === 'EXIT_TESTPART' || special === 'EXIT_SECTION') {
529
+ // Advance past all remaining items in the current testPart or section
530
+ const currentItem = this.items[this.currentItemIndex];
531
+ const isSection = special === 'EXIT_SECTION';
532
+ const nextIdx = this.items.findIndex((item, i) =>
533
+ i > this.currentItemIndex &&
534
+ (isSection
535
+ ? item.section.identifier !== currentItem?.section.identifier
536
+ : item.testPart.identifier !== currentItem?.testPart.identifier)
537
+ );
538
+ if (nextIdx >= 0) {
539
+ await this.navigateTo(nextIdx);
540
+ } else {
541
+ // No further items — signal completion
542
+ for (const l of this.completeListeners) l();
543
+ this.config.onComplete?.();
544
+ }
545
+ } else {
546
+ const nextIdx = this.items.findIndex((x) => x.identifier === special);
547
+ if (nextIdx >= 0) {
548
+ await this.navigateTo(nextIdx);
549
+ }
464
550
  }
465
551
  }
466
552
 
@@ -469,7 +555,7 @@ export class AssessmentPlayer {
469
555
 
470
556
  private canPrevious(): boolean {
471
557
  if (this.currentItemIndex <= 0) return false;
472
- const prev = this.questions[this.currentItemIndex - 1];
558
+ const prev = this.items[this.currentItemIndex - 1];
473
559
  if (!prev) return false;
474
560
  if (!this.navigationManager.canNavigateTo(this.currentItemIndex - 1, this.currentItemIndex)) return false;
475
561
  return this.sessionController.canReview(prev.identifier);
@@ -478,7 +564,7 @@ export class AssessmentPlayer {
478
564
  private canNext(): boolean {
479
565
  if (this.currentItemIndex < 0) return false;
480
566
  const nextIdx = this.currentItemIndex + 1;
481
- if (nextIdx >= this.questions.length) return false;
567
+ if (nextIdx >= this.items.length) return false;
482
568
  if (!this.navigationManager.canNavigateTo(nextIdx, this.currentItemIndex)) return false;
483
569
  // Note: itemSessionControl constraints on leaving current item are enforced in next().
484
570
  return true;
@@ -495,7 +581,7 @@ export class AssessmentPlayer {
495
581
  // wipe out responses for later items during this loop.
496
582
  const allItemResponses = { ...(this.state.itemResponses || {}) } as any;
497
583
 
498
- for (const q of this.questions) {
584
+ for (const q of this.items) {
499
585
  if (this.itemResults.has(q.identifier)) continue;
500
586
  const submittedAt = Date.now();
501
587
  const responsesForItem = (allItemResponses?.[q.identifier] || {}) as any;
@@ -527,7 +613,7 @@ export class AssessmentPlayer {
527
613
  }
528
614
  } else {
529
615
  // Ensure current item is submitted (individual submission mode)
530
- const q = this.questions[this.currentItemIndex];
616
+ const q = this.items[this.currentItemIndex];
531
617
  if (q && !this.itemResults.has(q.identifier)) {
532
618
  await this.submitCurrentItem();
533
619
  }
@@ -540,16 +626,33 @@ export class AssessmentPlayer {
540
626
 
541
627
  // Map backend itemScores to ItemResult[]
542
628
  const itemScores = finalized.itemScores || {};
543
- const itemResults: ItemResult[] = Object.values(itemScores).map((r: ScoringResult) => ({
629
+ const itemResults: ItemResult[] = Object.values(itemScores).map((r: AssessmentScoringResult) => ({
544
630
  itemIdentifier: r.itemIdentifier,
545
631
  score: r.score,
546
632
  maxScore: r.maxScore,
547
633
  responses: this.state.itemResponses[r.itemIdentifier] || {},
548
634
  }));
549
635
 
550
- this.visibleFeedback = finalized.feedback
551
- ? [{ identifier: 'testFeedback', content: finalized.feedback, access: 'atEnd' }]
552
- : [];
636
+ // Evaluate testFeedback visibility using QTI string equality:
637
+ // show when outcomeIdentifier's value equals feedback.identifier (for showHide='show'),
638
+ // or does NOT equal it (for showHide='hide').
639
+ const structuredFeedback = this.assessment.testFeedback ?? [];
640
+ const outcomes = finalized.outcomes ?? {};
641
+ if (structuredFeedback.length > 0) {
642
+ this.visibleFeedback = structuredFeedback
643
+ .filter((fb) => fb.access === 'atEnd')
644
+ .filter((fb) => {
645
+ const outcomeValue = String(outcomes[fb.outcomeIdentifier] ?? '');
646
+ const matches = outcomeValue === fb.identifier;
647
+ return fb.showHide === 'show' ? matches : !matches;
648
+ })
649
+ .map((fb) => ({ identifier: fb.identifier, content: fb.content, access: fb.access }));
650
+ } else {
651
+ // Legacy: backend returns a plain feedback string
652
+ this.visibleFeedback = finalized.feedback
653
+ ? [{ identifier: 'testFeedback', content: finalized.feedback, access: 'atEnd' }]
654
+ : [];
655
+ }
553
656
 
554
657
  this.notifyComplete();
555
658
  if (this.config.onComplete) this.config.onComplete();
@@ -575,7 +678,7 @@ export class AssessmentPlayer {
575
678
  canReview: boolean;
576
679
  canSkip: boolean;
577
680
  } | null {
578
- const q = this.questions[this.currentItemIndex];
681
+ const q = this.items[this.currentItemIndex];
579
682
  if (!q) return null;
580
683
  const id = q.identifier;
581
684
 
@@ -663,12 +766,12 @@ export class AssessmentPlayer {
663
766
  // ---------------------------------------------------------------------------
664
767
 
665
768
  private notifyItemChange(): void {
666
- for (const l of this.itemChangeListeners) l(this.currentItemIndex, this.questions.length);
667
- this.config.onItemChange?.(this.currentItemIndex, this.questions.length);
769
+ for (const l of this.itemChangeListeners) l(this.currentItemIndex, this.items.length);
770
+ this.config.onItemChange?.(this.currentItemIndex, this.items.length);
668
771
  }
669
772
 
670
773
  private notifySectionChange(): void {
671
- const q = this.questions[this.currentItemIndex];
774
+ const q = this.items[this.currentItemIndex];
672
775
  const sectionIndex = q?.sectionIndex ?? 0;
673
776
  const totalSections = this.getAllSections().length;
674
777
  for (const l of this.sectionChangeListeners) l(sectionIndex, totalSections);
@@ -718,3 +821,13 @@ export class AssessmentPlayer {
718
821
  };
719
822
  }
720
823
  }
824
+
825
+ /** Fisher-Yates shuffle using a provided RNG (returns a new array). */
826
+ function shuffleArray<T>(arr: T[], rng: () => number): T[] {
827
+ const out = [...arr];
828
+ for (let i = out.length - 1; i > 0; i--) {
829
+ const j = Math.floor(rng() * (i + 1));
830
+ [out[i], out[j]] = [out[j], out[i]];
831
+ }
832
+ return out;
833
+ }
@@ -25,6 +25,12 @@ export interface TimeManagerConfig {
25
25
  onExpired?: () => void;
26
26
  /** Callback for time updates (fires every second) */
27
27
  onTick?: (remainingSeconds: number, elapsedSeconds: number) => void;
28
+ /**
29
+ * QTI 3.0 PNP extended time accommodation.
30
+ * When active, multiplies assessmentTimeLimits.maxTime by the given multiplier.
31
+ * multiplier: Infinity removes the time limit entirely.
32
+ */
33
+ extendedTime?: { active: boolean; multiplier: number };
28
34
  }
29
35
 
30
36
  export interface TimeTrackingState {
@@ -63,10 +69,21 @@ export class TimeManager {
63
69
  isPaused: false,
64
70
  };
65
71
 
66
- // Initialize timer if time limit exists
72
+ // Initialize timer if time limit exists, applying PNP extended-time multiplier if set.
67
73
  if (config.assessmentTimeLimits?.maxTime) {
68
- this.maxTimeSeconds = config.assessmentTimeLimits.maxTime;
69
- this.startTimer();
74
+ const base = config.assessmentTimeLimits.maxTime;
75
+ const et = config.extendedTime;
76
+ if (et?.active && et.multiplier === Infinity) {
77
+ // multiplier: Infinity → unlimited time (no countdown)
78
+ this.maxTimeSeconds = null;
79
+ } else if (et?.active && et.multiplier > 0) {
80
+ this.maxTimeSeconds = base * et.multiplier;
81
+ } else {
82
+ this.maxTimeSeconds = base;
83
+ }
84
+ if (this.maxTimeSeconds !== null) {
85
+ this.startTimer();
86
+ }
70
87
  }
71
88
  }
72
89
 
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ export { AssessmentPlayer, NavigationManager } from './core/index.js';
6
6
  // Backend integration API + reference adapter
7
7
  export * from './integration/index.js';
8
8
  // Public UI/data types
9
- export type { AssessmentResults, ItemResult, NavigationState, QTIRole, QuestionRef } from './types/index.js';
9
+ export type { AssessmentResults, ItemRef, ItemResult, NavigationState, QTIRole } from './types/index.js';
10
10
 
11
11
  // Components are exported via package.json "exports" field
12
12
  // Users can import them like: