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