@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,556 +0,0 @@
1
- <svelte:options customElement="pie-qti-gap-match" />
2
-
3
- <script lang="ts">
4
- import type { GapMatchInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
8
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
- import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
10
-
11
- interface Props {
12
- interaction?: GapMatchInteractionData | string;
13
- response?: string[];
14
- correctResponse?: string[] | null;
15
- disabled?: boolean;
16
- role?: string;
17
- i18n?: I18nProvider;
18
- onChange?: (value: string[]) => void;
19
- }
20
-
21
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
22
-
23
- // Parse props that may be JSON strings (web component usage)
24
- const parsedInteraction = $derived(parseJsonProp<GapMatchInteractionData>(interaction));
25
- const parsedResponse = $derived(parseJsonProp<string[]>(response));
26
- const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
27
- const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
28
-
29
- const pairs = $derived(Array.isArray(parsedResponse) ? parsedResponse : []);
30
- const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
31
-
32
- // K-02: identifier of the word currently "held" in the keyboard pick-up flow
33
- let pickedUpWord: string | null = $state(null);
34
-
35
- // K-02: live region message for screen reader announcements
36
- let liveMessage: string = $state('');
37
-
38
- // Get reference to the root element for event dispatching
39
- let rootElement: HTMLDivElement | undefined = $state();
40
-
41
- // Rendered prompt container - we keep the original HTML structure and insert live gap targets.
42
- let promptContainer: HTMLDivElement | undefined = $state();
43
-
44
- // Track cleanup functions for event listeners to prevent memory leaks
45
- let cleanupFunctions: (() => void)[] = [];
46
-
47
- // Words that cannot be placed because they share a matchGroup with an already-placed word
48
- const unavailableWords = $derived.by(() => {
49
- if (!parsedInteraction) return new Set<string>();
50
- const placedGroups = new Set<string>();
51
- for (const pair of pairs) {
52
- const wordId = pair.split(' ')[0];
53
- const gt = parsedInteraction.gapTexts.find((g) => g.identifier === wordId);
54
- gt?.matchGroup?.forEach((g) => placedGroups.add(g));
55
- }
56
- return new Set(
57
- parsedInteraction.gapTexts
58
- .filter((gt) => {
59
- const isPlaced = pairs.some((p) => p.startsWith(`${gt.identifier} `));
60
- if (isPlaced) return false;
61
- return gt.matchGroup?.some((g) => placedGroups.has(g)) ?? false;
62
- })
63
- .map((gt) => gt.identifier)
64
- );
65
- });
66
-
67
- function getMatchMax(wordId: string): number {
68
- const gt = parsedInteraction?.gapTexts?.find((g) => g.identifier === wordId);
69
- return gt?.matchMax ?? 1;
70
- }
71
-
72
- function handleGapChange(gapId: string, wordId: string) {
73
- // Remove any existing pair for this gap (each gap holds one word)
74
- let newPairs = pairs.filter((p: string) => !p.endsWith(` ${gapId}`));
75
-
76
- // For reusable words (matchMax=0 or >1): don't remove other placements. For matchMax=1: move the word.
77
- const matchMax = getMatchMax(wordId);
78
- const currentCount = newPairs.filter((p: string) => p.startsWith(`${wordId} `)).length;
79
- if (matchMax === 1 || (matchMax > 0 && currentCount >= matchMax)) {
80
- // Single-use or at limit: remove this word from other gaps (move)
81
- newPairs = newPairs.filter((p: string) => !p.startsWith(`${wordId} `));
82
- }
83
-
84
- // Add new pair if a word was selected
85
- if (wordId) {
86
- const newPair = `${wordId} ${gapId}`;
87
- if (!newPairs.includes(newPair)) {
88
- newPairs.push(newPair);
89
- }
90
- }
91
-
92
- response = newPairs;
93
- // Call onChange callback if provided (for Svelte component usage)
94
- onChange?.(newPairs);
95
- // Dispatch event for web component usage - event will bubble up to the host element
96
- if (rootElement) {
97
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
98
- }
99
- }
100
-
101
- function isWordUsed(wordId: string): boolean {
102
- const matchMax = getMatchMax(wordId);
103
- const count = pairs.filter((p: string) => p.startsWith(`${wordId} `)).length;
104
- return matchMax > 0 ? count >= matchMax : false; // matchMax=0 means unlimited, never "used"
105
- }
106
-
107
- function getSelectedWord(gapId: string): string {
108
- const pair = pairs.find((p: string) => p.endsWith(` ${gapId}`));
109
- return pair ? pair.split(' ')[0] : '';
110
- }
111
-
112
- function getCorrectWord(gapId: string): string {
113
- const pair = correctPairs.find((p: string) => p.endsWith(` ${gapId}`));
114
- return pair ? pair.split(' ')[0] : '';
115
- }
116
-
117
- function isCorrectGap(gapId: string): boolean {
118
- return isShowingCorrect && getCorrectWord(gapId) !== '';
119
- }
120
-
121
- function getWordText(wordId: string): string {
122
- const w = parsedInteraction?.gapTexts?.find((gt) => gt.identifier === wordId);
123
- return w?.text ?? wordId;
124
- }
125
-
126
- function onWordDragStart(e: DragEvent, wordId: string) {
127
- if (disabled) return;
128
- if (!e.dataTransfer) return;
129
- e.dataTransfer.setData('text/plain', wordId);
130
- e.dataTransfer.effectAllowed = 'move';
131
- }
132
-
133
- // K-02: handle keyboard pick-up on a word button
134
- function onWordKeydown(e: KeyboardEvent, wordId: string) {
135
- if (disabled) return;
136
- if (e.key === 'Enter' || e.key === ' ') {
137
- e.preventDefault();
138
- if (pickedUpWord === wordId) {
139
- // Toggle off — pressing the already-held word cancels the pick-up
140
- pickedUpWord = null;
141
- liveMessage = i18n?.t('interactions.gapMatch.pickUpCancelled') ?? 'Pick-up cancelled.';
142
- } else {
143
- // Pick up this word (replaces any previously held word)
144
- pickedUpWord = wordId;
145
- const wordText = getWordText(wordId);
146
- liveMessage =
147
- i18n?.t('interactions.gapMatch.pickedUp', { word: wordText }) ??
148
- `Picked up: ${wordText}. Tab to a blank and press Enter to place it. Press Escape to cancel.`;
149
- }
150
- } else if (e.key === 'Escape') {
151
- if (pickedUpWord !== null) {
152
- pickedUpWord = null;
153
- liveMessage = i18n?.t('interactions.gapMatch.pickUpCancelled') ?? 'Pick-up cancelled.';
154
- }
155
- }
156
- }
157
-
158
- // K-02: global Escape handler to cancel pick-up from anywhere in the component
159
- function onRootKeydown(e: KeyboardEvent) {
160
- if (e.key === 'Escape' && pickedUpWord !== null) {
161
- pickedUpWord = null;
162
- liveMessage = i18n?.t('interactions.gapMatch.pickUpCancelled') ?? 'Pick-up cancelled.';
163
- }
164
- }
165
-
166
- function clearWord(wordId: string) {
167
- if (disabled) return;
168
- const newPairs = pairs.filter((p: string) => !p.startsWith(`${wordId} `));
169
- response = newPairs;
170
- // Call onChange callback if provided (for Svelte component usage)
171
- onChange?.(newPairs);
172
- // Dispatch event for web component usage - event will bubble up to the host element
173
- if (rootElement) {
174
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
175
- }
176
- }
177
-
178
- function renderPromptWithGaps() {
179
- if (!promptContainer || !parsedInteraction?.promptText) return;
180
-
181
- // Clean up any existing event listeners before creating new ones
182
- cleanupFunctions.forEach(cleanup => cleanup());
183
- cleanupFunctions = [];
184
-
185
- // Replace placeholders with marker spans so we can keep the original HTML structure.
186
- const html = parsedInteraction.promptText.replace(/\[GAP:([^\]]+)\]/g, (_m, gapId) => {
187
- const safe = String(gapId).replace(/"/g, '&quot;');
188
- return `<span data-gap-placeholder="${safe}"></span>`;
189
- });
190
-
191
- const tpl = document.createElement('template');
192
- tpl.innerHTML = html;
193
- promptContainer.innerHTML = '';
194
- promptContainer.appendChild(tpl.content.cloneNode(true));
195
-
196
- const placeholders = Array.from(
197
- promptContainer.querySelectorAll<HTMLSpanElement>('[data-gap-placeholder]')
198
- );
199
- for (const ph of placeholders) {
200
- const gapId = ph.getAttribute('data-gap-placeholder') ?? '';
201
- if (!gapId) continue;
202
-
203
- const btn = document.createElement('button');
204
- btn.type = 'button';
205
- btn.setAttribute('part', 'gap');
206
- btn.setAttribute('data-gap-id', gapId);
207
- // Match the look/feel of other interactions (DaisyUI input/select styling when present).
208
- btn.className = 'qti-gm-gap-target select select-bordered select-sm';
209
-
210
- const selected = getSelectedWord(gapId);
211
- const correct = getCorrectWord(gapId);
212
- const isCorrect = isCorrectGap(gapId);
213
- if (selected) {
214
- const word = getWordText(selected);
215
- btn.textContent = word;
216
- btn.removeAttribute('data-empty');
217
- if (isCorrect) {
218
- btn.classList.add('qti-gm-gap-correct');
219
- }
220
- // K-02: update aria-label to hint drop action when a word is held
221
- let filledAriaLabel: string;
222
- if (pickedUpWord !== null) {
223
- const heldWordText = getWordText(pickedUpWord);
224
- filledAriaLabel =
225
- i18n?.t('interactions.gapMatch.filledGapAriaLabelWithHeld', { gapId, word, heldWord: heldWordText }) ??
226
- `Blank ${gapId}, filled with ${word}. Press Enter to replace with ${heldWordText}.${isCorrect ? ' Correct answer.' : ''}`;
227
- } else {
228
- filledAriaLabel =
229
- i18n?.t('interactions.gapMatch.filledGapAriaLabel', { gapId, word }) ??
230
- `Blank ${gapId}, filled with ${word}. Click to clear.${isCorrect ? ' Correct answer.' : ''}`;
231
- }
232
- btn.setAttribute('aria-label', filledAriaLabel);
233
- } else {
234
- // Keep the gap visually blank (no letters), but still accessible.
235
- btn.textContent = '';
236
- btn.setAttribute('data-empty', 'true');
237
- if (isCorrect && correct) {
238
- const correctWord = getWordText(correct);
239
- btn.textContent = correctWord;
240
- btn.classList.add('qti-gm-gap-correct');
241
- btn.removeAttribute('data-empty');
242
- }
243
- // K-02: update aria-label to hint drop action when a word is held
244
- let ariaLabel: string;
245
- if (pickedUpWord !== null) {
246
- const heldWordText = getWordText(pickedUpWord);
247
- ariaLabel =
248
- i18n?.t('interactions.gapMatch.blankGapAriaLabelWithHeld', { gapId, heldWord: heldWordText }) ??
249
- `Blank ${gapId}. Press Enter to place ${heldWordText} here.${isCorrect ? ' Correct answer: ' + getWordText(correct) : ''}`;
250
- } else {
251
- ariaLabel =
252
- i18n?.t('interactions.gapMatch.blankGapAriaLabel', { gapId }) ??
253
- `Blank ${gapId}. Drop an answer here.${isCorrect ? ' Correct answer: ' + getWordText(correct) : ''}`;
254
- }
255
- btn.setAttribute('aria-label', ariaLabel);
256
- }
257
-
258
- // K-02: apply "ready to receive" visual class when a word is held
259
- if (pickedUpWord !== null) {
260
- btn.classList.add('qti-gm-gap-ready');
261
- }
262
-
263
- if (disabled) btn.setAttribute('aria-disabled', 'true');
264
-
265
- const onDragEnter = (e: DragEvent) => {
266
- if (disabled) return;
267
- e.preventDefault();
268
- btn.classList.add('is-dragover');
269
- };
270
-
271
- const onDragOver = (e: DragEvent) => {
272
- if (disabled) return;
273
- e.preventDefault();
274
- btn.classList.add('is-dragover');
275
- };
276
-
277
- const onDragLeave = () => {
278
- btn.classList.remove('is-dragover');
279
- };
280
-
281
- const onDrop = (e: DragEvent) => {
282
- if (disabled) return;
283
- e.preventDefault();
284
- btn.classList.remove('is-dragover');
285
- const wordId = e.dataTransfer?.getData('text/plain') ?? '';
286
- if (!wordId) return;
287
- handleGapChange(gapId, wordId);
288
- };
289
-
290
- const onClick = () => {
291
- if (disabled) return;
292
- // K-02: if a word is held, drop it into this gap
293
- if (pickedUpWord !== null) {
294
- const wordText = getWordText(pickedUpWord);
295
- handleGapChange(gapId, pickedUpWord);
296
- liveMessage =
297
- i18n?.t('interactions.gapMatch.placed', { word: wordText, gapId }) ??
298
- `Placed ${wordText} in blank ${gapId}.`;
299
- pickedUpWord = null;
300
- } else {
301
- // No word held: clear this gap if it has a word
302
- const current = getSelectedWord(gapId);
303
- if (current) handleGapChange(gapId, '');
304
- }
305
- };
306
-
307
- // K-02: keydown handler for gap buttons
308
- const onKeydown = (e: KeyboardEvent) => {
309
- if (disabled) return;
310
- if (e.key === 'Enter' || e.key === ' ') {
311
- e.preventDefault();
312
- onClick();
313
- } else if (e.key === 'Escape') {
314
- if (pickedUpWord !== null) {
315
- pickedUpWord = null;
316
- liveMessage = i18n?.t('interactions.gapMatch.pickUpCancelled') ?? 'Pick-up cancelled.';
317
- }
318
- }
319
- };
320
-
321
- btn.addEventListener('dragenter', onDragEnter);
322
- btn.addEventListener('dragover', onDragOver);
323
- btn.addEventListener('dragleave', onDragLeave);
324
- btn.addEventListener('drop', onDrop);
325
- btn.addEventListener('click', onClick);
326
- btn.addEventListener('keydown', onKeydown);
327
-
328
- // Store cleanup functions to remove event listeners later
329
- cleanupFunctions.push(() => {
330
- btn.removeEventListener('dragenter', onDragEnter);
331
- btn.removeEventListener('dragover', onDragOver);
332
- btn.removeEventListener('dragleave', onDragLeave);
333
- btn.removeEventListener('drop', onDrop);
334
- btn.removeEventListener('click', onClick);
335
- btn.removeEventListener('keydown', onKeydown);
336
- });
337
-
338
- ph.replaceWith(btn);
339
- }
340
- }
341
-
342
- // Re-render prompt when interaction or response changes (keeps selected word labels in sync)
343
- $effect(() => {
344
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
345
- parsedInteraction?.promptText;
346
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
347
- pairs.length;
348
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
349
- correctPairs.length;
350
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
351
- isShowingCorrect;
352
- // K-02: re-render whenever pickedUpWord changes so gap aria-labels and styles update
353
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
354
- pickedUpWord;
355
- renderPromptWithGaps();
356
- });
357
- </script>
358
-
359
- <ShadowBaseStyles />
360
-
361
- <!-- K-02: visually-hidden live region for screen reader announcements -->
362
- <div
363
- aria-live="polite"
364
- aria-atomic="true"
365
- class="qti-gm-live-region"
366
- >
367
- {liveMessage}
368
- </div>
369
-
370
- <!-- svelte-ignore a11y_no_static_element_interactions -->
371
- <div bind:this={rootElement} part="root" class={['qti-gap-match-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} onkeydown={onRootKeydown}>
372
- {#if !parsedInteraction}
373
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
374
- {:else}
375
- {#if parsedInteraction.prompt}
376
- <p part="prompt" class="qti-gm-prompt font-semibold">{@html parsedInteraction.prompt}</p>
377
- {/if}
378
-
379
- <!-- Available gap texts (draggable words) -->
380
- <div
381
- part="palette"
382
- class="qti-gm-palette flex flex-wrap gap-2 p-4 bg-base-200 rounded-lg border-2 border-base-300"
383
- style={parsedInteraction.choicesContainerWidth ? `width: ${parsedInteraction.choicesContainerWidth}` : undefined}
384
- role="group"
385
- aria-label={i18n?.t('interactions.gapMatch.availableLabel') ?? 'Available words to place'}
386
- >
387
- <div class="qti-gm-palette-title w-full text-sm text-base-content/70 font-semibold mb-2">
388
- Available words:
389
- </div>
390
- {#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
391
- {@const used = isWordUsed(gapText.identifier)}
392
- {@const isHeld = pickedUpWord === gapText.identifier}
393
- {@const isUnavailable = unavailableWords.has(gapText.identifier)}
394
- <div class="inline-flex items-center gap-1">
395
- <button
396
- part="word"
397
- type="button"
398
- class="btn btn-md font-medium transition-all"
399
- class:btn-primary={!used && !isHeld && !isUnavailable}
400
- class:btn-success={used && !isHeld}
401
- class:btn-warning={isHeld}
402
- class:qti-gm-word-held={isHeld}
403
- class:cursor-grab={!disabled && !used && !isUnavailable}
404
- class:cursor-not-allowed={disabled || isUnavailable}
405
- class:opacity-40={isUnavailable}
406
- class:opacity-70={disabled}
407
- data-word-id={gapText.identifier}
408
- draggable={!disabled && !used && !isUnavailable}
409
- aria-disabled={disabled || used || isUnavailable}
410
- aria-pressed={isHeld}
411
- disabled={disabled || used}
412
- ondragstart={(e: DragEvent) => onWordDragStart(e, gapText.identifier)}
413
- onkeydown={(e: KeyboardEvent) => onWordKeydown(e, gapText.identifier)}
414
- aria-label={isHeld
415
- ? (i18n?.t('interactions.gapMatch.wordAriaLabelHeld', { word: gapText.text }) ?? `${gapText.text} (currently held). Press Enter to cancel, or Tab to a blank.`)
416
- : (i18n?.t('interactions.gapMatch.wordAriaLabel', { word: gapText.text }) ?? `${gapText.text} (press Enter to pick up)`)}
417
- >
418
- {gapText.text}
419
- </button>
420
- {#if used && !disabled}
421
- <button
422
- type="button"
423
- part="word-remove"
424
- class="btn btn-sm btn-circle btn-error"
425
- onclick={() => clearWord(gapText.identifier)}
426
- aria-label="Remove {gapText.text} from the blanks"
427
- title={i18n?.t('interactions.gapMatch.removeWord') ?? 'Remove word'}
428
- >
429
- ✕
430
- </button>
431
- {/if}
432
- </div>
433
- {/each}
434
- </div>
435
-
436
- <!-- Render the text with gaps as drop targets, preserving original HTML structure -->
437
- <div part="text" class="qti-gm-text p-4 bg-base-100 border border-base-300 rounded">
438
- <div bind:this={promptContainer} class="qti-gm-inline"></div>
439
- </div>
440
- {/if}
441
- </div>
442
-
443
- <style>
444
- /* Minimal layout so this works without Tailwind/DaisyUI */
445
- .qti-gap-match-interaction {
446
- display: grid;
447
- gap: 0.75rem;
448
- }
449
- .qti-gm-prompt {
450
- margin: 0;
451
- }
452
- .qti-gm-palette {
453
- display: flex;
454
- flex-wrap: wrap;
455
- gap: 0.5rem;
456
- padding: 1rem;
457
- border-radius: 0.75rem;
458
- border: 2px solid var(--color-base-300, oklch(95% 0 0));
459
- background: var(--color-base-200, oklch(98% 0 0));
460
- align-items: center;
461
- }
462
- .qti-gm-text {
463
- padding: 1rem;
464
- border-radius: 0.75rem;
465
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
466
- background: var(--color-base-100, oklch(100% 0 0));
467
- }
468
- /* K-02: visually hidden live region */
469
- .qti-gm-live-region {
470
- position: absolute;
471
- width: 1px;
472
- height: 1px;
473
- padding: 0;
474
- margin: -1px;
475
- overflow: hidden;
476
- clip: rect(0, 0, 0, 0);
477
- white-space: nowrap;
478
- border: 0;
479
- }
480
- :global(.qti-gm-gap-target) {
481
- display: inline-flex;
482
- align-items: center;
483
- justify-content: center;
484
- min-width: 6.25rem;
485
- margin: 0 0.25rem;
486
- /* Height/padding/border/background should come from DaisyUI `select select-sm`
487
- (or ShadowBaseStyles fallback), so empty and filled gaps match exactly. */
488
- font: inherit;
489
- vertical-align: baseline;
490
- cursor: pointer;
491
- transition:
492
- border-color 120ms ease,
493
- box-shadow 120ms ease,
494
- background-color 120ms ease;
495
- }
496
- :global(.qti-gm-gap-target[data-empty='true']) {
497
- /* Same size + base styling as a filled gap, but dashed to indicate "drop here". */
498
- border-style: dashed;
499
- border-color: color-mix(
500
- in oklch,
501
- var(--color-base-content, oklch(21% 0 0)) 18%,
502
- var(--color-base-300, oklch(95% 0 0))
503
- );
504
- }
505
- :global(.qti-gm-gap-target[data-empty='true']::before) {
506
- /* Ensure empty gaps reserve the same line-height as filled gaps (no visible text). */
507
- content: '\00a0';
508
- }
509
- :global(.qti-gm-gap-target.is-dragover) {
510
- border-color: var(--color-primary, oklch(45% 0.24 277));
511
- box-shadow:
512
- 0 0 0 3px color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 28%, transparent),
513
- inset 0 -2px 0 var(--color-base-300, oklch(95% 0 0));
514
- background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 8%, transparent);
515
- }
516
- :global(.qti-gm-gap-target[aria-disabled='true']) {
517
- opacity: 0.6;
518
- cursor: not-allowed;
519
- }
520
- :global(.qti-gm-gap-target.qti-gm-gap-correct) {
521
- border-color: var(--color-success, oklch(76% 0.177 163.223));
522
- background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
523
- }
524
- /* K-02: "ready to receive" visual for gap targets when a word is held */
525
- :global(.qti-gm-gap-target.qti-gm-gap-ready) {
526
- border-style: dashed;
527
- border-color: var(--color-primary, oklch(45% 0.24 277));
528
- box-shadow: 0 0 0 2px color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 22%, transparent);
529
- }
530
- :global(.qti-gm-gap-target:focus-visible) {
531
- outline: 2px solid hsl(var(--p, 240 100% 50%) / 0.5);
532
- outline-offset: 2px;
533
- }
534
- :global(.qti-gm-gap-target:hover) {
535
- border-color: color-mix(
536
- in oklch,
537
- var(--color-primary, oklch(45% 0.24 277)) 22%,
538
- var(--color-base-300, oklch(95% 0 0))
539
- );
540
- }
541
- .qti-gm-palette [part='word'][aria-disabled='true'] {
542
- opacity: 0.55;
543
- cursor: not-allowed;
544
- }
545
- .qti-gm-palette [part='word'][draggable='true'] {
546
- cursor: grab;
547
- }
548
- .qti-gm-palette [part='word'][draggable='true']:active {
549
- cursor: grabbing;
550
- }
551
- /* K-02: "held" visual for the picked-up word button */
552
- :global(.qti-gm-word-held) {
553
- outline: 3px solid var(--color-warning, oklch(84% 0.2 85));
554
- outline-offset: 2px;
555
- }
556
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'gapMatchInteraction',
5
- tagName: 'pie-qti-gap-match',
6
- name: 'default-gap-match',
7
- description: 'Default Svelte-based gap match interaction',
8
- priority: 0,
9
- };