Skip to content

Commit 426ae64

Browse files
authored
Merge pull request #7029 from SebastianZ/stripes-function
[css-images-4][css-backgrounds-4] Added stripes() function The definition of 1-dimensional images was added together with a `stripes()` function. This function is then used for `border-*-color` and `outline-color` to allow multi-color borders and outlines.
2 parents 6689fac + d316d16 commit 426ae64

File tree

3 files changed

+132
-24
lines changed

3 files changed

+132
-24
lines changed

css-backgrounds-4/Overview.bs

+10-11
Original file line numberDiff line numberDiff line change
@@ -185,30 +185,28 @@ Painting Area: the 'background-clip' property</h3>
185185

186186
<pre class=propdef>
187187
Name: border-top-color, border-right-color, border-bottom-color, border-left-color
188-
Value: <<color>>#
188+
Value: <<color>> | <<1d-image>>
189189
Initial: currentcolor
190190
Applies to: all elements
191191
Inherited: no
192192
Percentages: n/a
193-
Computed Value: the computed color
193+
Computed Value: the computed color and/or a one-dimensional image function
194194
Animation type: see prose
195195
</pre>
196196

197197
<pre class="propdef shorthand">
198198
Name: border-color
199-
Value: <<color>>#{1,4}
199+
Value: [ <<color>> | <<1d-image>> ]{1,4}
200200
</pre>
201201

202202
These properties set the foreground color of the border specified
203203
by the 'border-style' properties.
204-
If a list of values is provided, the border is split into equal width bands of each color
205-
along the direction of the side the border is applied on
206-
(i.e. split horizontally on left and right borders and vertically on top and bottom borders),
207-
starting outwards.
208204

209-
When interpolating between borders with the same number of colors,
210-
interpolation is performed individually per color band as <a href="https://www.w3.org/TR/css3-transitions/#animtype-color">color</a>.
211-
Interpolation between borders with different numbers of colors is discrete.
205+
The stripes defined by <<1d-image>> follow the shape of the border
206+
on the side to which they apply,
207+
and are drawn in bands starting from the [=padding edge=] and progressing outwards.
208+
With that, the corresponding 'border-*-width' property defines the total
209+
width of the stripes.
212210

213211
'border-color' is a shorthand for the four 'border-*-color' properties.
214212
The four values set the top, right, bottom and left border, respectively.
@@ -223,7 +221,7 @@ Painting Area: the 'background-clip' property</h3>
223221
<pre class=lang-css>
224222
.foo {
225223
border: 30px solid;
226-
border-color: skyblue orange yellowgreen indianred, black yellow;
224+
border-color: stripes(skyblue, black) stripes(orange, yellow) stripes(yellowgreen, black) stripes(indianred, yellow);
227225
}
228226
</pre>
229227

@@ -702,6 +700,7 @@ Additions Since Level 3</h3>
702700
<li>logical 'background-position' values (''background-position/start'', ''background-position/end'')
703701
<li>the ''extend'' keyword of 'background-repeat'
704702
<li>'corner-shape'
703+
<li><<1d-image>> as value for ''border-color'' and its longhands
705704
<li>multiple border colors per border
706705
<li>logical border properties
707706
<li><a href="#partial-borders">Partial Borders</a> (make part of border shorthand as well!)

css-images-4/Overview.bs

+114-9
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,6 @@ Cycle Detection</h4>
11161116
If the graph contains a cycle,
11171117
any ''element()'' functions participating in the cycle are <a>invalid images</a>.
11181118

1119-
1120-
1121-
11221119
<!--
11231120
██████ ████████ ███ ████████ ████ ████████ ██ ██ ████████ ██████
11241121
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
@@ -1897,15 +1894,90 @@ Color Stop “Fixup”</h4>
18971894
</pre>
18981895
</div>
18991896

1900-
1901-
1897+
<!--
1898+
██████ ████████ ████████ ████ ████████ ███████ ██████ ███ ███
1899+
██ ██ ██ ██ ██ ██ ██ ██ █ ██ ██ ██ ██
1900+
██ ██ ██ ██ ██ ██ ██ █ ██ ██ ██
1901+
██████ ██ ████████ ██ ████████ █████ ██████ ██ ██
1902+
██ ██ ██ ██ ██ ██ █ ██ ██ ██
1903+
██ ██ ██ ██ ██ ██ ██ █ ██ ██ ██ ██
1904+
██████ ██ ██ ██ ████ ██ ███████ ██████ ███ ███
1905+
-->
19021906

19031907
1D Image Values: the ''stripes()'' notation {#stripes}
19041908
======================================================
19051909

1906-
Issue: <a href="https://github.com/w3c/csswg-drafts/issues/2532">Per WG resolution</a>,
1907-
define the ''stripes()'' function
1908-
which creates a 1D image for use in borders/outlines.
1910+
While most <<image>> values represent a 2-dimensional image,
1911+
and <<color>> can be thought of as a "0-dimensional" image
1912+
(unvarying in either axis),
1913+
there are some contexts where a 1-dimensional image makes sense,
1914+
specifying colors along a <dfn export>paint line</dfn>
1915+
without defining a <em>direction</em> for the line.
1916+
The <<1d-image>> type represents such images.
1917+
1918+
<pre class=prod>
1919+
<dfn>&lt;1d-image></dfn> = <<stripes()>>
1920+
<dfn>stripes()</dfn> = stripes( <<color-stripe>># )
1921+
<dfn>&lt;color-stripe></dfn> = <<color>> && [ <<length-percentage>> | <<flex>> ]?
1922+
</pre>
1923+
1924+
The ''stripes()'' function defines a 1d-image
1925+
as a number of colored stripes with different widths.
1926+
1927+
Each comma-separated entry defines a solid-color stripe,
1928+
each placed end-to-end on the [=paint line=] in the order given,
1929+
with the specified <<color>> and thickness.
1930+
If the thickness is omitted,
1931+
it defaults to ''1fr''.
1932+
1933+
In each entry, a <<percentage>> is relative to the |painting area|
1934+
and must be between ''0%'' and ''100%'' inclusive
1935+
or else the function is invalid.
1936+
A <<flex>> is evaluated as a fraction of the |painting area|
1937+
relative to the total sum of <<flex>> entries in the function,
1938+
after subtracting the thickness of any non-<<flex>> entries
1939+
(flooring the subtraction result at zero).
1940+
If the sum of <<flex>> values is less than 1fr,
1941+
the result of the subtraction is multiplied by the sum's value
1942+
before being distributed.
1943+
1944+
<div class=example>
1945+
For example,
1946+
''stripes(red 1fr, green 2fr, blue 100px)``
1947+
with a |painting area| of ''400px''
1948+
will result in a 100px red stripe and 200px green stripe,
1949+
giving red 1 share and green 2 shares of the 300px remaining
1950+
after subtracting blue's 100px from the 400px total.
1951+
1952+
On the other hand,
1953+
''stripes(red .1fr, green .2fr, blue 100px)``
1954+
with a |painting area| of ''400px''
1955+
will instead give a 30px red stripe and 60px green stripe,
1956+
followed by 100px of blue and then 210px of transparent.
1957+
The 300px of leftover space is multiplied by .3,
1958+
the value of the sum of the <<flex>> values,
1959+
to obtain only 90px,
1960+
which is then distributed in the 1:2 ratio
1961+
the <<flex>> values would dictate.
1962+
1963+
(This is similar to how [=flex layout=] deals with small <<flex>> sums on a line,
1964+
and ensures smoothly continuous behavior
1965+
as the <<flex>> values approach zero.)
1966+
</div>
1967+
1968+
The |painting area| is defined by the context in which the ''stripes()'' function is used.
1969+
If used generically as an <<image>>,
1970+
the |painting area| is the height of the [=concrete image size=].
1971+
1972+
If the sum thickness of the stripes is smaller than the |painting area|,
1973+
the [=paint line=] is [=transparent black=] for its remaining length,
1974+
as if a final ''transparent'' argument were given.
1975+
If the sum thickness is larger,
1976+
any stripes or portions thereof that would be past the end of the [=paint line=] have no effect.
1977+
1978+
The computed value of this function is the [=specified value=]
1979+
with all <<color>>s computed
1980+
and all <<length-percentage>>s absolutized and computed to the extent possible.
19091981

19101982
<!--
19111983
██████ ████ ████████ ████ ██ ██ ██████
@@ -2393,6 +2465,39 @@ Interpolating <<gradient>> {#interpolating-gradients}
23932465
Then, for each pair of color-stops,
23942466
interpolate the position and color independently.
23952467

2468+
Interpolating <<1d-image>> {#interpolating-1d-images}
2469+
-----------------------------------------------
2470+
2471+
Similar to <a lt="interpolating-gradients">gradient images</a>,
2472+
one-dimensional images can be interpolated directly in CSS transitions and animations,
2473+
smoothly animating from one image to another.
2474+
There are only a few restrictions on what images are allowed to be interpolated:
2475+
2476+
1. Both the starting and ending image must have the same number of <<color-stripe>>s.
2477+
2478+
2. Neither image uses a combination of <<length>>, <<percentage>>, and <<flex>> stripes.
2479+
2480+
If the two image satisfy both constraints,
2481+
they must be interpolated as described below.
2482+
If they fail the second one only,
2483+
they must be abruptly transitioned at 50%
2484+
(unless otherwise specified by a future specification).
2485+
If they fail the first constraint,
2486+
they must be interpolated using ''cross-fade()''
2487+
as for generic images.
2488+
2489+
Note: The abrupt transition at 50% is so that content will not rely on cross-fading,
2490+
and smarter interpolation rules can be added for this case in the future.
2491+
2492+
1. Interpolate each component and stripe of the images independently.
2493+
2494+
2. To interpolate a stripe,
2495+
first match each stripe in the start image
2496+
to the corresponding stripe at the same index in the end image.
2497+
Then, for each pair of stripes,
2498+
interpolate the <a href="https://www.w3.org/TR/css3-transitions/#animtype-length">thickness</a>
2499+
and <a href="https://www.w3.org/TR/css3-transitions/#animtype-color">color</a> independently.
2500+
23962501
<!--
23972502
██████ ████████ ████████ ████ ███ ██ ████ ████████ ███ ████████ ████ ███████ ██ ██
23982503
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
@@ -2471,7 +2576,7 @@ Changes {#changes}
24712576
- Switched color-stop grammar to repeat at end for readability
24722577
- Clarified that object-fit and image-resolution use discrete animation
24732578
- Fixed definition of cross-fade() image blending
2474-
- Added placeholder section for the stripes() function
2579+
- Added &lt;1d-image> data type and stripes() function and added &1d-image> to &lt;image> data type
24752580
- Moved interpolation of images from [[css3-images]]
24762581
- Clarifed that cross-fade() takes 1+ arguments. Defined sizing and painting of the new function arguments in detail.
24772582
- Moved cross-fade() from [[css3-images]]

css-ui-4/Overview.bs

+8-4
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,14 @@ Animation type: by computed value
287287

288288
<pre class="propdef">
289289
Name: outline-color
290-
Value: <<color>> | invert
290+
Value: [ <<color>> | <<1d-image>> ] | invert
291291
Initial: invert
292292
Applies to: all elements
293293
Inherited: no
294294
Percentages: N/A
295295
Computed value: The computed value for ''outline-color/invert'' is ''outline-color/invert''.
296-
For <<color>> values, see [[!CSS-COLOR-4#resolving-color-values]] in [[!CSS-COLOR-4]].
296+
For <<color>> values, see [[css-color-4#resolving-color-values]] in [[!CSS-COLOR-4]].
297+
For <<1d-image>> values, see [[css-images-4#stripes]] in [[!CSS-IMAGES-4]].
297298
Animation type: by computed value
298299
</pre>
299300

@@ -752,7 +753,7 @@ Values have the following meanings:
752753

753754
Note: This specification does not define
754755
how the coordinate systems of the various types of <<image>> are established,
755-
and defers these definitions to [[CSS4-IMAGES]].
756+
and defers these definitions to [[CSS-IMAGES-4]].
756757

757758
If the values are unspecified,
758759
then the natural hotspot defined inside the image resource itself is used.
@@ -2541,12 +2542,15 @@ the following normative changes have been made:
25412542

25422543
<ul>
25432544
<li>
2544-
Introduce a definition for the 'pointer-events' property.
2545+
Introduced a definition for the 'pointer-events' property.
25452546

25462547
<li>
25472548
Extend the image types required to be supported for the 'cursor' property
25482549
from just <<url>> to <<url>> and <<url-set>>.
25492550
(Support for the broader <<image>> type remains allowed but optional.)
2551+
2552+
<li>
2553+
Added <<1d-image>> as value for the 'outline-color' property.
25502554
</ul>
25512555

25522556
<h3 id=changes-24-1-2020 class=no-num>Changes from the

0 commit comments

Comments
 (0)