# color-diff

> Implemets the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest or most different color in palette Y based on the CIEDE2000 difference.

Latest version **1.4.0** (published 2023-05-31) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install color-diff
pnpm add color-diff
yarn add color-diff
bun add color-diff
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2023-05-31 |
| First published | 2013-06-17 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/color-diff) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 46.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 370 |
| Author | markusn kael |
| Maintainers | markusn |
| Keywords | color, diff, color-diff, pallette, closest, convert, conversion, CIEDE2000, ciede2000 |

## Links

- npm: https://www.npmjs.com/package/color-diff
- Repository: https://github.com/markusn/color-diff
- Homepage: https://github.com/markusn/color-diff#readme
- Issues: https://github.com/markusn/color-diff/issues
- npm.io page: https://npm.io/package/color-diff

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.4.0 (latest) — 2023-05-31
- 1.4.0-beta.2 (beta) — 2023-05-31
- 1.4.0-beta.1 — 2023-05-31
- 1.3.0 — 2023-04-26
- 1.2.0 — 2020-03-22
- 1.1.0 — 2017-05-15
- 1.0.0 — 2016-02-20
- 0.1.7 — 2015-02-20
- 0.1.6 — 2015-01-29
- 0.1.5 — 2014-09-20
- 0.1.4 — 2014-08-27
- 0.1.3 — 2013-12-10
- 0.1.2 — 2013-09-26
- 0.1.1 — 2013-06-17
- 0.1.0 — 2013-06-17

## README

# color-diff

[![Build Status](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml/badge.svg?branch=master)](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml)
[![Coverage Status](https://coveralls.io/repos/markusn/color-diff/badge.png?branch=master)](https://coveralls.io/r/markusn/color-diff?branch=master)

Implements the CIEDE2000 color difference algorithm, conversion between RGB and
LAB color and mapping all colors in palette X to the closest color in palette Y
based on the CIEDE2000 difference.

## Installation

```bash
npm install color-diff --save
```

## Tests

Are located in the `test/` folder and are run by:

```bash
npm test
```

## Usage

```js
// CommonJS
const { 
  closest, 
  furthest,
  diff, 
  mapPalette,
  paletteMapKey,
  rgbaToLab,
  mapPaletteLab,
  labPaletteMapKey,
} = require("color-diff");

// ESM
import {
  closest,
  furthest,
  diff,
  mapPalette,
  paletteMapKey,
  rgbaToLab,
  mapPaletteLab,
  labPaletteMapKey,
} from "color-diff";
```

### closest(color, palette, bc)

Returns the closest color. The parameter bc is optional and is used as
background color when the color and/or palette uses alpha channels.

```js
const color = { R: 255, G: 1, B: 30 };
// red, green, blue
const palette = [ {R: 255, G: 0, B: 0 },
                {R: 0, G: 255, B: 0 },
                {R: 0, G: 0, B: 255} ];

closest(color, palette); // {R: 255, G: 0, B: 0 }, red
```

The result above is obvious, but `diff.closest` could deal with more complicated
cases.

### furthest(color, palette, bc)

Returns the most different color. The parameter bc is optional and is used as
background color when the color and/or palette uses alpha channels.

```js
const color = { R: 255, G: 255, B: 255 };
// black, white
const palette = [ {R: 0, G: 0, B: 0 }, {R: 255, G: 255, B: 255 } ];

furthest(color, palette); // {R: 0, G: 0, B: 0 }, black
```

The result above is obvious, but `diff.furthest` could deal with more
complicated cases.

### mapPalette(palette1, palette2)

Returns a mapping from the colors in palette1 to palette2.

### paletteMapKey(color)

Return the palette map key for the color, to be used with the result from mapPalette.

### diff(color1, color2, bc)

Returns the difference between the lab colors color1 and color2. The parameter bc is optional and
is used as background color when one of the colors uses alpha channels.

#### rgba color

`Object`

`RGBAColor` is an object containing 4 properties: 'R', 'G', 'B', 'A', where 'A' is optional OR
'r', 'g', 'b', 'a', where 'a' is optional . Such as:

```js
{ R: 255, G: 1, B: 0 }
```

There is an optional property 'A', which specifies the alpha channel between 0.0
and 1.0. If not present the color will be treated as fully opaque, i.e. A = 1.0.

Each RGBA-color is transformed into a RGB-color before being used to calculate
the CIEDE2000 difference, using the specified background color
(defaults to white).

### lab color

`Object`

`LabColor` is an object containing 3 properties 'L', 'a', 'b' such as:

```js
{ L: 100, a: 0.005, b: -0.010 }
```

#### palette

`Array.<RGBAColor>`

Color palette array which contains many `RGBAColor` objects.

## Author

Markus Ekholm

## License

3-clause BSD. For details see `COPYING`.

---
_Source: https://npm.io/package/color-diff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
