};
var IE_BACKSLASH_HACK = '\\9';
+ var processable = processableInfo.processable(compatibility);
var overrides = {};
for (var granular in overridable) {
if (compatibility.properties.ieSuffixHack && !wasIEHack && isIEHack)
break;
- var _info = processableInfo.processable[_property];
+ var _info = processable[_property];
if (!isIEHack && !wasIEHack && _info && _info.canOverride && !_info.canOverride(tokens[toOverridePosition][1], value))
break;
};
var compact = function (input) {
- var processable = processableInfo.processable;
var Token = processableInfo.Token;
var tokens = Token.tokenize(input);
// NOTE: there is no point in having different vendor-specific functions override each other or standard functions,
// or having standard functions override vendor-specific functions, but standard functions can override each other
// NOTE: vendor-specific property values are not taken into consideration here at the moment
+ if (validator.isValidAndCompatibleUnitWithoutFunction(val1) && !validator.isValidAndCompatibleUnitWithoutFunction(val2))
+ return false;
if (validator.isValidUnitWithoutFunction(val2))
return true;
return {
implementedFor: /background|border|color|list|margin|outline|padding|transform/,
- processable: processable,
+ processable: function (compatibility) {
+ // FIXME: we need a proper OO way
+ validator.setCompatibility(compatibility);
+
+ return processable;
+ },
Token: Token
};
})();
module.exports = (function () {
// Regexes used for stuff
var widthKeywords = ['thin', 'thick', 'medium', 'inherit', 'initial'];
- var cssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(px|%|em|rem|in|cm|mm|ex|pt|pc|vw|vh|vmin|vmax|)|auto|inherit)';
+ var allUnits = ['px', '%', 'em', 'rem', 'in', 'cm', 'mm', 'ex', 'pt', 'pc', 'vw', 'vh', 'vmin', 'vmax'];
+ var cssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(' + allUnits.join('|') + '|)|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 cssVariableRegexStr = 'var\\(\\-\\-[^\\)]+\\)';
var listStylePositionKeywords = ['inside', 'outside', 'inherit'];
var outlineStyleKeywords = ['auto', 'inherit', 'hidden', 'none', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
+ var compatibleCssUnitRegex;
+ var compatibleCssUnitAnyRegex;
+
var validator = {
+ // FIXME: we need a proper OO here
+ setCompatibility: function (compatibility) {
+ if (compatibility.units.rem) {
+ compatibleCssUnitRegex = cssUnitRegex;
+ compatibleCssUnitAnyRegex = cssUnitAnyRegex;
+ return;
+ }
+
+ var validUnits = allUnits.slice(0).filter(function (value) {
+ return value != 'rem';
+ });
+
+ var compatibleCssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(' + validUnits.join('|') + ')|auto|inherit)';
+ compatibleCssUnitRegex = new RegExp('^' + compatibleCssUnitRegexStr + '$', 'i');
+ compatibleCssUnitAnyRegex = new RegExp('^(none|' + widthKeywords.join('|') + '|' + compatibleCssUnitRegexStr + '|' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')$', 'i');
+ },
+
isValidHexColor: function (s) {
return (s.length === 4 || s.length === 7) && s[0] === '#';
},
isValidUnitWithoutFunction: function (s) {
return cssUnitRegex.test(s);
},
+ isValidAndCompatibleUnit: function (s) {
+ return compatibleCssUnitAnyRegex.test(s);
+ },
+ isValidAndCompatibleUnitWithoutFunction: function (s) {
+ return compatibleCssUnitRegex.test(s);
+ },
isValidFunctionWithoutVendorPrefix: function (s) {
return cssFunctionNoVendorRegex.test(s);
},
'of supported and unsupported selector': '.one{color:red}.two:last-child{color:red}',
'of two unsupported selectors': '.one:before{color:red}.two:last-child{color:red}'
}, { compatibility: 'ie7' }),
+ 'units - IE8 compatibility': cssContext({
+ 'rems': 'div{padding-top:16px;padding-top:1rem}'
+ }, { compatibility: 'ie8' }),
'redefined more granular properties': redefineContext({
'animation-delay': ['animation'],
'animation-direction': ['animation'],