Skip to content

Commit 260b377

Browse files
author
Felix Arntz
committed
Allow specifying a default animation and implement a gentle wipe animation as first option.
1 parent 206551a commit 260b377

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@property --wp-view-transition-progress {
2+
syntax: "<number>";
3+
initial-value: 0;
4+
inherits: false;
5+
}
6+
7+
@keyframes wp-view-transition-new-animation {
8+
from {
9+
--wp-view-transition-progress: 0;
10+
}
11+
to {
12+
--wp-view-transition-progress: 1;
13+
}
14+
}
15+
16+
::view-transition-old(*),
17+
::view-transition-new(*) {
18+
mix-blend-mode: normal;
19+
backface-visibility: hidden;
20+
}
21+
22+
::view-transition-old(root) {
23+
opacity: 1;
24+
transform: none;
25+
animation: none 1.2s cubic-bezier(0.45, 0, 0.35, 1.0);
26+
animation-fill-mode: both;
27+
animation-delay: 0s;
28+
}
29+
30+
::view-transition-new(root) {
31+
opacity: 1;
32+
transform: none;
33+
animation: wp-view-transition-new-animation 1.2s cubic-bezier(0.45, 0, 0.35, 1.0);
34+
animation-fill-mode: both;
35+
mask-image: linear-gradient(270deg, #000 calc(-70% + calc(170% * var(--wp-view-transition-progress, 0))), transparent calc(170% * var(--wp-view-transition-progress, 0)));
36+
}

src/wp-includes/theme.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,6 +2949,7 @@ function add_theme_support( $feature, ...$args ) {
29492949
'.wp-post-image' => 'post-thumbnail',
29502950
'.wp-block-post-content, .entry-content' => 'post-content',
29512951
),
2952+
'default-animation' => 'default',
29522953
'chronological-slide-in-out' => (bool) get_option( 'permalink_structure' ),
29532954
);
29542955
if ( true === $args ) {
@@ -4476,8 +4477,36 @@ function wp_load_view_transitions() {
44764477

44774478
$theme_support = get_theme_support( 'view-transitions' );
44784479

4479-
// No point in loading the script if no specific view transition names are configured.
4480-
if ( ! $theme_support['global-transition-names'] && ! $theme_support['post-transition-names'] ) {
4480+
switch ( $theme_support['default-animation'] ) {
4481+
case 'wipe':
4482+
case 'wipe-from-right': // Default 'wipe' direction.
4483+
case 'wipe-from-left':
4484+
case 'wipe-from-top':
4485+
case 'wipe-from-bottom':
4486+
$animation_stylesheet = file_get_contents( ABSPATH . WPINC . "/css/view-transitions-animation-wipe{$suffix}.css" );
4487+
if ( str_ends_with( $theme_support['default-animation'], 'left' ) ) {
4488+
$animation_stylesheet = str_replace( '270deg', '90deg', $animation_stylesheet );
4489+
} elseif ( str_ends_with( $theme_support['default-animation'], 'top' ) ) {
4490+
$animation_stylesheet = str_replace( '270deg', '180deg', $animation_stylesheet );
4491+
} elseif ( str_ends_with( $theme_support['default-animation'], 'bottom' ) ) {
4492+
$animation_stylesheet = str_replace( '270deg', '0deg', $animation_stylesheet );
4493+
}
4494+
wp_add_inline_style( 'wp-view-transitions', $animation_stylesheet );
4495+
break;
4496+
case 'default':
4497+
default:
4498+
// The default animation does not require any additional CSS.
4499+
}
4500+
4501+
/*
4502+
* No point in loading the script if no specific view transition names are
4503+
* configured and if chronological animations are disabled.
4504+
*/
4505+
if (
4506+
! $theme_support['global-transition-names'] &&
4507+
! $theme_support['post-transition-names'] &&
4508+
! $theme_support['chronological-slide-in-out']
4509+
) {
44814510
return;
44824511
}
44834512

0 commit comments

Comments
 (0)