@whitesev/utils 1.9.6 → 1.9.8

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.
@@ -208,6 +208,7 @@ var Utils = (function () {
208
208
  decode(str) {
209
209
  var GBKMatcher = /%[0-9A-F]{2}%[0-9A-F]{2}/;
210
210
  var UTFMatcher = /%[0-9A-F]{2}/;
211
+ // @ts-ignore
211
212
  var utf = true;
212
213
  let that = this;
213
214
  while (utf) {
@@ -1168,6 +1169,7 @@ var Utils = (function () {
1168
1169
  let defaultEnable = Boolean(this.getLocalMenuData(menuLocalDataItemKey, menuOption.enable));
1169
1170
  /** 油猴菜单上显示的文本 */
1170
1171
  let showText = menuOption.showText(menuOption.text, defaultEnable);
1172
+ // @ts-ignore
1171
1173
  ({
1172
1174
  /**
1173
1175
  * 菜单的id
@@ -2540,6 +2542,7 @@ var Utils = (function () {
2540
2542
  #storeName;
2541
2543
  #dbVersion;
2542
2544
  /* websql的版本号,由于ios的问题,版本号的写法不一样 */
2545
+ // @ts-ignore
2543
2546
  #slqVersion = "1";
2544
2547
  /* 监听IndexDB */
2545
2548
  #indexedDB = UtilsCore.window.indexedDB ||
@@ -2548,6 +2551,7 @@ var Utils = (function () {
2548
2551
  UtilsCore.window.msIndexedDB;
2549
2552
  /* 缓存数据库,避免同一个页面重复创建和销毁 */
2550
2553
  #db = {};
2554
+ // @ts-ignore
2551
2555
  #store = null;
2552
2556
  #errorCode = {
2553
2557
  /* 错误码 */
@@ -2662,6 +2666,7 @@ var Utils = (function () {
2662
2666
  let request = idbStore.put(inData);
2663
2667
  request.onsuccess = function (event) {
2664
2668
  /* 保存成功有success 字段 */
2669
+ // @ts-ignore
2665
2670
  event.target;
2666
2671
  resolve({
2667
2672
  success: true,
@@ -2671,6 +2676,7 @@ var Utils = (function () {
2671
2676
  });
2672
2677
  };
2673
2678
  request.onerror = function (event) {
2679
+ // @ts-ignore
2674
2680
  event.target;
2675
2681
  resolve({
2676
2682
  success: false,
@@ -2732,6 +2738,7 @@ var Utils = (function () {
2732
2738
  }
2733
2739
  };
2734
2740
  request.onerror = function (event) {
2741
+ // @ts-ignore
2735
2742
  event.target;
2736
2743
  resolve({
2737
2744
  success: false,
@@ -2789,6 +2796,7 @@ var Utils = (function () {
2789
2796
  });
2790
2797
  };
2791
2798
  request.onerror = function (event) {
2799
+ // @ts-ignore
2792
2800
  event.target;
2793
2801
  resolve({
2794
2802
  success: false,
@@ -2843,6 +2851,7 @@ var Utils = (function () {
2843
2851
  }
2844
2852
  };
2845
2853
  request.onerror = function (event) {
2854
+ // @ts-ignore
2846
2855
  event.target;
2847
2856
  resolve({
2848
2857
  success: false,
@@ -3818,7 +3827,9 @@ var Utils = (function () {
3818
3827
  /* CODE FOR BROWSERS THAT SUPPORT window.find */
3819
3828
  let windowFind = UtilsCore.self.find;
3820
3829
  strFound = windowFind(str, caseSensitive, true, true, false);
3821
- if (strFound && UtilsCore.self.getSelection && !UtilsCore.self.getSelection().anchorNode) {
3830
+ if (strFound &&
3831
+ UtilsCore.self.getSelection &&
3832
+ !UtilsCore.self.getSelection().anchorNode) {
3822
3833
  strFound = windowFind(str, caseSensitive, true, true, false);
3823
3834
  }
3824
3835
  if (!strFound) {
@@ -4890,7 +4901,8 @@ var Utils = (function () {
4890
4901
  return result;
4891
4902
  }
4892
4903
  isThemeDark() {
4893
- return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
4904
+ return UtilsCore.globalThis.matchMedia("(prefers-color-scheme: dark)")
4905
+ .matches;
4894
4906
  }
4895
4907
  isVisible(element, inView = false) {
4896
4908
  let needCheckDomList = [];
@@ -5089,11 +5101,6 @@ var Utils = (function () {
5089
5101
  }
5090
5102
  mutationObserver(target, observer_config) {
5091
5103
  let UtilsContext = this;
5092
- if (!(target instanceof Node) &&
5093
- !(target instanceof NodeList) &&
5094
- !UtilsContext.isJQuery(target)) {
5095
- throw new Error("Utils.mutationObserver 参数 target 必须为 Node|NodeList|jQuery类型");
5096
- }
5097
5104
  let default_obverser_config = {
5098
5105
  /* 监听到元素有反馈,需执行的函数 */
5099
5106
  callback: () => { },
@@ -5139,15 +5146,14 @@ var Utils = (function () {
5139
5146
  let windowMutationObserver = UtilsCore.window.MutationObserver ||
5140
5147
  UtilsCore.window.webkitMutationObserver ||
5141
5148
  UtilsCore.window.MozMutationObserver;
5149
+ // 观察者对象
5142
5150
  let mutationObserver = new windowMutationObserver(function (mutations, observer) {
5143
- observer_config?.callback(mutations, observer);
5151
+ if (typeof observer_config.callback === "function") {
5152
+ observer_config.callback(mutations, observer);
5153
+ }
5144
5154
  });
5145
- if (target instanceof Node) {
5146
- /* 传入的参数是节点元素 */
5147
- mutationObserver.observe(target, observer_config.config);
5148
- }
5149
- else if (target instanceof NodeList) {
5150
- /* 传入的参数是节点元素数组 */
5155
+ if (Array.isArray(target) || target instanceof NodeList) {
5156
+ // 传入的是数组或者元素数组
5151
5157
  target.forEach((item) => {
5152
5158
  mutationObserver.observe(item, observer_config.config);
5153
5159
  });
@@ -5159,12 +5165,13 @@ var Utils = (function () {
5159
5165
  });
5160
5166
  }
5161
5167
  else {
5162
- /* 未知 */
5163
- console.error("Utils.mutationObserver 未知参数", arguments);
5168
+ mutationObserver.observe(target, observer_config.config);
5164
5169
  }
5165
5170
  if (observer_config.immediate) {
5166
5171
  /* 主动触发一次 */
5167
- observer_config.callback([], mutationObserver);
5172
+ if (typeof observer_config.callback === "function") {
5173
+ observer_config.callback([], mutationObserver);
5174
+ }
5168
5175
  }
5169
5176
  return mutationObserver;
5170
5177
  }
@@ -5412,6 +5419,7 @@ var Utils = (function () {
5412
5419
  EventTarget.prototype.addEventListener = function (...args) {
5413
5420
  let type = args[0];
5414
5421
  let callback = args[1];
5422
+ // @ts-ignore
5415
5423
  args[2];
5416
5424
  if (filter(type)) {
5417
5425
  if (typeof callback === "function") {
@@ -5505,6 +5513,7 @@ var Utils = (function () {
5505
5513
  }
5506
5514
  async init() {
5507
5515
  let copyStatus = false;
5516
+ // @ts-ignore
5508
5517
  await this.requestClipboardPermission();
5509
5518
  if (this.hasClipboard() &&
5510
5519
  (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
@@ -6038,12 +6047,7 @@ var Utils = (function () {
6038
6047
  return parent.querySelector(selector);
6039
6048
  }
6040
6049
  }
6041
- let node = getNode();
6042
- if (node) {
6043
- resolve(node);
6044
- return;
6045
- }
6046
- let observer = that.mutationObserver(parent, {
6050
+ var observer = that.mutationObserver(parent, {
6047
6051
  config: {
6048
6052
  subtree: true,
6049
6053
  childList: true,
@@ -6053,16 +6057,21 @@ var Utils = (function () {
6053
6057
  let node = getNode();
6054
6058
  if (node) {
6055
6059
  // 取消观察器
6056
- observer.disconnect();
6060
+ if (typeof observer?.disconnect === "function") {
6061
+ observer.disconnect();
6062
+ }
6057
6063
  resolve(node);
6058
6064
  return;
6059
6065
  }
6060
6066
  },
6067
+ immediate: true,
6061
6068
  });
6062
6069
  if (timeout > 0) {
6063
6070
  setTimeout(() => {
6064
6071
  // 取消观察器
6065
- observer.disconnect();
6072
+ if (typeof observer?.disconnect === "function") {
6073
+ observer.disconnect();
6074
+ }
6066
6075
  resolve(null);
6067
6076
  }, timeout);
6068
6077
  }
@@ -6196,12 +6205,7 @@ var Utils = (function () {
6196
6205
  }
6197
6206
  }
6198
6207
  }
6199
- let nodeList = getNodeList();
6200
- if (nodeList) {
6201
- resolve(nodeList);
6202
- return;
6203
- }
6204
- let observer = that.mutationObserver(parent, {
6208
+ var observer = that.mutationObserver(parent, {
6205
6209
  config: {
6206
6210
  subtree: true,
6207
6211
  childList: true,
@@ -6211,16 +6215,22 @@ var Utils = (function () {
6211
6215
  let node = getNodeList();
6212
6216
  if (node) {
6213
6217
  // 取消观察器
6214
- observer.disconnect();
6218
+ try {
6219
+ observer.disconnect();
6220
+ }
6221
+ catch (error) { }
6215
6222
  resolve(node);
6216
6223
  return;
6217
6224
  }
6218
6225
  },
6226
+ immediate: true,
6219
6227
  });
6220
6228
  if (timeout > 0) {
6221
6229
  setTimeout(() => {
6222
6230
  // 取消观察器
6223
- observer.disconnect();
6231
+ if (typeof observer?.disconnect === "function") {
6232
+ observer.disconnect();
6233
+ }
6224
6234
  resolve(null);
6225
6235
  }, timeout);
6226
6236
  }