-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.ts
63 lines (55 loc) · 1.51 KB
/
index.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
import { variants } from "@catppuccin/palette";
import type {
CatppuccinFlavor,
CatppuccinPalette,
ThemeContext,
ThemeOptions,
} from "@/types";
import { getTokenColors } from "./tokenColors";
import { getSemanticTokens } from "./semanticTokens";
import { getUiColors } from "./uiColors";
import { capitalize } from "./utils";
export const defaultOptions: ThemeOptions = {
accent: "mauve",
boldKeywords: true,
italicComments: true,
italicKeywords: true,
colorOverrides: {},
workbenchMode: "default",
bracketMode: "rainbow",
extraBordersEnabled: false,
customUIColors: {},
};
export const compileTheme = (
flavor: CatppuccinFlavor = "mocha",
options: ThemeOptions = defaultOptions,
) => {
const ctpPalette = Object.entries(variants[flavor])
.map(([k, v]) => {
return {
[k as unknown as any]: v["hex"],
name: flavor,
};
})
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
const palette: CatppuccinPalette = {
...(ctpPalette as CatppuccinPalette),
...options.colorOverrides?.all,
...options.colorOverrides?.[flavor],
};
const context: ThemeContext = {
palette,
options,
isLatte: flavor === "latte",
};
const flavourName = `Catppuccin ${capitalize(flavor)}`;
const theme = {
name: flavourName,
type: context.isLatte ? "light" : "dark",
colors: getUiColors(context),
semanticHighlighting: true,
semanticTokenColors: getSemanticTokens(context),
tokenColors: getTokenColors(context),
};
return theme;
};