Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@editora/light-code-editor

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@editora/light-code-editor - npm Package Compare versions

Comparing version
1.0.2
to
1.0.3
+821
-479
dist/index.es.js

@@ -1,8 +0,8 @@

class m {
constructor(e = "") {
this._lines = [], this._version = 0, this.setText(e);
class k {
constructor(t = "") {
this._lines = [], this._version = 0, this.setText(t);
}
// Get line at index
getLine(e) {
return this._lines[e] || "";
getLine(t) {
return this._lines[t] || "";
}

@@ -23,54 +23,54 @@ // Get all lines

// Set entire text content
setText(e) {
this._lines = e.split(`
setText(t) {
this._lines = t.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(`
getTextInRange(t) {
if (t.start.line === t.end.line)
return this.getLine(t.start.line).substring(t.start.column, t.end.column);
const e = [];
e.push(this.getLine(t.start.line).substring(t.start.column));
for (let s = t.start.line + 1; s < t.end.line; s++)
e.push(this.getLine(s));
return t.end.line < this.getLineCount() && e.push(this.getLine(t.end.line).substring(0, t.end.column)), e.join(`
`);
}
// Replace text in range
replaceRange(e, t) {
const n = this.getTextInRange(e);
if (e.start.line === e.end.line) {
const i = this.getLine(e.start.line), s = i.substring(0, e.start.column) + t + i.substring(e.end.column);
this._lines[e.start.line] = s;
replaceRange(t, e) {
const s = this.getTextInRange(t);
if (t.start.line === t.end.line) {
const i = this.getLine(t.start.line), n = i.substring(0, t.start.column) + e + i.substring(t.end.column);
this._lines[t.start.line] = n;
} else {
const i = this.getLine(e.start.line), s = this.getLine(e.end.line), o = i.substring(0, e.start.column) + t, h = s.substring(e.end.column), r = t.split(`
const i = this.getLine(t.start.line), n = this.getLine(t.end.line), o = i.substring(0, t.start.column) + e, h = n.substring(t.end.column), r = e.split(`
`);
r[0] = o + r[0], r[r.length - 1] = r[r.length - 1] + h, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...r);
r[0] = o + r[0], r[r.length - 1] = r[r.length - 1] + h, this._lines.splice(t.start.line, t.end.line - t.start.line + 1, ...r);
}
return this._version++, { range: e, text: t, oldText: n };
return this._version++, { range: t, text: e, oldText: s };
}
// Insert text at position
insertText(e, t) {
const n = { start: e, end: e };
return this.replaceRange(n, t);
insertText(t, e) {
const s = { start: t, end: t };
return this.replaceRange(s, e);
}
// Delete text in range
deleteRange(e) {
return this.replaceRange(e, "");
deleteRange(t) {
return this.replaceRange(t, "");
}
// 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;
positionToOffset(t) {
let e = 0;
for (let s = 0; s < t.line; s++)
e += this.getLine(s).length + 1;
return e += t.column, e;
}
// Convert offset to position
offsetToPosition(e) {
let t = e;
for (let n = 0; n < this.getLineCount(); n++) {
const i = this.getLine(n).length;
if (t <= i)
return { line: n, column: t };
t -= i + 1;
offsetToPosition(t) {
let e = t;
for (let s = 0; s < this.getLineCount(); s++) {
const i = this.getLine(s).length;
if (e <= i)
return { line: s, column: e };
e -= i + 1;
}

@@ -83,8 +83,8 @@ return {

// Validate position
isValidPosition(e) {
return !(e.line < 0 || e.line >= this.getLineCount() || e.column < 0 || e.column > this.getLine(e.line).length);
isValidPosition(t) {
return !(t.line < 0 || t.line >= this.getLineCount() || t.column < 0 || t.column > this.getLine(t.line).length);
}
// Validate range
isValidRange(e) {
return this.isValidPosition(e.start) && this.isValidPosition(e.end);
isValidRange(t) {
return this.isValidPosition(t.start) && this.isValidPosition(t.end);
}

@@ -97,14 +97,14 @@ // Get version for change tracking

clone() {
const e = new m();
return e._lines = [...this._lines], e._version = this._version, e;
const t = new k();
return t._lines = [...this._lines], t._version = this._version, t;
}
}
class p {
constructor(e) {
this.gutterWidth = 50, this.lineHeight = 21, this.container = e, this.createDOM();
class P {
constructor(t) {
this.gutterWidth = 50, this.lineHeight = 21, this.container = t, this.createDOM();
}
createDOM() {
this.container.innerHTML = "";
const e = document.createElement("div");
e.style.cssText = `
const t = document.createElement("div");
this.editorContainer = t, t.style.cssText = `
position: relative;

@@ -119,19 +119,19 @@ display: flex;

line-height: ${this.lineHeight}px;
overflow: hidden;
`, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.style.cssText = `
position: sticky;
left: 0;
top: 0;
/* make the outer container the single scrollable element so gutter and content scroll together */
overflow: auto;
`, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.setAttribute("data-editor-gutter", "true"), this.lineNumbersElement.style.cssText = `
display: table-cell;
vertical-align: top;
width: ${this.gutterWidth}px;
background: var(--editor-gutter-background, #252526);
color: var(--editor-gutter-foreground, #858585);
padding: 0;
padding: 0 8px 0 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;
display: table-cell;
vertical-align: top;
padding: 0 12px;
background: transparent;

@@ -142,3 +142,3 @@ border: none;

overflow-x: auto;
overflow-y: auto;
overflow-y: visible;
min-height: 400px;

@@ -151,8 +151,10 @@ font-family: inherit;

-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);
`, this.contentElement.contentEditable = "true", this.contentElement.spellcheck = !1;
const e = document.createElement("div");
e.setAttribute("data-editora-editor", "true"), e.style.cssText = "display: table; table-layout: fixed; width: 100%; height: 100%;", e.appendChild(this.lineNumbersElement), e.appendChild(this.contentElement), t.appendChild(e), this.container.appendChild(t), this.updateLineNumbers(1);
}
// Update line numbers
updateLineNumbers(e) {
const t = Math.max(e, 20), n = Array.from({ length: t }, (i, s) => s + 1);
this.lineNumbersElement.innerHTML = n.map((i) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("");
updateLineNumbers(t) {
const e = Math.max(t, 20), s = Array.from({ length: e }, (i, n) => n + 1);
this.lineNumbersElement.innerHTML = s.map((i) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("");
}

@@ -172,33 +174,41 @@ // Get content element

// Set text content
setText(e) {
this.contentElement.textContent = e;
const t = e.split(`
setText(t) {
this.contentElement.textContent = t;
const e = t.split(`
`).length;
this.updateLineNumbers(t);
this.updateLineNumbers(e);
}
// Set inner HTML (used for syntax highlighted content)
setHTML(t) {
const e = /&lt;|&gt;/.test(t), s = /<span\b/i.test(t), i = /<[^>]+>/.test(t);
e && s ? this.contentElement.innerHTML = t : i && !e ? this.contentElement.textContent = t : this.contentElement.innerHTML = t;
const o = (this.contentElement.textContent || "").split(`
`).length;
this.updateLineNumbers(o);
}
// Get cursor position from DOM selection
getCursorPosition() {
const e = window.getSelection();
if (!e || e.rangeCount === 0)
const t = window.getSelection();
if (!t || t.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 s = n.toString().split(`
const e = t.getRangeAt(0), s = e.cloneRange();
s.selectNodeContents(this.contentElement), s.setEnd(e.endContainer, e.endOffset);
const n = s.toString().split(`
`);
return {
line: s.length - 1,
column: s[s.length - 1].length
line: n.length - 1,
column: n[n.length - 1].length
};
}
// Set cursor position
setCursorPosition(e) {
const n = this.getText().split(`
`), i = Math.min(e.line, n.length - 1), s = Math.min(e.column, n[i]?.length || 0);
setCursorPosition(t) {
const s = this.getText().split(`
`), i = Math.min(t.line, s.length - 1), n = Math.min(t.column, s[i]?.length || 0);
let o = 0;
for (let g = 0; g < i; g++)
o += n[g].length + 1;
o += s;
for (let a = 0; a < i; a++)
o += s[a].length + 1;
o += n;
const h = document.createRange(), r = window.getSelection();
let l = 0, c = null, a = 0;
const u = document.createTreeWalker(
let l = 0, c = null, d = 0;
const f = document.createTreeWalker(
this.contentElement,

@@ -208,16 +218,16 @@ NodeFilter.SHOW_TEXT,

);
let f;
for (; f = u.nextNode(); ) {
const g = f.textContent?.length || 0;
if (l + g >= o) {
c = f, a = o - l;
let g;
for (; g = f.nextNode(); ) {
const a = g.textContent?.length || 0;
if (l + a >= o) {
c = g, d = o - l;
break;
}
l += g;
l += a;
}
if (c)
try {
h.setStart(c, a), h.setEnd(c, a), r?.removeAllRanges(), r?.addRange(h);
} catch (g) {
console.warn("Could not set cursor position:", g);
h.setStart(c, d), h.setEnd(c, d), r?.removeAllRanges(), r?.addRange(h);
} catch (a) {
console.warn("Could not set cursor position:", a);
}

@@ -227,10 +237,10 @@ }

getSelectionRange() {
const e = window.getSelection();
if (!e || e.rangeCount === 0 || e.isCollapsed)
const t = window.getSelection();
if (!t || t.rangeCount === 0 || t.isCollapsed)
return;
const t = e.getRangeAt(0), n = t.cloneRange();
n.selectNodeContents(this.contentElement), n.setEnd(t.startContainer, t.startOffset);
const s = n.toString().split(`
`), o = t.cloneRange();
o.selectNodeContents(this.contentElement), o.setEnd(t.endContainer, t.endOffset);
const e = t.getRangeAt(0), s = e.cloneRange();
s.selectNodeContents(this.contentElement), s.setEnd(e.startContainer, e.startOffset);
const n = s.toString().split(`
`), o = e.cloneRange();
o.selectNodeContents(this.contentElement), o.setEnd(e.endContainer, e.endOffset);
const r = o.toString().split(`

@@ -240,4 +250,4 @@ `);

start: {
line: s.length - 1,
column: s[s.length - 1].length
line: n.length - 1,
column: n[n.length - 1].length
},

@@ -251,4 +261,4 @@ end: {

// Set selection range
setSelectionRange(e) {
this.setCursorPosition(e.start);
setSelectionRange(t) {
this.setCursorPosition(t.start);
}

@@ -264,32 +274,32 @@ // Focus the editor

// Set read-only mode
setReadOnly(e) {
this.contentElement.contentEditable = e ? "false" : "true";
setReadOnly(t) {
this.contentElement.contentEditable = t ? "false" : "true";
}
// Apply theme
applyTheme(e) {
Object.entries(e).forEach(([t, n]) => {
this.container.style.setProperty(`--${t}`, n);
applyTheme(t) {
Object.entries(t).forEach(([e, s]) => {
this.container.style.setProperty(`--${e}`, s);
});
}
// Scroll to position
scrollToPosition(e) {
const t = this.lineNumbersElement.children[e.line];
t && t.scrollIntoView({ block: "center", behavior: "smooth" });
scrollToPosition(t) {
const e = this.lineNumbersElement.children[t.line];
e && e.scrollIntoView({ block: "center", behavior: "smooth" });
}
// Get scroll position
getScrollTop() {
return this.contentElement.scrollTop;
return this.editorContainer.scrollTop;
}
// Set scroll position
setScrollTop(e) {
this.contentElement.scrollTop = e, this.lineNumbersElement.scrollTop = e;
setScrollTop(t) {
this.editorContainer.scrollTop = t;
}
// Destroy the view
destroy() {
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container);
this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
}
}
class x {
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 = {
class $ {
constructor(t, e = {}) {
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.expectingProgrammaticCursor = !1, this.config = {
value: "",

@@ -301,4 +311,4 @@ theme: "default",

lineNumbers: !0,
...t
}, this.textModel = new m(this.config.value), this.view = new p(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);
...e
}, this.textModel = new k(this.config.value), this.view = new P(t), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((s) => this.addExtension(s)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
}

@@ -315,2 +325,8 @@ // Public accessors for extensions

}
// Register built-in editor commands like undo/redo/insertTab
registerBuiltInCommands() {
this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("save", () => {
this.emit("save");
});
}
// Get keymap extension if available

@@ -322,26 +338,73 @@ getKeymapExtension() {

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();
const t = this.view.getContentElement();
t.addEventListener("input", () => {
const e = this.view.getText(), s = this.textModel.getText();
if (e !== s) {
if (!this.suppressHistory) {
const i = this.getCursor().position, n = this.textModel.positionToOffset(i), o = this.getSelection();
let h, r;
o && (h = this.textModel.positionToOffset(o.start), r = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: s, cursorOffset: n, anchorOffset: h, focusOffset: r }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
}
this.textModel.setText(e), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: s }]);
}
}), t.addEventListener("selectionchange", () => {
const e = this.getCursor(), s = this.getSelection();
this.emit("cursor", e), s && this.emit("selection", s);
}), t.addEventListener("keydown", (e) => {
if (this.emit("keydown", e), e.key === "Tab") {
this.config.readOnly || this.insertTab(), e.preventDefault(), e.stopPropagation();
return;
}
if (e.key === "Enter") {
if (!this.config.readOnly) {
const s = window.getSelection();
if (s && s.rangeCount > 0) {
const i = this.getCursor().position, n = this.textModel.positionToOffset(i), o = this.getSelection();
let h, r;
o && (h = this.textModel.positionToOffset(o.start), r = this.textModel.positionToOffset(o.end)), this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: h, focusOffset: r }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
const l = s.getRangeAt(0);
l.deleteContents();
const c = document.createTextNode(`
`);
l.insertNode(c), l.setStartAfter(c), l.collapse(!0), s.removeAllRanges(), s.addRange(l);
const d = this.getCursor().position, f = this.textModel.positionToOffset(d), g = this.getSelection();
let a, u;
g && (a = this.textModel.positionToOffset(g.start), u = this.textModel.positionToOffset(g.end));
const p = this.view.getText();
this.textModel.setText(p), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
try {
if (g && (a !== void 0 || u !== void 0)) {
const m = a !== void 0 ? a : f, M = u !== void 0 ? u : f, y = Math.min(m, M), C = Math.max(m, M), w = this.textModel.offsetToPosition(y), v = this.textModel.offsetToPosition(C);
this.setSelection({ start: w, end: v });
} else {
const m = this.textModel.offsetToPosition(f);
this.setCursor(m);
}
} catch {
}
}), this.highlightTimeout = null;
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
}
}
e.preventDefault(), e.stopPropagation();
return;
}
for (const s of this.extensions.values())
if (s.onKeyDown && s.onKeyDown(e) === !1) {
e.preventDefault(), e.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();
}), t.addEventListener("mousedown", (e) => {
this.emit("mousedown", e);
for (const s of this.extensions.values())
if (s.onMouseDown && s.onMouseDown(e) === !1) {
e.preventDefault(), e.stopPropagation();
return;
}
}), e.addEventListener("focus", () => {
}), t.addEventListener("focus", () => {
this.emit("focus");
}), e.addEventListener("blur", () => {
}), t.addEventListener("blur", () => {
this.emit("blur");

@@ -352,4 +415,4 @@ });

updateLineNumbers() {
const e = this.textModel.getLineCount();
this.view.updateLineNumbers(e);
const t = this.textModel.getLineCount();
this.view.updateLineNumbers(t);
}

@@ -367,5 +430,5 @@ // Get full range of document

// Emit events to listeners
emit(e, ...t) {
const n = this.eventListeners.get(e);
n && n.forEach((i) => i(...t));
emit(t, ...e) {
const s = this.eventListeners.get(t);
s && s.forEach((i) => i(...e));
}

@@ -376,4 +439,5 @@ // State management

}
setValue(e) {
this.textModel.setText(e), this.view.setText(e), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: this.getValue() }]);
setValue(t) {
const e = this.textModel.getText();
this.textModel.setText(t), this.renderTextWithHighlight(t, !1), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: e }]);
}

@@ -391,11 +455,11 @@ getState() {

getCursor() {
const e = this.view.getCursorPosition();
const t = this.view.getCursorPosition();
return {
position: e,
anchor: e
position: t,
anchor: t
// For now, cursor and anchor are the same
};
}
setCursor(e) {
this.view.setCursorPosition(e), this.emit("cursor", this.getCursor());
setCursor(t) {
this.view.setCursorPosition(t), this.emit("cursor", this.getCursor());
}

@@ -405,55 +469,62 @@ getSelection() {

}
setSelection(e) {
this.view.setSelectionRange(e), this.emit("selection", e);
setSelection(t) {
this.view.setSelectionRange(t), this.emit("selection", t);
}
// 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"
setTheme(t) {
this.currentTheme = t;
const e = {
"editor-background": t === "dark" ? "#1e1e1e" : "#ffffff",
"editor-foreground": t === "dark" ? "#f8f9fa" : "#1a1a1a",
"editor-gutter-background": t === "dark" ? "#252526" : "#f8f9fa",
"editor-gutter-foreground": t === "dark" ? "#858585" : "#666666",
"editor-gutter-border": t === "dark" ? "#3e3e42" : "#e1e5e9"
};
this.view.applyTheme(t);
this.view.applyTheme(e);
const s = this.extensions.get("syntax-highlighting");
if (s && typeof s.setTheme == "function")
try {
s.setTheme(t === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
} catch (i) {
console.warn("Error applying theme to syntax-highlighting extension", i);
}
}
setReadOnly(e) {
this.config.readOnly = e, this.view.setReadOnly(e);
setReadOnly(t) {
this.config.readOnly = t, this.view.setReadOnly(t);
}
// 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);
addExtension(t) {
if (this.extensions.has(t.name))
throw new Error(`Extension '${t.name}' already exists`);
this.extensions.set(t.name, t), t.setup(this), t.name === "syntax-highlighting" && typeof t.highlightHTML == "function" && this.renderTextWithHighlight(this.textModel.getText());
}
removeExtension(e) {
const t = this.extensions.get(e);
t && t.destroy && t.destroy(), this.extensions.delete(e);
removeExtension(t) {
const e = this.extensions.get(t);
e && e.destroy && e.destroy(), this.extensions.delete(t);
}
executeCommand(e, ...t) {
const n = this.commands.get(e);
n ? n(this, ...t) : console.warn(`Command '${e}' not found`);
executeCommand(t, ...e) {
const s = this.commands.get(t);
s ? s(this, ...e) : console.warn(`Command '${t}' not found`);
}
// Register a command
registerCommand(e, t) {
this.commands.set(e, t);
registerCommand(t, e) {
this.commands.set(t, e);
}
// Search & Navigation
search(e, t = {}) {
const n = {
search(t, e = {}) {
const s = {
caseSensitive: !1,
regex: !1,
...t
}, i = [], s = this.getValue();
s.split(`
...e
}, i = [], n = this.getValue();
n.split(`
`);
let o = n.caseSensitive ? s : s.toLowerCase(), h = n.caseSensitive ? e : e.toLowerCase();
if (n.regex) {
const r = new RegExp(h, n.caseSensitive ? "g" : "gi");
let o = s.caseSensitive ? n : n.toLowerCase(), h = s.caseSensitive ? t : t.toLowerCase();
if (s.regex) {
const r = new RegExp(h, s.caseSensitive ? "g" : "gi");
let l;
for (; (l = r.exec(o)) !== null; ) {
const c = this.textModel.offsetToPosition(l.index), a = this.textModel.offsetToPosition(l.index + l[0].length);
const c = this.textModel.offsetToPosition(l.index), d = this.textModel.offsetToPosition(l.index + l[0].length);
i.push({
range: { start: c, end: a },
range: { start: c, end: d },
match: l[0]

@@ -465,6 +536,6 @@ });

for (; l !== -1; ) {
const c = l + e.length, a = this.textModel.offsetToPosition(l), u = this.textModel.offsetToPosition(c);
const c = l + t.length, d = this.textModel.offsetToPosition(l), f = this.textModel.offsetToPosition(c);
i.push({
range: { start: a, end: u },
match: s.substring(l, c)
range: { start: d, end: f },
match: n.substring(l, c)
}), r = c, l = o.indexOf(h, r);

@@ -475,26 +546,32 @@ }

}
replace(e, t) {
const n = this.textModel.replaceRange(e, t);
this.view.setText(this.getValue()), this.emit("change", [n]);
replace(t, e) {
const s = this.getValue();
if (!this.suppressHistory) {
const n = this.getCursor().position, o = this.textModel.positionToOffset(n), h = this.getSelection();
let r, l;
h && (r = this.textModel.positionToOffset(h.start), l = this.textModel.positionToOffset(h.end)), this.undoStack.push({ text: s, cursorOffset: o, anchorOffset: r, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
}
const i = this.textModel.replaceRange(t, e);
this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [i]);
}
replaceAll(e, t, n = {}) {
const i = this.search(e, n);
let s = 0;
replaceAll(t, e, s = {}) {
const i = this.search(t, s);
let n = 0;
for (let o = i.length - 1; o >= 0; o--)
this.replace(i[o].range, t), s++;
return s;
this.replace(i[o].range, e), n++;
return n;
}
// Folding (basic implementation)
fold(e) {
const t = {
start: e.start,
end: e.end,
fold(t) {
const e = {
start: t.start,
end: t.end,
collapsed: !0,
level: 0
};
this.folds.push(t);
this.folds.push(e);
}
unfold(e) {
unfold(t) {
this.folds = this.folds.filter(
(t) => !(t.start.line === e.start.line && t.end.line === e.end.line)
(e) => !(e.start.line === t.start.line && e.end.line === t.end.line)
);

@@ -512,71 +589,191 @@ }

}
// Render text using syntax highlighting extension if available
// If `restoreSelection` is true (default), the method captures current selection/caret
// and restores it after updating the DOM. Callers that will explicitly set the caret
// should pass `false` to avoid stomping programmatic cursor changes.
renderTextWithHighlight(t, e = !0) {
const s = this.extensions.get("syntax-highlighting");
if (s && typeof s.highlightHTML == "function")
try {
const i = !e && !this.expectingProgrammaticCursor;
let n, o, h, r;
if (e || i) {
n = this.getSelection();
const c = this.getCursor().position;
o = this.textModel.positionToOffset(c), n && (h = this.textModel.positionToOffset(n.start), r = this.textModel.positionToOffset(n.end));
}
const l = s.highlightHTML(t);
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(l) : this.view.setHTML(l), (e || i) && requestAnimationFrame(() => {
try {
if (n && (h !== void 0 || r !== void 0)) {
const c = h !== void 0 ? h : o, d = r !== void 0 ? r : o, f = Math.min(c, d), g = Math.max(c, d), a = this.textModel.offsetToPosition(f), u = this.textModel.offsetToPosition(g);
this.view.setSelectionRange({ start: a, end: u });
} else if (o !== void 0) {
const c = this.textModel.offsetToPosition(o);
this.view.setCursorPosition(c);
}
} catch {
}
});
return;
} catch (i) {
console.warn("Syntax highlighting failed, falling back to plain text", i);
}
this.view.setText(t);
}
destroy() {
if (!this.isDestroyed) {
this.isDestroyed = !0;
for (const e of this.extensions.values())
e.destroy && e.destroy();
for (const t of this.extensions.values())
t.destroy && t.destroy();
this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
}
}
// History: undo/redo
undo() {
if (this.undoStack.length === 0) return;
const t = this.undoStack.pop(), e = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
this.redoStack.push(e);
try {
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
let s, i;
typeof t == "string" ? s = t : (s = t.text, i = t.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
try {
if (i != null)
if (typeof t != "string" && (t.anchorOffset !== void 0 || t.focusOffset !== void 0)) {
const n = t.anchorOffset !== void 0 ? t.anchorOffset : i, o = t.focusOffset !== void 0 ? t.focusOffset : i, h = Math.min(n, o), r = Math.max(n, o), l = this.textModel.offsetToPosition(h), c = this.textModel.offsetToPosition(r);
this.setSelection({ start: l, end: c });
} else {
const n = this.textModel.offsetToPosition(i);
this.setCursor(n);
}
} catch {
}
}), setTimeout(() => {
this.expectingProgrammaticCursor = !1;
}, 30);
} finally {
this.suppressHistory = !1;
}
}
redo() {
if (this.redoStack.length === 0) return;
const t = this.redoStack.pop(), e = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
this.undoStack.push(e);
try {
this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
let s, i;
typeof t == "string" ? s = t : (s = t.text, i = t.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
try {
if (i != null)
if (typeof t != "string" && (t.anchorOffset !== void 0 || t.focusOffset !== void 0)) {
const n = t.anchorOffset !== void 0 ? t.anchorOffset : i, o = t.focusOffset !== void 0 ? t.focusOffset : i, h = Math.min(n, o), r = Math.max(n, o), l = this.textModel.offsetToPosition(h), c = this.textModel.offsetToPosition(r);
this.setSelection({ start: l, end: c });
} else {
const n = this.textModel.offsetToPosition(i);
this.setCursor(n);
}
} catch {
}
}), setTimeout(() => {
this.expectingProgrammaticCursor = !1;
}, 30);
} finally {
this.suppressHistory = !1;
}
}
// Insert a tab character or spaces at current cursor
insertTab() {
if (this.config.readOnly) return;
const t = this.getCursor().position, e = this.textModel.positionToOffset(t), s = " ".repeat(this.config.tabSize || 2), i = this.textModel.insertText(t, s), n = this.textModel.offsetToPosition(this.textModel.positionToOffset(t) + s.length);
if (!this.suppressHistory) {
const o = this.getSelection();
let h, r;
o && (h = this.textModel.positionToOffset(o.start), r = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: e, anchorOffset: h, focusOffset: r }), this.redoStack.length = 0;
}
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {
this.expectingProgrammaticCursor = !1;
}, 20), this.emit("change", [i]);
}
// Insert a newline at current cursor position
insertNewLine() {
if (this.config.readOnly) return;
const t = this.getCursor().position, e = this.textModel.positionToOffset(t), s = this.textModel.insertText(t, `
`), i = this.textModel.offsetToPosition(this.textModel.positionToOffset(t) + 1);
if (!this.suppressHistory) {
const n = this.getSelection();
let o, h;
n && (o = this.textModel.positionToOffset(n.start), h = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: e, anchorOffset: o, focusOffset: h }), this.redoStack.length = 0;
}
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(i), setTimeout(() => {
this.expectingProgrammaticCursor = !1;
}, 20), this.emit("change", [s]);
}
// Events
on(e, t) {
this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
on(t, e) {
this.eventListeners.has(t) || this.eventListeners.set(t, []), this.eventListeners.get(t).push(e);
}
off(e, t) {
if (!this.eventListeners.has(e)) return;
const n = this.eventListeners.get(e);
if (t) {
const i = n.indexOf(t);
i !== -1 && n.splice(i, 1);
off(t, e) {
if (!this.eventListeners.has(t)) return;
const s = this.eventListeners.get(t);
if (e) {
const i = s.indexOf(e);
i !== -1 && s.splice(i, 1);
} else
n.length = 0;
s.length = 0;
}
}
class y {
constructor(e) {
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
class H {
constructor(t) {
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = t || this.getDefaultKeymap();
}
setup(e) {
this.editor = e, e.on("keydown", (t) => this.handleKeyDown(t));
setup(t) {
this.editor = t;
}
handleKeyDown(e) {
handleKeyDown(t) {
if (!this.editor) return;
const t = this.findMatchingBinding(e);
if (t)
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
const e = this.findMatchingBinding(t);
if (e)
return this.editor.executeCommand(e.command), t.preventDefault(), t.stopPropagation(), !1;
}
findMatchingBinding(e) {
const { key: t, ctrlKey: n, altKey: i, shiftKey: s, metaKey: o } = e, h = t.toLowerCase(), r = this.keymap[h];
findMatchingBinding(t) {
const { key: e, ctrlKey: s, altKey: i, shiftKey: n, metaKey: o } = t, h = String(e).toLowerCase(), r = this.keymap[h];
if (!r) return null;
for (const l of r)
if ((l.ctrlKey === n || !l.ctrlKey && !n) && (l.altKey === i || !l.altKey && !i) && (l.shiftKey === s || !l.shiftKey && !s) && (l.metaKey === o || !l.metaKey && !o))
for (const l of r) {
const c = l.ctrlKey === void 0 || l.ctrlKey === s, d = l.altKey === void 0 || l.altKey === i, f = l.shiftKey === void 0 || l.shiftKey === n, g = l.metaKey === void 0 || l.metaKey === o;
if (c && d && f && g)
return l;
}
return null;
}
// Allow EditorCore to call this directly when checking extension.onKeyDown
onKeyDown(t) {
return this.handleKeyDown(t);
}
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;
const t = {};
return this.addBinding(t, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(t, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(t, "f3", {}, "findNext"), this.addBinding(t, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(t, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(t, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(t, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(t, "s", { ctrlKey: !0 }, "save"), this.addBinding(t, "s", { metaKey: !0 }, "save"), this.addBinding(t, "z", { ctrlKey: !0 }, "undo"), this.addBinding(t, "z", { metaKey: !0 }, "undo"), this.addBinding(t, "y", { ctrlKey: !0 }, "redo"), this.addBinding(t, "y", { metaKey: !0 }, "redo"), this.addBinding(t, "z", { ctrlKey: !0, shiftKey: !0 }, "redo"), this.addBinding(t, "z", { metaKey: !0, shiftKey: !0 }, "redo"), this.addBinding(t, "tab", {}, "insertTab"), this.addBinding(t, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), t;
}
addBinding(e, t, n, i) {
const s = t.toLowerCase();
e[s] || (e[s] = []), e[s].push({
key: s,
addBinding(t, e, s, i) {
const n = e.toLowerCase();
t[n] || (t[n] = []), t[n].push({
key: n,
command: i,
...n
...s
});
}
// Public API for customizing keymap
setKeymap(e) {
this.keymap = { ...e };
setKeymap(t) {
this.keymap = { ...t };
}
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
addKeyBinding(t) {
const e = t.key.toLowerCase();
this.keymap[e] || (this.keymap[e] = []), this.keymap[e] = this.keymap[e].filter((s) => s.command !== t.command), this.keymap[e].push({
...t,
key: e
});
}
removeKeyBinding(e, t) {
const n = e.toLowerCase();
t ? this.keymap[n] && (this.keymap[n] = this.keymap[n].filter((i) => i.command !== t), this.keymap[n].length === 0 && delete this.keymap[n]) : delete this.keymap[n];
removeKeyBinding(t, e) {
const s = t.toLowerCase();
e ? this.keymap[s] && (this.keymap[s] = this.keymap[s].filter((i) => i.command !== e), this.keymap[s].length === 0 && delete this.keymap[s]) : delete this.keymap[s];
}

@@ -586,8 +783,8 @@ getKeymap() {

}
getBindingsForCommand(e) {
const t = [];
for (const n in this.keymap)
for (const i of this.keymap[n])
i.command === e && t.push({ ...i });
return t;
getBindingsForCommand(t) {
const e = [];
for (const s in this.keymap)
for (const i of this.keymap[s])
i.command === t && e.push({ ...i });
return e;
}

@@ -604,10 +801,32 @@ getPlatformInfo() {

}
class b {
class R {
constructor() {
this.name = "transaction", this.transactions = [];
}
setup(t) {
t.on("change", (e) => {
const s = {
changes: [e],
selection: t.getSelection(),
effects: [],
annotations: []
};
this.transactions.push(s);
});
}
getTransactions() {
return this.transactions;
}
destroy() {
this.transactions = [];
}
}
class N {
constructor() {
this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
}
setup(e) {
this.editor = e, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
setup(t) {
this.editor = t, this.createLineNumbers(), t.registerCommand("toggleLineNumbers", () => {
this.toggle();
}), e.on("change", () => {
}), t.on("change", () => {
this.updateLineNumbers();

@@ -618,58 +837,37 @@ }), this.updateLineNumbers();

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 n = e.getContentElement();
n && n.parentNode && (n.parentNode.insertBefore(this.lineNumbersElement, n), n.style.marginLeft = "60px");
const e = this.editor.getView().getLineNumbersElement();
e && (this.lineNumbersElement = e);
}
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, i) => i + 1);
this.lineNumbersElement.innerHTML = t.map((n) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${n}</div>`).join("");
const t = this.editor.getValue().split(`
`).length, e = Array.from({ length: Math.max(t, 20) }, (s, i) => i + 1);
this.lineNumbersElement.innerHTML = e.map((s) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</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();
const t = this.editor.getView().getContentElement();
t && (t.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;
this.lineNumbersElement = null, this.editor = null;
}
}
class v {
class K {
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", () => {
setup(t) {
this.editor = t, t.registerCommand("setTheme", (e) => {
this.setTheme(e);
}), t.registerCommand("toggleTheme", () => {
this.toggleTheme();
}), this.setTheme(this.currentTheme);
}
setTheme(e) {
this.editor && (this.currentTheme = e, this.editor.setTheme(e));
setTheme(t) {
this.editor && (this.currentTheme = t, this.editor.setTheme(t));
}
toggleTheme() {
const e = this.currentTheme === "dark" ? "light" : "dark";
this.setTheme(e);
const t = this.currentTheme === "dark" ? "light" : "dark";
this.setTheme(t);
}

@@ -683,18 +881,18 @@ getCurrentTheme() {

}
class E {
class B {
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", () => {
setup(t) {
this.editor = t, t.registerCommand("setReadOnly", (e) => {
this.setReadOnly(e);
}), t.registerCommand("toggleReadOnly", () => {
this.toggleReadOnly();
}), e.on("keydown", (t) => {
if (t.ctrlKey && t.key === "r")
return t.preventDefault(), this.toggleReadOnly(), !1;
}), t.on("keydown", (e) => {
if (e.ctrlKey && e.key === "r")
return e.preventDefault(), this.toggleReadOnly(), !1;
});
}
setReadOnly(e) {
this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
setReadOnly(t) {
this.editor && (this.isReadOnly = t, this.editor.setReadOnly(t));
}

@@ -711,17 +909,17 @@ toggleReadOnly() {

}
class w {
class V {
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", () => {
setup(t) {
this.editor = t, t.registerCommand("find", () => {
this.showSearch();
}), e.registerCommand("findNext", () => {
}), t.registerCommand("findNext", () => {
this.findNext();
}), e.registerCommand("findPrev", () => {
}), t.registerCommand("findPrev", () => {
this.findPrev();
}), e.registerCommand("replace", () => {
}), t.registerCommand("replace", () => {
this.showReplace();
}), e.registerCommand("replaceAll", (t, n) => {
this.replaceAll(t, n);
}), t.registerCommand("replaceAll", (e, s) => {
this.replaceAll(e, s);
});

@@ -732,4 +930,4 @@ }

this.searchUI.style.display = "block";
const e = this.searchUI.querySelector("input");
e && (e.focus(), e.select());
const t = this.searchUI.querySelector("input");
t && (t.focus(), t.select());
}

@@ -739,6 +937,6 @@ }

this.showSearch();
const e = this.searchUI?.querySelector(".search-replace-input");
e && (e.style.display = "block", e.focus());
const t = this.searchUI?.querySelector(".search-status");
t && (t.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
const t = this.searchUI?.querySelector(".search-replace-input");
t && (t.style.display = "block", t.focus());
const e = this.searchUI?.querySelector(".search-status");
e && (e.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
}

@@ -750,4 +948,4 @@ hideSearch() {

if (!this.editor) return;
const e = document.querySelector(".rte-source-editor-modal");
if (!e) return;
const t = document.querySelector(".rte-source-editor-modal");
if (!t) return;
this.searchUI = document.createElement("div"), this.searchUI.style.cssText = `

@@ -823,31 +1021,31 @@ position: absolute;

`;
const t = this.searchUI.querySelector("input"), n = this.searchUI.querySelector(".search-replace-input"), i = this.searchUI.querySelector(".search-prev"), s = this.searchUI.querySelector(".search-next"), o = this.searchUI.querySelector(".search-close");
t.addEventListener("input", () => {
this.performSearch(t.value);
}), t.addEventListener("keydown", (h) => {
const e = this.searchUI.querySelector("input"), s = this.searchUI.querySelector(".search-replace-input"), i = this.searchUI.querySelector(".search-prev"), n = this.searchUI.querySelector(".search-next"), o = this.searchUI.querySelector(".search-close");
e.addEventListener("input", () => {
this.performSearch(e.value);
}), e.addEventListener("keydown", (h) => {
h.key === "Enter" && (h.preventDefault(), h.shiftKey ? this.findPrev() : this.findNext());
}), n.addEventListener("keydown", (h) => {
h.key === "Enter" && (h.preventDefault(), h.shiftKey ? this.replaceAll(t.value, n.value) : this.replaceCurrent(t.value, n.value));
}), i.addEventListener("click", () => this.findPrev()), s.addEventListener("click", () => this.findNext()), o.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
}), s.addEventListener("keydown", (h) => {
h.key === "Enter" && (h.preventDefault(), h.shiftKey ? this.replaceAll(e.value, s.value) : this.replaceCurrent(e.value, s.value));
}), i.addEventListener("click", () => this.findPrev()), n.addEventListener("click", () => this.findNext()), o.addEventListener("click", () => this.hideSearch()), t.appendChild(this.searchUI);
}
performSearch(e) {
if (!this.editor || !e.trim()) {
performSearch(t) {
if (!this.editor || !t.trim()) {
this.clearHighlights(), this.updateStatus("");
return;
}
const t = this.editor.getValue(), n = [];
let i = t.toLowerCase().indexOf(e.toLowerCase());
const e = this.editor.getValue(), s = [];
let i = e.toLowerCase().indexOf(t.toLowerCase());
for (; i !== -1; ) {
const s = this.getPositionFromOffset(t, i), o = this.getPositionFromOffset(t, i + e.length);
n.push({
range: { start: s, end: o },
match: t.substring(i, i + e.length)
}), i = t.toLowerCase().indexOf(e.toLowerCase(), i + 1);
const n = this.getPositionFromOffset(e, i), o = this.getPositionFromOffset(e, i + t.length);
s.push({
range: { start: n, end: o },
match: e.substring(i, i + t.length)
}), i = e.toLowerCase().indexOf(t.toLowerCase(), i + 1);
}
this.currentResults = n, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
this.currentResults = s, 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(`
`), i = n.length - 1, s = n[n.length - 1].length;
return { line: i, column: s };
getPositionFromOffset(t, e) {
const s = t.substring(0, e).split(`
`), i = s.length - 1, n = s[s.length - 1].length;
return { line: i, column: n };
}

@@ -860,23 +1058,23 @@ findNext() {

}
replaceCurrent(e, t) {
if (!this.editor || !e.trim() || this.currentIndex === -1) return;
const n = this.currentResults[this.currentIndex];
if (!n) return;
const i = this.editor.getValue(), s = this.getOffsetFromPosition(i, n.range.start), o = i.substring(0, s), h = i.substring(s + e.length), r = o + t + h;
this.editor.setValue(r), this.performSearch(e), this.updateStatus("Replaced current occurrence");
replaceCurrent(t, e) {
if (!this.editor || !t.trim() || this.currentIndex === -1) return;
const s = this.currentResults[this.currentIndex];
if (!s) return;
const i = this.editor.getValue(), n = this.getOffsetFromPosition(i, s.range.start), o = i.substring(0, n), h = i.substring(n + t.length), r = o + e + h;
this.editor.setValue(r), this.performSearch(t), this.updateStatus("Replaced current occurrence");
}
replaceAll(e, t) {
if (!this.editor || !e.trim()) return;
let n = this.editor.getValue(), i = 0, s = n.toLowerCase().indexOf(e.toLowerCase());
for (; s !== -1; )
n = n.substring(0, s) + t + n.substring(s + e.length), i++, s = n.toLowerCase().indexOf(e.toLowerCase(), s + t.length);
i > 0 && (this.editor.setValue(n), this.updateStatus(`Replaced ${i} occurrences`));
replaceAll(t, e) {
if (!this.editor || !t.trim()) return;
let s = this.editor.getValue(), i = 0, n = s.toLowerCase().indexOf(t.toLowerCase());
for (; n !== -1; )
s = s.substring(0, n) + e + s.substring(n + t.length), i++, n = s.toLowerCase().indexOf(t.toLowerCase(), n + e.length);
i > 0 && (this.editor.setValue(s), this.updateStatus(`Replaced ${i} occurrences`));
}
getOffsetFromPosition(e, t) {
const n = e.split(`
getOffsetFromPosition(t, e) {
const s = t.split(`
`);
let i = 0;
for (let s = 0; s < t.line; s++)
i += n[s].length + 1;
return i += t.column, i;
for (let n = 0; n < e.line; n++)
i += s[n].length + 1;
return i += e.column, i;
}

@@ -888,5 +1086,5 @@ updateHighlights() {

}
updateStatus(e) {
const t = this.searchUI?.querySelector(".search-status");
t && (t.textContent = e);
updateStatus(t) {
const e = this.searchUI?.querySelector(".search-status");
e && (e.textContent = t);
}

@@ -897,3 +1095,3 @@ destroy() {

}
class k {
class A {
constructor() {

@@ -912,6 +1110,6 @@ this.name = "bracket-matching", this.editor = null, this.bracketPairs = {

}
setup(e) {
this.editor = e, e.on("cursor", () => {
setup(t) {
this.editor = t, t.on("cursor", () => {
this.updateBracketMatching();
}), e.on("change", () => {
}), t.on("change", () => {
this.updateBracketMatching();

@@ -922,37 +1120,37 @@ });

if (!this.editor) return;
const e = this.editor.getCursor(), t = this.editor.getValue();
const t = this.editor.getCursor(), e = this.editor.getValue();
this.clearBracketHighlighting();
const n = this.getBracketAtPosition(t, e.position);
if (!n) return;
const i = this.findMatchingBracket(t, n);
const s = this.getBracketAtPosition(e, t.position);
if (!s) return;
const i = this.findMatchingBracket(e, s);
i && (this.currentMatch = i, this.highlightBrackets(i));
}
getBracketAtPosition(e, t) {
const n = e.split(`
getBracketAtPosition(t, e) {
const s = t.split(`
`);
if (t.line >= n.length) return null;
const i = n[t.line];
if (t.column >= i.length) return null;
const s = i[t.column];
return this.bracketPairs[s] || this.reverseBracketPairs[s] ? { char: s, position: t } : null;
if (e.line >= s.length) return null;
const i = s[e.line];
if (e.column >= i.length) return null;
const n = i[e.column];
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: e } : null;
}
findMatchingBracket(e, t) {
const n = e.split(`
`), i = t.position.line, s = t.position.column, o = t.char;
return this.bracketPairs[o] ? this.findClosingBracket(e, n, i, s, o) : this.reverseBracketPairs[o] ? this.findOpeningBracket(e, n, i, s, o) : null;
findMatchingBracket(t, e) {
const s = t.split(`
`), i = e.position.line, n = e.position.column, o = e.char;
return this.bracketPairs[o] ? this.findClosingBracket(t, s, i, n, o) : this.reverseBracketPairs[o] ? this.findOpeningBracket(t, s, i, n, o) : null;
}
findClosingBracket(e, t, n, i, s) {
const o = this.bracketPairs[s];
findClosingBracket(t, e, s, i, n) {
const o = this.bracketPairs[n];
let h = 0;
for (let r = n; r < t.length; r++) {
const l = t[r], c = r === n ? i : 0;
for (let a = c; a < l.length; a++) {
const u = l[a];
if (u === s)
for (let r = s; r < e.length; r++) {
const l = e[r], c = r === s ? i : 0;
for (let d = c; d < l.length; d++) {
const f = l[d];
if (f === n)
h++;
else if (u === o && (h--, h === 0))
else if (f === o && (h--, h === 0))
return {
open: { start: { line: n, column: i }, end: { line: n, column: i + 1 } },
close: { start: { line: r, column: a }, end: { line: r, column: a + 1 } },
type: s
open: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
close: { start: { line: r, column: d }, end: { line: r, column: d + 1 } },
type: n
};

@@ -963,15 +1161,15 @@ }

}
findOpeningBracket(e, t, n, i, s) {
const o = this.reverseBracketPairs[s];
findOpeningBracket(t, e, s, i, n) {
const o = this.reverseBracketPairs[n];
let h = 0;
for (let r = n; r >= 0; r--) {
const l = t[r], c = r === n ? i : l.length - 1;
for (let a = c; a >= 0; a--) {
const u = l[a];
if (u === s)
for (let r = s; r >= 0; r--) {
const l = e[r], c = r === s ? i : l.length - 1;
for (let d = c; d >= 0; d--) {
const f = l[d];
if (f === n)
h++;
else if (u === o && (h--, h === 0))
else if (f === o && (h--, h === 0))
return {
open: { start: { line: r, column: a }, end: { line: r, column: a + 1 } },
close: { start: { line: n, column: i }, end: { line: n, column: i + 1 } },
open: { start: { line: r, column: d }, end: { line: r, column: d + 1 } },
close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
type: o

@@ -983,4 +1181,3 @@ };

}
highlightBrackets(e) {
console.log("Bracket match found:", e);
highlightBrackets(t) {
}

@@ -997,16 +1194,16 @@ clearBracketHighlighting() {

}
class C {
class U {
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", () => {
setup(t) {
this.editor = t, t.registerCommand("fold", () => {
this.foldAtCursor();
}), t.registerCommand("unfold", () => {
this.unfoldAtCursor();
}), t.registerCommand("foldAll", () => {
this.foldAll();
}), t.registerCommand("unfoldAll", () => {
this.unfoldAll();
}), t.on("change", () => {
this.updateFoldIndicators();

@@ -1017,4 +1214,4 @@ }), this.createFoldingUI(), this.updateFoldIndicators();

if (!this.editor) return;
const e = document.querySelector(".rte-source-editor-modal");
e && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
const t = document.querySelector(".rte-source-editor-modal");
t && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
position: absolute;

@@ -1027,3 +1224,3 @@ left: 40px;

z-index: 2;
`, e.appendChild(this.foldingUI));
`, t.appendChild(this.foldingUI));
}

@@ -1033,23 +1230,23 @@ updateFoldIndicators() {

this.foldingUI.innerHTML = "", this.foldIndicators = [];
const t = this.editor.getValue().split(`
const e = this.editor.getValue().split(`
`);
this.findFoldableLines(t).forEach((i) => {
this.findFoldableLines(e).forEach((i) => {
this.createFoldIndicator(i);
});
}
findFoldableLines(e) {
const t = [];
for (let n = 0; n < e.length; n++) {
const i = e[n].trim();
(i.startsWith("{") || i.startsWith("function") || i.startsWith("class") || i.startsWith("if") || i.includes("=>") || i.startsWith("for") || i.startsWith("while") || i.startsWith("try")) && t.push(n);
findFoldableLines(t) {
const e = [];
for (let s = 0; s < t.length; s++) {
const i = t[s].trim();
(i.startsWith("{") || i.startsWith("function") || i.startsWith("class") || i.startsWith("if") || i.includes("=>") || i.startsWith("for") || i.startsWith("while") || i.startsWith("try")) && e.push(s);
}
return t;
return e;
}
createFoldIndicator(e) {
createFoldIndicator(t) {
if (!this.foldingUI) return;
const t = document.createElement("div");
t.style.cssText = `
const e = document.createElement("div");
e.style.cssText = `
position: absolute;
left: 0;
top: ${e * 21}px;
top: ${t * 21}px;
width: 20px;

@@ -1065,17 +1262,12 @@ height: 21px;

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);
`, e.innerHTML = "▶", e.title = "Code folding not yet implemented - click shows fold indicators", e.addEventListener("click", () => {
}), this.foldingUI.appendChild(e), this.foldIndicators.push(e);
}
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");
}

@@ -1086,13 +1278,19 @@ destroy() {

}
class L {
class F {
constructor() {
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark";
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
}
setup(e) {
this.editor = e, console.log("SyntaxHighlightingExtension: Isolated extension loaded - ready for use");
setup(t) {
this.editor = t, this.registerMode("html", { name: "html", highlight: (e, s) => this._highlightHTML(e, s) }), this.registerMode("javascript", { name: "javascript", highlight: (e, s) => this._highlightJS(e, s) }), this.registerMode("typescript", { name: "typescript", highlight: (e, s) => this._highlightJS(e, s) }), this.registerMode("php", { name: "php", highlight: (e, s) => this._highlightPHP(e, s) });
}
// Extension provides methods that can be called by the editor
setTheme(e) {
this.currentTheme = e, console.log(`SyntaxHighlightingExtension: Theme changed to ${e}`);
setTheme(t) {
this.currentTheme = t;
}
setLanguage(t) {
this.currentLanguage = t;
}
registerMode(t, e) {
this.modes.set(t.toLowerCase(), e);
}
// Method to get syntax highlighting colors for a given theme

@@ -1105,6 +1303,22 @@ getSyntaxColors() {

// Green
attrName: "#9cdcfe",
// Light blue for attribute names
attrValue: "#ce9178",
// Orange
text: "#d4d4d4"
// Light gray
// Orange for attribute values
styleProp: "#c586c0",
// Purple for CSS property names
styleVal: "#dcdcaa",
// Yellow-ish for CSS values
doctype: "#808080",
// Gray for doctype
text: "#d4d4d4",
// Light gray for normal text
keyword: "#c586c0",
// JS/PHP keywords (purple)
string: "#ce9178",
// JS strings
number: "#b5cea8",
// numbers
variable: "#9cdcfe"
// php variable color
} : {

@@ -1115,49 +1329,177 @@ tag: "#0000ff",

// Green
attrName: "#001080",
attrValue: "#a31515",
// Red
text: "#000000"
styleProp: "#6a00a8",
styleVal: "#804000",
doctype: "#444444",
text: "#000000",
// Black
keyword: "#000080",
string: "#a31515",
number: "#0086b3",
variable: "#001080"
};
}
// 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;
// Public API: highlight a source string using the chosen mode (or detect html)
highlight(t, e) {
const s = this.getSyntaxColors(), i = (e || this.currentLanguage || "html").toLowerCase();
return (this.modes.get(i) || this.modes.get("html")).highlight(t, s);
}
// Backwards-compatible method
highlightHTML(t) {
return this.highlight(t, "html");
}
// --- Internal mode implementations ---
escapeHTML(t) {
return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;");
}
// Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
unescapeEntitiesRepeated(t) {
let e = t || "";
for (let s = 0; s < 5; s++) {
const i = e;
if (e = e.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), e === i) break;
}
return e;
}
_highlightHTML(t, e) {
const s = e, i = (l) => this.escapeHTML(l);
let n = i(t);
const o = (l) => {
let c = l.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
return c = c.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), c = c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (d, f, g, a, u) => {
const p = String(a).trim(), m = i(p);
return `<span style="color: ${s.styleProp};">${f}</span>${g}<span style="color: ${s.styleVal};">${m}</span>${u}`;
}), c;
}, h = [];
try {
t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (l, c, d) => (h.push({ attrs: String(c || ""), inner: String(d || "") }), l));
} catch {
}
let r = 0;
return n = n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (l, c, d, f, g) => {
const a = h[r++]?.inner ?? this.unescapeEntitiesRepeated(f || "");
(h[r - 1]?.attrs || d || "").toLowerCase();
const u = this._highlightJS(a, s);
return `${c}${u}${g}`;
}), n = n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (l, c, d, f) => {
const g = o(d);
return `${c}${g}${f}`;
}), n = n.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${s.comment};">$1</span>`), n = n.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${s.doctype};">$1</span>`), n = n.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (l, c, d, f, g) => {
const a = `<span style="color: ${s.tag};">${d}</span>`;
let u = f;
return u = u.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g, (p, m, M, y) => {
const C = String(m).toLowerCase(), w = `<span style="color: ${s.attrName};">${m}</span>`;
let v = y, T = "";
y.startsWith("&quot;") && y.endsWith("&quot;") ? (v = y.slice(6, -6), T = "&quot;") : y.startsWith("&#39;") && y.endsWith("&#39;") && (v = y.slice(5, -5), T = "&#39;");
let b = y;
if (C === "style") {
const L = v.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (I, S, O, E) => `<span style="color: ${s.styleProp};">${S}</span>:<span style="color: ${s.styleVal};">${O.trim()}</span>${E}`);
T ? b = `${T}${L}${T}` : b = L, b = `<span style="color: ${s.attrValue};">${b}</span>`;
} else
T && (b = `${T}${v}${T}`), b = `<span style="color: ${s.attrValue};">${b}</span>`;
return `${w}${M}${b}`;
}), `${c}${a}${u}${g}`;
}), n;
}
_highlightJS(t, e) {
const s = this.unescapeEntitiesRepeated(t);
this.escapeHTML(s);
const i = [], n = (g) => {
let a = "", u = g;
do
a = String.fromCharCode(97 + u % 26) + a, u = Math.floor(u / 26) - 1;
while (u >= 0);
return a || "a";
}, o = (g) => `\0${n(g)}\0`, h = (g) => {
const a = i.length;
return i.push(g), o(a);
};
let r;
const l = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
let c = 0, d = "";
for (; r = l.exec(s); ) {
const g = r.index;
c < g && (d += this.escapeHTML(s.slice(c, g)));
const a = r[0];
/^\/\*/.test(a) || /^\/\//.test(a) ? d += h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`) : d += h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`), c = l.lastIndex;
}
return c < s.length && (d += this.escapeHTML(s.slice(c))), d = d.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (g, a, u) => {
const p = d[u - 1] || "", m = d[u + g.length] || "";
return p === "&" || p === "#" || m === ";" || m === "#" ? g : `<span style="color: ${e.number};">${g}</span>`;
}), d = d.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${e.keyword};">$1</span>`), d.replace(/\u0000([a-z]+)\u0000/g, (g, a) => {
let u = 0;
for (let p = 0; p < a.length; p++)
u = u * 26 + (a.charCodeAt(p) - 97 + 1);
return u = u - 1, i[u] || "";
});
}
_highlightPHP(t, e) {
const s = this.unescapeEntitiesRepeated(t);
let i = this.escapeHTML(s);
const n = [], o = (a) => {
let u = "", p = a;
do
u = String.fromCharCode(97 + p % 26) + u, p = Math.floor(p / 26) - 1;
while (p >= 0);
return u || "a";
}, h = (a) => {
const u = n.length;
return n.push(a), `\0${o(u)}\0`;
}, r = (a, u) => {
const p = i.indexOf(a);
return p === -1 ? !1 : (i = i.slice(0, p) + u + i.slice(p + a.length), !0);
};
let l;
const c = /\/\*[\s\S]*?\*\//g, d = /\/\/[^\n\r]*/g, f = /\#([^\n\r]*)/g, g = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
for (; l = c.exec(s); ) {
const a = l[0];
r(this.escapeHTML(a), h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`));
}
for (; l = d.exec(s); ) {
const a = l[0];
r(this.escapeHTML(a), h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`));
}
for (; l = f.exec(s); ) {
const a = l[0];
r(this.escapeHTML(a), h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`));
}
for (; l = g.exec(s); ) {
const a = l[0];
r(this.escapeHTML(a), h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`));
}
return i = i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${e.variable};">$1</span>`), i = i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${e.keyword};">$1</span>`), i = i.replace(/\u0000([a-z]+)\u0000/g, (a, u) => {
let p = 0;
for (let m = 0; m < u.length; m++)
p = p * 26 + (u.charCodeAt(m) - 97 + 1);
return p = p - 1, n[p] || "";
}), i;
}
// Method to check if content contains syntax that should be highlighted
shouldHighlight(e) {
return /<\/?[\w:-]+|<!--/.test(e);
shouldHighlight(t) {
return /<\/?[\w:-]+|<!--/.test(t);
}
destroy() {
this.editor = null, console.log("SyntaxHighlightingExtension: Extension destroyed");
this.editor = null, this.modes.clear();
}
}
function T(d, e) {
const t = { ...e };
return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new y(t.keymap)), new x(d, t);
function _(x, t) {
const e = { ...t };
return e.extensions || (e.extensions = []), e.extensions.some((n) => n.name === "keymap") || e.extensions.unshift(new H(e.keymap)), e.extensions.some((n) => n.name === "transaction") || e.extensions.unshift(new R()), new $(x, e);
}
export {
k as BracketMatchingExtension,
C as CodeFoldingExtension,
x as EditorCore,
y as KeymapExtension,
b as LineNumbersExtension,
E as ReadOnlyExtension,
w as SearchExtension,
L as SyntaxHighlightingExtension,
m as TextModel,
v as ThemeExtension,
p as View,
T as createEditor,
x as default
A as BracketMatchingExtension,
U as CodeFoldingExtension,
$ as EditorCore,
H as KeymapExtension,
N as LineNumbersExtension,
B as ReadOnlyExtension,
V as SearchExtension,
F as SyntaxHighlightingExtension,
k as TextModel,
K as ThemeExtension,
P as View,
_ as createEditor,
$ as default
};

@@ -1,6 +0,6 @@

(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.LightCodeEditor={}))})(this,(function(c){"use strict";class f{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
`)}setText(e){this._lines=e.split(`
`),this._version++}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(`
`)}replaceRange(e,t){const n=this.getTextInRange(e);if(e.start.line===e.end.line){const i=this.getLine(e.start.line),s=i.substring(0,e.start.column)+t+i.substring(e.end.column);this._lines[e.start.line]=s}else{const i=this.getLine(e.start.line),s=this.getLine(e.end.line),o=i.substring(0,e.start.column)+t,h=s.substring(e.end.column),r=t.split(`
`);r[0]=o+r[0],r[r.length-1]=r[r.length-1]+h,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...r)}return this._version++,{range:e,text:t,oldText:n}}insertText(e,t){const n={start:e,end:e};return this.replaceRange(n,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let n=0;n<e.line;n++)t+=this.getLine(n).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let n=0;n<this.getLineCount();n++){const i=this.getLine(n).length;if(t<=i)return{line:n,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new f;return e._lines=[...this._lines],e._version=this._version,e}}class y{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=`
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.LightCodeEditor={}))})(this,(function(m){"use strict";class b{constructor(t=""){this._lines=[],this._version=0,this.setText(t)}getLine(t){return this._lines[t]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
`)}setText(t){this._lines=t.split(`
`),this._version++}getTextInRange(t){if(t.start.line===t.end.line)return this.getLine(t.start.line).substring(t.start.column,t.end.column);const e=[];e.push(this.getLine(t.start.line).substring(t.start.column));for(let s=t.start.line+1;s<t.end.line;s++)e.push(this.getLine(s));return t.end.line<this.getLineCount()&&e.push(this.getLine(t.end.line).substring(0,t.end.column)),e.join(`
`)}replaceRange(t,e){const s=this.getTextInRange(t);if(t.start.line===t.end.line){const i=this.getLine(t.start.line),n=i.substring(0,t.start.column)+e+i.substring(t.end.column);this._lines[t.start.line]=n}else{const i=this.getLine(t.start.line),n=this.getLine(t.end.line),o=i.substring(0,t.start.column)+e,h=n.substring(t.end.column),r=e.split(`
`);r[0]=o+r[0],r[r.length-1]=r[r.length-1]+h,this._lines.splice(t.start.line,t.end.line-t.start.line+1,...r)}return this._version++,{range:t,text:e,oldText:s}}insertText(t,e){const s={start:t,end:t};return this.replaceRange(s,e)}deleteRange(t){return this.replaceRange(t,"")}positionToOffset(t){let e=0;for(let s=0;s<t.line;s++)e+=this.getLine(s).length+1;return e+=t.column,e}offsetToPosition(t){let e=t;for(let s=0;s<this.getLineCount();s++){const i=this.getLine(s).length;if(e<=i)return{line:s,column:e};e-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(t){return!(t.line<0||t.line>=this.getLineCount()||t.column<0||t.column>this.getLine(t.line).length)}isValidRange(t){return this.isValidPosition(t.start)&&this.isValidPosition(t.end)}getVersion(){return this._version}clone(){const t=new b;return t._lines=[...this._lines],t._version=this._version,t}}class O{constructor(t){this.gutterWidth=50,this.lineHeight=21,this.container=t,this.createDOM()}createDOM(){this.container.innerHTML="";const t=document.createElement("div");this.editorContainer=t,t.style.cssText=`
position: relative;

@@ -15,19 +15,19 @@ display: flex;

line-height: ${this.lineHeight}px;
overflow: hidden;
`,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.style.cssText=`
position: sticky;
left: 0;
top: 0;
/* make the outer container the single scrollable element so gutter and content scroll together */
overflow: auto;
`,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.setAttribute("data-editor-gutter","true"),this.lineNumbersElement.style.cssText=`
display: table-cell;
vertical-align: top;
width: ${this.gutterWidth}px;
background: var(--editor-gutter-background, #252526);
color: var(--editor-gutter-foreground, #858585);
padding: 0;
padding: 0 8px 0 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;
display: table-cell;
vertical-align: top;
padding: 0 12px;
background: transparent;

@@ -38,3 +38,3 @@ border: none;

overflow-x: auto;
overflow-y: auto;
overflow-y: visible;
min-height: 400px;

@@ -47,29 +47,14 @@ font-family: inherit;

-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)}updateLineNumbers(e){const t=Math.max(e,20),n=Array.from({length:t},(i,s)=>s+1);this.lineNumbersElement.innerHTML=n.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(e){this.contentElement.textContent=e;const t=e.split(`
`).length;this.updateLineNumbers(t)}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 s=n.toString().split(`
`);return{line:s.length-1,column:s[s.length-1].length}}setCursorPosition(e){const n=this.getText().split(`
`),i=Math.min(e.line,n.length-1),s=Math.min(e.column,n[i]?.length||0);let o=0;for(let m=0;m<i;m++)o+=n[m].length+1;o+=s;const h=document.createRange(),r=window.getSelection();let l=0,d=null,a=0;const g=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let x;for(;x=g.nextNode();){const m=x.textContent?.length||0;if(l+m>=o){d=x,a=o-l;break}l+=m}if(d)try{h.setStart(d,a),h.setEnd(d,a),r?.removeAllRanges(),r?.addRange(h)}catch(m){console.warn("Could not set cursor position:",m)}}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 s=n.toString().split(`
`),o=t.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(t.endContainer,t.endOffset);const r=o.toString().split(`
`);return{start:{line:s.length-1,column:s[s.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,n])=>{this.container.style.setProperty(`--${t}`,n)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.contentElement.scrollTop}setScrollTop(e){this.contentElement.scrollTop=e,this.lineNumbersElement.scrollTop=e}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}class p{constructor(e,t={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=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 f(this.config.value),this.view=new y(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)}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}getKeymapExtension(){return this.extensions.get("keymap")}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")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const n=this.eventListeners.get(e);n&&n.forEach(i=>i(...t))}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}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}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)}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)}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`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const n={caseSensitive:!1,regex:!1,...t},i=[],s=this.getValue();s.split(`
`);let o=n.caseSensitive?s:s.toLowerCase(),h=n.caseSensitive?e:e.toLowerCase();if(n.regex){const r=new RegExp(h,n.caseSensitive?"g":"gi");let l;for(;(l=r.exec(o))!==null;){const d=this.textModel.offsetToPosition(l.index),a=this.textModel.offsetToPosition(l.index+l[0].length);i.push({range:{start:d,end:a},match:l[0]})}}else{let r=0,l=o.indexOf(h,r);for(;l!==-1;){const d=l+e.length,a=this.textModel.offsetToPosition(l),g=this.textModel.offsetToPosition(d);i.push({range:{start:a,end:g},match:s.substring(l,d)}),r=d,l=o.indexOf(h,r)}}return i}replace(e,t){const n=this.textModel.replaceRange(e,t);this.view.setText(this.getValue()),this.emit("change",[n])}replaceAll(e,t,n={}){const i=this.search(e,n);let s=0;for(let o=i.length-1;o>=0;o--)this.replace(i[o].range,t),s++;return s}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]}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()}}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 i=n.indexOf(t);i!==-1&&n.splice(i,1)}else n.length=0}}class b{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:i,shiftKey:s,metaKey:o}=e,h=t.toLowerCase(),r=this.keymap[h];if(!r)return null;for(const l of r)if((l.ctrlKey===n||!l.ctrlKey&&!n)&&(l.altKey===i||!l.altKey&&!i)&&(l.shiftKey===s||!l.shiftKey&&!s)&&(l.metaKey===o||!l.metaKey&&!o))return l;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,i){const s=t.toLowerCase();e[s]||(e[s]=[]),e[s].push({key:s,command:i,...n})}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(i=>i.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 i of this.keymap[n])i.command===e&&t.push({...i});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class v{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=`
`,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1;const e=document.createElement("div");e.setAttribute("data-editora-editor","true"),e.style.cssText="display: table; table-layout: fixed; width: 100%; height: 100%;",e.appendChild(this.lineNumbersElement),e.appendChild(this.contentElement),t.appendChild(e),this.container.appendChild(t),this.updateLineNumbers(1)}updateLineNumbers(t){const e=Math.max(t,20),s=Array.from({length:e},(i,n)=>n+1);this.lineNumbersElement.innerHTML=s.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(t){this.contentElement.textContent=t;const e=t.split(`
`).length;this.updateLineNumbers(e)}setHTML(t){const e=/&lt;|&gt;/.test(t),s=/<span\b/i.test(t),i=/<[^>]+>/.test(t);e&&s?this.contentElement.innerHTML=t:i&&!e?this.contentElement.textContent=t:this.contentElement.innerHTML=t;const o=(this.contentElement.textContent||"").split(`
`).length;this.updateLineNumbers(o)}getCursorPosition(){const t=window.getSelection();if(!t||t.rangeCount===0)return{line:0,column:0};const e=t.getRangeAt(0),s=e.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(e.endContainer,e.endOffset);const n=s.toString().split(`
`);return{line:n.length-1,column:n[n.length-1].length}}setCursorPosition(t){const s=this.getText().split(`
`),i=Math.min(t.line,s.length-1),n=Math.min(t.column,s[i]?.length||0);let o=0;for(let a=0;a<i;a++)o+=s[a].length+1;o+=n;const h=document.createRange(),r=window.getSelection();let l=0,c=null,d=0;const f=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let g;for(;g=f.nextNode();){const a=g.textContent?.length||0;if(l+a>=o){c=g,d=o-l;break}l+=a}if(c)try{h.setStart(c,d),h.setEnd(c,d),r?.removeAllRanges(),r?.addRange(h)}catch(a){console.warn("Could not set cursor position:",a)}}getSelectionRange(){const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return;const e=t.getRangeAt(0),s=e.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(e.startContainer,e.startOffset);const n=s.toString().split(`
`),o=e.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(e.endContainer,e.endOffset);const r=o.toString().split(`
`);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(t){this.setCursorPosition(t.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(t){this.contentElement.contentEditable=t?"false":"true"}applyTheme(t){Object.entries(t).forEach(([e,s])=>{this.container.style.setProperty(`--${e}`,s)})}scrollToPosition(t){const e=this.lineNumbersElement.children[t.line];e&&e.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}setScrollTop(t){this.editorContainer.scrollTop=t}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}class k{constructor(t,e={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.undoStack=[],this.redoStack=[],this.suppressHistory=!1,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...e},this.textModel=new b(this.config.value),this.view=new O(t),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(s=>this.addExtension(s)),this.setTheme(this.config.theme),this.view.setReadOnly(this.config.readOnly||!1),this.renderTextWithHighlight(this.textModel.getText()),this.registerBuiltInCommands()}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}registerBuiltInCommands(){this.registerCommand("undo",()=>this.undo()),this.registerCommand("redo",()=>this.redo()),this.registerCommand("insertTab",()=>this.insertTab()),this.registerCommand("save",()=>{this.emit("save")})}getKeymapExtension(){return this.extensions.get("keymap")}setupEventHandlers(){const t=this.view.getContentElement();t.addEventListener("input",()=>{const e=this.view.getText(),s=this.textModel.getText();if(e!==s){if(!this.suppressHistory){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:h,focusOffset:r}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(e),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:s}])}}),t.addEventListener("selectionchange",()=>{const e=this.getCursor(),s=this.getSelection();this.emit("cursor",e),s&&this.emit("selection",s)}),t.addEventListener("keydown",e=>{if(this.emit("keydown",e),e.key==="Tab"){this.config.readOnly||this.insertTab(),e.preventDefault(),e.stopPropagation();return}if(e.key==="Enter"){if(!this.config.readOnly){const s=window.getSelection();if(s&&s.rangeCount>0){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:h,focusOffset:r}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const l=s.getRangeAt(0);l.deleteContents();const c=document.createTextNode(`
`);l.insertNode(c),l.setStartAfter(c),l.collapse(!0),s.removeAllRanges(),s.addRange(l);const d=this.getCursor().position,f=this.textModel.positionToOffset(d),g=this.getSelection();let a,u;g&&(a=this.textModel.positionToOffset(g.start),u=this.textModel.positionToOffset(g.end));const p=this.view.getText();this.textModel.setText(p),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{if(g&&(a!==void 0||u!==void 0)){const x=a!==void 0?a:f,w=u!==void 0?u:f,T=Math.min(x,w),L=Math.max(x,w),S=this.textModel.offsetToPosition(T),C=this.textModel.offsetToPosition(L);this.setSelection({start:S,end:C})}else{const x=this.textModel.offsetToPosition(f);this.setCursor(x)}}catch{}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}e.preventDefault(),e.stopPropagation();return}for(const s of this.extensions.values())if(s.onKeyDown&&s.onKeyDown(e)===!1){e.preventDefault(),e.stopPropagation();return}}),t.addEventListener("mousedown",e=>{this.emit("mousedown",e);for(const s of this.extensions.values())if(s.onMouseDown&&s.onMouseDown(e)===!1){e.preventDefault(),e.stopPropagation();return}}),t.addEventListener("focus",()=>{this.emit("focus")}),t.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const t=this.textModel.getLineCount();this.view.updateLineNumbers(t)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(t,...e){const s=this.eventListeners.get(t);s&&s.forEach(i=>i(...e))}getValue(){return this.textModel.getText()}setValue(t){const e=this.textModel.getText();this.textModel.setText(t),this.renderTextWithHighlight(t,!1),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:e}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const t=this.view.getCursorPosition();return{position:t,anchor:t}}setCursor(t){this.view.setCursorPosition(t),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(t){this.view.setSelectionRange(t),this.emit("selection",t)}setTheme(t){this.currentTheme=t;const e={"editor-background":t==="dark"?"#1e1e1e":"#ffffff","editor-foreground":t==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":t==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":t==="dark"?"#858585":"#666666","editor-gutter-border":t==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(e);const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.setTheme=="function")try{s.setTheme(t==="dark"?"dark":"light"),this.renderTextWithHighlight(this.textModel.getText())}catch(i){console.warn("Error applying theme to syntax-highlighting extension",i)}}setReadOnly(t){this.config.readOnly=t,this.view.setReadOnly(t)}addExtension(t){if(this.extensions.has(t.name))throw new Error(`Extension '${t.name}' already exists`);this.extensions.set(t.name,t),t.setup(this),t.name==="syntax-highlighting"&&typeof t.highlightHTML=="function"&&this.renderTextWithHighlight(this.textModel.getText())}removeExtension(t){const e=this.extensions.get(t);e&&e.destroy&&e.destroy(),this.extensions.delete(t)}executeCommand(t,...e){const s=this.commands.get(t);s?s(this,...e):console.warn(`Command '${t}' not found`)}registerCommand(t,e){this.commands.set(t,e)}search(t,e={}){const s={caseSensitive:!1,regex:!1,...e},i=[],n=this.getValue();n.split(`
`);let o=s.caseSensitive?n:n.toLowerCase(),h=s.caseSensitive?t:t.toLowerCase();if(s.regex){const r=new RegExp(h,s.caseSensitive?"g":"gi");let l;for(;(l=r.exec(o))!==null;){const c=this.textModel.offsetToPosition(l.index),d=this.textModel.offsetToPosition(l.index+l[0].length);i.push({range:{start:c,end:d},match:l[0]})}}else{let r=0,l=o.indexOf(h,r);for(;l!==-1;){const c=l+t.length,d=this.textModel.offsetToPosition(l),f=this.textModel.offsetToPosition(c);i.push({range:{start:d,end:f},match:n.substring(l,c)}),r=c,l=o.indexOf(h,r)}}return i}replace(t,e){const s=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,o=this.textModel.positionToOffset(n),h=this.getSelection();let r,l;h&&(r=this.textModel.positionToOffset(h.start),l=this.textModel.positionToOffset(h.end)),this.undoStack.push({text:s,cursorOffset:o,anchorOffset:r,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(t,e);this.renderTextWithHighlight(this.getValue(),!1),this.emit("change",[i])}replaceAll(t,e,s={}){const i=this.search(t,s);let n=0;for(let o=i.length-1;o>=0;o--)this.replace(i[o].range,e),n++;return n}fold(t){const e={start:t.start,end:t.end,collapsed:!0,level:0};this.folds.push(e)}unfold(t){this.folds=this.folds.filter(e=>!(e.start.line===t.start.line&&e.end.line===t.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}renderTextWithHighlight(t,e=!0){const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.highlightHTML=="function")try{const i=!e&&!this.expectingProgrammaticCursor;let n,o,h,r;if(e||i){n=this.getSelection();const c=this.getCursor().position;o=this.textModel.positionToOffset(c),n&&(h=this.textModel.positionToOffset(n.start),r=this.textModel.positionToOffset(n.end))}const l=s.highlightHTML(t);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(l):this.view.setHTML(l),(e||i)&&requestAnimationFrame(()=>{try{if(n&&(h!==void 0||r!==void 0)){const c=h!==void 0?h:o,d=r!==void 0?r:o,f=Math.min(c,d),g=Math.max(c,d),a=this.textModel.offsetToPosition(f),u=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:a,end:u})}else if(o!==void 0){const c=this.textModel.offsetToPosition(o);this.view.setCursorPosition(c)}}catch{}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(t)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const t of this.extensions.values())t.destroy&&t.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}undo(){if(this.undoStack.length===0)return;const t=this.undoStack.pop(),e={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.redoStack.push(e);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof t=="string"?s=t:(s=t.text,i=t.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof t!="string"&&(t.anchorOffset!==void 0||t.focusOffset!==void 0)){const n=t.anchorOffset!==void 0?t.anchorOffset:i,o=t.focusOffset!==void 0?t.focusOffset:i,h=Math.min(n,o),r=Math.max(n,o),l=this.textModel.offsetToPosition(h),c=this.textModel.offsetToPosition(r);this.setSelection({start:l,end:c})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const t=this.redoStack.pop(),e={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.undoStack.push(e);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof t=="string"?s=t:(s=t.text,i=t.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof t!="string"&&(t.anchorOffset!==void 0||t.focusOffset!==void 0)){const n=t.anchorOffset!==void 0?t.anchorOffset:i,o=t.focusOffset!==void 0?t.focusOffset:i,h=Math.min(n,o),r=Math.max(n,o),l=this.textModel.offsetToPosition(h),c=this.textModel.offsetToPosition(r);this.setSelection({start:l,end:c})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const t=this.getCursor().position,e=this.textModel.positionToOffset(t),s=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(t,s),n=this.textModel.offsetToPosition(this.textModel.positionToOffset(t)+s.length);if(!this.suppressHistory){const o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:h,focusOffset:r}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(n),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}insertNewLine(){if(this.config.readOnly)return;const t=this.getCursor().position,e=this.textModel.positionToOffset(t),s=this.textModel.insertText(t,`
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(t)+1);if(!this.suppressHistory){const n=this.getSelection();let o,h;n&&(o=this.textModel.positionToOffset(n.start),h=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:o,focusOffset:h}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(i),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[s])}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){if(!this.eventListeners.has(t))return;const s=this.eventListeners.get(t);if(e){const i=s.indexOf(e);i!==-1&&s.splice(i,1)}else s.length=0}}class E{constructor(t){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=t||this.getDefaultKeymap()}setup(t){this.editor=t}handleKeyDown(t){if(!this.editor)return;const e=this.findMatchingBinding(t);if(e)return this.editor.executeCommand(e.command),t.preventDefault(),t.stopPropagation(),!1}findMatchingBinding(t){const{key:e,ctrlKey:s,altKey:i,shiftKey:n,metaKey:o}=t,h=String(e).toLowerCase(),r=this.keymap[h];if(!r)return null;for(const l of r){const c=l.ctrlKey===void 0||l.ctrlKey===s,d=l.altKey===void 0||l.altKey===i,f=l.shiftKey===void 0||l.shiftKey===n,g=l.metaKey===void 0||l.metaKey===o;if(c&&d&&f&&g)return l}return null}onKeyDown(t){return this.handleKeyDown(t)}getDefaultKeymap(){const t={};return this.addBinding(t,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(t,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(t,"f3",{},"findNext"),this.addBinding(t,"f3",{shiftKey:!0},"findPrev"),this.addBinding(t,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(t,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(t,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(t,"s",{ctrlKey:!0},"save"),this.addBinding(t,"s",{metaKey:!0},"save"),this.addBinding(t,"z",{ctrlKey:!0},"undo"),this.addBinding(t,"z",{metaKey:!0},"undo"),this.addBinding(t,"y",{ctrlKey:!0},"redo"),this.addBinding(t,"y",{metaKey:!0},"redo"),this.addBinding(t,"z",{ctrlKey:!0,shiftKey:!0},"redo"),this.addBinding(t,"z",{metaKey:!0,shiftKey:!0},"redo"),this.addBinding(t,"tab",{},"insertTab"),this.addBinding(t,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),t}addBinding(t,e,s,i){const n=e.toLowerCase();t[n]||(t[n]=[]),t[n].push({key:n,command:i,...s})}setKeymap(t){this.keymap={...t}}addKeyBinding(t){const e=t.key.toLowerCase();this.keymap[e]||(this.keymap[e]=[]),this.keymap[e]=this.keymap[e].filter(s=>s.command!==t.command),this.keymap[e].push({...t,key:e})}removeKeyBinding(t,e){const s=t.toLowerCase();e?this.keymap[s]&&(this.keymap[s]=this.keymap[s].filter(i=>i.command!==e),this.keymap[s].length===0&&delete this.keymap[s]):delete this.keymap[s]}getKeymap(){return{...this.keymap}}getBindingsForCommand(t){const e=[];for(const s in this.keymap)for(const i of this.keymap[s])i.command===t&&e.push({...i});return e}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class ${constructor(){this.name="transaction",this.transactions=[]}setup(t){t.on("change",e=>{const s={changes:[e],selection:t.getSelection(),effects:[],annotations:[]};this.transactions.push(s)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class H{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(t){this.editor=t,this.createLineNumbers(),t.registerCommand("toggleLineNumbers",()=>{this.toggle()}),t.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.lineNumbersElement=e)}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const t=this.editor.getValue().split(`
`).length,e=Array.from({length:Math.max(t,20)},(s,i)=>i+1);this.lineNumbersElement.innerHTML=e.map(s=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const t=this.editor.getView().getContentElement();t&&(t.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class R{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(t){this.editor=t,t.registerCommand("setTheme",e=>{this.setTheme(e)}),t.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(t){this.editor&&(this.currentTheme=t,this.editor.setTheme(t))}toggleTheme(){const t=this.currentTheme==="dark"?"light":"dark";this.setTheme(t)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class I{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(t){this.editor=t,t.registerCommand("setReadOnly",e=>{this.setReadOnly(e)}),t.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),t.on("keydown",e=>{if(e.ctrlKey&&e.key==="r")return e.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(t){this.editor&&(this.isReadOnly=t,this.editor.setReadOnly(t))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class N{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(t){this.editor=t,t.registerCommand("find",()=>{this.showSearch()}),t.registerCommand("findNext",()=>{this.findNext()}),t.registerCommand("findPrev",()=>{this.findPrev()}),t.registerCommand("replace",()=>{this.showReplace()}),t.registerCommand("replaceAll",(e,s)=>{this.replaceAll(e,s)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const t=this.searchUI.querySelector("input");t&&(t.focus(),t.select())}}showReplace(){this.showSearch();const t=this.searchUI?.querySelector(".search-replace-input");t&&(t.style.display="block",t.focus());const e=this.searchUI?.querySelector(".search-status");e&&(e.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 t=document.querySelector(".rte-source-editor-modal");if(!t)return;this.searchUI=document.createElement("div"),this.searchUI.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 n=e.getContentElement();n&&n.parentNode&&(n.parentNode.insertBefore(this.lineNumbersElement,n),n.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,i)=>i+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 E{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 w{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 k{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(){this.showSearch();const e=this.searchUI?.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=this.searchUI?.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;

@@ -142,7 +127,7 @@ right: 10px;

" />
`;const t=this.searchUI.querySelector("input"),n=this.searchUI.querySelector(".search-replace-input"),i=this.searchUI.querySelector(".search-prev"),s=this.searchUI.querySelector(".search-next"),o=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.findPrev():this.findNext())}),n.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.replaceAll(t.value,n.value):this.replaceCurrent(t.value,n.value))}),i.addEventListener("click",()=>this.findPrev()),s.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 i=t.toLowerCase().indexOf(e.toLowerCase());for(;i!==-1;){const s=this.getPositionFromOffset(t,i),o=this.getPositionFromOffset(t,i+e.length);n.push({range:{start:s,end:o},match:t.substring(i,i+e.length)}),i=t.toLowerCase().indexOf(e.toLowerCase(),i+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(`
`),i=n.length-1,s=n[n.length-1].length;return{line:i,column:s}}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 i=this.editor.getValue(),s=this.getOffsetFromPosition(i,n.range.start),o=i.substring(0,s),h=i.substring(s+e.length),r=o+t+h;this.editor.setValue(r),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let n=this.editor.getValue(),i=0,s=n.toLowerCase().indexOf(e.toLowerCase());for(;s!==-1;)n=n.substring(0,s)+t+n.substring(s+e.length),i++,s=n.toLowerCase().indexOf(e.toLowerCase(),s+t.length);i>0&&(this.editor.setValue(n),this.updateStatus(`Replaced ${i} occurrences`))}getOffsetFromPosition(e,t){const n=e.split(`
`);let i=0;for(let s=0;s<t.line;s++)i+=n[s].length+1;return i+=t.column,i}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){const t=this.searchUI?.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 C{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 i=this.findMatchingBracket(t,n);i&&(this.currentMatch=i,this.highlightBrackets(i))}getBracketAtPosition(e,t){const n=e.split(`
`);if(t.line>=n.length)return null;const i=n[t.line];if(t.column>=i.length)return null;const s=i[t.column];return this.bracketPairs[s]||this.reverseBracketPairs[s]?{char:s,position:t}:null}findMatchingBracket(e,t){const n=e.split(`
`),i=t.position.line,s=t.position.column,o=t.char;return this.bracketPairs[o]?this.findClosingBracket(e,n,i,s,o):this.reverseBracketPairs[o]?this.findOpeningBracket(e,n,i,s,o):null}findClosingBracket(e,t,n,i,s){const o=this.bracketPairs[s];let h=0;for(let r=n;r<t.length;r++){const l=t[r],d=r===n?i:0;for(let a=d;a<l.length;a++){const g=l[a];if(g===s)h++;else if(g===o&&(h--,h===0))return{open:{start:{line:n,column:i},end:{line:n,column:i+1}},close:{start:{line:r,column:a},end:{line:r,column:a+1}},type:s}}}return null}findOpeningBracket(e,t,n,i,s){const o=this.reverseBracketPairs[s];let h=0;for(let r=n;r>=0;r--){const l=t[r],d=r===n?i:l.length-1;for(let a=d;a>=0;a--){const g=l[a];if(g===s)h++;else if(g===o&&(h--,h===0))return{open:{start:{line:r,column:a},end:{line:r,column:a+1}},close:{start:{line:n,column:i},end:{line:n,column:i+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 L{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=`
`;const e=this.searchUI.querySelector("input"),s=this.searchUI.querySelector(".search-replace-input"),i=this.searchUI.querySelector(".search-prev"),n=this.searchUI.querySelector(".search-next"),o=this.searchUI.querySelector(".search-close");e.addEventListener("input",()=>{this.performSearch(e.value)}),e.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.findPrev():this.findNext())}),s.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.replaceAll(e.value,s.value):this.replaceCurrent(e.value,s.value))}),i.addEventListener("click",()=>this.findPrev()),n.addEventListener("click",()=>this.findNext()),o.addEventListener("click",()=>this.hideSearch()),t.appendChild(this.searchUI)}performSearch(t){if(!this.editor||!t.trim()){this.clearHighlights(),this.updateStatus("");return}const e=this.editor.getValue(),s=[];let i=e.toLowerCase().indexOf(t.toLowerCase());for(;i!==-1;){const n=this.getPositionFromOffset(e,i),o=this.getPositionFromOffset(e,i+t.length);s.push({range:{start:n,end:o},match:e.substring(i,i+t.length)}),i=e.toLowerCase().indexOf(t.toLowerCase(),i+1)}this.currentResults=s,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(t,e){const s=t.substring(0,e).split(`
`),i=s.length-1,n=s[s.length-1].length;return{line:i,column:n}}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(t,e){if(!this.editor||!t.trim()||this.currentIndex===-1)return;const s=this.currentResults[this.currentIndex];if(!s)return;const i=this.editor.getValue(),n=this.getOffsetFromPosition(i,s.range.start),o=i.substring(0,n),h=i.substring(n+t.length),r=o+e+h;this.editor.setValue(r),this.performSearch(t),this.updateStatus("Replaced current occurrence")}replaceAll(t,e){if(!this.editor||!t.trim())return;let s=this.editor.getValue(),i=0,n=s.toLowerCase().indexOf(t.toLowerCase());for(;n!==-1;)s=s.substring(0,n)+e+s.substring(n+t.length),i++,n=s.toLowerCase().indexOf(t.toLowerCase(),n+e.length);i>0&&(this.editor.setValue(s),this.updateStatus(`Replaced ${i} occurrences`))}getOffsetFromPosition(t,e){const s=t.split(`
`);let i=0;for(let n=0;n<e.line;n++)i+=s[n].length+1;return i+=e.column,i}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(t){const e=this.searchUI?.querySelector(".search-status");e&&(e.textContent=t)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class K{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(t){this.editor=t,t.on("cursor",()=>{this.updateBracketMatching()}),t.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const t=this.editor.getCursor(),e=this.editor.getValue();this.clearBracketHighlighting();const s=this.getBracketAtPosition(e,t.position);if(!s)return;const i=this.findMatchingBracket(e,s);i&&(this.currentMatch=i,this.highlightBrackets(i))}getBracketAtPosition(t,e){const s=t.split(`
`);if(e.line>=s.length)return null;const i=s[e.line];if(e.column>=i.length)return null;const n=i[e.column];return this.bracketPairs[n]||this.reverseBracketPairs[n]?{char:n,position:e}:null}findMatchingBracket(t,e){const s=t.split(`
`),i=e.position.line,n=e.position.column,o=e.char;return this.bracketPairs[o]?this.findClosingBracket(t,s,i,n,o):this.reverseBracketPairs[o]?this.findOpeningBracket(t,s,i,n,o):null}findClosingBracket(t,e,s,i,n){const o=this.bracketPairs[n];let h=0;for(let r=s;r<e.length;r++){const l=e[r],c=r===s?i:0;for(let d=c;d<l.length;d++){const f=l[d];if(f===n)h++;else if(f===o&&(h--,h===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:r,column:d},end:{line:r,column:d+1}},type:n}}}return null}findOpeningBracket(t,e,s,i,n){const o=this.reverseBracketPairs[n];let h=0;for(let r=s;r>=0;r--){const l=e[r],c=r===s?i:l.length-1;for(let d=c;d>=0;d--){const f=l[d];if(f===n)h++;else if(f===o&&(h--,h===0))return{open:{start:{line:r,column:d},end:{line:r,column:d+1}},close:{start:{line:s,column:i},end:{line:s,column:i+1}},type:o}}}return null}highlightBrackets(t){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class B{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(t){this.editor=t,t.registerCommand("fold",()=>{this.foldAtCursor()}),t.registerCommand("unfold",()=>{this.unfoldAtCursor()}),t.registerCommand("foldAll",()=>{this.foldAll()}),t.registerCommand("unfoldAll",()=>{this.unfoldAll()}),t.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const t=document.querySelector(".rte-source-editor-modal");t&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
position: absolute;

@@ -155,7 +140,7 @@ left: 40px;

z-index: 2;
`,e.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const t=this.editor.getValue().split(`
`);this.findFoldableLines(t).forEach(i=>{this.createFoldIndicator(i)})}findFoldableLines(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&t.push(n)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
`,t.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(i=>{this.createFoldIndicator(i)})}findFoldableLines(t){const e=[];for(let s=0;s<t.length;s++){const i=t[s].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&e.push(s)}return e}createFoldIndicator(t){if(!this.foldingUI)return;const e=document.createElement("div");e.style.cssText=`
position: absolute;
left: 0;
top: ${e*21}px;
top: ${t*21}px;
width: 20px;

@@ -171,2 +156,2 @@ height: 21px;

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 T{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")}setTheme(e){this.currentTheme=e,console.log(`SyntaxHighlightingExtension: Theme changed to ${e}`)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrValue:"#ce9178",text:"#d4d4d4"}:{tag:"#0000ff",comment:"#008000",attrValue:"#a31515",text:"#000000"}}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}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,console.log("SyntaxHighlightingExtension: Extension destroyed")}}function M(u,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(i=>i.name==="keymap")||t.extensions.unshift(new b(t.keymap)),new p(u,t)}c.BracketMatchingExtension=C,c.CodeFoldingExtension=L,c.EditorCore=p,c.KeymapExtension=b,c.LineNumbersExtension=v,c.ReadOnlyExtension=w,c.SearchExtension=k,c.SyntaxHighlightingExtension=T,c.TextModel=f,c.ThemeExtension=E,c.View=y,c.createEditor=M,c.default=p,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
`,e.innerHTML="▶",e.title="Code folding not yet implemented - click shows fold indicators",e.addEventListener("click",()=>{}),this.foldingUI.appendChild(e),this.foldIndicators.push(e)}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class V{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark",this.currentLanguage=null,this.modes=new Map}setup(t){this.editor=t,this.registerMode("html",{name:"html",highlight:(e,s)=>this._highlightHTML(e,s)}),this.registerMode("javascript",{name:"javascript",highlight:(e,s)=>this._highlightJS(e,s)}),this.registerMode("typescript",{name:"typescript",highlight:(e,s)=>this._highlightJS(e,s)}),this.registerMode("php",{name:"php",highlight:(e,s)=>this._highlightPHP(e,s)})}setTheme(t){this.currentTheme=t}setLanguage(t){this.currentLanguage=t}registerMode(t,e){this.modes.set(t.toLowerCase(),e)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrName:"#9cdcfe",attrValue:"#ce9178",styleProp:"#c586c0",styleVal:"#dcdcaa",doctype:"#808080",text:"#d4d4d4",keyword:"#c586c0",string:"#ce9178",number:"#b5cea8",variable:"#9cdcfe"}:{tag:"#0000ff",comment:"#008000",attrName:"#001080",attrValue:"#a31515",styleProp:"#6a00a8",styleVal:"#804000",doctype:"#444444",text:"#000000",keyword:"#000080",string:"#a31515",number:"#0086b3",variable:"#001080"}}highlight(t,e){const s=this.getSyntaxColors(),i=(e||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(t,s)}highlightHTML(t){return this.highlight(t,"html")}escapeHTML(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}unescapeEntitiesRepeated(t){let e=t||"";for(let s=0;s<5;s++){const i=e;if(e=e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),e===i)break}return e}_highlightHTML(t,e){const s=e,i=l=>this.escapeHTML(l);let n=i(t);const o=l=>{let c=l.replace(/&quot;/g,'"').replace(/&#39;/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${s.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(d,f,g,a,u)=>{const p=String(a).trim(),x=i(p);return`<span style="color: ${s.styleProp};">${f}</span>${g}<span style="color: ${s.styleVal};">${x}</span>${u}`}),c},h=[];try{t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(l,c,d)=>(h.push({attrs:String(c||""),inner:String(d||"")}),l))}catch{}let r=0;return n=n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi,(l,c,d,f,g)=>{const a=h[r++]?.inner??this.unescapeEntitiesRepeated(f||"");(h[r-1]?.attrs||d||"").toLowerCase();const u=this._highlightJS(a,s);return`${c}${u}${g}`}),n=n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi,(l,c,d,f)=>{const g=o(d);return`${c}${g}${f}`}),n=n.replace(/(&lt;!--[\s\S]*?--&gt;)/g,`<span style="color: ${s.comment};">$1</span>`),n=n.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i,`<span style="color: ${s.doctype};">$1</span>`),n=n.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g,(l,c,d,f,g)=>{const a=`<span style="color: ${s.tag};">${d}</span>`;let u=f;return u=u.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,(p,x,w,T)=>{const L=String(x).toLowerCase(),S=`<span style="color: ${s.attrName};">${x}</span>`;let C=T,v="";T.startsWith("&quot;")&&T.endsWith("&quot;")?(C=T.slice(6,-6),v="&quot;"):T.startsWith("&#39;")&&T.endsWith("&#39;")&&(C=T.slice(5,-5),v="&#39;");let M=T;if(L==="style"){const P=C.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(z,U,F,_)=>`<span style="color: ${s.styleProp};">${U}</span>:<span style="color: ${s.styleVal};">${F.trim()}</span>${_}`);v?M=`${v}${P}${v}`:M=P,M=`<span style="color: ${s.attrValue};">${M}</span>`}else v&&(M=`${v}${C}${v}`),M=`<span style="color: ${s.attrValue};">${M}</span>`;return`${S}${w}${M}`}),`${c}${a}${u}${g}`}),n}_highlightJS(t,e){const s=this.unescapeEntitiesRepeated(t);this.escapeHTML(s);const i=[],n=g=>{let a="",u=g;do a=String.fromCharCode(97+u%26)+a,u=Math.floor(u/26)-1;while(u>=0);return a||"a"},o=g=>`\0${n(g)}\0`,h=g=>{const a=i.length;return i.push(g),o(a)};let r;const l=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,d="";for(;r=l.exec(s);){const g=r.index;c<g&&(d+=this.escapeHTML(s.slice(c,g)));const a=r[0];/^\/\*/.test(a)||/^\/\//.test(a)?d+=h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`):d+=h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`),c=l.lastIndex}return c<s.length&&(d+=this.escapeHTML(s.slice(c))),d=d.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(g,a,u)=>{const p=d[u-1]||"",x=d[u+g.length]||"";return p==="&"||p==="#"||x===";"||x==="#"?g:`<span style="color: ${e.number};">${g}</span>`}),d=d.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g,`<span style="color: ${e.keyword};">$1</span>`),d.replace(/\u0000([a-z]+)\u0000/g,(g,a)=>{let u=0;for(let p=0;p<a.length;p++)u=u*26+(a.charCodeAt(p)-97+1);return u=u-1,i[u]||""})}_highlightPHP(t,e){const s=this.unescapeEntitiesRepeated(t);let i=this.escapeHTML(s);const n=[],o=a=>{let u="",p=a;do u=String.fromCharCode(97+p%26)+u,p=Math.floor(p/26)-1;while(p>=0);return u||"a"},h=a=>{const u=n.length;return n.push(a),`\0${o(u)}\0`},r=(a,u)=>{const p=i.indexOf(a);return p===-1?!1:(i=i.slice(0,p)+u+i.slice(p+a.length),!0)};let l;const c=/\/\*[\s\S]*?\*\//g,d=/\/\/[^\n\r]*/g,f=/\#([^\n\r]*)/g,g=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;l=c.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=d.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=f.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=g.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`))}return i=i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g,`<span style="color: ${e.variable};">$1</span>`),i=i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g,`<span style="color: ${e.keyword};">$1</span>`),i=i.replace(/\u0000([a-z]+)\u0000/g,(a,u)=>{let p=0;for(let x=0;x<u.length;x++)p=p*26+(u.charCodeAt(x)-97+1);return p=p-1,n[p]||""}),i}shouldHighlight(t){return/<\/?[\w:-]+|<!--/.test(t)}destroy(){this.editor=null,this.modes.clear()}}function A(y,t){const e={...t};return e.extensions||(e.extensions=[]),e.extensions.some(n=>n.name==="keymap")||e.extensions.unshift(new E(e.keymap)),e.extensions.some(n=>n.name==="transaction")||e.extensions.unshift(new $),new k(y,e)}m.BracketMatchingExtension=K,m.CodeFoldingExtension=B,m.EditorCore=k,m.KeymapExtension=E,m.LineNumbersExtension=H,m.ReadOnlyExtension=I,m.SearchExtension=N,m.SyntaxHighlightingExtension=V,m.TextModel=b,m.ThemeExtension=R,m.View=O,m.createEditor=A,m.default=k,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));

@@ -1,1 +0,1 @@

.rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}
.rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}.editor-container{font-family:monospace;background-color:#1e1e1e;color:#d4d4d4;padding:10px;border:1px solid #333;border-radius:4px;overflow:auto}.editor-line{white-space:pre}.editor-line-number{display:inline-block;width:30px;text-align:right;margin-right:10px;color:#858585}
{
"name": "@editora/light-code-editor",
"version": "1.0.2",
"description": "Lightweight, extensible code editor library inspired by CodeMirror",
"version": "1.0.3",
"description": "Lightweight, extensible code editor for the web — syntax highlighting, line numbers, code folding, and a plugin-friendly API. Ideal for embedding in docs, demos, and web apps.",
"authors": [

@@ -28,7 +28,25 @@ "Ajay Kumar <ajaykr089@gmail.com>"

"code-editor",
"codemirror",
"lightweight",
"extensible",
"typescript"
"lightweight-editor",
"syntax-highlighting",
"javascript-editor",
"typescript-editor",
"web-editor",
"code-playground",
"line-numbers",
"code-folding",
"plugin-friendly"
],
"repository": {
"type": "git",
"url": "https://github.com/ajaykr089/Editora.git",
"directory": "packages/light-code-editor"
},
"homepage": "https://github.com/ajaykr089/Editora#readme",
"bugs": {
"url": "https://github.com/ajaykr089/Editora/issues"
},
"style": "dist/light-code-editor.css",
"publishConfig": {
"access": "public"
},
"author": "Ajay Kumar <ajaykr089@gmail.com>",

@@ -41,3 +59,3 @@ "license": "MIT",

},
"gitHead": "b4a92679b7a31308632c48abd5e536476d58b0c7"
"gitHead": "694494db58b809f0dcf24501696284faa1ab68a5"
}
MIT License
Copyright (c) 2026 Ajay Kumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.