1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/csso/lib/restructure/prepare/specificity.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
module.exports = function specificity(simpleSelector) {
var A = 0;
var B = 0;
var C = 0;
simpleSelector.children.each(function walk(node) {
switch (node.type) {
case 'SelectorList':
case 'Selector':
node.children.each(walk);
break;
case 'IdSelector':
A++;
break;
case 'ClassSelector':
case 'AttributeSelector':
B++;
break;
case 'PseudoClassSelector':
switch (node.name.toLowerCase()) {
case 'not':
node.children.each(walk);
break;
case 'before':
case 'after':
case 'first-line':
case 'first-letter':
C++;
break;
// TODO: support for :nth-*(.. of <SelectorList>), :matches(), :has()
default:
B++;
}
break;
case 'PseudoElementSelector':
C++;
break;
case 'TypeSelector':
// ignore universal selector
if (node.name.charAt(node.name.length - 1) !== '*') {
C++;
}
break;
}
});
return [A, B, C];
};