Add dark/light mode toggle and coolors.co palettes

Admin UI:
- system / light / dark switch in the sidebar (cycle button on
  mobile), stored in localStorage and applied before first paint
- dark mode now driven by data-theme instead of only the media query

Link page themes:
- keep the Midnight and Paper presets, replace the others with the
  4 trending palettes from coolors.co
- paste a coolors.co link (or a bare hex list) to use any palette;
  the colors are read from the URL, nothing is fetched
- palettes are mapped to background, text and button colors by
  contrast, with a dark/light background choice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 16:27:21 +02:00
co-authored by Claude Opus 5.5
parent 74ce76ab8b
commit 624517e010
13 changed files with 477 additions and 82 deletions
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { contrast, parseCoolorsInput, themeFromPalette, TRENDING_PALETTES } from "../src/web/lib/palette.js";
describe("coolors.co palettes", () => {
it("parses palette and generator links as well as bare color lists", () => {
const expected = ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"];
expect(parseCoolorsInput("https://coolors.co/palette/264653-2a9d8f-e9c46a-f4a261-e76f51")).toEqual(expected);
expect(parseCoolorsInput("https://coolors.co/264653-2a9d8f-e9c46a-f4a261-e76f51")).toEqual(expected);
expect(parseCoolorsInput("coolors.co/palette/264653-2A9D8F-e9c46a-f4a261-e76f51?ref=x")).toEqual(expected);
expect(parseCoolorsInput(" 264653-2a9d8f-e9c46a-f4a261-e76f51 ")).toEqual(expected);
});
it("rejects anything else", () => {
expect(parseCoolorsInput("")).toBeNull();
expect(parseCoolorsInput("https://example.com/264653-2a9d8f")).toBeNull();
expect(parseCoolorsInput("https://coolors.co/palettes/trending")).toBeNull();
expect(parseCoolorsInput("264653")).toBeNull();
expect(parseCoolorsInput("zzzzzz-2a9d8f")).toBeNull();
});
it("maps every trending palette to a readable theme in both variants", () => {
for (const { colors } of TRENDING_PALETTES) {
for (const variant of ["dark", "light"] as const) {
const theme = themeFromPalette(colors, variant);
expect(contrast(theme.text, theme.background)).toBeGreaterThanOrEqual(4.5);
expect(contrast(theme.buttonText, theme.button)).toBeGreaterThanOrEqual(4.5);
expect(theme.button).not.toBe(theme.background);
}
}
});
it("uses the darkest color as dark background and the lightest as light background", () => {
const colors = ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"];
expect(themeFromPalette(colors, "dark").background).toBe("#264653");
expect(themeFromPalette(colors, "light").background).toBe("#e9c46a");
});
});