in src/utils/utils.js [68:93]
export function colorFromBackground(backgroundColor, contrastRatio = 2.4) {
let color;
const lightColor = rgbFromHex('#FFFFFF');
const darkColor = rgbFromHex('#18171d');
if (backgroundColor.startsWith('#')) {
color = rgbFromHex(backgroundColor);
} else if (backgroundColor.startsWith('rgba(')) {
color = rgbFromString(backgroundColor, 5);
} else if (backgroundColor.startsWith('rgb(')) {
color = rgbFromString(backgroundColor, 4);
}
const luminance = relativeLuminance(color);
const lightLuminance = relativeLuminance(lightColor);
const darkLuminance = relativeLuminance(darkColor);
const contrastLight = (lightLuminance + 0.05) / (luminance + 0.05);
const contrastDark = (luminance + 0.05) / (darkLuminance + 0.05);
// Using a default threshold contrast of 2.4 instead of 3
// as this will solve weird color combinations in the mid tones
return contrastLight >= contrastRatio || contrastLight > contrastDark
? labelColorOptions.light
: labelColorOptions.dark;
}