@pie-qti/default-components 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/chunks/__vite-browser-external-BjvdLQIS.js +9 -0
  2. package/dist/chunks/__vite-browser-external-BjvdLQIS.js.map +1 -0
  3. package/dist/chunks/chunk-Bayd9M4T.js +20 -0
  4. package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-CAPebTxM.js} +245 -29
  5. package/dist/chunks/{mathlive.min-Bvtiaxg4.js.map → mathlive.min-CAPebTxM.js.map} +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/plugins/associate/index.d.ts +0 -1
  10. package/dist/plugins/associate/index.js +1 -0
  11. package/dist/plugins/associate/index.js.map +1 -0
  12. package/dist/plugins/choice/index.d.ts +0 -1
  13. package/dist/plugins/choice/index.js +1 -0
  14. package/dist/plugins/choice/index.js.map +1 -0
  15. package/dist/plugins/custom/index.d.ts +0 -1
  16. package/dist/plugins/custom/index.js +1 -0
  17. package/dist/plugins/custom/index.js.map +1 -0
  18. package/dist/plugins/end-attempt/index.d.ts +0 -1
  19. package/dist/plugins/end-attempt/index.js +1 -0
  20. package/dist/plugins/end-attempt/index.js.map +1 -0
  21. package/dist/plugins/extended-text/index.d.ts +0 -1
  22. package/dist/plugins/extended-text/index.js +1 -0
  23. package/dist/plugins/extended-text/index.js.map +1 -0
  24. package/dist/plugins/gap-match/index.d.ts +0 -1
  25. package/dist/plugins/gap-match/index.js +1 -0
  26. package/dist/plugins/gap-match/index.js.map +1 -0
  27. package/dist/plugins/graphic-associate/index.d.ts +0 -1
  28. package/dist/plugins/graphic-associate/index.js +1 -0
  29. package/dist/plugins/graphic-associate/index.js.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
  31. package/dist/plugins/graphic-gap-match/index.js +1 -0
  32. package/dist/plugins/graphic-gap-match/index.js.map +1 -0
  33. package/dist/plugins/graphic-order/index.d.ts +0 -1
  34. package/dist/plugins/graphic-order/index.js +1 -0
  35. package/dist/plugins/graphic-order/index.js.map +1 -0
  36. package/dist/plugins/hotspot/index.d.ts +0 -1
  37. package/dist/plugins/hotspot/index.js +1 -0
  38. package/dist/plugins/hotspot/index.js.map +1 -0
  39. package/dist/plugins/hottext/index.d.ts +0 -1
  40. package/dist/plugins/hottext/index.js +1 -0
  41. package/dist/plugins/hottext/index.js.map +1 -0
  42. package/dist/plugins/match/index.d.ts +0 -1
  43. package/dist/plugins/match/index.js +1 -0
  44. package/dist/plugins/match/index.js.map +1 -0
  45. package/dist/plugins/media/index.d.ts +0 -1
  46. package/dist/plugins/media/index.js +1 -0
  47. package/dist/plugins/media/index.js.map +1 -0
  48. package/dist/plugins/order/index.d.ts +0 -1
  49. package/dist/plugins/order/index.js +1 -0
  50. package/dist/plugins/order/index.js.map +1 -0
  51. package/dist/plugins/position-object/index.d.ts +0 -1
  52. package/dist/plugins/position-object/index.js +1 -0
  53. package/dist/plugins/position-object/index.js.map +1 -0
  54. package/dist/plugins/public-types.d.ts +5 -0
  55. package/dist/plugins/public-types.js +2 -0
  56. package/dist/plugins/public-types.js.map +1 -0
  57. package/dist/plugins/select-point/index.d.ts +0 -1
  58. package/dist/plugins/select-point/index.js +1 -0
  59. package/dist/plugins/select-point/index.js.map +1 -0
  60. package/dist/plugins/slider/index.d.ts +0 -1
  61. package/dist/plugins/slider/index.js +1 -0
  62. package/dist/plugins/slider/index.js.map +1 -0
  63. package/dist/plugins.js +25917 -7690
  64. package/dist/plugins.js.map +1 -1
  65. package/dist/shared/actions/typesetAction.d.ts +0 -1
  66. package/dist/shared/actions/typesetAction.js +1 -0
  67. package/dist/shared/actions/typesetAction.js.map +1 -0
  68. package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
  69. package/dist/shared/extensions/MathLiveEditor.js +1 -0
  70. package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
  71. package/dist/shared/index.d.ts +0 -1
  72. package/dist/shared/index.js +1 -0
  73. package/dist/shared/index.js.map +1 -0
  74. package/dist/shared/utils/eventHelpers.d.ts +0 -1
  75. package/dist/shared/utils/eventHelpers.js +1 -0
  76. package/dist/shared/utils/eventHelpers.js.map +1 -0
  77. package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
  78. package/dist/shared/utils/matchGroupUtils.js +1 -0
  79. package/dist/shared/utils/matchGroupUtils.js.map +1 -0
  80. package/dist/shared/utils/pairHelpers.d.ts +0 -1
  81. package/dist/shared/utils/pairHelpers.js +1 -0
  82. package/dist/shared/utils/pairHelpers.js.map +1 -0
  83. package/dist/shared/utils/webComponentHelpers.d.ts +0 -1
  84. package/dist/shared/utils/webComponentHelpers.js +1 -0
  85. package/dist/shared/utils/webComponentHelpers.js.map +1 -0
  86. package/package.json +11 -33
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/plugins/associate/index.d.ts.map +0 -1
  89. package/dist/plugins/choice/index.d.ts.map +0 -1
  90. package/dist/plugins/custom/index.d.ts.map +0 -1
  91. package/dist/plugins/end-attempt/index.d.ts.map +0 -1
  92. package/dist/plugins/extended-text/index.d.ts.map +0 -1
  93. package/dist/plugins/gap-match/index.d.ts.map +0 -1
  94. package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
  95. package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
  96. package/dist/plugins/graphic-order/index.d.ts.map +0 -1
  97. package/dist/plugins/hotspot/index.d.ts.map +0 -1
  98. package/dist/plugins/hottext/index.d.ts.map +0 -1
  99. package/dist/plugins/index.d.ts +0 -31
  100. package/dist/plugins/index.d.ts.map +0 -1
  101. package/dist/plugins/index.js +0 -31
  102. package/dist/plugins/match/index.d.ts.map +0 -1
  103. package/dist/plugins/media/index.d.ts.map +0 -1
  104. package/dist/plugins/order/index.d.ts.map +0 -1
  105. package/dist/plugins/position-object/index.d.ts.map +0 -1
  106. package/dist/plugins/select-point/index.d.ts.map +0 -1
  107. package/dist/plugins/slider/index.d.ts.map +0 -1
  108. package/dist/shared/actions/typesetAction.d.ts.map +0 -1
  109. package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
  110. package/dist/shared/index.d.ts.map +0 -1
  111. package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
  112. package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
  113. package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
  114. package/dist/shared/utils/touchDragHelper.d.ts +0 -2
  115. package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
  116. package/dist/shared/utils/touchDragHelper.js +0 -1
  117. package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
  118. package/src/catalog/CatalogPopup.svelte +0 -163
  119. package/src/index.ts +0 -141
  120. package/src/plugins/associate/AssociateInteraction.svelte +0 -304
  121. package/src/plugins/associate/index.ts +0 -9
  122. package/src/plugins/choice/ChoiceInteraction.svelte +0 -355
  123. package/src/plugins/choice/index.ts +0 -9
  124. package/src/plugins/custom/CustomInteraction.svelte +0 -61
  125. package/src/plugins/custom/index.ts +0 -9
  126. package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
  127. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
  128. package/src/plugins/end-attempt/index.ts +0 -9
  129. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -152
  130. package/src/plugins/extended-text/index.ts +0 -9
  131. package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
  132. package/src/plugins/gap-match/index.ts +0 -9
  133. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
  134. package/src/plugins/graphic-associate/index.ts +0 -9
  135. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
  136. package/src/plugins/graphic-gap-match/index.ts +0 -9
  137. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
  138. package/src/plugins/graphic-order/index.ts +0 -9
  139. package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
  140. package/src/plugins/hotspot/index.ts +0 -9
  141. package/src/plugins/hottext/HottextInteraction.svelte +0 -325
  142. package/src/plugins/hottext/index.ts +0 -9
  143. package/src/plugins/index.ts +0 -32
  144. package/src/plugins/match/MatchInteraction.svelte +0 -82
  145. package/src/plugins/match/index.ts +0 -9
  146. package/src/plugins/media/MediaInteraction.svelte +0 -216
  147. package/src/plugins/media/index.ts +0 -9
  148. package/src/plugins/order/OrderInteraction.svelte +0 -280
  149. package/src/plugins/order/index.ts +0 -9
  150. package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
  151. package/src/plugins/position-object/README.md +0 -130
  152. package/src/plugins/position-object/index.ts +0 -9
  153. package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
  154. package/src/plugins/select-point/index.ts +0 -9
  155. package/src/plugins/slider/SliderInteraction.svelte +0 -141
  156. package/src/plugins/slider/index.ts +0 -9
  157. package/src/plugins/upload/UploadInteraction.svelte +0 -59
  158. package/src/shared/actions/typesetAction.ts +0 -87
  159. package/src/shared/components/CustomInteractionFallback.svelte +0 -153
  160. package/src/shared/components/DragHandle.svelte +0 -44
  161. package/src/shared/components/DrawingCanvas.svelte +0 -259
  162. package/src/shared/components/FileUpload.svelte +0 -158
  163. package/src/shared/components/GraphicGapMatch.svelte +0 -318
  164. package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
  165. package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
  166. package/src/shared/components/MatchDragDrop.svelte +0 -481
  167. package/src/shared/components/MathContent.svelte +0 -18
  168. package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
  169. package/src/shared/components/RichTextEditor.svelte +0 -316
  170. package/src/shared/components/ShadowBaseStyles.svelte +0 -390
  171. package/src/shared/components/SortableList.svelte +0 -297
  172. package/src/shared/extensions/MathLiveEditor.ts +0 -299
  173. package/src/shared/index.ts +0 -15
  174. package/src/shared/styles/shared.css +0 -16
  175. package/src/shared/utils/eventHelpers.ts +0 -69
  176. package/src/shared/utils/matchGroupUtils.ts +0 -14
  177. package/src/shared/utils/pairHelpers.ts +0 -109
  178. package/src/shared/utils/webComponentHelpers.ts +0 -69
  179. package/src/svelte-shims.d.ts +0 -9
  180. /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
@@ -1,318 +0,0 @@
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 { touchDrag } from '@pie-qti/qti-common';
10
- import { createOrUpdatePair, getSourceForTarget, getTargetForSource, removePairBySource } from '../utils/pairHelpers.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, right, bottom] = coords;
153
- return { x, y, width: right - x, height: bottom - y };
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, right, bottom] = hotspot.coords.split(',').map(Number)}
260
- {@const width = right - x}
261
- {@const height = bottom - y}
262
- {@const hotspotIndex = hotspots.findIndex((h) => h.identifier === hotspot.identifier)}
263
- <rect
264
- role="button"
265
- tabindex={disabled || !keyboardSelectedTextId ? -1 : 0}
266
- aria-label="Hotspot {hotspotIndex + 1}{matchedGapText && gapTextObj ? '. Contains ' + gapTextObj.text : '. Available'}{keyboardSelectedTextId ? '. Press Space or Enter to place label' : ''}"
267
- x={x}
268
- y={y}
269
- width={width}
270
- height={height}
271
- fill={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : 'transparent'}
272
- fill-opacity={matchedGapText ? '0.3' : isHovered ? '0.2' : '0'}
273
- stroke={matchedGapText ? '#10b981' : isHovered ? '#3b82f6' : '#6b7280'}
274
- stroke-width="2"
275
- stroke-dasharray={matchedGapText ? '' : '4,4'}
276
- class="transition-all"
277
- style="pointer-events: auto; cursor: {disabled ? 'not-allowed' : 'pointer'};"
278
- ondragover={(e) => handleHotspotDragOver(e, hotspot.identifier)}
279
- ondragleave={handleHotspotDragLeave}
280
- ondrop={(e) => handleHotspotDrop(e, hotspot.identifier)}
281
- onkeydown={(e) => handleHotspotKeyDown(e, hotspot.identifier)}
282
- />
283
- {/if}
284
-
285
- <!-- Label text on hotspot if matched -->
286
- {#if matchedGapText && gapTextObj}
287
- {@const [cx, cy] = hotspot.coords.split(',').map(Number)}
288
- <text
289
- x={cx}
290
- y={cy}
291
- text-anchor="middle"
292
- dominant-baseline="middle"
293
- class="font-bold pointer-events-none"
294
- fill="#059669"
295
- font-size="14"
296
- >
297
- {gapTextObj.text}
298
- </text>
299
- {/if}
300
- </g>
301
- {/each}
302
- </svg>
303
- </div>
304
- </div>
305
-
306
- <style>
307
- [draggable='true'] {
308
- touch-action: none;
309
- }
310
-
311
- /* Ensure SVG fills its container */
312
- svg {
313
- width: 100%;
314
- height: 100%;
315
- display: block;
316
- }
317
-
318
- </style>
@@ -1,45 +0,0 @@
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
- // Build imageData HTML string: inline SVG content or an <img> tag for raster images
23
- const imageDataHtml = $derived.by(() => {
24
- const img = interaction.imageData;
25
- if (!img) return '';
26
- if (img.content) return img.content as string;
27
- if (img.src) return `<img src="${img.src}" alt="" style="width: 100%; height: 100%; display: block; position: absolute; top: 0; left: 0;" />`;
28
- return '';
29
- });
30
-
31
- function handlePairsChange(newPairs: string[]) {
32
- onChange(newPairs);
33
- }
34
- </script>
35
-
36
- <GraphicGapMatch
37
- gapTexts={interaction.gapTexts}
38
- hotspots={interaction.hotspots}
39
- {pairs}
40
- imageData={imageDataHtml}
41
- imageWidth={interaction.imageData?.width ?? '600'}
42
- imageHeight={interaction.imageData?.height ?? '500'}
43
- {disabled}
44
- onPairsChange={handlePairsChange}
45
- />
@@ -1,141 +0,0 @@
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 InlineRendererInteraction {
7
- responseId: string;
8
- interactionClasses?: string[];
9
- expectedLength?: number;
10
- placeholderText?: string | null;
11
- dataPrompt?: string | null;
12
- label?: string | null;
13
- choices?: Array<{ identifier: string; text: string }>;
14
- }
15
-
16
- type InlineResponseMap = Record<string, string | null>;
17
-
18
- interface Props {
19
- html: string;
20
- interactions: InlineRendererInteraction[];
21
- responses: InlineResponseMap;
22
- onResponseChange: (responseId: string, value: string) => void;
23
- }
24
-
25
- let { html, interactions, responses, onResponseChange }: Props = $props();
26
-
27
- // Parse HTML and extract inline interaction placeholders
28
- interface ParsedSegment {
29
- type: 'html' | 'textEntry' | 'inlineChoice';
30
- content?: string;
31
- interaction?: InlineRendererInteraction;
32
- }
33
-
34
- const segments = $derived.by(() => {
35
- const result: ParsedSegment[] = [];
36
-
37
- let lastIndex = 0;
38
- let match;
39
-
40
- // Create a combined pattern to find all placeholders in order
41
- const combinedPattern = /\[TEXTENTRY:([^\]]+)\]|\[INLINECHOICE:([^\]]+)\]/g;
42
-
43
- while ((match = combinedPattern.exec(html)) !== null) {
44
- // Add HTML before this match
45
- if (match.index > lastIndex) {
46
- result.push({
47
- type: 'html',
48
- content: html.substring(lastIndex, match.index),
49
- });
50
- }
51
-
52
- // Determine which type of interaction this is
53
- if (match[0].startsWith('[TEXTENTRY:')) {
54
- const responseId = match[1];
55
- const interaction = interactions.find((i) => i.responseId === responseId);
56
- if (interaction) {
57
- result.push({
58
- type: 'textEntry',
59
- interaction,
60
- });
61
- }
62
- } else if (match[0].startsWith('[INLINECHOICE:')) {
63
- const responseId = match[2];
64
- const interaction = interactions.find((i) => i.responseId === responseId);
65
- if (interaction) {
66
- result.push({
67
- type: 'inlineChoice',
68
- interaction,
69
- });
70
- }
71
- }
72
-
73
- lastIndex = match.index + match[0].length;
74
- }
75
-
76
- // Add remaining HTML after last match
77
- if (lastIndex < html.length) {
78
- result.push({
79
- type: 'html',
80
- content: html.substring(lastIndex),
81
- });
82
- }
83
-
84
- // If no matches found, just return the HTML as one segment
85
- if (result.length === 0) {
86
- result.push({
87
- type: 'html',
88
- content: html,
89
- });
90
- }
91
-
92
- return result;
93
- });
94
- </script>
95
-
96
- <div class="inline-interaction-container">
97
- {#each segments as segment}
98
- {#if segment.type === 'html'}
99
- {@html segment.content}
100
- {:else if segment.type === 'textEntry'}
101
- {@const inputWidthClass = (segment.interaction.interactionClasses ?? []).find((c: string) => c.startsWith('qti-input-width-'))}
102
- {@const inputWidthCh = inputWidthClass ? parseInt(inputWidthClass.replace('qti-input-width-', ''), 10) : null}
103
- <input
104
- type="text"
105
- class={['input input-bordered input-sm inline-input', ...(segment.interaction.interactionClasses ?? [])].join(' ')}
106
- style={inputWidthCh ? `width: ${inputWidthCh}ch; display: inline-block; margin: 0 4px;` : `width: ${(segment.interaction.expectedLength ?? 15) * 8}px; min-width: 100px; display: inline-block; margin: 0 4px;`}
107
- placeholder={segment.interaction.placeholderText || ''}
108
- aria-label={`Text entry ${segment.interaction.responseId}`}
109
- value={responses[segment.interaction.responseId] || ''}
110
- oninput={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
111
- />
112
- {:else if segment.type === 'inlineChoice'}
113
- {@const inputWidthClass = (segment.interaction.interactionClasses ?? []).find((c: string) => c.startsWith('qti-input-width-'))}
114
- {@const inputWidthCh = inputWidthClass ? parseInt(inputWidthClass.replace('qti-input-width-', ''), 10) : null}
115
- {@const placeholder = segment.interaction.dataPrompt ?? segment.interaction.label ?? 'Select...'}
116
- <select
117
- class={['select select-bordered select-sm inline-select', ...(segment.interaction.interactionClasses ?? [])].join(' ')}
118
- style={inputWidthCh ? `width: ${inputWidthCh}ch; display: inline-block; margin: 0 4px;` : `display: inline-block; margin: 0 4px; width: auto; min-width: 120px;`}
119
- aria-label={`Inline choice ${segment.interaction.responseId}`}
120
- value={responses[segment.interaction.responseId] || ''}
121
- onchange={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
122
- >
123
- <option value="" disabled>{placeholder}</option>
124
- {#each segment.interaction.choices ?? [] as choice}
125
- <option value={choice.identifier}>{choice.text}</option>
126
- {/each}
127
- </select>
128
- {/if}
129
- {/each}
130
- </div>
131
-
132
- <style>
133
- .inline-interaction-container :global(p) {
134
- display: inline;
135
- }
136
-
137
- .inline-input,
138
- .inline-select {
139
- vertical-align: baseline;
140
- }
141
- </style>