
function PriorityCalculator(){function calculateSingle(input){var selector=input,findMatch,typeCount={'a':0,'b':0,'c':0},parts=[],attributeRegex=/(\[[^\]]+\])/g,idRegex=/(#[^\s\+>~\.\[:]+)/g,classRegex=/(\.[^\s\+>~\.\[:]+)/g,pseudoElementRegex=/(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,pseudoClassWithBracketsRegex=/(:[\w-]+\([^\)]*\))/gi,pseudoClassRegex=/(:[^\s\+>~\.\[:]+)/g,elementRegex=/([^\s\+>~\.\[:]+)/g;findMatch=function(regex,type){var matches,i,len,match,index,length;if(regex.test(selector)){matches=selector.match(regex);for(i=0,len=matches.length;i<len;i+=1){typeCount[type]+=1;match=matches[i];index=selector.indexOf(match);length=match.length;parts.push({selector:match,type:type,index:index,length:length});selector=selector.replace(match,Array(length+1).join(' '));}}};(function(){var regex=/:not\(([^\)]*)\)/g;if(regex.test(selector)){selector=selector.replace(regex,'     $1 ');}}());(function(){var regex=/{[^]*/gm,matches,i,len,match;if(regex.test(selector)){matches=selector.match(regex);for(i=0,len=matches.length;i<len;i+=1){match=matches[i];selector=selector.replace(match,Array(match.length+1).join(' '));}}}());findMatch(attributeRegex,'b');findMatch(idRegex,'a');findMatch(classRegex,'b');findMatch(pseudoElementRegex,'c');findMatch(pseudoClassWithBracketsRegex,'b');findMatch(pseudoClassRegex,'b');selector=selector.replace(/[\*\s\+>~]/g,' ');selector=selector.replace(/[#\.]/g,' ');findMatch(elementRegex,'c');parts.sort(function(a,b){return a.index-b.index;});return{selector:input,specificity:'0,'+typeCount.a.toString()+','+typeCount.b.toString()+','+typeCount.c.toString(),priority:parseInt('0'+typeCount.a.toString()+''+typeCount.b.toString()+''+typeCount.c.toString()),parts:parts};}
return{calculate:function(input){var selectors,selector,i,len,results=[];if(!input){return results;}
selectors=input.split(',');for(i=0,len=selectors.length;i<len;i+=1){selector=selectors[i];if(selector.length>0){results.push(calculateSingle(selector));}}
return results;}}}