Elffuss BraidHub

kikocis/continue public

95c91a48de4e · 7.9 KiBRawPermalink
1// All vscode variables https://gist.github.com/estruyf/ba49203e1a7d6868e9320a4ea480c27a
2// Examples for vscode https://github.com/githubocto/tailwind-vscode/blob/main/index.js
3
4// The current default theme is dark with blue accents
5export const THEME_COLORS = {
6 background: {
7 vars: [
8 "--vscode-sideBar-background",
9 "--vscode-editor-background",
10 "--vscode-panel-background",
11 ],
12 default: "#1e1e1e", // dark gray
13 },
14 foreground: {
15 vars: [
16 "--vscode-sideBar-foreground",
17 "--vscode-editor-foreground",
18 "--vscode-panel-foreground",
19 ],
20 default: "#e6e6e6", // light gray
21 },
22 "editor-background": {
23 vars: ["--vscode-editor-background"],
24 default: "#1e1e1e", // dark gray
25 },
26 "editor-foreground": {
27 vars: ["--vscode-editor-foreground"],
28 default: "#e6e6e6", // light gray
29 },
30 "primary-background": {
31 vars: ["--vscode-button-background"],
32 default: "#2c5aa0", // medium blue
33 },
34 "primary-foreground": {
35 vars: ["--vscode-button-foreground"],
36 default: "#ffffff", // white
37 },
38 "primary-hover": {
39 vars: ["--vscode-button-hoverBackground"],
40 default: "#3a6db3", // lighter blue
41 },
42 "secondary-background": {
43 vars: ["--vscode-button-secondaryBackground"],
44 default: "#303030", // medium dark gray
45 },
46 "secondary-foreground": {
47 vars: ["--vscode-button-secondaryForeground"],
48 default: "#e6e6e6", // light gray
49 },
50 "secondary-hover": {
51 vars: ["--vscode-button-secondaryHoverBackground"],
52 default: "#3a3a3a", // medium gray
53 },
54 border: {
55 vars: ["--vscode-sideBar-border", "--vscode-panel-border"],
56 default: "#2a2a2a", // dark gray border
57 },
58 "border-focus": {
59 vars: ["--vscode-focusBorder"],
60 default: "#3a6db3", // lighter blue
61 },
62 // Command styles are used for tip-tap editor
63 "command-background": {
64 vars: ["--vscode-commandCenter-background"],
65 default: "#252525", // dark gray
66 },
67 "command-foreground": {
68 vars: ["--vscode-commandCenter-foreground"],
69 default: "#e6e6e6", // light gray
70 },
71 "command-border": {
72 vars: ["--vscode-commandCenter-inactiveBorder"],
73 default: "#555555", // medium gray
74 },
75 "command-border-focus": {
76 vars: ["--vscode-commandCenter-activeBorder"],
77 default: "#4d8bf0", // bright blue
78 },
79 description: {
80 vars: ["--vscode-descriptionForeground"],
81 default: "#b3b3b3", // medium light gray
82 },
83 "description-muted": {
84 vars: ["--vscode-list-deemphasizedForeground"],
85 default: "#8c8c8c", // medium gray
86 },
87 "input-background": {
88 vars: ["--vscode-input-background"],
89 default: "#2d2d2d", // dark gray
90 },
91 "input-foreground": {
92 vars: ["--vscode-input-foreground"],
93 default: "#e6e6e6", // light gray
94 },
95 "input-border": {
96 vars: [
97 "--vscode-input-border",
98 "--vscode-commandCenter-inactiveBorder",
99 "vscode-border",
100 ],
101 default: "#555555", // medium gray
102 },
103 "input-placeholder": {
104 vars: ["--vscode-input-placeholderForeground"],
105 default: "#9e9e9e", // medium light gray
106 },
107 "table-oddRow": {
108 vars: ["--vscode-tree-tableOddRowsBackground"],
109 default: "#2d2d2d", // dark gray
110 },
111 "badge-background": {
112 vars: ["--vscode-badge-background"],
113 default: "#4d4d4d", // medium dark gray
114 },
115 "badge-foreground": {
116 vars: ["--vscode-badge-foreground"],
117 default: "#ffffff", // white
118 },
119 success: {
120 vars: [
121 "--vscode-notebookStatusSuccessIcon-foreground",
122 "--vscode-testing-iconPassed",
123 "--vscode-gitDecoration-addedResourceForeground",
124 "--vscode-charts-green",
125 ],
126 default: "#4caf50", // green
127 },
128 warning: {
129 vars: [
130 "--vscode-editorWarning-foreground",
131 "--vscode-list-warningForeground",
132 ],
133 default: "#ffb74d", // amber/yellow
134 },
135 error: {
136 vars: ["--vscode-editorError-foreground", "--vscode-list-errorForeground"],
137 default: "#f44336", // red
138 },
139 link: {
140 vars: ["--vscode-textLink-foreground"],
141 default: "#5c9ce6", // medium blue
142 },
143 accent: {
144 vars: ["--vscode-tab-activeBorderTop", "--vscode-focusBorder"],
145 default: "#4d8bf0", // bright blue
146 },
147 "find-match": {
148 vars: ["--vscode-editor-findMatchBackground"], // Can't get "var(--vscode-editor-findMatchBackground, rgba(237, 18, 146, 0.5))" to work
149 default: "#264f7840", // translucent blue
150 },
151 "find-match-selected": {
152 vars: ["--vscode-editor-findMatchHighlightBackground"],
153 default: "#ffb74d40", // translucent amber
154 },
155 "list-hover": {
156 // --vscode-tab-hoverBackground
157 vars: ["--vscode-list-hoverBackground"],
158 default: "#383838", // medium dark gray
159 },
160 "list-active": {
161 vars: ["--vscode-list-activeSelectionBackground"],
162 default: "#2c5aa050", // translucent medium blue
163 },
164 "list-active-foreground": {
165 vars: ["--vscode-list-activeSelectionForeground"],
166 default: "#ffffff", // white
167 },
168};
169
170// TODO: add fonts - GUI fonts in jetbrains differ from IDE:
171// --vscode-editor-font-family;
172// --vscode-font-family;
173export const THEME_CSS_VARS = Object.values(THEME_COLORS)
174 .map((value) => value.vars)
175 .flat();
176
177export const THEME_CSS_VAR_DEFAULTS = Object.entries(THEME_COLORS).reduce(
178 (acc, [_, value]) => {
179 value.vars.forEach((varName) => {
180 acc[varName] = value.default;
181 });
182 return acc;
183 },
184 {} as Record<string, string>,
185);
186
187export const THEME_DEFAULTS = Object.entries(THEME_COLORS).reduce(
188 (acc, [key, value]) => {
189 acc[key] = value.default;
190 return acc;
191 },
192 {} as Record<string, string>,
193);
194
195// Generates recursive CSS variable fallback for a given color name
196// e.g. var(--vscode-button-background, var(--vscode-button-foreground, #ffffff))
197export const getRecursiveVar = (vars: string[], defaultColor: string) => {
198 return [...vars].reverse().reduce((curr, varName) => {
199 return `var(${varName}, ${curr})`;
200 }, defaultColor);
201};
202
203export const varWithFallback = (colorName: keyof typeof THEME_COLORS) => {
204 const themeVals = THEME_COLORS[colorName];
205 if (!themeVals) {
206 throw new Error(`Invalid theme color name ${colorName}`);
207 }
208 return getRecursiveVar(themeVals.vars, themeVals.default);
209};
210
211export const setDocumentStylesFromTheme = (
212 theme: Record<string, string | undefined | null>,
213) => {
214 // Check for extraneous theme items
215 Object.entries(theme).forEach(([colorName, value]) => {
216 const themeVals = THEME_COLORS[colorName as keyof typeof THEME_COLORS];
217 if (!themeVals) {
218 console.warn(
219 `Receieved theme color ${colorName} which is not used by the theme`,
220 );
221 return;
222 }
223 });
224
225 // Write theme values to document
226 const missingColors: string[] = [];
227 Object.entries(THEME_COLORS).forEach(([colorName, settings]) => {
228 let colorVal = settings.default;
229 const newColor = theme[colorName];
230 if (newColor) {
231 colorVal = newColor;
232 // Remove alpha channel from all hex colors (seems to cause bad colors)
233 if (newColor.startsWith("#") && newColor.length > 7) {
234 colorVal = colorVal.slice(0, 7);
235 }
236 } else {
237 missingColors.push(colorName);
238 // console.warn(
239 // `Missing theme color: ${colorName}. Falling back to default ${colorVal}`,
240 // );
241 }
242
243 localStorage.setItem(colorName, colorVal);
244 for (const cssVar of settings.vars) {
245 document.body.style.setProperty(cssVar, colorVal);
246 document.documentElement.style.setProperty(cssVar, colorVal);
247 }
248 });
249
250 return missingColors;
251};
252
253export const setDocumentStylesFromLocalStorage = (checkCache: boolean) => {
254 for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) {
255 for (const cssVar of themeVals.vars) {
256 // Get cached values (for non-vscode IDEs)
257 if (checkCache) {
258 const cached = localStorage.getItem(colorName);
259 if (cached) {
260 document.body.style.setProperty(cssVar, cached);
261 }
262 }
263 }
264 }
265};
266
267export const clearThemeLocalCache = () => {
268 for (const colorName of Object.keys(THEME_COLORS)) {
269 localStorage.removeItem(colorName);
270 }
271};