@whitesev/domutils 1.5.1 → 1.5.3
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 +28 -37
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +28 -37
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +28 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +28 -37
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +28 -37
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +28 -37
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/DOMUtils.ts +21 -20
- package/src/DOMUtilsEvent.ts +9 -6
package/dist/index.cjs.js
CHANGED
|
@@ -80,22 +80,7 @@ const DOMUtilsCommonUtils = {
|
|
|
80
80
|
*/
|
|
81
81
|
setSafeHTML($el, text) {
|
|
82
82
|
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
83
|
-
|
|
84
|
-
$el.innerHTML = text;
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
if (globalThis.trustedTypes) {
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
91
|
-
createHTML: (html) => html,
|
|
92
|
-
});
|
|
93
|
-
$el.innerHTML = policy.createHTML(text);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
throw new Error("trustedTypes is not defined");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
83
|
+
$el.innerHTML = this.getSafeHTML(text);
|
|
99
84
|
},
|
|
100
85
|
/**
|
|
101
86
|
* 用于显示元素并获取它的高度宽度等其它属性
|
|
@@ -310,18 +295,20 @@ class DOMUtilsEvent {
|
|
|
310
295
|
let eventTarget = listenerOption.isComposedPath
|
|
311
296
|
? event.composedPath()[0]
|
|
312
297
|
: event.target;
|
|
313
|
-
let totalParent = DOMUtilsCommonUtils.isWin(elementItem)
|
|
298
|
+
let totalParent = DOMUtilsCommonUtils.isWin(elementItem) ||
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
elementItem === DOMUtilsContext.windowApi.document
|
|
314
301
|
? DOMUtilsContext.windowApi.document.documentElement
|
|
315
302
|
: elementItem;
|
|
316
303
|
let findValue = selectorList.find((selectorItem) => {
|
|
317
304
|
// 判断目标元素是否匹配选择器
|
|
318
|
-
if (eventTarget
|
|
305
|
+
if (eventTarget?.matches(selectorItem)) {
|
|
319
306
|
/* 当前目标可以被selector所匹配到 */
|
|
320
307
|
return true;
|
|
321
308
|
}
|
|
322
309
|
/* 在上层与主元素之间寻找可以被selector所匹配到的 */
|
|
323
|
-
let $closestMatches = eventTarget
|
|
324
|
-
if ($closestMatches && totalParent
|
|
310
|
+
let $closestMatches = eventTarget?.closest(selectorItem);
|
|
311
|
+
if ($closestMatches && totalParent?.contains($closestMatches)) {
|
|
325
312
|
eventTarget = $closestMatches;
|
|
326
313
|
return true;
|
|
327
314
|
}
|
|
@@ -1075,7 +1062,7 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1075
1062
|
super(option);
|
|
1076
1063
|
}
|
|
1077
1064
|
/** 版本号 */
|
|
1078
|
-
version = "2025.
|
|
1065
|
+
version = "2025.4.23";
|
|
1079
1066
|
attr(element, attrName, attrValue) {
|
|
1080
1067
|
let DOMUtilsContext = this;
|
|
1081
1068
|
if (typeof element === "string") {
|
|
@@ -1218,6 +1205,19 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1218
1205
|
else ;
|
|
1219
1206
|
return;
|
|
1220
1207
|
}
|
|
1208
|
+
let setStyleProperty = (propertyName, propertyValue) => {
|
|
1209
|
+
if (propertyValue === "string" && propertyValue.includes("!important")) {
|
|
1210
|
+
propertyValue = propertyValue
|
|
1211
|
+
.trim()
|
|
1212
|
+
.replace(/!important$/gi, "")
|
|
1213
|
+
.trim();
|
|
1214
|
+
element.style.setProperty(propertyName, propertyValue, "important");
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
propertyValue = handlePixe(propertyName, propertyValue);
|
|
1218
|
+
element.style.setProperty(propertyName, propertyValue);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
1221
|
if (typeof property === "string") {
|
|
1222
1222
|
if (value == null) {
|
|
1223
1223
|
return DOMUtilsContext.windowApi.globalThis
|
|
@@ -1225,28 +1225,19 @@ class DOMUtils extends DOMUtilsEvent {
|
|
|
1225
1225
|
.getPropertyValue(property);
|
|
1226
1226
|
}
|
|
1227
1227
|
else {
|
|
1228
|
-
|
|
1229
|
-
element.style.setProperty(property, value, "important");
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
value = handlePixe(property, value);
|
|
1233
|
-
element.style.setProperty(property, value);
|
|
1234
|
-
}
|
|
1228
|
+
setStyleProperty(property, value);
|
|
1235
1229
|
}
|
|
1236
1230
|
}
|
|
1237
1231
|
else if (typeof property === "object") {
|
|
1238
1232
|
for (let prop in property) {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
element.style.setProperty(prop, property[prop], "important");
|
|
1242
|
-
}
|
|
1243
|
-
else {
|
|
1244
|
-
property[prop] = handlePixe(prop, property[prop]);
|
|
1245
|
-
element.style.setProperty(prop, property[prop]);
|
|
1246
|
-
}
|
|
1233
|
+
let value = property[prop];
|
|
1234
|
+
setStyleProperty(prop, value);
|
|
1247
1235
|
}
|
|
1248
1236
|
}
|
|
1249
|
-
else
|
|
1237
|
+
else {
|
|
1238
|
+
// 其他情况
|
|
1239
|
+
throw new TypeError("property must be string or object");
|
|
1240
|
+
}
|
|
1250
1241
|
}
|
|
1251
1242
|
text(element, text) {
|
|
1252
1243
|
let DOMUtilsContext = this;
|