@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,241 +0,0 @@
1
- <svelte:options customElement="pie-qti-graphic-order" />
2
-
3
- <script lang="ts">
4
- import type { GraphicOrderInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import SortableList from '../../shared/components/SortableList.svelte';
8
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
10
-
11
- interface Props {
12
- interaction?: GraphicOrderInteractionData | string;
13
- response?: string[] | null;
14
- correctResponse?: string[] | null;
15
- disabled?: boolean;
16
- role?: string;
17
- i18n?: I18nProvider;
18
- onChange?: (value: string[]) => void;
19
- }
20
-
21
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
22
-
23
- // Parse props that may be JSON strings (web component usage)
24
- const parsedInteraction = $derived(parseJsonProp<GraphicOrderInteractionData>(interaction));
25
- const parsedResponse = $derived(parseJsonProp<string[]>(response));
26
- const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
27
- const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
28
-
29
- // Get reference to the root element for event dispatching
30
- let rootElement: HTMLDivElement | undefined = $state();
31
-
32
- let orderedIds = $state<string[]>([]);
33
- let imageContainer: HTMLDivElement | null = $state(null);
34
- let imageElement: HTMLElement | null = $state(null);
35
-
36
- // Track whether user has confirmed their order
37
- let hasConfirmed = $state(false);
38
-
39
- // Track initial order to detect if user has made changes
40
- const initialOrder = $derived(parsedInteraction?.hotspotChoices.map((c) => c.identifier) || []);
41
- const hasReordered = $derived(
42
- orderedIds.length > 0 &&
43
- orderedIds.some((id, index) => id !== initialOrder[index])
44
- );
45
-
46
- // Show confirmation button when response is null or when not confirmed yet
47
- const needsConfirmation = $derived(
48
- !disabled &&
49
- (!parsedResponse || !hasConfirmed) &&
50
- orderedIds.length > 0
51
- );
52
-
53
- $effect(() => {
54
- // Sync with parent response changes
55
- orderedIds = parsedResponse ? [...parsedResponse] : parsedInteraction?.hotspotChoices.map((c) => c.identifier) || [];
56
- });
57
-
58
- // Reset confirmation state when response is externally cleared
59
- $effect(() => {
60
- if (parsedResponse === null || (Array.isArray(parsedResponse) && parsedResponse.length === 0)) {
61
- hasConfirmed = false;
62
- }
63
- });
64
-
65
- function handleReorder(newOrder: string[]) {
66
- hasConfirmed = true; // Auto-confirm on drag
67
- orderedIds = newOrder;
68
- response = orderedIds;
69
- // Call onChange callback if provided (for Svelte component usage)
70
- onChange?.(orderedIds);
71
- // Dispatch custom event for web component usage - event will bubble up to the host element
72
- if (rootElement) {
73
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, orderedIds));
74
- }
75
- }
76
-
77
- function confirmOrder() {
78
- if (disabled || hasConfirmed) return;
79
-
80
- hasConfirmed = true;
81
- const currentOrder = orderedIds;
82
- response = currentOrder;
83
-
84
- // Call onChange callback if provided (for Svelte component usage)
85
- onChange?.(currentOrder);
86
- // Dispatch custom event for web component usage - event will bubble up to the host element
87
- if (rootElement) {
88
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, currentOrder));
89
- }
90
- }
91
-
92
- function getChoiceByIdentifier(identifier: string) {
93
- return parsedInteraction?.hotspotChoices.find((c) => c.identifier === identifier);
94
- }
95
- </script>
96
-
97
- <ShadowBaseStyles />
98
-
99
- <div bind:this={rootElement} part="root" class="qti-graphic-order-interaction">
100
- {#if !parsedInteraction}
101
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
102
- {:else}
103
- {#if parsedInteraction.prompt}
104
- <p part="prompt" class="qti-go-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
105
- {/if}
106
-
107
- <div part="layout" class="qti-go-layout flex flex-col gap-4">
108
- <!-- Image Area -->
109
- <div part="image-area" class="qti-go-image-area">
110
- <div
111
- bind:this={imageContainer}
112
- part="stage"
113
- class="qti-go-stage relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200"
114
- >
115
- {#if parsedInteraction.imageData}
116
- {#if parsedInteraction.imageData.type === 'svg' && parsedInteraction.imageData.content}
117
- <div
118
- bind:this={imageElement}
119
- class="w-full h-auto"
120
- style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData.height}px;"
121
- >
122
- {@html parsedInteraction.imageData.content}
123
- </div>
124
- {:else if parsedInteraction.imageData.src}
125
- <img
126
- bind:this={imageElement}
127
- src={parsedInteraction.imageData.src}
128
- alt={i18n?.t('interactions.graphicOrder.altText') ?? 'Ordering diagram'}
129
- class="w-full h-auto"
130
- style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData
131
- .height}px;"
132
- />
133
- {/if}
134
- {/if}
135
- </div>
136
- </div>
137
-
138
- <!-- Ordering Area -->
139
- <div part="panel" class="qti-go-panel w-full">
140
- <div class="qti-go-card card bg-base-100 border border-base-300">
141
- <div class="qti-go-card-body card-body p-4">
142
- <h3 part="panel-title" class="qti-go-title card-title text-sm">{i18n?.t('interactions.graphicOrder.orderHeading') ?? 'Order (drag to reorder)'}</h3>
143
- <SortableList
144
- items={parsedInteraction.hotspotChoices.map(c => ({ id: c.identifier, text: c.label }))}
145
- {orderedIds}
146
- correctOrder={isShowingCorrect ? (parsedCorrectResponse || []) : []}
147
- orientation="vertical"
148
- {disabled}
149
- onReorder={handleReorder}
150
- />
151
-
152
- <!-- Confirmation button for WCAG 2.2 SC 3.3.4 compliance -->
153
- <div part="confirm" class="qti-go-confirm mt-4 pt-3 border-t border-base-300">
154
- {#if needsConfirmation}
155
- <button
156
- type="button"
157
- class="btn btn-primary btn-sm w-full"
158
- onclick={confirmOrder}
159
- aria-label={i18n?.t('interactions.graphicOrder.confirmAria') ?? 'Confirm this order as your answer'}
160
- >
161
- {hasReordered
162
- ? (i18n?.t('interactions.graphicOrder.confirmOrder') ?? 'Confirm Order')
163
- : (i18n?.t('interactions.graphicOrder.confirmOrderNoChanges') ?? 'Confirm Order (No Changes)')}
164
- </button>
165
- <p class="text-xs text-base-content/60 mt-2 text-center">
166
- {i18n?.t('interactions.graphicOrder.instruction') ?? 'Drag to reorder, or click to confirm'}
167
- </p>
168
- {:else if hasConfirmed}
169
- <div class="alert alert-success py-2">
170
- <svg
171
- xmlns="http://www.w3.org/2000/svg"
172
- fill="none"
173
- viewBox="0 0 24 24"
174
- part="confirmed-icon"
175
- class="qti-icon qti-go-confirmed stroke-current shrink-0 w-5 h-5"
176
- >
177
- <path
178
- stroke-linecap="round"
179
- stroke-linejoin="round"
180
- stroke-width="2"
181
- d="M5 13l4 4L19 7"
182
- ></path>
183
- </svg>
184
- <span class="text-sm">Order confirmed</span>
185
- </div>
186
- {/if}
187
- </div>
188
- </div>
189
- </div>
190
- </div>
191
- </div>
192
- {/if}
193
- </div>
194
-
195
- <style>
196
- /* Ensure proper drag and drop visual feedback */
197
- :global(.qti-graphic-order-interaction [draggable='true']) {
198
- user-select: none;
199
- -webkit-user-drag: element;
200
- }
201
-
202
- /* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
203
- .qti-icon {
204
- width: 1.25rem;
205
- height: 1.25rem;
206
- flex: 0 0 auto;
207
- }
208
-
209
- /* Minimal layout so this works without Tailwind utilities */
210
- .qti-go-layout {
211
- display: flex;
212
- flex-direction: column;
213
- gap: 1rem;
214
- }
215
- .qti-go-image-area {
216
- width: 100%;
217
- }
218
- .qti-go-panel {
219
- width: 100%;
220
- }
221
- .qti-go-stage {
222
- position: relative;
223
- border-radius: 0.75rem;
224
- overflow: hidden;
225
- border: 2px solid var(--color-base-300, oklch(95% 0 0));
226
- background: var(--color-base-200, oklch(98% 0 0));
227
- }
228
- .qti-go-card {
229
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
230
- border-radius: 0.75rem;
231
- background: var(--color-base-100, oklch(100% 0 0));
232
- }
233
- .qti-go-card-body {
234
- padding: 1rem;
235
- }
236
- .qti-go-confirm {
237
- border-top: 1px solid var(--color-base-300, oklch(95% 0 0));
238
- padding-top: 0.75rem;
239
- margin-top: 1rem;
240
- }
241
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'graphicOrderInteraction',
5
- tagName: 'pie-qti-graphic-order',
6
- name: 'default-graphic-order',
7
- description: 'Default Svelte-based graphic order interaction',
8
- priority: 0,
9
- };
@@ -1,287 +0,0 @@
1
- <svelte:options customElement="pie-qti-hotspot" />
2
-
3
- <script lang="ts">
4
- import type { HotspotInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
8
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
-
10
- interface Props {
11
- interaction?: HotspotInteractionData | string;
12
- response?: string | null;
13
- correctResponse?: string | string[] | null;
14
- disabled?: boolean;
15
- role?: string;
16
- i18n?: I18nProvider;
17
- onChange?: (value: string) => void;
18
- }
19
-
20
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
21
-
22
- // Parse props that may be JSON strings (web component usage)
23
- const parsedInteraction = $derived(parseJsonProp<HotspotInteractionData>(interaction));
24
- const parsedResponse = $derived(parseJsonProp<string>(response));
25
- const parsedCorrectResponse = $derived(parseJsonProp<string | string[]>(correctResponse));
26
- const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
27
-
28
- // Get correct IDs as array
29
- const correctIds = $derived.by(() => {
30
- if (!isShowingCorrect) return [];
31
- if (Array.isArray(parsedCorrectResponse)) {
32
- return parsedCorrectResponse;
33
- }
34
- return parsedCorrectResponse ? [parsedCorrectResponse] : [];
35
- });
36
-
37
- function isCorrect(identifier: string): boolean {
38
- return isShowingCorrect && correctIds.includes(identifier);
39
- }
40
-
41
- // Get reference to the root element for event dispatching
42
- let rootElement: HTMLDivElement | undefined = $state();
43
-
44
- const imageWidth = $derived.by(() => {
45
- const w = parsedInteraction?.imageData?.width;
46
- const n = w ? Number(w) : NaN;
47
- return Number.isFinite(n) && n > 0 ? n : null;
48
- });
49
-
50
- const imageHeight = $derived.by(() => {
51
- const h = parsedInteraction?.imageData?.height;
52
- const n = h ? Number(h) : NaN;
53
- return Number.isFinite(n) && n > 0 ? n : null;
54
- });
55
-
56
- const mediaStyle = $derived.by(() => {
57
- if (imageWidth && imageHeight) {
58
- // Fill available width, but don't exceed the asset's natural width.
59
- return `width: 100%; max-width: ${imageWidth}px; aspect-ratio: ${imageWidth} / ${imageHeight};`;
60
- }
61
- return 'width: 100%;';
62
- });
63
-
64
- function handleClick(identifier: string) {
65
- if (!disabled) {
66
- response = identifier;
67
- // Call onChange callback if provided (for Svelte component usage)
68
- onChange?.(identifier);
69
- // Dispatch event for web component usage - event will bubble up to the host element
70
- if (rootElement) {
71
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, identifier));
72
- }
73
- }
74
- }
75
-
76
- function handleKeyDown(e: KeyboardEvent, identifier: string) {
77
- if (disabled) return;
78
- if (e.key === 'Enter' || e.key === ' ') {
79
- e.preventDefault();
80
- handleClick(identifier);
81
- }
82
- }
83
- </script>
84
-
85
- <ShadowBaseStyles />
86
-
87
- <div bind:this={rootElement} class={['qti-hotspot-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
88
- {#if !parsedInteraction}
89
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
90
- {:else}
91
- {#if parsedInteraction.prompt}
92
- <p part="prompt" class="qti-hotspot-prompt font-semibold">{@html parsedInteraction.prompt}</p>
93
- {/if}
94
-
95
- <div part="stage" class="qti-hotspot-stage">
96
- <div class="qti-hotspot-media" style={mediaStyle}>
97
- <!-- Render the image/SVG -->
98
- {#if parsedInteraction.imageData}
99
- {#if parsedInteraction.imageData.type === 'svg'}
100
- <div part="image" class="qti-hotspot-image">
101
- {@html parsedInteraction.imageData.content}
102
- </div>
103
- {:else}
104
- <img
105
- src={parsedInteraction.imageData.src}
106
- alt={i18n?.t('interactions.hotspot.altText') ?? 'Hotspot interaction'}
107
- part="image"
108
- class="qti-hotspot-image"
109
- />
110
- {/if}
111
- {/if}
112
-
113
- <!-- Overlay clickable areas using SVG -->
114
- <svg
115
- part="overlay"
116
- class="qti-hotspot-overlay"
117
- style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
118
- viewBox="0 0 {parsedInteraction.imageData?.width || '800'} {parsedInteraction.imageData?.height || '600'}"
119
- xmlns="http://www.w3.org/2000/svg"
120
- >
121
- {#each parsedInteraction.hotspotChoices as choice}
122
- {@const isSelected = parsedResponse === choice.identifier}
123
- {@const isCorrectChoice = isCorrect(choice.identifier)}
124
- {@const coords = choice.coords.split(',').map(Number)}
125
-
126
- {@const shapeLabel = choice.hotspotLabel || `Hotspot ${choice.identifier}`}
127
- {@const ariaLabel = `${shapeLabel}${isCorrectChoice ? '. Correct answer' : ''}`}
128
-
129
- {#if choice.shape === 'circle'}
130
- <!-- Circle: coords are cx, cy, radius -->
131
- <circle
132
- cx={coords[0]}
133
- cy={coords[1]}
134
- r={coords[2]}
135
- fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
136
- stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
137
- stroke-width="2"
138
- class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
139
- role="button"
140
- aria-label={ariaLabel}
141
- aria-pressed={isSelected ? 'true' : 'false'}
142
- tabindex={disabled ? -1 : 0}
143
- onclick={() => handleClick(choice.identifier)}
144
- onkeydown={(e) => handleKeyDown(e, choice.identifier)}
145
- />
146
- {:else if choice.shape === 'rect'}
147
- <!-- Rectangle: QTI coords are left,top,right,bottom -->
148
- <rect
149
- x={coords[0]}
150
- y={coords[1]}
151
- width={coords[2] - coords[0]}
152
- height={coords[3] - coords[1]}
153
- fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
154
- stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
155
- stroke-width="2"
156
- class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
157
- role="button"
158
- aria-label={ariaLabel}
159
- aria-pressed={isSelected ? 'true' : 'false'}
160
- tabindex={disabled ? -1 : 0}
161
- onclick={() => handleClick(choice.identifier)}
162
- onkeydown={(e) => handleKeyDown(e, choice.identifier)}
163
- />
164
- {:else if choice.shape === 'ellipse'}
165
- <!-- Ellipse: QTI coords are cx,cy,rx,ry -->
166
- <ellipse
167
- cx={coords[0]}
168
- cy={coords[1]}
169
- rx={coords[2]}
170
- ry={coords[3]}
171
- fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
172
- stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
173
- stroke-width="2"
174
- class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
175
- role="button"
176
- aria-label={ariaLabel}
177
- aria-pressed={isSelected ? 'true' : 'false'}
178
- tabindex={disabled ? -1 : 0}
179
- onclick={() => handleClick(choice.identifier)}
180
- onkeydown={(e) => handleKeyDown(e, choice.identifier)}
181
- />
182
- {:else if choice.shape === 'poly'}
183
- <!-- Polygon: coords are x1,y1,x2,y2,... -->
184
- {@const points = coords
185
- .reduce((acc: string[], val: number, idx: number) => {
186
- if (idx % 2 === 0 && idx + 1 < coords.length) {
187
- acc.push(`${coords[idx]},${coords[idx + 1]}`);
188
- }
189
- return acc;
190
- }, [])
191
- .join(' ')}
192
- <polygon
193
- {points}
194
- fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
195
- stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
196
- stroke-width="2"
197
- class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
198
- role="button"
199
- aria-label={ariaLabel}
200
- aria-pressed={isSelected ? 'true' : 'false'}
201
- tabindex={disabled ? -1 : 0}
202
- onclick={() => handleClick(choice.identifier)}
203
- onkeydown={(e) => handleKeyDown(e, choice.identifier)}
204
- />
205
- {/if}
206
- {/each}
207
- </svg>
208
- </div>
209
- </div>
210
-
211
- {#if parsedResponse || (isShowingCorrect && correctIds.length > 0)}
212
- <div part="selected" class="alert alert-info">
213
- {#if parsedResponse}
214
- <span>{i18n?.t('interactions.hotspot.selected') ?? 'Selected:'} {parsedResponse}</span>
215
- {/if}
216
- {#if isShowingCorrect && correctIds.length > 0}
217
- <span class="ml-2">Correct: {correctIds.join(', ')}</span>
218
- {/if}
219
- </div>
220
- {/if}
221
- {#if parsedInteraction.maxSelectionsMessage}
222
- {@const selected = Array.isArray(parsedResponse) ? parsedResponse : (parsedResponse ? [parsedResponse] : [])}
223
- {#if selected.length >= parsedInteraction.maxChoices && parsedInteraction.maxChoices > 0}
224
- <p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
225
- {/if}
226
- {/if}
227
- {/if}
228
- </div>
229
-
230
- <style>
231
- .qti-selection-message {
232
- font-size: 0.875rem;
233
- color: var(--color-warning, oklch(77% 0.194 82));
234
- margin-top: 0.25rem;
235
- }
236
-
237
- /* qti-selections-light / qti-selections-dark: hotspot overlay color theme */
238
- .qti-selections-light .qti-hotspot-shape {
239
- fill: rgba(255, 255, 255, 0.4);
240
- stroke: rgba(255, 255, 255, 0.8);
241
- }
242
- .qti-selections-dark .qti-hotspot-shape {
243
- fill: rgba(0, 0, 0, 0.4);
244
- stroke: rgba(0, 0, 0, 0.8);
245
- }
246
-
247
- /* Minimal layout so this works without Tailwind utilities */
248
- .qti-hotspot-interaction {
249
- display: grid;
250
- gap: 0.75rem;
251
- }
252
- .qti-hotspot-prompt {
253
- margin: 0;
254
- }
255
- .qti-hotspot-stage {
256
- position: relative;
257
- display: block;
258
- width: 100%;
259
- max-width: 100%;
260
- }
261
- .qti-hotspot-media {
262
- position: relative;
263
- }
264
- .qti-hotspot-image {
265
- display: block;
266
- width: 100%;
267
- height: 100%;
268
- }
269
- /* Inline SVG injected via {@html} is not scoped; use :global to size it inside the shadow root. */
270
- .qti-hotspot-image :global(svg) {
271
- width: 100%;
272
- height: 100%;
273
- display: block;
274
- }
275
- .qti-hotspot-overlay {
276
- position: absolute;
277
- inset: 0;
278
- cursor: pointer;
279
- }
280
- /* Tailwind `hover:` utilities won't exist everywhere; provide a real hover style too */
281
- .qti-hotspot-shape {
282
- transition: fill 120ms ease, stroke 120ms ease, opacity 120ms ease;
283
- }
284
- .qti-hotspot-shape:hover {
285
- fill: rgba(59, 130, 246, 0.1);
286
- }
287
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'hotspotInteraction',
5
- tagName: 'pie-qti-hotspot',
6
- name: 'default-hotspot',
7
- description: 'Default Svelte-based hotspot interaction',
8
- priority: 0,
9
- };