Skip to content

Commit 0e22552

Browse files
committed
[css-typed-om] Define how to reify a color value.
1 parent d916d2b commit 0e22552

File tree

1 file changed

+95
-3
lines changed

1 file changed

+95
-3
lines changed

css-typed-om/Overview.bs

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,7 +2907,7 @@ with the subclasses representing individual CSS color functions.
29072907
interface CSSColorValue : CSSStyleValue {
29082908
readonly attribute CSSKeywordValue colorSpace;
29092909
CSSColorValue to(CSSKeywordish colorSpace);
2910-
[Exposed=Window] static CSSColorValue parse(USVString cssText);
2910+
[Exposed=Window] static (CSSColorValue or CSSStyleValue) parse(USVString cssText);
29112911
};
29122912
</xmp>
29132913

@@ -5248,9 +5248,101 @@ CSS <<number>>, <<percentage>>, and <<dimension>> values become {{CSSNumericValu
52485248
(depending on the value of an ''em'' in that context).
52495249
</div>
52505250

5251+
<<color>> Values {#reify-color}
5252+
-------------------------------
52515253

5252-
<<transform-list>> and <<transform-function>> values {#reify-transformvalue}
5253-
------------------------------------------------------------------------------------
5254+
CSS <<color>> values become either {{CSSColorValue}}s
5255+
(if they can be resolved to an absolute color)
5256+
or generic {{CSSStyleValue}}s (otherwise).
5257+
5258+
<div algorithm>
5259+
To <dfn>reify a color value</dfn> |val| for a property |prop|:
5260+
5261+
1. If |val| is a <<hex-color>>,
5262+
an ''rgb()'' function,
5263+
or an ''rgba()'' function,
5264+
then return a new {{CSSRGB}} object
5265+
with its {{CSSRGB/r}},
5266+
{{CSSRGB/g}},
5267+
{{CSSRGB/b}},
5268+
and {{CSSRGB/alpha}} internal slots
5269+
set to the [=reification=]
5270+
of its red, green, blue, and alpha components, respectively.
5271+
5272+
2. If |val| is an ''hsl()'' or ''hsla()'' function,
5273+
then return a new {{CSSHSL}} object
5274+
with its {{CSSHSL/h}},
5275+
{{CSSHSL/s}},
5276+
{{CSSHSL/l}},
5277+
and {{CSSHSL/alpha}} internal slots
5278+
set to the [=reification=]
5279+
of its hue angle, saturation, lightness, and alpha components, respectively.
5280+
5281+
3. If |val| is an ''hwb()'' function,
5282+
then return a new {{CSSHWB}} object
5283+
with its {{CSSHWB/h}},
5284+
{{CSSHWB/w}},
5285+
{{CSSHWB/b}},
5286+
and {{CSSHWB/alpha}} internal slots
5287+
set to the [=reification=]
5288+
of its hue angle, whiteness, blackness, and alpha components, respectively.
5289+
5290+
4. If |val| is an ''lch()'' function,
5291+
then return a new {{CSSLCH}} object
5292+
with its {{CSSLCH/l}},
5293+
{{CSSLCH/c}},
5294+
{{CSSLCH/h}},
5295+
and {{CSSLCH/alpha}} internal slots
5296+
set to the [=reification=]
5297+
of its lightness, chroma, hue angle, and alpha components, respectively.
5298+
5299+
5. If |val| is an ''lab()'' function,
5300+
then return a new {{CSSLab}} object
5301+
with its {{CSSLab/l}},
5302+
{{CSSLab/a}},
5303+
{{CSSLab/b}},
5304+
and {{CSSLab/alpha}} internal slots
5305+
set to the [=reification=]
5306+
of its lightness, a, b, and alpha components, respectively.
5307+
5308+
6. If |val| is a ''device-cmyk()'' function,
5309+
then return a new {{CSSDeviceCMYK}} object
5310+
with its {{CSSDeviceCMYK/c}},
5311+
{{CSSDeviceCMYK/m}},
5312+
{{CSSDeviceCMYK/y}},
5313+
{{CSSDeviceCMYK/k}},
5314+
and {{CSSDeviceCMYK/alpha}} internal slots
5315+
set to the [=reification=]
5316+
of its cyan, magenta, yellow, key, and alpha components, respectively.
5317+
5318+
7. If |val| is a ''color()'' function,
5319+
then return a new {{CSSColor}} object
5320+
with its {{CSSColor/colorSpace}} internal slot
5321+
set to the result of [=reifying an identifier=]
5322+
from |val|'s color space,
5323+
its {{CSSColor/channels}} internal slot
5324+
set to the result of [=reifying a percentish array=]
5325+
from |val|'s list of non-alpha components,
5326+
and {{CSSColor/alpha}} internal slot
5327+
set to the result of [=reifying=] |val|'s alpha component.
5328+
5329+
8. If |val| is a <<named-color>> or the keyword ''transparent'',
5330+
then return a new {{CSSRGB}} object
5331+
with its {{CSSRGB/r}},
5332+
{{CSSRGB/g}},
5333+
{{CSSRGB/b}},
5334+
and {{CSSRGB/alpha}} internal slots
5335+
set to the [=reification=]
5336+
of its red, green, blue, and alpha components, respectively.
5337+
5338+
8. If |val| is any other color keyword,
5339+
return the result of [=reifying as a CSSStyleValue=] |val| for |prop|.
5340+
</div>
5341+
5342+
5343+
5344+
<<transform-list>> and <<transform-function>> Values {#reify-transformvalue}
5345+
----------------------------------------------------------------------------
52545346

52555347
CSS <<transform-list>> values become {{CSSTransformValue}}s in the Typed OM,
52565348
while CSS <<transform-function>> values become {{CSSTransformComponent}}s.

0 commit comments

Comments
 (0)