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