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