( enabled: boolean, intervalMs: number = BLINK_INTERVAL_MS, )
| 20 | * } |
| 21 | */ |
| 22 | export function useBlink( |
| 23 | enabled: boolean, |
| 24 | intervalMs: number = BLINK_INTERVAL_MS, |
| 25 | ): [ref: (element: DOMElement | null) => void, isVisible: boolean] { |
| 26 | const focused = useTerminalFocus() |
| 27 | const [ref, time] = useAnimationFrame(enabled && focused ? intervalMs : null) |
| 28 | |
| 29 | if (!enabled || !focused) return [ref, true] |
| 30 | |
| 31 | // Derive blink state from time - all instances see the same time so they sync |
| 32 | const isVisible = Math.floor(time / intervalMs) % 2 === 0 |
| 33 | return [ref, isVisible] |
| 34 | } |
| 35 |
no test coverage detected