@whitesev/domutils 2.0.5 → 2.0.6
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 +34 -30
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +34 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +34 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +34 -30
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +34 -30
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +34 -30
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/CommonUtils.d.ts +10 -10
- package/dist/types/src/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/CommonUtils.ts +27 -27
- package/src/index.ts +11 -7
package/src/CommonUtils.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const CommonUtils = {
|
|
|
15
15
|
* 判断元素是否已显示或已连接
|
|
16
16
|
* @param $el
|
|
17
17
|
*/
|
|
18
|
-
isShow($el:
|
|
18
|
+
isShow($el: Element) {
|
|
19
19
|
return Boolean($el.getClientRects().length);
|
|
20
20
|
},
|
|
21
21
|
/**
|
|
@@ -37,7 +37,7 @@ export const CommonUtils = {
|
|
|
37
37
|
* @param $el 元素
|
|
38
38
|
* @param text 文本
|
|
39
39
|
*/
|
|
40
|
-
setSafeHTML($el:
|
|
40
|
+
setSafeHTML($el: Element, text: string) {
|
|
41
41
|
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
42
42
|
$el.innerHTML = this.createSafeHTML(text);
|
|
43
43
|
},
|
|
@@ -45,16 +45,16 @@ export const CommonUtils = {
|
|
|
45
45
|
* 用于强制显示元素并获取它的高度宽度等其它属性
|
|
46
46
|
* @param $el
|
|
47
47
|
*/
|
|
48
|
-
forceShow($el:
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
this.windowApi.document.documentElement.appendChild(
|
|
48
|
+
forceShow($el: Element) {
|
|
49
|
+
const $clone = $el.cloneNode(true) as HTMLElement;
|
|
50
|
+
$clone.setAttribute("style", "visibility: hidden !important;display:block !important;");
|
|
51
|
+
this.windowApi.document.documentElement.appendChild($clone);
|
|
52
52
|
return {
|
|
53
53
|
/**
|
|
54
54
|
* 恢复修改的style
|
|
55
55
|
*/
|
|
56
56
|
recovery() {
|
|
57
|
-
|
|
57
|
+
$clone.remove();
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
60
|
},
|
|
@@ -63,7 +63,7 @@ export const CommonUtils = {
|
|
|
63
63
|
* @param element
|
|
64
64
|
* @param styleName style名
|
|
65
65
|
*/
|
|
66
|
-
getStyleValue(element:
|
|
66
|
+
getStyleValue(element: Element | CSSStyleDeclaration, styleName: string) {
|
|
67
67
|
let view = null;
|
|
68
68
|
let styles = null;
|
|
69
69
|
if (element instanceof CSSStyleDeclaration) {
|
|
@@ -85,37 +85,37 @@ export const CommonUtils = {
|
|
|
85
85
|
},
|
|
86
86
|
/**
|
|
87
87
|
* 判断是否是window,例如window、self、globalThis
|
|
88
|
-
* @param
|
|
88
|
+
* @param obj
|
|
89
89
|
*/
|
|
90
|
-
isWin(
|
|
91
|
-
if (typeof
|
|
90
|
+
isWin(obj: any) {
|
|
91
|
+
if (typeof obj !== "object") {
|
|
92
92
|
return false;
|
|
93
93
|
}
|
|
94
|
-
if (
|
|
94
|
+
if (obj instanceof Node) {
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
|
-
if (
|
|
97
|
+
if (obj === globalThis) {
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
100
|
+
if (obj === window) {
|
|
101
101
|
return true;
|
|
102
102
|
}
|
|
103
|
-
if (
|
|
103
|
+
if (obj === self) {
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
|
-
if (
|
|
106
|
+
if (obj === globalThis) {
|
|
107
107
|
return true;
|
|
108
108
|
}
|
|
109
|
-
if (
|
|
109
|
+
if (obj === window) {
|
|
110
110
|
return true;
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
112
|
+
if (obj === self) {
|
|
113
113
|
return true;
|
|
114
114
|
}
|
|
115
|
-
if (typeof unsafeWindow !== "undefined" &&
|
|
115
|
+
if (typeof unsafeWindow !== "undefined" && obj === unsafeWindow) {
|
|
116
116
|
return true;
|
|
117
117
|
}
|
|
118
|
-
if (
|
|
118
|
+
if (obj?.Math?.toString() !== "[object Math]") {
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
121
|
return true;
|
|
@@ -135,22 +135,22 @@ export const CommonUtils = {
|
|
|
135
135
|
},
|
|
136
136
|
/**
|
|
137
137
|
* 删除对象上的属性
|
|
138
|
-
* @param
|
|
138
|
+
* @param obj
|
|
139
139
|
* @param propName
|
|
140
140
|
*/
|
|
141
|
-
delete(
|
|
141
|
+
delete(obj: any, propName: any) {
|
|
142
142
|
if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
|
|
143
|
-
return Reflect.deleteProperty(
|
|
143
|
+
return Reflect.deleteProperty(obj, propName);
|
|
144
144
|
} else {
|
|
145
|
-
delete
|
|
145
|
+
delete obj[propName];
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
/**
|
|
149
149
|
* 判断是否是元素列表
|
|
150
|
-
* @param $
|
|
150
|
+
* @param $el
|
|
151
151
|
*/
|
|
152
|
-
isNodeList($
|
|
153
|
-
return Array.isArray($
|
|
152
|
+
isNodeList($el: any): $el is any[] | NodeList {
|
|
153
|
+
return Array.isArray($el) || $el instanceof NodeList;
|
|
154
154
|
},
|
|
155
155
|
/** 获取 animationend 在各个浏览器的兼容名 */
|
|
156
156
|
getAnimationEndNameList() {
|
package/src/index.ts
CHANGED
|
@@ -1059,7 +1059,7 @@ class DOMUtils extends ElementHandler {
|
|
|
1059
1059
|
handler($el, $fragment);
|
|
1060
1060
|
}
|
|
1061
1061
|
/**
|
|
1062
|
-
*
|
|
1062
|
+
* 移除元素(包括它和内部使用.on添加的监听事件)
|
|
1063
1063
|
* @param $el 目标元素,可以是数组、单个元素、NodeList、元素选择器
|
|
1064
1064
|
* @example
|
|
1065
1065
|
* DOMUtils.remove(document.querySelector("a.xx"))
|
|
@@ -1067,20 +1067,24 @@ class DOMUtils extends ElementHandler {
|
|
|
1067
1067
|
* DOMUtils.remove("a.xx")
|
|
1068
1068
|
* DOMUtils.remove([a.xxx, div.xxx, span.xxx])
|
|
1069
1069
|
* */
|
|
1070
|
-
remove($el: DOMUtilsTargetElementType | Element) {
|
|
1071
|
-
const that = this;
|
|
1070
|
+
remove($el: DOMUtilsTargetElementType | Element | null | undefined) {
|
|
1072
1071
|
if (typeof $el === "string") {
|
|
1073
|
-
$el =
|
|
1072
|
+
$el = this.selectorAll($el);
|
|
1074
1073
|
}
|
|
1075
1074
|
if ($el == null) {
|
|
1076
1075
|
return;
|
|
1077
1076
|
}
|
|
1078
1077
|
if (CommonUtils.isNodeList($el)) {
|
|
1079
1078
|
$el.forEach(($elItem) => {
|
|
1080
|
-
|
|
1079
|
+
this.remove($elItem as HTMLElement);
|
|
1081
1080
|
});
|
|
1082
1081
|
return;
|
|
1083
1082
|
}
|
|
1083
|
+
// 移除事件
|
|
1084
|
+
$el.querySelectorAll("*").forEach(($elItem) => {
|
|
1085
|
+
this.offAll($elItem);
|
|
1086
|
+
});
|
|
1087
|
+
this.offAll($el);
|
|
1084
1088
|
if (typeof $el.remove === "function") {
|
|
1085
1089
|
$el.remove();
|
|
1086
1090
|
} else if ($el.parentElement) {
|
|
@@ -1113,7 +1117,7 @@ class DOMUtils extends ElementHandler {
|
|
|
1113
1117
|
return;
|
|
1114
1118
|
}
|
|
1115
1119
|
if ($el.innerHTML) {
|
|
1116
|
-
$el
|
|
1120
|
+
CommonUtils.setSafeHTML($el, "");
|
|
1117
1121
|
} else if ($el.textContent) {
|
|
1118
1122
|
$el.textContent = "";
|
|
1119
1123
|
}
|
|
@@ -1392,7 +1396,7 @@ class DOMUtils extends ElementHandler {
|
|
|
1392
1396
|
$parent.replaceChild($newEl as Node, $el);
|
|
1393
1397
|
} else {
|
|
1394
1398
|
that.after($el, $newEl as HTMLElement);
|
|
1395
|
-
|
|
1399
|
+
this.remove($el);
|
|
1396
1400
|
}
|
|
1397
1401
|
}
|
|
1398
1402
|
/**
|