"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=40,s=e=>["P","DIV","H1","H2","H3","H4","H5","H6","LI","BLOCKQUOTE","PRE"].includes(e.tagName)&&e.getAttribute("contenteditable")!=="true",E=()=>{const e=window.getSelection();if(e&&e.rangeCount>0){let t=e.getRangeAt(0).startContainer;for(;t&&t!==document.body;){if(t.nodeType===Node.ELEMENT_NODE){const o=t;if(o.getAttribute("contenteditable")==="true")return o}t=t.parentNode}}const n=document.activeElement;if(n){if(n.getAttribute("contenteditable")==="true")return n;const t=n.closest('[contenteditable="true"]');if(t)return t}return document.querySelector('[contenteditable="true"]')},l=e=>{let n=e;if(n.nodeType===Node.ELEMENT_NODE){const t=n;if(s(t))return t}for(;n;){if(n.nodeType===Node.ELEMENT_NODE){const t=n;if(s(t))return t;if(t.getAttribute("contenteditable")==="true")break}n=n.parentNode}return null},p=(e,n)=>{const t=[],o=new Set,c=r=>{!r||o.has(r)||n.contains(r)&&s(r)&&(o.add(r),t.push(r))};if(e.collapsed)return c(l(e.startContainer)),t;const i=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const a=r;if(!s(a))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const u=document.createRange();return u.selectNodeContents(a),e.compareBoundaryPoints(Range.END_TO_START,u)>0&&e.compareBoundaryPoints(Range.START_TO_END,u)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let d=i.nextNode();for(;d;)c(d),d=i.nextNode();return t.length===0&&c(l(e.commonAncestorContainer)),t},h=e=>{const n=window.getComputedStyle(e),t=n.paddingLeft;if(t.endsWith("px"))return parseFloat(t);if(t.endsWith("em")){const o=parseFloat(n.fontSize);return parseFloat(t)*o}return 0},T=(e,n)=>{if(n===e.innerHTML)return;const t=window.execEditorCommand||window.executeEditorCommand;if(typeof t=="function")try{t("recordDomTransaction",e,n,e.innerHTML)}catch{}},b=()=>{const e=E();if(!e)return!1;const n=window.getSelection();if(!n||n.rangeCount===0)return!1;const t=n.getRangeAt(0);if(!e.contains(t.commonAncestorContainer))return!1;const o=p(t,e);if(o.length===0)return!1;const c=e.innerHTML;return o.forEach(i=>{const r=h(i)+m;i.style.paddingLeft=`${r}px`}),T(e,c),e.dispatchEvent(new Event("input",{bubbles:!0})),!0},v=()=>{const e=E();if(!e)return!1;const n=window.getSelection();if(!n||n.rangeCount===0)return!1;const t=n.getRangeAt(0);if(!e.contains(t.commonAncestorContainer))return!1;const o=p(t,e);if(o.length===0)return!1;const c=e.innerHTML;return o.forEach(i=>{const d=h(i),r=Math.max(0,d-m);i.style.paddingLeft=`${r}px`}),T(e,c),e.dispatchEvent(new Event("input",{bubbles:!0})),!0},f=(e,n)=>{typeof window<"u"&&window.registerEditorCommand?.(e,n)},g=()=>{f("increaseIndent",b),f("decreaseIndent",v)};typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",g):g());const w=()=>({name:"indent",toolbar:[{label:"Increase Indent",command:"increaseIndent",type:"button",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M3 4h18v2H3V4zm0 14h18v2H3v-2zm8-7h10v2H11v-2zm0 4h10v2H11v-2zM3 8l4 4-4 4V8z"/></svg>',shortcut:"Mod-]"},{label:"Decrease Indent",command:"decreaseIndent",type:"button",icon:'<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M3 4h18v2H3V4zm0 14h18v2H3v-2zm8-7h10v2H11v-2zm0 4h10v2H11v-2zM7 8v8l-4-4 4-4z"/></svg>',shortcut:"Mod-["}],commands:{increaseIndent:b,decreaseIndent:v},keymap:{"Mod-]":"increaseIndent","Mod-[":"decreaseIndent",Tab:"increaseIndent","Shift-Tab":"decreaseIndent"}});exports.IndentPlugin=w;
