ph-utils 0.20.1 → 1.1.0

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.
Files changed (74) hide show
  1. package/lib/browser.d.ts +439 -0
  2. package/lib/browser.js +890 -0
  3. package/lib/color-CUZrwrjD.js +206 -0
  4. package/lib/index.d.ts +615 -61
  5. package/lib/index.js +1539 -235
  6. package/lib/node.d.ts +115 -0
  7. package/lib/node.js +213 -0
  8. package/package.json +10 -64
  9. package/lib/array.d.ts +0 -79
  10. package/lib/array.js +0 -212
  11. package/lib/color.d.ts +0 -55
  12. package/lib/color.js +0 -294
  13. package/lib/config.d.ts +0 -33
  14. package/lib/config.js +0 -99
  15. package/lib/copy.d.ts +0 -11
  16. package/lib/copy.js +0 -101
  17. package/lib/crypto.d.ts +0 -74
  18. package/lib/crypto.js +0 -261
  19. package/lib/crypto_node.d.ts +0 -61
  20. package/lib/crypto_node.js +0 -133
  21. package/lib/date.d.ts +0 -66
  22. package/lib/date.js +0 -202
  23. package/lib/dom.d.ts +0 -265
  24. package/lib/dom.js +0 -645
  25. package/lib/file.d.ts +0 -29
  26. package/lib/file.js +0 -54
  27. package/lib/id.d.ts +0 -68
  28. package/lib/id.js +0 -170
  29. package/lib/logger.d.ts +0 -62
  30. package/lib/logger.js +0 -122
  31. package/lib/server.d.ts +0 -33
  32. package/lib/server.js +0 -65
  33. package/lib/src/array.d.ts +0 -79
  34. package/lib/src/array.js +0 -212
  35. package/lib/src/color.d.ts +0 -55
  36. package/lib/src/color.js +0 -294
  37. package/lib/src/config.d.ts +0 -33
  38. package/lib/src/config.js +0 -99
  39. package/lib/src/copy.d.ts +0 -11
  40. package/lib/src/copy.js +0 -101
  41. package/lib/src/crypto.d.ts +0 -74
  42. package/lib/src/crypto.js +0 -261
  43. package/lib/src/crypto_node.d.ts +0 -61
  44. package/lib/src/crypto_node.js +0 -133
  45. package/lib/src/date.d.ts +0 -66
  46. package/lib/src/date.js +0 -202
  47. package/lib/src/dom.d.ts +0 -265
  48. package/lib/src/dom.js +0 -635
  49. package/lib/src/file.d.ts +0 -29
  50. package/lib/src/file.js +0 -54
  51. package/lib/src/id.d.ts +0 -68
  52. package/lib/src/id.js +0 -170
  53. package/lib/src/index.d.ts +0 -154
  54. package/lib/src/index.js +0 -239
  55. package/lib/src/logger.d.ts +0 -62
  56. package/lib/src/logger.js +0 -122
  57. package/lib/src/server.d.ts +0 -33
  58. package/lib/src/server.js +0 -65
  59. package/lib/src/storage.d.ts +0 -51
  60. package/lib/src/storage.js +0 -73
  61. package/lib/src/theme.d.ts +0 -44
  62. package/lib/src/theme.js +0 -156
  63. package/lib/src/validator.d.ts +0 -71
  64. package/lib/src/validator.js +0 -238
  65. package/lib/src/web.d.ts +0 -30
  66. package/lib/src/web.js +0 -100
  67. package/lib/storage.d.ts +0 -51
  68. package/lib/storage.js +0 -73
  69. package/lib/theme.d.ts +0 -44
  70. package/lib/theme.js +0 -156
  71. package/lib/validator.d.ts +0 -71
  72. package/lib/validator.js +0 -248
  73. package/lib/web.d.ts +0 -30
  74. package/lib/web.js +0 -100
@@ -0,0 +1,439 @@
1
+ //#region src/dom.d.ts
2
+ /**
3
+ * web(浏览器端) DOM 文件操作
4
+ * 现今不推荐在使用这种方式,现在开发前端的时候,推荐使用一些成熟的框架例如:React、Preact、Vue、Angular、Svelte、Ember、Knockout等
5
+ * 在使用这些框架的时候额外的一些不可避免的 dom 操作时才使用这个工具;如果确实需要使用原生开发推荐使用 jquery 或者想要更精简的话可以使用 https://github.com/finom/bala 封装
6
+ */
7
+ /**
8
+ * 根据选择器获取节点
9
+ * @param {string} selector 选择器
10
+ */
11
+ type FormatStyleParam = (string | undefined | null)[] | Record<string, boolean | string | undefined | null> | string;
12
+ type FormatClassParam = (string | undefined | null | boolean)[] | Record<string, boolean | string | undefined | null | boolean> | string;
13
+ type DocumentContext = HTMLElement | ShadowRoot | Document;
14
+ type NodeChildren = HTMLElement | DocumentFragment | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollection;
15
+ declare function elem(selector: string | HTMLElement, dom?: DocumentContext): HTMLElement[];
16
+ /**
17
+ * 根据选择器获取 DOM 元素。
18
+ * @param selector - 选择器字符串或 HTMLElement 实例。
19
+ * @param dom - 可选参数,指定在哪个 DOM 节点下查找元素,默认为 document。
20
+ * @returns 返回匹配到的 HTMLElement 实例。
21
+ */
22
+ declare function $(selector: string | HTMLElement, dom?: DocumentContext): HTMLElement[];
23
+ /**
24
+ * 创建一个 HTML 元素,支持通过标签名或 HTML 字符串创建。
25
+ * @param tag - 元素标签名或 HTML 字符串。
26
+ * @param option - 元素的属性、样式、文本内容等配置。所有不是指定的属性,都会通过 setAttribute 设置
27
+ * @param children - 子节点
28
+ * @returns 创建的 HTML 元素。
29
+ */
30
+ declare function create(tag: string, option?: {
31
+ class?: FormatClassParam;
32
+ style?: FormatStyleParam;
33
+ textContent?: string;
34
+ innerHTML?: string;
35
+ outerHTML?: string;
36
+ [index: string]: any;
37
+ }, children?: NodeChildren): HTMLElement;
38
+ /** 创建节点 */
39
+ declare function $$(tag: string, option?: {
40
+ class?: FormatClassParam;
41
+ style?: FormatStyleParam;
42
+ textContent?: string;
43
+ innerHTML?: string;
44
+ outerHTML?: string;
45
+ [index: string]: any;
46
+ }, children?: NodeChildren): HTMLElement;
47
+ /**
48
+ * 根据选择器获取匹配的第一个 DOM 元素。
49
+ * @param selector - 选择器字符串或直接的 HTMLElement。
50
+ * @param dom - 可选的父级 DOM 元素,默认为当前文档。
51
+ * @returns 返回匹配的第一个 HTMLElement,如果没有找到则返回 null。
52
+ */
53
+ declare function $one(selector: string | HTMLElement, dom?: DocumentContext): HTMLElement | null;
54
+ /**
55
+ * 为节点添加 class
56
+ * @param {HTMLElement} elem 待添加 class 的节点
57
+ * @param {string} clazz 需要添加的 class
58
+ */
59
+ declare function addClass(elem: HTMLElement, clazz: string): void;
60
+ /**
61
+ * 节点移除 class
62
+ * @param {HTMLElement} elem 待移除 class 的节点
63
+ * @param {string} clazz 需要移除的 class
64
+ */
65
+ declare function removeClass(elem: HTMLElement, clazz: string): void;
66
+ /**
67
+ * 判断节点是否包含某个 class
68
+ * @param elem 待判断 class 的节点
69
+ * @param clazz 待判断的 class
70
+ * @returns
71
+ */
72
+ declare function hasClass(elem: HTMLElement, clazz: string): boolean;
73
+ /**
74
+ * 切换指定元素的类名。
75
+ * 如果元素已包含该类名,则移除它;否则添加它。
76
+ * @param el - 要操作的 HTML 元素。
77
+ * @param clazz - 要切换的类名。
78
+ */
79
+ declare function toggleClass(el: HTMLElement, clazz: string): void;
80
+ /**
81
+ * 替换指定元素的 CSS 类
82
+ *
83
+ * 该函数用于根据给定的旧类名或类索引,将其替换为新类名。
84
+ * 如果旧类不存在,则不会进行替换。
85
+ *
86
+ * @param el - 目标 HTML 元素,将对其类进行操作
87
+ * @param oldClazz - 要替换的旧类名或类索引(基于数字时对应 classList 的索引位置)
88
+ * @param newClazz - 新的类名,用于替换旧的类
89
+ * @returns void
90
+ */
91
+ declare function replaceClass(el: HTMLElement, oldClazz: string | number, newClazz: string): void;
92
+ type EventHandler = EventListenerOrEventListenerObject | ((e: CustomEvent) => void);
93
+ /**
94
+ * 为节点添加事件处理
95
+ * @param {HTMLElement} element 添加事件的节点
96
+ * @param {string} listener 事件名称
97
+ * @param {function} fn 事件处理函数
98
+ * @param {boolean} option 是否是只运行一次的处理函数或者配置,其中 eventFlag 为 string,如果配置该项,则表明为委托事件
99
+ */
100
+ declare function on(element: HTMLElement | ShadowRoot | Document | HTMLCollection | NodeListOf<HTMLElement> | HTMLElement[], listener: string, fn: EventHandler, option?: boolean | (AddEventListenerOptions & {
101
+ eventFlag?: string;
102
+ })): void;
103
+ /**
104
+ * 移除指定元素的事件监听器。
105
+ * @param el - 要移除监听器的 HTML 元素。
106
+ * @param listener - 事件名称。
107
+ * @param fn - 要移除的事件监听器函数。
108
+ */
109
+ declare function off(el: HTMLElement | ShadowRoot | Document | HTMLCollection | NodeListOf<HTMLElement> | HTMLElement[], listener: string, fn: EventHandler, option?: boolean | EventListenerOptions): void;
110
+ /**
111
+ * 判断事件是否应该继续传递。
112
+ * 从事件目标开始向上遍历DOM树,检查每个节点上是否存在指定的属性。
113
+ * 如果找到该属性且其值不为'__stop__',则返回true,表示事件可以继续传递。
114
+ * 否则,返回false,表示事件应该停止传递。
115
+ * 通常用于事件委托时判断是否继续传递事件。
116
+ *
117
+ * @param e - 触发的事件对象
118
+ * @param eventFlag - 需要检查的属性名
119
+ * @param endRoot - 可选,如果传递该参数,则表示停止遍历的节点,如果未传递,则表示遍历到文档根节点为止
120
+ * @returns 包含三个元素的数组:[是否继续传递事件, 属性值, 当前检查的DOM节点]
121
+ */
122
+ declare function shouldEventNext(e: Event, eventFlag: string, endRoot?: HTMLElement | ShadowRoot): [boolean, string, HTMLElement];
123
+ /**
124
+ * 设置或获取节点的 innerHTML 属性
125
+ * @param element
126
+ * @param htmlstr 可选,如果传递该参数,则表示设置;否则表示获取
127
+ * @returns
128
+ */
129
+ declare function html(element: HTMLElement, htmlstr?: string): string | undefined;
130
+ /**
131
+ * 设置或获取节点的 textContent 属性
132
+ * @param element
133
+ * @param textstr 可选,如果传递该参数,则表示设置;否则表示获取
134
+ * @returns
135
+ */
136
+ declare function text(element: HTMLElement, textstr?: string): string | undefined | null;
137
+ declare function iterate<T>(elems: T[], fn: (el: T, index: number) => any): void;
138
+ declare function iterate(elems: NodeList | HTMLCollection | NodeListOf<HTMLElement>, fn: (el: HTMLElement, index: number) => any): void;
139
+ /**
140
+ * 设置或获取节点 data-* 属性
141
+ * @param elem
142
+ * @param key data- 后面跟随的值
143
+ * @param value 如果传递该值表示获取;否则表示设置
144
+ * @returns
145
+ */
146
+ declare function attr(elem: HTMLElement, key: string, value?: string): string | null | undefined;
147
+ /**
148
+ * 获取属性值
149
+ * @param key 属性名称
150
+ */
151
+ declare function getAttr(el: HTMLElement, key: string): string;
152
+ /**
153
+ * 获取属性值,同时将值转换为默认值的类型,如果未赋值,则返回默认值;
154
+ * @param key 属性名称
155
+ * @param defaultValue 默认值
156
+ */
157
+ declare function getAttr(el: HTMLElement, filepath: string, defaultValue: string): string;
158
+ declare function getAttr(el: HTMLElement, filepath: string, defaultValue: number): number;
159
+ declare function getAttr(el: HTMLElement, filepath: string, defaultValue: boolean): boolean;
160
+ declare function getAttr<T extends Record<string, string | number | boolean>>(el: HTMLElement, filepath: string, defaultValue: T): T;
161
+ /**
162
+ * 获取指定节点的父节点
163
+ * @param el
164
+ * @returns
165
+ */
166
+ declare function parent(el: HTMLElement): HTMLElement;
167
+ /**
168
+ * 获取隐藏节点的尺寸, 如果 parent 传空, 且 hideNode 为节点,则会通过修改原始样式方式计算
169
+ * @param {string | HTMLElement} hideNode - The node to hide.
170
+ * @param parent - 添加临时节点的父节点, 如果传递 null, 则通过修改原始样式方式计算,默认为: body.
171
+ * @returns The DOMRect of the element.
172
+ */
173
+ declare function queryHideNodeSize(hideNode: string | HTMLElement, parent?: null | HTMLElement): {
174
+ width: number;
175
+ height: number;
176
+ };
177
+ /**
178
+ * 判断元素是否在父元素的可视区域内。
179
+ *
180
+ * @param el 要检查的元素
181
+ * @param parent 元素的父元素,默认为document.body
182
+ * @param direction 检查的方向,默认为"horizontal"
183
+ * @returns 如果元素在父元素的可视区域内,则返回true;否则返回false。
184
+ */
185
+ declare function isVisible(el: HTMLElement, parent?: HTMLElement | null | undefined, direction?: string): boolean;
186
+ /**
187
+ * 判断当前设备是否为移动设备。
188
+ *
189
+ * 本函数通过检查用户代理字符串和屏幕尺寸来判断设备是否为移动设备。
190
+ * 这对于需要根据设备类型进行不同布局或功能调整的应用非常有用。
191
+ *
192
+ * @returns {boolean} 如果设备是移动设备,则返回true;否则返回false。
193
+ */
194
+ declare function isMobile(): boolean;
195
+ type ClsxValue = string | number | boolean | undefined | null | ClsxValue[] | Record<string, boolean | string | number | undefined | null>;
196
+ /**
197
+ * 条件化类名拼接工具,支持任意嵌套的字符串、数组、对象参数。
198
+ * - 字符串/数字:直接拼接
199
+ * - 数组:递归处理每个元素
200
+ * - 对象:值为真时拼接键名
201
+ * - falsy 值(false、null、undefined、0、""):跳过
202
+ * @param args - 任意数量的类名参数
203
+ * @returns 拼接后的类名字符串
204
+ */
205
+ declare function clsx(...args: ClsxValue[]): string;
206
+ /**
207
+ * 格式化类名,支持数组和对象两种形式。
208
+ * - 数组形式:数组中的每个元素代表一个类名,非空元素将被添加到结果字符串中。
209
+ * - 对象形式:对象的键代表类名,值为真(非空、非undefined、非null)时,键将被添加到结果字符串中。
210
+ * @param classObj - 类名对象或数组
211
+ * @returns 格式化后的类名字符串
212
+ */
213
+ declare function formatClass(classObj: (boolean | string | undefined | null)[] | Record<string, boolean | string | undefined | null> | string): string;
214
+ type StyxBaseValue = string | boolean | undefined | null;
215
+ type StyxValue = StyxBaseValue | StyxBaseValue[] | Record<string, StyxBaseValue | number>;
216
+ /**
217
+ * 条件化样式拼接工具,支持任意嵌套的字符串、数组、对象参数。
218
+ * - 字符串:直接拼接(自动补 `;`)
219
+ * - 数组:递归处理每个元素
220
+ * - 对象:拼接为 `key:value;` 格式
221
+ * - falsy 值(false、null、undefined、0、""):跳过
222
+ * @param args - 任意数量的样式参数
223
+ * @returns 拼接后的样式字符串
224
+ */
225
+ declare function styx(...args: StyxValue[]): string;
226
+ /**
227
+ * 将样式对象格式化为 CSS 样式字符串。
228
+ * @param styleObj - 样式对象,可以是字符串数组或键值对对象。
229
+ * @returns 格式化后的 CSS 样式字符串。
230
+ */
231
+ declare function formatStyle(styleObj: FormatStyleParam): string;
232
+ /**
233
+ * 执行元素的过渡动画。
234
+ *
235
+ * 如果是名称类似于 Vue.js 的过渡动画,通过添加 `*-active`、`*-from|to` class 类名。
236
+ *
237
+ * @param el - 需要执行过渡动画的 HTML 元素。
238
+ * @param nameOrProperties - 过渡动画的名称或属性数组。可以是字符串表示的动画名称,或者是包含属性名称、初始值或目标值、持续时间。eg. [['opacity', '0.5']] | 'nt-opacity'
239
+ * @param dir - 过渡动画的方向,"leave" 表示离开,"enter" 表示进入。默认值为 "enter"。
240
+ * @param finish - 过渡动画结束时的回调函数。
241
+ *
242
+ * @example <caption>执行 `nt-opacity` 名称动画</caption>
243
+ * // css
244
+ * .nt-opacity-enter-active,
245
+ * .nt-opacity-leave-active {
246
+ * transition: opacity 0.3s ease;
247
+ * }
248
+ * .nt-opacity-enter-from,
249
+ * .nt-opacity-leave-to {
250
+ * opacity: 0;
251
+ * }
252
+ * // js
253
+ * transition($el, "nt-opacity", "enter");
254
+ *
255
+ * @example <caption>执行 `style` 属性动画</caption>
256
+ * transition($el, [["opacity", "0", "0.3s"]], "enter");
257
+ *
258
+ * @example <caption>动画结束后移除节点</caption>
259
+ * transition($el, [["opacity", "0", "0.3s"]], "leave", () => { $el.remove(); });
260
+ */
261
+ declare function transition(el: HTMLElement, nameOrProperties: string | [string, string, string][], dir?: "leave" | "enter", finish?: () => void): void;
262
+ /**
263
+ * 计算光标位置
264
+ *
265
+ * 根据输入值的变化计算新的光标位置,主要用于输入框内容变化时的光标位置调整
266
+ *
267
+ * @param start - 光标起始位置,通常为: input.selectionStart
268
+ * @param end - 光标结束位置(通常与起始位置相同,用于选择范围),通常为: input.selectionEnd
269
+ * @param oldValue - 变化前的值
270
+ * @param newValue - 变化后的值
271
+ * @returns 新的光标位置对象,包含新的起始和结束位置
272
+ *
273
+ * @example
274
+ * // 删除字符时,光标向前移动
275
+ * calcuteCursorPosition(2, 2, "abc", "ac"); // 返回 { start: 1, end: 1 }
276
+ *
277
+ * @example
278
+ * // 添加字符时,光标向后移动
279
+ * calcuteCursorPosition(2, 2, "ac", "abc"); // 返回 { start: 3, end: 3 }
280
+ *
281
+ * @example
282
+ * // 替换字符时,保持位置
283
+ * calcuteCursorPosition(2, 2, "abc", "axc"); // 返回 { start: 2, end: 2 }
284
+ */
285
+ declare function calcuteCursorPosition(start: number, end: number, oldValue: string, newValue: string): {
286
+ start: number;
287
+ end: number;
288
+ };
289
+ //#endregion
290
+ //#region src/copy.d.ts
291
+ /**
292
+ * 复制数据, 可以从多种类型的数据
293
+ * 1. 直接复制文本: await copy("待复制的文本")
294
+ * 2. 复制节点上的 data-copy-text:
295
+ * <button data-copy-text="这是待复制的文本">复制</button>
296
+ * await copy(e.target) // or await copy("#a") or await copy(document.querySelector('#a'))
297
+ * 3. 直接复制节点本身数据: await copy('#a')
298
+ * @param {string | HTMLElement} source 复制源, 从中解析待复制的数据
299
+ * @returns {Promise<boolean>} 是否复制成功
300
+ */
301
+ declare function copy(source: string | HTMLElement): Promise<boolean>;
302
+ //#endregion
303
+ //#region src/storage.d.ts
304
+ /**
305
+ * 缓存相关
306
+ */
307
+ type StorageType = "session" | "local";
308
+ interface StorageSetOption {
309
+ storage?: StorageType;
310
+ /** 数据有效期, 单位秒, 默认: -1 - 永久存储 */
311
+ expire?: number;
312
+ }
313
+ /**
314
+ * 存储值到 Storage 中
315
+ * @param key 设置的 key
316
+ * @param value 设置的值
317
+ * @param [option.storage] session 或 local, 默认: session
318
+ * @param [option.expire] 数据有效期, 单位秒, 默认: -1 - 永久存储
319
+ *
320
+ * @example <caption>1. 存储到 SessionStorage</caption>
321
+ * set("key", "value");
322
+ *
323
+ * @example <caption>2. 存储到 LocalStorage</caption>
324
+ * set("key", "value", { storage: "local" });
325
+ */
326
+ declare function set(key: string, value: any, option?: StorageSetOption): void;
327
+ /**
328
+ * 清空所有的缓存内容
329
+ * @param storage 待清空的缓存对象
330
+ */
331
+ declare function clear(storage?: StorageType): void;
332
+ /**
333
+ * 删除存储到 Storage 中的数据
334
+ * @param key
335
+ * @param storage
336
+ */
337
+ declare function remove(key: string, storage?: StorageType): void;
338
+ /** 从 Storage 中获取数据时的配置 */
339
+ interface StorageQueryOption {
340
+ /** 数据是否持久化, 默认为: false, 设置为 true 则会在每一次取出数据后删除 */
341
+ delete?: boolean;
342
+ /** 存储对象, session、local */
343
+ storage?: StorageType;
344
+ }
345
+ /**
346
+ * 从 Storage 中取出数据
347
+ * @param key 保存时的 key
348
+ * @param defaultValue 没有数据时的默认值
349
+ * @param [option.delete] 是否在取出后,删除数据,默认:false - 取出后删除数据
350
+ * @param [option.storage] 使用的 Storage ,可以是 localStorage、sessionStorage, 默认: localStorage、sessionStorage
351
+ * @returns Storage 中 key 对应的数据
352
+ */
353
+ declare function get<T>(key: string, defaultValue?: T, option?: StorageQueryOption): T;
354
+ //#endregion
355
+ //#region src/theme.d.ts
356
+ /** 获取当前系统的主题 */
357
+ declare function getSystemTheme(): "light" | "dark" | "auto";
358
+ /**
359
+ * 初始化主题, 让网页能够适应系统主题, 同时根据缓存的主题切换主题
360
+ * @returns 当前应用的主题
361
+ */
362
+ declare function initTheme(): Promise<"light" | "dark" | "auto">;
363
+ /**
364
+ * 切换主题, 通常用于预览
365
+ * @param theme 切换的主题
366
+ * @param transition 是否使用过渡动画, 注意浏览器必须支持 document.startViewTransition, 默认: true
367
+ * @returns 切换后的主题
368
+ */
369
+ declare function toggleTheme(theme?: "light" | "dark" | "auto", transition?: boolean): Promise<"light" | "dark" | "auto">;
370
+ /** 获取当前主题 */
371
+ declare function getTheme(): string;
372
+ /**
373
+ * 应用主题
374
+ * @param theme 待应用的主题
375
+ * @param cache 是否缓存应用的主题, 让应用下一次启动的时候, 可以应用主题, 默认: true
376
+ * @param transition 是否使用过渡动画, 注意浏览器必须支持 document.startViewTransition, 默认: true
377
+ * @returns 应用的主题
378
+ */
379
+ declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean, transition?: boolean): Promise<"light" | "dark" | "auto">;
380
+ /** 获取当前主题色 */
381
+ declare function getColorTheme(defaultValue?: string): string | undefined;
382
+ /**
383
+ * 初始化主题色, 让网页能够适应系统主题色, 同时根据缓存的主题色切换主题色
384
+ * @returns 当前应用的主题色
385
+ */
386
+ declare function initColorTheme(): Promise<string> | null;
387
+ /**
388
+ * 切换主题色, 通常用于预览
389
+ * @param color 待切换的主题色
390
+ * @returns 切换后的主题色
391
+ */
392
+ declare function toggleColorTheme(color: string): Promise<string>;
393
+ /**
394
+ * 应用主题色
395
+ * @param color 主题色
396
+ * @param cache 是否缓存主题色, 让应用下一次启动的时候, 可以应用主题色, 默认: true
397
+ * @returns 切换后的主题色
398
+ */
399
+ declare function applyColorTheme(color: string, cache?: boolean): Promise<string>;
400
+ //#endregion
401
+ //#region src/web.d.ts
402
+ /**
403
+ * web(浏览器) 端工具类
404
+ */
405
+ type FormValue = string | number | boolean;
406
+ /**
407
+ * 解析 Form 表单中的 input 元素的数据为 JSON 格式,key: input-name;value: input-value
408
+ * @param form {object} Form 节点对象
409
+ */
410
+ declare const formJson: <T extends Record<string, FormValue>>(form: HTMLFormElement) => T;
411
+ type QueryResult = string | string[];
412
+ /**
413
+ * 获取 url query 参数 (get 请求的参数)
414
+ * @param search 如果是 React 应用就需要传递 useLocation().search
415
+ * @returns
416
+ */
417
+ declare function query(search?: string): Record<string, QueryResult>;
418
+ /**
419
+ * 函数节流 - 每隔单位时间,只执行一次
420
+ * @param cb 待节流的函数
421
+ * @param wait 间隔时间
422
+ * @returns
423
+ */
424
+ declare function throttle<R extends unknown[], T>(fn: (...args: R) => T, wait?: number): {
425
+ (...args: R): void;
426
+ cancel: () => void;
427
+ };
428
+ /**
429
+ * 函数防抖 - 当重复触发某一个行为(事件时),只执行最后一次触发
430
+ * @param fn 防抖函数
431
+ * @param interval 间隔时间段
432
+ * @returns
433
+ */
434
+ declare function debounce<R extends unknown[], T>(fn: (...args: R) => T, interval?: number): {
435
+ (...args: R): void;
436
+ cancel: () => void;
437
+ };
438
+ //#endregion
439
+ export { $, $$, $one, addClass, applyColorTheme, applyTheme, attr, calcuteCursorPosition, clear, clsx, copy, create, debounce, elem, formJson, formatClass, formatStyle, get, getAttr, getColorTheme, getSystemTheme, getTheme, hasClass, html, initColorTheme, initTheme, isMobile, isVisible, iterate, off, on, parent, query, queryHideNodeSize, remove, removeClass, replaceClass, set, shouldEventNext, styx, text, throttle, toggleClass, toggleColorTheme, toggleTheme, transition };