@@ -87,7 +87,7 @@ function transparent(color, opacity) {
87
87
}
88
88
89
89
function getThemeColors(theme) {
90
- return Object.assign({ colorScheme: theme.type }, getColors(theme));
90
+ return Object.assign({ colorScheme: theme.type === "from-css" ? "var(--ch-0)" : theme.type }, getColors(theme));
91
91
}
92
92
const colorNamesToKeys = {
93
93
background: "editor.background",
@@ -231,7 +231,7 @@ async function preloadTheme(theme) {
231
231
if (typeof theme === "string") {
232
232
const name = theme;
233
233
if (!THEME_NAMES.includes(name)) {
234
- throw new UnknownThemeError$1 (name);
234
+ throw new UnknownThemeError(name);
235
235
}
236
236
if (!promiseCache.has(name)) {
237
237
const promise = reallyLoadThemeByName(name).then((theme) => {
@@ -269,7 +269,7 @@ function toFinalTheme(theme) {
269
269
if (!theme) {
270
270
return undefined;
271
271
}
272
- const finalTheme = Object.assign(Object.assign({}, theme), { name: theme.name || "unknown-theme", type: getColorScheme(theme), settings: theme.settings || theme.tokenColors || [], colors: theme.colors || {} });
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
273
const globalSetting = finalTheme.settings.find((s) => !s.name && !s.scope);
274
274
if (globalSetting) {
275
275
const { foreground, background } = globalSetting.settings || {};
@@ -295,10 +295,37 @@ function toFinalTheme(theme) {
295
295
...finalTheme.settings,
296
296
];
297
297
}
298
+ if (theme.type === "from-css" && !finalTheme.colorNames) {
299
+ const colorNames = {};
300
+ let counter = 0;
301
+ finalTheme.settings = finalTheme.settings.map((s) => {
302
+ const setting = Object.assign(Object.assign({}, s), { settings: Object.assign({}, s.settings) });
303
+ const { foreground, background } = setting.settings || {};
304
+ if (foreground && !colorNames[foreground]) {
305
+ colorNames[foreground] = `#${counter.toString(16).padStart(6, "0")}`;
306
+ counter++;
307
+ }
308
+ if (background && !colorNames[background]) {
309
+ colorNames[background] = `#${counter.toString(16).padStart(6, "0")}`;
310
+ counter++;
311
+ }
312
+ if (foreground) {
313
+ setting.settings.foreground = colorNames[foreground];
314
+ }
315
+ if (background) {
316
+ setting.settings.background = colorNames[background];
317
+ }
318
+ return setting;
319
+ });
320
+ finalTheme.colorNames = colorNames;
321
+ }
298
322
return finalTheme;
299
323
}
300
324
function getColorScheme(theme) {
301
325
var _a;
326
+ if (theme.type === "from-css") {
327
+ return "from-css";
328
+ }
302
329
const themeType = theme.type
303
330
? theme.type
304
331
: ((_a = theme.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes("light"))
@@ -317,10 +344,12 @@ const THEME_NAMES = [
317
344
"dracula",
318
345
"github-dark",
319
346
"github-dark-dimmed",
347
+ "github-from-css",
320
348
"github-light",
321
349
"light-plus",
322
350
"material-darker",
323
351
"material-default",
352
+ "material-from-css",
324
353
"material-lighter",
325
354
"material-ocean",
326
355
"material-palenight",
@@ -335,7 +364,7 @@ const THEME_NAMES = [
335
364
"solarized-dark",
336
365
"solarized-light",
337
366
];
338
- class UnknownThemeError$1 extends Error {
367
+ class UnknownThemeError extends Error {
339
368
constructor(theme) {
340
369
super(`Unknown theme: ${theme}`);
341
370
this.theme = theme;
@@ -2582,9 +2611,18 @@ class UnknownLanguageError extends Error {
2582
2611
}
2583
2612
function highlightTokens(code, grammar, theme) {
2584
2613
registry.setTheme(theme);
2585
- const colorMap = registry. getColorMap();
2614
+ const colorMap = getColorMap(theme );
2586
2615
return tokenize(code, grammar, colorMap);
2587
2616
}
2617
+ function getColorMap(theme) {
2618
+ const colorMap = registry.getColorMap();
2619
+ if (!theme.colorNames)
2620
+ return colorMap;
2621
+ return colorMap.map((c) => {
2622
+ const key = Object.keys(theme.colorNames).find((key) => theme.colorNames[key].toUpperCase() === c.toUpperCase());
2623
+ return key || c;
2624
+ });
2625
+ }
2588
2626
function highlightTokensWithScopes(code, grammar, theme) {
2589
2627
registry.setTheme(theme);
2590
2628
const colorMap = registry.getColorMap();
@@ -3054,12 +3092,6 @@ function splitAnnotations(annotations) {
3054
3092
};
3055
3093
}
3056
3094
3057
- class UnknownThemeError extends Error {
3058
- constructor(theme) {
3059
- super(`Unknown theme: ${theme}`);
3060
- this.theme = theme;
3061
- }
3062
- }
3063
3095
function isAnnotatedConfig(config) {
3064
3096
return "annotations" in config;
3065
3097
}
0 commit comments