clear
This commit is contained in:
335
node_modules/clean-css/lib/properties/break-up.js
generated
vendored
Normal file
335
node_modules/clean-css/lib/properties/break-up.js
generated
vendored
Normal file
@@ -0,0 +1,335 @@
|
||||
var wrapSingle = require('./wrap-for-optimizing').single;
|
||||
var InvalidPropertyError = require('./invalid-property-error');
|
||||
|
||||
var split = require('../utils/split');
|
||||
var MULTIPLEX_SEPARATOR = ',';
|
||||
|
||||
function _colorFilter(validator) {
|
||||
return function (value) {
|
||||
return value[0] == 'invert' || validator.isValidColor(value[0]);
|
||||
};
|
||||
}
|
||||
|
||||
function _styleFilter(validator) {
|
||||
return function (value) {
|
||||
return value[0] != 'inherit' && validator.isValidStyle(value[0]) && !validator.isValidColorValue(value[0]);
|
||||
};
|
||||
}
|
||||
|
||||
function _wrapDefault(name, property, compactable) {
|
||||
var descriptor = compactable[name];
|
||||
if (descriptor.doubleValues && descriptor.defaultValue.length == 2)
|
||||
return wrapSingle([[name, property.important], [descriptor.defaultValue[0]], [descriptor.defaultValue[1]]]);
|
||||
else if (descriptor.doubleValues && descriptor.defaultValue.length == 1)
|
||||
return wrapSingle([[name, property.important], [descriptor.defaultValue[0]]]);
|
||||
else
|
||||
return wrapSingle([[name, property.important], [descriptor.defaultValue]]);
|
||||
}
|
||||
|
||||
function _widthFilter(validator) {
|
||||
return function (value) {
|
||||
return value[0] != 'inherit' && validator.isValidWidth(value[0]) && !validator.isValidStyleKeyword(value[0]) && !validator.isValidColorValue(value[0]);
|
||||
};
|
||||
}
|
||||
|
||||
function background(property, compactable, validator) {
|
||||
var image = _wrapDefault('background-image', property, compactable);
|
||||
var position = _wrapDefault('background-position', property, compactable);
|
||||
var size = _wrapDefault('background-size', property, compactable);
|
||||
var repeat = _wrapDefault('background-repeat', property, compactable);
|
||||
var attachment = _wrapDefault('background-attachment', property, compactable);
|
||||
var origin = _wrapDefault('background-origin', property, compactable);
|
||||
var clip = _wrapDefault('background-clip', property, compactable);
|
||||
var color = _wrapDefault('background-color', property, compactable);
|
||||
var components = [image, position, size, repeat, attachment, origin, clip, color];
|
||||
var values = property.value;
|
||||
|
||||
var positionSet = false;
|
||||
var clipSet = false;
|
||||
var originSet = false;
|
||||
var repeatSet = false;
|
||||
|
||||
if (property.value.length == 1 && property.value[0][0] == 'inherit') {
|
||||
// NOTE: 'inherit' is not a valid value for background-attachment
|
||||
color.value = image.value = repeat.value = position.value = size.value = origin.value = clip.value = property.value;
|
||||
return components;
|
||||
}
|
||||
|
||||
for (var i = values.length - 1; i >= 0; i--) {
|
||||
var value = values[i];
|
||||
|
||||
if (validator.isValidBackgroundAttachment(value[0])) {
|
||||
attachment.value = [value];
|
||||
} else if (validator.isValidBackgroundBox(value[0])) {
|
||||
if (clipSet) {
|
||||
origin.value = [value];
|
||||
originSet = true;
|
||||
} else {
|
||||
clip.value = [value];
|
||||
clipSet = true;
|
||||
}
|
||||
} else if (validator.isValidBackgroundRepeat(value[0])) {
|
||||
if (repeatSet) {
|
||||
repeat.value.unshift(value);
|
||||
} else {
|
||||
repeat.value = [value];
|
||||
repeatSet = true;
|
||||
}
|
||||
} else if (validator.isValidBackgroundPositionPart(value[0]) || validator.isValidBackgroundSizePart(value[0])) {
|
||||
if (i > 0) {
|
||||
var previousValue = values[i - 1];
|
||||
|
||||
if (previousValue[0].indexOf('/') > 0) {
|
||||
var twoParts = split(previousValue[0], '/');
|
||||
// NOTE: we do this slicing as value may contain metadata too, like for source maps
|
||||
size.value = [[twoParts.pop()].concat(previousValue.slice(1)), value];
|
||||
values[i - 1] = [twoParts.pop()].concat(previousValue.slice(1));
|
||||
} else if (i > 1 && values[i - 2][0] == '/') {
|
||||
size.value = [previousValue, value];
|
||||
i -= 2;
|
||||
} else if (previousValue[0] == '/') {
|
||||
size.value = [value];
|
||||
} else {
|
||||
if (!positionSet)
|
||||
position.value = [];
|
||||
|
||||
position.value.unshift(value);
|
||||
positionSet = true;
|
||||
}
|
||||
} else {
|
||||
if (!positionSet)
|
||||
position.value = [];
|
||||
|
||||
position.value.unshift(value);
|
||||
positionSet = true;
|
||||
}
|
||||
} else if (validator.isValidBackgroundPositionAndSize(value[0])) {
|
||||
var sizeValue = split(value[0], '/');
|
||||
// NOTE: we do this slicing as value may contain metadata too, like for source maps
|
||||
size.value = [[sizeValue.pop()].concat(value.slice(1))];
|
||||
position.value = [[sizeValue.pop()].concat(value.slice(1))];
|
||||
} else if ((color.value[0][0] == compactable[color.name].defaultValue || color.value[0][0] == 'none') && validator.isValidColor(value[0])) {
|
||||
color.value = [value];
|
||||
} else if (validator.isValidUrl(value[0]) || validator.isValidFunction(value[0])) {
|
||||
image.value = [value];
|
||||
}
|
||||
}
|
||||
|
||||
if (clipSet && !originSet)
|
||||
origin.value = clip.value.slice(0);
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
function borderRadius(property, compactable) {
|
||||
var values = property.value;
|
||||
var splitAt = -1;
|
||||
|
||||
for (var i = 0, l = values.length; i < l; i++) {
|
||||
if (values[i][0] == '/') {
|
||||
splitAt = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (splitAt === 0 || splitAt === values.length - 1) {
|
||||
throw new InvalidPropertyError('Invalid border-radius value.');
|
||||
}
|
||||
|
||||
var target = _wrapDefault(property.name, property, compactable);
|
||||
target.value = splitAt > -1 ?
|
||||
values.slice(0, splitAt) :
|
||||
values.slice(0);
|
||||
target.components = fourValues(target, compactable);
|
||||
|
||||
var remainder = _wrapDefault(property.name, property, compactable);
|
||||
remainder.value = splitAt > -1 ?
|
||||
values.slice(splitAt + 1) :
|
||||
values.slice(0);
|
||||
remainder.components = fourValues(remainder, compactable);
|
||||
|
||||
for (var j = 0; j < 4; j++) {
|
||||
target.components[j].multiplex = true;
|
||||
target.components[j].value = target.components[j].value.concat(remainder.components[j].value);
|
||||
}
|
||||
|
||||
return target.components;
|
||||
}
|
||||
|
||||
function fourValues(property, compactable) {
|
||||
var componentNames = compactable[property.name].components;
|
||||
var components = [];
|
||||
var value = property.value;
|
||||
|
||||
if (value.length < 1)
|
||||
return [];
|
||||
|
||||
if (value.length < 2)
|
||||
value[1] = value[0].slice(0);
|
||||
if (value.length < 3)
|
||||
value[2] = value[0].slice(0);
|
||||
if (value.length < 4)
|
||||
value[3] = value[1].slice(0);
|
||||
|
||||
for (var i = componentNames.length - 1; i >= 0; i--) {
|
||||
var component = wrapSingle([[componentNames[i], property.important]]);
|
||||
component.value = [value[i]];
|
||||
components.unshift(component);
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
function multiplex(splitWith) {
|
||||
return function (property, compactable, validator) {
|
||||
var splitsAt = [];
|
||||
var values = property.value;
|
||||
var i, j, l, m;
|
||||
|
||||
// find split commas
|
||||
for (i = 0, l = values.length; i < l; i++) {
|
||||
if (values[i][0] == ',')
|
||||
splitsAt.push(i);
|
||||
}
|
||||
|
||||
if (splitsAt.length === 0)
|
||||
return splitWith(property, compactable, validator);
|
||||
|
||||
var splitComponents = [];
|
||||
|
||||
// split over commas, and into components
|
||||
for (i = 0, l = splitsAt.length; i <= l; i++) {
|
||||
var from = i === 0 ? 0 : splitsAt[i - 1] + 1;
|
||||
var to = i < l ? splitsAt[i] : values.length;
|
||||
|
||||
var _property = _wrapDefault(property.name, property, compactable);
|
||||
_property.value = values.slice(from, to);
|
||||
|
||||
splitComponents.push(splitWith(_property, compactable, validator));
|
||||
}
|
||||
|
||||
var components = splitComponents[0];
|
||||
|
||||
// group component values from each split
|
||||
for (i = 0, l = components.length; i < l; i++) {
|
||||
components[i].multiplex = true;
|
||||
|
||||
for (j = 1, m = splitComponents.length; j < m; j++) {
|
||||
components[i].value.push([MULTIPLEX_SEPARATOR]);
|
||||
Array.prototype.push.apply(components[i].value, splitComponents[j][i].value);
|
||||
}
|
||||
}
|
||||
|
||||
return components;
|
||||
};
|
||||
}
|
||||
|
||||
function listStyle(property, compactable, validator) {
|
||||
var type = _wrapDefault('list-style-type', property, compactable);
|
||||
var position = _wrapDefault('list-style-position', property, compactable);
|
||||
var image = _wrapDefault('list-style-image', property, compactable);
|
||||
var components = [type, position, image];
|
||||
|
||||
if (property.value.length == 1 && property.value[0][0] == 'inherit') {
|
||||
type.value = position.value = image.value = [property.value[0]];
|
||||
return components;
|
||||
}
|
||||
|
||||
var values = property.value.slice(0);
|
||||
var total = values.length;
|
||||
var index = 0;
|
||||
|
||||
// `image` first...
|
||||
for (index = 0, total = values.length; index < total; index++) {
|
||||
if (validator.isValidUrl(values[index][0]) || values[index][0] == '0') {
|
||||
image.value = [values[index]];
|
||||
values.splice(index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ... then `type`...
|
||||
for (index = 0, total = values.length; index < total; index++) {
|
||||
if (validator.isValidListStyleType(values[index][0])) {
|
||||
type.value = [values[index]];
|
||||
values.splice(index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ... and what's left is a `position`
|
||||
if (values.length > 0 && validator.isValidListStylePosition(values[0][0]))
|
||||
position.value = [values[0]];
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
function widthStyleColor(property, compactable, validator) {
|
||||
var descriptor = compactable[property.name];
|
||||
var components = [
|
||||
_wrapDefault(descriptor.components[0], property, compactable),
|
||||
_wrapDefault(descriptor.components[1], property, compactable),
|
||||
_wrapDefault(descriptor.components[2], property, compactable)
|
||||
];
|
||||
var color, style, width;
|
||||
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var component = components[i];
|
||||
|
||||
if (component.name.indexOf('color') > 0)
|
||||
color = component;
|
||||
else if (component.name.indexOf('style') > 0)
|
||||
style = component;
|
||||
else
|
||||
width = component;
|
||||
}
|
||||
|
||||
if ((property.value.length == 1 && property.value[0][0] == 'inherit') ||
|
||||
(property.value.length == 3 && property.value[0][0] == 'inherit' && property.value[1][0] == 'inherit' && property.value[2][0] == 'inherit')) {
|
||||
color.value = style.value = width.value = [property.value[0]];
|
||||
return components;
|
||||
}
|
||||
|
||||
var values = property.value.slice(0);
|
||||
var match, matches;
|
||||
|
||||
// NOTE: usually users don't follow the required order of parts in this shorthand,
|
||||
// so we'll try to parse it caring as little about order as possible
|
||||
|
||||
if (values.length > 0) {
|
||||
matches = values.filter(_widthFilter(validator));
|
||||
match = matches.length > 1 && (matches[0][0] == 'none' || matches[0][0] == 'auto') ? matches[1] : matches[0];
|
||||
if (match) {
|
||||
width.value = [match];
|
||||
values.splice(values.indexOf(match), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (values.length > 0) {
|
||||
match = values.filter(_styleFilter(validator))[0];
|
||||
if (match) {
|
||||
style.value = [match];
|
||||
values.splice(values.indexOf(match), 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (values.length > 0) {
|
||||
match = values.filter(_colorFilter(validator))[0];
|
||||
if (match) {
|
||||
color.value = [match];
|
||||
values.splice(values.indexOf(match), 1);
|
||||
}
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
background: background,
|
||||
border: widthStyleColor,
|
||||
borderRadius: borderRadius,
|
||||
fourValues: fourValues,
|
||||
listStyle: listStyle,
|
||||
multiplex: multiplex,
|
||||
outline: widthStyleColor
|
||||
};
|
||||
142
node_modules/clean-css/lib/properties/can-override.js
generated
vendored
Normal file
142
node_modules/clean-css/lib/properties/can-override.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
// Functions that decide what value can override what.
|
||||
// The main purpose is to disallow removing CSS fallbacks.
|
||||
// A separate implementation is needed for every different kind of CSS property.
|
||||
// -----
|
||||
// The generic idea is that properties that have wider browser support are 'more understandable'
|
||||
// than others and that 'less understandable' values can't override more understandable ones.
|
||||
|
||||
// Use when two tokens of the same property can always be merged
|
||||
function always() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function alwaysButIntoFunction(property1, property2, validator) {
|
||||
var value1 = property1.value[0][0];
|
||||
var value2 = property2.value[0][0];
|
||||
|
||||
var validFunction1 = validator.isValidFunction(value1);
|
||||
var validFunction2 = validator.isValidFunction(value2);
|
||||
|
||||
if (validFunction1 && validFunction2) {
|
||||
return validator.areSameFunction(value1, value2);
|
||||
} else if (!validFunction1 && validFunction2) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function backgroundImage(property1, property2, validator) {
|
||||
// The idea here is that 'more understandable' values override 'less understandable' values, but not vice versa
|
||||
// Understandability: (none | url | inherit) > (same function) > (same value)
|
||||
|
||||
// (none | url)
|
||||
var image1 = property1.value[0][0];
|
||||
var image2 = property2.value[0][0];
|
||||
|
||||
if (image2 == 'none' || image2 == 'inherit' || validator.isValidUrl(image2))
|
||||
return true;
|
||||
if (image1 == 'none' || image1 == 'inherit' || validator.isValidUrl(image1))
|
||||
return false;
|
||||
|
||||
// Functions with the same name can override each other; same values can override each other
|
||||
return sameFunctionOrValue(property1, property2, validator);
|
||||
}
|
||||
|
||||
function border(property1, property2, validator) {
|
||||
return color(property1.components[2], property2.components[2], validator);
|
||||
}
|
||||
|
||||
// Use for color properties (color, background-color, border-color, etc.)
|
||||
function color(property1, property2, validator) {
|
||||
// The idea here is that 'more understandable' values override 'less understandable' values, but not vice versa
|
||||
// Understandability: (hex | named) > (rgba | hsla) > (same function name) > anything else
|
||||
// NOTE: at this point rgb and hsl are replaced by hex values by clean-css
|
||||
|
||||
var color1 = property1.value[0][0];
|
||||
var color2 = property2.value[0][0];
|
||||
|
||||
if (!validator.colorOpacity && (validator.isValidRgbaColor(color1) || validator.isValidHslaColor(color1)))
|
||||
return false;
|
||||
if (!validator.colorOpacity && (validator.isValidRgbaColor(color2) || validator.isValidHslaColor(color2)))
|
||||
return false;
|
||||
|
||||
// (hex | named)
|
||||
if (validator.isValidNamedColor(color2) || validator.isValidHexColor(color2))
|
||||
return true;
|
||||
if (validator.isValidNamedColor(color1) || validator.isValidHexColor(color1))
|
||||
return false;
|
||||
|
||||
// (rgba|hsla)
|
||||
if (validator.isValidRgbaColor(color2) || validator.isValidHslaColor(color2))
|
||||
return true;
|
||||
if (validator.isValidRgbaColor(color1) || validator.isValidHslaColor(color1))
|
||||
return false;
|
||||
|
||||
// Functions with the same name can override each other; same values can override each other
|
||||
return sameFunctionOrValue(property1, property2, validator);
|
||||
}
|
||||
|
||||
function twoOptionalFunctions(property1, property2, validator) {
|
||||
var value1 = property1.value[0][0];
|
||||
var value2 = property2.value[0][0];
|
||||
|
||||
return !(validator.isValidFunction(value1) ^ validator.isValidFunction(value2));
|
||||
}
|
||||
|
||||
function sameValue(property1, property2) {
|
||||
var value1 = property1.value[0][0];
|
||||
var value2 = property2.value[0][0];
|
||||
|
||||
return value1 === value2;
|
||||
}
|
||||
|
||||
function sameFunctionOrValue(property1, property2, validator) {
|
||||
var value1 = property1.value[0][0];
|
||||
var value2 = property2.value[0][0];
|
||||
|
||||
// Functions with the same name can override each other
|
||||
if (validator.areSameFunction(value1, value2))
|
||||
return true;
|
||||
|
||||
return value1 === value2;
|
||||
}
|
||||
|
||||
// Use for properties containing CSS units (margin-top, padding-left, etc.)
|
||||
function unit(property1, property2, validator) {
|
||||
// The idea here is that 'more understandable' values override 'less understandable' values, but not vice versa
|
||||
// Understandability: (unit without functions) > (same functions | standard functions) > anything else
|
||||
// NOTE: there is no point in having different vendor-specific functions override each other or standard functions,
|
||||
// or having standard functions override vendor-specific functions, but standard functions can override each other
|
||||
// NOTE: vendor-specific property values are not taken into consideration here at the moment
|
||||
var value1 = property1.value[0][0];
|
||||
var value2 = property2.value[0][0];
|
||||
|
||||
if (validator.isValidAndCompatibleUnitWithoutFunction(value1) && !validator.isValidAndCompatibleUnitWithoutFunction(value2))
|
||||
return false;
|
||||
|
||||
if (validator.isValidUnitWithoutFunction(value2))
|
||||
return true;
|
||||
if (validator.isValidUnitWithoutFunction(value1))
|
||||
return false;
|
||||
|
||||
// Standard non-vendor-prefixed functions can override each other
|
||||
if (validator.isValidFunctionWithoutVendorPrefix(value2) && validator.isValidFunctionWithoutVendorPrefix(value1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Functions with the same name can override each other; same values can override each other
|
||||
return sameFunctionOrValue(property1, property2, validator);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
always: always,
|
||||
alwaysButIntoFunction: alwaysButIntoFunction,
|
||||
backgroundImage: backgroundImage,
|
||||
border: border,
|
||||
color: color,
|
||||
sameValue: sameValue,
|
||||
sameFunctionOrValue: sameFunctionOrValue,
|
||||
twoOptionalFunctions: twoOptionalFunctions,
|
||||
unit: unit
|
||||
};
|
||||
26
node_modules/clean-css/lib/properties/clone.js
generated
vendored
Normal file
26
node_modules/clean-css/lib/properties/clone.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var wrapSingle = require('./wrap-for-optimizing').single;
|
||||
|
||||
function deep(property) {
|
||||
var cloned = shallow(property);
|
||||
for (var i = property.components.length - 1; i >= 0; i--) {
|
||||
var component = shallow(property.components[i]);
|
||||
component.value = property.components[i].value.slice(0);
|
||||
cloned.components.unshift(component);
|
||||
}
|
||||
|
||||
cloned.dirty = true;
|
||||
cloned.value = property.value.slice(0);
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
function shallow(property) {
|
||||
var cloned = wrapSingle([[property.name, property.important, property.hack]]);
|
||||
cloned.unused = false;
|
||||
return cloned;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
deep: deep,
|
||||
shallow: shallow
|
||||
};
|
||||
285
node_modules/clean-css/lib/properties/compactable.js
generated
vendored
Normal file
285
node_modules/clean-css/lib/properties/compactable.js
generated
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
// Contains the interpretation of CSS properties, as used by the property optimizer
|
||||
|
||||
var breakUp = require('./break-up');
|
||||
var canOverride = require('./can-override');
|
||||
var restore = require('./restore');
|
||||
|
||||
// Properties to process
|
||||
// Extend this object in order to add support for more properties in the optimizer.
|
||||
//
|
||||
// Each key in this object represents a CSS property and should be an object.
|
||||
// Such an object contains properties that describe how the represented CSS property should be handled.
|
||||
// Possible options:
|
||||
//
|
||||
// * components: array (Only specify for shorthand properties.)
|
||||
// Contains the names of the granular properties this shorthand compacts.
|
||||
//
|
||||
// * canOverride: function (Default is canOverride.sameValue - meaning that they'll only be merged if they have the same value.)
|
||||
// Returns whether two tokens of this property can be merged with each other.
|
||||
// This property has no meaning for shorthands.
|
||||
//
|
||||
// * defaultValue: string
|
||||
// Specifies the default value of the property according to the CSS standard.
|
||||
// For shorthand, this is used when every component is set to its default value, therefore it should be the shortest possible default value of all the components.
|
||||
//
|
||||
// * shortestValue: string
|
||||
// Specifies the shortest possible value the property can possibly have.
|
||||
// (Falls back to defaultValue if unspecified.)
|
||||
//
|
||||
// * breakUp: function (Only specify for shorthand properties.)
|
||||
// Breaks the shorthand up to its components.
|
||||
//
|
||||
// * restore: function (Only specify for shorthand properties.)
|
||||
// Puts the shorthand together from its components.
|
||||
//
|
||||
var compactable = {
|
||||
'color': {
|
||||
canOverride: canOverride.color,
|
||||
defaultValue: 'transparent',
|
||||
shortestValue: 'red'
|
||||
},
|
||||
'background': {
|
||||
components: [
|
||||
'background-image',
|
||||
'background-position',
|
||||
'background-size',
|
||||
'background-repeat',
|
||||
'background-attachment',
|
||||
'background-origin',
|
||||
'background-clip',
|
||||
'background-color'
|
||||
],
|
||||
breakUp: breakUp.multiplex(breakUp.background),
|
||||
defaultValue: '0 0',
|
||||
restore: restore.multiplex(restore.background),
|
||||
shortestValue: '0',
|
||||
shorthand: true
|
||||
},
|
||||
'background-clip': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'border-box',
|
||||
shortestValue: 'border-box'
|
||||
},
|
||||
'background-color': {
|
||||
canOverride: canOverride.color,
|
||||
defaultValue: 'transparent',
|
||||
multiplexLastOnly: true,
|
||||
nonMergeableValue: 'none',
|
||||
shortestValue: 'red'
|
||||
},
|
||||
'background-image': {
|
||||
canOverride: canOverride.backgroundImage,
|
||||
defaultValue: 'none'
|
||||
},
|
||||
'background-origin': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'padding-box',
|
||||
shortestValue: 'border-box'
|
||||
},
|
||||
'background-repeat': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: ['repeat'],
|
||||
doubleValues: true
|
||||
},
|
||||
'background-position': {
|
||||
canOverride: canOverride.alwaysButIntoFunction,
|
||||
defaultValue: ['0', '0'],
|
||||
doubleValues: true,
|
||||
shortestValue: '0'
|
||||
},
|
||||
'background-size': {
|
||||
canOverride: canOverride.alwaysButIntoFunction,
|
||||
defaultValue: ['auto'],
|
||||
doubleValues: true,
|
||||
shortestValue: '0 0'
|
||||
},
|
||||
'background-attachment': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'scroll'
|
||||
},
|
||||
'border': {
|
||||
breakUp: breakUp.border,
|
||||
canOverride: canOverride.border,
|
||||
components: [
|
||||
'border-width',
|
||||
'border-style',
|
||||
'border-color'
|
||||
],
|
||||
defaultValue: 'none',
|
||||
restore: restore.withoutDefaults,
|
||||
shorthand: true
|
||||
},
|
||||
'border-color': {
|
||||
canOverride: canOverride.color,
|
||||
defaultValue: 'none',
|
||||
shorthand: true
|
||||
},
|
||||
'border-style': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'none',
|
||||
shorthand: true
|
||||
},
|
||||
'border-width': {
|
||||
canOverride: canOverride.unit,
|
||||
defaultValue: 'medium',
|
||||
shortestValue: '0',
|
||||
shorthand: true
|
||||
},
|
||||
'list-style': {
|
||||
components: [
|
||||
'list-style-type',
|
||||
'list-style-position',
|
||||
'list-style-image'
|
||||
],
|
||||
canOverride: canOverride.always,
|
||||
breakUp: breakUp.listStyle,
|
||||
restore: restore.withoutDefaults,
|
||||
defaultValue: 'outside', // can't use 'disc' because that'd override default 'decimal' for <ol>
|
||||
shortestValue: 'none',
|
||||
shorthand: true
|
||||
},
|
||||
'list-style-type' : {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: '__hack',
|
||||
// NOTE: we can't tell the real default value here, it's 'disc' for <ul> and 'decimal' for <ol>
|
||||
// -- this is a hack, but it doesn't matter because this value will be either overridden or it will disappear at the final step anyway
|
||||
shortestValue: 'none'
|
||||
},
|
||||
'list-style-position' : {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'outside',
|
||||
shortestValue: 'inside'
|
||||
},
|
||||
'list-style-image' : {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'none'
|
||||
},
|
||||
'outline': {
|
||||
components: [
|
||||
'outline-color',
|
||||
'outline-style',
|
||||
'outline-width'
|
||||
],
|
||||
breakUp: breakUp.outline,
|
||||
restore: restore.withoutDefaults,
|
||||
defaultValue: '0',
|
||||
shorthand: true
|
||||
},
|
||||
'outline-color': {
|
||||
canOverride: canOverride.color,
|
||||
defaultValue: 'invert',
|
||||
shortestValue: 'red'
|
||||
},
|
||||
'outline-style': {
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'none'
|
||||
},
|
||||
'outline-width': {
|
||||
canOverride: canOverride.unit,
|
||||
defaultValue: 'medium',
|
||||
shortestValue: '0'
|
||||
},
|
||||
'-moz-transform': {
|
||||
canOverride: canOverride.sameFunctionOrValue
|
||||
},
|
||||
'-ms-transform': {
|
||||
canOverride: canOverride.sameFunctionOrValue
|
||||
},
|
||||
'-webkit-transform': {
|
||||
canOverride: canOverride.sameFunctionOrValue
|
||||
},
|
||||
'transform': {
|
||||
canOverride: canOverride.sameFunctionOrValue
|
||||
}
|
||||
};
|
||||
|
||||
var addFourValueShorthand = function (prop, components, options) {
|
||||
options = options || {};
|
||||
compactable[prop] = {
|
||||
canOverride: options.canOverride,
|
||||
components: components,
|
||||
breakUp: options.breakUp || breakUp.fourValues,
|
||||
defaultValue: options.defaultValue || '0',
|
||||
restore: options.restore || restore.fourValues,
|
||||
shortestValue: options.shortestValue,
|
||||
shorthand: true
|
||||
};
|
||||
for (var i = 0; i < components.length; i++) {
|
||||
compactable[components[i]] = {
|
||||
breakUp: options.breakUp || breakUp.fourValues,
|
||||
canOverride: options.canOverride || canOverride.unit,
|
||||
defaultValue: options.defaultValue || '0',
|
||||
shortestValue: options.shortestValue
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
['', '-moz-', '-o-', '-webkit-'].forEach(function (prefix) {
|
||||
addFourValueShorthand(prefix + 'border-radius', [
|
||||
prefix + 'border-top-left-radius',
|
||||
prefix + 'border-top-right-radius',
|
||||
prefix + 'border-bottom-right-radius',
|
||||
prefix + 'border-bottom-left-radius'
|
||||
], {
|
||||
breakUp: breakUp.borderRadius,
|
||||
restore: restore.borderRadius
|
||||
});
|
||||
});
|
||||
|
||||
addFourValueShorthand('border-color', [
|
||||
'border-top-color',
|
||||
'border-right-color',
|
||||
'border-bottom-color',
|
||||
'border-left-color'
|
||||
], {
|
||||
breakUp: breakUp.fourValues,
|
||||
canOverride: canOverride.color,
|
||||
defaultValue: 'none',
|
||||
shortestValue: 'red'
|
||||
});
|
||||
|
||||
addFourValueShorthand('border-style', [
|
||||
'border-top-style',
|
||||
'border-right-style',
|
||||
'border-bottom-style',
|
||||
'border-left-style'
|
||||
], {
|
||||
breakUp: breakUp.fourValues,
|
||||
canOverride: canOverride.always,
|
||||
defaultValue: 'none'
|
||||
});
|
||||
|
||||
addFourValueShorthand('border-width', [
|
||||
'border-top-width',
|
||||
'border-right-width',
|
||||
'border-bottom-width',
|
||||
'border-left-width'
|
||||
], {
|
||||
defaultValue: 'medium',
|
||||
shortestValue: '0'
|
||||
});
|
||||
|
||||
addFourValueShorthand('padding', [
|
||||
'padding-top',
|
||||
'padding-right',
|
||||
'padding-bottom',
|
||||
'padding-left'
|
||||
]);
|
||||
|
||||
addFourValueShorthand('margin', [
|
||||
'margin-top',
|
||||
'margin-right',
|
||||
'margin-bottom',
|
||||
'margin-left'
|
||||
]);
|
||||
|
||||
// Adds `componentOf` field to all longhands
|
||||
for (var property in compactable) {
|
||||
if (compactable[property].shorthand) {
|
||||
for (var i = 0, l = compactable[property].components.length; i < l; i++) {
|
||||
compactable[compactable[property].components[i]].componentOf = property;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = compactable;
|
||||
28
node_modules/clean-css/lib/properties/every-combination.js
generated
vendored
Normal file
28
node_modules/clean-css/lib/properties/every-combination.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var shallowClone = require('./clone').shallow;
|
||||
|
||||
var MULTIPLEX_SEPARATOR = ',';
|
||||
|
||||
function everyCombination(fn, left, right, validator) {
|
||||
var samePositon = !left.shorthand && !right.shorthand && !left.multiplex && !right.multiplex;
|
||||
var _left = shallowClone(left);
|
||||
var _right = shallowClone(right);
|
||||
|
||||
for (var i = 0, l = left.value.length; i < l; i++) {
|
||||
for (var j = 0, m = right.value.length; j < m; j++) {
|
||||
if (left.value[i][0] == MULTIPLEX_SEPARATOR || right.value[j][0] == MULTIPLEX_SEPARATOR)
|
||||
continue;
|
||||
|
||||
if (samePositon && i != j)
|
||||
continue;
|
||||
|
||||
_left.value = [left.value[i]];
|
||||
_right.value = [right.value[j]];
|
||||
if (!fn(_left, _right, validator))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = everyCombination;
|
||||
10
node_modules/clean-css/lib/properties/has-inherit.js
generated
vendored
Normal file
10
node_modules/clean-css/lib/properties/has-inherit.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function hasInherit(property) {
|
||||
for (var i = property.value.length - 1; i >= 0; i--) {
|
||||
if (property.value[i][0] == 'inherit')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = hasInherit;
|
||||
10
node_modules/clean-css/lib/properties/invalid-property-error.js
generated
vendored
Normal file
10
node_modules/clean-css/lib/properties/invalid-property-error.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function InvalidPropertyError(message) {
|
||||
this.name = 'InvalidPropertyError';
|
||||
this.message = message;
|
||||
this.stack = (new Error()).stack;
|
||||
}
|
||||
|
||||
InvalidPropertyError.prototype = Object.create(Error.prototype);
|
||||
InvalidPropertyError.prototype.constructor = InvalidPropertyError;
|
||||
|
||||
module.exports = InvalidPropertyError;
|
||||
215
node_modules/clean-css/lib/properties/optimizer.js
generated
vendored
Normal file
215
node_modules/clean-css/lib/properties/optimizer.js
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
var compactable = require('./compactable');
|
||||
var wrapForOptimizing = require('./wrap-for-optimizing').all;
|
||||
var populateComponents = require('./populate-components');
|
||||
var compactOverrides = require('./override-compactor');
|
||||
var compactShorthands = require('./shorthand-compactor');
|
||||
var removeUnused = require('./remove-unused');
|
||||
var restoreFromOptimizing = require('./restore-from-optimizing');
|
||||
var stringifyProperty = require('../stringifier/one-time').property;
|
||||
|
||||
var shorthands = {
|
||||
'animation-delay': ['animation'],
|
||||
'animation-direction': ['animation'],
|
||||
'animation-duration': ['animation'],
|
||||
'animation-fill-mode': ['animation'],
|
||||
'animation-iteration-count': ['animation'],
|
||||
'animation-name': ['animation'],
|
||||
'animation-play-state': ['animation'],
|
||||
'animation-timing-function': ['animation'],
|
||||
'-moz-animation-delay': ['-moz-animation'],
|
||||
'-moz-animation-direction': ['-moz-animation'],
|
||||
'-moz-animation-duration': ['-moz-animation'],
|
||||
'-moz-animation-fill-mode': ['-moz-animation'],
|
||||
'-moz-animation-iteration-count': ['-moz-animation'],
|
||||
'-moz-animation-name': ['-moz-animation'],
|
||||
'-moz-animation-play-state': ['-moz-animation'],
|
||||
'-moz-animation-timing-function': ['-moz-animation'],
|
||||
'-o-animation-delay': ['-o-animation'],
|
||||
'-o-animation-direction': ['-o-animation'],
|
||||
'-o-animation-duration': ['-o-animation'],
|
||||
'-o-animation-fill-mode': ['-o-animation'],
|
||||
'-o-animation-iteration-count': ['-o-animation'],
|
||||
'-o-animation-name': ['-o-animation'],
|
||||
'-o-animation-play-state': ['-o-animation'],
|
||||
'-o-animation-timing-function': ['-o-animation'],
|
||||
'-webkit-animation-delay': ['-webkit-animation'],
|
||||
'-webkit-animation-direction': ['-webkit-animation'],
|
||||
'-webkit-animation-duration': ['-webkit-animation'],
|
||||
'-webkit-animation-fill-mode': ['-webkit-animation'],
|
||||
'-webkit-animation-iteration-count': ['-webkit-animation'],
|
||||
'-webkit-animation-name': ['-webkit-animation'],
|
||||
'-webkit-animation-play-state': ['-webkit-animation'],
|
||||
'-webkit-animation-timing-function': ['-webkit-animation'],
|
||||
'border-color': ['border'],
|
||||
'border-style': ['border'],
|
||||
'border-width': ['border'],
|
||||
'border-bottom': ['border'],
|
||||
'border-bottom-color': ['border-bottom', 'border-color', 'border'],
|
||||
'border-bottom-style': ['border-bottom', 'border-style', 'border'],
|
||||
'border-bottom-width': ['border-bottom', 'border-width', 'border'],
|
||||
'border-left': ['border'],
|
||||
'border-left-color': ['border-left', 'border-color', 'border'],
|
||||
'border-left-style': ['border-left', 'border-style', 'border'],
|
||||
'border-left-width': ['border-left', 'border-width', 'border'],
|
||||
'border-right': ['border'],
|
||||
'border-right-color': ['border-right', 'border-color', 'border'],
|
||||
'border-right-style': ['border-right', 'border-style', 'border'],
|
||||
'border-right-width': ['border-right', 'border-width', 'border'],
|
||||
'border-top': ['border'],
|
||||
'border-top-color': ['border-top', 'border-color', 'border'],
|
||||
'border-top-style': ['border-top', 'border-style', 'border'],
|
||||
'border-top-width': ['border-top', 'border-width', 'border'],
|
||||
'font-family': ['font'],
|
||||
'font-size': ['font'],
|
||||
'font-style': ['font'],
|
||||
'font-variant': ['font'],
|
||||
'font-weight': ['font'],
|
||||
'transition-delay': ['transition'],
|
||||
'transition-duration': ['transition'],
|
||||
'transition-property': ['transition'],
|
||||
'transition-timing-function': ['transition'],
|
||||
'-moz-transition-delay': ['-moz-transition'],
|
||||
'-moz-transition-duration': ['-moz-transition'],
|
||||
'-moz-transition-property': ['-moz-transition'],
|
||||
'-moz-transition-timing-function': ['-moz-transition'],
|
||||
'-o-transition-delay': ['-o-transition'],
|
||||
'-o-transition-duration': ['-o-transition'],
|
||||
'-o-transition-property': ['-o-transition'],
|
||||
'-o-transition-timing-function': ['-o-transition'],
|
||||
'-webkit-transition-delay': ['-webkit-transition'],
|
||||
'-webkit-transition-duration': ['-webkit-transition'],
|
||||
'-webkit-transition-property': ['-webkit-transition'],
|
||||
'-webkit-transition-timing-function': ['-webkit-transition']
|
||||
};
|
||||
|
||||
function _optimize(properties, mergeAdjacent, aggressiveMerging, validator) {
|
||||
var overrideMapping = {};
|
||||
var lastName = null;
|
||||
var lastProperty;
|
||||
var j;
|
||||
|
||||
function mergeablePosition(position) {
|
||||
if (mergeAdjacent === false || mergeAdjacent === true)
|
||||
return mergeAdjacent;
|
||||
|
||||
return mergeAdjacent.indexOf(position) > -1;
|
||||
}
|
||||
|
||||
function sameValue(position) {
|
||||
var left = properties[position - 1];
|
||||
var right = properties[position];
|
||||
|
||||
return stringifyProperty(left.all, left.position) == stringifyProperty(right.all, right.position);
|
||||
}
|
||||
|
||||
propertyLoop:
|
||||
for (var position = 0, total = properties.length; position < total; position++) {
|
||||
var property = properties[position];
|
||||
var _name = (property.name == '-ms-filter' || property.name == 'filter') ?
|
||||
(lastName == 'background' || lastName == 'background-image' ? lastName : property.name) :
|
||||
property.name;
|
||||
var isImportant = property.important;
|
||||
var isHack = property.hack;
|
||||
|
||||
if (property.unused)
|
||||
continue;
|
||||
|
||||
if (position > 0 && lastProperty && _name == lastName && isImportant == lastProperty.important && isHack == lastProperty.hack && sameValue(position) && !lastProperty.unused) {
|
||||
property.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// comment is necessary - we assume that if two properties are one after another
|
||||
// then it is intentional way of redefining property which may not be widely supported
|
||||
// e.g. a{display:inline-block;display:-moz-inline-box}
|
||||
// however if `mergeablePosition` yields true then the rule does not apply
|
||||
// (e.g merging two adjacent selectors: `a{display:block}a{display:block}`)
|
||||
if (_name in overrideMapping && (aggressiveMerging && _name != lastName || mergeablePosition(position))) {
|
||||
var toOverridePositions = overrideMapping[_name];
|
||||
var canOverride = compactable[_name] && compactable[_name].canOverride;
|
||||
var anyRemoved = false;
|
||||
|
||||
for (j = toOverridePositions.length - 1; j >= 0; j--) {
|
||||
var toRemove = properties[toOverridePositions[j]];
|
||||
var longhandToShorthand = toRemove.name != _name;
|
||||
var wasImportant = toRemove.important;
|
||||
var wasHack = toRemove.hack;
|
||||
|
||||
if (toRemove.unused)
|
||||
continue;
|
||||
|
||||
if (longhandToShorthand && wasImportant)
|
||||
continue;
|
||||
|
||||
if (!wasImportant && (wasHack && !isHack || !wasHack && isHack))
|
||||
continue;
|
||||
|
||||
if (wasImportant && (isHack == 'star' || isHack == 'underscore'))
|
||||
continue;
|
||||
|
||||
if (!wasHack && !isHack && !longhandToShorthand && canOverride && !canOverride(toRemove, property, validator))
|
||||
continue;
|
||||
|
||||
if (wasImportant && !isImportant || wasImportant && isHack) {
|
||||
property.unused = true;
|
||||
lastProperty = property;
|
||||
continue propertyLoop;
|
||||
} else {
|
||||
anyRemoved = true;
|
||||
toRemove.unused = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (anyRemoved) {
|
||||
position = -1;
|
||||
lastProperty = null;
|
||||
lastName = null;
|
||||
overrideMapping = {};
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
overrideMapping[_name] = overrideMapping[_name] || [];
|
||||
overrideMapping[_name].push(position);
|
||||
|
||||
// TODO: to be removed with
|
||||
// certain shorthand (see values of `shorthands`) should trigger removal of
|
||||
// longhand properties (see keys of `shorthands`)
|
||||
var _shorthands = shorthands[_name];
|
||||
if (_shorthands) {
|
||||
for (j = _shorthands.length - 1; j >= 0; j--) {
|
||||
var shorthand = _shorthands[j];
|
||||
overrideMapping[shorthand] = overrideMapping[shorthand] || [];
|
||||
overrideMapping[shorthand].push(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastName = _name;
|
||||
lastProperty = property;
|
||||
}
|
||||
}
|
||||
|
||||
function optimize(selector, properties, mergeAdjacent, withCompacting, options, context) {
|
||||
var validator = context.validator;
|
||||
var warnings = context.warnings;
|
||||
|
||||
var _properties = wrapForOptimizing(properties);
|
||||
populateComponents(_properties, validator, warnings);
|
||||
_optimize(_properties, mergeAdjacent, options.aggressiveMerging, validator);
|
||||
|
||||
for (var i = 0, l = _properties.length; i < l; i++) {
|
||||
var _property = _properties[i];
|
||||
if (_property.variable && _property.block)
|
||||
optimize(selector, _property.value[0], mergeAdjacent, withCompacting, options, context);
|
||||
}
|
||||
|
||||
if (withCompacting && options.shorthandCompacting) {
|
||||
compactOverrides(_properties, options.compatibility, validator);
|
||||
compactShorthands(_properties, options.sourceMap, validator);
|
||||
}
|
||||
|
||||
restoreFromOptimizing(_properties);
|
||||
removeUnused(_properties);
|
||||
}
|
||||
|
||||
module.exports = optimize;
|
||||
384
node_modules/clean-css/lib/properties/override-compactor.js
generated
vendored
Normal file
384
node_modules/clean-css/lib/properties/override-compactor.js
generated
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
var canOverride = require('./can-override');
|
||||
var compactable = require('./compactable');
|
||||
var deepClone = require('./clone').deep;
|
||||
var shallowClone = require('./clone').shallow;
|
||||
var hasInherit = require('./has-inherit');
|
||||
var restoreFromOptimizing = require('./restore-from-optimizing');
|
||||
var everyCombination = require('./every-combination');
|
||||
var sameVendorPrefixesIn = require('./vendor-prefixes').same;
|
||||
|
||||
var stringifyProperty = require('../stringifier/one-time').property;
|
||||
|
||||
var MULTIPLEX_SEPARATOR = ',';
|
||||
|
||||
// Used when searching for a component that matches property
|
||||
function nameMatchFilter(to) {
|
||||
return function (property) {
|
||||
return to.name === property.name;
|
||||
};
|
||||
}
|
||||
|
||||
function wouldBreakCompatibility(property, validator) {
|
||||
for (var i = 0; i < property.components.length; i++) {
|
||||
var component = property.components[i];
|
||||
var descriptor = compactable[component.name];
|
||||
var canOverride = descriptor && descriptor.canOverride || canOverride.sameValue;
|
||||
|
||||
var _component = shallowClone(component);
|
||||
_component.value = [[descriptor.defaultValue]];
|
||||
|
||||
if (!canOverride(_component, component, validator))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isComponentOf(shorthand, longhand) {
|
||||
return compactable[shorthand.name].components.indexOf(longhand.name) > -1;
|
||||
}
|
||||
|
||||
function overrideIntoMultiplex(property, by) {
|
||||
by.unused = true;
|
||||
|
||||
turnIntoMultiplex(by, multiplexSize(property));
|
||||
property.value = by.value;
|
||||
}
|
||||
|
||||
function overrideByMultiplex(property, by) {
|
||||
by.unused = true;
|
||||
property.multiplex = true;
|
||||
property.value = by.value;
|
||||
}
|
||||
|
||||
function overrideSimple(property, by) {
|
||||
by.unused = true;
|
||||
property.value = by.value;
|
||||
}
|
||||
|
||||
function override(property, by) {
|
||||
if (by.multiplex)
|
||||
overrideByMultiplex(property, by);
|
||||
else if (property.multiplex)
|
||||
overrideIntoMultiplex(property, by);
|
||||
else
|
||||
overrideSimple(property, by);
|
||||
}
|
||||
|
||||
function overrideShorthand(property, by) {
|
||||
by.unused = true;
|
||||
|
||||
for (var i = 0, l = property.components.length; i < l; i++) {
|
||||
override(property.components[i], by.components[i], property.multiplex);
|
||||
}
|
||||
}
|
||||
|
||||
function turnIntoMultiplex(property, size) {
|
||||
property.multiplex = true;
|
||||
|
||||
for (var i = 0, l = property.components.length; i < l; i++) {
|
||||
var component = property.components[i];
|
||||
if (component.multiplex)
|
||||
continue;
|
||||
|
||||
var value = component.value.slice(0);
|
||||
|
||||
for (var j = 1; j < size; j++) {
|
||||
component.value.push([MULTIPLEX_SEPARATOR]);
|
||||
Array.prototype.push.apply(component.value, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function multiplexSize(component) {
|
||||
var size = 0;
|
||||
|
||||
for (var i = 0, l = component.value.length; i < l; i++) {
|
||||
if (component.value[i][0] == MULTIPLEX_SEPARATOR)
|
||||
size++;
|
||||
}
|
||||
|
||||
return size + 1;
|
||||
}
|
||||
|
||||
function lengthOf(property) {
|
||||
var fakeAsArray = [[property.name]].concat(property.value);
|
||||
return stringifyProperty([fakeAsArray], 0).length;
|
||||
}
|
||||
|
||||
function moreSameShorthands(properties, startAt, name) {
|
||||
// Since we run the main loop in `compactOverrides` backwards, at this point some
|
||||
// properties may not be marked as unused.
|
||||
// We should consider reverting the order if possible
|
||||
var count = 0;
|
||||
|
||||
for (var i = startAt; i >= 0; i--) {
|
||||
if (properties[i].name == name && !properties[i].unused)
|
||||
count++;
|
||||
if (count > 1)
|
||||
break;
|
||||
}
|
||||
|
||||
return count > 1;
|
||||
}
|
||||
|
||||
function overridingFunction(shorthand, validator) {
|
||||
for (var i = 0, l = shorthand.components.length; i < l; i++) {
|
||||
if (anyValue(validator.isValidFunction, shorthand.components[i]))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function anyValue(fn, property) {
|
||||
for (var i = 0, l = property.value.length; i < l; i++) {
|
||||
if (property.value[i][0] == MULTIPLEX_SEPARATOR)
|
||||
continue;
|
||||
|
||||
if (fn(property.value[i][0]))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function wouldResultInLongerValue(left, right) {
|
||||
if (!left.multiplex && !right.multiplex || left.multiplex && right.multiplex)
|
||||
return false;
|
||||
|
||||
var multiplex = left.multiplex ? left : right;
|
||||
var simple = left.multiplex ? right : left;
|
||||
var component;
|
||||
|
||||
var multiplexClone = deepClone(multiplex);
|
||||
restoreFromOptimizing([multiplexClone]);
|
||||
|
||||
var simpleClone = deepClone(simple);
|
||||
restoreFromOptimizing([simpleClone]);
|
||||
|
||||
var lengthBefore = lengthOf(multiplexClone) + 1 + lengthOf(simpleClone);
|
||||
|
||||
if (left.multiplex) {
|
||||
component = multiplexClone.components.filter(nameMatchFilter(simpleClone))[0];
|
||||
overrideIntoMultiplex(component, simpleClone);
|
||||
} else {
|
||||
component = simpleClone.components.filter(nameMatchFilter(multiplexClone))[0];
|
||||
turnIntoMultiplex(simpleClone, multiplexSize(multiplexClone));
|
||||
overrideByMultiplex(component, multiplexClone);
|
||||
}
|
||||
|
||||
restoreFromOptimizing([simpleClone]);
|
||||
|
||||
var lengthAfter = lengthOf(simpleClone);
|
||||
|
||||
return lengthBefore < lengthAfter;
|
||||
}
|
||||
|
||||
function isCompactable(property) {
|
||||
return property.name in compactable;
|
||||
}
|
||||
|
||||
function noneOverrideHack(left, right) {
|
||||
return !left.multiplex &&
|
||||
(left.name == 'background' || left.name == 'background-image') &&
|
||||
right.multiplex &&
|
||||
(right.name == 'background' || right.name == 'background-image') &&
|
||||
anyLayerIsNone(right.value);
|
||||
}
|
||||
|
||||
function anyLayerIsNone(values) {
|
||||
var layers = intoLayers(values);
|
||||
|
||||
for (var i = 0, l = layers.length; i < l; i++) {
|
||||
if (layers[i].length == 1 && layers[i][0][0] == 'none')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function intoLayers(values) {
|
||||
var layers = [];
|
||||
|
||||
for (var i = 0, layer = [], l = values.length; i < l; i++) {
|
||||
var value = values[i];
|
||||
if (value[0] == MULTIPLEX_SEPARATOR) {
|
||||
layers.push(layer);
|
||||
layer = [];
|
||||
} else {
|
||||
layer.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
layers.push(layer);
|
||||
return layers;
|
||||
}
|
||||
|
||||
function compactOverrides(properties, compatibility, validator) {
|
||||
var mayOverride, right, left, component;
|
||||
var i, j, k;
|
||||
|
||||
propertyLoop:
|
||||
for (i = properties.length - 1; i >= 0; i--) {
|
||||
right = properties[i];
|
||||
|
||||
if (!isCompactable(right))
|
||||
continue;
|
||||
|
||||
if (right.variable)
|
||||
continue;
|
||||
|
||||
mayOverride = compactable[right.name].canOverride || canOverride.sameValue;
|
||||
|
||||
for (j = i - 1; j >= 0; j--) {
|
||||
left = properties[j];
|
||||
|
||||
if (!isCompactable(left))
|
||||
continue;
|
||||
|
||||
if (left.variable)
|
||||
continue;
|
||||
|
||||
if (left.unused || right.unused)
|
||||
continue;
|
||||
|
||||
if (left.hack && !right.hack || !left.hack && right.hack)
|
||||
continue;
|
||||
|
||||
if (hasInherit(right))
|
||||
continue;
|
||||
|
||||
if (noneOverrideHack(left, right))
|
||||
continue;
|
||||
|
||||
if (!left.shorthand && right.shorthand && isComponentOf(right, left)) {
|
||||
// maybe `left` can be overridden by `right` which is a shorthand?
|
||||
if (!right.important && left.important)
|
||||
continue;
|
||||
|
||||
if (!sameVendorPrefixesIn([left], right.components))
|
||||
continue;
|
||||
|
||||
if (!anyValue(validator.isValidFunction, left) && overridingFunction(right, validator))
|
||||
continue;
|
||||
|
||||
component = right.components.filter(nameMatchFilter(left))[0];
|
||||
mayOverride = (compactable[left.name] && compactable[left.name].canOverride) || canOverride.sameValue;
|
||||
if (everyCombination(mayOverride, left, component, validator)) {
|
||||
left.unused = true;
|
||||
}
|
||||
} else if (left.shorthand && !right.shorthand && isComponentOf(left, right)) {
|
||||
// maybe `right` can be pulled into `left` which is a shorthand?
|
||||
if (right.important && !left.important)
|
||||
continue;
|
||||
|
||||
if (!right.important && left.important) {
|
||||
right.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pending more clever algorithm in #527
|
||||
if (moreSameShorthands(properties, i - 1, left.name))
|
||||
continue;
|
||||
|
||||
if (overridingFunction(left, validator))
|
||||
continue;
|
||||
|
||||
component = left.components.filter(nameMatchFilter(right))[0];
|
||||
if (everyCombination(mayOverride, component, right, validator)) {
|
||||
var disabledBackgroundMerging =
|
||||
!compatibility.properties.backgroundClipMerging && component.name.indexOf('background-clip') > -1 ||
|
||||
!compatibility.properties.backgroundOriginMerging && component.name.indexOf('background-origin') > -1 ||
|
||||
!compatibility.properties.backgroundSizeMerging && component.name.indexOf('background-size') > -1;
|
||||
var nonMergeableValue = compactable[right.name].nonMergeableValue === right.value[0][0];
|
||||
|
||||
if (disabledBackgroundMerging || nonMergeableValue)
|
||||
continue;
|
||||
|
||||
if (!compatibility.properties.merging && wouldBreakCompatibility(left, validator))
|
||||
continue;
|
||||
|
||||
if (component.value[0][0] != right.value[0][0] && (hasInherit(left) || hasInherit(right)))
|
||||
continue;
|
||||
|
||||
if (wouldResultInLongerValue(left, right))
|
||||
continue;
|
||||
|
||||
if (!left.multiplex && right.multiplex)
|
||||
turnIntoMultiplex(left, multiplexSize(right));
|
||||
|
||||
override(component, right);
|
||||
left.dirty = true;
|
||||
}
|
||||
} else if (left.shorthand && right.shorthand && left.name == right.name) {
|
||||
// merge if all components can be merged
|
||||
|
||||
if (!left.multiplex && right.multiplex)
|
||||
continue;
|
||||
|
||||
if (!right.important && left.important) {
|
||||
right.unused = true;
|
||||
continue propertyLoop;
|
||||
}
|
||||
|
||||
if (right.important && !left.important) {
|
||||
left.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (k = left.components.length - 1; k >= 0; k--) {
|
||||
var leftComponent = left.components[k];
|
||||
var rightComponent = right.components[k];
|
||||
|
||||
mayOverride = compactable[leftComponent.name].canOverride || canOverride.sameValue;
|
||||
if (!everyCombination(mayOverride, leftComponent, rightComponent, validator))
|
||||
continue propertyLoop;
|
||||
if (!everyCombination(canOverride.twoOptionalFunctions, leftComponent, rightComponent, validator) && validator.isValidFunction(rightComponent))
|
||||
continue propertyLoop;
|
||||
}
|
||||
|
||||
overrideShorthand(left, right);
|
||||
left.dirty = true;
|
||||
} else if (left.shorthand && right.shorthand && isComponentOf(left, right)) {
|
||||
// border is a shorthand but any of its components is a shorthand too
|
||||
|
||||
if (!left.important && right.important)
|
||||
continue;
|
||||
|
||||
component = left.components.filter(nameMatchFilter(right))[0];
|
||||
mayOverride = compactable[right.name].canOverride || canOverride.sameValue;
|
||||
if (!everyCombination(mayOverride, component, right, validator))
|
||||
continue;
|
||||
|
||||
if (left.important && !right.important) {
|
||||
right.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var rightRestored = compactable[right.name].restore(right, compactable);
|
||||
if (rightRestored.length > 1)
|
||||
continue;
|
||||
|
||||
component = left.components.filter(nameMatchFilter(right))[0];
|
||||
override(component, right);
|
||||
right.dirty = true;
|
||||
} else if (left.name == right.name) {
|
||||
// two non-shorthands should be merged based on understandability
|
||||
|
||||
if (left.important && !right.important) {
|
||||
right.unused = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
mayOverride = compactable[right.name].canOverride || canOverride.sameValue;
|
||||
if (!everyCombination(mayOverride, left, right, validator))
|
||||
continue;
|
||||
|
||||
left.unused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = compactOverrides;
|
||||
32
node_modules/clean-css/lib/properties/populate-components.js
generated
vendored
Normal file
32
node_modules/clean-css/lib/properties/populate-components.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var compactable = require('./compactable');
|
||||
var InvalidPropertyError = require('./invalid-property-error');
|
||||
|
||||
function populateComponents(properties, validator, warnings) {
|
||||
for (var i = properties.length - 1; i >= 0; i--) {
|
||||
var property = properties[i];
|
||||
var descriptor = compactable[property.name];
|
||||
|
||||
if (descriptor && descriptor.shorthand) {
|
||||
property.shorthand = true;
|
||||
property.dirty = true;
|
||||
|
||||
try {
|
||||
property.components = descriptor.breakUp(property, compactable, validator);
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidPropertyError) {
|
||||
property.components = []; // this will set property.unused to true below
|
||||
warnings.push(e.message);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (property.components.length > 0)
|
||||
property.multiplex = property.components[0].multiplex;
|
||||
else
|
||||
property.unused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = populateComponents;
|
||||
10
node_modules/clean-css/lib/properties/remove-unused.js
generated
vendored
Normal file
10
node_modules/clean-css/lib/properties/remove-unused.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function removeUnused(properties) {
|
||||
for (var i = properties.length - 1; i >= 0; i--) {
|
||||
var property = properties[i];
|
||||
|
||||
if (property.unused)
|
||||
property.all.splice(property.position, 1);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = removeUnused;
|
||||
60
node_modules/clean-css/lib/properties/restore-from-optimizing.js
generated
vendored
Normal file
60
node_modules/clean-css/lib/properties/restore-from-optimizing.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
var compactable = require('./compactable');
|
||||
|
||||
var BACKSLASH_HACK = '\\9';
|
||||
var IMPORTANT_TOKEN = '!important';
|
||||
var STAR_HACK = '*';
|
||||
var UNDERSCORE_HACK = '_';
|
||||
var BANG_HACK = '!ie';
|
||||
|
||||
function restoreImportant(property) {
|
||||
property.value[property.value.length - 1][0] += IMPORTANT_TOKEN;
|
||||
}
|
||||
|
||||
function restoreHack(property) {
|
||||
if (property.hack == 'underscore')
|
||||
property.name = UNDERSCORE_HACK + property.name;
|
||||
else if (property.hack == 'star')
|
||||
property.name = STAR_HACK + property.name;
|
||||
else if (property.hack == 'backslash')
|
||||
property.value[property.value.length - 1][0] += BACKSLASH_HACK;
|
||||
else if (property.hack == 'bang')
|
||||
property.value[property.value.length - 1][0] += ' ' + BANG_HACK;
|
||||
}
|
||||
|
||||
function restoreFromOptimizing(properties, simpleMode) {
|
||||
for (var i = properties.length - 1; i >= 0; i--) {
|
||||
var property = properties[i];
|
||||
var descriptor = compactable[property.name];
|
||||
var restored;
|
||||
|
||||
if (property.unused)
|
||||
continue;
|
||||
|
||||
if (!property.dirty && !property.important && !property.hack)
|
||||
continue;
|
||||
|
||||
if (!simpleMode && descriptor && descriptor.shorthand) {
|
||||
restored = descriptor.restore(property, compactable);
|
||||
property.value = restored;
|
||||
} else {
|
||||
restored = property.value;
|
||||
}
|
||||
|
||||
if (property.important)
|
||||
restoreImportant(property);
|
||||
|
||||
if (property.hack)
|
||||
restoreHack(property);
|
||||
|
||||
if (!('all' in property))
|
||||
continue;
|
||||
|
||||
var current = property.all[property.position];
|
||||
current[0][0] = property.name;
|
||||
|
||||
current.splice(1, current.length - 1);
|
||||
Array.prototype.push.apply(current, restored);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = restoreFromOptimizing;
|
||||
232
node_modules/clean-css/lib/properties/restore.js
generated
vendored
Normal file
232
node_modules/clean-css/lib/properties/restore.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
var shallowClone = require('./clone').shallow;
|
||||
var MULTIPLEX_SEPARATOR = ',';
|
||||
var SIZE_POSITION_SEPARATOR = '/';
|
||||
|
||||
function isInheritOnly(values) {
|
||||
for (var i = 0, l = values.length; i < l; i++) {
|
||||
var value = values[i][0];
|
||||
|
||||
if (value != 'inherit' && value != MULTIPLEX_SEPARATOR && value != SIZE_POSITION_SEPARATOR)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function background(property, compactable, lastInMultiplex) {
|
||||
var components = property.components;
|
||||
var restored = [];
|
||||
var needsOne, needsBoth;
|
||||
|
||||
function restoreValue(component) {
|
||||
Array.prototype.unshift.apply(restored, component.value);
|
||||
}
|
||||
|
||||
function isDefaultValue(component) {
|
||||
var descriptor = compactable[component.name];
|
||||
if (descriptor.doubleValues) {
|
||||
if (descriptor.defaultValue.length == 1)
|
||||
return component.value[0][0] == descriptor.defaultValue[0] && (component.value[1] ? component.value[1][0] == descriptor.defaultValue[0] : true);
|
||||
else
|
||||
return component.value[0][0] == descriptor.defaultValue[0] && (component.value[1] ? component.value[1][0] : component.value[0][0]) == descriptor.defaultValue[1];
|
||||
} else {
|
||||
return component.value[0][0] == descriptor.defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = components.length - 1; i >= 0; i--) {
|
||||
var component = components[i];
|
||||
var isDefault = isDefaultValue(component);
|
||||
|
||||
if (component.name == 'background-clip') {
|
||||
var originComponent = components[i - 1];
|
||||
var isOriginDefault = isDefaultValue(originComponent);
|
||||
|
||||
needsOne = component.value[0][0] == originComponent.value[0][0];
|
||||
|
||||
needsBoth = !needsOne && (
|
||||
(isOriginDefault && !isDefault) ||
|
||||
(!isOriginDefault && !isDefault) ||
|
||||
(!isOriginDefault && isDefault && component.value[0][0] != originComponent.value[0][0]));
|
||||
|
||||
if (needsOne) {
|
||||
restoreValue(originComponent);
|
||||
} else if (needsBoth) {
|
||||
restoreValue(component);
|
||||
restoreValue(originComponent);
|
||||
}
|
||||
|
||||
i--;
|
||||
} else if (component.name == 'background-size') {
|
||||
var positionComponent = components[i - 1];
|
||||
var isPositionDefault = isDefaultValue(positionComponent);
|
||||
|
||||
needsOne = !isPositionDefault && isDefault;
|
||||
|
||||
needsBoth = !needsOne &&
|
||||
(isPositionDefault && !isDefault || !isPositionDefault && !isDefault);
|
||||
|
||||
if (needsOne) {
|
||||
restoreValue(positionComponent);
|
||||
} else if (needsBoth) {
|
||||
restoreValue(component);
|
||||
restored.unshift([SIZE_POSITION_SEPARATOR]);
|
||||
restoreValue(positionComponent);
|
||||
} else if (positionComponent.value.length == 1) {
|
||||
restoreValue(positionComponent);
|
||||
}
|
||||
|
||||
i--;
|
||||
} else {
|
||||
if (isDefault || compactable[component.name].multiplexLastOnly && !lastInMultiplex)
|
||||
continue;
|
||||
|
||||
restoreValue(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (restored.length === 0 && property.value.length == 1 && property.value[0][0] == '0')
|
||||
restored.push(property.value[0]);
|
||||
|
||||
if (restored.length === 0)
|
||||
restored.push([compactable[property.name].defaultValue]);
|
||||
|
||||
if (isInheritOnly(restored))
|
||||
return [restored[0]];
|
||||
|
||||
return restored;
|
||||
}
|
||||
|
||||
function borderRadius(property, compactable) {
|
||||
if (property.multiplex) {
|
||||
var horizontal = shallowClone(property);
|
||||
var vertical = shallowClone(property);
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var component = property.components[i];
|
||||
|
||||
var horizontalComponent = shallowClone(property);
|
||||
horizontalComponent.value = [component.value[0]];
|
||||
horizontal.components.push(horizontalComponent);
|
||||
|
||||
var verticalComponent = shallowClone(property);
|
||||
// FIXME: only shorthand compactor (see breakup#borderRadius) knows that border radius
|
||||
// longhands have two values, whereas tokenizer does not care about populating 2nd value
|
||||
// if it's missing, hence this fallback
|
||||
verticalComponent.value = [component.value[1] || component.value[0]];
|
||||
vertical.components.push(verticalComponent);
|
||||
}
|
||||
|
||||
var horizontalValues = fourValues(horizontal, compactable);
|
||||
var verticalValues = fourValues(vertical, compactable);
|
||||
|
||||
if (horizontalValues.length == verticalValues.length &&
|
||||
horizontalValues[0][0] == verticalValues[0][0] &&
|
||||
(horizontalValues.length > 1 ? horizontalValues[1][0] == verticalValues[1][0] : true) &&
|
||||
(horizontalValues.length > 2 ? horizontalValues[2][0] == verticalValues[2][0] : true) &&
|
||||
(horizontalValues.length > 3 ? horizontalValues[3][0] == verticalValues[3][0] : true)) {
|
||||
return horizontalValues;
|
||||
} else {
|
||||
return horizontalValues.concat([['/']]).concat(verticalValues);
|
||||
}
|
||||
} else {
|
||||
return fourValues(property, compactable);
|
||||
}
|
||||
}
|
||||
|
||||
function fourValues(property) {
|
||||
var components = property.components;
|
||||
var value1 = components[0].value[0];
|
||||
var value2 = components[1].value[0];
|
||||
var value3 = components[2].value[0];
|
||||
var value4 = components[3].value[0];
|
||||
|
||||
if (value1[0] == value2[0] && value1[0] == value3[0] && value1[0] == value4[0]) {
|
||||
return [value1];
|
||||
} else if (value1[0] == value3[0] && value2[0] == value4[0]) {
|
||||
return [value1, value2];
|
||||
} else if (value2[0] == value4[0]) {
|
||||
return [value1, value2, value3];
|
||||
} else {
|
||||
return [value1, value2, value3, value4];
|
||||
}
|
||||
}
|
||||
|
||||
function multiplex(restoreWith) {
|
||||
return function (property, compactable) {
|
||||
if (!property.multiplex)
|
||||
return restoreWith(property, compactable, true);
|
||||
|
||||
var multiplexSize = 0;
|
||||
var restored = [];
|
||||
var componentMultiplexSoFar = {};
|
||||
var i, l;
|
||||
|
||||
// At this point we don't know what's the multiplex size, e.g. how many background layers are there
|
||||
for (i = 0, l = property.components[0].value.length; i < l; i++) {
|
||||
if (property.components[0].value[i][0] == MULTIPLEX_SEPARATOR)
|
||||
multiplexSize++;
|
||||
}
|
||||
|
||||
for (i = 0; i <= multiplexSize; i++) {
|
||||
var _property = shallowClone(property);
|
||||
|
||||
// We split multiplex into parts and restore them one by one
|
||||
for (var j = 0, m = property.components.length; j < m; j++) {
|
||||
var componentToClone = property.components[j];
|
||||
var _component = shallowClone(componentToClone);
|
||||
_property.components.push(_component);
|
||||
|
||||
// The trick is some properties has more than one value, so we iterate over values looking for
|
||||
// a multiplex separator - a comma
|
||||
for (var k = componentMultiplexSoFar[_component.name] || 0, n = componentToClone.value.length; k < n; k++) {
|
||||
if (componentToClone.value[k][0] == MULTIPLEX_SEPARATOR) {
|
||||
componentMultiplexSoFar[_component.name] = k + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
_component.value.push(componentToClone.value[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// No we can restore shorthand value
|
||||
var lastInMultiplex = i == multiplexSize;
|
||||
var _restored = restoreWith(_property, compactable, lastInMultiplex);
|
||||
Array.prototype.push.apply(restored, _restored);
|
||||
|
||||
if (i < multiplexSize)
|
||||
restored.push([',']);
|
||||
}
|
||||
|
||||
return restored;
|
||||
};
|
||||
}
|
||||
|
||||
function withoutDefaults(property, compactable) {
|
||||
var components = property.components;
|
||||
var restored = [];
|
||||
|
||||
for (var i = components.length - 1; i >= 0; i--) {
|
||||
var component = components[i];
|
||||
var descriptor = compactable[component.name];
|
||||
|
||||
if (component.value[0][0] != descriptor.defaultValue)
|
||||
restored.unshift(component.value[0]);
|
||||
}
|
||||
|
||||
if (restored.length === 0)
|
||||
restored.push([compactable[property.name].defaultValue]);
|
||||
|
||||
if (isInheritOnly(restored))
|
||||
return [restored[0]];
|
||||
|
||||
return restored;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
background: background,
|
||||
borderRadius: borderRadius,
|
||||
fourValues: fourValues,
|
||||
multiplex: multiplex,
|
||||
withoutDefaults: withoutDefaults
|
||||
};
|
||||
134
node_modules/clean-css/lib/properties/shorthand-compactor.js
generated
vendored
Normal file
134
node_modules/clean-css/lib/properties/shorthand-compactor.js
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
var compactable = require('./compactable');
|
||||
var deepClone = require('./clone').deep;
|
||||
var hasInherit = require('./has-inherit');
|
||||
var populateComponents = require('./populate-components');
|
||||
var wrapSingle = require('./wrap-for-optimizing').single;
|
||||
var everyCombination = require('./every-combination');
|
||||
|
||||
function mixedImportance(components) {
|
||||
var important;
|
||||
|
||||
for (var name in components) {
|
||||
if (undefined !== important && components[name].important != important)
|
||||
return true;
|
||||
|
||||
important = components[name].important;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function componentSourceMaps(components) {
|
||||
var sourceMapping = [];
|
||||
|
||||
for (var name in components) {
|
||||
var component = components[name];
|
||||
var originalValue = component.all[component.position];
|
||||
var mapping = originalValue[0][originalValue[0].length - 1];
|
||||
|
||||
if (Array.isArray(mapping))
|
||||
Array.prototype.push.apply(sourceMapping, mapping);
|
||||
}
|
||||
|
||||
return sourceMapping;
|
||||
}
|
||||
|
||||
function replaceWithShorthand(properties, candidateComponents, name, sourceMaps, validator) {
|
||||
var descriptor = compactable[name];
|
||||
var newValuePlaceholder = [[name], [descriptor.defaultValue]];
|
||||
var all;
|
||||
|
||||
var newProperty = wrapSingle(newValuePlaceholder);
|
||||
newProperty.shorthand = true;
|
||||
newProperty.dirty = true;
|
||||
|
||||
populateComponents([newProperty], validator, []);
|
||||
|
||||
for (var i = 0, l = descriptor.components.length; i < l; i++) {
|
||||
var component = candidateComponents[descriptor.components[i]];
|
||||
var canOverride = compactable[component.name].canOverride;
|
||||
|
||||
if (hasInherit(component))
|
||||
return;
|
||||
|
||||
if (!everyCombination(canOverride, newProperty.components[i], component, validator))
|
||||
return;
|
||||
|
||||
newProperty.components[i] = deepClone(component);
|
||||
newProperty.important = component.important;
|
||||
|
||||
all = component.all;
|
||||
}
|
||||
|
||||
for (var componentName in candidateComponents) {
|
||||
candidateComponents[componentName].unused = true;
|
||||
}
|
||||
|
||||
if (sourceMaps) {
|
||||
var sourceMapping = componentSourceMaps(candidateComponents);
|
||||
if (sourceMapping.length > 0)
|
||||
newValuePlaceholder[0].push(sourceMapping);
|
||||
}
|
||||
|
||||
newProperty.position = all.length;
|
||||
newProperty.all = all;
|
||||
newProperty.all.push(newValuePlaceholder);
|
||||
|
||||
properties.push(newProperty);
|
||||
}
|
||||
|
||||
function invalidateOrCompact(properties, position, candidates, sourceMaps, validator) {
|
||||
var property = properties[position];
|
||||
|
||||
for (var name in candidates) {
|
||||
if (undefined !== property && name == property.name)
|
||||
continue;
|
||||
|
||||
var descriptor = compactable[name];
|
||||
var candidateComponents = candidates[name];
|
||||
if (descriptor.components.length > Object.keys(candidateComponents).length) {
|
||||
delete candidates[name];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mixedImportance(candidateComponents))
|
||||
continue;
|
||||
|
||||
replaceWithShorthand(properties, candidateComponents, name, sourceMaps, validator);
|
||||
}
|
||||
}
|
||||
|
||||
function compactShortands(properties, sourceMaps, validator) {
|
||||
var candidates = {};
|
||||
|
||||
if (properties.length < 3)
|
||||
return;
|
||||
|
||||
for (var i = 0, l = properties.length; i < l; i++) {
|
||||
var property = properties[i];
|
||||
if (property.unused)
|
||||
continue;
|
||||
|
||||
if (property.hack)
|
||||
continue;
|
||||
|
||||
if (property.variable)
|
||||
continue;
|
||||
|
||||
var descriptor = compactable[property.name];
|
||||
if (!descriptor || !descriptor.componentOf)
|
||||
continue;
|
||||
|
||||
if (property.shorthand) {
|
||||
invalidateOrCompact(properties, i, candidates, sourceMaps, validator);
|
||||
} else {
|
||||
var componentOf = descriptor.componentOf;
|
||||
candidates[componentOf] = candidates[componentOf] || {};
|
||||
candidates[componentOf][property.name] = property;
|
||||
}
|
||||
}
|
||||
|
||||
invalidateOrCompact(properties, i, candidates, sourceMaps, validator);
|
||||
}
|
||||
|
||||
module.exports = compactShortands;
|
||||
197
node_modules/clean-css/lib/properties/validator.js
generated
vendored
Normal file
197
node_modules/clean-css/lib/properties/validator.js
generated
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
// Validates various CSS property values
|
||||
|
||||
var split = require('../utils/split');
|
||||
|
||||
var widthKeywords = ['thin', 'thick', 'medium', 'inherit', 'initial'];
|
||||
var allUnits = ['px', '%', 'em', 'in', 'cm', 'mm', 'ex', 'pt', 'pc', 'ch', 'rem', 'vh', 'vm', 'vmin', 'vmax', 'vw'];
|
||||
var cssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(' + allUnits.join('|') + '|)|auto|inherit)';
|
||||
var cssCalcRegexStr = '(\\-moz\\-|\\-webkit\\-)?calc\\([^\\)]+\\)';
|
||||
var cssFunctionNoVendorRegexStr = '[A-Z]+(\\-|[A-Z]|[0-9])+\\(.*?\\)';
|
||||
var cssFunctionVendorRegexStr = '\\-(\\-|[A-Z]|[0-9])+\\(.*?\\)';
|
||||
var cssVariableRegexStr = 'var\\(\\-\\-[^\\)]+\\)';
|
||||
var cssFunctionAnyRegexStr = '(' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
|
||||
var cssUnitOrCalcRegexStr = '(' + cssUnitRegexStr + '|' + cssCalcRegexStr + ')';
|
||||
var cssUnitAnyRegexStr = '(none|' + widthKeywords.join('|') + '|' + cssUnitRegexStr + '|' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
|
||||
|
||||
var cssFunctionNoVendorRegex = new RegExp('^' + cssFunctionNoVendorRegexStr + '$', 'i');
|
||||
var cssFunctionVendorRegex = new RegExp('^' + cssFunctionVendorRegexStr + '$', 'i');
|
||||
var cssVariableRegex = new RegExp('^' + cssVariableRegexStr + '$', 'i');
|
||||
var cssFunctionAnyRegex = new RegExp('^' + cssFunctionAnyRegexStr + '$', 'i');
|
||||
var cssUnitRegex = new RegExp('^' + cssUnitRegexStr + '$', 'i');
|
||||
var cssUnitOrCalcRegex = new RegExp('^' + cssUnitOrCalcRegexStr + '$', 'i');
|
||||
var cssUnitAnyRegex = new RegExp('^' + cssUnitAnyRegexStr + '$', 'i');
|
||||
|
||||
var backgroundRepeatKeywords = ['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'inherit'];
|
||||
var backgroundAttachmentKeywords = ['inherit', 'scroll', 'fixed', 'local'];
|
||||
var backgroundPositionKeywords = ['center', 'top', 'bottom', 'left', 'right'];
|
||||
var backgroundSizeKeywords = ['contain', 'cover'];
|
||||
var backgroundBoxKeywords = ['border-box', 'content-box', 'padding-box'];
|
||||
var styleKeywords = ['auto', 'inherit', 'hidden', 'none', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
|
||||
var listStyleTypeKeywords = ['armenian', 'circle', 'cjk-ideographic', 'decimal', 'decimal-leading-zero', 'disc', 'georgian', 'hebrew', 'hiragana', 'hiragana-iroha', 'inherit', 'katakana', 'katakana-iroha', 'lower-alpha', 'lower-greek', 'lower-latin', 'lower-roman', 'none', 'square', 'upper-alpha', 'upper-latin', 'upper-roman'];
|
||||
var listStylePositionKeywords = ['inside', 'outside', 'inherit'];
|
||||
|
||||
function Validator(compatibility) {
|
||||
var validUnits = allUnits.slice(0).filter(function (value) {
|
||||
return !(value in compatibility.units) || compatibility.units[value] === true;
|
||||
});
|
||||
|
||||
var compatibleCssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(' + validUnits.join('|') + '|)|auto|inherit)';
|
||||
this.compatibleCssUnitRegex = new RegExp('^' + compatibleCssUnitRegexStr + '$', 'i');
|
||||
this.compatibleCssUnitAnyRegex = new RegExp('^(none|' + widthKeywords.join('|') + '|' + compatibleCssUnitRegexStr + '|' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')$', 'i');
|
||||
|
||||
this.colorOpacity = compatibility.colors.opacity;
|
||||
}
|
||||
|
||||
Validator.prototype.isValidHexColor = function (s) {
|
||||
return (s.length === 4 || s.length === 7) && s[0] === '#';
|
||||
};
|
||||
|
||||
Validator.prototype.isValidRgbaColor = function (s) {
|
||||
s = s.split(' ').join('');
|
||||
return s.length > 0 && s.indexOf('rgba(') === 0 && s.indexOf(')') === s.length - 1;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidHslaColor = function (s) {
|
||||
s = s.split(' ').join('');
|
||||
return s.length > 0 && s.indexOf('hsla(') === 0 && s.indexOf(')') === s.length - 1;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidNamedColor = function (s) {
|
||||
// We don't really check if it's a valid color value, but allow any letters in it
|
||||
return s !== 'auto' && (s === 'transparent' || s === 'inherit' || /^[a-zA-Z]+$/.test(s));
|
||||
};
|
||||
|
||||
Validator.prototype.isValidVariable = function (s) {
|
||||
return cssVariableRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidColor = function (s) {
|
||||
return this.isValidNamedColor(s) ||
|
||||
this.isValidColorValue(s) ||
|
||||
this.isValidVariable(s) ||
|
||||
this.isValidVendorPrefixedValue(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidColorValue = function (s) {
|
||||
return this.isValidHexColor(s) ||
|
||||
this.isValidRgbaColor(s) ||
|
||||
this.isValidHslaColor(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidUrl = function (s) {
|
||||
// NOTE: at this point all URLs are replaced with placeholders by clean-css, so we check for those placeholders
|
||||
return s.indexOf('__ESCAPED_URL_CLEAN_CSS') === 0;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidUnit = function (s) {
|
||||
return cssUnitAnyRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidUnitWithoutFunction = function (s) {
|
||||
return cssUnitRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidAndCompatibleUnit = function (s) {
|
||||
return this.compatibleCssUnitAnyRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidAndCompatibleUnitWithoutFunction = function (s) {
|
||||
return this.compatibleCssUnitRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidFunctionWithoutVendorPrefix = function (s) {
|
||||
return cssFunctionNoVendorRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidFunctionWithVendorPrefix = function (s) {
|
||||
return cssFunctionVendorRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidFunction = function (s) {
|
||||
return cssFunctionAnyRegex.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundRepeat = function (s) {
|
||||
return backgroundRepeatKeywords.indexOf(s) >= 0 || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundAttachment = function (s) {
|
||||
return backgroundAttachmentKeywords.indexOf(s) >= 0 || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundBox = function (s) {
|
||||
return backgroundBoxKeywords.indexOf(s) >= 0 || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundPositionPart = function (s) {
|
||||
return backgroundPositionKeywords.indexOf(s) >= 0 || cssUnitOrCalcRegex.test(s) || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundPosition = function (s) {
|
||||
if (s === 'inherit')
|
||||
return true;
|
||||
|
||||
var parts = s.split(' ');
|
||||
for (var i = 0, l = parts.length; i < l; i++) {
|
||||
if (parts[i] === '')
|
||||
continue;
|
||||
if (this.isValidBackgroundPositionPart(parts[i]) || this.isValidVariable(parts[i]))
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundSizePart = function (s) {
|
||||
return backgroundSizeKeywords.indexOf(s) >= 0 || cssUnitRegex.test(s) || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidBackgroundPositionAndSize = function (s) {
|
||||
if (s.indexOf('/') < 0)
|
||||
return false;
|
||||
|
||||
var twoParts = split(s, '/');
|
||||
return this.isValidBackgroundSizePart(twoParts.pop()) && this.isValidBackgroundPositionPart(twoParts.pop());
|
||||
};
|
||||
|
||||
Validator.prototype.isValidListStyleType = function (s) {
|
||||
return listStyleTypeKeywords.indexOf(s) >= 0 || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidListStylePosition = function (s) {
|
||||
return listStylePositionKeywords.indexOf(s) >= 0 || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidStyle = function (s) {
|
||||
return this.isValidStyleKeyword(s) || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidStyleKeyword = function (s) {
|
||||
return styleKeywords.indexOf(s) >= 0;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidWidth = function (s) {
|
||||
return this.isValidUnit(s) || this.isValidWidthKeyword(s) || this.isValidVariable(s);
|
||||
};
|
||||
|
||||
Validator.prototype.isValidWidthKeyword = function (s) {
|
||||
return widthKeywords.indexOf(s) >= 0;
|
||||
};
|
||||
|
||||
Validator.prototype.isValidVendorPrefixedValue = function (s) {
|
||||
return /^-([A-Za-z0-9]|-)*$/gi.test(s);
|
||||
};
|
||||
|
||||
Validator.prototype.areSameFunction = function (a, b) {
|
||||
if (!this.isValidFunction(a) || !this.isValidFunction(b))
|
||||
return false;
|
||||
|
||||
var f1name = a.substring(0, a.indexOf('('));
|
||||
var f2name = b.substring(0, b.indexOf('('));
|
||||
|
||||
return f1name === f2name;
|
||||
};
|
||||
|
||||
module.exports = Validator;
|
||||
26
node_modules/clean-css/lib/properties/vendor-prefixes.js
generated
vendored
Normal file
26
node_modules/clean-css/lib/properties/vendor-prefixes.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var VENDOR_PREFIX_PATTERN = /$\-moz\-|\-ms\-|\-o\-|\-webkit\-/;
|
||||
|
||||
function prefixesIn(tokens) {
|
||||
var prefixes = [];
|
||||
|
||||
for (var i = 0, l = tokens.length; i < l; i++) {
|
||||
var token = tokens[i];
|
||||
|
||||
for (var j = 0, m = token.value.length; j < m; j++) {
|
||||
var match = VENDOR_PREFIX_PATTERN.exec(token.value[j][0]);
|
||||
|
||||
if (match && prefixes.indexOf(match[0]) == -1)
|
||||
prefixes.push(match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
function same(left, right) {
|
||||
return prefixesIn(left).sort().join(',') == prefixesIn(right).sort().join(',');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
same: same
|
||||
};
|
||||
118
node_modules/clean-css/lib/properties/wrap-for-optimizing.js
generated
vendored
Normal file
118
node_modules/clean-css/lib/properties/wrap-for-optimizing.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
var BACKSLASH_HACK = '\\';
|
||||
var IMPORTANT_WORD = 'important';
|
||||
var IMPORTANT_TOKEN = '!'+IMPORTANT_WORD;
|
||||
var IMPORTANT_WORD_MATCH = new RegExp(IMPORTANT_WORD+'$', 'i');
|
||||
var IMPORTANT_TOKEN_MATCH = new RegExp(IMPORTANT_TOKEN+'$', 'i');
|
||||
var STAR_HACK = '*';
|
||||
var UNDERSCORE_HACK = '_';
|
||||
var BANG_HACK = '!';
|
||||
|
||||
function wrapAll(properties) {
|
||||
var wrapped = [];
|
||||
|
||||
for (var i = properties.length - 1; i >= 0; i--) {
|
||||
if (typeof properties[i][0] == 'string')
|
||||
continue;
|
||||
|
||||
var single = wrapSingle(properties[i]);
|
||||
single.all = properties;
|
||||
single.position = i;
|
||||
wrapped.unshift(single);
|
||||
}
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
function isMultiplex(property) {
|
||||
for (var i = 1, l = property.length; i < l; i++) {
|
||||
if (property[i][0] == ',' || property[i][0] == '/')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function hackType(property) {
|
||||
var type = false;
|
||||
var name = property[0][0];
|
||||
var lastValue = property[property.length - 1];
|
||||
|
||||
if (name[0] == UNDERSCORE_HACK) {
|
||||
type = 'underscore';
|
||||
} else if (name[0] == STAR_HACK) {
|
||||
type = 'star';
|
||||
} else if (lastValue[0][0] == BANG_HACK && !lastValue[0].match(IMPORTANT_WORD_MATCH)) {
|
||||
type = 'bang';
|
||||
} else if (lastValue[0].indexOf(BANG_HACK) > 0 && !lastValue[0].match(IMPORTANT_WORD_MATCH)) {
|
||||
type = 'bang';
|
||||
} else if (lastValue[0].indexOf(BACKSLASH_HACK) > 0 && lastValue[0].indexOf(BACKSLASH_HACK) == lastValue[0].length - BACKSLASH_HACK.length - 1) {
|
||||
type = 'backslash';
|
||||
} else if (lastValue[0].indexOf(BACKSLASH_HACK) === 0 && lastValue[0].length == 2) {
|
||||
type = 'backslash';
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function isImportant(property) {
|
||||
if (property.length > 1) {
|
||||
var p = property[property.length - 1][0];
|
||||
if (typeof(p) === 'string') {
|
||||
return IMPORTANT_TOKEN_MATCH.test(p);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function stripImportant(property) {
|
||||
if (property.length > 0)
|
||||
property[property.length - 1][0] = property[property.length - 1][0].replace(IMPORTANT_TOKEN_MATCH, '');
|
||||
}
|
||||
|
||||
function stripPrefixHack(property) {
|
||||
property[0][0] = property[0][0].substring(1);
|
||||
}
|
||||
|
||||
function stripSuffixHack(property, hackType) {
|
||||
var lastValue = property[property.length - 1];
|
||||
lastValue[0] = lastValue[0]
|
||||
.substring(0, lastValue[0].indexOf(hackType == 'backslash' ? BACKSLASH_HACK : BANG_HACK))
|
||||
.trim();
|
||||
|
||||
if (lastValue[0].length === 0)
|
||||
property.pop();
|
||||
}
|
||||
|
||||
function wrapSingle(property) {
|
||||
var _isImportant = isImportant(property);
|
||||
if (_isImportant)
|
||||
stripImportant(property);
|
||||
|
||||
var _hackType = hackType(property);
|
||||
if (_hackType == 'star' || _hackType == 'underscore')
|
||||
stripPrefixHack(property);
|
||||
else if (_hackType == 'backslash' || _hackType == 'bang')
|
||||
stripSuffixHack(property, _hackType);
|
||||
|
||||
var isVariable = property[0][0].indexOf('--') === 0;
|
||||
|
||||
return {
|
||||
block: isVariable && property[1] && Array.isArray(property[1][0][0]),
|
||||
components: [],
|
||||
dirty: false,
|
||||
hack: _hackType,
|
||||
important: _isImportant,
|
||||
name: property[0][0],
|
||||
multiplex: property.length > 2 ? isMultiplex(property) : false,
|
||||
position: 0,
|
||||
shorthand: false,
|
||||
unused: property.length < 2,
|
||||
value: property.slice(1),
|
||||
variable: isVariable
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
all: wrapAll,
|
||||
single: wrapSingle
|
||||
};
|
||||
Reference in New Issue
Block a user