import e from"../../../../../_virtual/index20.mjs";import{isRule as s,isRoot as r,isAtRule as t,isDeclaration as o}from"../../utils/typeGuards.mjs";import{isString as i,isRegExp as l,isNumber as n}from"../../utils/validateTypes.mjs";import u from"../../utils/hasBlock.mjs";import a from"../../utils/isStandardSyntaxRule.mjs";import m from"../../utils/optionsMatches.mjs";import p from"../../utils/report.mjs";import c from"../../utils/ruleMessages.mjs";import g from"../../utils/validateOptions.mjs";const f="max-nesting-depth",d=c(f,{expected:e=>`Expected nesting depth to be no more than ${e}`}),R=(c,R)=>{const v=e=>t(e)&&m(R,"ignoreAtRules",e.name);return(e,r)=>{function t(e){if(v(e))return;if(s(t=e)&&m(R,"ignoreRules",t.selector))return;var t;if(!u(e))return;if(s(e)&&!a(e))return;h(e,0)>c&&p({ruleName:f,result:r,node:e,message:d.expected,messageArgs:[c]})}g(r,f,{actual:c,possible:[n]},{optional:!0,actual:R,possible:{ignore:["blockless-at-rules","pseudo-classes"],ignoreAtRules:[i,l],ignoreRules:[i,l],ignorePseudoClasses:[i,l]}})&&(e.walkRules(t),e.walkAtRules(t))};function h(i,l){const n=i.parent;if(!n)return 0;if(v(n))return 0;if(r(n)||t(n)&&n.parent&&r(n.parent))return l;return m(R,"ignore","blockless-at-rules")&&t(i)&&i.every(e=>!o(e))||m(R,"ignore","pseudo-classes")&&s(i)&&(a=i.selector,e().processSync(a,{lossless:!1}).split(",").filter(e=>!m(R,"ignoreRules",e)).every(e=>j(e)))||s(i)&&(u=i.selectors,R&&(R.ignorePseudoClasses||R.ignoreRules)&&u.every(e=>{if(R.ignoreRules&&m(R,"ignoreRules",e))return!0;if(!R.ignorePseudoClasses)return!1;const s=j(e);return!!s&&m(R,"ignorePseudoClasses",s)}))?h(n,l):h(n,l+1);var u,a}};function j(e){return e.startsWith("&:")&&":"!==e[2]?e.slice(2):void 0}R.ruleName=f,R.messages=d,R.meta={url:"https://stylelint.io/user-guide/rules/max-nesting-depth"};export{R as default};