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