@pie-qti/default-components 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/STYLING.md +226 -0
  4. package/dist/index.d.ts +35 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +190 -0
  7. package/dist/plugins/associate/index.d.ts +8 -0
  8. package/dist/plugins/associate/index.d.ts.map +1 -0
  9. package/dist/plugins/associate/index.js +8 -0
  10. package/dist/plugins/choice/index.d.ts +8 -0
  11. package/dist/plugins/choice/index.d.ts.map +1 -0
  12. package/dist/plugins/choice/index.js +8 -0
  13. package/dist/plugins/custom/index.d.ts +8 -0
  14. package/dist/plugins/custom/index.d.ts.map +1 -0
  15. package/dist/plugins/custom/index.js +8 -0
  16. package/dist/plugins/end-attempt/index.d.ts +8 -0
  17. package/dist/plugins/end-attempt/index.d.ts.map +1 -0
  18. package/dist/plugins/end-attempt/index.js +8 -0
  19. package/dist/plugins/extended-text/index.d.ts +8 -0
  20. package/dist/plugins/extended-text/index.d.ts.map +1 -0
  21. package/dist/plugins/extended-text/index.js +8 -0
  22. package/dist/plugins/gap-match/index.d.ts +8 -0
  23. package/dist/plugins/gap-match/index.d.ts.map +1 -0
  24. package/dist/plugins/gap-match/index.js +8 -0
  25. package/dist/plugins/graphic-associate/index.d.ts +8 -0
  26. package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
  27. package/dist/plugins/graphic-associate/index.js +8 -0
  28. package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.js +8 -0
  31. package/dist/plugins/graphic-order/index.d.ts +8 -0
  32. package/dist/plugins/graphic-order/index.d.ts.map +1 -0
  33. package/dist/plugins/graphic-order/index.js +8 -0
  34. package/dist/plugins/hotspot/index.d.ts +8 -0
  35. package/dist/plugins/hotspot/index.d.ts.map +1 -0
  36. package/dist/plugins/hotspot/index.js +8 -0
  37. package/dist/plugins/hottext/index.d.ts +8 -0
  38. package/dist/plugins/hottext/index.d.ts.map +1 -0
  39. package/dist/plugins/hottext/index.js +8 -0
  40. package/dist/plugins/index.d.ts +30 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/match/index.d.ts +8 -0
  44. package/dist/plugins/match/index.d.ts.map +1 -0
  45. package/dist/plugins/match/index.js +8 -0
  46. package/dist/plugins/media/index.d.ts +8 -0
  47. package/dist/plugins/media/index.d.ts.map +1 -0
  48. package/dist/plugins/media/index.js +8 -0
  49. package/dist/plugins/order/index.d.ts +8 -0
  50. package/dist/plugins/order/index.d.ts.map +1 -0
  51. package/dist/plugins/order/index.js +8 -0
  52. package/dist/plugins/position-object/index.d.ts +8 -0
  53. package/dist/plugins/position-object/index.d.ts.map +1 -0
  54. package/dist/plugins/position-object/index.js +8 -0
  55. package/dist/plugins/select-point/index.d.ts +8 -0
  56. package/dist/plugins/select-point/index.d.ts.map +1 -0
  57. package/dist/plugins/select-point/index.js +8 -0
  58. package/dist/plugins/slider/index.d.ts +8 -0
  59. package/dist/plugins/slider/index.d.ts.map +1 -0
  60. package/dist/plugins/slider/index.js +8 -0
  61. package/dist/shared/actions/typesetAction.d.ts +26 -0
  62. package/dist/shared/actions/typesetAction.d.ts.map +1 -0
  63. package/dist/shared/actions/typesetAction.js +70 -0
  64. package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
  65. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
  66. package/dist/shared/extensions/MathLiveEditor.js +239 -0
  67. package/dist/shared/index.d.ts +11 -0
  68. package/dist/shared/index.d.ts.map +1 -0
  69. package/dist/shared/index.js +15 -0
  70. package/dist/shared/utils/eventHelpers.d.ts +18 -0
  71. package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
  72. package/dist/shared/utils/eventHelpers.js +30 -0
  73. package/dist/shared/utils/pairHelpers.d.ts +55 -0
  74. package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
  75. package/dist/shared/utils/pairHelpers.js +76 -0
  76. package/dist/shared/utils/touchDragHelper.d.ts +33 -0
  77. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
  78. package/dist/shared/utils/touchDragHelper.js +168 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
  80. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
  81. package/dist/shared/utils/webComponentHelpers.js +26 -0
  82. package/package.json +93 -0
  83. package/src/index.ts +213 -0
  84. package/src/plugins/associate/AssociateInteraction.svelte +273 -0
  85. package/src/plugins/associate/index.ts +9 -0
  86. package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
  87. package/src/plugins/choice/index.ts +9 -0
  88. package/src/plugins/custom/CustomInteraction.svelte +61 -0
  89. package/src/plugins/custom/index.ts +9 -0
  90. package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
  91. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
  92. package/src/plugins/end-attempt/index.ts +9 -0
  93. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
  94. package/src/plugins/extended-text/index.ts +9 -0
  95. package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
  96. package/src/plugins/gap-match/index.ts +9 -0
  97. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
  98. package/src/plugins/graphic-associate/index.ts +9 -0
  99. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
  100. package/src/plugins/graphic-gap-match/index.ts +9 -0
  101. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
  102. package/src/plugins/graphic-order/index.ts +9 -0
  103. package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
  104. package/src/plugins/hotspot/index.ts +9 -0
  105. package/src/plugins/hottext/HottextInteraction.svelte +296 -0
  106. package/src/plugins/hottext/index.ts +9 -0
  107. package/src/plugins/index.ts +31 -0
  108. package/src/plugins/match/MatchInteraction.svelte +70 -0
  109. package/src/plugins/match/index.ts +9 -0
  110. package/src/plugins/media/MediaInteraction.svelte +213 -0
  111. package/src/plugins/media/index.ts +9 -0
  112. package/src/plugins/order/OrderInteraction.svelte +159 -0
  113. package/src/plugins/order/index.ts +9 -0
  114. package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
  115. package/src/plugins/position-object/README.md +130 -0
  116. package/src/plugins/position-object/index.ts +9 -0
  117. package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
  118. package/src/plugins/select-point/index.ts +9 -0
  119. package/src/plugins/slider/SliderInteraction.svelte +141 -0
  120. package/src/plugins/slider/index.ts +9 -0
  121. package/src/plugins/upload/UploadInteraction.svelte +59 -0
  122. package/src/shared/actions/typesetAction.ts +87 -0
  123. package/src/shared/components/CustomInteractionFallback.svelte +153 -0
  124. package/src/shared/components/DragHandle.svelte +44 -0
  125. package/src/shared/components/DrawingCanvas.svelte +243 -0
  126. package/src/shared/components/FileUpload.svelte +153 -0
  127. package/src/shared/components/GraphicGapMatch.svelte +316 -0
  128. package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
  129. package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
  130. package/src/shared/components/MatchDragDrop.svelte +434 -0
  131. package/src/shared/components/MathContent.svelte +18 -0
  132. package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
  133. package/src/shared/components/RichTextEditor.svelte +316 -0
  134. package/src/shared/components/ShadowBaseStyles.svelte +391 -0
  135. package/src/shared/components/SortableList.svelte +297 -0
  136. package/src/shared/extensions/MathLiveEditor.ts +304 -0
  137. package/src/shared/index.ts +17 -0
  138. package/src/shared/styles/shared.css +16 -0
  139. package/src/shared/utils/eventHelpers.ts +36 -0
  140. package/src/shared/utils/pairHelpers.ts +86 -0
  141. package/src/shared/utils/touchDragHelper.ts +211 -0
  142. package/src/shared/utils/webComponentHelpers.ts +27 -0
  143. package/src/svelte-shims.d.ts +9 -0
  144. package/svelte.config.js +9 -0
  145. package/tests/index.test.ts +8 -0
  146. package/tsconfig.json +20 -0
@@ -0,0 +1,508 @@
1
+ <svelte:options customElement="pie-qti-graphic-gap-match" />
2
+
3
+ <script lang="ts">
4
+ /**
5
+ * Graphic Gap Match component for graphicGapMatchInteractionData
6
+ * Drag labels onto specific areas of an image/diagram
7
+ * Supports keyboard, mouse, and touch interactions
8
+ */
9
+
10
+ import type { GraphicGapMatchInteractionData } from '@pie-qti/item-player';
11
+ import type { I18nProvider } from '@pie-qti/i18n';
12
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers.js';
13
+ import { touchDrag } from '../../shared/utils/touchDragHelper.js';
14
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
15
+ import '../../shared/styles/shared.css';
16
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
17
+
18
+ interface Props {
19
+ interaction?: GraphicGapMatchInteractionData | string;
20
+ response?: string | string[] | null;
21
+ correctResponse?: string[] | null;
22
+ disabled?: boolean;
23
+ role?: string;
24
+ i18n?: I18nProvider;
25
+ onChange?: (value: string[]) => void;
26
+ }
27
+
28
+ let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
29
+
30
+ // Parse props that may be JSON strings (web component usage)
31
+ const parsedInteraction = $derived(parseJsonProp<GraphicGapMatchInteractionData>(interaction));
32
+ const parsedResponse = $derived(parseJsonProp<string | string[]>(response));
33
+ const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
34
+ const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
35
+ const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
36
+
37
+ let pairs = $state<string[]>([]);
38
+ let draggedTextId = $state<string | null>(null);
39
+ let hoveredHotspotId = $state<string | null>(null);
40
+ let keyboardSelectedTextId = $state<string | null>(null); // Gap text selected via keyboard
41
+ let announceText = $state<string>(''); // For screen reader announcements
42
+
43
+ $effect(() => {
44
+ // Sync with parent response changes
45
+ pairs = Array.isArray(parsedResponse) ? [...parsedResponse] : [];
46
+ });
47
+
48
+ // Get the hotspot matched to a gap text
49
+ function getMatchedHotspot(gapTextId: string): string | null {
50
+ const pair = pairs.find((p) => p.startsWith(`${gapTextId} `));
51
+ return pair ? pair.split(' ')[1] : null;
52
+ }
53
+
54
+ // Get the gap text matched to a hotspot
55
+ function getMatchedGapText(hotspotId: string): string | null {
56
+ const pair = pairs.find((p) => p.endsWith(` ${hotspotId}`));
57
+ return pair ? pair.split(' ')[0] : null;
58
+ }
59
+
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
+ // Get the correct gap text for a hotspot
67
+ function getCorrectGapText(hotspotId: string): string | null {
68
+ const pair = correctPairs.find((p) => p.endsWith(` ${hotspotId}`));
69
+ return pair ? pair.split(' ')[0] : null;
70
+ }
71
+
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
+ // Check if a hotspot has a correct answer
78
+ function isCorrectHotspot(hotspotId: string): boolean {
79
+ return isShowingCorrect && getCorrectGapText(hotspotId) !== null;
80
+ }
81
+
82
+ function handleDragStart(gapTextId: string) {
83
+ if (disabled) return;
84
+ draggedTextId = gapTextId;
85
+ }
86
+
87
+ function handleDragEnd() {
88
+ draggedTextId = null;
89
+ hoveredHotspotId = null;
90
+ }
91
+
92
+ function handleHotspotDragOver(event: DragEvent, hotspotId: string) {
93
+ if (disabled || !draggedTextId) return;
94
+ event.preventDefault();
95
+ hoveredHotspotId = hotspotId;
96
+ }
97
+
98
+ function handleHotspotDragLeave() {
99
+ hoveredHotspotId = null;
100
+ }
101
+
102
+ function handleHotspotDrop(event: DragEvent, hotspotId: string) {
103
+ if (disabled || !draggedTextId) return;
104
+ event.preventDefault();
105
+
106
+ // Remove any existing pair for this gapText
107
+ let newPairs = pairs.filter((p) => !p.startsWith(`${draggedTextId} `));
108
+
109
+ // Remove any existing pair for this hotspot
110
+ newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
111
+
112
+ // Add new pair
113
+ newPairs.push(`${draggedTextId} ${hotspotId}`);
114
+
115
+ pairs = newPairs;
116
+ response = pairs;
117
+ // Call onChange callback if provided (for Svelte component usage)
118
+ onChange?.(pairs);
119
+ // Dispatch custom event for web component usage
120
+ const event2 = new CustomEvent('qti-change', {
121
+ detail: {
122
+ responseId: parsedInteraction?.responseId,
123
+ value: pairs,
124
+ timestamp: Date.now(),
125
+ },
126
+ bubbles: true,
127
+ composed: true,
128
+ });
129
+ dispatchEvent(event2);
130
+
131
+ draggedTextId = null;
132
+ hoveredHotspotId = null;
133
+ }
134
+
135
+ function clearMatch(gapTextId: string) {
136
+ if (disabled || !parsedInteraction) return;
137
+ const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === gapTextId);
138
+ const gapTextName = gapTextObj?.text || 'Label';
139
+
140
+ const newPairs = pairs.filter((p) => !p.startsWith(`${gapTextId} `));
141
+ pairs = newPairs;
142
+ response = pairs;
143
+ // Call onChange callback if provided (for Svelte component usage)
144
+ onChange?.(pairs);
145
+ // Dispatch custom event for web component usage
146
+ const event = new CustomEvent('qti-change', {
147
+ detail: {
148
+ responseId: parsedInteraction?.responseId,
149
+ value: pairs,
150
+ timestamp: Date.now(),
151
+ },
152
+ bubbles: true,
153
+ composed: true,
154
+ });
155
+ dispatchEvent(event);
156
+
157
+ announceText = `${gapTextName} removed from hotspot`;
158
+ }
159
+
160
+ // Keyboard handlers for gap texts (labels)
161
+ function handleGapTextClick(gapTextId: string) {
162
+ if (disabled || !parsedInteraction) return;
163
+
164
+ const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === gapTextId);
165
+ const gapTextName = gapTextObj?.text || 'Label';
166
+
167
+ if (keyboardSelectedTextId === gapTextId) {
168
+ // Deselect
169
+ keyboardSelectedTextId = null;
170
+ announceText = `${gapTextName} deselected`;
171
+ } else {
172
+ // Select this gap text for placement
173
+ keyboardSelectedTextId = gapTextId;
174
+ announceText = `${gapTextName} selected. Navigate to a hotspot and press Space or Enter to place.`;
175
+ }
176
+ }
177
+
178
+ function handleGapTextKeyDown(event: KeyboardEvent, gapTextId: string) {
179
+ if (disabled || !parsedInteraction) return;
180
+
181
+ const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === gapTextId);
182
+ const gapTextName = gapTextObj?.text || 'Label';
183
+
184
+ if (event.key === ' ' || event.key === 'Enter') {
185
+ event.preventDefault();
186
+
187
+ if (keyboardSelectedTextId === gapTextId) {
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) {
197
+ event.preventDefault();
198
+ keyboardSelectedTextId = null;
199
+ announceText = `Selection cancelled`;
200
+ }
201
+ }
202
+
203
+ // Keyboard handlers for hotspots
204
+ function placeSelectedLabelOnHotspot(hotspotId: string) {
205
+ if (disabled || !keyboardSelectedTextId || !parsedInteraction) return;
206
+
207
+ const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspotId);
208
+ const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === keyboardSelectedTextId);
209
+ const gapTextName = gapTextObj?.text || 'Label';
210
+
211
+ // Create match
212
+ let newPairs = pairs.filter((p) => !p.startsWith(`${keyboardSelectedTextId} `));
213
+ newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
214
+ newPairs.push(`${keyboardSelectedTextId} ${hotspotId}`);
215
+
216
+ pairs = newPairs;
217
+ response = pairs;
218
+ // Call onChange callback if provided (for Svelte component usage)
219
+ onChange?.(pairs);
220
+ // Dispatch custom event for web component usage
221
+ const event2 = new CustomEvent('qti-change', {
222
+ detail: {
223
+ responseId: parsedInteraction?.responseId,
224
+ value: pairs,
225
+ timestamp: Date.now(),
226
+ },
227
+ bubbles: true,
228
+ composed: true,
229
+ });
230
+ dispatchEvent(event2);
231
+
232
+ announceText = `${gapTextName} placed on hotspot ${hotspotIndex + 1}`;
233
+ keyboardSelectedTextId = null;
234
+ }
235
+
236
+ function handleHotspotKeyDown(event: KeyboardEvent, hotspotId: string) {
237
+ if (disabled || !keyboardSelectedTextId || !parsedInteraction) return;
238
+
239
+ if (event.key === ' ' || event.key === 'Enter') {
240
+ event.preventDefault();
241
+ placeSelectedLabelOnHotspot(hotspotId);
242
+ }
243
+ }
244
+
245
+ // Parse coords based on shape
246
+ function parseCoords(hotspot: { identifier: string; shape: string; coords: string; matchMax: number }): { x: number; y: number; width: number; height: number } {
247
+ const coords = hotspot.coords.split(',').map(Number);
248
+ const shape = hotspot.shape as 'circle' | 'rect' | 'poly';
249
+ if (shape === 'circle') {
250
+ const [cx, cy, r] = coords;
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 };
255
+ }
256
+ // For poly, use bounding box (simplified)
257
+ return { x: coords[0], y: coords[1], width: 40, height: 40 };
258
+ }
259
+ </script>
260
+
261
+ <ShadowBaseStyles />
262
+
263
+ <div class="qti-graphic-gap-match-interaction">
264
+ {#if !parsedInteraction}
265
+ <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
266
+ {:else}
267
+ {#if parsedInteraction.prompt}
268
+ <p part="prompt" class="qti-ggm-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
269
+ {/if}
270
+
271
+ <!-- Screen reader announcements -->
272
+ <div aria-live="polite" aria-atomic="true" class="sr-only">
273
+ {announceText}
274
+ </div>
275
+
276
+ <!-- Instructions for keyboard users -->
277
+ <div id="graphic-gap-match-instructions" class="sr-only">
278
+ Press Space or Enter to select a label. Tab to navigate to hotspots on the image. Press Space or Enter on a hotspot to place the label. Press Escape to cancel selection.
279
+ </div>
280
+
281
+ <div
282
+ part="region"
283
+ class="qti-ggm-region space-y-4"
284
+ role="region"
285
+ aria-describedby="graphic-gap-match-instructions"
286
+ >
287
+ <!-- Draggable gap texts (labels) - Hide when showing correct answers -->
288
+ {#if !isShowingCorrect}
289
+ <div
290
+ part="labels"
291
+ class="qti-ggm-labels flex flex-wrap gap-2 p-4 bg-base-200 rounded-lg border-2 border-base-300"
292
+ role="group"
293
+ aria-label={i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'Available labels to place'}
294
+ >
295
+ <div class="qti-ggm-labels-title w-full text-sm text-base-content/70 font-semibold mb-2">
296
+ {i18n?.t('interactions.graphicGapMatch.availableHeading') ?? 'Available Labels:'}
297
+ </div>
298
+ {#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
299
+ {@const matchedHotspot = getMatchedHotspot(gapText.identifier)}
300
+ {@const isDragged = draggedTextId === gapText.identifier}
301
+ {@const isSelected = keyboardSelectedTextId === gapText.identifier}
302
+
303
+ <div class="inline-flex items-center gap-1">
304
+ <button
305
+ type="button"
306
+ draggable={!disabled && !matchedHotspot}
307
+ use:touchDrag
308
+ ondragstart={() => handleDragStart(gapText.identifier)}
309
+ ondragend={handleDragEnd}
310
+ onclick={() => handleGapTextClick(gapText.identifier)}
311
+ onkeydown={(e) => handleGapTextKeyDown(e, gapText.identifier)}
312
+ disabled={disabled || !!matchedHotspot}
313
+ aria-pressed={isSelected}
314
+ aria-label="{gapText.text}{matchedHotspot ? '. Already placed on hotspot' : ''}{isSelected ? '. Selected for placement' : '. Press Space to select'}"
315
+ class="btn btn-md font-medium transition-all"
316
+ class:btn-primary={!matchedHotspot && !isSelected}
317
+ class:btn-accent={isSelected}
318
+ class:btn-success={matchedHotspot}
319
+ class:cursor-grab={!disabled && !matchedHotspot && !isSelected}
320
+ class:cursor-not-allowed={disabled}
321
+ class:opacity-70={disabled || isDragged}
322
+ class:contrast-125={matchedHotspot}
323
+ class:saturate-150={matchedHotspot}
324
+ >
325
+ {gapText.text}
326
+ </button>
327
+ {#if matchedHotspot && !disabled}
328
+ <button
329
+ type="button"
330
+ part="label-remove"
331
+ class="btn btn-sm btn-circle btn-error"
332
+ onclick={() => clearMatch(gapText.identifier)}
333
+ aria-label="Remove {gapText.text} from hotspot"
334
+ title={i18n?.t('interactions.graphicGapMatch.removeLabel') ?? 'Remove label'}
335
+ >
336
+ ✕
337
+ </button>
338
+ {/if}
339
+ </div>
340
+ {/each}
341
+ </div>
342
+ {/if}
343
+
344
+ <!-- Image/diagram with hotspot drop zones -->
345
+ <div
346
+ part="stage"
347
+ class="qti-ggm-stage relative inline-block border-2 border-base-300 rounded-lg"
348
+ style="position: relative; display: inline-block; width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
349
+ >
350
+ <!-- SVG image -->
351
+ {#if parsedInteraction.imageData?.content}
352
+ {@html parsedInteraction.imageData.content}
353
+ {/if}
354
+
355
+ <!-- Overlay with hotspot drop zones -->
356
+ <svg
357
+ part="overlay"
358
+ class="qti-ggm-overlay absolute top-0 left-0 w-full h-full pointer-events-none"
359
+ style="position: absolute; width: 100%; height: 100%; pointer-events: none; top: 0; left: 0;"
360
+ viewBox="0 0 {parsedInteraction.imageData?.width} {parsedInteraction.imageData?.height}"
361
+ >
362
+ {#each parsedInteraction.hotspots as hotspot (hotspot.identifier)}
363
+ {@const coords = parseCoords(hotspot)}
364
+ {@const matchedGapText = getMatchedGapText(hotspot.identifier)}
365
+ {@const gapTextObj = matchedGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === matchedGapText) : null}
366
+ {@const isHovered = hoveredHotspotId === hotspot.identifier}
367
+ {@const correctGapText = getCorrectGapText(hotspot.identifier)}
368
+ {@const correctGapTextObj = correctGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === correctGapText) : null}
369
+ {@const isCorrect = isCorrectHotspot(hotspot.identifier)}
370
+
371
+ <g>
372
+ <!-- Hotspot drop zone -->
373
+ {#if hotspot.shape === 'circle'}
374
+ {@const [cx, cy, r] = hotspot.coords.split(',').map(Number)}
375
+ {@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
376
+ <circle
377
+ role="button"
378
+ tabindex={disabled || !keyboardSelectedTextId ? -1 : 0}
379
+ aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '. Available'}{keyboardSelectedTextId ? '. Press Space or Enter to place label' : ''}"
380
+ cx={cx}
381
+ cy={cy}
382
+ 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="2"
387
+ stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
388
+ class="transition-all"
389
+ style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
390
+ ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
391
+ ondragleave={handleHotspotDragLeave}
392
+ ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
393
+ onclick={() => placeSelectedLabelOnHotspot(hotspot.identifier)}
394
+ onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
395
+ />
396
+ {:else if hotspot.shape === 'rect'}
397
+ {@const [x, y, width, height] = hotspot.coords.split(',').map(Number)}
398
+ {@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
399
+ <rect
400
+ role="button"
401
+ tabindex={disabled || !keyboardSelectedTextId ? -1 : 0}
402
+ aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : correctGapTextObj ? '. Correct answer: ' + correctGapTextObj.text : '. Available'}{keyboardSelectedTextId ? '. Press Space or Enter to place label' : ''}"
403
+ x={x}
404
+ y={y}
405
+ width={width}
406
+ 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="2"
411
+ stroke-dasharray={matchedGapText || isCorrect ? '' : '4,4'}
412
+ class="transition-all"
413
+ style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
414
+ ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
415
+ ondragleave={handleHotspotDragLeave}
416
+ ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
417
+ onclick={() => placeSelectedLabelOnHotspot(hotspot.identifier)}
418
+ onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
419
+ />
420
+ {/if}
421
+
422
+ <!-- Label text on hotspot if matched or correct -->
423
+ {#if matchedGapText && gapTextObj}
424
+ {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
425
+ <text
426
+ x={cx}
427
+ y={cy}
428
+ text-anchor="middle"
429
+ dominant-baseline="middle"
430
+ class="font-bold pointer-events-none"
431
+ fill="#059669"
432
+ font-size="14"
433
+ >
434
+ {gapTextObj.text}
435
+ </text>
436
+ {:else if isCorrect && correctGapTextObj}
437
+ {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
438
+ <text
439
+ x={cx}
440
+ y={cy}
441
+ text-anchor="middle"
442
+ dominant-baseline="middle"
443
+ class="font-bold pointer-events-none"
444
+ fill="#10b981"
445
+ font-size="14"
446
+ >
447
+ {correctGapTextObj.text}
448
+ </text>
449
+ {/if}
450
+ </g>
451
+ {/each}
452
+ </svg>
453
+ </div>
454
+ </div>
455
+ {/if}
456
+ </div>
457
+
458
+ <style>
459
+ [draggable='true'] {
460
+ touch-action: none;
461
+ }
462
+
463
+ /* Minimal layout so this works without Tailwind utilities */
464
+ .qti-graphic-gap-match-interaction {
465
+ display: grid;
466
+ gap: 0.75rem;
467
+ }
468
+ .qti-ggm-prompt {
469
+ margin: 0 0 0.75rem;
470
+ }
471
+ .qti-ggm-region {
472
+ display: grid;
473
+ gap: 1rem;
474
+ }
475
+ .qti-ggm-labels {
476
+ display: flex;
477
+ flex-wrap: wrap;
478
+ gap: 0.5rem;
479
+ padding: 1rem;
480
+ border-radius: 0.75rem;
481
+ border: 2px solid var(--color-base-300, oklch(95% 0 0));
482
+ background: var(--color-base-200, oklch(98% 0 0));
483
+ }
484
+ .qti-ggm-labels-title {
485
+ width: 100%;
486
+ margin: 0 0 0.5rem;
487
+ font-weight: 600;
488
+ }
489
+ .qti-ggm-stage {
490
+ position: relative;
491
+ display: inline-block;
492
+ border-radius: 0.75rem;
493
+ overflow: hidden;
494
+ border: 2px solid var(--color-base-300, oklch(95% 0 0));
495
+ }
496
+ .qti-ggm-overlay {
497
+ position: absolute;
498
+ inset: 0;
499
+ }
500
+
501
+ /* Ensure SVG fills its container */
502
+ svg {
503
+ width: 100%;
504
+ height: 100%;
505
+ display: block;
506
+ }
507
+
508
+ </style>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'graphicGapMatchInteraction',
5
+ tagName: 'pie-qti-graphic-gap-match',
6
+ name: 'default-graphic-gap-match',
7
+ description: 'Default Svelte-based graphic gap match interaction',
8
+ priority: 0,
9
+ };