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