@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
@@ -84,7 +84,7 @@
84
84
 
85
85
  <ShadowBaseStyles />
86
86
 
87
- <div bind:this={rootElement} class="qti-hotspot-interaction space-y-3">
87
+ <div bind:this={rootElement} class={['qti-hotspot-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
88
88
  {#if !parsedInteraction}
89
89
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
90
90
  {:else}
@@ -123,6 +123,9 @@
123
123
  {@const isCorrectChoice = isCorrect(choice.identifier)}
124
124
  {@const coords = choice.coords.split(',').map(Number)}
125
125
 
126
+ {@const shapeLabel = choice.hotspotLabel || `Hotspot ${choice.identifier}`}
127
+ {@const ariaLabel = `${shapeLabel}${isCorrectChoice ? '. Correct answer' : ''}`}
128
+
126
129
  {#if choice.shape === 'circle'}
127
130
  <!-- Circle: coords are cx, cy, radius -->
128
131
  <circle
@@ -134,25 +137,43 @@
134
137
  stroke-width="2"
135
138
  class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
136
139
  role="button"
137
- aria-label={`Select hotspot ${choice.identifier}${isCorrectChoice ? '. Correct answer' : ''}`}
140
+ aria-label={ariaLabel}
138
141
  aria-pressed={isSelected ? 'true' : 'false'}
139
142
  tabindex={disabled ? -1 : 0}
140
143
  onclick={() => handleClick(choice.identifier)}
141
144
  onkeydown={(e) => handleKeyDown(e, choice.identifier)}
142
145
  />
143
146
  {:else if choice.shape === 'rect'}
144
- <!-- Rectangle: coords are x, y, width, height -->
147
+ <!-- Rectangle: QTI coords are left,top,right,bottom -->
145
148
  <rect
146
149
  x={coords[0]}
147
150
  y={coords[1]}
148
- width={coords[2]}
149
- height={coords[3]}
151
+ width={coords[2] - coords[0]}
152
+ height={coords[3] - coords[1]}
150
153
  fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
151
154
  stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
152
155
  stroke-width="2"
153
156
  class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
154
157
  role="button"
155
- aria-label={`Select hotspot ${choice.identifier}${isCorrectChoice ? '. Correct answer' : ''}`}
158
+ aria-label={ariaLabel}
159
+ aria-pressed={isSelected ? 'true' : 'false'}
160
+ tabindex={disabled ? -1 : 0}
161
+ onclick={() => handleClick(choice.identifier)}
162
+ onkeydown={(e) => handleKeyDown(e, choice.identifier)}
163
+ />
164
+ {:else if choice.shape === 'ellipse'}
165
+ <!-- Ellipse: QTI coords are cx,cy,rx,ry -->
166
+ <ellipse
167
+ cx={coords[0]}
168
+ cy={coords[1]}
169
+ rx={coords[2]}
170
+ ry={coords[3]}
171
+ fill={isSelected ? 'rgba(59, 130, 246, 0.3)' : isCorrectChoice ? 'rgba(34, 197, 94, 0.3)' : 'rgba(0, 0, 0, 0)'}
172
+ stroke={isSelected ? '#3b82f6' : isCorrectChoice ? '#22c55e' : 'transparent'}
173
+ stroke-width="2"
174
+ class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
175
+ role="button"
176
+ aria-label={ariaLabel}
156
177
  aria-pressed={isSelected ? 'true' : 'false'}
157
178
  tabindex={disabled ? -1 : 0}
158
179
  onclick={() => handleClick(choice.identifier)}
@@ -175,7 +196,7 @@
175
196
  stroke-width="2"
176
197
  class="qti-hotspot-shape hover:fill-[rgba(59,130,246,0.1)] transition-all"
177
198
  role="button"
178
- aria-label={`Select hotspot ${choice.identifier}${isCorrectChoice ? '. Correct answer' : ''}`}
199
+ aria-label={ariaLabel}
179
200
  aria-pressed={isSelected ? 'true' : 'false'}
180
201
  tabindex={disabled ? -1 : 0}
181
202
  onclick={() => handleClick(choice.identifier)}
@@ -197,10 +218,32 @@
197
218
  {/if}
198
219
  </div>
199
220
  {/if}
221
+ {#if parsedInteraction.maxSelectionsMessage}
222
+ {@const selected = Array.isArray(parsedResponse) ? parsedResponse : (parsedResponse ? [parsedResponse] : [])}
223
+ {#if selected.length >= parsedInteraction.maxChoices && parsedInteraction.maxChoices > 0}
224
+ <p class="qti-selection-message" role="alert">{parsedInteraction.maxSelectionsMessage}</p>
225
+ {/if}
226
+ {/if}
200
227
  {/if}
201
228
  </div>
202
229
 
203
230
  <style>
231
+ .qti-selection-message {
232
+ font-size: 0.875rem;
233
+ color: var(--color-warning, oklch(77% 0.194 82));
234
+ margin-top: 0.25rem;
235
+ }
236
+
237
+ /* qti-selections-light / qti-selections-dark: hotspot overlay color theme */
238
+ .qti-selections-light .qti-hotspot-shape {
239
+ fill: rgba(255, 255, 255, 0.4);
240
+ stroke: rgba(255, 255, 255, 0.8);
241
+ }
242
+ .qti-selections-dark .qti-hotspot-shape {
243
+ fill: rgba(0, 0, 0, 0.4);
244
+ stroke: rgba(0, 0, 0, 0.8);
245
+ }
246
+
204
247
  /* Minimal layout so this works without Tailwind utilities */
205
248
  .qti-hotspot-interaction {
206
249
  display: grid;
@@ -55,8 +55,11 @@
55
55
  /**
56
56
  * Check if selection limit has been reached
57
57
  */
58
+ // maxChoices=0 means unlimited per QTI spec
58
59
  const canSelectMore = $derived(
59
- parsedInteraction ? selectedIds.length < parsedInteraction.maxChoices : false
60
+ parsedInteraction
61
+ ? parsedInteraction.maxChoices === 0 || selectedIds.length < parsedInteraction.maxChoices
62
+ : false
60
63
  );
61
64
 
62
65
  /**
@@ -197,7 +200,7 @@
197
200
 
198
201
  <ShadowBaseStyles />
199
202
 
200
- <div bind:this={rootElement} part="root" class="qti-hottext-interaction space-y-3">
203
+ <div bind:this={rootElement} part="root" class={['qti-hottext-interaction space-y-3', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
201
204
  {#if !parsedInteraction}
202
205
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
203
206
  {:else}
@@ -217,8 +220,15 @@
217
220
 
218
221
  <div part="footer" class="qti-hottext-footer flex items-center justify-between text-sm text-base-content/70">
219
222
  <div>
220
- <span class="font-medium">Selected:</span>
221
- <span class="ml-2">{selectedIds.length} / {parsedInteraction.maxChoices}</span>
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}
222
232
  </div>
223
233
 
224
234
  {#if selectedIds.length > 0}
@@ -245,10 +255,29 @@
245
255
  </button>
246
256
  {/if}
247
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}
248
261
  {/if}
249
262
  </div>
250
263
 
251
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
+
252
281
  /* Minimal layout so this works without Tailwind/DaisyUI */
253
282
  .qti-hottext-interaction {
254
283
  display: grid;
@@ -29,3 +29,4 @@ import './select-point/SelectPointInteraction.svelte';
29
29
  import './extended-text/ExtendedTextInteraction.svelte';
30
30
  import './upload/UploadInteraction.svelte';
31
31
  import './drawing/DrawingInteraction.svelte';
32
+ import '../catalog/CatalogPopup.svelte';
@@ -47,7 +47,7 @@
47
47
 
48
48
  <ShadowBaseStyles />
49
49
 
50
- <div bind:this={rootElement} class="qti-match-interaction" use:typesetAction={{ typeset }}>
50
+ <div bind:this={rootElement} class={['qti-match-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
51
51
  {#if !parsedInteraction}
52
52
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
53
53
  {:else}
@@ -61,10 +61,22 @@
61
61
  sourceSet={parsedInteraction.sourceSet}
62
62
  targetSet={parsedInteraction.targetSet}
63
63
  {pairs}
64
+ maxAssociations={parsedInteraction.maxAssociations}
64
65
  correctPairs={isShowingCorrect ? (parsedCorrectResponse || []) : []}
65
66
  {disabled}
66
67
  {i18n}
67
68
  onPairsChange={handlePairsChange}
68
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}
69
73
  {/if}
70
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>
@@ -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>
@@ -18,9 +18,11 @@
18
18
  i18n?: I18nProvider;
19
19
  typeset?: (element: HTMLElement) => void;
20
20
  onChange?: (value: string[]) => void;
21
+ /** When true, renders an elimination toggle button per choice (QTI 3.0 PNP §6.2). */
22
+ eliminationTool?: boolean;
21
23
  }
22
24
 
23
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
25
+ let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange, eliminationTool = false }: Props = $props();
24
26
 
25
27
  // Parse props that may be JSON strings (web component usage)
26
28
  const parsedInteraction = $derived(parseJsonProp<OrderInteractionData>(interaction));
@@ -34,11 +36,54 @@
34
36
  // Track whether user has confirmed their order
35
37
  let hasConfirmed = $state(false);
36
38
 
37
- // Get ordered IDs from response, or use original order
39
+ // Shuffle choices on first render when shuffle=true, respecting fixed=true per choice.
40
+ // Uses a simple seeded shuffle keyed to the responseId so the order is stable within a session.
41
+ const shuffledChoiceIds = $derived.by(() => {
42
+ const choices = parsedInteraction?.choices;
43
+ if (!choices || !parsedInteraction?.shuffle) {
44
+ return choices?.map((c) => c.identifier) ?? [];
45
+ }
46
+
47
+ // Separate fixed and non-fixed choices
48
+ const fixedSlots = new Map<number, string>(); // index → identifier
49
+ const movable: string[] = [];
50
+ for (let i = 0; i < choices.length; i++) {
51
+ if (choices[i].fixed) {
52
+ fixedSlots.set(i, choices[i].identifier);
53
+ } else {
54
+ movable.push(choices[i].identifier);
55
+ }
56
+ }
57
+
58
+ // Fisher-Yates shuffle with a simple deterministic seed
59
+ const seed = (parsedInteraction.responseId ?? 'order').split('').reduce((a, c) => a + c.charCodeAt(0), 0);
60
+ const rng = (n: number) => {
61
+ // LCG: good enough for presentation shuffle
62
+ return ((seed * 1664525 + 1013904223 + n * 22695477) & 0x7fffffff) / 0x7fffffff;
63
+ };
64
+ for (let i = movable.length - 1; i > 0; i--) {
65
+ const j = Math.floor(rng(i) * (i + 1));
66
+ [movable[i], movable[j]] = [movable[j], movable[i]];
67
+ }
68
+
69
+ // Reconstruct full array, inserting fixed choices back into their original slots
70
+ const result: string[] = new Array(choices.length);
71
+ let movableIdx = 0;
72
+ for (let i = 0; i < choices.length; i++) {
73
+ if (fixedSlots.has(i)) {
74
+ result[i] = fixedSlots.get(i)!;
75
+ } else {
76
+ result[i] = movable[movableIdx++];
77
+ }
78
+ }
79
+ return result;
80
+ });
81
+
82
+ // Get ordered IDs from response, or use shuffled/original order
38
83
  const orderedIds = $derived(
39
84
  parsedResponse && parsedResponse.length > 0
40
85
  ? parsedResponse
41
- : parsedInteraction?.choices.map((c) => c.identifier) ?? []
86
+ : shuffledChoiceIds
42
87
  );
43
88
 
44
89
  // Track initial order to detect if user has made changes
@@ -87,6 +132,25 @@
87
132
  hasConfirmed = false;
88
133
  }
89
134
  });
135
+
136
+ // Elimination tool state
137
+ let eliminatedChoices = $state(new Set<string>());
138
+
139
+ function toggleElimination(identifier: string) {
140
+ const next = new Set(eliminatedChoices);
141
+ if (next.has(identifier)) {
142
+ next.delete(identifier);
143
+ } else {
144
+ next.add(identifier);
145
+ }
146
+ eliminatedChoices = next;
147
+ }
148
+
149
+ function eliminationLabel(identifier: string): string {
150
+ return eliminatedChoices.has(identifier)
151
+ ? (i18n?.t('interactions.choice.restoreChoice') ?? 'Restore')
152
+ : (i18n?.t('interactions.choice.eliminateChoice') ?? 'Eliminate');
153
+ }
90
154
  </script>
91
155
 
92
156
  <ShadowBaseStyles />
@@ -101,14 +165,31 @@
101
165
  </div>
102
166
  {/if}
103
167
 
104
- <SortableList
105
- items={parsedInteraction.choices.map(c => ({ id: c.identifier, text: c.text }))}
106
- {orderedIds}
107
- correctOrder={isShowingCorrect ? (parsedCorrectResponse || []) : []}
108
- orientation="vertical"
109
- {disabled}
110
- onReorder={handleReorder}
111
- />
168
+ <div class="qti-order-sortable-wrapper" class:qti-order-with-elimination={eliminationTool}>
169
+ <SortableList
170
+ items={parsedInteraction.choices.map(c => ({ id: c.identifier, text: c.text }))}
171
+ {orderedIds}
172
+ correctOrder={isShowingCorrect ? (parsedCorrectResponse || []) : []}
173
+ orientation="vertical"
174
+ {disabled}
175
+ onReorder={handleReorder}
176
+ />
177
+ {#if eliminationTool}
178
+ <div class="qti-order-elimination-col" aria-hidden="true">
179
+ {#each orderedIds as id (id)}
180
+ <button
181
+ type="button"
182
+ class="qti-eliminate-btn"
183
+ aria-label={eliminationLabel(id)}
184
+ aria-pressed={eliminatedChoices.has(id)}
185
+ aria-hidden="false"
186
+ onclick={() => toggleElimination(id)}
187
+ data-eliminated={eliminatedChoices.has(id) ? '' : undefined}
188
+ >✕</button>
189
+ {/each}
190
+ </div>
191
+ {/if}
192
+ </div>
112
193
 
113
194
  <!-- Confirmation button for WCAG 2.2 SC 3.3.4 compliance -->
114
195
  <div class="mt-4 flex items-center gap-3">
@@ -156,4 +237,44 @@
156
237
  height: 1rem;
157
238
  flex: 0 0 auto;
158
239
  }
240
+
241
+ /* Elimination tool layout */
242
+ .qti-order-sortable-wrapper {
243
+ position: relative;
244
+ }
245
+
246
+ .qti-order-with-elimination {
247
+ display: grid;
248
+ grid-template-columns: 1fr auto;
249
+ gap: 0.25rem;
250
+ align-items: start;
251
+ }
252
+
253
+ .qti-order-elimination-col {
254
+ display: flex;
255
+ flex-direction: column;
256
+ gap: 0.5rem;
257
+ }
258
+
259
+ .qti-eliminate-btn {
260
+ background: none;
261
+ border: 1px solid currentColor;
262
+ border-radius: 50%;
263
+ width: 1.75rem;
264
+ height: 1.75rem;
265
+ font-size: 0.75rem;
266
+ cursor: pointer;
267
+ opacity: 0.4;
268
+ padding: 0;
269
+ display: flex;
270
+ align-items: center;
271
+ justify-content: center;
272
+ flex-shrink: 0;
273
+ }
274
+
275
+ .qti-eliminate-btn:hover,
276
+ .qti-eliminate-btn[data-eliminated] {
277
+ opacity: 1;
278
+ color: var(--color-error, oklch(63% 0.237 25.331));
279
+ }
159
280
  </style>