{"version":3,"file":"space.js","sources":["../../../../../../packages/components/space/src/space.ts"],"sourcesContent":["import {\n createTextVNode,\n createVNode,\n defineComponent,\n isVNode,\n renderSlot,\n} from 'vue'\nimport {\n PatchFlags,\n buildProps,\n definePropType,\n isArray,\n isFragment,\n isNumber,\n isString,\n isValidElementNode,\n} from '@element-plus/utils'\nimport { componentSizes } from '@element-plus/constants'\nimport Item from './item'\nimport { useSpace } from './use-space'\n\nimport type {\n ExtractPropTypes,\n StyleValue,\n VNode,\n VNodeArrayChildren,\n VNodeChild,\n} from 'vue'\nimport type { Arrayable } from '@element-plus/utils'\nimport type { AlignItemsProperty } from 'csstype'\n\nexport const spaceProps = buildProps({\n /**\n * @description Placement direction\n */\n direction: {\n type: String,\n values: ['horizontal', 'vertical'],\n default: 'horizontal',\n },\n /**\n * @description Classname\n */\n class: {\n type: definePropType | string>>([\n String,\n Object,\n Array,\n ]),\n default: '',\n },\n /**\n * @description Extra style rules\n */\n style: {\n type: definePropType([String, Array, Object]),\n default: '',\n },\n /**\n * @description Controls the alignment of items\n */\n alignment: {\n type: definePropType(String),\n default: 'center',\n },\n /**\n * @description Prefix for space-items\n */\n prefixCls: {\n type: String,\n },\n /**\n * @description Spacer\n */\n spacer: {\n type: definePropType([Object, String, Number, Array]),\n default: null,\n validator: (val: unknown) => isVNode(val) || isNumber(val) || isString(val),\n },\n /**\n * @description Auto wrapping\n */\n wrap: Boolean,\n /**\n * @description Whether to fill the container\n */\n fill: Boolean,\n /**\n * @description Ratio of fill\n */\n fillRatio: {\n type: Number,\n default: 100,\n },\n /**\n * @description Spacing size\n */\n size: {\n type: [String, Array, Number],\n values: componentSizes,\n validator: (val: unknown): val is [number, number] | number => {\n return (\n isNumber(val) ||\n (isArray(val) && val.length === 2 && val.every(isNumber))\n )\n },\n },\n} as const)\nexport type SpaceProps = ExtractPropTypes\n\nconst Space = defineComponent({\n name: 'ElSpace',\n\n props: spaceProps,\n\n setup(props, { slots }) {\n const { classes, containerStyle, itemStyle } = useSpace(props)\n\n // retrieve the children out via a simple for loop\n // the edge case here is that when users uses directives like , \n // we need to go deeper until the child is not the Fragment type\n function extractChildren(\n children: VNodeArrayChildren,\n parentKey = '',\n extractedChildren: VNode[] = []\n ) {\n const { prefixCls } = props\n children.forEach((child, loopKey) => {\n if (isFragment(child)) {\n if (isArray(child.children)) {\n child.children.forEach((nested, key) => {\n if (isFragment(nested) && isArray(nested.children)) {\n extractChildren(\n nested.children,\n `${parentKey + key}-`,\n extractedChildren\n )\n } else {\n extractedChildren.push(\n createVNode(\n Item,\n {\n style: itemStyle.value,\n prefixCls,\n key: `nested-${parentKey + key}`,\n },\n {\n default: () => [nested],\n },\n PatchFlags.PROPS | PatchFlags.STYLE,\n ['style', 'prefixCls']\n )\n )\n }\n })\n }\n // if the current child is valid vnode, then append this current vnode\n // to item as child node.\n } else if (isValidElementNode(child)) {\n extractedChildren.push(\n createVNode(\n Item,\n {\n style: itemStyle.value,\n prefixCls,\n key: `LoopKey${parentKey + loopKey}`,\n },\n {\n default: () => [child],\n },\n PatchFlags.PROPS | PatchFlags.STYLE,\n ['style', 'prefixCls']\n )\n )\n }\n })\n\n return extractedChildren\n }\n\n return () => {\n const { spacer, direction } = props\n\n const children = renderSlot(slots, 'default', { key: 0 }, () => [])\n\n if ((children.children ?? []).length === 0) return null\n // loop the children, if current children is rendered via `renderList` or ``\n if (isArray(children.children)) {\n let extractedChildren = extractChildren(children.children)\n\n if (spacer) {\n // track the current rendering index, when encounters the last element\n // then no need to add a spacer after it.\n const len = extractedChildren.length - 1\n extractedChildren = extractedChildren.reduce(\n (acc, child, idx) => {\n const children = [...acc, child]\n if (idx !== len) {\n children.push(\n createVNode(\n 'span',\n // adding width 100% for vertical alignment,\n // when the spacer inherit the width from the\n // parent, this span's width was not set, so space\n // might disappear\n {\n style: [\n itemStyle.value,\n direction === 'vertical' ? 'width: 100%' : null,\n ],\n key: idx,\n },\n [\n // if spacer is already a valid vnode, then append it to the current\n // span element.\n // otherwise, treat it as string.\n isVNode(spacer)\n ? spacer\n : createTextVNode(spacer as string, PatchFlags.TEXT),\n ],\n PatchFlags.STYLE\n )\n )\n }\n return children\n },\n []\n )\n }\n\n // spacer container.\n return createVNode(\n 'div',\n {\n class: classes.value,\n style: containerStyle.value,\n },\n extractedChildren,\n PatchFlags.STYLE | PatchFlags.CLASS\n )\n }\n\n return children.children\n }\n },\n})\n\nexport type SpaceInstance = InstanceType\n\nexport default Space\n"],"names":["buildProps","definePropType","isVNode","isNumber","isString","componentSizes","isArray","defineComponent","useSpace","isFragment","createVNode","Item","PatchFlags","isValidElementNode","renderSlot","createTextVNode"],"mappings":";;;;;;;;;;;;;;;AAoBY,MAAC,UAAU,GAAGA,kBAAU,CAAC;AACrC,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,MAAM,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC;AACtC,IAAI,OAAO,EAAE,YAAY;AACzB,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,IAAI,EAAEC,sBAAc,CAAC;AACzB,MAAM,MAAM;AACZ,MAAM,MAAM;AACZ,MAAM,KAAK;AACX,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,EAAE;AACf,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,IAAI,EAAEA,sBAAc,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACjD,IAAI,OAAO,EAAE,EAAE;AACf,GAAG;AACH,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAEA,sBAAc,CAAC,MAAM,CAAC;AAChC,IAAI,OAAO,EAAE,QAAQ;AACrB,GAAG;AACH,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAE,MAAM;AAChB,GAAG;AACH,EAAE,MAAM,EAAE;AACV,IAAI,IAAI,EAAEA,sBAAc,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACzD,IAAI,OAA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