@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.esm.js CHANGED
@@ -78,22 +78,7 @@ const DOMUtilsCommonUtils = {
78
78
  */
79
79
  setSafeHTML($el, text) {
80
80
  // 创建 TrustedHTML 策略(需 CSP 允许)
81
- try {
82
- $el.innerHTML = text;
83
- }
84
- catch (error) {
85
- // @ts-ignore
86
- if (globalThis.trustedTypes) {
87
- // @ts-ignore
88
- const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
89
- createHTML: (html) => html,
90
- });
91
- $el.innerHTML = policy.createHTML(text);
92
- }
93
- else {
94
- throw new Error("trustedTypes is not defined");
95
- }
96
- }
81
+ $el.innerHTML = this.getSafeHTML(text);
97
82
  },
98
83
  /**
99
84
  * 用于显示元素并获取它的高度宽度等其它属性
@@ -1073,7 +1058,7 @@ class DOMUtils extends DOMUtilsEvent {
1073
1058
  super(option);
1074
1059
  }
1075
1060
  /** 版本号 */
1076
- version = "2025.3.2";
1061
+ version = "2025.4.8";
1077
1062
  attr(element, attrName, attrValue) {
1078
1063
  let DOMUtilsContext = this;
1079
1064
  if (typeof element === "string") {
@@ -1216,6 +1201,19 @@ class DOMUtils extends DOMUtilsEvent {
1216
1201
  else ;
1217
1202
  return;
1218
1203
  }
1204
+ let setStyleProperty = (propertyName, propertyValue) => {
1205
+ if (propertyValue === "string" && propertyValue.includes("!important")) {
1206
+ propertyValue = propertyValue
1207
+ .trim()
1208
+ .replace(/!important$/gi, "")
1209
+ .trim();
1210
+ element.style.setProperty(propertyName, propertyValue, "important");
1211
+ }
1212
+ else {
1213
+ propertyValue = handlePixe(propertyName, propertyValue);
1214
+ element.style.setProperty(propertyName, propertyValue);
1215
+ }
1216
+ };
1219
1217
  if (typeof property === "string") {
1220
1218
  if (value == null) {
1221
1219
  return DOMUtilsContext.windowApi.globalThis
@@ -1223,28 +1221,19 @@ class DOMUtils extends DOMUtilsEvent {
1223
1221
  .getPropertyValue(property);
1224
1222
  }
1225
1223
  else {
1226
- if (value === "string" && value.includes("!important")) {
1227
- element.style.setProperty(property, value, "important");
1228
- }
1229
- else {
1230
- value = handlePixe(property, value);
1231
- element.style.setProperty(property, value);
1232
- }
1224
+ setStyleProperty(property, value);
1233
1225
  }
1234
1226
  }
1235
1227
  else if (typeof property === "object") {
1236
1228
  for (let prop in property) {
1237
- if (typeof property[prop] === "string" &&
1238
- property[prop].includes("!important")) {
1239
- element.style.setProperty(prop, property[prop], "important");
1240
- }
1241
- else {
1242
- property[prop] = handlePixe(prop, property[prop]);
1243
- element.style.setProperty(prop, property[prop]);
1244
- }
1229
+ let value = property[prop];
1230
+ setStyleProperty(prop, value);
1245
1231
  }
1246
1232
  }
1247
- else ;
1233
+ else {
1234
+ // 其他情况
1235
+ throw new TypeError("property must be string or object");
1236
+ }
1248
1237
  }
1249
1238
  text(element, text) {
1250
1239
  let DOMUtilsContext = this;