@pie-qti/default-components 0.1.4 → 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 (32) 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/utils/matchGroupUtils.d.ts +8 -0
  8. package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
  9. package/dist/shared/utils/matchGroupUtils.js +13 -0
  10. package/package.json +8 -4
  11. package/src/catalog/CatalogPopup.svelte +162 -0
  12. package/src/index.ts +10 -1
  13. package/src/plugins/associate/AssociateInteraction.svelte +18 -1
  14. package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
  15. package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
  16. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
  17. package/src/plugins/gap-match/GapMatchInteraction.svelte +174 -12
  18. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
  19. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +197 -107
  20. package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
  21. package/src/plugins/hottext/HottextInteraction.svelte +33 -4
  22. package/src/plugins/index.ts +1 -0
  23. package/src/plugins/match/MatchInteraction.svelte +13 -1
  24. package/src/plugins/order/OrderInteraction.svelte +132 -11
  25. package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -9
  26. package/src/plugins/select-point/SelectPointInteraction.svelte +139 -7
  27. package/src/shared/components/GraphicGapMatch.svelte +5 -3
  28. package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
  29. package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
  30. package/src/shared/components/MatchDragDrop.svelte +48 -2
  31. package/src/shared/styles/qti-shared-vocabulary.css +320 -0
  32. package/src/shared/utils/matchGroupUtils.ts +14 -0
package/dist/index.d.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
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,cAAc,mBAAmB,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CA+K3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,cAAc,mBAAmB,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAwL3E"}
package/dist/index.js 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
  */
@@ -187,4 +187,12 @@ export function registerDefaultComponents(registry) {
187
187
  });
188
188
  // Note: TextEntryInteraction and InlineChoiceInteraction are handled
189
189
  // by ItemRenderer as inline interactions, not as separate components
190
+ // CatalogPopup - focus-trapped dialog for glossary/keyword-translation entries
191
+ registry.register('catalogPopup', {
192
+ name: 'default-catalog-popup',
193
+ priority: 0,
194
+ description: 'Default Svelte-based catalog popup dialog',
195
+ canHandle: () => true,
196
+ tagName: 'pie-qti-catalog-popup',
197
+ });
190
198
  }
@@ -27,4 +27,5 @@ import './select-point/SelectPointInteraction.svelte';
27
27
  import './extended-text/ExtendedTextInteraction.svelte';
28
28
  import './upload/UploadInteraction.svelte';
29
29
  import './drawing/DrawingInteraction.svelte';
30
+ import '../catalog/CatalogPopup.svelte';
30
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mCAAmC,CAAC;AAC3C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,yCAAyC,CAAC;AACjD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4CAA4C,CAAC;AACpD,OAAO,oDAAoD,CAAC;AAC5D,OAAO,uDAAuD,CAAC;AAC/D,OAAO,gDAAgD,CAAC;AACxD,OAAO,wDAAwD,CAAC;AAChE,OAAO,8CAA8C,CAAC;AACtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mCAAmC,CAAC;AAC3C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,yCAAyC,CAAC;AACjD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4CAA4C,CAAC;AACpD,OAAO,oDAAoD,CAAC;AAC5D,OAAO,uDAAuD,CAAC;AAC/D,OAAO,gDAAgD,CAAC;AACxD,OAAO,wDAAwD,CAAC;AAChE,OAAO,8CAA8C,CAAC;AACtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,gCAAgC,CAAC"}
@@ -28,3 +28,4 @@ import './select-point/SelectPointInteraction.svelte';
28
28
  import './extended-text/ExtendedTextInteraction.svelte';
29
29
  import './upload/UploadInteraction.svelte';
30
30
  import './drawing/DrawingInteraction.svelte';
31
+ import '../catalog/CatalogPopup.svelte';
@@ -0,0 +1,8 @@
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 declare function isCompatibleMatchGroup(sourceGroups: string[] | undefined, targetGroups: string[] | undefined): boolean;
8
+ //# sourceMappingURL=matchGroupUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchGroupUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/matchGroupUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,EAClC,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,GAChC,OAAO,CAIT"}
@@ -0,0 +1,13 @@
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(sourceGroups, targetGroups) {
8
+ if (!sourceGroups || sourceGroups.length === 0)
9
+ return true;
10
+ if (!targetGroups || targetGroups.length === 0)
11
+ return true;
12
+ return sourceGroups.some((g) => targetGroups.includes(g));
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/default-components",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,9 +27,9 @@
27
27
  ],
28
28
  "license": "MIT",
29
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",
30
+ "@pie-qti/i18n": "0.1.5",
31
+ "@pie-qti/item-player": "0.1.5",
32
+ "@pie-qti/qti-common": "0.1.5",
33
33
  "@tiptap/core": "^3.15.3",
34
34
  "@tiptap/extension-mathematics": "^3.15.3",
35
35
  "@tiptap/extension-placeholder": "^3.15.3",
@@ -90,6 +90,10 @@
90
90
  "./shared/extensions/*": {
91
91
  "types": "./dist/shared/extensions/*.d.ts",
92
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"
93
97
  }
94
98
  },
95
99
  "repository": {
@@ -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>
@@ -63,6 +63,15 @@
63
63
  {#if parsedInteraction.prompt}
64
64
  <p class="font-semibold mb-2">{parsedInteraction.prompt}</p>
65
65
  {/if}
66
+ <!--
67
+ Accessibility note (WCAG 2.1 SC 2.1.1 exemption):
68
+ Free-form drawing is a path-dependent pointer input. WCAG 2.1.1 exempts inputs
69
+ "where the underlying function requires input that depends on the path of the
70
+ user's movement and not just the endpoints" (e.g. freehand drawing, handwriting).
71
+ Item authors MUST provide an accessible alternative form (e.g. an extended-text
72
+ response or upload interaction) so that keyboard-only and switch-access users
73
+ can submit equivalent evidence of their knowledge.
74
+ -->
66
75
  <DrawingCanvas
67
76
  responseId={parsedInteraction.responseId}
68
77
  imageData={parsedInteraction.imageData}
@@ -39,11 +39,27 @@
39
39
  rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, html));
40
40
  }
41
41
  }
42
+
43
+ // Character counter support (qti-counter-down / qti-counter-up)
44
+ function charCount(html: string, format: string): number {
45
+ if (format === 'xhtml') {
46
+ // Strip HTML tags, count only text characters
47
+ return html.replace(/<[^>]*>/g, '').length;
48
+ }
49
+ return html.length;
50
+ }
51
+
52
+ const currentCount = $derived(charCount(parsedResponse ?? '', parsedInteraction?.format ?? 'plain'));
53
+ const expectedLength = $derived(parsedInteraction?.expectedLength ?? 0);
54
+ const classes = $derived(parsedInteraction?.interactionClasses ?? []);
55
+ const showCounterDown = $derived(classes.includes('qti-counter-down') && expectedLength > 0);
56
+ const showCounterUp = $derived(classes.includes('qti-counter-up') && expectedLength > 0);
57
+ const remaining = $derived(expectedLength - currentCount);
42
58
  </script>
43
59
 
44
60
  <ShadowBaseStyles />
45
61
 
46
- <div bind:this={rootElement} part="root" class="qti-extended-text-interaction">
62
+ <div bind:this={rootElement} part="root" class={['qti-extended-text-interaction', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')}>
47
63
  {#if !parsedInteraction}
48
64
  <div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
49
65
  {:else}
@@ -57,6 +73,15 @@
57
73
  onChange={handleChange}
58
74
  />
59
75
  </div>
76
+ {#if showCounterDown}
77
+ <p part="counter" class="qti-character-counter" aria-live="polite">
78
+ {remaining >= 0 ? remaining : 0} {i18n?.t('interactions.extendedText.charsRemaining', 'characters remaining')}
79
+ </p>
80
+ {:else if showCounterUp}
81
+ <p part="counter" class="qti-character-counter" aria-live="polite">
82
+ {currentCount} / {expectedLength} {i18n?.t('interactions.extendedText.charsUsed', 'characters')}
83
+ </p>
84
+ {/if}
60
85
  {#if isShowingCorrect && parsedCorrectResponse}
61
86
  <div part="correct-answer" class="mt-3 p-3 bg-success bg-opacity-10 border border-success rounded">
62
87
  <div class="text-sm font-semibold text-success mb-2">
@@ -74,4 +99,34 @@
74
99
  display: grid;
75
100
  gap: 0.75rem;
76
101
  }
102
+
103
+ /* QTI 3.0 Shared Vocabulary: qti-height-lines-N sets minimum textarea height.
104
+ Each line unit = 1.5rem (24px) matching the editor's line-height. */
105
+ .qti-height-lines-1 { --qti-min-height: 1.5rem; }
106
+ .qti-height-lines-2 { --qti-min-height: 3rem; }
107
+ .qti-height-lines-3 { --qti-min-height: 4.5rem; }
108
+ .qti-height-lines-4 { --qti-min-height: 6rem; }
109
+ .qti-height-lines-5 { --qti-min-height: 7.5rem; }
110
+ .qti-height-lines-6 { --qti-min-height: 9rem; }
111
+ .qti-height-lines-7 { --qti-min-height: 10.5rem; }
112
+ .qti-height-lines-8 { --qti-min-height: 12rem; }
113
+ .qti-height-lines-10 { --qti-min-height: 15rem; }
114
+ .qti-height-lines-12 { --qti-min-height: 18rem; }
115
+ .qti-height-lines-15 { --qti-min-height: 22.5rem; }
116
+ .qti-height-lines-20 { --qti-min-height: 30rem; }
117
+ .qti-height-lines-25 { --qti-min-height: 37.5rem; }
118
+
119
+ /* Apply the CSS variable to the editor's inner textarea via the part */
120
+ [class*='qti-height-lines-'] :global([part='editor'] .ProseMirror),
121
+ [class*='qti-height-lines-'] :global([part='editor'] textarea) {
122
+ min-height: var(--qti-min-height);
123
+ }
124
+
125
+ .qti-character-counter {
126
+ font-size: 0.8125rem;
127
+ color: var(--color-base-content, #374151);
128
+ opacity: 0.7;
129
+ margin-top: 0.25rem;
130
+ text-align: right;
131
+ }
77
132
  </style>