@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.umd.js CHANGED
@@ -84,22 +84,7 @@
84
84
  */
85
85
  setSafeHTML($el, text) {
86
86
  // 创建 TrustedHTML 策略(需 CSP 允许)
87
- try {
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
  * 用于显示元素并获取它的高度宽度等其它属性
@@ -1079,7 +1064,7 @@
1079
1064
  super(option);
1080
1065
  }
1081
1066
  /** 版本号 */
1082
- version = "2025.3.2";
1067
+ version = "2025.4.8";
1083
1068
  attr(element, attrName, attrValue) {
1084
1069
  let DOMUtilsContext = this;
1085
1070
  if (typeof element === "string") {
@@ -1222,6 +1207,19 @@
1222
1207
  else ;
1223
1208
  return;
1224
1209
  }
1210
+ let setStyleProperty = (propertyName, propertyValue) => {
1211
+ if (propertyValue === "string" && propertyValue.includes("!important")) {
1212
+ propertyValue = propertyValue
1213
+ .trim()
1214
+ .replace(/!important$/gi, "")
1215
+ .trim();
1216
+ element.style.setProperty(propertyName, propertyValue, "important");
1217
+ }
1218
+ else {
1219
+ propertyValue = handlePixe(propertyName, propertyValue);
1220
+ element.style.setProperty(propertyName, propertyValue);
1221
+ }
1222
+ };
1225
1223
  if (typeof property === "string") {
1226
1224
  if (value == null) {
1227
1225
  return DOMUtilsContext.windowApi.globalThis
@@ -1229,28 +1227,19 @@
1229
1227
  .getPropertyValue(property);
1230
1228
  }
1231
1229
  else {
1232
- if (value === "string" && value.includes("!important")) {
1233
- element.style.setProperty(property, value, "important");
1234
- }
1235
- else {
1236
- value = handlePixe(property, value);
1237
- element.style.setProperty(property, value);
1238
- }
1230
+ setStyleProperty(property, value);
1239
1231
  }
1240
1232
  }
1241
1233
  else if (typeof property === "object") {
1242
1234
  for (let prop in property) {
1243
- if (typeof property[prop] === "string" &&
1244
- property[prop].includes("!important")) {
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
- }
1235
+ let value = property[prop];
1236
+ setStyleProperty(prop, value);
1251
1237
  }
1252
1238
  }
1253
- else ;
1239
+ else {
1240
+ // 其他情况
1241
+ throw new TypeError("property must be string or object");
1242
+ }
1254
1243
  }
1255
1244
  text(element, text) {
1256
1245
  let DOMUtilsContext = this;