mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
style: fix formatting via prettier
This commit is contained in:
+15
-10
@@ -1,20 +1,22 @@
|
||||
export type ThemeChoice = 'light' | 'dark';
|
||||
export type ThemeChoice = "light" | "dark";
|
||||
|
||||
const STORAGE_KEY = 'theme';
|
||||
const STORAGE_KEY = "theme";
|
||||
|
||||
let theme = $state<ThemeChoice>('light');
|
||||
let theme = $state<ThemeChoice>("light");
|
||||
|
||||
function storage(): Storage | null {
|
||||
return typeof localStorage === 'undefined' ? null : localStorage;
|
||||
return typeof localStorage === "undefined" ? null : localStorage;
|
||||
}
|
||||
|
||||
function systemTheme(): ThemeChoice {
|
||||
if (typeof window === 'undefined' || !window.matchMedia) return 'light';
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
if (typeof window === "undefined" || !window.matchMedia) return "light";
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: "light";
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
if (typeof document === 'undefined') return;
|
||||
if (typeof document === "undefined") return;
|
||||
document.documentElement.dataset.theme = theme;
|
||||
}
|
||||
|
||||
@@ -34,8 +36,11 @@ export function setTheme(next: ThemeChoice): void {
|
||||
* чтобы кнопка в шапке отражала реальную тему.
|
||||
*/
|
||||
export function initTheme(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const attr = typeof document !== 'undefined' ? document.documentElement.dataset.theme : undefined;
|
||||
theme = attr === 'dark' || attr === 'light' ? attr : systemTheme();
|
||||
if (typeof window === "undefined") return;
|
||||
const attr =
|
||||
typeof document !== "undefined"
|
||||
? document.documentElement.dataset.theme
|
||||
: undefined;
|
||||
theme = attr === "dark" || attr === "light" ? attr : systemTheme();
|
||||
apply();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user