@pie-qti/default-components 0.1.1 → 0.1.5

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 (61) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -1
  4. package/dist/plugins/index.d.ts +1 -0
  5. package/dist/plugins/index.d.ts.map +1 -1
  6. package/dist/plugins/index.js +1 -0
  7. package/dist/shared/extensions/MathLiveEditor.d.ts +1 -0
  8. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
  9. package/dist/shared/extensions/MathLiveEditor.js +3 -7
  10. package/dist/shared/utils/eventHelpers.d.ts +3 -11
  11. package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
  12. package/dist/shared/utils/eventHelpers.js +7 -1
  13. package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
  14. package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
  15. package/dist/shared/utils/matchGroupUtils.js +13 -0
  16. package/dist/shared/utils/pairHelpers.d.ts +15 -2
  17. package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
  18. package/dist/shared/utils/pairHelpers.js +30 -8
  19. package/dist/shared/utils/touchDragHelper.d.ts +1 -32
  20. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
  21. package/dist/shared/utils/touchDragHelper.js +1 -168
  22. package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
  23. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
  24. package/dist/shared/utils/webComponentHelpers.js +3 -3
  25. package/package.json +117 -91
  26. package/src/catalog/CatalogPopup.svelte +162 -0
  27. package/src/index.ts +10 -1
  28. package/src/plugins/associate/AssociateInteraction.svelte +18 -1
  29. package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
  30. package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
  31. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
  32. package/src/plugins/gap-match/GapMatchInteraction.svelte +199 -22
  33. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
  34. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +230 -145
  35. package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
  36. package/src/plugins/hottext/HottextInteraction.svelte +33 -4
  37. package/src/plugins/index.ts +1 -0
  38. package/src/plugins/match/MatchInteraction.svelte +13 -1
  39. package/src/plugins/media/MediaInteraction.svelte +2 -2
  40. package/src/plugins/order/OrderInteraction.svelte +132 -11
  41. package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -15
  42. package/src/plugins/select-point/SelectPointInteraction.svelte +139 -21
  43. package/src/shared/components/DrawingCanvas.svelte +17 -1
  44. package/src/shared/components/GraphicGapMatch.svelte +5 -3
  45. package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
  46. package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
  47. package/src/shared/components/MatchDragDrop.svelte +72 -25
  48. package/src/shared/components/ShadowBaseStyles.svelte +1 -2
  49. package/src/shared/extensions/MathLiveEditor.ts +3 -8
  50. package/src/shared/styles/qti-shared-vocabulary.css +320 -0
  51. package/src/shared/utils/eventHelpers.ts +12 -3
  52. package/src/shared/utils/matchGroupUtils.ts +14 -0
  53. package/src/shared/utils/pairHelpers.ts +32 -9
  54. package/src/shared/utils/touchDragHelper.ts +1 -211
  55. package/src/shared/utils/webComponentHelpers.ts +5 -5
  56. package/.turbo/turbo-build.log +0 -1
  57. package/CHANGELOG.md +0 -9
  58. package/STYLING.md +0 -226
  59. package/svelte.config.js +0 -9
  60. package/tests/index.test.ts +0 -8
  61. package/tsconfig.json +0 -20
@@ -7,8 +7,9 @@
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
+ import { isCompatibleMatchGroup } from '../utils/matchGroupUtils.js';
12
13
  import DragHandle from './DragHandle.svelte';
13
14
  import '../styles/shared.css';
14
15
 
@@ -16,13 +17,29 @@ interface Props {
16
17
  sourceSet: AssociableChoice[];
17
18
  targetSet: AssociableChoice[];
18
19
  pairs: string[]; // Array of "sourceId targetId" pairs
20
+ maxAssociations?: number; // 0 = unlimited per QTI spec
19
21
  correctPairs?: string[]; // Array of correct "sourceId targetId" pairs
20
22
  disabled?: boolean;
21
23
  i18n?: I18nProvider;
22
24
  onPairsChange: (newPairs: string[]) => void;
23
25
  }
24
26
 
25
- const { sourceSet, targetSet, pairs, correctPairs = [], disabled = false, i18n, onPairsChange }: Props = $props();
27
+ const { sourceSet, targetSet, pairs, maxAssociations = 0, correctPairs = [], disabled = false, i18n, onPairsChange }: Props = $props();
28
+
29
+ // maxAssociations=0 means unlimited; otherwise cap total pairs
30
+ const canAddMorePairs = $derived(maxAssociations === 0 || pairs.length < maxAssociations);
31
+
32
+ // Targets incompatible with the active source due to matchGroup constraints
33
+ const blockedTargetIds = $derived.by(() => {
34
+ const activeSourceId = draggedSourceId ?? keyboardSelectedSourceId;
35
+ if (!activeSourceId) return new Set<string>();
36
+ const src = sourceSet.find((s) => s.identifier === activeSourceId);
37
+ return new Set(
38
+ targetSet
39
+ .filter((t) => !isCompatibleMatchGroup(src?.matchGroup, t.matchGroup))
40
+ .map((t) => t.identifier)
41
+ );
42
+ });
26
43
 
27
44
  let draggedSourceId = $state<string | null>(null);
28
45
  let keyboardSelectedSourceId = $state<string | null>(null); // Source selected via keyboard
@@ -43,6 +60,18 @@ function handleDrop(event: DragEvent, targetId: string) {
43
60
  if (disabled || !draggedSourceId) return;
44
61
  event.preventDefault();
45
62
 
63
+ if (blockedTargetIds.has(targetId)) {
64
+ draggedSourceId = null;
65
+ return;
66
+ }
67
+
68
+ // Allow replacing an existing pair for this source, but block new pairs when at limit
69
+ const existingPair = pairs.find((p) => p.startsWith(draggedSourceId + ' '));
70
+ if (!existingPair && !canAddMorePairs) {
71
+ draggedSourceId = null;
72
+ return;
73
+ }
74
+
46
75
  createMatch(draggedSourceId, targetId);
47
76
  draggedSourceId = null;
48
77
  }
@@ -87,9 +116,22 @@ function handleTargetKeyDown(event: KeyboardEvent, targetId: string) {
87
116
  if ((event.key === ' ' || event.key === 'Enter') && keyboardSelectedSourceId) {
88
117
  event.preventDefault();
89
118
 
119
+ if (blockedTargetIds.has(targetId)) {
120
+ announceText = `This target cannot be matched with the selected source.`;
121
+ return;
122
+ }
123
+
90
124
  const source = sourceSet.find((s) => s.identifier === keyboardSelectedSourceId);
91
125
  const sourceName = source?.text || 'Item';
92
126
 
127
+ // Allow replacing an existing pair for this source, but block new pairs when at limit
128
+ const existingPair = pairs.find((p) => p.startsWith(keyboardSelectedSourceId + ' '));
129
+ if (!existingPair && !canAddMorePairs) {
130
+ announceText = `Maximum associations reached. Remove a pair to add a new one.`;
131
+ keyboardSelectedSourceId = null;
132
+ return;
133
+ }
134
+
93
135
  createMatch(keyboardSelectedSourceId, targetId);
94
136
  announceText = `${sourceName} matched with ${targetName}`;
95
137
  keyboardSelectedSourceId = null;
@@ -136,63 +178,64 @@ function clearMatch(sourceId: string) {
136
178
  {i18n?.t('interactions.match.dragFromHere') ?? 'Drag from here:'}
137
179
  </h3>
138
180
  {#each sourceSet as source (source.identifier)}
139
- {@const matchedTarget = getTargetForSource(pairs, source.identifier)}
140
- {@const targetItem = matchedTarget ? targetSet.find((t) => t.identifier === matchedTarget) : null}
181
+ {@const matchedTargets = getTargetsForSource(pairs, source.identifier)}
182
+ {@const targetItems = matchedTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
141
183
  {@const isSelected = keyboardSelectedSourceId === source.identifier}
142
- {@const correctTarget = getTargetForSource(correctPairs, source.identifier)}
143
- {@const isCorrect = correctTarget !== null}
184
+ {@const correctTargets = getTargetsForSource(correctPairs, source.identifier)}
185
+ {@const isCorrect = correctTargets.length > 0}
186
+ {@const canDragMore = matchedTargets.length < (source.matchMax ?? 1)}
144
187
 
145
188
  <div class="qti-match-source-wrapper relative">
146
189
  <button
147
190
  type="button"
148
- draggable={!disabled && !matchedTarget}
191
+ draggable={!disabled && canDragMore}
149
192
  use:touchDrag
150
193
  ondragstart={() => handleDragStart(source.identifier)}
151
194
  ondragend={handleDragEnd}
152
195
  onkeydown={(e) => handleSourceKeyDown(e, source.identifier)}
153
196
  disabled={disabled}
154
- aria-label="{source.text}{matchedTarget && targetItem ? '. Matched with ' + targetItem.text : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
197
+ aria-label="{source.text}{targetItems.length ? '. Matched with ' + targetItems.map((t) => t?.text).join(', ') : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
155
198
  aria-pressed={isSelected}
156
- data-matched={!!matchedTarget}
199
+ data-matched={matchedTargets.length > 0}
157
200
  data-selected={isSelected}
158
201
  data-correct={isCorrect}
159
202
  data-dragging={draggedSourceId === source.identifier}
160
203
  part="source-item"
161
204
  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}
205
+ class:bg-base-200={matchedTargets.length === 0 && !isSelected && !isCorrect}
206
+ class:bg-success={matchedTargets.length > 0 || isCorrect}
164
207
  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}
208
+ class:bg-opacity-20={matchedTargets.length > 0 || isSelected || isCorrect}
209
+ class:border-base-300={matchedTargets.length === 0 && !isSelected && !isCorrect}
210
+ class:border-success={matchedTargets.length > 0 || isCorrect}
168
211
  class:border-primary={isSelected}
169
212
  class:ring-2={isSelected}
170
213
  class:ring-primary={isSelected}
171
- class:cursor-grab={!disabled && !matchedTarget && !isSelected}
214
+ class:cursor-grab={!disabled && canDragMore && !isSelected}
172
215
  class:cursor-not-allowed={disabled}
173
216
  class:opacity-50={disabled || draggedSourceId === source.identifier}
174
217
  >
175
218
  <div class="qti-match-source-content flex items-center justify-between gap-2">
176
219
  <div class="qti-match-source-text flex-1">
177
220
  <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>
221
+ {#if targetItems.length > 0}
222
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {targetItems.map((t) => t?.text).join(', ')}</div>
223
+ {:else if isCorrect && correctTargets.length > 0}
224
+ {@const correctTargetItems = correctTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
225
+ {#if correctTargetItems.length > 0}
226
+ <div class="qti-match-source-sub text-sm text-success mt-1">→ {correctTargetItems.map((t) => t?.text).join(', ')}</div>
184
227
  {/if}
185
228
  {/if}
186
- {#if isCorrect && !matchedTarget}
229
+ {#if isCorrect && matchedTargets.length === 0}
187
230
  <span class="badge badge-success badge-sm ml-2">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
188
231
  {/if}
189
232
  </div>
190
- {#if !disabled && !matchedTarget}
233
+ {#if !disabled && canDragMore}
191
234
  <DragHandle size={1.25} opacity={0.3} class="text-base-content" />
192
235
  {/if}
193
236
  </div>
194
237
  </button>
195
- {#if matchedTarget && !disabled}
238
+ {#if matchedTargets.length > 0 && !disabled}
196
239
  <button
197
240
  type="button"
198
241
  part="source-clear"
@@ -218,6 +261,7 @@ function clearMatch(sourceId: string) {
218
261
  {@const isHighlight = (draggedSourceId && !matchedSource) || (keyboardSelectedSourceId && !matchedSource)}
219
262
  {@const correctSource = getSourceForTarget(correctPairs, target.identifier)}
220
263
  {@const isCorrect = correctSource !== null}
264
+ {@const isBlocked = blockedTargetIds.has(target.identifier)}
221
265
 
222
266
  <button
223
267
  type="button"
@@ -225,7 +269,8 @@ function clearMatch(sourceId: string) {
225
269
  ondrop={(e) => handleDrop(e, target.identifier)}
226
270
  onkeydown={(e) => handleTargetKeyDown(e, target.identifier)}
227
271
  disabled={disabled || !keyboardSelectedSourceId}
228
- aria-label="{target.text}{matchedSource && sourceItem ? '. Matched with ' + sourceItem.text : '. Available for matching'}{isCorrect ? '. Correct answer' : ''}"
272
+ aria-disabled={isBlocked ? 'true' : undefined}
273
+ aria-label="{target.text}{matchedSource && sourceItem ? '. Matched with ' + sourceItem.text : '. Available for matching'}{isCorrect ? '. Correct answer' : ''}{isBlocked ? '. Not compatible with selected source' : ''}"
229
274
  data-matched={!!matchedSource}
230
275
  data-highlight={isHighlight}
231
276
  data-correct={isCorrect}
@@ -242,6 +287,8 @@ function clearMatch(sourceId: string) {
242
287
  class:border-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
243
288
  class:bg-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
244
289
  class:bg-opacity-5={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
290
+ class:opacity-40={isBlocked}
291
+ class:cursor-not-allowed={isBlocked}
245
292
  >
246
293
  <div class="qti-match-target-content flex flex-col gap-1">
247
294
  <div class="qti-match-target-title font-medium text-base-content/70">{target.text}</div>
@@ -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();
@@ -0,0 +1,320 @@
1
+ /**
2
+ * QTI 3.0 Shared Vocabulary CSS Classes
3
+ *
4
+ * Implementation of the 1EdTech QTI 3.0 Standardized Shared Vocabulary and CSS Classes.
5
+ * Reference: https://www.imsglobal.org/spec/qti/v3p0/vocab
6
+ *
7
+ * These classes are applied by item authors to elements within qti-item-body.
8
+ * The sanitizer passes class attributes through unchanged, so no code changes
9
+ * are needed — this stylesheet alone provides the required visual behavior.
10
+ */
11
+
12
+ /* =============================================================================
13
+ Text Formatting
14
+ ============================================================================= */
15
+
16
+ .qti-underline {
17
+ text-decoration: underline;
18
+ }
19
+
20
+ .qti-italic {
21
+ font-style: italic;
22
+ }
23
+
24
+ .qti-bordered {
25
+ border: 1px solid currentColor;
26
+ padding: 0.25em 0.5em;
27
+ }
28
+
29
+ /* =============================================================================
30
+ Text Alignment
31
+ ============================================================================= */
32
+
33
+ .qti-align-left {
34
+ text-align: left;
35
+ }
36
+
37
+ .qti-align-center {
38
+ text-align: center;
39
+ }
40
+
41
+ .qti-align-right {
42
+ text-align: right;
43
+ }
44
+
45
+ /* =============================================================================
46
+ Vertical Alignment
47
+ ============================================================================= */
48
+
49
+ .qti-valign-top {
50
+ vertical-align: top;
51
+ }
52
+
53
+ .qti-valign-middle {
54
+ vertical-align: middle;
55
+ }
56
+
57
+ .qti-valign-baseline {
58
+ vertical-align: baseline;
59
+ }
60
+
61
+ .qti-valign-bottom {
62
+ vertical-align: bottom;
63
+ }
64
+
65
+ /* =============================================================================
66
+ Well (boxed content)
67
+ ============================================================================= */
68
+
69
+ .qti-well {
70
+ padding: 1em;
71
+ border: 1px solid #ccc;
72
+ border-radius: 4px;
73
+ background-color: #f9f9f9;
74
+ }
75
+
76
+ /* =============================================================================
77
+ Layout Grid (12-column flex grid)
78
+ ============================================================================= */
79
+
80
+ .qti-layout-row {
81
+ display: flex;
82
+ flex-wrap: wrap;
83
+ margin-left: -0.5rem;
84
+ margin-right: -0.5rem;
85
+ }
86
+
87
+ .qti-layout-row > * {
88
+ padding-left: 0.5rem;
89
+ padding-right: 0.5rem;
90
+ box-sizing: border-box;
91
+ }
92
+
93
+ .qti-layout-col1 { width: 8.3333%; }
94
+ .qti-layout-col2 { width: 16.6667%; }
95
+ .qti-layout-col3 { width: 25%; }
96
+ .qti-layout-col4 { width: 33.3333%; }
97
+ .qti-layout-col5 { width: 41.6667%; }
98
+ .qti-layout-col6 { width: 50%; }
99
+ .qti-layout-col7 { width: 58.3333%; }
100
+ .qti-layout-col8 { width: 66.6667%; }
101
+ .qti-layout-col9 { width: 75%; }
102
+ .qti-layout-col10 { width: 83.3333%; }
103
+ .qti-layout-col11 { width: 91.6667%; }
104
+ .qti-layout-col12 { width: 100%; }
105
+
106
+ .qti-layout-offset1 { margin-left: 8.3333%; }
107
+ .qti-layout-offset2 { margin-left: 16.6667%; }
108
+ .qti-layout-offset3 { margin-left: 25%; }
109
+ .qti-layout-offset4 { margin-left: 33.3333%; }
110
+ .qti-layout-offset5 { margin-left: 41.6667%; }
111
+ .qti-layout-offset6 { margin-left: 50%; }
112
+ .qti-layout-offset7 { margin-left: 58.3333%; }
113
+ .qti-layout-offset8 { margin-left: 66.6667%; }
114
+ .qti-layout-offset9 { margin-left: 75%; }
115
+ .qti-layout-offset10 { margin-left: 83.3333%; }
116
+ .qti-layout-offset11 { margin-left: 91.6667%; }
117
+
118
+ /* =============================================================================
119
+ Padding (0–5 scale; ~4px per unit)
120
+ ============================================================================= */
121
+
122
+ .qti-padding-0 { padding: 0; }
123
+ .qti-padding-1 { padding: 0.25rem; }
124
+ .qti-padding-2 { padding: 0.5rem; }
125
+ .qti-padding-3 { padding: 0.75rem; }
126
+ .qti-padding-4 { padding: 1rem; }
127
+ .qti-padding-5 { padding: 1.25rem; }
128
+
129
+ .qti-padding-x-0 { padding-left: 0; padding-right: 0; }
130
+ .qti-padding-x-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
131
+ .qti-padding-x-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
132
+ .qti-padding-x-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
133
+ .qti-padding-x-4 { padding-left: 1rem; padding-right: 1rem; }
134
+ .qti-padding-x-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
135
+
136
+ .qti-padding-y-0 { padding-top: 0; padding-bottom: 0; }
137
+ .qti-padding-y-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
138
+ .qti-padding-y-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
139
+ .qti-padding-y-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
140
+ .qti-padding-y-4 { padding-top: 1rem; padding-bottom: 1rem; }
141
+ .qti-padding-y-5 { padding-top: 1.25rem; padding-bottom: 1.25rem; }
142
+
143
+ .qti-padding-t-0 { padding-top: 0; }
144
+ .qti-padding-t-1 { padding-top: 0.25rem; }
145
+ .qti-padding-t-2 { padding-top: 0.5rem; }
146
+ .qti-padding-t-3 { padding-top: 0.75rem; }
147
+ .qti-padding-t-4 { padding-top: 1rem; }
148
+ .qti-padding-t-5 { padding-top: 1.25rem; }
149
+
150
+ .qti-padding-b-0 { padding-bottom: 0; }
151
+ .qti-padding-b-1 { padding-bottom: 0.25rem; }
152
+ .qti-padding-b-2 { padding-bottom: 0.5rem; }
153
+ .qti-padding-b-3 { padding-bottom: 0.75rem; }
154
+ .qti-padding-b-4 { padding-bottom: 1rem; }
155
+ .qti-padding-b-5 { padding-bottom: 1.25rem; }
156
+
157
+ /* qti-padding-s/e = logical inline-start/end (LTR = left/right) */
158
+ .qti-padding-s-0 { padding-inline-start: 0; }
159
+ .qti-padding-s-1 { padding-inline-start: 0.25rem; }
160
+ .qti-padding-s-2 { padding-inline-start: 0.5rem; }
161
+ .qti-padding-s-3 { padding-inline-start: 0.75rem; }
162
+ .qti-padding-s-4 { padding-inline-start: 1rem; }
163
+ .qti-padding-s-5 { padding-inline-start: 1.25rem; }
164
+
165
+ .qti-padding-e-0 { padding-inline-end: 0; }
166
+ .qti-padding-e-1 { padding-inline-end: 0.25rem; }
167
+ .qti-padding-e-2 { padding-inline-end: 0.5rem; }
168
+ .qti-padding-e-3 { padding-inline-end: 0.75rem; }
169
+ .qti-padding-e-4 { padding-inline-end: 1rem; }
170
+ .qti-padding-e-5 { padding-inline-end: 1.25rem; }
171
+
172
+ /* =============================================================================
173
+ Margin (0–5 scale + auto)
174
+ ============================================================================= */
175
+
176
+ .qti-margin-0 { margin: 0; }
177
+ .qti-margin-1 { margin: 0.25rem; }
178
+ .qti-margin-2 { margin: 0.5rem; }
179
+ .qti-margin-3 { margin: 0.75rem; }
180
+ .qti-margin-4 { margin: 1rem; }
181
+ .qti-margin-5 { margin: 1.25rem; }
182
+ .qti-margin-auto { margin: auto; }
183
+
184
+ .qti-margin-x-0 { margin-left: 0; margin-right: 0; }
185
+ .qti-margin-x-1 { margin-left: 0.25rem; margin-right: 0.25rem; }
186
+ .qti-margin-x-2 { margin-left: 0.5rem; margin-right: 0.5rem; }
187
+ .qti-margin-x-3 { margin-left: 0.75rem; margin-right: 0.75rem; }
188
+ .qti-margin-x-4 { margin-left: 1rem; margin-right: 1rem; }
189
+ .qti-margin-x-5 { margin-left: 1.25rem; margin-right: 1.25rem; }
190
+ .qti-margin-x-auto { margin-left: auto; margin-right: auto; }
191
+
192
+ .qti-margin-y-0 { margin-top: 0; margin-bottom: 0; }
193
+ .qti-margin-y-1 { margin-top: 0.25rem; margin-bottom: 0.25rem; }
194
+ .qti-margin-y-2 { margin-top: 0.5rem; margin-bottom: 0.5rem; }
195
+ .qti-margin-y-3 { margin-top: 0.75rem; margin-bottom: 0.75rem; }
196
+ .qti-margin-y-4 { margin-top: 1rem; margin-bottom: 1rem; }
197
+ .qti-margin-y-5 { margin-top: 1.25rem; margin-bottom: 1.25rem; }
198
+ .qti-margin-y-auto { margin-top: auto; margin-bottom: auto; }
199
+
200
+ .qti-margin-t-0 { margin-top: 0; }
201
+ .qti-margin-t-1 { margin-top: 0.25rem; }
202
+ .qti-margin-t-2 { margin-top: 0.5rem; }
203
+ .qti-margin-t-3 { margin-top: 0.75rem; }
204
+ .qti-margin-t-4 { margin-top: 1rem; }
205
+ .qti-margin-t-5 { margin-top: 1.25rem; }
206
+ .qti-margin-t-auto { margin-top: auto; }
207
+
208
+ .qti-margin-b-0 { margin-bottom: 0; }
209
+ .qti-margin-b-1 { margin-bottom: 0.25rem; }
210
+ .qti-margin-b-2 { margin-bottom: 0.5rem; }
211
+ .qti-margin-b-3 { margin-bottom: 0.75rem; }
212
+ .qti-margin-b-4 { margin-bottom: 1rem; }
213
+ .qti-margin-b-5 { margin-bottom: 1.25rem; }
214
+ .qti-margin-b-auto { margin-bottom: auto; }
215
+
216
+ .qti-margin-s-0 { margin-inline-start: 0; }
217
+ .qti-margin-s-1 { margin-inline-start: 0.25rem; }
218
+ .qti-margin-s-2 { margin-inline-start: 0.5rem; }
219
+ .qti-margin-s-3 { margin-inline-start: 0.75rem; }
220
+ .qti-margin-s-4 { margin-inline-start: 1rem; }
221
+ .qti-margin-s-5 { margin-inline-start: 1.25rem; }
222
+ .qti-margin-s-auto { margin-inline-start: auto; }
223
+
224
+ .qti-margin-e-0 { margin-inline-end: 0; }
225
+ .qti-margin-e-1 { margin-inline-end: 0.25rem; }
226
+ .qti-margin-e-2 { margin-inline-end: 0.5rem; }
227
+ .qti-margin-e-3 { margin-inline-end: 0.75rem; }
228
+ .qti-margin-e-4 { margin-inline-end: 1rem; }
229
+ .qti-margin-e-5 { margin-inline-end: 1.25rem; }
230
+ .qti-margin-e-auto { margin-inline-end: auto; }
231
+
232
+ /* =============================================================================
233
+ Display
234
+ ============================================================================= */
235
+
236
+ .qti-display-block { display: block; }
237
+ .qti-display-inherit { display: inherit; }
238
+ .qti-display-inline { display: inline; }
239
+ .qti-display-inline-block { display: inline-block; }
240
+ .qti-display-none { display: none; }
241
+ .qti-hidden { display: none; }
242
+ .qti-display-flex { display: flex; }
243
+ .qti-display-inline-flex { display: inline-flex; }
244
+ .qti-display-grid { display: grid; }
245
+ .qti-display-inline-grid { display: inline-grid; }
246
+ .qti-display-table { display: table; }
247
+ .qti-display-table-row { display: table-row; }
248
+ .qti-display-list-item { display: list-item; }
249
+
250
+ /* Visually hidden but available to screen readers */
251
+ .qti-visually-hidden {
252
+ position: absolute;
253
+ width: 1px;
254
+ height: 1px;
255
+ padding: 0;
256
+ margin: -1px;
257
+ overflow: hidden;
258
+ clip: rect(0, 0, 0, 0);
259
+ white-space: nowrap;
260
+ border: 0;
261
+ }
262
+
263
+ /* =============================================================================
264
+ Width (Tailwind-like numeric scale — rem-based)
265
+ ============================================================================= */
266
+
267
+ .qti-width-0 { width: 0; }
268
+ .qti-width-px { width: 1px; }
269
+ .qti-width-0p5 { width: 0.125rem; }
270
+ .qti-width-1 { width: 0.25rem; }
271
+ .qti-width-1p5 { width: 0.375rem; }
272
+ .qti-width-2 { width: 0.5rem; }
273
+ .qti-width-2p5 { width: 0.625rem; }
274
+ .qti-width-3 { width: 0.75rem; }
275
+ .qti-width-3p5 { width: 0.875rem; }
276
+ .qti-width-4 { width: 1rem; }
277
+ .qti-width-5 { width: 1.25rem; }
278
+ .qti-width-6 { width: 1.5rem; }
279
+ .qti-width-7 { width: 1.75rem; }
280
+ .qti-width-8 { width: 2rem; }
281
+ .qti-width-9 { width: 2.25rem; }
282
+ .qti-width-10 { width: 2.5rem; }
283
+ .qti-width-11 { width: 2.75rem; }
284
+ .qti-width-12 { width: 3rem; }
285
+ .qti-width-14 { width: 3.5rem; }
286
+ .qti-width-16 { width: 4rem; }
287
+ .qti-width-20 { width: 5rem; }
288
+ .qti-width-24 { width: 6rem; }
289
+ .qti-width-28 { width: 7rem; }
290
+ .qti-width-32 { width: 8rem; }
291
+ .qti-width-36 { width: 9rem; }
292
+ .qti-width-40 { width: 10rem; }
293
+ .qti-width-44 { width: 11rem; }
294
+ .qti-width-48 { width: 12rem; }
295
+ .qti-width-52 { width: 13rem; }
296
+ .qti-width-56 { width: 14rem; }
297
+ .qti-width-60 { width: 15rem; }
298
+ .qti-width-64 { width: 16rem; }
299
+ .qti-width-72 { width: 18rem; }
300
+ .qti-width-80 { width: 20rem; }
301
+ .qti-width-96 { width: 24rem; }
302
+
303
+ /* Fractional widths */
304
+ .qti-width-1-2 { width: 50%; }
305
+ .qti-width-1-3 { width: 33.3333%; }
306
+ .qti-width-2-3 { width: 66.6667%; }
307
+ .qti-width-1-4 { width: 25%; }
308
+ .qti-width-2-4 { width: 50%; }
309
+ .qti-width-3-4 { width: 75%; }
310
+ .qti-width-1-5 { width: 20%; }
311
+ .qti-width-2-5 { width: 40%; }
312
+ .qti-width-3-5 { width: 60%; }
313
+ .qti-width-4-5 { width: 80%; }
314
+ .qti-width-1-6 { width: 16.6667%; }
315
+ .qti-width-2-6 { width: 33.3333%; }
316
+ .qti-width-3-6 { width: 50%; }
317
+ .qti-width-4-6 { width: 66.6667%; }
318
+ .qti-width-5-6 { width: 83.3333%; }
319
+ .qti-width-full { width: 100%; }
320
+ .qti-width-auto { width: auto; }
@@ -1,3 +1,5 @@
1
+ import type { QTIChangeEventDetail } from '@pie-qti/item-player/web-components';
2
+
1
3
  /**
2
4
  * Event emission helpers for QTI components
3
5
  */
@@ -8,10 +10,17 @@
8
10
  * @param value - The response value
9
11
  * @returns A CustomEvent that can be dispatched
10
12
  */
11
- export function createQtiChangeEvent(responseId: string | undefined, value: any): CustomEvent {
13
+ function requireResponseId(responseId: string | undefined): string {
14
+ if (!responseId || responseId.trim().length === 0) {
15
+ throw new Error('qti-change event requires a non-empty responseId');
16
+ }
17
+ return responseId;
18
+ }
19
+
20
+ export function createQtiChangeEvent(responseId: string | undefined, value: unknown): CustomEvent<QTIChangeEventDetail> {
12
21
  return new CustomEvent('qti-change', {
13
22
  detail: {
14
- responseId,
23
+ responseId: requireResponseId(responseId),
15
24
  value,
16
25
  timestamp: Date.now(),
17
26
  },
@@ -29,7 +38,7 @@ export function createQtiChangeEvent(responseId: string | undefined, value: any)
29
38
  export function emitQtiChange(
30
39
  element: HTMLElement | EventTarget,
31
40
  responseId: string | undefined,
32
- value: any
41
+ value: unknown
33
42
  ): void {
34
43
  const event = createQtiChangeEvent(responseId, value);
35
44
  element.dispatchEvent(event);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns true if a source and target choice are compatible for pairing.
3
+ *
4
+ * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).
5
+ * Two non-empty matchGroups are compatible only if they share at least one value.
6
+ */
7
+ export function isCompatibleMatchGroup(
8
+ sourceGroups: string[] | undefined,
9
+ targetGroups: string[] | undefined
10
+ ): boolean {
11
+ if (!sourceGroups || sourceGroups.length === 0) return true;
12
+ if (!targetGroups || targetGroups.length === 0) return true;
13
+ return sourceGroups.some((g) => targetGroups.includes(g));
14
+ }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Gets the target ID matched with a source ID
7
+ * Gets the target ID matched with a source ID (first match only, for one-to-one display)
8
8
  * @param pairs - Array of "sourceId targetId" pair strings
9
9
  * @param sourceId - The source identifier to search for
10
10
  * @returns The matched target ID, or null if not found
@@ -14,6 +14,19 @@ export function getTargetForSource(pairs: string[], sourceId: string): string |
14
14
  return pair ? pair.split(' ')[1] : null;
15
15
  }
16
16
 
17
+ /**
18
+ * Gets all target IDs matched with a source ID (for many-to-many)
19
+ * @param pairs - Array of "sourceId targetId" pair strings
20
+ * @param sourceId - The source identifier to search for
21
+ * @returns Array of matched target IDs
22
+ */
23
+ export function getTargetsForSource(pairs: string[], sourceId: string): string[] {
24
+ return pairs
25
+ .filter((p) => p.startsWith(`${sourceId} `))
26
+ .map((p) => p.split(' ')[1])
27
+ .filter((t): t is string => !!t);
28
+ }
29
+
17
30
  /**
18
31
  * Gets the source ID matched with a target ID
19
32
  * @param pairs - Array of "sourceId targetId" pair strings
@@ -26,21 +39,24 @@ export function getSourceForTarget(pairs: string[], targetId: string): string |
26
39
  }
27
40
 
28
41
  /**
29
- * Creates or updates a pair, removing any existing pairs for the source or target
42
+ * Creates or updates a pair.
43
+ * - Removes any existing pair for the target (target receives at most one when matchMax=1)
44
+ * - Does NOT remove other pairs for the source (allows many-to-many: one source → multiple targets)
30
45
  * @param pairs - Array of existing pair strings
31
46
  * @param sourceId - The source identifier
32
47
  * @param targetId - The target identifier
33
48
  * @returns A new array with the pair created/updated
34
49
  */
35
50
  export function createOrUpdatePair(pairs: string[], sourceId: string, targetId: string): string[] {
36
- // Remove any existing pair for this source
37
- let newPairs = pairs.filter((p) => !p.startsWith(`${sourceId} `));
51
+ // Remove any existing pair for this target (target gets "replaced")
52
+ let newPairs = pairs.filter((p) => !p.endsWith(` ${targetId}`));
38
53
 
39
- // Remove any existing pair for this target
40
- newPairs = newPairs.filter((p) => !p.endsWith(` ${targetId}`));
41
-
42
- // Add new pair
43
- newPairs.push(`${sourceId} ${targetId}`);
54
+ // Don't remove source pairs - allows one source to match multiple targets (many-to-many)
55
+ // Add new pair (avoid duplicate if same pair already exists)
56
+ const newPair = `${sourceId} ${targetId}`;
57
+ if (!newPairs.includes(newPair)) {
58
+ newPairs.push(newPair);
59
+ }
44
60
 
45
61
  return newPairs;
46
62
  }
@@ -55,6 +71,13 @@ export function removePairBySource(pairs: string[], sourceId: string): string[]
55
71
  return pairs.filter((p) => !p.startsWith(`${sourceId} `));
56
72
  }
57
73
 
74
+ /**
75
+ * Removes a specific pair by source and target ID
76
+ */
77
+ export function removePair(pairs: string[], sourceId: string, targetId: string): string[] {
78
+ return pairs.filter((p) => p !== `${sourceId} ${targetId}`);
79
+ }
80
+
58
81
  /**
59
82
  * Removes a pair by target ID
60
83
  * @param pairs - Array of existing pair strings