@whitesev/utils 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/index.amd.js +260 -409
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +260 -409
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +260 -409
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +260 -409
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +260 -409
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +260 -409
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/ColorConversion.d.ts +3 -8
  14. package/dist/types/src/Dictionary.d.ts +21 -14
  15. package/dist/types/src/GBKEncoder.d.ts +1 -2
  16. package/dist/types/src/Hooks.d.ts +1 -2
  17. package/dist/types/src/Httpx.d.ts +45 -46
  18. package/dist/types/src/LockFunction.d.ts +1 -2
  19. package/dist/types/src/Log.d.ts +1 -2
  20. package/dist/types/src/Progress.d.ts +1 -2
  21. package/dist/types/src/Utils.d.ts +30 -2
  22. package/dist/types/src/UtilsGMMenu.d.ts +1 -2
  23. package/dist/types/src/WindowApi.d.ts +1 -2
  24. package/dist/types/src/indexedDB.d.ts +1 -2
  25. package/dist/types/src/types/Event.d.ts +1 -2
  26. package/dist/types/src/types/Httpx.d.ts +75 -86
  27. package/dist/types/src/types/ajaxHooker.d.ts +1 -5
  28. package/dist/types/src/types/env.d.ts +2 -0
  29. package/dist/types/src/types/global.d.ts +3 -0
  30. package/package.json +1 -1
  31. package/src/ColorConversion.ts +13 -37
  32. package/src/CommonUtil.ts +8 -31
  33. package/src/DOMUtils.ts +9 -24
  34. package/src/Dictionary.ts +37 -38
  35. package/src/GBKEncoder.ts +9 -18
  36. package/src/Hooks.ts +2 -7
  37. package/src/Httpx.ts +257 -412
  38. package/src/LockFunction.ts +1 -3
  39. package/src/Log.ts +8 -26
  40. package/src/Progress.ts +3 -13
  41. package/src/TryCatch.ts +4 -12
  42. package/src/Utils.ts +233 -595
  43. package/src/UtilsCommon.ts +5 -9
  44. package/src/UtilsGMCookie.ts +1 -4
  45. package/src/UtilsGMMenu.ts +29 -51
  46. package/src/Vue.ts +6 -18
  47. package/src/WindowApi.ts +2 -5
  48. package/src/indexedDB.ts +11 -20
  49. package/src/types/Event.d.ts +1 -2
  50. package/src/types/Httpx.d.ts +75 -86
  51. package/src/types/ajaxHooker.d.ts +1 -5
  52. package/src/types/env.d.ts +2 -0
  53. package/src/types/global.d.ts +3 -0
@@ -1,4 +1,4 @@
1
- class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
1
+ export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
2
2
  #flag: boolean = false;
3
3
  #delayTime: number = 0;
4
4
  #callback: K;
@@ -60,5 +60,3 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
60
60
  };
61
61
  }
62
62
  }
63
-
64
- export { LockFunction };
package/src/Log.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { UtilsLogOptions } from "./types/Log";
2
2
 
3
- class Log {
3
+ export class Log {
4
4
  /** 是否禁用输出的flag */
5
5
  #disable: boolean = false;
6
6
  /** 前面的TAG标志 */
@@ -45,10 +45,7 @@ class Log {
45
45
  ) {
46
46
  if (typeof __GM_info === "string") {
47
47
  this.tag = __GM_info;
48
- } else if (
49
- typeof __GM_info === "object" &&
50
- typeof __GM_info?.script?.name === "string"
51
- ) {
48
+ } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
52
49
  this.tag = __GM_info.script.name;
53
50
  }
54
51
  this.#console = console;
@@ -66,9 +63,7 @@ class Log {
66
63
  for (let stackString of stack) {
67
64
  stackString = stackString.trim();
68
65
  let stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
69
- let stackFunctionNamePositionMatch = stackString.match(
70
- /^at[\s]+.+[\s]+\((.+?)\)/i
71
- );
66
+ let stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
72
67
  if (stackFunctionNameMatch == null) {
73
68
  continue;
74
69
  }
@@ -76,12 +71,9 @@ class Log {
76
71
  continue;
77
72
  }
78
73
  /* 获取最后一个,因为第一个是包含了at */
79
- let stackFunctionName =
80
- stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
74
+ let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
81
75
  let stackFunctionNamePosition =
82
- stackFunctionNamePositionMatch[
83
- stackFunctionNamePositionMatch.length - 1
84
- ];
76
+ stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
85
77
  if (
86
78
  stackFunctionName === "" ||
87
79
  stackFunctionName.match(
@@ -114,10 +106,7 @@ class Log {
114
106
  */
115
107
  private checkClearConsole() {
116
108
  this.#logCount++;
117
- if (
118
- this.#details.autoClearConsole &&
119
- this.#logCount > this.#details.logMaxCount
120
- ) {
109
+ if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
121
110
  this.#console.clear();
122
111
  this.#logCount = 0;
123
112
  }
@@ -134,8 +123,7 @@ class Log {
134
123
  otherStyle = otherStyle || "";
135
124
  let stackSplit = new Error()!.stack!.split("\n");
136
125
  stackSplit.splice(0, 2);
137
- let { name: callerName, position: callerPosition } =
138
- this.parseErrorStack(stackSplit);
126
+ let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
139
127
  let tagName = this.tag;
140
128
  let that = this;
141
129
 
@@ -204,11 +192,7 @@ class Log {
204
192
  */
205
193
  warn(...args: any[]) {
206
194
  if (this.#disable) return;
207
- this.printContent(
208
- args,
209
- this.#details.warnColor,
210
- "background: #FEF6D5;padding: 4px 6px 4px 0px;"
211
- );
195
+ this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
212
196
  }
213
197
  /**
214
198
  * 控制台-错误输出
@@ -273,5 +257,3 @@ class Log {
273
257
  this.#disable = false;
274
258
  }
275
259
  }
276
-
277
- export { Log };
package/src/Progress.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { CommonUtil } from "./CommonUtil";
2
2
  import type { ProgressParamConfig } from "./types/Progress";
3
3
 
4
- class Progress {
4
+ export class Progress {
5
5
  #config: ProgressParamConfig = {
6
6
  /**
7
7
  * canvas元素节点
@@ -50,9 +50,7 @@ class Progress {
50
50
  constructor(paramConfig: ProgressParamConfig) {
51
51
  this.#config = CommonUtil.assign(this.#config, paramConfig);
52
52
  if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
53
- throw new Error(
54
- "Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement"
55
- );
53
+ throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
56
54
  }
57
55
  this.init();
58
56
  }
@@ -90,13 +88,7 @@ class Progress {
90
88
  this.#ctx.clearRect(0, 0, this.#width, this.#height);
91
89
  /* 开始绘制底圆 */
92
90
  this.#ctx.beginPath();
93
- this.#ctx.arc(
94
- this.#width / 2,
95
- this.#height / 2,
96
- this.#config.circleRadius,
97
- 1,
98
- 8
99
- );
91
+ this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
100
92
  this.#ctx.strokeStyle = this.#config.lineBgColor;
101
93
  this.#ctx.stroke();
102
94
  /* 开始绘制动态圆 */
@@ -120,5 +112,3 @@ class Progress {
120
112
  this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
121
113
  }
122
114
  }
123
-
124
- export { Progress };
package/src/TryCatch.ts CHANGED
@@ -24,8 +24,7 @@ export const TryCatch = function (...args: any) {
24
24
  * @param handler
25
25
  */
26
26
  error(handler: ((...args: any[]) => any) | string | Function) {
27
- // @ts-ignore
28
- handleError = handler;
27
+ handleError = handler as (error: Error) => void;
29
28
  return TryCatchCore;
30
29
  },
31
30
  /**
@@ -42,8 +41,7 @@ export const TryCatch = function (...args: any) {
42
41
  callbackFunction = callback;
43
42
  context = __context__ || this;
44
43
  let result = executeTryCatch(callbackFunction, handleError, context);
45
- // @ts-ignore
46
- return result !== void 0 ? result : TryCatchCore;
44
+ return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
47
45
  },
48
46
  };
49
47
 
@@ -69,19 +67,13 @@ export const TryCatch = function (...args: any) {
69
67
  } catch (error) {
70
68
  if (defaultDetails.log) {
71
69
  callback = callback as Function;
72
- console.log(
73
- `%c ${callback?.name ? callback?.name : callback + "出现错误"} `,
74
- "color: #f20000"
75
- );
70
+ console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
76
71
  console.log(`%c 错误原因:${error}`, "color: #f20000");
77
72
  console.trace(callback);
78
73
  }
79
74
  if (handleErrorFunc) {
80
75
  if (typeof handleErrorFunc === "string") {
81
- result = new Function(handleErrorFunc).apply(funcThis, [
82
- ...args,
83
- error,
84
- ]);
76
+ result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
85
77
  } else {
86
78
  result = handleErrorFunc.apply(funcThis, [...args, error]);
87
79
  }