@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.
- package/dist/chunks/__vite-browser-external-BjvdLQIS.js +9 -0
- package/dist/chunks/__vite-browser-external-BjvdLQIS.js.map +1 -0
- package/dist/chunks/chunk-Bayd9M4T.js +20 -0
- package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-CAPebTxM.js} +245 -29
- package/dist/chunks/{mathlive.min-Bvtiaxg4.js.map → mathlive.min-CAPebTxM.js.map} +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/associate/index.d.ts +0 -1
- package/dist/plugins/associate/index.js +1 -0
- package/dist/plugins/associate/index.js.map +1 -0
- package/dist/plugins/choice/index.d.ts +0 -1
- package/dist/plugins/choice/index.js +1 -0
- package/dist/plugins/choice/index.js.map +1 -0
- package/dist/plugins/custom/index.d.ts +0 -1
- package/dist/plugins/custom/index.js +1 -0
- package/dist/plugins/custom/index.js.map +1 -0
- package/dist/plugins/end-attempt/index.d.ts +0 -1
- package/dist/plugins/end-attempt/index.js +1 -0
- package/dist/plugins/end-attempt/index.js.map +1 -0
- package/dist/plugins/extended-text/index.d.ts +0 -1
- package/dist/plugins/extended-text/index.js +1 -0
- package/dist/plugins/extended-text/index.js.map +1 -0
- package/dist/plugins/gap-match/index.d.ts +0 -1
- package/dist/plugins/gap-match/index.js +1 -0
- package/dist/plugins/gap-match/index.js.map +1 -0
- package/dist/plugins/graphic-associate/index.d.ts +0 -1
- package/dist/plugins/graphic-associate/index.js +1 -0
- package/dist/plugins/graphic-associate/index.js.map +1 -0
- package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
- package/dist/plugins/graphic-gap-match/index.js +1 -0
- package/dist/plugins/graphic-gap-match/index.js.map +1 -0
- package/dist/plugins/graphic-order/index.d.ts +0 -1
- package/dist/plugins/graphic-order/index.js +1 -0
- package/dist/plugins/graphic-order/index.js.map +1 -0
- package/dist/plugins/hotspot/index.d.ts +0 -1
- package/dist/plugins/hotspot/index.js +1 -0
- package/dist/plugins/hotspot/index.js.map +1 -0
- package/dist/plugins/hottext/index.d.ts +0 -1
- package/dist/plugins/hottext/index.js +1 -0
- package/dist/plugins/hottext/index.js.map +1 -0
- package/dist/plugins/match/index.d.ts +0 -1
- package/dist/plugins/match/index.js +1 -0
- package/dist/plugins/match/index.js.map +1 -0
- package/dist/plugins/media/index.d.ts +0 -1
- package/dist/plugins/media/index.js +1 -0
- package/dist/plugins/media/index.js.map +1 -0
- package/dist/plugins/order/index.d.ts +0 -1
- package/dist/plugins/order/index.js +1 -0
- package/dist/plugins/order/index.js.map +1 -0
- package/dist/plugins/position-object/index.d.ts +0 -1
- package/dist/plugins/position-object/index.js +1 -0
- package/dist/plugins/position-object/index.js.map +1 -0
- package/dist/plugins/public-types.d.ts +5 -0
- package/dist/plugins/public-types.js +2 -0
- package/dist/plugins/public-types.js.map +1 -0
- package/dist/plugins/select-point/index.d.ts +0 -1
- package/dist/plugins/select-point/index.js +1 -0
- package/dist/plugins/select-point/index.js.map +1 -0
- package/dist/plugins/slider/index.d.ts +0 -1
- package/dist/plugins/slider/index.js +1 -0
- package/dist/plugins/slider/index.js.map +1 -0
- package/dist/plugins.js +25917 -7690
- package/dist/plugins.js.map +1 -1
- package/dist/shared/actions/typesetAction.d.ts +0 -1
- package/dist/shared/actions/typesetAction.js +1 -0
- package/dist/shared/actions/typesetAction.js.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
- package/dist/shared/extensions/MathLiveEditor.js +1 -0
- package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.js +1 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/utils/eventHelpers.d.ts +0 -1
- package/dist/shared/utils/eventHelpers.js +1 -0
- package/dist/shared/utils/eventHelpers.js.map +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
- package/dist/shared/utils/matchGroupUtils.js +1 -0
- package/dist/shared/utils/matchGroupUtils.js.map +1 -0
- package/dist/shared/utils/pairHelpers.d.ts +0 -1
- package/dist/shared/utils/pairHelpers.js +1 -0
- package/dist/shared/utils/pairHelpers.js.map +1 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +0 -1
- package/dist/shared/utils/webComponentHelpers.js +1 -0
- package/dist/shared/utils/webComponentHelpers.js.map +1 -0
- package/package.json +11 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/associate/index.d.ts.map +0 -1
- package/dist/plugins/choice/index.d.ts.map +0 -1
- package/dist/plugins/custom/index.d.ts.map +0 -1
- package/dist/plugins/end-attempt/index.d.ts.map +0 -1
- package/dist/plugins/extended-text/index.d.ts.map +0 -1
- package/dist/plugins/gap-match/index.d.ts.map +0 -1
- package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
- package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
- package/dist/plugins/graphic-order/index.d.ts.map +0 -1
- package/dist/plugins/hotspot/index.d.ts.map +0 -1
- package/dist/plugins/hottext/index.d.ts.map +0 -1
- package/dist/plugins/index.d.ts +0 -31
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -31
- package/dist/plugins/match/index.d.ts.map +0 -1
- package/dist/plugins/media/index.d.ts.map +0 -1
- package/dist/plugins/order/index.d.ts.map +0 -1
- package/dist/plugins/position-object/index.d.ts.map +0 -1
- package/dist/plugins/select-point/index.d.ts.map +0 -1
- package/dist/plugins/slider/index.d.ts.map +0 -1
- package/dist/shared/actions/typesetAction.d.ts.map +0 -1
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
- package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
- package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
- package/dist/shared/utils/touchDragHelper.d.ts +0 -2
- package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
- package/dist/shared/utils/touchDragHelper.js +0 -1
- package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
- package/src/catalog/CatalogPopup.svelte +0 -163
- package/src/index.ts +0 -141
- package/src/plugins/associate/AssociateInteraction.svelte +0 -304
- package/src/plugins/associate/index.ts +0 -9
- package/src/plugins/choice/ChoiceInteraction.svelte +0 -355
- package/src/plugins/choice/index.ts +0 -9
- package/src/plugins/custom/CustomInteraction.svelte +0 -61
- package/src/plugins/custom/index.ts +0 -9
- package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
- package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
- package/src/plugins/end-attempt/index.ts +0 -9
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -152
- package/src/plugins/extended-text/index.ts +0 -9
- package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
- package/src/plugins/gap-match/index.ts +0 -9
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
- package/src/plugins/graphic-associate/index.ts +0 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
- package/src/plugins/graphic-gap-match/index.ts +0 -9
- package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
- package/src/plugins/graphic-order/index.ts +0 -9
- package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
- package/src/plugins/hotspot/index.ts +0 -9
- package/src/plugins/hottext/HottextInteraction.svelte +0 -325
- package/src/plugins/hottext/index.ts +0 -9
- package/src/plugins/index.ts +0 -32
- package/src/plugins/match/MatchInteraction.svelte +0 -82
- package/src/plugins/match/index.ts +0 -9
- package/src/plugins/media/MediaInteraction.svelte +0 -216
- package/src/plugins/media/index.ts +0 -9
- package/src/plugins/order/OrderInteraction.svelte +0 -280
- package/src/plugins/order/index.ts +0 -9
- package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
- package/src/plugins/position-object/README.md +0 -130
- package/src/plugins/position-object/index.ts +0 -9
- package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
- package/src/plugins/select-point/index.ts +0 -9
- package/src/plugins/slider/SliderInteraction.svelte +0 -141
- package/src/plugins/slider/index.ts +0 -9
- package/src/plugins/upload/UploadInteraction.svelte +0 -59
- package/src/shared/actions/typesetAction.ts +0 -87
- package/src/shared/components/CustomInteractionFallback.svelte +0 -153
- package/src/shared/components/DragHandle.svelte +0 -44
- package/src/shared/components/DrawingCanvas.svelte +0 -259
- package/src/shared/components/FileUpload.svelte +0 -158
- package/src/shared/components/GraphicGapMatch.svelte +0 -318
- package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
- package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
- package/src/shared/components/MatchDragDrop.svelte +0 -481
- package/src/shared/components/MathContent.svelte +0 -18
- package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
- package/src/shared/components/RichTextEditor.svelte +0 -316
- package/src/shared/components/ShadowBaseStyles.svelte +0 -390
- package/src/shared/components/SortableList.svelte +0 -297
- package/src/shared/extensions/MathLiveEditor.ts +0 -299
- package/src/shared/index.ts +0 -15
- package/src/shared/styles/shared.css +0 -16
- package/src/shared/utils/eventHelpers.ts +0 -69
- package/src/shared/utils/matchGroupUtils.ts +0 -14
- package/src/shared/utils/pairHelpers.ts +0 -109
- package/src/shared/utils/webComponentHelpers.ts +0 -69
- package/src/svelte-shims.d.ts +0 -9
- /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
|
@@ -1,903 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-position-object" />
|
|
2
|
-
|
|
3
|
-
<!--
|
|
4
|
-
QTI 2.2 Position Object Interaction Component
|
|
5
|
-
|
|
6
|
-
⚠️ IMPORTANT LIMITATIONS ⚠️
|
|
7
|
-
|
|
8
|
-
This interaction type has severe limitations in the QTI 2.2 specification that make it
|
|
9
|
-
impractical for most educational use cases. After extensive research, we found:
|
|
10
|
-
|
|
11
|
-
1. NO real-world implementations beyond the official spec example
|
|
12
|
-
2. NOT included in QTI 3.0 shared vocabulary/styling guide (likely deprecated)
|
|
13
|
-
3. Major QTI platforms (TAO, Citolab) show no prominent support
|
|
14
|
-
4. Only suitable for very narrow use cases
|
|
15
|
-
|
|
16
|
-
THE CORE PROBLEM:
|
|
17
|
-
- Response format is baseType="point" which only stores coordinates: ["158 168", "210 195"]
|
|
18
|
-
- There is NO way to track WHICH object was placed WHERE
|
|
19
|
-
- The spec only supports placing multiple copies of the SAME object (like airport icons)
|
|
20
|
-
- It CANNOT support the obvious use case: "Place these labeled cities on the map"
|
|
21
|
-
|
|
22
|
-
SPEC-COMPLIANT USAGE (Airport Example):
|
|
23
|
-
- One draggable object (airport icon) that can be placed multiple times
|
|
24
|
-
- Response is just an array of coordinates
|
|
25
|
-
- Scoring uses areaMapping to check if ANY placement hits target zones
|
|
26
|
-
- No object identity tracking needed
|
|
27
|
-
|
|
28
|
-
NON-STANDARD EXTENSION (Current Implementation):
|
|
29
|
-
- This component supports multiple positionObjectStage elements with identifiers
|
|
30
|
-
- It tracks which stage (object) is at which position internally
|
|
31
|
-
- BUT the QTI response format cannot preserve this information
|
|
32
|
-
- On reload, objects are mapped to positions by array order (best effort)
|
|
33
|
-
|
|
34
|
-
RECOMMENDATION:
|
|
35
|
-
For labeled-object placement scenarios, use graphicGapMatchInteraction instead,
|
|
36
|
-
which uses baseType="directedPair" to properly track object+location pairs.
|
|
37
|
-
|
|
38
|
-
This implementation exists for QTI 2.2 compatibility but has limited practical utility.
|
|
39
|
-
-->
|
|
40
|
-
|
|
41
|
-
<script lang="ts">
|
|
42
|
-
import type { PositionObjectInteractionData } from '@pie-qti/item-player';
|
|
43
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
44
|
-
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
45
|
-
import DragHandle from '../../shared/components/DragHandle.svelte';
|
|
46
|
-
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
47
|
-
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
|
|
48
|
-
|
|
49
|
-
interface Position {
|
|
50
|
-
stageId: string;
|
|
51
|
-
x: number;
|
|
52
|
-
y: number;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface Props {
|
|
56
|
-
interaction?: PositionObjectInteractionData | string;
|
|
57
|
-
response?: string[] | null; // QTI format: array of "x y" strings
|
|
58
|
-
correctResponse?: string[] | null; // QTI format: array of "x y" strings
|
|
59
|
-
disabled?: boolean;
|
|
60
|
-
role?: string;
|
|
61
|
-
i18n?: I18nProvider;
|
|
62
|
-
onChange?: (value: string[]) => void;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
|
|
66
|
-
|
|
67
|
-
// Parse props that may be JSON strings (web component usage)
|
|
68
|
-
const parsedInteraction = $derived(parseJsonProp<PositionObjectInteractionData>(interaction));
|
|
69
|
-
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
70
|
-
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
71
|
-
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null && parsedCorrectResponse !== undefined);
|
|
72
|
-
|
|
73
|
-
// Get reference to the root element for event dispatching
|
|
74
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
75
|
-
|
|
76
|
-
// Positions stored as {stageId, x, y}
|
|
77
|
-
let positions = $state<Position[]>([]);
|
|
78
|
-
let draggedStageId: string | null = $state(null);
|
|
79
|
-
let draggedPositionIndex: number | null = $state(null);
|
|
80
|
-
// imageContainer / imageContainer are the same element — one binding covers both roles
|
|
81
|
-
let imageContainer: HTMLDivElement | null = $state(null);
|
|
82
|
-
|
|
83
|
-
// Keyboard accessibility state (K-04)
|
|
84
|
-
let selectedStageId: string | null = $state(null); // stage currently being keyboard-positioned
|
|
85
|
-
let crosshairX = $state(0.5); // normalized [0,1] x position on background image
|
|
86
|
-
let crosshairY = $state(0.5); // normalized [0,1] y position on background image
|
|
87
|
-
let crosshairActive = $state(false); // whether the crosshair is visible/active
|
|
88
|
-
let liveMessage = $state(''); // message for aria-live region
|
|
89
|
-
|
|
90
|
-
const canInteract = $derived(!disabled);
|
|
91
|
-
const canAddMore = $derived(
|
|
92
|
-
!parsedInteraction || parsedInteraction.maxChoices === 0 || positions.length < parsedInteraction.maxChoices
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// Calculate scale factor based on actual vs original image dimensions
|
|
96
|
-
const scaleFactor = $derived.by(() => {
|
|
97
|
-
if (!imageContainer || !parsedInteraction?.imageData?.width) return 1;
|
|
98
|
-
const actualWidth = imageContainer.offsetWidth;
|
|
99
|
-
const originalWidth = Number(parsedInteraction.imageData.width);
|
|
100
|
-
return actualWidth / originalWidth;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
$effect(() => {
|
|
104
|
-
// Sync with parent response changes - convert QTI point format back to internal Position format
|
|
105
|
-
// NOTE: This is best-effort reconstruction since QTI baseType="point" doesn't store object identity
|
|
106
|
-
// We map points to stages by array order, which works for single-stage scenarios but may
|
|
107
|
-
// produce incorrect results for multi-stage scenarios if objects were placed in different order
|
|
108
|
-
if (!parsedResponse || parsedResponse.length === 0) {
|
|
109
|
-
positions = [];
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Convert QTI point strings ("x y") back to Position objects with stageIds
|
|
114
|
-
// Map each point to stages in order - assumes response array order matches stage order
|
|
115
|
-
const newPositions: Position[] = [];
|
|
116
|
-
const stages = parsedInteraction?.positionObjectStages || [];
|
|
117
|
-
|
|
118
|
-
for (let i = 0; i < parsedResponse.length; i++) {
|
|
119
|
-
const pointStr = parsedResponse[i];
|
|
120
|
-
if (typeof pointStr !== 'string') continue;
|
|
121
|
-
const parts = pointStr.trim().split(/\s+/);
|
|
122
|
-
if (parts.length >= 2) {
|
|
123
|
-
const x = parseFloat(parts[0]);
|
|
124
|
-
const y = parseFloat(parts[1]);
|
|
125
|
-
|
|
126
|
-
// Determine which stage this point belongs to
|
|
127
|
-
// For simple cases with one stage, all points belong to that stage
|
|
128
|
-
// For multiple stages, we need to map based on order and matchMax constraints
|
|
129
|
-
let stageId = '';
|
|
130
|
-
if (stages.length === 1) {
|
|
131
|
-
// Single stage - all points belong to it
|
|
132
|
-
stageId = stages[0].identifier;
|
|
133
|
-
} else {
|
|
134
|
-
// Multiple stages - distribute points based on stage order and matchMax
|
|
135
|
-
let pointIndex = 0;
|
|
136
|
-
for (const stage of stages) {
|
|
137
|
-
if (pointIndex + stage.matchMax > i) {
|
|
138
|
-
stageId = stage.identifier;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
pointIndex += stage.matchMax;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (stageId && !isNaN(x) && !isNaN(y)) {
|
|
146
|
-
newPositions.push({ stageId, x, y });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
positions = newPositions;
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
function handleDragStart(event: DragEvent, stageId: string, existingIndex?: number) {
|
|
155
|
-
if (!canInteract) return;
|
|
156
|
-
draggedStageId = stageId;
|
|
157
|
-
draggedPositionIndex = existingIndex ?? null;
|
|
158
|
-
|
|
159
|
-
// Set drag image to be the object being dragged
|
|
160
|
-
if (event.dataTransfer) {
|
|
161
|
-
event.dataTransfer.effectAllowed = 'move';
|
|
162
|
-
|
|
163
|
-
// Create a custom drag image at full size
|
|
164
|
-
const stage = getStageById(stageId);
|
|
165
|
-
if (stage?.objectData) {
|
|
166
|
-
const width = parseInt(stage.objectData.width || '50');
|
|
167
|
-
const height = parseInt(stage.objectData.height || '50');
|
|
168
|
-
|
|
169
|
-
// Create a temporary element for the drag image
|
|
170
|
-
const dragImage = document.createElement('div');
|
|
171
|
-
dragImage.style.position = 'absolute';
|
|
172
|
-
dragImage.style.left = '-9999px';
|
|
173
|
-
dragImage.style.width = `${width}px`;
|
|
174
|
-
dragImage.style.height = `${height}px`;
|
|
175
|
-
|
|
176
|
-
if (stage.objectData.type === 'svg' && stage.objectData.content) {
|
|
177
|
-
dragImage.innerHTML = stage.objectData.content;
|
|
178
|
-
} else if (stage.objectData.src) {
|
|
179
|
-
const img = document.createElement('img');
|
|
180
|
-
img.src = stage.objectData.src;
|
|
181
|
-
img.style.width = '100%';
|
|
182
|
-
img.style.height = '100%';
|
|
183
|
-
dragImage.appendChild(img);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
document.body.appendChild(dragImage);
|
|
187
|
-
event.dataTransfer.setDragImage(dragImage, width / 2, height / 2);
|
|
188
|
-
|
|
189
|
-
// Clean up after a short delay
|
|
190
|
-
setTimeout(() => document.body.removeChild(dragImage), 0);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function handleDrop(event: DragEvent) {
|
|
196
|
-
if (!canInteract || !draggedStageId || !imageContainer) return;
|
|
197
|
-
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
|
|
200
|
-
// Get drop coordinates relative to the image container
|
|
201
|
-
const rect = imageContainer.getBoundingClientRect();
|
|
202
|
-
let x = event.clientX - rect.left;
|
|
203
|
-
let y = event.clientY - rect.top;
|
|
204
|
-
|
|
205
|
-
// Convert scaled coordinates back to original image coordinates
|
|
206
|
-
x = x / scaleFactor;
|
|
207
|
-
y = y / scaleFactor;
|
|
208
|
-
|
|
209
|
-
// If centerPoint is true, adjust coordinates to be at the center
|
|
210
|
-
if (parsedInteraction?.centerPoint) {
|
|
211
|
-
const stage = parsedInteraction.positionObjectStages.find((s) => s.identifier === draggedStageId);
|
|
212
|
-
if (stage?.objectData) {
|
|
213
|
-
const width = parseInt(stage.objectData.width || '50');
|
|
214
|
-
const height = parseInt(stage.objectData.height || '50');
|
|
215
|
-
x -= width / 2;
|
|
216
|
-
y -= height / 2;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Check if we're moving an existing position or creating a new one
|
|
221
|
-
if (draggedPositionIndex !== null) {
|
|
222
|
-
// Moving existing position
|
|
223
|
-
positions = positions.map((pos, idx) =>
|
|
224
|
-
idx === draggedPositionIndex ? { ...pos, x, y } : pos
|
|
225
|
-
);
|
|
226
|
-
} else {
|
|
227
|
-
// Creating new position
|
|
228
|
-
if (!parsedInteraction) return;
|
|
229
|
-
const stage = parsedInteraction.positionObjectStages.find((s) => s.identifier === draggedStageId);
|
|
230
|
-
if (!stage) return;
|
|
231
|
-
|
|
232
|
-
// Check how many times this stage has been used
|
|
233
|
-
const usageCount = positions.filter((p) => p.stageId === draggedStageId).length;
|
|
234
|
-
if (usageCount >= stage.matchMax) return;
|
|
235
|
-
|
|
236
|
-
// Check if we can add more positions
|
|
237
|
-
if (!canAddMore) return;
|
|
238
|
-
|
|
239
|
-
positions = [...positions, { stageId: draggedStageId, x, y }];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Convert positions to QTI point format (space-separated "x y" strings)
|
|
243
|
-
// QTI baseType="point" expects array of strings like ["158 168", "250 200"]
|
|
244
|
-
const responseValue = positions.map(pos => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
245
|
-
|
|
246
|
-
response = responseValue;
|
|
247
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
248
|
-
onChange?.(responseValue);
|
|
249
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
250
|
-
if (rootElement) {
|
|
251
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
252
|
-
}
|
|
253
|
-
draggedStageId = null;
|
|
254
|
-
draggedPositionIndex = null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function handleDragOver(event: DragEvent) {
|
|
258
|
-
if (!canInteract) return;
|
|
259
|
-
event.preventDefault();
|
|
260
|
-
if (event.dataTransfer) {
|
|
261
|
-
event.dataTransfer.dropEffect = 'move';
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function removePosition(index: number) {
|
|
266
|
-
if (!canInteract) return;
|
|
267
|
-
positions = positions.filter((_, i) => i !== index);
|
|
268
|
-
|
|
269
|
-
// Convert positions to QTI point format (space-separated "x y" strings)
|
|
270
|
-
// QTI baseType="point" expects array of strings like ["158 168", "250 200"]
|
|
271
|
-
const responseValue = positions.map(pos => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
272
|
-
|
|
273
|
-
response = responseValue;
|
|
274
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
275
|
-
onChange?.(responseValue);
|
|
276
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
277
|
-
if (rootElement) {
|
|
278
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function getStageById(id: string) {
|
|
283
|
-
return parsedInteraction?.positionObjectStages.find((s) => s.identifier === id);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function getStageUsageCount(id: string): number {
|
|
287
|
-
return positions.filter((p) => p.stageId === id).length;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function canDragStage(id: string): boolean {
|
|
291
|
-
const stage = getStageById(id);
|
|
292
|
-
if (!stage) return false;
|
|
293
|
-
return getStageUsageCount(id) < stage.matchMax;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Parse correct response points (same format as user response)
|
|
298
|
-
*/
|
|
299
|
-
function parseCorrectPositions(value: string[] | null | undefined): Position[] {
|
|
300
|
-
if (!value || !Array.isArray(value) || value.length === 0) return [];
|
|
301
|
-
if (!parsedInteraction) return [];
|
|
302
|
-
|
|
303
|
-
const stages = parsedInteraction.positionObjectStages || [];
|
|
304
|
-
const correctPositions: Position[] = [];
|
|
305
|
-
|
|
306
|
-
for (let i = 0; i < value.length; i++) {
|
|
307
|
-
const pointStr = value[i];
|
|
308
|
-
if (typeof pointStr !== 'string') continue;
|
|
309
|
-
const parts = pointStr.trim().split(/\s+/);
|
|
310
|
-
if (parts.length >= 2) {
|
|
311
|
-
const x = parseFloat(parts[0]);
|
|
312
|
-
const y = parseFloat(parts[1]);
|
|
313
|
-
|
|
314
|
-
// Determine which stage this point belongs to (same logic as user response)
|
|
315
|
-
let stageId = '';
|
|
316
|
-
if (stages.length === 1) {
|
|
317
|
-
stageId = stages[0].identifier;
|
|
318
|
-
} else {
|
|
319
|
-
let pointIndex = 0;
|
|
320
|
-
for (const stage of stages) {
|
|
321
|
-
if (pointIndex + stage.matchMax > i) {
|
|
322
|
-
stageId = stage.identifier;
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
pointIndex += stage.matchMax;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (stageId && !isNaN(x) && !isNaN(y)) {
|
|
330
|
-
correctPositions.push({ stageId, x, y });
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return correctPositions;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const correctPositions = $derived(
|
|
339
|
-
isShowingCorrect ? parseCorrectPositions(parsedCorrectResponse) : []
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Check if a user position matches a correct position (within tolerance)
|
|
344
|
-
*/
|
|
345
|
-
function isPositionCorrect(pos: Position): boolean {
|
|
346
|
-
if (!isShowingCorrect) return false;
|
|
347
|
-
return correctPositions.some(
|
|
348
|
-
(correct) =>
|
|
349
|
-
correct.stageId === pos.stageId &&
|
|
350
|
-
Math.abs(correct.x - pos.x) < 5 &&
|
|
351
|
-
Math.abs(correct.y - pos.y) < 5
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Check if a correct position is already placed by the user
|
|
357
|
-
*/
|
|
358
|
-
function isCorrectPositionPlaced(correctPos: Position): boolean {
|
|
359
|
-
return positions.some(
|
|
360
|
-
(pos) =>
|
|
361
|
-
pos.stageId === correctPos.stageId &&
|
|
362
|
-
Math.abs(pos.x - correctPos.x) < 5 &&
|
|
363
|
-
Math.abs(pos.y - correctPos.y) < 5
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// ---------------------------------------------------------------------------
|
|
368
|
-
// Keyboard accessibility (K-04) — two-phase: palette select → canvas place
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Activate keyboard placement mode for a palette stage.
|
|
373
|
-
* Phase 1: user presses Enter/Space on a palette item.
|
|
374
|
-
*/
|
|
375
|
-
function activateKeyboardPlacement(stageId: string) {
|
|
376
|
-
if (!canInteract) return;
|
|
377
|
-
const stage = getStageById(stageId);
|
|
378
|
-
if (!stage || !canDragStage(stageId)) return;
|
|
379
|
-
|
|
380
|
-
selectedStageId = stageId;
|
|
381
|
-
crosshairActive = true;
|
|
382
|
-
|
|
383
|
-
// Initialise crosshair to the stage's last placed position, or centre
|
|
384
|
-
const existing = [...positions].reverse().find((p: Position) => p.stageId === stageId);
|
|
385
|
-
if (existing && parsedInteraction?.imageData) {
|
|
386
|
-
const imgW = Number(parsedInteraction.imageData.width) || 1;
|
|
387
|
-
const imgH = Number(parsedInteraction.imageData.height) || 1;
|
|
388
|
-
crosshairX = Math.max(0, Math.min(1, existing.x / imgW));
|
|
389
|
-
crosshairY = Math.max(0, Math.min(1, existing.y / imgH));
|
|
390
|
-
} else {
|
|
391
|
-
crosshairX = 0.5;
|
|
392
|
-
crosshairY = 0.5;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
liveMessage = `${stage.label} selected. Tab to canvas, then use arrow keys to position. Press Enter to place, Escape to cancel.`;
|
|
396
|
-
|
|
397
|
-
// Move focus to the canvas so arrow keys work immediately
|
|
398
|
-
requestAnimationFrame(() => imageContainer?.focus());
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Handle keydown on a palette item.
|
|
403
|
-
*/
|
|
404
|
-
function handlePaletteKeydown(event: KeyboardEvent, stageId: string) {
|
|
405
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
406
|
-
event.preventDefault();
|
|
407
|
-
activateKeyboardPlacement(stageId);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Place the currently selected stage at the crosshair position.
|
|
413
|
-
*/
|
|
414
|
-
function placeAtCrosshair() {
|
|
415
|
-
if (!selectedStageId || !parsedInteraction?.imageData) return;
|
|
416
|
-
|
|
417
|
-
const imgW = Number(parsedInteraction.imageData.width) || 800;
|
|
418
|
-
const imgH = Number(parsedInteraction.imageData.height) || 600;
|
|
419
|
-
|
|
420
|
-
let x = crosshairX * imgW;
|
|
421
|
-
let y = crosshairY * imgH;
|
|
422
|
-
|
|
423
|
-
// Apply centerPoint adjustment (same logic as mouse drop)
|
|
424
|
-
if (parsedInteraction.centerPoint) {
|
|
425
|
-
const stage = getStageById(selectedStageId);
|
|
426
|
-
if (stage?.objectData) {
|
|
427
|
-
x -= parseInt(stage.objectData.width || '50') / 2;
|
|
428
|
-
y -= parseInt(stage.objectData.height || '50') / 2;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
const stage = getStageById(selectedStageId);
|
|
433
|
-
if (!stage) return;
|
|
434
|
-
|
|
435
|
-
// Check stage capacity
|
|
436
|
-
const usageCount = getStageUsageCount(selectedStageId);
|
|
437
|
-
if (usageCount >= stage.matchMax) return;
|
|
438
|
-
if (!canAddMore) return;
|
|
439
|
-
|
|
440
|
-
positions = [...positions, { stageId: selectedStageId, x, y }];
|
|
441
|
-
|
|
442
|
-
const responseValue = positions.map((pos) => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
|
|
443
|
-
response = responseValue;
|
|
444
|
-
onChange?.(responseValue);
|
|
445
|
-
if (rootElement) {
|
|
446
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const pct = (v: number) => Math.round(v * 100);
|
|
450
|
-
liveMessage = `${stage.label} placed at ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
451
|
-
|
|
452
|
-
selectedStageId = null;
|
|
453
|
-
crosshairActive = false;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Handle keydown on the canvas when in keyboard placement mode.
|
|
458
|
-
*/
|
|
459
|
-
function handleCanvasKeydown(event: KeyboardEvent) {
|
|
460
|
-
if (!crosshairActive || !selectedStageId) return;
|
|
461
|
-
|
|
462
|
-
const step = event.shiftKey ? 0.01 : 0.05;
|
|
463
|
-
|
|
464
|
-
switch (event.key) {
|
|
465
|
-
case 'ArrowLeft':
|
|
466
|
-
event.preventDefault();
|
|
467
|
-
crosshairX = Math.max(0, crosshairX - step);
|
|
468
|
-
break;
|
|
469
|
-
case 'ArrowRight':
|
|
470
|
-
event.preventDefault();
|
|
471
|
-
crosshairX = Math.min(1, crosshairX + step);
|
|
472
|
-
break;
|
|
473
|
-
case 'ArrowUp':
|
|
474
|
-
event.preventDefault();
|
|
475
|
-
crosshairY = Math.max(0, crosshairY - step);
|
|
476
|
-
break;
|
|
477
|
-
case 'ArrowDown':
|
|
478
|
-
event.preventDefault();
|
|
479
|
-
crosshairY = Math.min(1, crosshairY + step);
|
|
480
|
-
break;
|
|
481
|
-
case 'Enter':
|
|
482
|
-
case ' ':
|
|
483
|
-
event.preventDefault();
|
|
484
|
-
placeAtCrosshair();
|
|
485
|
-
return;
|
|
486
|
-
case 'Escape':
|
|
487
|
-
event.preventDefault();
|
|
488
|
-
selectedStageId = null;
|
|
489
|
-
crosshairActive = false;
|
|
490
|
-
liveMessage = 'Placement cancelled.';
|
|
491
|
-
return;
|
|
492
|
-
default:
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// Announce updated position after arrow movement
|
|
497
|
-
const pct = (v: number) => Math.round(v * 100);
|
|
498
|
-
liveMessage = `Position: ${pct(crosshairX)}%, ${pct(crosshairY)}%.`;
|
|
499
|
-
}
|
|
500
|
-
</script>
|
|
501
|
-
|
|
502
|
-
<ShadowBaseStyles />
|
|
503
|
-
|
|
504
|
-
<div bind:this={rootElement} part="root" class="qti-position-object-interaction">
|
|
505
|
-
{#if !parsedInteraction}
|
|
506
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
507
|
-
{:else}
|
|
508
|
-
{#if parsedInteraction.prompt}
|
|
509
|
-
<p part="prompt" class="qti-po-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
|
|
510
|
-
{/if}
|
|
511
|
-
|
|
512
|
-
<div part="layout" class="qti-po-layout flex flex-col lg:flex-row gap-4 items-start">
|
|
513
|
-
<!-- Canvas Area with Background Image -->
|
|
514
|
-
<div part="canvas-area" class="qti-po-canvas-area flex-1 min-w-0">
|
|
515
|
-
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
516
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
517
|
-
<div
|
|
518
|
-
bind:this={imageContainer}
|
|
519
|
-
part="canvas"
|
|
520
|
-
class="qti-po-canvas relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200 {crosshairActive ? 'qti-po-canvas-active' : ''}"
|
|
521
|
-
style="width: 100%; aspect-ratio: {parsedInteraction.imageData?.width || 800} / {parsedInteraction.imageData?.height || 600}; box-sizing: border-box;"
|
|
522
|
-
ondrop={handleDrop}
|
|
523
|
-
ondragover={handleDragOver}
|
|
524
|
-
onkeydown={handleCanvasKeydown}
|
|
525
|
-
role="application"
|
|
526
|
-
tabindex={crosshairActive ? 0 : -1}
|
|
527
|
-
aria-label={crosshairActive
|
|
528
|
-
? (i18n?.t('interactions.positionObject.canvasActiveLabel') ?? `Positioning canvas – use arrow keys to move crosshair, Enter to place, Escape to cancel`)
|
|
529
|
-
: (i18n?.t('interactions.positionObject.canvasLabel') ?? 'Positioning canvas')}
|
|
530
|
-
>
|
|
531
|
-
<!-- Background Image -->
|
|
532
|
-
{#if parsedInteraction.imageData}
|
|
533
|
-
{#if parsedInteraction.imageData.type === 'svg' && parsedInteraction.imageData.content}
|
|
534
|
-
<div class="w-full h-full pointer-events-none">
|
|
535
|
-
{@html parsedInteraction.imageData.content}
|
|
536
|
-
</div>
|
|
537
|
-
{:else if parsedInteraction.imageData.src}
|
|
538
|
-
<img
|
|
539
|
-
src={parsedInteraction.imageData.src}
|
|
540
|
-
alt={i18n?.t('interactions.positionObject.backgroundAlt') ?? 'Positioning background'}
|
|
541
|
-
class="pointer-events-none"
|
|
542
|
-
style="display: block; width: 100%; height: 100%; object-fit: contain;"
|
|
543
|
-
/>
|
|
544
|
-
{/if}
|
|
545
|
-
{/if}
|
|
546
|
-
|
|
547
|
-
<!-- Positioned Objects -->
|
|
548
|
-
{#each positions as position, index}
|
|
549
|
-
{@const stage = getStageById(position.stageId)}
|
|
550
|
-
{@const isCorrect = isPositionCorrect(position)}
|
|
551
|
-
{#if stage}
|
|
552
|
-
<div
|
|
553
|
-
part="placed"
|
|
554
|
-
class="qti-po-placed absolute cursor-move {isCorrect ? 'qti-po-placed-correct' : ''}"
|
|
555
|
-
style="left: {position.x * scaleFactor}px; top: {position.y * scaleFactor}px; z-index: {10 + index}; transform-origin: top left;"
|
|
556
|
-
draggable={canInteract}
|
|
557
|
-
ondragstart={(e) => handleDragStart(e, position.stageId, index)}
|
|
558
|
-
role="button"
|
|
559
|
-
tabindex={canInteract ? 0 : -1}
|
|
560
|
-
aria-label="Positioned {stage.label} at ({position.x}, {position.y}){isCorrect ? '. Correct position' : ''}"
|
|
561
|
-
>
|
|
562
|
-
{#if stage.objectData}
|
|
563
|
-
{#if stage.objectData.type === 'svg' && stage.objectData.content}
|
|
564
|
-
<div
|
|
565
|
-
style="width: {(parseInt(stage.objectData.width || '50')) * scaleFactor}px; height: {(parseInt(stage.objectData.height || '50')) * scaleFactor}px;"
|
|
566
|
-
>
|
|
567
|
-
{@html stage.objectData.content}
|
|
568
|
-
</div>
|
|
569
|
-
{:else if stage.objectData.src}
|
|
570
|
-
<img
|
|
571
|
-
src={stage.objectData.src}
|
|
572
|
-
alt={stage.label}
|
|
573
|
-
style="width: {(parseInt(stage.objectData.width || '50')) * scaleFactor}px; height: {(parseInt(stage.objectData.height || '50')) * scaleFactor}px;"
|
|
574
|
-
class="pointer-events-none"
|
|
575
|
-
/>
|
|
576
|
-
{/if}
|
|
577
|
-
{:else}
|
|
578
|
-
<!-- Text-only object -->
|
|
579
|
-
<div
|
|
580
|
-
class="px-3 py-2 rounded-lg shadow-lg font-medium {isCorrect ? 'bg-success text-white' : 'bg-primary text-primary-content'}"
|
|
581
|
-
>
|
|
582
|
-
{stage.label}
|
|
583
|
-
</div>
|
|
584
|
-
{/if}
|
|
585
|
-
|
|
586
|
-
{#if isCorrect}
|
|
587
|
-
<span class="badge badge-success badge-xs absolute -top-1 -right-1">✓</span>
|
|
588
|
-
{/if}
|
|
589
|
-
|
|
590
|
-
{#if canInteract}
|
|
591
|
-
<button
|
|
592
|
-
part="remove"
|
|
593
|
-
class="absolute -top-2 -right-2 btn btn-xs btn-circle btn-error opacity-80 hover:opacity-100"
|
|
594
|
-
onclick={(e) => {
|
|
595
|
-
e.stopPropagation();
|
|
596
|
-
removePosition(index);
|
|
597
|
-
}}
|
|
598
|
-
aria-label="Remove {stage.label}"
|
|
599
|
-
>
|
|
600
|
-
<svg
|
|
601
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
602
|
-
part="remove-icon"
|
|
603
|
-
class="qti-icon-xs h-3 w-3"
|
|
604
|
-
fill="none"
|
|
605
|
-
viewBox="0 0 24 24"
|
|
606
|
-
stroke="currentColor"
|
|
607
|
-
>
|
|
608
|
-
<path
|
|
609
|
-
stroke-linecap="round"
|
|
610
|
-
stroke-linejoin="round"
|
|
611
|
-
stroke-width="2"
|
|
612
|
-
d="M6 18L18 6M6 6l12 12"
|
|
613
|
-
/>
|
|
614
|
-
</svg>
|
|
615
|
-
</button>
|
|
616
|
-
{/if}
|
|
617
|
-
</div>
|
|
618
|
-
{/if}
|
|
619
|
-
{/each}
|
|
620
|
-
|
|
621
|
-
<!-- Render correct positions that haven't been placed by the user -->
|
|
622
|
-
{#if isShowingCorrect && correctPositions.length > 0}
|
|
623
|
-
{#each correctPositions as correctPos, index}
|
|
624
|
-
{@const stage = getStageById(correctPos.stageId)}
|
|
625
|
-
{@const isPlaced = isCorrectPositionPlaced(correctPos)}
|
|
626
|
-
{#if stage && !isPlaced}
|
|
627
|
-
<div
|
|
628
|
-
part="correct-placed"
|
|
629
|
-
class="qti-po-placed qti-po-placed-correct qti-po-placed-ghost absolute pointer-events-none"
|
|
630
|
-
style="left: {correctPos.x * scaleFactor}px; top: {correctPos.y * scaleFactor}px; z-index: {5 + index}; transform-origin: top left;"
|
|
631
|
-
aria-label="Correct position for {stage.label} at ({correctPos.x}, {correctPos.y})"
|
|
632
|
-
>
|
|
633
|
-
{#if stage.objectData}
|
|
634
|
-
{#if stage.objectData.type === 'svg' && stage.objectData.content}
|
|
635
|
-
<div
|
|
636
|
-
style="width: {(parseInt(stage.objectData.width || '50')) * scaleFactor}px; height: {(parseInt(stage.objectData.height || '50')) * scaleFactor}px;"
|
|
637
|
-
>
|
|
638
|
-
{@html stage.objectData.content}
|
|
639
|
-
</div>
|
|
640
|
-
{:else if stage.objectData.src}
|
|
641
|
-
<img
|
|
642
|
-
src={stage.objectData.src}
|
|
643
|
-
alt={stage.label}
|
|
644
|
-
style="width: {(parseInt(stage.objectData.width || '50')) * scaleFactor}px; height: {(parseInt(stage.objectData.height || '50')) * scaleFactor}px;"
|
|
645
|
-
class="pointer-events-none"
|
|
646
|
-
/>
|
|
647
|
-
{/if}
|
|
648
|
-
{:else}
|
|
649
|
-
<!-- Text-only object -->
|
|
650
|
-
<div
|
|
651
|
-
class="px-3 py-2 bg-success text-white rounded-lg shadow-lg font-medium opacity-60"
|
|
652
|
-
>
|
|
653
|
-
{stage.label}
|
|
654
|
-
</div>
|
|
655
|
-
{/if}
|
|
656
|
-
<span class="badge badge-success badge-xs absolute -top-1 -right-1">✓</span>
|
|
657
|
-
</div>
|
|
658
|
-
{/if}
|
|
659
|
-
{/each}
|
|
660
|
-
{/if}
|
|
661
|
-
|
|
662
|
-
<!-- Keyboard crosshair overlay (K-04) -->
|
|
663
|
-
{#if crosshairActive}
|
|
664
|
-
<svg
|
|
665
|
-
class="qti-po-crosshair-overlay"
|
|
666
|
-
aria-hidden="true"
|
|
667
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
668
|
-
>
|
|
669
|
-
<!-- vertical line -->
|
|
670
|
-
<line
|
|
671
|
-
x1="{crosshairX * 100}%"
|
|
672
|
-
y1="0"
|
|
673
|
-
x2="{crosshairX * 100}%"
|
|
674
|
-
y2="100%"
|
|
675
|
-
class="qti-po-crosshair-line"
|
|
676
|
-
/>
|
|
677
|
-
<!-- horizontal line -->
|
|
678
|
-
<line
|
|
679
|
-
x1="0"
|
|
680
|
-
y1="{crosshairY * 100}%"
|
|
681
|
-
x2="100%"
|
|
682
|
-
y2="{crosshairY * 100}%"
|
|
683
|
-
class="qti-po-crosshair-line"
|
|
684
|
-
/>
|
|
685
|
-
<!-- centre dot -->
|
|
686
|
-
<circle
|
|
687
|
-
cx="{crosshairX * 100}%"
|
|
688
|
-
cy="{crosshairY * 100}%"
|
|
689
|
-
r="6"
|
|
690
|
-
class="qti-po-crosshair-dot"
|
|
691
|
-
/>
|
|
692
|
-
</svg>
|
|
693
|
-
{/if}
|
|
694
|
-
</div>
|
|
695
|
-
|
|
696
|
-
{#if parsedInteraction.minChoices > 0}
|
|
697
|
-
<div class="text-xs text-base-content/60 mt-2">
|
|
698
|
-
Minimum required: {parsedInteraction.minChoices} {#if parsedInteraction.maxChoices > 0}
|
|
699
|
-
| Maximum: {parsedInteraction.maxChoices}
|
|
700
|
-
{/if}
|
|
701
|
-
</div>
|
|
702
|
-
{/if}
|
|
703
|
-
</div>
|
|
704
|
-
|
|
705
|
-
<!-- Object Palette -->
|
|
706
|
-
<div part="palette" class="qti-po-palette w-full lg:w-auto lg:flex-1 lg:min-w-[18rem]">
|
|
707
|
-
<div class="qti-po-card card bg-base-100 border border-base-300 h-full">
|
|
708
|
-
<div class="qti-po-card-body card-body p-4">
|
|
709
|
-
<h3 class="card-title text-sm">
|
|
710
|
-
Available Objects ({positions.length}{#if parsedInteraction.maxChoices > 0}/{parsedInteraction.maxChoices}{/if})
|
|
711
|
-
</h3>
|
|
712
|
-
|
|
713
|
-
<p class="text-xs text-base-content/60 mb-2">Drag objects onto the canvas, or press Enter/Space on an object then use arrow keys to position it on the canvas.</p>
|
|
714
|
-
|
|
715
|
-
<div class="space-y-2">
|
|
716
|
-
{#each parsedInteraction.positionObjectStages as stage}
|
|
717
|
-
{@const usageCount = getStageUsageCount(stage.identifier)}
|
|
718
|
-
{@const canDrag = canDragStage(stage.identifier)}
|
|
719
|
-
<div
|
|
720
|
-
part="palette-item"
|
|
721
|
-
class="qti-po-palette-item flex items-center gap-3 p-3 rounded-lg bg-base-200 border border-base-300 {canInteract && canDrag ? 'cursor-move hover:border-primary' : 'opacity-50 cursor-not-allowed'} {selectedStageId === stage.identifier ? 'qti-po-palette-item-selected' : ''}"
|
|
722
|
-
draggable={canInteract && canDrag}
|
|
723
|
-
ondragstart={(e) => {
|
|
724
|
-
if (canDrag) handleDragStart(e, stage.identifier);
|
|
725
|
-
}}
|
|
726
|
-
onkeydown={(e) => handlePaletteKeydown(e, stage.identifier)}
|
|
727
|
-
role="button"
|
|
728
|
-
tabindex={canInteract && canDrag ? 0 : -1}
|
|
729
|
-
aria-label="{stage.label} ({usageCount}/{stage.matchMax} used){selectedStageId === stage.identifier ? '. Selected for placement' : ''}"
|
|
730
|
-
aria-pressed={selectedStageId === stage.identifier}
|
|
731
|
-
>
|
|
732
|
-
<!-- Object Preview -->
|
|
733
|
-
<div class="qti-po-preview flex-shrink-0">
|
|
734
|
-
{#if stage.objectData}
|
|
735
|
-
{#if stage.objectData.type === 'svg' && stage.objectData.content}
|
|
736
|
-
<div class="w-10 h-10" data-drag-preview>
|
|
737
|
-
{@html stage.objectData.content}
|
|
738
|
-
</div>
|
|
739
|
-
{:else if stage.objectData.src}
|
|
740
|
-
<img
|
|
741
|
-
src={stage.objectData.src}
|
|
742
|
-
alt={stage.label}
|
|
743
|
-
class="w-10 h-10 object-contain qti-po-preview-image"
|
|
744
|
-
data-drag-preview
|
|
745
|
-
/>
|
|
746
|
-
{/if}
|
|
747
|
-
{:else}
|
|
748
|
-
<div class="w-10 h-10 flex items-center justify-center" data-drag-preview>
|
|
749
|
-
<span class="text-2xl">📦</span>
|
|
750
|
-
</div>
|
|
751
|
-
{/if}
|
|
752
|
-
</div>
|
|
753
|
-
|
|
754
|
-
<!-- Label and Usage -->
|
|
755
|
-
<div class="flex-1 min-w-0">
|
|
756
|
-
<div class="font-medium text-sm truncate">{stage.label}</div>
|
|
757
|
-
<div class="text-xs text-base-content/60">
|
|
758
|
-
{usageCount}/{stage.matchMax} used
|
|
759
|
-
</div>
|
|
760
|
-
</div>
|
|
761
|
-
|
|
762
|
-
<!-- Drag Indicator -->
|
|
763
|
-
{#if canInteract && canDrag}
|
|
764
|
-
<DragHandle size={1.25} opacity={0.4} />
|
|
765
|
-
{/if}
|
|
766
|
-
</div>
|
|
767
|
-
{/each}
|
|
768
|
-
</div>
|
|
769
|
-
</div>
|
|
770
|
-
</div>
|
|
771
|
-
</div>
|
|
772
|
-
</div>
|
|
773
|
-
{/if}
|
|
774
|
-
|
|
775
|
-
<!-- Visually-hidden live region for keyboard placement announcements (K-04) -->
|
|
776
|
-
<div aria-live="polite" aria-atomic="true" class="qti-po-sr-only">{liveMessage}</div>
|
|
777
|
-
</div>
|
|
778
|
-
|
|
779
|
-
<style>
|
|
780
|
-
/* Ensure proper draggable areas */
|
|
781
|
-
:global(.qti-position-object-interaction [draggable='true']) {
|
|
782
|
-
user-select: none;
|
|
783
|
-
-webkit-user-drag: element;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
/* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
|
|
787
|
-
.qti-icon-xs {
|
|
788
|
-
width: 0.75rem;
|
|
789
|
-
height: 0.75rem;
|
|
790
|
-
flex: 0 0 auto;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/* Minimal layout so this works without Tailwind utilities */
|
|
794
|
-
.qti-po-layout {
|
|
795
|
-
display: flex;
|
|
796
|
-
gap: 1rem;
|
|
797
|
-
flex-wrap: wrap;
|
|
798
|
-
align-items: flex-start;
|
|
799
|
-
}
|
|
800
|
-
.qti-po-canvas-area {
|
|
801
|
-
flex: 1 1 0;
|
|
802
|
-
min-width: 280px;
|
|
803
|
-
}
|
|
804
|
-
.qti-po-canvas {
|
|
805
|
-
position: relative;
|
|
806
|
-
border-radius: 0.75rem;
|
|
807
|
-
overflow: hidden;
|
|
808
|
-
border: 2px solid var(--color-base-300, oklch(95% 0 0));
|
|
809
|
-
background: var(--color-base-200, oklch(98% 0 0));
|
|
810
|
-
width: 100%;
|
|
811
|
-
}
|
|
812
|
-
/* Critical: positioned items must be absolutely positioned even without Tailwind's `absolute` utility */
|
|
813
|
-
.qti-po-placed {
|
|
814
|
-
position: absolute;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
.qti-po-placed-correct {
|
|
818
|
-
border: 3px solid var(--color-success, oklch(76% 0.177 163.223));
|
|
819
|
-
border-radius: 4px;
|
|
820
|
-
box-shadow: 0 0 0 2px var(--color-success, oklch(76% 0.177 163.223)) inset;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
.qti-po-placed-ghost {
|
|
824
|
-
opacity: 0.6;
|
|
825
|
-
border: 3px dashed var(--color-success, oklch(76% 0.177 163.223));
|
|
826
|
-
border-radius: 4px;
|
|
827
|
-
}
|
|
828
|
-
.qti-po-palette {
|
|
829
|
-
flex: 1 1 0;
|
|
830
|
-
min-width: 18rem;
|
|
831
|
-
}
|
|
832
|
-
.qti-po-card {
|
|
833
|
-
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
834
|
-
border-radius: 0.75rem;
|
|
835
|
-
background: var(--color-base-100, oklch(100% 0 0));
|
|
836
|
-
height: 100%;
|
|
837
|
-
}
|
|
838
|
-
.qti-po-card-body {
|
|
839
|
-
padding: 1rem;
|
|
840
|
-
}
|
|
841
|
-
.qti-po-palette-item {
|
|
842
|
-
display: flex;
|
|
843
|
-
align-items: center;
|
|
844
|
-
gap: 0.75rem;
|
|
845
|
-
padding: 0.75rem;
|
|
846
|
-
border-radius: 0.75rem;
|
|
847
|
-
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
848
|
-
background: var(--color-base-200, oklch(98% 0 0));
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
/* Selected palette item (K-04) */
|
|
852
|
-
.qti-po-palette-item-selected {
|
|
853
|
-
border-color: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
854
|
-
background: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
855
|
-
color: var(--color-primary-content, oklch(89.824% 0.06192 275.75));
|
|
856
|
-
box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary, oklch(49.12% 0.3096 275.75)) 40%, transparent);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
/* Canvas active state ring (K-04) */
|
|
860
|
-
.qti-po-canvas-active {
|
|
861
|
-
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
862
|
-
outline-offset: 2px;
|
|
863
|
-
}
|
|
864
|
-
.qti-po-canvas-active:focus {
|
|
865
|
-
outline: 3px solid var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
866
|
-
outline-offset: 2px;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/* Crosshair SVG overlay (K-04) */
|
|
870
|
-
.qti-po-crosshair-overlay {
|
|
871
|
-
position: absolute;
|
|
872
|
-
inset: 0;
|
|
873
|
-
width: 100%;
|
|
874
|
-
height: 100%;
|
|
875
|
-
pointer-events: none;
|
|
876
|
-
z-index: 100;
|
|
877
|
-
}
|
|
878
|
-
.qti-po-crosshair-line {
|
|
879
|
-
stroke: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
880
|
-
stroke-width: 1.5;
|
|
881
|
-
stroke-dasharray: 6 4;
|
|
882
|
-
opacity: 0.85;
|
|
883
|
-
}
|
|
884
|
-
.qti-po-crosshair-dot {
|
|
885
|
-
fill: var(--color-primary, oklch(49.12% 0.3096 275.75));
|
|
886
|
-
stroke: white;
|
|
887
|
-
stroke-width: 2;
|
|
888
|
-
opacity: 0.95;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
/* Visually hidden live region (K-04) */
|
|
892
|
-
.qti-po-sr-only {
|
|
893
|
-
position: absolute;
|
|
894
|
-
width: 1px;
|
|
895
|
-
height: 1px;
|
|
896
|
-
padding: 0;
|
|
897
|
-
margin: -1px;
|
|
898
|
-
overflow: hidden;
|
|
899
|
-
clip: rect(0, 0, 0, 0);
|
|
900
|
-
white-space: nowrap;
|
|
901
|
-
border: 0;
|
|
902
|
-
}
|
|
903
|
-
</style>
|