@whitesev/domutils 1.5.3 → 1.5.5

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.
@@ -44,5 +44,21 @@ declare const DOMUtilsCommonUtils: {
44
44
  * @param propName
45
45
  */
46
46
  delete(target: any, propName: any): void;
47
+ /**
48
+ * 自动使用 Worker 执行 setTimeout
49
+ */
50
+ setTimeout(callback: Function, timeout?: number): number;
51
+ /**
52
+ * 配合 .setTimeout 使用
53
+ */
54
+ clearTimeout(timeId: number | undefined): void;
55
+ /**
56
+ * 自动使用 Worker 执行 setInterval
57
+ */
58
+ setInterval(callback: Function, timeout?: number): number;
59
+ /**
60
+ * 配合 .setInterval 使用
61
+ */
62
+ clearInterval(timeId: number | undefined): void;
47
63
  };
48
64
  export { DOMUtilsCommonUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/domutils",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
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.4.23";
23
+ version = "2025.5.26";
24
24
  /**
25
25
  * 获取元素的属性值
26
26
  * @param element 目标元素
@@ -284,7 +284,10 @@ class DOMUtils extends DOMUtilsEvent {
284
284
  propertyName: string,
285
285
  propertyValue: string | number
286
286
  ) => {
287
- if (propertyValue === "string" && propertyValue.includes("!important")) {
287
+ if (
288
+ typeof propertyValue === "string" &&
289
+ propertyValue.trim().endsWith("!important")
290
+ ) {
288
291
  propertyValue = propertyValue
289
292
  .trim()
290
293
  .replace(/!important$/gi, "")
@@ -1453,7 +1456,7 @@ class DOMUtils extends DOMUtilsEvent {
1453
1456
  DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
1454
1457
  to[prop] = styles[prop];
1455
1458
  }
1456
- let timer = setInterval(function () {
1459
+ let timer = DOMUtilsCommonUtils.setInterval(function () {
1457
1460
  let timePassed = performance.now() - start;
1458
1461
  let progress = timePassed / duration;
1459
1462
  if (progress > 1) {
@@ -1464,7 +1467,7 @@ class DOMUtils extends DOMUtilsEvent {
1464
1467
  from[prop] + (to[prop] - from[prop]) * progress + "px";
1465
1468
  }
1466
1469
  if (progress === 1) {
1467
- clearInterval(timer);
1470
+ DOMUtilsCommonUtils.clearInterval(timer);
1468
1471
  if (callback) {
1469
1472
  callback();
1470
1473
  }
@@ -1,4 +1,10 @@
1
1
  import { WindowApi } from "./WindowApi";
2
+ import {
3
+ clearInterval as WorkerClearInterval,
4
+ clearTimeout as WorkerClearTimeout,
5
+ setInterval as WorkerSetInterval,
6
+ setTimeout as WorkerSetTimeout,
7
+ } from "worker-timers";
2
8
 
3
9
  /** 通用工具类 */
4
10
  const DOMUtilsCommonUtils = {
@@ -132,5 +138,51 @@ const DOMUtilsCommonUtils = {
132
138
  delete target[propName];
133
139
  }
134
140
  },
141
+ /**
142
+ * 自动使用 Worker 执行 setTimeout
143
+ */
144
+ setTimeout(callback: Function, timeout: number = 0) {
145
+ try {
146
+ return WorkerSetTimeout(callback, timeout);
147
+ } catch (error) {
148
+ return globalThis.setTimeout(callback, timeout);
149
+ }
150
+ },
151
+ /**
152
+ * 配合 .setTimeout 使用
153
+ */
154
+ clearTimeout(timeId: number | undefined) {
155
+ try {
156
+ if (timeId != null) {
157
+ WorkerClearTimeout(timeId);
158
+ }
159
+ } catch (error) {
160
+ } finally {
161
+ globalThis.clearTimeout(timeId);
162
+ }
163
+ },
164
+ /**
165
+ * 自动使用 Worker 执行 setInterval
166
+ */
167
+ setInterval(callback: Function, timeout: number = 0) {
168
+ try {
169
+ return WorkerSetInterval(callback, timeout);
170
+ } catch (error) {
171
+ return globalThis.setInterval(callback, timeout);
172
+ }
173
+ },
174
+ /**
175
+ * 配合 .setInterval 使用
176
+ */
177
+ clearInterval(timeId: number | undefined) {
178
+ try {
179
+ if (timeId != null) {
180
+ WorkerClearInterval(timeId);
181
+ }
182
+ } catch (error) {
183
+ } finally {
184
+ globalThis.clearInterval(timeId);
185
+ }
186
+ },
135
187
  };
136
188
  export { DOMUtilsCommonUtils };
@@ -765,7 +765,7 @@ export class DOMUtilsEvent {
765
765
  }
766
766
  if (checkDOMReadyState()) {
767
767
  /* 检查document状态 */
768
- setTimeout(callback);
768
+ DOMUtilsCommonUtils.setTimeout(callback);
769
769
  } else {
770
770
  /* 添加监听 */
771
771
  addDomReadyListener();