import type { ComponentPublicInstance, MaybeRef, MaybeRefOrGetter } from 'vue'; import { toValue } from 'vue'; export type VueInstance = ComponentPublicInstance; export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null; export type MaybeElementRef = MaybeRef; export type MaybeComputedElementRef = MaybeRefOrGetter; export type UnRefElementReturn = T extends VueInstance ? Exclude : T | undefined; /** * @name unrefElement * @category Components * @description Unwraps a Vue element reference to get the underlying instance or DOM element. * * @param {MaybeComputedElementRef} elRef - The element reference to unwrap. * @returns {UnRefElementReturn} - The unwrapped element or undefined. * * @example * const element = useTemplateRef('element'); * const result = unrefElement(element); // result is the element instance * * @example * const component = useTemplateRef('component'); * const result = unrefElement(component); // result is the component instance * * @since 0.0.11 */ export function unrefElement(elRef: MaybeComputedElementRef): UnRefElementReturn { const plain = toValue(elRef); return (plain as VueInstance)?.$el ?? plain; }