Skip to content

Commit 300e115

Browse files
committed
higher contrast search and players
1 parent b96a09b commit 300e115

File tree

2 files changed

+306
-207
lines changed

2 files changed

+306
-207
lines changed

src/theme.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,44 @@ export function getTheme({ themeKey, name, type }) {
1818
return themeKey.startsWith('light') ? tokens[lightTokenName] : tokens[darkTokenName]
1919
}
2020

21+
22+
/**
23+
* @param {string} tokenName
24+
* @param {number} alphaValue
25+
*/
26+
const alpha = (tokenName, alphaValue) => {
27+
const baseToken = tokens[tokenName];
28+
if (!baseToken) {
29+
console.warn(`Token '${tokenName}' not found in theme '${themeKey}'`)
30+
return null;
31+
}
32+
33+
const hexAlpha = Math.round(alphaValue * 255).toString(16).padStart(2, '0');
34+
35+
// Remove the '#' if present
36+
let color = baseToken.replace('#', '');
37+
38+
// If it's already an 8-digit HEXA, replace the last two characters
39+
if (color.length === 8) {
40+
color = color.slice(0, 6) + hexAlpha;
41+
}
42+
// If it's a 6-digit HEX, append the new alpha
43+
else if (color.length === 6) {
44+
color += hexAlpha;
45+
}
46+
// If it's a 3-digit HEX, expand it and append the new alpha
47+
else if (color.length === 3) {
48+
color = color.split('').map(char => char + char).join('') + hexAlpha;
49+
}
50+
else {
51+
console.warn(`Invalid color format for token '${tokenName}': ${baseToken}`);
52+
return baseToken;
53+
}
54+
55+
return '#' + color;
56+
}
57+
2158
return {
22-
"$schema": "https://zed.dev/schema/themes/v0.1.0.json",
2359
appearance: type,
2460
name,
2561
style: {
@@ -50,8 +86,8 @@ export function getTheme({ themeKey, name, type }) {
5086
"editor.active_line_number": tokens['fgColor/default'],
5187
"editor.active_wrap_guide": tokens['borderColor/muted'],
5288
"editor.background": tokens['bgColor/default'],
53-
"editor.document_highlight.read_background": tokens['bgColor/accent-muted'],
54-
"editor.document_highlight.write_background": tokens['bgColor/accent-emphasis'],
89+
"editor.document_highlight.read_background": alpha("fgColor/accent", 0.3),
90+
"editor.document_highlight.write_background": alpha("fgColor/accent", 0.2),
5591
"editor.foreground": tokens['fgColor/default'],
5692
"editor.gutter.background": tokens['bgColor/default'],
5793
"editor.highlighted_line.background": tokens['bgColor/neutral-muted'],
@@ -126,7 +162,7 @@ export function getTheme({ themeKey, name, type }) {
126162
"scrollbar.track.border": tokens['borderColor/transparent'],
127163
"scrollbar_thumb.background": tokens['bgColor/neutal-muted'],
128164

129-
"search.match_background": tokens['bgColor/attention-muted'],
165+
"search.match_background": alpha("base/color/yellow/1", 0.3),
130166

131167
"status_bar.background": tokens['bgColor/inset'],
132168

@@ -198,9 +234,9 @@ export function getTheme({ themeKey, name, type }) {
198234
"teal",
199235
"red"
200236
].map(color => ({
201-
"cursor": tokens[`data/${color}/color`],
202-
"background": tokens[`data/${color}/color/muted`],
203-
"border": tokens[`data/${color}/color/muted`]
237+
"cursor": tokens[`data/${color}/color/emphasis`],
238+
"background": tokens[`data/${color}/color/emphasis`],
239+
"selection": alpha(`data/${color}/color/emphasis`, 0.4)
204240
})),
205241

206242
"syntax": {
@@ -356,8 +392,8 @@ export function getTheme({ themeKey, name, type }) {
356392
},
357393
"string.escape": {
358394
"color": lightDark("base/color/green/6", "base/color/green/1"),
359-
"font_style": "bold",
360-
"font_weight": null
395+
"font_style": null,
396+
"font_weight": 700
361397
},
362398
"string.regex": {
363399
"color": lightDark("base/color/blue/8", "base/color/blue/1"),

0 commit comments

Comments
 (0)