Skip to content

Commit

Permalink
feat: use prefersReducedMotion from svelte/motion
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoppippi committed Dec 10, 2024
1 parent 6791b2f commit 77e167d
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/lib/DarkMode/transition.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import { browser } from '$app/environment';
import { on } from 'svelte/events';
import { prefersReducedMotion } from 'svelte/motion';

/**
* check if the browser supports appearance transition
*/
export class CheckTransitions {
#isReduced = $state(false);
#isViewTransitionAvailable = $state(false);
#mediaQuery: MediaQueryList | undefined = undefined;

#isAppearanceTransition = $derived(this.#isViewTransitionAvailable && !this.#isReduced);
constructor() {
if (!browser) {
return;
}

this.#isViewTransitionAvailable = document.startViewTransition != null;
this.#mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
this.#isReduced = this.#mediaQuery.matches;

on(this.#mediaQuery, 'change', (_event) => {
const event = _event;
this.#isReduced = event.matches;
});
}

get isAppearanceTransition() {
return this.#isAppearanceTransition;
return !prefersReducedMotion.current && this.#isViewTransitionAvailable;
}
}

0 comments on commit 77e167d

Please sign in to comment.