define("ace/ext/beautify",["require","exports","module","ace/token_iterator"],function(e,S,t){"use strict";function B(e,t){return-1<e.type.lastIndexOf(t+".xml")}var F=e("../token_iterator").TokenIterator;S.singletonTags=["area","base","br","col","command","embed","hr","html","img","input","keygen","link","meta","param","source","track","wbr"],S.blockTags=["article","aside","blockquote","body","div","dl","fieldset","footer","form","head","header","html","nav","ol","p","script","section","style","table","tbody","tfoot","thead","ul"],S.beautify=function(e){for(var t,r,a,o,s,n=new F(e,0,0),i=n.getCurrentToken(),c=e.getTabString(),u=S.singletonTags,m=S.blockTags,l=!1,p=!1,f=!1,b="",d="",y="",h=0,g=0,k=0,$=0,w=0,x=0,v=0,T=!1,R=!1,O=!1,q={0:0},C={},I=function(){t&&t.value&&"string.regexp"!==t.type&&(t.value=t.value.trim())},_=function(){b=b.replace(/ +$/,"")},j=function(){b=b.trimRight(),l=!1};null!==i;){if(a=n.getCurrentTokenRow(),n.$rowTokens,t=n.stepForward(),void 0!==i){if(d=i.value,w=0,s="style"===y||"ace/mode/css"===e.$modeId,B(i,"tag-open")?(R=!0,t&&(O=-1!==m.indexOf(t.value)),"</"===d&&(O&&!l&&v<1&&v++,s&&(v=1),O=!(w=1))):B(i,"tag-close")?R=!1:B(i,"comment.start")?O=!0:B(i,"comment.end")&&(O=!1),R||v||"paren.rparen"!==i.type||"}"!==i.value.substr(0,1)||v++,a!==r&&(v=a,r&&(v-=r)),v){for(j();0<v;v--)b+="\n";l=!0,B(i,"comment")||i.type.match(/^(comment|string)$/)||(d=d.trimLeft())}if(d){if("keyword"===i.type&&d.match(/^(if|else|elseif|for|foreach|while|switch)$/)?(C[h]=d,I(),f=!0,d.match(/^(else|elseif)$/)&&b.match(/\}[\s]*$/)&&(j(),p=!0)):"paren.lparen"===i.type?(I(),"{"===d.substr(-1)&&(T=!(f=!0),R||(v=1)),"{"===d.substr(0,1)&&(p=!0,"["!==b.substr(-1)&&"["===b.trimRight().substr(-1)?(j(),p=!1):(")"===b.trimRight().substr(-1)?j:_)())):"paren.rparen"===i.type?("}"===d.substr(0,w=1)&&("case"===C[h-1]&&w++,"{"===b.trimRight().substr(-1)?j():(p=!0,s&&(v+=2))),"]"===d.substr(0,1)&&"}"!==b.substr(-1)&&"}"===b.trimRight().substr(-1)&&(p=!1,$++,j()),")"===d.substr(0,1)&&"("!==b.substr(-1)&&"("===b.trimRight().substr(-1)&&(p=!1,$++,j()),_()):"keyword.operator"!==i.type&&"keyword"!==i.type||!d.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)?"punctuation.operator"===i.type&&";"===d?(j(),I(),f=!0,s&&v++):"punctuation.operator"===i.type&&d.match(/^(:|,)$/)?(j(),I(),l=!(f=!0)):"support.php_tag"!==i.type||"?>"!==d||l?B(i,"attribute-name")&&b.substr(-1).match(/^\s$/)?p=!0:B(i,"attribute-equals")?(_(),I()):B(i,"tag-close")&&(_(),"/>"===d&&(p=!0)):(j(),p=!0):(j(),I(),f=p=!0),l&&(!i.type.match(/^(comment)$/)||d.substr(0,1).match(/^[/#]$/))&&(!i.type.match(/^(string)$/)||d.substr(0,1).match(/^['"]$/))){if($=k,g<h)for($++,o=h;g<o;o--)q[o]=$;else h<g&&($=q[h]);for(g=h,k=$,w&&($-=w),T&&!x&&($++,T=!1),o=0;o<$;o++)b+=c}if("keyword"===i.type&&d.match(/^(case|default)$/)&&(C[h]=d,h++),"keyword"===i.type&&d.match(/^(break)$/)&&C[h-1]&&C[h-1].match(/^(case|default)$/)&&h--,"paren.lparen"===i.type&&(x+=(d.match(/\(/g)||[]).length,h+=d.length),"keyword"===i.type&&d.match(/^(if|else|elseif|for|while)$/)?(T=!0,x=0):!x&&d.trim()&&"comment"!==i.type&&(T=!1),"paren.rparen"===i.type)for(x-=(d.match(/\)/g)||[]).length,o=0;o<d.length;o++)h--,"}"===d.substr(o,1)&&"case"===C[h]&&h--;p&&!l&&(_(),"\n"!==b.substr(-1)&&(b+=" ")),b+=d,f&&(b+=" "),f=p=l=!1,(B(i,"tag-close")&&(O||-1!==m.indexOf(y))||B(i,"doctype")&&">"===d)&&(v=O&&t&&"</"===t.value?-1:1),B(i,"tag-open")&&"</"===d?h--:B(i,"tag-open")&&"<"===d&&-1===u.indexOf(t.value)?h++:B(i,"tag-name")?y=d:B(i,"tag-close")&&"/>"===d&&-1===u.indexOf(y)&&h--,r=a}}i=t}b=b.trim(),e.doc.setValue(b)},S.commands=[{name:"beautify",exec:function(e){S.beautify(e.session)},bindKey:"Ctrl-Shift-B"}]}),window.require(["ace/ext/beautify"],function(e){"object"==typeof module&&"object"==typeof exports&&module&&(module.exports=e)});