UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

43 lines (41 loc) 1.38 kB
import { cdnUrl } from "../core/consts.js"; import cache from "../icons/cache.js"; import { IconReplacements } from "../icons/iconReplacements.js"; //#region src/icon/helpers.ts const PREFIX_MAP = { con: "con", bra: "brand" }; /** Optimized prefix normalization with constant time lookup */ function normalizeIconPrefix(prefix) { return PREFIX_MAP[prefix] || (prefix.startsWith("ui") ? "fa" : prefix); } /** * Returns an object with either 'src' or 'customIcon', depending on whether the provided icon is: * - not in library: 'src' as CDN url * - in library: 'customIcon' as icon definition object */ function getIconDetails(iconName) { if (!iconName) return {}; const icon = IconReplacements?.[iconName] ?? iconName; if (!cache.has(icon)) { const normalizedPrefix = normalizeIconPrefix(icon.slice(0, 3)); return { src: `${cdnUrl}/common/icons/ui/${normalizedPrefix}/${icon}.svg` }; } const { details, name, pathProps = [], svgProps = {} } = cache.get(icon); const [width, height, , , d] = details; const viewBox = `0 0 ${width} ${height}`; return { customIcon: { d: Array.isArray(d) ? d : [d], pathProps: Array.isArray(pathProps) ? pathProps : [pathProps], svgProps: { "data-name": name, viewBox, ...svgProps } } }; } //#endregion export { getIconDetails }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=helpers.js.map