@editora/plugins 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/a11y-checker.cjs.js +1 -1
  2. package/dist/anchor.cjs.js +3 -3
  3. package/dist/background-color.cjs.js +2 -2
  4. package/dist/blockquote.cjs.js +1 -1
  5. package/dist/bold.cjs.js +1 -1
  6. package/dist/capitalization.cjs.js +1 -1
  7. package/dist/checklist.cjs.js +1 -1
  8. package/dist/clear-formatting.cjs.js +1 -1
  9. package/dist/code-sample.cjs.js +7 -7
  10. package/dist/code-sample.esm.js +51 -51
  11. package/dist/code.cjs.js +39 -31
  12. package/dist/code.esm.js +570 -440
  13. package/dist/comments.cjs.js +1 -1
  14. package/dist/direction.cjs.js +1 -1
  15. package/dist/document-manager.cjs.js +1 -1
  16. package/dist/embed-iframe.cjs.js +1 -1
  17. package/dist/emojis.cjs.js +1 -1
  18. package/dist/font-family.cjs.js +1 -1
  19. package/dist/font-size.cjs.js +1 -1
  20. package/dist/footnote.cjs.js +2 -2
  21. package/dist/fullscreen.cjs.js +1 -1
  22. package/dist/heading.cjs.js +1 -1
  23. package/dist/history.cjs.js +1 -1
  24. package/dist/history.esm.js +8 -8
  25. package/dist/indent.cjs.js +1 -1
  26. package/dist/index.cjs.js +1 -1
  27. package/dist/italic.cjs.js +1 -1
  28. package/dist/line-height.cjs.js +1 -1
  29. package/dist/link.cjs.js +3 -3
  30. package/dist/list.cjs.js +1 -1
  31. package/dist/lite.cjs.js +1 -1
  32. package/dist/math.cjs.js +2 -2
  33. package/dist/media-manager.cjs.js +4 -4
  34. package/dist/merge-tag.cjs.js +3 -3
  35. package/dist/merge-tag.esm.js +1 -1
  36. package/dist/page-break.cjs.js +2 -2
  37. package/dist/preview.cjs.js +3 -3
  38. package/dist/print.cjs.js +1 -1
  39. package/dist/shared-config.cjs.js +1 -1
  40. package/dist/special-characters.cjs.js +3 -3
  41. package/dist/spell-check.cjs.js +1 -1
  42. package/dist/strikethrough.cjs.js +1 -1
  43. package/dist/table.cjs.js +3 -3
  44. package/dist/template.cjs.js +5 -5
  45. package/dist/text-alignment.cjs.js +1 -1
  46. package/dist/text-color.cjs.js +1 -1
  47. package/dist/underline.cjs.js +1 -1
  48. package/package.json +91 -47
package/dist/code.cjs.js CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class H{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class H{constructor(e=""){this._lines=[],this._version=0,this.setText(e)}getLine(e){return this._lines[e]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
2
2
  `)}setText(e){this._lines=e.split(`
3
- `),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let s=e.start.line+1;s<e.end.line;s++)t.push(this.getLine(s));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
4
- `)}replaceRange(e,t){const s=this.getTextInRange(e);if(e.start.line===e.end.line){const i=this.getLine(e.start.line),r=i.substring(0,e.start.column)+t+i.substring(e.end.column);this._lines[e.start.line]=r}else{const i=this.getLine(e.start.line),r=this.getLine(e.end.line),n=i.substring(0,e.start.column)+t,o=r.substring(e.end.column),a=t.split(`
5
- `);a[0]=n+a[0],a[a.length-1]=a[a.length-1]+o,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...a)}return this._version++,{range:e,text:t,oldText:s}}insertText(e,t){const s={start:e,end:e};return this.replaceRange(s,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let s=0;s<e.line;s++)t+=this.getLine(s).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let s=0;s<this.getLineCount();s++){const i=this.getLine(s).length;if(t<=i)return{line:s,column:t};t-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new H;return e._lines=[...this._lines],e._version=this._version,e}}class R{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.style.cssText=`
3
+ `),this._version++}getTextInRange(e){if(e.start.line===e.end.line)return this.getLine(e.start.line).substring(e.start.column,e.end.column);const t=[];t.push(this.getLine(e.start.line).substring(e.start.column));for(let i=e.start.line+1;i<e.end.line;i++)t.push(this.getLine(i));return e.end.line<this.getLineCount()&&t.push(this.getLine(e.end.line).substring(0,e.end.column)),t.join(`
4
+ `)}replaceRange(e,t){const i=this.getTextInRange(e);if(e.start.line===e.end.line){const s=this.getLine(e.start.line),r=s.substring(0,e.start.column)+t+s.substring(e.end.column);this._lines[e.start.line]=r}else{const s=this.getLine(e.start.line),r=this.getLine(e.end.line),o=s.substring(0,e.start.column)+t,n=r.substring(e.end.column),l=t.split(`
5
+ `);l[0]=o+l[0],l[l.length-1]=l[l.length-1]+n,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...l)}return this._version++,{range:e,text:t,oldText:i}}insertText(e,t){const i={start:e,end:e};return this.replaceRange(i,t)}deleteRange(e){return this.replaceRange(e,"")}positionToOffset(e){let t=0;for(let i=0;i<e.line;i++)t+=this.getLine(i).length+1;return t+=e.column,t}offsetToPosition(e){let t=e;for(let i=0;i<this.getLineCount();i++){const s=this.getLine(i).length;if(t<=s)return{line:i,column:t};t-=s+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(e){return!(e.line<0||e.line>=this.getLineCount()||e.column<0||e.column>this.getLine(e.line).length)}isValidRange(e){return this.isValidPosition(e.start)&&this.isValidPosition(e.end)}getVersion(){return this._version}clone(){const e=new H;return e._lines=[...this._lines],e._version=this._version,e}}class P{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.style.cssText=`
6
6
  position: relative;
7
7
  display: flex;
8
8
  width: 100%;
@@ -42,17 +42,25 @@
42
42
  color: inherit;
43
43
  tab-size: 2;
44
44
  -moz-tab-size: 2;
45
- `,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1;const t=document.createElement("div");t.setAttribute("data-editora-editor","true"),t.style.cssText="display: table; table-layout: fixed; width: 100%; height: 100%;",t.appendChild(this.lineNumbersElement),t.appendChild(this.contentElement),e.appendChild(t),this.container.appendChild(e),this.updateLineNumbers(1)}updateLineNumbers(e){const t=Math.max(e,20),s=Array.from({length:t},(i,r)=>r+1);this.lineNumbersElement.innerHTML=s.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(e){this.contentElement.textContent=e;const t=e.split(`
46
- `).length;this.updateLineNumbers(t)}setHTML(e){const t=/&lt;|&gt;/.test(e),s=/<span\b/i.test(e),i=/<[^>]+>/.test(e);t&&s?this.contentElement.innerHTML=e:i&&!t?this.contentElement.textContent=e:this.contentElement.innerHTML=e;const r=(this.contentElement.textContent||"").split(`
47
- `).length;this.updateLineNumbers(r)}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),s=t.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(t.endContainer,t.endOffset);const i=s.toString().split(`
48
- `);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){const t=this.getText().split(`
49
- `),s=Math.min(e.line,t.length-1),i=Math.min(e.column,t[s]?.length||0);let r=0;for(let u=0;u<s;u++)r+=t[u].length+1;r+=i;const n=document.createRange(),o=window.getSelection();let a=0,l=null,c=0;const g=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let d;for(;d=g.nextNode();){const u=d.textContent?.length||0;if(a+u>=r){l=d,c=r-a;break}a+=u}if(l)try{n.setStart(l,c),n.setEnd(l,c),o?.removeAllRanges(),o?.addRange(n)}catch(u){console.warn("Could not set cursor position:",u)}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),s=t.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(t.startContainer,t.startOffset);const i=s.toString().split(`
50
- `),r=t.cloneRange();r.selectNodeContents(this.contentElement),r.setEnd(t.endContainer,t.endOffset);const n=r.toString().split(`
51
- `);return{start:{line:i.length-1,column:i[i.length-1].length},end:{line:n.length-1,column:n[n.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,s])=>{this.container.style.setProperty(`--${t}`,s)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}setScrollTop(e){this.editorContainer.scrollTop=e}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}class I{constructor(e,t={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.undoStack=[],this.redoStack=[],this.suppressHistory=!1,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...t},this.textModel=new H(this.config.value),this.view=new R(e),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 e=this.view.getContentElement();e.addEventListener("input",()=>{const t=this.view.getText(),s=this.textModel.getText();if(t!==s){if(!this.suppressHistory){const i=this.getCursor().position,r=this.textModel.positionToOffset(i),n=this.getSelection();let o,a;n&&(o=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:s,cursorOffset:r,anchorOffset:o,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(t),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:s}])}}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),s=this.getSelection();this.emit("cursor",t),s&&this.emit("selection",s)}),e.addEventListener("keydown",t=>{if(this.emit("keydown",t),t.key==="Tab"){this.config.readOnly||this.insertTab(),t.preventDefault(),t.stopPropagation();return}if(t.key==="Enter"){if(!this.config.readOnly){const s=window.getSelection();if(s&&s.rangeCount>0){const i=this.getCursor().position,r=this.textModel.positionToOffset(i),n=this.getSelection();let o,a;n&&(o=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end)),this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:r,anchorOffset:o,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const l=s.getRangeAt(0);l.deleteContents();const c=document.createTextNode(`
52
- `);l.insertNode(c),l.setStartAfter(c),l.collapse(!0),s.removeAllRanges(),s.addRange(l);const g=this.getCursor().position,d=this.textModel.positionToOffset(g),u=this.getSelection();let h,f;u&&(h=this.textModel.positionToOffset(u.start),f=this.textModel.positionToOffset(u.end));const m=this.view.getText();this.textModel.setText(m),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{if(u&&(h!==void 0||f!==void 0)){const x=h!==void 0?h:d,k=f!==void 0?f:d,y=Math.min(x,k),C=Math.max(x,k),L=this.textModel.offsetToPosition(y),w=this.textModel.offsetToPosition(C);this.setSelection({start:L,end:w})}else{const x=this.textModel.offsetToPosition(d);this.setCursor(x)}}catch{}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}t.preventDefault(),t.stopPropagation();return}for(const s of this.extensions.values())if(s.onKeyDown&&s.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const s of this.extensions.values())if(s.onMouseDown&&s.onMouseDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("focus",()=>{this.emit("focus")}),e.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const s=this.eventListeners.get(e);s&&s.forEach(i=>i(...t))}getValue(){return this.textModel.getText()}setValue(e){const t=this.textModel.getText();this.textModel.setText(e),this.renderTextWithHighlight(e,!1),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:t}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}setCursor(e){this.view.setCursorPosition(e),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(e){this.view.setSelectionRange(e),this.emit("selection",e)}setTheme(e){this.currentTheme=e;const t={"editor-background":e==="dark"?"#1e1e1e":"#ffffff","editor-foreground":e==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":e==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":e==="dark"?"#858585":"#666666","editor-gutter-border":e==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(t);const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.setTheme=="function")try{s.setTheme(e==="dark"?"dark":"light"),this.renderTextWithHighlight(this.textModel.getText())}catch(i){console.warn("Error applying theme to syntax-highlighting extension",i)}}setReadOnly(e){this.config.readOnly=e,this.view.setReadOnly(e)}addExtension(e){if(this.extensions.has(e.name))throw new Error(`Extension '${e.name}' already exists`);this.extensions.set(e.name,e),e.setup(this),e.name==="syntax-highlighting"&&typeof e.highlightHTML=="function"&&this.renderTextWithHighlight(this.textModel.getText())}removeExtension(e){const t=this.extensions.get(e);t&&t.destroy&&t.destroy(),this.extensions.delete(e)}executeCommand(e,...t){const s=this.commands.get(e);s?s(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const s={caseSensitive:!1,regex:!1,...t},i=[],r=this.getValue();r.split(`
53
- `);let n=s.caseSensitive?r:r.toLowerCase(),o=s.caseSensitive?e:e.toLowerCase();if(s.regex){const a=new RegExp(o,s.caseSensitive?"g":"gi");let l;for(;(l=a.exec(n))!==null;){const c=this.textModel.offsetToPosition(l.index),g=this.textModel.offsetToPosition(l.index+l[0].length);i.push({range:{start:c,end:g},match:l[0]})}}else{let a=0,l=n.indexOf(o,a);for(;l!==-1;){const c=l+e.length,g=this.textModel.offsetToPosition(l),d=this.textModel.offsetToPosition(c);i.push({range:{start:g,end:d},match:r.substring(l,c)}),a=c,l=n.indexOf(o,a)}}return i}replace(e,t){const s=this.getValue();if(!this.suppressHistory){const r=this.getCursor().position,n=this.textModel.positionToOffset(r),o=this.getSelection();let a,l;o&&(a=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:a,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(e,t);this.renderTextWithHighlight(this.getValue(),!1),this.emit("change",[i])}replaceAll(e,t,s={}){const i=this.search(e,s);let r=0;for(let n=i.length-1;n>=0;n--)this.replace(i[n].range,t),r++;return r}fold(e){const t={start:e.start,end:e.end,collapsed:!0,level:0};this.folds.push(t)}unfold(e){this.folds=this.folds.filter(t=>!(t.start.line===e.start.line&&t.end.line===e.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}renderTextWithHighlight(e,t=!0){const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.highlightHTML=="function")try{const i=!t&&!this.expectingProgrammaticCursor;let r,n,o,a;if(t||i){r=this.getSelection();const c=this.getCursor().position;n=this.textModel.positionToOffset(c),r&&(o=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end))}const l=s.highlightHTML(e);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(l):this.view.setHTML(l),(t||i)&&requestAnimationFrame(()=>{try{if(r&&(o!==void 0||a!==void 0)){const c=o!==void 0?o:n,g=a!==void 0?a:n,d=Math.min(c,g),u=Math.max(c,g),h=this.textModel.offsetToPosition(d),f=this.textModel.offsetToPosition(u);this.view.setSelectionRange({start:h,end:f})}else if(n!==void 0){const c=this.textModel.offsetToPosition(n);this.view.setCursorPosition(c)}}catch{}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(e)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const e of this.extensions.values())e.destroy&&e.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}undo(){if(this.undoStack.length===0)return;const e=this.undoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.redoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof e=="string"?s=e:(s=e.text,i=e.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const r=e.anchorOffset!==void 0?e.anchorOffset:i,n=e.focusOffset!==void 0?e.focusOffset:i,o=Math.min(r,n),a=Math.max(r,n),l=this.textModel.offsetToPosition(o),c=this.textModel.offsetToPosition(a);this.setSelection({start:l,end:c})}else{const r=this.textModel.offsetToPosition(i);this.setCursor(r)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const e=this.redoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.undoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof e=="string"?s=e:(s=e.text,i=e.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const r=e.anchorOffset!==void 0?e.anchorOffset:i,n=e.focusOffset!==void 0?e.focusOffset:i,o=Math.min(r,n),a=Math.max(r,n),l=this.textModel.offsetToPosition(o),c=this.textModel.offsetToPosition(a);this.setSelection({start:l,end:c})}else{const r=this.textModel.offsetToPosition(i);this.setCursor(r)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),s=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(e,s),r=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+s.length);if(!this.suppressHistory){const n=this.getSelection();let o,a;n&&(o=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:o,focusOffset:a}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(r),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}insertNewLine(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),s=this.textModel.insertText(e,`
54
- `),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const r=this.getSelection();let n,o;r&&(n=this.textModel.positionToOffset(r.start),o=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:n,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(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}off(e,t){if(!this.eventListeners.has(e))return;const s=this.eventListeners.get(e);if(t){const i=s.indexOf(t);i!==-1&&s.splice(i,1)}else s.length=0}}class N{constructor(e){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=e||this.getDefaultKeymap()}setup(e){this.editor=e}handleKeyDown(e){if(!this.editor)return;const t=this.findMatchingBinding(e);if(t)return this.editor.executeCommand(t.command),e.preventDefault(),e.stopPropagation(),!1}findMatchingBinding(e){const{key:t,ctrlKey:s,altKey:i,shiftKey:r,metaKey:n}=e,o=String(t).toLowerCase(),a=this.keymap[o];if(!a)return null;for(const l of a){const c=l.ctrlKey===void 0||l.ctrlKey===s,g=l.altKey===void 0||l.altKey===i,d=l.shiftKey===void 0||l.shiftKey===r,u=l.metaKey===void 0||l.metaKey===n;if(c&&g&&d&&u)return l}return null}onKeyDown(e){return this.handleKeyDown(e)}getDefaultKeymap(){const e={};return this.addBinding(e,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(e,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(e,"f3",{},"findNext"),this.addBinding(e,"f3",{shiftKey:!0},"findPrev"),this.addBinding(e,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(e,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(e,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(e,"s",{ctrlKey:!0},"save"),this.addBinding(e,"s",{metaKey:!0},"save"),this.addBinding(e,"z",{ctrlKey:!0},"undo"),this.addBinding(e,"z",{metaKey:!0},"undo"),this.addBinding(e,"y",{ctrlKey:!0},"redo"),this.addBinding(e,"y",{metaKey:!0},"redo"),this.addBinding(e,"z",{ctrlKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"z",{metaKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"tab",{},"insertTab"),this.addBinding(e,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),e}addBinding(e,t,s,i){const r=t.toLowerCase();e[r]||(e[r]=[]),e[r].push({key:r,command:i,...s})}setKeymap(e){this.keymap={...e}}addKeyBinding(e){const t=e.key.toLowerCase();this.keymap[t]||(this.keymap[t]=[]),this.keymap[t]=this.keymap[t].filter(s=>s.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const s=e.toLowerCase();t?this.keymap[s]&&(this.keymap[s]=this.keymap[s].filter(i=>i.command!==t),this.keymap[s].length===0&&delete this.keymap[s]):delete this.keymap[s]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const s in this.keymap)for(const i of this.keymap[s])i.command===e&&t.push({...i});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class B{constructor(){this.name="transaction",this.transactions=[]}setup(e){e.on("change",t=>{const s={changes:[t],selection:e.getSelection(),effects:[],annotations:[]};this.transactions.push(s)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class K{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(e){this.editor=e,this.createLineNumbers(),e.registerCommand("toggleLineNumbers",()=>{this.toggle()}),e.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.lineNumbersElement=e)}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
55
- `).length,t=Array.from({length:Math.max(e,20)},(s,i)=>i+1);this.lineNumbersElement.innerHTML=t.map(s=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class A{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class V{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class U{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,s)=>{this.replaceAll(t,s)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){this.showSearch();const e=this.searchUI?.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=this.searchUI?.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
45
+ `,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1;const t=document.createElement("div");t.setAttribute("data-editora-editor","true"),t.style.cssText="display: table; table-layout: fixed; width: 100%; height: 100%;",t.appendChild(this.lineNumbersElement),t.appendChild(this.contentElement),e.appendChild(t),this.container.appendChild(e),this.updateLineNumbers(1)}updateLineNumbers(e){const t=Math.max(e,20),i=Array.from({length:t},(s,r)=>r+1);this.lineNumbersElement.innerHTML=i.map(s=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){const e=this.contentElement.textContent||"";return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`)&&e.endsWith("​")?e.slice(0,-1):e}setText(e){this.contentElement.textContent=e,this.syncTrailingNewlineMarker(e.endsWith(`
46
+ `));const t=e.split(`
47
+ `).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),i=/&lt;|&gt;/.test(e),s=/<span\b/i.test(e),r=/<[^>]+>/.test(e);i&&s?this.contentElement.innerHTML=e:r&&!i?this.contentElement.textContent=e:this.contentElement.innerHTML=e,this.syncTrailingNewlineMarker(t);const o=(this.contentElement.textContent||"").split(`
48
+ `).length;this.updateLineNumbers(o)}syncTrailingNewlineMarkerForText(e){this.syncTrailingNewlineMarker(e.endsWith(`
49
+ `))}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),i=t.cloneRange();i.selectNodeContents(this.contentElement),i.setEnd(t.endContainer,t.endOffset);const s=i.toString().replace(/\u200B/g,"").split(`
50
+ `);return{line:s.length-1,column:s[s.length-1].length}}setCursorPosition(e){const t=this.getText().split(`
51
+ `),i=Math.min(e.line,t.length-1),s=Math.min(e.column,t[i]?.length||0);let r=0;for(let u=0;u<i;u++)r+=t[u].length+1;r+=s;const o=document.createRange(),n=window.getSelection();let l=0,a=null,c=0;const g=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let h;for(;h=g.nextNode();){const u=h.textContent?.length||0;if(l+u>=r){a=h,c=r-l;break}l+=u}if(a)try{o.setStart(a,c),o.setEnd(a,c),n?.removeAllRanges(),n?.addRange(o),this.ensureCaretVisible()}catch(u){console.warn("Could not set cursor position:",u)}else{const u=this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`);try{u&&u.parentNode===this.contentElement?o.setStartBefore(u):(o.selectNodeContents(this.contentElement),o.collapse(!1)),o.collapse(!0),n?.removeAllRanges(),n?.addRange(o),this.ensureCaretVisible()}catch(d){console.warn("Could not set fallback cursor position:",d)}}}getSelectionRange(){const e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed)return;const t=e.getRangeAt(0),i=t.cloneRange();i.selectNodeContents(this.contentElement),i.setEnd(t.startContainer,t.startOffset);const s=i.toString().replace(/\u200B/g,"").split(`
52
+ `),r=t.cloneRange();r.selectNodeContents(this.contentElement),r.setEnd(t.endContainer,t.endOffset);const o=r.toString().replace(/\u200B/g,"").split(`
53
+ `);return{start:{line:s.length-1,column:s[s.length-1].length},end:{line:o.length-1,column:o[o.length-1].length}}}setSelectionRange(e){this.setCursorPosition(e.start)}focus(){this.contentElement.focus(),this.ensureCaretVisible()}blur(){this.contentElement.blur()}setReadOnly(e){this.contentElement.contentEditable=e?"false":"true"}applyTheme(e){Object.entries(e).forEach(([t,i])=>{this.container.style.setProperty(`--${t}`,i)})}scrollToPosition(e){const t=this.lineNumbersElement.children[e.line];t&&t.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}setScrollTop(e){this.editorContainer.scrollTop=e}syncTrailingNewlineMarker(e){if(this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach(i=>i.remove()),!e)return;const t=document.createElement("span");t.setAttribute(this.trailingNewlineMarkerAttr,"true"),t.setAttribute("aria-hidden","true"),t.contentEditable="false",t.style.cssText=`
54
+ display: inline-block;
55
+ width: 0;
56
+ overflow: hidden;
57
+ pointer-events: none;
58
+ user-select: none;
59
+ `,t.appendChild(document.createTextNode("​")),this.contentElement.appendChild(t)}ensureCaretVisible(){const e=window.getSelection();if(!e||e.rangeCount===0)return;const t=e.getRangeAt(0).cloneRange();t.collapse(!1);let i=t.getClientRects()[0]||t.getBoundingClientRect();if((!i||i.width===0&&i.height===0)&&e.focusNode instanceof Element?i=e.focusNode.getBoundingClientRect():(!i||i.width===0&&i.height===0)&&e.focusNode?.parentElement&&(i=e.focusNode.parentElement.getBoundingClientRect()),!i)return;const s=this.editorContainer.getBoundingClientRect(),r=12;i.bottom>s.bottom-r?this.editorContainer.scrollTop+=i.bottom-(s.bottom-r):i.top<s.top+r&&(this.editorContainer.scrollTop-=s.top+r-i.top)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}const $=class M{constructor(e,t={}){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,...t},this.textModel=new H(this.config.value),this.view=new P(e),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(i=>this.addExtension(i)),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 e=this.view.getContentElement();e.addEventListener("input",()=>{const t=this.view.getText(),i=this.textModel.getText();if(t!==i){if(!this.suppressHistory){const s=this.getCursor().position,r=this.textModel.positionToOffset(s),o=this.getSelection();let n,l;o&&(n=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:i,cursorOffset:r,anchorOffset:n,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(t),this.view.syncTrailingNewlineMarkerForText(t),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{const s=this.view.getText();s!==this.textModel.getText()&&this.textModel.setText(s),this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:i}])}}),e.addEventListener("selectionchange",()=>{const t=this.getCursor(),i=this.getSelection();this.emit("cursor",t),i&&this.emit("selection",i)}),e.addEventListener("keydown",t=>{if(this.emit("keydown",t),t.key==="Tab"){this.config.readOnly||this.insertTab(),t.preventDefault(),t.stopPropagation();return}if(t.key==="Enter"){if(!this.config.readOnly){const i=window.getSelection();if(i&&i.rangeCount>0){const s=this.getCursor().position,r=this.textModel.positionToOffset(s),o=this.getSelection();let n,l;o&&(n=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end));const a=o&&n!==void 0&&l!==void 0?Math.min(n,l):r;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:r,anchorOffset:n,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const c=i.getRangeAt(0);c.deleteContents();const g=document.createTextNode(`
60
+ `);c.insertNode(g),c.setStartAfter(g),c.collapse(!0),i.removeAllRanges(),i.addRange(c),this.view.ensureCaretVisible();const h=this.view.getText();this.textModel.setText(h),this.view.syncTrailingNewlineMarkerForText(h);const u=Math.min(a+1,this.textModel.getText().length);try{const d=this.textModel.offsetToPosition(u);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(u);this.setCursor(d),this.view.ensureCaretVisible()}catch{}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}t.preventDefault(),t.stopPropagation();return}for(const i of this.extensions.values())if(i.onKeyDown&&i.onKeyDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("mousedown",t=>{this.emit("mousedown",t);for(const i of this.extensions.values())if(i.onMouseDown&&i.onMouseDown(t)===!1){t.preventDefault(),t.stopPropagation();return}}),e.addEventListener("focus",()=>{this.emit("focus")}),e.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const e=this.textModel.getLineCount();this.view.updateLineNumbers(e)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(e,...t){const i=this.eventListeners.get(e);i&&i.forEach(s=>s(...t))}getValue(){return this.textModel.getText()}setValue(e){const t=this.textModel.getText();this.textModel.setText(e),this.renderTextWithHighlight(e,!1),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:t}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const e=this.view.getCursorPosition();return{position:e,anchor:e}}setCursor(e){this.view.setCursorPosition(e),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(e){this.view.setSelectionRange(e),this.emit("selection",e)}setTheme(e){this.currentTheme=e;const t={"editor-background":e==="dark"?"#1e1e1e":"#ffffff","editor-foreground":e==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":e==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":e==="dark"?"#858585":"#666666","editor-gutter-border":e==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(t);const i=this.extensions.get("syntax-highlighting");if(i&&typeof i.setTheme=="function")try{i.setTheme(e==="dark"?"dark":"light"),this.renderTextWithHighlight(this.textModel.getText())}catch(s){console.warn("Error applying theme to syntax-highlighting extension",s)}}setReadOnly(e){this.config.readOnly=e,this.view.setReadOnly(e)}addExtension(e){if(this.extensions.has(e.name))throw new Error(`Extension '${e.name}' already exists`);this.extensions.set(e.name,e),e.setup(this),e.name==="syntax-highlighting"&&typeof e.highlightHTML=="function"&&this.renderTextWithHighlight(this.textModel.getText())}removeExtension(e){const t=this.extensions.get(e);t&&t.destroy&&t.destroy(),this.extensions.delete(e)}executeCommand(e,...t){const i=this.commands.get(e);i?i(this,...t):console.warn(`Command '${e}' not found`)}registerCommand(e,t){this.commands.set(e,t)}search(e,t={}){const i={caseSensitive:!1,regex:!1,...t},s=[],r=this.getValue();r.split(`
61
+ `);let o=i.caseSensitive?r:r.toLowerCase(),n=i.caseSensitive?e:e.toLowerCase();if(i.regex){const l=new RegExp(n,i.caseSensitive?"g":"gi");let a;for(;(a=l.exec(o))!==null;){const c=this.textModel.offsetToPosition(a.index),g=this.textModel.offsetToPosition(a.index+a[0].length);s.push({range:{start:c,end:g},match:a[0]})}}else{let l=0,a=o.indexOf(n,l);for(;a!==-1;){const c=a+e.length,g=this.textModel.offsetToPosition(a),h=this.textModel.offsetToPosition(c);s.push({range:{start:g,end:h},match:r.substring(a,c)}),l=c,a=o.indexOf(n,l)}}return s}replace(e,t){const i=this.getValue();if(!this.suppressHistory){const r=this.getCursor().position,o=this.textModel.positionToOffset(r),n=this.getSelection();let l,a;n&&(l=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:i,cursorOffset:o,anchorOffset:l,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const s=this.textModel.replaceRange(e,t);this.renderTextWithHighlight(this.getValue(),!1),this.emit("change",[s])}replaceAll(e,t,i={}){const s=this.search(e,i);let r=0;for(let o=s.length-1;o>=0;o--)this.replace(s[o].range,t),r++;return r}fold(e){const t={start:e.start,end:e.end,collapsed:!0,level:0};this.folds.push(t)}unfold(e){this.folds=this.folds.filter(t=>!(t.start.line===e.start.line&&t.end.line===e.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}renderTextWithHighlight(e,t=!0){const i=this.extensions.get("syntax-highlighting");if(i&&typeof i.highlightHTML=="function")try{const s=!t&&!this.expectingProgrammaticCursor;let r,o,n,l;if(t||s){r=this.getSelection();const h=this.getCollapsedSelectionOffsetInEditor();if(h!==void 0)o=h;else{const u=this.getCursor().position;o=this.textModel.positionToOffset(u)}r&&(n=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end))}const a=(t||s)&&!r&&o!==void 0&&this.hasCollapsedSelectionInEditor(),c=a?this.insertSentinelAtOffset(e,o):e,g=i.highlightHTML(c);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(g):this.view.setHTML(g),this.view.syncTrailingNewlineMarkerForText(e),(t||s)&&requestAnimationFrame(()=>{try{if(a&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(r&&(n!==void 0||l!==void 0)){const h=n!==void 0?n:o,u=l!==void 0?l:o,d=Math.min(h,u),f=Math.max(h,u),m=this.textModel.offsetToPosition(d),y=this.textModel.offsetToPosition(f);this.view.setSelectionRange({start:m,end:y})}else if(o!==void 0){const h=this.textModel.offsetToPosition(o);this.view.setCursorPosition(h)}}catch{}});return}catch(s){console.warn("Syntax highlighting failed, falling back to plain text",s)}this.view.setText(e)}hasCollapsedSelectionInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return!1;const t=e.getRangeAt(0);return this.view.getContentElement().contains(t.commonAncestorContainer)}getCollapsedSelectionOffsetInEditor(){const e=window.getSelection();if(!e||e.rangeCount===0||!e.isCollapsed)return;const t=e.getRangeAt(0),i=this.view.getContentElement();if(!i.contains(t.commonAncestorContainer))return;const s=t.cloneRange();return s.selectNodeContents(i),s.setEnd(t.endContainer,t.endOffset),this.stripVirtualMarkers(s.toString()).length}stripVirtualMarkers(e){return e.replace(/\u200B/g,"").split(M.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(e,t){const i=Math.max(0,Math.min(t,e.length));return e.slice(0,i)+M.CURSOR_SENTINEL+e.slice(i)}restoreCursorFromSentinel(){const e=this.view.getContentElement(),t=window.getSelection(),i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let s=i.nextNode(),r=null,o=0;for(;s;){const n=s.textContent??"",l=n.indexOf(M.CURSOR_SENTINEL);l!==-1&&(r||(r=s,o=l),s.textContent=n.split(M.CURSOR_SENTINEL).join("")),s=i.nextNode()}if(!r||!t)return!1;try{const n=document.createRange();return n.setStart(r,o),n.collapse(!0),t.removeAllRanges(),t.addRange(n),!0}catch{return!1}}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const e of this.extensions.values())e.destroy&&e.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}undo(){if(this.undoStack.length===0)return;const e=this.undoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.redoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let i,s;typeof e=="string"?i=e:(i=e.text,s=e.cursorOffset),this.setValue(i),requestAnimationFrame(()=>{try{if(s!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const r=e.anchorOffset!==void 0?e.anchorOffset:s,o=e.focusOffset!==void 0?e.focusOffset:s,n=Math.min(r,o),l=Math.max(r,o),a=this.textModel.offsetToPosition(n),c=this.textModel.offsetToPosition(l);this.setSelection({start:a,end:c})}else{const r=this.textModel.offsetToPosition(s);this.setCursor(r)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const e=this.redoStack.pop(),t={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.undoStack.push(t);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let i,s;typeof e=="string"?i=e:(i=e.text,s=e.cursorOffset),this.setValue(i),requestAnimationFrame(()=>{try{if(s!=null)if(typeof e!="string"&&(e.anchorOffset!==void 0||e.focusOffset!==void 0)){const r=e.anchorOffset!==void 0?e.anchorOffset:s,o=e.focusOffset!==void 0?e.focusOffset:s,n=Math.min(r,o),l=Math.max(r,o),a=this.textModel.offsetToPosition(n),c=this.textModel.offsetToPosition(l);this.setSelection({start:a,end:c})}else{const r=this.textModel.offsetToPosition(s);this.setCursor(r)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),i=" ".repeat(this.config.tabSize||2),s=this.textModel.insertText(e,i),r=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+i.length);if(!this.suppressHistory){const o=this.getSelection();let n,l;o&&(n=this.textModel.positionToOffset(o.start),l=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:n,focusOffset:l}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(r),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[s])}insertNewLine(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),i=this.textModel.insertText(e,`
62
+ `),s=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const r=this.getSelection();let o,n;r&&(o=this.textModel.positionToOffset(r.start),n=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:o,focusOffset:n}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(s),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,[]),this.eventListeners.get(e).push(t)}off(e,t){if(!this.eventListeners.has(e))return;const i=this.eventListeners.get(e);if(t){const s=i.indexOf(t);s!==-1&&i.splice(s,1)}else i.length=0}};$.CURSOR_SENTINEL="";let A=$;class B{constructor(e){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=e||this.getDefaultKeymap()}setup(e){this.editor=e}handleKeyDown(e){if(!this.editor)return;const t=this.findMatchingBinding(e);if(t)return this.editor.executeCommand(t.command),e.preventDefault(),e.stopPropagation(),!1}findMatchingBinding(e){const{key:t,ctrlKey:i,altKey:s,shiftKey:r,metaKey:o}=e,n=String(t).toLowerCase(),l=this.keymap[n];if(!l)return null;for(const a of l){const c=a.ctrlKey===void 0||a.ctrlKey===i,g=a.altKey===void 0||a.altKey===s,h=a.shiftKey===void 0||a.shiftKey===r,u=a.metaKey===void 0||a.metaKey===o;if(c&&g&&h&&u)return a}return null}onKeyDown(e){return this.handleKeyDown(e)}getDefaultKeymap(){const e={};return this.addBinding(e,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(e,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(e,"f3",{},"findNext"),this.addBinding(e,"f3",{shiftKey:!0},"findPrev"),this.addBinding(e,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(e,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(e,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(e,"s",{ctrlKey:!0},"save"),this.addBinding(e,"s",{metaKey:!0},"save"),this.addBinding(e,"z",{ctrlKey:!0},"undo"),this.addBinding(e,"z",{metaKey:!0},"undo"),this.addBinding(e,"y",{ctrlKey:!0},"redo"),this.addBinding(e,"y",{metaKey:!0},"redo"),this.addBinding(e,"z",{ctrlKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"z",{metaKey:!0,shiftKey:!0},"redo"),this.addBinding(e,"tab",{},"insertTab"),this.addBinding(e,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),e}addBinding(e,t,i,s){const r=t.toLowerCase();e[r]||(e[r]=[]),e[r].push({key:r,command:s,...i})}setKeymap(e){this.keymap={...e}}addKeyBinding(e){const t=e.key.toLowerCase();this.keymap[t]||(this.keymap[t]=[]),this.keymap[t]=this.keymap[t].filter(i=>i.command!==e.command),this.keymap[t].push({...e,key:t})}removeKeyBinding(e,t){const i=e.toLowerCase();t?this.keymap[i]&&(this.keymap[i]=this.keymap[i].filter(s=>s.command!==t),this.keymap[i].length===0&&delete this.keymap[i]):delete this.keymap[i]}getKeymap(){return{...this.keymap}}getBindingsForCommand(e){const t=[];for(const i in this.keymap)for(const s of this.keymap[i])s.command===e&&t.push({...s});return t}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class V{constructor(){this.name="transaction",this.transactions=[]}setup(e){e.on("change",t=>{const i={changes:t,selection:e.getSelection(),effects:[],annotations:[]};this.transactions.push(i)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class K{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(e){this.editor=e,this.createLineNumbers(),e.registerCommand("toggleLineNumbers",()=>{this.toggle()}),e.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.lineNumbersElement=e)}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
63
+ `).length,t=Array.from({length:Math.max(e,20)},(i,s)=>s+1);this.lineNumbersElement.innerHTML=t.map(i=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("")}toggle(){if(!this.editor)return;this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class U{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class z{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class q{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,i)=>{this.replaceAll(t,i)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){this.showSearch();const e=this.searchUI?.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=this.searchUI?.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
56
64
  position: absolute;
57
65
  top: 10px;
58
66
  right: 10px;
@@ -121,11 +129,11 @@
121
129
  display: none;
122
130
  margin-top: 4px;
123
131
  " />
124
- `;const t=this.searchUI.querySelector("input"),s=this.searchUI.querySelector(".search-replace-input"),i=this.searchUI.querySelector(".search-prev"),r=this.searchUI.querySelector(".search-next"),n=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.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(t.value,s.value):this.replaceCurrent(t.value,s.value))}),i.addEventListener("click",()=>this.findPrev()),r.addEventListener("click",()=>this.findNext()),n.addEventListener("click",()=>this.hideSearch()),e.appendChild(this.searchUI)}performSearch(e){if(!this.editor||!e.trim()){this.clearHighlights(),this.updateStatus("");return}const t=this.editor.getValue(),s=[];let i=t.toLowerCase().indexOf(e.toLowerCase());for(;i!==-1;){const r=this.getPositionFromOffset(t,i),n=this.getPositionFromOffset(t,i+e.length);s.push({range:{start:r,end:n},match:t.substring(i,i+e.length)}),i=t.toLowerCase().indexOf(e.toLowerCase(),i+1)}this.currentResults=s,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(e,t){const s=e.substring(0,t).split(`
125
- `),i=s.length-1,r=s[s.length-1].length;return{line:i,column:r}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(e,t){if(!this.editor||!e.trim()||this.currentIndex===-1)return;const s=this.currentResults[this.currentIndex];if(!s)return;const i=this.editor.getValue(),r=this.getOffsetFromPosition(i,s.range.start),n=i.substring(0,r),o=i.substring(r+e.length),a=n+t+o;this.editor.setValue(a),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let s=this.editor.getValue(),i=0,r=s.toLowerCase().indexOf(e.toLowerCase());for(;r!==-1;)s=s.substring(0,r)+t+s.substring(r+e.length),i++,r=s.toLowerCase().indexOf(e.toLowerCase(),r+t.length);i>0&&(this.editor.setValue(s),this.updateStatus(`Replaced ${i} occurrences`))}getOffsetFromPosition(e,t){const s=e.split(`
126
- `);let i=0;for(let r=0;r<t.line;r++)i+=s[r].length+1;return i+=t.column,i}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(e){const t=this.searchUI?.querySelector(".search-status");t&&(t.textContent=e)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class z{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(e){this.editor=e,e.on("cursor",()=>{this.updateBracketMatching()}),e.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const e=this.editor.getCursor(),t=this.editor.getValue();this.clearBracketHighlighting();const s=this.getBracketAtPosition(t,e.position);if(!s)return;const i=this.findMatchingBracket(t,s);i&&(this.currentMatch=i,this.highlightBrackets(i))}getBracketAtPosition(e,t){const s=e.split(`
127
- `);if(t.line>=s.length)return null;const i=s[t.line];if(t.column>=i.length)return null;const r=i[t.column];return this.bracketPairs[r]||this.reverseBracketPairs[r]?{char:r,position:t}:null}findMatchingBracket(e,t){const s=e.split(`
128
- `),i=t.position.line,r=t.position.column,n=t.char;return this.bracketPairs[n]?this.findClosingBracket(e,s,i,r,n):this.reverseBracketPairs[n]?this.findOpeningBracket(e,s,i,r,n):null}findClosingBracket(e,t,s,i,r){const n=this.bracketPairs[r];let o=0;for(let a=s;a<t.length;a++){const l=t[a],c=a===s?i:0;for(let g=c;g<l.length;g++){const d=l[g];if(d===r)o++;else if(d===n&&(o--,o===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:a,column:g},end:{line:a,column:g+1}},type:r}}}return null}findOpeningBracket(e,t,s,i,r){const n=this.reverseBracketPairs[r];let o=0;for(let a=s;a>=0;a--){const l=t[a],c=a===s?i:l.length-1;for(let g=c;g>=0;g--){const d=l[g];if(d===r)o++;else if(d===n&&(o--,o===0))return{open:{start:{line:a,column:g},end:{line:a,column:g+1}},close:{start:{line:s,column:i},end:{line:s,column:i+1}},type:n}}}return null}highlightBrackets(e){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class q{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),e.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
132
+ `;const t=this.searchUI.querySelector("input"),i=this.searchUI.querySelector(".search-replace-input"),s=this.searchUI.querySelector(".search-prev"),r=this.searchUI.querySelector(".search-next"),o=this.searchUI.querySelector(".search-close");t.addEventListener("input",()=>{this.performSearch(t.value)}),t.addEventListener("keydown",n=>{n.key==="Enter"&&(n.preventDefault(),n.shiftKey?this.findPrev():this.findNext())}),i.addEventListener("keydown",n=>{n.key==="Enter"&&(n.preventDefault(),n.shiftKey?this.replaceAll(t.value,i.value):this.replaceCurrent(t.value,i.value))}),s.addEventListener("click",()=>this.findPrev()),r.addEventListener("click",()=>this.findNext()),o.addEventListener("click",()=>this.hideSearch()),e.appendChild(this.searchUI)}performSearch(e){if(!this.editor||!e.trim()){this.clearHighlights(),this.updateStatus("");return}const t=this.editor.getValue(),i=[];let s=t.toLowerCase().indexOf(e.toLowerCase());for(;s!==-1;){const r=this.getPositionFromOffset(t,s),o=this.getPositionFromOffset(t,s+e.length);i.push({range:{start:r,end:o},match:t.substring(s,s+e.length)}),s=t.toLowerCase().indexOf(e.toLowerCase(),s+1)}this.currentResults=i,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(e,t){const i=e.substring(0,t).split(`
133
+ `),s=i.length-1,r=i[i.length-1].length;return{line:s,column:r}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(e,t){if(!this.editor||!e.trim()||this.currentIndex===-1)return;const i=this.currentResults[this.currentIndex];if(!i)return;const s=this.editor.getValue(),r=this.getOffsetFromPosition(s,i.range.start),o=s.substring(0,r),n=s.substring(r+e.length),l=o+t+n;this.editor.setValue(l),this.performSearch(e),this.updateStatus("Replaced current occurrence")}replaceAll(e,t){if(!this.editor||!e.trim())return;let i=this.editor.getValue(),s=0,r=i.toLowerCase().indexOf(e.toLowerCase());for(;r!==-1;)i=i.substring(0,r)+t+i.substring(r+e.length),s++,r=i.toLowerCase().indexOf(e.toLowerCase(),r+t.length);s>0&&(this.editor.setValue(i),this.updateStatus(`Replaced ${s} occurrences`))}getOffsetFromPosition(e,t){const i=e.split(`
134
+ `);let s=0;for(let r=0;r<t.line;r++)s+=i[r].length+1;return s+=t.column,s}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(e){const t=this.searchUI?.querySelector(".search-status");t&&(t.textContent=e)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class F{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(e){this.editor=e,e.on("cursor",()=>{this.updateBracketMatching()}),e.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const e=this.editor.getCursor(),t=this.editor.getValue();this.clearBracketHighlighting();const i=this.getBracketAtPosition(t,e.position);if(!i)return;const s=this.findMatchingBracket(t,i);s&&(this.currentMatch=s,this.highlightBrackets(s))}getBracketAtPosition(e,t){const i=e.split(`
135
+ `);if(t.line>=i.length)return null;const s=i[t.line];if(t.column>=s.length)return null;const r=s[t.column];return this.bracketPairs[r]||this.reverseBracketPairs[r]?{char:r,position:t}:null}findMatchingBracket(e,t){const i=e.split(`
136
+ `),s=t.position.line,r=t.position.column,o=t.char;return this.bracketPairs[o]?this.findClosingBracket(e,i,s,r,o):this.reverseBracketPairs[o]?this.findOpeningBracket(e,i,s,r,o):null}findClosingBracket(e,t,i,s,r){const o=this.bracketPairs[r];let n=0;for(let l=i;l<t.length;l++){const a=t[l],c=l===i?s:0;for(let g=c;g<a.length;g++){const h=a[g];if(h===r)n++;else if(h===o&&(n--,n===0))return{open:{start:{line:i,column:s},end:{line:i,column:s+1}},close:{start:{line:l,column:g},end:{line:l,column:g+1}},type:r}}}return null}findOpeningBracket(e,t,i,s,r){const o=this.reverseBracketPairs[r];let n=0;for(let l=i;l>=0;l--){const a=t[l],c=l===i?s:a.length-1;for(let g=c;g>=0;g--){const h=a[g];if(h===r)n++;else if(h===o&&(n--,n===0))return{open:{start:{line:l,column:g},end:{line:l,column:g+1}},close:{start:{line:i,column:s},end:{line:i,column:s+1}},type:o}}}return null}highlightBrackets(e){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class _{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(e){this.editor=e,e.registerCommand("fold",()=>{this.foldAtCursor()}),e.registerCommand("unfold",()=>{this.unfoldAtCursor()}),e.registerCommand("foldAll",()=>{this.foldAll()}),e.registerCommand("unfoldAll",()=>{this.unfoldAll()}),e.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");e&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
129
137
  position: absolute;
130
138
  left: 40px;
131
139
  top: 0;
@@ -134,7 +142,7 @@
134
142
  pointer-events: none;
135
143
  z-index: 2;
136
144
  `,e.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const e=this.editor.getValue().split(`
137
- `);this.findFoldableLines(e).forEach(t=>{this.createFoldIndicator(t)})}findFoldableLines(e){const t=[];for(let s=0;s<e.length;s++){const i=e[s].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&t.push(s)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
145
+ `);this.findFoldableLines(e).forEach(t=>{this.createFoldIndicator(t)})}findFoldableLines(e){const t=[];for(let i=0;i<e.length;i++){const s=e[i].trim();(s.startsWith("{")||s.startsWith("function")||s.startsWith("class")||s.startsWith("if")||s.includes("=>")||s.startsWith("for")||s.startsWith("while")||s.startsWith("try"))&&t.push(i)}return t}createFoldIndicator(e){if(!this.foldingUI)return;const t=document.createElement("div");t.style.cssText=`
138
146
  position: absolute;
139
147
  left: 0;
140
148
  top: ${e*21}px;
@@ -148,7 +156,7 @@
148
156
  color: var(--editor-gutter-foreground, #858585);
149
157
  font-size: 10px;
150
158
  user-select: none;
151
- `,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),this.foldingUI.appendChild(t),this.foldIndicators.push(t)}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 _{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark",this.currentLanguage=null,this.modes=new Map}setup(e){this.editor=e,this.registerMode("html",{name:"html",highlight:(t,s)=>this._highlightHTML(t,s)}),this.registerMode("javascript",{name:"javascript",highlight:(t,s)=>this._highlightJS(t,s)}),this.registerMode("typescript",{name:"typescript",highlight:(t,s)=>this._highlightJS(t,s)}),this.registerMode("php",{name:"php",highlight:(t,s)=>this._highlightPHP(t,s)})}setTheme(e){this.currentTheme=e}setLanguage(e){this.currentLanguage=e}registerMode(e,t){this.modes.set(e.toLowerCase(),t)}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(e,t){const s=this.getSyntaxColors(),i=(t||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(e,s)}highlightHTML(e){return this.highlight(e,"html")}escapeHTML(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}unescapeEntitiesRepeated(e){let t=e||"";for(let s=0;s<5;s++){const i=t;if(t=t.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),t===i)break}return t}_highlightHTML(e,t){const s=t,i=l=>this.escapeHTML(l);let r=i(e);const n=l=>{let c=l.replace(/&quot;/g,'"').replace(/&#39;/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${s.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(g,d,u,h,f)=>{const m=String(h).trim(),x=i(m);return`<span style="color: ${s.styleProp};">${d}</span>${u}<span style="color: ${s.styleVal};">${x}</span>${f}`}),c},o=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(l,c,g)=>(o.push({attrs:String(c||""),inner:String(g||"")}),l))}catch{}let a=0;return r=r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi,(l,c,g,d,u)=>{const h=o[a++]?.inner??this.unescapeEntitiesRepeated(d||"");(o[a-1]?.attrs||g||"").toLowerCase();const f=this._highlightJS(h,s);return`${c}${f}${u}`}),r=r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi,(l,c,g,d)=>{const u=n(g);return`${c}${u}${d}`}),r=r.replace(/(&lt;!--[\s\S]*?--&gt;)/g,`<span style="color: ${s.comment};">$1</span>`),r=r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i,`<span style="color: ${s.doctype};">$1</span>`),r=r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g,(l,c,g,d,u)=>{const h=`<span style="color: ${s.tag};">${g}</span>`;let f=d;return f=f.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,(m,x,k,y)=>{const C=String(x).toLowerCase(),L=`<span style="color: ${s.attrName};">${x}</span>`;let w=y,b="";y.startsWith("&quot;")&&y.endsWith("&quot;")?(w=y.slice(6,-6),b="&quot;"):y.startsWith("&#39;")&&y.endsWith("&#39;")&&(w=y.slice(5,-5),b="&#39;");let T=y;if(C==="style"){const S=w.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(E,p,M,$)=>`<span style="color: ${s.styleProp};">${p}</span>:<span style="color: ${s.styleVal};">${M.trim()}</span>${$}`);b?T=`${b}${S}${b}`:T=S,T=`<span style="color: ${s.attrValue};">${T}</span>`}else b&&(T=`${b}${w}${b}`),T=`<span style="color: ${s.attrValue};">${T}</span>`;return`${L}${k}${T}`}),`${c}${h}${f}${u}`}),r}_highlightJS(e,t){const s=this.unescapeEntitiesRepeated(e);this.escapeHTML(s);const i=[],r=d=>{let u="",h=d;do u=String.fromCharCode(97+h%26)+u,h=Math.floor(h/26)-1;while(h>=0);return u||"a"},n=d=>`\0${r(d)}\0`,o=d=>{const u=i.length;return i.push(d),n(u)};let a;const l=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,g="";for(;a=l.exec(s);){const d=a.index;c<d&&(g+=this.escapeHTML(s.slice(c,d)));const u=a[0];/^\/\*/.test(u)||/^\/\//.test(u)?g+=o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`):g+=o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`),c=l.lastIndex}return c<s.length&&(g+=this.escapeHTML(s.slice(c))),g=g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(d,u,h)=>{const f=g[h-1]||"",m=g[h+d.length]||"";return f==="&"||f==="#"||m===";"||m==="#"?d:`<span style="color: ${t.number};">${d}</span>`}),g=g.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: ${t.keyword};">$1</span>`),g.replace(/\u0000([a-z]+)\u0000/g,(d,u)=>{let h=0;for(let f=0;f<u.length;f++)h=h*26+(u.charCodeAt(f)-97+1);return h=h-1,i[h]||""})}_highlightPHP(e,t){const s=this.unescapeEntitiesRepeated(e);let i=this.escapeHTML(s);const r=[],n=h=>{let f="",m=h;do f=String.fromCharCode(97+m%26)+f,m=Math.floor(m/26)-1;while(m>=0);return f||"a"},o=h=>{const f=r.length;return r.push(h),`\0${n(f)}\0`},a=(h,f)=>{const m=i.indexOf(h);return m===-1?!1:(i=i.slice(0,m)+f+i.slice(m+h.length),!0)};let l;const c=/\/\*[\s\S]*?\*\//g,g=/\/\/[^\n\r]*/g,d=/\#([^\n\r]*)/g,u=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;l=c.exec(s);){const h=l[0];a(this.escapeHTML(h),o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;l=g.exec(s);){const h=l[0];a(this.escapeHTML(h),o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;l=d.exec(s);){const h=l[0];a(this.escapeHTML(h),o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`))}for(;l=u.exec(s);){const h=l[0];a(this.escapeHTML(h),o(`<span style="color: ${t.string};">${this.escapeHTML(h)}</span>`))}return i=i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g,`<span style="color: ${t.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: ${t.keyword};">$1</span>`),i=i.replace(/\u0000([a-z]+)\u0000/g,(h,f)=>{let m=0;for(let x=0;x<f.length;x++)m=m*26+(f.charCodeAt(x)-97+1);return m=m-1,r[m]||""}),i}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function F(v,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(s=>s.name==="keymap")||t.extensions.unshift(new N(t.keymap)),t.extensions.some(s=>s.name==="transaction")||t.extensions.unshift(new B),new I(v,t)}const O='[data-theme="dark"], .dark, .editora-theme-dark',D=`/* Source Editor Dialog Styles */
159
+ `,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),this.foldingUI.appendChild(t),this.foldIndicators.push(t)}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 W{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark",this.currentLanguage=null,this.modes=new Map}setup(e){this.editor=e,this.registerMode("html",{name:"html",highlight:(t,i)=>this._highlightHTML(t,i)}),this.registerMode("javascript",{name:"javascript",highlight:(t,i)=>this._highlightJS(t,i)}),this.registerMode("typescript",{name:"typescript",highlight:(t,i)=>this._highlightJS(t,i)}),this.registerMode("php",{name:"php",highlight:(t,i)=>this._highlightPHP(t,i)})}setTheme(e){this.currentTheme=e}setLanguage(e){this.currentLanguage=e}registerMode(e,t){this.modes.set(e.toLowerCase(),t)}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(e,t){const i=this.getSyntaxColors(),s=(t||this.currentLanguage||"html").toLowerCase();return(this.modes.get(s)||this.modes.get("html")).highlight(e,i)}highlightHTML(e){return this.highlight(e,"html")}escapeHTML(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}unescapeEntitiesRepeated(e){let t=e||"";for(let i=0;i<5;i++){const s=t;if(t=t.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),t===s)break}return t}_highlightHTML(e,t){const i=t,s=a=>this.escapeHTML(a);let r=s(e);const o=a=>{let c=a.replace(/&quot;/g,'"').replace(/&#39;/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${i.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(g,h,u,d,f)=>{const m=String(d).trim(),y=s(m);return`<span style="color: ${i.styleProp};">${h}</span>${u}<span style="color: ${i.styleVal};">${y}</span>${f}`}),c},n=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(a,c,g)=>(n.push({attrs:String(c||""),inner:String(g||"")}),a))}catch{}let l=0;return r=r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi,(a,c,g,h,u)=>{const d=n[l++]?.inner??this.unescapeEntitiesRepeated(h||"");(n[l-1]?.attrs||g||"").toLowerCase();const f=this._highlightJS(d,i);return`${c}${f}${u}`}),r=r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi,(a,c,g,h)=>{const u=o(g);return`${c}${u}${h}`}),r=r.replace(/(&lt;!--[\s\S]*?--&gt;)/g,`<span style="color: ${i.comment};">$1</span>`),r=r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i,`<span style="color: ${i.doctype};">$1</span>`),r=r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g,(a,c,g,h,u)=>{const d=`<span style="color: ${i.tag};">${g}</span>`;let f=h;return f=f.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,(m,y,T,x)=>{const E=String(y).toLowerCase(),L=`<span style="color: ${i.attrName};">${y}</span>`;let C=x,b="";x.startsWith("&quot;")&&x.endsWith("&quot;")?(C=x.slice(6,-6),b="&quot;"):x.startsWith("&#39;")&&x.endsWith("&#39;")&&(C=x.slice(5,-5),b="&#39;");let k=x;if(E==="style"){const S=C.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(O,p,w,N)=>`<span style="color: ${i.styleProp};">${p}</span>:<span style="color: ${i.styleVal};">${w.trim()}</span>${N}`);b?k=`${b}${S}${b}`:k=S,k=`<span style="color: ${i.attrValue};">${k}</span>`}else b&&(k=`${b}${C}${b}`),k=`<span style="color: ${i.attrValue};">${k}</span>`;return`${L}${T}${k}`}),`${c}${d}${f}${u}`}),r}_highlightJS(e,t){const i=this.unescapeEntitiesRepeated(e);this.escapeHTML(i);const s=[],r=h=>{let u="",d=h;do u=String.fromCharCode(97+d%26)+u,d=Math.floor(d/26)-1;while(d>=0);return u||"a"},o=h=>`\0${r(h)}\0`,n=h=>{const u=s.length;return s.push(h),o(u)};let l;const a=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,g="";for(;l=a.exec(i);){const h=l.index;c<h&&(g+=this.escapeHTML(i.slice(c,h)));const u=l[0];/^\/\*/.test(u)||/^\/\//.test(u)?g+=n(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`):g+=n(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`),c=a.lastIndex}return c<i.length&&(g+=this.escapeHTML(i.slice(c))),g=g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(h,u,d)=>{const f=g[d-1]||"",m=g[d+h.length]||"";return f==="&"||f==="#"||m===";"||m==="#"?h:`<span style="color: ${t.number};">${h}</span>`}),g=g.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: ${t.keyword};">$1</span>`),g.replace(/\u0000([a-z]+)\u0000/g,(h,u)=>{let d=0;for(let f=0;f<u.length;f++)d=d*26+(u.charCodeAt(f)-97+1);return d=d-1,s[d]||""})}_highlightPHP(e,t){const i=this.unescapeEntitiesRepeated(e);let s=this.escapeHTML(i);const r=[],o=d=>{let f="",m=d;do f=String.fromCharCode(97+m%26)+f,m=Math.floor(m/26)-1;while(m>=0);return f||"a"},n=d=>{const f=r.length;return r.push(d),`\0${o(f)}\0`},l=(d,f)=>{const m=s.indexOf(d);return m===-1?!1:(s=s.slice(0,m)+f+s.slice(m+d.length),!0)};let a;const c=/\/\*[\s\S]*?\*\//g,g=/\/\/[^\n\r]*/g,h=/\#([^\n\r]*)/g,u=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;a=c.exec(i);){const d=a[0];l(this.escapeHTML(d),n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;a=g.exec(i);){const d=a[0];l(this.escapeHTML(d),n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;a=h.exec(i);){const d=a[0];l(this.escapeHTML(d),n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;a=u.exec(i);){const d=a[0];l(this.escapeHTML(d),n(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`))}return s=s.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g,`<span style="color: ${t.variable};">$1</span>`),s=s.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: ${t.keyword};">$1</span>`),s=s.replace(/\u0000([a-z]+)\u0000/g,(d,f)=>{let m=0;for(let y=0;y<f.length;y++)m=m*26+(f.charCodeAt(y)-97+1);return m=m-1,r[m]||""}),s}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function D(v,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(i=>i.name==="keymap")||t.extensions.unshift(new B(t.keymap)),t.extensions.some(i=>i.name==="transaction")||t.extensions.unshift(new V),new A(v,t)}const R='[data-theme="dark"], .dark, .editora-theme-dark',j=`/* Source Editor Dialog Styles */
152
160
  .rte-source-editor-overlay {
153
161
  position: fixed !important;
154
162
  top: 0 !important;
@@ -525,10 +533,10 @@
525
533
  flex: 1;
526
534
  text-align: center;
527
535
  }
528
- }`,W=()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",type:"button",icon:"<>",shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{const r=window.getSelection();if(r&&r.anchorNode){let o=r.anchorNode instanceof HTMLElement?r.anchorNode:r.anchorNode.parentElement;for(;o;){if(o.classList?.contains("rte-content"))return o;o=o.parentElement}}if(document.activeElement){let o=document.activeElement;if(o.classList?.contains("rte-content"))return o;for(;o&&o!==document.body;){if(o.classList?.contains("rte-content"))return o;const a=o.querySelector(".rte-content");if(a)return a;o=o.parentElement}}const n=document.querySelector("[data-editora-editor]");if(n){const o=n.querySelector(".rte-content");if(o)return o}return document.querySelector(".rte-content")})();if(!e)return console.error("[CodePlugin] Editor content area not found"),alert("Editor content area not found. Please click inside the editor first."),!1;const t=e.innerHTML,s=r=>{let n="",o=0;const a=2,l=r.split(/(<\/?[a-zA-Z][^>]*>)/);for(const c of l)c.trim()&&(c.match(/^<\/[a-zA-Z]/)?(o=Math.max(0,o-1),n+=`
529
- `+" ".repeat(o*a)+c):c.match(/^<[a-zA-Z]/)&&!c.match(/\/>$/)?(n+=`
530
- `+" ".repeat(o*a)+c,o++):c.match(/^<[a-zA-Z].*\/>$/)?n+=`
531
- `+" ".repeat(o*a)+c:n+=c.trim());return n.trim()};return(()=>{let r=null,n="dark",o=!1,a=!1,l=!1;const c=t,g=!!e.closest(O)||document.body.matches(O)||document.documentElement.matches(O),d=document.createElement("div");d.className="rte-source-editor-overlay",g&&d.classList.add("rte-theme-dark");const u=document.createElement("div");u.className="rte-source-editor-modal",u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),u.setAttribute("aria-labelledby","source-editor-title");const h=document.createElement("div");h.className="rte-source-editor-header",h.innerHTML=`
536
+ }`,Z=()=>({name:"code",toolbar:[{label:"Source",command:"toggleSourceView",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>',shortcut:"Mod-Shift-S"}],commands:{toggleSourceView:()=>{const e=(()=>{const r=window.getSelection();if(r&&r.anchorNode){let n=r.anchorNode instanceof HTMLElement?r.anchorNode:r.anchorNode.parentElement;for(;n;){if(n.classList?.contains("rte-content"))return n;n=n.parentElement}}if(document.activeElement){let n=document.activeElement;if(n.classList?.contains("rte-content"))return n;for(;n&&n!==document.body;){if(n.classList?.contains("rte-content"))return n;const l=n.querySelector(".rte-content");if(l)return l;n=n.parentElement}}const o=document.querySelector("[data-editora-editor]");if(o){const n=o.querySelector(".rte-content");if(n)return n}return document.querySelector(".rte-content")})();if(!e)return console.error("[CodePlugin] Editor content area not found"),alert("Editor content area not found. Please click inside the editor first."),!1;const t=e.innerHTML,i=r=>{let o="",n=0;const l=2,a=r.split(/(<\/?[a-zA-Z][^>]*>)/);for(const c of a)c.trim()&&(c.match(/^<\/[a-zA-Z]/)?(n=Math.max(0,n-1),o+=`
537
+ `+" ".repeat(n*l)+c):c.match(/^<[a-zA-Z]/)&&!c.match(/\/>$/)?(o+=`
538
+ `+" ".repeat(n*l)+c,n++):c.match(/^<[a-zA-Z].*\/>$/)?o+=`
539
+ `+" ".repeat(n*l)+c:o+=c.trim());return o.trim()};return(()=>{let r=null,o="dark",n=!1,l=!1,a=!1;const c=t,g=!!e.closest(R)||document.body.matches(R)||document.documentElement.matches(R),h=document.createElement("div");h.className="rte-source-editor-overlay",g&&h.classList.add("rte-theme-dark");const u=document.createElement("div");u.className="rte-source-editor-modal",u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),u.setAttribute("aria-labelledby","source-editor-title");const d=document.createElement("div");d.className="rte-source-editor-header",d.innerHTML=`
532
540
  <h2 id="source-editor-title">Source Editor</h2>
533
541
  <div class="rte-source-editor-header-toolbar">
534
542
  <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
@@ -564,7 +572,7 @@
564
572
  </svg>
565
573
  </button>
566
574
  </div>
567
- `;const f=document.createElement("div");f.className="rte-source-editor-body";const m=document.createElement("div");m.className="rte-source-editor-content";const x=document.createElement("div");x.className="rte-source-editor-warning",x.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const k=document.createElement("div");k.className="rte-source-editor-light-editor",k.style.height="400px",m.appendChild(x),m.appendChild(k),f.appendChild(m);const y=document.createElement("div");if(y.className="rte-source-editor-footer",y.innerHTML=`
575
+ `;const f=document.createElement("div");f.className="rte-source-editor-body";const m=document.createElement("div");m.className="rte-source-editor-content";const y=document.createElement("div");y.className="rte-source-editor-warning",y.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const T=document.createElement("div");T.className="rte-source-editor-light-editor",T.style.height="400px",m.appendChild(y),m.appendChild(T),f.appendChild(m);const x=document.createElement("div");if(x.className="rte-source-editor-footer",x.innerHTML=`
568
576
  <div class="rte-source-editor-footer-info">
569
577
  <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
570
578
  </div>
@@ -572,11 +580,11 @@
572
580
  <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
573
581
  <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
574
582
  </div>
575
- `,u.appendChild(h),u.appendChild(f),u.appendChild(y),d.appendChild(u),!document.getElementById("rte-source-editor-styles")){const p=document.createElement("style");p.id="rte-source-editor-styles",p.textContent=D,document.head.appendChild(p)}document.body.appendChild(d);try{r=F(k,{value:s(t),theme:"dark",readOnly:!1,extensions:[new K,new A,new V,new z,new U,new q,new _]}),r.on("change",()=>{l=(r?.getValue()||"")!==s(c);const M=y.querySelector(".unsaved-changes");M&&(M.style.display=l?"inline":"none")}),setTimeout(()=>r?.focus(),100)}catch(p){console.error("Failed to initialize code editor:",p)}const C=()=>{n=n==="dark"?"light":"dark",r?.setTheme(n);const p=h.querySelector(".theme-toggle-btn");p&&n==="light"&&(p.innerHTML=`
583
+ `,u.appendChild(d),u.appendChild(f),u.appendChild(x),h.appendChild(u),!document.getElementById("rte-source-editor-styles")){const p=document.createElement("style");p.id="rte-source-editor-styles",p.textContent=j,document.head.appendChild(p)}document.body.appendChild(h);try{r=D(T,{value:i(t),theme:"dark",readOnly:!1,extensions:[new K,new U,new z,new F,new q,new _,new W]}),r.on("change",()=>{a=(r?.getValue()||"")!==i(c);const w=x.querySelector(".unsaved-changes");w&&(w.style.display=a?"inline":"none")}),setTimeout(()=>r?.focus(),100)}catch(p){console.error("Failed to initialize code editor:",p)}const E=()=>{o=o==="dark"?"light":"dark",r?.setTheme(o);const p=d.querySelector(".theme-toggle-btn");p&&o==="light"&&(p.innerHTML=`
576
584
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
577
585
  <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
578
586
  </svg>
579
- `)},L=()=>{o=!o,r?.setReadOnly(o);const p=h.querySelector(".readonly-toggle-btn");p&&(o?(p.classList.add("active"),p.innerHTML=`
587
+ `)},L=()=>{n=!n,r?.setReadOnly(n);const p=d.querySelector(".readonly-toggle-btn");p&&(n?(p.classList.add("active"),p.innerHTML=`
580
588
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
581
589
  <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
582
590
  <circle cx="12" cy="16" r="1"/>
@@ -587,7 +595,7 @@
587
595
  <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
588
596
  <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
589
597
  </svg>
590
- `))},w=()=>{a=!a,a?(d.classList.add("fullscreen"),k.style.height="calc(100vh - 200px)"):(d.classList.remove("fullscreen"),k.style.height="400px");const p=h.querySelector(".rte-source-editor-fullscreen-btn");p&&(p.innerHTML=a?`
598
+ `))},C=()=>{l=!l,l?(h.classList.add("fullscreen"),T.style.height="calc(100vh - 200px)"):(h.classList.remove("fullscreen"),T.style.height="400px");const p=d.querySelector(".rte-source-editor-fullscreen-btn");p&&(p.innerHTML=l?`
591
599
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
592
600
  <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
593
601
  </svg>
@@ -595,4 +603,4 @@
595
603
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
596
604
  <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
597
605
  </svg>
598
- `)},b=()=>{r&&(r.destroy(),r=null),document.body.removeChild(d)},T=()=>{l&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||b()},S=()=>{try{const p=r?.getValue()||"",M=document.createElement("div");M.innerHTML=p,M.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(P=>P.remove()),e.innerHTML=M.innerHTML,l=!1,b()}catch(p){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",p)}};h.querySelector(".theme-toggle-btn")?.addEventListener("click",C),h.querySelector(".readonly-toggle-btn")?.addEventListener("click",L),h.querySelector(".rte-source-editor-fullscreen-btn")?.addEventListener("click",w),h.querySelector(".rte-source-editor-close-btn")?.addEventListener("click",b),y.querySelector(".rte-source-editor-btn-cancel")?.addEventListener("click",T),y.querySelector(".rte-source-editor-btn-save")?.addEventListener("click",S),d.addEventListener("click",p=>{p.target===d&&b()});const E=p=>{p.key==="Escape"&&(b(),document.removeEventListener("keydown",E))};document.addEventListener("keydown",E)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}});exports.CodePlugin=W;
606
+ `)},b=()=>{r&&(r.destroy(),r=null),document.body.removeChild(h)},k=()=>{a&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||b()},S=()=>{try{const p=r?.getValue()||"",w=document.createElement("div");w.innerHTML=p,w.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(I=>I.remove()),e.innerHTML=w.innerHTML;try{e.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!1,inputType:"insertReplacementText"}))}catch{e.dispatchEvent(new Event("input",{bubbles:!0}))}e.dispatchEvent(new Event("change",{bubbles:!0})),a=!1,b()}catch(p){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",p)}};d.querySelector(".theme-toggle-btn")?.addEventListener("click",E),d.querySelector(".readonly-toggle-btn")?.addEventListener("click",L),d.querySelector(".rte-source-editor-fullscreen-btn")?.addEventListener("click",C),d.querySelector(".rte-source-editor-close-btn")?.addEventListener("click",b),x.querySelector(".rte-source-editor-btn-cancel")?.addEventListener("click",k),x.querySelector(".rte-source-editor-btn-save")?.addEventListener("click",S),h.addEventListener("click",p=>{p.target===h&&b()});const O=p=>{p.key==="Escape"&&(b(),document.removeEventListener("keydown",O))};document.addEventListener("keydown",O)})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}});exports.CodePlugin=Z;