format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -23,10 +23,13 @@ function cloneAndMergeSelectors(propertyA, propertyB) {
function restructure(tokens, context) {
var options = context.options;
var mergeablePseudoClasses = options.compatibility.selectors.mergeablePseudoClasses;
var mergeablePseudoElements = options.compatibility.selectors.mergeablePseudoElements;
var mergeablePseudoClasses =
options.compatibility.selectors.mergeablePseudoClasses;
var mergeablePseudoElements =
options.compatibility.selectors.mergeablePseudoElements;
var mergeLimit = options.compatibility.selectors.mergeLimit;
var multiplePseudoMerging = options.compatibility.selectors.multiplePseudoMerging;
var multiplePseudoMerging =
options.compatibility.selectors.multiplePseudoMerging;
var specificityCache = context.cache.specificity;
var movableTokens = {};
var movedProperties = [];
@ -40,7 +43,10 @@ function restructure(tokens, context) {
var fit = allFits[i][0];
var id = addToCache(movedProperty, fit);
if (multiPropertyMoveCache[id].length > 1 && processMultiPropertyMove(position, multiPropertyMoveCache[id])) {
if (
multiPropertyMoveCache[id].length > 1 &&
processMultiPropertyMove(position, multiPropertyMoveCache[id])
) {
removeAllMatchingFromCache(id);
break;
}
@ -87,18 +93,26 @@ function restructure(tokens, context) {
var mergeableTokens = [];
for (var i = sourceTokens.length - 1; i >= 0; i--) {
if (!isMergeable(serializeRules(sourceTokens[i][1]), mergeablePseudoClasses, mergeablePseudoElements, multiplePseudoMerging)) {
if (
!isMergeable(
serializeRules(sourceTokens[i][1]),
mergeablePseudoClasses,
mergeablePseudoElements,
multiplePseudoMerging
)
) {
continue;
}
mergeableTokens.unshift(sourceTokens[i]);
if (sourceTokens[i][2].length > 0 && uniqueTokensWithBody.indexOf(sourceTokens[i]) == -1)
if (
sourceTokens[i][2].length > 0 &&
uniqueTokensWithBody.indexOf(sourceTokens[i]) == -1
)
uniqueTokensWithBody.push(sourceTokens[i]);
}
return uniqueTokensWithBody.length > 1 ?
mergeableTokens :
[];
return uniqueTokensWithBody.length > 1 ? mergeableTokens : [];
}
function shortenIfPossible(position, movedProperty) {
@ -110,15 +124,14 @@ function restructure(tokens, context) {
var qualifiedTokens = [];
var mergeableTokens = tokensToMerge(movableTokens[key]);
if (mergeableTokens.length < 2)
return;
if (mergeableTokens.length < 2) return;
var allFits = findAllFits(mergeableTokens, valueSize, 1);
var bestFit = allFits[0];
if (bestFit[1] > 0)
return sendToMultiPropertyMoveCache(position, movedProperty, allFits);
for (var i = bestFit[0].length - 1; i >=0; i--) {
for (var i = bestFit[0].length - 1; i >= 0; i--) {
allSelectors = bestFit[0][i][1].concat(allSelectors);
qualifiedTokens.unshift(bestFit[0][i]);
}
@ -128,21 +141,42 @@ function restructure(tokens, context) {
}
function fitSorter(fit1, fit2) {
return fit1[1] > fit2[1] ? 1 : (fit1[1] == fit2[1] ? 0 : -1);
return (
fit1[1] > fit2[1] ? 1
: fit1[1] == fit2[1] ? 0
: -1
);
}
function findAllFits(mergeableTokens, propertySize, propertiesCount) {
var combinations = allCombinations(mergeableTokens, propertySize, propertiesCount, maxCombinationsLevel - 1);
var combinations = allCombinations(
mergeableTokens,
propertySize,
propertiesCount,
maxCombinationsLevel - 1
);
return combinations.sort(fitSorter);
}
function allCombinations(tokensVariant, propertySize, propertiesCount, level) {
var differenceVariants = [[tokensVariant, sizeDifference(tokensVariant, propertySize, propertiesCount)]];
function allCombinations(
tokensVariant,
propertySize,
propertiesCount,
level
) {
var differenceVariants = [
[
tokensVariant,
sizeDifference(tokensVariant, propertySize, propertiesCount),
],
];
if (tokensVariant.length > 2 && level > 0) {
for (var i = tokensVariant.length - 1; i >= 0; i--) {
var subVariant = Array.prototype.slice.call(tokensVariant, 0);
subVariant.splice(i, 1);
differenceVariants = differenceVariants.concat(allCombinations(subVariant, propertySize, propertiesCount, level - 1));
differenceVariants = differenceVariants.concat(
allCombinations(subVariant, propertySize, propertiesCount, level - 1)
);
}
}
@ -152,12 +186,20 @@ function restructure(tokens, context) {
function sizeDifference(tokensVariant, propertySize, propertiesCount) {
var allSelectorsSize = 0;
for (var i = tokensVariant.length - 1; i >= 0; i--) {
allSelectorsSize += tokensVariant[i][2].length > propertiesCount ? serializeRules(tokensVariant[i][1]).length : -1;
allSelectorsSize +=
tokensVariant[i][2].length > propertiesCount ?
serializeRules(tokensVariant[i][1]).length
: -1;
}
return allSelectorsSize - (tokensVariant.length - 1) * propertySize + 1;
}
function dropAsNewTokenAt(position, properties, allSelectors, mergeableTokens) {
function dropAsNewTokenAt(
position,
properties,
allSelectors,
mergeableTokens
) {
var i, j, k, m;
var allProperties = [];
@ -173,7 +215,10 @@ function restructure(tokens, context) {
var mergeablePropertyName = mergeableProperty[1][1];
var propertyName = property[0];
var propertyBody = property[4];
if (mergeablePropertyName == propertyName && serializeBody([mergeableProperty]) == propertyBody) {
if (
mergeablePropertyName == propertyName &&
serializeBody([mergeableProperty]) == propertyBody
) {
mergeableToken[2].splice(j, 1);
break;
}
@ -206,28 +251,27 @@ function restructure(tokens, context) {
var j, k;
var mergeableTokens = tokensToMerge(movableTokens[key]);
if (mergeableTokens.length < 2)
return;
if (mergeableTokens.length < 2) return;
movableLoop:
for (var value in movableTokens) {
movableLoop: for (var value in movableTokens) {
var tokensList = movableTokens[value];
for (j = mergeableTokens.length - 1; j >= 0; j--) {
if (tokensList.indexOf(mergeableTokens[j]) == -1)
continue movableLoop;
if (tokensList.indexOf(mergeableTokens[j]) == -1) continue movableLoop;
}
candidates.push(value);
}
if (candidates.length < 2)
return false;
if (candidates.length < 2) return false;
for (j = candidates.length - 1; j >= 0; j--) {
for (k = movedProperties.length - 1; k >= 0; k--) {
if (movedProperties[k][4] == candidates[j]) {
propertiesAndMergableTokens.unshift([movedProperties[k], mergeableTokens]);
propertiesAndMergableTokens.unshift([
movedProperties[k],
mergeableTokens,
]);
break;
}
}
@ -251,8 +295,7 @@ function restructure(tokens, context) {
var mergeableTokens = propertiesAndMergableTokens[0][1];
var bestFit = findAllFits(mergeableTokens, valueSize, properties.length)[0];
if (bestFit[1] > 0)
return false;
if (bestFit[1] > 0) return false;
var allSelectors = [];
var qualifiedTokens = [];
@ -277,11 +320,14 @@ function restructure(tokens, context) {
return true;
}
function boundToAnotherPropertyInCurrrentToken(property, movedProperty, token) {
function boundToAnotherPropertyInCurrrentToken(
property,
movedProperty,
token
) {
var propertyName = property[0];
var movedPropertyName = movedProperty[0];
if (propertyName != movedPropertyName)
return false;
if (propertyName != movedPropertyName) return false;
var key = movedProperty[4];
var toMove = movableTokens[key];
@ -325,8 +371,17 @@ function restructure(tokens, context) {
for (k = 0; k < movedCount; k++) {
var movedProperty = movedProperties[k];
if (movedToBeDropped.indexOf(k) == -1 && (!canReorderSingle(property, movedProperty, specificityCache) && !boundToAnotherPropertyInCurrrentToken(property, movedProperty, token) ||
movableTokens[movedProperty[4]] && movableTokens[movedProperty[4]].length === mergeLimit)) {
if (
movedToBeDropped.indexOf(k) == -1 &&
((!canReorderSingle(property, movedProperty, specificityCache) &&
!boundToAnotherPropertyInCurrrentToken(
property,
movedProperty,
token
)) ||
(movableTokens[movedProperty[4]] &&
movableTokens[movedProperty[4]].length === mergeLimit))
) {
dropPropertiesAt(i + 1, movedProperty, token);
if (movedToBeDropped.indexOf(k) == -1) {
@ -336,7 +391,8 @@ function restructure(tokens, context) {
}
if (!movedSameProperty) {
movedSameProperty = property[0] == movedProperty[0] && property[1] == movedProperty[1];
movedSameProperty =
property[0] == movedProperty[0] && property[1] == movedProperty[1];
if (movedSameProperty) {
samePropertyAt = k;
@ -344,12 +400,15 @@ function restructure(tokens, context) {
}
}
if (!isRule || unmovableInCurrentToken.indexOf(j) > -1)
continue;
if (!isRule || unmovableInCurrentToken.indexOf(j) > -1) continue;
var key = property[4];
if (movedSameProperty && movedProperties[samePropertyAt][5].length + property[5].length > mergeLimit) {
if (
movedSameProperty &&
movedProperties[samePropertyAt][5].length + property[5].length >
mergeLimit
) {
dropPropertiesAt(i + 1, movedProperties[samePropertyAt]);
movedProperties.splice(samePropertyAt, 1);
movableTokens[key] = [token];
@ -360,7 +419,10 @@ function restructure(tokens, context) {
}
if (movedSameProperty) {
movedProperties[samePropertyAt] = cloneAndMergeSelectors(movedProperties[samePropertyAt], property);
movedProperties[samePropertyAt] = cloneAndMergeSelectors(
movedProperties[samePropertyAt],
property
);
} else {
movedProperties.push(property);
}
@ -373,12 +435,20 @@ function restructure(tokens, context) {
}
}
var position = tokens[0] && tokens[0][0] == Token.AT_RULE && tokens[0][1].indexOf('@charset') === 0 ? 1 : 0;
var position =
(
tokens[0] &&
tokens[0][0] == Token.AT_RULE &&
tokens[0][1].indexOf('@charset') === 0
) ?
1
: 0;
for (; position < tokens.length - 1; position++) {
var isImportRule = tokens[position][0] === Token.AT_RULE && tokens[position][1].indexOf('@import') === 0;
var isImportRule =
tokens[position][0] === Token.AT_RULE &&
tokens[position][1].indexOf('@import') === 0;
var isComment = tokens[position][0] === Token.COMMENT;
if (!(isImportRule || isComment))
break;
if (!(isImportRule || isComment)) break;
}
for (i = 0; i < movedProperties.length; i++) {