|
| 1 | +import { EditorView } from "@codemirror/view" |
| 2 | +import { githubDark, githubLight } from "@uiw/codemirror-theme-github" |
| 3 | +import { dracula } from "@uiw/codemirror-theme-dracula" |
| 4 | +import { tokyoNight } from "@uiw/codemirror-theme-tokyo-night" |
| 5 | +import { nord } from "@uiw/codemirror-theme-nord" |
| 6 | +import { oneDark } from "@codemirror/theme-one-dark" |
| 7 | +import type { Extension } from "@codemirror/state" |
| 8 | + |
| 9 | +export const EDITOR_THEMES = [ |
| 10 | + { value: "github-dark", label: "GitHub Dark" }, |
| 11 | + { value: "github-light", label: "GitHub Light" }, |
| 12 | + { value: "dracula", label: "Dracula" }, |
| 13 | + { value: "tokyo-night", label: "Tokyo Night" }, |
| 14 | + { value: "nord", label: "Nord" }, |
| 15 | + { value: "one-dark", label: "One Dark" }, |
| 16 | +] as const |
| 17 | + |
| 18 | +export const EDITOR_FONTS = [ |
| 19 | + { value: "geist-mono", label: "Geist Mono", css: "var(--font-mono, ui-monospace, monospace)" }, |
| 20 | + { value: "jetbrains", label: "JetBrains Mono", css: "var(--font-jetbrains, 'JetBrains Mono', monospace)" }, |
| 21 | + { value: "fira-code", label: "Fira Code", css: "var(--font-fira, 'Fira Code', monospace)" }, |
| 22 | + { value: "ibm-plex", label: "IBM Plex Mono", css: "var(--font-ibm-plex, 'IBM Plex Mono', monospace)" }, |
| 23 | +] as const |
| 24 | + |
| 25 | +export type EditorTheme = (typeof EDITOR_THEMES)[number]["value"] |
| 26 | +export type EditorFont = (typeof EDITOR_FONTS)[number]["value"] |
| 27 | + |
| 28 | +export interface EditorPrefs { |
| 29 | + theme: EditorTheme |
| 30 | + font: EditorFont |
| 31 | +} |
| 32 | + |
| 33 | +export const DEFAULT_PREFS: EditorPrefs = { theme: "github-dark", font: "geist-mono" } |
| 34 | + |
| 35 | +export function getThemeExtension(theme: EditorTheme): Extension { |
| 36 | + switch (theme) { |
| 37 | + case "github-dark": return githubDark |
| 38 | + case "github-light": return githubLight |
| 39 | + case "dracula": return dracula |
| 40 | + case "tokyo-night": return tokyoNight |
| 41 | + case "nord": return nord |
| 42 | + case "one-dark": return oneDark |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +export function getFontCss(font: EditorFont): string { |
| 47 | + return EDITOR_FONTS.find((f) => f.value === font)?.css ?? EDITOR_FONTS[0].css |
| 48 | +} |
| 49 | + |
| 50 | +// Cleans up the line-number gutter across all themes: |
| 51 | +// transparent background, subtle separator, tabular-nums, muted color. |
| 52 | +export const cleanGutter = EditorView.theme({ |
| 53 | + ".cm-gutters": { |
| 54 | + backgroundColor: "transparent !important", |
| 55 | + borderRight: "1px solid rgba(128,128,128,0.10) !important", |
| 56 | + paddingRight: "0", |
| 57 | + }, |
| 58 | + ".cm-lineNumbers .cm-gutterElement": { |
| 59 | + fontVariantNumeric: "tabular-nums", |
| 60 | + paddingLeft: "12px", |
| 61 | + paddingRight: "14px", |
| 62 | + fontSize: "11.5px", |
| 63 | + color: "rgba(128,128,128,0.40)", |
| 64 | + minWidth: "2.75rem", |
| 65 | + userSelect: "none", |
| 66 | + }, |
| 67 | + ".cm-activeLineGutter": { |
| 68 | + backgroundColor: "transparent !important", |
| 69 | + color: "rgba(128,128,128,0.70) !important", |
| 70 | + }, |
| 71 | +}) |
0 commit comments