@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/src/Progress.ts CHANGED
@@ -1,108 +1,108 @@
1
- import { CommonUtil } from "./CommonUtil";
2
- import type { ProgressParamConfig } from "./types/Progress";
3
-
4
- export class Progress {
5
- #config: ProgressParamConfig = {
6
- /**
7
- * canvas元素节点
8
- */
9
- canvasNode: null as any,
10
- /**
11
- * 绘制角度
12
- */
13
- deg: 95,
14
- /**
15
- * 进度
16
- */
17
- progress: 0,
18
- /**
19
- * 绘制的线宽度
20
- */
21
- lineWidth: 10,
22
- /**
23
- * 绘制的背景颜色
24
- */
25
- lineBgColor: "#1e637c",
26
- /**
27
- * 绘制的线的颜色
28
- */
29
- lineColor: "#25deff",
30
- /**
31
- * 绘制的字体颜色
32
- */
33
- textColor: "#000000",
34
- /**
35
- * 绘制的字体大小(px)
36
- */
37
- fontSize: 22,
38
- /**
39
- * 绘制的圆的半径
40
- */
41
- circleRadius: 50,
42
- };
43
- #ctx: CanvasRenderingContext2D;
44
- #width: number;
45
- #height: number;
46
- /**
47
- *
48
- * @param paramConfig 配置信息
49
- */
50
- constructor(paramConfig: ProgressParamConfig) {
51
- this.#config = CommonUtil.assign(this.#config, paramConfig);
52
- if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
53
- throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
54
- }
55
- /* 获取画笔 */
56
- const ctx = this.#config.canvasNode.getContext("2d");
57
- if (ctx == null) {
58
- throw new Error("Utils.Progress 获取画笔失败");
59
- }
60
- this.#ctx = ctx;
61
- /* 元素宽度 */
62
- this.#width = this.#config.canvasNode.width;
63
- /* 元素高度 */
64
- this.#height = this.#config.canvasNode.height;
65
- /* 清除锯齿 */
66
- if (window.devicePixelRatio) {
67
- this.#config.canvasNode.style.width = `${this.#width}px`;
68
- this.#config.canvasNode.style.height = `${this.#height}px`;
69
- this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
70
- this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
71
- this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
72
- }
73
- /* 设置线宽 */
74
- this.#ctx.lineWidth = this.#config.lineWidth;
75
- }
76
- /**
77
- * 绘制
78
- */
79
- draw() {
80
- const degActive = (this.#config.progress * 360) / 100;
81
- /* 清除画布 */
82
- this.#ctx.clearRect(0, 0, this.#width, this.#height);
83
- /* 开始绘制底圆 */
84
- this.#ctx.beginPath();
85
- this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
86
- this.#ctx.strokeStyle = this.#config.lineBgColor;
87
- this.#ctx.stroke();
88
- /* 开始绘制动态圆 */
89
- this.#ctx.beginPath();
90
- this.#ctx.arc(
91
- this.#width / 2,
92
- this.#height / 2,
93
- this.#config.circleRadius,
94
- -Math.PI / 2,
95
- (degActive * Math.PI) / 180 - Math.PI / 2
96
- );
97
- this.#ctx.strokeStyle = this.#config.lineColor;
98
- this.#ctx.stroke();
99
- /* 获取百分比 */
100
- const txt = `${parseInt(this.#config.progress.toString())}%`;
101
- this.#ctx.font = `${this.#config.fontSize}px SimHei`;
102
- /* 获取文本宽度 */
103
- const w = this.#ctx.measureText(txt).width;
104
- const h = this.#config.fontSize / 2;
105
- this.#ctx.fillStyle = this.#config.textColor;
106
- this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
107
- }
108
- }
1
+ import { CommonUtil } from "./CommonUtil";
2
+ import type { ProgressParamConfig } from "./types/Progress";
3
+
4
+ export class Progress {
5
+ #config: ProgressParamConfig = {
6
+ /**
7
+ * canvas元素节点
8
+ */
9
+ canvasNode: null as any,
10
+ /**
11
+ * 绘制角度
12
+ */
13
+ deg: 95,
14
+ /**
15
+ * 进度
16
+ */
17
+ progress: 0,
18
+ /**
19
+ * 绘制的线宽度
20
+ */
21
+ lineWidth: 10,
22
+ /**
23
+ * 绘制的背景颜色
24
+ */
25
+ lineBgColor: "#1e637c",
26
+ /**
27
+ * 绘制的线的颜色
28
+ */
29
+ lineColor: "#25deff",
30
+ /**
31
+ * 绘制的字体颜色
32
+ */
33
+ textColor: "#000000",
34
+ /**
35
+ * 绘制的字体大小(px)
36
+ */
37
+ fontSize: 22,
38
+ /**
39
+ * 绘制的圆的半径
40
+ */
41
+ circleRadius: 50,
42
+ };
43
+ #ctx: CanvasRenderingContext2D;
44
+ #width: number;
45
+ #height: number;
46
+ /**
47
+ *
48
+ * @param paramConfig 配置信息
49
+ */
50
+ constructor(paramConfig: ProgressParamConfig) {
51
+ this.#config = CommonUtil.assign(this.#config, paramConfig);
52
+ if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
53
+ throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
54
+ }
55
+ /* 获取画笔 */
56
+ const ctx = this.#config.canvasNode.getContext("2d");
57
+ if (ctx == null) {
58
+ throw new Error("Utils.Progress 获取画笔失败");
59
+ }
60
+ this.#ctx = ctx;
61
+ /* 元素宽度 */
62
+ this.#width = this.#config.canvasNode.width;
63
+ /* 元素高度 */
64
+ this.#height = this.#config.canvasNode.height;
65
+ /* 清除锯齿 */
66
+ if (window.devicePixelRatio) {
67
+ this.#config.canvasNode.style.width = `${this.#width}px`;
68
+ this.#config.canvasNode.style.height = `${this.#height}px`;
69
+ this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
70
+ this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
71
+ this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
72
+ }
73
+ /* 设置线宽 */
74
+ this.#ctx.lineWidth = this.#config.lineWidth;
75
+ }
76
+ /**
77
+ * 绘制
78
+ */
79
+ draw() {
80
+ const degActive = (this.#config.progress * 360) / 100;
81
+ /* 清除画布 */
82
+ this.#ctx.clearRect(0, 0, this.#width, this.#height);
83
+ /* 开始绘制底圆 */
84
+ this.#ctx.beginPath();
85
+ this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
86
+ this.#ctx.strokeStyle = this.#config.lineBgColor;
87
+ this.#ctx.stroke();
88
+ /* 开始绘制动态圆 */
89
+ this.#ctx.beginPath();
90
+ this.#ctx.arc(
91
+ this.#width / 2,
92
+ this.#height / 2,
93
+ this.#config.circleRadius,
94
+ -Math.PI / 2,
95
+ (degActive * Math.PI) / 180 - Math.PI / 2
96
+ );
97
+ this.#ctx.strokeStyle = this.#config.lineColor;
98
+ this.#ctx.stroke();
99
+ /* 获取百分比 */
100
+ const txt = `${parseInt(this.#config.progress.toString())}%`;
101
+ this.#ctx.font = `${this.#config.fontSize}px SimHei`;
102
+ /* 获取文本宽度 */
103
+ const w = this.#ctx.measureText(txt).width;
104
+ const h = this.#config.fontSize / 2;
105
+ this.#ctx.fillStyle = this.#config.textColor;
106
+ this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
107
+ }
108
+ }
package/src/TryCatch.ts CHANGED
@@ -1,86 +1,86 @@
1
- import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
2
-
3
- export const TryCatch = function (...args: any) {
4
- /* 定义变量和函数 */
5
- let callbackFunction = null;
6
- let context = null;
7
- let handleError: (error: Error) => void = () => {};
8
- let defaultDetails = {
9
- log: true,
10
- };
11
-
12
- const TryCatchCore = {
13
- /**
14
- *
15
- * @param paramDetails 配置
16
- * @returns
17
- */
18
- config(paramDetails: UtilsTryCatchConfig) {
19
- defaultDetails = Object.assign(defaultDetails, paramDetails);
20
- return TryCatchCore;
21
- },
22
- /**
23
- * 处理错误
24
- * @param handler
25
- */
26
- error(handler: ((...args: any[]) => any) | string | ((...args: any[]) => any)) {
27
- handleError = handler as (error: Error) => void;
28
- return TryCatchCore;
29
- },
30
- /**
31
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
32
- * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
33
- * @param __context__ 待执行函数的作用域,用于apply指定
34
- * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
35
- * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
36
- */
37
- run<A extends any[], R>(
38
- callback: ((...args: A) => R) | string | ((...args: any[]) => any),
39
- __context__?: any
40
- ): UtilsTryCatchType {
41
- callbackFunction = callback;
42
- context = __context__ || this;
43
- const result = executeTryCatch(callbackFunction, handleError, context);
44
- return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
45
- },
46
- };
47
-
48
- /**
49
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
50
- * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
51
- * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
52
- * @param funcThis - 待执行函数的作用域,用于apply指定
53
- * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
54
- */
55
- function executeTryCatch<A extends any[], R>(
56
- callback: string | ((...args: A) => R) | ((...args: any[]) => any),
57
- handleErrorFunc: string | ((...args: any[]) => any),
58
- funcThis?: any
59
- ) {
60
- let result = void 0;
61
- try {
62
- if (typeof callback === "string") {
63
- result = new Function(callback).apply(funcThis, args);
64
- } else {
65
- result = (callback as (...args: any[]) => any).apply(funcThis, args);
66
- }
67
- } catch (error) {
68
- if (defaultDetails.log) {
69
- callback = callback as (...args: any[]) => any;
70
- console.log(`%c ${callback?.name ? callback?.name : `${callback}`} `, "color: #f20000");
71
- console.log(`%c ${error}`, "color: #f20000");
72
- console.trace(callback);
73
- }
74
- if (handleErrorFunc) {
75
- if (typeof handleErrorFunc === "string") {
76
- result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
77
- } else {
78
- result = handleErrorFunc.apply(funcThis, [...args, error]);
79
- }
80
- }
81
- }
82
- return result;
83
- }
84
-
85
- return TryCatchCore;
86
- };
1
+ import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
2
+
3
+ export const TryCatch = function (...args: any) {
4
+ /* 定义变量和函数 */
5
+ let callbackFunction = null;
6
+ let context = null;
7
+ let handleError: (error: Error) => void = () => {};
8
+ let defaultDetails = {
9
+ log: true,
10
+ };
11
+
12
+ const TryCatchCore = {
13
+ /**
14
+ *
15
+ * @param paramDetails 配置
16
+ * @returns
17
+ */
18
+ config(paramDetails: UtilsTryCatchConfig) {
19
+ defaultDetails = Object.assign(defaultDetails, paramDetails);
20
+ return TryCatchCore;
21
+ },
22
+ /**
23
+ * 处理错误
24
+ * @param handler
25
+ */
26
+ error(handler: ((...args: any[]) => any) | string | ((...args: any[]) => any)) {
27
+ handleError = handler as (error: Error) => void;
28
+ return TryCatchCore;
29
+ },
30
+ /**
31
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
32
+ * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
33
+ * @param __context__ 待执行函数的作用域,用于apply指定
34
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
35
+ * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
36
+ */
37
+ run<A extends any[], R>(
38
+ callback: ((...args: A) => R) | string | ((...args: any[]) => any),
39
+ __context__?: any
40
+ ): UtilsTryCatchType {
41
+ callbackFunction = callback;
42
+ context = __context__ || this;
43
+ const result = executeTryCatch(callbackFunction, handleError, context);
44
+ return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
45
+ },
46
+ };
47
+
48
+ /**
49
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
50
+ * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
51
+ * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
52
+ * @param funcThis - 待执行函数的作用域,用于apply指定
53
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
54
+ */
55
+ function executeTryCatch<A extends any[], R>(
56
+ callback: string | ((...args: A) => R) | ((...args: any[]) => any),
57
+ handleErrorFunc: string | ((...args: any[]) => any),
58
+ funcThis?: any
59
+ ) {
60
+ let result = void 0;
61
+ try {
62
+ if (typeof callback === "string") {
63
+ result = new Function(callback).apply(funcThis, args);
64
+ } else {
65
+ result = (callback as (...args: any[]) => any).apply(funcThis, args);
66
+ }
67
+ } catch (error) {
68
+ if (defaultDetails.log) {
69
+ callback = callback as (...args: any[]) => any;
70
+ console.log(`%c ${callback?.name ? callback?.name : `${callback}`} `, "color: #f20000");
71
+ console.log(`%c ${error}`, "color: #f20000");
72
+ console.trace(callback);
73
+ }
74
+ if (handleErrorFunc) {
75
+ if (typeof handleErrorFunc === "string") {
76
+ result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
77
+ } else {
78
+ result = handleErrorFunc.apply(funcThis, [...args, error]);
79
+ }
80
+ }
81
+ }
82
+ return result;
83
+ }
84
+
85
+ return TryCatchCore;
86
+ };