npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pie-players/pie-tool-answer-eliminator

v0.2.8

Published

Answer eliminator tool for PIE assessment player - supports process-of-elimination test-taking strategy

Readme

@pie-players/pie-tool-answer-eliminator

Test-taking strategy tool that allows students to eliminate answer choices they believe are incorrect.

Features

  • Element-Level State: Answer eliminations tracked per PIE element (not per item)
  • Visual Feedback: Strikethrough styling for eliminated choices
  • Global Uniqueness: Uses composite keys for state management across sections
  • Ephemeral State: State is client-only, separate from PIE session data
  • ElementToolStateStore Integration: Works with Assessment Toolkit's state management

Installation

npm install @pie-players/pie-tool-answer-eliminator
# or
bun add @pie-players/pie-tool-answer-eliminator

Usage

As Web Component

The answer eliminator is automatically integrated when using the PIE Section Player with ToolkitCoordinator:

<script type="module">
  import '@pie-players/pie-section-player';
  import { ToolkitCoordinator } from '@pie-players/pie-assessment-toolkit';

  const coordinator = new ToolkitCoordinator({
    assessmentId: 'my-assessment',
    tools: {
      answerEliminator: { enabled: true }
    }
  });

  const player = document.getElementById('player');
  player.toolkitCoordinator = coordinator;
  player.section = mySection;
</script>

<pie-section-player id="player"></pie-section-player>

The section player automatically:

  • Renders answer eliminator buttons in question toolbars
  • Generates global element IDs
  • Passes ElementToolStateStore to the tool
  • Manages state lifecycle

Manual Integration (Advanced)

For custom implementations outside the section player:

<script type="module">
  import '@pie-players/pie-tool-answer-eliminator';
  import { ElementToolStateStore } from '@pie-players/pie-assessment-toolkit';

  const store = new ElementToolStateStore();
  const globalElementId = store.getGlobalElementId(
    'my-assessment',
    'section-1',
    'question-1',
    'mc1'
  );

  const tool = document.querySelector('pie-tool-answer-eliminator');
  tool.globalElementId = globalElementId;
  tool.elementToolStateStore = store;
  tool.scopeElement = document.querySelector('.question-content');
</script>

<pie-tool-answer-eliminator></pie-tool-answer-eliminator>

Props/Attributes

The web component accepts the following properties (set via JavaScript, not HTML attributes):

| Property | Type | Required | Description | |----------|------|----------|-------------| | globalElementId | string | Yes | Composite key: assessmentId:sectionId:itemId:elementId | | elementToolStateStore | IElementToolStateStore | Yes | Store for element-level tool state | | scopeElement | HTMLElement | No | DOM element to scope choice detection (defaults to document) |

Global Element ID Format

The tool uses globally unique composite keys for state management:

${assessmentId}:${sectionId}:${itemId}:${elementId}

Example:

"demo-assessment:section-1:question-1:mc1"
"biology-exam:section-2:genetics-q1:ebsr-part1"

Benefits of Composite Keys

  • Element-Level Granularity: Each PIE element has independent eliminations
  • No Cross-Item Contamination: Eliminations from question 1 don't appear on question 2
  • Cross-Section Persistence: State persists when navigating between sections
  • Global Uniqueness: No ID collisions across entire assessment

Why Element-Level?

Items can contain multiple interactive elements (e.g., EBSR with two parts). Each element needs independent state:

// ✅ Correct: Element-level state
{
  "demo:section-1:question-1:ebsr-part1": {
    "answerEliminator": { "eliminatedChoices": ["choice-a", "choice-c"] }
  },
  "demo:section-1:question-1:ebsr-part2": {
    "answerEliminator": { "eliminatedChoices": ["choice-b"] }
  }
}

State Management

Ephemeral vs Persistent State

The answer eliminator stores state in ElementToolStateStore (ephemeral, client-only):

Tool State (Ephemeral - NOT sent to server):

{
  "demo:section-1:question-1:mc1": {
    "answerEliminator": {
      "eliminatedChoices": ["choice-b", "choice-d"]
    }
  }
}

PIE Session Data (Persistent - sent to server for scoring):

{
  "question-1": {
    "id": "session-123",
    "data": [
      { "id": "mc1", "element": "multiple-choice", "value": ["choice-a"] }
    ]
  }
}

Persistence Integration

To persist tool state across page refreshes:

const coordinator = new ToolkitCoordinator({
  assessmentId: 'my-assessment',
  tools: { answerEliminator: { enabled: true } }
});

// Save to localStorage on change
const storageKey = `tool-state:${coordinator.assessmentId}`;
coordinator.elementToolStateStore.setOnStateChange((state) => {
  localStorage.setItem(storageKey, JSON.stringify(state));
});

// Load on mount
const saved = localStorage.getItem(storageKey);
if (saved) {
  coordinator.elementToolStateStore.loadState(JSON.parse(saved));
}

How It Works

1. Choice Detection

The tool automatically detects answer choices within the scoped element:

// Searches for choice elements with these patterns
const choiceSelectors = [
  '[data-choice-id]',           // PIE standard
  '.choice',                     // Common class
  '[role="radio"]',              // Accessibility
  '[role="checkbox"]',           // Accessibility
  'input[type="radio"]',         // Native inputs
  'input[type="checkbox"]'       // Native inputs
];

2. State Storage

Eliminated choices are stored by choice ID:

{
  "eliminatedChoices": ["choice-a", "choice-c"]
}

3. Visual Feedback

Eliminated choices receive the eliminated CSS class:

.choice.eliminated {
  text-decoration: line-through;
  opacity: 0.5;
}

4. Toggle Behavior

Clicking a choice toggles its elimination state:

// First click: eliminate
choiceElement.classList.add('eliminated');

// Second click: restore
choiceElement.classList.remove('eliminated');

Cleanup

The ElementToolStateStore provides cleanup methods:

// Clear state for a specific element
store.clearElement('demo:section-1:question-1:mc1');

// Clear all answer eliminator state across all elements
store.clearTool('answerEliminator');

// Clear all elements in a section
store.clearSection('demo', 'section-1');

// Clear all state
store.clearAll();

TypeScript Support

Full TypeScript definitions included:

import type { IElementToolStateStore } from '@pie-players/pie-assessment-toolkit';

interface AnswerEliminatorState {
  eliminatedChoices: string[];
}

Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+

Requires ES2020+ support (native ES modules, optional chaining, nullish coalescing).

Examples

See the section-demos for complete examples:

  • Three Questions Demo: Element-level answer eliminator with state persistence
  • Paired Passages Demo: Multi-section assessment with cross-section state

Related Documentation

License

MIT