Fix css color parse

This commit is contained in:
sapics 2018-12-13 16:48:35 +09:00 committed by Jürg Lehni
parent 449c5c3e6d
commit 5904a288e7
3 changed files with 10 additions and 1 deletions

View file

@ -1,5 +1,11 @@
# Change Log
## Prebuilt version
### Fixed
- Fix css color parse (#1629)
## `0.12.0`
### News

View file

@ -80,7 +80,7 @@ var Color = Base.extend(new function() {
} else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) {
// RGB / RGBA or HSL / HSLA
type = match[1];
components = match[2].split(/[,\s]+/g);
components = match[2].trim().split(/[,\s]+/g);
var isHSL = type === 'hsl';
for (var i = 0, l = Math.min(components.length, 4); i < l; i++) {
var component = components[i];

View file

@ -81,6 +81,9 @@ test('Creating Colors', function() {
equals(new Color('rgba(255, 0, 0, 0.5)'), new Color(1, 0, 0, 0.5),
'Color from rgba() string');
equals(new Color('rgba( 255, 0, 0, 0.5 )'), new Color(1, 0, 0, 0.5),
'Color from rgba() string 2nd test');
equals(new Color('hsl(180deg, 20%, 40%)'),
new Color({ hue: 180, saturation: 0.2, lightness: 0.4 }),
'Color from hsl() string');