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.3
to
1.0.4
+16
CHANGELOG.md
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## 1.0.2 (2026-02-13)
**Note:** Version bump only for package @editora/light-code-editor
## 1.0.1 (2026-02-12)
**Note:** Version bump only for package @editora/light-code-editor
/**
* Lightweight Code Editor - Core Editor Class
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { TextModel } from './TextModel';
import { View } from './View';
import { EditorAPI, EditorConfig, EditorState, EditorEvents, EditorExtension, Position, Range, Cursor, SearchResult, SearchOptions, FoldRange } from './types';
export declare class EditorCore implements EditorAPI {
private static readonly CURSOR_SENTINEL;
private textModel;
private view;
private config;
private extensions;
private commands;
private eventListeners;
private folds;
private currentTheme;
private isDestroyed;
private undoStack;
private redoStack;
private suppressHistory;
private highlightTimeout;
private expectingProgrammaticCursor;
getTextModel(): TextModel;
getView(): View;
getConfig(): EditorConfig;
constructor(container: HTMLElement, config?: EditorConfig);
private registerBuiltInCommands;
getKeymapExtension(): any;
private setupEventHandlers;
private updateLineNumbers;
private getFullRange;
private emit;
getValue(): string;
setValue(value: string): void;
getState(): EditorState;
getCursor(): Cursor;
setCursor(position: Position): void;
getSelection(): Range | undefined;
setSelection(range: Range): void;
setTheme(theme: string): void;
setReadOnly(readOnly: boolean): void;
addExtension(extension: EditorExtension): void;
removeExtension(name: string): void;
executeCommand(name: string, ...args: any[]): void;
registerCommand(name: string, handler: Function): void;
search(query: string, options?: Partial<SearchOptions>): SearchResult[];
replace(range: Range, text: string): void;
replaceAll(query: string, replacement: string, options?: Partial<SearchOptions>): number;
fold(range: Range): void;
unfold(range: Range): void;
getFolds(): FoldRange[];
focus(): void;
blur(): void;
private renderTextWithHighlight;
private hasCollapsedSelectionInEditor;
private getCollapsedSelectionOffsetInEditor;
private stripVirtualMarkers;
private insertSentinelAtOffset;
private restoreCursorFromSentinel;
destroy(): void;
private undo;
private redo;
private insertTab;
private insertNewLine;
on<K extends keyof EditorEvents>(event: K, handler: EditorEvents[K]): void;
off<K extends keyof EditorEvents>(event: K, handler?: EditorEvents[K]): void;
}
//# sourceMappingURL=EditorCore.d.ts.map
/**
* Bracket Matching Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorCore, BracketMatch } from '../types';
export declare class BracketMatchingExtension implements EditorExtension {
readonly name = "bracket-matching";
private editor;
private bracketPairs;
private reverseBracketPairs;
private currentMatch;
setup(editor: EditorCore): void;
private updateBracketMatching;
private getBracketAtPosition;
private findMatchingBracket;
private findClosingBracket;
private findOpeningBracket;
private highlightBrackets;
private clearBracketHighlighting;
getCurrentMatch(): BracketMatch | null;
destroy(): void;
}
//# sourceMappingURL=BracketMatchingExtension.d.ts.map
/**
* Code Folding Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorAPI } from '../types';
export declare class CodeFoldingExtension implements EditorExtension {
readonly name = "code-folding";
private editor;
private foldIndicators;
private foldingUI;
setup(editor: EditorAPI): void;
private createFoldingUI;
private updateFoldIndicators;
private findFoldableLines;
private createFoldIndicator;
private foldAtCursor;
private unfoldAtCursor;
private foldAll;
private unfoldAll;
destroy(): void;
}
//# sourceMappingURL=CodeFoldingExtension.d.ts.map
/**
* Lightweight Code Editor - Built-in Extensions
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
export { LineNumbersExtension } from './LineNumbersExtension';
export { ThemeExtension } from './ThemeExtension';
export { ReadOnlyExtension } from './ReadOnlyExtension';
export { SearchExtension } from './SearchExtension';
export { BracketMatchingExtension } from './BracketMatchingExtension';
export { CodeFoldingExtension } from './CodeFoldingExtension';
export { SyntaxHighlightingExtension } from './SyntaxHighlightingExtension';
export { KeymapExtension } from './KeymapExtension';
//# sourceMappingURL=index.d.ts.map
/**
* Keymap Extension - Platform-aware configurable keyboard bindings
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorCore, KeyBinding, Keymap } from '../types';
export declare class KeymapExtension implements EditorExtension {
readonly name = "keymap";
private editor;
private keymap;
private isMac;
constructor(keymap?: Keymap);
setup(editor: EditorCore): void;
private handleKeyDown;
private findMatchingBinding;
onKeyDown(event: KeyboardEvent): boolean | void;
private getDefaultKeymap;
private addBinding;
setKeymap(keymap: Keymap): void;
addKeyBinding(binding: KeyBinding): void;
removeKeyBinding(key: string, command?: string): void;
getKeymap(): Keymap;
getBindingsForCommand(command: string): KeyBinding[];
getPlatformInfo(): {
isMac: boolean;
platform: string;
};
destroy(): void;
}
//# sourceMappingURL=KeymapExtension.d.ts.map
/**
* Line Numbers Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorCore } from '../types';
export declare class LineNumbersExtension implements EditorExtension {
readonly name = "line-numbers";
private editor;
private lineNumbersElement;
private isEnabled;
setup(editor: EditorCore): void;
private createLineNumbers;
private updateLineNumbers;
private toggle;
destroy(): void;
}
//# sourceMappingURL=LineNumbersExtension.d.ts.map
/**
* Read-Only Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorCore } from '../types';
export declare class ReadOnlyExtension implements EditorExtension {
readonly name = "read-only";
private editor;
private isReadOnly;
setup(editor: EditorCore): void;
private setReadOnly;
private toggleReadOnly;
isCurrentlyReadOnly(): boolean;
destroy(): void;
}
//# sourceMappingURL=ReadOnlyExtension.d.ts.map
/**
* Search Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorAPI } from '../types';
export declare class SearchExtension implements EditorExtension {
readonly name = "search";
private editor;
private searchUI;
private isVisible;
private currentResults;
private currentIndex;
setup(editor: EditorAPI): void;
private showSearch;
private showReplace;
private hideSearch;
private createSearchUI;
private performSearch;
private getPositionFromOffset;
private findNext;
private findPrev;
private replaceCurrent;
private replaceAll;
private getOffsetFromPosition;
private updateHighlights;
private clearHighlights;
private updateStatus;
destroy(): void;
}
//# sourceMappingURL=SearchExtension.d.ts.map
/**
* Syntax Highlighting Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*
* Implements CodeMirror-style syntax highlighting for HTML content
* Completely isolated extension with no external dependencies
*/
import { EditorExtension, EditorAPI } from '../types';
export declare class SyntaxHighlightingExtension implements EditorExtension {
readonly name = "syntax-highlighting";
private editor;
private currentTheme;
private currentLanguage;
private modes;
setup(editor: EditorAPI): void;
setTheme(theme: string): void;
setLanguage(lang: string | null): void;
registerMode(lang: string, mode: {
name: string;
highlight: (src: string, colors: Record<string, string>) => string;
}): void;
getSyntaxColors(): Record<string, string>;
highlight(src: string, lang?: string): string;
highlightHTML(html: string): string;
private escapeHTML;
private unescapeEntitiesRepeated;
private _highlightHTML;
private _highlightJS;
private _highlightPHP;
shouldHighlight(content: string): boolean;
destroy(): void;
}
//# sourceMappingURL=SyntaxHighlightingExtension.d.ts.map
/**
* Theme Extension
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { EditorExtension, EditorCore } from '../types';
export declare class ThemeExtension implements EditorExtension {
readonly name = "theme";
private editor;
private currentTheme;
setup(editor: EditorCore): void;
private setTheme;
private toggleTheme;
getCurrentTheme(): string;
destroy(): void;
}
//# sourceMappingURL=ThemeExtension.d.ts.map
/**
* Transaction Extension for Light Code Editor
* Implements immutable state updates and batched changes.
*/
import { EditorCore, EditorExtension, Transaction } from '../types';
export declare class TransactionExtension implements EditorExtension {
name: string;
private transactions;
setup(editor: EditorCore): void;
getTransactions(): Transaction[];
destroy(): void;
}
//# sourceMappingURL=TransactionExtension.d.ts.map
/**
* Lightweight Code Editor Library
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import './styles/editor.css';
import { EditorCore } from './EditorCore';
export { EditorCore } from './EditorCore';
export { TextModel } from './TextModel';
export { View } from './View';
export * from './extensions';
export type { EditorAPI, EditorConfig, EditorState, EditorEvents, EditorExtension, Position, Range, TextChange, Transaction, Cursor, SearchResult, SearchOptions, BracketMatch, FoldRange, Theme } from './types';
export declare function createEditor(container: HTMLElement, config?: import('./types').EditorConfig): EditorCore;
export default EditorCore;
//# sourceMappingURL=index.d.ts.map
/**
* Lightweight Code Editor - Text Model
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { Position, Range, TextChange } from './types';
export declare class TextModel {
private _lines;
private _version;
constructor(text?: string);
getLine(line: number): string;
getLines(): string[];
getLineCount(): number;
getText(): string;
setText(text: string): void;
getTextInRange(range: Range): string;
replaceRange(range: Range, text: string): TextChange;
insertText(position: Position, text: string): TextChange;
deleteRange(range: Range): TextChange;
positionToOffset(position: Position): number;
offsetToPosition(offset: number): Position;
isValidPosition(position: Position): boolean;
isValidRange(range: Range): boolean;
getVersion(): number;
clone(): TextModel;
}
//# sourceMappingURL=TextModel.d.ts.map
/**
* Lightweight Code Editor Library - Types and Interfaces
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
export interface Position {
line: number;
column: number;
}
export interface Range {
start: Position;
end: Position;
}
export interface TextChange {
range: Range;
text: string;
oldText: string;
}
export interface Transaction {
changes: TextChange[];
selection?: Range;
effects: unknown[];
annotations: unknown[];
}
export interface Cursor {
position: Position;
anchor?: Position;
}
export interface EditorState {
text: string;
cursor: Cursor;
selection?: Range;
readOnly: boolean;
theme: string;
}
export interface Theme {
name: string;
variables: Record<string, string>;
}
export interface EditorExtension {
name: string;
setup(editor: EditorCore): void;
onUpdate?(state: EditorState): void;
onKeyDown?(event: KeyboardEvent): boolean | void;
onMouseDown?(event: MouseEvent): boolean | void;
destroy?(): void;
}
export interface Command {
name: string;
execute(editor: EditorCore, ...args: any[]): void;
canExecute?(editor: EditorCore): boolean;
}
export interface KeyBinding {
key: string;
ctrlKey?: boolean;
altKey?: boolean;
shiftKey?: boolean;
metaKey?: boolean;
command: string;
}
export interface Keymap {
[key: string]: KeyBinding[];
}
export interface SearchOptions {
query: string;
caseSensitive?: boolean;
wholeWord?: boolean;
regex?: boolean;
}
export interface SearchResult {
range: Range;
match: string;
}
export interface BracketMatch {
open: Range;
close: Range;
type: '(' | '[' | '{' | '<';
}
export interface FoldRange {
start: Position;
end: Position;
collapsed: boolean;
level: number;
}
export interface EditorConfig {
value?: string;
theme?: string;
readOnly?: boolean;
tabSize?: number;
lineWrapping?: boolean;
lineNumbers?: boolean;
extensions?: EditorExtension[];
keymap?: Keymap;
}
export interface EditorEvents {
change: (changes: TextChange[]) => void;
cursor: (cursor: Cursor) => void;
selection: (range?: Range) => void;
focus: () => void;
blur: () => void;
keydown: (event: KeyboardEvent) => void;
mousedown: (event: MouseEvent) => void;
save: () => void;
}
export interface View {
getContentElement(): HTMLElement;
getLineNumbersElement(): HTMLElement;
getText(): string;
setText(text: string): void;
setHTML(html: string): void;
getCursorPosition(): Position;
setCursorPosition(position: Position): void;
getSelectionRange(): Range | undefined;
setSelectionRange(range: Range): void;
focus(): void;
blur(): void;
setReadOnly(readOnly: boolean): void;
applyTheme(theme: Record<string, string>): void;
scrollToPosition(position: Position): void;
getScrollTop(): number;
setScrollTop(scrollTop: number): void;
updateLineNumbers(lineCount: number): void;
destroy(): void;
}
export interface EditorAPI {
getValue(): string;
setValue(value: string): void;
getState(): EditorState;
getCursor(): Cursor;
setCursor(position: Position): void;
getSelection(): Range | undefined;
setSelection(range: Range): void;
setTheme(theme: string): void;
setReadOnly(readOnly: boolean): void;
addExtension(extension: EditorExtension): void;
removeExtension(name: string): void;
executeCommand(name: string, ...args: any[]): void;
getView(): View;
registerCommand(name: string, handler: Function): void;
search(query: string, options?: Partial<SearchOptions>): SearchResult[];
replace(range: Range, text: string): void;
replaceAll(query: string, replacement: string, options?: Partial<SearchOptions>): number;
fold(range: Range): void;
unfold(range: Range): void;
getFolds(): FoldRange[];
focus(): void;
blur(): void;
destroy(): void;
on<K extends keyof EditorEvents>(event: K, handler: EditorEvents[K]): void;
off<K extends keyof EditorEvents>(event: K, handler?: EditorEvents[K]): void;
}
export interface EditorCore extends EditorAPI {
}
//# sourceMappingURL=types.d.ts.map
/**
* Lightweight Code Editor - View/Renderer
* Author: Ajay Kumar <ajaykr089@gmail.com>
*/
import { Position, Range } from './types';
export declare class View {
private container;
private editorContainer;
private contentElement;
private lineNumbersElement;
private gutterWidth;
private lineHeight;
private _rafId?;
private readonly trailingNewlineMarkerAttr;
constructor(container: HTMLElement);
private createDOM;
updateLineNumbers(lineCount: number): void;
getContentElement(): HTMLElement;
getLineNumbersElement(): HTMLElement;
getText(): string;
setText(text: string): void;
setHTML(html: string): void;
syncTrailingNewlineMarkerForText(text: string): void;
getCursorPosition(): Position;
setCursorPosition(position: Position): void;
getSelectionRange(): Range | undefined;
setSelectionRange(range: Range): void;
focus(): void;
blur(): void;
setReadOnly(readOnly: boolean): void;
applyTheme(theme: Record<string, string>): void;
scrollToPosition(position: Position): void;
getScrollTop(): number;
setScrollTop(scrollTop: number): void;
private syncTrailingNewlineMarker;
ensureCaretVisible(): void;
destroy(): void;
}
//# sourceMappingURL=View.d.ts.map
+319
-219

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

class k {
class M {
constructor(t = "") {

@@ -45,5 +45,5 @@ this._lines = [], this._version = 0, this.setText(t);

} 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(`
const i = this.getLine(t.start.line), n = this.getLine(t.end.line), o = i.substring(0, t.start.column) + e, r = n.substring(t.end.column), l = 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);
l[0] = o + l[0], l[l.length - 1] = l[l.length - 1] + r, this._lines.splice(t.start.line, t.end.line - t.start.line + 1, ...l);
}

@@ -96,3 +96,3 @@ return this._version++, { range: t, text: e, oldText: s };

clone() {
const t = new k();
const t = new M();
return t._lines = [...this._lines], t._version = this._version, t;

@@ -103,3 +103,3 @@ }

constructor(t) {
this.gutterWidth = 50, this.lineHeight = 21, this.container = t, this.createDOM();
this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.container = t, this.createDOM();
}

@@ -168,7 +168,9 @@ createDOM() {

getText() {
return this.contentElement.textContent || "";
const t = this.contentElement.textContent || "";
return !!this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && t.endsWith("​") ? t.slice(0, -1) : t;
}
// Set text content
setText(t) {
this.contentElement.textContent = t;
this.contentElement.textContent = t, this.syncTrailingNewlineMarker(t.endsWith(`
`));
const e = t.split(`

@@ -180,8 +182,14 @@ `).length;

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(`
const e = /\n$/.test(t), s = /&lt;|&gt;/.test(t), i = /<span\b/i.test(t), n = /<[^>]+>/.test(t);
s && i ? this.contentElement.innerHTML = t : n && !s ? this.contentElement.textContent = t : this.contentElement.innerHTML = t, this.syncTrailingNewlineMarker(e);
const r = (this.contentElement.textContent || "").split(`
`).length;
this.updateLineNumbers(o);
this.updateLineNumbers(r);
}
// Keep trailing-newline caret marker in sync for live contenteditable edits
// (without forcing a full setText/setHTML render).
syncTrailingNewlineMarkerForText(t) {
this.syncTrailingNewlineMarker(t.endsWith(`
`));
}
// Get cursor position from DOM selection

@@ -194,3 +202,3 @@ getCursorPosition() {

s.selectNodeContents(this.contentElement), s.setEnd(e.endContainer, e.endOffset);
const n = s.toString().split(`
const n = s.toString().replace(/\u200B/g, "").split(`
`);

@@ -207,7 +215,7 @@ return {

let o = 0;
for (let a = 0; a < i; a++)
o += s[a].length + 1;
for (let h = 0; h < i; h++)
o += s[h].length + 1;
o += n;
const h = document.createRange(), r = window.getSelection();
let l = 0, c = null, d = 0;
const r = document.createRange(), l = window.getSelection();
let a = 0, c = null, d = 0;
const f = document.createTreeWalker(

@@ -218,17 +226,27 @@ this.contentElement,

);
let g;
for (; g = f.nextNode(); ) {
const a = g.textContent?.length || 0;
if (l + a >= o) {
c = g, d = o - l;
let u;
for (; u = f.nextNode(); ) {
const h = u.textContent?.length || 0;
if (a + h >= o) {
c = u, d = o - a;
break;
}
l += a;
a += h;
}
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);
r.setStart(c, d), r.setEnd(c, d), l?.removeAllRanges(), l?.addRange(r), this.ensureCaretVisible();
} catch (h) {
console.warn("Could not set cursor position:", h);
}
else {
const h = this.contentElement.querySelector(
`[${this.trailingNewlineMarkerAttr}]`
);
try {
h && h.parentNode === this.contentElement ? r.setStartBefore(h) : (r.selectNodeContents(this.contentElement), r.collapse(!1)), r.collapse(!0), l?.removeAllRanges(), l?.addRange(r), this.ensureCaretVisible();
} catch (g) {
console.warn("Could not set fallback cursor position:", g);
}
}
}

@@ -242,6 +260,6 @@ // Get selection range

s.selectNodeContents(this.contentElement), s.setEnd(e.startContainer, e.startOffset);
const n = s.toString().split(`
const n = s.toString().replace(/\u200B/g, "").split(`
`), o = e.cloneRange();
o.selectNodeContents(this.contentElement), o.setEnd(e.endContainer, e.endOffset);
const r = o.toString().split(`
const l = o.toString().replace(/\u200B/g, "").split(`
`);

@@ -254,4 +272,4 @@ return {

end: {
line: r.length - 1,
column: r[r.length - 1].length
line: l.length - 1,
column: l[l.length - 1].length
}

@@ -266,3 +284,3 @@ };

focus() {
this.contentElement.focus();
this.contentElement.focus(), this.ensureCaretVisible();
}

@@ -296,2 +314,24 @@ // Blur the editor

}
syncTrailingNewlineMarker(t) {
if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((s) => s.remove()), !t) return;
const e = document.createElement("span");
e.setAttribute(this.trailingNewlineMarkerAttr, "true"), e.setAttribute("aria-hidden", "true"), e.contentEditable = "false", e.style.cssText = `
display: inline-block;
width: 0;
overflow: hidden;
pointer-events: none;
user-select: none;
`, e.appendChild(document.createTextNode("​")), this.contentElement.appendChild(e);
}
// Ensure caret is visible inside the editor scroll container
ensureCaretVisible() {
const t = window.getSelection();
if (!t || t.rangeCount === 0) return;
const e = t.getRangeAt(0).cloneRange();
e.collapse(!1);
let s = e.getClientRects()[0] || e.getBoundingClientRect();
if ((!s || s.width === 0 && s.height === 0) && t.focusNode instanceof Element ? s = t.focusNode.getBoundingClientRect() : (!s || s.width === 0 && s.height === 0) && t.focusNode?.parentElement && (s = t.focusNode.parentElement.getBoundingClientRect()), !s) return;
const i = this.editorContainer.getBoundingClientRect(), n = 12;
s.bottom > i.bottom - n ? this.editorContainer.scrollTop += s.bottom - (i.bottom - n) : s.top < i.top + n && (this.editorContainer.scrollTop -= i.top + n - s.top);
}
// Destroy the view

@@ -302,5 +342,5 @@ destroy() {

}
class $ {
const C = class C {
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 = {
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.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.config = {
value: "",

@@ -313,3 +353,3 @@ theme: "default",

...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();
}, this.textModel = new M(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();
}

@@ -344,7 +384,8 @@ // Public accessors for extensions

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;
let r, l;
o && (r = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: s, cursorOffset: n, anchorOffset: r, focusOffset: l }), 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;
this.textModel.setText(e), this.view.syncTrailingNewlineMarkerForText(e), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
const i = this.view.getText();
i !== this.textModel.getText() && this.textModel.setText(i), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
}, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: s }]);

@@ -365,23 +406,27 @@ }

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(`
let r, l;
o && (r = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end));
const a = o && r !== void 0 && l !== void 0 ? Math.min(r, l) : n;
this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: r, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
const c = s.getRangeAt(0);
c.deleteContents();
const d = 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(() => {
c.insertNode(d), c.setStartAfter(d), c.collapse(!0), s.removeAllRanges(), s.addRange(c), this.view.ensureCaretVisible();
const f = this.view.getText();
this.textModel.setText(f), this.view.syncTrailingNewlineMarkerForText(f);
const u = Math.min(
a + 1,
this.textModel.getText().length
);
try {
const h = this.textModel.offsetToPosition(u);
this.setCursor(h), this.view.ensureCaretVisible();
} catch {
}
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);
}
const h = this.textModel.offsetToPosition(u);
this.setCursor(h), this.view.ensureCaretVisible();
} catch {

@@ -518,21 +563,21 @@ }

`);
let o = s.caseSensitive ? n : n.toLowerCase(), h = s.caseSensitive ? t : t.toLowerCase();
let o = s.caseSensitive ? n : n.toLowerCase(), r = 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);
const l = new RegExp(r, s.caseSensitive ? "g" : "gi");
let a;
for (; (a = l.exec(o)) !== null; ) {
const c = this.textModel.offsetToPosition(a.index), d = this.textModel.offsetToPosition(a.index + a[0].length);
i.push({
range: { start: c, end: d },
match: l[0]
match: a[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);
let l = 0, a = o.indexOf(r, l);
for (; a !== -1; ) {
const c = a + t.length, d = this.textModel.offsetToPosition(a), f = this.textModel.offsetToPosition(c);
i.push({
range: { start: d, end: f },
match: n.substring(l, c)
}), r = c, l = o.indexOf(h, r);
match: n.substring(a, c)
}), l = c, a = o.indexOf(r, l);
}

@@ -545,5 +590,5 @@ }

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 n = this.getCursor().position, o = this.textModel.positionToOffset(n), r = this.getSelection();
let l, a;
r && (l = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: s, cursorOffset: o, anchorOffset: l, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
}

@@ -594,17 +639,27 @@ const i = this.textModel.replaceRange(t, e);

const i = !e && !this.expectingProgrammaticCursor;
let n, o, h, r;
let n, o, r, l;
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 f = this.getCollapsedSelectionOffsetInEditor();
if (f !== void 0)
o = f;
else {
const u = this.getCursor().position;
o = this.textModel.positionToOffset(u);
}
n && (r = this.textModel.positionToOffset(n.start), l = 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(() => {
const a = (e || i) && !n && o !== void 0 && this.hasCollapsedSelectionInEditor(), c = a ? this.insertSentinelAtOffset(t, o) : t, d = s.highlightHTML(c);
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(d) : this.view.setHTML(d), this.view.syncTrailingNewlineMarkerForText(t), (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 });
if (a && this.restoreCursorFromSentinel()) {
this.view.ensureCaretVisible();
return;
}
if (n && (r !== void 0 || l !== void 0)) {
const f = r !== void 0 ? r : o, u = l !== void 0 ? l : o, h = Math.min(f, u), g = Math.max(f, u), p = this.textModel.offsetToPosition(h), m = this.textModel.offsetToPosition(g);
this.view.setSelectionRange({ start: p, end: m });
} else if (o !== void 0) {
const c = this.textModel.offsetToPosition(o);
this.view.setCursorPosition(c);
const f = this.textModel.offsetToPosition(o);
this.view.setCursorPosition(f);
}

@@ -620,2 +675,41 @@ } catch {

}
hasCollapsedSelectionInEditor() {
const t = window.getSelection();
if (!t || t.rangeCount === 0 || !t.isCollapsed)
return !1;
const e = t.getRangeAt(0);
return this.view.getContentElement().contains(e.commonAncestorContainer);
}
getCollapsedSelectionOffsetInEditor() {
const t = window.getSelection();
if (!t || t.rangeCount === 0 || !t.isCollapsed)
return;
const e = t.getRangeAt(0), s = this.view.getContentElement();
if (!s.contains(e.commonAncestorContainer))
return;
const i = e.cloneRange();
return i.selectNodeContents(s), i.setEnd(e.endContainer, e.endOffset), this.stripVirtualMarkers(i.toString()).length;
}
stripVirtualMarkers(t) {
return t.replace(/\u200B/g, "").split(C.CURSOR_SENTINEL).join("");
}
insertSentinelAtOffset(t, e) {
const s = Math.max(0, Math.min(e, t.length));
return t.slice(0, s) + C.CURSOR_SENTINEL + t.slice(s);
}
restoreCursorFromSentinel() {
const t = this.view.getContentElement(), e = window.getSelection(), s = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
let i = s.nextNode(), n = null, o = 0;
for (; i; ) {
const r = i.textContent ?? "", l = r.indexOf(C.CURSOR_SENTINEL);
l !== -1 && (n || (n = i, o = l), i.textContent = r.split(C.CURSOR_SENTINEL).join("")), i = s.nextNode();
}
if (!n || !e) return !1;
try {
const r = document.createRange();
return r.setStart(n, o), r.collapse(!0), e.removeAllRanges(), e.addRange(r), !0;
} catch {
return !1;
}
}
destroy() {

@@ -641,4 +735,4 @@ if (!this.isDestroyed) {

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 });
const n = t.anchorOffset !== void 0 ? t.anchorOffset : i, o = t.focusOffset !== void 0 ? t.focusOffset : i, r = Math.min(n, o), l = Math.max(n, o), a = this.textModel.offsetToPosition(r), c = this.textModel.offsetToPosition(l);
this.setSelection({ start: a, end: c });
} else {

@@ -668,4 +762,4 @@ const n = this.textModel.offsetToPosition(i);

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 });
const n = t.anchorOffset !== void 0 ? t.anchorOffset : i, o = t.focusOffset !== void 0 ? t.focusOffset : i, r = Math.min(n, o), l = Math.max(n, o), a = this.textModel.offsetToPosition(r), c = this.textModel.offsetToPosition(l);
this.setSelection({ start: a, end: c });
} else {

@@ -690,4 +784,4 @@ const n = this.textModel.offsetToPosition(i);

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;
let r, l;
o && (r = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: e, anchorOffset: r, focusOffset: l }), this.redoStack.length = 0;
}

@@ -705,4 +799,4 @@ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {

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;
let o, r;
n && (o = this.textModel.positionToOffset(n.start), r = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: e, anchorOffset: o, focusOffset: r }), this.redoStack.length = 0;
}

@@ -726,4 +820,6 @@ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(i), setTimeout(() => {

}
}
class H {
};
C.CURSOR_SENTINEL = "";
let w = C;
class $ {
constructor(t) {

@@ -742,8 +838,8 @@ this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = t || this.getDefaultKeymap();

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;
const { key: e, ctrlKey: s, altKey: i, shiftKey: n, metaKey: o } = t, r = String(e).toLowerCase(), l = this.keymap[r];
if (!l) return null;
for (const a of l) {
const c = a.ctrlKey === void 0 || a.ctrlKey === s, d = a.altKey === void 0 || a.altKey === i, f = a.shiftKey === void 0 || a.shiftKey === n, u = a.metaKey === void 0 || a.metaKey === o;
if (c && d && f && u)
return a;
}

@@ -803,3 +899,3 @@ return null;

}
class R {
class I {
constructor() {

@@ -811,3 +907,3 @@ this.name = "transaction", this.transactions = [];

const s = {
changes: [e],
changes: e,
selection: t.getSelection(),

@@ -827,3 +923,3 @@ effects: [],

}
class N {
class B {
constructor() {

@@ -851,2 +947,3 @@ this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;

toggle() {
if (!this.editor) return;
this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");

@@ -860,3 +957,3 @@ const t = this.editor.getView().getContentElement();

}
class K {
class A {
constructor() {

@@ -886,3 +983,3 @@ this.name = "theme", this.editor = null, this.currentTheme = "dark";

}
class B {
class K {
constructor() {

@@ -1025,6 +1122,6 @@ this.name = "read-only", this.editor = null, this.isReadOnly = !1;

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));
}), e.addEventListener("keydown", (r) => {
r.key === "Enter" && (r.preventDefault(), r.shiftKey ? this.findPrev() : this.findNext());
}), s.addEventListener("keydown", (r) => {
r.key === "Enter" && (r.preventDefault(), r.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);

@@ -1063,4 +1160,4 @@ }

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");
const i = this.editor.getValue(), n = this.getOffsetFromPosition(i, s.range.start), o = i.substring(0, n), r = i.substring(n + t.length), l = o + e + r;
this.editor.setValue(l), this.performSearch(t), this.updateStatus("Replaced current occurrence");
}

@@ -1095,3 +1192,3 @@ replaceAll(t, e) {

}
class A {
class U {
constructor() {

@@ -1142,13 +1239,13 @@ this.name = "bracket-matching", this.editor = null, this.bracketPairs = {

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];
let r = 0;
for (let l = s; l < e.length; l++) {
const a = e[l], c = l === s ? i : 0;
for (let d = c; d < a.length; d++) {
const f = a[d];
if (f === n)
h++;
else if (f === o && (h--, h === 0))
r++;
else if (f === o && (r--, r === 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 } },
close: { start: { line: l, column: d }, end: { line: l, column: d + 1 } },
type: n

@@ -1162,12 +1259,12 @@ };

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;
let r = 0;
for (let l = s; l >= 0; l--) {
const a = e[l], c = l === s ? i : a.length - 1;
for (let d = c; d >= 0; d--) {
const f = l[d];
const f = a[d];
if (f === n)
h++;
else if (f === o && (h--, h === 0))
r++;
else if (f === o && (r--, r === 0))
return {
open: { start: { line: r, column: d }, end: { line: r, column: d + 1 } },
open: { start: { line: l, column: d }, end: { line: l, column: d + 1 } },
close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },

@@ -1192,3 +1289,3 @@ type: o

}
class U {
class F {
constructor() {

@@ -1272,3 +1369,3 @@ this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;

}
class F {
class _ {
constructor() {

@@ -1359,39 +1456,42 @@ this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();

_highlightHTML(t, e) {
const s = e, i = (l) => this.escapeHTML(l);
const s = e, i = (a) => this.escapeHTML(a);
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}`;
const o = (a) => {
let c = a.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, u, h, g) => {
const p = String(h).trim(), m = i(p);
return `<span style="color: ${s.styleProp};">${f}</span>${u}<span style="color: ${s.styleVal};">${m}</span>${g}`;
}), c;
}, h = [];
}, r = [];
try {
t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (l, c, d) => (h.push({ attrs: String(c || ""), inner: String(d || "") }), l));
t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (a, c, d) => (r.push({ attrs: String(c || ""), inner: String(d || "") }), a));
} 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}`;
let l = 0;
return n = n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (a, c, d, f, u) => {
const h = r[l++]?.inner ?? this.unescapeEntitiesRepeated(f || "");
(r[l - 1]?.attrs || d || "").toLowerCase();
const g = this._highlightJS(h, s);
return `${c}${g}${u}`;
}), n = n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (a, c, d, f) => {
const u = o(d);
return `${c}${u}${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, (a, c, d, f, u) => {
const h = `<span style="color: ${s.tag};">${d}</span>`;
let g = f;
return g = g.replace(
/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
(p, m, S, y) => {
const E = String(m).toLowerCase(), L = `<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 (E === "style") {
const k = v.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (H, O, R, N) => `<span style="color: ${s.styleProp};">${O}</span>:<span style="color: ${s.styleVal};">${R.trim()}</span>${N}`);
T ? b = `${T}${k}${T}` : b = k, b = `<span style="color: ${s.attrValue};">${b}</span>`;
} else
T && (b = `${T}${v}${T}`), b = `<span style="color: ${s.attrValue};">${b}</span>`;
return `${L}${S}${b}`;
}
), `${c}${h}${g}${u}`;
}), n;

@@ -1402,29 +1502,29 @@ }

this.escapeHTML(s);
const i = [], n = (g) => {
let a = "", u = g;
const i = [], n = (u) => {
let h = "", g = u;
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);
h = String.fromCharCode(97 + g % 26) + h, g = Math.floor(g / 26) - 1;
while (g >= 0);
return h || "a";
}, o = (u) => `\0${n(u)}\0`, r = (u) => {
const h = i.length;
return i.push(u), o(h);
};
let r;
const l = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
let l;
const a = /(\/\*[\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;
for (; l = a.exec(s); ) {
const u = l.index;
c < u && (d += this.escapeHTML(s.slice(c, u)));
const h = l[0];
/^\/\*/.test(h) || /^\/\//.test(h) ? d += r(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`) : d += r(`<span style="color: ${e.string};">${this.escapeHTML(h)}</span>`), c = a.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] || "";
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, (u, h, g) => {
const p = d[g - 1] || "", m = d[g + u.length] || "";
return p === "&" || p === "#" || m === ";" || m === "#" ? u : `<span style="color: ${e.number};">${u}</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, (u, h) => {
let g = 0;
for (let p = 0; p < h.length; p++)
g = g * 26 + (h.charCodeAt(p) - 97 + 1);
return g = g - 1, i[g] || "";
});

@@ -1435,37 +1535,37 @@ }

let i = this.escapeHTML(s);
const n = [], o = (a) => {
let u = "", p = a;
const n = [], o = (h) => {
let g = "", p = h;
do
u = String.fromCharCode(97 + p % 26) + u, p = Math.floor(p / 26) - 1;
g = String.fromCharCode(97 + p % 26) + g, 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);
return g || "a";
}, r = (h) => {
const g = n.length;
return n.push(h), `\0${o(g)}\0`;
}, l = (h, g) => {
const p = i.indexOf(h);
return p === -1 ? !1 : (i = i.slice(0, p) + g + i.slice(p + h.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>`));
let a;
const c = /\/\*[\s\S]*?\*\//g, d = /\/\/[^\n\r]*/g, f = /\#([^\n\r]*)/g, u = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
for (; a = c.exec(s); ) {
const h = a[0];
l(this.escapeHTML(h), r(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</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 (; a = d.exec(s); ) {
const h = a[0];
l(this.escapeHTML(h), r(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</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 (; a = f.exec(s); ) {
const h = a[0];
l(this.escapeHTML(h), r(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`));
}
for (; l = g.exec(s); ) {
const a = l[0];
r(this.escapeHTML(a), h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`));
for (; a = u.exec(s); ) {
const h = a[0];
l(this.escapeHTML(h), r(`<span style="color: ${e.string};">${this.escapeHTML(h)}</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) => {
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, (h, g) => {
let p = 0;
for (let m = 0; m < u.length; m++)
p = p * 26 + (u.charCodeAt(m) - 97 + 1);
for (let m = 0; m < g.length; m++)
p = p * 26 + (g.charCodeAt(m) - 97 + 1);
return p = p - 1, n[p] || "";

@@ -1482,20 +1582,20 @@ }), i;

}
function _(x, t) {
function W(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);
return e.extensions || (e.extensions = []), e.extensions.some((n) => n.name === "keymap") || e.extensions.unshift(new $(e.keymap)), e.extensions.some((n) => n.name === "transaction") || e.extensions.unshift(new I()), new w(x, e);
}
export {
A as BracketMatchingExtension,
U as CodeFoldingExtension,
$ as EditorCore,
H as KeymapExtension,
N as LineNumbersExtension,
B as ReadOnlyExtension,
U as BracketMatchingExtension,
F as CodeFoldingExtension,
w as EditorCore,
$ as KeymapExtension,
B as LineNumbersExtension,
K as ReadOnlyExtension,
V as SearchExtension,
F as SyntaxHighlightingExtension,
k as TextModel,
K as ThemeExtension,
_ as SyntaxHighlightingExtension,
M as TextModel,
A as ThemeExtension,
P as View,
_ as createEditor,
$ as default
W as createEditor,
w as default
};

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

(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(`
(function(m,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(m=typeof globalThis<"u"?globalThis:m||self,T(m.LightCodeEditor={}))})(this,(function(m){"use strict";class T{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=`
`)}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),r=i.substring(0,t.start.column)+e,o=n.substring(t.end.column),l=e.split(`
`);l[0]=r+l[0],l[l.length-1]=l[l.length-1]+o,this._lines.splice(t.start.line,t.end.line-t.start.line+1,...l)}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 T;return t._lines=[...this._lines],t._version=this._version,t}}class S{constructor(t){this.gutterWidth=50,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.container=t,this.createDOM()}createDOM(){this.container.innerHTML="";const t=document.createElement("div");this.editorContainer=t,t.style.cssText=`
position: relative;

@@ -45,13 +45,21 @@ display: flex;

-moz-tab-size: 2;
`,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(`
`,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(){const t=this.contentElement.textContent||"";return!!this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`)&&t.endsWith("​")?t.slice(0,-1):t}setText(t){this.contentElement.textContent=t,this.syncTrailingNewlineMarker(t.endsWith(`
`));const e=t.split(`
`).length;this.updateLineNumbers(e)}setHTML(t){const e=/\n$/.test(t),s=/&lt;|&gt;/.test(t),i=/<span\b/i.test(t),n=/<[^>]+>/.test(t);s&&i?this.contentElement.innerHTML=t:n&&!s?this.contentElement.textContent=t:this.contentElement.innerHTML=t,this.syncTrailingNewlineMarker(e);const o=(this.contentElement.textContent||"").split(`
`).length;this.updateLineNumbers(o)}syncTrailingNewlineMarkerForText(t){this.syncTrailingNewlineMarker(t.endsWith(`
`))}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().replace(/\u200B/g,"").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=`
`),i=Math.min(t.line,s.length-1),n=Math.min(t.column,s[i]?.length||0);let r=0;for(let h=0;h<i;h++)r+=s[h].length+1;r+=n;const o=document.createRange(),l=window.getSelection();let a=0,c=null,d=0;const f=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let u;for(;u=f.nextNode();){const h=u.textContent?.length||0;if(a+h>=r){c=u,d=r-a;break}a+=h}if(c)try{o.setStart(c,d),o.setEnd(c,d),l?.removeAllRanges(),l?.addRange(o),this.ensureCaretVisible()}catch(h){console.warn("Could not set cursor position:",h)}else{const h=this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`);try{h&&h.parentNode===this.contentElement?o.setStartBefore(h):(o.selectNodeContents(this.contentElement),o.collapse(!1)),o.collapse(!0),l?.removeAllRanges(),l?.addRange(o),this.ensureCaretVisible()}catch(g){console.warn("Could not set fallback cursor position:",g)}}}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().replace(/\u200B/g,"").split(`
`),r=e.cloneRange();r.selectNodeContents(this.contentElement),r.setEnd(e.endContainer,e.endOffset);const l=r.toString().replace(/\u200B/g,"").split(`
`);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:l.length-1,column:l[l.length-1].length}}}setSelectionRange(t){this.setCursorPosition(t.start)}focus(){this.contentElement.focus(),this.ensureCaretVisible()}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}syncTrailingNewlineMarker(t){if(this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach(s=>s.remove()),!t)return;const e=document.createElement("span");e.setAttribute(this.trailingNewlineMarkerAttr,"true"),e.setAttribute("aria-hidden","true"),e.contentEditable="false",e.style.cssText=`
display: inline-block;
width: 0;
overflow: hidden;
pointer-events: none;
user-select: none;
`,e.appendChild(document.createTextNode("​")),this.contentElement.appendChild(e)}ensureCaretVisible(){const t=window.getSelection();if(!t||t.rangeCount===0)return;const e=t.getRangeAt(0).cloneRange();e.collapse(!1);let s=e.getClientRects()[0]||e.getBoundingClientRect();if((!s||s.width===0&&s.height===0)&&t.focusNode instanceof Element?s=t.focusNode.getBoundingClientRect():(!s||s.width===0&&s.height===0)&&t.focusNode?.parentElement&&(s=t.focusNode.parentElement.getBoundingClientRect()),!s)return;const i=this.editorContainer.getBoundingClientRect(),n=12;s.bottom>i.bottom-n?this.editorContainer.scrollTop+=s.bottom-(i.bottom-n):s.top<i.top+n&&(this.editorContainer.scrollTop-=i.top+n-s.top)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}const w=class w{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.highlightTimeout=null,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...e},this.textModel=new T(this.config.value),this.view=new S(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),r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:o,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(e),this.view.syncTrailingNewlineMarkerForText(e),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{const i=this.view.getText();i!==this.textModel.getText()&&this.textModel.setText(i),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),r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end));const a=r&&o!==void 0&&l!==void 0?Math.min(o,l):n;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:o,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const c=s.getRangeAt(0);c.deleteContents();const d=document.createTextNode(`
`);c.insertNode(d),c.setStartAfter(d),c.collapse(!0),s.removeAllRanges(),s.addRange(c),this.view.ensureCaretVisible();const f=this.view.getText();this.textModel.setText(f),this.view.syncTrailingNewlineMarkerForText(f);const u=Math.min(a+1,this.textModel.getText().length);try{const h=this.textModel.offsetToPosition(u);this.setCursor(h),this.view.ensureCaretVisible()}catch{}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const h=this.textModel.offsetToPosition(u);this.setCursor(h),this.view.ensureCaretVisible()}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 r=s.caseSensitive?n:n.toLowerCase(),o=s.caseSensitive?t:t.toLowerCase();if(s.regex){const l=new RegExp(o,s.caseSensitive?"g":"gi");let a;for(;(a=l.exec(r))!==null;){const c=this.textModel.offsetToPosition(a.index),d=this.textModel.offsetToPosition(a.index+a[0].length);i.push({range:{start:c,end:d},match:a[0]})}}else{let l=0,a=r.indexOf(o,l);for(;a!==-1;){const c=a+t.length,d=this.textModel.offsetToPosition(a),f=this.textModel.offsetToPosition(c);i.push({range:{start:d,end:f},match:n.substring(a,c)}),l=c,a=r.indexOf(o,l)}}return i}replace(t,e){const s=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,r=this.textModel.positionToOffset(n),o=this.getSelection();let l,a;o&&(l=this.textModel.positionToOffset(o.start),a=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:s,cursorOffset:r,anchorOffset:l,focusOffset:a}),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 r=i.length-1;r>=0;r--)this.replace(i[r].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,r,o,l;if(e||i){n=this.getSelection();const f=this.getCollapsedSelectionOffsetInEditor();if(f!==void 0)r=f;else{const u=this.getCursor().position;r=this.textModel.positionToOffset(u)}n&&(o=this.textModel.positionToOffset(n.start),l=this.textModel.positionToOffset(n.end))}const a=(e||i)&&!n&&r!==void 0&&this.hasCollapsedSelectionInEditor(),c=a?this.insertSentinelAtOffset(t,r):t,d=s.highlightHTML(c);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(d):this.view.setHTML(d),this.view.syncTrailingNewlineMarkerForText(t),(e||i)&&requestAnimationFrame(()=>{try{if(a&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(n&&(o!==void 0||l!==void 0)){const f=o!==void 0?o:r,u=l!==void 0?l:r,h=Math.min(f,u),g=Math.max(f,u),p=this.textModel.offsetToPosition(h),x=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:p,end:x})}else if(r!==void 0){const f=this.textModel.offsetToPosition(r);this.view.setCursorPosition(f)}}catch{}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(t)}hasCollapsedSelectionInEditor(){const t=window.getSelection();if(!t||t.rangeCount===0||!t.isCollapsed)return!1;const e=t.getRangeAt(0);return this.view.getContentElement().contains(e.commonAncestorContainer)}getCollapsedSelectionOffsetInEditor(){const t=window.getSelection();if(!t||t.rangeCount===0||!t.isCollapsed)return;const e=t.getRangeAt(0),s=this.view.getContentElement();if(!s.contains(e.commonAncestorContainer))return;const i=e.cloneRange();return i.selectNodeContents(s),i.setEnd(e.endContainer,e.endOffset),this.stripVirtualMarkers(i.toString()).length}stripVirtualMarkers(t){return t.replace(/\u200B/g,"").split(w.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(t,e){const s=Math.max(0,Math.min(e,t.length));return t.slice(0,s)+w.CURSOR_SENTINEL+t.slice(s)}restoreCursorFromSentinel(){const t=this.view.getContentElement(),e=window.getSelection(),s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);let i=s.nextNode(),n=null,r=0;for(;i;){const o=i.textContent??"",l=o.indexOf(w.CURSOR_SENTINEL);l!==-1&&(n||(n=i,r=l),i.textContent=o.split(w.CURSOR_SENTINEL).join("")),i=s.nextNode()}if(!n||!e)return!1;try{const o=document.createRange();return o.setStart(n,r),o.collapse(!0),e.removeAllRanges(),e.addRange(o),!0}catch{return!1}}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,r=t.focusOffset!==void 0?t.focusOffset:i,o=Math.min(n,r),l=Math.max(n,r),a=this.textModel.offsetToPosition(o),c=this.textModel.offsetToPosition(l);this.setSelection({start:a,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,r=t.focusOffset!==void 0?t.focusOffset:i,o=Math.min(n,r),l=Math.max(n,r),a=this.textModel.offsetToPosition(o),c=this.textModel.offsetToPosition(l);this.setSelection({start:a,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 r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:o,focusOffset:l}),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 r,o;n&&(r=this.textModel.positionToOffset(n.start),o=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:r,focusOffset:o}),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}};w.CURSOR_SENTINEL="";let M=w;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:r}=t,o=String(e).toLowerCase(),l=this.keymap[o];if(!l)return null;for(const a of l){const c=a.ctrlKey===void 0||a.ctrlKey===s,d=a.altKey===void 0||a.altKey===i,f=a.shiftKey===void 0||a.shiftKey===n,u=a.metaKey===void 0||a.metaKey===r;if(c&&d&&f&&u)return a}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 O{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 R{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(){if(!this.editor)return;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 N{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 P{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 ${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;

@@ -125,7 +133,7 @@ top: 10px;

" />
`;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(`
`;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"),r=this.searchUI.querySelector(".search-close");e.addEventListener("input",()=>{this.performSearch(e.value)}),e.addEventListener("keydown",o=>{o.key==="Enter"&&(o.preventDefault(),o.shiftKey?this.findPrev():this.findNext())}),s.addEventListener("keydown",o=>{o.key==="Enter"&&(o.preventDefault(),o.shiftKey?this.replaceAll(e.value,s.value):this.replaceCurrent(e.value,s.value))}),i.addEventListener("click",()=>this.findPrev()),n.addEventListener("click",()=>this.findNext()),r.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),r=this.getPositionFromOffset(e,i+t.length);s.push({range:{start:n,end:r},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),r=i.substring(0,n),o=i.substring(n+t.length),l=r+e+o;this.editor.setValue(l),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 I{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=`
`),i=e.position.line,n=e.position.column,r=e.char;return this.bracketPairs[r]?this.findClosingBracket(t,s,i,n,r):this.reverseBracketPairs[r]?this.findOpeningBracket(t,s,i,n,r):null}findClosingBracket(t,e,s,i,n){const r=this.bracketPairs[n];let o=0;for(let l=s;l<e.length;l++){const a=e[l],c=l===s?i:0;for(let d=c;d<a.length;d++){const f=a[d];if(f===n)o++;else if(f===r&&(o--,o===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:l,column:d},end:{line:l,column:d+1}},type:n}}}return null}findOpeningBracket(t,e,s,i,n){const r=this.reverseBracketPairs[n];let o=0;for(let l=s;l>=0;l--){const a=e[l],c=l===s?i:a.length-1;for(let d=c;d>=0;d--){const f=a[d];if(f===n)o++;else if(f===r&&(o--,o===0))return{open:{start:{line:l,column:d},end:{line:l,column:d+1}},close:{start:{line:s,column:i},end:{line:s,column:i+1}},type:r}}}return null}highlightBrackets(t){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class H{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;

@@ -153,2 +161,2 @@ left: 40px;

user-select: none;
`,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"}})}));
`,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 B{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=a=>this.escapeHTML(a);let n=i(t);const r=a=>{let c=a.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,u,h,g)=>{const p=String(h).trim(),x=i(p);return`<span style="color: ${s.styleProp};">${f}</span>${u}<span style="color: ${s.styleVal};">${x}</span>${g}`}),c},o=[];try{t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(a,c,d)=>(o.push({attrs:String(c||""),inner:String(d||"")}),a))}catch{}let l=0;return n=n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi,(a,c,d,f,u)=>{const h=o[l++]?.inner??this.unescapeEntitiesRepeated(f||"");(o[l-1]?.attrs||d||"").toLowerCase();const g=this._highlightJS(h,s);return`${c}${g}${u}`}),n=n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi,(a,c,d,f)=>{const u=r(d);return`${c}${u}${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,(a,c,d,f,u)=>{const h=`<span style="color: ${s.tag};">${d}</span>`;let g=f;return g=g.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,(p,x,A,b)=>{const V=String(x).toLowerCase(),U=`<span style="color: ${s.attrName};">${x}</span>`;let k=b,C="";b.startsWith("&quot;")&&b.endsWith("&quot;")?(k=b.slice(6,-6),C="&quot;"):b.startsWith("&#39;")&&b.endsWith("&#39;")&&(k=b.slice(5,-5),C="&#39;");let v=b;if(V==="style"){const L=k.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(z,F,_,W)=>`<span style="color: ${s.styleProp};">${F}</span>:<span style="color: ${s.styleVal};">${_.trim()}</span>${W}`);C?v=`${C}${L}${C}`:v=L,v=`<span style="color: ${s.attrValue};">${v}</span>`}else C&&(v=`${C}${k}${C}`),v=`<span style="color: ${s.attrValue};">${v}</span>`;return`${U}${A}${v}`}),`${c}${h}${g}${u}`}),n}_highlightJS(t,e){const s=this.unescapeEntitiesRepeated(t);this.escapeHTML(s);const i=[],n=u=>{let h="",g=u;do h=String.fromCharCode(97+g%26)+h,g=Math.floor(g/26)-1;while(g>=0);return h||"a"},r=u=>`\0${n(u)}\0`,o=u=>{const h=i.length;return i.push(u),r(h)};let l;const a=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,d="";for(;l=a.exec(s);){const u=l.index;c<u&&(d+=this.escapeHTML(s.slice(c,u)));const h=l[0];/^\/\*/.test(h)||/^\/\//.test(h)?d+=o(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`):d+=o(`<span style="color: ${e.string};">${this.escapeHTML(h)}</span>`),c=a.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,(u,h,g)=>{const p=d[g-1]||"",x=d[g+u.length]||"";return p==="&"||p==="#"||x===";"||x==="#"?u:`<span style="color: ${e.number};">${u}</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,(u,h)=>{let g=0;for(let p=0;p<h.length;p++)g=g*26+(h.charCodeAt(p)-97+1);return g=g-1,i[g]||""})}_highlightPHP(t,e){const s=this.unescapeEntitiesRepeated(t);let i=this.escapeHTML(s);const n=[],r=h=>{let g="",p=h;do g=String.fromCharCode(97+p%26)+g,p=Math.floor(p/26)-1;while(p>=0);return g||"a"},o=h=>{const g=n.length;return n.push(h),`\0${r(g)}\0`},l=(h,g)=>{const p=i.indexOf(h);return p===-1?!1:(i=i.slice(0,p)+g+i.slice(p+h.length),!0)};let a;const c=/\/\*[\s\S]*?\*\//g,d=/\/\/[^\n\r]*/g,f=/\#([^\n\r]*)/g,u=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;a=c.exec(s);){const h=a[0];l(this.escapeHTML(h),o(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`))}for(;a=d.exec(s);){const h=a[0];l(this.escapeHTML(h),o(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`))}for(;a=f.exec(s);){const h=a[0];l(this.escapeHTML(h),o(`<span style="color: ${e.comment};">${this.escapeHTML(h)}</span>`))}for(;a=u.exec(s);){const h=a[0];l(this.escapeHTML(h),o(`<span style="color: ${e.string};">${this.escapeHTML(h)}</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,(h,g)=>{let p=0;for(let x=0;x<g.length;x++)p=p*26+(g.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 K(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 O),new M(y,e)}m.BracketMatchingExtension=I,m.CodeFoldingExtension=H,m.EditorCore=M,m.KeymapExtension=E,m.LineNumbersExtension=R,m.ReadOnlyExtension=P,m.SearchExtension=$,m.SyntaxHighlightingExtension=B,m.TextModel=T,m.ThemeExtension=N,m.View=S,m.createEditor=K,m.default=M,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
{
"name": "@editora/light-code-editor",
"version": "1.0.3",
"version": "1.0.4",
"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.",

@@ -13,14 +13,21 @@ "authors": [

".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.es.js",
"require": "./dist/index.umd.js",
"types": "./dist/index.d.ts"
"require": "./dist/index.umd.js"
}
},
"files": [
"dist"
"dist/**/*.js",
"dist/**/*.css",
"dist/**/*.d.ts",
"README.md",
"CHANGELOG.md"
],
"scripts": {
"build": "vite build",
"build": "npm run build:js && npm run build:types",
"build:js": "vite build",
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly --noEmit false --outDir dist",
"dev": "vite build --watch",
"clean": "rm -rf dist"
"clean": "rm -rf dist",
"prepublishOnly": "npm run clean && npm run build"
},

@@ -27,0 +34,0 @@ "keywords": [