Files
yaak-mountain-loop/src-web/lib/theme/themes.ts
2024-09-25 07:35:27 -07:00

56 lines
1.6 KiB
TypeScript

import type { Appearance } from './appearance';
import { resolveAppearance } from './appearance';
import { catppuccin } from './themes/catppuccin';
import { github } from './themes/github';
import { hotdogStand } from './themes/hotdog-stand';
import { monokaiPro } from './themes/monokai-pro';
import { relaxing } from './themes/relaxing';
import { rosePine } from './themes/rose-pine';
import { yaak, yaakDark, yaakLight } from './themes/yaak';
import { isThemeDark } from './window';
export const defaultDarkTheme = yaakDark;
export const defaultLightTheme = yaakLight;
const allThemes = [
...yaak,
...catppuccin,
...relaxing,
...rosePine,
...github,
...monokaiPro,
...hotdogStand,
];
export function getThemes() {
const dark = defaultDarkTheme;
const light = defaultLightTheme;
const otherThemes = allThemes
.filter((t) => t.id !== dark.id && t.id !== light.id)
.sort((a, b) => a.name.localeCompare(b.name));
const themes = [dark, light, ...otherThemes];
return { themes, fallback: { dark, light } };
}
export function getResolvedTheme(
preferredAppearance: Appearance,
appearanceSetting: string,
themeLight: string,
themeDark: string,
) {
const appearance = resolveAppearance(preferredAppearance, appearanceSetting);
const { themes, fallback } = getThemes();
const darkThemes = themes.filter((t) => isThemeDark(t));
const lightThemes = themes.filter((t) => !isThemeDark(t));
const dark = darkThemes.find((t) => t.id === themeDark) ?? fallback.dark;
const light = lightThemes.find((t) => t.id === themeLight) ?? fallback.light;
const active = appearance === 'dark' ? dark : light;
return { dark, light, active };
}