@whitesev/domutils 1.2.0 → 1.3.1

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.umd.js CHANGED
@@ -4,43 +4,12 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DOMUtils = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
- const DOMUtilsCoreDefaultEnv = {
8
- document: document,
9
- window: window,
10
- globalThis: globalThis,
11
- self: self,
12
- top: top,
13
- };
14
- const DOMUtilsCoreEnv = {
15
- document: document,
16
- window: window,
17
- globalThis: globalThis,
18
- self: self,
19
- top: top,
20
- };
21
- const DOMUtilsCore = {
22
- init(option) {
23
- if (!option) {
24
- option = Object.assign({}, DOMUtilsCoreDefaultEnv);
25
- }
26
- Object.assign(DOMUtilsCoreEnv, option);
27
- },
28
- get document() {
29
- return DOMUtilsCoreEnv.document;
30
- },
31
- get window() {
32
- return DOMUtilsCoreEnv.window;
33
- },
34
- get globalThis() {
35
- return DOMUtilsCoreEnv.globalThis;
36
- },
37
- get self() {
38
- return DOMUtilsCoreEnv.self;
39
- },
40
- };
41
-
42
7
  /** 通用工具类 */
43
8
  const DOMUtilsCommonUtils = {
9
+ windowApi: {
10
+ window: window,
11
+ document: document,
12
+ },
44
13
  /**
45
14
  * 判断元素是否已显示或已连接
46
15
  * @param element
@@ -55,7 +24,7 @@
55
24
  showElement(element) {
56
25
  let dupNode = element.cloneNode(true);
57
26
  dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
58
- DOMUtilsCore.document.documentElement.appendChild(dupNode);
27
+ this.windowApi.document.documentElement.appendChild(dupNode);
59
28
  return {
60
29
  /**
61
30
  * 恢复修改的style
@@ -112,13 +81,13 @@
112
81
  if (target === self) {
113
82
  return true;
114
83
  }
115
- if (target === DOMUtilsCore.globalThis) {
84
+ if (target === globalThis) {
116
85
  return true;
117
86
  }
118
- if (target === DOMUtilsCore.window) {
87
+ if (target === window) {
119
88
  return true;
120
89
  }
121
- if (target === DOMUtilsCore.self) {
90
+ if (target === self) {
122
91
  return true;
123
92
  }
124
93
  if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
@@ -156,7 +125,45 @@
156
125
  },
157
126
  };
158
127
 
128
+ class WindowApi {
129
+ /** 默认的配置 */
130
+ defaultApi = {
131
+ document: document,
132
+ window: window,
133
+ globalThis: globalThis,
134
+ self: self,
135
+ top: top,
136
+ };
137
+ /** 使用的配置 */
138
+ api;
139
+ constructor(option) {
140
+ if (!option) {
141
+ option = Object.assign({}, this.defaultApi);
142
+ }
143
+ this.api = Object.assign({}, option);
144
+ }
145
+ get document() {
146
+ return this.api.document;
147
+ }
148
+ get window() {
149
+ return this.api.window;
150
+ }
151
+ get globalThis() {
152
+ return this.api.globalThis;
153
+ }
154
+ get self() {
155
+ return this.api.self;
156
+ }
157
+ get top() {
158
+ return this.api.top;
159
+ }
160
+ }
161
+
159
162
  class DOMUtilsEvent {
163
+ windowApi;
164
+ constructor(windowApiOption) {
165
+ this.windowApi = new WindowApi(windowApiOption);
166
+ }
160
167
  on(element, eventType, selector, callback, option) {
161
168
  /**
162
169
  * 获取option配置
@@ -187,7 +194,7 @@
187
194
  let DOMUtilsContext = this;
188
195
  let args = arguments;
189
196
  if (typeof element === "string") {
190
- element = DOMUtilsCore.document.querySelectorAll(element);
197
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
191
198
  }
192
199
  if (element == null) {
193
200
  return;
@@ -238,7 +245,7 @@
238
245
  if (_selector_) {
239
246
  /* 存在自定义子元素选择器 */
240
247
  let totalParent = DOMUtilsCommonUtils.isWin(elementItem)
241
- ? DOMUtilsCore.document.documentElement
248
+ ? DOMUtilsContext.windowApi.document.documentElement
242
249
  : elementItem;
243
250
  if (target.matches(_selector_)) {
244
251
  /* 当前目标可以被selector所匹配到 */
@@ -302,9 +309,10 @@
302
309
  }
303
310
  return option;
304
311
  }
312
+ let DOMUtilsContext = this;
305
313
  let args = arguments;
306
314
  if (typeof element === "string") {
307
- element = DOMUtilsCore.document.querySelectorAll(element);
315
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
308
316
  }
309
317
  if (element == null) {
310
318
  return;
@@ -387,8 +395,9 @@
387
395
  * @param eventType (可选)需要取消监听的事件
388
396
  */
389
397
  offAll(element, eventType) {
398
+ let DOMUtilsContext = this;
390
399
  if (typeof element === "string") {
391
- element = DOMUtilsCore.document.querySelectorAll(element);
400
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
392
401
  }
393
402
  if (element == null) {
394
403
  return;
@@ -443,14 +452,16 @@
443
452
  if (typeof callback !== "function") {
444
453
  return;
445
454
  }
455
+ let DOMUtilsContext = this;
446
456
  /**
447
457
  * 检测文档是否加载完毕
448
458
  */
449
459
  function checkDOMReadyState() {
450
460
  try {
451
- if (DOMUtilsCore.document.readyState === "complete" ||
452
- (DOMUtilsCore.document.readyState !== "loading" &&
453
- !DOMUtilsCore.document.documentElement.doScroll)) {
461
+ if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
462
+ (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
463
+ !DOMUtilsContext.windowApi.document.documentElement
464
+ .doScroll)) {
454
465
  return true;
455
466
  }
456
467
  else {
@@ -470,12 +481,12 @@
470
481
  }
471
482
  let targetList = [
472
483
  {
473
- target: DOMUtilsCore.document,
484
+ target: DOMUtilsContext.windowApi.document,
474
485
  eventType: "DOMContentLoaded",
475
486
  callback: completed,
476
487
  },
477
488
  {
478
- target: DOMUtilsCore.window,
489
+ target: DOMUtilsContext.windowApi.window,
479
490
  eventType: "load",
480
491
  callback: completed,
481
492
  },
@@ -522,8 +533,9 @@
522
533
  * DOMUtils.trigger("a.xx",["click","tap","hover"])
523
534
  */
524
535
  trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
536
+ let DOMUtilsContext = this;
525
537
  if (typeof element === "string") {
526
- element = DOMUtilsCore.document.querySelector(element);
538
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
527
539
  }
528
540
  if (element == null) {
529
541
  return;
@@ -587,7 +599,7 @@
587
599
  click(element, handler, details, useDispatchToTriggerEvent) {
588
600
  let DOMUtilsContext = this;
589
601
  if (typeof element === "string") {
590
- element = DOMUtilsCore.document.querySelector(element);
602
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
591
603
  }
592
604
  if (element == null) {
593
605
  return;
@@ -616,7 +628,7 @@
616
628
  blur(element, handler, details, useDispatchToTriggerEvent) {
617
629
  let DOMUtilsContext = this;
618
630
  if (typeof element === "string") {
619
- element = DOMUtilsCore.document.querySelector(element);
631
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
620
632
  }
621
633
  if (element == null) {
622
634
  return;
@@ -645,7 +657,7 @@
645
657
  focus(element, handler, details, useDispatchToTriggerEvent) {
646
658
  let DOMUtilsContext = this;
647
659
  if (typeof element === "string") {
648
- element = DOMUtilsCore.document.querySelector(element);
660
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
649
661
  }
650
662
  if (element == null) {
651
663
  return;
@@ -674,7 +686,7 @@
674
686
  hover(element, handler, option) {
675
687
  let DOMUtilsContext = this;
676
688
  if (typeof element === "string") {
677
- element = DOMUtilsCore.document.querySelector(element);
689
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
678
690
  }
679
691
  if (element == null) {
680
692
  return;
@@ -703,7 +715,7 @@
703
715
  return;
704
716
  }
705
717
  if (typeof target === "string") {
706
- target = DOMUtilsCore.document.querySelector(target);
718
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
707
719
  }
708
720
  DOMUtilsContext.on(target, "keyup", null, handler, option);
709
721
  }
@@ -728,7 +740,7 @@
728
740
  return;
729
741
  }
730
742
  if (typeof target === "string") {
731
- target = DOMUtilsCore.document.querySelector(target);
743
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
732
744
  }
733
745
  DOMUtilsContext.on(target, "keydown", null, handler, option);
734
746
  }
@@ -753,22 +765,113 @@
753
765
  return;
754
766
  }
755
767
  if (typeof target === "string") {
756
- target = DOMUtilsCore.document.querySelector(target);
768
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
757
769
  }
758
770
  DOMUtilsContext.on(target, "keypress", null, handler, option);
759
771
  }
772
+ /**
773
+ * 监听某个元素键盘按键事件或window全局按键事件
774
+ * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
775
+ * @param target 需要监听的对象,可以是全局Window或者某个元素
776
+ * @param eventName 事件名,默认keypress
777
+ * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
778
+ * @param options 监听事件的配置
779
+ * @example
780
+ Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
781
+ if(keyName === "Enter"){
782
+ console.log("回车按键的值是:"+keyValue)
783
+ }
784
+ if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
785
+ console.log("Ctrl和回车键");
786
+ }
787
+ })
788
+ * @example
789
+ 字母和数字键的键码值(keyCode)
790
+ 按键 键码 按键 键码 按键 键码 按键 键码
791
+ A 65 J 74 S 83 1 49
792
+ B 66 K 75 T 84 2 50
793
+ C 67 L 76 U 85 3 51
794
+ D 68 M 77 V 86 4 52
795
+ E 69 N 78 W 87 5 53
796
+ F 70 O 79 X 88 6 54
797
+ G 71 P 80 Y 89 7 55
798
+ H 72 Q 81 Z 90 8 56
799
+ I 73 R 82 0 48 9 57
800
+
801
+ 数字键盘上的键的键码值(keyCode)
802
+ 功能键键码值(keyCode)
803
+ 按键 键码 按键 键码 按键 键码 按键 键码
804
+ 0 96 8 104 F1 112 F7 118
805
+ 1 97 9 105 F2 113 F8 119
806
+ 2 98 * 106 F3 114 F9 120
807
+ 3 99 + 107 F4 115 F10 121
808
+ 4 100 Enter 108 F5 116 F11 122
809
+ 5 101 - 109 F6 117 F12 123
810
+ 6 102 . 110
811
+ 7 103 / 111
812
+
813
+ 控制键键码值(keyCode)
814
+ 按键 键码 按键 键码 按键 键码 按键 键码
815
+ BackSpace 8 Esc 27 → 39 -_ 189
816
+ Tab 9 Spacebar 32 ↓ 40 .> 190
817
+ Clear 12 Page Up 33 Insert 45 /? 191
818
+ Enter 13 Page Down 34 Delete 46 `~ 192
819
+ Shift 16 End 35 Num Lock 144 [{ 219
820
+ Control 17 Home 36 ;: 186 \| 220
821
+ Alt 18 ← 37 =+ 187 ]} 221
822
+ Cape Lock 20 ↑ 38 ,< 188 '" 222
823
+
824
+ 多媒体键码值(keyCode)
825
+ 按键 键码
826
+ 音量加 175
827
+ 音量减 174
828
+ 停止 179
829
+ 静音 173
830
+ 浏览器 172
831
+ 邮件 180
832
+ 搜索 170
833
+ 收藏 171
834
+ **/
835
+ listenKeyboard(target, eventName = "keypress", callback, options) {
836
+ let keyboardEventCallBack = function (event) {
837
+ let keyName = event.key || event.code;
838
+ let keyValue = event.charCode || event.keyCode || event.which;
839
+ let otherCodeList = [];
840
+ if (event.ctrlKey) {
841
+ otherCodeList.push("ctrl");
842
+ }
843
+ if (event.altKey) {
844
+ otherCodeList.push("alt");
845
+ }
846
+ if (event.metaKey) {
847
+ otherCodeList.push("meta");
848
+ }
849
+ if (event.shiftKey) {
850
+ otherCodeList.push("shift");
851
+ }
852
+ if (typeof callback === "function") {
853
+ callback(keyName, keyValue.toString(), otherCodeList, event);
854
+ }
855
+ };
856
+ this.on(target, eventName, keyboardEventCallBack, options);
857
+ return {
858
+ removeListen: () => {
859
+ this.off(target, eventName, keyboardEventCallBack, options);
860
+ },
861
+ };
862
+ }
760
863
  }
761
864
 
762
865
  class DOMUtils extends DOMUtilsEvent {
763
866
  constructor(option) {
764
- DOMUtilsCore.init(option);
765
- super();
867
+ super(option);
766
868
  }
767
869
  /** 版本号 */
768
- version = "2024.6.21";
870
+ version = "2024.8.30";
769
871
  attr(element, attrName, attrValue) {
872
+ let DOMUtilsContext = this;
770
873
  if (typeof element === "string") {
771
- element = DOMUtilsCore.document.querySelector(element);
874
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
772
875
  }
773
876
  if (element == null) {
774
877
  return;
@@ -805,7 +908,8 @@
805
908
  property,
806
909
  /** 自定义属性 */
807
910
  attributes) {
808
- let tempElement = DOMUtilsCore.document.createElement(tagName);
911
+ let DOMUtilsContext = this;
912
+ let tempElement = DOMUtilsContext.windowApi.document.createElement(tagName);
809
913
  if (typeof property === "string") {
810
914
  tempElement.innerHTML = property;
811
915
  return tempElement;
@@ -835,6 +939,7 @@
835
939
  return tempElement;
836
940
  }
837
941
  css(element, property, value) {
942
+ let DOMUtilsContext = this;
838
943
  /**
839
944
  * 把纯数字没有px的加上
840
945
  */
@@ -859,7 +964,7 @@
859
964
  return propertyValue;
860
965
  }
861
966
  if (typeof element === "string") {
862
- element = DOMUtilsCore.document.querySelector(element);
967
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
863
968
  }
864
969
  if (element == null) {
865
970
  return;
@@ -892,8 +997,9 @@
892
997
  }
893
998
  }
894
999
  text(element, text) {
1000
+ let DOMUtilsContext = this;
895
1001
  if (typeof element === "string") {
896
- element = DOMUtilsCore.document.querySelector(element);
1002
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
897
1003
  }
898
1004
  if (element == null) {
899
1005
  return;
@@ -914,8 +1020,9 @@
914
1020
  }
915
1021
  }
916
1022
  html(element, html) {
1023
+ let DOMUtilsContext = this;
917
1024
  if (typeof element === "string") {
918
- element = DOMUtilsCore.document.querySelector(element);
1025
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
919
1026
  }
920
1027
  if (element == null) {
921
1028
  return;
@@ -968,8 +1075,9 @@
968
1075
  };
969
1076
  }
970
1077
  val(element, value) {
1078
+ let DOMUtilsContext = this;
971
1079
  if (typeof element === "string") {
972
- element = DOMUtilsCore.document.querySelector(element);
1080
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
973
1081
  }
974
1082
  if (element == null) {
975
1083
  return;
@@ -994,11 +1102,12 @@
994
1102
  }
995
1103
  }
996
1104
  prop(element, propName, propValue) {
1105
+ let DOMUtilsContext = this;
997
1106
  if (element == null) {
998
1107
  return;
999
1108
  }
1000
1109
  if (typeof element === "string") {
1001
- element = DOMUtilsCore.document.querySelector(element);
1110
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1002
1111
  }
1003
1112
  if (propValue == null) {
1004
1113
  return element[propName];
@@ -1017,8 +1126,9 @@
1017
1126
  * DOMUtils.removeAttr("a.xx","data-value")
1018
1127
  * */
1019
1128
  removeAttr(element, attrName) {
1129
+ let DOMUtilsContext = this;
1020
1130
  if (typeof element === "string") {
1021
- element = DOMUtilsCore.document.querySelector(element);
1131
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1022
1132
  }
1023
1133
  if (element == null) {
1024
1134
  return;
@@ -1035,8 +1145,9 @@
1035
1145
  * DOMUtils.removeClass("a.xx","xx")
1036
1146
  */
1037
1147
  removeClass(element, className) {
1148
+ let DOMUtilsContext = this;
1038
1149
  if (typeof element === "string") {
1039
- element = DOMUtilsCore.document.querySelector(element);
1150
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1040
1151
  }
1041
1152
  if (element == null) {
1042
1153
  return;
@@ -1056,8 +1167,9 @@
1056
1167
  * DOMUtils.removeProp("a.xx","href")
1057
1168
  * */
1058
1169
  removeProp(element, propName) {
1170
+ let DOMUtilsContext = this;
1059
1171
  if (typeof element === "string") {
1060
- element = DOMUtilsCore.document.querySelector(element);
1172
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1061
1173
  }
1062
1174
  if (element == null) {
1063
1175
  return;
@@ -1076,7 +1188,7 @@
1076
1188
  replaceWith(element, newElement) {
1077
1189
  let DOMUtilsContext = this;
1078
1190
  if (typeof element === "string") {
1079
- element = DOMUtilsCore.document.querySelector(element);
1191
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1080
1192
  }
1081
1193
  if (element == null) {
1082
1194
  return;
@@ -1103,8 +1215,9 @@
1103
1215
  * DOMUtils.addClass("a.xx","_vue_")
1104
1216
  * */
1105
1217
  addClass(element, className) {
1218
+ let DOMUtilsContext = this;
1106
1219
  if (typeof element === "string") {
1107
- element = DOMUtilsCore.document.querySelector(element);
1220
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1108
1221
  }
1109
1222
  if (element == null) {
1110
1223
  return;
@@ -1121,8 +1234,9 @@
1121
1234
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
1122
1235
  * */
1123
1236
  append(element, content) {
1237
+ let DOMUtilsContext = this;
1124
1238
  if (typeof element === "string") {
1125
- element = DOMUtilsCore.document.querySelector(element);
1239
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1126
1240
  }
1127
1241
  if (element == null) {
1128
1242
  return;
@@ -1137,7 +1251,7 @@
1137
1251
  }
1138
1252
  if (Array.isArray(content) || content instanceof NodeList) {
1139
1253
  /* 数组 */
1140
- let fragment = DOMUtilsCore.document.createDocumentFragment();
1254
+ let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
1141
1255
  content.forEach((ele) => {
1142
1256
  if (typeof ele === "string") {
1143
1257
  ele = this.parseHTML(ele, true, false);
@@ -1160,8 +1274,9 @@
1160
1274
  * DOMUtils.prepend("a.xx","'<b class="xx"></b>")
1161
1275
  * */
1162
1276
  prepend(element, content) {
1277
+ let DOMUtilsContext = this;
1163
1278
  if (typeof element === "string") {
1164
- element = DOMUtilsCore.document.querySelector(element);
1279
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1165
1280
  }
1166
1281
  if (element == null) {
1167
1282
  return;
@@ -1183,8 +1298,9 @@
1183
1298
  * DOMUtils.after("a.xx","'<b class="xx"></b>")
1184
1299
  * */
1185
1300
  after(element, content) {
1301
+ let DOMUtilsContext = this;
1186
1302
  if (typeof element === "string") {
1187
- element = DOMUtilsCore.document.querySelector(element);
1303
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1188
1304
  }
1189
1305
  if (element == null) {
1190
1306
  return;
@@ -1206,8 +1322,9 @@
1206
1322
  * DOMUtils.before("a.xx","'<b class="xx"></b>")
1207
1323
  * */
1208
1324
  before(element, content) {
1325
+ let DOMUtilsContext = this;
1209
1326
  if (typeof element === "string") {
1210
- element = DOMUtilsCore.document.querySelector(element);
1327
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1211
1328
  }
1212
1329
  if (element == null) {
1213
1330
  return;
@@ -1231,7 +1348,7 @@
1231
1348
  remove(target) {
1232
1349
  let DOMUtilsContext = this;
1233
1350
  if (typeof target === "string") {
1234
- target = DOMUtilsCore.document.querySelectorAll(target);
1351
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1235
1352
  }
1236
1353
  if (target == null) {
1237
1354
  return;
@@ -1255,8 +1372,9 @@
1255
1372
  * DOMUtils.empty("a.xx")
1256
1373
  * */
1257
1374
  empty(element) {
1375
+ let DOMUtilsContext = this;
1258
1376
  if (typeof element === "string") {
1259
- element = DOMUtilsCore.document.querySelector(element);
1377
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1260
1378
  }
1261
1379
  if (element == null) {
1262
1380
  return;
@@ -1273,8 +1391,9 @@
1273
1391
  * > 0
1274
1392
  */
1275
1393
  offset(element) {
1394
+ let DOMUtilsContext = this;
1276
1395
  if (typeof element === "string") {
1277
- element = DOMUtilsCore.document.querySelector(element);
1396
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1278
1397
  }
1279
1398
  if (element == null) {
1280
1399
  return;
@@ -1282,21 +1401,22 @@
1282
1401
  let rect = element.getBoundingClientRect();
1283
1402
  return {
1284
1403
  /** y轴偏移 */
1285
- top: rect.top + DOMUtilsCore.globalThis.scrollY,
1404
+ top: rect.top + DOMUtilsContext.windowApi.globalThis.scrollY,
1286
1405
  /** x轴偏移 */
1287
- left: rect.left + DOMUtilsCore.globalThis.scrollX,
1406
+ left: rect.left + DOMUtilsContext.windowApi.globalThis.scrollX,
1288
1407
  };
1289
1408
  }
1290
1409
  width(element, isShow = false) {
1291
1410
  let DOMUtilsContext = this;
1292
1411
  if (typeof element === "string") {
1293
- element = DOMUtilsCore.document.querySelector(element);
1412
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1294
1413
  }
1295
1414
  if (element == null) {
1296
1415
  return;
1297
1416
  }
1298
1417
  if (DOMUtilsCommonUtils.isWin(element)) {
1299
- return DOMUtilsCore.window.document.documentElement.clientWidth;
1418
+ return DOMUtilsContext.windowApi.window.document.documentElement
1419
+ .clientWidth;
1300
1420
  }
1301
1421
  if (element.nodeType === 9) {
1302
1422
  /* Document文档节点 */
@@ -1339,10 +1459,11 @@
1339
1459
  height(element, isShow = false) {
1340
1460
  let DOMUtilsContext = this;
1341
1461
  if (DOMUtilsCommonUtils.isWin(element)) {
1342
- return DOMUtilsCore.window.document.documentElement.clientHeight;
1462
+ return DOMUtilsContext.windowApi.window.document.documentElement
1463
+ .clientHeight;
1343
1464
  }
1344
1465
  if (typeof element === "string") {
1345
- element = DOMUtilsCore.document.querySelector(element);
1466
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1346
1467
  }
1347
1468
  if (element == null) {
1348
1469
  // @ts-ignore
@@ -1389,10 +1510,10 @@
1389
1510
  outerWidth(element, isShow = false) {
1390
1511
  let DOMUtilsContext = this;
1391
1512
  if (DOMUtilsCommonUtils.isWin(element)) {
1392
- return DOMUtilsCore.window.innerWidth;
1513
+ return DOMUtilsContext.windowApi.window.innerWidth;
1393
1514
  }
1394
1515
  if (typeof element === "string") {
1395
- element = DOMUtilsCore.document.querySelector(element);
1516
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1396
1517
  }
1397
1518
  if (element == null) {
1398
1519
  // @ts-ignore
@@ -1415,10 +1536,10 @@
1415
1536
  outerHeight(element, isShow = false) {
1416
1537
  let DOMUtilsContext = this;
1417
1538
  if (DOMUtilsCommonUtils.isWin(element)) {
1418
- return DOMUtilsCore.window.innerHeight;
1539
+ return DOMUtilsContext.windowApi.window.innerHeight;
1419
1540
  }
1420
1541
  if (typeof element === "string") {
1421
- element = DOMUtilsCore.document.querySelector(element);
1542
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1422
1543
  }
1423
1544
  if (element == null) {
1424
1545
  // @ts-ignore
@@ -1451,8 +1572,9 @@
1451
1572
  * })
1452
1573
  */
1453
1574
  animate(element, styles, duration = 1000, callback = null) {
1575
+ let DOMUtilsContext = this;
1454
1576
  if (typeof element === "string") {
1455
- element = DOMUtilsCore.document.querySelector(element);
1577
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1456
1578
  }
1457
1579
  if (element == null) {
1458
1580
  return;
@@ -1503,15 +1625,16 @@
1503
1625
  * DOMUtils.wrap(document.querySelector("a.xx"),"<div></div>")
1504
1626
  */
1505
1627
  wrap(element, wrapperHTML) {
1628
+ let DOMUtilsContext = this;
1506
1629
  if (typeof element === "string") {
1507
- element = DOMUtilsCore.document.querySelector(element);
1630
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1508
1631
  }
1509
1632
  if (element == null) {
1510
1633
  return;
1511
1634
  }
1512
1635
  element = element;
1513
1636
  // 创建一个新的div元素,并将wrapperHTML作为其innerHTML
1514
- let wrapper = DOMUtilsCore.document.createElement("div");
1637
+ let wrapper = DOMUtilsContext.windowApi.document.createElement("div");
1515
1638
  wrapper.innerHTML = wrapperHTML;
1516
1639
  let wrapperFirstChild = wrapper.firstChild;
1517
1640
  // 将要包裹的元素插入目标元素前面
@@ -1520,8 +1643,9 @@
1520
1643
  wrapperFirstChild.appendChild(element);
1521
1644
  }
1522
1645
  prev(element) {
1646
+ let DOMUtilsContext = this;
1523
1647
  if (typeof element === "string") {
1524
- element = DOMUtilsCore.document.querySelector(element);
1648
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1525
1649
  }
1526
1650
  if (element == null) {
1527
1651
  return;
@@ -1529,8 +1653,9 @@
1529
1653
  return element.previousElementSibling;
1530
1654
  }
1531
1655
  next(element) {
1656
+ let DOMUtilsContext = this;
1532
1657
  if (typeof element === "string") {
1533
- element = DOMUtilsCore.document.querySelector(element);
1658
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1534
1659
  }
1535
1660
  if (element == null) {
1536
1661
  return;
@@ -1543,15 +1668,17 @@
1543
1668
  * let DOMUtils = window.DOMUtils.noConflict()
1544
1669
  */
1545
1670
  noConflict() {
1546
- if (DOMUtilsCore.window.DOMUtils) {
1671
+ let DOMUtilsContext = this;
1672
+ if (DOMUtilsContext.windowApi.window.DOMUtils) {
1547
1673
  DOMUtilsCommonUtils.delete(window, "DOMUtils");
1548
1674
  }
1549
- DOMUtilsCore.window.DOMUtils = this;
1675
+ DOMUtilsContext.windowApi.window.DOMUtils = this;
1550
1676
  return this;
1551
1677
  }
1552
1678
  siblings(element) {
1679
+ let DOMUtilsContext = this;
1553
1680
  if (typeof element === "string") {
1554
- element = DOMUtilsCore.document.querySelector(element);
1681
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1555
1682
  }
1556
1683
  if (element == null) {
1557
1684
  return;
@@ -1572,7 +1699,7 @@
1572
1699
  parent(element) {
1573
1700
  let DOMUtilsContext = this;
1574
1701
  if (typeof element === "string") {
1575
- element = DOMUtilsCore.document.querySelector(element);
1702
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1576
1703
  }
1577
1704
  if (element == null) {
1578
1705
  return;
@@ -1590,6 +1717,7 @@
1590
1717
  }
1591
1718
  }
1592
1719
  parseHTML(html, useParser = false, isComplete = false) {
1720
+ let DOMUtilsContext = this;
1593
1721
  function parseHTMLByDOMParser() {
1594
1722
  let parser = new DOMParser();
1595
1723
  if (isComplete) {
@@ -1600,7 +1728,7 @@
1600
1728
  }
1601
1729
  }
1602
1730
  function parseHTMLByCreateDom() {
1603
- let tempDIV = DOMUtilsCore.document.createElement("div");
1731
+ let tempDIV = DOMUtilsContext.windowApi.document.createElement("div");
1604
1732
  tempDIV.innerHTML = html;
1605
1733
  if (isComplete) {
1606
1734
  return tempDIV;
@@ -1631,7 +1759,7 @@
1631
1759
  return;
1632
1760
  }
1633
1761
  if (typeof target === "string") {
1634
- target = DOMUtilsCore.document.querySelectorAll(target);
1762
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1635
1763
  }
1636
1764
  if (target instanceof NodeList || target instanceof Array) {
1637
1765
  target = target;
@@ -1663,7 +1791,7 @@
1663
1791
  return;
1664
1792
  }
1665
1793
  if (typeof target === "string") {
1666
- target = DOMUtilsCore.document.querySelectorAll(target);
1794
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1667
1795
  }
1668
1796
  if (target instanceof NodeList || target instanceof Array) {
1669
1797
  target = target;
@@ -1698,8 +1826,9 @@
1698
1826
  if (element == null) {
1699
1827
  return;
1700
1828
  }
1829
+ let DOMUtilsContext = this;
1701
1830
  if (typeof element === "string") {
1702
- element = DOMUtilsCore.document.querySelector(element);
1831
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1703
1832
  }
1704
1833
  element = element;
1705
1834
  element.style.opacity = "0";
@@ -1713,16 +1842,16 @@
1713
1842
  element = element;
1714
1843
  element.style.opacity = Math.min(progress / duration, 1).toString();
1715
1844
  if (progress < duration) {
1716
- DOMUtilsCore.window.requestAnimationFrame(step);
1845
+ DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1717
1846
  }
1718
1847
  else {
1719
1848
  if (callback && typeof callback === "function") {
1720
1849
  callback();
1721
1850
  }
1722
- DOMUtilsCore.window.cancelAnimationFrame(timer);
1851
+ DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
1723
1852
  }
1724
1853
  }
1725
- timer = DOMUtilsCore.window.requestAnimationFrame(step);
1854
+ timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1726
1855
  }
1727
1856
  /**
1728
1857
  * 淡出元素
@@ -1739,11 +1868,12 @@
1739
1868
  * })
1740
1869
  */
1741
1870
  fadeOut(element, duration = 400, callback) {
1871
+ let DOMUtilsContext = this;
1742
1872
  if (element == null) {
1743
1873
  return;
1744
1874
  }
1745
1875
  if (typeof element === "string") {
1746
- element = DOMUtilsCore.document.querySelector(element);
1876
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1747
1877
  }
1748
1878
  element = element;
1749
1879
  element.style.opacity = "1";
@@ -1756,17 +1886,17 @@
1756
1886
  element = element;
1757
1887
  element.style.opacity = Math.max(1 - progress / duration, 0).toString();
1758
1888
  if (progress < duration) {
1759
- DOMUtilsCore.window.requestAnimationFrame(step);
1889
+ DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1760
1890
  }
1761
1891
  else {
1762
1892
  element.style.display = "none";
1763
1893
  if (typeof callback === "function") {
1764
1894
  callback();
1765
1895
  }
1766
- DOMUtilsCore.window.cancelAnimationFrame(timer);
1896
+ DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
1767
1897
  }
1768
1898
  }
1769
- timer = DOMUtilsCore.window.requestAnimationFrame(step);
1899
+ timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1770
1900
  }
1771
1901
  /**
1772
1902
  * 切换元素的显示和隐藏状态
@@ -1779,7 +1909,7 @@
1779
1909
  toggle(element) {
1780
1910
  let DOMUtilsContext = this;
1781
1911
  if (typeof element === "string") {
1782
- element = DOMUtilsCore.document.querySelector(element);
1912
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1783
1913
  }
1784
1914
  if (element == null) {
1785
1915
  return;
@@ -1808,6 +1938,7 @@
1808
1938
  * DOMUtils.getTextBoundingRect(document.querySelector("input"));
1809
1939
  */
1810
1940
  getTextBoundingRect($input, selectionStart, selectionEnd) {
1941
+ let DOMUtilsContext = this;
1811
1942
  // Basic parameter validation
1812
1943
  if (!$input || !("value" in $input))
1813
1944
  return $input;
@@ -1877,7 +2008,7 @@
1877
2008
  }
1878
2009
  // End of CSS variable checks
1879
2010
  // 不能为空,不然获取不到高度
1880
- let text = $input.value || "G", textLen = text.length, fakeClone = DOMUtilsCore.document.createElement("div");
2011
+ let text = $input.value || "G", textLen = text.length, fakeClone = DOMUtilsContext.windowApi.document.createElement("div");
1881
2012
  if (selectionStart > 0)
1882
2013
  appendPart(0, selectionStart);
1883
2014
  var fakeRange = appendPart(selectionStart, selectionEnd);
@@ -1891,7 +2022,7 @@
1891
2022
  fakeClone.style.left = leftPos + "px";
1892
2023
  fakeClone.style.width = width + "px";
1893
2024
  fakeClone.style.height = height + "px";
1894
- DOMUtilsCore.document.body.appendChild(fakeClone);
2025
+ DOMUtilsContext.windowApi.document.body.appendChild(fakeClone);
1895
2026
  var returnValue = fakeRange.getBoundingClientRect(); //Get rect
1896
2027
  fakeClone?.parentNode?.removeChild(fakeClone); //Remove temp
1897
2028
  return returnValue;
@@ -1903,7 +2034,7 @@
1903
2034
  * @returns
1904
2035
  */
1905
2036
  function appendPart(start, end) {
1906
- var span = DOMUtilsCore.document.createElement("span");
2037
+ var span = DOMUtilsContext.windowApi.document.createElement("span");
1907
2038
  span.style.cssText = cssDefaultStyles; //Force styles to prevent unexpected results
1908
2039
  span.textContent = text.substring(start, end);
1909
2040
  fakeClone.appendChild(span);
@@ -1911,7 +2042,7 @@
1911
2042
  }
1912
2043
  // Computing offset position
1913
2044
  function getInputOffset() {
1914
- let body = DOMUtilsCore.document.body, win = DOMUtilsCore.document.defaultView, docElem = DOMUtilsCore.document.documentElement, $box = DOMUtilsCore.document.createElement("div");
2045
+ let body = DOMUtilsContext.windowApi.document.body, win = DOMUtilsContext.windowApi.document.defaultView, docElem = DOMUtilsContext.windowApi.document.documentElement, $box = DOMUtilsContext.windowApi.document.createElement("div");
1915
2046
  $box.style.paddingLeft = $box.style.width = "1px";
1916
2047
  body.appendChild($box);
1917
2048
  var isBoxModel = $box.offsetWidth == 2;
@@ -1934,7 +2065,7 @@
1934
2065
  * @returns
1935
2066
  */
1936
2067
  function getInputCSS(prop, isNumber) {
1937
- var val = DOMUtilsCore.document
2068
+ var val = DOMUtilsContext.windowApi.document
1938
2069
  .defaultView.getComputedStyle($input, null)
1939
2070
  .getPropertyValue(prop);
1940
2071
  return isNumber ? parseFloat(val) : val;