import tinycolor2 from "tinycolor2";
const isGradient = (color)=>color.includes('deg');
const splitLinearColor = (str)=>str.split(', ');
const transformColor2Gradient = (colorStr)=>{
    const [degStr, startColor, endColor] = splitLinearColor(colorStr);
    const deg = +degStr.slice(0, -3);
    const endX = Math.cos(deg / 180 * Math.PI);
    const endY = Math.sin(deg / 180 * Math.PI);
    return {
        gradient: 'linear',
        x0: endX < 0 ? Math.abs(endX) : 0,
        x1: endX > 0 ? endX : 0,
        y1: endY < 0 ? Math.abs(endY) : 0,
        y0: endY > 0 ? endY : 0,
        stops: [
            {
                offset: 0,
                color: startColor
            },
            {
                offset: 1,
                color: endColor
            }
        ]
    };
};
const transform2VChartColor = (colorStr)=>{
    if (!colorStr) return colorStr;
    return isGradient(colorStr) ? transformColor2Gradient(colorStr) : colorStr;
};
const fillColorToStrokeColor = (color)=>tinycolor2(color).lighten(10).toRgbString();
const atmosphereColorToFill = (color, isGradientChart, isHorizontal)=>{
    if (isGradient(color)) return transformColor2Gradient(color);
    if (!isGradientChart) return color;
    const deg = isHorizontal ? 90 : 0;
    const start = tinycolor2(color).setAlpha(0.2).toRgbString();
    const end = tinycolor2(color).setAlpha(1).toRgbString();
    return transformColor2Gradient(`${deg}deg, ${start}, ${end}`);
};
const atmosphereColorToStroke = (color, isGradientChart, isHorizontal)=>{
    if (isGradient(color)) return transformColor2Gradient(color);
    if (!isGradientChart) return color;
    const deg = isHorizontal ? 90 : 0;
    const base = fillColorToStrokeColor(color);
    const start = tinycolor2(base).setAlpha(0.2).toRgbString();
    const end = tinycolor2(base).setAlpha(1).toRgbString();
    return transformColor2Gradient(`${deg}deg, ${start}, ${end}`);
};
export { atmosphereColorToFill, atmosphereColorToStroke, transform2VChartColor };

//# sourceMappingURL=barColor.js.map