1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-04 04:40:05 +02:00

update packages to latest version

This commit is contained in:
s2
2022-08-20 18:51:33 +02:00
parent 09663a35a5
commit 806ebf9a57
4513 changed files with 366205 additions and 92512 deletions

View File

@@ -7,7 +7,7 @@ function findComponentIn(shorthand, longhand) {
}
function nameComparator(to) {
return function (property) {
return function(property) {
return to.name === property.name;
};
}
@@ -33,8 +33,6 @@ function findInSubComponents(shorthand, comparator) {
return longhandMatch;
}
}
return;
}
module.exports = findComponentIn;

View File

@@ -1,7 +1,6 @@
function hasInherit(property) {
for (var i = property.value.length - 1; i >= 0; i--) {
if (property.value[i][1] == 'inherit')
return true;
if (property.value[i][1] == 'inherit') { return true; }
}
return false;

View File

@@ -1,7 +1,6 @@
function hasUnset(property) {
for (var i = property.value.length - 1; i >= 0; i--) {
if (property.value[i][1] == 'unset')
return true;
if (property.value[i][1] == 'unset') { return true; }
}
return false;

View File

@@ -1,8 +1,8 @@
var configuration = require('../../configuration');
function isComponentOf(property1, property2, shallow) {
return isDirectComponentOf(property1, property2) ||
!shallow && !!configuration[property1.name].shorthandComponents && isSubComponentOf(property1, property2);
return isDirectComponentOf(property1, property2)
|| !shallow && !!configuration[property1.name].shorthandComponents && isSubComponentOf(property1, property2);
}
function isDirectComponentOf(property1, property2) {
@@ -14,7 +14,7 @@ function isDirectComponentOf(property1, property2) {
function isSubComponentOf(property1, property2) {
return property1
.components
.some(function (component) {
.some(function(component) {
return isDirectComponentOf(component, property2);
});
}

View File

@@ -336,9 +336,8 @@ function inferComponentValue(components, propertyName) {
if ('oppositeTo' in descriptor) {
return components[descriptor.oppositeTo].value;
} else {
return [[Token.PROPERTY_VALUE, descriptor.defaultValue]];
}
return [[Token.PROPERTY_VALUE, descriptor.defaultValue]];
}
function joinMetadata(components, at) {
@@ -367,11 +366,10 @@ function metadataSorter(metadata1, metadata2) {
if (line1 < line2) {
return -1;
} else if (line1 === line2) {
} if (line1 === line2) {
return column1 < column2 ? -1 : 1;
} else {
return 1;
}
return 1;
}
function buildSequenceWithInheritShorthand(components, shorthandName, validator) {
@@ -481,9 +479,8 @@ function inferInsertAtFrom(properties, candidateComponents, shorthandName) {
if (shorthandName == 'border' && traversesVia(properties.slice(firstCandidatePosition, lastCandidatePosition), 'border-image')) {
return firstCandidatePosition;
} else {
return lastCandidatePosition;
}
return lastCandidatePosition;
}
function traversesVia(properties, propertyName) {

View File

@@ -59,19 +59,20 @@ function overrideSimple(property, by) {
}
function override(property, by) {
if (by.multiplex)
if (by.multiplex) {
overrideByMultiplex(property, by);
else if (property.multiplex)
} else if (property.multiplex) {
overrideIntoMultiplex(property, by);
else
} 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);
override(property.components[i], by.components[i]);
}
}
@@ -101,9 +102,9 @@ function turnShorthandValueIntoMultiplex(property, size) {
function turnLonghandValueIntoMultiplex(property, size) {
var descriptor = configuration[property.name];
var withRealValue = descriptor.intoMultiplexMode == 'real';
var withValue = descriptor.intoMultiplexMode == 'real' ?
property.value.slice(0) :
(descriptor.intoMultiplexMode == 'placeholder' ? descriptor.placeholderValue : descriptor.defaultValue);
var withValue = descriptor.intoMultiplexMode == 'real'
? property.value.slice(0)
: (descriptor.intoMultiplexMode == 'placeholder' ? descriptor.placeholderValue : descriptor.defaultValue);
var i = multiplexSize(property);
var j;
var m = withValue.length;
@@ -125,8 +126,7 @@ function multiplexSize(component) {
var size = 0;
for (var i = 0, l = component.value.length; i < l; i++) {
if (component.value[i][1] == Marker.COMMA)
size++;
if (component.value[i][1] == Marker.COMMA) { size++; }
}
return size + 1;
@@ -147,10 +147,8 @@ function moreSameShorthands(properties, startAt, name) {
var count = 0;
for (var i = startAt; i >= 0; i--) {
if (properties[i].name == name && !properties[i].unused)
count++;
if (count > 1)
break;
if (properties[i].name == name && !properties[i].unused) { count++; }
if (count > 1) { break; }
}
return count > 1;
@@ -158,9 +156,8 @@ function moreSameShorthands(properties, startAt, name) {
function overridingFunction(shorthand, validator) {
for (var i = 0, l = shorthand.components.length; i < l; i++) {
if (!anyValue(validator.isUrl, shorthand.components[i]) && anyValue(validator.isFunction, shorthand.components[i])) {
return true;
}
if (!anyValue(validator.isUrl, shorthand.components[i])
&& anyValue(validator.isFunction, shorthand.components[i])) { return true; }
}
return false;
@@ -168,19 +165,16 @@ function overridingFunction(shorthand, validator) {
function anyValue(fn, property) {
for (var i = 0, l = property.value.length; i < l; i++) {
if (property.value[i][1] == Marker.COMMA)
continue;
if (property.value[i][1] == Marker.COMMA) { continue; }
if (fn(property.value[i][1]))
return true;
if (fn(property.value[i][1])) { return true; }
}
return false;
}
function wouldResultInLongerValue(left, right) {
if (!left.multiplex && !right.multiplex || left.multiplex && right.multiplex)
return false;
if (!left.multiplex && !right.multiplex || left.multiplex && right.multiplex) { return false; }
var multiplex = left.multiplex ? left : right;
var simple = left.multiplex ? right : left;
@@ -215,19 +209,18 @@ function isCompactable(property) {
}
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);
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][1] == 'none')
return true;
if (layers[i].length == 1 && layers[i][0][1] == 'none') { return true; }
}
return false;
@@ -262,11 +255,9 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
for (i = properties.length - 1; i >= 0; i--) {
right = properties[i];
if (!isCompactable(right))
continue;
if (!isCompactable(right)) { continue; }
if (right.block)
continue;
if (right.block) { continue; }
mayOverride = configuration[right.name].canOverride || sameValue;
@@ -274,43 +265,32 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
for (j = i - 1; j >= 0; j--) {
left = properties[j];
if (!isCompactable(left))
continue;
if (!isCompactable(left)) { continue; }
if (left.block)
continue;
if (left.block) { continue; }
if (left.dynamic || right.dynamic)
continue;
if (left.dynamic || right.dynamic) { continue; }
if (left.unused || right.unused)
continue;
if (left.unused || right.unused) { continue; }
if (left.hack && !right.hack && !right.important || !left.hack && !left.important && right.hack)
continue;
if (left.hack && !right.hack && !right.important || !left.hack && !left.important && right.hack) { continue; }
if (left.important == right.important && left.hack[0] != right.hack[0])
continue;
if (left.important == right.important && left.hack[0] != right.hack[0]) { continue; }
if (left.important == right.important && (left.hack[0] != right.hack[0] || (left.hack[1] && left.hack[1] != right.hack[1])))
continue;
if (left.important == right.important
&& (left.hack[0] != right.hack[0] || (left.hack[1] && left.hack[1] != right.hack[1]))) { continue; }
if (hasInherit(right))
continue;
if (hasInherit(right)) { continue; }
if (noneOverrideHack(left, right))
continue;
if (noneOverrideHack(left, right)) { continue; }
if (right.shorthand && isComponentOf(right, left)) {
// maybe `left` can be overridden by `right` which is a shorthand?
if (!right.important && left.important)
continue;
if (!right.important && left.important) { continue; }
if (!sameVendorPrefixesIn([left], right.components))
continue;
if (!sameVendorPrefixesIn([left], right.components)) { continue; }
if (!anyValue(validator.isFunction, left) && overridingFunction(right, validator))
continue;
if (!anyValue(validator.isFunction, left) && overridingFunction(right, validator)) { continue; }
if (!isMergeableShorthand(right)) {
left.unused = true;
@@ -336,9 +316,9 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
continue;
}
overriddenComponents = left.shorthand ?
left.components:
[left];
overriddenComponents = left.shorthand
? left.components
: [left];
for (k = overriddenComponents.length - 1; k >= 0; k--) {
overriddenComponent = overriddenComponents[k];
@@ -353,8 +333,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
left.unused = true;
} else if (withMerging && left.shorthand && !right.shorthand && isComponentOf(left, right, true)) {
// maybe `right` can be pulled into `left` which is a shorthand?
if (right.important && !left.important)
continue;
if (right.important && !left.important) { continue; }
if (!right.important && left.important) {
right.unused = true;
@@ -362,40 +341,30 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
}
// Pending more clever algorithm in #527
if (moreSameShorthands(properties, i - 1, left.name))
continue;
if (moreSameShorthands(properties, i - 1, left.name)) { continue; }
if (overridingFunction(left, validator))
continue;
if (overridingFunction(left, validator)) { continue; }
if (!isMergeableShorthand(left))
continue;
if (!isMergeableShorthand(left)) { continue; }
if (hasUnset(left) || hasUnset(right))
continue;
if (hasUnset(left) || hasUnset(right)) { continue; }
component = findComponentIn(left, right);
if (everyValuesPair(mayOverride.bind(null, validator), component, right)) {
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 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 = configuration[right.name].nonMergeableValue === right.value[0][1];
if (disabledBackgroundMerging || nonMergeableValue)
continue;
if (disabledBackgroundMerging || nonMergeableValue) { continue; }
if (!compatibility.properties.merging && wouldBreakCompatibility(left, validator))
continue;
if (!compatibility.properties.merging && wouldBreakCompatibility(left, validator)) { continue; }
if (component.value[0][1] != right.value[0][1] && (hasInherit(left) || hasInherit(right)))
continue;
if (component.value[0][1] != right.value[0][1] && (hasInherit(left) || hasInherit(right))) { continue; }
if (wouldResultInLongerValue(left, right))
continue;
if (wouldResultInLongerValue(left, right)) { continue; }
if (!left.multiplex && right.multiplex)
turnIntoMultiplex(left, multiplexSize(right));
if (!left.multiplex && right.multiplex) { turnIntoMultiplex(left, multiplexSize(right)); }
override(component, right);
left.dirty = true;
@@ -403,8 +372,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
} else if (withMerging && left.shorthand && right.shorthand && left.name == right.name) {
// merge if all components can be merged
if (!left.multiplex && right.multiplex)
continue;
if (!left.multiplex && right.multiplex) { continue; }
if (!right.important && left.important) {
right.unused = true;
@@ -426,8 +394,9 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
var rightComponent = right.components[k];
mayOverride = configuration[leftComponent.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), leftComponent, rightComponent))
if (!everyValuesPair(mayOverride.bind(null, validator), leftComponent, rightComponent)) {
continue propertyLoop;
}
}
overrideShorthand(left, right);
@@ -435,13 +404,11 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
} else if (withMerging && 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;
if (!left.important && right.important) { continue; }
component = findComponentIn(left, right);
mayOverride = configuration[right.name].canOverride || sameValue;
if (!everyValuesPair(mayOverride.bind(null, validator), component, right))
continue;
if (!everyValuesPair(mayOverride.bind(null, validator), component, right)) { continue; }
if (left.important && !right.important) {
right.unused = true;
@@ -449,8 +416,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
}
var rightRestored = configuration[right.name].restore(right, configuration);
if (rightRestored.length > 1)
continue;
if (rightRestored.length > 1) { continue; }
component = findComponentIn(left, right);
override(component, right);
@@ -465,7 +431,7 @@ function overrideProperties(properties, withMerging, compatibility, validator) {
overridingComponent = right.components[k];
mayOverride = configuration[overridingComponent.name].canOverride || sameValue;
overridable = overridable && everyValuesPair(mayOverride.bind(null, validator), overriddenComponent, overridingComponent);
overridable = everyValuesPair(mayOverride.bind(null, validator), overriddenComponent, overridingComponent);
}
} else {
mayOverride = configuration[right.name].canOverride || sameValue;

View File

@@ -1,9 +1,9 @@
var configuration = require('../../configuration');
function overridesNonComponentShorthand(property1, property2) {
return property1.name in configuration &&
'overridesShorthands' in configuration[property1.name] &&
configuration[property1.name].overridesShorthands.indexOf(property2.name) > -1;
return property1.name in configuration
&& 'overridesShorthands' in configuration[property1.name]
&& configuration[property1.name].overridesShorthands.indexOf(property2.name) > -1;
}
module.exports = overridesNonComponentShorthand;

View File

@@ -36,10 +36,11 @@ function populateComponents(properties, validator, warnings) {
}
}
if (property.components.length > 0)
if (property.components.length > 0) {
property.multiplex = property.components[0].multiplex;
else
} else {
property.unused = true;
}
}
}
}
@@ -49,7 +50,12 @@ function onlyValueIsVariable(property, validator) {
}
function moreThanOneValueIsVariable(property, validator) {
return property.value.length > 1 && property.value.filter(function (value) { return validator.isVariable(value[1]); }).length > 1;
return property.value.length > 1
&& property.value.filter(
function(value) {
return validator.isVariable(value[1]);
}
).length > 1;
}
module.exports = populateComponents;