diff --git a/src/App.vue b/src/App.vue index 790f7ab..a77f038 100644 --- a/src/App.vue +++ b/src/App.vue @@ -58,6 +58,12 @@ function toggleTheme(event: MouseEvent) { return } + const willBeDark = !isDark.value + + if (willBeDark) { + document.documentElement.classList.add('theme-transition-reverse') + } + const x = event.clientX const y = event.clientY const endRadius = Math.hypot( @@ -66,7 +72,7 @@ function toggleTheme(event: MouseEvent) { ) const transition = document.startViewTransition(async () => { - isDark.value = !isDark.value + isDark.value = willBeDark localStorage.setItem('theme', isDark.value ? 'dark' : 'light') updateTheme() await nextTick() @@ -77,17 +83,25 @@ function toggleTheme(event: MouseEvent) { `circle(0px at ${x}px ${y}px)`, `circle(${endRadius}px at ${x}px ${y}px)` ] + + const isReverse = willBeDark + document.documentElement.animate( { - clipPath: clipPath, + clipPath: isReverse ? [...clipPath].reverse() : clipPath, }, { duration: 400, easing: 'ease-out', - pseudoElement: '::view-transition-new(root)', + pseudoElement: isReverse ? '::view-transition-old(root)' : '::view-transition-new(root)', + fill: 'forwards', } ) }) + + transition.finished.then(() => { + document.documentElement.classList.remove('theme-transition-reverse') + }) } function updateTheme() { @@ -192,7 +206,6 @@ const bgModeLabel = computed(() => {