@whitesev/utils 1.1.8 → 1.2.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 +19 -13
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +19 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +19 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +19 -13
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +19 -13
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +19 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/src/ColorConversion.d.ts +2 -2
- package/dist/src/Utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/ColorConversion.ts +27 -20
- package/src/Utils.ts +6 -2
- package/src/ajaxHooker/index.d.ts +1 -1
|
@@ -17,7 +17,7 @@ declare class ColorConversion {
|
|
|
17
17
|
* @param str
|
|
18
18
|
* @returns
|
|
19
19
|
*/
|
|
20
|
-
hexToRgb(str: string): RegExpMatchArray;
|
|
20
|
+
hexToRgb(str: string): RegExpMatchArray | null;
|
|
21
21
|
/**
|
|
22
22
|
* rgb转hex
|
|
23
23
|
* @param redValue
|
|
@@ -32,7 +32,7 @@ declare class ColorConversion {
|
|
|
32
32
|
* @param level 0~1.0
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
35
|
-
getDarkColor(color: string, level:
|
|
35
|
+
getDarkColor(color: string, level: string): string;
|
|
36
36
|
/**
|
|
37
37
|
* 获取颜色变亮
|
|
38
38
|
* @param color 颜色
|
package/dist/src/Utils.d.ts
CHANGED
|
@@ -1584,7 +1584,7 @@ declare class Utils {
|
|
|
1584
1584
|
* "__vue__"
|
|
1585
1585
|
* )
|
|
1586
1586
|
*/
|
|
1587
|
-
waitVueByInterval(element: HTMLElement | (() =>
|
|
1587
|
+
waitVueByInterval(element: HTMLElement | (() => any), propertyName: string | ((__vue__: any) => boolean), timer?: number, maxTime?: number, vueName?: "__vue__" | string): Promise<boolean>;
|
|
1588
1588
|
/**
|
|
1589
1589
|
* 观察对象的set、get
|
|
1590
1590
|
* @param target 观察的对象
|
package/package.json
CHANGED
package/src/ColorConversion.ts
CHANGED
|
@@ -3,7 +3,7 @@ class ColorConversion {
|
|
|
3
3
|
* 判断是否是16进制颜色
|
|
4
4
|
* @param str
|
|
5
5
|
*/
|
|
6
|
-
isHex(str: string) {
|
|
6
|
+
isHex(str: string): boolean {
|
|
7
7
|
if (typeof str !== "string") {
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
@@ -19,9 +19,10 @@ class ColorConversion {
|
|
|
19
19
|
* @param hex
|
|
20
20
|
* @param opacity
|
|
21
21
|
*/
|
|
22
|
-
hexToRgba(hex: string, opacity: number) {
|
|
22
|
+
hexToRgba(hex: string, opacity: number): string {
|
|
23
23
|
if (!this.isHex(hex)) {
|
|
24
|
-
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
throw new TypeError("输入错误的hex", hex);
|
|
25
26
|
}
|
|
26
27
|
return hex && hex.replace(/\s+/g, "").length === 7
|
|
27
28
|
? "rgba(" +
|
|
@@ -42,17 +43,18 @@ class ColorConversion {
|
|
|
42
43
|
*/
|
|
43
44
|
hexToRgb(str: string) {
|
|
44
45
|
if (!this.isHex(str)) {
|
|
45
|
-
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
throw new TypeError("输入错误的hex", str);
|
|
46
48
|
}
|
|
47
49
|
/* replace替换查找的到的字符串 */
|
|
48
50
|
str = str.replace("#", "");
|
|
49
51
|
/* match得到查询数组 */
|
|
50
52
|
let hxs = str.match(/../g);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
for (let index = 0; index < 3; index++) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
hxs[index] = parseInt(hxs[index], 16);
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
hxs[index] = parseInt(hxs[index], 16).toString();
|
|
57
|
+
|
|
56
58
|
return hxs;
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
@@ -66,7 +68,7 @@ class ColorConversion {
|
|
|
66
68
|
redValue: string | number,
|
|
67
69
|
greenValue: string | number,
|
|
68
70
|
blueValue: string | number
|
|
69
|
-
) {
|
|
71
|
+
): string {
|
|
70
72
|
/* 验证输入的rgb值是否合法 */
|
|
71
73
|
let validPattern = /^\d{1,3}$/;
|
|
72
74
|
if (
|
|
@@ -90,14 +92,18 @@ class ColorConversion {
|
|
|
90
92
|
* @param level 0~1.0
|
|
91
93
|
* @returns
|
|
92
94
|
*/
|
|
93
|
-
getDarkColor(color: string, level:
|
|
95
|
+
getDarkColor(color: string, level: string): string {
|
|
94
96
|
if (!this.isHex(color)) {
|
|
95
|
-
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
throw new TypeError("输入错误的hex", color);
|
|
96
99
|
}
|
|
97
100
|
let rgbc = this.hexToRgb(color);
|
|
98
|
-
for (let index = 0; index < 3; index++)
|
|
101
|
+
for (let index = 0; index < 3; index++) {
|
|
99
102
|
// @ts-ignore
|
|
100
|
-
rgbc[index] = Math.floor(rgbc[index] * (1 - level))
|
|
103
|
+
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// @ts-ignore
|
|
101
107
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
102
108
|
}
|
|
103
109
|
/**
|
|
@@ -106,16 +112,17 @@ class ColorConversion {
|
|
|
106
112
|
* @param level 0~1.0
|
|
107
113
|
* @returns
|
|
108
114
|
*/
|
|
109
|
-
getLightColor(color: string, level: number) {
|
|
115
|
+
getLightColor(color: string, level: number): string {
|
|
110
116
|
if (!this.isHex(color)) {
|
|
111
|
-
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
throw new TypeError("输入错误的hex", color);
|
|
112
119
|
}
|
|
113
120
|
let rgbc = this.hexToRgb(color);
|
|
114
|
-
for (let index = 0; index < 3; index++)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
for (let index = 0; index < 3; index++) {
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
124
|
+
}
|
|
125
|
+
// @ts-ignore
|
|
119
126
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
120
127
|
}
|
|
121
128
|
}
|
package/src/Utils.ts
CHANGED
|
@@ -4407,14 +4407,18 @@ class Utils {
|
|
|
4407
4407
|
* )
|
|
4408
4408
|
*/
|
|
4409
4409
|
waitVueByInterval(
|
|
4410
|
-
element:
|
|
4410
|
+
element:
|
|
4411
|
+
| HTMLElement
|
|
4412
|
+
| (() => any),
|
|
4411
4413
|
propertyName: string | ((__vue__: any) => boolean),
|
|
4412
4414
|
timer?: number,
|
|
4413
4415
|
maxTime?: number,
|
|
4414
4416
|
vueName?: "__vue__" | string
|
|
4415
4417
|
): Promise<boolean>;
|
|
4416
4418
|
async waitVueByInterval(
|
|
4417
|
-
element:
|
|
4419
|
+
element:
|
|
4420
|
+
| HTMLElement
|
|
4421
|
+
| (() => any),
|
|
4418
4422
|
propertyName: string | ((__vue__: any) => boolean),
|
|
4419
4423
|
timer = 250,
|
|
4420
4424
|
maxTime = -1,
|
|
@@ -57,7 +57,7 @@ declare interface UtilsAjaxHookRequestOptions {
|
|
|
57
57
|
*
|
|
58
58
|
* 在控制台输出时,xhr响应将包含所有属性,但只有被读取过的属性具有明确的值。修改对应属性即可影响读取结果,进而实现响应数据的修改。
|
|
59
59
|
*/
|
|
60
|
-
response?: (res: UtilsAjaxHookResponseOptions) => void;
|
|
60
|
+
response?: (res: Required<UtilsAjaxHookResponseOptions>) => void;
|
|
61
61
|
/**
|
|
62
62
|
* 只读属性。异步请求为true,同步请求为false,异步特性无法作用于同步请求
|
|
63
63
|
*/
|