import { ref, Ref } from 'vue'; import { inBrowser } from '../utils'; type VisibilityState = 'hidden' | 'visible'; let visibility: Ref; export function usePageVisibility() { if (!visibility) { visibility = ref('visible'); if (inBrowser) { const update = () => { visibility.value = document.hidden ? 'hidden' : 'visible'; }; update(); window.addEventListener('visibilitychange', update); } } return visibility; }