};
}
+function unitOrNumber(validator, value1, value2) {
+ if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
+ return false;
+ } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
+ return true;
+ } else if ((validator.isUnit(value1) || validator.isNumber(value1)) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
+ return false;
+ } else if (validator.isUnit(value2) || validator.isNumber(value2)) {
+ return true;
+ } else if (validator.isUnit(value1) || validator.isNumber(value1)) {
+ return false;
+ } else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
+ return true;
+ }
+
+ return sameFunctionOrValue(validator, value1, value2);
+}
+
function zIndex(validator, value1, value2) {
if (!understandable(validator, value1, value2, 0, true) && !validator.isZIndex(value2)) {
return false;
propertyName: propertyName,
time: time,
timingFunction: timingFunction,
- unit: unit
+ unit: unit,
+ unitOrNumber: unitOrNumber
},
property: {
animationDirection: keywordWithGlobal('animation-direction'),
var functionAnyRegexStr = '(' + variableRegexStr + '|' + functionNoVendorRegexStr + '|' + functionVendorRegexStr + ')';
var calcRegex = new RegExp('^(\\-moz\\-|\\-webkit\\-)?calc\\([^\\)]+\\)$', 'i');
+var decimalRegex = /[0-9]/;
var functionAnyRegex = new RegExp('^' + functionAnyRegexStr + '$', 'i');
-var hslColorRegex = /^hsl\(\s*[\-\.\d]+\s*,\s*[\.\d]+%\s*,\s*[\.\d]+%\s*\)|hsla\(\s*[\-\.\d]+\s*,\s*[\.\d]+%\s*,\s*[\.\d]+%\s*,\s*[\.\d]+\s*\)$/;
+var hslColorRegex = /^hsl\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31}\)|hsla\(\s{0,31}[\-\.]?\d+\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+%\s{0,31},\s{0,31}\.?\d+\s{0,31}\)$/;
var identifierRegex = /^(\-[a-z0-9_][a-z0-9\-_]*|[a-z][a-z0-9\-_]*)$/i;
var longHexColorRegex = /^#[0-9a-f]{6}$/i;
var namedEntityRegex = /^[a-z]+$/i;
var prefixRegex = /^-([a-z0-9]|-)*$/i;
-var rgbColorRegex = /^rgb\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*\)|rgba\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\.\d]+\s*\)$/;
+var rgbColorRegex = /^rgb\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31}\)|rgba\(\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\d]{1,3}\s{0,31},\s{0,31}[\.\d]+\s{0,31}\)$/;
var shortHexColorRegex = /^#[0-9a-f]{3}$/i;
-var timeRegex = new RegExp('^(\\-?\\+?\\.?\\d+\\.?\\d*(s|ms))$');
var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/;
+var validTimeUnits = ['ms', 's'];
var urlRegex = /^url\([\s\S]+\)$/i;
var variableRegex = new RegExp('^' + variableRegexStr + '$', 'i');
+var DECIMAL_DOT = '.';
+var MINUS_SIGN = '-';
+var PLUS_SIGN = '+';
+
var Keywords = {
'^': [
'inherit',
}
function isNumber(value) {
- return value.length > 0 && ('' + parseFloat(value)) === value;
+ return scanForNumber(value) == value.length;
}
function isRgbColor(value) {
}
function isTime(value) {
- return timeRegex.test(value);
+ var numberUpTo = scanForNumber(value);
+
+ return numberUpTo == value.length && parseInt(value) === 0 ||
+ numberUpTo > -1 && validTimeUnits.indexOf(value.slice(numberUpTo + 1)) > -1;
}
function isTimingFunction() {
};
}
-function isUnit(compatibleCssUnitRegex, value) {
- return compatibleCssUnitRegex.test(value);
+function isUnit(validUnits, value) {
+ var numberUpTo = scanForNumber(value);
+
+ return numberUpTo == value.length && parseInt(value) === 0 ||
+ numberUpTo > -1 && validUnits.indexOf(value.slice(numberUpTo + 1)) > -1 ||
+ value == 'auto' ||
+ value == 'inherit';
}
function isUrl(value) {
isKeyword('^')(value);
}
+function scanForNumber(value) {
+ var hasDot = false;
+ var hasSign = false;
+ var character;
+ var i, l;
+
+ for (i = 0, l = value.length; i < l; i++) {
+ character = value[i];
+
+ if (i === 0 && (character == PLUS_SIGN || character == MINUS_SIGN)) {
+ hasSign = true;
+ } else if (i > 0 && hasSign && (character == PLUS_SIGN || character == MINUS_SIGN)) {
+ return i - 1;
+ } else if (character == DECIMAL_DOT && !hasDot) {
+ hasDot = true;
+ } else if (character == DECIMAL_DOT && hasDot) {
+ return i - 1;
+ } else if (decimalRegex.test(character)) {
+ continue;
+ } else {
+ return i - 1;
+ }
+ }
+
+ return i;
+}
+
function validator(compatibility) {
var validUnits = Units.slice(0).filter(function (value) {
return !(value in compatibility.units) || compatibility.units[value] === true;
});
- var compatibleCssUnitRegex = new RegExp('^(\\-?\\.?\\d+\\.?\\d*(' + validUnits.join('|') + '|)|auto|inherit)$', 'i');
-
return {
colorOpacity: compatibility.colors.opacity,
isAnimationDirectionKeyword: isKeyword('animation-direction'),
isLineHeightKeyword: isKeyword('line-height'),
isListStylePositionKeyword: isKeyword('list-style-position'),
isListStyleTypeKeyword: isKeyword('list-style-type'),
+ isNumber: isNumber,
isPrefixed: isPrefixed,
isPositiveNumber: isPositiveNumber,
isRgbColor: isRgbColor,
isStyleKeyword: isKeyword('*-style'),
isTime: isTime,
- isUnit: isUnit.bind(null, compatibleCssUnitRegex),
+ isUnit: isUnit.bind(null, validUnits),
isUrl: isUrl,
isVariable: isVariable,
isWidth: isKeyword('width'),