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