const d = (n) => ["P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "LI", "BLOCKQUOTE", "PRE"].includes(n.tagName), u = () => {
  const n = window.getSelection();
  if (n && n.rangeCount > 0) {
    let e = n.getRangeAt(0).startContainer;
    for (; e && e !== document.body; ) {
      if (e.nodeType === Node.ELEMENT_NODE) {
        const o = e;
        if (o.getAttribute("contenteditable") === "true")
          return o;
      }
      e = e.parentNode;
    }
  }
  const t = document.activeElement;
  if (t) {
    if (t.getAttribute("contenteditable") === "true")
      return t;
    const e = t.closest('[contenteditable="true"]');
    if (e) return e;
  }
  return document.querySelector('[contenteditable="true"]');
}, s = (n) => {
  let t = n;
  if (t.nodeType === Node.ELEMENT_NODE) {
    const e = t;
    if (d(e))
      return e;
  }
  for (; t; ) {
    if (t.nodeType === Node.ELEMENT_NODE) {
      const e = t;
      if (d(e))
        return e;
      if (e.getAttribute("contenteditable") === "true")
        break;
    }
    t = t.parentNode;
  }
  return null;
}, f = (n) => {
  const t = [], e = s(n.startContainer), o = s(n.endContainer);
  if (!e && !o) return t;
  if (n.collapsed)
    return e && t.push(e), t;
  if (e === o)
    e && t.push(e);
  else {
    let r = e;
    for (; r && r !== o; ) {
      t.push(r);
      let i = r.nextElementSibling;
      for (; i && !d(i); )
        i = i.nextElementSibling;
      r = i;
    }
    o && o !== e && t.push(o);
  }
  return t;
}, g = (n) => {
  const t = window.getComputedStyle(n), e = t.paddingLeft;
  if (e.endsWith("px"))
    return parseFloat(e);
  if (e.endsWith("em")) {
    const o = parseFloat(t.fontSize);
    return parseFloat(e) * o;
  }
  return 0;
}, m = () => {
  const n = u();
  if (!n) return !1;
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return !1;
  const e = t.getRangeAt(0);
  if (!n.contains(e.commonAncestorContainer)) return !1;
  const o = f(e);
  return o.length === 0 ? !1 : (o.forEach((r) => {
    const a = g(r) + 40;
    r.style.paddingLeft = `${a}px`;
  }), !0);
}, h = () => {
  const n = u();
  if (!n) return !1;
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return !1;
  const e = t.getRangeAt(0);
  if (!n.contains(e.commonAncestorContainer)) return !1;
  const o = f(e);
  return o.length === 0 ? !1 : (o.forEach((r) => {
    const i = g(r), a = Math.max(0, i - 40);
    r.style.paddingLeft = `${a}px`;
  }), !0);
}, c = (n, t) => {
  var e;
  typeof window != "undefined" && ((e = window.registerEditorCommand) == null || e.call(window, n, t));
}, l = () => {
  c("increaseIndent", m), c("decreaseIndent", h);
};
typeof window != "undefined" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", l) : l());
const p = () => ({
  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: m,
    decreaseIndent: h
  },
  keymap: {
    "Mod-]": "increaseIndent",
    "Mod-[": "decreaseIndent",
    Tab: "increaseIndent",
    "Shift-Tab": "decreaseIndent"
  }
});
export {
  p as IndentPlugin,
  h as decreaseIndent,
  m as increaseIndent
};
//# sourceMappingURL=IndentPlugin.native-CbFugPoi.mjs.map
