mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
update node modules
This commit is contained in:
466
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
466
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
@@ -1,6 +1,3 @@
|
||||
var shortenHex = require('./shorten-hex');
|
||||
var shortenHsl = require('./shorten-hsl');
|
||||
var shortenRgb = require('./shorten-rgb');
|
||||
var sortSelectors = require('./sort-selectors');
|
||||
var tidyRules = require('./tidy-rules');
|
||||
var tidyBlock = require('./tidy-block');
|
||||
@@ -11,399 +8,85 @@ var removeUnused = require('../remove-unused');
|
||||
var restoreFromOptimizing = require('../restore-from-optimizing');
|
||||
var wrapForOptimizing = require('../wrap-for-optimizing').all;
|
||||
|
||||
var configuration = require('../configuration');
|
||||
var optimizers = require('./value-optimizers');
|
||||
|
||||
var OptimizationLevel = require('../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var Token = require('../../tokenizer/token');
|
||||
var Marker = require('../../tokenizer/marker');
|
||||
|
||||
var formatPosition = require('../../utils/format-position');
|
||||
var split = require('../../utils/split');
|
||||
|
||||
var serializeRules = require('../../writer/one-time').rules;
|
||||
|
||||
var IgnoreProperty = 'ignore-property';
|
||||
|
||||
var CHARSET_TOKEN = '@charset';
|
||||
var CHARSET_REGEXP = new RegExp('^' + CHARSET_TOKEN, 'i');
|
||||
|
||||
var DEFAULT_ROUNDING_PRECISION = require('../../options/rounding-precision').DEFAULT;
|
||||
|
||||
var WHOLE_PIXEL_VALUE = /(?:^|\s|\()(-?\d+)px/;
|
||||
var TIME_VALUE = /^(\-?[\d\.]+)(m?s)$/;
|
||||
|
||||
var HEX_VALUE_PATTERN = /[0-9a-f]/i;
|
||||
var PROPERTY_NAME_PATTERN = /^(?:\-chrome\-|\-[\w\-]+\w|\w[\w\-]+\w|\-\-\S+)$/;
|
||||
var PROPERTY_NAME_PATTERN = /^(?:\-chrome\-|\-[\w\-]+\w|\w[\w\-]+\w|\w{1,}|\-\-\S+)$/;
|
||||
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;
|
||||
}
|
||||
|
||||
function isQuoted(value) {
|
||||
return QUOTED_PATTERN.test(value);
|
||||
}
|
||||
|
||||
function isUrl(value) {
|
||||
function startsAsUrl(value) {
|
||||
return URL_PREFIX_PATTERN.test(value);
|
||||
}
|
||||
|
||||
function normalizeUrl(value) {
|
||||
return value
|
||||
.replace(URL_PREFIX_PATTERN, 'url(')
|
||||
.replace(/\\?\n|\\?\r\n/g, '');
|
||||
function isImport(token) {
|
||||
return IMPORT_PREFIX_PATTERN.test(token[1]);
|
||||
}
|
||||
|
||||
function optimizeBackground(property) {
|
||||
var values = property.value;
|
||||
function isLegacyFilter(property) {
|
||||
var value;
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'none') {
|
||||
values[0][1] = '0 0';
|
||||
}
|
||||
if (property.name == 'filter' || property.name == '-ms-filter') {
|
||||
value = property.value[0][1];
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'transparent') {
|
||||
values[0][1] = '0 0';
|
||||
}
|
||||
}
|
||||
|
||||
function optimizeBorderRadius(property) {
|
||||
var values = property.value;
|
||||
var spliceAt;
|
||||
|
||||
if (values.length == 3 && values[1][1] == '/' && values[0][1] == values[2][1]) {
|
||||
spliceAt = 1;
|
||||
} else if (values.length == 5 && values[2][1] == '/' && values[0][1] == values[3][1] && values[1][1] == values[4][1]) {
|
||||
spliceAt = 2;
|
||||
} else if (values.length == 7 && values[3][1] == '/' && values[0][1] == values[4][1] && values[1][1] == values[5][1] && values[2][1] == values[6][1]) {
|
||||
spliceAt = 3;
|
||||
} else if (values.length == 9 && values[4][1] == '/' && values[0][1] == values[5][1] && values[1][1] == values[6][1] && values[2][1] == values[7][1] && values[3][1] == values[8][1]) {
|
||||
spliceAt = 4;
|
||||
}
|
||||
|
||||
if (spliceAt) {
|
||||
property.value.splice(spliceAt);
|
||||
property.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string} value
|
||||
* @param {Object} compatibility
|
||||
* @return {string}
|
||||
*/
|
||||
function optimizeColors(name, value, compatibility) {
|
||||
if (!value.match(/#|rgb|hsl/gi)) {
|
||||
return shortenHex(value);
|
||||
}
|
||||
|
||||
value = value
|
||||
.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+)%?\)/gi, function (match, hue, saturation, lightness) {
|
||||
return shortenHsl(hue, saturation, lightness);
|
||||
})
|
||||
.replace(/(^|[^='"])#([0-9a-f]{6})/gi, function (match, prefix, color, at, inputValue) {
|
||||
var suffix = inputValue[at + match.length];
|
||||
|
||||
if (suffix && HEX_VALUE_PATTERN.test(suffix)) {
|
||||
return match;
|
||||
} else if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
|
||||
return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase();
|
||||
} else {
|
||||
return (prefix + '#' + color).toLowerCase();
|
||||
}
|
||||
})
|
||||
.replace(/(^|[^='"])#([0-9a-f]{3})/gi, function (match, prefix, color) {
|
||||
return prefix + '#' + color.toLowerCase();
|
||||
})
|
||||
.replace(/(rgb|rgba|hsl|hsla)\(([^\)]+)\)/gi, function (match, colorFunction, colorDef) {
|
||||
var tokens = colorDef.split(',');
|
||||
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;
|
||||
}
|
||||
|
||||
if (tokens[1].indexOf('%') == -1) {
|
||||
tokens[1] += '%';
|
||||
}
|
||||
|
||||
if (tokens[2].indexOf('%') == -1) {
|
||||
tokens[2] += '%';
|
||||
}
|
||||
|
||||
return colorFunction + '(' + tokens.join(',') + ')';
|
||||
});
|
||||
|
||||
if (compatibility.colors.opacity && name.indexOf('background') == -1) {
|
||||
value = value.replace(/(?:rgba|hsla)\(0,0%?,0%?,0\)/g, function (match) {
|
||||
if (split(value, ',').pop().indexOf('gradient(') > -1) {
|
||||
return match;
|
||||
}
|
||||
|
||||
return 'transparent';
|
||||
});
|
||||
}
|
||||
|
||||
return shortenHex(value);
|
||||
}
|
||||
|
||||
function optimizeFilter(property) {
|
||||
if (property.value.length == 1) {
|
||||
property.value[0][1] = property.value[0][1].replace(/progid:DXImageTransform\.Microsoft\.(Alpha|Chroma)(\W)/, function (match, filter, suffix) {
|
||||
return filter.toLowerCase() + suffix;
|
||||
});
|
||||
}
|
||||
|
||||
property.value[0][1] = property.value[0][1]
|
||||
.replace(/,(\S)/g, ', $1')
|
||||
.replace(/ ?= ?/g, '=');
|
||||
}
|
||||
|
||||
function optimizeFontWeight(property, atIndex) {
|
||||
var value = property.value[atIndex][1];
|
||||
|
||||
if (value == 'normal') {
|
||||
value = '400';
|
||||
} else if (value == 'bold') {
|
||||
value = '700';
|
||||
}
|
||||
|
||||
property.value[atIndex][1] = value;
|
||||
}
|
||||
|
||||
function optimizeMultipleZeros(property) {
|
||||
var values = property.value;
|
||||
var spliceAt;
|
||||
|
||||
if (values.length == 4 && values[0][1] === '0' && values[1][1] === '0' && values[2][1] === '0' && values[3][1] === '0') {
|
||||
if (property.name.indexOf('box-shadow') > -1) {
|
||||
spliceAt = 2;
|
||||
} else {
|
||||
spliceAt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (spliceAt) {
|
||||
property.value.splice(spliceAt);
|
||||
property.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
function optimizeOutline(property) {
|
||||
var values = property.value;
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'none') {
|
||||
values[0][1] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
function optimizePixelLengths(_, value, compatibility) {
|
||||
if (!WHOLE_PIXEL_VALUE.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(WHOLE_PIXEL_VALUE, function (match, val) {
|
||||
var newValue;
|
||||
var intVal = parseInt(val);
|
||||
|
||||
if (intVal === 0) {
|
||||
return match;
|
||||
}
|
||||
|
||||
if (compatibility.properties.shorterLengthUnits && compatibility.units.pt && intVal * 3 % 4 === 0) {
|
||||
newValue = intVal * 3 / 4 + 'pt';
|
||||
}
|
||||
|
||||
if (compatibility.properties.shorterLengthUnits && compatibility.units.pc && intVal % 16 === 0) {
|
||||
newValue = intVal / 16 + 'pc';
|
||||
}
|
||||
|
||||
if (compatibility.properties.shorterLengthUnits && compatibility.units.in && intVal % 96 === 0) {
|
||||
newValue = intVal / 96 + 'in';
|
||||
}
|
||||
|
||||
if (newValue) {
|
||||
newValue = match.substring(0, match.indexOf(val)) + newValue;
|
||||
}
|
||||
|
||||
return newValue && newValue.length < match.length ? newValue : match;
|
||||
});
|
||||
}
|
||||
|
||||
function optimizePrecision(_, value, precisionOptions) {
|
||||
if (!precisionOptions.enabled || value.indexOf('.') === -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(precisionOptions.decimalPointMatcher, '$1$2$3')
|
||||
.replace(precisionOptions.zeroMatcher, function (match, integerPart, fractionPart, unit) {
|
||||
var multiplier = precisionOptions.units[unit].multiplier;
|
||||
var parsedInteger = parseInt(integerPart);
|
||||
var integer = isNaN(parsedInteger) ? 0 : parsedInteger;
|
||||
var fraction = parseFloat(fractionPart);
|
||||
|
||||
return Math.round((integer + fraction) * multiplier) / multiplier + unit;
|
||||
});
|
||||
}
|
||||
|
||||
function optimizeTimeUnits(_, value) {
|
||||
if (!TIME_VALUE.test(value))
|
||||
return value;
|
||||
|
||||
return value.replace(TIME_VALUE, function (match, val, unit) {
|
||||
var newValue;
|
||||
|
||||
if (unit == 'ms') {
|
||||
newValue = parseInt(val) / 1000 + 's';
|
||||
} else if (unit == 's') {
|
||||
newValue = parseFloat(val) * 1000 + 'ms';
|
||||
}
|
||||
|
||||
return newValue.length < match.length ? newValue : match;
|
||||
});
|
||||
}
|
||||
|
||||
function optimizeUnits(name, value, unitsRegexp) {
|
||||
if (/^(?:\-moz\-calc|\-webkit\-calc|calc|rgb|hsl|rgba|hsla)\(/.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (name == 'flex' || name == '-ms-flex' || name == '-webkit-flex' || name == 'flex-basis' || name == '-webkit-flex-basis') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height' || name == 'width' || name == 'max-width')) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(unitsRegexp, '$1' + '0' + '$2')
|
||||
.replace(unitsRegexp, '$1' + '0' + '$2');
|
||||
}
|
||||
|
||||
function optimizeWhitespace(name, value) {
|
||||
if (name.indexOf('filter') > -1 || value.indexOf(' ') == -1 || value.indexOf('expression') === 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf(Marker.SINGLE_QUOTE) > -1 || value.indexOf(Marker.DOUBLE_QUOTE) > -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value = value.replace(/\s+/g, ' ');
|
||||
|
||||
if (value.indexOf('calc') > -1) {
|
||||
value = value.replace(/\) ?\/ ?/g, ')/ ');
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(/(\(;?)\s+/g, '$1')
|
||||
.replace(/\s+(;?\))/g, '$1')
|
||||
.replace(/, /g, ',');
|
||||
}
|
||||
|
||||
function optimizeZeroDegUnit(_, value) {
|
||||
if (value.indexOf('0deg') == -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(/\(0deg\)/g, '(0)');
|
||||
}
|
||||
|
||||
function optimizeZeroUnits(name, value) {
|
||||
if (value.indexOf('0') == -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('-') > -1) {
|
||||
value = value
|
||||
.replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2')
|
||||
.replace(/([^\w\d\-]|^)\-0([^\.]|$)/g, '$10$2');
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(/(^|\s)0+([1-9])/g, '$1$2')
|
||||
.replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
|
||||
.replace(/(^|\D)\.0+(\D|$)/g, '$10$2')
|
||||
.replace(/\.([1-9]*)0+(\D|$)/g, function (match, nonZeroPart, suffix) {
|
||||
return (nonZeroPart.length > 0 ? '.' : '') + nonZeroPart + suffix;
|
||||
})
|
||||
.replace(/(^|\D)0\.(\d)/g, '$1.$2');
|
||||
}
|
||||
|
||||
function removeQuotes(name, value) {
|
||||
if (name == 'content' || name.indexOf('font-variation-settings') > -1 || name.indexOf('font-feature-settings') > -1 || name == 'grid' || name.indexOf('grid-') > -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return QUOTED_BUT_SAFE_PATTERN.test(value) ?
|
||||
value.substring(1, value.length - 1) :
|
||||
value;
|
||||
}
|
||||
|
||||
function removeUrlQuotes(value) {
|
||||
return /^url\(['"].+['"]\)$/.test(value) && !/^url\(['"].*[\*\s\(\)'"].*['"]\)$/.test(value) && !/^url\(['"]data:[^;]+;charset/.test(value) ?
|
||||
value.replace(/["']/g, '') :
|
||||
value;
|
||||
}
|
||||
|
||||
function transformValue(propertyName, propertyValue, rule, transformCallback) {
|
||||
var selector = serializeRules(rule);
|
||||
var transformedValue = transformCallback(propertyName, propertyValue, selector);
|
||||
|
||||
if (transformedValue === undefined) {
|
||||
return propertyValue;
|
||||
} else if (transformedValue === false) {
|
||||
return IgnoreProperty;
|
||||
return value.indexOf('progid') > -1 ||
|
||||
value.indexOf('alpha') === 0 ||
|
||||
value.indexOf('chroma') === 0;
|
||||
} else {
|
||||
return transformedValue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
function noop() {}
|
||||
|
||||
function optimizeBody(rule, properties, context) {
|
||||
var options = context.options;
|
||||
var levelOptions = options.level[OptimizationLevel.One];
|
||||
var valueOptimizers;
|
||||
var property, name, type, value;
|
||||
var valueIsUrl;
|
||||
var propertyToken;
|
||||
var _properties = wrapForOptimizing(properties, true);
|
||||
var propertyOptimizer;
|
||||
var serializedRule = serializeRules(rule);
|
||||
var _properties = wrapForOptimizing(properties);
|
||||
var pluginValueOptimizers = context.options.plugins.level1Value;
|
||||
var pluginPropertyOptimizers = context.options.plugins.level1Property;
|
||||
var i, l;
|
||||
|
||||
propertyLoop:
|
||||
for (var i = 0, l = _properties.length; i < l; i++) {
|
||||
for (i = 0, l = _properties.length; i < l; i++) {
|
||||
var j, k, m, n;
|
||||
|
||||
property = _properties[i];
|
||||
name = property.name;
|
||||
propertyOptimizer = configuration[name] && configuration[name].propertyOptimizer || noop;
|
||||
valueOptimizers = configuration[name] && configuration[name].valueOptimizers || [optimizers.whiteSpace];
|
||||
|
||||
if (!PROPERTY_NAME_PATTERN.test(name)) {
|
||||
propertyToken = property.all[property.position];
|
||||
context.warnings.push('Invalid property name \'' + name + '\' at ' + formatPosition(propertyToken[1][2][0]) + '. Ignoring.');
|
||||
property.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.value.length === 0) {
|
||||
propertyToken = property.all[property.position];
|
||||
context.warnings.push('Empty property \'' + name + '\' at ' + formatPosition(propertyToken[1][2][0]) + '. Ignoring.');
|
||||
property.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.hack && (
|
||||
@@ -411,17 +94,11 @@ function optimizeBody(rule, properties, context) {
|
||||
property.hack[0] == Hack.BACKSLASH && !options.compatibility.properties.ieSuffixHack ||
|
||||
property.hack[0] == Hack.BANG && !options.compatibility.properties.ieBangHack)) {
|
||||
property.unused = true;
|
||||
}
|
||||
|
||||
if (levelOptions.removeNegativePaddings && name.indexOf('padding') === 0 && (isNegative(property.value[0]) || isNegative(property.value[1]) || isNegative(property.value[2]) || isNegative(property.value[3]))) {
|
||||
property.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!options.compatibility.properties.ieFilters && isLegacyFilter(property)) {
|
||||
property.unused = true;
|
||||
}
|
||||
|
||||
if (property.unused) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -434,10 +111,10 @@ function optimizeBody(rule, properties, context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var j = 0, m = property.value.length; j < m; j++) {
|
||||
valuesLoop:
|
||||
for (j = 0, m = property.value.length; j < m; j++) {
|
||||
type = property.value[j][0];
|
||||
value = property.value[j][1];
|
||||
valueIsUrl = isUrl(value);
|
||||
|
||||
if (type == Token.PROPERTY_BLOCK) {
|
||||
property.unused = true;
|
||||
@@ -445,70 +122,27 @@ function optimizeBody(rule, properties, context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (valueIsUrl && !context.validator.isUrl(value)) {
|
||||
if (startsAsUrl(value) && !context.validator.isUrl(value)) {
|
||||
property.unused = true;
|
||||
context.warnings.push('Broken URL \'' + value + '\' at ' + formatPosition(property.value[j][2][0]) + '. Ignoring.');
|
||||
break;
|
||||
}
|
||||
|
||||
if (valueIsUrl) {
|
||||
value = levelOptions.normalizeUrls ?
|
||||
normalizeUrl(value) :
|
||||
value;
|
||||
value = !options.compatibility.properties.urlQuotes ?
|
||||
removeUrlQuotes(value) :
|
||||
value;
|
||||
} else if (isQuoted(value) || isLocal(value)) {
|
||||
value = levelOptions.removeQuotes ?
|
||||
removeQuotes(name, value) :
|
||||
value;
|
||||
} else {
|
||||
value = levelOptions.removeWhitespace ?
|
||||
optimizeWhitespace(name, value) :
|
||||
value;
|
||||
value = optimizePrecision(name, value, options.precision);
|
||||
value = optimizePixelLengths(name, value, options.compatibility);
|
||||
value = levelOptions.replaceTimeUnits ?
|
||||
optimizeTimeUnits(name, value) :
|
||||
value;
|
||||
value = levelOptions.replaceZeroUnits ?
|
||||
optimizeZeroUnits(name, value) :
|
||||
value;
|
||||
|
||||
if (options.compatibility.properties.zeroUnits) {
|
||||
value = optimizeZeroDegUnit(name, value);
|
||||
value = optimizeUnits(name, value, options.unitsRegexp);
|
||||
}
|
||||
|
||||
if (options.compatibility.properties.colors) {
|
||||
value = optimizeColors(name, value, options.compatibility);
|
||||
}
|
||||
for (k = 0, n = valueOptimizers.length; k < n; k++) {
|
||||
value = valueOptimizers[k](name, value, options);
|
||||
}
|
||||
|
||||
value = transformValue(name, value, rule, levelOptions.transform);
|
||||
|
||||
if (value === IgnoreProperty) {
|
||||
property.unused = true;
|
||||
continue propertyLoop;
|
||||
for (k = 0, n = pluginValueOptimizers.length; k < n; k++) {
|
||||
value = pluginValueOptimizers[k](name, value, options);
|
||||
}
|
||||
|
||||
property.value[j][1] = value;
|
||||
}
|
||||
|
||||
if (levelOptions.replaceMultipleZeros) {
|
||||
optimizeMultipleZeros(property);
|
||||
}
|
||||
propertyOptimizer(serializedRule, property, options);
|
||||
|
||||
if (name == 'background' && levelOptions.optimizeBackground) {
|
||||
optimizeBackground(property);
|
||||
} else if (name.indexOf('border') === 0 && name.indexOf('radius') > 0 && levelOptions.optimizeBorderRadius) {
|
||||
optimizeBorderRadius(property);
|
||||
} else if (name == 'filter'&& levelOptions.optimizeFilter && options.compatibility.properties.ieFilters) {
|
||||
optimizeFilter(property);
|
||||
} else if (name == 'font-weight' && levelOptions.optimizeFontWeight) {
|
||||
optimizeFontWeight(property, 0);
|
||||
} else if (name == 'outline' && levelOptions.optimizeOutline) {
|
||||
optimizeOutline(property);
|
||||
for (j = 0, m = pluginPropertyOptimizers.length; j < m; j++) {
|
||||
pluginPropertyOptimizers[j](serializedRule, property, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,24 +247,6 @@ function buildPrecisionOptions(roundingPrecision) {
|
||||
return precisionOptions;
|
||||
}
|
||||
|
||||
function isImport(token) {
|
||||
return IMPORT_PREFIX_PATTERN.test(token[1]);
|
||||
}
|
||||
|
||||
function isLegacyFilter(property) {
|
||||
var value;
|
||||
|
||||
if (property.name == 'filter' || property.name == '-ms-filter') {
|
||||
value = property.value[0][1];
|
||||
|
||||
return value.indexOf('progid') > -1 ||
|
||||
value.indexOf('alpha') === 0 ||
|
||||
value.indexOf('chroma') === 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function level1Optimize(tokens, context) {
|
||||
var options = context.options;
|
||||
var levelOptions = options.level[OptimizationLevel.One];
|
||||
|
10
node_modules/clean-css/lib/optimizer/level-1/property-optimizers.js
generated
vendored
Normal file
10
node_modules/clean-css/lib/optimizer/level-1/property-optimizers.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
background: require('./property-optimizers/background').level1.property,
|
||||
boxShadow: require('./property-optimizers/box-shadow').level1.property,
|
||||
borderRadius: require('./property-optimizers/border-radius').level1.property,
|
||||
filter: require('./property-optimizers/filter').level1.property,
|
||||
fontWeight: require('./property-optimizers/font-weight').level1.property,
|
||||
margin: require('./property-optimizers/margin').level1.property,
|
||||
outline: require('./property-optimizers/outline').level1.property,
|
||||
padding: require('./property-optimizers/padding').level1.property
|
||||
};
|
23
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/background.js
generated
vendored
Normal file
23
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/background.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function background(_rule, property, options) {
|
||||
var values = property.value;
|
||||
|
||||
if (!options.level[OptimizationLevel.One].optimizeBackground) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'none') {
|
||||
values[0][1] = '0 0';
|
||||
}
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'transparent') {
|
||||
values[0][1] = '0 0';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
29
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/border-radius.js
generated
vendored
Normal file
29
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/border-radius.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function borderRadius(_rule, property, options) {
|
||||
var values = property.value;
|
||||
|
||||
if (!options.level[OptimizationLevel.One].optimizeBorderRadius) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.length == 3 && values[1][1] == '/' && values[0][1] == values[2][1]) {
|
||||
property.value.splice(1);
|
||||
property.dirty = true;
|
||||
} else if (values.length == 5 && values[2][1] == '/' && values[0][1] == values[3][1] && values[1][1] == values[4][1]) {
|
||||
property.value.splice(2);
|
||||
property.dirty = true;
|
||||
} else if (values.length == 7 && values[3][1] == '/' && values[0][1] == values[4][1] && values[1][1] == values[5][1] && values[2][1] == values[6][1]) {
|
||||
property.value.splice(3);
|
||||
property.dirty = true;
|
||||
} else if (values.length == 9 && values[4][1] == '/' && values[0][1] == values[5][1] && values[1][1] == values[6][1] && values[2][1] == values[7][1] && values[3][1] == values[8][1]) {
|
||||
property.value.splice(4);
|
||||
property.dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
15
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/box-shadow.js
generated
vendored
Normal file
15
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/box-shadow.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function boxShadow(_rule, property) {
|
||||
var values = property.value;
|
||||
|
||||
// remove multiple zeros
|
||||
if (values.length == 4 && values[0][1] === '0' && values[1][1] === '0' && values[2][1] === '0' && values[3][1] === '0') {
|
||||
property.value.splice(2);
|
||||
property.dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
31
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/filter.js
generated
vendored
Normal file
31
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/filter.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var ALPHA_OR_CHROMA_FILTER_PATTERN = /progid:DXImageTransform\.Microsoft\.(Alpha|Chroma)(\W)/;
|
||||
var NO_SPACE_AFTER_COMMA_PATTERN = /,(\S)/g;
|
||||
var WHITESPACE_AROUND_EQUALS_PATTERN = / ?= ?/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function filter(_rule, property, options) {
|
||||
if (!options.compatibility.properties.ieFilters) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options.level[OptimizationLevel.One].optimizeFilter) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (property.value.length == 1) {
|
||||
property.value[0][1] = property.value[0][1].replace(ALPHA_OR_CHROMA_FILTER_PATTERN, function (match, filter, suffix) {
|
||||
return filter.toLowerCase() + suffix;
|
||||
});
|
||||
}
|
||||
|
||||
property.value[0][1] = property.value[0][1]
|
||||
.replace(NO_SPACE_AFTER_COMMA_PATTERN, ', $1')
|
||||
.replace(WHITESPACE_AROUND_EQUALS_PATTERN, '=');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
23
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/font-weight.js
generated
vendored
Normal file
23
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/font-weight.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function fontWeight(_rule, property, options) {
|
||||
var value = property.value[0][1];
|
||||
|
||||
if (!options.level[OptimizationLevel.One].optimizeFontWeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value == 'normal') {
|
||||
value = '400';
|
||||
} else if (value == 'bold') {
|
||||
value = '700';
|
||||
}
|
||||
|
||||
property.value[0][1] = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
21
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/margin.js
generated
vendored
Normal file
21
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/margin.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function margin(_rule, property, options) {
|
||||
var values = property.value;
|
||||
|
||||
if (!options.level[OptimizationLevel.One].replaceMultipleZeros) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove multiple zeros
|
||||
if (values.length == 4 && values[0][1] === '0' && values[1][1] === '0' && values[2][1] === '0' && values[3][1] === '0') {
|
||||
property.value.splice(1);
|
||||
property.dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
19
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/outline.js
generated
vendored
Normal file
19
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/outline.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function outline(_rule, property, options) {
|
||||
var values = property.value;
|
||||
|
||||
if (!options.level[OptimizationLevel.One].optimizeOutline) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (values.length == 1 && values[0][1] == 'none') {
|
||||
values[0][1] = '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
26
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/padding.js
generated
vendored
Normal file
26
node_modules/clean-css/lib/optimizer/level-1/property-optimizers/padding.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
function isNegative(value) {
|
||||
return value && value[1][0] == '-' && parseFloat(value[1]) < 0;
|
||||
}
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
property: function padding(_rule, property, options) {
|
||||
var values = property.value;
|
||||
|
||||
// remove multiple zeros
|
||||
if (values.length == 4 && values[0][1] === '0' && values[1][1] === '0' && values[2][1] === '0' && values[3][1] === '0') {
|
||||
property.value.splice(1);
|
||||
property.dirty = true;
|
||||
}
|
||||
|
||||
// remove negative paddings
|
||||
if (options.level[OptimizationLevel.One].removeNegativePaddings && (isNegative(property.value[0]) || isNegative(property.value[1]) || isNegative(property.value[2]) || isNegative(property.value[3]))) {
|
||||
property.unused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
19
node_modules/clean-css/lib/optimizer/level-1/tidy-block.js
generated
vendored
19
node_modules/clean-css/lib/optimizer/level-1/tidy-block.js
generated
vendored
@@ -1,20 +1,31 @@
|
||||
var SUPPORTED_COMPACT_BLOCK_MATCHER = /^@media\W/;
|
||||
var SUPPORTED_QUOTE_REMOVAL_MATCHER = /^@(?:keyframes|-moz-keyframes|-o-keyframes|-webkit-keyframes)\W/;
|
||||
|
||||
function tidyBlock(values, spaceAfterClosingBrace) {
|
||||
var withoutSpaceAfterClosingBrace;
|
||||
var withoutQuotes;
|
||||
var i;
|
||||
|
||||
for (i = values.length - 1; i >= 0; i--) {
|
||||
withoutSpaceAfterClosingBrace = !spaceAfterClosingBrace && SUPPORTED_COMPACT_BLOCK_MATCHER.test(values[i][1]);
|
||||
withoutQuotes = SUPPORTED_QUOTE_REMOVAL_MATCHER.test(values[i][1]);
|
||||
|
||||
values[i][1] = values[i][1]
|
||||
.replace(/\n|\r\n/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/(,|:|\() /g, '$1')
|
||||
.replace(/ \)/g, ')')
|
||||
.replace(/'([a-zA-Z][a-zA-Z\d\-_]+)'/, '$1')
|
||||
.replace(/"([a-zA-Z][a-zA-Z\d\-_]+)"/, '$1')
|
||||
.replace(withoutSpaceAfterClosingBrace ? /\) /g : null, ')');
|
||||
.replace(/ \)/g, ')');
|
||||
|
||||
if (withoutQuotes) {
|
||||
values[i][1] = values[i][1]
|
||||
.replace(/'([a-zA-Z][a-zA-Z\d\-_]+)'/, '$1')
|
||||
.replace(/"([a-zA-Z][a-zA-Z\d\-_]+)"/, '$1');
|
||||
}
|
||||
|
||||
if (withoutSpaceAfterClosingBrace) {
|
||||
values[i][1] = values[i][1]
|
||||
.replace(/\) /g, ')');
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
|
28
node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js
generated
vendored
28
node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js
generated
vendored
@@ -16,6 +16,18 @@ var ASTERISK_PLUS_HTML_HACK = '*+html ';
|
||||
var ASTERISK_FIRST_CHILD_PLUS_HTML_HACK = '*:first-child+html ';
|
||||
var LESS_THAN = '<';
|
||||
|
||||
var PSEUDO_CLASSES_WITH_SELECTORS = [
|
||||
':current',
|
||||
':future',
|
||||
':has',
|
||||
':host',
|
||||
':host-context',
|
||||
':is',
|
||||
':not',
|
||||
':past',
|
||||
':where'
|
||||
];
|
||||
|
||||
function hasInvalidCharacters(value) {
|
||||
var isEscaped;
|
||||
var isInvalid = false;
|
||||
@@ -57,7 +69,9 @@ function removeWhitespace(value, format) {
|
||||
var isAttribute;
|
||||
var isRelation;
|
||||
var isWhitespace;
|
||||
var isSpaceAwarePseudoClass;
|
||||
var roundBracketLevel = 0;
|
||||
var wasComma = false;
|
||||
var wasRelation = false;
|
||||
var wasWhitespace = false;
|
||||
var withCaseAttribute = CASE_ATTRIBUTE_PATTERN.test(value);
|
||||
@@ -72,6 +86,9 @@ function removeWhitespace(value, format) {
|
||||
isQuoted = isSingleQuoted || isDoubleQuoted;
|
||||
isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character);
|
||||
isWhitespace = WHITESPACE_PATTERN.test(character);
|
||||
isSpaceAwarePseudoClass = roundBracketLevel == 1 && character == Marker.CLOSE_ROUND_BRACKET ?
|
||||
false :
|
||||
isSpaceAwarePseudoClass || (roundBracketLevel === 0 && character == Marker.COLON && isPseudoClassWithSelectors(value, i));
|
||||
|
||||
if (wasEscaped && isQuoted && isNewLineWin) {
|
||||
// swallow escaped new windows lines in comments
|
||||
@@ -111,6 +128,10 @@ function removeWhitespace(value, format) {
|
||||
} else if (!isWhitespace && wasRelation && spaceAroundRelation) {
|
||||
stripped.push(Marker.SPACE);
|
||||
stripped.push(character);
|
||||
} else if (isWhitespace && !wasWhitespace && wasComma && roundBracketLevel > 0 && isSpaceAwarePseudoClass) {
|
||||
// skip space
|
||||
} else if (isWhitespace && !wasWhitespace && roundBracketLevel > 0 && isSpaceAwarePseudoClass) {
|
||||
stripped.push(character);
|
||||
} else if (isWhitespace && (isAttribute || roundBracketLevel > 0) && !isQuoted) {
|
||||
// skip space
|
||||
} else if (isWhitespace && wasWhitespace && !isQuoted) {
|
||||
@@ -133,6 +154,7 @@ function removeWhitespace(value, format) {
|
||||
isEscaped = character == Marker.BACK_SLASH;
|
||||
wasRelation = isRelation;
|
||||
wasWhitespace = isWhitespace;
|
||||
wasComma = character == Marker.COMMA;
|
||||
}
|
||||
|
||||
return withCaseAttribute ?
|
||||
@@ -140,6 +162,12 @@ function removeWhitespace(value, format) {
|
||||
stripped.join('');
|
||||
}
|
||||
|
||||
function isPseudoClassWithSelectors(value, colonPosition) {
|
||||
var pseudoClass = value.substring(colonPosition, value.indexOf(Marker.OPEN_ROUND_BRACKET, colonPosition));
|
||||
|
||||
return PSEUDO_CLASSES_WITH_SELECTORS.indexOf(pseudoClass) > -1;
|
||||
}
|
||||
|
||||
function removeQuotes(value) {
|
||||
if (value.indexOf('\'') == -1 && value.indexOf('"') == -1) {
|
||||
return value;
|
||||
|
14
node_modules/clean-css/lib/optimizer/level-1/value-optimizers.js
generated
vendored
Normal file
14
node_modules/clean-css/lib/optimizer/level-1/value-optimizers.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
color: require('./value-optimizers/color').level1.value,
|
||||
degrees: require('./value-optimizers/degrees').level1.value,
|
||||
fraction: require('./value-optimizers/fraction').level1.value,
|
||||
precision: require('./value-optimizers/precision').level1.value,
|
||||
textQuotes: require('./value-optimizers/text-quotes').level1.value,
|
||||
time: require('./value-optimizers/time').level1.value,
|
||||
unit: require('./value-optimizers/unit').level1.value,
|
||||
urlPrefix: require('./value-optimizers/url-prefix').level1.value,
|
||||
urlQuotes: require('./value-optimizers/url-quotes').level1.value,
|
||||
urlWhiteSpace: require('./value-optimizers/url-whitespace').level1.value,
|
||||
whiteSpace: require('./value-optimizers/whitespace').level1.value,
|
||||
zero: require('./value-optimizers/zero').level1.value
|
||||
};
|
90
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/color.js
generated
vendored
Normal file
90
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/color.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
var shortenHex = require('./color/shorten-hex');
|
||||
var shortenHsl = require('./color/shorten-hsl');
|
||||
var shortenRgb = require('./color/shorten-rgb');
|
||||
|
||||
var split = require('../../../utils/split');
|
||||
|
||||
var ANY_COLOR_FUNCTION_PATTERN = /(rgb|rgba|hsl|hsla)\(([^\(\)]+)\)/gi;
|
||||
var COLOR_PREFIX_PATTERN = /#|rgb|hsl/gi;
|
||||
var HEX_LONG_PATTERN = /(^|[^='"])#([0-9a-f]{6})/gi;
|
||||
var HEX_SHORT_PATTERN = /(^|[^='"])#([0-9a-f]{3})/gi;
|
||||
var HEX_VALUE_PATTERN = /[0-9a-f]/i;
|
||||
var HSL_PATTERN = /hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/gi;
|
||||
var RGBA_HSLA_PATTERN = /(rgb|hsl)a?\((\-?\d+),(\-?\d+\%?),(\-?\d+\%?),(0*[1-9]+[0-9]*(\.?\d*)?)\)/gi;
|
||||
var RGB_PATTERN = /rgb\((\-?\d+),(\-?\d+),(\-?\d+)\)/gi;
|
||||
var TRANSPARENT_FUNCTION_PATTERN = /(?:rgba|hsla)\(0,0%?,0%?,0\)/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function color(name, value, options) {
|
||||
if (!options.compatibility.properties.colors) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!value.match(COLOR_PREFIX_PATTERN)) {
|
||||
return shortenHex(value);
|
||||
}
|
||||
|
||||
value = value
|
||||
.replace(RGBA_HSLA_PATTERN, function (match, colorFn, p1, p2, p3, alpha) {
|
||||
return (parseInt(alpha, 10) >= 1 ? colorFn + '(' + [p1,p2,p3].join(',') + ')' : match);
|
||||
})
|
||||
.replace(RGB_PATTERN, function (match, red, green, blue) {
|
||||
return shortenRgb(red, green, blue);
|
||||
})
|
||||
.replace(HSL_PATTERN, function (match, hue, saturation, lightness) {
|
||||
return shortenHsl(hue, saturation, lightness);
|
||||
})
|
||||
.replace(HEX_LONG_PATTERN, function (match, prefix, color, at, inputValue) {
|
||||
var suffix = inputValue[at + match.length];
|
||||
|
||||
if (suffix && HEX_VALUE_PATTERN.test(suffix)) {
|
||||
return match;
|
||||
} else if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
|
||||
return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase();
|
||||
} else {
|
||||
return (prefix + '#' + color).toLowerCase();
|
||||
}
|
||||
})
|
||||
.replace(HEX_SHORT_PATTERN, function (match, prefix, color) {
|
||||
return prefix + '#' + color.toLowerCase();
|
||||
})
|
||||
.replace(ANY_COLOR_FUNCTION_PATTERN, function (match, colorFunction, colorDef) {
|
||||
var tokens = colorDef.split(',');
|
||||
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;
|
||||
}
|
||||
|
||||
if (tokens[1].indexOf('%') == -1) {
|
||||
tokens[1] += '%';
|
||||
}
|
||||
|
||||
if (tokens[2].indexOf('%') == -1) {
|
||||
tokens[2] += '%';
|
||||
}
|
||||
|
||||
return colorFunction + '(' + tokens.join(',') + ')';
|
||||
});
|
||||
|
||||
if (options.compatibility.colors.opacity && name.indexOf('background') == -1) {
|
||||
value = value.replace(TRANSPARENT_FUNCTION_PATTERN, function (match) {
|
||||
if (split(value, ',').pop().indexOf('gradient(') > -1) {
|
||||
return match;
|
||||
}
|
||||
|
||||
return 'transparent';
|
||||
});
|
||||
}
|
||||
|
||||
return shortenHex(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
19
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/degrees.js
generated
vendored
Normal file
19
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/degrees.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var ZERO_DEG_PATTERN = /\(0deg\)/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function degrees(_name, value, options) {
|
||||
if (!options.compatibility.properties.zeroUnits) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('0deg') == -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(ZERO_DEG_PATTERN, '(0)');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
43
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/fraction.js
generated
vendored
Normal file
43
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/fraction.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
var startsAsUrl = require('./starts-as-url');
|
||||
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var DOT_ZERO_PATTERN = /(^|\D)\.0+(\D|$)/g;
|
||||
var FRACTION_PATTERN = /\.([1-9]*)0+(\D|$)/g;
|
||||
var LEADING_ZERO_FRACTION_PATTERN = /(^|\D)0\.(\d)/g;
|
||||
var MINUS_ZERO_FRACTION_PATTERN = /([^\w\d\-]|^)\-0([^\.]|$)/g;
|
||||
var ZERO_PREFIXED_UNIT_PATTERN = /(^|\s)0+([1-9])/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function fraction(name, value, options) {
|
||||
if (!options.level[OptimizationLevel.One].replaceZeroUnits) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (startsAsUrl(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('0') == -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('-') > -1) {
|
||||
value = value
|
||||
.replace(MINUS_ZERO_FRACTION_PATTERN, '$10$2')
|
||||
.replace(MINUS_ZERO_FRACTION_PATTERN, '$10$2');
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(ZERO_PREFIXED_UNIT_PATTERN, '$1$2')
|
||||
.replace(DOT_ZERO_PATTERN, '$10$2')
|
||||
.replace(FRACTION_PATTERN, function (match, nonZeroPart, suffix) {
|
||||
return (nonZeroPart.length > 0 ? '.' : '') + nonZeroPart + suffix;
|
||||
})
|
||||
.replace(LEADING_ZERO_FRACTION_PATTERN, '$1.$2');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
22
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/precision.js
generated
vendored
Normal file
22
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/precision.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function precision(_name, value, options) {
|
||||
if (!options.precision.enabled || value.indexOf('.') === -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(options.precision.decimalPointMatcher, '$1$2$3')
|
||||
.replace(options.precision.zeroMatcher, function (match, integerPart, fractionPart, unit) {
|
||||
var multiplier = options.precision.units[unit].multiplier;
|
||||
var parsedInteger = parseInt(integerPart);
|
||||
var integer = isNaN(parsedInteger) ? 0 : parsedInteger;
|
||||
var fraction = parseFloat(fractionPart);
|
||||
|
||||
return Math.round((integer + fraction) * multiplier) / multiplier + unit;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
7
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/starts-as-url.js
generated
vendored
Normal file
7
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/starts-as-url.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
var URL_PREFIX_PATTERN = /^url\(/i;
|
||||
|
||||
function startsAsUrl(value) {
|
||||
return URL_PREFIX_PATTERN.test(value);
|
||||
}
|
||||
|
||||
module.exports = startsAsUrl;
|
25
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/text-quotes.js
generated
vendored
Normal file
25
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/text-quotes.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var LOCAL_PREFIX_PATTERN = /^local\(/i;
|
||||
var QUOTED_PATTERN = /^('.*'|".*")$/;
|
||||
var QUOTED_BUT_SAFE_PATTERN = /^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function textQuotes(_name, value, options) {
|
||||
if (!options.level[OptimizationLevel.One].removeQuotes) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!QUOTED_PATTERN.test(value) && !LOCAL_PREFIX_PATTERN.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return QUOTED_BUT_SAFE_PATTERN.test(value) ?
|
||||
value.substring(1, value.length - 1) :
|
||||
value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
31
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/time.js
generated
vendored
Normal file
31
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/time.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var TIME_VALUE = /^(\-?[\d\.]+)(m?s)$/;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function time(name, value, options) {
|
||||
if (!options.level[OptimizationLevel.One].replaceTimeUnits) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!TIME_VALUE.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(TIME_VALUE, function (match, val, unit) {
|
||||
var newValue;
|
||||
|
||||
if (unit == 'ms') {
|
||||
newValue = parseInt(val) / 1000 + 's';
|
||||
} else if (unit == 's') {
|
||||
newValue = parseFloat(val) * 1000 + 'ms';
|
||||
}
|
||||
|
||||
return newValue.length < match.length ? newValue : match;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
40
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js
generated
vendored
Normal file
40
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
var WHOLE_PIXEL_VALUE = /(?:^|\s|\()(-?\d+)px/;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function unit(_name, value, options) {
|
||||
if (!WHOLE_PIXEL_VALUE.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(WHOLE_PIXEL_VALUE, function (match, val) {
|
||||
var newValue;
|
||||
var intVal = parseInt(val);
|
||||
|
||||
if (intVal === 0) {
|
||||
return match;
|
||||
}
|
||||
|
||||
if (options.compatibility.properties.shorterLengthUnits && options.compatibility.units.pt && intVal * 3 % 4 === 0) {
|
||||
newValue = intVal * 3 / 4 + 'pt';
|
||||
}
|
||||
|
||||
if (options.compatibility.properties.shorterLengthUnits && options.compatibility.units.pc && intVal % 16 === 0) {
|
||||
newValue = intVal / 16 + 'pc';
|
||||
}
|
||||
|
||||
if (options.compatibility.properties.shorterLengthUnits && options.compatibility.units.in && intVal % 96 === 0) {
|
||||
newValue = intVal / 96 + 'in';
|
||||
}
|
||||
|
||||
if (newValue) {
|
||||
newValue = match.substring(0, match.indexOf(val)) + newValue;
|
||||
}
|
||||
|
||||
return newValue && newValue.length < match.length ? newValue : match;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
23
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-prefix.js
generated
vendored
Normal file
23
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-prefix.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
var startsAsUrl = require('./starts-as-url');
|
||||
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var URL_PREFIX_PATTERN = /^url\(/i;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function urlPrefix(_name, value, options) {
|
||||
if (!options.level[OptimizationLevel.One].normalizeUrls) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (!startsAsUrl(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(URL_PREFIX_PATTERN, 'url(');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
20
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-quotes.js
generated
vendored
Normal file
20
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-quotes.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var QUOTED_URL_PATTERN = /^url\(['"].+['"]\)$/;
|
||||
var QUOTED_URL_WITH_WHITESPACE_PATTERN = /^url\(['"].*[\*\s\(\)'"].*['"]\)$/;
|
||||
var QUOTES_PATTERN = /["']/g;
|
||||
var URL_DATA_PATTERN = /^url\(['"]data:[^;]+;charset/;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function urlQuotes(_name, value, options) {
|
||||
if (options.compatibility.properties.urlQuotes) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return QUOTED_URL_PATTERN.test(value) && !QUOTED_URL_WITH_WHITESPACE_PATTERN.test(value) && !URL_DATA_PATTERN.test(value) ?
|
||||
value.replace(QUOTES_PATTERN, '') :
|
||||
value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
17
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-whitespace.js
generated
vendored
Normal file
17
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/url-whitespace.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
var startsAsUrl = require('./starts-as-url');
|
||||
|
||||
var WHITESPACE_PATTERN = /\\?\n|\\?\r\n/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function urlWhitespace(_name, value) {
|
||||
if (!startsAsUrl(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.replace(WHITESPACE_PATTERN, '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
40
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/whitespace.js
generated
vendored
Normal file
40
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/whitespace.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
var OptimizationLevel = require('../../../options/optimization-level').OptimizationLevel;
|
||||
|
||||
var Marker = require('../../../tokenizer/marker');
|
||||
|
||||
var CALC_DIVISION_WHITESPACE_PATTERN = /\) ?\/ ?/g;
|
||||
var COMMA_AND_SPACE_PATTERN = /, /g;
|
||||
var MULTI_WHITESPACE_PATTERN = /\s+/g;
|
||||
var FUNCTION_CLOSING_BRACE_WHITESPACE_PATTERN = /\s+(;?\))/g;
|
||||
var FUNCTION_OPENING_BRACE_WHITESPACE_PATTERN = /(\(;?)\s+/g;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function whitespace(name, value, options) {
|
||||
if (!options.level[OptimizationLevel.One].removeWhitespace) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf(' ') == -1 || value.indexOf('expression') === 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf(Marker.SINGLE_QUOTE) > -1 || value.indexOf(Marker.DOUBLE_QUOTE) > -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value = value.replace(MULTI_WHITESPACE_PATTERN, ' ');
|
||||
|
||||
if (value.indexOf('calc') > -1) {
|
||||
value = value.replace(CALC_DIVISION_WHITESPACE_PATTERN, ')/ ');
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(FUNCTION_OPENING_BRACE_WHITESPACE_PATTERN, '$1')
|
||||
.replace(FUNCTION_CLOSING_BRACE_WHITESPACE_PATTERN, '$1')
|
||||
.replace(COMMA_AND_SPACE_PATTERN, ',');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
25
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/zero.js
generated
vendored
Normal file
25
node_modules/clean-css/lib/optimizer/level-1/value-optimizers/zero.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var FUNCTION_PATTERN = /^(?:\-moz\-calc|\-webkit\-calc|calc|rgb|hsl|rgba|hsla|min|max|clamp)\(/;
|
||||
|
||||
var plugin = {
|
||||
level1: {
|
||||
value: function zero(name, value, options) {
|
||||
if (!options.compatibility.properties.zeroUnits) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (FUNCTION_PATTERN.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height' || name == 'width' || name == 'max-width')) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value
|
||||
.replace(options.unitsRegexp, '$1' + '0' + '$2')
|
||||
.replace(options.unitsRegexp, '$1' + '0' + '$2');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = plugin;
|
Reference in New Issue
Block a user