@pie-qti/default-components 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -1
  4. package/dist/plugins/index.d.ts +1 -0
  5. package/dist/plugins/index.d.ts.map +1 -1
  6. package/dist/plugins/index.js +1 -0
  7. package/dist/shared/extensions/MathLiveEditor.d.ts +1 -0
  8. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
  9. package/dist/shared/extensions/MathLiveEditor.js +3 -7
  10. package/dist/shared/utils/eventHelpers.d.ts +3 -11
  11. package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
  12. package/dist/shared/utils/eventHelpers.js +7 -1
  13. package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
  14. package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
  15. package/dist/shared/utils/matchGroupUtils.js +13 -0
  16. package/dist/shared/utils/pairHelpers.d.ts +15 -2
  17. package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
  18. package/dist/shared/utils/pairHelpers.js +30 -8
  19. package/dist/shared/utils/touchDragHelper.d.ts +1 -32
  20. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
  21. package/dist/shared/utils/touchDragHelper.js +1 -168
  22. package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
  23. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
  24. package/dist/shared/utils/webComponentHelpers.js +3 -3
  25. package/package.json +117 -91
  26. package/src/catalog/CatalogPopup.svelte +162 -0
  27. package/src/index.ts +10 -1
  28. package/src/plugins/associate/AssociateInteraction.svelte +18 -1
  29. package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
  30. package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
  31. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
  32. package/src/plugins/gap-match/GapMatchInteraction.svelte +199 -22
  33. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
  34. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +230 -145
  35. package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
  36. package/src/plugins/hottext/HottextInteraction.svelte +33 -4
  37. package/src/plugins/index.ts +1 -0
  38. package/src/plugins/match/MatchInteraction.svelte +13 -1
  39. package/src/plugins/media/MediaInteraction.svelte +2 -2
  40. package/src/plugins/order/OrderInteraction.svelte +132 -11
  41. package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -15
  42. package/src/plugins/select-point/SelectPointInteraction.svelte +139 -21
  43. package/src/shared/components/DrawingCanvas.svelte +17 -1
  44. package/src/shared/components/GraphicGapMatch.svelte +5 -3
  45. package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
  46. package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
  47. package/src/shared/components/MatchDragDrop.svelte +72 -25
  48. package/src/shared/components/ShadowBaseStyles.svelte +1 -2
  49. package/src/shared/extensions/MathLiveEditor.ts +3 -8
  50. package/src/shared/styles/qti-shared-vocabulary.css +320 -0
  51. package/src/shared/utils/eventHelpers.ts +12 -3
  52. package/src/shared/utils/matchGroupUtils.ts +14 -0
  53. package/src/shared/utils/pairHelpers.ts +32 -9
  54. package/src/shared/utils/touchDragHelper.ts +1 -211
  55. package/src/shared/utils/webComponentHelpers.ts +5 -5
  56. package/.turbo/turbo-build.log +0 -1
  57. package/CHANGELOG.md +0 -9
  58. package/STYLING.md +0 -226
  59. package/svelte.config.js +0 -9
  60. package/tests/index.test.ts +0 -8
  61. package/tsconfig.json +0 -20
@@ -63,6 +63,15 @@
63
63
  {#if parsedInteraction.prompt}
64
64
  <p class="font-semibold mb-2">{parsedInteraction.prompt}</p>
65
65
  {/if}
66
+ <!--
67
+ Accessibility note (WCAG 2.1 SC 2.1.1 exemption):
68
+ Free-form drawing is a path-dependent pointer input. WCAG 2.1.1 exempts inputs
69
+ "where the underlying function requires input that depends on the path of the
70
+ user's movement and not just the endpoints" (e.g. freehand drawing, handwriting).
71
+ Item authors MUST provide an accessible alternative form (e.g. an extended-text
72
+ response or upload interaction) so that keyboard-only and switch-access users
73
+ can submit equivalent evidence of their knowledge.
74
+ -->
66
75
  <DrawingCanvas
67
76
  responseId={parsedInteraction.responseId}
68
77
  imageData={parsedInteraction.imageData}
@@ -39,11 +39,27 @@
39
39
  rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, html));
40
40
  }
41
41
  }
42
+
43
+ // Character counter support (qti-counter-down / qti-counter-up)
44
+ function charCount(html: string, format: string): number {
45
+ if (format === 'xhtml') {
46
+ // Strip HTML tags, count only text characters
47
+ return html.replace(/<[^>]*>/g, '').length;
48
+ }
49
+ return html.length;
50
+ }
51
+
52
+ const currentCount = $derived(charCount(parsedResponse ?? '', parsedInteraction?.format ?? 'plain'));
53
+ const expectedLength = $derived(parsedInteraction?.expectedLength ?? 0);
54
+ const classes = $derived(parsedInteraction?.interactionClasses ?? []);
55
+ const showCounterDown = $derived(classes.includes('qti-counter-down') && expectedLength > 0);
56
+ const showCounterUp = $derived(classes.includes('qti-counter-up') && expectedLength > 0);
57
+ const remaining = $derived(expectedLength - currentCount);
42
58
  </script>
43
59
 
44
60
  <ShadowBaseStyles />
45
61
 
46
- <div bind:this={rootElement} part="root" class="qti-extended-text-interaction">
62
+ <div bind:this={rootElement} part="root" class={['qti-extended-text-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
47
63
  {#if !parsedInteraction}
48
64
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
49
65
  {:else}
@@ -57,6 +73,15 @@
57
73
  onChange={handleChange}
58
74
  />
59
75
  </div>
76
+ {#if showCounterDown}
77
+ <p part="counter" class="qti-character-counter" aria-live="polite">
78
+ {remaining >= 0 ? remaining : 0} {i18n?.t('interactions.extendedText.charsRemaining', 'characters remaining')}
79
+ </p>
80
+ {:else if showCounterUp}
81
+ <p part="counter" class="qti-character-counter" aria-live="polite">
82
+ {currentCount} / {expectedLength} {i18n?.t('interactions.extendedText.charsUsed', 'characters')}
83
+ </p>
84
+ {/if}
60
85
  {#if isShowingCorrect && parsedCorrectResponse}
61
86
  <div part="correct-answer" class="mt-3 p-3 bg-success bg-opacity-10 border border-success rounded">
62
87
  <div class="text-sm font-semibold text-success mb-2">
@@ -74,4 +99,34 @@
74
99
  display: grid;
75
100
  gap: 0.75rem;
76
101
  }
102
+
103
+ /* QTI 3.0 Shared Vocabulary: qti-height-lines-N sets minimum textarea height.
104
+ Each line unit = 1.5rem (24px) matching the editor's line-height. */
105
+ .qti-height-lines-1 { --qti-min-height: 1.5rem; }
106
+ .qti-height-lines-2 { --qti-min-height: 3rem; }
107
+ .qti-height-lines-3 { --qti-min-height: 4.5rem; }
108
+ .qti-height-lines-4 { --qti-min-height: 6rem; }
109
+ .qti-height-lines-5 { --qti-min-height: 7.5rem; }
110
+ .qti-height-lines-6 { --qti-min-height: 9rem; }
111
+ .qti-height-lines-7 { --qti-min-height: 10.5rem; }
112
+ .qti-height-lines-8 { --qti-min-height: 12rem; }
113
+ .qti-height-lines-10 { --qti-min-height: 15rem; }
114
+ .qti-height-lines-12 { --qti-min-height: 18rem; }
115
+ .qti-height-lines-15 { --qti-min-height: 22.5rem; }
116
+ .qti-height-lines-20 { --qti-min-height: 30rem; }
117
+ .qti-height-lines-25 { --qti-min-height: 37.5rem; }
118
+
119
+ /* Apply the CSS variable to the editor's inner textarea via the part */
120
+ [class*='qti-height-lines-'] :global([part='editor'] .ProseMirror),
121
+ [class*='qti-height-lines-'] :global([part='editor'] textarea) {
122
+ min-height: var(--qti-min-height);
123
+ }
124
+
125
+ .qti-character-counter {
126
+ font-size: 0.8125rem;
127
+ color: var(--color-base-content, #374151);
128
+ opacity: 0.7;
129
+ margin-top: 0.25rem;
130
+ text-align: right;
131
+ }
77
132
  </style>
@@ -6,6 +6,7 @@
6
6
  import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
7
  import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
8
8
  import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
+ import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
9
10
 
10
11
  interface Props {
11
12
  interaction?: GapMatchInteractionData | string;
@@ -28,6 +29,12 @@
28
29
  const pairs = $derived(Array.isArray(parsedResponse) ? parsedResponse : []);
29
30
  const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
30
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
+
31
38
  // Get reference to the root element for event dispatching
32
39
  let rootElement: HTMLDivElement | undefined = $state();
33
40
 
@@ -37,29 +44,64 @@
37
44
  // Track cleanup functions for event listeners to prevent memory leaks
38
45
  let cleanupFunctions: (() => void)[] = [];
39
46
 
40
- function handleGapChange(gapId: string, wordId: string) {
41
- // Remove any existing pair for this gap
42
- const newPairs = pairs.filter((p: string) => !p.endsWith(` ${gapId}`));
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
+ });
43
66
 
44
- // If this word is already used in another gap, move it (remove its previous assignment).
45
- const withoutWord = newPairs.filter((p: string) => !p.startsWith(`${wordId} `));
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
+ }
46
83
 
47
84
  // Add new pair if a word was selected
48
85
  if (wordId) {
49
- withoutWord.push(`${wordId} ${gapId}`);
86
+ const newPair = `${wordId} ${gapId}`;
87
+ if (!newPairs.includes(newPair)) {
88
+ newPairs.push(newPair);
89
+ }
50
90
  }
51
91
 
52
- response = withoutWord;
92
+ response = newPairs;
53
93
  // Call onChange callback if provided (for Svelte component usage)
54
- onChange?.(withoutWord);
94
+ onChange?.(newPairs);
55
95
  // Dispatch event for web component usage - event will bubble up to the host element
56
96
  if (rootElement) {
57
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, withoutWord));
97
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
58
98
  }
59
99
  }
60
100
 
61
101
  function isWordUsed(wordId: string): boolean {
62
- return pairs.some((p: string) => p.startsWith(wordId));
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"
63
105
  }
64
106
 
65
107
  function getSelectedWord(gapId: string): string {
@@ -88,6 +130,39 @@
88
130
  e.dataTransfer.effectAllowed = 'move';
89
131
  }
90
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
+
91
166
  function clearWord(wordId: string) {
92
167
  if (disabled) return;
93
168
  const newPairs = pairs.filter((p: string) => !p.startsWith(`${wordId} `));
@@ -142,7 +217,18 @@
142
217
  if (isCorrect) {
143
218
  btn.classList.add('qti-gm-gap-correct');
144
219
  }
145
- const filledAriaLabel = i18n?.t('interactions.gapMatch.filledGapAriaLabel', { gapId, word }) ?? `Blank ${gapId}, filled with ${word}. Click to clear.${isCorrect ? ' Correct answer.' : ''}`;
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
+ }
146
232
  btn.setAttribute('aria-label', filledAriaLabel);
147
233
  } else {
148
234
  // Keep the gap visually blank (no letters), but still accessible.
@@ -154,9 +240,26 @@
154
240
  btn.classList.add('qti-gm-gap-correct');
155
241
  btn.removeAttribute('data-empty');
156
242
  }
157
- const ariaLabel = i18n?.t('interactions.gapMatch.blankGapAriaLabel', { gapId }) ?? `Blank ${gapId}. Drop an answer here.${isCorrect ? ' Correct answer: ' + getWordText(correct) : ''}`;
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
+ }
158
255
  btn.setAttribute('aria-label', ariaLabel);
159
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
+
160
263
  if (disabled) btn.setAttribute('aria-disabled', 'true');
161
264
 
162
265
  const onDragEnter = (e: DragEvent) => {
@@ -186,8 +289,33 @@
186
289
 
187
290
  const onClick = () => {
188
291
  if (disabled) return;
189
- const current = getSelectedWord(gapId);
190
- if (current) handleGapChange(gapId, '');
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
+ }
191
319
  };
192
320
 
193
321
  btn.addEventListener('dragenter', onDragEnter);
@@ -195,6 +323,7 @@
195
323
  btn.addEventListener('dragleave', onDragLeave);
196
324
  btn.addEventListener('drop', onDrop);
197
325
  btn.addEventListener('click', onClick);
326
+ btn.addEventListener('keydown', onKeydown);
198
327
 
199
328
  // Store cleanup functions to remove event listeners later
200
329
  cleanupFunctions.push(() => {
@@ -203,6 +332,7 @@
203
332
  btn.removeEventListener('dragleave', onDragLeave);
204
333
  btn.removeEventListener('drop', onDrop);
205
334
  btn.removeEventListener('click', onClick);
335
+ btn.removeEventListener('keydown', onKeydown);
206
336
  });
207
337
 
208
338
  ph.replaceWith(btn);
@@ -219,13 +349,26 @@
219
349
  correctPairs.length;
220
350
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
221
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;
222
355
  renderPromptWithGaps();
223
356
  });
224
357
  </script>
225
358
 
226
359
  <ShadowBaseStyles />
227
360
 
228
- <div bind:this={rootElement} part="root" class="qti-gap-match-interaction space-y-3">
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}>
229
372
  {#if !parsedInteraction}
230
373
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
231
374
  {:else}
@@ -237,6 +380,7 @@
237
380
  <div
238
381
  part="palette"
239
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}
240
384
  role="group"
241
385
  aria-label={i18n?.t('interactions.gapMatch.availableLabel') ?? 'Available words to place'}
242
386
  >
@@ -245,21 +389,31 @@
245
389
  </div>
246
390
  {#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
247
391
  {@const used = isWordUsed(gapText.identifier)}
392
+ {@const isHeld = pickedUpWord === gapText.identifier}
393
+ {@const isUnavailable = unavailableWords.has(gapText.identifier)}
248
394
  <div class="inline-flex items-center gap-1">
249
395
  <button
250
396
  part="word"
251
397
  type="button"
252
398
  class="btn btn-md font-medium transition-all"
253
- class:btn-primary={!used}
254
- class:btn-success={used}
255
- class:cursor-grab={!disabled && !used}
256
- class:cursor-not-allowed={disabled}
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}
257
406
  class:opacity-70={disabled}
258
407
  data-word-id={gapText.identifier}
259
- draggable={!disabled && !used}
260
- aria-disabled={disabled || used}
408
+ draggable={!disabled && !used && !isUnavailable}
409
+ aria-disabled={disabled || used || isUnavailable}
410
+ aria-pressed={isHeld}
261
411
  disabled={disabled || used}
262
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)`)}
263
417
  >
264
418
  {gapText.text}
265
419
  </button>
@@ -311,6 +465,18 @@
311
465
  border: 1px solid var(--color-base-300, oklch(95% 0 0));
312
466
  background: var(--color-base-100, oklch(100% 0 0));
313
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
+ }
314
480
  :global(.qti-gm-gap-target) {
315
481
  display: inline-flex;
316
482
  align-items: center;
@@ -328,7 +494,7 @@
328
494
  background-color 120ms ease;
329
495
  }
330
496
  :global(.qti-gm-gap-target[data-empty='true']) {
331
- /* Same size + base styling as a filled gap, but dashed to indicate “drop here”. */
497
+ /* Same size + base styling as a filled gap, but dashed to indicate "drop here". */
332
498
  border-style: dashed;
333
499
  border-color: color-mix(
334
500
  in oklch,
@@ -355,6 +521,12 @@
355
521
  border-color: var(--color-success, oklch(76% 0.177 163.223));
356
522
  background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
357
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
+ }
358
530
  :global(.qti-gm-gap-target:focus-visible) {
359
531
  outline: 2px solid hsl(var(--p, 240 100% 50%) / 0.5);
360
532
  outline-offset: 2px;
@@ -376,4 +548,9 @@
376
548
  .qti-gm-palette [part='word'][draggable='true']:active {
377
549
  cursor: grabbing;
378
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
+ }
379
556
  </style>
@@ -6,6 +6,7 @@
6
6
  import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
7
  import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
8
8
  import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
9
+ import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
9
10
 
10
11
  interface Props {
11
12
  interaction?: GraphicAssociateInteractionData | string;
@@ -38,6 +39,19 @@
38
39
  const canInteract = $derived(!disabled);
39
40
  const canAddMore = $derived(!parsedInteraction || pairs.length < parsedInteraction.maxAssociations);
40
41
 
42
+ // Hotspots incompatible with the currently selected hotspot due to matchGroup constraints
43
+ const blockedHotspots = $derived.by(() => {
44
+ if (!selectedHotspot || !parsedInteraction) return new Set<string>();
45
+ type WithMatchGroup = { identifier: string; matchGroup?: string[] };
46
+ const hotspots = parsedInteraction.associableHotspots as (typeof parsedInteraction.associableHotspots[number] & WithMatchGroup)[];
47
+ const src = hotspots.find((h) => h.identifier === selectedHotspot);
48
+ return new Set(
49
+ hotspots
50
+ .filter((h) => h.identifier !== selectedHotspot && !isCompatibleMatchGroup(src?.matchGroup, h.matchGroup))
51
+ .map((h) => h.identifier)
52
+ );
53
+ });
54
+
41
55
  $effect(() => {
42
56
  // Sync with parent response changes
43
57
  pairs = parsedResponse ? [...parsedResponse] : [];
@@ -65,6 +79,7 @@
65
79
  } else {
66
80
  // Second selection - create a pair
67
81
  if (!canAddMore) return;
82
+ if (blockedHotspots.has(hotspotId)) return;
68
83
 
69
84
  const newPair = `${selectedHotspot} ${hotspotId}`;
70
85
  pairs = [...pairs, newPair];
@@ -123,14 +138,22 @@
123
138
  function getHotspotCenter(coords: string, shape: string): { x: number; y: number } {
124
139
  const parts = coords.split(',').map(Number);
125
140
  if (shape === 'rect') {
126
- // rect: x1,y1,x2,y2
141
+ // rect: left,top,right,bottom
127
142
  return {
128
143
  x: (parts[0] + parts[2]) / 2,
129
144
  y: (parts[1] + parts[3]) / 2,
130
145
  };
131
- } else if (shape === 'circle') {
132
- // circle: cx,cy,r
146
+ } else if (shape === 'circle' || shape === 'ellipse') {
147
+ // circle: cx,cy,r | ellipse: cx,cy,rx,ry
133
148
  return { x: parts[0], y: parts[1] };
149
+ } else if (shape === 'poly') {
150
+ // poly: x1,y1,x2,y2,... — centroid average
151
+ const xs = parts.filter((_, i) => i % 2 === 0);
152
+ const ys = parts.filter((_, i) => i % 2 !== 0);
153
+ return {
154
+ x: xs.reduce((a, b) => a + b, 0) / xs.length,
155
+ y: ys.reduce((a, b) => a + b, 0) / ys.length,
156
+ };
134
157
  }
135
158
  // Default fallback
136
159
  return { x: parts[0] || 0, y: parts[1] || 0 };
@@ -228,6 +251,7 @@
228
251
  {#each parsedInteraction.associableHotspots as hotspot}
229
252
  {@const isSelected = isHotspotSelected(hotspot.identifier)}
230
253
  {@const isMaxed = isHotspotMaxed(hotspot.identifier)}
254
+ {@const isBlocked = blockedHotspots.has(hotspot.identifier)}
231
255
  {@const usageCount = getHotspotUsageCount(hotspot.identifier)}
232
256
  {@const isCorrect = isHotspotInCorrectPair(hotspot.identifier)}
233
257
 
@@ -239,8 +263,8 @@
239
263
  ? 'bg-primary/40 border-primary border-4'
240
264
  : isCorrect
241
265
  ? 'bg-success/20 border-success'
242
- : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed
243
- ? 'opacity-50 cursor-not-allowed'
266
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
267
+ ? 'opacity-40 cursor-not-allowed'
244
268
  : canInteract
245
269
  ? 'cursor-pointer'
246
270
  : 'cursor-not-allowed opacity-70'}"
@@ -248,7 +272,8 @@
248
272
  y1}px; z-index: 20;"
249
273
  onclick={() => handleHotspotClick(hotspot.identifier)}
250
274
  disabled={!canInteract || isMaxed}
251
- aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : ''}"
275
+ aria-disabled={isBlocked ? 'true' : undefined}
276
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
252
277
  >
253
278
  <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
254
279
  </button>
@@ -260,8 +285,8 @@
260
285
  ? 'bg-primary/40 border-primary border-4'
261
286
  : isCorrect
262
287
  ? 'bg-success/20 border-success'
263
- : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed
264
- ? 'opacity-50 cursor-not-allowed'
288
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
289
+ ? 'opacity-40 cursor-not-allowed'
265
290
  : canInteract
266
291
  ? 'cursor-pointer'
267
292
  : 'cursor-not-allowed opacity-70'}"
@@ -269,7 +294,58 @@
269
294
  2}px; z-index: 20;"
270
295
  onclick={() => handleHotspotClick(hotspot.identifier)}
271
296
  disabled={!canInteract || isMaxed}
272
- aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : ''}"
297
+ aria-disabled={isBlocked ? 'true' : undefined}
298
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
299
+ >
300
+ <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
301
+ </button>
302
+ {:else if hotspot.shape === 'ellipse'}
303
+ <!-- Ellipse: QTI coords are cx,cy,rx,ry — use bounding box for hit target -->
304
+ {@const [cx, cy, rx, ry] = hotspot.coords.split(',').map(Number)}
305
+ <button
306
+ part="hotspot"
307
+ class="qti-ga-hotspot absolute border-2 flex items-center justify-center transition-all {isSelected
308
+ ? 'bg-primary/40 border-primary border-4'
309
+ : isCorrect
310
+ ? 'bg-success/20 border-success'
311
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
312
+ ? 'opacity-40 cursor-not-allowed'
313
+ : canInteract
314
+ ? 'cursor-pointer'
315
+ : 'cursor-not-allowed opacity-70'}"
316
+ style="left: {cx - rx}px; top: {cy - ry}px; width: {rx * 2}px; height: {ry * 2}px; border-radius: 50%; z-index: 20;"
317
+ onclick={() => handleHotspotClick(hotspot.identifier)}
318
+ disabled={!canInteract || isMaxed}
319
+ aria-disabled={isBlocked ? 'true' : undefined}
320
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
321
+ >
322
+ <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
323
+ </button>
324
+ {:else if hotspot.shape === 'poly'}
325
+ <!-- Polygon: use axis-aligned bounding box of all vertices for hit target -->
326
+ {@const pts = hotspot.coords.split(',').map(Number)}
327
+ {@const xs = pts.filter((_, i) => i % 2 === 0)}
328
+ {@const ys = pts.filter((_, i) => i % 2 !== 0)}
329
+ {@const x1 = Math.min(...xs)}
330
+ {@const y1 = Math.min(...ys)}
331
+ {@const x2 = Math.max(...xs)}
332
+ {@const y2 = Math.max(...ys)}
333
+ <button
334
+ part="hotspot"
335
+ class="qti-ga-hotspot absolute border-2 flex items-center justify-center transition-all {isSelected
336
+ ? 'bg-primary/40 border-primary border-4'
337
+ : isCorrect
338
+ ? 'bg-success/20 border-success'
339
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
340
+ ? 'opacity-40 cursor-not-allowed'
341
+ : canInteract
342
+ ? 'cursor-pointer'
343
+ : 'cursor-not-allowed opacity-70'}"
344
+ style="left: {x1}px; top: {y1}px; width: {x2 - x1}px; height: {y2 - y1}px; z-index: 20;"
345
+ onclick={() => handleHotspotClick(hotspot.identifier)}
346
+ disabled={!canInteract || isMaxed}
347
+ aria-disabled={isBlocked ? 'true' : undefined}
348
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
273
349
  >
274
350
  <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
275
351
  </button>