@whitesev/utils 2.0.2 → 2.1.1

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/src/Utils.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ColorConversion } from "./ColorConversion";
2
2
  import { GBKEncoder } from "./GBKEncoder";
3
- import { UtilsCore } from "./UtilsCore";
4
3
  import { UtilsGMCookie } from "./UtilsGMCookie";
5
4
  import { AjaxHooker } from "./ajaxHooker/ajaxHooker.js";
6
5
  import { GMMenu } from "./UtilsGMMenu";
@@ -13,10 +12,10 @@ import { Progress } from "./Progress";
13
12
  import { TryCatch } from "./TryCatch";
14
13
  import { UtilsDictionary } from "./Dictionary";
15
14
  import type { DOMUtils_EventType } from "./Event";
16
- import type { UtilsCoreOption } from "./UtilsCore";
17
15
  import type { Vue2Object } from "./VueObject";
18
16
  import type { UtilsAjaxHookResult } from "./AjaxHookerType";
19
17
  import { GenerateUUID } from "./UtilsCommon";
18
+ import { WindowApi, type UtilsWindowApiOption } from "./WindowApi";
20
19
 
21
20
  export declare var unsafeWindow: Window & typeof globalThis;
22
21
 
@@ -48,11 +47,12 @@ export declare interface AnyObject {
48
47
  export declare interface Vue2Context extends Vue2Object {}
49
48
 
50
49
  class Utils {
51
- constructor(option?: UtilsCoreOption) {
52
- UtilsCore.init(option);
50
+ private windowApi: WindowApi;
51
+ constructor(option?: UtilsWindowApiOption) {
52
+ this.windowApi = new WindowApi(option);
53
53
  }
54
54
  /** 版本号 */
55
- version = "2024.7.20";
55
+ version = "2024.7.24";
56
56
 
57
57
  /**
58
58
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -67,23 +67,25 @@ class Utils {
67
67
  if (typeof cssText !== "string") {
68
68
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
69
69
  }
70
- let cssNode = UtilsCore.document.createElement("style");
70
+ let cssNode = this.windowApi.document.createElement("style");
71
71
  cssNode.setAttribute("type", "text/css");
72
72
  cssNode.innerHTML = cssText;
73
- if (UtilsCore.document.head) {
73
+ if (this.windowApi.document.head) {
74
74
  /* 插入head最后 */
75
- UtilsCore.document.head.appendChild(cssNode);
76
- } else if (UtilsCore.document.body) {
75
+ this.windowApi.document.head.appendChild(cssNode);
76
+ } else if (this.windowApi.document.body) {
77
77
  /* 插入body后 */
78
- UtilsCore.document.body.appendChild(cssNode);
79
- } else if (UtilsCore.document.documentElement.childNodes.length === 0) {
78
+ this.windowApi.document.body.appendChild(cssNode);
79
+ } else if (
80
+ this.windowApi.document.documentElement.childNodes.length === 0
81
+ ) {
80
82
  /* 插入#html第一个元素后 */
81
- UtilsCore.document.documentElement.appendChild(cssNode);
83
+ this.windowApi.document.documentElement.appendChild(cssNode);
82
84
  } else {
83
85
  /* 插入head前面 */
84
- UtilsCore.document.documentElement.insertBefore(
86
+ this.windowApi.document.documentElement.insertBefore(
85
87
  cssNode,
86
- UtilsCore.document.documentElement.childNodes[0]
88
+ this.windowApi.document.documentElement.childNodes[0]
87
89
  );
88
90
  }
89
91
  return cssNode;
@@ -306,7 +308,7 @@ class Utils {
306
308
  let elementPosYBottom = Number(
307
309
  (element as HTMLElement).getBoundingClientRect().bottom
308
310
  ); /* 要检测的元素的相对屏幕的纵坐标最下边 */
309
- let clickNodeHTML = (UtilsCore.window.event as any).target
311
+ let clickNodeHTML = (this.windowApi.window.event as any).target
310
312
  .innerHTML as string;
311
313
  if (
312
314
  mouseClickPosX >= elementPosXLeft &&
@@ -561,21 +563,21 @@ class Utils {
561
563
  }
562
564
  if (isIFrame) {
563
565
  /* 使用iframe */
564
- const iframeElement = UtilsCore.document.createElement("iframe");
566
+ const iframeElement = this.windowApi.document.createElement("iframe");
565
567
  iframeElement.style.display = "none";
566
568
  iframeElement.src = base64Data;
567
- UtilsCore.document.body.appendChild(iframeElement);
569
+ this.windowApi.document.body.appendChild(iframeElement);
568
570
  setTimeout(() => {
569
571
  iframeElement!.contentWindow!.document.execCommand(
570
572
  "SaveAs",
571
573
  true,
572
574
  fileName
573
575
  );
574
- UtilsCore.document.body.removeChild(iframeElement);
576
+ this.windowApi.document.body.removeChild(iframeElement);
575
577
  }, 100);
576
578
  } else {
577
579
  /* 使用A标签 */
578
- const linkElement = UtilsCore.document.createElement("a");
580
+ const linkElement = this.windowApi.document.createElement("a");
579
581
  linkElement.setAttribute("target", "_blank");
580
582
  linkElement.download = fileName;
581
583
  linkElement.href = base64Data;
@@ -601,14 +603,14 @@ class Utils {
601
603
  findWebPageVisibleText(str = "", caseSensitive = false) {
602
604
  let TRange = null;
603
605
  let strFound;
604
- if ((UtilsCore.globalThis as any).find) {
606
+ if ((this.windowApi.globalThis as any).find) {
605
607
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
606
- let windowFind = (UtilsCore.self as any).find;
608
+ let windowFind = (this.windowApi.self as any).find;
607
609
  strFound = windowFind(str, caseSensitive, true, true, false);
608
610
  if (
609
611
  strFound &&
610
- UtilsCore.self.getSelection &&
611
- !UtilsCore.self.getSelection()!.anchorNode
612
+ this.windowApi.self.getSelection &&
613
+ !this.windowApi.self.getSelection()!.anchorNode
612
614
  ) {
613
615
  strFound = windowFind(str, caseSensitive, true, true, false);
614
616
  }
@@ -625,7 +627,7 @@ class Utils {
625
627
  if (strFound) TRange.select();
626
628
  }
627
629
  if (TRange == null || strFound == 0) {
628
- TRange = (UtilsCore.self.document.body as any).createTextRange();
630
+ TRange = (this.windowApi.self.document.body as any).createTextRange();
629
631
  strFound = TRange.findText(str);
630
632
  if (strFound) TRange.select();
631
633
  }
@@ -1235,8 +1237,8 @@ class Utils {
1235
1237
  // 当前的最大z-index的元素,调试使用
1236
1238
  // @ts-ignore
1237
1239
  let maxZIndexNode = null;
1238
- UtilsCore.document.querySelectorAll("*").forEach(($ele, index) => {
1239
- let nodeStyle = UtilsCore.window.getComputedStyle($ele);
1240
+ this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
1241
+ let nodeStyle = this.windowApi.window.getComputedStyle($ele);
1240
1242
  /* 不对position为static和display为none的元素进行获取它们的z-index */
1241
1243
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
1242
1244
  let nodeZIndex = parseInt(nodeStyle.zIndex);
@@ -1559,7 +1561,7 @@ class Utils {
1559
1561
  if (url.trim() === "") {
1560
1562
  throw new TypeError("url不能为空字符串或纯空格");
1561
1563
  }
1562
- return `thunder://${UtilsCore.globalThis.btoa("AA" + url + "ZZ")}`;
1564
+ return `thunder://${this.windowApi.globalThis.btoa("AA" + url + "ZZ")}`;
1563
1565
  }
1564
1566
  /**
1565
1567
  * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
@@ -1797,12 +1799,12 @@ class Utils {
1797
1799
  isNearBottom(nearValue?: number): boolean;
1798
1800
  isNearBottom(nearValue: number = 50): boolean {
1799
1801
  var scrollTop =
1800
- UtilsCore.window.pageYOffset ||
1801
- UtilsCore.document.documentElement.scrollTop;
1802
+ this.windowApi.window.pageYOffset ||
1803
+ this.windowApi.document.documentElement.scrollTop;
1802
1804
  var windowHeight =
1803
- UtilsCore.window.innerHeight ||
1804
- UtilsCore.document.documentElement.clientHeight;
1805
- var documentHeight = UtilsCore.document.documentElement.scrollHeight;
1805
+ this.windowApi.window.innerHeight ||
1806
+ this.windowApi.document.documentElement.clientHeight;
1807
+ var documentHeight = this.windowApi.document.documentElement.scrollHeight;
1806
1808
  return scrollTop + windowHeight >= documentHeight - nearValue;
1807
1809
  }
1808
1810
  /**
@@ -1825,10 +1827,10 @@ class Utils {
1825
1827
  isFullscreenEnabled(): boolean;
1826
1828
  isFullscreenEnabled(): boolean {
1827
1829
  return !!(
1828
- (UtilsCore.document as any).fullscreenEnabled ||
1829
- (UtilsCore.document as any).webkitFullScreenEnabled ||
1830
- (UtilsCore.document as any).mozFullScreenEnabled ||
1831
- (UtilsCore.document as any).msFullScreenEnabled
1830
+ (this.windowApi.document as any).fullscreenEnabled ||
1831
+ (this.windowApi.document as any).webkitFullScreenEnabled ||
1832
+ (this.windowApi.document as any).mozFullScreenEnabled ||
1833
+ (this.windowApi.document as any).msFullScreenEnabled
1832
1834
  );
1833
1835
  }
1834
1836
  /**
@@ -2152,7 +2154,7 @@ class Utils {
2152
2154
  */
2153
2155
  isThemeDark(): boolean;
2154
2156
  isThemeDark(): boolean {
2155
- return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
2157
+ return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
2156
2158
  .matches;
2157
2159
  }
2158
2160
  /**
@@ -2182,18 +2184,18 @@ class Utils {
2182
2184
  }
2183
2185
  let result = true;
2184
2186
  for (const domItem of needCheckDomList) {
2185
- let domDisplay = UtilsCore.window.getComputedStyle(domItem);
2187
+ let domDisplay = this.windowApi.window.getComputedStyle(domItem);
2186
2188
  if (domDisplay.display === "none") {
2187
2189
  result = false;
2188
2190
  } else {
2189
2191
  let domClientRect = domItem.getBoundingClientRect();
2190
2192
  if (inView) {
2191
2193
  let viewportWidth =
2192
- UtilsCore.window.innerWidth ||
2193
- UtilsCore.document.documentElement.clientWidth;
2194
+ this.windowApi.window.innerWidth ||
2195
+ this.windowApi.document.documentElement.clientWidth;
2194
2196
  let viewportHeight =
2195
- UtilsCore.window.innerHeight ||
2196
- UtilsCore.document.documentElement.clientHeight;
2197
+ this.windowApi.window.innerHeight ||
2198
+ this.windowApi.document.documentElement.clientHeight;
2197
2199
  result = !(
2198
2200
  domClientRect.right < 0 ||
2199
2201
  domClientRect.left > viewportWidth ||
@@ -2225,10 +2227,10 @@ class Utils {
2225
2227
  isWebView_Via(): boolean {
2226
2228
  let result = true;
2227
2229
  let UtilsContext = this;
2228
- if (typeof (UtilsCore.top.window as any).via === "object") {
2229
- for (const key in Object.values((UtilsCore.top.window as any).via)) {
2230
- if (Reflect.has((UtilsCore.top.window as any).via, key)) {
2231
- let objValueFunc = (UtilsCore.top.window as any).via[key];
2230
+ if (typeof (this.windowApi.top.window as any).via === "object") {
2231
+ for (const key in Object.values((this.windowApi.top.window as any).via)) {
2232
+ if (Reflect.has((this.windowApi.top.window as any).via, key)) {
2233
+ let objValueFunc = (this.windowApi.top.window as any).via[key];
2232
2234
  if (
2233
2235
  typeof objValueFunc === "function" &&
2234
2236
  UtilsContext.isNativeFunc(objValueFunc)
@@ -2258,10 +2260,12 @@ class Utils {
2258
2260
  isWebView_X(): boolean {
2259
2261
  let result = true;
2260
2262
  let UtilsContext = this;
2261
- if (typeof (UtilsCore.top.window as any).mbrowser === "object") {
2262
- for (const key in Object.values((UtilsCore.top.window as any).mbrowser)) {
2263
- if (Reflect.has((UtilsCore.top.window as any).mbrowser, key)) {
2264
- let objValueFunc = (UtilsCore.top.window as any).mbrowser[key];
2263
+ if (typeof (this.windowApi.top.window as any).mbrowser === "object") {
2264
+ for (const key in Object.values(
2265
+ (this.windowApi.top.window as any).mbrowser
2266
+ )) {
2267
+ if (Reflect.has((this.windowApi.top.window as any).mbrowser, key)) {
2268
+ let objValueFunc = (this.windowApi.top.window as any).mbrowser[key];
2265
2269
  if (
2266
2270
  typeof objValueFunc === "function" &&
2267
2271
  UtilsContext.isNativeFunc(objValueFunc)
@@ -2598,9 +2602,9 @@ class Utils {
2598
2602
  observer_config
2599
2603
  );
2600
2604
  let windowMutationObserver =
2601
- UtilsCore.window.MutationObserver ||
2602
- (UtilsCore.window as any).webkitMutationObserver ||
2603
- (UtilsCore.window as any).MozMutationObserver;
2605
+ this.windowApi.window.MutationObserver ||
2606
+ (this.windowApi.window as any).webkitMutationObserver ||
2607
+ (this.windowApi.window as any).MozMutationObserver;
2604
2608
  // 观察者对象
2605
2609
  let mutationObserver = new windowMutationObserver(function (
2606
2610
  mutations: MutationRecord[],
@@ -2638,13 +2642,13 @@ class Utils {
2638
2642
  * let utils = Utils.noConflict();
2639
2643
  * > ...
2640
2644
  */
2641
- noConflict = function () {
2642
- if ((UtilsCore.window as any).Utils) {
2643
- Reflect.deleteProperty(UtilsCore.window as any, "Utils");
2645
+ noConflict() {
2646
+ if ((this.windowApi.window as any).Utils) {
2647
+ Reflect.deleteProperty(this.windowApi.window as any, "Utils");
2644
2648
  }
2645
- (UtilsCore.window as any).Utils = utils;
2649
+ (this.windowApi.window as any).Utils = utils;
2646
2650
  return utils;
2647
- };
2651
+ }
2648
2652
  /**
2649
2653
  * 恢复/释放该对象内的为function,让它无效/有效
2650
2654
  * @param needReleaseObject 需要操作的对象
@@ -2710,11 +2714,14 @@ class Utils {
2710
2714
  * 释放所有
2711
2715
  */
2712
2716
  function releaseAll() {
2713
- if (typeof (UtilsCore.window as any)[needReleaseKey] !== "undefined") {
2717
+ if (
2718
+ typeof (UtilsContext.windowApi.window as any)[needReleaseKey] !==
2719
+ "undefined"
2720
+ ) {
2714
2721
  /* 已存在 */
2715
2722
  return;
2716
2723
  }
2717
- (UtilsCore.window as any)[needReleaseKey] =
2724
+ (UtilsContext.windowApi.window as any)[needReleaseKey] =
2718
2725
  UtilsContext.deepClone(needReleaseObject);
2719
2726
  Object.values(needReleaseObject).forEach((value) => {
2720
2727
  if (typeof value === "function") {
@@ -2730,14 +2737,15 @@ class Utils {
2730
2737
  Object.values(needReleaseObject).forEach((value) => {
2731
2738
  if (typeof value === "function") {
2732
2739
  if (
2733
- typeof (UtilsCore.window as any)[needReleaseKey] === "undefined"
2740
+ typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2741
+ "undefined"
2734
2742
  ) {
2735
- (UtilsCore.window as any)[needReleaseKey] = {};
2743
+ (UtilsContext.windowApi.window as any)[needReleaseKey] = {};
2736
2744
  }
2737
2745
  if (item === value.name) {
2738
- (UtilsCore.window as any)[needReleaseKey][value.name] = (
2739
- needReleaseObject as any
2740
- )[value.name];
2746
+ (UtilsContext.windowApi.window as any)[needReleaseKey][
2747
+ value.name
2748
+ ] = (needReleaseObject as any)[value.name];
2741
2749
  (needReleaseObject as any)[value.name] = () => {};
2742
2750
  }
2743
2751
  }
@@ -2748,36 +2756,46 @@ class Utils {
2748
2756
  * 恢复所有
2749
2757
  */
2750
2758
  function recoveryAll() {
2751
- if (typeof (UtilsCore.window as any)[needReleaseKey] === "undefined") {
2759
+ if (
2760
+ typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2761
+ "undefined"
2762
+ ) {
2752
2763
  /* 未存在 */
2753
2764
  return;
2754
2765
  }
2755
2766
  Object.assign(
2756
2767
  needReleaseObject,
2757
- (UtilsCore.window as any)[needReleaseKey]
2768
+ (UtilsContext.windowApi.window as any)[needReleaseKey]
2769
+ );
2770
+ Reflect.deleteProperty(
2771
+ UtilsContext.windowApi.window as any,
2772
+ "needReleaseKey"
2758
2773
  );
2759
- Reflect.deleteProperty(UtilsCore.window as any, "needReleaseKey");
2760
2774
  }
2761
2775
 
2762
2776
  /**
2763
2777
  * 恢复单个
2764
2778
  */
2765
2779
  function recoveryOne() {
2766
- if (typeof (UtilsCore.window as any)[needReleaseKey] === "undefined") {
2780
+ if (
2781
+ typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
2782
+ "undefined"
2783
+ ) {
2767
2784
  /* 未存在 */
2768
2785
  return;
2769
2786
  }
2770
2787
  Array.from(functionNameList).forEach((item) => {
2771
- if ((UtilsCore.window as any)[needReleaseKey][item]) {
2772
- (needReleaseObject as any)[item] = (UtilsCore.window as any)[
2773
- needReleaseKey
2774
- ][item];
2788
+ if ((UtilsContext.windowApi.window as any)[needReleaseKey][item]) {
2789
+ (needReleaseObject as any)[item] = (
2790
+ UtilsContext.windowApi.window as any
2791
+ )[needReleaseKey][item];
2775
2792
  Reflect.deleteProperty(
2776
- (UtilsCore.window as any)[needReleaseKey],
2793
+ (UtilsContext.windowApi.window as any)[needReleaseKey],
2777
2794
  item
2778
2795
  );
2779
2796
  if (
2780
- Object.keys((UtilsCore.window as any)[needReleaseKey]).length === 0
2797
+ Object.keys((UtilsContext.windowApi.window as any)[needReleaseKey])
2798
+ .length === 0
2781
2799
  ) {
2782
2800
  Reflect.deleteProperty(window, needReleaseKey);
2783
2801
  }
@@ -3175,7 +3193,7 @@ class Utils {
3175
3193
  startIndex?: number,
3176
3194
  endIndex?: number
3177
3195
  ): void {
3178
- let range = UtilsCore.document.createRange();
3196
+ let range = this.windowApi.document.createRange();
3179
3197
  range.selectNodeContents(element);
3180
3198
  if (childTextNode) {
3181
3199
  if (childTextNode.nodeType !== Node.TEXT_NODE) {
@@ -3187,7 +3205,7 @@ class Utils {
3187
3205
  }
3188
3206
  }
3189
3207
 
3190
- let selection = UtilsCore.globalThis.getSelection();
3208
+ let selection = this.windowApi.globalThis.getSelection();
3191
3209
  if (selection) {
3192
3210
  selection.removeAllRanges();
3193
3211
  selection.addRange(range);
@@ -3251,6 +3269,7 @@ class Utils {
3251
3269
  } else {
3252
3270
  textType = "text/plain";
3253
3271
  }
3272
+ let UtilsContext = this;
3254
3273
  class UtilsClipboard {
3255
3274
  #resolve;
3256
3275
  #copyData;
@@ -3309,15 +3328,16 @@ class Utils {
3309
3328
  */
3310
3329
  copyTextByTextArea() {
3311
3330
  try {
3312
- let copyElement = UtilsCore.document.createElement("textarea");
3331
+ let copyElement =
3332
+ UtilsContext.windowApi.document.createElement("textarea");
3313
3333
  copyElement.value = this.#copyData;
3314
3334
  copyElement.setAttribute("type", "text");
3315
3335
  copyElement.setAttribute("style", "opacity:0;position:absolute;");
3316
3336
  copyElement.setAttribute("readonly", "readonly");
3317
- UtilsCore.document.body.appendChild(copyElement);
3337
+ UtilsContext.windowApi.document.body.appendChild(copyElement);
3318
3338
  copyElement.select();
3319
- UtilsCore.document.execCommand("copy");
3320
- UtilsCore.document.body.removeChild(copyElement);
3339
+ UtilsContext.windowApi.document.execCommand("copy");
3340
+ UtilsContext.windowApi.document.body.removeChild(copyElement);
3321
3341
  return true;
3322
3342
  } catch (error) {
3323
3343
  console.error("复制失败,error👉", error);
@@ -3392,10 +3412,10 @@ class Utils {
3392
3412
  }
3393
3413
  return new Promise((resolve) => {
3394
3414
  const utilsClipboard = new UtilsClipboard(resolve, data, textType);
3395
- if (UtilsCore.document.hasFocus()) {
3415
+ if (UtilsContext.windowApi.document.hasFocus()) {
3396
3416
  utilsClipboard.init();
3397
3417
  } else {
3398
- UtilsCore.window.addEventListener(
3418
+ UtilsContext.windowApi.window.addEventListener(
3399
3419
  "focus",
3400
3420
  () => {
3401
3421
  utilsClipboard.init();
@@ -3465,15 +3485,17 @@ class Utils {
3465
3485
  dragSlider(selector: string | Element | Node, offsetX?: number): void;
3466
3486
  dragSlider(
3467
3487
  selector: string | Element | Node,
3468
- offsetX: number = UtilsCore.window.innerWidth
3488
+ offsetX: number = this.windowApi.window.innerWidth
3469
3489
  ): void {
3490
+ let UtilsContext = this;
3470
3491
  function initMouseEvent(
3471
3492
  eventName: string,
3472
3493
  offSetX: number,
3473
3494
  offSetY: number
3474
3495
  ) {
3475
3496
  let win = unsafeWindow || window;
3476
- let mouseEvent = UtilsCore.document.createEvent("MouseEvents");
3497
+ let mouseEvent =
3498
+ UtilsContext.windowApi.document.createEvent("MouseEvents");
3477
3499
  mouseEvent.initMouseEvent(
3478
3500
  eventName,
3479
3501
  true,
@@ -3495,7 +3517,7 @@ class Utils {
3495
3517
  }
3496
3518
  let sliderElement =
3497
3519
  typeof selector === "string"
3498
- ? UtilsCore.document.querySelector(selector)
3520
+ ? this.windowApi.document.querySelector(selector)
3499
3521
  : selector;
3500
3522
  if (
3501
3523
  !(sliderElement instanceof Node) ||
@@ -3522,7 +3544,7 @@ class Utils {
3522
3544
  */
3523
3545
  enterFullScreen(element: HTMLElement, options?: FullscreenOptions): void;
3524
3546
  enterFullScreen(
3525
- element: HTMLElement = UtilsCore.document.documentElement,
3547
+ element: HTMLElement = this.windowApi.document.documentElement,
3526
3548
  options?: FullscreenOptions
3527
3549
  ): void {
3528
3550
  try {
@@ -3549,16 +3571,16 @@ class Utils {
3549
3571
  */
3550
3572
  exitFullScreen(element?: HTMLElement): Promise<void>;
3551
3573
  exitFullScreen(
3552
- element: HTMLElement = UtilsCore.document.documentElement
3574
+ element: HTMLElement = this.windowApi.document.documentElement
3553
3575
  ): Promise<void> {
3554
- if (UtilsCore.document.exitFullscreen) {
3555
- return UtilsCore.document.exitFullscreen();
3556
- } else if ((UtilsCore.document as any).msExitFullscreen) {
3557
- return (UtilsCore.document as any).msExitFullscreen();
3558
- } else if ((UtilsCore.document as any).mozCancelFullScreen) {
3559
- return (UtilsCore.document as any).mozCancelFullScreen();
3560
- } else if ((UtilsCore.document as any).webkitCancelFullScreen) {
3561
- return (UtilsCore.document as any).webkitCancelFullScreen();
3576
+ if (this.windowApi.document.exitFullscreen) {
3577
+ return this.windowApi.document.exitFullscreen();
3578
+ } else if ((this.windowApi.document as any).msExitFullscreen) {
3579
+ return (this.windowApi.document as any).msExitFullscreen();
3580
+ } else if ((this.windowApi.document as any).mozCancelFullScreen) {
3581
+ return (this.windowApi.document as any).mozCancelFullScreen();
3582
+ } else if ((this.windowApi.document as any).webkitCancelFullScreen) {
3583
+ return (this.windowApi.document as any).webkitCancelFullScreen();
3562
3584
  } else {
3563
3585
  return new Promise((resolve, reject) => {
3564
3586
  reject(new TypeError("该浏览器不支持全屏API"));
@@ -3580,16 +3602,16 @@ class Utils {
3580
3602
  * Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
3581
3603
  * > [{time: '2022-1-1'},{time: '2022-2-2'}]
3582
3604
  **/
3583
- sortListByProperty<T extends any[] | NodeList>(
3584
- data: T,
3605
+ sortListByProperty<T extends any>(
3606
+ data: T[],
3585
3607
  getPropertyValueFunc: string | ((value: T) => any),
3586
3608
  sortByDesc?: boolean
3587
- ): T;
3588
- sortListByProperty<T extends any[] | NodeList>(
3589
- data: T,
3609
+ ): T[];
3610
+ sortListByProperty<T extends any>(
3611
+ data: T[],
3590
3612
  getPropertyValueFunc: string | ((value: T) => any),
3591
3613
  sortByDesc: boolean = true
3592
- ): T {
3614
+ ): T[] {
3593
3615
  let UtilsContext = this;
3594
3616
  if (
3595
3617
  typeof getPropertyValueFunc !== "function" &&
@@ -3680,7 +3702,10 @@ class Utils {
3680
3702
  }
3681
3703
  if (Array.isArray(data)) {
3682
3704
  data.sort(sortFunc);
3683
- } else if (data instanceof NodeList || UtilsContext.isJQuery(data)) {
3705
+ } else if (
3706
+ (data as any) instanceof NodeList ||
3707
+ UtilsContext.isJQuery(data)
3708
+ ) {
3684
3709
  sortNodeFunc(data as any, getDataFunc as any);
3685
3710
  result = (getDataFunc as any)();
3686
3711
  } else {
@@ -3830,7 +3855,9 @@ class Utils {
3830
3855
  UtilsContext.tryCatch()
3831
3856
  .error(() => {
3832
3857
  try {
3833
- result = (UtilsCore.window as any).eval("(" + data + ")");
3858
+ result = (UtilsContext.windowApi.window as any).eval(
3859
+ "(" + data + ")"
3860
+ );
3834
3861
  } catch (error2: any) {
3835
3862
  if (typeof errorCallBack === "function") {
3836
3863
  errorCallBack(error2);
@@ -4077,11 +4104,11 @@ class Utils {
4077
4104
  waitNode<T extends Element | Element[]>(...args: any[]): Promise<T | null> {
4078
4105
  // 过滤掉undefined
4079
4106
  args = args.filter((arg) => arg !== void 0);
4080
- let that = this;
4107
+ let UtilsContext = this;
4081
4108
  // 选择器
4082
4109
  let selector = args[0] as unknown as string | string[];
4083
4110
  // 父元素(监听的元素)
4084
- let parent: Element = UtilsCore.document as any as Element;
4111
+ let parent: Element = UtilsContext.windowApi.document as any as Element;
4085
4112
  // 超时时间
4086
4113
  let timeout = 0;
4087
4114
  if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
@@ -4139,7 +4166,7 @@ class Utils {
4139
4166
  return parent.querySelector(selector);
4140
4167
  }
4141
4168
  }
4142
- var observer = that.mutationObserver(parent, {
4169
+ var observer = UtilsContext.mutationObserver(parent, {
4143
4170
  config: {
4144
4171
  subtree: true,
4145
4172
  childList: true,
@@ -4229,11 +4256,11 @@ class Utils {
4229
4256
  waitAnyNode<T extends Element>(...args: any[]): Promise<T | null> {
4230
4257
  // 过滤掉undefined
4231
4258
  args = args.filter((arg) => arg !== void 0);
4232
- let that = this;
4259
+ let UtilsContext = this;
4233
4260
  // 选择器
4234
4261
  let selectorList = args[0] as unknown as string[];
4235
4262
  // 父元素(监听的元素)
4236
- let parent: Element = UtilsCore.document as any as Element;
4263
+ let parent: Element = UtilsContext.windowApi.document as any as Element;
4237
4264
  // 超时时间
4238
4265
  let timeout = 0;
4239
4266
  if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
@@ -4275,7 +4302,7 @@ class Utils {
4275
4302
  throw new TypeError("Utils.waitAnyNode 参数个数错误");
4276
4303
  }
4277
4304
  let promiseList = selectorList.map((selector) => {
4278
- return that.waitNode<T>(selector, parent, timeout);
4305
+ return UtilsContext.waitNode<T>(selector, parent, timeout);
4279
4306
  });
4280
4307
  return Promise.any(promiseList);
4281
4308
  }
@@ -4399,11 +4426,11 @@ class Utils {
4399
4426
  ): Promise<T | null> {
4400
4427
  // 过滤掉undefined
4401
4428
  args = args.filter((arg) => arg !== void 0);
4402
- let that = this;
4429
+ let UtilsContext = this;
4403
4430
  // 选择器数组
4404
4431
  let selector = args[0] as unknown as string | string[];
4405
4432
  // 父元素(监听的元素)
4406
- let parent: Element = UtilsCore.document as any as Element;
4433
+ let parent: Element = UtilsContext.windowApi.document as any as Element;
4407
4434
  // 超时时间
4408
4435
  let timeout = 0;
4409
4436
  if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
@@ -4466,7 +4493,7 @@ class Utils {
4466
4493
  }
4467
4494
  }
4468
4495
  }
4469
- var observer = that.mutationObserver(parent, {
4496
+ var observer = UtilsContext.mutationObserver(parent, {
4470
4497
  config: {
4471
4498
  subtree: true,
4472
4499
  childList: true,
@@ -4558,11 +4585,11 @@ class Utils {
4558
4585
  ): Promise<NodeListOf<T> | null> {
4559
4586
  // 过滤掉undefined
4560
4587
  args = args.filter((arg) => arg !== void 0);
4561
- let that = this;
4588
+ let UtilsContext = this;
4562
4589
  // 选择器数组
4563
4590
  let selectorList = args[0] as unknown as string[];
4564
4591
  // 父元素(监听的元素)
4565
- let parent: Element = UtilsCore.document as any as Element;
4592
+ let parent: Element = UtilsContext.windowApi.document as any as Element;
4566
4593
  // 超时时间
4567
4594
  let timeout = 0;
4568
4595
  if (!Array.isArray(args[0])) {
@@ -4607,7 +4634,11 @@ class Utils {
4607
4634
  }
4608
4635
 
4609
4636
  let promiseList = selectorList.map((selector) => {
4610
- return that.waitNodeList<NodeListOf<T>>(selector, parent, timeout);
4637
+ return UtilsContext.waitNodeList<NodeListOf<T>>(
4638
+ selector,
4639
+ parent,
4640
+ timeout
4641
+ );
4611
4642
  });
4612
4643
  return Promise.any(promiseList);
4613
4644
  }
@@ -4858,7 +4889,7 @@ class Utils {
4858
4889
  * @param option
4859
4890
  * @returns
4860
4891
  */
4861
- createUtils(option?: UtilsCoreOption) {
4892
+ createUtils(option?: UtilsWindowApiOption) {
4862
4893
  return new Utils(option);
4863
4894
  }
4864
4895
 
@@ -4916,11 +4947,11 @@ class Utils {
4916
4947
  if (text.startsWith("//")) {
4917
4948
  /* //www.baidu.com/xxxxxxx */
4918
4949
  /* 没有protocol,加上 */
4919
- text = UtilsCore.globalThis.location.protocol + text;
4950
+ text = this.windowApi.globalThis.location.protocol + text;
4920
4951
  } else if (text.startsWith("/")) {
4921
4952
  /* /xxx/info?xxx=xxx */
4922
4953
  /* 没有Origin,加上 */
4923
- text = UtilsCore.globalThis.location.origin + text;
4954
+ text = this.windowApi.globalThis.location.origin + text;
4924
4955
  }
4925
4956
  return new URL(text);
4926
4957
  }
@@ -1,11 +1,9 @@
1
- import { UtilsCore } from "./UtilsCore";
2
-
3
1
  /**
4
2
  * 生成uuid
5
3
  */
6
4
  export const GenerateUUID = function () {
7
- if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
8
- return UtilsCore.globalThis.crypto.randomUUID();
5
+ if (typeof window?.crypto?.randomUUID === "function") {
6
+ return window.crypto.randomUUID();
9
7
  } else {
10
8
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
11
9
  /[xy]/g,