@mlola-ui/motion 1.0.13 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/reduced-motion.js +4 -2
- package/package.json +1 -1
package/dist/reduced-motion.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
const query = "(prefers-reduced-motion: reduce)";
|
|
4
|
+
// Test environments such as jsdom have a window but no matchMedia.
|
|
5
|
+
const supported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
4
6
|
function subscribe(listener) {
|
|
5
|
-
if (
|
|
7
|
+
if (!supported())
|
|
6
8
|
return () => { };
|
|
7
9
|
const media = window.matchMedia(query);
|
|
8
10
|
media.addEventListener("change", listener);
|
|
9
11
|
return () => media.removeEventListener("change", listener);
|
|
10
12
|
}
|
|
11
13
|
function snapshot() {
|
|
12
|
-
return
|
|
14
|
+
return supported() && window.matchMedia(query).matches;
|
|
13
15
|
}
|
|
14
16
|
export function useReducedMotion() {
|
|
15
17
|
return React.useSyncExternalStore(subscribe, snapshot, () => false);
|