froala-editor
Version:
The next generation Javascript WYSIWYG HTML rich text editor made by devs for devs. High performance and modern design make it easy to use for developers and loved by users.
7 lines (6 loc) • 16 kB
JavaScript
/*!
* froala_editor v5.1.0 (https://www.froala.com/wysiwyg-editor)
* License https://froala.com/wysiwyg-editor/terms/
* Copyright 2014-2026 Froala Labs
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(("undefined"!=typeof globalThis?globalThis:e||self).FroalaEditor)}(this,function(e){"use strict";function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function c(e,t,r,n,o,l,i){try{var a=e[l](i),c=a.value}catch(e){return r(e)}a.done?t(c):Promise.resolve(c).then(n,o)}function r(a){return function(){var e=this,i=arguments;return new Promise(function(t,r){var n=a.apply(e,i);function o(e){c(n,t,r,o,l,"next",e)}function l(e){c(n,t,r,o,l,"throw",e)}o(void 0)})}}function f(e,t){var r,n,o,l,i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(i)return o=!(n=!0),{s:function(){i=i.call(e)},n:function(){var e=i.next();return n=e.done,e},e:function(e){o=!0,r=e},f:function(){try{n||null==i["return"]||i["return"]()}finally{if(o)throw r}}};if(Array.isArray(e)||(i=function(e,t){{var r;if(e)return"string"==typeof e?a(e,t):"Map"===(r="Object"===(r={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}(e))||t)return i&&(e=i),l=0,{s:t=function(){},n:function(){return l>=e.length?{done:!0}:{done:!1,value:e[l++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function x(){var g,h,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",r=e.toStringTag||"@@toStringTag";function n(e,t,r,n){var o,l,i,a,c,s,u,d,f,t=t&&t.prototype instanceof y?t:y,t=Object.create(t.prototype);return m(t,"_invoke",(o=e,l=r,u=n||[],d=!1,f={p:s=0,n:0,v:g,a:p,f:p.bind(g,4),d:function(e,t){return i=e,a=0,c=g,f.n=t,b}},function(e,t,r){if(1<s)throw TypeError("Generator is already running");for(d&&1===t&&p(t,r),a=t,c=r;(h=a<2?g:c)||!d;){i||(a?a<3?(1<a&&(f.n=-1),p(a,c)):f.n=c:f.v=c);try{if(s=2,i){if(h=i[e=a?e:"next"]){if(!(h=h.call(i,c)))throw TypeError("iterator result is not an object");if(!h.done)return h;c=h.value,a<2&&(a=0)}else 1===a&&(h=i["return"])&&h.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+e+"' method"),a=1);i=g}else if((h=(d=f.n<0)?c:o.call(l,f))!==b)break}catch(h){i=g,a=1,c=h}finally{s=1}}return{value:h,done:d}}),!0),t;function p(e,t){for(a=e,c=t,h=0;!d&&s&&!r&&h<u.length;h++){var r,n=u[h],o=f.p,l=n[2];3<e?(r=l===t)&&(c=n[(a=n[4])?5:a=3],n[4]=n[5]=g):n[0]<=o&&((r=e<2&&o<n[1])?(a=0,f.v=t,f.n=n[1]):o<l&&(r=e<3||n[0]>t||l<t)&&(n[4]=e,n[5]=t,f.n=l,a=0))}if(r||1<e)return b;throw d=!0,t}}var b={};function y(){}function o(){}function l(){}h=Object.getPrototypeOf;var e=[][t]?h(h([][t]())):(m(h={},t,function(){return this}),h),i=l.prototype=y.prototype=Object.create(e);function a(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,m(e,r,"GeneratorFunction")),e.prototype=Object.create(i),e}return m(i,"constructor",o.prototype=l),m(l,"constructor",o),m(l,r,o.displayName="GeneratorFunction"),m(i),m(i,r,"Generator"),m(i,t,function(){return this}),m(i,"toString",function(){return"[object Generator]"}),(x=function(){return{w:n,m:a}})()}function m(e,t,r,n){var l=Object.defineProperty;try{l({},"",{})}catch(e){l=0}(m=function(e,t,r,n){function o(t,r){m(e,t,function(e){return this._invoke(t,r,e)})}t?l?l(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(o("next",0),o("throw",1),o("return",2))})(e,t,r,n)}Object.assign(e.POPUP_TEMPLATES,{"wordExport.error":"[_EXPORT_LAYER_]"}),Object.assign(e.DEFAULTS,{wordExportFileName:"froala_editor"}),e.PLUGINS.exportToWord=function(s){var u=s.$,d="";function p(e,t){t=new RegExp("\\b".concat(t,"\\s*:\\s*([^;]+)"),"i").exec(e);return t?t[1].trim():""}function a(){return(a=r(x().m(function e(t){var r,y,m,n,o,l,v,w;return x().w(function(e){for(;;)switch(e.n){case 0:for((r=document.createElement("div")).innerHTML=t,y=r.querySelectorAll("img"),m=s.el.querySelectorAll("img"),n=0;n<y.length;n++)o=y[n],(l=o.parentElement).classList.contains("fr-img-wrap")&&(o=l.parentElement,l=o.parentElement),l&&"SPAN"===l.tagName&&!l.classList.contains("fr-marker")&&(l.parentNode.insertBefore(o,l),0!==l.childNodes.length&&""!==l.textContent.trim()||l.remove());v=x().m(function v(){var t,r,n,o,l,i,a,c,s,u,d,f,p,g,h,b;return x().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=y[w],r=m[w],!(n=t.getAttribute("src"))||n.startsWith("data:"))return e.a(2,1);e.n=1;break;case 1:return r=r.closest("span.fr-img-caption")?r.closest("span.fr-img-caption"):r,c=r?window.getComputedStyle(r):{},o=c["float"]||"",l=c.height||t.getAttribute("height")||"100px",i=c.width||t.getAttribute("width")||"100px",a=c.marginLeft&&"0px"!==c.marginLeft?c.marginLeft:"",c=c.marginRight&&"0px"!==c.marginRight?c.marginRight:"",s="0px"===a||""==a?"left":"0px"===c||""===c?"right":"center",e.p=2,e.n=3,fetch(n).then(function(e){return e.blob()});case 3:return u=e.v,e.n=4,new Promise(function(e,t){var r=new FileReader;r.onloadend=function(){return e(r.result)},r.onerror=t,r.readAsDataURL(u)});case 4:f=e.v,(d=document.createElement("img")).setAttribute("src",f),d.setAttribute("width",parseInt(i)),d.setAttribute("height",parseInt(l)),d.style.display="block",f=t.closest("span.fr-img-caption")||null,p=null,f&&((p=document.createElement("table")).style.borderCollapse="collapse",p.style.margin="auto",p.classList.add("fr-img-caption"),h=document.createElement("tr"),(b=document.createElement("td")).style.textAlign="center",b.appendChild(d),h.appendChild(b),p.appendChild(h),b=document.createElement("tr"),(h=document.createElement("td")).style.textAlign="center",h.style.width=i+"px",g=f.querySelector("span.fr-inner"),g=g.cloneNode(!0),h.appendChild(g),b.appendChild(h),p.appendChild(b)),(g=f?p:d).style.display="inline-block","left"===o||"right"===o?(g.setAttribute("align",o),f?f.replaceWith(g):(g.style.margin="0 0 1em 1em",(h=document.createElement("p")).setAttribute("align",o),h.style.display="inline-block",h.appendChild(g),t.replaceWith(h))):"none"===o&&("5px"===a||"5px"===c?(g.setAttribute("align",s),g.style.textAlign=s,(f||t).replaceWith(g)):((b=document.createElement("div")).setAttribute("align",s),b.style.textAlign=s,b.appendChild(g),(f||t).replaceWith(b))),e.n=6;break;case 5:e.p=5,0;case 6:return e.a(2)}},v,null,[[2,5]])}),w=0;case 1:if(w<y.length)return e.d(function(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return{value:(e=e&&r>=e.length?void 0:e)&&e[r++],done:!e}}}}throw new TypeError(typeof e+" is not iterable")}(v()),2);e.n=4;break;case 2:if(e.v)return e.a(3,3);e.n=3;break;case 3:w++,e.n=1;break;case 4:return e.a(2,r.innerHTML)}},e)}))).apply(this,arguments)}function t(){return(t=r(x().m(function e(n){var o,l,i,a,c;return x().w(function(e){for(;;)switch(e.n){case 0:return l=s.$el.find(".fr-selected-cell"),o=s.$el.find(".fr-selection-handle-selected"),0<l.length&&l.each(function(){var e=u(this);e.removeClass("fr-selected-cell"),""===e.attr("class")&&e.removeAttr("class")}),0<o.length&&((l=u(this)).removeClass("fr-selection-handle-selected"),""===l.attr("class"))&&l.removeAttr("class"),s.popups.hideAll(),d=n||s.html.get(),o=!!s.opts.toolbarButtonsEnabledOnEditorOff.includes("export_to_word")||null,e.n=1,s.events.trigger("word.beforeExport",[d],o);case 1:if(!1===(d=e.v))return e.a(2,!1);e.n=2;break;case 2:s.popups.get("wordExport.error")||(t=s.language.translate("Export libraries are missing."),r=void 0,r="<div style='text-align:right;' class='fr-buttons'>\n <button class='fr-trim-button fr-plugins-ok'>".concat(s.language.translate("OK"),"</button> \n </div>"),t="<div style= 'padding:10px'>\n <div class = 'fr-message fr-error-message'><h3 style ='font-size: 16px; margin: 10px 10px;font-weight: normal;'>".concat(s.language.translate(t),"</h3></div>\n ").concat(r,"\n "),r=s.popups.create("wordExport.error",{export_layer:t}),s.popups.setContainer("wordExport.error",s.$tb),(t=r.find(".fr-plugins-ok")[0])&&t.addEventListener("click",function(e){s.popups.hide("wordExport.error"),e.preventDefault()}),0),window.htmlDocx&&window.saveAs?(l=window.htmlDocx.asBlob(d),i=s.opts.wordExportFileName,window.saveAs(l,i+".docx")):(i=s.$tb.find('.fr-command[data-cmd="export_to_word"]'),c=s.button.getPosition(i),a=c.left,c=c.top,s.popups.show("wordExport.error",a,c,i.outerHeight(),!0)),s.events.trigger("word.afterExport",[d],o);case 3:return e.a(2)}var t,r},e,this)}))).apply(this,arguments)}function c(e){var t=e.cloneNode(!0);return function u(e,t){var r,n=window.getComputedStyle(e),o=f(n);try{for(o.s();!(r=o.n()).done;){var l=r.value;t.style[l]=n.getPropertyValue(l)}}catch(s){o.e(s)}finally{o.f()}for(var i=Array.from(e.children),a=Array.from(t.children),c=0;c<i.length;c++)u(i[c],a[c])}(e,t),t}return s.events.on("word.beforeExport",function(){var t=r(x().m(function e(n){var o,l,i;return x().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,o=function o(e){e.style.clear="both";var t=e.previousElementSibling;if(t){t=t.querySelector("br");if(t)return void t.setAttribute("clear","all")}var t=document.createElement("p"),r=(t.style.cssText="margin:0;padding:0;line-height:0;font-size:0;",document.createElement("br"));r.setAttribute("clear","all"),t.appendChild(r),e.parentNode.insertBefore(t,e)},e.n=1,function(){return a.apply(this,arguments)}(n);case 1:return i=e.v,(l=document.createElement("div")).innerHTML=i,l.querySelectorAll(".fr-emoticon").forEach(function(e){var t,r=(e.getAttribute("style")||"").match(/url\(["']?(.*?)["']?\)/);r&&r[1]&&((t=document.createElement("img")).src=r[1],t.alt="emoji",t.setAttribute("width","20"),t.setAttribute("height","20"),e.replaceWith(t))}),l.querySelectorAll("table.fr-table-left-align, table.fr-table-right-align").forEach(function(e){e=e.nextElementSibling;e&&o(e)}),l.querySelectorAll("table[style]").forEach(function(e){var t=e.getAttribute("style")||"";/\bfloat\s*:\s*(left|right)\b/i.test(t)&&(t=e.nextElementSibling)&&o(t)}),l.querySelectorAll("table:not(.fr-img-caption)").forEach(function(e,t){e.setAttribute("border","1"),e.setAttribute("cellpadding","10"),e.setAttribute("cellspacing","0");var r,n=e.getAttribute("style")||"",o=s.el.querySelectorAll("table")[t],u=(t=n,(r=e).classList.contains("fr-table-left-no-wrap")?(r.style.marginLeft="0",r.style.marginRight="auto"):r.classList.contains("fr-table-right-no-wrap")?(r.style.marginLeft="auto",r.style.marginRight="0"):(l="left",r.classList.contains("fr-table-right-align")||/\bfloat\s*:\s*right\b/i.test(t)?l="right":!r.classList.contains("fr-table-left-align")&&/\bmargin\s*:\s*auto\b/i.test(t)&&(l="center"),r.setAttribute("align",l)),window.getComputedStyle(o).border||"1px solid #DDD"),d=(t=(t=u).match(/^(\d+(?:\.\d+)?)/))?parseFloat(t[1]):1,l=(e.style.borderCollapse=p(n,"border-collapse")||"collapse",e.querySelectorAll("tr")),f=l.length;l.forEach(function(e,a){var t=e.querySelectorAll("td, th"),c=t.length,s=o?o.querySelectorAll("tr")[a]:null;e.style.backgroundColor=window.getComputedStyle(s).backgroundColor||"",t.forEach(function(e,t){var r,n,o=s?s.querySelectorAll("td, th")[t]:null,o=window.getComputedStyle(o)||"",l=(e.style.padding="10px",e.style.height=e.style.height||"50px",e.setAttribute("valign","top"),e.style.verticalAlign="top",e.style.backgroundColor=o.backgroundColor,e.getAttribute("style")||""),i=(i={width:"1px",style:"solid",color:"#DDD"},(n=p(l=l,"border"))||(n=p(l,"border-width")||i.width,r=p(l,"border-style")||i.style,l=p(l,"border-color")||i.color,"".concat(n," ").concat(r," ").concat(l)));e.style.borderTop||(e.style.borderTop=i),e.style.borderBottom||(e.style.borderBottom=i),e.style.borderLeft||(e.style.borderLeft=i),e.style.borderRight||(e.style.borderRight=i),1<d&&(0===a&&(e.style.borderTop=u),a===f-1&&(e.style.borderBottom=u),0===t&&(e.style.borderLeft=u),t===c-1)&&(e.style.borderRight=u),e.style.borderStyle="none"!==o.borderStyle&&o.borderStyle?o.borderStyle:"solid"})})}),l.innerHTML=(t=l.innerHTML,t=(r=function(e,t,r){var n=new RegExp("<".concat(t,"(?:\\s[^>]*)?>"),"gi"),n=(e=e.replace(n,'<span style="'.concat(r,';">')),new RegExp("</".concat(t,">"),"gi"));return e=e.replace(n,"</span>")})(t,"strong","font-weight: bold"),t=r(t,"em","font-style: italic")),l.querySelectorAll('[data-title="PageBreak"]').forEach(function(e){var t=s.doc.createElement("span");t.innerHTML='<br clear=all style="mso-special-character:line-break;page-break-before:always">',e.replaceWith(t)}),l.querySelectorAll("[data-code-snippet]").forEach(function(e){var t=s.$el.find("#"+e.id),r=c(t[0]),n=s.doc.createElement("div"),r=r.querySelector("code");n.innerHTML='\n <table style="border-collapse: collapse;">\n <tr style="background: #ECECEC; padding: 10px; border-collapse: collapse;">\n <td>\n <p style="background: #ECECEC; margin:0; font-family: sans-serif; font-size: 14px;">'.concat(t.find(".fr-code-header div").text(),'</p>\n </td>\n </tr>\n <tr style="background: #f5f2f0; padding: 10px; border-collapse: collapse;">\n <td>\n <div style="background: #f5f2f0; margin:0; padding:0; line-height: 0px; text-box: none;"><pre>').concat(r.outerHTML,"</pre></div>\n </td>\n </tr>\n </table>\n "),e.replaceWith(n)}),i="\n <html xmlns:o='urn:schemas-microsoft-com:office:office'\n xmlns:w='urn:schemas-microsoft-com:office:word'\n xmlns='http://www.w3.org/TR/REC-html40'>\n <head><meta charset='utf-8'></head>\n <body>".concat(l.innerHTML,"</body>\n </html>"),e.a(2,i);case 2:return e.p=2,e.a(2,!1)}var t,r},e,null,[[0,2]])}));return function(e){return t.apply(this,arguments)}}()),{"export":function(e){return t.apply(this,arguments)}}},e.DefineIcon("export_to_word",{template:"svgMultiplePath",PATHS:'\n <path d="M22.5247 17.7645L18.6914 21.5978L14.858 17.7645L16.1997 16.4228L17.733 17.9561V13.9551H19.6497V17.9561L21.183 16.4228L22.5247 17.7645Z" fill="#333333"/>\n <path fill-rule="evenodd" clip-rule="evenodd" d="M9.06971 15.1051H2.62971C2.18513 15.1051 1.82471 14.7447 1.82471 14.3001V7.86008C1.82471 7.4155 2.18513 7.05508 2.62971 7.05508H9.06971C9.51429 7.05508 9.87471 7.4155 9.87471 7.86008V14.3001C9.87471 14.7447 9.51429 15.1051 9.06971 15.1051ZM4.50294 12.3628C4.49849 12.2917 4.48924 12.2085 4.47499 12.1129C4.46074 12.0176 4.44601 11.9408 4.43072 11.8829L3.74411 9.06758H2.83096L3.94451 13.0926H5.00877L5.715 10.4345C5.73029 10.3727 5.75058 10.2774 5.77579 10.1482C5.801 10.0191 5.81799 9.92188 5.82676 9.85639H5.83987C5.84641 9.91252 5.86338 10.0024 5.89076 10.1258C5.91814 10.2493 5.94277 10.3493 5.96468 10.4261L6.71689 13.0926H7.76482L8.86846 9.06758H7.97174L7.34101 11.8519C7.2972 12.0428 7.26984 12.2112 7.25888 12.3572H7.24577C7.21953 12.1457 7.18669 11.9718 7.14723 11.8352L6.35886 9.06758H5.37341L4.61139 11.8773C4.59384 11.9428 4.57571 12.0232 4.55712 12.1186C4.53853 12.2141 4.52596 12.2954 4.51937 12.3628H4.50294Z" fill="#333333"/>\n <path d="M5.27471 5.90508V4.37174C5.27471 3.84466 5.46238 3.39345 5.83773 3.0181C6.21307 2.64275 6.66429 2.45508 7.19137 2.45508H13.8997L19.6497 8.20508V11.104H17.733V9.16341H12.9414V4.37174H7.19137V5.90508H5.27471Z" fill="#333333"/>\n <path d="M5.83773 19.1421C6.21307 19.5174 6.66429 19.7051 7.19137 19.7051H12.9414V17.7884H7.19137V16.2551H5.27471V17.7884C5.27471 18.3155 5.46238 18.7667 5.83773 19.1421Z" fill="#333333"/>\n '}),e.RegisterCommand("export_to_word",{title:"Export to Word",focus:!1,undo:!1,refreshAfterCallback:!1,callback:function(){this.exportToWord["export"]()}})});