/*! * @plugin @tinymce-plugin/tp-layout * @version 0.0.2 (2022-8-3) * @description 一键排版 * @copyright (2022) Five(Li Hailong) . All rights reserved. https://github.com/tinymce-plugin/tp-layout */(function(){"use strict";var w=function(e){return e.getParam("tp_layout_options",{selection:"p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote",clearStyle:[],filterTags:["table>*","img"],style:{"text-align":"justify","text-indent":"2em","line-height":1.5},tagsStyle:{}})},g={},o={},A=function(e){var a=e.dom,u=[],h=tinymce.util.Tools.resolve("tinymce.util.Tools");e.execCommand("selectAll");var n=w(e);for(var c in n.filterTags)n.filterTags[c].indexOf(">*")!=-1?o[n.filterTags[c].replace(">*","").toUpperCase()]=!0:g[n.filterTags[c].toUpperCase()]=!0;n.selection=n.selection||"p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote";for(var c in n.tagsStyle){var f=c.split(",");n.selection+=","+c;for(var S in f)f[S].indexOf(">*")!=-1?o[f[S].replace(">*","").toUpperCase()]=c:g[f[S].toUpperCase()]=c}u=e.selection.getNode().querySelectorAll(n.selection);function N(t,s){var i=s.match(new RegExp(t+':?(.+?)"?[;}]'));return i?i[1]:!1}function C(t,s){var i="BODY",r=t.tagName;if(g[r]||o[r])return!n.tagsStyle[g[r]]||s?s&&m(t,n.tagsStyle[g[r]]):v(t,n.tagsStyle[g[r]]),!0;for(var l=t.parentNode,y=l.tagName;y!==i;){var V=l;if(r=y+">"+r,g[r]||o[y])return!n.tagsStyle[o[y]]||s?s&&m(t,n.tagsStyle[o[y]]):v(t,n.tagsStyle[o[y]]),!n.tagsStyle[g[r]]||s?s&&m(t,n.tagsStyle[g[r]]):v(t,n.tagsStyle[g[r]]),!0;l=V.parentNode,y=l.tagName}return!1}function O(t){var s=a.getAttrib(t,"style");for(var i in n.clearStyle){var r=new RegExp(n.clearStyle[i]+':?(.+?)"?[;}]');s=s.replace(r,"")}a.setAttrib(t,"style",s)}function m(t,s){var i=a.getAttrib(t,"style");for(var r in s){var l=new RegExp(r+':?(.+?)"?[;}]');i=i.replace(l,"")}a.setAttrib(t,"style",i)}function v(t,s){for(var i in s)a.setStyle(t,i,s[i]);if(s["text-indent"]){var r="",l="";t&&t.children[0]&&t.children[0].attributes&&t.children[0].attributes.style&&(r=N("font-size",t.children[0].attributes.style.textContent),l=N("letter-spacing",t.children[0].attributes.style.textContent),r?r=(parseInt(r)+parseInt(l||0))*2+"px":r=(parseInt(l||0)+16)*2+"px"),a.setStyle(t,"text-indent",n.style["text-indent"]&&n.style["text-indent"]!="2em"?n.style["text-indent"]:r||"2em")}}var p="";u[0]&&(u[0].dataset.layoutFv=u[0].dataset.layoutFv?"":u[0].dataset.layoutFv="layoutFV"),h.each(u,function(t){p==""&&(a.hasClass(t,"layoutFV")?(p="remove",a.removeClass(t,"layoutFV")):(p="add",a.addClass(t,"layoutFV"))),p=="add"?(C(t)||v(t,n.style),n.clearStyle&&O(t)):C(t,"remove")||m(t,n.style)})},d=function(e,a){e.undoManager.transact(function(){e.focus(),A(e)})},F=function(e,a){e.ui.registry.getAll().icons[a.registryName]||e.ui.registry.addIcon(a.registryName,a.icon),e.ui.registry.addToggleButton(a.registryName,{icon:a.registryName,tooltip:a.title,onAction:function(){return d(e)}}),e.ui.registry.addMenuItem(a.registryName,{icon:a.registryName,text:a.title,onAction:function(){return d(e)}})},M=function(e,a){e.addCommand("mce".concat(a.registryName.substring(0,1).toUpperCase()+a.registryName.substring(1)),function(u,h){d(e)})},T=function(e,a){tinymce.util.XHR.send({url:e.tp$.isDev()?"/langs/i18n.json":e.editorManager.PluginManager.urls[a.registryName]+"/langs/i18n.json",async:!1,success:function(u){console.log(u);try{e.tp$.I18n.add(e.settings.language,JSON.parse(u)[e.settings.language])}catch{}}})},z=function(e){tinymce.PluginManager.add(e.registryName,function(a,u){return T(a,e),F(a,e),M(a,e),{getMetadata:function(){return{name:e.name,url:e.repo}}}})},x={name:"Layout",registryName:"tpLayout",title:"One click layout",repo:"https://github.com/tinymce-plugin/tp-layout",icon:''};z(x);var I={opt:x};return I})();