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