Skip to content

Commit 3c8eb27

Browse files
committed
[css-images-4] Make cross-fade() accept 1+ arguments. #11530
1 parent c686523 commit 3c8eb27

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

css-images-4/Overview.bs

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,15 @@ Image Fallbacks and Annotations: the ''image()'' notation {#image-notation}
564564
565565

566566

567-
576577

577578
Combining images: the ''cross-fade()'' notation {#cross-fade-function}
@@ -647,37 +648,35 @@ Combining images: the ''cross-fade()'' notation {#cross-fade-function}
647648
648649
To determine the [=natural dimensions=] of a cross-fade():
649650

650-
1. Let |images| be an empty list.
651+
1. [=Normalize mix percentages=] from the function's arguments,
652+
and let |args| and |leftover| be the result.
653+
654+
2. If |leftover| is 100%,
655+
return no [=natural dimensions=].
651656

652-
2. For each |argument| of the ''cross-fade()'' function with an <> value:
653-
1. Let |item| be a [=tuple=] consisting of a width, a height, and a percentage.
654-
2. Run the [=object size negotiation=] algorithm for the <>,
657+
3. Let |images| be an empty list.
658+
659+
4. For each <> |argument| of the function's arguments:
660+
1. If |argument| is not an <>,
661+
or is an <> with no natural dimensions,
662+
[=iteration/continue=].
663+
2. Let |item| be a [=tuple=] consisting of a width, a height, and a percentage.
664+
3. Run the [=object size negotiation=] algorithm for the <>,
655665
as appropriate for the context in which the ''cross-fade()'' appears,
656666
and set |item|’s width and height
657667
to the width and height of the resulting [=concrete object size=].
658-
3. Set |item|’s percentage to the |argument|’s percentage.
668+
4. Set |item|’s percentage to the |argument|’s percentage.
659669

660-
3. If |images| is empty,
670+
5. If |images| is empty,
661671
return no [=natural dimensions=].
662672

663-
4. Let |percentage sum| be the sum of all the percentages of the [=list/items=] in |images|.
664-
665-
5. [=list/For each=] |item| in |images|,
666-
divide |item|’s percentage by |percentage sum|,
667-
and set |item|’s percentage to the result.
673+
6. Return a [=natural width=] and [=natural height=]
674+
that are weighted averages of the width and height
675+
of each item in |images|,
676+
according to their corresponding percentages.
668677

669-
Assert: The percentages in |images| now sum to ''100%''.
670-
671-
6. Let |final width| and |final height| be ''0px''.
672-
673-
7. [=list/For each=] |item| in |images|,
674-
multiply |item|’s width by |item|’s percentage
675-
and add the result to |final width|,
676-
and multiply |item|’s height by |item|’s percentage
677-
and add the result to |final height|.
678-
679-
8. Return a [=natural width=] of |final width|
680-
and a [=natural height=] of |final height|.
678+
Note: The percentages might sum to a value less than 100%,
679+
so a naive weighted-averaging process might need to normalize them first.
681680
682681

683682
### ''cross-fade()'' Painting ### {#cross-fade-painting}
@@ -686,10 +685,12 @@ Combining images: the ''cross-fade()'' notation {#cross-fade-function}
686685
is a weighted average of the input arguments to the function,
687686
calculated as follows:
688687

689-
690688
691689
To determine the appearance of a cross-fade():
692690

691+
1. [=Normalize mix percentages=] from the function's arguments,
692+
and let |args| and |leftover| be the result.
693+
693694
1. Let |images| be an empty list.
694695

695696
2. Let |size| be a [=tuple=] of width and height,
@@ -707,19 +708,11 @@ Combining images: the ''cross-fade()'' notation {#cross-fade-function}
707708
with |size|’s dimensions.
708709
3. Set |item|’s percentage to the |argument|’s percentage.
709710

710-
4. Let |percentage sum| be the sum of all the percentages of the [=list/items=] in |images|.
711-
712-
5. If |percentage sum| is less than ''100%'',
711+
5. If |leftover| is greater than ''0%'',
713712
append a [=tuple=] to |images|
714713
consisting of a solid-color transparent-black image
715714
with |size|’s dimensions,
716-
and a percentage equal to ''100%'' minus |percentage sum|.
717-
718-
Otherwise,
719-
if |percentage sum| is greater than ''100%'',
720-
then [=list/for each=] |item| in |images|,
721-
divide |item|’s percentage by |percentage sum|,
722-
and set |item|’s percentage to the result.
715+
and a percentage equal to |leftover|.
723716

724717
6. Let |final image| be an image
725718
with |size|’s dimensions,

0 commit comments

Comments
 (0)