@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/domutils",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "使用js重新对jQuery的部分函数进行了仿写",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/DOMUtils.ts CHANGED
@@ -20,7 +20,7 @@ class DOMUtils extends DOMUtilsEvent {
20
20
  super(option);
21
21
  }
22
22
  /** 版本号 */
23
- version = "2025.3.2";
23
+ version = "2025.4.8";
24
24
  /**
25
25
  * 获取元素的属性值
26
26
  * @param element 目标元素
@@ -280,36 +280,37 @@ class DOMUtils extends DOMUtilsEvent {
280
280
  }
281
281
  return;
282
282
  }
283
+ let setStyleProperty = (
284
+ propertyName: string,
285
+ propertyValue: string | number
286
+ ) => {
287
+ if (propertyValue === "string" && propertyValue.includes("!important")) {
288
+ propertyValue = propertyValue
289
+ .trim()
290
+ .replace(/!important$/gi, "")
291
+ .trim();
292
+ element.style.setProperty(propertyName, propertyValue, "important");
293
+ } else {
294
+ propertyValue = handlePixe(propertyName, propertyValue);
295
+ element.style.setProperty(propertyName, propertyValue);
296
+ }
297
+ };
283
298
  if (typeof property === "string") {
284
299
  if (value == null) {
285
300
  return DOMUtilsContext.windowApi.globalThis
286
301
  .getComputedStyle(element)
287
302
  .getPropertyValue(property);
288
303
  } else {
289
- if (value === "string" && value.includes("!important")) {
290
- element.style.setProperty(property, value, "important");
291
- } else {
292
- value = handlePixe(property, value);
293
- element.style.setProperty(property, value);
294
- }
304
+ setStyleProperty(property, value);
295
305
  }
296
306
  } else if (typeof property === "object") {
297
307
  for (let prop in property) {
298
- if (
299
- typeof property[prop] === "string" &&
300
- (property[prop] as string).includes("!important")
301
- ) {
302
- element.style.setProperty(
303
- prop,
304
- property[prop] as string,
305
- "important"
306
- );
307
- } else {
308
- property[prop] = handlePixe(prop, property[prop] as string);
309
- element.style.setProperty(prop, property[prop] as string);
310
- }
308
+ let value = property[prop];
309
+ setStyleProperty(prop, value!);
311
310
  }
312
311
  } else {
312
+ // 其他情况
313
+ throw new TypeError("property must be string or object");
313
314
  }
314
315
  }
315
316
  /**