@whitesev/domutils 1.6.3 → 1.6.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.
@@ -7,11 +7,15 @@ import {
7
7
  } from "worker-timers";
8
8
 
9
9
  /** 通用工具类 */
10
- const DOMUtilsCommonUtils = {
10
+ export const DOMUtilsCommonUtils = {
11
11
  windowApi: new WindowApi({
12
12
  document: document,
13
13
  window: window,
14
14
  top: top!,
15
+ setTimeout: setTimeout,
16
+ clearTimeout: clearTimeout,
17
+ setInterval: setInterval,
18
+ clearInterval: clearInterval,
15
19
  }),
16
20
  /**
17
21
  * 判断元素是否已显示或已连接
@@ -142,7 +146,7 @@ const DOMUtilsCommonUtils = {
142
146
  try {
143
147
  return WorkerSetTimeout(callback, timeout);
144
148
  } catch (error) {
145
- return globalThis.setTimeout(callback, timeout);
149
+ return this.windowApi.setTimeout(callback, timeout);
146
150
  }
147
151
  },
148
152
  /**
@@ -155,7 +159,7 @@ const DOMUtilsCommonUtils = {
155
159
  }
156
160
  } catch (error) {
157
161
  } finally {
158
- globalThis.clearTimeout(timeId);
162
+ this.windowApi.clearTimeout(timeId);
159
163
  }
160
164
  },
161
165
  /**
@@ -165,7 +169,7 @@ const DOMUtilsCommonUtils = {
165
169
  try {
166
170
  return WorkerSetInterval(callback, timeout);
167
171
  } catch (error) {
168
- return globalThis.setInterval(callback, timeout);
172
+ return this.windowApi.setInterval(callback, timeout);
169
173
  }
170
174
  },
171
175
  /**
@@ -178,7 +182,7 @@ const DOMUtilsCommonUtils = {
178
182
  }
179
183
  } catch (error) {
180
184
  } finally {
181
- globalThis.clearInterval(timeId);
185
+ this.windowApi.clearInterval(timeId);
182
186
  }
183
187
  },
184
188
  /**
@@ -197,4 +201,3 @@ const DOMUtilsCommonUtils = {
197
201
  return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
198
202
  },
199
203
  };
200
- export { DOMUtilsCommonUtils };
package/src/WindowApi.ts CHANGED
@@ -8,6 +8,10 @@ export class WindowApi {
8
8
  globalThis: globalThis,
9
9
  self: self,
10
10
  top: top!,
11
+ setTimeout: globalThis.setTimeout.bind(globalThis),
12
+ setInterval: globalThis.setInterval.bind(globalThis),
13
+ clearTimeout: globalThis.clearTimeout.bind(globalThis),
14
+ clearInterval: globalThis.clearInterval.bind(globalThis),
11
15
  };
12
16
  /** 使用的配置 */
13
17
  private api: Required<WindowApiOption>;
@@ -23,8 +27,7 @@ export class WindowApi {
23
27
  if (!option) {
24
28
  option = Object.assign({}, this.defaultApi);
25
29
  }
26
- // @ts-ignore
27
- this.api = Object.assign({}, option);
30
+ this.api = Object.assign({}, option as Required<WindowApiOption>);
28
31
  }
29
32
  get document() {
30
33
  return this.api.document;
@@ -41,4 +44,16 @@ export class WindowApi {
41
44
  get top() {
42
45
  return this.api.top;
43
46
  }
47
+ get setTimeout() {
48
+ return this.api.setTimeout;
49
+ }
50
+ get clearTimeout() {
51
+ return this.api.clearTimeout;
52
+ }
53
+ get setInterval() {
54
+ return this.api.setInterval;
55
+ }
56
+ get clearInterval() {
57
+ return this.api.clearInterval;
58
+ }
44
59
  }
@@ -7,4 +7,8 @@ export type WindowApiOption = {
7
7
  globalThis?: typeof globalThis | Window;
8
8
  self?: Window & typeof globalThis;
9
9
  top: Window;
10
+ setTimeout: typeof setTimeout;
11
+ clearTimeout: typeof clearTimeout;
12
+ setInterval: typeof setInterval;
13
+ clearInterval: typeof clearInterval;
10
14
  };