import { getCurrentScope, onScopeDispose, ref, type Ref } from 'vue' /** A reactive matchMedia; false where matchMedia does not exist (tests, SSR). */ export function useMediaQuery(query: string): Ref { const matches = ref(false) if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return matches const mql = window.matchMedia(query) matches.value = mql.matches const update = (e: MediaQueryListEvent) => { matches.value = e.matches } mql.addEventListener('change', update) if (getCurrentScope()) onScopeDispose(() => mql.removeEventListener('change', update)) return matches } /** True at and above a viewport width (the CSS `min-width` breakpoints). */ export function useMinWidth(px: number): Ref { return useMediaQuery(`(min-width: ${px}px)`) }