import { ReplaceAroundStep as h, findWrapping as w, liftTarget as C, canJoin as L, canSplit as R } from "../../../../prosemirror-transform@1.10.4/node_modules/prosemirror-transform/dist/index.js";
import { Fragment as s, Slice as I, NodeRange as x } from "../../../../prosemirror-model@1.25.1/node_modules/prosemirror-model/dist/index.js";
function O(r, t = null) {
  return function(e, l) {
    let { $from: o, $to: n } = e.selection, f = o.blockRange(n);
    if (!f)
      return !1;
    let i = l ? e.tr : null;
    return S(i, f, r, t) ? (l && l(i.scrollIntoView()), !0) : !1;
  };
}
function S(r, t, e, l = null) {
  let o = !1, n = t, f = t.$from.doc;
  if (t.depth >= 2 && t.$from.node(t.depth - 1).type.compatibleContent(e) && t.startIndex == 0) {
    if (t.$from.index(t.depth - 1) == 0)
      return !1;
    let d = f.resolve(t.start - 2);
    n = new x(d, d, t.depth), t.endIndex < t.parent.childCount && (t = new x(t.$from, f.resolve(t.$to.end(t.depth)), t.depth)), o = !0;
  }
  let i = w(n, e, l, t);
  return i ? (r && v(r, t, i, o, e), !0) : !1;
}
function v(r, t, e, l, o) {
  let n = s.empty;
  for (let u = e.length - 1; u >= 0; u--)
    n = s.from(e[u].type.create(e[u].attrs, n));
  r.step(new h(t.start - (l ? 2 : 0), t.end, t.start, t.end, new I(n, 0, 0), e.length, !0));
  let f = 0;
  for (let u = 0; u < e.length; u++)
    e[u].type == o && (f = u + 1);
  let i = e.length - f, d = t.start + e.length - (l ? 2 : 0), c = t.parent;
  for (let u = t.startIndex, m = t.endIndex, p = !0; u < m; u++, p = !1)
    !p && R(r.doc, d, i) && (r.split(d, i), d += 2 * i), d += c.child(u).nodeSize;
  return r;
}
function V(r) {
  return function(t, e) {
    let { $from: l, $to: o } = t.selection, n = l.blockRange(o, (f) => f.childCount > 0 && f.firstChild.type == r);
    return n ? e ? l.node(n.depth - 1).type == r ? b(t, e, r, n) : k(t, e, n) : !0 : !1;
  };
}
function b(r, t, e, l) {
  let o = r.tr, n = l.end, f = l.$to.end(l.depth);
  n < f && (o.step(new h(n - 1, f, n, f, new I(s.from(e.create(null, l.parent.copy())), 1, 0), 1, !0)), l = new x(o.doc.resolve(l.$from.pos), o.doc.resolve(f), l.depth));
  const i = C(l);
  if (i == null)
    return !1;
  o.lift(l, i);
  let d = o.doc.resolve(o.mapping.map(n, -1) - 1);
  return L(o.doc, d.pos) && d.nodeBefore.type == d.nodeAfter.type && o.join(d.pos), t(o.scrollIntoView()), !0;
}
function k(r, t, e) {
  let l = r.tr, o = e.parent;
  for (let a = e.end, $ = e.endIndex - 1, y = e.startIndex; $ > y; $--)
    a -= o.child($).nodeSize, l.delete(a - 1, a + 1);
  let n = l.doc.resolve(e.start), f = n.nodeAfter;
  if (l.mapping.map(e.end) != e.start + n.nodeAfter.nodeSize)
    return !1;
  let i = e.startIndex == 0, d = e.endIndex == o.childCount, c = n.node(-1), u = n.index(-1);
  if (!c.canReplace(u + (i ? 0 : 1), u + 1, f.content.append(d ? s.empty : s.from(o))))
    return !1;
  let m = n.pos, p = m + f.nodeSize;
  return l.step(new h(m - (i ? 1 : 0), p + (d ? 1 : 0), m + 1, p - 1, new I((i ? s.empty : s.from(o.copy(s.empty))).append(d ? s.empty : s.from(o.copy(s.empty))), i ? 0 : 1, d ? 0 : 1), i ? 0 : 1)), t(l.scrollIntoView()), !0;
}
function B(r) {
  return function(t, e) {
    let { $from: l, $to: o } = t.selection, n = l.blockRange(o, (c) => c.childCount > 0 && c.firstChild.type == r);
    if (!n)
      return !1;
    let f = n.startIndex;
    if (f == 0)
      return !1;
    let i = n.parent, d = i.child(f - 1);
    if (d.type != r)
      return !1;
    if (e) {
      let c = d.lastChild && d.lastChild.type == i.type, u = s.from(c ? r.create() : null), m = new I(s.from(r.create(null, s.from(i.type.create(null, u)))), c ? 3 : 1, 0), p = n.start, a = n.end;
      e(t.tr.step(new h(p - (c ? 3 : 1), a, p, a, m, 1, !0)).scrollIntoView());
    }
    return !0;
  };
}
export {
  V as liftListItem,
  B as sinkListItem,
  O as wrapInList,
  S as wrapRangeInList
};
//# sourceMappingURL=index.js.map
