@whitesev/utils 2.3.7 → 2.4.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.
- package/dist/index.amd.js +415 -289
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +415 -289
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +415 -289
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +415 -289
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +415 -289
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +415 -289
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +25 -1178
- package/dist/types/src/Log.d.ts +1 -19
- package/dist/types/src/Progress.d.ts +1 -20
- package/dist/types/src/TryCatch.d.ts +2 -11
- package/dist/types/src/Utils.d.ts +8 -32
- package/dist/types/src/UtilsGMCookie.d.ts +1 -51
- package/dist/types/src/UtilsGMMenu.d.ts +1 -50
- package/dist/types/src/WindowApi.d.ts +3 -11
- package/dist/types/src/types/Httpx.d.ts +1316 -0
- package/dist/types/src/types/Log.d.ts +19 -0
- package/dist/types/src/types/Progress.d.ts +20 -0
- package/dist/types/src/types/TryCatch.d.ts +9 -0
- package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
- package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
- package/dist/types/src/types/Vue3.d.ts +0 -0
- package/dist/types/src/types/WindowApi.d.ts +10 -0
- package/dist/types/src/types/global.d.ts +24 -1
- package/package.json +1 -1
- package/src/GBKEncoder.ts +1 -1
- package/src/Httpx.ts +535 -1627
- package/src/Log.ts +1 -19
- package/src/Progress.ts +1 -20
- package/src/TryCatch.ts +2 -12
- package/src/Utils.ts +44 -66
- package/src/UtilsGMCookie.ts +7 -56
- package/src/UtilsGMMenu.ts +5 -78
- package/src/WindowApi.ts +4 -11
- package/src/indexedDB.ts +12 -10
- package/src/types/Event.d.ts +189 -0
- package/src/types/Httpx.d.ts +1316 -0
- package/src/types/Log.d.ts +19 -0
- package/src/types/Progress.d.ts +20 -0
- package/src/types/TryCatch.d.ts +9 -0
- package/src/types/UtilsGMCookie.d.ts +55 -0
- package/src/types/UtilsGMMenu.d.ts +77 -0
- package/src/types/Vue2.d.ts +154 -0
- package/src/types/Vue3.d.ts +0 -0
- package/src/types/WindowApi.d.ts +10 -0
- package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
- package/src/types/global.d.ts +24 -1
- package/dist/types/src/Event.d.ts +0 -156
- package/dist/types/src/VueObject.d.ts +0 -123
- /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
- /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
package/src/Log.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
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 {
|
|
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
|
|
17
|
+
import { WindowApi } from "./WindowApi";
|
|
19
18
|
import { Vue } from "./Vue";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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.
|
|
32
|
+
version = "2024.10.28";
|
|
57
33
|
|
|
58
34
|
/**
|
|
59
35
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
@@ -291,37 +267,38 @@ class Utils {
|
|
|
291
267
|
"Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型"
|
|
292
268
|
);
|
|
293
269
|
}
|
|
294
|
-
let
|
|
295
|
-
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
270
|
+
let clickEvent = UtilsContext.windowApi.window.event as PointerEvent;
|
|
271
|
+
let touchEvent = UtilsContext.windowApi.window.event as TouchEvent;
|
|
272
|
+
let $click = clickEvent?.composedPath()?.[0] as HTMLElement;
|
|
273
|
+
|
|
274
|
+
// 点击的x坐标
|
|
275
|
+
let clickPosX =
|
|
276
|
+
clickEvent?.clientX != null
|
|
277
|
+
? clickEvent.clientX
|
|
278
|
+
: touchEvent.touches[0].clientX;
|
|
279
|
+
// 点击的y坐标
|
|
280
|
+
let clickPosY =
|
|
281
|
+
clickEvent?.clientY != null
|
|
282
|
+
? clickEvent.clientY
|
|
283
|
+
: touchEvent.touches[0].clientY;
|
|
284
|
+
let {
|
|
285
|
+
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
286
|
+
left: elementPosXLeft,
|
|
287
|
+
/* 要检测的元素的相对屏幕的横坐标最右边 */
|
|
288
|
+
right: elementPosXRight,
|
|
289
|
+
/* 要检测的元素的相对屏幕的纵坐标最上边 */
|
|
290
|
+
top: elementPosYTop,
|
|
291
|
+
/* 要检测的元素的相对屏幕的纵坐标最下边 */
|
|
292
|
+
bottom: elementPosYBottom,
|
|
293
|
+
} = (element as HTMLElement).getBoundingClientRect();
|
|
314
294
|
if (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
295
|
+
clickPosX >= elementPosXLeft &&
|
|
296
|
+
clickPosX <= elementPosXRight &&
|
|
297
|
+
clickPosY >= elementPosYTop &&
|
|
298
|
+
clickPosY <= elementPosYBottom
|
|
319
299
|
) {
|
|
320
300
|
return true;
|
|
321
|
-
} else if (
|
|
322
|
-
clickNodeHTML &&
|
|
323
|
-
(element as HTMLElement).innerHTML.includes(clickNodeHTML)
|
|
324
|
-
) {
|
|
301
|
+
} else if (($click && element.contains($click)) || $click == element) {
|
|
325
302
|
/* 这种情况是应对在界面中隐藏的元素,getBoundingClientRect获取的都是0 */
|
|
326
303
|
return true;
|
|
327
304
|
} else {
|
|
@@ -503,7 +480,7 @@ class Utils {
|
|
|
503
480
|
dispatchEvent(
|
|
504
481
|
element: HTMLElement | Document,
|
|
505
482
|
eventName: DOMUtils_EventType | DOMUtils_EventType[],
|
|
506
|
-
details?:
|
|
483
|
+
details?: any
|
|
507
484
|
): void;
|
|
508
485
|
/**
|
|
509
486
|
* 主动触发事件
|
|
@@ -518,12 +495,12 @@ class Utils {
|
|
|
518
495
|
dispatchEvent(
|
|
519
496
|
element: HTMLElement | Document,
|
|
520
497
|
eventName: string,
|
|
521
|
-
details?:
|
|
498
|
+
details?: any
|
|
522
499
|
): void;
|
|
523
500
|
dispatchEvent(
|
|
524
501
|
element: HTMLElement | Document,
|
|
525
502
|
eventName: DOMUtils_EventType | DOMUtils_EventType[] | string,
|
|
526
|
-
details?:
|
|
503
|
+
details?: any
|
|
527
504
|
) {
|
|
528
505
|
let eventNameList: string[] = [];
|
|
529
506
|
if (typeof eventName === "string") {
|
|
@@ -3509,7 +3486,8 @@ class Utils {
|
|
|
3509
3486
|
offSetX: number,
|
|
3510
3487
|
offSetY: number
|
|
3511
3488
|
) {
|
|
3512
|
-
|
|
3489
|
+
// @ts-ignore
|
|
3490
|
+
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
3513
3491
|
let mouseEvent =
|
|
3514
3492
|
UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
3515
3493
|
mouseEvent.initMouseEvent(
|
package/src/UtilsGMCookie.ts
CHANGED
|
@@ -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,
|
package/src/UtilsGMMenu.ts
CHANGED
|
@@ -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
|
-
|
|
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 };
|
package/src/indexedDB.ts
CHANGED
|
@@ -35,6 +35,10 @@ class indexedDB {
|
|
|
35
35
|
code: 401,
|
|
36
36
|
msg: "操作失败",
|
|
37
37
|
},
|
|
38
|
+
empty: {
|
|
39
|
+
code: 201,
|
|
40
|
+
msg: "操作成功,但是没有数据",
|
|
41
|
+
},
|
|
38
42
|
openFailed: { code: 91001, msg: "打开数据库失败" },
|
|
39
43
|
saveFailed: { code: 91002, msg: "保存数据失败" },
|
|
40
44
|
getFailed: { code: 91003, msg: "获取数据失败" },
|
|
@@ -287,23 +291,21 @@ class indexedDB {
|
|
|
287
291
|
/* result 返回的是 {key: string, value: any} */
|
|
288
292
|
/* 键值对存储 */
|
|
289
293
|
let data = result ? result.value : void 0;
|
|
290
|
-
if (data) {
|
|
294
|
+
if (data == null) {
|
|
291
295
|
resolve({
|
|
292
296
|
success: true,
|
|
293
|
-
code: that.#statusCode.
|
|
294
|
-
msg: that.#statusCode.
|
|
295
|
-
data: data
|
|
296
|
-
|
|
297
|
+
code: that.#statusCode.empty.code,
|
|
298
|
+
msg: that.#statusCode.empty.msg,
|
|
299
|
+
data: data!,
|
|
297
300
|
event: event,
|
|
298
301
|
result: result,
|
|
299
302
|
});
|
|
300
303
|
} else {
|
|
301
304
|
resolve({
|
|
302
|
-
success:
|
|
303
|
-
code: that.#statusCode.
|
|
304
|
-
msg: that.#statusCode.
|
|
305
|
-
data:
|
|
306
|
-
|
|
305
|
+
success: true,
|
|
306
|
+
code: that.#statusCode.operationSuccess.code,
|
|
307
|
+
msg: that.#statusCode.operationSuccess.msg,
|
|
308
|
+
data: data,
|
|
307
309
|
event: event,
|
|
308
310
|
result: result,
|
|
309
311
|
});
|
|
@@ -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;
|