Skip to content

Commit a3f1eb5

Browse files
committed
Adjust catppuccin color mapping
1 parent 8ef3beb commit a3f1eb5

5 files changed

Lines changed: 302 additions & 240 deletions

File tree

‎src/color/catppuccin.ts‎

Lines changed: 184 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,74 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { type CatppuccinFlavor } from "@catppuccin/palette";
21-
import { rgba } from "polished";
20+
import type { CatppuccinFlavor } from "@catppuccin/palette";
21+
import { darken, lighten, rgba, saturate } from "polished";
2222
import { scaleColorLight } from "src/functions";
23-
import { themeVars, type Ansi, type Console, type Diff, type Other } from "src/types";
23+
import type { Ansi, Console, Diff, GitHub, Other } from "src/types";
24+
import { themeVars } from "src/types";
2425
import type { ThemeColor } from "./theme";
2526

2627
// 颜色映射标准: https://github.com/catppuccin/catppuccin/blob/main/docs/style-guide.md
2728
// 颜色映射参考: https://github.com/catppuccin/gitea/blob/main/src/_theme.scss
28-
export function catppuccin2ThemeColor(catppuccinFlavor: CatppuccinFlavor): ThemeColor {
29-
const brightDir = catppuccinFlavor.dark ? -1 : 1;
30-
const accentColor = catppuccinFlavor.colors.mauve.hex;
31-
const lv1Color = catppuccinFlavor.dark ? catppuccinFlavor.colors.crust.hex : catppuccinFlavor.colors.base.hex;
32-
const lv2Color = catppuccinFlavor.colors.mantle.hex;
33-
// const lv3Color = catppuccinFlavor.dark ? catppuccinFlavor.colors.base.hex : catppuccinFlavor.colors.crust.hex;
29+
export function catppuccin2ThemeColor(flavor: CatppuccinFlavor): ThemeColor {
30+
const brightDir = flavor.dark ? -1 : 1;
31+
const accentColor = flavor.colors.mauve.hex;
32+
const lv1Color = flavor.dark ? flavor.colors.crust.hex : flavor.colors.base.hex;
33+
const lv2Color = flavor.colors.mantle.hex;
34+
// const lv3Color = flavor.dark ? flavor.colors.base.hex : flavor.colors.crust.hex;
3435

3536
const ansi: Ansi = {
36-
black: catppuccinFlavor.ansiColors.black.normal.hex,
37-
red: catppuccinFlavor.ansiColors.red.normal.hex,
38-
green: catppuccinFlavor.ansiColors.green.normal.hex,
39-
yellow: catppuccinFlavor.ansiColors.yellow.normal.hex,
40-
blue: catppuccinFlavor.ansiColors.blue.normal.hex,
41-
magenta: catppuccinFlavor.ansiColors.magenta.normal.hex,
42-
cyan: catppuccinFlavor.ansiColors.cyan.normal.hex,
43-
white: catppuccinFlavor.ansiColors.white.normal.hex,
37+
black: flavor.ansiColors.black.normal.hex,
38+
red: flavor.ansiColors.red.normal.hex,
39+
green: flavor.ansiColors.green.normal.hex,
40+
yellow: flavor.ansiColors.yellow.normal.hex,
41+
blue: flavor.ansiColors.blue.normal.hex,
42+
magenta: flavor.ansiColors.magenta.normal.hex,
43+
cyan: flavor.ansiColors.cyan.normal.hex,
44+
white: flavor.ansiColors.white.normal.hex,
4445
bright: {
45-
black: catppuccinFlavor.ansiColors.black.bright.hex,
46-
red: catppuccinFlavor.ansiColors.red.bright.hex,
47-
green: catppuccinFlavor.ansiColors.green.bright.hex,
48-
yellow: catppuccinFlavor.ansiColors.yellow.bright.hex,
49-
blue: catppuccinFlavor.ansiColors.blue.bright.hex,
50-
magenta: catppuccinFlavor.ansiColors.magenta.bright.hex,
51-
cyan: catppuccinFlavor.ansiColors.cyan.bright.hex,
52-
white: catppuccinFlavor.ansiColors.white.bright.hex,
46+
black: flavor.ansiColors.black.bright.hex,
47+
red: flavor.ansiColors.red.bright.hex,
48+
green: flavor.ansiColors.green.bright.hex,
49+
yellow: flavor.ansiColors.yellow.bright.hex,
50+
blue: flavor.ansiColors.blue.bright.hex,
51+
magenta: flavor.ansiColors.magenta.bright.hex,
52+
cyan: flavor.ansiColors.cyan.bright.hex,
53+
white: flavor.ansiColors.white.bright.hex,
5354
},
5455
};
5556
const console: Console = {
5657
fg: {
57-
self: catppuccinFlavor.colors.text.hex,
58-
subtle: catppuccinFlavor.colors.subtext0.hex,
58+
self: flavor.colors.text.hex,
59+
subtle: flavor.colors.subtext0.hex,
5960
},
60-
bg: catppuccinFlavor.colors.base.hex,
61-
border: catppuccinFlavor.colors.overlay0.hex,
62-
activeBg: rgba(catppuccinFlavor.colors.text.hex, 0.1),
63-
hoverBg: rgba(catppuccinFlavor.colors.overlay0.hex, 0.2),
61+
bg: flavor.colors.base.hex,
62+
border: flavor.colors.overlay0.hex,
63+
activeBg: flavor.colors.overlay0.hex,
64+
hoverBg: rgba(flavor.colors.overlay0.hex, 0.2),
6465
menu: {
6566
bg: themeVars.color.menu,
6667
border: themeVars.color.secondary.self,
6768
},
68-
link: catppuccinFlavor.colors.blue.hex,
69+
link: flavor.colors.blue.hex,
6970
};
7071
const diff: Diff = {
7172
added: {
72-
fg: catppuccinFlavor.colors.green.hex,
73-
linenum: { bg: rgba(catppuccinFlavor.colors.green.hex, 0.1) },
74-
row: { bg: rgba(catppuccinFlavor.colors.green.hex, 0.2), border: rgba(catppuccinFlavor.colors.green.hex, 0.2) },
75-
word: { bg: rgba(catppuccinFlavor.colors.green.hex, 0.1) },
73+
fg: flavor.colors.green.hex,
74+
linenum: { bg: rgba(flavor.colors.green.hex, 0.1) },
75+
row: { bg: rgba(flavor.colors.green.hex, 0.2), border: rgba(flavor.colors.green.hex, 0.2) },
76+
word: { bg: rgba(flavor.colors.green.hex, 0.1) },
7677
},
7778
removed: {
78-
fg: catppuccinFlavor.colors.red.hex,
79-
linenum: { bg: rgba(catppuccinFlavor.colors.red.hex, 0.1) },
80-
row: { bg: rgba(catppuccinFlavor.colors.red.hex, 0.2), border: rgba(catppuccinFlavor.colors.red.hex, 0.2) },
81-
word: { bg: rgba(catppuccinFlavor.colors.red.hex, 0.1) },
79+
fg: flavor.colors.red.hex,
80+
linenum: { bg: rgba(flavor.colors.red.hex, 0.1) },
81+
row: { bg: rgba(flavor.colors.red.hex, 0.2), border: rgba(flavor.colors.red.hex, 0.2) },
82+
word: { bg: rgba(flavor.colors.red.hex, 0.1) },
8283
},
8384
moved: {
84-
row: { bg: rgba(catppuccinFlavor.colors.yellow.hex, 0.2), border: rgba(catppuccinFlavor.colors.yellow.hex, 0.2) },
85+
row: { bg: rgba(flavor.colors.yellow.hex, 0.2), border: rgba(flavor.colors.yellow.hex, 0.2) },
8586
},
86-
inactive: catppuccinFlavor.colors.overlay2.hex,
87+
inactive: flavor.colors.overlay2.hex,
8788
};
8889
const other: Other = {
8990
logo: themeVars.color.primary.self,
@@ -93,92 +94,189 @@ export function catppuccin2ThemeColor(catppuccinFlavor: CatppuccinFlavor): Theme
9394
body: { self: themeVars.color.body, highlight: rgba(accentColor, 0.2) },
9495
},
9596
text: {
96-
self: catppuccinFlavor.colors.text.hex,
97+
self: flavor.colors.text.hex,
9798
light: {
98-
self: catppuccinFlavor.colors.subtext1.hex,
99-
num1: catppuccinFlavor.colors.subtext1.hex,
100-
num2: catppuccinFlavor.colors.subtext1.hex,
101-
num3: catppuccinFlavor.colors.subtext1.hex,
99+
self: flavor.colors.subtext1.hex,
100+
num1: flavor.colors.subtext1.hex,
101+
num2: flavor.colors.subtext1.hex,
102+
num3: flavor.colors.subtext1.hex,
102103
},
103-
dark: catppuccinFlavor.colors.subtext0.hex,
104+
dark: flavor.colors.subtext0.hex,
104105
},
105106
footer: lv2Color,
106-
timeline: catppuccinFlavor.colors.surface0.hex,
107+
timeline: flavor.colors.surface0.hex,
107108
input: {
108109
text: themeVars.color.text.self,
109-
background: catppuccinFlavor.colors.surface0.hex,
110-
toggleBackground: catppuccinFlavor.colors.surface0.hex,
111-
border: catppuccinFlavor.colors.surface1.hex,
112-
},
113-
light: { self: themeVars.color.body, border: catppuccinFlavor.colors.surface2.hex },
114-
hover: { self: rgba(catppuccinFlavor.colors.overlay0.hex, 0.2), opaque: themeVars.color.box.header },
115-
active: rgba(catppuccinFlavor.colors.text.hex, 0.1),
116-
menu: catppuccinFlavor.colors.surface0.hex,
117-
card: catppuccinFlavor.colors.surface0.hex,
110+
background: lv2Color,
111+
toggleBackground: lv2Color,
112+
border: flavor.colors.surface1.hex,
113+
},
114+
light: { self: themeVars.color.body, border: flavor.colors.surface2.hex },
115+
hover: { self: rgba(flavor.colors.overlay0.hex, 0.2), opaque: themeVars.color.box.header },
116+
active: rgba(flavor.colors.text.hex, 0.1),
117+
menu: flavor.colors.base.hex,
118+
card: flavor.colors.base.hex,
118119
markup: {
119-
tableRow: rgba(catppuccinFlavor.colors.text.hex, 0.02),
120-
code: { block: rgba(catppuccinFlavor.colors.text.hex, 0.05), inline: catppuccinFlavor.colors.surface0.hex },
120+
tableRow: rgba(flavor.colors.text.hex, 0.02),
121+
code: { block: rgba(flavor.colors.text.hex, 0.05), inline: flavor.colors.surface0.hex },
121122
},
122-
button: catppuccinFlavor.colors.surface0.hex,
123+
button: flavor.colors.surface0.hex,
123124
codeBg: "unset",
124125
shadow: { self: rgba(lv1Color, 0.1), opaque: themeVars.color.shadow.self },
125126
secondaryBg: "unset",
126-
expandButton: catppuccinFlavor.colors.surface2.hex,
127+
expandButton: rgba(accentColor, 0.5),
127128
placeholderText: themeVars.color.text.light.num3,
128129
editor: {
129-
lineHighlight: rgba(catppuccinFlavor.colors.text.hex, 0.1),
130+
lineHighlight: rgba(flavor.colors.text.hex, 0.1),
130131
selection: themeVars.color.editor.lineHighlight,
131132
},
132133
projectColumnBg: themeVars.color.secondary.light.num2,
133134
caret: themeVars.color.text.self,
134135
reaction: { bg: "initial", hoverBg: themeVars.color.primary.self, activeBg: themeVars.color.primary.alpha.num40 },
135-
tooltip: { text: themeVars.color.text.self, bg: catppuccinFlavor.colors.overlay0.hex },
136+
tooltip: { text: themeVars.color.text.self, bg: flavor.colors.overlay0.hex },
136137
nav: {
137138
bg: lv2Color,
138139
hoverBg: themeVars.color.hover.self,
139140
text: themeVars.color.text.self,
140141
},
141142
secondaryNavBg: themeVars.color.body,
142143
label: {
143-
text: catppuccinFlavor.colors.crust.hex,
144+
text: flavor.colors.crust.hex,
144145
bg: accentColor,
145146
hoverBg: scaleColorLight(accentColor, 6 * brightDir),
146147
activeBg: scaleColorLight(accentColor, 3 * brightDir),
147148
},
148-
accent: themeVars.color.primary.light.num1,
149+
accent: accentColor,
149150
smallAccent: themeVars.color.primary.light.num5,
150-
highlight: { fg: catppuccinFlavor.colors.text.hex, bg: rgba(catppuccinFlavor.colors.teal.hex, 0.2) },
151-
overlayBackdrop: catppuccinFlavor.colors.overlay2.hex,
151+
highlight: { fg: flavor.colors.text.hex, bg: rgba(flavor.colors.teal.hex, 0.2) },
152+
overlayBackdrop: rgba(flavor.colors.overlay2.hex, 0.4),
152153
danger: themeVars.color.red.self,
153154
transparency: { grid: { light: "#ffffff", dark: "#e5e5e5" } },
154155
workflowEdgeHover: accentColor,
155156
};
157+
// 颜色映射参考: https://github.com/catppuccin/userstyles/blob/main/styles/github/catppuccin.user.less
158+
const github: GitHub = {
159+
avatar: { bgColor: rgba(flavor.colors.text.hex, 0.26), borderColor: flavor.colors.surface0.hex },
160+
fgColor: {
161+
accent: accentColor,
162+
success: flavor.colors.green.hex,
163+
done: flavor.colors.mauve.hex,
164+
onEmphasis: flavor.colors.base.hex,
165+
},
166+
bgColor: {
167+
accent: {
168+
emphasis: accentColor,
169+
muted: rgba(accentColor, 0.2),
170+
},
171+
success: { emphasis: flavor.colors.green.hex },
172+
attention: {
173+
emphasis: flavor.colors.yellow.hex,
174+
},
175+
danger: { emphasis: flavor.colors.red.hex },
176+
done: { emphasis: flavor.colors.mauve.hex },
177+
neutral: { emphasis: flavor.colors.subtext0.hex },
178+
},
179+
borderColor: {
180+
emphasis: "#484f58",
181+
accent: { emphasis: accentColor },
182+
attention: { emphasis: flavor.colors.flamingo.hex },
183+
success: { emphasis: flavor.colors.green.hex },
184+
done: { emphasis: flavor.colors.mauve.hex },
185+
},
186+
button: {
187+
default: { bgColor: { active: flavor.colors.surface2.hex } },
188+
primary: {
189+
fgColor: { accent: flavor.colors.green.hex, rest: flavor.colors.base.hex },
190+
bgColor: {
191+
rest: flavor.colors.green.hex,
192+
hover: lighten(0.05, flavor.colors.green.hex),
193+
active: saturate(0.05, flavor.colors.green.hex),
194+
},
195+
borderColor: { rest: flavor.colors.green.hex, hover: flavor.colors.green.hex },
196+
},
197+
danger: {
198+
fgColor: { rest: flavor.colors.red.hex, hover: flavor.colors.base.hex },
199+
bgColor: {
200+
rest: flavor.colors.surface0.hex,
201+
hover: flavor.colors.red.hex,
202+
active: darken(0.05, flavor.colors.red.hex),
203+
},
204+
borderColor: { hover: flavor.colors.red.hex },
205+
},
206+
star: { iconColor: flavor.colors.yellow.hex },
207+
invisible: { iconColor: { rest: flavor.colors.overlay2.hex } },
208+
},
209+
control: {
210+
bgColor: { rest: themeVars.color.timeline },
211+
transparent: {
212+
bgColor: { hover: rgba(flavor.colors.surface2.hex, 0.2), active: rgba(flavor.colors.overlay0.hex, 0.5) },
213+
},
214+
danger: { bgColor: { active: rgba(flavor.colors.red.hex, 0.3) } },
215+
},
216+
// 对调颜色映射, 倾向于个人标准(激活项颜色和菜单色一致)
217+
controlTrack: { bgColor: { rest: flavor.colors.surface0.hex } },
218+
controlKnob: { bgColor: { rest: flavor.colors.base.hex } },
219+
shadow: {
220+
floating: {
221+
small: `0px 0px 0px 1px ${flavor.colors.overlay0.hex}, 0px 6px 12px -3px ${flavor.colors.crust.hex}, 0px 6px 18px 0px ${flavor.colors.crust.hex};`,
222+
},
223+
inset: `inset 0px 1px 0px 0px ${flavor.colors.crust.hex}`,
224+
resting: {
225+
small: `0px 1px 1px 0px ${flavor.colors.crust.hex}, 0px 1px 3px 0px ${flavor.colors.crust.hex};`,
226+
// 此阴影用于工作流的流程图的节点悬浮效果, 该效果在 Gitea 中通过 svg, g 的 filter 实现, 而非 box-shadow
227+
medium: `drop-shadow(0 1px 1px ${flavor.colors.crust.hex}) drop-shadow(0 3px 6px ${flavor.colors.crust.hex})`,
228+
},
229+
},
230+
underlineNav: { borderColor: { active: accentColor } },
231+
contribution: {
232+
default: {
233+
bgColor: {
234+
num0: rgba(accentColor, 0.05),
235+
num1: rgba(accentColor, 0.25),
236+
num2: rgba(accentColor, 0.45),
237+
num3: rgba(accentColor, 0.65),
238+
num4: rgba(accentColor, 0.85),
239+
num5: accentColor,
240+
},
241+
borderColor: {
242+
num0: rgba(flavor.colors.overlay0.hex, 0.05),
243+
num1: themeVars.github.contribution.default.borderColor.num0,
244+
num2: themeVars.github.contribution.default.borderColor.num0,
245+
num3: themeVars.github.contribution.default.borderColor.num0,
246+
num4: themeVars.github.contribution.default.borderColor.num0,
247+
num5: themeVars.github.contribution.default.borderColor.num0,
248+
},
249+
},
250+
},
251+
workflowCardBg: flavor.colors.surface0.hex,
252+
};
156253
return {
157-
isDarkTheme: catppuccinFlavor.dark,
254+
isDarkTheme: flavor.dark,
158255
primary: accentColor,
159256
primaryContrast: lv1Color,
160-
secondary: catppuccinFlavor.colors.overlay0.hex,
257+
secondary: flavor.colors.overlay0.hex,
161258
base: {
162-
red: catppuccinFlavor.colors.red.hex,
163-
orange: catppuccinFlavor.colors.peach.hex,
164-
yellow: catppuccinFlavor.colors.yellow.hex,
165-
olive: catppuccinFlavor.colors.green.hex,
166-
green: catppuccinFlavor.colors.green.hex,
167-
teal: catppuccinFlavor.colors.teal.hex,
168-
cyan: catppuccinFlavor.colors.sky.hex,
169-
blue: catppuccinFlavor.colors.blue.hex,
170-
violet: catppuccinFlavor.colors.lavender.hex,
171-
purple: catppuccinFlavor.colors.mauve.hex,
172-
pink: catppuccinFlavor.colors.pink.hex,
173-
brown: catppuccinFlavor.colors.flamingo.hex,
174-
black: catppuccinFlavor.dark ? catppuccinFlavor.colors.crust.hex : catppuccinFlavor.colors.text.hex,
175-
grey: catppuccinFlavor.colors.overlay2.hex,
176-
gold: catppuccinFlavor.colors.rosewater.hex,
177-
white: catppuccinFlavor.dark ? catppuccinFlavor.colors.text.hex : catppuccinFlavor.colors.crust.hex,
259+
red: flavor.colors.red.hex,
260+
orange: flavor.colors.peach.hex,
261+
yellow: flavor.colors.yellow.hex,
262+
olive: flavor.colors.green.hex,
263+
green: flavor.colors.green.hex,
264+
teal: flavor.colors.teal.hex,
265+
cyan: flavor.colors.sky.hex,
266+
blue: flavor.colors.blue.hex,
267+
violet: flavor.colors.lavender.hex,
268+
purple: flavor.colors.mauve.hex,
269+
pink: flavor.colors.pink.hex,
270+
brown: flavor.colors.flamingo.hex,
271+
black: flavor.dark ? flavor.colors.crust.hex : flavor.colors.text.hex,
272+
grey: flavor.colors.overlay2.hex,
273+
gold: flavor.colors.rosewater.hex,
274+
white: "#f0f6fc",
178275
},
179276
console,
180277
diff,
181278
other,
279+
github,
182280
override: {
183281
ansi,
184282
},

0 commit comments

Comments
 (0)