@@ -2,6 +2,8 @@ import Dimension from '../tree/dimension';
2
2
import Color from '../tree/color' ;
3
3
import Quoted from '../tree/quoted' ;
4
4
import Anonymous from '../tree/anonymous' ;
5
+ import Expression from '../tree/expression' ;
6
+ import Operation from '../tree/operation' ;
5
7
let colorFunctions ;
6
8
7
9
function clamp ( val ) {
@@ -56,7 +58,27 @@ function scaled(n, size) {
56
58
}
57
59
colorFunctions = {
58
60
rgb : function ( r , g , b ) {
59
- const color = colorFunctions . rgba ( r , g , b , 1.0 ) ;
61
+ let a = 1
62
+ /**
63
+ * Comma-less syntax
64
+ * e.g. rgb(0 128 255 / 50%)
65
+ */
66
+ if ( r instanceof Expression ) {
67
+ const val = r . value
68
+ r = val [ 0 ]
69
+ g = val [ 1 ]
70
+ b = val [ 2 ]
71
+ /**
72
+ * @todo - should this be normalized in
73
+ * function caller? Or parsed differently?
74
+ */
75
+ if ( b instanceof Operation ) {
76
+ const op = b
77
+ b = op . operands [ 0 ]
78
+ a = op . operands [ 1 ]
79
+ }
80
+ }
81
+ const color = colorFunctions . rgba ( r , g , b , a ) ;
60
82
if ( color ) {
61
83
color . value = 'rgb' ;
62
84
return color ;
@@ -79,7 +101,20 @@ colorFunctions = {
79
101
catch ( e ) { }
80
102
} ,
81
103
hsl : function ( h , s , l ) {
82
- const color = colorFunctions . hsla ( h , s , l , 1.0 ) ;
104
+ let a = 1
105
+ if ( h instanceof Expression ) {
106
+ const val = h . value
107
+ h = val [ 0 ]
108
+ s = val [ 1 ]
109
+ l = val [ 2 ]
110
+
111
+ if ( l instanceof Operation ) {
112
+ const op = l
113
+ l = op . operands [ 0 ]
114
+ a = op . operands [ 1 ]
115
+ }
116
+ }
117
+ const color = colorFunctions . hsla ( h , s , l , a ) ;
83
118
if ( color ) {
84
119
color . value = 'hsl' ;
85
120
return color ;
0 commit comments