@pie-qti/default-components 0.1.9 → 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 (181) 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 +25958 -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 -2
  72. package/dist/shared/index.js +1 -2
  73. package/dist/shared/index.js.map +1 -0
  74. package/dist/shared/utils/eventHelpers.d.ts +6 -1
  75. package/dist/shared/utils/eventHelpers.js +7 -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 +16 -1
  84. package/dist/shared/utils/webComponentHelpers.js +13 -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 -310
  121. package/src/plugins/associate/index.ts +0 -9
  122. package/src/plugins/choice/ChoiceInteraction.svelte +0 -358
  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 -150
  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 -17
  174. package/src/shared/styles/shared.css +0 -16
  175. package/src/shared/utils/eventHelpers.ts +0 -52
  176. package/src/shared/utils/matchGroupUtils.ts +0 -14
  177. package/src/shared/utils/pairHelpers.ts +0 -109
  178. package/src/shared/utils/touchDragHelper.ts +0 -1
  179. package/src/shared/utils/webComponentHelpers.ts +0 -27
  180. package/src/svelte-shims.d.ts +0 -9
  181. /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
@@ -1,571 +0,0 @@
1
- <svelte:options customElement="pie-qti-select-point" />
2
-
3
- <script lang="ts">
4
- import type { Point, SelectPointInteractionData } 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?: SelectPointInteractionData | string;
12
- /**
13
- * QTI point responses are typically represented as a single "x y" string (cardinality=single),
14
- * or an array of "x y" strings (cardinality=multiple/ordered). Some UI layers may pass
15
- * an array of {x,y} points for convenience. We accept all of these and normalize internally.
16
- */
17
- response?: any;
18
- correctResponse?: any;
19
- disabled?: boolean;
20
- role?: string;
21
- i18n?: I18nProvider;
22
- onChange?: (value: any) => void;
23
- }
24
-
25
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
26
-
27
- // Parse props that may be JSON strings (web component usage)
28
- const parsedInteraction = $derived(parseJsonProp<SelectPointInteractionData>(interaction));
29
- const parsedResponse = $derived(parseJsonProp<any>(response));
30
- const parsedCorrectResponse = $derived(parseJsonProp<any>(correctResponse));
31
- const isShowingCorrect = $derived(
32
- role === 'scorer' && parsedCorrectResponse !== null && parsedCorrectResponse !== undefined
33
- );
34
-
35
- let selectedPoints = $state<Point[]>([]);
36
- let rootElement: HTMLDivElement | null = $state(null);
37
- let imageContainer: HTMLDivElement | null = $state(null);
38
- let imageElement: HTMLElement | null = $state(null);
39
-
40
- // Keyboard crosshair state (K-01)
41
- let crosshairActive = $state(false);
42
- let crosshairX = $state(0.5); // normalized 0-1
43
- let crosshairY = $state(0.5); // normalized 0-1
44
- let liveRegionText = $state('');
45
-
46
- /**
47
- * Parse correct response points (same format as user response)
48
- */
49
- function parsePoints(value: any): Point[] {
50
- if (!value) return [];
51
-
52
- if (Array.isArray(value)) {
53
- return value
54
- .map((v) => {
55
- if (typeof v === 'string') {
56
- const parts = v.trim().split(/\s+/);
57
- if (parts.length === 2) {
58
- const x = Number(parts[0]);
59
- const y = Number(parts[1]);
60
- if (!isNaN(x) && !isNaN(y)) {
61
- return { x, y } satisfies Point;
62
- }
63
- }
64
- return null;
65
- }
66
- if (v && typeof v === 'object' && v.x !== undefined && v.y !== undefined) {
67
- const x = Number(v.x);
68
- const y = Number(v.y);
69
- if (!isNaN(x) && !isNaN(y)) {
70
- return { x, y } satisfies Point;
71
- }
72
- }
73
- return null;
74
- })
75
- .filter(Boolean) as Point[];
76
- } else if (typeof value === 'string' && value.trim()) {
77
- const parts = value.trim().split(/\s+/);
78
- if (parts.length === 2) {
79
- const x = Number(parts[0]);
80
- const y = Number(parts[1]);
81
- if (!isNaN(x) && !isNaN(y)) {
82
- return [{ x, y }];
83
- }
84
- }
85
- } else if (value && typeof value === 'object' && value.x !== undefined && value.y !== undefined) {
86
- const x = Number(value.x);
87
- const y = Number(value.y);
88
- if (!isNaN(x) && !isNaN(y)) {
89
- return [{ x, y }];
90
- }
91
- }
92
- return [];
93
- }
94
-
95
- const correctPoints = $derived(
96
- isShowingCorrect && parsedCorrectResponse !== null && parsedCorrectResponse !== undefined
97
- ? parsePoints(parsedCorrectResponse)
98
- : []
99
- );
100
-
101
- $effect(() => {
102
- // Sync with parent response changes
103
- const r = parsedResponse;
104
- if (Array.isArray(r)) {
105
- // Array can be [{x,y}, ...] or ["x y", ...]
106
- selectedPoints = r
107
- .map((v) => {
108
- if (typeof v === 'string') {
109
- const parts = v.trim().split(/\s+/);
110
- if (parts.length === 2) return { x: Number(parts[0]), y: Number(parts[1]) } satisfies Point;
111
- return null;
112
- }
113
- if (v && typeof v === 'object' && v.x !== undefined && v.y !== undefined) {
114
- return { x: Number(v.x), y: Number(v.y) } satisfies Point;
115
- }
116
- return null;
117
- })
118
- .filter(Boolean) as Point[];
119
- } else if (typeof r === 'string') {
120
- const parts = r.trim().split(/\s+/);
121
- selectedPoints =
122
- parts.length === 2
123
- ? [{ x: Number(parts[0]), y: Number(parts[1]) }]
124
- : [];
125
- } else if (r && typeof r === 'object' && r.x !== undefined && r.y !== undefined) {
126
- selectedPoints = [{ x: Number(r.x), y: Number(r.y) }];
127
- } else {
128
- selectedPoints = [];
129
- }
130
- });
131
-
132
- /**
133
- * Check if selection limit has been reached
134
- */
135
- // maxChoices=0 means unlimited per QTI spec
136
- const canSelectMore = $derived(
137
- !parsedInteraction ||
138
- parsedInteraction.maxChoices === 0 ||
139
- selectedPoints.length < parsedInteraction.maxChoices
140
- );
141
-
142
- /**
143
- * Check if minimum selection requirement has been met
144
- */
145
- const hasMetMinChoices = $derived(
146
- parsedInteraction && selectedPoints.length >= parsedInteraction.minChoices
147
- );
148
-
149
- /**
150
- * Handle click on image to select a point
151
- */
152
- function handleImageClick(event: MouseEvent) {
153
- if (disabled || !canSelectMore || !imageElement || !parsedInteraction?.imageData) return;
154
-
155
- const rect = imageElement.getBoundingClientRect();
156
- const clickX = event.clientX - rect.left;
157
- const clickY = event.clientY - rect.top;
158
-
159
- // Convert to absolute coordinates matching the SVG/image coordinate system
160
- // The image is displayed at rect.width x rect.height but has intrinsic dimensions
161
- const intrinsicWidth = parseInt(parsedInteraction.imageData.width) || rect.width;
162
- const intrinsicHeight = parseInt(parsedInteraction.imageData.height) || rect.height;
163
-
164
- const x = Math.round((clickX / rect.width) * intrinsicWidth);
165
- const y = Math.round((clickY / rect.height) * intrinsicHeight);
166
-
167
- selectedPoints = [...selectedPoints, { x, y }];
168
-
169
- // QTI canonical value representation for baseType="point" is "x y"
170
- const canonicalValue =
171
- parsedInteraction.maxChoices === 1
172
- ? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
173
- : selectedPoints.map((p) => `${p.x} ${p.y}`);
174
- // Normalize outward response shape to canonical QTI form (even if inbound was legacy/object form).
175
- response = canonicalValue;
176
- // Call onChange callback if provided (for Svelte component usage)
177
- onChange?.(canonicalValue);
178
- // Dispatch event for web component usage - event will bubble up to the host element
179
- rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
180
- }
181
-
182
- /**
183
- * Remove a selected point
184
- */
185
- function removePoint(index: number) {
186
- if (disabled) return;
187
- selectedPoints = selectedPoints.filter((_, i) => i !== index);
188
- const canonicalValue =
189
- parsedInteraction?.maxChoices === 1
190
- ? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
191
- : selectedPoints.map((p) => `${p.x} ${p.y}`);
192
- response = canonicalValue;
193
- // Call onChange callback if provided (for Svelte component usage)
194
- onChange?.(canonicalValue);
195
- rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
196
- }
197
-
198
- /**
199
- * Clear all selected points
200
- */
201
- function clearAllPoints() {
202
- if (disabled) return;
203
- selectedPoints = [];
204
- const canonicalValue =
205
- parsedInteraction?.maxChoices === 1
206
- ? null
207
- : [];
208
- response = canonicalValue;
209
- // Call onChange callback if provided (for Svelte component usage)
210
- onChange?.(canonicalValue);
211
- rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
212
- }
213
-
214
- /**
215
- * Initialize image element reference
216
- */
217
- $effect(() => {
218
- if (imageContainer) {
219
- const img = imageContainer.querySelector('img, svg, object');
220
- if (img) {
221
- imageElement = img as HTMLElement;
222
- }
223
- }
224
- });
225
-
226
- /**
227
- * Place a point at the current crosshair position (K-01).
228
- * Converts normalized crosshair coords to intrinsic pixel coords.
229
- */
230
- function placePointAtCrosshair() {
231
- if (!canSelectMore || !parsedInteraction?.imageData) return;
232
-
233
- const intrinsicWidth = parseInt(parsedInteraction.imageData.width) || 500;
234
- const intrinsicHeight = parseInt(parsedInteraction.imageData.height) || 300;
235
-
236
- const x = Math.round(crosshairX * intrinsicWidth);
237
- const y = Math.round(crosshairY * intrinsicHeight);
238
-
239
- selectedPoints = [...selectedPoints, { x, y }];
240
-
241
- const canonicalValue =
242
- parsedInteraction.maxChoices === 1
243
- ? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
244
- : selectedPoints.map((p) => `${p.x} ${p.y}`);
245
- response = canonicalValue;
246
- onChange?.(canonicalValue);
247
- rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
248
- }
249
-
250
- /**
251
- * Handle keyboard events on the image container (K-01).
252
- * Arrow keys move the crosshair; Enter/Space place a point.
253
- */
254
- function handleKeydown(e: KeyboardEvent) {
255
- if (disabled) return;
256
-
257
- const LARGE_STEP = 0.05; // 5% per arrow key press
258
- const SMALL_STEP = 0.01; // 1% with Shift for fine control
259
-
260
- switch (e.key) {
261
- case 'ArrowLeft':
262
- case 'ArrowRight':
263
- case 'ArrowUp':
264
- case 'ArrowDown': {
265
- e.preventDefault();
266
- const step = e.shiftKey ? SMALL_STEP : LARGE_STEP;
267
- if (e.key === 'ArrowLeft') crosshairX = Math.max(0, crosshairX - step);
268
- if (e.key === 'ArrowRight') crosshairX = Math.min(1, crosshairX + step);
269
- if (e.key === 'ArrowUp') crosshairY = Math.max(0, crosshairY - step);
270
- if (e.key === 'ArrowDown') crosshairY = Math.min(1, crosshairY + step);
271
-
272
- const xPct = Math.round(crosshairX * 100);
273
- const yPct = Math.round(crosshairY * 100);
274
- liveRegionText = `Position: ${xPct}%, ${yPct}%`;
275
- break;
276
- }
277
- case 'Enter':
278
- case ' ':
279
- e.preventDefault();
280
- if (canSelectMore) {
281
- placePointAtCrosshair();
282
- }
283
- break;
284
- }
285
- }
286
-
287
- function handleFocus() {
288
- crosshairActive = true;
289
- crosshairX = 0.5;
290
- crosshairY = 0.5;
291
- liveRegionText = 'Position: 50%, 50%';
292
- }
293
-
294
- function handleBlur() {
295
- crosshairActive = false;
296
- liveRegionText = '';
297
- }
298
- </script>
299
-
300
- <ShadowBaseStyles />
301
-
302
- <div bind:this={rootElement} class="qti-select-point-interaction">
303
- {#if !parsedInteraction}
304
- <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
305
- {:else}
306
- {#if parsedInteraction.prompt}
307
- <p class="font-semibold mb-3">{@html parsedInteraction.prompt}</p>
308
- {/if}
309
-
310
- <div class="space-y-3">
311
-
312
- <!-- Visually-hidden live region announces crosshair position to screen readers -->
313
- <span
314
- aria-live="polite"
315
- aria-atomic="true"
316
- style="position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;"
317
- >{liveRegionText}</span>
318
-
319
- <div
320
- bind:this={imageContainer}
321
- class="image-container relative inline-block"
322
- style={disabled ? 'cursor: default;' : 'cursor: crosshair;'}
323
- role="button"
324
- tabindex={disabled ? -1 : 0}
325
- aria-label={i18n?.t('interactions.selectPoint.instructionAria') ?? 'Click or use arrow keys to position crosshair, then press Enter or Space to select a point on the image'}
326
- onclick={handleImageClick}
327
- onkeydown={handleKeydown}
328
- onfocus={handleFocus}
329
- onblur={handleBlur}
330
- >
331
- {#if parsedInteraction.imageData}
332
- {#if parsedInteraction.imageData.type === 'svg'}
333
- <div
334
- style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData.height}px; position: relative;"
335
- >
336
- {@html parsedInteraction.imageData.content}
337
- </div>
338
- {:else if parsedInteraction.imageData.src}
339
- <img
340
- src={parsedInteraction.imageData.src}
341
- alt={i18n?.t('interactions.selectPoint.canvas') ?? 'Selection canvas'}
342
- style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData.height}px; position: relative; z-index: 1;"
343
- class="block"
344
- />
345
- {/if}
346
-
347
- <!-- Render selected points as markers -->
348
- {#each selectedPoints as point, index}
349
- {@const intrinsicWidth = parseInt(parsedInteraction.imageData?.width || '500')}
350
- {@const intrinsicHeight = parseInt(parsedInteraction.imageData?.height || '300')}
351
- {@const xPercent = (point.x / intrinsicWidth) * 100}
352
- {@const yPercent = (point.y / intrinsicHeight) * 100}
353
- {@const isCorrect = isShowingCorrect && correctPoints.some((p) => Math.abs(p.x - point.x) < 1 && Math.abs(p.y - point.y) < 1)}
354
- <button
355
- type="button"
356
- class="point-marker"
357
- class:point-marker-correct={isCorrect}
358
- style="left: {xPercent}%; top: {yPercent}%; z-index: 100;"
359
- onclick={(e) => {
360
- e.stopPropagation();
361
- removePoint(index);
362
- }}
363
- aria-label="Remove point {index + 1} at coordinates {point.x}, {point.y}{isCorrect ? '. Correct answer' : ''}"
364
- title="Click to remove this point ({point.x}, {point.y}){isCorrect ? ' - Correct' : ''}"
365
- {disabled}
366
- >
367
- <span class="point-number">{isCorrect ? '✓' : index + 1}</span>
368
- </button>
369
- {/each}
370
-
371
- <!-- Render correct points as markers (when in scorer mode and not already selected) -->
372
- {#if isShowingCorrect && correctPoints.length > 0}
373
- {#each correctPoints as point, index}
374
- {@const intrinsicWidth = parseInt(parsedInteraction.imageData?.width || '500')}
375
- {@const intrinsicHeight = parseInt(parsedInteraction.imageData?.height || '300')}
376
- {@const xPercent = (point.x / intrinsicWidth) * 100}
377
- {@const yPercent = (point.y / intrinsicHeight) * 100}
378
- {@const isAlreadySelected = selectedPoints.some((p) => Math.abs(p.x - point.x) < 1 && Math.abs(p.y - point.y) < 1)}
379
- <div
380
- part="correct-point"
381
- class="point-marker point-marker-correct"
382
- style="left: {xPercent}%; top: {yPercent}%; pointer-events: none; z-index: 200;"
383
- aria-label="Correct answer point at coordinates {point.x}, {point.y}"
384
- title="Correct answer: ({point.x}, {point.y})"
385
- >
386
- <span class="point-number">✓</span>
387
- </div>
388
- {/each}
389
- {/if}
390
- {:else}
391
- <div
392
- class="no-image-placeholder bg-base-200 flex items-center justify-center"
393
- style="width: 500px; height: 300px;"
394
- >
395
- <p class="text-base-content/50">{i18n?.t('interactions.selectPoint.noImage') ?? 'No image provided'}</p>
396
- </div>
397
- {/if}
398
-
399
- <!-- Keyboard crosshair overlay (K-01) — visible only when container has focus -->
400
- {#if crosshairActive && !disabled && parsedInteraction?.imageData}
401
- {@const imgW = parseInt(parsedInteraction.imageData.width) || 500}
402
- {@const imgH = parseInt(parsedInteraction.imageData.height) || 300}
403
- {@const cx = crosshairX * imgW}
404
- {@const cy = crosshairY * imgH}
405
- <svg
406
- aria-hidden="true"
407
- class="crosshair-overlay"
408
- style="width: {imgW}px; height: {imgH}px;"
409
- viewBox="0 0 {imgW} {imgH}"
410
- xmlns="http://www.w3.org/2000/svg"
411
- >
412
- <!-- Horizontal line -->
413
- <line x1="0" y1={cy} x2={imgW} y2={cy} class="crosshair-line" />
414
- <!-- Vertical line -->
415
- <line x1={cx} y1="0" x2={cx} y2={imgH} class="crosshair-line" />
416
- <!-- Centre dot -->
417
- <circle cx={cx} cy={cy} r="5" class="crosshair-dot" />
418
- </svg>
419
- {/if}
420
- </div>
421
-
422
- <div class="flex items-center justify-between text-sm text-base-content/70">
423
- <div>
424
- <span class="font-medium">Points selected:</span>
425
- <span class="ml-2">{selectedPoints.length} / {parsedInteraction.maxChoices}</span>
426
- {#if parsedInteraction.minChoices > 0}
427
- <span class="ml-2">
428
- {#if hasMetMinChoices}
429
- <span class="badge badge-success badge-sm">✓ Minimum met</span>
430
- {:else}
431
- <span class="badge badge-warning badge-sm">
432
- Select at least {parsedInteraction.minChoices}
433
- </span>
434
- {/if}
435
- </span>
436
- {/if}
437
- </div>
438
-
439
- {#if selectedPoints.length > 0}
440
- <button type="button" class="btn btn-sm btn-ghost" onclick={clearAllPoints} {disabled}>
441
- Clear All
442
- </button>
443
- {/if}
444
- </div>
445
-
446
- {#if !canSelectMore}
447
- <div class="alert alert-info">
448
- <svg
449
- xmlns="http://www.w3.org/2000/svg"
450
- fill="none"
451
- viewBox="0 0 24 24"
452
- part="limit-icon"
453
- class="qti-icon stroke-current shrink-0 w-6 h-6"
454
- >
455
- <path
456
- stroke-linecap="round"
457
- stroke-linejoin="round"
458
- stroke-width="2"
459
- d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
460
- ></path>
461
- </svg>
462
- <span>Maximum points reached. Remove a point to add a new one.</span>
463
- </div>
464
- {/if}
465
- </div>
466
- {/if}
467
- </div>
468
-
469
- <style>
470
- /* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
471
- .qti-icon {
472
- width: 1.5rem;
473
- height: 1.5rem;
474
- flex: 0 0 auto;
475
- }
476
-
477
- .image-container {
478
- position: relative;
479
- display: inline-block;
480
- border: 2px solid hsl(var(--bc) / 0.2);
481
- border-radius: 8px;
482
- overflow: hidden;
483
- }
484
-
485
- .point-marker {
486
- position: absolute;
487
- width: 32px;
488
- height: 32px;
489
- transform: translate(-50%, -50%);
490
- background-color: hsl(var(--p));
491
- border: 3px solid white;
492
- border-radius: 50%;
493
- display: flex;
494
- align-items: center;
495
- justify-content: center;
496
- cursor: pointer;
497
- transition: all 0.2s;
498
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
499
- }
500
-
501
- .point-marker:hover {
502
- background-color: hsl(var(--er));
503
- transform: translate(-50%, -50%) scale(1.1);
504
- }
505
-
506
- .point-marker:disabled {
507
- cursor: not-allowed;
508
- opacity: 0.6;
509
- }
510
-
511
- .point-marker-correct {
512
- background-color: #10b981 !important;
513
- border-color: white !important;
514
- border-width: 4px !important;
515
- cursor: default;
516
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 4px #10b981 !important;
517
- width: 50px !important;
518
- height: 50px !important;
519
- z-index: 200 !important;
520
- position: absolute !important;
521
- opacity: 1 !important;
522
- display: flex !important;
523
- align-items: center !important;
524
- justify-content: center !important;
525
- }
526
-
527
- .point-marker-correct .point-number {
528
- font-size: 28px !important;
529
- font-weight: 900 !important;
530
- color: white !important;
531
- line-height: 1 !important;
532
- display: block !important;
533
- }
534
-
535
- .point-marker-correct:hover {
536
- background-color: var(--color-success, oklch(76% 0.177 163.223));
537
- transform: translate(-50%, -50%);
538
- }
539
-
540
- .point-number {
541
- color: white;
542
- font-weight: 700;
543
- font-size: 14px;
544
- }
545
-
546
- .no-image-placeholder {
547
- border: 2px dashed hsl(var(--bc) / 0.2);
548
- border-radius: 8px;
549
- }
550
-
551
- /* K-01 keyboard crosshair overlay */
552
- .crosshair-overlay {
553
- position: absolute;
554
- top: 0;
555
- left: 0;
556
- pointer-events: none;
557
- z-index: 150;
558
- }
559
-
560
- .crosshair-line {
561
- stroke: #2563eb;
562
- stroke-width: 1.5;
563
- stroke-dasharray: 4 3;
564
- opacity: 0.85;
565
- }
566
-
567
- .crosshair-dot {
568
- fill: #2563eb;
569
- opacity: 0.9;
570
- }
571
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'selectPointInteraction',
5
- tagName: 'pie-qti-select-point',
6
- name: 'default-select-point',
7
- description: 'Default Svelte-based select point interaction',
8
- priority: 0,
9
- };