mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 22:02:16 +00:00
Pre-existing format drift accumulated across v1.4.x; running prettier brings the whole tree back to baseline so future diffs read clean. No behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
29 lines
954 B
TypeScript
29 lines
954 B
TypeScript
/**
|
|
* Tiny helper for chart wrappers that need to respect
|
|
* `prefers-reduced-motion` (v1.4.16 B1a).
|
|
*
|
|
* SSR-safe: returns `false` (i.e. animations *enabled*) whenever
|
|
* `window.matchMedia` is unavailable. The chart wrappers consume this
|
|
* during render and pass the negation to Recharts' `isAnimationActive`
|
|
* prop so first-render line-draw animations are suppressed for users
|
|
* who've requested reduced motion at the OS level.
|
|
*
|
|
* Pure / no-side-effects so the unit test runs under the default
|
|
* vitest "node" environment.
|
|
*/
|
|
export function prefersReducedMotion(): boolean {
|
|
if (
|
|
typeof window === "undefined" ||
|
|
typeof window.matchMedia !== "function"
|
|
) {
|
|
return false;
|
|
}
|
|
try {
|
|
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
} catch {
|
|
// matchMedia can throw on legacy mobile browsers when the query
|
|
// string is unrecognised — fall back to "no, animate".
|
|
return false;
|
|
}
|
|
}
|