|
| 1 | +import { HighlightStyle, syntaxHighlighting } from "@codemirror/language"; |
| 2 | +import { EditorView } from "@codemirror/view"; |
| 3 | +import { tags as t } from "@lezer/highlight"; |
| 4 | + |
| 5 | +export const config = { |
| 6 | + name: "cobalt", |
| 7 | + dark: true, |
| 8 | + background: "#002240", |
| 9 | + foreground: "#ffffff", |
| 10 | + selection: "#b3653966", |
| 11 | + cursor: "#ffffff", |
| 12 | + dropdownBackground: "#001b33", |
| 13 | + dropdownBorder: "#0088ff", |
| 14 | + activeLine: "#ffffff0d", |
| 15 | + lineNumber: "#7285b7", |
| 16 | + lineNumberActive: "#ffffff", |
| 17 | + matchingBracket: "#00aaff66", |
| 18 | + keyword: "#ffee80", |
| 19 | + storage: "#ff9d00", |
| 20 | + variable: "#ffffff", |
| 21 | + parameter: "#ffffff", |
| 22 | + function: "#ffc600", |
| 23 | + string: "#3ad900", |
| 24 | + constant: "#ff628c", |
| 25 | + type: "#80ffbb", |
| 26 | + class: "#80ffbb", |
| 27 | + number: "#ff628c", |
| 28 | + comment: "#0088ff", |
| 29 | + heading: "#ffc600", |
| 30 | + invalid: "#f8f8f8", |
| 31 | + regexp: "#80ffc2", |
| 32 | +}; |
| 33 | + |
| 34 | +export const cobaltTheme = EditorView.theme( |
| 35 | + { |
| 36 | + "&": { color: config.foreground, backgroundColor: config.background }, |
| 37 | + ".cm-content": { caretColor: config.cursor }, |
| 38 | + ".cm-cursor, .cm-dropCursor": { borderLeftColor: config.cursor }, |
| 39 | + "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": |
| 40 | + { backgroundColor: config.selection }, |
| 41 | + ".cm-panels": { |
| 42 | + backgroundColor: config.dropdownBackground, |
| 43 | + color: config.foreground, |
| 44 | + }, |
| 45 | + ".cm-panels.cm-panels-top": { |
| 46 | + borderBottom: `1px solid ${config.dropdownBorder}`, |
| 47 | + }, |
| 48 | + ".cm-panels.cm-panels-bottom": { |
| 49 | + borderTop: `1px solid ${config.dropdownBorder}`, |
| 50 | + }, |
| 51 | + ".cm-searchMatch": { |
| 52 | + backgroundColor: config.matchingBracket, |
| 53 | + outline: `1px solid ${config.dropdownBorder}`, |
| 54 | + }, |
| 55 | + ".cm-searchMatch.cm-searchMatch-selected, .cm-selectionMatch": { |
| 56 | + backgroundColor: config.selection, |
| 57 | + }, |
| 58 | + ".cm-activeLine": { backgroundColor: config.activeLine }, |
| 59 | + "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": { |
| 60 | + backgroundColor: config.matchingBracket, |
| 61 | + }, |
| 62 | + ".cm-gutters": { |
| 63 | + backgroundColor: config.background, |
| 64 | + color: config.lineNumber, |
| 65 | + border: "none", |
| 66 | + }, |
| 67 | + ".cm-activeLineGutter": { backgroundColor: config.activeLine }, |
| 68 | + ".cm-lineNumbers .cm-activeLineGutter": { color: config.lineNumberActive }, |
| 69 | + ".cm-foldPlaceholder": { |
| 70 | + backgroundColor: "transparent", |
| 71 | + border: "none", |
| 72 | + color: config.foreground, |
| 73 | + }, |
| 74 | + ".cm-tooltip": { |
| 75 | + border: `1px solid ${config.dropdownBorder}`, |
| 76 | + backgroundColor: config.dropdownBackground, |
| 77 | + color: config.foreground, |
| 78 | + }, |
| 79 | + ".cm-tooltip-autocomplete > ul > li[aria-selected]": { |
| 80 | + background: config.selection, |
| 81 | + color: config.foreground, |
| 82 | + }, |
| 83 | + }, |
| 84 | + { dark: config.dark }, |
| 85 | +); |
| 86 | + |
| 87 | +export const cobaltHighlightStyle = HighlightStyle.define([ |
| 88 | + { tag: t.keyword, color: config.keyword }, |
| 89 | + { tag: [t.modifier, t.definitionKeyword], color: config.storage }, |
| 90 | + { |
| 91 | + tag: [t.name, t.deleted, t.character, t.macroName], |
| 92 | + color: config.variable, |
| 93 | + }, |
| 94 | + { |
| 95 | + tag: [t.propertyName, t.function(t.variableName), t.labelName], |
| 96 | + color: config.function, |
| 97 | + }, |
| 98 | + { |
| 99 | + tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)], |
| 100 | + color: config.string, |
| 101 | + }, |
| 102 | + { |
| 103 | + tag: [t.color, t.constant(t.name), t.standard(t.name), t.atom, t.bool], |
| 104 | + color: config.constant, |
| 105 | + }, |
| 106 | + { tag: [t.className, t.typeName], color: config.type }, |
| 107 | + { |
| 108 | + tag: [t.number, t.changed, t.annotation, t.self, t.namespace], |
| 109 | + color: config.number, |
| 110 | + }, |
| 111 | + { tag: [t.operator, t.operatorKeyword], color: config.keyword }, |
| 112 | + { tag: [t.url, t.escape, t.regexp, t.link], color: config.regexp }, |
| 113 | + { tag: [t.meta, t.comment], color: config.comment, fontStyle: "italic" }, |
| 114 | + { tag: t.strong, fontWeight: "bold" }, |
| 115 | + { tag: t.emphasis, fontStyle: "italic" }, |
| 116 | + { tag: t.link, textDecoration: "underline" }, |
| 117 | + { tag: t.heading, fontWeight: "bold", color: config.heading }, |
| 118 | + { tag: t.invalid, color: config.invalid, backgroundColor: "#ff0000" }, |
| 119 | + { tag: t.strikethrough, textDecoration: "line-through" }, |
| 120 | +]); |
| 121 | + |
| 122 | +export function cobalt() { |
| 123 | + return [cobaltTheme, syntaxHighlighting(cobaltHighlightStyle)]; |
| 124 | +} |
| 125 | + |
| 126 | +export default cobalt; |
0 commit comments