@pie-qti/default-components 0.1.4 → 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 (32) 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/utils/matchGroupUtils.d.ts +8 -0
  8. package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
  9. package/dist/shared/utils/matchGroupUtils.js +13 -0
  10. package/package.json +8 -4
  11. package/src/catalog/CatalogPopup.svelte +162 -0
  12. package/src/index.ts +10 -1
  13. package/src/plugins/associate/AssociateInteraction.svelte +18 -1
  14. package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
  15. package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
  16. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
  17. package/src/plugins/gap-match/GapMatchInteraction.svelte +174 -12
  18. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
  19. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +197 -107
  20. package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
  21. package/src/plugins/hottext/HottextInteraction.svelte +33 -4
  22. package/src/plugins/index.ts +1 -0
  23. package/src/plugins/match/MatchInteraction.svelte +13 -1
  24. package/src/plugins/order/OrderInteraction.svelte +132 -11
  25. package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -9
  26. package/src/plugins/select-point/SelectPointInteraction.svelte +139 -7
  27. package/src/shared/components/GraphicGapMatch.svelte +5 -3
  28. package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
  29. package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
  30. package/src/shared/components/MatchDragDrop.svelte +48 -2
  31. package/src/shared/styles/qti-shared-vocabulary.css +320 -0
  32. package/src/shared/utils/matchGroupUtils.ts +14 -0
@@ -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,6 +44,26 @@
37
44
  // Track cleanup functions for event listeners to prevent memory leaks
38
45
  let cleanupFunctions: (() => void)[] = [];
39
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
+
40
67
  function getMatchMax(wordId: string): number {
41
68
  const gt = parsedInteraction?.gapTexts?.find((g) => g.identifier === wordId);
42
69
  return gt?.matchMax ?? 1;
@@ -103,6 +130,39 @@
103
130
  e.dataTransfer.effectAllowed = 'move';
104
131
  }
105
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
+
106
166
  function clearWord(wordId: string) {
107
167
  if (disabled) return;
108
168
  const newPairs = pairs.filter((p: string) => !p.startsWith(`${wordId} `));
@@ -157,7 +217,18 @@
157
217
  if (isCorrect) {
158
218
  btn.classList.add('qti-gm-gap-correct');
159
219
  }
160
- 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
+ }
161
232
  btn.setAttribute('aria-label', filledAriaLabel);
162
233
  } else {
163
234
  // Keep the gap visually blank (no letters), but still accessible.
@@ -169,9 +240,26 @@
169
240
  btn.classList.add('qti-gm-gap-correct');
170
241
  btn.removeAttribute('data-empty');
171
242
  }
172
- 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
+ }
173
255
  btn.setAttribute('aria-label', ariaLabel);
174
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
+
175
263
  if (disabled) btn.setAttribute('aria-disabled', 'true');
176
264
 
177
265
  const onDragEnter = (e: DragEvent) => {
@@ -201,8 +289,33 @@
201
289
 
202
290
  const onClick = () => {
203
291
  if (disabled) return;
204
- const current = getSelectedWord(gapId);
205
- 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
+ }
206
319
  };
207
320
 
208
321
  btn.addEventListener('dragenter', onDragEnter);
@@ -210,6 +323,7 @@
210
323
  btn.addEventListener('dragleave', onDragLeave);
211
324
  btn.addEventListener('drop', onDrop);
212
325
  btn.addEventListener('click', onClick);
326
+ btn.addEventListener('keydown', onKeydown);
213
327
 
214
328
  // Store cleanup functions to remove event listeners later
215
329
  cleanupFunctions.push(() => {
@@ -218,6 +332,7 @@
218
332
  btn.removeEventListener('dragleave', onDragLeave);
219
333
  btn.removeEventListener('drop', onDrop);
220
334
  btn.removeEventListener('click', onClick);
335
+ btn.removeEventListener('keydown', onKeydown);
221
336
  });
222
337
 
223
338
  ph.replaceWith(btn);
@@ -234,13 +349,26 @@
234
349
  correctPairs.length;
235
350
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
236
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;
237
355
  renderPromptWithGaps();
238
356
  });
239
357
  </script>
240
358
 
241
359
  <ShadowBaseStyles />
242
360
 
243
- <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}>
244
372
  {#if !parsedInteraction}
245
373
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
246
374
  {:else}
@@ -252,6 +380,7 @@
252
380
  <div
253
381
  part="palette"
254
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}
255
384
  role="group"
256
385
  aria-label={i18n?.t('interactions.gapMatch.availableLabel') ?? 'Available words to place'}
257
386
  >
@@ -260,21 +389,31 @@
260
389
  </div>
261
390
  {#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
262
391
  {@const used = isWordUsed(gapText.identifier)}
392
+ {@const isHeld = pickedUpWord === gapText.identifier}
393
+ {@const isUnavailable = unavailableWords.has(gapText.identifier)}
263
394
  <div class="inline-flex items-center gap-1">
264
395
  <button
265
396
  part="word"
266
397
  type="button"
267
398
  class="btn btn-md font-medium transition-all"
268
- class:btn-primary={!used}
269
- class:btn-success={used}
270
- class:cursor-grab={!disabled && !used}
271
- 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}
272
406
  class:opacity-70={disabled}
273
407
  data-word-id={gapText.identifier}
274
- draggable={!disabled && !used}
275
- aria-disabled={disabled || used}
408
+ draggable={!disabled && !used && !isUnavailable}
409
+ aria-disabled={disabled || used || isUnavailable}
410
+ aria-pressed={isHeld}
276
411
  disabled={disabled || used}
277
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)`)}
278
417
  >
279
418
  {gapText.text}
280
419
  </button>
@@ -326,6 +465,18 @@
326
465
  border: 1px solid var(--color-base-300, oklch(95% 0 0));
327
466
  background: var(--color-base-100, oklch(100% 0 0));
328
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
+ }
329
480
  :global(.qti-gm-gap-target) {
330
481
  display: inline-flex;
331
482
  align-items: center;
@@ -343,7 +494,7 @@
343
494
  background-color 120ms ease;
344
495
  }
345
496
  :global(.qti-gm-gap-target[data-empty='true']) {
346
- /* 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". */
347
498
  border-style: dashed;
348
499
  border-color: color-mix(
349
500
  in oklch,
@@ -370,6 +521,12 @@
370
521
  border-color: var(--color-success, oklch(76% 0.177 163.223));
371
522
  background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
372
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
+ }
373
530
  :global(.qti-gm-gap-target:focus-visible) {
374
531
  outline: 2px solid hsl(var(--p, 240 100% 50%) / 0.5);
375
532
  outline-offset: 2px;
@@ -391,4 +548,9 @@
391
548
  .qti-gm-palette [part='word'][draggable='true']:active {
392
549
  cursor: grabbing;
393
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
+ }
394
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>