ph-utils 0.12.5 → 0.12.6
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/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/theme.d.ts +4 -3
- package/lib/theme.js +33 -17
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
@@ -14,8 +14,8 @@ export declare function shieldMobile(mobile: string): string;
|
|
14
14
|
* 验证参数是否是数字
|
15
15
|
* @param str 待验证的字符串
|
16
16
|
* @param numericParam 通过参数标记是否包含小数、正数
|
17
|
-
* @param numericParam.isPositive
|
18
|
-
* @param numericParam.isFloat
|
17
|
+
* @param numericParam.isPositive 是否是正数, 默认: false
|
18
|
+
* @param numericParam.isFloat 是否是小数, 默认: true
|
19
19
|
* @returns true 是数字, false 不是数字
|
20
20
|
*/
|
21
21
|
export declare function isNumeric(str: string, numericParam?: {
|
package/lib/index.js
CHANGED
@@ -37,8 +37,8 @@ export function shieldMobile(mobile) {
|
|
37
37
|
* 验证参数是否是数字
|
38
38
|
* @param str 待验证的字符串
|
39
39
|
* @param numericParam 通过参数标记是否包含小数、正数
|
40
|
-
* @param numericParam.isPositive
|
41
|
-
* @param numericParam.isFloat
|
40
|
+
* @param numericParam.isPositive 是否是正数, 默认: false
|
41
|
+
* @param numericParam.isFloat 是否是小数, 默认: true
|
42
42
|
* @returns true 是数字, false 不是数字
|
43
43
|
*/
|
44
44
|
export function isNumeric(str, numericParam) {
|
package/lib/theme.d.ts
CHANGED
@@ -4,13 +4,14 @@ export declare function getSystemTheme(): "dark" | "light" | "auto";
|
|
4
4
|
* 初始化主题, 让网页能够适应系统主题, 同时根据缓存的主题切换主题
|
5
5
|
* @returns 当前应用的主题
|
6
6
|
*/
|
7
|
-
export declare function initTheme(): Promise<
|
7
|
+
export declare function initTheme(): Promise<unknown>;
|
8
8
|
/**
|
9
9
|
* 切换主题, 通常用于预览
|
10
10
|
* @param theme 切换的主题
|
11
|
+
* @param transition 是否使用过渡动画, 注意浏览器必须支持 document.startViewTransition, 默认: true
|
11
12
|
* @returns 切换后的主题
|
12
13
|
*/
|
13
|
-
export declare function toggleTheme(theme?: "light" | "dark" | "auto"): Promise<
|
14
|
+
export declare function toggleTheme(theme?: "light" | "dark" | "auto", transition?: boolean): Promise<unknown>;
|
14
15
|
/** 获取当前主题 */
|
15
16
|
export declare function getTheme(): string;
|
16
17
|
/**
|
@@ -19,7 +20,7 @@ export declare function getTheme(): string;
|
|
19
20
|
* @param cache 是否缓存应用的主题, 让应用下一次启动的时候, 可以应用主题, 默认: true
|
20
21
|
* @returns 应用的主题
|
21
22
|
*/
|
22
|
-
export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<
|
23
|
+
export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<unknown>;
|
23
24
|
/** 获取当前主题色 */
|
24
25
|
export declare function getColorTheme(defaultValue?: string): string | undefined;
|
25
26
|
/**
|
package/lib/theme.js
CHANGED
@@ -33,25 +33,41 @@ export async function initTheme() {
|
|
33
33
|
/**
|
34
34
|
* 切换主题, 通常用于预览
|
35
35
|
* @param theme 切换的主题
|
36
|
+
* @param transition 是否使用过渡动画, 注意浏览器必须支持 document.startViewTransition, 默认: true
|
36
37
|
* @returns 切换后的主题
|
37
38
|
*/
|
38
|
-
export async function toggleTheme(theme) {
|
39
|
-
|
40
|
-
|
41
|
-
theme
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
export async function toggleTheme(theme, transition = true) {
|
40
|
+
return new Promise((resolve) => {
|
41
|
+
const classList = document.documentElement.classList;
|
42
|
+
if (theme == null) {
|
43
|
+
theme = getSystemTheme();
|
44
|
+
}
|
45
|
+
function updateThemeClass() {
|
46
|
+
if (theme === "light") {
|
47
|
+
classList.add("light");
|
48
|
+
classList.remove("dark");
|
49
|
+
}
|
50
|
+
else if (theme === "dark") {
|
51
|
+
classList.add("dark");
|
52
|
+
classList.remove("light");
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
classList.remove("light", "dark");
|
56
|
+
}
|
57
|
+
}
|
58
|
+
// @ts-ignore
|
59
|
+
if (transition && document.startViewTransition) {
|
60
|
+
// @ts-ignore
|
61
|
+
document.startViewTransition(() => {
|
62
|
+
updateThemeClass();
|
63
|
+
resolve(theme);
|
64
|
+
});
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
updateThemeClass();
|
68
|
+
resolve(theme);
|
69
|
+
}
|
70
|
+
});
|
55
71
|
}
|
56
72
|
/** 获取当前主题 */
|
57
73
|
export function getTheme() {
|