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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bjornlu/colorblind

v1.0.3

Published

Simulate color blindness

Downloads

272

Readme

Colorblind

package version npm downloads

A zero-dependencies color blindness simulation library.

It is based on the color blindness simulation research and its Processing library by hx2A.

Demo

Install

$ npm install @bjornlu/colorblind

or with CDN for direct browser usage, such as:

<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@bjornlu/colorblind"></script>

<!-- unpkg -->
<script src="https://unpkg.com/@bjornlu/colorblind>"></script>

The CDN version sets a global colorblind object, e.g. colorblind.simulate(...).

Usage

import { simulate } from '@bjornlu/colorblind'

simulate({ r: 120, g: 50, b: 30 }, 'protanopia')
// => { r: 62, g: 62, b: 30 }

The color deficiency can be set to:

| Deficiency | Description | | ----------------- | ----------- | | 'protanopia' | No red | | 'deuteranopia' | No green | | 'tritanopia' | No blue | | 'achromatopsia' | No color |

Advanced

The library also exports two functions:

  1. simulateDichromatic(rgb: RGB, simMatrix: Array<number>): RGB
  2. simulateMonochromatic(rgb: RGB, simMatrix: Array<number>): RGB

You would almost never used this unless you need to perform custom color simulation.

simulateDichromatic() accepts a simulation matrix represented as an array of 9 numbers, while simulateMonochromatic() accepts array of 3 numbers.

Check out the research for how to calculate simulation matrices.

Additional Notes

  • The library makes no assumption of the color's gamma, hence gamma correction must be applied or removed manually where needed.
  • The algorithm does not use daltonization to calculate the result values.

Contributing

PRs are welcomed for any typos or documentation issues. Edits on the simulation algorithm must be backed up with research and is preferred to be discussed in an issue first.

Prior Research

The library was actually planned to be a rewrite of color-blind to remove the onecolor dependency and to add typings. In the process of understanding how the code works, I found that the original reference was outdated and has a newer version.

I also found out about the LMS version of the daltonize implementation, which happens to be the same technique used in the color blindness simulation research. The only difference was the simulation matrix used for the color deficiencies and its post color correction calculations.

I finally decided to follow the algorithm from the research since it's the only source I found that backs up how the values were calculated. So this means that this library does not use daltonization to calculate the colors.

Since I'm no expert in this field, I would highly appreciate validation on the implementation and whether daltonization would be the better choice.

License

MIT