@pie-qti/default-components 0.1.10 → 0.1.12

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-Dz5RCjpq.js +9 -0
  2. package/dist/chunks/__vite-browser-external-Dz5RCjpq.js.map +1 -0
  3. package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-ClqhKA_b.js} +4199 -3978
  4. package/dist/chunks/mathlive.min-ClqhKA_b.js.map +1 -0
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/plugins/associate/index.d.ts +0 -1
  9. package/dist/plugins/associate/index.js +1 -0
  10. package/dist/plugins/associate/index.js.map +1 -0
  11. package/dist/plugins/choice/index.d.ts +0 -1
  12. package/dist/plugins/choice/index.js +1 -0
  13. package/dist/plugins/choice/index.js.map +1 -0
  14. package/dist/plugins/custom/index.d.ts +0 -1
  15. package/dist/plugins/custom/index.js +1 -0
  16. package/dist/plugins/custom/index.js.map +1 -0
  17. package/dist/plugins/end-attempt/index.d.ts +0 -1
  18. package/dist/plugins/end-attempt/index.js +1 -0
  19. package/dist/plugins/end-attempt/index.js.map +1 -0
  20. package/dist/plugins/extended-text/index.d.ts +0 -1
  21. package/dist/plugins/extended-text/index.js +1 -0
  22. package/dist/plugins/extended-text/index.js.map +1 -0
  23. package/dist/plugins/gap-match/index.d.ts +0 -1
  24. package/dist/plugins/gap-match/index.js +1 -0
  25. package/dist/plugins/gap-match/index.js.map +1 -0
  26. package/dist/plugins/graphic-associate/index.d.ts +0 -1
  27. package/dist/plugins/graphic-associate/index.js +1 -0
  28. package/dist/plugins/graphic-associate/index.js.map +1 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
  30. package/dist/plugins/graphic-gap-match/index.js +1 -0
  31. package/dist/plugins/graphic-gap-match/index.js.map +1 -0
  32. package/dist/plugins/graphic-order/index.d.ts +0 -1
  33. package/dist/plugins/graphic-order/index.js +1 -0
  34. package/dist/plugins/graphic-order/index.js.map +1 -0
  35. package/dist/plugins/hotspot/index.d.ts +0 -1
  36. package/dist/plugins/hotspot/index.js +1 -0
  37. package/dist/plugins/hotspot/index.js.map +1 -0
  38. package/dist/plugins/hottext/index.d.ts +0 -1
  39. package/dist/plugins/hottext/index.js +1 -0
  40. package/dist/plugins/hottext/index.js.map +1 -0
  41. package/dist/plugins/match/index.d.ts +0 -1
  42. package/dist/plugins/match/index.js +1 -0
  43. package/dist/plugins/match/index.js.map +1 -0
  44. package/dist/plugins/media/index.d.ts +0 -1
  45. package/dist/plugins/media/index.js +1 -0
  46. package/dist/plugins/media/index.js.map +1 -0
  47. package/dist/plugins/order/index.d.ts +0 -1
  48. package/dist/plugins/order/index.js +1 -0
  49. package/dist/plugins/order/index.js.map +1 -0
  50. package/dist/plugins/position-object/index.d.ts +0 -1
  51. package/dist/plugins/position-object/index.js +1 -0
  52. package/dist/plugins/position-object/index.js.map +1 -0
  53. package/dist/plugins/public-types.d.ts +5 -0
  54. package/dist/plugins/public-types.js +2 -0
  55. package/dist/plugins/public-types.js.map +1 -0
  56. package/dist/plugins/select-point/index.d.ts +0 -1
  57. package/dist/plugins/select-point/index.js +1 -0
  58. package/dist/plugins/select-point/index.js.map +1 -0
  59. package/dist/plugins/slider/index.d.ts +0 -1
  60. package/dist/plugins/slider/index.js +1 -0
  61. package/dist/plugins/slider/index.js.map +1 -0
  62. package/dist/plugins.js +27589 -9160
  63. package/dist/plugins.js.map +1 -1
  64. package/dist/shared/actions/typesetAction.d.ts +0 -1
  65. package/dist/shared/actions/typesetAction.js +1 -0
  66. package/dist/shared/actions/typesetAction.js.map +1 -0
  67. package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
  68. package/dist/shared/extensions/MathLiveEditor.js +1 -0
  69. package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
  70. package/dist/shared/index.d.ts +0 -1
  71. package/dist/shared/index.js +1 -0
  72. package/dist/shared/index.js.map +1 -0
  73. package/dist/shared/utils/eventHelpers.d.ts +0 -1
  74. package/dist/shared/utils/eventHelpers.js +1 -0
  75. package/dist/shared/utils/eventHelpers.js.map +1 -0
  76. package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
  77. package/dist/shared/utils/matchGroupUtils.js +1 -0
  78. package/dist/shared/utils/matchGroupUtils.js.map +1 -0
  79. package/dist/shared/utils/pairHelpers.d.ts +0 -1
  80. package/dist/shared/utils/pairHelpers.js +1 -0
  81. package/dist/shared/utils/pairHelpers.js.map +1 -0
  82. package/dist/shared/utils/webComponentHelpers.d.ts +0 -1
  83. package/dist/shared/utils/webComponentHelpers.js +1 -0
  84. package/dist/shared/utils/webComponentHelpers.js.map +1 -0
  85. package/package.json +15 -33
  86. package/dist/chunks/mathlive.min-Bvtiaxg4.js.map +0 -1
  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,304 +0,0 @@
1
- <svelte:options customElement="pie-qti-associate" />
2
-
3
- <script lang="ts">
4
- import type { AssociateInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import { emitInteractionChange } from '../../shared/utils/eventHelpers';
8
- import { createInteractionShell } from '../../shared/utils/webComponentHelpers';
9
- import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
10
-
11
- interface Props {
12
- interaction?: AssociateInteractionData | string;
13
- response?: string[] | null;
14
- correctResponse?: string[] | null;
15
- disabled?: boolean;
16
- role?: string;
17
- i18n?: I18nProvider;
18
- selectedForPairing?: string | null;
19
- onSelectionChange?: (selected: string | null) => void;
20
- onChange?: (value: string[]) => void;
21
- }
22
-
23
- let {
24
- interaction = $bindable(),
25
- response = $bindable(),
26
- correctResponse = $bindable(),
27
- disabled = false,
28
- role = 'candidate',
29
- i18n = $bindable(),
30
- selectedForPairing: externalSelectedForPairing,
31
- onSelectionChange,
32
- onChange,
33
- }: Props = $props();
34
-
35
- const shell = $derived(
36
- createInteractionShell<AssociateInteractionData, string[], string[]>({
37
- interaction,
38
- response,
39
- correctResponse,
40
- role,
41
- })
42
- );
43
- const parsedInteraction = $derived(shell.interaction);
44
- const parsedResponse = $derived(shell.response);
45
- const parsedCorrectResponse = $derived(shell.correctResponse);
46
- const isShowingCorrect = $derived(shell.isShowingCorrect);
47
-
48
- // Get reference to the root element for event dispatching
49
- let rootElement: HTMLDivElement | undefined = $state();
50
-
51
- // Use external selection state if provided, otherwise use internal state
52
- let internalSelectedForPairing = $state<string | null>(null);
53
- const selectedForPairing = $derived(externalSelectedForPairing ?? internalSelectedForPairing);
54
-
55
- // Ensure response is always an array
56
- const pairs = $derived(parsedResponse || []);
57
- const helperId = $derived(`associate-helper-${parsedInteraction?.responseId ?? 'unknown'}`);
58
-
59
- function emitChange(newPairs: string[]) {
60
- response = newPairs;
61
- emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: newPairs, onChange });
62
- }
63
-
64
- function setSelectedForPairing(value: string | null) {
65
- if (onSelectionChange) {
66
- onSelectionChange(value);
67
- } else {
68
- internalSelectedForPairing = value;
69
- }
70
- }
71
-
72
- // Choices that cannot be paired with the currently selected choice due to matchGroup constraints
73
- const blockedChoices = $derived.by(() => {
74
- if (!selectedForPairing || !parsedInteraction) return new Set<string>();
75
- const src = parsedInteraction.choices.find((c) => c.identifier === selectedForPairing);
76
- return new Set(
77
- parsedInteraction.choices
78
- .filter((c) => c.identifier !== selectedForPairing && !isCompatibleMatchGroup(src?.matchGroup, c.matchGroup))
79
- .map((c) => c.identifier)
80
- );
81
- });
82
-
83
- function handleChoiceClick(choiceId: string) {
84
- if (disabled) return;
85
-
86
- // If no item selected yet, select this one
87
- if (selectedForPairing === null) {
88
- setSelectedForPairing(choiceId);
89
- }
90
- // If same item clicked again, deselect
91
- else if (selectedForPairing === choiceId) {
92
- setSelectedForPairing(null);
93
- }
94
- // If different item clicked, check matchGroup compatibility then create a pair
95
- else {
96
- if (blockedChoices.has(choiceId)) return;
97
- const newPair = `${selectedForPairing} ${choiceId}`;
98
- const newPairs = [...pairs, newPair];
99
- emitChange(newPairs);
100
- setSelectedForPairing(null);
101
- }
102
- }
103
-
104
- function removePair(index: number) {
105
- const newPairs = pairs.filter((_, i) => i !== index);
106
- emitChange(newPairs);
107
- }
108
-
109
- function isInPair(choiceId: string): boolean {
110
- return pairs.some((p) => p.includes(choiceId));
111
- }
112
-
113
- function isCorrectPair(choiceId: string): boolean {
114
- if (!isShowingCorrect) return false;
115
- return (parsedCorrectResponse || []).some((p) => p.includes(choiceId));
116
- }
117
-
118
- function isCorrectPairMatch(id1: string, id2: string): boolean {
119
- if (!isShowingCorrect || !parsedCorrectResponse) return false;
120
- return parsedCorrectResponse.some(
121
- (p) => p === `${id1} ${id2}` || p === `${id2} ${id1}`
122
- );
123
- }
124
-
125
- function toPlainText(html: string): string {
126
- return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
127
- }
128
-
129
- function getChoiceLabel(choice: { identifier: string; text: string }): string {
130
- const text = toPlainText(choice.text);
131
- return text ? `${choice.identifier}: ${text}` : choice.identifier;
132
- }
133
-
134
- function getPairLabel(choice1: { identifier: string; text: string }, choice2: { identifier: string; text: string }): string {
135
- return `${getChoiceLabel(choice1)} and ${getChoiceLabel(choice2)}`;
136
- }
137
-
138
- const correctPairs = $derived(
139
- isShowingCorrect && parsedCorrectResponse ? parsedCorrectResponse : []
140
- );
141
- </script>
142
-
143
- <ShadowBaseStyles />
144
-
145
- <div bind:this={rootElement} part="root" class="qti-associate-interaction space-y-3">
146
- {#if !parsedInteraction}
147
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
148
- {:else}
149
- {#if parsedInteraction.prompt}
150
- <p part="prompt" class="qti-associate-prompt font-semibold">{@html parsedInteraction.prompt}</p>
151
- {/if}
152
-
153
- <!-- Display choices as buttons that can be clicked to form pairs -->
154
- <div part="choices" class="qti-associate-choices grid grid-cols-2 gap-2">
155
- {#each parsedInteraction.choices as choice}
156
- {@const isSelected = selectedForPairing === choice.identifier}
157
- {@const inPair = isInPair(choice.identifier)}
158
- {@const isCorrect = isCorrectPair(choice.identifier)}
159
- {@const isBlocked = blockedChoices.has(choice.identifier)}
160
- <button
161
- part="choice"
162
- class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
163
- class:opacity-40={isBlocked}
164
- class:cursor-not-allowed={isBlocked}
165
- type="button"
166
- aria-label={getChoiceLabel(choice)}
167
- aria-pressed={isSelected}
168
- aria-disabled={isBlocked ? 'true' : undefined}
169
- aria-describedby={helperId}
170
- onclick={() => handleChoiceClick(choice.identifier)}
171
- {disabled}
172
- >
173
- {@html choice.text}
174
- {#if isSelected}
175
- <span class="ml-2">◉</span>
176
- {:else if inPair}
177
- <span class="ml-2">✓</span>
178
- {/if}
179
- </button>
180
- {/each}
181
- </div>
182
-
183
- <!-- Display correct associations when in scorer mode -->
184
- {#if isShowingCorrect && correctPairs.length > 0}
185
- <div part="correct-pairs-title" class="divider">
186
- {i18n?.t('interactions.associate.correctAssociations') ?? 'Correct Associations'}
187
- </div>
188
- <div part="correct-pairs" class="qti-associate-pairs space-y-2">
189
- {#each correctPairs as pair}
190
- {@const [id1, id2] = pair.split(' ')}
191
- {@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
192
- {@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
193
- {@const isInUserPairs = pairs.some((p) => p === pair || p === `${id2} ${id1}`)}
194
- {#if choice1 && choice2}
195
- <div
196
- part="correct-pair"
197
- class="qti-associate-pair flex items-center gap-4 p-2 bg-success/10 border border-success rounded"
198
- >
199
- <span class="flex-1">{choice1.text}</span>
200
- <span class="text-success">↔</span>
201
- <span class="flex-1">{choice2.text}</span>
202
- <span class="badge badge-success badge-sm">
203
- {i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
204
- </span>
205
- </div>
206
- {/if}
207
- {/each}
208
- </div>
209
- {/if}
210
-
211
- <!-- Display current pairs -->
212
- {#if pairs.length > 0}
213
- <div part="pairs-title" class="divider">
214
- {i18n?.t('interactions.associate.currentAssociations') ?? 'Current Associations'}
215
- </div>
216
- <div part="pairs" class="qti-associate-pairs space-y-2">
217
- {#each pairs as pair, index}
218
- {@const [id1, id2] = pair.split(' ')}
219
- {@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
220
- {@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
221
- {@const isCorrect = isCorrectPairMatch(id1, id2)}
222
- {#if choice1 && choice2}
223
- <div
224
- part="pair"
225
- class="qti-associate-pair flex items-center gap-4 p-2 rounded {isCorrect
226
- ? 'bg-success/10 border border-success'
227
- : 'bg-primary/10 border border-base-300'}"
228
- >
229
- <span class="flex-1">{choice1.text}</span>
230
- <span class="{isCorrect ? 'text-success' : 'text-primary'}">↔</span>
231
- <span class="flex-1">{choice2.text}</span>
232
- {#if isCorrect}
233
- <span class="badge badge-success badge-sm">
234
- {i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
235
- </span>
236
- {/if}
237
- <button
238
- part="pair-remove"
239
- class="btn btn-sm btn-ghost btn-circle"
240
- type="button"
241
- aria-label={`Remove association between ${getPairLabel(choice1, choice2)}`}
242
- onclick={() => removePair(index)}
243
- {disabled}
244
- >
245
- ✕
246
- </button>
247
- </div>
248
- {/if}
249
- {/each}
250
- </div>
251
- {/if}
252
-
253
- <!-- Selection helper - Hide when showing correct answers -->
254
- {#if !isShowingCorrect}
255
- <div id={helperId} part="helper" class="qti-associate-helper alert alert-info" role="status" aria-live="polite">
256
- <span class="text-sm">
257
- {#if selectedForPairing}
258
- {i18n?.t('interactions.associate.clickAnotherOrDeselect') ??
259
- 'Select another item to create an association, or select this item again to deselect it.'}
260
- {:else}
261
- {i18n?.t('interactions.associate.clickToAssociate') ??
262
- 'Select two items to create an association between them. Keyboard users can tab to each item and press Enter or Space.'}
263
- {/if}
264
- </span>
265
- </div>
266
- {/if}
267
- {/if}
268
- </div>
269
-
270
- <style>
271
- /* Minimal layout so this works without Tailwind/DaisyUI */
272
- .qti-associate-interaction {
273
- display: grid;
274
- gap: 0.75rem;
275
- }
276
- .qti-associate-prompt {
277
- margin: 0;
278
- }
279
- .qti-associate-choices {
280
- display: grid;
281
- grid-template-columns: repeat(2, minmax(0, 1fr));
282
- gap: 0.5rem;
283
- }
284
- @media (max-width: 640px) {
285
- .qti-associate-choices {
286
- grid-template-columns: 1fr;
287
- }
288
- }
289
- .qti-associate-pairs {
290
- display: grid;
291
- gap: 0.5rem;
292
- }
293
- .qti-associate-pair {
294
- display: flex;
295
- align-items: center;
296
- gap: 0.75rem;
297
- padding: 0.5rem;
298
- border-radius: 0.75rem;
299
- }
300
- .qti-associate-helper {
301
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
302
- background: var(--color-base-200, oklch(98% 0 0));
303
- }
304
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'associateInteraction',
5
- tagName: 'pie-qti-associate',
6
- name: 'default-associate',
7
- description: 'Default Svelte-based associate interaction',
8
- priority: 0,
9
- };
@@ -1,355 +0,0 @@
1
- <svelte:options customElement="pie-qti-choice" />
2
-
3
- <script lang="ts">
4
- import type { ChoiceInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import { normalizeHeuristicsConfig, type QtiHeuristicsConfig } from '@pie-qti/item-player';
7
- import { processFeedbackInline } from '@pie-qti/item-player/components/utils';
8
- import { typesetAction } from '../../shared/actions/typesetAction';
9
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
10
- import { emitInteractionChange } from '../../shared/utils/eventHelpers';
11
- import { createInteractionShell } from '../../shared/utils/webComponentHelpers';
12
-
13
- interface Props {
14
- interaction?: ChoiceInteractionData | string;
15
- response?: string | string[] | null;
16
- correctResponse?: string | string[] | null;
17
- disabled?: boolean;
18
- role?: string;
19
- i18n?: I18nProvider;
20
- typeset?: (element: HTMLElement) => void;
21
- onChange?: (value: string | string[]) => void;
22
- outcomeValues?: Record<string, any>;
23
- heuristicsConfig?: QtiHeuristicsConfig;
24
- /** When true, renders an elimination toggle button per choice (QTI 3.0 PNP §6.2). */
25
- eliminationTool?: boolean;
26
- }
27
-
28
- let {
29
- interaction = $bindable(),
30
- response = $bindable(),
31
- correctResponse = $bindable(),
32
- disabled = false,
33
- role = 'candidate',
34
- i18n = $bindable(),
35
- typeset,
36
- onChange,
37
- outcomeValues = {},
38
- heuristicsConfig,
39
- eliminationTool = false
40
- }: Props = $props();
41
-
42
- // Normalize heuristics configuration with defaults
43
- const heuristics = $derived(normalizeHeuristicsConfig(heuristicsConfig));
44
-
45
- // Translation helper:
46
- // The default i18n provider returns the key itself when a translation is missing.
47
- // We treat that as "missing" so we can safely fall back to the provided string.
48
- const t = $derived((key: string, fallback: string) => {
49
- const v = i18n?.t(key);
50
- return !v || v === key ? fallback : v;
51
- });
52
-
53
- const shell = $derived(
54
- createInteractionShell<ChoiceInteractionData, string | string[], string | string[]>({
55
- interaction,
56
- response,
57
- correctResponse,
58
- role,
59
- })
60
- );
61
- const parsedInteraction = $derived(shell.interaction);
62
- const parsedResponse = $derived(shell.response);
63
- const parsedCorrectResponse = $derived(shell.correctResponse);
64
- const isShowingCorrect = $derived(shell.isShowingCorrect);
65
-
66
- // Helper function to check if a choice is correct
67
- function isCorrectChoice(identifier: string): boolean {
68
- if (!isShowingCorrect) return false;
69
- if (Array.isArray(parsedCorrectResponse)) {
70
- return parsedCorrectResponse.includes(identifier);
71
- }
72
- return parsedCorrectResponse === identifier;
73
- }
74
-
75
- // Helper function to filter feedbackInline from choice text based on outcome values
76
- function filterFeedbackInline(text: string): string {
77
- return processFeedbackInline(text, {
78
- outcomeValues,
79
- applyHeuristics: heuristics.feedbackTextFormatting,
80
- wrapWithSpan: true
81
- });
82
- }
83
-
84
- // Get reference to the root element for event dispatching
85
- let rootElement: HTMLDivElement | undefined = $state();
86
-
87
- // Elimination tool state: set of eliminated choice identifiers.
88
- // Eliminated choices remain in DOM and in the response; only visually dimmed.
89
- let eliminatedChoices = $state(new Set<string>());
90
-
91
- function toggleElimination(identifier: string) {
92
- const next = new Set(eliminatedChoices);
93
- if (next.has(identifier)) {
94
- next.delete(identifier);
95
- } else {
96
- next.add(identifier);
97
- }
98
- eliminatedChoices = next;
99
- }
100
-
101
- function eliminationLabel(identifier: string): string {
102
- const isEliminated = eliminatedChoices.has(identifier);
103
- const action = isEliminated
104
- ? (i18n?.t('interactions.choice.restoreChoice') ?? 'Restore')
105
- : (i18n?.t('interactions.choice.eliminateChoice') ?? 'Eliminate');
106
- return action;
107
- }
108
-
109
- function handleRadioChange(identifier: string) {
110
- response = identifier;
111
- emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: identifier, onChange });
112
- }
113
-
114
- function handleCheckboxChange(identifier: string, checked: boolean) {
115
- const currentValues = Array.isArray(parsedResponse) ? parsedResponse : [];
116
- let newValues = [...currentValues];
117
-
118
- if (checked) {
119
- // Enforce maxChoices (0 = unlimited)
120
- const max = parsedInteraction?.maxChoices ?? 0;
121
- if (max > 0 && newValues.length >= max) return;
122
- newValues.push(identifier);
123
- } else {
124
- newValues = newValues.filter((v) => v !== identifier);
125
- }
126
-
127
- response = newValues;
128
- emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: newValues, onChange });
129
- }
130
-
131
- // Selection limit message: show max message when at/over limit; min message is for submit time
132
- const selectionCount = $derived(Array.isArray(parsedResponse) ? parsedResponse.length : (parsedResponse ? 1 : 0));
133
- const maxChoices = $derived(parsedInteraction?.maxChoices ?? 0);
134
- const showMaxMessage = $derived(
135
- maxChoices > 0 && selectionCount >= maxChoices && !!parsedInteraction?.maxSelectionsMessage
136
- );
137
- </script>
138
-
139
- <ShadowBaseStyles />
140
-
141
- <div bind:this={rootElement} part="root" class={['qti-choice-interaction space-y-2', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
142
- {#if parsedInteraction?.prompt}
143
- <div part="prompt" class="qti-choice-prompt font-semibold">{@html parsedInteraction.prompt}</div>
144
- {/if}
145
-
146
- {#if !parsedInteraction}
147
- <div class="alert alert-error">{i18n?.t('common.errorNoData') ?? 'No interaction data provided'}</div>
148
- {:else if parsedInteraction.maxChoices === 1}
149
- <!-- Single choice (radio buttons) -->
150
- {#each parsedInteraction.choices as choice}
151
- <div
152
- part="option"
153
- class="qti-choice-option form-control"
154
- data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
155
- >
156
- <label
157
- part="label"
158
- class="qti-choice-label label cursor-pointer justify-start gap-4"
159
- class:qti-choice-correct={isCorrectChoice(choice.identifier)}
160
- >
161
- <input
162
- part="input"
163
- type="radio"
164
- name={parsedInteraction.responseId}
165
- class="radio radio-primary"
166
- class:radio-success={isCorrectChoice(choice.identifier)}
167
- value={choice.identifier}
168
- checked={parsedResponse === choice.identifier}
169
- onchange={() => handleRadioChange(choice.identifier)}
170
- {disabled}
171
- />
172
- <span part="text" class="qti-choice-text label-text">
173
- {@html choice.text}
174
- </span>
175
- {#if isCorrectChoice(choice.identifier)}
176
- <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
177
- {/if}
178
- </label>
179
- {#if eliminationTool}
180
- <button
181
- type="button"
182
- class="qti-eliminate-btn"
183
- aria-label={eliminationLabel(choice.identifier)}
184
- aria-pressed={eliminatedChoices.has(choice.identifier)}
185
- onclick={() => toggleElimination(choice.identifier)}
186
- >✕</button>
187
- {/if}
188
- </div>
189
- {/each}
190
- {:else}
191
- <!-- Multiple choice (checkboxes) -->
192
- {@const currentValues = Array.isArray(parsedResponse) ? parsedResponse : []}
193
- {#each parsedInteraction.choices as choice}
194
- <div
195
- part="option"
196
- class="qti-choice-option form-control"
197
- data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
198
- >
199
- <label
200
- part="label"
201
- class="qti-choice-label label cursor-pointer justify-start gap-4"
202
- class:qti-choice-correct={isCorrectChoice(choice.identifier)}
203
- >
204
- <input
205
- part="input"
206
- type="checkbox"
207
- class="checkbox checkbox-primary"
208
- class:checkbox-success={isCorrectChoice(choice.identifier)}
209
- value={choice.identifier}
210
- checked={currentValues.includes(choice.identifier)}
211
- onchange={(e: Event) => {
212
- const checked = (e.currentTarget as HTMLInputElement).checked;
213
- handleCheckboxChange(choice.identifier, checked);
214
- }}
215
- {disabled}
216
- />
217
- <span part="text" class="qti-choice-text label-text">
218
- {@html choice.text}
219
- </span>
220
- {#if isCorrectChoice(choice.identifier)}
221
- <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
222
- {/if}
223
- </label>
224
- {#if eliminationTool}
225
- <button
226
- type="button"
227
- class="qti-eliminate-btn"
228
- aria-label={eliminationLabel(choice.identifier)}
229
- aria-pressed={eliminatedChoices.has(choice.identifier)}
230
- onclick={() => toggleElimination(choice.identifier)}
231
- >✕</button>
232
- {/if}
233
- </div>
234
- {/each}
235
- {/if}
236
- {#if showMaxMessage}
237
- <p class="qti-selection-message qti-max-selection-message" role="alert">{parsedInteraction?.maxSelectionsMessage}</p>
238
- {/if}
239
- </div>
240
-
241
- <style>
242
- /* Minimal layout so this works without Tailwind/DaisyUI */
243
- .qti-choice-interaction {
244
- display: grid;
245
- gap: 0.5rem;
246
- }
247
- .qti-choice-prompt {
248
- margin: 0 0 0.25rem;
249
- }
250
- .qti-choice-option {
251
- display: block;
252
- }
253
- .qti-choice-label {
254
- display: flex;
255
- align-items: flex-start;
256
- gap: 0.75rem;
257
- cursor: pointer;
258
- }
259
- .qti-choice-text {
260
- display: inline-block;
261
- line-height: 1.35;
262
- }
263
- .qti-choice-interaction input[type='radio'],
264
- .qti-choice-interaction input[type='checkbox'] {
265
- margin-top: 0.15rem;
266
- }
267
-
268
- /* Correct answer highlighting */
269
- .qti-choice-correct {
270
- background-color: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
271
- border-radius: 0.5rem;
272
- padding: 0.25rem 0.5rem;
273
- margin: -0.25rem -0.5rem;
274
- }
275
-
276
- .radio-success,
277
- .checkbox-success {
278
- accent-color: var(--color-success, oklch(76% 0.177 163.223));
279
- }
280
-
281
- /* Elimination tool */
282
- .qti-choice-option {
283
- position: relative;
284
- }
285
-
286
- .qti-eliminate-btn {
287
- position: absolute;
288
- right: 0.25rem;
289
- top: 50%;
290
- transform: translateY(-50%);
291
- background: none;
292
- border: 1px solid currentColor;
293
- border-radius: 50%;
294
- width: 1.5rem;
295
- height: 1.5rem;
296
- line-height: 1;
297
- font-size: 0.75rem;
298
- cursor: pointer;
299
- opacity: 0.4;
300
- padding: 0;
301
- display: flex;
302
- align-items: center;
303
- justify-content: center;
304
- }
305
-
306
- .qti-eliminate-btn:hover,
307
- .qti-eliminate-btn[aria-pressed='true'] {
308
- opacity: 1;
309
- }
310
-
311
- /* Eliminated choices are dimmed with a strikethrough */
312
- [data-eliminated] .qti-choice-label {
313
- opacity: 0.4;
314
- text-decoration: line-through;
315
- }
316
-
317
- [data-eliminated] .qti-eliminate-btn {
318
- opacity: 1;
319
- color: var(--color-error, oklch(63% 0.237 25.331));
320
- }
321
-
322
- /* ── QTI Shared Vocabulary behavioral classes ─────────────────────────── */
323
-
324
- /* qti-input-control-hidden: hide radio/checkbox controls but keep keyboard-accessible */
325
- :global(.qti-input-control-hidden) .qti-choice-interaction input[type='radio'],
326
- :global(.qti-input-control-hidden) .qti-choice-interaction input[type='checkbox'],
327
- .qti-choice-interaction.qti-input-control-hidden input[type='radio'],
328
- .qti-choice-interaction.qti-input-control-hidden input[type='checkbox'] {
329
- position: absolute;
330
- opacity: 0;
331
- width: 0;
332
- height: 0;
333
- pointer-events: none;
334
- }
335
-
336
- /* qti-orientation-horizontal: choices in a row */
337
- .qti-choice-interaction.qti-orientation-horizontal {
338
- grid-auto-flow: column;
339
- grid-template-columns: repeat(auto-fill, minmax(0, 1fr));
340
- }
341
-
342
- /* qti-choices-stacking-N: N-column grid */
343
- .qti-choice-interaction.qti-choices-stacking-1 { grid-template-columns: 1fr; }
344
- .qti-choice-interaction.qti-choices-stacking-2 { grid-template-columns: repeat(2, 1fr); }
345
- .qti-choice-interaction.qti-choices-stacking-3 { grid-template-columns: repeat(3, 1fr); }
346
- .qti-choice-interaction.qti-choices-stacking-4 { grid-template-columns: repeat(4, 1fr); }
347
- .qti-choice-interaction.qti-choices-stacking-5 { grid-template-columns: repeat(5, 1fr); }
348
-
349
- /* Selection limit messages */
350
- .qti-selection-message {
351
- font-size: 0.875rem;
352
- color: var(--color-warning, oklch(77% 0.194 82));
353
- margin-top: 0.5rem;
354
- }
355
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'choiceInteraction',
5
- tagName: 'pie-qti-choice',
6
- name: 'default-choice',
7
- description: 'Default Svelte-based choice interaction',
8
- priority: 0,
9
- };