@whitesev/domutils 1.3.4 → 1.3.5

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 CHANGED
@@ -595,11 +595,18 @@ define((function () { 'use strict';
595
595
  click(element, handler, details, useDispatchToTriggerEvent) {
596
596
  let DOMUtilsContext = this;
597
597
  if (typeof element === "string") {
598
- element = DOMUtilsContext.windowApi.document.querySelector(element);
598
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
599
599
  }
600
600
  if (element == null) {
601
601
  return;
602
602
  }
603
+ if (isNodeList(element)) {
604
+ // 设置
605
+ element.forEach(($ele) => {
606
+ DOMUtilsContext.click($ele, handler, details, useDispatchToTriggerEvent);
607
+ });
608
+ return;
609
+ }
603
610
  if (handler == null) {
604
611
  DOMUtilsContext.trigger(element, "click", details, useDispatchToTriggerEvent);
605
612
  }
@@ -629,6 +636,13 @@ define((function () { 'use strict';
629
636
  if (element == null) {
630
637
  return;
631
638
  }
639
+ if (isNodeList(element)) {
640
+ // 设置
641
+ element.forEach(($ele) => {
642
+ DOMUtilsContext.focus($ele, handler, details, useDispatchToTriggerEvent);
643
+ });
644
+ return;
645
+ }
632
646
  if (handler === null) {
633
647
  DOMUtilsContext.trigger(element, "blur", details, useDispatchToTriggerEvent);
634
648
  }
@@ -653,11 +667,18 @@ define((function () { 'use strict';
653
667
  focus(element, handler, details, useDispatchToTriggerEvent) {
654
668
  let DOMUtilsContext = this;
655
669
  if (typeof element === "string") {
656
- element = DOMUtilsContext.windowApi.document.querySelector(element);
670
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
657
671
  }
658
672
  if (element == null) {
659
673
  return;
660
674
  }
675
+ if (isNodeList(element)) {
676
+ // 设置
677
+ element.forEach(($ele) => {
678
+ DOMUtilsContext.focus($ele, handler, details, useDispatchToTriggerEvent);
679
+ });
680
+ return;
681
+ }
661
682
  if (handler == null) {
662
683
  DOMUtilsContext.trigger(element, "focus", details, useDispatchToTriggerEvent);
663
684
  }
@@ -682,18 +703,25 @@ define((function () { 'use strict';
682
703
  hover(element, handler, option) {
683
704
  let DOMUtilsContext = this;
684
705
  if (typeof element === "string") {
685
- element = DOMUtilsContext.windowApi.document.querySelector(element);
706
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
686
707
  }
687
708
  if (element == null) {
688
709
  return;
689
710
  }
711
+ if (isNodeList(element)) {
712
+ // 设置
713
+ element.forEach(($ele) => {
714
+ DOMUtilsContext.hover($ele, handler, option);
715
+ });
716
+ return;
717
+ }
690
718
  DOMUtilsContext.on(element, "mouseenter", null, handler, option);
691
719
  DOMUtilsContext.on(element, "mouseleave", null, handler, option);
692
720
  }
693
721
  /**
694
722
  * 当按键松开时触发事件
695
723
  * keydown - > keypress - > keyup
696
- * @param target 当前元素
724
+ * @param element 当前元素
697
725
  * @param handler 事件处理函数
698
726
  * @param option 配置
699
727
  * @example
@@ -705,20 +733,27 @@ define((function () { 'use strict';
705
733
  * console.log("按键松开");
706
734
  * })
707
735
  */
708
- keyup(target, handler, option) {
736
+ keyup(element, handler, option) {
709
737
  let DOMUtilsContext = this;
710
- if (target == null) {
738
+ if (element == null) {
711
739
  return;
712
740
  }
713
- if (typeof target === "string") {
714
- target = DOMUtilsContext.windowApi.document.querySelector(target);
741
+ if (typeof element === "string") {
742
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
743
+ }
744
+ if (isNodeList(element)) {
745
+ // 设置
746
+ element.forEach(($ele) => {
747
+ DOMUtilsContext.keyup($ele, handler, option);
748
+ });
749
+ return;
715
750
  }
716
- DOMUtilsContext.on(target, "keyup", null, handler, option);
751
+ DOMUtilsContext.on(element, "keyup", null, handler, option);
717
752
  }
718
753
  /**
719
754
  * 当按键按下时触发事件
720
755
  * keydown - > keypress - > keyup
721
- * @param target 目标
756
+ * @param element 目标
722
757
  * @param handler 事件处理函数
723
758
  * @param option 配置
724
759
  * @example
@@ -730,20 +765,27 @@ define((function () { 'use strict';
730
765
  * console.log("按键按下");
731
766
  * })
732
767
  */
733
- keydown(target, handler, option) {
768
+ keydown(element, handler, option) {
734
769
  let DOMUtilsContext = this;
735
- if (target == null) {
770
+ if (element == null) {
736
771
  return;
737
772
  }
738
- if (typeof target === "string") {
739
- target = DOMUtilsContext.windowApi.document.querySelector(target);
773
+ if (typeof element === "string") {
774
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
775
+ }
776
+ if (isNodeList(element)) {
777
+ // 设置
778
+ element.forEach(($ele) => {
779
+ DOMUtilsContext.keydown($ele, handler, option);
780
+ });
781
+ return;
740
782
  }
741
- DOMUtilsContext.on(target, "keydown", null, handler, option);
783
+ DOMUtilsContext.on(element, "keydown", null, handler, option);
742
784
  }
743
785
  /**
744
786
  * 当按键按下时触发事件
745
787
  * keydown - > keypress - > keyup
746
- * @param target 目标
788
+ * @param element 目标
747
789
  * @param handler 事件处理函数
748
790
  * @param option 配置
749
791
  * @example
@@ -755,20 +797,27 @@ define((function () { 'use strict';
755
797
  * console.log("按键按下");
756
798
  * })
757
799
  */
758
- keypress(target, handler, option) {
800
+ keypress(element, handler, option) {
759
801
  let DOMUtilsContext = this;
760
- if (target == null) {
802
+ if (element == null) {
761
803
  return;
762
804
  }
763
- if (typeof target === "string") {
764
- target = DOMUtilsContext.windowApi.document.querySelector(target);
805
+ if (typeof element === "string") {
806
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
807
+ }
808
+ if (isNodeList(element)) {
809
+ // 设置
810
+ element.forEach(($ele) => {
811
+ DOMUtilsContext.keypress($ele, handler, option);
812
+ });
813
+ return;
765
814
  }
766
- DOMUtilsContext.on(target, "keypress", null, handler, option);
815
+ DOMUtilsContext.on(element, "keypress", null, handler, option);
767
816
  }
768
817
  /**
769
818
  * 监听某个元素键盘按键事件或window全局按键事件
770
819
  * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
771
- * @param target 需要监听的对象,可以是全局Window或者某个元素
820
+ * @param element 需要监听的对象,可以是全局Window或者某个元素
772
821
  * @param eventName 事件名,默认keypress
773
822
  * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
774
823
  * @param options 监听事件的配置
@@ -828,7 +877,11 @@ define((function () { 'use strict';
828
877
  搜索 170
829
878
  收藏 171
830
879
  **/
831
- listenKeyboard(target, eventName = "keypress", callback, options) {
880
+ listenKeyboard(element, eventName = "keypress", callback, options) {
881
+ let DOMUtilsContext = this;
882
+ if (typeof element === "string") {
883
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
884
+ }
832
885
  let keyboardEventCallBack = function (event) {
833
886
  /** 键名 */
834
887
  let keyName = event.key || event.code;
@@ -852,29 +905,49 @@ define((function () { 'use strict';
852
905
  callback(keyName, keyValue, otherCodeList, event);
853
906
  }
854
907
  };
855
- this.on(target, eventName, keyboardEventCallBack, options);
908
+ DOMUtilsContext.on(element, eventName, keyboardEventCallBack, options);
856
909
  return {
857
910
  removeListen: () => {
858
- this.off(target, eventName, keyboardEventCallBack, options);
911
+ DOMUtilsContext.off(element, eventName, keyboardEventCallBack, options);
859
912
  },
860
913
  };
861
914
  }
862
915
  }
863
916
 
917
+ /**
918
+ * 判断是否是元素列表
919
+ * @param $ele
920
+ */
921
+ const isNodeList = ($ele) => {
922
+ return Array.isArray($ele) || $ele instanceof NodeList;
923
+ };
864
924
  class DOMUtils extends DOMUtilsEvent {
865
925
  constructor(option) {
866
926
  super(option);
867
927
  }
868
928
  /** 版本号 */
869
- version = "2024.10.19";
929
+ version = "2024.10.22";
870
930
  attr(element, attrName, attrValue) {
871
931
  let DOMUtilsContext = this;
872
932
  if (typeof element === "string") {
873
- element = DOMUtilsContext.windowApi.document.querySelector(element);
933
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
874
934
  }
875
935
  if (element == null) {
876
936
  return;
877
937
  }
938
+ if (isNodeList(element)) {
939
+ if (attrValue == null) {
940
+ // 获取属性
941
+ return DOMUtilsContext.attr(element[0], attrName, attrValue);
942
+ }
943
+ else {
944
+ // 设置属性
945
+ element.forEach(($ele) => {
946
+ DOMUtilsContext.attr($ele, attrName, attrValue);
947
+ });
948
+ return;
949
+ }
950
+ }
878
951
  if (attrValue == null) {
879
952
  return element.getAttribute(attrName);
880
953
  }
@@ -963,14 +1036,40 @@ define((function () { 'use strict';
963
1036
  return propertyValue;
964
1037
  }
965
1038
  if (typeof element === "string") {
966
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1039
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
967
1040
  }
968
1041
  if (element == null) {
969
1042
  return;
970
1043
  }
1044
+ if (isNodeList(element)) {
1045
+ if (typeof property === "string") {
1046
+ if (value == null) {
1047
+ // 获取属性
1048
+ return DOMUtilsContext.css(element[0], property);
1049
+ }
1050
+ else {
1051
+ // 设置属性
1052
+ element.forEach(($ele) => {
1053
+ DOMUtilsContext.css($ele, property);
1054
+ });
1055
+ return;
1056
+ }
1057
+ }
1058
+ else if (typeof property === "object") {
1059
+ // 设置属性
1060
+ element.forEach(($ele) => {
1061
+ DOMUtilsContext.css($ele, property);
1062
+ });
1063
+ return;
1064
+ }
1065
+ else ;
1066
+ return;
1067
+ }
971
1068
  if (typeof property === "string") {
972
1069
  if (value == null) {
973
- return getComputedStyle(element).getPropertyValue(property);
1070
+ return DOMUtilsContext.windowApi.globalThis
1071
+ .getComputedStyle(element)
1072
+ .getPropertyValue(property);
974
1073
  }
975
1074
  else {
976
1075
  if (value === "string" && value.includes("!important")) {
@@ -994,15 +1093,29 @@ define((function () { 'use strict';
994
1093
  }
995
1094
  }
996
1095
  }
1096
+ else ;
997
1097
  }
998
1098
  text(element, text) {
999
1099
  let DOMUtilsContext = this;
1000
1100
  if (typeof element === "string") {
1001
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1101
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1002
1102
  }
1003
1103
  if (element == null) {
1004
1104
  return;
1005
1105
  }
1106
+ if (isNodeList(element)) {
1107
+ if (text == null) {
1108
+ // 获取
1109
+ return DOMUtilsContext.text(element[0]);
1110
+ }
1111
+ else {
1112
+ // 设置
1113
+ element.forEach(($ele) => {
1114
+ DOMUtilsContext.text($ele, text);
1115
+ });
1116
+ }
1117
+ return;
1118
+ }
1006
1119
  if (text == null) {
1007
1120
  return element.textContent || element.innerText;
1008
1121
  }
@@ -1021,15 +1134,30 @@ define((function () { 'use strict';
1021
1134
  html(element, html) {
1022
1135
  let DOMUtilsContext = this;
1023
1136
  if (typeof element === "string") {
1024
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1137
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1025
1138
  }
1026
1139
  if (element == null) {
1027
1140
  return;
1028
1141
  }
1142
+ if (isNodeList(element)) {
1143
+ if (html == null) {
1144
+ // 获取
1145
+ return DOMUtilsContext.html(element[0]);
1146
+ }
1147
+ else {
1148
+ // 设置
1149
+ element.forEach(($ele) => {
1150
+ DOMUtilsContext.html($ele, html);
1151
+ });
1152
+ }
1153
+ return;
1154
+ }
1029
1155
  if (html == null) {
1156
+ // 获取
1030
1157
  return element.innerHTML;
1031
1158
  }
1032
1159
  else {
1160
+ // 设置
1033
1161
  if (html instanceof Element) {
1034
1162
  html = html.innerHTML;
1035
1163
  }
@@ -1052,7 +1180,7 @@ define((function () { 'use strict';
1052
1180
  recovery();
1053
1181
  return transformInfo;
1054
1182
  }
1055
- let elementTransform = getComputedStyle(element).transform;
1183
+ let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
1056
1184
  if (elementTransform != null &&
1057
1185
  elementTransform !== "none" &&
1058
1186
  elementTransform !== "") {
@@ -1076,12 +1204,26 @@ define((function () { 'use strict';
1076
1204
  val(element, value) {
1077
1205
  let DOMUtilsContext = this;
1078
1206
  if (typeof element === "string") {
1079
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1207
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1080
1208
  }
1081
1209
  if (element == null) {
1082
1210
  return;
1083
1211
  }
1212
+ if (isNodeList(element)) {
1213
+ if (value == null) {
1214
+ // 获取
1215
+ return DOMUtilsContext.val(element[0]);
1216
+ }
1217
+ else {
1218
+ // 设置
1219
+ element.forEach(($ele) => {
1220
+ DOMUtilsContext.val($ele, value);
1221
+ });
1222
+ }
1223
+ return;
1224
+ }
1084
1225
  if (value == null) {
1226
+ // 获取
1085
1227
  if (element.localName === "input" &&
1086
1228
  (element.type === "checkbox" || element.type === "radio")) {
1087
1229
  return element.checked;
@@ -1091,6 +1233,7 @@ define((function () { 'use strict';
1091
1233
  }
1092
1234
  }
1093
1235
  else {
1236
+ // 设置
1094
1237
  if (element.localName === "input" &&
1095
1238
  (element.type === "checkbox" || element.type === "radio")) {
1096
1239
  element.checked = !!value;
@@ -1102,17 +1245,30 @@ define((function () { 'use strict';
1102
1245
  }
1103
1246
  prop(element, propName, propValue) {
1104
1247
  let DOMUtilsContext = this;
1248
+ if (typeof element === "string") {
1249
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1250
+ }
1105
1251
  if (element == null) {
1106
1252
  return;
1107
1253
  }
1108
- if (typeof element === "string") {
1109
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1254
+ if (isNodeList(element)) {
1255
+ if (propValue == null) {
1256
+ // 获取
1257
+ return DOMUtilsContext.prop(element[0], propName);
1258
+ }
1259
+ else {
1260
+ // 设置
1261
+ element.forEach(($ele) => {
1262
+ DOMUtilsContext.prop($ele, propName, propValue);
1263
+ });
1264
+ }
1265
+ return;
1110
1266
  }
1111
1267
  if (propValue == null) {
1112
- return element[propName];
1268
+ return Reflect.get(element, propName);
1113
1269
  }
1114
1270
  else {
1115
- element[propName] = propValue;
1271
+ Reflect.set(element, propName, propValue);
1116
1272
  }
1117
1273
  }
1118
1274
  /**
@@ -1127,11 +1283,18 @@ define((function () { 'use strict';
1127
1283
  removeAttr(element, attrName) {
1128
1284
  let DOMUtilsContext = this;
1129
1285
  if (typeof element === "string") {
1130
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1286
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1131
1287
  }
1132
1288
  if (element == null) {
1133
1289
  return;
1134
1290
  }
1291
+ if (isNodeList(element)) {
1292
+ // 设置
1293
+ element.forEach(($ele) => {
1294
+ DOMUtilsContext.removeAttr($ele, attrName);
1295
+ });
1296
+ return;
1297
+ }
1135
1298
  element.removeAttribute(attrName);
1136
1299
  }
1137
1300
  /**
@@ -1146,15 +1309,30 @@ define((function () { 'use strict';
1146
1309
  removeClass(element, className) {
1147
1310
  let DOMUtilsContext = this;
1148
1311
  if (typeof element === "string") {
1149
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1312
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1150
1313
  }
1151
1314
  if (element == null) {
1152
1315
  return;
1153
1316
  }
1154
- if (className == null) {
1317
+ if (isNodeList(element)) {
1318
+ // 设置
1319
+ element.forEach(($ele) => {
1320
+ DOMUtilsContext.removeClass($ele, className);
1321
+ });
1155
1322
  return;
1156
1323
  }
1157
- element.classList.remove(className);
1324
+ if (className == null) {
1325
+ // 清空全部className
1326
+ element.className = "";
1327
+ }
1328
+ else {
1329
+ if (!Array.isArray(className)) {
1330
+ className = className.split(" ");
1331
+ }
1332
+ className.forEach((itemClassName) => {
1333
+ element.classList.remove(itemClassName);
1334
+ });
1335
+ }
1158
1336
  }
1159
1337
  /**
1160
1338
  * 移除元素的属性
@@ -1168,11 +1346,18 @@ define((function () { 'use strict';
1168
1346
  removeProp(element, propName) {
1169
1347
  let DOMUtilsContext = this;
1170
1348
  if (typeof element === "string") {
1171
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1349
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1172
1350
  }
1173
1351
  if (element == null) {
1174
1352
  return;
1175
1353
  }
1354
+ if (isNodeList(element)) {
1355
+ // 设置
1356
+ element.forEach(($ele) => {
1357
+ DOMUtilsContext.removeProp($ele, propName);
1358
+ });
1359
+ return;
1360
+ }
1176
1361
  DOMUtilsCommonUtils.delete(element, propName);
1177
1362
  }
1178
1363
  /**
@@ -1187,22 +1372,22 @@ define((function () { 'use strict';
1187
1372
  replaceWith(element, newElement) {
1188
1373
  let DOMUtilsContext = this;
1189
1374
  if (typeof element === "string") {
1190
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1375
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1191
1376
  }
1192
1377
  if (element == null) {
1193
1378
  return;
1194
1379
  }
1195
- if (typeof newElement === "string") {
1196
- newElement = DOMUtilsContext.parseHTML(newElement, false, false);
1197
- }
1198
- if (element instanceof NodeList || element instanceof Array) {
1199
- element.forEach((item) => {
1200
- DOMUtilsContext.replaceWith(item, newElement);
1380
+ if (isNodeList(element)) {
1381
+ // 设置
1382
+ element.forEach(($ele) => {
1383
+ DOMUtilsContext.replaceWith($ele, newElement);
1201
1384
  });
1385
+ return;
1202
1386
  }
1203
- else {
1204
- element.parentElement.replaceChild(newElement, element);
1387
+ if (typeof newElement === "string") {
1388
+ newElement = DOMUtilsContext.parseHTML(newElement, false, false);
1205
1389
  }
1390
+ element.parentElement.replaceChild(newElement, element);
1206
1391
  }
1207
1392
  /**
1208
1393
  * 给元素添加class
@@ -1216,12 +1401,27 @@ define((function () { 'use strict';
1216
1401
  addClass(element, className) {
1217
1402
  let DOMUtilsContext = this;
1218
1403
  if (typeof element === "string") {
1219
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1404
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1220
1405
  }
1221
1406
  if (element == null) {
1222
1407
  return;
1223
1408
  }
1224
- element.classList.add(className);
1409
+ if (isNodeList(element)) {
1410
+ // 设置
1411
+ element.forEach(($ele) => {
1412
+ DOMUtilsContext.addClass($ele, className);
1413
+ });
1414
+ return;
1415
+ }
1416
+ if (!Array.isArray(className)) {
1417
+ className = className.split(" ");
1418
+ }
1419
+ className.forEach((itemClassName) => {
1420
+ if (itemClassName.trim() == "") {
1421
+ return;
1422
+ }
1423
+ element.classList.add(itemClassName);
1424
+ });
1225
1425
  }
1226
1426
  /**
1227
1427
  * 函数在元素内部末尾添加子元素或HTML字符串
@@ -1235,11 +1435,18 @@ define((function () { 'use strict';
1235
1435
  append(element, content) {
1236
1436
  let DOMUtilsContext = this;
1237
1437
  if (typeof element === "string") {
1238
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1438
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1239
1439
  }
1240
1440
  if (element == null) {
1241
1441
  return;
1242
1442
  }
1443
+ if (isNodeList(element)) {
1444
+ // 设置
1445
+ element.forEach(($ele) => {
1446
+ DOMUtilsContext.append($ele, content);
1447
+ });
1448
+ return;
1449
+ }
1243
1450
  function elementAppendChild(ele, text) {
1244
1451
  if (typeof content === "string") {
1245
1452
  ele.insertAdjacentHTML("beforeend", text);
@@ -1253,7 +1460,7 @@ define((function () { 'use strict';
1253
1460
  let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
1254
1461
  content.forEach((ele) => {
1255
1462
  if (typeof ele === "string") {
1256
- ele = this.parseHTML(ele, true, false);
1463
+ ele = DOMUtilsContext.parseHTML(ele, true, false);
1257
1464
  }
1258
1465
  fragment.appendChild(ele);
1259
1466
  });
@@ -1275,11 +1482,18 @@ define((function () { 'use strict';
1275
1482
  prepend(element, content) {
1276
1483
  let DOMUtilsContext = this;
1277
1484
  if (typeof element === "string") {
1278
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1485
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1279
1486
  }
1280
1487
  if (element == null) {
1281
1488
  return;
1282
1489
  }
1490
+ if (isNodeList(element)) {
1491
+ // 设置
1492
+ element.forEach(($ele) => {
1493
+ DOMUtilsContext.prepend($ele, content);
1494
+ });
1495
+ return;
1496
+ }
1283
1497
  if (typeof content === "string") {
1284
1498
  element.insertAdjacentHTML("afterbegin", content);
1285
1499
  }
@@ -1305,11 +1519,18 @@ define((function () { 'use strict';
1305
1519
  after(element, content) {
1306
1520
  let DOMUtilsContext = this;
1307
1521
  if (typeof element === "string") {
1308
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1522
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1309
1523
  }
1310
1524
  if (element == null) {
1311
1525
  return;
1312
1526
  }
1527
+ if (isNodeList(element)) {
1528
+ // 设置
1529
+ element.forEach(($ele) => {
1530
+ DOMUtilsContext.after($ele, content);
1531
+ });
1532
+ return;
1533
+ }
1313
1534
  if (typeof content === "string") {
1314
1535
  element.insertAdjacentHTML("afterend", content);
1315
1536
  }
@@ -1337,11 +1558,18 @@ define((function () { 'use strict';
1337
1558
  before(element, content) {
1338
1559
  let DOMUtilsContext = this;
1339
1560
  if (typeof element === "string") {
1340
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1561
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1341
1562
  }
1342
1563
  if (element == null) {
1343
1564
  return;
1344
1565
  }
1566
+ if (isNodeList(element)) {
1567
+ // 设置
1568
+ element.forEach(($ele) => {
1569
+ DOMUtilsContext.before($ele, content);
1570
+ });
1571
+ return;
1572
+ }
1345
1573
  if (typeof content === "string") {
1346
1574
  element.insertAdjacentHTML("beforebegin", content);
1347
1575
  }
@@ -1357,30 +1585,28 @@ define((function () { 'use strict';
1357
1585
  }
1358
1586
  /**
1359
1587
  * 移除元素
1360
- * @param target 目标元素
1588
+ * @param element 目标元素
1361
1589
  * @example
1362
1590
  * // 元素a.xx前面添加一个元素
1363
1591
  * DOMUtils.remove(document.querySelector("a.xx"))
1364
1592
  * DOMUtils.remove(document.querySelectorAll("a.xx"))
1365
1593
  * DOMUtils.remove("a.xx")
1366
1594
  * */
1367
- remove(target) {
1595
+ remove(element) {
1368
1596
  let DOMUtilsContext = this;
1369
- if (typeof target === "string") {
1370
- target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1597
+ if (typeof element === "string") {
1598
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1371
1599
  }
1372
- if (target == null) {
1600
+ if (element == null) {
1373
1601
  return;
1374
1602
  }
1375
- if (target instanceof NodeList || target instanceof Array) {
1376
- target = target;
1377
- for (const element of target) {
1378
- DOMUtilsContext.remove(element);
1379
- }
1380
- }
1381
- else {
1382
- target.remove();
1603
+ if (isNodeList(element)) {
1604
+ element.forEach(($ele) => {
1605
+ DOMUtilsContext.remove($ele);
1606
+ });
1607
+ return;
1383
1608
  }
1609
+ element.remove();
1384
1610
  }
1385
1611
  /**
1386
1612
  * 移除元素的所有子元素
@@ -1393,11 +1619,18 @@ define((function () { 'use strict';
1393
1619
  empty(element) {
1394
1620
  let DOMUtilsContext = this;
1395
1621
  if (typeof element === "string") {
1396
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1622
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1397
1623
  }
1398
1624
  if (element == null) {
1399
1625
  return;
1400
1626
  }
1627
+ if (isNodeList(element)) {
1628
+ // 设置
1629
+ element.forEach(($ele) => {
1630
+ DOMUtilsContext.empty($ele);
1631
+ });
1632
+ return;
1633
+ }
1401
1634
  element.innerHTML = "";
1402
1635
  }
1403
1636
  /**
@@ -1428,7 +1661,8 @@ define((function () { 'use strict';
1428
1661
  width(element, isShow = false) {
1429
1662
  let DOMUtilsContext = this;
1430
1663
  if (typeof element === "string") {
1431
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1664
+ element =
1665
+ DOMUtilsContext.windowApi.document.querySelector(element);
1432
1666
  }
1433
1667
  if (element == null) {
1434
1668
  return;
@@ -1540,7 +1774,7 @@ define((function () { 'use strict';
1540
1774
  }
1541
1775
  element = element;
1542
1776
  if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
1543
- let style = getComputedStyle(element, null);
1777
+ let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
1544
1778
  let marginLeft = DOMUtilsCommonUtils.getStyleValue(style, "marginLeft");
1545
1779
  let marginRight = DOMUtilsCommonUtils.getStyleValue(style, "marginRight");
1546
1780
  return element.offsetWidth + marginLeft + marginRight;
@@ -1566,7 +1800,7 @@ define((function () { 'use strict';
1566
1800
  }
1567
1801
  element = element;
1568
1802
  if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
1569
- let style = getComputedStyle(element, null);
1803
+ let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
1570
1804
  let marginTop = DOMUtilsCommonUtils.getStyleValue(style, "marginTop");
1571
1805
  let marginBottom = DOMUtilsCommonUtils.getStyleValue(style, "marginBottom");
1572
1806
  return element.offsetHeight + marginTop + marginBottom;
@@ -1593,11 +1827,18 @@ define((function () { 'use strict';
1593
1827
  animate(element, styles, duration = 1000, callback = null) {
1594
1828
  let DOMUtilsContext = this;
1595
1829
  if (typeof element === "string") {
1596
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1830
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1597
1831
  }
1598
1832
  if (element == null) {
1599
1833
  return;
1600
1834
  }
1835
+ if (isNodeList(element)) {
1836
+ // 设置
1837
+ element.forEach(($ele) => {
1838
+ DOMUtilsContext.animate($ele, styles, duration, callback);
1839
+ });
1840
+ return;
1841
+ }
1601
1842
  if (typeof duration !== "number" || duration <= 0) {
1602
1843
  throw new TypeError("duration must be a positive number");
1603
1844
  }
@@ -1614,7 +1855,9 @@ define((function () { 'use strict';
1614
1855
  let from = {};
1615
1856
  let to = {};
1616
1857
  for (let prop in styles) {
1617
- from[prop] = element.style[prop] || getComputedStyle(element)[prop];
1858
+ from[prop] =
1859
+ element.style[prop] ||
1860
+ DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
1618
1861
  to[prop] = styles[prop];
1619
1862
  }
1620
1863
  let timer = setInterval(function () {
@@ -1646,18 +1889,26 @@ define((function () { 'use strict';
1646
1889
  wrap(element, wrapperHTML) {
1647
1890
  let DOMUtilsContext = this;
1648
1891
  if (typeof element === "string") {
1649
- element = DOMUtilsContext.windowApi.document.querySelector(element);
1892
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1650
1893
  }
1651
1894
  if (element == null) {
1652
1895
  return;
1653
1896
  }
1897
+ if (isNodeList(element)) {
1898
+ // 设置
1899
+ element.forEach(($ele) => {
1900
+ DOMUtilsContext.wrap($ele, wrapperHTML);
1901
+ });
1902
+ return;
1903
+ }
1654
1904
  element = element;
1655
1905
  // 创建一个新的div元素,并将wrapperHTML作为其innerHTML
1656
1906
  let wrapper = DOMUtilsContext.windowApi.document.createElement("div");
1657
1907
  wrapper.innerHTML = wrapperHTML;
1658
1908
  let wrapperFirstChild = wrapper.firstChild;
1659
1909
  // 将要包裹的元素插入目标元素前面
1660
- element.parentElement.insertBefore(wrapperFirstChild, element);
1910
+ let parentElement = element.parentElement;
1911
+ parentElement.insertBefore(wrapperFirstChild, element);
1661
1912
  // 将要包裹的元素移动到wrapper中
1662
1913
  wrapperFirstChild.appendChild(element);
1663
1914
  }
@@ -1737,6 +1988,8 @@ define((function () { 'use strict';
1737
1988
  }
1738
1989
  parseHTML(html, useParser = false, isComplete = false) {
1739
1990
  let DOMUtilsContext = this;
1991
+ // 去除html前后的空格
1992
+ html = html.trim();
1740
1993
  function parseHTMLByDOMParser() {
1741
1994
  let parser = new DOMParser();
1742
1995
  if (isComplete) {
@@ -1763,16 +2016,61 @@ define((function () { 'use strict';
1763
2016
  return parseHTMLByCreateDom();
1764
2017
  }
1765
2018
  }
2019
+ /**
2020
+ * 序列化表单元素
2021
+ * @param $form 表单元素
2022
+ * @example
2023
+ * DOMUtils.serialize(document.querySelector("form"))
2024
+ * > xxx=xxx&aaa=
2025
+ */
2026
+ serialize($form) {
2027
+ const elements = $form.elements;
2028
+ let serializedArray = [];
2029
+ for (let i = 0; i < elements.length; i++) {
2030
+ const element = elements[i];
2031
+ if (element.name &&
2032
+ !element.disabled &&
2033
+ (element.checked ||
2034
+ [
2035
+ "text",
2036
+ "hidden",
2037
+ "password",
2038
+ "textarea",
2039
+ "select-one",
2040
+ "select-multiple",
2041
+ ].includes(element.type))) {
2042
+ if (element.type === "select-multiple") {
2043
+ for (let j = 0; j < element.options.length; j++) {
2044
+ if (element.options[j].selected) {
2045
+ serializedArray.push({
2046
+ name: element.name,
2047
+ value: element.options[j].value,
2048
+ });
2049
+ }
2050
+ }
2051
+ }
2052
+ else {
2053
+ serializedArray.push({ name: element.name, value: element.value });
2054
+ }
2055
+ }
2056
+ }
2057
+ return serializedArray
2058
+ .map((item) => `${encodeURIComponent(item.name)}=${encodeURIComponent(item.value)}`)
2059
+ .join("&");
2060
+ }
1766
2061
  /**
1767
2062
  * 显示元素
1768
2063
  * @param target 当前元素
2064
+ * @param checkVisiblie 是否检测元素是否显示
2065
+ * + true (默认)如果检测到还未显示,则强制使用display: unset !important;
2066
+ * + false 不检测,直接设置display属性为空
1769
2067
  * @example
1770
2068
  * // 显示a.xx元素
1771
2069
  * DOMUtils.show(document.querySelector("a.xx"))
1772
2070
  * DOMUtils.show(document.querySelectorAll("a.xx"))
1773
2071
  * DOMUtils.show("a.xx")
1774
2072
  */
1775
- show(target) {
2073
+ show(target, checkVisiblie = true) {
1776
2074
  let DOMUtilsContext = this;
1777
2075
  if (target == null) {
1778
2076
  return;
@@ -1783,28 +2081,33 @@ define((function () { 'use strict';
1783
2081
  if (target instanceof NodeList || target instanceof Array) {
1784
2082
  target = target;
1785
2083
  for (const element of target) {
1786
- DOMUtilsContext.show(element);
2084
+ DOMUtilsContext.show(element, checkVisiblie);
1787
2085
  }
1788
2086
  }
1789
2087
  else {
1790
2088
  target = target;
1791
2089
  target.style.display = "";
1792
- if (!DOMUtilsCommonUtils.isShow(target)) {
1793
- /* 仍然是不显示,尝试使用强覆盖 */
1794
- target.style.setProperty("display", "unset", "important");
2090
+ if (checkVisiblie) {
2091
+ if (!DOMUtilsCommonUtils.isShow(target)) {
2092
+ /* 仍然是不显示,尝试使用强覆盖 */
2093
+ target.style.setProperty("display", "unset", "important");
2094
+ }
1795
2095
  }
1796
2096
  }
1797
2097
  }
1798
2098
  /**
1799
2099
  * 隐藏元素
1800
2100
  * @param target 当前元素
2101
+ * @param checkVisiblie 是否检测元素是否显示
2102
+ * + true (默认)如果检测到显示,则强制使用display: none !important;
2103
+ * + false 不检测,直接设置display属性为none
1801
2104
  * @example
1802
2105
  * // 隐藏a.xx元素
1803
2106
  * DOMUtils.hide(document.querySelector("a.xx"))
1804
2107
  * DOMUtils.hide(document.querySelectorAll("a.xx"))
1805
2108
  * DOMUtils.hide("a.xx")
1806
2109
  */
1807
- hide(target) {
2110
+ hide(target, checkVisiblie = true) {
1808
2111
  let DOMUtilsContext = this;
1809
2112
  if (target == null) {
1810
2113
  return;
@@ -1815,15 +2118,17 @@ define((function () { 'use strict';
1815
2118
  if (target instanceof NodeList || target instanceof Array) {
1816
2119
  target = target;
1817
2120
  for (const element of target) {
1818
- DOMUtilsContext.hide(element);
2121
+ DOMUtilsContext.hide(element, checkVisiblie);
1819
2122
  }
1820
2123
  }
1821
2124
  else {
1822
2125
  target = target;
1823
2126
  target.style.display = "none";
1824
- if (DOMUtilsCommonUtils.isShow(target)) {
1825
- /* 仍然是显示,尝试使用强覆盖 */
1826
- target.style.setProperty("display", "none", "important");
2127
+ if (checkVisiblie) {
2128
+ if (DOMUtilsCommonUtils.isShow(target)) {
2129
+ /* 仍然是显示,尝试使用强覆盖 */
2130
+ target.style.setProperty("display", "none", "important");
2131
+ }
1827
2132
  }
1828
2133
  }
1829
2134
  }
@@ -1847,9 +2152,15 @@ define((function () { 'use strict';
1847
2152
  }
1848
2153
  let DOMUtilsContext = this;
1849
2154
  if (typeof element === "string") {
1850
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2155
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
2156
+ }
2157
+ if (isNodeList(element)) {
2158
+ // 设置
2159
+ element.forEach(($ele) => {
2160
+ DOMUtilsContext.fadeIn($ele, duration, callback);
2161
+ });
2162
+ return;
1851
2163
  }
1852
- element = element;
1853
2164
  element.style.opacity = "0";
1854
2165
  element.style.display = "";
1855
2166
  let start = null;
@@ -1892,9 +2203,15 @@ define((function () { 'use strict';
1892
2203
  return;
1893
2204
  }
1894
2205
  if (typeof element === "string") {
1895
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2206
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
2207
+ }
2208
+ if (isNodeList(element)) {
2209
+ // 设置
2210
+ element.forEach(($ele) => {
2211
+ DOMUtilsContext.fadeOut($ele, duration, callback);
2212
+ });
2213
+ return;
1896
2214
  }
1897
- element = element;
1898
2215
  element.style.opacity = "1";
1899
2216
  let start = null;
1900
2217
  let timer = null;
@@ -1920,24 +2237,34 @@ define((function () { 'use strict';
1920
2237
  /**
1921
2238
  * 切换元素的显示和隐藏状态
1922
2239
  * @param element 当前元素
2240
+ * @param checkVisiblie 是否检测元素是否显示
1923
2241
  * @example
1924
2242
  * // 如果元素a.xx当前是隐藏,则显示,如果是显示,则隐藏
1925
2243
  * DOMUtils.toggle(document.querySelector("a.xx"))
1926
2244
  * DOMUtils.toggle("a.xx")
1927
2245
  */
1928
- toggle(element) {
2246
+ toggle(element, checkVisiblie) {
1929
2247
  let DOMUtilsContext = this;
1930
2248
  if (typeof element === "string") {
1931
- element = DOMUtilsContext.windowApi.document.querySelector(element);
2249
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
1932
2250
  }
1933
2251
  if (element == null) {
1934
2252
  return;
1935
2253
  }
1936
- if (getComputedStyle(element).getPropertyValue("display") === "none") {
1937
- DOMUtilsContext.show(element);
2254
+ if (isNodeList(element)) {
2255
+ // 设置
2256
+ element.forEach(($ele) => {
2257
+ DOMUtilsContext.toggle($ele);
2258
+ });
2259
+ return;
2260
+ }
2261
+ if (DOMUtilsContext.windowApi.globalThis
2262
+ .getComputedStyle(element)
2263
+ .getPropertyValue("display") === "none") {
2264
+ DOMUtilsContext.show(element, checkVisiblie);
1938
2265
  }
1939
2266
  else {
1940
- DOMUtilsContext.hide(element);
2267
+ DOMUtilsContext.hide(element, checkVisiblie);
1941
2268
  }
1942
2269
  }
1943
2270
  /**