import{RULE_NAME_ALL as t}from"./constants.mjs";import{isConfigurationComment as e,extractConfigurationComment as n,ENABLE_COMMAND as s,DISABLE_COMMAND as o,DISABLE_NEXT_LINE_COMMAND as r,DISABLE_LINE_COMMAND as i,getConfigurationComment as l}from"./utils/configurationComment.mjs";import{assertNumber as c,assertString as a,assert as f}from"./utils/validateTypes.mjs";import{isComment as u,isRule as d,isAtRule as m,isDeclaration as h}from"./utils/typeGuards.mjs";import p from"./utils/isStandardSyntaxComment.mjs";import{tokenize as b,isTokenComment as g}from"../../@csstools/css-tokenizer/dist/index.mjs";function w(t,e,n,s,o,r){return{node:t,start:e,end:o||void 0,strictStart:n,strictEnd:"boolean"==typeof r?r:void 0,description:s}}function y(y,x){const v=x.stylelint.disabledRanges,j=[];let k;v[t]=j;const O=x.stylelint.config?.configurationComment;return y.walk(t=>{if(u(t)){if(k)return void(k===t&&(k=null));const n=t.next();if(p(t)||!e(t.text,O)||!n||!u(n)||!t.text.includes("--")&&!n.text.startsWith("--"))return void E(t,t.source,t.text);let s=t.source?.end?.line??0;const o=t.clone();let r=n;for(;!p(r)&&!e(r.text,O);){const t=r.source?.end?.line??0;if(s+1!==t)break;o.text+=`\n${r.text}`,o.source&&r.source&&(o.source.end=r.source.end),k=r;const e=r.next();if(!e||!u(e))break;r=e,s=t}E(o,o.source,o.text)}if(d(t)){let e=0;const n=t.raws?.selector?.raw;C(t,n,e),e+=n?.length??t.selector.length;const s=t.raws?.between;C(t,s,e)}if(m(t)){let e=t.name.length+1;const n=t.raws?.afterName;C(t,n,e),e+=n?.length??0;const s=t.raws?.params?.raw;C(t,s,e),e+=s?.length??t.params.length;const o=t.raws?.between;C(t,o,e)}if(h(t)){let e=t.prop.length;const n=t.raws?.between;C(t,n,e),e+=n?.length??0;const s=t.raws?.value?.raw;C(t,s,e)}}),x;function $(e,n,s,o){if(z(t))throw e.error("All rules have already been disabled",{plugin:"stylelint"});if(s===t)for(const s of Object.keys(v)){if(z(s))continue;const r=s===t;B(e,n,s,r,o),N(n,s,r)}else{if(z(s))throw e.error(`"${s}" has already been disabled`,{plugin:"stylelint"});B(e,n,s,!0,o),N(n,s,!0)}}function C(t,e,n){e&&e.includes("/*")&&e.includes("*/")&&b({css:e}).forEach(e=>{if(!g(e))return;const[,s,o,r]=e,i=t.rangeBy({index:o+n,endIndex:r+1+n});E(t,i,s.slice(2,-2).trim())})}function E(l,a,f){if(a&&e(f,O))switch(n(f,O)){case i:!function(t,e,n){if(e.start){const s=e.start.line,o=A(n);for(const e of S(i,n))$(t,s,e,o)}}(l,a,f);break;case r:!function(t,e,n){if(e.end){const s=e.end.line,o=A(n);for(const e of S(r,n))$(t,s+1,e,o)}}(l,a,f);break;case o:!function(e,n,s){const r=A(s);for(const i of S(o,s)){const s=i===t;if(z(i))throw e.error(s?"All rules have already been disabled":`"${i}" has already been disabled`,{plugin:"stylelint"});if(n.start){const o=n.start.line;if(s)for(const n of Object.keys(v))B(e,o,n,n===t,r);else B(e,o,i,!0,r)}}}(l,a,f);break;case s:!function(e,n,o){for(const r of S(s,o)){const s=n.end?.line;if(c(s),r!==t)if(z(t)&&void 0===v[r])v[r]=j.map(({start:t,end:n,description:s})=>w(e,t,!1,s,n,!1)),N(s,r,!0);else{if(!z(r))throw e.error(`"${r}" has not been disabled`,{plugin:"stylelint"});N(s,r,!0)}else{if(Object.values(v).every(t=>{if(0===t.length)return!0;const e=t[t.length-1];return e&&"number"==typeof e.end}))throw e.error("No rules have been disabled",{plugin:"stylelint"});for(const[e,n]of Object.entries(v)){const o=n[n.length-1];o&&o.end||N(s,e,e===t)}}}}(l,a,f)}}function S(e,n){const s=l(e,O),o=n.slice(s.length).split(/\s-{2,}\s/u)[0];a(o);const r=o.trim().split(",").filter(Boolean).map(t=>t.trim());return 0===r.length?[t]:r}function A(t){const e=t.indexOf("--");if(-1!==e)return t.slice(e+2).trim()}function B(t,e,n,s,o){const r=w(t,e,s,o);!function(t){v[t]||(v[t]=j.map(({node:t,start:e,end:n,description:s})=>w(t,e,!1,s,n,!1)))}(n);const i=v[n];f(i),i.push(r)}function N(t,e,n){const s=v[e],o=s?s[s.length-1]:null;o&&(o.end=t,o.strictEnd=n)}function z(t){const e=v[t];if(!e)return!1;const n=e[e.length-1];return!!n&&!n.end}}export{y as default};