Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Color = function(obj) {
if (obj instanceof Color) return obj;
if (! (this instanceof Color)) return new Color(obj);
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
}
// parse Color() argument
if (typeof obj == "string") {
var vals = string.getRgba(obj);
if (vals) {
this.setValues("rgb", vals);
}
else if(vals = string.getHsla(obj)) {
this.setValues("hsl", vals);
}
else if(vals = string.getHwb(obj)) {
this.setValues("hwb", vals);
}
else {
throw new Error("Unable to parse color from string \"" + obj + "\"");
}
}
else if (typeof obj == "object") {
var vals = obj;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
var Color = function(cssString) {
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
}
// parse Color() argument
if (typeof cssString == "string") {
var vals = string.getRgba(cssString);
if (vals) {
this.setValues("rgb", vals);
}
else if(vals = string.getHsla(cssString)) {
this.setValues("hsl", vals);
}
else if(vals = string.getHwb(cssString)) {
this.setValues("hwb", vals);
}
else {
throw new Error("Unable to parse color from string " + cssString);
}
}
else if (typeof cssString == "object") {
var vals = cssString;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
var Color = function(cssString) {
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
}
// parse Color() argument
if (typeof cssString == "string") {
var vals = string.getRgba(cssString);
if (vals) {
this.setValues("rgb", vals);
}
else if(vals = string.getHsla(cssString)) {
this.setValues("hsl", vals);
}
}
else if (typeof cssString == "object") {
var vals = cssString;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
this.setValues("rgb", vals)
}
else if(vals["l"] !== undefined || vals["lightness"] !== undefined) {
this.setValues("hsl", vals)
}
else if(vals["v"] !== undefined || vals["value"] !== undefined) {
var Color = function(cssString) {
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
}
// parse Color() argument
if (typeof cssString == "string") {
var vals = string.getRgba(cssString);
if (vals) {
this.setValues("rgb", vals);
}
else if(vals = string.getHsla(cssString)) {
this.setValues("hsl", vals);
}
}
else if (typeof cssString == "object") {
var vals = cssString;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
this.setValues("rgb", vals)
}
else if(vals["l"] !== undefined || vals["lightness"] !== undefined) {
this.setValues("hsl", vals)
}
else if(vals["v"] !== undefined || vals["value"] !== undefined) {
return new Color(obj);
}
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
};
// parse Color() argument
var vals;
if (typeof obj === 'string') {
vals = string.getRgba(obj);
if (vals) {
this.setValues('rgb', vals);
} else if (vals = string.getHsla(obj)) {
this.setValues('hsl', vals);
} else if (vals = string.getHwb(obj)) {
this.setValues('hwb', vals);
} else {
throw new Error('Unable to parse color from string "' + obj + '"');
}
} else if (typeof obj === 'object') {
vals = obj;
if (vals.r !== undefined || vals.red !== undefined) {
this.setValues('rgb', vals);
} else if (vals.l !== undefined || vals.lightness !== undefined) {
this.setValues('hsl', vals);
} else if (vals.v !== undefined || vals.value !== undefined) {
return new Color(obj);
}
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
};
// parse Color() argument
var vals;
if (typeof obj === 'string') {
vals = string.getRgba(obj);
if (vals) {
this.setValues('rgb', vals);
} else if (vals = string.getHsla(obj)) {
this.setValues('hsl', vals);
} else if (vals = string.getHwb(obj)) {
this.setValues('hwb', vals);
} else {
throw new Error('Unable to parse color from string "' + obj + '"');
}
} else if (typeof obj === 'object') {
vals = obj;
if (vals.r !== undefined || vals.red !== undefined) {
this.setValues('rgb', vals);
} else if (vals.l !== undefined || vals.lightness !== undefined) {
this.setValues('hsl', vals);
} else if (vals.v !== undefined || vals.value !== undefined) {
return new Color(obj);
}
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
};
// parse Color() argument
var vals;
if (typeof obj === 'string') {
vals = string.getRgba(obj);
if (vals) {
this.setValues('rgb', vals);
} else if (vals = string.getHsla(obj)) {
this.setValues('hsl', vals);
} else if (vals = string.getHwb(obj)) {
this.setValues('hwb', vals);
} else {
throw new Error('Unable to parse color from string "' + obj + '"');
}
} else if (typeof obj === 'object') {
vals = obj;
if (vals.r !== undefined || vals.red !== undefined) {
this.setValues('rgb', vals);
} else if (vals.l !== undefined || vals.lightness !== undefined) {
this.setValues('hsl', vals);
} else if (vals.v !== undefined || vals.value !== undefined) {
var Color = function(obj) {
if (obj instanceof Color) return obj;
if (! (this instanceof Color)) return new Color(obj);
this.values = {
rgb: [0, 0, 0],
hsl: [0, 0, 0],
hsv: [0, 0, 0],
hwb: [0, 0, 0],
cmyk: [0, 0, 0, 0],
alpha: 1
}
// parse Color() argument
if (typeof obj == "string") {
var vals = string.getRgba(obj);
if (vals) {
this.setValues("rgb", vals);
}
else if(vals = string.getHsla(obj)) {
this.setValues("hsl", vals);
}
else if(vals = string.getHwb(obj)) {
this.setValues("hwb", vals);
}
else {
throw new Error("Unable to parse color from string \"" + obj + "\"");
}
}
else if (typeof obj == "object") {
var vals = obj;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
// convert to all the other color spaces
for (var sname in spaces) {
if (sname != space) {
values[sname] = convert[space][sname](values[space])
}
// cap values
for (var i = 0; i < sname.length; i++) {
values[sname][i] = Math.round(Math.max(0, Math.min(maxes[sname][i], values[sname][i])));
}
}
}
// parse Color() argument
if (typeof cssString == "string") {
var vals = string.getRgba(cssString);
if (vals) {
setValues("rgb", vals);
}
else if(vals = string.getHsla(cssString)) {
setValues("hsl", vals);
}
}
else if (typeof cssString == "object") {
var vals = cssString;
if(vals["r"] !== undefined || vals["red"] !== undefined) {
setValues("rgb", vals)
}
else if(vals["l"] !== undefined || vals["lightness"] !== undefined) {
setValues("hsl", vals)
}
else if(vals["v"] !== undefined || vals["value"] !== undefined) {