@whitesev/domutils 1.5.11 → 1.6.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 +129 -75
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +129 -75
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +129 -75
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +129 -75
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +129 -75
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +129 -75
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/DOMUtils.d.ts +16 -12
- package/dist/types/src/DOMUtilsCommonUtils.d.ts +4 -0
- package/dist/types/src/DOMUtilsEvent.d.ts +18 -0
- package/dist/types/src/types/DOMUtilsEvent.d.ts +2 -1
- package/package.json +5 -3
- package/src/DOMUtils.ts +98 -254
- package/src/DOMUtilsCommonUtils.ts +9 -4
- package/src/DOMUtilsData.ts +1 -3
- package/src/DOMUtilsEvent.ts +121 -178
- package/src/types/DOMUtilsEvent.d.ts +2 -1
package/src/DOMUtils.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { DOMUtilsCommonUtils } from "./DOMUtilsCommonUtils";
|
|
2
2
|
import { DOMUtilsEvent } from "./DOMUtilsEvent";
|
|
3
3
|
import type { DOMUtilsCreateElementAttributesMap } from "./types/DOMUtilsEvent";
|
|
4
|
-
import {
|
|
5
|
-
ParseHTMLReturnType,
|
|
6
|
-
type DOMUtilsTargetElementType,
|
|
7
|
-
} from "./types/global";
|
|
4
|
+
import { ParseHTMLReturnType, type DOMUtilsTargetElementType } from "./types/global";
|
|
8
5
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
9
6
|
|
|
10
7
|
class DOMUtils extends DOMUtilsEvent {
|
|
@@ -12,7 +9,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
12
9
|
super(option);
|
|
13
10
|
}
|
|
14
11
|
/** 版本号 */
|
|
15
|
-
version = "2025.
|
|
12
|
+
version = "2025.8.11";
|
|
16
13
|
/**
|
|
17
14
|
* 获取元素的属性值
|
|
18
15
|
* @param element 目标元素
|
|
@@ -23,7 +20,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
23
20
|
* DOMUtils.attr("a.xx","href");
|
|
24
21
|
* > https://xxxx....
|
|
25
22
|
*/
|
|
26
|
-
attr(element: DOMUtilsTargetElementType, attrName: string): string;
|
|
23
|
+
attr(element: DOMUtilsTargetElementType | Element, attrName: string): string;
|
|
27
24
|
/**
|
|
28
25
|
* 设置元素的属性值
|
|
29
26
|
* @param element 目标元素
|
|
@@ -35,11 +32,11 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
35
32
|
* DOMUtils.attr("a.xx","href","abcd");
|
|
36
33
|
*/
|
|
37
34
|
attr(
|
|
38
|
-
element: DOMUtilsTargetElementType,
|
|
35
|
+
element: DOMUtilsTargetElementType | Element,
|
|
39
36
|
attrName: string,
|
|
40
37
|
attrValue: string | boolean | number
|
|
41
38
|
): void;
|
|
42
|
-
attr(element: DOMUtilsTargetElementType, attrName: string, attrValue?: any) {
|
|
39
|
+
attr(element: DOMUtilsTargetElementType | Element, attrName: string, attrValue?: any) {
|
|
43
40
|
let DOMUtilsContext = this;
|
|
44
41
|
if (typeof element === "string") {
|
|
45
42
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -50,11 +47,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
50
47
|
if (DOMUtilsCommonUtils.isNodeList(element)) {
|
|
51
48
|
if (attrValue == null) {
|
|
52
49
|
// 获取属性
|
|
53
|
-
return DOMUtilsContext.attr(
|
|
54
|
-
element[0] as HTMLElement,
|
|
55
|
-
attrName,
|
|
56
|
-
attrValue
|
|
57
|
-
);
|
|
50
|
+
return DOMUtilsContext.attr(element[0] as HTMLElement, attrName, attrValue);
|
|
58
51
|
} else {
|
|
59
52
|
// 设置属性
|
|
60
53
|
element.forEach(($ele) => {
|
|
@@ -199,10 +192,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
199
192
|
element: DOMUtilsTargetElementType,
|
|
200
193
|
property:
|
|
201
194
|
| {
|
|
202
|
-
[P in keyof Omit<
|
|
203
|
-
CSSStyleDeclaration,
|
|
204
|
-
"zIndex"
|
|
205
|
-
>]?: CSSStyleDeclaration[P];
|
|
195
|
+
[P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: CSSStyleDeclaration[P];
|
|
206
196
|
}
|
|
207
197
|
| {
|
|
208
198
|
"z-index": string | number;
|
|
@@ -217,10 +207,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
217
207
|
| keyof Omit<CSSStyleDeclaration, "zIndex">
|
|
218
208
|
| string
|
|
219
209
|
| {
|
|
220
|
-
[P in keyof Omit<CSSStyleDeclaration, "zIndex">]?:
|
|
221
|
-
| string
|
|
222
|
-
| number
|
|
223
|
-
| CSSStyleDeclaration[P];
|
|
210
|
+
[P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: string | number | CSSStyleDeclaration[P];
|
|
224
211
|
},
|
|
225
212
|
value?: string | number
|
|
226
213
|
) {
|
|
@@ -229,15 +216,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
229
216
|
* 把纯数字没有px的加上
|
|
230
217
|
*/
|
|
231
218
|
function handlePixe(propertyName: string, propertyValue: string | number) {
|
|
232
|
-
let allowAddPixe = [
|
|
233
|
-
"width",
|
|
234
|
-
"height",
|
|
235
|
-
"top",
|
|
236
|
-
"left",
|
|
237
|
-
"right",
|
|
238
|
-
"bottom",
|
|
239
|
-
"font-size",
|
|
240
|
-
];
|
|
219
|
+
let allowAddPixe = ["width", "height", "top", "left", "right", "bottom", "font-size"];
|
|
241
220
|
if (typeof propertyValue === "number") {
|
|
242
221
|
propertyValue = propertyValue.toString();
|
|
243
222
|
}
|
|
@@ -278,14 +257,8 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
278
257
|
}
|
|
279
258
|
return;
|
|
280
259
|
}
|
|
281
|
-
let setStyleProperty = (
|
|
282
|
-
|
|
283
|
-
propertyValue: string | number
|
|
284
|
-
) => {
|
|
285
|
-
if (
|
|
286
|
-
typeof propertyValue === "string" &&
|
|
287
|
-
propertyValue.trim().endsWith("!important")
|
|
288
|
-
) {
|
|
260
|
+
let setStyleProperty = (propertyName: string, propertyValue: string | number) => {
|
|
261
|
+
if (typeof propertyValue === "string" && propertyValue.trim().endsWith("!important")) {
|
|
289
262
|
propertyValue = propertyValue
|
|
290
263
|
.trim()
|
|
291
264
|
.replace(/!important$/gi, "")
|
|
@@ -298,9 +271,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
298
271
|
};
|
|
299
272
|
if (typeof property === "string") {
|
|
300
273
|
if (value == null) {
|
|
301
|
-
return DOMUtilsContext.windowApi.globalThis
|
|
302
|
-
.getComputedStyle(element)
|
|
303
|
-
.getPropertyValue(property);
|
|
274
|
+
return DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue(property);
|
|
304
275
|
} else {
|
|
305
276
|
setStyleProperty(property, value);
|
|
306
277
|
}
|
|
@@ -337,10 +308,10 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
337
308
|
* DOMUtils.text("a.xx",document.querySelector("b"))
|
|
338
309
|
* */
|
|
339
310
|
text(
|
|
340
|
-
element: DOMUtilsTargetElementType,
|
|
311
|
+
element: DOMUtilsTargetElementType | DocumentFragment,
|
|
341
312
|
text: string | HTMLElement | Element | number
|
|
342
313
|
): void;
|
|
343
|
-
text(element: DOMUtilsTargetElementType, text?: any) {
|
|
314
|
+
text(element: DOMUtilsTargetElementType | DocumentFragment, text?: any) {
|
|
344
315
|
let DOMUtilsContext = this;
|
|
345
316
|
if (typeof element === "string") {
|
|
346
317
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -361,7 +332,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
361
332
|
return;
|
|
362
333
|
}
|
|
363
334
|
if (text == null) {
|
|
364
|
-
return element.textContent || element.innerText;
|
|
335
|
+
return element.textContent || (<HTMLElement>element).innerText;
|
|
365
336
|
} else {
|
|
366
337
|
if (text instanceof Node) {
|
|
367
338
|
text = text.textContent || (text as HTMLElement).innerText;
|
|
@@ -385,10 +356,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
385
356
|
* DOMUtils.html("a.xx","<b>abcd</b>")
|
|
386
357
|
* DOMUtils.html("a.xx",document.querySelector("b"))
|
|
387
358
|
* */
|
|
388
|
-
html(
|
|
389
|
-
element: DOMUtilsTargetElementType,
|
|
390
|
-
html: string | HTMLElement | Element | number
|
|
391
|
-
): void;
|
|
359
|
+
html(element: DOMUtilsTargetElementType, html: string | HTMLElement | Element | number): void;
|
|
392
360
|
/**
|
|
393
361
|
* 获取元素的HTML内容
|
|
394
362
|
* @param element 目标元素
|
|
@@ -454,16 +422,9 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
454
422
|
recovery();
|
|
455
423
|
return transformInfo;
|
|
456
424
|
}
|
|
457
|
-
let elementTransform =
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
elementTransform != null &&
|
|
461
|
-
elementTransform !== "none" &&
|
|
462
|
-
elementTransform !== ""
|
|
463
|
-
) {
|
|
464
|
-
let elementTransformSplit = elementTransform
|
|
465
|
-
.match(/\((.+)\)/)?.[1]
|
|
466
|
-
.split(",");
|
|
425
|
+
let elementTransform = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).transform;
|
|
426
|
+
if (elementTransform != null && elementTransform !== "none" && elementTransform !== "") {
|
|
427
|
+
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
467
428
|
if (elementTransformSplit) {
|
|
468
429
|
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
469
430
|
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
@@ -562,20 +523,14 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
562
523
|
}
|
|
563
524
|
if (value == null) {
|
|
564
525
|
// 获取
|
|
565
|
-
if (
|
|
566
|
-
element.localName === "input" &&
|
|
567
|
-
(element.type === "checkbox" || element.type === "radio")
|
|
568
|
-
) {
|
|
526
|
+
if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
|
|
569
527
|
return (element as HTMLInputElement).checked;
|
|
570
528
|
} else {
|
|
571
529
|
return element.value;
|
|
572
530
|
}
|
|
573
531
|
} else {
|
|
574
532
|
// 设置
|
|
575
|
-
if (
|
|
576
|
-
element.localName === "input" &&
|
|
577
|
-
(element.type === "checkbox" || element.type === "radio")
|
|
578
|
-
) {
|
|
533
|
+
if (element.localName === "input" && (element.type === "checkbox" || element.type === "radio")) {
|
|
579
534
|
(element as HTMLInputElement).checked = !!value;
|
|
580
535
|
} else {
|
|
581
536
|
element.value = value as string;
|
|
@@ -594,7 +549,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
594
549
|
* DOMUtils.val("a.xx","data-value")
|
|
595
550
|
* > undefined
|
|
596
551
|
* */
|
|
597
|
-
prop<T extends any>(element: DOMUtilsTargetElementType, propName: string): T;
|
|
552
|
+
prop<T extends any>(element: DOMUtilsTargetElementType | DocumentFragment, propName: string): T;
|
|
598
553
|
/**
|
|
599
554
|
* 设置元素的属性值
|
|
600
555
|
* @param element 目标元素
|
|
@@ -606,11 +561,11 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
606
561
|
* DOMUtils.val("a.xx","data-value",1)
|
|
607
562
|
* */
|
|
608
563
|
prop<T extends any>(
|
|
609
|
-
element: DOMUtilsTargetElementType,
|
|
564
|
+
element: DOMUtilsTargetElementType | DocumentFragment,
|
|
610
565
|
propName: string,
|
|
611
566
|
propValue: T
|
|
612
567
|
): void;
|
|
613
|
-
prop(element: DOMUtilsTargetElementType, propName: string, propValue?: any) {
|
|
568
|
+
prop(element: DOMUtilsTargetElementType | DocumentFragment, propName: string, propValue?: any) {
|
|
614
569
|
let DOMUtilsContext = this;
|
|
615
570
|
if (typeof element === "string") {
|
|
616
571
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -649,7 +604,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
649
604
|
* DOMUtils.removeAttr(document.querySelector("a.xx"),"data-value")
|
|
650
605
|
* DOMUtils.removeAttr("a.xx","data-value")
|
|
651
606
|
* */
|
|
652
|
-
removeAttr(element: DOMUtilsTargetElementType, attrName: string) {
|
|
607
|
+
removeAttr(element: DOMUtilsTargetElementType | Element, attrName: string) {
|
|
653
608
|
let DOMUtilsContext = this;
|
|
654
609
|
if (typeof element === "string") {
|
|
655
610
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -676,7 +631,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
676
631
|
* DOMUtils.removeClass("a.xx","xx")
|
|
677
632
|
*/
|
|
678
633
|
removeClass(
|
|
679
|
-
element: DOMUtilsTargetElementType,
|
|
634
|
+
element: DOMUtilsTargetElementType | Element,
|
|
680
635
|
className?: string | string[] | undefined | null
|
|
681
636
|
) {
|
|
682
637
|
let DOMUtilsContext = this;
|
|
@@ -714,7 +669,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
714
669
|
* DOMUtils.removeProp(document.querySelector("a.xx"),"href")
|
|
715
670
|
* DOMUtils.removeProp("a.xx","href")
|
|
716
671
|
* */
|
|
717
|
-
removeProp(element: DOMUtilsTargetElementType, propName: string) {
|
|
672
|
+
removeProp(element: DOMUtilsTargetElementType | DocumentFragment, propName: string) {
|
|
718
673
|
let DOMUtilsContext = this;
|
|
719
674
|
if (typeof element === "string") {
|
|
720
675
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -740,10 +695,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
740
695
|
* DOMUtils.replaceWith(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
741
696
|
* DOMUtils.replaceWith("a.xx",'<b class="xx"></b>')
|
|
742
697
|
*/
|
|
743
|
-
replaceWith(
|
|
744
|
-
element: DOMUtilsTargetElementType,
|
|
745
|
-
newElement: HTMLElement | string | Node
|
|
746
|
-
) {
|
|
698
|
+
replaceWith(element: DOMUtilsTargetElementType, newElement: HTMLElement | string | Node) {
|
|
747
699
|
let DOMUtilsContext = this;
|
|
748
700
|
if (typeof element === "string") {
|
|
749
701
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -772,7 +724,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
772
724
|
* DOMUtils.addClass(document.querySelector("a.xx"),"_vue_")
|
|
773
725
|
* DOMUtils.addClass("a.xx","_vue_")
|
|
774
726
|
* */
|
|
775
|
-
addClass(element: DOMUtilsTargetElementType, className: string | string[]) {
|
|
727
|
+
addClass(element: DOMUtilsTargetElementType | Element, className: string | string[]) {
|
|
776
728
|
let DOMUtilsContext = this;
|
|
777
729
|
if (typeof element === "string") {
|
|
778
730
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -802,10 +754,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
802
754
|
* @param element
|
|
803
755
|
* @param className
|
|
804
756
|
*/
|
|
805
|
-
hasClass(
|
|
806
|
-
element: DOMUtilsTargetElementType,
|
|
807
|
-
className: string | string[]
|
|
808
|
-
): boolean {
|
|
757
|
+
hasClass(element: DOMUtilsTargetElementType | Element, className: string | string[]): boolean {
|
|
809
758
|
let DOMUtilsContext = this;
|
|
810
759
|
if (typeof element === "string") {
|
|
811
760
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -845,12 +794,8 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
845
794
|
* DOMUtils.append("a.xx","'<b class="xx"></b>")
|
|
846
795
|
* */
|
|
847
796
|
append(
|
|
848
|
-
element: DOMUtilsTargetElementType,
|
|
849
|
-
content:
|
|
850
|
-
| HTMLElement
|
|
851
|
-
| string
|
|
852
|
-
| (HTMLElement | string | Element)[]
|
|
853
|
-
| NodeList
|
|
797
|
+
element: DOMUtilsTargetElementType | DocumentFragment,
|
|
798
|
+
content: HTMLElement | string | (HTMLElement | string | Element)[] | NodeList
|
|
854
799
|
) {
|
|
855
800
|
let DOMUtilsContext = this;
|
|
856
801
|
if (typeof element === "string") {
|
|
@@ -867,22 +812,26 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
867
812
|
});
|
|
868
813
|
return;
|
|
869
814
|
}
|
|
870
|
-
function elementAppendChild(ele: HTMLElement, text: HTMLElement | string) {
|
|
815
|
+
function elementAppendChild(ele: HTMLElement | DocumentFragment, text: HTMLElement | string) {
|
|
871
816
|
if (typeof content === "string") {
|
|
872
|
-
ele
|
|
873
|
-
"
|
|
874
|
-
|
|
875
|
-
|
|
817
|
+
if (ele instanceof DocumentFragment) {
|
|
818
|
+
if (typeof text === "string") {
|
|
819
|
+
text = DOMUtilsContext.parseHTML(text, true, false);
|
|
820
|
+
}
|
|
821
|
+
ele.appendChild(text);
|
|
822
|
+
} else {
|
|
823
|
+
ele.insertAdjacentHTML("beforeend", DOMUtilsCommonUtils.getSafeHTML(text as string));
|
|
824
|
+
}
|
|
876
825
|
} else {
|
|
877
826
|
ele.appendChild(text as HTMLElement);
|
|
878
827
|
}
|
|
879
828
|
}
|
|
880
829
|
if (Array.isArray(content) || content instanceof NodeList) {
|
|
881
830
|
/* 数组 */
|
|
882
|
-
let fragment =
|
|
883
|
-
DOMUtilsContext.windowApi.document.createDocumentFragment();
|
|
831
|
+
let fragment = DOMUtilsContext.windowApi.document.createDocumentFragment();
|
|
884
832
|
content.forEach((ele) => {
|
|
885
833
|
if (typeof ele === "string") {
|
|
834
|
+
// 转为元素
|
|
886
835
|
ele = DOMUtilsContext.parseHTML(ele, true, false);
|
|
887
836
|
}
|
|
888
837
|
fragment.appendChild(ele);
|
|
@@ -901,7 +850,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
901
850
|
* DOMUtils.prepend(document.querySelector("a.xx"),document.querySelector("b.xx"))
|
|
902
851
|
* DOMUtils.prepend("a.xx","'<b class="xx"></b>")
|
|
903
852
|
* */
|
|
904
|
-
prepend(element: DOMUtilsTargetElementType, content: HTMLElement | string) {
|
|
853
|
+
prepend(element: DOMUtilsTargetElementType | DocumentFragment, content: HTMLElement | string) {
|
|
905
854
|
let DOMUtilsContext = this;
|
|
906
855
|
if (typeof element === "string") {
|
|
907
856
|
element = DOMUtilsContext.selectorAll(element);
|
|
@@ -917,10 +866,12 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
917
866
|
return;
|
|
918
867
|
}
|
|
919
868
|
if (typeof content === "string") {
|
|
920
|
-
element
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
869
|
+
if (element instanceof DocumentFragment) {
|
|
870
|
+
content = DOMUtilsContext.parseHTML(content, true, false);
|
|
871
|
+
element.prepend(content);
|
|
872
|
+
} else {
|
|
873
|
+
element.insertAdjacentHTML("afterbegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
874
|
+
}
|
|
924
875
|
} else {
|
|
925
876
|
let $firstChild = element.firstChild;
|
|
926
877
|
if ($firstChild == null) {
|
|
@@ -955,10 +906,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
955
906
|
return;
|
|
956
907
|
}
|
|
957
908
|
if (typeof content === "string") {
|
|
958
|
-
element.insertAdjacentHTML(
|
|
959
|
-
"afterend",
|
|
960
|
-
DOMUtilsCommonUtils.getSafeHTML(content)
|
|
961
|
-
);
|
|
909
|
+
element.insertAdjacentHTML("afterend", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
962
910
|
} else {
|
|
963
911
|
let $parent = element.parentElement;
|
|
964
912
|
let $nextSlibling = element.nextSibling;
|
|
@@ -995,10 +943,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
995
943
|
return;
|
|
996
944
|
}
|
|
997
945
|
if (typeof content === "string") {
|
|
998
|
-
element.insertAdjacentHTML(
|
|
999
|
-
"beforebegin",
|
|
1000
|
-
DOMUtilsCommonUtils.getSafeHTML(content)
|
|
1001
|
-
);
|
|
946
|
+
element.insertAdjacentHTML("beforebegin", DOMUtilsCommonUtils.getSafeHTML(content));
|
|
1002
947
|
} else {
|
|
1003
948
|
let $parent = element.parentElement;
|
|
1004
949
|
if (!$parent) {
|
|
@@ -1103,10 +1048,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1103
1048
|
* DOMUtils.width(document.querySelector("a.xx"),200)
|
|
1104
1049
|
* DOMUtils.width("a.xx",200)
|
|
1105
1050
|
*/
|
|
1106
|
-
width(
|
|
1107
|
-
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1108
|
-
isShow?: boolean
|
|
1109
|
-
): number;
|
|
1051
|
+
width(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
|
|
1110
1052
|
width(
|
|
1111
1053
|
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1112
1054
|
isShow: boolean = false
|
|
@@ -1120,8 +1062,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1120
1062
|
return;
|
|
1121
1063
|
}
|
|
1122
1064
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1123
|
-
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
1124
|
-
.clientWidth;
|
|
1065
|
+
return DOMUtilsContext.windowApi.window.document.documentElement.clientWidth;
|
|
1125
1066
|
}
|
|
1126
1067
|
if ((element as HTMLElement).nodeType === 9) {
|
|
1127
1068
|
/* Document文档节点 */
|
|
@@ -1134,42 +1075,21 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1134
1075
|
element.documentElement.clientWidth
|
|
1135
1076
|
);
|
|
1136
1077
|
}
|
|
1137
|
-
if (
|
|
1138
|
-
isShow ||
|
|
1139
|
-
(!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))
|
|
1140
|
-
) {
|
|
1078
|
+
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))) {
|
|
1141
1079
|
/* 已显示 */
|
|
1142
1080
|
/* 不从style中获取对应的宽度,因为可能使用了class定义了width !important */
|
|
1143
1081
|
element = element as HTMLElement;
|
|
1144
1082
|
/* 如果element.style.width为空 则从css里面获取是否定义了width信息如果定义了 则读取css里面定义的宽度width */
|
|
1145
|
-
if (
|
|
1146
|
-
parseFloat(
|
|
1147
|
-
DOMUtilsCommonUtils.getStyleValue(element, "width").toString()
|
|
1148
|
-
) > 0
|
|
1149
|
-
) {
|
|
1150
|
-
return parseFloat(
|
|
1151
|
-
DOMUtilsCommonUtils.getStyleValue(element, "width").toString()
|
|
1152
|
-
);
|
|
1083
|
+
if (parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "width").toString()) > 0) {
|
|
1084
|
+
return parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "width").toString());
|
|
1153
1085
|
}
|
|
1154
1086
|
|
|
1155
1087
|
/* 如果从css里获取到的值不是大于0 可能是auto 则通过offsetWidth来进行计算 */
|
|
1156
1088
|
if (element.offsetWidth > 0) {
|
|
1157
|
-
let borderLeftWidth = DOMUtilsCommonUtils.getStyleValue(
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
);
|
|
1161
|
-
let borderRightWidth = DOMUtilsCommonUtils.getStyleValue(
|
|
1162
|
-
element,
|
|
1163
|
-
"borderRightWidth"
|
|
1164
|
-
);
|
|
1165
|
-
let paddingLeft = DOMUtilsCommonUtils.getStyleValue(
|
|
1166
|
-
element,
|
|
1167
|
-
"paddingLeft"
|
|
1168
|
-
);
|
|
1169
|
-
let paddingRight = DOMUtilsCommonUtils.getStyleValue(
|
|
1170
|
-
element,
|
|
1171
|
-
"paddingRight"
|
|
1172
|
-
);
|
|
1089
|
+
let borderLeftWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderLeftWidth");
|
|
1090
|
+
let borderRightWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderRightWidth");
|
|
1091
|
+
let paddingLeft = DOMUtilsCommonUtils.getStyleValue(element, "paddingLeft");
|
|
1092
|
+
let paddingRight = DOMUtilsCommonUtils.getStyleValue(element, "paddingRight");
|
|
1173
1093
|
let backHeight =
|
|
1174
1094
|
parseFloat(element.offsetWidth.toString()) -
|
|
1175
1095
|
parseFloat(borderLeftWidth.toString()) -
|
|
@@ -1207,18 +1127,14 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1207
1127
|
* DOMUtils.height(document.querySelector("a.xx"),200)
|
|
1208
1128
|
* DOMUtils.height("a.xx",200)
|
|
1209
1129
|
*/
|
|
1210
|
-
height(
|
|
1211
|
-
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1212
|
-
isShow?: boolean
|
|
1213
|
-
): number;
|
|
1130
|
+
height(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
|
|
1214
1131
|
height(
|
|
1215
1132
|
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1216
1133
|
isShow: boolean = false
|
|
1217
1134
|
): number {
|
|
1218
1135
|
let DOMUtilsContext = this;
|
|
1219
1136
|
if (DOMUtilsCommonUtils.isWin(element)) {
|
|
1220
|
-
return DOMUtilsContext.windowApi.window.document.documentElement
|
|
1221
|
-
.clientHeight;
|
|
1137
|
+
return DOMUtilsContext.windowApi.window.document.documentElement.clientHeight;
|
|
1222
1138
|
}
|
|
1223
1139
|
if (typeof element === "string") {
|
|
1224
1140
|
element = DOMUtilsContext.selector(element) as HTMLElement;
|
|
@@ -1238,42 +1154,21 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1238
1154
|
element.documentElement.clientHeight
|
|
1239
1155
|
);
|
|
1240
1156
|
}
|
|
1241
|
-
if (
|
|
1242
|
-
isShow ||
|
|
1243
|
-
(!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))
|
|
1244
|
-
) {
|
|
1157
|
+
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element as HTMLElement))) {
|
|
1245
1158
|
element = element as HTMLElement;
|
|
1246
1159
|
/* 已显示 */
|
|
1247
1160
|
/* 从style中获取对应的高度,因为可能使用了class定义了width !important */
|
|
1248
1161
|
/* 如果element.style.height为空 则从css里面获取是否定义了height信息如果定义了 则读取css里面定义的高度height */
|
|
1249
|
-
if (
|
|
1250
|
-
parseFloat(
|
|
1251
|
-
DOMUtilsCommonUtils.getStyleValue(element, "height").toString()
|
|
1252
|
-
) > 0
|
|
1253
|
-
) {
|
|
1254
|
-
return parseFloat(
|
|
1255
|
-
DOMUtilsCommonUtils.getStyleValue(element, "height").toString()
|
|
1256
|
-
);
|
|
1162
|
+
if (parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "height").toString()) > 0) {
|
|
1163
|
+
return parseFloat(DOMUtilsCommonUtils.getStyleValue(element, "height").toString());
|
|
1257
1164
|
}
|
|
1258
1165
|
|
|
1259
1166
|
/* 如果从css里获取到的值不是大于0 可能是auto 则通过offsetHeight来进行计算 */
|
|
1260
1167
|
if (element.offsetHeight > 0) {
|
|
1261
|
-
let borderTopWidth = DOMUtilsCommonUtils.getStyleValue(
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
);
|
|
1265
|
-
let borderBottomWidth = DOMUtilsCommonUtils.getStyleValue(
|
|
1266
|
-
element,
|
|
1267
|
-
"borderBottomWidth"
|
|
1268
|
-
);
|
|
1269
|
-
let paddingTop = DOMUtilsCommonUtils.getStyleValue(
|
|
1270
|
-
element,
|
|
1271
|
-
"paddingTop"
|
|
1272
|
-
);
|
|
1273
|
-
let paddingBottom = DOMUtilsCommonUtils.getStyleValue(
|
|
1274
|
-
element,
|
|
1275
|
-
"paddingBottom"
|
|
1276
|
-
);
|
|
1168
|
+
let borderTopWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderTopWidth");
|
|
1169
|
+
let borderBottomWidth = DOMUtilsCommonUtils.getStyleValue(element, "borderBottomWidth");
|
|
1170
|
+
let paddingTop = DOMUtilsCommonUtils.getStyleValue(element, "paddingTop");
|
|
1171
|
+
let paddingBottom = DOMUtilsCommonUtils.getStyleValue(element, "paddingBottom");
|
|
1277
1172
|
let backHeight =
|
|
1278
1173
|
parseFloat(element.offsetHeight.toString()) -
|
|
1279
1174
|
parseFloat(borderTopWidth.toString()) -
|
|
@@ -1306,10 +1201,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1306
1201
|
* DOMUtils.outerWidth(window)
|
|
1307
1202
|
* > 400
|
|
1308
1203
|
*/
|
|
1309
|
-
outerWidth(
|
|
1310
|
-
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1311
|
-
isShow?: boolean
|
|
1312
|
-
): number;
|
|
1204
|
+
outerWidth(element: HTMLElement | string | Window | typeof globalThis | Document, isShow?: boolean): number;
|
|
1313
1205
|
outerWidth(
|
|
1314
1206
|
element: HTMLElement | string | Window | typeof globalThis | Document,
|
|
1315
1207
|
isShow: boolean = false
|
|
@@ -1327,10 +1219,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1327
1219
|
}
|
|
1328
1220
|
element = element as HTMLElement;
|
|
1329
1221
|
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
1330
|
-
let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(
|
|
1331
|
-
element,
|
|
1332
|
-
null
|
|
1333
|
-
);
|
|
1222
|
+
let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
|
|
1334
1223
|
let marginLeft = DOMUtilsCommonUtils.getStyleValue(style, "marginLeft");
|
|
1335
1224
|
let marginRight = DOMUtilsCommonUtils.getStyleValue(style, "marginRight");
|
|
1336
1225
|
return element.offsetWidth + marginLeft + marginRight;
|
|
@@ -1376,15 +1265,9 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1376
1265
|
}
|
|
1377
1266
|
element = element as HTMLElement;
|
|
1378
1267
|
if (isShow || (!isShow && DOMUtilsCommonUtils.isShow(element))) {
|
|
1379
|
-
let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(
|
|
1380
|
-
element,
|
|
1381
|
-
null
|
|
1382
|
-
);
|
|
1268
|
+
let style = DOMUtilsContext.windowApi.globalThis.getComputedStyle(element, null);
|
|
1383
1269
|
let marginTop = DOMUtilsCommonUtils.getStyleValue(style, "marginTop");
|
|
1384
|
-
let marginBottom = DOMUtilsCommonUtils.getStyleValue(
|
|
1385
|
-
style,
|
|
1386
|
-
"marginBottom"
|
|
1387
|
-
);
|
|
1270
|
+
let marginBottom = DOMUtilsCommonUtils.getStyleValue(style, "marginBottom");
|
|
1388
1271
|
return element.offsetHeight + marginTop + marginBottom;
|
|
1389
1272
|
} else {
|
|
1390
1273
|
let { recovery } = DOMUtilsCommonUtils.showElement(element);
|
|
@@ -1421,12 +1304,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1421
1304
|
if (DOMUtilsCommonUtils.isNodeList(element)) {
|
|
1422
1305
|
// 设置
|
|
1423
1306
|
element.forEach(($ele) => {
|
|
1424
|
-
DOMUtilsContext.animate(
|
|
1425
|
-
$ele as HTMLElement,
|
|
1426
|
-
styles,
|
|
1427
|
-
duration,
|
|
1428
|
-
callback
|
|
1429
|
-
);
|
|
1307
|
+
DOMUtilsContext.animate($ele as HTMLElement, styles, duration, callback);
|
|
1430
1308
|
});
|
|
1431
1309
|
return;
|
|
1432
1310
|
}
|
|
@@ -1451,8 +1329,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1451
1329
|
} = {};
|
|
1452
1330
|
for (let prop in styles) {
|
|
1453
1331
|
from[prop] =
|
|
1454
|
-
element.style[prop] ||
|
|
1455
|
-
DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
|
|
1332
|
+
element.style[prop] || DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
|
|
1456
1333
|
to[prop] = styles[prop];
|
|
1457
1334
|
}
|
|
1458
1335
|
let timer = DOMUtilsCommonUtils.setInterval(function () {
|
|
@@ -1462,8 +1339,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1462
1339
|
progress = 1;
|
|
1463
1340
|
}
|
|
1464
1341
|
for (let prop in styles) {
|
|
1465
|
-
element.style[prop] =
|
|
1466
|
-
from[prop] + (to[prop] - from[prop]) * progress + "px";
|
|
1342
|
+
element.style[prop] = from[prop] + (to[prop] - from[prop]) * progress + "px";
|
|
1467
1343
|
}
|
|
1468
1344
|
if (progress === 1) {
|
|
1469
1345
|
DOMUtilsCommonUtils.clearInterval(timer);
|
|
@@ -1585,8 +1461,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1585
1461
|
return;
|
|
1586
1462
|
}
|
|
1587
1463
|
return Array.from(
|
|
1588
|
-
(element.parentElement as HTMLElement)
|
|
1589
|
-
.children as HTMLCollectionOf<HTMLElement>
|
|
1464
|
+
(element.parentElement as HTMLElement).children as HTMLCollectionOf<HTMLElement>
|
|
1590
1465
|
).filter((child) => child !== element);
|
|
1591
1466
|
}
|
|
1592
1467
|
/**
|
|
@@ -1711,30 +1586,16 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1711
1586
|
let serializedArray: { name: string; value: string }[] = [];
|
|
1712
1587
|
|
|
1713
1588
|
for (let i = 0; i < elements.length; i++) {
|
|
1714
|
-
const element = elements[i] as
|
|
1715
|
-
| HTMLInputElement
|
|
1716
|
-
| HTMLSelectElement
|
|
1717
|
-
| HTMLTextAreaElement;
|
|
1589
|
+
const element = elements[i] as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
1718
1590
|
|
|
1719
1591
|
if (
|
|
1720
1592
|
element.name &&
|
|
1721
1593
|
!element.disabled &&
|
|
1722
1594
|
((element as HTMLInputElement).checked ||
|
|
1723
|
-
[
|
|
1724
|
-
"text",
|
|
1725
|
-
"hidden",
|
|
1726
|
-
"password",
|
|
1727
|
-
"textarea",
|
|
1728
|
-
"select-one",
|
|
1729
|
-
"select-multiple",
|
|
1730
|
-
].includes(element.type))
|
|
1595
|
+
["text", "hidden", "password", "textarea", "select-one", "select-multiple"].includes(element.type))
|
|
1731
1596
|
) {
|
|
1732
1597
|
if (element.type === "select-multiple") {
|
|
1733
|
-
for (
|
|
1734
|
-
let j = 0;
|
|
1735
|
-
j < (element as HTMLSelectElement).options.length;
|
|
1736
|
-
j++
|
|
1737
|
-
) {
|
|
1598
|
+
for (let j = 0; j < (element as HTMLSelectElement).options.length; j++) {
|
|
1738
1599
|
if ((element as HTMLSelectElement).options[j].selected) {
|
|
1739
1600
|
serializedArray.push({
|
|
1740
1601
|
name: (element as HTMLSelectElement).name,
|
|
@@ -1749,10 +1610,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1749
1610
|
}
|
|
1750
1611
|
|
|
1751
1612
|
return serializedArray
|
|
1752
|
-
.map(
|
|
1753
|
-
(item) =>
|
|
1754
|
-
`${encodeURIComponent(item.name)}=${encodeURIComponent(item.value)}`
|
|
1755
|
-
)
|
|
1613
|
+
.map((item) => `${encodeURIComponent(item.name)}=${encodeURIComponent(item.value)}`)
|
|
1756
1614
|
.join("&");
|
|
1757
1615
|
}
|
|
1758
1616
|
/**
|
|
@@ -1841,11 +1699,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1841
1699
|
* console.log("淡入完毕");
|
|
1842
1700
|
* })
|
|
1843
1701
|
*/
|
|
1844
|
-
fadeIn(
|
|
1845
|
-
element: DOMUtilsTargetElementType,
|
|
1846
|
-
duration: number = 400,
|
|
1847
|
-
callback?: () => void
|
|
1848
|
-
) {
|
|
1702
|
+
fadeIn(element: DOMUtilsTargetElementType, duration: number = 400, callback?: () => void) {
|
|
1849
1703
|
if (element == null) {
|
|
1850
1704
|
return;
|
|
1851
1705
|
}
|
|
@@ -1894,11 +1748,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1894
1748
|
* console.log("淡出完毕");
|
|
1895
1749
|
* })
|
|
1896
1750
|
*/
|
|
1897
|
-
fadeOut(
|
|
1898
|
-
element: DOMUtilsTargetElementType,
|
|
1899
|
-
duration: number = 400,
|
|
1900
|
-
callback?: () => void
|
|
1901
|
-
) {
|
|
1751
|
+
fadeOut(element: DOMUtilsTargetElementType, duration: number = 400, callback?: () => void) {
|
|
1902
1752
|
let DOMUtilsContext = this;
|
|
1903
1753
|
if (element == null) {
|
|
1904
1754
|
return;
|
|
@@ -1958,9 +1808,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1958
1808
|
return;
|
|
1959
1809
|
}
|
|
1960
1810
|
if (
|
|
1961
|
-
DOMUtilsContext.windowApi.globalThis
|
|
1962
|
-
.getComputedStyle(element)
|
|
1963
|
-
.getPropertyValue("display") === "none"
|
|
1811
|
+
DOMUtilsContext.windowApi.globalThis.getComputedStyle(element).getPropertyValue("display") === "none"
|
|
1964
1812
|
) {
|
|
1965
1813
|
DOMUtilsContext.show(element, checkVisiblie);
|
|
1966
1814
|
} else {
|
|
@@ -1997,20 +1845,14 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1997
1845
|
if (selectionEnd == null) {
|
|
1998
1846
|
selectionEnd = $input.selectionEnd || 0;
|
|
1999
1847
|
}
|
|
2000
|
-
if (typeof selectionStart == "string")
|
|
2001
|
-
selectionStart = parseFloat(selectionStart);
|
|
1848
|
+
if (typeof selectionStart == "string") selectionStart = parseFloat(selectionStart);
|
|
2002
1849
|
if (typeof selectionStart != "number" || isNaN(selectionStart)) {
|
|
2003
1850
|
selectionStart = 0;
|
|
2004
1851
|
}
|
|
2005
1852
|
if (selectionStart < 0) selectionStart = 0;
|
|
2006
1853
|
else selectionStart = Math.min($input.value.length, selectionStart);
|
|
2007
|
-
if (typeof selectionEnd == "string")
|
|
2008
|
-
|
|
2009
|
-
if (
|
|
2010
|
-
typeof selectionEnd != "number" ||
|
|
2011
|
-
isNaN(selectionEnd) ||
|
|
2012
|
-
selectionEnd < selectionStart
|
|
2013
|
-
) {
|
|
1854
|
+
if (typeof selectionEnd == "string") selectionEnd = parseFloat(selectionEnd);
|
|
1855
|
+
if (typeof selectionEnd != "number" || isNaN(selectionEnd) || selectionEnd < selectionStart) {
|
|
2014
1856
|
selectionEnd = selectionStart;
|
|
2015
1857
|
}
|
|
2016
1858
|
if (selectionEnd < 0) selectionEnd = 0;
|
|
@@ -2112,14 +1954,8 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
2112
1954
|
let $boxRect = $input.getBoundingClientRect();
|
|
2113
1955
|
var clientTop = docElem.clientTop || body.clientTop || 0,
|
|
2114
1956
|
clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
|
2115
|
-
scrollTop =
|
|
2116
|
-
|
|
2117
|
-
(isBoxModel && docElem.scrollTop) ||
|
|
2118
|
-
body.scrollTop,
|
|
2119
|
-
scrollLeft =
|
|
2120
|
-
win.pageXOffset ||
|
|
2121
|
-
(isBoxModel && docElem.scrollLeft) ||
|
|
2122
|
-
body.scrollLeft;
|
|
1957
|
+
scrollTop = win.pageYOffset || (isBoxModel && docElem.scrollTop) || body.scrollTop,
|
|
1958
|
+
scrollLeft = win.pageXOffset || (isBoxModel && docElem.scrollLeft) || body.scrollLeft;
|
|
2123
1959
|
return {
|
|
2124
1960
|
top: $boxRect.top + scrollTop - clientTop,
|
|
2125
1961
|
left: $boxRect.left + scrollLeft - clientLeft,
|
|
@@ -2138,6 +1974,14 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
2138
1974
|
return isNumber ? parseFloat(val) : val;
|
|
2139
1975
|
}
|
|
2140
1976
|
}
|
|
1977
|
+
/** 获取 animationend 在各个浏览器的兼容名 */
|
|
1978
|
+
getAnimationEndNameList() {
|
|
1979
|
+
return DOMUtilsCommonUtils.getAnimationEndNameList();
|
|
1980
|
+
}
|
|
1981
|
+
/** 获取 transitionend 在各个浏览器的兼容名 */
|
|
1982
|
+
getTransitionEndNameList() {
|
|
1983
|
+
return DOMUtilsCommonUtils.getTransitionEndNameList();
|
|
1984
|
+
}
|
|
2141
1985
|
}
|
|
2142
1986
|
|
|
2143
1987
|
let domUtils = new DOMUtils();
|