Loading files
82965f623This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/stack-chan-374381865.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
82965f623This file is pinned to the selected release. Download the original to open it in your design tool.
export const THEME_STORAGE_KEY = 'stackchan.theme'
export const THEMES = ['light', 'dark', 'system'] as const
export type Theme = (typeof THEMES)[number]
export type ResolvedTheme = Exclude<Theme, 'system'>
export const normalizeTheme = (value: unknown): Theme | null =>
typeof value === 'string' && THEMES.includes(value as Theme) ? (value as Theme) : null
export const readTheme = (): Theme => {
try {
return normalizeTheme(globalThis.localStorage?.getItem(THEME_STORAGE_KEY)) ?? 'system'
} catch {
return 'system'
}
}
export const systemTheme = (): ResolvedTheme =>
globalThis.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
export const resolveTheme = (theme: Theme): ResolvedTheme => (theme === 'system' ? systemTheme() : theme)
export const applyTheme = (theme: Theme) => {
if (typeof document === 'undefined') return resolveTheme(theme)
const resolved = resolveTheme(theme)
document.documentElement.classList.remove('light', 'dark')
document.documentElement.classList.add(resolved)
document.documentElement.style.colorScheme = resolved
return resolved
}