constructor()

in src/canvastools/ts/CanvasTools/Core/Colors/Color.ts [63:98]


    constructor(...args) {
        if (args.length === 1) {
            const c = args[0];
            if (c instanceof SRGBColor) {
                this.srgbColor = c;
            } else if (c instanceof RGBColor) {
                this.rgbColor = c;
                this.srgbColor = c.toSRGB();
            } else if (c instanceof HSLColor) {
                this.hslColor = c;
                this.srgbColor = c.toSRGB();
            } else if (c instanceof XYZColor) {
                this.xyzColor = c;
                this.rgbColor = c.toRGB();
                this.srgbColor = this.rgbColor.toSRGB();
            } else if (c instanceof LABColor) {
                this.labColor = c;
                this.xyzColor = c.toXYZ();
                this.rgbColor = this.xyzColor.toRGB();
                this.srgbColor = this.rgbColor.toSRGB();
            } else if (typeof c === "string") {
                this.srgbColor = SRGBColor.ParseHex(c);
            } else {
                throw new Error("Wrong arg type. Expected one of the '***Color' types.");
            }
        } else if (args.length === 3) {
            if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number") {
                this.srgbColor = new SRGBColor(args[0], args[1], args[2]);
            } else {
                throw new Error("Wrong arg type. Expected 3 args of the 'number' type.");
            }

        } else {
            throw new Error("Wrong args for Color constructor.");
        }
    }