import { MaybeElementRef } from "../toElement/index.mjs"; import { ObserverReturn } from "../createObserver/index.mjs"; import { Ref } from "vue"; //#region src/composables/useIntersectionObserver/index.d.ts interface IntersectionObserverEntry { boundingClientRect: DOMRectReadOnly; intersectionRatio: number; intersectionRect: DOMRectReadOnly; isIntersecting: boolean; rootBounds: DOMRectReadOnly | null; target: Element; time: number; } interface IntersectionObserverOptions { immediate?: boolean; once?: boolean; root?: Element | null; rootMargin?: string; threshold?: number | number[]; } interface UseIntersectionObserverReturn extends ObserverReturn { /** * Whether the target element is currently intersecting with the viewport */ readonly isIntersecting: Readonly>; } /** * A composable that uses the Intersection Observer API to detect when an element * is visible in the viewport. * * @param target The element to observe. * @param callback The callback to execute when the element's intersection changes. * @param options The options for the Intersection Observer. * @returns An object with methods to control the observer. * * @see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver * @see https://0.vuetifyjs.com/composables/system/use-intersection-observer * * @example * ```ts * import { ref } from 'vue' * import { useIntersectionObserver } from '@vuetify/v0' * * const target = ref() * const isVisible = ref(false) * * const { isIntersecting, pause, resume } = useIntersectionObserver( * target, * (entries) => { * const entry = entries[0] * if (entry) { * isVisible.value = entry.isIntersecting * console.log('Element is visible:', entry.isIntersecting) * } * }, * { threshold: 0.5 } * ) * * // Pause observation * pause() * * // Resume observation * resume() * ``` */ declare function useIntersectionObserver(target: MaybeElementRef, callback: (entries: IntersectionObserverEntry[]) => void, options?: IntersectionObserverOptions): UseIntersectionObserverReturn; interface UseElementIntersectionReturn extends UseIntersectionObserverReturn { /** * The intersection ratio (0.0 to 1.0) indicating how much of the element is visible */ readonly intersectionRatio: Readonly>; } /** * A convenience composable that uses the Intersection Observer API to detect * when an element is visible in the viewport. * * @param target The element to observe. * @param options The options for the Intersection Observer. * @returns An object with the intersection state. * * @see https://0.vuetifyjs.com/composables/system/use-intersection-observer * * @example * ```ts * import { ref } from 'vue' * import { useElementIntersection } from '@vuetify/v0' * * const myElement = ref() * const { isIntersecting, intersectionRatio } = useElementIntersection(myElement, { * threshold: 0.5 * }) * * // Use in template to conditionally render or animate * watchEffect(() => { * if (isIntersecting.value) { * console.log('Element is visible!', intersectionRatio.value) * } * }) * ``` */ declare function useElementIntersection(target: MaybeElementRef, options?: IntersectionObserverOptions): UseElementIntersectionReturn; //#endregion export { IntersectionObserverEntry, IntersectionObserverOptions, UseElementIntersectionReturn, UseIntersectionObserverReturn, useElementIntersection, useIntersectionObserver };