generated from kawarimidoll/deno-dev-template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
color_scheme.ts
77 lines (67 loc) · 3.22 KB
/
color_scheme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { hexStrToHexNum } from "./utils.ts";
import {
CONTRIBUTION_LEVELS,
ContributionLevelName,
isValidContributionLevelName,
} from "./contributions.ts";
const COLOR_SCHEMES = {
// by [williambelle/github-contribution-color-graph](https://github.com/williambelle/github-contribution-color-graph)
github: ["#eeeeee", "#9be9a8", "#40c463", "#30a14e", "#216e39"],
halloween: ["#eeeeee", "#fdf156", "#ffc722", "#ff9711", "#04001b"],
amber: ["#eeeeee", "#ffecb3", "#ffd54f", "#ffb300", "#ff6f00"],
blue: ["#eeeeee", "#bbdefb", "#64b5f6", "#1e88e5", "#0d47a1"],
bluegrey: ["#eeeeee", "#cfd8dc", "#90a4ae", "#546e7a", "#263238"],
brown: ["#eeeeee", "#d7ccc8", "#a1887f", "#6d4c41", "#3e2723"],
cyan: ["#eeeeee", "#b2ebf2", "#4dd0e1", "#00acc1", "#006064"],
deeporange: ["#eeeeee", "#ffccbc", "#ff8a65", "#f4511e", "#bf360c"],
deeppurple: ["#eeeeee", "#d1c4e9", "#9575cd", "#5e35b1", "#311b92"],
green: ["#eeeeee", "#c8e6c9", "#81c784", "#43a047", "#1b5e20"],
grey: ["#eeeeee", "#e0e0e0", "#9e9e9e", "#616161", "#212121"],
indigo: ["#eeeeee", "#c5cae9", "#7986cb", "#3949ab", "#1a237e"],
lightblue: ["#eeeeee", "#b3e5fc", "#4fc3f7", "#039be5", "#01579b"],
lightgreen: ["#eeeeee", "#dcedc8", "#aed581", "#7cb342", "#33691e"],
lime: ["#eeeeee", "#f0f4c3", "#dce775", "#c0ca33", "#827717"],
orange: ["#eeeeee", "#ffe0b2", "#ffb74d", "#fb8c00", "#e65100"],
pink: ["#eeeeee", "#f8bbd0", "#f06292", "#e91e63", "#880e4f"],
purple: ["#eeeeee", "#e1bee7", "#ba68c8", "#8e24aa", "#4a148c"],
red: ["#eeeeee", "#ffcdd2", "#e57373", "#e53935", "#b71c1c"],
teal: ["#eeeeee", "#b2dfdb", "#4db6ac", "#00897b", "#004d40"],
yellowMd: ["#eeeeee", "#fff9c4", "#fff176", "#ffd835", "#f57f17"],
unicorn: ["#eeeeee", "#6dc5fb", "#f6f68c", "#8affa4", "#f283d1"],
summer: ["#eeeeee", "#eae374", "#f9d62e", "#fc913a", "#ff4e50"],
sunset: ["#eeeeee", "#fed800", "#ff6f01", "#fd2f24", "#811d5e"],
moon: ["#eeeeee", "#6bcdff", "#00a1f3", "#48009a", "#4f2266"],
psychedelic: ["#eeeeee", "#faafe1", "#fb6dcc", "#fa3fbc", "#ff00ab"],
yellow: ["#eeeeee", "#d7d7a2", "#d4d462", "#e0e03f", "#ffff00"],
// by kawarimidoll
gameboy: ["#eeeeee", "#ccdc5f", "#91a633", "#606520", "#2c370b"],
};
type ColorSchemeName = keyof typeof COLOR_SCHEMES;
const isValidColorSchemeName = (name?: string): name is ColorSchemeName =>
!!name && Object.hasOwn(COLOR_SCHEMES, name);
const randomColorScheme = () => {
const values = Object.values(COLOR_SCHEMES);
return values[(Math.random() * values.length) << 0];
};
const getColorScheme = (name = "github") => {
if (name != "random" && !isValidColorSchemeName(name)) {
throw new Error(
`'${name}' is invalid color scheme name! Choose from: ${
Object.keys(COLOR_SCHEMES)
},random`,
);
}
const hexStrColors = name === "random"
? randomColorScheme()
: COLOR_SCHEMES[name];
const hexNumColors = hexStrColors.map((color) => hexStrToHexNum(color));
const getByLevel = (levelName?: ContributionLevelName) =>
hexNumColors[
isValidContributionLevelName(levelName)
? CONTRIBUTION_LEVELS[levelName]
: 0
];
return { hexStrColors, hexNumColors, getByLevel };
};
export { COLOR_SCHEMES, getColorScheme, isValidColorSchemeName };
export type { ColorSchemeName };