import { o as ne, E as je, I as ve, $ as we, K as ie, a as Ee, i as Ce, c as Se, p as Y, b as Te, t as se, v as $e, n as X, G as he, f as Pe, U as ae, d as ke, u as ze, g as Re, e as pe, j as m, h as Le, k as ee, l as te, m as le, q as De, r as K, S as Be, C as He, N as Ie, O as Fe, s as Me, w as _e, x as We, y as Oe, z as Ae, A as Ke, L as Ue, B as Ge, D as Xe, F as Ye, H as Ve, P as Ze, J as qe, M as Je } from "./index-Buqt2Jsq.js";
import * as H from "react";
import { useEffect as G, useCallback as U, forwardRef as Qe, useState as M, useRef as A, useMemo as et, Suspense as tt } from "react";
import { l as nt } from "./LexicalCollaborationContext.prod-CKLiaJe8.js";
import { _ as rt, c as st } from "./collaboration-Dl2h9xXg.js";
import { p as ot } from "./LexicalNestedComposer.prod-CHMPrVx_.js";
const ce = /* @__PURE__ */ new Map([
  [":)", ["emoji happysmile", "🙂"]],
  [":D", ["emoji veryhappysmile", "😀"]],
  [":(", ["emoji unhappysmile", "🙁"]],
  ["<3", ["emoji heart", "❤"]],
  ["🙂", ["emoji happysmile", "🙂"]],
  ["😀", ["emoji veryhappysmile", "😀"]],
  ["🙁", ["emoji unhappysmile", "🙁"]],
  ["❤", ["emoji heart", "❤"]]
]);
function it(e) {
  const t = e.getTextContent();
  for (let n = 0; n < t.length; n++) {
    const a = ce.get(t[n]) || ce.get(t.slice(n, n + 2));
    if (a !== void 0) {
      const [y, f] = a;
      let o;
      n === 0 ? [o] = e.splitText(n + 2) : [, o] = e.splitText(n, n + 2);
      const h = we(y, f);
      return o.replace(h), h;
    }
  }
  return null;
}
function at(e) {
  let t = e;
  for (; t !== null; ) {
    if (!t.isSimpleText())
      return;
    t = it(t);
  }
}
function lt(e) {
  G(() => {
    if (!e.hasNodes([je]))
      throw new Error("EmojisPlugin: EmojiNode not registered on editor");
    return e.registerNodeTransform(ve, at);
  }, [e]);
}
function ct() {
  const [e] = ne();
  return lt(e), null;
}
const ut = /(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])(congrats|congratulations|gratuluju|gratuluji|gratulujeme|blahopřeju|blahopřeji|blahopřejeme|Til lykke|Tillykke|Glückwunsch|Gratuliere|felicitaciones|enhorabuena|paljon onnea|onnittelut|Félicitations|gratula|gratulálok|gratulálunk|congratulazioni|complimenti|おめでとう|おめでとうございます|축하해|축하해요|gratulerer|Gefeliciteerd|gratulacje|Parabéns|parabéns|felicitações|felicitări|мои поздравления|поздравляем|поздравляю|gratulujem|blahoželám|ยินดีด้วย|ขอแสดงความยินดี|tebrikler|tebrik ederim|恭喜|祝贺你|恭喜你|恭喜|恭喜|baie geluk|veels geluk|অভিনন্দন|Čestitam|Čestitke|Čestitamo|Συγχαρητήρια|Μπράβο|અભિનંદન|badhai|बधाई|अभिनंदन|Честитам|Свака част|hongera|வாழ்த்துகள்|வாழ்த்துக்கள்|అభినందనలు|അഭിനന്ദനങ്ങൾ|Chúc mừng|מזל טוב|mazel tov|mazal tov)(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])/i;
function dt() {
  const [e] = ne();
  G(() => {
    if (!e.hasNodes([ie]))
      throw new Error("KeywordsPlugin: KeywordNode not registered on editor");
  }, [e]);
  const t = U((a) => Ee(a.getTextContent()), []), n = U((a) => {
    const y = ut.exec(a);
    if (y === null)
      return null;
    const f = y[2].length, o = y.index + y[1].length;
    return {
      end: o + f,
      start: o
    };
  }, []);
  return Ce(n, ie, t), null;
}
const ye = Object.freeze({ "	": "\\t", "\n": "\\n" }), ue = new RegExp(Object.keys(ye).join("|"), "g"), O = Object.freeze({ ancestorHasNextSibling: "|", ancestorIsLastChild: " ", hasNextSibling: "├", isLastChild: "└", selectedChar: "^", selectedLine: ">" }), mt = [(e) => e.hasFormat("bold") && "Bold", (e) => e.hasFormat("code") && "Code", (e) => e.hasFormat("italic") && "Italic", (e) => e.hasFormat("strikethrough") && "Strikethrough", (e) => e.hasFormat("subscript") && "Subscript", (e) => e.hasFormat("superscript") && "Superscript", (e) => e.hasFormat("underline") && "Underline"], gt = [(e) => e.hasTextFormat("bold") && "Bold", (e) => e.hasTextFormat("code") && "Code", (e) => e.hasTextFormat("italic") && "Italic", (e) => e.hasTextFormat("strikethrough") && "Strikethrough", (e) => e.hasTextFormat("subscript") && "Subscript", (e) => e.hasTextFormat("superscript") && "Superscript", (e) => e.hasTextFormat("underline") && "Underline"], ft = [(e) => e.isDirectionless() && "Directionless", (e) => e.isUnmergeable() && "Unmergeable"], ht = [(e) => e.isToken() && "Token", (e) => e.isSegmented() && "Segmented"];
function pt(e, t, n) {
  const a = e.getEditorState(), y = e._config, f = e._compositionKey, o = e._editable;
  if (n) {
    let v = "";
    return a.read(() => {
      v = function(s) {
        const i = document.createElement("div");
        return i.innerHTML = s.trim(), Ne(i, 0).innerHTML;
      }(Se(e));
    }), v;
  }
  let h = ` root
`;
  const B = a.read(() => {
    const v = Y();
    return xe(Te(), (s, i) => {
      const p = `(${s.getKey()})`, k = s.getType() || "", L = s.isSelected(), z = Pe(s) ? ` id: [ ${s.getIDs().join(", ")} ] ` : "";
      h += `${L ? O.selectedLine : " "} ${i.join(" ")} ${p} ${k} ${z} ${function(w) {
        if (ae(w)) {
          const T = w.getTextContent(), l = T.length === 0 ? "(empty)" : `"${de(T)}"`, d = function(E) {
            return [me(E), yt(E), xt(E)].filter(Boolean).join(", ");
          }(w);
          return [l, d.length !== 0 ? `{ ${d} }` : null].filter(Boolean).join(" ").trim();
        }
        if (ke(w)) {
          const T = w.getURL(), l = T.length === 0 ? "(empty)" : `"${de(T)}"`, d = function(E) {
            return [Nt(E), bt(E), jt(E)].filter(Boolean).join(", ");
          }(w);
          return [l, d.length !== 0 ? `{ ${d} }` : null].filter(Boolean).join(" ").trim();
        }
        if (ze(w)) {
          const T = function(l) {
            let d = gt.map((E) => E(l)).filter(Boolean).join(", ").toLocaleLowerCase();
            return d !== "" && (d = "format: " + d), d;
          }(w);
          return T !== "" ? `{ ${T} }` : "";
        }
        return "";
      }(s)}
`, h += function({ indent: w, isSelected: T, node: l, nodeKeyDisplay: d, selection: E, typeDisplay: I }) {
        if (!ae(l) || !se(E) || !T || he(l))
          return "";
        const r = E.anchor, g = E.focus;
        if (l.getTextContent() === "" || r.getNode() === E.focus.getNode() && r.offset === g.offset)
          return "";
        const [c, C] = function(R, P) {
          const j = P.getStartEndPoints();
          if (X(P) || j === null)
            return [-1, -1];
          const [u, S] = j, F = R.getTextContent(), V = F.length;
          let Z = -1, J = -1;
          if (u.type === "text" && S.type === "text") {
            const q = u.getNode(), Q = S.getNode();
            q === Q && R === q && u.offset !== S.offset ? [Z, J] = u.offset < S.offset ? [u.offset, S.offset] : [S.offset, u.offset] : [Z, J] = R === q ? q.isBefore(Q) ? [u.offset, V] : [0, u.offset] : R === Q ? Q.isBefore(q) ? [S.offset, V] : [0, S.offset] : [0, V];
          }
          const oe = (F.slice(0, Z).match(ue) || []).length, be = (F.slice(Z, J).match(ue) || []).length;
          return [Z + oe, J + oe + be];
        }(l, E);
        if (c === C)
          return "";
        const $ = w[w.length - 1] === O.hasNextSibling ? O.ancestorHasNextSibling : O.ancestorIsLastChild, b = [...w.slice(0, w.length - 1), $], x = Array(c + 1).fill(" "), _ = Array(C - c).fill(O.selectedChar), W = I.length + 3, D = Array(d.length + W).fill(" ");
        return [O.selectedLine, b.join(" "), [...D, ...x, ..._].join("")].join(" ") + `
`;
      }({ indent: i, isSelected: L, node: s, nodeKeyDisplay: p, selection: v, typeDisplay: k });
    }), v === null ? ": null" : se(v) ? function(s) {
      let i = "";
      const p = me(s);
      i += `: range ${p !== "" ? `{ ${p} }` : ""} ${s.style !== "" ? `{ style: ${s.style} } ` : ""}`;
      const k = s.anchor, L = s.focus, z = k.offset, w = L.offset;
      return i += `
  ├ anchor { key: ${k.key}, offset: ${z === null ? "null" : z}, type: ${k.type} }`, i += `
  └ focus { key: ${L.key}, offset: ${w === null ? "null" : w}, type: ${L.type} }`, i;
    }(v) : $e(v) ? function(s) {
      return `: table
  └ { table: ${s.tableKey}, anchorCell: ${s.anchor.key}, focusCell: ${s.focus.key} }`;
    }(v) : function(s) {
      return X(s) ? `: node
  └ [${Array.from(s._nodes).join(", ")}]` : "";
    }(v);
  });
  if (h += `
 selection` + B, h += `

 commands:`, t.length)
    for (const { type: v, payload: s } of t)
      h += `
  └ { type: ${v}, payload: ${s instanceof Event ? s.constructor.name : s} }`;
  else
    h += `
  └ None dispatched.`;
  return h += `

 editor:`, h += `
  └ namespace ${y.namespace}`, f !== null && (h += `
  └ compositionKey ${f}`), h += `
  └ editable ${String(o)}`, h;
}
function xe(e, t, n = []) {
  const a = e.getChildren(), y = a.length;
  a.forEach((f, o) => {
    t(f, n.concat(o === y - 1 ? O.isLastChild : O.hasNextSibling)), he(f) && xe(f, t, n.concat(o === y - 1 ? O.ancestorIsLastChild : O.ancestorHasNextSibling));
  });
}
function de(e) {
  return Object.entries(ye).reduce((t, [n, a]) => t.replace(new RegExp(n, "g"), String(a)), e);
}
function yt(e) {
  let t = ft.map((n) => n(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "detail: " + t), t;
}
function xt(e) {
  let t = ht.map((n) => n(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "mode: " + t), t;
}
function me(e) {
  let t = mt.map((n) => n(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "format: " + t), t;
}
function Nt(e) {
  let t = e.getTarget();
  return t != null && (t = "target: " + t), t;
}
function bt(e) {
  let t = e.getRel();
  return t != null && (t = "rel: " + t), t;
}
function jt(e) {
  let t = e.getTitle();
  return t != null && (t = "title: " + t), t;
}
function Ne(e, t) {
  const n = new Array(1 + t++).join("  "), a = new Array(t - 1).join("  ");
  let y;
  for (let f = 0; f < e.children.length; f++)
    y = document.createTextNode(`
` + n), e.insertBefore(y, e.children[f]), Ne(e.children[f], t), e.lastElementChild === e.children[f] && (y = document.createTextNode(`
` + a), e.appendChild(y));
  return e;
}
const vt = Qe(function({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: n, timeTravelPanelButtonClassName: a, viewClassName: y, timeTravelPanelClassName: f, editorState: o, setEditorState: h, setEditorReadOnly: B, generateContent: v }, s) {
  const [i, p] = M([]), [k, L] = M(""), [z, w] = M(!1), [T, l] = M(!1), d = A(0), E = A(null), [I, r] = M(!1), [g, c] = M(!1), [C, $] = M(!1), b = A(), x = A(0), _ = U((D) => {
    const R = ++x.current;
    v(D).then((P) => {
      R === x.current && L(P);
    }).catch((P) => {
      R === x.current && L(`Error rendering tree: ${P.message}

Stack:
${P.stack}`);
    });
  }, [v]);
  G(() => {
    !C && o._nodeMap.size > 1e3 && (c(!0), !C) || b.current !== o && (b.current = o, _(T), z || p((D) => [...D, [Date.now(), o]]));
  }, [o, _, T, C, z]);
  const W = i.length;
  return G(() => {
    if (I) {
      let D;
      const R = () => {
        const P = d.current;
        if (P === W - 1)
          return void r(!1);
        const j = i[P][0], u = i[P + 1][0];
        D = setTimeout(() => {
          d.current++;
          const S = d.current, F = E.current;
          F !== null && (F.value = String(S)), h(i[S][1]), R();
        }, u - j);
      };
      return R(), () => {
        clearTimeout(D);
      };
    }
  }, [i, I, W, h]), H.createElement("div", { className: y }, !C && g ? H.createElement("div", { style: { padding: 20 } }, H.createElement("span", { style: { marginRight: 20 } }, "Detected large EditorState, this can impact debugging performance."), H.createElement("button", { onClick: () => {
    $(!0);
  }, style: { background: "transparent", border: "1px solid white", color: "white", cursor: "pointer", padding: 5 } }, "Show full tree")) : null, C ? null : H.createElement("button", { onClick: () => (_(!T), void l(!T)), className: e, type: "button" }, T ? "Tree" : "Export DOM"), !z && (C || !g) && W > 2 && H.createElement("button", { onClick: () => {
    B(!0), d.current = W - 1, w(!0);
  }, className: t, type: "button" }, "Time Travel"), (C || !g) && H.createElement("pre", { ref: s }, k), z && (C || !g) && H.createElement("div", { className: f }, H.createElement("button", { className: a, onClick: () => {
    d.current === W - 1 && (d.current = 1), r(!I);
  }, type: "button" }, I ? "Pause" : "Play"), H.createElement("input", { className: n, ref: E, onChange: (D) => {
    const R = Number(D.target.value), P = i[R];
    P && (d.current = R, h(P[1]));
  }, type: "range", min: "1", max: W - 1 }), H.createElement("button", { className: a, onClick: () => {
    B(!1);
    const D = i.length - 1, R = i[D];
    h(R[1]);
    const P = E.current;
    P !== null && (P.value = String(D)), w(!1), r(!1);
  }, type: "button" }, "Exit")));
});
function wt(e, t) {
  const n = /* @__PURE__ */ new Set();
  for (const [a] of e._commands)
    n.add(e.registerCommand(a, (y) => (t((f) => {
      const o = [...f];
      return o.push({ payload: y, type: a.type ? a.type : "UNKNOWN" }), o.length > 10 && o.shift(), o;
    }), !1), Re));
  return () => n.forEach((a) => a());
}
function Et(e) {
  const [t, n] = M([]);
  return G(() => wt(e, n), [e]), et(() => t, [t]);
}
function Ct({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: n, timeTravelPanelButtonClassName: a, viewClassName: y, timeTravelPanelClassName: f, editor: o }) {
  const h = H.createRef(), [B, v] = M(o.getEditorState()), s = Et(o);
  return G(() => pe(o.registerUpdateListener(({ editorState: i }) => {
    v(i);
  }), o.registerEditableListener(() => {
    v(o.getEditorState());
  })), [o]), G(() => {
    const i = h.current;
    if (i !== null)
      return i.__lexicalEditor = o, () => {
        i.__lexicalEditor = null;
      };
  }, [o, h]), H.createElement(vt, { treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: n, timeTravelPanelButtonClassName: a, viewClassName: y, timeTravelPanelClassName: f, setEditorReadOnly: (i) => {
    const p = o.getRootElement();
    p != null && (p.contentEditable = i ? "false" : "true");
  }, editorState: B, setEditorState: (i) => o.setEditorState(i), generateContent: async function(i) {
    return pt(o, s, i);
  }, ref: h });
}
function St() {
  const [e] = ne();
  return /* @__PURE__ */ m.jsx(
    Ct,
    {
      viewClassName: "tree-view-output",
      treeTypeButtonClassName: "debug-treetype-button",
      timeTravelPanelClassName: "debug-timetravel-panel",
      timeTravelButtonClassName: "debug-timetravel-button",
      timeTravelPanelSliderClassName: "debug-timetravel-panel-slider",
      timeTravelPanelButtonClassName: "debug-timetravel-panel-button",
      editor: e
    }
  );
}
function re(e, t, n) {
  return Math.min(Math.max(e, t), n);
}
const N = {
  east: 1,
  north: 8,
  south: 2,
  west: 4
};
function Tt({
  onResizeStart: e,
  onResizeEnd: t,
  buttonRef: n,
  imageRef: a,
  maxWidth: y,
  editor: f,
  showCaption: o,
  setShowCaption: h,
  captionsEnabled: B
}) {
  const v = A(null), s = A({
    priority: "",
    value: "default"
  }), i = A({
    currentHeight: 0,
    currentWidth: 0,
    direction: 0,
    isResizing: !1,
    ratio: 0,
    startHeight: 0,
    startWidth: 0,
    startX: 0,
    startY: 0
  }), p = f.getRootElement(), k = y || (p !== null ? p.getBoundingClientRect().width - 20 : 100), L = p !== null ? p.getBoundingClientRect().height - 20 : 100, z = 100, w = 100, T = (r) => {
    const g = r === N.east || r === N.west, c = r === N.north || r === N.south, C = r & N.north && r & N.west || r & N.south && r & N.east, $ = g ? "ew" : c ? "ns" : C ? "nwse" : "nesw";
    p !== null && p.style.setProperty("cursor", `${$}-resize`, "important"), document.body !== null && (document.body.style.setProperty("cursor", `${$}-resize`, "important"), s.current.value = document.body.style.getPropertyValue("-webkit-user-select"), s.current.priority = document.body.style.getPropertyPriority("-webkit-user-select"), document.body.style.setProperty("-webkit-user-select", "none", "important"));
  }, l = () => {
    p !== null && p.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
      "-webkit-user-select",
      s.current.value,
      s.current.priority
    ));
  }, d = (r, g) => {
    if (!f.isEditable())
      return;
    const c = a.current, C = v.current;
    if (c !== null && C !== null) {
      r.preventDefault();
      const { width: $, height: b } = c.getBoundingClientRect(), x = i.current;
      x.startWidth = $, x.startHeight = b, x.ratio = $ / b, x.currentWidth = $, x.currentHeight = b, x.startX = r.clientX, x.startY = r.clientY, x.isResizing = !0, x.direction = g, T(g), e(), C.classList.add("image-control-wrapper--resizing"), c.style.height = `${b}px`, c.style.width = `${$}px`, document.addEventListener("pointermove", E), document.addEventListener("pointerup", I);
    }
  }, E = (r) => {
    const g = a.current, c = i.current, C = c.direction & (N.east | N.west), $ = c.direction & (N.south | N.north);
    if (g !== null && c.isResizing)
      if (C && $) {
        let b = Math.floor(c.startX - r.clientX);
        b = c.direction & N.east ? -b : b;
        const x = re(c.startWidth + b, z, k), _ = x / c.ratio;
        g.style.width = `${x}px`, g.style.height = `${_}px`, c.currentHeight = _, c.currentWidth = x;
      } else if ($) {
        let b = Math.floor(c.startY - r.clientY);
        b = c.direction & N.south ? -b : b;
        const x = re(c.startHeight + b, w, L);
        g.style.height = `${x}px`, c.currentHeight = x;
      } else {
        let b = Math.floor(c.startX - r.clientX);
        b = c.direction & N.east ? -b : b;
        const x = re(c.startWidth + b, z, k);
        g.style.width = `${x}px`, c.currentWidth = x;
      }
  }, I = () => {
    const r = a.current, g = i.current, c = v.current;
    if (r !== null && c !== null && g.isResizing) {
      const C = g.currentWidth, $ = g.currentHeight;
      g.startWidth = 0, g.startHeight = 0, g.ratio = 0, g.startX = 0, g.startY = 0, g.currentWidth = 0, g.currentHeight = 0, g.isResizing = !1, c.classList.remove("image-control-wrapper--resizing"), l(), t(C, $), document.removeEventListener("pointermove", E), document.removeEventListener("pointerup", I);
    }
  };
  return /* @__PURE__ */ m.jsxs("div", { ref: v, children: [
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-n",
        onPointerDown: (r) => {
          d(r, N.north);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-ne",
        onPointerDown: (r) => {
          d(r, N.north | N.east);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-e",
        onPointerDown: (r) => {
          d(r, N.east);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-se",
        onPointerDown: (r) => {
          d(r, N.south | N.east);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-s",
        onPointerDown: (r) => {
          d(r, N.south);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-sw",
        onPointerDown: (r) => {
          d(r, N.south | N.west);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-w",
        onPointerDown: (r) => {
          d(r, N.west);
        }
      }
    ),
    /* @__PURE__ */ m.jsx(
      "div",
      {
        className: "image-resizer image-resizer-nw",
        onPointerDown: (r) => {
          d(r, N.north | N.west);
        }
      }
    )
  ] });
}
const ge = /* @__PURE__ */ new Set(), fe = Je();
function $t(e) {
  if (!ge.has(e))
    throw new Promise((t) => {
      const n = new Image();
      n.src = e, n.onload = () => {
        ge.add(e), t(null);
      };
    });
}
function Pt({
  altText: e,
  className: t,
  imageRef: n,
  src: a,
  width: y,
  height: f,
  maxWidth: o
}) {
  return $t(a), /* @__PURE__ */ m.jsx(
    "img",
    {
      className: t || void 0,
      src: a,
      alt: e,
      ref: n,
      style: {
        height: f,
        maxWidth: o,
        width: y
      },
      draggable: "false"
    }
  );
}
function Bt({
  src: e,
  altText: t,
  nodeKey: n,
  width: a,
  height: y,
  maxWidth: f,
  resizable: o,
  showCaption: h,
  caption: B,
  captionsEnabled: v
}) {
  const s = A(null), i = A(null), [p, k, L] = Le(n), [z, w] = M(!1), { isCollabActive: T } = nt(), [l] = ne(), [d, E] = M(null), I = A(null), r = U(
    (j) => {
      if (p && X(Y())) {
        j.preventDefault();
        const S = ee(n);
        te(S) && S.remove();
      }
      return !1;
    },
    [p, n]
  ), g = U(
    (j) => {
      const u = Y(), S = i.current;
      if (p && X(u) && u.getNodes().length === 1) {
        if (h)
          return le(null), j.preventDefault(), B.focus(), !0;
        if (S !== null && S !== document.activeElement)
          return j.preventDefault(), S.focus(), !0;
      }
      return !1;
    },
    [B, p, h]
  ), c = U(
    (j) => I.current === B || i.current === j.target ? (le(null), l.update(() => {
      k(!0);
      const u = l.getRootElement();
      u !== null && u.focus();
    }), !0) : !1,
    [B, l, k]
  ), C = U(
    (j) => {
      const u = j;
      return z ? !0 : u.target === s.current ? (u.shiftKey ? k(!p) : (L(), k(!0)), !0) : !1;
    },
    [z, p, k, L]
  ), $ = U(
    (j) => {
      l.getEditorState().read(() => {
        const u = Y();
        j.target.tagName === "IMG" && se(u) && u.getNodes().length === 1 && l.dispatchCommand(fe, j);
      });
    },
    [l]
  );
  G(() => {
    let j = !0;
    const u = l.getRootElement(), S = pe(
      l.registerUpdateListener(({ editorState: F }) => {
        j && E(F.read(() => Y()));
      }),
      l.registerCommand(
        _e,
        (F, V) => (I.current = V, !1),
        K
      ),
      l.registerCommand(Me, C, K),
      l.registerCommand(fe, C, K),
      l.registerCommand(
        Fe,
        (F) => F.target === s.current ? (F.preventDefault(), !0) : !1,
        K
      ),
      l.registerCommand(Ie, r, K),
      l.registerCommand(He, r, K),
      l.registerCommand(Be, g, K),
      l.registerCommand(De, c, K)
    );
    return u == null || u.addEventListener("contextmenu", $), () => {
      j = !1, S(), u == null || u.removeEventListener("contextmenu", $);
    };
  }, [
    L,
    l,
    z,
    p,
    n,
    r,
    g,
    c,
    C,
    $,
    k
  ]);
  const b = () => {
    l.update(() => {
      const j = ee(n);
      te(j) && j.setShowCaption(!0);
    });
  }, x = (j, u) => {
    setTimeout(() => {
      w(!1);
    }, 200), l.update(() => {
      const S = ee(n);
      te(S) && S.setWidthAndHeight(j, u);
    });
  }, _ = () => {
    w(!0);
  }, { historyState: W } = We(), {
    settings: { showNestedEditorTreeView: D }
  } = Oe(), R = p && X(d) && !z, P = p || z;
  return /* @__PURE__ */ m.jsx(tt, { fallback: null, children: /* @__PURE__ */ m.jsxs(m.Fragment, { children: [
    /* @__PURE__ */ m.jsxs("div", { draggable: R, children: [
      p && /* @__PURE__ */ m.jsx(
        "div",
        {
          className: "image-delete-icon",
          onClick: (j) => {
            j.stopPropagation(), l.update(() => {
              if (Y()) {
                const u = ee(n);
                te(u) && u.remove();
              }
              return !1;
            });
          },
          children: /* @__PURE__ */ m.jsx("i", { className: "format clear" })
        }
      ),
      /* @__PURE__ */ m.jsx(
        Pt,
        {
          className: P ? `focused ${X(d) ? "draggable" : ""}` : null,
          src: e,
          altText: t,
          imageRef: s,
          width: a,
          height: y,
          maxWidth: f || "auto"
        }
      )
    ] }),
    h && /* @__PURE__ */ m.jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ m.jsxs(ot, { initialEditor: B, children: [
      /* @__PURE__ */ m.jsx(Ae, {}),
      /* @__PURE__ */ m.jsx(Ke, {}),
      /* @__PURE__ */ m.jsx(Ue, {}),
      /* @__PURE__ */ m.jsx(ct, {}),
      /* @__PURE__ */ m.jsx(Ge, {}),
      /* @__PURE__ */ m.jsx(dt, {}),
      T ? /* @__PURE__ */ m.jsx(
        rt,
        {
          id: B.getKey(),
          providerFactory: st,
          shouldBootstrap: !0
        }
      ) : /* @__PURE__ */ m.jsx(Xe, { externalHistoryState: W }),
      /* @__PURE__ */ m.jsx(
        Ye,
        {
          contentEditable: /* @__PURE__ */ m.jsx(Ve, { className: "ImageNode__contentEditable" }),
          placeholder: /* @__PURE__ */ m.jsx(Ze, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
          ErrorBoundary: qe
        }
      ),
      D === !0 ? /* @__PURE__ */ m.jsx(St, {}) : null
    ] }) }),
    o && X(d) && P && /* @__PURE__ */ m.jsx(
      Tt,
      {
        showCaption: h,
        setShowCaption: b,
        editor: l,
        buttonRef: i,
        imageRef: s,
        maxWidth: f,
        onResizeStart: _,
        onResizeEnd: x,
        captionsEnabled: v
      }
    )
  ] }) });
}
export {
  fe as RIGHT_CLICK_IMAGE_COMMAND,
  Bt as default
};
