code-theme-converter
Version:
Convert any vscode theme with ease!
106 lines (105 loc) • 4.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vscode_1 = require("../util/vscode");
function fromTokenColorToSublimeRule(tokenColor) {
var _a, _b, _c;
const mapFontStyle = (fontStyle) => {
switch (fontStyle) {
case undefined:
case 'normal':
return 0;
default:
return fontStyle;
}
};
return {
name: tokenColor.name,
foreground: (_a = tokenColor.settings) === null || _a === void 0 ? void 0 : _a.foreground,
background: (_b = tokenColor.settings) === null || _b === void 0 ? void 0 : _b.background,
font_style: mapFontStyle((_c = tokenColor.settings) === null || _c === void 0 ? void 0 : _c.fontStyle),
scope: Array.isArray(tokenColor.scope)
? tokenColor.scope.join(', ')
: tokenColor.scope
};
}
function toSublimeColorScheme(vscodeTheme) {
const { name, author = '', colors, tokenColors } = vscodeTheme;
const findEditorColorForField = vscode_1.findEditorColor(colors);
return {
name,
author,
globals: {
background: findEditorColorForField(['editor.background']),
foreground: findEditorColorForField(['editor.foreground']),
caret: findEditorColorForField([
'editorCursor.background',
'editor.foreground'
]),
block_caret: findEditorColorForField([
'editorCursor.background',
'editor.foreground'
]),
line_highlight: findEditorColorForField([
'editor.lineHighlightBackground'
]),
misspelling: findEditorColorForField(['editorError.foreground']),
fold_marker: findEditorColorForField(['list.highlightForeground']),
accent: findEditorColorForField(['list.highlightForeground']),
gutter: findEditorColorForField(['editorGutter.background']),
gutter_foreground: findEditorColorForField([
'editorLineNumber.foreground'
]),
line_diff_added: findEditorColorForField([
'diffEditor.insertedTextBackground',
'gitDecoration.addedResourceForeground'
]),
line_diff_modified: findEditorColorForField([
'diffEditor.modifiedTextBackground',
'gitDecoration.modifiedResourceForeground'
]),
line_diff_deleted: findEditorColorForField([
'diffEditor.removedTextBackground',
'gitDecoration.deletedResourceForeground'
]),
selection: findEditorColorForField(['editor.selectionBackground']),
inactive_selection: findEditorColorForField([
'list.inactiveSelectionBackground'
]),
inactive_selection_foreground: findEditorColorForField([
'list.inactiveSelectionForeground'
]),
highlight: findEditorColorForField([
'editor.findMatchHighlightBackground',
'peekViewEditor.matchHighlightBorder'
]),
find_highlight: findEditorColorForField([
'editor.findMatchHighlightBackground',
'peekViewEditor.matchHighlightBorder'
]),
find_highlight_foreground: findEditorColorForField([
'list.highlightForeground'
]),
guide: findEditorColorForField(['editorIndentGuide.background']),
active_guide: findEditorColorForField([
'breadcrumb.activeSelectionForeground'
]),
stack_guide: findEditorColorForField(['breadcrumb.foreground']),
brackets_foreground: findEditorColorForField(['selection.background']),
tags_foreground: findEditorColorForField(['selection.background']),
shadow: findEditorColorForField(['widget.shadow', 'scrollbar.shadow'])
},
variables: {
black: findEditorColorForField(['terminal.ansiBlack']),
white: findEditorColorForField(['terminal.ansiWhite']),
red: findEditorColorForField(['terminal.ansiRed']),
green: findEditorColorForField(['terminal.ansiGreen']),
yellow: findEditorColorForField(['terminal.ansiYellow']),
orange: findEditorColorForField(['terminal.ansiYellow']),
blue: findEditorColorForField(['terminal.ansiBlue']),
magenta: findEditorColorForField(['terminal.ansiMagenta']),
cyan: findEditorColorForField(['terminal.ansiCyan'])
},
rules: tokenColors.map(fromTokenColorToSublimeRule)
};
}
exports.toSublimeColorScheme = toSublimeColorScheme;