|
| 1 | +import { HighlightStyle, syntaxHighlighting } from "@codemirror/language"; |
| 2 | +import { EditorView } from "@codemirror/view"; |
| 3 | +import { tags as t } from "@lezer/highlight"; |
| 4 | + |
| 5 | +const palettes = { |
| 6 | + latte: { |
| 7 | + dark: false, |
| 8 | + rosewater: "#dc8a78", |
| 9 | + pink: "#ea76cb", |
| 10 | + mauve: "#8839ef", |
| 11 | + red: "#d20f39", |
| 12 | + peach: "#fe640b", |
| 13 | + yellow: "#df8e1d", |
| 14 | + green: "#40a02b", |
| 15 | + teal: "#179299", |
| 16 | + sky: "#04a5e5", |
| 17 | + blue: "#1e66f5", |
| 18 | + lavender: "#7287fd", |
| 19 | + text: "#4c4f69", |
| 20 | + subtext0: "#6c6f85", |
| 21 | + overlay2: "#7c7f93", |
| 22 | + overlay1: "#8c8fa1", |
| 23 | + overlay0: "#9ca0b0", |
| 24 | + surface2: "#acb0be", |
| 25 | + surface1: "#bcc0cc", |
| 26 | + surface0: "#ccd0da", |
| 27 | + base: "#eff1f5", |
| 28 | + mantle: "#e6e9ef", |
| 29 | + }, |
| 30 | + frappe: { |
| 31 | + dark: true, |
| 32 | + rosewater: "#f2d5cf", |
| 33 | + pink: "#f4b8e4", |
| 34 | + mauve: "#ca9ee6", |
| 35 | + red: "#e78284", |
| 36 | + peach: "#ef9f76", |
| 37 | + yellow: "#e5c890", |
| 38 | + green: "#a6d189", |
| 39 | + teal: "#81c8be", |
| 40 | + sky: "#99d1db", |
| 41 | + blue: "#8caaee", |
| 42 | + lavender: "#babbf1", |
| 43 | + text: "#c6d0f5", |
| 44 | + subtext0: "#a5adce", |
| 45 | + overlay2: "#949cbb", |
| 46 | + overlay1: "#838ba7", |
| 47 | + overlay0: "#737994", |
| 48 | + surface2: "#626880", |
| 49 | + surface1: "#51576d", |
| 50 | + surface0: "#414559", |
| 51 | + base: "#303446", |
| 52 | + mantle: "#292c3c", |
| 53 | + }, |
| 54 | + macchiato: { |
| 55 | + dark: true, |
| 56 | + rosewater: "#f4dbd6", |
| 57 | + pink: "#f5bde6", |
| 58 | + mauve: "#c6a0f6", |
| 59 | + red: "#ed8796", |
| 60 | + peach: "#f5a97f", |
| 61 | + yellow: "#eed49f", |
| 62 | + green: "#a6da95", |
| 63 | + teal: "#8bd5ca", |
| 64 | + sky: "#91d7e3", |
| 65 | + blue: "#8aadf4", |
| 66 | + lavender: "#b7bdf8", |
| 67 | + text: "#cad3f5", |
| 68 | + subtext0: "#a5adcb", |
| 69 | + overlay2: "#939ab7", |
| 70 | + overlay1: "#8087a2", |
| 71 | + overlay0: "#6e738d", |
| 72 | + surface2: "#5b6078", |
| 73 | + surface1: "#494d64", |
| 74 | + surface0: "#363a4f", |
| 75 | + base: "#24273a", |
| 76 | + mantle: "#1e2030", |
| 77 | + }, |
| 78 | + mocha: { |
| 79 | + dark: true, |
| 80 | + rosewater: "#f5e0dc", |
| 81 | + pink: "#f5c2e7", |
| 82 | + mauve: "#cba6f7", |
| 83 | + red: "#f38ba8", |
| 84 | + peach: "#fab387", |
| 85 | + yellow: "#f9e2af", |
| 86 | + green: "#a6e3a1", |
| 87 | + teal: "#94e2d5", |
| 88 | + sky: "#89dceb", |
| 89 | + blue: "#89b4fa", |
| 90 | + lavender: "#b4befe", |
| 91 | + text: "#cdd6f4", |
| 92 | + subtext0: "#a6adc8", |
| 93 | + overlay2: "#9399b2", |
| 94 | + overlay1: "#7f849c", |
| 95 | + overlay0: "#6c7086", |
| 96 | + surface2: "#585b70", |
| 97 | + surface1: "#45475a", |
| 98 | + surface0: "#313244", |
| 99 | + base: "#1e1e2e", |
| 100 | + mantle: "#181825", |
| 101 | + }, |
| 102 | +}; |
| 103 | + |
| 104 | +function createConfig(name, caption, palette) { |
| 105 | + return { |
| 106 | + name, |
| 107 | + caption, |
| 108 | + dark: palette.dark, |
| 109 | + background: palette.base, |
| 110 | + foreground: palette.text, |
| 111 | + selection: `${palette.overlay2}40`, |
| 112 | + selectionMatch: `${palette.surface2}4d`, |
| 113 | + cursor: palette.rosewater, |
| 114 | + dropdownBackground: palette.mantle, |
| 115 | + dropdownBorder: palette.overlay0, |
| 116 | + activeLine: palette.surface0, |
| 117 | + lineNumber: palette.subtext0, |
| 118 | + lineNumberActive: palette.mauve, |
| 119 | + matchingBracket: `${palette.surface2}47`, |
| 120 | + keyword: palette.mauve, |
| 121 | + variable: palette.text, |
| 122 | + parameter: palette.text, |
| 123 | + function: palette.blue, |
| 124 | + string: palette.green, |
| 125 | + constant: palette.peach, |
| 126 | + type: palette.yellow, |
| 127 | + class: palette.yellow, |
| 128 | + number: palette.peach, |
| 129 | + comment: palette.overlay2, |
| 130 | + heading: palette.blue, |
| 131 | + invalid: palette.red, |
| 132 | + regexp: palette.pink, |
| 133 | + tag: palette.blue, |
| 134 | + operator: palette.sky, |
| 135 | + palette, |
| 136 | + }; |
| 137 | +} |
| 138 | + |
| 139 | +export const configs = [ |
| 140 | + createConfig("catppuccinLatte", "Catppuccin Latte", palettes.latte), |
| 141 | + createConfig("catppuccinFrappe", "Catppuccin Frappé", palettes.frappe), |
| 142 | + createConfig( |
| 143 | + "catppuccinMacchiato", |
| 144 | + "Catppuccin Macchiato", |
| 145 | + palettes.macchiato, |
| 146 | + ), |
| 147 | + createConfig("catppuccinMocha", "Catppuccin Mocha", palettes.mocha), |
| 148 | +]; |
| 149 | + |
| 150 | +function createCatppuccinTheme(config) { |
| 151 | + const colors = config.palette; |
| 152 | + const theme = EditorView.theme( |
| 153 | + { |
| 154 | + "&": { |
| 155 | + color: config.foreground, |
| 156 | + backgroundColor: config.background, |
| 157 | + }, |
| 158 | + ".cm-content": { caretColor: config.cursor }, |
| 159 | + ".cm-cursor, .cm-dropCursor": { |
| 160 | + borderLeftColor: config.cursor, |
| 161 | + }, |
| 162 | + "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": |
| 163 | + { backgroundColor: config.selection }, |
| 164 | + ".cm-panels": { |
| 165 | + backgroundColor: config.dropdownBackground, |
| 166 | + color: config.foreground, |
| 167 | + }, |
| 168 | + ".cm-panels.cm-panels-top": { |
| 169 | + borderBottom: `1px solid ${config.dropdownBorder}`, |
| 170 | + }, |
| 171 | + ".cm-panels.cm-panels-bottom": { |
| 172 | + borderTop: `1px solid ${config.dropdownBorder}`, |
| 173 | + }, |
| 174 | + ".cm-searchMatch": { |
| 175 | + backgroundColor: `${colors.blue}59`, |
| 176 | + outline: `1px solid ${colors.blue}`, |
| 177 | + }, |
| 178 | + ".cm-searchMatch.cm-searchMatch-selected": { |
| 179 | + backgroundColor: `${colors.blue}2f`, |
| 180 | + }, |
| 181 | + ".cm-activeLine": { backgroundColor: config.activeLine }, |
| 182 | + ".cm-selectionMatch": { backgroundColor: config.selectionMatch }, |
| 183 | + "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": { |
| 184 | + backgroundColor: config.matchingBracket, |
| 185 | + color: config.foreground, |
| 186 | + }, |
| 187 | + ".cm-gutters": { |
| 188 | + backgroundColor: config.background, |
| 189 | + color: config.lineNumber, |
| 190 | + border: "none", |
| 191 | + }, |
| 192 | + ".cm-activeLineGutter": { backgroundColor: config.activeLine }, |
| 193 | + ".cm-lineNumbers .cm-gutterElement": { color: config.lineNumber }, |
| 194 | + ".cm-lineNumbers .cm-activeLineGutter": { |
| 195 | + color: config.lineNumberActive, |
| 196 | + }, |
| 197 | + ".cm-foldPlaceholder": { |
| 198 | + backgroundColor: "transparent", |
| 199 | + border: "none", |
| 200 | + color: colors.overlay0, |
| 201 | + }, |
| 202 | + ".cm-placeholder": { color: colors.overlay1 }, |
| 203 | + ".cm-tooltip": { |
| 204 | + border: "none", |
| 205 | + backgroundColor: colors.surface0, |
| 206 | + color: config.foreground, |
| 207 | + }, |
| 208 | + ".cm-tooltip-autocomplete": { |
| 209 | + "& > ul > li[aria-selected]": { |
| 210 | + backgroundColor: colors.surface1, |
| 211 | + color: config.foreground, |
| 212 | + }, |
| 213 | + }, |
| 214 | + }, |
| 215 | + { dark: config.dark }, |
| 216 | + ); |
| 217 | + |
| 218 | + const highlightStyle = HighlightStyle.define([ |
| 219 | + { tag: t.keyword, color: config.keyword }, |
| 220 | + { |
| 221 | + tag: [t.name, t.definition(t.name), t.deleted, t.character, t.macroName], |
| 222 | + color: config.variable, |
| 223 | + }, |
| 224 | + { |
| 225 | + tag: [ |
| 226 | + t.function(t.variableName), |
| 227 | + t.function(t.propertyName), |
| 228 | + t.propertyName, |
| 229 | + t.labelName, |
| 230 | + ], |
| 231 | + color: config.function, |
| 232 | + }, |
| 233 | + { |
| 234 | + tag: [t.color, t.constant(t.name), t.standard(t.name)], |
| 235 | + color: config.constant, |
| 236 | + }, |
| 237 | + { tag: [t.self, t.atom], color: colors.red }, |
| 238 | + { |
| 239 | + tag: [t.typeName, t.className, t.changed, t.annotation, t.namespace], |
| 240 | + color: config.type, |
| 241 | + }, |
| 242 | + { tag: t.operator, color: config.operator }, |
| 243 | + { tag: t.url, color: colors.teal }, |
| 244 | + { tag: [t.escape, t.regexp], color: config.regexp }, |
| 245 | + { |
| 246 | + tag: [t.meta, t.punctuation, t.separator, t.comment], |
| 247 | + color: config.comment, |
| 248 | + }, |
| 249 | + { tag: t.strong, fontWeight: "bold" }, |
| 250 | + { tag: t.emphasis, fontStyle: "italic" }, |
| 251 | + { tag: t.strikethrough, textDecoration: "line-through" }, |
| 252 | + { tag: t.link, color: config.function, textDecoration: "underline" }, |
| 253 | + { tag: t.heading, fontWeight: "bold", color: config.heading }, |
| 254 | + { tag: t.special(t.variableName), color: colors.lavender }, |
| 255 | + { tag: [t.bool, t.number], color: config.number }, |
| 256 | + { |
| 257 | + tag: [t.processingInstruction, t.string, t.inserted], |
| 258 | + color: config.string, |
| 259 | + }, |
| 260 | + { tag: t.invalid, color: config.invalid }, |
| 261 | + ]); |
| 262 | + |
| 263 | + return [theme, syntaxHighlighting(highlightStyle)]; |
| 264 | +} |
| 265 | + |
| 266 | +export const themes = new Map( |
| 267 | + configs.map((config) => [config.name, createCatppuccinTheme(config)]), |
| 268 | +); |
| 269 | + |
| 270 | +export default themes; |
0 commit comments