@whitesev/domutils 1.6.8 → 1.7.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.
- package/dist/index.amd.js +1928 -1047
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +2 -0
- package/dist/index.amd.min.js.map +1 -0
- package/dist/index.cjs.js +1928 -1047
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +2 -0
- package/dist/index.cjs.min.js.map +1 -0
- package/dist/index.esm.js +1928 -1047
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.iife.js +1928 -1047
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +2 -0
- package/dist/index.iife.min.js.map +1 -0
- package/dist/index.system.js +1928 -1047
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +2 -0
- package/dist/index.system.min.js.map +1 -0
- package/dist/index.umd.js +1928 -1047
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/src/{DOMUtilsCommonUtils.d.ts → CommonUtils.d.ts} +20 -8
- package/dist/types/src/ElementAnimate.d.ts +89 -0
- package/dist/types/src/{DOMUtilsEvent.d.ts → ElementEvent.d.ts} +19 -84
- package/dist/types/src/ElementHandler.d.ts +17 -0
- package/dist/types/src/ElementSelector.d.ts +96 -0
- package/dist/types/src/ElementWait.d.ts +278 -0
- package/dist/types/src/GlobalData.d.ts +4 -0
- package/dist/types/src/{DOMUtilsOriginPrototype.d.ts → OriginPrototype.d.ts} +1 -2
- package/dist/types/src/Utils.d.ts +68 -0
- package/dist/types/src/{DOMUtils.d.ts → index.d.ts} +157 -177
- package/dist/types/src/types/env.d.ts +9 -0
- package/dist/types/src/types/global.d.ts +0 -2
- package/dist/types/src/types/gm.d.ts +0 -4
- package/index.ts +1 -1
- package/package.json +6 -2
- package/src/{DOMUtilsCommonUtils.ts → CommonUtils.ts} +25 -11
- package/src/ElementAnimate.ts +290 -0
- package/src/{DOMUtilsEvent.ts → ElementEvent.ts} +166 -361
- package/src/ElementHandler.ts +43 -0
- package/src/ElementSelector.ts +260 -0
- package/src/ElementWait.ts +699 -0
- package/src/GlobalData.ts +5 -0
- package/src/{DOMUtilsOriginPrototype.ts → OriginPrototype.ts} +1 -3
- package/src/Utils.ts +386 -0
- package/src/{DOMUtils.ts → index.ts} +678 -757
- package/src/types/env.d.ts +9 -0
- package/src/types/global.d.ts +0 -2
- package/src/types/gm.d.ts +0 -4
- package/dist/types/src/DOMUtilsData.d.ts +0 -5
- package/src/DOMUtilsData.ts +0 -7
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
|
+
import { WindowApi } from "./WindowApi";
|
|
3
|
+
declare class ElementSelector {
|
|
4
|
+
windowApi: typeof WindowApi.prototype;
|
|
5
|
+
constructor(windowApiOption?: WindowApiOption);
|
|
6
|
+
/**
|
|
7
|
+
* 选择器,可使用以下的额外语法
|
|
8
|
+
*
|
|
9
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
10
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
11
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
12
|
+
* @param selector 选择器
|
|
13
|
+
* @param parent 指定父元素
|
|
14
|
+
* @example
|
|
15
|
+
* DOMUtils.selector("div:contains('测试')")
|
|
16
|
+
* > div.xxx
|
|
17
|
+
* @example
|
|
18
|
+
* DOMUtils.selector("div:empty")
|
|
19
|
+
* > div.xxx
|
|
20
|
+
* @example
|
|
21
|
+
* DOMUtils.selector("div:regexp('^xxxx$')")
|
|
22
|
+
* > div.xxx
|
|
23
|
+
*/
|
|
24
|
+
selector<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: Element | Document | DocumentFragment | ShadowRoot): HTMLElementTagNameMap[K] | undefined;
|
|
25
|
+
selector<E extends Element = HTMLElement>(selector: string, parent?: Element | Document | DocumentFragment | ShadowRoot): E | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* 选择器,可使用以下的额外语法
|
|
28
|
+
*
|
|
29
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
30
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
31
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
32
|
+
* @param selector 选择器
|
|
33
|
+
* @param parent 指定父元素
|
|
34
|
+
* @example
|
|
35
|
+
* DOMUtils.selectorAll("div:contains('测试')")
|
|
36
|
+
* > [div.xxx]
|
|
37
|
+
* @example
|
|
38
|
+
* DOMUtils.selectorAll("div:empty")
|
|
39
|
+
* > [div.xxx]
|
|
40
|
+
* @example
|
|
41
|
+
* DOMUtils.selectorAll("div:regexp('^xxxx$')")
|
|
42
|
+
* > [div.xxx]
|
|
43
|
+
* @example
|
|
44
|
+
* DOMUtils.selectorAll("div:regexp(/^xxx/ig)")
|
|
45
|
+
* > [div.xxx]
|
|
46
|
+
*/
|
|
47
|
+
selectorAll<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: Element | Document | DocumentFragment | ShadowRoot): HTMLElementTagNameMap[K][];
|
|
48
|
+
selectorAll<E extends Element = HTMLElement>(selector: string, parent?: Element | Document | DocumentFragment | ShadowRoot): E[];
|
|
49
|
+
/**
|
|
50
|
+
* 匹配元素,可使用以下的额外语法
|
|
51
|
+
*
|
|
52
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
53
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
54
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
55
|
+
* @param $el 元素
|
|
56
|
+
* @param selector 选择器
|
|
57
|
+
* @example
|
|
58
|
+
* DOMUtils.matches("div:contains('测试')")
|
|
59
|
+
* > true
|
|
60
|
+
* @example
|
|
61
|
+
* DOMUtils.matches("div:empty")
|
|
62
|
+
* > true
|
|
63
|
+
* @example
|
|
64
|
+
* DOMUtils.matches("div:regexp('^xxxx$')")
|
|
65
|
+
* > true
|
|
66
|
+
* @example
|
|
67
|
+
* DOMUtils.matches("div:regexp(/^xxx/ig)")
|
|
68
|
+
* > false
|
|
69
|
+
*/
|
|
70
|
+
matches($el: HTMLElement | Element | null | undefined, selector: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 根据选择器获取上层元素,可使用以下的额外语法
|
|
73
|
+
*
|
|
74
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
75
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
76
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
77
|
+
* @param $el 元素
|
|
78
|
+
* @param selector 选择器
|
|
79
|
+
* @example
|
|
80
|
+
* DOMUtils.closest("div:contains('测试')")
|
|
81
|
+
* > div.xxx
|
|
82
|
+
* @example
|
|
83
|
+
* DOMUtils.closest("div:empty")
|
|
84
|
+
* > div.xxx
|
|
85
|
+
* @example
|
|
86
|
+
* DOMUtils.closest("div:regexp('^xxxx$')")
|
|
87
|
+
* > div.xxxx
|
|
88
|
+
* @example
|
|
89
|
+
* DOMUtils.closest("div:regexp(/^xxx/ig)")
|
|
90
|
+
* > null
|
|
91
|
+
*/
|
|
92
|
+
closest<K extends keyof HTMLElementTagNameMap>($el: HTMLElement | Element, selector: string): HTMLElementTagNameMap[K] | null;
|
|
93
|
+
closest<E extends Element = Element>($el: HTMLElement | Element, selector: string): E | null;
|
|
94
|
+
}
|
|
95
|
+
declare const elementSelector: ElementSelector;
|
|
96
|
+
export { elementSelector, ElementSelector };
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { ElementSelector } from "./ElementSelector";
|
|
2
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
3
|
+
import { WindowApi } from "./WindowApi";
|
|
4
|
+
declare class ElementWait extends ElementSelector {
|
|
5
|
+
windowApi: typeof WindowApi.prototype;
|
|
6
|
+
constructor(windowApiOption?: WindowApiOption);
|
|
7
|
+
/**
|
|
8
|
+
* 等待任意事件成立
|
|
9
|
+
*
|
|
10
|
+
* 运行方式为根据页面元素的改变而触发回调
|
|
11
|
+
* @param checkFn 检测的函数
|
|
12
|
+
* @param timeout 超时时间,默认0
|
|
13
|
+
* @param parent (可选)父元素,默认document
|
|
14
|
+
* @example
|
|
15
|
+
* Utils.wait(()=> {
|
|
16
|
+
* let $test = document.querySelector("#test");
|
|
17
|
+
* return {
|
|
18
|
+
* success: $test !== null,
|
|
19
|
+
* data: $test
|
|
20
|
+
* }
|
|
21
|
+
* })
|
|
22
|
+
*/
|
|
23
|
+
wait<T>(checkFn: (...args: any[]) => {
|
|
24
|
+
/**
|
|
25
|
+
* 是否检测成功
|
|
26
|
+
*/
|
|
27
|
+
success: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 返回的值
|
|
30
|
+
*/
|
|
31
|
+
data: T;
|
|
32
|
+
}, timeout?: null | undefined, parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
33
|
+
wait<T>(checkFn: (...args: any[]) => {
|
|
34
|
+
/**
|
|
35
|
+
* 是否检测成功
|
|
36
|
+
*/
|
|
37
|
+
success: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 返回的值
|
|
40
|
+
*/
|
|
41
|
+
data: T;
|
|
42
|
+
}, timeout?: number, parent?: Node | Element | Document | HTMLElement): Promise<T | null>;
|
|
43
|
+
/**
|
|
44
|
+
* 等待元素出现
|
|
45
|
+
* @param selectorFn 获取元素的函数
|
|
46
|
+
* @param timeout 超时时间,默认0
|
|
47
|
+
* @example
|
|
48
|
+
* Utils.waitNode(()=>document.querySelector("div"), 1000).then( $div =>{
|
|
49
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
50
|
+
* })
|
|
51
|
+
*/
|
|
52
|
+
waitNode<K>(selectorFn: () => K | null | undefined): Promise<K>;
|
|
53
|
+
waitNode<K>(selectorFn: () => K | null | undefined, timeout: number): Promise<K | null | undefined>;
|
|
54
|
+
/**
|
|
55
|
+
* 等待元素出现
|
|
56
|
+
* @param selector CSS选择器
|
|
57
|
+
* @param parent (可选)父元素,默认document
|
|
58
|
+
* @example
|
|
59
|
+
* Utils.waitNode("div").then( $div =>{
|
|
60
|
+
* console.log($div); // div => HTMLDivELement
|
|
61
|
+
* })
|
|
62
|
+
* Utils.waitNode("div", document).then( $div =>{
|
|
63
|
+
* console.log($div); // div => HTMLDivELement
|
|
64
|
+
* })
|
|
65
|
+
*/
|
|
66
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
|
|
67
|
+
waitNode<T extends Element>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
68
|
+
/**
|
|
69
|
+
* 等待元素出现
|
|
70
|
+
* @param selectorList CSS选择器数组
|
|
71
|
+
* @param parent (可选)父元素,默认document
|
|
72
|
+
* @example
|
|
73
|
+
* Utils.waitNode(["div"]).then( ([$div]) =>{
|
|
74
|
+
* console.log($div); // div => HTMLDivELement[]
|
|
75
|
+
* })
|
|
76
|
+
* Utils.waitNode(["div"], document).then( ([$div]) =>{
|
|
77
|
+
* console.log($div); // div => HTMLDivELement[]
|
|
78
|
+
* })
|
|
79
|
+
*/
|
|
80
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K][]>;
|
|
81
|
+
waitNode<T extends Element[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
82
|
+
/**
|
|
83
|
+
* 等待元素出现
|
|
84
|
+
* @param selector CSS选择器
|
|
85
|
+
* @param parent 父元素,默认document
|
|
86
|
+
* @param timeout 超时时间,默认0
|
|
87
|
+
* @example
|
|
88
|
+
* Utils.waitNode("div", document, 1000).then( $div =>{
|
|
89
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
90
|
+
* })
|
|
91
|
+
*/
|
|
92
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
93
|
+
waitNode<T extends Element>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
|
|
94
|
+
/**
|
|
95
|
+
* 等待元素出现
|
|
96
|
+
* @param selectorList CSS选择器数组
|
|
97
|
+
* @param parent 父元素,默认document
|
|
98
|
+
* @param timeout 超时时间,默认0
|
|
99
|
+
* @example
|
|
100
|
+
* Utils.waitNode(["div"], document, 1000).then( ([$div]) =>{
|
|
101
|
+
* console.log($div); // $div => HTMLDivELement[] | null
|
|
102
|
+
* })
|
|
103
|
+
*/
|
|
104
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
105
|
+
waitNode<T extends Element[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
|
|
106
|
+
/**
|
|
107
|
+
* 等待元素出现
|
|
108
|
+
* @param selector CSS选择器
|
|
109
|
+
* @param timeout 超时时间,默认0
|
|
110
|
+
* @example
|
|
111
|
+
* Utils.waitNode("div", 1000).then( $div =>{
|
|
112
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
113
|
+
* })
|
|
114
|
+
*/
|
|
115
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
116
|
+
waitNode<T extends Element>(selector: string, timeout: number): Promise<T | null>;
|
|
117
|
+
/**
|
|
118
|
+
* 等待元素出现
|
|
119
|
+
* @param selectorList CSS选择器数组
|
|
120
|
+
* @param timeout 超时时间,默认0
|
|
121
|
+
* @example
|
|
122
|
+
* Utils.waitNode(["div"], 1000).then( [$div] =>{
|
|
123
|
+
* console.log($div); // $div => HTMLDivELement[] | null
|
|
124
|
+
* })
|
|
125
|
+
*/
|
|
126
|
+
waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
127
|
+
waitNode<T extends Element[]>(selectorList: string[], timeout: number): Promise<T | null>;
|
|
128
|
+
/**
|
|
129
|
+
* 等待任意元素出现
|
|
130
|
+
* @param selectorList CSS选择器数组
|
|
131
|
+
* @param parent (可选)监听的父元素
|
|
132
|
+
* @example
|
|
133
|
+
* Utils.waitAnyNode(["div","div"]).then( $div =>{
|
|
134
|
+
* console.log($div); // $div => HTMLDivELement 这里是第一个
|
|
135
|
+
* })
|
|
136
|
+
* Utils.waitAnyNode(["a","div"], document).then( $a =>{
|
|
137
|
+
* console.log($a); // $a => HTMLAnchorElement 这里是第一个
|
|
138
|
+
* })
|
|
139
|
+
*/
|
|
140
|
+
waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
|
|
141
|
+
waitAnyNode<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
142
|
+
/**
|
|
143
|
+
* 等待任意元素出现
|
|
144
|
+
* @param selectorList CSS选择器数组
|
|
145
|
+
* @param parent 父元素,默认document
|
|
146
|
+
* @param timeout 超时时间,默认0
|
|
147
|
+
* @example
|
|
148
|
+
* Utils.waitAnyNode(["div","div"], document, 10000).then( $div =>{
|
|
149
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
150
|
+
* })
|
|
151
|
+
*/
|
|
152
|
+
waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
153
|
+
waitAnyNode<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
|
|
154
|
+
/**
|
|
155
|
+
* 等待任意元素出现
|
|
156
|
+
* @param selectorList CSS选择器数组
|
|
157
|
+
* @param timeout 超时时间,默认0
|
|
158
|
+
* @example
|
|
159
|
+
* Utils.waitAnyNode(["div","div"], 10000).then( $div =>{
|
|
160
|
+
* console.log($div); // $div => HTMLDivELement | null
|
|
161
|
+
* })
|
|
162
|
+
*/
|
|
163
|
+
waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
|
|
164
|
+
waitAnyNode<T extends Element>(selectorList: string[], timeout: number): Promise<T | null>;
|
|
165
|
+
/**
|
|
166
|
+
* 等待元素数组出现
|
|
167
|
+
* @param selector CSS选择器
|
|
168
|
+
* @param parent (可选)监听的父元素
|
|
169
|
+
* @example
|
|
170
|
+
* Utils.waitNodeList("div").then( $result =>{
|
|
171
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
172
|
+
* })
|
|
173
|
+
* Utils.waitNodeList("div", document).then( $result =>{
|
|
174
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
175
|
+
* })
|
|
176
|
+
*/
|
|
177
|
+
waitNodeList<T extends keyof HTMLElementTagNameMap>(selector: T, parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[T]>>;
|
|
178
|
+
waitNodeList<T extends NodeListOf<Element>>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
179
|
+
/**
|
|
180
|
+
* 等待元素数组出现
|
|
181
|
+
* @param selectorList CSS选择器数组
|
|
182
|
+
* @param parent (可选)监听的父元素
|
|
183
|
+
* @example
|
|
184
|
+
* Utils.waitNodeList(["div"]).then( $result =>{
|
|
185
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>[]
|
|
186
|
+
* })
|
|
187
|
+
* Utils.waitNodeList(["div"], document).then( $result =>{
|
|
188
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>[]
|
|
189
|
+
* })
|
|
190
|
+
*/
|
|
191
|
+
waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>[]>;
|
|
192
|
+
waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
193
|
+
/**
|
|
194
|
+
* 等待元素数组出现
|
|
195
|
+
* @param selector CSS选择器
|
|
196
|
+
* @param parent 监听的父元素
|
|
197
|
+
* @param timeout 超时时间,默认0
|
|
198
|
+
* @example
|
|
199
|
+
* Utils.waitNodeList("div", document, 10000).then( $result =>{
|
|
200
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
201
|
+
* })
|
|
202
|
+
*/
|
|
203
|
+
waitNodeList<T extends NodeListOf<Element>>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
|
|
204
|
+
waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
205
|
+
/**
|
|
206
|
+
* 等待元素数组出现
|
|
207
|
+
* @param selectorList CSS选择器数组
|
|
208
|
+
* @param parent 监听的父元素
|
|
209
|
+
* @param timeout 超时时间,默认0
|
|
210
|
+
* @example
|
|
211
|
+
* Utils.waitNodeList(["div"], document, 10000).then( $result =>{
|
|
212
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
|
|
213
|
+
* })
|
|
214
|
+
*/
|
|
215
|
+
waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
|
|
216
|
+
waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
|
|
217
|
+
/**
|
|
218
|
+
* 等待元素数组出现
|
|
219
|
+
* @param selector CSS选择器数组
|
|
220
|
+
* @param timeout 超时时间,默认0
|
|
221
|
+
* @example
|
|
222
|
+
* Utils.waitNodeList("div", 10000).then( $result =>{
|
|
223
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
224
|
+
* })
|
|
225
|
+
*/
|
|
226
|
+
waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
227
|
+
waitNodeList<T extends NodeListOf<Element>>(selector: string[], timeout: number): Promise<T | null>;
|
|
228
|
+
/**
|
|
229
|
+
* 等待元素数组出现
|
|
230
|
+
* @param selectorList CSS选择器数组
|
|
231
|
+
* @param timeout 超时时间,默认0
|
|
232
|
+
* @example
|
|
233
|
+
* Utils.waitNodeList(["div"], 10000).then( $result =>{
|
|
234
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
|
|
235
|
+
* })
|
|
236
|
+
*/
|
|
237
|
+
waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
|
|
238
|
+
waitNodeList<T extends NodeListOf<Element>>(selectorList: string[], timeout: number): Promise<T[] | null>;
|
|
239
|
+
/**
|
|
240
|
+
* 等待任意元素数组出现
|
|
241
|
+
* @param selectorList CSS选择器数组
|
|
242
|
+
* @param parent (可选)监听的父元素
|
|
243
|
+
* @example
|
|
244
|
+
* Utils.waitAnyNodeList(["div","a"]).then( $result =>{
|
|
245
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
246
|
+
* })
|
|
247
|
+
* Utils.waitAnyNodeList(["div","a"], document).then( $result =>{
|
|
248
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement>
|
|
249
|
+
* })
|
|
250
|
+
*/
|
|
251
|
+
waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>>;
|
|
252
|
+
waitAnyNodeList<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<T>>;
|
|
253
|
+
/**
|
|
254
|
+
* 等待任意元素数组出现
|
|
255
|
+
* @param selectorList CSS选择器数组
|
|
256
|
+
* @param parent 父元素,默认document
|
|
257
|
+
* @param timeout 超时时间,默认0
|
|
258
|
+
* @example
|
|
259
|
+
* Utils.waitAnyNodeList(["div","a"], document, 10000).then( $result =>{
|
|
260
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
261
|
+
* })
|
|
262
|
+
*/
|
|
263
|
+
waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
264
|
+
waitAnyNodeList<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<T> | null>;
|
|
265
|
+
/**
|
|
266
|
+
* 等待任意元素出现
|
|
267
|
+
* @param selectorList CSS选择器数组
|
|
268
|
+
* @param timeout 超时时间,默认0
|
|
269
|
+
* @example
|
|
270
|
+
* Utils.waitAnyNodeList(["div","div"], 10000).then( $result =>{
|
|
271
|
+
* console.log($result); // $result => NodeListOf<HTMLDivElement> | null
|
|
272
|
+
* })
|
|
273
|
+
*/
|
|
274
|
+
waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
275
|
+
waitAnyNodeList<T extends Element>(selectorList: string[], timeout: number): Promise<NodeListOf<T> | null>;
|
|
276
|
+
}
|
|
277
|
+
declare const elementWait: ElementWait;
|
|
278
|
+
export { elementWait, ElementWait };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
|
+
declare class Utils {
|
|
3
|
+
private windowApi;
|
|
4
|
+
constructor(option?: WindowApiOption);
|
|
5
|
+
/**
|
|
6
|
+
* 判断对象是否是jQuery对象
|
|
7
|
+
* @param target
|
|
8
|
+
* @returns
|
|
9
|
+
* + true 是jQuery对象
|
|
10
|
+
* + false 不是jQuery对象
|
|
11
|
+
* @example
|
|
12
|
+
* Utils.isJQuery($("a"))
|
|
13
|
+
* > true
|
|
14
|
+
*/
|
|
15
|
+
isJQuery(target: any): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
|
|
18
|
+
* @param target 目标数据
|
|
19
|
+
* @param source 源数据
|
|
20
|
+
* @param isAdd 是否可以追加键,默认false
|
|
21
|
+
* @example
|
|
22
|
+
* Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
|
|
23
|
+
* >
|
|
24
|
+
* {
|
|
25
|
+
"1": 1,
|
|
26
|
+
"2": {
|
|
27
|
+
"3": 4
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
*/
|
|
31
|
+
assign<T1, T2 extends object, T3 extends boolean>(target: T1, source: T2, isAdd?: T3): T3 extends true ? T1 & T2 : T1;
|
|
32
|
+
/**
|
|
33
|
+
* 监听页面元素改变并处理
|
|
34
|
+
* @param target 需要监听的元素,如果不存在,可以等待它出现
|
|
35
|
+
* @param observer_config MutationObserver的配置
|
|
36
|
+
* @example
|
|
37
|
+
Utils.mutationObserver(document.querySelector("div.xxxx"),{
|
|
38
|
+
"callback":(mutations, observer)=>{},
|
|
39
|
+
"config":{childList:true,attributes:true}
|
|
40
|
+
});
|
|
41
|
+
* @example
|
|
42
|
+
Utils.mutationObserver(document.querySelectorAll("div.xxxx"),{
|
|
43
|
+
"callback":(mutations, observer)=>{},
|
|
44
|
+
"config":{childList:true,attributes:true}}
|
|
45
|
+
);
|
|
46
|
+
* @example
|
|
47
|
+
Utils.mutationObserver($("div.xxxx"),{
|
|
48
|
+
"callback":(mutations, observer)=>{},
|
|
49
|
+
"config":{childList:true,attributes:true}}
|
|
50
|
+
);
|
|
51
|
+
**/
|
|
52
|
+
mutationObserver(target: HTMLElement | Node | NodeList | Document, observer_config: {
|
|
53
|
+
/**
|
|
54
|
+
* observer的配置
|
|
55
|
+
*/
|
|
56
|
+
config?: MutationObserverInit;
|
|
57
|
+
/**
|
|
58
|
+
* 是否主动触发一次
|
|
59
|
+
*/
|
|
60
|
+
immediate?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 触发的回调函数
|
|
63
|
+
*/
|
|
64
|
+
callback: MutationCallback;
|
|
65
|
+
}): MutationObserver;
|
|
66
|
+
}
|
|
67
|
+
declare const utils: Utils;
|
|
68
|
+
export { utils, Utils };
|