Skip to content

Commit c802635

Browse files
committed
[css-color-4] start splitting out serialization
1 parent 66e2064 commit c802635

File tree

1 file changed

+194
-50
lines changed

1 file changed

+194
-50
lines changed

css-color-4/Overview.bs

Lines changed: 194 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Former Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.
1414
Abstract: This specification describes CSS <<color>> values and properties for foreground color and group opacity.
1515
Repository: w3c/csswg-drafts
1616
Ignored Terms: stacking context, double, octet
17+
Complain About: missing-example-ids true
18+
Complain About: broken-links true
19+
Complain About: accidental-2119 true
1720
</pre>
1821

1922
<pre class='ignored-specs'>
@@ -409,55 +412,55 @@ Resolving <<color>> Values</h3>
409412
Unless otherwise specified for a particular property,
410413
[=specified value|specified=] colors are resolved to
411414
<dfn export lt="computed color">[=computed value|computed=] colors</dfn>
412-
and then further to <dfn export lt="used color">[=used value|used=] colors</dfn> as follows:
413-
414-
: ''transparent''
415-
::
416-
The computed and used value is [=transparent black=].
417-
418-
: [=hex colors=]
419-
: ''rgb()'' and ''rgba()'' values
420-
: ''hsl()'' and ''hsla()'' values
421-
: ''hwb()'' values
422-
: [=named colors=]
423-
::
415+
and then further to <dfn export lt="used color">[=used value|used=] colors</dfn> as described below.
416+
417+
The [=resolved value=] of a <<color>> is its [=used value=].
418+
419+
<h4 id="resolving-sRGB-values">Resolving sRGB values</h4>
420+
421+
This applies to:
422+
423+
* [=hex colors=]
424+
* ''rgb()'' and ''rgba()'' values
425+
* ''hsl()'' and ''hsla()'' values
426+
* ''hwb()'' values
427+
* [=named colors=]
428+
429+
While the function names and named colors
430+
are <a href="https://infra.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a>,
431+
the [=specified value=]
432+
does not preserve any mixed casing
433+
and is treated as being all lowercase.
434+
435+
<div class="example">
436+
<p>For example, the first form below is treated as identical to the second:</p>
437+
<pre class="lang-css"><span class="swatch" style="--color: hsl(39 100% 50%)"></span> HsL(39 100% 50%)
438+
439+
<span class="swatch" style="--color: hsl(39 100% 50%)"></span> hsl(39 100% 50%)</pre>
440+
<p>Similarly the first form below is treated as identical to the second:</p>
441+
<pre class="lang-css"><span class="swatch" style="--color: purple"></span> pUrPlE
442+
443+
<span class="swatch" style="--color: purple"></span> purple</pre>
444+
</div>
445+
424446
The computed and used value
425447
is the corresponding sRGB color,
426-
(for compatibility, in <<number>> form, not <<percentage>>)
427448
paired with the specified alpha channel
428-
(as a <<number>>, not a <<percentage>>;
429449
and defaulting to opaque if unspecified).
430450

431-
Note: contrary to CSS Color 3,
432-
the parameters of the ''rgb()'' function
433-
are of type <<number>> not <<integer>>.
434-
For compatibility, numbers are still
435-
in the range [0-255];
436-
higher precision is indicated with any fractional part.
437-
438-
Trailing zeroes in any component values must be suppressed;
439-
if the fractional part consists of all zeroes,
440-
the decimal point must also be suppressed.
441-
This means that sRGB colors specified with integer component values
442-
will serialize with backwards-compatible integer values.
443451

444452
<div class="example">
445-
<p>
446-
For example,</p>
447-
<pre class="lang-css"><span class="swatch" style="--color: rgb(57.28% 42.14% 51.46%)"></span> rgb(146.064 107.457 131.223)</pre>
448-
<p>is now valid, and equal to</p>
449-
<pre class="lang-css"><span class="swatch" style="--color: rgb(57.28% 42.14% 51.46%)"></span> rgb(57.28% 42.14% 51.46%)</pre>
450-
<p>while ''goldenrod'' will serialize as</p>
451-
<pre class="lang-css"><span class="swatch" style="--color: goldenrod"></span> "rgb(218 165 32)"</pre>
452-
<p>and not</p>
453-
<pre class="lang-css"><span class="swatch" style="--color: goldenrod"></span> "rgb(218.000 165.000 32.000)"</pre>
454-
455-
<!-- required precision?
456-
sRGB should accomodate at least 10 bits/component -->
453+
<p>For example, the computed value of</p>
454+
<pre class="lang-css"><span class="swatch" style="--color: rgb(255, 165, 0)"></span> hsl(38.824 100% 50%)</pre>
455+
<p>is</p>
456+
<pre class="lang-css"><span class="swatch" style="--color: rgb(255, 165, 0)"></span> rgb(255, 165, 0)</pre>
457457
</div>
458458

459-
: ''lab()'' and ''lch()'' values
460-
::
459+
460+
<h4 id="resolving-lab-lch-values">Resolving Lab and LCH values</h4>
461+
462+
This applies to ''lab()'' and ''lch()'' values.
463+
461464
The computed and used value
462465
is the corresponding CIE Lab color
463466
paired with the specified alpha channel
@@ -471,9 +474,8 @@ Resolving <<color>> Values</h3>
471474
<pre class="lang-css"><span class="swatch" style="--color: rgb(77.61% 36.34% 2.45%)"></span> "lab(52.2345% 40.1645 59.9971)"</pre>
472475
</div>
473476

477+
<h4 id="resolving-color-values">Resolving values of the ''color()'' function</h4>
474478

475-
: ''color()'' values
476-
::
477479
The computed and used value
478480
is the color in the specified [=colorspace=],
479481
paired with the specified alpha channel
@@ -487,8 +489,8 @@ Resolving <<color>> Values</h3>
487489
<pre class="lang-css"><span class="swatch" style="--color: goldenrod"></span> "color(display-p3 0.823 0.6554 0.2537)"</pre>
488490
</div>
489491

490-
: ''device-cmyk()'' values
491-
::
492+
<h4 id="resolving-device-cmyk-values">Resolving ''device-cmyk'' values</h4>
493+
492494
The computed and used value
493495
is the specified device-specific CMYK color,
494496
(with components as <<number>>, not <<percentage>>)
@@ -517,19 +519,25 @@ Resolving <<color>> Values</h3>
517519
have the used value
518520
</p>
519521
<pre class="lang-css"><span class="swatch" style="--color: rgb(93.124%, 44.098%, 57.491%)"></span> lab(63.673% 51.577 5.811)</pre>
522+
<p class="note">As with all colors, the used value is not available to script.</p>
520523
</div>
521524

522-
: [=system colors=]
523-
::
525+
<h4 id="resolving-other-colors">Resolving other colors</h4>
526+
527+
This applies to [=system colors=],
528+
[[#deprecated-system-colors]],
529+
''transparent'', and
530+
''currentcolor''.
531+
524532
Each <<system-color>> keyword computes to itself.
525533
Its used value is the corresponding color in its color space.
526534

527-
: ''currentcolor''
528-
::
535+
The computed and used value of ''transparent'' is [=transparent black=].
536+
529537
The ''currentcolor'' keyword computes to itself.
530538

531539
In the 'color' property,
532-
its used value is the [=inherited value=].
540+
the used value of ''currentcolor'' is the [=inherited value=].
533541
In any other property,
534542
its used value is the used value of the 'color' property on the same element.
535543

@@ -538,10 +546,146 @@ Resolving <<color>> Values</h3>
538546
not as the value of the 'color' property,
539547
so descendants will use their own 'color' property to resolve it.
540548

541-
The [=resolved value=] of a <<color>> is its [=used value=].
542549

543550
Issue(3845): When should channel-clamping occur?
544551

552+
<h3 id='serializing-color-values'>
553+
Serializing <<color>> Values</h3>
554+
555+
This section updates and replaces that part of CSS Object Model, section
556+
<a href="https://drafts.csswg.org/cssom-1/#serializing-css-values"> Serializing CSS Values</a>, which relates to serializing <<color>> values.
557+
558+
<h4 id="serializing-alpha-values">Serializing alpha values</h4>
559+
560+
This applies to any <<color>> value which can take an optional alpha value.
561+
562+
If the alpha is exactly 1,
563+
it is ommitted from the serialization;
564+
an implicit value of 1 (fully opaque) is the default.
565+
566+
If the alpha is any other value than 1,
567+
it is explicitly included in the serialization,
568+
as a <<number>>, not a <<percentage>>.
569+
The value is expressed in base ten,
570+
with the "." character as decimal separator.
571+
Trailing zeroes must be omitted.
572+
573+
<div class="example">
574+
<p>For example, an alpha value of 70%
575+
will be serialized as the string
576+
"0.7".
577+
</p>
578+
</div>
579+
580+
The precision with which alpha values are retained,
581+
and thus the number of decimal places in the serialised value,
582+
is not defined in this specification,
583+
but must at least be sufficient
584+
to round-trip integer percentage values.
585+
Thus, the serialised value must contain
586+
at least two decimal places
587+
(unless trailing zeroes have been removed).
588+
Values must be rounded, not truncated.
589+
590+
<div class="example">
591+
<p>For example, an alpha value of 12.3456789%
592+
may be serialized as the strings
593+
"0.12" or "0.123" or "0.1234" or "0.12346"
594+
(rounding up the value of 5 because the following digit is 6)
595+
or any longer, rounded serialisation of the same form.
596+
</p>
597+
</div>
598+
599+
600+
<h4 id="serialising-sRGB-values">Serialising sRGB values</h4>
601+
602+
The serialised form of the following sRGB values:
603+
604+
* [=hex colors=]
605+
* ''rgb()'' and ''rgba()'' values
606+
* ''hsl()'' and ''hsla()'' values
607+
* ''hwb()'' values
608+
* [=named colors=]
609+
610+
is derived from the [=computed value=] and thus,
611+
uses either the ''rgb()'' or ''rgba()'' form,
612+
with lowercase letters.
613+
614+
For compatibility, the sRGB component values
615+
are serialized in <<number>> form, not <<percentage>>).
616+
Also for compatibility,
617+
the component values are serialized in base 10,
618+
with a range of [0-255], regardless of
619+
the bit depth with which they are stored.
620+
621+
For compatibiity, if the alpha is exactly 1,
622+
the ''rgb()'' form is used,
623+
with an implicit alpha;
624+
otherwise, the ''rgba()'' form is used,
625+
with an explicit alpha value.
626+
627+
For compatibility,
628+
the legacy form with comma separators is used;
629+
exactly one ASCII space follows each comma.
630+
This includes the comma (not slash) used
631+
to separate the blue component of ''rgba()''
632+
from the alpha value.
633+
634+
635+
<div class="example">
636+
<p>For example, the serialized value of</p>
637+
<pre class="lang-css"><span class="swatch" style="--color: rgba(29, 164, 192, 0.95)"></span> rgb(29 164 192 / 95%)</pre>
638+
<p>is the string "rgba(29, 164, 192, 0.95)"</p>
639+
</div>
640+
641+
Note: contrary to CSS Color 3,
642+
the parameters of the ''rgb()'' function
643+
are of type <<number>> not <<integer>>.
644+
Thus, any higher precision than eight bits
645+
is indicated with a fractional part.
646+
647+
Trailing fractional zeroes in any component values must be suppressed;
648+
if the fractional part consists of all zeroes,
649+
the decimal point must also be suppressed.
650+
This means that sRGB colors specified with integer component values
651+
will serialize with backwards-compatible integer values.
652+
653+
The precision with which sRGB component values are retained,
654+
and thus the number of significant figures in the serialised value,
655+
is not defined in this specification,
656+
but must at least be sufficient
657+
to round-trip eight bit values.
658+
Values must be rounded, not truncated.
659+
660+
Note: authors of scripts which expect
661+
color values returned from
662+
<span style="font-family:monospace">getComputedStyle</span>
663+
to have <<integer>> component values,
664+
are advised to update them to cope with
665+
<<number>>.
666+
667+
<div class="example">
668+
<p>
669+
For example,</p>
670+
<pre class="lang-css"><span class="swatch" style="--color: rgb(57.28% 42.14% 51.46%)"></span> rgb(146.064 107.457 131.223)</pre>
671+
<p>is now valid, and equal to</p>
672+
<pre class="lang-css"><span class="swatch" style="--color: rgb(57.28% 42.14% 51.46%)"></span> rgb(57.28% 42.14% 51.46%)</pre>
673+
<p>A conformant serialized form for both,
674+
is the string "rgb(146.06, 107.46, 131.2)".</p>
675+
</div>
676+
677+
<div class="example">
678+
<p>The serialized value of </p>
679+
<pre class="lang-css"><span class="swatch" style="--color: goldenrod"></span> ''goldenrod''</pre>
680+
<p>is the string "rgb(218 165 32)"
681+
and not the string "rgb(218.000 165.000 32.000)"</p>
682+
</div>
683+
684+
685+
686+
687+
688+
545689
<h2 id='numeric-srgb'>
546690
sRGB Colors</h2>
547691

0 commit comments

Comments
 (0)