3.9 KiB
Color Level 4 rgb()
and hsl()
Functions: Draft 1
(Issue)
This proposal expands Sass's built-in rgb()
, rgba()
, hsl()
, and hsla()
functions to support the new terse syntax defined in CSS Color Level 4.
Table of Contents
Summary
This section is non-normative.
Sass's rgb()
and hsl()
functions will add support for the Color Level 4
syntax, so rgb(179 115 153)
, rgb(70% 45% 60%)
, and hsl(324deg 29% 57%)
will all return the same color. They'll also support the slash-separated alpha
syntax using the normal rules for distinguishing between division and /
,
so rgb(179 115 153 / 50%)
will return a 50%-opacity color but
rgb(179 115 $blue / 50%)
will not.
Color Level 4 redefines rgba()
and hsla()
as pure aliases for rgb()
and
hsl()
, which also means that rgb()
and hsl()
support the old syntax for
defining colors with alpha channels. In keeping with this, Sass will redefine
rgba()
and hsla()
as aliases for rgb()
and hsl()
as well, and add
support to the latter for the former's syntax. This includes the Sass-specific
rgba($color, $alpha)
syntax, which will now work with rgb()
and hsl()
as
well.
Sass will continue generating colors with alpha channels as rgba()
calls, for
backwards-compatibility with older browsers that don't yet support Color Level
4.
Semantics
This proposal adds new overloads to the rgb()
, hsl()
, rgba()
, and hsla()
functions:
-
rgb($channels)
-
If
$channels
is not an unbracketed space-separated list, throw an error. -
If
$channels
doesn't have exactly three elements, throw an error. -
Let
red
andgreen
be the first two elements of$channels
. -
If the third element of
$channels
has preserved its status as two slash-separated numbers:-
Let
blue
be the number before the slash andalpha
the number after the slash. -
Call
rgba()
withred
,green
,blue
, andalpha
as arguments and return the result.
-
-
Otherwise:
-
Let
blue
be the third element of$channels
. -
Call
rgb()
withred
,green
, andblue
as arguments and return the result.
-
-
-
rgb($red, $green, $blue, $alpha)
- Call
rgba()
with the same arguments and return the result.
- Call
-
rgb($color, $alpha)
- Call
rgba()
with the same arguments and return the result.
- Call
-
hsl($channels)
-
If
$channels
is not an unbracketed space-separated list, throw an error. -
If
$channels
doesn't have exactly three elements, throw an error. -
Let
hue
andsaturation
be the first two elements of$channels
. -
If the third element of
$channels
has preserved its status as two slash-separated numbers:-
Let
lightness
be the number before the slash andalpha
the number after the slash. -
Call
hsla()
withhue
,saturation
,lightness
, andalpha
as arguments and return the result.
-
-
Otherwise:
-
Let
lightness
be the third element of$channels
. -
Call
hsl()
withhue
,saturation
, andlightness
as arguments and return the result.
-
-
-
hsl($hue, $saturation, $lightness, $alpha)
- Call
hsla()
with the same arguments and return the result.
- Call
-
hsl($color, $alpha)
- Call
hsla()
with the same arguments and return the result.
- Call
-
rgba($channels)
- Call
rgb()
with the same argument and return the result.
- Call
-
rgba($red, $green, $blue)
- Call
rgb()
with the same arguments and return the result.
- Call
-
hsla($channels)
- Call
hsl()
with the same argument and return the result.
- Call
-
hsla($hue, $saturation, $lightness)
- Call
hsl()
with the same arguments and return the result.
- Call