Liferay.Loader.define("liferay!template-web$codemirror@5.65.2/addon/edit/closetag",["module","exports","require","../../lib/codemirror","../fold/xml-fold"],(function(e,t,n){var o,r=void 0;window;o=function(e){e.defineOption("autoCloseTags",!1,(function(o,r,i){if(i!=e.Init&&i&&o.removeKeyMap("autoCloseTags"),r){var a={name:"autoCloseTags"};"object"==typeof r&&!1===r.whenClosing||(a["'/'"]=function(t){return function autoCloseSlash(t){return t.getOption("disableInput")?e.Pass:autoCloseCurrent(t,!0)}(t)}),"object"==typeof r&&!1===r.whenOpening||(a["'>'"]=function(o){return function autoCloseGT(o){if(o.getOption("disableInput"))return e.Pass;for(var r=o.listSelections(),i=[],a=o.getOption("autoCloseTags"),l=0;l<r.length;l++){if(!r[l].empty())return e.Pass;var s=r[l].head,d=o.getTokenAt(s),c=e.innerMode(o.getMode(),d.state),f=c.state,g=c.mode.xmlCurrentTag&&c.mode.xmlCurrentTag(f),u=g&&g.name;if(!u)return e.Pass;var m="html"==c.mode.configuration,h="object"==typeof a&&a.dontCloseTags||m&&t,p="object"==typeof a&&a.indentTags||m&&n;d.end>s.ch&&(u=u.slice(0,u.length-d.end+s.ch));var C=u.toLowerCase();if(!u||"string"==d.type&&(d.end!=s.ch||!/[\"\']/.test(d.string.charAt(d.string.length-1))||1==d.string.length)||"tag"==d.type&&g.close||d.string.indexOf("/")==s.ch-d.start-1||h&&indexOf(h,C)>-1||closingTagExists(o,c.mode.xmlCurrentContext&&c.mode.xmlCurrentContext(f)||[],u,s,!0))return e.Pass;var x="object"==typeof a&&a.emptyTags;if(x&&indexOf(x,u)>-1)i[l]={text:"/>",newPos:e.Pos(s.line,s.ch+2)};else{var b=p&&indexOf(p,C)>-1;i[l]={indent:b,text:">"+(b?"\n\n":"")+"</"+u+">",newPos:b?e.Pos(s.line+1,0):e.Pos(s.line,s.ch+1)}}}var v="object"==typeof a&&a.dontIndentOnAutoClose;for(l=r.length-1;l>=0;l--){var y=i[l];o.replaceRange(y.text,r[l].head,r[l].anchor,"+insert");var T=o.listSelections().slice(0);T[l]={head:y.newPos,anchor:y.newPos},o.setSelections(T),!v&&y.indent&&(o.indentLine(y.newPos.line,null,!0),o.indentLine(y.newPos.line+1,null,!0))}}(o)}),o.addKeyMap(a)}}));var t=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],n=["applet","blockquote","body","button","div","dl","fieldset","form","frameset","h1","h2","h3","h4","h5","h6","head","html","iframe","layer","legend","object","ol","p","select","table","ul"];function autoCloseCurrent(t,n){for(var o=t.listSelections(),r=[],i=n?"/":"</",a=t.getOption("autoCloseTags"),l="object"==typeof a&&a.dontIndentOnSlash,s=0;s<o.length;s++){if(!o[s].empty())return e.Pass;var d=o[s].head,c=t.getTokenAt(d),f=e.innerMode(t.getMode(),c.state),g=f.state;if(n&&("string"==c.type||"<"!=c.string.charAt(0)||c.start!=d.ch-1))return e.Pass;var u,m="xml"!=f.mode.name&&"htmlmixed"==t.getMode().name;if(m&&"javascript"==f.mode.name)u=i+"script";else if(m&&"css"==f.mode.name)u=i+"style";else{var h=f.mode.xmlCurrentContext&&f.mode.xmlCurrentContext(g),p=h.length?h[h.length-1]:"";if(!h||h.length&&closingTagExists(t,h,p,d))return e.Pass;u=i+p}">"!=t.getLine(d.line).charAt(c.end)&&(u+=">"),r[s]=u}if(t.replaceSelections(r),o=t.listSelections(),!l)for(s=0;s<o.length;s++)(s==o.length-1||o[s].head.line<o[s+1].head.line)&&t.indentLine(o[s].head.line)}function indexOf(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,o=e.length;n<o;++n)if(e[n]==t)return n;return-1}function closingTagExists(t,n,o,r,i){if(!e.scanForClosingTag)return!1;var a=Math.min(t.lastLine()+1,r.line+500),l=e.scanForClosingTag(t,r,null,a);if(!l||l.tag!=o)return!1;for(var s=i?1:0,d=n.length-1;d>=0&&n[d]==o;d--)++s;for(r=l.to,d=1;d<s;d++){var c=e.scanForClosingTag(t,r,null,a);if(!c||c.tag!=o)return!1;r=c.to}return!0}e.commands.closeTag=function(e){return autoCloseCurrent(e)}},"object"==typeof t&&"object"==typeof e?o(n("../../lib/codemirror"),n("../fold/xml-fold")):"function"==typeof r&&r.amd?r(["../../lib/codemirror","../fold/xml-fold"],o):o(CodeMirror)}));
//# sourceMappingURL=closetag.js.map