Skip to content

Commit 258a87e

Browse files
noamrkhushalsagarvmpstr
authored
[css-view-transitions-2] Specify 'view-transition-class' and corresponding algorithms (#9773)
* [css-view-transitions-2] Add 'view-transition-class' A `view-transition-class` property allows specifying view-transition pseudo-elements that apply to multiple participating elements without having to replicate them. In this PR: - Specifying `view-transition-class` - Extending the pseudo-element syntax to support `::view-transition-foo(name.class)` - Extending the capture algorithms and data structure to capture the classes - Added a simple example for using classes Based on [this resolution](#8319 (comment)). Closes #8319 --------- Co-authored-by: Khushal Sagar <63884798+khushalsagar@users.noreply.github.com> Co-authored-by: vmpstr <vmpstr@chromium.org>
1 parent acdca61 commit 258a87e

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

‎css-view-transitions-2/Overview.bs‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ spec:css-view-transitions-1;
3232
text: call the update callback; type: dfn;
3333
text: perform pending transition operations; type: dfn;
3434
text: setup view transition; type: dfn;
35+
text: named view transition pseudo-element; type: dfn;
3536
spec:dom; type:dfn; text:document
3637
spec:css22; type:dfn; text:element
38+
spec:selectors-4; type:dfn;
39+
text:selector
40+
text:type selector
3741
spec:html
3842
text: latest entry; type: dfn;
3943
text: was created via cross-origin redirects; type: dfn;
@@ -122,6 +126,8 @@ spec:infra; type:dfn; text:list
122126

123127
## Examples ## {#examples}
124128

129+
### Cross-document view-transitions ### {#cross-doc-example}
130+
125131
<div class=example>
126132
To generate the same cross-fade as in the first example [[css-view-transitions-1#examples]],
127133
but across documents, we don't need JavaScript.
@@ -199,6 +205,84 @@ spec:infra; type:dfn; text:list
199205
```
200206
</div>
201207

208+
### 'view-transition-class' ### {#vt-class-example}
209+
210+
view-transition-class provides a way to use the same style
211+
for multiple view transition pseudo elements without having to replicate the corresponding pseudo-elements.
212+
213+
<div class="example">
214+
This example creates a transition with each box participating under its own name, while applying
215+
a 1-second duration to the animation of all the boxes:
216+
217+
```html
218+
<div class="box" id="red-box"></div>
219+
<div class="box" id="green-box"></div>
220+
<div class="box" id="yellow-box"></div>
221+
```
222+
223+
```css
224+
div.box {
225+
view-transition-class: any-box;
226+
width: 100px;
227+
height: 100px;
228+
}
229+
#red-box {
230+
view-transition-name: red-box;
231+
background: red;
232+
}
233+
#green-box {
234+
view-transition-name: green-box;
235+
background: green;
236+
}
237+
#yellow-box {
238+
view-transition-name: yellow-box;
239+
background: yellow;
240+
}
241+
242+
/* The following style would apply to all the boxes, thanks to 'view-transition-class' */
243+
::view-transition-group(*.any-box) {
244+
animation-duration: 1s;
245+
}
246+
```
247+
248+
</div>
249+
250+
251+
# CSS Properties # {#css-properties}
252+
253+
## Applying the same style to multiple participating elements: the 'view-transition-class' property ## {#view-transition-class-prop}
254+
255+
<pre class=propdef>
256+
Name: view-transition-class
257+
Value: none | <<custom-ident>>*
258+
Initial: none
259+
Inherited: no
260+
Percentages: n/a
261+
Computed Value: as specified
262+
Animation type: discrete
263+
</pre>
264+
265+
The 'view-transition-class' can be used to apply the same style rule to multiple [=named view transition pseudo-elements=] which may have a different 'view-transition-name'.
266+
While 'view-transition-name' is used to match between the element in the old state with its corresponding element in the new state, 'view-transition-class' is used
267+
only to apply styles using the view-transition pseudo-elements
268+
(''::view-transition-group()'', ''::view-transition-image-pair()'', ''::view-transition-old()'', ''::view-transition-new()'').
269+
270+
Note that 'view-transition-class' by itself doesn't mark an element for capturing, it is only used as an additional
271+
way to style an element that already has a 'view-transition-name'.
272+
273+
<dl dfn-type=value dfn-for=view-transition-class>
274+
: <dfn>none</dfn>
275+
:: No class would apply to the [=named view transition pseudo-elements=] generated for this element.
276+
277+
: <dfn><<custom-ident>>*</dfn>
278+
:: All of the specified <<custom-ident>> values (apart from <css>none</css>) are applied when used in [=named view transition pseudo-element=] selectors.
279+
<css>none</css> is an invalid <<custom-ident>> for 'view-transition-class', even when combined with other <<custom-ident>>s.
280+
281+
Note: If the same 'view-transition-name' is specified for an element both in the old and new states of the transition,
282+
only the 'view-transition-class' values from the new state apply. This also applies for cross-document view-transitions:
283+
classes from the old document would only apply if their corresponding 'view-transition-name' was not specified in the new document.
284+
</dl>
285+
202286
# Pseudo-classes # {#pseudo-classes}
203287

204288
## Active View Transition Pseudo-class '':active-view-transition()''' ## {#the-active-view-transition-pseudo}
@@ -252,6 +336,34 @@ document.startViewTransition({update: updateTheDOMSomehow});
252336
```
253337
</div>
254338

339+
# Additions to named view-transition pseudo-elements # {#pseudo-element-additions}
340+
341+
The [=named view transition pseudo-elements=]
342+
(''view-transition-group()'', ''view-transition-image-pair()'', ''view-transition-old()'', ''view-transition-new()'')
343+
are extended to support the following syntax:
344+
345+
<pre class=prod>
346+
::view-transition-group(<<pt-name-selector>><<pt-class-selector>>)
347+
::view-transition-image-pair(<<pt-name-selector>><<pt-class-selector>>)
348+
::view-transition-old(<<pt-name-selector>><<pt-class-selector>>)
349+
::view-transition-new(<<pt-name-selector>><<pt-class-selector>>)
350+
</pre>
351+
352+
where <<pt-name-selector>> works as previously defined, and
353+
<<pt-class-selector>> has the following syntax definition:
354+
355+
<pre class=prod>
356+
<dfn>&lt;pt-class-selector></dfn> = ('.' <<custom-ident>>)*
357+
</pre>
358+
359+
A [=named view transition pseudo-element=] [=selector=] which has one or more <<custom-ident>> values
360+
in its <<pt-class-selector>> would only match an element if the [=captured element/class list=] value in
361+
[=ViewTransition/named elements=] for the pseudo-element's 'view-transition-name' [=list/contains=] all of those values.
362+
363+
The specificity of a [=named view transition pseudo-element=] [=selector=]
364+
with a <<pt-class-selector>>
365+
is equivalent to a [=class selector=] with the equivalent number of classes.
366+
255367
# CSS rules # {#css-rules}
256368

257369
## The <dfn id="at-view-transition-rule">''@view-transition''</dfn> rule ## {#view-transition-rule}
@@ -385,6 +497,24 @@ The {{CSSViewTransitionRule}} represents a ''@view-transition'' rule.
385497
:: Null or a [=list=] of strings, initially null.
386498
</dl>
387499

500+
## Additions to [=captured element=] struct ## {#additions-to-captured-element-struct}
501+
502+
The [=captured element=] struct should contain these fields, in addition to the existing ones:
503+
504+
<dl>
505+
: <dfn for="captured element">class list</dfn>
506+
:: a [=/list=] of strings, initially empty.
507+
</dl>
508+
509+
## Algorithms to capture 'view-transition-class': ## {#vt-class-algorithms}
510+
<div algorithm="additional capture steps">
511+
When capturing the old or new state for an element, perform the following steps given a [=captured element=] |capture| and an [=element=] |element|:
512+
513+
1. Set |capture|'s [=captured element/class list=] to the [=computed value=] of |element|'s 'view-transition-class'.
514+
515+
Note: This is written in a monkey-patch manner, and will be merged into the algorithm once the L1 spec graduates.
516+
</div>
517+
388518
## Monkey patches to HTML ## {#monkey-patch-to-html}
389519

390520
<div algorithm="monkey patch to apply the history step">

0 commit comments

Comments
 (0)