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