clean-css
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -40,4 +40,9 @@ var shortenHex = require('./shorten-hex'); | ||
var URL_PREFIX_PATTERN = /^url\(/i; | ||
var LOCAL_PREFIX_PATTERN = /^local\(/i; | ||
var VARIABLE_NAME_PATTERN = /^--\S+$/; | ||
function isLocal(value){ | ||
return LOCAL_PREFIX_PATTERN.test(value); | ||
} | ||
function isNegative(value) { | ||
@@ -93,4 +98,10 @@ return value && value[1][0] == '-' && parseFloat(value[1]) < 0; | ||
/** | ||
* @param {string} name | ||
* @param {string} value | ||
* @param {Object} compatibility | ||
* @return {string} | ||
*/ | ||
function optimizeColors(name, value, compatibility) { | ||
if (value.indexOf('#') === -1 && value.indexOf('rgb') == -1 && value.indexOf('hsl') == -1) { | ||
if (!value.match(/#|rgb|hsl/gi)) { | ||
return shortenHex(value); | ||
@@ -100,6 +111,9 @@ } | ||
value = value | ||
.replace(/rgb\((\-?\d+),(\-?\d+),(\-?\d+)\)/g, function (match, red, green, blue) { | ||
.replace(/(rgb|hsl)a?\((\-?\d+),(\-?\d+\%?),(\-?\d+\%?),(0*[1-9]+[0-9]*(.?\d*)?)\)/gi, function (match, colorFn, p1, p2, p3, alpha) { | ||
return (parseInt(alpha, 10) >= 1 ? colorFn + '(' + [p1,p2,p3].join(',') + ')' : match); | ||
}) | ||
.replace(/rgb\((\-?\d+),(\-?\d+),(\-?\d+)\)/gi, function (match, red, green, blue) { | ||
return shortenRgb(red, green, blue); | ||
}) | ||
.replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/g, function (match, hue, saturation, lightness) { | ||
.replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/gi, function (match, hue, saturation, lightness) { | ||
return shortenHsl(hue, saturation, lightness); | ||
@@ -121,8 +135,9 @@ }) | ||
}) | ||
.replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/g, function (match, colorFunction, colorDef) { | ||
.replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/gi, function (match, colorFunction, colorDef) { | ||
var tokens = colorDef.split(','); | ||
var applies = (colorFunction == 'hsl' && tokens.length == 3) || | ||
(colorFunction == 'hsla' && tokens.length == 4) || | ||
(colorFunction == 'rgb' && tokens.length == 3 && colorDef.indexOf('%') > 0) || | ||
(colorFunction == 'rgba' && tokens.length == 4 && colorDef.indexOf('%') > 0); | ||
var colorFnLowercase = colorFunction && colorFunction.toLowerCase(); | ||
var applies = (colorFnLowercase == 'hsl' && tokens.length == 3) || | ||
(colorFnLowercase == 'hsla' && tokens.length == 4) || | ||
(colorFnLowercase == 'rgb' && tokens.length === 3 && colorDef.indexOf('%') > 0) || | ||
(colorFnLowercase == 'rgba' && tokens.length == 4 && colorDef.indexOf('%') > 0); | ||
@@ -343,3 +358,3 @@ if (!applies) { | ||
function removeQuotes(name, value) { | ||
if (name == 'content' || name.indexOf('font-variation-settings') > -1 || name.indexOf('font-feature-settings') > -1 || name.indexOf('grid-') > -1) { | ||
if (name == 'content' || name.indexOf('font-variation-settings') > -1 || name.indexOf('font-feature-settings') > -1 || name == 'grid' || name.indexOf('grid-') > -1) { | ||
return value; | ||
@@ -451,3 +466,3 @@ } | ||
value; | ||
} else if (isQuoted(value)) { | ||
} else if (isQuoted(value) || isLocal(value)) { | ||
value = levelOptions.removeQuotes ? | ||
@@ -454,0 +469,0 @@ removeQuotes(name, value) : |
@@ -9,7 +9,7 @@ var functionNoVendorRegexStr = '[A-Z]+(\\-|[A-Z]|[0-9])+\\(.*?\\)'; | ||
var functionAnyRegex = new RegExp('^' + functionAnyRegexStr + '$', 'i'); | ||
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 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}\)$/i; | ||
var identifierRegex = /^(\-[a-z0-9_][a-z0-9\-_]*|[a-z][a-z0-9\-_]*)$/i; | ||
var namedEntityRegex = /^[a-z]+$/i; | ||
var prefixRegex = /^-([a-z0-9]|-)*$/i; | ||
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 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}\)$/i; | ||
var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/; | ||
@@ -16,0 +16,0 @@ var validTimeUnits = ['ms', 's']; |
@@ -80,4 +80,6 @@ var emptyCharacter = ''; | ||
var token = tokens[position]; | ||
var isPropertyBlock = token[2][0] == Token.PROPERTY_BLOCK; | ||
var propertyValue = token[2]; | ||
var isPropertyBlock = propertyValue && propertyValue[0] === Token.PROPERTY_BLOCK; | ||
var needsSemicolon; | ||
@@ -115,3 +117,5 @@ if ( context.format ) { | ||
store(context, colon(context)); | ||
value(context, token); | ||
if (propertyValue) { | ||
value(context, token); | ||
} | ||
store(context, needsSemicolon ? semicolon(context, Breaks.AfterProperty, isLast) : emptyCharacter); | ||
@@ -118,0 +122,0 @@ break; |
{ | ||
"name": "clean-css", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"author": "Jakub Pawlowicz <contact@jakubpawlowicz.com> (http://twitter.com/jakubpawlowicz)", | ||
@@ -5,0 +5,0 @@ "description": "A well-tested CSS minifier", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
437208
9207