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

@allystudio/color-vision-simulator

v0.1.0

Published

Color vision deficiency simulator for accessibility testing and design

Readme

@allystudio/color-vision-simulator

A JavaScript library for simulating color vision deficiencies (color blindness) on web pages. Useful for accessibility testing, design validation, and educational purposes.

Features

  • 🎨 Multiple Color Vision Types: Protanopia, Deuteranopia, Tritanopia, Achromatopsia
  • High Performance: Direct HTML filter application with overlay fallback
  • 🔧 Configurable: Customizable overlay IDs, z-index, and behavior
  • 📱 Event-Driven: Subscribe to state changes with callback system
  • 🧹 Clean API: Simple functional interface with closure-based state management
  • 🧪 Well Tested: Comprehensive test suite with browser testing
  • 📦 Zero Dependencies: Lightweight and self-contained

Installation

npm install @allystudio/color-vision-simulator

Quick Start

import { createColorVisionSimulator, COLOR_VISION_PRESETS } from '@allystudio/color-vision-simulator'

// Create a simulator instance
const simulator = createColorVisionSimulator()

// Start simulating protanopia (red-blindness)
simulator.start()

// Change to deuteranopia (green-blindness)
simulator.setVisionType(COLOR_VISION_PRESETS.DEUTERANOPIA)

// Stop simulation
simulator.stop()

API Reference

createColorVisionSimulator

Factory Function

createColorVisionSimulator(options?: SimulatorOptions): ColorVisionSimulator

Options

interface SimulatorOptions {
  overlayId?: string          // Custom overlay ID (default: "color-vision-simulator-overlay")
  stylesId?: string           // Custom styles ID (default: "color-vision-simulator-styles")
  zIndex?: number             // Custom z-index (default: 2147483647)
  useDirectFilter?: boolean   // Use direct HTML filter (default: true)
}

Methods

State Management
// Start the simulation
simulator.start(): void

// Stop the simulation
simulator.stop(): void

// Toggle simulation on/off
simulator.toggle(): void

// Set vision type
simulator.setVisionType(type: ColorVisionType): void

// Configure both vision type and active state
simulator.configure(visionType: ColorVisionType, isActive: boolean): void
State Queries
// Get current state
simulator.getState(): SimulatorState

// Check if active
simulator.isActive(): boolean

// Get current vision type
simulator.getVisionType(): ColorVisionType
Event Handling
// Subscribe to state changes
const unsubscribe = simulator.onStateChange((state) => {
  console.log('State changed:', state)
})

// Unsubscribe
unsubscribe()

Vision Types

type ColorVisionType = 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia' | 'normal'

// Presets for convenience
const COLOR_VISION_PRESETS = {
  PROTANOPIA: 'protanopia' as const,      // Red-blindness
  DEUTERANOPIA: 'deuteranopia' as const,  // Green-blindness
  TRITANOPIA: 'tritanopia' as const,      // Blue-blindness
  ACHROMATOPSIA: 'achromatopsia' as const, // Total color blindness
  NORMAL: 'normal' as const               // Normal vision (no simulation)
}

Utility Functions

import {
  createColorVisionSimulator,
  formatColorVisionType,
  getColorVisionDescription
} from '@allystudio/color-vision-simulator'

// Create a new instance
const simulator = createColorVisionSimulator(options)

// Format vision type for display
const displayName = formatColorVisionType('protanopia') // "Protanopia"

// Get description of vision type
const description = getColorVisionDescription('protanopia')
// "Difficulty distinguishing between red and green colors, with red appearing darker"

Examples

Basic Usage

import { createColorVisionSimulator, COLOR_VISION_PRESETS } from '@allystudio/color-vision-simulator'

const simulator = createColorVisionSimulator()

// Simulate protanopia
simulator.setVisionType(COLOR_VISION_PRESETS.PROTANOPIA)
simulator.start()

// Later...
simulator.stop()

With State Change Monitoring

const simulator = createColorVisionSimulator()

// Monitor state changes
simulator.onStateChange((state) => {
  console.log(`Simulation ${state.isActive ? 'started' : 'stopped'}`)
  console.log(`Vision type: ${state.visionType}`)
})

simulator.start()
simulator.setVisionType(COLOR_VISION_PRESETS.DEUTERANOPIA)
simulator.stop()

Custom Configuration

const simulator = createColorVisionSimulator({
  overlayId: 'my-color-overlay',
  stylesId: 'my-color-styles',
  zIndex: 999999,
  useDirectFilter: false  // Disable direct HTML filtering
})

Using Utility Functions

import { formatColorVisionType, getColorVisionDescription } from '@allystudio/color-vision-simulator'

// Format for UI display
const displayName = formatColorVisionType('protanopia') // "Protanopia"

// Get user-friendly description
const description = getColorVisionDescription('deuteranopia')
// "Difficulty distinguishing between red and green colors, with green appearing darker"

// Use in UI components
function VisionTypeSelector({ currentType, onChange }) {
  const types = ['protanopia', 'deuteranopia', 'tritanopia', 'achromatopsia', 'normal']

  return (
    <select value={currentType} onChange={(e) => onChange(e.target.value)}>
      {types.map(type => (
        <option key={type} value={type}>
          {formatColorVisionType(type)}
        </option>
      ))}
    </select>
  )
}

React Integration

import { useEffect, useState } from 'react'
import {
  createColorVisionSimulator,
  COLOR_VISION_PRESETS,
  formatColorVisionType,
  type ColorVisionType
} from '@allystudio/color-vision-simulator'

function ColorVisionControls() {
  const [simulator] = useState(() => createColorVisionSimulator())
  const [isActive, setIsActive] = useState(false)
  const [visionType, setVisionType] = useState<ColorVisionType>('protanopia')

  useEffect(() => {
    const unsubscribe = simulator.onStateChange((state) => {
      setIsActive(state.isActive)
      setVisionType(state.visionType)
    })

    return unsubscribe
  }, [simulator])

  const visionTypes: ColorVisionType[] = [
    'protanopia', 'deuteranopia', 'tritanopia', 'achromatopsia', 'normal'
  ]

  return (
    <div>
      <button onClick={() => simulator.toggle()}>
        {isActive ? 'Stop' : 'Start'} Simulation
      </button>

      <select
        value={visionType}
        onChange={(e) => simulator.setVisionType(e.target.value as ColorVisionType)}
      >
        {visionTypes.map(type => (
          <option key={type} value={type}>
            {formatColorVisionType(type)}
          </option>
        ))}
      </select>
    </div>
  )
}

How It Works

The simulator uses CSS filters to modify the visual appearance of web pages:

  1. Color Matrix Filters: For protanopia, deuteranopia, and tritanopia, scientifically accurate color transformation matrices are applied
  2. Grayscale Filter: For achromatopsia (total color blindness)
  3. Direct HTML Filtering: For better performance, filters are applied directly to the <html> element when possible
  4. Overlay Fallback: When direct filtering isn't suitable, a full-screen overlay with the filter is used

Browser Support

  • Chrome/Edge: Full support
  • Firefox: Full support
  • Safari: Full support
  • Mobile browsers: Full support

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.

License

MIT License - see LICENSE file for details.

Related Packages

  • @allystudio/accessibility-utils - Accessibility analysis utilities
  • @allystudio/element-inspector - DOM element inspection tools