@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,316 @@
1
+ <script lang="ts">
2
+ /**
3
+ * Graphic Gap Match component for graphicGapMatchInteraction
4
+ * Drag labels onto specific areas of an image/diagram
5
+ * Supports keyboard, mouse, and touch interactions
6
+ */
7
+
8
+ import type { I18nProvider } from '@pie-qti/i18n';
9
+ import { createOrUpdatePair, getSourceForTarget, getTargetForSource, removePairBySource } from '../utils/pairHelpers.js';
10
+ import { touchDrag } from '../utils/touchDragHelper.js';
11
+ import '../styles/shared.css';
12
+
13
+ interface GapText {
14
+ identifier: string;
15
+ text: string;
16
+ matchMax: number;
17
+ }
18
+
19
+ interface Hotspot {
20
+ identifier: string;
21
+ shape: 'circle' | 'rect' | 'poly';
22
+ coords: string;
23
+ matchMax: number;
24
+ }
25
+
26
+ interface Props {
27
+ gapTexts: GapText[];
28
+ hotspots: Hotspot[];
29
+ pairs: string[]; // Array of "gapTextId hotspotId" pairs
30
+ imageData: string; // SVG or image data
31
+ imageWidth: string;
32
+ imageHeight: string;
33
+ disabled?: boolean;
34
+ i18n?: I18nProvider;
35
+ onPairsChange: (newPairs: string[]) => void;
36
+ }
37
+
38
+ const { gapTexts, hotspots, pairs, imageData, imageWidth, imageHeight, disabled = false, i18n, onPairsChange }: Props = $props();
39
+
40
+ // Reactive translations
41
+ const translations = $derived({
42
+ keyboardInstructions: i18n?.t('interactions.graphicGapMatch.keyboardInstructions') ?? 'interactions.graphicGapMatch.keyboardInstructions',
43
+ availableLabel: i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'interactions.graphicGapMatch.availableLabel',
44
+ availableHeading: i18n?.t('interactions.graphicGapMatch.availableHeading') ?? 'interactions.graphicGapMatch.availableHeading',
45
+ alreadyPlaced: i18n?.t('interactions.graphicGapMatch.alreadyPlaced') ?? 'interactions.graphicGapMatch.alreadyPlaced',
46
+ selectedForPlacement: i18n?.t('interactions.graphicGapMatch.selectedForPlacement') ?? 'interactions.graphicGapMatch.selectedForPlacement',
47
+ pressSpaceToSelect: i18n?.t('interactions.graphicGapMatch.pressSpaceToSelect') ?? 'interactions.graphicGapMatch.pressSpaceToSelect',
48
+ pressSpaceToPlace: i18n?.t('interactions.graphicGapMatch.pressSpaceToPlace') ?? 'interactions.graphicGapMatch.pressSpaceToPlace',
49
+ removeFromHotspot: (label: string) => i18n?.t('interactions.graphicGapMatch.removeFromHotspot', { label }) ?? `interactions.graphicGapMatch.removeFromHotspot (${label})`,
50
+ hotspot: (number: number) => i18n?.t('interactions.graphicGapMatch.hotspot', { number }) ?? `interactions.graphicGapMatch.hotspot (${number})`,
51
+ contains: (label: string) => i18n?.t('interactions.graphicGapMatch.contains', { label }) ?? `interactions.graphicGapMatch.contains (${label})`,
52
+ });
53
+
54
+ let draggedTextId = $state<string | null>(null);
55
+ let hoveredHotspotId = $state<string | null>(null);
56
+ let keyboardSelectedTextId = $state<string | null>(null); // Gap text selected via keyboard
57
+ let announceText = $state<string>(''); // For screen reader announcements
58
+
59
+ function handleDragStart(gapTextId: string) {
60
+ if (disabled) return;
61
+ draggedTextId = gapTextId;
62
+ }
63
+
64
+ function handleDragEnd() {
65
+ draggedTextId = null;
66
+ hoveredHotspotId = null;
67
+ }
68
+
69
+ function handleHotspotDragOver(event: DragEvent, hotspotId: string) {
70
+ if (disabled || !draggedTextId) return;
71
+ event.preventDefault();
72
+ hoveredHotspotId = hotspotId;
73
+ }
74
+
75
+ function handleHotspotDragLeave() {
76
+ hoveredHotspotId = null;
77
+ }
78
+
79
+ function handleHotspotDrop(event: DragEvent, hotspotId: string) {
80
+ if (disabled || !draggedTextId) return;
81
+ event.preventDefault();
82
+
83
+ const newPairs = createOrUpdatePair(pairs, draggedTextId, hotspotId);
84
+ onPairsChange(newPairs);
85
+ draggedTextId = null;
86
+ hoveredHotspotId = null;
87
+ }
88
+
89
+ function clearMatch(gapTextId: string) {
90
+ if (disabled) return;
91
+ const gapTextObj = gapTexts.find((g) => g.identifier === gapTextId);
92
+ const gapTextName = gapTextObj?.text || 'Label';
93
+
94
+ const newPairs = removePairBySource(pairs, gapTextId);
95
+ onPairsChange(newPairs);
96
+
97
+ announceText = `${gapTextName} removed from hotspot`;
98
+ }
99
+
100
+ // Keyboard handlers for gap texts (labels)
101
+ function handleGapTextKeyDown(event: KeyboardEvent, gapTextId: string) {
102
+ if (disabled) return;
103
+
104
+ const gapTextObj = gapTexts.find((g) => g.identifier === gapTextId);
105
+ const gapTextName = gapTextObj?.text || 'Label';
106
+
107
+ if (event.key === ' ' || event.key === 'Enter') {
108
+ event.preventDefault();
109
+
110
+ if (keyboardSelectedTextId === gapTextId) {
111
+ // Deselect
112
+ keyboardSelectedTextId = null;
113
+ announceText = `${gapTextName} deselected`;
114
+ } else {
115
+ // Select this gap text for placement
116
+ keyboardSelectedTextId = gapTextId;
117
+ announceText = `${gapTextName} selected. Navigate to a hotspot and press Space or Enter to place.`;
118
+ }
119
+ } else if (event.key === 'Escape' && keyboardSelectedTextId) {
120
+ event.preventDefault();
121
+ keyboardSelectedTextId = null;
122
+ announceText = `Selection cancelled`;
123
+ }
124
+ }
125
+
126
+ // Keyboard handlers for hotspots
127
+ function handleHotspotKeyDown(event: KeyboardEvent, hotspotId: string) {
128
+ if (disabled || !keyboardSelectedTextId) return;
129
+
130
+ const hotspotIndex = hotspots.findIndex((h) => h.identifier === hotspotId);
131
+ const gapTextObj = gapTexts.find((g) => g.identifier === keyboardSelectedTextId);
132
+ const gapTextName = gapTextObj?.text || 'Label';
133
+
134
+ if (event.key === ' ' || event.key === 'Enter') {
135
+ event.preventDefault();
136
+
137
+ // Create match
138
+ const newPairs = createOrUpdatePair(pairs, keyboardSelectedTextId!, hotspotId);
139
+ onPairsChange(newPairs);
140
+ announceText = `${gapTextName} placed on hotspot ${hotspotIndex + 1}`;
141
+ keyboardSelectedTextId = null;
142
+ }
143
+ }
144
+
145
+ // Parse coords based on shape
146
+ function parseCoords(hotspot: Hotspot): { x: number; y: number; width: number; height: number } {
147
+ const coords = hotspot.coords.split(',').map(Number);
148
+ if (hotspot.shape === 'circle') {
149
+ const [cx, cy, r] = coords;
150
+ return { x: cx - r, y: cy - r, width: r * 2, height: r * 2 };
151
+ } else if (hotspot.shape === 'rect') {
152
+ const [x, y, width, height] = coords;
153
+ return { x, y, width, height };
154
+ }
155
+ // For poly, use bounding box (simplified)
156
+ return { x: coords[0], y: coords[1], width: 40, height: 40 };
157
+ }
158
+ </script>
159
+
160
+ <!-- Screen reader announcements -->
161
+ <div aria-live="polite" aria-atomic="true" class="sr-only">
162
+ {announceText}
163
+ </div>
164
+
165
+ <!-- Instructions for keyboard users -->
166
+ <div id="graphic-gap-match-instructions" class="sr-only">
167
+ Press Space or Enter to select a label. Tab to navigate to hotspots on the image. Press Space or Enter on a hotspot to place the label. Press Escape to cancel selection.
168
+ </div>
169
+
170
+ <div class="space-y-4" role="region" aria-describedby="graphic-gap-match-instructions">
171
+ <!-- Draggable gap texts (labels) -->
172
+ <div class="flex flex-wrap gap-2 p-4 bg-base-200 rounded-lg border-2 border-base-300" role="group" aria-label={i18n?.t('interactions.graphicGapMatch.availableLabel') ?? 'Available labels to place'}>
173
+ <div class="w-full text-sm text-base-content/70 font-semibold mb-2">{i18n?.t('interactions.graphicGapMatch.availableHeading') ?? 'Available Labels:'}</div>
174
+ {#each gapTexts as gapText (gapText.identifier)}
175
+ {@const matchedHotspot = getTargetForSource(pairs, gapText.identifier)}
176
+ {@const isDragged = draggedTextId === gapText.identifier}
177
+ {@const isSelected = keyboardSelectedTextId === gapText.identifier}
178
+
179
+ <div class="inline-flex items-center gap-1">
180
+ <button
181
+ type="button"
182
+ draggable={!disabled && !matchedHotspot}
183
+ use:touchDrag
184
+ ondragstart={() => handleDragStart(gapText.identifier)}
185
+ ondragend={handleDragEnd}
186
+ onkeydown={(e) => handleGapTextKeyDown(e, gapText.identifier)}
187
+ disabled={disabled || !!matchedHotspot}
188
+ aria-pressed={isSelected}
189
+ aria-label="{gapText.text}{matchedHotspot ? '. Already placed on hotspot' : ''}{isSelected ? '. Selected for placement' : '. Press Space to select'}"
190
+ class="btn btn-md font-medium transition-all"
191
+ class:btn-primary={!matchedHotspot && !isSelected}
192
+ class:btn-accent={isSelected}
193
+ class:btn-success={matchedHotspot}
194
+ class:cursor-grab={!disabled && !matchedHotspot && !isSelected}
195
+ class:cursor-not-allowed={disabled}
196
+ class:opacity-70={disabled || isDragged}
197
+ class:contrast-125={matchedHotspot}
198
+ class:saturate-150={matchedHotspot}
199
+ >
200
+ {gapText.text}
201
+ </button>
202
+ {#if matchedHotspot && !disabled}
203
+ <button
204
+ type="button"
205
+ class="btn btn-sm btn-circle btn-error"
206
+ onclick={() => clearMatch(gapText.identifier)}
207
+ aria-label="Remove {gapText.text} from hotspot"
208
+ title={i18n?.t('interactions.graphicGapMatch.removeLabel') ?? 'Remove label'}
209
+ >
210
+ ✕
211
+ </button>
212
+ {/if}
213
+ </div>
214
+ {/each}
215
+ </div>
216
+
217
+ <!-- Image/diagram with hotspot drop zones -->
218
+ <div class="relative inline-block border-2 border-base-300 rounded-lg" style="width: {imageWidth}px; height: {imageHeight}px;">
219
+ <!-- SVG image -->
220
+ {@html imageData}
221
+
222
+ <!-- Overlay with hotspot drop zones -->
223
+ <svg
224
+ class="absolute top-0 left-0 w-full h-full pointer-events-none"
225
+ style="pointer-events: none; top: 0; left: 0;"
226
+ viewBox="0 0 {imageWidth} {imageHeight}"
227
+ >
228
+ {#each hotspots as hotspot (hotspot.identifier)}
229
+ {@const coords = parseCoords(hotspot)}
230
+ {@const matchedGapText = getSourceForTarget(pairs, hotspot.identifier)}
231
+ {@const gapTextObj = matchedGapText ? gapTexts.find((g) => g.identifier === matchedGapText) : null}
232
+ {@const isHovered = hoveredHotspotId === hotspot.identifier}
233
+
234
+ <g>
235
+ <!-- Hotspot drop zone -->
236
+ {#if hotspot.shape === 'circle'}
237
+ {@const [cx, cy, r] = hotspot.coords.split(',').map(Number)}
238
+ {@const hotspotIndex = hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
239
+ <circle
240
+ role="button"
241
+ tabindex={disabled || !keyboardSelectedTextId ? -1 : 0}
242
+ aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : '. Available'}{keyboardSelectedTextId ? '. Press Space or Enter to place label' : ''}"
243
+ cx={cx}
244
+ cy={cy}
245
+ r={r}
246
+ fill={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
247
+ fill-opacity={matchedGapText ? '0.3' : isHovered ? '0.2' : '0'}
248
+ stroke={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
249
+ stroke-width="2"
250
+ stroke-dasharray={matchedGapText ? '' : '4,4'}
251
+ class="transition-all"
252
+ style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
253
+ ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
254
+ ondragleave={handleHotspotDragLeave}
255
+ ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
256
+ onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
257
+ />
258
+ {:else if hotspot.shape === 'rect'}
259
+ {@const [x, y, width, height] = hotspot.coords.split(',').map(Number)}
260
+ {@const hotspotIndex = hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
261
+ <rect
262
+ role="button"
263
+ tabindex={disabled || !keyboardSelectedTextId ? -1 : 0}
264
+ aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : '. Available'}{keyboardSelectedTextId ? '. Press Space or Enter to place label' : ''}"
265
+ x={x}
266
+ y={y}
267
+ width={width}
268
+ height={height}
269
+ fill={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
270
+ fill-opacity={matchedGapText ? '0.3' : isHovered ? '0.2' : '0'}
271
+ stroke={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
272
+ stroke-width="2"
273
+ stroke-dasharray={matchedGapText ? '' : '4,4'}
274
+ class="transition-all"
275
+ style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
276
+ ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
277
+ ondragleave={handleHotspotDragLeave}
278
+ ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
279
+ onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
280
+ />
281
+ {/if}
282
+
283
+ <!-- Label text on hotspot if matched -->
284
+ {#if matchedGapText && gapTextObj}
285
+ {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
286
+ <text
287
+ x={cx}
288
+ y={cy}
289
+ text-anchor="middle"
290
+ dominant-baseline="middle"
291
+ class="font-bold pointer-events-none"
292
+ fill="#059669"
293
+ font-size="14"
294
+ >
295
+ {gapTextObj.text}
296
+ </text>
297
+ {/if}
298
+ </g>
299
+ {/each}
300
+ </svg>
301
+ </div>
302
+ </div>
303
+
304
+ <style>
305
+ [draggable='true'] {
306
+ touch-action: none;
307
+ }
308
+
309
+ /* Ensure SVG fills its container */
310
+ svg {
311
+ width: 100%;
312
+ height: 100%;
313
+ display: block;
314
+ }
315
+
316
+ </style>
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ /**
3
+ * Adapter component that transforms standard interaction props into GraphicGapMatch-specific props
4
+ * This allows GraphicGapMatch to be used in the generic component rendering system
5
+ */
6
+ import type { GraphicGapMatchInteractionData } from '@pie-qti/item-player';
7
+ import GraphicGapMatch from './GraphicGapMatch.svelte';
8
+
9
+ interface Props {
10
+ interaction: GraphicGapMatchInteractionData;
11
+ response: string[] | null;
12
+ disabled?: boolean;
13
+ typeset?: (element: HTMLElement) => void;
14
+ onChange: (value: string[]) => void;
15
+ }
16
+
17
+ const { interaction, response = null, disabled = false, typeset, onChange }: Props = $props();
18
+
19
+ // Transform response format: string[] to the pairs format GraphicGapMatch expects
20
+ const pairs = $derived(response ?? []);
21
+
22
+ function handlePairsChange(newPairs: string[]) {
23
+ onChange(newPairs);
24
+ }
25
+ </script>
26
+
27
+ <GraphicGapMatch
28
+ gapTexts={interaction.gapTexts}
29
+ hotspots={interaction.hotspots}
30
+ {pairs}
31
+ imageData={interaction.imageData?.content ?? ''}
32
+ imageWidth={interaction.imageData?.width ?? '600'}
33
+ imageHeight={interaction.imageData?.height ?? '500'}
34
+ {disabled}
35
+ onPairsChange={handlePairsChange}
36
+ />
@@ -0,0 +1,124 @@
1
+ <script lang="ts">
2
+ /**
3
+ * Component to render HTML with inline interactive elements (textEntry, inlineChoice)
4
+ * Uses a custom parsing approach to embed Svelte components within HTML
5
+ */
6
+ interface Props {
7
+ html: string;
8
+ interactions: any[];
9
+ responses: Record<string, any>;
10
+ onResponseChange: (responseId: string, value: any) => void;
11
+ }
12
+
13
+ let { html, interactions, responses, onResponseChange }: Props = $props();
14
+
15
+ // Parse HTML and extract inline interaction placeholders
16
+ interface ParsedSegment {
17
+ type: 'html' | 'textEntry' | 'inlineChoice';
18
+ content?: string;
19
+ interaction?: any;
20
+ }
21
+
22
+ const segments = $derived.by(() => {
23
+ const result: ParsedSegment[] = [];
24
+
25
+ let lastIndex = 0;
26
+ let match;
27
+
28
+ // Create a combined pattern to find all placeholders in order
29
+ const combinedPattern = /\[TEXTENTRY:([^\]]+)\]|\[INLINECHOICE:([^\]]+)\]/g;
30
+
31
+ while ((match = combinedPattern.exec(html)) !== null) {
32
+ // Add HTML before this match
33
+ if (match.index > lastIndex) {
34
+ result.push({
35
+ type: 'html',
36
+ content: html.substring(lastIndex, match.index),
37
+ });
38
+ }
39
+
40
+ // Determine which type of interaction this is
41
+ if (match[0].startsWith('[TEXTENTRY:')) {
42
+ const responseId = match[1];
43
+ const interaction = interactions.find((i) => i.responseId === responseId);
44
+ if (interaction) {
45
+ result.push({
46
+ type: 'textEntry',
47
+ interaction,
48
+ });
49
+ }
50
+ } else if (match[0].startsWith('[INLINECHOICE:')) {
51
+ const responseId = match[2];
52
+ const interaction = interactions.find((i) => i.responseId === responseId);
53
+ if (interaction) {
54
+ result.push({
55
+ type: 'inlineChoice',
56
+ interaction,
57
+ });
58
+ }
59
+ }
60
+
61
+ lastIndex = match.index + match[0].length;
62
+ }
63
+
64
+ // Add remaining HTML after last match
65
+ if (lastIndex < html.length) {
66
+ result.push({
67
+ type: 'html',
68
+ content: html.substring(lastIndex),
69
+ });
70
+ }
71
+
72
+ // If no matches found, just return the HTML as one segment
73
+ if (result.length === 0) {
74
+ result.push({
75
+ type: 'html',
76
+ content: html,
77
+ });
78
+ }
79
+
80
+ return result;
81
+ });
82
+ </script>
83
+
84
+ <div class="inline-interaction-container">
85
+ {#each segments as segment}
86
+ {#if segment.type === 'html'}
87
+ {@html segment.content}
88
+ {:else if segment.type === 'textEntry'}
89
+ <input
90
+ type="text"
91
+ class="input input-bordered input-sm inline-input"
92
+ style="width: {segment.interaction.expectedLength * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;"
93
+ placeholder="..."
94
+ aria-label={`Text entry ${segment.interaction.responseId}`}
95
+ value={responses[segment.interaction.responseId] || ''}
96
+ oninput={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
97
+ />
98
+ {:else if segment.type === 'inlineChoice'}
99
+ <select
100
+ class="select select-bordered select-sm inline-select"
101
+ style="display: inline-block; margin: 0 4px; width: auto; min-width: 120px;"
102
+ aria-label={`Inline choice ${segment.interaction.responseId}`}
103
+ value={responses[segment.interaction.responseId] || ''}
104
+ onchange={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
105
+ >
106
+ <option value="">Select...</option>
107
+ {#each segment.interaction.choices as choice}
108
+ <option value={choice.identifier}>{choice.text}</option>
109
+ {/each}
110
+ </select>
111
+ {/if}
112
+ {/each}
113
+ </div>
114
+
115
+ <style>
116
+ .inline-interaction-container :global(p) {
117
+ display: inline;
118
+ }
119
+
120
+ .inline-input,
121
+ .inline-select {
122
+ vertical-align: baseline;
123
+ }
124
+ </style>