@pie-qti/default-components 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.
- 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/extensions/MathLiveEditor.d.ts +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
- package/dist/shared/extensions/MathLiveEditor.js +3 -7
- package/dist/shared/utils/eventHelpers.d.ts +3 -11
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
- package/dist/shared/utils/eventHelpers.js +7 -1
- 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/dist/shared/utils/pairHelpers.d.ts +15 -2
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
- package/dist/shared/utils/pairHelpers.js +30 -8
- package/dist/shared/utils/touchDragHelper.d.ts +1 -32
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
- package/dist/shared/utils/touchDragHelper.js +1 -168
- package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
- package/dist/shared/utils/webComponentHelpers.js +3 -3
- package/package.json +117 -91
- 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 +199 -22
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +230 -145
- 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/media/MediaInteraction.svelte +2 -2
- package/src/plugins/order/OrderInteraction.svelte +132 -11
- package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -15
- package/src/plugins/select-point/SelectPointInteraction.svelte +139 -21
- package/src/shared/components/DrawingCanvas.svelte +17 -1
- 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 +72 -25
- package/src/shared/components/ShadowBaseStyles.svelte +1 -2
- package/src/shared/extensions/MathLiveEditor.ts +3 -8
- package/src/shared/styles/qti-shared-vocabulary.css +320 -0
- package/src/shared/utils/eventHelpers.ts +12 -3
- package/src/shared/utils/matchGroupUtils.ts +14 -0
- package/src/shared/utils/pairHelpers.ts +32 -9
- package/src/shared/utils/touchDragHelper.ts +1 -211
- package/src/shared/utils/webComponentHelpers.ts +5 -5
- package/.turbo/turbo-build.log +0 -1
- package/CHANGELOG.md +0 -9
- package/STYLING.md +0 -226
- package/svelte.config.js +0 -9
- package/tests/index.test.ts +0 -8
- package/tsconfig.json +0 -20
|
@@ -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,12 +38,47 @@ 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>('');
|
|
45
|
+
|
|
46
|
+
// Get reference to the root element for event dispatching (needed for Shadow DOM)
|
|
47
|
+
let rootElement: HTMLDivElement | undefined = $state();
|
|
48
|
+
|
|
49
|
+
// Track if we're updating from internal change (user drag) vs external (prop update)
|
|
50
|
+
let isInternalUpdate = false;
|
|
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
|
+
});
|
|
42
74
|
|
|
43
75
|
$effect(() => {
|
|
44
|
-
// Sync with parent response changes
|
|
45
|
-
|
|
76
|
+
// Sync with parent response changes (only if not an internal update)
|
|
77
|
+
if (!isInternalUpdate) {
|
|
78
|
+
const newPairs = Array.isArray(parsedResponse) ? [...parsedResponse] : [];
|
|
79
|
+
pairs = newPairs;
|
|
80
|
+
}
|
|
81
|
+
isInternalUpdate = false; // Reset flag
|
|
46
82
|
});
|
|
47
83
|
|
|
48
84
|
// Get the hotspot matched to a gap text
|
|
@@ -57,23 +93,12 @@ function getMatchedGapText(hotspotId: string): string | null {
|
|
|
57
93
|
return pair ? pair.split(' ')[0] : null;
|
|
58
94
|
}
|
|
59
95
|
|
|
60
|
-
// Get the correct hotspot for a gap text
|
|
61
|
-
function getCorrectHotspot(gapTextId: string): string | null {
|
|
62
|
-
const pair = correctPairs.find((p) => p.startsWith(`${gapTextId} `));
|
|
63
|
-
return pair ? pair.split(' ')[1] : null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
96
|
// Get the correct gap text for a hotspot
|
|
67
97
|
function getCorrectGapText(hotspotId: string): string | null {
|
|
68
98
|
const pair = correctPairs.find((p) => p.endsWith(` ${hotspotId}`));
|
|
69
99
|
return pair ? pair.split(' ')[0] : null;
|
|
70
100
|
}
|
|
71
101
|
|
|
72
|
-
// Check if a gap text has a correct answer
|
|
73
|
-
function isCorrectGapText(gapTextId: string): boolean {
|
|
74
|
-
return isShowingCorrect && getCorrectHotspot(gapTextId) !== null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
102
|
// Check if a hotspot has a correct answer
|
|
78
103
|
function isCorrectHotspot(hotspotId: string): boolean {
|
|
79
104
|
return isShowingCorrect && getCorrectGapText(hotspotId) !== null;
|
|
@@ -100,7 +125,7 @@ function handleHotspotDragLeave() {
|
|
|
100
125
|
}
|
|
101
126
|
|
|
102
127
|
function handleHotspotDrop(event: DragEvent, hotspotId: string) {
|
|
103
|
-
if (disabled || !draggedTextId) return;
|
|
128
|
+
if (disabled || !draggedTextId || !parsedInteraction) return;
|
|
104
129
|
event.preventDefault();
|
|
105
130
|
|
|
106
131
|
// Remove any existing pair for this gapText
|
|
@@ -112,21 +137,16 @@ function handleHotspotDrop(event: DragEvent, hotspotId: string) {
|
|
|
112
137
|
// Add new pair
|
|
113
138
|
newPairs.push(`${draggedTextId} ${hotspotId}`);
|
|
114
139
|
|
|
140
|
+
isInternalUpdate = true; // Mark as internal update to prevent sync effect from overwriting
|
|
115
141
|
pairs = newPairs;
|
|
116
142
|
response = pairs;
|
|
117
143
|
// Call onChange callback if provided (for Svelte component usage)
|
|
118
144
|
onChange?.(pairs);
|
|
119
|
-
// Dispatch custom event for web component usage
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
timestamp: Date.now(),
|
|
125
|
-
},
|
|
126
|
-
bubbles: true,
|
|
127
|
-
composed: true,
|
|
128
|
-
});
|
|
129
|
-
dispatchEvent(event2);
|
|
145
|
+
// Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
|
|
146
|
+
const valueArray = Array.isArray(pairs) ? [...pairs] : [];
|
|
147
|
+
if (rootElement) {
|
|
148
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
|
|
149
|
+
}
|
|
130
150
|
|
|
131
151
|
draggedTextId = null;
|
|
132
152
|
hoveredHotspotId = null;
|
|
@@ -138,129 +158,114 @@ function clearMatch(gapTextId: string) {
|
|
|
138
158
|
const gapTextName = gapTextObj?.text || 'Label';
|
|
139
159
|
|
|
140
160
|
const newPairs = pairs.filter((p) => !p.startsWith(`${gapTextId} `));
|
|
161
|
+
isInternalUpdate = true; // Mark as internal update
|
|
141
162
|
pairs = newPairs;
|
|
142
163
|
response = pairs;
|
|
143
164
|
// Call onChange callback if provided (for Svelte component usage)
|
|
144
165
|
onChange?.(pairs);
|
|
145
|
-
// Dispatch custom event for web component usage
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
bubbles: true,
|
|
153
|
-
composed: true,
|
|
154
|
-
});
|
|
155
|
-
dispatchEvent(event);
|
|
156
|
-
|
|
157
|
-
announceText = `${gapTextName} removed from hotspot`;
|
|
166
|
+
// Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
|
|
167
|
+
const valueArray = Array.isArray(pairs) ? [...pairs] : [];
|
|
168
|
+
if (rootElement) {
|
|
169
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
|
|
170
|
+
}
|
|
171
|
+
|
|
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
|
|
|
228
|
+
isInternalUpdate = true; // Mark as internal update
|
|
216
229
|
pairs = newPairs;
|
|
217
230
|
response = pairs;
|
|
218
231
|
// Call onChange callback if provided (for Svelte component usage)
|
|
219
232
|
onChange?.(pairs);
|
|
220
|
-
// Dispatch custom event for web component usage
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
composed: true,
|
|
229
|
-
});
|
|
230
|
-
dispatchEvent(event2);
|
|
231
|
-
|
|
232
|
-
announceText = `${gapTextName} placed on hotspot ${hotspotIndex + 1}`;
|
|
233
|
-
keyboardSelectedTextId = null;
|
|
233
|
+
// Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
|
|
234
|
+
const valueArray = Array.isArray(pairs) ? [...pairs] : [];
|
|
235
|
+
if (rootElement) {
|
|
236
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
liveMessage = `Placed ${labelName} on hotspot ${hotspotIndex + 1}.`;
|
|
240
|
+
pickedUpLabel = null;
|
|
234
241
|
}
|
|
235
242
|
|
|
236
243
|
function handleHotspotKeyDown(event: KeyboardEvent, hotspotId: string) {
|
|
237
|
-
if (disabled || !
|
|
244
|
+
if (disabled || !parsedInteraction) return;
|
|
238
245
|
|
|
239
246
|
if (event.key === ' ' || event.key === 'Enter') {
|
|
240
|
-
|
|
241
|
-
|
|
247
|
+
if (pickedUpLabel) {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
placePickedUpLabelOnHotspot(hotspotId);
|
|
250
|
+
}
|
|
242
251
|
}
|
|
243
252
|
}
|
|
244
253
|
|
|
245
|
-
//
|
|
246
|
-
function
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
|
|
252
|
-
} else if (shape === 'rect') {
|
|
253
|
-
const [x, y, width, height] = coords;
|
|
254
|
-
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.';
|
|
255
260
|
}
|
|
256
|
-
// For poly, use bounding box (simplified)
|
|
257
|
-
return { x: coords[0], y: coords[1], width: 40, height: 40 };
|
|
258
261
|
}
|
|
262
|
+
|
|
259
263
|
</script>
|
|
260
264
|
|
|
261
265
|
<ShadowBaseStyles />
|
|
262
266
|
|
|
263
|
-
|
|
267
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
268
|
+
<div bind:this={rootElement} class={['qti-graphic-gap-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} onkeydown={handleRootKeyDown}>
|
|
264
269
|
{#if !parsedInteraction}
|
|
265
270
|
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
266
271
|
{:else}
|
|
@@ -268,14 +273,14 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
268
273
|
<p part="prompt" class="qti-ggm-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
|
|
269
274
|
{/if}
|
|
270
275
|
|
|
271
|
-
<!--
|
|
276
|
+
<!-- Visually-hidden live region for screen reader announcements -->
|
|
272
277
|
<div aria-live="polite" aria-atomic="true" class="sr-only">
|
|
273
|
-
{
|
|
278
|
+
{liveMessage}
|
|
274
279
|
</div>
|
|
275
280
|
|
|
276
281
|
<!-- Instructions for keyboard users -->
|
|
277
282
|
<div id="graphic-gap-match-instructions" class="sr-only">
|
|
278
|
-
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.
|
|
279
284
|
</div>
|
|
280
285
|
|
|
281
286
|
<div
|
|
@@ -289,6 +294,7 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
289
294
|
<div
|
|
290
295
|
part="labels"
|
|
291
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}
|
|
292
298
|
role="group"
|
|
293
299
|
aria-label={i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'Available labels to place'}
|
|
294
300
|
>
|
|
@@ -298,27 +304,30 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
298
304
|
{#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
|
|
299
305
|
{@const matchedHotspot = getMatchedHotspot(gapText.identifier)}
|
|
300
306
|
{@const isDragged = draggedTextId === gapText.identifier}
|
|
301
|
-
{@const
|
|
307
|
+
{@const isHeld = pickedUpLabel === gapText.identifier}
|
|
308
|
+
{@const isUnavailable = unavailableLabels.has(gapText.identifier)}
|
|
302
309
|
|
|
303
310
|
<div class="inline-flex items-center gap-1">
|
|
304
311
|
<button
|
|
305
312
|
type="button"
|
|
306
|
-
draggable={!disabled && !matchedHotspot}
|
|
313
|
+
draggable={!disabled && !matchedHotspot && !isUnavailable}
|
|
307
314
|
use:touchDrag
|
|
308
315
|
ondragstart={() => handleDragStart(gapText.identifier)}
|
|
309
316
|
ondragend={handleDragEnd}
|
|
310
|
-
onclick={() =>
|
|
311
|
-
onkeydown={(e) =>
|
|
317
|
+
onclick={() => handleLabelActivate(gapText.identifier)}
|
|
318
|
+
onkeydown={(e) => handleLabelKeyDown(e, gapText.identifier)}
|
|
312
319
|
disabled={disabled || !!matchedHotspot}
|
|
313
|
-
aria-
|
|
314
|
-
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'}"
|
|
315
323
|
class="btn btn-md font-medium transition-all"
|
|
316
|
-
class:btn-primary={!matchedHotspot && !
|
|
317
|
-
class:
|
|
324
|
+
class:btn-primary={!matchedHotspot && !isHeld}
|
|
325
|
+
class:qti-ggm-label-held={isHeld}
|
|
318
326
|
class:btn-success={matchedHotspot}
|
|
319
|
-
class:cursor-grab={!disabled && !matchedHotspot && !
|
|
320
|
-
class:cursor-not-allowed={disabled}
|
|
321
|
-
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)}
|
|
322
331
|
class:contrast-125={matchedHotspot}
|
|
323
332
|
class:saturate-150={matchedHotspot}
|
|
324
333
|
>
|
|
@@ -338,6 +347,55 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
338
347
|
{/if}
|
|
339
348
|
</div>
|
|
340
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}
|
|
341
399
|
</div>
|
|
342
400
|
{/if}
|
|
343
401
|
|
|
@@ -347,9 +405,15 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
347
405
|
class="qti-ggm-stage relative inline-block border-2 border-base-300 rounded-lg"
|
|
348
406
|
style="position: relative; display: inline-block; width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
|
|
349
407
|
>
|
|
350
|
-
<!-- SVG image -->
|
|
408
|
+
<!-- SVG image or raster image -->
|
|
351
409
|
{#if parsedInteraction.imageData?.content}
|
|
352
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
|
+
/>
|
|
353
417
|
{/if}
|
|
354
418
|
|
|
355
419
|
<!-- Overlay with hotspot drop zones -->
|
|
@@ -360,13 +424,14 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
360
424
|
viewBox="0 0 {parsedInteraction.imageData?.width} {parsedInteraction.imageData?.height}"
|
|
361
425
|
>
|
|
362
426
|
{#each parsedInteraction.hotspots as hotspot (hotspot.identifier)}
|
|
363
|
-
{@const coords = parseCoords(hotspot)}
|
|
364
427
|
{@const matchedGapText = getMatchedGapText(hotspot.identifier)}
|
|
365
428
|
{@const gapTextObj = matchedGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === matchedGapText) : null}
|
|
366
429
|
{@const isHovered = hoveredHotspotId === hotspot.identifier}
|
|
367
430
|
{@const correctGapText = getCorrectGapText(hotspot.identifier)}
|
|
368
431
|
{@const correctGapTextObj = correctGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === correctGapText) : null}
|
|
369
432
|
{@const isCorrect = isCorrectHotspot(hotspot.identifier)}
|
|
433
|
+
{@const hotspotReady = !!pickedUpLabel && !disabled}
|
|
434
|
+
{@const pickedUpLabelName = pickedUpLabel ? getLabelName(pickedUpLabel) : ''}
|
|
370
435
|
|
|
371
436
|
<g>
|
|
372
437
|
<!-- Hotspot drop zone -->
|
|
@@ -375,46 +440,48 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
375
440
|
{@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
|
|
376
441
|
<circle
|
|
377
442
|
role="button"
|
|
378
|
-
tabindex={disabled
|
|
379
|
-
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' : ''}"
|
|
380
445
|
cx={cx}
|
|
381
446
|
cy={cy}
|
|
382
447
|
r={r}
|
|
383
|
-
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
|
|
384
|
-
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : isHovered ? '0.2' : '0'}
|
|
385
|
-
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
386
|
-
stroke-width=
|
|
387
|
-
stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
|
|
388
|
-
class="transition-all"
|
|
389
|
-
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'};"
|
|
390
455
|
ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
|
|
391
456
|
ondragleave={handleHotspotDragLeave}
|
|
392
457
|
ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
|
|
393
|
-
onclick={() =>
|
|
458
|
+
onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
|
|
394
459
|
onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
|
|
395
460
|
/>
|
|
396
461
|
{:else if hotspot.shape === 'rect'}
|
|
397
|
-
{@const [x, y,
|
|
462
|
+
{@const [x, y, right, bottom] = hotspot.coords.split(',').map(Number)}
|
|
463
|
+
{@const width = right - x}
|
|
464
|
+
{@const height = bottom - y}
|
|
398
465
|
{@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
|
|
399
466
|
<rect
|
|
400
467
|
role="button"
|
|
401
|
-
tabindex={disabled
|
|
402
|
-
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' : ''}"
|
|
403
470
|
x={x}
|
|
404
471
|
y={y}
|
|
405
472
|
width={width}
|
|
406
473
|
height={height}
|
|
407
|
-
fill={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
|
|
408
|
-
fill-opacity={matchedGapText ? '0.3' : isCorrect ? '0.2' : isHovered ? '0.2' : '0'}
|
|
409
|
-
stroke={matchedGapText ? '#10b981' : isCorrect ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
|
|
410
|
-
stroke-width=
|
|
411
|
-
stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
|
|
412
|
-
class="transition-all"
|
|
413
|
-
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'};"
|
|
414
481
|
ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
|
|
415
482
|
ondragleave={handleHotspotDragLeave}
|
|
416
483
|
ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
|
|
417
|
-
onclick={() =>
|
|
484
|
+
onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
|
|
418
485
|
onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
|
|
419
486
|
/>
|
|
420
487
|
{/if}
|
|
@@ -505,4 +572,22 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
|
|
|
505
572
|
display: block;
|
|
506
573
|
}
|
|
507
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
|
+
}
|
|
508
593
|
</style>
|