import { __exports as d } from "./index-LexicalCode.prod2.js";
import { __require as ie } from "./index-prism.js";
import { __require as ne } from "./index-prism-clike.js";
import { __require as oe } from "./index-prism-javascript.js";
import { __require as le } from "./index-prism-markup.js";
import { __require as se } from "./index-prism-markdown.js";
import { __require as ue } from "./index-prism-c.js";
import { __require as ge } from "./index-prism-css.js";
import { __require as ae } from "./index-prism-objectivec.js";
import { __require as de } from "./index-prism-sql.js";
import { __require as fe } from "./index-prism-python.js";
import { __require as Ne } from "./index-prism-rust.js";
import { __require as ce } from "./index-prism-swift.js";
import { __require as he } from "./index-prism-typescript.js";
import { __require as _e } from "./index-prism-java.js";
import { __require as pe } from "./index-prism-cpp.js";
import { __require as Te } from "./index-LexicalUtils.js";
import { __require as me } from "./index-Lexical.js";
var V;
function Ie() {
  if (V) return d;
  V = 1;
  var L = ie();
  ne(), oe(), le(), se(), ue(), ge(), ae(), de(), fe(), Ne(), ce(), he(), _e(), pe();
  var O = Te(), i = me();
  let P = (t) => t != null && L.languages.hasOwnProperty(t) ? t : void 0;
  function R(t, e) {
    for (let r of t.childNodes) {
      if (O.isHTMLElement(r) && r.tagName === e) return !0;
      R(r, e);
    }
    return !1;
  }
  class T extends i.ElementNode {
    static getType() {
      return "code";
    }
    static clone(e) {
      return new T(e.__language, e.__key);
    }
    constructor(e, r) {
      super(r), this.__language = P(e);
    }
    createDOM(e) {
      let r = document.createElement("code");
      return O.addClassNamesToElement(r, e.theme.code), r.setAttribute("spellcheck", "false"), (e = this.getLanguage()) && r.setAttribute("data-highlight-language", e), r;
    }
    updateDOM(e, r) {
      let n = this.__language;
      return e = e.__language, n ? n !== e && r.setAttribute("data-highlight-language", n) : e && r.removeAttribute("data-highlight-language"), !1;
    }
    exportDOM() {
      let e = document.createElement("pre");
      e.setAttribute("spellcheck", "false");
      let r = this.getLanguage();
      return r && e.setAttribute("data-highlight-language", r), { element: e };
    }
    static importDOM() {
      return { code: (e) => e.textContent != null && (/\r?\n/.test(e.textContent) || R(e, "BR")) ? { conversion: b, priority: 1 } : null, div: () => ({ conversion: Q, priority: 1 }), pre: () => ({ conversion: b, priority: 0 }), table: (e) => y(e) ? { conversion: X, priority: 3 } : null, td: (e) => {
        let r = e.closest("table");
        return e.classList.contains("js-file-line") ? { conversion: Z, priority: 3 } : r && y(r) ? { conversion: B, priority: 3 } : null;
      }, tr: (e) => (e = e.closest("table")) && y(e) ? { conversion: B, priority: 3 } : null };
    }
    static importJSON(e) {
      let r = E(e.language);
      return r.setFormat(e.format), r.setIndent(e.indent), r.setDirection(e.direction), r;
    }
    exportJSON() {
      return { ...super.exportJSON(), language: this.getLanguage(), type: "code", version: 1 };
    }
    insertNewAfter(e, r = !0) {
      var n = this.getChildren(), o = n.length;
      if (2 <= o && n[o - 1].getTextContent() === `
` && n[o - 2].getTextContent() === `
` && e.isCollapsed() && e.anchor.key === this.__key && e.anchor.offset === o) return n[o - 1].remove(), n[o - 2].remove(), e = i.$createParagraphNode(), this.insertAfter(e, r), e;
      let { anchor: l, focus: u } = e;
      if (r = (l.isBefore(u) ? l : u).getNode(), i.$isTextNode(r)) {
        for (o = m(r), n = []; ; ) if (i.$isTabNode(o)) n.push(i.$createTabNode()), o = o.getNextSibling();
        else if (a(o)) {
          for (var s = 0, g = o.getTextContent(), f = o.getTextContentSize(); s < f && g[s] === " "; s++) ;
          if (s !== 0 && n.push(x(" ".repeat(s))), s !== f) break;
          o = o.getNextSibling();
        } else break;
        o = r.splitText(l.offset)[0], s = l.offset === 0 ? 0 : 1, s = o.getIndexWithinParent() + s, g = r.getParentOrThrow(), f = [i.$createLineBreakNode(), ...n], g.splice(s, 0, f), (n = n[n.length - 1]) ? n.select() : l.offset === 0 ? o.selectPrevious() : o.getNextSibling().selectNext(0, 0);
      }
      return h(r) && ({ offset: e } = e.anchor, r.splice(e, 0, [i.$createLineBreakNode()]), r.select(e + 1, e + 1)), null;
    }
    canIndent() {
      return !1;
    }
    collapseAtStart() {
      let e = i.$createParagraphNode();
      return this.getChildren().forEach((r) => e.append(r)), this.replace(e), !0;
    }
    setLanguage(e) {
      this.getWritable().__language = P(e);
    }
    getLanguage() {
      return this.getLatest().__language;
    }
  }
  function E(t) {
    return i.$applyNodeReplacement(new T(t));
  }
  function h(t) {
    return t instanceof T;
  }
  function b(t) {
    let e;
    return O.isHTMLElement(t) && (e = t.getAttribute("data-highlight-language")), { node: E(e) };
  }
  function Q(t) {
    let e = t.style.fontFamily.match("monospace") !== null;
    return e || ee(t) ? { after: (r) => {
      let n = t.parentNode;
      return n != null && t !== n.lastChild && r.push(i.$createLineBreakNode()), r;
    }, node: e ? E() : null } : { node: null };
  }
  function X() {
    return { node: E() };
  }
  function B() {
    return { node: null };
  }
  function Z(t) {
    return { after: (e) => (t.parentNode && t.parentNode.nextSibling && e.push(i.$createLineBreakNode()), e), node: null };
  }
  function ee(t) {
    for (t = t.parentElement; t !== null; ) {
      if (t.style.fontFamily.match("monospace") !== null) return !0;
      t = t.parentElement;
    }
    return !1;
  }
  function y(t) {
    return t.classList.contains("js-file-line-container");
  }
  let q = { c: "C", clike: "C-like", cpp: "C++", css: "CSS", html: "HTML", java: "Java", js: "JavaScript", markdown: "Markdown", objc: "Objective-C", plain: "Plain Text", py: "Python", rust: "Rust", sql: "SQL", swift: "Swift", typescript: "TypeScript", xml: "XML" }, I = { cpp: "cpp", java: "java", javascript: "js", md: "markdown", plaintext: "plain", python: "py", text: "plain", ts: "typescript" };
  function w(t) {
    return I[t] || t;
  }
  class M extends i.TextNode {
    constructor(e, r, n) {
      super(e, n), this.__highlightType = r;
    }
    static getType() {
      return "code-highlight";
    }
    static clone(e) {
      return new M(e.__text, e.__highlightType || void 0, e.__key);
    }
    getHighlightType() {
      return this.getLatest().__highlightType;
    }
    createDOM(e) {
      let r = super.createDOM(e);
      return e = A(e.theme, this.__highlightType), O.addClassNamesToElement(r, e), r;
    }
    updateDOM(e, r, n) {
      let o = super.updateDOM(e, r, n);
      return e = A(n.theme, e.__highlightType), n = A(n.theme, this.__highlightType), e !== n && (e && O.removeClassNamesFromElement(
        r,
        e
      ), n && O.addClassNamesToElement(r, n)), o;
    }
    static importJSON(e) {
      let r = x(e.text, e.highlightType);
      return r.setFormat(e.format), r.setDetail(e.detail), r.setMode(e.mode), r.setStyle(e.style), r;
    }
    exportJSON() {
      return { ...super.exportJSON(), highlightType: this.getHighlightType(), type: "code-highlight", version: 1 };
    }
    setFormat() {
      return this;
    }
    isParentRequired() {
      return !0;
    }
    createParentElementNode() {
      return E();
    }
  }
  function A(t, e) {
    return e && t && t.codeHighlight && t.codeHighlight[e];
  }
  function x(t, e) {
    return i.$applyNodeReplacement(new M(t, e));
  }
  function a(t) {
    return t instanceof M;
  }
  function m(t) {
    let e = t;
    for (; a(t) || i.$isTabNode(t); ) e = t, t = t.getPreviousSibling();
    return e;
  }
  function v(t) {
    let e = t;
    for (; a(t) || i.$isTabNode(t); ) e = t, t = t.getNextSibling();
    return e;
  }
  let W = { defaultLanguage: "javascript", tokenize(t, e) {
    return L.tokenize(t, L.languages[e || ""] || L.languages[this.defaultLanguage]);
  } };
  function H(t, e) {
    let r = null;
    var n = null, o = t;
    let l = e, u = t.getTextContent();
    for (; ; ) {
      if (l === 0) {
        if (o = o.getPreviousSibling(), o === null) break;
        if (!(a(o) || i.$isTabNode(o) || i.$isLineBreakNode(o))) throw Error("Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode");
        if (i.$isLineBreakNode(o)) {
          r = { node: o, offset: 1 };
          break;
        }
        l = Math.max(0, o.getTextContentSize() - 1), u = o.getTextContent();
      } else l--;
      let s = u[l];
      a(o) && s !== " " && (n = { node: o, offset: l });
    }
    if (n !== null) return n;
    if (n = null, e < t.getTextContentSize() ? a(t) && (n = t.getTextContent()[e]) : (o = t.getNextSibling(), a(o) && (n = o.getTextContent()[0])), n !== null && n !== " ") return r;
    e: for (n = t, o = t.getTextContent(), t = t.getTextContentSize(); ; ) {
      if (!a(n) || e === t) {
        if (n = n.getNextSibling(), n === null || i.$isLineBreakNode(n)) {
          t = null;
          break e;
        }
        a(n) && (e = 0, o = n.getTextContent(), t = n.getTextContentSize());
      }
      if (a(n)) {
        if (o[e] !== " ") {
          t = { node: n, offset: e };
          break e;
        }
        e++;
      }
    }
    return t !== null ? t : r;
  }
  function K(t) {
    if (t = v(t), i.$isLineBreakNode(t)) throw Error("Unexpected lineBreakNode in getEndOfCodeInLine");
    return t;
  }
  function Y(t, e, r) {
    let n = t.getParent();
    h(n) ? U(n, e, r) : a(t) && t.replace(i.$createTextNode(t.__text));
  }
  let S = /* @__PURE__ */ new Set();
  function U(t, e, r) {
    let n = t.getKey();
    S.has(n) || (S.add(n), t.getLanguage() === void 0 && t.setLanguage(r.defaultLanguage), e.update(() => {
      te(n, () => {
        var o = i.$getNodeByKey(n);
        if (!h(o) || !o.isAttached()) return !1;
        var l = o.getTextContent();
        l = r.tokenize(l, o.getLanguage() || r.defaultLanguage), l = D(l);
        var u = o.getChildren();
        for (o = 0; o < u.length && j(u[o], l[o]); ) o++;
        var s = u.length;
        let g = l.length, f = Math.min(s, g) - o, N = 0;
        for (; N < f; ) if (N++, !j(u[s - N], l[g - N])) {
          N--;
          break;
        }
        u = o, s -= N, l = l.slice(o, g - N);
        let { from: c, to: C, nodesForReplacement: p } = { from: u, nodesForReplacement: l, to: s };
        return c !== C || p.length ? (t.splice(c, C - c, p), !0) : !1;
      });
    }, { onUpdate: () => {
      S.delete(n);
    }, skipTransforms: !0 }));
  }
  function D(t, e) {
    let r = [];
    for (let n of t) if (typeof n == "string") {
      t = n.split(/(\n|\t)/);
      let o = t.length;
      for (let l = 0; l < o; l++) {
        let u = t[l];
        u === `
` || u === `\r
` ? r.push(i.$createLineBreakNode()) : u === "	" ? r.push(i.$createTabNode()) : 0 < u.length && r.push(x(u, e));
      }
    } else ({ content: t } = n), typeof t == "string" ? r.push(...D([t], n.type)) : Array.isArray(t) && r.push(...D(t, n.type));
    return r;
  }
  function te(t, e) {
    if (t = i.$getNodeByKey(t), h(t) && t.isAttached()) {
      var r = i.$getSelection();
      if (i.$isRangeSelection(r)) {
        r = r.anchor;
        var n = r.offset, o = r.type === "element" && i.$isLineBreakNode(t.getChildAtIndex(r.offset - 1)), l = 0;
        if (!o) {
          let u = r.getNode();
          l = n + u.getPreviousSiblings().reduce((s, g) => s + g.getTextContentSize(), 0);
        }
        e() && (o ? r.getNode().select(n, n) : t.getChildren().some((u) => {
          let s = i.$isTextNode(u);
          if (s || i.$isLineBreakNode(u)) {
            let g = u.getTextContentSize();
            if (s && g >= l) return u.select(l, l), !0;
            l -= g;
          }
          return !1;
        }));
      } else e();
    }
  }
  function j(t, e) {
    return a(t) && a(e) && t.__text === e.__text && t.__highlightType === e.__highlightType || i.$isTabNode(t) && i.$isTabNode(e) || i.$isLineBreakNode(t) && i.$isLineBreakNode(e);
  }
  function $(t) {
    if (!i.$isRangeSelection(t)) return !1;
    var e = t.anchor.getNode();
    return t = t.focus.getNode(), e.is(t) && h(e) ? !0 : (e = e.getParent(), h(e) && e.is(t.getParent()));
  }
  function z(t) {
    t = t.getNodes();
    let e = [[]];
    if (t.length === 1 && h(t[0])) return e;
    let r = e[0];
    for (let n = 0; n < t.length; n++) {
      let o = t[n];
      if (!(a(o) || i.$isTabNode(o) || i.$isLineBreakNode(o))) throw Error("Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode");
      i.$isLineBreakNode(o) ? n !== 0 && 0 < r.length && (r = [], e.push(r)) : r.push(o);
    }
    return e;
  }
  function re(t) {
    var e = i.$getSelection();
    if (!i.$isRangeSelection(e) || !$(e)) return null;
    let r = t ? i.OUTDENT_CONTENT_COMMAND : i.INDENT_CONTENT_COMMAND;
    if (t = t ? i.OUTDENT_CONTENT_COMMAND : i.INSERT_TAB_COMMAND, 1 < z(e).length) return r;
    var n = e.getNodes()[0];
    if (!(h(n) || a(n) || i.$isTabNode(n) || i.$isLineBreakNode(n))) throw Error("Expected selection firstNode to be CodeHighlightNode or TabNode");
    if (h(n)) return r;
    let o = m(n);
    n = v(n);
    var l = e.anchor;
    let u = e.focus;
    return u.isBefore(l) ? e = u : (e = l, l = u), o !== null && n !== null && e.key === o.getKey() && e.offset === 0 && l.key === n.getKey() && l.offset === n.getTextContentSize() ? r : t;
  }
  function F(t) {
    var e = i.$getSelection();
    if (!i.$isRangeSelection(e) || !$(e)) return !1;
    var r = z(e);
    let n = r.length;
    if (1 < r.length) {
      for (e = 0; e < n; e++) {
        var o = r[e];
        0 < o.length && (o = o[0], e === 0 && (o = m(o)), o !== null && (t === i.INDENT_CONTENT_COMMAND ? o.insertBefore(i.$createTabNode()) : i.$isTabNode(o) && o.remove()));
      }
      return !0;
    }
    if (r = e.getNodes()[0], !(h(r) || a(r) || i.$isTabNode(r) || i.$isLineBreakNode(r))) throw Error("Expected selection firstNode to be CodeHighlightNode or CodeTabNode");
    if (h(r)) return t === i.INDENT_CONTENT_COMMAND && e.insertNodes([i.$createTabNode()]), !0;
    if (r = m(r), r === null) throw Error("Expected getFirstCodeNodeOfLine to return a valid Code Node");
    return t === i.INDENT_CONTENT_COMMAND ? i.$isLineBreakNode(r) ? r.insertAfter(i.$createTabNode()) : r.insertBefore(i.$createTabNode()) : i.$isTabNode(r) && r.remove(), !0;
  }
  function J(t, e) {
    let r = i.$getSelection();
    if (!i.$isRangeSelection(r)) return !1;
    let { anchor: n, focus: o } = r, l = n.offset, u = o.offset, s = n.getNode(), g = o.getNode();
    var f = t === i.KEY_ARROW_UP_COMMAND;
    if (!$(r) || !a(s) && !i.$isTabNode(s) || !a(g) && !i.$isTabNode(g)) return !1;
    if (!e.altKey) {
      if (r.isCollapsed()) {
        if (t = s.getParentOrThrow(), f && l === 0 && s.getPreviousSibling() === null) {
          if (t.getPreviousSibling() === null) return t.selectPrevious(), e.preventDefault(), !0;
        } else if (!f && l === s.getTextContentSize() && s.getNextSibling() === null && t.getNextSibling() === null) return t.selectNext(), e.preventDefault(), !0;
      }
      return !1;
    }
    let N;
    if (s.isBefore(g)) {
      var c = m(s);
      N = v(g);
    } else c = m(g), N = v(s);
    if (c == null || N == null) return !1;
    let C = c.getNodesBetween(N);
    for (let _ = 0; _ < C.length; _++) {
      let k = C[_];
      if (!a(k) && !i.$isTabNode(k) && !i.$isLineBreakNode(k)) return !1;
    }
    if (e.preventDefault(), e.stopPropagation(), e = f ? c.getPreviousSibling() : N.getNextSibling(), !i.$isLineBreakNode(e) || (c = f ? e.getPreviousSibling() : e.getNextSibling(), c == null)) return !0;
    f = a(c) || i.$isTabNode(c) || i.$isLineBreakNode(c) ? f ? m(c) : v(c) : null;
    let p = f ?? c;
    return e.remove(), C.forEach((_) => _.remove()), t === i.KEY_ARROW_UP_COMMAND ? (C.forEach((_) => p.insertBefore(_)), p.insertBefore(e)) : (p.insertAfter(e), p = e, C.forEach((_) => {
      p.insertAfter(_), p = _;
    })), r.setTextNodeRange(s, l, g, u), !0;
  }
  function G(t, e) {
    let r = i.$getSelection();
    if (!i.$isRangeSelection(r)) return !1;
    let { anchor: n, focus: o } = r;
    var l = n.getNode();
    let u = o.getNode();
    if (t = t === i.MOVE_TO_START, !a(l) && !i.$isTabNode(l) || !a(u) && !i.$isTabNode(u)) return !1;
    if (t) if (l = H(u, o.offset), l !== null) {
      let { node: s, offset: g } = l;
      i.$isLineBreakNode(s) ? s.selectNext(0, 0) : r.setTextNodeRange(s, g, s, g);
    } else u.getParentOrThrow().selectStart();
    else K(u).select();
    return e.preventDefault(), e.stopPropagation(), !0;
  }
  return d.$createCodeHighlightNode = x, d.$createCodeNode = E, d.$isCodeHighlightNode = a, d.$isCodeNode = h, d.CODE_LANGUAGE_FRIENDLY_NAME_MAP = q, d.CODE_LANGUAGE_MAP = I, d.CodeHighlightNode = M, d.CodeNode = T, d.DEFAULT_CODE_LANGUAGE = "javascript", d.PrismTokenizer = W, d.getCodeLanguages = () => Object.keys(L.languages).filter((t) => typeof L.languages[t] != "function").sort(), d.getDefaultCodeLanguage = () => "javascript", d.getEndOfCodeInLine = K, d.getFirstCodeNodeOfLine = m, d.getLanguageFriendlyName = function(t) {
    return t = w(t), q[t] || t;
  }, d.getLastCodeNodeOfLine = v, d.getStartOfCodeInLine = H, d.normalizeCodeLang = w, d.registerCodeHighlighting = function(t, e) {
    if (!t.hasNodes([T, M])) throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");
    return e == null && (e = W), O.mergeRegister(
      t.registerMutationListener(T, (r) => {
        t.update(() => {
          for (let [l, u] of r) if (u !== "destroyed") {
            var n = i.$getNodeByKey(l);
            if (n !== null) e: {
              var o = n;
              if (n = t.getElementByKey(o.getKey()), n === null) break e;
              o = o.getChildren();
              let s = o.length;
              if (s === n.__cachedChildrenLength) break e;
              n.__cachedChildrenLength = s;
              let g = "1", f = 1;
              for (let N = 0; N < s; N++) i.$isLineBreakNode(o[N]) && (g += `
` + ++f);
              n.setAttribute("data-gutter", g);
            }
          }
        });
      }),
      t.registerNodeTransform(T, (r) => U(r, t, e)),
      t.registerNodeTransform(i.TextNode, (r) => Y(r, t, e)),
      t.registerNodeTransform(M, (r) => Y(r, t, e)),
      t.registerCommand(i.KEY_TAB_COMMAND, (r) => {
        let n = re(r.shiftKey);
        return n === null ? !1 : (r.preventDefault(), t.dispatchCommand(n, void 0), !0);
      }, i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.INSERT_TAB_COMMAND, () => {
        let r = i.$getSelection();
        return $(r) ? (i.$insertNodes([i.$createTabNode()]), !0) : !1;
      }, i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.INDENT_CONTENT_COMMAND, () => F(i.INDENT_CONTENT_COMMAND), i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.OUTDENT_CONTENT_COMMAND, () => F(i.OUTDENT_CONTENT_COMMAND), i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.KEY_ARROW_UP_COMMAND, (r) => J(i.KEY_ARROW_UP_COMMAND, r), i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.KEY_ARROW_DOWN_COMMAND, (r) => J(i.KEY_ARROW_DOWN_COMMAND, r), i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.MOVE_TO_END, (r) => G(i.MOVE_TO_END, r), i.COMMAND_PRIORITY_LOW),
      t.registerCommand(i.MOVE_TO_START, (r) => G(i.MOVE_TO_START, r), i.COMMAND_PRIORITY_LOW)
    );
  }, d;
}
export {
  Ie as __require
};
