xonecas.io
8058
Ir

irvc / commit aba3c25

refactor: consolidate themeing paths

- builtin themes are now fuit based as well and work with skittles

xonecas2026-10-24 aba3c25870a79492fe3a72dab7ff9d3a365f8f3b parent a4f740b

8 files changed

fruit/README.md+3−0
@@ -3,6 +3,9 @@
33 * derived from https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/yaml
44 * run `npm run schemes` to rebuild
55
6+The built-in themes are fruit definitions too, but they are not files: they live
7+in `web/src/lib/fruit.ts` and are defaults only.
8+
69 The YAML format is an extension of the YAML format
710 used by [Gogh](https://github.com/Gogh-Co/Gogh/),
811 with the optional extra keys:
irvc.md+7−4
@@ -96,10 +96,13 @@ read_state (user_id, channel_id, last_read_message_id, updated_at)
9696 reference the roles. The shared vocabulary on top (`src/ui`) is buttons, inputs, fields,
9797 toggles, menus and lists — feature code composes those instead of inventing new Tailwind
9898 recipes, so the UI stays consistent by construction.
99-- **Theming.** `80s-nicotine` (sepia, default) and `tuxedo` (grayscale) are presets of those
100- colors, not fixed themes: any color can be overridden per light/dark mode from the
101- settings pane and is stored with the rest of the preferences. Mode, preset and overrides
102- are applied before first paint.
99+- **Theming.** One path from a theme to the colors: a fruit definition (background,
100+ foreground and 16 ANSI colors, the same shape as the terminal schemes in `fruit/`) is
101+ expanded into the palette tokens. The built-ins, `80s-nicotine` (sepia, default) and
102+ `tuxedo` (grayscale), are fruit definitions too (`src/lib/fruit.ts`), one per mode, so
103+ they are not special: any color can be overridden per light/dark mode from the settings
104+ pane and is stored with the rest of the preferences. Mode, palette and overrides are
105+ applied before first paint.
103106 - **No hover-only interactions.** Anything interactive is visible and reachable by tap and
104107 keyboard: per-message actions open from an always-present `⋯`, channel actions from a
105108 `⋯` menu, and the selected message's actions appear in a contextual bar above the
web/index.html+4−26
@@ -5,35 +5,13 @@
55 <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
66 <meta name="color-scheme" content="light dark" />
77 <script>
8- // Applied before first paint: mode, palette and the user's color
9- // overrides, plus their font-size preference.
8+ // Applied before first paint: the text size preference. The theme is
9+ // applied by applyTheme() from main.tsx, also before the first paint.
1010 (function () {
11- var prefs = null;
12- try {
13- prefs = JSON.parse(localStorage.getItem("irvc.theme"));
14- } catch (e) {
15- var legacy = localStorage.getItem("irvc.theme");
16- if (legacy === "light" || legacy === "dark") prefs = { mode: legacy };
17- else if (legacy === "tuxedo" || legacy === "nicotine") prefs = { preset: legacy };
18- }
19- if (!prefs || typeof prefs !== "object") {
20- prefs = { mode: matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" };
21- }
22- var el = document.documentElement;
23- el.classList.toggle("dark", prefs.mode === "dark");
24- el.dataset.preset = prefs.preset === "tuxedo" ? "tuxedo" : "nicotine";
25- var over = (prefs.overrides && prefs.overrides[prefs.mode]) || {};
26- for (var t in over) {
27- el.style.setProperty(
28- "--" + t.replace(/[A-Z]/g, function (c) {
29- return "-" + c.toLowerCase();
30- }),
31- over[t],
32- );
33- }
3411 try {
3512 var s = JSON.parse(localStorage.getItem("irvc.settings")) || {};
36- el.style.fontSize = { default: "", normal: "16px", large: "18px" }[s.fontSize] || "16px";
13+ document.documentElement.style.fontSize =
14+ { default: "", normal: "16px", large: "18px" }[s.fontSize] || "16px";
3715 } catch (e) {}
3816 })();
3917 </script>
web/src/index.css+5−52
@@ -24,63 +24,16 @@
2424 --color-scrim: var(--scrim);
2525 }
2626
27-/* ── palettes ──────────────────────────────────────────────────────────── */
27+/* ── palette ───────────────────────────────────────────────────────────── */
2828
29-/* 80s nicotine: sepia paper, the default. */
29+/* The palette variables are written by applyTheme() in lib/theme.ts, expanded
30+ from a fruit scheme (built-in in lib/fruit.ts, or a picked terminal scheme)
31+ plus the user's overrides. Only the scrim, a plain dimming overlay, is fixed. */
3032 :root {
31- --bg: #f6efe2;
32- --surface: #ece2cf;
33- --raised: #fdfaf3;
34- --fg: #4a3418;
35- --muted: #8a6f4a;
36- --faint: #b3a086;
37- --line: #ddceb4;
38- --accent: #a9791f;
39- --accent-fg: #fdfaf3;
40- --danger: #b4432f;
41- --scrim: rgb(20 12 4 / 0.5);
33+ --scrim: rgb(0 0 0 / 0.5);
4234 }
4335
4436 .dark {
45- --bg: #0b0906;
46- --surface: #100c08;
47- --raised: #1a130c;
48- --fg: #d8b98f;
49- --muted: #9c7d57;
50- --faint: #6d583c;
51- --line: #2a2016;
52- --accent: #ffcc55;
53- --accent-fg: #171109;
54- --danger: #e0715a;
55- --scrim: rgb(0 0 0 / 0.6);
56-}
57-
58-/* tuxedo: pure grayscale. */
59-[data-preset="tuxedo"] {
60- --bg: #ffffff;
61- --surface: #f1f1f1;
62- --raised: #ffffff;
63- --fg: #141414;
64- --muted: #666666;
65- --faint: #a0a0a0;
66- --line: #dcdcdc;
67- --accent: #333333;
68- --accent-fg: #ffffff;
69- --danger: #b3261e;
70- --scrim: rgb(0 0 0 / 0.4);
71-}
72-
73-.dark[data-preset="tuxedo"] {
74- --bg: #000000;
75- --surface: #0b0b0b;
76- --raised: #161616;
77- --fg: #e8e8e8;
78- --muted: #9a9a9a;
79- --faint: #6b6b6b;
80- --line: #272727;
81- --accent: #d4d4d4;
82- --accent-fg: #0a0a0a;
83- --danger: #e07a6a;
8437 --scrim: rgb(0 0 0 / 0.65);
8538 }
8639
web/src/lib/fruit.ts+110−0
@@ -0,0 +1,110 @@
1+import type { Scheme } from "./scheme";
2+
3+// The built-in themes, written as fruit definitions: the same { bg, fg, c }
4+// shape as the terminal schemes in schemes.json. Nothing downstream knows a
5+// built-in is special — the palette is toPalette(scheme) like any other, so
6+// there is one path from a theme to the CSS variables.
7+//
8+// The ANSI slots are not meant to be used as a terminal: the accent comes from
9+// the most colorful slot, and the danger from the red that reads best on the
10+// background, so those two are the slots worth tuning.
11+
12+type Variants = Record<"light" | "dark", Scheme>;
13+
14+export const nicotine: Variants = {
15+ light: {
16+ n: "80s nicotine",
17+ bg: "#f6efe2",
18+ fg: "#4a3418",
19+ c: [
20+ "#2b1c0c",
21+ "#b4432f", // danger
22+ "#6d7a45",
23+ "#a9791f", // accent
24+ "#4f6b86",
25+ "#8a5570",
26+ "#4a7a74",
27+ "#ece2cf",
28+ "#8a6f4a",
29+ "#c9795f",
30+ "#8a9a5f",
31+ "#c9a04a",
32+ "#6f8fae",
33+ "#b07a94",
34+ "#6aa39b",
35+ "#fdfaf3",
36+ ],
37+ },
38+ dark: {
39+ n: "80s nicotine dark",
40+ bg: "#0b0906",
41+ fg: "#d8b98f",
42+ c: [
43+ "#1a130c",
44+ "#e0715a", // danger
45+ "#7d8a5a",
46+ "#ffcc55", // accent
47+ "#6f8fae",
48+ "#b07a94",
49+ "#6aa39b",
50+ "#d8b98f",
51+ "#6d583c",
52+ "#8f4030",
53+ "#9aad6a",
54+ "#e0b060",
55+ "#8fafc9",
56+ "#cf9ab4",
57+ "#8ac9c1",
58+ "#f3e6d2",
59+ ],
60+ },
61+};
62+
63+export const tuxedo: Variants = {
64+ light: {
65+ n: "tuxedo",
66+ bg: "#ffffff",
67+ fg: "#141414",
68+ c: [
69+ "#000000",
70+ "#b3261e", // danger
71+ "#333333", // accent
72+ "#666666",
73+ "#4d4d4d",
74+ "#7a7a7a",
75+ "#8c8c8c",
76+ "#f1f1f1",
77+ "#a0a0a0",
78+ "#d07070",
79+ "#555555",
80+ "#777777",
81+ "#999999",
82+ "#b3b3b3",
83+ "#cccccc",
84+ "#ffffff",
85+ ],
86+ },
87+ dark: {
88+ n: "tuxedo dark",
89+ bg: "#000000",
90+ fg: "#e8e8e8",
91+ c: [
92+ "#0b0b0b",
93+ "#e07a6a", // danger
94+ "#d4d4d4", // accent
95+ "#9a9a9a",
96+ "#8a8a8a",
97+ "#7a7a7a",
98+ "#b0b0b0",
99+ "#272727",
100+ "#6b6b6b",
101+ "#8a4a3e",
102+ "#a0a0a0",
103+ "#c0c0c0",
104+ "#909090",
105+ "#b8b8b8",
106+ "#cccccc",
107+ "#ffffff",
108+ ],
109+ },
110+};
web/src/lib/scheme.ts+4−2
@@ -58,11 +58,13 @@ const COLORED = [1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14];
5858 export function toPalette(s: Scheme): Record<Token, string> {
5959 const { bg, fg, c } = s;
6060 const ok = (h: string) => contrast(h, bg) >= 3;
61+ const reds = [c[1], c[9]].sort((a, b) => contrast(b, bg) - contrast(a, bg));
62+ // The reds are the danger, never the accent: a grayscale scheme keeps its
63+ // gray accent and still gets a legible red.
6164 const accent =
6265 COLORED.map((i) => c[i])
63- .filter(ok)
66+ .filter((h) => ok(h) && !reds.includes(h))
6467 .sort((a, b) => chroma(b) - chroma(a))[0] ?? fg;
65- const reds = [c[1], c[9]].sort((a, b) => contrast(b, bg) - contrast(a, bg));
6668 return {
6769 bg,
6870 surface: mix(bg, fg, 0.05),
web/src/lib/theme.ts+19−27
@@ -1,10 +1,11 @@
11 import { useCallback, useEffect, useLayoutEffect, useState } from "react";
2+import { nicotine, tuxedo } from "./fruit";
23 import { SKITTLES, isDark, schemeColors, skittlesPalette, toPalette, type Scheme } from "./scheme";
34
45 export type Mode = "light" | "dark";
56
67 // Every color the UI uses. Palettes and user overrides are both just maps of
7-// these; the values live in index.css as CSS variables named "kebab of key".
8+// these; the values land as CSS variables named "kebab of key".
89 export const TOKENS = [
910 "bg",
1011 "surface",
@@ -34,7 +35,7 @@ export const tokenLabels: Record<Token, string> = {
3435 };
3536
3637 // "custom" is not a palette of its own: it layers the user's color overrides on
37-// top of `base`, the built-in palette that was active when custom was chosen.
38+// top of `base`, the built-in theme that was active when custom was chosen.
3839 export const presets = [
3940 { id: "nicotine", label: "80s nicotine" },
4041 { id: "tuxedo", label: "tuxedo" },
@@ -44,6 +45,10 @@ export const presets = [
4445 export type PresetId = (typeof presets)[number]["id"];
4546 export type BasePreset = Exclude<PresetId, "custom">;
4647
48+// The built-in themes are fruit definitions like any terminal scheme, so they
49+// are only ever a source of a palette, never CSS of their own.
50+const builtin: Record<BasePreset, Record<Mode, Scheme>> = { nicotine, tuxedo };
51+
4752 export interface ThemePrefs {
4853 mode: Mode;
4954 preset: PresetId;
@@ -105,25 +110,24 @@ export function loadPrefs(): ThemePrefs {
105110 };
106111 }
107112
108-// basePalette is the built-in palette whose CSS is in effect.
113+// basePalette is the built-in theme the palette comes from.
109114 const basePalette = (p: ThemePrefs): BasePreset => (p.preset === "custom" ? p.base : p.preset);
110115
111-// applyTheme writes the mode class, the preset attribute and the user's
112-// overrides onto <html>. The palettes themselves live in CSS, so switching
113-// preset is a single attribute change.
116+// palette is the scheme→tokens expansion of the built-in theme in effect.
117+const palette = (p: ThemePrefs) => toPalette(builtin[basePalette(p)][p.mode]);
118+
119+// applyTheme writes the mode class and every token onto <html>: the built-in
120+// theme's palette, with the user's overrides on top when the preset is custom.
114121 export function applyTheme(prefs: ThemePrefs) {
115122 const el = document.documentElement;
116123 el.classList.toggle("dark", prefs.mode === "dark");
117- el.dataset.preset = basePalette(prefs);
118- for (const t of TOKENS) {
119- const v = prefs.preset === "custom" ? prefs.overrides[prefs.mode][t] : undefined;
120- if (v) el.style.setProperty(cssVar(t), v);
121- else el.style.removeProperty(cssVar(t));
122- }
124+ const p = palette(prefs);
125+ const over = prefs.preset === "custom" ? prefs.overrides[prefs.mode] : {};
126+ for (const t of TOKENS) el.style.setProperty(cssVar(t), over[t] ?? p[t]);
123127 // Skittles: --user-N are only defined while it is on; userColor() falls back
124- // to the accent otherwise. Needs the resolved bg/fg, hence after the loop.
128+ // to the accent otherwise.
125129 const colors = prefs.skittles
126- ? skittlesPalette(prefs.scheme?.colors, effective("bg"), effective("fg"), basePalette(prefs))
130+ ? skittlesPalette(prefs.scheme?.colors, p.bg, p.fg, basePalette(prefs))
127131 : [];
128132 for (let i = 0; i < SKITTLES; i++) {
129133 if (colors[i]) el.style.setProperty(`--user-${i}`, colors[i]);
@@ -134,19 +138,7 @@ export function applyTheme(prefs: ThemePrefs) {
134138 // effective returns the color a token currently resolves to, so the theme
135139 // editor can seed its color inputs with the palette values.
136140 export function effective(t: Token): string {
137- const v = getComputedStyle(document.documentElement).getPropertyValue(cssVar(t)).trim();
138- if (v.startsWith("#")) return v.length === 4 ? expand(v) : v;
139- return rgbToHex(v);
140-}
141-
142-function expand(hex: string) {
143- return "#" + hex.slice(1).replace(/./g, (c) => c + c);
144-}
145-
146-function rgbToHex(color: string) {
147- const m = color.match(/(\d+)\D+(\d+)\D+(\d+)/);
148- if (!m) return "#000000";
149- return "#" + m.slice(1, 4).map((n) => Number(n).toString(16).padStart(2, "0")).join("");
141+ return getComputedStyle(document.documentElement).getPropertyValue(cssVar(t)).trim();
150142 }
151143
152144 export function useTheme() {
web/src/main.tsx+4−0
@@ -2,6 +2,10 @@ import { createRoot } from "react-dom/client";
22 import "./index.css";
33 import App from "./App";
44 import Toasts from "./components/Toasts";
5+import { applyTheme, loadPrefs } from "./lib/theme";
6+
7+// Before the first render, so the first paint already has the palette.
8+applyTheme(loadPrefs());
59
610 createRoot(document.getElementById("root")!).render(
711 <>