@@ -347,19 +347,19 @@ Color.fromRandom = function (options, result) {
347
347
return result ;
348
348
} ;
349
349
350
- //#rgb
351
- var rgbMatcher = / ^ # ( [ 0 - 9 a - f ] ) ( [ 0 - 9 a - f ] ) ( [ 0 - 9 a - f ] ) $ / i;
352
- //#rrggbb
353
- var rrggbbMatcher = / ^ # ( [ 0 - 9 a - f ] { 2 } ) ( [ 0 - 9 a - f ] { 2 } ) ( [ 0 - 9 a - f ] { 2 } ) $ / i;
350
+ //#rgba
351
+ var rgbaMatcher = / ^ # ( [ 0 - 9 a - f ] ) ( [ 0 - 9 a - f ] ) ( [ 0 - 9 a - f ] ) ( [ 0 - 9 a - f ] ) ? $ / i;
352
+ //#rrggbbaa
353
+ var rrggbbaaMatcher = / ^ # ( [ 0 - 9 a - f ] { 2 } ) ( [ 0 - 9 a - f ] { 2 } ) ( [ 0 - 9 a - f ] { 2 } ) ( [ 0 - 9 a - f ] { 2 } ) ? $ / i;
354
354
//rgb(), rgba(), or rgb%()
355
355
var rgbParenthesesMatcher = / ^ r g b a ? \( \s * ( [ 0 - 9 . ] + % ? ) \s * , \s * ( [ 0 - 9 . ] + % ? ) \s * , \s * ( [ 0 - 9 . ] + % ? ) (?: \s * , \s * ( [ 0 - 9 . ] + ) ) ? \s * \) $ / i;
356
- //hsl(), hsla(), or hsl% ()
356
+ //hsl() or hsla ()
357
357
var hslParenthesesMatcher = / ^ h s l a ? \( \s * ( [ 0 - 9 . ] + ) \s * , \s * ( [ 0 - 9 . ] + % ) \s * , \s * ( [ 0 - 9 . ] + % ) (?: \s * , \s * ( [ 0 - 9 . ] + ) ) ? \s * \) $ / i;
358
358
359
359
/**
360
360
* Creates a Color instance from a CSS color value.
361
361
*
362
- * @param {String } color The CSS color value in #rgb, #rrggbb, rgb(), rgba(), hsl(), or hsla() format.
362
+ * @param {String } color The CSS color value in #rgb, #rgba, # rrggbb, #rrggbbaa , rgb(), rgba(), hsl(), or hsla() format.
363
363
* @param {Color } [result] The object to store the result in, if undefined a new instance will be created.
364
364
* @returns {Color } The color object, or undefined if the string was not a valid CSS color.
365
365
*
@@ -385,21 +385,21 @@ Color.fromCssColorString = function (color, result) {
385
385
return result ;
386
386
}
387
387
388
- var matches = rgbMatcher . exec ( color ) ;
388
+ var matches = rgbaMatcher . exec ( color ) ;
389
389
if ( matches !== null ) {
390
390
result . red = parseInt ( matches [ 1 ] , 16 ) / 15 ;
391
391
result . green = parseInt ( matches [ 2 ] , 16 ) / 15.0 ;
392
392
result . blue = parseInt ( matches [ 3 ] , 16 ) / 15.0 ;
393
- result . alpha = 1 .0;
393
+ result . alpha = parseInt ( defaultValue ( matches [ 4 ] , "f" ) , 16 ) / 15 .0;
394
394
return result ;
395
395
}
396
396
397
- matches = rrggbbMatcher . exec ( color ) ;
397
+ matches = rrggbbaaMatcher . exec ( color ) ;
398
398
if ( matches !== null ) {
399
399
result . red = parseInt ( matches [ 1 ] , 16 ) / 255.0 ;
400
400
result . green = parseInt ( matches [ 2 ] , 16 ) / 255.0 ;
401
401
result . blue = parseInt ( matches [ 3 ] , 16 ) / 255.0 ;
402
- result . alpha = 1 .0;
402
+ result . alpha = parseInt ( defaultValue ( matches [ 4 ] , "ff" ) , 16 ) / 255 .0;
403
403
return result ;
404
404
}
405
405
0 commit comments