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