import { MaybeArray } from "../../types/index.mjs"; import { MaybeRefOrGetter, Ref } from "vue"; //#region src/composables/useClickOutside/index.d.ts type ClickOutsideElement = HTMLElement | null | undefined; type ClickOutsideTarget = MaybeRefOrGetter; type ClickOutsideIgnoreTarget = ClickOutsideTarget | string; interface UseClickOutsideOptions { /** * Use capture phase for event listeners. * Ensures detection works even when inner elements call stopPropagation. * @default true */ capture?: boolean; /** * Touch movement threshold in pixels. * If finger moves more than this distance, it's treated as a scroll, not a tap. * Only applies to touch interactions. * @default 30 */ touchScrollThreshold?: number; /** * Detect focus moving to iframes as an outside click. * Useful when iframes are outside the target elements. * @default false */ detectIframe?: boolean; /** * Elements to ignore when detecting outside clicks. * Accepts element refs, getters, or CSS selector strings. * Clicks on these elements (or their descendants) won't trigger the handler. * * Note: CSS selectors cannot match across Shadow DOM boundaries due to * browser limitations. Use element refs instead when ignoring shadow hosts. */ ignore?: MaybeRefOrGetter; /** * Use bounding rect instead of DOM containment to detect outside clicks. * When true, checks if click coordinates are outside the element's bounding box. * Useful for native elements where backdrop clicks have the dialog as target. * @default false */ bounds?: boolean; } interface UseClickOutsideReturn { /** * Whether the listener is currently active */ readonly isActive: Readonly>; /** * Whether the listener is currently paused */ readonly isPaused: Readonly>; /** * Pause listening (stops detection but keeps state) */ pause: () => void; /** * Resume listening */ resume: () => void; /** * Stop listening and clean up */ stop: () => void; } /** * Detects clicks outside of the specified element(s). * * Uses two-phase detection (pointerdown → pointerup) to prevent false positives * when users drag from inside to outside an element. * * @param target Element ref(s) to detect clicks outside of. Accepts a single ref/getter or array of refs/getters. * @param handler Callback invoked when a click outside is detected. * @param options Configuration options. * @returns An object with methods to control the listener. * * @see https://0.vuetifyjs.com/composables/system/use-click-outside * * @example Native element ref * ```ts * const menuRef = useTemplateRef('menu') * * useClickOutside(menuRef, () => { isOpen.value = false }) * ``` * * @example Component ref (e.g., Atom) * ```ts * const atomRef = useTemplateRef('atom') * * // Pass the exposed element TemplateRef via getter * useClickOutside( * () => atomRef.value?.element, * () => { isOpen.value = false } * ) * ``` * * @example Multiple targets * ```ts * const popoverRef = useTemplateRef('popover') * const anchorRef = useTemplateRef('anchor') * * useClickOutside( * [() => popoverRef.value?.element, anchorRef], * () => { isOpen.value = false } * ) * ``` * * @example Ignoring elements (CSS selectors or refs) * ```ts * useClickOutside( * () => navRef.value?.element, * () => { isOpen.value = false }, * { ignore: ['[data-app-bar]'] } * ) * ``` * * @example Native dialog with bounds detection * ```ts * // For native elements, use bounds mode to detect backdrop clicks * const dialogRef = useTemplateRef('dialog') * * useClickOutside( * dialogRef, * () => { dialogRef.value?.close() }, * { bounds: true } * ) * ``` */ declare function useClickOutside(target: MaybeArray, handler: (event: PointerEvent | FocusEvent) => void, options?: UseClickOutsideOptions): UseClickOutsideReturn; //#endregion export { ClickOutsideElement, ClickOutsideIgnoreTarget, ClickOutsideTarget, UseClickOutsideOptions, UseClickOutsideReturn, useClickOutside };