(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.hexToHsl = void 0;
    var hexToHsl = function (hex) {
        var result = /^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i.exec(hex);
        if (!result) {
            return null;
        }
        var rHex = parseInt(result[1], 16);
        var gHex = parseInt(result[2], 16);
        var bHex = parseInt(result[3], 16);
        var r = rHex / 255;
        var g = gHex / 255;
        var b = bHex / 255;
        var max = Math.max(r, g, b);
        var min = Math.min(r, g, b);
        var h = (max + min) / 2;
        var s = h;
        var l = h;
        if (max === min) {
            // Achromatic
            return { h: 0, s: 0, l: l };
        }
        var d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        switch (max) {
            case r:
                h = (g - b) / d + (g < b ? 6 : 0);
                break;
            case g:
                h = (b - r) / d + 2;
                break;
            case b:
                h = (r - g) / d + 4;
                break;
        }
        h /= 6;
        s = s * 100;
        s = Math.round(s);
        l = l * 100;
        l = Math.round(l);
        h = Math.round(360 * h);
        return { h: h, s: s, l: l };
    };
    exports.hexToHsl = hexToHsl;
});
