Skip to content

Commit 1796eb4

Browse files
author
Simon Pieters
committed
[cssom] Use nicer serialization for non-opaque colors and avoid excessive decimals in <number>
1 parent 6d6a1b7 commit 1796eb4

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cssom/Overview.bs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,7 @@ depends on the component, as follows:
25902590
<li>The string "<code lt>, </code>".
25912591
<li>The shortest base-ten serialization of the color's blue component.
25922592
<li>The string "<code lt>, </code>".
2593-
<li>The shortest serialization of the &lt;number&gt; that denotes the color's alpha component.
2593+
<li>The serialization of the color's alpha component as an &lt;alphavalue>.
25942594
<li>The string "<code lt>)</code>".
25952595
</ol>
25962596

@@ -2637,6 +2637,23 @@ depends on the component, as follows:
26372637
<dd>The color is <code lt>rgba(0, 0, 0, 0)</code>.
26382638
-->
26392639

2640+
<dt>&lt;alphavalue>
2641+
<dd>
2642+
If the value is internally represented as an integer between 0 and 255 inclusive (i.e. 8-bit unsigned integer),
2643+
follow these steps:
2644+
2645+
<ol>
2646+
<li>Let <var>alpha</var> be the given integer.
2647+
<li>If there exists an integer between 0 and 100 inclusive that,
2648+
when multiplied with 2.55 and rounded to the closest integer (rounding up if two values are equally close), equals <var>alpha</var>,
2649+
let <var>rounded</var> be that integer divided by 100.
2650+
<li>Otherwise, let <var>rounded</var> be <var>alpha</var> divided by 0.255 and rounded to the closest integer (rounding up if two values are equally close),
2651+
divided by 1000.
2652+
<li>Return the result of serializing <var>rounded</var> as a &lt;number>.
2653+
</ol>
2654+
2655+
Otherwise, return the result of serializing the given value as a &lt;number>.
2656+
26402657
<dt>&lt;counter>
26412658
<dd>
26422659
The return value of the following algorithm:
@@ -2684,11 +2701,12 @@ depends on the component, as follows:
26842701

26852702
<dt>&lt;number>
26862703
<dd>
2687-
A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible, using "<code lt>.</code>" to separate decimals (if any), preceded
2688-
by "<code lt>-</code>" (U+002D) if it is negative.
2704+
A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible,
2705+
using "<code lt>.</code>" to separate decimals (if any),
2706+
rounding the value if necessary to not produce more than 6 decimals,
2707+
preceded by "<code lt>-</code>" (U+002D) if it is negative.
26892708

2690-
Note: JavaScript's <code lt>ToString</code> algorithm cannot be used since it can serialize numbers using an exponent, which would not round-trip
2691-
in CSS.
2709+
Note: scientific notation is not used.
26922710

26932711
<dt>&lt;percentage>
26942712
<dd>The &lt;number> component serialized as per &lt;number> followed

0 commit comments

Comments
 (0)