-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathbuild.ts
More file actions
executable file
·61 lines (54 loc) · 1.66 KB
/
build.ts
File metadata and controls
executable file
·61 lines (54 loc) · 1.66 KB
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
#!/usr/bin/env -S deno run --allow-write
import {
type ColorFormat,
type Colors,
flavorEntries,
} from "https://deno.land/x/catppuccin@v1.7.1/mod.ts";
import plist from "https://esm.sh/v135/plist@3.1.0";
type ITermColor = {
"Red Component": number;
"Green Component": number;
"Blue Component": number;
"Alpha Component": number;
"Color Space": "sRGB";
};
function toItermColor(rgb: ColorFormat["rgb"]): ITermColor {
const [red, green, blue] = [rgb.r, rgb.g, rgb.b].map((v) => v / 255);
return {
"Red Component": red,
"Green Component": green,
"Blue Component": blue,
"Alpha Component": 1.0,
"Color Space": "sRGB",
};
}
for (const [flavorIdentifier, flavor] of flavorEntries) {
const ansiColors = Object.fromEntries(
flavor.ansiColorEntries
.flatMap(([_, { normal, bright }]) => [normal, bright])
.toSorted((a, b) => a.code - b.code)
.map(({ code, rgb }) => [`Ansi ${code} Color`, toItermColor(rgb)]),
);
const colors = flavor.colorEntries.reduce((acc, [colorIdentifier, color]) => {
return {
[colorIdentifier]: toItermColor(color.rgb),
...acc,
};
}, {} as Colors<ITermColor>);
const mappings = {
...ansiColors,
"Background Color": colors.base,
"Foreground Color": colors.text,
"Link Color": colors.sky,
"Bold Color": colors.text,
"Cursor Color": colors.rosewater,
"Cursor Text Color": colors.base,
"Cursor Guide Color": { ...colors.text, "Alpha Component": 0.07 },
"Selection Color": colors.surface2,
"Selected Text Color": colors.text,
};
Deno.writeTextFileSync(
`./colors/catppuccin-${flavorIdentifier}.itermcolors`,
plist.build(mappings),
);
}