From dcec6d3e76900cb3b09efd44e8322e0620c756ee Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Mon, 20 Oct 2025 00:56:45 +0200 Subject: [PATCH] api updates --- src/components/TestPage.astro | 1 + src/content/docs/basics/api.mdx | 5 ++- src/content/docs/basics/javascript.mdx | 47 ++++++++++++++++---------- src/content/docs/basics/pseudos.mdx | 6 +++- src/content/docs/basics/test-page.mdx | 7 ++-- src/content/docs/fwvt/customizing.mdx | 4 +-- src/content/docs/fwvt/healing.mdx | 6 ++-- src/content/docs/tools/turn-signal.mdx | 4 +-- src/dom-view-transitions-level2.d.ts | 1 + 9 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/components/TestPage.astro b/src/components/TestPage.astro index 06eaf9b..1186e02 100644 --- a/src/components/TestPage.astro +++ b/src/components/TestPage.astro @@ -57,6 +57,7 @@ if (document.startViewTransition) { let matchElement = true; const transition = document.startViewTransition(); + transition.waitUntil && document.documentElement.setAttribute("wut", ""); transition.types && transition.types.add("test"); await transition.ready; document.documentElement.setAttribute("sdvt", ""); diff --git a/src/content/docs/basics/api.mdx b/src/content/docs/basics/api.mdx index f5c059f..7dcd1c1 100644 --- a/src/content/docs/basics/api.mdx +++ b/src/content/docs/basics/api.mdx @@ -36,6 +36,10 @@ While I add more pages, I'm also happy that I can offer some links to previous w |When|What|Where| |---|---|---| +|2025-10-17|The view transitionObject offers a `waitUntil()` function that can be called with a promise. Now the view transitions `finished` promise does not only wait for the animations on pseudo-elements to end, but also waits for all promises passed via `waitUntil()` to settle.|[Level 2, waitUntil](https://drafts.csswg.org/css-view-transitions-2/#dom-viewtransition-waituntil)| +|2025-10-02|Scoped view transitions, where `startViewTransition()` can be called on DOM elements. View transitions started with `document.startViewTransition()` are called _global_ view transitions.|[Level 2, Scoped View Transitions](https://drafts.csswg.org/css-view-transitions-2/#scoped-vt) +|2025-10-02| The `transitionRoot` property of the view transition object returns the root element of a scoped view transition. For a global view transition it returns the `documentElement`|[Level 2, transitionRoot](https://drafts.csswg.org/css-view-transitions-2/#dom-viewtransition-transitionroot)| +|2025-10-02|The new value `view-transition` for the `contain` property ensures that view transition names are not visible outside a subtree|[Level 2, View Transition Name Isolation](https://drafts.csswg.org/css-view-transitions-2/#contain-view-transition)| |2025-08-25|Expose the currently active view transition object as `activeViewTransition` on the document, or on an element for scoped view transitions.| [Level 2, Exposing current transition](https://drafts.csswg.org/css-view-transitions-2/#active-view-transition) | |2025-06-18| The `old`, `new`, and `image-pair` pseudos now also inherit the timing function, iteration count, direction, play state animation poperties.|[Level 1, User Agent Styles](https://drafts.csswg.org/css-view-transitions-1/#ua-styles) |2025-06-16| Nested view transition groups are children of a new pseudo-element, which is the sibling of the image pair. The border width of this `::view-transition-group-children()` pseudo-element gets automatically copied over from the original element.|[Level 2, Group Children](https://drafts.csswg.org/css-view-transitions-2/#view-transition-group-children-pseudo)| @@ -55,7 +59,6 @@ These may or may not make it into the spec. |2025-05-28|User defined view transition names must not start with `-ua-` as those are reserved for the user agent, e.g. for `match-element` and `auto`.|[#12241](https://github.com/w3c/csswg-drafts/issues/12241) | |2025-01-29| `::view-transition-new(*) { pointer-events: auto }` to forward pointer events from the pseudo-element to the original element.|[#11596](https://github.com/w3c/csswg-drafts/issues/11596) | 2024-06-13| `transitionRoot` property of the `ViewTransition` object reports the DOM element the scoped view transition was called on.|[comment on #9908](https://github.com/w3c/csswg-drafts/issues/9908#issuecomment-2165621635)| -2023-09-23| Scoped view transitions, where `startViewTransition()` can be called on DOM elements.|[Explainer: Scoped View Transitions](https://github.com/WICG/view-transitions/blob/main/scoped-transitions.md) | diff --git a/src/content/docs/basics/javascript.mdx b/src/content/docs/basics/javascript.mdx index 644a1e8..07fe525 100644 --- a/src/content/docs/basics/javascript.mdx +++ b/src/content/docs/basics/javascript.mdx @@ -17,7 +17,7 @@ Browser-native cross-document view transitions can be [created entirely with CSS ## Same-Document View Transitions -Same document view transitions are amazing! You assign view transition names to the HTML elements you want to animate during the transition. The transition spans from the current DOM state to a future version, which is generated by calling and awaiting an update function. +Same document view transitions are amazing! You assign view transition names to the HTML elements you want to animate during the transition. The transition spans from the current DOM state to a future version, which is generated by calling and awaiting an update function. ### startViewTransition() @@ -26,15 +26,19 @@ You start a same-document view transition with an update callback that transform It is good practice to care for users that do not want motion effects and for browsers that do not support the API: ```js -if (window.matchMedia('(prefers-reduced-motion: reduce)') || !document.startViewTransition) { - updateCallback() +if ( + window.matchMedia("(prefers-reduced-motion: reduce)") || + !document.startViewTransition +) { + updateCallback(); } else { document.startViewTransition(updateCallback); } ``` -For users who prefer reduced motion or when the browser doesn't support the View Transition API, the code above directly executes the update function without calling `startViewTransition()`. -:::note +For users who prefer reduced motion or when the browser doesn't support the View Transition API, the code above directly executes the update function without calling `startViewTransition()`. + +:::note Calling `startViewTransition()` while another view transition is active will end the previous view transition in the same way as [`skipTransition()`](#skiptransition) ends the view transition: any running animation abruptly jumps to the end before the new transition starts. ::: @@ -65,8 +69,6 @@ interface Document { } ``` - - ### ViewTransition Object The `startViewTransition()` function returns an object that includes promises, the current transition types, the root/scope of a scoped view transition, and a function to skip the animations. @@ -79,6 +81,7 @@ interface ViewTransition { readonly types?: Set; readonly transitionRoot?: Element; skipTransition(): void; + waitUntil(Promise promise): void; } ``` @@ -86,11 +89,11 @@ interface ViewTransition { The promises allow you to hook into the different stages of the view transition process. -* The `updateCallbackDone` promise resolves once the update callback fulfills. You can use this to (synchronously) make last-minute changes before the new images are created. If the update function rejects, the `updateCallbackDone` promise rejects, too. View transition processing ends, and the `ready` and `finished` promises also reject. +- The `updateCallbackDone` promise resolves once the update callback fulfills. You can use this to (synchronously) make last-minute changes before the new images are created. If the update function rejects, the `updateCallbackDone` promise rejects, too. View transition processing ends, and the `ready` and `finished` promises also reject. -* The `ready` promise settles once the pseudo-elements have been inserted into the DOM. Inserting the pseudo-elements triggers their animations. For example, you can use this promise to add your own JavaScript animations using the Web Animation API. If there are errors, like duplicate view transition names, the `ready` promise will reject. +- The `ready` promise settles once the pseudo-elements have been inserted into the DOM. Inserting the pseudo-elements triggers their animations. For example, you can use this promise to add your own JavaScript animations using the Web Animation API. If there are errors, like duplicate view transition names, the `ready` promise will reject. -* Lastly, the `finished` promise settles once the animations are complete and the pseudo-elements have been removed. It resolves with the same outcome as `updateCallbackDone`. +- Lastly, the `finished` promise settles once the animations are complete and the pseudo-elements have been removed. It resolves with the same outcome as `updateCallbackDone`. When using the promises, your call to `startViewTransition()` might look something like this: @@ -106,10 +109,9 @@ if (document.startViewTransition && window.matchMedia('(prefers-reduced-motion: } ``` - #### skipTransition() -Calling `skipTransition()` stops the current view transition animations or prevents their start if the `ready` promise hasn't settled yet. +Calling `skipTransition()` stops the current view transition animations or prevents their start if the `ready` promise hasn't settled yet. If called before or during the update callback, it doesn't affect the update itself, nor does it impact the processing or the outcome of the updateCallbackDone promise. @@ -123,42 +125,51 @@ View transition types are a feature of Level 2 of the View Transition API. They #### transitionRoot -For scoped view transitions, this property returns the element on which `Element.startViewTransition` was called. For view transitions started on the `document`, either same-document or cross-document, it returns `null`. This property is only implemented in browsers that support scoped view transitions. +For scoped view transitions, this property returns the element on which `Element.startViewTransition` was called. For view transitions started on the `document`, either same-document or cross-document, it should return `document.documentElement` but does return `null` on current implementations. This property is only implemented in browsers that support scoped view transitions. + +#### waitUntil + +The `finished` promise of a view transition does only settle once all animations on pseudo-elements have come to an end. With `waitUntil()` you can pass a promise to the view transition to wait for. `finished` will then also wait until all passed promises have settled. + ### Checking for an Active View Transition The View Transition API now offers a way to check whether some view transition is currently active or not. If so, the `document.activeViewTransition()` function returns the ViewTransition object of a currently active view transition. This works for same-document and cross-document view transition alike, but does not yet seem to work for scoped view transition when calling `Element.activeViewTransition()`. -If you use [`mayStartViewTransition`](/tools/utensil-drawer/#maystartviewtransition) from the Utensil Drawer, you can access the current `ViewTransition` object by calling [getCurrentViewTransition](/tools/utensil-drawer/#current-view-transition). +If you use [`mayStartViewTransition`](/tools/utensil-drawer/#maystartviewtransition) from the Utensil Drawer, you can access the current `ViewTransition` object by calling [getCurrentViewTransition](/tools/utensil-drawer/#current-view-transition). ### Canceling and Chaining Calling `startViewTransition()` while another view transition is active will interrupt the current view transition, fast forward to the end state of the animations, and start the new view transition from there. If you want to avoid these jerky jump, you can either -* chain the update callback functions, passing the chained callback to a single call of `startViewTransition()`, or -* chain multiple calls to `startViewTransition()` by awaiting the `finished` promise before starting the next view transition. + +- chain the update callback functions, passing the chained callback to a single call of `startViewTransition()`, or +- chain multiple calls to `startViewTransition()` by awaiting the `finished` promise before starting the next view transition. The [`mayStartViewTransition()`](/tools/utensil-drawer/#maystartviewtransition) function from the Utensil Drawer has automatic support for both strategies. ### Scoped View Transitions [Scoped view transitions](https://github.com/WICG/view-transitions/blob/main/scoped-transitions.md) are rooted at arbitrary DOM elements. Instead of calling `document.startViewTransition()` it's `element.startViewTransition()`. This has some severe advantages: + - Rendering is only blocked on the DOM subtree rooted at element. The rest of the page is still interactive. - There can be several scoped view transitions on the page and they can independently perform in parallel. Rumor has it that the root element of the scoped view transition needs to have its `contain` CSS property set to `layout` (or `strict`). - Scoped view transitions are not widely supported jet. If your [browser supports](/basics/test-page/) them, this site features a [small example on clipping](/basics/hide-and-seek/#clipping-with-scoped-view-transition-groups). +Scoped view transitions are not widely supported jet. If your [browser supports](/basics/test-page/) them, this site features a [small example on clipping](/basics/hide-and-seek/#clipping-with-scoped-view-transition-groups). ## Cross-Document View Transitions You activate cross-document view transitions by adding the following incantation to the styles of all pages that should participate in view transitions: + ```css -@view-transition{ +@view-transition { navigation: auto; } ``` + Opting in to cross-document view transitions is CSS-only. But cross-document view transitions, too, have their JavaScript API. 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. diff --git a/src/content/docs/basics/pseudos.mdx b/src/content/docs/basics/pseudos.mdx index 6d89053..acc3a62 100644 --- a/src/content/docs/basics/pseudos.mdx +++ b/src/content/docs/basics/pseudos.mdx @@ -381,7 +381,11 @@ selector { } ``` Here the definition of the view transition name creates a view transition group `my-name`. Adding the `view-transition-group` property makes the `my-name` group a child of the `other` group defined elsewhere. -Reserved values are `none`, `normal`, `contain`, and `nearest` with their obvious ;-) meaning. +Reserved values are `none`, `normal`, `contain`, and `nearest`. + +When the property is set to `contain`, it will automatically become the parent of contained elements. + +While pseudo-elements can be moved independently of their named elements' position in the DOM, grouping is more restricted. A parent-child relationship in the view transition tree can only exist if the named elements also are descendants in the DOM ```c ::view-transition // the parent of all groups diff --git a/src/content/docs/basics/test-page.mdx b/src/content/docs/basics/test-page.mdx index 730492b..23b6011 100644 --- a/src/content/docs/basics/test-page.mdx +++ b/src/content/docs/basics/test-page.mdx @@ -22,6 +22,7 @@ This page shows whether your current browser has nativ | [view-transition-class](https://drafts.csswg.org/css-view-transitions-2/#view-transition-class-prop) | | | [view-transition-name: match-element](https://drafts.csswg.org/css-view-transitions-2/#additions-to-vt-name) | | | [view-transition-name: auto](https://drafts.csswg.org/css-view-transitions-2/#additions-to-vt-name) | | +| [`ViewTransition.prototype.waitUntil()`](https://drafts.csswg.org/css-view-transitions-2/#dom-viewtransition-waituntil)|| | [Active view transition property](https://drafts.csswg.org/css-view-transitions-2/#active-view-transition) | | | [Active view transition pseudo class](https://drafts.csswg.org/css-view-transitions-2/#the-active-view-transition-pseudo) | | | [Active view transition type pseudo class](https://drafts.csswg.org/css-view-transitions-2/#the-active-view-transition-type-pseudo) | | @@ -54,7 +55,8 @@ For browser compatibility data regarding the View Transition API see [the mdn pa #vtg, #vtgc, #vtna, - #vtnme { + #vtnme, + #wut { &::before { content: 'Not supported'; } @@ -73,7 +75,8 @@ For browser compatibility data regarding the View Transition API see [the mdn pa :root[vtg] #vtg, :root[vtgc] #vtgc, :root[vtna] #vtna, - :root[vtnme] #vtnme + :root[vtnme] #vtnme, + :root[wut] #wut { &::before { content: 'Supported'; diff --git a/src/content/docs/fwvt/customizing.mdx b/src/content/docs/fwvt/customizing.mdx index c447f15..aed98e7 100644 --- a/src/content/docs/fwvt/customizing.mdx +++ b/src/content/docs/fwvt/customizing.mdx @@ -152,9 +152,9 @@ We can select and animate these pseudo-elements just like `` or `
` ele -Fortunately, we don't need to define this ourselves. This exact[^1] animation is already applied by the View Transition API through the browser's built-in user-agent stylesheet as the default behavior. +Fortunately, we don't need to define this ourselves. This exact animation is already applied by the View Transition API through the browser's built-in user-agent stylesheet as the default behavior. -[^1]: Well, not _exaclty_ this, but very close. [See for yourself!](/basics/styling/#cross-fade-of-the-images)! +Well, not _exactly_ this, but very close. [See for yourself!](/basics/styling/#cross-fade-of-the-images)! Similarly, the API provides a built-in animation to fade in the new image: diff --git a/src/content/docs/fwvt/healing.mdx b/src/content/docs/fwvt/healing.mdx index a437342..60a0f29 100644 --- a/src/content/docs/fwvt/healing.mdx +++ b/src/content/docs/fwvt/healing.mdx @@ -495,12 +495,12 @@ Here's the prescribed solution: /* When going from Page 1 to Page 2 keep the browser generated fade-out, but add a shrink animation to the old one line image */ .page2::view-transition-old(header) { - animation-name: -ua-view-transition-fade-out, shrink; + animation-name: shrink, -ua-view-transition-fade-out, -ua-mix-blend-mode-plus-lighter; } /* When navigating from Page 2 to Page 1 -keep the browser generated fade-in but add a grow animation the new two line image */ +keep the browser generated fade-in but add a grow animation to the new two line image */ .page1::view-transition-new(header) { - animation-name: -ua-view-transition-fade-in, grow; + animation-name: grow, -ua-view-transition-fade-in, -ua-mix-blend-mode-plus-lighter; } ::view-transition-group(header) { animation-timing-function: ease-in-out; diff --git a/src/content/docs/tools/turn-signal.mdx b/src/content/docs/tools/turn-signal.mdx index c1ad2d6..4a6724f 100644 --- a/src/content/docs/tools/turn-signal.mdx +++ b/src/content/docs/tools/turn-signal.mdx @@ -209,10 +209,10 @@ You can use the view transition types set by the scripts in your CSS to select d This example shows how to use a cross-fade effect by default and to replace that with a sliding animation iff a view transition type called `shift-right` is set. ```css ::view-transition-old(main) { - animation: 200ms both fade-out; + animation-duration: 200ms; } ::view-transition-new(main) { - animation: 200ms both fade-in; + animation-duration: 200ms; } :active-view-transition-type(shift-right) { &::view-transition-old(main) { diff --git a/src/dom-view-transitions-level2.d.ts b/src/dom-view-transitions-level2.d.ts index 51f730c..4c3b8b3 100644 --- a/src/dom-view-transitions-level2.d.ts +++ b/src/dom-view-transitions-level2.d.ts @@ -36,6 +36,7 @@ declare global { interface ViewTransition { readonly types?: Set; readonly transitionRoot?: Element; + waitUntil(promise: Promise): void; } interface Window { navigation?: Navigation; -- knotmirror 0.0.1