{"version":3,"file":"styles-helper.js","sources":["../../../../../../../packages/components/table/src/table-body/styles-helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { inject } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport {\n ensurePosition,\n getFixedColumnOffset,\n getFixedColumnsClass,\n} from '../util'\nimport { TABLE_INJECTION_KEY } from '../tokens'\nimport type { TableColumnCtx } from '../table-column/defaults'\nimport type { TableBodyProps } from './defaults'\n\nfunction useStyles(props: Partial>) {\n const parent = inject(TABLE_INJECTION_KEY)\n const ns = useNamespace('table')\n\n const getRowStyle = (row: T, rowIndex: number) => {\n const rowStyle = parent?.props.rowStyle\n if (typeof rowStyle === 'function') {\n return rowStyle.call(null, {\n row,\n rowIndex,\n })\n }\n return rowStyle || null\n }\n\n const getRowClass = (row: T, rowIndex: number) => {\n const classes = [ns.e('row')]\n if (\n parent?.props.highlightCurrentRow &&\n row === props.store.states.currentRow.value\n ) {\n classes.push('current-row')\n }\n\n if (props.stripe && rowIndex % 2 === 1) {\n classes.push(ns.em('row', 'striped'))\n }\n const rowClassName = parent?.props.rowClassName\n if (typeof rowClassName === 'string') {\n classes.push(rowClassName)\n } else if (typeof rowClassName === 'function') {\n classes.push(\n rowClassName.call(null, {\n row,\n rowIndex,\n })\n )\n }\n return classes\n }\n\n const getCellStyle = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx\n ) => {\n const cellStyle = parent?.props.cellStyle\n let cellStyles = cellStyle ?? {}\n if (typeof cellStyle === 'function') {\n cellStyles = cellStyle.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n }\n const fixedStyle = getFixedColumnOffset(\n columnIndex,\n props?.fixed,\n props.store\n )\n ensurePosition(fixedStyle, 'left')\n ensurePosition(fixedStyle, 'right')\n return Object.assign({}, cellStyles, fixedStyle)\n }\n\n const getCellClass = (\n rowIndex: number,\n columnIndex: number,\n row: T,\n column: TableColumnCtx,\n offset: number\n ) => {\n const fixedClasses = getFixedColumnsClass(\n ns.b(),\n columnIndex,\n props?.fixed,\n props.store,\n undefined,\n offset\n )\n const classes = [column.id, column.align, column.className, ...fixedClasses]\n const cellClassName = parent?.props.cellClassName\n if (typeof cellClassName === 'string') {\n classes.push(cellClassName)\n } else if (typeof cellClassName === 'function') {\n classes.push(\n cellClassName.call(null, {\n rowIndex,\n columnIndex,\n row,\n column,\n })\n )\n }\n classes.push(ns.e('cell'))\n return classes.filter((className) => Boolean(className)).join(' ')\n }\n const getSpan = (\n row: T,\n column: TableColumnCtx,\n rowIndex: number,\n columnIndex: number\n ) => {\n let rowspan = 1\n let colspan = 1\n const fn = parent?.props.spanMethod\n if (typeof fn === 'function') {\n const result = fn({\n row,\n column,\n rowIndex,\n columnIndex,\n })\n if (Array.isArray(result)) {\n rowspan = result[0]\n colspan = result[1]\n } else if (typeof result === 'object') {\n rowspan = result.rowspan\n colspan = result.colspan\n }\n }\n return { rowspan, colspan }\n }\n const getColspanRealWidth = (\n columns: TableColumnCtx[],\n colspan: number,\n index: number\n ): number => {\n if (colspan < 1) {\n return columns[index].realWidth\n }\n const widthArr = columns\n .map(({ realWidth, width }) => realWidth || width)\n .slice(index, index + colspan)\n return Number(\n widthArr.reduce((acc, width) => Number(acc) + Number(width), -1)\n )\n }\n\n return {\n getRowStyle,\n getRowClass,\n getCellStyle,\n getCellClass,\n getSpan,\n getColspanRealWidth,\n }\n}\n\nexport default useStyles\n"],"names":["inject","TABLE_INJECTION_KEY","useNamespace","getFixedColumnOffset","ensurePosition","getFixedColumnsClass"],"mappings":";;;;;;;;;;AAQA,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,EAAE,MAAM,MAAM,GAAGA,UAAM,CAACC,0BAAmB,CAAC,CAAC;AAC7C,EAAE,MAAM,EAAE,GAAGC,kBAAY,CAAC,OAAO,CAAC,CAAC;AACnC,EAAE,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,QAAQ,KAAK;AACzC,IAAI,MAAM,QAAQ,GAAG,MAAM,IAAI,IAA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