in seriously.js [5341:5460]
color: function (value, input, defaultValue, oldValue) {
var s, a, i, computed, bg;
a = oldValue || [];
if (typeof value === 'string') {
//todo: support percentages, decimals
s = (/^(rgb|hsl)a?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d+(\.\d*)?)\s*)?\)/i).exec(value);
if (s && s.length) {
if (s.length < 3) {
a[0] = a[1] = a[2] = a[3] = 0;
return a;
}
a[3] = 1;
for (i = 0; i < 3; i++) {
a[i] = parseFloat(s[i+2]) / 255;
}
if (!isNaN(s[6])) {
a[3] = parseFloat(s[6]);
}
if (s[1].toLowerCase() === 'hsl') {
return hslToRgb(a[0], a[1], a[2], a[3], a);
}
return a;
}
s = (/^#(([0-9a-fA-F]{3,8}))/).exec(value);
if (s && s.length) {
s = s[1];
if (s.length === 3) {
a[0] = parseInt(s[0], 16) / 15;
a[1] = parseInt(s[1], 16) / 15;
a[2] = parseInt(s[2], 16) / 15;
a[3] = 1;
} else if (s.length === 4) {
a[0] = parseInt(s[0], 16) / 15;
a[1] = parseInt(s[1], 16) / 15;
a[2] = parseInt(s[2], 16) / 15;
a[3] = parseInt(s[3], 16) / 15;
} else if (s.length === 6) {
a[0] = parseInt(s.substr(0, 2), 16) / 255;
a[1] = parseInt(s.substr(2, 2), 16) / 255;
a[2] = parseInt(s.substr(4, 2), 16) / 255;
a[3] = 1;
} else if (s.length === 8) {
a[0] = parseInt(s.substr(0, 2), 16) / 255;
a[1] = parseInt(s.substr(2, 2), 16) / 255;
a[2] = parseInt(s.substr(4, 2), 16) / 255;
a[3] = parseInt(s.substr(6, 2), 16) / 255;
} else {
a[0] = a[1] = a[2] = a[3] = 0;
}
return a;
}
s = colorNames[value.toLowerCase()];
if (s) {
for (i = 0; i < 4; i++) {
a[i] = s[i];
}
return a;
}
if (!colorElement) {
colorElement = document.createElement('a');
}
colorElement.style.backgroundColor = '';
colorElement.style.backgroundColor = value;
computed = window.getComputedStyle(colorElement);
bg = computed.getPropertyValue('background-color') ||
computed.getPropertyValue('backgroundColor') ||
colorElement.style.backgroundColor;
if (bg && bg !== value) {
return Seriously.inputValidators.color(bg, input, oldValue);
}
a[0] = a[1] = a[2] = a[3] = 0;
return a;
}
if (isArrayLike(value)) {
a = value;
if (a.length < 3) {
a[0] = a[1] = a[2] = a[3] = 0;
return a;
}
for (i = 0; i < 3; i++) {
if (isNaN(a[i])) {
a[0] = a[1] = a[2] = a[3] = 0;
return a;
}
}
if (a.length < 4) {
a.push(1);
}
return a;
}
if (typeof value === 'number') {
a[0] = a[1] = a[2] = value;
a[3] = 1;
return a;
}
if (typeof value === 'object') {
for (i = 0; i < 4; i++) {
s = colorFields[i];
if (value[s] === null || isNaN(value[s])) {
a[i] = i === 3 ? 1 : 0;
} else {
a[i] = value[s];
}
}
return a;
}
a[0] = a[1] = a[2] = a[3] = 0;
return a;
},