@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,434 @@
1
+ <script lang="ts">
2
+ /**
3
+ * Drag-and-drop matching component with keyboard, mouse, and touch support
4
+ * Keyboard: Tab to navigate, Space/Enter to select source, Tab to targets, Space/Enter to match
5
+ * Touch: Touch and drag source items to target drop zones
6
+ */
7
+
8
+ import type { AssociableChoice } from '@pie-qti/item-player';
9
+ import type { I18nProvider } from '@pie-qti/i18n';
10
+ import { createOrUpdatePair, getSourceForTarget, getTargetForSource, removePairBySource } from '../utils/pairHelpers.js';
11
+ import { touchDrag } from '../utils/touchDragHelper.js';
12
+ import DragHandle from './DragHandle.svelte';
13
+ import '../styles/shared.css';
14
+
15
+ interface Props {
16
+ sourceSet: AssociableChoice[];
17
+ targetSet: AssociableChoice[];
18
+ pairs: string[]; // Array of "sourceId targetId" pairs
19
+ correctPairs?: string[]; // Array of correct "sourceId targetId" pairs
20
+ disabled?: boolean;
21
+ i18n?: I18nProvider;
22
+ onPairsChange: (newPairs: string[]) => void;
23
+ }
24
+
25
+ const { sourceSet, targetSet, pairs, correctPairs = [], disabled = false, i18n, onPairsChange }: Props = $props();
26
+
27
+ let draggedSourceId = $state<string | null>(null);
28
+ let keyboardSelectedSourceId = $state<string | null>(null); // Source selected via keyboard
29
+ let announceText = $state<string>(''); // For screen reader announcements
30
+
31
+ // Mouse drag handlers
32
+ function handleDragStart(sourceId: string) {
33
+ if (disabled) return;
34
+ draggedSourceId = sourceId;
35
+ }
36
+
37
+ function handleDragOver(event: DragEvent) {
38
+ if (disabled) return;
39
+ event.preventDefault();
40
+ }
41
+
42
+ function handleDrop(event: DragEvent, targetId: string) {
43
+ if (disabled || !draggedSourceId) return;
44
+ event.preventDefault();
45
+
46
+ createMatch(draggedSourceId, targetId);
47
+ draggedSourceId = null;
48
+ }
49
+
50
+ function handleDragEnd() {
51
+ draggedSourceId = null;
52
+ }
53
+
54
+ // Keyboard handlers for source items
55
+ function handleSourceKeyDown(event: KeyboardEvent, sourceId: string) {
56
+ if (disabled) return;
57
+
58
+ const source = sourceSet.find((s) => s.identifier === sourceId);
59
+ const sourceName = source?.text || 'Item';
60
+
61
+ if (event.key === ' ' || event.key === 'Enter') {
62
+ event.preventDefault();
63
+
64
+ if (keyboardSelectedSourceId === sourceId) {
65
+ // Deselect
66
+ keyboardSelectedSourceId = null;
67
+ announceText = `${sourceName} deselected`;
68
+ } else {
69
+ // Select this source for matching
70
+ keyboardSelectedSourceId = sourceId;
71
+ announceText = `${sourceName} selected. Navigate to a target and press Space or Enter to match.`;
72
+ }
73
+ } else if (event.key === 'Escape' && keyboardSelectedSourceId) {
74
+ event.preventDefault();
75
+ keyboardSelectedSourceId = null;
76
+ announceText = `Selection cancelled`;
77
+ }
78
+ }
79
+
80
+ // Keyboard handlers for target items
81
+ function handleTargetKeyDown(event: KeyboardEvent, targetId: string) {
82
+ if (disabled) return;
83
+
84
+ const target = targetSet.find((t) => t.identifier === targetId);
85
+ const targetName = target?.text || 'Target';
86
+
87
+ if ((event.key === ' ' || event.key === 'Enter') && keyboardSelectedSourceId) {
88
+ event.preventDefault();
89
+
90
+ const source = sourceSet.find((s) => s.identifier === keyboardSelectedSourceId);
91
+ const sourceName = source?.text || 'Item';
92
+
93
+ createMatch(keyboardSelectedSourceId, targetId);
94
+ announceText = `${sourceName} matched with ${targetName}`;
95
+ keyboardSelectedSourceId = null;
96
+ }
97
+ }
98
+
99
+ // Create or update a match
100
+ function createMatch(sourceId: string, targetId: string) {
101
+ const newPairs = createOrUpdatePair(pairs, sourceId, targetId);
102
+ onPairsChange(newPairs);
103
+ }
104
+
105
+ function clearMatch(sourceId: string) {
106
+ if (disabled) return;
107
+ const source = sourceSet.find((s) => s.identifier === sourceId);
108
+ const sourceName = source?.text || 'Item';
109
+
110
+ const newPairs = removePairBySource(pairs, sourceId);
111
+ onPairsChange(newPairs);
112
+
113
+ announceText = `Match cleared for ${sourceName}`;
114
+ }
115
+ </script>
116
+
117
+ <!-- Screen reader announcements -->
118
+ <div aria-live="polite" aria-atomic="true" class="sr-only">
119
+ {announceText}
120
+ </div>
121
+
122
+ <!-- Instructions for keyboard users -->
123
+ <div id="match-instructions" class="sr-only">
124
+ Press Space or Enter to select a source item. Tab to navigate to targets. Press Space or Enter on a target to create a match. Press Escape to cancel selection.
125
+ </div>
126
+
127
+ <div
128
+ class="qti-match-grid grid grid-cols-2 gap-6"
129
+ part="grid"
130
+ role="region"
131
+ aria-describedby="match-instructions"
132
+ >
133
+ <!-- Source Set (Left Column) -->
134
+ <div part="source-column" class="qti-match-col space-y-2" role="group" aria-label={i18n?.t('interactions.match.sourceItemsLabel') ?? 'Source items to match'}>
135
+ <h3 part="source-heading" class="qti-match-heading font-semibold text-sm text-base-content/70 mb-3">
136
+ {i18n?.t('interactions.match.dragFromHere') ?? 'Drag from here:'}
137
+ </h3>
138
+ {#each sourceSet as source (source.identifier)}
139
+ {@const matchedTarget = getTargetForSource(pairs, source.identifier)}
140
+ {@const targetItem = matchedTarget ? targetSet.find((t) => t.identifier === matchedTarget) : null}
141
+ {@const isSelected = keyboardSelectedSourceId === source.identifier}
142
+ {@const correctTarget = getTargetForSource(correctPairs, source.identifier)}
143
+ {@const isCorrect = correctTarget !== null}
144
+
145
+ <div class="qti-match-source-wrapper relative">
146
+ <button
147
+ type="button"
148
+ draggable={!disabled && !matchedTarget}
149
+ use:touchDrag
150
+ ondragstart={() => handleDragStart(source.identifier)}
151
+ ondragend={handleDragEnd}
152
+ onkeydown={(e) => handleSourceKeyDown(e, source.identifier)}
153
+ disabled={disabled}
154
+ aria-label="{source.text}{matchedTarget && targetItem ? '. Matched with ' + targetItem.text : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
155
+ aria-pressed={isSelected}
156
+ data-matched={!!matchedTarget}
157
+ data-selected={isSelected}
158
+ data-correct={isCorrect}
159
+ data-dragging={draggedSourceId === source.identifier}
160
+ part="source-item"
161
+ class="qti-match-source p-3 rounded-lg border-2 transition-all w-full"
162
+ class:bg-base-200={!matchedTarget && !isSelected && !isCorrect}
163
+ class:bg-success={matchedTarget || isCorrect}
164
+ class:bg-primary={isSelected}
165
+ class:bg-opacity-20={matchedTarget || isSelected || isCorrect}
166
+ class:border-base-300={!matchedTarget && !isSelected && !isCorrect}
167
+ class:border-success={matchedTarget || isCorrect}
168
+ class:border-primary={isSelected}
169
+ class:ring-2={isSelected}
170
+ class:ring-primary={isSelected}
171
+ class:cursor-grab={!disabled && !matchedTarget && !isSelected}
172
+ class:cursor-not-allowed={disabled}
173
+ class:opacity-50={disabled || draggedSourceId === source.identifier}
174
+ >
175
+ <div class="qti-match-source-content flex items-center justify-between gap-2">
176
+ <div class="qti-match-source-text flex-1">
177
+ <div class="qti-match-source-title font-medium">{source.text}</div>
178
+ {#if matchedTarget && targetItem}
179
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {targetItem.text}</div>
180
+ {:else if isCorrect && correctTarget}
181
+ {@const correctTargetItem = targetSet.find((t) => t.identifier === correctTarget)}
182
+ {#if correctTargetItem}
183
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {correctTargetItem.text}</div>
184
+ {/if}
185
+ {/if}
186
+ {#if isCorrect && !matchedTarget}
187
+ <span class="badge badge-success badge-sm ml-2">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
188
+ {/if}
189
+ </div>
190
+ {#if !disabled && !matchedTarget}
191
+ <DragHandle size={1.25} opacity={0.3} class="text-base-content" />
192
+ {/if}
193
+ </div>
194
+ </button>
195
+ {#if matchedTarget && !disabled}
196
+ <button
197
+ type="button"
198
+ part="source-clear"
199
+ class="qti-match-clear btn btn-xs btn-ghost absolute top-2 right-2"
200
+ onclick={() => clearMatch(source.identifier)}
201
+ aria-label="Clear match for {source.text}"
202
+ >
203
+ ✕
204
+ </button>
205
+ {/if}
206
+ </div>
207
+ {/each}
208
+ </div>
209
+
210
+ <!-- Target Set (Right Column) - Drop Zones -->
211
+ <div part="target-column" class="qti-match-col space-y-2" role="group" aria-label={i18n?.t('interactions.match.targetItemsLabel') ?? 'Target items for matching'}>
212
+ <h3 part="target-heading" class="qti-match-heading font-semibold text-sm text-base-content/70 mb-3">
213
+ {i18n?.t('interactions.match.dropHere') ?? 'Drop here:'}
214
+ </h3>
215
+ {#each targetSet as target (target.identifier)}
216
+ {@const matchedSource = getSourceForTarget(pairs, target.identifier)}
217
+ {@const sourceItem = matchedSource ? sourceSet.find((s) => s.identifier === matchedSource) : null}
218
+ {@const isHighlight = (draggedSourceId && !matchedSource) || (keyboardSelectedSourceId && !matchedSource)}
219
+ {@const correctSource = getSourceForTarget(correctPairs, target.identifier)}
220
+ {@const isCorrect = correctSource !== null}
221
+
222
+ <button
223
+ type="button"
224
+ ondragover={handleDragOver}
225
+ ondrop={(e) => handleDrop(e, target.identifier)}
226
+ onkeydown={(e) => handleTargetKeyDown(e, target.identifier)}
227
+ disabled={disabled || !keyboardSelectedSourceId}
228
+ aria-label="{target.text}{matchedSource && sourceItem ? '. Matched with ' + sourceItem.text : '. Available for matching'}{isCorrect ? '. Correct answer' : ''}"
229
+ data-matched={!!matchedSource}
230
+ data-highlight={isHighlight}
231
+ data-correct={isCorrect}
232
+ part="target"
233
+ class="qti-match-target p-3 rounded-lg border-2 border-dashed min-h-[60px] transition-all"
234
+ class:bg-base-100={!matchedSource && !isCorrect}
235
+ class:bg-primary={matchedSource}
236
+ class:bg-success={isCorrect && !matchedSource}
237
+ class:bg-opacity-10={matchedSource}
238
+ class:bg-opacity-20={isCorrect && !matchedSource}
239
+ class:border-base-300={!matchedSource && !isCorrect}
240
+ class:border-primary={matchedSource}
241
+ class:border-success={isCorrect && !matchedSource}
242
+ class:border-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
243
+ class:bg-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
244
+ class:bg-opacity-5={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
245
+ >
246
+ <div class="qti-match-target-content flex flex-col gap-1">
247
+ <div class="qti-match-target-title font-medium text-base-content/70">{target.text}</div>
248
+ {#if matchedSource && sourceItem}
249
+ <div class="qti-match-target-sub text-sm text-primary font-medium">← {sourceItem.text}</div>
250
+ {:else if isCorrect && correctSource}
251
+ {@const correctSourceItem = sourceSet.find((s) => s.identifier === correctSource)}
252
+ {#if correctSourceItem}
253
+ <div class="qti-match-target-sub text-sm text-success font-medium">← {correctSourceItem.text}</div>
254
+ {/if}
255
+ {:else if !disabled}
256
+ <div class="qti-match-target-hint text-xs text-base-content/70 italic">
257
+ {keyboardSelectedSourceId
258
+ ? (i18n?.t('interactions.match.dragInstruction') ?? 'Press Space or Enter to match')
259
+ : (i18n?.t('interactions.match.dropTarget') ?? 'Drop item here')}
260
+ </div>
261
+ {/if}
262
+ {#if isCorrect && !matchedSource}
263
+ <span class="badge badge-success badge-sm mt-1">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
264
+ {/if}
265
+ </div>
266
+ </button>
267
+ {/each}
268
+ </div>
269
+ </div>
270
+
271
+ <style>
272
+ [draggable="true"] {
273
+ touch-action: none;
274
+ }
275
+
276
+ /* Minimal, self-contained layout so the component doesn't break when Tailwind utilities aren't present */
277
+ .qti-match-grid {
278
+ display: grid;
279
+ grid-template-columns: 1fr 1fr;
280
+ gap: 1.5rem;
281
+ }
282
+ @media (max-width: 640px) {
283
+ .qti-match-grid {
284
+ grid-template-columns: 1fr;
285
+ }
286
+ }
287
+ .qti-match-col {
288
+ display: flex;
289
+ flex-direction: column;
290
+ gap: 0.5rem;
291
+ min-width: 0;
292
+ }
293
+ .qti-match-heading {
294
+ margin: 0 0 0.75rem;
295
+ font-weight: 600;
296
+ font-size: 0.875rem;
297
+ color: color-mix(
298
+ in oklch,
299
+ var(--color-base-content, oklch(21% 0 0)) 70%,
300
+ transparent
301
+ );
302
+ }
303
+
304
+ .qti-match-source-wrapper {
305
+ position: relative;
306
+ }
307
+ .qti-match-source {
308
+ display: block;
309
+ width: 100%;
310
+ padding: 0.75rem;
311
+ border-radius: 0.5rem;
312
+ border: 2px solid var(--color-base-300, oklch(95% 0 0));
313
+ background: var(--color-base-200, oklch(98% 0 0));
314
+ color: var(--color-base-content, oklch(21% 0 0));
315
+ text-align: left;
316
+ user-select: none;
317
+ transition: background-color 120ms ease, border-color 120ms ease, outline-color 120ms ease,
318
+ opacity 120ms ease;
319
+ }
320
+ .qti-match-source:focus-visible {
321
+ outline: 2px solid var(--color-primary, oklch(45% 0.24 277));
322
+ outline-offset: 2px;
323
+ }
324
+ .qti-match-source[data-selected='true'] {
325
+ border-color: var(--color-primary, oklch(45% 0.24 277));
326
+ background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 8%, transparent);
327
+ }
328
+ .qti-match-source[data-matched='true'],
329
+ .qti-match-source[data-correct='true'] {
330
+ border-color: var(--color-success, oklch(76% 0.177 163.223));
331
+ background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
332
+ }
333
+ .qti-match-source[data-dragging='true'] {
334
+ opacity: 0.55;
335
+ }
336
+
337
+ .qti-match-source-content {
338
+ display: flex;
339
+ align-items: center;
340
+ justify-content: space-between;
341
+ gap: 0.5rem;
342
+ }
343
+ .qti-match-source-text {
344
+ flex: 1 1 auto;
345
+ min-width: 0;
346
+ }
347
+ .qti-match-source-title {
348
+ font-weight: 600;
349
+ }
350
+ .qti-match-source-sub {
351
+ margin-top: 0.25rem;
352
+ font-size: 0.875rem;
353
+ color: var(--color-success, oklch(76% 0.177 163.223));
354
+ }
355
+
356
+ .qti-match-clear {
357
+ position: absolute;
358
+ top: 0.5rem;
359
+ right: 0.5rem;
360
+ width: 1.5rem;
361
+ height: 1.5rem;
362
+ display: inline-flex;
363
+ align-items: center;
364
+ justify-content: center;
365
+ border-radius: 0.375rem;
366
+ border: 1px solid transparent;
367
+ background: transparent;
368
+ color: inherit;
369
+ cursor: pointer;
370
+ }
371
+ .qti-match-clear:hover {
372
+ background: color-mix(in oklch, var(--color-base-300, oklch(95% 0 0)) 35%, transparent);
373
+ }
374
+
375
+ .qti-match-target {
376
+ width: 100%;
377
+ padding: 0.75rem;
378
+ border-radius: 0.5rem;
379
+ border: 2px dashed var(--color-base-300, oklch(95% 0 0));
380
+ background: var(--color-base-100, oklch(100% 0 0));
381
+ color: var(--color-base-content, oklch(21% 0 0));
382
+ text-align: left;
383
+ min-height: 60px;
384
+ transition: background-color 120ms ease, border-color 120ms ease, outline-color 120ms ease,
385
+ opacity 120ms ease;
386
+ }
387
+ .qti-match-target:focus-visible {
388
+ outline: 2px solid var(--color-primary, oklch(45% 0.24 277));
389
+ outline-offset: 2px;
390
+ }
391
+ .qti-match-target[data-matched='true'] {
392
+ border-color: var(--color-primary, oklch(45% 0.24 277));
393
+ background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 6%, transparent);
394
+ }
395
+ .qti-match-target[data-correct='true'] {
396
+ border-color: var(--color-success, oklch(76% 0.177 163.223));
397
+ background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
398
+ }
399
+ .qti-match-target[data-highlight='true'] {
400
+ border-color: var(--color-accent, oklch(77% 0.152 181.912));
401
+ background: color-mix(in oklch, var(--color-accent, oklch(77% 0.152 181.912)) 6%, transparent);
402
+ }
403
+ .qti-match-target:disabled {
404
+ opacity: 0.6;
405
+ cursor: not-allowed;
406
+ }
407
+ .qti-match-target-content {
408
+ display: flex;
409
+ flex-direction: column;
410
+ gap: 0.25rem;
411
+ }
412
+ .qti-match-target-title {
413
+ font-weight: 600;
414
+ color: color-mix(
415
+ in oklch,
416
+ var(--color-base-content, oklch(21% 0 0)) 70%,
417
+ transparent
418
+ );
419
+ }
420
+ .qti-match-target-sub {
421
+ font-size: 0.875rem;
422
+ font-weight: 600;
423
+ color: hsl(var(--p, 240 100% 50%));
424
+ }
425
+ .qti-match-target-hint {
426
+ font-size: 0.75rem;
427
+ font-style: italic;
428
+ color: color-mix(
429
+ in oklch,
430
+ var(--color-base-content, oklch(21% 0 0)) 70%,
431
+ transparent
432
+ );
433
+ }
434
+ </style>
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ import { typesetAction } from '../actions/typesetAction.js';
3
+
4
+ interface Props {
5
+ /** HTML content that may contain MathML or LaTeX */
6
+ content: string;
7
+ /** Typeset function (KaTeX, MathJax, etc.) */
8
+ typeset: (root: HTMLElement) => void | Promise<void>;
9
+ /** Additional CSS classes */
10
+ class?: string;
11
+ }
12
+
13
+ const { content, typeset, class: className = '' }: Props = $props();
14
+ </script>
15
+
16
+ <div class={className} use:typesetAction={{ typeset }}>
17
+ {@html content}
18
+ </div>
@@ -0,0 +1,81 @@
1
+ <script lang="ts">
2
+ import type { ModalFeedback } from '@pie-qti/item-player';
3
+ import type { I18nProvider } from '@pie-qti/i18n';
4
+ import { typesetAction } from './actions/typesetAction';
5
+
6
+ interface Props {
7
+ feedback: ModalFeedback[];
8
+ onClose?: () => void;
9
+ typeset?: (element: HTMLElement) => void;
10
+ i18n?: I18nProvider;
11
+ }
12
+
13
+ let { feedback = [], onClose, typeset, i18n }: Props = $props();
14
+
15
+ // Show modal if there's feedback
16
+ const hasActiveFeedback = $derived(feedback.length > 0);
17
+
18
+ function handleClose() {
19
+ onClose?.();
20
+ }
21
+
22
+ function handleBackdropClick(e: MouseEvent) {
23
+ // Close when clicking the backdrop (outside the modal content)
24
+ if (e.target === e.currentTarget) {
25
+ handleClose();
26
+ }
27
+ }
28
+ </script>
29
+
30
+ {#if hasActiveFeedback}
31
+ <!-- DaisyUI Modal -->
32
+ <dialog class="modal modal-open" onclick={handleBackdropClick}>
33
+ <div class="modal-box max-w-3xl">
34
+ <!-- Close button -->
35
+ <button
36
+ class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
37
+ onclick={handleClose}
38
+ aria-label={i18n?.t('feedback.close') ?? 'Close feedback'}
39
+ >
40
+ ✕
41
+ </button>
42
+
43
+ <!-- Feedback content -->
44
+ {#each feedback as item, index}
45
+ <div class="mb-4 {index < feedback.length - 1 ? 'border-b pb-4' : ''}">
46
+ {#if item.title}
47
+ <h3 class="font-bold text-lg mb-2">{item.title}</h3>
48
+ {/if}
49
+
50
+ <!-- Render HTML content with MathJax support -->
51
+ <div
52
+ class="prose max-w-none"
53
+ use:typesetAction={typeset}
54
+ >
55
+ {@html item.content}
56
+ </div>
57
+ </div>
58
+ {/each}
59
+
60
+ <!-- Action buttons -->
61
+ <div class="modal-action">
62
+ <button class="btn btn-primary" onclick={handleClose}>
63
+ Continue
64
+ </button>
65
+ </div>
66
+ </div>
67
+ </dialog>
68
+ {/if}
69
+
70
+ <style>
71
+ /* Ensure modal is accessible */
72
+ dialog {
73
+ background-color: rgba(0, 0, 0, 0.5);
74
+ }
75
+
76
+ /* Ensure feedback content is readable */
77
+ .modal-box {
78
+ max-height: 80vh;
79
+ overflow-y: auto;
80
+ }
81
+ </style>