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