mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Fix css color parse
This commit is contained in:
parent
449c5c3e6d
commit
5904a288e7
3 changed files with 10 additions and 1 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## Prebuilt version
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix css color parse (#1629)
|
||||||
|
|
||||||
## `0.12.0`
|
## `0.12.0`
|
||||||
|
|
||||||
### News
|
### News
|
||||||
|
|
|
@ -80,7 +80,7 @@ var Color = Base.extend(new function() {
|
||||||
} else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) {
|
} else if (match = string.match(/^(rgb|hsl)a?\((.*)\)$/)) {
|
||||||
// RGB / RGBA or HSL / HSLA
|
// RGB / RGBA or HSL / HSLA
|
||||||
type = match[1];
|
type = match[1];
|
||||||
components = match[2].split(/[,\s]+/g);
|
components = match[2].trim().split(/[,\s]+/g);
|
||||||
var isHSL = type === 'hsl';
|
var isHSL = type === 'hsl';
|
||||||
for (var i = 0, l = Math.min(components.length, 4); i < l; i++) {
|
for (var i = 0, l = Math.min(components.length, 4); i < l; i++) {
|
||||||
var component = components[i];
|
var component = components[i];
|
||||||
|
|
|
@ -81,6 +81,9 @@ test('Creating Colors', function() {
|
||||||
equals(new Color('rgba(255, 0, 0, 0.5)'), new Color(1, 0, 0, 0.5),
|
equals(new Color('rgba(255, 0, 0, 0.5)'), new Color(1, 0, 0, 0.5),
|
||||||
'Color from rgba() string');
|
'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%)'),
|
equals(new Color('hsl(180deg, 20%, 40%)'),
|
||||||
new Color({ hue: 180, saturation: 0.2, lightness: 0.4 }),
|
new Color({ hue: 180, saturation: 0.2, lightness: 0.4 }),
|
||||||
'Color from hsl() string');
|
'Color from hsl() string');
|
||||||
|
|
Loading…
Reference in a new issue