@whitesev/domutils 1.3.7 → 1.4.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/LICENSE +674 -0
- package/dist/index.amd.js +98 -55
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -55
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -55
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -55
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -55
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -55
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +14 -7
- package/dist/types/src/DOMUtilsCommonUtils.d.ts +2 -2
- package/dist/types/src/DOMUtilsData.d.ts +1 -1
- package/dist/types/src/DOMUtilsEvent.d.ts +5 -204
- package/dist/types/src/WindowApi.d.ts +2 -11
- package/dist/types/src/types/DOMUtilsEvent.d.ts +238 -0
- package/dist/types/src/types/WindowApi.d.ts +10 -0
- package/package.json +1 -1
- package/src/DOMUtils.ts +68 -46
- package/src/DOMUtilsCommonUtils.ts +5 -4
- package/src/DOMUtilsData.ts +1 -1
- package/src/DOMUtilsEvent.ts +12 -248
- package/src/WindowApi.ts +13 -13
- package/src/types/DOMUtilsEvent.d.ts +238 -0
- package/src/types/WindowApi.d.ts +10 -0
package/src/DOMUtils.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { DOMUtilsCommonUtils } from "./DOMUtilsCommonUtils";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
DOMUtilsEvent,
|
|
5
|
-
} from "./DOMUtilsEvent";
|
|
2
|
+
import { DOMUtilsEvent } from "./DOMUtilsEvent";
|
|
3
|
+
import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
|
|
6
4
|
import {
|
|
7
5
|
ParseHTMLReturnType,
|
|
8
6
|
type DOMUtilsTargetElementType,
|
|
9
7
|
} from "./types/global";
|
|
10
|
-
import {
|
|
8
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* 判断是否是元素列表
|
|
@@ -18,11 +16,11 @@ export const isNodeList = ($ele: any): $ele is any[] | NodeList => {
|
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
class DOMUtils extends DOMUtilsEvent {
|
|
21
|
-
constructor(option?:
|
|
19
|
+
constructor(option?: WindowApiOption) {
|
|
22
20
|
super(option);
|
|
23
21
|
}
|
|
24
22
|
/** 版本号 */
|
|
25
|
-
version = "2024.
|
|
23
|
+
version = "2024.11.6";
|
|
26
24
|
/**
|
|
27
25
|
* 获取元素的属性值
|
|
28
26
|
* @param element 目标元素
|
|
@@ -489,9 +487,10 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
489
487
|
element:
|
|
490
488
|
| HTMLInputElement
|
|
491
489
|
| HTMLTextAreaElement
|
|
490
|
+
| HTMLSelectElement
|
|
492
491
|
| string
|
|
493
|
-
| (HTMLInputElement | HTMLTextAreaElement)[]
|
|
494
|
-
| NodeListOf<HTMLInputElement | HTMLTextAreaElement>,
|
|
492
|
+
| (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
|
493
|
+
| NodeListOf<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
|
|
495
494
|
value: string | boolean | number
|
|
496
495
|
): void;
|
|
497
496
|
/**
|
|
@@ -505,9 +504,10 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
505
504
|
element:
|
|
506
505
|
| HTMLInputElement
|
|
507
506
|
| HTMLTextAreaElement
|
|
507
|
+
| HTMLSelectElement
|
|
508
508
|
| string
|
|
509
|
-
| (HTMLInputElement | HTMLTextAreaElement)[]
|
|
510
|
-
| NodeListOf<HTMLInputElement | HTMLTextAreaElement>
|
|
509
|
+
| (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
|
510
|
+
| NodeListOf<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>
|
|
511
511
|
): string;
|
|
512
512
|
/**
|
|
513
513
|
* 获取value属性值
|
|
@@ -521,16 +521,18 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
521
521
|
element:
|
|
522
522
|
| HTMLInputElement
|
|
523
523
|
| HTMLTextAreaElement
|
|
524
|
-
|
|
|
525
|
-
|
|
|
524
|
+
| HTMLSelectElement
|
|
525
|
+
| (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
|
526
|
+
| NodeListOf<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>
|
|
526
527
|
): boolean | string;
|
|
527
528
|
val(
|
|
528
529
|
element:
|
|
529
530
|
| HTMLInputElement
|
|
530
531
|
| HTMLTextAreaElement
|
|
532
|
+
| HTMLSelectElement
|
|
531
533
|
| string
|
|
532
|
-
| (HTMLInputElement | HTMLTextAreaElement)[]
|
|
533
|
-
| NodeListOf<HTMLInputElement | HTMLTextAreaElement>,
|
|
534
|
+
| (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
|
535
|
+
| NodeListOf<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
|
|
534
536
|
value?: string | boolean | number
|
|
535
537
|
) {
|
|
536
538
|
let DOMUtilsContext = this;
|
|
@@ -785,6 +787,44 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
785
787
|
element.classList.add(itemClassName);
|
|
786
788
|
});
|
|
787
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* 判断元素是否存在className
|
|
792
|
+
* @param element
|
|
793
|
+
* @param className
|
|
794
|
+
*/
|
|
795
|
+
hasClass(
|
|
796
|
+
element: DOMUtilsTargetElementType,
|
|
797
|
+
className: string | string[]
|
|
798
|
+
): boolean {
|
|
799
|
+
let DOMUtilsContext = this;
|
|
800
|
+
if (typeof element === "string") {
|
|
801
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
802
|
+
}
|
|
803
|
+
if (element == null) {
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
if (isNodeList(element)) {
|
|
807
|
+
let flag = true;
|
|
808
|
+
for (let index = 0; index < element.length; index++) {
|
|
809
|
+
const $ele = element[index] as HTMLElement;
|
|
810
|
+
flag = flag && DOMUtilsContext.hasClass($ele, className);
|
|
811
|
+
}
|
|
812
|
+
return flag;
|
|
813
|
+
}
|
|
814
|
+
if (!element?.classList) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
if (!Array.isArray(className)) {
|
|
818
|
+
className = className.split(" ");
|
|
819
|
+
}
|
|
820
|
+
for (let index = 0; index < className.length; index++) {
|
|
821
|
+
const item = className[index].trim();
|
|
822
|
+
if (!element.classList.contains(item)) {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
788
828
|
/**
|
|
789
829
|
* 函数在元素内部末尾添加子元素或HTML字符串
|
|
790
830
|
* @param element 目标元素
|
|
@@ -1008,9 +1048,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1008
1048
|
offset(element: HTMLElement | string) {
|
|
1009
1049
|
let DOMUtilsContext = this;
|
|
1010
1050
|
if (typeof element === "string") {
|
|
1011
|
-
element = DOMUtilsContext.
|
|
1012
|
-
element
|
|
1013
|
-
) as HTMLElement;
|
|
1051
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1014
1052
|
}
|
|
1015
1053
|
if (element == null) {
|
|
1016
1054
|
return;
|
|
@@ -1053,8 +1091,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1053
1091
|
) {
|
|
1054
1092
|
let DOMUtilsContext = this;
|
|
1055
1093
|
if (typeof element === "string") {
|
|
1056
|
-
element =
|
|
1057
|
-
DOMUtilsContext.windowApi.document.querySelector<HTMLElement>(element)!;
|
|
1094
|
+
element = DOMUtilsContext.selector<HTMLElement>(element)!;
|
|
1058
1095
|
}
|
|
1059
1096
|
if (element == null) {
|
|
1060
1097
|
return;
|
|
@@ -1161,9 +1198,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1161
1198
|
.clientHeight;
|
|
1162
1199
|
}
|
|
1163
1200
|
if (typeof element === "string") {
|
|
1164
|
-
element = DOMUtilsContext.
|
|
1165
|
-
element
|
|
1166
|
-
) as HTMLElement;
|
|
1201
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1167
1202
|
}
|
|
1168
1203
|
if (element == null) {
|
|
1169
1204
|
// @ts-ignore
|
|
@@ -1261,9 +1296,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1261
1296
|
return DOMUtilsContext.windowApi.window.innerWidth;
|
|
1262
1297
|
}
|
|
1263
1298
|
if (typeof element === "string") {
|
|
1264
|
-
element = DOMUtilsContext.
|
|
1265
|
-
element
|
|
1266
|
-
) as HTMLElement;
|
|
1299
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1267
1300
|
}
|
|
1268
1301
|
if (element == null) {
|
|
1269
1302
|
// @ts-ignore
|
|
@@ -1312,9 +1345,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1312
1345
|
return DOMUtilsContext.windowApi.window.innerHeight;
|
|
1313
1346
|
}
|
|
1314
1347
|
if (typeof element === "string") {
|
|
1315
|
-
element = DOMUtilsContext.
|
|
1316
|
-
element
|
|
1317
|
-
) as HTMLElement;
|
|
1348
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1318
1349
|
}
|
|
1319
1350
|
if (element == null) {
|
|
1320
1351
|
// @ts-ignore
|
|
@@ -1469,9 +1500,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1469
1500
|
prev(element: HTMLElement | string) {
|
|
1470
1501
|
let DOMUtilsContext = this;
|
|
1471
1502
|
if (typeof element === "string") {
|
|
1472
|
-
element = DOMUtilsContext.
|
|
1473
|
-
element
|
|
1474
|
-
) as HTMLElement;
|
|
1503
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1475
1504
|
}
|
|
1476
1505
|
if (element == null) {
|
|
1477
1506
|
return;
|
|
@@ -1493,9 +1522,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1493
1522
|
next(element: HTMLElement | string) {
|
|
1494
1523
|
let DOMUtilsContext = this;
|
|
1495
1524
|
if (typeof element === "string") {
|
|
1496
|
-
element = DOMUtilsContext.
|
|
1497
|
-
element
|
|
1498
|
-
) as HTMLElement;
|
|
1525
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1499
1526
|
}
|
|
1500
1527
|
if (element == null) {
|
|
1501
1528
|
return;
|
|
@@ -1529,9 +1556,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1529
1556
|
siblings(element: HTMLElement | string) {
|
|
1530
1557
|
let DOMUtilsContext = this;
|
|
1531
1558
|
if (typeof element === "string") {
|
|
1532
|
-
element = DOMUtilsContext.
|
|
1533
|
-
element
|
|
1534
|
-
) as HTMLElement;
|
|
1559
|
+
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
1535
1560
|
}
|
|
1536
1561
|
if (element == null) {
|
|
1537
1562
|
return;
|
|
@@ -1576,18 +1601,15 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1576
1601
|
parent(element: HTMLElement | NodeList | string | HTMLElement[]) {
|
|
1577
1602
|
let DOMUtilsContext = this;
|
|
1578
1603
|
if (typeof element === "string") {
|
|
1579
|
-
element = DOMUtilsContext.
|
|
1580
|
-
element
|
|
1581
|
-
) as HTMLElement;
|
|
1604
|
+
element = DOMUtilsContext.selector<HTMLElement>(element)!;
|
|
1582
1605
|
}
|
|
1583
1606
|
if (element == null) {
|
|
1584
1607
|
return;
|
|
1585
1608
|
}
|
|
1586
|
-
if (element
|
|
1587
|
-
element = element as HTMLElement[];
|
|
1609
|
+
if (isNodeList(element)) {
|
|
1588
1610
|
let resultArray: HTMLElement[] = [];
|
|
1589
|
-
element.forEach((
|
|
1590
|
-
resultArray.push(DOMUtilsContext.parent(
|
|
1611
|
+
element.forEach(($ele) => {
|
|
1612
|
+
resultArray.push(DOMUtilsContext.parent($ele as HTMLElement));
|
|
1591
1613
|
});
|
|
1592
1614
|
return resultArray;
|
|
1593
1615
|
} else {
|
|
@@ -1927,7 +1949,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1927
1949
|
* @param option
|
|
1928
1950
|
* @returns
|
|
1929
1951
|
*/
|
|
1930
|
-
createDOMUtils(option?:
|
|
1952
|
+
createDOMUtils(option?: WindowApiOption) {
|
|
1931
1953
|
return new DOMUtils(option);
|
|
1932
1954
|
}
|
|
1933
1955
|
/**
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WindowApi } from "./WindowApi";
|
|
2
2
|
|
|
3
3
|
/** 通用工具类 */
|
|
4
4
|
const DOMUtilsCommonUtils = {
|
|
5
|
-
windowApi: {
|
|
6
|
-
window: window,
|
|
5
|
+
windowApi: new WindowApi({
|
|
7
6
|
document: document,
|
|
8
|
-
|
|
7
|
+
window: window,
|
|
8
|
+
top: top!,
|
|
9
|
+
}),
|
|
9
10
|
/**
|
|
10
11
|
* 判断元素是否已显示或已连接
|
|
11
12
|
* @param element
|
package/src/DOMUtilsData.ts
CHANGED
package/src/DOMUtilsEvent.ts
CHANGED
|
@@ -2,251 +2,19 @@ import { isNodeList } from "./DOMUtils";
|
|
|
2
2
|
import { DOMUtilsCommonUtils } from "./DOMUtilsCommonUtils";
|
|
3
3
|
import { DOMUtilsData } from "./DOMUtilsData";
|
|
4
4
|
import { OriginPrototype } from "./DOMUtilsOriginPrototype";
|
|
5
|
+
import type {
|
|
6
|
+
DOMUtils_Event,
|
|
7
|
+
DOMUtils_EventType,
|
|
8
|
+
DOMUtilsElementEventType,
|
|
9
|
+
DOMUtilsEventListenerOptionsAttribute,
|
|
10
|
+
} from "./types/DOMUtilsEvent";
|
|
5
11
|
import type { DOMUtilsTargetElementType } from "./types/global";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export type DOMUtilsEventObject<T extends Node> = Event & {
|
|
9
|
-
target: T;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export declare type DOMUtilsCreateElementAttributesMap = {
|
|
13
|
-
style?: string;
|
|
14
|
-
id?: string;
|
|
15
|
-
class?: string;
|
|
16
|
-
"data-"?: string;
|
|
17
|
-
type?: string;
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* 鼠标事件
|
|
22
|
-
* + https://blog.csdn.net/weixin_68658847/article/details/126939879
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export interface DOMUtils_MouseEvent {
|
|
26
|
-
click: MouseEvent | PointerEvent;
|
|
27
|
-
contextmenu: MouseEvent | PointerEvent;
|
|
28
|
-
dblclick: MouseEvent | PointerEvent;
|
|
29
|
-
mousedown: MouseEvent | PointerEvent;
|
|
30
|
-
mouseenter: MouseEvent | PointerEvent;
|
|
31
|
-
mouseleave: MouseEvent | PointerEvent;
|
|
32
|
-
mousemove: MouseEvent | PointerEvent;
|
|
33
|
-
mouseover: MouseEvent | PointerEvent;
|
|
34
|
-
mouseout: MouseEvent | PointerEvent;
|
|
35
|
-
mouseup: MouseEvent | PointerEvent;
|
|
36
|
-
hover: MouseEvent;
|
|
37
|
-
}
|
|
38
|
-
export type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
|
|
39
|
-
/**
|
|
40
|
-
* 鼠标事件
|
|
41
|
-
*/
|
|
42
|
-
export interface DOMUtils_KeyboardEvent {
|
|
43
|
-
keydown: KeyboardEvent;
|
|
44
|
-
keypress: KeyboardEvent;
|
|
45
|
-
keyup: KeyboardEvent;
|
|
46
|
-
}
|
|
47
|
-
export type DOMUtils_KeyboardEventType = keyof DOMUtils_KeyboardEvent;
|
|
48
|
-
/**
|
|
49
|
-
* 框架/对象事件
|
|
50
|
-
*/
|
|
51
|
-
export interface DOMUtils_Frame_Object_Event {
|
|
52
|
-
abort: Event;
|
|
53
|
-
beforeunload: Event;
|
|
54
|
-
error: Event;
|
|
55
|
-
hashchange: Event;
|
|
56
|
-
load: Event;
|
|
57
|
-
pageshow: Event;
|
|
58
|
-
pagehide: Event;
|
|
59
|
-
resize: Event;
|
|
60
|
-
scroll: Event;
|
|
61
|
-
unload: Event;
|
|
62
|
-
}
|
|
63
|
-
export type DOMUtils_Frame_Object_EventType = keyof DOMUtils_Frame_Object_Event;
|
|
64
|
-
/**
|
|
65
|
-
* 表单事件
|
|
66
|
-
*/
|
|
67
|
-
export interface DOMUtils_FormEvent {
|
|
68
|
-
blur: Event;
|
|
69
|
-
change: Event;
|
|
70
|
-
focus: Event;
|
|
71
|
-
focusin: Event;
|
|
72
|
-
focusout: Event;
|
|
73
|
-
input: Event;
|
|
74
|
-
reset: Event;
|
|
75
|
-
search: Event;
|
|
76
|
-
}
|
|
77
|
-
export type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 剪贴板事件
|
|
81
|
-
*/
|
|
82
|
-
export interface DOMUtils_ClipboardEvent {
|
|
83
|
-
copy: ClipboardEvent;
|
|
84
|
-
cut: ClipboardEvent;
|
|
85
|
-
paste: ClipboardEvent;
|
|
86
|
-
}
|
|
87
|
-
export type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 打印事件
|
|
91
|
-
*/
|
|
92
|
-
export interface DOMUtils_PrintEvent {
|
|
93
|
-
afterprint: Event;
|
|
94
|
-
beforeprint: Event;
|
|
95
|
-
}
|
|
96
|
-
export type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 拖动事件
|
|
100
|
-
*/
|
|
101
|
-
export interface DOMUtils_DragEvent {
|
|
102
|
-
drag: DragEvent;
|
|
103
|
-
dragend: DragEvent;
|
|
104
|
-
dragenter: DragEvent;
|
|
105
|
-
dragleave: DragEvent;
|
|
106
|
-
dragover: DragEvent;
|
|
107
|
-
dragstart: DragEvent;
|
|
108
|
-
drop: DragEvent;
|
|
109
|
-
}
|
|
110
|
-
export type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 多媒体(Media)事件
|
|
114
|
-
*/
|
|
115
|
-
export interface DOMUtils_MediaEvent {
|
|
116
|
-
abort: Event;
|
|
117
|
-
canplay: Event;
|
|
118
|
-
canplaythrough: Event;
|
|
119
|
-
durationchange: Event;
|
|
120
|
-
emptied: Event;
|
|
121
|
-
ended: Event;
|
|
122
|
-
error: Event;
|
|
123
|
-
loadeddata: Event;
|
|
124
|
-
loadedmetadata: Event;
|
|
125
|
-
loadstart: Event;
|
|
126
|
-
pause: Event;
|
|
127
|
-
play: Event;
|
|
128
|
-
playing: Event;
|
|
129
|
-
progress: Event;
|
|
130
|
-
ratechange: Event;
|
|
131
|
-
seeked: Event;
|
|
132
|
-
seeking: Event;
|
|
133
|
-
stalled: Event;
|
|
134
|
-
suspend: Event;
|
|
135
|
-
timeupdate: Event;
|
|
136
|
-
volumechange: Event;
|
|
137
|
-
waiting: Event;
|
|
138
|
-
}
|
|
139
|
-
export type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 动画事件
|
|
143
|
-
*/
|
|
144
|
-
export interface DOMUtils_AnimationEvent {
|
|
145
|
-
animationend: AnimationEvent;
|
|
146
|
-
animationiteration: AnimationEvent;
|
|
147
|
-
animationstart: AnimationEvent;
|
|
148
|
-
}
|
|
149
|
-
export type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 过渡事件
|
|
153
|
-
*/
|
|
154
|
-
export interface DOMUtils_TransitionEvent {
|
|
155
|
-
transitionend: TransitionEvent;
|
|
156
|
-
}
|
|
157
|
-
export type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 触摸事件
|
|
161
|
-
*/
|
|
162
|
-
export interface DOMUtils_TouchEvent {
|
|
163
|
-
touchstart: TouchEvent;
|
|
164
|
-
touchmove: TouchEvent;
|
|
165
|
-
touchend: TouchEvent;
|
|
166
|
-
touchcancel: TouchEvent;
|
|
167
|
-
touchenter: TouchEvent;
|
|
168
|
-
touchleave: TouchEvent;
|
|
169
|
-
}
|
|
170
|
-
export type DOMUtils_TouchEventType = keyof DOMUtils_TouchEvent;
|
|
171
|
-
/**
|
|
172
|
-
* 其它事件
|
|
173
|
-
*/
|
|
174
|
-
export interface DOMUtils_OtherEvent {
|
|
175
|
-
message: Event;
|
|
176
|
-
online: Event;
|
|
177
|
-
offline: Event;
|
|
178
|
-
popstate: Event;
|
|
179
|
-
show: Event;
|
|
180
|
-
storage: Event;
|
|
181
|
-
toggle: Event;
|
|
182
|
-
wheel: Event;
|
|
183
|
-
propertychange: Event;
|
|
184
|
-
fullscreenchange: Event;
|
|
185
|
-
DOMContentLoaded: Event;
|
|
186
|
-
}
|
|
187
|
-
export type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* 全部事件
|
|
191
|
-
*/
|
|
192
|
-
export declare type DOMUtils_Event = DOMUtils_MouseEvent &
|
|
193
|
-
DOMUtils_KeyboardEvent &
|
|
194
|
-
DOMUtils_Frame_Object_Event &
|
|
195
|
-
DOMUtils_FormEvent &
|
|
196
|
-
DOMUtils_ClipboardEvent &
|
|
197
|
-
DOMUtils_PrintEvent &
|
|
198
|
-
DOMUtils_DragEvent &
|
|
199
|
-
DOMUtils_MediaEvent &
|
|
200
|
-
DOMUtils_AnimationEvent &
|
|
201
|
-
DOMUtils_TransitionEvent &
|
|
202
|
-
DOMUtils_TouchEvent &
|
|
203
|
-
DOMUtils_OtherEvent;
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* 事件类型
|
|
207
|
-
*/
|
|
208
|
-
export declare type DOMUtils_EventType = keyof DOMUtils_Event;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 元素上的events属性
|
|
212
|
-
*/
|
|
213
|
-
export declare interface DOMUtilsEventListenerOptionsAttribute {
|
|
214
|
-
/**
|
|
215
|
-
* 自定义的ownCallBack
|
|
216
|
-
*/
|
|
217
|
-
callback: () => void;
|
|
218
|
-
/**
|
|
219
|
-
* 属性配置
|
|
220
|
-
*/
|
|
221
|
-
option: AddEventListenerOptions;
|
|
222
|
-
/**
|
|
223
|
-
* 用户添加的事件
|
|
224
|
-
*/
|
|
225
|
-
originCallBack: () => void;
|
|
226
|
-
/**
|
|
227
|
-
* 子元素选择器
|
|
228
|
-
*/
|
|
229
|
-
selector?: string;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export declare type DOMUtilsElementEventType =
|
|
233
|
-
| HTMLElement
|
|
234
|
-
| string
|
|
235
|
-
| NodeList
|
|
236
|
-
| (HTMLElement | Window | Document | Element | typeof globalThis)[]
|
|
237
|
-
| Window
|
|
238
|
-
| Document
|
|
239
|
-
| Element
|
|
240
|
-
| null
|
|
241
|
-
| typeof globalThis
|
|
242
|
-
| ShadowRoot
|
|
243
|
-
| EventTarget
|
|
244
|
-
| ChildNode
|
|
245
|
-
| Node;
|
|
12
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
13
|
+
import { WindowApi } from "./WindowApi";
|
|
246
14
|
|
|
247
15
|
export class DOMUtilsEvent {
|
|
248
|
-
windowApi:
|
|
249
|
-
constructor(windowApiOption?:
|
|
16
|
+
windowApi: typeof WindowApi.prototype;
|
|
17
|
+
constructor(windowApiOption?: WindowApiOption) {
|
|
250
18
|
this.windowApi = new WindowApi(windowApiOption);
|
|
251
19
|
}
|
|
252
20
|
/**
|
|
@@ -967,9 +735,7 @@ export class DOMUtilsEvent {
|
|
|
967
735
|
) {
|
|
968
736
|
let DOMUtilsContext = this;
|
|
969
737
|
if (typeof element === "string") {
|
|
970
|
-
element = DOMUtilsContext.
|
|
971
|
-
element
|
|
972
|
-
) as HTMLElement;
|
|
738
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
973
739
|
}
|
|
974
740
|
if (element == null) {
|
|
975
741
|
return;
|
|
@@ -1086,9 +852,7 @@ export class DOMUtilsEvent {
|
|
|
1086
852
|
) {
|
|
1087
853
|
let DOMUtilsContext = this;
|
|
1088
854
|
if (typeof element === "string") {
|
|
1089
|
-
element = DOMUtilsContext.
|
|
1090
|
-
element
|
|
1091
|
-
) as HTMLElement;
|
|
855
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
1092
856
|
}
|
|
1093
857
|
if (element == null) {
|
|
1094
858
|
return;
|
package/src/WindowApi.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* 配置类型
|
|
3
|
-
*/
|
|
4
|
-
export type UtilsWindowApiOption = {
|
|
5
|
-
document: Document;
|
|
6
|
-
window: Window & typeof globalThis;
|
|
7
|
-
globalThis: typeof globalThis | Window;
|
|
8
|
-
self: Window & typeof globalThis;
|
|
9
|
-
top: Window;
|
|
10
|
-
};
|
|
1
|
+
import type { WindowApiOption } from "./types/WindowApi";
|
|
11
2
|
|
|
12
3
|
export class WindowApi {
|
|
13
4
|
/** 默认的配置 */
|
|
14
|
-
private defaultApi:
|
|
5
|
+
private defaultApi: Required<WindowApiOption> = {
|
|
15
6
|
document: document,
|
|
16
7
|
window: window,
|
|
17
8
|
globalThis: globalThis,
|
|
@@ -19,11 +10,20 @@ export class WindowApi {
|
|
|
19
10
|
top: top!,
|
|
20
11
|
};
|
|
21
12
|
/** 使用的配置 */
|
|
22
|
-
private api:
|
|
23
|
-
constructor(option?:
|
|
13
|
+
private api: Required<WindowApiOption>;
|
|
14
|
+
constructor(option?: WindowApiOption) {
|
|
15
|
+
if (option) {
|
|
16
|
+
if (option.globalThis == null) {
|
|
17
|
+
option.globalThis = option.window;
|
|
18
|
+
}
|
|
19
|
+
if (option.self == null) {
|
|
20
|
+
option.self = option.window;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
24
23
|
if (!option) {
|
|
25
24
|
option = Object.assign({}, this.defaultApi);
|
|
26
25
|
}
|
|
26
|
+
// @ts-ignore
|
|
27
27
|
this.api = Object.assign({}, option);
|
|
28
28
|
}
|
|
29
29
|
get document() {
|