@whitesev/utils 1.1.8 → 1.1.9
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/package.json +1 -1
- package/src/ColorConversion.ts +27 -20
package/dist/index.esm.js
CHANGED
|
@@ -21,7 +21,8 @@ class ColorConversion {
|
|
|
21
21
|
*/
|
|
22
22
|
hexToRgba(hex, opacity) {
|
|
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,17 @@ class ColorConversion {
|
|
|
42
43
|
*/
|
|
43
44
|
hexToRgb(str) {
|
|
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
|
-
for (let index = 0; index < 3; index++)
|
|
55
|
-
hxs[index] = parseInt(hxs[index], 16).toString();
|
|
56
57
|
return hxs;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
@@ -87,12 +88,15 @@ class ColorConversion {
|
|
|
87
88
|
*/
|
|
88
89
|
getDarkColor(color, level) {
|
|
89
90
|
if (!this.isHex(color)) {
|
|
90
|
-
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
throw new TypeError("输入错误的hex", color);
|
|
91
93
|
}
|
|
92
94
|
let rgbc = this.hexToRgb(color);
|
|
93
|
-
for (let index = 0; index < 3; index++)
|
|
95
|
+
for (let index = 0; index < 3; index++) {
|
|
94
96
|
// @ts-ignore
|
|
95
|
-
rgbc[index] = Math.floor(rgbc[index] * (1 - level))
|
|
97
|
+
rgbc[index] = Math.floor(rgbc[index] * (1 - level));
|
|
98
|
+
}
|
|
99
|
+
// @ts-ignore
|
|
96
100
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
97
101
|
}
|
|
98
102
|
/**
|
|
@@ -103,13 +107,15 @@ class ColorConversion {
|
|
|
103
107
|
*/
|
|
104
108
|
getLightColor(color, level) {
|
|
105
109
|
if (!this.isHex(color)) {
|
|
106
|
-
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
throw new TypeError("输入错误的hex", color);
|
|
107
112
|
}
|
|
108
113
|
let rgbc = this.hexToRgb(color);
|
|
109
|
-
for (let index = 0; index < 3; index++)
|
|
110
|
-
rgbc[index] = Math.floor(
|
|
114
|
+
for (let index = 0; index < 3; index++) {
|
|
111
115
|
// @ts-ignore
|
|
112
|
-
(255 - rgbc[index]) * level + rgbc[index])
|
|
116
|
+
rgbc[index] = Math.floor((255 - rgbc[index]) * level + rgbc[index]);
|
|
117
|
+
}
|
|
118
|
+
// @ts-ignore
|
|
113
119
|
return this.rgbToHex(rgbc[0], rgbc[1], rgbc[2]);
|
|
114
120
|
}
|
|
115
121
|
}
|