UI: normalize light theme data token

This commit is contained in:
Vincent Koc 2026-03-11 01:19:10 -04:00
parent fece56306f
commit 5ab585ab4a
3 changed files with 22 additions and 1 deletions

View File

@ -216,4 +216,20 @@ describe("setTabFromRoute", () => {
listeners[0]?.({ matches: false } as MediaQueryListEvent);
expect(host.themeResolved).toBe("openknot-light");
});
it("normalizes light family themes to the shared light CSS token", async () => {
appSettings ??= await import("./app-settings.ts");
const root = {
dataset: {} as DOMStringMap,
style: { colorScheme: "" } as CSSStyleDeclaration & { colorScheme: string },
};
vi.stubGlobal("document", { documentElement: root } as Document);
const host = createHost("chat");
appSettings.applyResolvedTheme(host, "dash-light");
expect(host.themeResolved).toBe("dash-light");
expect(root.dataset.theme).toBe("light");
expect(root.style.colorScheme).toBe("light");
});
});

View File

@ -38,6 +38,7 @@ import { saveSettings, type UiSettings } from "./storage.ts";
import { startThemeTransition, type ThemeTransitionContext } from "./theme-transition.ts";
import {
colorSchemeForTheme,
dataThemeForTheme,
resolveTheme,
type ResolvedTheme,
type ThemeMode,
@ -299,7 +300,7 @@ export function applyResolvedTheme(host: SettingsHost, resolved: ResolvedTheme)
return;
}
const root = document.documentElement;
root.dataset.theme = resolved;
root.dataset.theme = dataThemeForTheme(resolved);
root.style.colorScheme = colorSchemeForTheme(resolved);
}

View File

@ -97,3 +97,7 @@ export function colorSchemeForTheme(theme: ResolvedTheme): "light" | "dark" {
? "light"
: "dark";
}
export function dataThemeForTheme(theme: ResolvedTheme): ResolvedTheme | "light" {
return colorSchemeForTheme(theme) === "light" ? "light" : theme;
}