index.cjs 1.5 KB

1
  1. "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var s=e(require("postcss-selector-parser"));function t(e){if(!e)return{a:0,b:0,c:0};let n=0,c=0,o=0;if("universal"==e.type)return{a:0,b:0,c:0};if("id"===e.type)n+=1;else if("tag"===e.type)o+=1;else if("class"===e.type)c+=1;else if("attribute"===e.type)c+=1;else if(function(e){return s.default.isPseudoElement(e)}(e))o+=1;else if(s.default.isPseudoClass(e))switch(e.value.toLowerCase()){case":-moz-any":case":-webkit-any":case":any":case":has":case":is":case":matches":case":not":if(e.nodes&&e.nodes.length>0){const s=a(e.nodes);n+=s.a,c+=s.b,o+=s.c}break;case":where":break;case":nth-child":case":nth-last-child":if(c+=1,e.nodes&&e.nodes.length>0){const t=e.nodes[0].nodes.findIndex((e=>"tag"===e.type&&"of"===e.value.toLowerCase()));if(t>-1){const r=[s.default.selector({nodes:e.nodes[0].nodes.slice(t+1),value:""})];e.nodes.length>1&&r.push(...e.nodes.slice(1));const l=a(r);n+=l.a,c+=l.b,o+=l.c}}break;case":local":case":global":e.nodes&&e.nodes.length>0&&e.nodes.forEach((e=>{const s=t(e);n+=s.a,c+=s.b,o+=s.c}));break;default:c+=1}else s.default.isContainer(e)&&e.nodes.length>0&&e.nodes.forEach((e=>{const s=t(e);n+=s.a,c+=s.b,o+=s.c}));return{a:n,b:c,c:o}}function a(e){let s={a:0,b:0,c:0};return e.forEach((e=>{const a=t(e);a.a>s.a?s=a:a.a<s.a||(a.b>s.b?s=a:a.b<s.b||a.c>s.c&&(s=a))})),s}exports.compare=function(e,s){return e.a===s.a?e.b===s.b?e.c-s.c:e.b-s.b:e.a-s.a},exports.selectorSpecificity=t;