UNPKG

@oruga-ui/oruga-next

Version:

UI components for Vue.js and CSS framework agnostic

1 lines 1.73 kB
{"version":3,"file":"unrefElement-BozOaxdL.cjs","sources":["../../src/composables/unrefElement.ts"],"sourcesContent":["import {\n toValue,\n type ComponentPublicInstance,\n type MaybeRefOrGetter,\n type MaybeRef,\n type Component,\n} from \"vue\";\n\nexport type MaybeElement =\n | Element\n | Document\n | Window\n | HTMLElement\n | SVGElement\n | Component\n | ComponentPublicInstance\n | undefined\n | null;\n\nexport type UnRefElementReturn<T extends MaybeElement = MaybeElement> =\n T extends ComponentPublicInstance\n ? Exclude<MaybeElement, ComponentPublicInstance>\n : T extends Component\n ? HTMLElement\n : T | undefined;\n\n/** Get the dom element of a ref of element or Vue component instance */\nexport function unrefElement<T extends MaybeElement>(\n elRef: MaybeRefOrGetter<T> | MaybeRef<T>,\n): UnRefElementReturn<T> {\n const plain = toValue(elRef);\n return (plain as ComponentPublicInstance)?.$el ?? plain;\n}\n\n/** Resolve an HTML element based on query selector or an explizit dom element */\nexport function resolveElement(\n target: MaybeRefOrGetter<HTMLElement | string>,\n): HTMLElement | null {\n const targetQuery = toValue(target);\n // query element if target is a string\n if (typeof targetQuery === \"string\")\n return document.querySelector<HTMLElement>(targetQuery);\n // else unwrap element\n else return unrefElement(targetQuery);\n}\n"],"names":["toValue"],"mappings":";;;AA2BO,SAAS,aACZ,OACqB;AACf,QAAA,QAAQA,YAAQ,KAAK;AAC3B,UAAQ,+BAAmC,QAAO;AACtD;AAGO,SAAS,eACZ,QACkB;AACZ,QAAA,cAAcA,YAAQ,MAAM;AAElC,MAAI,OAAO,gBAAgB;AAChB,WAAA,SAAS,cAA2B,WAAW;AAAA,MAErD,QAAO,aAAa,WAAW;AACxC;;;"}