@pie-qti/default-components 0.1.10 → 0.1.12

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 (180) hide show
  1. package/dist/chunks/__vite-browser-external-Dz5RCjpq.js +9 -0
  2. package/dist/chunks/__vite-browser-external-Dz5RCjpq.js.map +1 -0
  3. package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-ClqhKA_b.js} +4199 -3978
  4. package/dist/chunks/mathlive.min-ClqhKA_b.js.map +1 -0
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/plugins/associate/index.d.ts +0 -1
  9. package/dist/plugins/associate/index.js +1 -0
  10. package/dist/plugins/associate/index.js.map +1 -0
  11. package/dist/plugins/choice/index.d.ts +0 -1
  12. package/dist/plugins/choice/index.js +1 -0
  13. package/dist/plugins/choice/index.js.map +1 -0
  14. package/dist/plugins/custom/index.d.ts +0 -1
  15. package/dist/plugins/custom/index.js +1 -0
  16. package/dist/plugins/custom/index.js.map +1 -0
  17. package/dist/plugins/end-attempt/index.d.ts +0 -1
  18. package/dist/plugins/end-attempt/index.js +1 -0
  19. package/dist/plugins/end-attempt/index.js.map +1 -0
  20. package/dist/plugins/extended-text/index.d.ts +0 -1
  21. package/dist/plugins/extended-text/index.js +1 -0
  22. package/dist/plugins/extended-text/index.js.map +1 -0
  23. package/dist/plugins/gap-match/index.d.ts +0 -1
  24. package/dist/plugins/gap-match/index.js +1 -0
  25. package/dist/plugins/gap-match/index.js.map +1 -0
  26. package/dist/plugins/graphic-associate/index.d.ts +0 -1
  27. package/dist/plugins/graphic-associate/index.js +1 -0
  28. package/dist/plugins/graphic-associate/index.js.map +1 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
  30. package/dist/plugins/graphic-gap-match/index.js +1 -0
  31. package/dist/plugins/graphic-gap-match/index.js.map +1 -0
  32. package/dist/plugins/graphic-order/index.d.ts +0 -1
  33. package/dist/plugins/graphic-order/index.js +1 -0
  34. package/dist/plugins/graphic-order/index.js.map +1 -0
  35. package/dist/plugins/hotspot/index.d.ts +0 -1
  36. package/dist/plugins/hotspot/index.js +1 -0
  37. package/dist/plugins/hotspot/index.js.map +1 -0
  38. package/dist/plugins/hottext/index.d.ts +0 -1
  39. package/dist/plugins/hottext/index.js +1 -0
  40. package/dist/plugins/hottext/index.js.map +1 -0
  41. package/dist/plugins/match/index.d.ts +0 -1
  42. package/dist/plugins/match/index.js +1 -0
  43. package/dist/plugins/match/index.js.map +1 -0
  44. package/dist/plugins/media/index.d.ts +0 -1
  45. package/dist/plugins/media/index.js +1 -0
  46. package/dist/plugins/media/index.js.map +1 -0
  47. package/dist/plugins/order/index.d.ts +0 -1
  48. package/dist/plugins/order/index.js +1 -0
  49. package/dist/plugins/order/index.js.map +1 -0
  50. package/dist/plugins/position-object/index.d.ts +0 -1
  51. package/dist/plugins/position-object/index.js +1 -0
  52. package/dist/plugins/position-object/index.js.map +1 -0
  53. package/dist/plugins/public-types.d.ts +5 -0
  54. package/dist/plugins/public-types.js +2 -0
  55. package/dist/plugins/public-types.js.map +1 -0
  56. package/dist/plugins/select-point/index.d.ts +0 -1
  57. package/dist/plugins/select-point/index.js +1 -0
  58. package/dist/plugins/select-point/index.js.map +1 -0
  59. package/dist/plugins/slider/index.d.ts +0 -1
  60. package/dist/plugins/slider/index.js +1 -0
  61. package/dist/plugins/slider/index.js.map +1 -0
  62. package/dist/plugins.js +27589 -9160
  63. package/dist/plugins.js.map +1 -1
  64. package/dist/shared/actions/typesetAction.d.ts +0 -1
  65. package/dist/shared/actions/typesetAction.js +1 -0
  66. package/dist/shared/actions/typesetAction.js.map +1 -0
  67. package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
  68. package/dist/shared/extensions/MathLiveEditor.js +1 -0
  69. package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
  70. package/dist/shared/index.d.ts +0 -1
  71. package/dist/shared/index.js +1 -0
  72. package/dist/shared/index.js.map +1 -0
  73. package/dist/shared/utils/eventHelpers.d.ts +0 -1
  74. package/dist/shared/utils/eventHelpers.js +1 -0
  75. package/dist/shared/utils/eventHelpers.js.map +1 -0
  76. package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
  77. package/dist/shared/utils/matchGroupUtils.js +1 -0
  78. package/dist/shared/utils/matchGroupUtils.js.map +1 -0
  79. package/dist/shared/utils/pairHelpers.d.ts +0 -1
  80. package/dist/shared/utils/pairHelpers.js +1 -0
  81. package/dist/shared/utils/pairHelpers.js.map +1 -0
  82. package/dist/shared/utils/webComponentHelpers.d.ts +0 -1
  83. package/dist/shared/utils/webComponentHelpers.js +1 -0
  84. package/dist/shared/utils/webComponentHelpers.js.map +1 -0
  85. package/package.json +15 -33
  86. package/dist/chunks/mathlive.min-Bvtiaxg4.js.map +0 -1
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/plugins/associate/index.d.ts.map +0 -1
  89. package/dist/plugins/choice/index.d.ts.map +0 -1
  90. package/dist/plugins/custom/index.d.ts.map +0 -1
  91. package/dist/plugins/end-attempt/index.d.ts.map +0 -1
  92. package/dist/plugins/extended-text/index.d.ts.map +0 -1
  93. package/dist/plugins/gap-match/index.d.ts.map +0 -1
  94. package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
  95. package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
  96. package/dist/plugins/graphic-order/index.d.ts.map +0 -1
  97. package/dist/plugins/hotspot/index.d.ts.map +0 -1
  98. package/dist/plugins/hottext/index.d.ts.map +0 -1
  99. package/dist/plugins/index.d.ts +0 -31
  100. package/dist/plugins/index.d.ts.map +0 -1
  101. package/dist/plugins/index.js +0 -31
  102. package/dist/plugins/match/index.d.ts.map +0 -1
  103. package/dist/plugins/media/index.d.ts.map +0 -1
  104. package/dist/plugins/order/index.d.ts.map +0 -1
  105. package/dist/plugins/position-object/index.d.ts.map +0 -1
  106. package/dist/plugins/select-point/index.d.ts.map +0 -1
  107. package/dist/plugins/slider/index.d.ts.map +0 -1
  108. package/dist/shared/actions/typesetAction.d.ts.map +0 -1
  109. package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
  110. package/dist/shared/index.d.ts.map +0 -1
  111. package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
  112. package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
  113. package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
  114. package/dist/shared/utils/touchDragHelper.d.ts +0 -2
  115. package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
  116. package/dist/shared/utils/touchDragHelper.js +0 -1
  117. package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
  118. package/src/catalog/CatalogPopup.svelte +0 -163
  119. package/src/index.ts +0 -141
  120. package/src/plugins/associate/AssociateInteraction.svelte +0 -304
  121. package/src/plugins/associate/index.ts +0 -9
  122. package/src/plugins/choice/ChoiceInteraction.svelte +0 -355
  123. package/src/plugins/choice/index.ts +0 -9
  124. package/src/plugins/custom/CustomInteraction.svelte +0 -61
  125. package/src/plugins/custom/index.ts +0 -9
  126. package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
  127. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
  128. package/src/plugins/end-attempt/index.ts +0 -9
  129. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -152
  130. package/src/plugins/extended-text/index.ts +0 -9
  131. package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
  132. package/src/plugins/gap-match/index.ts +0 -9
  133. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
  134. package/src/plugins/graphic-associate/index.ts +0 -9
  135. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
  136. package/src/plugins/graphic-gap-match/index.ts +0 -9
  137. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
  138. package/src/plugins/graphic-order/index.ts +0 -9
  139. package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
  140. package/src/plugins/hotspot/index.ts +0 -9
  141. package/src/plugins/hottext/HottextInteraction.svelte +0 -325
  142. package/src/plugins/hottext/index.ts +0 -9
  143. package/src/plugins/index.ts +0 -32
  144. package/src/plugins/match/MatchInteraction.svelte +0 -82
  145. package/src/plugins/match/index.ts +0 -9
  146. package/src/plugins/media/MediaInteraction.svelte +0 -216
  147. package/src/plugins/media/index.ts +0 -9
  148. package/src/plugins/order/OrderInteraction.svelte +0 -280
  149. package/src/plugins/order/index.ts +0 -9
  150. package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
  151. package/src/plugins/position-object/README.md +0 -130
  152. package/src/plugins/position-object/index.ts +0 -9
  153. package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
  154. package/src/plugins/select-point/index.ts +0 -9
  155. package/src/plugins/slider/SliderInteraction.svelte +0 -141
  156. package/src/plugins/slider/index.ts +0 -9
  157. package/src/plugins/upload/UploadInteraction.svelte +0 -59
  158. package/src/shared/actions/typesetAction.ts +0 -87
  159. package/src/shared/components/CustomInteractionFallback.svelte +0 -153
  160. package/src/shared/components/DragHandle.svelte +0 -44
  161. package/src/shared/components/DrawingCanvas.svelte +0 -259
  162. package/src/shared/components/FileUpload.svelte +0 -158
  163. package/src/shared/components/GraphicGapMatch.svelte +0 -318
  164. package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
  165. package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
  166. package/src/shared/components/MatchDragDrop.svelte +0 -481
  167. package/src/shared/components/MathContent.svelte +0 -18
  168. package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
  169. package/src/shared/components/RichTextEditor.svelte +0 -316
  170. package/src/shared/components/ShadowBaseStyles.svelte +0 -390
  171. package/src/shared/components/SortableList.svelte +0 -297
  172. package/src/shared/extensions/MathLiveEditor.ts +0 -299
  173. package/src/shared/index.ts +0 -15
  174. package/src/shared/styles/shared.css +0 -16
  175. package/src/shared/utils/eventHelpers.ts +0 -69
  176. package/src/shared/utils/matchGroupUtils.ts +0 -14
  177. package/src/shared/utils/pairHelpers.ts +0 -109
  178. package/src/shared/utils/webComponentHelpers.ts +0 -69
  179. package/src/svelte-shims.d.ts +0 -9
  180. /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
@@ -1,593 +0,0 @@
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 (two-phase pick-up/drop), 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 { touchDrag } from '@pie-qti/qti-common';
13
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers.js';
14
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
15
-
16
- import '../../shared/styles/shared.css';
17
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
18
-
19
- interface Props {
20
- interaction?: GraphicGapMatchInteractionData | string;
21
- response?: string | string[] | null;
22
- correctResponse?: string[] | null;
23
- disabled?: boolean;
24
- role?: string;
25
- i18n?: I18nProvider;
26
- onChange?: (value: string[]) => void;
27
- }
28
-
29
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
30
-
31
- // Parse props that may be JSON strings (web component usage)
32
- const parsedInteraction = $derived(parseJsonProp<GraphicGapMatchInteractionData>(interaction));
33
- const parsedResponse = $derived(parseJsonProp<string | string[]>(response));
34
- const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
35
- const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
36
- const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
37
-
38
- let pairs = $state<string[]>([]);
39
- let draggedTextId = $state<string | null>(null);
40
- let hoveredHotspotId = $state<string | null>(null);
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
- });
74
-
75
- $effect(() => {
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
82
- });
83
-
84
- // Get the hotspot matched to a gap text
85
- function getMatchedHotspot(gapTextId: string): string | null {
86
- const pair = pairs.find((p) => p.startsWith(`${gapTextId} `));
87
- return pair ? pair.split(' ')[1] : null;
88
- }
89
-
90
- // Get the gap text matched to a hotspot
91
- function getMatchedGapText(hotspotId: string): string | null {
92
- const pair = pairs.find((p) => p.endsWith(` ${hotspotId}`));
93
- return pair ? pair.split(' ')[0] : null;
94
- }
95
-
96
- // Get the correct gap text for a hotspot
97
- function getCorrectGapText(hotspotId: string): string | null {
98
- const pair = correctPairs.find((p) => p.endsWith(` ${hotspotId}`));
99
- return pair ? pair.split(' ')[0] : null;
100
- }
101
-
102
- // Check if a hotspot has a correct answer
103
- function isCorrectHotspot(hotspotId: string): boolean {
104
- return isShowingCorrect && getCorrectGapText(hotspotId) !== null;
105
- }
106
-
107
- function handleDragStart(gapTextId: string) {
108
- if (disabled) return;
109
- draggedTextId = gapTextId;
110
- }
111
-
112
- function handleDragEnd() {
113
- draggedTextId = null;
114
- hoveredHotspotId = null;
115
- }
116
-
117
- function handleHotspotDragOver(event: DragEvent, hotspotId: string) {
118
- if (disabled || !draggedTextId) return;
119
- event.preventDefault();
120
- hoveredHotspotId = hotspotId;
121
- }
122
-
123
- function handleHotspotDragLeave() {
124
- hoveredHotspotId = null;
125
- }
126
-
127
- function handleHotspotDrop(event: DragEvent, hotspotId: string) {
128
- if (disabled || !draggedTextId || !parsedInteraction) return;
129
- event.preventDefault();
130
-
131
- // Remove any existing pair for this gapText
132
- let newPairs = pairs.filter((p) => !p.startsWith(`${draggedTextId} `));
133
-
134
- // Remove any existing pair for this hotspot
135
- newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
136
-
137
- // Add new pair
138
- newPairs.push(`${draggedTextId} ${hotspotId}`);
139
-
140
- isInternalUpdate = true; // Mark as internal update to prevent sync effect from overwriting
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 - 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
- }
150
-
151
- draggedTextId = null;
152
- hoveredHotspotId = null;
153
- }
154
-
155
- function clearMatch(gapTextId: string) {
156
- if (disabled || !parsedInteraction) return;
157
- const gapTextObj = parsedInteraction.gapTexts.find((g) => g.identifier === gapTextId);
158
- const gapTextName = gapTextObj?.text || 'Label';
159
-
160
- const newPairs = pairs.filter((p) => !p.startsWith(`${gapTextId} `));
161
- isInternalUpdate = true; // Mark as internal update
162
- pairs = newPairs;
163
- response = pairs;
164
- // Call onChange callback if provided (for Svelte component usage)
165
- onChange?.(pairs);
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`;
173
- }
174
-
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
- }
187
-
188
- // Phase-1 handler: pick up or put down a label from the palette.
189
- function handleLabelActivate(labelId: string) {
190
- if (disabled) return;
191
-
192
- if (pickedUpLabel === labelId) {
193
- // Second press on the same label cancels the pick-up
194
- pickedUpLabel = null;
195
- liveMessage = 'Cancelled.';
196
- } else {
197
- pickedUpLabel = labelId;
198
- const name = getLabelName(labelId);
199
- liveMessage = `Picked up: ${name}. Tab to a hotspot and press Enter to place it.`;
200
- }
201
- }
202
-
203
- function handleLabelKeyDown(event: KeyboardEvent, labelId: string) {
204
- if (disabled) return;
205
-
206
- if (event.key === ' ' || event.key === 'Enter') {
207
- event.preventDefault();
208
- handleLabelActivate(labelId);
209
- } else if (event.key === 'Escape' && pickedUpLabel) {
210
- event.preventDefault();
211
- pickedUpLabel = null;
212
- liveMessage = 'Cancelled.';
213
- }
214
- }
215
-
216
- // Phase-2 handler: drop the held label onto a hotspot.
217
- function placePickedUpLabelOnHotspot(hotspotId: string) {
218
- if (disabled || !pickedUpLabel || !parsedInteraction) return;
219
-
220
- const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspotId);
221
- const labelName = getLabelName(pickedUpLabel);
222
-
223
- // Create match
224
- let newPairs = pairs.filter((p) => !p.startsWith(`${pickedUpLabel} `));
225
- newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
226
- newPairs.push(`${pickedUpLabel} ${hotspotId}`);
227
-
228
- isInternalUpdate = true; // Mark as internal update
229
- pairs = newPairs;
230
- response = pairs;
231
- // Call onChange callback if provided (for Svelte component usage)
232
- onChange?.(pairs);
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;
241
- }
242
-
243
- function handleHotspotKeyDown(event: KeyboardEvent, hotspotId: string) {
244
- if (disabled || !parsedInteraction) return;
245
-
246
- if (event.key === ' ' || event.key === 'Enter') {
247
- if (pickedUpLabel) {
248
- event.preventDefault();
249
- placePickedUpLabelOnHotspot(hotspotId);
250
- }
251
- }
252
- }
253
-
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.';
260
- }
261
- }
262
-
263
- </script>
264
-
265
- <ShadowBaseStyles />
266
-
267
- <!-- svelte-ignore a11y_no_static_element_interactions -->
268
- <div bind:this={rootElement} class={['qti-graphic-gap-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} onkeydown={handleRootKeyDown}>
269
- {#if !parsedInteraction}
270
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
271
- {:else}
272
- {#if parsedInteraction.prompt}
273
- <p part="prompt" class="qti-ggm-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
274
- {/if}
275
-
276
- <!-- Visually-hidden live region for screen reader announcements -->
277
- <div aria-live="polite" aria-atomic="true" class="sr-only">
278
- {liveMessage}
279
- </div>
280
-
281
- <!-- Instructions for keyboard users -->
282
- <div id="graphic-gap-match-instructions" class="sr-only">
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.
284
- </div>
285
-
286
- <div
287
- part="region"
288
- class="qti-ggm-region space-y-4"
289
- role="region"
290
- aria-describedby="graphic-gap-match-instructions"
291
- >
292
- <!-- Draggable gap texts (labels) - Hide when showing correct answers -->
293
- {#if !isShowingCorrect}
294
- <div
295
- part="labels"
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}
298
- role="group"
299
- aria-label={i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'Available labels to place'}
300
- >
301
- <div class="qti-ggm-labels-title w-full text-sm text-base-content/70 font-semibold mb-2">
302
- {i18n?.t('interactions.graphicGapMatch.availableHeading') ?? 'Available Labels:'}
303
- </div>
304
- {#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
305
- {@const matchedHotspot = getMatchedHotspot(gapText.identifier)}
306
- {@const isDragged = draggedTextId === gapText.identifier}
307
- {@const isHeld = pickedUpLabel === gapText.identifier}
308
- {@const isUnavailable = unavailableLabels.has(gapText.identifier)}
309
-
310
- <div class="inline-flex items-center gap-1">
311
- <button
312
- type="button"
313
- draggable={!disabled && !matchedHotspot && !isUnavailable}
314
- use:touchDrag
315
- ondragstart={() => handleDragStart(gapText.identifier)}
316
- ondragend={handleDragEnd}
317
- onclick={() => handleLabelActivate(gapText.identifier)}
318
- onkeydown={(e) => handleLabelKeyDown(e, gapText.identifier)}
319
- disabled={disabled || !!matchedHotspot}
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'}"
323
- class="btn btn-md font-medium transition-all"
324
- class:btn-primary={!matchedHotspot && !isHeld}
325
- class:qti-ggm-label-held={isHeld}
326
- class:btn-success={matchedHotspot}
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)}
331
- class:contrast-125={matchedHotspot}
332
- class:saturate-150={matchedHotspot}
333
- >
334
- {gapText.text}
335
- </button>
336
- {#if matchedHotspot && !disabled}
337
- <button
338
- type="button"
339
- part="label-remove"
340
- class="btn btn-sm btn-circle btn-error"
341
- onclick={() => clearMatch(gapText.identifier)}
342
- aria-label="Remove {gapText.text} from hotspot"
343
- title={i18n?.t('interactions.graphicGapMatch.removeLabel') ?? 'Remove label'}
344
- >
345
- ✕
346
- </button>
347
- {/if}
348
- </div>
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}
399
- </div>
400
- {/if}
401
-
402
- <!-- Image/diagram with hotspot drop zones -->
403
- <div
404
- part="stage"
405
- class="qti-ggm-stage relative inline-block border-2 border-base-300 rounded-lg"
406
- style="position: relative; display: inline-block; width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
407
- >
408
- <!-- SVG image or raster image -->
409
- {#if parsedInteraction.imageData?.content}
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
- />
417
- {/if}
418
-
419
- <!-- Overlay with hotspot drop zones -->
420
- <svg
421
- part="overlay"
422
- class="qti-ggm-overlay absolute top-0 left-0 w-full h-full pointer-events-none"
423
- style="position: absolute; width: 100%; height: 100%; pointer-events: none; top: 0; left: 0;"
424
- viewBox="0 0 {parsedInteraction.imageData?.width} {parsedInteraction.imageData?.height}"
425
- >
426
- {#each parsedInteraction.hotspots as hotspot (hotspot.identifier)}
427
- {@const matchedGapText = getMatchedGapText(hotspot.identifier)}
428
- {@const gapTextObj = matchedGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === matchedGapText) : null}
429
- {@const isHovered = hoveredHotspotId === hotspot.identifier}
430
- {@const correctGapText = getCorrectGapText(hotspot.identifier)}
431
- {@const correctGapTextObj = correctGapText ? parsedInteraction.gapTexts.find((g) => g.identifier === correctGapText) : null}
432
- {@const isCorrect = isCorrectHotspot(hotspot.identifier)}
433
- {@const hotspotReady = !!pickedUpLabel && !disabled}
434
- {@const pickedUpLabelName = pickedUpLabel ? getLabelName(pickedUpLabel) : ''}
435
-
436
- <g>
437
- <!-- Hotspot drop zone -->
438
- {#if hotspot.shape === 'circle'}
439
- {@const [cx, cy, r] = hotspot.coords.split(',').map(Number)}
440
- {@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
441
- <circle
442
- role="button"
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' : ''}"
445
- cx={cx}
446
- cy={cy}
447
- r={r}
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'};"
455
- ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
456
- ondragleave={handleHotspotDragLeave}
457
- ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
458
- onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
459
- onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
460
- />
461
- {:else if hotspot.shape === 'rect'}
462
- {@const [x, y, right, bottom] = hotspot.coords.split(',').map(Number)}
463
- {@const width = right - x}
464
- {@const height = bottom - y}
465
- {@const hotspotIndex = parsedInteraction.hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
466
- <rect
467
- role="button"
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' : ''}"
470
- x={x}
471
- y={y}
472
- width={width}
473
- height={height}
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'};"
481
- ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
482
- ondragleave={handleHotspotDragLeave}
483
- ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
484
- onclick={() => placePickedUpLabelOnHotspot(hotspot.identifier)}
485
- onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
486
- />
487
- {/if}
488
-
489
- <!-- Label text on hotspot if matched or correct -->
490
- {#if matchedGapText && gapTextObj}
491
- {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
492
- <text
493
- x={cx}
494
- y={cy}
495
- text-anchor="middle"
496
- dominant-baseline="middle"
497
- class="font-bold pointer-events-none"
498
- fill="#059669"
499
- font-size="14"
500
- >
501
- {gapTextObj.text}
502
- </text>
503
- {:else if isCorrect && correctGapTextObj}
504
- {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
505
- <text
506
- x={cx}
507
- y={cy}
508
- text-anchor="middle"
509
- dominant-baseline="middle"
510
- class="font-bold pointer-events-none"
511
- fill="#10b981"
512
- font-size="14"
513
- >
514
- {correctGapTextObj.text}
515
- </text>
516
- {/if}
517
- </g>
518
- {/each}
519
- </svg>
520
- </div>
521
- </div>
522
- {/if}
523
- </div>
524
-
525
- <style>
526
- [draggable='true'] {
527
- touch-action: none;
528
- }
529
-
530
- /* Minimal layout so this works without Tailwind utilities */
531
- .qti-graphic-gap-match-interaction {
532
- display: grid;
533
- gap: 0.75rem;
534
- }
535
- .qti-ggm-prompt {
536
- margin: 0 0 0.75rem;
537
- }
538
- .qti-ggm-region {
539
- display: grid;
540
- gap: 1rem;
541
- }
542
- .qti-ggm-labels {
543
- display: flex;
544
- flex-wrap: wrap;
545
- gap: 0.5rem;
546
- padding: 1rem;
547
- border-radius: 0.75rem;
548
- border: 2px solid var(--color-base-300, oklch(95% 0 0));
549
- background: var(--color-base-200, oklch(98% 0 0));
550
- }
551
- .qti-ggm-labels-title {
552
- width: 100%;
553
- margin: 0 0 0.5rem;
554
- font-weight: 600;
555
- }
556
- .qti-ggm-stage {
557
- position: relative;
558
- display: inline-block;
559
- border-radius: 0.75rem;
560
- overflow: hidden;
561
- border: 2px solid var(--color-base-300, oklch(95% 0 0));
562
- }
563
- .qti-ggm-overlay {
564
- position: absolute;
565
- inset: 0;
566
- }
567
-
568
- /* Ensure SVG fills its container */
569
- svg {
570
- width: 100%;
571
- height: 100%;
572
- display: block;
573
- }
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
- }
593
- </style>
@@ -1,9 +0,0 @@
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
- };