@pie-qti/default-components 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/shared/extensions/MathLiveEditor.d.ts +1 -0
  2. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
  3. package/dist/shared/extensions/MathLiveEditor.js +3 -7
  4. package/dist/shared/utils/eventHelpers.d.ts +3 -11
  5. package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
  6. package/dist/shared/utils/eventHelpers.js +7 -1
  7. package/dist/shared/utils/pairHelpers.d.ts +15 -2
  8. package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
  9. package/dist/shared/utils/pairHelpers.js +30 -8
  10. package/dist/shared/utils/touchDragHelper.d.ts +1 -32
  11. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
  12. package/dist/shared/utils/touchDragHelper.js +1 -168
  13. package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
  14. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
  15. package/dist/shared/utils/webComponentHelpers.js +3 -3
  16. package/package.json +113 -91
  17. package/src/plugins/gap-match/GapMatchInteraction.svelte +25 -10
  18. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +32 -37
  19. package/src/plugins/hottext/HottextInteraction.svelte +1 -1
  20. package/src/plugins/media/MediaInteraction.svelte +2 -2
  21. package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -6
  22. package/src/plugins/select-point/SelectPointInteraction.svelte +0 -14
  23. package/src/shared/components/DrawingCanvas.svelte +17 -1
  24. package/src/shared/components/MatchDragDrop.svelte +24 -23
  25. package/src/shared/components/ShadowBaseStyles.svelte +1 -2
  26. package/src/shared/extensions/MathLiveEditor.ts +3 -8
  27. package/src/shared/utils/eventHelpers.ts +12 -3
  28. package/src/shared/utils/pairHelpers.ts +32 -9
  29. package/src/shared/utils/touchDragHelper.ts +1 -211
  30. package/src/shared/utils/webComponentHelpers.ts +5 -5
  31. package/.turbo/turbo-build.log +0 -1
  32. package/CHANGELOG.md +0 -9
  33. package/STYLING.md +0 -226
  34. package/svelte.config.js +0 -9
  35. package/tests/index.test.ts +0 -8
  36. package/tsconfig.json +0 -20
package/package.json CHANGED
@@ -1,93 +1,115 @@
1
1
  {
2
- "name": "@pie-qti/default-components",
3
- "version": "0.1.1",
4
- "description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "scripts": {
9
- "build": "tsc",
10
- "test": "bun test",
11
- "typecheck": "tsc --noEmit",
12
- "check": "../assessment-player/node_modules/.bin/svelte-check --tsconfig ./tsconfig.json",
13
- "lint": "biome check .",
14
- "lint:fix": "biome check --write .",
15
- "format": "biome format --write ."
16
- },
17
- "keywords": [
18
- "qti",
19
- "qti2", "qti3",
20
- "qti2.2",
21
- "assessment",
22
- "player",
23
- "components",
24
- "svelte",
25
- "web-components"
26
- ],
27
- "license": "MIT",
28
- "dependencies": {
29
- "@pie-qti/i18n": "workspace:*",
30
- "@pie-qti/item-player": "workspace:*",
31
- "@tiptap/core": "^3.15.3",
32
- "@tiptap/extension-mathematics": "^3.15.3",
33
- "@tiptap/extension-placeholder": "^3.15.3",
34
- "@tiptap/starter-kit": "^3.15.3",
35
- "mathlive": "^0.108.2"
36
- },
37
- "peerDependencies": {
38
- "svelte": "^5.46.1"
39
- },
40
- "devDependencies": {
41
- "@biomejs/biome": "^2.3.11",
42
- "@types/node": "^25.0.3",
43
- "svelte": "^5.46.1",
44
- "svelte-check": "^4.3.5",
45
- "typescript": "^5.9.3"
46
- },
47
- "exports": {
48
- ".": {
49
- "types": "./dist/index.d.ts",
50
- "import": "./dist/index.js"
51
- },
52
- "./MathContent.svelte": {
53
- "svelte": "./src/shared/components/MathContent.svelte",
54
- "import": "./src/shared/components/MathContent.svelte",
55
- "default": "./src/shared/components/MathContent.svelte"
56
- },
57
- "./plugins": {
58
- "svelte": "./src/plugins/index.ts",
59
- "import": "./src/plugins/index.ts",
60
- "default": "./src/plugins/index.ts"
61
- },
62
- "./shared": {
63
- "types": "./dist/shared/index.d.ts",
64
- "import": "./dist/shared/index.js"
65
- },
66
- "./plugins/*/*.svelte": {
67
- "svelte": "./src/plugins/*/*.svelte",
68
- "import": "./src/plugins/*/*.svelte",
69
- "default": "./src/plugins/*/*.svelte"
70
- },
71
- "./plugins/*/index": {
72
- "types": "./dist/plugins/*/index.d.ts",
73
- "import": "./dist/plugins/*/index.js"
74
- },
75
- "./shared/components/*.svelte": {
76
- "svelte": "./src/shared/components/*.svelte",
77
- "import": "./src/shared/components/*.svelte",
78
- "default": "./src/shared/components/*.svelte"
79
- },
80
- "./shared/utils/*": {
81
- "types": "./dist/shared/utils/*.d.ts",
82
- "import": "./dist/shared/utils/*.js"
83
- },
84
- "./shared/actions/*": {
85
- "types": "./dist/shared/actions/*.d.ts",
86
- "import": "./dist/shared/actions/*.js"
87
- },
88
- "./shared/extensions/*": {
89
- "types": "./dist/shared/extensions/*.d.ts",
90
- "import": "./dist/shared/extensions/*.js"
91
- }
92
- }
2
+ "name": "@pie-qti/default-components",
3
+ "version": "0.1.4",
4
+ "description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "bun test",
11
+ "typecheck": "tsc --noEmit",
12
+ "check": "svelte-check --tsconfig ./tsconfig.json",
13
+ "lint": "biome check .",
14
+ "lint:fix": "biome check --write .",
15
+ "format": "biome format --write ."
16
+ },
17
+ "keywords": [
18
+ "qti",
19
+ "qti2",
20
+ "qti3",
21
+ "qti2.2",
22
+ "assessment",
23
+ "player",
24
+ "components",
25
+ "svelte",
26
+ "web-components"
27
+ ],
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "@pie-qti/i18n": "0.1.4",
31
+ "@pie-qti/item-player": "0.1.4",
32
+ "@pie-qti/qti-common": "0.1.4",
33
+ "@tiptap/core": "^3.15.3",
34
+ "@tiptap/extension-mathematics": "^3.15.3",
35
+ "@tiptap/extension-placeholder": "^3.15.3",
36
+ "@tiptap/starter-kit": "^3.15.3",
37
+ "mathlive": "^0.108.2"
38
+ },
39
+ "peerDependencies": {
40
+ "svelte": "^5.54.0"
41
+ },
42
+ "devDependencies": {
43
+ "@biomejs/biome": "^2.4.8",
44
+ "@types/node": "^25.0.3",
45
+ "svelte": "^5.54.0",
46
+ "svelte-check": "^4.3.5",
47
+ "typescript": "^5.9.3"
48
+ },
49
+ "exports": {
50
+ ".": {
51
+ "types": "./dist/index.d.ts",
52
+ "import": "./dist/index.js"
53
+ },
54
+ "./MathContent.svelte": {
55
+ "svelte": "./src/shared/components/MathContent.svelte",
56
+ "import": "./src/shared/components/MathContent.svelte",
57
+ "default": "./src/shared/components/MathContent.svelte"
58
+ },
59
+ "./plugins": {
60
+ "svelte": "./src/plugins/index.ts",
61
+ "import": "./src/plugins/index.ts",
62
+ "default": "./src/plugins/index.ts"
63
+ },
64
+ "./shared": {
65
+ "types": "./dist/shared/index.d.ts",
66
+ "import": "./dist/shared/index.js"
67
+ },
68
+ "./plugins/*/*.svelte": {
69
+ "svelte": "./src/plugins/*/*.svelte",
70
+ "import": "./src/plugins/*/*.svelte",
71
+ "default": "./src/plugins/*/*.svelte"
72
+ },
73
+ "./plugins/*/index": {
74
+ "types": "./dist/plugins/*/index.d.ts",
75
+ "import": "./dist/plugins/*/index.js"
76
+ },
77
+ "./shared/components/*.svelte": {
78
+ "svelte": "./src/shared/components/*.svelte",
79
+ "import": "./src/shared/components/*.svelte",
80
+ "default": "./src/shared/components/*.svelte"
81
+ },
82
+ "./shared/utils/*": {
83
+ "types": "./dist/shared/utils/*.d.ts",
84
+ "import": "./dist/shared/utils/*.js"
85
+ },
86
+ "./shared/actions/*": {
87
+ "types": "./dist/shared/actions/*.d.ts",
88
+ "import": "./dist/shared/actions/*.js"
89
+ },
90
+ "./shared/extensions/*": {
91
+ "types": "./dist/shared/extensions/*.d.ts",
92
+ "import": "./dist/shared/extensions/*.js"
93
+ }
94
+ },
95
+ "repository": {
96
+ "type": "git",
97
+ "url": "https://github.com/pie-framework/pie-qti.git",
98
+ "directory": "packages/default-components"
99
+ },
100
+ "homepage": "https://github.com/pie-framework/pie-qti/tree/master/packages/default-components",
101
+ "bugs": {
102
+ "url": "https://github.com/pie-framework/pie-qti/issues"
103
+ },
104
+ "publishConfig": {
105
+ "access": "public"
106
+ },
107
+ "sideEffects": false,
108
+ "engines": {
109
+ "node": ">=20.19.0"
110
+ },
111
+ "files": [
112
+ "dist",
113
+ "src"
114
+ ]
93
115
  }
@@ -37,29 +37,44 @@
37
37
  // Track cleanup functions for event listeners to prevent memory leaks
38
38
  let cleanupFunctions: (() => void)[] = [];
39
39
 
40
- function handleGapChange(gapId: string, wordId: string) {
41
- // Remove any existing pair for this gap
42
- const newPairs = pairs.filter((p: string) => !p.endsWith(` ${gapId}`));
40
+ function getMatchMax(wordId: string): number {
41
+ const gt = parsedInteraction?.gapTexts?.find((g) => g.identifier === wordId);
42
+ return gt?.matchMax ?? 1;
43
+ }
43
44
 
44
- // If this word is already used in another gap, move it (remove its previous assignment).
45
- const withoutWord = newPairs.filter((p: string) => !p.startsWith(`${wordId} `));
45
+ function handleGapChange(gapId: string, wordId: string) {
46
+ // Remove any existing pair for this gap (each gap holds one word)
47
+ let newPairs = pairs.filter((p: string) => !p.endsWith(` ${gapId}`));
48
+
49
+ // For reusable words (matchMax=0 or >1): don't remove other placements. For matchMax=1: move the word.
50
+ const matchMax = getMatchMax(wordId);
51
+ const currentCount = newPairs.filter((p: string) => p.startsWith(`${wordId} `)).length;
52
+ if (matchMax === 1 || (matchMax > 0 && currentCount >= matchMax)) {
53
+ // Single-use or at limit: remove this word from other gaps (move)
54
+ newPairs = newPairs.filter((p: string) => !p.startsWith(`${wordId} `));
55
+ }
46
56
 
47
57
  // Add new pair if a word was selected
48
58
  if (wordId) {
49
- withoutWord.push(`${wordId} ${gapId}`);
59
+ const newPair = `${wordId} ${gapId}`;
60
+ if (!newPairs.includes(newPair)) {
61
+ newPairs.push(newPair);
62
+ }
50
63
  }
51
64
 
52
- response = withoutWord;
65
+ response = newPairs;
53
66
  // Call onChange callback if provided (for Svelte component usage)
54
- onChange?.(withoutWord);
67
+ onChange?.(newPairs);
55
68
  // Dispatch event for web component usage - event will bubble up to the host element
56
69
  if (rootElement) {
57
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, withoutWord));
70
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
58
71
  }
59
72
  }
60
73
 
61
74
  function isWordUsed(wordId: string): boolean {
62
- return pairs.some((p: string) => p.startsWith(wordId));
75
+ const matchMax = getMatchMax(wordId);
76
+ const count = pairs.filter((p: string) => p.startsWith(`${wordId} `)).length;
77
+ return matchMax > 0 ? count >= matchMax : false; // matchMax=0 means unlimited, never "used"
63
78
  }
64
79
 
65
80
  function getSelectedWord(gapId: string): string {
@@ -40,9 +40,19 @@ let hoveredHotspotId = $state<string | null>(null);
40
40
  let keyboardSelectedTextId = $state<string | null>(null); // Gap text selected via keyboard
41
41
  let announceText = $state<string>(''); // For screen reader announcements
42
42
 
43
+ // Get reference to the root element for event dispatching (needed for Shadow DOM)
44
+ let rootElement: HTMLDivElement | undefined = $state();
45
+
46
+ // Track if we're updating from internal change (user drag) vs external (prop update)
47
+ let isInternalUpdate = false;
48
+
43
49
  $effect(() => {
44
- // Sync with parent response changes
45
- pairs = Array.isArray(parsedResponse) ? [...parsedResponse] : [];
50
+ // Sync with parent response changes (only if not an internal update)
51
+ if (!isInternalUpdate) {
52
+ const newPairs = Array.isArray(parsedResponse) ? [...parsedResponse] : [];
53
+ pairs = newPairs;
54
+ }
55
+ isInternalUpdate = false; // Reset flag
46
56
  });
47
57
 
48
58
  // Get the hotspot matched to a gap text
@@ -100,7 +110,7 @@ function handleHotspotDragLeave() {
100
110
  }
101
111
 
102
112
  function handleHotspotDrop(event: DragEvent, hotspotId: string) {
103
- if (disabled || !draggedTextId) return;
113
+ if (disabled || !draggedTextId || !parsedInteraction) return;
104
114
  event.preventDefault();
105
115
 
106
116
  // Remove any existing pair for this gapText
@@ -112,21 +122,16 @@ function handleHotspotDrop(event: DragEvent, hotspotId: string) {
112
122
  // Add new pair
113
123
  newPairs.push(`${draggedTextId} ${hotspotId}`);
114
124
 
125
+ isInternalUpdate = true; // Mark as internal update to prevent sync effect from overwriting
115
126
  pairs = newPairs;
116
127
  response = pairs;
117
128
  // Call onChange callback if provided (for Svelte component usage)
118
129
  onChange?.(pairs);
119
- // Dispatch custom event for web component usage
120
- const event2 = new CustomEvent('qti-change', {
121
- detail: {
122
- responseId: parsedInteraction?.responseId,
123
- value: pairs,
124
- timestamp: Date.now(),
125
- },
126
- bubbles: true,
127
- composed: true,
128
- });
129
- dispatchEvent(event2);
130
+ // Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
131
+ const valueArray = Array.isArray(pairs) ? [...pairs] : [];
132
+ if (rootElement) {
133
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
134
+ }
130
135
 
131
136
  draggedTextId = null;
132
137
  hoveredHotspotId = null;
@@ -138,21 +143,16 @@ function clearMatch(gapTextId: string) {
138
143
  const gapTextName = gapTextObj?.text || 'Label';
139
144
 
140
145
  const newPairs = pairs.filter((p) => !p.startsWith(`${gapTextId} `));
146
+ isInternalUpdate = true; // Mark as internal update
141
147
  pairs = newPairs;
142
148
  response = pairs;
143
149
  // Call onChange callback if provided (for Svelte component usage)
144
150
  onChange?.(pairs);
145
- // Dispatch custom event for web component usage
146
- const event = new CustomEvent('qti-change', {
147
- detail: {
148
- responseId: parsedInteraction?.responseId,
149
- value: pairs,
150
- timestamp: Date.now(),
151
- },
152
- bubbles: true,
153
- composed: true,
154
- });
155
- dispatchEvent(event);
151
+ // Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
152
+ const valueArray = Array.isArray(pairs) ? [...pairs] : [];
153
+ if (rootElement) {
154
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
155
+ }
156
156
 
157
157
  announceText = `${gapTextName} removed from hotspot`;
158
158
  }
@@ -213,21 +213,16 @@ function placeSelectedLabelOnHotspot(hotspotId: string) {
213
213
  newPairs = newPairs.filter((p) => !p.endsWith(` ${hotspotId}`));
214
214
  newPairs.push(`${keyboardSelectedTextId} ${hotspotId}`);
215
215
 
216
+ isInternalUpdate = true; // Mark as internal update
216
217
  pairs = newPairs;
217
218
  response = pairs;
218
219
  // Call onChange callback if provided (for Svelte component usage)
219
220
  onChange?.(pairs);
220
- // Dispatch custom event for web component usage
221
- const event2 = new CustomEvent('qti-change', {
222
- detail: {
223
- responseId: parsedInteraction?.responseId,
224
- value: pairs,
225
- timestamp: Date.now(),
226
- },
227
- bubbles: true,
228
- composed: true,
229
- });
230
- dispatchEvent(event2);
221
+ // Dispatch custom event for web component usage - dispatch from rootElement to ensure it bubbles out of Shadow DOM
222
+ const valueArray = Array.isArray(pairs) ? [...pairs] : [];
223
+ if (rootElement) {
224
+ rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, valueArray));
225
+ }
231
226
 
232
227
  announceText = `${gapTextName} placed on hotspot ${hotspotIndex + 1}`;
233
228
  keyboardSelectedTextId = null;
@@ -260,7 +255,7 @@ function parseCoords(hotspot: { identifier: string; shape: string; coords: strin
260
255
 
261
256
  <ShadowBaseStyles />
262
257
 
263
- <div class="qti-graphic-gap-match-interaction">
258
+ <div bind:this={rootElement} class="qti-graphic-gap-match-interaction">
264
259
  {#if !parsedInteraction}
265
260
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
266
261
  {:else}
@@ -218,7 +218,7 @@
218
218
  <div part="footer" class="qti-hottext-footer flex items-center justify-between text-sm text-base-content/70">
219
219
  <div>
220
220
  <span class="font-medium">Selected:</span>
221
- <span class="ml-2">{selectedIds.length} / {parsedInteraction.maxChoices}</span>
221
+ <span class="ml-2">{selectedIds.length} / {parsedInteraction.hottextChoices.length}</span>
222
222
  </div>
223
223
 
224
224
  {#if selectedIds.length > 0}
@@ -154,10 +154,10 @@
154
154
  </div>
155
155
  {/if}
156
156
 
157
- {#if parsedInteraction.maxPlays > 0}
157
+ {#if parsedInteraction.minPlays > 0 && !hasMetMinPlays}
158
158
  <div>
159
159
  <span class="font-medium">Remaining:</span>
160
- <span class="ml-2">{Math.max(0, parsedInteraction.maxPlays - playCount)}</span>
160
+ <span class="ml-2">{Math.max(0, parsedInteraction.minPlays - playCount)}</span>
161
161
  </div>
162
162
  {/if}
163
163
  </div>
@@ -234,12 +234,6 @@
234
234
  // QTI baseType="point" expects array of strings like ["158 168", "250 200"]
235
235
  const responseValue = positions.map(pos => `${Math.round(pos.x)} ${Math.round(pos.y)}`);
236
236
 
237
- console.log('[PositionObject] Emitting response:', {
238
- responseId: parsedInteraction?.responseId,
239
- value: responseValue,
240
- positions: positions
241
- });
242
-
243
237
  response = responseValue;
244
238
  // Call onChange callback if provided (for Svelte component usage)
245
239
  onChange?.(responseValue);
@@ -92,20 +92,6 @@
92
92
  : []
93
93
  );
94
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
95
  $effect(() => {
110
96
  // Sync with parent response changes
111
97
  const r = parsedResponse;
@@ -139,8 +139,18 @@
139
139
  }
140
140
 
141
141
  function commitValue() {
142
- if (!canvasEl) return;
142
+ if (!canvasEl || !ctx) return;
143
143
  const dataUrl = canvasEl.toDataURL('image/png');
144
+
145
+ // Extract ImageData synchronously from canvas and include it in the response
146
+ // This allows custom operators to analyze drawing content without async image loading
147
+ let canvasImageData: globalThis.ImageData | undefined;
148
+ try {
149
+ canvasImageData = ctx.getImageData(0, 0, canvasEl.width, canvasEl.height);
150
+ } catch (e) {
151
+ console.warn('[DrawingCanvas] Failed to extract image data:', e);
152
+ }
153
+
144
154
  const size = dataUrlSize(dataUrl);
145
155
  const response: QTIFileResponse = {
146
156
  name: `drawing-${responseId}.png`,
@@ -148,6 +158,12 @@
148
158
  size,
149
159
  lastModified: Date.now(),
150
160
  dataUrl,
161
+ // Include ImageData if available (for drawing analysis in custom operators)
162
+ imageData: canvasImageData ? {
163
+ data: canvasImageData.data,
164
+ width: canvasImageData.width,
165
+ height: canvasImageData.height,
166
+ } : undefined,
151
167
  };
152
168
  onChange(response);
153
169
  announceText = translations.updated;
@@ -7,7 +7,7 @@
7
7
 
8
8
  import type { AssociableChoice } from '@pie-qti/item-player';
9
9
  import type { I18nProvider } from '@pie-qti/i18n';
10
- import { createOrUpdatePair, getSourceForTarget, getTargetForSource, removePairBySource } from '../utils/pairHelpers.js';
10
+ import { createOrUpdatePair, getSourceForTarget, getTargetsForSource, removePairBySource } from '../utils/pairHelpers.js';
11
11
  import { touchDrag } from '../utils/touchDragHelper.js';
12
12
  import DragHandle from './DragHandle.svelte';
13
13
  import '../styles/shared.css';
@@ -136,63 +136,64 @@ function clearMatch(sourceId: string) {
136
136
  {i18n?.t('interactions.match.dragFromHere') ?? 'Drag from here:'}
137
137
  </h3>
138
138
  {#each sourceSet as source (source.identifier)}
139
- {@const matchedTarget = getTargetForSource(pairs, source.identifier)}
140
- {@const targetItem = matchedTarget ? targetSet.find((t) => t.identifier === matchedTarget) : null}
139
+ {@const matchedTargets = getTargetsForSource(pairs, source.identifier)}
140
+ {@const targetItems = matchedTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
141
141
  {@const isSelected = keyboardSelectedSourceId === source.identifier}
142
- {@const correctTarget = getTargetForSource(correctPairs, source.identifier)}
143
- {@const isCorrect = correctTarget !== null}
142
+ {@const correctTargets = getTargetsForSource(correctPairs, source.identifier)}
143
+ {@const isCorrect = correctTargets.length > 0}
144
+ {@const canDragMore = matchedTargets.length < (source.matchMax ?? 1)}
144
145
 
145
146
  <div class="qti-match-source-wrapper relative">
146
147
  <button
147
148
  type="button"
148
- draggable={!disabled && !matchedTarget}
149
+ draggable={!disabled && canDragMore}
149
150
  use:touchDrag
150
151
  ondragstart={() => handleDragStart(source.identifier)}
151
152
  ondragend={handleDragEnd}
152
153
  onkeydown={(e) => handleSourceKeyDown(e, source.identifier)}
153
154
  disabled={disabled}
154
- aria-label="{source.text}{matchedTarget && targetItem ? '. Matched with ' + targetItem.text : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
155
+ aria-label="{source.text}{targetItems.length ? '. Matched with ' + targetItems.map((t) => t?.text).join(', ') : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
155
156
  aria-pressed={isSelected}
156
- data-matched={!!matchedTarget}
157
+ data-matched={matchedTargets.length > 0}
157
158
  data-selected={isSelected}
158
159
  data-correct={isCorrect}
159
160
  data-dragging={draggedSourceId === source.identifier}
160
161
  part="source-item"
161
162
  class="qti-match-source p-3 rounded-lg border-2 transition-all w-full"
162
- class:bg-base-200={!matchedTarget && !isSelected && !isCorrect}
163
- class:bg-success={matchedTarget || isCorrect}
163
+ class:bg-base-200={matchedTargets.length === 0 && !isSelected && !isCorrect}
164
+ class:bg-success={matchedTargets.length > 0 || isCorrect}
164
165
  class:bg-primary={isSelected}
165
- class:bg-opacity-20={matchedTarget || isSelected || isCorrect}
166
- class:border-base-300={!matchedTarget && !isSelected && !isCorrect}
167
- class:border-success={matchedTarget || isCorrect}
166
+ class:bg-opacity-20={matchedTargets.length > 0 || isSelected || isCorrect}
167
+ class:border-base-300={matchedTargets.length === 0 && !isSelected && !isCorrect}
168
+ class:border-success={matchedTargets.length > 0 || isCorrect}
168
169
  class:border-primary={isSelected}
169
170
  class:ring-2={isSelected}
170
171
  class:ring-primary={isSelected}
171
- class:cursor-grab={!disabled && !matchedTarget && !isSelected}
172
+ class:cursor-grab={!disabled && canDragMore && !isSelected}
172
173
  class:cursor-not-allowed={disabled}
173
174
  class:opacity-50={disabled || draggedSourceId === source.identifier}
174
175
  >
175
176
  <div class="qti-match-source-content flex items-center justify-between gap-2">
176
177
  <div class="qti-match-source-text flex-1">
177
178
  <div class="qti-match-source-title font-medium">{source.text}</div>
178
- {#if matchedTarget && targetItem}
179
- <div class="qti-match-source-sub text-sm text-success mt-1">→ {targetItem.text}</div>
180
- {:else if isCorrect && correctTarget}
181
- {@const correctTargetItem = targetSet.find((t) => t.identifier === correctTarget)}
182
- {#if correctTargetItem}
183
- <div class="qti-match-source-sub text-sm text-success mt-1">→ {correctTargetItem.text}</div>
179
+ {#if targetItems.length > 0}
180
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {targetItems.map((t) => t?.text).join(', ')}</div>
181
+ {:else if isCorrect && correctTargets.length > 0}
182
+ {@const correctTargetItems = correctTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
183
+ {#if correctTargetItems.length > 0}
184
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {correctTargetItems.map((t) => t?.text).join(', ')}</div>
184
185
  {/if}
185
186
  {/if}
186
- {#if isCorrect && !matchedTarget}
187
+ {#if isCorrect && matchedTargets.length === 0}
187
188
  <span class="badge badge-success badge-sm ml-2">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
188
189
  {/if}
189
190
  </div>
190
- {#if !disabled && !matchedTarget}
191
+ {#if !disabled && canDragMore}
191
192
  <DragHandle size={1.25} opacity={0.3} class="text-base-content" />
192
193
  {/if}
193
194
  </div>
194
195
  </button>
195
- {#if matchedTarget && !disabled}
196
+ {#if matchedTargets.length > 0 && !disabled}
196
197
  <button
197
198
  type="button"
198
199
  part="source-clear"
@@ -11,8 +11,7 @@
11
11
  -->
12
12
 
13
13
  <style>
14
- /* Import KaTeX CSS for math rendering in Shadow DOM */
15
- @import url('https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.css');
14
+ /* KaTeX CSS is provided by host app bundles (avoid runtime @import 404s in nested routes). */
16
15
  /* Buttons */
17
16
  :global(.btn) {
18
17
  display: inline-flex;
@@ -10,6 +10,8 @@
10
10
  */
11
11
 
12
12
  import type { MathfieldElement } from 'mathlive';
13
+ // Import MathLive CSS from the local package
14
+ import 'mathlive/static.css';
13
15
 
14
16
  // Dynamically import MathLive to register the custom element
15
17
  let mathLiveLoaded: Promise<void> | null = null;
@@ -18,15 +20,8 @@ async function ensureMathLiveLoaded(): Promise<void> {
18
20
  if (!mathLiveLoaded && typeof window !== 'undefined') {
19
21
  mathLiveLoaded = (async () => {
20
22
  // Import MathLive to register the <math-field> custom element
23
+ // CSS is already imported at the top of this file
21
24
  await import('mathlive');
22
-
23
- // Load MathLive CSS if not already loaded
24
- if (!document.querySelector('link[href*="mathlive"]')) {
25
- const link = document.createElement('link');
26
- link.rel = 'stylesheet';
27
- link.href = 'https://cdn.jsdelivr.net/npm/mathlive@0.108.2/dist/mathlive-static.css';
28
- document.head.appendChild(link);
29
- }
30
25
  })();
31
26
  }
32
27
  return mathLiveLoaded || Promise.resolve();