UNPKG

784 BJavaScriptView Raw
1import { Globals } from '@react-spring/web';
2import { useSyncExternalStore } from 'use-sync-external-store/shim';
3let reduced = false;
4const subscribers = new Set();
5function notify() {
6 subscribers.forEach(subscriber => {
7 subscriber();
8 });
9}
10export function reduceMotion() {
11 reduced = true;
12 notify();
13 Globals.assign({
14 skipAnimation: true
15 });
16}
17export function restoreMotion() {
18 reduced = false;
19 notify();
20 Globals.assign({
21 skipAnimation: false
22 });
23}
24export function isMotionReduced() {
25 return reduced;
26}
27function subscribe(onStoreChange) {
28 subscribers.add(onStoreChange);
29 return () => {
30 subscribers.delete(onStoreChange);
31 };
32}
33export function useMotionReduced() {
34 return useSyncExternalStore(subscribe, isMotionReduced, isMotionReduced);
35}
\No newline at end of file