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