{"version":3,"names":["getNestedChildren","hostElement","tagName","getElementsByTagName","getNestedChildrenOf","elements","getFirstNestedChild","slottedElements","length","preciseSlottedChildSelector","node","slotName","tag","finalSelection","tempSelection","querySelector","elementHasDimensions","callback","hasDimensions","Promise","resolve","checkDimension","clientWidth","requestAnimationFrame","then","getParentEonUiElement","element","parent","parentNode","host","match","this"],"sources":["src/utils/dom-helper.ts"],"sourcesContent":["export function getNestedChildren(hostElement: Element, tagName: string): HTMLCollectionOf {\n return hostElement.getElementsByTagName(tagName);\n}\n\nexport function getNestedChildrenOf(hostElement: Element, tagName: string): HTMLCollectionOf {\n const elements = getNestedChildren(hostElement, tagName);\n return >(elements as unknown);\n}\n\nexport function getFirstNestedChild(hostElement: Element, tagName: string): T {\n const slottedElements = getNestedChildren(hostElement, tagName);\n return slottedElements.length > 0 ? ((slottedElements[0] as unknown) as T) : null;\n}\n\n/**\n * Returns a HTMLElement selected based on slot information.\n * If the child is wrapped by another div (this is a typical scenario in AEM) the selector\n * searches for the defined tag name inside of the element coming with the slot attribute.\n * @param node Node the selector is applied on\n * @param slotName string that defines the slot name for the queryselection\n * @param tag actual tag name that should be the result of the queryselection\n * @example preciseSlottedChildSelector(this.hostElement, \"header-image\", \"EON-UI-IMAGE\")\n */\nexport function preciseSlottedChildSelector(node: HTMLElement, slotName: string, tag: string) {\n let finalSelection: HTMLElement;\n let tempSelection = node.querySelector(`[slot=\"${slotName}\"`) as HTMLElement;\n\n if (tempSelection) {\n if (tempSelection.tagName === tag) {\n finalSelection = tempSelection;\n } else {\n finalSelection = tempSelection.querySelector(tag);\n }\n }\n\n return finalSelection;\n}\n\n/**\n * Returns the width of the host element's parent container\n * @param the child element whose parent element is targeted\n * @example getParentWidth(this.hostElement)\n */\nexport function getParentWidth(hostElement: Element): number {\n return hostElement?.parentElement ? hostElement.parentElement.offsetWidth : 0;\n}\n\nexport function elementHasDimensions(hostElement: HTMLElement, callback) {\n const hasDimensions = new Promise((resolve) => {\n const checkDimension = () => {\n if (!hostElement.clientWidth) {\n requestAnimationFrame(() => checkDimension());\n } else {\n resolve(\"Found\");\n }\n };\n checkDimension();\n });\n\n hasDimensions.then(() => {\n callback();\n });\n}\n\nexport function getParentEonUiElement(element: HTMLElement): HTMLElement {\n const parent = (element.parentNode as HTMLElement) || ((element as any).host as HTMLElement);\n if (!parent) {\n return null;\n }\n\n if (parent.tagName.match(/^EON-UI/)) return parent;\n\n return this.getParentEonUiElement(parent);\n}\n"],"mappings":"SAAgBA,EAAkBC,EAAsBC,GACtD,OAAOD,EAAYE,qBAAqBD,EAC1C,C,SAEgBE,EAAuCH,EAAsBC,GAC3E,MAAMG,EAAWL,EAAkBC,EAAaC,GAChD,OAA6BG,CAC/B,C,SAEgBC,EAAuBL,EAAsBC,GAC3D,MAAMK,EAAkBP,EAAkBC,EAAaC,GACvD,OAAOK,EAAgBC,OAAS,EAAMD,EAAgB,GAAuB,IAC/E,C,SAWgBE,EAA4BC,EAAmBC,EAAkBC,GAC/E,IAAIC,EACJ,IAAIC,EAAgBJ,EAAKK,cAAc,UAAUJ,MAEjD,GAAIG,EAAe,CACjB,GAAIA,EAAcZ,UAAYU,EAAK,CACjCC,EAAiBC,C,KACZ,CACLD,EAAiBC,EAAcC,cAAcH,E,EAIjD,OAAOC,CACT,C,SAWgBG,EAAqBf,EAA0BgB,GAC7D,MAAMC,EAAgB,IAAIC,SAASC,IACjC,MAAMC,EAAiB,KACrB,IAAKpB,EAAYqB,YAAa,CAC5BC,uBAAsB,IAAMF,K,KACvB,CACLD,EAAQ,Q,GAGZC,GAAgB,IAGlBH,EAAcM,MAAK,KACjBP,GAAU,GAEd,C,SAEgBQ,EAAsBC,GACpC,MAAMC,EAAUD,EAAQE,YAAgCF,EAAgBG,KACxE,IAAKF,EAAQ,CACX,OAAO,I,CAGT,GAAIA,EAAOzB,QAAQ4B,MAAM,WAAY,OAAOH,EAE5C,OAAOI,KAAKN,sBAAsBE,EACpC,Q"}