@whitesev/domutils 1.5.1 → 1.5.2
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 +22 -33
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +22 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +22 -33
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +22 -33
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +22 -33
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +22 -33
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/DOMUtils.ts +21 -20
package/dist/index.amd.js
CHANGED
|
@@ -80,22 +80,7 @@ define((function () { 'use strict';
|
|
|
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
|
* 用于显示元素并获取它的高度宽度等其它属性
|
|
@@ -1075,7 +1060,7 @@ define((function () { 'use strict';
|
|
|
1075
1060
|
super(option);
|
|
1076
1061
|
}
|
|
1077
1062
|
/** 版本号 */
|
|
1078
|
-
version = "2025.
|
|
1063
|
+
version = "2025.4.8";
|
|
1079
1064
|
attr(element, attrName, attrValue) {
|
|
1080
1065
|
let DOMUtilsContext = this;
|
|
1081
1066
|
if (typeof element === "string") {
|
|
@@ -1218,6 +1203,19 @@ define((function () { 'use strict';
|
|
|
1218
1203
|
else ;
|
|
1219
1204
|
return;
|
|
1220
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
|
+
};
|
|
1221
1219
|
if (typeof property === "string") {
|
|
1222
1220
|
if (value == null) {
|
|
1223
1221
|
return DOMUtilsContext.windowApi.globalThis
|
|
@@ -1225,28 +1223,19 @@ define((function () { 'use strict';
|
|
|
1225
1223
|
.getPropertyValue(property);
|
|
1226
1224
|
}
|
|
1227
1225
|
else {
|
|
1228
|
-
|
|
1229
|
-
element.style.setProperty(property, value, "important");
|
|
1230
|
-
}
|
|
1231
|
-
else {
|
|
1232
|
-
value = handlePixe(property, value);
|
|
1233
|
-
element.style.setProperty(property, value);
|
|
1234
|
-
}
|
|
1226
|
+
setStyleProperty(property, value);
|
|
1235
1227
|
}
|
|
1236
1228
|
}
|
|
1237
1229
|
else if (typeof property === "object") {
|
|
1238
1230
|
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
|
-
}
|
|
1231
|
+
let value = property[prop];
|
|
1232
|
+
setStyleProperty(prop, value);
|
|
1247
1233
|
}
|
|
1248
1234
|
}
|
|
1249
|
-
else
|
|
1235
|
+
else {
|
|
1236
|
+
// 其他情况
|
|
1237
|
+
throw new TypeError("property must be string or object");
|
|
1238
|
+
}
|
|
1250
1239
|
}
|
|
1251
1240
|
text(element, text) {
|
|
1252
1241
|
let DOMUtilsContext = this;
|