import{__require as e}from"../../postcss/lib/comment.mjs";import{__require as t}from"../../postcss/lib/parser.mjs";import{__require as s}from"./nodes/inline-comment.mjs";import{__require as i}from"./nodes/interpolation.mjs";import{__require as n}from"./nodes/mixin.mjs";import{__require as o}from"./nodes/import.mjs";import{__require as r}from"./nodes/variable.mjs";var a,c;function l(){if(c)return a;c=1;const l=e(),d=t(),{isInlineComment:h}=s(),{interpolation:m}=i(),{isMixinToken:u}=n(),p=o(),f=r(),x=/(!\s*important)$/i;return a=class extends d{constructor(...e){super(...e),this.lastNode=null}atrule(e){m.bind(this)(e)||(super.atrule(e),p(this.lastNode),f(this.lastNode))}decl(...e){super.decl(...e);/extend\(.+\)/i.test(this.lastNode.value)&&(this.lastNode.extend=!0)}each(e){e[0][1]=` ${e[0][1]}`;const t=e.findIndex(e=>"("===e[0]),s=e.reverse().find(e=>")"===e[0]),i=e.reverse().indexOf(s),n=e.splice(t,i).map(e=>e[1]).join("");for(const t of e.reverse())this.tokenizer.back(t);this.atrule(this.tokenizer.nextToken()),this.lastNode.function=!0,this.lastNode.params=n}init(e,t,s){super.init(e,t,s),this.lastNode=e}inlineComment(e){const t=new l,s=e[1].slice(2);if(this.init(t,e[2]),t.source.end=this.getPosition(e[3]||e[2]),t.inline=!0,t.raws.begin="//",/^\s*$/.test(s))t.text="",t.raws.left=s,t.raws.right="";else{const e=s.match(/^(\s*)([^]*[^\s])(\s*)$/);[,t.raws.left,t.text,t.raws.right]=e}}mixin(e){const[t]=e,s=t[1].slice(0,1),i=e.findIndex(e=>"brackets"===e[0]),n=e.findIndex(e=>"("===e[0]);let o="";if((i<0||i>3)&&n>0){const t=e.reduce((e,t,s)=>")"===t[0]?s:e),s=e.slice(n,t+n).map(e=>e[1]).join(""),[i]=e.slice(n),o=[i[2],i[3]],[r]=e.slice(t,t+1),a=[r[2],r[3]],c=["brackets",s].concat(o,a),l=e.slice(0,n),d=e.slice(t+1);(e=l).push(c),e=e.concat(d)}const r=[];for(const t of e)if(("!"===t[1]||r.length)&&r.push(t),"important"===t[1])break;if(r.length){const[t]=r,s=e.indexOf(t),i=r[r.length-1],n=[t[2],t[3]],o=[i[4],i[5]],a=["word",r.map(e=>e[1]).join("")].concat(n,o);e.splice(s,r.length,a)}const a=e.findIndex(e=>x.test(e[1]));a>0&&([,o]=e[a],e.splice(a,1));for(const t of e.reverse())this.tokenizer.back(t);this.atrule(this.tokenizer.nextToken()),this.lastNode.mixin=!0,this.lastNode.raws.identifier=s,o&&(this.lastNode.important=!0,this.lastNode.raws.important=o)}other(e){h.bind(this)(e)||super.other(e)}rule(e){const t=e[e.length-1],s=e[e.length-2];if("at-word"===s[0]&&"{"===t[0]&&(this.tokenizer.back(t),m.bind(this)(s))){const t=this.tokenizer.nextToken();e=e.slice(0,e.length-2).concat([t]);for(const t of e.reverse())this.tokenizer.back(t);return}super.rule(e);/:extend\(.+\)/i.test(this.lastNode.selector)&&(this.lastNode.extend=!0)}unknownWord(e){const[t]=e;"each"!==e[0][1]||"("!==e[1][0]?u(t)?this.mixin(e):super.unknownWord(e):this.each(e)}}}export{l as __require};