@editora/light-code-editor
Advanced tools
@@ -48,2 +48,6 @@ /** | ||
| search(query: string, options?: Partial<SearchOptions>): SearchResult[]; | ||
| private pushSearchResultFromOffsets; | ||
| private isWholeWordBoundary; | ||
| private isWordChar; | ||
| private buildSearchTextAndOffsetMap; | ||
| replace(range: Range, text: string): void; | ||
@@ -50,0 +54,0 @@ replaceAll(query: string, replacement: string, options?: Partial<SearchOptions>): number; |
@@ -11,4 +11,8 @@ /** | ||
| private foldingUI; | ||
| private pendingUpdateRaf; | ||
| private lastSnapshot; | ||
| private changeHandler; | ||
| setup(editor: EditorAPI): void; | ||
| private createFoldingUI; | ||
| private scheduleFoldIndicatorUpdate; | ||
| private updateFoldIndicators; | ||
@@ -15,0 +19,0 @@ private findFoldableLines; |
@@ -9,2 +9,3 @@ /** | ||
| export { SearchExtension } from './SearchExtension'; | ||
| export type { SearchExtensionConfig } from './SearchExtension'; | ||
| export { BracketMatchingExtension } from './BracketMatchingExtension'; | ||
@@ -11,0 +12,0 @@ export { CodeFoldingExtension } from './CodeFoldingExtension'; |
@@ -6,3 +6,7 @@ /** | ||
| import { EditorExtension, EditorAPI } from '../types'; | ||
| export interface SearchExtensionConfig { | ||
| replaceAndFindNext?: boolean; | ||
| } | ||
| export declare class SearchExtension implements EditorExtension { | ||
| private static readonly css; | ||
| readonly name = "search"; | ||
@@ -14,2 +18,29 @@ private editor; | ||
| private currentIndex; | ||
| private searchDebounceTimer; | ||
| private liveRefreshTimer; | ||
| private statusResetTimer; | ||
| private statusFreezeUntil; | ||
| private findInput; | ||
| private replaceInputEl; | ||
| private statusDiv; | ||
| private modeDiv; | ||
| private caseSensitiveInput; | ||
| private wholeWordInput; | ||
| private regexInput; | ||
| private currentQuery; | ||
| private savedSelection; | ||
| private savedCursor; | ||
| private editorChangeHandler; | ||
| private readonly searchOptions; | ||
| private readonly trailingMarkerAttr; | ||
| private readonly editorContainerSelector; | ||
| private readonly highlightId; | ||
| private readonly highlightMatchName; | ||
| private readonly highlightActiveName; | ||
| private readonly highlightStyleId; | ||
| private readonly maxCustomHighlightRanges; | ||
| private readonly virtualMarkerRegex; | ||
| private readonly config; | ||
| private hasCustomHighlightSupport; | ||
| constructor(config?: SearchExtensionConfig); | ||
| setup(editor: EditorAPI): void; | ||
@@ -20,4 +51,4 @@ private showSearch; | ||
| private createSearchUI; | ||
| private updateModeHint; | ||
| private performSearch; | ||
| private getPositionFromOffset; | ||
| private findNext; | ||
@@ -27,8 +58,38 @@ private findPrev; | ||
| private replaceAll; | ||
| private getOffsetFromPosition; | ||
| private updateHighlights; | ||
| private navigateToResult; | ||
| private clearHighlights; | ||
| private scrollResultIntoView; | ||
| private scrollLogicalRangeIntoView; | ||
| private restoreReplaceInputFocus; | ||
| private centerCurrentSelectionInView; | ||
| private computeReplacementRange; | ||
| private findNextResultIndexAfter; | ||
| private comparePositions; | ||
| private clampRangeToDocument; | ||
| private focusWithoutScrolling; | ||
| private findScrollContainer; | ||
| private resolveScrollContainer; | ||
| private canScroll; | ||
| private revealActiveResultAfterFocusRestore; | ||
| private applyCustomHighlights; | ||
| private buildLineStarts; | ||
| private positionToOffset; | ||
| private buildTextNodeIndex; | ||
| private resolveDomPoint; | ||
| private toDomRange; | ||
| private buildVisibleDocumentText; | ||
| private findNearestMatchOffset; | ||
| private scheduleLiveRefresh; | ||
| private updateStatus; | ||
| private showTransientStatus; | ||
| private syncMatchStatus; | ||
| private isValidRegex; | ||
| private captureSelectionState; | ||
| private restoreSelectionState; | ||
| private detectCustomHighlightSupport; | ||
| private buildVisibleToDomMap; | ||
| private ensureHighlightStyles; | ||
| destroy(): void; | ||
| } | ||
| //# sourceMappingURL=SearchExtension.d.ts.map |
+55
-87
@@ -1,6 +0,6 @@ | ||
| (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(` | ||
| (function(y,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(y=typeof globalThis<"u"?globalThis:y||self,C(y.LightCodeEditor={}))})(this,(function(y){"use strict";class C{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),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=` | ||
| `)}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,l=n.substring(t.end.column),o=e.split(` | ||
| `);o[0]=r+o[0],o[o.length-1]=o[o.length-1]+l,this._lines.splice(t.start.line,t.end.line-t.start.line+1,...o)}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 C;return t._lines=[...this._lines],t._version=this._version,t}}class I{constructor(t){this.gutterWidth=50,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.virtualMarkerRegex=/[\u200B\uE000]/,this.container=t,this.createDOM()}createDOM(){this.container.innerHTML="";const t=document.createElement("div");this.editorContainer=t,t.setAttribute("data-lce-editor-container","true"),t.style.cssText=` | ||
| position: relative; | ||
@@ -47,9 +47,10 @@ display: flex; | ||
| `));const e=t.split(` | ||
| `).length;this.updateLineNumbers(e)}setHTML(t){const e=/\n$/.test(t),s=/<|>/.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(` | ||
| `).length;this.updateLineNumbers(e)}setHTML(t){const e=/\n$/.test(t),s=/<|>/.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 l=(this.contentElement.textContent||"").split(` | ||
| `).length;this.updateLineNumbers(l)}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 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=` | ||
| `),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 l=document.createRange(),o=window.getSelection(),c=this.resolveOffsetToDomPoint(r);if(c)try{l.setStart(c.node,c.offset),l.setEnd(c.node,c.offset),o?.removeAllRanges(),o?.addRange(l),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?l.setStartBefore(h):(l.selectNodeContents(this.contentElement),l.collapse(!1)),l.collapse(!0),o?.removeAllRanges(),o?.addRange(l),this.ensureCaretVisible()}catch(a){console.warn("Could not set fallback 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().replace(/\u200B/g,"").split(` | ||
| `),r=e.cloneRange();r.selectNodeContents(this.contentElement),r.setEnd(e.endContainer,e.endOffset);const o=r.toString().replace(/\u200B/g,"").split(` | ||
| `);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:o.length-1,column:o[o.length-1].length}}}setSelectionRange(t){const s=this.getText().split(` | ||
| `),i=u=>{const f=Math.max(0,Math.min(u.line,s.length-1)),d=Math.max(0,Math.min(u.column,s[f]?s[f].length:0));let g=0;for(let m=0;m<f;m++)g+=s[m].length+1;return g+d},n=i(t.start),r=i(t.end),[l,o]=n<=r?[n,r]:[r,n],c=this.resolveOffsetToDomPoint(l),h=this.resolveOffsetToDomPoint(o);if(!c||!h)return;const a=document.createRange();try{a.setStart(c.node,c.offset),a.setEnd(h.node,h.offset);const u=window.getSelection();u?.removeAllRanges(),u?.addRange(a),this.ensureCaretVisible()}catch(u){console.warn("Could not set selection range:",u)}}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}getScrollElement(){return this.editorContainer}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; | ||
@@ -60,80 +61,47 @@ width: 0; | ||
| 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; | ||
| top: 10px; | ||
| right: 10px; | ||
| background: var(--editor-background, #1e1e1e); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 4px; | ||
| padding: 8px; | ||
| z-index: 1000; | ||
| display: none; | ||
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); | ||
| min-width: 250px; | ||
| `,this.searchUI.innerHTML=` | ||
| <div style="display: flex; align-items: center; gap: 4px; margin-bottom: 4px;"> | ||
| <input type="text" placeholder="Find..." style=" | ||
| flex: 1; | ||
| padding: 4px 8px; | ||
| background: var(--editor-gutter-background, #252526); | ||
| color: var(--editor-foreground, #f8f9fa); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 3px; | ||
| font-size: 12px; | ||
| outline: none; | ||
| " /> | ||
| <button class="search-prev" style=" | ||
| padding: 2px 6px; | ||
| background: var(--editor-gutter-background, #252526); | ||
| color: var(--editor-gutter-foreground, #858585); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 3px; | ||
| cursor: pointer; | ||
| font-size: 11px; | ||
| ">↑</button> | ||
| <button class="search-next" style=" | ||
| padding: 2px 6px; | ||
| background: var(--editor-gutter-background, #252526); | ||
| color: var(--editor-gutter-foreground, #858585); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 3px; | ||
| cursor: pointer; | ||
| font-size: 11px; | ||
| ">↓</button> | ||
| <button class="search-close" style=" | ||
| padding: 2px 6px; | ||
| background: var(--editor-gutter-background, #252526); | ||
| color: var(--editor-gutter-foreground, #858585); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 3px; | ||
| cursor: pointer; | ||
| font-size: 11px; | ||
| ">×</button> | ||
| `,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)}resolveOffsetToDomPoint(t){const e=Math.max(0,t);let s=0;const i=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let n=null,r;for(;r=i.nextNode();){if(r.parentElement?.hasAttribute(this.trailingNewlineMarkerAttr))continue;n=r;const o=r.textContent||"",c=this.buildVisibleToDomMap(o),h=Math.max(0,c.length-1);if(s+h>=e){const a=Math.max(0,e-s),u=c[a]??o.length;return{node:r,offset:u}}s+=h}if(n){const l=n.textContent?.length||0;return{node:n,offset:l}}return null}buildVisibleToDomMap(t){const e=[0];let s=0;for(let i=0;i<t.length;i++){const n=t[i];this.virtualMarkerRegex.test(n)||(s+=1,e[s]=i+1)}return e}}const S=class S{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 C(this.config.value),this.view=new I(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 l,o;r&&(l=this.textModel.positionToOffset(r.start),o=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:l,focusOffset:o}),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 l,o;r&&(l=this.textModel.positionToOffset(r.start),o=this.textModel.positionToOffset(r.end));const c=r&&l!==void 0&&o!==void 0?Math.min(l,o):n;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:l,focusOffset:o}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const h=s.getRangeAt(0);h.deleteContents();const a=document.createTextNode(` | ||
| `);h.insertNode(a),h.setStartAfter(a),h.collapse(!0),s.removeAllRanges(),s.addRange(h),this.view.ensureCaretVisible();const u=this.view.getText();this.textModel.setText(u),this.view.syncTrailingNewlineMarkerForText(u);const f=Math.min(c+1,this.textModel.getText().length);try{const d=this.textModel.offsetToPosition(f);this.setCursor(d),this.view.ensureCaretVisible()}catch{}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const d=this.textModel.offsetToPosition(f);this.setCursor(d),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={}){if(!t)return[];const s={query:t,caseSensitive:!1,wholeWord:!1,regex:!1,...e},i=[],n=this.textModel.getText(),{normalizedText:r,normalizedToRawOffsets:l}=this.buildSearchTextAndOffsetMap(n),o=s.caseSensitive?r:r.toLowerCase(),c=s.caseSensitive?t:t.toLowerCase();if(s.regex){let h;try{h=new RegExp(t,s.caseSensitive?"g":"gi")}catch{return[]}let a;for(;(a=h.exec(r))!==null;){const u=a[0]??"";if(u.length===0){h.lastIndex=a.index+1;continue}const f=a.index,d=a.index+u.length;s.wholeWord&&!this.isWholeWordBoundary(r,f,d)||this.pushSearchResultFromOffsets(i,f,d,r,l)}}else{let h=0,a=o.indexOf(c,h);for(;a!==-1;){const u=a+c.length;!s.wholeWord||this.isWholeWordBoundary(r,a,u)?(this.pushSearchResultFromOffsets(i,a,u,r,l),h=u):h=a+1,a=o.indexOf(c,h)}}return i}pushSearchResultFromOffsets(t,e,s,i,n){const r=n[e]??e,l=n[s]??r,o=this.textModel.offsetToPosition(r),c=this.textModel.offsetToPosition(l);t.push({range:{start:o,end:c},match:i.substring(e,s)})}isWholeWordBoundary(t,e,s){const i=e>0?t[e-1]:"",n=s<t.length?t[s]:"";return!this.isWordChar(i)&&!this.isWordChar(n)}isWordChar(t){return/^[A-Za-z0-9_]$/.test(t)}buildSearchTextAndOffsetMap(t){const e=[],s=[0];let i=0;for(let n=0;n<t.length;n++){const r=t[n];r===""||r===S.CURSOR_SENTINEL||(e.push(r),i+=1,s[i]=n+1)}return s[i]=t.length,{normalizedText:e.join(""),normalizedToRawOffsets:s}}replace(t,e){const s=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,r=this.textModel.positionToOffset(n),l=this.getSelection();let o,c;l&&(o=this.textModel.positionToOffset(l.start),c=this.textModel.positionToOffset(l.end)),this.undoStack.push({text:s,cursorOffset:r,anchorOffset:o,focusOffset:c}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(t,e);this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.expectingProgrammaticCursor=!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,l,o;if(e||i){n=this.getSelection();const u=this.getCollapsedSelectionOffsetInEditor();if(u!==void 0)r=u;else{const f=this.getCursor().position;r=this.textModel.positionToOffset(f)}n&&(l=this.textModel.positionToOffset(n.start),o=this.textModel.positionToOffset(n.end))}const c=(e||i)&&!n&&r!==void 0&&this.hasCollapsedSelectionInEditor(),h=c?this.insertSentinelAtOffset(t,r):t,a=s.highlightHTML(h);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(a):this.view.setHTML(a),this.view.syncTrailingNewlineMarkerForText(t),(e||i)&&requestAnimationFrame(()=>{try{if(c&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(n&&(l!==void 0||o!==void 0)){const u=l!==void 0?l:r,f=o!==void 0?o:r,d=Math.min(u,f),g=Math.max(u,f),m=this.textModel.offsetToPosition(d),x=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:m,end:x})}else if(r!==void 0){const u=this.textModel.offsetToPosition(r);this.view.setCursorPosition(u)}}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(S.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(t,e){const s=Math.max(0,Math.min(e,t.length));return t.slice(0,s)+S.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 l=i.textContent??"",o=l.indexOf(S.CURSOR_SENTINEL);o!==-1&&(n||(n=i,r=o),i.textContent=l.split(S.CURSOR_SENTINEL).join("")),i=s.nextNode()}if(!n||!e)return!1;try{const l=document.createRange();return l.setStart(n,r),l.collapse(!0),e.removeAllRanges(),e.addRange(l),!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,l=Math.min(n,r),o=Math.max(n,r),c=this.textModel.offsetToPosition(l),h=this.textModel.offsetToPosition(o);this.setSelection({start:c,end:h})}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,l=Math.min(n,r),o=Math.max(n,r),c=this.textModel.offsetToPosition(l),h=this.textModel.offsetToPosition(o);this.setSelection({start:c,end:h})}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 l,o;r&&(l=this.textModel.positionToOffset(r.start),o=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:l,focusOffset:o}),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,l;n&&(r=this.textModel.positionToOffset(n.start),l=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:r,focusOffset:l}),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}};S.CURSOR_SENTINEL="";let M=S;class N{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,l=String(e).toLowerCase(),o=this.keymap[l];if(!o)return null;for(const c of o){const h=c.ctrlKey===void 0||c.ctrlKey===s,a=c.altKey===void 0||c.altKey===i,u=c.shiftKey===void 0||c.shiftKey===n,f=c.metaKey===void 0||c.metaKey===r;if(h&&a&&u&&f)return c}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 H{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 A{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 P{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 B{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}}let V=0;const p=class p{constructor(t={}){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1,this.searchDebounceTimer=null,this.liveRefreshTimer=null,this.statusResetTimer=null,this.statusFreezeUntil=0,this.findInput=null,this.replaceInputEl=null,this.statusDiv=null,this.modeDiv=null,this.caseSensitiveInput=null,this.wholeWordInput=null,this.regexInput=null,this.currentQuery="",this.savedCursor=null,this.editorChangeHandler=null,this.searchOptions={caseSensitive:!1,wholeWord:!1,regex:!1},this.trailingMarkerAttr="data-lce-trailing-newline-marker",this.editorContainerSelector='[data-lce-editor-container="true"]',this.highlightId=++V,this.highlightMatchName=`editora-search-match-${this.highlightId}`,this.highlightActiveName=`editora-search-active-${this.highlightId}`,this.highlightStyleId=`editora-search-highlight-style-${this.highlightId}`,this.maxCustomHighlightRanges=2e3,this.virtualMarkerRegex=/[\u200B\uE000]/,this.hasCustomHighlightSupport=!1,this.config={replaceAndFindNext:!0,...t}}setup(t){this.editor=t,this.hasCustomHighlightSupport=this.detectCustomHighlightSupport(),this.hasCustomHighlightSupport&&this.ensureHighlightStyles(),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)}),this.editorChangeHandler=()=>{!this.isVisible||!this.currentQuery||this.scheduleLiveRefresh(!0)},t.on("change",this.editorChangeHandler)}showSearch(){this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible||this.captureSelectionState(),this.isVisible=!0,this.searchUI&&(this.searchUI.style.display="block",this.updateModeHint(!1),this.findInput&&(this.findInput.focus(),this.findInput.select())),this.currentQuery&&this.performSearch(this.currentQuery,!0,!1))}showReplace(){this.showSearch(),this.replaceInputEl&&(this.replaceInputEl.style.display="block",this.replaceInputEl.focus()),this.updateModeHint(!0),this.currentQuery&&this.performSearch(this.currentQuery,!1,!0)}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.replaceInputEl&&(this.replaceInputEl.style.display="none",this.replaceInputEl.value=""),this.updateModeHint(!1),this.clearHighlights(),this.restoreSelectionState()}createSearchUI(){if(!this.editor)return;const t=this.editor.getView().getContentElement(),e=t.closest(this.editorContainerSelector),s=t.closest(".rte-source-editor-modal")||e||t.parentElement;if(!s)return;window.getComputedStyle(s).position==="static"&&(s.style.position="relative"),this.searchUI=document.createElement("div"),this.searchUI.className=p.css.root,this.searchUI.style.display="none",this.searchUI.innerHTML=` | ||
| <div class="${p.css.row}"> | ||
| <input type="text" class="${p.css.findInput} ${p.css.inputBase}" placeholder="Find..." /> | ||
| <button class="${p.css.prevButton} ${p.css.buttonBase}" type="button" aria-label="Previous match">↑</button> | ||
| <button class="${p.css.nextButton} ${p.css.buttonBase}" type="button" aria-label="Next match">↓</button> | ||
| <button class="${p.css.closeButton} ${p.css.buttonBase}" type="button" aria-label="Close search">×</button> | ||
| </div> | ||
| <div class="search-status" style=" | ||
| font-size: 11px; | ||
| color: var(--editor-gutter-foreground, #858585); | ||
| text-align: center; | ||
| "></div> | ||
| <input type="text" class="search-replace-input" placeholder="Replace with..." style=" | ||
| width: 100%; | ||
| padding: 4px 8px; | ||
| background: var(--editor-gutter-background, #252526); | ||
| color: var(--editor-foreground, #f8f9fa); | ||
| border: 1px solid var(--editor-gutter-border, #3e3e42); | ||
| border-radius: 3px; | ||
| font-size: 12px; | ||
| outline: none; | ||
| display: none; | ||
| margin-top: 4px; | ||
| " /> | ||
| `;const 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(` | ||
| <div class="${p.css.options}"> | ||
| <label class="${p.css.optionLabel}" title="Case sensitive"> | ||
| <input type="checkbox" class="${p.css.optionInput} ${p.css.caseSensitive}" /> | ||
| <span>Aa</span> | ||
| </label> | ||
| <label class="${p.css.optionLabel}" title="Whole word"> | ||
| <input type="checkbox" class="${p.css.optionInput} ${p.css.wholeWord}" /> | ||
| <span>Whole</span> | ||
| </label> | ||
| <label class="${p.css.optionLabel}" title="Regular expression"> | ||
| <input type="checkbox" class="${p.css.optionInput} ${p.css.regex}" /> | ||
| <span>.*</span> | ||
| </label> | ||
| </div> | ||
| <div class="${p.css.meta}"> | ||
| <div class="${p.css.status} ${p.css.statusLayout}"></div> | ||
| <div class="${p.css.mode} ${p.css.modeLayout}" aria-live="polite"></div> | ||
| </div> | ||
| <input type="text" class="${p.css.replaceInput} ${p.css.inputBase} ${p.css.replaceInputLayout}" placeholder="Replace with..." /> | ||
| `;const i=this.searchUI.querySelector(`.${p.css.findInput}`),n=this.searchUI.querySelector(`.${p.css.replaceInput}`),r=this.searchUI.querySelector(`.${p.css.prevButton}`),l=this.searchUI.querySelector(`.${p.css.nextButton}`),o=this.searchUI.querySelector(`.${p.css.closeButton}`),c=this.searchUI.querySelector(`.${p.css.status}`),h=this.searchUI.querySelector(`.${p.css.mode}`),a=this.searchUI.querySelector(`.${p.css.caseSensitive}`),u=this.searchUI.querySelector(`.${p.css.wholeWord}`),f=this.searchUI.querySelector(`.${p.css.regex}`);this.findInput=i,this.replaceInputEl=n,this.statusDiv=c,this.modeDiv=h,this.caseSensitiveInput=a,this.wholeWordInput=u,this.regexInput=f,a.checked=!!this.searchOptions.caseSensitive,u.checked=!!this.searchOptions.wholeWord,f.checked=!!this.searchOptions.regex,i.addEventListener("input",()=>{this.searchDebounceTimer&&clearTimeout(this.searchDebounceTimer);const g=i.value;this.searchDebounceTimer=setTimeout(()=>{this.performSearch(g,!1,!1)},120)});const d=()=>{this.searchOptions.caseSensitive=a.checked,this.searchOptions.wholeWord=u.checked,this.searchOptions.regex=f.checked;const g=i.value;g.trim()?this.performSearch(g,!1,!1):this.performSearch("",!1,!1)};a.addEventListener("change",d),u.addEventListener("change",d),f.addEventListener("change",d),i.addEventListener("keydown",g=>{g.key==="Enter"?(g.preventDefault(),g.shiftKey?this.findPrev():this.findNext()):g.key==="Escape"&&(g.preventDefault(),this.hideSearch())}),n.addEventListener("keydown",g=>{g.key==="Enter"?(g.preventDefault(),g.shiftKey?this.replaceAll(i.value,n.value):this.replaceCurrent(i.value,n.value)):g.key==="Escape"&&(g.preventDefault(),this.hideSearch())}),r.addEventListener("click",()=>this.findPrev()),l.addEventListener("click",()=>this.findNext()),o.addEventListener("click",()=>this.hideSearch()),s.appendChild(this.searchUI)}updateModeHint(t){this.modeDiv&&(this.modeDiv.textContent=t?`Replace: move next ${this.config.replaceAndFindNext?"ON":"OFF"}`:"Find mode")}performSearch(t,e,s){if(!this.editor||!t.trim()){this.currentQuery="",this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("");return}if(this.searchOptions.regex&&!this.isValidRegex(t)){this.currentQuery=t,this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Invalid regular expression");return}this.currentQuery=t;const i=this.currentIndex,n=this.editor.search(t,this.searchOptions);if(this.currentResults=n,n.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("No matches");return}e&&i>=0?this.currentIndex=Math.min(i,n.length-1):this.currentIndex=0,this.updateHighlights(s)}findNext(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights(!0)}findPrev(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights(!0)}replaceCurrent(t,e){if(!this.editor||!t.trim()||((this.currentQuery!==t||this.currentResults.length===0)&&this.performSearch(t,!1,!0),this.currentIndex<0||this.currentResults.length===0))return;const s=this.currentResults[this.currentIndex];if(!s)return;const i=this.computeReplacementRange(s.range.start,e);if(this.editor.replace(s.range,e),this.config.replaceAndFindNext){this.currentQuery=t;const n=this.editor.search(t,this.searchOptions);if(this.currentResults=n,n.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Replaced current occurrence"),this.restoreReplaceInputFocus();return}this.currentIndex=this.findNextResultIndexAfter(i.end,n),this.updateHighlights(!0)}else this.scrollLogicalRangeIntoView(i,!0),this.performSearch(t,!0,!1);this.currentResults.length>0||this.showTransientStatus("Replaced current occurrence"),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}replaceAll(t,e){if(!this.editor||!t.trim())return;const s=this.editor.replaceAll(t,e,this.searchOptions);this.performSearch(t,!1,!1),this.showTransientStatus(`Replaced ${s} occurrence${s===1?"":"s"}`),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}updateHighlights(t){if(this.clearHighlights(),this.currentResults.length===0||this.currentIndex===-1||!this.editor)return;this.applyCustomHighlights();const e=this.currentResults[this.currentIndex];e&&((t||!this.hasCustomHighlightSupport)&&this.navigateToResult(e,!this.hasCustomHighlightSupport),this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}navigateToResult(t,e){if(!this.editor)return;const s=document.activeElement,i=!!s&&(s===this.findInput||s===this.replaceInputEl);e?(this.editor.setSelection(t.range),this.centerCurrentSelectionInView()):this.scrollResultIntoView(t);const n=this.editor.getView();e&&typeof n.ensureCaretVisible=="function"&&n.ensureCaretVisible(),e&&i&&s&&requestAnimationFrame(()=>{this.focusWithoutScrolling(s)})}clearHighlights(){if(this.hasCustomHighlightSupport)try{const t=CSS;t.highlights?.delete(this.highlightMatchName),t.highlights?.delete(this.highlightActiveName)}catch{}}scrollResultIntoView(t){this.scrollLogicalRangeIntoView(t.range,!0)}scrollLogicalRangeIntoView(t,e){if(!this.editor)return;const s=this.editor.getView().getContentElement(),i=this.editor.getValue(),{lineStarts:n,lines:r}=this.buildLineStarts(i),l=this.buildTextNodeIndex(s);if(l.length===0)return;const o=this.toDomRange(t,n,r,l);if(!o)return;const c=o.startContainer.nodeType===Node.TEXT_NODE?o.startContainer.parentElement:o.startContainer,h=this.resolveScrollContainer(s);if(h){const a=o.getClientRects()[0]||o.getBoundingClientRect(),u=h.getBoundingClientRect(),d=h.scrollTop+(a.top-u.top)-u.height/2+a.height/2,g=18;let m=e?d:h.scrollTop,x=h.scrollLeft;const R=h.scrollLeft+(a.left-u.left),v=R+a.width;a.right>u.right-g?x=v-u.width+g:a.left<u.left+g&&(x=Math.max(0,R-g));const E=Math.max(0,h.scrollHeight-h.clientHeight),k=Math.max(0,h.scrollWidth-h.clientWidth);if(m=Math.min(E,Math.max(0,m)),x=Math.min(k,Math.max(0,x)),E===0&&k===0){c?.scrollIntoView({block:e?"center":"nearest",inline:"nearest",behavior:"smooth"});return}(m!==h.scrollTop||x!==h.scrollLeft)&&h.scrollTo({top:m,left:x,behavior:"smooth"});return}c?.scrollIntoView({block:e?"center":"nearest",inline:"nearest",behavior:"smooth"})}restoreReplaceInputFocus(){const t=this.replaceInputEl;!t||t.style.display==="none"||requestAnimationFrame(()=>{this.focusWithoutScrolling(t);const e=t.value.length;try{t.setSelectionRange(e,e)}catch{}})}centerCurrentSelectionInView(){if(!this.editor)return;const t=this.editor.getView().getContentElement(),e=this.resolveScrollContainer(t);if(!e)return;const s=window.getSelection();if(!s||s.rangeCount===0)return;const i=s.getRangeAt(0).cloneRange(),n=i.getClientRects()[0]||i.getBoundingClientRect();if(!n)return;const r=e.getBoundingClientRect(),o=e.scrollTop+(n.top-r.top)-r.height/2+n.height/2,c=Math.max(0,e.scrollHeight-e.clientHeight),h=Math.min(c,Math.max(0,o));h!==e.scrollTop&&e.scrollTo({top:h,behavior:"smooth"})}computeReplacementRange(t,e){const s=e.replace(/\r\n?/g,` | ||
| `),i=s.split(` | ||
| `);let n;return i.length<=1?(n={start:t,end:{line:t.line,column:t.column+s.length}},this.clampRangeToDocument(n)):(n={start:t,end:{line:t.line+i.length-1,column:i[i.length-1].length}},this.clampRangeToDocument(n))}findNextResultIndexAfter(t,e){for(let s=0;s<e.length;s++)if(this.comparePositions(e[s].range.start,t)>=0)return s;return 0}comparePositions(t,e){return t.line!==e.line?t.line-e.line:t.column-e.column}clampRangeToDocument(t){const e=this.editor;if(!e)return t;const s=e.getValue().split(` | ||
| `),i=Math.max(0,s.length-1),n=Math.max(0,Math.min(t.start.line,i)),r=Math.max(0,Math.min(t.end.line,i)),l=Math.max(0,Math.min(t.start.column,s[n]?.length||0)),o=Math.max(0,Math.min(t.end.column,s[r]?.length||0));return{start:{line:n,column:l},end:{line:r,column:o}}}focusWithoutScrolling(t){try{t.focus({preventScroll:!0})}catch{const e=[];let s=t.parentElement;for(;s;)this.canScroll(s)&&e.push({el:s,top:s.scrollTop,left:s.scrollLeft}),s=s.parentElement;const i=window.scrollX,n=window.scrollY;t.focus();for(let r=0;r<e.length;r++){const l=e[r];l.el.scrollTop=l.top,l.el.scrollLeft=l.left}window.scrollTo(i,n)}}findScrollContainer(t){let e=t;for(;e;){const i=window.getComputedStyle(e).overflowY;if((i==="auto"||i==="scroll")&&e.scrollHeight>e.clientHeight)return e;e=e.parentElement}return null}resolveScrollContainer(t){const s=this.editor?.getView()?.getScrollElement?.()||null;return s&&this.canScroll(s)?s:this.findScrollContainer(t)}canScroll(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth}revealActiveResultAfterFocusRestore(){!this.currentResults.length||this.currentIndex<0||requestAnimationFrame(()=>{const t=this.currentResults[this.currentIndex];t&&this.scrollResultIntoView(t)})}applyCustomHighlights(){if(!this.editor||!this.hasCustomHighlightSupport||this.currentResults.length===0)return;const t=this.editor.getView().getContentElement(),e=this.editor.getValue(),{lineStarts:s,lines:i}=this.buildLineStarts(e),n=this.buildTextNodeIndex(t);if(n.length===0)return;const r=this.buildVisibleDocumentText(n),l=[];let o=null;const c=Math.min(this.currentResults.length,this.maxCustomHighlightRanges);for(let h=0;h<c;h++){const a=this.currentResults[h],u=this.searchOptions.regex?a.match||this.currentQuery:this.currentQuery||a.match,f=this.toDomRange(a.range,s,i,n,r,u);f&&(l.push(f),h===this.currentIndex&&(o=f))}if(l.length!==0)try{const h=CSS,a=window.Highlight;if(!h.highlights||!a)return;h.highlights.set(this.highlightMatchName,new a(...l)),o&&h.highlights.set(this.highlightActiveName,new a(o))}catch{}}buildLineStarts(t){const e=t.split(` | ||
| `),s=new Array(e.length);let i=0;for(let n=0;n<e.length;n++)s[n]=i,i+=e[n].length+1;return{lineStarts:s,lines:e}}positionToOffset(t,e,s){const i=Math.max(0,Math.min(t.line,s.length-1)),n=Math.max(0,Math.min(t.column,s[i]?.length||0));return e[i]+n}buildTextNodeIndex(t){const e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null),s=[];let i=0,n;for(;n=e.nextNode();){const r=n;if(r.parentElement?.hasAttribute(this.trailingMarkerAttr))continue;const o=r.textContent||"",c=this.buildVisibleToDomMap(o),h=Math.max(0,c.length-1);h===0&&o.length===0||(s.push({node:r,start:i,end:i+h,visibleToDom:c}),i+=h)}return s}resolveDomPoint(t,e){const s=Math.max(0,t);for(let n=0;n<e.length;n++){const r=e[n];if(s<=r.end){const l=Math.max(0,s-r.start),o=r.visibleToDom[l]??r.node.textContent?.length??0;return{node:r.node,offset:o}}}const i=e[e.length-1];return i?{node:i.node,offset:i.visibleToDom[i.visibleToDom.length-1]??i.node.textContent?.length??0}:null}toDomRange(t,e,s,i,n,r){const l=this.positionToOffset(t.start,e,s),o=this.positionToOffset(t.end,e,s);let c=Math.min(l,o),h=Math.max(l,o);if(n&&r){const d=r,g=n.slice(c,h);if(g.length===d.length&&g.toLowerCase()!==d.toLowerCase()){const m=this.findNearestMatchOffset(n,d,c);m!==-1&&(c=m,h=m+d.length)}}const a=this.resolveDomPoint(c,i),u=this.resolveDomPoint(h,i);if(!a||!u)return null;const f=document.createRange();try{return f.setStart(a.node,a.offset),f.setEnd(u.node,u.offset),f}catch{return null}}buildVisibleDocumentText(t){let e="";for(let s=0;s<t.length;s++){const i=t[s].node.textContent||"";for(let n=0;n<i.length;n++){const r=i[n];this.virtualMarkerRegex.test(r)||(e+=r)}}return e}findNearestMatchOffset(t,e,s){const i=e.toLowerCase();let n=t.toLowerCase().indexOf(i);if(n===-1)return-1;let r=n,l=Math.abs(n-s);for(;n!==-1;){const o=Math.abs(n-s);if(o<l&&(l=o,r=n),o===0)return n;n=t.toLowerCase().indexOf(i,n+1)}return r}scheduleLiveRefresh(t){this.liveRefreshTimer&&clearTimeout(this.liveRefreshTimer);const e=this.currentQuery;this.liveRefreshTimer=setTimeout(()=>{!this.isVisible||!e||this.performSearch(e,t,!1)},90)}updateStatus(t,e=!1){if(this.statusDiv){if(!e&&Date.now()<this.statusFreezeUntil)return;this.statusDiv.textContent=t}}showTransientStatus(t,e=900){this.statusFreezeUntil=Date.now()+e,this.updateStatus(t,!0),this.statusResetTimer&&clearTimeout(this.statusResetTimer),this.statusResetTimer=setTimeout(()=>{this.statusFreezeUntil=0,this.syncMatchStatus()},e)}syncMatchStatus(){if(!this.currentQuery){this.updateStatus("",!0);return}if(this.currentResults.length===0||this.currentIndex<0){this.updateStatus("No matches",!0);return}this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`,!0)}isValidRegex(t){try{const e=this.searchOptions.caseSensitive?"g":"gi";return new RegExp(t,e),!0}catch{return!1}}captureSelectionState(){this.editor&&(this.savedSelection=this.editor.getSelection(),this.savedCursor=this.editor.getCursor().position)}restoreSelectionState(){this.editor&&(this.savedSelection?this.editor.setSelection(this.savedSelection):this.savedCursor&&this.editor.setCursor(this.savedCursor),this.savedSelection=void 0,this.savedCursor=null)}detectCustomHighlightSupport(){try{const t=CSS,e=window.Highlight;return!!t.highlights&&!!e}catch{return!1}}buildVisibleToDomMap(t){const e=[0];let s=0;for(let i=0;i<t.length;i++){const n=t[i];this.virtualMarkerRegex.test(n)||(s+=1,e[s]=i+1)}return e}ensureHighlightStyles(){if(document.getElementById(this.highlightStyleId))return;const t=document.createElement("style");t.id=this.highlightStyleId,t.textContent=` | ||
| ::highlight(${this.highlightMatchName}) { | ||
| background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34)); | ||
| border-radius: 2px; | ||
| } | ||
| ::highlight(${this.highlightActiveName}) { | ||
| background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45)); | ||
| border-radius: 2px; | ||
| } | ||
| `,document.head.appendChild(t)}destroy(){this.searchDebounceTimer&&(clearTimeout(this.searchDebounceTimer),this.searchDebounceTimer=null),this.liveRefreshTimer&&(clearTimeout(this.liveRefreshTimer),this.liveRefreshTimer=null),this.statusResetTimer&&(clearTimeout(this.statusResetTimer),this.statusResetTimer=null),this.clearHighlights(),this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.editor&&this.editorChangeHandler&&this.editor.off("change",this.editorChangeHandler),this.editorChangeHandler=null,this.findInput=null,this.replaceInputEl=null,this.statusDiv=null,this.modeDiv=null,this.caseSensitiveInput=null,this.wholeWordInput=null,this.regexInput=null,this.searchUI=null;const t=document.getElementById(this.highlightStyleId);t?.parentNode&&t.parentNode.removeChild(t),this.editor=null}};p.css={root:"lce-search-ui",row:"lce-search-row",options:"lce-search-options",optionLabel:"lce-search-option",optionInput:"lce-search-option-input",caseSensitive:"search-case-sensitive",wholeWord:"search-whole-word",regex:"search-regex",meta:"lce-search-meta",findInput:"search-find-input",replaceInput:"search-replace-input",inputBase:"lce-search-input",replaceInputLayout:"lce-search-replace",prevButton:"search-prev",nextButton:"search-next",closeButton:"search-close",buttonBase:"lce-search-btn",status:"search-status",statusLayout:"lce-search-status",mode:"search-mode",modeLayout:"lce-search-mode"};let O=p;class D{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,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=` | ||
| `),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 l=0;for(let o=s;o<e.length;o++){const c=e[o],h=o===s?i:0;for(let a=h;a<c.length;a++){const u=c[a];if(u===n)l++;else if(u===r&&(l--,l===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:o,column:a},end:{line:o,column:a+1}},type:n}}}return null}findOpeningBracket(t,e,s,i,n){const r=this.reverseBracketPairs[n];let l=0;for(let o=s;o>=0;o--){const c=e[o],h=o===s?i:c.length-1;for(let a=h;a>=0;a--){const u=c[a];if(u===n)l++;else if(u===r&&(l--,l===0))return{open:{start:{line:o,column:a},end:{line:o,column:a+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 F{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.changeHandler=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()}),this.changeHandler=()=>{this.scheduleFoldIndicatorUpdate()},t.on("change",this.changeHandler),this.createFoldingUI(),this.scheduleFoldIndicatorUpdate()}createFoldingUI(){if(!this.editor)return;const t=this.editor.getView().getContentElement(),e=t.closest(".rte-source-editor-modal")||t.parentElement;e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=` | ||
| position: absolute; | ||
@@ -146,4 +114,4 @@ left: 40px; | ||
| z-index: 2; | ||
| `,t.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const e=this.editor.getValue().split(` | ||
| `);this.findFoldableLines(e).forEach(i=>{this.createFoldIndicator(i)})}findFoldableLines(t){const e=[];for(let s=0;s<t.length;s++){const i=t[s].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&e.push(s)}return e}createFoldIndicator(t){if(!this.foldingUI)return;const e=document.createElement("div");e.style.cssText=` | ||
| `,e.appendChild(this.foldingUI))}scheduleFoldIndicatorUpdate(){this.pendingUpdateRaf===null&&(this.pendingUpdateRaf=requestAnimationFrame(()=>{this.pendingUpdateRaf=null,this.updateFoldIndicators()}))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;const t=this.editor.getValue();if(t===this.lastSnapshot)return;this.lastSnapshot=t,this.foldingUI.innerHTML="",this.foldIndicators=[];const e=t.split(` | ||
| `),s=this.findFoldableLines(e),i=document.createDocumentFragment();s.forEach(n=>{const r=this.createFoldIndicator(n);i.appendChild(r),this.foldIndicators.push(r)}),this.foldingUI.appendChild(i)}findFoldableLines(t){const e=[];for(let s=0;s<t.length;s++){const i=t[s].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&e.push(s)}return e}createFoldIndicator(t){const e=document.createElement("div");return e.style.cssText=` | ||
| position: absolute; | ||
@@ -162,2 +130,2 @@ left: 0; | ||
| 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 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,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(t){let e=t||"";for(let s=0;s<5;s++){const i=e;if(e=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/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(/"/g,'"').replace(/'/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(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/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(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(a,c,d,f)=>{const u=r(d);return`${c}${u}${f}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${s.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${s.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/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*)(("[\s\S]*?"|'[\s\S]*?'|[^\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(""")&&b.endsWith(""")?(k=b.slice(6,-6),C="""):b.startsWith("'")&&b.endsWith("'")&&(k=b.slice(5,-5),C="'");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"}})})); | ||
| `,e.innerHTML="▶",e.title="Code folding not yet implemented - click shows fold indicators",e.addEventListener("click",()=>{}),e}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.pendingUpdateRaf!==null&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.changeHandler=null,this.lastSnapshot="",this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class U{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,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(t){let e=t||"";for(let s=0;s<5;s++){const i=e;if(e=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),e===i)break}return e}_highlightHTML(t,e){const s=e,i=c=>this.escapeHTML(c);let n=i(t);const r=c=>{let h=c.replace(/"/g,'"').replace(/'/g,"'");return h=h.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${s.comment};">$1</span>`),h=h.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(a,u,f,d,g)=>{const m=String(d).trim(),x=i(m);return`<span style="color: ${s.styleProp};">${u}</span>${f}<span style="color: ${s.styleVal};">${x}</span>${g}`}),h},l=[];try{t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(c,h,a)=>(l.push({attrs:String(h||""),inner:String(a||"")}),c))}catch{}let o=0;return n=n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(c,h,a,u,f)=>{const d=l[o++]?.inner??this.unescapeEntitiesRepeated(u||"");(l[o-1]?.attrs||a||"").toLowerCase();const g=this._highlightJS(d,s);return`${h}${g}${f}`}),n=n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(c,h,a,u)=>{const f=r(a);return`${h}${f}${u}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${s.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${s.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(c,h,a,u,f)=>{const d=`<span style="color: ${s.tag};">${a}</span>`;let g=u;return g=g.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(m,x,R,v)=>{const E=String(x).toLowerCase(),k=`<span style="color: ${s.attrName};">${x}</span>`;let L=v,w="";v.startsWith(""")&&v.endsWith(""")?(L=v.slice(6,-6),w="""):v.startsWith("'")&&v.endsWith("'")&&(L=v.slice(5,-5),w="'");let b=v;if(E==="style"){const $=L.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(q,K,z,Q)=>`<span style="color: ${s.styleProp};">${K}</span>:<span style="color: ${s.styleVal};">${z.trim()}</span>${Q}`);w?b=`${w}${$}${w}`:b=$,b=`<span style="color: ${s.attrValue};">${b}</span>`}else w&&(b=`${w}${L}${w}`),b=`<span style="color: ${s.attrValue};">${b}</span>`;return`${k}${R}${b}`}),`${h}${d}${g}${f}`}),n}_highlightJS(t,e){const s=this.unescapeEntitiesRepeated(t);this.escapeHTML(s);const i=[],n=f=>{let d="",g=f;do d=String.fromCharCode(97+g%26)+d,g=Math.floor(g/26)-1;while(g>=0);return d||"a"},r=f=>`\0${n(f)}\0`,l=f=>{const d=i.length;return i.push(f),r(d)};let o;const c=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let h=0,a="";for(;o=c.exec(s);){const f=o.index;h<f&&(a+=this.escapeHTML(s.slice(h,f)));const d=o[0];/^\/\*/.test(d)||/^\/\//.test(d)?a+=l(`<span style="color: ${e.comment};">${this.escapeHTML(d)}</span>`):a+=l(`<span style="color: ${e.string};">${this.escapeHTML(d)}</span>`),h=c.lastIndex}return h<s.length&&(a+=this.escapeHTML(s.slice(h))),a=a.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(f,d,g)=>{const m=a[g-1]||"",x=a[g+f.length]||"";return m==="&"||m==="#"||x===";"||x==="#"?f:`<span style="color: ${e.number};">${f}</span>`}),a=a.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>`),a.replace(/\u0000([a-z]+)\u0000/g,(f,d)=>{let g=0;for(let m=0;m<d.length;m++)g=g*26+(d.charCodeAt(m)-97+1);return g=g-1,i[g]||""})}_highlightPHP(t,e){const s=this.unescapeEntitiesRepeated(t);let i=this.escapeHTML(s);const n=[],r=d=>{let g="",m=d;do g=String.fromCharCode(97+m%26)+g,m=Math.floor(m/26)-1;while(m>=0);return g||"a"},l=d=>{const g=n.length;return n.push(d),`\0${r(g)}\0`},o=(d,g)=>{const m=i.indexOf(d);return m===-1?!1:(i=i.slice(0,m)+g+i.slice(m+d.length),!0)};let c;const h=/\/\*[\s\S]*?\*\//g,a=/\/\/[^\n\r]*/g,u=/\#([^\n\r]*)/g,f=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;c=h.exec(s);){const d=c[0];o(this.escapeHTML(d),l(`<span style="color: ${e.comment};">${this.escapeHTML(d)}</span>`))}for(;c=a.exec(s);){const d=c[0];o(this.escapeHTML(d),l(`<span style="color: ${e.comment};">${this.escapeHTML(d)}</span>`))}for(;c=u.exec(s);){const d=c[0];o(this.escapeHTML(d),l(`<span style="color: ${e.comment};">${this.escapeHTML(d)}</span>`))}for(;c=f.exec(s);){const d=c[0];o(this.escapeHTML(d),l(`<span style="color: ${e.string};">${this.escapeHTML(d)}</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,(d,g)=>{let m=0;for(let x=0;x<g.length;x++)m=m*26+(g.charCodeAt(x)-97+1);return m=m-1,n[m]||""}),i}shouldHighlight(t){return/<\/?[\w:-]+|<!--/.test(t)}destroy(){this.editor=null,this.modes.clear()}}function W(T,t){const e={...t};return e.extensions||(e.extensions=[]),e.extensions.some(n=>n.name==="keymap")||e.extensions.unshift(new N(e.keymap)),e.extensions.some(n=>n.name==="transaction")||e.extensions.unshift(new H),new M(T,e)}y.BracketMatchingExtension=D,y.CodeFoldingExtension=F,y.EditorCore=M,y.KeymapExtension=N,y.LineNumbersExtension=A,y.ReadOnlyExtension=B,y.SearchExtension=O,y.SyntaxHighlightingExtension=U,y.TextModel=C,y.ThemeExtension=P,y.View=I,y.createEditor=W,y.default=M,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})); |
@@ -1,1 +0,1 @@ | ||
| .rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}.editor-container{font-family:monospace;background-color:#1e1e1e;color:#d4d4d4;padding:10px;border:1px solid #333;border-radius:4px;overflow:auto}.editor-line{white-space:pre}.editor-line-number{display:inline-block;width:30px;text-align:right;margin-right:10px;color:#858585} | ||
| .rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}.editor-container{font-family:monospace;background-color:#1e1e1e;color:#d4d4d4;padding:10px;border:1px solid #333;border-radius:4px;overflow:auto}.editor-line{white-space:pre}.editor-line-number{display:inline-block;width:30px;text-align:right;margin-right:10px;color:#858585}.lce-search-ui{position:absolute;top:12px;right:12px;z-index:1000;min-width:250px;max-width:min(320px,calc(100% - 24px));box-sizing:border-box;border-radius:6px;border:1px solid var(--editor-gutter-border, #3e3e42);background:var(--editor-background, #1e1e1e);box-shadow:0 8px 20px #0000003d;padding:8px}.lce-search-row{display:flex;align-items:center;gap:6px;margin-bottom:6px}.lce-search-options{display:flex;align-items:center;gap:8px;margin:2px 0 6px}.lce-search-option{display:inline-flex;align-items:center;gap:4px;color:var(--editor-gutter-foreground, #858585);font-size:11px;line-height:1.2;-webkit-user-select:none;user-select:none;cursor:pointer}.lce-search-option-input{margin:0;accent-color:var(--editor-cursor, #007acc)}.lce-search-meta{display:flex;align-items:center;justify-content:space-between;gap:8px}.lce-search-input{appearance:none;width:100%;min-width:0;height:30px;padding:6px 10px;box-sizing:border-box;border-radius:4px;border:1px solid var(--editor-gutter-border, #3e3e42);background:var(--editor-gutter-background, #252526);color:var(--editor-foreground, #f8f9fa);font-size:12px;line-height:1.4;outline:none}.lce-search-input:focus{border-color:var(--editor-cursor, #007acc);box-shadow:0 0 0 2px #007acc33}.lce-search-replace{display:none;margin-top:8px}.lce-search-btn{appearance:none;width:28px;min-width:28px;height:28px;padding:0;border-radius:4px;border:1px solid var(--editor-gutter-border, #3e3e42);background:var(--editor-gutter-background, #252526);color:var(--editor-gutter-foreground, #858585);font-size:12px;line-height:1;cursor:pointer}.lce-search-btn:hover{color:var(--editor-foreground, #f8f9fa)}.lce-search-status{min-height:16px;margin:2px 2px 0;color:var(--editor-gutter-foreground, #858585);font-size:11px;line-height:1.35;text-align:left;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.lce-search-mode{min-height:16px;margin:2px 2px 0;color:var(--editor-gutter-foreground, #858585);font-size:11px;line-height:1.35;white-space:nowrap;opacity:.9} |
+1
-0
@@ -121,2 +121,3 @@ /** | ||
| setScrollTop(scrollTop: number): void; | ||
| getScrollElement(): HTMLElement; | ||
| updateLineNumbers(lineCount: number): void; | ||
@@ -123,0 +124,0 @@ destroy(): void; |
+4
-0
@@ -15,2 +15,3 @@ /** | ||
| private readonly trailingNewlineMarkerAttr; | ||
| private readonly virtualMarkerRegex; | ||
| constructor(container: HTMLElement); | ||
@@ -35,2 +36,3 @@ private createDOM; | ||
| getScrollTop(): number; | ||
| getScrollElement(): HTMLElement; | ||
| setScrollTop(scrollTop: number): void; | ||
@@ -40,3 +42,5 @@ private syncTrailingNewlineMarker; | ||
| destroy(): void; | ||
| private resolveOffsetToDomPoint; | ||
| private buildVisibleToDomMap; | ||
| } | ||
| //# sourceMappingURL=View.d.ts.map |
+1
-1
| { | ||
| "name": "@editora/light-code-editor", | ||
| "version": "1.0.5", | ||
| "version": "1.0.6", | ||
| "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.", | ||
@@ -5,0 +5,0 @@ "authors": [ |
+15
-1
@@ -165,6 +165,20 @@ # Light Code Editor | ||
| const editor = createEditor(container, { | ||
| extensions: [new SearchExtension()] | ||
| extensions: [ | ||
| new SearchExtension({ | ||
| // Replace mode defaults to true and advances to the next match | ||
| // after each Enter press in the replace field. | ||
| replaceAndFindNext: true | ||
| }) | ||
| ] | ||
| }); | ||
| ``` | ||
| Advanced find/replace UI supports: | ||
| - `Aa` for case-sensitive search | ||
| - `Whole` for whole-word-only matching | ||
| - `.*` for regular-expression search | ||
| If regex input is invalid, the status shows `Invalid regular expression` and matching is skipped until the pattern is fixed. | ||
| #### `BracketMatchingExtension` | ||
@@ -171,0 +185,0 @@ Highlights matching brackets. |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
175607
30.12%2990
25.42%289
5.09%0
-100%