@nuxt/docs-nightly 4.4.0-29534143.9efac4dc → 4.4.0-29535027.34787e4f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -459,6 +459,106 @@ definePageMeta({
459
459
  Overriding view transitions on a per-page basis will only have an effect if you have enabled the `experimental.viewTransition` option.
460
460
  ::
461
461
 
462
+ ### View Transition Types
463
+
464
+ [View transition types](https://developer.chrome.com/blog/view-transitions-update-io24#view-transition-types) allow you to apply different CSS animations depending on the type of navigation. This is useful for creating asymmetric transitions (e.g., a different animation when navigating forward vs. backward).
465
+
466
+ Types are set on the [`ViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) and can be targeted in CSS using the [`:active-view-transition-type()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:active-view-transition-type) pseudo-class selector.
467
+
468
+ You can set default types globally in your `nuxt.config.ts`:
469
+
470
+ ```ts twoslash [nuxt.config.ts]
471
+ export default defineNuxtConfig({
472
+ app: {
473
+ viewTransition: {
474
+ enabled: true,
475
+ types: ['slide'],
476
+ },
477
+ },
478
+ })
479
+ ```
480
+
481
+ Or configure types per-page using `definePageMeta`. Per-page types support both static arrays and functions for dynamic behavior:
482
+
483
+ ```vue twoslash [pages/detail.vue]
484
+ <script setup lang="ts">
485
+ definePageMeta({
486
+ viewTransition: {
487
+ enabled: true,
488
+ // Types applied to any transition involving this page
489
+ types: ['slide'],
490
+ // Types applied only when navigating TO this page
491
+ toTypes: ['slide-in'],
492
+ // Types applied only when navigating FROM this page
493
+ fromTypes: ['slide-out'],
494
+ },
495
+ })
496
+ </script>
497
+ ```
498
+
499
+ You can also use functions for `types`, `toTypes`, and `fromTypes` in `definePageMeta` to determine types dynamically based on the route:
500
+
501
+ ```vue twoslash [pages/[id].vue]
502
+ <script setup lang="ts">
503
+ definePageMeta({
504
+ viewTransition: {
505
+ enabled: true,
506
+ toTypes: (to, from) => {
507
+ // Slide left when going to a higher ID, right otherwise
508
+ return Number(to.params.id) > Number(from.params.id)
509
+ ? ['slide-left']
510
+ : ['slide-right']
511
+ },
512
+ },
513
+ })
514
+ </script>
515
+ ```
516
+
517
+ Then target these types in your CSS:
518
+
519
+ ```css
520
+ /* Default crossfade */
521
+ ::view-transition-old(root),
522
+ ::view-transition-new(root) {
523
+ animation-duration: 0.3s;
524
+ }
525
+
526
+ /* Slide left animation */
527
+ html:active-view-transition-type(slide-left) {
528
+ &::view-transition-old(root) {
529
+ animation: slide-out-left 0.3s ease-in-out;
530
+ }
531
+ &::view-transition-new(root) {
532
+ animation: slide-in-right 0.3s ease-in-out;
533
+ }
534
+ }
535
+
536
+ /* Slide right animation */
537
+ html:active-view-transition-type(slide-right) {
538
+ &::view-transition-old(root) {
539
+ animation: slide-out-right 0.3s ease-in-out;
540
+ }
541
+ &::view-transition-new(root) {
542
+ animation: slide-in-left 0.3s ease-in-out;
543
+ }
544
+ }
545
+ ```
546
+
547
+ ::note
548
+ Function values for `types`, `toTypes`, and `fromTypes` only work in `definePageMeta`, not in `nuxt.config.ts` (where only static `string[]` is supported).
549
+ ::
550
+
551
+ The `page:view-transition:start` hook provides access to the [`ViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) object, which includes a [`types`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/types) property (`ViewTransitionTypeSet`) that can be read or modified at runtime:
552
+
553
+ ```ts [plugins/view-transition.client.ts]
554
+ export default defineNuxtPlugin((nuxtApp) => {
555
+ nuxtApp.hook('page:view-transition:start', (transition) => {
556
+ // Read or modify types at runtime
557
+ console.log([...transition.types])
558
+ })
559
+ })
560
+ ```
561
+
462
562
  If you are also using Vue transitions like `pageTransition` and `layoutTransition` (see above) to achieve the same result as the new View Transitions API, then you may wish to _disable_ Vue transitions if the user's browser supports the newer, native web API. You can do this by creating `~/middleware/disable-vue-transitions.global.ts` with the following contents:
463
563
 
464
564
  ```ts
@@ -303,11 +303,27 @@ export default defineNuxtConfig({
303
303
  })
304
304
  ```
305
305
 
306
+ You can also pass an object to configure [view transition types](/docs/4.x/getting-started/transitions#view-transition-types), which allow different CSS animations based on the type of navigation:
307
+
308
+ ```ts twoslash [nuxt.config.ts]
309
+ export default defineNuxtConfig({
310
+ experimental: {
311
+ viewTransition: {
312
+ enabled: true,
313
+ types: ['slide'],
314
+ },
315
+ },
316
+ })
317
+ ```
318
+
306
319
  :link-example{to="https://stackblitz.com/edit/nuxt-view-transitions?file=app.vue" target="_blank"}
307
320
 
308
321
  ::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API" target="_blank"}
309
322
  Read more about the **View Transition API**.
310
323
  ::
324
+ ::read-more{icon="i-simple-icons-google" to="https://developer.chrome.com/blog/view-transitions-update-io24" target="_blank"}
325
+ Read more about the **View Transition API**.
326
+ ::
311
327
 
312
328
  ## writeEarlyHints
313
329
 
@@ -35,7 +35,7 @@ interface PageMeta {
35
35
  groups?: string[]
36
36
  pageTransition?: boolean | TransitionProps
37
37
  layoutTransition?: boolean | TransitionProps
38
- viewTransition?: boolean | 'always'
38
+ viewTransition?: ViewTransitionPageOptions['enabled'] | ViewTransitionPageOptions
39
39
  key?: false | string | ((route: RouteLocationNormalizedLoaded) => string)
40
40
  keepalive?: boolean | KeepAliveProps
41
41
  layout?: false | LayoutKey | Ref<LayoutKey> | ComputedRef<LayoutKey>
@@ -121,12 +121,18 @@ interface PageMeta {
121
121
 
122
122
  **`viewTransition`**
123
123
 
124
- - **Type**: `boolean | 'always'`
124
+ - **Type**: `boolean | 'always' | ViewTransitionPageOptions`
125
125
 
126
126
  **Experimental feature, only available when [enabled in your nuxt.config file](/docs/4.x/getting-started/transitions#view-transitions-api-experimental)**</br>
127
127
  Enable/disable View Transitions for the current page.
128
128
  If set to true, Nuxt will not apply the transition if the users browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition.
129
129
 
130
+ You can also pass a `ViewTransitionPageOptions` object to configure [view transition types](/docs/4.x/getting-started/transitions#view-transition-types):
131
+ - `enabled`: `boolean | 'always'` - enable/disable the transition
132
+ - `types`: `string[] | (to, from) => string[]` - types applied to any transition involving this page
133
+ - `toTypes`: `string[] | (to, from) => string[]` - types applied only when navigating **to** this page
134
+ - `fromTypes`: `string[] | (to, from) => string[]` - types applied only when navigating **from** this page
135
+
130
136
  **`redirect`**
131
137
 
132
138
  - **Type**: [`RouteRecordRedirectOption`](https://router.vuejs.org/guide/essentials/redirect-and-alias)
@@ -30,7 +30,7 @@ Check the [app source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt
30
30
  | `page:loading:end` | - | Client | Called after `page:finish` |
31
31
  | `page:transition:finish` | `pageComponent?` | Client | After page transition [onAfterLeave](https://vuejs.org/guide/built-ins/transition#javascript-hooks) event. |
32
32
  | `dev:ssr-logs` | `logs` | Client | Called with an array of server-side logs that have been passed to the client (if `features.devLogs` is enabled). |
33
- | `page:view-transition:start` | `transition` | Client | Called after `document.startViewTransition` is called when [experimental viewTransition support is enabled](/docs/4.x/getting-started/transitions#view-transitions-api-experimental). |
33
+ | `page:view-transition:start` | `transition` | Client | Called after `document.startViewTransition` is called when [experimental viewTransition support is enabled](/docs/4.x/getting-started/transitions#view-transitions-api-experimental). The `transition` argument is a [`ViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) object with a `types` property ([`ViewTransitionTypeSet`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransitionTypeSet)) that can be read or modified. |
34
34
 
35
35
  ## Nuxt Hooks (build time)
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.4.0-29534143.9efac4dc",
3
+ "version": "4.4.0-29535027.34787e4f",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",