2023-08-28 20:31:49 -04:00
|
|
|
export enum Themes {
|
|
|
|
Light = 'light',
|
|
|
|
Dark = 'dark',
|
|
|
|
System = 'system',
|
|
|
|
}
|
|
|
|
|
2023-08-31 09:34:13 -04:00
|
|
|
// Get the theme from the system settings manually
|
2023-08-28 20:31:49 -04:00
|
|
|
export function getSystemTheme(): Exclude<Themes, 'system'> {
|
2024-03-22 09:35:07 -04:00
|
|
|
return typeof globalThis.window !== 'undefined' &&
|
|
|
|
'matchMedia' in globalThis.window
|
2023-08-31 09:34:13 -04:00
|
|
|
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
|
|
? Themes.Dark
|
|
|
|
: Themes.Light
|
2023-08-28 20:31:49 -04:00
|
|
|
: Themes.Light
|
|
|
|
}
|
|
|
|
|
2023-08-31 09:34:13 -04:00
|
|
|
// Set the theme class on the body element
|
2023-08-28 20:31:49 -04:00
|
|
|
export function setThemeClass(theme: Themes) {
|
2023-08-31 09:34:13 -04:00
|
|
|
if (theme === Themes.Dark) {
|
2023-08-28 20:31:49 -04:00
|
|
|
document.body.classList.add('dark')
|
|
|
|
} else {
|
|
|
|
document.body.classList.remove('dark')
|
|
|
|
}
|
|
|
|
}
|
2024-03-22 09:35:07 -04:00
|
|
|
|
|
|
|
export function getThemeColorForEngine(theme: Themes) {
|
|
|
|
const resolvedTheme = theme === Themes.System ? getSystemTheme() : theme
|
|
|
|
const dark = 28 / 255
|
2024-04-15 13:40:09 -04:00
|
|
|
const light = 249 / 255
|
2024-03-22 09:35:07 -04:00
|
|
|
return resolvedTheme === Themes.Dark
|
|
|
|
? { r: dark, g: dark, b: dark, a: 1 }
|
|
|
|
: { r: light, g: light, b: light, a: 1 }
|
|
|
|
}
|