@pie-qti/default-components 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +25958 -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 -2
- package/dist/shared/index.js +1 -2
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/utils/eventHelpers.d.ts +6 -1
- package/dist/shared/utils/eventHelpers.js +7 -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 +16 -1
- package/dist/shared/utils/webComponentHelpers.js +13 -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 -310
- package/src/plugins/associate/index.ts +0 -9
- package/src/plugins/choice/ChoiceInteraction.svelte +0 -358
- 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 -150
- 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 -17
- package/src/shared/styles/shared.css +0 -16
- package/src/shared/utils/eventHelpers.ts +0 -52
- package/src/shared/utils/matchGroupUtils.ts +0 -14
- package/src/shared/utils/pairHelpers.ts +0 -109
- package/src/shared/utils/touchDragHelper.ts +0 -1
- package/src/shared/utils/webComponentHelpers.ts +0 -27
- package/src/svelte-shims.d.ts +0 -9
- /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-hottext" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import type { HottextInteractionData } 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
|
-
|
|
10
|
-
interface Props {
|
|
11
|
-
interaction?: HottextInteractionData | string;
|
|
12
|
-
response?: string | string[] | null;
|
|
13
|
-
correctResponse?: string | string[] | null;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
role?: string;
|
|
16
|
-
i18n?: I18nProvider;
|
|
17
|
-
onChange?: (value: string | string[]) => void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
|
|
21
|
-
|
|
22
|
-
// Parse props that may be JSON strings (web component usage)
|
|
23
|
-
const parsedInteraction = $derived(parseJsonProp<HottextInteractionData>(interaction));
|
|
24
|
-
const parsedResponse = $derived(parseJsonProp<string | string[]>(response));
|
|
25
|
-
const parsedCorrectResponse = $derived(parseJsonProp<string | string[]>(correctResponse));
|
|
26
|
-
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
27
|
-
|
|
28
|
-
// Get correct IDs as array
|
|
29
|
-
const correctIds = $derived.by(() => {
|
|
30
|
-
if (!isShowingCorrect) return [];
|
|
31
|
-
if (Array.isArray(parsedCorrectResponse)) {
|
|
32
|
-
return parsedCorrectResponse;
|
|
33
|
-
}
|
|
34
|
-
return parsedCorrectResponse ? [parsedCorrectResponse] : [];
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Get reference to the root element for event dispatching
|
|
38
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
39
|
-
|
|
40
|
-
let selectedIds = $state<string[]>([]);
|
|
41
|
-
|
|
42
|
-
$effect(() => {
|
|
43
|
-
// Sync with parent response changes
|
|
44
|
-
// Handle both single string (maxChoices=1) and array (maxChoices>1) formats
|
|
45
|
-
if (Array.isArray(parsedResponse)) {
|
|
46
|
-
selectedIds = [...parsedResponse];
|
|
47
|
-
} else if (typeof parsedResponse === 'string') {
|
|
48
|
-
selectedIds = [parsedResponse];
|
|
49
|
-
} else {
|
|
50
|
-
selectedIds = [];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
let contentElement: HTMLDivElement | null = $state(null);
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check if selection limit has been reached
|
|
57
|
-
*/
|
|
58
|
-
// maxChoices=0 means unlimited per QTI spec
|
|
59
|
-
const canSelectMore = $derived(
|
|
60
|
-
parsedInteraction
|
|
61
|
-
? parsedInteraction.maxChoices === 0 || selectedIds.length < parsedInteraction.maxChoices
|
|
62
|
-
: false
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Check if a hottext element is selected
|
|
67
|
-
*/
|
|
68
|
-
function isSelected(identifier: string): boolean {
|
|
69
|
-
return selectedIds.includes(identifier);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Check if a hottext element is correct
|
|
74
|
-
*/
|
|
75
|
-
function isCorrect(identifier: string): boolean {
|
|
76
|
-
return isShowingCorrect && correctIds.includes(identifier);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Handle hottext element click
|
|
81
|
-
*/
|
|
82
|
-
function handleHottextClick(identifier: string) {
|
|
83
|
-
if (disabled || !parsedInteraction) return;
|
|
84
|
-
|
|
85
|
-
const currentlySelected = isSelected(identifier);
|
|
86
|
-
|
|
87
|
-
if (currentlySelected) {
|
|
88
|
-
// Deselect
|
|
89
|
-
selectedIds = selectedIds.filter((id) => id !== identifier);
|
|
90
|
-
} else if (canSelectMore) {
|
|
91
|
-
// Select
|
|
92
|
-
selectedIds = [...selectedIds, identifier];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Return single string for maxChoices=1, array for multiple selection
|
|
96
|
-
const responseValue = parsedInteraction.maxChoices === 1
|
|
97
|
-
? (selectedIds.length > 0 ? selectedIds[0] : null)
|
|
98
|
-
: selectedIds;
|
|
99
|
-
|
|
100
|
-
response = responseValue;
|
|
101
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
102
|
-
if (responseValue !== null) {
|
|
103
|
-
onChange?.(responseValue);
|
|
104
|
-
}
|
|
105
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
106
|
-
if (rootElement) {
|
|
107
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, responseValue));
|
|
108
|
-
}
|
|
109
|
-
updateHottextStyles();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Update visual styles of hottext elements based on selection state
|
|
114
|
-
*/
|
|
115
|
-
function updateHottextStyles() {
|
|
116
|
-
if (!contentElement) return;
|
|
117
|
-
|
|
118
|
-
const hottextElements = contentElement.querySelectorAll('hottext');
|
|
119
|
-
hottextElements.forEach((elem: Element) => {
|
|
120
|
-
const identifier = elem.getAttribute('identifier');
|
|
121
|
-
if (identifier) {
|
|
122
|
-
const htmlElem = elem as HTMLElement;
|
|
123
|
-
const selected = isSelected(identifier);
|
|
124
|
-
|
|
125
|
-
// Update ARIA state
|
|
126
|
-
htmlElem.setAttribute('aria-pressed', selected ? 'true' : 'false');
|
|
127
|
-
|
|
128
|
-
// Update classes
|
|
129
|
-
const isCorrectChoice = isCorrect(identifier);
|
|
130
|
-
if (selected) {
|
|
131
|
-
htmlElem.classList.add('selected');
|
|
132
|
-
htmlElem.classList.remove('selectable');
|
|
133
|
-
} else {
|
|
134
|
-
htmlElem.classList.remove('selected');
|
|
135
|
-
if (canSelectMore && !disabled) {
|
|
136
|
-
htmlElem.classList.add('selectable');
|
|
137
|
-
} else {
|
|
138
|
-
htmlElem.classList.remove('selectable');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (isCorrectChoice) {
|
|
142
|
-
htmlElem.classList.add('correct');
|
|
143
|
-
} else {
|
|
144
|
-
htmlElem.classList.remove('correct');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Initialize hottext elements with click handlers and keyboard accessibility
|
|
152
|
-
*/
|
|
153
|
-
$effect(() => {
|
|
154
|
-
if (!contentElement) return;
|
|
155
|
-
|
|
156
|
-
const hottextElements = contentElement.querySelectorAll('hottext');
|
|
157
|
-
hottextElements.forEach((elem: Element) => {
|
|
158
|
-
const identifier = elem.getAttribute('identifier');
|
|
159
|
-
if (identifier) {
|
|
160
|
-
const htmlElem = elem as HTMLElement;
|
|
161
|
-
|
|
162
|
-
// Make it visually interactive
|
|
163
|
-
htmlElem.style.cursor = disabled ? 'default' : 'pointer';
|
|
164
|
-
htmlElem.style.padding = '2px 4px';
|
|
165
|
-
htmlElem.style.borderRadius = '3px';
|
|
166
|
-
htmlElem.style.transition = 'all 0.2s';
|
|
167
|
-
|
|
168
|
-
// Make keyboard accessible
|
|
169
|
-
htmlElem.setAttribute('role', 'button');
|
|
170
|
-
htmlElem.setAttribute('tabindex', disabled ? '-1' : '0');
|
|
171
|
-
htmlElem.setAttribute('aria-pressed', isSelected(identifier) ? 'true' : 'false');
|
|
172
|
-
|
|
173
|
-
// Get text content for aria-label
|
|
174
|
-
const textContent = htmlElem.textContent || identifier;
|
|
175
|
-
htmlElem.setAttribute('aria-label', `Selectable text: ${textContent}`);
|
|
176
|
-
|
|
177
|
-
// Add click handler
|
|
178
|
-
htmlElem.onclick = () => handleHottextClick(identifier);
|
|
179
|
-
|
|
180
|
-
// Add keyboard handler
|
|
181
|
-
htmlElem.onkeydown = (e: KeyboardEvent) => {
|
|
182
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
183
|
-
e.preventDefault();
|
|
184
|
-
handleHottextClick(identifier);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
updateHottextStyles();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Update styles when selection or disabled state changes
|
|
195
|
-
*/
|
|
196
|
-
$effect(() => {
|
|
197
|
-
updateHottextStyles();
|
|
198
|
-
});
|
|
199
|
-
</script>
|
|
200
|
-
|
|
201
|
-
<ShadowBaseStyles />
|
|
202
|
-
|
|
203
|
-
<div bind:this={rootElement} part="root" class={['qti-hottext-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
|
|
204
|
-
{#if !parsedInteraction}
|
|
205
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
206
|
-
{:else}
|
|
207
|
-
{#if parsedInteraction.prompt}
|
|
208
|
-
<p part="prompt" class="qti-hottext-prompt font-semibold">{@html parsedInteraction.prompt}</p>
|
|
209
|
-
{/if}
|
|
210
|
-
|
|
211
|
-
<div
|
|
212
|
-
bind:this={contentElement}
|
|
213
|
-
part="content"
|
|
214
|
-
class="hottext-content qti-hottext-content prose max-w-none"
|
|
215
|
-
role="group"
|
|
216
|
-
aria-label={i18n?.t('interactions.hottext.ariaLabel') ?? 'Text selection interaction'}
|
|
217
|
-
>
|
|
218
|
-
{@html parsedInteraction.contentHtml}
|
|
219
|
-
</div>
|
|
220
|
-
|
|
221
|
-
<div part="footer" class="qti-hottext-footer flex items-center justify-between text-sm text-base-content/70">
|
|
222
|
-
<div>
|
|
223
|
-
<span class="font-medium">{i18n?.t('interactions.hottext.selected') ?? 'Selected'}:</span>
|
|
224
|
-
<span class="ml-2">{selectedIds.length} / {parsedInteraction.hottextChoices?.length ?? 0}</span>
|
|
225
|
-
{#if parsedInteraction.minChoices > 0}
|
|
226
|
-
{#if selectedIds.length >= parsedInteraction.minChoices}
|
|
227
|
-
<span class="badge badge-success badge-sm ml-2">✓ {i18n?.t('interactions.hottext.minimumMet') ?? 'Minimum met'}</span>
|
|
228
|
-
{:else}
|
|
229
|
-
<span class="badge badge-warning badge-sm ml-2">{i18n?.t('interactions.hottext.selectAtLeast', `Select at least ${parsedInteraction.minChoices}`) ?? `Select at least ${parsedInteraction.minChoices}`}</span>
|
|
230
|
-
{/if}
|
|
231
|
-
{/if}
|
|
232
|
-
</div>
|
|
233
|
-
|
|
234
|
-
{#if selectedIds.length > 0}
|
|
235
|
-
<button
|
|
236
|
-
type="button"
|
|
237
|
-
class="btn btn-sm btn-ghost"
|
|
238
|
-
onclick={() => {
|
|
239
|
-
selectedIds = [];
|
|
240
|
-
// Return null for single selection, empty array for multiple
|
|
241
|
-
const responseValue = parsedInteraction!.maxChoices === 1 ? null : [];
|
|
242
|
-
response = responseValue;
|
|
243
|
-
if (responseValue !== null) {
|
|
244
|
-
onChange?.(responseValue);
|
|
245
|
-
}
|
|
246
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
247
|
-
if (rootElement) {
|
|
248
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, responseValue));
|
|
249
|
-
}
|
|
250
|
-
updateHottextStyles();
|
|
251
|
-
}}
|
|
252
|
-
{disabled}
|
|
253
|
-
>
|
|
254
|
-
Clear Selection
|
|
255
|
-
</button>
|
|
256
|
-
{/if}
|
|
257
|
-
</div>
|
|
258
|
-
{#if parsedInteraction.maxSelectionsMessage && selectedIds.length >= parsedInteraction.maxChoices && parsedInteraction.maxChoices > 0}
|
|
259
|
-
<p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
|
|
260
|
-
{/if}
|
|
261
|
-
{/if}
|
|
262
|
-
</div>
|
|
263
|
-
|
|
264
|
-
<style>
|
|
265
|
-
.qti-selection-message {
|
|
266
|
-
font-size: 0.875rem;
|
|
267
|
-
color: var(--color-warning, oklch(77% 0.194 82));
|
|
268
|
-
margin-top: 0.25rem;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/* qti-input-control-hidden: hide visual selection indicators but keep keyboard-accessible */
|
|
272
|
-
.qti-input-control-hidden :global(hottext) {
|
|
273
|
-
cursor: pointer;
|
|
274
|
-
outline: none;
|
|
275
|
-
}
|
|
276
|
-
.qti-input-control-hidden :global(hottext[data-selected]) {
|
|
277
|
-
background-color: transparent;
|
|
278
|
-
text-decoration: underline;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/* Minimal layout so this works without Tailwind/DaisyUI */
|
|
282
|
-
.qti-hottext-interaction {
|
|
283
|
-
display: grid;
|
|
284
|
-
gap: 0.75rem;
|
|
285
|
-
}
|
|
286
|
-
.qti-hottext-prompt {
|
|
287
|
-
margin: 0;
|
|
288
|
-
}
|
|
289
|
-
.qti-hottext-footer {
|
|
290
|
-
display: flex;
|
|
291
|
-
align-items: center;
|
|
292
|
-
justify-content: space-between;
|
|
293
|
-
gap: 0.75rem;
|
|
294
|
-
flex-wrap: wrap;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
:global(.hottext-content hottext) {
|
|
298
|
-
display: inline;
|
|
299
|
-
user-select: none;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
:global(.hottext-content hottext.selectable) {
|
|
303
|
-
background-color: hsl(var(--bc) / 0.1);
|
|
304
|
-
border: 1px solid hsl(var(--bc) / 0.2);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
:global(.hottext-content hottext.selectable:hover) {
|
|
308
|
-
background-color: hsl(var(--p) / 0.2);
|
|
309
|
-
border-color: hsl(var(--p) / 0.4);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
:global(.hottext-content hottext.selected) {
|
|
313
|
-
background-color: hsl(var(--p) / 0.3);
|
|
314
|
-
border: 2px solid hsl(var(--p));
|
|
315
|
-
font-weight: 600;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
:global(.hottext-content hottext.correct) {
|
|
319
|
-
background-color: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
|
|
320
|
-
border: 1px solid var(--color-success, oklch(76% 0.177 163.223));
|
|
321
|
-
border-radius: 0.25rem;
|
|
322
|
-
padding: 2px 4px;
|
|
323
|
-
margin: -2px -4px;
|
|
324
|
-
}
|
|
325
|
-
</style>
|
package/src/plugins/index.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QTI Interaction Plugins
|
|
3
|
-
*
|
|
4
|
-
* Imports all interaction plugins to trigger web component registration.
|
|
5
|
-
* Each plugin directory contains a Svelte component that compiles to a
|
|
6
|
-
* custom element (web component).
|
|
7
|
-
*
|
|
8
|
-
* These imports have side effects: they register the custom elements
|
|
9
|
-
* with the browser's customElements registry.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// Import all Svelte custom element components to trigger registration
|
|
13
|
-
import './choice/ChoiceInteraction.svelte';
|
|
14
|
-
import './slider/SliderInteraction.svelte';
|
|
15
|
-
import './order/OrderInteraction.svelte';
|
|
16
|
-
import './match/MatchInteraction.svelte';
|
|
17
|
-
import './associate/AssociateInteraction.svelte';
|
|
18
|
-
import './gap-match/GapMatchInteraction.svelte';
|
|
19
|
-
import './hotspot/HotspotInteraction.svelte';
|
|
20
|
-
import './hottext/HottextInteraction.svelte';
|
|
21
|
-
import './media/MediaInteraction.svelte';
|
|
22
|
-
import './custom/CustomInteraction.svelte';
|
|
23
|
-
import './end-attempt/EndAttemptInteraction.svelte';
|
|
24
|
-
import './position-object/PositionObjectInteraction.svelte';
|
|
25
|
-
import './graphic-gap-match/GraphicGapMatchInteraction.svelte';
|
|
26
|
-
import './graphic-order/GraphicOrderInteraction.svelte';
|
|
27
|
-
import './graphic-associate/GraphicAssociateInteraction.svelte';
|
|
28
|
-
import './select-point/SelectPointInteraction.svelte';
|
|
29
|
-
import './extended-text/ExtendedTextInteraction.svelte';
|
|
30
|
-
import './upload/UploadInteraction.svelte';
|
|
31
|
-
import './drawing/DrawingInteraction.svelte';
|
|
32
|
-
import '../catalog/CatalogPopup.svelte';
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-match" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import type { MatchInteractionData } from '@pie-qti/item-player';
|
|
5
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
-
import { typesetAction } from '../../shared/actions/typesetAction';
|
|
7
|
-
import MatchDragDrop from '../../shared/components/MatchDragDrop.svelte';
|
|
8
|
-
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
9
|
-
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
|
|
10
|
-
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
11
|
-
|
|
12
|
-
interface Props {
|
|
13
|
-
interaction?: MatchInteractionData | string;
|
|
14
|
-
response?: string[] | null;
|
|
15
|
-
correctResponse?: string[] | null;
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
role?: string;
|
|
18
|
-
i18n?: I18nProvider;
|
|
19
|
-
typeset?: (element: HTMLElement) => void;
|
|
20
|
-
onChange?: (value: string[]) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
|
|
24
|
-
|
|
25
|
-
// Parse props that may be JSON strings (web component usage)
|
|
26
|
-
const parsedInteraction = $derived(parseJsonProp<MatchInteractionData>(interaction));
|
|
27
|
-
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
28
|
-
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
29
|
-
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
30
|
-
|
|
31
|
-
// Get reference to the root element for event dispatching
|
|
32
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
33
|
-
|
|
34
|
-
// Convert response to pairs array, or empty array
|
|
35
|
-
const pairs = $derived(parsedResponse && Array.isArray(parsedResponse) ? parsedResponse : []);
|
|
36
|
-
|
|
37
|
-
function handlePairsChange(newPairs: string[]) {
|
|
38
|
-
response = newPairs;
|
|
39
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
40
|
-
onChange?.(newPairs);
|
|
41
|
-
// Dispatch event for web component usage - event will bubble up to the host element
|
|
42
|
-
if (rootElement) {
|
|
43
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<ShadowBaseStyles />
|
|
49
|
-
|
|
50
|
-
<div bind:this={rootElement} class={['qti-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
|
|
51
|
-
{#if !parsedInteraction}
|
|
52
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
53
|
-
{:else}
|
|
54
|
-
{#if parsedInteraction.prompt}
|
|
55
|
-
<div class="mb-3 text-sm text-base-content/70">
|
|
56
|
-
{@html parsedInteraction.prompt}
|
|
57
|
-
</div>
|
|
58
|
-
{/if}
|
|
59
|
-
|
|
60
|
-
<MatchDragDrop
|
|
61
|
-
sourceSet={parsedInteraction.sourceSet}
|
|
62
|
-
targetSet={parsedInteraction.targetSet}
|
|
63
|
-
{pairs}
|
|
64
|
-
maxAssociations={parsedInteraction.maxAssociations}
|
|
65
|
-
correctPairs={isShowingCorrect ? (parsedCorrectResponse || []) : []}
|
|
66
|
-
{disabled}
|
|
67
|
-
{i18n}
|
|
68
|
-
onPairsChange={handlePairsChange}
|
|
69
|
-
/>
|
|
70
|
-
{#if parsedInteraction.maxSelectionsMessage && pairs.length >= parsedInteraction.maxAssociations && parsedInteraction.maxAssociations > 0}
|
|
71
|
-
<p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
|
|
72
|
-
{/if}
|
|
73
|
-
{/if}
|
|
74
|
-
</div>
|
|
75
|
-
|
|
76
|
-
<style>
|
|
77
|
-
.qti-selection-message {
|
|
78
|
-
font-size: 0.875rem;
|
|
79
|
-
color: var(--color-warning, oklch(77% 0.194 82));
|
|
80
|
-
margin-top: 0.5rem;
|
|
81
|
-
}
|
|
82
|
-
</style>
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-media" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import type { MediaInteractionData } 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?: MediaInteractionData | string;
|
|
12
|
-
response?: number | null;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
i18n?: I18nProvider;
|
|
15
|
-
onChange?: (value: number) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let { interaction = $bindable(), response = $bindable(), disabled = false, i18n = $bindable(), onChange }: Props = $props();
|
|
19
|
-
|
|
20
|
-
// Parse props that may be JSON strings (web component usage)
|
|
21
|
-
const parsedInteraction = $derived(parseJsonProp<MediaInteractionData>(interaction));
|
|
22
|
-
const parsedResponse = $derived(parseJsonProp<number>(response));
|
|
23
|
-
|
|
24
|
-
// Get reference to the root element for event dispatching
|
|
25
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
26
|
-
|
|
27
|
-
let playCount = $state(0);
|
|
28
|
-
let mediaElement: HTMLAudioElement | HTMLVideoElement | null = $state(null);
|
|
29
|
-
|
|
30
|
-
$effect(() => {
|
|
31
|
-
// Sync with parent response changes
|
|
32
|
-
playCount = parsedResponse ?? 0;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Check if the max play limit has been reached
|
|
37
|
-
*/
|
|
38
|
-
const hasReachedMaxPlays = $derived(
|
|
39
|
-
parsedInteraction && parsedInteraction.maxPlays > 0 && playCount >= parsedInteraction.maxPlays
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Check if the minimum play requirement has been met
|
|
44
|
-
*/
|
|
45
|
-
const hasMetMinPlays = $derived(parsedInteraction && playCount >= parsedInteraction.minPlays);
|
|
46
|
-
const mediaLabel = $derived(i18n?.t('interactions.media.ariaLabel') ?? 'Media content');
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Handle media ended event.
|
|
50
|
-
*
|
|
51
|
-
* For minPlays/maxPlays semantics, a "play" should count when the media finishes
|
|
52
|
-
* (i.e. the learner completed a play-through), not merely when playback starts.
|
|
53
|
-
*/
|
|
54
|
-
function handleEndedCountPlay() {
|
|
55
|
-
playCount++;
|
|
56
|
-
response = playCount;
|
|
57
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
58
|
-
onChange?.(playCount);
|
|
59
|
-
// Dispatch event for web component usage - event will bubble up to the host element
|
|
60
|
-
if (rootElement) {
|
|
61
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, playCount));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Handle media ended event for loop behavior.
|
|
67
|
-
* Counting plays happens first, then looping (if enabled).
|
|
68
|
-
*/
|
|
69
|
-
function handleEnded() {
|
|
70
|
-
handleEndedCountPlay();
|
|
71
|
-
if (parsedInteraction?.loop && !hasReachedMaxPlays) {
|
|
72
|
-
mediaElement?.play();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Prevent playing if max plays reached
|
|
78
|
-
*/
|
|
79
|
-
function handlePlayAttempt(e: Event) {
|
|
80
|
-
if (hasReachedMaxPlays) {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
</script>
|
|
86
|
-
|
|
87
|
-
<ShadowBaseStyles />
|
|
88
|
-
|
|
89
|
-
<div bind:this={rootElement} class="qti-media-interaction space-y-3">
|
|
90
|
-
{#if !parsedInteraction}
|
|
91
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
92
|
-
{:else}
|
|
93
|
-
{#if parsedInteraction.prompt}
|
|
94
|
-
<p class="font-semibold">{@html parsedInteraction.prompt}</p>
|
|
95
|
-
{/if}
|
|
96
|
-
|
|
97
|
-
<div class="qti-media-container media-container" part="media">
|
|
98
|
-
{#if parsedInteraction.mediaElement.type === 'audio'}
|
|
99
|
-
<audio
|
|
100
|
-
bind:this={mediaElement}
|
|
101
|
-
class="w-full"
|
|
102
|
-
controls
|
|
103
|
-
aria-label={mediaLabel}
|
|
104
|
-
autoplay={parsedInteraction.autostart}
|
|
105
|
-
loop={parsedInteraction.loop && parsedInteraction.maxPlays === 0}
|
|
106
|
-
onended={handleEnded}
|
|
107
|
-
onplaying={handlePlayAttempt}
|
|
108
|
-
>
|
|
109
|
-
<source src={parsedInteraction.mediaElement.src} type={parsedInteraction.mediaElement.mimeType} />
|
|
110
|
-
Your browser does not support the audio element.
|
|
111
|
-
</audio>
|
|
112
|
-
{:else if parsedInteraction.mediaElement.type === 'video'}
|
|
113
|
-
<video
|
|
114
|
-
bind:this={mediaElement}
|
|
115
|
-
class="w-full rounded-lg"
|
|
116
|
-
controls
|
|
117
|
-
aria-label={mediaLabel}
|
|
118
|
-
autoplay={parsedInteraction.autostart}
|
|
119
|
-
loop={parsedInteraction.loop && parsedInteraction.maxPlays === 0}
|
|
120
|
-
width={parsedInteraction.mediaElement.width}
|
|
121
|
-
height={parsedInteraction.mediaElement.height}
|
|
122
|
-
onended={handleEnded}
|
|
123
|
-
onplaying={handlePlayAttempt}
|
|
124
|
-
>
|
|
125
|
-
<source src={parsedInteraction.mediaElement.src} type={parsedInteraction.mediaElement.mimeType} />
|
|
126
|
-
Your browser does not support the video element.
|
|
127
|
-
</video>
|
|
128
|
-
{:else if parsedInteraction.mediaElement.type === 'object'}
|
|
129
|
-
<object
|
|
130
|
-
data={parsedInteraction.mediaElement.src}
|
|
131
|
-
type={parsedInteraction.mediaElement.mimeType}
|
|
132
|
-
width={parsedInteraction.mediaElement.width}
|
|
133
|
-
height={parsedInteraction.mediaElement.height}
|
|
134
|
-
class="w-full"
|
|
135
|
-
aria-label={i18n?.t('interactions.media.ariaLabel') ?? 'Media content'}
|
|
136
|
-
>
|
|
137
|
-
<p>Your browser does not support this media type.</p>
|
|
138
|
-
</object>
|
|
139
|
-
{/if}
|
|
140
|
-
</div>
|
|
141
|
-
|
|
142
|
-
<div class="qti-media-stats flex items-center justify-between text-sm text-base-content/70" part="stats" role="status" aria-live="polite">
|
|
143
|
-
<div>
|
|
144
|
-
<span class="font-medium">Play count:</span>
|
|
145
|
-
<span class="ml-2">{playCount}</span>
|
|
146
|
-
</div>
|
|
147
|
-
|
|
148
|
-
{#if parsedInteraction.minPlays > 0}
|
|
149
|
-
<div class="flex items-center gap-2">
|
|
150
|
-
{#if hasMetMinPlays}
|
|
151
|
-
<span class="badge badge-success badge-sm">✓ Requirement met</span>
|
|
152
|
-
{:else}
|
|
153
|
-
<span class="badge badge-warning badge-sm">
|
|
154
|
-
Play at least {parsedInteraction.minPlays} time{parsedInteraction.minPlays === 1 ? '' : 's'}
|
|
155
|
-
</span>
|
|
156
|
-
{/if}
|
|
157
|
-
</div>
|
|
158
|
-
{/if}
|
|
159
|
-
|
|
160
|
-
{#if parsedInteraction.minPlays > 0 && !hasMetMinPlays}
|
|
161
|
-
<div>
|
|
162
|
-
<span class="font-medium">Remaining:</span>
|
|
163
|
-
<span class="ml-2">{Math.max(0, parsedInteraction.minPlays - playCount)}</span>
|
|
164
|
-
</div>
|
|
165
|
-
{/if}
|
|
166
|
-
</div>
|
|
167
|
-
|
|
168
|
-
{#if hasReachedMaxPlays}
|
|
169
|
-
<div class="alert alert-info" role="status" aria-live="polite">
|
|
170
|
-
<svg
|
|
171
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
172
|
-
fill="none"
|
|
173
|
-
viewBox="0 0 24 24"
|
|
174
|
-
part="limit-icon"
|
|
175
|
-
class="qti-icon stroke-current shrink-0 w-6 h-6"
|
|
176
|
-
>
|
|
177
|
-
<path
|
|
178
|
-
stroke-linecap="round"
|
|
179
|
-
stroke-linejoin="round"
|
|
180
|
-
stroke-width="2"
|
|
181
|
-
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
182
|
-
></path>
|
|
183
|
-
</svg>
|
|
184
|
-
<span>{i18n?.t('interactions.media.maxPlayLimitReached') ?? 'Maximum play limit reached'}</span>
|
|
185
|
-
</div>
|
|
186
|
-
{/if}
|
|
187
|
-
{/if}
|
|
188
|
-
</div>
|
|
189
|
-
|
|
190
|
-
<style>
|
|
191
|
-
/* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
|
|
192
|
-
.qti-icon {
|
|
193
|
-
width: 1.5rem;
|
|
194
|
-
height: 1.5rem;
|
|
195
|
-
flex: 0 0 auto;
|
|
196
|
-
}
|
|
197
|
-
/* Minimal layout if host doesn't provide utility classes */
|
|
198
|
-
.qti-media-interaction {
|
|
199
|
-
display: grid;
|
|
200
|
-
gap: 0.75rem;
|
|
201
|
-
}
|
|
202
|
-
.qti-media-container :global(audio),
|
|
203
|
-
.qti-media-container :global(video),
|
|
204
|
-
.qti-media-container :global(object) {
|
|
205
|
-
width: 100%;
|
|
206
|
-
max-width: 100%;
|
|
207
|
-
display: block;
|
|
208
|
-
}
|
|
209
|
-
.qti-media-stats {
|
|
210
|
-
display: flex;
|
|
211
|
-
align-items: center;
|
|
212
|
-
justify-content: space-between;
|
|
213
|
-
gap: 0.75rem;
|
|
214
|
-
flex-wrap: wrap;
|
|
215
|
-
}
|
|
216
|
-
</style>
|