@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.amd.js CHANGED
@@ -1,42 +1,11 @@
1
1
  define((function () { 'use strict';
2
2
 
3
- const DOMUtilsCoreDefaultEnv = {
4
- document: document,
5
- window: window,
6
- globalThis: globalThis,
7
- self: self,
8
- top: top,
9
- };
10
- const DOMUtilsCoreEnv = {
11
- document: document,
12
- window: window,
13
- globalThis: globalThis,
14
- self: self,
15
- top: top,
16
- };
17
- const DOMUtilsCore = {
18
- init(option) {
19
- if (!option) {
20
- option = Object.assign({}, DOMUtilsCoreDefaultEnv);
21
- }
22
- Object.assign(DOMUtilsCoreEnv, option);
23
- },
24
- get document() {
25
- return DOMUtilsCoreEnv.document;
26
- },
27
- get window() {
28
- return DOMUtilsCoreEnv.window;
29
- },
30
- get globalThis() {
31
- return DOMUtilsCoreEnv.globalThis;
32
- },
33
- get self() {
34
- return DOMUtilsCoreEnv.self;
35
- },
36
- };
37
-
38
3
  /** 通用工具类 */
39
4
  const DOMUtilsCommonUtils = {
5
+ windowApi: {
6
+ window: window,
7
+ document: document,
8
+ },
40
9
  /**
41
10
  * 判断元素是否已显示或已连接
42
11
  * @param element
@@ -51,7 +20,7 @@ define((function () { 'use strict';
51
20
  showElement(element) {
52
21
  let dupNode = element.cloneNode(true);
53
22
  dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
54
- DOMUtilsCore.document.documentElement.appendChild(dupNode);
23
+ this.windowApi.document.documentElement.appendChild(dupNode);
55
24
  return {
56
25
  /**
57
26
  * 恢复修改的style
@@ -108,13 +77,13 @@ define((function () { 'use strict';
108
77
  if (target === self) {
109
78
  return true;
110
79
  }
111
- if (target === DOMUtilsCore.globalThis) {
80
+ if (target === globalThis) {
112
81
  return true;
113
82
  }
114
- if (target === DOMUtilsCore.window) {
83
+ if (target === window) {
115
84
  return true;
116
85
  }
117
- if (target === DOMUtilsCore.self) {
86
+ if (target === self) {
118
87
  return true;
119
88
  }
120
89
  if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
@@ -152,7 +121,45 @@ define((function () { 'use strict';
152
121
  },
153
122
  };
154
123
 
124
+ class WindowApi {
125
+ /** 默认的配置 */
126
+ defaultApi = {
127
+ document: document,
128
+ window: window,
129
+ globalThis: globalThis,
130
+ self: self,
131
+ top: top,
132
+ };
133
+ /** 使用的配置 */
134
+ api;
135
+ constructor(option) {
136
+ if (!option) {
137
+ option = Object.assign({}, this.defaultApi);
138
+ }
139
+ this.api = Object.assign({}, option);
140
+ }
141
+ get document() {
142
+ return this.api.document;
143
+ }
144
+ get window() {
145
+ return this.api.window;
146
+ }
147
+ get globalThis() {
148
+ return this.api.globalThis;
149
+ }
150
+ get self() {
151
+ return this.api.self;
152
+ }
153
+ get top() {
154
+ return this.api.top;
155
+ }
156
+ }
157
+
155
158
  class DOMUtilsEvent {
159
+ windowApi;
160
+ constructor(windowApiOption) {
161
+ this.windowApi = new WindowApi(windowApiOption);
162
+ }
156
163
  on(element, eventType, selector, callback, option) {
157
164
  /**
158
165
  * 获取option配置
@@ -183,7 +190,7 @@ define((function () { 'use strict';
183
190
  let DOMUtilsContext = this;
184
191
  let args = arguments;
185
192
  if (typeof element === "string") {
186
- element = DOMUtilsCore.document.querySelectorAll(element);
193
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
187
194
  }
188
195
  if (element == null) {
189
196
  return;
@@ -234,7 +241,7 @@ define((function () { 'use strict';
234
241
  if (_selector_) {
235
242
  /* 存在自定义子元素选择器 */
236
243
  let totalParent = DOMUtilsCommonUtils.isWin(elementItem)
237
- ? DOMUtilsCore.document.documentElement
244
+ ? DOMUtilsContext.windowApi.document.documentElement
238
245
  : elementItem;
239
246
  if (target.matches(_selector_)) {
240
247
  /* 当前目标可以被selector所匹配到 */
@@ -298,9 +305,10 @@ define((function () { 'use strict';
298
305
  }
299
306
  return option;
300
307
  }
308
+ let DOMUtilsContext = this;
301
309
  let args = arguments;
302
310
  if (typeof element === "string") {
303
- element = DOMUtilsCore.document.querySelectorAll(element);
311
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
304
312
  }
305
313
  if (element == null) {
306
314
  return;
@@ -383,8 +391,9 @@ define((function () { 'use strict';
383
391
  * @param eventType (可选)需要取消监听的事件
384
392
  */
385
393
  offAll(element, eventType) {
394
+ let DOMUtilsContext = this;
386
395
  if (typeof element === "string") {
387
- element = DOMUtilsCore.document.querySelectorAll(element);
396
+ element = DOMUtilsContext.windowApi.document.querySelectorAll(element);
388
397
  }
389
398
  if (element == null) {
390
399
  return;
@@ -439,14 +448,16 @@ define((function () { 'use strict';
439
448
  if (typeof callback !== "function") {
440
449
  return;
441
450
  }
451
+ let DOMUtilsContext = this;
442
452
  /**
443
453
  * 检测文档是否加载完毕
444
454
  */
445
455
  function checkDOMReadyState() {
446
456
  try {
447
- if (DOMUtilsCore.document.readyState === "complete" ||
448
- (DOMUtilsCore.document.readyState !== "loading" &&
449
- !DOMUtilsCore.document.documentElement.doScroll)) {
457
+ if (DOMUtilsContext.windowApi.document.readyState === "complete" ||
458
+ (DOMUtilsContext.windowApi.document.readyState !== "loading" &&
459
+ !DOMUtilsContext.windowApi.document.documentElement
460
+ .doScroll)) {
450
461
  return true;
451
462
  }
452
463
  else {
@@ -466,12 +477,12 @@ define((function () { 'use strict';
466
477
  }
467
478
  let targetList = [
468
479
  {
469
- target: DOMUtilsCore.document,
480
+ target: DOMUtilsContext.windowApi.document,
470
481
  eventType: "DOMContentLoaded",
471
482
  callback: completed,
472
483
  },
473
484
  {
474
- target: DOMUtilsCore.window,
485
+ target: DOMUtilsContext.windowApi.window,
475
486
  eventType: "load",
476
487
  callback: completed,
477
488
  },
@@ -518,8 +529,9 @@ define((function () { 'use strict';
518
529
  * DOMUtils.trigger("a.xx",["click","tap","hover"])
519
530
  */
520
531
  trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
532
+ let DOMUtilsContext = this;
521
533
  if (typeof element === "string") {
522
- element = DOMUtilsCore.document.querySelector(element);
534
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
523
535
  }
524
536
  if (element == null) {
525
537
  return;
@@ -583,7 +595,7 @@ define((function () { 'use strict';
583
595
  click(element, handler, details, useDispatchToTriggerEvent) {
584
596
  let DOMUtilsContext = this;
585
597
  if (typeof element === "string") {
586
- element = DOMUtilsCore.document.querySelector(element);
598
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
587
599
  }
588
600
  if (element == null) {
589
601
  return;
@@ -612,7 +624,7 @@ define((function () { 'use strict';
612
624
  blur(element, handler, details, useDispatchToTriggerEvent) {
613
625
  let DOMUtilsContext = this;
614
626
  if (typeof element === "string") {
615
- element = DOMUtilsCore.document.querySelector(element);
627
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
616
628
  }
617
629
  if (element == null) {
618
630
  return;
@@ -641,7 +653,7 @@ define((function () { 'use strict';
641
653
  focus(element, handler, details, useDispatchToTriggerEvent) {
642
654
  let DOMUtilsContext = this;
643
655
  if (typeof element === "string") {
644
- element = DOMUtilsCore.document.querySelector(element);
656
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
645
657
  }
646
658
  if (element == null) {
647
659
  return;
@@ -670,7 +682,7 @@ define((function () { 'use strict';
670
682
  hover(element, handler, option) {
671
683
  let DOMUtilsContext = this;
672
684
  if (typeof element === "string") {
673
- element = DOMUtilsCore.document.querySelector(element);
685
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
674
686
  }
675
687
  if (element == null) {
676
688
  return;
@@ -699,7 +711,7 @@ define((function () { 'use strict';
699
711
  return;
700
712
  }
701
713
  if (typeof target === "string") {
702
- target = DOMUtilsCore.document.querySelector(target);
714
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
703
715
  }
704
716
  DOMUtilsContext.on(target, "keyup", null, handler, option);
705
717
  }
@@ -724,7 +736,7 @@ define((function () { 'use strict';
724
736
  return;
725
737
  }
726
738
  if (typeof target === "string") {
727
- target = DOMUtilsCore.document.querySelector(target);
739
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
728
740
  }
729
741
  DOMUtilsContext.on(target, "keydown", null, handler, option);
730
742
  }
@@ -749,22 +761,113 @@ define((function () { 'use strict';
749
761
  return;
750
762
  }
751
763
  if (typeof target === "string") {
752
- target = DOMUtilsCore.document.querySelector(target);
764
+ target = DOMUtilsContext.windowApi.document.querySelector(target);
753
765
  }
754
766
  DOMUtilsContext.on(target, "keypress", null, handler, option);
755
767
  }
768
+ /**
769
+ * 监听某个元素键盘按键事件或window全局按键事件
770
+ * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
771
+ * @param target 需要监听的对象,可以是全局Window或者某个元素
772
+ * @param eventName 事件名,默认keypress
773
+ * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
774
+ * @param options 监听事件的配置
775
+ * @example
776
+ Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
777
+ if(keyName === "Enter"){
778
+ console.log("回车按键的值是:"+keyValue)
779
+ }
780
+ if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
781
+ console.log("Ctrl和回车键");
782
+ }
783
+ })
784
+ * @example
785
+ 字母和数字键的键码值(keyCode)
786
+ 按键 键码 按键 键码 按键 键码 按键 键码
787
+ A 65 J 74 S 83 1 49
788
+ B 66 K 75 T 84 2 50
789
+ C 67 L 76 U 85 3 51
790
+ D 68 M 77 V 86 4 52
791
+ E 69 N 78 W 87 5 53
792
+ F 70 O 79 X 88 6 54
793
+ G 71 P 80 Y 89 7 55
794
+ H 72 Q 81 Z 90 8 56
795
+ I 73 R 82 0 48 9 57
796
+
797
+ 数字键盘上的键的键码值(keyCode)
798
+ 功能键键码值(keyCode)
799
+ 按键 键码 按键 键码 按键 键码 按键 键码
800
+ 0 96 8 104 F1 112 F7 118
801
+ 1 97 9 105 F2 113 F8 119
802
+ 2 98 * 106 F3 114 F9 120
803
+ 3 99 + 107 F4 115 F10 121
804
+ 4 100 Enter 108 F5 116 F11 122
805
+ 5 101 - 109 F6 117 F12 123
806
+ 6 102 . 110
807
+ 7 103 / 111
808
+
809
+ 控制键键码值(keyCode)
810
+ 按键 键码 按键 键码 按键 键码 按键 键码
811
+ BackSpace 8 Esc 27 → 39 -_ 189
812
+ Tab 9 Spacebar 32 ↓ 40 .> 190
813
+ Clear 12 Page Up 33 Insert 45 /? 191
814
+ Enter 13 Page Down 34 Delete 46 `~ 192
815
+ Shift 16 End 35 Num Lock 144 [{ 219
816
+ Control 17 Home 36 ;: 186 \| 220
817
+ Alt 18 ← 37 =+ 187 ]} 221
818
+ Cape Lock 20 ↑ 38 ,< 188 '" 222
819
+
820
+ 多媒体键码值(keyCode)
821
+ 按键 键码
822
+ 音量加 175
823
+ 音量减 174
824
+ 停止 179
825
+ 静音 173
826
+ 浏览器 172
827
+ 邮件 180
828
+ 搜索 170
829
+ 收藏 171
830
+ **/
831
+ listenKeyboard(target, eventName = "keypress", callback, options) {
832
+ let keyboardEventCallBack = function (event) {
833
+ let keyName = event.key || event.code;
834
+ let keyValue = event.charCode || event.keyCode || event.which;
835
+ let otherCodeList = [];
836
+ if (event.ctrlKey) {
837
+ otherCodeList.push("ctrl");
838
+ }
839
+ if (event.altKey) {
840
+ otherCodeList.push("alt");
841
+ }
842
+ if (event.metaKey) {
843
+ otherCodeList.push("meta");
844
+ }
845
+ if (event.shiftKey) {
846
+ otherCodeList.push("shift");
847
+ }
848
+ if (typeof callback === "function") {
849
+ callback(keyName, keyValue.toString(), otherCodeList, event);
850
+ }
851
+ };
852
+ this.on(target, eventName, keyboardEventCallBack, options);
853
+ return {
854
+ removeListen: () => {
855
+ this.off(target, eventName, keyboardEventCallBack, options);
856
+ },
857
+ };
858
+ }
756
859
  }
757
860
 
758
861
  class DOMUtils extends DOMUtilsEvent {
759
862
  constructor(option) {
760
- DOMUtilsCore.init(option);
761
- super();
863
+ super(option);
762
864
  }
763
865
  /** 版本号 */
764
- version = "2024.6.21";
866
+ version = "2024.8.30";
765
867
  attr(element, attrName, attrValue) {
868
+ let DOMUtilsContext = this;
766
869
  if (typeof element === "string") {
767
- element = DOMUtilsCore.document.querySelector(element);
870
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
768
871
  }
769
872
  if (element == null) {
770
873
  return;
@@ -801,7 +904,8 @@ define((function () { 'use strict';
801
904
  property,
802
905
  /** 自定义属性 */
803
906
  attributes) {
804
- let tempElement = DOMUtilsCore.document.createElement(tagName);
907
+ let DOMUtilsContext = this;
908
+ let tempElement = DOMUtilsContext.windowApi.document.createElement(tagName);
805
909
  if (typeof property === "string") {
806
910
  tempElement.innerHTML = property;
807
911
  return tempElement;
@@ -831,6 +935,7 @@ define((function () { 'use strict';
831
935
  return tempElement;
832
936
  }
833
937
  css(element, property, value) {
938
+ let DOMUtilsContext = this;
834
939
  /**
835
940
  * 把纯数字没有px的加上
836
941
  */
@@ -855,7 +960,7 @@ define((function () { 'use strict';
855
960
  return propertyValue;
856
961
  }
857
962
  if (typeof element === "string") {
858
- element = DOMUtilsCore.document.querySelector(element);
963
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
859
964
  }
860
965
  if (element == null) {
861
966
  return;
@@ -888,8 +993,9 @@ define((function () { 'use strict';
888
993
  }
889
994
  }
890
995
  text(element, text) {
996
+ let DOMUtilsContext = this;
891
997
  if (typeof element === "string") {
892
- element = DOMUtilsCore.document.querySelector(element);
998
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
893
999
  }
894
1000
  if (element == null) {
895
1001
  return;
@@ -910,8 +1016,9 @@ define((function () { 'use strict';
910
1016
  }
911
1017
  }
912
1018
  html(element, html) {
1019
+ let DOMUtilsContext = this;
913
1020
  if (typeof element === "string") {
914
- element = DOMUtilsCore.document.querySelector(element);
1021
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
915
1022
  }
916
1023
  if (element == null) {
917
1024
  return;
@@ -964,8 +1071,9 @@ define((function () { 'use strict';
964
1071
  };
965
1072
  }
966
1073
  val(element, value) {
1074
+ let DOMUtilsContext = this;
967
1075
  if (typeof element === "string") {
968
- element = DOMUtilsCore.document.querySelector(element);
1076
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
969
1077
  }
970
1078
  if (element == null) {
971
1079
  return;
@@ -990,11 +1098,12 @@ define((function () { 'use strict';
990
1098
  }
991
1099
  }
992
1100
  prop(element, propName, propValue) {
1101
+ let DOMUtilsContext = this;
993
1102
  if (element == null) {
994
1103
  return;
995
1104
  }
996
1105
  if (typeof element === "string") {
997
- element = DOMUtilsCore.document.querySelector(element);
1106
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
998
1107
  }
999
1108
  if (propValue == null) {
1000
1109
  return element[propName];
@@ -1013,8 +1122,9 @@ define((function () { 'use strict';
1013
1122
  * DOMUtils.removeAttr("a.xx","data-value")
1014
1123
  * */
1015
1124
  removeAttr(element, attrName) {
1125
+ let DOMUtilsContext = this;
1016
1126
  if (typeof element === "string") {
1017
- element = DOMUtilsCore.document.querySelector(element);
1127
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1018
1128
  }
1019
1129
  if (element == null) {
1020
1130
  return;
@@ -1031,8 +1141,9 @@ define((function () { 'use strict';
1031
1141
  * DOMUtils.removeClass("a.xx","xx")
1032
1142
  */
1033
1143
  removeClass(element, className) {
1144
+ let DOMUtilsContext = this;
1034
1145
  if (typeof element === "string") {
1035
- element = DOMUtilsCore.document.querySelector(element);
1146
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1036
1147
  }
1037
1148
  if (element == null) {
1038
1149
  return;
@@ -1052,8 +1163,9 @@ define((function () { 'use strict';
1052
1163
  * DOMUtils.removeProp("a.xx","href")
1053
1164
  * */
1054
1165
  removeProp(element, propName) {
1166
+ let DOMUtilsContext = this;
1055
1167
  if (typeof element === "string") {
1056
- element = DOMUtilsCore.document.querySelector(element);
1168
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1057
1169
  }
1058
1170
  if (element == null) {
1059
1171
  return;
@@ -1072,7 +1184,7 @@ define((function () { 'use strict';
1072
1184
  replaceWith(element, newElement) {
1073
1185
  let DOMUtilsContext = this;
1074
1186
  if (typeof element === "string") {
1075
- element = DOMUtilsCore.document.querySelector(element);
1187
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1076
1188
  }
1077
1189
  if (element == null) {
1078
1190
  return;
@@ -1099,8 +1211,9 @@ define((function () { 'use strict';
1099
1211
  * DOMUtils.addClass("a.xx","_vue_")
1100
1212
  * */
1101
1213
  addClass(element, className) {
1214
+ let DOMUtilsContext = this;
1102
1215
  if (typeof element === "string") {
1103
- element = DOMUtilsCore.document.querySelector(element);
1216
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1104
1217
  }
1105
1218
  if (element == null) {
1106
1219
  return;
@@ -1117,8 +1230,9 @@ define((function () { 'use strict';
1117
1230
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
1118
1231
  * */
1119
1232
  append(element, content) {
1233
+ let DOMUtilsContext = this;
1120
1234
  if (typeof element === "string") {
1121
- element = DOMUtilsCore.document.querySelector(element);
1235
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1122
1236
  }
1123
1237
  if (element == null) {
1124
1238
  return;
@@ -1133,7 +1247,7 @@ define((function () { 'use strict';
1133
1247
  }
1134
1248
  if (Array.isArray(content) || content instanceof NodeList) {
1135
1249
  /* 数组 */
1136
- let fragment = DOMUtilsCore.document.createDocumentFragment();
1250
+ let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
1137
1251
  content.forEach((ele) => {
1138
1252
  if (typeof ele === "string") {
1139
1253
  ele = this.parseHTML(ele, true, false);
@@ -1156,8 +1270,9 @@ define((function () { 'use strict';
1156
1270
  * DOMUtils.prepend("a.xx","'<b class="xx"></b>")
1157
1271
  * */
1158
1272
  prepend(element, content) {
1273
+ let DOMUtilsContext = this;
1159
1274
  if (typeof element === "string") {
1160
- element = DOMUtilsCore.document.querySelector(element);
1275
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1161
1276
  }
1162
1277
  if (element == null) {
1163
1278
  return;
@@ -1179,8 +1294,9 @@ define((function () { 'use strict';
1179
1294
  * DOMUtils.after("a.xx","'<b class="xx"></b>")
1180
1295
  * */
1181
1296
  after(element, content) {
1297
+ let DOMUtilsContext = this;
1182
1298
  if (typeof element === "string") {
1183
- element = DOMUtilsCore.document.querySelector(element);
1299
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1184
1300
  }
1185
1301
  if (element == null) {
1186
1302
  return;
@@ -1202,8 +1318,9 @@ define((function () { 'use strict';
1202
1318
  * DOMUtils.before("a.xx","'<b class="xx"></b>")
1203
1319
  * */
1204
1320
  before(element, content) {
1321
+ let DOMUtilsContext = this;
1205
1322
  if (typeof element === "string") {
1206
- element = DOMUtilsCore.document.querySelector(element);
1323
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1207
1324
  }
1208
1325
  if (element == null) {
1209
1326
  return;
@@ -1227,7 +1344,7 @@ define((function () { 'use strict';
1227
1344
  remove(target) {
1228
1345
  let DOMUtilsContext = this;
1229
1346
  if (typeof target === "string") {
1230
- target = DOMUtilsCore.document.querySelectorAll(target);
1347
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1231
1348
  }
1232
1349
  if (target == null) {
1233
1350
  return;
@@ -1251,8 +1368,9 @@ define((function () { 'use strict';
1251
1368
  * DOMUtils.empty("a.xx")
1252
1369
  * */
1253
1370
  empty(element) {
1371
+ let DOMUtilsContext = this;
1254
1372
  if (typeof element === "string") {
1255
- element = DOMUtilsCore.document.querySelector(element);
1373
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1256
1374
  }
1257
1375
  if (element == null) {
1258
1376
  return;
@@ -1269,8 +1387,9 @@ define((function () { 'use strict';
1269
1387
  * > 0
1270
1388
  */
1271
1389
  offset(element) {
1390
+ let DOMUtilsContext = this;
1272
1391
  if (typeof element === "string") {
1273
- element = DOMUtilsCore.document.querySelector(element);
1392
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1274
1393
  }
1275
1394
  if (element == null) {
1276
1395
  return;
@@ -1278,21 +1397,22 @@ define((function () { 'use strict';
1278
1397
  let rect = element.getBoundingClientRect();
1279
1398
  return {
1280
1399
  /** y轴偏移 */
1281
- top: rect.top + DOMUtilsCore.globalThis.scrollY,
1400
+ top: rect.top + DOMUtilsContext.windowApi.globalThis.scrollY,
1282
1401
  /** x轴偏移 */
1283
- left: rect.left + DOMUtilsCore.globalThis.scrollX,
1402
+ left: rect.left + DOMUtilsContext.windowApi.globalThis.scrollX,
1284
1403
  };
1285
1404
  }
1286
1405
  width(element, isShow = false) {
1287
1406
  let DOMUtilsContext = this;
1288
1407
  if (typeof element === "string") {
1289
- element = DOMUtilsCore.document.querySelector(element);
1408
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1290
1409
  }
1291
1410
  if (element == null) {
1292
1411
  return;
1293
1412
  }
1294
1413
  if (DOMUtilsCommonUtils.isWin(element)) {
1295
- return DOMUtilsCore.window.document.documentElement.clientWidth;
1414
+ return DOMUtilsContext.windowApi.window.document.documentElement
1415
+ .clientWidth;
1296
1416
  }
1297
1417
  if (element.nodeType === 9) {
1298
1418
  /* Document文档节点 */
@@ -1335,10 +1455,11 @@ define((function () { 'use strict';
1335
1455
  height(element, isShow = false) {
1336
1456
  let DOMUtilsContext = this;
1337
1457
  if (DOMUtilsCommonUtils.isWin(element)) {
1338
- return DOMUtilsCore.window.document.documentElement.clientHeight;
1458
+ return DOMUtilsContext.windowApi.window.document.documentElement
1459
+ .clientHeight;
1339
1460
  }
1340
1461
  if (typeof element === "string") {
1341
- element = DOMUtilsCore.document.querySelector(element);
1462
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1342
1463
  }
1343
1464
  if (element == null) {
1344
1465
  // @ts-ignore
@@ -1385,10 +1506,10 @@ define((function () { 'use strict';
1385
1506
  outerWidth(element, isShow = false) {
1386
1507
  let DOMUtilsContext = this;
1387
1508
  if (DOMUtilsCommonUtils.isWin(element)) {
1388
- return DOMUtilsCore.window.innerWidth;
1509
+ return DOMUtilsContext.windowApi.window.innerWidth;
1389
1510
  }
1390
1511
  if (typeof element === "string") {
1391
- element = DOMUtilsCore.document.querySelector(element);
1512
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1392
1513
  }
1393
1514
  if (element == null) {
1394
1515
  // @ts-ignore
@@ -1411,10 +1532,10 @@ define((function () { 'use strict';
1411
1532
  outerHeight(element, isShow = false) {
1412
1533
  let DOMUtilsContext = this;
1413
1534
  if (DOMUtilsCommonUtils.isWin(element)) {
1414
- return DOMUtilsCore.window.innerHeight;
1535
+ return DOMUtilsContext.windowApi.window.innerHeight;
1415
1536
  }
1416
1537
  if (typeof element === "string") {
1417
- element = DOMUtilsCore.document.querySelector(element);
1538
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1418
1539
  }
1419
1540
  if (element == null) {
1420
1541
  // @ts-ignore
@@ -1447,8 +1568,9 @@ define((function () { 'use strict';
1447
1568
  * })
1448
1569
  */
1449
1570
  animate(element, styles, duration = 1000, callback = null) {
1571
+ let DOMUtilsContext = this;
1450
1572
  if (typeof element === "string") {
1451
- element = DOMUtilsCore.document.querySelector(element);
1573
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1452
1574
  }
1453
1575
  if (element == null) {
1454
1576
  return;
@@ -1499,15 +1621,16 @@ define((function () { 'use strict';
1499
1621
  * DOMUtils.wrap(document.querySelector("a.xx"),"<div></div>")
1500
1622
  */
1501
1623
  wrap(element, wrapperHTML) {
1624
+ let DOMUtilsContext = this;
1502
1625
  if (typeof element === "string") {
1503
- element = DOMUtilsCore.document.querySelector(element);
1626
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1504
1627
  }
1505
1628
  if (element == null) {
1506
1629
  return;
1507
1630
  }
1508
1631
  element = element;
1509
1632
  // 创建一个新的div元素,并将wrapperHTML作为其innerHTML
1510
- let wrapper = DOMUtilsCore.document.createElement("div");
1633
+ let wrapper = DOMUtilsContext.windowApi.document.createElement("div");
1511
1634
  wrapper.innerHTML = wrapperHTML;
1512
1635
  let wrapperFirstChild = wrapper.firstChild;
1513
1636
  // 将要包裹的元素插入目标元素前面
@@ -1516,8 +1639,9 @@ define((function () { 'use strict';
1516
1639
  wrapperFirstChild.appendChild(element);
1517
1640
  }
1518
1641
  prev(element) {
1642
+ let DOMUtilsContext = this;
1519
1643
  if (typeof element === "string") {
1520
- element = DOMUtilsCore.document.querySelector(element);
1644
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1521
1645
  }
1522
1646
  if (element == null) {
1523
1647
  return;
@@ -1525,8 +1649,9 @@ define((function () { 'use strict';
1525
1649
  return element.previousElementSibling;
1526
1650
  }
1527
1651
  next(element) {
1652
+ let DOMUtilsContext = this;
1528
1653
  if (typeof element === "string") {
1529
- element = DOMUtilsCore.document.querySelector(element);
1654
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1530
1655
  }
1531
1656
  if (element == null) {
1532
1657
  return;
@@ -1539,15 +1664,17 @@ define((function () { 'use strict';
1539
1664
  * let DOMUtils = window.DOMUtils.noConflict()
1540
1665
  */
1541
1666
  noConflict() {
1542
- if (DOMUtilsCore.window.DOMUtils) {
1667
+ let DOMUtilsContext = this;
1668
+ if (DOMUtilsContext.windowApi.window.DOMUtils) {
1543
1669
  DOMUtilsCommonUtils.delete(window, "DOMUtils");
1544
1670
  }
1545
- DOMUtilsCore.window.DOMUtils = this;
1671
+ DOMUtilsContext.windowApi.window.DOMUtils = this;
1546
1672
  return this;
1547
1673
  }
1548
1674
  siblings(element) {
1675
+ let DOMUtilsContext = this;
1549
1676
  if (typeof element === "string") {
1550
- element = DOMUtilsCore.document.querySelector(element);
1677
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1551
1678
  }
1552
1679
  if (element == null) {
1553
1680
  return;
@@ -1568,7 +1695,7 @@ define((function () { 'use strict';
1568
1695
  parent(element) {
1569
1696
  let DOMUtilsContext = this;
1570
1697
  if (typeof element === "string") {
1571
- element = DOMUtilsCore.document.querySelector(element);
1698
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1572
1699
  }
1573
1700
  if (element == null) {
1574
1701
  return;
@@ -1586,6 +1713,7 @@ define((function () { 'use strict';
1586
1713
  }
1587
1714
  }
1588
1715
  parseHTML(html, useParser = false, isComplete = false) {
1716
+ let DOMUtilsContext = this;
1589
1717
  function parseHTMLByDOMParser() {
1590
1718
  let parser = new DOMParser();
1591
1719
  if (isComplete) {
@@ -1596,7 +1724,7 @@ define((function () { 'use strict';
1596
1724
  }
1597
1725
  }
1598
1726
  function parseHTMLByCreateDom() {
1599
- let tempDIV = DOMUtilsCore.document.createElement("div");
1727
+ let tempDIV = DOMUtilsContext.windowApi.document.createElement("div");
1600
1728
  tempDIV.innerHTML = html;
1601
1729
  if (isComplete) {
1602
1730
  return tempDIV;
@@ -1627,7 +1755,7 @@ define((function () { 'use strict';
1627
1755
  return;
1628
1756
  }
1629
1757
  if (typeof target === "string") {
1630
- target = DOMUtilsCore.document.querySelectorAll(target);
1758
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1631
1759
  }
1632
1760
  if (target instanceof NodeList || target instanceof Array) {
1633
1761
  target = target;
@@ -1659,7 +1787,7 @@ define((function () { 'use strict';
1659
1787
  return;
1660
1788
  }
1661
1789
  if (typeof target === "string") {
1662
- target = DOMUtilsCore.document.querySelectorAll(target);
1790
+ target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
1663
1791
  }
1664
1792
  if (target instanceof NodeList || target instanceof Array) {
1665
1793
  target = target;
@@ -1694,8 +1822,9 @@ define((function () { 'use strict';
1694
1822
  if (element == null) {
1695
1823
  return;
1696
1824
  }
1825
+ let DOMUtilsContext = this;
1697
1826
  if (typeof element === "string") {
1698
- element = DOMUtilsCore.document.querySelector(element);
1827
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1699
1828
  }
1700
1829
  element = element;
1701
1830
  element.style.opacity = "0";
@@ -1709,16 +1838,16 @@ define((function () { 'use strict';
1709
1838
  element = element;
1710
1839
  element.style.opacity = Math.min(progress / duration, 1).toString();
1711
1840
  if (progress < duration) {
1712
- DOMUtilsCore.window.requestAnimationFrame(step);
1841
+ DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1713
1842
  }
1714
1843
  else {
1715
1844
  if (callback && typeof callback === "function") {
1716
1845
  callback();
1717
1846
  }
1718
- DOMUtilsCore.window.cancelAnimationFrame(timer);
1847
+ DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
1719
1848
  }
1720
1849
  }
1721
- timer = DOMUtilsCore.window.requestAnimationFrame(step);
1850
+ timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1722
1851
  }
1723
1852
  /**
1724
1853
  * 淡出元素
@@ -1735,11 +1864,12 @@ define((function () { 'use strict';
1735
1864
  * })
1736
1865
  */
1737
1866
  fadeOut(element, duration = 400, callback) {
1867
+ let DOMUtilsContext = this;
1738
1868
  if (element == null) {
1739
1869
  return;
1740
1870
  }
1741
1871
  if (typeof element === "string") {
1742
- element = DOMUtilsCore.document.querySelector(element);
1872
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1743
1873
  }
1744
1874
  element = element;
1745
1875
  element.style.opacity = "1";
@@ -1752,17 +1882,17 @@ define((function () { 'use strict';
1752
1882
  element = element;
1753
1883
  element.style.opacity = Math.max(1 - progress / duration, 0).toString();
1754
1884
  if (progress < duration) {
1755
- DOMUtilsCore.window.requestAnimationFrame(step);
1885
+ DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1756
1886
  }
1757
1887
  else {
1758
1888
  element.style.display = "none";
1759
1889
  if (typeof callback === "function") {
1760
1890
  callback();
1761
1891
  }
1762
- DOMUtilsCore.window.cancelAnimationFrame(timer);
1892
+ DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
1763
1893
  }
1764
1894
  }
1765
- timer = DOMUtilsCore.window.requestAnimationFrame(step);
1895
+ timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
1766
1896
  }
1767
1897
  /**
1768
1898
  * 切换元素的显示和隐藏状态
@@ -1775,7 +1905,7 @@ define((function () { 'use strict';
1775
1905
  toggle(element) {
1776
1906
  let DOMUtilsContext = this;
1777
1907
  if (typeof element === "string") {
1778
- element = DOMUtilsCore.document.querySelector(element);
1908
+ element = DOMUtilsContext.windowApi.document.querySelector(element);
1779
1909
  }
1780
1910
  if (element == null) {
1781
1911
  return;
@@ -1804,6 +1934,7 @@ define((function () { 'use strict';
1804
1934
  * DOMUtils.getTextBoundingRect(document.querySelector("input"));
1805
1935
  */
1806
1936
  getTextBoundingRect($input, selectionStart, selectionEnd) {
1937
+ let DOMUtilsContext = this;
1807
1938
  // Basic parameter validation
1808
1939
  if (!$input || !("value" in $input))
1809
1940
  return $input;
@@ -1873,7 +2004,7 @@ define((function () { 'use strict';
1873
2004
  }
1874
2005
  // End of CSS variable checks
1875
2006
  // 不能为空,不然获取不到高度
1876
- let text = $input.value || "G", textLen = text.length, fakeClone = DOMUtilsCore.document.createElement("div");
2007
+ let text = $input.value || "G", textLen = text.length, fakeClone = DOMUtilsContext.windowApi.document.createElement("div");
1877
2008
  if (selectionStart > 0)
1878
2009
  appendPart(0, selectionStart);
1879
2010
  var fakeRange = appendPart(selectionStart, selectionEnd);
@@ -1887,7 +2018,7 @@ define((function () { 'use strict';
1887
2018
  fakeClone.style.left = leftPos + "px";
1888
2019
  fakeClone.style.width = width + "px";
1889
2020
  fakeClone.style.height = height + "px";
1890
- DOMUtilsCore.document.body.appendChild(fakeClone);
2021
+ DOMUtilsContext.windowApi.document.body.appendChild(fakeClone);
1891
2022
  var returnValue = fakeRange.getBoundingClientRect(); //Get rect
1892
2023
  fakeClone?.parentNode?.removeChild(fakeClone); //Remove temp
1893
2024
  return returnValue;
@@ -1899,7 +2030,7 @@ define((function () { 'use strict';
1899
2030
  * @returns
1900
2031
  */
1901
2032
  function appendPart(start, end) {
1902
- var span = DOMUtilsCore.document.createElement("span");
2033
+ var span = DOMUtilsContext.windowApi.document.createElement("span");
1903
2034
  span.style.cssText = cssDefaultStyles; //Force styles to prevent unexpected results
1904
2035
  span.textContent = text.substring(start, end);
1905
2036
  fakeClone.appendChild(span);
@@ -1907,7 +2038,7 @@ define((function () { 'use strict';
1907
2038
  }
1908
2039
  // Computing offset position
1909
2040
  function getInputOffset() {
1910
- let body = DOMUtilsCore.document.body, win = DOMUtilsCore.document.defaultView, docElem = DOMUtilsCore.document.documentElement, $box = DOMUtilsCore.document.createElement("div");
2041
+ let body = DOMUtilsContext.windowApi.document.body, win = DOMUtilsContext.windowApi.document.defaultView, docElem = DOMUtilsContext.windowApi.document.documentElement, $box = DOMUtilsContext.windowApi.document.createElement("div");
1911
2042
  $box.style.paddingLeft = $box.style.width = "1px";
1912
2043
  body.appendChild($box);
1913
2044
  var isBoxModel = $box.offsetWidth == 2;
@@ -1930,7 +2061,7 @@ define((function () { 'use strict';
1930
2061
  * @returns
1931
2062
  */
1932
2063
  function getInputCSS(prop, isNumber) {
1933
- var val = DOMUtilsCore.document
2064
+ var val = DOMUtilsContext.windowApi.document
1934
2065
  .defaultView.getComputedStyle($input, null)
1935
2066
  .getPropertyValue(prop);
1936
2067
  return isNumber ? parseFloat(val) : val;