this repo has no description
1import tinycolor from "tinycolor2";
2
3export function ensureReadable(background: string, foregroundWish: string) {
4 const bg = tinycolor(background);
5 const fg = tinycolor(foregroundWish);
6
7 if (tinycolor.isReadable(bg, fg)) {
8 return fg.toHexString();
9 }
10
11 return bg.isLight() ? "#000000" : "#ffffff";
12}
13
14export function setCssColors(
15 colors:
16 | {
17 primary: string;
18 secondary: string;
19 tertiary: string;
20 }
21 | undefined
22 | null,
23) {
24 colors = {
25 primary: colors?.primary || "#000000",
26 secondary: colors?.secondary || "#ffffff",
27 tertiary: colors?.tertiary || "#ffffff",
28 };
29
30 return colors
31 ? `
32 --primary: ${ensureReadable(colors.secondary, colors.primary)};
33 --secondary: ${colors.secondary};
34 --tertiary: ${colors.tertiary};`
35 : undefined;
36}