Improve color parsing for 4 characters hex code (#1565)

This commit is contained in:
Takahiro Nishino 2018-10-15 04:44:22 +09:00 committed by Jürg Lehni
parent d070286cde
commit 6f2d75442c
3 changed files with 6 additions and 3 deletions

View file

@ -20,7 +20,7 @@ solid fixes, as we are paving the way for the upcoming release of `1.0.0`. Here
- Draw shadows on `Raster` images (#1437) - Draw shadows on `Raster` images (#1437)
- Fix boolean operation edge case (#1506, #1513, #1515). - Fix boolean operation edge case (#1506, #1513, #1515).
- Remove memory leak on gradient colors (#1499). - Remove memory leak on gradient colors (#1499).
- Support alpha channel in CSS colors (#1468, #1539). - Support alpha channel in CSS colors (#1468, #1539, #1565).
- Improve color CSS string parsing and documentation. - Improve color CSS string parsing and documentation.
- Improve caching of item positions (#1503). - Improve caching of item positions (#1503).
- Always draw selected position in global coordinates system (#1545). - Always draw selected position in global coordinates system (#1545).

View file

@ -64,7 +64,7 @@ var Color = Base.extend(new function() {
var match = string.match( var match = string.match(
/^#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?$/i /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?$/i
) || string.match( ) || string.match(
/^#([\da-f])([\da-f])([\da-f])$/i /^#([\da-f])([\da-f])([\da-f])([\da-f])?$/i
), ),
type = 'rgb', type = 'rgb',
components; components;

View file

@ -69,8 +69,11 @@ test('Creating Colors', function() {
equals(new Color('#FF3300'), new Color(1, 0.2, 0), equals(new Color('#FF3300'), new Color(1, 0.2, 0),
'Color from uppercase hex string'); 'Color from uppercase hex string');
equals(new Color('#f009'), new Color(1, 0, 0, .6),
'Color from 4 characters hex code with alpha');
equals(new Color('#ff000099'), new Color(1, 0, 0, .6), equals(new Color('#ff000099'), new Color(1, 0, 0, .6),
'Color from hex code with alpha'); 'Color from 8 characters hex code with alpha');
equals(new Color('rgb(255, 0, 0)'), new Color(1, 0, 0), equals(new Color('rgb(255, 0, 0)'), new Color(1, 0, 0),
'Color from rgb() string'); 'Color from rgb() string');