deltaEOK
deltaEOK measures the straight-line distance between two colors in OKLab. It uses the same metric Colore applies to find the closest color in a list or the closest CSS color name.
Example
import { colore } from 'colore-js';
import { deltaEOK } from 'colore-js/fn';
colore('#7c3aed').deltaEOK('#7b3ae8').toFixed(4); // '0.0078'
deltaEOK('#7c3aed', '#2563eb').toFixed(4); // '0.1239'
Syntax
colore(first).deltaEOK(second: ColorInput | Color): number
deltaEOK(first: ColorInput, second: ColorInput): number
Parameters
Returns
Both APIs return a nonnegative distance. Identical OKLab coordinates give zero regardless of opacity. This number uses OKLab units. Use deltaE when your threshold is specified in CIEDE2000.
Throws
A ColorError when an input cannot be parsed.
Rank possible replacements for a color
import { colore } from 'colore-js';
const target = colore('#7c3aed');
const candidates = ['#2563eb', '#7b3ae8'];
candidates.map((color) => target.deltaEOK(color).toFixed(4));
// ['0.1239', '0.0078']
The smaller distance identifies the closer match. Keep the numerical distances when you need to compare several candidates in a report. For the winning candidate alone, use nearest.
Related
- nearest to find the closest candidate directly
- deltaE for a CIEDE2000 threshold
- OKLCH in JavaScript to convert and edit perceptual color coordinates