@whitesev/utils 2.3.8 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/index.amd.js +379 -268
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +379 -268
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +379 -268
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +379 -268
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +379 -268
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +379 -268
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Httpx.d.ts +25 -1178
  14. package/dist/types/src/Log.d.ts +1 -19
  15. package/dist/types/src/Progress.d.ts +1 -20
  16. package/dist/types/src/TryCatch.d.ts +2 -11
  17. package/dist/types/src/Utils.d.ts +8 -32
  18. package/dist/types/src/UtilsGMCookie.d.ts +1 -51
  19. package/dist/types/src/UtilsGMMenu.d.ts +1 -50
  20. package/dist/types/src/WindowApi.d.ts +3 -11
  21. package/dist/types/src/types/Httpx.d.ts +1316 -0
  22. package/dist/types/src/types/Log.d.ts +19 -0
  23. package/dist/types/src/types/Progress.d.ts +20 -0
  24. package/dist/types/src/types/TryCatch.d.ts +9 -0
  25. package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
  26. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
  27. package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
  28. package/dist/types/src/types/Vue3.d.ts +0 -0
  29. package/dist/types/src/types/WindowApi.d.ts +10 -0
  30. package/dist/types/src/types/global.d.ts +24 -1
  31. package/package.json +1 -1
  32. package/src/GBKEncoder.ts +1 -1
  33. package/src/Httpx.ts +533 -1627
  34. package/src/Log.ts +1 -19
  35. package/src/Progress.ts +1 -20
  36. package/src/TryCatch.ts +2 -12
  37. package/src/Utils.ts +15 -38
  38. package/src/UtilsGMCookie.ts +7 -56
  39. package/src/UtilsGMMenu.ts +5 -78
  40. package/src/WindowApi.ts +4 -11
  41. package/src/types/Event.d.ts +189 -0
  42. package/src/types/Httpx.d.ts +1316 -0
  43. package/src/types/Log.d.ts +19 -0
  44. package/src/types/Progress.d.ts +20 -0
  45. package/src/types/TryCatch.d.ts +9 -0
  46. package/src/types/UtilsGMCookie.d.ts +55 -0
  47. package/src/types/UtilsGMMenu.d.ts +77 -0
  48. package/src/types/Vue2.d.ts +154 -0
  49. package/src/types/Vue3.d.ts +0 -0
  50. package/src/types/WindowApi.d.ts +10 -0
  51. package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
  52. package/src/types/global.d.ts +24 -1
  53. package/dist/types/src/Event.d.ts +0 -156
  54. package/dist/types/src/VueObject.d.ts +0 -123
  55. /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
  56. /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
package/src/Log.ts CHANGED
@@ -1,22 +1,4 @@
1
- /** Utils.Log的初始化配置 */
2
- declare interface UtilsLogOptions {
3
- /** 是否输出Tag,false的话其它的颜色也不输出 @default true */
4
- tag: boolean;
5
- /** log.success的颜色 @default "#0000FF" */
6
- successColor: string;
7
- /** log.warn的颜色 @default "0" */
8
- warnColor: string;
9
- /** log.error的颜色 @default "#FF0000" */
10
- errorColor: string;
11
- /** log.info的颜色 @default "0" */
12
- infoColor: string;
13
- /** 是否开启debug模式,true会在控制台每次调用时输出调用函数的所在位置,false不会输出位置 @default false */
14
- debug: boolean;
15
- /** 当console输出超过logMaxCount数量自动清理控制台 @default false */
16
- autoClearConsole: boolean;
17
- /** console输出的最高数量,autoClearConsole开启则生效 @default 999 */
18
- logMaxCount: number;
19
- }
1
+ import type { UtilsLogOptions } from "./types/Log";
20
2
 
21
3
  class Log {
22
4
  /** 是否禁用输出的flag */
package/src/Progress.ts CHANGED
@@ -1,25 +1,6 @@
1
+ import type { ProgressParamConfig } from "./types/Progress";
1
2
  import { Utils } from "./Utils";
2
3
 
3
- declare interface ProgressParamConfig {
4
- /** canvas元素节点 */
5
- canvasNode: HTMLCanvasElement;
6
- /** 绘制角度,默认:95 */
7
- deg: number;
8
- /** 进度,默认:0 */
9
- progress: number;
10
- /** 绘制的线宽度,默认:10 */
11
- lineWidth: number;
12
- /** 绘制的背景颜色,默认:#1e637c */
13
- lineBgColor: string;
14
- /** 绘制的线的颜色,默认:#25deff */
15
- lineColor: string;
16
- /** 绘制的字体颜色,默认:#000000 */
17
- textColor: string;
18
- /** 绘制的字体大小(px),默认:22px */
19
- fontSize: number;
20
- /** 绘制的圆的半径,默认:50 */
21
- circleRadius: number;
22
- }
23
4
  class Progress {
24
5
  #config: ProgressParamConfig = {
25
6
  /**
package/src/TryCatch.ts CHANGED
@@ -1,15 +1,7 @@
1
+ import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
1
2
  import { Utils } from "./Utils";
2
3
 
3
- export declare interface UtilsTryCatchConfig {
4
- log: boolean;
5
- }
6
- /** tryCatch */
7
- export declare interface UtilsTryCatchType {
8
- run: UtilsTryCatchType;
9
- config: UtilsTryCatchType;
10
- error: UtilsTryCatchType;
11
- }
12
- const TryCatch = function (...args: any) {
4
+ export const TryCatch = function (...args: any) {
13
5
  /* 定义变量和函数 */
14
6
  let callbackFunction = null;
15
7
  let context = null;
@@ -103,5 +95,3 @@ const TryCatch = function (...args: any) {
103
95
 
104
96
  return TryCatchCore;
105
97
  };
106
-
107
- export { TryCatch };
package/src/Utils.ts CHANGED
@@ -11,41 +11,17 @@ import { Log } from "./Log";
11
11
  import { Progress } from "./Progress";
12
12
  import { TryCatch } from "./TryCatch";
13
13
  import { UtilsDictionary } from "./Dictionary";
14
- import type { DOMUtils_EventType } from "./Event";
15
- import type { Vue2Object } from "./VueObject";
16
- import type { UtilsAjaxHookResult } from "./AjaxHookerType";
14
+ import type { DOMUtils_EventType } from "./types/Event";
15
+ import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
17
16
  import { GenerateUUID } from "./UtilsCommon";
18
- import { WindowApi, type UtilsWindowApiOption } from "./WindowApi";
17
+ import { WindowApi } from "./WindowApi";
19
18
  import { Vue } from "./Vue";
20
-
21
- export declare var unsafeWindow: Window & typeof globalThis;
22
-
23
- export type JSTypeMap = {
24
- string: string;
25
- number: number;
26
- boolean: boolean;
27
- object: object;
28
- symbol: symbol;
29
- bigint: bigint;
30
- undefined: undefined;
31
- null: null;
32
- };
33
-
34
- export type JSTypeNames = keyof JSTypeMap;
35
-
36
- export type ArgsType<T extends JSTypeNames[]> = {
37
- [I in keyof T]: JSTypeMap[T[I]];
38
- };
39
-
40
- export declare interface UtilsOwnObject<V extends any> {
41
- [key: string]: V | UtilsOwnObject<V>;
42
- }
43
- export declare interface AnyObject {
44
- [key: string]: any | AnyObject;
45
- toString(): string;
46
- }
47
-
48
- export declare interface Vue2Context extends Vue2Object {}
19
+ import {
20
+ type ArgsType,
21
+ type JSTypeNames,
22
+ type UtilsOwnObject,
23
+ } from "./types/global";
24
+ import type { UtilsWindowApiOption } from "./types/WindowApi";
49
25
 
50
26
  class Utils {
51
27
  private windowApi: WindowApi;
@@ -53,7 +29,7 @@ class Utils {
53
29
  this.windowApi = new WindowApi(option);
54
30
  }
55
31
  /** 版本号 */
56
- version = "2024.10.19";
32
+ version = "2024.10.28";
57
33
 
58
34
  /**
59
35
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -504,7 +480,7 @@ class Utils {
504
480
  dispatchEvent(
505
481
  element: HTMLElement | Document,
506
482
  eventName: DOMUtils_EventType | DOMUtils_EventType[],
507
- details?: UtilsOwnObject<any>
483
+ details?: any
508
484
  ): void;
509
485
  /**
510
486
  * 主动触发事件
@@ -519,12 +495,12 @@ class Utils {
519
495
  dispatchEvent(
520
496
  element: HTMLElement | Document,
521
497
  eventName: string,
522
- details?: UtilsOwnObject<any>
498
+ details?: any
523
499
  ): void;
524
500
  dispatchEvent(
525
501
  element: HTMLElement | Document,
526
502
  eventName: DOMUtils_EventType | DOMUtils_EventType[] | string,
527
- details?: UtilsOwnObject<any>
503
+ details?: any
528
504
  ) {
529
505
  let eventNameList: string[] = [];
530
506
  if (typeof eventName === "string") {
@@ -3510,7 +3486,8 @@ class Utils {
3510
3486
  offSetX: number,
3511
3487
  offSetY: number
3512
3488
  ) {
3513
- let win = unsafeWindow || window;
3489
+ // @ts-ignore
3490
+ let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
3514
3491
  let mouseEvent =
3515
3492
  UtilsContext.windowApi.document.createEvent("MouseEvents");
3516
3493
  mouseEvent.initMouseEvent(
@@ -1,61 +1,12 @@
1
+ import type {
2
+ UtilsGMCookieDeleteOptions,
3
+ UtilsGMCookieListOptions,
4
+ UtilsGMCookieResult,
5
+ UtilsGMCookieSetOptions,
6
+ WindowApiOption,
7
+ } from "./types/UtilsGMCookie";
1
8
  import { Utils } from "./Utils";
2
9
 
3
- declare interface UtilsGMCookieResult {
4
- /** 为 window.location.hostname */
5
- domain: string;
6
- expirationDate: null;
7
- hostOnly: true;
8
- httpOnly: false;
9
- name: string;
10
- path: "/";
11
- sameSite: "unspecified";
12
- secure: true;
13
- session: false;
14
- value: string;
15
- }
16
-
17
- declare interface UtilsGMCookieListOptions {
18
- /** 默认为当前的url */
19
- url: string;
20
- /** 默认为当前的域名(window.location.hostname) */
21
- domain: string;
22
- /** 需要检索的Cookie的名字 */
23
- name: string | RegExp;
24
- /** 需要检索的Cookie的路径,默认为"/" */
25
- path: string;
26
- }
27
-
28
- declare interface UtilsGMCookieSetOptions {
29
- /** 默认为当前的url */
30
- url?: string;
31
- /** 默认为当前的域名(window.location.hostname) */
32
- domain?: string;
33
- /** 需要检索的Cookie的名字 */
34
- name?: string;
35
- /** 需要检索的Cookie的路径,默认为"/" */
36
- path?: string;
37
- /** 值 */
38
- value?: string | number;
39
- /** 确保Cookie只在通过安全协议(如HTTPS)的情况下传输 */
40
- secure?: boolean;
41
- /** 是否防止JavaScript代码访问Cookie */
42
- httpOnly?: boolean;
43
- /** Cookie过期时间,默认为30天 */
44
- expirationDate?: number;
45
- }
46
-
47
- declare interface UtilsGMCookieDeleteOptions {
48
- /** 默认为当前的url */
49
- url: string;
50
- /** 需要检索的Cookie的名字 */
51
- name: string;
52
- }
53
-
54
- interface WindowApiOption {
55
- window: Window & typeof globalThis;
56
- document: Document;
57
- }
58
-
59
10
  class UtilsGMCookie {
60
11
  private windowApi = {
61
12
  window: window,
@@ -1,83 +1,10 @@
1
+ import type {
2
+ UtilsGMMenuConstructorOptions,
3
+ UtilsGMMenuOption,
4
+ UtilsGMMenuOptionData,
5
+ } from "./types/UtilsGMMenu";
1
6
  import { Utils } from "./Utils";
2
7
 
3
- declare interface UtilsGMMenuClickCallBackData {
4
- /** 菜单键名 */
5
- key: string;
6
- /** 是否启用 */
7
- enable: boolean;
8
- /** 点击前的enable值 */
9
- oldEnable: boolean;
10
- /** 触发的事件 */
11
- event: MouseEvent | KeyboardEvent;
12
- /** 将enable值写入本地的回调,设置参数false就不保存到本地 */
13
- storeValue(enable: boolean): void;
14
- }
15
-
16
- declare interface UtilsGMMenuOption {
17
- /** 菜单的本地键key,不可重复,会覆盖 */
18
- key: string;
19
- /** 菜单的文本 */
20
- text: string;
21
- /** (可选)菜单的开启状态,默认为false */
22
- enable?: boolean;
23
- /** (可选)使用条件:TamperMonkey版本>5.0,如果id和已注册的菜单id相同,可修改当前已注册菜单的options */
24
- id?: number;
25
- /** (可选)An optional access key. Please see the description below. Either options or accessKey can be specified. */
26
- accessKey?: string;
27
- /** (可选)自动关闭菜单,可不设置 */
28
- autoClose?: boolean;
29
- /** 使用条件:TamperMonkey版本>5.0,使用菜单项的鼠标悬浮上的工具提示*/
30
- title?: string;
31
- /** (可选)点击菜单后自动刷新网页,默认为true */
32
- autoReload?: boolean;
33
- /** 菜单的显示文本,未设置的话则自动根据enable在前面加上图标 */
34
- showText(text: string, enable: boolean): string;
35
- /** 点击菜单的回调 */
36
- callback(data: UtilsGMMenuClickCallBackData): void;
37
- /** 是否允许菜单进行存储值,默认true允许 */
38
- isStoreValue?: boolean;
39
- }
40
-
41
- declare interface UtilsGMMenuHandledOption extends UtilsGMMenuOption {
42
- /**
43
- * 删除该菜单
44
- */
45
- deleteMenu(): void;
46
- }
47
-
48
- declare interface UtilsGMMenuOptionData {
49
- /**
50
- * 菜单id
51
- */
52
- id?: number;
53
- /**
54
- * 菜单配置
55
- */
56
- data: UtilsGMMenuOption;
57
- /**
58
- * 处理后的菜单配置
59
- * 对autoReload进行处理,如果未赋值,按默认的true赋值
60
- * 对isStoreValue进行处理,如果未赋值,按默认的true赋值
61
- * 新增一个deleteMenu
62
- */
63
- handleData: UtilsGMMenuHandledOption;
64
- }
65
-
66
- declare interface UtilsGMMenuConstructorOptions {
67
- /** (可选)配置*/
68
- data?: UtilsGMMenuOption[];
69
- /** (可选)全局菜单点击菜单后自动刷新网页,默认为true */
70
- autoReload?: boolean;
71
- /** 油猴函数 @grant GM_getValue */
72
- GM_getValue: any;
73
- /** 油猴函数 @grant GM_setValue */
74
- GM_setValue: any;
75
- /** 油猴函数 @grant GM_registerMenuCommand */
76
- GM_registerMenuCommand: any;
77
- /** 油猴函数 @grant GM_unregisterMenuCommand */
78
- GM_unregisterMenuCommand: any;
79
- }
80
-
81
8
  class GMMenu {
82
9
  private GM_Api = {
83
10
  /**
package/src/WindowApi.ts CHANGED
@@ -1,15 +1,6 @@
1
- /**
2
- * 配置类型
3
- */
4
- export type UtilsWindowApiOption = {
5
- document: Document;
6
- window: Window & typeof globalThis;
7
- globalThis: typeof globalThis | Window;
8
- self: Window & typeof globalThis;
9
- top: Window;
10
- };
1
+ import type { UtilsWindowApiOption } from "./types/WindowApi";
11
2
 
12
- export class WindowApi {
3
+ class WindowApi {
13
4
  /** 默认的配置 */
14
5
  private defaultApi: UtilsWindowApiOption = {
15
6
  document: document,
@@ -42,3 +33,5 @@ export class WindowApi {
42
33
  return this.api.top;
43
34
  }
44
35
  }
36
+
37
+ export { WindowApi };
@@ -0,0 +1,189 @@
1
+ /**
2
+ * 鼠标事件
3
+ * + https://blog.csdn.net/weixin_68658847/article/details/126939879
4
+ */
5
+
6
+ declare interface DOMUtils_MouseEvent {
7
+ click: MouseEvent | PointerEvent;
8
+ contextmenu: MouseEvent | PointerEvent;
9
+ dblclick: MouseEvent | PointerEvent;
10
+ mousedown: MouseEvent | PointerEvent;
11
+ mouseenter: MouseEvent | PointerEvent;
12
+ mouseleave: MouseEvent | PointerEvent;
13
+ mousemove: MouseEvent | PointerEvent;
14
+ mouseover: MouseEvent | PointerEvent;
15
+ mouseout: MouseEvent | PointerEvent;
16
+ mouseup: MouseEvent | PointerEvent;
17
+ }
18
+ declare type DOMUtils_MouseEventType = keyof DOMUtils_MouseEvent;
19
+ /**
20
+ * 鼠标事件
21
+ */
22
+ declare interface DOMUtils_KeyboardEvent {
23
+ keydown: KeyboardEvent;
24
+ keypress: KeyboardEvent;
25
+ keyup: KeyboardEvent;
26
+ }
27
+ declare type DOMUtils_KeyboardEventType = keyof DOMUtils_KeyboardEvent;
28
+ /**
29
+ * 框架/对象事件
30
+ */
31
+ declare interface DOMUtils_Frame_Object_Event {
32
+ abort: Event;
33
+ beforeunload: Event;
34
+ error: Event;
35
+ hashchange: Event;
36
+ load: Event;
37
+ pageshow: Event;
38
+ pagehide: Event;
39
+ resize: Event;
40
+ scroll: Event;
41
+ unload: Event;
42
+ }
43
+ declare type DOMUtils_Frame_Object_EventType =
44
+ keyof DOMUtils_Frame_Object_Event;
45
+ /**
46
+ * 表单事件
47
+ */
48
+ declare interface DOMUtils_FormEvent {
49
+ blur: Event;
50
+ change: Event;
51
+ focus: Event;
52
+ focusin: Event;
53
+ focusout: Event;
54
+ input: Event;
55
+ reset: Event;
56
+ search: Event;
57
+ }
58
+ declare type DOMUtils_FormEventType = keyof DOMUtils_FormEvent;
59
+
60
+ /**
61
+ * 剪贴板事件
62
+ */
63
+ declare interface DOMUtils_ClipboardEvent {
64
+ copy: ClipboardEvent;
65
+ cut: ClipboardEvent;
66
+ paste: ClipboardEvent;
67
+ }
68
+ declare type DOMUtils_ClipboardEventType = keyof DOMUtils_ClipboardEvent;
69
+
70
+ /**
71
+ * 打印事件
72
+ */
73
+ declare interface DOMUtils_PrintEvent {
74
+ afterprint: Event;
75
+ beforeprint: Event;
76
+ }
77
+ declare type DOMUtils_PrintEventType = keyof DOMUtils_PrintEvent;
78
+
79
+ /**
80
+ * 拖动事件
81
+ */
82
+ declare interface DOMUtils_DragEvent {
83
+ drag: DragEvent;
84
+ dragend: DragEvent;
85
+ dragenter: DragEvent;
86
+ dragleave: DragEvent;
87
+ dragover: DragEvent;
88
+ dragstart: DragEvent;
89
+ drop: DragEvent;
90
+ }
91
+ declare type DOMUtils_DragEventType = keyof DOMUtils_DragEvent;
92
+
93
+ /**
94
+ * 多媒体(Media)事件
95
+ */
96
+ declare interface DOMUtils_MediaEvent {
97
+ abort: Event;
98
+ canplay: Event;
99
+ canplaythrough: Event;
100
+ durationchange: Event;
101
+ emptied: Event;
102
+ ended: Event;
103
+ error: Event;
104
+ loadeddata: Event;
105
+ loadedmetadata: Event;
106
+ loadstart: Event;
107
+ pause: Event;
108
+ play: Event;
109
+ playing: Event;
110
+ progress: Event;
111
+ ratechange: Event;
112
+ seeked: Event;
113
+ seeking: Event;
114
+ stalled: Event;
115
+ suspend: Event;
116
+ timeupdate: Event;
117
+ volumechange: Event;
118
+ waiting: Event;
119
+ }
120
+ declare type DOMUtils_MediaEventType = keyof DOMUtils_MediaEvent;
121
+
122
+ /**
123
+ * 动画事件
124
+ */
125
+ declare interface DOMUtils_AnimationEvent {
126
+ animationend: AnimationEvent;
127
+ animationiteration: AnimationEvent;
128
+ animationstart: AnimationEvent;
129
+ }
130
+ declare type DOMUtils_AnimationEventType = keyof DOMUtils_AnimationEvent;
131
+
132
+ /**
133
+ * 过渡事件
134
+ */
135
+ declare interface DOMUtils_TransitionEvent {
136
+ transitionend: TransitionEvent;
137
+ }
138
+ declare type DOMUtils_TransitionEventType = keyof DOMUtils_TransitionEvent;
139
+
140
+ /**
141
+ * 触摸事件
142
+ */
143
+ declare interface DOMUtils_TouchEvent {
144
+ touchstart: TouchEvent;
145
+ touchmove: TouchEvent;
146
+ touchend: TouchEvent;
147
+ touchcancel: TouchEvent;
148
+ touchenter: TouchEvent;
149
+ touchleave: TouchEvent;
150
+ }
151
+ declare type DOMUtils_TouchEventType = keyof DOMUtils_TouchEvent;
152
+ /**
153
+ * 其它事件
154
+ */
155
+ declare interface DOMUtils_OtherEvent {
156
+ message: Event;
157
+ online: Event;
158
+ offline: Event;
159
+ popstate: Event;
160
+ show: Event;
161
+ storage: Event;
162
+ toggle: Event;
163
+ wheel: Event;
164
+ propertychange: Event;
165
+ fullscreenchange: Event;
166
+ DOMContentLoaded: Event;
167
+ }
168
+ declare type DOMUtils_OtherEventType = keyof DOMUtils_OtherEvent;
169
+
170
+ /**
171
+ * 全部事件
172
+ */
173
+ export declare type DOMUtils_Event = DOMUtils_MouseEvent &
174
+ DOMUtils_KeyboardEvent &
175
+ DOMUtils_Frame_Object_Event &
176
+ DOMUtils_FormEvent &
177
+ DOMUtils_ClipboardEvent &
178
+ DOMUtils_PrintEvent &
179
+ DOMUtils_DragEvent &
180
+ DOMUtils_MediaEvent &
181
+ DOMUtils_AnimationEvent &
182
+ DOMUtils_TransitionEvent &
183
+ DOMUtils_TouchEvent &
184
+ DOMUtils_OtherEvent;
185
+
186
+ /**
187
+ * 事件类型
188
+ */
189
+ export declare type DOMUtils_EventType = keyof DOMUtils_Event;