class k {
  constructor(e = "") {
    this._lines = [], this._version = 0, this.setText(e);
  }
  // Get line at index
  getLine(e) {
    return this._lines[e] || "";
  }
  // Get all lines
  getLines() {
    return [...this._lines];
  }
  // Get total number of lines
  getLineCount() {
    return this._lines.length;
  }
  // Get total text content
  getText() {
    return this._lines.join(`
`);
  }
  // Set entire text content
  setText(e) {
    this._lines = e.split(`
`), this._version++;
  }
  // Get text in a range
  getTextInRange(e) {
    if (e.start.line === e.end.line)
      return this.getLine(e.start.line).substring(e.start.column, e.end.column);
    const t = [];
    t.push(this.getLine(e.start.line).substring(e.start.column));
    for (let n = e.start.line + 1; n < e.end.line; n++)
      t.push(this.getLine(n));
    return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
`);
  }
  // Replace text in range
  replaceRange(e, t) {
    const n = this.getTextInRange(e);
    if (e.start.line === e.end.line) {
      const r = this.getLine(e.start.line), i = r.substring(0, e.start.column) + t + r.substring(e.end.column);
      this._lines[e.start.line] = i;
    } else {
      const r = this.getLine(e.start.line), i = this.getLine(e.end.line), o = r.substring(0, e.start.column) + t, l = i.substring(e.end.column), s = t.split(`
`);
      s[0] = o + s[0], s[s.length - 1] = s[s.length - 1] + l, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...s);
    }
    return this._version++, { range: e, text: t, oldText: n };
  }
  // Insert text at position
  insertText(e, t) {
    const n = { start: e, end: e };
    return this.replaceRange(n, t);
  }
  // Delete text in range
  deleteRange(e) {
    return this.replaceRange(e, "");
  }
  // Convert position to offset
  positionToOffset(e) {
    let t = 0;
    for (let n = 0; n < e.line; n++)
      t += this.getLine(n).length + 1;
    return t += e.column, t;
  }
  // Convert offset to position
  offsetToPosition(e) {
    let t = e;
    for (let n = 0; n < this.getLineCount(); n++) {
      const r = this.getLine(n).length;
      if (t <= r)
        return { line: n, column: t };
      t -= r + 1;
    }
    return {
      line: this.getLineCount() - 1,
      column: this.getLine(this.getLineCount() - 1).length
    };
  }
  // Validate position
  isValidPosition(e) {
    return !(e.line < 0 || e.line >= this.getLineCount() || e.column < 0 || e.column > this.getLine(e.line).length);
  }
  // Validate range
  isValidRange(e) {
    return this.isValidPosition(e.start) && this.isValidPosition(e.end);
  }
  // Get version for change tracking
  getVersion() {
    return this._version;
  }
  // Clone the model
  clone() {
    const e = new k();
    return e._lines = [...this._lines], e._version = this._version, e;
  }
}
class U {
  constructor(e) {
    this.gutterWidth = 50, this.lineHeight = 21, this.container = e, this.createDOM();
  }
  createDOM() {
    this.container.innerHTML = "";
    const e = document.createElement("div");
    e.style.cssText = `
      position: relative;
      display: flex;
      width: 100%;
      height: 100%;
      background: var(--editor-background, #1e1e1e);
      color: var(--editor-foreground, #f8f9fa);
      font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
      font-size: 14px;
      line-height: ${this.lineHeight}px;
      overflow: hidden;
    `, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.style.cssText = `
      position: sticky;
      left: 0;
      top: 0;
      width: ${this.gutterWidth}px;
      background: var(--editor-gutter-background, #252526);
      color: var(--editor-gutter-foreground, #858585);
      padding: 0;
      text-align: right;
      border-right: 1px solid var(--editor-gutter-border, #3e3e42);
      user-select: none;
      overflow: hidden;
      z-index: 1;
    `, this.contentElement = document.createElement("div"), this.contentElement.style.cssText = `
      flex: 1;
      padding: 0;
      background: transparent;
      border: none;
      outline: none;
      white-space: pre;
      overflow-x: auto;
      overflow-y: auto;
      min-height: 400px;
      font-family: inherit;
      font-size: inherit;
      line-height: inherit;
      color: inherit;
      tab-size: 2;
      -moz-tab-size: 2;
    `, this.contentElement.contentEditable = "true", this.contentElement.spellcheck = !1, e.appendChild(this.lineNumbersElement), e.appendChild(this.contentElement), this.container.appendChild(e), this.updateLineNumbers(1);
  }
  // Update line numbers
  updateLineNumbers(e) {
    const t = Math.max(e, 20), n = Array.from({ length: t }, (r, i) => i + 1);
    this.lineNumbersElement.innerHTML = n.map((r) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${r}</div>`).join("");
  }
  // Get content element
  getContentElement() {
    return this.contentElement;
  }
  // Get line numbers element
  getLineNumbersElement() {
    return this.lineNumbersElement;
  }
  // Get text content
  getText() {
    return this.contentElement.textContent || "";
  }
  // Set text content
  setText(e) {
    this.contentElement.textContent = e;
    const t = e.split(`
`).length;
    this.updateLineNumbers(t);
  }
  // Get cursor position from DOM selection
  getCursorPosition() {
    const e = window.getSelection();
    if (!e || e.rangeCount === 0)
      return { line: 0, column: 0 };
    const t = e.getRangeAt(0), n = t.cloneRange();
    n.selectNodeContents(this.contentElement), n.setEnd(t.endContainer, t.endOffset);
    const r = n.toString().split(`
`);
    return {
      line: r.length - 1,
      column: r[r.length - 1].length
    };
  }
  // Set cursor position
  setCursorPosition(e) {
    var g, f;
    const t = this.getText().split(`
`), n = Math.min(e.line, t.length - 1), r = Math.min(e.column, ((g = t[n]) == null ? void 0 : g.length) || 0);
    let i = 0;
    for (let m = 0; m < n; m++)
      i += t[m].length + 1;
    i += r;
    const o = document.createRange(), l = window.getSelection();
    let s = 0, d = null, a = 0;
    const c = document.createTreeWalker(
      this.contentElement,
      NodeFilter.SHOW_TEXT,
      null
    );
    let u;
    for (; u = c.nextNode(); ) {
      const m = ((f = u.textContent) == null ? void 0 : f.length) || 0;
      if (s + m >= i) {
        d = u, a = i - s;
        break;
      }
      s += m;
    }
    if (d)
      try {
        o.setStart(d, a), o.setEnd(d, a), l == null || l.removeAllRanges(), l == null || l.addRange(o);
      } catch (m) {
        console.warn("Could not set cursor position:", m);
      }
  }
  // Get selection range
  getSelectionRange() {
    const e = window.getSelection();
    if (!e || e.rangeCount === 0 || e.isCollapsed)
      return;
    const t = e.getRangeAt(0), n = t.cloneRange();
    n.selectNodeContents(this.contentElement), n.setEnd(t.startContainer, t.startOffset);
    const r = n.toString().split(`
`), i = t.cloneRange();
    i.selectNodeContents(this.contentElement), i.setEnd(t.endContainer, t.endOffset);
    const o = i.toString().split(`
`);
    return {
      start: {
        line: r.length - 1,
        column: r[r.length - 1].length
      },
      end: {
        line: o.length - 1,
        column: o[o.length - 1].length
      }
    };
  }
  // Set selection range
  setSelectionRange(e) {
    this.setCursorPosition(e.start);
  }
  // Focus the editor
  focus() {
    this.contentElement.focus();
  }
  // Blur the editor
  blur() {
    this.contentElement.blur();
  }
  // Set read-only mode
  setReadOnly(e) {
    this.contentElement.contentEditable = e ? "false" : "true";
  }
  // Apply theme
  applyTheme(e) {
    Object.entries(e).forEach(([t, n]) => {
      this.container.style.setProperty(`--${t}`, n);
    });
  }
  // Scroll to position
  scrollToPosition(e) {
    const t = this.lineNumbersElement.children[e.line];
    t && t.scrollIntoView({ block: "center", behavior: "smooth" });
  }
  // Get scroll position
  getScrollTop() {
    return this.contentElement.scrollTop;
  }
  // Set scroll position
  setScrollTop(e) {
    this.contentElement.scrollTop = e, this.lineNumbersElement.scrollTop = e;
  }
  // Destroy the view
  destroy() {
    this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container);
  }
}
class P {
  constructor(e, t = {}) {
    this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.config = {
      value: "",
      theme: "default",
      readOnly: !1,
      tabSize: 2,
      lineWrapping: !1,
      lineNumbers: !0,
      ...t
    }, this.textModel = new k(this.config.value), this.view = new U(e), this.view.setText(this.textModel.getText()), this.view.setReadOnly(this.config.readOnly || !1), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((n) => this.addExtension(n)), this.setTheme(this.config.theme);
  }
  // Public accessors for extensions
  getTextModel() {
    return this.textModel;
  }
  getView() {
    return this.view;
  }
  getConfig() {
    return { ...this.config };
  }
  // Get keymap extension if available
  getKeymapExtension() {
    return this.extensions.get("keymap");
  }
  // Setup DOM event handlers
  setupEventHandlers() {
    const e = this.view.getContentElement();
    e.addEventListener("input", () => {
      const t = this.view.getText(), n = this.textModel.getText();
      t !== n && (this.textModel.setText(t), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: n }]), this.updateLineNumbers());
    }), e.addEventListener("selectionchange", () => {
      const t = this.getCursor(), n = this.getSelection();
      this.emit("cursor", t), n && this.emit("selection", n);
    }), e.addEventListener("keydown", (t) => {
      this.emit("keydown", t);
      for (const n of this.extensions.values())
        if (n.onKeyDown && n.onKeyDown(t) === !1) {
          t.preventDefault(), t.stopPropagation();
          return;
        }
    }), e.addEventListener("mousedown", (t) => {
      this.emit("mousedown", t);
      for (const n of this.extensions.values())
        if (n.onMouseDown && n.onMouseDown(t) === !1) {
          t.preventDefault(), t.stopPropagation();
          return;
        }
    }), e.addEventListener("focus", () => {
      this.emit("focus");
    }), e.addEventListener("blur", () => {
      this.emit("blur");
    });
  }
  // Update line numbers display
  updateLineNumbers() {
    const e = this.textModel.getLineCount();
    this.view.updateLineNumbers(e);
  }
  // Get full range of document
  getFullRange() {
    return {
      start: { line: 0, column: 0 },
      end: {
        line: this.textModel.getLineCount() - 1,
        column: this.textModel.getLine(this.textModel.getLineCount() - 1).length
      }
    };
  }
  // Emit events to listeners
  emit(e, ...t) {
    const n = this.eventListeners.get(e);
    n && n.forEach((r) => r(...t));
  }
  // State management
  getValue() {
    return this.textModel.getText();
  }
  setValue(e) {
    this.textModel.setText(e), this.view.setText(e), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: this.getValue() }]);
  }
  getState() {
    return {
      text: this.getValue(),
      cursor: this.getCursor(),
      selection: this.getSelection(),
      readOnly: this.config.readOnly || !1,
      theme: this.currentTheme
    };
  }
  // Cursor & Selection
  getCursor() {
    const e = this.view.getCursorPosition();
    return {
      position: e,
      anchor: e
      // For now, cursor and anchor are the same
    };
  }
  setCursor(e) {
    this.view.setCursorPosition(e), this.emit("cursor", this.getCursor());
  }
  getSelection() {
    return this.view.getSelectionRange();
  }
  setSelection(e) {
    this.view.setSelectionRange(e), this.emit("selection", e);
  }
  // Configuration
  setTheme(e) {
    this.currentTheme = e;
    const t = {
      "editor-background": e === "dark" ? "#1e1e1e" : "#ffffff",
      "editor-foreground": e === "dark" ? "#f8f9fa" : "#1a1a1a",
      "editor-gutter-background": e === "dark" ? "#252526" : "#f8f9fa",
      "editor-gutter-foreground": e === "dark" ? "#858585" : "#666666",
      "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
    };
    this.view.applyTheme(t);
  }
  setReadOnly(e) {
    this.config.readOnly = e, this.view.setReadOnly(e);
  }
  // Extensions & Commands
  addExtension(e) {
    if (this.extensions.has(e.name))
      throw new Error(`Extension '${e.name}' already exists`);
    this.extensions.set(e.name, e), e.setup(this);
  }
  removeExtension(e) {
    const t = this.extensions.get(e);
    t && t.destroy && t.destroy(), this.extensions.delete(e);
  }
  executeCommand(e, ...t) {
    const n = this.commands.get(e);
    n ? n(this, ...t) : console.warn(`Command '${e}' not found`);
  }
  // Register a command
  registerCommand(e, t) {
    this.commands.set(e, t);
  }
  // Search & Navigation
  search(e, t = {}) {
    const n = {
      caseSensitive: !1,
      regex: !1,
      ...t
    }, r = [], i = this.getValue();
    i.split(`
`);
    let o = n.caseSensitive ? i : i.toLowerCase(), l = n.caseSensitive ? e : e.toLowerCase();
    if (n.regex) {
      const s = new RegExp(l, n.caseSensitive ? "g" : "gi");
      let d;
      for (; (d = s.exec(o)) !== null; ) {
        const a = this.textModel.offsetToPosition(d.index), c = this.textModel.offsetToPosition(d.index + d[0].length);
        r.push({
          range: { start: a, end: c },
          match: d[0]
        });
      }
    } else {
      let s = 0, d = o.indexOf(l, s);
      for (; d !== -1; ) {
        const a = d + e.length, c = this.textModel.offsetToPosition(d), u = this.textModel.offsetToPosition(a);
        r.push({
          range: { start: c, end: u },
          match: i.substring(d, a)
        }), s = a, d = o.indexOf(l, s);
      }
    }
    return r;
  }
  replace(e, t) {
    const n = this.textModel.replaceRange(e, t);
    this.view.setText(this.getValue()), this.emit("change", [n]);
  }
  replaceAll(e, t, n = {}) {
    const r = this.search(e, n);
    let i = 0;
    for (let o = r.length - 1; o >= 0; o--)
      this.replace(r[o].range, t), i++;
    return i;
  }
  // Folding (basic implementation)
  fold(e) {
    const t = {
      start: e.start,
      end: e.end,
      collapsed: !0,
      level: 0
    };
    this.folds.push(t);
  }
  unfold(e) {
    this.folds = this.folds.filter(
      (t) => !(t.start.line === e.start.line && t.end.line === e.end.line)
    );
  }
  getFolds() {
    return [...this.folds];
  }
  // Utilities
  focus() {
    this.view.focus();
  }
  blur() {
    this.view.blur();
  }
  destroy() {
    if (!this.isDestroyed) {
      this.isDestroyed = !0;
      for (const e of this.extensions.values())
        e.destroy && e.destroy();
      this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
    }
  }
  // Events
  on(e, t) {
    this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
  }
  off(e, t) {
    if (!this.eventListeners.has(e)) return;
    const n = this.eventListeners.get(e);
    if (t) {
      const r = n.indexOf(t);
      r !== -1 && n.splice(r, 1);
    } else
      n.length = 0;
  }
}
class z {
  constructor(e) {
    this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
  }
  setup(e) {
    this.editor = e, e.on("keydown", (t) => this.handleKeyDown(t));
  }
  handleKeyDown(e) {
    if (!this.editor) return;
    const t = this.findMatchingBinding(e);
    if (t)
      return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
  }
  findMatchingBinding(e) {
    const { key: t, ctrlKey: n, altKey: r, shiftKey: i, metaKey: o } = e, l = t.toLowerCase(), s = this.keymap[l];
    if (!s) return null;
    for (const d of s)
      if ((d.ctrlKey === n || !d.ctrlKey && !n) && (d.altKey === r || !d.altKey && !r) && (d.shiftKey === i || !d.shiftKey && !i) && (d.metaKey === o || !d.metaKey && !o))
        return d;
    return null;
  }
  getDefaultKeymap() {
    const e = {};
    return this.addBinding(e, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(e, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(e, "f3", {}, "findNext"), this.addBinding(e, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(e, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(e, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(e, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(e, "s", { ctrlKey: !this.isMac, metaKey: this.isMac }, "save"), this.addBinding(e, "z", { ctrlKey: !this.isMac, metaKey: this.isMac }, "undo"), this.addBinding(e, "y", { ctrlKey: !this.isMac, metaKey: this.isMac }, "redo"), this.addBinding(e, "z", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "redo"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), e;
  }
  addBinding(e, t, n, r) {
    const i = t.toLowerCase();
    e[i] || (e[i] = []), e[i].push({
      key: i,
      command: r,
      ...n
    });
  }
  // Public API for customizing keymap
  setKeymap(e) {
    this.keymap = { ...e };
  }
  addKeyBinding(e) {
    const t = e.key.toLowerCase();
    this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((n) => n.command !== e.command), this.keymap[t].push({
      ...e,
      key: t
    });
  }
  removeKeyBinding(e, t) {
    const n = e.toLowerCase();
    t ? this.keymap[n] && (this.keymap[n] = this.keymap[n].filter((r) => r.command !== t), this.keymap[n].length === 0 && delete this.keymap[n]) : delete this.keymap[n];
  }
  getKeymap() {
    return { ...this.keymap };
  }
  getBindingsForCommand(e) {
    const t = [];
    for (const n in this.keymap)
      for (const r of this.keymap[n])
        r.command === e && t.push({ ...r });
    return t;
  }
  getPlatformInfo() {
    return {
      isMac: this.isMac,
      platform: navigator.platform
    };
  }
  destroy() {
    this.keymap = {}, this.editor = null;
  }
}
class A {
  constructor() {
    this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
  }
  setup(e) {
    this.editor = e, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
      this.toggle();
    }), e.on("change", () => {
      this.updateLineNumbers();
    }), this.updateLineNumbers();
  }
  createLineNumbers() {
    if (!this.editor) return;
    const e = this.editor.getView();
    if (!e.container) return;
    this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.style.cssText = `
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 50px;
      background: var(--editor-gutter-background, #252526);
      color: var(--editor-gutter-foreground, #858585);
      font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
      font-size: 14px;
      line-height: 21px;
      padding: 0;
      text-align: right;
      border-right: 1px solid var(--editor-gutter-border, #3e3e42);
      user-select: none;
      overflow: hidden;
      z-index: 1;
      pointer-events: none;
    `;
    const t = e.getContentElement();
    t && t.parentNode && (t.parentNode.insertBefore(this.lineNumbersElement, t), t.style.marginLeft = "60px");
  }
  updateLineNumbers() {
    if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
    const e = this.editor.getValue().split(`
`).length, t = Array.from({ length: Math.max(e, 20) }, (n, r) => r + 1);
    this.lineNumbersElement.innerHTML = t.map((n) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${n}</div>`).join("");
  }
  toggle() {
    this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
    const e = this.editor.getView().getContentElement();
    e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
  }
  destroy() {
    this.lineNumbersElement && this.lineNumbersElement.parentNode && this.lineNumbersElement.parentNode.removeChild(this.lineNumbersElement), this.lineNumbersElement = null, this.editor = null;
  }
}
class V {
  constructor() {
    this.name = "theme", this.editor = null, this.currentTheme = "dark";
  }
  setup(e) {
    this.editor = e, e.registerCommand("setTheme", (t) => {
      this.setTheme(t);
    }), e.registerCommand("toggleTheme", () => {
      this.toggleTheme();
    }), this.setTheme(this.currentTheme);
  }
  setTheme(e) {
    this.editor && (this.currentTheme = e, this.editor.setTheme(e));
  }
  toggleTheme() {
    const e = this.currentTheme === "dark" ? "light" : "dark";
    this.setTheme(e);
  }
  getCurrentTheme() {
    return this.currentTheme;
  }
  destroy() {
    this.editor = null;
  }
}
class F {
  constructor() {
    this.name = "read-only", this.editor = null, this.isReadOnly = !1;
  }
  setup(e) {
    this.editor = e, e.registerCommand("setReadOnly", (t) => {
      this.setReadOnly(t);
    }), e.registerCommand("toggleReadOnly", () => {
      this.toggleReadOnly();
    }), e.on("keydown", (t) => {
      if (t.ctrlKey && t.key === "r")
        return t.preventDefault(), this.toggleReadOnly(), !1;
    });
  }
  setReadOnly(e) {
    this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
  }
  toggleReadOnly() {
    this.setReadOnly(!this.isReadOnly);
  }
  isCurrentlyReadOnly() {
    return this.isReadOnly;
  }
  destroy() {
    this.editor = null;
  }
}
class q {
  constructor() {
    this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
  }
  setup(e) {
    this.editor = e, e.registerCommand("find", () => {
      this.showSearch();
    }), e.registerCommand("findNext", () => {
      this.findNext();
    }), e.registerCommand("findPrev", () => {
      this.findPrev();
    }), e.registerCommand("replace", () => {
      this.showReplace();
    }), e.registerCommand("replaceAll", (t, n) => {
      this.replaceAll(t, n);
    });
  }
  showSearch() {
    if (this.editor && (this.searchUI || this.createSearchUI(), this.isVisible = !0, this.searchUI)) {
      this.searchUI.style.display = "block";
      const e = this.searchUI.querySelector("input");
      e && (e.focus(), e.select());
    }
  }
  showReplace() {
    var n, r;
    this.showSearch();
    const e = (n = this.searchUI) == null ? void 0 : n.querySelector(".search-replace-input");
    e && (e.style.display = "block", e.focus());
    const t = (r = this.searchUI) == null ? void 0 : r.querySelector(".search-status");
    t && (t.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
  }
  hideSearch() {
    this.isVisible = !1, this.searchUI && (this.searchUI.style.display = "none"), this.clearHighlights();
  }
  createSearchUI() {
    if (!this.editor) return;
    const e = document.querySelector(".rte-source-editor-modal");
    if (!e) return;
    this.searchUI = document.createElement("div"), this.searchUI.style.cssText = `
      position: absolute;
      top: 10px;
      right: 10px;
      background: var(--editor-background, #1e1e1e);
      border: 1px solid var(--editor-gutter-border, #3e3e42);
      border-radius: 4px;
      padding: 8px;
      z-index: 1000;
      display: none;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
      min-width: 250px;
    `, this.searchUI.innerHTML = `
      <div style="display: flex; align-items: center; gap: 4px; margin-bottom: 4px;">
        <input type="text" placeholder="Find..." style="
          flex: 1;
          padding: 4px 8px;
          background: var(--editor-gutter-background, #252526);
          color: var(--editor-foreground, #f8f9fa);
          border: 1px solid var(--editor-gutter-border, #3e3e42);
          border-radius: 3px;
          font-size: 12px;
          outline: none;
        " />
        <button class="search-prev" style="
          padding: 2px 6px;
          background: var(--editor-gutter-background, #252526);
          color: var(--editor-gutter-foreground, #858585);
          border: 1px solid var(--editor-gutter-border, #3e3e42);
          border-radius: 3px;
          cursor: pointer;
          font-size: 11px;
        ">↑</button>
        <button class="search-next" style="
          padding: 2px 6px;
          background: var(--editor-gutter-background, #252526);
          color: var(--editor-gutter-foreground, #858585);
          border: 1px solid var(--editor-gutter-border, #3e3e42);
          border-radius: 3px;
          cursor: pointer;
          font-size: 11px;
        ">↓</button>
        <button class="search-close" style="
          padding: 2px 6px;
          background: var(--editor-gutter-background, #252526);
          color: var(--editor-gutter-foreground, #858585);
          border: 1px solid var(--editor-gutter-border, #3e3e42);
          border-radius: 3px;
          cursor: pointer;
          font-size: 11px;
        ">×</button>
      </div>
      <div class="search-status" style="
        font-size: 11px;
        color: var(--editor-gutter-foreground, #858585);
        text-align: center;
      "></div>
      <input type="text" class="search-replace-input" placeholder="Replace with..." style="
        width: 100%;
        padding: 4px 8px;
        background: var(--editor-gutter-background, #252526);
        color: var(--editor-foreground, #f8f9fa);
        border: 1px solid var(--editor-gutter-border, #3e3e42);
        border-radius: 3px;
        font-size: 12px;
        outline: none;
        display: none;
        margin-top: 4px;
      " />
    `;
    const t = this.searchUI.querySelector("input"), n = this.searchUI.querySelector(".search-replace-input"), r = this.searchUI.querySelector(".search-prev"), i = this.searchUI.querySelector(".search-next"), o = this.searchUI.querySelector(".search-close");
    t.addEventListener("input", () => {
      this.performSearch(t.value);
    }), t.addEventListener("keydown", (l) => {
      l.key === "Enter" && (l.preventDefault(), l.shiftKey ? this.findPrev() : this.findNext());
    }), n.addEventListener("keydown", (l) => {
      l.key === "Enter" && (l.preventDefault(), l.shiftKey ? this.replaceAll(t.value, n.value) : this.replaceCurrent(t.value, n.value));
    }), r.addEventListener("click", () => this.findPrev()), i.addEventListener("click", () => this.findNext()), o.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
  }
  performSearch(e) {
    if (!this.editor || !e.trim()) {
      this.clearHighlights(), this.updateStatus("");
      return;
    }
    const t = this.editor.getValue(), n = [];
    let r = t.toLowerCase().indexOf(e.toLowerCase());
    for (; r !== -1; ) {
      const i = this.getPositionFromOffset(t, r), o = this.getPositionFromOffset(t, r + e.length);
      n.push({
        range: { start: i, end: o },
        match: t.substring(r, r + e.length)
      }), r = t.toLowerCase().indexOf(e.toLowerCase(), r + 1);
    }
    this.currentResults = n, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
  }
  getPositionFromOffset(e, t) {
    const n = e.substring(0, t).split(`
`), r = n.length - 1, i = n[n.length - 1].length;
    return { line: r, column: i };
  }
  findNext() {
    this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
  }
  findPrev() {
    this.currentResults.length !== 0 && (this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights());
  }
  replaceCurrent(e, t) {
    if (!this.editor || !e.trim() || this.currentIndex === -1) return;
    const n = this.currentResults[this.currentIndex];
    if (!n) return;
    const r = this.editor.getValue(), i = this.getOffsetFromPosition(r, n.range.start), o = r.substring(0, i), l = r.substring(i + e.length), s = o + t + l;
    this.editor.setValue(s), this.performSearch(e), this.updateStatus("Replaced current occurrence");
  }
  replaceAll(e, t) {
    if (!this.editor || !e.trim()) return;
    let n = this.editor.getValue(), r = 0, i = n.toLowerCase().indexOf(e.toLowerCase());
    for (; i !== -1; )
      n = n.substring(0, i) + t + n.substring(i + e.length), r++, i = n.toLowerCase().indexOf(e.toLowerCase(), i + t.length);
    r > 0 && (this.editor.setValue(n), this.updateStatus(`Replaced ${r} occurrences`));
  }
  getOffsetFromPosition(e, t) {
    const n = e.split(`
`);
    let r = 0;
    for (let i = 0; i < t.line; i++)
      r += n[i].length + 1;
    return r += t.column, r;
  }
  updateHighlights() {
    this.clearHighlights(), !(this.currentResults.length === 0 || this.currentIndex === -1) && (this.currentResults[this.currentIndex], this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`));
  }
  clearHighlights() {
  }
  updateStatus(e) {
    var n;
    const t = (n = this.searchUI) == null ? void 0 : n.querySelector(".search-status");
    t && (t.textContent = e);
  }
  destroy() {
    this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
  }
}
class D {
  constructor() {
    this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
      "(": ")",
      "[": "]",
      "{": "}",
      "<": ">"
    }, this.reverseBracketPairs = {
      ")": "(",
      "]": "[",
      "}": "{",
      ">": "<"
    }, this.currentMatch = null;
  }
  setup(e) {
    this.editor = e, e.on("cursor", () => {
      this.updateBracketMatching();
    }), e.on("change", () => {
      this.updateBracketMatching();
    });
  }
  updateBracketMatching() {
    if (!this.editor) return;
    const e = this.editor.getCursor(), t = this.editor.getValue();
    this.clearBracketHighlighting();
    const n = this.getBracketAtPosition(t, e.position);
    if (!n) return;
    const r = this.findMatchingBracket(t, n);
    r && (this.currentMatch = r, this.highlightBrackets(r));
  }
  getBracketAtPosition(e, t) {
    const n = e.split(`
`);
    if (t.line >= n.length) return null;
    const r = n[t.line];
    if (t.column >= r.length) return null;
    const i = r[t.column];
    return this.bracketPairs[i] || this.reverseBracketPairs[i] ? { char: i, position: t } : null;
  }
  findMatchingBracket(e, t) {
    const n = e.split(`
`), r = t.position.line, i = t.position.column, o = t.char;
    return this.bracketPairs[o] ? this.findClosingBracket(e, n, r, i, o) : this.reverseBracketPairs[o] ? this.findOpeningBracket(e, n, r, i, o) : null;
  }
  findClosingBracket(e, t, n, r, i) {
    const o = this.bracketPairs[i];
    let l = 0;
    for (let s = n; s < t.length; s++) {
      const d = t[s], a = s === n ? r : 0;
      for (let c = a; c < d.length; c++) {
        const u = d[c];
        if (u === i)
          l++;
        else if (u === o && (l--, l === 0))
          return {
            open: { start: { line: n, column: r }, end: { line: n, column: r + 1 } },
            close: { start: { line: s, column: c }, end: { line: s, column: c + 1 } },
            type: i
          };
      }
    }
    return null;
  }
  findOpeningBracket(e, t, n, r, i) {
    const o = this.reverseBracketPairs[i];
    let l = 0;
    for (let s = n; s >= 0; s--) {
      const d = t[s], a = s === n ? r : d.length - 1;
      for (let c = a; c >= 0; c--) {
        const u = d[c];
        if (u === i)
          l++;
        else if (u === o && (l--, l === 0))
          return {
            open: { start: { line: s, column: c }, end: { line: s, column: c + 1 } },
            close: { start: { line: n, column: r }, end: { line: n, column: r + 1 } },
            type: o
          };
      }
    }
    return null;
  }
  highlightBrackets(e) {
    console.log("Bracket match found:", e);
  }
  clearBracketHighlighting() {
    this.currentMatch = null;
  }
  getCurrentMatch() {
    return this.currentMatch;
  }
  destroy() {
    this.clearBracketHighlighting(), this.editor = null;
  }
}
class $ {
  constructor() {
    this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
  }
  setup(e) {
    this.editor = e, e.registerCommand("fold", () => {
      console.log("Fold command executed - folding not yet implemented"), this.foldAtCursor();
    }), e.registerCommand("unfold", () => {
      console.log("Unfold command executed - unfolding not yet implemented"), this.unfoldAtCursor();
    }), e.registerCommand("foldAll", () => {
      console.log("Fold all command executed - folding not yet implemented"), this.foldAll();
    }), e.registerCommand("unfoldAll", () => {
      console.log("Unfold all command executed - unfolding not yet implemented"), this.unfoldAll();
    }), e.on("change", () => {
      this.updateFoldIndicators();
    }), this.createFoldingUI(), this.updateFoldIndicators();
  }
  createFoldingUI() {
    if (!this.editor) return;
    const e = document.querySelector(".rte-source-editor-modal");
    e && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
      position: absolute;
      left: 40px;
      top: 0;
      bottom: 0;
      width: 20px;
      pointer-events: none;
      z-index: 2;
    `, e.appendChild(this.foldingUI));
  }
  updateFoldIndicators() {
    if (!this.editor || !this.foldingUI) return;
    this.foldingUI.innerHTML = "", this.foldIndicators = [];
    const e = this.editor.getValue().split(`
`);
    this.findFoldableLines(e).forEach((t) => {
      this.createFoldIndicator(t);
    });
  }
  findFoldableLines(e) {
    const t = [];
    for (let n = 0; n < e.length; n++) {
      const r = e[n].trim();
      (r.startsWith("{") || r.startsWith("function") || r.startsWith("class") || r.startsWith("if") || r.includes("=>") || r.startsWith("for") || r.startsWith("while") || r.startsWith("try")) && t.push(n);
    }
    return t;
  }
  createFoldIndicator(e) {
    if (!this.foldingUI) return;
    const t = document.createElement("div");
    t.style.cssText = `
      position: absolute;
      left: 0;
      top: ${e * 21}px;
      width: 20px;
      height: 21px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      pointer-events: auto;
      color: var(--editor-gutter-foreground, #858585);
      font-size: 10px;
      user-select: none;
    `, t.innerHTML = "▶", t.title = "Code folding not yet implemented - click shows fold indicators", t.addEventListener("click", () => {
      console.log(`Fold toggle clicked at line ${e} - implementation pending`);
    }), this.foldingUI.appendChild(t), this.foldIndicators.push(t);
  }
  foldAtCursor() {
    console.log("foldAtCursor called - implementation pending");
  }
  unfoldAtCursor() {
    console.log("unfoldAtCursor called - implementation pending");
  }
  foldAll() {
    console.log("foldAll called - implementation pending");
  }
  unfoldAll() {
    console.log("unfoldAll called - implementation pending");
  }
  destroy() {
    this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
  }
}
class _ {
  constructor() {
    this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark";
  }
  setup(e) {
    this.editor = e, console.log("SyntaxHighlightingExtension: Isolated extension loaded - ready for use");
  }
  // Extension provides methods that can be called by the editor
  setTheme(e) {
    this.currentTheme = e, console.log(`SyntaxHighlightingExtension: Theme changed to ${e}`);
  }
  // Method to get syntax highlighting colors for a given theme
  getSyntaxColors() {
    return this.currentTheme === "dark" ? {
      tag: "#569cd6",
      // Blue
      comment: "#6a9955",
      // Green
      attrValue: "#ce9178",
      // Orange
      text: "#d4d4d4"
      // Light gray
    } : {
      tag: "#0000ff",
      // Blue
      comment: "#008000",
      // Green
      attrValue: "#a31515",
      // Red
      text: "#000000"
      // Black
    };
  }
  // Method to parse and highlight HTML content (returns highlighted HTML string)
  highlightHTML(e) {
    const t = this.getSyntaxColors();
    let n = e;
    return n = n.replace(
      /(<\/?[\w:-]+(?:\s[^>]*?)?\/?>)/g,
      `<span style="color: ${t.tag};">$1</span>`
    ), n = n.replace(
      /(<!--[\s\S]*?-->)/g,
      `<span style="color: ${t.comment};">$1</span>`
    ), n = n.replace(
      /("[^"]*"|'[^']*')/g,
      `<span style="color: ${t.attrValue};">$1</span>`
    ), n;
  }
  // Method to check if content contains syntax that should be highlighted
  shouldHighlight(e) {
    return /<\/?[\w:-]+|<!--/.test(e);
  }
  destroy() {
    this.editor = null, console.log("SyntaxHighlightingExtension: Extension destroyed");
  }
}
function j(p, e) {
  const t = { ...e };
  return t.extensions || (t.extensions = []), t.extensions.some((n) => n.name === "keymap") || t.extensions.unshift(new z(t.keymap)), new P(p, t);
}
const W = `/* Source Editor Dialog Styles */
.rte-source-editor-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background-color: rgba(0, 0, 0, 0.6) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 10000 !important;
  padding: 20px !important;
  box-sizing: border-box !important;
  margin: 0 !important;
}

.rte-source-editor-overlay.fullscreen {
  padding: 0 !important;
}

.rte-source-editor-modal {
  background: white;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 1200px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
  border-radius: 0;
  max-width: 100%;
  max-height: 100vh;
  width: 100%;
  height: 100vh;
}

.rte-source-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e1e5e9;
  background: #f8f9fa;
  border-radius: 8px 8px 0 0;
}

.rte-source-editor-overlay.fullscreen .rte-source-editor-header {
  border-radius: 0;
}

.rte-source-editor-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
}

.rte-source-editor-header-toolbar {
  display: flex;
  gap: 8px;
  margin-left: auto;
  margin-right: 16px;
}

.rte-source-editor-toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s ease;
  color: #666;
}

.rte-source-editor-toolbar-btn:hover:not(:disabled) {
  background: #e1e5e9;
  color: #1a1a1a;
}

.rte-source-editor-toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rte-source-editor-toolbar-btn.active {
  background: #007acc;
  color: white;
}

.rte-source-editor-toolbar-btn.active:hover {
  background: #0056b3;
}

.rte-source-editor-header-actions {
  display: flex;
  gap: 8px;
}

.rte-source-editor-fullscreen-btn,
.rte-source-editor-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: #666;
  font-size: 16px;
  line-height: 1;
  transition: all 0.2s ease;
}

.rte-source-editor-fullscreen-btn:hover,
.rte-source-editor-close-btn:hover {
  background: #e1e5e9;
  color: #1a1a1a;
}

.rte-source-editor-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.rte-source-editor-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #666;
  position: absolute;
  z-index: 9;
  margin: 0 auto;
  width: 100%;
  top: 44%;
}

.rte-source-editor-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e1e5e9;
  border-top: 3px solid #007acc;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.rte-source-editor-error {
  background: #fee;
  color: #c53030;
  padding: 12px 16px;
  border-left: 4px solid #c53030;
  margin: 16px;
  border-radius: 4px;
  font-size: 14px;
}

.rte-source-editor-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rte-source-editor-warning {
  background: #fefcbf;
  color: #744210;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  border-bottom: 1px solid #f6e05e;
}

.rte-source-editor-codemirror {
  flex: 1;
  overflow: auto;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 14px;
  line-height: 1.5;
}

.rte-source-editor-codemirror .cm-editor {
  height: 100%;
}

.rte-source-editor-codemirror .cm-focused {
  outline: none;
}

.rte-source-editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid #e1e5e9;
  background: #f8f9fa;
  border-radius: 0 0 8px 8px;
}

.rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
  border-radius: 0;
}

.rte-source-editor-footer-info {
  font-size: 12px;
  color: #666;
}

.unsaved-changes {
  color: #d69e2e;
  font-weight: 500;
}

.rte-source-editor-footer-actions {
  display: flex;
  gap: 12px;
}

.rte-source-editor-btn {
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.rte-source-editor-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.rte-source-editor-btn-cancel {
  background: white;
  border-color: #d1d5db;
  color: #374151;
}

.rte-source-editor-btn-cancel:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
}

.rte-source-editor-btn-save {
  background: #007acc;
  color: white;
}

.rte-source-editor-btn-save:hover:not(:disabled) {
  background: #0056b3;
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
  .rte-source-editor-modal {
    background: #1e1e1e;
    color: #f8f9fa;
  }

  .rte-source-editor-header {
    background: #2d2d2d;
    border-color: #404040;
  }

  .rte-source-editor-header h2 {
    color: #f8f9fa;
  }

  .rte-source-editor-fullscreen-btn,
  .rte-source-editor-close-btn {
    color: #ccc;
  }

  .rte-source-editor-fullscreen-btn:hover,
  .rte-source-editor-close-btn:hover {
    background: #404040;
    color: #f8f9fa;
  }

  .rte-source-editor-error {
    background: #2d1b1b;
    color: #fca5a5;
    border-color: #dc2626;
  }

  .rte-source-editor-warning {
    background: #2d2a1b;
    color: #fcd34d;
    border-color: #d97706;
  }

  .rte-source-editor-footer {
    background: #2d2d2d;
    border-color: #404040;
  }

  .rte-source-editor-footer-info {
    color: #ccc;
  }

  .rte-source-editor-btn-cancel {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
  }

  .rte-source-editor-btn-cancel:hover:not(:disabled) {
    background: #4b5563;
    border-color: #6b7280;
  }
}

/* Responsive design */
@media (max-width: 768px) {
  .rte-source-editor-overlay {
    padding: 10px;
  }

  .rte-source-editor-modal {
    max-height: 95vh;
  }

  .rte-source-editor-header {
    padding: 12px 16px;
  }

  .rte-source-editor-footer {
    padding: 12px 16px;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .rte-source-editor-footer-actions {
    justify-content: stretch;
  }

  .rte-source-editor-btn {
    flex: 1;
    text-align: center;
  }
}`, X = () => ({
  name: "code",
  // Toolbar button configuration
  toolbar: [
    {
      label: "Source",
      command: "toggleSourceView",
      type: "button",
      icon: "<>",
      shortcut: "Mod-Shift-S"
    }
  ],
  // Native command implementations
  commands: {
    /**
     * Toggle HTML source view
     * Opens a dialog to edit raw HTML
     */
    toggleSourceView: () => {
      const e = (() => {
        var l, s, d;
        const i = window.getSelection();
        if (i && i.anchorNode) {
          let a = i.anchorNode instanceof HTMLElement ? i.anchorNode : i.anchorNode.parentElement;
          for (; a; ) {
            if ((l = a.classList) != null && l.contains("rte-content"))
              return a;
            a = a.parentElement;
          }
        }
        if (document.activeElement) {
          let a = document.activeElement;
          if ((s = a.classList) != null && s.contains("rte-content"))
            return a;
          for (; a && a !== document.body; ) {
            if ((d = a.classList) != null && d.contains("rte-content"))
              return a;
            const c = a.querySelector(".rte-content");
            if (c) return c;
            a = a.parentElement;
          }
        }
        const o = document.querySelector("[data-editora-editor]");
        if (o) {
          const a = o.querySelector(".rte-content");
          if (a) return a;
        }
        return document.querySelector(".rte-content");
      })();
      if (!e)
        return console.error("[CodePlugin] Editor content area not found"), alert("Editor content area not found. Please click inside the editor first."), !1;
      const t = e.innerHTML, n = (i) => {
        let o = "", l = 0;
        const s = 2, d = i.split(/(<\/?[a-zA-Z][^>]*>)/);
        for (const a of d)
          a.trim() && (a.match(/^<\/[a-zA-Z]/) ? (l = Math.max(0, l - 1), o += `
` + " ".repeat(l * s) + a) : a.match(/^<[a-zA-Z]/) && !a.match(/\/>$/) ? (o += `
` + " ".repeat(l * s) + a, l++) : a.match(/^<[a-zA-Z].*\/>$/) ? o += `
` + " ".repeat(l * s) + a : o += a.trim());
        return o.trim();
      };
      return (() => {
        var E, L, M, T, S, N;
        let i = null, o = "dark", l = !1, s = !1, d = !1;
        const a = t, c = document.createElement("div");
        c.className = "rte-source-editor-overlay";
        const u = document.createElement("div");
        u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
        const g = document.createElement("div");
        g.className = "rte-source-editor-header", g.innerHTML = `
          <h2 id="source-editor-title">Source Editor</h2>
          <div class="rte-source-editor-header-toolbar">
            <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <circle cx="12" cy="12" r="5"/>
                <line x1="12" y1="1" x2="12" y2="3"/>
                <line x1="12" y1="21" x2="12" y2="23"/>
                <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
                <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
                <line x1="1" y1="12" x2="3" y2="12"/>
                <line x1="21" y1="12" x2="23" y2="12"/>
                <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
                <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
              </svg>
            </button>
            <button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
                <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
              </svg>
            </button>
          </div>
          <div class="rte-source-editor-header-actions">
            <button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
              </svg>
            </button>
            <button class="rte-source-editor-close-btn" aria-label="Close source editor">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <line x1="18" y1="6" x2="6" y2="18"/>
                <line x1="6" y1="6" x2="18" y2="18"/>
              </svg>
            </button>
          </div>
        `;
        const f = document.createElement("div");
        f.className = "rte-source-editor-body";
        const m = document.createElement("div");
        m.className = "rte-source-editor-content";
        const w = document.createElement("div");
        w.className = "rte-source-editor-warning", w.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
        const x = document.createElement("div");
        x.className = "rte-source-editor-light-editor", x.style.height = "400px", m.appendChild(w), m.appendChild(x), f.appendChild(m);
        const y = document.createElement("div");
        if (y.className = "rte-source-editor-footer", y.innerHTML = `
          <div class="rte-source-editor-footer-info">
            <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
          </div>
          <div class="rte-source-editor-footer-actions">
            <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
            <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
          </div>
        `, u.appendChild(g), u.appendChild(f), u.appendChild(y), c.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
          const h = document.createElement("style");
          h.id = "rte-source-editor-styles", h.textContent = W, document.head.appendChild(h);
        }
        document.body.appendChild(c);
        try {
          i = j(x, {
            value: n(t),
            theme: "dark",
            readOnly: !1,
            extensions: [
              new A(),
              new V(),
              new F(),
              new D(),
              new q(),
              new $(),
              new _()
            ]
          }), i.on("change", () => {
            d = ((i == null ? void 0 : i.getValue()) || "") !== n(a);
            const b = y.querySelector(".unsaved-changes");
            b && (b.style.display = d ? "inline" : "none");
          }), setTimeout(() => i == null ? void 0 : i.focus(), 100);
        } catch (h) {
          console.error("Failed to initialize code editor:", h);
        }
        const R = () => {
          o = o === "dark" ? "light" : "dark", i == null || i.setTheme(o);
          const h = g.querySelector(".theme-toggle-btn");
          h && o === "light" && (h.innerHTML = `
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
              </svg>
            `);
        }, I = () => {
          l = !l, i == null || i.setReadOnly(l);
          const h = g.querySelector(".readonly-toggle-btn");
          h && (l ? (h.classList.add("active"), h.innerHTML = `
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                  <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
                  <circle cx="12" cy="16" r="1"/>
                  <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
                </svg>
              `) : (h.classList.remove("active"), h.innerHTML = `
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                  <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
                  <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
                </svg>
              `));
        }, B = () => {
          s = !s, s ? (c.classList.add("fullscreen"), x.style.height = "calc(100vh - 200px)") : (c.classList.remove("fullscreen"), x.style.height = "400px");
          const h = g.querySelector(".rte-source-editor-fullscreen-btn");
          h && (h.innerHTML = s ? `
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
              </svg>
            ` : `
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
              </svg>
            `);
        }, v = () => {
          i && (i.destroy(), i = null), document.body.removeChild(c);
        }, H = () => {
          d && !confirm("You have unsaved changes. Are you sure you want to cancel?") || v();
        }, O = () => {
          try {
            const h = (i == null ? void 0 : i.getValue()) || "", b = document.createElement("div");
            b.innerHTML = h, b.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach((K) => K.remove()), e.innerHTML = b.innerHTML, d = !1, v();
          } catch (h) {
            alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", h);
          }
        };
        (E = g.querySelector(".theme-toggle-btn")) == null || E.addEventListener("click", R), (L = g.querySelector(".readonly-toggle-btn")) == null || L.addEventListener("click", I), (M = g.querySelector(".rte-source-editor-fullscreen-btn")) == null || M.addEventListener("click", B), (T = g.querySelector(".rte-source-editor-close-btn")) == null || T.addEventListener("click", v), (S = y.querySelector(".rte-source-editor-btn-cancel")) == null || S.addEventListener("click", H), (N = y.querySelector(".rte-source-editor-btn-save")) == null || N.addEventListener("click", O), c.addEventListener("click", (h) => {
          h.target === c && v();
        });
        const C = (h) => {
          h.key === "Escape" && (v(), document.removeEventListener("keydown", C));
        };
        document.addEventListener("keydown", C);
      })(), !0;
    }
  },
  // Keyboard shortcuts
  keymap: {
    "Mod-Shift-s": "toggleSourceView",
    "Mod-Shift-S": "toggleSourceView"
  }
});
export {
  X as CodePlugin
};
//# sourceMappingURL=CodePlugin.native-DD9xFIid.mjs.map
