@pie-qti/default-components 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +9 -0
- package/STYLING.md +226 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/plugins/associate/index.d.ts +8 -0
- package/dist/plugins/associate/index.d.ts.map +1 -0
- package/dist/plugins/associate/index.js +8 -0
- package/dist/plugins/choice/index.d.ts +8 -0
- package/dist/plugins/choice/index.d.ts.map +1 -0
- package/dist/plugins/choice/index.js +8 -0
- package/dist/plugins/custom/index.d.ts +8 -0
- package/dist/plugins/custom/index.d.ts.map +1 -0
- package/dist/plugins/custom/index.js +8 -0
- package/dist/plugins/end-attempt/index.d.ts +8 -0
- package/dist/plugins/end-attempt/index.d.ts.map +1 -0
- package/dist/plugins/end-attempt/index.js +8 -0
- package/dist/plugins/extended-text/index.d.ts +8 -0
- package/dist/plugins/extended-text/index.d.ts.map +1 -0
- package/dist/plugins/extended-text/index.js +8 -0
- package/dist/plugins/gap-match/index.d.ts +8 -0
- package/dist/plugins/gap-match/index.d.ts.map +1 -0
- package/dist/plugins/gap-match/index.js +8 -0
- package/dist/plugins/graphic-associate/index.d.ts +8 -0
- package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
- package/dist/plugins/graphic-associate/index.js +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
- package/dist/plugins/graphic-gap-match/index.js +8 -0
- package/dist/plugins/graphic-order/index.d.ts +8 -0
- package/dist/plugins/graphic-order/index.d.ts.map +1 -0
- package/dist/plugins/graphic-order/index.js +8 -0
- package/dist/plugins/hotspot/index.d.ts +8 -0
- package/dist/plugins/hotspot/index.d.ts.map +1 -0
- package/dist/plugins/hotspot/index.js +8 -0
- package/dist/plugins/hottext/index.d.ts +8 -0
- package/dist/plugins/hottext/index.d.ts.map +1 -0
- package/dist/plugins/hottext/index.js +8 -0
- package/dist/plugins/index.d.ts +30 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +30 -0
- package/dist/plugins/match/index.d.ts +8 -0
- package/dist/plugins/match/index.d.ts.map +1 -0
- package/dist/plugins/match/index.js +8 -0
- package/dist/plugins/media/index.d.ts +8 -0
- package/dist/plugins/media/index.d.ts.map +1 -0
- package/dist/plugins/media/index.js +8 -0
- package/dist/plugins/order/index.d.ts +8 -0
- package/dist/plugins/order/index.d.ts.map +1 -0
- package/dist/plugins/order/index.js +8 -0
- package/dist/plugins/position-object/index.d.ts +8 -0
- package/dist/plugins/position-object/index.d.ts.map +1 -0
- package/dist/plugins/position-object/index.js +8 -0
- package/dist/plugins/select-point/index.d.ts +8 -0
- package/dist/plugins/select-point/index.d.ts.map +1 -0
- package/dist/plugins/select-point/index.js +8 -0
- package/dist/plugins/slider/index.d.ts +8 -0
- package/dist/plugins/slider/index.d.ts.map +1 -0
- package/dist/plugins/slider/index.js +8 -0
- package/dist/shared/actions/typesetAction.d.ts +26 -0
- package/dist/shared/actions/typesetAction.d.ts.map +1 -0
- package/dist/shared/actions/typesetAction.js +70 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.js +239 -0
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/utils/eventHelpers.d.ts +18 -0
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
- package/dist/shared/utils/eventHelpers.js +30 -0
- package/dist/shared/utils/pairHelpers.d.ts +55 -0
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
- package/dist/shared/utils/pairHelpers.js +76 -0
- package/dist/shared/utils/touchDragHelper.d.ts +33 -0
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
- package/dist/shared/utils/touchDragHelper.js +168 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
- package/dist/shared/utils/webComponentHelpers.js +26 -0
- package/package.json +93 -0
- package/src/index.ts +213 -0
- package/src/plugins/associate/AssociateInteraction.svelte +273 -0
- package/src/plugins/associate/index.ts +9 -0
- package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
- package/src/plugins/choice/index.ts +9 -0
- package/src/plugins/custom/CustomInteraction.svelte +61 -0
- package/src/plugins/custom/index.ts +9 -0
- package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
- package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
- package/src/plugins/end-attempt/index.ts +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
- package/src/plugins/extended-text/index.ts +9 -0
- package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
- package/src/plugins/gap-match/index.ts +9 -0
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
- package/src/plugins/graphic-associate/index.ts +9 -0
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
- package/src/plugins/graphic-gap-match/index.ts +9 -0
- package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
- package/src/plugins/graphic-order/index.ts +9 -0
- package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
- package/src/plugins/hotspot/index.ts +9 -0
- package/src/plugins/hottext/HottextInteraction.svelte +296 -0
- package/src/plugins/hottext/index.ts +9 -0
- package/src/plugins/index.ts +31 -0
- package/src/plugins/match/MatchInteraction.svelte +70 -0
- package/src/plugins/match/index.ts +9 -0
- package/src/plugins/media/MediaInteraction.svelte +213 -0
- package/src/plugins/media/index.ts +9 -0
- package/src/plugins/order/OrderInteraction.svelte +159 -0
- package/src/plugins/order/index.ts +9 -0
- package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
- package/src/plugins/position-object/README.md +130 -0
- package/src/plugins/position-object/index.ts +9 -0
- package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
- package/src/plugins/select-point/index.ts +9 -0
- package/src/plugins/slider/SliderInteraction.svelte +141 -0
- package/src/plugins/slider/index.ts +9 -0
- package/src/plugins/upload/UploadInteraction.svelte +59 -0
- package/src/shared/actions/typesetAction.ts +87 -0
- package/src/shared/components/CustomInteractionFallback.svelte +153 -0
- package/src/shared/components/DragHandle.svelte +44 -0
- package/src/shared/components/DrawingCanvas.svelte +243 -0
- package/src/shared/components/FileUpload.svelte +153 -0
- package/src/shared/components/GraphicGapMatch.svelte +316 -0
- package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
- package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
- package/src/shared/components/MatchDragDrop.svelte +434 -0
- package/src/shared/components/MathContent.svelte +18 -0
- package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
- package/src/shared/components/RichTextEditor.svelte +316 -0
- package/src/shared/components/ShadowBaseStyles.svelte +391 -0
- package/src/shared/components/SortableList.svelte +297 -0
- package/src/shared/extensions/MathLiveEditor.ts +304 -0
- package/src/shared/index.ts +17 -0
- package/src/shared/styles/shared.css +16 -0
- package/src/shared/utils/eventHelpers.ts +36 -0
- package/src/shared/utils/pairHelpers.ts +86 -0
- package/src/shared/utils/touchDragHelper.ts +211 -0
- package/src/shared/utils/webComponentHelpers.ts +27 -0
- package/src/svelte-shims.d.ts +9 -0
- package/svelte.config.js +9 -0
- package/tests/index.test.ts +8 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Position Object Interaction
|
|
2
|
+
|
|
3
|
+
## ⚠️ Important Limitations
|
|
4
|
+
|
|
5
|
+
This QTI 2.2 interaction type has **severe limitations** that make it impractical for most educational scenarios. This implementation exists for QTI 2.2 specification compliance, but the interaction itself has limited practical utility.
|
|
6
|
+
|
|
7
|
+
## The Core Problem
|
|
8
|
+
|
|
9
|
+
The `positionObjectInteraction` response format uses `baseType="point"`, which only stores coordinates:
|
|
10
|
+
|
|
11
|
+
```xml
|
|
12
|
+
<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="point">
|
|
13
|
+
<correctResponse>
|
|
14
|
+
<value>158 168</value>
|
|
15
|
+
<value>210 195</value>
|
|
16
|
+
</correctResponse>
|
|
17
|
+
</responseDeclaration>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**There is NO way to track which specific object was placed where.**
|
|
21
|
+
|
|
22
|
+
## What It Was Designed For
|
|
23
|
+
|
|
24
|
+
Based on the official QTI 2.2 specification example (airport placement):
|
|
25
|
+
|
|
26
|
+
- Place **multiple copies of the SAME object** (e.g., airport icons)
|
|
27
|
+
- One `positionObjectStage` container with background image
|
|
28
|
+
- One `positionObjectInteraction` with ONE draggable object
|
|
29
|
+
- `maxChoices` determines how many times the object can be placed
|
|
30
|
+
- Scoring uses `areaMapping` to check if ANY placement hits target zones
|
|
31
|
+
|
|
32
|
+
### Example Use Case (Spec-Compliant)
|
|
33
|
+
|
|
34
|
+
"Place 3 airport markers on the UK map where you think the major airports are located."
|
|
35
|
+
|
|
36
|
+
- All 3 placements use identical airport icons
|
|
37
|
+
- Response: `["118 184", "150 235", "96 114"]` (just coordinates)
|
|
38
|
+
- Scoring: Check if any coordinate falls within acceptable zones around correct airports
|
|
39
|
+
|
|
40
|
+
## What It CANNOT Do
|
|
41
|
+
|
|
42
|
+
### ❌ Labeled Object Placement
|
|
43
|
+
|
|
44
|
+
"Place these labeled city names on their correct locations on the map."
|
|
45
|
+
|
|
46
|
+
- Cannot track which city label goes where
|
|
47
|
+
- Response format doesn't support object identifiers
|
|
48
|
+
- On reload, labels would be mapped to positions incorrectly
|
|
49
|
+
|
|
50
|
+
### ❌ Multiple Different Objects
|
|
51
|
+
|
|
52
|
+
"Place the heart, lungs, and liver on the correct locations in the body diagram."
|
|
53
|
+
|
|
54
|
+
- Cannot distinguish between different organs in the response
|
|
55
|
+
- Impossible to score "heart must be here, liver must be there"
|
|
56
|
+
|
|
57
|
+
## Research Findings
|
|
58
|
+
|
|
59
|
+
After extensive research, we found:
|
|
60
|
+
|
|
61
|
+
1. **No real-world implementations** beyond the official QTI 2.2 spec example
|
|
62
|
+
2. **Not included** in QTI 3.0 shared vocabulary/styling guide (likely being phased out)
|
|
63
|
+
3. **Major QTI platforms** (TAO, Citolab) show no prominent support for this interaction
|
|
64
|
+
4. **Zero community discussions** or Stack Overflow questions about implementation
|
|
65
|
+
|
|
66
|
+
This strongly suggests the interaction type has been **effectively abandoned** by the QTI community.
|
|
67
|
+
|
|
68
|
+
## Alternative Solutions
|
|
69
|
+
|
|
70
|
+
### For Labeled Object Placement: Use `graphicGapMatchInteraction`
|
|
71
|
+
|
|
72
|
+
This interaction uses `baseType="directedPair"` which properly tracks object-location pairs:
|
|
73
|
+
|
|
74
|
+
```xml
|
|
75
|
+
<responseDeclaration identifier="RESPONSE" cardinality="multiple" baseType="directedPair">
|
|
76
|
+
<correctResponse>
|
|
77
|
+
<value>HEART A</value>
|
|
78
|
+
<value>LUNGS B</value>
|
|
79
|
+
<value>LIVER C</value>
|
|
80
|
+
</correctResponse>
|
|
81
|
+
</responseDeclaration>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This format **explicitly stores which object (HEART) was placed at which location (A)**.
|
|
85
|
+
|
|
86
|
+
### For Abstract Point Placement: Use `selectPointInteraction`
|
|
87
|
+
|
|
88
|
+
For scenarios where you just need to capture coordinate clicks without draggable objects:
|
|
89
|
+
|
|
90
|
+
- "Click on 3 locations where you think the treasure is buried"
|
|
91
|
+
- "Mark points on the graph where the function crosses zero"
|
|
92
|
+
|
|
93
|
+
## Current Implementation
|
|
94
|
+
|
|
95
|
+
This component includes a **non-standard extension** that:
|
|
96
|
+
|
|
97
|
+
- Supports multiple `positionObjectStage` elements with identifiers
|
|
98
|
+
- Tracks which stage (object) is at which position internally
|
|
99
|
+
- Uses best-effort array-order mapping to reconstruct positions on reload
|
|
100
|
+
|
|
101
|
+
**However**, this cannot be stored in the QTI response format, making it unreliable for:
|
|
102
|
+
- Saving and restoring state
|
|
103
|
+
- Scoring based on specific object placements
|
|
104
|
+
- Multi-session assessments
|
|
105
|
+
|
|
106
|
+
## Recommendation
|
|
107
|
+
|
|
108
|
+
**Do not use `positionObjectInteraction` for new assessment items.**
|
|
109
|
+
|
|
110
|
+
Use:
|
|
111
|
+
- `graphicGapMatchInteraction` for labeled object placement
|
|
112
|
+
- `selectPointInteraction` for coordinate-based responses
|
|
113
|
+
- `hotspotInteraction` for clicking predefined regions
|
|
114
|
+
|
|
115
|
+
This interaction exists in our library solely for QTI 2.2 specification compliance.
|
|
116
|
+
|
|
117
|
+
## Official QTI 2.2 Example
|
|
118
|
+
|
|
119
|
+
The only real example from IMS Global:
|
|
120
|
+
|
|
121
|
+
```xml
|
|
122
|
+
<positionObjectStage>
|
|
123
|
+
<object type="image/png" data="images/uk.png" width="206" height="280"/>
|
|
124
|
+
<positionObjectInteraction responseIdentifier="RESPONSE" maxChoices="3">
|
|
125
|
+
<object type="image/png" data="images/airport.png" width="16" height="16"/>
|
|
126
|
+
</positionObjectInteraction>
|
|
127
|
+
</positionObjectStage>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Note: ONE stage, ONE draggable object, multiple placements allowed.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Svelte component exported via web component
|
|
2
|
+
|
|
3
|
+
export const metadata = {
|
|
4
|
+
interactionType: 'positionObjectInteraction',
|
|
5
|
+
tagName: 'pie-qti-position-object',
|
|
6
|
+
name: 'default-position-object',
|
|
7
|
+
description: 'Default Svelte-based position object interaction',
|
|
8
|
+
priority: 0,
|
|
9
|
+
};
|
|
@@ -0,0 +1,453 @@
|
|
|
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
|
+
/**
|
|
41
|
+
* Parse correct response points (same format as user response)
|
|
42
|
+
*/
|
|
43
|
+
function parsePoints(value: any): Point[] {
|
|
44
|
+
if (!value) return [];
|
|
45
|
+
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value
|
|
48
|
+
.map((v) => {
|
|
49
|
+
if (typeof v === 'string') {
|
|
50
|
+
const parts = v.trim().split(/\s+/);
|
|
51
|
+
if (parts.length === 2) {
|
|
52
|
+
const x = Number(parts[0]);
|
|
53
|
+
const y = Number(parts[1]);
|
|
54
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
55
|
+
return { x, y } satisfies Point;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (v && typeof v === 'object' && v.x !== undefined && v.y !== undefined) {
|
|
61
|
+
const x = Number(v.x);
|
|
62
|
+
const y = Number(v.y);
|
|
63
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
64
|
+
return { x, y } satisfies Point;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
})
|
|
69
|
+
.filter(Boolean) as Point[];
|
|
70
|
+
} else if (typeof value === 'string' && value.trim()) {
|
|
71
|
+
const parts = value.trim().split(/\s+/);
|
|
72
|
+
if (parts.length === 2) {
|
|
73
|
+
const x = Number(parts[0]);
|
|
74
|
+
const y = Number(parts[1]);
|
|
75
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
76
|
+
return [{ x, y }];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else if (value && typeof value === 'object' && value.x !== undefined && value.y !== undefined) {
|
|
80
|
+
const x = Number(value.x);
|
|
81
|
+
const y = Number(value.y);
|
|
82
|
+
if (!isNaN(x) && !isNaN(y)) {
|
|
83
|
+
return [{ x, y }];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const correctPoints = $derived(
|
|
90
|
+
isShowingCorrect && parsedCorrectResponse !== null && parsedCorrectResponse !== undefined
|
|
91
|
+
? parsePoints(parsedCorrectResponse)
|
|
92
|
+
: []
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Debug logging
|
|
96
|
+
$effect(() => {
|
|
97
|
+
if (role === 'scorer') {
|
|
98
|
+
console.log('[SelectPoint] Role:', role);
|
|
99
|
+
console.log('[SelectPoint] parsedCorrectResponse:', parsedCorrectResponse);
|
|
100
|
+
console.log('[SelectPoint] correctPoints array:', JSON.stringify(correctPoints));
|
|
101
|
+
console.log('[SelectPoint] correctPoints.length:', correctPoints.length);
|
|
102
|
+
if (correctPoints.length > 0) {
|
|
103
|
+
console.log('[SelectPoint] First correct point x:', correctPoints[0].x, 'y:', correctPoints[0].y);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
$effect(() => {
|
|
110
|
+
// Sync with parent response changes
|
|
111
|
+
const r = parsedResponse;
|
|
112
|
+
if (Array.isArray(r)) {
|
|
113
|
+
// Array can be [{x,y}, ...] or ["x y", ...]
|
|
114
|
+
selectedPoints = r
|
|
115
|
+
.map((v) => {
|
|
116
|
+
if (typeof v === 'string') {
|
|
117
|
+
const parts = v.trim().split(/\s+/);
|
|
118
|
+
if (parts.length === 2) return { x: Number(parts[0]), y: Number(parts[1]) } satisfies Point;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (v && typeof v === 'object' && v.x !== undefined && v.y !== undefined) {
|
|
122
|
+
return { x: Number(v.x), y: Number(v.y) } satisfies Point;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
})
|
|
126
|
+
.filter(Boolean) as Point[];
|
|
127
|
+
} else if (typeof r === 'string') {
|
|
128
|
+
const parts = r.trim().split(/\s+/);
|
|
129
|
+
selectedPoints =
|
|
130
|
+
parts.length === 2
|
|
131
|
+
? [{ x: Number(parts[0]), y: Number(parts[1]) }]
|
|
132
|
+
: [];
|
|
133
|
+
} else if (r && typeof r === 'object' && r.x !== undefined && r.y !== undefined) {
|
|
134
|
+
selectedPoints = [{ x: Number(r.x), y: Number(r.y) }];
|
|
135
|
+
} else {
|
|
136
|
+
selectedPoints = [];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Check if selection limit has been reached
|
|
142
|
+
*/
|
|
143
|
+
const canSelectMore = $derived(!parsedInteraction || selectedPoints.length < parsedInteraction.maxChoices);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Check if minimum selection requirement has been met
|
|
147
|
+
*/
|
|
148
|
+
const hasMetMinChoices = $derived(
|
|
149
|
+
parsedInteraction && selectedPoints.length >= parsedInteraction.minChoices
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Handle click on image to select a point
|
|
154
|
+
*/
|
|
155
|
+
function handleImageClick(event: MouseEvent) {
|
|
156
|
+
if (disabled || !canSelectMore || !imageElement || !parsedInteraction?.imageData) return;
|
|
157
|
+
|
|
158
|
+
const rect = imageElement.getBoundingClientRect();
|
|
159
|
+
const clickX = event.clientX - rect.left;
|
|
160
|
+
const clickY = event.clientY - rect.top;
|
|
161
|
+
|
|
162
|
+
// Convert to absolute coordinates matching the SVG/image coordinate system
|
|
163
|
+
// The image is displayed at rect.width x rect.height but has intrinsic dimensions
|
|
164
|
+
const intrinsicWidth = parseInt(parsedInteraction.imageData.width) || rect.width;
|
|
165
|
+
const intrinsicHeight = parseInt(parsedInteraction.imageData.height) || rect.height;
|
|
166
|
+
|
|
167
|
+
const x = Math.round((clickX / rect.width) * intrinsicWidth);
|
|
168
|
+
const y = Math.round((clickY / rect.height) * intrinsicHeight);
|
|
169
|
+
|
|
170
|
+
selectedPoints = [...selectedPoints, { x, y }];
|
|
171
|
+
|
|
172
|
+
// QTI canonical value representation for baseType="point" is "x y"
|
|
173
|
+
const canonicalValue =
|
|
174
|
+
parsedInteraction.maxChoices === 1
|
|
175
|
+
? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
|
|
176
|
+
: selectedPoints.map((p) => `${p.x} ${p.y}`);
|
|
177
|
+
// Normalize outward response shape to canonical QTI form (even if inbound was legacy/object form).
|
|
178
|
+
response = canonicalValue;
|
|
179
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
180
|
+
onChange?.(canonicalValue);
|
|
181
|
+
// Dispatch event for web component usage - event will bubble up to the host element
|
|
182
|
+
rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Remove a selected point
|
|
187
|
+
*/
|
|
188
|
+
function removePoint(index: number) {
|
|
189
|
+
if (disabled) return;
|
|
190
|
+
selectedPoints = selectedPoints.filter((_, i) => i !== index);
|
|
191
|
+
const canonicalValue =
|
|
192
|
+
parsedInteraction?.maxChoices === 1
|
|
193
|
+
? (selectedPoints[0] ? `${selectedPoints[0].x} ${selectedPoints[0].y}` : null)
|
|
194
|
+
: selectedPoints.map((p) => `${p.x} ${p.y}`);
|
|
195
|
+
response = canonicalValue;
|
|
196
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
197
|
+
onChange?.(canonicalValue);
|
|
198
|
+
rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Clear all selected points
|
|
203
|
+
*/
|
|
204
|
+
function clearAllPoints() {
|
|
205
|
+
if (disabled) return;
|
|
206
|
+
selectedPoints = [];
|
|
207
|
+
const canonicalValue =
|
|
208
|
+
parsedInteraction?.maxChoices === 1
|
|
209
|
+
? null
|
|
210
|
+
: [];
|
|
211
|
+
response = canonicalValue;
|
|
212
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
213
|
+
onChange?.(canonicalValue);
|
|
214
|
+
rootElement?.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, canonicalValue));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Initialize image element reference
|
|
219
|
+
*/
|
|
220
|
+
$effect(() => {
|
|
221
|
+
if (imageContainer) {
|
|
222
|
+
const img = imageContainer.querySelector('img, svg, object');
|
|
223
|
+
if (img) {
|
|
224
|
+
imageElement = img as HTMLElement;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<ShadowBaseStyles />
|
|
231
|
+
|
|
232
|
+
<div bind:this={rootElement} class="qti-select-point-interaction">
|
|
233
|
+
{#if !parsedInteraction}
|
|
234
|
+
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
235
|
+
{:else}
|
|
236
|
+
{#if parsedInteraction.prompt}
|
|
237
|
+
<p class="font-semibold mb-3">{@html parsedInteraction.prompt}</p>
|
|
238
|
+
{/if}
|
|
239
|
+
|
|
240
|
+
<div class="space-y-3">
|
|
241
|
+
|
|
242
|
+
<div
|
|
243
|
+
bind:this={imageContainer}
|
|
244
|
+
class="image-container relative inline-block"
|
|
245
|
+
style={disabled ? 'cursor: default;' : 'cursor: crosshair;'}
|
|
246
|
+
role="button"
|
|
247
|
+
tabindex={disabled ? -1 : 0}
|
|
248
|
+
aria-label={i18n?.t('interactions.selectPoint.instructionAria') ?? 'Click to select points on the image'}
|
|
249
|
+
onclick={handleImageClick}
|
|
250
|
+
onkeydown={(e) => {
|
|
251
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
252
|
+
e.preventDefault();
|
|
253
|
+
}
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
{#if parsedInteraction.imageData}
|
|
257
|
+
{#if parsedInteraction.imageData.type === 'svg'}
|
|
258
|
+
<div
|
|
259
|
+
style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData.height}px; position: relative;"
|
|
260
|
+
>
|
|
261
|
+
{@html parsedInteraction.imageData.content}
|
|
262
|
+
</div>
|
|
263
|
+
{:else if parsedInteraction.imageData.src}
|
|
264
|
+
<img
|
|
265
|
+
src={parsedInteraction.imageData.src}
|
|
266
|
+
alt={i18n?.t('interactions.selectPoint.canvas') ?? 'Selection canvas'}
|
|
267
|
+
style="width: {parsedInteraction.imageData.width}px; height: {parsedInteraction.imageData.height}px; position: relative; z-index: 1;"
|
|
268
|
+
class="block"
|
|
269
|
+
/>
|
|
270
|
+
{/if}
|
|
271
|
+
|
|
272
|
+
<!-- Render selected points as markers -->
|
|
273
|
+
{#each selectedPoints as point, index}
|
|
274
|
+
{@const intrinsicWidth = parseInt(parsedInteraction.imageData?.width || '500')}
|
|
275
|
+
{@const intrinsicHeight = parseInt(parsedInteraction.imageData?.height || '300')}
|
|
276
|
+
{@const xPercent = (point.x / intrinsicWidth) * 100}
|
|
277
|
+
{@const yPercent = (point.y / intrinsicHeight) * 100}
|
|
278
|
+
{@const isCorrect = isShowingCorrect && correctPoints.some((p) => Math.abs(p.x - point.x) < 1 && Math.abs(p.y - point.y) < 1)}
|
|
279
|
+
<button
|
|
280
|
+
type="button"
|
|
281
|
+
class="point-marker"
|
|
282
|
+
class:point-marker-correct={isCorrect}
|
|
283
|
+
style="left: {xPercent}%; top: {yPercent}%; z-index: 100;"
|
|
284
|
+
onclick={(e) => {
|
|
285
|
+
e.stopPropagation();
|
|
286
|
+
removePoint(index);
|
|
287
|
+
}}
|
|
288
|
+
aria-label="Remove point {index + 1} at coordinates {point.x}, {point.y}{isCorrect ? '. Correct answer' : ''}"
|
|
289
|
+
title="Click to remove this point ({point.x}, {point.y}){isCorrect ? ' - Correct' : ''}"
|
|
290
|
+
{disabled}
|
|
291
|
+
>
|
|
292
|
+
<span class="point-number">{isCorrect ? '✓' : index + 1}</span>
|
|
293
|
+
</button>
|
|
294
|
+
{/each}
|
|
295
|
+
|
|
296
|
+
<!-- Render correct points as markers (when in scorer mode and not already selected) -->
|
|
297
|
+
{#if isShowingCorrect && correctPoints.length > 0}
|
|
298
|
+
{#each correctPoints as point, index}
|
|
299
|
+
{@const intrinsicWidth = parseInt(parsedInteraction.imageData?.width || '500')}
|
|
300
|
+
{@const intrinsicHeight = parseInt(parsedInteraction.imageData?.height || '300')}
|
|
301
|
+
{@const xPercent = (point.x / intrinsicWidth) * 100}
|
|
302
|
+
{@const yPercent = (point.y / intrinsicHeight) * 100}
|
|
303
|
+
{@const isAlreadySelected = selectedPoints.some((p) => Math.abs(p.x - point.x) < 1 && Math.abs(p.y - point.y) < 1)}
|
|
304
|
+
<div
|
|
305
|
+
part="correct-point"
|
|
306
|
+
class="point-marker point-marker-correct"
|
|
307
|
+
style="left: {xPercent}%; top: {yPercent}%; pointer-events: none; z-index: 200;"
|
|
308
|
+
aria-label="Correct answer point at coordinates {point.x}, {point.y}"
|
|
309
|
+
title="Correct answer: ({point.x}, {point.y})"
|
|
310
|
+
>
|
|
311
|
+
<span class="point-number">✓</span>
|
|
312
|
+
</div>
|
|
313
|
+
{/each}
|
|
314
|
+
{/if}
|
|
315
|
+
{:else}
|
|
316
|
+
<div
|
|
317
|
+
class="no-image-placeholder bg-base-200 flex items-center justify-center"
|
|
318
|
+
style="width: 500px; height: 300px;"
|
|
319
|
+
>
|
|
320
|
+
<p class="text-base-content/50">{i18n?.t('interactions.selectPoint.noImage') ?? 'No image provided'}</p>
|
|
321
|
+
</div>
|
|
322
|
+
{/if}
|
|
323
|
+
</div>
|
|
324
|
+
|
|
325
|
+
<div class="flex items-center justify-between text-sm text-base-content/70">
|
|
326
|
+
<div>
|
|
327
|
+
<span class="font-medium">Points selected:</span>
|
|
328
|
+
<span class="ml-2">{selectedPoints.length} / {parsedInteraction.maxChoices}</span>
|
|
329
|
+
{#if parsedInteraction.minChoices > 0}
|
|
330
|
+
<span class="ml-2">
|
|
331
|
+
{#if hasMetMinChoices}
|
|
332
|
+
<span class="badge badge-success badge-sm">✓ Minimum met</span>
|
|
333
|
+
{:else}
|
|
334
|
+
<span class="badge badge-warning badge-sm">
|
|
335
|
+
Select at least {parsedInteraction.minChoices}
|
|
336
|
+
</span>
|
|
337
|
+
{/if}
|
|
338
|
+
</span>
|
|
339
|
+
{/if}
|
|
340
|
+
</div>
|
|
341
|
+
|
|
342
|
+
{#if selectedPoints.length > 0}
|
|
343
|
+
<button type="button" class="btn btn-sm btn-ghost" onclick={clearAllPoints} {disabled}>
|
|
344
|
+
Clear All
|
|
345
|
+
</button>
|
|
346
|
+
{/if}
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
{#if !canSelectMore}
|
|
350
|
+
<div class="alert alert-info">
|
|
351
|
+
<svg
|
|
352
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
353
|
+
fill="none"
|
|
354
|
+
viewBox="0 0 24 24"
|
|
355
|
+
part="limit-icon"
|
|
356
|
+
class="qti-icon stroke-current shrink-0 w-6 h-6"
|
|
357
|
+
>
|
|
358
|
+
<path
|
|
359
|
+
stroke-linecap="round"
|
|
360
|
+
stroke-linejoin="round"
|
|
361
|
+
stroke-width="2"
|
|
362
|
+
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
363
|
+
></path>
|
|
364
|
+
</svg>
|
|
365
|
+
<span>Maximum points reached. Remove a point to add a new one.</span>
|
|
366
|
+
</div>
|
|
367
|
+
{/if}
|
|
368
|
+
</div>
|
|
369
|
+
{/if}
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<style>
|
|
373
|
+
/* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
|
|
374
|
+
.qti-icon {
|
|
375
|
+
width: 1.5rem;
|
|
376
|
+
height: 1.5rem;
|
|
377
|
+
flex: 0 0 auto;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.image-container {
|
|
381
|
+
position: relative;
|
|
382
|
+
display: inline-block;
|
|
383
|
+
border: 2px solid hsl(var(--bc) / 0.2);
|
|
384
|
+
border-radius: 8px;
|
|
385
|
+
overflow: hidden;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.point-marker {
|
|
389
|
+
position: absolute;
|
|
390
|
+
width: 32px;
|
|
391
|
+
height: 32px;
|
|
392
|
+
transform: translate(-50%, -50%);
|
|
393
|
+
background-color: hsl(var(--p));
|
|
394
|
+
border: 3px solid white;
|
|
395
|
+
border-radius: 50%;
|
|
396
|
+
display: flex;
|
|
397
|
+
align-items: center;
|
|
398
|
+
justify-content: center;
|
|
399
|
+
cursor: pointer;
|
|
400
|
+
transition: all 0.2s;
|
|
401
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.point-marker:hover {
|
|
405
|
+
background-color: hsl(var(--er));
|
|
406
|
+
transform: translate(-50%, -50%) scale(1.1);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
.point-marker:disabled {
|
|
410
|
+
cursor: not-allowed;
|
|
411
|
+
opacity: 0.6;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.point-marker-correct {
|
|
415
|
+
background-color: #10b981 !important;
|
|
416
|
+
border-color: white !important;
|
|
417
|
+
border-width: 4px !important;
|
|
418
|
+
cursor: default;
|
|
419
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 4px #10b981 !important;
|
|
420
|
+
width: 50px !important;
|
|
421
|
+
height: 50px !important;
|
|
422
|
+
z-index: 200 !important;
|
|
423
|
+
position: absolute !important;
|
|
424
|
+
opacity: 1 !important;
|
|
425
|
+
display: flex !important;
|
|
426
|
+
align-items: center !important;
|
|
427
|
+
justify-content: center !important;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
.point-marker-correct .point-number {
|
|
431
|
+
font-size: 28px !important;
|
|
432
|
+
font-weight: 900 !important;
|
|
433
|
+
color: white !important;
|
|
434
|
+
line-height: 1 !important;
|
|
435
|
+
display: block !important;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
.point-marker-correct:hover {
|
|
439
|
+
background-color: var(--color-success, oklch(76% 0.177 163.223));
|
|
440
|
+
transform: translate(-50%, -50%);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.point-number {
|
|
444
|
+
color: white;
|
|
445
|
+
font-weight: 700;
|
|
446
|
+
font-size: 14px;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
.no-image-placeholder {
|
|
450
|
+
border: 2px dashed hsl(var(--bc) / 0.2);
|
|
451
|
+
border-radius: 8px;
|
|
452
|
+
}
|
|
453
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
};
|