@@ -86,52 +86,18 @@ function transparent(color, opacity) {
86
86
return objectToHex({ r, g, b, a: a * opacity });
87
87
}
88
88
89
- function getThemeColors(theme) {
90
- return Object.assign({ colorScheme: theme.type === "from-css" ? "var(--ch-0)" : theme.type }, getColors(theme));
91
- }
92
- const colorNamesToKeys = {
93
- background: "editor.background",
94
- foreground: "editor.foreground",
95
- lineNumberForeground: "editorLineNumber.foreground",
96
- selectionBackground: "editor.selectionBackground",
97
- editorBackground: "editor.background",
98
- editorGroupHeaderBackground: "editorGroupHeader.tabsBackground",
99
- activeTabBackground: "tab.activeBackground",
100
- activeTabForeground: "tab.activeForeground",
101
- tabBorder: "tab.border",
102
- activeTabBorder: "tab.activeBorder",
103
- inactiveTabBackground: "tab.inactiveBackground",
104
- inactiveTabForeground: "tab.inactiveForeground",
105
- diffInsertedTextBackground: "diffEditor.insertedTextBackground",
106
- diffInsertedLineBackground: "diffEditor.insertedLineBackground",
107
- diffRemovedTextBackground: "diffEditor.removedTextBackground",
108
- diffRemovedLineBackground: "diffEditor.removedLineBackground",
109
- iconForeground: "icon.foreground",
110
- sideBarBackground: "sideBar.background",
111
- sideBarForeground: "sideBar.foreground",
112
- sideBarBorder: "sideBar.border",
113
- listSelectionBackground: "list.inactiveSelectionBackground",
114
- listSelectionForeground: "list.inactiveSelectionForeground",
115
- listHoverBackground: "list.hoverBackground",
116
- listHoverForeground: "list.hoverForeground",
117
- tabsBorder: "editorGroupHeader.tabsBorder",
118
- activeTabTopBorder: "tab.activeBorderTop",
119
- hoverTabBackground: "tab.hoverBackground",
120
- hoverTabForeground: "tab.hoverForeground",
121
- };
122
- function getColors(theme) {
123
- const colors = {};
124
- for (const key in colorNamesToKeys) {
125
- colors[key] = getColor(theme, colorNamesToKeys[key]);
126
- }
127
- return colors;
89
+ function getColorScheme(theme) {
90
+ return theme.type === "from-css" ? "var(--ch-0)" : theme.type;
128
91
}
129
92
function getColor(theme, name) {
130
93
const colors = theme.colors || {};
131
94
if (colors[name]) {
132
95
return colors[name];
133
96
}
134
97
const defaultColors = defaults[name];
98
+ if (!defaultColors) {
99
+ throw new Error(`Unknown theme color key: ${name}`);
100
+ }
135
101
if (typeof defaultColors === "string") {
136
102
return getColor(theme, defaultColors);
137
103
}
@@ -152,11 +118,7 @@ function getDefault(theme, defaults) {
152
118
// keys from : https://code.visualstudio.com/api/references/theme-color#editor-groups-tabs
153
119
const contrastBorder = "#6FC3DF";
154
120
const defaults = {
155
- "editor.foreground": {
156
- dark: "#bbbbbb",
157
- light: "#333333",
158
- hc: "#ffffff",
159
- },
121
+ "editor.foreground": { dark: "#bbbbbb", light: "#333333", hc: "#ffffff" },
160
122
"editorLineNumber.foreground": {
161
123
dark: "#858585",
162
124
light: "#237893",
@@ -167,25 +129,13 @@ const defaults = {
167
129
dark: "#264F78",
168
130
hc: "#f3f518",
169
131
},
170
- "editor.background": {
171
- light: "#fffffe",
172
- dark: "#1E1E1E",
173
- hc: "#000000",
174
- },
175
- "editorGroupHeader.tabsBackground": {
176
- dark: "#252526",
177
- light: "#F3F3F3",
178
- hc: undefined,
179
- },
132
+ "editor.background": { light: "#fffffe", dark: "#1E1E1E", hc: "#000000" },
133
+ "editorGroupHeader.tabsBackground": { dark: "#252526", light: "#F3F3F3" },
180
134
"tab.activeBackground": "editor.background",
181
135
"tab.activeForeground": { dark: "#ffffff", light: "#333333", hc: "#ffffff" },
182
136
"tab.border": { dark: "#252526", light: "#F3F3F3", hc: contrastBorder },
183
137
"tab.activeBorder": "tab.activeBackground",
184
- "tab.inactiveBackground": {
185
- dark: "#2D2D2D",
186
- light: "#ECECEC",
187
- hc: undefined,
188
- },
138
+ "tab.inactiveBackground": { dark: "#2D2D2D", light: "#ECECEC" },
189
139
"tab.inactiveForeground": {
190
140
dark: [transparent, "tab.activeForeground", 0.5],
191
141
light: [transparent, "tab.activeForeground", 0.5],
@@ -194,35 +144,52 @@ const defaults = {
194
144
"diffEditor.insertedTextBackground": {
195
145
dark: "#9ccc2c33",
196
146
light: "#9ccc2c40",
197
- hc: undefined,
198
- },
199
- "diffEditor.removedTextBackground": {
200
- dark: "#ff000033",
201
- light: "#ff000033",
202
- hc: undefined,
203
147
},
148
+ "diffEditor.removedTextBackground": { dark: "#ff000033", light: "#ff000033" },
204
149
"diffEditor.insertedLineBackground": {
205
150
dark: "#9bb95533",
206
151
light: "#9bb95533",
207
- hc: undefined,
208
- },
209
- "diffEditor.removedLineBackground": {
210
- dark: "#ff000033",
211
- light: "#ff000033",
212
- hc: undefined,
213
152
},
153
+ "diffEditor.removedLineBackground": { dark: "#ff000033", light: "#ff000033" },
214
154
"icon.foreground": { dark: "#C5C5C5", light: "#424242", hc: "#FFFFFF" },
215
155
"sideBar.background": { dark: "#252526", light: "#F3F3F3", hc: "#000000" },
216
156
"sideBar.foreground": "editor.foreground",
217
157
"sideBar.border": "sideBar.background",
218
158
"list.inactiveSelectionBackground": { dark: "#37373D", light: "#E4E6F1" },
219
- "list.inactiveSelectionForeground": { dark: undefined, light: undefined },
159
+ "list.inactiveSelectionForeground": {},
220
160
"list.hoverBackground": { dark: "#2A2D2E", light: "#F0F0F0" },
221
- "list.hoverForeground": { dark: undefined, light: undefined },
161
+ "list.hoverForeground": {},
222
162
"editorGroupHeader.tabsBorder": { hc: contrastBorder },
223
163
"tab.activeBorderTop": { hc: contrastBorder },
224
164
"tab.hoverBackground": "tab.inactiveBackground",
225
165
"tab.hoverForeground": "tab.inactiveForeground",
166
+ "editor.rangeHighlightBackground": { dark: "#ffffff0b", light: "#fdff0033" },
167
+ "editor.infoForeground": { dark: "#3794FF", light: "#1a85ff", hc: "#3794FF" },
168
+ "input.border": { hc: contrastBorder },
169
+ "input.background": { dark: "#3C3C3C", light: "#fffffe", hc: "#000000" },
170
+ "input.foreground": "editor.foreground",
171
+ "editor.lineHighlightBackground": {},
172
+ focusBorder: { light: "#0090F1", dark: "#007FD4", hc: contrastBorder },
173
+ "editorGroup.border": {
174
+ dark: "#444444",
175
+ light: "#E7E7E7",
176
+ hc: contrastBorder,
177
+ },
178
+ "list.activeSelectionBackground": {
179
+ dark: "#094771",
180
+ light: "#0060C0",
181
+ hc: "#000000",
182
+ },
183
+ "list.activeSelectionForeground": {
184
+ dark: "#fffffe",
185
+ light: "#fffffe",
186
+ hc: "#fffffe",
187
+ },
188
+ // this aren't from vscode, they are specific to lighter
189
+ "lighter.inlineBackground": {
190
+ dark: [transparent, "editor.background", 0.9],
191
+ light: [transparent, "editor.background", 0.9],
192
+ },
226
193
};
227
194
228
195
const promiseCache = new Map();
@@ -269,10 +236,19 @@ function toFinalTheme(theme) {
269
236
if (!theme) {
270
237
return undefined;
271
238
}
272
- const finalTheme = Object.assign(Object.assign({}, theme), { name: theme.name || "unknown-theme", type: getColorScheme(theme), settings: theme.settings || theme.tokenColors || [], colors: theme.colors || {}, colorNames: theme.colorNames });
273
- const globalSetting = finalTheme.settings.find((s) => !s.name && !s.scope);
239
+ const settings = theme.settings || theme.tokenColors || [];
240
+ const finalTheme = {
241
+ name: theme.name || "unknown-theme",
242
+ type: getThemeType(theme),
243
+ foreground: "",
244
+ background: "",
245
+ settings,
246
+ colors: theme.colors || {},
247
+ colorNames: theme.colorNames,
248
+ };
249
+ const globalSetting = settings.find((s) => !s.scope);
274
250
if (globalSetting) {
275
- const { foreground, background } = globalSetting.settings || {};
251
+ const { foreground, background } = ( globalSetting === null || globalSetting === void 0 ? void 0 : globalSetting .settings) || {};
276
252
const newColors = {};
277
253
if (foreground && !finalTheme.colors["editor.foreground"]) {
278
254
newColors["editor.foreground"] = foreground;
@@ -283,6 +259,8 @@ function toFinalTheme(theme) {
283
259
if (Object.keys(newColors).length > 0) {
284
260
finalTheme.colors = Object.assign(Object.assign({}, finalTheme.colors), newColors);
285
261
}
262
+ finalTheme.foreground = foreground;
263
+ finalTheme.background = background;
286
264
}
287
265
if (!globalSetting) {
288
266
finalTheme.settings = [
@@ -295,6 +273,10 @@ function toFinalTheme(theme) {
295
273
...finalTheme.settings,
296
274
];
297
275
}
276
+ finalTheme.background =
277
+ finalTheme.background || getColor(finalTheme, "editor.background");
278
+ finalTheme.foreground =
279
+ finalTheme.foreground || getColor(finalTheme, "editor.foreground");
298
280
if (theme.type === "from-css" && !finalTheme.colorNames) {
299
281
const colorNames = {};
300
282
let counter = 0;
@@ -321,7 +303,7 @@ function toFinalTheme(theme) {
321
303
}
322
304
return finalTheme;
323
305
}
324
- function getColorScheme (theme) {
306
+ function getThemeType (theme) {
325
307
var _a;
326
308
if (theme.type === "from-css") {
327
309
return "from-css";
@@ -369,6 +351,73 @@ class UnknownThemeError extends Error {
369
351
super(`Unknown theme: ${theme}`);
370
352
this.theme = theme;
371
353
}
354
+ }
355
+ function getAllThemeColors(theme) {
356
+ const c = (key) => {
357
+ if (key === "colorScheme") {
358
+ return getColorScheme(theme);
359
+ }
360
+ if (key === "foreground") {
361
+ return theme.foreground;
362
+ }
363
+ if (key === "background") {
364
+ return theme.background;
365
+ }
366
+ return getColor(theme, key);
367
+ };
368
+ return {
369
+ colorScheme: c("colorScheme"),
370
+ foreground: c("foreground"),
371
+ background: c("background"),
372
+ lighter: {
373
+ inlineBackground: c("lighter.inlineBackground"),
374
+ },
375
+ editor: {
376
+ background: c("editor.background"),
377
+ foreground: c("editor.foreground"),
378
+ lineHighlightBackground: c("editor.lineHighlightBackground"),
379
+ rangeHighlightBackground: c("editor.rangeHighlightBackground"),
380
+ infoForeground: c("editor.infoForeground"),
381
+ selectionBackground: c("editor.selectionBackground"),
382
+ },
383
+ focusBorder: c("focusBorder"),
384
+ tab: {
385
+ activeBackground: c("tab.activeBackground"),
386
+ activeForeground: c("tab.activeForeground"),
387
+ inactiveBackground: c("tab.inactiveBackground"),
388
+ inactiveForeground: c("tab.inactiveForeground"),
389
+ border: c("tab.border"),
390
+ activeBorder: c("tab.activeBorder"),
391
+ },
392
+ editorGroup: {
393
+ border: c("editorGroup.border"),
394
+ },
395
+ editorGroupHeader: {
396
+ tabsBackground: c("editorGroupHeader.tabsBackground"),
397
+ },
398
+ editorLineNumber: {
399
+ foreground: c("editorLineNumber.foreground"),
400
+ },
401
+ input: {
402
+ background: c("input.background"),
403
+ foreground: c("input.foreground"),
404
+ border: c("input.border"),
405
+ },
406
+ icon: {
407
+ foreground: c("icon.foreground"),
408
+ },
409
+ sideBar: {
410
+ background: c("sideBar.background"),
411
+ foreground: c("sideBar.foreground"),
412
+ border: c("sideBar.border"),
413
+ },
414
+ list: {
415
+ activeSelectionBackground: c("list.activeSelectionBackground"),
416
+ activeSelectionForeground: c("list.activeSelectionForeground"),
417
+ hoverBackground: c("list.hoverBackground"),
418
+ hoverForeground: c("list.hoverForeground"),
419
+ },
420
+ };
372
421
}
373
422
374
423
// generated by lib/utils/3.update-languages-data.mjs
@@ -2723,6 +2772,8 @@ const COMMENT = "#010";
2723
2772
const commentsTheme = {
2724
2773
name: "comments",
2725
2774
type: "light",
2775
+ foreground: "",
2776
+ background: "",
2726
2777
colors: {},
2727
2778
settings: [
2728
2779
{ settings: { foreground: "#000" } },
@@ -3131,25 +3182,23 @@ function highlightSync(code, lang, themeOrThemeName = "dark-plus", config = {})
3131
3182
return {
3132
3183
lines: applyAnnotations(lines, annotations),
3133
3184
lang: langId,
3134
- colors: getThemeColors(theme),
3185
+ style: {
3186
+ color: theme.foreground,
3187
+ background: theme.background,
3188
+ },
3135
3189
};
3136
3190
}
3137
3191
else {
3138
3192
return {
3139
3193
lines: lines,
3140
3194
lang: langId,
3141
- colors: getThemeColors(theme),
3195
+ style: {
3196
+ color: theme.foreground,
3197
+ background: theme.background,
3198
+ },
3142
3199
};
3143
3200
}
3144
3201
}
3145
- /** @deprecated use highlight instead */
3146
- async function highlightWithScopes(code, alias, themeOrThemeName = "dark-plus") {
3147
- return highlight(code, alias, themeOrThemeName, { scopes: true });
3148
- }
3149
- /** @deprecated use highlight instead */
3150
- async function annotatedHighlight(code, alias, themeOrThemeName = "dark-plus", annotations = []) {
3151
- return highlight(code, alias, themeOrThemeName, { annotations });
3152
- }
3153
3202
async function extractAnnotations(code, lang, annotationNames = []) {
3154
3203
if (annotationNames.length === 0) {
3155
3204
return { code, annotations: [] };
@@ -3158,6 +3207,14 @@ async function extractAnnotations(code, lang, annotationNames = []) {
3158
3207
const { grammar } = getGrammar(lang);
3159
3208
const { newCode, annotations } = extractCommentsFromCode(code, grammar, annotationNames);
3160
3209
return { code: newCode, annotations };
3210
+ }
3211
+ async function getThemeColors(themeOrThemeName) {
3212
+ if (!themeOrThemeName) {
3213
+ throw new Error("Syntax highlighter error: undefined theme");
3214
+ }
3215
+ await preload([], themeOrThemeName);
3216
+ const theme = getTheme(themeOrThemeName);
3217
+ return getAllThemeColors(theme);
3161
3218
}
3162
3219
3163
- export { LANG_NAMES, THEME_NAMES, UnknownLanguageError, UnknownThemeError, annotatedHighlight, extractAnnotations , highlight, highlightSync, highlightWithScopes , preload };
3220
+ export { LANG_NAMES, THEME_NAMES, UnknownLanguageError, UnknownThemeError, extractAnnotations, getThemeColors , highlight, highlightSync, preload };
0 commit comments