mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
update node modules
This commit is contained in:
96
node_modules/clean-css/lib/optimizer/level-2/properties/merge-into-shorthands.js
generated
vendored
96
node_modules/clean-css/lib/optimizer/level-2/properties/merge-into-shorthands.js
generated
vendored
@@ -1,9 +1,10 @@
|
||||
var everyValuesPair = require('./every-values-pair');
|
||||
var hasInherit = require('./has-inherit');
|
||||
var hasSameValues = require('./has-same-values');
|
||||
var populateComponents = require('./populate-components');
|
||||
|
||||
var compactable = require('../compactable');
|
||||
var deepClone = require('../clone').deep;
|
||||
var configuration = require('../../configuration');
|
||||
var deepClone = require('../../clone').deep;
|
||||
var restoreWithComponents = require('../restore-with-components');
|
||||
|
||||
var restoreFromOptimizing = require('../../restore-from-optimizing');
|
||||
@@ -27,7 +28,11 @@ function mergeIntoShorthands(properties, validator) {
|
||||
|
||||
for (i = 0, l = properties.length; i < l; i++) {
|
||||
property = properties[i];
|
||||
descriptor = compactable[property.name];
|
||||
descriptor = configuration[property.name];
|
||||
|
||||
if (property.dynamic) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.unused) {
|
||||
continue;
|
||||
@@ -41,6 +46,10 @@ function mergeIntoShorthands(properties, validator) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (descriptor && descriptor.singleTypeComponents && !hasSameValues(property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
invalidateOrCompact(properties, i, candidates, validator);
|
||||
|
||||
if (descriptor && descriptor.componentOf) {
|
||||
@@ -61,13 +70,15 @@ function invalidateOrCompact(properties, position, candidates, validator) {
|
||||
var shorthandName;
|
||||
var shorthandDescriptor;
|
||||
var candidateComponents;
|
||||
var replacedCandidates = [];
|
||||
var i;
|
||||
|
||||
for (shorthandName in candidates) {
|
||||
if (undefined !== invalidatedBy && shorthandName == invalidatedBy.name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
shorthandDescriptor = compactable[shorthandName];
|
||||
shorthandDescriptor = configuration[shorthandName];
|
||||
candidateComponents = candidates[shorthandName];
|
||||
if (invalidatedBy && invalidates(candidates, shorthandName, invalidatedBy)) {
|
||||
delete candidates[shorthandName];
|
||||
@@ -95,12 +106,18 @@ function invalidateOrCompact(properties, position, candidates, validator) {
|
||||
} else {
|
||||
replaceWithShorthand(properties, candidateComponents, shorthandName, validator);
|
||||
}
|
||||
|
||||
replacedCandidates.push(shorthandName);
|
||||
}
|
||||
|
||||
for (i = replacedCandidates.length - 1; i >= 0; i--) {
|
||||
delete candidates[replacedCandidates[i]];
|
||||
}
|
||||
}
|
||||
|
||||
function invalidates(candidates, shorthandName, invalidatedBy) {
|
||||
var shorthandDescriptor = compactable[shorthandName];
|
||||
var invalidatedByDescriptor = compactable[invalidatedBy.name];
|
||||
var shorthandDescriptor = configuration[shorthandName];
|
||||
var invalidatedByDescriptor = configuration[invalidatedBy.name];
|
||||
var componentName;
|
||||
|
||||
if ('overridesShorthands' in shorthandDescriptor && shorthandDescriptor.overridesShorthands.indexOf(invalidatedBy.name) > -1) {
|
||||
@@ -134,7 +151,7 @@ function mixedImportance(components) {
|
||||
}
|
||||
|
||||
function overridable(components, shorthandName, validator) {
|
||||
var descriptor = compactable[shorthandName];
|
||||
var descriptor = configuration[shorthandName];
|
||||
var newValuePlaceholder = [
|
||||
Token.PROPERTY,
|
||||
[Token.PROPERTY_NAME, shorthandName],
|
||||
@@ -149,7 +166,7 @@ function overridable(components, shorthandName, validator) {
|
||||
|
||||
for (i = 0, l = descriptor.components.length; i < l; i++) {
|
||||
component = components[descriptor.components[i]];
|
||||
mayOverride = compactable[component.name].canOverride;
|
||||
mayOverride = configuration[component.name].canOverride || sameValue;
|
||||
|
||||
if (!everyValuesPair(mayOverride.bind(null, validator), newProperty.components[i], component)) {
|
||||
return false;
|
||||
@@ -159,6 +176,10 @@ function overridable(components, shorthandName, validator) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function sameValue(_validator, value1, value2) {
|
||||
return value1 === value2;
|
||||
}
|
||||
|
||||
function mergeable(components) {
|
||||
var lastCount = null;
|
||||
var currentCount;
|
||||
@@ -169,14 +190,14 @@ function mergeable(components) {
|
||||
|
||||
for (componentName in components) {
|
||||
component = components[componentName];
|
||||
descriptor = compactable[componentName];
|
||||
descriptor = configuration[componentName];
|
||||
|
||||
if (!('restore' in descriptor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
restoreFromOptimizing([component.all[component.position]], restoreWithComponents);
|
||||
values = descriptor.restore(component, compactable);
|
||||
values = descriptor.restore(component, configuration);
|
||||
|
||||
currentCount = values.length;
|
||||
|
||||
@@ -217,24 +238,30 @@ function replaceWithInheritBestFit(properties, candidateComponents, shorthandNam
|
||||
var newTokensSequence = isLonghandsShorter ? longhandTokensSequence : shorthandTokensSequence;
|
||||
var newProperty = isLonghandsShorter ? viaLonghands[1] : viaShorthand[1];
|
||||
var newComponents = isLonghandsShorter ? viaLonghands[2] : viaShorthand[2];
|
||||
var all = candidateComponents[Object.keys(candidateComponents)[0]].all;
|
||||
var lastComponent = candidateComponents[Object.keys(candidateComponents).pop()];
|
||||
var all = lastComponent.all;
|
||||
var insertAt = lastComponent.position;
|
||||
var componentName;
|
||||
var oldComponent;
|
||||
var newComponent;
|
||||
var newToken;
|
||||
|
||||
newProperty.position = all.length;
|
||||
newProperty.position = insertAt;
|
||||
newProperty.shorthand = true;
|
||||
newProperty.important = lastComponent.important;
|
||||
newProperty.multiplex = false;
|
||||
newProperty.dirty = true;
|
||||
newProperty.all = all;
|
||||
newProperty.all.push(newTokensSequence[0]);
|
||||
newProperty.all[insertAt] = newTokensSequence[0];
|
||||
|
||||
properties.push(newProperty);
|
||||
properties.splice(insertAt, 1, newProperty);
|
||||
|
||||
for (componentName in candidateComponents) {
|
||||
oldComponent = candidateComponents[componentName];
|
||||
oldComponent.unused = true;
|
||||
|
||||
newProperty.multiplex = newProperty.multiplex || oldComponent.multiplex;
|
||||
|
||||
if (oldComponent.name in newComponents) {
|
||||
newComponent = newComponents[oldComponent.name];
|
||||
newToken = findTokenIn(newTokensSequence, componentName);
|
||||
@@ -252,7 +279,7 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
|
||||
var tokensSequence = [];
|
||||
var inheritComponents = {};
|
||||
var nonInheritComponents = {};
|
||||
var descriptor = compactable[shorthandName];
|
||||
var descriptor = configuration[shorthandName];
|
||||
var shorthandToken = [
|
||||
Token.PROPERTY,
|
||||
[Token.PROPERTY_NAME, shorthandName],
|
||||
@@ -289,6 +316,8 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
|
||||
}
|
||||
}
|
||||
|
||||
newProperty.important = components[Object.keys(components).pop()].important;
|
||||
|
||||
nameMetadata = joinMetadata(nonInheritComponents, 1);
|
||||
shorthandToken[1].push(nameMetadata);
|
||||
|
||||
@@ -303,7 +332,7 @@ function buildSequenceWithInheritLonghands(components, shorthandName, validator)
|
||||
}
|
||||
|
||||
function inferComponentValue(components, propertyName) {
|
||||
var descriptor = compactable[propertyName];
|
||||
var descriptor = configuration[propertyName];
|
||||
|
||||
if ('oppositeTo' in descriptor) {
|
||||
return components[descriptor.oppositeTo].value;
|
||||
@@ -349,7 +378,7 @@ function buildSequenceWithInheritShorthand(components, shorthandName, validator)
|
||||
var tokensSequence = [];
|
||||
var inheritComponents = {};
|
||||
var nonInheritComponents = {};
|
||||
var descriptor = compactable[shorthandName];
|
||||
var descriptor = configuration[shorthandName];
|
||||
var shorthandToken = [
|
||||
Token.PROPERTY,
|
||||
[Token.PROPERTY_NAME, shorthandName],
|
||||
@@ -400,7 +429,7 @@ function findTokenIn(tokens, componentName) {
|
||||
}
|
||||
|
||||
function replaceWithShorthand(properties, candidateComponents, shorthandName, validator) {
|
||||
var descriptor = compactable[shorthandName];
|
||||
var descriptor = configuration[shorthandName];
|
||||
var nameMetadata;
|
||||
var valueMetadata;
|
||||
var newValuePlaceholder = [
|
||||
@@ -409,10 +438,12 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
|
||||
[Token.PROPERTY_VALUE, descriptor.defaultValue]
|
||||
];
|
||||
var all;
|
||||
var insertAt = inferInsertAtFrom(properties, candidateComponents, shorthandName);
|
||||
|
||||
var newProperty = wrapSingle(newValuePlaceholder);
|
||||
newProperty.shorthand = true;
|
||||
newProperty.dirty = true;
|
||||
newProperty.multiplex = false;
|
||||
|
||||
populateComponents([newProperty], validator, []);
|
||||
|
||||
@@ -421,6 +452,7 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
|
||||
|
||||
newProperty.components[i] = deepClone(component);
|
||||
newProperty.important = component.important;
|
||||
newProperty.multiplex = newProperty.multiplex || component.multiplex;
|
||||
|
||||
all = component.all;
|
||||
}
|
||||
@@ -435,11 +467,33 @@ function replaceWithShorthand(properties, candidateComponents, shorthandName, va
|
||||
valueMetadata = joinMetadata(candidateComponents, 2);
|
||||
newValuePlaceholder[2].push(valueMetadata);
|
||||
|
||||
newProperty.position = all.length;
|
||||
newProperty.position = insertAt;
|
||||
newProperty.all = all;
|
||||
newProperty.all.push(newValuePlaceholder);
|
||||
newProperty.all[insertAt] = newValuePlaceholder;
|
||||
|
||||
properties.push(newProperty);
|
||||
properties.splice(insertAt, 1, newProperty);
|
||||
}
|
||||
|
||||
function inferInsertAtFrom(properties, candidateComponents, shorthandName) {
|
||||
var candidateComponentNames = Object.keys(candidateComponents);
|
||||
var firstCandidatePosition = candidateComponents[candidateComponentNames[0]].position;
|
||||
var lastCandidatePosition = candidateComponents[candidateComponentNames[candidateComponentNames.length - 1]].position;
|
||||
|
||||
if (shorthandName == 'border' && traversesVia(properties.slice(firstCandidatePosition, lastCandidatePosition), 'border-image')) {
|
||||
return firstCandidatePosition;
|
||||
} else {
|
||||
return lastCandidatePosition;
|
||||
}
|
||||
}
|
||||
|
||||
function traversesVia(properties, propertyName) {
|
||||
for (var i = properties.length - 1; i >= 0; i--) {
|
||||
if (properties[i].name == propertyName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = mergeIntoShorthands;
|
||||
|
Reference in New Issue
Block a user