export function rgba(rgb: string): { r: number, g: number, b: number, a: number } { const result = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec( rgb.toLowerCase() ); if (result) { const r = parseInt(result[1], 10); const g = parseInt(result[2], 10); const b = parseInt(result[3], 10); const a = result[4] !== undefined ? parseFloat(result[4]) : 1; return { r, g, b, a }; } else { throw new Error('rgba color parsed failed'); } } export function rgb2hex(r: number, g: number, b: number): string { return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); }