/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@mrhenry/stylelint-mrhenry-nesting@4.0.0/index.mjs
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import stylelint from"stylelint";import selectorParser from"postcss-selector-parser";import{compare,selectorSpecificity}from"@csstools/selector-specificity";const ruleName="@mrhenry/stylelint-mrhenry-nesting",messages=stylelint.utils.ruleMessages(ruleName,{rejectedAtRule:e=>`Nested at-rules with name "${e}" is not allowed.`,rejectedMustStartWithAmpersand:()=>'Nested selectors must start with "&".',rejectedMustEndWithPseudo:()=>"Nested selectors must end with a pseudo selectors.",rejectedNestingDepth:()=>"Nested rules must be limited to 1 level deep.",rejectedNestingSelectorIncorrectShape:()=>'Nested selectors must be compound selectors, starting with "&" and followed by a single pseudo selector.',rejectedMixedSpecificity:()=>"Each selector of a list in a nested context take the specificity of the most specific list item. This can lead to unexpected results."}),meta={url:"https://github.com/mrhenry/stylelint-mrhenry/tree/main/packages/nesting",fixable:!0},ruleFunction=(e,t)=>(s,r)=>{if(!stylelint.utils.validateOptions(r,ruleName,{actual:e,possible:[!0]}))return;if(!stylelint.utils.validateOptions(r,ruleName,{actual:t,possible:{ignoreAtRules:[isString,isRegExp]},optional:!0}))return;const n=t?.ignoreAtRules??[];s.walkAtRules((e=>{let t=e.name.toLowerCase();if("media"===t||"supports"===t||"container"===t||"scope"===t||"starting-style"===t)return;for(const e of n)if(e instanceof RegExp){if(e.test(t))return}else if(t===e)return;let s=0,l=e.parent;for(;l;){if("rule"===l.type){s++;break}l=l.parent}0!==s&&stylelint.utils.report({message:messages.rejectedAtRule(t),node:e,index:0,endIndex:e.name.length,result:r,ruleName:ruleName})})),s.walkRules((e=>{if(!(e.nodes&&e.nodes.some((e=>"rule"===e.type||"atrule"===e.type))))return;const t=selectorParser().astSync(e.selector);if(t.nodes?.length<2)return;const s=t.nodes.map((e=>selectorSpecificity(e)));s.every((e=>0===compare(e,s[0])))||stylelint.utils.report({message:messages.rejectedMixedSpecificity(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName})})),s.walkRules((e=>{{let t=1,s=e.parent;for(;s&&("rule"===s.type&&t++,!(t>2));)s=s.parent;if(1===t)return;if(t>2)return void stylelint.utils.report({message:messages.rejectedNestingDepth(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName})}const t=selectorParser().astSync(e.selector),s=getFirstCompoundOrSelf(t);let n=!1;"combinator"===s.nodes[0]?.type&&(n=!0);for(let s=0;s<t.nodes.length;s++){const l=t.nodes[s];if(!l.nodes||!l.nodes.length)continue;if(l.nodes.every((e=>"nesting"===e.type||"comment"===e.type))){stylelint.utils.report({message:messages.rejectedNestingSelectorIncorrectShape(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName});continue}let o=0;l.walkNesting((()=>{o++})),1!==o||"nesting"!==l.nodes[l.nodes.length-1]?.type||"combinator"!==l.nodes[l.nodes.length-2]?.type?2===l.nodes.length&&"pseudo"===l.nodes[0]?.type&&selectorParser.isPseudoClass(l.nodes[0])&&"nesting"===l.nodes[1]?.type?stylelint.utils.report({message:messages.rejectedMustStartWithAmpersand(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName,fix:{apply:()=>{const s=l.nodes[0],r=l.nodes[1];l.replaceWith(selectorParser.selector({nodes:[r,s]})),e.selector=t.toString()},node:e}}):"nesting"===l.nodes[0]?.type?2===l.nodes.length?"pseudo"===l.nodes[1]?.type||stylelint.utils.report({message:messages.rejectedMustEndWithPseudo(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName,fix:{apply:()=>{l.nodes[0]?.remove(),fixSelector(e,t,l)},node:e}}):stylelint.utils.report({message:messages.rejectedNestingSelectorIncorrectShape(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName,fix:{apply:()=>{const s=l.nodes[0],r=l.nodes[0]?.next();s&&"combinator"===r?.type?(l.nodes[0]?.replaceWith(selectorParser.nesting()),fixSelector(e,t,l)):(l.nodes[0]?.remove(),fixSelector(e,t,l))},node:e}}):stylelint.utils.report({message:messages.rejectedMustStartWithAmpersand(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName,fix:{apply:()=>{fixSelector(e,t,l,n)},node:e}}):stylelint.utils.report({message:messages.rejectedMustStartWithAmpersand(),node:e,index:0,endIndex:e.selector.length,result:r,ruleName:ruleName,fix:{apply:()=>{fixSelector_AncestorPattern(e,t,l)},node:e}})}}))};function fixSelector(e,t,s,r){if(1===s.nodes.length&&"pseudo"===s.nodes[0].type)return s.replaceWith(selectorParser.selector({nodes:[selectorParser.nesting(),s.nodes[0]]})),void(e.selector=t.toString());s.replaceWith(selectorParser.selector({nodes:[selectorParser.nesting(),selectorParser.pseudo({value:r?":has":":is",nodes:[s]})]})),e.selector=t.toString()}function fixSelector_AncestorPattern(e,t,s){s.nodes[s.nodes.length-1].replaceWith(selectorParser.universal()),s.replaceWith(selectorParser.selector({nodes:[selectorParser.nesting(),selectorParser.pseudo({value:":is",nodes:[s]})]})),e.selector=t.toString()}ruleFunction.ruleName=ruleName,ruleFunction.messages=messages,ruleFunction.meta=meta;export default stylelint.createPlugin(ruleName,ruleFunction);function getFirstCompoundOrSelf(e){if(!e.nodes)return e;for(let t=0;t<e.nodes.length;t++)if("selector"!==e.nodes[t].type)return e;return e.nodes[0]}function isRegExp(e){return e instanceof RegExp}function isString(e){return"string"==typeof e||e instanceof String}
//# sourceMappingURL=/sm/bc67e9bc2b32ee78cc93fd176a1c01c9b0620c6453a502cacd1e44a38dc1fa3e.map