| 1 | // Terminal + sidebar palettes. |
| 2 | // |
| 3 | // One source of truth. `ui` becomes CSS custom properties on :root, `xterm` |
| 4 | // goes to term.options.theme — so the chrome and the terminal can never drift |
| 5 | // apart, which is the usual failure mode when a theme is half in CSS and half |
| 6 | // in JS. |
| 7 | // |
| 8 | // Pure data plus one function, so `node --test` can check the palettes are |
| 9 | // complete and actually readable. |
| 10 | |
| 11 | const THEMES = { |
| 12 | dark: { |
| 13 | name: "dark", |
| 14 | colorScheme: "dark", |
| 15 | ui: { |
| 16 | "--bg": "#14161a", |
| 17 | "--bg-panel": "#1c1f25", |
| 18 | "--bg-strip": "#191b21", |
| 19 | "--bg-input": "#14161a", |
| 20 | "--border": "#2d3138", |
| 21 | "--fg": "#d7dae0", |
| 22 | "--fg-muted": "#8b93a1", |
| 23 | "--accent": "#3b6ea5", |
| 24 | "--accent-hover": "#4a82bd", |
| 25 | "--accent-fg": "#ffffff", |
| 26 | "--ok": "#6ec177", |
| 27 | "--err": "#e06c75", |
| 28 | "--warn": "#d5a458", |
| 29 | "--warn-bg": "#241f16", |
| 30 | "--warn-border": "#4a3a22", |
| 31 | "--shadow": "rgba(0,0,0,.4)", |
| 32 | }, |
| 33 | xterm: { |
| 34 | background: "#14161a", |
| 35 | foreground: "#d7dae0", |
| 36 | cursor: "#d7dae0", |
| 37 | cursorAccent: "#14161a", |
| 38 | selectionBackground: "#3b6ea5", |
| 39 | selectionForeground: "#ffffff", |
| 40 | black: "#2d3138", |
| 41 | red: "#e06c75", |
| 42 | green: "#6ec177", |
| 43 | yellow: "#d5a458", |
| 44 | blue: "#61afef", |
| 45 | magenta: "#c678dd", |
| 46 | cyan: "#56b6c2", |
| 47 | white: "#d7dae0", |
| 48 | brightBlack: "#6b7280", |
| 49 | brightRed: "#ff7b86", |
| 50 | brightGreen: "#86d98f", |
| 51 | brightYellow: "#e8c07d", |
| 52 | brightBlue: "#7fb3e8", |
| 53 | brightMagenta: "#d7a3e8", |
| 54 | brightCyan: "#6fd0dd", |
| 55 | brightWhite: "#ffffff", |
| 56 | }, |
| 57 | }, |
| 58 | |
| 59 | light: { |
| 60 | name: "light", |
| 61 | colorScheme: "light", |
| 62 | ui: { |
| 63 | "--bg": "#ffffff", |
| 64 | "--bg-panel": "#f6f8fa", |
| 65 | "--bg-strip": "#e6e9ed", |
| 66 | "--bg-input": "#ffffff", |
| 67 | "--border": "#d0d7de", |
| 68 | "--fg": "#1f2328", |
| 69 | "--fg-muted": "#656d76", |
| 70 | "--accent": "#0969da", |
| 71 | "--accent-hover": "#0550ae", |
| 72 | "--accent-fg": "#ffffff", |
| 73 | "--ok": "#1a7f37", |
| 74 | "--err": "#cf222e", |
| 75 | "--warn": "#9a6700", |
| 76 | "--warn-bg": "#fff8c5", |
| 77 | "--warn-border": "#d4a72c", |
| 78 | "--shadow": "rgba(31,35,40,.15)", |
| 79 | }, |
| 80 | xterm: { |
| 81 | background: "#ffffff", |
| 82 | foreground: "#1f2328", |
| 83 | cursor: "#1f2328", |
| 84 | cursorAccent: "#ffffff", |
| 85 | selectionBackground: "#b6d7ff", |
| 86 | selectionForeground: "#1f2328", |
| 87 | // Deliberately the darker end of each hue: these sit on white, and the |
| 88 | // usual bright terminal colours are unreadable there. |
| 89 | black: "#1f2328", |
| 90 | red: "#cf222e", |
| 91 | green: "#116329", |
| 92 | yellow: "#7d4e00", |
| 93 | blue: "#0550ae", |
| 94 | magenta: "#8250df", |
| 95 | cyan: "#1b7c83", |
| 96 | white: "#6e7781", |
| 97 | brightBlack: "#57606a", |
| 98 | brightRed: "#a40e26", |
| 99 | brightGreen: "#1a7f37", |
| 100 | brightYellow: "#9a6700", |
| 101 | brightBlue: "#0969da", |
| 102 | brightMagenta: "#6639ba", |
| 103 | brightCyan: "#3192aa", |
| 104 | brightWhite: "#7f8894", |
| 105 | }, |
| 106 | }, |
| 107 | }; |
| 108 | |
| 109 | /** Preference values the UI offers, in cycle order. */ |
| 110 | const PREFERENCES = ["auto", "light", "dark"]; |
| 111 | |
| 112 | /** |
| 113 | * Resolve a stored preference to a concrete theme. |
| 114 | * `auto` follows the browser, which follows the OS. |
| 115 | * |
| 116 | * @param {string} preference one of PREFERENCES; anything else means `auto` |
| 117 | * @param {boolean} prefersDark what the browser says the OS wants |
| 118 | */ |
| 119 | function resolveTheme(preference, prefersDark) { |
| 120 | if (preference === "light") return THEMES.light; |
| 121 | if (preference === "dark") return THEMES.dark; |
| 122 | return prefersDark ? THEMES.dark : THEMES.light; |
| 123 | } |
| 124 | |
| 125 | const Themes = { THEMES, PREFERENCES, resolveTheme }; |
| 126 | |
| 127 | if (typeof module !== "undefined" && module.exports) { |
| 128 | module.exports = Themes; |
| 129 | } |