{"version":3,"file":"description2.js","sources":["../../../../../../packages/components/descriptions/src/description.vue"],"sourcesContent":["<template>\n  <div :class=\"descriptionKls\">\n    <div\n      v-if=\"title || extra || $slots.title || $slots.extra\"\n      :class=\"ns.e('header')\"\n    >\n      <div :class=\"ns.e('title')\">\n        <slot name=\"title\">{{ title }}</slot>\n      </div>\n      <div :class=\"ns.e('extra')\">\n        <slot name=\"extra\">{{ extra }}</slot>\n      </div>\n    </div>\n\n    <div :class=\"ns.e('body')\">\n      <table :class=\"[ns.e('table'), ns.is('bordered', border)]\">\n        <tbody>\n          <template v-for=\"(row, _index) in getRows()\" :key=\"_index\">\n            <el-descriptions-row :row=\"row\" />\n          </template>\n        </tbody>\n      </table>\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, provide, useSlots } from 'vue'\nimport { flattedChildren } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { useFormSize } from '@element-plus/components/form'\nimport ElDescriptionsRow from './descriptions-row.vue'\nimport { descriptionsKey } from './token'\nimport { descriptionProps } from './description'\n\nimport type { IDescriptionsInject } from './descriptions.type'\nimport type { DescriptionItemVNode } from './description-item'\n\ndefineOptions({\n  name: 'ElDescriptions',\n})\n\nconst props = defineProps(descriptionProps)\n\nconst ns = useNamespace('descriptions')\n\nconst descriptionsSize = useFormSize()\n\nconst slots = useSlots()\n\nprovide(descriptionsKey, props as IDescriptionsInject)\n\nconst descriptionKls = computed(() => [ns.b(), ns.m(descriptionsSize.value)])\n\nconst filledNode = (\n  node: DescriptionItemVNode,\n  span: number,\n  count: number,\n  isLast = false\n) => {\n  if (!node.props) {\n    node.props = {}\n  }\n  if (span > count) {\n    node.props.span = count\n  }\n  if (isLast) {\n    // set the last span\n    node.props.span = span\n  }\n  return node\n}\n\nconst getRows = () => {\n  if (!slots.default) return []\n\n  const children = flattedChildren(slots.default()).filter(\n    (node): node is DescriptionItemVNode =>\n      (node as any)?.type?.name === 'ElDescriptionsItem'\n  )\n  const rows: DescriptionItemVNode[][] = []\n  let temp: DescriptionItemVNode[] = []\n  let count = props.column\n  let totalSpan = 0 // all spans number of item\n  const rowspanTemp: number[] = [] // the number of row spans\n\n  children.forEach((node, index) => {\n    const span = node.props?.span || 1\n    const rowspan = node.props?.rowspan || 1\n    const rowNo = rows.length\n    rowspanTemp[rowNo] ||= 0\n\n    if (rowspan > 1) {\n      for (let i = 1; i < rowspan; i++) {\n        rowspanTemp[rowNo + i] ||= 0\n        rowspanTemp[rowNo + i]++\n        totalSpan++\n      }\n    }\n    if (rowspanTemp[rowNo] > 0) {\n      count -= rowspanTemp[rowNo]\n      rowspanTemp[rowNo] = 0\n    }\n    if (index < children.length - 1) {\n      totalSpan += span > count ? count : span\n    }\n\n    if (index === children.length - 1) {\n      // calculate the last item span\n      const lastSpan = props.column - (totalSpan % props.column)\n      temp.push(filledNode(node, lastSpan, count, true))\n      rows.push(temp)\n      return\n    }\n\n    if (span < count) {\n      count -= span\n      temp.push(node)\n    } else {\n      temp.push(filledNode(node, span, count))\n      rows.push(temp)\n      count = props.column\n      temp = []\n    }\n  })\n\n  return rows\n}\n</script>\n"],"names":["useNamespace","useFormSize","useSlots","provide","descriptionsKey","computed","flattedChildren"],"mappings":";;;;;;;;;;;;;;;;uCAsCc,CAAA;AAAA,EACZ,IAAM,EAAA,gBAAA;AACR,CAAA,CAAA,CAAA;;;;;;AAIA,IAAM,MAAA,EAAA,GAAKA,mBAAa,cAAc,CAAA,CAAA;AAEtC,IAAA,MAAM,mBAAmBC,8BAAY,EAAA,CAAA;AAErC,IAAA,MAAM,QAAQC,YAAS,EAAA,CAAA;AAEvB,IAAAC,WAAA,CAAQC,uBAAiB,KAA4B,CAAA,CAAA;AAErD,IAAA,MAAM,cAAiB,GAAAC,YAAA,CAAS,MAAM,CAAC,EAAG,CAAA,CAAA,EAAK,EAAA,EAAA,CAAG,CAAE,CAAA,gBAAA,CAAiB,KAAK,CAAC,CAAC,CAAA,CAAA;AAE5E,IAAA,MAAM,a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