(t=>{var e=t.escapeEntities,n=t.escapeUriScheme,r=t.dom,l=t.utils,i=r.css,o=r.attr,a=r.is,s=l.extend,u=l.each,c="data-sceditor-emoticon",f=t.command.get,d={always:1,never:2,auto:3},h={bold:{txtExec:["[b]","[/b]"]},italic:{txtExec:["[i]","[/i]"]},underline:{txtExec:["[u]","[/u]"]},strike:{txtExec:["[s]","[/s]"]},subscript:{txtExec:["[sub]","[/sub]"]},superscript:{txtExec:["[sup]","[/sup]"]},left:{txtExec:["[left]","[/left]"]},center:{txtExec:["[center]","[/center]"]},right:{txtExec:["[right]","[/right]"]},justify:{txtExec:["[justify]","[/justify]"]},font:{txtExec:function(t){var e=this;f("font")._dropDown(e,t,function(t){e.insertText("[font="+t+"]","[/font]")})}},size:{txtExec:function(t){var e=this;f("size")._dropDown(e,t,function(t){e.insertText("[size="+t+"]","[/size]")})}},color:{txtExec:function(t){var e=this;f("color")._dropDown(e,t,function(t){e.insertText("[color="+t+"]","[/color]")})}},bulletlist:{txtExec:function(t,e){this.insertText("[ul]\n[li]"+e.split(/\r?\n/).join("[/li]\n[li]")+"[/li]\n[/ul]")}},orderedlist:{txtExec:function(t,e){this.insertText("[ol]\n[li]"+e.split(/\r?\n/).join("[/li]\n[li]")+"[/li]\n[/ol]")}},table:{txtExec:["[table][tr][td]","[/td][/tr][/table]"]},horizontalrule:{txtExec:["[hr]"]},code:{txtExec:["[code]","[/code]"]},image:{txtExec:function(t,e){var n=this;f("image")._dropDown(n,t,e,function(t,e,r){var l="";e&&(l+=" width="+e),r&&(l+=" height="+r),n.insertText("[img"+l+"]"+t+"[/img]")})}},email:{txtExec:function(t,e){var n=this;f("email")._dropDown(n,t,function(t,r){n.insertText("[email="+t+"]"+(r||e||t)+"[/email]")})}},link:{txtExec:function(t,e){var n=this;f("link")._dropDown(n,t,function(t,r){n.insertText("[url="+t+"]"+(r||e||t)+"[/url]")})}},quote:{txtExec:["[quote]","[/quote]"]},youtube:{txtExec:function(t){var e=this;f("youtube")._dropDown(e,t,function(t){e.insertText("[youtube]"+t+"[/youtube]")})}},rtl:{txtExec:["[rtl]","[/rtl]"]},ltr:{txtExec:["[ltr]","[/ltr]"]}},m={b:{tags:{b:null,strong:null},styles:{"font-weight":["bold","bolder","401","700","800","900"]},format:"[b]{0}[/b]",html:"{0}"},i:{tags:{i:null,em:null},styles:{"font-style":["italic","oblique"]},format:"[i]{0}[/i]",html:"{0}"},u:{tags:{u:null},styles:{"text-decoration":["underline"]},format:"[u]{0}[/u]",html:"{0}"},s:{tags:{s:null,strike:null},styles:{"text-decoration":["line-through"]},format:"[s]{0}[/s]",html:"{0}"},sub:{tags:{sub:null},format:"[sub]{0}[/sub]",html:"{0}"},sup:{tags:{sup:null},format:"[sup]{0}[/sup]",html:"{0}"},font:{tags:{font:{face:null}},styles:{"font-family":null},quoteType:d.never,format:function(t,e){var n;return"[font="+b(n=a(t,"font")&&(n=o(t,"face"))?n:i(t,"font-family"))+"]"+e+"[/font]"},html:'{0}'},size:{tags:{font:{size:null}},styles:{"font-size":null},format:function(t,e){var n=o(t,"size"),r=2;return-1<(n=n||i(t,"fontSize")).indexOf("px")?((n=+n.replace("px",""))<12&&(r=1),15{!0}'},color:{tags:{font:{color:null}},styles:{color:null},quoteType:d.never,format:function(t,e){var n;return"[color="+I(n=a(t,"font")&&(n=o(t,"color"))?n:t.style.color||i(t,"color"))+"]"+e+"[/color]"},html:function(t,n,r){return''+r+""}},ul:{tags:{ul:null},breakStart:!0,isInline:!1,skipLastLineBreak:!0,format:"[ul]{0}[/ul]",html:""},list:{breakStart:!0,isInline:!1,skipLastLineBreak:!0,html:""},ol:{tags:{ol:null},breakStart:!0,isInline:!1,skipLastLineBreak:!0,format:"[ol]{0}[/ol]",html:"
    {0}
"},li:{tags:{li:null},isInline:!1,closedBy:["/ul","/ol","/list","*","li"],format:"[li]{0}[/li]",html:"
  • {0}
  • "},"*":{isInline:!1,closedBy:["/ul","/ol","/list","*","li"],html:"
  • {0}
  • "},table:{tags:{table:null},isInline:!1,isHtmlInline:!0,skipLastLineBreak:!0,format:"[table]{0}[/table]",html:"{0}
    "},tr:{tags:{tr:null},isInline:!1,skipLastLineBreak:!0,format:"[tr]{0}[/tr]",html:"{0}"},th:{tags:{th:null},allowsEmpty:!0,isInline:!1,format:"[th]{0}[/th]",html:"{0}"},td:{tags:{td:null},allowsEmpty:!0,isInline:!1,format:"[td]{0}[/td]",html:"{0}"},emoticon:{allowsEmpty:!0,tags:{img:{src:null,"data-sceditor-emoticon":null}},format:function(t,e){return o(t,c)+e},html:"{0}"},hr:{tags:{hr:null},allowsEmpty:!0,isSelfClosing:!0,isInline:!1,format:"[hr]{0}",html:"
    "},img:{allowsEmpty:!0,tags:{img:{src:null}},allowedChildren:["#"],quoteType:d.never,format:function(t,e){function n(e){return t.style?t.style[e]:null}var l,i="";return o(t,c)?e:(e=o(t,"width")||n("width"),l=o(t,"height")||n("height"),"[img"+(i=t.complete&&(e||l)||e&&l?"="+r.width(t)+"x"+r.height(t):i)+"]"+o(t,"src")+"[/img]")},html:function(t,r,l){var i="",o=r.width,a=r.height;return r.defaultattr&&(o=(r=r.defaultattr.split(/x/i))[0],a=2===r.length?r[1]:r[0]),void 0!==o&&(i+=' width="'+e(o,!0)+'"'),void 0!==a&&(i+=' height="'+e(a,!0)+'"'),"'}},url:{allowsEmpty:!0,tags:{a:{href:null}},quoteType:d.never,format:function(t,e){return"mailto:"===(t=o(t,"href")).substr(0,7)?'[email="'+t.substr(7)+'"]'+e+"[/email]":"[url="+t+"]"+e+"[/url]"},html:function(t,r,l){return r.defaultattr=e(r.defaultattr,!0)||l,''+l+""}},email:{quoteType:d.never,html:function(t,n,r){return''+r+""}},quote:{tags:{blockquote:null},isInline:!1,quoteType:d.never,format:function(t,e){for(var n,r="data-author",l="",i=t.children,s=0;!n&&s"+(r=n.defaultattr?""+e(n.defaultattr)+""+r:r)+""}},code:{tags:{code:null},isInline:!1,allowedChildren:["#","#newline"],format:"[code]{0}[/code]",html:"{0}"},left:{styles:{"text-align":["left","-webkit-left","-moz-left","-khtml-left"]},isInline:!1,allowsEmpty:!0,format:"[left]{0}[/left]",html:'
    {0}
    '},center:{styles:{"text-align":["center","-webkit-center","-moz-center","-khtml-center"]},isInline:!1,allowsEmpty:!0,format:"[center]{0}[/center]",html:'
    {0}
    '},right:{styles:{"text-align":["right","-webkit-right","-moz-right","-khtml-right"]},isInline:!1,allowsEmpty:!0,format:"[right]{0}[/right]",html:'
    {0}
    '},justify:{styles:{"text-align":["justify","-webkit-justify","-moz-justify","-khtml-justify"]},isInline:!1,allowsEmpty:!0,format:"[justify]{0}[/justify]",html:'
    {0}
    '},youtube:{allowsEmpty:!0,tags:{iframe:{"data-youtube-id":null}},format:function(t,e){return(t=o(t,"data-youtube-id"))?"[youtube]"+t+"[/youtube]":e},html:''},rtl:{styles:{direction:["rtl"]},isInline:!1,format:"[rtl]{0}[/rtl]",html:'
    {0}
    '},ltr:{styles:{direction:["ltr"]},isInline:!1,format:"[ltr]{0}[/ltr]",html:'
    {0}
    '},ignore:{}};function p(t,n){return t.replace(/\{([^}]+)\}/g,function(t,r){var l=!0;return"!"===r.charAt(0)&&(l=!1,r=r.substring(1)),"0"===r&&(l=!1),void 0===n[r]?t:l?e(n[r],!0):n[r]})}function g(t){return"function"==typeof t}function b(t){return t&&t.replace(/\\(.)/g,"$1").replace(/^(["'])(.*?)\1$/,"$2")}var y="open",v="content",x="newline",k="close";function w(t,e,n,r,l,i){var o=this;o.type=t,o.name=e,o.val=n,o.attrs=r||{},o.children=l||[],o.closing=i||null}function E(t){var n=this;function r(t,e){var n,r,l;return t===y&&(n=e.match(/\[([^\]\s=]+)(?:([^\]]+))?\]/))&&(l=c(n[1]),n[2])&&(n[2]=n[2].trim())&&(r=(t=>{var e,n=/([^\s=]+)=(?:(?:(["'])((?:\\\2|[^\2])*?)\2)|((?:.(?!\s\S+=))*.))/g,r={};if("="===t.charAt(0)&&t.indexOf("=",1)<0)r.defaultattr=b(t.substr(1));else for("="===t.charAt(0)&&(t="defaultattr"+t);e=n.exec(t);)r[c(e[1])]=b(e[3])||e[4];return r})(n[2])),t===k&&(n=e.match(/\[\/([^\[\]]+)\]/))&&(l=c(n[1])),(l=t===x?"#newline":l)&&(t!==y&&t!==k||m[l])||(t=v,l="#"),new w(t,l,e,r)}function l(t,e,n){for(var r=n.length;r--;)if(n[r].type===e&&n[r].name===t)return 1}function i(t,e){return t=(t?m[t.name]:{}).allowedChildren,!n.opts.fixInvalidChildren||!t||-1"),g(i.html)?i.html.call(n,l,l.attrs,a):(l.attrs[0]=a,p(i.html,l.attrs))):l.val+a+(l.closing?l.closing.val:"");else{if(l.type===x){if(!r){f+="
    ";continue}u||(f+="
    "),f+="
    ",t.length||(f+="
    "),f+="
    \n",u=!1;continue}s=r,c=e(l.val,!0)}s&&!u?(f+="
    ",u=!0):!s&&u&&(f+="
    \n",u=!1),f+=c}return u&&(f+="\n"),f}function a(t,e,n){var r=/\s|=/.test(t);return g(e)?e(t,n):e===d.never||e===d.auto&&!r?t:'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function u(t){return t.length?t[t.length-1]:null}function c(t){return t.toLowerCase()}n.opts=s({},E.defaults,t),n.tokenize=function(t){var e,n,l,i=[],o=[{type:v,regex:/^([^\[\r\n]+|\[)/},{type:x,regex:/^(\r\n|\r|\n)/},{type:y,regex:/^\[[^\[\]]+\]/},{type:k,regex:/^\[\/[^\[\]]+\]/}];t:for(;t.length;){for(l=o.length;l--;)if(n=o[l].type,(e=t.match(o[l].regex))&&e[0]){i.push(r(n,e[0])),t=t.substr(e[0].length);continue t}t.length&&i.push(r(v,t)),t=""}return i},n.parse=function(t,e){t=(t=>{function e(){return u(g)}function r(t){(e()?e().children:p).push(t)}function o(t){return e()&&(s=m[e().name])&&s.closedBy&&-1{var n=t.nodeName.toLowerCase(),l=r.isInline;if(!l(t,!0)||"br"===n){for(var i,o,s=t.previousSibling;s&&1===s.nodeType&&!a(s,"br")&&l(s,!0)&&!s.firstChild;)s=s.previousSibling;for(;i=((o=t.parentNode)&&o.lastChild)===t,(t=o)&&i&&l(o,!0););i&&"li"!==n||(e+="\n"),"br"!==n&&s&&!a(s,"br")&&l(s,!0)&&(e="\n"+e)}return e})(e,f)):u+=f):3===d&&(u+=e.nodeValue)},!1,!0),u}(t,e)}function d(e,n,r){var l=new E(t.opts.parserOptions);return(e||r?l.toHTMLFragment:l.toHTML)(t.opts.bbcodeTrim?n.trim():n)}function p(e,n,l,o){l=l||document;var a,s=!!r.closest(o,"code"),u=l.createElement("div"),c=l.createElement("div"),d=new E(t.opts.parserOptions);for(c.innerHTML=n,i(u,"visibility","hidden"),u.appendChild(c),l.body.appendChild(u),e&&(u.insertBefore(l.createTextNode("#"),u.firstChild),u.appendChild(l.createTextNode("#"))),o&&i(c,"whiteSpace",i(o,"whiteSpace")),a=c.getElementsByClassName("sceditor-ignore");a.length;)a[0].parentNode.removeChild(a[0]);return r.removeWhiteSpace(u),n=f(c,s),l.body.removeChild(u),n=d.toBBCode(n,!0),t.opts.bbcodeTrim?n.trim():n}t.init=function(){t.opts=this.opts,t.elementToBbcode=f,u(m,function(t,n){var r=!1===n.isInline,l=(n=m[t].tags,m[t].styles);l&&(e["*"]=e["*"]||{},e["*"][r]=e["*"][r]||{},e["*"][r][t]=[["style",Object.entries(l)]]),n&&u(n,function(n,l){l&&l.style&&(l.style=Object.entries(l.style)),e[n]=e[n]||{},e[n][r]=e[n][r]||{},e[n][r][t]=l&&Object.entries(l)})}),this.commands=s(!0,{},h,this.commands),this.toBBCode=t.toSource,this.fromBBCode=t.toHtml},t.toHtml=d.bind(null,!1),t.fragmentToHtml=d.bind(null,!0),t.toSource=p.bind(null,!1),t.fragmentToSource=p.bind(null,!0)}w.prototype={clone:function(){var t=this;return new w(t.type,t.name,t.val,s({},t.attrs),[],t.closing?t.closing.clone():null)},splitAt:function(t){var e,n=this.clone();return-1<(t=this.children.indexOf(t))&&(e=this.children.length-t,n.children=this.children.splice(t,e)),n}},E.QuoteType=d,E.defaults={breakBeforeBlock:!1,breakStartBlock:!1,breakEndBlock:!1,breakAfterBlock:!0,removeEmptyTags:!0,fixInvalidNesting:!0,fixInvalidChildren:!0,quoteType:d.auto,strictMatch:!1},C.get=function(t){return m[t]||null},C.set=function(t,e){return t&&e&&((e=s(m[t]||{},e)).remove=function(){delete m[t]},m[t]=e),this},C.rename=function(t,e){return t in m&&(m[e]=m[t],delete m[t]),this},C.remove=function(t){return t in m&&delete m[t],this},C.formatBBCodeString=p,t.formats.bbcode=C,t.BBCodeParser=E})(sceditor);