mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
use minify
This commit is contained in:
16
node_modules/clean-css/lib/clean.js
generated
vendored
16
node_modules/clean-css/lib/clean.js
generated
vendored
@@ -46,6 +46,22 @@ var CleanCSS = module.exports = function CleanCSS(options) {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// for compatibility with optimize-css-assets-webpack-plugin
|
||||
CleanCSS.process = function (input, opts) {
|
||||
var cleanCss;
|
||||
var optsTo = opts.to;
|
||||
|
||||
delete opts.to;
|
||||
cleanCss = new CleanCSS(Object.assign({ returnPromise: true, rebaseTo: optsTo }, opts));
|
||||
|
||||
return cleanCss.minify(input)
|
||||
.then(function(output) {
|
||||
return { css: output.styles };
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
CleanCSS.prototype.minify = function (input, maybeSourceMap, maybeCallback) {
|
||||
var options = this.options;
|
||||
|
||||
|
19
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
19
node_modules/clean-css/lib/optimizer/level-1/optimize.js
generated
vendored
@@ -19,6 +19,8 @@ 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';
|
||||
@@ -334,7 +336,7 @@ function optimizeZeroUnits(name, value) {
|
||||
}
|
||||
|
||||
function removeQuotes(name, value) {
|
||||
if (name == 'content' || 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.indexOf('grid-') > -1) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -349,8 +351,9 @@ function removeUrlQuotes(value) {
|
||||
value;
|
||||
}
|
||||
|
||||
function transformValue(propertyName, propertyValue, transformCallback) {
|
||||
var transformedValue = transformCallback(propertyName, propertyValue);
|
||||
function transformValue(propertyName, propertyValue, rule, transformCallback) {
|
||||
var selector = serializeRules(rule);
|
||||
var transformedValue = transformCallback(propertyName, propertyValue, selector);
|
||||
|
||||
if (transformedValue === undefined) {
|
||||
return propertyValue;
|
||||
@@ -363,7 +366,7 @@ function transformValue(propertyName, propertyValue, transformCallback) {
|
||||
|
||||
//
|
||||
|
||||
function optimizeBody(properties, context) {
|
||||
function optimizeBody(rule, properties, context) {
|
||||
var options = context.options;
|
||||
var levelOptions = options.level[OptimizationLevel.One];
|
||||
var property, name, type, value;
|
||||
@@ -408,7 +411,7 @@ function optimizeBody(properties, context) {
|
||||
}
|
||||
|
||||
if (property.block) {
|
||||
optimizeBody(property.value[0][1], context);
|
||||
optimizeBody(rule, property.value[0][1], context);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -467,7 +470,7 @@ function optimizeBody(properties, context) {
|
||||
}
|
||||
}
|
||||
|
||||
value = transformValue(name, value, levelOptions.transform);
|
||||
value = transformValue(name, value, rule, levelOptions.transform);
|
||||
|
||||
if (value === IgnoreProperty) {
|
||||
property.unused = true;
|
||||
@@ -637,7 +640,7 @@ function level1Optimize(tokens, context) {
|
||||
mayHaveCharset = true;
|
||||
break;
|
||||
case Token.AT_RULE_BLOCK:
|
||||
optimizeBody(token[2], context);
|
||||
optimizeBody(token[1], token[2], context);
|
||||
afterRules = true;
|
||||
break;
|
||||
case Token.NESTED_BLOCK:
|
||||
@@ -651,7 +654,7 @@ function level1Optimize(tokens, context) {
|
||||
case Token.RULE:
|
||||
token[1] = levelOptions.tidySelectors ? tidyRules(token[1], !ie7Hack, adjacentSpace, format, context.warnings) : token[1];
|
||||
token[1] = token[1].length > 1 ? sortSelectors(token[1], levelOptions.selectorsSortingMethod) : token[1];
|
||||
optimizeBody(token[2], context);
|
||||
optimizeBody(token[1], token[2], context);
|
||||
afterRules = true;
|
||||
break;
|
||||
}
|
||||
|
2
node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js
generated
vendored
2
node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js
generated
vendored
@@ -68,7 +68,7 @@ function removeWhitespace(value, format) {
|
||||
character = value[i];
|
||||
|
||||
isNewLineNix = character == Marker.NEW_LINE_NIX;
|
||||
isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.NEW_LINE_WIN;
|
||||
isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.CARRIAGE_RETURN;
|
||||
isQuoted = isSingleQuoted || isDoubleQuoted;
|
||||
isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character);
|
||||
isWhitespace = WHITESPACE_PATTERN.test(character);
|
||||
|
52
node_modules/clean-css/lib/optimizer/level-2/break-up.js
generated
vendored
52
node_modules/clean-css/lib/optimizer/level-2/break-up.js
generated
vendored
@@ -105,7 +105,7 @@ function animation(property, compactable, validator) {
|
||||
} else if (validator.isTime(value[1]) && !delaySet) {
|
||||
delay.value = [value];
|
||||
delaySet = true;
|
||||
} else if ((validator.isGlobal(value[1]) || validator.isAnimationTimingFunction(value[1])) && !timingSet) {
|
||||
} else if ((validator.isGlobal(value[1]) || validator.isTimingFunction(value[1])) && !timingSet) {
|
||||
timing.value = [value];
|
||||
timingSet = true;
|
||||
} else if ((validator.isAnimationIterationCountKeyword(value[1]) || validator.isPositiveNumber(value[1])) && !iterationSet) {
|
||||
@@ -523,6 +523,53 @@ function listStyle(property, compactable, validator) {
|
||||
return components;
|
||||
}
|
||||
|
||||
function transition(property, compactable, validator) {
|
||||
var prop = _wrapDefault(property.name + '-property', property, compactable);
|
||||
var duration = _wrapDefault(property.name + '-duration', property, compactable);
|
||||
var timing = _wrapDefault(property.name + '-timing-function', property, compactable);
|
||||
var delay = _wrapDefault(property.name + '-delay', property, compactable);
|
||||
var components = [prop, duration, timing, delay];
|
||||
var values = property.value;
|
||||
var value;
|
||||
var durationSet = false;
|
||||
var delaySet = false;
|
||||
var propSet = false;
|
||||
var timingSet = false;
|
||||
var i;
|
||||
var l;
|
||||
|
||||
if (property.value.length == 1 && property.value[0][1] == 'inherit') {
|
||||
prop.value = duration.value = timing.value = delay.value = property.value;
|
||||
return components;
|
||||
}
|
||||
|
||||
if (values.length > 1 && _anyIsInherit(values)) {
|
||||
throw new InvalidPropertyError('Invalid animation values at ' + formatPosition(values[0][2][0]) + '. Ignoring.');
|
||||
}
|
||||
|
||||
for (i = 0, l = values.length; i < l; i++) {
|
||||
value = values[i];
|
||||
|
||||
if (validator.isTime(value[1]) && !durationSet) {
|
||||
duration.value = [value];
|
||||
durationSet = true;
|
||||
} else if (validator.isTime(value[1]) && !delaySet) {
|
||||
delay.value = [value];
|
||||
delaySet = true;
|
||||
} else if ((validator.isGlobal(value[1]) || validator.isTimingFunction(value[1])) && !timingSet) {
|
||||
timing.value = [value];
|
||||
timingSet = true;
|
||||
} else if (validator.isIdentifier(value[1]) && !propSet) {
|
||||
prop.value = [value];
|
||||
propSet = true;
|
||||
} else {
|
||||
throw new InvalidPropertyError('Invalid animation value at ' + formatPosition(value[2][0]) + '. Ignoring.');
|
||||
}
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
function widthStyleColor(property, compactable, validator) {
|
||||
var descriptor = compactable[property.name];
|
||||
var components = [
|
||||
@@ -592,5 +639,6 @@ module.exports = {
|
||||
fourValues: fourValues,
|
||||
listStyle: listStyle,
|
||||
multiplex: multiplex,
|
||||
outline: widthStyleColor
|
||||
outline: widthStyleColor,
|
||||
transition: transition
|
||||
};
|
||||
|
35
node_modules/clean-css/lib/optimizer/level-2/can-override.js
generated
vendored
35
node_modules/clean-css/lib/optimizer/level-2/can-override.js
generated
vendored
@@ -20,16 +20,6 @@ function animationName(validator, value1, value2) {
|
||||
return validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2);
|
||||
}
|
||||
|
||||
function animationTimingFunction(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2);
|
||||
}
|
||||
|
||||
function areSameFunction(validator, value1, value2) {
|
||||
if (!validator.isFunction(value1) || !validator.isFunction(value2)) {
|
||||
return false;
|
||||
@@ -129,14 +119,22 @@ function keywordWithGlobal(propertyName) {
|
||||
};
|
||||
}
|
||||
|
||||
function propertyName(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isIdentifier(value2)) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isIdentifier(value2);
|
||||
}
|
||||
|
||||
function sameFunctionOrValue(validator, value1, value2) {
|
||||
return areSameFunction(validator, value1, value2) ?
|
||||
true :
|
||||
value1 === value2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function textShadow(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
@@ -165,6 +163,16 @@ function time(validator, value1, value2) {
|
||||
return sameFunctionOrValue(validator, value1, value2);
|
||||
}
|
||||
|
||||
function timingFunction(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !(validator.isTimingFunction(value2) || validator.isGlobal(value2))) {
|
||||
return false;
|
||||
} else if (validator.isVariable(value1) && validator.isVariable(value2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return validator.isTimingFunction(value2) || validator.isGlobal(value2);
|
||||
}
|
||||
|
||||
function unit(validator, value1, value2) {
|
||||
if (!understandable(validator, value1, value2, 0, true) && !validator.isUnit(value2)) {
|
||||
return false;
|
||||
@@ -224,7 +232,9 @@ module.exports = {
|
||||
color: color,
|
||||
components: components,
|
||||
image: image,
|
||||
propertyName: propertyName,
|
||||
time: time,
|
||||
timingFunction: timingFunction,
|
||||
unit: unit,
|
||||
unitOrNumber: unitOrNumber
|
||||
},
|
||||
@@ -234,7 +244,6 @@ module.exports = {
|
||||
animationIterationCount: animationIterationCount,
|
||||
animationName: animationName,
|
||||
animationPlayState: keywordWithGlobal('animation-play-state'),
|
||||
animationTimingFunction: animationTimingFunction,
|
||||
backgroundAttachment: keyword('background-attachment'),
|
||||
backgroundClip: keywordWithGlobal('background-clip'),
|
||||
backgroundOrigin: keyword('background-origin'),
|
||||
|
80
node_modules/clean-css/lib/optimizer/level-2/compactable.js
generated
vendored
80
node_modules/clean-css/lib/optimizer/level-2/compactable.js
generated
vendored
@@ -38,7 +38,7 @@ var compactable = {
|
||||
'animation': {
|
||||
canOverride: canOverride.generic.components([
|
||||
canOverride.generic.time,
|
||||
canOverride.property.animationTimingFunction,
|
||||
canOverride.generic.timingFunction,
|
||||
canOverride.generic.time,
|
||||
canOverride.property.animationIterationCount,
|
||||
canOverride.property.animationDirection,
|
||||
@@ -159,7 +159,7 @@ var compactable = {
|
||||
]
|
||||
},
|
||||
'animation-timing-function': {
|
||||
canOverride: canOverride.property.animationTimingFunction,
|
||||
canOverride: canOverride.generic.timingFunction,
|
||||
componentOf: [
|
||||
'animation'
|
||||
],
|
||||
@@ -918,6 +918,82 @@ var compactable = {
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'transition': {
|
||||
breakUp: breakUp.multiplex(breakUp.transition),
|
||||
canOverride: canOverride.generic.components([
|
||||
canOverride.property.transitionProperty,
|
||||
canOverride.generic.time,
|
||||
canOverride.generic.timingFunction,
|
||||
canOverride.generic.time
|
||||
]),
|
||||
components: [
|
||||
'transition-property',
|
||||
'transition-duration',
|
||||
'transition-timing-function',
|
||||
'transition-delay'
|
||||
],
|
||||
defaultValue: 'none',
|
||||
restore: restore.multiplex(restore.withoutDefaults),
|
||||
shorthand: true,
|
||||
vendorPrefixes: [
|
||||
'-moz-',
|
||||
'-o-',
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'transition-delay': {
|
||||
canOverride: canOverride.generic.time,
|
||||
componentOf: [
|
||||
'transition'
|
||||
],
|
||||
defaultValue: '0s',
|
||||
intoMultiplexMode: 'real',
|
||||
vendorPrefixes: [
|
||||
'-moz-',
|
||||
'-o-',
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'transition-duration': {
|
||||
canOverride: canOverride.generic.time,
|
||||
componentOf: [
|
||||
'transition'
|
||||
],
|
||||
defaultValue: '0s',
|
||||
intoMultiplexMode: 'real',
|
||||
vendorPrefixes: [
|
||||
'-moz-',
|
||||
'-o-',
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'transition-property': {
|
||||
canOverride: canOverride.generic.propertyName,
|
||||
componentOf: [
|
||||
'transition'
|
||||
],
|
||||
defaultValue: 'all',
|
||||
intoMultiplexMode: 'placeholder',
|
||||
placeholderValue: '_', // it's a short value that won't match any property and still be a valid `transition-property`
|
||||
vendorPrefixes: [
|
||||
'-moz-',
|
||||
'-o-',
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'transition-timing-function': {
|
||||
canOverride: canOverride.generic.timingFunction,
|
||||
componentOf: [
|
||||
'transition'
|
||||
],
|
||||
defaultValue: 'ease',
|
||||
intoMultiplexMode: 'real',
|
||||
vendorPrefixes: [
|
||||
'-moz-',
|
||||
'-o-',
|
||||
'-webkit-'
|
||||
]
|
||||
},
|
||||
'vertical-align': {
|
||||
canOverride: canOverride.property.verticalAlign,
|
||||
defaultValue: 'baseline'
|
||||
|
8
node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js
generated
vendored
8
node_modules/clean-css/lib/optimizer/level-2/properties/override-properties.js
generated
vendored
@@ -8,7 +8,6 @@ var sameVendorPrefixesIn = require('./vendor-prefixes').same;
|
||||
|
||||
var compactable = require('../compactable');
|
||||
var deepClone = require('../clone').deep;
|
||||
var deepClone = require('../clone').deep;
|
||||
var restoreWithComponents = require('../restore-with-components');
|
||||
var shallowClone = require('../clone').shallow;
|
||||
|
||||
@@ -95,10 +94,11 @@ function turnShorthandValueIntoMultiplex(property, size) {
|
||||
}
|
||||
|
||||
function turnLonghandValueIntoMultiplex(property, size) {
|
||||
var withRealValue = compactable[property.name].intoMultiplexMode == 'real';
|
||||
var withValue = withRealValue ?
|
||||
var descriptor = compactable[property.name];
|
||||
var withRealValue = descriptor.intoMultiplexMode == 'real';
|
||||
var withValue = descriptor.intoMultiplexMode == 'real' ?
|
||||
property.value.slice(0) :
|
||||
compactable[property.name].defaultValue;
|
||||
(descriptor.intoMultiplexMode == 'placeholder' ? descriptor.placeholderValue : descriptor.defaultValue);
|
||||
var i = multiplexSize(property);
|
||||
var j;
|
||||
var m = withValue.length;
|
||||
|
47
node_modules/clean-css/lib/optimizer/validator.js
generated
vendored
47
node_modules/clean-css/lib/optimizer/validator.js
generated
vendored
@@ -3,21 +3,24 @@ var functionVendorRegexStr = '\\-(\\-|[A-Z]|[0-9])+\\(.*?\\)';
|
||||
var variableRegexStr = 'var\\(\\-\\-[^\\)]+\\)';
|
||||
var functionAnyRegexStr = '(' + variableRegexStr + '|' + functionNoVendorRegexStr + '|' + functionVendorRegexStr + ')';
|
||||
|
||||
var animationTimingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/;
|
||||
var calcRegex = new RegExp('^(\\-moz\\-|\\-webkit\\-)?calc\\([^\\)]+\\)$', 'i');
|
||||
var decimalRegex = /[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 identifierRegex = /^(\-[a-z0-9_][a-z0-9\-_]*|[a-z][a-z0-9\-_]*)$/i;
|
||||
var longHexColorRegex = /^#[0-9a-f]{6}$/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 shortHexColorRegex = /^#[0-9a-f]{3}$/i;
|
||||
var timingFunctionRegex = /^(cubic\-bezier|steps)\([^\)]+\)$/;
|
||||
var validTimeUnits = ['ms', 's'];
|
||||
var urlRegex = /^url\([\s\S]+\)$/i;
|
||||
var variableRegex = new RegExp('^' + variableRegexStr + '$', 'i');
|
||||
|
||||
var eightValueColorRegex = /^#[0-9a-f]{8}$/i;
|
||||
var fourValueColorRegex = /^#[0-9a-f]{4}$/i;
|
||||
var sixValueColorRegex = /^#[0-9a-f]{6}$/i;
|
||||
var threeValueColorRegex = /^#[0-9a-f]{3}$/i;
|
||||
|
||||
var DECIMAL_DOT = '.';
|
||||
var MINUS_SIGN = '-';
|
||||
var PLUS_SIGN = '+';
|
||||
@@ -41,6 +44,15 @@ var Keywords = {
|
||||
'ridge',
|
||||
'solid'
|
||||
],
|
||||
'*-timing-function': [
|
||||
'ease',
|
||||
'ease-in',
|
||||
'ease-in-out',
|
||||
'ease-out',
|
||||
'linear',
|
||||
'step-end',
|
||||
'step-start'
|
||||
],
|
||||
'animation-direction': [
|
||||
'alternate',
|
||||
'alternate-reverse',
|
||||
@@ -63,15 +75,6 @@ var Keywords = {
|
||||
'paused',
|
||||
'running'
|
||||
],
|
||||
'animation-timing-function': [
|
||||
'ease',
|
||||
'ease-in',
|
||||
'ease-in-out',
|
||||
'ease-out',
|
||||
'linear',
|
||||
'step-end',
|
||||
'step-start'
|
||||
],
|
||||
'background-attachment': [
|
||||
'fixed',
|
||||
'inherit',
|
||||
@@ -342,14 +345,6 @@ var Units = [
|
||||
'vw'
|
||||
];
|
||||
|
||||
function isAnimationTimingFunction() {
|
||||
var isTimingFunctionKeyword = isKeyword('animation-timing-function');
|
||||
|
||||
return function (value) {
|
||||
return isTimingFunctionKeyword(value) || animationTimingFunctionRegex.test(value);
|
||||
};
|
||||
}
|
||||
|
||||
function isColor(value) {
|
||||
return value != 'auto' &&
|
||||
(
|
||||
@@ -373,7 +368,7 @@ function isFunction(value) {
|
||||
}
|
||||
|
||||
function isHexColor(value) {
|
||||
return shortHexColorRegex.test(value) || longHexColorRegex.test(value);
|
||||
return threeValueColorRegex.test(value) || fourValueColorRegex.test(value) || sixValueColorRegex.test(value) || eightValueColorRegex.test(value);
|
||||
}
|
||||
|
||||
function isHslColor(value) {
|
||||
@@ -426,6 +421,14 @@ function isTime(value) {
|
||||
numberUpTo > -1 && validTimeUnits.indexOf(value.slice(numberUpTo + 1)) > -1;
|
||||
}
|
||||
|
||||
function isTimingFunction() {
|
||||
var isTimingFunctionKeyword = isKeyword('*-timing-function');
|
||||
|
||||
return function (value) {
|
||||
return isTimingFunctionKeyword(value) || timingFunctionRegex.test(value);
|
||||
};
|
||||
}
|
||||
|
||||
function isUnit(validUnits, value) {
|
||||
var numberUpTo = scanForNumber(value);
|
||||
|
||||
@@ -484,7 +487,7 @@ function validator(compatibility) {
|
||||
isAnimationIterationCountKeyword: isKeyword('animation-iteration-count'),
|
||||
isAnimationNameKeyword: isKeyword('animation-name'),
|
||||
isAnimationPlayStateKeyword: isKeyword('animation-play-state'),
|
||||
isAnimationTimingFunction: isAnimationTimingFunction(),
|
||||
isTimingFunction: isTimingFunction(),
|
||||
isBackgroundAttachmentKeyword: isKeyword('background-attachment'),
|
||||
isBackgroundClipKeyword: isKeyword('background-clip'),
|
||||
isBackgroundOriginKeyword: isKeyword('background-origin'),
|
||||
|
33
node_modules/clean-css/lib/options/format.js
generated
vendored
33
node_modules/clean-css/lib/options/format.js
generated
vendored
@@ -1,3 +1,5 @@
|
||||
var systemLineBreak = require('os').EOL;
|
||||
|
||||
var override = require('../utils/override');
|
||||
|
||||
var Breaks = {
|
||||
@@ -12,6 +14,12 @@ var Breaks = {
|
||||
BetweenSelectors: 'betweenSelectors'
|
||||
};
|
||||
|
||||
var BreakWith = {
|
||||
CarriageReturnLineFeed: '\r\n',
|
||||
LineFeed: '\n',
|
||||
System: systemLineBreak
|
||||
};
|
||||
|
||||
var IndentWith = {
|
||||
Space: ' ',
|
||||
Tab: '\t'
|
||||
@@ -25,10 +33,12 @@ var Spaces = {
|
||||
|
||||
var DEFAULTS = {
|
||||
breaks: breaks(false),
|
||||
breakWith: BreakWith.System,
|
||||
indentBy: 0,
|
||||
indentWith: IndentWith.Space,
|
||||
spaces: spaces(false),
|
||||
wrapAt: false
|
||||
wrapAt: false,
|
||||
semicolonAfterLastProperty: false
|
||||
};
|
||||
|
||||
var BEAUTIFY_ALIAS = 'beautify';
|
||||
@@ -75,6 +85,10 @@ function formatFrom(source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof source == 'object' && 'breakWith' in source) {
|
||||
source = override(source, { breakWith: mapBreakWith(source.breakWith) });
|
||||
}
|
||||
|
||||
if (typeof source == 'object' && 'indentBy' in source) {
|
||||
source = override(source, { indentBy: parseInt(source.indentBy) });
|
||||
}
|
||||
@@ -133,6 +147,8 @@ function toHash(string) {
|
||||
accumulator[name] = parseInt(value);
|
||||
} else if (name == 'indentWith') {
|
||||
accumulator[name] = mapIndentWith(value);
|
||||
} else if (name == 'breakWith') {
|
||||
accumulator[name] = mapBreakWith(value);
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
@@ -167,6 +183,21 @@ function normalizeValue(value) {
|
||||
}
|
||||
}
|
||||
|
||||
function mapBreakWith(value) {
|
||||
switch (value) {
|
||||
case 'windows':
|
||||
case 'crlf':
|
||||
case BreakWith.CarriageReturnLineFeed:
|
||||
return BreakWith.CarriageReturnLineFeed;
|
||||
case 'unix':
|
||||
case 'lf':
|
||||
case BreakWith.LineFeed:
|
||||
return BreakWith.LineFeed;
|
||||
default:
|
||||
return systemLineBreak;
|
||||
}
|
||||
}
|
||||
|
||||
function mapIndentWith(value) {
|
||||
switch (value) {
|
||||
case 'space':
|
||||
|
2
node_modules/clean-css/lib/tokenizer/marker.js
generated
vendored
2
node_modules/clean-css/lib/tokenizer/marker.js
generated
vendored
@@ -2,6 +2,7 @@ var Marker = {
|
||||
ASTERISK: '*',
|
||||
AT: '@',
|
||||
BACK_SLASH: '\\',
|
||||
CARRIAGE_RETURN: '\r',
|
||||
CLOSE_CURLY_BRACKET: '}',
|
||||
CLOSE_ROUND_BRACKET: ')',
|
||||
CLOSE_SQUARE_BRACKET: ']',
|
||||
@@ -12,7 +13,6 @@ var Marker = {
|
||||
FORWARD_SLASH: '/',
|
||||
INTERNAL: '-clean-css-',
|
||||
NEW_LINE_NIX: '\n',
|
||||
NEW_LINE_WIN: '\r',
|
||||
OPEN_CURLY_BRACKET: '{',
|
||||
OPEN_ROUND_BRACKET: '(',
|
||||
OPEN_SQUARE_BRACKET: '[',
|
||||
|
1
node_modules/clean-css/lib/tokenizer/token.js
generated
vendored
1
node_modules/clean-css/lib/tokenizer/token.js
generated
vendored
@@ -9,6 +9,7 @@ var Token = {
|
||||
PROPERTY_BLOCK: 'property-block', // e.g. `--var:{color:red}`
|
||||
PROPERTY_NAME: 'property-name', // e.g. `color`
|
||||
PROPERTY_VALUE: 'property-value', // e.g. `red`
|
||||
RAW: 'raw', // e.g. anything between /* clean-css ignore:start */ and /* clean-css ignore:end */ comments
|
||||
RULE: 'rule', // e.g `div > a{...}`
|
||||
RULE_SCOPE: 'rule-scope' // e.g `div > a`
|
||||
};
|
||||
|
53
node_modules/clean-css/lib/tokenizer/tokenize.js
generated
vendored
53
node_modules/clean-css/lib/tokenizer/tokenize.js
generated
vendored
@@ -28,6 +28,9 @@ var BLOCK_RULES = [
|
||||
'@supports'
|
||||
];
|
||||
|
||||
var IGNORE_END_COMMENT_PATTERN = /\/\* clean\-css ignore:end \*\/$/;
|
||||
var IGNORE_START_COMMENT_PATTERN = /^\/\* clean\-css ignore:start \*\//;
|
||||
|
||||
var PAGE_MARGIN_BOXES = [
|
||||
'@bottom-center',
|
||||
'@bottom-left',
|
||||
@@ -88,11 +91,13 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
var buffer = [];
|
||||
var buffers = [];
|
||||
var serializedBuffer;
|
||||
var serializedBufferPart;
|
||||
var roundBracketLevel = 0;
|
||||
var isQuoted;
|
||||
var isSpace;
|
||||
var isNewLineNix;
|
||||
var isNewLineWin;
|
||||
var isCarriageReturn;
|
||||
var isCommentStart;
|
||||
var wasCommentStart = false;
|
||||
var isCommentEnd;
|
||||
@@ -100,9 +105,11 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
var isCommentEndMarker;
|
||||
var isEscaped;
|
||||
var wasEscaped = false;
|
||||
var isRaw = false;
|
||||
var seekingValue = false;
|
||||
var seekingPropertyBlockClosing = false;
|
||||
var position = internalContext.position;
|
||||
var lastCommentStartAt;
|
||||
|
||||
for (; position.index < source.length; position.index++) {
|
||||
var character = source[position.index];
|
||||
@@ -110,7 +117,8 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
isQuoted = level == Level.SINGLE_QUOTE || level == Level.DOUBLE_QUOTE;
|
||||
isSpace = character == Marker.SPACE || character == Marker.TAB;
|
||||
isNewLineNix = character == Marker.NEW_LINE_NIX;
|
||||
isNewLineWin = character == Marker.NEW_LINE_NIX && source[position.index - 1] == Marker.NEW_LINE_WIN;
|
||||
isNewLineWin = character == Marker.NEW_LINE_NIX && source[position.index - 1] == Marker.CARRIAGE_RETURN;
|
||||
isCarriageReturn = character == Marker.CARRIAGE_RETURN && source[position.index + 1] && source[position.index + 1] != Marker.NEW_LINE_NIX;
|
||||
isCommentStart = !wasCommentEnd && level != Level.COMMENT && !isQuoted && character == Marker.ASTERISK && source[position.index - 1] == Marker.FORWARD_SLASH;
|
||||
isCommentEndMarker = !wasCommentStart && !isQuoted && character == Marker.FORWARD_SLASH && source[position.index - 1] == Marker.ASTERISK;
|
||||
isCommentEnd = level == Level.COMMENT && isCommentEndMarker;
|
||||
@@ -125,6 +133,8 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
buffer.push(character);
|
||||
} else if (!isCommentEnd && level == Level.COMMENT) {
|
||||
buffer.push(character);
|
||||
} else if (!isCommentStart && !isCommentEnd && isRaw) {
|
||||
buffer.push(character);
|
||||
} else if (isCommentStart && (level == Level.BLOCK || level == Level.RULE) && buffer.length > 1) {
|
||||
// comment start within block preceded by some content, e.g. div/*<--
|
||||
metadatas.push(metadata);
|
||||
@@ -141,6 +151,33 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
levels.push(level);
|
||||
level = Level.COMMENT;
|
||||
buffer.push(character);
|
||||
} else if (isCommentEnd && isIgnoreStartComment(buffer)) {
|
||||
// ignore:start comment end, e.g. /* clean-css ignore:start */<--
|
||||
serializedBuffer = buffer.join('').trim() + character;
|
||||
lastToken = [Token.COMMENT, serializedBuffer, [originalMetadata(metadata, serializedBuffer, externalContext)]];
|
||||
newTokens.push(lastToken);
|
||||
|
||||
isRaw = true;
|
||||
metadata = metadatas.pop() || null;
|
||||
buffer = buffers.pop() || [];
|
||||
} else if (isCommentEnd && isIgnoreEndComment(buffer)) {
|
||||
// ignore:start comment end, e.g. /* clean-css ignore:end */<--
|
||||
serializedBuffer = buffer.join('') + character;
|
||||
lastCommentStartAt = serializedBuffer.lastIndexOf(Marker.FORWARD_SLASH + Marker.ASTERISK);
|
||||
|
||||
serializedBufferPart = serializedBuffer.substring(0, lastCommentStartAt);
|
||||
lastToken = [Token.RAW, serializedBufferPart, [originalMetadata(metadata, serializedBufferPart, externalContext)]];
|
||||
newTokens.push(lastToken);
|
||||
|
||||
serializedBufferPart = serializedBuffer.substring(lastCommentStartAt);
|
||||
metadata = [position.line, position.column - serializedBufferPart.length + 1, position.source];
|
||||
lastToken = [Token.COMMENT, serializedBufferPart, [originalMetadata(metadata, serializedBufferPart, externalContext)]];
|
||||
newTokens.push(lastToken);
|
||||
|
||||
isRaw = false;
|
||||
level = levels.pop();
|
||||
metadata = metadatas.pop() || null;
|
||||
buffer = buffers.pop() || [];
|
||||
} else if (isCommentEnd) {
|
||||
// comment end, e.g. /* comment */<--
|
||||
serializedBuffer = buffer.join('').trim() + character;
|
||||
@@ -448,7 +485,7 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
} else if (buffer.length == 1 && isNewLineWin) {
|
||||
// ignore windows newline which is composed of two characters
|
||||
buffer.pop();
|
||||
} else if (buffer.length > 0 || !isSpace && !isNewLineNix && !isNewLineWin) {
|
||||
} else if (buffer.length > 0 || !isSpace && !isNewLineNix && !isNewLineWin && !isCarriageReturn) {
|
||||
// any character
|
||||
buffer.push(character);
|
||||
}
|
||||
@@ -458,8 +495,8 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
wasCommentStart = isCommentStart;
|
||||
wasCommentEnd = isCommentEnd;
|
||||
|
||||
position.line = (isNewLineWin || isNewLineNix) ? position.line + 1 : position.line;
|
||||
position.column = (isNewLineWin || isNewLineNix) ? 0 : position.column + 1;
|
||||
position.line = (isNewLineWin || isNewLineNix || isCarriageReturn) ? position.line + 1 : position.line;
|
||||
position.column = (isNewLineWin || isNewLineNix || isCarriageReturn) ? 0 : position.column + 1;
|
||||
}
|
||||
|
||||
if (seekingValue) {
|
||||
@@ -480,6 +517,14 @@ function intoTokens(source, externalContext, internalContext, isNested) {
|
||||
return allTokens;
|
||||
}
|
||||
|
||||
function isIgnoreStartComment(buffer) {
|
||||
return IGNORE_START_COMMENT_PATTERN.test(buffer.join('') + Marker.FORWARD_SLASH);
|
||||
}
|
||||
|
||||
function isIgnoreEndComment(buffer) {
|
||||
return IGNORE_END_COMMENT_PATTERN.test(buffer.join('') + Marker.FORWARD_SLASH);
|
||||
}
|
||||
|
||||
function originalMetadata(metadata, value, externalContext, selectorFallbacks) {
|
||||
var source = metadata[2];
|
||||
|
||||
|
34
node_modules/clean-css/lib/writer/helpers.js
generated
vendored
34
node_modules/clean-css/lib/writer/helpers.js
generated
vendored
@@ -1,4 +1,3 @@
|
||||
var lineBreak = require('os').EOL;
|
||||
var emptyCharacter = '';
|
||||
|
||||
var Breaks = require('../options/format').Breaks;
|
||||
@@ -79,7 +78,20 @@ function property(context, tokens, position, lastPropertyAt) {
|
||||
var store = context.store;
|
||||
var token = tokens[position];
|
||||
var isPropertyBlock = token[2][0] == Token.PROPERTY_BLOCK;
|
||||
var needsSemicolon = position < lastPropertyAt || isPropertyBlock;
|
||||
|
||||
var needsSemicolon;
|
||||
if ( context.format ) {
|
||||
if ( context.format.semicolonAfterLastProperty || isPropertyBlock ) {
|
||||
needsSemicolon = true;
|
||||
} else if ( position < lastPropertyAt ) {
|
||||
needsSemicolon = true;
|
||||
} else {
|
||||
needsSemicolon = false;
|
||||
}
|
||||
} else {
|
||||
needsSemicolon = position < lastPropertyAt || isPropertyBlock;
|
||||
}
|
||||
|
||||
var isLast = position === lastPropertyAt;
|
||||
|
||||
switch (token[0]) {
|
||||
@@ -101,6 +113,9 @@ function property(context, tokens, position, lastPropertyAt) {
|
||||
store(context, colon(context));
|
||||
value(context, token);
|
||||
store(context, needsSemicolon ? semicolon(context, Breaks.AfterProperty, isLast) : emptyCharacter);
|
||||
break;
|
||||
case Token.RAW:
|
||||
store(context, token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +152,7 @@ function openBrace(context, where, needsPrefixSpace) {
|
||||
context.indentWith = context.format.indentWith.repeat(context.indentBy);
|
||||
return (needsPrefixSpace && allowsSpace(context, Spaces.BeforeBlockBegins) ? Marker.SPACE : emptyCharacter) +
|
||||
Marker.OPEN_CURLY_BRACKET +
|
||||
(allowsBreak(context, where) ? lineBreak : emptyCharacter) +
|
||||
(allowsBreak(context, where) ? context.format.breakWith : emptyCharacter) +
|
||||
context.indentWith;
|
||||
} else {
|
||||
return Marker.OPEN_CURLY_BRACKET;
|
||||
@@ -148,10 +163,10 @@ function closeBrace(context, where, beforeBlockEnd, isLast) {
|
||||
if (context.format) {
|
||||
context.indentBy -= context.format.indentBy;
|
||||
context.indentWith = context.format.indentWith.repeat(context.indentBy);
|
||||
return (allowsBreak(context, Breaks.AfterProperty) || beforeBlockEnd && allowsBreak(context, Breaks.BeforeBlockEnds) ? lineBreak : emptyCharacter) +
|
||||
return (allowsBreak(context, Breaks.AfterProperty) || beforeBlockEnd && allowsBreak(context, Breaks.BeforeBlockEnds) ? context.format.breakWith : emptyCharacter) +
|
||||
context.indentWith +
|
||||
Marker.CLOSE_CURLY_BRACKET +
|
||||
(isLast ? emptyCharacter : (allowsBreak(context, where) ? lineBreak : emptyCharacter) + context.indentWith);
|
||||
(isLast ? emptyCharacter : (allowsBreak(context, where) ? context.format.breakWith : emptyCharacter) + context.indentWith);
|
||||
} else {
|
||||
return Marker.CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
@@ -165,13 +180,13 @@ function colon(context) {
|
||||
|
||||
function semicolon(context, where, isLast) {
|
||||
return context.format ?
|
||||
Marker.SEMICOLON + (isLast || !allowsBreak(context, where) ? emptyCharacter : lineBreak + context.indentWith) :
|
||||
Marker.SEMICOLON + (isLast || !allowsBreak(context, where) ? emptyCharacter : context.format.breakWith + context.indentWith) :
|
||||
Marker.SEMICOLON;
|
||||
}
|
||||
|
||||
function comma(context) {
|
||||
return context.format ?
|
||||
Marker.COMMA + (allowsBreak(context, Breaks.BetweenSelectors) ? lineBreak : emptyCharacter) + context.indentWith :
|
||||
Marker.COMMA + (allowsBreak(context, Breaks.BetweenSelectors) ? context.format.breakWith : emptyCharacter) + context.indentWith :
|
||||
Marker.COMMA;
|
||||
}
|
||||
|
||||
@@ -204,7 +219,10 @@ function all(context, tokens) {
|
||||
break;
|
||||
case Token.COMMENT:
|
||||
store(context, token);
|
||||
store(context, allowsBreak(context, Breaks.AfterComment) ? lineBreak : emptyCharacter);
|
||||
store(context, allowsBreak(context, Breaks.AfterComment) ? context.format.breakWith : emptyCharacter);
|
||||
break;
|
||||
case Token.RAW:
|
||||
store(context, token);
|
||||
break;
|
||||
case Token.RULE:
|
||||
rules(context, token[1]);
|
||||
|
6
node_modules/clean-css/lib/writer/simple.js
generated
vendored
6
node_modules/clean-css/lib/writer/simple.js
generated
vendored
@@ -1,7 +1,5 @@
|
||||
var all = require('./helpers').all;
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
function store(serializeContext, token) {
|
||||
var value = typeof token == 'string' ?
|
||||
token :
|
||||
@@ -15,8 +13,8 @@ function store(serializeContext, token) {
|
||||
|
||||
function wrap(serializeContext, value) {
|
||||
if (serializeContext.column + value.length > serializeContext.format.wrapAt) {
|
||||
track(serializeContext, lineBreak);
|
||||
serializeContext.output.push(lineBreak);
|
||||
track(serializeContext, serializeContext.format.breakWith);
|
||||
serializeContext.output.push(serializeContext.format.breakWith);
|
||||
}
|
||||
}
|
||||
|
||||
|
5
node_modules/clean-css/lib/writer/source-maps.js
generated
vendored
5
node_modules/clean-css/lib/writer/source-maps.js
generated
vendored
@@ -1,7 +1,6 @@
|
||||
var SourceMapGenerator = require('source-map').SourceMapGenerator;
|
||||
var all = require('./helpers').all;
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
var isRemoteResource = require('../utils/is-remote-resource');
|
||||
|
||||
var isWindows = process.platform == 'win32';
|
||||
@@ -23,8 +22,8 @@ function store(serializeContext, element) {
|
||||
|
||||
function wrap(serializeContext, value) {
|
||||
if (serializeContext.column + value.length > serializeContext.format.wrapAt) {
|
||||
track(serializeContext, lineBreak, false);
|
||||
serializeContext.output.push(lineBreak);
|
||||
track(serializeContext, serializeContext.format.breakWith, false);
|
||||
serializeContext.output.push(serializeContext.format.breakWith);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user