import"./chunk-HVV3ARZI.js";var b=t=>{let e=[],o=0,s;return t=t.replace(/(\[[^\]]*\])/g,(n,a)=>{let r=`__ph-${o}__`;return e.push(a),o++,r}),s=t.replace(/(:nth-[-\w]+)(\([^)]+\))/g,(n,a,r)=>{let l=`__ph-${o}__`;return e.push(r),o++,a+l}),{content:s,placeholders:e}},w=(t,e)=>e.replace(/__ph-(\d+)__/g,(o,s)=>t[+s]),_="-shadowcsshost",k="-shadowcssslotted",y="-shadowcsscontext",O=")(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)",L=new RegExp("("+_+O,"gim"),P=new RegExp("("+y+O,"gim"),j=new RegExp("("+k+O,"gim"),g=_+"-no-combinator",x=/-shadowcsshost-no-combinator([^\s]*)/,v=[/::shadow/g,/::content/g],N="([>\\s~+[.,{:][\\s\\S]*)?$",S=/-shadowcsshost/gim,M=/:host/gim,D=/::slotted/gim,I=/:host-context/gim,K=/\/\*\s*[\s\S]*?\*\//g,U=t=>t.replace(K,""),Y=/\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g,A=t=>t.match(Y)||[],q=/(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g,z=/([{}])/g,F="{",G="}",C="%BLOCK%",$=(t,e)=>{let o=J(t),s=0;return o.escapedString.replace(q,(...c)=>{let n=c[2],a="",r=c[4],l="";r&&r.startsWith("{"+C)&&(a=o.blocks[s++],r=r.substring(C.length+1),l="{");let p=e({selector:n,content:a});return`${c[1]}${p.selector}${c[3]}${l}${p.content}${r}`})},J=t=>{let e=t.split(z),o=[],s=[],c=0,n=[];for(let r=0;r<e.length;r++){let l=e[r];l===G&&c--,c>0?n.push(l):(n.length>0&&(s.push(n.join("")),o.push(C),n=[]),o.push(l)),l===F&&c++}return n.length>0&&(s.push(n.join("")),o.push(C)),{escapedString:o.join(""),blocks:s}},Q=t=>(t=t.replace(I,y).replace(M,_).replace(D,k),t),B=(t,e,o)=>t.replace(e,(...s)=>{if(s[2]){let c=s[2].split(","),n=[];for(let a=0;a<c.length;a++){let r=c[a].trim();if(!r)break;n.push(o(g,r,s[3]))}return n.join(",")}else return g+s[3]}),E=(t,e,o)=>t+e.replace(_,"")+o,V=t=>B(t,L,E),X=(t,e,o)=>e.indexOf(_)>-1?E(t,e,o):t+e+o+", "+e+" "+t+o,Z=(t,e)=>{let o="."+e+" > ",s=[];return t=t.replace(j,(...c)=>{if(c[2]){let n=c[2].trim(),a=c[3],r=o+n+a,l="";for(let d=c[4]-1;d>=0;d--){let u=c[5][d];if(u==="}"||u===",")break;l=u+l}let i=l+r,p=`${l.trimRight()}${r.trim()}`;if(i.trim()!==p.trim()){let d=`${p}, ${i}`;s.push({orgSelector:i,updatedSelector:d})}return r}else return g+c[3]}),{selectors:s,cssText:t}},T=t=>B(t,P,X),tt=t=>v.reduce((e,o)=>e.replace(o," "),t),et=t=>{let e=/\[/g,o=/\]/g;return t=t.replace(e,"\\[").replace(o,"\\]"),new RegExp("^("+t+")"+N,"m")},ot=(t,e)=>!et(e).test(t),nt=(t,e,o)=>{if(S.lastIndex=0,S.test(t)){let s=`.${o}`;return t.replace(x,(c,n)=>n.replace(/([^:]*)(:*)(.*)/,(a,r,l,i)=>r+s+l+i)).replace(S,s+" ")}return e+" "+t},st=(t,e,o)=>{let s=/\[is=([^\]]*)\]/g;e=e.replace(s,(f,...h)=>h[0]);let c="."+e,n=f=>{let h=f.trim();if(!h)return"";if(f.indexOf(g)>-1)h=nt(f,e,o);else{let m=f.replace(S,"");if(m.length>0){let R=m.match(/([^:]*)(:*)(.*)/);R&&(h=R[1]+c+R[2]+R[3])}}return h},a=b(t);t=a.content;let r="",l=0,i,p=/( |>|\+|~(?!=))\s*/g,u=!(t.indexOf(g)>-1);for(;(i=p.exec(t))!==null;){let f=i[1],h=t.slice(l,i.index).trim();u=u||h.indexOf(g)>-1;let m=u?n(h):h;r+=`${m} ${f} `,l=p.lastIndex}let H=t.substring(l);return u=u||H.indexOf(g)>-1,r+=u?n(H):H,w(a.placeholders,r)},ct=(t,e,o,s)=>t.split(",").map(c=>s&&c.indexOf("."+s)>-1?c.trim():ot(c,e)?st(c,e,o).trim():c.trim()).join(", "),W=(t,e,o,s,c)=>$(t,n=>{let a=n.selector,r=n.content;return n.selector[0]!=="@"?a=ct(n.selector,e,o,s):(n.selector.startsWith("@media")||n.selector.startsWith("@supports")||n.selector.startsWith("@page")||n.selector.startsWith("@document"))&&(r=W(n.content,e,o,s)),{selector:a.replace(/\s{2,}/g," ").trim(),content:r}}),rt=(t,e,o,s,c)=>{t=Q(t),t=V(t),t=T(t);let n=Z(t,s);return t=n.cssText,t=tt(t),e&&(t=W(t,e,o,s)),t=t.replace(/-shadowcsshost-no-combinator/g,`.${o}`),t=t.replace(/>\s*\*\s+([^{, ]+)/gm," $1 "),{cssText:t.trim(),slottedSelectors:n.selectors}},lt=(t,e,o)=>{let s=e+"-h",c=e+"-s",n=A(t);t=U(t);let a=[];if(o){let l=i=>{let p=`/*!@___${a.length}___*/`,d=`/*!@${i.selector}*/`;return a.push({placeholder:p,comment:d}),i.selector=p+i.selector,i};t=$(t,i=>i.selector[0]!=="@"?l(i):((i.selector.startsWith("@media")||i.selector.startsWith("@supports")||i.selector.startsWith("@page")||i.selector.startsWith("@document"))&&(i.content=$(i.content,l)),i))}let r=rt(t,e,s,c);return t=[r.cssText,...n].join(`
`),o&&a.forEach(({placeholder:l,comment:i})=>{t=t.replace(l,i)}),r.slottedSelectors.forEach(l=>{t=t.replace(l.orgSelector,l.updatedSelector)}),t};export{lt as scopeCss};
