Fix parsing of rgb color string with percentages

This commit is contained in:
sapics 2019-12-05 17:04:03 +09:00 committed by Jürg Lehni
parent 7dad1a495d
commit 871531b46a
2 changed files with 4 additions and 1 deletions

View file

@ -102,7 +102,7 @@ var Color = Base.extend(new function() {
}
} else if (i < 3) {
// RGB color values to 0..1
value /= 255;
value /= /%$/.test(component) ? 100 : 255;
}
components[i] = value;
}

View file

@ -84,6 +84,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 2nd test');
equals(new Color('rgb(100%, 50%, 0%)'), new Color(1, 0.5, 0),
'Color from rgb() percenst string');
equals(new Color('hsl(180deg, 20%, 40%)'),
new Color({ hue: 180, saturation: 0.2, lightness: 0.4 }),
'Color from hsl() string');