管理后台可关全站动画,并细调代码折叠、平滑滚动、装饰入场;统一 lib/motion,尊重系统减少动态效果。 Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
"use client";
|
||
|
||
import { useEffect, type ReactNode } from "react";
|
||
import {
|
||
applyMotionSiteConfig,
|
||
getMotionSiteConfig,
|
||
motionConfigFromSettings,
|
||
type MotionSiteConfig,
|
||
} from "@/lib/motion";
|
||
import { realtime, RT_SETTINGS_CHANGED, type RtSettingsData } from "@/lib/realtime";
|
||
|
||
/**
|
||
* 根布局注入:SSR 初值写入 motion 模块 + html class;settings:changed 热更新。
|
||
*/
|
||
export default function MotionProvider({
|
||
initial,
|
||
children,
|
||
}: {
|
||
initial: MotionSiteConfig;
|
||
children: ReactNode;
|
||
}) {
|
||
useEffect(() => {
|
||
applyMotionSiteConfig(motionConfigFromSettings(initial));
|
||
}, [initial]);
|
||
|
||
useEffect(() => {
|
||
return realtime.on<RtSettingsData>(RT_SETTINGS_CHANGED, (data) => {
|
||
if (!data) return;
|
||
const cur = getMotionSiteConfig();
|
||
applyMotionSiteConfig(
|
||
motionConfigFromSettings({
|
||
ui_animations:
|
||
typeof data.ui_animations === "boolean"
|
||
? data.ui_animations
|
||
: cur.ui_animations,
|
||
anim_code_fold:
|
||
typeof data.anim_code_fold === "boolean"
|
||
? data.anim_code_fold
|
||
: cur.anim_code_fold,
|
||
anim_smooth_scroll:
|
||
typeof data.anim_smooth_scroll === "boolean"
|
||
? data.anim_smooth_scroll
|
||
: cur.anim_smooth_scroll,
|
||
anim_chrome:
|
||
typeof data.anim_chrome === "boolean" ? data.anim_chrome : cur.anim_chrome,
|
||
})
|
||
);
|
||
});
|
||
}, []);
|
||
|
||
return children;
|
||
}
|