|
1 | 1 | /** |
2 | | - * FrostColor v3.0.0 |
| 2 | + * FrostColor v3.0.1 |
3 | 3 | * https://github.com/elusivecodes/FrostColor |
4 | 4 | */ |
5 | 5 | (function(global, factory) { |
|
719 | 719 | * @returns {Color} A new Color object. |
720 | 720 | */ |
721 | 721 | fromHSLString(string) { |
| 722 | + string = string.trim(); |
| 723 | + |
722 | 724 | const HSL2Match = string.match(this._hsl2RegExp); |
723 | 725 |
|
724 | 726 | if (HSL2Match) { |
|
757 | 759 | ); |
758 | 760 | } |
759 | 761 |
|
760 | | - throw new Error('Invalid HSLA string'); |
| 762 | + throw new Error('Invalid HSL string'); |
761 | 763 | }, |
762 | 764 |
|
763 | 765 | /** |
|
791 | 793 | * @returns {Color} A new Color object. |
792 | 794 | */ |
793 | 795 | fromRGBString(string) { |
| 796 | + string = string.trim(); |
| 797 | + |
794 | 798 | const RGB2Match = string.match(this._rgb2RegExp); |
795 | 799 |
|
796 | 800 | if (RGB2Match) { |
|
838 | 842 | * @returns {Color} A new Color object. |
839 | 843 | */ |
840 | 844 | fromString(string) { |
841 | | - string = string.toLowerCase(); |
| 845 | + string = string.toLowerCase().trim(); |
842 | 846 |
|
843 | 847 | if (string === 'transparent') { |
844 | 848 | return new this(0, 0, 0, 0); |
845 | 849 | } |
846 | 850 |
|
847 | 851 | if (string in this.colors) { |
848 | 852 | string = this.colors[string]; |
849 | | - } else { |
850 | | - string = string.trim(); |
851 | 853 | } |
852 | 854 |
|
853 | 855 | if (string.substring(0, 1) === '#') { |
|
900 | 902 | + b * amount; |
901 | 903 | }, |
902 | 904 |
|
| 905 | + /** |
| 906 | + * Shorten a hex string (if possible). |
| 907 | + * @param {string} hex The hex string. |
| 908 | + * @returns {string} The hex string. |
| 909 | + */ |
903 | 910 | _toHex(hex) { |
904 | 911 | if (hex.length === 9 && |
905 | 912 | hex[1] === hex[2] && |
|
992 | 999 | */ |
993 | 1000 | mix(color1, color2, amount) { |
994 | 1001 | return new this( |
995 | | - Color._lerp(color1._r, color2._r, amount), |
996 | | - Color._lerp(color1._g, color2._g, amount), |
997 | | - Color._lerp(color1._b, color2._b, amount), |
998 | | - Color._lerp(color1._a, color2._a, amount) |
| 1002 | + this._lerp(color1._r, color2._r, amount), |
| 1003 | + this._lerp(color1._g, color2._g, amount), |
| 1004 | + this._lerp(color1._b, color2._b, amount), |
| 1005 | + this._lerp(color1._a, color2._a, amount) |
999 | 1006 | ); |
1000 | 1007 | }, |
1001 | 1008 |
|
|
1008 | 1015 | */ |
1009 | 1016 | multiply(color1, color2, amount) { |
1010 | 1017 | return new this( |
1011 | | - Color._lerp( |
| 1018 | + this._lerp( |
1012 | 1019 | color1._r, |
1013 | 1020 | color1._r * color2._r / 255, |
1014 | 1021 | amount |
1015 | 1022 | ), |
1016 | | - Color._lerp( |
| 1023 | + this._lerp( |
1017 | 1024 | color1._g, |
1018 | 1025 | color1._g * color2._g / 255, |
1019 | 1026 | amount |
1020 | 1027 | ), |
1021 | | - Color._lerp( |
| 1028 | + this._lerp( |
1022 | 1029 | color1._b, |
1023 | 1030 | color1._b * color2._b / 255, |
1024 | 1031 | amount |
1025 | 1032 | ), |
1026 | | - Color._lerp( |
| 1033 | + this._lerp( |
1027 | 1034 | color1._a, |
1028 | 1035 | color1._a * color2._a, |
1029 | 1036 | amount |
|
1159 | 1166 |
|
1160 | 1167 | if (this._a < 1) { |
1161 | 1168 | return hex + |
1162 | | - (this._a * 255 | 1 << 8) |
| 1169 | + (Math.round(this._a * 255) | 1 << 8) |
1163 | 1170 | .toString(16) |
1164 | 1171 | .slice(1); |
1165 | 1172 | } |
|
1181 | 1188 | */ |
1182 | 1189 | _getHSV() { |
1183 | 1190 | return this.constructor.RGB2HSV(this._r, this._g, this._b); |
1184 | | - }, |
| 1191 | + } |
1185 | 1192 |
|
1186 | 1193 | }); |
1187 | 1194 |
|
|
0 commit comments