@@ -87,7 +87,7 @@ function transparent(color, opacity) {
8787}
8888
8989function 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));
9191}
9292const colorNamesToKeys = {
9393 background: "editor.background",
@@ -231,7 +231,7 @@ async function preloadTheme(theme) {
231231 if (typeof theme === "string") {
232232 const name = theme;
233233 if (!THEME_NAMES.includes(name)) {
234- throw new UnknownThemeError$1 (name);
234+ throw new UnknownThemeError(name);
235235 }
236236 if (!promiseCache.has(name)) {
237237 const promise = reallyLoadThemeByName(name).then((theme) => {
@@ -269,7 +269,7 @@ function toFinalTheme(theme) {
269269 if (!theme) {
270270 return undefined;
271271 }
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 });
273273 const globalSetting = finalTheme.settings.find((s) => !s.name && !s.scope);
274274 if (globalSetting) {
275275 const { foreground, background } = globalSetting.settings || {};
@@ -295,10 +295,37 @@ function toFinalTheme(theme) {
295295 ...finalTheme.settings,
296296 ];
297297 }
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+ }
298322 return finalTheme;
299323}
300324function getColorScheme(theme) {
301325 var _a;
326+ if (theme.type === "from-css") {
327+ return "from-css";
328+ }
302329 const themeType = theme.type
303330 ? theme.type
304331 : ((_a = theme.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes("light"))
@@ -317,10 +344,12 @@ const THEME_NAMES = [
317344 "dracula",
318345 "github-dark",
319346 "github-dark-dimmed",
347+ "github-from-css",
320348 "github-light",
321349 "light-plus",
322350 "material-darker",
323351 "material-default",
352+ "material-from-css",
324353 "material-lighter",
325354 "material-ocean",
326355 "material-palenight",
@@ -335,7 +364,7 @@ const THEME_NAMES = [
335364 "solarized-dark",
336365 "solarized-light",
337366];
338- class UnknownThemeError$1 extends Error {
367+ class UnknownThemeError extends Error {
339368 constructor(theme) {
340369 super(`Unknown theme: ${theme}`);
341370 this.theme = theme;
@@ -2582,9 +2611,18 @@ class UnknownLanguageError extends Error {
25822611}
25832612function highlightTokens(code, grammar, theme) {
25842613 registry.setTheme(theme);
2585- const colorMap = registry. getColorMap();
2614+ const colorMap = getColorMap(theme );
25862615 return tokenize(code, grammar, colorMap);
25872616}
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+ }
25882626function highlightTokensWithScopes(code, grammar, theme) {
25892627 registry.setTheme(theme);
25902628 const colorMap = registry.getColorMap();
@@ -3054,12 +3092,6 @@ function splitAnnotations(annotations) {
30543092 };
30553093}
30563094
3057- class UnknownThemeError extends Error {
3058- constructor(theme) {
3059- super(`Unknown theme: ${theme}`);
3060- this.theme = theme;
3061- }
3062- }
30633095function isAnnotatedConfig(config) {
30643096 return "annotations" in config;
30653097}
0 commit comments