diff --git a/tinycolor.js b/tinycolor.js index 9580299..0cb2a56 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -303,15 +303,23 @@ tinycolor.fromRatio = function(color, opts) { // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%" // function inputToRGB(color) { - + var rgb = { r: 0, g: 0, b: 0 }; var a = 1; var s = null; var v = null; var l = null; var ok = false; + var tooManyCommas = false; var format = false; + var colorSplitToArray = "" + color.split(","); + for(var i=0, len=colorSplitToArray.length; i 360 || color.s < 0 || color.s > 100 || color.l < 0 || color.l > 100) { + ok = false; + } else { + ok = true; + } s = convertToPercentage(color.s); l = convertToPercentage(color.l); rgb = hslToRgb(color.h, s, l); - ok = true; format = "hsl"; } if (color.hasOwnProperty("a")) { + if (format === "hsl" && color.a > 1 || color.a < 0) { + ok = false; + } a = color.a; } + if (tooManyCommas) ok = false; } - a = boundAlpha(a); return { @@ -1050,21 +1069,24 @@ function convertHexToDecimal(h) { var matchers = (function() { + + // var CSS_INTEGER = "[-\\+]?\\d+%?"; - + // var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?"; // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; - + // Actual matching. // Parentheses and commas are optional, but not required. // Whitespace can take the place of commas or opening paren var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; + var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; - + return { CSS_UNIT: new RegExp(CSS_UNIT), rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),