@whitesev/domutils 1.5.4 → 1.5.6

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.
@@ -72,7 +72,7 @@ declare class DOMUtils extends DOMUtilsEvent {
72
72
  * DOMUtils.css("a.xx","display");
73
73
  * > "none"
74
74
  * */
75
- css(element: DOMUtilsTargetElementType, property: keyof CSSStyleDeclaration): string;
75
+ css(element: DOMUtilsTargetElementType, property: keyof Omit<CSSStyleDeclaration, "zIndex"> | "z-index"): string;
76
76
  /**
77
77
  * 获取元素的样式属性值
78
78
  * @param element 目标元素
@@ -100,7 +100,7 @@ declare class DOMUtils extends DOMUtilsEvent {
100
100
  * DOMUtils.css(document.querySelector("a.xx"),"top","10px");
101
101
  * DOMUtils.css(document.querySelector("a.xx"),"top",10);
102
102
  * */
103
- css(element: DOMUtilsTargetElementType, property: keyof CSSStyleDeclaration & string, value: string | number): string;
103
+ css(element: DOMUtilsTargetElementType, property: (keyof Omit<CSSStyleDeclaration, "zIndex"> | "z-index") & string, value: string | number): string;
104
104
  /**
105
105
  * 设置元素的样式属性
106
106
  * @param element 目标元素
@@ -116,7 +116,9 @@ declare class DOMUtils extends DOMUtilsEvent {
116
116
  * DOMUtils.css(document.querySelector("a.xx"),{ top: 10 });
117
117
  * */
118
118
  css(element: DOMUtilsTargetElementType, property: {
119
- [P in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[P];
119
+ [P in keyof Omit<CSSStyleDeclaration, "zIndex">]?: CSSStyleDeclaration[P];
120
+ } | {
121
+ "z-index": string | number;
120
122
  } | {
121
123
  [key: string]: string | number;
122
124
  }): string;
@@ -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.4",
3
+ "version": "1.5.6",
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.5.12";
23
+ version = "2025.5.26";
24
24
  /**
25
25
  * 获取元素的属性值
26
26
  * @param element 目标元素
@@ -155,7 +155,7 @@ class DOMUtils extends DOMUtilsEvent {
155
155
  * */
156
156
  css(
157
157
  element: DOMUtilsTargetElementType,
158
- property: keyof CSSStyleDeclaration
158
+ property: keyof Omit<CSSStyleDeclaration, "zIndex"> | "z-index"
159
159
  ): string;
160
160
  /**
161
161
  * 获取元素的样式属性值
@@ -186,7 +186,7 @@ class DOMUtils extends DOMUtilsEvent {
186
186
  * */
187
187
  css(
188
188
  element: DOMUtilsTargetElementType,
189
- property: keyof CSSStyleDeclaration & string,
189
+ property: (keyof Omit<CSSStyleDeclaration, "zIndex"> | "z-index") & string,
190
190
  value: string | number
191
191
  ): string;
192
192
  /**
@@ -207,7 +207,13 @@ class DOMUtils extends DOMUtilsEvent {
207
207
  element: DOMUtilsTargetElementType,
208
208
  property:
209
209
  | {
210
- [P in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[P];
210
+ [P in keyof Omit<
211
+ CSSStyleDeclaration,
212
+ "zIndex"
213
+ >]?: CSSStyleDeclaration[P];
214
+ }
215
+ | {
216
+ "z-index": string | number;
211
217
  }
212
218
  | {
213
219
  [key: string]: string | number;
@@ -216,10 +222,10 @@ class DOMUtils extends DOMUtilsEvent {
216
222
  css(
217
223
  element: DOMUtilsTargetElementType,
218
224
  property:
219
- | keyof CSSStyleDeclaration
225
+ | keyof Omit<CSSStyleDeclaration, "zIndex">
220
226
  | string
221
227
  | {
222
- [P in keyof CSSStyleDeclaration]?:
228
+ [P in keyof Omit<CSSStyleDeclaration, "zIndex">]?:
223
229
  | string
224
230
  | number
225
231
  | CSSStyleDeclaration[P];
@@ -1456,7 +1462,7 @@ class DOMUtils extends DOMUtilsEvent {
1456
1462
  DOMUtilsContext.windowApi.globalThis.getComputedStyle(element)[prop];
1457
1463
  to[prop] = styles[prop];
1458
1464
  }
1459
- let timer = setInterval(function () {
1465
+ let timer = DOMUtilsCommonUtils.setInterval(function () {
1460
1466
  let timePassed = performance.now() - start;
1461
1467
  let progress = timePassed / duration;
1462
1468
  if (progress > 1) {
@@ -1467,7 +1473,7 @@ class DOMUtils extends DOMUtilsEvent {
1467
1473
  from[prop] + (to[prop] - from[prop]) * progress + "px";
1468
1474
  }
1469
1475
  if (progress === 1) {
1470
- clearInterval(timer);
1476
+ DOMUtilsCommonUtils.clearInterval(timer);
1471
1477
  if (callback) {
1472
1478
  callback();
1473
1479
  }
@@ -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();