@editora/plugins 1.0.4 → 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.
package/dist/code.esm.js CHANGED
@@ -30,28 +30,28 @@ class H {
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), o = s.substring(0, e.start.column) + t, n = 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] = o + l[0], l[l.length - 1] = l[l.length - 1] + n, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...l);
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 H {
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 H {
96
96
  return e._lines = [...this._lines], e._version = this._version, e;
97
97
  }
98
98
  }
99
- class R {
99
+ class P {
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 R {
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,88 +162,106 @@ class R {
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 o = (this.contentElement.textContent || "").split(`
179
181
  `).length;
180
- this.updateLineNumbers(r);
182
+ this.updateLineNumbers(o);
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
206
  const t = this.getText().split(`
199
- `), s = Math.min(e.line, t.length - 1), i = Math.min(e.column, t[s]?.length || 0);
207
+ `), i = Math.min(e.line, t.length - 1), s = Math.min(e.column, t[i]?.length || 0);
200
208
  let r = 0;
201
- for (let u = 0; u < s; u++)
209
+ for (let u = 0; u < i; u++)
202
210
  r += t[u].length + 1;
203
- r += i;
204
- const n = document.createRange(), o = window.getSelection();
205
- let a = 0, l = null, c = 0;
211
+ r += s;
212
+ const o = document.createRange(), n = window.getSelection();
213
+ let l = 0, a = null, c = 0;
206
214
  const g = document.createTreeWalker(
207
215
  this.contentElement,
208
216
  NodeFilter.SHOW_TEXT,
209
217
  null
210
218
  );
211
- let d;
212
- for (; d = g.nextNode(); ) {
213
- const u = d.textContent?.length || 0;
214
- if (a + u >= r) {
215
- l = d, c = r - a;
219
+ let h;
220
+ for (; h = g.nextNode(); ) {
221
+ const u = h.textContent?.length || 0;
222
+ if (l + u >= r) {
223
+ a = h, c = r - l;
216
224
  break;
217
225
  }
218
- a += u;
226
+ l += u;
219
227
  }
220
- if (l)
228
+ if (a)
221
229
  try {
222
- n.setStart(l, c), n.setEnd(l, c), o?.removeAllRanges(), o?.addRange(n);
230
+ o.setStart(a, c), o.setEnd(a, c), n?.removeAllRanges(), n?.addRange(o), this.ensureCaretVisible();
223
231
  } catch (u) {
224
232
  console.warn("Could not set cursor position:", u);
225
233
  }
234
+ else {
235
+ const u = this.contentElement.querySelector(
236
+ `[${this.trailingNewlineMarkerAttr}]`
237
+ );
238
+ try {
239
+ u && u.parentNode === this.contentElement ? o.setStartBefore(u) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), n?.removeAllRanges(), n?.addRange(o), this.ensureCaretVisible();
240
+ } catch (d) {
241
+ console.warn("Could not set fallback cursor position:", d);
242
+ }
243
+ }
226
244
  }
227
245
  // Get selection range
228
246
  getSelectionRange() {
229
247
  const e = window.getSelection();
230
248
  if (!e || e.rangeCount === 0 || e.isCollapsed)
231
249
  return;
232
- const t = e.getRangeAt(0), s = t.cloneRange();
233
- s.selectNodeContents(this.contentElement), s.setEnd(t.startContainer, t.startOffset);
234
- const i = s.toString().split(`
250
+ const t = e.getRangeAt(0), i = t.cloneRange();
251
+ i.selectNodeContents(this.contentElement), i.setEnd(t.startContainer, t.startOffset);
252
+ const s = i.toString().replace(/\u200B/g, "").split(`
235
253
  `), r = t.cloneRange();
236
254
  r.selectNodeContents(this.contentElement), r.setEnd(t.endContainer, t.endOffset);
237
- const n = r.toString().split(`
255
+ const o = r.toString().replace(/\u200B/g, "").split(`
238
256
  `);
239
257
  return {
240
258
  start: {
241
- line: i.length - 1,
242
- column: i[i.length - 1].length
259
+ line: s.length - 1,
260
+ column: s[s.length - 1].length
243
261
  },
244
262
  end: {
245
- line: n.length - 1,
246
- column: n[n.length - 1].length
263
+ line: o.length - 1,
264
+ column: o[o.length - 1].length
247
265
  }
248
266
  };
249
267
  }
@@ -253,7 +271,7 @@ class R {
253
271
  }
254
272
  // Focus the editor
255
273
  focus() {
256
- this.contentElement.focus();
274
+ this.contentElement.focus(), this.ensureCaretVisible();
257
275
  }
258
276
  // Blur the editor
259
277
  blur() {
@@ -265,8 +283,8 @@ class R {
265
283
  }
266
284
  // Apply theme
267
285
  applyTheme(e) {
268
- Object.entries(e).forEach(([t, s]) => {
269
- this.container.style.setProperty(`--${t}`, s);
286
+ Object.entries(e).forEach(([t, i]) => {
287
+ this.container.style.setProperty(`--${t}`, i);
270
288
  });
271
289
  }
272
290
  // Scroll to position
@@ -282,14 +300,36 @@ class R {
282
300
  setScrollTop(e) {
283
301
  this.editorContainer.scrollTop = e;
284
302
  }
303
+ syncTrailingNewlineMarker(e) {
304
+ if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
305
+ const t = document.createElement("span");
306
+ t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
307
+ display: inline-block;
308
+ width: 0;
309
+ overflow: hidden;
310
+ pointer-events: none;
311
+ user-select: none;
312
+ `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
313
+ }
314
+ // Ensure caret is visible inside the editor scroll container
315
+ ensureCaretVisible() {
316
+ const e = window.getSelection();
317
+ if (!e || e.rangeCount === 0) return;
318
+ const t = e.getRangeAt(0).cloneRange();
319
+ t.collapse(!1);
320
+ let i = t.getClientRects()[0] || t.getBoundingClientRect();
321
+ if ((!i || i.width === 0 && i.height === 0) && e.focusNode instanceof Element ? i = e.focusNode.getBoundingClientRect() : (!i || i.width === 0 && i.height === 0) && e.focusNode?.parentElement && (i = e.focusNode.parentElement.getBoundingClientRect()), !i) return;
322
+ const s = this.editorContainer.getBoundingClientRect(), r = 12;
323
+ 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);
324
+ }
285
325
  // Destroy the view
286
326
  destroy() {
287
327
  this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
288
328
  }
289
329
  }
290
- class I {
330
+ const $ = class M {
291
331
  constructor(e, t = {}) {
292
- 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 = {
332
+ 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 = {
293
333
  value: "",
294
334
  theme: "default",
295
335
  readOnly: !1,
@@ -297,7 +337,7 @@ class I {
297
337
  lineWrapping: !1,
298
338
  lineNumbers: !0,
299
339
  ...t
300
- }, this.textModel = new H(this.config.value), this.view = new R(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((s) => this.addExtension(s)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
340
+ }, this.textModel = new H(this.config.value), this.view = new P(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
301
341
  }
302
342
  // Public accessors for extensions
303
343
  getTextModel() {
@@ -323,20 +363,21 @@ class I {
323
363
  setupEventHandlers() {
324
364
  const e = this.view.getContentElement();
325
365
  e.addEventListener("input", () => {
326
- const t = this.view.getText(), s = this.textModel.getText();
327
- if (t !== s) {
366
+ const t = this.view.getText(), i = this.textModel.getText();
367
+ if (t !== i) {
328
368
  if (!this.suppressHistory) {
329
- const i = this.getCursor().position, r = this.textModel.positionToOffset(i), n = this.getSelection();
330
- let o, a;
331
- 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;
369
+ const s = this.getCursor().position, r = this.textModel.positionToOffset(s), o = this.getSelection();
370
+ let n, l;
371
+ o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: i, cursorOffset: r, anchorOffset: n, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
332
372
  }
333
- this.textModel.setText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
334
- this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
335
- }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: s }]);
373
+ this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
374
+ const s = this.view.getText();
375
+ s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
376
+ }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }]);
336
377
  }
337
378
  }), e.addEventListener("selectionchange", () => {
338
- const t = this.getCursor(), s = this.getSelection();
339
- this.emit("cursor", t), s && this.emit("selection", s);
379
+ const t = this.getCursor(), i = this.getSelection();
380
+ this.emit("cursor", t), i && this.emit("selection", i);
340
381
  }), e.addEventListener("keydown", (t) => {
341
382
  if (this.emit("keydown", t), t.key === "Tab") {
342
383
  this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
@@ -344,30 +385,34 @@ class I {
344
385
  }
345
386
  if (t.key === "Enter") {
346
387
  if (!this.config.readOnly) {
347
- const s = window.getSelection();
348
- if (s && s.rangeCount > 0) {
349
- const i = this.getCursor().position, r = this.textModel.positionToOffset(i), n = this.getSelection();
350
- let o, a;
351
- 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);
352
- const l = s.getRangeAt(0);
353
- l.deleteContents();
354
- const c = document.createTextNode(`
388
+ const i = window.getSelection();
389
+ if (i && i.rangeCount > 0) {
390
+ const s = this.getCursor().position, r = this.textModel.positionToOffset(s), o = this.getSelection();
391
+ let n, l;
392
+ o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end));
393
+ const a = o && n !== void 0 && l !== void 0 ? Math.min(n, l) : r;
394
+ this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: r, anchorOffset: n, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
395
+ const c = i.getRangeAt(0);
396
+ c.deleteContents();
397
+ const g = document.createTextNode(`
355
398
  `);
356
- l.insertNode(c), l.setStartAfter(c), l.collapse(!0), s.removeAllRanges(), s.addRange(l);
357
- const g = this.getCursor().position, d = this.textModel.positionToOffset(g), u = this.getSelection();
358
- let h, f;
359
- u && (h = this.textModel.positionToOffset(u.start), f = this.textModel.positionToOffset(u.end));
360
- const m = this.view.getText();
361
- this.textModel.setText(m), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
399
+ c.insertNode(g), c.setStartAfter(g), c.collapse(!0), i.removeAllRanges(), i.addRange(c), this.view.ensureCaretVisible();
400
+ const h = this.view.getText();
401
+ this.textModel.setText(h), this.view.syncTrailingNewlineMarkerForText(h);
402
+ const u = Math.min(
403
+ a + 1,
404
+ this.textModel.getText().length
405
+ );
406
+ try {
407
+ const d = this.textModel.offsetToPosition(u);
408
+ this.setCursor(d), this.view.ensureCaretVisible();
409
+ } catch {
410
+ }
411
+ this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
362
412
  this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
363
413
  try {
364
- if (u && (h !== void 0 || f !== void 0)) {
365
- const x = h !== void 0 ? h : d, k = f !== void 0 ? f : d, y = Math.min(x, k), C = Math.max(x, k), L = this.textModel.offsetToPosition(y), w = this.textModel.offsetToPosition(C);
366
- this.setSelection({ start: L, end: w });
367
- } else {
368
- const x = this.textModel.offsetToPosition(d);
369
- this.setCursor(x);
370
- }
414
+ const d = this.textModel.offsetToPosition(u);
415
+ this.setCursor(d), this.view.ensureCaretVisible();
371
416
  } catch {
372
417
  }
373
418
  }), this.highlightTimeout = null;
@@ -377,15 +422,15 @@ class I {
377
422
  t.preventDefault(), t.stopPropagation();
378
423
  return;
379
424
  }
380
- for (const s of this.extensions.values())
381
- if (s.onKeyDown && s.onKeyDown(t) === !1) {
425
+ for (const i of this.extensions.values())
426
+ if (i.onKeyDown && i.onKeyDown(t) === !1) {
382
427
  t.preventDefault(), t.stopPropagation();
383
428
  return;
384
429
  }
385
430
  }), e.addEventListener("mousedown", (t) => {
386
431
  this.emit("mousedown", t);
387
- for (const s of this.extensions.values())
388
- if (s.onMouseDown && s.onMouseDown(t) === !1) {
432
+ for (const i of this.extensions.values())
433
+ if (i.onMouseDown && i.onMouseDown(t) === !1) {
389
434
  t.preventDefault(), t.stopPropagation();
390
435
  return;
391
436
  }
@@ -412,8 +457,8 @@ class I {
412
457
  }
413
458
  // Emit events to listeners
414
459
  emit(e, ...t) {
415
- const s = this.eventListeners.get(e);
416
- s && s.forEach((i) => i(...t));
460
+ const i = this.eventListeners.get(e);
461
+ i && i.forEach((s) => s(...t));
417
462
  }
418
463
  // State management
419
464
  getValue() {
@@ -461,12 +506,12 @@ class I {
461
506
  "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
462
507
  };
463
508
  this.view.applyTheme(t);
464
- const s = this.extensions.get("syntax-highlighting");
465
- if (s && typeof s.setTheme == "function")
509
+ const i = this.extensions.get("syntax-highlighting");
510
+ if (i && typeof i.setTheme == "function")
466
511
  try {
467
- s.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
468
- } catch (i) {
469
- console.warn("Error applying theme to syntax-highlighting extension", i);
512
+ i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
513
+ } catch (s) {
514
+ console.warn("Error applying theme to syntax-highlighting extension", s);
470
515
  }
471
516
  }
472
517
  setReadOnly(e) {
@@ -483,8 +528,8 @@ class I {
483
528
  t && t.destroy && t.destroy(), this.extensions.delete(e);
484
529
  }
485
530
  executeCommand(e, ...t) {
486
- const s = this.commands.get(e);
487
- s ? s(this, ...t) : console.warn(`Command '${e}' not found`);
531
+ const i = this.commands.get(e);
532
+ i ? i(this, ...t) : console.warn(`Command '${e}' not found`);
488
533
  }
489
534
  // Register a command
490
535
  registerCommand(e, t) {
@@ -492,51 +537,51 @@ class I {
492
537
  }
493
538
  // Search & Navigation
494
539
  search(e, t = {}) {
495
- const s = {
540
+ const i = {
496
541
  caseSensitive: !1,
497
542
  regex: !1,
498
543
  ...t
499
- }, i = [], r = this.getValue();
544
+ }, s = [], r = this.getValue();
500
545
  r.split(`
501
546
  `);
502
- let n = s.caseSensitive ? r : r.toLowerCase(), o = s.caseSensitive ? e : e.toLowerCase();
503
- if (s.regex) {
504
- const a = new RegExp(o, s.caseSensitive ? "g" : "gi");
505
- let l;
506
- for (; (l = a.exec(n)) !== null; ) {
507
- const c = this.textModel.offsetToPosition(l.index), g = this.textModel.offsetToPosition(l.index + l[0].length);
508
- i.push({
547
+ let o = i.caseSensitive ? r : r.toLowerCase(), n = i.caseSensitive ? e : e.toLowerCase();
548
+ if (i.regex) {
549
+ const l = new RegExp(n, i.caseSensitive ? "g" : "gi");
550
+ let a;
551
+ for (; (a = l.exec(o)) !== null; ) {
552
+ const c = this.textModel.offsetToPosition(a.index), g = this.textModel.offsetToPosition(a.index + a[0].length);
553
+ s.push({
509
554
  range: { start: c, end: g },
510
- match: l[0]
555
+ match: a[0]
511
556
  });
512
557
  }
513
558
  } else {
514
- let a = 0, l = n.indexOf(o, a);
515
- for (; l !== -1; ) {
516
- const c = l + e.length, g = this.textModel.offsetToPosition(l), d = this.textModel.offsetToPosition(c);
517
- i.push({
518
- range: { start: g, end: d },
519
- match: r.substring(l, c)
520
- }), a = c, l = n.indexOf(o, a);
559
+ let l = 0, a = o.indexOf(n, l);
560
+ for (; a !== -1; ) {
561
+ const c = a + e.length, g = this.textModel.offsetToPosition(a), h = this.textModel.offsetToPosition(c);
562
+ s.push({
563
+ range: { start: g, end: h },
564
+ match: r.substring(a, c)
565
+ }), l = c, a = o.indexOf(n, l);
521
566
  }
522
567
  }
523
- return i;
568
+ return s;
524
569
  }
525
570
  replace(e, t) {
526
- const s = this.getValue();
571
+ const i = this.getValue();
527
572
  if (!this.suppressHistory) {
528
- const r = this.getCursor().position, n = this.textModel.positionToOffset(r), o = this.getSelection();
529
- let a, l;
530
- o && (a = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: s, cursorOffset: n, anchorOffset: a, focusOffset: l }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
573
+ const r = this.getCursor().position, o = this.textModel.positionToOffset(r), n = this.getSelection();
574
+ let l, a;
575
+ n && (l = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: i, cursorOffset: o, anchorOffset: l, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
531
576
  }
532
- const i = this.textModel.replaceRange(e, t);
533
- this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [i]);
577
+ const s = this.textModel.replaceRange(e, t);
578
+ this.renderTextWithHighlight(this.getValue(), !1), this.emit("change", [s]);
534
579
  }
535
- replaceAll(e, t, s = {}) {
536
- const i = this.search(e, s);
580
+ replaceAll(e, t, i = {}) {
581
+ const s = this.search(e, i);
537
582
  let r = 0;
538
- for (let n = i.length - 1; n >= 0; n--)
539
- this.replace(i[n].range, t), r++;
583
+ for (let o = s.length - 1; o >= 0; o--)
584
+ this.replace(s[o].range, t), r++;
540
585
  return r;
541
586
  }
542
587
  // Folding (basic implementation)
@@ -569,35 +614,84 @@ class I {
569
614
  // and restores it after updating the DOM. Callers that will explicitly set the caret
570
615
  // should pass `false` to avoid stomping programmatic cursor changes.
571
616
  renderTextWithHighlight(e, t = !0) {
572
- const s = this.extensions.get("syntax-highlighting");
573
- if (s && typeof s.highlightHTML == "function")
617
+ const i = this.extensions.get("syntax-highlighting");
618
+ if (i && typeof i.highlightHTML == "function")
574
619
  try {
575
- const i = !t && !this.expectingProgrammaticCursor;
576
- let r, n, o, a;
577
- if (t || i) {
620
+ const s = !t && !this.expectingProgrammaticCursor;
621
+ let r, o, n, l;
622
+ if (t || s) {
578
623
  r = this.getSelection();
579
- const c = this.getCursor().position;
580
- n = this.textModel.positionToOffset(c), r && (o = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end));
624
+ const h = this.getCollapsedSelectionOffsetInEditor();
625
+ if (h !== void 0)
626
+ o = h;
627
+ else {
628
+ const u = this.getCursor().position;
629
+ o = this.textModel.positionToOffset(u);
630
+ }
631
+ r && (n = this.textModel.positionToOffset(r.start), l = this.textModel.positionToOffset(r.end));
581
632
  }
582
- const l = s.highlightHTML(e);
583
- typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(l) : this.view.setHTML(l), (t || i) && requestAnimationFrame(() => {
633
+ const a = (t || s) && !r && o !== void 0 && this.hasCollapsedSelectionInEditor(), c = a ? this.insertSentinelAtOffset(e, o) : e, g = i.highlightHTML(c);
634
+ typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(g) : this.view.setHTML(g), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && requestAnimationFrame(() => {
584
635
  try {
585
- if (r && (o !== void 0 || a !== void 0)) {
586
- const c = o !== void 0 ? o : n, g = a !== void 0 ? a : n, d = Math.min(c, g), u = Math.max(c, g), h = this.textModel.offsetToPosition(d), f = this.textModel.offsetToPosition(u);
587
- this.view.setSelectionRange({ start: h, end: f });
588
- } else if (n !== void 0) {
589
- const c = this.textModel.offsetToPosition(n);
590
- this.view.setCursorPosition(c);
636
+ if (a && this.restoreCursorFromSentinel()) {
637
+ this.view.ensureCaretVisible();
638
+ return;
639
+ }
640
+ if (r && (n !== void 0 || l !== void 0)) {
641
+ const h = n !== void 0 ? n : o, u = l !== void 0 ? l : o, d = Math.min(h, u), f = Math.max(h, u), m = this.textModel.offsetToPosition(d), y = this.textModel.offsetToPosition(f);
642
+ this.view.setSelectionRange({ start: m, end: y });
643
+ } else if (o !== void 0) {
644
+ const h = this.textModel.offsetToPosition(o);
645
+ this.view.setCursorPosition(h);
591
646
  }
592
647
  } catch {
593
648
  }
594
649
  });
595
650
  return;
596
- } catch (i) {
597
- console.warn("Syntax highlighting failed, falling back to plain text", i);
651
+ } catch (s) {
652
+ console.warn("Syntax highlighting failed, falling back to plain text", s);
598
653
  }
599
654
  this.view.setText(e);
600
655
  }
656
+ hasCollapsedSelectionInEditor() {
657
+ const e = window.getSelection();
658
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
659
+ return !1;
660
+ const t = e.getRangeAt(0);
661
+ return this.view.getContentElement().contains(t.commonAncestorContainer);
662
+ }
663
+ getCollapsedSelectionOffsetInEditor() {
664
+ const e = window.getSelection();
665
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
666
+ return;
667
+ const t = e.getRangeAt(0), i = this.view.getContentElement();
668
+ if (!i.contains(t.commonAncestorContainer))
669
+ return;
670
+ const s = t.cloneRange();
671
+ return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
672
+ }
673
+ stripVirtualMarkers(e) {
674
+ return e.replace(/\u200B/g, "").split(M.CURSOR_SENTINEL).join("");
675
+ }
676
+ insertSentinelAtOffset(e, t) {
677
+ const i = Math.max(0, Math.min(t, e.length));
678
+ return e.slice(0, i) + M.CURSOR_SENTINEL + e.slice(i);
679
+ }
680
+ restoreCursorFromSentinel() {
681
+ const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
682
+ let s = i.nextNode(), r = null, o = 0;
683
+ for (; s; ) {
684
+ const n = s.textContent ?? "", l = n.indexOf(M.CURSOR_SENTINEL);
685
+ l !== -1 && (r || (r = s, o = l), s.textContent = n.split(M.CURSOR_SENTINEL).join("")), s = i.nextNode();
686
+ }
687
+ if (!r || !t) return !1;
688
+ try {
689
+ const n = document.createRange();
690
+ return n.setStart(r, o), n.collapse(!0), t.removeAllRanges(), t.addRange(n), !0;
691
+ } catch {
692
+ return !1;
693
+ }
694
+ }
601
695
  destroy() {
602
696
  if (!this.isDestroyed) {
603
697
  this.isDestroyed = !0;
@@ -613,15 +707,15 @@ class I {
613
707
  this.redoStack.push(t);
614
708
  try {
615
709
  this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
616
- let s, i;
617
- typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
710
+ let i, s;
711
+ typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
618
712
  try {
619
- if (i != null)
713
+ if (s != null)
620
714
  if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
621
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : i, n = e.focusOffset !== void 0 ? e.focusOffset : i, o = Math.min(r, n), a = Math.max(r, n), l = this.textModel.offsetToPosition(o), c = this.textModel.offsetToPosition(a);
622
- this.setSelection({ start: l, end: c });
715
+ const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, o = e.focusOffset !== void 0 ? e.focusOffset : s, n = Math.min(r, o), l = Math.max(r, o), a = this.textModel.offsetToPosition(n), c = this.textModel.offsetToPosition(l);
716
+ this.setSelection({ start: a, end: c });
623
717
  } else {
624
- const r = this.textModel.offsetToPosition(i);
718
+ const r = this.textModel.offsetToPosition(s);
625
719
  this.setCursor(r);
626
720
  }
627
721
  } catch {
@@ -639,15 +733,15 @@ class I {
639
733
  this.undoStack.push(t);
640
734
  try {
641
735
  this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
642
- let s, i;
643
- typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
736
+ let i, s;
737
+ typeof e == "string" ? i = e : (i = e.text, s = e.cursorOffset), this.setValue(i), requestAnimationFrame(() => {
644
738
  try {
645
- if (i != null)
739
+ if (s != null)
646
740
  if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
647
- const r = e.anchorOffset !== void 0 ? e.anchorOffset : i, n = e.focusOffset !== void 0 ? e.focusOffset : i, o = Math.min(r, n), a = Math.max(r, n), l = this.textModel.offsetToPosition(o), c = this.textModel.offsetToPosition(a);
648
- this.setSelection({ start: l, end: c });
741
+ const r = e.anchorOffset !== void 0 ? e.anchorOffset : s, o = e.focusOffset !== void 0 ? e.focusOffset : s, n = Math.min(r, o), l = Math.max(r, o), a = this.textModel.offsetToPosition(n), c = this.textModel.offsetToPosition(l);
742
+ this.setSelection({ start: a, end: c });
649
743
  } else {
650
- const r = this.textModel.offsetToPosition(i);
744
+ const r = this.textModel.offsetToPosition(s);
651
745
  this.setCursor(r);
652
746
  }
653
747
  } catch {
@@ -662,29 +756,29 @@ class I {
662
756
  // Insert a tab character or spaces at current cursor
663
757
  insertTab() {
664
758
  if (this.config.readOnly) return;
665
- 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);
759
+ 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);
666
760
  if (!this.suppressHistory) {
667
- const n = this.getSelection();
668
- let o, a;
669
- 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;
761
+ const o = this.getSelection();
762
+ let n, l;
763
+ o && (n = this.textModel.positionToOffset(o.start), l = this.textModel.positionToOffset(o.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: n, focusOffset: l }), this.redoStack.length = 0;
670
764
  }
671
765
  this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(r), setTimeout(() => {
672
766
  this.expectingProgrammaticCursor = !1;
673
- }, 20), this.emit("change", [i]);
767
+ }, 20), this.emit("change", [s]);
674
768
  }
675
769
  // Insert a newline at current cursor position
676
770
  insertNewLine() {
677
771
  if (this.config.readOnly) return;
678
- const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = this.textModel.insertText(e, `
679
- `), i = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
772
+ const e = this.getCursor().position, t = this.textModel.positionToOffset(e), i = this.textModel.insertText(e, `
773
+ `), s = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
680
774
  if (!this.suppressHistory) {
681
775
  const r = this.getSelection();
682
- let n, o;
683
- 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;
776
+ let o, n;
777
+ r && (o = this.textModel.positionToOffset(r.start), n = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: o, focusOffset: n }), this.redoStack.length = 0;
684
778
  }
685
- this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(i), setTimeout(() => {
779
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(s), setTimeout(() => {
686
780
  this.expectingProgrammaticCursor = !1;
687
- }, 20), this.emit("change", [s]);
781
+ }, 20), this.emit("change", [i]);
688
782
  }
689
783
  // Events
690
784
  on(e, t) {
@@ -692,15 +786,17 @@ class I {
692
786
  }
693
787
  off(e, t) {
694
788
  if (!this.eventListeners.has(e)) return;
695
- const s = this.eventListeners.get(e);
789
+ const i = this.eventListeners.get(e);
696
790
  if (t) {
697
- const i = s.indexOf(t);
698
- i !== -1 && s.splice(i, 1);
791
+ const s = i.indexOf(t);
792
+ s !== -1 && i.splice(s, 1);
699
793
  } else
700
- s.length = 0;
794
+ i.length = 0;
701
795
  }
702
- }
703
- class N {
796
+ };
797
+ $.CURSOR_SENTINEL = "";
798
+ let A = $;
799
+ class B {
704
800
  constructor(e) {
705
801
  this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
706
802
  }
@@ -714,12 +810,12 @@ class N {
714
810
  return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
715
811
  }
716
812
  findMatchingBinding(e) {
717
- const { key: t, ctrlKey: s, altKey: i, shiftKey: r, metaKey: n } = e, o = String(t).toLowerCase(), a = this.keymap[o];
718
- if (!a) return null;
719
- for (const l of a) {
720
- const c = l.ctrlKey === void 0 || l.ctrlKey === s, g = l.altKey === void 0 || l.altKey === i, d = l.shiftKey === void 0 || l.shiftKey === r, u = l.metaKey === void 0 || l.metaKey === n;
721
- if (c && g && d && u)
722
- return l;
813
+ const { key: t, ctrlKey: i, altKey: s, shiftKey: r, metaKey: o } = e, n = String(t).toLowerCase(), l = this.keymap[n];
814
+ if (!l) return null;
815
+ for (const a of l) {
816
+ const c = a.ctrlKey === void 0 || a.ctrlKey === i, g = a.altKey === void 0 || a.altKey === s, h = a.shiftKey === void 0 || a.shiftKey === r, u = a.metaKey === void 0 || a.metaKey === o;
817
+ if (c && g && h && u)
818
+ return a;
723
819
  }
724
820
  return null;
725
821
  }
@@ -731,12 +827,12 @@ class N {
731
827
  const e = {};
732
828
  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;
733
829
  }
734
- addBinding(e, t, s, i) {
830
+ addBinding(e, t, i, s) {
735
831
  const r = t.toLowerCase();
736
832
  e[r] || (e[r] = []), e[r].push({
737
833
  key: r,
738
- command: i,
739
- ...s
834
+ command: s,
835
+ ...i
740
836
  });
741
837
  }
742
838
  // Public API for customizing keymap
@@ -745,23 +841,23 @@ class N {
745
841
  }
746
842
  addKeyBinding(e) {
747
843
  const t = e.key.toLowerCase();
748
- this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((s) => s.command !== e.command), this.keymap[t].push({
844
+ this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
749
845
  ...e,
750
846
  key: t
751
847
  });
752
848
  }
753
849
  removeKeyBinding(e, t) {
754
- const s = e.toLowerCase();
755
- 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];
850
+ const i = e.toLowerCase();
851
+ 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];
756
852
  }
757
853
  getKeymap() {
758
854
  return { ...this.keymap };
759
855
  }
760
856
  getBindingsForCommand(e) {
761
857
  const t = [];
762
- for (const s in this.keymap)
763
- for (const i of this.keymap[s])
764
- i.command === e && t.push({ ...i });
858
+ for (const i in this.keymap)
859
+ for (const s of this.keymap[i])
860
+ s.command === e && t.push({ ...s });
765
861
  return t;
766
862
  }
767
863
  getPlatformInfo() {
@@ -774,19 +870,19 @@ class N {
774
870
  this.keymap = {}, this.editor = null;
775
871
  }
776
872
  }
777
- class B {
873
+ class V {
778
874
  constructor() {
779
875
  this.name = "transaction", this.transactions = [];
780
876
  }
781
877
  setup(e) {
782
878
  e.on("change", (t) => {
783
- const s = {
784
- changes: [t],
879
+ const i = {
880
+ changes: t,
785
881
  selection: e.getSelection(),
786
882
  effects: [],
787
883
  annotations: []
788
884
  };
789
- this.transactions.push(s);
885
+ this.transactions.push(i);
790
886
  });
791
887
  }
792
888
  getTransactions() {
@@ -815,10 +911,11 @@ class K {
815
911
  updateLineNumbers() {
816
912
  if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
817
913
  const e = this.editor.getValue().split(`
818
- `).length, t = Array.from({ length: Math.max(e, 20) }, (s, i) => i + 1);
819
- this.lineNumbersElement.innerHTML = t.map((s) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("");
914
+ `).length, t = Array.from({ length: Math.max(e, 20) }, (i, s) => s + 1);
915
+ this.lineNumbersElement.innerHTML = t.map((i) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${i}</div>`).join("");
820
916
  }
821
917
  toggle() {
918
+ if (!this.editor) return;
822
919
  this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
823
920
  const e = this.editor.getView().getContentElement();
824
921
  e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
@@ -827,7 +924,7 @@ class K {
827
924
  this.lineNumbersElement = null, this.editor = null;
828
925
  }
829
926
  }
830
- class A {
927
+ class U {
831
928
  constructor() {
832
929
  this.name = "theme", this.editor = null, this.currentTheme = "dark";
833
930
  }
@@ -852,7 +949,7 @@ class A {
852
949
  this.editor = null;
853
950
  }
854
951
  }
855
- class V {
952
+ class z {
856
953
  constructor() {
857
954
  this.name = "read-only", this.editor = null, this.isReadOnly = !1;
858
955
  }
@@ -879,7 +976,7 @@ class V {
879
976
  this.editor = null;
880
977
  }
881
978
  }
882
- class U {
979
+ class q {
883
980
  constructor() {
884
981
  this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1;
885
982
  }
@@ -892,8 +989,8 @@ class U {
892
989
  this.findPrev();
893
990
  }), e.registerCommand("replace", () => {
894
991
  this.showReplace();
895
- }), e.registerCommand("replaceAll", (t, s) => {
896
- this.replaceAll(t, s);
992
+ }), e.registerCommand("replaceAll", (t, i) => {
993
+ this.replaceAll(t, i);
897
994
  });
898
995
  }
899
996
  showSearch() {
@@ -987,35 +1084,35 @@ class U {
987
1084
  margin-top: 4px;
988
1085
  " />
989
1086
  `;
990
- 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");
1087
+ const t = this.searchUI.querySelector("input"), i = this.searchUI.querySelector(".search-replace-input"), s = this.searchUI.querySelector(".search-prev"), r = this.searchUI.querySelector(".search-next"), o = this.searchUI.querySelector(".search-close");
991
1088
  t.addEventListener("input", () => {
992
1089
  this.performSearch(t.value);
993
- }), t.addEventListener("keydown", (o) => {
994
- o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.findPrev() : this.findNext());
995
- }), s.addEventListener("keydown", (o) => {
996
- o.key === "Enter" && (o.preventDefault(), o.shiftKey ? this.replaceAll(t.value, s.value) : this.replaceCurrent(t.value, s.value));
997
- }), i.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), n.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
1090
+ }), t.addEventListener("keydown", (n) => {
1091
+ n.key === "Enter" && (n.preventDefault(), n.shiftKey ? this.findPrev() : this.findNext());
1092
+ }), i.addEventListener("keydown", (n) => {
1093
+ n.key === "Enter" && (n.preventDefault(), n.shiftKey ? this.replaceAll(t.value, i.value) : this.replaceCurrent(t.value, i.value));
1094
+ }), s.addEventListener("click", () => this.findPrev()), r.addEventListener("click", () => this.findNext()), o.addEventListener("click", () => this.hideSearch()), e.appendChild(this.searchUI);
998
1095
  }
999
1096
  performSearch(e) {
1000
1097
  if (!this.editor || !e.trim()) {
1001
1098
  this.clearHighlights(), this.updateStatus("");
1002
1099
  return;
1003
1100
  }
1004
- const t = this.editor.getValue(), s = [];
1005
- let i = t.toLowerCase().indexOf(e.toLowerCase());
1006
- for (; i !== -1; ) {
1007
- const r = this.getPositionFromOffset(t, i), n = this.getPositionFromOffset(t, i + e.length);
1008
- s.push({
1009
- range: { start: r, end: n },
1010
- match: t.substring(i, i + e.length)
1011
- }), i = t.toLowerCase().indexOf(e.toLowerCase(), i + 1);
1101
+ const t = this.editor.getValue(), i = [];
1102
+ let s = t.toLowerCase().indexOf(e.toLowerCase());
1103
+ for (; s !== -1; ) {
1104
+ const r = this.getPositionFromOffset(t, s), o = this.getPositionFromOffset(t, s + e.length);
1105
+ i.push({
1106
+ range: { start: r, end: o },
1107
+ match: t.substring(s, s + e.length)
1108
+ }), s = t.toLowerCase().indexOf(e.toLowerCase(), s + 1);
1012
1109
  }
1013
- this.currentResults = s, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
1110
+ this.currentResults = i, this.currentIndex = this.currentResults.length > 0 ? 0 : -1, this.updateHighlights(), this.updateStatus(`${this.currentResults.length} matches`);
1014
1111
  }
1015
1112
  getPositionFromOffset(e, t) {
1016
- const s = e.substring(0, t).split(`
1017
- `), i = s.length - 1, r = s[s.length - 1].length;
1018
- return { line: i, column: r };
1113
+ const i = e.substring(0, t).split(`
1114
+ `), s = i.length - 1, r = i[i.length - 1].length;
1115
+ return { line: s, column: r };
1019
1116
  }
1020
1117
  findNext() {
1021
1118
  this.currentResults.length !== 0 && (this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights());
@@ -1025,25 +1122,25 @@ class U {
1025
1122
  }
1026
1123
  replaceCurrent(e, t) {
1027
1124
  if (!this.editor || !e.trim() || this.currentIndex === -1) return;
1028
- const s = this.currentResults[this.currentIndex];
1029
- if (!s) return;
1030
- 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;
1031
- this.editor.setValue(a), this.performSearch(e), this.updateStatus("Replaced current occurrence");
1125
+ const i = this.currentResults[this.currentIndex];
1126
+ if (!i) return;
1127
+ const s = this.editor.getValue(), r = this.getOffsetFromPosition(s, i.range.start), o = s.substring(0, r), n = s.substring(r + e.length), l = o + t + n;
1128
+ this.editor.setValue(l), this.performSearch(e), this.updateStatus("Replaced current occurrence");
1032
1129
  }
1033
1130
  replaceAll(e, t) {
1034
1131
  if (!this.editor || !e.trim()) return;
1035
- let s = this.editor.getValue(), i = 0, r = s.toLowerCase().indexOf(e.toLowerCase());
1132
+ let i = this.editor.getValue(), s = 0, r = i.toLowerCase().indexOf(e.toLowerCase());
1036
1133
  for (; r !== -1; )
1037
- s = s.substring(0, r) + t + s.substring(r + e.length), i++, r = s.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
1038
- i > 0 && (this.editor.setValue(s), this.updateStatus(`Replaced ${i} occurrences`));
1134
+ i = i.substring(0, r) + t + i.substring(r + e.length), s++, r = i.toLowerCase().indexOf(e.toLowerCase(), r + t.length);
1135
+ s > 0 && (this.editor.setValue(i), this.updateStatus(`Replaced ${s} occurrences`));
1039
1136
  }
1040
1137
  getOffsetFromPosition(e, t) {
1041
- const s = e.split(`
1138
+ const i = e.split(`
1042
1139
  `);
1043
- let i = 0;
1140
+ let s = 0;
1044
1141
  for (let r = 0; r < t.line; r++)
1045
- i += s[r].length + 1;
1046
- return i += t.column, i;
1142
+ s += i[r].length + 1;
1143
+ return s += t.column, s;
1047
1144
  }
1048
1145
  updateHighlights() {
1049
1146
  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})`));
@@ -1058,7 +1155,7 @@ class U {
1058
1155
  this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.searchUI = null, this.editor = null;
1059
1156
  }
1060
1157
  }
1061
- class z {
1158
+ class F {
1062
1159
  constructor() {
1063
1160
  this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
1064
1161
  "(": ")",
@@ -1083,58 +1180,58 @@ class z {
1083
1180
  if (!this.editor) return;
1084
1181
  const e = this.editor.getCursor(), t = this.editor.getValue();
1085
1182
  this.clearBracketHighlighting();
1086
- const s = this.getBracketAtPosition(t, e.position);
1087
- if (!s) return;
1088
- const i = this.findMatchingBracket(t, s);
1089
- i && (this.currentMatch = i, this.highlightBrackets(i));
1183
+ const i = this.getBracketAtPosition(t, e.position);
1184
+ if (!i) return;
1185
+ const s = this.findMatchingBracket(t, i);
1186
+ s && (this.currentMatch = s, this.highlightBrackets(s));
1090
1187
  }
1091
1188
  getBracketAtPosition(e, t) {
1092
- const s = e.split(`
1189
+ const i = e.split(`
1093
1190
  `);
1094
- if (t.line >= s.length) return null;
1095
- const i = s[t.line];
1096
- if (t.column >= i.length) return null;
1097
- const r = i[t.column];
1191
+ if (t.line >= i.length) return null;
1192
+ const s = i[t.line];
1193
+ if (t.column >= s.length) return null;
1194
+ const r = s[t.column];
1098
1195
  return this.bracketPairs[r] || this.reverseBracketPairs[r] ? { char: r, position: t } : null;
1099
1196
  }
1100
1197
  findMatchingBracket(e, t) {
1101
- const s = e.split(`
1102
- `), i = t.position.line, r = t.position.column, n = t.char;
1103
- return this.bracketPairs[n] ? this.findClosingBracket(e, s, i, r, n) : this.reverseBracketPairs[n] ? this.findOpeningBracket(e, s, i, r, n) : null;
1104
- }
1105
- findClosingBracket(e, t, s, i, r) {
1106
- const n = this.bracketPairs[r];
1107
- let o = 0;
1108
- for (let a = s; a < t.length; a++) {
1109
- const l = t[a], c = a === s ? i : 0;
1110
- for (let g = c; g < l.length; g++) {
1111
- const d = l[g];
1112
- if (d === r)
1113
- o++;
1114
- else if (d === n && (o--, o === 0))
1198
+ const i = e.split(`
1199
+ `), s = t.position.line, r = t.position.column, o = t.char;
1200
+ return this.bracketPairs[o] ? this.findClosingBracket(e, i, s, r, o) : this.reverseBracketPairs[o] ? this.findOpeningBracket(e, i, s, r, o) : null;
1201
+ }
1202
+ findClosingBracket(e, t, i, s, r) {
1203
+ const o = this.bracketPairs[r];
1204
+ let n = 0;
1205
+ for (let l = i; l < t.length; l++) {
1206
+ const a = t[l], c = l === i ? s : 0;
1207
+ for (let g = c; g < a.length; g++) {
1208
+ const h = a[g];
1209
+ if (h === r)
1210
+ n++;
1211
+ else if (h === o && (n--, n === 0))
1115
1212
  return {
1116
- open: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1117
- close: { start: { line: a, column: g }, end: { line: a, column: g + 1 } },
1213
+ open: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1214
+ close: { start: { line: l, column: g }, end: { line: l, column: g + 1 } },
1118
1215
  type: r
1119
1216
  };
1120
1217
  }
1121
1218
  }
1122
1219
  return null;
1123
1220
  }
1124
- findOpeningBracket(e, t, s, i, r) {
1125
- const n = this.reverseBracketPairs[r];
1126
- let o = 0;
1127
- for (let a = s; a >= 0; a--) {
1128
- const l = t[a], c = a === s ? i : l.length - 1;
1221
+ findOpeningBracket(e, t, i, s, r) {
1222
+ const o = this.reverseBracketPairs[r];
1223
+ let n = 0;
1224
+ for (let l = i; l >= 0; l--) {
1225
+ const a = t[l], c = l === i ? s : a.length - 1;
1129
1226
  for (let g = c; g >= 0; g--) {
1130
- const d = l[g];
1131
- if (d === r)
1132
- o++;
1133
- else if (d === n && (o--, o === 0))
1227
+ const h = a[g];
1228
+ if (h === r)
1229
+ n++;
1230
+ else if (h === o && (n--, n === 0))
1134
1231
  return {
1135
- open: { start: { line: a, column: g }, end: { line: a, column: g + 1 } },
1136
- close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1137
- type: n
1232
+ open: { start: { line: l, column: g }, end: { line: l, column: g + 1 } },
1233
+ close: { start: { line: i, column: s }, end: { line: i, column: s + 1 } },
1234
+ type: o
1138
1235
  };
1139
1236
  }
1140
1237
  }
@@ -1152,7 +1249,7 @@ class z {
1152
1249
  this.clearBracketHighlighting(), this.editor = null;
1153
1250
  }
1154
1251
  }
1155
- class q {
1252
+ class _ {
1156
1253
  constructor() {
1157
1254
  this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null;
1158
1255
  }
@@ -1193,9 +1290,9 @@ class q {
1193
1290
  }
1194
1291
  findFoldableLines(e) {
1195
1292
  const t = [];
1196
- for (let s = 0; s < e.length; s++) {
1197
- const i = e[s].trim();
1198
- (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);
1293
+ for (let i = 0; i < e.length; i++) {
1294
+ const s = e[i].trim();
1295
+ (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);
1199
1296
  }
1200
1297
  return t;
1201
1298
  }
@@ -1231,12 +1328,12 @@ class q {
1231
1328
  this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.foldingUI = null, this.foldIndicators = [], this.editor = null;
1232
1329
  }
1233
1330
  }
1234
- class _ {
1331
+ class W {
1235
1332
  constructor() {
1236
1333
  this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
1237
1334
  }
1238
1335
  setup(e) {
1239
- 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) });
1336
+ 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) });
1240
1337
  }
1241
1338
  // Extension provides methods that can be called by the editor
1242
1339
  setTheme(e) {
@@ -1296,8 +1393,8 @@ class _ {
1296
1393
  }
1297
1394
  // Public API: highlight a source string using the chosen mode (or detect html)
1298
1395
  highlight(e, t) {
1299
- const s = this.getSyntaxColors(), i = (t || this.currentLanguage || "html").toLowerCase();
1300
- return (this.modes.get(i) || this.modes.get("html")).highlight(e, s);
1396
+ const i = this.getSyntaxColors(), s = (t || this.currentLanguage || "html").toLowerCase();
1397
+ return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
1301
1398
  }
1302
1399
  // Backwards-compatible method
1303
1400
  highlightHTML(e) {
@@ -1310,124 +1407,127 @@ class _ {
1310
1407
  // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
1311
1408
  unescapeEntitiesRepeated(e) {
1312
1409
  let t = e || "";
1313
- for (let s = 0; s < 5; s++) {
1314
- const i = t;
1315
- if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === i) break;
1410
+ for (let i = 0; i < 5; i++) {
1411
+ const s = t;
1412
+ if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === s) break;
1316
1413
  }
1317
1414
  return t;
1318
1415
  }
1319
1416
  _highlightHTML(e, t) {
1320
- const s = t, i = (l) => this.escapeHTML(l);
1321
- let r = i(e);
1322
- const n = (l) => {
1323
- let c = l.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1324
- return c = c.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), c = c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (g, d, u, h, f) => {
1325
- const m = String(h).trim(), x = i(m);
1326
- return `<span style="color: ${s.styleProp};">${d}</span>${u}<span style="color: ${s.styleVal};">${x}</span>${f}`;
1417
+ const i = t, s = (a) => this.escapeHTML(a);
1418
+ let r = s(e);
1419
+ const o = (a) => {
1420
+ let c = a.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1421
+ return c = c.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${i.comment};">$1</span>`), c = c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (g, h, u, d, f) => {
1422
+ const m = String(d).trim(), y = s(m);
1423
+ return `<span style="color: ${i.styleProp};">${h}</span>${u}<span style="color: ${i.styleVal};">${y}</span>${f}`;
1327
1424
  }), c;
1328
- }, o = [];
1425
+ }, n = [];
1329
1426
  try {
1330
- e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (l, c, g) => (o.push({ attrs: String(c || ""), inner: String(g || "") }), l));
1427
+ e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (a, c, g) => (n.push({ attrs: String(c || ""), inner: String(g || "") }), a));
1331
1428
  } catch {
1332
1429
  }
1333
- let a = 0;
1334
- return r = r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (l, c, g, d, u) => {
1335
- const h = o[a++]?.inner ?? this.unescapeEntitiesRepeated(d || "");
1336
- (o[a - 1]?.attrs || g || "").toLowerCase();
1337
- const f = this._highlightJS(h, s);
1430
+ let l = 0;
1431
+ return r = r.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (a, c, g, h, u) => {
1432
+ const d = n[l++]?.inner ?? this.unescapeEntitiesRepeated(h || "");
1433
+ (n[l - 1]?.attrs || g || "").toLowerCase();
1434
+ const f = this._highlightJS(d, i);
1338
1435
  return `${c}${f}${u}`;
1339
- }), r = r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (l, c, g, d) => {
1340
- const u = n(g);
1341
- return `${c}${u}${d}`;
1342
- }), r = r.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${s.comment};">$1</span>`), r = r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${s.doctype};">$1</span>`), r = r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (l, c, g, d, u) => {
1343
- const h = `<span style="color: ${s.tag};">${g}</span>`;
1344
- let f = d;
1345
- return f = f.replace(/([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g, (m, x, k, y) => {
1346
- const C = String(x).toLowerCase(), L = `<span style="color: ${s.attrName};">${x}</span>`;
1347
- let w = y, b = "";
1348
- y.startsWith("&quot;") && y.endsWith("&quot;") ? (w = y.slice(6, -6), b = "&quot;") : y.startsWith("&#39;") && y.endsWith("&#39;") && (w = y.slice(5, -5), b = "&#39;");
1349
- let T = y;
1350
- if (C === "style") {
1351
- const S = w.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (E, p, M, $) => `<span style="color: ${s.styleProp};">${p}</span>:<span style="color: ${s.styleVal};">${M.trim()}</span>${$}`);
1352
- b ? T = `${b}${S}${b}` : T = S, T = `<span style="color: ${s.attrValue};">${T}</span>`;
1353
- } else
1354
- b && (T = `${b}${w}${b}`), T = `<span style="color: ${s.attrValue};">${T}</span>`;
1355
- return `${L}${k}${T}`;
1356
- }), `${c}${h}${f}${u}`;
1436
+ }), r = r.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (a, c, g, h) => {
1437
+ const u = o(g);
1438
+ return `${c}${u}${h}`;
1439
+ }), r = r.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${i.comment};">$1</span>`), r = r.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${i.doctype};">$1</span>`), r = r.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (a, c, g, h, u) => {
1440
+ const d = `<span style="color: ${i.tag};">${g}</span>`;
1441
+ let f = h;
1442
+ return f = f.replace(
1443
+ /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
1444
+ (m, y, w, x) => {
1445
+ const E = String(y).toLowerCase(), L = `<span style="color: ${i.attrName};">${y}</span>`;
1446
+ let C = x, b = "";
1447
+ x.startsWith("&quot;") && x.endsWith("&quot;") ? (C = x.slice(6, -6), b = "&quot;") : x.startsWith("&#39;") && x.endsWith("&#39;") && (C = x.slice(5, -5), b = "&#39;");
1448
+ let k = x;
1449
+ if (E === "style") {
1450
+ const S = C.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (O, p, T, N) => `<span style="color: ${i.styleProp};">${p}</span>:<span style="color: ${i.styleVal};">${T.trim()}</span>${N}`);
1451
+ b ? k = `${b}${S}${b}` : k = S, k = `<span style="color: ${i.attrValue};">${k}</span>`;
1452
+ } else
1453
+ b && (k = `${b}${C}${b}`), k = `<span style="color: ${i.attrValue};">${k}</span>`;
1454
+ return `${L}${w}${k}`;
1455
+ }
1456
+ ), `${c}${d}${f}${u}`;
1357
1457
  }), r;
1358
1458
  }
1359
1459
  _highlightJS(e, t) {
1360
- const s = this.unescapeEntitiesRepeated(e);
1361
- this.escapeHTML(s);
1362
- const i = [], r = (d) => {
1363
- let u = "", h = d;
1460
+ const i = this.unescapeEntitiesRepeated(e);
1461
+ this.escapeHTML(i);
1462
+ const s = [], r = (h) => {
1463
+ let u = "", d = h;
1364
1464
  do
1365
- u = String.fromCharCode(97 + h % 26) + u, h = Math.floor(h / 26) - 1;
1366
- while (h >= 0);
1465
+ u = String.fromCharCode(97 + d % 26) + u, d = Math.floor(d / 26) - 1;
1466
+ while (d >= 0);
1367
1467
  return u || "a";
1368
- }, n = (d) => `\0${r(d)}\0`, o = (d) => {
1369
- const u = i.length;
1370
- return i.push(d), n(u);
1468
+ }, o = (h) => `\0${r(h)}\0`, n = (h) => {
1469
+ const u = s.length;
1470
+ return s.push(h), o(u);
1371
1471
  };
1372
- let a;
1373
- const l = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
1472
+ let l;
1473
+ const a = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
1374
1474
  let c = 0, g = "";
1375
- for (; a = l.exec(s); ) {
1376
- const d = a.index;
1377
- c < d && (g += this.escapeHTML(s.slice(c, d)));
1378
- const u = a[0];
1379
- /^\/\*/.test(u) || /^\/\//.test(u) ? g += o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`) : g += o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`), c = l.lastIndex;
1475
+ for (; l = a.exec(i); ) {
1476
+ const h = l.index;
1477
+ c < h && (g += this.escapeHTML(i.slice(c, h)));
1478
+ const u = l[0];
1479
+ /^\/\*/.test(u) || /^\/\//.test(u) ? g += n(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`) : g += n(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`), c = a.lastIndex;
1380
1480
  }
1381
- return c < s.length && (g += this.escapeHTML(s.slice(c))), g = g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, u, h) => {
1382
- const f = g[h - 1] || "", m = g[h + d.length] || "";
1383
- return f === "&" || f === "#" || m === ";" || m === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
1384
- }), g = g.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), g.replace(/\u0000([a-z]+)\u0000/g, (d, u) => {
1385
- let h = 0;
1481
+ return c < i.length && (g += this.escapeHTML(i.slice(c))), g = g.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (h, u, d) => {
1482
+ const f = g[d - 1] || "", m = g[d + h.length] || "";
1483
+ return f === "&" || f === "#" || m === ";" || m === "#" ? h : `<span style="color: ${t.number};">${h}</span>`;
1484
+ }), g = g.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), g.replace(/\u0000([a-z]+)\u0000/g, (h, u) => {
1485
+ let d = 0;
1386
1486
  for (let f = 0; f < u.length; f++)
1387
- h = h * 26 + (u.charCodeAt(f) - 97 + 1);
1388
- return h = h - 1, i[h] || "";
1487
+ d = d * 26 + (u.charCodeAt(f) - 97 + 1);
1488
+ return d = d - 1, s[d] || "";
1389
1489
  });
1390
1490
  }
1391
1491
  _highlightPHP(e, t) {
1392
- const s = this.unescapeEntitiesRepeated(e);
1393
- let i = this.escapeHTML(s);
1394
- const r = [], n = (h) => {
1395
- let f = "", m = h;
1492
+ const i = this.unescapeEntitiesRepeated(e);
1493
+ let s = this.escapeHTML(i);
1494
+ const r = [], o = (d) => {
1495
+ let f = "", m = d;
1396
1496
  do
1397
1497
  f = String.fromCharCode(97 + m % 26) + f, m = Math.floor(m / 26) - 1;
1398
1498
  while (m >= 0);
1399
1499
  return f || "a";
1400
- }, o = (h) => {
1500
+ }, n = (d) => {
1401
1501
  const f = r.length;
1402
- return r.push(h), `\0${n(f)}\0`;
1403
- }, a = (h, f) => {
1404
- const m = i.indexOf(h);
1405
- return m === -1 ? !1 : (i = i.slice(0, m) + f + i.slice(m + h.length), !0);
1502
+ return r.push(d), `\0${o(f)}\0`;
1503
+ }, l = (d, f) => {
1504
+ const m = s.indexOf(d);
1505
+ return m === -1 ? !1 : (s = s.slice(0, m) + f + s.slice(m + d.length), !0);
1406
1506
  };
1407
- let l;
1408
- const c = /\/\*[\s\S]*?\*\//g, g = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, u = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
1409
- for (; l = c.exec(s); ) {
1410
- const h = l[0];
1411
- a(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1507
+ let a;
1508
+ const c = /\/\*[\s\S]*?\*\//g, g = /\/\/[^\n\r]*/g, h = /\#([^\n\r]*)/g, u = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
1509
+ for (; a = c.exec(i); ) {
1510
+ const d = a[0];
1511
+ l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1412
1512
  }
1413
- for (; l = g.exec(s); ) {
1414
- const h = l[0];
1415
- a(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1513
+ for (; a = g.exec(i); ) {
1514
+ const d = a[0];
1515
+ l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1416
1516
  }
1417
- for (; l = d.exec(s); ) {
1418
- const h = l[0];
1419
- a(this.escapeHTML(h), o(`<span style="color: ${t.comment};">${this.escapeHTML(h)}</span>`));
1517
+ for (; a = h.exec(i); ) {
1518
+ const d = a[0];
1519
+ l(this.escapeHTML(d), n(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
1420
1520
  }
1421
- for (; l = u.exec(s); ) {
1422
- const h = l[0];
1423
- a(this.escapeHTML(h), o(`<span style="color: ${t.string};">${this.escapeHTML(h)}</span>`));
1521
+ for (; a = u.exec(i); ) {
1522
+ const d = a[0];
1523
+ l(this.escapeHTML(d), n(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`));
1424
1524
  }
1425
- return i = i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), i = i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), i = i.replace(/\u0000([a-z]+)\u0000/g, (h, f) => {
1525
+ return s = s.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), s = s.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), s = s.replace(/\u0000([a-z]+)\u0000/g, (d, f) => {
1426
1526
  let m = 0;
1427
- for (let x = 0; x < f.length; x++)
1428
- m = m * 26 + (f.charCodeAt(x) - 97 + 1);
1527
+ for (let y = 0; y < f.length; y++)
1528
+ m = m * 26 + (f.charCodeAt(y) - 97 + 1);
1429
1529
  return m = m - 1, r[m] || "";
1430
- }), i;
1530
+ }), s;
1431
1531
  }
1432
1532
  // Method to check if content contains syntax that should be highlighted
1433
1533
  shouldHighlight(e) {
@@ -1437,11 +1537,11 @@ class _ {
1437
1537
  this.editor = null, this.modes.clear();
1438
1538
  }
1439
1539
  }
1440
- function F(v, e) {
1540
+ function D(v, e) {
1441
1541
  const t = { ...e };
1442
- return t.extensions || (t.extensions = []), t.extensions.some((s) => s.name === "keymap") || t.extensions.unshift(new N(t.keymap)), t.extensions.some((s) => s.name === "transaction") || t.extensions.unshift(new B()), new I(v, t);
1542
+ return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new B(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new V()), new A(v, t);
1443
1543
  }
1444
- const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Editor Dialog Styles */
1544
+ const R = '[data-theme="dark"], .dark, .editora-theme-dark', j = `/* Source Editor Dialog Styles */
1445
1545
  .rte-source-editor-overlay {
1446
1546
  position: fixed !important;
1447
1547
  top: 0 !important;
@@ -1818,15 +1918,15 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
1818
1918
  flex: 1;
1819
1919
  text-align: center;
1820
1920
  }
1821
- }`, W = () => ({
1921
+ }`, Z = () => ({
1822
1922
  name: "code",
1823
1923
  // Toolbar button configuration
1824
1924
  toolbar: [
1825
1925
  {
1826
1926
  label: "Source",
1827
1927
  command: "toggleSourceView",
1828
- type: "button",
1829
- icon: "<>",
1928
+ // type: "button",
1929
+ 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>',
1830
1930
  shortcut: "Mod-Shift-S"
1831
1931
  }
1832
1932
  ],
@@ -1840,52 +1940,58 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
1840
1940
  const e = (() => {
1841
1941
  const r = window.getSelection();
1842
1942
  if (r && r.anchorNode) {
1843
- let o = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
1844
- for (; o; ) {
1845
- if (o.classList?.contains("rte-content"))
1846
- return o;
1847
- o = o.parentElement;
1943
+ let n = r.anchorNode instanceof HTMLElement ? r.anchorNode : r.anchorNode.parentElement;
1944
+ for (; n; ) {
1945
+ if (n.classList?.contains("rte-content"))
1946
+ return n;
1947
+ n = n.parentElement;
1848
1948
  }
1849
1949
  }
1850
1950
  if (document.activeElement) {
1851
- let o = document.activeElement;
1852
- if (o.classList?.contains("rte-content"))
1853
- return o;
1854
- for (; o && o !== document.body; ) {
1855
- if (o.classList?.contains("rte-content"))
1856
- return o;
1857
- const a = o.querySelector(".rte-content");
1858
- if (a) return a;
1859
- o = o.parentElement;
1951
+ let n = document.activeElement;
1952
+ if (n.classList?.contains("rte-content"))
1953
+ return n;
1954
+ for (; n && n !== document.body; ) {
1955
+ if (n.classList?.contains("rte-content"))
1956
+ return n;
1957
+ const l = n.querySelector(
1958
+ ".rte-content"
1959
+ );
1960
+ if (l) return l;
1961
+ n = n.parentElement;
1860
1962
  }
1861
1963
  }
1862
- const n = document.querySelector("[data-editora-editor]");
1863
- if (n) {
1864
- const o = n.querySelector(".rte-content");
1865
- if (o) return o;
1964
+ const o = document.querySelector("[data-editora-editor]");
1965
+ if (o) {
1966
+ const n = o.querySelector(
1967
+ ".rte-content"
1968
+ );
1969
+ if (n) return n;
1866
1970
  }
1867
1971
  return document.querySelector(".rte-content");
1868
1972
  })();
1869
1973
  if (!e)
1870
- return console.error("[CodePlugin] Editor content area not found"), alert("Editor content area not found. Please click inside the editor first."), !1;
1871
- const t = e.innerHTML, s = (r) => {
1872
- let n = "", o = 0;
1873
- const a = 2, l = r.split(/(<\/?[a-zA-Z][^>]*>)/);
1874
- for (const c of l)
1875
- c.trim() && (c.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), n += `
1876
- ` + " ".repeat(o * a) + c) : c.match(/^<[a-zA-Z]/) && !c.match(/\/>$/) ? (n += `
1877
- ` + " ".repeat(o * a) + c, o++) : c.match(/^<[a-zA-Z].*\/>$/) ? n += `
1878
- ` + " ".repeat(o * a) + c : n += c.trim());
1879
- return n.trim();
1974
+ return console.error("[CodePlugin] Editor content area not found"), alert(
1975
+ "Editor content area not found. Please click inside the editor first."
1976
+ ), !1;
1977
+ const t = e.innerHTML, i = (r) => {
1978
+ let o = "", n = 0;
1979
+ const l = 2, a = r.split(/(<\/?[a-zA-Z][^>]*>)/);
1980
+ for (const c of a)
1981
+ c.trim() && (c.match(/^<\/[a-zA-Z]/) ? (n = Math.max(0, n - 1), o += `
1982
+ ` + " ".repeat(n * l) + c) : c.match(/^<[a-zA-Z]/) && !c.match(/\/>$/) ? (o += `
1983
+ ` + " ".repeat(n * l) + c, n++) : c.match(/^<[a-zA-Z].*\/>$/) ? o += `
1984
+ ` + " ".repeat(n * l) + c : o += c.trim());
1985
+ return o.trim();
1880
1986
  };
1881
1987
  return (() => {
1882
- let r = null, n = "dark", o = !1, a = !1, l = !1;
1883
- const c = t, g = !!e.closest(O) || document.body.matches(O) || document.documentElement.matches(O), d = document.createElement("div");
1884
- d.className = "rte-source-editor-overlay", g && d.classList.add("rte-theme-dark");
1988
+ let r = null, o = "dark", n = !1, l = !1, a = !1;
1989
+ const c = t, g = !!e.closest(R) || document.body.matches(R) || document.documentElement.matches(R), h = document.createElement("div");
1990
+ h.className = "rte-source-editor-overlay", g && h.classList.add("rte-theme-dark");
1885
1991
  const u = document.createElement("div");
1886
1992
  u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
1887
- const h = document.createElement("div");
1888
- h.className = "rte-source-editor-header", h.innerHTML = `
1993
+ const d = document.createElement("div");
1994
+ d.className = "rte-source-editor-header", d.innerHTML = `
1889
1995
  <h2 id="source-editor-title">Source Editor</h2>
1890
1996
  <div class="rte-source-editor-header-toolbar">
1891
1997
  <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
@@ -1926,12 +2032,12 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
1926
2032
  f.className = "rte-source-editor-body";
1927
2033
  const m = document.createElement("div");
1928
2034
  m.className = "rte-source-editor-content";
1929
- const x = document.createElement("div");
1930
- x.className = "rte-source-editor-warning", x.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
1931
- const k = document.createElement("div");
1932
- k.className = "rte-source-editor-light-editor", k.style.height = "400px", m.appendChild(x), m.appendChild(k), f.appendChild(m);
1933
2035
  const y = document.createElement("div");
1934
- if (y.className = "rte-source-editor-footer", y.innerHTML = `
2036
+ y.className = "rte-source-editor-warning", y.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2037
+ const w = document.createElement("div");
2038
+ w.className = "rte-source-editor-light-editor", w.style.height = "400px", m.appendChild(y), m.appendChild(w), f.appendChild(m);
2039
+ const x = document.createElement("div");
2040
+ if (x.className = "rte-source-editor-footer", x.innerHTML = `
1935
2041
  <div class="rte-source-editor-footer-info">
1936
2042
  <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
1937
2043
  </div>
@@ -1939,45 +2045,47 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
1939
2045
  <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
1940
2046
  <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
1941
2047
  </div>
1942
- `, u.appendChild(h), u.appendChild(f), u.appendChild(y), d.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
2048
+ `, u.appendChild(d), u.appendChild(f), u.appendChild(x), h.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
1943
2049
  const p = document.createElement("style");
1944
- p.id = "rte-source-editor-styles", p.textContent = D, document.head.appendChild(p);
2050
+ p.id = "rte-source-editor-styles", p.textContent = j, document.head.appendChild(p);
1945
2051
  }
1946
- document.body.appendChild(d);
2052
+ document.body.appendChild(h);
1947
2053
  try {
1948
- r = F(k, {
1949
- value: s(t),
2054
+ r = D(w, {
2055
+ value: i(t),
1950
2056
  theme: "dark",
1951
2057
  readOnly: !1,
1952
2058
  extensions: [
1953
2059
  new K(),
1954
- new A(),
1955
- new V(),
1956
- new z(),
1957
2060
  new U(),
2061
+ new z(),
2062
+ new F(),
1958
2063
  new q(),
1959
- new _()
2064
+ new _(),
2065
+ new W()
1960
2066
  ]
1961
2067
  }), r.on("change", () => {
1962
- l = (r?.getValue() || "") !== s(c);
1963
- const M = y.querySelector(".unsaved-changes");
1964
- M && (M.style.display = l ? "inline" : "none");
2068
+ a = (r?.getValue() || "") !== i(c);
2069
+ const T = x.querySelector(
2070
+ ".unsaved-changes"
2071
+ );
2072
+ T && (T.style.display = a ? "inline" : "none");
1965
2073
  }), setTimeout(() => r?.focus(), 100);
1966
2074
  } catch (p) {
1967
2075
  console.error("Failed to initialize code editor:", p);
1968
2076
  }
1969
- const C = () => {
1970
- n = n === "dark" ? "light" : "dark", r?.setTheme(n);
1971
- const p = h.querySelector(".theme-toggle-btn");
1972
- p && n === "light" && (p.innerHTML = `
2077
+ const E = () => {
2078
+ o = o === "dark" ? "light" : "dark", r?.setTheme(o);
2079
+ const p = d.querySelector(".theme-toggle-btn");
2080
+ p && o === "light" && (p.innerHTML = `
1973
2081
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1974
2082
  <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
1975
2083
  </svg>
1976
2084
  `);
1977
2085
  }, L = () => {
1978
- o = !o, r?.setReadOnly(o);
1979
- const p = h.querySelector(".readonly-toggle-btn");
1980
- p && (o ? (p.classList.add("active"), p.innerHTML = `
2086
+ n = !n, r?.setReadOnly(n);
2087
+ const p = d.querySelector(".readonly-toggle-btn");
2088
+ p && (n ? (p.classList.add("active"), p.innerHTML = `
1981
2089
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1982
2090
  <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
1983
2091
  <circle cx="12" cy="16" r="1"/>
@@ -1989,10 +2097,12 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
1989
2097
  <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
1990
2098
  </svg>
1991
2099
  `));
1992
- }, w = () => {
1993
- a = !a, a ? (d.classList.add("fullscreen"), k.style.height = "calc(100vh - 200px)") : (d.classList.remove("fullscreen"), k.style.height = "400px");
1994
- const p = h.querySelector(".rte-source-editor-fullscreen-btn");
1995
- p && (p.innerHTML = a ? `
2100
+ }, C = () => {
2101
+ l = !l, l ? (h.classList.add("fullscreen"), w.style.height = "calc(100vh - 200px)") : (h.classList.remove("fullscreen"), w.style.height = "400px");
2102
+ const p = d.querySelector(
2103
+ ".rte-source-editor-fullscreen-btn"
2104
+ );
2105
+ p && (p.innerHTML = l ? `
1996
2106
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1997
2107
  <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"/>
1998
2108
  </svg>
@@ -2002,24 +2112,44 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
2002
2112
  </svg>
2003
2113
  `);
2004
2114
  }, b = () => {
2005
- r && (r.destroy(), r = null), document.body.removeChild(d);
2006
- }, T = () => {
2007
- l && !confirm("You have unsaved changes. Are you sure you want to cancel?") || b();
2115
+ r && (r.destroy(), r = null), document.body.removeChild(h);
2116
+ }, k = () => {
2117
+ a && !confirm(
2118
+ "You have unsaved changes. Are you sure you want to cancel?"
2119
+ ) || b();
2008
2120
  }, S = () => {
2009
2121
  try {
2010
- const p = r?.getValue() || "", M = document.createElement("div");
2011
- M.innerHTML = p, M.querySelectorAll('script, iframe[src^="javascript:"], object, embed').forEach((P) => P.remove()), e.innerHTML = M.innerHTML, l = !1, b();
2122
+ const p = r?.getValue() || "", T = document.createElement("div");
2123
+ T.innerHTML = p, T.querySelectorAll(
2124
+ 'script, iframe[src^="javascript:"], object, embed'
2125
+ ).forEach((I) => I.remove()), e.innerHTML = T.innerHTML;
2126
+ try {
2127
+ e.dispatchEvent(
2128
+ new InputEvent("input", {
2129
+ bubbles: !0,
2130
+ cancelable: !1,
2131
+ inputType: "insertReplacementText"
2132
+ })
2133
+ );
2134
+ } catch {
2135
+ e.dispatchEvent(
2136
+ new Event("input", { bubbles: !0 })
2137
+ );
2138
+ }
2139
+ e.dispatchEvent(
2140
+ new Event("change", { bubbles: !0 })
2141
+ ), a = !1, b();
2012
2142
  } catch (p) {
2013
2143
  alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", p);
2014
2144
  }
2015
2145
  };
2016
- h.querySelector(".theme-toggle-btn")?.addEventListener("click", C), h.querySelector(".readonly-toggle-btn")?.addEventListener("click", L), h.querySelector(".rte-source-editor-fullscreen-btn")?.addEventListener("click", w), h.querySelector(".rte-source-editor-close-btn")?.addEventListener("click", b), y.querySelector(".rte-source-editor-btn-cancel")?.addEventListener("click", T), y.querySelector(".rte-source-editor-btn-save")?.addEventListener("click", S), d.addEventListener("click", (p) => {
2017
- p.target === d && b();
2146
+ d.querySelector(".theme-toggle-btn")?.addEventListener("click", E), d.querySelector(".readonly-toggle-btn")?.addEventListener("click", L), d.querySelector(".rte-source-editor-fullscreen-btn")?.addEventListener("click", C), d.querySelector(".rte-source-editor-close-btn")?.addEventListener("click", b), x.querySelector(".rte-source-editor-btn-cancel")?.addEventListener("click", k), x.querySelector(".rte-source-editor-btn-save")?.addEventListener("click", S), h.addEventListener("click", (p) => {
2147
+ p.target === h && b();
2018
2148
  });
2019
- const E = (p) => {
2020
- p.key === "Escape" && (b(), document.removeEventListener("keydown", E));
2149
+ const O = (p) => {
2150
+ p.key === "Escape" && (b(), document.removeEventListener("keydown", O));
2021
2151
  };
2022
- document.addEventListener("keydown", E);
2152
+ document.addEventListener("keydown", O);
2023
2153
  })(), !0;
2024
2154
  }
2025
2155
  },
@@ -2030,5 +2160,5 @@ const O = '[data-theme="dark"], .dark, .editora-theme-dark', D = `/* Source Edit
2030
2160
  }
2031
2161
  });
2032
2162
  export {
2033
- W as CodePlugin
2163
+ Z as CodePlugin
2034
2164
  };