Files
cinny/src/app/plugins/color.ts
T

17 lines
466 B
TypeScript
Raw Normal View History

import chroma from 'chroma-js';
import { ThemeKind } from '../hooks/useTheme';
export const accessibleColor = (themeKind: ThemeKind, color: string): string => {
if (!chroma.valid(color)) return color;
let lightness = chroma(color).lab()[0];
if (themeKind === ThemeKind.Dark && lightness < 60) {
lightness = 60;
}
if (themeKind === ThemeKind.Light && lightness > 50) {
lightness = 50;
}
return chroma(color).set('lab.l', lightness).hex();
};