{"version":3,"file":"use-styles.js","sources":["../../../../../../../packages/components/table-v2/src/composables/use-styles.ts"],"sourcesContent":["import { computed, unref } from 'vue'\nimport { addUnit, isNumber } from '@element-plus/utils'\nimport { enforceUnit, sum } from '../utils'\n\nimport type { CSSProperties } from 'vue'\nimport type { TableV2Props } from '../table'\nimport type { UseColumnsReturn } from './use-columns'\nimport type { UseDataReturn } from './use-data'\n\ntype UseStyleProps = {\n columnsTotalWidth: UseColumnsReturn['columnsTotalWidth']\n data: UseDataReturn['data']\n fixedColumnsOnLeft: UseColumnsReturn['fixedColumnsOnLeft']\n fixedColumnsOnRight: UseColumnsReturn['fixedColumnsOnRight']\n}\n\nexport const useStyles = (\n props: TableV2Props,\n {\n columnsTotalWidth,\n data,\n fixedColumnsOnLeft,\n fixedColumnsOnRight,\n }: UseStyleProps\n) => {\n const bodyWidth = computed(() => {\n const { fixed, width, vScrollbarSize } = props\n const ret = width - vScrollbarSize\n return fixed ? Math.max(Math.round(unref(columnsTotalWidth)), ret) : ret\n })\n\n const headerWidth = computed(() => unref(bodyWidth) + props.vScrollbarSize)\n\n const mainTableHeight = computed(() => {\n const { height = 0, maxHeight = 0, footerHeight, hScrollbarSize } = props\n\n if (maxHeight > 0) {\n const _fixedRowsHeight = unref(fixedRowsHeight)\n const _rowsHeight = unref(rowsHeight)\n const _headerHeight = unref(headerHeight)\n const total =\n _headerHeight + _fixedRowsHeight + _rowsHeight + hScrollbarSize\n\n return Math.min(total, maxHeight - footerHeight)\n }\n\n return height - footerHeight\n })\n\n const rowsHeight = computed(() => {\n const { rowHeight, estimatedRowHeight } = props\n const _data = unref(data)\n if (isNumber(estimatedRowHeight)) {\n return _data.length * estimatedRowHeight\n }\n\n return _data.length * rowHeight\n })\n\n const fixedTableHeight = computed(() => {\n const { maxHeight } = props\n const tableHeight = unref(mainTableHeight)\n if (isNumber(maxHeight) && maxHeight > 0) return tableHeight\n\n const totalHeight =\n unref(rowsHeight) + unref(headerHeight) + unref(fixedRowsHeight)\n\n return Math.min(tableHeight, totalHeight)\n })\n\n const mapColumn = (column: TableV2Props['columns'][number]) => column.width\n\n const leftTableWidth = computed(() =>\n sum(unref(fixedColumnsOnLeft).map(mapColumn))\n )\n\n const rightTableWidth = computed(() =>\n sum(unref(fixedColumnsOnRight).map(mapColumn))\n )\n\n const headerHeight = computed(() => sum(props.headerHeight))\n\n const fixedRowsHeight = computed(() => {\n return (props.fixedData?.length || 0) * props.rowHeight\n })\n\n const windowHeight = computed(() => {\n return unref(mainTableHeight) - unref(headerHeight) - unref(fixedRowsHeight)\n })\n\n const rootStyle = computed(() => {\n const { style = {}, height, width } = props\n return enforceUnit({\n ...style,\n height,\n width,\n })\n })\n\n const footerHeight = computed(() =>\n enforceUnit({ height: props.footerHeight })\n )\n\n const emptyStyle = computed(() => ({\n top: addUnit(unref(headerHeight)),\n bottom: addUnit(props.footerHeight),\n width: addUnit(props.width),\n }))\n\n return {\n bodyWidth,\n fixedTableHeight,\n mainTableHeight,\n leftTableWidth,\n rightTableWidth,\n headerWidth,\n rowsHeight,\n windowHeight,\n footerHeight,\n emptyStyle,\n rootStyle,\n headerHeight,\n }\n}\n\nexport type UseStyleReturn = ReturnType\n"],"names":["computed","unref","isNumber","sum","enforceUnit","addUnit"],"mappings":";;;;;;;;;;AAGY,MAAC,SAAS,GAAG,CAAC,KAAK,EAAE;AACjC,EAAE,iBAAiB;AACnB,EAAE,IAAI;AACN,EAAE,kBAAkB;AACpB,EAAE,mBAAmB;AACrB,CAAC,KAAK;AACN,EAAE,MAAM,SAAS,GAAGA,YAAQ,CAAC,MAAM;AACnC,IAAI,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;AACnD,IAAI,MAAM,GAAG,GAAG,KAAK,GAAG,cAAc,CAAC;AACvC,IAAI,OAAO,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAACC,SAAK,CAAC,iBAAiB,CAAC,CAAC,EAAE,GAAG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