{"version":3,"file":"use-space.js","sources":["../../../../../../packages/components/space/src/use-space.ts"],"sourcesContent":["import { computed, ref, watchEffect } from 'vue'\nimport { isArray, isNumber } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\n\nimport type { SpaceProps } from './space'\nimport type { CSSProperties, StyleValue } from 'vue'\n\nconst SIZE_MAP = {\n small: 8,\n default: 12,\n large: 16,\n} as const\n\nexport function useSpace(props: SpaceProps) {\n const ns = useNamespace('space')\n\n const classes = computed(() => [ns.b(), ns.m(props.direction), props.class])\n\n const horizontalSize = ref(0)\n const verticalSize = ref(0)\n\n const containerStyle = computed(() => {\n const wrapKls: CSSProperties =\n props.wrap || props.fill ? { flexWrap: 'wrap' } : {}\n const alignment: CSSProperties = {\n alignItems: props.alignment,\n }\n const gap: CSSProperties = {\n rowGap: `${verticalSize.value}px`,\n columnGap: `${horizontalSize.value}px`,\n }\n return [wrapKls, alignment, gap, props.style]\n })\n\n const itemStyle = computed(() => {\n return props.fill ? { flexGrow: 1, minWidth: `${props.fillRatio}%` } : {}\n })\n\n watchEffect(() => {\n const { size = 'small', wrap, direction: dir, fill } = props\n\n // when the specified size have been given\n if (isArray(size)) {\n const [h = 0, v = 0] = size\n horizontalSize.value = h\n verticalSize.value = v\n } else {\n let val: number\n if (isNumber(size)) {\n val = size\n } else {\n val = SIZE_MAP[size || 'small'] || SIZE_MAP.small\n }\n\n if ((wrap || fill) && dir === 'horizontal') {\n horizontalSize.value = verticalSize.value = val\n } else {\n if (dir === 'horizontal') {\n horizontalSize.value = val\n verticalSize.value = 0\n } else {\n verticalSize.value = val\n horizontalSize.value = 0\n }\n }\n }\n })\n\n return {\n classes,\n containerStyle,\n itemStyle,\n }\n}\n"],"names":["useNamespace","computed","ref","watchEffect","isArray","isNumber"],"mappings":";;;;;;;;;;;AAGA,MAAM,QAAQ,GAAG;AACjB,EAAE,KAAK,EAAE,CAAC;AACV,EAAE,OAAO,EAAE,EAAE;AACb,EAAE,KAAK,EAAE,EAAE;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