@editora/plugins 1.0.7 → 1.0.8
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.
- package/README.md +50 -4
- package/dist/_commonjsHelpers-BH3jXuIh.js +1 -0
- package/dist/_commonjsHelpers-ByX85dGu.mjs +33 -0
- package/dist/anchor.cjs.js +11 -11
- package/dist/anchor.esm.js +130 -107
- package/dist/anchoredPopover-BzqGPOAE.js +1 -0
- package/dist/anchoredPopover-Dts0IrgU.mjs +106 -0
- package/dist/background-color.cjs.js +3 -3
- package/dist/background-color.esm.js +116 -119
- package/dist/code.cjs.js +82 -102
- package/dist/code.esm.js +1172 -662
- package/dist/comments.cjs.js +10 -10
- package/dist/comments.esm.js +195 -177
- package/dist/document-manager.cjs.js +1 -1
- package/dist/document-manager.esm.js +1 -1
- package/dist/documentManager-CTqRftU8.mjs +8369 -0
- package/dist/documentManager-Jf0RbSks.js +17 -0
- package/dist/embed-iframe.cjs.js +2 -2
- package/dist/embed-iframe.esm.js +8 -5
- package/dist/emojis.cjs.js +64 -39
- package/dist/emojis.esm.js +133 -104
- package/dist/html2canvas.esm-B5qzocYs.js +5 -0
- package/dist/html2canvas.esm-BWVIUcAF.mjs +4802 -0
- package/dist/{index-Bskk414V.mjs → index-BFsKNTTj.mjs} +50 -50
- package/dist/index-CvJk4DKa.js +221 -0
- package/dist/index-D3CycEFU.mjs +16543 -0
- package/dist/index-tqLTHcO6.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-Cz1qItab.js → index.es-CE_A4QSm.js} +5 -5
- package/dist/{index.es-DEcRmSTY.mjs → index.es-DQ78mYYo.mjs} +4 -3
- package/dist/index.esm.js +87 -79
- package/dist/jspdf.es.min-BoS80556.js +77 -0
- package/dist/jspdf.es.min-DQCoX5yh.mjs +7889 -0
- package/dist/link.cjs.js +6 -6
- package/dist/link.esm.js +41 -39
- package/dist/math.cjs.js +21 -21
- package/dist/math.esm.js +151 -112
- package/dist/media-manager.cjs.js +15 -15
- package/dist/media-manager.esm.js +227 -206
- package/dist/merge-tag.cjs.js +44 -12
- package/dist/merge-tag.esm.js +368 -241
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +77 -69
- package/dist/special-characters.cjs.js +83 -45
- package/dist/special-characters.esm.js +149 -100
- package/dist/spell-check.cjs.js +9 -9
- package/dist/spell-check.esm.js +235 -216
- package/dist/template.cjs.js +14 -14
- package/dist/template.esm.js +157 -131
- package/dist/text-color.cjs.js +9 -9
- package/dist/text-color.esm.js +131 -115
- package/index.d.ts +51 -1
- package/package.json +3 -3
- package/dist/colorSelectionApply-C0iOfMWb.js +0 -1
- package/dist/colorSelectionApply-D8r_gV32.mjs +0 -63
- package/dist/documentManager-DRUc1-Cs.mjs +0 -37581
- package/dist/documentManager-_tQQfQi9.js +0 -317
- package/dist/index-D3pJyAsj.js +0 -1
package/dist/code.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class D{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
|
|
4
|
-
`)}replaceRange(e,t){const
|
|
5
|
-
`);l[0]=
|
|
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),n=i.substring(0,e.start.column)+t+i.substring(e.end.column);this._lines[e.start.line]=n}else{const i=this.getLine(e.start.line),n=this.getLine(e.end.line),r=i.substring(0,e.start.column)+t,o=n.substring(e.end.column),l=t.split(`
|
|
5
|
+
`);l[0]=r+l[0],l[l.length-1]=l[l.length-1]+o,this._lines.splice(e.start.line,e.end.line-e.start.line+1,...l)}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 D;return e._lines=[...this._lines],e._version=this._version,e}}class Z{constructor(e){this.gutterWidth=50,this.lineHeight=21,this.trailingNewlineMarkerAttr="data-lce-trailing-newline-marker",this.virtualMarkerRegex=/[\u200B\uE000]/,this.container=e,this.createDOM()}createDOM(){this.container.innerHTML="";const e=document.createElement("div");this.editorContainer=e,e.setAttribute("data-lce-editor-container","true"),e.style.cssText=`
|
|
6
6
|
position: relative;
|
|
7
7
|
display: flex;
|
|
8
8
|
width: 100%;
|
|
@@ -42,98 +42,66 @@
|
|
|
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),
|
|
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,n)=>n+1);this.lineNumbersElement.innerHTML=s.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){const 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
46
|
`));const t=e.split(`
|
|
47
|
-
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),
|
|
48
|
-
`).length;this.updateLineNumbers(
|
|
49
|
-
`))}getCursorPosition(){const e=window.getSelection();if(!e||e.rangeCount===0)return{line:0,column:0};const t=e.getRangeAt(0),
|
|
50
|
-
`);return{line:
|
|
51
|
-
`),
|
|
52
|
-
`),
|
|
53
|
-
`);return{start:{line:
|
|
47
|
+
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),s=/<|>/.test(e),i=/<span\b/i.test(e),n=/<[^>]+>/.test(e);s&&i?this.contentElement.innerHTML=e:n&&!s?this.contentElement.textContent=e:this.contentElement.innerHTML=e,this.syncTrailingNewlineMarker(t);const r=(this.contentElement.textContent||"").split(`
|
|
48
|
+
`).length;this.updateLineNumbers(r)}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),s=t.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(t.endContainer,t.endOffset);const i=s.toString().replace(/\u200B/g,"").split(`
|
|
50
|
+
`);return{line:i.length-1,column:i[i.length-1].length}}setCursorPosition(e){const t=this.getText().split(`
|
|
51
|
+
`),s=Math.min(e.line,t.length-1),i=Math.min(e.column,t[s]?.length||0);let n=0;for(let h=0;h<s;h++)n+=t[h].length+1;n+=i;const r=document.createRange(),o=window.getSelection(),l=this.resolveOffsetToDomPoint(n);if(l)try{r.setStart(l.node,l.offset),r.setEnd(l.node,l.offset),o?.removeAllRanges(),o?.addRange(r),this.ensureCaretVisible()}catch(h){console.warn("Could not set cursor position:",h)}else{const h=this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`);try{h&&h.parentNode===this.contentElement?r.setStartBefore(h):(r.selectNodeContents(this.contentElement),r.collapse(!1)),r.collapse(!0),o?.removeAllRanges(),o?.addRange(r),this.ensureCaretVisible()}catch(a){console.warn("Could not set fallback cursor position:",a)}}}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().replace(/\u200B/g,"").split(`
|
|
52
|
+
`),n=t.cloneRange();n.selectNodeContents(this.contentElement),n.setEnd(t.endContainer,t.endOffset);const r=n.toString().replace(/\u200B/g,"").split(`
|
|
53
|
+
`);return{start:{line:i.length-1,column:i[i.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){const t=this.getText().split(`
|
|
54
|
+
`),s=c=>{const u=Math.max(0,Math.min(c.line,t.length-1)),f=Math.max(0,Math.min(c.column,t[u]?t[u].length:0));let d=0;for(let g=0;g<u;g++)d+=t[g].length+1;return d+f},i=s(e.start),n=s(e.end),[r,o]=i<=n?[i,n]:[n,i],l=this.resolveOffsetToDomPoint(r),h=this.resolveOffsetToDomPoint(o);if(!l||!h)return;const a=document.createRange();try{a.setStart(l.node,l.offset),a.setEnd(h.node,h.offset);const c=window.getSelection();c?.removeAllRanges(),c?.addRange(a),this.ensureCaretVisible()}catch(c){console.warn("Could not set selection range:",c)}}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,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}getScrollElement(){return this.editorContainer}setScrollTop(e){this.editorContainer.scrollTop=e}syncTrailingNewlineMarker(e){if(this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach(s=>s.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
55
|
display: inline-block;
|
|
55
56
|
width: 0;
|
|
56
57
|
overflow: hidden;
|
|
57
58
|
pointer-events: none;
|
|
58
59
|
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
|
|
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
|
-
`)
|
|
62
|
-
`),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
" />
|
|
87
|
-
<button class="search-prev" style="
|
|
88
|
-
padding: 2px 6px;
|
|
89
|
-
background: var(--editor-gutter-background, #252526);
|
|
90
|
-
color: var(--editor-gutter-foreground, #858585);
|
|
91
|
-
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
92
|
-
border-radius: 3px;
|
|
93
|
-
cursor: pointer;
|
|
94
|
-
font-size: 11px;
|
|
95
|
-
">↑</button>
|
|
96
|
-
<button class="search-next" style="
|
|
97
|
-
padding: 2px 6px;
|
|
98
|
-
background: var(--editor-gutter-background, #252526);
|
|
99
|
-
color: var(--editor-gutter-foreground, #858585);
|
|
100
|
-
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
101
|
-
border-radius: 3px;
|
|
102
|
-
cursor: pointer;
|
|
103
|
-
font-size: 11px;
|
|
104
|
-
">↓</button>
|
|
105
|
-
<button class="search-close" style="
|
|
106
|
-
padding: 2px 6px;
|
|
107
|
-
background: var(--editor-gutter-background, #252526);
|
|
108
|
-
color: var(--editor-gutter-foreground, #858585);
|
|
109
|
-
border: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
110
|
-
border-radius: 3px;
|
|
111
|
-
cursor: pointer;
|
|
112
|
-
font-size: 11px;
|
|
113
|
-
">×</button>
|
|
60
|
+
`,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 s=t.getClientRects()[0]||t.getBoundingClientRect();if((!s||s.width===0&&s.height===0)&&e.focusNode instanceof Element?s=e.focusNode.getBoundingClientRect():(!s||s.width===0&&s.height===0)&&e.focusNode?.parentElement&&(s=e.focusNode.parentElement.getBoundingClientRect()),!s)return;const i=this.editorContainer.getBoundingClientRect(),n=12;s.bottom>i.bottom-n?this.editorContainer.scrollTop+=s.bottom-(i.bottom-n):s.top<i.top+n&&(this.editorContainer.scrollTop-=i.top+n-s.top)}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}resolveOffsetToDomPoint(e){const t=Math.max(0,e);let s=0;const i=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let n=null,r;for(;r=i.nextNode();){if(r.parentElement?.hasAttribute(this.trailingNewlineMarkerAttr))continue;n=r;const o=r.textContent||"",l=this.buildVisibleToDomMap(o),h=Math.max(0,l.length-1);if(s+h>=t){const a=Math.max(0,t-s),c=l[a]??o.length;return{node:r,offset:c}}s+=h}if(n){const o=n.textContent?.length||0;return{node:n,offset:o}}return null}buildVisibleToDomMap(e){const t=[0];let s=0;for(let i=0;i<e.length;i++){const n=e[i];this.virtualMarkerRegex.test(n)||(s+=1,t[s]=i+1)}return t}}const F=class L{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 D(this.config.value),this.view=new Z(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,n=this.textModel.positionToOffset(i),r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:o,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(t),this.view.syncTrailingNewlineMarkerForText(t),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{const i=this.view.getText();i!==this.textModel.getText()&&this.textModel.setText(i),this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text: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,n=this.textModel.positionToOffset(i),r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end));const h=r&&o!==void 0&&l!==void 0?Math.min(o,l):n;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:o,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const a=s.getRangeAt(0);a.deleteContents();const c=document.createTextNode(`
|
|
61
|
+
`);a.insertNode(c),a.setStartAfter(c),a.collapse(!0),s.removeAllRanges(),s.addRange(a),this.view.ensureCaretVisible();const u=this.view.getText();this.textModel.setText(u),this.view.syncTrailingNewlineMarkerForText(u);const f=Math.min(h+1,this.textModel.getText().length);try{const d=this.textModel.offsetToPosition(f);this.setCursor(d),this.view.ensureCaretVisible()}catch{}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const d=this.textModel.offsetToPosition(f);this.setCursor(d),this.view.ensureCaretVisible()}catch{}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}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={}){if(!e)return[];const s={query:e,caseSensitive:!1,wholeWord:!1,regex:!1,...t},i=[],n=this.textModel.getText(),{normalizedText:r,normalizedToRawOffsets:o}=this.buildSearchTextAndOffsetMap(n),l=s.caseSensitive?r:r.toLowerCase(),h=s.caseSensitive?e:e.toLowerCase();if(s.regex){let a;try{a=new RegExp(e,s.caseSensitive?"g":"gi")}catch{return[]}let c;for(;(c=a.exec(r))!==null;){const u=c[0]??"";if(u.length===0){a.lastIndex=c.index+1;continue}const f=c.index,d=c.index+u.length;s.wholeWord&&!this.isWholeWordBoundary(r,f,d)||this.pushSearchResultFromOffsets(i,f,d,r,o)}}else{let a=0,c=l.indexOf(h,a);for(;c!==-1;){const u=c+h.length;!s.wholeWord||this.isWholeWordBoundary(r,c,u)?(this.pushSearchResultFromOffsets(i,c,u,r,o),a=u):a=c+1,c=l.indexOf(h,a)}}return i}pushSearchResultFromOffsets(e,t,s,i,n){const r=n[t]??t,o=n[s]??r,l=this.textModel.offsetToPosition(r),h=this.textModel.offsetToPosition(o);e.push({range:{start:l,end:h},match:i.substring(t,s)})}isWholeWordBoundary(e,t,s){const i=t>0?e[t-1]:"",n=s<e.length?e[s]:"";return!this.isWordChar(i)&&!this.isWordChar(n)}isWordChar(e){return/^[A-Za-z0-9_]$/.test(e)}buildSearchTextAndOffsetMap(e){const t=[],s=[0];let i=0;for(let n=0;n<e.length;n++){const r=e[n];r===""||r===L.CURSOR_SENTINEL||(t.push(r),i+=1,s[i]=n+1)}return s[i]=e.length,{normalizedText:t.join(""),normalizedToRawOffsets:s}}replace(e,t){const s=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,r=this.textModel.positionToOffset(n),o=this.getSelection();let l,h;o&&(l=this.textModel.positionToOffset(o.start),h=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:s,cursorOffset:r,anchorOffset:l,focusOffset:h}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(e,t);this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.expectingProgrammaticCursor=!1,this.emit("change",[i])}replaceAll(e,t,s={}){const i=this.search(e,s);let n=0;for(let r=i.length-1;r>=0;r--)this.replace(i[r].range,t),n++;return n}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 n,r,o,l;if(t||i){n=this.getSelection();const u=this.getCollapsedSelectionOffsetInEditor();if(u!==void 0)r=u;else{const f=this.getCursor().position;r=this.textModel.positionToOffset(f)}n&&(o=this.textModel.positionToOffset(n.start),l=this.textModel.positionToOffset(n.end))}const h=(t||i)&&!n&&r!==void 0&&this.hasCollapsedSelectionInEditor(),a=h?this.insertSentinelAtOffset(e,r):e,c=s.highlightHTML(a);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(c):this.view.setHTML(c),this.view.syncTrailingNewlineMarkerForText(e),(t||i)&&requestAnimationFrame(()=>{try{if(h&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(n&&(o!==void 0||l!==void 0)){const u=o!==void 0?o:r,f=l!==void 0?l:r,d=Math.min(u,f),g=Math.max(u,f),p=this.textModel.offsetToPosition(d),y=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:p,end:y})}else if(r!==void 0){const u=this.textModel.offsetToPosition(r);this.view.setCursorPosition(u)}}catch{}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(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),s=this.view.getContentElement();if(!s.contains(t.commonAncestorContainer))return;const i=t.cloneRange();return i.selectNodeContents(s),i.setEnd(t.endContainer,t.endOffset),this.stripVirtualMarkers(i.toString()).length}stripVirtualMarkers(e){return e.replace(/\u200B/g,"").split(L.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(e,t){const s=Math.max(0,Math.min(t,e.length));return e.slice(0,s)+L.CURSOR_SENTINEL+e.slice(s)}restoreCursorFromSentinel(){const e=this.view.getContentElement(),t=window.getSelection(),s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let i=s.nextNode(),n=null,r=0;for(;i;){const o=i.textContent??"",l=o.indexOf(L.CURSOR_SENTINEL);l!==-1&&(n||(n=i,r=l),i.textContent=o.split(L.CURSOR_SENTINEL).join("")),i=s.nextNode()}if(!n||!t)return!1;try{const o=document.createRange();return o.setStart(n,r),o.collapse(!0),t.removeAllRanges(),t.addRange(o),!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 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 n=e.anchorOffset!==void 0?e.anchorOffset:i,r=e.focusOffset!==void 0?e.focusOffset:i,o=Math.min(n,r),l=Math.max(n,r),h=this.textModel.offsetToPosition(o),a=this.textModel.offsetToPosition(l);this.setSelection({start:h,end:a})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const 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 n=e.anchorOffset!==void 0?e.anchorOffset:i,r=e.focusOffset!==void 0?e.focusOffset:i,o=Math.min(n,r),l=Math.max(n,r),h=this.textModel.offsetToPosition(o),a=this.textModel.offsetToPosition(l);this.setSelection({start:h,end:a})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),s=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(e,s),n=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+s.length);if(!this.suppressHistory){const r=this.getSelection();let o,l;r&&(o=this.textModel.positionToOffset(r.start),l=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:o,focusOffset:l}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(n),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}insertNewLine(){if(this.config.readOnly)return;const e=this.getCursor().position,t=this.textModel.positionToOffset(e),s=this.textModel.insertText(e,`
|
|
62
|
+
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+1);if(!this.suppressHistory){const n=this.getSelection();let r,o;n&&(r=this.textModel.positionToOffset(n.start),o=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:t,anchorOffset:r,focusOffset:o}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(i),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[s])}on(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}};F.CURSOR_SENTINEL="";let X=F;class J{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:n,metaKey:r}=e,o=String(t).toLowerCase(),l=this.keymap[o];if(!l)return null;for(const h of l){const a=h.ctrlKey===void 0||h.ctrlKey===s,c=h.altKey===void 0||h.altKey===i,u=h.shiftKey===void 0||h.shiftKey===n,f=h.metaKey===void 0||h.metaKey===r;if(a&&c&&u&&f)return h}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 n=t.toLowerCase();e[n]||(e[n]=[]),e[n].push({key:n,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 Y{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 _{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)},(s,i)=>i+1);this.lineNumbersElement.innerHTML=t.map(s=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("")}toggle(){if(!this.editor)return;this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class G{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 ee{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}}let te=0;const W=class m{constructor(e={}){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1,this.searchDebounceTimer=null,this.liveRefreshTimer=null,this.statusResetTimer=null,this.statusFreezeUntil=0,this.findInput=null,this.replaceInputEl=null,this.statusDiv=null,this.modeDiv=null,this.caseSensitiveInput=null,this.wholeWordInput=null,this.regexInput=null,this.currentQuery="",this.savedCursor=null,this.editorChangeHandler=null,this.searchOptions={caseSensitive:!1,wholeWord:!1,regex:!1},this.trailingMarkerAttr="data-lce-trailing-newline-marker",this.editorContainerSelector='[data-lce-editor-container="true"]',this.highlightId=++te,this.highlightMatchName=`editora-search-match-${this.highlightId}`,this.highlightActiveName=`editora-search-active-${this.highlightId}`,this.highlightStyleId=`editora-search-highlight-style-${this.highlightId}`,this.maxCustomHighlightRanges=2e3,this.virtualMarkerRegex=/[\u200B\uE000]/,this.hasCustomHighlightSupport=!1,this.config={replaceAndFindNext:!0,...e}}setup(e){this.editor=e,this.hasCustomHighlightSupport=this.detectCustomHighlightSupport(),this.hasCustomHighlightSupport&&this.ensureHighlightStyles(),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)}),this.editorChangeHandler=()=>{!this.isVisible||!this.currentQuery||this.scheduleLiveRefresh(!0)},e.on("change",this.editorChangeHandler)}showSearch(){this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible||this.captureSelectionState(),this.isVisible=!0,this.searchUI&&(this.searchUI.style.display="block",this.updateModeHint(!1),this.findInput&&(this.findInput.focus(),this.findInput.select())),this.currentQuery&&this.performSearch(this.currentQuery,!0,!1))}showReplace(){this.showSearch(),this.replaceInputEl&&(this.replaceInputEl.style.display="block",this.replaceInputEl.focus()),this.updateModeHint(!0),this.currentQuery&&this.performSearch(this.currentQuery,!1,!0)}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.replaceInputEl&&(this.replaceInputEl.style.display="none",this.replaceInputEl.value=""),this.updateModeHint(!1),this.clearHighlights(),this.restoreSelectionState()}createSearchUI(){if(!this.editor)return;const e=this.editor.getView().getContentElement(),t=e.closest(this.editorContainerSelector),s=e.closest(".rte-source-editor-modal")||t||e.parentElement;if(!s)return;window.getComputedStyle(s).position==="static"&&(s.style.position="relative"),this.searchUI=document.createElement("div"),this.searchUI.className=m.css.root,this.searchUI.style.display="none",this.searchUI.innerHTML=`
|
|
64
|
+
<div class="${m.css.row}">
|
|
65
|
+
<input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
|
|
66
|
+
<button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
67
|
+
<button class="${m.css.nextButton} ${m.css.buttonBase}" type="button" aria-label="Next match">↓</button>
|
|
68
|
+
<button class="${m.css.closeButton} ${m.css.buttonBase}" type="button" aria-label="Close search">×</button>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="${m.css.options}">
|
|
71
|
+
<label class="${m.css.optionLabel}" title="Case sensitive">
|
|
72
|
+
<input type="checkbox" class="${m.css.optionInput} ${m.css.caseSensitive}" />
|
|
73
|
+
<span>Aa</span>
|
|
74
|
+
</label>
|
|
75
|
+
<label class="${m.css.optionLabel}" title="Whole word">
|
|
76
|
+
<input type="checkbox" class="${m.css.optionInput} ${m.css.wholeWord}" />
|
|
77
|
+
<span>Whole</span>
|
|
78
|
+
</label>
|
|
79
|
+
<label class="${m.css.optionLabel}" title="Regular expression">
|
|
80
|
+
<input type="checkbox" class="${m.css.optionInput} ${m.css.regex}" />
|
|
81
|
+
<span>.*</span>
|
|
82
|
+
</label>
|
|
83
|
+
</div>
|
|
84
|
+
<div class="${m.css.meta}">
|
|
85
|
+
<div class="${m.css.status} ${m.css.statusLayout}"></div>
|
|
86
|
+
<div class="${m.css.mode} ${m.css.modeLayout}" aria-live="polite"></div>
|
|
114
87
|
</div>
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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=`
|
|
88
|
+
<input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
89
|
+
`;const i=this.searchUI.querySelector(`.${m.css.findInput}`),n=this.searchUI.querySelector(`.${m.css.replaceInput}`),r=this.searchUI.querySelector(`.${m.css.prevButton}`),o=this.searchUI.querySelector(`.${m.css.nextButton}`),l=this.searchUI.querySelector(`.${m.css.closeButton}`),h=this.searchUI.querySelector(`.${m.css.status}`),a=this.searchUI.querySelector(`.${m.css.mode}`),c=this.searchUI.querySelector(`.${m.css.caseSensitive}`),u=this.searchUI.querySelector(`.${m.css.wholeWord}`),f=this.searchUI.querySelector(`.${m.css.regex}`);this.findInput=i,this.replaceInputEl=n,this.statusDiv=h,this.modeDiv=a,this.caseSensitiveInput=c,this.wholeWordInput=u,this.regexInput=f,c.checked=!!this.searchOptions.caseSensitive,u.checked=!!this.searchOptions.wholeWord,f.checked=!!this.searchOptions.regex,i.addEventListener("input",()=>{this.searchDebounceTimer&&clearTimeout(this.searchDebounceTimer);const g=i.value;this.searchDebounceTimer=setTimeout(()=>{this.performSearch(g,!1,!1)},120)});const d=()=>{this.searchOptions.caseSensitive=c.checked,this.searchOptions.wholeWord=u.checked,this.searchOptions.regex=f.checked;const g=i.value;g.trim()?this.performSearch(g,!1,!1):this.performSearch("",!1,!1)};c.addEventListener("change",d),u.addEventListener("change",d),f.addEventListener("change",d),i.addEventListener("keydown",g=>{g.key==="Enter"?(g.preventDefault(),g.shiftKey?this.findPrev():this.findNext()):g.key==="Escape"&&(g.preventDefault(),this.hideSearch())}),n.addEventListener("keydown",g=>{g.key==="Enter"?(g.preventDefault(),g.shiftKey?this.replaceAll(i.value,n.value):this.replaceCurrent(i.value,n.value)):g.key==="Escape"&&(g.preventDefault(),this.hideSearch())}),r.addEventListener("click",()=>this.findPrev()),o.addEventListener("click",()=>this.findNext()),l.addEventListener("click",()=>this.hideSearch()),s.appendChild(this.searchUI)}updateModeHint(e){this.modeDiv&&(this.modeDiv.textContent=e?`Replace: move next ${this.config.replaceAndFindNext?"ON":"OFF"}`:"Find mode")}performSearch(e,t,s){if(!this.editor||!e.trim()){this.currentQuery="",this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("");return}if(this.searchOptions.regex&&!this.isValidRegex(e)){this.currentQuery=e,this.currentResults=[],this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Invalid regular expression");return}this.currentQuery=e;const i=this.currentIndex,n=this.editor.search(e,this.searchOptions);if(this.currentResults=n,n.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("No matches");return}t&&i>=0?this.currentIndex=Math.min(i,n.length-1):this.currentIndex=0,this.updateHighlights(s)}findNext(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights(!0)}findPrev(){if(this.currentResults.length===0){this.currentQuery&&this.performSearch(this.currentQuery,!0,!0);return}this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights(!0)}replaceCurrent(e,t){if(!this.editor||!e.trim()||((this.currentQuery!==e||this.currentResults.length===0)&&this.performSearch(e,!1,!0),this.currentIndex<0||this.currentResults.length===0))return;const s=this.currentResults[this.currentIndex];if(!s)return;const i=this.computeReplacementRange(s.range.start,t);if(this.editor.replace(s.range,t),this.config.replaceAndFindNext){this.currentQuery=e;const n=this.editor.search(e,this.searchOptions);if(this.currentResults=n,n.length===0){this.currentIndex=-1,this.clearHighlights(),this.updateStatus("Replaced current occurrence"),this.restoreReplaceInputFocus();return}this.currentIndex=this.findNextResultIndexAfter(i.end,n),this.updateHighlights(!0)}else this.scrollLogicalRangeIntoView(i,!0),this.performSearch(e,!0,!1);this.currentResults.length>0||this.showTransientStatus("Replaced current occurrence"),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}replaceAll(e,t){if(!this.editor||!e.trim())return;const s=this.editor.replaceAll(e,t,this.searchOptions);this.performSearch(e,!1,!1),this.showTransientStatus(`Replaced ${s} occurrence${s===1?"":"s"}`),this.restoreReplaceInputFocus(),this.revealActiveResultAfterFocusRestore()}updateHighlights(e){if(this.clearHighlights(),this.currentResults.length===0||this.currentIndex===-1||!this.editor)return;this.applyCustomHighlights();const t=this.currentResults[this.currentIndex];t&&((e||!this.hasCustomHighlightSupport)&&this.navigateToResult(t,!this.hasCustomHighlightSupport),this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}navigateToResult(e,t){if(!this.editor)return;const s=document.activeElement,i=!!s&&(s===this.findInput||s===this.replaceInputEl);t?(this.editor.setSelection(e.range),this.centerCurrentSelectionInView()):this.scrollResultIntoView(e);const n=this.editor.getView();t&&typeof n.ensureCaretVisible=="function"&&n.ensureCaretVisible(),t&&i&&s&&requestAnimationFrame(()=>{this.focusWithoutScrolling(s)})}clearHighlights(){if(this.hasCustomHighlightSupport)try{const e=CSS;e.highlights?.delete(this.highlightMatchName),e.highlights?.delete(this.highlightActiveName)}catch{}}scrollResultIntoView(e){this.scrollLogicalRangeIntoView(e.range,!0)}scrollLogicalRangeIntoView(e,t){if(!this.editor)return;const s=this.editor.getView().getContentElement(),i=this.editor.getValue(),{lineStarts:n,lines:r}=this.buildLineStarts(i),o=this.buildTextNodeIndex(s);if(o.length===0)return;const l=this.toDomRange(e,n,r,o);if(!l)return;const h=l.startContainer.nodeType===Node.TEXT_NODE?l.startContainer.parentElement:l.startContainer,a=this.resolveScrollContainer(s);if(a){const c=l.getClientRects()[0]||l.getBoundingClientRect(),u=a.getBoundingClientRect(),f=a.scrollTop+(c.top-u.top)-u.height/2+c.height/2,d=18;let g=t?f:a.scrollTop,p=a.scrollLeft;const y=a.scrollLeft+(c.left-u.left),k=y+c.width;c.right>u.right-d?p=k-u.width+d:c.left<u.left+d&&(p=Math.max(0,y-d));const v=Math.max(0,a.scrollHeight-a.clientHeight),C=Math.max(0,a.scrollWidth-a.clientWidth);if(g=Math.min(v,Math.max(0,g)),p=Math.min(C,Math.max(0,p)),v===0&&C===0){h?.scrollIntoView({block:t?"center":"nearest",inline:"nearest",behavior:"smooth"});return}(g!==a.scrollTop||p!==a.scrollLeft)&&a.scrollTo({top:g,left:p,behavior:"smooth"});return}h?.scrollIntoView({block:t?"center":"nearest",inline:"nearest",behavior:"smooth"})}restoreReplaceInputFocus(){const e=this.replaceInputEl;!e||e.style.display==="none"||requestAnimationFrame(()=>{this.focusWithoutScrolling(e);const t=e.value.length;try{e.setSelectionRange(t,t)}catch{}})}centerCurrentSelectionInView(){if(!this.editor)return;const e=this.editor.getView().getContentElement(),t=this.resolveScrollContainer(e);if(!t)return;const s=window.getSelection();if(!s||s.rangeCount===0)return;const i=s.getRangeAt(0).cloneRange(),n=i.getClientRects()[0]||i.getBoundingClientRect();if(!n)return;const r=t.getBoundingClientRect(),o=t.scrollTop+(n.top-r.top)-r.height/2+n.height/2,l=Math.max(0,t.scrollHeight-t.clientHeight),h=Math.min(l,Math.max(0,o));h!==t.scrollTop&&t.scrollTo({top:h,behavior:"smooth"})}computeReplacementRange(e,t){const s=t.replace(/\r\n?/g,`
|
|
90
|
+
`),i=s.split(`
|
|
91
|
+
`);let n;return i.length<=1?(n={start:e,end:{line:e.line,column:e.column+s.length}},this.clampRangeToDocument(n)):(n={start:e,end:{line:e.line+i.length-1,column:i[i.length-1].length}},this.clampRangeToDocument(n))}findNextResultIndexAfter(e,t){for(let s=0;s<t.length;s++)if(this.comparePositions(t[s].range.start,e)>=0)return s;return 0}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}clampRangeToDocument(e){const t=this.editor;if(!t)return e;const s=t.getValue().split(`
|
|
92
|
+
`),i=Math.max(0,s.length-1),n=Math.max(0,Math.min(e.start.line,i)),r=Math.max(0,Math.min(e.end.line,i)),o=Math.max(0,Math.min(e.start.column,s[n]?.length||0)),l=Math.max(0,Math.min(e.end.column,s[r]?.length||0));return{start:{line:n,column:o},end:{line:r,column:l}}}focusWithoutScrolling(e){try{e.focus({preventScroll:!0})}catch{const t=[];let s=e.parentElement;for(;s;)this.canScroll(s)&&t.push({el:s,top:s.scrollTop,left:s.scrollLeft}),s=s.parentElement;const i=window.scrollX,n=window.scrollY;e.focus();for(let r=0;r<t.length;r++){const o=t[r];o.el.scrollTop=o.top,o.el.scrollLeft=o.left}window.scrollTo(i,n)}}findScrollContainer(e){let t=e;for(;t;){const s=window.getComputedStyle(t).overflowY;if((s==="auto"||s==="scroll")&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}resolveScrollContainer(e){const t=this.editor?.getView()?.getScrollElement?.()||null;return t&&this.canScroll(t)?t:this.findScrollContainer(e)}canScroll(e){return e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth}revealActiveResultAfterFocusRestore(){!this.currentResults.length||this.currentIndex<0||requestAnimationFrame(()=>{const e=this.currentResults[this.currentIndex];e&&this.scrollResultIntoView(e)})}applyCustomHighlights(){if(!this.editor||!this.hasCustomHighlightSupport||this.currentResults.length===0)return;const e=this.editor.getView().getContentElement(),t=this.editor.getValue(),{lineStarts:s,lines:i}=this.buildLineStarts(t),n=this.buildTextNodeIndex(e);if(n.length===0)return;const r=this.buildVisibleDocumentText(n),o=[];let l=null;const h=Math.min(this.currentResults.length,this.maxCustomHighlightRanges);for(let a=0;a<h;a++){const c=this.currentResults[a],u=this.searchOptions.regex?c.match||this.currentQuery:this.currentQuery||c.match,f=this.toDomRange(c.range,s,i,n,r,u);f&&(o.push(f),a===this.currentIndex&&(l=f))}if(o.length!==0)try{const a=CSS,c=window.Highlight;if(!a.highlights||!c)return;a.highlights.set(this.highlightMatchName,new c(...o)),l&&a.highlights.set(this.highlightActiveName,new c(l))}catch{}}buildLineStarts(e){const t=e.split(`
|
|
93
|
+
`),s=new Array(t.length);let i=0;for(let n=0;n<t.length;n++)s[n]=i,i+=t[n].length+1;return{lineStarts:s,lines:t}}positionToOffset(e,t,s){const i=Math.max(0,Math.min(e.line,s.length-1)),n=Math.max(0,Math.min(e.column,s[i]?.length||0));return t[i]+n}buildTextNodeIndex(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),s=[];let i=0,n;for(;n=t.nextNode();){const r=n;if(r.parentElement?.hasAttribute(this.trailingMarkerAttr))continue;const o=r.textContent||"",l=this.buildVisibleToDomMap(o),h=Math.max(0,l.length-1);h===0&&o.length===0||(s.push({node:r,start:i,end:i+h,visibleToDom:l}),i+=h)}return s}resolveDomPoint(e,t){const s=Math.max(0,e);for(let n=0;n<t.length;n++){const r=t[n];if(s<=r.end){const o=Math.max(0,s-r.start),l=r.visibleToDom[o]??r.node.textContent?.length??0;return{node:r.node,offset:l}}}const i=t[t.length-1];return i?{node:i.node,offset:i.visibleToDom[i.visibleToDom.length-1]??i.node.textContent?.length??0}:null}toDomRange(e,t,s,i,n,r){const o=this.positionToOffset(e.start,t,s),l=this.positionToOffset(e.end,t,s);let h=Math.min(o,l),a=Math.max(o,l);if(n&&r){const d=r,g=n.slice(h,a);if(g.length===d.length&&g.toLowerCase()!==d.toLowerCase()){const p=this.findNearestMatchOffset(n,d,h);p!==-1&&(h=p,a=p+d.length)}}const c=this.resolveDomPoint(h,i),u=this.resolveDomPoint(a,i);if(!c||!u)return null;const f=document.createRange();try{return f.setStart(c.node,c.offset),f.setEnd(u.node,u.offset),f}catch{return null}}buildVisibleDocumentText(e){let t="";for(let s=0;s<e.length;s++){const i=e[s].node.textContent||"";for(let n=0;n<i.length;n++){const r=i[n];this.virtualMarkerRegex.test(r)||(t+=r)}}return t}findNearestMatchOffset(e,t,s){const i=t.toLowerCase();let n=e.toLowerCase().indexOf(i);if(n===-1)return-1;let r=n,o=Math.abs(n-s);for(;n!==-1;){const l=Math.abs(n-s);if(l<o&&(o=l,r=n),l===0)return n;n=e.toLowerCase().indexOf(i,n+1)}return r}scheduleLiveRefresh(e){this.liveRefreshTimer&&clearTimeout(this.liveRefreshTimer);const t=this.currentQuery;this.liveRefreshTimer=setTimeout(()=>{!this.isVisible||!t||this.performSearch(t,e,!1)},90)}updateStatus(e,t=!1){if(this.statusDiv){if(!t&&Date.now()<this.statusFreezeUntil)return;this.statusDiv.textContent=e}}showTransientStatus(e,t=900){this.statusFreezeUntil=Date.now()+t,this.updateStatus(e,!0),this.statusResetTimer&&clearTimeout(this.statusResetTimer),this.statusResetTimer=setTimeout(()=>{this.statusFreezeUntil=0,this.syncMatchStatus()},t)}syncMatchStatus(){if(!this.currentQuery){this.updateStatus("",!0);return}if(this.currentResults.length===0||this.currentIndex<0){this.updateStatus("No matches",!0);return}this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`,!0)}isValidRegex(e){try{const t=this.searchOptions.caseSensitive?"g":"gi";return new RegExp(e,t),!0}catch{return!1}}captureSelectionState(){this.editor&&(this.savedSelection=this.editor.getSelection(),this.savedCursor=this.editor.getCursor().position)}restoreSelectionState(){this.editor&&(this.savedSelection?this.editor.setSelection(this.savedSelection):this.savedCursor&&this.editor.setCursor(this.savedCursor),this.savedSelection=void 0,this.savedCursor=null)}detectCustomHighlightSupport(){try{const e=CSS,t=window.Highlight;return!!e.highlights&&!!t}catch{return!1}}buildVisibleToDomMap(e){const t=[0];let s=0;for(let i=0;i<e.length;i++){const n=e[i];this.virtualMarkerRegex.test(n)||(s+=1,t[s]=i+1)}return t}ensureHighlightStyles(){if(document.getElementById(this.highlightStyleId))return;const e=document.createElement("style");e.id=this.highlightStyleId,e.textContent=`
|
|
94
|
+
::highlight(${this.highlightMatchName}) {
|
|
95
|
+
background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
|
|
96
|
+
border-radius: 2px;
|
|
97
|
+
}
|
|
98
|
+
::highlight(${this.highlightActiveName}) {
|
|
99
|
+
background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45));
|
|
100
|
+
border-radius: 2px;
|
|
101
|
+
}
|
|
102
|
+
`,document.head.appendChild(e)}destroy(){this.searchDebounceTimer&&(clearTimeout(this.searchDebounceTimer),this.searchDebounceTimer=null),this.liveRefreshTimer&&(clearTimeout(this.liveRefreshTimer),this.liveRefreshTimer=null),this.statusResetTimer&&(clearTimeout(this.statusResetTimer),this.statusResetTimer=null),this.clearHighlights(),this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.editor&&this.editorChangeHandler&&this.editor.off("change",this.editorChangeHandler),this.editorChangeHandler=null,this.findInput=null,this.replaceInputEl=null,this.statusDiv=null,this.modeDiv=null,this.caseSensitiveInput=null,this.wholeWordInput=null,this.regexInput=null,this.searchUI=null;const e=document.getElementById(this.highlightStyleId);e?.parentNode&&e.parentNode.removeChild(e),this.editor=null}};W.css={root:"lce-search-ui",row:"lce-search-row",options:"lce-search-options",optionLabel:"lce-search-option",optionInput:"lce-search-option-input",caseSensitive:"search-case-sensitive",wholeWord:"search-whole-word",regex:"search-regex",meta:"lce-search-meta",findInput:"search-find-input",replaceInput:"search-replace-input",inputBase:"lce-search-input",replaceInputLayout:"lce-search-replace",prevButton:"search-prev",nextButton:"search-next",closeButton:"search-close",buttonBase:"lce-search-btn",status:"search-status",statusLayout:"lce-search-status",mode:"search-mode",modeLayout:"lce-search-mode"};let se=W;class ie{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(`
|
|
103
|
+
`);if(t.line>=s.length)return null;const i=s[t.line];if(t.column>=i.length)return null;const n=i[t.column];return this.bracketPairs[n]||this.reverseBracketPairs[n]?{char:n,position:t}:null}findMatchingBracket(e,t){const s=e.split(`
|
|
104
|
+
`),i=t.position.line,n=t.position.column,r=t.char;return this.bracketPairs[r]?this.findClosingBracket(e,s,i,n,r):this.reverseBracketPairs[r]?this.findOpeningBracket(e,s,i,n,r):null}findClosingBracket(e,t,s,i,n){const r=this.bracketPairs[n];let o=0;for(let l=s;l<t.length;l++){const h=t[l],a=l===s?i:0;for(let c=a;c<h.length;c++){const u=h[c];if(u===n)o++;else if(u===r&&(o--,o===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:l,column:c},end:{line:l,column:c+1}},type:n}}}return null}findOpeningBracket(e,t,s,i,n){const r=this.reverseBracketPairs[n];let o=0;for(let l=s;l>=0;l--){const h=t[l],a=l===s?i:h.length-1;for(let c=a;c>=0;c--){const u=h[c];if(u===n)o++;else if(u===r&&(o--,o===0))return{open:{start:{line:l,column:c},end:{line:l,column:c+1}},close:{start:{line:s,column:i},end:{line:s,column:i+1}},type:r}}}return null}highlightBrackets(e){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class ne{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null,this.pendingUpdateRaf=null,this.lastSnapshot="",this.changeHandler=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()}),this.changeHandler=()=>{this.scheduleFoldIndicatorUpdate()},e.on("change",this.changeHandler),this.createFoldingUI(),this.scheduleFoldIndicatorUpdate()}createFoldingUI(){if(!this.editor)return;const e=this.editor.getView().getContentElement(),t=e.closest(".rte-source-editor-modal")||e.parentElement;t&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
|
|
137
105
|
position: absolute;
|
|
138
106
|
left: 40px;
|
|
139
107
|
top: 0;
|
|
@@ -141,8 +109,8 @@
|
|
|
141
109
|
width: 20px;
|
|
142
110
|
pointer-events: none;
|
|
143
111
|
z-index: 2;
|
|
144
|
-
`,
|
|
145
|
-
`)
|
|
112
|
+
`,t.appendChild(this.foldingUI))}scheduleFoldIndicatorUpdate(){this.pendingUpdateRaf===null&&(this.pendingUpdateRaf=requestAnimationFrame(()=>{this.pendingUpdateRaf=null,this.updateFoldIndicators()}))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;const e=this.editor.getValue();if(e===this.lastSnapshot)return;this.lastSnapshot=e,this.foldingUI.innerHTML="",this.foldIndicators=[];const t=e.split(`
|
|
113
|
+
`),s=this.findFoldableLines(t),i=document.createDocumentFragment();s.forEach(n=>{const r=this.createFoldIndicator(n);i.appendChild(r),this.foldIndicators.push(r)}),this.foldingUI.appendChild(i)}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){const t=document.createElement("div");return t.style.cssText=`
|
|
146
114
|
position: absolute;
|
|
147
115
|
left: 0;
|
|
148
116
|
top: ${e*21}px;
|
|
@@ -156,7 +124,7 @@
|
|
|
156
124
|
color: var(--editor-gutter-foreground, #858585);
|
|
157
125
|
font-size: 10px;
|
|
158
126
|
user-select: none;
|
|
159
|
-
`,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),
|
|
127
|
+
`,t.innerHTML="▶",t.title="Code folding not yet implemented - click shows fold indicators",t.addEventListener("click",()=>{}),t}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.pendingUpdateRaf!==null&&(cancelAnimationFrame(this.pendingUpdateRaf),this.pendingUpdateRaf=null),this.editor&&this.changeHandler&&this.editor.off("change",this.changeHandler),this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.changeHandler=null,this.lastSnapshot="",this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class re{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,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(e){let t=e||"";for(let s=0;s<5;s++){const i=t;if(t=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),t===i)break}return t}_highlightHTML(e,t){const s=t,i=h=>this.escapeHTML(h);let n=i(e);const r=h=>{let a=h.replace(/"/g,'"').replace(/'/g,"'");return a=a.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${s.comment};">$1</span>`),a=a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(c,u,f,d,g)=>{const p=String(d).trim(),y=i(p);return`<span style="color: ${s.styleProp};">${u}</span>${f}<span style="color: ${s.styleVal};">${y}</span>${g}`}),a},o=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(h,a,c)=>(o.push({attrs:String(a||""),inner:String(c||"")}),h))}catch{}let l=0;return n=n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(h,a,c,u,f)=>{const d=o[l++]?.inner??this.unescapeEntitiesRepeated(u||"");(o[l-1]?.attrs||c||"").toLowerCase();const g=this._highlightJS(d,s);return`${a}${g}${f}`}),n=n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(h,a,c,u)=>{const f=r(c);return`${a}${f}${u}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${s.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${s.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(h,a,c,u,f)=>{const d=`<span style="color: ${s.tag};">${c}</span>`;let g=u;return g=g.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(p,y,k,v)=>{const C=String(y).toLowerCase(),E=`<span style="color: ${s.attrName};">${y}</span>`;let S=v,b="";v.startsWith(""")&&v.endsWith(""")?(S=v.slice(6,-6),b="""):v.startsWith("'")&&v.endsWith("'")&&(S=v.slice(5,-5),b="'");let T=v;if(C==="style"){const I=S.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(B,N,$,O)=>`<span style="color: ${s.styleProp};">${N}</span>:<span style="color: ${s.styleVal};">${$.trim()}</span>${O}`);b?T=`${b}${I}${b}`:T=I,T=`<span style="color: ${s.attrValue};">${T}</span>`}else b&&(T=`${b}${S}${b}`),T=`<span style="color: ${s.attrValue};">${T}</span>`;return`${E}${k}${T}`}),`${a}${d}${g}${f}`}),n}_highlightJS(e,t){const s=this.unescapeEntitiesRepeated(e);this.escapeHTML(s);const i=[],n=u=>{let f="",d=u;do f=String.fromCharCode(97+d%26)+f,d=Math.floor(d/26)-1;while(d>=0);return f||"a"},r=u=>`\0${n(u)}\0`,o=u=>{const f=i.length;return i.push(u),r(f)};let l;const h=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let a=0,c="";for(;l=h.exec(s);){const u=l.index;a<u&&(c+=this.escapeHTML(s.slice(a,u)));const f=l[0];/^\/\*/.test(f)||/^\/\//.test(f)?c+=o(`<span style="color: ${t.comment};">${this.escapeHTML(f)}</span>`):c+=o(`<span style="color: ${t.string};">${this.escapeHTML(f)}</span>`),a=h.lastIndex}return a<s.length&&(c+=this.escapeHTML(s.slice(a))),c=c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(u,f,d)=>{const g=c[d-1]||"",p=c[d+u.length]||"";return g==="&"||g==="#"||p===";"||p==="#"?u:`<span style="color: ${t.number};">${u}</span>`}),c=c.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>`),c.replace(/\u0000([a-z]+)\u0000/g,(u,f)=>{let d=0;for(let g=0;g<f.length;g++)d=d*26+(f.charCodeAt(g)-97+1);return d=d-1,i[d]||""})}_highlightPHP(e,t){const s=this.unescapeEntitiesRepeated(e);let i=this.escapeHTML(s);const n=[],r=d=>{let g="",p=d;do g=String.fromCharCode(97+p%26)+g,p=Math.floor(p/26)-1;while(p>=0);return g||"a"},o=d=>{const g=n.length;return n.push(d),`\0${r(g)}\0`},l=(d,g)=>{const p=i.indexOf(d);return p===-1?!1:(i=i.slice(0,p)+g+i.slice(p+d.length),!0)};let h;const a=/\/\*[\s\S]*?\*\//g,c=/\/\/[^\n\r]*/g,u=/\#([^\n\r]*)/g,f=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;h=a.exec(s);){const d=h[0];l(this.escapeHTML(d),o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;h=c.exec(s);){const d=h[0];l(this.escapeHTML(d),o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;h=u.exec(s);){const d=h[0];l(this.escapeHTML(d),o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`))}for(;h=f.exec(s);){const d=h[0];l(this.escapeHTML(d),o(`<span style="color: ${t.string};">${this.escapeHTML(d)}</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,(d,g)=>{let p=0;for(let y=0;y<g.length;y++)p=p*26+(g.charCodeAt(y)-97+1);return p=p-1,n[p]||""}),i}shouldHighlight(e){return/<\/?[\w:-]+|<!--/.test(e)}destroy(){this.editor=null,this.modes.clear()}}function oe(w,e){const t={...e};return t.extensions||(t.extensions=[]),t.extensions.some(s=>s.name==="keymap")||t.extensions.unshift(new J(t.keymap)),t.extensions.some(s=>s.name==="transaction")||t.extensions.unshift(new Y),new X(w,t)}const P='[data-theme="dark"], .dark, .editora-theme-dark',le=`/* Source Editor Dialog Styles */
|
|
160
128
|
.rte-source-editor-overlay {
|
|
161
129
|
position: fixed !important;
|
|
162
130
|
top: 0 !important;
|
|
@@ -533,10 +501,10 @@
|
|
|
533
501
|
flex: 1;
|
|
534
502
|
text-align: center;
|
|
535
503
|
}
|
|
536
|
-
}`,
|
|
537
|
-
`+" ".repeat(
|
|
538
|
-
`+" ".repeat(
|
|
539
|
-
`+" ".repeat(
|
|
504
|
+
}`,ae=()=>({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 n=window.getSelection();if(n&&n.anchorNode){let o=n.anchorNode instanceof HTMLElement?n.anchorNode:n.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 l=o.querySelector(".rte-content");if(l)return l;o=o.parentElement}}const r=document.querySelector("[data-editora-editor]");if(r){const o=r.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=n=>{let r="",o=0;const l=2,h=n.split(/(<\/?[a-zA-Z][^>]*>)/);for(const a of h)a.trim()&&(a.match(/^<\/[a-zA-Z]/)?(o=Math.max(0,o-1),r+=`
|
|
505
|
+
`+" ".repeat(o*l)+a):a.match(/^<[a-zA-Z]/)&&!a.match(/\/>$/)?(r+=`
|
|
506
|
+
`+" ".repeat(o*l)+a,o++):a.match(/^<[a-zA-Z].*\/>$/)?r+=`
|
|
507
|
+
`+" ".repeat(o*l)+a:r+=a.trim());return r.trim()};return(()=>{const r=s(t);let o=null,l="dark",h=!1,a=!1,c=!1,u=!1;const f=!!e.closest(P)||document.body.matches(P)||document.documentElement.matches(P),d=document.createElement("div");d.className="rte-source-editor-overlay",f&&d.classList.add("rte-theme-dark");const g=document.createElement("div");g.className="rte-source-editor-modal",g.setAttribute("role","dialog"),g.setAttribute("aria-modal","true"),g.setAttribute("aria-labelledby","source-editor-title");const p=document.createElement("div");p.className="rte-source-editor-header",p.innerHTML=`
|
|
540
508
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
541
509
|
<div class="rte-source-editor-header-toolbar">
|
|
542
510
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -572,7 +540,7 @@
|
|
|
572
540
|
</svg>
|
|
573
541
|
</button>
|
|
574
542
|
</div>
|
|
575
|
-
`;const
|
|
543
|
+
`;const y=document.createElement("div");y.className="rte-source-editor-body";const k=document.createElement("div");k.className="rte-source-editor-content";const v=document.createElement("div");v.className="rte-source-editor-warning",v.textContent="⚠️ Advanced users only. Invalid HTML may break the editor.";const C=document.createElement("div");C.className="rte-source-editor-light-editor",C.style.height="400px",k.appendChild(v),k.appendChild(C),y.appendChild(k);const E=document.createElement("div");if(E.className="rte-source-editor-footer",E.innerHTML=`
|
|
576
544
|
<div class="rte-source-editor-footer-info">
|
|
577
545
|
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
578
546
|
</div>
|
|
@@ -580,22 +548,34 @@
|
|
|
580
548
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
581
549
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
582
550
|
</div>
|
|
583
|
-
`,
|
|
551
|
+
`,g.appendChild(p),g.appendChild(y),g.appendChild(E),d.appendChild(g),!document.getElementById("rte-source-editor-styles")){const x=document.createElement("style");x.id="rte-source-editor-styles",x.textContent=le,document.head.appendChild(x)}const S=p.querySelector(".theme-toggle-btn"),b=p.querySelector(".readonly-toggle-btn"),T=p.querySelector(".rte-source-editor-fullscreen-btn"),I=p.querySelector(".rte-source-editor-close-btn"),B=E.querySelector(".rte-source-editor-btn-cancel"),N=E.querySelector(".rte-source-editor-btn-save"),$=E.querySelector(".unsaved-changes"),O=[],R=(x,M,V,A)=>{x.addEventListener(M,V,A),O.push(()=>x.removeEventListener(M,V,A))},U=x=>{c!==x&&(c=x,$&&($.style.display=c?"inline":"none"))},H=()=>{if(!u){for(u=!0;O.length;)O.pop()?.();o&&(o.destroy(),o=null),d.isConnected&&d.remove()}},K=()=>{l=l==="dark"?"light":"dark",o?.setTheme(l),S&&(S.innerHTML=l==="light"?`
|
|
584
552
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
585
553
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
586
554
|
</svg>
|
|
587
|
-
|
|
555
|
+
`:`
|
|
556
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
557
|
+
<circle cx="12" cy="12" r="5"/>
|
|
558
|
+
<line x1="12" y1="1" x2="12" y2="3"/>
|
|
559
|
+
<line x1="12" y1="21" x2="12" y2="23"/>
|
|
560
|
+
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
|
|
561
|
+
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
|
562
|
+
<line x1="1" y1="12" x2="3" y2="12"/>
|
|
563
|
+
<line x1="21" y1="12" x2="23" y2="12"/>
|
|
564
|
+
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
|
|
565
|
+
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
|
|
566
|
+
</svg>
|
|
567
|
+
`)},z=()=>{h=!h,o?.setReadOnly(h),b&&(b.classList.toggle("active",h),b.innerHTML=h?`
|
|
588
568
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
589
569
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
590
570
|
<circle cx="12" cy="16" r="1"/>
|
|
591
571
|
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
|
|
592
572
|
</svg>
|
|
593
|
-
|
|
573
|
+
`:`
|
|
594
574
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
595
575
|
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
596
576
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
597
577
|
</svg>
|
|
598
|
-
`)
|
|
578
|
+
`)},q=()=>{a=!a,d.classList.toggle("fullscreen",a),C.style.height=a?"calc(100vh - 200px)":"400px",T&&(T.innerHTML=a?`
|
|
599
579
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
600
580
|
<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"/>
|
|
601
581
|
</svg>
|
|
@@ -603,4 +583,4 @@
|
|
|
603
583
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
604
584
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
605
585
|
</svg>
|
|
606
|
-
`)},
|
|
586
|
+
`)},Q=()=>{c&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||H()},j=()=>{try{const x=o?.getValue()||"",M=document.createElement("div");M.innerHTML=x,M.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach(A=>A.remove()),e.innerHTML=M.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})),U(!1),H()}catch(x){alert("Failed to update HTML. Please check your syntax."),console.error("HTML update error:",x)}};S&&R(S,"click",K),b&&R(b,"click",z),T&&R(T,"click",q),I&&R(I,"click",H),B&&R(B,"click",Q),N&&R(N,"click",j),R(d,"click",x=>{x.target===d&&H()}),R(document,"keydown",x=>{const M=x;M.key==="Escape"&&(M.preventDefault(),H())}),document.body.appendChild(d),requestAnimationFrame(()=>{if(!(u||!d.isConnected))try{o=oe(C,{value:r,theme:"dark",readOnly:!1,extensions:[new _,new G,new ee,new ie,new se,new ne,new re]}),o.on("change",()=>{const x=o?.getValue()||"";U(x!==r)}),requestAnimationFrame(()=>o?.focus())}catch(x){console.error("Failed to initialize code editor:",x)}})})(),!0}},keymap:{"Mod-Shift-s":"toggleSourceView","Mod-Shift-S":"toggleSourceView"}});exports.CodePlugin=ae;
|