@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,503 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-graphic-associate" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import type { GraphicAssociateInteractionData } from '@pie-qti/item-player';
|
|
5
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
-
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
|
-
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
8
|
-
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
|
|
9
|
-
import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
interaction?: GraphicAssociateInteractionData | string;
|
|
13
|
-
response?: string[] | null;
|
|
14
|
-
correctResponse?: string[] | null;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
role?: string;
|
|
17
|
-
i18n?: I18nProvider;
|
|
18
|
-
onChange?: (value: string[]) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
|
|
22
|
-
|
|
23
|
-
// Parse props that may be JSON strings (web component usage)
|
|
24
|
-
const parsedInteraction = $derived(parseJsonProp<GraphicAssociateInteractionData>(interaction));
|
|
25
|
-
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
26
|
-
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
27
|
-
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
28
|
-
const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
|
|
29
|
-
|
|
30
|
-
// Get reference to the root element for event dispatching
|
|
31
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
32
|
-
|
|
33
|
-
// Pairs are stored as "ID1 ID2" strings (space-separated)
|
|
34
|
-
let pairs = $state<string[]>([]);
|
|
35
|
-
let selectedHotspot: string | null = $state(null);
|
|
36
|
-
let imageContainer: HTMLDivElement | null = $state(null);
|
|
37
|
-
let imageElement: HTMLElement | null = $state(null);
|
|
38
|
-
|
|
39
|
-
const canInteract = $derived(!disabled);
|
|
40
|
-
const canAddMore = $derived(!parsedInteraction || pairs.length < parsedInteraction.maxAssociations);
|
|
41
|
-
|
|
42
|
-
// Hotspots incompatible with the currently selected hotspot due to matchGroup constraints
|
|
43
|
-
const blockedHotspots = $derived.by(() => {
|
|
44
|
-
if (!selectedHotspot || !parsedInteraction) return new Set<string>();
|
|
45
|
-
type WithMatchGroup = { identifier: string; matchGroup?: string[] };
|
|
46
|
-
const hotspots = parsedInteraction.associableHotspots as (typeof parsedInteraction.associableHotspots[number] & WithMatchGroup)[];
|
|
47
|
-
const src = hotspots.find((h) => h.identifier === selectedHotspot);
|
|
48
|
-
return new Set(
|
|
49
|
-
hotspots
|
|
50
|
-
.filter((h) => h.identifier !== selectedHotspot && !isCompatibleMatchGroup(src?.matchGroup, h.matchGroup))
|
|
51
|
-
.map((h) => h.identifier)
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
$effect(() => {
|
|
56
|
-
// Sync with parent response changes
|
|
57
|
-
pairs = parsedResponse ? [...parsedResponse] : [];
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
function handleHotspotClick(hotspotId: string) {
|
|
61
|
-
if (!canInteract || !parsedInteraction) return;
|
|
62
|
-
|
|
63
|
-
const hotspot = parsedInteraction.associableHotspots.find((h) => h.identifier === hotspotId);
|
|
64
|
-
if (!hotspot) return;
|
|
65
|
-
|
|
66
|
-
// Count how many times this hotspot is already used
|
|
67
|
-
const usageCount = pairs.filter((pair) => pair.includes(hotspotId)).length;
|
|
68
|
-
if (usageCount >= hotspot.matchMax) {
|
|
69
|
-
// This hotspot is at its maximum connections
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!selectedHotspot) {
|
|
74
|
-
// First selection
|
|
75
|
-
selectedHotspot = hotspotId;
|
|
76
|
-
} else if (selectedHotspot === hotspotId) {
|
|
77
|
-
// Clicking the same hotspot deselects it
|
|
78
|
-
selectedHotspot = null;
|
|
79
|
-
} else {
|
|
80
|
-
// Second selection - create a pair
|
|
81
|
-
if (!canAddMore) return;
|
|
82
|
-
if (blockedHotspots.has(hotspotId)) return;
|
|
83
|
-
|
|
84
|
-
const newPair = `${selectedHotspot} ${hotspotId}`;
|
|
85
|
-
pairs = [...pairs, newPair];
|
|
86
|
-
response = pairs;
|
|
87
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
88
|
-
onChange?.(pairs);
|
|
89
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
90
|
-
if (rootElement) {
|
|
91
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, pairs));
|
|
92
|
-
}
|
|
93
|
-
selectedHotspot = null;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function removePair(index: number) {
|
|
98
|
-
if (!canInteract) return;
|
|
99
|
-
pairs = pairs.filter((_, i) => i !== index);
|
|
100
|
-
response = pairs;
|
|
101
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
102
|
-
onChange?.(pairs);
|
|
103
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
104
|
-
if (rootElement) {
|
|
105
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, pairs));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getHotspotById(id: string) {
|
|
110
|
-
return parsedInteraction?.associableHotspots.find((h) => h.identifier === id);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function isHotspotSelected(id: string): boolean {
|
|
114
|
-
return selectedHotspot === id;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function getHotspotUsageCount(id: string): number {
|
|
118
|
-
return pairs.filter((pair) => pair.includes(id)).length;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function isHotspotMaxed(id: string): boolean {
|
|
122
|
-
const hotspot = getHotspotById(id);
|
|
123
|
-
if (!hotspot) return false;
|
|
124
|
-
return getHotspotUsageCount(id) >= hotspot.matchMax;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function isCorrectPair(id1: string, id2: string): boolean {
|
|
128
|
-
if (!isShowingCorrect) return false;
|
|
129
|
-
return correctPairs.some((p) => p === `${id1} ${id2}` || p === `${id2} ${id1}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function isHotspotInCorrectPair(id: string): boolean {
|
|
133
|
-
if (!isShowingCorrect) return false;
|
|
134
|
-
return correctPairs.some((p) => p.includes(id));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Calculate center point of a hotspot for visual connections
|
|
138
|
-
function getHotspotCenter(coords: string, shape: string): { x: number; y: number } {
|
|
139
|
-
const parts = coords.split(',').map(Number);
|
|
140
|
-
if (shape === 'rect') {
|
|
141
|
-
// rect: left,top,right,bottom
|
|
142
|
-
return {
|
|
143
|
-
x: (parts[0] + parts[2]) / 2,
|
|
144
|
-
y: (parts[1] + parts[3]) / 2,
|
|
145
|
-
};
|
|
146
|
-
} else if (shape === 'circle' || shape === 'ellipse') {
|
|
147
|
-
// circle: cx,cy,r | ellipse: cx,cy,rx,ry
|
|
148
|
-
return { x: parts[0], y: parts[1] };
|
|
149
|
-
} else if (shape === 'poly') {
|
|
150
|
-
// poly: x1,y1,x2,y2,... — centroid average
|
|
151
|
-
const xs = parts.filter((_, i) => i % 2 === 0);
|
|
152
|
-
const ys = parts.filter((_, i) => i % 2 !== 0);
|
|
153
|
-
return {
|
|
154
|
-
x: xs.reduce((a, b) => a + b, 0) / xs.length,
|
|
155
|
-
y: ys.reduce((a, b) => a + b, 0) / ys.length,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
// Default fallback
|
|
159
|
-
return { x: parts[0] || 0, y: parts[1] || 0 };
|
|
160
|
-
}
|
|
161
|
-
</script>
|
|
162
|
-
|
|
163
|
-
<ShadowBaseStyles />
|
|
164
|
-
|
|
165
|
-
<div bind:this={rootElement} part="root" class="qti-graphic-associate-interaction">
|
|
166
|
-
{#if !parsedInteraction}
|
|
167
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
168
|
-
{:else}
|
|
169
|
-
{#if parsedInteraction.prompt}
|
|
170
|
-
<p part="prompt" class="qti-ga-prompt font-semibold mb-3">{@html parsedInteraction.prompt}</p>
|
|
171
|
-
{/if}
|
|
172
|
-
|
|
173
|
-
<div part="layout" class="qti-ga-layout flex flex-col lg:flex-row gap-4">
|
|
174
|
-
<!-- Image with Hotspots -->
|
|
175
|
-
<div part="image-area" class="qti-ga-image-area flex-1">
|
|
176
|
-
<div
|
|
177
|
-
bind:this={imageContainer}
|
|
178
|
-
part="stage"
|
|
179
|
-
class="qti-ga-stage relative border-2 border-base-300 rounded-lg overflow-hidden bg-base-200"
|
|
180
|
-
style="width: {parsedInteraction.imageData?.width}px; height: {parsedInteraction.imageData?.height}px;"
|
|
181
|
-
>
|
|
182
|
-
{#if parsedInteraction.imageData}
|
|
183
|
-
{#if parsedInteraction.imageData.type === 'svg' && parsedInteraction.imageData.content}
|
|
184
|
-
<div
|
|
185
|
-
bind:this={imageElement}
|
|
186
|
-
class="w-full h-full"
|
|
187
|
-
>
|
|
188
|
-
{@html parsedInteraction.imageData.content}
|
|
189
|
-
</div>
|
|
190
|
-
{:else if parsedInteraction.imageData.src}
|
|
191
|
-
<img
|
|
192
|
-
bind:this={imageElement}
|
|
193
|
-
src={parsedInteraction.imageData.src}
|
|
194
|
-
alt={i18n?.t('interactions.associate.altText') ?? 'Association diagram'}
|
|
195
|
-
class="w-full h-full object-contain"
|
|
196
|
-
/>
|
|
197
|
-
{/if}
|
|
198
|
-
{/if}
|
|
199
|
-
|
|
200
|
-
<!-- SVG overlay for drawing connection lines -->
|
|
201
|
-
<svg
|
|
202
|
-
part="overlay"
|
|
203
|
-
class="qti-ga-overlay absolute inset-0 w-full h-full pointer-events-none"
|
|
204
|
-
style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 10;"
|
|
205
|
-
>
|
|
206
|
-
{#each pairs as pair, index}
|
|
207
|
-
{@const [id1, id2] = pair.split(' ')}
|
|
208
|
-
{@const hotspot1 = getHotspotById(id1)}
|
|
209
|
-
{@const hotspot2 = getHotspotById(id2)}
|
|
210
|
-
{#if hotspot1 && hotspot2}
|
|
211
|
-
{@const center1 = getHotspotCenter(hotspot1.coords, hotspot1.shape)}
|
|
212
|
-
{@const center2 = getHotspotCenter(hotspot2.coords, hotspot2.shape)}
|
|
213
|
-
{@const isCorrect = isCorrectPair(id1, id2)}
|
|
214
|
-
<line
|
|
215
|
-
x1={center1.x}
|
|
216
|
-
y1={center1.y}
|
|
217
|
-
x2={center2.x}
|
|
218
|
-
y2={center2.y}
|
|
219
|
-
stroke={isCorrect ? 'var(--color-success, oklch(76% 0.177 163.223))' : 'var(--color-primary, oklch(45% 0.24 277))'}
|
|
220
|
-
stroke-width="3"
|
|
221
|
-
stroke-linecap="round"
|
|
222
|
-
/>
|
|
223
|
-
{/if}
|
|
224
|
-
{/each}
|
|
225
|
-
{#if isShowingCorrect}
|
|
226
|
-
{#each correctPairs as pair}
|
|
227
|
-
{@const [id1, id2] = pair.split(' ')}
|
|
228
|
-
{@const hotspot1 = getHotspotById(id1)}
|
|
229
|
-
{@const hotspot2 = getHotspotById(id2)}
|
|
230
|
-
{@const isInUserPairs = pairs.some((p) => p === pair || p === `${id2} ${id1}`)}
|
|
231
|
-
{#if hotspot1 && hotspot2 && !isInUserPairs}
|
|
232
|
-
{@const center1 = getHotspotCenter(hotspot1.coords, hotspot1.shape)}
|
|
233
|
-
{@const center2 = getHotspotCenter(hotspot2.coords, hotspot2.shape)}
|
|
234
|
-
<line
|
|
235
|
-
x1={center1.x}
|
|
236
|
-
y1={center1.y}
|
|
237
|
-
x2={center2.x}
|
|
238
|
-
y2={center2.y}
|
|
239
|
-
stroke="var(--color-success, oklch(76% 0.177 163.223))"
|
|
240
|
-
stroke-width="2"
|
|
241
|
-
stroke-dasharray="4,4"
|
|
242
|
-
stroke-linecap="round"
|
|
243
|
-
opacity="0.6"
|
|
244
|
-
/>
|
|
245
|
-
{/if}
|
|
246
|
-
{/each}
|
|
247
|
-
{/if}
|
|
248
|
-
</svg>
|
|
249
|
-
|
|
250
|
-
<!-- Clickable hotspot areas -->
|
|
251
|
-
{#each parsedInteraction.associableHotspots as hotspot}
|
|
252
|
-
{@const isSelected = isHotspotSelected(hotspot.identifier)}
|
|
253
|
-
{@const isMaxed = isHotspotMaxed(hotspot.identifier)}
|
|
254
|
-
{@const isBlocked = blockedHotspots.has(hotspot.identifier)}
|
|
255
|
-
{@const usageCount = getHotspotUsageCount(hotspot.identifier)}
|
|
256
|
-
{@const isCorrect = isHotspotInCorrectPair(hotspot.identifier)}
|
|
257
|
-
|
|
258
|
-
{#if hotspot.shape === 'rect'}
|
|
259
|
-
{@const [x1, y1, x2, y2] = hotspot.coords.split(',').map(Number)}
|
|
260
|
-
<button
|
|
261
|
-
part="hotspot"
|
|
262
|
-
class="qti-ga-hotspot absolute border-2 transition-all {isSelected
|
|
263
|
-
? 'bg-primary/40 border-primary border-4'
|
|
264
|
-
: isCorrect
|
|
265
|
-
? 'bg-success/20 border-success'
|
|
266
|
-
: 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
|
|
267
|
-
? 'opacity-40 cursor-not-allowed'
|
|
268
|
-
: canInteract
|
|
269
|
-
? 'cursor-pointer'
|
|
270
|
-
: 'cursor-not-allowed opacity-70'}"
|
|
271
|
-
style="left: {x1}px; top: {y1}px; width: {x2 - x1}px; height: {y2 -
|
|
272
|
-
y1}px; z-index: 20;"
|
|
273
|
-
onclick={() => handleHotspotClick(hotspot.identifier)}
|
|
274
|
-
disabled={!canInteract || isMaxed}
|
|
275
|
-
aria-disabled={isBlocked ? 'true' : undefined}
|
|
276
|
-
aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
|
|
277
|
-
>
|
|
278
|
-
<span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
|
|
279
|
-
</button>
|
|
280
|
-
{:else if hotspot.shape === 'circle'}
|
|
281
|
-
{@const [cx, cy, r] = hotspot.coords.split(',').map(Number)}
|
|
282
|
-
<button
|
|
283
|
-
part="hotspot"
|
|
284
|
-
class="qti-ga-hotspot qti-ga-hotspot-circle absolute rounded-full border-2 flex items-center justify-center transition-all {isSelected
|
|
285
|
-
? 'bg-primary/40 border-primary border-4'
|
|
286
|
-
: isCorrect
|
|
287
|
-
? 'bg-success/20 border-success'
|
|
288
|
-
: 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
|
|
289
|
-
? 'opacity-40 cursor-not-allowed'
|
|
290
|
-
: canInteract
|
|
291
|
-
? 'cursor-pointer'
|
|
292
|
-
: 'cursor-not-allowed opacity-70'}"
|
|
293
|
-
style="left: {cx - r}px; top: {cy - r}px; width: {r * 2}px; height: {r *
|
|
294
|
-
2}px; z-index: 20;"
|
|
295
|
-
onclick={() => handleHotspotClick(hotspot.identifier)}
|
|
296
|
-
disabled={!canInteract || isMaxed}
|
|
297
|
-
aria-disabled={isBlocked ? 'true' : undefined}
|
|
298
|
-
aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
|
|
299
|
-
>
|
|
300
|
-
<span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
|
|
301
|
-
</button>
|
|
302
|
-
{:else if hotspot.shape === 'ellipse'}
|
|
303
|
-
<!-- Ellipse: QTI coords are cx,cy,rx,ry — use bounding box for hit target -->
|
|
304
|
-
{@const [cx, cy, rx, ry] = hotspot.coords.split(',').map(Number)}
|
|
305
|
-
<button
|
|
306
|
-
part="hotspot"
|
|
307
|
-
class="qti-ga-hotspot absolute border-2 flex items-center justify-center transition-all {isSelected
|
|
308
|
-
? 'bg-primary/40 border-primary border-4'
|
|
309
|
-
: isCorrect
|
|
310
|
-
? 'bg-success/20 border-success'
|
|
311
|
-
: 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
|
|
312
|
-
? 'opacity-40 cursor-not-allowed'
|
|
313
|
-
: canInteract
|
|
314
|
-
? 'cursor-pointer'
|
|
315
|
-
: 'cursor-not-allowed opacity-70'}"
|
|
316
|
-
style="left: {cx - rx}px; top: {cy - ry}px; width: {rx * 2}px; height: {ry * 2}px; border-radius: 50%; z-index: 20;"
|
|
317
|
-
onclick={() => handleHotspotClick(hotspot.identifier)}
|
|
318
|
-
disabled={!canInteract || isMaxed}
|
|
319
|
-
aria-disabled={isBlocked ? 'true' : undefined}
|
|
320
|
-
aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
|
|
321
|
-
>
|
|
322
|
-
<span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
|
|
323
|
-
</button>
|
|
324
|
-
{:else if hotspot.shape === 'poly'}
|
|
325
|
-
<!-- Polygon: use axis-aligned bounding box of all vertices for hit target -->
|
|
326
|
-
{@const pts = hotspot.coords.split(',').map(Number)}
|
|
327
|
-
{@const xs = pts.filter((_, i) => i % 2 === 0)}
|
|
328
|
-
{@const ys = pts.filter((_, i) => i % 2 !== 0)}
|
|
329
|
-
{@const x1 = Math.min(...xs)}
|
|
330
|
-
{@const y1 = Math.min(...ys)}
|
|
331
|
-
{@const x2 = Math.max(...xs)}
|
|
332
|
-
{@const y2 = Math.max(...ys)}
|
|
333
|
-
<button
|
|
334
|
-
part="hotspot"
|
|
335
|
-
class="qti-ga-hotspot absolute border-2 flex items-center justify-center transition-all {isSelected
|
|
336
|
-
? 'bg-primary/40 border-primary border-4'
|
|
337
|
-
: isCorrect
|
|
338
|
-
? 'bg-success/20 border-success'
|
|
339
|
-
: 'bg-primary/10 border-primary hover:bg-primary/20'} {isMaxed || isBlocked
|
|
340
|
-
? 'opacity-40 cursor-not-allowed'
|
|
341
|
-
: canInteract
|
|
342
|
-
? 'cursor-pointer'
|
|
343
|
-
: 'cursor-not-allowed opacity-70'}"
|
|
344
|
-
style="left: {x1}px; top: {y1}px; width: {x2 - x1}px; height: {y2 - y1}px; z-index: 20;"
|
|
345
|
-
onclick={() => handleHotspotClick(hotspot.identifier)}
|
|
346
|
-
disabled={!canInteract || isMaxed}
|
|
347
|
-
aria-disabled={isBlocked ? 'true' : undefined}
|
|
348
|
-
aria-label="{hotspot.label} ({usageCount}/{hotspot.matchMax} connections){isCorrect ? '. Correct answer' : isBlocked ? '. Not available due to match group restriction' : ''}"
|
|
349
|
-
>
|
|
350
|
-
<span class="text-xs font-bold text-primary-content">{hotspot.label}</span>
|
|
351
|
-
</button>
|
|
352
|
-
{/if}
|
|
353
|
-
{/each}
|
|
354
|
-
</div>
|
|
355
|
-
|
|
356
|
-
{#if selectedHotspot}
|
|
357
|
-
<div class="alert alert-info mt-2">
|
|
358
|
-
<svg
|
|
359
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
360
|
-
fill="none"
|
|
361
|
-
viewBox="0 0 24 24"
|
|
362
|
-
part="selected-icon"
|
|
363
|
-
class="qti-icon stroke-current shrink-0 w-6 h-6"
|
|
364
|
-
>
|
|
365
|
-
<path
|
|
366
|
-
stroke-linecap="round"
|
|
367
|
-
stroke-linejoin="round"
|
|
368
|
-
stroke-width="2"
|
|
369
|
-
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
370
|
-
></path>
|
|
371
|
-
</svg>
|
|
372
|
-
<span>
|
|
373
|
-
{@html i18n?.t('interactions.associate.selectAnotherHotspot', { label: getHotspotById(selectedHotspot)?.label }) ?? `Selected: <strong>${getHotspotById(selectedHotspot)?.label}</strong>. Click another hotspot to create an association.`}
|
|
374
|
-
</span>
|
|
375
|
-
</div>
|
|
376
|
-
{/if}
|
|
377
|
-
</div>
|
|
378
|
-
|
|
379
|
-
<!-- Associations List -->
|
|
380
|
-
<div part="panel" class="qti-ga-panel w-full lg:w-80">
|
|
381
|
-
<div class="qti-ga-card card bg-base-100 border border-base-300">
|
|
382
|
-
<div class="qti-ga-card-body card-body p-4">
|
|
383
|
-
<h3 class="card-title text-sm">
|
|
384
|
-
Associations ({pairs.length}/{parsedInteraction.maxAssociations})
|
|
385
|
-
</h3>
|
|
386
|
-
|
|
387
|
-
{#if pairs.length === 0}
|
|
388
|
-
<p class="text-sm text-base-content/60">
|
|
389
|
-
Click two hotspots on the image to create an association.
|
|
390
|
-
</p>
|
|
391
|
-
{:else}
|
|
392
|
-
<div class="space-y-2">
|
|
393
|
-
{#each pairs as pair, index}
|
|
394
|
-
{@const [id1, id2] = pair.split(' ')}
|
|
395
|
-
{@const hotspot1 = getHotspotById(id1)}
|
|
396
|
-
{@const hotspot2 = getHotspotById(id2)}
|
|
397
|
-
{@const isCorrect = isCorrectPair(id1, id2)}
|
|
398
|
-
<div
|
|
399
|
-
class="flex items-center gap-2 p-2 rounded-lg bg-base-200 border border-base-300 {isCorrect ? 'border-success bg-success/10' : ''}"
|
|
400
|
-
>
|
|
401
|
-
<div class="badge badge-sm {isCorrect ? 'badge-success' : 'badge-primary'}">{index + 1}</div>
|
|
402
|
-
<div class="flex-1 text-sm">
|
|
403
|
-
<span class="font-medium">{hotspot1?.label}</span>
|
|
404
|
-
<span class="mx-1">↔</span>
|
|
405
|
-
<span class="font-medium">{hotspot2?.label}</span>
|
|
406
|
-
</div>
|
|
407
|
-
{#if canInteract}
|
|
408
|
-
<button
|
|
409
|
-
class="btn btn-xs btn-ghost btn-circle"
|
|
410
|
-
onclick={() => removePair(index)}
|
|
411
|
-
aria-label={i18n?.t('interactions.associate.removeAssociation') ?? 'Remove association'}
|
|
412
|
-
>
|
|
413
|
-
<svg
|
|
414
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
415
|
-
part="remove-icon"
|
|
416
|
-
class="qti-icon-sm h-4 w-4"
|
|
417
|
-
fill="none"
|
|
418
|
-
viewBox="0 0 24 24"
|
|
419
|
-
stroke="currentColor"
|
|
420
|
-
>
|
|
421
|
-
<path
|
|
422
|
-
stroke-linecap="round"
|
|
423
|
-
stroke-linejoin="round"
|
|
424
|
-
stroke-width="2"
|
|
425
|
-
d="M6 18L18 6M6 6l12 12"
|
|
426
|
-
/>
|
|
427
|
-
</svg>
|
|
428
|
-
</button>
|
|
429
|
-
{/if}
|
|
430
|
-
</div>
|
|
431
|
-
{/each}
|
|
432
|
-
</div>
|
|
433
|
-
{/if}
|
|
434
|
-
|
|
435
|
-
{#if parsedInteraction.minAssociations > 0}
|
|
436
|
-
<div class="text-xs text-base-content/60 mt-2">
|
|
437
|
-
Minimum required: {parsedInteraction.minAssociations}
|
|
438
|
-
</div>
|
|
439
|
-
{/if}
|
|
440
|
-
</div>
|
|
441
|
-
</div>
|
|
442
|
-
</div>
|
|
443
|
-
</div>
|
|
444
|
-
{/if}
|
|
445
|
-
</div>
|
|
446
|
-
|
|
447
|
-
<style>
|
|
448
|
-
/* Ensure proper clickable areas */
|
|
449
|
-
:global(.qti-graphic-associate-interaction button) {
|
|
450
|
-
min-height: unset;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
|
|
454
|
-
.qti-icon {
|
|
455
|
-
width: 1.5rem;
|
|
456
|
-
height: 1.5rem;
|
|
457
|
-
flex: 0 0 auto;
|
|
458
|
-
}
|
|
459
|
-
.qti-icon-sm {
|
|
460
|
-
width: 1rem;
|
|
461
|
-
height: 1rem;
|
|
462
|
-
flex: 0 0 auto;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/* Minimal layout so this works without Tailwind utilities */
|
|
466
|
-
.qti-ga-layout {
|
|
467
|
-
display: flex;
|
|
468
|
-
gap: 1rem;
|
|
469
|
-
flex-wrap: wrap;
|
|
470
|
-
}
|
|
471
|
-
.qti-ga-image-area {
|
|
472
|
-
flex: 1 1 520px;
|
|
473
|
-
min-width: 280px;
|
|
474
|
-
}
|
|
475
|
-
.qti-ga-stage {
|
|
476
|
-
position: relative;
|
|
477
|
-
border-radius: 0.75rem;
|
|
478
|
-
overflow: hidden;
|
|
479
|
-
border: 2px solid var(--color-base-300, oklch(95% 0 0));
|
|
480
|
-
background: var(--color-base-200, oklch(98% 0 0));
|
|
481
|
-
}
|
|
482
|
-
/* Critical: overlay must be absolutely positioned even without Tailwind utilities */
|
|
483
|
-
.qti-ga-overlay {
|
|
484
|
-
position: absolute;
|
|
485
|
-
inset: 0;
|
|
486
|
-
}
|
|
487
|
-
/* Critical: hotspot buttons are absolutely positioned via inline styles; ensure `position:absolute` exists */
|
|
488
|
-
.qti-ga-hotspot {
|
|
489
|
-
position: absolute;
|
|
490
|
-
}
|
|
491
|
-
.qti-ga-panel {
|
|
492
|
-
flex: 0 0 20rem;
|
|
493
|
-
min-width: 18rem;
|
|
494
|
-
}
|
|
495
|
-
.qti-ga-card {
|
|
496
|
-
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
497
|
-
border-radius: 0.75rem;
|
|
498
|
-
background: var(--color-base-100, oklch(100% 0 0));
|
|
499
|
-
}
|
|
500
|
-
.qti-ga-card-body {
|
|
501
|
-
padding: 1rem;
|
|
502
|
-
}
|
|
503
|
-
</style>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Svelte component exported via web component
|
|
2
|
-
|
|
3
|
-
export const metadata = {
|
|
4
|
-
interactionType: 'graphicAssociateInteraction',
|
|
5
|
-
tagName: 'pie-qti-graphic-associate',
|
|
6
|
-
name: 'default-graphic-associate',
|
|
7
|
-
description: 'Default Svelte-based graphic associate interaction',
|
|
8
|
-
priority: 0,
|
|
9
|
-
};
|