@pie-qti/default-components 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/STYLING.md +226 -0
  4. package/dist/index.d.ts +35 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +190 -0
  7. package/dist/plugins/associate/index.d.ts +8 -0
  8. package/dist/plugins/associate/index.d.ts.map +1 -0
  9. package/dist/plugins/associate/index.js +8 -0
  10. package/dist/plugins/choice/index.d.ts +8 -0
  11. package/dist/plugins/choice/index.d.ts.map +1 -0
  12. package/dist/plugins/choice/index.js +8 -0
  13. package/dist/plugins/custom/index.d.ts +8 -0
  14. package/dist/plugins/custom/index.d.ts.map +1 -0
  15. package/dist/plugins/custom/index.js +8 -0
  16. package/dist/plugins/end-attempt/index.d.ts +8 -0
  17. package/dist/plugins/end-attempt/index.d.ts.map +1 -0
  18. package/dist/plugins/end-attempt/index.js +8 -0
  19. package/dist/plugins/extended-text/index.d.ts +8 -0
  20. package/dist/plugins/extended-text/index.d.ts.map +1 -0
  21. package/dist/plugins/extended-text/index.js +8 -0
  22. package/dist/plugins/gap-match/index.d.ts +8 -0
  23. package/dist/plugins/gap-match/index.d.ts.map +1 -0
  24. package/dist/plugins/gap-match/index.js +8 -0
  25. package/dist/plugins/graphic-associate/index.d.ts +8 -0
  26. package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
  27. package/dist/plugins/graphic-associate/index.js +8 -0
  28. package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.js +8 -0
  31. package/dist/plugins/graphic-order/index.d.ts +8 -0
  32. package/dist/plugins/graphic-order/index.d.ts.map +1 -0
  33. package/dist/plugins/graphic-order/index.js +8 -0
  34. package/dist/plugins/hotspot/index.d.ts +8 -0
  35. package/dist/plugins/hotspot/index.d.ts.map +1 -0
  36. package/dist/plugins/hotspot/index.js +8 -0
  37. package/dist/plugins/hottext/index.d.ts +8 -0
  38. package/dist/plugins/hottext/index.d.ts.map +1 -0
  39. package/dist/plugins/hottext/index.js +8 -0
  40. package/dist/plugins/index.d.ts +30 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/match/index.d.ts +8 -0
  44. package/dist/plugins/match/index.d.ts.map +1 -0
  45. package/dist/plugins/match/index.js +8 -0
  46. package/dist/plugins/media/index.d.ts +8 -0
  47. package/dist/plugins/media/index.d.ts.map +1 -0
  48. package/dist/plugins/media/index.js +8 -0
  49. package/dist/plugins/order/index.d.ts +8 -0
  50. package/dist/plugins/order/index.d.ts.map +1 -0
  51. package/dist/plugins/order/index.js +8 -0
  52. package/dist/plugins/position-object/index.d.ts +8 -0
  53. package/dist/plugins/position-object/index.d.ts.map +1 -0
  54. package/dist/plugins/position-object/index.js +8 -0
  55. package/dist/plugins/select-point/index.d.ts +8 -0
  56. package/dist/plugins/select-point/index.d.ts.map +1 -0
  57. package/dist/plugins/select-point/index.js +8 -0
  58. package/dist/plugins/slider/index.d.ts +8 -0
  59. package/dist/plugins/slider/index.d.ts.map +1 -0
  60. package/dist/plugins/slider/index.js +8 -0
  61. package/dist/shared/actions/typesetAction.d.ts +26 -0
  62. package/dist/shared/actions/typesetAction.d.ts.map +1 -0
  63. package/dist/shared/actions/typesetAction.js +70 -0
  64. package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
  65. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
  66. package/dist/shared/extensions/MathLiveEditor.js +239 -0
  67. package/dist/shared/index.d.ts +11 -0
  68. package/dist/shared/index.d.ts.map +1 -0
  69. package/dist/shared/index.js +15 -0
  70. package/dist/shared/utils/eventHelpers.d.ts +18 -0
  71. package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
  72. package/dist/shared/utils/eventHelpers.js +30 -0
  73. package/dist/shared/utils/pairHelpers.d.ts +55 -0
  74. package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
  75. package/dist/shared/utils/pairHelpers.js +76 -0
  76. package/dist/shared/utils/touchDragHelper.d.ts +33 -0
  77. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
  78. package/dist/shared/utils/touchDragHelper.js +168 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
  80. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
  81. package/dist/shared/utils/webComponentHelpers.js +26 -0
  82. package/package.json +93 -0
  83. package/src/index.ts +213 -0
  84. package/src/plugins/associate/AssociateInteraction.svelte +273 -0
  85. package/src/plugins/associate/index.ts +9 -0
  86. package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
  87. package/src/plugins/choice/index.ts +9 -0
  88. package/src/plugins/custom/CustomInteraction.svelte +61 -0
  89. package/src/plugins/custom/index.ts +9 -0
  90. package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
  91. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
  92. package/src/plugins/end-attempt/index.ts +9 -0
  93. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
  94. package/src/plugins/extended-text/index.ts +9 -0
  95. package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
  96. package/src/plugins/gap-match/index.ts +9 -0
  97. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
  98. package/src/plugins/graphic-associate/index.ts +9 -0
  99. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
  100. package/src/plugins/graphic-gap-match/index.ts +9 -0
  101. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
  102. package/src/plugins/graphic-order/index.ts +9 -0
  103. package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
  104. package/src/plugins/hotspot/index.ts +9 -0
  105. package/src/plugins/hottext/HottextInteraction.svelte +296 -0
  106. package/src/plugins/hottext/index.ts +9 -0
  107. package/src/plugins/index.ts +31 -0
  108. package/src/plugins/match/MatchInteraction.svelte +70 -0
  109. package/src/plugins/match/index.ts +9 -0
  110. package/src/plugins/media/MediaInteraction.svelte +213 -0
  111. package/src/plugins/media/index.ts +9 -0
  112. package/src/plugins/order/OrderInteraction.svelte +159 -0
  113. package/src/plugins/order/index.ts +9 -0
  114. package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
  115. package/src/plugins/position-object/README.md +130 -0
  116. package/src/plugins/position-object/index.ts +9 -0
  117. package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
  118. package/src/plugins/select-point/index.ts +9 -0
  119. package/src/plugins/slider/SliderInteraction.svelte +141 -0
  120. package/src/plugins/slider/index.ts +9 -0
  121. package/src/plugins/upload/UploadInteraction.svelte +59 -0
  122. package/src/shared/actions/typesetAction.ts +87 -0
  123. package/src/shared/components/CustomInteractionFallback.svelte +153 -0
  124. package/src/shared/components/DragHandle.svelte +44 -0
  125. package/src/shared/components/DrawingCanvas.svelte +243 -0
  126. package/src/shared/components/FileUpload.svelte +153 -0
  127. package/src/shared/components/GraphicGapMatch.svelte +316 -0
  128. package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
  129. package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
  130. package/src/shared/components/MatchDragDrop.svelte +434 -0
  131. package/src/shared/components/MathContent.svelte +18 -0
  132. package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
  133. package/src/shared/components/RichTextEditor.svelte +316 -0
  134. package/src/shared/components/ShadowBaseStyles.svelte +391 -0
  135. package/src/shared/components/SortableList.svelte +297 -0
  136. package/src/shared/extensions/MathLiveEditor.ts +304 -0
  137. package/src/shared/index.ts +17 -0
  138. package/src/shared/styles/shared.css +16 -0
  139. package/src/shared/utils/eventHelpers.ts +36 -0
  140. package/src/shared/utils/pairHelpers.ts +86 -0
  141. package/src/shared/utils/touchDragHelper.ts +211 -0
  142. package/src/shared/utils/webComponentHelpers.ts +27 -0
  143. package/src/svelte-shims.d.ts +9 -0
  144. package/svelte.config.js +9 -0
  145. package/tests/index.test.ts +8 -0
  146. package/tsconfig.json +20 -0
@@ -0,0 +1,427 @@
1
+ <svelte:options customElement="pie-qti-graphic-associate" />
2
+
3
+ <script lang="ts">
4
+ import type { GraphicAssociateInteractionData } from '@pie-qti/item-player';
5
+ import type { I18nProvider } from '@pie-qti/i18n';
6
+ import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
+ import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
8
+ import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
9
+
10
+ interface Props {
11
+ interaction?: GraphicAssociateInteractionData | string;
12
+ response?: string[] | null;
13
+ correctResponse?: string[] | null;
14
+ disabled?: boolean;
15
+ role?: string;
16
+ i18n?: I18nProvider;
17
+ onChange?: (value: string[]) => void;
18
+ }
19
+
20
+ let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
21
+
22
+ // Parse props that may be JSON strings (web component usage)
23
+ const parsedInteraction = $derived(parseJsonProp<GraphicAssociateInteractionData>(interaction));
24
+ const parsedResponse = $derived(parseJsonProp<string[]>(response));
25
+ const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
26
+ const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
27
+ const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
28
+
29
+ // Get reference to the root element for event dispatching
30
+ let rootElement: HTMLDivElement | undefined = $state();
31
+
32
+ // Pairs are stored as "ID1 ID2" strings (space-separated)
33
+ let pairs = $state<string[]>([]);
34
+ let selectedHotspot: string | null = $state(null);
35
+ let imageContainer: HTMLDivElement | null = $state(null);
36
+ let imageElement: HTMLElement | null = $state(null);
37
+
38
+ const canInteract = $derived(!disabled);
39
+ const canAddMore = $derived(!parsedInteraction || pairs.length < parsedInteraction.maxAssociations);
40
+
41
+ $effect(() => {
42
+ // Sync with parent response changes
43
+ pairs = parsedResponse ? [...parsedResponse] : [];
44
+ });
45
+
46
+ function handleHotspotClick(hotspotId: string) {
47
+ if (!canInteract || !parsedInteraction) return;
48
+
49
+ const hotspot = parsedInteraction.associableHotspots.find((h) => h.identifier === hotspotId);
50
+ if (!hotspot) return;
51
+
52
+ // Count how many times this hotspot is already used
53
+ const usageCount = pairs.filter((pair) => pair.includes(hotspotId)).length;
54
+ if (usageCount >= hotspot.matchMax) {
55
+ // This hotspot is at its maximum connections
56
+ return;
57
+ }
58
+
59
+ if (!selectedHotspot) {
60
+ // First selection
61
+ selectedHotspot = hotspotId;
62
+ } else if (selectedHotspot === hotspotId) {
63
+ // Clicking the same hotspot deselects it
64
+ selectedHotspot = null;
65
+ } else {
66
+ // Second selection - create a pair
67
+ if (!canAddMore) return;
68
+
69
+ const newPair = `${selectedHotspot} ${hotspotId}`;
70
+ pairs = [...pairs, newPair];
71
+ response = pairs;
72
+ // Call onChange callback if provided (for Svelte component usage)
73
+ onChange?.(pairs);
74
+ // Dispatch custom event for web component usage - event will bubble up to the host element
75
+ if (rootElement) {
76
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, pairs));
77
+ }
78
+ selectedHotspot = null;
79
+ }
80
+ }
81
+
82
+ function removePair(index: number) {
83
+ if (!canInteract) return;
84
+ pairs = pairs.filter((_, i) => i !== index);
85
+ response = pairs;
86
+ // Call onChange callback if provided (for Svelte component usage)
87
+ onChange?.(pairs);
88
+ // Dispatch custom event for web component usage - event will bubble up to the host element
89
+ if (rootElement) {
90
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, pairs));
91
+ }
92
+ }
93
+
94
+ function getHotspotById(id: string) {
95
+ return parsedInteraction?.associableHotspots.find((h) => h.identifier === id);
96
+ }
97
+
98
+ function isHotspotSelected(id: string): boolean {
99
+ return selectedHotspot === id;
100
+ }
101
+
102
+ function getHotspotUsageCount(id: string): number {
103
+ return pairs.filter((pair) => pair.includes(id)).length;
104
+ }
105
+
106
+ function isHotspotMaxed(id: string): boolean {
107
+ const hotspot = getHotspotById(id);
108
+ if (!hotspot) return false;
109
+ return getHotspotUsageCount(id) >= hotspot.matchMax;
110
+ }
111
+
112
+ function isCorrectPair(id1: string, id2: string): boolean {
113
+ if (!isShowingCorrect) return false;
114
+ return correctPairs.some((p) => p === `${id1} ${id2}` || p === `${id2} ${id1}`);
115
+ }
116
+
117
+ function isHotspotInCorrectPair(id: string): boolean {
118
+ if (!isShowingCorrect) return false;
119
+ return correctPairs.some((p) => p.includes(id));
120
+ }
121
+
122
+ // Calculate center point of a hotspot for visual connections
123
+ function getHotspotCenter(coords: string, shape: string): { x: number; y: number } {
124
+ const parts = coords.split(',').map(Number);
125
+ if (shape === 'rect') {
126
+ // rect: x1,y1,x2,y2
127
+ return {
128
+ x: (parts[0] + parts[2]) / 2,
129
+ y: (parts[1] + parts[3]) / 2,
130
+ };
131
+ } else if (shape === 'circle') {
132
+ // circle: cx,cy,r
133
+ return { x: parts[0], y: parts[1] };
134
+ }
135
+ // Default fallback
136
+ return { x: parts[0] || 0, y: parts[1] || 0 };
137
+ }
138
+ </script>
139
+
140
+ <ShadowBaseStyles />
141
+
142
+ <div bind:this={rootElement} part="root" class="qti-graphic-associate-interaction">
143
+ {#if !parsedInteraction}
144
+ <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
145
+ {:else}
146
+ {#if parsedInteraction.prompt}
147
+ <p part="prompt" class="qti-ga-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
148
+ {/if}
149
+
150
+ <div part="layout" class="qti-ga-layout flex flex-col lg:flex-row gap-4">
151
+ <!-- Image with Hotspots -->
152
+ <div part="image-area" class="qti-ga-image-area flex-1">
153
+ <div
154
+ bind:this={imageContainer}
155
+ part="stage"
156
+ class="qti-ga-stage relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200"
157
+ style="width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
158
+ >
159
+ {#if parsedInteraction.imageData}
160
+ {#if parsedInteraction.imageData.type === 'svg' && parsedInteraction.imageData.content}
161
+ <div
162
+ bind:this={imageElement}
163
+ class="w-full h-full"
164
+ >
165
+ {@html parsedInteraction.imageData.content}
166
+ </div>
167
+ {:else if parsedInteraction.imageData.src}
168
+ <img
169
+ bind:this={imageElement}
170
+ src={parsedInteraction.imageData.src}
171
+ alt={i18n?.t('interactions.associate.altText') ?? 'Association diagram'}
172
+ class="w-full h-full object-contain"
173
+ />
174
+ {/if}
175
+ {/if}
176
+
177
+ <!-- SVG overlay for drawing connection lines -->
178
+ <svg
179
+ part="overlay"
180
+ class="qti-ga-overlay absolute inset-0 w-full h-full pointer-events-none"
181
+ style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 10;"
182
+ >
183
+ {#each pairs as pair, index}
184
+ {@const [id1, id2] = pair.split(' ')}
185
+ {@const hotspot1 = getHotspotById(id1)}
186
+ {@const hotspot2 = getHotspotById(id2)}
187
+ {#if hotspot1 && hotspot2}
188
+ {@const center1 = getHotspotCenter(hotspot1.coords, hotspot1.shape)}
189
+ {@const center2 = getHotspotCenter(hotspot2.coords, hotspot2.shape)}
190
+ {@const isCorrect = isCorrectPair(id1, id2)}
191
+ <line
192
+ x1={center1.x}
193
+ y1={center1.y}
194
+ x2={center2.x}
195
+ y2={center2.y}
196
+ stroke={isCorrect ? 'var(--color-success, oklch(76% 0.177 163.223))' : 'var(--color-primary, oklch(45% 0.24 277))'}
197
+ stroke-width="3"
198
+ stroke-linecap="round"
199
+ />
200
+ {/if}
201
+ {/each}
202
+ {#if isShowingCorrect}
203
+ {#each correctPairs as pair}
204
+ {@const [id1, id2] = pair.split(' ')}
205
+ {@const hotspot1 = getHotspotById(id1)}
206
+ {@const hotspot2 = getHotspotById(id2)}
207
+ {@const isInUserPairs = pairs.some((p) => p === pair || p === `${id2} ${id1}`)}
208
+ {#if hotspot1 && hotspot2 && !isInUserPairs}
209
+ {@const center1 = getHotspotCenter(hotspot1.coords, hotspot1.shape)}
210
+ {@const center2 = getHotspotCenter(hotspot2.coords, hotspot2.shape)}
211
+ <line
212
+ x1={center1.x}
213
+ y1={center1.y}
214
+ x2={center2.x}
215
+ y2={center2.y}
216
+ stroke="var(--color-success, oklch(76% 0.177 163.223))"
217
+ stroke-width="2"
218
+ stroke-dasharray="4,4"
219
+ stroke-linecap="round"
220
+ opacity="0.6"
221
+ />
222
+ {/if}
223
+ {/each}
224
+ {/if}
225
+ </svg>
226
+
227
+ <!-- Clickable hotspot areas -->
228
+ {#each parsedInteraction.associableHotspots as hotspot}
229
+ {@const isSelected = isHotspotSelected(hotspot.identifier)}
230
+ {@const isMaxed = isHotspotMaxed(hotspot.identifier)}
231
+ {@const usageCount = getHotspotUsageCount(hotspot.identifier)}
232
+ {@const isCorrect = isHotspotInCorrectPair(hotspot.identifier)}
233
+
234
+ {#if hotspot.shape === 'rect'}
235
+ {@const [x1, y1, x2, y2] = hotspot.coords.split(',').map(Number)}
236
+ <button
237
+ part="hotspot"
238
+ class="qti-ga-hotspot absolute border-2 transition-all {isSelected
239
+ ? 'bg-primary/40 border-primary border-4'
240
+ : isCorrect
241
+ ? 'bg-success/20 border-success'
242
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed
243
+ ? 'opacity-50 cursor-not-allowed'
244
+ : canInteract
245
+ ? 'cursor-pointer'
246
+ : 'cursor-not-allowed opacity-70'}"
247
+ style="left: {x1}px; top: {y1}px; width: {x2 - x1}px; height: {y2 -
248
+ y1}px; z-index: 20;"
249
+ onclick={() => handleHotspotClick(hotspot.identifier)}
250
+ disabled={!canInteract || isMaxed}
251
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : ''}"
252
+ >
253
+ <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
254
+ </button>
255
+ {:else if hotspot.shape === 'circle'}
256
+ {@const [cx, cy, r] = hotspot.coords.split(',').map(Number)}
257
+ <button
258
+ part="hotspot"
259
+ class="qti-ga-hotspot qti-ga-hotspot-circle absolute rounded-full border-2 flex items-center justify-center transition-all {isSelected
260
+ ? 'bg-primary/40 border-primary border-4'
261
+ : isCorrect
262
+ ? 'bg-success/20 border-success'
263
+ : 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed
264
+ ? 'opacity-50 cursor-not-allowed'
265
+ : canInteract
266
+ ? 'cursor-pointer'
267
+ : 'cursor-not-allowed opacity-70'}"
268
+ style="left: {cx - r}px; top: {cy - r}px; width: {r * 2}px; height: {r *
269
+ 2}px; z-index: 20;"
270
+ onclick={() => handleHotspotClick(hotspot.identifier)}
271
+ disabled={!canInteract || isMaxed}
272
+ aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : ''}"
273
+ >
274
+ <span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
275
+ </button>
276
+ {/if}
277
+ {/each}
278
+ </div>
279
+
280
+ {#if selectedHotspot}
281
+ <div class="alert alert-info mt-2">
282
+ <svg
283
+ xmlns="http://www.w3.org/2000/svg"
284
+ fill="none"
285
+ viewBox="0 0 24 24"
286
+ part="selected-icon"
287
+ class="qti-icon stroke-current shrink-0 w-6 h-6"
288
+ >
289
+ <path
290
+ stroke-linecap="round"
291
+ stroke-linejoin="round"
292
+ stroke-width="2"
293
+ d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
294
+ ></path>
295
+ </svg>
296
+ <span>
297
+ {@html i18n?.t('interactions.associate.selectAnotherHotspot', { label: getHotspotById(selectedHotspot)?.label }) ?? `Selected: <strong>${getHotspotById(selectedHotspot)?.label}</strong>. Click another hotspot to create an association.`}
298
+ </span>
299
+ </div>
300
+ {/if}
301
+ </div>
302
+
303
+ <!-- Associations List -->
304
+ <div part="panel" class="qti-ga-panel w-full lg:w-80">
305
+ <div class="qti-ga-card card bg-base-100 border border-base-300">
306
+ <div class="qti-ga-card-body card-body p-4">
307
+ <h3 class="card-title text-sm">
308
+ Associations ({pairs.length}/{parsedInteraction.maxAssociations})
309
+ </h3>
310
+
311
+ {#if pairs.length === 0}
312
+ <p class="text-sm text-base-content/60">
313
+ Click two hotspots on the image to create an association.
314
+ </p>
315
+ {:else}
316
+ <div class="space-y-2">
317
+ {#each pairs as pair, index}
318
+ {@const [id1, id2] = pair.split(' ')}
319
+ {@const hotspot1 = getHotspotById(id1)}
320
+ {@const hotspot2 = getHotspotById(id2)}
321
+ {@const isCorrect = isCorrectPair(id1, id2)}
322
+ <div
323
+ class="flex items-center gap-2 p-2 rounded-lg bg-base-200 border border-base-300 {isCorrect ? 'border-success bg-success/10' : ''}"
324
+ >
325
+ <div class="badge badge-sm {isCorrect ? 'badge-success' : 'badge-primary'}">{index + 1}</div>
326
+ <div class="flex-1 text-sm">
327
+ <span class="font-medium">{hotspot1?.label}</span>
328
+ <span class="mx-1">↔</span>
329
+ <span class="font-medium">{hotspot2?.label}</span>
330
+ </div>
331
+ {#if canInteract}
332
+ <button
333
+ class="btn btn-xs btn-ghost btn-circle"
334
+ onclick={() => removePair(index)}
335
+ aria-label={i18n?.t('interactions.associate.removeAssociation') ?? 'Remove association'}
336
+ >
337
+ <svg
338
+ xmlns="http://www.w3.org/2000/svg"
339
+ part="remove-icon"
340
+ class="qti-icon-sm h-4 w-4"
341
+ fill="none"
342
+ viewBox="0 0 24 24"
343
+ stroke="currentColor"
344
+ >
345
+ <path
346
+ stroke-linecap="round"
347
+ stroke-linejoin="round"
348
+ stroke-width="2"
349
+ d="M6 18L18 6M6 6l12 12"
350
+ />
351
+ </svg>
352
+ </button>
353
+ {/if}
354
+ </div>
355
+ {/each}
356
+ </div>
357
+ {/if}
358
+
359
+ {#if parsedInteraction.minAssociations > 0}
360
+ <div class="text-xs text-base-content/60 mt-2">
361
+ Minimum required: {parsedInteraction.minAssociations}
362
+ </div>
363
+ {/if}
364
+ </div>
365
+ </div>
366
+ </div>
367
+ </div>
368
+ {/if}
369
+ </div>
370
+
371
+ <style>
372
+ /* Ensure proper clickable areas */
373
+ :global(.qti-graphic-associate-interaction button) {
374
+ min-height: unset;
375
+ }
376
+
377
+ /* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
378
+ .qti-icon {
379
+ width: 1.5rem;
380
+ height: 1.5rem;
381
+ flex: 0 0 auto;
382
+ }
383
+ .qti-icon-sm {
384
+ width: 1rem;
385
+ height: 1rem;
386
+ flex: 0 0 auto;
387
+ }
388
+
389
+ /* Minimal layout so this works without Tailwind utilities */
390
+ .qti-ga-layout {
391
+ display: flex;
392
+ gap: 1rem;
393
+ flex-wrap: wrap;
394
+ }
395
+ .qti-ga-image-area {
396
+ flex: 1 1 520px;
397
+ min-width: 280px;
398
+ }
399
+ .qti-ga-stage {
400
+ position: relative;
401
+ border-radius: 0.75rem;
402
+ overflow: hidden;
403
+ border: 2px solid var(--color-base-300, oklch(95% 0 0));
404
+ background: var(--color-base-200, oklch(98% 0 0));
405
+ }
406
+ /* Critical: overlay must be absolutely positioned even without Tailwind utilities */
407
+ .qti-ga-overlay {
408
+ position: absolute;
409
+ inset: 0;
410
+ }
411
+ /* Critical: hotspot buttons are absolutely positioned via inline styles; ensure `position:absolute` exists */
412
+ .qti-ga-hotspot {
413
+ position: absolute;
414
+ }
415
+ .qti-ga-panel {
416
+ flex: 0 0 20rem;
417
+ min-width: 18rem;
418
+ }
419
+ .qti-ga-card {
420
+ border: 1px solid var(--color-base-300, oklch(95% 0 0));
421
+ border-radius: 0.75rem;
422
+ background: var(--color-base-100, oklch(100% 0 0));
423
+ }
424
+ .qti-ga-card-body {
425
+ padding: 1rem;
426
+ }
427
+ </style>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'graphicAssociateInteraction',
5
+ tagName: 'pie-qti-graphic-associate',
6
+ name: 'default-graphic-associate',
7
+ description: 'Default Svelte-based graphic associate interaction',
8
+ priority: 0,
9
+ };