@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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Graphic Gap Match component for graphicGapMatchInteractionData
|
|
6
6
|
* Drag labels onto specific areas of an image/diagram
|
|
7
|
-
* Supports keyboard, mouse, and touch interactions
|
|
7
|
+
* Supports keyboard (two-phase pick-up/drop), mouse, and touch interactions
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { GraphicGapMatchInteractionData } from '@pie-qti/item-player';
|
|
@@ -12,6 +12,7 @@ import type { I18nProvider } from '@pie-qti/i18n';
|
|
|
12
12
|
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers.js';
|
|
13
13
|
import { touchDrag } from '../../shared/utils/touchDragHelper.js';
|
|
14
14
|
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
15
|
+
|
|
15
16
|
import '../../shared/styles/shared.css';
|
|
16
17
|
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
17
18
|
|
|
@@ -37,8 +38,10 @@ const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorre
|
|
|
37
38
|
let pairs = $state<string[]>([]);
|
|
38
39
|
let draggedTextId = $state<string | null>(null);
|
|
39
40
|
let hoveredHotspotId = $state<string | null>(null);
|
|
40
|
-
|
|
41
|
-
let
|
|
41
|
+
/** Identifier of the label currently "held" via keyboard (two-phase pick-up/drop). */
|
|
42
|
+
let pickedUpLabel = $state<string | null>(null);
|
|
43
|
+
/** Text announced to screen readers via the aria-live region. */
|
|
44
|
+
let liveMessage = $state<string>('');
|
|
42
45
|
|
|
43
46
|
// Get reference to the root element for event dispatching (needed for Shadow DOM)
|
|
44
47
|
let rootElement: HTMLDivElement | undefined = $state();
|
|
@@ -46,6 +49,29 @@ let rootElement: HTMLDivElement | undefined = $state();
|
|
|
46
49
|
// Track if we're updating from internal change (user drag) vs external (prop update)
|
|
47
50
|
let isInternalUpdate = false;
|
|
48
51
|
|
|
52
|
+
// Labels (gapTexts + gapImages) unavailable due to matchGroup conflicts with already-placed labels
|
|
53
|
+
const unavailableLabels = $derived.by(() => {
|
|
54
|
+
if (!parsedInteraction) return new Set<string>();
|
|
55
|
+
type WithMatchGroup = { identifier: string; matchGroup?: string[] };
|
|
56
|
+
const gapTexts = parsedInteraction.gapTexts as WithMatchGroup[];
|
|
57
|
+
const gapImages = (parsedInteraction.gapImages ?? []) as WithMatchGroup[];
|
|
58
|
+
const placedGroups = new Set<string>();
|
|
59
|
+
for (const pair of pairs) {
|
|
60
|
+
const labelId = pair.split(' ')[0];
|
|
61
|
+
const label = [...gapTexts, ...gapImages].find((g) => g.identifier === labelId);
|
|
62
|
+
label?.matchGroup?.forEach((g) => placedGroups.add(g));
|
|
63
|
+
}
|
|
64
|
+
return new Set(
|
|
65
|
+
[...gapTexts, ...gapImages]
|
|
66
|
+
.filter((label) => {
|
|
67
|
+
const isPlaced = pairs.some((p) => p.startsWith(`${label.identifier} `));
|
|
68
|
+
if (isPlaced) return false;
|
|
69
|
+
return label.matchGroup?.some((g) => placedGroups.has(g)) ?? false;
|
|
70
|
+
})
|
|
71
|
+
.map((label) => label.identifier)
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
49
75
|
$effect(() => {
|
|
50
76
|
// Sync with parent response changes (only if not an internal update)
|
|
51
77
|
if (!isInternalUpdate) {
|
|
@@ -67,23 +93,12 @@ function getMatchedGapText(hotspotId: string): string | null {
|
|
|
67
93
|
return pair ? pair.split(' ')[0] : null;
|
|
68
94
|
}
|
|
69
95
|
|
|
70
|
-
// Get the correct hotspot for a gap text
|
|
71
|
-
function getCorrectHotspot(gapTextId: string): string | null {
|
|
72
|
-
const pair = correctPairs.find((p) => p.startsWith(`${gapTextId} `));
|
|
73
|
-
return pair ? pair.split(' ')[1] : null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
96
|
// Get the correct gap text for a hotspot
|
|
77
97
|
function getCorrectGapText(hotspotId: string): string | null {
|
|
78
98
|
const pair = correctPairs.find((p) => p.endsWith(` ${hotspotId}`));
|
|
79
99
|
return pair ? pair.split(' ')[0] : null;
|
|
80
100
|
}
|
|
81
101
|
|
|
82
|
-
// Check if a gap text has a correct answer
|
|
83
|
-
function isCorrectGapText(gapTextId: string): boolean {
|
|
84
|
-
return isShowingCorrect && getCorrectHotspot(gapTextId) !== null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
102
|
// Check if a hotspot has a correct answer
|
|
88
103
|
function isCorrectHotspot(hotspotId: string): boolean {
|
|
89
104
|
return isShowingCorrect && getCorrectGapText(hotspotId) !== null;
|
|
@@ -154,64 +169,61 @@ function clearMatch(gapTextId: string) {
|
|
|
154
169
|
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
|
|
155
170
|
}
|
|
156
171
|
|
|
157
|
-
|
|
172
|
+
liveMessage = `${gapTextName} removed from hotspot`;
|
|
158
173
|
}
|
|
159
174
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Resolve a human-readable name for a label by identifier.
|
|
177
|
+
* Checks gapTexts first, then gapImages.
|
|
178
|
+
*/
|
|
179
|
+
function getLabelName(labelId: string): string {
|
|
180
|
+
if (!parsedInteraction) return 'Label';
|
|
181
|
+
const text = parsedInteraction.gapTexts.find((g) => g.identifier === labelId);
|
|
182
|
+
if (text) return text.text;
|
|
183
|
+
const img = parsedInteraction.gapImages.find((g) => g.identifier === labelId);
|
|
184
|
+
if (img) return img.alt || img.identifier;
|
|
185
|
+
return 'Label';
|
|
186
|
+
}
|
|
163
187
|
|
|
164
|
-
|
|
165
|
-
|
|
188
|
+
// Phase-1 handler: pick up or put down a label from the palette.
|
|
189
|
+
function handleLabelActivate(labelId: string) {
|
|
190
|
+
if (disabled) return;
|
|
166
191
|
|
|
167
|
-
if (
|
|
168
|
-
//
|
|
169
|
-
|
|
170
|
-
|
|
192
|
+
if (pickedUpLabel === labelId) {
|
|
193
|
+
// Second press on the same label cancels the pick-up
|
|
194
|
+
pickedUpLabel = null;
|
|
195
|
+
liveMessage = 'Cancelled.';
|
|
171
196
|
} else {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
197
|
+
pickedUpLabel = labelId;
|
|
198
|
+
const name = getLabelName(labelId);
|
|
199
|
+
liveMessage = `Picked up: ${name}. Tab to a hotspot and press Enter to place it.`;
|
|
175
200
|
}
|
|
176
201
|
}
|
|
177
202
|
|
|
178
|
-
function
|
|
179
|
-
if (disabled
|
|
180
|
-
|
|
181
|
-
const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === gapTextId);
|
|
182
|
-
const gapTextName = gapTextObj?.text || 'Label';
|
|
203
|
+
function handleLabelKeyDown(event: KeyboardEvent, labelId: string) {
|
|
204
|
+
if (disabled) return;
|
|
183
205
|
|
|
184
206
|
if (event.key === ' ' || event.key === 'Enter') {
|
|
185
207
|
event.preventDefault();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// Deselect
|
|
189
|
-
keyboardSelectedTextId = null;
|
|
190
|
-
announceText = `${gapTextName} deselected`;
|
|
191
|
-
} else {
|
|
192
|
-
// Select this gap text for placement
|
|
193
|
-
keyboardSelectedTextId = gapTextId;
|
|
194
|
-
announceText = `${gapTextName} selected. Navigate to a hotspot and press Space or Enter to place.`;
|
|
195
|
-
}
|
|
196
|
-
} else if (event.key === 'Escape' && keyboardSelectedTextId) {
|
|
208
|
+
handleLabelActivate(labelId);
|
|
209
|
+
} else if (event.key === 'Escape' && pickedUpLabel) {
|
|
197
210
|
event.preventDefault();
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
pickedUpLabel = null;
|
|
212
|
+
liveMessage = 'Cancelled.';
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
|
|
203
|
-
//
|
|
204
|
-
function
|
|
205
|
-
if (disabled || !
|
|
216
|
+
// Phase-2 handler: drop the held label onto a hotspot.
|
|
217
|
+
function placePickedUpLabelOnHotspot(hotspotId: string) {
|
|
218
|
+
if (disabled || !pickedUpLabel || !parsedInteraction) return;
|
|
206
219
|
|
|
207
220
|
const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspotId);
|
|
208
|
-
const
|
|
209
|
-
const gapTextName = gapTextObj?.text || 'Label';
|
|
221
|
+
const labelName = getLabelName(pickedUpLabel);
|
|
210
222
|
|
|
211
223
|
// Create match
|
|
212
|
-
let newPairs = pairs.filter((p) => !p.startsWith(`${
|
|
224
|
+
let newPairs = pairs.filter((p) => !p.startsWith(`${pickedUpLabel} `));
|
|
213
225
|
newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
|
|
214
|
-
newPairs.push(`${
|
|
226
|
+
newPairs.push(`${pickedUpLabel} ${hotspotId}`);
|
|
215
227
|
|
|
216
228
|
isInternalUpdate = true; // Mark as internal update
|
|
217
229
|
pairs = newPairs;
|
|
@@ -224,38 +236,36 @@ function placeSelectedLabelOnHotspot(hotspotId: string) {
|
|
|
224
236
|
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
|
|
225
237
|
}
|
|
226
238
|
|
|
227
|
-
|
|
228
|
-
|
|
239
|
+
liveMessage = `Placed ${labelName} on hotspot ${hotspotIndex + 1}.`;
|
|
240
|
+
pickedUpLabel = null;
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
function handleHotspotKeyDown(event: KeyboardEvent, hotspotId: string) {
|
|
232
|
-
if (disabled || !
|
|
244
|
+
if (disabled || !parsedInteraction) return;
|
|
233
245
|
|
|
234
246
|
if (event.key === ' ' || event.key === 'Enter') {
|
|
235
|
-
|
|
236
|
-
|
|
247
|
+
if (pickedUpLabel) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
placePickedUpLabelOnHotspot(hotspotId);
|
|
250
|
+
}
|
|
237
251
|
}
|
|
238
252
|
}
|
|
239
253
|
|
|
240
|
-
//
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
|
|
247
|
-
} else if (shape === 'rect') {
|
|
248
|
-
const [x, y, width, height] = coords;
|
|
249
|
-
return { x, y, width, height };
|
|
254
|
+
// Global Escape on root element cancels any active pick-up
|
|
255
|
+
function handleRootKeyDown(event: KeyboardEvent) {
|
|
256
|
+
if (event.key === 'Escape' && pickedUpLabel) {
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
pickedUpLabel = null;
|
|
259
|
+
liveMessage = 'Cancelled.';
|
|
250
260
|
}
|
|
251
|
-
// For poly, use bounding box (simplified)
|
|
252
|
-
return { x: coords[0], y: coords[1], width: 40, height: 40 };
|
|
253
261
|
}
|
|
262
|
+
|
|
254
263
|
</script>
|
|
255
264
|
|
|
256
265
|
<ShadowBaseStyles />
|
|
257
266
|
|
|
258
|
-
|
|
267
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
268
|
+
<div bind:this={rootElement} class={['qti-graphic-gap-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} onkeydown={handleRootKeyDown}>
|
|
259
269
|
{#if !parsedInteraction}
|
|
260
270
|
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
261
271
|
{:else}
|
|
@@ -263,14 +273,14 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
263
273
|
<p part="prompt" class="qti-ggm-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
|
|
264
274
|
{/if}
|
|
265
275
|
|
|
266
|
-
<!--
|
|
276
|
+
<!-- Visually-hidden live region for screen reader announcements -->
|
|
267
277
|
<div aria-live="polite" aria-atomic="true" class="sr-only">
|
|
268
|
-
{
|
|
278
|
+
{liveMessage}
|
|
269
279
|
</div>
|
|
270
280
|
|
|
271
281
|
<!-- Instructions for keyboard users -->
|
|
272
282
|
<div id="graphic-gap-match-instructions" class="sr-only">
|
|
273
|
-
Press Space or Enter to
|
|
283
|
+
Press Space or Enter to pick up a label. Tab to a hotspot on the image and press Enter to place it. Press Escape to cancel.
|
|
274
284
|
</div>
|
|
275
285
|
|
|
276
286
|
<div
|
|
@@ -284,6 +294,7 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
284
294
|
<div
|
|
285
295
|
part="labels"
|
|
286
296
|
class="qti-ggm-labels flex flex-wrap gap-2 p-4 bg-base-200 rounded-lg border-2 border-base-300"
|
|
297
|
+
style={parsedInteraction.choicesContainerWidth ? `width: ${parsedInteraction.choicesContainerWidth}` : undefined}
|
|
287
298
|
role="group"
|
|
288
299
|
aria-label={i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'Available labels to place'}
|
|
289
300
|
>
|
|
@@ -293,27 +304,30 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
293
304
|
{#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
|
|
294
305
|
{@const matchedHotspot = getMatchedHotspot(gapText.identifier)}
|
|
295
306
|
{@const isDragged = draggedTextId === gapText.identifier}
|
|
296
|
-
{@const
|
|
307
|
+
{@const isHeld = pickedUpLabel === gapText.identifier}
|
|
308
|
+
{@const isUnavailable = unavailableLabels.has(gapText.identifier)}
|
|
297
309
|
|
|
298
310
|
<div class="inline-flex items-center gap-1">
|
|
299
311
|
<button
|
|
300
312
|
type="button"
|
|
301
|
-
draggable={!disabled && !matchedHotspot}
|
|
313
|
+
draggable={!disabled && !matchedHotspot && !isUnavailable}
|
|
302
314
|
use:touchDrag
|
|
303
315
|
ondragstart={() => handleDragStart(gapText.identifier)}
|
|
304
316
|
ondragend={handleDragEnd}
|
|
305
|
-
onclick={() =>
|
|
306
|
-
onkeydown={(e) =>
|
|
317
|
+
onclick={() => handleLabelActivate(gapText.identifier)}
|
|
318
|
+
onkeydown={(e) => handleLabelKeyDown(e, gapText.identifier)}
|
|
307
319
|
disabled={disabled || !!matchedHotspot}
|
|
308
|
-
aria-
|
|
309
|
-
aria-
|
|
320
|
+
aria-disabled={isUnavailable ? 'true' : undefined}
|
|
321
|
+
aria-pressed={isHeld}
|
|
322
|
+
aria-label="{gapText.text}{matchedHotspot ? '. Already placed on hotspot' : isUnavailable ? '. Not available due to match group restriction' : ''}{isHeld ? '. Picked up. Tab to a hotspot and press Enter to place.' : '. Press Space or Enter to pick up'}"
|
|
310
323
|
class="btn btn-md font-medium transition-all"
|
|
311
|
-
class:btn-primary={!matchedHotspot && !
|
|
312
|
-
class:
|
|
324
|
+
class:btn-primary={!matchedHotspot && !isHeld}
|
|
325
|
+
class:qti-ggm-label-held={isHeld}
|
|
313
326
|
class:btn-success={matchedHotspot}
|
|
314
|
-
class:cursor-grab={!disabled && !matchedHotspot && !
|
|
315
|
-
class:cursor-not-allowed={disabled}
|
|
316
|
-
class:opacity-
|
|
327
|
+
class:cursor-grab={!disabled && !matchedHotspot && !isHeld && !isUnavailable}
|
|
328
|
+
class:cursor-not-allowed={disabled || isUnavailable}
|
|
329
|
+
class:opacity-40={isUnavailable}
|
|
330
|
+
class:opacity-70={!isUnavailable && (disabled || isDragged)}
|
|
317
331
|
class:contrast-125={matchedHotspot}
|
|
318
332
|
class:saturate-150={matchedHotspot}
|
|
319
333
|
>
|
|
@@ -333,6 +347,55 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
333
347
|
{/if}
|
|
334
348
|
</div>
|
|
335
349
|
{/each}
|
|
350
|
+
|
|
351
|
+
{#each (parsedInteraction.gapImages ?? []) as gapImage (gapImage.identifier)}
|
|
352
|
+
{@const matchedHotspot = getMatchedHotspot(gapImage.identifier)}
|
|
353
|
+
{@const isDragged = draggedTextId === gapImage.identifier}
|
|
354
|
+
{@const isHeld = pickedUpLabel === gapImage.identifier}
|
|
355
|
+
{@const isUnavailable = unavailableLabels.has(gapImage.identifier)}
|
|
356
|
+
|
|
357
|
+
<div class="inline-flex items-center gap-1">
|
|
358
|
+
<button
|
|
359
|
+
type="button"
|
|
360
|
+
draggable={!disabled && !matchedHotspot && !isUnavailable}
|
|
361
|
+
use:touchDrag
|
|
362
|
+
ondragstart={() => handleDragStart(gapImage.identifier)}
|
|
363
|
+
ondragend={handleDragEnd}
|
|
364
|
+
onclick={() => handleLabelActivate(gapImage.identifier)}
|
|
365
|
+
onkeydown={(e) => handleLabelKeyDown(e, gapImage.identifier)}
|
|
366
|
+
disabled={disabled || !!matchedHotspot}
|
|
367
|
+
aria-disabled={isUnavailable ? 'true' : undefined}
|
|
368
|
+
aria-pressed={isHeld}
|
|
369
|
+
aria-label="{gapImage.alt || gapImage.identifier}{matchedHotspot ? '. Already placed on hotspot' : isUnavailable ? '. Not available due to match group restriction' : ''}{isHeld ? '. Picked up. Tab to a hotspot and press Enter to place.' : '. Press Space or Enter to pick up'}"
|
|
370
|
+
class="btn btn-md p-1 transition-all"
|
|
371
|
+
class:btn-primary={!matchedHotspot && !isHeld}
|
|
372
|
+
class:qti-ggm-label-held={isHeld}
|
|
373
|
+
class:btn-success={matchedHotspot}
|
|
374
|
+
class:cursor-grab={!disabled && !matchedHotspot && !isHeld && !isUnavailable}
|
|
375
|
+
class:cursor-not-allowed={disabled || isUnavailable}
|
|
376
|
+
class:opacity-40={isUnavailable}
|
|
377
|
+
class:opacity-70={!isUnavailable && (disabled || isDragged)}
|
|
378
|
+
>
|
|
379
|
+
<img
|
|
380
|
+
src={gapImage.src}
|
|
381
|
+
alt={gapImage.alt || gapImage.identifier}
|
|
382
|
+
style={gapImage.width ? `width: ${gapImage.width}px;` : ''}
|
|
383
|
+
/>
|
|
384
|
+
</button>
|
|
385
|
+
{#if matchedHotspot && !disabled}
|
|
386
|
+
<button
|
|
387
|
+
type="button"
|
|
388
|
+
part="label-remove"
|
|
389
|
+
class="btn btn-sm btn-circle btn-error"
|
|
390
|
+
onclick={() => clearMatch(gapImage.identifier)}
|
|
391
|
+
aria-label="Remove {gapImage.alt || gapImage.identifier} from hotspot"
|
|
392
|
+
title={i18n?.t('interactions.graphicGapMatch.removeLabel') ?? 'Remove label'}
|
|
393
|
+
>
|
|
394
|
+
✕
|
|
395
|
+
</button>
|
|
396
|
+
{/if}
|
|
397
|
+
</div>
|
|
398
|
+
{/each}
|
|
336
399
|
</div>
|
|
337
400
|
{/if}
|
|
338
401
|
|
|
@@ -342,9 +405,15 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
342
405
|
class="qti-ggm-stage relative inline-block border-2 border-base-300 rounded-lg"
|
|
343
406
|
style="position: relative; display: inline-block; width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
|
|
344
407
|
>
|
|
345
|
-
<!-- SVG image -->
|
|
408
|
+
<!-- SVG image or raster image -->
|
|
346
409
|
{#if parsedInteraction.imageData?.content}
|
|
347
410
|
{@html parsedInteraction.imageData.content}
|
|
411
|
+
{:else if parsedInteraction.imageData?.src}
|
|
412
|
+
<img
|
|
413
|
+
src={parsedInteraction.imageData.src}
|
|
414
|
+
alt={i18n?.t('interactions.graphicGapMatch.imageAlt') ?? 'Graphic gap match image'}
|
|
415
|
+
style="width: 100%; height: 100%; display: block; position: absolute; top: 0; left: 0;"
|
|
416
|
+
/>
|
|
348
417
|
{/if}
|
|
349
418
|
|
|
350
419
|
<!-- Overlay with hotspot drop zones -->
|
|
@@ -355,13 +424,14 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
355
424
|
viewBox="0 0 {parsedInteraction.imageData?.width} {parsedInteraction.imageData?.height}"
|
|
356
425
|
>
|
|
357
426
|
{#each parsedInteraction.hotspots as hotspot (hotspot.identifier)}
|
|
358
|
-
{@const coords = parseCoords(hotspot)}
|
|
359
427
|
{@const matchedGapText = getMatchedGapText(hotspot.identifier)}
|
|
360
428
|
{@const gapTextObj = matchedGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === matchedGapText) : null}
|
|
361
429
|
{@const isHovered = hoveredHotspotId === hotspot.identifier}
|
|
362
430
|
{@const correctGapText = getCorrectGapText(hotspot.identifier)}
|
|
363
431
|
{@const correctGapTextObj = correctGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === correctGapText) : null}
|
|
364
432
|
{@const isCorrect = isCorrectHotspot(hotspot.identifier)}
|
|
433
|
+
{@const hotspotReady = !!pickedUpLabel && !disabled}
|
|
434
|
+
{@const pickedUpLabelName = pickedUpLabel ? getLabelName(pickedUpLabel) : ''}
|
|
365
435
|
|
|
366
436
|
<g>
|
|
367
437
|
<!-- Hotspot drop zone -->
|
|
@@ -370,46 +440,48 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
370
440
|
{@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
|
|
371
441
|
<circle
|
|
372
442
|
role="button"
|
|
373
|
-
tabindex={disabled
|
|
374
|
-
aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '.
|
|
443
|
+
tabindex={disabled ? -1 : 0}
|
|
444
|
+
aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '. Empty'}{hotspotReady ? '. Press Enter to place ' + pickedUpLabelName + ' here' : ''}"
|
|
375
445
|
cx={cx}
|
|
376
446
|
cy={cy}
|
|
377
447
|
r={r}
|
|
378
|
-
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
|
|
379
|
-
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : isHovered ? '0.2' : '0'}
|
|
380
|
-
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
381
|
-
stroke-width=
|
|
382
|
-
stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
|
|
383
|
-
class="transition-all"
|
|
384
|
-
style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
|
|
448
|
+
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : hotspotReady ? '#3b82f6' : isHovered ? '#3b82f6' : 'transparent'}
|
|
449
|
+
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : hotspotReady ? '0.15' : isHovered ? '0.2' : '0'}
|
|
450
|
+
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : hotspotReady ? '#3b82f6' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
451
|
+
stroke-width={hotspotReady ? '3' : '2'}
|
|
452
|
+
stroke-dasharray={matchedGapText || isCorrect ? '' : hotspotReady ? '6,3' : '4,4'}
|
|
453
|
+
class="transition-all{hotspotReady ? ' qti-ggm-hotspot-ready' : ''}"
|
|
454
|
+
style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : hotspotReady ? 'copy' : 'pointer'};"
|
|
385
455
|
ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
|
|
386
456
|
ondragleave={handleHotspotDragLeave}
|
|
387
457
|
ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
|
|
388
|
-
onclick={() =>
|
|
458
|
+
onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
|
|
389
459
|
onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
|
|
390
460
|
/>
|
|
391
461
|
{:else if hotspot.shape === 'rect'}
|
|
392
|
-
{@const [x, y,
|
|
462
|
+
{@const [x, y, right, bottom] = hotspot.coords.split(',').map(Number)}
|
|
463
|
+
{@const width = right - x}
|
|
464
|
+
{@const height = bottom - y}
|
|
393
465
|
{@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
|
|
394
466
|
<rect
|
|
395
467
|
role="button"
|
|
396
|
-
tabindex={disabled
|
|
397
|
-
aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '.
|
|
468
|
+
tabindex={disabled ? -1 : 0}
|
|
469
|
+
aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '. Empty'}{hotspotReady ? '. Press Enter to place ' + pickedUpLabelName + ' here' : ''}"
|
|
398
470
|
x={x}
|
|
399
471
|
y={y}
|
|
400
472
|
width={width}
|
|
401
473
|
height={height}
|
|
402
|
-
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
|
|
403
|
-
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : isHovered ? '0.2' : '0'}
|
|
404
|
-
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
405
|
-
stroke-width=
|
|
406
|
-
stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
|
|
407
|
-
class="transition-all"
|
|
408
|
-
style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
|
|
474
|
+
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : hotspotReady ? '#3b82f6' : isHovered ? '#3b82f6' : 'transparent'}
|
|
475
|
+
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : hotspotReady ? '0.15' : isHovered ? '0.2' : '0'}
|
|
476
|
+
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : hotspotReady ? '#3b82f6' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
477
|
+
stroke-width={hotspotReady ? '3' : '2'}
|
|
478
|
+
stroke-dasharray={matchedGapText || isCorrect ? '' : hotspotReady ? '6,3' : '4,4'}
|
|
479
|
+
class="transition-all{hotspotReady ? ' qti-ggm-hotspot-ready' : ''}"
|
|
480
|
+
style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : hotspotReady ? 'copy' : 'pointer'};"
|
|
409
481
|
ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
|
|
410
482
|
ondragleave={handleHotspotDragLeave}
|
|
411
483
|
ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
|
|
412
|
-
onclick={() =>
|
|
484
|
+
onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
|
|
413
485
|
onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
|
|
414
486
|
/>
|
|
415
487
|
{/if}
|
|
@@ -500,4 +572,22 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
500
572
|
display: block;
|
|
501
573
|
}
|
|
502
574
|
|
|
575
|
+
/* Label button in "held" (picked-up) state */
|
|
576
|
+
:global(.qti-ggm-label-held) {
|
|
577
|
+
outline: 3px solid var(--color-accent, oklch(65% 0.2 320));
|
|
578
|
+
outline-offset: 2px;
|
|
579
|
+
background-color: var(--color-accent, oklch(65% 0.2 320)) !important;
|
|
580
|
+
color: var(--color-accent-content, #fff) !important;
|
|
581
|
+
box-shadow: 0 0 0 4px oklch(65% 0.2 320 / 0.25);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/* SVG hotspot shape in "ready to receive drop" state — pulsing outline */
|
|
585
|
+
:global(.qti-ggm-hotspot-ready) {
|
|
586
|
+
animation: ggm-hotspot-pulse 1.2s ease-in-out infinite;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
@keyframes ggm-hotspot-pulse {
|
|
590
|
+
0%, 100% { stroke-opacity: 1; }
|
|
591
|
+
50% { stroke-opacity: 0.4; }
|
|
592
|
+
}
|
|
503
593
|
</style>
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
|
|
85
85
|
<ShadowBaseStyles />
|
|
86
86
|
|
|
87
|
-
<div bind:this={rootElement} class=
|
|
87
|
+
<div bind:this={rootElement} class={['qti-hotspot-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
|
|
88
88
|
{#if !parsedInteraction}
|
|
89
89
|
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
90
90
|
{:else}
|
|
@@ -123,6 +123,9 @@
|
|
|
123
123
|
{@const isCorrectChoice = isCorrect(choice.identifier)}
|
|
124
124
|
{@const coords = choice.coords.split(',').map(Number)}
|
|
125
125
|
|
|
126
|
+
{@const shapeLabel = choice.hotspotLabel || `Hotspot ${choice.identifier}`}
|
|
127
|
+
{@const ariaLabel = `${shapeLabel}${isCorrectChoice ? '. Correct answer' : ''}`}
|
|
128
|
+
|
|
126
129
|
{#if choice.shape === 'circle'}
|
|
127
130
|
<!-- Circle: coords are cx, cy, radius -->
|
|
128
131
|
<circle
|
|
@@ -134,25 +137,43 @@
|
|
|
134
137
|
stroke-width="2"
|
|
135
138
|
class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
|
|
136
139
|
role="button"
|
|
137
|
-
aria-label={
|
|
140
|
+
aria-label={ariaLabel}
|
|
138
141
|
aria-pressed={isSelected ? 'true' : 'false'}
|
|
139
142
|
tabindex={disabled ? -1 : 0}
|
|
140
143
|
onclick={() => handleClick(choice.identifier)}
|
|
141
144
|
onkeydown={(e) => handleKeyDown(e, choice.identifier)}
|
|
142
145
|
/>
|
|
143
146
|
{:else if choice.shape === 'rect'}
|
|
144
|
-
<!-- Rectangle: coords are
|
|
147
|
+
<!-- Rectangle: QTI coords are left,top,right,bottom -->
|
|
145
148
|
<rect
|
|
146
149
|
x={coords[0]}
|
|
147
150
|
y={coords[1]}
|
|
148
|
-
width={coords[2]}
|
|
149
|
-
height={coords[3]}
|
|
151
|
+
width={coords[2] - coords[0]}
|
|
152
|
+
height={coords[3] - coords[1]}
|
|
150
153
|
fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
|
|
151
154
|
stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
|
|
152
155
|
stroke-width="2"
|
|
153
156
|
class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
|
|
154
157
|
role="button"
|
|
155
|
-
aria-label={
|
|
158
|
+
aria-label={ariaLabel}
|
|
159
|
+
aria-pressed={isSelected ? 'true' : 'false'}
|
|
160
|
+
tabindex={disabled ? -1 : 0}
|
|
161
|
+
onclick={() => handleClick(choice.identifier)}
|
|
162
|
+
onkeydown={(e) => handleKeyDown(e, choice.identifier)}
|
|
163
|
+
/>
|
|
164
|
+
{:else if choice.shape === 'ellipse'}
|
|
165
|
+
<!-- Ellipse: QTI coords are cx,cy,rx,ry -->
|
|
166
|
+
<ellipse
|
|
167
|
+
cx={coords[0]}
|
|
168
|
+
cy={coords[1]}
|
|
169
|
+
rx={coords[2]}
|
|
170
|
+
ry={coords[3]}
|
|
171
|
+
fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
|
|
172
|
+
stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
|
|
173
|
+
stroke-width="2"
|
|
174
|
+
class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
|
|
175
|
+
role="button"
|
|
176
|
+
aria-label={ariaLabel}
|
|
156
177
|
aria-pressed={isSelected ? 'true' : 'false'}
|
|
157
178
|
tabindex={disabled ? -1 : 0}
|
|
158
179
|
onclick={() => handleClick(choice.identifier)}
|
|
@@ -175,7 +196,7 @@
|
|
|
175
196
|
stroke-width="2"
|
|
176
197
|
class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
|
|
177
198
|
role="button"
|
|
178
|
-
aria-label={
|
|
199
|
+
aria-label={ariaLabel}
|
|
179
200
|
aria-pressed={isSelected ? 'true' : 'false'}
|
|
180
201
|
tabindex={disabled ? -1 : 0}
|
|
181
202
|
onclick={() => handleClick(choice.identifier)}
|
|
@@ -197,10 +218,32 @@
|
|
|
197
218
|
{/if}
|
|
198
219
|
</div>
|
|
199
220
|
{/if}
|
|
221
|
+
{#if parsedInteraction.maxSelectionsMessage}
|
|
222
|
+
{@const selected = Array.isArray(parsedResponse) ? parsedResponse : (parsedResponse ? [parsedResponse] : [])}
|
|
223
|
+
{#if selected.length >= parsedInteraction.maxChoices && parsedInteraction.maxChoices > 0}
|
|
224
|
+
<p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
|
|
225
|
+
{/if}
|
|
226
|
+
{/if}
|
|
200
227
|
{/if}
|
|
201
228
|
</div>
|
|
202
229
|
|
|
203
230
|
<style>
|
|
231
|
+
.qti-selection-message {
|
|
232
|
+
font-size: 0.875rem;
|
|
233
|
+
color: var(--color-warning, oklch(77% 0.194 82));
|
|
234
|
+
margin-top: 0.25rem;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* qti-selections-light / qti-selections-dark: hotspot overlay color theme */
|
|
238
|
+
.qti-selections-light .qti-hotspot-shape {
|
|
239
|
+
fill: rgba(255, 255, 255, 0.4);
|
|
240
|
+
stroke: rgba(255, 255, 255, 0.8);
|
|
241
|
+
}
|
|
242
|
+
.qti-selections-dark .qti-hotspot-shape {
|
|
243
|
+
fill: rgba(0, 0, 0, 0.4);
|
|
244
|
+
stroke: rgba(0, 0, 0, 0.8);
|
|
245
|
+
}
|
|
246
|
+
|
|
204
247
|
/* Minimal layout so this works without Tailwind utilities */
|
|
205
248
|
.qti-hotspot-interaction {
|
|
206
249
|
display: grid;
|