ph-utils 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme.d.ts +4 -4
- package/lib/theme.js +9 -3
- package/package.json +1 -1
package/lib/theme.d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
/** 获取当前系统的主题 */
|
2
|
-
export declare function getSystemTheme(): "dark" | "light";
|
2
|
+
export declare function getSystemTheme(): "dark" | "light" | "auto";
|
3
3
|
/**
|
4
4
|
* 初始化主题, 让网页能够适应系统主题, 同时根据缓存的主题切换主题
|
5
5
|
* @returns 当前应用的主题
|
6
6
|
*/
|
7
|
-
export declare function initTheme(): Promise<"dark" | "light">;
|
7
|
+
export declare function initTheme(): Promise<"dark" | "light" | "auto">;
|
8
8
|
/**
|
9
9
|
* 切换主题, 通常用于预览
|
10
10
|
* @param theme 切换的主题
|
11
11
|
* @returns 切换后的主题
|
12
12
|
*/
|
13
|
-
export declare function toggleTheme(theme?: "light" | "dark" | "auto"): Promise<"dark" | "light">;
|
13
|
+
export declare function toggleTheme(theme?: "light" | "dark" | "auto"): Promise<"dark" | "light" | "auto">;
|
14
14
|
/** 获取当前主题 */
|
15
15
|
export declare function getTheme(): string;
|
16
16
|
/**
|
@@ -19,7 +19,7 @@ export declare function getTheme(): string;
|
|
19
19
|
* @param cache 是否缓存应用的主题, 让应用下一次启动的时候, 可以应用主题, 默认: true
|
20
20
|
* @returns 应用的主题
|
21
21
|
*/
|
22
|
-
export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<"dark" | "light">;
|
22
|
+
export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<"dark" | "light" | "auto">;
|
23
23
|
/** 获取当前主题色 */
|
24
24
|
export declare function getColorTheme(defaultValue?: string): string | undefined;
|
25
25
|
/**
|
package/lib/theme.js
CHANGED
@@ -4,7 +4,10 @@ export function getSystemTheme() {
|
|
4
4
|
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
5
5
|
return "dark";
|
6
6
|
}
|
7
|
-
|
7
|
+
else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
8
|
+
return "light";
|
9
|
+
}
|
10
|
+
return "auto";
|
8
11
|
}
|
9
12
|
/**
|
10
13
|
* 初始化主题, 让网页能够适应系统主题, 同时根据缓存的主题切换主题
|
@@ -33,10 +36,10 @@ export async function initTheme() {
|
|
33
36
|
* @returns 切换后的主题
|
34
37
|
*/
|
35
38
|
export async function toggleTheme(theme) {
|
36
|
-
|
39
|
+
const classList = document.documentElement.classList;
|
40
|
+
if (theme == null) {
|
37
41
|
theme = getSystemTheme();
|
38
42
|
}
|
39
|
-
const classList = document.documentElement.classList;
|
40
43
|
if (theme === "light") {
|
41
44
|
classList.add("light");
|
42
45
|
classList.remove("dark");
|
@@ -45,6 +48,9 @@ export async function toggleTheme(theme) {
|
|
45
48
|
classList.add("dark");
|
46
49
|
classList.remove("light");
|
47
50
|
}
|
51
|
+
else {
|
52
|
+
classList.remove("light", "dark");
|
53
|
+
}
|
48
54
|
return theme;
|
49
55
|
}
|
50
56
|
/** 获取当前主题 */
|