import { __exports as g } from "./index-LexicalText.dev2.js";
import { __require as k } from "./index-Lexical.js";
var y;
function D() {
  if (y) return g;
  y = 1;
  var r = k();
  function _(o, l) {
    let t = o.getFirstChild(), d = 0;
    e: for (; t !== null; ) {
      if (r.$isElementNode(t)) {
        const s = t.getFirstChild();
        if (s !== null) {
          t = s;
          continue;
        }
      } else if (r.$isTextNode(t)) {
        const s = t.getTextContentSize();
        if (d + s > l)
          return {
            node: t,
            offset: l - d
          };
        d += s;
      }
      const f = t.getNextSibling();
      if (f !== null) {
        t = f;
        continue;
      }
      let n = t.getParent();
      for (; n !== null; ) {
        const s = n.getNextSibling();
        if (s !== null) {
          t = s;
          continue e;
        }
        n = n.getParent();
      }
      break;
    }
    return null;
  }
  function $(o, l = !0) {
    if (o)
      return !1;
    let t = v();
    return l && (t = t.trim()), t === "";
  }
  function E(o, l) {
    return () => $(o, l);
  }
  function v() {
    return r.$getRoot().getTextContent();
  }
  function b(o) {
    if (!$(o, !1))
      return !1;
    const t = r.$getRoot().getChildren(), d = t.length;
    if (d > 1)
      return !1;
    for (let f = 0; f < d; f++) {
      const n = t[f];
      if (r.$isDecoratorNode(n))
        return !1;
      if (r.$isElementNode(n)) {
        if (!r.$isParagraphNode(n) || n.__indent !== 0)
          return !1;
        const s = n.getChildren(), N = s.length;
        for (let C = 0; C < N; C++) {
          const S = s[f];
          if (!r.$isTextNode(S))
            return !1;
        }
      }
    }
    return !0;
  }
  function P(o) {
    return () => b(o);
  }
  function L(o, l, t, d) {
    const f = (e) => e instanceof t, n = (e) => {
      const i = r.$createTextNode(e.getTextContent());
      i.setFormat(e.getFormat()), e.replace(i);
    }, s = (e) => e.getLatest().__mode, N = (e) => {
      if (!e.isSimpleText())
        return;
      const i = e.getPreviousSibling();
      let u = e.getTextContent(), x = e, c;
      if (r.$isTextNode(i)) {
        const T = i.getTextContent(), h = T + u, m = l(h);
        if (f(i))
          if (m === null || s(i) !== 0) {
            n(i);
            return;
          } else {
            const a = m.end - T.length;
            if (a > 0) {
              const p = u.slice(0, a), w = T + p;
              if (i.select(), i.setTextContent(w), a === u.length)
                e.remove();
              else {
                const F = u.slice(a);
                e.setTextContent(F);
              }
              return;
            }
          }
        else if (m === null || m.start < T.length)
          return;
      }
      for (; ; ) {
        c = l(u);
        let T = c === null ? "" : u.slice(c.end);
        if (u = T, T === "") {
          const a = x.getNextSibling();
          if (r.$isTextNode(a)) {
            T = x.getTextContent() + a.getTextContent();
            const p = l(T);
            if (p === null) {
              f(a) ? n(a) : a.markDirty();
              return;
            } else if (p.start !== 0)
              return;
          }
        } else {
          const a = l(T);
          if (a !== null && a.start === 0)
            return;
        }
        if (c === null)
          return;
        if (c.start === 0 && r.$isTextNode(i) && i.isTextEntity())
          continue;
        let h;
        c.start === 0 ? [h, x] = x.splitText(c.end) : [, h, x] = x.splitText(c.start, c.end);
        const m = d(h);
        if (m.setFormat(h.getFormat()), h.replace(m), x == null)
          return;
      }
    }, C = (e) => {
      const i = e.getTextContent(), u = l(i);
      if (u === null || u.start !== 0) {
        n(e);
        return;
      }
      if (i.length > u.end) {
        e.splitText(u.end);
        return;
      }
      const x = e.getPreviousSibling();
      r.$isTextNode(x) && x.isTextEntity() && (n(x), n(e));
      const c = e.getNextSibling();
      r.$isTextNode(c) && c.isTextEntity() && (n(c), f(e) && n(e));
    }, S = o.registerNodeTransform(r.TextNode, N), R = o.registerNodeTransform(t, C);
    return [S, R];
  }
  return g.$canShowPlaceholder = b, g.$canShowPlaceholderCurry = P, g.$findTextIntersectionFromCharacters = _, g.$isRootTextContentEmpty = $, g.$isRootTextContentEmptyCurry = E, g.$rootTextContent = v, g.registerLexicalTextEntity = L, g;
}
export {
  D as __require
};
