-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.py
68 lines (57 loc) · 2.12 KB
/
build.py
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
#!/usr/bin/env python
from typing import Tuple, Dict, Union
import json
import plistlib
import operator
from functools import reduce
from pathlib import Path
NAME = "everforest"
VARIANTS = ["light", "dark"]
CONTRASTS = ["hard", "medium", "low"]
OUT_DIR = "themes"
THEME_FILE = "theme.json"
PALETTE_FILE = "palette.json"
def get_color_components(hex: str) -> Tuple[float, float, float]:
return tuple(int(hex[i + 1 : i + 3], 16) / 255 for i in (0, 2, 4))
def get_color_dict(
components: Tuple[float, float, float]
) -> Dict[str, Union[str, float]]:
return {
"Color Space": "sRGB",
"Red Component": components[0],
"Green Component": components[1],
"Blue Component": components[2],
"Alpha Component": 1.0,
}
if __name__ == "__main__":
with open(THEME_FILE) as f:
theme = json.load(f)
with open(PALETTE_FILE) as f:
palette = json.load(f)
out_dir = Path(OUT_DIR)
out_dir.mkdir(exist_ok=True)
for variant in VARIANTS:
for contrast in CONTRASTS:
file_name = f"{NAME}_{variant}_{contrast}.itermcolors"
file_path = out_dir / file_name
content = theme.copy()
for name, slug in content.items():
color_dictionary = {}
if slug.stratswith("#"):
color_dictionary = get_color_dict(get_color_components(slug))
elif "." in slug:
color_dictionary = get_color_dict(
get_color_components(
reduce(operator.getitem, slug.split("."), palette)
)
)
else:
path = f"{variant}.{'background.' + contrast if slug.startswith('bg') else 'foreground'}.{slug}"
color_dictionary = get_color_dict(
get_color_components(
reduce(operator.getitem, path.split("."), palette)
)
)
content[name] = color_dictionary
with open(file_path, "wb") as f:
plistlib.dump(content, f)