import { __exports as d } from "./index-LexicalDragon.dev2.js";
import { __require as T } from "./index-Lexical.js";
var _;
function R() {
  if (_) return d;
  _ = 1;
  var a = T();
  function L(l) {
    const N = window.location.origin, u = (c) => {
      if (c.origin !== N)
        return;
      const v = l.getRootElement();
      if (document.activeElement !== v)
        return;
      const m = c.data;
      if (typeof m == "string") {
        let n;
        try {
          n = JSON.parse(m);
        } catch {
          return;
        }
        if (n && n.protocol === "nuanria_messaging" && n.type === "request") {
          const i = n.payload;
          if (i && i.functionId === "makeChanges") {
            const f = i.args;
            if (f) {
              const [g, p, x, h, w, q] = f;
              l.update(() => {
                const o = a.$getSelection();
                if (a.$isRangeSelection(o)) {
                  const S = o.anchor;
                  let e = S.getNode(), t = 0, r = 0;
                  if (a.$isTextNode(e) && g >= 0 && p >= 0 && (t = g, r = g + p, o.setTextNodeRange(e, t, e, r)), (t !== r || x !== "") && (o.insertRawText(x), e = S.getNode()), a.$isTextNode(e)) {
                    t = h, r = h + w;
                    const s = e.getTextContentSize();
                    t = t > s ? s : t, r = r > s ? s : r, o.setTextNodeRange(e, t, e, r);
                  }
                  c.stopImmediatePropagation();
                }
              });
            }
          }
        }
      }
    };
    return window.addEventListener("message", u, !0), () => {
      window.removeEventListener("message", u, !0);
    };
  }
  return d.registerDragonSupport = L, d;
}
export {
  R as __require
};
