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