|
| 1 | +import { HighlightStyle, syntaxHighlighting } from "@codemirror/language"; |
| 2 | +import { EditorView } from "@codemirror/view"; |
| 3 | +import { tags as t } from "@lezer/highlight"; |
| 4 | + |
| 5 | +// Palette adapted from Tomorrow Night Bright (Chris Kempson) |
| 6 | +export const config = { |
| 7 | + name: "tomorrowNightBright", |
| 8 | + dark: true, |
| 9 | + background: "#000000", |
| 10 | + foreground: "#DEDEDE", |
| 11 | + selection: "#424242", |
| 12 | + cursor: "#9F9F9F", |
| 13 | + dropdownBackground: "#000000", |
| 14 | + dropdownBorder: "#343434", |
| 15 | + activeLine: "#2A2A2A", |
| 16 | + lineNumber: "#343434", |
| 17 | + lineNumberActive: "#DEDEDE", |
| 18 | + matchingBracket: "#2A2A2A", |
| 19 | + keyword: "#C397D8", |
| 20 | + storage: "#C397D8", |
| 21 | + variable: "#D54E53", |
| 22 | + parameter: "#E78C45", |
| 23 | + function: "#7AA6DA", |
| 24 | + string: "#B9CA4A", |
| 25 | + constant: "#E78C45", |
| 26 | + type: "#E7C547", |
| 27 | + class: "#E7C547", |
| 28 | + number: "#E78C45", |
| 29 | + comment: "#969896", |
| 30 | + heading: "#7AA6DA", |
| 31 | + invalid: "#DF5F5F", |
| 32 | + regexp: "#D54E53", |
| 33 | + operator: "#70C0B1", |
| 34 | + tag: "#D54E53", |
| 35 | +}; |
| 36 | + |
| 37 | +export const tomorrowNightBrightTheme = EditorView.theme( |
| 38 | + { |
| 39 | + "&": { |
| 40 | + color: config.foreground, |
| 41 | + backgroundColor: config.background, |
| 42 | + }, |
| 43 | + |
| 44 | + ".cm-content": { caretColor: config.cursor }, |
| 45 | + |
| 46 | + ".cm-cursor, .cm-dropCursor": { borderLeftColor: config.cursor }, |
| 47 | + "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": |
| 48 | + { backgroundColor: config.selection }, |
| 49 | + |
| 50 | + ".cm-panels": { |
| 51 | + backgroundColor: config.dropdownBackground, |
| 52 | + color: config.foreground, |
| 53 | + }, |
| 54 | + ".cm-panels.cm-panels-top": { |
| 55 | + borderBottom: `1px solid ${config.dropdownBorder}`, |
| 56 | + }, |
| 57 | + ".cm-panels.cm-panels-bottom": { |
| 58 | + borderTop: `1px solid ${config.dropdownBorder}`, |
| 59 | + }, |
| 60 | + |
| 61 | + ".cm-searchMatch": { |
| 62 | + backgroundColor: config.dropdownBackground, |
| 63 | + outline: `1px solid ${config.dropdownBorder}`, |
| 64 | + }, |
| 65 | + ".cm-searchMatch.cm-searchMatch-selected": { |
| 66 | + backgroundColor: config.selection, |
| 67 | + }, |
| 68 | + |
| 69 | + ".cm-activeLine": { backgroundColor: config.activeLine }, |
| 70 | + ".cm-selectionMatch": { backgroundColor: config.selection }, |
| 71 | + |
| 72 | + "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": { |
| 73 | + backgroundColor: config.matchingBracket, |
| 74 | + outline: "none", |
| 75 | + }, |
| 76 | + |
| 77 | + ".cm-gutters": { |
| 78 | + backgroundColor: config.background, |
| 79 | + color: config.foreground, |
| 80 | + border: "none", |
| 81 | + }, |
| 82 | + ".cm-activeLineGutter": { backgroundColor: config.background }, |
| 83 | + |
| 84 | + ".cm-lineNumbers .cm-gutterElement": { color: config.lineNumber }, |
| 85 | + ".cm-lineNumbers .cm-activeLineGutter": { color: config.lineNumberActive }, |
| 86 | + |
| 87 | + ".cm-foldPlaceholder": { |
| 88 | + backgroundColor: "transparent", |
| 89 | + border: "none", |
| 90 | + color: config.foreground, |
| 91 | + }, |
| 92 | + ".cm-tooltip": { |
| 93 | + border: `1px solid ${config.dropdownBorder}`, |
| 94 | + backgroundColor: config.dropdownBackground, |
| 95 | + color: config.foreground, |
| 96 | + }, |
| 97 | + ".cm-tooltip .cm-tooltip-arrow:before": { |
| 98 | + borderTopColor: "transparent", |
| 99 | + borderBottomColor: "transparent", |
| 100 | + }, |
| 101 | + ".cm-tooltip .cm-tooltip-arrow:after": { |
| 102 | + borderTopColor: config.foreground, |
| 103 | + borderBottomColor: config.foreground, |
| 104 | + }, |
| 105 | + ".cm-tooltip-autocomplete": { |
| 106 | + "& > ul > li[aria-selected]": { |
| 107 | + background: config.selection, |
| 108 | + color: config.foreground, |
| 109 | + }, |
| 110 | + }, |
| 111 | + }, |
| 112 | + { dark: config.dark }, |
| 113 | +); |
| 114 | + |
| 115 | +export const tomorrowNightBrightHighlightStyle = HighlightStyle.define([ |
| 116 | + { tag: t.keyword, color: config.keyword }, |
| 117 | + { |
| 118 | + tag: [t.name, t.deleted, t.character, t.macroName], |
| 119 | + color: config.variable, |
| 120 | + }, |
| 121 | + { tag: [t.propertyName], color: config.function }, |
| 122 | + { |
| 123 | + tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)], |
| 124 | + color: config.string, |
| 125 | + }, |
| 126 | + { tag: [t.function(t.variableName), t.labelName], color: config.function }, |
| 127 | + { |
| 128 | + tag: [t.color, t.constant(t.name), t.standard(t.name)], |
| 129 | + color: config.constant, |
| 130 | + }, |
| 131 | + { tag: [t.definition(t.name), t.separator], color: config.variable }, |
| 132 | + { tag: [t.className], color: config.class }, |
| 133 | + { |
| 134 | + tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace], |
| 135 | + color: config.number, |
| 136 | + }, |
| 137 | + { tag: [t.typeName], color: config.type }, |
| 138 | + { tag: [t.operator, t.operatorKeyword], color: config.operator }, |
| 139 | + { tag: [t.url, t.escape, t.regexp, t.link], color: config.regexp }, |
| 140 | + { tag: [t.meta, t.comment], color: config.comment }, |
| 141 | + { tag: t.tagName, color: config.tag }, |
| 142 | + { tag: t.strong, fontWeight: "bold" }, |
| 143 | + { tag: t.emphasis, fontStyle: "italic" }, |
| 144 | + { tag: t.link, textDecoration: "underline" }, |
| 145 | + { tag: t.heading, fontWeight: "bold", color: config.heading }, |
| 146 | + { tag: [t.atom, t.bool, t.special(t.variableName)], color: config.variable }, |
| 147 | + { tag: t.invalid, color: config.invalid }, |
| 148 | + { tag: t.strikethrough, textDecoration: "line-through" }, |
| 149 | +]); |
| 150 | + |
| 151 | +export function tomorrowNightBright() { |
| 152 | + return [ |
| 153 | + tomorrowNightBrightTheme, |
| 154 | + syntaxHighlighting(tomorrowNightBrightHighlightStyle), |
| 155 | + ]; |
| 156 | +} |
| 157 | + |
| 158 | +export default tomorrowNightBright; |
0 commit comments