ph-utils 0.12.5 → 0.12.7

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/dom.d.ts CHANGED
@@ -33,6 +33,15 @@ export declare function create(tag: string, option?: {
33
33
  outerHTML?: string;
34
34
  [index: string]: any;
35
35
  }, ctx?: DocumentContext): HTMLElement;
36
+ /** 创建节点 */
37
+ export declare function $$(tag: string, option?: {
38
+ class?: FormatClassParam;
39
+ style?: FormatStyleParam;
40
+ textContent?: string;
41
+ innerHTML?: string;
42
+ outerHTML?: string;
43
+ [index: string]: any;
44
+ }, ctx?: DocumentContext): HTMLElement;
36
45
  /**
37
46
  * 根据选择器获取匹配的第一个 DOM 元素。
38
47
  * @param selector - 选择器字符串或直接的 HTMLElement。
package/lib/dom.js CHANGED
@@ -67,6 +67,10 @@ export function create(tag, option = {}, ctx) {
67
67
  }
68
68
  return $el;
69
69
  }
70
+ /** 创建节点 */
71
+ export function $$(tag, option = {}, ctx) {
72
+ return create(tag, option, ctx);
73
+ }
70
74
  /**
71
75
  * 根据选择器获取匹配的第一个 DOM 元素。
72
76
  * @param selector - 选择器字符串或直接的 HTMLElement。
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<"dark" | "light" | "auto">;
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<"dark" | "light" | "auto">;
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<"dark" | "light" | "auto">;
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
- const classList = document.documentElement.classList;
40
- if (theme == null) {
41
- theme = getSystemTheme();
42
- }
43
- if (theme === "light") {
44
- classList.add("light");
45
- classList.remove("dark");
46
- }
47
- else if (theme === "dark") {
48
- classList.add("dark");
49
- classList.remove("light");
50
- }
51
- else {
52
- classList.remove("light", "dark");
53
- }
54
- return theme;
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() {
package/package.json CHANGED
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "./*": "./lib/*"
70
70
  },
71
- "version": "0.12.5",
71
+ "version": "0.12.7",
72
72
  "type": "module",
73
73
  "repository": {
74
74
  "type": "git",