@@ -8,28 +8,33 @@ defineOptions({
88const settingsStore = useSettingsStore ()
99
1010function toggleColorScheme(event : MouseEvent ) {
11- const { startViewTransition } = useViewTransition (() => {
11+ if ( ! document . startViewTransition || window . matchMedia ( ' (prefers-reduced-motion: reduce) ' ). matches ) {
1212 settingsStore .currentColorScheme && settingsStore .setColorScheme (settingsStore .currentColorScheme === ' dark' ? ' light' : ' dark' )
13+ return
14+ }
15+ const x = event .clientX
16+ const y = event .clientY
17+ const endRadius = Math .hypot (
18+ Math .max (x , innerWidth - x ),
19+ Math .max (y , innerHeight - y ),
20+ )
21+ const transition = document .startViewTransition (async () => {
22+ settingsStore .currentColorScheme && settingsStore .setColorScheme (settingsStore .currentColorScheme === ' dark' ? ' light' : ' dark' )
23+ await nextTick ()
1324 })
14- startViewTransition ()?.ready .then (() => {
15- const x = event .clientX
16- const y = event .clientY
17- const endRadius = Math .hypot (
18- Math .max (x , innerWidth - x ),
19- Math .max (y , innerHeight - y ),
20- )
25+ transition .ready .then (() => {
2126 const clipPath = [
2227 ` circle(0px at ${x }px ${y }px) ` ,
2328 ` circle(${endRadius }px at ${x }px ${y }px) ` ,
2429 ]
2530 document .documentElement .animate (
2631 {
27- clipPath: settingsStore .settings . app . colorScheme !== ' dark ' ? clipPath : clipPath .reverse (),
32+ clipPath: settingsStore .currentColorScheme === ' light ' ? clipPath : clipPath .reverse (),
2833 },
2934 {
30- duration: 300 ,
31- easing: ' ease-out' ,
32- pseudoElement: settingsStore .settings . app . colorScheme !== ' dark ' ? ' ::view-transition-new(root)' : ' ::view-transition-old(root)' ,
35+ duration: 500 ,
36+ easing: ' ease-in- out' ,
37+ pseudoElement: settingsStore .currentColorScheme === ' light ' ? ' ::view-transition-new(root)' : ' ::view-transition-old(root)' ,
3338 },
3439 )
3540 })
0 commit comments