Skip to content

Commit b35b729

Browse files
committed
allow optional alpha channel in rgb()
match browsers, which don't distinguish rbg() vs rgba()
1 parent 441ecf0 commit b35b729

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/CSS/Grammar.rakumod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ grammar CSS::Grammar:ver<0.3.10> {
8686
rule end-decl { ';' | <?before '}'> | $ }
8787
8888
rule color-range { <num>[$<percentage>=\%]? }
89+
rule alpha-value { <num>[$<percentage>=\%]? }
8990
9091
proto rule color {*}
9192
rule color:sym<rgb> {:i 'rgb('
92-
[ <color-range> **3% ',' || <any-args> ]
93+
[ <color-range> **3% ',' [ ',' <alpha-value> ]? || <any-args> ]
9394
')'
9495
}
9596
rule color:sym<hex> { <id> }

lib/CSS/Grammar/Actions.rakumod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class CSS::Grammar::Actions {
192192
make $.build.token( $range.round, :type(CSSValue::NumberComponent));
193193
}
194194

195+
method alpha-value($/) {
196+
my $alpha = $<num>.ast.value;
197+
$alpha /= 100
198+
if $<percentage>;
199+
$alpha = min( max($alpha, 0), 1);
200+
make $.build.token( $alpha.round(.01), :type(CSSValue::NumberComponent));
201+
}
202+
195203
proto method color {*}
196204
method color:sym<rgb>($/) {
197205
return $.warning('usage: rgb(c,c,c) where c is 0..255 or 0%-100%')

0 commit comments

Comments
 (0)