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/diopter-simulator

v0.1.0

Published

Visual acuity and refractive error simulator for accessibility testing and design

Readme

Diopter Simulator

A JavaScript library for simulating visual impairments caused by refractive errors (nearsightedness, farsightedness) by applying realistic blur effects to web elements.

Features

  • 🔬 Scientific Accuracy: Real diopter calculations with viewing distance effects
  • High Performance: CSS filter-based blur rendering
  • 🧹 Clean API: Simple functional interface with closure-based state
  • 📱 Viewing Distance: Realistic simulation for different devices (phone, laptop, TV)
  • 🧪 Well Tested: Comprehensive test suite with 94%+ coverage
  • 📦 Zero Dependencies: Lightweight and self-contained

Installation

npm install @allystudio/diopter-simulator

Quick Start

import { createDiopterSimulator } from '@allystudio/diopter-simulator'

const simulator = createDiopterSimulator()

// Simulate -3.0 diopters (moderate myopia) at laptop distance
simulator.configure(-3.0, 0.6)
simulator.applyToElement(document.body)

// Remove simulation
simulator.reset()

API

createDiopterSimulator()

Creates a new simulator instance.

const simulator = createDiopterSimulator()

Configuration Methods

setDiopters(value: number)

Set diopter strength (-8 to +8 range):

  • Negative values: Myopia (nearsightedness) - distant objects blurry
  • Positive values: Hyperopia (farsightedness) - close objects blurry
  • Zero: No refractive error

setViewingDistance(meters: number)

Set viewing distance in meters (0.2 to 4.0 range):

  • 0.3m: Phone/tablet distance
  • 0.6m: Laptop/desktop distance
  • 2.0m: TV viewing distance

configure(diopters: number, viewingDistance: number)

Set both values at once.

Simulation Methods

applyToElement(element: HTMLElement)

Apply blur effect to specified element and all children.

applyToPage()

Apply blur effect to entire page (document.body).

reset()

Remove all blur effects and reset state.

State Methods

isActive(): boolean

Check if simulation is currently active.

getCurrentConfig()

Get current diopter and viewing distance values.

Presets

Diopter Presets

import { DIOPTER_PRESETS } from '@allystudio/diopter-simulator'

// Common prescription strengths
DIOPTER_PRESETS.MILD_MYOPIA        // -1.5
DIOPTER_PRESETS.MODERATE_MYOPIA    // -3.0
DIOPTER_PRESETS.SEVERE_MYOPIA      // -6.0
DIOPTER_PRESETS.MILD_HYPEROPIA     // +1.5
DIOPTER_PRESETS.MODERATE_HYPEROPIA // +3.0

Viewing Distance Presets

import { VIEWING_DISTANCE_PRESETS } from '@allystudio/diopter-simulator'

VIEWING_DISTANCE_PRESETS.PHONE   // 0.3m
VIEWING_DISTANCE_PRESETS.LAPTOP  // 0.6m
VIEWING_DISTANCE_PRESETS.DESKTOP // 0.7m
VIEWING_DISTANCE_PRESETS.TV      // 2.0m

Examples

Testing Mobile App Accessibility

const simulator = createDiopterSimulator()

// Simulate user with -4D prescription using phone
simulator.configure(DIOPTER_PRESETS.MODERATE_MYOPIA, VIEWING_DISTANCE_PRESETS.PHONE)
simulator.applyToPage()

// Test if UI is still usable with blur
// Reset when done
simulator.reset()

Progressive Testing

const simulator = createDiopterSimulator()

// Test multiple prescription strengths
const testCases = [
  { diopters: -1.5, distance: 0.6, label: 'Mild myopia at laptop' },
  { diopters: -3.0, distance: 0.6, label: 'Moderate myopia at laptop' },
  { diopters: +2.0, distance: 0.3, label: 'Hyperopia reading phone' }
]

testCases.forEach(test => {
  simulator.configure(test.diopters, test.distance)
  simulator.applyToPage()
  console.log(`Testing: ${test.label}`)
  // Perform your accessibility tests here
  simulator.reset()
})

Dynamic Simulation

const simulator = createDiopterSimulator()

// Create interactive controls
const diopterSlider = document.getElementById('diopter-slider')
const distanceSlider = document.getElementById('distance-slider')

function updateSimulation() {
  const diopters = parseFloat(diopterSlider.value)
  const distance = parseFloat(distanceSlider.value)

  simulator.configure(diopters, distance)
  simulator.applyToPage()
}

diopterSlider.addEventListener('input', updateSimulation)
distanceSlider.addEventListener('input', updateSimulation)

Understanding Diopters

  • -1.5D: Mild myopia - slight blur at distance
  • -3.0D: Moderate myopia - significant blur beyond arm's length
  • -6.0D: Severe myopia - only close objects are clear
  • +1.5D: Mild hyperopia - slight difficulty with close work
  • +3.0D: Moderate hyperopia - reading and close tasks affected

Viewing Distance Impact

The same prescription affects vision differently at various distances:

  • Myopia: More blur at greater distances (TV > laptop > phone)
  • Hyperopia: More consistent blur, slightly worse up close

Browser Support

  • Modern browsers with CSS filter support
  • Chrome 53+, Firefox 35+, Safari 9.1+, Edge 12+

License

MIT License - see LICENSE file for details.