Skip to content

Commit 828ac92

Browse files
committed
[css-color-5] Finish separating processing and syntactic aspects of RCS, #10151
1 parent 965812f commit 828ac92

File tree

1 file changed

+73
-62
lines changed

1 file changed

+73
-62
lines changed

css-color-5/Overview.bs

+73-62
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,11 @@ which is rgb(52.446% 45.821% 62.953%)
793793
-->
794794

795795
<h2 id="relative-colors">
796-
Relative Color Syntax
796+
Relative Colors
797797
</h2>
798798

799799
<h3 id="rcs-intro">
800-
Introduction to Relative Color Syntax
800+
Processing Model for Relative Colors
801801
</h3>
802802

803803
In previous levels of this specification,
@@ -819,11 +819,81 @@ The origin color and the relative color need not use the same color function.
819819

820820
All operations take part in the
821821
[=color space=] of the [=relative color=] function;
822-
the [=origin color=] is converted to that color space,
822+
<span id="required-conversion">if the
823+
<dfn export>originally specified color space</dfn>
824+
for the [=origin color=] used a different color function,
825+
it's first converted into the chosen color function,
826+
so it has meaningful values for the channels</span>
823827
and [=channel keywords=]
824828
refer to the color space of the relative color,
825829
<em>not</em> the [=origin color=].
826830

831+
If the alpha value of the relative color is omitted,
832+
it defaults to that of the [=origin color=]
833+
(rather than defaulting to ''100%'', as it does in the absolute syntax).
834+
835+
When relative color syntax is used,
836+
<strong>color channel</strong> values,
837+
whether directly specified
838+
or arising from color space conversion,
839+
are <em>not clamped</em> to the reference ranges but are retained as-is.
840+
This preserves out of gamut values,
841+
if the destination color space is capable of representing them.
842+
843+
However, when relative color syntax is used,
844+
<strong>alpha channel</strong> values
845+
whether directly specified
846+
or arising from color space conversion,
847+
<em>are</em> clamped to the reference range.
848+
849+
Missing components are handled the same way as with
850+
[[css-color-4#interpolation-missing]]:
851+
the origin colorspace and the relative function colorspace
852+
are checked for [=analogous components=]
853+
which are then [=carried forward=] as missing.
854+
855+
While most uses of [=relative color=] syntax
856+
will use the [=channel keywords=] in their corresponding argument,
857+
you can use them in any position.
858+
859+
Beware when using components outside their normal position;
860+
when percentages are resolved to numbers,
861+
there is no "magic scaling"
862+
to account for the changed position
863+
if those numbers are used in a different place.
864+
865+
866+
<h3 id="relative-syntax">
867+
Relative Color Syntax
868+
</h3>
869+
870+
The precise details of each function's syntactic changes
871+
to accommodate [=relative colors=] are listed below,
872+
but they all follow a common structure:
873+
874+
* An [=origin color=] can be specified with a ''from <<color>>'' value
875+
at the start of the function.
876+
This includes the optional alpha channel, if specified.
877+
* If no origin color is specified, the function is not a relative color.
878+
* If an [=origin color=] is specified,
879+
the remaining arguments can either be specified directly, as normal,
880+
or be specified as a <dfn>channel keyword</dfn>
881+
referring to one of the channels of the [=origin color=]
882+
converted to the [=color space=] of the relative color.
883+
[=Math functions=] can also use these keywords
884+
to do dynamic modifications of the [=origin color's=] channels.
885+
* [=Relative color=] syntax doesn't change whether an argument is required or optional.
886+
* Relative color syntax only applies to the [=modern color syntax=].
887+
It <em>cannot</em> be used with <a>legacy color syntax</a>
888+
and attempting to do so is an error.
889+
* However, the [=origin color=] can use either modern or legacy syntax.
890+
891+
The [=channel keywords=] return a <<number>>;
892+
if they were originally specified as a <<percentage>> or an <<angle>>,
893+
that <<percentage>> is resolved to a <<number>>
894+
and the <<angle>> is resolved to a <<number>> of degrees
895+
(which is the [=canonical unit=])
896+
in the range [0, 360].
827897

828898
<wpt>
829899
relative-currentcolor-a98rgb-01.html
@@ -848,33 +918,6 @@ refer to the color space of the relative color,
848918
parsing/relative-color-out-of-gamut.html
849919
</wpt>
850920

851-
The precise details of each function's changes to accommodate [=relative colors=] are listed below,
852-
but they all follow a common structure:
853-
854-
* An [=origin color=] can be specified with a ''from <<color>>'' value at the start of the function.
855-
This includes the optional alpha channel, if specified.
856-
* If an [=origin color=] is specified,
857-
the remaining arguments can either be specified directly, as normal,
858-
or be specified as a <dfn>channel keyword</dfn>
859-
referring to one of the channels of the [=origin color=].
860-
[=Math functions=] can also use these keywords
861-
to do dynamic modifications of the [=origin color's=] channels.
862-
* [=Relative color=] syntax doesn't change whether an argument is required or optional.
863-
If the alpha value is omitted, however,
864-
it defaults to taking from the [=origin color=]
865-
(rather than defaulting to ''100%'', as it does in the absolute syntax).
866-
* Relative color syntax only applies to the [=modern color syntax=].
867-
It <em>cannot</em> be used with <a>legacy color syntax</a>
868-
and attempting to do so is an error.
869-
* However, the [=origin color=] can use either modern or legacy syntax.
870-
871-
The [=channel keywords=] return a <<number>>;
872-
if they were originally specified as a <<percentage>> or an <<angle>>,
873-
that <<percentage>> is resolved to a <<number>>
874-
and the <<angle>> is resolved to a <<number>> of degrees
875-
(which is the [=canonical unit=])
876-
in the range [0, 360].
877-
878921
<div class=example>
879922
For example, if a color is specified using <<percentage>>,
880923
then RCS in the same colorspace will use the resolved <<number>> form:
@@ -913,12 +956,6 @@ in the range [0, 360].
913956

914957
</div>
915958

916-
<p id="required-conversion">If the
917-
<dfn export>originally specified color space</dfn>
918-
for the [=origin color=] used a different color function,
919-
it's first converted into the chosen color function,
920-
so it has meaningful values for the channels.</p>
921-
922959
<div class=example>
923960
By using the [=channel keywords=] in a [=math function=],
924961
an [=origin color=] can be manipulated in more advanced ways.
@@ -958,14 +995,6 @@ so it has meaningful values for the channels.</p>
958995
regardless of what the [=origin color's=] opacity was.
959996
</div>
960997

961-
When relative color syntax is used,
962-
color channel values,
963-
whether directly specified
964-
or arising from color space conversion,
965-
are <em>not</em> clamped to the reference ranges but are retained as-is.
966-
This preserves out of gamut values,
967-
if the destination color space is capable of representing them.
968-
969998
<div class="example">
970999
For example, a Display P3 color
9711000
which is outside the gamut of sRGB can still be represented,
@@ -983,9 +1012,6 @@ if the destination color space is capable of representing them.
9831012
<span class="swatch" style="--color: rgb(100% 100% 15.37%)"></span> rgb(100% 100% 15.37%)
9841013
</div>
9851014

986-
However, when relative color syntax is used,
987-
alpha channels <em>are</em> clamped to the reference range.
988-
9891015
<div class="example">
9901016
For example, attempting to double an alpha of 0.7 in the origin color
9911017
results in an alpha in the result of 1, not 1.4.
@@ -996,9 +1022,6 @@ alpha channels <em>are</em> clamped to the reference range.
9961022
</pre>
9971023
</div>
9981024

999-
While most uses of [=relative color=] syntax
1000-
will use the [=channel keywords=] in their corresponding argument,
1001-
you can use them in any position.
10021025

10031026
<div class=example>
10041027
For example, to do a rough approximation of grayscaling a color:
@@ -1037,12 +1060,6 @@ you can use them in any position.
10371060
which determines how "colorful" the color is.)
10381061
</div>
10391062

1040-
Beware when using components outside their normal position;
1041-
when percentages are resolved to numbers,
1042-
there is no "magic scaling"
1043-
to account for the changed position
1044-
if those numbers are used in a different place.
1045-
10461063
<div class="example" id="ex-no-percentage-magic">
10471064
<p>For example,</p>
10481065

@@ -1073,12 +1090,6 @@ you can use them in any position.
10731090

10741091
</div>
10751092

1076-
Missing components are handled the same way as with
1077-
[[css-color-4#interpolation-missing]]:
1078-
the origin colorspace and the relative function colorspace
1079-
are checked for [=analogous components=]
1080-
which are then carried forward as missing.
1081-
10821093
<div class="example" id="ex-missing-analogous">
10831094
In this example the achromatic origin color has a missing hue;
10841095
the [=relative color=] also has a missing hue,

0 commit comments

Comments
 (0)