§60a: "CSS-style color strings used throughout the API (§50, §59, §68) denote
sRGB values", and the GPU pipeline is linear-light. The result of this
function is therefore not ready to hand to a material or a light — run it
through srgbToLinearRGBA first. The two steps are separate so that a
loader reading #rrggbb out of a document, a test asserting the byte value,
and a debug overlay printing what the author wrote all get the encoded value
they are actually talking about.
The grammar this tier accepts
#rgb, #rgba, #rrggbb, #rrggbbaa (case-insensitive); rgb(…) and
rgba(…) with three components and an optional alpha, comma-separated or
space-separated with / before the alpha, each component a number 0…255 or
a percentage and the alpha a number 0…1 or a percentage; transparent; and
the sixteen CSS Level 1 keywords (black, silver, gray, white,
maroon, red, purple, fuchsia, green, lime, olive, yellow,
navy, blue, teal, aqua). Leading and trailing whitespace is ignored,
and keywords are case-insensitive.
Everything else — hsl(), lab(), color(), currentColor, the other ~132
keywords — throws a TypeError naming what is accepted (§85). A full CSS
colour parser is not this tier: refusing loudly is what keeps an unsupported
notation from silently becoming black.
Components are not clamped: rgb(300 0 0) parses to [1.176…, 0, 0, 1],
because §60a's pipeline is extended-range and this function's job is to report
what the string said (module header).
Optional destination, returned when given. Parsing is setup-time
work, so this is optional where the transfer functions' out-parameters are
required; it exists for a loader filling an array it already owns.
Parses a CSS colour string into sRGB-encoded components in 0…1 (§60a).
What "sRGB-encoded" obliges the caller to do
§60a: "CSS-style color strings used throughout the API (§50, §59, §68) denote sRGB values", and the GPU pipeline is linear-light. The result of this function is therefore not ready to hand to a material or a light — run it through srgbToLinearRGBA first. The two steps are separate so that a loader reading
#rrggbbout of a document, a test asserting the byte value, and a debug overlay printing what the author wrote all get the encoded value they are actually talking about.The grammar this tier accepts
#rgb,#rgba,#rrggbb,#rrggbbaa(case-insensitive);rgb(…)andrgba(…)with three components and an optional alpha, comma-separated or space-separated with/before the alpha, each component a number0…255or a percentage and the alpha a number0…1or a percentage;transparent; and the sixteen CSS Level 1 keywords (black,silver,gray,white,maroon,red,purple,fuchsia,green,lime,olive,yellow,navy,blue,teal,aqua). Leading and trailing whitespace is ignored, and keywords are case-insensitive.Everything else —
hsl(),lab(),color(),currentColor, the other ~132 keywords — throws aTypeErrornaming what is accepted (§85). A full CSS colour parser is not this tier: refusing loudly is what keeps an unsupported notation from silently becoming black.Components are not clamped:
rgb(300 0 0)parses to[1.176…, 0, 0, 1], because §60a's pipeline is extended-range and this function's job is to report what the string said (module header).