mirror of
https://github.com/Tyriar/vscode-theme-generator.git
synced 2025-12-07 09:36:11 -08:00
Implement fallbacks
This commit is contained in:
@@ -2,17 +2,19 @@ export interface IThemeGenerator {
|
||||
generateTheme(name: string, colorSet: IColorSet): string;
|
||||
}
|
||||
|
||||
export interface IBaseColorSet {
|
||||
/** The default background color */
|
||||
background: string;
|
||||
/** The default foreground color */
|
||||
foreground: string;
|
||||
color1: string;
|
||||
color2: string;
|
||||
color3: string;
|
||||
color4: string;
|
||||
}
|
||||
|
||||
export interface IColorSet {
|
||||
base: {
|
||||
/** The default background color */
|
||||
background: string;
|
||||
/** The default foreground color */
|
||||
foreground: string;
|
||||
accent1: string;
|
||||
accent2: string;
|
||||
accent3: string;
|
||||
accent4: string;
|
||||
},
|
||||
base: IBaseColorSet,
|
||||
syntax?: {
|
||||
boolean?: string;
|
||||
function?: string;
|
||||
@@ -27,7 +29,6 @@ export interface IColorSet {
|
||||
classMember?: string;
|
||||
type?: string;
|
||||
modifier?: string;
|
||||
this?: string;
|
||||
cssClass?: string;
|
||||
cssId?: string;
|
||||
cssTag?: string;
|
||||
@@ -56,7 +57,7 @@ export interface IColorSet {
|
||||
wordHighlightStrong?: string;
|
||||
activeLinkForeground?: string;
|
||||
},
|
||||
terminal: {
|
||||
terminal?: {
|
||||
black?: string;
|
||||
red?: string;
|
||||
green?: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IColorSet, IThemeGenerator } from './interfaces'
|
||||
import { IColorSet, IThemeGenerator, IBaseColorSet } from './interfaces'
|
||||
|
||||
export interface IVscodeJsonTheme {
|
||||
name?: string;
|
||||
@@ -24,6 +24,15 @@ interface IRuleGenerator {
|
||||
generate: ColorGenerator;
|
||||
}
|
||||
|
||||
type ColorFetcher = (colorSet: IColorSet) => string;
|
||||
type FallbackFetcher = (baseColorSet: IBaseColorSet) => string;
|
||||
|
||||
interface IRuleGenerator2 {
|
||||
color: ColorFetcher;
|
||||
fallback: FallbackFetcher;
|
||||
generate: ColorGenerator;
|
||||
}
|
||||
|
||||
enum FontStyle {
|
||||
NONE = 0,
|
||||
ITALIC = 1 << 0,
|
||||
@@ -92,44 +101,118 @@ function getFontStyleGenerator(name: string, scope: string, fontStyle: number =
|
||||
}
|
||||
}
|
||||
|
||||
const vscodeJsonGlobalThemeRules: IRuleGenerator[] = [
|
||||
// Global settings
|
||||
{ source: set => set.base.background, generate: getGlobalSettingGenerator('background') },
|
||||
{ source: set => set.base.foreground, generate: getGlobalSettingGenerator('foreground') }
|
||||
const globalRules: IRuleGenerator2[] = [
|
||||
{ color: s => s.base.background, fallback: s => null, generate: getGlobalSettingGenerator('background') },
|
||||
{ color: s => s.base.foreground, fallback: s => null, generate: getGlobalSettingGenerator('foreground') }
|
||||
];
|
||||
|
||||
const vscodeColorRules: IRuleGenerator[] = [
|
||||
{ source: set => set.base.background, generate: getGlobalSettingGenerator('editorBackground') },
|
||||
{ source: set => set.base.foreground, generate: getGlobalSettingGenerator('editorForeground') },
|
||||
{ source: set => set.ui.cursor, generate: getGlobalSettingGenerator('editorCaret') },
|
||||
{ source: set => set.ui.guide, generate: getGlobalSettingGenerator('editorGuide') },
|
||||
{ source: set => set.ui.invisibles, generate: getGlobalSettingGenerator('editorInvisibles') },
|
||||
{ source: set => set.ui.findMatchHighlight, generate: getGlobalSettingGenerator('editorFindMatchHighlight') },
|
||||
{ source: set => set.ui.currentFindMatchHighlight, generate: getGlobalSettingGenerator('editorCurrentFindMatchHighlight') },
|
||||
{ source: set => set.ui.findRangeHighlight, generate: getGlobalSettingGenerator('editorFindRangeHighlight') },
|
||||
{ source: set => set.ui.rangeHighlight, generate: getGlobalSettingGenerator('editorRangeHighlight') },
|
||||
{ source: set => set.ui.selection, generate: getGlobalSettingGenerator('editorSelection') },
|
||||
{ source: set => set.ui.selectionHighlight, generate: getGlobalSettingGenerator('editorSelectionHighlight') },
|
||||
{ source: set => set.ui.wordHighlight, generate: getGlobalSettingGenerator('editorWordHighlight') },
|
||||
{ source: set => set.ui.wordHighlightStrong, generate: getGlobalSettingGenerator('editorWordHighlightStrong') },
|
||||
{ source: set => set.ui.activeLinkForeground, generate: getGlobalSettingGenerator('editorActiveLinkForeground') },
|
||||
// Terminal
|
||||
{ source: set => set.terminal.black, generate: getGlobalSettingGenerator('terminalAnsiBlack') },
|
||||
{ source: set => set.terminal.red, generate: getGlobalSettingGenerator('terminalAnsiRed') },
|
||||
{ source: set => set.terminal.green, generate: getGlobalSettingGenerator('terminalAnsiGreen') },
|
||||
{ source: set => set.terminal.yellow, generate: getGlobalSettingGenerator('terminalAnsiYellow') },
|
||||
{ source: set => set.terminal.blue, generate: getGlobalSettingGenerator('terminalAnsiBlue') },
|
||||
{ source: set => set.terminal.magenta, generate: getGlobalSettingGenerator('terminalAnsiMagenta') },
|
||||
{ source: set => set.terminal.cyan, generate: getGlobalSettingGenerator('terminalAnsiCyan') },
|
||||
{ source: set => set.terminal.white, generate: getGlobalSettingGenerator('terminalAnsiWhite') },
|
||||
{ source: set => set.terminal.brightBlack, generate: getGlobalSettingGenerator('terminalAnsiBrightBlack') },
|
||||
{ source: set => set.terminal.brightRed, generate: getGlobalSettingGenerator('terminalAnsiBrightRed') },
|
||||
{ source: set => set.terminal.brightGreen, generate: getGlobalSettingGenerator('terminalAnsiBrightGreen') },
|
||||
{ source: set => set.terminal.brightYellow, generate: getGlobalSettingGenerator('terminalAnsiBrightYellow') },
|
||||
{ source: set => set.terminal.brightBlue, generate: getGlobalSettingGenerator('terminalAnsiBrightBlue') },
|
||||
{ source: set => set.terminal.brightMagenta, generate: getGlobalSettingGenerator('terminalAnsiBrightMagenta') },
|
||||
{ source: set => set.terminal.brightCyan, generate: getGlobalSettingGenerator('terminalAnsiBrightCyan') },
|
||||
{ source: set => set.terminal.brightWhite, generate: getGlobalSettingGenerator('terminalAnsiBrightWhite') },
|
||||
const terminalRules: IRuleGenerator2[] = [
|
||||
{ color: s => s.terminal.black, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBlack') },
|
||||
{ color: s => s.terminal.red, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiRed') },
|
||||
{ color: s => s.terminal.green, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiGreen') },
|
||||
{ color: s => s.terminal.yellow, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiYellow') },
|
||||
{ color: s => s.terminal.blue, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBlue') },
|
||||
{ color: s => s.terminal.magenta, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiMagenta') },
|
||||
{ color: s => s.terminal.cyan, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiCyan') },
|
||||
{ color: s => s.terminal.white, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiWhite') },
|
||||
{ color: s => s.terminal.brightBlack, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightBlack') },
|
||||
{ color: s => s.terminal.brightRed, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightRed') },
|
||||
{ color: s => s.terminal.brightGreen, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightGreen') },
|
||||
{ color: s => s.terminal.brightYellow, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightYellow') },
|
||||
{ color: s => s.terminal.brightBlue, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightBlue') },
|
||||
{ color: s => s.terminal.brightMagenta, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightMagenta') },
|
||||
{ color: s => s.terminal.brightCyan, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightCyan') },
|
||||
{ color: s => s.terminal.brightWhite, fallback: s => null, generate: getGlobalSettingGenerator('terminalAnsiBrightWhite') }
|
||||
];
|
||||
|
||||
const colorRules: IRuleGenerator2[] = [
|
||||
{ color: s => s.base.background, fallback: s => null, generate: getGlobalSettingGenerator('editorBackground') },
|
||||
{ color: s => s.base.foreground, fallback: s => null, generate: getGlobalSettingGenerator('editorForeground') },
|
||||
{ color: s => s.ui.cursor, fallback: s => null, generate: getGlobalSettingGenerator('editorCaret') },
|
||||
{ color: s => s.ui.guide, fallback: s => lighten(s.background, 0.2), generate: getGlobalSettingGenerator('editorGuide') },
|
||||
{ color: s => s.ui.invisibles, fallback: s => lighten(s.background, 0.2), generate: getGlobalSettingGenerator('editorInvisibles') },
|
||||
{ color: s => s.ui.findMatchHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorFindMatchHighlight') },
|
||||
{ color: s => s.ui.currentFindMatchHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorCurrentFindMatchHighlight') },
|
||||
{ color: s => s.ui.findRangeHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorFindRangeHighlight') },
|
||||
{ color: s => s.ui.rangeHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorRangeHighlight') },
|
||||
{ color: s => s.ui.selection, fallback: s => null, generate: getGlobalSettingGenerator('editorSelection') },
|
||||
{ color: s => s.ui.selectionHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorSelectionHighlight') },
|
||||
{ color: s => s.ui.wordHighlight, fallback: s => null, generate: getGlobalSettingGenerator('editorWordHighlight') },
|
||||
{ color: s => s.ui.wordHighlightStrong, fallback: s => null, generate: getGlobalSettingGenerator('editorWordHighlightStrong') },
|
||||
{ color: s => s.ui.activeLinkForeground, fallback: s => null, generate: getGlobalSettingGenerator('editorActiveLinkForeground') },
|
||||
];
|
||||
|
||||
const tokenRules: IRuleGenerator2[] = [
|
||||
// string: It's important that string is put first so that other scopes can override strings
|
||||
// within template expressions
|
||||
{ color: s => s.syntax.string, fallback: s => s.color2, generate: getSimpleColorGenerator('String', 'string') },
|
||||
{ color: s => s.syntax.boolean, fallback: s => s.color1, generate: getSimpleColorGenerator('Boolean', 'constant.language.boolean') },
|
||||
{ color: s => s.syntax.number, fallback: s => s.color4, generate: getSimpleColorGenerator('Number', 'constant.numeric') },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Identifier', 'variable, support.variable, support.class, support.constant, meta.definition.variable entity.name.function') },
|
||||
// support.type.object: module.exports (ts)
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('Keyword', 'keyword, modifier, variable.language.this, support.type.object, constant.language') },
|
||||
// support.function: eg. join in path.join in TypeScript
|
||||
{ color: s => s.syntax.functionCall, fallback: s => s.color4, generate: getSimpleColorGenerator('Function call', 'entity.name.function, support.function') },
|
||||
// storage.type: var (ts)
|
||||
// storage.modifier: private (ts)
|
||||
{ color: s => s.syntax.storage, fallback: s => s.color1, generate: getSimpleColorGenerator('Storage', 'storage.type, storage.modifier') },
|
||||
// module.support: imported modules in TypeScript
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Modules', 'support.module, support.node', FontStyle.ITALIC) },
|
||||
// support.type: `boolean` (ts)
|
||||
{ color: s => s.syntax.type, fallback: s => s.color3, generate: getSimpleColorGenerator('Type', 'support.type') },
|
||||
// entity.name.type: `: SomeType` (ts)
|
||||
{ color: s => s.syntax.type, fallback: s => s.color3, generate: getSimpleColorGenerator('Type', 'entity.name.type, entity.other.inherited-class') },
|
||||
{ color: s => s.syntax.comment, fallback: s => lighten(s.background, 2.0), generate: getSimpleColorGenerator('Comment', 'comment', FontStyle.ITALIC) },
|
||||
{ color: s => s.syntax.class, fallback: s => s.color3, generate: getSimpleColorGenerator('Class', 'entity.name.type.class', FontStyle.UNDERLINE) },
|
||||
{ color: s => s.syntax.classMember, fallback: s => s.color3, generate: getSimpleColorGenerator('Class variable', 'variable.object.property') },
|
||||
{ color: s => s.syntax.classMember, fallback: s => s.color3, generate: getSimpleColorGenerator('Class method', 'meta.definition.method entity.name.function') },
|
||||
{ color: s => s.syntax.function, fallback: s => s.color3, generate: getSimpleColorGenerator('Function definition', 'meta.function entity.name.function') },
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('Template expression', 'template.expression.begin, template.expression.end') },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('YAML key', 'entity.name.tag.yaml') },
|
||||
// modifier: This includes things like access modifiers, static, readonly, etc.
|
||||
{ color: s => s.syntax.modifier, fallback: s => null, generate: getSimpleColorGenerator('Modifier', 'modifier') },
|
||||
/**
|
||||
* JSON
|
||||
*/
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('JSON key', 'meta.object-literal.key, meta.object-literal.key string, support.type.property-name.json') },
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('JSON constant', 'constant.language.json') },
|
||||
/**
|
||||
* CSS
|
||||
*/
|
||||
{ color: s => s.syntax.cssClass, fallback: s => s.color1, generate: getSimpleColorGenerator('CSS class', 'entity.other.attribute-name.class') },
|
||||
{ color: s => s.syntax.cssId, fallback: s => s.color2, generate: getSimpleColorGenerator('CSS ID', 'entity.other.attribute-name.id') },
|
||||
{ color: s => s.syntax.cssTag, fallback: s => s.color3, generate: getSimpleColorGenerator('CSS tag', 'source.css entity.name.tag') },
|
||||
/**
|
||||
* HTML
|
||||
*/
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('HTML tag outer', 'meta.tag, punctuation.definition.tag') },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('HTML tag inner', 'entity.name.tag') },
|
||||
{ color: s => s.syntax.functionCall, fallback: s => s.color4, generate: getSimpleColorGenerator('HTML tag attribute', 'entity.other.attribute-name') },
|
||||
/**
|
||||
* Markdown
|
||||
*/
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('Markdown heading', 'markup.heading') },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Markdown link text', 'text.html.markdown meta.link.inline, meta.link.reference') },
|
||||
{ color: s => s.syntax.markdownQuote, fallback: s => darken(s.foreground, 0.5), generate: getSimpleColorGenerator('Markdown block quote', 'text.html.markdown markup.quote') },
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('Markdown list item', 'text.html.markdown beginning.punctuation.definition.list') },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Markdown italic', 'markup.italic', FontStyle.ITALIC) },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Markdown bold', 'markup.bold', FontStyle.BOLD) },
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('Markdown bold italic', 'markup.bold markup.italic, markup.italic markup.bold', FontStyle.BOLD | FontStyle.ITALIC) },
|
||||
/**
|
||||
* Ini
|
||||
*/
|
||||
{ color: s => s.syntax.identifier, fallback: s => lighten(s.color1, 0.5), generate: getSimpleColorGenerator('INI property name', 'keyword.other.definition.ini') },
|
||||
{ color: s => s.syntax.keyword, fallback: s => s.color1, generate: getSimpleColorGenerator('INI section title', 'entity.name.section.group-title.ini') },
|
||||
/**
|
||||
* C#
|
||||
*/
|
||||
{ color: s => s.syntax.class, fallback: s => s.color3, generate: getSimpleColorGenerator('C# class', 'source.cs meta.class.identifier storage.type', FontStyle.UNDERLINE) },
|
||||
{ color: s => s.syntax.classMember, fallback: s => s.color3, generate: getSimpleColorGenerator('C# class method', 'source.cs meta.method.identifier entity.name.function') },
|
||||
{ color: s => s.syntax.functionCall, fallback: s => s.color4, generate: getSimpleColorGenerator('C# function call', 'source.cs meta.method-call meta.method, source.cs entity.name.function') },
|
||||
{ color: s => s.syntax.type, fallback: s => s.color3, generate: getSimpleColorGenerator('C# type', 'source.cs storage.type') },
|
||||
{ color: s => s.syntax.type, fallback: s => s.color3, generate: getSimpleColorGenerator('C# return type', 'source.cs meta.method.return-type') }, // Lambda function returns do not use storage.type scope
|
||||
{ color: s => s.syntax.comment, fallback: s => lighten(s.background, 2.0), generate: getSimpleColorGenerator('C# preprocessor', 'source.cs meta.preprocessor') },
|
||||
{ color: s => s.base.foreground, fallback: s => null, generate: getSimpleColorGenerator('C# namespace', 'source.cs entity.name.type.namespace') } // Override generic entity.name.type rule
|
||||
];
|
||||
|
||||
// An ordered list of rules to be applied if the source conditions are met
|
||||
@@ -226,75 +309,89 @@ const vscodeJsonThemeRules: IRuleGenerator[] = [
|
||||
|
||||
export class VscodeThemeGenerator implements IThemeGenerator {
|
||||
public generateTheme(name: string, colorSet: IColorSet): string {
|
||||
const theme: IVscodeJsonTheme = {};
|
||||
theme.name = name;
|
||||
theme.tokenColors = [];
|
||||
// Fill in missing subsets to prevent NPEs
|
||||
if (!colorSet.syntax) colorSet.syntax = {};
|
||||
if (!colorSet.terminal) colorSet.terminal = {};
|
||||
if (!colorSet.ui) colorSet.ui = {};
|
||||
|
||||
const globalSetting: any = {
|
||||
const theme: IVscodeJsonTheme = {
|
||||
name: name,
|
||||
tokenColors: [],
|
||||
colors: {}
|
||||
};
|
||||
const globalSettings: any = {
|
||||
name: 'Global settings',
|
||||
settings: {}
|
||||
};
|
||||
vscodeJsonGlobalThemeRules.forEach(ruleGenerator => {
|
||||
const color = <string>ruleGenerator.source(colorSet);
|
||||
if (color) {
|
||||
const generated = ruleGenerator.generate(color);
|
||||
globalSetting.settings[Object.keys(generated)[0]] = color;
|
||||
}
|
||||
});
|
||||
theme.tokenColors.push(globalSetting);
|
||||
theme.tokenColors.push(globalSettings);
|
||||
|
||||
vscodeJsonThemeRules.forEach(ruleGenerator => {
|
||||
const color = <string>ruleGenerator.source(colorSet);
|
||||
tokenRules.forEach(generator => {
|
||||
const color = generator.color(colorSet) || generator.fallback(colorSet.base);
|
||||
if (color) {
|
||||
theme.tokenColors.push(ruleGenerator.generate(color));
|
||||
theme.tokenColors.push(generator.generate(color));
|
||||
}
|
||||
});
|
||||
|
||||
theme.colors = {};
|
||||
vscodeColorRules.forEach(ruleGenerator => {
|
||||
const color = <string>ruleGenerator.source(colorSet);
|
||||
// vscodeJsonThemeRules.forEach(ruleGenerator => {
|
||||
// const color = <string>ruleGenerator.source(colorSet);
|
||||
// if (color) {
|
||||
// theme.tokenColors.push(ruleGenerator.generate(color));
|
||||
// }
|
||||
// });
|
||||
|
||||
colorRules.concat(terminalRules).forEach(generator => {
|
||||
const color = generator.color(colorSet) || generator.fallback(colorSet.base);
|
||||
if (color) {
|
||||
const generated = ruleGenerator.generate(color);
|
||||
const generated = generator.generate(color);
|
||||
theme.colors[Object.keys(generated)[0]] = color;
|
||||
}
|
||||
});
|
||||
|
||||
theme.colors['tabsContainerBackground'] = this._lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['inactiveTabBackground'] = this._lighten(colorSet.base.background, 0.4);
|
||||
theme.colors['sideBarBackground'] = this._lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['panelBackground'] = this._lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['activityBarBackground'] = this._lighten(colorSet.base.background, 0.4);
|
||||
theme.colors['statusBarBackground'] = this._darken(colorSet.base.background, 0.2);
|
||||
globalRules.forEach(generator => {
|
||||
const color = generator.color(colorSet) || generator.fallback(colorSet.base);
|
||||
if (color) {
|
||||
const generated = generator.generate(color);
|
||||
globalSettings.settings[Object.keys(generated)[0]] = color;
|
||||
}
|
||||
});
|
||||
theme.tokenColors.push(globalSettings);
|
||||
|
||||
theme.colors['tabsContainerBackground'] = lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['inactiveTabBackground'] = lighten(colorSet.base.background, 0.4);
|
||||
theme.colors['sideBarBackground'] = lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['panelBackground'] = lighten(colorSet.base.background, 0.2);
|
||||
theme.colors['activityBarBackground'] = lighten(colorSet.base.background, 0.4);
|
||||
theme.colors['statusBarBackground'] = darken(colorSet.base.background, 0.2);
|
||||
// Peek editor
|
||||
theme.colors['editorPeekEditorBackground'] = this._darken(colorSet.base.background, 0.2);
|
||||
theme.colors['editorPeekEditorBackground'] = darken(colorSet.base.background, 0.2);
|
||||
|
||||
return JSON.stringify(theme);
|
||||
}
|
||||
|
||||
private _lighten(color: string, amount: number): string {
|
||||
const MAX = 255;
|
||||
let r = parseInt(color.substr(1, 2), 16);
|
||||
let g = parseInt(color.substr(3, 2), 16);
|
||||
let b = parseInt(color.substr(5, 2), 16);
|
||||
r = Math.floor(r + (r * amount));
|
||||
g = Math.floor(g + (g * amount));
|
||||
b = Math.floor(b + (b * amount));
|
||||
let rs = r.toString(16);
|
||||
if (rs.length === 1) {
|
||||
rs = '0' + rs;
|
||||
}
|
||||
let gs = g.toString(16);
|
||||
if (gs.length === 1) {
|
||||
gs = '0' + gs;
|
||||
}
|
||||
let bs = b.toString(16);
|
||||
if (bs.length === 1) {
|
||||
bs = '0' + bs;
|
||||
}
|
||||
return `#${rs}${gs}${bs}`;
|
||||
}
|
||||
|
||||
private _darken(color: string, amount: number): string {
|
||||
return this._lighten(color, -amount);
|
||||
}
|
||||
}
|
||||
|
||||
function lighten(color: string, amount: number): string {
|
||||
const MAX = 255;
|
||||
let r = parseInt(color.substr(1, 2), 16);
|
||||
let g = parseInt(color.substr(3, 2), 16);
|
||||
let b = parseInt(color.substr(5, 2), 16);
|
||||
r = Math.min(Math.floor(r + (r * amount)), MAX);
|
||||
g = Math.min(Math.floor(g + (g * amount)), MAX);
|
||||
b = Math.min(Math.floor(b + (b * amount)), MAX);
|
||||
let rs = r.toString(16);
|
||||
if (rs.length === 1) {
|
||||
rs = '0' + rs;
|
||||
}
|
||||
let gs = g.toString(16);
|
||||
if (gs.length === 1) {
|
||||
gs = '0' + gs;
|
||||
}
|
||||
let bs = b.toString(16);
|
||||
if (bs.length === 1) {
|
||||
bs = '0' + bs;
|
||||
}
|
||||
return `#${rs}${gs}${bs}`;
|
||||
}
|
||||
|
||||
function darken(color: string, amount: number): string {
|
||||
return lighten(color, -amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user