Six palettes, each with a light half and a dark one

The theme was one enum -- system, light, dark, ihasmail -- where one value
carried a whole palette and implied dark. That works for exactly one
palette. The two questions now come apart: which palette, and which side.

Classic is the plain light and dark this app has always had. ihasmail's
own palette gains a day version, so the background of the dark one becomes
the text of the light one and the two read as one palette from either end.
Dracula, Gruvbox, Rosé Pine and Tokyo Night are the work of their own
projects, used under the MIT licence, and taken from each project's own
repository rather than from anyone's reimplementation. What was fetched is
recorded in .palette-sources/ and credited in NOTICE.

Giving ihasmail's palette a light half removed a whole special case.
Nothing is one-sided any more, so a palette can no longer override the
mode, the toggle no longer has to set a palette aside on the way to light
and remember it, and the greyed-out control that explained all that is
gone. The old lastDarkTheme, which existed only for that, is gone with it.

The shades between the published colours are derived rather than guessed:
these projects publish twelve to twenty values and ihasmail needs about
thirty. scripts/build-palettes.py computes the tiers and then measures
every text colour against the surface it sits on -- 4.5:1 for prose, 3:1
for borders and marks -- lifting anything short towards white on a dark
ground and towards black on a light one, so a lifted tier keeps its hue.
It refuses to write a palette that would not pass.

Every one of the nine halves needed at least one lift. These palettes are
built for code editors, not for prose at this size: Dracula's comment grey
is 3.03:1 on its own background and Rosé Pine's gold is 2.7:1 on Dawn.
Shipping them as published would have quietly ended the WCAG AA claim.

Two things caught while checking rather than while writing. The generated
blocks were appended to the end of the stylesheet, which put them after
the accent variants at equal specificity -- so choosing an accent over one
of the new palettes did nothing at all. They now sit before those rules,
where the existing ihasmail block's own comment says they have to. And
that block was unqualified, so it would have shadowed the new light half;
it is now explicitly the dark one.

Settings written before this carry `theme` and no palette, and are read
through the old enum. `theme` is still written back, derived, because a
device on an older build reads it and would otherwise be stranded on a
theme nobody chose.
This commit is contained in:
2026-09-02 00:14:54 -07:00
parent 6c7c6d19b3
commit 9aa0eda0d5
12 changed files with 1207 additions and 104 deletions
+55 -42
View File
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_SETTINGS, DEVICE_KEYS, acceptRemote, isDarkTheme, syncedPart, toggleTarget, useSettings, type Theme } from "@/store/settings";
import { DEFAULT_SETTINGS, DEVICE_KEYS, acceptRemote, isDarkTheme, syncedPart, useSettings, type Theme } from "@/store/settings";
import { toggleTarget, type Mode, type PaletteId } from "@/lib/palette";
import { loadJson, saveJson, setDeviceTrusted } from "@/lib/storage";
/**
@@ -98,55 +99,49 @@ describe("the default theme", () => {
describe("the top-bar toggle", () => {
it("goes to light from anything dark", () => {
expect(toggleTarget("dark", "ihasmail")).toBe("light");
expect(toggleTarget("dark", "dark")).toBe("light");
expect(toggleTarget("dark", "system")).toBe("light");
expect(toggleTarget({ palette: "ihasmail", mode: "dark" }, false).mode).toBe("light");
expect(toggleTarget({ palette: "default", mode: "dark" }, false).mode).toBe("light");
expect(toggleTarget({ palette: "default", mode: "system" }, true).mode).toBe("light");
});
it("comes back to the theme you were actually on", () => {
// The whole point: two clicks from ihasmail must return to ihasmail, not
it("comes back to the palette you were actually on", () => {
// The whole point: two presses from ihasmail must return to ihasmail, not
// deposit you on plain dark.
expect(toggleTarget("light", "ihasmail")).toBe("ihasmail");
expect(toggleTarget("light", "dark")).toBe("dark");
});
it("can bring back \"match system\", which the toggle used to strand", () => {
expect(toggleTarget("light", "system")).toBe("system");
});
it("round-trips every dark theme there is", () => {
for (const t of ["dark", "ihasmail", "system"] as const) {
expect(toggleTarget(toggleTarget("light", t) === "light" ? "light" : "dark", t), t).toBe("light");
expect(toggleTarget("light", t), t).toBe(t);
}
const away = toggleTarget({ palette: "ihasmail", mode: "dark" }, false);
expect(toggleTarget(away, false).palette).toBe("ihasmail");
expect(toggleTarget({ palette: "default", mode: "light" }, false)).toMatchObject({ palette: "default", mode: "dark" });
});
});
describe("remembering which dark theme you were on", () => {
const setTheme = (t: Theme) => {
useSettings.getState().update({ theme: t });
describe("remembering the palette you were on", () => {
const set = (palette: PaletteId, mode: Mode) => {
useSettings.getState().update({ palette, mode });
return useSettings.getState().settings;
};
it("records a dark theme chosen from Settings, not just from the toggle", () => {
// update() is the single path every way of choosing a theme goes through,
// which is why the remembering lives there rather than at the call sites.
expect(setTheme("dark").lastDarkTheme).toBe("dark");
expect(setTheme("ihasmail").lastDarkTheme).toBe("ihasmail");
expect(setTheme("system").lastDarkTheme).toBe("system");
});
it("does not let light overwrite it — that is the theme being toggled away from", () => {
setTheme("ihasmail");
expect(setTheme("light").lastDarkTheme).toBe("ihasmail");
it("derives the legacy theme from whatever set the palette or mode", () => {
// `theme` is no longer chosen; it is kept in step so a device on an older
// build is not stranded on a theme nobody picked.
expect(set("default", "dark").theme).toBe("dark");
expect(set("ihasmail", "dark").theme).toBe("ihasmail");
expect(set("default", "system").theme).toBe("system");
expect(set("gruvbox", "light").theme).toBe("light");
expect(set("dracula", "dark").theme).toBe("dark");
});
it("survives a there-and-back through the toggle", () => {
setTheme("ihasmail");
const away = setTheme(toggleTarget("dark", useSettings.getState().settings.lastDarkTheme));
expect(away.theme).toBe("light");
const back = setTheme(toggleTarget("light", away.lastDarkTheme));
expect(back.theme).toBe("ihasmail");
// Two presses return you exactly where you started, and the palette never
// moves -- which is the whole of what the old lastDarkTheme existed for.
set("ihasmail", "dark");
const away = toggleTarget({ palette: "ihasmail", mode: "dark" }, false);
expect(away).toEqual({ palette: "ihasmail", mode: "light" });
expect(toggleTarget(away, false)).toEqual({ palette: "ihasmail", mode: "dark" });
});
it("keeps the colours when the palette has both sides", () => {
const away = toggleTarget({ palette: "gruvbox", mode: "dark" }, false);
expect(away.palette).toBe("gruvbox");
expect(away.mode).toBe("light");
});
});
@@ -159,12 +154,30 @@ describe("where the theme settings live", () => {
// its expectation would move too.
const synced = syncedPart(DEFAULT_SETTINGS);
expect(synced).toHaveProperty("theme");
expect(synced).toHaveProperty("lastDarkTheme");
expect(DEVICE_KEYS.has("theme")).toBe(false);
expect(DEVICE_KEYS.has("lastDarkTheme")).toBe(false);
expect(synced).toHaveProperty("palette");
expect(synced).toHaveProperty("mode");
for (const k of ["theme", "palette", "mode"] as const) {
expect(DEVICE_KEYS.has(k)).toBe(false);
}
});
it("is applied from a settings file another device wrote", () => {
expect(acceptRemote({ theme: "dark", lastDarkTheme: "dark" })).toEqual({ theme: "dark", lastDarkTheme: "dark" });
expect(acceptRemote({ palette: "gruvbox", mode: "light" })).toEqual({ palette: "gruvbox", mode: "light" });
});
it("reads a file written before palettes existed through the old enum", () => {
// Settings live in the account's Files and are opened by whatever version
// runs next, so this is not a one-release migration.
expect(acceptRemote({ theme: "ihasmail" })).toMatchObject({ palette: "ihasmail", mode: "dark" });
expect(acceptRemote({ theme: "light" })).toMatchObject({ palette: "default", mode: "light" });
});
it("prefers the new fields when a file carries both", () => {
// A file with both is newer, and its `theme` is the derived copy rather
// than the choice -- so it must not overrule the palette beside it.
expect(acceptRemote({ theme: "dark", palette: "rose-pine", mode: "light" })).toMatchObject({
palette: "rose-pine",
mode: "light",
});
});
});