parseColor
Reads a colour into a record with hex, r, g, b, a, h, s and l.
Details #
parseColor(text) takes one argument and returns a record:
hex: lower-case#rrggbb, or#rrggbbaawhen the colour is see-through;r,g,b: 0 to 255;a: 0 to 1;h(0 to 360),sandl(0 to 100).
It reads #rgb, #rgba, #rrggbb, #rrggbbaa (the # is optional), rgb() and rgba() with commas or spaces, / alpha, percent channels, hsl() and hsla() the same way, transparent, and the 148 CSS colour names such as tomato. Capitals don't matter.
Parameters #
Takes 1 argument.
{{ parseColor(text) }}
Examples #
parseColor("tomato").hex→
#ff6347parseColor("rgb(255 128 0 / 50%)").a→
0.5parseColor("hsl(120, 100%, 50%)").hex→
#00ff00Gotchas #
An unknown colour is an error:
parseColor() doesn't know the colour 'plaid'.