@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/dist/index.amd.js
CHANGED
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
define((function () { 'use strict';
|
|
2
2
|
|
|
3
|
+
class WindowApi {
|
|
4
|
+
/** 默认的配置 */
|
|
5
|
+
defaultApi = {
|
|
6
|
+
document: document,
|
|
7
|
+
window: window,
|
|
8
|
+
globalThis: globalThis,
|
|
9
|
+
self: self,
|
|
10
|
+
top: top,
|
|
11
|
+
};
|
|
12
|
+
/** 使用的配置 */
|
|
13
|
+
api;
|
|
14
|
+
constructor(option) {
|
|
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
|
+
}
|
|
23
|
+
if (!option) {
|
|
24
|
+
option = Object.assign({}, this.defaultApi);
|
|
25
|
+
}
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
this.api = Object.assign({}, option);
|
|
28
|
+
}
|
|
29
|
+
get document() {
|
|
30
|
+
return this.api.document;
|
|
31
|
+
}
|
|
32
|
+
get window() {
|
|
33
|
+
return this.api.window;
|
|
34
|
+
}
|
|
35
|
+
get globalThis() {
|
|
36
|
+
return this.api.globalThis;
|
|
37
|
+
}
|
|
38
|
+
get self() {
|
|
39
|
+
return this.api.self;
|
|
40
|
+
}
|
|
41
|
+
get top() {
|
|
42
|
+
return this.api.top;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
3
46
|
/** 通用工具类 */
|
|
4
47
|
const DOMUtilsCommonUtils = {
|
|
5
|
-
windowApi: {
|
|
6
|
-
window: window,
|
|
48
|
+
windowApi: new WindowApi({
|
|
7
49
|
document: document,
|
|
8
|
-
|
|
50
|
+
window: window,
|
|
51
|
+
top: top,
|
|
52
|
+
}),
|
|
9
53
|
/**
|
|
10
54
|
* 判断元素是否已显示或已连接
|
|
11
55
|
* @param element
|
|
@@ -111,7 +155,7 @@ define((function () { 'use strict';
|
|
|
111
155
|
|
|
112
156
|
/* 数据 */
|
|
113
157
|
const DOMUtilsData = {
|
|
114
|
-
/** .on
|
|
158
|
+
/** .on添加在元素存储的事件 */
|
|
115
159
|
SymbolEvents: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
|
|
116
160
|
};
|
|
117
161
|
|
|
@@ -121,40 +165,6 @@ define((function () { 'use strict';
|
|
|
121
165
|
},
|
|
122
166
|
};
|
|
123
167
|
|
|
124
|
-
class WindowApi {
|
|
125
|
-
/** 默认的配置 */
|
|
126
|
-
defaultApi = {
|
|
127
|
-
document: document,
|
|
128
|
-
window: window,
|
|
129
|
-
globalThis: globalThis,
|
|
130
|
-
self: self,
|
|
131
|
-
top: top,
|
|
132
|
-
};
|
|
133
|
-
/** 使用的配置 */
|
|
134
|
-
api;
|
|
135
|
-
constructor(option) {
|
|
136
|
-
if (!option) {
|
|
137
|
-
option = Object.assign({}, this.defaultApi);
|
|
138
|
-
}
|
|
139
|
-
this.api = Object.assign({}, option);
|
|
140
|
-
}
|
|
141
|
-
get document() {
|
|
142
|
-
return this.api.document;
|
|
143
|
-
}
|
|
144
|
-
get window() {
|
|
145
|
-
return this.api.window;
|
|
146
|
-
}
|
|
147
|
-
get globalThis() {
|
|
148
|
-
return this.api.globalThis;
|
|
149
|
-
}
|
|
150
|
-
get self() {
|
|
151
|
-
return this.api.self;
|
|
152
|
-
}
|
|
153
|
-
get top() {
|
|
154
|
-
return this.api.top;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
168
|
class DOMUtilsEvent {
|
|
159
169
|
windowApi;
|
|
160
170
|
constructor(windowApiOption) {
|
|
@@ -531,7 +541,7 @@ define((function () { 'use strict';
|
|
|
531
541
|
trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
|
|
532
542
|
let DOMUtilsContext = this;
|
|
533
543
|
if (typeof element === "string") {
|
|
534
|
-
element = DOMUtilsContext.
|
|
544
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
535
545
|
}
|
|
536
546
|
if (element == null) {
|
|
537
547
|
return;
|
|
@@ -631,7 +641,7 @@ define((function () { 'use strict';
|
|
|
631
641
|
blur(element, handler, details, useDispatchToTriggerEvent) {
|
|
632
642
|
let DOMUtilsContext = this;
|
|
633
643
|
if (typeof element === "string") {
|
|
634
|
-
element = DOMUtilsContext.
|
|
644
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
635
645
|
}
|
|
636
646
|
if (element == null) {
|
|
637
647
|
return;
|
|
@@ -967,7 +977,7 @@ define((function () { 'use strict';
|
|
|
967
977
|
super(option);
|
|
968
978
|
}
|
|
969
979
|
/** 版本号 */
|
|
970
|
-
version = "2024.
|
|
980
|
+
version = "2024.11.6";
|
|
971
981
|
attr(element, attrName, attrValue) {
|
|
972
982
|
let DOMUtilsContext = this;
|
|
973
983
|
if (typeof element === "string") {
|
|
@@ -1464,6 +1474,41 @@ define((function () { 'use strict';
|
|
|
1464
1474
|
element.classList.add(itemClassName);
|
|
1465
1475
|
});
|
|
1466
1476
|
}
|
|
1477
|
+
/**
|
|
1478
|
+
* 判断元素是否存在className
|
|
1479
|
+
* @param element
|
|
1480
|
+
* @param className
|
|
1481
|
+
*/
|
|
1482
|
+
hasClass(element, className) {
|
|
1483
|
+
let DOMUtilsContext = this;
|
|
1484
|
+
if (typeof element === "string") {
|
|
1485
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
1486
|
+
}
|
|
1487
|
+
if (element == null) {
|
|
1488
|
+
return false;
|
|
1489
|
+
}
|
|
1490
|
+
if (isNodeList(element)) {
|
|
1491
|
+
let flag = true;
|
|
1492
|
+
for (let index = 0; index < element.length; index++) {
|
|
1493
|
+
const $ele = element[index];
|
|
1494
|
+
flag = flag && DOMUtilsContext.hasClass($ele, className);
|
|
1495
|
+
}
|
|
1496
|
+
return flag;
|
|
1497
|
+
}
|
|
1498
|
+
if (!element?.classList) {
|
|
1499
|
+
return false;
|
|
1500
|
+
}
|
|
1501
|
+
if (!Array.isArray(className)) {
|
|
1502
|
+
className = className.split(" ");
|
|
1503
|
+
}
|
|
1504
|
+
for (let index = 0; index < className.length; index++) {
|
|
1505
|
+
const item = className[index].trim();
|
|
1506
|
+
if (!element.classList.contains(item)) {
|
|
1507
|
+
return false;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return true;
|
|
1511
|
+
}
|
|
1467
1512
|
/**
|
|
1468
1513
|
* 函数在元素内部末尾添加子元素或HTML字符串
|
|
1469
1514
|
* @param element 目标元素
|
|
@@ -1686,7 +1731,7 @@ define((function () { 'use strict';
|
|
|
1686
1731
|
offset(element) {
|
|
1687
1732
|
let DOMUtilsContext = this;
|
|
1688
1733
|
if (typeof element === "string") {
|
|
1689
|
-
element = DOMUtilsContext.
|
|
1734
|
+
element = DOMUtilsContext.selector(element);
|
|
1690
1735
|
}
|
|
1691
1736
|
if (element == null) {
|
|
1692
1737
|
return;
|
|
@@ -1702,8 +1747,7 @@ define((function () { 'use strict';
|
|
|
1702
1747
|
width(element, isShow = false) {
|
|
1703
1748
|
let DOMUtilsContext = this;
|
|
1704
1749
|
if (typeof element === "string") {
|
|
1705
|
-
element =
|
|
1706
|
-
DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1750
|
+
element = DOMUtilsContext.selector(element);
|
|
1707
1751
|
}
|
|
1708
1752
|
if (element == null) {
|
|
1709
1753
|
return;
|
|
@@ -1757,7 +1801,7 @@ define((function () { 'use strict';
|
|
|
1757
1801
|
.clientHeight;
|
|
1758
1802
|
}
|
|
1759
1803
|
if (typeof element === "string") {
|
|
1760
|
-
element = DOMUtilsContext.
|
|
1804
|
+
element = DOMUtilsContext.selector(element);
|
|
1761
1805
|
}
|
|
1762
1806
|
if (element == null) {
|
|
1763
1807
|
// @ts-ignore
|
|
@@ -1807,7 +1851,7 @@ define((function () { 'use strict';
|
|
|
1807
1851
|
return DOMUtilsContext.windowApi.window.innerWidth;
|
|
1808
1852
|
}
|
|
1809
1853
|
if (typeof element === "string") {
|
|
1810
|
-
element = DOMUtilsContext.
|
|
1854
|
+
element = DOMUtilsContext.selector(element);
|
|
1811
1855
|
}
|
|
1812
1856
|
if (element == null) {
|
|
1813
1857
|
// @ts-ignore
|
|
@@ -1833,7 +1877,7 @@ define((function () { 'use strict';
|
|
|
1833
1877
|
return DOMUtilsContext.windowApi.window.innerHeight;
|
|
1834
1878
|
}
|
|
1835
1879
|
if (typeof element === "string") {
|
|
1836
|
-
element = DOMUtilsContext.
|
|
1880
|
+
element = DOMUtilsContext.selector(element);
|
|
1837
1881
|
}
|
|
1838
1882
|
if (element == null) {
|
|
1839
1883
|
// @ts-ignore
|
|
@@ -1956,7 +2000,7 @@ define((function () { 'use strict';
|
|
|
1956
2000
|
prev(element) {
|
|
1957
2001
|
let DOMUtilsContext = this;
|
|
1958
2002
|
if (typeof element === "string") {
|
|
1959
|
-
element = DOMUtilsContext.
|
|
2003
|
+
element = DOMUtilsContext.selector(element);
|
|
1960
2004
|
}
|
|
1961
2005
|
if (element == null) {
|
|
1962
2006
|
return;
|
|
@@ -1966,7 +2010,7 @@ define((function () { 'use strict';
|
|
|
1966
2010
|
next(element) {
|
|
1967
2011
|
let DOMUtilsContext = this;
|
|
1968
2012
|
if (typeof element === "string") {
|
|
1969
|
-
element = DOMUtilsContext.
|
|
2013
|
+
element = DOMUtilsContext.selector(element);
|
|
1970
2014
|
}
|
|
1971
2015
|
if (element == null) {
|
|
1972
2016
|
return;
|
|
@@ -1989,7 +2033,7 @@ define((function () { 'use strict';
|
|
|
1989
2033
|
siblings(element) {
|
|
1990
2034
|
let DOMUtilsContext = this;
|
|
1991
2035
|
if (typeof element === "string") {
|
|
1992
|
-
element = DOMUtilsContext.
|
|
2036
|
+
element = DOMUtilsContext.selector(element);
|
|
1993
2037
|
}
|
|
1994
2038
|
if (element == null) {
|
|
1995
2039
|
return;
|
|
@@ -2010,16 +2054,15 @@ define((function () { 'use strict';
|
|
|
2010
2054
|
parent(element) {
|
|
2011
2055
|
let DOMUtilsContext = this;
|
|
2012
2056
|
if (typeof element === "string") {
|
|
2013
|
-
element = DOMUtilsContext.
|
|
2057
|
+
element = DOMUtilsContext.selector(element);
|
|
2014
2058
|
}
|
|
2015
2059
|
if (element == null) {
|
|
2016
2060
|
return;
|
|
2017
2061
|
}
|
|
2018
|
-
if (element
|
|
2019
|
-
element = element;
|
|
2062
|
+
if (isNodeList(element)) {
|
|
2020
2063
|
let resultArray = [];
|
|
2021
|
-
element.forEach((
|
|
2022
|
-
resultArray.push(DOMUtilsContext.parent(
|
|
2064
|
+
element.forEach(($ele) => {
|
|
2065
|
+
resultArray.push(DOMUtilsContext.parent($ele));
|
|
2023
2066
|
});
|
|
2024
2067
|
return resultArray;
|
|
2025
2068
|
}
|