@whitesev/utils 2.0.1 → 2.1.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 +183 -173
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +183 -173
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +183 -173
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +183 -173
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +183 -173
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +183 -173
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +5 -4
- package/dist/types/src/UtilsGMCookie.d.ts +6 -0
- package/dist/types/src/UtilsWindowApi.d.ts +22 -0
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +2 -1
- package/src/Httpx.ts +3 -5
- package/src/Log.ts +1 -2
- package/src/Progress.ts +4 -10
- package/src/Utils.ts +139 -111
- package/src/UtilsCommon.ts +2 -4
- package/src/UtilsGMCookie.ts +29 -16
- package/src/UtilsGMMenu.ts +1 -2
- package/src/UtilsWindowApi.ts +44 -0
- package/src/indexedDB.ts +4 -6
- package/src/types/global.d.ts +1 -0
- package/dist/types/src/UtilsCore.d.ts +0 -16
- package/src/UtilsCore.ts +0 -47
|
@@ -10,9 +10,9 @@ import { Log } from "./Log";
|
|
|
10
10
|
import { Progress } from "./Progress";
|
|
11
11
|
import { UtilsDictionary } from "./Dictionary";
|
|
12
12
|
import type { DOMUtils_EventType } from "./Event";
|
|
13
|
-
import type { UtilsCoreOption } from "./UtilsCore";
|
|
14
13
|
import type { Vue2Object } from "./VueObject";
|
|
15
14
|
import type { UtilsAjaxHookResult } from "./AjaxHookerType";
|
|
15
|
+
import { type UtilsWindowApiOption } from "./UtilsWindowApi";
|
|
16
16
|
export declare var unsafeWindow: Window & typeof globalThis;
|
|
17
17
|
export type JSTypeMap = {
|
|
18
18
|
string: string;
|
|
@@ -38,7 +38,8 @@ export declare interface AnyObject {
|
|
|
38
38
|
export declare interface Vue2Context extends Vue2Object {
|
|
39
39
|
}
|
|
40
40
|
declare class Utils {
|
|
41
|
-
|
|
41
|
+
private windowApi;
|
|
42
|
+
constructor(option?: UtilsWindowApiOption);
|
|
42
43
|
/** 版本号 */
|
|
43
44
|
version: string;
|
|
44
45
|
/**
|
|
@@ -1099,7 +1100,7 @@ declare class Utils {
|
|
|
1099
1100
|
* let utils = Utils.noConflict();
|
|
1100
1101
|
* > ...
|
|
1101
1102
|
*/
|
|
1102
|
-
noConflict
|
|
1103
|
+
noConflict(): Utils;
|
|
1103
1104
|
/**
|
|
1104
1105
|
* 恢复/释放该对象内的为function,让它无效/有效
|
|
1105
1106
|
* @param needReleaseObject 需要操作的对象
|
|
@@ -1730,7 +1731,7 @@ declare class Utils {
|
|
|
1730
1731
|
* @param option
|
|
1731
1732
|
* @returns
|
|
1732
1733
|
*/
|
|
1733
|
-
createUtils(option?:
|
|
1734
|
+
createUtils(option?: UtilsWindowApiOption): Utils;
|
|
1734
1735
|
/**
|
|
1735
1736
|
* 将对象转换为FormData
|
|
1736
1737
|
* @param data 待转换的对象
|
|
@@ -45,7 +45,13 @@ declare interface UtilsGMCookieDeleteOptions {
|
|
|
45
45
|
/** 需要检索的Cookie的名字 */
|
|
46
46
|
name: string;
|
|
47
47
|
}
|
|
48
|
+
interface WindowApiOption {
|
|
49
|
+
window: Window & typeof globalThis;
|
|
50
|
+
document: Document;
|
|
51
|
+
}
|
|
48
52
|
declare class UtilsGMCookie {
|
|
53
|
+
private windowApi;
|
|
54
|
+
constructor(windowApiOption?: WindowApiOption);
|
|
49
55
|
/**
|
|
50
56
|
* 获取单个cookie
|
|
51
57
|
* @param cookieName cookie名
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
};
|
|
11
|
+
export declare class UtilsWindowApi {
|
|
12
|
+
/** 默认的配置 */
|
|
13
|
+
private defaultApi;
|
|
14
|
+
/** 使用的配置 */
|
|
15
|
+
private api;
|
|
16
|
+
constructor(option?: UtilsWindowApiOption);
|
|
17
|
+
get document(): Document;
|
|
18
|
+
get window(): Window & typeof globalThis;
|
|
19
|
+
get globalThis(): typeof globalThis | Window;
|
|
20
|
+
get self(): Window & typeof globalThis;
|
|
21
|
+
get top(): Window;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare var GM_xmlhttpRequest: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whitesev/utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "一个常用的工具库",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"jsdelivr": "dist/index.umd.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
"./package.json": "./package.json",
|
|
11
|
+
"./dist/*": "./dist/*",
|
|
11
12
|
".": {
|
|
12
13
|
"import": "./dist/index.esm.js",
|
|
13
14
|
"require": "./dist/index.cjs.js",
|
package/src/Httpx.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AnyObject, Utils } from "./Utils";
|
|
2
2
|
import { GenerateUUID } from "./UtilsCommon";
|
|
3
|
-
import { UtilsCore } from "./UtilsCore";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* 状态码
|
|
@@ -1681,12 +1680,11 @@ class Httpx {
|
|
|
1681
1680
|
new URL(details.url);
|
|
1682
1681
|
} catch (error) {
|
|
1683
1682
|
if (details.url.startsWith("//")) {
|
|
1684
|
-
details.url =
|
|
1683
|
+
details.url = window.location.protocol + details.url;
|
|
1685
1684
|
} else if (details.url.startsWith("/")) {
|
|
1686
|
-
details.url =
|
|
1685
|
+
details.url = window.location.origin + details.url;
|
|
1687
1686
|
} else {
|
|
1688
|
-
details.url =
|
|
1689
|
-
UtilsCore.globalThis.location.origin + "/" + details.url;
|
|
1687
|
+
details.url = window.location.origin + "/" + details.url;
|
|
1690
1688
|
}
|
|
1691
1689
|
}
|
|
1692
1690
|
return details;
|
package/src/Log.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AnyObject } from "./Utils";
|
|
2
|
-
import { UtilsCore } from "./UtilsCore";
|
|
3
2
|
|
|
4
3
|
/** Utils.Log的初始化配置 */
|
|
5
4
|
declare interface UtilsLogOptions {
|
|
@@ -59,7 +58,7 @@ class Log {
|
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
| string,
|
|
62
|
-
console: Console =
|
|
61
|
+
console: Console = window.console
|
|
63
62
|
) {
|
|
64
63
|
if (typeof _GM_info_ === "string") {
|
|
65
64
|
this.tag = _GM_info_;
|
package/src/Progress.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Utils } from "./Utils";
|
|
2
|
-
import { UtilsCore } from "./UtilsCore";
|
|
3
2
|
|
|
4
3
|
declare interface ProgressParamConfig {
|
|
5
4
|
/** canvas元素节点 */
|
|
@@ -91,17 +90,12 @@ class Progress {
|
|
|
91
90
|
/* 元素高度 */
|
|
92
91
|
this.#height = this.#config.canvasNode.height;
|
|
93
92
|
/* 清除锯齿 */
|
|
94
|
-
if (
|
|
93
|
+
if (window.devicePixelRatio) {
|
|
95
94
|
this.#config.canvasNode.style.width = this.#width + "px";
|
|
96
95
|
this.#config.canvasNode.style.height = this.#height + "px";
|
|
97
|
-
this.#config.canvasNode.height =
|
|
98
|
-
|
|
99
|
-
this.#
|
|
100
|
-
this.#width * UtilsCore.window.devicePixelRatio;
|
|
101
|
-
this.#ctx.scale(
|
|
102
|
-
UtilsCore.window.devicePixelRatio,
|
|
103
|
-
UtilsCore.window.devicePixelRatio
|
|
104
|
-
);
|
|
96
|
+
this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
|
|
97
|
+
this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
|
|
98
|
+
this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
105
99
|
}
|
|
106
100
|
/* 设置线宽 */
|
|
107
101
|
this.#ctx.lineWidth = this.#config.lineWidth;
|