@pie-players/pie-tool-answer-eliminator 0.3.51 → 0.3.53

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.
package/README.md CHANGED
@@ -179,18 +179,21 @@ if (saved) {
179
179
 
180
180
  ### 1. Choice Detection
181
181
 
182
- The tool automatically detects answer choices within the scoped element:
182
+ The tool detects choices through an **adapter registry** (`AdapterRegistry`), not a fixed selector list. Each adapter knows how to find and operate on choices for a specific PIE element type, and the registry runs them in priority order (`canHandle()`, then `findChoices()`), so a single question can mix element types:
183
+
184
+ | Adapter | Element type | How it finds choices |
185
+ | --- | --- | --- |
186
+ | `MultipleChoiceAdapter` | `multiple-choice` (single- or multi-select) | `.corespring-checkbox` / `.corespring-radio-button` choices |
187
+ | `EBSRAdapter` | `ebsr` | delegates to the multiple-choice adapter for each `ebsr-multiple-choice` part (Part A/B), prefixing choice IDs with the part |
188
+ | `InlineDropdownAdapter` | `inline-dropdown` | dropdown items with `role="option"` |
189
+
190
+ Support more element types at runtime by registering your own adapter (any object implementing the `ChoiceAdapter` interface: `canHandle`, `findChoices`, `getChoiceId`, `getChoiceLabel`, `canEliminate`, `createChoiceRange`, `getButtonContainer`):
183
191
 
184
192
  ```typescript
185
- // Searches for choice elements with these patterns
186
- const choiceSelectors = [
187
- '[data-choice-id]', // PIE standard
188
- '.choice', // Common class
189
- '[role="radio"]', // Accessibility
190
- '[role="checkbox"]', // Accessibility
191
- 'input[type="radio"]', // Native inputs
192
- 'input[type="checkbox"]' // Native inputs
193
- ];
193
+ import { AdapterRegistry } from '@pie-players/pie-tool-answer-eliminator';
194
+
195
+ const registry = new AdapterRegistry();
196
+ registry.registerAdapter(myCustomChoiceAdapter);
194
197
  ```
195
198
 
196
199
  ### 2. State Storage
@@ -205,26 +208,16 @@ Eliminated choices are stored by choice ID:
205
208
 
206
209
  ### 3. Visual Feedback
207
210
 
208
- Eliminated choices receive the `eliminated` CSS class:
209
-
210
- ```css
211
- .choice.eliminated {
212
- text-decoration: line-through;
213
- opacity: 0.5;
214
- }
215
- ```
211
+ Elimination styling is applied by a pluggable `EliminationStrategy` built on the **CSS Custom Highlight API** (zero DOM mutation, so the choice text and structure stay intact for screen readers). Two strategies ship today:
216
212
 
217
- ### 4. Toggle Behavior
213
+ - `strikethrough` (default): a `::highlight(pie-answer-eliminated-<id>)` rule renders a line-through over the choice label.
214
+ - `mask`: a `::highlight(pie-answer-masked-<id>)` rule dims and blurs the choice.
218
215
 
219
- Clicking a choice toggles its elimination state:
216
+ For browsers without the Highlight API, each strategy falls back to a class on the choice container. Either way the eliminated choice also receives ARIA hooks (`data-pie-answer-eliminated`, plus `aria-disabled`/`aria-hidden` and an offscreen "(eliminated)" announcement) for assistive technology.
220
217
 
221
- ```typescript
222
- // First click: eliminate
223
- choiceElement.classList.add('eliminated');
218
+ ### 4. Toggle Behavior
224
219
 
225
- // Second click: restore
226
- choiceElement.classList.remove('eliminated');
227
- ```
220
+ Each detected choice gets its own elimination toggle button (class `pie-answer-eliminator-toggle`, rendered as `⊗`) placed via the adapter's `getButtonContainer()`. Clicking the button toggles that choice through the active strategy. Eliminating is blocked when the adapter's `canEliminate()` returns false — for example when the choice is already selected, disabled, or the item is in evaluate/view mode. An active button is marked with `pie-answer-eliminator-toggle--active` and `aria-pressed="true"`; clicking again restores the choice.
228
221
 
229
222
  ## Cleanup
230
223