// Adapted from agentui (https://github.com/ashish200729/agentui) — replaces `useReducedMotion` from motion/react. // Copyright (c) 2026 Saurabh Chauhan. MIT License, see ./LICENSE-agentui.md // 改造:不引 motion 库,直接读 prefers-reduced-motion;样式层的减弱动效由 motion-reduce: 变体负责,这里只给 JS 滚动用。 import { useSyncExternalStore } from "react"; const QUERY = "(prefers-reduced-motion: reduce)"; function subscribe(cb: () => void) { if (typeof window === "undefined" || !window.matchMedia) return () => {}; const mq = window.matchMedia(QUERY); mq.addEventListener("change", cb); return () => mq.removeEventListener("change", cb); } export function useReducedMotion(): boolean { return useSyncExternalStore( subscribe, () => (typeof window !== "undefined" && window.matchMedia ? window.matchMedia(QUERY).matches : false), () => false, ); }