var cssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(px|%|em|rem|in|cm|mm|ex|pt|pc|vw|vh|vmin|vmax|)|auto|inherit)';
var cssFunctionNoVendorRegexStr = '[A-Z]+(\\-|[A-Z]|[0-9])+\\(([A-Z]|[0-9]|\\ |\\,|\\#|\\+|\\-|\\%|\\.|\\(|\\))*\\)';
var cssFunctionVendorRegexStr = '\\-(\\-|[A-Z]|[0-9])+\\(([A-Z]|[0-9]|\\ |\\,|\\#|\\+|\\-|\\%|\\.|\\(|\\))*\\)';
- var cssFunctionAnyRegexStr = '(' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
- var cssUnitAnyRegexStr = '(none|' + widthKeywords.join('|') + '|' + cssUnitRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
+ var cssVariableRegexStr = 'var\\(\\-\\-[^\\)]+\\)';
+ var cssFunctionAnyRegexStr = '(' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
+ var cssUnitAnyRegexStr = '(none|' + widthKeywords.join('|') + '|' + cssUnitRegexStr + '|' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
var backgroundRepeatKeywords = ['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'inherit'];
var backgroundAttachmentKeywords = ['inherit', 'scroll', 'fixed', 'local'];
// We don't really check if it's a valid color value, but allow any letters in it
return s !== 'auto' && (s === 'transparent' || s === 'inherit' || /^[a-zA-Z]+$/.test(s));
},
+ isValidVariable: function(s) {
+ return new RegExp('^' + cssVariableRegexStr + '$', 'gi').test(s);
+ },
isValidColor: function (s) {
- return validator.isValidNamedColor(s) || validator.isValidHexColor(s) || validator.isValidRgbaColor(s) || validator.isValidHslaColor(s);
+ return validator.isValidNamedColor(s) || validator.isValidHexColor(s) || validator.isValidRgbaColor(s) || validator.isValidHslaColor(s) || validator.isValidVariable(s);
},
isValidUrl: function (s) {
// NOTE: at this point all URLs are replaced with placeholders by clean-css, so we check for those placeholders
return new RegExp('^' + cssFunctionAnyRegexStr + '$', 'gi').test(s);
},
isValidBackgroundRepeat: function (s) {
- return backgroundRepeatKeywords.indexOf(s) >= 0;
+ return backgroundRepeatKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidBackgroundAttachment: function (s) {
- return backgroundAttachmentKeywords.indexOf(s) >= 0;
+ return backgroundAttachmentKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidBackgroundPositionPart: function (s) {
if (backgroundPositionKeywords.indexOf(s) >= 0)
return true;
- return new RegExp('^' + cssUnitRegexStr + '$', 'gi').test(s);
+ return new RegExp('^' + cssUnitRegexStr + '$', 'gi').test(s) || validator.isValidVariable(s);
},
isValidBackgroundPosition: function (s) {
if (s === 'inherit')
return s.split(' ').filter(function (p) {
return p !== '';
}).every(function(p) {
- return validator.isValidBackgroundPositionPart(p);
+ return validator.isValidBackgroundPositionPart(p) || validator.isValidVariable(s);
});
},
isValidListStyleType: function (s) {
- return listStyleTypeKeywords.indexOf(s) >= 0;
+ return listStyleTypeKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidListStylePosition: function (s) {
- return listStylePositionKeywords.indexOf(s) >= 0;
+ return listStylePositionKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidOutlineColor: function (s) {
return s === 'invert' || validator.isValidColor(s) || validator.isValidVendorPrefixedValue(s);
},
isValidOutlineStyle: function (s) {
- return outlineStyleKeywords.indexOf(s) >= 0;
+ return outlineStyleKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidOutlineWidth: function (s) {
- return validator.isValidUnit(s) || widthKeywords.indexOf(s) >= 0;
+ return validator.isValidUnit(s) || widthKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
},
isValidVendorPrefixedValue: function (s) {
return /^-([A-Za-z0-9]|-)*$/gi.test(s);