-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
mod.ts
327 lines (284 loc) · 5.54 KB
/
mod.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import definitions from "./palette.json" with { type: "json" };
type Entries<T> = {
[K in keyof T]: [K, T[K]];
}[keyof T][];
const entriesFromObject = <T extends object>(obj: T): Entries<T> =>
Object.entries(obj) as Entries<T>;
/**
* All flavor names of Catppuccin.
*/
export type FlavorName = "latte" | "frappe" | "macchiato" | "mocha";
/**
* Accent colors of Catppuccin.
*/
export type AccentName =
| "rosewater"
| "flamingo"
| "pink"
| "mauve"
| "red"
| "maroon"
| "peach"
| "yellow"
| "green"
| "teal"
| "sky"
| "sapphire"
| "blue"
| "lavender";
/**
* Monochromatic colors of Catppuccin,
* from `text` to `crust`
*/
export type MonochromaticName =
| "text"
| "subtext1"
| "subtext0"
| "overlay2"
| "overlay1"
| "overlay0"
| "surface2"
| "surface1"
| "surface0"
| "base"
| "mantle"
| "crust";
type AnsiName =
| "black"
| "red"
| "green"
| "yellow"
| "blue"
| "magenta"
| "cyan"
| "white";
/**
* All color names of Catppuccin.
*/
export type ColorName = AccentName | MonochromaticName;
/**
* Generic to map type T to all Catppuccin color names.
*/
export type Colors<T> = Record<ColorName, T>;
/**
* Generic to map type T to all ANSI color names.
*/
export type AnsiColors<T> = Record<AnsiName, T>;
/**
* A flavor of Catppuccin.
*/
export type CatppuccinFlavor = Readonly<{
/**
* Name of the flavor.
*/
name: string;
/**
* Emoji associated with the flavor. Requires Unicode 13.0 (2020) or later to render.
*/
emoji: string;
/**
* Order of the flavor in the palette spec.
*/
order: number;
/**
* Whether the flavor is a dark theme.
*/
dark: boolean;
/**
* An object containing all the colors of the flavor.
*/
colors: CatppuccinColors;
/**
* An object containing all the ANSI color mappings of the flavor.
*/
ansiColors: CatppuccinAnsiColors;
/**
* A typed Object.entries iterable of the colors of the flavor.
*/
colorEntries: Entries<CatppuccinColors>;
/**
* A typed Object.entries iterable of the ANSI colors of the flavor.
*/
ansiColorEntries: Entries<CatppuccinAnsiColors>;
}>;
/**
* All colors of Catppuccin.
*/
export type CatppuccinColors = Readonly<Colors<ColorFormat>>;
/**
* All ANSI color mappings of Catppuccin.
*/
export type CatppuccinAnsiColors = Readonly<AnsiColors<AnsiColorGroups>>;
/**
* All flavors of Catppuccin.
*/
export type CatppuccinFlavors = Flavors<CatppuccinFlavor>;
export type Flavors<T> = {
/**
* Light variant.
*/
latte: T;
/**
* Low-saturation, low-contrast dark variant.
*/
frappe: T;
/**
* Mid-saturation, mid-contrast dark variant.
*/
macchiato: T;
/**
* High-saturation, High-contrast dark variant.
*/
mocha: T;
};
export type ColorFormat = Readonly<{
/**
* Name of the color.
*/
name: string;
/**
* Order of the color in the palette spec.
*/
order: number;
/**
* String-formatted hex value.
* @example "#babbf1"
*/
hex: string;
/**
* Formatted rgb value.
* @example { r: 186, g: 187, b: 241}
*/
rgb: {
/**
* Red, 0-255
*/
r: number;
/**
* Green, 0-255
*/
g: number;
/**
* Blue, 0-255
*/
b: number;
};
/**
* Formatted hsl value.
* @example { h: 238.9, s: 12.1, l: 83.5 }
*/
hsl: {
/**
* Hue, 0-360
*/
h: number;
/**
* Saturation, 0-100
*/
s: number;
/**
* Lightness, 0-100
*/
l: number;
};
/**
* Indicates whether the color is intended to be used as an accent color.
*/
accent: boolean;
}>;
export type AnsiColorGroups = Readonly<{
/**
* Name of the ANSI color.
*/
name: string;
/**
* Order of the ANSI color in the palette spec.
*/
order: number;
/**
* An object containing all the ANSI "normal" colors, which are the 8 standard colors from 0 to 7.
*/
normal: AnsiColorFormat;
/**
* An object containing all the ANSI "bright" colors, which are the 8 standard colors from 8 to 15.
*
* Note: These bright colors are not necessarily "brighter" than the normal colors, but rather more bold and saturated.
*/
bright: AnsiColorFormat;
}>;
export type AnsiColorFormat = Readonly<{
/**
* Name of the ANSI group.
*/
name: string;
/**
* String-formatted hex value.
* @example "#babbf1"
*/
hex: string;
/**
* Formatted rgb value.
* @example { r: 186, g: 187, b: 241}
*/
rgb: {
/**
* Red, 0-255
*/
r: number;
/**
* Green, 0-255
*/
g: number;
/**
* Blue, 0-255
*/
b: number;
};
/**
* Formatted hsl value.
* @example { h: 238.9, s: 12.1, l: 83.5 }
*/
hsl: {
/**
* Hue, 0-360
*/
h: number;
/**
* Saturation, 0-100
*/
s: number;
/**
* Lightness, 0-100
*/
l: number;
};
/**
* The ANSI color code.
* @example 4
*/
code: number;
}>;
const { version: _, ...jsonFlavors } = definitions;
/**
* The version of the Catppuccin palette.
*/
export const version = definitions.version;
/**
* All flavors of Catppuccin.
*/
export const flavors: CatppuccinFlavors = entriesFromObject(
jsonFlavors,
).reduce((acc, [flavorName, flavor]) => {
acc[flavorName] = {
...flavor,
colorEntries: entriesFromObject(flavor.colors),
ansiColorEntries: entriesFromObject(flavor.ansiColors),
};
return acc;
}, {} as CatppuccinFlavors);
/**
* A typed `Object.entries()` iterable of all Catppuccin flavors.
*/
export const flavorEntries: Entries<CatppuccinFlavors> = entriesFromObject(
flavors,
);