import{r as e}from"./rolldown-runtime.WmLfqUcM.js";var t=e({plugin_exports:()=>n});(function(){var e=hugerte.util.Tools.resolve(`hugerte.PluginManager`),t=hugerte.util.Tools.resolve(`hugerte.dom.RangeUtils`),n=hugerte.util.Tools.resolve(`hugerte.util.Tools`);let r=e=>t=>t.options.get(e),i=e=>{let t=e.options.register;t(`allow_html_in_named_anchor`,{processor:`boolean`,default:!1})},a=r(`allow_html_in_named_anchor`),o=`a:not([href])`,s=e=>!e,c=e=>e.getAttribute(`id`)||e.getAttribute(`name`)||``,l=e=>e.nodeName.toLowerCase()===`a`,u=e=>l(e)&&!e.getAttribute(`href`)&&c(e)!==``,d=e=>u(e)&&!e.firstChild,f=e=>{let r=e.dom;t(r).walk(e.selection.getRng(),e=>{n.each(e,e=>{d(e)&&r.remove(e,!1)})})},p=e=>/^[A-Za-z][A-Za-z0-9\-:._]*$/.test(e),m=e=>e.dom.getParent(e.selection.getStart(),o),h=e=>{let t=m(e);return t?c(t):``},g=(e,t)=>{e.undoManager.transact(()=>{a(e)||e.selection.collapse(!0),e.selection.isCollapsed()?e.insertContent(e.dom.createHTML(`a`,{id:t})):(f(e),e.formatter.remove(`namedAnchor`,void 0,void 0,!0),e.formatter.apply(`namedAnchor`,{value:t}),e.addVisual())})},_=(e,t,n)=>{n.removeAttribute(`name`),n.id=t,e.addVisual(),e.undoManager.add()},v=(e,t)=>{let n=m(e);n?_(e,t,n):g(e,t),e.focus()},y=(e,t)=>p(t)?(v(e,t),!0):(e.windowManager.alert(`ID should start with a letter, followed only by letters, numbers, dashes, dots, colons or underscores.`),!1),b=e=>{let t=h(e);e.windowManager.open({title:`Anchor`,size:`normal`,body:{type:`panel`,items:[{name:`id`,type:`input`,label:`ID`,placeholder:`example`}]},buttons:[{type:`cancel`,name:`cancel`,text:`Cancel`},{type:`submit`,name:`save`,text:`Save`,primary:!0}],initialData:{id:t},onSubmit:t=>{y(e,t.getData().id)&&t.close()}})},x=e=>{e.addCommand(`mceAnchor`,()=>{b(e)})},S=e=>s(e.attr(`href`))&&!s(e.attr(`id`)||e.attr(`name`)),C=e=>S(e)&&!e.firstChild,w=e=>t=>{for(let n=0;n<t.length;n++){let r=t[n];C(r)&&r.attr(`contenteditable`,e)}},T=e=>{e.on(`PreInit`,()=>{e.parser.addNodeFilter(`a`,w(`false`)),e.serializer.addNodeFilter(`a`,w(null))})},E=e=>{e.formatter.register(`namedAnchor`,{inline:`a`,selector:o,remove:`all`,split:!0,deep:!0,attributes:{id:`%value`},onmatch:(e,t,n)=>u(e)})},D=e=>t=>{let n=()=>{t.setEnabled(e.selection.isEditable())};return e.on(`NodeChange`,n),n(),()=>{e.off(`NodeChange`,n)}},O=e=>{let t=()=>e.execCommand(`mceAnchor`);e.ui.registry.addToggleButton(`anchor`,{icon:`bookmark`,tooltip:`Anchor`,onAction:t,onSetup:t=>{let n=e.selection.selectorChangedWithUnbind(`a:not([href])`,t.setActive).unbind,r=D(e)(t);return()=>{n(),r()}}}),e.ui.registry.addMenuItem(`anchor`,{icon:`bookmark`,text:`Anchor...`,onAction:t,onSetup:D(e)})};e.add(`anchor`,e=>{i(e),T(e),x(e),O(e),e.on(`PreInit`,()=>{E(e)})})})();var n={};export{t};