@editora/core 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +34 -0
  2. package/dist/{A11yCheckerPlugin.native-CZKpi3uF.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +225 -173
  3. package/dist/AnchorPlugin.native-C1Rw5m04.mjs +404 -0
  4. package/dist/BackgroundColorPlugin.native-BE-p9DRd.mjs +489 -0
  5. package/dist/ChecklistPlugin.native-nuSSEFNI.mjs +309 -0
  6. package/dist/ClearFormattingPlugin.native-Bq_XcTh2.mjs +140 -0
  7. package/dist/{CodePlugin.native-CK9d8rmt.mjs → CodePlugin.native-B263UI8O.mjs} +624 -473
  8. package/dist/CodeSamplePlugin.native-CgGoH-X4.mjs +384 -0
  9. package/dist/CommentsPlugin.native-tMnWn8a2.mjs +723 -0
  10. package/dist/DirectionPlugin.native-CDnbdNyl.mjs +130 -0
  11. package/dist/{EmbedIframePlugin.native-ifr9KLdN.mjs → EmbedIframePlugin.native-CSWIB1jm.mjs} +154 -50
  12. package/dist/{EmojisPlugin.native-D6mJSnSR.mjs → EmojisPlugin.native-DxTm_DL-.mjs} +156 -103
  13. package/dist/FontFamilyPlugin.native-j8hMTbg4.mjs +158 -0
  14. package/dist/FontSizePlugin.native-B_jCh7dY.mjs +286 -0
  15. package/dist/FootnotePlugin.native-D730OGRm.mjs +425 -0
  16. package/dist/HistoryPlugin.native-TDnVMsEO.mjs +257 -0
  17. package/dist/IndentPlugin.native-BHixp8sP.mjs +150 -0
  18. package/dist/LineHeightPlugin.native-CM7iXdQj.mjs +151 -0
  19. package/dist/{LinkPlugin.native-BdAOV-iu.mjs → LinkPlugin.native-CS2g-G18.mjs} +128 -53
  20. package/dist/{ListPlugin.native-CLFU5AUQ.mjs → ListPlugin.native-V7EZC1lM.mjs} +59 -12
  21. package/dist/MathPlugin.native-KUxz0o8C.mjs +251 -0
  22. package/dist/MediaManagerPlugin.native-CgP5iInD.mjs +970 -0
  23. package/dist/MergeTagPlugin.native-DIGWhdnF.mjs +419 -0
  24. package/dist/PageBreakPlugin.native-CGiQxXqR.mjs +297 -0
  25. package/dist/{PrintPlugin.native-BUpm52VJ.mjs → PrintPlugin.native-7qt5v7L5.mjs} +10 -10
  26. package/dist/{SpecialCharactersPlugin.native-x7a2SWXc.mjs → SpecialCharactersPlugin.native-DANrbExJ.mjs} +143 -97
  27. package/dist/SpellCheckPlugin.native-C8bPvRHy.mjs +1019 -0
  28. package/dist/StrikethroughPlugin.native-0Be7j49s.mjs +73 -0
  29. package/dist/{TablePlugin.native-EEWXn1-s.mjs → TablePlugin.native-DrHX-efe.mjs} +149 -145
  30. package/dist/TemplatePlugin.native-4lKEm-WY.mjs +578 -0
  31. package/dist/TextAlignmentPlugin.native-sM_1s00t.mjs +108 -0
  32. package/dist/{TextColorPlugin.native-D6SmTglm.mjs → TextColorPlugin.native-Clgtb50j.mjs} +173 -92
  33. package/dist/colorSelectionApply-CK1My9N2.mjs +67 -0
  34. package/dist/core.css +1 -1
  35. package/dist/editora.min.js +31 -29
  36. package/dist/editora.umd.js +31 -29
  37. package/dist/index-CqWQFb3D.js +10 -0
  38. package/dist/index-OwnkG39N.mjs +2227 -0
  39. package/dist/index.cjs.js +14 -18
  40. package/dist/index.esm.js +204 -521
  41. package/dist/plugin-loader.js +26 -26
  42. package/dist/webcomponent-core.js +1286 -295
  43. package/dist/webcomponent-core.min.css +1 -1
  44. package/dist/webcomponent-core.min.js +111 -78
  45. package/dist/webcomponent.cjs.js +1 -1
  46. package/dist/webcomponent.esm.js +1 -1
  47. package/dist/webcomponent.js +1252 -261
  48. package/dist/webcomponent.min.css +1 -1
  49. package/dist/webcomponent.min.js +3552 -2037
  50. package/index.d.ts +355 -0
  51. package/package.json +21 -18
  52. package/dist/A11yCheckerPlugin.native-CZKpi3uF.mjs.map +0 -1
  53. package/dist/AnchorPlugin.native-7es9PVZ9.mjs +0 -340
  54. package/dist/AnchorPlugin.native-7es9PVZ9.mjs.map +0 -1
  55. package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs +0 -449
  56. package/dist/BackgroundColorPlugin.native-Dip5uqTg.mjs.map +0 -1
  57. package/dist/BlockquotePlugin.native-JFmOLsxN.mjs.map +0 -1
  58. package/dist/BoldPlugin.native-BAzzoqU5.mjs.map +0 -1
  59. package/dist/CapitalizationPlugin.native-DOMsh5R7.mjs.map +0 -1
  60. package/dist/ChecklistPlugin.native-Dccs3nLe.mjs +0 -153
  61. package/dist/ChecklistPlugin.native-Dccs3nLe.mjs.map +0 -1
  62. package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs +0 -27
  63. package/dist/ClearFormattingPlugin.native-BZPDHswo.mjs.map +0 -1
  64. package/dist/CodePlugin.native-CK9d8rmt.mjs.map +0 -1
  65. package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs +0 -326
  66. package/dist/CodeSamplePlugin.native-DMbEdO9j.mjs.map +0 -1
  67. package/dist/CommentsPlugin.native-2zQV8Ia4.mjs +0 -473
  68. package/dist/CommentsPlugin.native-2zQV8Ia4.mjs.map +0 -1
  69. package/dist/DirectionPlugin.native-Be7wCzkI.mjs +0 -59
  70. package/dist/DirectionPlugin.native-Be7wCzkI.mjs.map +0 -1
  71. package/dist/DocumentManagerPlugin.native-BvZL5CSG.mjs.map +0 -1
  72. package/dist/EmbedIframePlugin.native-ifr9KLdN.mjs.map +0 -1
  73. package/dist/EmojisPlugin.native-D6mJSnSR.mjs.map +0 -1
  74. package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs +0 -106
  75. package/dist/FontFamilyPlugin.native-BzS_9qbM.mjs.map +0 -1
  76. package/dist/FontSizePlugin.native-DkLMLPue.mjs +0 -186
  77. package/dist/FontSizePlugin.native-DkLMLPue.mjs.map +0 -1
  78. package/dist/FootnotePlugin.native-BciVc9W6.mjs +0 -128
  79. package/dist/FootnotePlugin.native-BciVc9W6.mjs.map +0 -1
  80. package/dist/FullscreenPlugin.native-ChXyxeNw.mjs.map +0 -1
  81. package/dist/HeadingPlugin.native-DrLYwQnQ.mjs.map +0 -1
  82. package/dist/HistoryPlugin.native-DoDRifCf.mjs +0 -89
  83. package/dist/HistoryPlugin.native-DoDRifCf.mjs.map +0 -1
  84. package/dist/IndentPlugin.native-CbFugPoi.mjs +0 -133
  85. package/dist/IndentPlugin.native-CbFugPoi.mjs.map +0 -1
  86. package/dist/ItalicPlugin.native-CQjjDyUL.mjs.map +0 -1
  87. package/dist/LineHeightPlugin.native-CWQT2FIa.mjs +0 -73
  88. package/dist/LineHeightPlugin.native-CWQT2FIa.mjs.map +0 -1
  89. package/dist/LinkPlugin.native-BdAOV-iu.mjs.map +0 -1
  90. package/dist/ListPlugin.native-CLFU5AUQ.mjs.map +0 -1
  91. package/dist/MathPlugin.native-DE_ii-LA.mjs +0 -182
  92. package/dist/MathPlugin.native-DE_ii-LA.mjs.map +0 -1
  93. package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs +0 -533
  94. package/dist/MediaManagerPlugin.native-DaYFDzNM.mjs.map +0 -1
  95. package/dist/MergeTagPlugin.native-CrxyThyn.mjs +0 -178
  96. package/dist/MergeTagPlugin.native-CrxyThyn.mjs.map +0 -1
  97. package/dist/PageBreakPlugin.native-DDjcDyRW.mjs +0 -172
  98. package/dist/PageBreakPlugin.native-DDjcDyRW.mjs.map +0 -1
  99. package/dist/PreviewPlugin.native-DBvfpmIv.mjs.map +0 -1
  100. package/dist/PrintPlugin.native-BUpm52VJ.mjs.map +0 -1
  101. package/dist/SpecialCharactersPlugin.native-x7a2SWXc.mjs.map +0 -1
  102. package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs +0 -465
  103. package/dist/SpellCheckPlugin.native-B7yTh0iE.mjs.map +0 -1
  104. package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs +0 -43
  105. package/dist/StrikethroughPlugin.native-ChaZLaXw.mjs.map +0 -1
  106. package/dist/TablePlugin.native-EEWXn1-s.mjs.map +0 -1
  107. package/dist/TemplatePlugin.native-BlSn1c9h.mjs +0 -564
  108. package/dist/TemplatePlugin.native-BlSn1c9h.mjs.map +0 -1
  109. package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs +0 -97
  110. package/dist/TextAlignmentPlugin.native-CQIs1m7R.mjs.map +0 -1
  111. package/dist/TextColorPlugin.native-D6SmTglm.mjs.map +0 -1
  112. package/dist/UnderlinePlugin.native-QpIcK4L2.mjs.map +0 -1
  113. package/dist/documentManager-irzj9n3V.mjs.map +0 -1
  114. package/dist/editorContainerHelpers-C7kdWnS0.mjs.map +0 -1
  115. package/dist/editora.min.js.map +0 -1
  116. package/dist/editora.umd.js.map +0 -1
  117. package/dist/index-BF5RBhL9.js +0 -4
  118. package/dist/index-BF5RBhL9.js.map +0 -1
  119. package/dist/index-BPsf460l.mjs +0 -1243
  120. package/dist/index-BPsf460l.mjs.map +0 -1
  121. package/dist/index.cjs.js.map +0 -1
  122. package/dist/index.es-CuicffkQ.mjs.map +0 -1
  123. package/dist/index.esm.js.map +0 -1
  124. package/dist/plugin-loader.js.map +0 -1
  125. package/dist/purify.es-CKpwg8Tk.mjs.map +0 -1
  126. package/dist/webcomponent-core.js.map +0 -1
  127. package/dist/webcomponent-core.min.js.map +0 -1
  128. package/dist/webcomponent.cjs.js.map +0 -1
  129. package/dist/webcomponent.esm.js.map +0 -1
  130. package/dist/webcomponent.js.map +0 -1
  131. package/dist/webcomponent.min.js.map +0 -1
@@ -30,28 +30,28 @@ class P {
30
30
  return this.getLine(e.start.line).substring(e.start.column, e.end.column);
31
31
  const t = [];
32
32
  t.push(this.getLine(e.start.line).substring(e.start.column));
33
- for (let s = e.start.line + 1; s < e.end.line; s++)
34
- t.push(this.getLine(s));
33
+ for (let i = e.start.line + 1; i < e.end.line; i++)
34
+ t.push(this.getLine(i));
35
35
  return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
36
36
  `);
37
37
  }
38
38
  // Replace text in range
39
39
  replaceRange(e, t) {
40
- const s = this.getTextInRange(e);
40
+ const i = this.getTextInRange(e);
41
41
  if (e.start.line === e.end.line) {
42
- const i = this.getLine(e.start.line), r = i.substring(0, e.start.column) + t + i.substring(e.end.column);
42
+ const s = this.getLine(e.start.line), r = s.substring(0, e.start.column) + t + s.substring(e.end.column);
43
43
  this._lines[e.start.line] = r;
44
44
  } else {
45
- const i = this.getLine(e.start.line), r = this.getLine(e.end.line), n = i.substring(0, e.start.column) + t, o = r.substring(e.end.column), a = t.split(`
45
+ const s = this.getLine(e.start.line), r = this.getLine(e.end.line), n = s.substring(0, e.start.column) + t, o = r.substring(e.end.column), l = t.split(`
46
46
  `);
47
- a[0] = n + a[0], a[a.length - 1] = a[a.length - 1] + o, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...a);
47
+ l[0] = n + 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);
48
48
  }
49
- return this._version++, { range: e, text: t, oldText: s };
49
+ return this._version++, { range: e, text: t, oldText: i };
50
50
  }
51
51
  // Insert text at position
52
52
  insertText(e, t) {
53
- const s = { start: e, end: e };
54
- return this.replaceRange(s, t);
53
+ const i = { start: e, end: e };
54
+ return this.replaceRange(i, t);
55
55
  }
56
56
  // Delete text in range
57
57
  deleteRange(e) {
@@ -60,18 +60,18 @@ class P {
60
60
  // Convert position to offset
61
61
  positionToOffset(e) {
62
62
  let t = 0;
63
- for (let s = 0; s < e.line; s++)
64
- t += this.getLine(s).length + 1;
63
+ for (let i = 0; i < e.line; i++)
64
+ t += this.getLine(i).length + 1;
65
65
  return t += e.column, t;
66
66
  }
67
67
  // Convert offset to position
68
68
  offsetToPosition(e) {
69
69
  let t = e;
70
- for (let s = 0; s < this.getLineCount(); s++) {
71
- const i = this.getLine(s).length;
72
- if (t <= i)
73
- return { line: s, column: t };
74
- t -= i + 1;
70
+ for (let i = 0; i < this.getLineCount(); i++) {
71
+ const s = this.getLine(i).length;
72
+ if (t <= s)
73
+ return { line: i, column: t };
74
+ t -= s + 1;
75
75
  }
76
76
  return {
77
77
  line: this.getLineCount() - 1,
@@ -96,9 +96,9 @@ class P {
96
96
  return e._lines = [...this._lines], e._version = this._version, e;
97
97
  }
98
98
  }
99
- class B {
99
+ class U {
100
100
  constructor(e) {
101
- this.gutterWidth = 50, this.lineHeight = 21, this.container = e, this.createDOM();
101
+ this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.container = e, this.createDOM();
102
102
  }
103
103
  createDOM() {
104
104
  this.container.innerHTML = "";
@@ -149,8 +149,8 @@ class B {
149
149
  }
150
150
  // Update line numbers
151
151
  updateLineNumbers(e) {
152
- const t = Math.max(e, 20), s = Array.from({ length: t }, (i, r) => r + 1);
153
- this.lineNumbersElement.innerHTML = s.map((i) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("");
152
+ const t = Math.max(e, 20), i = Array.from({ length: t }, (s, r) => r + 1);
153
+ this.lineNumbersElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
154
154
  }
155
155
  // Get content element
156
156
  getContentElement() {
@@ -162,85 +162,103 @@ class B {
162
162
  }
163
163
  // Get text content
164
164
  getText() {
165
- return this.contentElement.textContent || "";
165
+ const e = this.contentElement.textContent || "";
166
+ return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && e.endsWith("​") ? e.slice(0, -1) : e;
166
167
  }
167
168
  // Set text content
168
169
  setText(e) {
169
- this.contentElement.textContent = e;
170
+ this.contentElement.textContent = e, this.syncTrailingNewlineMarker(e.endsWith(`
171
+ `));
170
172
  const t = e.split(`
171
173
  `).length;
172
174
  this.updateLineNumbers(t);
173
175
  }
174
176
  // Set inner HTML (used for syntax highlighted content)
175
177
  setHTML(e) {
176
- const t = /&lt;|&gt;/.test(e), s = /<span\b/i.test(e), i = /<[^>]+>/.test(e);
177
- t && s ? this.contentElement.innerHTML = e : i && !t ? this.contentElement.textContent = e : this.contentElement.innerHTML = e;
178
- const r = (this.contentElement.textContent || "").split(`
178
+ const t = /\n$/.test(e), i = /&lt;|&gt;/.test(e), s = /<span\b/i.test(e), r = /<[^>]+>/.test(e);
179
+ i && s ? this.contentElement.innerHTML = e : r && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
180
+ const n = (this.contentElement.textContent || "").split(`
179
181
  `).length;
180
- this.updateLineNumbers(r);
182
+ this.updateLineNumbers(n);
183
+ }
184
+ // Keep trailing-newline caret marker in sync for live contenteditable edits
185
+ // (without forcing a full setText/setHTML render).
186
+ syncTrailingNewlineMarkerForText(e) {
187
+ this.syncTrailingNewlineMarker(e.endsWith(`
188
+ `));
181
189
  }
182
190
  // Get cursor position from DOM selection
183
191
  getCursorPosition() {
184
192
  const e = window.getSelection();
185
193
  if (!e || e.rangeCount === 0)
186
194
  return { line: 0, column: 0 };
187
- const t = e.getRangeAt(0), s = t.cloneRange();
188
- s.selectNodeContents(this.contentElement), s.setEnd(t.endContainer, t.endOffset);
189
- const i = s.toString().split(`
195
+ const t = e.getRangeAt(0), i = t.cloneRange();
196
+ i.selectNodeContents(this.contentElement), i.setEnd(t.endContainer, t.endOffset);
197
+ const s = i.toString().replace(/\u200B/g, "").split(`
190
198
  `);
191
199
  return {
192
- line: i.length - 1,
193
- column: i[i.length - 1].length
200
+ line: s.length - 1,
201
+ column: s[s.length - 1].length
194
202
  };
195
203
  }
196
204
  // Set cursor position
197
205
  setCursorPosition(e) {
198
- var g, d;
206
+ var g, h;
199
207
  const t = this.getText().split(`
200
- `), s = Math.min(e.line, t.length - 1), i = Math.min(e.column, ((g = t[s]) == null ? void 0 : g.length) || 0);
208
+ `), i = Math.min(e.line, t.length - 1), s = Math.min(e.column, ((g = t[i]) == null ? void 0 : g.length) || 0);
201
209
  let r = 0;
202
- for (let f = 0; f < s; f++)
210
+ for (let f = 0; f < i; f++)
203
211
  r += t[f].length + 1;
204
- r += i;
212
+ r += s;
205
213
  const n = document.createRange(), o = window.getSelection();
206
- let a = 0, c = null, l = 0;
207
- const h = document.createTreeWalker(
214
+ let l = 0, c = null, a = 0;
215
+ const u = document.createTreeWalker(
208
216
  this.contentElement,
209
217
  NodeFilter.SHOW_TEXT,
210
218
  null
211
219
  );
212
- let u;
213
- for (; u = h.nextNode(); ) {
214
- const f = ((d = u.textContent) == null ? void 0 : d.length) || 0;
215
- if (a + f >= r) {
216
- c = u, l = r - a;
220
+ let d;
221
+ for (; d = u.nextNode(); ) {
222
+ const f = ((h = d.textContent) == null ? void 0 : h.length) || 0;
223
+ if (l + f >= r) {
224
+ c = d, a = r - l;
217
225
  break;
218
226
  }
219
- a += f;
227
+ l += f;
220
228
  }
221
229
  if (c)
222
230
  try {
223
- n.setStart(c, l), n.setEnd(c, l), o == null || o.removeAllRanges(), o == null || o.addRange(n);
231
+ n.setStart(c, a), n.setEnd(c, a), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
224
232
  } catch (f) {
225
233
  console.warn("Could not set cursor position:", f);
226
234
  }
235
+ else {
236
+ const f = this.contentElement.querySelector(
237
+ `[${this.trailingNewlineMarkerAttr}]`
238
+ );
239
+ try {
240
+ f && f.parentNode === this.contentElement ? n.setStartBefore(f) : (n.selectNodeContents(this.contentElement), n.collapse(!1)), n.collapse(!0), o == null || o.removeAllRanges(), o == null || o.addRange(n), this.ensureCaretVisible();
241
+ } catch (p) {
242
+ console.warn("Could not set fallback cursor position:", p);
243
+ }
244
+ }
227
245
  }
228
246
  // Get selection range
229
247
  getSelectionRange() {
230
248
  const e = window.getSelection();
231
249
  if (!e || e.rangeCount === 0 || e.isCollapsed)
232
250
  return;
233
- const t = e.getRangeAt(0), s = t.cloneRange();
234
- s.selectNodeContents(this.contentElement), s.setEnd(t.startContainer, t.startOffset);
235
- const i = s.toString().split(`
251
+ const t = e.getRangeAt(0), i = t.cloneRange();
252
+ i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
253
+ const s = i.toString().replace(/\u200B/g, "").split(`
236
254
  `), r = t.cloneRange();
237
255
  r.selectNodeContents(this.contentElement), r.setEnd(t.endContainer, t.endOffset);
238
- const n = r.toString().split(`
256
+ const n = r.toString().replace(/\u200B/g, "").split(`
239
257
  `);
240
258
  return {
241
259
  start: {
242
- line: i.length - 1,
243
- column: i[i.length - 1].length
260
+ line: s.length - 1,
261
+ column: s[s.length - 1].length
244
262
  },
245
263
  end: {
246
264
  line: n.length - 1,
@@ -254,7 +272,7 @@ class B {
254
272
  }
255
273
  // Focus the editor
256
274
  focus() {
257
- this.contentElement.focus();
275
+ this.contentElement.focus(), this.ensureCaretVisible();
258
276
  }
259
277
  // Blur the editor
260
278
  blur() {
@@ -266,8 +284,8 @@ class B {
266
284
  }
267
285
  // Apply theme
268
286
  applyTheme(e) {
269
- Object.entries(e).forEach(([t, s]) => {
270
- this.container.style.setProperty(`--${t}`, s);
287
+ Object.entries(e).forEach(([t, i]) => {
288
+ this.container.style.setProperty(`--${t}`, i);
271
289
  });
272
290
  }
273
291
  // Scroll to position
@@ -283,14 +301,37 @@ class B {
283
301
  setScrollTop(e) {
284
302
  this.editorContainer.scrollTop = e;
285
303
  }
304
+ syncTrailingNewlineMarker(e) {
305
+ if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
306
+ const t = document.createElement("span");
307
+ t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
308
+ display: inline-block;
309
+ width: 0;
310
+ overflow: hidden;
311
+ pointer-events: none;
312
+ user-select: none;
313
+ `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
314
+ }
315
+ // Ensure caret is visible inside the editor scroll container
316
+ ensureCaretVisible() {
317
+ var n;
318
+ const e = window.getSelection();
319
+ if (!e || e.rangeCount === 0) return;
320
+ const t = e.getRangeAt(0).cloneRange();
321
+ t.collapse(!1);
322
+ let i = t.getClientRects()[0] || t.getBoundingClientRect();
323
+ if ((!i || i.width === 0 && i.height === 0) && e.focusNode instanceof Element ? i = e.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && ((n = e.focusNode) != null && n.parentElement) && (i = e.focusNode.parentElement.getBoundingClientRect()), !i) return;
324
+ const s = this.editorContainer.getBoundingClientRect(), r = 12;
325
+ i.bottom > s.bottom - r ? this.editorContainer.scrollTop += i.bottom - (s.bottom - r) : i.top < s.top + r && (this.editorContainer.scrollTop -= s.top + r - i.top);
326
+ }
286
327
  // Destroy the view
287
328
  destroy() {
288
329
  this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
289
330
  }
290
331
  }
291
- class K {
332
+ const K = class M {
292
333
  constructor(e, t = {}) {
293
- this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.expectingProgrammaticCursor = !1, this.config = {
334
+ this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.config = {
294
335
  value: "",
295
336
  theme: "default",
296
337
  readOnly: !1,
@@ -298,7 +339,7 @@ class K {
298
339
  lineWrapping: !1,
299
340
  lineNumbers: !0,
300
341
  ...t
301
- }, this.textModel = new P(this.config.value), this.view = new B(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();
342
+ }, this.textModel = new P(this.config.value), this.view = new U(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();
302
343
  }
303
344
  // Public accessors for extensions
304
345
  getTextModel() {
@@ -324,20 +365,21 @@ class K {
324
365
  setupEventHandlers() {
325
366
  const e = this.view.getContentElement();
326
367
  e.addEventListener("input", () => {
327
- const t = this.view.getText(), s = this.textModel.getText();
328
- if (t !== s) {
368
+ const t = this.view.getText(), i = this.textModel.getText();
369
+ if (t !== i) {
329
370
  if (!this.suppressHistory) {
330
- const i = this.getCursor().position, r = this.textModel.positionToOffset(i), n = this.getSelection();
331
- let o, a;
332
- n && (o = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: s, cursorOffset: r, anchorOffset: o, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
371
+ const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
372
+ let o, l;
373
+ n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
333
374
  }
334
- this.textModel.setText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
335
- this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
336
- }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: s }]);
375
+ this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
376
+ const s = this.view.getText();
377
+ s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
378
+ }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
337
379
  }
338
380
  }), e.addEventListener("selectionchange", () => {
339
- const t = this.getCursor(), s = this.getSelection();
340
- this.emit("cursor", t), s && this.emit("selection", s);
381
+ const t = this.getCursor(), i = this.getSelection();
382
+ this.emit("cursor", t), i && this.emit("selection", i);
341
383
  }), e.addEventListener("keydown", (t) => {
342
384
  if (this.emit("keydown", t), t.key === "Tab") {
343
385
  this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
@@ -345,31 +387,35 @@ class K {
345
387
  }
346
388
  if (t.key === "Enter") {
347
389
  if (!this.config.readOnly) {
348
- const s = window.getSelection();
349
- if (s && s.rangeCount > 0) {
350
- const i = this.getCursor().position, r = this.textModel.positionToOffset(i), n = this.getSelection();
351
- let o, a;
352
- n && (o = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end)), this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: o, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
353
- const c = s.getRangeAt(0);
354
- c.deleteContents();
355
- const l = document.createTextNode(`
390
+ const i = window.getSelection();
391
+ if (i && i.rangeCount > 0) {
392
+ const s = this.getCursor().position, r = this.textModel.positionToOffset(s), n = this.getSelection();
393
+ let o, l;
394
+ n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end));
395
+ const c = n && o !== void 0 && l !== void 0 ? Math.min(o, l) : r;
396
+ this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: o, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
397
+ const a = i.getRangeAt(0);
398
+ a.deleteContents();
399
+ const u = document.createTextNode(`
356
400
  `);
357
- c.insertNode(l), c.setStartAfter(l), c.collapse(!0), s.removeAllRanges(), s.addRange(c);
358
- const h = this.getCursor().position, u = this.textModel.positionToOffset(h), g = this.getSelection();
359
- let d, f;
360
- g && (d = this.textModel.positionToOffset(g.start), f = this.textModel.positionToOffset(g.end));
361
- const p = this.view.getText();
362
- this.textModel.setText(p), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
401
+ a.insertNode(u), a.setStartAfter(u), a.collapse(!0), i.removeAllRanges(), i.addRange(a), this.view.ensureCaretVisible();
402
+ const d = this.view.getText();
403
+ this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
404
+ const g = Math.min(
405
+ c + 1,
406
+ this.textModel.getText().length
407
+ );
408
+ try {
409
+ const h = this.textModel.offsetToPosition(g);
410
+ this.setCursor(h), this.view.ensureCaretVisible();
411
+ } catch (h) {
412
+ }
413
+ this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
363
414
  this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
364
415
  try {
365
- if (g && (d !== void 0 || f !== void 0)) {
366
- const x = d !== void 0 ? d : u, y = f !== void 0 ? f : u, v = Math.min(x, y), C = Math.max(x, y), L = this.textModel.offsetToPosition(v), T = this.textModel.offsetToPosition(C);
367
- this.setSelection({ start: L, end: T });
368
- } else {
369
- const x = this.textModel.offsetToPosition(u);
370
- this.setCursor(x);
371
- }
372
- } catch (x) {
416
+ const h = this.textModel.offsetToPosition(g);
417
+ this.setCursor(h), this.view.ensureCaretVisible();
418
+ } catch (h) {
373
419
  }
374
420
  }), this.highlightTimeout = null;
375
421
  }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
@@ -378,15 +424,15 @@ class K {
378
424
  t.preventDefault(), t.stopPropagation();
379
425
  return;
380
426
  }
381
- for (const s of this.extensions.values())
382
- if (s.onKeyDown && s.onKeyDown(t) === !1) {
427
+ for (const i of this.extensions.values())
428
+ if (i.onKeyDown && i.onKeyDown(t) === !1) {
383
429
  t.preventDefault(), t.stopPropagation();
384
430
  return;
385
431
  }
386
432
  }), e.addEventListener("mousedown", (t) => {
387
433
  this.emit("mousedown", t);
388
- for (const s of this.extensions.values())
389
- if (s.onMouseDown && s.onMouseDown(t) === !1) {
434
+ for (const i of this.extensions.values())
435
+ if (i.onMouseDown && i.onMouseDown(t) === !1) {
390
436
  t.preventDefault(), t.stopPropagation();
391
437
  return;
392
438
  }
@@ -413,8 +459,8 @@ class K {
413
459
  }
414
460
  // Emit events to listeners
415
461
  emit(e, ...t) {
416
- const s = this.eventListeners.get(e);
417
- s && s.forEach((i) => i(...t));
462
+ const i = this.eventListeners.get(e);
463
+ i && i.forEach((s) => s(...t));
418
464
  }
419
465
  // State management
420
466
  getValue() {
@@ -462,12 +508,12 @@ class K {
462
508
  "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
463
509
  };
464
510
  this.view.applyTheme(t);
465
- const s = this.extensions.get("syntax-highlighting");
466
- if (s && typeof s.setTheme == "function")
511
+ const i = this.extensions.get("syntax-highlighting");
512
+ if (i && typeof i.setTheme == "function")
467
513
  try {
468
- s.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
469
- } catch (i) {
470
- console.warn("Error applying theme to syntax-highlighting extension", i);
514
+ i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
515
+ } catch (s) {
516
+ console.warn("Error applying theme to syntax-highlighting extension", s);
471
517
  }
472
518
  }
473
519
  setReadOnly(e) {
@@ -484,8 +530,8 @@ class K {
484
530
  t && t.destroy && t.destroy(), this.extensions.delete(e);
485
531
  }
486
532
  executeCommand(e, ...t) {
487
- const s = this.commands.get(e);
488
- s ? s(this, ...t) : console.warn(`Command '${e}' not found`);
533
+ const i = this.commands.get(e);
534
+ i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
489
535
  }
490
536
  // Register a command
491
537
  registerCommand(e, t) {
@@ -493,51 +539,51 @@ class K {
493
539
  }
494
540
  // Search & Navigation
495
541
  search(e, t = {}) {
496
- const s = {
542
+ const i = {
497
543
  caseSensitive: !1,
498
544
  regex: !1,
499
545
  ...t
500
- }, i = [], r = this.getValue();
546
+ }, s = [], r = this.getValue();
501
547
  r.split(`
502
548
  `);
503
- let n = s.caseSensitive ? r : r.toLowerCase(), o = s.caseSensitive ? e : e.toLowerCase();
504
- if (s.regex) {
505
- const a = new RegExp(o, s.caseSensitive ? "g" : "gi");
549
+ let n = i.caseSensitive ? r : r.toLowerCase(), o = i.caseSensitive ? e : e.toLowerCase();
550
+ if (i.regex) {
551
+ const l = new RegExp(o, i.caseSensitive ? "g" : "gi");
506
552
  let c;
507
- for (; (c = a.exec(n)) !== null; ) {
508
- const l = this.textModel.offsetToPosition(c.index), h = this.textModel.offsetToPosition(c.index + c[0].length);
509
- i.push({
510
- range: { start: l, end: h },
553
+ for (; (c = l.exec(n)) !== null; ) {
554
+ const a = this.textModel.offsetToPosition(c.index), u = this.textModel.offsetToPosition(c.index + c[0].length);
555
+ s.push({
556
+ range: { start: a, end: u },
511
557
  match: c[0]
512
558
  });
513
559
  }
514
560
  } else {
515
- let a = 0, c = n.indexOf(o, a);
561
+ let l = 0, c = n.indexOf(o, l);
516
562
  for (; c !== -1; ) {
517
- const l = c + e.length, h = this.textModel.offsetToPosition(c), u = this.textModel.offsetToPosition(l);
518
- i.push({
519
- range: { start: h, end: u },
520
- match: r.substring(c, l)
521
- }), a = l, c = n.indexOf(o, a);
563
+ const a = c + e.length, u = this.textModel.offsetToPosition(c), d = this.textModel.offsetToPosition(a);
564
+ s.push({
565
+ range: { start: u, end: d },
566
+ match: r.substring(c, a)
567
+ }), l = a, c = n.indexOf(o, l);
522
568
  }
523
569
  }
524
- return i;
570
+ return s;
525
571
  }
526
572
  replace(e, t) {
527
- const s = this.getValue();
573
+ const i = this.getValue();
528
574
  if (!this.suppressHistory) {
529
575
  const r = this.getCursor().position, n = this.textModel.positionToOffset(r), o = this.getSelection();
530
- let a, c;
531
- o && (a = this.textModel.positionToOffset(o.start), c = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: s, cursorOffset: n, anchorOffset: a, focusOffset: c }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
576
+ let l, c;
577
+ o && (l = this.textModel.positionToOffset(o.start), c = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: n, anchorOffset: l, focusOffset: c }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
532
578
  }
533
- const i = this.textModel.replaceRange(e, t);
534
- this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [i]);
579
+ const s = this.textModel.replaceRange(e, t);
580
+ this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [s]);
535
581
  }
536
- replaceAll(e, t, s = {}) {
537
- const i = this.search(e, s);
582
+ replaceAll(e, t, i = {}) {
583
+ const s = this.search(e, i);
538
584
  let r = 0;
539
- for (let n = i.length - 1; n >= 0; n--)
540
- this.replace(i[n].range, t), r++;
585
+ for (let n = s.length - 1; n >= 0; n--)
586
+ this.replace(s[n].range, t), r++;
541
587
  return r;
542
588
  }
543
589
  // Folding (basic implementation)
@@ -570,35 +616,85 @@ class K {
570
616
  // and restores it after updating the DOM. Callers that will explicitly set the caret
571
617
  // should pass `false` to avoid stomping programmatic cursor changes.
572
618
  renderTextWithHighlight(e, t = !0) {
573
- const s = this.extensions.get("syntax-highlighting");
574
- if (s && typeof s.highlightHTML == "function")
619
+ const i = this.extensions.get("syntax-highlighting");
620
+ if (i && typeof i.highlightHTML == "function")
575
621
  try {
576
- const i = !t && !this.expectingProgrammaticCursor;
577
- let r, n, o, a;
578
- if (t || i) {
622
+ const s = !t && !this.expectingProgrammaticCursor;
623
+ let r, n, o, l;
624
+ if (t || s) {
579
625
  r = this.getSelection();
580
- const l = this.getCursor().position;
581
- n = this.textModel.positionToOffset(l), r && (o = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end));
626
+ const d = this.getCollapsedSelectionOffsetInEditor();
627
+ if (d !== void 0)
628
+ n = d;
629
+ else {
630
+ const g = this.getCursor().position;
631
+ n = this.textModel.positionToOffset(g);
632
+ }
633
+ r && (o = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
582
634
  }
583
- const c = s.highlightHTML(e);
584
- typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), (t || i) && requestAnimationFrame(() => {
635
+ const c = (t || s) && !r && n !== void 0 && this.hasCollapsedSelectionInEditor(), a = c ? this.insertSentinelAtOffset(e, n) : e, u = i.highlightHTML(a);
636
+ typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
585
637
  try {
586
- if (r && (o !== void 0 || a !== void 0)) {
587
- const l = o !== void 0 ? o : n, h = a !== void 0 ? a : n, u = Math.min(l, h), g = Math.max(l, h), d = this.textModel.offsetToPosition(u), f = this.textModel.offsetToPosition(g);
588
- this.view.setSelectionRange({ start: d, end: f });
638
+ if (c && this.restoreCursorFromSentinel()) {
639
+ this.view.ensureCaretVisible();
640
+ return;
641
+ }
642
+ if (r && (o !== void 0 || l !== void 0)) {
643
+ const d = o !== void 0 ? o : n, g = l !== void 0 ? l : n, h = Math.min(d, g), f = Math.max(d, g), p = this.textModel.offsetToPosition(h), x = this.textModel.offsetToPosition(f);
644
+ this.view.setSelectionRange({ start: p, end: x });
589
645
  } else if (n !== void 0) {
590
- const l = this.textModel.offsetToPosition(n);
591
- this.view.setCursorPosition(l);
646
+ const d = this.textModel.offsetToPosition(n);
647
+ this.view.setCursorPosition(d);
592
648
  }
593
- } catch (l) {
649
+ } catch (d) {
594
650
  }
595
651
  });
596
652
  return;
597
- } catch (i) {
598
- console.warn("Syntax highlighting failed, falling back to plain text", i);
653
+ } catch (s) {
654
+ console.warn("Syntax highlighting failed, falling back to plain text", s);
599
655
  }
600
656
  this.view.setText(e);
601
657
  }
658
+ hasCollapsedSelectionInEditor() {
659
+ const e = window.getSelection();
660
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
661
+ return !1;
662
+ const t = e.getRangeAt(0);
663
+ return this.view.getContentElement().contains(t.commonAncestorContainer);
664
+ }
665
+ getCollapsedSelectionOffsetInEditor() {
666
+ const e = window.getSelection();
667
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
668
+ return;
669
+ const t = e.getRangeAt(0), i = this.view.getContentElement();
670
+ if (!i.contains(t.commonAncestorContainer))
671
+ return;
672
+ const s = t.cloneRange();
673
+ return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
674
+ }
675
+ stripVirtualMarkers(e) {
676
+ return e.replace(/\u200B/g, "").split(M.CURSOR_SENTINEL).join("");
677
+ }
678
+ insertSentinelAtOffset(e, t) {
679
+ const i = Math.max(0, Math.min(t, e.length));
680
+ return e.slice(0, i) + M.CURSOR_SENTINEL + e.slice(i);
681
+ }
682
+ restoreCursorFromSentinel() {
683
+ var o;
684
+ const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
685
+ let s = i.nextNode(), r = null, n = 0;
686
+ for (; s; ) {
687
+ const l = (o = s.textContent) != null ? o : "", c = l.indexOf(M.CURSOR_SENTINEL);
688
+ c !== -1 && (r || (r = s, n = c), s.textContent = l.split(M.CURSOR_SENTINEL).join("")), s = i.nextNode();
689
+ }
690
+ if (!r || !t) return !1;
691
+ try {
692
+ const l = document.createRange();
693
+ return l.setStart(r, n), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
694
+ } catch (l) {
695
+ return !1;
696
+ }
697
+ }
602
698
  destroy() {
603
699
  if (!this.isDestroyed) {
604
700
  this.isDestroyed = !0;
@@ -614,15 +710,15 @@ class K {
614
710
  this.redoStack.push(t);
615
711
  try {
616
712
  this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
617
- let s, i;
618
- typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
713
+ let i, s;
714
+ typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
619
715
  try {
620
- if (i != null)
716
+ if (s != null)
621
717
  if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
622
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : i, n = e.focusOffset !== void 0 ? e.focusOffset : i, o = Math.min(r, n), a = Math.max(r, n), c = this.textModel.offsetToPosition(o), l = this.textModel.offsetToPosition(a);
623
- this.setSelection({ start: c, end: l });
718
+ const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
719
+ this.setSelection({ start: c, end: a });
624
720
  } else {
625
- const r = this.textModel.offsetToPosition(i);
721
+ const r = this.textModel.offsetToPosition(s);
626
722
  this.setCursor(r);
627
723
  }
628
724
  } catch (r) {
@@ -640,15 +736,15 @@ class K {
640
736
  this.undoStack.push(t);
641
737
  try {
642
738
  this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
643
- let s, i;
644
- typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
739
+ let i, s;
740
+ typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
645
741
  try {
646
- if (i != null)
742
+ if (s != null)
647
743
  if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
648
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : i, n = e.focusOffset !== void 0 ? e.focusOffset : i, o = Math.min(r, n), a = Math.max(r, n), c = this.textModel.offsetToPosition(o), l = this.textModel.offsetToPosition(a);
649
- this.setSelection({ start: c, end: l });
744
+ const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, n = e.focusOffset !== void 0 ? e.focusOffset : s, o = Math.min(r, n), l = Math.max(r, n), c = this.textModel.offsetToPosition(o), a = this.textModel.offsetToPosition(l);
745
+ this.setSelection({ start: c, end: a });
650
746
  } else {
651
- const r = this.textModel.offsetToPosition(i);
747
+ const r = this.textModel.offsetToPosition(s);
652
748
  this.setCursor(r);
653
749
  }
654
750
  } catch (r) {
@@ -663,29 +759,29 @@ class K {
663
759
  // Insert a tab character or spaces at current cursor
664
760
  insertTab() {
665
761
  if (this.config.readOnly) return;
666
- const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = " ".repeat(this.config.tabSize || 2), i = this.textModel.insertText(e, s), r = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + s.length);
762
+ const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = " ".repeat(this.config.tabSize || 2), s = this.textModel.insertText(e, i), r = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + i.length);
667
763
  if (!this.suppressHistory) {
668
764
  const n = this.getSelection();
669
- let o, a;
670
- n && (o = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: a }), this.redoStack.length = 0;
765
+ let o, l;
766
+ n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: l }), this.redoStack.length = 0;
671
767
  }
672
768
  this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(r), setTimeout(() => {
673
769
  this.expectingProgrammaticCursor = !1;
674
- }, 20), this.emit("change", [i]);
770
+ }, 20), this.emit("change", [s]);
675
771
  }
676
772
  // Insert a newline at current cursor position
677
773
  insertNewLine() {
678
774
  if (this.config.readOnly) return;
679
- const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = this.textModel.insertText(e, `
680
- `), i = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
775
+ const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
776
+ `), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
681
777
  if (!this.suppressHistory) {
682
778
  const r = this.getSelection();
683
779
  let n, o;
684
780
  r && (n = this.textModel.positionToOffset(r.start), o = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: n, focusOffset: o }), this.redoStack.length = 0;
685
781
  }
686
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(i), setTimeout(() => {
782
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
687
783
  this.expectingProgrammaticCursor = !1;
688
- }, 20), this.emit("change", [s]);
784
+ }, 20), this.emit("change", [i]);
689
785
  }
690
786
  // Events
691
787
  on(e, t) {
@@ -693,15 +789,17 @@ class K {
693
789
  }
694
790
  off(e, t) {
695
791
  if (!this.eventListeners.has(e)) return;
696
- const s = this.eventListeners.get(e);
792
+ const i = this.eventListeners.get(e);
697
793
  if (t) {
698
- const i = s.indexOf(t);
699
- i !== -1 && s.splice(i, 1);
794
+ const s = i.indexOf(t);
795
+ s !== -1 && i.splice(s, 1);
700
796
  } else
701
- s.length = 0;
797
+ i.length = 0;
702
798
  }
703
- }
704
- class V {
799
+ };
800
+ K.CURSOR_SENTINEL = "";
801
+ let z = K;
802
+ class q {
705
803
  constructor(e) {
706
804
  this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
707
805
  }
@@ -715,11 +813,11 @@ class V {
715
813
  return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
716
814
  }
717
815
  findMatchingBinding(e) {
718
- const { key: t, ctrlKey: s, altKey: i, shiftKey: r, metaKey: n } = e, o = String(t).toLowerCase(), a = this.keymap[o];
719
- if (!a) return null;
720
- for (const c of a) {
721
- const l = c.ctrlKey === void 0 || c.ctrlKey === s, h = c.altKey === void 0 || c.altKey === i, u = c.shiftKey === void 0 || c.shiftKey === r, g = c.metaKey === void 0 || c.metaKey === n;
722
- if (l && h && u && g)
816
+ const { key: t, ctrlKey: i, altKey: s, shiftKey: r, metaKey: n } = e, o = String(t).toLowerCase(), l = this.keymap[o];
817
+ if (!l) return null;
818
+ for (const c of l) {
819
+ const a = c.ctrlKey === void 0 || c.ctrlKey === i, u = c.altKey === void 0 || c.altKey === s, d = c.shiftKey === void 0 || c.shiftKey === r, g = c.metaKey === void 0 || c.metaKey === n;
820
+ if (a && u && d && g)
723
821
  return c;
724
822
  }
725
823
  return null;
@@ -732,12 +830,12 @@ class V {
732
830
  const e = {};
733
831
  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;
734
832
  }
735
- addBinding(e, t, s, i) {
833
+ addBinding(e, t, i, s) {
736
834
  const r = t.toLowerCase();
737
835
  e[r] || (e[r] = []), e[r].push({
738
836
  key: r,
739
- command: i,
740
- ...s
837
+ command: s,
838
+ ...i
741
839
  });
742
840
  }
743
841
  // Public API for customizing keymap
@@ -746,23 +844,23 @@ class V {
746
844
  }
747
845
  addKeyBinding(e) {
748
846
  const t = e.key.toLowerCase();
749
- this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((s) => s.command !== e.command), this.keymap[t].push({
847
+ this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
750
848
  ...e,
751
849
  key: t
752
850
  });
753
851
  }
754
852
  removeKeyBinding(e, t) {
755
- const s = e.toLowerCase();
756
- 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];
853
+ const i = e.toLowerCase();
854
+ 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];
757
855
  }
758
856
  getKeymap() {
759
857
  return { ...this.keymap };
760
858
  }
761
859
  getBindingsForCommand(e) {
762
860
  const t = [];
763
- for (const s in this.keymap)
764
- for (const i of this.keymap[s])
765
- i.command === e && t.push({ ...i });
861
+ for (const i in this.keymap)
862
+ for (const s of this.keymap[i])
863
+ s.command === e && t.push({ ...s });
766
864
  return t;
767
865
  }
768
866
  getPlatformInfo() {
@@ -775,19 +873,19 @@ class V {
775
873
  this.keymap = {}, this.editor = null;
776
874
  }
777
875
  }
778
- class A {
876
+ class F {
779
877
  constructor() {
780
878
  this.name = "transaction", this.transactions = [];
781
879
  }
782
880
  setup(e) {
783
881
  e.on("change", (t) => {
784
- const s = {
785
- changes: [t],
882
+ const i = {
883
+ changes: t,
786
884
  selection: e.getSelection(),
787
885
  effects: [],
788
886
  annotations: []
789
887
  };
790
- this.transactions.push(s);
888
+ this.transactions.push(i);
791
889
  });
792
890
  }
793
891
  getTransactions() {
@@ -797,7 +895,7 @@ class A {
797
895
  this.transactions = [];
798
896
  }
799
897
  }
800
- class U {
898
+ class _ {
801
899
  constructor() {
802
900
  this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
803
901
  }
@@ -816,10 +914,11 @@ class U {
816
914
  updateLineNumbers() {
817
915
  if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
818
916
  const e = this.editor.getValue().split(`
819
- `).length, t = Array.from({ length: Math.max(e, 20) }, (s, i) => i + 1);
820
- this.lineNumbersElement.innerHTML = t.map((s) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("");
917
+ `).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
918
+ this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
821
919
  }
822
920
  toggle() {
921
+ if (!this.editor) return;
823
922
  this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
824
923
  const e = this.editor.getView().getContentElement();
825
924
  e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
@@ -828,7 +927,7 @@ class U {
828
927
  this.lineNumbersElement = null, this.editor = null;
829
928
  }
830
929
  }
831
- class z {
930
+ class W {
832
931
  constructor() {
833
932
  this.name = "theme", this.editor = null, this.currentTheme = "dark";
834
933
  }
@@ -853,7 +952,7 @@ class z {
853
952
  this.editor = null;
854
953
  }
855
954
  }
856
- class q {
955
+ class D {
857
956
  constructor() {
858
957
  this.name = "read-only", this.editor = null, this.isReadOnly = !1;
859
958
  }
@@ -880,7 +979,7 @@ class q {
880
979
  this.editor = null;
881
980
  }
882
981
  }
883
- class F {
982
+ class j {
884
983
  constructor() {
885
984
  this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
886
985
  }
@@ -893,8 +992,8 @@ class F {
893
992
  this.findPrev();
894
993
  }), e.registerCommand("replace", () => {
895
994
  this.showReplace();
896
- }), e.registerCommand("replaceAll", (t, s) => {
897
- this.replaceAll(t, s);
995
+ }), e.registerCommand("replaceAll", (t, i) => {
996
+ this.replaceAll(t, i);
898
997
  });
899
998
  }
900
999
  showSearch() {
@@ -905,11 +1004,11 @@ class F {
905
1004
  }
906
1005
  }
907
1006
  showReplace() {
908
- var s, i;
1007
+ var i, s;
909
1008
  this.showSearch();
910
- const e = (s = this.searchUI) == null ? void 0 : s.querySelector(".search-replace-input");
1009
+ const e = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-replace-input");
911
1010
  e && (e.style.display = "block", e.focus());
912
- const t = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-status");
1011
+ const t = (s = this.searchUI) == null ? void 0 : s.querySelector(".search-status");
913
1012
  t && (t.textContent = "Replace mode - Enter to replace, Shift+Enter to replace all");
914
1013
  }
915
1014
  hideSearch() {
@@ -989,35 +1088,35 @@ class F {
989
1088
  margin-top: 4px;
990
1089
  " />
991
1090
  `;
992
- const t = this.searchUI.querySelector("input"), s = this.searchUI.querySelector(".search-replace-input"), i = this.searchUI.querySelector(".search-prev"), r = this.searchUI.querySelector(".search-next"), n = this.searchUI.querySelector(".search-close");
1091
+ 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"), n = this.searchUI.querySelector(".search-close");
993
1092
  t.addEventListener("input", () => {
994
1093
  this.performSearch(t.value);
995
1094
  }), t.addEventListener("keydown", (o) => {
996
1095
  o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.findPrev() : this.findNext());
997
- }), s.addEventListener("keydown", (o) => {
998
- o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value, s.value) : this.replaceCurrent(t.value, s.value));
999
- }), i.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), n.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
1096
+ }), i.addEventListener("keydown", (o) => {
1097
+ o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value, i.value) : this.replaceCurrent(t.value, i.value));
1098
+ }), s.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), n.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
1000
1099
  }
1001
1100
  performSearch(e) {
1002
1101
  if (!this.editor || !e.trim()) {
1003
1102
  this.clearHighlights(), this.updateStatus("");
1004
1103
  return;
1005
1104
  }
1006
- const t = this.editor.getValue(), s = [];
1007
- let i = t.toLowerCase().indexOf(e.toLowerCase());
1008
- for (; i !== -1; ) {
1009
- const r = this.getPositionFromOffset(t, i), n = this.getPositionFromOffset(t, i + e.length);
1010
- s.push({
1105
+ const t = this.editor.getValue(), i = [];
1106
+ let s = t.toLowerCase().indexOf(e.toLowerCase());
1107
+ for (; s !== -1; ) {
1108
+ const r = this.getPositionFromOffset(t, s), n = this.getPositionFromOffset(t, s + e.length);
1109
+ i.push({
1011
1110
  range: { start: r, end: n },
1012
- match: t.substring(i, i + e.length)
1013
- }), i = t.toLowerCase().indexOf(e.toLowerCase(), i + 1);
1111
+ match: t.substring(s, s + e.length)
1112
+ }), s = t.toLowerCase().indexOf(e.toLowerCase(), s + 1);
1014
1113
  }
1015
- this.currentResults = s, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
1114
+ this.currentResults = i, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
1016
1115
  }
1017
1116
  getPositionFromOffset(e, t) {
1018
- const s = e.substring(0, t).split(`
1019
- `), i = s.length - 1, r = s[s.length - 1].length;
1020
- return { line: i, column: r };
1117
+ const i = e.substring(0, t).split(`
1118
+ `), s = i.length - 1, r = i[i.length - 1].length;
1119
+ return { line: s, column: r };
1021
1120
  }
1022
1121
  findNext() {
1023
1122
  this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
@@ -1027,25 +1126,25 @@ class F {
1027
1126
  }
1028
1127
  replaceCurrent(e, t) {
1029
1128
  if (!this.editor || !e.trim() || this.currentIndex === -1) return;
1030
- const s = this.currentResults[this.currentIndex];
1031
- if (!s) return;
1032
- const i = this.editor.getValue(), r = this.getOffsetFromPosition(i, s.range.start), n = i.substring(0, r), o = i.substring(r + e.length), a = n + t + o;
1033
- this.editor.setValue(a), this.performSearch(e), this.updateStatus("Replaced current occurrence");
1129
+ const i = this.currentResults[this.currentIndex];
1130
+ if (!i) return;
1131
+ const s = this.editor.getValue(), r = this.getOffsetFromPosition(s, i.range.start), n = s.substring(0, r), o = s.substring(r + e.length), l = n + t + o;
1132
+ this.editor.setValue(l), this.performSearch(e), this.updateStatus("Replaced current occurrence");
1034
1133
  }
1035
1134
  replaceAll(e, t) {
1036
1135
  if (!this.editor || !e.trim()) return;
1037
- let s = this.editor.getValue(), i = 0, r = s.toLowerCase().indexOf(e.toLowerCase());
1136
+ let i = this.editor.getValue(), s = 0, r = i.toLowerCase().indexOf(e.toLowerCase());
1038
1137
  for (; r !== -1; )
1039
- s = s.substring(0, r) + t + s.substring(r + e.length), i++, r = s.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
1040
- i > 0 && (this.editor.setValue(s), this.updateStatus(`Replaced ${i} occurrences`));
1138
+ i = i.substring(0, r) + t + i.substring(r + e.length), s++, r = i.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
1139
+ s > 0 && (this.editor.setValue(i), this.updateStatus(`Replaced ${s} occurrences`));
1041
1140
  }
1042
1141
  getOffsetFromPosition(e, t) {
1043
- const s = e.split(`
1142
+ const i = e.split(`
1044
1143
  `);
1045
- let i = 0;
1144
+ let s = 0;
1046
1145
  for (let r = 0; r < t.line; r++)
1047
- i += s[r].length + 1;
1048
- return i += t.column, i;
1146
+ s += i[r].length + 1;
1147
+ return s += t.column, s;
1049
1148
  }
1050
1149
  updateHighlights() {
1051
1150
  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})`));
@@ -1053,15 +1152,15 @@ class F {
1053
1152
  clearHighlights() {
1054
1153
  }
1055
1154
  updateStatus(e) {
1056
- var s;
1057
- const t = (s = this.searchUI) == null ? void 0 : s.querySelector(".search-status");
1155
+ var i;
1156
+ const t = (i = this.searchUI) == null ? void 0 : i.querySelector(".search-status");
1058
1157
  t && (t.textContent = e);
1059
1158
  }
1060
1159
  destroy() {
1061
1160
  this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
1062
1161
  }
1063
1162
  }
1064
- class _ {
1163
+ class Z {
1065
1164
  constructor() {
1066
1165
  this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
1067
1166
  "(": ")",
@@ -1086,57 +1185,57 @@ class _ {
1086
1185
  if (!this.editor) return;
1087
1186
  const e = this.editor.getCursor(), t = this.editor.getValue();
1088
1187
  this.clearBracketHighlighting();
1089
- const s = this.getBracketAtPosition(t, e.position);
1090
- if (!s) return;
1091
- const i = this.findMatchingBracket(t, s);
1092
- i && (this.currentMatch = i, this.highlightBrackets(i));
1188
+ const i = this.getBracketAtPosition(t, e.position);
1189
+ if (!i) return;
1190
+ const s = this.findMatchingBracket(t, i);
1191
+ s && (this.currentMatch = s, this.highlightBrackets(s));
1093
1192
  }
1094
1193
  getBracketAtPosition(e, t) {
1095
- const s = e.split(`
1194
+ const i = e.split(`
1096
1195
  `);
1097
- if (t.line >= s.length) return null;
1098
- const i = s[t.line];
1099
- if (t.column >= i.length) return null;
1100
- const r = i[t.column];
1196
+ if (t.line >= i.length) return null;
1197
+ const s = i[t.line];
1198
+ if (t.column >= s.length) return null;
1199
+ const r = s[t.column];
1101
1200
  return this.bracketPairs[r] || this.reverseBracketPairs[r] ? { char: r, position: t } : null;
1102
1201
  }
1103
1202
  findMatchingBracket(e, t) {
1104
- const s = e.split(`
1105
- `), i = t.position.line, r = t.position.column, n = t.char;
1106
- return this.bracketPairs[n] ? this.findClosingBracket(e, s, i, r, n) : this.reverseBracketPairs[n] ? this.findOpeningBracket(e, s, i, r, n) : null;
1203
+ const i = e.split(`
1204
+ `), s = t.position.line, r = t.position.column, n = t.char;
1205
+ return this.bracketPairs[n] ? this.findClosingBracket(e, i, s, r, n) : this.reverseBracketPairs[n] ? this.findOpeningBracket(e, i, s, r, n) : null;
1107
1206
  }
1108
- findClosingBracket(e, t, s, i, r) {
1207
+ findClosingBracket(e, t, i, s, r) {
1109
1208
  const n = this.bracketPairs[r];
1110
1209
  let o = 0;
1111
- for (let a = s; a < t.length; a++) {
1112
- const c = t[a], l = a === s ? i : 0;
1113
- for (let h = l; h < c.length; h++) {
1114
- const u = c[h];
1115
- if (u === r)
1210
+ for (let l = i; l < t.length; l++) {
1211
+ const c = t[l], a = l === i ? s : 0;
1212
+ for (let u = a; u < c.length; u++) {
1213
+ const d = c[u];
1214
+ if (d === r)
1116
1215
  o++;
1117
- else if (u === n && (o--, o === 0))
1216
+ else if (d === n && (o--, o === 0))
1118
1217
  return {
1119
- open: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1120
- close: { start: { line: a, column: h }, end: { line: a, column: h + 1 } },
1218
+ open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1219
+ close: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
1121
1220
  type: r
1122
1221
  };
1123
1222
  }
1124
1223
  }
1125
1224
  return null;
1126
1225
  }
1127
- findOpeningBracket(e, t, s, i, r) {
1226
+ findOpeningBracket(e, t, i, s, r) {
1128
1227
  const n = this.reverseBracketPairs[r];
1129
1228
  let o = 0;
1130
- for (let a = s; a >= 0; a--) {
1131
- const c = t[a], l = a === s ? i : c.length - 1;
1132
- for (let h = l; h >= 0; h--) {
1133
- const u = c[h];
1134
- if (u === r)
1229
+ for (let l = i; l >= 0; l--) {
1230
+ const c = t[l], a = l === i ? s : c.length - 1;
1231
+ for (let u = a; u >= 0; u--) {
1232
+ const d = c[u];
1233
+ if (d === r)
1135
1234
  o++;
1136
- else if (u === n && (o--, o === 0))
1235
+ else if (d === n && (o--, o === 0))
1137
1236
  return {
1138
- open: { start: { line: a, column: h }, end: { line: a, column: h + 1 } },
1139
- close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1237
+ open: { start: { line: l, column: u }, end: { line: l, column: u + 1 } },
1238
+ close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1140
1239
  type: n
1141
1240
  };
1142
1241
  }
@@ -1155,7 +1254,7 @@ class _ {
1155
1254
  this.clearBracketHighlighting(), this.editor = null;
1156
1255
  }
1157
1256
  }
1158
- class D {
1257
+ class J {
1159
1258
  constructor() {
1160
1259
  this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
1161
1260
  }
@@ -1196,9 +1295,9 @@ class D {
1196
1295
  }
1197
1296
  findFoldableLines(e) {
1198
1297
  const t = [];
1199
- for (let s = 0; s < e.length; s++) {
1200
- const i = e[s].trim();
1201
- (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);
1298
+ for (let i = 0; i < e.length; i++) {
1299
+ const s = e[i].trim();
1300
+ (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);
1202
1301
  }
1203
1302
  return t;
1204
1303
  }
@@ -1234,12 +1333,12 @@ class D {
1234
1333
  this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
1235
1334
  }
1236
1335
  }
1237
- class W {
1336
+ class X {
1238
1337
  constructor() {
1239
1338
  this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
1240
1339
  }
1241
1340
  setup(e) {
1242
- 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) });
1341
+ 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) });
1243
1342
  }
1244
1343
  // Extension provides methods that can be called by the editor
1245
1344
  setTheme(e) {
@@ -1299,8 +1398,8 @@ class W {
1299
1398
  }
1300
1399
  // Public API: highlight a source string using the chosen mode (or detect html)
1301
1400
  highlight(e, t) {
1302
- const s = this.getSyntaxColors(), i = (t || this.currentLanguage || "html").toLowerCase();
1303
- return (this.modes.get(i) || this.modes.get("html")).highlight(e, s);
1401
+ const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
1402
+ return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
1304
1403
  }
1305
1404
  // Backwards-compatible method
1306
1405
  highlightHTML(e) {
@@ -1313,125 +1412,128 @@ class W {
1313
1412
  // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
1314
1413
  unescapeEntitiesRepeated(e) {
1315
1414
  let t = e || "";
1316
- for (let s = 0; s < 5; s++) {
1317
- const i = t;
1318
- if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === i) break;
1415
+ for (let i = 0; i < 5; i++) {
1416
+ const s = t;
1417
+ if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === s) break;
1319
1418
  }
1320
1419
  return t;
1321
1420
  }
1322
1421
  _highlightHTML(e, t) {
1323
- const s = t, i = (c) => this.escapeHTML(c);
1324
- let r = i(e);
1422
+ const i = t, s = (c) => this.escapeHTML(c);
1423
+ let r = s(e);
1325
1424
  const n = (c) => {
1326
- let l = c.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1327
- return l = l.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), l = l.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (h, u, g, d, f) => {
1328
- const p = String(d).trim(), x = i(p);
1329
- return `<span style="color: ${s.styleProp};">${u}</span>${g}<span style="color: ${s.styleVal};">${x}</span>${f}`;
1330
- }), l;
1425
+ let a = c.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1426
+ return a = a.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), a = a.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (u, d, g, h, f) => {
1427
+ const p = String(h).trim(), x = s(p);
1428
+ return `<span style="color: ${i.styleProp};">${d}</span>${g}<span style="color: ${i.styleVal};">${x}</span>${f}`;
1429
+ }), a;
1331
1430
  }, o = [];
1332
1431
  try {
1333
- e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c, l, h) => (o.push({ attrs: String(l || ""), inner: String(h || "") }), c));
1432
+ e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c, a, u) => (o.push({ attrs: String(a || ""), inner: String(u || "") }), c));
1334
1433
  } catch (c) {
1335
1434
  }
1336
- let a = 0;
1337
- return r = r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (c, l, h, u, g) => {
1338
- var p, x, y;
1339
- const d = (x = (p = o[a++]) == null ? void 0 : p.inner) != null ? x : this.unescapeEntitiesRepeated(u || "");
1340
- (((y = o[a - 1]) == null ? void 0 : y.attrs) || h || "").toLowerCase();
1341
- const f = this._highlightJS(d, s);
1342
- return `${l}${f}${g}`;
1343
- }), r = r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (c, l, h, u) => {
1344
- const g = n(h);
1345
- return `${l}${g}${u}`;
1346
- }), r = r.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${s.comment};">$1</span>`), r = r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${s.doctype};">$1</span>`), r = r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (c, l, h, u, g) => {
1347
- const d = `<span style="color: ${s.tag};">${h}</span>`;
1348
- let f = u;
1349
- return f = f.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g, (p, x, y, v) => {
1350
- const C = String(x).toLowerCase(), L = `<span style="color: ${s.attrName};">${x}</span>`;
1351
- let T = v, k = "";
1352
- v.startsWith("&quot;") && v.endsWith("&quot;") ? (T = v.slice(6, -6), k = "&quot;") : v.startsWith("&#39;") && v.endsWith("&#39;") && (T = v.slice(5, -5), k = "&#39;");
1353
- let w = v;
1354
- if (C === "style") {
1355
- const S = T.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, ($, E, O, H) => `<span style="color: ${s.styleProp};">${E}</span>:<span style="color: ${s.styleVal};">${O.trim()}</span>${H}`);
1356
- k ? w = `${k}${S}${k}` : w = S, w = `<span style="color: ${s.attrValue};">${w}</span>`;
1357
- } else
1358
- k && (w = `${k}${T}${k}`), w = `<span style="color: ${s.attrValue};">${w}</span>`;
1359
- return `${L}${y}${w}`;
1360
- }), `${l}${d}${f}${g}`;
1435
+ let l = 0;
1436
+ return r = r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (c, a, u, d, g) => {
1437
+ var p, x, k;
1438
+ const h = (x = (p = o[l++]) == null ? void 0 : p.inner) != null ? x : this.unescapeEntitiesRepeated(d || "");
1439
+ (((k = o[l - 1]) == null ? void 0 : k.attrs) || u || "").toLowerCase();
1440
+ const f = this._highlightJS(h, i);
1441
+ return `${a}${f}${g}`;
1442
+ }), r = r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (c, a, u, d) => {
1443
+ const g = n(u);
1444
+ return `${a}${g}${d}`;
1445
+ }), r = r.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${i.comment};">$1</span>`), r = r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${i.doctype};">$1</span>`), r = r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (c, a, u, d, g) => {
1446
+ const h = `<span style="color: ${i.tag};">${u}</span>`;
1447
+ let f = d;
1448
+ return f = f.replace(
1449
+ /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
1450
+ (p, x, k, y) => {
1451
+ const R = String(x).toLowerCase(), H = `<span style="color: ${i.attrName};">${x}</span>`;
1452
+ let T = y, b = "";
1453
+ y.startsWith("&quot;") && y.endsWith("&quot;") ? (T = y.slice(6, -6), b = "&quot;") : y.startsWith("&#39;") && y.endsWith("&#39;") && (T = y.slice(5, -5), b = "&#39;");
1454
+ let w = y;
1455
+ if (R === "style") {
1456
+ const S = T.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (N, E, L, O) => `<span style="color: ${i.styleProp};">${E}</span>:<span style="color: ${i.styleVal};">${L.trim()}</span>${O}`);
1457
+ b ? w = `${b}${S}${b}` : w = S, w = `<span style="color: ${i.attrValue};">${w}</span>`;
1458
+ } else
1459
+ b && (w = `${b}${T}${b}`), w = `<span style="color: ${i.attrValue};">${w}</span>`;
1460
+ return `${H}${k}${w}`;
1461
+ }
1462
+ ), `${a}${h}${f}${g}`;
1361
1463
  }), r;
1362
1464
  }
1363
1465
  _highlightJS(e, t) {
1364
- const s = this.unescapeEntitiesRepeated(e);
1365
- this.escapeHTML(s);
1366
- const i = [], r = (u) => {
1367
- let g = "", d = u;
1466
+ const i = this.unescapeEntitiesRepeated(e);
1467
+ this.escapeHTML(i);
1468
+ const s = [], r = (d) => {
1469
+ let g = "", h = d;
1368
1470
  do
1369
- g = String.fromCharCode(97 + d % 26) + g, d = Math.floor(d / 26) - 1;
1370
- while (d >= 0);
1471
+ g = String.fromCharCode(97 + h % 26) + g, h = Math.floor(h / 26) - 1;
1472
+ while (h >= 0);
1371
1473
  return g || "a";
1372
- }, n = (u) => `\0${r(u)}\0`, o = (u) => {
1373
- const g = i.length;
1374
- return i.push(u), n(g);
1474
+ }, n = (d) => `\0${r(d)}\0`, o = (d) => {
1475
+ const g = s.length;
1476
+ return s.push(d), n(g);
1375
1477
  };
1376
- let a;
1478
+ let l;
1377
1479
  const c = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
1378
- let l = 0, h = "";
1379
- for (; a = c.exec(s); ) {
1380
- const u = a.index;
1381
- l < u && (h += this.escapeHTML(s.slice(l, u)));
1382
- const g = a[0];
1383
- /^\/\*/.test(g) || /^\/\//.test(g) ? h += o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`) : h += o(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`), l = c.lastIndex;
1480
+ let a = 0, u = "";
1481
+ for (; l = c.exec(i); ) {
1482
+ const d = l.index;
1483
+ a < d && (u += this.escapeHTML(i.slice(a, d)));
1484
+ const g = l[0];
1485
+ /^\/\*/.test(g) || /^\/\//.test(g) ? u += o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`) : u += o(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`), a = c.lastIndex;
1384
1486
  }
1385
- return l < s.length && (h += this.escapeHTML(s.slice(l))), h = h.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (u, g, d) => {
1386
- const f = h[d - 1] || "", p = h[d + u.length] || "";
1387
- return f === "&" || f === "#" || p === ";" || p === "#" ? u : `<span style="color: ${t.number};">${u}</span>`;
1388
- }), h = h.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>`), h.replace(/\u0000([a-z]+)\u0000/g, (u, g) => {
1389
- let d = 0;
1487
+ return a < i.length && (u += this.escapeHTML(i.slice(a))), u = u.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, g, h) => {
1488
+ const f = u[h - 1] || "", p = u[h + d.length] || "";
1489
+ return f === "&" || f === "#" || p === ";" || p === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
1490
+ }), u = u.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>`), u.replace(/\u0000([a-z]+)\u0000/g, (d, g) => {
1491
+ let h = 0;
1390
1492
  for (let f = 0; f < g.length; f++)
1391
- d = d * 26 + (g.charCodeAt(f) - 97 + 1);
1392
- return d = d - 1, i[d] || "";
1493
+ h = h * 26 + (g.charCodeAt(f) - 97 + 1);
1494
+ return h = h - 1, s[h] || "";
1393
1495
  });
1394
1496
  }
1395
1497
  _highlightPHP(e, t) {
1396
- const s = this.unescapeEntitiesRepeated(e);
1397
- let i = this.escapeHTML(s);
1398
- const r = [], n = (d) => {
1399
- let f = "", p = d;
1498
+ const i = this.unescapeEntitiesRepeated(e);
1499
+ let s = this.escapeHTML(i);
1500
+ const r = [], n = (h) => {
1501
+ let f = "", p = h;
1400
1502
  do
1401
1503
  f = String.fromCharCode(97 + p % 26) + f, p = Math.floor(p / 26) - 1;
1402
1504
  while (p >= 0);
1403
1505
  return f || "a";
1404
- }, o = (d) => {
1506
+ }, o = (h) => {
1405
1507
  const f = r.length;
1406
- return r.push(d), `\0${n(f)}\0`;
1407
- }, a = (d, f) => {
1408
- const p = i.indexOf(d);
1409
- return p === -1 ? !1 : (i = i.slice(0, p) + f + i.slice(p + d.length), !0);
1508
+ return r.push(h), `\0${n(f)}\0`;
1509
+ }, l = (h, f) => {
1510
+ const p = s.indexOf(h);
1511
+ return p === -1 ? !1 : (s = s.slice(0, p) + f + s.slice(p + h.length), !0);
1410
1512
  };
1411
1513
  let c;
1412
- const l = /\/\*[\s\S]*?\*\//g, h = /\/\/[^\n\r]*/g, u = /\#([^\n\r]*)/g, g = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
1413
- for (; c = l.exec(s); ) {
1414
- const d = c[0];
1415
- a(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1514
+ const a = /\/\*[\s\S]*?\*\//g, u = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, g = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
1515
+ for (; c = a.exec(i); ) {
1516
+ const h = c[0];
1517
+ l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1416
1518
  }
1417
- for (; c = h.exec(s); ) {
1418
- const d = c[0];
1419
- a(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1519
+ for (; c = u.exec(i); ) {
1520
+ const h = c[0];
1521
+ l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1420
1522
  }
1421
- for (; c = u.exec(s); ) {
1422
- const d = c[0];
1423
- a(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1523
+ for (; c = d.exec(i); ) {
1524
+ const h = c[0];
1525
+ l(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1424
1526
  }
1425
- for (; c = g.exec(s); ) {
1426
- const d = c[0];
1427
- a(this.escapeHTML(d), o(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`));
1527
+ for (; c = g.exec(i); ) {
1528
+ const h = c[0];
1529
+ l(this.escapeHTML(h), o(`<span style="color: ${t.string};">${this.escapeHTML(h)}</span>`));
1428
1530
  }
1429
- 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, f) => {
1531
+ 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, (h, f) => {
1430
1532
  let p = 0;
1431
1533
  for (let x = 0; x < f.length; x++)
1432
1534
  p = p * 26 + (f.charCodeAt(x) - 97 + 1);
1433
1535
  return p = p - 1, r[p] || "";
1434
- }), i;
1536
+ }), s;
1435
1537
  }
1436
1538
  // Method to check if content contains syntax that should be highlighted
1437
1539
  shouldHighlight(e) {
@@ -1441,11 +1543,11 @@ class W {
1441
1543
  this.editor = null, this.modes.clear();
1442
1544
  }
1443
1545
  }
1444
- function j(b, e) {
1546
+ function Y(v, e) {
1445
1547
  const t = { ...e };
1446
- return t.extensions || (t.extensions = []), t.extensions.some((s) => s.name === "keymap") || t.extensions.unshift(new V(t.keymap)), t.extensions.some((s) => s.name === "transaction") || t.extensions.unshift(new A()), new K(b, t);
1548
+ return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new q(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new F()), new z(v, t);
1447
1549
  }
1448
- const Z = `/* Source Editor Dialog Styles */
1550
+ const $ = '[data-theme="dark"], .dark, .editora-theme-dark', G = `/* Source Editor Dialog Styles */
1449
1551
  .rte-source-editor-overlay {
1450
1552
  position: fixed !important;
1451
1553
  top: 0 !important;
@@ -1714,64 +1816,83 @@ const Z = `/* Source Editor Dialog Styles */
1714
1816
  background: #0056b3;
1715
1817
  }
1716
1818
 
1717
- /* Dark theme support */
1718
- @media (prefers-color-scheme: dark) {
1719
- .rte-source-editor-modal {
1720
- background: #1e1e1e;
1721
- color: #f8f9fa;
1722
- }
1819
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
1820
+ background: #1e1e1e;
1821
+ color: #f8f9fa;
1822
+ border: 1px solid #434d5f;
1823
+ }
1723
1824
 
1724
- .rte-source-editor-header {
1725
- background: #2d2d2d;
1726
- border-color: #404040;
1727
- }
1825
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
1826
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
1827
+ background: #2a3442;
1828
+ border-color: #434d5f;
1829
+ }
1728
1830
 
1729
- .rte-source-editor-header h2 {
1730
- color: #f8f9fa;
1731
- }
1831
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
1832
+ color: #f8f9fa;
1833
+ }
1732
1834
 
1733
- .rte-source-editor-fullscreen-btn,
1734
- .rte-source-editor-close-btn {
1735
- color: #ccc;
1736
- }
1835
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
1836
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
1837
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
1838
+ color: #c1cede;
1839
+ }
1737
1840
 
1738
- .rte-source-editor-fullscreen-btn:hover,
1739
- .rte-source-editor-close-btn:hover {
1740
- background: #404040;
1741
- color: #f8f9fa;
1742
- }
1841
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
1842
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
1843
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
1844
+ background: #404a5a;
1845
+ color: #f8fafc;
1846
+ }
1743
1847
 
1744
- .rte-source-editor-error {
1745
- background: #2d1b1b;
1746
- color: #fca5a5;
1747
- border-color: #dc2626;
1748
- }
1848
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
1849
+ background: #3b82f6;
1850
+ color: #ffffff;
1851
+ }
1749
1852
 
1750
- .rte-source-editor-warning {
1751
- background: #2d2a1b;
1752
- color: #fcd34d;
1753
- border-color: #d97706;
1754
- }
1853
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
1854
+ background: #2563eb;
1855
+ }
1755
1856
 
1756
- .rte-source-editor-footer {
1757
- background: #2d2d2d;
1758
- border-color: #404040;
1759
- }
1857
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
1858
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
1859
+ color: #cbd5e1;
1860
+ }
1760
1861
 
1761
- .rte-source-editor-footer-info {
1762
- color: #ccc;
1763
- }
1862
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
1863
+ border-color: #3f4b60;
1864
+ border-top-color: #58a6ff;
1865
+ }
1764
1866
 
1765
- .rte-source-editor-btn-cancel {
1766
- background: #374151;
1767
- border-color: #4b5563;
1768
- color: #f9fafb;
1769
- }
1867
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
1868
+ background: #3f2124;
1869
+ color: #fecaca;
1870
+ border-color: #ef4444;
1871
+ }
1770
1872
 
1771
- .rte-source-editor-btn-cancel:hover:not(:disabled) {
1772
- background: #4b5563;
1773
- border-color: #6b7280;
1774
- }
1873
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
1874
+ background: #3b3220;
1875
+ color: #fde68a;
1876
+ border-color: #f59e0b;
1877
+ }
1878
+
1879
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
1880
+ background: #334155;
1881
+ border-color: #475569;
1882
+ color: #f1f5f9;
1883
+ }
1884
+
1885
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
1886
+ background: #475569;
1887
+ border-color: #64748b;
1888
+ }
1889
+
1890
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
1891
+ background: #3b82f6;
1892
+ }
1893
+
1894
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
1895
+ background: #2563eb;
1775
1896
  }
1776
1897
 
1777
1898
  /* Responsive design */
@@ -1803,15 +1924,15 @@ const Z = `/* Source Editor Dialog Styles */
1803
1924
  flex: 1;
1804
1925
  text-align: center;
1805
1926
  }
1806
- }`, Y = () => ({
1927
+ }`, ee = () => ({
1807
1928
  name: "code",
1808
1929
  // Toolbar button configuration
1809
1930
  toolbar: [
1810
1931
  {
1811
1932
  label: "Source",
1812
1933
  command: "toggleSourceView",
1813
- type: "button",
1814
- icon: "<>",
1934
+ // type: "button",
1935
+ 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>',
1815
1936
  shortcut: "Mod-Shift-S"
1816
1937
  }
1817
1938
  ],
@@ -1823,56 +1944,62 @@ const Z = `/* Source Editor Dialog Styles */
1823
1944
  */
1824
1945
  toggleSourceView: () => {
1825
1946
  const e = (() => {
1826
- var o, a, c;
1947
+ var o, l, c;
1827
1948
  const r = window.getSelection();
1828
1949
  if (r && r.anchorNode) {
1829
- let l = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
1830
- for (; l; ) {
1831
- if ((o = l.classList) != null && o.contains("rte-content"))
1832
- return l;
1833
- l = l.parentElement;
1950
+ let a = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
1951
+ for (; a; ) {
1952
+ if ((o = a.classList) != null && o.contains("rte-content"))
1953
+ return a;
1954
+ a = a.parentElement;
1834
1955
  }
1835
1956
  }
1836
1957
  if (document.activeElement) {
1837
- let l = document.activeElement;
1838
- if ((a = l.classList) != null && a.contains("rte-content"))
1839
- return l;
1840
- for (; l && l !== document.body; ) {
1841
- if ((c = l.classList) != null && c.contains("rte-content"))
1842
- return l;
1843
- const h = l.querySelector(".rte-content");
1844
- if (h) return h;
1845
- l = l.parentElement;
1958
+ let a = document.activeElement;
1959
+ if ((l = a.classList) != null && l.contains("rte-content"))
1960
+ return a;
1961
+ for (; a && a !== document.body; ) {
1962
+ if ((c = a.classList) != null && c.contains("rte-content"))
1963
+ return a;
1964
+ const u = a.querySelector(
1965
+ ".rte-content"
1966
+ );
1967
+ if (u) return u;
1968
+ a = a.parentElement;
1846
1969
  }
1847
1970
  }
1848
1971
  const n = document.querySelector("[data-editora-editor]");
1849
1972
  if (n) {
1850
- const l = n.querySelector(".rte-content");
1851
- if (l) return l;
1973
+ const a = n.querySelector(
1974
+ ".rte-content"
1975
+ );
1976
+ if (a) return a;
1852
1977
  }
1853
1978
  return document.querySelector(".rte-content");
1854
1979
  })();
1855
1980
  if (!e)
1856
- return console.error("[CodePlugin] Editor content area not found"), alert("Editor content area not found. Please click inside the editor first."), !1;
1857
- const t = e.innerHTML, s = (r) => {
1981
+ return console.error("[CodePlugin] Editor content area not found"), alert(
1982
+ "Editor content area not found. Please click inside the editor first."
1983
+ ), !1;
1984
+ const t = e.innerHTML, i = (r) => {
1858
1985
  let n = "", o = 0;
1859
- const a = 2, c = r.split(/(<\/?[a-zA-Z][^>]*>)/);
1860
- for (const l of c)
1861
- l.trim() && (l.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), n += `
1862
- ` + " ".repeat(o * a) + l) : l.match(/^<[a-zA-Z]/) && !l.match(/\/>$/) ? (n += `
1863
- ` + " ".repeat(o * a) + l, o++) : l.match(/^<[a-zA-Z].*\/>$/) ? n += `
1864
- ` + " ".repeat(o * a) + l : n += l.trim());
1986
+ const l = 2, c = r.split(/(<\/?[a-zA-Z][^>]*>)/);
1987
+ for (const a of c)
1988
+ a.trim() && (a.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), n += `
1989
+ ` + " ".repeat(o * l) + a) : a.match(/^<[a-zA-Z]/) && !a.match(/\/>$/) ? (n += `
1990
+ ` + " ".repeat(o * l) + a, o++) : a.match(/^<[a-zA-Z].*\/>$/) ? n += `
1991
+ ` + " ".repeat(o * l) + a : n += a.trim());
1865
1992
  return n.trim();
1866
1993
  };
1867
1994
  return (() => {
1868
- var $, E, O, H, R, N;
1869
- let r = null, n = "dark", o = !1, a = !1, c = !1;
1870
- const l = t, h = document.createElement("div");
1871
- h.className = "rte-source-editor-overlay";
1872
- const u = document.createElement("div");
1873
- u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
1995
+ var E, L, O, I, A, B;
1996
+ let r = null, n = "dark", o = !1, l = !1, c = !1;
1997
+ const a = t, u = !!e.closest($) || document.body.matches($) || document.documentElement.matches($), d = document.createElement("div");
1998
+ d.className = "rte-source-editor-overlay", u && d.classList.add("rte-theme-dark");
1874
1999
  const g = document.createElement("div");
1875
- g.className = "rte-source-editor-header", g.innerHTML = `
2000
+ g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
2001
+ const h = document.createElement("div");
2002
+ h.className = "rte-source-editor-header", h.innerHTML = `
1876
2003
  <h2 id="source-editor-title">Source Editor</h2>
1877
2004
  <div class="rte-source-editor-header-toolbar">
1878
2005
  <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
@@ -1909,14 +2036,14 @@ const Z = `/* Source Editor Dialog Styles */
1909
2036
  </button>
1910
2037
  </div>
1911
2038
  `;
1912
- const d = document.createElement("div");
1913
- d.className = "rte-source-editor-body";
1914
2039
  const f = document.createElement("div");
1915
- f.className = "rte-source-editor-content";
2040
+ f.className = "rte-source-editor-body";
1916
2041
  const p = document.createElement("div");
1917
- p.className = "rte-source-editor-warning", p.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2042
+ p.className = "rte-source-editor-content";
1918
2043
  const x = document.createElement("div");
1919
- x.className = "rte-source-editor-light-editor", x.style.height = "400px", f.appendChild(p), f.appendChild(x), d.appendChild(f);
2044
+ x.className = "rte-source-editor-warning", x.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2045
+ const k = document.createElement("div");
2046
+ k.className = "rte-source-editor-light-editor", k.style.height = "400px", p.appendChild(x), p.appendChild(k), f.appendChild(p);
1920
2047
  const y = document.createElement("div");
1921
2048
  if (y.className = "rte-source-editor-footer", y.innerHTML = `
1922
2049
  <div class="rte-source-editor-footer-info">
@@ -1926,44 +2053,46 @@ const Z = `/* Source Editor Dialog Styles */
1926
2053
  <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
1927
2054
  <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
1928
2055
  </div>
1929
- `, u.appendChild(g), u.appendChild(d), u.appendChild(y), h.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
2056
+ `, g.appendChild(h), g.appendChild(f), g.appendChild(y), d.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
1930
2057
  const m = document.createElement("style");
1931
- m.id = "rte-source-editor-styles", m.textContent = Z, document.head.appendChild(m);
2058
+ m.id = "rte-source-editor-styles", m.textContent = G, document.head.appendChild(m);
1932
2059
  }
1933
- document.body.appendChild(h);
2060
+ document.body.appendChild(d);
1934
2061
  try {
1935
- r = j(x, {
1936
- value: s(t),
2062
+ r = Y(k, {
2063
+ value: i(t),
1937
2064
  theme: "dark",
1938
2065
  readOnly: !1,
1939
2066
  extensions: [
1940
- new U(),
1941
- new z(),
1942
- new q(),
1943
2067
  new _(),
1944
- new F(),
2068
+ new W(),
1945
2069
  new D(),
1946
- new W()
2070
+ new Z(),
2071
+ new j(),
2072
+ new J(),
2073
+ new X()
1947
2074
  ]
1948
2075
  }), r.on("change", () => {
1949
- c = ((r == null ? void 0 : r.getValue()) || "") !== s(l);
1950
- const M = y.querySelector(".unsaved-changes");
1951
- M && (M.style.display = c ? "inline" : "none");
2076
+ c = ((r == null ? void 0 : r.getValue()) || "") !== i(a);
2077
+ const C = y.querySelector(
2078
+ ".unsaved-changes"
2079
+ );
2080
+ C && (C.style.display = c ? "inline" : "none");
1952
2081
  }), setTimeout(() => r == null ? void 0 : r.focus(), 100);
1953
2082
  } catch (m) {
1954
2083
  console.error("Failed to initialize code editor:", m);
1955
2084
  }
1956
- const v = () => {
2085
+ const R = () => {
1957
2086
  n = n === "dark" ? "light" : "dark", r == null || r.setTheme(n);
1958
- const m = g.querySelector(".theme-toggle-btn");
2087
+ const m = h.querySelector(".theme-toggle-btn");
1959
2088
  m && n === "light" && (m.innerHTML = `
1960
2089
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1961
2090
  <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
1962
2091
  </svg>
1963
2092
  `);
1964
- }, C = () => {
2093
+ }, H = () => {
1965
2094
  o = !o, r == null || r.setReadOnly(o);
1966
- const m = g.querySelector(".readonly-toggle-btn");
2095
+ const m = h.querySelector(".readonly-toggle-btn");
1967
2096
  m && (o ? (m.classList.add("active"), m.innerHTML = `
1968
2097
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1969
2098
  <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
@@ -1976,10 +2105,12 @@ const Z = `/* Source Editor Dialog Styles */
1976
2105
  <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
1977
2106
  </svg>
1978
2107
  `));
1979
- }, L = () => {
1980
- a = !a, a ? (h.classList.add("fullscreen"), x.style.height = "calc(100vh - 200px)") : (h.classList.remove("fullscreen"), x.style.height = "400px");
1981
- const m = g.querySelector(".rte-source-editor-fullscreen-btn");
1982
- m && (m.innerHTML = a ? `
2108
+ }, T = () => {
2109
+ l = !l, l ? (d.classList.add("fullscreen"), k.style.height = "calc(100vh - 200px)") : (d.classList.remove("fullscreen"), k.style.height = "400px");
2110
+ const m = h.querySelector(
2111
+ ".rte-source-editor-fullscreen-btn"
2112
+ );
2113
+ m && (m.innerHTML = l ? `
1983
2114
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1984
2115
  <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"/>
1985
2116
  </svg>
@@ -1988,25 +2119,45 @@ const Z = `/* Source Editor Dialog Styles */
1988
2119
  <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
1989
2120
  </svg>
1990
2121
  `);
1991
- }, T = () => {
1992
- r && (r.destroy(), r = null), document.body.removeChild(h);
1993
- }, k = () => {
1994
- c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || T();
2122
+ }, b = () => {
2123
+ r && (r.destroy(), r = null), document.body.removeChild(d);
1995
2124
  }, w = () => {
2125
+ c && !confirm(
2126
+ "You have unsaved changes. Are you sure you want to cancel?"
2127
+ ) || b();
2128
+ }, S = () => {
1996
2129
  try {
1997
- const m = (r == null ? void 0 : r.getValue()) || "", M = document.createElement("div");
1998
- M.innerHTML = m, M.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach((I) => I.remove()), e.innerHTML = M.innerHTML, c = !1, T();
2130
+ const m = (r == null ? void 0 : r.getValue()) || "", C = document.createElement("div");
2131
+ C.innerHTML = m, C.querySelectorAll(
2132
+ 'script, iframe[src^="javascript:"], object, embed'
2133
+ ).forEach((V) => V.remove()), e.innerHTML = C.innerHTML;
2134
+ try {
2135
+ e.dispatchEvent(
2136
+ new InputEvent("input", {
2137
+ bubbles: !0,
2138
+ cancelable: !1,
2139
+ inputType: "insertReplacementText"
2140
+ })
2141
+ );
2142
+ } catch (V) {
2143
+ e.dispatchEvent(
2144
+ new Event("input", { bubbles: !0 })
2145
+ );
2146
+ }
2147
+ e.dispatchEvent(
2148
+ new Event("change", { bubbles: !0 })
2149
+ ), c = !1, b();
1999
2150
  } catch (m) {
2000
2151
  alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", m);
2001
2152
  }
2002
2153
  };
2003
- ($ = g.querySelector(".theme-toggle-btn")) == null || $.addEventListener("click", v), (E = g.querySelector(".readonly-toggle-btn")) == null || E.addEventListener("click", C), (O = g.querySelector(".rte-source-editor-fullscreen-btn")) == null || O.addEventListener("click", L), (H = g.querySelector(".rte-source-editor-close-btn")) == null || H.addEventListener("click", T), (R = y.querySelector(".rte-source-editor-btn-cancel")) == null || R.addEventListener("click", k), (N = y.querySelector(".rte-source-editor-btn-save")) == null || N.addEventListener("click", w), h.addEventListener("click", (m) => {
2004
- m.target === h && T();
2154
+ (E = h.querySelector(".theme-toggle-btn")) == null || E.addEventListener("click", R), (L = h.querySelector(".readonly-toggle-btn")) == null || L.addEventListener("click", H), (O = h.querySelector(".rte-source-editor-fullscreen-btn")) == null || O.addEventListener("click", T), (I = h.querySelector(".rte-source-editor-close-btn")) == null || I.addEventListener("click", b), (A = y.querySelector(".rte-source-editor-btn-cancel")) == null || A.addEventListener("click", w), (B = y.querySelector(".rte-source-editor-btn-save")) == null || B.addEventListener("click", S), d.addEventListener("click", (m) => {
2155
+ m.target === d && b();
2005
2156
  });
2006
- const S = (m) => {
2007
- m.key === "Escape" && (T(), document.removeEventListener("keydown", S));
2157
+ const N = (m) => {
2158
+ m.key === "Escape" && (b(), document.removeEventListener("keydown", N));
2008
2159
  };
2009
- document.addEventListener("keydown", S);
2160
+ document.addEventListener("keydown", N);
2010
2161
  })(), !0;
2011
2162
  }
2012
2163
  },
@@ -2017,6 +2168,6 @@ const Z = `/* Source Editor Dialog Styles */
2017
2168
  }
2018
2169
  });
2019
2170
  export {
2020
- Y as CodePlugin
2171
+ ee as CodePlugin
2021
2172
  };
2022
- //# sourceMappingURL=CodePlugin.native-CK9d8rmt.mjs.map
2173
+ //# sourceMappingURL=CodePlugin.native-B263UI8O.mjs.map