feat(effort): useRippleFrame hook 包装 useAnimationFrame,按需订阅时钟

Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-06-14 14:50:02 +08:00
parent fe01c728f2
commit 67ef7aea73

View File

@@ -0,0 +1,22 @@
import { type DOMElement, useAnimationFrame } from '@anthropic/ink'
const RIPPLE_INTERVAL_MS = 60
/**
* ultracode 波纹动画 hook。
*
* 设计:
* - 仅当 enabled=truecursor === 'ultracode'时订阅时钟pass null 时
* useAnimationFrame 内部不订阅 ClockContextsetInterval 不触发。
* - 返回 [ref, time]ref 附到波纹容器(驱动 viewport-pausetime
* 用于 computeRippleLine 计算各行的波纹相位。
*
* enabled=false 时返回 time=0下游基于 enabled 直接不渲染波纹层,
* 但 0 仍是合法值,避免意外的 phase 输出 NaN
*/
export function useRippleFrame(
enabled: boolean,
): [ref: (element: DOMElement | null) => void, time: number] {
const [ref, time] = useAnimationFrame(enabled ? RIPPLE_INTERVAL_MS : null)
return [ref, enabled ? time : 0]
}