var UUID = /** @class */ (function () {
    function UUID() {
    }
    UUID.v4 = function () {
        return ('' + 1e7 + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
            var r = crypto.getRandomValues(new Uint8Array(1))[0];
            var n = parseInt(c, 10);
            return (n ^ (r & (15 >> (n / 4)))).toString(16);
        });
    };
    return UUID;
}());
var colorShade = function (color1, color2, mix) {
    if (color2 === void 0) { color2 = '#fff'; }
    if (mix === void 0) { mix = '#fff'; }
    var c1 = parseColor(color1);
    var c2 = parseColor(color2);
    var c3 = parseColor(mix);
    if (!c1 || !c2 || !c3)
        return null;
    var mixL = c3;
    var mixD = colorMultiply(c1, c1);
    return {
        c300: rgbaToHex(colorMix(c1, mixL, 0.7)),
        c400: rgbaToHex(colorMix(c1, mixL, 0.85)),
        c500: rgbaToHex(c1),
        c600: rgbaToHex(colorMix(c1, mixD, 0.87)),
        c700: rgbaToHex(colorMix(c1, mixD, 0.7)),
        con1: rgbaToHex(Object.assign(Object.assign({}, c2), { a: 0.87 })),
        con2: rgbaToHex(Object.assign(Object.assign({}, c2), { a: 0.6 })),
        con3: rgbaToHex(Object.assign(Object.assign({}, c2), { a: 0.38 })),
        con4: rgbaToHex(Object.assign(Object.assign({}, c2), { a: 0.1 }))
    };
};
var getColorShade = function (el, name) {
    var style = getComputedStyle(el);
    var color1 = style.getPropertyValue("--bce-c500-" + name).trim();
    var color2 = style.getPropertyValue("--bce-con1-" + name).trim();
    return color1 + " " + rgbaToHex(Object.assign(Object.assign({}, parseColor(color2)), { a: 1 }));
};
var setColorShade = function (el, name, colors, mix) {
    var _a = colors.split(' '), color1 = _a[0], color2 = _a[1];
    var shades = colorShade(color1, color2, mix);
    for (var _i = 0, _b = Object.keys(shades || {}); _i < _b.length; _i++) {
        var shade = _b[_i];
        var color = shades[shade];
        el.style.setProperty("--bce-" + shade + "-" + name, color);
    }
};
var parseColor = function (color) {
    return color.startsWith('#') ? parseHex(color) : parseRgba(color);
};
var parseHex = function (hex) {
    var shortRegex = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i;
    var full = hex.replace(shortRegex, function (_, r, g, b, a) {
        var opacity = a !== null && a !== void 0 ? a : 'f';
        return '#' + r + r + g + g + b + b + opacity + opacity;
    });
    var fullRegex = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
    var result = fullRegex.exec(full);
    if (!result)
        return null;
    var alpha = parseInt(result[4], 16);
    return {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16),
        a: isNaN(alpha) ? 1 : alpha / 255
    };
};
var parseRgba = function (rgba) {
    var regex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d\.]+)(%)?)?\)$/;
    var match = rgba.match(regex);
    if (!match)
        return null;
    return {
        r: parseInt(match[1], 10),
        g: parseInt(match[2], 10),
        b: parseInt(match[3], 10),
        a: match[5] !== '%' ? parseFloat(match[4]) : parseInt(match[4], 10) / 100
    };
};
var rgbaToHex = function (rgba) {
    var toHex = function (n) { return Math.round(n).toString(16).padStart(2, '0'); };
    var base = "" + toHex(rgba.r) + toHex(rgba.g) + toHex(rgba.b);
    var alpha = rgba.a == 1 ? '' : toHex(rgba.a * 255);
    return "#" + base + alpha;
};
var colorMix = function (c1, c2, weight) {
    if (weight === void 0) { weight = 0.5; }
    var w = 2 * weight - 1;
    var a = c1.a - c2.a;
    var w1 = ((w * a == -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
    var w2 = 1 - w1;
    return {
        r: w1 * c1.r + w2 * c2.r,
        g: w1 * c1.g + w2 * c2.g,
        b: w1 * c1.b + w2 * c2.b,
        a: c1.a * weight + c2.a * (1 - weight)
    };
};
var colorMultiply = function (c1, c2) {
    return {
        r: (c1.r * c2.r) / 255,
        g: (c1.g * c2.g) / 255,
        b: (c1.b * c2.b) / 255,
        a: 1
    };
};
export { UUID as U, colorShade as c, getColorShade as g, setColorShade as s };
