@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
package/package.json CHANGED
@@ -1,93 +1,119 @@
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.5",
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.5",
31
+ "@pie-qti/item-player": "0.1.5",
32
+ "@pie-qti/qti-common": "0.1.5",
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
+ "./src/shared/styles/qti-shared-vocabulary.css": {
95
+ "style": "./src/shared/styles/qti-shared-vocabulary.css",
96
+ "default": "./src/shared/styles/qti-shared-vocabulary.css"
97
+ }
98
+ },
99
+ "repository": {
100
+ "type": "git",
101
+ "url": "https://github.com/pie-framework/pie-qti.git",
102
+ "directory": "packages/default-components"
103
+ },
104
+ "homepage": "https://github.com/pie-framework/pie-qti/tree/master/packages/default-components",
105
+ "bugs": {
106
+ "url": "https://github.com/pie-framework/pie-qti/issues"
107
+ },
108
+ "publishConfig": {
109
+ "access": "public"
110
+ },
111
+ "sideEffects": false,
112
+ "engines": {
113
+ "node": ">=20.19.0"
114
+ },
115
+ "files": [
116
+ "dist",
117
+ "src"
118
+ ]
93
119
  }
@@ -0,0 +1,162 @@
1
+ <svelte:options customElement="pie-qti-catalog-popup" />
2
+
3
+ <script lang="ts">
4
+ /**
5
+ * CatalogPopup — accessible floating dialog for QTI 3.0 catalog entries.
6
+ *
7
+ * Renders glossary definitions, keyword translations, and illustrated-glossary images.
8
+ * Focus-trapped: Tab/Shift+Tab cycle within; Escape closes.
9
+ * For platform-level usages (TTS, signing, braille) the player fires a qti-catalog-lookup
10
+ * event instead of mounting this component.
11
+ */
12
+
13
+ interface Props {
14
+ /** HTML content from CatalogEntry.html (or URL for illustrated-glossary). */
15
+ content: string;
16
+ /** Accessible label for the dialog (the term text). */
17
+ label: string;
18
+ /** Callback when the popup is closed. */
19
+ onClose: () => void;
20
+ }
21
+
22
+ const { content, label, onClose }: Props = $props();
23
+
24
+ // Illustrated-glossary: if content looks like a URL, render as <img>
25
+ const isUrl = $derived(/^(https?:\/\/|\/)/i.test(content.trim()));
26
+
27
+ let dialogEl: HTMLDivElement | undefined = $state();
28
+ let closeBtn: HTMLButtonElement | undefined = $state();
29
+
30
+ // Move focus into the popup on mount
31
+ $effect(() => {
32
+ if (dialogEl) {
33
+ closeBtn?.focus();
34
+ }
35
+ });
36
+
37
+ function handleKeyDown(event: KeyboardEvent) {
38
+ if (event.key === 'Escape') {
39
+ event.preventDefault();
40
+ onClose();
41
+ return;
42
+ }
43
+
44
+ // Focus trap: keep Tab within the popup
45
+ if (event.key === 'Tab' && dialogEl) {
46
+ const focusable = Array.from(
47
+ dialogEl.querySelectorAll<HTMLElement>(
48
+ 'a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])'
49
+ )
50
+ ).filter((el) => el.offsetParent !== null);
51
+
52
+ if (focusable.length === 0) {
53
+ event.preventDefault();
54
+ return;
55
+ }
56
+
57
+ const first = focusable[0];
58
+ const last = focusable[focusable.length - 1];
59
+
60
+ if (event.shiftKey && document.activeElement === first) {
61
+ event.preventDefault();
62
+ last.focus();
63
+ } else if (!event.shiftKey && document.activeElement === last) {
64
+ event.preventDefault();
65
+ first.focus();
66
+ }
67
+ }
68
+ }
69
+ </script>
70
+
71
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
72
+ <div
73
+ bind:this={dialogEl}
74
+ role="dialog"
75
+ aria-label={label}
76
+ aria-modal="true"
77
+ class="qti-catalog-popup"
78
+ onkeydown={handleKeyDown}
79
+ >
80
+ <div class="qti-catalog-popup__header">
81
+ <span class="qti-catalog-popup__title">{label}</span>
82
+ <button
83
+ bind:this={closeBtn}
84
+ type="button"
85
+ class="qti-catalog-popup__close"
86
+ aria-label="Close"
87
+ onclick={onClose}
88
+ >✕</button>
89
+ </div>
90
+ <div class="qti-catalog-popup__body">
91
+ {#if isUrl}
92
+ <img src={content} alt={label} class="qti-catalog-popup__img" />
93
+ {:else}
94
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
95
+ {@html content}
96
+ {/if}
97
+ </div>
98
+ </div>
99
+
100
+ <style>
101
+ .qti-catalog-popup {
102
+ position: absolute;
103
+ z-index: 1000;
104
+ background: var(--color-base-100, #fff);
105
+ border: 1px solid var(--color-base-300, #d1d5db);
106
+ border-radius: 0.5rem;
107
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
108
+ min-width: 16rem;
109
+ max-width: 24rem;
110
+ padding: 0;
111
+ font-size: 0.9rem;
112
+ line-height: 1.5;
113
+ }
114
+
115
+ .qti-catalog-popup__header {
116
+ display: flex;
117
+ align-items: center;
118
+ justify-content: space-between;
119
+ padding: 0.5rem 0.75rem;
120
+ border-bottom: 1px solid var(--color-base-300, #d1d5db);
121
+ background: var(--color-base-200, #f9fafb);
122
+ border-radius: 0.5rem 0.5rem 0 0;
123
+ }
124
+
125
+ .qti-catalog-popup__title {
126
+ font-weight: 600;
127
+ font-size: 0.85rem;
128
+ color: var(--color-base-content, #111);
129
+ }
130
+
131
+ .qti-catalog-popup__close {
132
+ background: none;
133
+ border: none;
134
+ cursor: pointer;
135
+ font-size: 1rem;
136
+ line-height: 1;
137
+ padding: 0.2rem 0.4rem;
138
+ border-radius: 0.25rem;
139
+ color: var(--color-base-content, #111);
140
+ opacity: 0.6;
141
+ }
142
+
143
+ .qti-catalog-popup__close:hover,
144
+ .qti-catalog-popup__close:focus-visible {
145
+ opacity: 1;
146
+ background: var(--color-base-300, #e5e7eb);
147
+ outline: 2px solid var(--color-primary, #4f46e5);
148
+ outline-offset: 1px;
149
+ }
150
+
151
+ .qti-catalog-popup__body {
152
+ padding: 0.75rem;
153
+ color: var(--color-base-content, #111);
154
+ }
155
+
156
+ .qti-catalog-popup__img {
157
+ max-width: 100%;
158
+ height: auto;
159
+ display: block;
160
+ margin: 0 auto;
161
+ }
162
+ </style>
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @pie-qti/default-components
3
3
  *
4
- * Default Svelte-based component implementations for the QTI 2.x player.
4
+ * Default Svelte-based component implementations for the QTI player.
5
5
  * These components are packaged as web components that work with the
6
6
  * framework-agnostic @pie-qti/item-player core.
7
7
  */
@@ -210,4 +210,13 @@ export function registerDefaultComponents(registry: ComponentRegistry): void {
210
210
 
211
211
  // Note: TextEntryInteraction and InlineChoiceInteraction are handled
212
212
  // by ItemRenderer as inline interactions, not as separate components
213
+
214
+ // CatalogPopup - focus-trapped dialog for glossary/keyword-translation entries
215
+ registry.register('catalogPopup', {
216
+ name: 'default-catalog-popup',
217
+ priority: 0,
218
+ description: 'Default Svelte-based catalog popup dialog',
219
+ canHandle: () => true,
220
+ tagName: 'pie-qti-catalog-popup',
221
+ });
213
222
  }
@@ -5,6 +5,7 @@
5
5
  import type { I18nProvider } from '@pie-qti/i18n';
6
6
  import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
7
  import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
8
+ import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
8
9
 
9
10
  interface Props {
10
11
  interaction?: AssociateInteractionData | string;
@@ -73,6 +74,17 @@
73
74
  }
74
75
  }
75
76
 
77
+ // Choices that cannot be paired with the currently selected choice due to matchGroup constraints
78
+ const blockedChoices = $derived.by(() => {
79
+ if (!selectedForPairing || !parsedInteraction) return new Set<string>();
80
+ const src = parsedInteraction.choices.find((c) => c.identifier === selectedForPairing);
81
+ return new Set(
82
+ parsedInteraction.choices
83
+ .filter((c) => c.identifier !== selectedForPairing && !isCompatibleMatchGroup(src?.matchGroup, c.matchGroup))
84
+ .map((c) => c.identifier)
85
+ );
86
+ });
87
+
76
88
  function handleChoiceClick(choiceId: string) {
77
89
  if (disabled) return;
78
90
 
@@ -84,8 +96,9 @@
84
96
  else if (selectedForPairing === choiceId) {
85
97
  setSelectedForPairing(null);
86
98
  }
87
- // If different item clicked, create a pair
99
+ // If different item clicked, check matchGroup compatibility then create a pair
88
100
  else {
101
+ if (blockedChoices.has(choiceId)) return;
89
102
  const newPair = `${selectedForPairing} ${choiceId}`;
90
103
  const newPairs = [...pairs, newPair];
91
104
  emitChange(newPairs);
@@ -135,9 +148,13 @@
135
148
  {@const isSelected = selectedForPairing === choice.identifier}
136
149
  {@const inPair = isInPair(choice.identifier)}
137
150
  {@const isCorrect = isCorrectPair(choice.identifier)}
151
+ {@const isBlocked = blockedChoices.has(choice.identifier)}
138
152
  <button
139
153
  part="choice"
140
154
  class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
155
+ class:opacity-40={isBlocked}
156
+ class:cursor-not-allowed={isBlocked}
157
+ aria-disabled={isBlocked ? 'true' : undefined}
141
158
  onclick={() => handleChoiceClick(choice.identifier)}
142
159
  {disabled}
143
160
  >
@@ -21,6 +21,8 @@
21
21
  onChange?: (value: string | string[]) => void;
22
22
  outcomeValues?: Record<string, any>;
23
23
  heuristicsConfig?: QtiHeuristicsConfig;
24
+ /** When true, renders an elimination toggle button per choice (QTI 3.0 PNP §6.2). */
25
+ eliminationTool?: boolean;
24
26
  }
25
27
 
26
28
  let {
@@ -33,7 +35,8 @@
33
35
  typeset,
34
36
  onChange,
35
37
  outcomeValues = {},
36
- heuristicsConfig
38
+ heuristicsConfig,
39
+ eliminationTool = false
37
40
  }: Props = $props();
38
41
 
39
42
  // Normalize heuristics configuration with defaults
@@ -74,6 +77,28 @@
74
77
  // Get reference to the root element for event dispatching
75
78
  let rootElement: HTMLDivElement | undefined = $state();
76
79
 
80
+ // Elimination tool state: set of eliminated choice identifiers.
81
+ // Eliminated choices remain in DOM and in the response; only visually dimmed.
82
+ let eliminatedChoices = $state(new Set<string>());
83
+
84
+ function toggleElimination(identifier: string) {
85
+ const next = new Set(eliminatedChoices);
86
+ if (next.has(identifier)) {
87
+ next.delete(identifier);
88
+ } else {
89
+ next.add(identifier);
90
+ }
91
+ eliminatedChoices = next;
92
+ }
93
+
94
+ function eliminationLabel(identifier: string): string {
95
+ const isEliminated = eliminatedChoices.has(identifier);
96
+ const action = isEliminated
97
+ ? (i18n?.t('interactions.choice.restoreChoice') ?? 'Restore')
98
+ : (i18n?.t('interactions.choice.eliminateChoice') ?? 'Eliminate');
99
+ return action;
100
+ }
101
+
77
102
  function handleRadioChange(identifier: string) {
78
103
  response = identifier;
79
104
  // Call onChange callback if provided (for Svelte component usage)
@@ -89,6 +114,9 @@
89
114
  let newValues = [...currentValues];
90
115
 
91
116
  if (checked) {
117
+ // Enforce maxChoices (0 = unlimited)
118
+ const max = parsedInteraction?.maxChoices ?? 0;
119
+ if (max > 0 && newValues.length >= max) return;
92
120
  newValues.push(identifier);
93
121
  } else {
94
122
  newValues = newValues.filter((v) => v !== identifier);
@@ -102,17 +130,28 @@
102
130
  rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newValues));
103
131
  }
104
132
  }
133
+
134
+ // Selection limit message: show max message when at/over limit; min message is for submit time
135
+ const selectionCount = $derived(Array.isArray(parsedResponse) ? parsedResponse.length : (parsedResponse ? 1 : 0));
136
+ const maxChoices = $derived(parsedInteraction?.maxChoices ?? 0);
137
+ const showMaxMessage = $derived(
138
+ maxChoices > 0 && selectionCount >= maxChoices && !!parsedInteraction?.maxSelectionsMessage
139
+ );
105
140
  </script>
106
141
 
107
142
  <ShadowBaseStyles />
108
143
 
109
- <div bind:this={rootElement} part="root" class="qti-choice-interaction space-y-2" use:typesetAction={{ typeset }}>
144
+ <div bind:this={rootElement} part="root" class={['qti-choice-interaction space-y-2', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
110
145
  {#if !parsedInteraction}
111
146
  <div class="alert alert-error">{i18n?.t('common.errorNoData') ?? 'No interaction data provided'}</div>
112
147
  {:else if parsedInteraction.maxChoices === 1}
113
148
  <!-- Single choice (radio buttons) -->
114
149
  {#each parsedInteraction.choices as choice}
115
- <div part="option" class="qti-choice-option form-control">
150
+ <div
151
+ part="option"
152
+ class="qti-choice-option form-control"
153
+ data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
154
+ >
116
155
  <label
117
156
  part="label"
118
157
  class="qti-choice-label label cursor-pointer justify-start gap-4"
@@ -136,13 +175,26 @@
136
175
  <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
137
176
  {/if}
138
177
  </label>
178
+ {#if eliminationTool}
179
+ <button
180
+ type="button"
181
+ class="qti-eliminate-btn"
182
+ aria-label={eliminationLabel(choice.identifier)}
183
+ aria-pressed={eliminatedChoices.has(choice.identifier)}
184
+ onclick={() => toggleElimination(choice.identifier)}
185
+ >✕</button>
186
+ {/if}
139
187
  </div>
140
188
  {/each}
141
189
  {:else}
142
190
  <!-- Multiple choice (checkboxes) -->
143
191
  {@const currentValues = Array.isArray(parsedResponse) ? parsedResponse : []}
144
192
  {#each parsedInteraction.choices as choice}
145
- <div part="option" class="qti-choice-option form-control">
193
+ <div
194
+ part="option"
195
+ class="qti-choice-option form-control"
196
+ data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
197
+ >
146
198
  <label
147
199
  part="label"
148
200
  class="qti-choice-label label cursor-pointer justify-start gap-4"
@@ -168,9 +220,21 @@
168
220
  <span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
169
221
  {/if}
170
222
  </label>
223
+ {#if eliminationTool}
224
+ <button
225
+ type="button"
226
+ class="qti-eliminate-btn"
227
+ aria-label={eliminationLabel(choice.identifier)}
228
+ aria-pressed={eliminatedChoices.has(choice.identifier)}
229
+ onclick={() => toggleElimination(choice.identifier)}
230
+ >✕</button>
231
+ {/if}
171
232
  </div>
172
233
  {/each}
173
234
  {/if}
235
+ {#if showMaxMessage}
236
+ <p class="qti-selection-message qti-max-selection-message" role="alert">{parsedInteraction?.maxSelectionsMessage}</p>
237
+ {/if}
174
238
  </div>
175
239
 
176
240
  <style>
@@ -209,4 +273,79 @@
209
273
  .checkbox-success {
210
274
  accent-color: var(--color-success, oklch(76% 0.177 163.223));
211
275
  }
276
+
277
+ /* Elimination tool */
278
+ .qti-choice-option {
279
+ position: relative;
280
+ }
281
+
282
+ .qti-eliminate-btn {
283
+ position: absolute;
284
+ right: 0.25rem;
285
+ top: 50%;
286
+ transform: translateY(-50%);
287
+ background: none;
288
+ border: 1px solid currentColor;
289
+ border-radius: 50%;
290
+ width: 1.5rem;
291
+ height: 1.5rem;
292
+ line-height: 1;
293
+ font-size: 0.75rem;
294
+ cursor: pointer;
295
+ opacity: 0.4;
296
+ padding: 0;
297
+ display: flex;
298
+ align-items: center;
299
+ justify-content: center;
300
+ }
301
+
302
+ .qti-eliminate-btn:hover,
303
+ .qti-eliminate-btn[aria-pressed='true'] {
304
+ opacity: 1;
305
+ }
306
+
307
+ /* Eliminated choices are dimmed with a strikethrough */
308
+ [data-eliminated] .qti-choice-label {
309
+ opacity: 0.4;
310
+ text-decoration: line-through;
311
+ }
312
+
313
+ [data-eliminated] .qti-eliminate-btn {
314
+ opacity: 1;
315
+ color: var(--color-error, oklch(63% 0.237 25.331));
316
+ }
317
+
318
+ /* ── QTI Shared Vocabulary behavioral classes ─────────────────────────── */
319
+
320
+ /* qti-input-control-hidden: hide radio/checkbox controls but keep keyboard-accessible */
321
+ :global(.qti-input-control-hidden) .qti-choice-interaction input[type='radio'],
322
+ :global(.qti-input-control-hidden) .qti-choice-interaction input[type='checkbox'],
323
+ .qti-choice-interaction.qti-input-control-hidden input[type='radio'],
324
+ .qti-choice-interaction.qti-input-control-hidden input[type='checkbox'] {
325
+ position: absolute;
326
+ opacity: 0;
327
+ width: 0;
328
+ height: 0;
329
+ pointer-events: none;
330
+ }
331
+
332
+ /* qti-orientation-horizontal: choices in a row */
333
+ .qti-choice-interaction.qti-orientation-horizontal {
334
+ grid-auto-flow: column;
335
+ grid-template-columns: repeat(auto-fill, minmax(0, 1fr));
336
+ }
337
+
338
+ /* qti-choices-stacking-N: N-column grid */
339
+ .qti-choice-interaction.qti-choices-stacking-1 { grid-template-columns: 1fr; }
340
+ .qti-choice-interaction.qti-choices-stacking-2 { grid-template-columns: repeat(2, 1fr); }
341
+ .qti-choice-interaction.qti-choices-stacking-3 { grid-template-columns: repeat(3, 1fr); }
342
+ .qti-choice-interaction.qti-choices-stacking-4 { grid-template-columns: repeat(4, 1fr); }
343
+ .qti-choice-interaction.qti-choices-stacking-5 { grid-template-columns: repeat(5, 1fr); }
344
+
345
+ /* Selection limit messages */
346
+ .qti-selection-message {
347
+ font-size: 0.875rem;
348
+ color: var(--color-warning, oklch(77% 0.194 82));
349
+ margin-top: 0.5rem;
350
+ }
212
351
  </style>