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

@ -4,70 +4,74 @@ const cssTree = require('css-tree');
const utils = require('./utils.cjs');
function cleanAtrule(node, item, list) {
if (node.block) {
// otherwise removed at-rule don't prevent @import for removal
if (this.stylesheet !== null) {
this.stylesheet.firstAtrulesAllowed = false;
}
if (utils.hasNoChildren(node.block)) {
list.remove(item);
return;
}
if (node.block) {
// otherwise removed at-rule don't prevent @import for removal
if (this.stylesheet !== null) {
this.stylesheet.firstAtrulesAllowed = false;
}
switch (node.name) {
case 'charset':
if (utils.hasNoChildren(node.prelude)) {
list.remove(item);
return;
}
// if there is any rule before @charset -> remove it
if (item.prev) {
list.remove(item);
return;
}
break;
case 'import':
if (this.stylesheet === null || !this.stylesheet.firstAtrulesAllowed) {
list.remove(item);
return;
}
// if there are some rules that not an @import or @charset before @import
// remove it
list.prevUntil(item.prev, function(rule) {
if (rule.type === 'Atrule') {
if (rule.name === 'import' || rule.name === 'charset') {
return;
}
}
this.root.firstAtrulesAllowed = false;
list.remove(item);
return true;
}, this);
break;
default: {
const name = cssTree.keyword(node.name).basename;
if (name === 'keyframes' ||
name === 'media' ||
name === 'supports') {
// drop at-rule with no prelude
if (utils.hasNoChildren(node.prelude) || utils.hasNoChildren(node.block)) {
list.remove(item);
}
}
}
if (utils.hasNoChildren(node.block)) {
list.remove(item);
return;
}
}
switch (node.name) {
case 'charset':
if (utils.hasNoChildren(node.prelude)) {
list.remove(item);
return;
}
// if there is any rule before @charset -> remove it
if (item.prev) {
list.remove(item);
return;
}
break;
case 'import':
if (this.stylesheet === null || !this.stylesheet.firstAtrulesAllowed) {
list.remove(item);
return;
}
// if there are some rules that not an @import or @charset before @import
// remove it
list.prevUntil(
item.prev,
function (rule) {
if (rule.type === 'Atrule') {
if (rule.name === 'import' || rule.name === 'charset') {
return;
}
}
this.root.firstAtrulesAllowed = false;
list.remove(item);
return true;
},
this
);
break;
default: {
const name = cssTree.keyword(node.name).basename;
if (name === 'keyframes' || name === 'media' || name === 'supports') {
// drop at-rule with no prelude
if (
utils.hasNoChildren(node.prelude) ||
utils.hasNoChildren(node.block)
) {
list.remove(item);
}
}
}
}
}
module.exports = cleanAtrule;

View File

@ -1,7 +1,7 @@
'use strict';
function cleanComment(data, item, list) {
list.remove(item);
list.remove(item);
}
module.exports = cleanComment;

View File

@ -3,16 +3,16 @@
const cssTree = require('css-tree');
function cleanDeclartion(node, item, list) {
if (node.value.children && node.value.children.isEmpty) {
list.remove(item);
return;
}
if (node.value.children && node.value.children.isEmpty) {
list.remove(item);
return;
}
if (cssTree.property(node.property).custom) {
if (/\S/.test(node.value.value)) {
node.value.value = node.value.value.trim();
}
if (cssTree.property(node.property).custom) {
if (/\S/.test(node.value.value)) {
node.value.value = node.value.value.trim();
}
}
}
module.exports = cleanDeclartion;

12
node_modules/csso/cjs/clean/Raw.cjs generated vendored
View File

@ -3,11 +3,13 @@
const utils = require('./utils.cjs');
function cleanRaw(node, item, list) {
// raw in stylesheet or block children
if (utils.isNodeChildrenList(this.stylesheet, list) ||
utils.isNodeChildrenList(this.block, list)) {
list.remove(item);
}
// raw in stylesheet or block children
if (
utils.isNodeChildrenList(this.stylesheet, list) ||
utils.isNodeChildrenList(this.block, list)
) {
list.remove(item);
}
}
module.exports = cleanRaw;

188
node_modules/csso/cjs/clean/Rule.cjs generated vendored
View File

@ -7,98 +7,122 @@ const { hasOwnProperty } = Object.prototype;
const skipUsageFilteringAtrule = new Set(['keyframes']);
function cleanUnused(selectorList, usageData) {
selectorList.children.forEach((selector, item, list) => {
let shouldRemove = false;
selectorList.children.forEach((selector, item, list) => {
let shouldRemove = false;
cssTree.walk(selector, function(node) {
// ignore nodes in nested selectors
if (this.selector === null || this.selector === selectorList) {
switch (node.type) {
case 'SelectorList':
// TODO: remove toLowerCase when pseudo selectors will be normalized
// ignore selectors inside :not()
if (this.function === null || this.function.name.toLowerCase() !== 'not') {
if (cleanUnused(node, usageData)) {
shouldRemove = true;
}
}
break;
case 'ClassSelector':
if (usageData.whitelist !== null &&
usageData.whitelist.classes !== null &&
!hasOwnProperty.call(usageData.whitelist.classes, node.name)) {
shouldRemove = true;
}
if (usageData.blacklist !== null &&
usageData.blacklist.classes !== null &&
hasOwnProperty.call(usageData.blacklist.classes, node.name)) {
shouldRemove = true;
}
break;
case 'IdSelector':
if (usageData.whitelist !== null &&
usageData.whitelist.ids !== null &&
!hasOwnProperty.call(usageData.whitelist.ids, node.name)) {
shouldRemove = true;
}
if (usageData.blacklist !== null &&
usageData.blacklist.ids !== null &&
hasOwnProperty.call(usageData.blacklist.ids, node.name)) {
shouldRemove = true;
}
break;
case 'TypeSelector':
// TODO: remove toLowerCase when type selectors will be normalized
// ignore universal selectors
if (node.name.charAt(node.name.length - 1) !== '*') {
if (usageData.whitelist !== null &&
usageData.whitelist.tags !== null &&
!hasOwnProperty.call(usageData.whitelist.tags, node.name.toLowerCase())) {
shouldRemove = true;
}
if (usageData.blacklist !== null &&
usageData.blacklist.tags !== null &&
hasOwnProperty.call(usageData.blacklist.tags, node.name.toLowerCase())) {
shouldRemove = true;
}
}
break;
}
cssTree.walk(selector, function (node) {
// ignore nodes in nested selectors
if (this.selector === null || this.selector === selectorList) {
switch (node.type) {
case 'SelectorList':
// TODO: remove toLowerCase when pseudo selectors will be normalized
// ignore selectors inside :not()
if (
this.function === null ||
this.function.name.toLowerCase() !== 'not'
) {
if (cleanUnused(node, usageData)) {
shouldRemove = true;
}
}
});
break;
if (shouldRemove) {
list.remove(item);
case 'ClassSelector':
if (
usageData.whitelist !== null &&
usageData.whitelist.classes !== null &&
!hasOwnProperty.call(usageData.whitelist.classes, node.name)
) {
shouldRemove = true;
}
if (
usageData.blacklist !== null &&
usageData.blacklist.classes !== null &&
hasOwnProperty.call(usageData.blacklist.classes, node.name)
) {
shouldRemove = true;
}
break;
case 'IdSelector':
if (
usageData.whitelist !== null &&
usageData.whitelist.ids !== null &&
!hasOwnProperty.call(usageData.whitelist.ids, node.name)
) {
shouldRemove = true;
}
if (
usageData.blacklist !== null &&
usageData.blacklist.ids !== null &&
hasOwnProperty.call(usageData.blacklist.ids, node.name)
) {
shouldRemove = true;
}
break;
case 'TypeSelector':
// TODO: remove toLowerCase when type selectors will be normalized
// ignore universal selectors
if (node.name.charAt(node.name.length - 1) !== '*') {
if (
usageData.whitelist !== null &&
usageData.whitelist.tags !== null &&
!hasOwnProperty.call(
usageData.whitelist.tags,
node.name.toLowerCase()
)
) {
shouldRemove = true;
}
if (
usageData.blacklist !== null &&
usageData.blacklist.tags !== null &&
hasOwnProperty.call(
usageData.blacklist.tags,
node.name.toLowerCase()
)
) {
shouldRemove = true;
}
}
break;
}
}
});
return selectorList.children.isEmpty;
if (shouldRemove) {
list.remove(item);
}
});
return selectorList.children.isEmpty;
}
function cleanRule(node, item, list, options) {
if (utils.hasNoChildren(node.prelude) || utils.hasNoChildren(node.block)) {
list.remove(item);
return;
}
// avoid usage filtering for some at-rules
if (this.atrule && skipUsageFilteringAtrule.has(cssTree.keyword(this.atrule.name).basename)) {
return;
}
const { usage } = options;
if (usage && (usage.whitelist !== null || usage.blacklist !== null)) {
cleanUnused(node.prelude, usage);
if (utils.hasNoChildren(node.prelude)) {
list.remove(item);
return;
}
if (utils.hasNoChildren(node.prelude) || utils.hasNoChildren(node.block)) {
list.remove(item);
return;
}
// avoid usage filtering for some at-rules
if (
this.atrule &&
skipUsageFilteringAtrule.has(cssTree.keyword(this.atrule.name).basename)
) {
return;
}
const { usage } = options;
if (usage && (usage.whitelist !== null || usage.blacklist !== null)) {
cleanUnused(node.prelude, usage);
if (utils.hasNoChildren(node.prelude)) {
list.remove(item);
return;
}
}
}
module.exports = cleanRule;

View File

@ -2,22 +2,24 @@
// remove useless universal selector
function cleanTypeSelector(node, item, list) {
const name = item.data.name;
const name = item.data.name;
// check it's a non-namespaced universal selector
if (name !== '*') {
return;
}
// check it's a non-namespaced universal selector
if (name !== '*') {
return;
}
// remove when universal selector before other selectors
const nextType = item.next && item.next.data.type;
if (nextType === 'IdSelector' ||
nextType === 'ClassSelector' ||
nextType === 'AttributeSelector' ||
nextType === 'PseudoClassSelector' ||
nextType === 'PseudoElementSelector') {
list.remove(item);
}
// remove when universal selector before other selectors
const nextType = item.next && item.next.data.type;
if (
nextType === 'IdSelector' ||
nextType === 'ClassSelector' ||
nextType === 'AttributeSelector' ||
nextType === 'PseudoClassSelector' ||
nextType === 'PseudoElementSelector'
) {
list.remove(item);
}
}
module.exports = cleanTypeSelector;

View File

@ -1,7 +1,7 @@
'use strict';
function cleanWhitespace(node, item, list) {
list.remove(item);
list.remove(item);
}
module.exports = cleanWhitespace;

View File

@ -10,23 +10,23 @@ const TypeSelector = require('./TypeSelector.cjs');
const WhiteSpace = require('./WhiteSpace.cjs');
const handlers = {
Atrule,
Comment,
Declaration,
Raw,
Rule,
TypeSelector,
WhiteSpace
Atrule,
Comment,
Declaration,
Raw,
Rule,
TypeSelector,
WhiteSpace,
};
function clean(ast, options) {
cssTree.walk(ast, {
leave(node, item, list) {
if (handlers.hasOwnProperty(node.type)) {
handlers[node.type].call(this, node, item, list, options);
}
}
});
cssTree.walk(ast, {
leave(node, item, list) {
if (handlers.hasOwnProperty(node.type)) {
handlers[node.type].call(this, node, item, list, options);
}
},
});
}
module.exports = clean;

View File

@ -1,11 +1,11 @@
'use strict';
function hasNoChildren(node) {
return !node || !node.children || node.children.isEmpty;
return !node || !node.children || node.children.isEmpty;
}
function isNodeChildrenList(node, list) {
return node !== null && node.children === list;
return node !== null && node.children === list;
}
exports.hasNoChildren = hasNoChildren;