@whitesev/domutils 1.5.10 → 1.6.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/src/DOMUtils.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { DOMUtilsCommonUtils } from "./DOMUtilsCommonUtils";
2
2
  import { DOMUtilsEvent } from "./DOMUtilsEvent";
3
3
  import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
4
- import {
5
- ParseHTMLReturnType,
6
- type DOMUtilsTargetElementType,
7
- } from "./types/global";
4
+ import { ParseHTMLReturnType, type DOMUtilsTargetElementType } from "./types/global";
8
5
  import type { WindowApiOption } from "./types/WindowApi";
9
6
 
10
7
  class DOMUtils extends DOMUtilsEvent {
@@ -12,7 +9,7 @@ class DOMUtils extends DOMUtilsEvent {
12
9
  super(option);
13
10
  }
14
11
  /** 版本号 */
15
- version = "2025.6.7";
12
+ version = "2025.8.9";
16
13
  /**
17
14
  * 获取元素的属性值
18
15
  * @param element 目标元素
@@ -34,11 +31,7 @@ class DOMUtils extends DOMUtilsEvent {
34
31
  * DOMUtils.attr(document.querySelector("a.xx"),"href","abcd");
35
32
  * DOMUtils.attr("a.xx","href","abcd");
36
33
  */
37
- attr(
38
- element: DOMUtilsTargetElementType,
39
- attrName: string,
40
- attrValue: string | boolean | number
41
- ): void;
34
+ attr(element: DOMUtilsTargetElementType, attrName: string, attrValue: string | boolean | number): void;
42
35
  attr(element: DOMUtilsTargetElementType, attrName: string, attrValue?: any) {
43
36
  let DOMUtilsContext = this;
44
37
  if (typeof element === "string") {
@@ -50,11 +43,7 @@ class DOMUtils extends DOMUtilsEvent {
50
43
  if (DOMUtilsCommonUtils.isNodeList(element)) {
51
44
  if (attrValue == null) {
52
45
  // 获取属性
53
- return DOMUtilsContext.attr(
54
- element[0] as HTMLElement,
55
- attrName,
56
- attrValue
57
- );
46
+ return DOMUtilsContext.attr(element[0] as HTMLElement, attrName, attrValue);
58
47
  } else {
59
48
  // 设置属性
60
49
  element.forEach(($ele) => {
@@ -199,10 +188,7 @@ class DOMUtils extends DOMUtilsEvent {
199
188
  element: DOMUtilsTargetElementType,
200
189
  property:
201
190
  | {
202
- [P in keyof Omit<
203
- CSSStyleDeclaration,
204
- "zIndex"
205
- >]?: CSSStyleDeclaration[P];
191
+ [P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: CSSStyleDeclaration[P];
206
192
  }
207
193
  | {
208
194
  "z-index": string | number;
@@ -217,10 +203,7 @@ class DOMUtils extends DOMUtilsEvent {
217
203
  | keyof Omit<CSSStyleDeclaration, "zIndex">
218
204
  | string
219
205
  | {
220
- [P in keyof Omit<CSSStyleDeclaration, "zIndex">]?:
221
- | string
222
- | number
223
- | CSSStyleDeclaration[P];
206
+ [P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: string | number | CSSStyleDeclaration[P];
224
207
  },
225
208
  value?: string | number
226
209
  ) {
@@ -229,15 +212,7 @@ class DOMUtils extends DOMUtilsEvent {
229
212
  * 把纯数字没有px的加上
230
213
  */
231
214
  function handlePixe(propertyName: string, propertyValue: string | number) {
232
- let allowAddPixe = [
233
- "width",
234
- "height",
235
- "top",
236
- "left",
237
- "right",
238
- "bottom",
239
- "font-size",
240
- ];
215
+ let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
241
216
  if (typeof propertyValue === "number") {
242
217
  propertyValue = propertyValue.toString();
243
218
  }
@@ -278,14 +253,8 @@ class DOMUtils extends DOMUtilsEvent {
278
253
  }
279
254
  return;
280
255
  }
281
- let setStyleProperty = (
282
- propertyName: string,
283
- propertyValue: string | number
284
- ) => {
285
- if (
286
- typeof propertyValue === "string" &&
287
- propertyValue.trim().endsWith("!important")
288
- ) {
256
+ let setStyleProperty = (propertyName: string, propertyValue: string | number) => {
257
+ if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
289
258
  propertyValue = propertyValue
290
259
  .trim()
291
260
  .replace(/!important$/gi, "")
@@ -298,9 +267,7 @@ class DOMUtils extends DOMUtilsEvent {
298
267
  };
299
268
  if (typeof property === "string") {
300
269
  if (value == null) {
301
- return DOMUtilsContext.windowApi.globalThis
302
- .getComputedStyle(element)
303
- .getPropertyValue(property);
270
+ return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
304
271
  } else {
305
272
  setStyleProperty(property, value);
306
273
  }
@@ -337,10 +304,10 @@ class DOMUtils extends DOMUtilsEvent {
337
304
  * DOMUtils.text("a.xx",document.querySelector("b"))
338
305
  * */
339
306
  text(
340
- element: DOMUtilsTargetElementType,
307
+ element: DOMUtilsTargetElementType | DocumentFragment,
341
308
  text: string | HTMLElement | Element | number
342
309
  ): void;
343
- text(element: DOMUtilsTargetElementType, text?: any) {
310
+ text(element: DOMUtilsTargetElementType | DocumentFragment, text?: any) {
344
311
  let DOMUtilsContext = this;
345
312
  if (typeof element === "string") {
346
313
  element = DOMUtilsContext.selectorAll(element);
@@ -361,7 +328,7 @@ class DOMUtils extends DOMUtilsEvent {
361
328
  return;
362
329
  }
363
330
  if (text == null) {
364
- return element.textContent || element.innerText;
331
+ return element.textContent || (<HTMLElement>element).innerText;
365
332
  } else {
366
333
  if (text instanceof Node) {
367
334
  text = text.textContent || (text as HTMLElement).innerText;
@@ -385,10 +352,7 @@ class DOMUtils extends DOMUtilsEvent {
385
352
  * DOMUtils.html("a.xx","<b>abcd</b>")
386
353
  * DOMUtils.html("a.xx",document.querySelector("b"))
387
354
  * */
388
- html(
389
- element: DOMUtilsTargetElementType,
390
- html: string | HTMLElement | Element | number
391
- ): void;
355
+ html(element: DOMUtilsTargetElementType, html: string | HTMLElement | Element | number): void;
392
356
  /**
393
357
  * 获取元素的HTML内容
394
358
  * @param element 目标元素
@@ -454,16 +418,9 @@ class DOMUtils extends DOMUtilsEvent {
454
418
  recovery();
455
419
  return transformInfo;
456
420
  }
457
- let elementTransform =
458
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
459
- if (
460
- elementTransform != null &&
461
- elementTransform !== "none" &&
462
- elementTransform !== ""
463
- ) {
464
- let elementTransformSplit = elementTransform
465
- .match(/\((.+)\)/)?.[1]
466
- .split(",");
421
+ let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
422
+ if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
423
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
467
424
  if (elementTransformSplit) {
468
425
  transform_left = Math.abs(parseInt(elementTransformSplit[4]));
469
426
  transform_top = Math.abs(parseInt(elementTransformSplit[5]));
@@ -562,20 +519,14 @@ class DOMUtils extends DOMUtilsEvent {
562
519
  }
563
520
  if (value == null) {
564
521
  // 获取
565
- if (
566
- element.localName === "input" &&
567
- (element.type === "checkbox" || element.type === "radio")
568
- ) {
522
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
569
523
  return (element as HTMLInputElement).checked;
570
524
  } else {
571
525
  return element.value;
572
526
  }
573
527
  } else {
574
528
  // 设置
575
- if (
576
- element.localName === "input" &&
577
- (element.type === "checkbox" || element.type === "radio")
578
- ) {
529
+ if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
579
530
  (element as HTMLInputElement).checked = !!value;
580
531
  } else {
581
532
  element.value = value as string;
@@ -594,7 +545,7 @@ class DOMUtils extends DOMUtilsEvent {
594
545
  * DOMUtils.val("a.xx","data-value")
595
546
  * > undefined
596
547
  * */
597
- prop<T extends any>(element: DOMUtilsTargetElementType, propName: string): T;
548
+ prop<T extends any>(element: DOMUtilsTargetElementType | DocumentFragment, propName: string): T;
598
549
  /**
599
550
  * 设置元素的属性值
600
551
  * @param element 目标元素
@@ -606,11 +557,11 @@ class DOMUtils extends DOMUtilsEvent {
606
557
  * DOMUtils.val("a.xx","data-value",1)
607
558
  * */
608
559
  prop<T extends any>(
609
- element: DOMUtilsTargetElementType,
560
+ element: DOMUtilsTargetElementType | DocumentFragment,
610
561
  propName: string,
611
562
  propValue: T
612
563
  ): void;
613
- prop(element: DOMUtilsTargetElementType, propName: string, propValue?: any) {
564
+ prop(element: DOMUtilsTargetElementType | DocumentFragment, propName: string, propValue?: any) {
614
565
  let DOMUtilsContext = this;
615
566
  if (typeof element === "string") {
616
567
  element = DOMUtilsContext.selectorAll(element);
@@ -675,10 +626,7 @@ class DOMUtils extends DOMUtilsEvent {
675
626
  * DOMUtils.removeClass(document.querySelector("a.xx"),"xx")
676
627
  * DOMUtils.removeClass("a.xx","xx")
677
628
  */
678
- removeClass(
679
- element: DOMUtilsTargetElementType,
680
- className?: string | string[] | undefined | null
681
- ) {
629
+ removeClass(element: DOMUtilsTargetElementType, className?: string | string[] | undefined | null) {
682
630
  let DOMUtilsContext = this;
683
631
  if (typeof element === "string") {
684
632
  element = DOMUtilsContext.selectorAll(element);
@@ -714,7 +662,7 @@ class DOMUtils extends DOMUtilsEvent {
714
662
  * DOMUtils.removeProp(document.querySelector("a.xx"),"href")
715
663
  * DOMUtils.removeProp("a.xx","href")
716
664
  * */
717
- removeProp(element: DOMUtilsTargetElementType, propName: string) {
665
+ removeProp(element: DOMUtilsTargetElementType | DocumentFragment, propName: string) {
718
666
  let DOMUtilsContext = this;
719
667
  if (typeof element === "string") {
720
668
  element = DOMUtilsContext.selectorAll(element);
@@ -740,10 +688,7 @@ class DOMUtils extends DOMUtilsEvent {
740
688
  * DOMUtils.replaceWith(document.querySelector("a.xx"),document.querySelector("b.xx"))
741
689
  * DOMUtils.replaceWith("a.xx",'<b class="xx"></b>')
742
690
  */
743
- replaceWith(
744
- element: DOMUtilsTargetElementType,
745
- newElement: HTMLElement | string | Node
746
- ) {
691
+ replaceWith(element: DOMUtilsTargetElementType, newElement: HTMLElement | string | Node) {
747
692
  let DOMUtilsContext = this;
748
693
  if (typeof element === "string") {
749
694
  element = DOMUtilsContext.selectorAll(element);
@@ -802,10 +747,7 @@ class DOMUtils extends DOMUtilsEvent {
802
747
  * @param element
803
748
  * @param className
804
749
  */
805
- hasClass(
806
- element: DOMUtilsTargetElementType,
807
- className: string | string[]
808
- ): boolean {
750
+ hasClass(element: DOMUtilsTargetElementType, className: string | string[]): boolean {
809
751
  let DOMUtilsContext = this;
810
752
  if (typeof element === "string") {
811
753
  element = DOMUtilsContext.selectorAll(element);
@@ -845,12 +787,8 @@ class DOMUtils extends DOMUtilsEvent {
845
787
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
846
788
  * */
847
789
  append(
848
- element: DOMUtilsTargetElementType,
849
- content:
850
- | HTMLElement
851
- | string
852
- | (HTMLElement | string | Element)[]
853
- | NodeList
790
+ element: DOMUtilsTargetElementType | DocumentFragment,
791
+ content: HTMLElement | string | (HTMLElement | string | Element)[] | NodeList
854
792
  ) {
855
793
  let DOMUtilsContext = this;
856
794
  if (typeof element === "string") {
@@ -867,22 +805,26 @@ class DOMUtils extends DOMUtilsEvent {
867
805
  });
868
806
  return;
869
807
  }
870
- function elementAppendChild(ele: HTMLElement, text: HTMLElement | string) {
808
+ function elementAppendChild(ele: HTMLElement | DocumentFragment, text: HTMLElement | string) {
871
809
  if (typeof content === "string") {
872
- ele.insertAdjacentHTML(
873
- "beforeend",
874
- DOMUtilsCommonUtils.getSafeHTML(text as string)
875
- );
810
+ if (ele instanceof DocumentFragment) {
811
+ if (typeof text === "string") {
812
+ text = DOMUtilsContext.parseHTML(text, true, false);
813
+ }
814
+ ele.appendChild(text);
815
+ } else {
816
+ ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text as string));
817
+ }
876
818
  } else {
877
819
  ele.appendChild(text as HTMLElement);
878
820
  }
879
821
  }
880
822
  if (Array.isArray(content) || content instanceof NodeList) {
881
823
  /* 数组 */
882
- let fragment =
883
- DOMUtilsContext.windowApi.document.createDocumentFragment();
824
+ let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
884
825
  content.forEach((ele) => {
885
826
  if (typeof ele === "string") {
827
+ // 转为元素
886
828
  ele = DOMUtilsContext.parseHTML(ele, true, false);
887
829
  }
888
830
  fragment.appendChild(ele);
@@ -901,7 +843,7 @@ class DOMUtils extends DOMUtilsEvent {
901
843
  * DOMUtils.prepend(document.querySelector("a.xx"),document.querySelector("b.xx"))
902
844
  * DOMUtils.prepend("a.xx","'<b class="xx"></b>")
903
845
  * */
904
- prepend(element: DOMUtilsTargetElementType, content: HTMLElement | string) {
846
+ prepend(element: DOMUtilsTargetElementType | DocumentFragment, content: HTMLElement | string) {
905
847
  let DOMUtilsContext = this;
906
848
  if (typeof element === "string") {
907
849
  element = DOMUtilsContext.selectorAll(element);
@@ -917,10 +859,12 @@ class DOMUtils extends DOMUtilsEvent {
917
859
  return;
918
860
  }
919
861
  if (typeof content === "string") {
920
- element.insertAdjacentHTML(
921
- "afterbegin",
922
- DOMUtilsCommonUtils.getSafeHTML(content)
923
- );
862
+ if (element instanceof DocumentFragment) {
863
+ content = DOMUtilsContext.parseHTML(content, true, false);
864
+ element.prepend(content);
865
+ } else {
866
+ element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
867
+ }
924
868
  } else {
925
869
  let $firstChild = element.firstChild;
926
870
  if ($firstChild == null) {
@@ -955,10 +899,7 @@ class DOMUtils extends DOMUtilsEvent {
955
899
  return;
956
900
  }
957
901
  if (typeof content === "string") {
958
- element.insertAdjacentHTML(
959
- "afterend",
960
- DOMUtilsCommonUtils.getSafeHTML(content)
961
- );
902
+ element.insertAdjacentHTML("afterend", DOMUtilsCommonUtils.getSafeHTML(content));
962
903
  } else {
963
904
  let $parent = element.parentElement;
964
905
  let $nextSlibling = element.nextSibling;
@@ -995,10 +936,7 @@ class DOMUtils extends DOMUtilsEvent {
995
936
  return;
996
937
  }
997
938
  if (typeof content === "string") {
998
- element.insertAdjacentHTML(
999
- "beforebegin",
1000
- DOMUtilsCommonUtils.getSafeHTML(content)
1001
- );
939
+ element.insertAdjacentHTML("beforebegin", DOMUtilsCommonUtils.getSafeHTML(content));
1002
940
  } else {
1003
941
  let $parent = element.parentElement;
1004
942
  if (!$parent) {
@@ -1103,10 +1041,7 @@ class DOMUtils extends DOMUtilsEvent {
1103
1041
  * DOMUtils.width(document.querySelector("a.xx"),200)
1104
1042
  * DOMUtils.width("a.xx",200)
1105
1043
  */
1106
- width(
1107
- element: HTMLElement | string | Window | typeof globalThis | Document,
1108
- isShow?: boolean
1109
- ): number;
1044
+ width(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
1110
1045
  width(
1111
1046
  element: HTMLElement | string | Window | typeof globalThis | Document,
1112
1047
  isShow: boolean = false
@@ -1120,8 +1055,7 @@ class DOMUtils extends DOMUtilsEvent {
1120
1055
  return;
1121
1056
  }
1122
1057
  if (DOMUtilsCommonUtils.isWin(element)) {
1123
- return DOMUtilsContext.windowApi.window.document.documentElement
1124
- .clientWidth;
1058
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
1125
1059
  }
1126
1060
  if ((element as HTMLElement).nodeType === 9) {
1127
1061
  /* Document文档节点 */
@@ -1134,42 +1068,21 @@ class DOMUtils extends DOMUtilsEvent {
1134
1068
  element.documentElement.clientWidth
1135
1069
  );
1136
1070
  }
1137
- if (
1138
- isShow ||
1139
- (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))
1140
- ) {
1071
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))) {
1141
1072
  /* 已显示 */
1142
1073
  /* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
1143
1074
  element = element as HTMLElement;
1144
1075
  /* 如果element.style.width为空 则从css里面获取是否定义了width信息如果定义了 则读取css里面定义的宽度width */
1145
- if (
1146
- parseFloat(
1147
- DOMUtilsCommonUtils.getStyleValue(element, "width").toString()
1148
- ) > 0
1149
- ) {
1150
- return parseFloat(
1151
- DOMUtilsCommonUtils.getStyleValue(element, "width").toString()
1152
- );
1076
+ if (parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "width").toString()) > 0) {
1077
+ return parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "width").toString());
1153
1078
  }
1154
1079
 
1155
1080
  /* 如果从css里获取到的值不是大于0 可能是auto 则通过offsetWidth来进行计算 */
1156
1081
  if (element.offsetWidth > 0) {
1157
- let borderLeftWidth = DOMUtilsCommonUtils.getStyleValue(
1158
- element,
1159
- "borderLeftWidth"
1160
- );
1161
- let borderRightWidth = DOMUtilsCommonUtils.getStyleValue(
1162
- element,
1163
- "borderRightWidth"
1164
- );
1165
- let paddingLeft = DOMUtilsCommonUtils.getStyleValue(
1166
- element,
1167
- "paddingLeft"
1168
- );
1169
- let paddingRight = DOMUtilsCommonUtils.getStyleValue(
1170
- element,
1171
- "paddingRight"
1172
- );
1082
+ let borderLeftWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderLeftWidth");
1083
+ let borderRightWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderRightWidth");
1084
+ let paddingLeft = DOMUtilsCommonUtils.getStyleValue(element, "paddingLeft");
1085
+ let paddingRight = DOMUtilsCommonUtils.getStyleValue(element, "paddingRight");
1173
1086
  let backHeight =
1174
1087
  parseFloat(element.offsetWidth.toString()) -
1175
1088
  parseFloat(borderLeftWidth.toString()) -
@@ -1207,18 +1120,14 @@ class DOMUtils extends DOMUtilsEvent {
1207
1120
  * DOMUtils.height(document.querySelector("a.xx"),200)
1208
1121
  * DOMUtils.height("a.xx",200)
1209
1122
  */
1210
- height(
1211
- element: HTMLElement | string | Window | typeof globalThis | Document,
1212
- isShow?: boolean
1213
- ): number;
1123
+ height(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
1214
1124
  height(
1215
1125
  element: HTMLElement | string | Window | typeof globalThis | Document,
1216
1126
  isShow: boolean = false
1217
1127
  ): number {
1218
1128
  let DOMUtilsContext = this;
1219
1129
  if (DOMUtilsCommonUtils.isWin(element)) {
1220
- return DOMUtilsContext.windowApi.window.document.documentElement
1221
- .clientHeight;
1130
+ return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
1222
1131
  }
1223
1132
  if (typeof element === "string") {
1224
1133
  element = DOMUtilsContext.selector(element) as HTMLElement;
@@ -1238,42 +1147,21 @@ class DOMUtils extends DOMUtilsEvent {
1238
1147
  element.documentElement.clientHeight
1239
1148
  );
1240
1149
  }
1241
- if (
1242
- isShow ||
1243
- (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))
1244
- ) {
1150
+ if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))) {
1245
1151
  element = element as HTMLElement;
1246
1152
  /* 已显示 */
1247
1153
  /* 从style中获取对应的高度,因为可能使用了class定义了width !important */
1248
1154
  /* 如果element.style.height为空 则从css里面获取是否定义了height信息如果定义了 则读取css里面定义的高度height */
1249
- if (
1250
- parseFloat(
1251
- DOMUtilsCommonUtils.getStyleValue(element, "height").toString()
1252
- ) > 0
1253
- ) {
1254
- return parseFloat(
1255
- DOMUtilsCommonUtils.getStyleValue(element, "height").toString()
1256
- );
1155
+ if (parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "height").toString()) > 0) {
1156
+ return parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "height").toString());
1257
1157
  }
1258
1158
 
1259
1159
  /* 如果从css里获取到的值不是大于0 可能是auto 则通过offsetHeight来进行计算 */
1260
1160
  if (element.offsetHeight > 0) {
1261
- let borderTopWidth = DOMUtilsCommonUtils.getStyleValue(
1262
- element,
1263
- "borderTopWidth"
1264
- );
1265
- let borderBottomWidth = DOMUtilsCommonUtils.getStyleValue(
1266
- element,
1267
- "borderBottomWidth"
1268
- );
1269
- let paddingTop = DOMUtilsCommonUtils.getStyleValue(
1270
- element,
1271
- "paddingTop"
1272
- );
1273
- let paddingBottom = DOMUtilsCommonUtils.getStyleValue(
1274
- element,
1275
- "paddingBottom"
1276
- );
1161
+ let borderTopWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderTopWidth");
1162
+ let borderBottomWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderBottomWidth");
1163
+ let paddingTop = DOMUtilsCommonUtils.getStyleValue(element, "paddingTop");
1164
+ let paddingBottom = DOMUtilsCommonUtils.getStyleValue(element, "paddingBottom");
1277
1165
  let backHeight =
1278
1166
  parseFloat(element.offsetHeight.toString()) -
1279
1167
  parseFloat(borderTopWidth.toString()) -
@@ -1306,10 +1194,7 @@ class DOMUtils extends DOMUtilsEvent {
1306
1194
  * DOMUtils.outerWidth(window)
1307
1195
  * > 400
1308
1196
  */
1309
- outerWidth(
1310
- element: HTMLElement | string | Window | typeof globalThis | Document,
1311
- isShow?: boolean
1312
- ): number;
1197
+ outerWidth(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
1313
1198
  outerWidth(
1314
1199
  element: HTMLElement | string | Window | typeof globalThis | Document,
1315
1200
  isShow: boolean = false
@@ -1327,10 +1212,7 @@ class DOMUtils extends DOMUtilsEvent {
1327
1212
  }
1328
1213
  element = element as HTMLElement;
1329
1214
  if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
1330
- let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(
1331
- element,
1332
- null
1333
- );
1215
+ let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
1334
1216
  let marginLeft = DOMUtilsCommonUtils.getStyleValue(style, "marginLeft");
1335
1217
  let marginRight = DOMUtilsCommonUtils.getStyleValue(style, "marginRight");
1336
1218
  return element.offsetWidth + marginLeft + marginRight;
@@ -1376,15 +1258,9 @@ class DOMUtils extends DOMUtilsEvent {
1376
1258
  }
1377
1259
  element = element as HTMLElement;
1378
1260
  if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
1379
- let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(
1380
- element,
1381
- null
1382
- );
1261
+ let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
1383
1262
  let marginTop = DOMUtilsCommonUtils.getStyleValue(style, "marginTop");
1384
- let marginBottom = DOMUtilsCommonUtils.getStyleValue(
1385
- style,
1386
- "marginBottom"
1387
- );
1263
+ let marginBottom = DOMUtilsCommonUtils.getStyleValue(style, "marginBottom");
1388
1264
  return element.offsetHeight + marginTop + marginBottom;
1389
1265
  } else {
1390
1266
  let { recovery } = DOMUtilsCommonUtils.showElement(element);
@@ -1421,12 +1297,7 @@ class DOMUtils extends DOMUtilsEvent {
1421
1297
  if (DOMUtilsCommonUtils.isNodeList(element)) {
1422
1298
  // 设置
1423
1299
  element.forEach(($ele) => {
1424
- DOMUtilsContext.animate(
1425
- $ele as HTMLElement,
1426
- styles,
1427
- duration,
1428
- callback
1429
- );
1300
+ DOMUtilsContext.animate($ele as HTMLElement, styles, duration, callback);
1430
1301
  });
1431
1302
  return;
1432
1303
  }
@@ -1451,8 +1322,7 @@ class DOMUtils extends DOMUtilsEvent {
1451
1322
  } = {};
1452
1323
  for (let prop in styles) {
1453
1324
  from[prop] =
1454
- element.style[prop] ||
1455
- DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
1325
+ element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
1456
1326
  to[prop] = styles[prop];
1457
1327
  }
1458
1328
  let timer = DOMUtilsCommonUtils.setInterval(function () {
@@ -1462,8 +1332,7 @@ class DOMUtils extends DOMUtilsEvent {
1462
1332
  progress = 1;
1463
1333
  }
1464
1334
  for (let prop in styles) {
1465
- element.style[prop] =
1466
- from[prop] + (to[prop] - from[prop]) * progress + "px";
1335
+ element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
1467
1336
  }
1468
1337
  if (progress === 1) {
1469
1338
  DOMUtilsCommonUtils.clearInterval(timer);
@@ -1585,8 +1454,7 @@ class DOMUtils extends DOMUtilsEvent {
1585
1454
  return;
1586
1455
  }
1587
1456
  return Array.from(
1588
- (element.parentElement as HTMLElement)
1589
- .children as HTMLCollectionOf<HTMLElement>
1457
+ (element.parentElement as HTMLElement).children as HTMLCollectionOf<HTMLElement>
1590
1458
  ).filter((child) => child !== element);
1591
1459
  }
1592
1460
  /**
@@ -1711,30 +1579,16 @@ class DOMUtils extends DOMUtilsEvent {
1711
1579
  let serializedArray: { name: string; value: string }[] = [];
1712
1580
 
1713
1581
  for (let i = 0; i < elements.length; i++) {
1714
- const element = elements[i] as
1715
- | HTMLInputElement
1716
- | HTMLSelectElement
1717
- | HTMLTextAreaElement;
1582
+ const element = elements[i] as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
1718
1583
 
1719
1584
  if (
1720
1585
  element.name &&
1721
1586
  !element.disabled &&
1722
1587
  ((element as HTMLInputElement).checked ||
1723
- [
1724
- "text",
1725
- "hidden",
1726
- "password",
1727
- "textarea",
1728
- "select-one",
1729
- "select-multiple",
1730
- ].includes(element.type))
1588
+ ["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))
1731
1589
  ) {
1732
1590
  if (element.type === "select-multiple") {
1733
- for (
1734
- let j = 0;
1735
- j < (element as HTMLSelectElement).options.length;
1736
- j++
1737
- ) {
1591
+ for (let j = 0; j < (element as HTMLSelectElement).options.length; j++) {
1738
1592
  if ((element as HTMLSelectElement).options[j].selected) {
1739
1593
  serializedArray.push({
1740
1594
  name: (element as HTMLSelectElement).name,
@@ -1749,10 +1603,7 @@ class DOMUtils extends DOMUtilsEvent {
1749
1603
  }
1750
1604
 
1751
1605
  return serializedArray
1752
- .map(
1753
- (item) =>
1754
- `${encodeURIComponent(item.name)}=${encodeURIComponent(item.value)}`
1755
- )
1606
+ .map((item) => `${encodeURIComponent(item.name)}=${encodeURIComponent(item.value)}`)
1756
1607
  .join("&");
1757
1608
  }
1758
1609
  /**
@@ -1841,11 +1692,7 @@ class DOMUtils extends DOMUtilsEvent {
1841
1692
  * console.log("淡入完毕");
1842
1693
  * })
1843
1694
  */
1844
- fadeIn(
1845
- element: DOMUtilsTargetElementType,
1846
- duration: number = 400,
1847
- callback?: () => void
1848
- ) {
1695
+ fadeIn(element: DOMUtilsTargetElementType, duration: number = 400, callback?: () => void) {
1849
1696
  if (element == null) {
1850
1697
  return;
1851
1698
  }
@@ -1894,11 +1741,7 @@ class DOMUtils extends DOMUtilsEvent {
1894
1741
  * console.log("淡出完毕");
1895
1742
  * })
1896
1743
  */
1897
- fadeOut(
1898
- element: DOMUtilsTargetElementType,
1899
- duration: number = 400,
1900
- callback?: () => void
1901
- ) {
1744
+ fadeOut(element: DOMUtilsTargetElementType, duration: number = 400, callback?: () => void) {
1902
1745
  let DOMUtilsContext = this;
1903
1746
  if (element == null) {
1904
1747
  return;
@@ -1958,9 +1801,7 @@ class DOMUtils extends DOMUtilsEvent {
1958
1801
  return;
1959
1802
  }
1960
1803
  if (
1961
- DOMUtilsContext.windowApi.globalThis
1962
- .getComputedStyle(element)
1963
- .getPropertyValue("display") === "none"
1804
+ DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none"
1964
1805
  ) {
1965
1806
  DOMUtilsContext.show(element, checkVisiblie);
1966
1807
  } else {
@@ -1997,20 +1838,14 @@ class DOMUtils extends DOMUtilsEvent {
1997
1838
  if (selectionEnd == null) {
1998
1839
  selectionEnd = $input.selectionEnd || 0;
1999
1840
  }
2000
- if (typeof selectionStart == "string")
2001
- selectionStart = parseFloat(selectionStart);
1841
+ if (typeof selectionStart == "string") selectionStart = parseFloat(selectionStart);
2002
1842
  if (typeof selectionStart != "number" || isNaN(selectionStart)) {
2003
1843
  selectionStart = 0;
2004
1844
  }
2005
1845
  if (selectionStart < 0) selectionStart = 0;
2006
1846
  else selectionStart = Math.min($input.value.length, selectionStart);
2007
- if (typeof selectionEnd == "string")
2008
- selectionEnd = parseFloat(selectionEnd);
2009
- if (
2010
- typeof selectionEnd != "number" ||
2011
- isNaN(selectionEnd) ||
2012
- selectionEnd < selectionStart
2013
- ) {
1847
+ if (typeof selectionEnd == "string") selectionEnd = parseFloat(selectionEnd);
1848
+ if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
2014
1849
  selectionEnd = selectionStart;
2015
1850
  }
2016
1851
  if (selectionEnd < 0) selectionEnd = 0;
@@ -2112,14 +1947,8 @@ class DOMUtils extends DOMUtilsEvent {
2112
1947
  let $boxRect = $input.getBoundingClientRect();
2113
1948
  var clientTop = docElem.clientTop || body.clientTop || 0,
2114
1949
  clientLeft = docElem.clientLeft || body.clientLeft || 0,
2115
- scrollTop =
2116
- win.pageYOffset ||
2117
- (isBoxModel && docElem.scrollTop) ||
2118
- body.scrollTop,
2119
- scrollLeft =
2120
- win.pageXOffset ||
2121
- (isBoxModel && docElem.scrollLeft) ||
2122
- body.scrollLeft;
1950
+ scrollTop = win.pageYOffset || (isBoxModel && docElem.scrollTop) || body.scrollTop,
1951
+ scrollLeft = win.pageXOffset || (isBoxModel && docElem.scrollLeft) || body.scrollLeft;
2123
1952
  return {
2124
1953
  top: $boxRect.top + scrollTop - clientTop,
2125
1954
  left: $boxRect.left + scrollLeft - clientLeft,