function componentToHex(component) {
    return component.toString(16).padStart(2, '0');
}
export function rgbToHex(r, g, b) {
    const rValue = componentToHex(r);
    const gValue = componentToHex(g);
    const bValue = componentToHex(b);
    return `#${rValue}${gValue}${bValue}`;
}
export function hexToRgb(hex) {
    // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
    const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
    const normalized = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
    const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(normalized);
    return result
        ? {
            r: parseInt(result[1], 16),
            g: parseInt(result[2], 16),
            b: parseInt(result[3], 16),
        }
        : null;
}
/**
 * Normalizes a color value to a consistent HEX value.
 * @param value The color value
 * @returns Normalized color as hex value
 */
export function normalizeColor(value) {
    const tmp = value.trim().toLowerCase();
    if (!tmp) {
        return '';
    }
    if (tmp[0] === '#') {
        return tmp;
    }
    const matches = /(\d+),?\s?(\d+),?\s?(\d+)/.exec(tmp);
    if (matches) {
        const r = Number(matches[1]);
        const g = Number(matches[2]);
        const b = Number(matches[3]);
        return rgbToHex(r, g, b).toLowerCase();
    }
    return tmp;
}
//# sourceMappingURL=ColorConverter.js.map