Files
stack/apps/web/src/themes/registry.ts
Jason Woltje cfd1def4a9
All checks were successful
ci/woodpecker/push/web Pipeline was successful
feat(web): add theme definition system with 5 built-in themes (#493)
Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
2026-02-23 13:59:01 +00:00

51 lines
1.4 KiB
TypeScript

import { darkTheme } from "./dark";
import { draculaTheme } from "./dracula";
import { lightTheme } from "./light";
import { nordTheme } from "./nord";
import { solarizedDarkTheme } from "./solarized-dark";
import type { ThemeDefinition } from "./types";
/** All built-in themes, ordered for display */
const builtInThemes: ThemeDefinition[] = [
darkTheme,
lightTheme,
nordTheme,
draculaTheme,
solarizedDarkTheme,
];
const themeMap = new Map<string, ThemeDefinition>(builtInThemes.map((t) => [t.id, t]));
/** Default theme when no preference is set */
export const DEFAULT_THEME_ID = "dark";
/** Get all registered themes */
export function getAllThemes(): ThemeDefinition[] {
return [...builtInThemes];
}
/** Get a theme by ID, or undefined if not found */
export function getTheme(id: string): ThemeDefinition | undefined {
return themeMap.get(id);
}
/** Get a theme by ID, falling back to the default dark theme */
export function getThemeOrDefault(id: string): ThemeDefinition {
return themeMap.get(id) ?? darkTheme;
}
/** Get only dark themes */
export function getDarkThemes(): ThemeDefinition[] {
return builtInThemes.filter((t) => t.isDark);
}
/** Get only light themes */
export function getLightThemes(): ThemeDefinition[] {
return builtInThemes.filter((t) => !t.isDark);
}
/** Check if a theme ID is valid */
export function isValidThemeId(id: string): boolean {
return themeMap.has(id);
}