@editora/plugins 1.0.9 → 1.0.10
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 +5 -0
- package/dist/_commonjsHelpers-6763f629.js +1 -0
- package/dist/_commonjsHelpers-c5d32002.mjs +30 -0
- package/dist/a11y-checker.cjs.js +12 -12
- package/dist/a11y-checker.esm.js +98 -80
- package/dist/anchor.cjs.js +12 -12
- package/dist/anchor.esm.js +128 -115
- package/dist/anchoredPopover-33f1358d.mjs +109 -0
- package/dist/anchoredPopover-8151d535.js +1 -0
- package/dist/approval-workflow.cjs.js +40 -40
- package/dist/approval-workflow.esm.js +249 -208
- package/dist/background-color.cjs.js +2 -2
- package/dist/background-color.esm.js +68 -55
- package/dist/blockquote.esm.js +2 -1
- package/dist/blocks-library.cjs.js +45 -45
- package/dist/blocks-library.esm.js +245 -178
- package/dist/capitalization.esm.js +2 -1
- package/dist/checklist.cjs.js +1 -1
- package/dist/checklist.esm.js +82 -58
- package/dist/citations.cjs.js +37 -37
- package/dist/citations.esm.js +512 -439
- package/dist/clear-formatting.cjs.js +1 -1
- package/dist/clear-formatting.esm.js +33 -27
- package/dist/code-sample.cjs.js +14 -14
- package/dist/code-sample.esm.js +93 -82
- package/dist/code.cjs.js +32 -32
- package/dist/code.esm.js +653 -594
- package/dist/comments.cjs.js +6 -6
- package/dist/comments.esm.js +158 -116
- package/dist/conditional-content.cjs.js +90 -90
- package/dist/conditional-content.esm.js +432 -371
- package/dist/content-rules.cjs.js +7 -7
- package/dist/content-rules.esm.js +159 -105
- package/dist/data-binding.cjs.js +46 -46
- package/dist/data-binding.esm.js +368 -328
- package/dist/direction.esm.js +18 -9
- package/dist/doc-schema.cjs.js +29 -29
- package/dist/doc-schema.esm.js +308 -240
- package/dist/document-manager.cjs.js +1 -1
- package/dist/document-manager.esm.js +5 -4
- package/dist/documentManager-25b6203c.mjs +9122 -0
- package/dist/documentManager-b69e7054.js +17 -0
- package/dist/{editorContainerHelpers-C7kdWnS0.mjs → editorContainerHelpers-69585c07.mjs} +2 -1
- package/dist/embed-iframe.cjs.js +4 -4
- package/dist/embed-iframe.esm.js +81 -73
- package/dist/emojis.cjs.js +8 -8
- package/dist/emojis.esm.js +77 -65
- package/dist/enterprise.cjs.js +1 -1
- package/dist/enterprise.esm.js +56 -54
- package/dist/font-family.cjs.js +1 -1
- package/dist/font-family.esm.js +47 -39
- package/dist/font-size.cjs.js +1 -1
- package/dist/font-size.esm.js +53 -37
- package/dist/footnote.cjs.js +2 -2
- package/dist/footnote.esm.js +117 -76
- package/dist/history.cjs.js +1 -1
- package/dist/history.esm.js +92 -70
- package/dist/html2canvas.esm-09133e29.js +22 -0
- package/dist/{html2canvas.esm-BWVIUcAF.mjs → html2canvas.esm-1a1724a1.mjs} +225 -141
- package/dist/indent.cjs.js +1 -1
- package/dist/indent.esm.js +24 -12
- package/dist/index-656d224b.js +231 -0
- package/dist/index-6a8c48bb.js +1 -0
- package/dist/index-d027b7e2.mjs +16859 -0
- package/dist/{index-BFsKNTTj.mjs → index-f04538f2.mjs} +71 -70
- package/dist/index.cjs.js +1 -1
- package/dist/index.es-730f2d98.mjs +5775 -0
- package/dist/index.es-dd40173b.js +18 -0
- package/dist/index.esm.js +128 -125
- package/dist/italic.cjs.js +1 -1
- package/dist/italic.esm.js +9 -8
- package/dist/jspdf.es.min-90db2c97.js +243 -0
- package/dist/{jspdf.es.min-DQCoX5yh.mjs → jspdf.es.min-c36a4fd8.mjs} +4682 -3658
- package/dist/line-height.cjs.js +1 -1
- package/dist/line-height.esm.js +24 -11
- package/dist/link.cjs.js +5 -5
- package/dist/link.esm.js +30 -24
- package/dist/list.cjs.js +1 -1
- package/dist/list.esm.js +25 -20
- package/dist/lite.cjs.js +1 -1
- package/dist/lite.esm.js +61 -59
- package/dist/math.cjs.js +21 -21
- package/dist/math.esm.js +146 -139
- package/dist/media-manager.cjs.js +38 -38
- package/dist/media-manager.esm.js +325 -308
- package/dist/mentions.cjs.js +9 -9
- package/dist/mentions.esm.js +286 -238
- package/dist/merge-tag.cjs.js +2 -2
- package/dist/merge-tag.esm.js +216 -177
- package/dist/page-break.cjs.js +2 -2
- package/dist/page-break.esm.js +49 -33
- package/dist/pii-redaction.cjs.js +19 -19
- package/dist/pii-redaction.esm.js +463 -393
- package/dist/preview.esm.js +10 -5
- package/dist/print.cjs.js +4 -4
- package/dist/print.esm.js +20 -17
- package/dist/{purify.es-DHhaBdbu.mjs → purify.es-35a15df8.mjs} +19 -9
- package/dist/{purify.es-T2a3nLiC.js → purify.es-a8d731c6.js} +1 -1
- package/dist/slash-commands.cjs.js +3 -3
- package/dist/slash-commands.esm.js +212 -176
- package/dist/smart-paste.cjs.js +27 -27
- package/dist/smart-paste.esm.js +336 -280
- package/dist/special-characters.cjs.js +7 -7
- package/dist/special-characters.esm.js +69 -61
- package/dist/spell-check.cjs.js +5 -5
- package/dist/spell-check.esm.js +123 -97
- package/dist/strikethrough.cjs.js +1 -1
- package/dist/strikethrough.esm.js +19 -14
- package/dist/style.css +1 -0
- package/dist/table.cjs.js +4 -4
- package/dist/table.esm.js +225 -191
- package/dist/template.cjs.js +11 -11
- package/dist/template.esm.js +153 -124
- package/dist/text-alignment.cjs.js +1 -1
- package/dist/text-alignment.esm.js +27 -21
- package/dist/text-color.cjs.js +3 -3
- package/dist/text-color.esm.js +87 -70
- package/dist/track-changes.cjs.js +2 -2
- package/dist/track-changes.esm.js +162 -100
- package/dist/translation-workflow.cjs.js +74 -74
- package/dist/translation-workflow.esm.js +678 -602
- package/dist/version-diff.cjs.js +14 -14
- package/dist/version-diff.esm.js +157 -128
- package/package.json +13 -7
- package/LICENSE +0 -21
- package/dist/_commonjsHelpers-BH3jXuIh.js +0 -1
- package/dist/_commonjsHelpers-ByX85dGu.mjs +0 -33
- package/dist/anchoredPopover-BzqGPOAE.js +0 -1
- package/dist/anchoredPopover-Dts0IrgU.mjs +0 -106
- package/dist/documentManager-CTqRftU8.mjs +0 -8369
- package/dist/documentManager-Jf0RbSks.js +0 -17
- package/dist/html2canvas.esm-B5qzocYs.js +0 -5
- package/dist/index-CvJk4DKa.js +0 -221
- package/dist/index-D3CycEFU.mjs +0 -16543
- package/dist/index-tqLTHcO6.js +0 -1
- package/dist/index.es-CE_A4QSm.js +0 -5
- package/dist/index.es-DQ78mYYo.mjs +0 -6665
- package/dist/jspdf.es.min-BoS80556.js +0 -77
- package/dist/plugins.css +0 -1
- /package/dist/{editorContainerHelpers-CFbfiOJI.js → editorContainerHelpers-36b8ddf3.js} +0 -0
package/dist/code.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
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
|
-
`);
|
|
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),n=s.substring(0,e.start.column)+t+s.substring(e.end.column);this._lines[e.start.line]=n}else{const s=this.getLine(e.start.line),n=this.getLine(e.end.line),r=s.substring(0,e.start.column)+t,o=n.substring(e.end.column),a=t.split(`
|
|
5
|
+
`);a[0]=r+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: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 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,25 +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),
|
|
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,n)=>n+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
46
|
`));const t=e.split(`
|
|
47
|
-
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),
|
|
47
|
+
`).length;this.updateLineNumbers(t)}setHTML(e){const t=/\n$/.test(e),i=/<|>/.test(e),s=/<span\b/i.test(e),n=/<[^>]+>/.test(e);i&&s?this.contentElement.innerHTML=e:n&&!i?this.contentElement.textContent=e:this.contentElement.innerHTML=e,this.syncTrailingNewlineMarker(t);const r=(this.contentElement.textContent||"").split(`
|
|
48
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),
|
|
50
|
-
`);return{line:
|
|
51
|
-
`),s=Math.min(e.line,
|
|
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){var t;const i=this.getText().split(`
|
|
51
|
+
`),s=Math.min(e.line,i.length-1),n=Math.min(e.column,((t=i[s])==null?void 0:t.length)||0);let r=0;for(let l=0;l<s;l++)r+=i[l].length+1;r+=n;const o=document.createRange(),a=window.getSelection(),h=this.resolveOffsetToDomPoint(r);if(h)try{o.setStart(h.node,h.offset),o.setEnd(h.node,h.offset),a==null||a.removeAllRanges(),a==null||a.addRange(o),this.ensureCaretVisible()}catch(l){console.warn("Could not set cursor position:",l)}else{const l=this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`);try{l&&l.parentNode===this.contentElement?o.setStartBefore(l):(o.selectNodeContents(this.contentElement),o.collapse(!1)),o.collapse(!0),a==null||a.removeAllRanges(),a==null||a.addRange(o),this.ensureCaretVisible()}catch(c){console.warn("Could not set fallback cursor position:",c)}}}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
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:
|
|
54
|
-
`),
|
|
53
|
+
`);return{start:{line:s.length-1,column:s[s.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(e){const t=this.getText().split(`
|
|
54
|
+
`),i=c=>{const d=Math.max(0,Math.min(c.line,t.length-1)),p=Math.max(0,Math.min(c.column,t[d]?t[d].length:0));let u=0;for(let g=0;g<d;g++)u+=t[g].length+1;return u+p},s=i(e.start),n=i(e.end),[r,o]=s<=n?[s,n]:[n,s],a=this.resolveOffsetToDomPoint(r),h=this.resolveOffsetToDomPoint(o);if(!a||!h)return;const l=document.createRange();try{l.setStart(a.node,a.offset),l.setEnd(h.node,h.offset);const c=window.getSelection();c==null||c.removeAllRanges(),c==null||c.addRange(l),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,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}getScrollElement(){return this.editorContainer}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=`
|
|
55
55
|
display: inline-block;
|
|
56
56
|
width: 0;
|
|
57
57
|
overflow: hidden;
|
|
58
58
|
pointer-events: none;
|
|
59
59
|
user-select: none;
|
|
60
|
-
`,t.appendChild(document.createTextNode("")),this.contentElement.appendChild(t)}ensureCaretVisible(){const
|
|
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
|
-
`),
|
|
63
|
-
`).length,t=Array.from({length:Math.max(e,20)},(s
|
|
60
|
+
`,t.appendChild(document.createTextNode("")),this.contentElement.appendChild(t)}ensureCaretVisible(){var e;const t=window.getSelection();if(!t||t.rangeCount===0)return;const i=t.getRangeAt(0).cloneRange();i.collapse(!1);let s=i.getClientRects()[0]||i.getBoundingClientRect();if((!s||s.width===0&&s.height===0)&&t.focusNode instanceof Element?s=t.focusNode.getBoundingClientRect():(!s||s.width===0&&s.height===0)&&(e=t.focusNode)!=null&&e.parentElement&&(s=t.focusNode.parentElement.getBoundingClientRect()),!s)return;const n=this.editorContainer.getBoundingClientRect(),r=12;s.bottom>n.bottom-r?this.editorContainer.scrollTop+=s.bottom-(n.bottom-r):s.top<n.top+r&&(this.editorContainer.scrollTop-=n.top+r-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){var t;const i=Math.max(0,e);let s=0;const n=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let r=null,o;for(;o=n.nextNode();){const a=o.parentElement;if(a!=null&&a.hasAttribute(this.trailingNewlineMarkerAttr))continue;r=o;const h=o.textContent||"",l=this.buildVisibleToDomMap(h),c=Math.max(0,l.length-1);if(s+c>=i){const d=Math.max(0,i-s),p=l[d]??h.length;return{node:o,offset:p}}s+=c}if(r){const a=((t=r.textContent)==null?void 0:t.length)||0;return{node:r,offset:a}}return null}buildVisibleToDomMap(e){const t=[0];let i=0;for(let s=0;s<e.length;s++){const n=e[s];this.virtualMarkerRegex.test(n)||(i+=1,t[i]=s+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(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,n=this.textModel.positionToOffset(s),r=this.getSelection();let o,a;r&&(o=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end)),this.undoStack.push({text:i,cursorOffset:n,anchorOffset:o,focusOffset:a}),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,n=this.textModel.positionToOffset(s),r=this.getSelection();let o,a;r&&(o=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.end));const h=r&&o!==void 0&&a!==void 0?Math.min(o,a):n;this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:o,focusOffset:a}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const l=i.getRangeAt(0);l.deleteContents();const c=document.createTextNode(`
|
|
61
|
+
`);l.insertNode(c),l.setStartAfter(c),l.collapse(!0),i.removeAllRanges(),i.addRange(l),this.view.ensureCaretVisible();const d=this.view.getText();this.textModel.setText(d),this.view.syncTrailingNewlineMarkerForText(d);const p=Math.min(h+1,this.textModel.getText().length);try{const u=this.textModel.offsetToPosition(p);this.setCursor(u),this.view.ensureCaretVisible()}catch{}this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{const u=this.textModel.offsetToPosition(p);this.setCursor(u),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={}){if(!e)return[];const i={query:e,caseSensitive:!1,wholeWord:!1,regex:!1,...t},s=[],n=this.textModel.getText(),{normalizedText:r,normalizedToRawOffsets:o}=this.buildSearchTextAndOffsetMap(n),a=i.caseSensitive?r:r.toLowerCase(),h=i.caseSensitive?e:e.toLowerCase();if(i.regex){let l;try{l=new RegExp(e,i.caseSensitive?"g":"gi")}catch{return[]}let c;for(;(c=l.exec(r))!==null;){const d=c[0]??"";if(d.length===0){l.lastIndex=c.index+1;continue}const p=c.index,u=c.index+d.length;i.wholeWord&&!this.isWholeWordBoundary(r,p,u)||this.pushSearchResultFromOffsets(s,p,u,r,o)}}else{let l=0,c=a.indexOf(h,l);for(;c!==-1;){const d=c+h.length;!i.wholeWord||this.isWholeWordBoundary(r,c,d)?(this.pushSearchResultFromOffsets(s,c,d,r,o),l=d):l=c+1,c=a.indexOf(h,l)}}return s}pushSearchResultFromOffsets(e,t,i,s,n){const r=n[t]??t,o=n[i]??r,a=this.textModel.offsetToPosition(r),h=this.textModel.offsetToPosition(o);e.push({range:{start:a,end:h},match:s.substring(t,i)})}isWholeWordBoundary(e,t,i){const s=t>0?e[t-1]:"",n=i<e.length?e[i]:"";return!this.isWordChar(s)&&!this.isWordChar(n)}isWordChar(e){return/^[A-Za-z0-9_]$/.test(e)}buildSearchTextAndOffsetMap(e){const t=[],i=[0];let s=0;for(let n=0;n<e.length;n++){const r=e[n];r===""||r===L.CURSOR_SENTINEL||(t.push(r),s+=1,i[s]=n+1)}return i[s]=e.length,{normalizedText:t.join(""),normalizedToRawOffsets:i}}replace(e,t){const i=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,r=this.textModel.positionToOffset(n),o=this.getSelection();let a,h;o&&(a=this.textModel.positionToOffset(o.start),h=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:i,cursorOffset:r,anchorOffset:a,focusOffset:h}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const s=this.textModel.replaceRange(e,t);this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.expectingProgrammaticCursor=!1,this.emit("change",[s])}replaceAll(e,t,i={}){const s=this.search(e,i);let n=0;for(let r=s.length-1;r>=0;r--)this.replace(s[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 i=this.extensions.get("syntax-highlighting");if(i&&typeof i.highlightHTML=="function")try{const s=!t&&!this.expectingProgrammaticCursor;let n,r,o,a;if(t||s){n=this.getSelection();const d=this.getCollapsedSelectionOffsetInEditor();if(d!==void 0)r=d;else{const p=this.getCursor().position;r=this.textModel.positionToOffset(p)}n&&(o=this.textModel.positionToOffset(n.start),a=this.textModel.positionToOffset(n.end))}const h=(t||s)&&!n&&r!==void 0&&this.hasCollapsedSelectionInEditor(),l=h?this.insertSentinelAtOffset(e,r):e,c=i.highlightHTML(l);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(c):this.view.setHTML(c),this.view.syncTrailingNewlineMarkerForText(e),(t||s)&&requestAnimationFrame(()=>{try{if(h&&this.restoreCursorFromSentinel()){this.view.ensureCaretVisible();return}if(n&&(o!==void 0||a!==void 0)){const d=o!==void 0?o:r,p=a!==void 0?a:r,u=Math.min(d,p),g=Math.max(d,p),f=this.textModel.offsetToPosition(u),y=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:f,end:y})}else if(r!==void 0){const d=this.textModel.offsetToPosition(r);this.view.setCursorPosition(d)}}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(L.CURSOR_SENTINEL).join("")}insertSentinelAtOffset(e,t){const i=Math.max(0,Math.min(t,e.length));return e.slice(0,i)+L.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(),n=null,r=0;for(;s;){const o=s.textContent??"",a=o.indexOf(L.CURSOR_SENTINEL);a!==-1&&(n||(n=s,r=a),s.textContent=o.split(L.CURSOR_SENTINEL).join("")),s=i.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 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 n=e.anchorOffset!==void 0?e.anchorOffset:s,r=e.focusOffset!==void 0?e.focusOffset:s,o=Math.min(n,r),a=Math.max(n,r),h=this.textModel.offsetToPosition(o),l=this.textModel.offsetToPosition(a);this.setSelection({start:h,end:l})}else{const n=this.textModel.offsetToPosition(s);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 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 n=e.anchorOffset!==void 0?e.anchorOffset:s,r=e.focusOffset!==void 0?e.focusOffset:s,o=Math.min(n,r),a=Math.max(n,r),h=this.textModel.offsetToPosition(o),l=this.textModel.offsetToPosition(a);this.setSelection({start:h,end:l})}else{const n=this.textModel.offsetToPosition(s);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),i=" ".repeat(this.config.tabSize||2),s=this.textModel.insertText(e,i),n=this.textModel.offsetToPosition(this.textModel.positionToOffset(e)+i.length);if(!this.suppressHistory){const r=this.getSelection();let o,a;r&&(o=this.textModel.positionToOffset(r.start),a=this.textModel.positionToOffset(r.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(n),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 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(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}};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:i,altKey:s,shiftKey:n,metaKey:r}=e,o=String(t).toLowerCase(),a=this.keymap[o];if(!a)return null;for(const h of a){const l=h.ctrlKey===void 0||h.ctrlKey===i,c=h.altKey===void 0||h.altKey===s,d=h.shiftKey===void 0||h.shiftKey===n,p=h.metaKey===void 0||h.metaKey===r;if(l&&c&&d&&p)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,i,s){const n=t.toLowerCase();e[n]||(e[n]=[]),e[n].push({key:n,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 Y{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 _{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 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,i)=>{this.replaceAll(t,i)}),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),i=e.closest(".rte-source-editor-modal")||t||e.parentElement;if(!i)return;window.getComputedStyle(i).position==="static"&&(i.style.position="relative"),this.searchUI=document.createElement("div"),this.searchUI.className=m.css.root,this.searchUI.style.display="none",this.searchUI.innerHTML=`
|
|
64
64
|
<div class="${m.css.row}">
|
|
65
65
|
<input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
|
|
66
66
|
<button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
@@ -86,11 +86,11 @@
|
|
|
86
86
|
<div class="${m.css.mode} ${m.css.modeLayout}" aria-live="polite"></div>
|
|
87
87
|
</div>
|
|
88
88
|
<input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
89
|
-
`;const
|
|
90
|
-
`),i
|
|
91
|
-
`);let n;return
|
|
92
|
-
`),
|
|
93
|
-
`),
|
|
89
|
+
`;const s=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}`),a=this.searchUI.querySelector(`.${m.css.closeButton}`),h=this.searchUI.querySelector(`.${m.css.status}`),l=this.searchUI.querySelector(`.${m.css.mode}`),c=this.searchUI.querySelector(`.${m.css.caseSensitive}`),d=this.searchUI.querySelector(`.${m.css.wholeWord}`),p=this.searchUI.querySelector(`.${m.css.regex}`);this.findInput=s,this.replaceInputEl=n,this.statusDiv=h,this.modeDiv=l,this.caseSensitiveInput=c,this.wholeWordInput=d,this.regexInput=p,c.checked=!!this.searchOptions.caseSensitive,d.checked=!!this.searchOptions.wholeWord,p.checked=!!this.searchOptions.regex,s.addEventListener("input",()=>{this.searchDebounceTimer&&clearTimeout(this.searchDebounceTimer);const g=s.value;this.searchDebounceTimer=setTimeout(()=>{this.performSearch(g,!1,!1)},120)});const u=()=>{this.searchOptions.caseSensitive=c.checked,this.searchOptions.wholeWord=d.checked,this.searchOptions.regex=p.checked;const g=s.value;g.trim()?this.performSearch(g,!1,!1):this.performSearch("",!1,!1)};c.addEventListener("change",u),d.addEventListener("change",u),p.addEventListener("change",u),s.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(s.value,n.value):this.replaceCurrent(s.value,n.value)):g.key==="Escape"&&(g.preventDefault(),this.hideSearch())}),r.addEventListener("click",()=>this.findPrev()),o.addEventListener("click",()=>this.findNext()),a.addEventListener("click",()=>this.hideSearch()),i.appendChild(this.searchUI)}updateModeHint(e){this.modeDiv&&(this.modeDiv.textContent=e?`Replace: move next ${this.config.replaceAndFindNext?"ON":"OFF"}`:"Find mode")}performSearch(e,t,i){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 s=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&&s>=0?this.currentIndex=Math.min(s,n.length-1):this.currentIndex=0,this.updateHighlights(i)}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 i=this.currentResults[this.currentIndex];if(!i)return;const s=this.computeReplacementRange(i.range.start,t);if(this.editor.replace(i.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(s.end,n),this.updateHighlights(!0)}else this.scrollLogicalRangeIntoView(s,!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 i=this.editor.replaceAll(e,t,this.searchOptions);this.performSearch(e,!1,!1),this.showTransientStatus(`Replaced ${i} occurrence${i===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 i=document.activeElement,s=!!i&&(i===this.findInput||i===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&&s&&i&&requestAnimationFrame(()=>{this.focusWithoutScrolling(i)})}clearHighlights(){var e,t;if(this.hasCustomHighlightSupport)try{const i=CSS;(e=i.highlights)==null||e.delete(this.highlightMatchName),(t=i.highlights)==null||t.delete(this.highlightActiveName)}catch{}}scrollResultIntoView(e){this.scrollLogicalRangeIntoView(e.range,!0)}scrollLogicalRangeIntoView(e,t){if(!this.editor)return;const i=this.editor.getView().getContentElement(),s=this.editor.getValue(),{lineStarts:n,lines:r}=this.buildLineStarts(s),o=this.buildTextNodeIndex(i);if(o.length===0)return;const a=this.toDomRange(e,n,r,o);if(!a)return;const h=a.startContainer.nodeType===Node.TEXT_NODE?a.startContainer.parentElement:a.startContainer,l=this.resolveScrollContainer(i);if(l){const c=a.getClientRects()[0]||a.getBoundingClientRect(),d=l.getBoundingClientRect(),p=l.scrollTop+(c.top-d.top)-d.height/2+c.height/2,u=18;let g=t?p:l.scrollTop,f=l.scrollLeft;const y=l.scrollLeft+(c.left-d.left),k=y+c.width;c.right>d.right-u?f=k-d.width+u:c.left<d.left+u&&(f=Math.max(0,y-u));const v=Math.max(0,l.scrollHeight-l.clientHeight),C=Math.max(0,l.scrollWidth-l.clientWidth);if(g=Math.min(v,Math.max(0,g)),f=Math.min(C,Math.max(0,f)),v===0&&C===0){h==null||h.scrollIntoView({block:t?"center":"nearest",inline:"nearest",behavior:"smooth"});return}(g!==l.scrollTop||f!==l.scrollLeft)&&l.scrollTo({top:g,left:f,behavior:"smooth"});return}h==null||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 i=window.getSelection();if(!i||i.rangeCount===0)return;const s=i.getRangeAt(0).cloneRange(),n=s.getClientRects()[0]||s.getBoundingClientRect();if(!n)return;const r=t.getBoundingClientRect(),o=t.scrollTop+(n.top-r.top)-r.height/2+n.height/2,a=Math.max(0,t.scrollHeight-t.clientHeight),h=Math.min(a,Math.max(0,o));h!==t.scrollTop&&t.scrollTo({top:h,behavior:"smooth"})}computeReplacementRange(e,t){const i=t.replace(/\r\n?/g,`
|
|
90
|
+
`),s=i.split(`
|
|
91
|
+
`);let n;return s.length<=1?(n={start:e,end:{line:e.line,column:e.column+i.length}},this.clampRangeToDocument(n)):(n={start:e,end:{line:e.line+s.length-1,column:s[s.length-1].length}},this.clampRangeToDocument(n))}findNextResultIndexAfter(e,t){for(let i=0;i<t.length;i++)if(this.comparePositions(t[i].range.start,e)>=0)return i;return 0}comparePositions(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}clampRangeToDocument(e){var t,i;const s=this.editor;if(!s)return e;const n=s.getValue().split(`
|
|
92
|
+
`),r=Math.max(0,n.length-1),o=Math.max(0,Math.min(e.start.line,r)),a=Math.max(0,Math.min(e.end.line,r)),h=Math.max(0,Math.min(e.start.column,((t=n[o])==null?void 0:t.length)||0)),l=Math.max(0,Math.min(e.end.column,((i=n[a])==null?void 0:i.length)||0));return{start:{line:o,column:h},end:{line:a,column:l}}}focusWithoutScrolling(e){try{e.focus({preventScroll:!0})}catch{const t=[];let i=e.parentElement;for(;i;)this.canScroll(i)&&t.push({el:i,top:i.scrollTop,left:i.scrollLeft}),i=i.parentElement;const s=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(s,n)}}findScrollContainer(e){let t=e;for(;t;){const i=window.getComputedStyle(t).overflowY;if((i==="auto"||i==="scroll")&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return null}resolveScrollContainer(e){var t,i;const s=(t=this.editor)==null?void 0:t.getView(),n=((i=s==null?void 0:s.getScrollElement)==null?void 0:i.call(s))||null;return n&&this.canScroll(n)?n: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:i,lines:s}=this.buildLineStarts(t),n=this.buildTextNodeIndex(e);if(n.length===0)return;const r=this.buildVisibleDocumentText(n),o=[];let a=null;const h=Math.min(this.currentResults.length,this.maxCustomHighlightRanges);for(let l=0;l<h;l++){const c=this.currentResults[l],d=this.searchOptions.regex?c.match||this.currentQuery:this.currentQuery||c.match,p=this.toDomRange(c.range,i,s,n,r,d);p&&(o.push(p),l===this.currentIndex&&(a=p))}if(o.length!==0)try{const l=CSS,c=window.Highlight;if(!l.highlights||!c)return;l.highlights.set(this.highlightMatchName,new c(...o)),a&&l.highlights.set(this.highlightActiveName,new c(a))}catch{}}buildLineStarts(e){const t=e.split(`
|
|
93
|
+
`),i=new Array(t.length);let s=0;for(let n=0;n<t.length;n++)i[n]=s,s+=t[n].length+1;return{lineStarts:i,lines:t}}positionToOffset(e,t,i){var s;const n=Math.max(0,Math.min(e.line,i.length-1)),r=Math.max(0,Math.min(e.column,((s=i[n])==null?void 0:s.length)||0));return t[n]+r}buildTextNodeIndex(e){const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),i=[];let s=0,n;for(;n=t.nextNode();){const r=n,o=r.parentElement;if(o!=null&&o.hasAttribute(this.trailingMarkerAttr))continue;const a=r.textContent||"",h=this.buildVisibleToDomMap(a),l=Math.max(0,h.length-1);l===0&&a.length===0||(i.push({node:r,start:s,end:s+l,visibleToDom:h}),s+=l)}return i}resolveDomPoint(e,t){var i,s;const n=Math.max(0,e);for(let o=0;o<t.length;o++){const a=t[o];if(n<=a.end){const h=Math.max(0,n-a.start),l=a.visibleToDom[h]??((i=a.node.textContent)==null?void 0:i.length)??0;return{node:a.node,offset:l}}}const r=t[t.length-1];return r?{node:r.node,offset:r.visibleToDom[r.visibleToDom.length-1]??((s=r.node.textContent)==null?void 0:s.length)??0}:null}toDomRange(e,t,i,s,n,r){const o=this.positionToOffset(e.start,t,i),a=this.positionToOffset(e.end,t,i);let h=Math.min(o,a),l=Math.max(o,a);if(n&&r){const u=r,g=n.slice(h,l);if(g.length===u.length&&g.toLowerCase()!==u.toLowerCase()){const f=this.findNearestMatchOffset(n,u,h);f!==-1&&(h=f,l=f+u.length)}}const c=this.resolveDomPoint(h,s),d=this.resolveDomPoint(l,s);if(!c||!d)return null;const p=document.createRange();try{return p.setStart(c.node,c.offset),p.setEnd(d.node,d.offset),p}catch{return null}}buildVisibleDocumentText(e){let t="";for(let i=0;i<e.length;i++){const s=e[i].node.textContent||"";for(let n=0;n<s.length;n++){const r=s[n];this.virtualMarkerRegex.test(r)||(t+=r)}}return t}findNearestMatchOffset(e,t,i){const s=t.toLowerCase();let n=e.toLowerCase().indexOf(s);if(n===-1)return-1;let r=n,o=Math.abs(n-i);for(;n!==-1;){const a=Math.abs(n-i);if(a<o&&(o=a,r=n),a===0)return n;n=e.toLowerCase().indexOf(s,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 i=0;for(let s=0;s<e.length;s++){const n=e[s];this.virtualMarkerRegex.test(n)||(i+=1,t[i]=s+1)}return t}ensureHighlightStyles(){if(document.getElementById(this.highlightStyleId))return;const e=document.createElement("style");e.id=this.highlightStyleId,e.textContent=`
|
|
94
94
|
::highlight(${this.highlightMatchName}) {
|
|
95
95
|
background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
|
|
96
96
|
border-radius: 2px;
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45));
|
|
100
100
|
border-radius: 2px;
|
|
101
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
|
|
103
|
-
`);if(t.line>=
|
|
104
|
-
`),
|
|
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!=null&&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 ie=W;class se{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(`
|
|
103
|
+
`);if(t.line>=i.length)return null;const s=i[t.line];if(t.column>=s.length)return null;const n=s[t.column];return this.bracketPairs[n]||this.reverseBracketPairs[n]?{char:n,position:t}:null}findMatchingBracket(e,t){const i=e.split(`
|
|
104
|
+
`),s=t.position.line,n=t.position.column,r=t.char;return this.bracketPairs[r]?this.findClosingBracket(e,i,s,n,r):this.reverseBracketPairs[r]?this.findOpeningBracket(e,i,s,n,r):null}findClosingBracket(e,t,i,s,n){const r=this.bracketPairs[n];let o=0;for(let a=i;a<t.length;a++){const h=t[a],l=a===i?s:0;for(let c=l;c<h.length;c++){const d=h[c];if(d===n)o++;else if(d===r&&(o--,o===0))return{open:{start:{line:i,column:s},end:{line:i,column:s+1}},close:{start:{line:a,column:c},end:{line:a,column:c+1}},type:n}}}return null}findOpeningBracket(e,t,i,s,n){const r=this.reverseBracketPairs[n];let o=0;for(let a=i;a>=0;a--){const h=t[a],l=a===i?s:h.length-1;for(let c=l;c>=0;c--){const d=h[c];if(d===n)o++;else if(d===r&&(o--,o===0))return{open:{start:{line:a,column:c},end:{line:a,column:c+1}},close:{start:{line:i,column:s},end:{line:i,column:s+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=`
|
|
105
105
|
position: absolute;
|
|
106
106
|
left: 40px;
|
|
107
107
|
top: 0;
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
pointer-events: none;
|
|
111
111
|
z-index: 2;
|
|
112
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
|
-
`),
|
|
113
|
+
`),i=this.findFoldableLines(t),s=document.createDocumentFragment();i.forEach(n=>{const r=this.createFoldIndicator(n);s.appendChild(r),this.foldIndicators.push(r)}),this.foldingUI.appendChild(s)}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){const t=document.createElement("div");return t.style.cssText=`
|
|
114
114
|
position: absolute;
|
|
115
115
|
left: 0;
|
|
116
116
|
top: ${e*21}px;
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
color: var(--editor-gutter-foreground, #858585);
|
|
125
125
|
font-size: 10px;
|
|
126
126
|
user-select: none;
|
|
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,
|
|
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,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,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(e){let t=e||"";for(let i=0;i<5;i++){const s=t;if(t=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),t===s)break}return t}_highlightHTML(e,t){const i=t,s=h=>this.escapeHTML(h);let n=s(e);const r=h=>{let l=h.replace(/"/g,'"').replace(/'/g,"'");return l=l.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${i.comment};">$1</span>`),l=l.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(c,d,p,u,g)=>{const f=String(u).trim(),y=s(f);return`<span style="color: ${i.styleProp};">${d}</span>${p}<span style="color: ${i.styleVal};">${y}</span>${g}`}),l},o=[];try{e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(h,l,c)=>(o.push({attrs:String(l||""),inner:String(c||"")}),h))}catch{}let a=0;return n=n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(h,l,c,d,p)=>{var u,g;const f=((u=o[a++])==null?void 0:u.inner)??this.unescapeEntitiesRepeated(d||"");(((g=o[a-1])==null?void 0:g.attrs)||c||"").toLowerCase();const y=this._highlightJS(f,i);return`${l}${y}${p}`}),n=n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(h,l,c,d)=>{const p=r(c);return`${l}${p}${d}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${i.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${i.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(h,l,c,d,p)=>{const u=`<span style="color: ${i.tag};">${c}</span>`;let g=d;return g=g.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(f,y,k,v)=>{const C=String(y).toLowerCase(),E=`<span style="color: ${i.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: ${i.styleProp};">${N}</span>:<span style="color: ${i.styleVal};">${$.trim()}</span>${O}`);b?T=`${b}${I}${b}`:T=I,T=`<span style="color: ${i.attrValue};">${T}</span>`}else b&&(T=`${b}${S}${b}`),T=`<span style="color: ${i.attrValue};">${T}</span>`;return`${E}${k}${T}`}),`${l}${u}${g}${p}`}),n}_highlightJS(e,t){const i=this.unescapeEntitiesRepeated(e);this.escapeHTML(i);const s=[],n=d=>{let p="",u=d;do p=String.fromCharCode(97+u%26)+p,u=Math.floor(u/26)-1;while(u>=0);return p||"a"},r=d=>`\0${n(d)}\0`,o=d=>{const p=s.length;return s.push(d),r(p)};let a;const h=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let l=0,c="";for(;a=h.exec(i);){const d=a.index;l<d&&(c+=this.escapeHTML(i.slice(l,d)));const p=a[0];/^\/\*/.test(p)||/^\/\//.test(p)?c+=o(`<span style="color: ${t.comment};">${this.escapeHTML(p)}</span>`):c+=o(`<span style="color: ${t.string};">${this.escapeHTML(p)}</span>`),l=h.lastIndex}return l<i.length&&(c+=this.escapeHTML(i.slice(l))),c=c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(d,p,u)=>{const g=c[u-1]||"",f=c[u+d.length]||"";return g==="&"||g==="#"||f===";"||f==="#"?d:`<span style="color: ${t.number};">${d}</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,(d,p)=>{let u=0;for(let g=0;g<p.length;g++)u=u*26+(p.charCodeAt(g)-97+1);return u=u-1,s[u]||""})}_highlightPHP(e,t){const i=this.unescapeEntitiesRepeated(e);let s=this.escapeHTML(i);const n=[],r=u=>{let g="",f=u;do g=String.fromCharCode(97+f%26)+g,f=Math.floor(f/26)-1;while(f>=0);return g||"a"},o=u=>{const g=n.length;return n.push(u),`\0${r(g)}\0`},a=(u,g)=>{const f=s.indexOf(u);return f===-1?!1:(s=s.slice(0,f)+g+s.slice(f+u.length),!0)};let h;const l=/\/\*[\s\S]*?\*\//g,c=/\/\/[^\n\r]*/g,d=/\#([^\n\r]*)/g,p=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;h=l.exec(i);){const u=h[0];a(this.escapeHTML(u),o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`))}for(;h=c.exec(i);){const u=h[0];a(this.escapeHTML(u),o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`))}for(;h=d.exec(i);){const u=h[0];a(this.escapeHTML(u),o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`))}for(;h=p.exec(i);){const u=h[0];a(this.escapeHTML(u),o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</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,(u,g)=>{let f=0;for(let y=0;y<g.length;y++)f=f*26+(g.charCodeAt(y)-97+1);return f=f-1,n[f]||""}),s}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(i=>i.name==="keymap")||t.extensions.unshift(new J(t.keymap)),t.extensions.some(i=>i.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 */
|
|
128
128
|
.rte-source-editor-overlay {
|
|
129
129
|
position: fixed !important;
|
|
130
130
|
top: 0 !important;
|
|
@@ -501,10 +501,10 @@
|
|
|
501
501
|
flex: 1;
|
|
502
502
|
text-align: center;
|
|
503
503
|
}
|
|
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
|
|
505
|
-
`+" ".repeat(o*
|
|
506
|
-
`+" ".repeat(o*
|
|
507
|
-
`+" ".repeat(o*
|
|
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=(()=>{var o,a,h;const n=window.getSelection();if(n&&n.anchorNode){let l=n.anchorNode instanceof HTMLElement?n.anchorNode:n.anchorNode.parentElement;for(;l;){if((o=l.classList)!=null&&o.contains("rte-content"))return l;l=l.parentElement}}if(document.activeElement){let l=document.activeElement;if((a=l.classList)!=null&&a.contains("rte-content"))return l;for(;l&&l!==document.body;){if((h=l.classList)!=null&&h.contains("rte-content"))return l;const c=l.querySelector(".rte-content");if(c)return c;l=l.parentElement}}const r=document.querySelector("[data-editora-editor]");if(r){const l=r.querySelector(".rte-content");if(l)return l}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=n=>{let r="",o=0;const a=2,h=n.split(/(<\/?[a-zA-Z][^>]*>)/);for(const l of h)l.trim()&&(l.match(/^<\/[a-zA-Z]/)?(o=Math.max(0,o-1),r+=`
|
|
505
|
+
`+" ".repeat(o*a)+l):l.match(/^<[a-zA-Z]/)&&!l.match(/\/>$/)?(r+=`
|
|
506
|
+
`+" ".repeat(o*a)+l,o++):l.match(/^<[a-zA-Z].*\/>$/)?r+=`
|
|
507
|
+
`+" ".repeat(o*a)+l:r+=l.trim());return r.trim()};return(()=>{const r=i(t);let o=null,a="dark",h=!1,l=!1,c=!1,d=!1;const p=!!e.closest(P)||document.body.matches(P)||document.documentElement.matches(P),u=document.createElement("div");u.className="rte-source-editor-overlay",p&&u.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 f=document.createElement("div");f.className="rte-source-editor-header",f.innerHTML=`
|
|
508
508
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
509
509
|
<div class="rte-source-editor-header-toolbar">
|
|
510
510
|
<button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
|
|
@@ -548,7 +548,7 @@
|
|
|
548
548
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
549
549
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
550
550
|
</div>
|
|
551
|
-
`,g.appendChild(
|
|
551
|
+
`,g.appendChild(f),g.appendChild(y),g.appendChild(E),u.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=f.querySelector(".theme-toggle-btn"),b=f.querySelector(".readonly-toggle-btn"),T=f.querySelector(".rte-source-editor-fullscreen-btn"),I=f.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(!d){for(d=!0;O.length;){const x=O.pop();x==null||x()}o&&(o.destroy(),o=null),u.isConnected&&u.remove()}},K=()=>{a=a==="dark"?"light":"dark",o==null||o.setTheme(a),S&&(S.innerHTML=a==="light"?`
|
|
552
552
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
553
553
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
554
554
|
</svg>
|
|
@@ -564,7 +564,7 @@
|
|
|
564
564
|
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
|
|
565
565
|
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
|
|
566
566
|
</svg>
|
|
567
|
-
`)},z=()=>{h=!h,o
|
|
567
|
+
`)},z=()=>{h=!h,o==null||o.setReadOnly(h),b&&(b.classList.toggle("active",h),b.innerHTML=h?`
|
|
568
568
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
569
569
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
570
570
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -575,7 +575,7 @@
|
|
|
575
575
|
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
|
|
576
576
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
|
|
577
577
|
</svg>
|
|
578
|
-
`)},q=()=>{
|
|
578
|
+
`)},q=()=>{l=!l,u.classList.toggle("fullscreen",l),C.style.height=l?"calc(100vh - 200px)":"400px",T&&(T.innerHTML=l?`
|
|
579
579
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
580
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"/>
|
|
581
581
|
</svg>
|
|
@@ -583,4 +583,4 @@
|
|
|
583
583
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
584
584
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
|
|
585
585
|
</svg>
|
|
586
|
-
`)},
|
|
586
|
+
`)},j=()=>{c&&!confirm("You have unsaved changes. Are you sure you want to cancel?")||H()},Q=()=>{try{const x=(o==null?void 0: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",j),N&&R(N,"click",Q),R(u,"click",x=>{x.target===u&&H()}),R(document,"keydown",x=>{const M=x;M.key==="Escape"&&(M.preventDefault(),H())}),document.body.appendChild(u),requestAnimationFrame(()=>{if(!(d||!u.isConnected))try{o=oe(C,{value:r,theme:"dark",readOnly:!1,extensions:[new _,new G,new ee,new se,new ie,new ne,new re]}),o.on("change",()=>{const x=(o==null?void 0:o.getValue())||"";U(x!==r)}),requestAnimationFrame(()=>o==null?void 0: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;
|