@whitesev/utils 2.7.1 → 2.7.2
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 +168 -212
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +168 -212
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +168 -212
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +168 -212
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +168 -212
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +168 -212
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/ColorConversion.d.ts +3 -8
- package/dist/types/src/Dictionary.d.ts +21 -14
- package/dist/types/src/GBKEncoder.d.ts +1 -2
- package/dist/types/src/Hooks.d.ts +1 -2
- package/dist/types/src/Httpx.d.ts +45 -46
- package/dist/types/src/LockFunction.d.ts +1 -2
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Progress.d.ts +1 -2
- package/dist/types/src/UtilsGMMenu.d.ts +1 -2
- package/dist/types/src/WindowApi.d.ts +1 -2
- package/dist/types/src/indexedDB.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +73 -67
- package/dist/types/src/types/env.d.ts +2 -0
- package/dist/types/src/types/global.d.ts +3 -0
- package/package.json +1 -1
- package/src/ColorConversion.ts +14 -25
- package/src/DOMUtils.ts +14 -16
- package/src/Dictionary.ts +39 -35
- package/src/GBKEncoder.ts +8 -12
- package/src/Hooks.ts +1 -3
- package/src/Httpx.ts +194 -174
- package/src/LockFunction.ts +3 -3
- package/src/Log.ts +1 -3
- package/src/Progress.ts +1 -3
- package/src/TryCatch.ts +4 -4
- package/src/Utils.ts +27 -43
- package/src/UtilsGMMenu.ts +19 -22
- package/src/Vue.ts +4 -7
- package/src/WindowApi.ts +2 -5
- package/src/indexedDB.ts +8 -8
- package/src/types/Httpx.d.ts +73 -67
- package/src/types/env.d.ts +2 -0
- package/src/types/global.d.ts +3 -0
package/src/LockFunction.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
class LockFunction<
|
|
1
|
+
export class LockFunction<
|
|
2
|
+
K extends (...args: any[]) => any | Promise<any> | void
|
|
3
|
+
> {
|
|
2
4
|
#flag: boolean = false;
|
|
3
5
|
#delayTime: number = 0;
|
|
4
6
|
#callback: K;
|
|
@@ -60,5 +62,3 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
|
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
export { LockFunction };
|
package/src/Log.ts
CHANGED
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元素节点
|
|
@@ -120,5 +120,3 @@ class Progress {
|
|
|
120
120
|
this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
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
|
-
|
|
28
|
-
handleError = handler;
|
|
27
|
+
handleError = handler as (error: Error) => void;
|
|
29
28
|
return TryCatchCore;
|
|
30
29
|
},
|
|
31
30
|
/**
|
|
@@ -42,8 +41,9 @@ export const TryCatch = function (...args: any) {
|
|
|
42
41
|
callbackFunction = callback;
|
|
43
42
|
context = __context__ || this;
|
|
44
43
|
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
return result !== void 0
|
|
45
|
+
? result
|
|
46
|
+
: (TryCatchCore as any as UtilsTryCatchType);
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
|
package/src/Utils.ts
CHANGED
|
@@ -177,7 +177,7 @@ class Utils {
|
|
|
177
177
|
canvasElement: HTMLCanvasElement,
|
|
178
178
|
clientX = 0,
|
|
179
179
|
clientY = 0,
|
|
180
|
-
view =
|
|
180
|
+
view = this.windowApi.window
|
|
181
181
|
) {
|
|
182
182
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
183
183
|
throw new Error(
|
|
@@ -186,12 +186,13 @@ class Utils {
|
|
|
186
186
|
}
|
|
187
187
|
clientX = parseInt(clientX.toString());
|
|
188
188
|
clientY = parseInt(clientY.toString());
|
|
189
|
-
const eventInit: MouseEventInit
|
|
189
|
+
const eventInit: MouseEventInit & {
|
|
190
|
+
cancelBubble: boolean;
|
|
191
|
+
} = {
|
|
190
192
|
cancelBubble: true,
|
|
191
193
|
cancelable: true,
|
|
192
194
|
clientX: clientX,
|
|
193
195
|
clientY: clientY,
|
|
194
|
-
// @ts-ignore
|
|
195
196
|
view: view,
|
|
196
197
|
detail: 1,
|
|
197
198
|
};
|
|
@@ -1064,10 +1065,8 @@ class Utils {
|
|
|
1064
1065
|
getElementSelector(element: HTMLElement): string;
|
|
1065
1066
|
getElementSelector(element: HTMLElement): string {
|
|
1066
1067
|
let UtilsContext = this;
|
|
1067
|
-
|
|
1068
|
-
if (!element) return;
|
|
1069
|
-
// @ts-ignore
|
|
1070
|
-
if (!element.parentElement) return;
|
|
1068
|
+
if (!element) return void 0 as any as string;
|
|
1069
|
+
if (!element.parentElement) return void 0 as any as string;
|
|
1071
1070
|
/* 如果元素有id属性,则直接返回id选择器 */
|
|
1072
1071
|
if (element.id) return "#" + element.id;
|
|
1073
1072
|
|
|
@@ -1122,8 +1121,7 @@ class Utils {
|
|
|
1122
1121
|
let result = [...args];
|
|
1123
1122
|
let newResult: number[] = [];
|
|
1124
1123
|
if (result.length === 0) {
|
|
1125
|
-
|
|
1126
|
-
return;
|
|
1124
|
+
return void 0 as any as number;
|
|
1127
1125
|
}
|
|
1128
1126
|
if (result.length > 1) {
|
|
1129
1127
|
if (
|
|
@@ -1194,8 +1192,7 @@ class Utils {
|
|
|
1194
1192
|
// 当前页面最大的z-index
|
|
1195
1193
|
let zIndex = 0;
|
|
1196
1194
|
// 当前的最大z-index的元素,调试使用
|
|
1197
|
-
|
|
1198
|
-
let maxZIndexNode: Element = null;
|
|
1195
|
+
let maxZIndexNode: Element | null = null;
|
|
1199
1196
|
/**
|
|
1200
1197
|
* 元素是否可见
|
|
1201
1198
|
* @param $css
|
|
@@ -1244,7 +1241,7 @@ class Utils {
|
|
|
1244
1241
|
zIndex = maxZIndexCompare;
|
|
1245
1242
|
}
|
|
1246
1243
|
return {
|
|
1247
|
-
node: maxZIndexNode
|
|
1244
|
+
node: maxZIndexNode!,
|
|
1248
1245
|
zIndex: zIndex,
|
|
1249
1246
|
};
|
|
1250
1247
|
}
|
|
@@ -1311,8 +1308,7 @@ class Utils {
|
|
|
1311
1308
|
let result = [...args];
|
|
1312
1309
|
let newResult: number[] = [];
|
|
1313
1310
|
if (result.length === 0) {
|
|
1314
|
-
|
|
1315
|
-
return;
|
|
1311
|
+
return void 0 as any as number;
|
|
1316
1312
|
}
|
|
1317
1313
|
if (result.length > 1) {
|
|
1318
1314
|
if (
|
|
@@ -1905,7 +1901,6 @@ class Utils {
|
|
|
1905
1901
|
isJQuery(target: any): boolean;
|
|
1906
1902
|
isJQuery(target: any): boolean {
|
|
1907
1903
|
let result = false;
|
|
1908
|
-
// @ts-ignore
|
|
1909
1904
|
if (typeof jQuery === "object" && target instanceof jQuery) {
|
|
1910
1905
|
result = true;
|
|
1911
1906
|
}
|
|
@@ -3060,31 +3055,27 @@ class Utils {
|
|
|
3060
3055
|
const originalListener = EventTarget.prototype.addEventListener;
|
|
3061
3056
|
EventTarget.prototype.addEventListener = function (...args) {
|
|
3062
3057
|
let type = args[0];
|
|
3063
|
-
let callback = args[1];
|
|
3064
|
-
//
|
|
3065
|
-
let options = args[2];
|
|
3058
|
+
let callback: any = args[1];
|
|
3059
|
+
// let options = args[2];
|
|
3066
3060
|
if (filter(type)) {
|
|
3067
3061
|
if (typeof callback === "function") {
|
|
3068
3062
|
args[1] = function (event) {
|
|
3069
3063
|
callback.call(this, trustEvent(event));
|
|
3070
3064
|
};
|
|
3071
|
-
} else if (
|
|
3072
|
-
|
|
3073
|
-
"handleEvent" in (callback as any)
|
|
3074
|
-
) {
|
|
3075
|
-
let oldHandleEvent = (callback as any)["handleEvent"];
|
|
3065
|
+
} else if (typeof callback === "object" && "handleEvent" in callback) {
|
|
3066
|
+
let oldHandleEvent = callback["handleEvent"];
|
|
3076
3067
|
|
|
3077
3068
|
(args[1] as any)["handleEvent"] = function (event: Event) {
|
|
3078
3069
|
if (event == null) {
|
|
3079
3070
|
return;
|
|
3080
3071
|
}
|
|
3081
3072
|
try {
|
|
3082
|
-
|
|
3073
|
+
// Proxy对象使用instanceof会报错
|
|
3074
|
+
// 这里故意尝试一下,如果报错,则说明是Proxy对象
|
|
3083
3075
|
event instanceof Proxy;
|
|
3084
3076
|
oldHandleEvent.call(this, trustEvent(event));
|
|
3085
3077
|
} catch (error) {
|
|
3086
|
-
|
|
3087
|
-
event["isTrusted"] = isTrustValue;
|
|
3078
|
+
Reflect.set(event, "isTrusted", isTrustValue);
|
|
3088
3079
|
}
|
|
3089
3080
|
};
|
|
3090
3081
|
}
|
|
@@ -3226,8 +3217,8 @@ class Utils {
|
|
|
3226
3217
|
}
|
|
3227
3218
|
async init() {
|
|
3228
3219
|
let copyStatus = false;
|
|
3229
|
-
// @ts-ignore
|
|
3230
3220
|
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
3221
|
+
console.log(requestPermissionStatus);
|
|
3231
3222
|
if (
|
|
3232
3223
|
this.hasClipboard() &&
|
|
3233
3224
|
(this.hasClipboardWrite() || this.hasClipboardWriteText())
|
|
@@ -3245,12 +3236,9 @@ class Utils {
|
|
|
3245
3236
|
this.destroy();
|
|
3246
3237
|
}
|
|
3247
3238
|
destroy() {
|
|
3248
|
-
|
|
3249
|
-
this.#resolve = null;
|
|
3250
|
-
// @ts-ignore
|
|
3239
|
+
this.#resolve = null as any;
|
|
3251
3240
|
this.#copyData = null;
|
|
3252
|
-
|
|
3253
|
-
this.#copyDataType = null;
|
|
3241
|
+
this.#copyDataType = null as any;
|
|
3254
3242
|
}
|
|
3255
3243
|
isText() {
|
|
3256
3244
|
return this.#copyDataType.includes("text");
|
|
@@ -3293,8 +3281,7 @@ class Utils {
|
|
|
3293
3281
|
if (navigator.permissions && navigator.permissions.query) {
|
|
3294
3282
|
navigator.permissions
|
|
3295
3283
|
.query({
|
|
3296
|
-
|
|
3297
|
-
name: "clipboard-write",
|
|
3284
|
+
name: "clipboard-write" as any as PermissionName,
|
|
3298
3285
|
})
|
|
3299
3286
|
.then((permissionStatus) => {
|
|
3300
3287
|
resolve(true);
|
|
@@ -3431,7 +3418,6 @@ class Utils {
|
|
|
3431
3418
|
offSetX: number,
|
|
3432
3419
|
offSetY: number
|
|
3433
3420
|
) {
|
|
3434
|
-
// @ts-ignore
|
|
3435
3421
|
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
3436
3422
|
let mouseEvent =
|
|
3437
3423
|
UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
@@ -3439,7 +3425,7 @@ class Utils {
|
|
|
3439
3425
|
eventName,
|
|
3440
3426
|
true,
|
|
3441
3427
|
true,
|
|
3442
|
-
win,
|
|
3428
|
+
win as Window,
|
|
3443
3429
|
0,
|
|
3444
3430
|
offSetX,
|
|
3445
3431
|
offSetY,
|
|
@@ -3668,7 +3654,6 @@ class Utils {
|
|
|
3668
3654
|
flags: "g" | "i" | "m" | "u" | "y" | string = "ig"
|
|
3669
3655
|
): RegExp {
|
|
3670
3656
|
let reg;
|
|
3671
|
-
// @ts-ignore
|
|
3672
3657
|
flags = flags.toLowerCase();
|
|
3673
3658
|
if (typeof targetString === "string") {
|
|
3674
3659
|
reg = new RegExp(
|
|
@@ -3824,11 +3809,11 @@ class Utils {
|
|
|
3824
3809
|
searhParamsStr?: string | null | undefined
|
|
3825
3810
|
): T {
|
|
3826
3811
|
if (typeof searhParamsStr !== "string") {
|
|
3827
|
-
|
|
3828
|
-
return {};
|
|
3812
|
+
return {} as any as T;
|
|
3829
3813
|
}
|
|
3830
|
-
|
|
3831
|
-
|
|
3814
|
+
return Object.fromEntries(
|
|
3815
|
+
new URLSearchParams(searhParamsStr) as any
|
|
3816
|
+
) as any;
|
|
3832
3817
|
}
|
|
3833
3818
|
/**
|
|
3834
3819
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
@@ -5137,8 +5122,7 @@ class Utils {
|
|
|
5137
5122
|
function requestPermissionsWithClipboard() {
|
|
5138
5123
|
navigator.permissions
|
|
5139
5124
|
.query({
|
|
5140
|
-
|
|
5141
|
-
name: "clipboard-read",
|
|
5125
|
+
name: "clipboard-read" as any as PermissionName,
|
|
5142
5126
|
})
|
|
5143
5127
|
.then((permissionStatus) => {
|
|
5144
5128
|
readClipboardText();
|
package/src/UtilsGMMenu.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
UtilsGMMenuOptionData,
|
|
6
6
|
} from "./types/UtilsGMMenu";
|
|
7
7
|
|
|
8
|
-
class GMMenu {
|
|
8
|
+
export class GMMenu {
|
|
9
9
|
private GM_Api = {
|
|
10
10
|
/**
|
|
11
11
|
* 获取存储的数据
|
|
@@ -157,25 +157,24 @@ class GMMenu {
|
|
|
157
157
|
);
|
|
158
158
|
/** 油猴菜单上显示的文本 */
|
|
159
159
|
let showText = menuOption.showText(menuOption.text, defaultEnable);
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
160
|
+
// const GMMenuOptions = {
|
|
161
|
+
// /**
|
|
162
|
+
// * 菜单的id
|
|
163
|
+
// */
|
|
164
|
+
// id: menuOption.id,
|
|
165
|
+
// /**
|
|
166
|
+
// * 点击菜单项后是否应关闭弹出菜单
|
|
167
|
+
// */
|
|
168
|
+
// autoClose: menuOption.autoClose,
|
|
169
|
+
// /**
|
|
170
|
+
// * 菜单项的可选访问键
|
|
171
|
+
// */
|
|
172
|
+
// accessKey: menuOption.accessKey,
|
|
173
|
+
// /**
|
|
174
|
+
// * 菜单项的鼠标悬浮上的工具提示
|
|
175
|
+
// */
|
|
176
|
+
// title: menuOption.title,
|
|
177
|
+
// };
|
|
179
178
|
/* 点击菜单后触发callback后的网页是否刷新 */
|
|
180
179
|
menuOption.autoReload =
|
|
181
180
|
typeof menuOption.autoReload !== "boolean"
|
|
@@ -472,5 +471,3 @@ class GMMenu {
|
|
|
472
471
|
this.MenuHandle.$data.key = keyName;
|
|
473
472
|
}
|
|
474
473
|
}
|
|
475
|
-
|
|
476
|
-
export { GMMenu };
|
package/src/Vue.ts
CHANGED
|
@@ -37,11 +37,10 @@ class ReactiveEffect {
|
|
|
37
37
|
deps: any[] = [];
|
|
38
38
|
private active = true;
|
|
39
39
|
private fn;
|
|
40
|
-
//
|
|
41
|
-
private scheduler;
|
|
40
|
+
// private scheduler;
|
|
42
41
|
constructor(fn: Function, scheduler: any) {
|
|
43
42
|
this.fn = fn;
|
|
44
|
-
this.scheduler = scheduler;
|
|
43
|
+
// this.scheduler = scheduler;
|
|
45
44
|
}
|
|
46
45
|
run(cb: (activeEffect: any) => void) {
|
|
47
46
|
if (!this.active) {
|
|
@@ -107,8 +106,7 @@ export class Vue {
|
|
|
107
106
|
reactive<T extends object>(target: T): T {
|
|
108
107
|
const that = this;
|
|
109
108
|
if (!(typeof target === "object" && target !== null)) {
|
|
110
|
-
|
|
111
|
-
return;
|
|
109
|
+
return void 0 as any as T;
|
|
112
110
|
}
|
|
113
111
|
if (VueUtils.isReactive(target)) {
|
|
114
112
|
return target;
|
|
@@ -179,8 +177,7 @@ export class Vue {
|
|
|
179
177
|
toRefs(object: any) {
|
|
180
178
|
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
181
179
|
for (let key in object) {
|
|
182
|
-
|
|
183
|
-
result[key] = this.toRef(object, key);
|
|
180
|
+
(result as any)[key as any] = this.toRef(object, key);
|
|
184
181
|
}
|
|
185
182
|
return result;
|
|
186
183
|
}
|
package/src/WindowApi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
2
2
|
|
|
3
|
-
class WindowApi {
|
|
3
|
+
export class WindowApi {
|
|
4
4
|
/** 默认的配置 */
|
|
5
5
|
private defaultApi: Required<WindowApiOption> = {
|
|
6
6
|
document: document,
|
|
@@ -23,8 +23,7 @@ class WindowApi {
|
|
|
23
23
|
if (!option) {
|
|
24
24
|
option = Object.assign({}, this.defaultApi);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
this.api = Object.assign({}, option);
|
|
26
|
+
this.api = Object.assign({}, option as Required<WindowApiOption>);
|
|
28
27
|
}
|
|
29
28
|
get document() {
|
|
30
29
|
return this.api.document;
|
|
@@ -42,5 +41,3 @@ class WindowApi {
|
|
|
42
41
|
return this.api.top;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
export { WindowApi };
|
package/src/indexedDB.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* indexedDB 错误结果
|
|
3
|
+
*/
|
|
1
4
|
declare interface UtilsIDBOpenErrorResult {
|
|
2
5
|
code: number;
|
|
3
6
|
msg: string;
|
|
@@ -6,13 +9,13 @@ declare interface UtilsIDBOpenErrorResult {
|
|
|
6
9
|
target: IDBRequest;
|
|
7
10
|
} & Event;
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
export class indexedDB {
|
|
10
14
|
#dbName: string;
|
|
11
15
|
#storeName: string;
|
|
12
16
|
#dbVersion: number;
|
|
13
17
|
/* websql的版本号,由于ios的问题,版本号的写法不一样 */
|
|
14
|
-
//
|
|
15
|
-
#slqVersion = "1";
|
|
18
|
+
// #slqVersion = "1";
|
|
16
19
|
/* 监听IndexDB */
|
|
17
20
|
#indexedDB =
|
|
18
21
|
window.indexedDB ||
|
|
@@ -23,8 +26,7 @@ class indexedDB {
|
|
|
23
26
|
#db: {
|
|
24
27
|
[key: string]: IDBDatabase;
|
|
25
28
|
} = {};
|
|
26
|
-
//
|
|
27
|
-
#store: IDBObjectStore = null as any;
|
|
29
|
+
// #store: IDBObjectStore = null as any;
|
|
28
30
|
/** 状态码 */
|
|
29
31
|
#statusCode = {
|
|
30
32
|
operationSuccess: {
|
|
@@ -76,7 +78,7 @@ class indexedDB {
|
|
|
76
78
|
) as IDBTransaction;
|
|
77
79
|
/* IndexDB的读写权限 */
|
|
78
80
|
store = txn.objectStore(this.#storeName) as IDBObjectStore;
|
|
79
|
-
this.#store = store;
|
|
81
|
+
// this.#store = store;
|
|
80
82
|
return store;
|
|
81
83
|
}
|
|
82
84
|
/**
|
|
@@ -507,5 +509,3 @@ class indexedDB {
|
|
|
507
509
|
});
|
|
508
510
|
}
|
|
509
511
|
}
|
|
510
|
-
|
|
511
|
-
export { indexedDB };
|