import { MaybeElementRef } from "../toElement/index.mjs"; import { ObserverReturn } from "../createObserver/index.mjs"; import { Ref } from "vue"; //#region src/composables/useResizeObserver/index.d.ts /** * A reported size change for an observed element. * * `contentRect` always describes the content box, regardless of the `box` * option. Read `borderBoxSize` when padding and borders should be included — * both arrays are populated on every entry, so `box` selects which box model * triggers a callback, not which measurements are available. * * @example * ```ts * useResizeObserver(el, ([entry]) => { * entry.contentRect.height // content box, excludes padding + border * entry.contentBoxSize[0].blockSize // same value, writing-mode relative * entry.borderBoxSize[0].blockSize // includes padding + border * }, { box: 'border-box' }) * ``` */ interface ResizeObserverEntry { contentRect: { width: number; height: number; top: number; left: number; }; /** * The element's border box — content plus padding plus border — in * writing-mode-relative `inlineSize` / `blockSize` terms. * * Unlike `getBoundingClientRect()`, this is a layout measurement and is not * scaled by CSS transforms. The array mirrors the native API: one entry per * box fragment, so single-fragment elements report `borderBoxSize[0]`. */ borderBoxSize: readonly ResizeObserverSize[]; /** * The element's content box — excluding padding and border — in * writing-mode-relative `inlineSize` / `blockSize` terms. * * Carries the same measurement as `contentRect`, expressed on the logical * axes. The array mirrors the native API: one entry per box fragment. */ contentBoxSize: readonly ResizeObserverSize[]; target: Element; } interface ResizeObserverOptions { immediate?: boolean; once?: boolean; box?: 'content-box' | 'border-box'; } interface UseResizeObserverReturn extends ObserverReturn {} /** * A composable that uses the Resize Observer API to detect when an element's * size changes. * * @param target The element to observe. * @param callback The callback to execute when the element's size changes. * @param options The options for the Resize Observer. * @returns An object with methods to control the observer. * * @see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver * @see https://0.vuetifyjs.com/composables/system/use-resize-observer * * @example * ```ts * import { ref } from 'vue' * import { useResizeObserver } from '@vuetify/v0' * * const el = ref() * const width = ref(0) * const height = ref(0) * * const { pause, resume, isPaused } = useResizeObserver( * el, * (entries) => { * const entry = entries[0] * if (entry) { * width.value = entry.contentRect.width * height.value = entry.contentRect.height * console.log('Size changed:', width.value, 'x', height.value) * } * }, * { immediate: true } * ) * * // Pause observation * pause() * * // Resume observation * resume() * ``` * * @example * Measuring the border box — padding and borders included: * * ```ts * useResizeObserver(el, ([entry]) => { * height.value = entry.borderBoxSize[0].blockSize * }, { box: 'border-box' }) * ``` */ declare function useResizeObserver(target: MaybeElementRef, callback: (entries: ResizeObserverEntry[]) => void, options?: ResizeObserverOptions): UseResizeObserverReturn; interface UseElementSizeReturn extends UseResizeObserverReturn { /** * The width of the element in pixels */ readonly width: Readonly>; /** * The height of the element in pixels */ readonly height: Readonly>; } /** * A convenience composable that uses the Resize Observer API to track an * element's size. * * @param target The element to observe. * @returns An object with the element's width and height. * * @see https://0.vuetifyjs.com/composables/system/use-resize-observer * * @example * ```ts * import { ref, watchEffect } from 'vue' * import { useElementSize } from '@vuetify/v0' * * const box = ref() * const { width, height } = useElementSize(box) * * // Width and height are reactive refs * watchEffect(() => { * console.log('Box size:', width.value, 'x', height.value) * }) * ``` */ declare function useElementSize(target: MaybeElementRef): UseElementSizeReturn; //#endregion export { ResizeObserverEntry, ResizeObserverOptions, UseElementSizeReturn, UseResizeObserverReturn, useElementSize, useResizeObserver };