@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
package/dist/index.umd.js
CHANGED
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
*/
|
|
28
28
|
hexToRgba(hex, opacity) {
|
|
29
29
|
if (!this.isHex(hex)) {
|
|
30
|
-
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
throw new TypeError("输入错误的hex", hex);
|
|
31
32
|
}
|
|
32
33
|
return hex && hex.replace(/\s+/g, "").length === 7
|
|
33
34
|
? "rgba(" +
|
|
@@ -48,17 +49,17 @@
|
|
|
48
49
|
*/
|
|
49
50
|
hexToRgb(str) {
|
|
50
51
|
if (!this.isHex(str)) {
|
|
51
|
-
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
throw new TypeError("输入错误的hex", str);
|
|
52
54
|
}
|
|
53
55
|
/* replace替换查找的到的字符串 */
|
|
54
56
|
str = str.replace("#", "");
|
|
55
57
|
/* match得到查询数组 */
|
|
56
58
|
let hxs = str.match(/../g);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
for (let index = 0; index < 3; index++) {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
hxs[index] = parseInt(hxs[index], 16);
|
|
59
62
|
}
|
|
60
|
-
for (let index = 0; index < 3; index++)
|
|
61
|
-
hxs[index] = parseInt(hxs[index], 16).toString();
|
|
62
63
|
return hxs;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
@@ -93,12 +94,15 @@
|
|
|
93
94
|
*/
|
|
94
95
|
getDarkColor(color, level) {
|
|
95
96
|
if (!this.isHex(color)) {
|
|
96
|
-
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
throw new TypeError("输入错误的hex", color);
|
|
97
99
|
}
|
|
98
100
|
let rgbc = this.hexToRgb(color);
|
|
99
|
-
for (let index = 0; index < 3; index++)
|
|
101
|
+
for (let index = 0; index < 3; index++) {
|
|
100
102
|
// @ts-ignore
|
|
101
|
-
rgbc[index] = Math.floor(rgbc[index] * (1 - level))
|
|
103
|
+
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
104
|
+
}
|
|
105
|
+
// @ts-ignore
|
|
102
106
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
@@ -109,13 +113,15 @@
|
|
|
109
113
|
*/
|
|
110
114
|
getLightColor(color, level) {
|
|
111
115
|
if (!this.isHex(color)) {
|
|
112
|
-
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
throw new TypeError("输入错误的hex", color);
|
|
113
118
|
}
|
|
114
119
|
let rgbc = this.hexToRgb(color);
|
|
115
|
-
for (let index = 0; index < 3; index++)
|
|
116
|
-
rgbc[index] = Math.floor(
|
|
120
|
+
for (let index = 0; index < 3; index++) {
|
|
117
121
|
// @ts-ignore
|
|
118
|
-
(255 - rgbc[index]) * level + rgbc[index])
|
|
122
|
+
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
123
|
+
}
|
|
124
|
+
// @ts-ignore
|
|
119
125
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
120
126
|
}
|
|
121
127
|
}
|