@pie-qti/assessment-player 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/AssessmentPlayer.d.ts +27 -5
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +211 -20
- package/dist/integration/ReferenceBackendAdapter.d.ts +1 -7
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +144 -61
- package/dist/integration/api-contract.d.ts +39 -11
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +14 -0
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -0
- package/dist/integration/assessment-item-scorer.js +43 -0
- package/dist/integration/index.d.ts +2 -1
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/integration/index.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/components/AccessibilityAnnouncer.svelte +13 -2
- package/src/components/AssessmentShell.svelte +22 -39
- package/src/components/AssessmentTimer.svelte +23 -0
- package/src/components/ItemRenderer.svelte +14 -4
- package/src/components/NavigationBar.svelte +2 -0
- package/src/components/SectionMenu.svelte +72 -5
- package/src/core/AssessmentPlayer.ts +249 -23
- package/src/integration/ReferenceBackendAdapter.ts +155 -65
- package/src/integration/api-contract.ts +42 -11
- package/src/integration/assessment-item-scorer.ts +58 -0
- package/src/integration/index.ts +7 -0
- package/src/types/index.ts +3 -0
|
@@ -61,41 +61,13 @@
|
|
|
61
61
|
const nonPassageRubricBlocks = $derived(currentRubricBlocks.filter((b) => b?.use !== 'passage'));
|
|
62
62
|
const hasPassage = $derived(passageBlocks.length > 0);
|
|
63
63
|
|
|
64
|
-
// Fallback: listen at the shell root for any `qti-change` custom events from nested
|
|
65
|
-
// web components. Use a reactive effect so we attach even if `rootEl` is set after mount.
|
|
66
|
-
function handleRootQtiChange(e: Event) {
|
|
67
|
-
const ce = e as CustomEvent;
|
|
68
|
-
const detail = (ce as any).detail;
|
|
69
|
-
if (!detail) return;
|
|
70
|
-
const { responseId, value } = detail;
|
|
71
|
-
if (responseId) {
|
|
72
|
-
handleResponseChange(responseId, value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
$effect(() => {
|
|
77
|
-
if (!rootEl) return;
|
|
78
|
-
rootEl.addEventListener('qti-change', handleRootQtiChange as EventListener);
|
|
79
|
-
return () => rootEl?.removeEventListener('qti-change', handleRootQtiChange as EventListener);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
64
|
// Initialize player
|
|
83
65
|
onMount(() => {
|
|
84
|
-
// Capture bubbled `qti-change` events at the document level as a safety net.
|
|
85
|
-
// This ensures responses are recorded even if an intermediate renderer misses the event.
|
|
86
|
-
const handleDocumentQtiChange = (e: Event) => {
|
|
87
|
-
const ce = e as CustomEvent;
|
|
88
|
-
const detail = (ce as any).detail;
|
|
89
|
-
if (!detail) return;
|
|
90
|
-
const { responseId, value } = detail;
|
|
91
|
-
if (responseId) handleResponseChange(responseId, value);
|
|
92
|
-
};
|
|
93
|
-
document.addEventListener('qti-change', handleDocumentQtiChange as EventListener);
|
|
94
|
-
|
|
95
66
|
// Never allow infinite "Loading assessment..." state
|
|
96
67
|
initTimeout = setTimeout(() => {
|
|
97
68
|
if (!hasFirstItem && !error) {
|
|
98
69
|
error = contextI18n?.t('assessment.loadingError') ?? 'assessment.loadingError';
|
|
70
|
+
announcer?.announce(error, 3000, 'assertive');
|
|
99
71
|
}
|
|
100
72
|
}, 10000);
|
|
101
73
|
|
|
@@ -139,15 +111,21 @@
|
|
|
139
111
|
// If backend did not restore a current item, start at index 0.
|
|
140
112
|
if (player.getNavigationState().currentIndex < 0) {
|
|
141
113
|
await player.navigateTo(0);
|
|
114
|
+
} else {
|
|
115
|
+
updateState();
|
|
116
|
+
hasFirstItem = true;
|
|
117
|
+
if (initTimeout) {
|
|
118
|
+
clearTimeout(initTimeout);
|
|
119
|
+
initTimeout = null;
|
|
120
|
+
}
|
|
142
121
|
}
|
|
143
122
|
})().catch((err) => {
|
|
144
123
|
console.error('Failed to initialize assessment player:', err);
|
|
145
124
|
error = err instanceof Error ? err.message : (contextI18n?.t('assessment.loadingError') ?? 'assessment.loadingError');
|
|
125
|
+
announcer?.announce(error, 3000, 'assertive');
|
|
146
126
|
});
|
|
147
127
|
|
|
148
128
|
return () => {
|
|
149
|
-
document.removeEventListener('qti-change', handleDocumentQtiChange as EventListener);
|
|
150
|
-
rootEl?.removeEventListener('qti-change', handleRootQtiChange as EventListener);
|
|
151
129
|
if (initTimeout) {
|
|
152
130
|
clearTimeout(initTimeout);
|
|
153
131
|
initTimeout = null;
|
|
@@ -176,7 +154,8 @@
|
|
|
176
154
|
announceCurrentQuestion();
|
|
177
155
|
} catch (err) {
|
|
178
156
|
console.error('Previous navigation failed:', err);
|
|
179
|
-
|
|
157
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.navigationFailed') ?? 'assessment.errors.navigationFailed');
|
|
158
|
+
navError = message;
|
|
180
159
|
}
|
|
181
160
|
}
|
|
182
161
|
|
|
@@ -189,7 +168,8 @@
|
|
|
189
168
|
announceCurrentQuestion();
|
|
190
169
|
} catch (err) {
|
|
191
170
|
console.error('Next navigation failed:', err);
|
|
192
|
-
|
|
171
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.navigationFailed') ?? 'assessment.errors.navigationFailed');
|
|
172
|
+
navError = message;
|
|
193
173
|
}
|
|
194
174
|
}
|
|
195
175
|
|
|
@@ -251,7 +231,9 @@
|
|
|
251
231
|
// Or show results modal
|
|
252
232
|
} catch (err) {
|
|
253
233
|
console.error('Failed to submit assessment:', err);
|
|
254
|
-
|
|
234
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.submitFailed') ?? 'assessment.errors.submitFailed');
|
|
235
|
+
error = message;
|
|
236
|
+
announcer?.announce(message, 3000, 'assertive');
|
|
255
237
|
}
|
|
256
238
|
}
|
|
257
239
|
|
|
@@ -305,7 +287,7 @@
|
|
|
305
287
|
|
|
306
288
|
{#if error}
|
|
307
289
|
<div class="assessment-error">
|
|
308
|
-
<div class="alert alert-error">
|
|
290
|
+
<div class="alert alert-error" role="alert" aria-live="assertive">
|
|
309
291
|
<svg
|
|
310
292
|
xmlns="http://www.w3.org/2000/svg"
|
|
311
293
|
class="stroke-current shrink-0 h-6 w-6"
|
|
@@ -324,13 +306,13 @@
|
|
|
324
306
|
</div>
|
|
325
307
|
{:else if !player || navState.currentIndex < 0}
|
|
326
308
|
<div class="assessment-loading">
|
|
327
|
-
<div class="flex items-center justify-center p-8">
|
|
309
|
+
<div class="flex items-center justify-center p-8" role="status" aria-live="polite">
|
|
328
310
|
<span class="loading loading-spinner loading-lg"></span>
|
|
329
311
|
<span class="ml-4">{contextI18n?.t('assessment.loading') ?? 'assessment.loading'}</span>
|
|
330
312
|
</div>
|
|
331
313
|
</div>
|
|
332
314
|
{:else}
|
|
333
|
-
<div bind:this={rootEl} class="assessment-shell" role="
|
|
315
|
+
<div bind:this={rootEl} class="assessment-shell" role="region" aria-label="Assessment player">
|
|
334
316
|
<!-- Header with title and section menu -->
|
|
335
317
|
<AssessmentHeader
|
|
336
318
|
title={initSession.assessmentId || (i18n?.t('assessment.title') ?? 'Assessment')}
|
|
@@ -348,7 +330,7 @@
|
|
|
348
330
|
|
|
349
331
|
{#if navError}
|
|
350
332
|
<div class="assessment-nav-error">
|
|
351
|
-
<div class="alert alert-warning">
|
|
333
|
+
<div class="alert alert-warning" role="alert" aria-live="assertive">
|
|
352
334
|
<svg
|
|
353
335
|
xmlns="http://www.w3.org/2000/svg"
|
|
354
336
|
class="stroke-current shrink-0 h-6 w-6"
|
|
@@ -374,7 +356,6 @@
|
|
|
374
356
|
tabindex="-1"
|
|
375
357
|
role="region"
|
|
376
358
|
aria-label={i18n?.t('accessibility.itemBody') ?? 'Question content'}
|
|
377
|
-
aria-live="polite"
|
|
378
359
|
>
|
|
379
360
|
{#if hasPassage}
|
|
380
361
|
<SplitPaneResizer
|
|
@@ -397,6 +378,7 @@
|
|
|
397
378
|
{typeset}
|
|
398
379
|
{i18n}
|
|
399
380
|
security={config.security}
|
|
381
|
+
pnp={config.pnp}
|
|
400
382
|
/>
|
|
401
383
|
{/if}
|
|
402
384
|
</SplitPaneResizer>
|
|
@@ -416,6 +398,7 @@
|
|
|
416
398
|
{typeset}
|
|
417
399
|
{i18n}
|
|
418
400
|
security={config.security}
|
|
401
|
+
pnp={config.pnp}
|
|
419
402
|
/>
|
|
420
403
|
{/if}
|
|
421
404
|
{/if}
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
let elapsedSeconds = $state(0);
|
|
20
20
|
let isWarning = $state(false);
|
|
21
21
|
let isExpired = $state(false);
|
|
22
|
+
let announcement = $state('');
|
|
23
|
+
let announcementPriority = $state<'polite' | 'assertive'>('polite');
|
|
22
24
|
|
|
23
25
|
// Initialize state and subscribe to timer events
|
|
24
26
|
$effect(() => {
|
|
@@ -31,11 +33,17 @@
|
|
|
31
33
|
const unsubscribeWarning = player.onTimeWarning((remaining) => {
|
|
32
34
|
isWarning = true;
|
|
33
35
|
remainingSeconds = remaining;
|
|
36
|
+
announcementPriority = 'polite';
|
|
37
|
+
announcement =
|
|
38
|
+
i18n?.t('assessment.timer.timeRemaining', { time: TimeManager.formatTime(remaining) }) ??
|
|
39
|
+
`Time remaining: ${TimeManager.formatTime(remaining)}`;
|
|
34
40
|
});
|
|
35
41
|
|
|
36
42
|
const unsubscribeExpired = player.onTimeExpired(() => {
|
|
37
43
|
isExpired = true;
|
|
38
44
|
remainingSeconds = 0;
|
|
45
|
+
announcementPriority = 'assertive';
|
|
46
|
+
announcement = i18n?.t('assessment.timer.expired') ?? 'Time expired';
|
|
39
47
|
});
|
|
40
48
|
|
|
41
49
|
const unsubscribeTick = player.onTimeTick((remaining, elapsed) => {
|
|
@@ -106,6 +114,9 @@
|
|
|
106
114
|
<div class="timer-label">{timerLabel()}</div>
|
|
107
115
|
<div class="timer-value">{displayTime()}</div>
|
|
108
116
|
</div>
|
|
117
|
+
<div class="sr-only" role={announcementPriority === 'assertive' ? 'alert' : 'status'} aria-live={announcementPriority} aria-atomic="true">
|
|
118
|
+
{announcement}
|
|
119
|
+
</div>
|
|
109
120
|
</div>
|
|
110
121
|
{/if}
|
|
111
122
|
|
|
@@ -170,6 +181,18 @@
|
|
|
170
181
|
color: hsl(var(--bc));
|
|
171
182
|
}
|
|
172
183
|
|
|
184
|
+
.sr-only {
|
|
185
|
+
position: absolute;
|
|
186
|
+
width: 1px;
|
|
187
|
+
height: 1px;
|
|
188
|
+
padding: 0;
|
|
189
|
+
margin: -1px;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
clip: rect(0, 0, 0, 0);
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
border-width: 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
173
196
|
.assessment-timer.warning .timer-value {
|
|
174
197
|
color: hsl(var(--wa));
|
|
175
198
|
}
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
import { registerDefaultComponents } from '@pie-qti/default-components';
|
|
4
4
|
// @ts-expect-error - Svelte-check can't resolve workspace subpath exports, but runtime works correctly
|
|
5
5
|
import { ItemBody } from '@pie-qti/item-player/components';
|
|
6
|
-
import { Player, type PlayerSecurityConfig, type QTIRole } from '@pie-qti/item-player';
|
|
6
|
+
import { Player, type PlayerSecurityConfig, type PnpProfile, type QTIRole } from '@pie-qti/item-player';
|
|
7
|
+
import type { InteractionResponseValue } from '@pie-qti/item-player/web-components';
|
|
7
8
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
8
9
|
import { onMount } from 'svelte';
|
|
9
10
|
import type { ItemRef } from '../types/index.js';
|
|
10
11
|
|
|
12
|
+
type ItemResponseValue = InteractionResponseValue | null;
|
|
13
|
+
type ItemResponseMap = Record<string, ItemResponseValue>;
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* Ensure default interaction web components are registered (browser-only).
|
|
13
17
|
*
|
|
@@ -34,14 +38,16 @@
|
|
|
34
38
|
role?: QTIRole;
|
|
35
39
|
extendedTextEditor?: string;
|
|
36
40
|
/** Responses for the current item (keyed by responseIdentifier). */
|
|
37
|
-
responses?:
|
|
38
|
-
onResponseChange?: (responseId: string, value:
|
|
41
|
+
responses?: ItemResponseMap;
|
|
42
|
+
onResponseChange?: (responseId: string, value: ItemResponseValue) => void;
|
|
39
43
|
/** Math typesetting function (KaTeX, MathJax, etc.) */
|
|
40
44
|
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
41
45
|
/** I18n provider for translations */
|
|
42
46
|
i18n?: I18nProvider;
|
|
43
47
|
/** Security configuration for URL policy and content restrictions */
|
|
44
48
|
security?: PlayerSecurityConfig;
|
|
49
|
+
/** QTI 3.0 Personal Needs and Preferences profile */
|
|
50
|
+
pnp?: PnpProfile;
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
const {
|
|
@@ -53,6 +59,7 @@
|
|
|
53
59
|
typeset,
|
|
54
60
|
i18n,
|
|
55
61
|
security,
|
|
62
|
+
pnp,
|
|
56
63
|
}: Props = $props();
|
|
57
64
|
|
|
58
65
|
// Derive player from itemRef
|
|
@@ -66,6 +73,8 @@
|
|
|
66
73
|
itemXml: itemRef.itemXml,
|
|
67
74
|
role,
|
|
68
75
|
security,
|
|
76
|
+
pnp,
|
|
77
|
+
deliveryContext: itemRef.deliveryContext,
|
|
69
78
|
});
|
|
70
79
|
|
|
71
80
|
// Ensure the item player can actually render interactions by registering the
|
|
@@ -86,7 +95,7 @@
|
|
|
86
95
|
});
|
|
87
96
|
|
|
88
97
|
// Handle response changes
|
|
89
|
-
function handleResponseChange(responseId: string, value:
|
|
98
|
+
function handleResponseChange(responseId: string, value: ItemResponseValue) {
|
|
90
99
|
onResponseChange?.(responseId, value);
|
|
91
100
|
}
|
|
92
101
|
</script>
|
|
@@ -129,6 +138,7 @@
|
|
|
129
138
|
{role}
|
|
130
139
|
{typeset}
|
|
131
140
|
{i18n}
|
|
141
|
+
deliveryContext={itemRef.deliveryContext}
|
|
132
142
|
onResponseChange={handleResponseChange}
|
|
133
143
|
/>
|
|
134
144
|
</div>
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
previous: i18n?.t('common.previous') ?? 'Previous',
|
|
30
30
|
next: i18n?.t('common.next') ?? 'Next',
|
|
31
31
|
submit: i18n?.t('assessment.navigation.submit') ?? 'Submit',
|
|
32
|
+
progress: `${i18n?.t('assessment.navigation.progress', { percent: Math.round(progressPercentage) }) ?? `Progress: ${Math.round(progressPercentage)}%`}: ${i18n?.t('assessment.question', { current: navState.currentIndex + 1, total: navState.totalItems }) ?? `Question ${navState.currentIndex + 1} of ${navState.totalItems}`}`,
|
|
32
33
|
});
|
|
33
34
|
</script>
|
|
34
35
|
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
class="progress progress-primary w-full"
|
|
49
50
|
value={progressPercentage}
|
|
50
51
|
max="100"
|
|
52
|
+
aria-label={translations.progress}
|
|
51
53
|
></progress>
|
|
52
54
|
</div>
|
|
53
55
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { tick } from 'svelte';
|
|
2
3
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
3
4
|
|
|
4
5
|
interface Section {
|
|
@@ -18,9 +19,50 @@
|
|
|
18
19
|
const { sections, currentSectionIndex, i18n, onSectionSelect, disabled = false }: Props = $props();
|
|
19
20
|
|
|
20
21
|
let isOpen = $state(false);
|
|
22
|
+
let toggleButton = $state<HTMLButtonElement | null>(null);
|
|
23
|
+
let dropdownContent = $state<HTMLDivElement | null>(null);
|
|
24
|
+
const menuId = 'assessment-section-menu';
|
|
25
|
+
|
|
26
|
+
async function openMenu() {
|
|
27
|
+
if (disabled) return;
|
|
28
|
+
isOpen = true;
|
|
29
|
+
await tick();
|
|
30
|
+
const active = dropdownContent?.querySelector<HTMLButtonElement>('.section-item.active');
|
|
31
|
+
const first = dropdownContent?.querySelector<HTMLButtonElement>('.section-item:not(:disabled)');
|
|
32
|
+
(active ?? first)?.focus();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closeMenu({ restoreFocus = true } = {}) {
|
|
36
|
+
isOpen = false;
|
|
37
|
+
if (restoreFocus) {
|
|
38
|
+
toggleButton?.focus();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
|
|
22
42
|
function toggleMenu() {
|
|
23
|
-
isOpen
|
|
43
|
+
if (isOpen) {
|
|
44
|
+
closeMenu();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
void openMenu();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleMenuKeydown(event: KeyboardEvent) {
|
|
51
|
+
if (event.key === 'Escape') {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
closeMenu();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleToggleKeydown(event: KeyboardEvent) {
|
|
58
|
+
if (event.key === 'ArrowDown') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
void openMenu();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleBackdropClick() {
|
|
65
|
+
closeMenu();
|
|
24
66
|
}
|
|
25
67
|
|
|
26
68
|
function selectSection(sectionIndex: number) {
|
|
@@ -28,13 +70,22 @@
|
|
|
28
70
|
if (onSectionSelect) {
|
|
29
71
|
onSectionSelect(sectionIndex);
|
|
30
72
|
}
|
|
31
|
-
|
|
73
|
+
closeMenu();
|
|
32
74
|
}
|
|
33
75
|
</script>
|
|
34
76
|
|
|
35
77
|
{#if sections.length > 1}
|
|
36
78
|
<div class="section-menu">
|
|
37
|
-
<button
|
|
79
|
+
<button
|
|
80
|
+
bind:this={toggleButton}
|
|
81
|
+
class="btn btn-outline btn-sm"
|
|
82
|
+
type="button"
|
|
83
|
+
aria-expanded={isOpen}
|
|
84
|
+
aria-controls={menuId}
|
|
85
|
+
onclick={() => toggleMenu?.()}
|
|
86
|
+
onkeydown={handleToggleKeydown}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
>
|
|
38
89
|
<svg
|
|
39
90
|
xmlns="http://www.w3.org/2000/svg"
|
|
40
91
|
class="h-5 w-5"
|
|
@@ -54,12 +105,23 @@
|
|
|
54
105
|
|
|
55
106
|
{#if isOpen}
|
|
56
107
|
<div class="section-dropdown">
|
|
57
|
-
<div
|
|
108
|
+
<div
|
|
109
|
+
bind:this={dropdownContent}
|
|
110
|
+
id={menuId}
|
|
111
|
+
class="section-dropdown-content"
|
|
112
|
+
role="menu"
|
|
113
|
+
tabindex="-1"
|
|
114
|
+
aria-label={i18n?.t('assessment.sections.title') ?? 'Sections'}
|
|
115
|
+
onkeydown={handleMenuKeydown}
|
|
116
|
+
>
|
|
58
117
|
<div class="section-list">
|
|
59
118
|
{#each sections as section}
|
|
60
119
|
<button
|
|
61
120
|
class="section-item"
|
|
62
121
|
class:active={currentSectionIndex === section.index}
|
|
122
|
+
type="button"
|
|
123
|
+
role="menuitemradio"
|
|
124
|
+
aria-checked={currentSectionIndex === section.index}
|
|
63
125
|
onclick={() => selectSection(section.index)}
|
|
64
126
|
disabled={disabled}
|
|
65
127
|
>
|
|
@@ -103,7 +165,12 @@
|
|
|
103
165
|
{/each}
|
|
104
166
|
</div>
|
|
105
167
|
</div>
|
|
106
|
-
<button
|
|
168
|
+
<button
|
|
169
|
+
class="section-backdrop"
|
|
170
|
+
type="button"
|
|
171
|
+
onclick={handleBackdropClick}
|
|
172
|
+
aria-label={i18n?.t('assessment.closeMenu') ?? 'Close menu'}
|
|
173
|
+
></button>
|
|
107
174
|
</div>
|
|
108
175
|
{/if}
|
|
109
176
|
</div>
|