export const hexToRGBA = (hex: string) => { const normalizedHex = hex.startsWith('#') ? hex.slice(1) : hex; if (!/^([0-9A-Fa-f]{3}){1,2}$/.test(normalizedHex)) { throw new Error('Invalid HEX color.'); } const expandedHex = normalizedHex.length === 3 ? normalizedHex .split('') .map(val => val + val) .join('') : normalizedHex; const hexMatch = expandedHex.match(/.{2}/g); if (!hexMatch) { throw new Error('HEX parsing failed.'); } return hexMatch .map(val => parseInt(val, 16)) .map(val => Math.round((val / 255) * 1000) / 1000); };