@whitesev/utils 2.8.1 → 2.9.0

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 (74) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +271 -777
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +2 -0
  5. package/dist/index.amd.min.js.map +1 -0
  6. package/dist/index.cjs.js +271 -777
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +2 -0
  9. package/dist/index.cjs.min.js.map +1 -0
  10. package/dist/index.esm.js +271 -777
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +2 -0
  13. package/dist/index.esm.min.js.map +1 -0
  14. package/dist/index.iife.js +271 -777
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +2 -0
  17. package/dist/index.iife.min.js.map +1 -0
  18. package/dist/index.system.js +271 -777
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +2 -0
  21. package/dist/index.system.min.js.map +1 -0
  22. package/dist/index.umd.js +271 -777
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +2 -0
  25. package/dist/index.umd.min.js.map +1 -0
  26. package/dist/types/src/Utils.d.ts +103 -450
  27. package/dist/types/src/UtilsGMCookie.d.ts +4 -0
  28. package/dist/types/src/UtilsGMMenu.d.ts +3 -6
  29. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  30. package/dist/types/src/types/Log.d.ts +19 -19
  31. package/dist/types/src/types/Progress.d.ts +20 -20
  32. package/dist/types/src/types/React.d.ts +119 -119
  33. package/dist/types/src/types/TryCatch.d.ts +9 -9
  34. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  35. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  36. package/dist/types/src/types/Vue2.d.ts +166 -166
  37. package/dist/types/src/types/WindowApi.d.ts +14 -14
  38. package/dist/types/src/types/ajaxHooker.d.ts +151 -151
  39. package/dist/types/src/types/env.d.ts +7 -7
  40. package/dist/types/src/types/global.d.ts +31 -31
  41. package/index.ts +3 -0
  42. package/package.json +16 -10
  43. package/src/ColorConversion.ts +105 -105
  44. package/src/CommonUtil.ts +280 -280
  45. package/src/DOMUtils.ts +251 -251
  46. package/src/Dictionary.ts +153 -153
  47. package/src/GBKEncoder.ts +108 -108
  48. package/src/Hooks.ts +73 -73
  49. package/src/Httpx.ts +1457 -1457
  50. package/src/LockFunction.ts +62 -62
  51. package/src/Log.ts +258 -258
  52. package/src/Progress.ts +108 -108
  53. package/src/TryCatch.ts +86 -86
  54. package/src/Utils.ts +3778 -4772
  55. package/src/UtilsCommon.ts +14 -14
  56. package/src/UtilsGMCookie.ts +272 -254
  57. package/src/UtilsGMMenu.ts +441 -445
  58. package/src/Vue.ts +233 -233
  59. package/src/WindowApi.ts +59 -59
  60. package/src/indexedDB.ts +497 -497
  61. package/src/types/Httpx.d.ts +1344 -1344
  62. package/src/types/Log.d.ts +19 -19
  63. package/src/types/Progress.d.ts +20 -20
  64. package/src/types/React.d.ts +119 -119
  65. package/src/types/TryCatch.d.ts +9 -9
  66. package/src/types/UtilsGMCookie.d.ts +93 -93
  67. package/src/types/UtilsGMMenu.d.ts +77 -77
  68. package/src/types/Vue2.d.ts +166 -166
  69. package/src/types/WindowApi.d.ts +14 -14
  70. package/src/types/ajaxHooker.d.ts +151 -151
  71. package/src/types/env.d.ts +7 -7
  72. package/src/types/global.d.ts +31 -31
  73. package/dist/types/src/types/Event.d.ts +0 -188
  74. package/src/types/Event.d.ts +0 -188
package/dist/index.amd.js CHANGED
@@ -521,18 +521,12 @@ define((function () { 'use strict';
521
521
  }
522
522
  return findValue;
523
523
  }
524
- /**
525
- * 获取多组Cookie
526
- * @param option 配置
527
- * @param callback 获取操作后的回调
528
- * + cookies object[]
529
- * + error string|undefined
530
- **/
531
524
  list(option, callback) {
532
525
  if (option == null) {
533
526
  throw new Error("Utils.GMCookie.list 参数不能为空");
534
527
  }
535
528
  const resultData = [];
529
+ let error;
536
530
  try {
537
531
  let defaultOption = {
538
532
  url: this.windowApi.window.location.href,
@@ -566,14 +560,18 @@ define((function () { 'use strict';
566
560
  });
567
561
  }
568
562
  });
569
- if (typeof callback === "function") {
570
- callback(resultData);
571
- }
572
563
  }
573
- catch (error) {
574
- if (typeof callback === "function") {
575
- callback(resultData, error);
576
- }
564
+ catch (e) {
565
+ error = e;
566
+ }
567
+ if (typeof callback === "function") {
568
+ callback(resultData, error);
569
+ }
570
+ else {
571
+ return {
572
+ cookies: resultData,
573
+ error: error,
574
+ };
577
575
  }
578
576
  }
579
577
  /**
@@ -1782,7 +1780,7 @@ define((function () { 'use strict';
1782
1780
  },
1783
1781
  /**
1784
1782
  * 注册油猴菜单
1785
- * @param menuOptions 如果存在,使用它
1783
+ * @param menuOptions (可选)菜单配置
1786
1784
  */
1787
1785
  register(menuOptions) {
1788
1786
  const that = this;
@@ -1806,7 +1804,8 @@ define((function () { 'use strict';
1806
1804
  },
1807
1805
  /**
1808
1806
  * 获取本地存储菜单键值
1809
- * @param {string} key 键
1807
+ * @param key 键
1808
+ * @param defaultValue 默认值
1810
1809
  */
1811
1810
  getLocalMenuData(key, defaultValue) {
1812
1811
  const localData = this.context.GM_Api.getValue(this.$data.key, {});
@@ -1829,7 +1828,7 @@ define((function () { 'use strict';
1829
1828
  },
1830
1829
  /**
1831
1830
  * 处理初始化配置
1832
- * @param menuOption
1831
+ * @param menuOption 菜单配置
1833
1832
  */
1834
1833
  handleInitDetail(menuOption) {
1835
1834
  menuOption.enable = Boolean(this.getLocalMenuData(menuOption.key, menuOption.enable));
@@ -1847,7 +1846,7 @@ define((function () { 'use strict';
1847
1846
  },
1848
1847
  /**
1849
1848
  * 对菜单数据进行处理
1850
- * @param menuOption
1849
+ * @param menuOption 菜单配置
1851
1850
  */
1852
1851
  handleMenuData(menuOption) {
1853
1852
  const that = this;
@@ -1935,6 +1934,9 @@ define((function () { 'use strict';
1935
1934
  return this.$data.data.find((item) => item.handleData.key === menuKey)?.handleData;
1936
1935
  },
1937
1936
  };
1937
+ /**
1938
+ * @param details 菜单配置
1939
+ */
1938
1940
  constructor(details) {
1939
1941
  this.GM_Api.getValue = details.GM_getValue;
1940
1942
  this.GM_Api.setValue = details.GM_setValue;
@@ -2022,14 +2024,6 @@ define((function () { 'use strict';
2022
2024
  delete(menuId) {
2023
2025
  this.GM_Api.unregisterMenuCommand(menuId);
2024
2026
  }
2025
- /**
2026
- * 根据键值获取enable值
2027
- * @param menuKey 菜单-键key
2028
- * @deprecated
2029
- */
2030
- get(menuKey) {
2031
- return this.getEnable(menuKey);
2032
- }
2033
2027
  /**
2034
2028
  * 根据键值获取enable值
2035
2029
  * @param menuKey 菜单-键key
@@ -2187,11 +2181,11 @@ define((function () { 'use strict';
2187
2181
  return "";
2188
2182
  }
2189
2183
  try {
2190
- new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2191
- let args = Array.prototype.slice.call(arguments, 0);
2192
- let obj = this;
2193
- hookFunc.apply(obj, args);
2194
- return _context['realFunc_${_funcName}'].apply(obj, args);
2184
+ new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2185
+ let args = Array.prototype.slice.call(arguments, 0);
2186
+ let obj = this;
2187
+ hookFunc.apply(obj, args);
2188
+ return _context['realFunc_${_funcName}'].apply(obj, args);
2195
2189
  };`)(_context, _funcName, hookFunc);
2196
2190
  _context[_funcName].prototype.isHooked = true;
2197
2191
  return true;
@@ -5480,38 +5474,15 @@ define((function () { 'use strict';
5480
5474
  }
5481
5475
  const domUtils = new DOMUtils();
5482
5476
 
5477
+ const version = "2.9.0";
5478
+
5483
5479
  class Utils {
5484
5480
  windowApi;
5485
5481
  constructor(option) {
5486
5482
  this.windowApi = new WindowApi(option);
5487
5483
  }
5488
5484
  /** 版本号 */
5489
- version = "2025.9.14";
5490
- addStyle(cssText) {
5491
- if (typeof cssText !== "string") {
5492
- throw new Error("Utils.addStyle 参数cssText 必须为String类型");
5493
- }
5494
- const cssNode = this.windowApi.document.createElement("style");
5495
- cssNode.setAttribute("type", "text/css");
5496
- cssNode.innerHTML = cssText;
5497
- if (this.windowApi.document.head) {
5498
- /* 插入head最后 */
5499
- this.windowApi.document.head.appendChild(cssNode);
5500
- }
5501
- else if (this.windowApi.document.body) {
5502
- /* 插入body后 */
5503
- this.windowApi.document.body.appendChild(cssNode);
5504
- }
5505
- else if (this.windowApi.document.documentElement.childNodes.length === 0) {
5506
- /* 插入#html第一个元素后 */
5507
- this.windowApi.document.documentElement.appendChild(cssNode);
5508
- }
5509
- else {
5510
- /* 插入head前面 */
5511
- this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
5512
- }
5513
- return cssNode;
5514
- }
5485
+ version = version;
5515
5486
  /**
5516
5487
  * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
5517
5488
  * @param target 目标数据
@@ -5529,7 +5500,7 @@ define((function () { 'use strict';
5529
5500
  */
5530
5501
  assign = commonUtil.assign.bind(commonUtil);
5531
5502
  async asyncReplaceAll(string, pattern, asyncFn) {
5532
- const UtilsContext = this;
5503
+ const that = this;
5533
5504
  if (typeof string !== "string") {
5534
5505
  throw new TypeError("string必须是字符串");
5535
5506
  }
@@ -5538,7 +5509,7 @@ define((function () { 'use strict';
5538
5509
  }
5539
5510
  let reg;
5540
5511
  if (typeof pattern === "string") {
5541
- reg = new RegExp(UtilsContext.parseStringToRegExpString(pattern), "g");
5512
+ reg = new RegExp(that.toRegExpStr(pattern), "g");
5542
5513
  }
5543
5514
  else if (pattern instanceof RegExp) {
5544
5515
  if (!pattern.global) {
@@ -5570,7 +5541,7 @@ define((function () { 'use strict';
5570
5541
  * ajax劫持库,支持xhr和fetch劫持。
5571
5542
  * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
5572
5543
  * + 作者:cxxjackie
5573
- * + 版本:1.4.7
5544
+ * + 版本:1.4.8
5574
5545
  * + 旧版本:1.2.4
5575
5546
  * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
5576
5547
  * @param useOldVersion 是否使用旧版本,默认false
@@ -5600,41 +5571,6 @@ define((function () { 'use strict';
5600
5571
  canvasElement.dispatchEvent(new MouseEvent("mousedown", eventInit));
5601
5572
  canvasElement.dispatchEvent(new MouseEvent("mouseup", eventInit));
5602
5573
  }
5603
- checkUserClickInNode(element) {
5604
- const UtilsContext = this;
5605
- if (!UtilsContext.isDOM(element)) {
5606
- throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
5607
- }
5608
- const clickEvent = UtilsContext.windowApi.window.event;
5609
- const touchEvent = UtilsContext.windowApi.window.event;
5610
- const $click = clickEvent?.composedPath()?.[0];
5611
- // 点击的x坐标
5612
- const clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
5613
- // 点击的y坐标
5614
- const clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
5615
- const {
5616
- /* 要检测的元素的相对屏幕的横坐标最左边 */
5617
- left: elementPosXLeft,
5618
- /* 要检测的元素的相对屏幕的横坐标最右边 */
5619
- right: elementPosXRight,
5620
- /* 要检测的元素的相对屏幕的纵坐标最上边 */
5621
- top: elementPosYTop,
5622
- /* 要检测的元素的相对屏幕的纵坐标最下边 */
5623
- bottom: elementPosYBottom, } = element.getBoundingClientRect();
5624
- if (clickPosX >= elementPosXLeft &&
5625
- clickPosX <= elementPosXRight &&
5626
- clickPosY >= elementPosYTop &&
5627
- clickPosY <= elementPosYBottom) {
5628
- return true;
5629
- }
5630
- else if (($click && element.contains($click)) || $click == element) {
5631
- /* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
5632
- return true;
5633
- }
5634
- else {
5635
- return false;
5636
- }
5637
- }
5638
5574
  /**
5639
5575
  * 复制formData数据
5640
5576
  * @param formData 需要clone的数据
@@ -5682,33 +5618,14 @@ define((function () { 'use strict';
5682
5618
  deepClone = commonUtil.deepClone.bind(commonUtil);
5683
5619
  debounce(fn, delay = 0) {
5684
5620
  let timer = null;
5685
- const UtilsContext = this;
5621
+ const that = this;
5686
5622
  return function (...args) {
5687
- UtilsContext.workerClearTimeout(timer);
5688
- timer = UtilsContext.workerSetTimeout(function () {
5689
- fn.apply(UtilsContext, args);
5623
+ that.workerClearTimeout(timer);
5624
+ timer = that.workerSetTimeout(function () {
5625
+ fn.apply(that, args);
5690
5626
  }, delay);
5691
5627
  };
5692
5628
  }
5693
- deleteParentNode(element, targetSelector) {
5694
- const UtilsContext = this;
5695
- if (element == null) {
5696
- return;
5697
- }
5698
- if (!UtilsContext.isDOM(element)) {
5699
- throw new Error("Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型");
5700
- }
5701
- if (typeof targetSelector !== "string") {
5702
- throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
5703
- }
5704
- let result = false;
5705
- const needRemoveDOM = domUtils.closest(element, targetSelector);
5706
- if (needRemoveDOM) {
5707
- needRemoveDOM.remove();
5708
- result = true;
5709
- }
5710
- return result;
5711
- }
5712
5629
  /**
5713
5630
  * 字典
5714
5631
  * @example
@@ -5722,25 +5639,8 @@ define((function () { 'use strict';
5722
5639
  * dictionary.concat(dictionary2);
5723
5640
  **/
5724
5641
  Dictionary = UtilsDictionary;
5725
- dispatchEvent(element, eventName, details) {
5726
- // let UtilsContext = this;
5727
- let eventNameList = [];
5728
- if (typeof eventName === "string") {
5729
- eventNameList = [eventName];
5730
- }
5731
- if (Array.isArray(eventName)) {
5732
- eventNameList = [...eventName];
5733
- }
5734
- eventNameList.forEach((_eventName_) => {
5735
- const event = new Event(_eventName_);
5736
- if (details) {
5737
- Object.assign(event, details);
5738
- }
5739
- element.dispatchEvent(event);
5740
- });
5741
- }
5742
5642
  downloadBase64(base64Data, fileName, isIFrame = false) {
5743
- const UtilsContext = this;
5643
+ const that = this;
5744
5644
  if (typeof base64Data !== "string") {
5745
5645
  throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
5746
5646
  }
@@ -5749,13 +5649,13 @@ define((function () { 'use strict';
5749
5649
  }
5750
5650
  if (isIFrame) {
5751
5651
  /* 使用iframe */
5752
- const iframeElement = this.windowApi.document.createElement("iframe");
5753
- iframeElement.style.display = "none";
5754
- iframeElement.src = base64Data;
5755
- this.windowApi.document.body.appendChild(iframeElement);
5756
- UtilsContext.workerSetTimeout(() => {
5757
- iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
5758
- this.windowApi.document.body.removeChild(iframeElement);
5652
+ const $iframe = this.windowApi.document.createElement("iframe");
5653
+ $iframe.style.display = "none";
5654
+ $iframe.src = base64Data;
5655
+ (this.windowApi.document.body || this.windowApi.document.documentElement).appendChild($iframe);
5656
+ that.workerSetTimeout(() => {
5657
+ $iframe.contentWindow.document.execCommand("SaveAs", true, fileName);
5658
+ (this.windowApi.document.body || this.windowApi.document.documentElement).removeChild($iframe);
5759
5659
  }, 100);
5760
5660
  }
5761
5661
  else {
@@ -5805,50 +5705,6 @@ define((function () { 'use strict';
5805
5705
  }
5806
5706
  return strFound ? true : false;
5807
5707
  }
5808
- *findElementsWithText(element, text, filter) {
5809
- const that = this;
5810
- if (element.outerHTML.includes(text)) {
5811
- if (element.children.length === 0) {
5812
- const filterResult = typeof filter === "function" ? filter(element) : false;
5813
- if (!filterResult) {
5814
- yield element;
5815
- }
5816
- }
5817
- else {
5818
- const textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
5819
- for (const $child of textElement) {
5820
- if ($child.textContent.includes(text)) {
5821
- const filterResult = typeof filter === "function" ? filter(element) : false;
5822
- if (!filterResult) {
5823
- yield $child;
5824
- }
5825
- }
5826
- }
5827
- }
5828
- }
5829
- for (let index = 0; index < element.children.length; index++) {
5830
- const $child = element.children[index];
5831
- yield* that.findElementsWithText($child, text, filter);
5832
- }
5833
- }
5834
- /**
5835
- * 判断该元素是否可见,如果不可见,向上找它的父元素直至找到可见的元素
5836
- * @param element
5837
- * @example
5838
- * let visibleElement = Utils.findVisibleElement(document.querySelector("a.xx"));
5839
- * > <HTMLElement>
5840
- */
5841
- findVisibleElement(element) {
5842
- let currentElement = element;
5843
- while (currentElement) {
5844
- const elementRect = currentElement.getBoundingClientRect();
5845
- if (elementRect.length) {
5846
- return currentElement;
5847
- }
5848
- currentElement = currentElement.parentElement;
5849
- }
5850
- return null;
5851
- }
5852
5708
  formatByteToSize(byteSize, addType = true) {
5853
5709
  byteSize = parseInt(byteSize.toString());
5854
5710
  if (isNaN(byteSize)) {
@@ -5897,9 +5753,9 @@ define((function () { 'use strict';
5897
5753
  }
5898
5754
  getNonNullValue(...args) {
5899
5755
  let resultValue = args[args.length - 1];
5900
- const UtilsContext = this;
5756
+ const that = this;
5901
5757
  for (const argValue of args) {
5902
- if (UtilsContext.isNotNull(argValue)) {
5758
+ if (that.isNotNull(argValue)) {
5903
5759
  resultValue = argValue;
5904
5760
  break;
5905
5761
  }
@@ -5973,20 +5829,8 @@ define((function () { 'use strict';
5973
5829
  * > 测试
5974
5830
  */
5975
5831
  GBKEncoder = GBKEncoder;
5976
- /**
5977
- * 获取 transitionend 的在各个浏览器的兼容名
5978
- */
5979
- getTransitionEndNameList() {
5980
- return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
5981
- }
5982
- /**
5983
- * 获取 animationend 的在各个浏览器的兼容名
5984
- */
5985
- getAnimationEndNameList() {
5986
- return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
5987
- }
5988
- getArrayLastValue(targetObj) {
5989
- return targetObj[targetObj.length - 1];
5832
+ getArrayLastValue(target) {
5833
+ return target[target.length - 1];
5990
5834
  }
5991
5835
  getArrayRealValue(...args) {
5992
5836
  let result = null;
@@ -6071,30 +5915,6 @@ define((function () { 'use strict';
6071
5915
  }
6072
5916
  return diffValue;
6073
5917
  }
6074
- getElementSelector(element) {
6075
- const UtilsContext = this;
6076
- if (!element)
6077
- return void 0;
6078
- if (!element.parentElement)
6079
- return void 0;
6080
- /* 如果元素有id属性,则直接返回id选择器 */
6081
- if (element.id)
6082
- return `#${element.id}`;
6083
- /* 递归地获取父元素的选择器 */
6084
- let selector = UtilsContext.getElementSelector(element.parentElement);
6085
- if (!selector) {
6086
- return element.tagName.toLowerCase();
6087
- }
6088
- /* 如果有多个相同类型的兄弟元素,则需要添加索引 */
6089
- if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
6090
- const index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
6091
- selector += ` > ${element.tagName.toLowerCase()}:nth-child(${index})`;
6092
- }
6093
- else {
6094
- selector += ` > ${element.tagName.toLowerCase()}`;
6095
- }
6096
- return selector;
6097
- }
6098
5918
  /**
6099
5919
  * 获取最大值
6100
5920
  * @example
@@ -6135,7 +5955,7 @@ define((function () { 'use strict';
6135
5955
  }
6136
5956
  getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
6137
5957
  deviation = Number.isNaN(deviation) ? 1 : deviation;
6138
- const UtilsContext = this;
5958
+ const that = this;
6139
5959
  // 最大值 2147483647
6140
5960
  // const maxZIndex = Math.pow(2, 31) - 1;
6141
5961
  // 比较值 2000000000
@@ -6164,7 +5984,7 @@ define((function () { 'use strict';
6164
5984
  }
6165
5985
  }
6166
5986
  /** 元素的样式 */
6167
- const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
5987
+ const nodeStyle = that.windowApi.window.getComputedStyle($ele);
6168
5988
  /* 不对position为static和display为none的元素进行获取它们的z-index */
6169
5989
  if (isVisibleNode(nodeStyle)) {
6170
5990
  const nodeZIndex = parseInt(nodeStyle.zIndex);
@@ -6238,7 +6058,7 @@ define((function () { 'use strict';
6238
6058
  * > 'Mozilla/5.0 (Linux; Android 10; MI 13 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.3490.40 Mobile Safari/537.36'
6239
6059
  **/
6240
6060
  getRandomAndroidUA() {
6241
- const UtilsContext = this;
6061
+ const that = this;
6242
6062
  const mobileNameList = [
6243
6063
  "LDN-LX3",
6244
6064
  "RNE-L03",
@@ -6256,14 +6076,14 @@ define((function () { 'use strict';
6256
6076
  "MI 13 Build/OPR1.170623.027; wv",
6257
6077
  ];
6258
6078
  /* 安卓版本 */
6259
- const androidVersion = UtilsContext.getRandomValue(12, 14);
6079
+ const androidVersion = that.getRandomValue(12, 14);
6260
6080
  /* 手机型号 */
6261
- const randomMobile = UtilsContext.getRandomValue(mobileNameList);
6081
+ const randomMobile = that.getRandomValue(mobileNameList);
6262
6082
  /* chrome大版本号 */
6263
- const chromeVersion1 = UtilsContext.getRandomValue(120, 132);
6264
- const chromeVersion2 = UtilsContext.getRandomValue(0, 0);
6265
- const chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
6266
- const chromeVersion4 = UtilsContext.getRandomValue(1, 218);
6083
+ const chromeVersion1 = that.getRandomValue(130, 140);
6084
+ const chromeVersion2 = that.getRandomValue(0, 0);
6085
+ const chromeVersion3 = that.getRandomValue(2272, 6099);
6086
+ const chromeVersion4 = that.getRandomValue(1, 218);
6267
6087
  return `Mozilla/5.0 (Linux; Android ${androidVersion}; ${randomMobile}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Mobile Safari/537.36`;
6268
6088
  }
6269
6089
  /**
@@ -6285,12 +6105,12 @@ define((function () { 'use strict';
6285
6105
  * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
6286
6106
  **/
6287
6107
  getRandomPCUA() {
6288
- const UtilsContext = this;
6108
+ const that = this;
6289
6109
  /* chrome大版本号 */
6290
- const chromeVersion1 = UtilsContext.getRandomValue(120, 132);
6291
- const chromeVersion2 = UtilsContext.getRandomValue(0, 0);
6292
- const chromeVersion3 = UtilsContext.getRandomValue(2272, 6099);
6293
- const chromeVersion4 = UtilsContext.getRandomValue(1, 218);
6110
+ const chromeVersion1 = that.getRandomValue(130, 140);
6111
+ const chromeVersion2 = that.getRandomValue(0, 0);
6112
+ const chromeVersion3 = that.getRandomValue(2272, 6099);
6113
+ const chromeVersion4 = that.getRandomValue(1, 218);
6294
6114
  return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion1}.${chromeVersion2}.${chromeVersion3}.${chromeVersion4} Safari/537.36`;
6295
6115
  }
6296
6116
  getRandomValue(...args) {
@@ -6324,9 +6144,9 @@ define((function () { 'use strict';
6324
6144
  * @param element 需要获取的目标元素
6325
6145
  * @returns
6326
6146
  * @example
6327
- * Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
6147
+ * Utils.getReactInstance(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
6328
6148
  */
6329
- getReactObj(element) {
6149
+ getReactInstance(element) {
6330
6150
  const result = {};
6331
6151
  if (element == null) {
6332
6152
  return result;
@@ -6336,7 +6156,9 @@ define((function () { 'use strict';
6336
6156
  if (domPropsName.startsWith("__react")) {
6337
6157
  const propsName = domPropsName.replace(/__(.+)\$.+/i, "$1");
6338
6158
  const propsValue = Reflect.get(element, domPropsName);
6339
- if (propsName in result) ;
6159
+ if (propsName in result) {
6160
+ console.error(`重复属性 ${domPropsName}`);
6161
+ }
6340
6162
  else {
6341
6163
  Reflect.set(result, propsName, propsValue);
6342
6164
  }
@@ -6391,8 +6213,8 @@ define((function () { 'use strict';
6391
6213
  return bytes.length;
6392
6214
  }
6393
6215
  getTextStorageSize(text, addType = true) {
6394
- const UtilsContext = this;
6395
- return UtilsContext.formatByteToSize(UtilsContext.getTextLength(text), addType);
6216
+ const that = this;
6217
+ return that.formatByteToSize(that.getTextLength(text), addType);
6396
6218
  }
6397
6219
  getThunderUrl(url) {
6398
6220
  if (url == null) {
@@ -6966,12 +6788,12 @@ define((function () { 'use strict';
6966
6788
  }
6967
6789
  isWebView_Via() {
6968
6790
  let result = true;
6969
- const UtilsContext = this;
6791
+ const that = this;
6970
6792
  if (typeof this.windowApi.top.window.via === "object") {
6971
6793
  for (const key in Object.values(this.windowApi.top.window.via)) {
6972
6794
  if (Reflect.has(this.windowApi.top.window.via, key)) {
6973
6795
  const objValueFunc = this.windowApi.top.window.via[key];
6974
- if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
6796
+ if (typeof objValueFunc === "function" && that.isNativeFunc(objValueFunc)) {
6975
6797
  result = true;
6976
6798
  }
6977
6799
  else {
@@ -6988,12 +6810,12 @@ define((function () { 'use strict';
6988
6810
  }
6989
6811
  isWebView_X() {
6990
6812
  let result = true;
6991
- const UtilsContext = this;
6813
+ const that = this;
6992
6814
  if (typeof this.windowApi.top.window.mbrowser === "object") {
6993
6815
  for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
6994
6816
  if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
6995
6817
  const objValueFunc = this.windowApi.top.window.mbrowser[key];
6996
- if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
6818
+ if (typeof objValueFunc === "function" && that.isNativeFunc(objValueFunc)) {
6997
6819
  result = true;
6998
6820
  }
6999
6821
  else {
@@ -7013,8 +6835,10 @@ define((function () { 'use strict';
7013
6835
  throw new Error("Utils.parseObjectToArray 参数 target 必须为 object 类型");
7014
6836
  }
7015
6837
  let result = [];
7016
- Object.keys(target).forEach(function (keyName) {
7017
- result = result.concat(target[keyName]);
6838
+ const keys = Object.keys(target);
6839
+ keys.forEach(function (keyName) {
6840
+ const value = Reflect.get(target, keyName);
6841
+ result = result.concat(value);
7018
6842
  });
7019
6843
  return result;
7020
6844
  }
@@ -7087,7 +6911,7 @@ define((function () { 'use strict';
7087
6911
  return content;
7088
6912
  }
7089
6913
  mutationObserver(target, observer_config) {
7090
- const UtilsContext = this;
6914
+ const that = this;
7091
6915
  const default_obverser_config = {
7092
6916
  /* 监听到元素有反馈,需执行的函数 */
7093
6917
  callback: () => { },
@@ -7129,7 +6953,7 @@ define((function () { 'use strict';
7129
6953
  },
7130
6954
  immediate: false,
7131
6955
  };
7132
- observer_config = UtilsContext.assign(default_obverser_config, observer_config);
6956
+ observer_config = that.assign(default_obverser_config, observer_config);
7133
6957
  const windowMutationObserver = this.windowApi.window.MutationObserver ||
7134
6958
  this.windowApi.window.webkitMutationObserver ||
7135
6959
  this.windowApi.window.MozMutationObserver;
@@ -7145,7 +6969,7 @@ define((function () { 'use strict';
7145
6969
  mutationObserver.observe(item, observer_config.config);
7146
6970
  });
7147
6971
  }
7148
- else if (UtilsContext.isJQuery(target)) {
6972
+ else if (that.isJQuery(target)) {
7149
6973
  /* 传入的参数是jQuery对象 */
7150
6974
  target.each((_, item) => {
7151
6975
  mutationObserver.observe(item, observer_config.config);
@@ -7215,7 +7039,7 @@ define((function () { 'use strict';
7215
7039
  return utils;
7216
7040
  }
7217
7041
  noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
7218
- const UtilsContext = this;
7042
+ const that = this;
7219
7043
  if (typeof needReleaseObject !== "object") {
7220
7044
  throw new Error("Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型");
7221
7045
  }
@@ -7230,11 +7054,11 @@ define((function () { 'use strict';
7230
7054
  * 释放所有
7231
7055
  */
7232
7056
  function releaseAll() {
7233
- if (typeof UtilsContext.windowApi.window[needReleaseKey] !== "undefined") {
7057
+ if (typeof that.windowApi.window[needReleaseKey] !== "undefined") {
7234
7058
  /* 已存在 */
7235
7059
  return;
7236
7060
  }
7237
- UtilsContext.windowApi.window[needReleaseKey] = UtilsContext.deepClone(needReleaseObject);
7061
+ that.windowApi.window[needReleaseKey] = that.deepClone(needReleaseObject);
7238
7062
  Object.values(needReleaseObject).forEach((value) => {
7239
7063
  if (typeof value === "function") {
7240
7064
  needReleaseObject[value.name] = () => { };
@@ -7248,11 +7072,11 @@ define((function () { 'use strict';
7248
7072
  Array.from(functionNameList).forEach((item) => {
7249
7073
  Object.values(needReleaseObject).forEach((value) => {
7250
7074
  if (typeof value === "function") {
7251
- if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
7252
- UtilsContext.windowApi.window[needReleaseKey] = {};
7075
+ if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
7076
+ that.windowApi.window[needReleaseKey] = {};
7253
7077
  }
7254
7078
  if (item === value.name) {
7255
- UtilsContext.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
7079
+ that.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
7256
7080
  needReleaseObject[value.name] = () => { };
7257
7081
  }
7258
7082
  }
@@ -7263,26 +7087,26 @@ define((function () { 'use strict';
7263
7087
  * 恢复所有
7264
7088
  */
7265
7089
  function recoveryAll() {
7266
- if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
7090
+ if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
7267
7091
  /* 未存在 */
7268
7092
  return;
7269
7093
  }
7270
- Object.assign(needReleaseObject, UtilsContext.windowApi.window[needReleaseKey]);
7271
- Reflect.deleteProperty(UtilsContext.windowApi.window, "needReleaseKey");
7094
+ Object.assign(needReleaseObject, that.windowApi.window[needReleaseKey]);
7095
+ Reflect.deleteProperty(that.windowApi.window, "needReleaseKey");
7272
7096
  }
7273
7097
  /**
7274
7098
  * 恢复单个
7275
7099
  */
7276
7100
  function recoveryOne() {
7277
- if (typeof UtilsContext.windowApi.window[needReleaseKey] === "undefined") {
7101
+ if (typeof that.windowApi.window[needReleaseKey] === "undefined") {
7278
7102
  /* 未存在 */
7279
7103
  return;
7280
7104
  }
7281
7105
  Array.from(functionNameList).forEach((item) => {
7282
- if (UtilsContext.windowApi.window[needReleaseKey][item]) {
7283
- needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
7284
- Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
7285
- if (Object.keys(UtilsContext.windowApi.window[needReleaseKey]).length === 0) {
7106
+ if (that.windowApi.window[needReleaseKey][item]) {
7107
+ needReleaseObject[item] = that.windowApi.window[needReleaseKey][item];
7108
+ Reflect.deleteProperty(that.windowApi.window[needReleaseKey], item);
7109
+ if (Object.keys(that.windowApi.window[needReleaseKey]).length === 0) {
7286
7110
  Reflect.deleteProperty(window, needReleaseKey);
7287
7111
  }
7288
7112
  }
@@ -7386,39 +7210,44 @@ define((function () { 'use strict';
7386
7210
  const parser = new DOMParser();
7387
7211
  return parser.parseFromString(text, mimeType);
7388
7212
  }
7389
- parseStringToRegExpString(text) {
7390
- if (typeof text !== "string") {
7391
- throw new TypeError("string必须是字符串");
7392
- }
7393
- const regString = text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
7394
- return regString;
7395
- }
7396
- preventEvent(element, eventNameList = [], capture) {
7397
- function stopEvent(event) {
7398
- /* 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL */
7399
- event?.preventDefault();
7400
- /* 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素 */
7401
- event?.stopPropagation();
7402
- /* 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发 */
7403
- event?.stopImmediatePropagation();
7404
- return false;
7213
+ /**
7214
+ * 字符串转正则,用于把字符串中不规范的字符进行转义
7215
+ * @param text 需要进行转换的字符串
7216
+ * @param flags (可选)正则标志,默认`gi`
7217
+ * @example
7218
+ * Utils.toRegExp("^替换$");
7219
+ * > /^替换$/gi
7220
+ */
7221
+ toRegExp(text, flags = "gi") {
7222
+ let regExp;
7223
+ flags = flags.toLowerCase();
7224
+ if (typeof text === "string") {
7225
+ const pattern = this.toRegExpStr(text);
7226
+ regExp = new RegExp(pattern, flags);
7405
7227
  }
7406
- if (arguments.length === 1) {
7407
- /* 直接阻止事件 */
7408
- // eslint-disable-next-line prefer-rest-params
7409
- return stopEvent(arguments[0]);
7228
+ else if (text instanceof RegExp) {
7229
+ regExp = text;
7410
7230
  }
7411
7231
  else {
7412
- /* 添加对应的事件来阻止触发 */
7413
- if (typeof eventNameList === "string") {
7414
- eventNameList = [eventNameList];
7415
- }
7416
- eventNameList.forEach((eventName) => {
7417
- element.addEventListener(eventName, stopEvent, {
7418
- capture: Boolean(capture),
7419
- });
7420
- });
7232
+ throw new Error("Utils.toRegExp 参数text必须是string|Regexp类型");
7233
+ }
7234
+ return regExp;
7235
+ }
7236
+ /**
7237
+ * 将字符串进行正则转义
7238
+ * 例如:^替换$
7239
+ * 转换:\^替换\$
7240
+ * @param text 需要转义的字符串
7241
+ * @example
7242
+ * Utils.toRegExpStr("^替换$");
7243
+ * > \^替换\$
7244
+ */
7245
+ toRegExpStr(text) {
7246
+ if (typeof text !== "string") {
7247
+ throw new TypeError("toRegExpStr 参数text必须是string类型");
7421
7248
  }
7249
+ const regExpStr = text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
7250
+ return regExpStr;
7422
7251
  }
7423
7252
  /**
7424
7253
  * 在canvas元素节点上绘制进度圆圈
@@ -7427,7 +7256,7 @@ define((function () { 'use strict';
7427
7256
  progress.draw();
7428
7257
  * **/
7429
7258
  Progress = Progress;
7430
- registerTrustClickEvent(isTrustValue = true, filter) {
7259
+ hookEvent_isTrusted(isTrustValue = true, filter) {
7431
7260
  function trustEvent(event) {
7432
7261
  return new Proxy(event, {
7433
7262
  get: function (target, property) {
@@ -7490,25 +7319,7 @@ define((function () { 'use strict';
7490
7319
  }
7491
7320
  return isNegative ? -reversedNum : reversedNum;
7492
7321
  }
7493
- selectElementText(element, childTextNode, startIndex, endIndex) {
7494
- const range = this.windowApi.document.createRange();
7495
- range.selectNodeContents(element);
7496
- if (childTextNode) {
7497
- if (childTextNode.nodeType !== Node.TEXT_NODE) {
7498
- throw new TypeError("childTextNode必须是#text元素");
7499
- }
7500
- if (startIndex != null && endIndex != null) {
7501
- range.setStart(childTextNode, startIndex);
7502
- range.setEnd(childTextNode, endIndex);
7503
- }
7504
- }
7505
- const selection = this.windowApi.globalThis.getSelection();
7506
- if (selection) {
7507
- selection.removeAllRanges();
7508
- selection.addRange(range);
7509
- }
7510
- }
7511
- setClip(data, info = {
7322
+ copy(data, info = {
7512
7323
  type: "text",
7513
7324
  mimetype: "text/plain",
7514
7325
  }) {
@@ -7530,7 +7341,7 @@ define((function () { 'use strict';
7530
7341
  else {
7531
7342
  textType = "text/plain";
7532
7343
  }
7533
- const UtilsContext = this;
7344
+ const that = this;
7534
7345
  class UtilsClipboard {
7535
7346
  #resolve;
7536
7347
  #copyData;
@@ -7581,15 +7392,15 @@ define((function () { 'use strict';
7581
7392
  */
7582
7393
  copyTextByTextArea() {
7583
7394
  try {
7584
- const copyElement = UtilsContext.windowApi.document.createElement("textarea");
7395
+ const copyElement = that.windowApi.document.createElement("textarea");
7585
7396
  copyElement.value = this.#copyData;
7586
7397
  copyElement.setAttribute("type", "text");
7587
7398
  copyElement.setAttribute("style", "opacity:0;position:absolute;");
7588
7399
  copyElement.setAttribute("readonly", "readonly");
7589
- UtilsContext.windowApi.document.body.appendChild(copyElement);
7400
+ that.windowApi.document.body.appendChild(copyElement);
7590
7401
  copyElement.select();
7591
- UtilsContext.windowApi.document.execCommand("copy");
7592
- UtilsContext.windowApi.document.body.removeChild(copyElement);
7402
+ that.windowApi.document.execCommand("copy");
7403
+ that.windowApi.document.body.removeChild(copyElement);
7593
7404
  return true;
7594
7405
  }
7595
7406
  catch (error) {
@@ -7659,18 +7470,88 @@ define((function () { 'use strict';
7659
7470
  }
7660
7471
  return new Promise((resolve) => {
7661
7472
  const utilsClipboard = new UtilsClipboard(resolve, data, textType);
7662
- if (UtilsContext.windowApi.document.hasFocus()) {
7473
+ if (that.windowApi.document.hasFocus()) {
7663
7474
  utilsClipboard.init();
7664
7475
  }
7665
7476
  else {
7666
- UtilsContext.windowApi.window.addEventListener("focus", () => {
7477
+ that.windowApi.window.addEventListener("focus", () => {
7667
7478
  utilsClipboard.init();
7668
7479
  }, { once: true });
7669
7480
  }
7670
7481
  });
7671
7482
  }
7483
+ /**
7484
+ * 获取剪贴板信息
7485
+ * @example
7486
+ * await Utils.getClipboardInfo();
7487
+ * > { error: null, content: "剪贴板内容" }
7488
+ */
7489
+ async getClipboardInfo() {
7490
+ return new Promise((resolve) => {
7491
+ /** 读取剪贴板 */
7492
+ function readClipboardText() {
7493
+ navigator.clipboard
7494
+ .readText()
7495
+ .then((clipboardText) => {
7496
+ resolve({
7497
+ error: null,
7498
+ content: clipboardText,
7499
+ });
7500
+ })
7501
+ .catch((error) => {
7502
+ resolve({
7503
+ error: error,
7504
+ content: "",
7505
+ });
7506
+ });
7507
+ }
7508
+ /** 申请读取剪贴板的权限 */
7509
+ function requestPermissionsWithClipboard() {
7510
+ navigator.permissions
7511
+ .query({
7512
+ name: "clipboard-read",
7513
+ })
7514
+ .then(() => {
7515
+ readClipboardText();
7516
+ })
7517
+ .catch(() => {
7518
+ /* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
7519
+ readClipboardText();
7520
+ });
7521
+ }
7522
+ /**
7523
+ * 检查当前环境是否支持读取剪贴板Api
7524
+ */
7525
+ function checkClipboardApi() {
7526
+ if (typeof navigator?.clipboard?.readText !== "function") {
7527
+ return false;
7528
+ }
7529
+ if (typeof navigator?.permissions?.query !== "function") {
7530
+ return false;
7531
+ }
7532
+ return true;
7533
+ }
7534
+ if (!checkClipboardApi()) {
7535
+ resolve({
7536
+ error: new Error("当前环境不支持读取剪贴板Api"),
7537
+ content: "",
7538
+ });
7539
+ return;
7540
+ }
7541
+ if (document.hasFocus()) {
7542
+ requestPermissionsWithClipboard();
7543
+ }
7544
+ else {
7545
+ window.addEventListener("focus", () => {
7546
+ requestPermissionsWithClipboard();
7547
+ }, {
7548
+ once: true,
7549
+ });
7550
+ }
7551
+ });
7552
+ }
7672
7553
  setTimeout(callback, delayTime = 0) {
7673
- const UtilsContext = this;
7554
+ const that = this;
7674
7555
  if (typeof callback !== "function" && typeof callback !== "string") {
7675
7556
  throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
7676
7557
  }
@@ -7678,27 +7559,27 @@ define((function () { 'use strict';
7678
7559
  throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
7679
7560
  }
7680
7561
  return new Promise((resolve) => {
7681
- UtilsContext.workerSetTimeout(() => {
7682
- resolve(UtilsContext.tryCatch().run(callback));
7562
+ that.workerSetTimeout(() => {
7563
+ resolve(that.tryCatch().run(callback));
7683
7564
  }, delayTime);
7684
7565
  });
7685
7566
  }
7686
7567
  sleep(delayTime = 0) {
7687
- const UtilsContext = this;
7568
+ const that = this;
7688
7569
  if (typeof delayTime !== "number") {
7689
7570
  throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
7690
7571
  }
7691
7572
  return new Promise((resolve) => {
7692
- UtilsContext.workerSetTimeout(() => {
7573
+ that.workerSetTimeout(() => {
7693
7574
  resolve(void 0);
7694
7575
  }, delayTime);
7695
7576
  });
7696
7577
  }
7697
7578
  dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
7698
- const UtilsContext = this;
7579
+ const that = this;
7699
7580
  function initMouseEvent(eventName, offSetX, offSetY) {
7700
7581
  const win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
7701
- const mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
7582
+ const mouseEvent = that.windowApi.document.createEvent("MouseEvents");
7702
7583
  mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
7703
7584
  return mouseEvent;
7704
7585
  }
@@ -7754,7 +7635,7 @@ define((function () { 'use strict';
7754
7635
  }
7755
7636
  }
7756
7637
  sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
7757
- const UtilsContext = this;
7638
+ const that = this;
7758
7639
  if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
7759
7640
  throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
7760
7641
  }
@@ -7766,9 +7647,8 @@ define((function () { 'use strict';
7766
7647
  };
7767
7648
  /**
7768
7649
  * 排序方法
7769
- * @param {any} after_obj
7770
- * @param {any} before_obj
7771
- * @returns
7650
+ * @param after_obj
7651
+ * @param before_obj
7772
7652
  */
7773
7653
  const sortFunc = function (after_obj, before_obj) {
7774
7654
  const beforeValue = getObjValue(before_obj); /* 前 */
@@ -7798,7 +7678,7 @@ define((function () { 'use strict';
7798
7678
  };
7799
7679
  /**
7800
7680
  * 排序元素方法
7801
- * @param nodeList 元素列表
7681
+ * @param nodeList 元素列表
7802
7682
  * @param getNodeListFunc 获取元素列表的函数
7803
7683
  */
7804
7684
  const sortNodeFunc = function (nodeList, getNodeListFunc) {
@@ -7836,7 +7716,7 @@ define((function () { 'use strict';
7836
7716
  if (Array.isArray(data)) {
7837
7717
  data.sort(sortFunc);
7838
7718
  }
7839
- else if (data instanceof NodeList || UtilsContext.isJQuery(data)) {
7719
+ else if (data instanceof NodeList || that.isJQuery(data)) {
7840
7720
  sortNodeFunc(data, getDataFunc);
7841
7721
  result = getDataFunc();
7842
7722
  }
@@ -7845,20 +7725,6 @@ define((function () { 'use strict';
7845
7725
  }
7846
7726
  return result;
7847
7727
  }
7848
- stringToRegular(targetString, flags = "ig") {
7849
- let reg;
7850
- flags = flags.toLowerCase();
7851
- if (typeof targetString === "string") {
7852
- reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
7853
- }
7854
- else if (targetString instanceof RegExp) {
7855
- reg = targetString;
7856
- }
7857
- else {
7858
- throw new Error("Utils.stringToRegular 参数targetString必须是string|Regexp类型");
7859
- }
7860
- return reg;
7861
- }
7862
7728
  stringTitleToUpperCase(targetString, otherStrToLowerCase = false) {
7863
7729
  let newTargetString = targetString.slice(0, 1).toUpperCase();
7864
7730
  if (otherStrToLowerCase) {
@@ -7870,7 +7736,7 @@ define((function () { 'use strict';
7870
7736
  return newTargetString;
7871
7737
  }
7872
7738
  startsWith(target, searchString, position = 0) {
7873
- const UtilsContext = this;
7739
+ const that = this;
7874
7740
  if (position > target.length) {
7875
7741
  /* 超出目标字符串的长度 */
7876
7742
  return false;
@@ -7885,7 +7751,7 @@ define((function () { 'use strict';
7885
7751
  else if (Array.isArray(searchString)) {
7886
7752
  let flag = false;
7887
7753
  for (const searcStr of searchString) {
7888
- if (!UtilsContext.startsWith(target, searcStr, position)) {
7754
+ if (!that.startsWith(target, searcStr, position)) {
7889
7755
  flag = true;
7890
7756
  break;
7891
7757
  }
@@ -7894,13 +7760,18 @@ define((function () { 'use strict';
7894
7760
  }
7895
7761
  return Boolean(target.match(searchStringRegexp));
7896
7762
  }
7897
- stringTitleToLowerCase(targetString, otherStrToUpperCase = false) {
7898
- let newTargetString = targetString.slice(0, 1).toLowerCase();
7899
- if (otherStrToUpperCase) {
7900
- newTargetString = newTargetString + targetString.slice(1).toUpperCase();
7763
+ /**
7764
+ * 字符串首字母转小写
7765
+ * @param text 目标字符串
7766
+ * @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
7767
+ */
7768
+ firstLetterToLowercase(text, otherToUpperCase = false) {
7769
+ let newTargetString = text.slice(0, 1).toLowerCase();
7770
+ if (otherToUpperCase) {
7771
+ newTargetString = newTargetString + text.slice(1).toUpperCase();
7901
7772
  }
7902
7773
  else {
7903
- newTargetString = newTargetString + targetString.slice(1);
7774
+ newTargetString = newTargetString + text.slice(1);
7904
7775
  }
7905
7776
  return newTargetString;
7906
7777
  }
@@ -7914,15 +7785,15 @@ define((function () { 'use strict';
7914
7785
  */
7915
7786
  toJSON = commonUtil.toJSON.bind(commonUtil);
7916
7787
  toSearchParamsStr(obj, addPrefix) {
7917
- const UtilsContext = this;
7788
+ const that = this;
7918
7789
  let searhParamsStr = "";
7919
7790
  if (Array.isArray(obj)) {
7920
7791
  obj.forEach((item) => {
7921
7792
  if (searhParamsStr === "") {
7922
- searhParamsStr += UtilsContext.toSearchParamsStr(item);
7793
+ searhParamsStr += that.toSearchParamsStr(item);
7923
7794
  }
7924
7795
  else {
7925
- searhParamsStr += `&${UtilsContext.toSearchParamsStr(item)}`;
7796
+ searhParamsStr += `&${that.toSearchParamsStr(item)}`;
7926
7797
  }
7927
7798
  });
7928
7799
  }
@@ -7977,341 +7848,33 @@ define((function () { 'use strict';
7977
7848
  }));
7978
7849
  }
7979
7850
  }
7851
+ /**
7852
+ * 等待函数数组全部执行完毕,注意,每个函数的顺序不是同步
7853
+ * @param data 需要遍历的数组
7854
+ * @param handleFunc 对该数组进行操作的函数,该函数的参数为数组格式的参数,[数组下标,数组项]
7855
+ * @example
7856
+ * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
7857
+ **/
7980
7858
  waitArrayLoopToEnd(data, handleFunc) {
7981
- const UtilsContext = this;
7859
+ const that = this;
7982
7860
  if (typeof handleFunc !== "function" && typeof handleFunc !== "string") {
7983
7861
  throw new Error("Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型");
7984
7862
  }
7985
7863
  return Promise.all(Array.from(data).map(async (item, index) => {
7986
- await UtilsContext.tryCatch(index, item).run(handleFunc);
7864
+ await that.tryCatch(index, item).run(handleFunc);
7987
7865
  }));
7988
7866
  }
7989
- wait(checkFn, timeout, parent) {
7990
- const UtilsContext = this;
7991
- const __timeout__ = typeof timeout === "number" ? timeout : 0;
7867
+ waitProperty(target, propertyName) {
7992
7868
  return new Promise((resolve) => {
7993
- const observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
7994
- config: {
7995
- subtree: true,
7996
- childList: true,
7997
- attributes: true,
7998
- },
7999
- immediate: true,
8000
- callback(_, __observer__) {
8001
- const result = checkFn();
8002
- if (result.success) {
8003
- // 取消观察器
8004
- if (typeof __observer__?.disconnect === "function") {
8005
- __observer__.disconnect();
8006
- }
8007
- resolve(result.data);
8008
- }
8009
- },
8010
- });
8011
- if (__timeout__ > 0) {
8012
- UtilsContext.workerSetTimeout(() => {
8013
- // 取消观察器
8014
- if (typeof observer?.disconnect === "function") {
8015
- observer.disconnect();
8016
- }
8017
- resolve(null);
8018
- }, __timeout__);
8019
- }
8020
- });
8021
- }
8022
- waitNode(...args) {
8023
- // 过滤掉undefined
8024
- args = args.filter((arg) => arg !== void 0);
8025
- const UtilsContext = this;
8026
- // 选择器
8027
- const selector = args[0];
8028
- // 父元素(监听的元素)
8029
- let parent = UtilsContext.windowApi.document;
8030
- // 超时时间
8031
- let timeout = 0;
8032
- if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
8033
- throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
8034
- }
8035
- if (args.length === 1) ;
8036
- else if (args.length === 2) {
8037
- const secondParam = args[1];
8038
- if (typeof secondParam === "number") {
8039
- // "div",10000
8040
- timeout = secondParam;
8041
- }
8042
- else if (typeof secondParam === "object" && secondParam instanceof Node) {
8043
- // "div",document
8044
- parent = secondParam;
8045
- }
8046
- else {
8047
- throw new TypeError("Utils.waitNode 第二个参数必须是number|Node");
8048
- }
8049
- }
8050
- else if (args.length === 3) {
8051
- // "div",document,10000
8052
- // 第二个参数,parent
8053
- const secondParam = args[1];
8054
- // 第三个参数,timeout
8055
- const thirdParam = args[2];
8056
- if (typeof secondParam === "object" && secondParam instanceof Node) {
8057
- parent = secondParam;
8058
- if (typeof thirdParam === "number") {
8059
- timeout = thirdParam;
8060
- }
8061
- else {
8062
- throw new TypeError("Utils.waitNode 第三个参数必须是number");
8063
- }
8064
- }
8065
- else {
8066
- throw new TypeError("Utils.waitNode 第二个参数必须是Node");
8067
- }
8068
- }
8069
- else {
8070
- throw new TypeError("Utils.waitNode 参数个数错误");
8071
- }
8072
- function getNode() {
8073
- if (Array.isArray(selector)) {
8074
- const result = [];
8075
- for (let index = 0; index < selector.length; index++) {
8076
- const node = domUtils.selector(selector[index]);
8077
- if (node) {
8078
- result.push(node);
8079
- }
8080
- }
8081
- if (result.length === selector.length) {
8082
- return result;
8083
- }
8084
- }
8085
- else if (typeof selector === "function") {
8086
- return selector();
8087
- }
8088
- else {
8089
- return domUtils.selector(selector, parent);
8090
- }
8091
- }
8092
- return UtilsContext.wait(() => {
8093
- const node = getNode();
8094
- if (node) {
8095
- return {
8096
- success: true,
8097
- data: node,
8098
- };
8099
- }
8100
- else {
8101
- return {
8102
- success: false,
8103
- data: node,
8104
- };
8105
- }
8106
- }, timeout, parent);
8107
- }
8108
- waitAnyNode(...args) {
8109
- // 过滤掉undefined
8110
- args = args.filter((arg) => arg !== void 0);
8111
- const UtilsContext = this;
8112
- // 选择器
8113
- const selectorList = args[0];
8114
- // 父元素(监听的元素)
8115
- let parent = UtilsContext.windowApi.document;
8116
- // 超时时间
8117
- let timeout = 0;
8118
- if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
8119
- throw new TypeError("Utils.waitAnyNode 第一个参数必须是string[]");
8120
- }
8121
- if (args.length === 1) ;
8122
- else if (args.length === 2) {
8123
- const secondParam = args[1];
8124
- if (typeof secondParam === "number") {
8125
- // "div",10000
8126
- timeout = secondParam;
8127
- }
8128
- else if (typeof secondParam === "object" && secondParam instanceof Node) {
8129
- // "div",document
8130
- parent = secondParam;
8131
- }
8132
- else {
8133
- throw new TypeError("Utils.waitAnyNode 第二个参数必须是number|Node");
8134
- }
8135
- }
8136
- else if (args.length === 3) {
8137
- // "div",document,10000
8138
- // 第二个参数,parent
8139
- const secondParam = args[1];
8140
- // 第三个参数,timeout
8141
- const thirdParam = args[2];
8142
- if (typeof secondParam === "object" && secondParam instanceof Node) {
8143
- parent = secondParam;
8144
- if (typeof thirdParam === "number") {
8145
- timeout = thirdParam;
8146
- }
8147
- else {
8148
- throw new TypeError("Utils.waitAnyNode 第三个参数必须是number");
8149
- }
8150
- }
8151
- else {
8152
- throw new TypeError("Utils.waitAnyNode 第二个参数必须是Node");
8153
- }
8154
- }
8155
- else {
8156
- throw new TypeError("Utils.waitAnyNode 参数个数错误");
8157
- }
8158
- const promiseList = selectorList.map((selector) => {
8159
- return UtilsContext.waitNode(selector, parent, timeout);
8160
- });
8161
- return Promise.any(promiseList);
8162
- }
8163
- waitNodeList(...args) {
8164
- // 过滤掉undefined
8165
- args = args.filter((arg) => arg !== void 0);
8166
- const UtilsContext = this;
8167
- // 选择器数组
8168
- const selector = args[0];
8169
- // 父元素(监听的元素)
8170
- let parent = UtilsContext.windowApi.document;
8171
- // 超时时间
8172
- let timeout = 0;
8173
- if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
8174
- throw new TypeError("Utils.waitNodeList 第一个参数必须是string|string[]");
8175
- }
8176
- if (args.length === 1) ;
8177
- else if (args.length === 2) {
8178
- const secondParam = args[1];
8179
- if (typeof secondParam === "number") {
8180
- // "div",10000
8181
- timeout = secondParam;
8182
- }
8183
- else if (typeof secondParam === "object" && secondParam instanceof Node) {
8184
- // "div",document
8185
- parent = secondParam;
7869
+ let obj = target;
7870
+ if (typeof target === "function") {
7871
+ obj = target();
8186
7872
  }
8187
- else {
8188
- throw new TypeError("Utils.waitNodeList 第二个参数必须是number|Node");
8189
- }
8190
- }
8191
- else if (args.length === 3) {
8192
- // "div",document,10000
8193
- // 第二个参数,parent
8194
- const secondParam = args[1];
8195
- // 第三个参数,timeout
8196
- const thirdParam = args[2];
8197
- if (typeof secondParam === "object" && secondParam instanceof Node) {
8198
- parent = secondParam;
8199
- if (typeof thirdParam === "number") {
8200
- timeout = thirdParam;
8201
- }
8202
- else {
8203
- throw new TypeError("Utils.waitNodeList 第三个参数必须是number");
8204
- }
7873
+ if (Reflect.has(obj, propertyName)) {
7874
+ resolve(obj[propertyName]);
8205
7875
  }
8206
7876
  else {
8207
- throw new TypeError("Utils.waitNodeList 第二个参数必须是Node");
8208
- }
8209
- }
8210
- else {
8211
- throw new TypeError("Utils.waitNodeList 参数个数错误");
8212
- }
8213
- function getNodeList() {
8214
- if (Array.isArray(selector)) {
8215
- const result = [];
8216
- for (let index = 0; index < selector.length; index++) {
8217
- const nodeList = domUtils.selectorAll(selector[index], parent);
8218
- if (nodeList.length) {
8219
- result.push(nodeList);
8220
- }
8221
- }
8222
- if (result.length === selector.length) {
8223
- return result;
8224
- }
8225
- }
8226
- else {
8227
- const nodeList = domUtils.selectorAll(selector, parent);
8228
- if (nodeList.length) {
8229
- return nodeList;
8230
- }
8231
- }
8232
- }
8233
- return UtilsContext.wait(() => {
8234
- const node = getNodeList();
8235
- if (node) {
8236
- return {
8237
- success: true,
8238
- data: node,
8239
- };
8240
- }
8241
- else {
8242
- return {
8243
- success: false,
8244
- data: node,
8245
- };
8246
- }
8247
- }, timeout, parent);
8248
- }
8249
- waitAnyNodeList(...args) {
8250
- // 过滤掉undefined
8251
- args = args.filter((arg) => arg !== void 0);
8252
- const UtilsContext = this;
8253
- // 选择器数组
8254
- const selectorList = args[0];
8255
- // 父元素(监听的元素)
8256
- let parent = UtilsContext.windowApi.document;
8257
- // 超时时间
8258
- let timeout = 0;
8259
- if (!Array.isArray(args[0])) {
8260
- throw new TypeError("Utils.waitAnyNodeList 第一个参数必须是string[]");
8261
- }
8262
- if (args.length === 1) ;
8263
- else if (args.length === 2) {
8264
- const secondParam = args[1];
8265
- if (typeof secondParam === "number") {
8266
- // "div",10000
8267
- timeout = secondParam;
8268
- }
8269
- else if (typeof secondParam === "object" && secondParam instanceof Node) {
8270
- // "div",document
8271
- parent = secondParam;
8272
- }
8273
- else {
8274
- throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
8275
- }
8276
- }
8277
- else if (args.length === 3) {
8278
- // "div",document,10000
8279
- // 第二个参数,parent
8280
- const secondParam = args[1];
8281
- // 第三个参数,timeout
8282
- const thirdParam = args[2];
8283
- if (typeof secondParam === "object" && secondParam instanceof Node) {
8284
- parent = secondParam;
8285
- if (typeof thirdParam === "number") {
8286
- timeout = thirdParam;
8287
- }
8288
- else {
8289
- throw new TypeError("Utils.waitAnyNodeList 第三个参数必须是number");
8290
- }
8291
- }
8292
- else {
8293
- throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是Node");
8294
- }
8295
- }
8296
- else {
8297
- throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
8298
- }
8299
- const promiseList = selectorList.map((selector) => {
8300
- return UtilsContext.waitNodeList(selector, parent, timeout);
8301
- });
8302
- return Promise.any(promiseList);
8303
- }
8304
- waitProperty(checkObj, checkPropertyName) {
8305
- return new Promise((resolve) => {
8306
- let obj = checkObj;
8307
- if (typeof checkObj === "function") {
8308
- obj = checkObj();
8309
- }
8310
- if (Reflect.has(obj, checkPropertyName)) {
8311
- resolve(obj[checkPropertyName]);
8312
- }
8313
- else {
8314
- Object.defineProperty(obj, checkPropertyName, {
7877
+ Object.defineProperty(obj, propertyName, {
8315
7878
  set: function (value) {
8316
7879
  try {
8317
7880
  resolve(value);
@@ -8324,49 +7887,48 @@ define((function () { 'use strict';
8324
7887
  }
8325
7888
  });
8326
7889
  }
8327
- waitPropertyByInterval(checkObj, checkPropertyName, intervalTimer = 250, maxTime = -1) {
8328
- const UtilsContext = this;
8329
- if (checkObj == null) {
7890
+ waitPropertyByInterval(checkFn, propertyName, intervalTimer = 250, maxTime = -1) {
7891
+ const that = this;
7892
+ if (checkFn == null) {
8330
7893
  throw new TypeError("checkObj 不能为空对象 ");
8331
7894
  }
8332
7895
  let isResolve = false;
8333
7896
  return new Promise((resolve, reject) => {
8334
- const interval = UtilsContext.workerSetInterval(() => {
8335
- let obj = checkObj;
8336
- if (typeof checkObj === "function") {
8337
- obj = checkObj();
7897
+ const interval = that.workerSetInterval(() => {
7898
+ let inst = checkFn;
7899
+ if (typeof checkFn === "function") {
7900
+ inst = checkFn();
8338
7901
  }
8339
- if (typeof obj !== "object") {
7902
+ if (typeof inst !== "object") {
8340
7903
  return;
8341
7904
  }
8342
- if (obj == null) {
7905
+ if (inst == null) {
8343
7906
  return;
8344
7907
  }
8345
- if ((typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
8346
- Reflect.has(obj, checkPropertyName)) {
7908
+ if ((typeof propertyName === "function" && propertyName(inst)) || Reflect.has(inst, propertyName)) {
8347
7909
  isResolve = true;
8348
- UtilsContext.workerClearInterval(interval);
8349
- resolve(obj[checkPropertyName]);
7910
+ that.workerClearInterval(interval);
7911
+ resolve(inst[propertyName]);
8350
7912
  }
8351
7913
  }, intervalTimer);
8352
7914
  if (maxTime !== -1) {
8353
- UtilsContext.workerSetTimeout(() => {
7915
+ that.workerSetTimeout(() => {
8354
7916
  if (!isResolve) {
8355
- UtilsContext.workerClearInterval(interval);
7917
+ that.workerClearInterval(interval);
8356
7918
  reject();
8357
7919
  }
8358
7920
  }, maxTime);
8359
7921
  }
8360
7922
  });
8361
7923
  }
8362
- async waitVueByInterval(element, propertyName, timer = 250, maxTime = -1, vueName = "__vue__") {
8363
- if (element == null) {
7924
+ async waitVueByInterval($el, propertyName, timer = 250, maxTime = -1, vueName = "__vue__") {
7925
+ if ($el == null) {
8364
7926
  throw new Error("Utils.waitVueByInterval 参数element 不能为空");
8365
7927
  }
8366
7928
  let flag = false;
8367
- const UtilsContext = this;
7929
+ const that = this;
8368
7930
  try {
8369
- await UtilsContext.waitPropertyByInterval(element, function (targetElement) {
7931
+ await that.waitPropertyByInterval($el, function (targetElement) {
8370
7932
  if (targetElement == null) {
8371
7933
  return false;
8372
7934
  }
@@ -8376,25 +7938,24 @@ define((function () { 'use strict';
8376
7938
  if (propertyName == null) {
8377
7939
  return true;
8378
7940
  }
8379
- const vueObject = targetElement[vueName];
7941
+ const $vueEl = targetElement[vueName];
8380
7942
  if (typeof propertyName === "string") {
8381
- if (propertyName in vueObject) {
7943
+ if (propertyName in $vueEl) {
8382
7944
  flag = true;
8383
7945
  return true;
8384
7946
  }
8385
7947
  }
8386
7948
  else {
8387
7949
  /* Function */
8388
- if (propertyName(vueObject)) {
7950
+ if (propertyName($vueEl)) {
8389
7951
  flag = true;
8390
7952
  return true;
8391
7953
  }
8392
7954
  }
8393
7955
  return false;
8394
7956
  }, timer, maxTime);
8395
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
8396
7957
  }
8397
- catch (error) {
7958
+ catch {
8398
7959
  return flag;
8399
7960
  }
8400
7961
  return flag;
@@ -8631,73 +8192,6 @@ define((function () { 'use strict';
8631
8192
  this.windowApi.clearInterval(timeId);
8632
8193
  }
8633
8194
  }
8634
- /**
8635
- * 获取剪贴板信息
8636
- */
8637
- async getClipboardInfo() {
8638
- return new Promise((resolve) => {
8639
- /** 读取剪贴板 */
8640
- function readClipboardText() {
8641
- navigator.clipboard
8642
- .readText()
8643
- .then((clipboardText) => {
8644
- resolve({
8645
- error: null,
8646
- content: clipboardText,
8647
- });
8648
- })
8649
- .catch((error) => {
8650
- resolve({
8651
- error: error,
8652
- content: "",
8653
- });
8654
- });
8655
- }
8656
- /** 申请读取剪贴板的权限 */
8657
- function requestPermissionsWithClipboard() {
8658
- navigator.permissions
8659
- .query({
8660
- name: "clipboard-read",
8661
- })
8662
- .then(() => {
8663
- readClipboardText();
8664
- })
8665
- .catch(() => {
8666
- /* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
8667
- readClipboardText();
8668
- });
8669
- }
8670
- /**
8671
- * 检查当前环境是否支持读取剪贴板Api
8672
- */
8673
- function checkClipboardApi() {
8674
- if (typeof navigator?.clipboard?.readText !== "function") {
8675
- return false;
8676
- }
8677
- if (typeof navigator?.permissions?.query !== "function") {
8678
- return false;
8679
- }
8680
- return true;
8681
- }
8682
- if (!checkClipboardApi()) {
8683
- resolve({
8684
- error: new Error("当前环境不支持读取剪贴板Api"),
8685
- content: "",
8686
- });
8687
- return;
8688
- }
8689
- if (document.hasFocus()) {
8690
- requestPermissionsWithClipboard();
8691
- }
8692
- else {
8693
- window.addEventListener("focus", () => {
8694
- requestPermissionsWithClipboard();
8695
- }, {
8696
- once: true,
8697
- });
8698
- }
8699
- });
8700
- }
8701
8195
  }
8702
8196
  const utils = new Utils();
8703
8197