Skip to content

Commit bb17db9

Browse files
committed
clarifying API levels
1 parent 7527abc commit bb17db9

13 files changed

Lines changed: 113 additions & 48 deletions

File tree

astro.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ function sidebar() {
135135
items: [
136136
{ label: 'Test Your Browser', link: "/basics/test-page/" },
137137
{ label: 'View Transition API', link: "/basics/api/" },
138-
{ label: 'Web Framework Support', link: "/basics/frameworks/", badge: { text: 'New!', variant: 'success' } as Badge },
139-
140138
{
141139
label: 'View Transition Examples', link: "/basics/examples/",
142140
},
143141
{ label: 'Names and Pseudo-Elements', link: "/basics/pseudos/" },
144142
{ label: 'Mechanics of Default Animations', link: "/basics/default-animations/" },
145143
{ label: 'Styling View Transitions', link: "/basics/styling/" },
146144
{ label: 'JavaScript API', link: "/basics/javascript/" },
147-
{ label: "Playing Hide & Seek", link: "/basics/hide-and-seek/" }
145+
{ label: "Playing Hide & Seek", link: "/basics/hide-and-seek/" },
146+
{ label: 'API Levels and Implications', link: "/basics/levels/", badge: { text: 'New!', variant: 'success' } as Badge },
147+
{ label: 'Web Framework Support', link: "/basics/frameworks/"}
148148
]
149149
}, {
150150
label: 'Tools',

src/components/TestPage.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
document.documentElement.setAttribute("sdvt", "");
8888
"navigation" in window &&
8989
document.documentElement.setAttribute("nav", "");
90+
CSS.supports("view-transition-class", "mine") &&
91+
document.documentElement.setAttribute("vtc", "");
9092
CSS.supports("view-transition-name", "auto") &&
9193
document.documentElement.setAttribute("vtna", "");
9294
CSS.supports("view-transition-group", "g") &&

src/content/docs/basics/api.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ While I add more pages, I'm also happy that I can offer some links to previous w
2626

2727

2828
### W3C Drafts (Preliminary Specs)
29-
* Level 1: The W3C Candidate Recommendation Snapshot: *CSS View Transitions Module Level 1* [https://drafts.csswg.org/css-view-transitions-1/](https://drafts.csswg.org/css-view-transitions-1/)
3029

31-
* Level 2: The Editor's Draft: *CSS View Transitions Module Level 2* [https://drafts.csswg.org/css-view-transitions-2/](https://drafts.csswg.org/css-view-transitions-2/)
30+
* Level 1: *CSS View Transitions Module Level 1* (Editor's Draft) [https://drafts.csswg.org/css-view-transitions-1/](https://drafts.csswg.org/css-view-transitions-1/)
31+
32+
* Level 2: *CSS View Transitions Module Level 2* (Editor's Draft) [https://drafts.csswg.org/css-view-transitions-2/](https://drafts.csswg.org/css-view-transitions-2/)
3233

3334
### MDN
3435
* The Documentation of the View Transition API on MDN [https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)

src/content/docs/basics/javascript.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ head:
88
content: "/javascript-og.png"
99
---
1010

11-
Browser-native cross-document view transitions can be created entirely with CSS, without the need for JavaScript. However, JavaScript becomes essential for advanced functionality, such as:
11+
Browser-native cross-document view transitions can be [created entirely with CSS](#cross-document-view-transitions), without the need for JavaScript. However, even for cross-document view transitions, JavaScript becomes essential for advanced functionality. And for same-document view transitions, even the activation is done via JavaScript:
1212

1313
- Triggering same-page view transitions with `startViewTransition()`,
1414
- Dynamically modifying CSS properties like `view-transition-name`,
@@ -141,6 +141,14 @@ Rumor has it that the root element of the scoped view transition needs to have i
141141

142142
## Cross-Document View Transitions
143143

144+
You activate cross-document view transitions by adding the following incantation to the styles of all pages that should participate in view transitions:
145+
```css
146+
@view-transition{
147+
navigation: auto;
148+
}
149+
```
150+
Opting in to cross-document view transitions is CSS-only. But cross-document view transitions, too, have their JavaScript API.
151+
144152
Cross-document view transitions work similarly to [same-document](#same-document-view-transitions) ones but are triggered by navigation. In particular you can get access to the [view transition object](#viewtransition-object) in event listeners for the new `pageswap` and `pagereveal` events.
145153

146154
### Pageswap and Pagereveal Events
@@ -162,4 +170,4 @@ Similarly, `pagereveal` listeners allow you to tweak view transition names and t
162170

163171
### Activation Object
164172

165-
The `pageswap` event also provides a `NavigationActivation` object via its `activation` property, offering details about the current page (`from`) and next page (`entry`). While the `pagereveal` event does not include this property, in browsers supporting the Navigation API, you can use `navigation.activation` to access information about the previous page (`from`) and current page (`entry`).
173+
The `pageswap` event also provides a [`NavigationActivation`](https://developer.mozilla.org/en-US/docs/Web/API/NavigationActivation) object via its `activation` property, offering details about the current page (`from`) and next page (`entry`). While the `pagereveal` event does not include this property, in browsers supporting the Navigation API, you can use `navigation.activation` to access information about the previous page (`from`) and current page (`entry`).

src/content/docs/basics/levels.mdx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: API Levels and Implications
3+
description: What are those levels of the View Transition API, and what does that mean for me as a dev?
4+
head:
5+
- tag: meta
6+
attrs:
7+
property: "og:image"
8+
content: "/bag-og.png"
9+
---
10+
The (preliminary) View Transition API's specification comes in two parts:
11+
12+
13+
* Level 1: *CSS View Transitions Module Level 1* (Editor's Draft) [https://drafts.csswg.org/css-view-transitions-1/](https://drafts.csswg.org/css-view-transitions-1/)
14+
15+
* Level 2: *CSS View Transitions Module Level 2* (Editor's Draft) [https://drafts.csswg.org/css-view-transitions-2/](https://drafts.csswg.org/css-view-transitions-2/)
16+
17+
Splitting the specification into two parts allows browser vendors to roll out the API incrementally.
18+
19+
You might often hear that
20+
* Level 1 is _same-document_ view transitions and
21+
* Level 2 defines _cross-document_ view transitions
22+
23+
It is a neat, memorable way to explain it. Half‑true, slightly wrong, but sticky enough to spread. Just do not forget: the real implications still hide in the details.
24+
25+
I prefer to think of Level 1 as the core and Level 2 as the extensions.
26+
27+
## Level 1: Core Features
28+
29+
The essentials boil down to these core features:
30+
* The [`view-transition-name`](/basics/pseudos/#view-transition-names) CSS property to mark elements that should participate in the view transition.
31+
* The [`document.startViewTransition()`](/basics/javascript/#startviewtransition) function that takes an update callback and returns a `ViewTransition` object with three promises (`updateCallbackDon`, `ready`, `finished`) and the `skipTransition()` function.
32+
* [Pseudo-elements](/basics/pseudos/#types-of-pseudo-elements) and selectors to capture, structure and style before and after images: `::view-transition`, `::view-transition-group`, `::view-transition-image-pair`, `::view-transition-old` and `::view-transition-new`
33+
* Additions to the user [agent stylesheet and dynamically generated animations](/basics/styling/#the-user-agent-stylesheet).
34+
* Some rules when view transitions automatically get skipped, e.g. on resize events or view transition start while another view transition is still active.
35+
36+
## Level 2: Extensions
37+
Part two indeed adds extensions for cross-document view transitions, but also features that come extremely handy for same-document, even though they are no core features.
38+
39+
### Cross-Document
40+
* The `@view-transition{ navigation: auto }` at-rule to opt in to [cross-document view transitions](/basics/javascript/#cross-document-view-transitions).
41+
* `pageswap` and `pagereveal` [events](/basics/javascript/#pageswap-and-pagereveal-events) that give access to the view transition object on the old and new page.
42+
* An [`activation`](/basics/javascript/#activation-object) property on `pageswap` holds a `NavigationActivation` object from the Navigation API, even if the browser doesn't otherwise support the Navigation API. But there is nothing equivalent on `pagereveal`.
43+
44+
### Extensions for Both, Same- and Cross-Document
45+
* The [`view-transition-class`](/basics/styling/#with-classes) property and selector syntax to address multiple pseudo-elements with a single selector.
46+
* [View transition types](/basics/styling/#with-types) being part of the ViewTransition object, the `startViewTransition()` signature, and the `@view-transition{ }` at-rule; as well as matching pseudo-class selector `:active-view-transition-type()` and the type-less `:active-view-transition`.
47+
* [Generated view transition names](/basics/pseudos/#auto-generated-names-auto-and-match-element) with `view-transition-name: auto` and `view-transition-name: match-element`.
48+
* [Nested view transition groups](/basics/pseudos/#nested-view-transition-groups) with the `::view-transition-group-children()` pseudo element.
49+
50+
## Future extensions
51+
52+
* [Scoped view transitions](/basics/javascript/#scoped-view-transitions)
53+
54+
55+
56+
## Implications
57+
58+
The new features defined in Level 2 of the view transition API are in deed written as extensions to the Level 1 spec. They can easily be merged into one specification. But the interesting part here is not the document structure but the implication from incremental releasing of the two parts.
59+
60+
Up to now, all vendors have implemented and released Level 1 first before they went on to Level2. For Chrome and Edge there was a period of over 12 month before level 2 got released. For Safari, it had been 3 month. Now Firefox is actively working on Level 1 of the API as it is part of Interop 2025. It's unclear when Level 2 will be released.
61+
62+
For the Chromium based browsers, this was not a problem as when they released Level 1 support there where no othr browsers that understood Level 2. When Safari came out, this was different, but it did not take that lon for them to deliver Level 2 after that.
63+
64+
### Same-Document Features Missing in Level 1
65+
The problem is not same-document vs. cross-document. The problem is that there are browser versions out there in the wild that support only Level 1 of the API. To say it more clearly: Soon you can use same-document view transitions on all major browsers, but if you want to support them all, you can't use the extensions from the Level 2 list above.
66+
67+
This might be obvious for the more experimental stuff like nested view transition groups or scoped view transitions.
68+
69+
But for simple same-document view transitions, there are some highly desirable features that we cannot use cross-browser before Level 2 becomes baseline.
70+
- no view transition classes
71+
- no view transition types
72+
- no auto-generated view transition names
73+
74+
Of course, there is no guarantee that it comes that bad:
75+
* Firefox Nightly already seems to have support for `view-transition-class`. So this should not become a problem.
76+
* When usings the [declarative-names script](/tools/utensil-drawer/#declarative-names) from The Bag's utensil-drawer, you have an alternative for dynamically generating view transition names that work more reliably than `view-transition-name: auto`.
77+
* I started a polyfill to use view transition types even on browsers that only support Level 1.
78+
Let's keep our fingers crossed.

src/content/docs/basics/pseudos.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ main {
164164

165165
At the start of the view transition, the **view transition names have to be unique** in the DOM.
166166

167-
There is an important exception: The View Transition API will ignore the `view-transition-name` of an element if that element is not rendered. For instance, you can use the same `view-transition-name` multiple times within the same DOM, provided that all but one instance have their `display` CSS property set to `none`. This technique is utilized in the intra-document [image morph examples](/basics/examples/#image-morph-examples) on this site.
167+
There are two exceptions:
168+
- The API ignores the `view-transition-name` of a fragmented element, i.e. an element that consists of two or more boxes, like an inline element that spans two lines.
169+
170+
- The API ignores the `view-transition-name` of an element if that element is not rendered, like the `<head>`, or if it is skipped. For instance, you can use the same `view-transition-name` multiple times within the same DOM, provided that all but one instance have their `display` CSS property set to `none`. Looking for an example? This technique is utilized in the intra-document [image morph examples](/basics/examples/#image-morph-examples) on this site. This trick also works with an ancestor with `content-visibility: hidden` but not with a simple `visibility: hidden` directly on the element.
168171

169172

170173
The static user agent stylesheet provides one default name for the document, called `root`.

src/content/docs/basics/styling.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ If both, the old image and the new image for `x` exist, the API defines a [morph
104104
```css
105105
::view-transition-group(x) {
106106
animation-name: -ua-view-transition-group-anim-x;
107-
animation-duration: 0.25s;
108-
animation-delay: 0s;
109-
animation-fill-mode: both;
107+
animation-duration: <inherited>;
108+
animation-delay: <inherited>;
109+
animation-fill-mode: <inherited>;
110110
}
111111
@keyframes -ua-view-transition-group-anim-x {
112112
0% {

src/content/docs/basics/test-page.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This page shows whether your current browser <span id="browser"></span>has nativ
2020
| [Cross-document view transitions](https://drafts.csswg.org/css-view-transitions-2) | <span id="cdvt"/> |
2121
| [Navigation API](https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API) | <span id="nav"/> |
2222
| [PageSwapEvent.activation.\*.index](https://drafts.csswg.org/css-view-transitions-2/#old-doc-event) | <span id="idx"/> |
23+
| [view-transition-class](https://drafts.csswg.org/css-view-transitions-2/#view-transition-class-prop) | <span id="vtc"/> |
2324
| [view-transition-name: auto](https://drafts.csswg.org/css-view-transitions-2/#additions-to-vt-name) | <span id="vtna"/> |
2425
| [Nested view transition groups](https://drafts.csswg.org/css-view-transitions-2/#view-transition-group-prop) | <span id="vtg"/> |
2526
| [View transition group children](https://drafts.csswg.org/css-view-transitions-2/#view-transition-group-children-pseudo) | <span id="vtgc"/> |
@@ -42,6 +43,7 @@ For browser compatibility data regarding the View Transition API see [the mdn pa
4243
#psvt,
4344
#prvt,
4445
#vtna,
46+
#vtc,
4547
#vtg,
4648
#vtgc,
4749
#idx,
@@ -57,6 +59,7 @@ For browser compatibility data regarding the View Transition API see [the mdn pa
5759
:root[nav] #nav,
5860
:root[svt] #psvt,
5961
:root[rvt] #prvt,
62+
:root[vtc] #vtc,
6063
:root[vtg] #vtg,
6164
:root[vtgc] #vtgc,
6265
:root[vtna] #vtna,

src/content/docs/fwvt/customizing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Now it is time to ask why all the pseudo-element names we saw in this episode en
248248

249249
View transition names tell the View Transition API to generate a `::view-transition-group` pseudo element for the DOM element the name is assigned to. So with more view transition names, there will be multiple `:view-transition-group` elements and the view transition name is used to distinguish them. Therefore, the view transition names, for which the API generates groups, must be unique on a page. The API won't generate groups for elements that are not rendered[^i]. So the rule in truth is: View transition names for displayed DOM elements must be unique on a page.
250250

251-
[^i]: "not rendered" here means `display: none`. Just being clipped or hidden by `visibility: hidden`, `overflow: ...` or being obscured by other elements does not hinder group generation.
251+
[^i]: "not rendered" here means `display: none`, or `content-visibility: hidden`. Just being clipped or hidden by `visibility: hidden`, `overflow: ...` or being obscured by other elements does not hinder group generation.
252252

253253
That the whole view port is assigned the `root` name is another default from the useragent stylesheet:
254254

src/content/docs/fwvt/playing.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,10 @@ startViewTransition({update, types: ["some-type"]});
636636
```
637637
You can use this to guard animations of the pseudo-elements, but you can even use it to _define_ the pseudo-elements by setting view transition names nested inside the type guarded rule. And of course you can use this pattern to style regular DOM elements _just for the time_ a certain view transition is active.
638638

639-
:::caution
639+
:::note
640640
This pattern will likely break in Firefox once it adds support for Level 1 of the View Transition API.
641+
But I'm already working on a polyfill. For an explanation and more on this pattern, check the [CSS Tips & Tricks](/tips/css/#scoping-with-types) section.
641642
:::
642-
For an explanation and more on this pattern, check the [CSS Tips & Tricks](/tips/css/#scoping-with-types) section.
643643

644644
### Changing Group Stacking Order
645645
With the View Transition API, the [stacking order](/basics/pseudos/#rendering-pseudo-elements) of the `::view-transition-group` pseudo-elements corresponds to the paint order of the named elements on the old page, then followed by those only on the new page, also in paint order.

0 commit comments

Comments
 (0)