mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 20:30:04 +02:00
update minify
This commit is contained in:
35
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
35
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
@@ -37,8 +37,13 @@ var IMPORT_PREFIX_PATTERN = /^@import/i;
|
||||
var QUOTED_PATTERN = /^('.*'|".*")$/;
|
||||
var QUOTED_BUT_SAFE_PATTERN = /^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/;
|
||||
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) {
|
||||
return value && value[1][0] == '-' && parseFloat(value[1]) < 0;
|
||||
}
|
||||
@@ -89,16 +94,25 @@ function optimizeBorderRadius(property) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
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);
|
||||
})
|
||||
.replace(/(^|[^='"])#([0-9a-f]{6})/gi, function (match, prefix, color, at, inputValue) {
|
||||
@@ -115,12 +129,13 @@ function optimizeColors(name, value, compatibility) {
|
||||
.replace(/(^|[^='"])#([0-9a-f]{3})/gi, function (match, prefix, color) {
|
||||
return prefix + '#' + color.toLowerCase();
|
||||
})
|
||||
.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);
|
||||
|
||||
if (!applies) {
|
||||
return match;
|
||||
@@ -336,7 +351,7 @@ function optimizeZeroUnits(name, value) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -443,7 +458,7 @@ function optimizeBody(rule, properties, context) {
|
||||
value = !options.compatibility.properties.urlQuotes ?
|
||||
removeUrlQuotes(value) :
|
||||
value;
|
||||
} else if (isQuoted(value)) {
|
||||
} else if (isQuoted(value) || isLocal(value)) {
|
||||
value = levelOptions.removeQuotes ?
|
||||
removeQuotes(name, value) :
|
||||
value;
|
||||
|
Reference in New Issue
Block a user