@pie-qti/default-components 0.1.4 → 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.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
- package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
- package/dist/shared/utils/matchGroupUtils.js +13 -0
- package/package.json +8 -4
- package/src/catalog/CatalogPopup.svelte +162 -0
- package/src/index.ts +10 -1
- package/src/plugins/associate/AssociateInteraction.svelte +18 -1
- package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
- package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
- package/src/plugins/gap-match/GapMatchInteraction.svelte +174 -12
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +197 -107
- package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
- package/src/plugins/hottext/HottextInteraction.svelte +33 -4
- package/src/plugins/index.ts +1 -0
- package/src/plugins/match/MatchInteraction.svelte +13 -1
- package/src/plugins/order/OrderInteraction.svelte +132 -11
- package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -9
- package/src/plugins/select-point/SelectPointInteraction.svelte +139 -7
- package/src/shared/components/GraphicGapMatch.svelte +5 -3
- package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
- package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
- package/src/shared/components/MatchDragDrop.svelte +48 -2
- package/src/shared/styles/qti-shared-vocabulary.css +320 -0
- package/src/shared/utils/matchGroupUtils.ts +14 -0
|
@@ -55,8 +55,11 @@
|
|
|
55
55
|
/**
|
|
56
56
|
* Check if selection limit has been reached
|
|
57
57
|
*/
|
|
58
|
+
// maxChoices=0 means unlimited per QTI spec
|
|
58
59
|
const canSelectMore = $derived(
|
|
59
|
-
parsedInteraction
|
|
60
|
+
parsedInteraction
|
|
61
|
+
? parsedInteraction.maxChoices === 0 || selectedIds.length < parsedInteraction.maxChoices
|
|
62
|
+
: false
|
|
60
63
|
);
|
|
61
64
|
|
|
62
65
|
/**
|
|
@@ -197,7 +200,7 @@
|
|
|
197
200
|
|
|
198
201
|
<ShadowBaseStyles />
|
|
199
202
|
|
|
200
|
-
<div bind:this={rootElement} part="root" class=
|
|
203
|
+
<div bind:this={rootElement} part="root" class={['qti-hottext-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
|
|
201
204
|
{#if !parsedInteraction}
|
|
202
205
|
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
203
206
|
{:else}
|
|
@@ -217,8 +220,15 @@
|
|
|
217
220
|
|
|
218
221
|
<div part="footer" class="qti-hottext-footer flex items-center justify-between text-sm text-base-content/70">
|
|
219
222
|
<div>
|
|
220
|
-
<span class="font-medium">Selected:</span>
|
|
221
|
-
<span class="ml-2">{selectedIds.length} / {parsedInteraction.hottextChoices
|
|
223
|
+
<span class="font-medium">{i18n?.t('interactions.hottext.selected') ?? 'Selected'}:</span>
|
|
224
|
+
<span class="ml-2">{selectedIds.length} / {parsedInteraction.hottextChoices?.length ?? 0}</span>
|
|
225
|
+
{#if parsedInteraction.minChoices > 0}
|
|
226
|
+
{#if selectedIds.length >= parsedInteraction.minChoices}
|
|
227
|
+
<span class="badge badge-success badge-sm ml-2">✓ {i18n?.t('interactions.hottext.minimumMet') ?? 'Minimum met'}</span>
|
|
228
|
+
{:else}
|
|
229
|
+
<span class="badge badge-warning badge-sm ml-2">{i18n?.t('interactions.hottext.selectAtLeast', `Select at least ${parsedInteraction.minChoices}`) ?? `Select at least ${parsedInteraction.minChoices}`}</span>
|
|
230
|
+
{/if}
|
|
231
|
+
{/if}
|
|
222
232
|
</div>
|
|
223
233
|
|
|
224
234
|
{#if selectedIds.length > 0}
|
|
@@ -245,10 +255,29 @@
|
|
|
245
255
|
</button>
|
|
246
256
|
{/if}
|
|
247
257
|
</div>
|
|
258
|
+
{#if parsedInteraction.maxSelectionsMessage && selectedIds.length >= parsedInteraction.maxChoices && parsedInteraction.maxChoices > 0}
|
|
259
|
+
<p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
|
|
260
|
+
{/if}
|
|
248
261
|
{/if}
|
|
249
262
|
</div>
|
|
250
263
|
|
|
251
264
|
<style>
|
|
265
|
+
.qti-selection-message {
|
|
266
|
+
font-size: 0.875rem;
|
|
267
|
+
color: var(--color-warning, oklch(77% 0.194 82));
|
|
268
|
+
margin-top: 0.25rem;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* qti-input-control-hidden: hide visual selection indicators but keep keyboard-accessible */
|
|
272
|
+
.qti-input-control-hidden :global(hottext) {
|
|
273
|
+
cursor: pointer;
|
|
274
|
+
outline: none;
|
|
275
|
+
}
|
|
276
|
+
.qti-input-control-hidden :global(hottext[data-selected]) {
|
|
277
|
+
background-color: transparent;
|
|
278
|
+
text-decoration: underline;
|
|
279
|
+
}
|
|
280
|
+
|
|
252
281
|
/* Minimal layout so this works without Tailwind/DaisyUI */
|
|
253
282
|
.qti-hottext-interaction {
|
|
254
283
|
display: grid;
|
package/src/plugins/index.ts
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
<ShadowBaseStyles />
|
|
49
49
|
|
|
50
|
-
<div bind:this={rootElement} class=
|
|
50
|
+
<div bind:this={rootElement} class={['qti-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
|
|
51
51
|
{#if !parsedInteraction}
|
|
52
52
|
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
53
53
|
{:else}
|
|
@@ -61,10 +61,22 @@
|
|
|
61
61
|
sourceSet={parsedInteraction.sourceSet}
|
|
62
62
|
targetSet={parsedInteraction.targetSet}
|
|
63
63
|
{pairs}
|
|
64
|
+
maxAssociations={parsedInteraction.maxAssociations}
|
|
64
65
|
correctPairs={isShowingCorrect ? (parsedCorrectResponse || []) : []}
|
|
65
66
|
{disabled}
|
|
66
67
|
{i18n}
|
|
67
68
|
onPairsChange={handlePairsChange}
|
|
68
69
|
/>
|
|
70
|
+
{#if parsedInteraction.maxSelectionsMessage && pairs.length >= parsedInteraction.maxAssociations && parsedInteraction.maxAssociations > 0}
|
|
71
|
+
<p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
|
|
72
|
+
{/if}
|
|
69
73
|
{/if}
|
|
70
74
|
</div>
|
|
75
|
+
|
|
76
|
+
<style>
|
|
77
|
+
.qti-selection-message {
|
|
78
|
+
font-size: 0.875rem;
|
|
79
|
+
color: var(--color-warning, oklch(77% 0.194 82));
|
|
80
|
+
margin-top: 0.5rem;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
i18n?: I18nProvider;
|
|
19
19
|
typeset?: (element: HTMLElement) => void;
|
|
20
20
|
onChange?: (value: string[]) => void;
|
|
21
|
+
/** When true, renders an elimination toggle button per choice (QTI 3.0 PNP §6.2). */
|
|
22
|
+
eliminationTool?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
|
|
25
|
+
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange, eliminationTool = false }: Props = $props();
|
|
24
26
|
|
|
25
27
|
// Parse props that may be JSON strings (web component usage)
|
|
26
28
|
const parsedInteraction = $derived(parseJsonProp<OrderInteractionData>(interaction));
|
|
@@ -34,11 +36,54 @@
|
|
|
34
36
|
// Track whether user has confirmed their order
|
|
35
37
|
let hasConfirmed = $state(false);
|
|
36
38
|
|
|
37
|
-
//
|
|
39
|
+
// Shuffle choices on first render when shuffle=true, respecting fixed=true per choice.
|
|
40
|
+
// Uses a simple seeded shuffle keyed to the responseId so the order is stable within a session.
|
|
41
|
+
const shuffledChoiceIds = $derived.by(() => {
|
|
42
|
+
const choices = parsedInteraction?.choices;
|
|
43
|
+
if (!choices || !parsedInteraction?.shuffle) {
|
|
44
|
+
return choices?.map((c) => c.identifier) ?? [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Separate fixed and non-fixed choices
|
|
48
|
+
const fixedSlots = new Map<number, string>(); // index → identifier
|
|
49
|
+
const movable: string[] = [];
|
|
50
|
+
for (let i = 0; i < choices.length; i++) {
|
|
51
|
+
if (choices[i].fixed) {
|
|
52
|
+
fixedSlots.set(i, choices[i].identifier);
|
|
53
|
+
} else {
|
|
54
|
+
movable.push(choices[i].identifier);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Fisher-Yates shuffle with a simple deterministic seed
|
|
59
|
+
const seed = (parsedInteraction.responseId ?? 'order').split('').reduce((a, c) => a + c.charCodeAt(0), 0);
|
|
60
|
+
const rng = (n: number) => {
|
|
61
|
+
// LCG: good enough for presentation shuffle
|
|
62
|
+
return ((seed * 1664525 + 1013904223 + n * 22695477) & 0x7fffffff) / 0x7fffffff;
|
|
63
|
+
};
|
|
64
|
+
for (let i = movable.length - 1; i > 0; i--) {
|
|
65
|
+
const j = Math.floor(rng(i) * (i + 1));
|
|
66
|
+
[movable[i], movable[j]] = [movable[j], movable[i]];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Reconstruct full array, inserting fixed choices back into their original slots
|
|
70
|
+
const result: string[] = new Array(choices.length);
|
|
71
|
+
let movableIdx = 0;
|
|
72
|
+
for (let i = 0; i < choices.length; i++) {
|
|
73
|
+
if (fixedSlots.has(i)) {
|
|
74
|
+
result[i] = fixedSlots.get(i)!;
|
|
75
|
+
} else {
|
|
76
|
+
result[i] = movable[movableIdx++];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Get ordered IDs from response, or use shuffled/original order
|
|
38
83
|
const orderedIds = $derived(
|
|
39
84
|
parsedResponse && parsedResponse.length > 0
|
|
40
85
|
? parsedResponse
|
|
41
|
-
:
|
|
86
|
+
: shuffledChoiceIds
|
|
42
87
|
);
|
|
43
88
|
|
|
44
89
|
// Track initial order to detect if user has made changes
|
|
@@ -87,6 +132,25 @@
|
|
|
87
132
|
hasConfirmed = false;
|
|
88
133
|
}
|
|
89
134
|
});
|
|
135
|
+
|
|
136
|
+
// Elimination tool state
|
|
137
|
+
let eliminatedChoices = $state(new Set<string>());
|
|
138
|
+
|
|
139
|
+
function toggleElimination(identifier: string) {
|
|
140
|
+
const next = new Set(eliminatedChoices);
|
|
141
|
+
if (next.has(identifier)) {
|
|
142
|
+
next.delete(identifier);
|
|
143
|
+
} else {
|
|
144
|
+
next.add(identifier);
|
|
145
|
+
}
|
|
146
|
+
eliminatedChoices = next;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function eliminationLabel(identifier: string): string {
|
|
150
|
+
return eliminatedChoices.has(identifier)
|
|
151
|
+
? (i18n?.t('interactions.choice.restoreChoice') ?? 'Restore')
|
|
152
|
+
: (i18n?.t('interactions.choice.eliminateChoice') ?? 'Eliminate');
|
|
153
|
+
}
|
|
90
154
|
</script>
|
|
91
155
|
|
|
92
156
|
<ShadowBaseStyles />
|
|
@@ -101,14 +165,31 @@
|
|
|
101
165
|
</div>
|
|
102
166
|
{/if}
|
|
103
167
|
|
|
104
|
-
<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
168
|
+
<div class="qti-order-sortable-wrapper" class:qti-order-with-elimination={eliminationTool}>
|
|
169
|
+
<SortableList
|
|
170
|
+
items={parsedInteraction.choices.map(c => ({ id: c.identifier, text: c.text }))}
|
|
171
|
+
{orderedIds}
|
|
172
|
+
correctOrder={isShowingCorrect ? (parsedCorrectResponse || []) : []}
|
|
173
|
+
orientation="vertical"
|
|
174
|
+
{disabled}
|
|
175
|
+
onReorder={handleReorder}
|
|
176
|
+
/>
|
|
177
|
+
{#if eliminationTool}
|
|
178
|
+
<div class="qti-order-elimination-col" aria-hidden="true">
|
|
179
|
+
{#each orderedIds as id (id)}
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
class="qti-eliminate-btn"
|
|
183
|
+
aria-label={eliminationLabel(id)}
|
|
184
|
+
aria-pressed={eliminatedChoices.has(id)}
|
|
185
|
+
aria-hidden="false"
|
|
186
|
+
onclick={() => toggleElimination(id)}
|
|
187
|
+
data-eliminated={eliminatedChoices.has(id) ? '' : undefined}
|
|
188
|
+
>✕</button>
|
|
189
|
+
{/each}
|
|
190
|
+
</div>
|
|
191
|
+
{/if}
|
|
192
|
+
</div>
|
|
112
193
|
|
|
113
194
|
<!-- Confirmation button for WCAG 2.2 SC 3.3.4 compliance -->
|
|
114
195
|
<div class="mt-4 flex items-center gap-3">
|
|
@@ -156,4 +237,44 @@
|
|
|
156
237
|
height: 1rem;
|
|
157
238
|
flex: 0 0 auto;
|
|
158
239
|
}
|
|
240
|
+
|
|
241
|
+
/* Elimination tool layout */
|
|
242
|
+
.qti-order-sortable-wrapper {
|
|
243
|
+
position: relative;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.qti-order-with-elimination {
|
|
247
|
+
display: grid;
|
|
248
|
+
grid-template-columns: 1fr auto;
|
|
249
|
+
gap: 0.25rem;
|
|
250
|
+
align-items: start;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.qti-order-elimination-col {
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
gap: 0.5rem;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.qti-eliminate-btn {
|
|
260
|
+
background: none;
|
|
261
|
+
border: 1px solid currentColor;
|
|
262
|
+
border-radius: 50%;
|
|
263
|
+
width: 1.75rem;
|
|
264
|
+
height: 1.75rem;
|
|
265
|
+
font-size: 0.75rem;
|
|
266
|
+
cursor: pointer;
|
|
267
|
+
opacity: 0.4;
|
|
268
|
+
padding: 0;
|
|
269
|
+
display: flex;
|
|
270
|
+
align-items: center;
|
|
271
|
+
justify-content: center;
|
|
272
|
+
flex-shrink: 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.qti-eliminate-btn:hover,
|
|
276
|
+
.qti-eliminate-btn[data-eliminated] {
|
|
277
|
+
opacity: 1;
|
|
278
|
+
color: var(--color-error, oklch(63% 0.237 25.331));
|
|
279
|
+
}
|
|
159
280
|
</style>
|
|
@@ -77,8 +77,16 @@
|
|
|
77
77
|
let positions = $state<Position[]>([]);
|
|
78
78
|
let draggedStageId: string | null = $state(null);
|
|
79
79
|
let draggedPositionIndex: number | null = $state(null);
|
|
80
|
+
// imageContainer / imageContainer are the same element — one binding covers both roles
|
|
80
81
|
let imageContainer: HTMLDivElement | null = $state(null);
|
|
81
82
|
|
|
83
|
+
// Keyboard accessibility state (K-04)
|
|
84
|
+
let selectedStageId: string | null = $state(null); // stage currently being keyboard-positioned
|
|
85
|
+
let crosshairX = $state(0.5); // normalized [0,1] x position on background image
|
|
86
|
+
let crosshairY = $state(0.5); // normalized [0,1] y position on background image
|
|
87
|
+
let crosshairActive = $state(false); // whether the crosshair is visible/active
|
|
88
|
+
let liveMessage = $state(''); // message for aria-live region
|
|
89
|
+
|
|
82
90
|
const canInteract = $derived(!disabled);
|
|
83
91
|
const canAddMore = $derived(
|
|
84
92
|
!parsedInteraction || parsedInteraction.maxChoices === 0 || positions.length < parsedInteraction.maxChoices
|
|
@@ -109,6 +117,7 @@
|
|
|
109
117
|
|
|
110
118
|
for (let i = 0; i < parsedResponse.length; i++) {
|
|
111
119
|
const pointStr = parsedResponse[i];
|
|
120
|
+
if (typeof pointStr !== 'string') continue;
|
|
112
121
|
const parts = pointStr.trim().split(/\s+/);
|
|
113
122
|
if (parts.length >= 2) {
|
|
114
123
|
const x = parseFloat(parts[0]);
|
|
@@ -296,6 +305,7 @@
|
|
|
296
305
|
|
|
297
306
|
for (let i = 0; i < value.length; i++) {
|
|
298
307
|
const pointStr = value[i];
|
|
308
|
+
if (typeof pointStr !== 'string') continue;
|
|
299
309
|
const parts = pointStr.trim().split(/\s+/);
|
|
300
310
|
if (parts.length >= 2) {
|
|
301
311
|
const x = parseFloat(parts[0]);
|
|
@@ -353,6 +363,140 @@
|
|
|
353
363
|
Math.abs(pos.y - correctPos.y) < 5
|
|
354
364
|
);
|
|
355
365
|
}
|
|
366
|
+
|
|
367
|
+
// ---------------------------------------------------------------------------
|
|
368
|
+
// Keyboard accessibility (K-04) — two-phase: palette select → canvas place
|
|
369
|
+
// ---------------------------------------------------------------------------
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Activate keyboard placement mode for a palette stage.
|
|
373
|
+
* Phase 1: user presses Enter/Space on a palette item.
|
|
374
|
+
*/
|
|
375
|
+
function activateKeyboardPlacement(stageId: string) {
|
|
376
|
+
if (!canInteract) return;
|
|
377
|
+
const stage = getStageById(stageId);
|
|
378
|
+
if (!stage || !canDragStage(stageId)) return;
|
|
379
|
+
|
|
380
|
+
selectedStageId = stageId;
|
|
381
|
+
crosshairActive = true;
|
|
382
|
+
|
|
383
|
+
// Initialise crosshair to the stage's last placed position, or centre
|
|
384
|
+
const existing = [...positions].reverse().find((p: Position) => p.stageId === stageId);
|
|
385
|
+
if (existing && parsedInteraction?.imageData) {
|
|
386
|
+
const imgW = Number(parsedInteraction.imageData.width) || 1;
|
|
387
|
+
const imgH = Number(parsedInteraction.imageData.height) || 1;
|
|
388
|
+
crosshairX = Math.max(0, Math.min(1, existing.x / imgW));
|
|
389
|
+
crosshairY = Math.max(0, Math.min(1, existing.y / imgH));
|
|
390
|
+
} else {
|
|
391
|
+
crosshairX = 0.5;
|
|
392
|
+
crosshairY = 0.5;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
liveMessage = `${stage.label} selected. Tab to canvas, then use arrow keys to position. Press Enter to place, Escape to cancel.`;
|
|
396
|
+
|
|
397
|
+
// Move focus to the canvas so arrow keys work immediately
|
|
398
|
+
requestAnimationFrame(() => imageContainer?.focus());
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Handle keydown on a palette item.
|
|
403
|
+
*/
|
|
404
|
+
function handlePaletteKeydown(event: KeyboardEvent, stageId: string) {
|
|
405
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
406
|
+
event.preventDefault();
|
|
407
|
+
activateKeyboardPlacement(stageId);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Place the currently selected stage at the crosshair position.
|
|
413
|
+
*/
|
|
414
|
+
function placeAtCrosshair() {
|
|
415
|
+
if (!selectedStageId || !parsedInteraction?.imageData) return;
|
|
416
|
+
|
|
417
|
+
const imgW = Number(parsedInteraction.imageData.width) || 800;
|
|
418
|
+
const imgH = Number(parsedInteraction.imageData.height) || 600;
|
|
419
|
+
|
|
420
|
+
let x = crosshairX * imgW;
|
|
421
|
+
let y = crosshairY * imgH;
|
|
422
|
+
|
|
423
|
+
// Apply centerPoint adjustment (same logic as mouse drop)
|
|
424
|
+
if (parsedInteraction.centerPoint) {
|
|
425
|
+
const stage = getStageById(selectedStageId);
|
|
426
|
+
if (stage?.objectData) {
|
|
427
|
+
x -= parseInt(stage.objectData.width || '50') / 2;
|
|
428
|
+
y -= parseInt(stage.objectData.height || '50') / 2;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const stage = getStageById(selectedStageId);
|
|
433
|
+
if (!stage) return;
|
|
434
|
+
|
|
435
|
+
// Check stage capacity
|
|
436
|
+
const usageCount = getStageUsageCount(selectedStageId);
|
|
437
|
+
if (usageCount >= stage.matchMax) return;
|
|
438
|
+
if (!canAddMore) return;
|
|
439
|
+
|
|
440
|
+
positions = [...positions, { stageId: selectedStageId, x, y }];
|
|
441
|
+
|
|
442
|
+
const responseValue = positions.map((pos) => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
443
|
+
response = responseValue;
|
|
444
|
+
onChange?.(responseValue);
|
|
445
|
+
if (rootElement) {
|
|
446
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const pct = (v: number) => Math.round(v * 100);
|
|
450
|
+
liveMessage = `${stage.label} placed at ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
451
|
+
|
|
452
|
+
selectedStageId = null;
|
|
453
|
+
crosshairActive = false;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Handle keydown on the canvas when in keyboard placement mode.
|
|
458
|
+
*/
|
|
459
|
+
function handleCanvasKeydown(event: KeyboardEvent) {
|
|
460
|
+
if (!crosshairActive || !selectedStageId) return;
|
|
461
|
+
|
|
462
|
+
const step = event.shiftKey ? 0.01 : 0.05;
|
|
463
|
+
|
|
464
|
+
switch (event.key) {
|
|
465
|
+
case 'ArrowLeft':
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
crosshairX = Math.max(0, crosshairX - step);
|
|
468
|
+
break;
|
|
469
|
+
case 'ArrowRight':
|
|
470
|
+
event.preventDefault();
|
|
471
|
+
crosshairX = Math.min(1, crosshairX + step);
|
|
472
|
+
break;
|
|
473
|
+
case 'ArrowUp':
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
crosshairY = Math.max(0, crosshairY - step);
|
|
476
|
+
break;
|
|
477
|
+
case 'ArrowDown':
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
crosshairY = Math.min(1, crosshairY + step);
|
|
480
|
+
break;
|
|
481
|
+
case 'Enter':
|
|
482
|
+
case ' ':
|
|
483
|
+
event.preventDefault();
|
|
484
|
+
placeAtCrosshair();
|
|
485
|
+
return;
|
|
486
|
+
case 'Escape':
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
selectedStageId = null;
|
|
489
|
+
crosshairActive = false;
|
|
490
|
+
liveMessage = 'Placement cancelled.';
|
|
491
|
+
return;
|
|
492
|
+
default:
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Announce updated position after arrow movement
|
|
497
|
+
const pct = (v: number) => Math.round(v * 100);
|
|
498
|
+
liveMessage = `Position: ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
499
|
+
}
|
|
356
500
|
</script>
|
|
357
501
|
|
|
358
502
|
<ShadowBaseStyles />
|
|
@@ -368,15 +512,21 @@
|
|
|
368
512
|
<div part="layout" class="qti-po-layout flex flex-col lg:flex-row gap-4 items-start">
|
|
369
513
|
<!-- Canvas Area with Background Image -->
|
|
370
514
|
<div part="canvas-area" class="qti-po-canvas-area flex-1 min-w-0">
|
|
515
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
516
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
371
517
|
<div
|
|
372
518
|
bind:this={imageContainer}
|
|
373
519
|
part="canvas"
|
|
374
|
-
class="qti-po-canvas relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200"
|
|
520
|
+
class="qti-po-canvas relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200 {crosshairActive ? 'qti-po-canvas-active' : ''}"
|
|
375
521
|
style="width: 100%; aspect-ratio: {parsedInteraction.imageData?.width || 800} / {parsedInteraction.imageData?.height || 600}; box-sizing: border-box;"
|
|
376
522
|
ondrop={handleDrop}
|
|
377
523
|
ondragover={handleDragOver}
|
|
378
|
-
|
|
379
|
-
|
|
524
|
+
onkeydown={handleCanvasKeydown}
|
|
525
|
+
role="application"
|
|
526
|
+
tabindex={crosshairActive ? 0 : -1}
|
|
527
|
+
aria-label={crosshairActive
|
|
528
|
+
? (i18n?.t('interactions.positionObject.canvasActiveLabel') ?? `Positioning canvas – use arrow keys to move crosshair, Enter to place, Escape to cancel`)
|
|
529
|
+
: (i18n?.t('interactions.positionObject.canvasLabel') ?? 'Positioning canvas')}
|
|
380
530
|
>
|
|
381
531
|
<!-- Background Image -->
|
|
382
532
|
{#if parsedInteraction.imageData}
|
|
@@ -508,6 +658,39 @@
|
|
|
508
658
|
{/if}
|
|
509
659
|
{/each}
|
|
510
660
|
{/if}
|
|
661
|
+
|
|
662
|
+
<!-- Keyboard crosshair overlay (K-04) -->
|
|
663
|
+
{#if crosshairActive}
|
|
664
|
+
<svg
|
|
665
|
+
class="qti-po-crosshair-overlay"
|
|
666
|
+
aria-hidden="true"
|
|
667
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
668
|
+
>
|
|
669
|
+
<!-- vertical line -->
|
|
670
|
+
<line
|
|
671
|
+
x1="{crosshairX * 100}%"
|
|
672
|
+
y1="0"
|
|
673
|
+
x2="{crosshairX * 100}%"
|
|
674
|
+
y2="100%"
|
|
675
|
+
class="qti-po-crosshair-line"
|
|
676
|
+
/>
|
|
677
|
+
<!-- horizontal line -->
|
|
678
|
+
<line
|
|
679
|
+
x1="0"
|
|
680
|
+
y1="{crosshairY * 100}%"
|
|
681
|
+
x2="100%"
|
|
682
|
+
y2="{crosshairY * 100}%"
|
|
683
|
+
class="qti-po-crosshair-line"
|
|
684
|
+
/>
|
|
685
|
+
<!-- centre dot -->
|
|
686
|
+
<circle
|
|
687
|
+
cx="{crosshairX * 100}%"
|
|
688
|
+
cy="{crosshairY * 100}%"
|
|
689
|
+
r="6"
|
|
690
|
+
class="qti-po-crosshair-dot"
|
|
691
|
+
/>
|
|
692
|
+
</svg>
|
|
693
|
+
{/if}
|
|
511
694
|
</div>
|
|
512
695
|
|
|
513
696
|
{#if parsedInteraction.minChoices > 0}
|
|
@@ -527,7 +710,7 @@
|
|
|
527
710
|
Available Objects ({positions.length}{#if parsedInteraction.maxChoices > 0}/{parsedInteraction.maxChoices}{/if})
|
|
528
711
|
</h3>
|
|
529
712
|
|
|
530
|
-
<p class="text-xs text-base-content/60 mb-2">Drag objects onto the canvas to position
|
|
713
|
+
<p class="text-xs text-base-content/60 mb-2">Drag objects onto the canvas, or press Enter/Space on an object then use arrow keys to position it on the canvas.</p>
|
|
531
714
|
|
|
532
715
|
<div class="space-y-2">
|
|
533
716
|
{#each parsedInteraction.positionObjectStages as stage}
|
|
@@ -535,17 +718,16 @@
|
|
|
535
718
|
{@const canDrag = canDragStage(stage.identifier)}
|
|
536
719
|
<div
|
|
537
720
|
part="palette-item"
|
|
538
|
-
class="qti-po-palette-item flex items-center gap-3 p-3 rounded-lg bg-base-200 border border-base-300 {canInteract &&
|
|
539
|
-
canDrag
|
|
540
|
-
? 'cursor-move hover:border-primary'
|
|
541
|
-
: 'opacity-50 cursor-not-allowed'}"
|
|
721
|
+
class="qti-po-palette-item flex items-center gap-3 p-3 rounded-lg bg-base-200 border border-base-300 {canInteract && canDrag ? 'cursor-move hover:border-primary' : 'opacity-50 cursor-not-allowed'} {selectedStageId === stage.identifier ? 'qti-po-palette-item-selected' : ''}"
|
|
542
722
|
draggable={canInteract && canDrag}
|
|
543
723
|
ondragstart={(e) => {
|
|
544
724
|
if (canDrag) handleDragStart(e, stage.identifier);
|
|
545
725
|
}}
|
|
726
|
+
onkeydown={(e) => handlePaletteKeydown(e, stage.identifier)}
|
|
546
727
|
role="button"
|
|
547
728
|
tabindex={canInteract && canDrag ? 0 : -1}
|
|
548
|
-
aria-label="{stage.label} ({usageCount}/{stage.matchMax} used)"
|
|
729
|
+
aria-label="{stage.label} ({usageCount}/{stage.matchMax} used){selectedStageId === stage.identifier ? '. Selected for placement' : ''}"
|
|
730
|
+
aria-pressed={selectedStageId === stage.identifier}
|
|
549
731
|
>
|
|
550
732
|
<!-- Object Preview -->
|
|
551
733
|
<div class="qti-po-preview flex-shrink-0">
|
|
@@ -589,6 +771,9 @@
|
|
|
589
771
|
</div>
|
|
590
772
|
</div>
|
|
591
773
|
{/if}
|
|
774
|
+
|
|
775
|
+
<!-- Visually-hidden live region for keyboard placement announcements (K-04) -->
|
|
776
|
+
<div aria-live="polite" aria-atomic="true" class="qti-po-sr-only">{liveMessage}</div>
|
|
592
777
|
</div>
|
|
593
778
|
|
|
594
779
|
<style>
|
|
@@ -662,4 +847,57 @@
|
|
|
662
847
|
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
663
848
|
background: var(--color-base-200, oklch(98% 0 0));
|
|
664
849
|
}
|
|
850
|
+
|
|
851
|
+
/* Selected palette item (K-04) */
|
|
852
|
+
.qti-po-palette-item-selected {
|
|
853
|
+
border-color: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
854
|
+
background: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
855
|
+
color: var(--color-primary-content, oklch(89.824% 0.06192 275.75));
|
|
856
|
+
box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary, oklch(49.12% 0.3096 275.75)) 40%, transparent);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/* Canvas active state ring (K-04) */
|
|
860
|
+
.qti-po-canvas-active {
|
|
861
|
+
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
862
|
+
outline-offset: 2px;
|
|
863
|
+
}
|
|
864
|
+
.qti-po-canvas-active:focus {
|
|
865
|
+
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
866
|
+
outline-offset: 2px;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/* Crosshair SVG overlay (K-04) */
|
|
870
|
+
.qti-po-crosshair-overlay {
|
|
871
|
+
position: absolute;
|
|
872
|
+
inset: 0;
|
|
873
|
+
width: 100%;
|
|
874
|
+
height: 100%;
|
|
875
|
+
pointer-events: none;
|
|
876
|
+
z-index: 100;
|
|
877
|
+
}
|
|
878
|
+
.qti-po-crosshair-line {
|
|
879
|
+
stroke: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
880
|
+
stroke-width: 1.5;
|
|
881
|
+
stroke-dasharray: 6 4;
|
|
882
|
+
opacity: 0.85;
|
|
883
|
+
}
|
|
884
|
+
.qti-po-crosshair-dot {
|
|
885
|
+
fill: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
886
|
+
stroke: white;
|
|
887
|
+
stroke-width: 2;
|
|
888
|
+
opacity: 0.95;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/* Visually hidden live region (K-04) */
|
|
892
|
+
.qti-po-sr-only {
|
|
893
|
+
position: absolute;
|
|
894
|
+
width: 1px;
|
|
895
|
+
height: 1px;
|
|
896
|
+
padding: 0;
|
|
897
|
+
margin: -1px;
|
|
898
|
+
overflow: hidden;
|
|
899
|
+
clip: rect(0, 0, 0, 0);
|
|
900
|
+
white-space: nowrap;
|
|
901
|
+
border: 0;
|
|
902
|
+
}
|
|
665
903
|
</style>
|