var u=function(c){var e=c,t,r={a:0,b:0,c:0},i=[],h=/(\[[^\]]+\])/g,d=/(#[^\#\s\+>~\.\[:\)]+)/g,x=/(\.[^\s\+>~\.\[:\)]+)/g,m=/(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,S=/(:(?!not|global|local)[\w-]+\([^\)]*\))/gi,v=/(:(?!not|global|local)[^\s\+>~\.\[:]+)/g,A=/([^\s\+>~\.\[:]+)/g;return t=function(a,l){var n,s,o,f,g,p;if(a.test(e))for(n=e.match(a),s=0,o=n.length;s<o;s+=1)r[l]+=1,f=n[s],g=e.indexOf(f),p=f.length,i.push({selector:c.substr(g,p),type:l,index:g,length:p}),e=e.replace(f,Array(p+1).join(" "))},function(){var a=function(o){var f,g,p,y;if(o.test(e))for(f=e.match(o),g=0,p=f.length;g<p;g+=1)y=f[g],e=e.replace(y,Array(y.length+1).join("A"))},l=/\\[0-9A-Fa-f]{6}\s?/g,n=/\\[0-9A-Fa-f]{1,5}\s/g,s=/\\./g;a(l),a(n),a(s)}(),function(){var a=/{[^]*/gm,l,n,s,o;if(a.test(e))for(l=e.match(a),n=0,s=l.length;n<s;n+=1)o=l[n],e=e.replace(o,Array(o.length+1).join(" "))}(),t(h,"b"),t(d,"a"),t(x,"b"),t(m,"c"),t(S,"b"),t(v,"b"),e=e.replace(/[\*\s\+>~]/g," "),e=e.replace(/[#\.]/g," "),e=e.replace(/:not/g,"    "),e=e.replace(/:local/g,"      "),e=e.replace(/:global/g,"       "),e=e.replace(/[\(\)]/g," "),t(A,"c"),i.sort(function(a,l){return a.index-l.index}),{selector:c,specificity:"0,"+r.a.toString()+","+r.b.toString()+","+r.c.toString(),specificityArray:[0,r.a,r.b,r.c],parts:i}},b=function(c,e){var t,r,i;if(typeof c=="string"){if(c.indexOf(",")!==-1)throw"Invalid CSS selector";t=u(c).specificityArray}else if(Array.isArray(c)){if(c.filter(function(h){return typeof h=="number"}).length!==4)throw"Invalid specificity array";t=c}else throw"Invalid CSS selector or specificity array";if(typeof e=="string"){if(e.indexOf(",")!==-1)throw"Invalid CSS selector";r=u(e).specificityArray}else if(Array.isArray(e)){if(e.filter(function(h){return typeof h=="number"}).length!==4)throw"Invalid specificity array";r=e}else throw"Invalid CSS selector or specificity array";for(i=0;i<4;i+=1){if(t[i]<r[i])return-1;if(t[i]>r[i])return 1}return 0};export{b as c};
