mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
🎉 Kit is live! 🎉 Merge prior to #9030. Manually updates Kit to latest (will need to have a commit pushed after 1.0 goes live on NPM). Co-authored-by: Steven <steven@ceriously.com>
27 lines
745 B
JavaScript
27 lines
745 B
JavaScript
import { readable } from 'svelte/store';
|
|
import { browser } from '$app/environment';
|
|
|
|
const reduced_motion_query = '(prefers-reduced-motion: reduce)';
|
|
|
|
const get_initial_motion_preference = () => {
|
|
if (!browser) return false;
|
|
return window.matchMedia(reduced_motion_query).matches;
|
|
};
|
|
|
|
export const reduced_motion = readable(get_initial_motion_preference(), (set) => {
|
|
if (browser) {
|
|
/**
|
|
* @param {MediaQueryListEvent} event
|
|
*/
|
|
const set_reduced_motion = (event) => {
|
|
set(event.matches);
|
|
};
|
|
const media_query_list = window.matchMedia(reduced_motion_query);
|
|
media_query_list.addEventListener('change', set_reduced_motion);
|
|
|
|
return () => {
|
|
media_query_list.removeEventListener('change', set_reduced_motion);
|
|
};
|
|
}
|
|
});
|