@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.
@@ -3,12 +3,56 @@ System.register('DOMUtils', [], (function (exports) {
3
3
  return {
4
4
  execute: (function () {
5
5
 
6
+ class WindowApi {
7
+ /** 默认的配置 */
8
+ defaultApi = {
9
+ document: document,
10
+ window: window,
11
+ globalThis: globalThis,
12
+ self: self,
13
+ top: top,
14
+ };
15
+ /** 使用的配置 */
16
+ api;
17
+ constructor(option) {
18
+ if (option) {
19
+ if (option.globalThis == null) {
20
+ option.globalThis = option.window;
21
+ }
22
+ if (option.self == null) {
23
+ option.self = option.window;
24
+ }
25
+ }
26
+ if (!option) {
27
+ option = Object.assign({}, this.defaultApi);
28
+ }
29
+ // @ts-ignore
30
+ this.api = Object.assign({}, option);
31
+ }
32
+ get document() {
33
+ return this.api.document;
34
+ }
35
+ get window() {
36
+ return this.api.window;
37
+ }
38
+ get globalThis() {
39
+ return this.api.globalThis;
40
+ }
41
+ get self() {
42
+ return this.api.self;
43
+ }
44
+ get top() {
45
+ return this.api.top;
46
+ }
47
+ }
48
+
6
49
  /** 通用工具类 */
7
50
  const DOMUtilsCommonUtils = {
8
- windowApi: {
9
- window: window,
51
+ windowApi: new WindowApi({
10
52
  document: document,
11
- },
53
+ window: window,
54
+ top: top,
55
+ }),
12
56
  /**
13
57
  * 判断元素是否已显示或已连接
14
58
  * @param element
@@ -114,7 +158,7 @@ System.register('DOMUtils', [], (function (exports) {
114
158
 
115
159
  /* 数据 */
116
160
  const DOMUtilsData = {
117
- /** .on绑定的事件 */
161
+ /** .on添加在元素存储的事件 */
118
162
  SymbolEvents: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
119
163
  };
120
164
 
@@ -124,40 +168,6 @@ System.register('DOMUtils', [], (function (exports) {
124
168
  },
125
169
  };
126
170
 
127
- class WindowApi {
128
- /** 默认的配置 */
129
- defaultApi = {
130
- document: document,
131
- window: window,
132
- globalThis: globalThis,
133
- self: self,
134
- top: top,
135
- };
136
- /** 使用的配置 */
137
- api;
138
- constructor(option) {
139
- if (!option) {
140
- option = Object.assign({}, this.defaultApi);
141
- }
142
- this.api = Object.assign({}, option);
143
- }
144
- get document() {
145
- return this.api.document;
146
- }
147
- get window() {
148
- return this.api.window;
149
- }
150
- get globalThis() {
151
- return this.api.globalThis;
152
- }
153
- get self() {
154
- return this.api.self;
155
- }
156
- get top() {
157
- return this.api.top;
158
- }
159
- }
160
-
161
171
  class DOMUtilsEvent {
162
172
  windowApi;
163
173
  constructor(windowApiOption) {
@@ -534,7 +544,7 @@ System.register('DOMUtils', [], (function (exports) {
534
544
  trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
535
545
  let DOMUtilsContext = this;
536
546
  if (typeof element === "string") {
537
- element = DOMUtilsContext.windowApi.document.querySelector(element);
547
+ element = DOMUtilsContext.selectorAll(element);
538
548
  }
539
549
  if (element == null) {
540
550
  return;
@@ -634,7 +644,7 @@ System.register('DOMUtils', [], (function (exports) {
634
644
  blur(element, handler, details, useDispatchToTriggerEvent) {
635
645
  let DOMUtilsContext = this;
636
646
  if (typeof element === "string") {
637
- element = DOMUtilsContext.windowApi.document.querySelector(element);
647
+ element = DOMUtilsContext.selectorAll(element);
638
648
  }
639
649
  if (element == null) {
640
650
  return;
@@ -970,7 +980,7 @@ System.register('DOMUtils', [], (function (exports) {
970
980
  super(option);
971
981
  }
972
982
  /** 版本号 */
973
- version = "2024.10.23";
983
+ version = "2024.11.6";
974
984
  attr(element, attrName, attrValue) {
975
985
  let DOMUtilsContext = this;
976
986
  if (typeof element === "string") {
@@ -1467,6 +1477,41 @@ System.register('DOMUtils', [], (function (exports) {
1467
1477
  element.classList.add(itemClassName);
1468
1478
  });
1469
1479
  }
1480
+ /**
1481
+ * 判断元素是否存在className
1482
+ * @param element
1483
+ * @param className
1484
+ */
1485
+ hasClass(element, className) {
1486
+ let DOMUtilsContext = this;
1487
+ if (typeof element === "string") {
1488
+ element = DOMUtilsContext.selectorAll(element);
1489
+ }
1490
+ if (element == null) {
1491
+ return false;
1492
+ }
1493
+ if (isNodeList(element)) {
1494
+ let flag = true;
1495
+ for (let index = 0; index < element.length; index++) {
1496
+ const $ele = element[index];
1497
+ flag = flag && DOMUtilsContext.hasClass($ele, className);
1498
+ }
1499
+ return flag;
1500
+ }
1501
+ if (!element?.classList) {
1502
+ return false;
1503
+ }
1504
+ if (!Array.isArray(className)) {
1505
+ className = className.split(" ");
1506
+ }
1507
+ for (let index = 0; index < className.length; index++) {
1508
+ const item = className[index].trim();
1509
+ if (!element.classList.contains(item)) {
1510
+ return false;
1511
+ }
1512
+ }
1513
+ return true;
1514
+ }
1470
1515
  /**
1471
1516
  * 函数在元素内部末尾添加子元素或HTML字符串
1472
1517
  * @param element 目标元素
@@ -1689,7 +1734,7 @@ System.register('DOMUtils', [], (function (exports) {
1689
1734
  offset(element) {
1690
1735
  let DOMUtilsContext = this;
1691
1736
  if (typeof element === "string") {
1692
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1737
+ element = DOMUtilsContext.selector(element);
1693
1738
  }
1694
1739
  if (element == null) {
1695
1740
  return;
@@ -1705,8 +1750,7 @@ System.register('DOMUtils', [], (function (exports) {
1705
1750
  width(element, isShow = false) {
1706
1751
  let DOMUtilsContext = this;
1707
1752
  if (typeof element === "string") {
1708
- element =
1709
- DOMUtilsContext.windowApi.document.querySelector(element);
1753
+ element = DOMUtilsContext.selector(element);
1710
1754
  }
1711
1755
  if (element == null) {
1712
1756
  return;
@@ -1760,7 +1804,7 @@ System.register('DOMUtils', [], (function (exports) {
1760
1804
  .clientHeight;
1761
1805
  }
1762
1806
  if (typeof element === "string") {
1763
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1807
+ element = DOMUtilsContext.selector(element);
1764
1808
  }
1765
1809
  if (element == null) {
1766
1810
  // @ts-ignore
@@ -1810,7 +1854,7 @@ System.register('DOMUtils', [], (function (exports) {
1810
1854
  return DOMUtilsContext.windowApi.window.innerWidth;
1811
1855
  }
1812
1856
  if (typeof element === "string") {
1813
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1857
+ element = DOMUtilsContext.selector(element);
1814
1858
  }
1815
1859
  if (element == null) {
1816
1860
  // @ts-ignore
@@ -1836,7 +1880,7 @@ System.register('DOMUtils', [], (function (exports) {
1836
1880
  return DOMUtilsContext.windowApi.window.innerHeight;
1837
1881
  }
1838
1882
  if (typeof element === "string") {
1839
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1883
+ element = DOMUtilsContext.selector(element);
1840
1884
  }
1841
1885
  if (element == null) {
1842
1886
  // @ts-ignore
@@ -1959,7 +2003,7 @@ System.register('DOMUtils', [], (function (exports) {
1959
2003
  prev(element) {
1960
2004
  let DOMUtilsContext = this;
1961
2005
  if (typeof element === "string") {
1962
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2006
+ element = DOMUtilsContext.selector(element);
1963
2007
  }
1964
2008
  if (element == null) {
1965
2009
  return;
@@ -1969,7 +2013,7 @@ System.register('DOMUtils', [], (function (exports) {
1969
2013
  next(element) {
1970
2014
  let DOMUtilsContext = this;
1971
2015
  if (typeof element === "string") {
1972
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2016
+ element = DOMUtilsContext.selector(element);
1973
2017
  }
1974
2018
  if (element == null) {
1975
2019
  return;
@@ -1992,7 +2036,7 @@ System.register('DOMUtils', [], (function (exports) {
1992
2036
  siblings(element) {
1993
2037
  let DOMUtilsContext = this;
1994
2038
  if (typeof element === "string") {
1995
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2039
+ element = DOMUtilsContext.selector(element);
1996
2040
  }
1997
2041
  if (element == null) {
1998
2042
  return;
@@ -2013,16 +2057,15 @@ System.register('DOMUtils', [], (function (exports) {
2013
2057
  parent(element) {
2014
2058
  let DOMUtilsContext = this;
2015
2059
  if (typeof element === "string") {
2016
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2060
+ element = DOMUtilsContext.selector(element);
2017
2061
  }
2018
2062
  if (element == null) {
2019
2063
  return;
2020
2064
  }
2021
- if (element instanceof NodeList || element instanceof Array) {
2022
- element = element;
2065
+ if (isNodeList(element)) {
2023
2066
  let resultArray = [];
2024
- element.forEach((eleItem) => {
2025
- resultArray.push(DOMUtilsContext.parent(eleItem));
2067
+ element.forEach(($ele) => {
2068
+ resultArray.push(DOMUtilsContext.parent($ele));
2026
2069
  });
2027
2070
  return resultArray;
2028
2071
  }