function t(t,n){for(;t&&t!==n;){if(t instanceof HTMLElement){const n=getComputedStyle(t).display;if(t.tagName.match(/^(P|DIV|H1|H2|H3|H4|H5|H6|LI)$/)||"block"===n||"list-item"===n)return t}t=t?.parentNode||null}return n}function n(n,e){const o=document.getSelection();if(!o||0===o.rangeCount)return;const r=t(o.getRangeAt(0).startContainer,n);if(!r)return;if(r.tagName.toLowerCase()===e)return;const c=document.createElement(e);for(;r.firstChild;)c.appendChild(r.firstChild);r.replaceWith(c);const i=document.createRange();i.selectNodeContents(c),i.collapse(!0),o.removeAllRanges(),o.addRange(i)}function e(n,e){const o=window.getSelection();if(!o||0===o.rangeCount)return;const r=o.getRangeAt(0),c=r.commonAncestorContainer,i=[],u=document.createTreeWalker(c,NodeFilter.SHOW_ELEMENT,{acceptNode:t=>{const n=t;return r.intersectsNode(n)&&/^(P|DIV|LI|H[1-6])$/.test(n.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let f=u.nextNode();for(;f;)i.push(f),f=u.nextNode();if(0===i.length){const e=t(o.focusNode,n);e&&i.push(e)}i.forEach((t=>{t.style.textAlign=e}))}function o(t){for(;t&&!(t instanceof HTMLElement);)t=t.parentNode;return t}export{n as a,t as c,o as n,e as s};
