(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.ColorItem = void 0;
    // tslint:disable:member-ordering
    var ColorItem = /** @class */ (function () {
        function ColorItem(colorCodeOrRed, namedColorOrGreen, blue, alpha) {
            if (typeof colorCodeOrRed === "string") {
                this.colorCode = colorCodeOrRed;
                if (typeof namedColorOrGreen === "string") {
                    this.namedColor = namedColorOrGreen;
                }
                var r = ColorItem.parseRgb(this.colorCode);
                this.red = r.red;
                this.green = r.green;
                this.blue = r.blue;
                this.alpha = r.alpha;
            }
            else {
                this.red = colorCodeOrRed;
                if (typeof namedColorOrGreen === "number") {
                    this.green = namedColorOrGreen;
                }
                this.blue = blue;
                this.alpha = alpha;
                this.colorCode = ColorItem.rgb(this.red, this.green, this.blue, this.alpha);
            }
        }
        ColorItem.prototype.toString = function () {
            return this.colorCode;
        };
        ColorItem.prototype.withAlphaPercent = function (a) {
            // a = a * 255;
            return new ColorItem(this.red, this.green, this.blue, a);
        };
        ColorItem.parseRgb = function (rgba) {
            if (/^\#/.test(rgba)) {
                rgba = rgba.substr(1);
                // this is hex...
                if (rgba.length === 3) {
                    rgba = rgba.split("").map(function (x) { return x + x; }).join("");
                }
                var red = Number.parseInt(rgba[0] + rgba[1], 16);
                var green = Number.parseInt(rgba[2] + rgba[3], 16);
                var blue = Number.parseInt(rgba[4] + rgba[5], 16);
                if (rgba.length > 6) {
                    var alpha = Number.parseInt(rgba[6] + rgba[7], 16);
                    return { red: red, green: green, blue: blue, alpha: alpha };
                }
                return { red: red, green: green, blue: blue };
            }
            if (/^rgba/i.test(rgba)) {
                rgba = rgba.substr(5);
                rgba = rgba.substr(0, rgba.length - 1);
                var a = rgba.split(",").map(function (x, i) { return i === 3 ? Number.parseFloat(x) : Number.parseInt(x, 10); });
                return { red: a[0], green: a[1], blue: a[2], alpha: a[3] };
            }
            if (/^rgb/i.test(rgba)) {
                rgba = rgba.substr(4);
                rgba = rgba.substr(0, rgba.length - 1);
                var a = rgba.split(",").map(function (x) { return Number.parseInt(x, 10); });
                return { red: a[0], green: a[1], blue: a[2] };
            }
            throw new Error("Unknown color format " + rgba);
        };
        ColorItem.rgb = function (r, g, b, a) {
            // if (!isInt(r)) {
            //     // all must be less than one...
            //     if (isInt(g) || isInt(b) || (a !== undefined && isInt(a))) {
            //         throw new Error("All color values must be either fractions or integers between 0 to 255");
            //     }
            //     r = r * 255;
            //     g = g * 255;
            //     b = b * 255;
            // }
            if (a !== undefined) {
                return "rgba(" + r + "," + g + "," + b + "," + a + ")";
            }
            return "#" + toFixedString(r) + toFixedString(g) + toFixedString(b);
        };
        return ColorItem;
    }());
    exports.ColorItem = ColorItem;
    // function isInt(n: number): boolean {
    //     return Number(n) === n && n % 1 === 0;
    // }
    function toFixedString(t) {
        return ("0" + t.toString(16)).slice(-2);
    }
    var Colors = /** @class */ (function () {
        function Colors() {
        }
        Colors.rgba = function (red, green, blue, alpha) {
            return new ColorItem(red, green, blue, alpha);
        };
        Colors.parse = function (color) {
            if (!color) {
                return null;
            }
            color = color.toLowerCase();
            // check if exists in current...
            for (var key in Colors) {
                if (Colors.hasOwnProperty(key)) {
                    var element = Colors[key];
                    if (element instanceof ColorItem) {
                        var ci = element;
                        if (ci.namedColor === color) {
                            return ci;
                        }
                    }
                }
            }
            if (/^(\#|rgb\(|rgba\()/i.test(color)) {
                return new ColorItem(color);
            }
            throw new Error("Invalid color format " + color);
        };
        Colors.black = new ColorItem("#000000", "black");
        Colors.silver = new ColorItem("#c0c0c0", "silver");
        Colors.gray = new ColorItem("#808080", "gray");
        Colors.white = new ColorItem("#ffffff", "white");
        Colors.maroon = new ColorItem("#800000", "maroon");
        Colors.red = new ColorItem("#ff0000", "red");
        Colors.purple = new ColorItem("#800080", "purple");
        Colors.fuchsia = new ColorItem("#ff00ff", "fuchsia");
        Colors.green = new ColorItem("#008000", "green");
        Colors.lime = new ColorItem("#00ff00", "lime");
        Colors.olive = new ColorItem("#808000", "olive");
        Colors.yellow = new ColorItem("#ffff00", "yellow");
        Colors.navy = new ColorItem("#000080", "navy");
        Colors.blue = new ColorItem("#0000ff", "blue");
        Colors.teal = new ColorItem("#008080", "teal");
        Colors.aqua = new ColorItem("#00ffff", "aqua");
        Colors.orange = new ColorItem("#ffa500", "orange");
        Colors.aliceBlue = new ColorItem("#f0f8ff", "aliceblue");
        Colors.antiqueWhite = new ColorItem("#faebd7", "antiquewhite");
        Colors.aquaMarine = new ColorItem("#7fffd4", "aquamarine");
        Colors.azure = new ColorItem("#f0ffff", "azure");
        Colors.beige = new ColorItem("#f5f5dc", "beige");
        Colors.bisque = new ColorItem("#ffe4c4", "bisque");
        Colors.blanchedAlmond = new ColorItem("#ffebcd", "blanchedalmond");
        Colors.blueViolet = new ColorItem("#8a2be2", "blueviolet");
        Colors.brown = new ColorItem("#a52a2a", "brown");
        Colors.burlyWood = new ColorItem("#deb887", "burlywood");
        Colors.cadetBlue = new ColorItem("#5f9ea0", "cadetblue");
        Colors.chartReuse = new ColorItem("#7fff00", "chartreuse");
        Colors.chocolate = new ColorItem("#d2691e", "chocolate");
        Colors.coral = new ColorItem("#ff7f50", "coral");
        Colors.cornFlowerBlue = new ColorItem("#6495ed", "cornflowerblue");
        Colors.cornSilk = new ColorItem("#fff8dc", "cornsilk");
        Colors.crimson = new ColorItem("#dc143c", "crimson");
        Colors.cyan = new ColorItem("#00ffff", "cyan");
        Colors.darkBlue = new ColorItem("#00008b", "darkblue");
        Colors.darkCyan = new ColorItem("#008b8b", "darkcyan");
        Colors.darkGoldenRod = new ColorItem("#b8860b", "darkgoldenrod");
        Colors.darkGray = new ColorItem("#a9a9a9", "darkgray");
        Colors.darkGreen = new ColorItem("#006400", "darkgreen");
        Colors.darkGrey = new ColorItem("#a9a9a9", "darkgrey");
        Colors.darkKhaki = new ColorItem("#bdb76b", "darkkhaki");
        Colors.darkMagenta = new ColorItem("#8b008b", "darkmagenta");
        Colors.darkOliveGreen = new ColorItem("#556b2f", "darkolivegreen");
        Colors.darkOrange = new ColorItem("#ff8c00", "darkorange");
        Colors.darkOrchid = new ColorItem("#9932cc", "darkorchid");
        Colors.darkRed = new ColorItem("#8b0000", "darkred");
        Colors.darkSalmon = new ColorItem("#e9967a", "darksalmon");
        Colors.darkSeaGreen = new ColorItem("#8fbc8f", "darkseagreen");
        Colors.darkSlateBlue = new ColorItem("#483d8b", "darkslateblue");
        Colors.darkSlateGray = new ColorItem("#2f4f4f", "darkslategray");
        Colors.darkSlateGrey = new ColorItem("#2f4f4f", "darkslategrey");
        Colors.darkTurquoise = new ColorItem("#00ced1", "darkturquoise");
        Colors.darkViolet = new ColorItem("#9400d3", "darkviolet");
        Colors.deepPink = new ColorItem("#ff1493", "deeppink");
        Colors.deepSkyBlue = new ColorItem("#00bfff", "deepskyblue");
        Colors.dimGray = new ColorItem("#696969", "dimgray");
        Colors.dimGrey = new ColorItem("#696969", "dimgrey");
        Colors.dodgerBlue = new ColorItem("#1e90ff", "dodgerblue");
        Colors.fireBrick = new ColorItem("#b22222", "firebrick");
        Colors.floralWhite = new ColorItem("#fffaf0", "floralwhite");
        Colors.forestGreen = new ColorItem("#228b22", "forestgreen");
        Colors.gainsboro = new ColorItem("#dcdcdc", "gainsboro");
        Colors.ghostWhite = new ColorItem("#f8f8ff", "ghostwhite");
        Colors.gold = new ColorItem("#ffd700", "gold");
        Colors.goldenRod = new ColorItem("#daa520", "goldenrod");
        Colors.greenYellow = new ColorItem("#adff2f", "greenyellow");
        Colors.grey = new ColorItem("#808080", "grey");
        Colors.honeyDew = new ColorItem("#f0fff0", "honeydew");
        Colors.hotPink = new ColorItem("#ff69b4", "hotpink");
        Colors.indianRed = new ColorItem("#cd5c5c", "indianred");
        Colors.indigo = new ColorItem("#4b0082", "indigo");
        Colors.ivory = new ColorItem("#fffff0", "ivory");
        Colors.khaki = new ColorItem("#f0e68c", "khaki");
        Colors.lavender = new ColorItem("#e6e6fa", "lavender");
        Colors.lavenderBlush = new ColorItem("#fff0f5", "lavenderblush");
        Colors.lawnGreen = new ColorItem("#7cfc00", "lawngreen");
        Colors.lemonChiffon = new ColorItem("#fffacd", "lemonchiffon");
        Colors.lightBlue = new ColorItem("#add8e6", "lightblue");
        Colors.lightCoral = new ColorItem("#f08080", "lightcoral");
        Colors.lightCyan = new ColorItem("#e0ffff", "lightcyan");
        Colors.lightGoldenRodYellow = new ColorItem("#fafad2", "lightgoldenrodyellow");
        Colors.lightGray = new ColorItem("#d3d3d3", "lightgray");
        Colors.lightGreen = new ColorItem("#90ee90", "lightgreen");
        Colors.lightGrey = new ColorItem("#d3d3d3", "lightgrey");
        Colors.lightPink = new ColorItem("#ffb6c1", "lightpink");
        Colors.lightSalmon = new ColorItem("#ffa07a", "lightsalmon");
        Colors.lightSeaGreen = new ColorItem("#20b2aa", "lightseagreen");
        Colors.lightSkyBlue = new ColorItem("#87cefa", "lightskyblue");
        Colors.lightSlateGray = new ColorItem("#778899", "lightslategray");
        Colors.lightSlateGrey = new ColorItem("#778899", "lightslategrey");
        Colors.lightSteelBlue = new ColorItem("#b0c4de", "lightsteelblue");
        Colors.lightYellow = new ColorItem("#ffffe0", "lightyellow");
        Colors.limeGreen = new ColorItem("#32cd32", "limegreen");
        Colors.linen = new ColorItem("#faf0e6", "linen");
        Colors.magenta = new ColorItem("#ff00ff", "magenta");
        Colors.mediumAquaMarine = new ColorItem("#66cdaa", "mediumaquamarine");
        Colors.mediumBlue = new ColorItem("#0000cd", "mediumblue");
        Colors.mediumOrchid = new ColorItem("#ba55d3", "mediumorchid");
        Colors.mediumPurple = new ColorItem("#9370db", "mediumpurple");
        Colors.mediumSeaGreen = new ColorItem("#3cb371", "mediumseagreen");
        Colors.mediumSlateBlue = new ColorItem("#7b68ee", "mediumslateblue");
        Colors.mediumSpringGreen = new ColorItem("#00fa9a", "mediumspringgreen");
        Colors.mediumTurquoise = new ColorItem("#48d1cc", "mediumturquoise");
        Colors.mediumVioletred = new ColorItem("#c71585", "mediumvioletred");
        Colors.midNightBlue = new ColorItem("#191970", "midnightblue");
        Colors.mintCream = new ColorItem("#f5fffa", "mintcream");
        Colors.mistyRose = new ColorItem("#ffe4e1", "mistyrose");
        Colors.moccasin = new ColorItem("#ffe4b5", "moccasin");
        Colors.navajoWhite = new ColorItem("#ffdead", "navajowhite");
        Colors.oldLace = new ColorItem("#fdf5e6", "oldlace");
        Colors.oliveDrab = new ColorItem("#6b8e23", "olivedrab");
        Colors.orangeRed = new ColorItem("#ff4500", "orangered");
        Colors.orchid = new ColorItem("#da70d6", "orchid");
        Colors.paleGoldenRod = new ColorItem("#eee8aa", "palegoldenrod");
        Colors.paleGreen = new ColorItem("#98fb98", "palegreen");
        Colors.paleTurquoise = new ColorItem("#afeeee", "paleturquoise");
        Colors.paleVioletRed = new ColorItem("#db7093", "palevioletred");
        Colors.papayaWhip = new ColorItem("#ffefd5", "papayawhip");
        Colors.peachPuff = new ColorItem("#ffdab9", "peachpuff");
        Colors.peru = new ColorItem("#cd853f", "peru");
        Colors.pink = new ColorItem("#ffc0cb", "pink");
        Colors.plum = new ColorItem("#dda0dd", "plum");
        Colors.powderBlue = new ColorItem("#b0e0e6", "powderblue");
        Colors.rosyBrown = new ColorItem("#bc8f8f", "rosybrown");
        Colors.royalBlue = new ColorItem("#4169e1", "royalblue");
        Colors.saddleBrown = new ColorItem("#8b4513", "saddlebrown");
        Colors.salmon = new ColorItem("#fa8072", "salmon");
        Colors.sandyBrown = new ColorItem("#f4a460", "sandybrown");
        Colors.seaGreen = new ColorItem("#2e8b57", "seagreen");
        Colors.seaShell = new ColorItem("#fff5ee", "seashell");
        Colors.sienna = new ColorItem("#a0522d", "sienna");
        Colors.skyBlue = new ColorItem("#87ceeb", "skyblue");
        Colors.slateBlue = new ColorItem("#6a5acd", "slateblue");
        Colors.slateGray = new ColorItem("#708090", "slategray");
        Colors.slateGrey = new ColorItem("#708090", "slategrey");
        Colors.snow = new ColorItem("#fffafa", "snow");
        Colors.springGreen = new ColorItem("#00ff7f", "springgreen");
        Colors.steelBlue = new ColorItem("#4682b4", "steelblue");
        Colors.tan = new ColorItem("#d2b48c", "tan");
        Colors.thistle = new ColorItem("#d8bfd8", "thistle");
        Colors.tomato = new ColorItem("#ff6347", "tomato");
        Colors.turquoise = new ColorItem("#40e0d0", "turquoise");
        Colors.violet = new ColorItem("#ee82ee", "violet");
        Colors.wheat = new ColorItem("#f5deb3", "wheat");
        Colors.whiteSmoke = new ColorItem("#f5f5f5", "whitesmoke");
        Colors.yellowGreen = new ColorItem("#9acd32", "yellowgreen");
        Colors.rebeccaPurple = new ColorItem("#663399", "rebeccapurple");
        return Colors;
    }());
    exports.default = Colors;
});
//# sourceMappingURL=Colors.js.map