import{selectorSpecificity as e,compare as t}from"../../../../@csstools/selector-specificity/dist/index.mjs";import{isString as s,isRegExp as o,assertNumber as r}from"../../utils/validateTypes.mjs";import i from"../../utils/flattenNestedSelectorsForRule.mjs";import c from"../../utils/getStrippedSelectorSource.mjs";import a from"../../utils/isStandardSyntaxRule.mjs";import l from"../../utils/optionsMatches.mjs";import m from"../../utils/report.mjs";import n from"../../utils/ruleMessages.mjs";import u from"../../utils/validateOptions.mjs";const p="selector-max-specificity",d=n(p,{expected:(e,t)=>`Expected "${e}" to have a specificity no more than "${t}"`}),f=(n,f)=>(g,x)=>{if(!u(x,p,{actual:n,possible:[e=>s(e)&&/^\d+,\d+,\d+$/.test(e)]},{actual:f,possible:{ignoreSelectors:[s,o]},optional:!0}))return;const S=e=>l(f,"ignoreSelectors",e),b=f?.ignoreSelectors?t=>{switch(t.type){case"attribute":case"class":case"id":case"tag":if(!S(t.toString()))return;return{a:0,b:0,c:0};case"pseudo":{if(!S(t.value.toLowerCase()))return;if(!t.nodes?.length)return{a:0,b:0,c:0};const s=e(t),o=e(t.clone({nodes:[]}));return{a:s.a-o.a,b:s.b-o.b,c:s.c-o.c}}}}:void 0,[j,y,h]=n.split(",").map(e=>Number.parseFloat(e));r(j),r(y),r(h);const v={a:j,b:y,c:h};g.walkRules(s=>{a(s)&&i(s,x).forEach(({selector:o,resolvedSelectors:r})=>{r.each(r=>{const i=e(r,{customSpecificity:b});if(t(i,v)>0){const{index:e,endIndex:t,selector:r}=c(o);m({ruleName:p,result:x,node:s,message:d.expected,messageArgs:[r,n],index:e,endIndex:t})}})})})};f.ruleName=p,f.messages=d,f.meta={url:"https://stylelint.io/user-guide/rules/selector-max-specificity"};export{f as default};