UNPKG

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) 15 kB
/*! * froala_editor v5.0.1 (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,i,l){try{var a=e[i](l),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,l=arguments;return new Promise(function(t,r){var n=a.apply(e,l);function o(e){c(n,t,r,o,i,"next",e)}function i(e){c(n,t,r,o,i,"throw",e)}o(void 0)})}}function f(e,t){var r,n,o,i,l="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(l)return o=!(n=!0),{s:function(){l=l.call(e)},n:function(){var e=l.next();return n=e.done,e},e:function(e){o=!0,r=e},f:function(){try{n||null==l["return"]||l["return"]()}finally{if(o)throw r}}};if(Array.isArray(e)||(l=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 l&&(e=l),i=0,{s:t=function(){},n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},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 h,g,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",r=e.toStringTag||"@@toStringTag";function n(e,t,r,n){var o,i,l,a,c,s,u,d,f,t=t&&t.prototype instanceof m?t:m,t=Object.create(t.prototype);return b(t,"_invoke",(o=e,i=r,u=n||[],d=!1,f={p:s=0,n:0,v:h,a:p,f:p.bind(h,4),d:function(e,t){return l=e,a=0,c=h,f.n=t,y}},function(e,t,r){if(1<s)throw TypeError("Generator is already running");for(d&&1===t&&p(t,r),a=t,c=r;(g=a<2?h:c)||!d;){l||(a?a<3?(1<a&&(f.n=-1),p(a,c)):f.n=c:f.v=c);try{if(s=2,l){if(g=l[e=a?e:"next"]){if(!(g=g.call(l,c)))throw TypeError("iterator result is not an object");if(!g.done)return g;c=g.value,a<2&&(a=0)}else 1===a&&(g=l["return"])&&g.call(l),a<2&&(c=TypeError("The iterator does not provide a '"+e+"' method"),a=1);l=h}else if((g=(d=f.n<0)?c:o.call(i,f))!==y)break}catch(g){l=h,a=1,c=g}finally{s=1}}return{value:g,done:d}}),!0),t;function p(e,t){for(a=e,c=t,g=0;!d&&s&&!r&&g<u.length;g++){var r,n=u[g],o=f.p,i=n[2];3<e?(r=i===t)&&(c=n[(a=n[4])?5:a=3],n[4]=n[5]=h):n[0]<=o&&((r=e<2&&o<n[1])?(a=0,f.v=t,f.n=n[1]):o<i&&(r=e<3||n[0]>t||i<t)&&(n[4]=e,n[5]=t,f.n=i,a=0))}if(r||1<e)return y;throw d=!0,t}}var y={};function m(){}function o(){}function i(){}g=Object.getPrototypeOf;var e=[][t]?g(g([][t]())):(b(g={},t,function(){return this}),g),l=i.prototype=m.prototype=Object.create(e);function a(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,i):(e.__proto__=i,b(e,r,"GeneratorFunction")),e.prototype=Object.create(l),e}return b(l,"constructor",o.prototype=i),b(i,"constructor",o),b(i,r,o.displayName="GeneratorFunction"),b(l),b(l,r,"Generator"),b(l,t,function(){return this}),b(l,"toString",function(){return"[object Generator]"}),(x=function(){return{w:n,m:a}})()}function b(e,t,r,n){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}(b=function(e,t,r,n){function o(t,r){b(e,t,function(e){return this._invoke(t,r,e)})}t?i?i(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 l(){return(l=r(x().m(function e(t){var r,m,b,n,o,i,v,w;return x().w(function(e){for(;;)switch(e.n){case 0:for((r=document.createElement("div")).innerHTML=t,m=r.querySelectorAll("img"),b=s.el.querySelectorAll("img"),n=0;n<m.length;n++)o=m[n],(i=o.parentElement).classList.contains("fr-img-wrap")&&(o=i.parentElement,i=o.parentElement),i&&"SPAN"===i.tagName&&!i.classList.contains("fr-marker")&&(i.parentNode.insertBefore(o,i),0!==i.childNodes.length&&""!==i.textContent.trim()||i.remove());v=x().m(function v(){var t,r,n,o,i,l,a,c,s,u,d,f,p,h,g,y;return x().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=m[w],r=b[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"]||"",i=c.height||t.getAttribute("height")||"100px",l=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(l)),d.setAttribute("height",parseInt(i)),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"),g=document.createElement("tr"),(y=document.createElement("td")).style.textAlign="center",y.appendChild(d),g.appendChild(y),p.appendChild(g),y=document.createElement("tr"),(g=document.createElement("td")).style.textAlign="center",g.style.width=l+"px",h=f.querySelector("span.fr-inner"),h=h.cloneNode(!0),g.appendChild(h),y.appendChild(g),p.appendChild(y)),(h=f?p:d).style.display="inline-block","left"===o||"right"===o?(h.setAttribute("align",o),f?f.replaceWith(h):(h.style.margin="0 0 1em 1em",(g=document.createElement("p")).setAttribute("align",o),g.style.display="inline-block",g.appendChild(h),t.replaceWith(g))):"none"===o&&("5px"===a||"5px"===c?(h.setAttribute("align",s),h.style.textAlign=s,(f||t).replaceWith(h)):((y=document.createElement("div")).setAttribute("align",s),y.style.textAlign=s,y.appendChild(h),(f||t).replaceWith(y))),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<m.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,i,l,a,c;return x().w(function(e){for(;;)switch(e.n){case 0:return i=s.$el.find(".fr-selected-cell"),o=s.$el.find(".fr-selection-handle-selected"),0<i.length&&i.each(function(){var e=u(this);e.removeClass("fr-selected-cell"),""===e.attr("class")&&e.removeAttr("class")}),0<o.length&&((i=u(this)).removeClass("fr-selection-handle-selected"),""===i.attr("class"))&&i.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?(i=window.htmlDocx.asBlob(d),l=s.opts.wordExportFileName,window.saveAs(i,l+".docx")):(l=s.$tb.find('.fr-command[data-cmd="export_to_word"]'),c=s.button.getPosition(l),a=c.left,c=c.top,s.popups.show("wordExport.error",a,c,l.outerHeight(),!0)),s.events.trigger("word.afterExport",[d],o);case 3:return e.a(2)}var t,r},e,this)}))).apply(this,arguments)}function a(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 i=r.value;t.style[i]=n.getPropertyValue(i)}}catch(s){o.e(s)}finally{o.f()}for(var l=Array.from(e.children),a=Array.from(t.children),c=0;c<l.length;c++)u(l[c],a[c])}(e,t),t}return s.events.on("word.beforeExport",function(){var t=r(x().m(function e(n){var o,i;return x().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,function(){return l.apply(this,arguments)}(n);case 1:return i=e.v,(o=document.createElement("div")).innerHTML=i,o.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))}),o.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=e,i="left",/\bfloat\s*:\s*right\b/i.test(r=n)?i="right":/\bmargin\s*:\s*auto\b/i.test(r)&&(i="center"),t.setAttribute("align",i),window.getComputedStyle(o).border||"1px solid #DDD"),d=(r=(r=u).match(/^(\d+(?:\.\d+)?)/))?parseFloat(r[1]):1,i=(e.style.borderCollapse=p(n,"border-collapse")||"collapse",e.querySelectorAll("tr")),f=i.length;i.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)||"",i=(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")||""),l=(l={width:"1px",style:"solid",color:"#DDD"},(n=p(i=i,"border"))||(n=p(i,"border-width")||l.width,r=p(i,"border-style")||l.style,i=p(i,"border-color")||l.color,"".concat(n," ").concat(r," ").concat(i)));e.style.borderTop||(e.style.borderTop=l),e.style.borderBottom||(e.style.borderBottom=l),e.style.borderLeft||(e.style.borderLeft=l),e.style.borderRight||(e.style.borderRight=l),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"})})}),o.innerHTML=(t=o.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")),o.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)}),o.querySelectorAll("[data-code-snippet]").forEach(function(e){var t=s.$el.find("#"+e.id),r=a(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(o.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"]()}})});