@whitesev/domutils 1.6.2 → 1.6.4
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 +54 -14
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +54 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +54 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +54 -14
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +54 -14
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +54 -14
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +4 -4
- package/dist/types/src/DOMUtilsEvent.d.ts +11 -11
- package/dist/types/src/WindowApi.d.ts +4 -0
- package/dist/types/src/types/WindowApi.d.ts +4 -0
- package/package.json +1 -1
- package/src/DOMUtils.ts +25 -9
- package/src/DOMUtilsCommonUtils.ts +8 -4
- package/src/DOMUtilsEvent.ts +23 -16
- package/src/WindowApi.ts +16 -0
- package/src/types/WindowApi.d.ts +4 -0
|
@@ -127,7 +127,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
127
127
|
* DOMUtils.text("a.xx","abcd")
|
|
128
128
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
129
129
|
* */
|
|
130
|
-
text(element: DOMUtilsTargetElementType): string;
|
|
130
|
+
text(element: DOMUtilsTargetElementType | Element | DocumentFragment | Node): string;
|
|
131
131
|
/**
|
|
132
132
|
* 设置元素的文本内容
|
|
133
133
|
* @param element 目标元素
|
|
@@ -139,7 +139,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
139
139
|
* DOMUtils.text("a.xx","abcd")
|
|
140
140
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
141
141
|
* */
|
|
142
|
-
text(element: DOMUtilsTargetElementType | DocumentFragment, text: string | HTMLElement | Element | number): void;
|
|
142
|
+
text(element: DOMUtilsTargetElementType | Element | DocumentFragment | Node, text: string | HTMLElement | Element | number): void;
|
|
143
143
|
/**
|
|
144
144
|
* 设置元素的HTML内容
|
|
145
145
|
* @param element 目标元素
|
|
@@ -328,7 +328,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
328
328
|
* DOMUtils.remove(document.querySelectorAll("a.xx"))
|
|
329
329
|
* DOMUtils.remove("a.xx")
|
|
330
330
|
* */
|
|
331
|
-
remove(element: DOMUtilsTargetElementType): void;
|
|
331
|
+
remove(element: DOMUtilsTargetElementType | Element): void;
|
|
332
332
|
/**
|
|
333
333
|
* 移除元素的所有子元素
|
|
334
334
|
* @param element 目标元素
|
|
@@ -337,7 +337,7 @@ declare class DOMUtils extends DOMUtilsEvent {
|
|
|
337
337
|
* DOMUtils.empty(document.querySelector("a.xx"))
|
|
338
338
|
* DOMUtils.empty("a.xx")
|
|
339
339
|
* */
|
|
340
|
-
empty(element: DOMUtilsTargetElementType): void;
|
|
340
|
+
empty(element: DOMUtilsTargetElementType | Element): void;
|
|
341
341
|
/**
|
|
342
342
|
* 获取元素相对于文档的偏移坐标(加上文档的滚动条)
|
|
343
343
|
* @param element 目标元素
|
|
@@ -186,7 +186,7 @@ export declare class DOMUtilsEvent {
|
|
|
186
186
|
* DOMUtils.trigger(document.querySelector("a.xx"),"click tap hover")
|
|
187
187
|
* DOMUtils.trigger("a.xx",["click","tap","hover"])
|
|
188
188
|
*/
|
|
189
|
-
trigger(element: DOMUtilsTargetElementType | any[] | typeof globalThis | Window | Document, eventType: string, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
189
|
+
trigger(element: DOMUtilsTargetElementType | Element | DocumentFragment | any[] | typeof globalThis | Window | Document, eventType: string, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
190
190
|
/**
|
|
191
191
|
* 主动触发事件
|
|
192
192
|
* @param element 需要触发的元素|元素数组|window
|
|
@@ -216,7 +216,7 @@ export declare class DOMUtilsEvent {
|
|
|
216
216
|
* console.log("触发click事件成功")
|
|
217
217
|
* })
|
|
218
218
|
* */
|
|
219
|
-
click(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["click"]) => void, details?: any, useDispatchToTriggerEvent?: boolean): void;
|
|
219
|
+
click(element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["click"]) => void, details?: any, useDispatchToTriggerEvent?: boolean): void;
|
|
220
220
|
/**
|
|
221
221
|
* 绑定或触发元素的blur事件
|
|
222
222
|
* @param element 目标元素
|
|
@@ -231,7 +231,7 @@ export declare class DOMUtilsEvent {
|
|
|
231
231
|
* console.log("触发blur事件成功")
|
|
232
232
|
* })
|
|
233
233
|
* */
|
|
234
|
-
blur(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["blur"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
234
|
+
blur(element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["blur"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
235
235
|
/**
|
|
236
236
|
* 绑定或触发元素的focus事件
|
|
237
237
|
* @param element 目标元素
|
|
@@ -246,7 +246,7 @@ export declare class DOMUtilsEvent {
|
|
|
246
246
|
* console.log("触发focus事件成功")
|
|
247
247
|
* })
|
|
248
248
|
* */
|
|
249
|
-
focus(element: DOMUtilsTargetElementType | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["focus"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
249
|
+
focus(element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window, handler?: (this: HTMLElement, event: DOMUtils_Event["focus"]) => void, details?: object, useDispatchToTriggerEvent?: boolean): void;
|
|
250
250
|
/**
|
|
251
251
|
* 当鼠标移入或移出元素时触发事件
|
|
252
252
|
* @param element 当前元素
|
|
@@ -261,14 +261,14 @@ export declare class DOMUtilsEvent {
|
|
|
261
261
|
* console.log("移入/移除");
|
|
262
262
|
* })
|
|
263
263
|
*/
|
|
264
|
-
hover(element: DOMUtilsTargetElementType, handler: (this: HTMLElement, event: DOMUtils_Event["hover"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
264
|
+
hover(element: DOMUtilsTargetElementType | Element | DocumentFragment | Node, handler: (this: HTMLElement, event: DOMUtils_Event["hover"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
265
265
|
/**
|
|
266
266
|
* 当动画结束时触发事件
|
|
267
267
|
* @param element 监听的元素
|
|
268
268
|
* @param handler 触发的回调函数
|
|
269
269
|
* @param option 配置项,这里默认配置once为true
|
|
270
270
|
*/
|
|
271
|
-
animationend(element: HTMLElement | string, handler: (this: HTMLElement, event: DOMUtils_Event["animationend"]) => void, option?: boolean | DOMUtilsEventListenerOption): {
|
|
271
|
+
animationend(element: HTMLElement | string | Element | DocumentFragment, handler: (this: HTMLElement, event: DOMUtils_Event["animationend"]) => void, option?: boolean | DOMUtilsEventListenerOption): {
|
|
272
272
|
off(): void;
|
|
273
273
|
} | undefined;
|
|
274
274
|
/**
|
|
@@ -277,7 +277,7 @@ export declare class DOMUtilsEvent {
|
|
|
277
277
|
* @param handler 触发的回调函数
|
|
278
278
|
* @param option 配置项,这里默认配置once为true
|
|
279
279
|
*/
|
|
280
|
-
transitionend(element: HTMLElement | string, handler: (this: HTMLElement, event: DOMUtils_Event["transitionend"]) => void, option?: boolean | DOMUtilsEventListenerOption): {
|
|
280
|
+
transitionend(element: HTMLElement | string | Element | DocumentFragment, handler: (this: HTMLElement, event: DOMUtils_Event["transitionend"]) => void, option?: boolean | DOMUtilsEventListenerOption): {
|
|
281
281
|
off(): void;
|
|
282
282
|
} | undefined;
|
|
283
283
|
/**
|
|
@@ -295,7 +295,7 @@ export declare class DOMUtilsEvent {
|
|
|
295
295
|
* console.log("按键松开");
|
|
296
296
|
* })
|
|
297
297
|
*/
|
|
298
|
-
keyup(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keyup"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
298
|
+
keyup(element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keyup"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
299
299
|
/**
|
|
300
300
|
* 当按键按下时触发事件
|
|
301
301
|
* keydown - > keypress - > keyup
|
|
@@ -311,7 +311,7 @@ export declare class DOMUtilsEvent {
|
|
|
311
311
|
* console.log("按键按下");
|
|
312
312
|
* })
|
|
313
313
|
*/
|
|
314
|
-
keydown(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keydown"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
314
|
+
keydown(element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keydown"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
315
315
|
/**
|
|
316
316
|
* 当按键按下时触发事件
|
|
317
317
|
* keydown - > keypress - > keyup
|
|
@@ -327,7 +327,7 @@ export declare class DOMUtilsEvent {
|
|
|
327
327
|
* console.log("按键按下");
|
|
328
328
|
* })
|
|
329
329
|
*/
|
|
330
|
-
keypress(element: DOMUtilsTargetElementType | Window | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keypress"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
330
|
+
keypress(element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis, handler: (this: HTMLElement, event: DOMUtils_Event["keypress"]) => void, option?: boolean | DOMUtilsEventListenerOption): void;
|
|
331
331
|
/**
|
|
332
332
|
* 监听某个元素键盘按键事件或window全局按键事件
|
|
333
333
|
* 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
|
|
@@ -391,7 +391,7 @@ export declare class DOMUtilsEvent {
|
|
|
391
391
|
搜索 170
|
|
392
392
|
收藏 171
|
|
393
393
|
**/
|
|
394
|
-
listenKeyboard(element: DOMUtilsTargetElementType | Window | Node | typeof globalThis, eventName: "keyup" | "keypress" | "keydown" | undefined, callback: (keyName: string, keyValue: number, otherCodeList: string[], event: KeyboardEvent) => void, options?: DOMUtilsEventListenerOption | boolean): {
|
|
394
|
+
listenKeyboard(element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis, eventName: "keyup" | "keypress" | "keydown" | undefined, callback: (keyName: string, keyValue: number, otherCodeList: string[], event: KeyboardEvent) => void, options?: DOMUtilsEventListenerOption | boolean): {
|
|
395
395
|
removeListen(): void;
|
|
396
396
|
};
|
|
397
397
|
/**
|
|
@@ -10,4 +10,8 @@ export declare class WindowApi {
|
|
|
10
10
|
get globalThis(): typeof globalThis | Window;
|
|
11
11
|
get self(): Window & typeof globalThis;
|
|
12
12
|
get top(): Window;
|
|
13
|
+
get setTimeout(): typeof setTimeout;
|
|
14
|
+
get clearTimeout(): typeof clearTimeout;
|
|
15
|
+
get setInterval(): typeof setInterval;
|
|
16
|
+
get clearInterval(): typeof clearInterval;
|
|
13
17
|
}
|
|
@@ -7,4 +7,8 @@ export type WindowApiOption = {
|
|
|
7
7
|
globalThis?: typeof globalThis | Window;
|
|
8
8
|
self?: Window & typeof globalThis;
|
|
9
9
|
top: Window;
|
|
10
|
+
setTimeout: typeof setTimeout;
|
|
11
|
+
clearTimeout: typeof clearTimeout;
|
|
12
|
+
setInterval: typeof setInterval;
|
|
13
|
+
clearInterval: typeof clearInterval;
|
|
10
14
|
};
|
package/package.json
CHANGED
package/src/DOMUtils.ts
CHANGED
|
@@ -295,7 +295,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
295
295
|
* DOMUtils.text("a.xx","abcd")
|
|
296
296
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
297
297
|
* */
|
|
298
|
-
text(element: DOMUtilsTargetElementType): string;
|
|
298
|
+
text(element: DOMUtilsTargetElementType | Element | DocumentFragment | Node): string;
|
|
299
299
|
/**
|
|
300
300
|
* 设置元素的文本内容
|
|
301
301
|
* @param element 目标元素
|
|
@@ -308,10 +308,10 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
308
308
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
309
309
|
* */
|
|
310
310
|
text(
|
|
311
|
-
element: DOMUtilsTargetElementType | DocumentFragment,
|
|
311
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Node,
|
|
312
312
|
text: string | HTMLElement | Element | number
|
|
313
313
|
): void;
|
|
314
|
-
text(element: DOMUtilsTargetElementType | DocumentFragment, text?: any) {
|
|
314
|
+
text(element: DOMUtilsTargetElementType | Element | DocumentFragment | Node, text?: any) {
|
|
315
315
|
let DOMUtilsContext = this;
|
|
316
316
|
if (typeof element === "string") {
|
|
317
317
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -713,7 +713,13 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
713
713
|
if (typeof newElement === "string") {
|
|
714
714
|
newElement = DOMUtilsContext.parseHTML(newElement, false, false);
|
|
715
715
|
}
|
|
716
|
-
|
|
716
|
+
let $parent = element.parentElement;
|
|
717
|
+
if ($parent) {
|
|
718
|
+
$parent.replaceChild(newElement as Node, element);
|
|
719
|
+
} else {
|
|
720
|
+
DOMUtilsContext.after(element, newElement as HTMLElement);
|
|
721
|
+
element.remove();
|
|
722
|
+
}
|
|
717
723
|
}
|
|
718
724
|
/**
|
|
719
725
|
* 给元素添加class
|
|
@@ -962,7 +968,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
962
968
|
* DOMUtils.remove(document.querySelectorAll("a.xx"))
|
|
963
969
|
* DOMUtils.remove("a.xx")
|
|
964
970
|
* */
|
|
965
|
-
remove(element: DOMUtilsTargetElementType) {
|
|
971
|
+
remove(element: DOMUtilsTargetElementType | Element) {
|
|
966
972
|
let DOMUtilsContext = this;
|
|
967
973
|
if (typeof element === "string") {
|
|
968
974
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -976,7 +982,13 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
976
982
|
});
|
|
977
983
|
return;
|
|
978
984
|
}
|
|
979
|
-
element.remove
|
|
985
|
+
if (typeof element.remove === "function") {
|
|
986
|
+
element.remove();
|
|
987
|
+
} else if (element.parentElement) {
|
|
988
|
+
element.parentElement.removeChild(element);
|
|
989
|
+
} else if (element.parentNode) {
|
|
990
|
+
element.parentNode.removeChild(element);
|
|
991
|
+
}
|
|
980
992
|
}
|
|
981
993
|
/**
|
|
982
994
|
* 移除元素的所有子元素
|
|
@@ -986,7 +998,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
986
998
|
* DOMUtils.empty(document.querySelector("a.xx"))
|
|
987
999
|
* DOMUtils.empty("a.xx")
|
|
988
1000
|
* */
|
|
989
|
-
empty(element: DOMUtilsTargetElementType) {
|
|
1001
|
+
empty(element: DOMUtilsTargetElementType | Element) {
|
|
990
1002
|
let DOMUtilsContext = this;
|
|
991
1003
|
if (typeof element === "string") {
|
|
992
1004
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -1001,7 +1013,11 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1001
1013
|
});
|
|
1002
1014
|
return;
|
|
1003
1015
|
}
|
|
1004
|
-
|
|
1016
|
+
if (element.innerHTML) {
|
|
1017
|
+
element.innerHTML = "";
|
|
1018
|
+
} else if (element.textContent) {
|
|
1019
|
+
element.textContent = "";
|
|
1020
|
+
}
|
|
1005
1021
|
}
|
|
1006
1022
|
/**
|
|
1007
1023
|
* 获取元素相对于文档的偏移坐标(加上文档的滚动条)
|
|
@@ -1496,7 +1512,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1496
1512
|
* DOMUtils.parent("a.xx")
|
|
1497
1513
|
* > <div ...>....</div>
|
|
1498
1514
|
*/
|
|
1499
|
-
parent(element: HTMLElement | NodeList | string | HTMLElement[]) {
|
|
1515
|
+
parent(element: HTMLElement | Element | Node | NodeList | string | HTMLElement[]) {
|
|
1500
1516
|
let DOMUtilsContext = this;
|
|
1501
1517
|
if (typeof element === "string") {
|
|
1502
1518
|
element = DOMUtilsContext.selector<HTMLElement>(element)!;
|
|
@@ -12,6 +12,10 @@ const DOMUtilsCommonUtils = {
|
|
|
12
12
|
document: document,
|
|
13
13
|
window: window,
|
|
14
14
|
top: top!,
|
|
15
|
+
setTimeout: setTimeout,
|
|
16
|
+
clearTimeout: clearTimeout,
|
|
17
|
+
setInterval: setInterval,
|
|
18
|
+
clearInterval: clearInterval,
|
|
15
19
|
}),
|
|
16
20
|
/**
|
|
17
21
|
* 判断元素是否已显示或已连接
|
|
@@ -142,7 +146,7 @@ const DOMUtilsCommonUtils = {
|
|
|
142
146
|
try {
|
|
143
147
|
return WorkerSetTimeout(callback, timeout);
|
|
144
148
|
} catch (error) {
|
|
145
|
-
return
|
|
149
|
+
return this.windowApi.setTimeout(callback, timeout);
|
|
146
150
|
}
|
|
147
151
|
},
|
|
148
152
|
/**
|
|
@@ -155,7 +159,7 @@ const DOMUtilsCommonUtils = {
|
|
|
155
159
|
}
|
|
156
160
|
} catch (error) {
|
|
157
161
|
} finally {
|
|
158
|
-
|
|
162
|
+
this.windowApi.clearTimeout(timeId);
|
|
159
163
|
}
|
|
160
164
|
},
|
|
161
165
|
/**
|
|
@@ -165,7 +169,7 @@ const DOMUtilsCommonUtils = {
|
|
|
165
169
|
try {
|
|
166
170
|
return WorkerSetInterval(callback, timeout);
|
|
167
171
|
} catch (error) {
|
|
168
|
-
return
|
|
172
|
+
return this.windowApi.setInterval(callback, timeout);
|
|
169
173
|
}
|
|
170
174
|
},
|
|
171
175
|
/**
|
|
@@ -178,7 +182,7 @@ const DOMUtilsCommonUtils = {
|
|
|
178
182
|
}
|
|
179
183
|
} catch (error) {
|
|
180
184
|
} finally {
|
|
181
|
-
|
|
185
|
+
this.windowApi.clearInterval(timeId);
|
|
182
186
|
}
|
|
183
187
|
},
|
|
184
188
|
/**
|
package/src/DOMUtilsEvent.ts
CHANGED
|
@@ -728,7 +728,14 @@ export class DOMUtilsEvent {
|
|
|
728
728
|
* DOMUtils.trigger("a.xx",["click","tap","hover"])
|
|
729
729
|
*/
|
|
730
730
|
trigger(
|
|
731
|
-
element:
|
|
731
|
+
element:
|
|
732
|
+
| DOMUtilsTargetElementType
|
|
733
|
+
| Element
|
|
734
|
+
| DocumentFragment
|
|
735
|
+
| any[]
|
|
736
|
+
| typeof globalThis
|
|
737
|
+
| Window
|
|
738
|
+
| Document,
|
|
732
739
|
eventType: string,
|
|
733
740
|
details?: object,
|
|
734
741
|
useDispatchToTriggerEvent?: boolean
|
|
@@ -835,7 +842,7 @@ export class DOMUtilsEvent {
|
|
|
835
842
|
* })
|
|
836
843
|
* */
|
|
837
844
|
click(
|
|
838
|
-
element: DOMUtilsTargetElementType | typeof globalThis | Window,
|
|
845
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window,
|
|
839
846
|
handler?: (this: HTMLElement, event: DOMUtils_Event["click"]) => void,
|
|
840
847
|
details?: any,
|
|
841
848
|
useDispatchToTriggerEvent?: boolean
|
|
@@ -875,14 +882,14 @@ export class DOMUtilsEvent {
|
|
|
875
882
|
* })
|
|
876
883
|
* */
|
|
877
884
|
blur(
|
|
878
|
-
element: DOMUtilsTargetElementType | typeof globalThis | Window,
|
|
885
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window,
|
|
879
886
|
handler?: (this: HTMLElement, event: DOMUtils_Event["blur"]) => void,
|
|
880
887
|
details?: object,
|
|
881
888
|
useDispatchToTriggerEvent?: boolean
|
|
882
889
|
) {
|
|
883
890
|
let DOMUtilsContext = this;
|
|
884
891
|
if (typeof element === "string") {
|
|
885
|
-
element = DOMUtilsContext.selectorAll
|
|
892
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
886
893
|
}
|
|
887
894
|
if (element == null) {
|
|
888
895
|
return;
|
|
@@ -915,14 +922,14 @@ export class DOMUtilsEvent {
|
|
|
915
922
|
* })
|
|
916
923
|
* */
|
|
917
924
|
focus(
|
|
918
|
-
element: DOMUtilsTargetElementType | typeof globalThis | Window,
|
|
925
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | typeof globalThis | Window,
|
|
919
926
|
handler?: (this: HTMLElement, event: DOMUtils_Event["focus"]) => void,
|
|
920
927
|
details?: object,
|
|
921
928
|
useDispatchToTriggerEvent?: boolean
|
|
922
929
|
) {
|
|
923
930
|
let DOMUtilsContext = this;
|
|
924
931
|
if (typeof element === "string") {
|
|
925
|
-
element = DOMUtilsContext.selectorAll
|
|
932
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
926
933
|
}
|
|
927
934
|
if (element == null) {
|
|
928
935
|
return;
|
|
@@ -955,13 +962,13 @@ export class DOMUtilsEvent {
|
|
|
955
962
|
* })
|
|
956
963
|
*/
|
|
957
964
|
hover(
|
|
958
|
-
element: DOMUtilsTargetElementType,
|
|
965
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Node,
|
|
959
966
|
handler: (this: HTMLElement, event: DOMUtils_Event["hover"]) => void,
|
|
960
967
|
option?: boolean | DOMUtilsEventListenerOption
|
|
961
968
|
) {
|
|
962
969
|
let DOMUtilsContext = this;
|
|
963
970
|
if (typeof element === "string") {
|
|
964
|
-
element = DOMUtilsContext.selectorAll
|
|
971
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
965
972
|
}
|
|
966
973
|
if (element == null) {
|
|
967
974
|
return;
|
|
@@ -983,13 +990,13 @@ export class DOMUtilsEvent {
|
|
|
983
990
|
* @param option 配置项,这里默认配置once为true
|
|
984
991
|
*/
|
|
985
992
|
animationend(
|
|
986
|
-
element: HTMLElement | string,
|
|
993
|
+
element: HTMLElement | string | Element | DocumentFragment,
|
|
987
994
|
handler: (this: HTMLElement, event: DOMUtils_Event["animationend"]) => void,
|
|
988
995
|
option?: boolean | DOMUtilsEventListenerOption
|
|
989
996
|
) {
|
|
990
997
|
let DOMUtilsContext = this;
|
|
991
998
|
if (typeof element === "string") {
|
|
992
|
-
element = DOMUtilsContext.selector
|
|
999
|
+
element = DOMUtilsContext.selector(element)!;
|
|
993
1000
|
}
|
|
994
1001
|
if (element == null) {
|
|
995
1002
|
return;
|
|
@@ -1022,13 +1029,13 @@ export class DOMUtilsEvent {
|
|
|
1022
1029
|
* @param option 配置项,这里默认配置once为true
|
|
1023
1030
|
*/
|
|
1024
1031
|
transitionend(
|
|
1025
|
-
element: HTMLElement | string,
|
|
1032
|
+
element: HTMLElement | string | Element | DocumentFragment,
|
|
1026
1033
|
handler: (this: HTMLElement, event: DOMUtils_Event["transitionend"]) => void,
|
|
1027
1034
|
option?: boolean | DOMUtilsEventListenerOption
|
|
1028
1035
|
) {
|
|
1029
1036
|
let DOMUtilsContext = this;
|
|
1030
1037
|
if (typeof element === "string") {
|
|
1031
|
-
element = DOMUtilsContext.selector
|
|
1038
|
+
element = DOMUtilsContext.selector(element)!;
|
|
1032
1039
|
}
|
|
1033
1040
|
if (element == null) {
|
|
1034
1041
|
return;
|
|
@@ -1070,7 +1077,7 @@ export class DOMUtilsEvent {
|
|
|
1070
1077
|
* })
|
|
1071
1078
|
*/
|
|
1072
1079
|
keyup(
|
|
1073
|
-
element: DOMUtilsTargetElementType | Window | typeof globalThis,
|
|
1080
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
|
|
1074
1081
|
handler: (this: HTMLElement, event: DOMUtils_Event["keyup"]) => void,
|
|
1075
1082
|
option?: boolean | DOMUtilsEventListenerOption
|
|
1076
1083
|
) {
|
|
@@ -1106,7 +1113,7 @@ export class DOMUtilsEvent {
|
|
|
1106
1113
|
* })
|
|
1107
1114
|
*/
|
|
1108
1115
|
keydown(
|
|
1109
|
-
element: DOMUtilsTargetElementType | Window | typeof globalThis,
|
|
1116
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
|
|
1110
1117
|
handler: (this: HTMLElement, event: DOMUtils_Event["keydown"]) => void,
|
|
1111
1118
|
option?: boolean | DOMUtilsEventListenerOption
|
|
1112
1119
|
) {
|
|
@@ -1142,7 +1149,7 @@ export class DOMUtilsEvent {
|
|
|
1142
1149
|
* })
|
|
1143
1150
|
*/
|
|
1144
1151
|
keypress(
|
|
1145
|
-
element: DOMUtilsTargetElementType | Window | typeof globalThis,
|
|
1152
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
|
|
1146
1153
|
handler: (this: HTMLElement, event: DOMUtils_Event["keypress"]) => void,
|
|
1147
1154
|
option?: boolean | DOMUtilsEventListenerOption
|
|
1148
1155
|
) {
|
|
@@ -1226,7 +1233,7 @@ export class DOMUtilsEvent {
|
|
|
1226
1233
|
收藏 171
|
|
1227
1234
|
**/
|
|
1228
1235
|
listenKeyboard(
|
|
1229
|
-
element: DOMUtilsTargetElementType | Window | Node | typeof globalThis,
|
|
1236
|
+
element: DOMUtilsTargetElementType | Element | DocumentFragment | Window | Node | typeof globalThis,
|
|
1230
1237
|
eventName: "keyup" | "keypress" | "keydown" = "keypress",
|
|
1231
1238
|
callback: (keyName: string, keyValue: number, otherCodeList: string[], event: KeyboardEvent) => void,
|
|
1232
1239
|
options?: DOMUtilsEventListenerOption | boolean
|
package/src/WindowApi.ts
CHANGED
|
@@ -8,6 +8,10 @@ export class WindowApi {
|
|
|
8
8
|
globalThis: globalThis,
|
|
9
9
|
self: self,
|
|
10
10
|
top: top!,
|
|
11
|
+
setTimeout: globalThis.setTimeout,
|
|
12
|
+
clearTimeout: globalThis.clearTimeout,
|
|
13
|
+
setInterval: globalThis.setInterval,
|
|
14
|
+
clearInterval: globalThis.clearInterval,
|
|
11
15
|
};
|
|
12
16
|
/** 使用的配置 */
|
|
13
17
|
private api: Required<WindowApiOption>;
|
|
@@ -41,4 +45,16 @@ export class WindowApi {
|
|
|
41
45
|
get top() {
|
|
42
46
|
return this.api.top;
|
|
43
47
|
}
|
|
48
|
+
get setTimeout() {
|
|
49
|
+
return this.api.setTimeout;
|
|
50
|
+
}
|
|
51
|
+
get clearTimeout() {
|
|
52
|
+
return this.api.clearTimeout;
|
|
53
|
+
}
|
|
54
|
+
get setInterval() {
|
|
55
|
+
return this.api.setInterval;
|
|
56
|
+
}
|
|
57
|
+
get clearInterval() {
|
|
58
|
+
return this.api.clearInterval;
|
|
59
|
+
}
|
|
44
60
|
}
|
package/src/types/WindowApi.d.ts
CHANGED
|
@@ -7,4 +7,8 @@ export type WindowApiOption = {
|
|
|
7
7
|
globalThis?: typeof globalThis | Window;
|
|
8
8
|
self?: Window & typeof globalThis;
|
|
9
9
|
top: Window;
|
|
10
|
+
setTimeout: typeof setTimeout;
|
|
11
|
+
clearTimeout: typeof clearTimeout;
|
|
12
|
+
setInterval: typeof setInterval;
|
|
13
|
+
clearInterval: typeof clearInterval;
|
|
10
14
|
};
|