Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findClosestColor( value, targetValues ) {
let closestValue = value;
let closestDistance = Infinity;
let targetValue;
for ( targetValue of targetValues ) {
const distance = chroma.distance( value, targetValue );
// This bit shortens existing variations of white to `#fff`
if ( distance === 0 ) {
closestValue = targetValue;
closestDistance = distance;
break;
}
// Unless white is explicitely used, let’s not convert darker colors to it
if ( targetValue === '#fff' ) {
continue;
}
if ( distance < closestDistance ) {
closestValue = targetValue;
closestDistance = distance;
forIn(PALETTE, (colorValue, colorName) => {
if (colorValue === color) {
closestColorName = colorName
closestColorValue = colorValue
return false
}
const colorDistance = chroma.distance(color, colorValue)
if (!isNumber(closestColorDistance) || closestColorDistance > colorDistance) {
closestColorDistance = colorDistance
closestColorName = colorName
closestColorValue = colorValue
}
})
function compareColor(a: string, b: string) {
const a0 = chroma(a);
const b0 = chroma(b);
const d: number = distance(a0, b0) as any;
return d === 0;
}
.map (function(name) {
name.distance = chroma.distance(color, chroma(name.hex))
return name
})
.sort (function(a, b) {