import type { IconStyleProps } from '../elements/shapes'; import type { Size } from '../types'; import { parseSize } from './size'; /** * 如果没有手动指定图标大小,则根据主图形尺寸自动推断 * * Infer the icon size according to key size if icon size is not manually specified * @param size - 主图形尺寸 | Key size * @param iconStyle - 图标样式 | Icon style * @returns 图标样式 | Icon style */ export function inferIconStyle(size: Size, iconStyle: IconStyleProps): IconStyleProps { const stdSize = parseSize(size); let style = {}; if (iconStyle.text && !iconStyle.fontSize) style = { fontSize: Math.min(...stdSize) * 0.5 }; if (iconStyle.src && (!iconStyle.width || !iconStyle.height)) style = { width: stdSize[0] * 0.5, height: stdSize[1] * 0.5 }; return style; }