feat: persist complete multitheme palettes

This commit is contained in:
Simo committed 2026-07-12 14:49:36 +02:00
1 parent 3fd2a27719
commit 9cdd0b4000
4 files changed
+69 -21

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { presetSettings, settingKey } from "@/lib/theme-settings";
import { PRESETS, THEME_COLOR_KEYS } from "@/lib/theme-presets";
describe("theme settings mapping", () => {
it("keeps legacy light keys and suffixes dark keys", () => {
expect(settingKey("color_primary", "light")).toBe("color_primary");
expect(settingKey("color_primary", "dark")).toBe("color_primary_dark");
});
it("serializes every preset key for both modes without duplicates", () => {
const settings = presetSettings(PRESETS.Ocean);
const keys = settings.map(([key]) => key);
expect(settings).toHaveLength(THEME_COLOR_KEYS.length * 2);
expect(new Set(keys).size).toBe(keys.length);
for (const key of THEME_COLOR_KEYS) {
expect(keys).toContain(key);
expect(keys).toContain(`${key}_dark`);
}
});
});
+11
View File
@@ -0,0 +1,11 @@
import { THEME_COLOR_KEYS, type ThemeColorKey, type ThemeMode, type ThemePreset } from "@/lib/theme-presets";
export function settingKey(key: ThemeColorKey, mode: ThemeMode): string {
return mode === "light" ? key : `${key}_dark`;
}
export function presetSettings(preset: ThemePreset): Array<[string, string]> {
return (["light", "dark"] as const).flatMap((mode) =>
THEME_COLOR_KEYS.map((key) => [settingKey(key, mode), preset[mode][key]] as [string, string]),
);
}