"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE","TD","TH"];function d(n){let t=n;if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(a.includes(e.tagName))return e}for(;t;){if(t.nodeType===Node.ELEMENT_NODE){const e=t;if(a.includes(e.tagName))return e;if(e.hasAttribute("contenteditable"))return null}t=t.parentNode}return null}function g(n){const t=[],e=d(n.startContainer),i=d(n.endContainer);if(!e&&!i)return t;if(n.collapsed)return e&&t.push(e),t;if(e===i)e&&t.push(e);else{let o=e;const s=new Set;for(e&&(t.push(e),s.add(e));o&&o!==i&&!s.has(i);){let r=o.nextElementSibling;for(;r;){if(a.includes(r.tagName)){o=r,s.has(o)||(t.push(o),s.add(o));break}r=r.nextElementSibling}if(!r)break}i&&!t.includes(i)&&t.push(i)}return t}function h(n){const t=n.commonAncestorContainer.nodeType===Node.ELEMENT_NODE?n.commonAncestorContainer:n.commonAncestorContainer.parentElement;return t?t.closest(".rte-content, .editora-content")||t.closest('[contenteditable="true"]'):null}function f(n,t){if(!n||t===n.innerHTML)return;const e=window.execEditorCommand||window.executeEditorCommand;if(typeof e=="function")try{e("recordDomTransaction",n,t,n.innerHTML)}catch{}}const E=n=>{if(!n||!["left","center","right","justify"].includes(n))return!1;const e=window.getSelection();if(!e||e.rangeCount===0)return!1;const i=e.getRangeAt(0).cloneRange(),o=h(i),s=o?.innerHTML||"",r=g(i);if(r.length>0)r.forEach(l=>{l&&(l.style.textAlign=n)}),e.removeAllRanges(),e.addRange(i),f(o,s),o&&o.dispatchEvent(new Event("input",{bubbles:!0}));else try{const l=document.createElement("div");l.style.textAlign=n;const m=i.extractContents();l.appendChild(m),i.insertNode(l);const u=document.createRange();u.selectNodeContents(l),e.removeAllRanges(),e.addRange(u);const c=l.closest(".rte-content, .editora-content")||l.closest('[contenteditable="true"]');f(c||o,s),(c||o)&&(c||o)?.dispatchEvent(new Event("input",{bubbles:!0}))}catch(l){return console.error("Failed to wrap content for alignment:",l),!1}return!0},b=()=>({name:"textAlignment",toolbar:[{label:"Text Alignment",command:"setTextAlignment",type:"inline-menu",options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Justify",value:"justify"}],icon:'<svg width="24" height="24" focusable="false"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2Zm0 4h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2Zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2Zm0-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2Z" fill-rule="evenodd"></path></svg>'}],commands:{setTextAlignment:E},keymap:{}});exports.TextAlignmentPlugin=b;
