Skip to content

Commit d49b54a

Browse files
committed
[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](w3c#8319 (comment)). Closes w3c#8319
1 parent e62445c commit d49b54a

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

css-view-transitions-1/Overview.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ urlPrefix: https://wicg.github.io/navigation-api/; type: interface;
11681168

11691169
### [=Captured elements=] ### {#captured-elements}
11701170

1171-
A <dfn>captured element</dfn> is a [=struct=] with the following:
1171+
A <dfn export>captured element</dfn> is a [=struct=] with the following:
11721172

11731173
<dl dfn-for="captured element">
11741174
: <dfn>old image</dfn>

css-view-transitions-2/Overview.bs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ spec:css-view-transitions-1;
3434
text: setup view transition; type: dfn;
3535
spec:dom; type:dfn; text:document
3636
spec:css22; type:dfn; text:element
37+
spec:selectors-4; type:dfn;
38+
text:selector
39+
text:type selector
3740
spec:html
3841
text: latest entry; type: dfn;
3942
text: was created via cross-origin redirects; type: dfn;
@@ -199,6 +202,83 @@ spec:infra; type:dfn; text:list
199202
```
200203
</div>
201204

205+
### Example of using 'view-transition-class' ### {#vt-class-example}
206+
207+
In addition to cross-document view-transitions, this document specifies a way to use the same view-transition style
208+
for multiple elements without having to replicate the corresponding pseudo-elements.
209+
210+
<div class="example">
211+
This example creates a transition with each box participating under its own name, while applying
212+
a 1-second duration to the animation of all the boxes:
213+
214+
```html
215+
<div class="box" id="red-box"></div>
216+
<div class="box" id="green-box"></div>
217+
<div class="box" id="yellow-box"></div>
218+
```
219+
220+
```css
221+
div.box {
222+
view-transition-class: any-box;
223+
width: 100px;
224+
height: 100px;
225+
}
226+
#red-box {
227+
view-transition-name: red-box;
228+
background: red;
229+
}
230+
#green-box {
231+
view-transition-name: green-box;
232+
background: green;
233+
}
234+
#yellow-box {
235+
view-transition-name: yellow-box;
236+
background: yellow;
237+
}
238+
239+
/* The following style would apply to all the boxes, thanks to 'view-transition-class' */
240+
::view-transition-group(*.any-box) {
241+
animation-duration: 1s;
242+
}
243+
```
244+
245+
</div>
246+
247+
248+
# CSS Properties # {#css-properties}
249+
250+
## Applying the same style to multiple participating elements: the 'view-transition-class' property ## {#view-transition-class-prop}
251+
252+
<pre class=propdef>
253+
Name: view-transition-class
254+
Value: none | <<custom-ident>>*
255+
Initial: none
256+
Inherited: no
257+
Percentages: n/a
258+
Computed Value: as specified
259+
Animation type: discrete
260+
</pre>
261+
262+
The 'view-transition-class' works alongside 'view-transition-name', and is read at the same time
263+
'view-transition-name' is read. But unlike 'view-transition-name', 'view-transition-class' doesn't
264+
have to be unique - an element can have several view-transition classes, and the same 'view-transition-class'
265+
can apply to multiple elements. While 'view-transition-name' is used to match between the element
266+
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+
<dl dfn-type=value dfn-for=view-transition-class>
271+
: <dfn>none</dfn>
272+
:: No class would apply to the [=/element=], and pseudo-elements would have to match its 'view-transition-name'.
273+
274+
: <dfn><<custom-ident>>*</dfn>
275+
:: All of the specified <<custom-ident>> values (apart from <css>none</css>) apply as classes for the [=/element=].
276+
277+
Note: If the same 'view-transition-name' is specified for an element both in the old and new states of the transition,
278+
only the 'view-transition-class' values from the new state apply. This also applies for cross-document view-transitions:
279+
classes from the old document would only apply if their corresponding 'view-transition-name' was not specified in the new document.
280+
</dl>
281+
202282
# Pseudo-classes # {#pseudo-classes}
203283

204284
## Active View Transition Pseudo-class '':active-view-transition()''' ## {#the-active-view-transition-pseudo}
@@ -252,6 +332,34 @@ document.startViewTransition({update: updateTheDOMSomehow});
252332
```
253333
</div>
254334

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

257365
## The <dfn id="at-view-transition-rule">''@view-transition''</dfn> rule ## {#view-transition-rule}
@@ -385,6 +493,27 @@ The {{CSSViewTransitionRule}} represents a ''@view-transition'' rule.
385493
:: Null or a [=list=] of strings, initially null.
386494
</dl>
387495

496+
## Additions to [=captured element=] struct ## {#additions-to-captured-element-struct}
497+
498+
<dl>
499+
: <dfn for="captured element">class list</dfn>
500+
:: a [=/list=] of strings, initially empty.
501+
</dl>
502+
503+
## Additions to capture algorithms: ## {#additions-to-capture-algorithms}
504+
<div algorithm="capture old classes">
505+
When capturing the old state of the view transition, perform the following step when iterating on |captureElements| given |element| and |capture|:
506+
507+
1. Set |capture|'s [=captured element/class list=] to the [=computed value=] of |element|'s 'view-transition-class'.
508+
509+
</div>
510+
511+
<div algorithm="capture new classes">
512+
When capturing the new state of the view transition, perform the following step when iterating on |captureElements| given |element| and |namedElements|:
513+
514+
1. Set |namedElement|[|transitionName|]'s [=captured element/class list=] to the [=computed value=] of |element|'s 'view-transition-class'.
515+
</div>
516+
388517
## Monkey patches to HTML ## {#monkey-patch-to-html}
389518

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

0 commit comments

Comments
 (0)