@whitesev/utils 2.7.1 → 2.7.3

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.
Files changed (53) hide show
  1. package/dist/index.amd.js +260 -409
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +260 -409
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +260 -409
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +260 -409
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +260 -409
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +260 -409
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/ColorConversion.d.ts +3 -8
  14. package/dist/types/src/Dictionary.d.ts +21 -14
  15. package/dist/types/src/GBKEncoder.d.ts +1 -2
  16. package/dist/types/src/Hooks.d.ts +1 -2
  17. package/dist/types/src/Httpx.d.ts +45 -46
  18. package/dist/types/src/LockFunction.d.ts +1 -2
  19. package/dist/types/src/Log.d.ts +1 -2
  20. package/dist/types/src/Progress.d.ts +1 -2
  21. package/dist/types/src/Utils.d.ts +30 -2
  22. package/dist/types/src/UtilsGMMenu.d.ts +1 -2
  23. package/dist/types/src/WindowApi.d.ts +1 -2
  24. package/dist/types/src/indexedDB.d.ts +1 -2
  25. package/dist/types/src/types/Event.d.ts +1 -2
  26. package/dist/types/src/types/Httpx.d.ts +75 -86
  27. package/dist/types/src/types/ajaxHooker.d.ts +1 -5
  28. package/dist/types/src/types/env.d.ts +2 -0
  29. package/dist/types/src/types/global.d.ts +3 -0
  30. package/package.json +1 -1
  31. package/src/ColorConversion.ts +13 -37
  32. package/src/CommonUtil.ts +8 -31
  33. package/src/DOMUtils.ts +9 -24
  34. package/src/Dictionary.ts +37 -38
  35. package/src/GBKEncoder.ts +9 -18
  36. package/src/Hooks.ts +2 -7
  37. package/src/Httpx.ts +257 -412
  38. package/src/LockFunction.ts +1 -3
  39. package/src/Log.ts +8 -26
  40. package/src/Progress.ts +3 -13
  41. package/src/TryCatch.ts +4 -12
  42. package/src/Utils.ts +233 -595
  43. package/src/UtilsCommon.ts +5 -9
  44. package/src/UtilsGMCookie.ts +1 -4
  45. package/src/UtilsGMMenu.ts +29 -51
  46. package/src/Vue.ts +6 -18
  47. package/src/WindowApi.ts +2 -5
  48. package/src/indexedDB.ts +11 -20
  49. package/src/types/Event.d.ts +1 -2
  50. package/src/types/Httpx.d.ts +75 -86
  51. package/src/types/ajaxHooker.d.ts +1 -5
  52. package/src/types/env.d.ts +2 -0
  53. package/src/types/global.d.ts +3 -0
package/src/Utils.ts CHANGED
@@ -17,11 +17,7 @@ import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
17
17
  import { GenerateUUID } from "./UtilsCommon";
18
18
  import { WindowApi } from "./WindowApi";
19
19
  import { Vue } from "./Vue";
20
- import {
21
- type ArgsType,
22
- type JSTypeNames,
23
- type UtilsOwnObject,
24
- } from "./types/global";
20
+ import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
25
21
  import type { WindowApiOption } from "./types/WindowApi";
26
22
  import {
27
23
  clearInterval as WorkerClearInterval,
@@ -39,7 +35,7 @@ class Utils {
39
35
  this.windowApi = new WindowApi(option);
40
36
  }
41
37
  /** 版本号 */
42
- version = "2025.7.29";
38
+ version = "2025.8.11";
43
39
  /**
44
40
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
45
41
  * @param cssText css字符串
@@ -62,9 +58,7 @@ class Utils {
62
58
  } else if (this.windowApi.document.body) {
63
59
  /* 插入body后 */
64
60
  this.windowApi.document.body.appendChild(cssNode);
65
- } else if (
66
- this.windowApi.document.documentElement.childNodes.length === 0
67
- ) {
61
+ } else if (this.windowApi.document.documentElement.childNodes.length === 0) {
68
62
  /* 插入#html第一个元素后 */
69
63
  this.windowApi.document.documentElement.appendChild(cssNode);
70
64
  } else {
@@ -177,21 +171,20 @@ class Utils {
177
171
  canvasElement: HTMLCanvasElement,
178
172
  clientX = 0,
179
173
  clientY = 0,
180
- view = globalThis
174
+ view = this.windowApi.window
181
175
  ) {
182
176
  if (!(canvasElement instanceof HTMLCanvasElement)) {
183
- throw new Error(
184
- "Utils.canvasClickByPosition 参数canvasElement必须是canvas元素"
185
- );
177
+ throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
186
178
  }
187
179
  clientX = parseInt(clientX.toString());
188
180
  clientY = parseInt(clientY.toString());
189
- const eventInit: MouseEventInit = {
181
+ const eventInit: MouseEventInit & {
182
+ cancelBubble: boolean;
183
+ } = {
190
184
  cancelBubble: true,
191
185
  cancelable: true,
192
186
  clientX: clientX,
193
187
  clientY: clientY,
194
- // @ts-ignore
195
188
  view: view,
196
189
  detail: 1,
197
190
  };
@@ -212,24 +205,16 @@ class Utils {
212
205
  checkUserClickInNode(element: Element | Node | HTMLElement) {
213
206
  let UtilsContext = this;
214
207
  if (!UtilsContext.isDOM(element)) {
215
- throw new Error(
216
- "Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型"
217
- );
208
+ throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
218
209
  }
219
210
  let clickEvent = UtilsContext.windowApi.window.event as PointerEvent;
220
211
  let touchEvent = UtilsContext.windowApi.window.event as TouchEvent;
221
212
  let $click = clickEvent?.composedPath()?.[0] as HTMLElement;
222
213
 
223
214
  // 点击的x坐标
224
- let clickPosX =
225
- clickEvent?.clientX != null
226
- ? clickEvent.clientX
227
- : touchEvent.touches[0].clientX;
215
+ let clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
228
216
  // 点击的y坐标
229
- let clickPosY =
230
- clickEvent?.clientY != null
231
- ? clickEvent.clientY
232
- : touchEvent.touches[0].clientY;
217
+ let clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
233
218
  let {
234
219
  /* 要检测的元素的相对屏幕的横坐标最左边 */
235
220
  left: elementPosXLeft,
@@ -264,8 +249,7 @@ class Utils {
264
249
  ): T {
265
250
  let clonedFormData = new FormData() as T;
266
251
  for (let [key, value] of (formData as any).entries()) {
267
- let isFilter =
268
- typeof filterFn === "function" ? filterFn(key, value) : false;
252
+ let isFilter = typeof filterFn === "function" ? filterFn(key, value) : false;
269
253
  if (typeof isFilter === "boolean" && isFilter) {
270
254
  continue;
271
255
  }
@@ -297,17 +281,13 @@ class Utils {
297
281
  /**
298
282
  * 前面的参数都是字符串,最后一个参数是函数
299
283
  */
300
- addImpl<T extends JSTypeNames[]>(
301
- ...args: [...T, (...args: ArgsType<T>) => any]
302
- ): void;
284
+ addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
303
285
  };
304
286
  createOverload(): {
305
287
  /**
306
288
  * 前面的参数都是字符串,最后一个参数是函数
307
289
  */
308
- addImpl<T extends JSTypeNames[]>(
309
- ...args: [...T, (...args: ArgsType<T>) => any]
310
- ): void;
290
+ addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
311
291
  } {
312
292
  let fnMap = new Map();
313
293
  function overload(this: any, ...args: any[]) {
@@ -343,10 +323,7 @@ class Utils {
343
323
  * @param fn 需要触发的回调
344
324
  * @param delay 防抖判定时间(毫秒),默认是0ms
345
325
  */
346
- debounce<A extends any[], R>(
347
- fn: (...args: A) => R,
348
- delay?: number
349
- ): (...args: A) => void;
326
+ debounce<A extends any[], R>(fn: (...args: A) => R, delay?: number): (...args: A) => void;
350
327
  debounce<A extends any[], R>(fn: (...args: A) => R, delay = 0) {
351
328
  let timer: any = null as any;
352
329
  let UtilsContext = this;
@@ -368,33 +345,20 @@ class Utils {
368
345
  * Utils.deleteParentNode(document.querySelector("a"),".xxx");
369
346
  * > true
370
347
  **/
371
- deleteParentNode(
372
- element: Node | HTMLElement | Element | null,
373
- targetSelector: string
374
- ): boolean;
375
- deleteParentNode(
376
- element: Node | HTMLElement | Element | null,
377
- targetSelector: string
378
- ) {
348
+ deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string): boolean;
349
+ deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string) {
379
350
  let UtilsContext = this;
380
351
  if (element == null) {
381
352
  return;
382
353
  }
383
354
  if (!UtilsContext.isDOM(element)) {
384
- throw new Error(
385
- "Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型"
386
- );
355
+ throw new Error("Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型");
387
356
  }
388
357
  if (typeof targetSelector !== "string") {
389
- throw new Error(
390
- "Utils.deleteParentNode 参数 targetSelector 必须为 string 类型"
391
- );
358
+ throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
392
359
  }
393
360
  let result = false;
394
- let needRemoveDOM = domUtils.closest(
395
- element as HTMLElement,
396
- targetSelector
397
- );
361
+ let needRemoveDOM = domUtils.closest(element as HTMLElement, targetSelector);
398
362
  if (needRemoveDOM) {
399
363
  needRemoveDOM.remove();
400
364
  result = true;
@@ -440,11 +404,7 @@ class Utils {
440
404
  * @example
441
405
  * Utils.dispatchEvent(document.querySelector("input","input"))
442
406
  */
443
- dispatchEvent(
444
- element: HTMLElement | Document,
445
- eventName: string,
446
- details?: any
447
- ): void;
407
+ dispatchEvent(element: HTMLElement | Document, eventName: string, details?: any): void;
448
408
  dispatchEvent(
449
409
  element: HTMLElement | Document,
450
410
  eventName: DOMUtils_EventType | DOMUtils_EventType[] | string,
@@ -474,17 +434,11 @@ class Utils {
474
434
  * @example
475
435
  * Utils.downloadBase64("data:image/jpeg:base64/,xxxxxx");
476
436
  **/
477
- downloadBase64(
478
- base64Data: string,
479
- fileName: string,
480
- isIFrame?: boolean
481
- ): void;
437
+ downloadBase64(base64Data: string, fileName: string, isIFrame?: boolean): void;
482
438
  downloadBase64(base64Data: string, fileName: string, isIFrame = false) {
483
439
  let UtilsContext = this;
484
440
  if (typeof base64Data !== "string") {
485
- throw new Error(
486
- "Utils.downloadBase64 参数 base64Data 必须为 string 类型"
487
- );
441
+ throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
488
442
  }
489
443
  if (typeof fileName !== "string") {
490
444
  throw new Error("Utils.downloadBase64 参数 fileName 必须为 string 类型");
@@ -496,11 +450,7 @@ class Utils {
496
450
  iframeElement.src = base64Data;
497
451
  this.windowApi.document.body.appendChild(iframeElement);
498
452
  UtilsContext.workerSetTimeout(() => {
499
- iframeElement!.contentWindow!.document.execCommand(
500
- "SaveAs",
501
- true,
502
- fileName
503
- );
453
+ iframeElement!.contentWindow!.document.execCommand("SaveAs", true, fileName);
504
454
  this.windowApi.document.body.removeChild(iframeElement);
505
455
  }, 100);
506
456
  } else {
@@ -535,11 +485,7 @@ class Utils {
535
485
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
536
486
  let windowFind = (this.windowApi.self as any).find;
537
487
  strFound = windowFind(str, caseSensitive, true, true, false);
538
- if (
539
- strFound &&
540
- this.windowApi.self.getSelection &&
541
- !this.windowApi.self.getSelection()!.anchorNode
542
- ) {
488
+ if (strFound && this.windowApi.self.getSelection && !this.windowApi.self.getSelection()!.anchorNode) {
543
489
  strFound = windowFind(str, caseSensitive, true, true, false);
544
490
  }
545
491
  if (!strFound) {
@@ -588,19 +534,15 @@ class Utils {
588
534
  let that = this;
589
535
  if ((element as HTMLElement).outerHTML.includes(text)) {
590
536
  if ((element as HTMLElement).children.length === 0) {
591
- let filterResult =
592
- typeof filter === "function" ? filter(element) : false;
537
+ let filterResult = typeof filter === "function" ? filter(element) : false;
593
538
  if (!filterResult) {
594
539
  yield element as any;
595
540
  }
596
541
  } else {
597
- let textElement = Array.from(element.childNodes).filter(
598
- (ele) => ele.nodeType === Node.TEXT_NODE
599
- );
542
+ let textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
600
543
  for (let ele of textElement) {
601
544
  if ((ele as any).textContent.includes(text)) {
602
- let filterResult =
603
- typeof filter === "function" ? filter(element) : false;
545
+ let filterResult = typeof filter === "function" ? filter(element) : false;
604
546
  if (!filterResult) {
605
547
  yield ele;
606
548
  }
@@ -609,11 +551,7 @@ class Utils {
609
551
  }
610
552
  }
611
553
 
612
- for (
613
- let index = 0;
614
- index < (element as HTMLElement).children.length;
615
- index++
616
- ) {
554
+ for (let index = 0; index < (element as HTMLElement).children.length; index++) {
617
555
  let childElement = (element as HTMLElement).children[index] as any;
618
556
  yield* that.findElementsWithText(childElement, text, filter);
619
557
  }
@@ -685,9 +623,7 @@ class Utils {
685
623
  }
686
624
  }
687
625
  result = result.toFixed(2) as any;
688
- result = addType
689
- ? result + resultType.toString()
690
- : (parseFloat(result.toString()) as any);
626
+ result = addType ? result + resultType.toString() : (parseFloat(result.toString()) as any);
691
627
  return result;
692
628
  }
693
629
  /**
@@ -862,14 +798,7 @@ class Utils {
862
798
  if (text.length === 8) {
863
799
  /* 该字符串只有时分秒 */
864
800
  let today = new Date();
865
- text =
866
- today.getFullYear() +
867
- "-" +
868
- (today.getMonth() + 1) +
869
- "-" +
870
- today.getDate() +
871
- " " +
872
- text;
801
+ text = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + text;
873
802
  }
874
803
  text = text.substring(0, 19);
875
804
  text = text.replace(/-/g, "/");
@@ -890,25 +819,13 @@ class Utils {
890
819
  * 获取 transitionend 的在各个浏览器的兼容名
891
820
  */
892
821
  getTransitionEndNameList() {
893
- return [
894
- "webkitTransitionEnd",
895
- "mozTransitionEnd",
896
- "MSTransitionEnd",
897
- "otransitionend",
898
- "transitionend",
899
- ];
822
+ return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
900
823
  }
901
824
  /**
902
825
  * 获取 animationend 的在各个浏览器的兼容名
903
826
  */
904
827
  getAnimationEndNameList() {
905
- return [
906
- "webkitAnimationEnd",
907
- "mozAnimationEnd",
908
- "MSAnimationEnd",
909
- "oanimationend",
910
- "animationend",
911
- ];
828
+ return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
912
829
  }
913
830
  /**
914
831
  * 获取NodeList或Array对象中的最后一个的值
@@ -964,11 +881,7 @@ class Utils {
964
881
  * Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
965
882
  * > 0
966
883
  */
967
- getDaysDifference(
968
- timestamp1?: number,
969
- timestamp2?: number,
970
- type?: "auto"
971
- ): string;
884
+ getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "auto"): string;
972
885
  /**
973
886
  * 获取天数差异,如何获取某个时间与另一个时间相差的天数
974
887
  * @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
@@ -986,11 +899,7 @@ class Utils {
986
899
  timestamp2?: number,
987
900
  type?: "年" | "月" | "天" | "时" | "分" | "秒"
988
901
  ): number;
989
- getDaysDifference(
990
- timestamp1 = Date.now(),
991
- timestamp2 = Date.now(),
992
- type = "天"
993
- ): number | string {
902
+ getDaysDifference(timestamp1 = Date.now(), timestamp2 = Date.now(), type = "天"): number | string {
994
903
  type = type.trim();
995
904
  if (timestamp1.toString().length === 10) {
996
905
  timestamp1 = timestamp1 * 1000;
@@ -1022,9 +931,7 @@ class Utils {
1022
931
  } else if (type === "秒") {
1023
932
  remainderValue = oneSecond;
1024
933
  }
1025
- let diffValue = Math.round(
1026
- Math.abs(((bigDate as any) - (smallDate as any)) / remainderValue)
1027
- );
934
+ let diffValue = Math.round(Math.abs(((bigDate as any) - (smallDate as any)) / remainderValue));
1028
935
  if (type === "auto") {
1029
936
  let timeDifference = bigTimeStamp - smallTimeStamp;
1030
937
  diffValue = Math.floor(timeDifference / (24 * 3600 * 1000));
@@ -1032,8 +939,7 @@ class Utils {
1032
939
  (diffValue as any) = diffValue + "天";
1033
940
  } else {
1034
941
  /* 计算出小时数 */
1035
- let leave1 =
1036
- timeDifference % (24 * 3600 * 1000); /* 计算天数后剩余的毫秒数 */
942
+ let leave1 = timeDifference % (24 * 3600 * 1000); /* 计算天数后剩余的毫秒数 */
1037
943
  let hours = Math.floor(leave1 / (3600 * 1000));
1038
944
  if (hours > 0) {
1039
945
  (diffValue as any) = hours + "小时";
@@ -1064,10 +970,8 @@ class Utils {
1064
970
  getElementSelector(element: HTMLElement): string;
1065
971
  getElementSelector(element: HTMLElement): string {
1066
972
  let UtilsContext = this;
1067
- // @ts-ignore
1068
- if (!element) return;
1069
- // @ts-ignore
1070
- if (!element.parentElement) return;
973
+ if (!element) return void 0 as any as string;
974
+ if (!element.parentElement) return void 0 as any as string;
1071
975
  /* 如果元素有id属性,则直接返回id选择器 */
1072
976
  if (element.id) return "#" + element.id;
1073
977
 
@@ -1078,11 +982,8 @@ class Utils {
1078
982
  }
1079
983
  /* 如果有多个相同类型的兄弟元素,则需要添加索引 */
1080
984
  if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
1081
- let index =
1082
- Array.prototype.indexOf.call(element.parentElement.children, element) +
1083
- 1;
1084
- selector +=
1085
- " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
985
+ let index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
986
+ selector += " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
1086
987
  } else {
1087
988
  selector += " > " + element.tagName.toLowerCase();
1088
989
  }
@@ -1108,10 +1009,7 @@ class Utils {
1108
1009
  * Utils.getMaxValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
1109
1010
  * > 456
1110
1011
  */
1111
- getMaxValue(
1112
- val: UtilsOwnObject<number>,
1113
- handler: (key: any, value: any) => number
1114
- ): number;
1012
+ getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
1115
1013
  /**
1116
1014
  * 获取最大值
1117
1015
  * @example
@@ -1122,15 +1020,10 @@ class Utils {
1122
1020
  let result = [...args];
1123
1021
  let newResult: number[] = [];
1124
1022
  if (result.length === 0) {
1125
- // @ts-ignore
1126
- return;
1023
+ return void 0 as any as number;
1127
1024
  }
1128
1025
  if (result.length > 1) {
1129
- if (
1130
- result.length === 2 &&
1131
- typeof result[0] === "object" &&
1132
- typeof result[1] === "function"
1133
- ) {
1026
+ if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
1134
1027
  let data = result[0];
1135
1028
  let handleDataFunc = result[1];
1136
1029
  Object.keys(data).forEach((keyName) => {
@@ -1168,9 +1061,7 @@ class Utils {
1168
1061
  getMaxZIndexNodeInfo(
1169
1062
  deviation?: number,
1170
1063
  target?: Element | ShadowRoot | Document,
1171
- ignoreCallBack?: (
1172
- $ele: Element | HTMLElement | ShadowRoot
1173
- ) => boolean | void
1064
+ ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
1174
1065
  ): {
1175
1066
  node: Element;
1176
1067
  zIndex: number;
@@ -1178,9 +1069,7 @@ class Utils {
1178
1069
  getMaxZIndexNodeInfo(
1179
1070
  deviation = 1,
1180
1071
  target: Element | ShadowRoot | Document = this.windowApi.document,
1181
- ignoreCallBack?: (
1182
- $ele: Element | HTMLElement | ShadowRoot
1183
- ) => boolean | void
1072
+ ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
1184
1073
  ): {
1185
1074
  node: Element;
1186
1075
  zIndex: number;
@@ -1194,8 +1083,7 @@ class Utils {
1194
1083
  // 当前页面最大的z-index
1195
1084
  let zIndex = 0;
1196
1085
  // 当前的最大z-index的元素,调试使用
1197
- // @ts-ignore
1198
- let maxZIndexNode: Element = null;
1086
+ let maxZIndexNode: Element | null = null;
1199
1087
  /**
1200
1088
  * 元素是否可见
1201
1089
  * @param $css
@@ -1244,7 +1132,7 @@ class Utils {
1244
1132
  zIndex = maxZIndexCompare;
1245
1133
  }
1246
1134
  return {
1247
- node: maxZIndexNode,
1135
+ node: maxZIndexNode!,
1248
1136
  zIndex: zIndex,
1249
1137
  };
1250
1138
  }
@@ -1260,16 +1148,12 @@ class Utils {
1260
1148
  getMaxZIndex(
1261
1149
  deviation?: number,
1262
1150
  target?: Element | DocumentOrShadowRoot | Document,
1263
- ignoreCallBack?: (
1264
- $ele: Element | HTMLElement | ShadowRoot
1265
- ) => boolean | void
1151
+ ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
1266
1152
  ): number;
1267
1153
  getMaxZIndex(
1268
1154
  deviation = 1,
1269
1155
  target: Element | ShadowRoot | Document = this.windowApi.document,
1270
- ignoreCallBack?: (
1271
- $ele: Element | HTMLElement | ShadowRoot
1272
- ) => boolean | void
1156
+ ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
1273
1157
  ): number {
1274
1158
  return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
1275
1159
  }
@@ -1293,33 +1177,22 @@ class Utils {
1293
1177
  * Utils.getMinValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
1294
1178
  * > 123
1295
1179
  */
1296
- getMinValue(
1297
- val: UtilsOwnObject<number>,
1298
- handler: (key: any, value: any) => number
1299
- ): number;
1180
+ getMinValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
1300
1181
  /**
1301
1182
  * 获取最小值
1302
1183
  * @example
1303
1184
  * Utils.getMinValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
1304
1185
  * > 0
1305
1186
  */
1306
- getMinValue(
1307
- val: UtilsOwnObject<number>[],
1308
- handler: (index: number, value: any) => number
1309
- ): number;
1187
+ getMinValue(val: UtilsOwnObject<number>[], handler: (index: number, value: any) => number): number;
1310
1188
  getMinValue(...args: any[]): number {
1311
1189
  let result = [...args];
1312
1190
  let newResult: number[] = [];
1313
1191
  if (result.length === 0) {
1314
- // @ts-ignore
1315
- return;
1192
+ return void 0 as any as number;
1316
1193
  }
1317
1194
  if (result.length > 1) {
1318
- if (
1319
- result.length === 2 &&
1320
- typeof result[0] === "object" &&
1321
- typeof result[1] === "function"
1322
- ) {
1195
+ if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
1323
1196
  let data = result[0];
1324
1197
  let handleDataFunc = result[1];
1325
1198
  Object.keys(data).forEach((keyName) => {
@@ -1434,23 +1307,14 @@ class Utils {
1434
1307
  * Utils.getRandomValue({1:1},{2:2})
1435
1308
  * > {1: 1}
1436
1309
  */
1437
- getRandomValue<T extends any>(
1438
- val_1: UtilsOwnObject<T>,
1439
- val_2: UtilsOwnObject<T>
1440
- ): T;
1310
+ getRandomValue<T extends any>(val_1: UtilsOwnObject<T>, val_2: UtilsOwnObject<T>): T;
1441
1311
  getRandomValue(...args: any[]): any {
1442
1312
  let result = [...args];
1443
1313
  if (result.length > 1) {
1444
- if (
1445
- result.length === 2 &&
1446
- typeof result[0] === "number" &&
1447
- typeof result[1] === "number"
1448
- ) {
1314
+ if (result.length === 2 && typeof result[0] === "number" && typeof result[1] === "number") {
1449
1315
  let leftNumber = result[0] > result[1] ? result[1] : result[0];
1450
1316
  let rightNumber = result[0] > result[1] ? result[0] : result[1];
1451
- return (
1452
- Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber
1453
- );
1317
+ return Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber;
1454
1318
  } else {
1455
1319
  return result[Math.floor(Math.random() * result.length)];
1456
1320
  }
@@ -1458,14 +1322,9 @@ class Utils {
1458
1322
  let paramData = result[0];
1459
1323
  if (Array.isArray(paramData)) {
1460
1324
  return paramData[Math.floor(Math.random() * paramData.length)];
1461
- } else if (
1462
- typeof paramData === "object" &&
1463
- Object.keys(paramData).length > 0
1464
- ) {
1325
+ } else if (typeof paramData === "object" && Object.keys(paramData).length > 0) {
1465
1326
  let paramObjDataKey =
1466
- Object.keys(paramData)[
1467
- Math.floor(Math.random() * Object.keys(paramData).length)
1468
- ];
1327
+ Object.keys(paramData)[Math.floor(Math.random() * Object.keys(paramData).length)];
1469
1328
  return paramData[paramObjDataKey];
1470
1329
  } else {
1471
1330
  return paramData;
@@ -1554,16 +1413,10 @@ class Utils {
1554
1413
  * Utils.getTextStorageSize("测试文本");
1555
1414
  * > '12.00B'
1556
1415
  */
1557
- getTextStorageSize<T extends boolean>(
1558
- text: string,
1559
- addType?: T
1560
- ): T extends true ? string : number;
1416
+ getTextStorageSize<T extends boolean>(text: string, addType?: T): T extends true ? string : number;
1561
1417
  getTextStorageSize(text: string, addType = true) {
1562
1418
  let UtilsContext = this;
1563
- return UtilsContext.formatByteToSize(
1564
- UtilsContext.getTextLength(text),
1565
- addType
1566
- );
1419
+ return UtilsContext.formatByteToSize(UtilsContext.getTextLength(text), addType);
1567
1420
  }
1568
1421
  /**
1569
1422
  * 获取迅雷协议的Url
@@ -1804,9 +1657,7 @@ class Utils {
1804
1657
  */
1805
1658
  isNativeFunc(target: Function): boolean;
1806
1659
  isNativeFunc(target: Function): boolean {
1807
- return Boolean(
1808
- target.toString().match(/^function .*\(\) { \[native code\] }$/)
1809
- );
1660
+ return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
1810
1661
  }
1811
1662
  /**
1812
1663
  * 判断当前的位置是否位于页面底部附近
@@ -1828,15 +1679,12 @@ class Utils {
1828
1679
  let checkWindow = () => {
1829
1680
  // 已滚动的距离
1830
1681
  let scrollTop: number =
1831
- this.windowApi.window.pageYOffset ||
1832
- this.windowApi.document.documentElement.scrollTop;
1682
+ this.windowApi.window.pageYOffset || this.windowApi.document.documentElement.scrollTop;
1833
1683
  // 视窗高度
1834
1684
  let viewportHeight: number =
1835
- this.windowApi.window.innerHeight ||
1836
- this.windowApi.document.documentElement.clientHeight;
1685
+ this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
1837
1686
  // 最大滚动距离
1838
- let maxScrollHeight: number =
1839
- this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
1687
+ let maxScrollHeight: number = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
1840
1688
 
1841
1689
  return scrollTop + viewportHeight >= maxScrollHeight;
1842
1690
  };
@@ -1847,8 +1695,7 @@ class Utils {
1847
1695
  // 视窗高度
1848
1696
  let viewportHeight: number = $ele.clientHeight;
1849
1697
  // 最大滚动距离
1850
- let maxScrollHeight: number =
1851
- $ele.scrollHeight - viewportHeight - nearBottomHeight;
1698
+ let maxScrollHeight: number = $ele.scrollHeight - viewportHeight - nearBottomHeight;
1852
1699
 
1853
1700
  return scrollTop >= maxScrollHeight;
1854
1701
  };
@@ -1905,7 +1752,6 @@ class Utils {
1905
1752
  isJQuery(target: any): boolean;
1906
1753
  isJQuery(target: any): boolean {
1907
1754
  let result = false;
1908
- // @ts-ignore
1909
1755
  if (typeof jQuery === "object" && target instanceof jQuery) {
1910
1756
  result = true;
1911
1757
  }
@@ -2164,8 +2010,7 @@ class Utils {
2164
2010
  */
2165
2011
  isThemeDark(): boolean;
2166
2012
  isThemeDark(): boolean {
2167
- return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
2168
- .matches;
2013
+ return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
2169
2014
  }
2170
2015
  /**
2171
2016
  * 判断元素是否在页面中可见
@@ -2180,10 +2025,7 @@ class Utils {
2180
2025
  * Utils.isVisible(document.documentElement)
2181
2026
  * > true
2182
2027
  */
2183
- isVisible(
2184
- element: HTMLElement | HTMLElement[] | Element | NodeList,
2185
- inView: boolean = false
2186
- ): boolean {
2028
+ isVisible(element: HTMLElement | HTMLElement[] | Element | NodeList, inView: boolean = false): boolean {
2187
2029
  let needCheckDomList = [];
2188
2030
  if (element instanceof Array || element instanceof NodeList) {
2189
2031
  element = element as HTMLElement[];
@@ -2200,11 +2042,9 @@ class Utils {
2200
2042
  let domClientRect = domItem.getBoundingClientRect();
2201
2043
  if (inView) {
2202
2044
  let viewportWidth =
2203
- this.windowApi.window.innerWidth ||
2204
- this.windowApi.document.documentElement.clientWidth;
2045
+ this.windowApi.window.innerWidth || this.windowApi.document.documentElement.clientWidth;
2205
2046
  let viewportHeight =
2206
- this.windowApi.window.innerHeight ||
2207
- this.windowApi.document.documentElement.clientHeight;
2047
+ this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
2208
2048
  result = !(
2209
2049
  domClientRect.right < 0 ||
2210
2050
  domClientRect.left > viewportWidth ||
@@ -2240,10 +2080,7 @@ class Utils {
2240
2080
  for (const key in Object.values((this.windowApi.top.window as any).via)) {
2241
2081
  if (Reflect.has((this.windowApi.top.window as any).via, key)) {
2242
2082
  let objValueFunc = (this.windowApi.top.window as any).via[key];
2243
- if (
2244
- typeof objValueFunc === "function" &&
2245
- UtilsContext.isNativeFunc(objValueFunc)
2246
- ) {
2083
+ if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
2247
2084
  result = true;
2248
2085
  } else {
2249
2086
  result = false;
@@ -2270,15 +2107,10 @@ class Utils {
2270
2107
  let result = true;
2271
2108
  let UtilsContext = this;
2272
2109
  if (typeof (this.windowApi.top.window as any).mbrowser === "object") {
2273
- for (const key in Object.values(
2274
- (this.windowApi.top.window as any).mbrowser
2275
- )) {
2110
+ for (const key in Object.values((this.windowApi.top.window as any).mbrowser)) {
2276
2111
  if (Reflect.has((this.windowApi.top.window as any).mbrowser, key)) {
2277
2112
  let objValueFunc = (this.windowApi.top.window as any).mbrowser[key];
2278
- if (
2279
- typeof objValueFunc === "function" &&
2280
- UtilsContext.isNativeFunc(objValueFunc)
2281
- ) {
2113
+ if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
2282
2114
  result = true;
2283
2115
  } else {
2284
2116
  result = false;
@@ -2302,9 +2134,7 @@ class Utils {
2302
2134
  parseObjectToArray<T extends any>(target: T): T[keyof T][];
2303
2135
  parseObjectToArray<T extends any>(target: T) {
2304
2136
  if (typeof target !== "object") {
2305
- throw new Error(
2306
- "Utils.parseObjectToArray 参数 target 必须为 object 类型"
2307
- );
2137
+ throw new Error("Utils.parseObjectToArray 参数 target 必须为 object 类型");
2308
2138
  }
2309
2139
  let result: T[keyof T][] = [];
2310
2140
  Object.keys(target!).forEach(function (keyName) {
@@ -2362,14 +2192,8 @@ class Utils {
2362
2192
  * Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
2363
2193
  * > '数组内数据部分字段合并成字符串->mergeToString'
2364
2194
  **/
2365
- mergeArrayToString<T extends any>(
2366
- data: T[],
2367
- handleFunc?: ((val: T) => T) | keyof T
2368
- ): string;
2369
- mergeArrayToString<T extends any>(
2370
- data: T[],
2371
- handleFunc?: ((val: T) => T) | keyof T
2372
- ): string {
2195
+ mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string;
2196
+ mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string {
2373
2197
  if (!(data instanceof Array)) {
2374
2198
  throw new Error("Utils.mergeArrayToString 参数 data 必须为 Array 类型");
2375
2199
  }
@@ -2490,10 +2314,7 @@ class Utils {
2490
2314
  },
2491
2315
  immediate: false,
2492
2316
  };
2493
- observer_config = UtilsContext.assign(
2494
- default_obverser_config,
2495
- observer_config
2496
- );
2317
+ observer_config = UtilsContext.assign(default_obverser_config, observer_config);
2497
2318
  let windowMutationObserver =
2498
2319
  this.windowApi.window.MutationObserver ||
2499
2320
  (this.windowApi.window as any).webkitMutationObserver ||
@@ -2541,10 +2362,7 @@ class Utils {
2541
2362
  */
2542
2363
  mutationVisible(
2543
2364
  target: Element | Element[],
2544
- callback: (
2545
- entries: IntersectionObserverEntry[],
2546
- observer: IntersectionObserver
2547
- ) => void,
2365
+ callback: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void,
2548
2366
  options?: IntersectionObserverInit
2549
2367
  ) {
2550
2368
  if (typeof IntersectionObserver === "undefined") {
@@ -2633,34 +2451,24 @@ class Utils {
2633
2451
  ): void {
2634
2452
  let UtilsContext = this;
2635
2453
  if (typeof needReleaseObject !== "object") {
2636
- throw new Error(
2637
- "Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型"
2638
- );
2454
+ throw new Error("Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型");
2639
2455
  }
2640
2456
  if (typeof needReleaseName !== "string") {
2641
- throw new Error(
2642
- "Utils.noConflictFunc 参数 needReleaseName 必须为 string 类型"
2643
- );
2457
+ throw new Error("Utils.noConflictFunc 参数 needReleaseName 必须为 string 类型");
2644
2458
  }
2645
2459
  if (!Array.isArray(functionNameList)) {
2646
- throw new Error(
2647
- "Utils.noConflictFunc 参数 functionNameList 必须为 Array 类型"
2648
- );
2460
+ throw new Error("Utils.noConflictFunc 参数 functionNameList 必须为 Array 类型");
2649
2461
  }
2650
2462
  let needReleaseKey = "__" + needReleaseName;
2651
2463
  /**
2652
2464
  * 释放所有
2653
2465
  */
2654
2466
  function releaseAll() {
2655
- if (
2656
- typeof (UtilsContext.windowApi.window as any)[needReleaseKey] !==
2657
- "undefined"
2658
- ) {
2467
+ if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] !== "undefined") {
2659
2468
  /* 已存在 */
2660
2469
  return;
2661
2470
  }
2662
- (UtilsContext.windowApi.window as any)[needReleaseKey] =
2663
- UtilsContext.deepClone(needReleaseObject);
2471
+ (UtilsContext.windowApi.window as any)[needReleaseKey] = UtilsContext.deepClone(needReleaseObject);
2664
2472
  Object.values(needReleaseObject).forEach((value) => {
2665
2473
  if (typeof value === "function") {
2666
2474
  (needReleaseObject as any)[value.name] = () => {};
@@ -2674,16 +2482,13 @@ class Utils {
2674
2482
  Array.from(functionNameList).forEach((item) => {
2675
2483
  Object.values(needReleaseObject).forEach((value) => {
2676
2484
  if (typeof value === "function") {
2677
- if (
2678
- typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2679
- "undefined"
2680
- ) {
2485
+ if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
2681
2486
  (UtilsContext.windowApi.window as any)[needReleaseKey] = {};
2682
2487
  }
2683
2488
  if (item === value.name) {
2684
- (UtilsContext.windowApi.window as any)[needReleaseKey][
2489
+ (UtilsContext.windowApi.window as any)[needReleaseKey][value.name] = (needReleaseObject as any)[
2685
2490
  value.name
2686
- ] = (needReleaseObject as any)[value.name];
2491
+ ];
2687
2492
  (needReleaseObject as any)[value.name] = () => {};
2688
2493
  }
2689
2494
  }
@@ -2694,47 +2499,27 @@ class Utils {
2694
2499
  * 恢复所有
2695
2500
  */
2696
2501
  function recoveryAll() {
2697
- if (
2698
- typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2699
- "undefined"
2700
- ) {
2502
+ if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
2701
2503
  /* 未存在 */
2702
2504
  return;
2703
2505
  }
2704
- Object.assign(
2705
- needReleaseObject,
2706
- (UtilsContext.windowApi.window as any)[needReleaseKey]
2707
- );
2708
- Reflect.deleteProperty(
2709
- UtilsContext.windowApi.window as any,
2710
- "needReleaseKey"
2711
- );
2506
+ Object.assign(needReleaseObject, (UtilsContext.windowApi.window as any)[needReleaseKey]);
2507
+ Reflect.deleteProperty(UtilsContext.windowApi.window as any, "needReleaseKey");
2712
2508
  }
2713
2509
 
2714
2510
  /**
2715
2511
  * 恢复单个
2716
2512
  */
2717
2513
  function recoveryOne() {
2718
- if (
2719
- typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2720
- "undefined"
2721
- ) {
2514
+ if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
2722
2515
  /* 未存在 */
2723
2516
  return;
2724
2517
  }
2725
2518
  Array.from(functionNameList).forEach((item) => {
2726
2519
  if ((UtilsContext.windowApi.window as any)[needReleaseKey][item]) {
2727
- (needReleaseObject as any)[item] = (
2728
- UtilsContext.windowApi.window as any
2729
- )[needReleaseKey][item];
2730
- Reflect.deleteProperty(
2731
- (UtilsContext.windowApi.window as any)[needReleaseKey],
2732
- item
2733
- );
2734
- if (
2735
- Object.keys((UtilsContext.windowApi.window as any)[needReleaseKey])
2736
- .length === 0
2737
- ) {
2520
+ (needReleaseObject as any)[item] = (UtilsContext.windowApi.window as any)[needReleaseKey][item];
2521
+ Reflect.deleteProperty((UtilsContext.windowApi.window as any)[needReleaseKey], item);
2522
+ if (Object.keys((UtilsContext.windowApi.window as any)[needReleaseKey]).length === 0) {
2738
2523
  Reflect.deleteProperty(window, needReleaseKey);
2739
2524
  }
2740
2525
  }
@@ -2769,9 +2554,7 @@ class Utils {
2769
2554
  parseBase64ToBlob(dataUri: string): Blob;
2770
2555
  parseBase64ToBlob(dataUri: string): Blob {
2771
2556
  if (typeof dataUri !== "string") {
2772
- throw new Error(
2773
- "Utils.parseBase64ToBlob 参数 dataUri 必须为 string 类型"
2774
- );
2557
+ throw new Error("Utils.parseBase64ToBlob 参数 dataUri 必须为 string 类型");
2775
2558
  }
2776
2559
  let dataUriSplit = dataUri.split(","),
2777
2560
  dataUriMime = (dataUriSplit[0] as any).match(/:(.*?);/)[1],
@@ -2797,14 +2580,10 @@ class Utils {
2797
2580
  parseBase64ToFile(dataUri: string, fileName?: string): File;
2798
2581
  parseBase64ToFile(dataUri: string, fileName = "example") {
2799
2582
  if (typeof dataUri !== "string") {
2800
- throw new Error(
2801
- "Utils.parseBase64ToFile 参数 dataUri 必须为 string 类型"
2802
- );
2583
+ throw new Error("Utils.parseBase64ToFile 参数 dataUri 必须为 string 类型");
2803
2584
  }
2804
2585
  if (typeof fileName !== "string") {
2805
- throw new Error(
2806
- "Utils.parseBase64ToFile 参数 fileName 必须为 string 类型"
2807
- );
2586
+ throw new Error("Utils.parseBase64ToFile 参数 fileName 必须为 string 类型");
2808
2587
  }
2809
2588
  let dataUriSplit = dataUri.split(","),
2810
2589
  dataUriMime = (dataUriSplit[0] as any).match(/:(.*?);/)[1],
@@ -2841,10 +2620,7 @@ class Utils {
2841
2620
  * Utils.parseInt(["aaaaaaa"],"aa");
2842
2621
  * > NaN
2843
2622
  **/
2844
- parseInt(
2845
- matchList?: any[] | null | undefined | RegExpMatchArray,
2846
- defaultValue?: number
2847
- ): number;
2623
+ parseInt(matchList?: any[] | null | undefined | RegExpMatchArray, defaultValue?: number): number;
2848
2624
  parseInt(matchList: any[] = [], defaultValue = 0): number {
2849
2625
  if (matchList == null) {
2850
2626
  return parseInt(defaultValue.toString());
@@ -2864,10 +2640,7 @@ class Utils {
2864
2640
  * > object
2865
2641
  **/
2866
2642
  parseBlobToFile(blobUrl: string, fileName?: string): Promise<File | Error>;
2867
- async parseBlobToFile(
2868
- blobUrl: string,
2869
- fileName: string = "example"
2870
- ): Promise<File | Error> {
2643
+ async parseBlobToFile(blobUrl: string, fileName: string = "example"): Promise<File | Error> {
2871
2644
  return new Promise((resolve, reject) => {
2872
2645
  fetch(blobUrl)
2873
2646
  .then((response) => response.blob())
@@ -2932,12 +2705,7 @@ class Utils {
2932
2705
  */
2933
2706
  parseFromString(
2934
2707
  text: string,
2935
- mimeType?:
2936
- | "text/html"
2937
- | "text/xml"
2938
- | "application/xml"
2939
- | "application/xhtml+xml"
2940
- | "image/svg+xml"
2708
+ mimeType?: "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml"
2941
2709
  ): HTMLElement | XMLDocument | SVGElement;
2942
2710
  parseFromString(
2943
2711
  text: string,
@@ -2985,11 +2753,7 @@ class Utils {
2985
2753
  * @example
2986
2754
  * Utils.preventEvent(event);
2987
2755
  */
2988
- preventEvent(
2989
- element: HTMLElement,
2990
- eventNameList?: string | string[],
2991
- capture?: boolean
2992
- ): boolean;
2756
+ preventEvent(element: HTMLElement, eventNameList?: string | string[], capture?: boolean): boolean;
2993
2757
  preventEvent(
2994
2758
  element: HTMLElement | Event,
2995
2759
  eventNameList: string | string[] = [],
@@ -3033,14 +2797,8 @@ class Utils {
3033
2797
  * @example
3034
2798
  * Utils.registerTrustClickEvent()
3035
2799
  */
3036
- registerTrustClickEvent(
3037
- isTrustValue?: boolean,
3038
- filter?: (typeName: string) => boolean
3039
- ): void;
3040
- registerTrustClickEvent(
3041
- isTrustValue: boolean = true,
3042
- filter?: (typeName: string) => boolean
3043
- ): void {
2800
+ registerTrustClickEvent(isTrustValue?: boolean, filter?: (typeName: string) => boolean): void;
2801
+ registerTrustClickEvent(isTrustValue: boolean = true, filter?: (typeName: string) => boolean): void {
3044
2802
  function trustEvent(event: Event) {
3045
2803
  return new Proxy(event, {
3046
2804
  get: function (target, property) {
@@ -3060,31 +2818,27 @@ class Utils {
3060
2818
  const originalListener = EventTarget.prototype.addEventListener;
3061
2819
  EventTarget.prototype.addEventListener = function (...args) {
3062
2820
  let type = args[0];
3063
- let callback = args[1];
3064
- // @ts-ignore
3065
- let options = args[2];
2821
+ let callback: any = args[1];
2822
+ // let options = args[2];
3066
2823
  if (filter(type)) {
3067
2824
  if (typeof callback === "function") {
3068
2825
  args[1] = function (event) {
3069
2826
  callback.call(this, trustEvent(event));
3070
2827
  };
3071
- } else if (
3072
- typeof callback === "object" &&
3073
- "handleEvent" in (callback as any)
3074
- ) {
3075
- let oldHandleEvent = (callback as any)["handleEvent"];
2828
+ } else if (typeof callback === "object" && "handleEvent" in callback) {
2829
+ let oldHandleEvent = callback["handleEvent"];
3076
2830
 
3077
2831
  (args[1] as any)["handleEvent"] = function (event: Event) {
3078
2832
  if (event == null) {
3079
2833
  return;
3080
2834
  }
3081
2835
  try {
3082
- /* Proxy对象使用instanceof会报错 */
2836
+ // Proxy对象使用instanceof会报错
2837
+ // 这里故意尝试一下,如果报错,则说明是Proxy对象
3083
2838
  event instanceof Proxy;
3084
2839
  oldHandleEvent.call(this, trustEvent(event));
3085
2840
  } catch (error) {
3086
- // @ts-ignore
3087
- event["isTrusted"] = isTrustValue;
2841
+ Reflect.set(event, "isTrusted", isTrustValue);
3088
2842
  }
3089
2843
  };
3090
2844
  }
@@ -3226,12 +2980,9 @@ class Utils {
3226
2980
  }
3227
2981
  async init() {
3228
2982
  let copyStatus = false;
3229
- // @ts-ignore
3230
2983
  let requestPermissionStatus = await this.requestClipboardPermission();
3231
- if (
3232
- this.hasClipboard() &&
3233
- (this.hasClipboardWrite() || this.hasClipboardWriteText())
3234
- ) {
2984
+ console.log(requestPermissionStatus);
2985
+ if (this.hasClipboard() && (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
3235
2986
  try {
3236
2987
  copyStatus = await this.copyDataByClipboard();
3237
2988
  } catch (error) {
@@ -3245,12 +2996,9 @@ class Utils {
3245
2996
  this.destroy();
3246
2997
  }
3247
2998
  destroy() {
3248
- // @ts-ignore
3249
- this.#resolve = null;
3250
- // @ts-ignore
2999
+ this.#resolve = null as any;
3251
3000
  this.#copyData = null;
3252
- // @ts-ignore
3253
- this.#copyDataType = null;
3001
+ this.#copyDataType = null as any;
3254
3002
  }
3255
3003
  isText() {
3256
3004
  return this.#copyDataType.includes("text");
@@ -3269,8 +3017,7 @@ class Utils {
3269
3017
  */
3270
3018
  copyTextByTextArea() {
3271
3019
  try {
3272
- let copyElement =
3273
- UtilsContext.windowApi.document.createElement("textarea");
3020
+ let copyElement = UtilsContext.windowApi.document.createElement("textarea");
3274
3021
  copyElement.value = this.#copyData;
3275
3022
  copyElement.setAttribute("type", "text");
3276
3023
  copyElement.setAttribute("style", "opacity:0;position:absolute;");
@@ -3293,8 +3040,7 @@ class Utils {
3293
3040
  if (navigator.permissions && navigator.permissions.query) {
3294
3041
  navigator.permissions
3295
3042
  .query({
3296
- // @ts-ignore
3297
- name: "clipboard-write",
3043
+ name: "clipboard-write" as any as PermissionName,
3298
3044
  })
3299
3045
  .then((permissionStatus) => {
3300
3046
  resolve(true);
@@ -3374,15 +3120,10 @@ class Utils {
3374
3120
  * > ƒ tryCatchObj() {}
3375
3121
  **/
3376
3122
  setTimeout(callback: (() => void) | string, delayTime?: number): Promise<any>;
3377
- setTimeout(
3378
- callback: (() => void) | string,
3379
- delayTime: number = 0
3380
- ): Promise<any> {
3123
+ setTimeout(callback: (() => void) | string, delayTime: number = 0): Promise<any> {
3381
3124
  let UtilsContext = this;
3382
3125
  if (typeof callback !== "function" && typeof callback !== "string") {
3383
- throw new TypeError(
3384
- "Utils.setTimeout 参数 callback 必须为 function|string 类型"
3385
- );
3126
+ throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
3386
3127
  }
3387
3128
  if (typeof delayTime !== "number") {
3388
3129
  throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
@@ -3421,25 +3162,16 @@ class Utils {
3421
3162
  * Utils.dragSlider("#xxxx",100);
3422
3163
  */
3423
3164
  dragSlider(selector: string | Element | Node, offsetX?: number): void;
3424
- dragSlider(
3425
- selector: string | Element | Node,
3426
- offsetX: number = this.windowApi.window.innerWidth
3427
- ): void {
3165
+ dragSlider(selector: string | Element | Node, offsetX: number = this.windowApi.window.innerWidth): void {
3428
3166
  let UtilsContext = this;
3429
- function initMouseEvent(
3430
- eventName: string,
3431
- offSetX: number,
3432
- offSetY: number
3433
- ) {
3434
- // @ts-ignore
3167
+ function initMouseEvent(eventName: string, offSetX: number, offSetY: number) {
3435
3168
  let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
3436
- let mouseEvent =
3437
- UtilsContext.windowApi.document.createEvent("MouseEvents");
3169
+ let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
3438
3170
  mouseEvent.initMouseEvent(
3439
3171
  eventName,
3440
3172
  true,
3441
3173
  true,
3442
- win,
3174
+ win as Window,
3443
3175
  0,
3444
3176
  offSetX,
3445
3177
  offSetY,
@@ -3454,14 +3186,8 @@ class Utils {
3454
3186
  );
3455
3187
  return mouseEvent;
3456
3188
  }
3457
- let sliderElement =
3458
- typeof selector === "string"
3459
- ? domUtils.selector<HTMLElement>(selector)
3460
- : selector;
3461
- if (
3462
- !(sliderElement instanceof Node) ||
3463
- !(sliderElement instanceof Element)
3464
- ) {
3189
+ let sliderElement = typeof selector === "string" ? domUtils.selector<HTMLElement>(selector) : selector;
3190
+ if (!(sliderElement instanceof Node) || !(sliderElement instanceof Element)) {
3465
3191
  throw new Error("Utils.dragSlider 参数selector 必须为Node/Element类型");
3466
3192
  }
3467
3193
  let rect = sliderElement.getBoundingClientRect(),
@@ -3509,9 +3235,7 @@ class Utils {
3509
3235
  * Utils.exitFullScreen();
3510
3236
  */
3511
3237
  exitFullScreen(element?: HTMLElement): Promise<void>;
3512
- exitFullScreen(
3513
- element: HTMLElement = this.windowApi.document.documentElement
3514
- ): Promise<void> {
3238
+ exitFullScreen(element: HTMLElement = this.windowApi.document.documentElement): Promise<void> {
3515
3239
  if (this.windowApi.document.exitFullscreen) {
3516
3240
  return this.windowApi.document.exitFullscreen();
3517
3241
  } else if ((this.windowApi.document as any).msExitFullscreen) {
@@ -3552,23 +3276,14 @@ class Utils {
3552
3276
  sortByDesc: boolean = true
3553
3277
  ): T[] {
3554
3278
  let UtilsContext = this;
3555
- if (
3556
- typeof getPropertyValueFunc !== "function" &&
3557
- typeof getPropertyValueFunc !== "string"
3558
- ) {
3559
- throw new Error(
3560
- "Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型"
3561
- );
3279
+ if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
3280
+ throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
3562
3281
  }
3563
3282
  if (typeof sortByDesc !== "boolean") {
3564
- throw new Error(
3565
- "Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型"
3566
- );
3283
+ throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
3567
3284
  }
3568
3285
  let getObjValue = function (obj: any) {
3569
- return typeof getPropertyValueFunc === "string"
3570
- ? obj[getPropertyValueFunc]
3571
- : getPropertyValueFunc(obj);
3286
+ return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
3572
3287
  };
3573
3288
  /**
3574
3289
  * 排序方法
@@ -3641,16 +3356,11 @@ class Utils {
3641
3356
  }
3642
3357
  if (Array.isArray(data)) {
3643
3358
  data.sort(sortFunc);
3644
- } else if (
3645
- (data as any) instanceof NodeList ||
3646
- UtilsContext.isJQuery(data)
3647
- ) {
3359
+ } else if ((data as any) instanceof NodeList || UtilsContext.isJQuery(data)) {
3648
3360
  sortNodeFunc(data as any, getDataFunc as any);
3649
3361
  result = (getDataFunc as any)();
3650
3362
  } else {
3651
- throw new Error(
3652
- "Utils.sortListByProperty 参数 data 必须为 Array|NodeList|jQuery 类型"
3653
- );
3363
+ throw new Error("Utils.sortListByProperty 参数 data 必须为 Array|NodeList|jQuery 类型");
3654
3364
  }
3655
3365
  return result;
3656
3366
  }
@@ -3659,28 +3369,16 @@ class Utils {
3659
3369
  * @param targetString 需要进行转换的字符串
3660
3370
  * @param flags 正则标志
3661
3371
  */
3662
- stringToRegular(
3663
- targetString: string | RegExp,
3664
- flags?: "g" | "i" | "m" | "u" | "y" | string
3665
- ): RegExp;
3666
- stringToRegular(
3667
- targetString: string | RegExp,
3668
- flags: "g" | "i" | "m" | "u" | "y" | string = "ig"
3669
- ): RegExp {
3372
+ stringToRegular(targetString: string | RegExp, flags?: "g" | "i" | "m" | "u" | "y" | string): RegExp;
3373
+ stringToRegular(targetString: string | RegExp, flags: "g" | "i" | "m" | "u" | "y" | string = "ig"): RegExp {
3670
3374
  let reg;
3671
- // @ts-ignore
3672
3375
  flags = flags.toLowerCase();
3673
3376
  if (typeof targetString === "string") {
3674
- reg = new RegExp(
3675
- targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"),
3676
- flags
3677
- );
3377
+ reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
3678
3378
  } else if ((targetString as any) instanceof RegExp) {
3679
3379
  reg = targetString;
3680
3380
  } else {
3681
- throw new Error(
3682
- "Utils.stringToRegular 参数targetString必须是string|Regexp类型"
3683
- );
3381
+ throw new Error("Utils.stringToRegular 参数targetString必须是string|Regexp类型");
3684
3382
  }
3685
3383
  return reg;
3686
3384
  }
@@ -3689,14 +3387,8 @@ class Utils {
3689
3387
  * @param targetString 目标字符串
3690
3388
  * @param otherStrToLowerCase (可选)剩余部分字符串转小写,默认false
3691
3389
  */
3692
- stringTitleToUpperCase(
3693
- targetString: string,
3694
- otherStrToLowerCase?: boolean
3695
- ): string;
3696
- stringTitleToUpperCase(
3697
- targetString: string,
3698
- otherStrToLowerCase: boolean = false
3699
- ): string {
3390
+ stringTitleToUpperCase(targetString: string, otherStrToLowerCase?: boolean): string;
3391
+ stringTitleToUpperCase(targetString: string, otherStrToLowerCase: boolean = false): string {
3700
3392
  let newTargetString = targetString.slice(0, 1).toUpperCase();
3701
3393
  if (otherStrToLowerCase) {
3702
3394
  newTargetString = newTargetString + targetString.slice(1).toLowerCase();
@@ -3713,16 +3405,8 @@ class Utils {
3713
3405
  * @param searchString 需要搜索的字符串
3714
3406
  * @param position (可选)目标字符串的判断起点,要求≥0,默认为0
3715
3407
  */
3716
- startsWith(
3717
- target: string,
3718
- searchString: string | RegExp | string[],
3719
- position?: number
3720
- ): boolean;
3721
- startsWith(
3722
- target: string,
3723
- searchString: string | RegExp | string[],
3724
- position: number = 0
3725
- ): boolean {
3408
+ startsWith(target: string, searchString: string | RegExp | string[], position?: number): boolean;
3409
+ startsWith(target: string, searchString: string | RegExp | string[], position: number = 0): boolean {
3726
3410
  let UtilsContext = this;
3727
3411
  if (position > target.length) {
3728
3412
  /* 超出目标字符串的长度 */
@@ -3751,14 +3435,8 @@ class Utils {
3751
3435
  * @param targetString 目标字符串
3752
3436
  * @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
3753
3437
  */
3754
- stringTitleToLowerCase(
3755
- targetString: string,
3756
- otherStrToUpperCase?: boolean
3757
- ): string;
3758
- stringTitleToLowerCase(
3759
- targetString: string,
3760
- otherStrToUpperCase: boolean = false
3761
- ): string {
3438
+ stringTitleToLowerCase(targetString: string, otherStrToUpperCase?: boolean): string;
3439
+ stringTitleToLowerCase(targetString: string, otherStrToUpperCase: boolean = false): string {
3762
3440
  let newTargetString = targetString.slice(0, 1).toLowerCase();
3763
3441
  if (otherStrToUpperCase) {
3764
3442
  newTargetString = newTargetString + targetString.slice(1).toUpperCase();
@@ -3820,15 +3498,11 @@ class Utils {
3820
3498
  /**
3821
3499
  * 将UrlSearchParams格式的字符串转为对象
3822
3500
  */
3823
- searchParamStrToObj<T extends any>(
3824
- searhParamsStr?: string | null | undefined
3825
- ): T {
3501
+ searchParamStrToObj<T extends any>(searhParamsStr?: string | null | undefined): T {
3826
3502
  if (typeof searhParamsStr !== "string") {
3827
- // @ts-ignore
3828
- return {};
3503
+ return {} as any as T;
3829
3504
  }
3830
- // @ts-ignore
3831
- return Object.fromEntries(new URLSearchParams(searhParamsStr));
3505
+ return Object.fromEntries(new URLSearchParams(searhParamsStr) as any) as any;
3832
3506
  }
3833
3507
  /**
3834
3508
  * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
@@ -3871,10 +3545,7 @@ class Utils {
3871
3545
  * Utils.uniqueArray([{name:"1",host:"baidu.com"},{name:"2",host:"baidu.com"},{name:"3",host:"baidu.com"}]);
3872
3546
  * > [{name:"1",host:"baidu.com"}]
3873
3547
  */
3874
- uniqueArray<T>(
3875
- uniqueArrayData: T[],
3876
- getIdentfierValue: (itemValue: T) => any
3877
- ): T[];
3548
+ uniqueArray<T>(uniqueArrayData: T[], getIdentfierValue: (itemValue: T) => any): T[];
3878
3549
  uniqueArray<T, T2>(
3879
3550
  uniqueArrayData: T[] = [],
3880
3551
  compareArrayData: any,
@@ -3913,19 +3584,11 @@ class Utils {
3913
3584
  * @example
3914
3585
  * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
3915
3586
  **/
3916
- waitArrayLoopToEnd(
3917
- data: any[] | HTMLElement[],
3918
- handleFunc: Function
3919
- ): Promise<void[]>;
3920
- waitArrayLoopToEnd(
3921
- data: any[] | HTMLElement[],
3922
- handleFunc: Function
3923
- ): Promise<void[]> {
3587
+ waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
3588
+ waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]> {
3924
3589
  let UtilsContext = this;
3925
3590
  if (typeof handleFunc !== "function" && typeof handleFunc !== "string") {
3926
- throw new Error(
3927
- "Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型"
3928
- );
3591
+ throw new Error("Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型");
3929
3592
  }
3930
3593
  return Promise.all(
3931
3594
  Array.from(data).map(async (item, index) => {
@@ -3994,27 +3657,24 @@ class Utils {
3994
3657
  const UtilsContext = this;
3995
3658
  let __timeout__ = typeof timeout === "number" ? timeout : 0;
3996
3659
  return new Promise((resolve) => {
3997
- let observer = UtilsContext.mutationObserver(
3998
- parent || UtilsContext.windowApi.document,
3999
- {
4000
- config: {
4001
- subtree: true,
4002
- childList: true,
4003
- attributes: true,
4004
- },
4005
- immediate: true,
4006
- callback(mutations, __observer__) {
4007
- let result = checkFn();
4008
- if (result.success) {
4009
- // 取消观察器
4010
- if (typeof __observer__?.disconnect === "function") {
4011
- __observer__.disconnect();
4012
- }
4013
- resolve(result.data);
3660
+ let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
3661
+ config: {
3662
+ subtree: true,
3663
+ childList: true,
3664
+ attributes: true,
3665
+ },
3666
+ immediate: true,
3667
+ callback(mutations, __observer__) {
3668
+ let result = checkFn();
3669
+ if (result.success) {
3670
+ // 取消观察器
3671
+ if (typeof __observer__?.disconnect === "function") {
3672
+ __observer__.disconnect();
4014
3673
  }
4015
- },
4016
- }
4017
- );
3674
+ resolve(result.data);
3675
+ }
3676
+ },
3677
+ });
4018
3678
  if (__timeout__ > 0) {
4019
3679
  UtilsContext.workerSetTimeout(() => {
4020
3680
  // 取消观察器
@@ -4056,10 +3716,7 @@ class Utils {
4056
3716
  selector: K,
4057
3717
  parent?: Node | Element | Document | HTMLElement
4058
3718
  ): Promise<HTMLElementTagNameMap[K]>;
4059
- waitNode<T extends Element>(
4060
- selector: string,
4061
- parent?: Node | Element | Document | HTMLElement
4062
- ): Promise<T>;
3719
+ waitNode<T extends Element>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
4063
3720
  /**
4064
3721
  * 等待元素出现
4065
3722
  * @param selectorList CSS选择器数组
@@ -4133,10 +3790,7 @@ class Utils {
4133
3790
  selector: K,
4134
3791
  timeout: number
4135
3792
  ): Promise<HTMLElementTagNameMap[K] | null>;
4136
- waitNode<T extends Element>(
4137
- selector: string,
4138
- timeout: number
4139
- ): Promise<T | null>;
3793
+ waitNode<T extends Element>(selector: string, timeout: number): Promise<T | null>;
4140
3794
  /**
4141
3795
  * 等待元素出现
4142
3796
  * @param selectorList CSS选择器数组
@@ -4150,10 +3804,7 @@ class Utils {
4150
3804
  selectorList: K[],
4151
3805
  timeout: number
4152
3806
  ): Promise<HTMLElementTagNameMap[K] | null>;
4153
- waitNode<T extends Element[]>(
4154
- selectorList: string[],
4155
- timeout: number
4156
- ): Promise<T | null>;
3807
+ waitNode<T extends Element[]>(selectorList: string[], timeout: number): Promise<T | null>;
4157
3808
  waitNode<T extends Element | Element[]>(...args: any[]): Promise<T | null> {
4158
3809
  // 过滤掉undefined
4159
3810
  args = args.filter((arg) => arg !== void 0);
@@ -4164,14 +3815,8 @@ class Utils {
4164
3815
  let parent: Element = UtilsContext.windowApi.document as any as Element;
4165
3816
  // 超时时间
4166
3817
  let timeout = 0;
4167
- if (
4168
- typeof args[0] !== "string" &&
4169
- !Array.isArray(args[0]) &&
4170
- typeof args[0] !== "function"
4171
- ) {
4172
- throw new TypeError(
4173
- "Utils.waitNode 第一个参数必须是string|string[]|Function"
4174
- );
3818
+ if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
3819
+ throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
4175
3820
  }
4176
3821
  if (args.length === 1) {
4177
3822
  // 上面已做处理
@@ -4180,10 +3825,7 @@ class Utils {
4180
3825
  if (typeof secondParam === "number") {
4181
3826
  // "div",10000
4182
3827
  timeout = secondParam;
4183
- } else if (
4184
- typeof secondParam === "object" &&
4185
- secondParam instanceof Node
4186
- ) {
3828
+ } else if (typeof secondParam === "object" && secondParam instanceof Node) {
4187
3829
  // "div",document
4188
3830
  parent = secondParam as any as Element;
4189
3831
  } else {
@@ -4298,10 +3940,7 @@ class Utils {
4298
3940
  selectorList: K[],
4299
3941
  timeout: number
4300
3942
  ): Promise<HTMLElementTagNameMap[K] | null>;
4301
- waitAnyNode<T extends Element>(
4302
- selectorList: string[],
4303
- timeout: number
4304
- ): Promise<T | null>;
3943
+ waitAnyNode<T extends Element>(selectorList: string[], timeout: number): Promise<T | null>;
4305
3944
  waitAnyNode<T extends Element>(...args: any[]): Promise<T | null> {
4306
3945
  // 过滤掉undefined
4307
3946
  args = args.filter((arg) => arg !== void 0);
@@ -4322,10 +3961,7 @@ class Utils {
4322
3961
  if (typeof secondParam === "number") {
4323
3962
  // "div",10000
4324
3963
  timeout = secondParam;
4325
- } else if (
4326
- typeof secondParam === "object" &&
4327
- secondParam instanceof Node
4328
- ) {
3964
+ } else if (typeof secondParam === "object" && secondParam instanceof Node) {
4329
3965
  // "div",document
4330
3966
  parent = secondParam as any as Element;
4331
3967
  } else {
@@ -4448,10 +4084,7 @@ class Utils {
4448
4084
  selector: K[],
4449
4085
  timeout: number
4450
4086
  ): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
4451
- waitNodeList<T extends NodeListOf<Element>>(
4452
- selector: string[],
4453
- timeout: number
4454
- ): Promise<T | null>;
4087
+ waitNodeList<T extends NodeListOf<Element>>(selector: string[], timeout: number): Promise<T | null>;
4455
4088
  /**
4456
4089
  * 等待元素数组出现
4457
4090
  * @param selectorList CSS选择器数组
@@ -4465,13 +4098,8 @@ class Utils {
4465
4098
  selectorList: K[],
4466
4099
  timeout: number
4467
4100
  ): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
4468
- waitNodeList<T extends NodeListOf<Element>>(
4469
- selectorList: string[],
4470
- timeout: number
4471
- ): Promise<T[] | null>;
4472
- waitNodeList<T extends NodeListOf<Element> | NodeListOf<Element>[]>(
4473
- ...args: any[]
4474
- ): Promise<T | null> {
4101
+ waitNodeList<T extends NodeListOf<Element>>(selectorList: string[], timeout: number): Promise<T[] | null>;
4102
+ waitNodeList<T extends NodeListOf<Element> | NodeListOf<Element>[]>(...args: any[]): Promise<T | null> {
4475
4103
  // 过滤掉undefined
4476
4104
  args = args.filter((arg) => arg !== void 0);
4477
4105
  let UtilsContext = this;
@@ -4491,10 +4119,7 @@ class Utils {
4491
4119
  if (typeof secondParam === "number") {
4492
4120
  // "div",10000
4493
4121
  timeout = secondParam;
4494
- } else if (
4495
- typeof secondParam === "object" &&
4496
- secondParam instanceof Node
4497
- ) {
4122
+ } else if (typeof secondParam === "object" && secondParam instanceof Node) {
4498
4123
  // "div",document
4499
4124
  parent = secondParam as any as Element;
4500
4125
  } else {
@@ -4610,13 +4235,8 @@ class Utils {
4610
4235
  selectorList: K[],
4611
4236
  timeout: number
4612
4237
  ): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
4613
- waitAnyNodeList<T extends Element>(
4614
- selectorList: string[],
4615
- timeout: number
4616
- ): Promise<NodeListOf<T> | null>;
4617
- waitAnyNodeList<T extends Element>(
4618
- ...args: any[]
4619
- ): Promise<NodeListOf<T> | null> {
4238
+ waitAnyNodeList<T extends Element>(selectorList: string[], timeout: number): Promise<NodeListOf<T> | null>;
4239
+ waitAnyNodeList<T extends Element>(...args: any[]): Promise<NodeListOf<T> | null> {
4620
4240
  // 过滤掉undefined
4621
4241
  args = args.filter((arg) => arg !== void 0);
4622
4242
  let UtilsContext = this;
@@ -4636,16 +4256,11 @@ class Utils {
4636
4256
  if (typeof secondParam === "number") {
4637
4257
  // "div",10000
4638
4258
  timeout = secondParam;
4639
- } else if (
4640
- typeof secondParam === "object" &&
4641
- secondParam instanceof Node
4642
- ) {
4259
+ } else if (typeof secondParam === "object" && secondParam instanceof Node) {
4643
4260
  // "div",document
4644
4261
  parent = secondParam as any as Element;
4645
4262
  } else {
4646
- throw new TypeError(
4647
- "Utils.waitAnyNodeList 第二个参数必须是number|Node"
4648
- );
4263
+ throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
4649
4264
  }
4650
4265
  } else if (args.length === 3) {
4651
4266
  // "div",document,10000
@@ -4668,11 +4283,7 @@ class Utils {
4668
4283
  }
4669
4284
 
4670
4285
  let promiseList = selectorList.map((selector) => {
4671
- return UtilsContext.waitNodeList<NodeListOf<T>>(
4672
- selector,
4673
- parent,
4674
- timeout
4675
- );
4286
+ return UtilsContext.waitNodeList<NodeListOf<T>>(selector, parent, timeout);
4676
4287
  });
4677
4288
  return Promise.any(promiseList);
4678
4289
  }
@@ -4689,14 +4300,8 @@ class Utils {
4689
4300
  * > "test success set"
4690
4301
  *
4691
4302
  */
4692
- waitProperty<T extends any>(
4693
- checkObj: any | (() => any),
4694
- checkPropertyName: string
4695
- ): Promise<T>;
4696
- waitProperty<T extends any>(
4697
- checkObj: any | (() => any),
4698
- checkPropertyName: string
4699
- ): Promise<T> {
4303
+ waitProperty<T extends any>(checkObj: any | (() => any), checkPropertyName: string): Promise<T>;
4304
+ waitProperty<T extends any>(checkObj: any | (() => any), checkPropertyName: string): Promise<T> {
4700
4305
  return new Promise((resolve) => {
4701
4306
  let obj = checkObj;
4702
4307
  if (typeof checkObj === "function") {
@@ -4876,10 +4481,7 @@ class Utils {
4876
4481
  getCallBack: (value: any) => void,
4877
4482
  setCallBack: (value: any) => void
4878
4483
  ): void {
4879
- if (
4880
- typeof getCallBack !== "function" &&
4881
- typeof setCallBack !== "function"
4882
- ) {
4484
+ if (typeof getCallBack !== "function" && typeof setCallBack !== "function") {
4883
4485
  return;
4884
4486
  }
4885
4487
 
@@ -4918,19 +4520,18 @@ class Utils {
4918
4520
  });
4919
4521
  }
4920
4522
  }
4921
-
4922
4523
  /**
4923
4524
  * 深度获取对象属性
4924
4525
  * @param target 待获取的对象
4925
4526
  * @param handler 获取属性的回调
4926
4527
  */
4927
- queryProperty(
4528
+ queryProperty<T extends any = any>(
4928
4529
  target: any,
4929
- handler: (target: any) => {
4530
+ handler: (target: T) => {
4930
4531
  /**
4931
4532
  * 是否是需要的属性
4932
- * + true 将目标值赋值给data
4933
- * + false 不是需要的,data为下一个处理的对象
4533
+ * + `true` 将目标值赋值给data
4534
+ * + `false` 不是需要的,data为下一个处理的对象
4934
4535
  */
4935
4536
  isFind: boolean;
4936
4537
  /**
@@ -4943,16 +4544,54 @@ class Utils {
4943
4544
  return;
4944
4545
  }
4945
4546
  let handleResult = handler(target);
4946
- if (
4947
- handleResult &&
4948
- typeof handleResult.isFind === "boolean" &&
4949
- handleResult.isFind
4950
- ) {
4547
+ if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
4951
4548
  return handleResult.data;
4952
4549
  }
4953
4550
  return this.queryProperty(handleResult.data, handler);
4954
4551
  }
4955
-
4552
+ /**
4553
+ * 异步-深度获取对象属性
4554
+ * @param target 待获取的对象
4555
+ * @param handler 获取属性的回调
4556
+ */
4557
+ async asyncQueryProperty<T extends any = any>(
4558
+ target: any,
4559
+ handler: (target: T) =>
4560
+ | {
4561
+ /**
4562
+ * 是否是需要的属性
4563
+ * + true 将目标值赋值给data
4564
+ * + false 不是需要的,data为下一个处理的对象
4565
+ */
4566
+ isFind: boolean;
4567
+ /**
4568
+ * 对象/目标值
4569
+ */
4570
+ data: any;
4571
+ }
4572
+ | Promise<{
4573
+ /**
4574
+ * 是否是需要的属性
4575
+ * + true 将目标值赋值给data
4576
+ * + false 不是需要的,data为下一个处理的对象
4577
+ */
4578
+ isFind: boolean;
4579
+ /**
4580
+ * 对象/目标值
4581
+ */
4582
+ data: any;
4583
+ }>
4584
+ ): Promise<Awaited<T>> {
4585
+ if (target == null) {
4586
+ // @ts-ignore
4587
+ return;
4588
+ }
4589
+ let handleResult = await handler(target);
4590
+ if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
4591
+ return handleResult.data;
4592
+ }
4593
+ return await this.asyncQueryProperty(handleResult.data, handler);
4594
+ }
4956
4595
  /**
4957
4596
  * 创建一个新的Utils实例
4958
4597
  * @param option
@@ -5137,8 +4776,7 @@ class Utils {
5137
4776
  function requestPermissionsWithClipboard() {
5138
4777
  navigator.permissions
5139
4778
  .query({
5140
- // @ts-ignore
5141
- name: "clipboard-read",
4779
+ name: "clipboard-read" as any as PermissionName,
5142
4780
  })
5143
4781
  .then((permissionStatus) => {
5144
4782
  readClipboardText();