{"version":3,"file":"tab-bar.js","sources":["../../../../../../packages/components/tabs/src/tab-bar.vue"],"sourcesContent":["<template>\n <div\n ref=\"barRef\"\n :class=\"[ns.e('active-bar'), ns.is(rootTabs.props.tabPosition)]\"\n :style=\"barStyle\"\n />\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n getCurrentInstance,\n inject,\n nextTick,\n onBeforeUnmount,\n ref,\n watch,\n} from 'vue'\nimport { useResizeObserver } from '@vueuse/core'\nimport { capitalize, throwError } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { tabsRootContextKey } from './constants'\nimport { tabBarProps } from './tab-bar'\n\nimport type { CSSProperties } from 'vue'\n\nconst COMPONENT_NAME = 'ElTabBar'\ndefineOptions({\n name: COMPONENT_NAME,\n})\nconst props = defineProps(tabBarProps)\n\nconst instance = getCurrentInstance()!\nconst rootTabs = inject(tabsRootContextKey)\nif (!rootTabs) throwError(COMPONENT_NAME, '<el-tabs><el-tab-bar /></el-tabs>')\n\nconst ns = useNamespace('tabs')\n\nconst barRef = ref<HTMLDivElement>()\nconst barStyle = ref<CSSProperties>()\n\nconst getBarStyle = (): CSSProperties => {\n let offset = 0\n let tabSize = 0\n\n const sizeName = ['top', 'bottom'].includes(rootTabs.props.tabPosition)\n ? 'width'\n : 'height'\n const sizeDir = sizeName === 'width' ? 'x' : 'y'\n const position = sizeDir === 'x' ? 'left' : 'top'\n\n props.tabs.every((tab) => {\n const $el = instance.parent?.refs?.[`tab-${tab.uid}`] as HTMLElement\n if (!$el) return false\n\n if (!tab.active) {\n return true\n }\n\n offset = $el[`offset${capitalize(position)}`]\n tabSize = $el[`client${capitalize(sizeName)}`]\n\n const tabStyles = window.getComputedStyle($el)\n\n if (sizeName === 'width') {\n tabSize -=\n Number.parseFloat(tabStyles.paddingLeft) +\n Number.parseFloat(tabStyles.paddingRight)\n offset += Number.parseFloat(tabStyles.paddingLeft)\n }\n return false\n })\n\n return {\n [sizeName]: `${tabSize}px`,\n transform: `translate${capitalize(sizeDir)}(${offset}px)`,\n }\n}\n\nconst update = () => (barStyle.value = getBarStyle())\n\nconst saveObserver = [] as ReturnType<typeof useResizeObserver>[]\nconst observerTabs = () => {\n saveObserver.forEach((observer) => observer.stop())\n saveObserver.length = 0\n const list = instance.parent?.refs as Record<string, HTMLElement>\n if (!list) return\n for (const key in list) {\n if (key.startsWith('tab-')) {\n const _el = list[key]\n if (_el) {\n saveObserver.push(useResizeObserver(_el, update))\n }\n }\n }\n}\n\nwatch(\n () => props.tabs,\n async () => {\n await nextTick()\n update()\n\n observerTabs()\n },\n { immediate: true }\n)\nconst barObserever = useResizeObserver(barRef, () => update())\n\nonBeforeUnmount(() => {\n saveObserver.forEach((observer) => observer.stop())\n saveObserver.length = 0\n barObserever.stop()\n})\n\ndefineExpose({\n /** @description tab root html element */\n ref: barRef,\n /** @description method to manually update tab bar style */\n update,\n})\n</script>\n"],"names":["getCurrentInstance","inject","tabsRootContextKey","throwError","useNamespace","ref","capitalize","useResizeObserver","watch","nextTick","onBeforeUnmount"],"mappings":";;;;;;;;;;;;;;;;uCA0Bc,CAAA;AAAA,EACZ,IAAM,EAAA,cAAA;AACR;;;;;;AAGA,IAAA,MAAM,WAAWA,sBAAmB,EAAA,CAAA;AACpC,IAAM,MAAA,QAAA,GAAWC,WAAOC,4BAAkB,CAAA,CAAA;AAC1C,IAAA,IAAI,CAAC,QAAA;AAAU,MAAAC,gBAAA,CAAW,gBAAgB,mCAAmC,CAAA,CAAA;AAE7E,IAAM,MAAA,EAAA,GAAKC,mBAAa,MAAM,CAAA,CAAA;AAE9B,IAAA,MAAM,SAASC,OAAoB,EAAA,CAAA;AACnC,IAAA,MAAM,WAAWA,OAAmB,EAAA,CAAA;AAEpC,IAAA,MAAM,cAAc,MAAqB;AACvC,MAAA,IAAI,MAAS,GAAA,CAAA,CAAA;AACb,MAAA,IAAI,OAAU,GAAA,CAAA,CAAA;AAEd,MAAM,MAAA,QAAA,GAAW,CAAC,KAAA,EAAO,QAAQ,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