@bjornlu/colorblind

中文文档
1.0.3发布于 2020/10/22MITTypeScriptESM + CJS零依赖近 30 天下载 3582

Simulate color blindness

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Advanced
  4. Additional Notes
  5. Contributing
  6. Prior Research
  7. License

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:

DeficiencyDescription
'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

版本与发布记录

@bjornlu/colorblind 共发布 4 个版本,首次发布于 2020/06/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.3latest2020/10/226 年前
1.0.22020/07/286 年前
1.0.12020/07/026 年前
1.0.02020/06/286 年前

关于 @bjornlu/colorblind 的常见问题

@bjornlu/colorblind 是什么?

Simulate color blindness

如何安装 @bjornlu/colorblind?

在项目目录运行 npm install @bjornlu/colorblind,或使用 pnpm add / yarn add / bun add。

@bjornlu/colorblind 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bjornlu/colorblind 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bjornlu/colorblind 可以商用吗?

@bjornlu/colorblind 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bjornlu/colorblind 的下载量有多少?

根据 npm 官方下载统计,@bjornlu/colorblind 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,582 次,日均约 119 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bjornlu/colorblind 还在维护吗?

最新版本 1.0.3 发布于 2020/10/22(6 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。