@whitesev/domutils 1.1.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +155 -115
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +155 -115
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +155 -115
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +155 -115
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +155 -115
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +155 -115
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +3 -3
- package/dist/types/src/DOMUtilsCommonUtils.d.ts +2 -0
- package/dist/types/src/DOMUtilsEvent.d.ts +4 -2
- package/dist/types/src/WindowApi.d.ts +22 -0
- package/package.json +5 -3
- package/src/DOMUtils.ts +1791 -0
- package/src/DOMUtilsCommonUtils.ts +111 -0
- package/src/DOMUtilsData.ts +9 -0
- package/src/DOMUtilsEvent.ts +1259 -0
- package/src/DOMUtilsOriginPrototype.ts +7 -0
- package/src/WindowApi.ts +44 -0
- package/src/types/global.d.ts +5 -0
- package/src/types/gm.d.ts +2 -0
- package/dist/types/src/DOMUtilsCore.d.ts +0 -15
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
|
-
|
|
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 ===
|
|
80
|
+
if (target === globalThis) {
|
|
112
81
|
return true;
|
|
113
82
|
}
|
|
114
|
-
if (target ===
|
|
83
|
+
if (target === window) {
|
|
115
84
|
return true;
|
|
116
85
|
}
|
|
117
|
-
if (target ===
|
|
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 =
|
|
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
|
-
?
|
|
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 =
|
|
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 =
|
|
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 (
|
|
448
|
-
(
|
|
449
|
-
!
|
|
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:
|
|
480
|
+
target: DOMUtilsContext.windowApi.document,
|
|
470
481
|
eventType: "DOMContentLoaded",
|
|
471
482
|
callback: completed,
|
|
472
483
|
},
|
|
473
484
|
{
|
|
474
|
-
target:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
739
|
+
target = DOMUtilsContext.windowApi.document.querySelector(target);
|
|
728
740
|
}
|
|
729
741
|
DOMUtilsContext.on(target, "keydown", null, handler, option);
|
|
730
742
|
}
|
|
@@ -749,7 +761,7 @@ define((function () { 'use strict';
|
|
|
749
761
|
return;
|
|
750
762
|
}
|
|
751
763
|
if (typeof target === "string") {
|
|
752
|
-
target =
|
|
764
|
+
target = DOMUtilsContext.windowApi.document.querySelector(target);
|
|
753
765
|
}
|
|
754
766
|
DOMUtilsContext.on(target, "keypress", null, handler, option);
|
|
755
767
|
}
|
|
@@ -757,14 +769,14 @@ define((function () { 'use strict';
|
|
|
757
769
|
|
|
758
770
|
class DOMUtils extends DOMUtilsEvent {
|
|
759
771
|
constructor(option) {
|
|
760
|
-
|
|
761
|
-
super();
|
|
772
|
+
super(option);
|
|
762
773
|
}
|
|
763
774
|
/** 版本号 */
|
|
764
|
-
version = "2024.
|
|
775
|
+
version = "2024.7.24";
|
|
765
776
|
attr(element, attrName, attrValue) {
|
|
777
|
+
let DOMUtilsContext = this;
|
|
766
778
|
if (typeof element === "string") {
|
|
767
|
-
element =
|
|
779
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
768
780
|
}
|
|
769
781
|
if (element == null) {
|
|
770
782
|
return;
|
|
@@ -801,7 +813,8 @@ define((function () { 'use strict';
|
|
|
801
813
|
property,
|
|
802
814
|
/** 自定义属性 */
|
|
803
815
|
attributes) {
|
|
804
|
-
let
|
|
816
|
+
let DOMUtilsContext = this;
|
|
817
|
+
let tempElement = DOMUtilsContext.windowApi.document.createElement(tagName);
|
|
805
818
|
if (typeof property === "string") {
|
|
806
819
|
tempElement.innerHTML = property;
|
|
807
820
|
return tempElement;
|
|
@@ -831,6 +844,7 @@ define((function () { 'use strict';
|
|
|
831
844
|
return tempElement;
|
|
832
845
|
}
|
|
833
846
|
css(element, property, value) {
|
|
847
|
+
let DOMUtilsContext = this;
|
|
834
848
|
/**
|
|
835
849
|
* 把纯数字没有px的加上
|
|
836
850
|
*/
|
|
@@ -855,7 +869,7 @@ define((function () { 'use strict';
|
|
|
855
869
|
return propertyValue;
|
|
856
870
|
}
|
|
857
871
|
if (typeof element === "string") {
|
|
858
|
-
element =
|
|
872
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
859
873
|
}
|
|
860
874
|
if (element == null) {
|
|
861
875
|
return;
|
|
@@ -888,8 +902,9 @@ define((function () { 'use strict';
|
|
|
888
902
|
}
|
|
889
903
|
}
|
|
890
904
|
text(element, text) {
|
|
905
|
+
let DOMUtilsContext = this;
|
|
891
906
|
if (typeof element === "string") {
|
|
892
|
-
element =
|
|
907
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
893
908
|
}
|
|
894
909
|
if (element == null) {
|
|
895
910
|
return;
|
|
@@ -910,8 +925,9 @@ define((function () { 'use strict';
|
|
|
910
925
|
}
|
|
911
926
|
}
|
|
912
927
|
html(element, html) {
|
|
928
|
+
let DOMUtilsContext = this;
|
|
913
929
|
if (typeof element === "string") {
|
|
914
|
-
element =
|
|
930
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
915
931
|
}
|
|
916
932
|
if (element == null) {
|
|
917
933
|
return;
|
|
@@ -964,8 +980,9 @@ define((function () { 'use strict';
|
|
|
964
980
|
};
|
|
965
981
|
}
|
|
966
982
|
val(element, value) {
|
|
983
|
+
let DOMUtilsContext = this;
|
|
967
984
|
if (typeof element === "string") {
|
|
968
|
-
element =
|
|
985
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
969
986
|
}
|
|
970
987
|
if (element == null) {
|
|
971
988
|
return;
|
|
@@ -990,11 +1007,12 @@ define((function () { 'use strict';
|
|
|
990
1007
|
}
|
|
991
1008
|
}
|
|
992
1009
|
prop(element, propName, propValue) {
|
|
1010
|
+
let DOMUtilsContext = this;
|
|
993
1011
|
if (element == null) {
|
|
994
1012
|
return;
|
|
995
1013
|
}
|
|
996
1014
|
if (typeof element === "string") {
|
|
997
|
-
element =
|
|
1015
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
998
1016
|
}
|
|
999
1017
|
if (propValue == null) {
|
|
1000
1018
|
return element[propName];
|
|
@@ -1013,8 +1031,9 @@ define((function () { 'use strict';
|
|
|
1013
1031
|
* DOMUtils.removeAttr("a.xx","data-value")
|
|
1014
1032
|
* */
|
|
1015
1033
|
removeAttr(element, attrName) {
|
|
1034
|
+
let DOMUtilsContext = this;
|
|
1016
1035
|
if (typeof element === "string") {
|
|
1017
|
-
element =
|
|
1036
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1018
1037
|
}
|
|
1019
1038
|
if (element == null) {
|
|
1020
1039
|
return;
|
|
@@ -1031,8 +1050,9 @@ define((function () { 'use strict';
|
|
|
1031
1050
|
* DOMUtils.removeClass("a.xx","xx")
|
|
1032
1051
|
*/
|
|
1033
1052
|
removeClass(element, className) {
|
|
1053
|
+
let DOMUtilsContext = this;
|
|
1034
1054
|
if (typeof element === "string") {
|
|
1035
|
-
element =
|
|
1055
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1036
1056
|
}
|
|
1037
1057
|
if (element == null) {
|
|
1038
1058
|
return;
|
|
@@ -1052,8 +1072,9 @@ define((function () { 'use strict';
|
|
|
1052
1072
|
* DOMUtils.removeProp("a.xx","href")
|
|
1053
1073
|
* */
|
|
1054
1074
|
removeProp(element, propName) {
|
|
1075
|
+
let DOMUtilsContext = this;
|
|
1055
1076
|
if (typeof element === "string") {
|
|
1056
|
-
element =
|
|
1077
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1057
1078
|
}
|
|
1058
1079
|
if (element == null) {
|
|
1059
1080
|
return;
|
|
@@ -1072,7 +1093,7 @@ define((function () { 'use strict';
|
|
|
1072
1093
|
replaceWith(element, newElement) {
|
|
1073
1094
|
let DOMUtilsContext = this;
|
|
1074
1095
|
if (typeof element === "string") {
|
|
1075
|
-
element =
|
|
1096
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1076
1097
|
}
|
|
1077
1098
|
if (element == null) {
|
|
1078
1099
|
return;
|
|
@@ -1099,8 +1120,9 @@ define((function () { 'use strict';
|
|
|
1099
1120
|
* DOMUtils.addClass("a.xx","_vue_")
|
|
1100
1121
|
* */
|
|
1101
1122
|
addClass(element, className) {
|
|
1123
|
+
let DOMUtilsContext = this;
|
|
1102
1124
|
if (typeof element === "string") {
|
|
1103
|
-
element =
|
|
1125
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1104
1126
|
}
|
|
1105
1127
|
if (element == null) {
|
|
1106
1128
|
return;
|
|
@@ -1117,8 +1139,9 @@ define((function () { 'use strict';
|
|
|
1117
1139
|
* DOMUtils.append("a.xx","'<b class="xx"></b>")
|
|
1118
1140
|
* */
|
|
1119
1141
|
append(element, content) {
|
|
1142
|
+
let DOMUtilsContext = this;
|
|
1120
1143
|
if (typeof element === "string") {
|
|
1121
|
-
element =
|
|
1144
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1122
1145
|
}
|
|
1123
1146
|
if (element == null) {
|
|
1124
1147
|
return;
|
|
@@ -1133,7 +1156,7 @@ define((function () { 'use strict';
|
|
|
1133
1156
|
}
|
|
1134
1157
|
if (Array.isArray(content) || content instanceof NodeList) {
|
|
1135
1158
|
/* 数组 */
|
|
1136
|
-
let fragment =
|
|
1159
|
+
let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
|
|
1137
1160
|
content.forEach((ele) => {
|
|
1138
1161
|
if (typeof ele === "string") {
|
|
1139
1162
|
ele = this.parseHTML(ele, true, false);
|
|
@@ -1156,8 +1179,9 @@ define((function () { 'use strict';
|
|
|
1156
1179
|
* DOMUtils.prepend("a.xx","'<b class="xx"></b>")
|
|
1157
1180
|
* */
|
|
1158
1181
|
prepend(element, content) {
|
|
1182
|
+
let DOMUtilsContext = this;
|
|
1159
1183
|
if (typeof element === "string") {
|
|
1160
|
-
element =
|
|
1184
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1161
1185
|
}
|
|
1162
1186
|
if (element == null) {
|
|
1163
1187
|
return;
|
|
@@ -1179,8 +1203,9 @@ define((function () { 'use strict';
|
|
|
1179
1203
|
* DOMUtils.after("a.xx","'<b class="xx"></b>")
|
|
1180
1204
|
* */
|
|
1181
1205
|
after(element, content) {
|
|
1206
|
+
let DOMUtilsContext = this;
|
|
1182
1207
|
if (typeof element === "string") {
|
|
1183
|
-
element =
|
|
1208
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1184
1209
|
}
|
|
1185
1210
|
if (element == null) {
|
|
1186
1211
|
return;
|
|
@@ -1202,8 +1227,9 @@ define((function () { 'use strict';
|
|
|
1202
1227
|
* DOMUtils.before("a.xx","'<b class="xx"></b>")
|
|
1203
1228
|
* */
|
|
1204
1229
|
before(element, content) {
|
|
1230
|
+
let DOMUtilsContext = this;
|
|
1205
1231
|
if (typeof element === "string") {
|
|
1206
|
-
element =
|
|
1232
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1207
1233
|
}
|
|
1208
1234
|
if (element == null) {
|
|
1209
1235
|
return;
|
|
@@ -1227,7 +1253,7 @@ define((function () { 'use strict';
|
|
|
1227
1253
|
remove(target) {
|
|
1228
1254
|
let DOMUtilsContext = this;
|
|
1229
1255
|
if (typeof target === "string") {
|
|
1230
|
-
target =
|
|
1256
|
+
target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
|
|
1231
1257
|
}
|
|
1232
1258
|
if (target == null) {
|
|
1233
1259
|
return;
|
|
@@ -1251,8 +1277,9 @@ define((function () { 'use strict';
|
|
|
1251
1277
|
* DOMUtils.empty("a.xx")
|
|
1252
1278
|
* */
|
|
1253
1279
|
empty(element) {
|
|
1280
|
+
let DOMUtilsContext = this;
|
|
1254
1281
|
if (typeof element === "string") {
|
|
1255
|
-
element =
|
|
1282
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1256
1283
|
}
|
|
1257
1284
|
if (element == null) {
|
|
1258
1285
|
return;
|
|
@@ -1269,8 +1296,9 @@ define((function () { 'use strict';
|
|
|
1269
1296
|
* > 0
|
|
1270
1297
|
*/
|
|
1271
1298
|
offset(element) {
|
|
1299
|
+
let DOMUtilsContext = this;
|
|
1272
1300
|
if (typeof element === "string") {
|
|
1273
|
-
element =
|
|
1301
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1274
1302
|
}
|
|
1275
1303
|
if (element == null) {
|
|
1276
1304
|
return;
|
|
@@ -1278,21 +1306,22 @@ define((function () { 'use strict';
|
|
|
1278
1306
|
let rect = element.getBoundingClientRect();
|
|
1279
1307
|
return {
|
|
1280
1308
|
/** y轴偏移 */
|
|
1281
|
-
top: rect.top +
|
|
1309
|
+
top: rect.top + DOMUtilsContext.windowApi.globalThis.scrollY,
|
|
1282
1310
|
/** x轴偏移 */
|
|
1283
|
-
left: rect.left +
|
|
1311
|
+
left: rect.left + DOMUtilsContext.windowApi.globalThis.scrollX,
|
|
1284
1312
|
};
|
|
1285
1313
|
}
|
|
1286
1314
|
width(element, isShow = false) {
|
|
1287
1315
|
let DOMUtilsContext = this;
|
|
1288
1316
|
if (typeof element === "string") {
|
|
1289
|
-
element =
|
|
1317
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1290
1318
|
}
|
|
1291
1319
|
if (element == null) {
|
|
1292
1320
|
return;
|
|
1293
1321
|
}
|
|
1294
1322
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1295
|
-
return
|
|
1323
|
+
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
1324
|
+
.clientWidth;
|
|
1296
1325
|
}
|
|
1297
1326
|
if (element.nodeType === 9) {
|
|
1298
1327
|
/* Document文档节点 */
|
|
@@ -1335,10 +1364,11 @@ define((function () { 'use strict';
|
|
|
1335
1364
|
height(element, isShow = false) {
|
|
1336
1365
|
let DOMUtilsContext = this;
|
|
1337
1366
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1338
|
-
return
|
|
1367
|
+
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
1368
|
+
.clientHeight;
|
|
1339
1369
|
}
|
|
1340
1370
|
if (typeof element === "string") {
|
|
1341
|
-
element =
|
|
1371
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1342
1372
|
}
|
|
1343
1373
|
if (element == null) {
|
|
1344
1374
|
// @ts-ignore
|
|
@@ -1385,10 +1415,10 @@ define((function () { 'use strict';
|
|
|
1385
1415
|
outerWidth(element, isShow = false) {
|
|
1386
1416
|
let DOMUtilsContext = this;
|
|
1387
1417
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1388
|
-
return
|
|
1418
|
+
return DOMUtilsContext.windowApi.window.innerWidth;
|
|
1389
1419
|
}
|
|
1390
1420
|
if (typeof element === "string") {
|
|
1391
|
-
element =
|
|
1421
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1392
1422
|
}
|
|
1393
1423
|
if (element == null) {
|
|
1394
1424
|
// @ts-ignore
|
|
@@ -1411,10 +1441,10 @@ define((function () { 'use strict';
|
|
|
1411
1441
|
outerHeight(element, isShow = false) {
|
|
1412
1442
|
let DOMUtilsContext = this;
|
|
1413
1443
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1414
|
-
return
|
|
1444
|
+
return DOMUtilsContext.windowApi.window.innerHeight;
|
|
1415
1445
|
}
|
|
1416
1446
|
if (typeof element === "string") {
|
|
1417
|
-
element =
|
|
1447
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1418
1448
|
}
|
|
1419
1449
|
if (element == null) {
|
|
1420
1450
|
// @ts-ignore
|
|
@@ -1447,8 +1477,9 @@ define((function () { 'use strict';
|
|
|
1447
1477
|
* })
|
|
1448
1478
|
*/
|
|
1449
1479
|
animate(element, styles, duration = 1000, callback = null) {
|
|
1480
|
+
let DOMUtilsContext = this;
|
|
1450
1481
|
if (typeof element === "string") {
|
|
1451
|
-
element =
|
|
1482
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1452
1483
|
}
|
|
1453
1484
|
if (element == null) {
|
|
1454
1485
|
return;
|
|
@@ -1499,15 +1530,16 @@ define((function () { 'use strict';
|
|
|
1499
1530
|
* DOMUtils.wrap(document.querySelector("a.xx"),"<div></div>")
|
|
1500
1531
|
*/
|
|
1501
1532
|
wrap(element, wrapperHTML) {
|
|
1533
|
+
let DOMUtilsContext = this;
|
|
1502
1534
|
if (typeof element === "string") {
|
|
1503
|
-
element =
|
|
1535
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1504
1536
|
}
|
|
1505
1537
|
if (element == null) {
|
|
1506
1538
|
return;
|
|
1507
1539
|
}
|
|
1508
1540
|
element = element;
|
|
1509
1541
|
// 创建一个新的div元素,并将wrapperHTML作为其innerHTML
|
|
1510
|
-
let wrapper =
|
|
1542
|
+
let wrapper = DOMUtilsContext.windowApi.document.createElement("div");
|
|
1511
1543
|
wrapper.innerHTML = wrapperHTML;
|
|
1512
1544
|
let wrapperFirstChild = wrapper.firstChild;
|
|
1513
1545
|
// 将要包裹的元素插入目标元素前面
|
|
@@ -1516,8 +1548,9 @@ define((function () { 'use strict';
|
|
|
1516
1548
|
wrapperFirstChild.appendChild(element);
|
|
1517
1549
|
}
|
|
1518
1550
|
prev(element) {
|
|
1551
|
+
let DOMUtilsContext = this;
|
|
1519
1552
|
if (typeof element === "string") {
|
|
1520
|
-
element =
|
|
1553
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1521
1554
|
}
|
|
1522
1555
|
if (element == null) {
|
|
1523
1556
|
return;
|
|
@@ -1525,8 +1558,9 @@ define((function () { 'use strict';
|
|
|
1525
1558
|
return element.previousElementSibling;
|
|
1526
1559
|
}
|
|
1527
1560
|
next(element) {
|
|
1561
|
+
let DOMUtilsContext = this;
|
|
1528
1562
|
if (typeof element === "string") {
|
|
1529
|
-
element =
|
|
1563
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1530
1564
|
}
|
|
1531
1565
|
if (element == null) {
|
|
1532
1566
|
return;
|
|
@@ -1539,15 +1573,17 @@ define((function () { 'use strict';
|
|
|
1539
1573
|
* let DOMUtils = window.DOMUtils.noConflict()
|
|
1540
1574
|
*/
|
|
1541
1575
|
noConflict() {
|
|
1542
|
-
|
|
1576
|
+
let DOMUtilsContext = this;
|
|
1577
|
+
if (DOMUtilsContext.windowApi.window.DOMUtils) {
|
|
1543
1578
|
DOMUtilsCommonUtils.delete(window, "DOMUtils");
|
|
1544
1579
|
}
|
|
1545
|
-
|
|
1580
|
+
DOMUtilsContext.windowApi.window.DOMUtils = this;
|
|
1546
1581
|
return this;
|
|
1547
1582
|
}
|
|
1548
1583
|
siblings(element) {
|
|
1584
|
+
let DOMUtilsContext = this;
|
|
1549
1585
|
if (typeof element === "string") {
|
|
1550
|
-
element =
|
|
1586
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1551
1587
|
}
|
|
1552
1588
|
if (element == null) {
|
|
1553
1589
|
return;
|
|
@@ -1568,7 +1604,7 @@ define((function () { 'use strict';
|
|
|
1568
1604
|
parent(element) {
|
|
1569
1605
|
let DOMUtilsContext = this;
|
|
1570
1606
|
if (typeof element === "string") {
|
|
1571
|
-
element =
|
|
1607
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1572
1608
|
}
|
|
1573
1609
|
if (element == null) {
|
|
1574
1610
|
return;
|
|
@@ -1586,6 +1622,7 @@ define((function () { 'use strict';
|
|
|
1586
1622
|
}
|
|
1587
1623
|
}
|
|
1588
1624
|
parseHTML(html, useParser = false, isComplete = false) {
|
|
1625
|
+
let DOMUtilsContext = this;
|
|
1589
1626
|
function parseHTMLByDOMParser() {
|
|
1590
1627
|
let parser = new DOMParser();
|
|
1591
1628
|
if (isComplete) {
|
|
@@ -1596,7 +1633,7 @@ define((function () { 'use strict';
|
|
|
1596
1633
|
}
|
|
1597
1634
|
}
|
|
1598
1635
|
function parseHTMLByCreateDom() {
|
|
1599
|
-
let tempDIV =
|
|
1636
|
+
let tempDIV = DOMUtilsContext.windowApi.document.createElement("div");
|
|
1600
1637
|
tempDIV.innerHTML = html;
|
|
1601
1638
|
if (isComplete) {
|
|
1602
1639
|
return tempDIV;
|
|
@@ -1627,7 +1664,7 @@ define((function () { 'use strict';
|
|
|
1627
1664
|
return;
|
|
1628
1665
|
}
|
|
1629
1666
|
if (typeof target === "string") {
|
|
1630
|
-
target =
|
|
1667
|
+
target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
|
|
1631
1668
|
}
|
|
1632
1669
|
if (target instanceof NodeList || target instanceof Array) {
|
|
1633
1670
|
target = target;
|
|
@@ -1659,7 +1696,7 @@ define((function () { 'use strict';
|
|
|
1659
1696
|
return;
|
|
1660
1697
|
}
|
|
1661
1698
|
if (typeof target === "string") {
|
|
1662
|
-
target =
|
|
1699
|
+
target = DOMUtilsContext.windowApi.document.querySelectorAll(target);
|
|
1663
1700
|
}
|
|
1664
1701
|
if (target instanceof NodeList || target instanceof Array) {
|
|
1665
1702
|
target = target;
|
|
@@ -1694,8 +1731,9 @@ define((function () { 'use strict';
|
|
|
1694
1731
|
if (element == null) {
|
|
1695
1732
|
return;
|
|
1696
1733
|
}
|
|
1734
|
+
let DOMUtilsContext = this;
|
|
1697
1735
|
if (typeof element === "string") {
|
|
1698
|
-
element =
|
|
1736
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1699
1737
|
}
|
|
1700
1738
|
element = element;
|
|
1701
1739
|
element.style.opacity = "0";
|
|
@@ -1709,16 +1747,16 @@ define((function () { 'use strict';
|
|
|
1709
1747
|
element = element;
|
|
1710
1748
|
element.style.opacity = Math.min(progress / duration, 1).toString();
|
|
1711
1749
|
if (progress < duration) {
|
|
1712
|
-
|
|
1750
|
+
DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
|
|
1713
1751
|
}
|
|
1714
1752
|
else {
|
|
1715
1753
|
if (callback && typeof callback === "function") {
|
|
1716
1754
|
callback();
|
|
1717
1755
|
}
|
|
1718
|
-
|
|
1756
|
+
DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
|
|
1719
1757
|
}
|
|
1720
1758
|
}
|
|
1721
|
-
timer =
|
|
1759
|
+
timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
|
|
1722
1760
|
}
|
|
1723
1761
|
/**
|
|
1724
1762
|
* 淡出元素
|
|
@@ -1735,11 +1773,12 @@ define((function () { 'use strict';
|
|
|
1735
1773
|
* })
|
|
1736
1774
|
*/
|
|
1737
1775
|
fadeOut(element, duration = 400, callback) {
|
|
1776
|
+
let DOMUtilsContext = this;
|
|
1738
1777
|
if (element == null) {
|
|
1739
1778
|
return;
|
|
1740
1779
|
}
|
|
1741
1780
|
if (typeof element === "string") {
|
|
1742
|
-
element =
|
|
1781
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1743
1782
|
}
|
|
1744
1783
|
element = element;
|
|
1745
1784
|
element.style.opacity = "1";
|
|
@@ -1752,17 +1791,17 @@ define((function () { 'use strict';
|
|
|
1752
1791
|
element = element;
|
|
1753
1792
|
element.style.opacity = Math.max(1 - progress / duration, 0).toString();
|
|
1754
1793
|
if (progress < duration) {
|
|
1755
|
-
|
|
1794
|
+
DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
|
|
1756
1795
|
}
|
|
1757
1796
|
else {
|
|
1758
1797
|
element.style.display = "none";
|
|
1759
1798
|
if (typeof callback === "function") {
|
|
1760
1799
|
callback();
|
|
1761
1800
|
}
|
|
1762
|
-
|
|
1801
|
+
DOMUtilsContext.windowApi.window.cancelAnimationFrame(timer);
|
|
1763
1802
|
}
|
|
1764
1803
|
}
|
|
1765
|
-
timer =
|
|
1804
|
+
timer = DOMUtilsContext.windowApi.window.requestAnimationFrame(step);
|
|
1766
1805
|
}
|
|
1767
1806
|
/**
|
|
1768
1807
|
* 切换元素的显示和隐藏状态
|
|
@@ -1775,7 +1814,7 @@ define((function () { 'use strict';
|
|
|
1775
1814
|
toggle(element) {
|
|
1776
1815
|
let DOMUtilsContext = this;
|
|
1777
1816
|
if (typeof element === "string") {
|
|
1778
|
-
element =
|
|
1817
|
+
element = DOMUtilsContext.windowApi.document.querySelector(element);
|
|
1779
1818
|
}
|
|
1780
1819
|
if (element == null) {
|
|
1781
1820
|
return;
|
|
@@ -1804,6 +1843,7 @@ define((function () { 'use strict';
|
|
|
1804
1843
|
* DOMUtils.getTextBoundingRect(document.querySelector("input"));
|
|
1805
1844
|
*/
|
|
1806
1845
|
getTextBoundingRect($input, selectionStart, selectionEnd) {
|
|
1846
|
+
let DOMUtilsContext = this;
|
|
1807
1847
|
// Basic parameter validation
|
|
1808
1848
|
if (!$input || !("value" in $input))
|
|
1809
1849
|
return $input;
|
|
@@ -1873,7 +1913,7 @@ define((function () { 'use strict';
|
|
|
1873
1913
|
}
|
|
1874
1914
|
// End of CSS variable checks
|
|
1875
1915
|
// 不能为空,不然获取不到高度
|
|
1876
|
-
let text = $input.value || "G", textLen = text.length, fakeClone =
|
|
1916
|
+
let text = $input.value || "G", textLen = text.length, fakeClone = DOMUtilsContext.windowApi.document.createElement("div");
|
|
1877
1917
|
if (selectionStart > 0)
|
|
1878
1918
|
appendPart(0, selectionStart);
|
|
1879
1919
|
var fakeRange = appendPart(selectionStart, selectionEnd);
|
|
@@ -1887,7 +1927,7 @@ define((function () { 'use strict';
|
|
|
1887
1927
|
fakeClone.style.left = leftPos + "px";
|
|
1888
1928
|
fakeClone.style.width = width + "px";
|
|
1889
1929
|
fakeClone.style.height = height + "px";
|
|
1890
|
-
|
|
1930
|
+
DOMUtilsContext.windowApi.document.body.appendChild(fakeClone);
|
|
1891
1931
|
var returnValue = fakeRange.getBoundingClientRect(); //Get rect
|
|
1892
1932
|
fakeClone?.parentNode?.removeChild(fakeClone); //Remove temp
|
|
1893
1933
|
return returnValue;
|
|
@@ -1899,7 +1939,7 @@ define((function () { 'use strict';
|
|
|
1899
1939
|
* @returns
|
|
1900
1940
|
*/
|
|
1901
1941
|
function appendPart(start, end) {
|
|
1902
|
-
var span =
|
|
1942
|
+
var span = DOMUtilsContext.windowApi.document.createElement("span");
|
|
1903
1943
|
span.style.cssText = cssDefaultStyles; //Force styles to prevent unexpected results
|
|
1904
1944
|
span.textContent = text.substring(start, end);
|
|
1905
1945
|
fakeClone.appendChild(span);
|
|
@@ -1907,7 +1947,7 @@ define((function () { 'use strict';
|
|
|
1907
1947
|
}
|
|
1908
1948
|
// Computing offset position
|
|
1909
1949
|
function getInputOffset() {
|
|
1910
|
-
let body =
|
|
1950
|
+
let body = DOMUtilsContext.windowApi.document.body, win = DOMUtilsContext.windowApi.document.defaultView, docElem = DOMUtilsContext.windowApi.document.documentElement, $box = DOMUtilsContext.windowApi.document.createElement("div");
|
|
1911
1951
|
$box.style.paddingLeft = $box.style.width = "1px";
|
|
1912
1952
|
body.appendChild($box);
|
|
1913
1953
|
var isBoxModel = $box.offsetWidth == 2;
|
|
@@ -1930,7 +1970,7 @@ define((function () { 'use strict';
|
|
|
1930
1970
|
* @returns
|
|
1931
1971
|
*/
|
|
1932
1972
|
function getInputCSS(prop, isNumber) {
|
|
1933
|
-
var val =
|
|
1973
|
+
var val = DOMUtilsContext.windowApi.document
|
|
1934
1974
|
.defaultView.getComputedStyle($input, null)
|
|
1935
1975
|
.getPropertyValue(prop);
|
|
1936
1976
|
return isNumber ? parseFloat(val) : val;
|