@editora/core 1.0.6 → 1.0.7

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 (43) hide show
  1. package/dist/{AnchorPlugin.native-C1Rw5m04.mjs → AnchorPlugin.native-BcYGEtd9.mjs} +129 -105
  2. package/dist/{BackgroundColorPlugin.native-BE-p9DRd.mjs → BackgroundColorPlugin.native-50iAT9xU.mjs} +119 -122
  3. package/dist/CodePlugin.native-DlpTPdkd.mjs +2691 -0
  4. package/dist/{CommentsPlugin.native-tMnWn8a2.mjs → CommentsPlugin.native-DPSqTkiv.mjs} +153 -135
  5. package/dist/{DocumentManagerPlugin.native-BvZL5CSG.mjs → DocumentManagerPlugin.native-C2cs_1w4.mjs} +43 -43
  6. package/dist/{EmbedIframePlugin.native-CSWIB1jm.mjs → EmbedIframePlugin.native-DKJx2OS7.mjs} +61 -58
  7. package/dist/{EmojisPlugin.native-DxTm_DL-.mjs → EmojisPlugin.native-CitxxlWX.mjs} +135 -104
  8. package/dist/{LinkPlugin.native-CS2g-G18.mjs → LinkPlugin.native-DYCIcdTm.mjs} +47 -45
  9. package/dist/{MathPlugin.native-KUxz0o8C.mjs → MathPlugin.native-f_mDp8VL.mjs} +149 -108
  10. package/dist/{MediaManagerPlugin.native-CgP5iInD.mjs → MediaManagerPlugin.native-BiXiK8FC.mjs} +238 -217
  11. package/dist/MergeTagPlugin.native-C3eOfEgw.mjs +559 -0
  12. package/dist/{PageBreakPlugin.native-CGiQxXqR.mjs → PageBreakPlugin.native-CXdX5fAv.mjs} +77 -68
  13. package/dist/{SpecialCharactersPlugin.native-DANrbExJ.mjs → SpecialCharactersPlugin.native-CZDato89.mjs} +143 -98
  14. package/dist/{SpellCheckPlugin.native-C8bPvRHy.mjs → SpellCheckPlugin.native-BZB9AewP.mjs} +239 -219
  15. package/dist/{TemplatePlugin.native-4lKEm-WY.mjs → TemplatePlugin.native-CrpfKRJ8.mjs} +167 -143
  16. package/dist/{TextColorPlugin.native-Clgtb50j.mjs → TextColorPlugin.native-Bwl_bSmc.mjs} +134 -118
  17. package/dist/_commonjsHelpers-DOllISpa.mjs +32 -0
  18. package/dist/anchoredPopover-Bxds0VoB.mjs +110 -0
  19. package/dist/documentManager-vQ1VkbUY.mjs +8418 -0
  20. package/dist/editora.min.js +10 -10
  21. package/dist/editora.umd.js +10 -10
  22. package/dist/html2canvas.esm-AYkPY5LS.mjs +4803 -0
  23. package/dist/{index-CqWQFb3D.js → index-BpE6GFbz.js} +4 -4
  24. package/dist/index-BslAFzmv.mjs +16544 -0
  25. package/dist/{index-OwnkG39N.mjs → index-yzU4NdPT.mjs} +200 -183
  26. package/dist/index.cjs.js +1 -1
  27. package/dist/{index.es-CuicffkQ.mjs → index.es-BYD2KEo6.mjs} +5 -4
  28. package/dist/index.esm.js +2 -2
  29. package/dist/jspdf.es.min-BJGtOnRT.mjs +7890 -0
  30. package/dist/plugin-loader.js +15 -15
  31. package/dist/webcomponent-core.js +241 -224
  32. package/dist/webcomponent-core.min.css +1 -1
  33. package/dist/webcomponent-core.min.js +86 -106
  34. package/dist/webcomponent.cjs.js +1 -1
  35. package/dist/webcomponent.esm.js +1 -1
  36. package/dist/webcomponent.js +205 -188
  37. package/dist/webcomponent.min.css +1 -1
  38. package/dist/webcomponent.min.js +477 -402
  39. package/package.json +1 -1
  40. package/dist/CodePlugin.native-B263UI8O.mjs +0 -2173
  41. package/dist/MergeTagPlugin.native-DIGWhdnF.mjs +0 -419
  42. package/dist/colorSelectionApply-CK1My9N2.mjs +0 -67
  43. package/dist/documentManager-irzj9n3V.mjs +0 -37627
@@ -0,0 +1,2691 @@
1
+ class D {
2
+ constructor(e = "") {
3
+ this._lines = [], this._version = 0, this.setText(e);
4
+ }
5
+ // Get line at index
6
+ getLine(e) {
7
+ return this._lines[e] || "";
8
+ }
9
+ // Get all lines
10
+ getLines() {
11
+ return [...this._lines];
12
+ }
13
+ // Get total number of lines
14
+ getLineCount() {
15
+ return this._lines.length;
16
+ }
17
+ // Get total text content
18
+ getText() {
19
+ return this._lines.join(`
20
+ `);
21
+ }
22
+ // Set entire text content
23
+ setText(e) {
24
+ this._lines = e.split(`
25
+ `), this._version++;
26
+ }
27
+ // Get text in a range
28
+ getTextInRange(e) {
29
+ if (e.start.line === e.end.line)
30
+ return this.getLine(e.start.line).substring(e.start.column, e.end.column);
31
+ const t = [];
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));
35
+ return e.end.line < this.getLineCount() && t.push(this.getLine(e.end.line).substring(0, e.end.column)), t.join(`
36
+ `);
37
+ }
38
+ // Replace text in range
39
+ replaceRange(e, t) {
40
+ const s = this.getTextInRange(e);
41
+ if (e.start.line === e.end.line) {
42
+ const i = this.getLine(e.start.line), n = i.substring(0, e.start.column) + t + i.substring(e.end.column);
43
+ this._lines[e.start.line] = n;
44
+ } else {
45
+ const i = this.getLine(e.start.line), n = this.getLine(e.end.line), r = i.substring(0, e.start.column) + t, l = n.substring(e.end.column), a = t.split(`
46
+ `);
47
+ a[0] = r + a[0], a[a.length - 1] = a[a.length - 1] + l, this._lines.splice(e.start.line, e.end.line - e.start.line + 1, ...a);
48
+ }
49
+ return this._version++, { range: e, text: t, oldText: s };
50
+ }
51
+ // Insert text at position
52
+ insertText(e, t) {
53
+ const s = { start: e, end: e };
54
+ return this.replaceRange(s, t);
55
+ }
56
+ // Delete text in range
57
+ deleteRange(e) {
58
+ return this.replaceRange(e, "");
59
+ }
60
+ // Convert position to offset
61
+ positionToOffset(e) {
62
+ let t = 0;
63
+ for (let s = 0; s < e.line; s++)
64
+ t += this.getLine(s).length + 1;
65
+ return t += e.column, t;
66
+ }
67
+ // Convert offset to position
68
+ offsetToPosition(e) {
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;
75
+ }
76
+ return {
77
+ line: this.getLineCount() - 1,
78
+ column: this.getLine(this.getLineCount() - 1).length
79
+ };
80
+ }
81
+ // Validate position
82
+ isValidPosition(e) {
83
+ return !(e.line < 0 || e.line >= this.getLineCount() || e.column < 0 || e.column > this.getLine(e.line).length);
84
+ }
85
+ // Validate range
86
+ isValidRange(e) {
87
+ return this.isValidPosition(e.start) && this.isValidPosition(e.end);
88
+ }
89
+ // Get version for change tracking
90
+ getVersion() {
91
+ return this._version;
92
+ }
93
+ // Clone the model
94
+ clone() {
95
+ const e = new D();
96
+ return e._lines = [...this._lines], e._version = this._version, e;
97
+ }
98
+ }
99
+ class Z {
100
+ constructor(e) {
101
+ this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.virtualMarkerRegex = /[\u200B\uE000]/, this.container = e, this.createDOM();
102
+ }
103
+ createDOM() {
104
+ this.container.innerHTML = "";
105
+ const e = document.createElement("div");
106
+ this.editorContainer = e, e.setAttribute("data-lce-editor-container", "true"), e.style.cssText = `
107
+ position: relative;
108
+ display: flex;
109
+ width: 100%;
110
+ height: 100%;
111
+ background: var(--editor-background, #1e1e1e);
112
+ color: var(--editor-foreground, #f8f9fa);
113
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
114
+ font-size: 14px;
115
+ line-height: ${this.lineHeight}px;
116
+ /* make the outer container the single scrollable element so gutter and content scroll together */
117
+ overflow: auto;
118
+ `, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.setAttribute("data-editor-gutter", "true"), this.lineNumbersElement.style.cssText = `
119
+ display: table-cell;
120
+ vertical-align: top;
121
+ width: ${this.gutterWidth}px;
122
+ background: var(--editor-gutter-background, #252526);
123
+ color: var(--editor-gutter-foreground, #858585);
124
+ padding: 0 8px 0 0;
125
+ text-align: right;
126
+ border-right: 1px solid var(--editor-gutter-border, #3e3e42);
127
+ user-select: none;
128
+ z-index: 1;
129
+ `, this.contentElement = document.createElement("div"), this.contentElement.style.cssText = `
130
+ display: table-cell;
131
+ vertical-align: top;
132
+ padding: 0 12px;
133
+ background: transparent;
134
+ border: none;
135
+ outline: none;
136
+ white-space: pre;
137
+ overflow-x: auto;
138
+ overflow-y: visible;
139
+ min-height: 400px;
140
+ font-family: inherit;
141
+ font-size: inherit;
142
+ line-height: inherit;
143
+ color: inherit;
144
+ tab-size: 2;
145
+ -moz-tab-size: 2;
146
+ `, this.contentElement.contentEditable = "true", this.contentElement.spellcheck = !1;
147
+ const t = document.createElement("div");
148
+ t.setAttribute("data-editora-editor", "true"), t.style.cssText = "display: table; table-layout: fixed; width: 100%; height: 100%;", t.appendChild(this.lineNumbersElement), t.appendChild(this.contentElement), e.appendChild(t), this.container.appendChild(e), this.updateLineNumbers(1);
149
+ }
150
+ // Update line numbers
151
+ updateLineNumbers(e) {
152
+ const t = Math.max(e, 20), s = Array.from({ length: t }, (i, n) => n + 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("");
154
+ }
155
+ // Get content element
156
+ getContentElement() {
157
+ return this.contentElement;
158
+ }
159
+ // Get line numbers element
160
+ getLineNumbersElement() {
161
+ return this.lineNumbersElement;
162
+ }
163
+ // Get text content
164
+ getText() {
165
+ const e = this.contentElement.textContent || "";
166
+ return this.contentElement.querySelector(`[${this.trailingNewlineMarkerAttr}]`) && e.endsWith("​") ? e.slice(0, -1) : e;
167
+ }
168
+ // Set text content
169
+ setText(e) {
170
+ this.contentElement.textContent = e, this.syncTrailingNewlineMarker(e.endsWith(`
171
+ `));
172
+ const t = e.split(`
173
+ `).length;
174
+ this.updateLineNumbers(t);
175
+ }
176
+ // Set inner HTML (used for syntax highlighted content)
177
+ setHTML(e) {
178
+ const t = /\n$/.test(e), s = /&lt;|&gt;/.test(e), i = /<span\b/i.test(e), n = /<[^>]+>/.test(e);
179
+ s && i ? this.contentElement.innerHTML = e : n && !s ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
180
+ const r = (this.contentElement.textContent || "").split(`
181
+ `).length;
182
+ this.updateLineNumbers(r);
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
+ `));
189
+ }
190
+ // Get cursor position from DOM selection
191
+ getCursorPosition() {
192
+ const e = window.getSelection();
193
+ if (!e || e.rangeCount === 0)
194
+ return { line: 0, column: 0 };
195
+ const t = e.getRangeAt(0), s = t.cloneRange();
196
+ s.selectNodeContents(this.contentElement), s.setEnd(t.endContainer, t.endOffset);
197
+ const i = s.toString().replace(/\u200B/g, "").split(`
198
+ `);
199
+ return {
200
+ line: i.length - 1,
201
+ column: i[i.length - 1].length
202
+ };
203
+ }
204
+ // Set cursor position
205
+ setCursorPosition(e) {
206
+ var h;
207
+ const t = this.getText().split(`
208
+ `), s = Math.min(e.line, t.length - 1), i = Math.min(e.column, ((h = t[s]) == null ? void 0 : h.length) || 0);
209
+ let n = 0;
210
+ for (let o = 0; o < s; o++)
211
+ n += t[o].length + 1;
212
+ n += i;
213
+ const r = document.createRange(), l = window.getSelection(), a = this.resolveOffsetToDomPoint(n);
214
+ if (a)
215
+ try {
216
+ r.setStart(a.node, a.offset), r.setEnd(a.node, a.offset), l == null || l.removeAllRanges(), l == null || l.addRange(r), this.ensureCaretVisible();
217
+ } catch (o) {
218
+ console.warn("Could not set cursor position:", o);
219
+ }
220
+ else {
221
+ const o = this.contentElement.querySelector(
222
+ `[${this.trailingNewlineMarkerAttr}]`
223
+ );
224
+ try {
225
+ o && o.parentNode === this.contentElement ? r.setStartBefore(o) : (r.selectNodeContents(this.contentElement), r.collapse(!1)), r.collapse(!0), l == null || l.removeAllRanges(), l == null || l.addRange(r), this.ensureCaretVisible();
226
+ } catch (c) {
227
+ console.warn("Could not set fallback cursor position:", c);
228
+ }
229
+ }
230
+ }
231
+ // Get selection range
232
+ getSelectionRange() {
233
+ const e = window.getSelection();
234
+ if (!e || e.rangeCount === 0 || e.isCollapsed)
235
+ return;
236
+ const t = e.getRangeAt(0), s = t.cloneRange();
237
+ s.selectNodeContents(this.contentElement), s.setEnd(t.startContainer, t.startOffset);
238
+ const i = s.toString().replace(/\u200B/g, "").split(`
239
+ `), n = t.cloneRange();
240
+ n.selectNodeContents(this.contentElement), n.setEnd(t.endContainer, t.endOffset);
241
+ const r = n.toString().replace(/\u200B/g, "").split(`
242
+ `);
243
+ return {
244
+ start: {
245
+ line: i.length - 1,
246
+ column: i[i.length - 1].length
247
+ },
248
+ end: {
249
+ line: r.length - 1,
250
+ column: r[r.length - 1].length
251
+ }
252
+ };
253
+ }
254
+ // Set selection range
255
+ setSelectionRange(e) {
256
+ const t = this.getText().split(`
257
+ `), s = (c) => {
258
+ const d = Math.max(0, Math.min(c.line, t.length - 1)), f = Math.max(
259
+ 0,
260
+ Math.min(c.column, t[d] ? t[d].length : 0)
261
+ );
262
+ let u = 0;
263
+ for (let g = 0; g < d; g++)
264
+ u += t[g].length + 1;
265
+ return u + f;
266
+ }, i = s(e.start), n = s(e.end), [r, l] = i <= n ? [i, n] : [n, i], a = this.resolveOffsetToDomPoint(r), h = this.resolveOffsetToDomPoint(l);
267
+ if (!a || !h) return;
268
+ const o = document.createRange();
269
+ try {
270
+ o.setStart(a.node, a.offset), o.setEnd(h.node, h.offset);
271
+ const c = window.getSelection();
272
+ c == null || c.removeAllRanges(), c == null || c.addRange(o), this.ensureCaretVisible();
273
+ } catch (c) {
274
+ console.warn("Could not set selection range:", c);
275
+ }
276
+ }
277
+ // Focus the editor
278
+ focus() {
279
+ this.contentElement.focus(), this.ensureCaretVisible();
280
+ }
281
+ // Blur the editor
282
+ blur() {
283
+ this.contentElement.blur();
284
+ }
285
+ // Set read-only mode
286
+ setReadOnly(e) {
287
+ this.contentElement.contentEditable = e ? "false" : "true";
288
+ }
289
+ // Apply theme
290
+ applyTheme(e) {
291
+ Object.entries(e).forEach(([t, s]) => {
292
+ this.container.style.setProperty(`--${t}`, s);
293
+ });
294
+ }
295
+ // Scroll to position
296
+ scrollToPosition(e) {
297
+ const t = this.lineNumbersElement.children[e.line];
298
+ t && t.scrollIntoView({ block: "center", behavior: "smooth" });
299
+ }
300
+ // Get scroll position
301
+ getScrollTop() {
302
+ return this.editorContainer.scrollTop;
303
+ }
304
+ // Get primary scroll element
305
+ getScrollElement() {
306
+ return this.editorContainer;
307
+ }
308
+ // Set scroll position
309
+ setScrollTop(e) {
310
+ this.editorContainer.scrollTop = e;
311
+ }
312
+ syncTrailingNewlineMarker(e) {
313
+ if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((s) => s.remove()), !e) return;
314
+ const t = document.createElement("span");
315
+ t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
316
+ display: inline-block;
317
+ width: 0;
318
+ overflow: hidden;
319
+ pointer-events: none;
320
+ user-select: none;
321
+ `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
322
+ }
323
+ // Ensure caret is visible inside the editor scroll container
324
+ ensureCaretVisible() {
325
+ var r;
326
+ const e = window.getSelection();
327
+ if (!e || e.rangeCount === 0) return;
328
+ const t = e.getRangeAt(0).cloneRange();
329
+ t.collapse(!1);
330
+ let s = t.getClientRects()[0] || t.getBoundingClientRect();
331
+ if ((!s || s.width === 0 && s.height === 0) && e.focusNode instanceof Element ? s = e.focusNode.getBoundingClientRect() : (!s || s.width === 0 && s.height === 0) && ((r = e.focusNode) != null && r.parentElement) && (s = e.focusNode.parentElement.getBoundingClientRect()), !s) return;
332
+ const i = this.editorContainer.getBoundingClientRect(), n = 12;
333
+ s.bottom > i.bottom - n ? this.editorContainer.scrollTop += s.bottom - (i.bottom - n) : s.top < i.top + n && (this.editorContainer.scrollTop -= i.top + n - s.top);
334
+ }
335
+ // Destroy the view
336
+ destroy() {
337
+ this.container && this.container.parentNode && this.container.parentNode.removeChild(this.container), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
338
+ }
339
+ resolveOffsetToDomPoint(e) {
340
+ var l, a, h;
341
+ const t = Math.max(0, e);
342
+ let s = 0;
343
+ const i = document.createTreeWalker(
344
+ this.contentElement,
345
+ NodeFilter.SHOW_TEXT,
346
+ null
347
+ );
348
+ let n = null, r;
349
+ for (; r = i.nextNode(); ) {
350
+ if ((l = r.parentElement) != null && l.hasAttribute(this.trailingNewlineMarkerAttr))
351
+ continue;
352
+ n = r;
353
+ const o = r.textContent || "", c = this.buildVisibleToDomMap(o), d = Math.max(0, c.length - 1);
354
+ if (s + d >= t) {
355
+ const f = Math.max(0, t - s), u = (a = c[f]) != null ? a : o.length;
356
+ return {
357
+ node: r,
358
+ offset: u
359
+ };
360
+ }
361
+ s += d;
362
+ }
363
+ if (n) {
364
+ const o = ((h = n.textContent) == null ? void 0 : h.length) || 0;
365
+ return { node: n, offset: o };
366
+ }
367
+ return null;
368
+ }
369
+ buildVisibleToDomMap(e) {
370
+ const t = [0];
371
+ let s = 0;
372
+ for (let i = 0; i < e.length; i++) {
373
+ const n = e[i];
374
+ this.virtualMarkerRegex.test(n) || (s += 1, t[s] = i + 1);
375
+ }
376
+ return t;
377
+ }
378
+ }
379
+ const F = class L {
380
+ constructor(e, t = {}) {
381
+ 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 = {
382
+ value: "",
383
+ theme: "default",
384
+ readOnly: !1,
385
+ tabSize: 2,
386
+ lineWrapping: !1,
387
+ lineNumbers: !0,
388
+ ...t
389
+ }, this.textModel = new D(this.config.value), this.view = new Z(e), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((s) => this.addExtension(s)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
390
+ }
391
+ // Public accessors for extensions
392
+ getTextModel() {
393
+ return this.textModel;
394
+ }
395
+ getView() {
396
+ return this.view;
397
+ }
398
+ getConfig() {
399
+ return { ...this.config };
400
+ }
401
+ // Register built-in editor commands like undo/redo/insertTab
402
+ registerBuiltInCommands() {
403
+ this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("save", () => {
404
+ this.emit("save");
405
+ });
406
+ }
407
+ // Get keymap extension if available
408
+ getKeymapExtension() {
409
+ return this.extensions.get("keymap");
410
+ }
411
+ // Setup DOM event handlers
412
+ setupEventHandlers() {
413
+ const e = this.view.getContentElement();
414
+ e.addEventListener("input", () => {
415
+ const t = this.view.getText(), s = this.textModel.getText();
416
+ if (t !== s) {
417
+ if (!this.suppressHistory) {
418
+ const i = this.getCursor().position, n = this.textModel.positionToOffset(i), r = this.getSelection();
419
+ let l, a;
420
+ r && (l = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: s, cursorOffset: n, anchorOffset: l, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
421
+ }
422
+ this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
423
+ const i = this.view.getText();
424
+ i !== this.textModel.getText() && this.textModel.setText(i), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
425
+ }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: s }]);
426
+ }
427
+ }), e.addEventListener("selectionchange", () => {
428
+ const t = this.getCursor(), s = this.getSelection();
429
+ this.emit("cursor", t), s && this.emit("selection", s);
430
+ }), e.addEventListener("keydown", (t) => {
431
+ if (this.emit("keydown", t), t.key === "Tab") {
432
+ this.config.readOnly || this.insertTab(), t.preventDefault(), t.stopPropagation();
433
+ return;
434
+ }
435
+ if (t.key === "Enter") {
436
+ if (!this.config.readOnly) {
437
+ const s = window.getSelection();
438
+ if (s && s.rangeCount > 0) {
439
+ const i = this.getCursor().position, n = this.textModel.positionToOffset(i), r = this.getSelection();
440
+ let l, a;
441
+ r && (l = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end));
442
+ const h = r && l !== void 0 && a !== void 0 ? Math.min(l, a) : n;
443
+ this.suppressHistory || (this.undoStack.push({ text: this.textModel.getText(), cursorOffset: n, anchorOffset: l, focusOffset: a }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0);
444
+ const o = s.getRangeAt(0);
445
+ o.deleteContents();
446
+ const c = document.createTextNode(`
447
+ `);
448
+ o.insertNode(c), o.setStartAfter(c), o.collapse(!0), s.removeAllRanges(), s.addRange(o), this.view.ensureCaretVisible();
449
+ const d = this.view.getText();
450
+ this.textModel.setText(d), this.view.syncTrailingNewlineMarkerForText(d);
451
+ const f = Math.min(
452
+ h + 1,
453
+ this.textModel.getText().length
454
+ );
455
+ try {
456
+ const u = this.textModel.offsetToPosition(f);
457
+ this.setCursor(u), this.view.ensureCaretVisible();
458
+ } catch (u) {
459
+ }
460
+ this.highlightTimeout && clearTimeout(this.highlightTimeout), this.highlightTimeout = setTimeout(() => {
461
+ this.renderTextWithHighlight(this.textModel.getText(), !1), requestAnimationFrame(() => {
462
+ try {
463
+ const u = this.textModel.offsetToPosition(f);
464
+ this.setCursor(u), this.view.ensureCaretVisible();
465
+ } catch (u) {
466
+ }
467
+ }), this.highlightTimeout = null;
468
+ }, 300), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: this.getValue(), oldText: "" }]);
469
+ }
470
+ }
471
+ t.preventDefault(), t.stopPropagation();
472
+ return;
473
+ }
474
+ for (const s of this.extensions.values())
475
+ if (s.onKeyDown && s.onKeyDown(t) === !1) {
476
+ t.preventDefault(), t.stopPropagation();
477
+ return;
478
+ }
479
+ }), e.addEventListener("mousedown", (t) => {
480
+ this.emit("mousedown", t);
481
+ for (const s of this.extensions.values())
482
+ if (s.onMouseDown && s.onMouseDown(t) === !1) {
483
+ t.preventDefault(), t.stopPropagation();
484
+ return;
485
+ }
486
+ }), e.addEventListener("focus", () => {
487
+ this.emit("focus");
488
+ }), e.addEventListener("blur", () => {
489
+ this.emit("blur");
490
+ });
491
+ }
492
+ // Update line numbers display
493
+ updateLineNumbers() {
494
+ const e = this.textModel.getLineCount();
495
+ this.view.updateLineNumbers(e);
496
+ }
497
+ // Get full range of document
498
+ getFullRange() {
499
+ return {
500
+ start: { line: 0, column: 0 },
501
+ end: {
502
+ line: this.textModel.getLineCount() - 1,
503
+ column: this.textModel.getLine(this.textModel.getLineCount() - 1).length
504
+ }
505
+ };
506
+ }
507
+ // Emit events to listeners
508
+ emit(e, ...t) {
509
+ const s = this.eventListeners.get(e);
510
+ s && s.forEach((i) => i(...t));
511
+ }
512
+ // State management
513
+ getValue() {
514
+ return this.textModel.getText();
515
+ }
516
+ setValue(e) {
517
+ const t = this.textModel.getText();
518
+ this.textModel.setText(e), this.renderTextWithHighlight(e, !1), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: t }]);
519
+ }
520
+ getState() {
521
+ return {
522
+ text: this.getValue(),
523
+ cursor: this.getCursor(),
524
+ selection: this.getSelection(),
525
+ readOnly: this.config.readOnly || !1,
526
+ theme: this.currentTheme
527
+ };
528
+ }
529
+ // Cursor & Selection
530
+ getCursor() {
531
+ const e = this.view.getCursorPosition();
532
+ return {
533
+ position: e,
534
+ anchor: e
535
+ // For now, cursor and anchor are the same
536
+ };
537
+ }
538
+ setCursor(e) {
539
+ this.view.setCursorPosition(e), this.emit("cursor", this.getCursor());
540
+ }
541
+ getSelection() {
542
+ return this.view.getSelectionRange();
543
+ }
544
+ setSelection(e) {
545
+ this.view.setSelectionRange(e), this.emit("selection", e);
546
+ }
547
+ // Configuration
548
+ setTheme(e) {
549
+ this.currentTheme = e;
550
+ const t = {
551
+ "editor-background": e === "dark" ? "#1e1e1e" : "#ffffff",
552
+ "editor-foreground": e === "dark" ? "#f8f9fa" : "#1a1a1a",
553
+ "editor-gutter-background": e === "dark" ? "#252526" : "#f8f9fa",
554
+ "editor-gutter-foreground": e === "dark" ? "#858585" : "#666666",
555
+ "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
556
+ };
557
+ this.view.applyTheme(t);
558
+ const s = this.extensions.get("syntax-highlighting");
559
+ if (s && typeof s.setTheme == "function")
560
+ try {
561
+ s.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
562
+ } catch (i) {
563
+ console.warn("Error applying theme to syntax-highlighting extension", i);
564
+ }
565
+ }
566
+ setReadOnly(e) {
567
+ this.config.readOnly = e, this.view.setReadOnly(e);
568
+ }
569
+ // Extensions & Commands
570
+ addExtension(e) {
571
+ if (this.extensions.has(e.name))
572
+ throw new Error(`Extension '${e.name}' already exists`);
573
+ this.extensions.set(e.name, e), e.setup(this), e.name === "syntax-highlighting" && typeof e.highlightHTML == "function" && this.renderTextWithHighlight(this.textModel.getText());
574
+ }
575
+ removeExtension(e) {
576
+ const t = this.extensions.get(e);
577
+ t && t.destroy && t.destroy(), this.extensions.delete(e);
578
+ }
579
+ executeCommand(e, ...t) {
580
+ const s = this.commands.get(e);
581
+ s ? s(this, ...t) : console.warn(`Command '${e}' not found`);
582
+ }
583
+ // Register a command
584
+ registerCommand(e, t) {
585
+ this.commands.set(e, t);
586
+ }
587
+ // Search & Navigation
588
+ search(e, t = {}) {
589
+ var o;
590
+ if (!e) return [];
591
+ const s = {
592
+ query: e,
593
+ caseSensitive: !1,
594
+ wholeWord: !1,
595
+ regex: !1,
596
+ ...t
597
+ }, i = [], n = this.textModel.getText(), { normalizedText: r, normalizedToRawOffsets: l } = this.buildSearchTextAndOffsetMap(n), a = s.caseSensitive ? r : r.toLowerCase(), h = s.caseSensitive ? e : e.toLowerCase();
598
+ if (s.regex) {
599
+ let c;
600
+ try {
601
+ c = new RegExp(e, s.caseSensitive ? "g" : "gi");
602
+ } catch (f) {
603
+ return [];
604
+ }
605
+ let d;
606
+ for (; (d = c.exec(r)) !== null; ) {
607
+ const f = (o = d[0]) != null ? o : "";
608
+ if (f.length === 0) {
609
+ c.lastIndex = d.index + 1;
610
+ continue;
611
+ }
612
+ const u = d.index, g = d.index + f.length;
613
+ s.wholeWord && !this.isWholeWordBoundary(r, u, g) || this.pushSearchResultFromOffsets(
614
+ i,
615
+ u,
616
+ g,
617
+ r,
618
+ l
619
+ );
620
+ }
621
+ } else {
622
+ let c = 0, d = a.indexOf(h, c);
623
+ for (; d !== -1; ) {
624
+ const f = d + h.length;
625
+ !s.wholeWord || this.isWholeWordBoundary(r, d, f) ? (this.pushSearchResultFromOffsets(
626
+ i,
627
+ d,
628
+ f,
629
+ r,
630
+ l
631
+ ), c = f) : c = d + 1, d = a.indexOf(h, c);
632
+ }
633
+ }
634
+ return i;
635
+ }
636
+ pushSearchResultFromOffsets(e, t, s, i, n) {
637
+ var o, c;
638
+ const r = (o = n[t]) != null ? o : t, l = (c = n[s]) != null ? c : r, a = this.textModel.offsetToPosition(r), h = this.textModel.offsetToPosition(l);
639
+ e.push({
640
+ range: { start: a, end: h },
641
+ match: i.substring(t, s)
642
+ });
643
+ }
644
+ isWholeWordBoundary(e, t, s) {
645
+ const i = t > 0 ? e[t - 1] : "", n = s < e.length ? e[s] : "";
646
+ return !this.isWordChar(i) && !this.isWordChar(n);
647
+ }
648
+ isWordChar(e) {
649
+ return /^[A-Za-z0-9_]$/.test(e);
650
+ }
651
+ buildSearchTextAndOffsetMap(e) {
652
+ const t = [], s = [0];
653
+ let i = 0;
654
+ for (let n = 0; n < e.length; n++) {
655
+ const r = e[n];
656
+ r === "​" || r === L.CURSOR_SENTINEL || (t.push(r), i += 1, s[i] = n + 1);
657
+ }
658
+ return s[i] = e.length, {
659
+ normalizedText: t.join(""),
660
+ normalizedToRawOffsets: s
661
+ };
662
+ }
663
+ replace(e, t) {
664
+ const s = this.getValue();
665
+ if (!this.suppressHistory) {
666
+ const n = this.getCursor().position, r = this.textModel.positionToOffset(n), l = this.getSelection();
667
+ let a, h;
668
+ l && (a = this.textModel.positionToOffset(l.start), h = this.textModel.positionToOffset(l.end)), this.undoStack.push({ text: s, cursorOffset: r, anchorOffset: a, focusOffset: h }), this.undoStack.length > 100 && this.undoStack.shift(), this.redoStack.length = 0;
669
+ }
670
+ const i = this.textModel.replaceRange(e, t);
671
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [i]);
672
+ }
673
+ replaceAll(e, t, s = {}) {
674
+ const i = this.search(e, s);
675
+ let n = 0;
676
+ for (let r = i.length - 1; r >= 0; r--)
677
+ this.replace(i[r].range, t), n++;
678
+ return n;
679
+ }
680
+ // Folding (basic implementation)
681
+ fold(e) {
682
+ const t = {
683
+ start: e.start,
684
+ end: e.end,
685
+ collapsed: !0,
686
+ level: 0
687
+ };
688
+ this.folds.push(t);
689
+ }
690
+ unfold(e) {
691
+ this.folds = this.folds.filter(
692
+ (t) => !(t.start.line === e.start.line && t.end.line === e.end.line)
693
+ );
694
+ }
695
+ getFolds() {
696
+ return [...this.folds];
697
+ }
698
+ // Utilities
699
+ focus() {
700
+ this.view.focus();
701
+ }
702
+ blur() {
703
+ this.view.blur();
704
+ }
705
+ // Render text using syntax highlighting extension if available
706
+ // If `restoreSelection` is true (default), the method captures current selection/caret
707
+ // and restores it after updating the DOM. Callers that will explicitly set the caret
708
+ // should pass `false` to avoid stomping programmatic cursor changes.
709
+ renderTextWithHighlight(e, t = !0) {
710
+ const s = this.extensions.get("syntax-highlighting");
711
+ if (s && typeof s.highlightHTML == "function")
712
+ try {
713
+ const i = !t && !this.expectingProgrammaticCursor;
714
+ let n, r, l, a;
715
+ if (t || i) {
716
+ n = this.getSelection();
717
+ const d = this.getCollapsedSelectionOffsetInEditor();
718
+ if (d !== void 0)
719
+ r = d;
720
+ else {
721
+ const f = this.getCursor().position;
722
+ r = this.textModel.positionToOffset(f);
723
+ }
724
+ n && (l = this.textModel.positionToOffset(n.start), a = this.textModel.positionToOffset(n.end));
725
+ }
726
+ const h = (t || i) && !n && r !== void 0 && this.hasCollapsedSelectionInEditor(), o = h ? this.insertSentinelAtOffset(e, r) : e, c = s.highlightHTML(o);
727
+ typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(c) : this.view.setHTML(c), this.view.syncTrailingNewlineMarkerForText(e), (t || i) && requestAnimationFrame(() => {
728
+ try {
729
+ if (h && this.restoreCursorFromSentinel()) {
730
+ this.view.ensureCaretVisible();
731
+ return;
732
+ }
733
+ if (n && (l !== void 0 || a !== void 0)) {
734
+ const d = l !== void 0 ? l : r, f = a !== void 0 ? a : r, u = Math.min(d, f), g = Math.max(d, f), p = this.textModel.offsetToPosition(u), y = this.textModel.offsetToPosition(g);
735
+ this.view.setSelectionRange({ start: p, end: y });
736
+ } else if (r !== void 0) {
737
+ const d = this.textModel.offsetToPosition(r);
738
+ this.view.setCursorPosition(d);
739
+ }
740
+ } catch (d) {
741
+ }
742
+ });
743
+ return;
744
+ } catch (i) {
745
+ console.warn("Syntax highlighting failed, falling back to plain text", i);
746
+ }
747
+ this.view.setText(e);
748
+ }
749
+ hasCollapsedSelectionInEditor() {
750
+ const e = window.getSelection();
751
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
752
+ return !1;
753
+ const t = e.getRangeAt(0);
754
+ return this.view.getContentElement().contains(t.commonAncestorContainer);
755
+ }
756
+ getCollapsedSelectionOffsetInEditor() {
757
+ const e = window.getSelection();
758
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
759
+ return;
760
+ const t = e.getRangeAt(0), s = this.view.getContentElement();
761
+ if (!s.contains(t.commonAncestorContainer))
762
+ return;
763
+ const i = t.cloneRange();
764
+ return i.selectNodeContents(s), i.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(i.toString()).length;
765
+ }
766
+ stripVirtualMarkers(e) {
767
+ return e.replace(/\u200B/g, "").split(L.CURSOR_SENTINEL).join("");
768
+ }
769
+ insertSentinelAtOffset(e, t) {
770
+ const s = Math.max(0, Math.min(t, e.length));
771
+ return e.slice(0, s) + L.CURSOR_SENTINEL + e.slice(s);
772
+ }
773
+ restoreCursorFromSentinel() {
774
+ var l;
775
+ const e = this.view.getContentElement(), t = window.getSelection(), s = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
776
+ let i = s.nextNode(), n = null, r = 0;
777
+ for (; i; ) {
778
+ const a = (l = i.textContent) != null ? l : "", h = a.indexOf(L.CURSOR_SENTINEL);
779
+ h !== -1 && (n || (n = i, r = h), i.textContent = a.split(L.CURSOR_SENTINEL).join("")), i = s.nextNode();
780
+ }
781
+ if (!n || !t) return !1;
782
+ try {
783
+ const a = document.createRange();
784
+ return a.setStart(n, r), a.collapse(!0), t.removeAllRanges(), t.addRange(a), !0;
785
+ } catch (a) {
786
+ return !1;
787
+ }
788
+ }
789
+ destroy() {
790
+ if (!this.isDestroyed) {
791
+ this.isDestroyed = !0;
792
+ for (const e of this.extensions.values())
793
+ e.destroy && e.destroy();
794
+ this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
795
+ }
796
+ }
797
+ // History: undo/redo
798
+ undo() {
799
+ if (this.undoStack.length === 0) return;
800
+ const e = this.undoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
801
+ this.redoStack.push(t);
802
+ try {
803
+ this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
804
+ let s, i;
805
+ typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
806
+ try {
807
+ if (i != null)
808
+ if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
809
+ const n = e.anchorOffset !== void 0 ? e.anchorOffset : i, r = e.focusOffset !== void 0 ? e.focusOffset : i, l = Math.min(n, r), a = Math.max(n, r), h = this.textModel.offsetToPosition(l), o = this.textModel.offsetToPosition(a);
810
+ this.setSelection({ start: h, end: o });
811
+ } else {
812
+ const n = this.textModel.offsetToPosition(i);
813
+ this.setCursor(n);
814
+ }
815
+ } catch (n) {
816
+ }
817
+ }), setTimeout(() => {
818
+ this.expectingProgrammaticCursor = !1;
819
+ }, 30);
820
+ } finally {
821
+ this.suppressHistory = !1;
822
+ }
823
+ }
824
+ redo() {
825
+ if (this.redoStack.length === 0) return;
826
+ const e = this.redoStack.pop(), t = { text: this.getValue(), cursorOffset: this.textModel.positionToOffset(this.getCursor().position) };
827
+ this.undoStack.push(t);
828
+ try {
829
+ this.suppressHistory = !0, this.expectingProgrammaticCursor = !0;
830
+ let s, i;
831
+ typeof e == "string" ? s = e : (s = e.text, i = e.cursorOffset), this.setValue(s), requestAnimationFrame(() => {
832
+ try {
833
+ if (i != null)
834
+ if (typeof e != "string" && (e.anchorOffset !== void 0 || e.focusOffset !== void 0)) {
835
+ const n = e.anchorOffset !== void 0 ? e.anchorOffset : i, r = e.focusOffset !== void 0 ? e.focusOffset : i, l = Math.min(n, r), a = Math.max(n, r), h = this.textModel.offsetToPosition(l), o = this.textModel.offsetToPosition(a);
836
+ this.setSelection({ start: h, end: o });
837
+ } else {
838
+ const n = this.textModel.offsetToPosition(i);
839
+ this.setCursor(n);
840
+ }
841
+ } catch (n) {
842
+ }
843
+ }), setTimeout(() => {
844
+ this.expectingProgrammaticCursor = !1;
845
+ }, 30);
846
+ } finally {
847
+ this.suppressHistory = !1;
848
+ }
849
+ }
850
+ // Insert a tab character or spaces at current cursor
851
+ insertTab() {
852
+ if (this.config.readOnly) return;
853
+ const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = " ".repeat(this.config.tabSize || 2), i = this.textModel.insertText(e, s), n = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + s.length);
854
+ if (!this.suppressHistory) {
855
+ const r = this.getSelection();
856
+ let l, a;
857
+ r && (l = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: l, focusOffset: a }), this.redoStack.length = 0;
858
+ }
859
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(n), setTimeout(() => {
860
+ this.expectingProgrammaticCursor = !1;
861
+ }, 20), this.emit("change", [i]);
862
+ }
863
+ // Insert a newline at current cursor position
864
+ insertNewLine() {
865
+ if (this.config.readOnly) return;
866
+ const e = this.getCursor().position, t = this.textModel.positionToOffset(e), s = this.textModel.insertText(e, `
867
+ `), i = this.textModel.offsetToPosition(this.textModel.positionToOffset(e) + 1);
868
+ if (!this.suppressHistory) {
869
+ const n = this.getSelection();
870
+ let r, l;
871
+ n && (r = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)), this.undoStack.push({ text: this.getValue(), cursorOffset: t, anchorOffset: r, focusOffset: l }), this.redoStack.length = 0;
872
+ }
873
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.setCursor(i), setTimeout(() => {
874
+ this.expectingProgrammaticCursor = !1;
875
+ }, 20), this.emit("change", [s]);
876
+ }
877
+ // Events
878
+ on(e, t) {
879
+ this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
880
+ }
881
+ off(e, t) {
882
+ if (!this.eventListeners.has(e)) return;
883
+ const s = this.eventListeners.get(e);
884
+ if (t) {
885
+ const i = s.indexOf(t);
886
+ i !== -1 && s.splice(i, 1);
887
+ } else
888
+ s.length = 0;
889
+ }
890
+ };
891
+ F.CURSOR_SENTINEL = "";
892
+ let X = F;
893
+ class J {
894
+ constructor(e) {
895
+ this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
896
+ }
897
+ setup(e) {
898
+ this.editor = e;
899
+ }
900
+ handleKeyDown(e) {
901
+ if (!this.editor) return;
902
+ const t = this.findMatchingBinding(e);
903
+ if (t)
904
+ return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
905
+ }
906
+ findMatchingBinding(e) {
907
+ const { key: t, ctrlKey: s, altKey: i, shiftKey: n, metaKey: r } = e, l = String(t).toLowerCase(), a = this.keymap[l];
908
+ if (!a) return null;
909
+ for (const h of a) {
910
+ const o = h.ctrlKey === void 0 || h.ctrlKey === s, c = h.altKey === void 0 || h.altKey === i, d = h.shiftKey === void 0 || h.shiftKey === n, f = h.metaKey === void 0 || h.metaKey === r;
911
+ if (o && c && d && f)
912
+ return h;
913
+ }
914
+ return null;
915
+ }
916
+ // Allow EditorCore to call this directly when checking extension.onKeyDown
917
+ onKeyDown(e) {
918
+ return this.handleKeyDown(e);
919
+ }
920
+ getDefaultKeymap() {
921
+ const e = {};
922
+ 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;
923
+ }
924
+ addBinding(e, t, s, i) {
925
+ const n = t.toLowerCase();
926
+ e[n] || (e[n] = []), e[n].push({
927
+ key: n,
928
+ command: i,
929
+ ...s
930
+ });
931
+ }
932
+ // Public API for customizing keymap
933
+ setKeymap(e) {
934
+ this.keymap = { ...e };
935
+ }
936
+ addKeyBinding(e) {
937
+ const t = e.key.toLowerCase();
938
+ this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((s) => s.command !== e.command), this.keymap[t].push({
939
+ ...e,
940
+ key: t
941
+ });
942
+ }
943
+ removeKeyBinding(e, t) {
944
+ const s = e.toLowerCase();
945
+ 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];
946
+ }
947
+ getKeymap() {
948
+ return { ...this.keymap };
949
+ }
950
+ getBindingsForCommand(e) {
951
+ const t = [];
952
+ for (const s in this.keymap)
953
+ for (const i of this.keymap[s])
954
+ i.command === e && t.push({ ...i });
955
+ return t;
956
+ }
957
+ getPlatformInfo() {
958
+ return {
959
+ isMac: this.isMac,
960
+ platform: navigator.platform
961
+ };
962
+ }
963
+ destroy() {
964
+ this.keymap = {}, this.editor = null;
965
+ }
966
+ }
967
+ class Y {
968
+ constructor() {
969
+ this.name = "transaction", this.transactions = [];
970
+ }
971
+ setup(e) {
972
+ e.on("change", (t) => {
973
+ const s = {
974
+ changes: t,
975
+ selection: e.getSelection(),
976
+ effects: [],
977
+ annotations: []
978
+ };
979
+ this.transactions.push(s);
980
+ });
981
+ }
982
+ getTransactions() {
983
+ return this.transactions;
984
+ }
985
+ destroy() {
986
+ this.transactions = [];
987
+ }
988
+ }
989
+ class G {
990
+ constructor() {
991
+ this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
992
+ }
993
+ setup(e) {
994
+ this.editor = e, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
995
+ this.toggle();
996
+ }), e.on("change", () => {
997
+ this.updateLineNumbers();
998
+ }), this.updateLineNumbers();
999
+ }
1000
+ createLineNumbers() {
1001
+ if (!this.editor) return;
1002
+ const e = this.editor.getView().getLineNumbersElement();
1003
+ e && (this.lineNumbersElement = e);
1004
+ }
1005
+ updateLineNumbers() {
1006
+ if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
1007
+ const e = this.editor.getValue().split(`
1008
+ `).length, t = Array.from({ length: Math.max(e, 20) }, (s, i) => i + 1);
1009
+ this.lineNumbersElement.innerHTML = t.map((s) => `<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("");
1010
+ }
1011
+ toggle() {
1012
+ if (!this.editor) return;
1013
+ this.isEnabled = !this.isEnabled, this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "block" : "none");
1014
+ const e = this.editor.getView().getContentElement();
1015
+ e && (e.style.marginLeft = this.isEnabled ? "60px" : "0"), this.updateLineNumbers();
1016
+ }
1017
+ destroy() {
1018
+ this.lineNumbersElement = null, this.editor = null;
1019
+ }
1020
+ }
1021
+ class _ {
1022
+ constructor() {
1023
+ this.name = "theme", this.editor = null, this.currentTheme = "dark";
1024
+ }
1025
+ setup(e) {
1026
+ this.editor = e, e.registerCommand("setTheme", (t) => {
1027
+ this.setTheme(t);
1028
+ }), e.registerCommand("toggleTheme", () => {
1029
+ this.toggleTheme();
1030
+ }), this.setTheme(this.currentTheme);
1031
+ }
1032
+ setTheme(e) {
1033
+ this.editor && (this.currentTheme = e, this.editor.setTheme(e));
1034
+ }
1035
+ toggleTheme() {
1036
+ const e = this.currentTheme === "dark" ? "light" : "dark";
1037
+ this.setTheme(e);
1038
+ }
1039
+ getCurrentTheme() {
1040
+ return this.currentTheme;
1041
+ }
1042
+ destroy() {
1043
+ this.editor = null;
1044
+ }
1045
+ }
1046
+ class ee {
1047
+ constructor() {
1048
+ this.name = "read-only", this.editor = null, this.isReadOnly = !1;
1049
+ }
1050
+ setup(e) {
1051
+ this.editor = e, e.registerCommand("setReadOnly", (t) => {
1052
+ this.setReadOnly(t);
1053
+ }), e.registerCommand("toggleReadOnly", () => {
1054
+ this.toggleReadOnly();
1055
+ }), e.on("keydown", (t) => {
1056
+ if (t.ctrlKey && t.key === "r")
1057
+ return t.preventDefault(), this.toggleReadOnly(), !1;
1058
+ });
1059
+ }
1060
+ setReadOnly(e) {
1061
+ this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
1062
+ }
1063
+ toggleReadOnly() {
1064
+ this.setReadOnly(!this.isReadOnly);
1065
+ }
1066
+ isCurrentlyReadOnly() {
1067
+ return this.isReadOnly;
1068
+ }
1069
+ destroy() {
1070
+ this.editor = null;
1071
+ }
1072
+ }
1073
+ let te = 0;
1074
+ const W = class m {
1075
+ constructor(e = {}) {
1076
+ this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1, this.searchDebounceTimer = null, this.liveRefreshTimer = null, this.statusResetTimer = null, this.statusFreezeUntil = 0, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.currentQuery = "", this.savedCursor = null, this.editorChangeHandler = null, this.searchOptions = {
1077
+ caseSensitive: !1,
1078
+ wholeWord: !1,
1079
+ regex: !1
1080
+ }, this.trailingMarkerAttr = "data-lce-trailing-newline-marker", this.editorContainerSelector = '[data-lce-editor-container="true"]', this.highlightId = ++te, this.highlightMatchName = `editora-search-match-${this.highlightId}`, this.highlightActiveName = `editora-search-active-${this.highlightId}`, this.highlightStyleId = `editora-search-highlight-style-${this.highlightId}`, this.maxCustomHighlightRanges = 2e3, this.virtualMarkerRegex = /[\u200B\uE000]/, this.hasCustomHighlightSupport = !1, this.config = {
1081
+ replaceAndFindNext: !0,
1082
+ ...e
1083
+ };
1084
+ }
1085
+ setup(e) {
1086
+ this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && this.ensureHighlightStyles(), e.registerCommand("find", () => {
1087
+ this.showSearch();
1088
+ }), e.registerCommand("findNext", () => {
1089
+ this.findNext();
1090
+ }), e.registerCommand("findPrev", () => {
1091
+ this.findPrev();
1092
+ }), e.registerCommand("replace", () => {
1093
+ this.showReplace();
1094
+ }), e.registerCommand("replaceAll", (t, s) => {
1095
+ this.replaceAll(t, s);
1096
+ }), this.editorChangeHandler = () => {
1097
+ !this.isVisible || !this.currentQuery || this.scheduleLiveRefresh(!0);
1098
+ }, e.on("change", this.editorChangeHandler);
1099
+ }
1100
+ showSearch() {
1101
+ this.editor && (this.searchUI || this.createSearchUI(), this.isVisible || this.captureSelectionState(), this.isVisible = !0, this.searchUI && (this.searchUI.style.display = "block", this.updateModeHint(!1), this.findInput && (this.findInput.focus(), this.findInput.select())), this.currentQuery && this.performSearch(this.currentQuery, !0, !1));
1102
+ }
1103
+ showReplace() {
1104
+ this.showSearch(), this.replaceInputEl && (this.replaceInputEl.style.display = "block", this.replaceInputEl.focus()), this.updateModeHint(!0), this.currentQuery && this.performSearch(this.currentQuery, !1, !0);
1105
+ }
1106
+ hideSearch() {
1107
+ this.isVisible = !1, this.searchUI && (this.searchUI.style.display = "none"), this.replaceInputEl && (this.replaceInputEl.style.display = "none", this.replaceInputEl.value = ""), this.updateModeHint(!1), this.clearHighlights(), this.restoreSelectionState();
1108
+ }
1109
+ createSearchUI() {
1110
+ if (!this.editor) return;
1111
+ const e = this.editor.getView().getContentElement(), t = e.closest(
1112
+ this.editorContainerSelector
1113
+ ), s = e.closest(".rte-source-editor-modal") || t || e.parentElement;
1114
+ if (!s) return;
1115
+ window.getComputedStyle(s).position === "static" && (s.style.position = "relative"), this.searchUI = document.createElement("div"), this.searchUI.className = m.css.root, this.searchUI.style.display = "none", this.searchUI.innerHTML = `
1116
+ <div class="${m.css.row}">
1117
+ <input type="text" class="${m.css.findInput} ${m.css.inputBase}" placeholder="Find..." />
1118
+ <button class="${m.css.prevButton} ${m.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
1119
+ <button class="${m.css.nextButton} ${m.css.buttonBase}" type="button" aria-label="Next match">↓</button>
1120
+ <button class="${m.css.closeButton} ${m.css.buttonBase}" type="button" aria-label="Close search">×</button>
1121
+ </div>
1122
+ <div class="${m.css.options}">
1123
+ <label class="${m.css.optionLabel}" title="Case sensitive">
1124
+ <input type="checkbox" class="${m.css.optionInput} ${m.css.caseSensitive}" />
1125
+ <span>Aa</span>
1126
+ </label>
1127
+ <label class="${m.css.optionLabel}" title="Whole word">
1128
+ <input type="checkbox" class="${m.css.optionInput} ${m.css.wholeWord}" />
1129
+ <span>Whole</span>
1130
+ </label>
1131
+ <label class="${m.css.optionLabel}" title="Regular expression">
1132
+ <input type="checkbox" class="${m.css.optionInput} ${m.css.regex}" />
1133
+ <span>.*</span>
1134
+ </label>
1135
+ </div>
1136
+ <div class="${m.css.meta}">
1137
+ <div class="${m.css.status} ${m.css.statusLayout}"></div>
1138
+ <div class="${m.css.mode} ${m.css.modeLayout}" aria-live="polite"></div>
1139
+ </div>
1140
+ <input type="text" class="${m.css.replaceInput} ${m.css.inputBase} ${m.css.replaceInputLayout}" placeholder="Replace with..." />
1141
+ `;
1142
+ const i = this.searchUI.querySelector(
1143
+ `.${m.css.findInput}`
1144
+ ), n = this.searchUI.querySelector(
1145
+ `.${m.css.replaceInput}`
1146
+ ), r = this.searchUI.querySelector(
1147
+ `.${m.css.prevButton}`
1148
+ ), l = this.searchUI.querySelector(
1149
+ `.${m.css.nextButton}`
1150
+ ), a = this.searchUI.querySelector(
1151
+ `.${m.css.closeButton}`
1152
+ ), h = this.searchUI.querySelector(
1153
+ `.${m.css.status}`
1154
+ ), o = this.searchUI.querySelector(
1155
+ `.${m.css.mode}`
1156
+ ), c = this.searchUI.querySelector(
1157
+ `.${m.css.caseSensitive}`
1158
+ ), d = this.searchUI.querySelector(
1159
+ `.${m.css.wholeWord}`
1160
+ ), f = this.searchUI.querySelector(
1161
+ `.${m.css.regex}`
1162
+ );
1163
+ this.findInput = i, this.replaceInputEl = n, this.statusDiv = h, this.modeDiv = o, this.caseSensitiveInput = c, this.wholeWordInput = d, this.regexInput = f, c.checked = !!this.searchOptions.caseSensitive, d.checked = !!this.searchOptions.wholeWord, f.checked = !!this.searchOptions.regex, i.addEventListener("input", () => {
1164
+ this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
1165
+ const g = i.value;
1166
+ this.searchDebounceTimer = setTimeout(() => {
1167
+ this.performSearch(g, !1, !1);
1168
+ }, 120);
1169
+ });
1170
+ const u = () => {
1171
+ this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = d.checked, this.searchOptions.regex = f.checked;
1172
+ const g = i.value;
1173
+ g.trim() ? this.performSearch(g, !1, !1) : this.performSearch("", !1, !1);
1174
+ };
1175
+ c.addEventListener("change", u), d.addEventListener("change", u), f.addEventListener("change", u), i.addEventListener("keydown", (g) => {
1176
+ g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.findPrev() : this.findNext()) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
1177
+ }), n.addEventListener("keydown", (g) => {
1178
+ g.key === "Enter" ? (g.preventDefault(), g.shiftKey ? this.replaceAll(i.value, n.value) : this.replaceCurrent(i.value, n.value)) : g.key === "Escape" && (g.preventDefault(), this.hideSearch());
1179
+ }), r.addEventListener("click", () => this.findPrev()), l.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()), s.appendChild(this.searchUI);
1180
+ }
1181
+ updateModeHint(e) {
1182
+ this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
1183
+ }
1184
+ performSearch(e, t, s) {
1185
+ if (!this.editor || !e.trim()) {
1186
+ this.currentQuery = "", this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("");
1187
+ return;
1188
+ }
1189
+ if (this.searchOptions.regex && !this.isValidRegex(e)) {
1190
+ this.currentQuery = e, this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Invalid regular expression");
1191
+ return;
1192
+ }
1193
+ this.currentQuery = e;
1194
+ const i = this.currentIndex, n = this.editor.search(e, this.searchOptions);
1195
+ if (this.currentResults = n, n.length === 0) {
1196
+ this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
1197
+ return;
1198
+ }
1199
+ t && i >= 0 ? this.currentIndex = Math.min(i, n.length - 1) : this.currentIndex = 0, this.updateHighlights(s);
1200
+ }
1201
+ findNext() {
1202
+ if (this.currentResults.length === 0) {
1203
+ this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
1204
+ return;
1205
+ }
1206
+ this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights(!0);
1207
+ }
1208
+ findPrev() {
1209
+ if (this.currentResults.length === 0) {
1210
+ this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
1211
+ return;
1212
+ }
1213
+ this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights(!0);
1214
+ }
1215
+ replaceCurrent(e, t) {
1216
+ if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0)) return;
1217
+ const s = this.currentResults[this.currentIndex];
1218
+ if (!s) return;
1219
+ const i = this.computeReplacementRange(s.range.start, t);
1220
+ if (this.editor.replace(s.range, t), this.config.replaceAndFindNext) {
1221
+ this.currentQuery = e;
1222
+ const n = this.editor.search(e, this.searchOptions);
1223
+ if (this.currentResults = n, n.length === 0) {
1224
+ this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
1225
+ return;
1226
+ }
1227
+ this.currentIndex = this.findNextResultIndexAfter(i.end, n), this.updateHighlights(!0);
1228
+ } else
1229
+ this.scrollLogicalRangeIntoView(i, !0), this.performSearch(e, !0, !1);
1230
+ this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
1231
+ }
1232
+ replaceAll(e, t) {
1233
+ if (!this.editor || !e.trim()) return;
1234
+ const s = this.editor.replaceAll(e, t, this.searchOptions);
1235
+ this.performSearch(e, !1, !1), this.showTransientStatus(`Replaced ${s} occurrence${s === 1 ? "" : "s"}`), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
1236
+ }
1237
+ updateHighlights(e) {
1238
+ if (this.clearHighlights(), this.currentResults.length === 0 || this.currentIndex === -1 || !this.editor)
1239
+ return;
1240
+ this.applyCustomHighlights();
1241
+ const t = this.currentResults[this.currentIndex];
1242
+ t && ((e || !this.hasCustomHighlightSupport) && this.navigateToResult(t, !this.hasCustomHighlightSupport), this.updateStatus(
1243
+ `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`
1244
+ ));
1245
+ }
1246
+ navigateToResult(e, t) {
1247
+ if (!this.editor) return;
1248
+ const s = document.activeElement, i = !!s && (s === this.findInput || s === this.replaceInputEl);
1249
+ t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
1250
+ const n = this.editor.getView();
1251
+ t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t && i && s && requestAnimationFrame(() => {
1252
+ this.focusWithoutScrolling(s);
1253
+ });
1254
+ }
1255
+ clearHighlights() {
1256
+ var e, t;
1257
+ if (this.hasCustomHighlightSupport)
1258
+ try {
1259
+ const s = CSS;
1260
+ (e = s.highlights) == null || e.delete(this.highlightMatchName), (t = s.highlights) == null || t.delete(this.highlightActiveName);
1261
+ } catch (s) {
1262
+ }
1263
+ }
1264
+ scrollResultIntoView(e) {
1265
+ this.scrollLogicalRangeIntoView(e.range, !0);
1266
+ }
1267
+ scrollLogicalRangeIntoView(e, t) {
1268
+ if (!this.editor) return;
1269
+ const s = this.editor.getView().getContentElement(), i = this.editor.getValue(), { lineStarts: n, lines: r } = this.buildLineStarts(i), l = this.buildTextNodeIndex(s);
1270
+ if (l.length === 0) return;
1271
+ const a = this.toDomRange(e, n, r, l);
1272
+ if (!a) return;
1273
+ const h = a.startContainer.nodeType === Node.TEXT_NODE ? a.startContainer.parentElement : a.startContainer, o = this.resolveScrollContainer(s);
1274
+ if (o) {
1275
+ const c = a.getClientRects()[0] || a.getBoundingClientRect(), d = o.getBoundingClientRect(), f = o.scrollTop + (c.top - d.top) - d.height / 2 + c.height / 2, u = 18;
1276
+ let g = t ? f : o.scrollTop, p = o.scrollLeft;
1277
+ const y = o.scrollLeft + (c.left - d.left), C = y + c.width;
1278
+ c.right > d.right - u ? p = C - d.width + u : c.left < d.left + u && (p = Math.max(0, y - u));
1279
+ const v = Math.max(0, o.scrollHeight - o.clientHeight), S = Math.max(0, o.scrollWidth - o.clientWidth);
1280
+ if (g = Math.min(v, Math.max(0, g)), p = Math.min(S, Math.max(0, p)), v === 0 && S === 0) {
1281
+ h == null || h.scrollIntoView({
1282
+ block: t ? "center" : "nearest",
1283
+ inline: "nearest",
1284
+ behavior: "smooth"
1285
+ });
1286
+ return;
1287
+ }
1288
+ (g !== o.scrollTop || p !== o.scrollLeft) && o.scrollTo({
1289
+ top: g,
1290
+ left: p,
1291
+ behavior: "smooth"
1292
+ });
1293
+ return;
1294
+ }
1295
+ h == null || h.scrollIntoView({
1296
+ block: t ? "center" : "nearest",
1297
+ inline: "nearest",
1298
+ behavior: "smooth"
1299
+ });
1300
+ }
1301
+ restoreReplaceInputFocus() {
1302
+ const e = this.replaceInputEl;
1303
+ !e || e.style.display === "none" || requestAnimationFrame(() => {
1304
+ this.focusWithoutScrolling(e);
1305
+ const t = e.value.length;
1306
+ try {
1307
+ e.setSelectionRange(t, t);
1308
+ } catch (s) {
1309
+ }
1310
+ });
1311
+ }
1312
+ centerCurrentSelectionInView() {
1313
+ if (!this.editor) return;
1314
+ const e = this.editor.getView().getContentElement(), t = this.resolveScrollContainer(e);
1315
+ if (!t) return;
1316
+ const s = window.getSelection();
1317
+ if (!s || s.rangeCount === 0) return;
1318
+ const i = s.getRangeAt(0).cloneRange(), n = i.getClientRects()[0] || i.getBoundingClientRect();
1319
+ if (!n) return;
1320
+ const r = t.getBoundingClientRect(), l = t.scrollTop + (n.top - r.top) - r.height / 2 + n.height / 2, a = Math.max(0, t.scrollHeight - t.clientHeight), h = Math.min(a, Math.max(0, l));
1321
+ h !== t.scrollTop && t.scrollTo({
1322
+ top: h,
1323
+ behavior: "smooth"
1324
+ });
1325
+ }
1326
+ computeReplacementRange(e, t) {
1327
+ const s = t.replace(/\r\n?/g, `
1328
+ `), i = s.split(`
1329
+ `);
1330
+ let n;
1331
+ return i.length <= 1 ? (n = {
1332
+ start: e,
1333
+ end: {
1334
+ line: e.line,
1335
+ column: e.column + s.length
1336
+ }
1337
+ }, this.clampRangeToDocument(n)) : (n = {
1338
+ start: e,
1339
+ end: {
1340
+ line: e.line + i.length - 1,
1341
+ column: i[i.length - 1].length
1342
+ }
1343
+ }, this.clampRangeToDocument(n));
1344
+ }
1345
+ findNextResultIndexAfter(e, t) {
1346
+ for (let s = 0; s < t.length; s++)
1347
+ if (this.comparePositions(t[s].range.start, e) >= 0)
1348
+ return s;
1349
+ return 0;
1350
+ }
1351
+ comparePositions(e, t) {
1352
+ return e.line !== t.line ? e.line - t.line : e.column - t.column;
1353
+ }
1354
+ clampRangeToDocument(e) {
1355
+ var h, o;
1356
+ const t = this.editor;
1357
+ if (!t) return e;
1358
+ const s = t.getValue().split(`
1359
+ `), i = Math.max(0, s.length - 1), n = Math.max(0, Math.min(e.start.line, i)), r = Math.max(0, Math.min(e.end.line, i)), l = Math.max(
1360
+ 0,
1361
+ Math.min(e.start.column, ((h = s[n]) == null ? void 0 : h.length) || 0)
1362
+ ), a = Math.max(
1363
+ 0,
1364
+ Math.min(e.end.column, ((o = s[r]) == null ? void 0 : o.length) || 0)
1365
+ );
1366
+ return {
1367
+ start: { line: n, column: l },
1368
+ end: { line: r, column: a }
1369
+ };
1370
+ }
1371
+ focusWithoutScrolling(e) {
1372
+ try {
1373
+ e.focus({
1374
+ preventScroll: !0
1375
+ });
1376
+ } catch (t) {
1377
+ const s = [];
1378
+ let i = e.parentElement;
1379
+ for (; i; )
1380
+ this.canScroll(i) && s.push({
1381
+ el: i,
1382
+ top: i.scrollTop,
1383
+ left: i.scrollLeft
1384
+ }), i = i.parentElement;
1385
+ const n = window.scrollX, r = window.scrollY;
1386
+ e.focus();
1387
+ for (let l = 0; l < s.length; l++) {
1388
+ const a = s[l];
1389
+ a.el.scrollTop = a.top, a.el.scrollLeft = a.left;
1390
+ }
1391
+ window.scrollTo(n, r);
1392
+ }
1393
+ }
1394
+ findScrollContainer(e) {
1395
+ let t = e;
1396
+ for (; t; ) {
1397
+ const s = window.getComputedStyle(t).overflowY;
1398
+ if ((s === "auto" || s === "scroll") && t.scrollHeight > t.clientHeight)
1399
+ return t;
1400
+ t = t.parentElement;
1401
+ }
1402
+ return null;
1403
+ }
1404
+ resolveScrollContainer(e) {
1405
+ var s, i, n;
1406
+ const t = ((n = (i = (s = this.editor) == null ? void 0 : s.getView()) == null ? void 0 : i.getScrollElement) == null ? void 0 : n.call(i)) || null;
1407
+ return t && this.canScroll(t) ? t : this.findScrollContainer(e);
1408
+ }
1409
+ canScroll(e) {
1410
+ return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
1411
+ }
1412
+ revealActiveResultAfterFocusRestore() {
1413
+ !this.currentResults.length || this.currentIndex < 0 || requestAnimationFrame(() => {
1414
+ const e = this.currentResults[this.currentIndex];
1415
+ e && this.scrollResultIntoView(e);
1416
+ });
1417
+ }
1418
+ applyCustomHighlights() {
1419
+ if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
1420
+ return;
1421
+ const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: s, lines: i } = this.buildLineStarts(t), n = this.buildTextNodeIndex(e);
1422
+ if (n.length === 0) return;
1423
+ const r = this.buildVisibleDocumentText(n), l = [];
1424
+ let a = null;
1425
+ const h = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
1426
+ for (let o = 0; o < h; o++) {
1427
+ const c = this.currentResults[o], d = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, f = this.toDomRange(
1428
+ c.range,
1429
+ s,
1430
+ i,
1431
+ n,
1432
+ r,
1433
+ d
1434
+ );
1435
+ f && (l.push(f), o === this.currentIndex && (a = f));
1436
+ }
1437
+ if (l.length !== 0)
1438
+ try {
1439
+ const o = CSS, c = window.Highlight;
1440
+ if (!o.highlights || !c) return;
1441
+ o.highlights.set(this.highlightMatchName, new c(...l)), a && o.highlights.set(this.highlightActiveName, new c(a));
1442
+ } catch (o) {
1443
+ }
1444
+ }
1445
+ buildLineStarts(e) {
1446
+ const t = e.split(`
1447
+ `), s = new Array(t.length);
1448
+ let i = 0;
1449
+ for (let n = 0; n < t.length; n++)
1450
+ s[n] = i, i += t[n].length + 1;
1451
+ return { lineStarts: s, lines: t };
1452
+ }
1453
+ positionToOffset(e, t, s) {
1454
+ var r;
1455
+ const i = Math.max(0, Math.min(e.line, s.length - 1)), n = Math.max(0, Math.min(e.column, ((r = s[i]) == null ? void 0 : r.length) || 0));
1456
+ return t[i] + n;
1457
+ }
1458
+ buildTextNodeIndex(e) {
1459
+ var r;
1460
+ const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), s = [];
1461
+ let i = 0, n;
1462
+ for (; n = t.nextNode(); ) {
1463
+ const l = n;
1464
+ if ((r = l.parentElement) != null && r.hasAttribute(this.trailingMarkerAttr))
1465
+ continue;
1466
+ const a = l.textContent || "", h = this.buildVisibleToDomMap(a), o = Math.max(0, h.length - 1);
1467
+ o === 0 && a.length === 0 || (s.push({
1468
+ node: l,
1469
+ start: i,
1470
+ end: i + o,
1471
+ visibleToDom: h
1472
+ }), i += o);
1473
+ }
1474
+ return s;
1475
+ }
1476
+ resolveDomPoint(e, t) {
1477
+ var n, r, l, a, h, o;
1478
+ const s = Math.max(0, e);
1479
+ for (let c = 0; c < t.length; c++) {
1480
+ const d = t[c];
1481
+ if (s <= d.end) {
1482
+ const f = Math.max(0, s - d.start), u = (l = (r = d.visibleToDom[f]) != null ? r : (n = d.node.textContent) == null ? void 0 : n.length) != null ? l : 0;
1483
+ return {
1484
+ node: d.node,
1485
+ offset: u
1486
+ };
1487
+ }
1488
+ }
1489
+ const i = t[t.length - 1];
1490
+ return i ? {
1491
+ node: i.node,
1492
+ offset: (o = (h = i.visibleToDom[i.visibleToDom.length - 1]) != null ? h : (a = i.node.textContent) == null ? void 0 : a.length) != null ? o : 0
1493
+ } : null;
1494
+ }
1495
+ toDomRange(e, t, s, i, n, r) {
1496
+ const l = this.positionToOffset(e.start, t, s), a = this.positionToOffset(e.end, t, s);
1497
+ let h = Math.min(l, a), o = Math.max(l, a);
1498
+ if (n && r) {
1499
+ const u = r, g = n.slice(h, o);
1500
+ if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
1501
+ const p = this.findNearestMatchOffset(
1502
+ n,
1503
+ u,
1504
+ h
1505
+ );
1506
+ p !== -1 && (h = p, o = p + u.length);
1507
+ }
1508
+ }
1509
+ const c = this.resolveDomPoint(h, i), d = this.resolveDomPoint(o, i);
1510
+ if (!c || !d) return null;
1511
+ const f = document.createRange();
1512
+ try {
1513
+ return f.setStart(c.node, c.offset), f.setEnd(d.node, d.offset), f;
1514
+ } catch (u) {
1515
+ return null;
1516
+ }
1517
+ }
1518
+ buildVisibleDocumentText(e) {
1519
+ let t = "";
1520
+ for (let s = 0; s < e.length; s++) {
1521
+ const i = e[s].node.textContent || "";
1522
+ for (let n = 0; n < i.length; n++) {
1523
+ const r = i[n];
1524
+ this.virtualMarkerRegex.test(r) || (t += r);
1525
+ }
1526
+ }
1527
+ return t;
1528
+ }
1529
+ findNearestMatchOffset(e, t, s) {
1530
+ const i = t.toLowerCase();
1531
+ let n = e.toLowerCase().indexOf(i);
1532
+ if (n === -1) return -1;
1533
+ let r = n, l = Math.abs(n - s);
1534
+ for (; n !== -1; ) {
1535
+ const a = Math.abs(n - s);
1536
+ if (a < l && (l = a, r = n), a === 0) return n;
1537
+ n = e.toLowerCase().indexOf(i, n + 1);
1538
+ }
1539
+ return r;
1540
+ }
1541
+ scheduleLiveRefresh(e) {
1542
+ this.liveRefreshTimer && clearTimeout(this.liveRefreshTimer);
1543
+ const t = this.currentQuery;
1544
+ this.liveRefreshTimer = setTimeout(() => {
1545
+ !this.isVisible || !t || this.performSearch(t, e, !1);
1546
+ }, 90);
1547
+ }
1548
+ updateStatus(e, t = !1) {
1549
+ if (this.statusDiv) {
1550
+ if (!t && Date.now() < this.statusFreezeUntil)
1551
+ return;
1552
+ this.statusDiv.textContent = e;
1553
+ }
1554
+ }
1555
+ showTransientStatus(e, t = 900) {
1556
+ this.statusFreezeUntil = Date.now() + t, this.updateStatus(e, !0), this.statusResetTimer && clearTimeout(this.statusResetTimer), this.statusResetTimer = setTimeout(() => {
1557
+ this.statusFreezeUntil = 0, this.syncMatchStatus();
1558
+ }, t);
1559
+ }
1560
+ syncMatchStatus() {
1561
+ if (!this.currentQuery) {
1562
+ this.updateStatus("", !0);
1563
+ return;
1564
+ }
1565
+ if (this.currentResults.length === 0 || this.currentIndex < 0) {
1566
+ this.updateStatus("No matches", !0);
1567
+ return;
1568
+ }
1569
+ this.updateStatus(
1570
+ `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`,
1571
+ !0
1572
+ );
1573
+ }
1574
+ isValidRegex(e) {
1575
+ try {
1576
+ const t = this.searchOptions.caseSensitive ? "g" : "gi";
1577
+ return new RegExp(e, t), !0;
1578
+ } catch (t) {
1579
+ return !1;
1580
+ }
1581
+ }
1582
+ captureSelectionState() {
1583
+ this.editor && (this.savedSelection = this.editor.getSelection(), this.savedCursor = this.editor.getCursor().position);
1584
+ }
1585
+ restoreSelectionState() {
1586
+ this.editor && (this.savedSelection ? this.editor.setSelection(this.savedSelection) : this.savedCursor && this.editor.setCursor(this.savedCursor), this.savedSelection = void 0, this.savedCursor = null);
1587
+ }
1588
+ detectCustomHighlightSupport() {
1589
+ try {
1590
+ const e = CSS, t = window.Highlight;
1591
+ return !!e.highlights && !!t;
1592
+ } catch (e) {
1593
+ return !1;
1594
+ }
1595
+ }
1596
+ buildVisibleToDomMap(e) {
1597
+ const t = [0];
1598
+ let s = 0;
1599
+ for (let i = 0; i < e.length; i++) {
1600
+ const n = e[i];
1601
+ this.virtualMarkerRegex.test(n) || (s += 1, t[s] = i + 1);
1602
+ }
1603
+ return t;
1604
+ }
1605
+ ensureHighlightStyles() {
1606
+ if (document.getElementById(this.highlightStyleId)) return;
1607
+ const e = document.createElement("style");
1608
+ e.id = this.highlightStyleId, e.textContent = `
1609
+ ::highlight(${this.highlightMatchName}) {
1610
+ background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
1611
+ border-radius: 2px;
1612
+ }
1613
+ ::highlight(${this.highlightActiveName}) {
1614
+ background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45));
1615
+ border-radius: 2px;
1616
+ }
1617
+ `, document.head.appendChild(e);
1618
+ }
1619
+ destroy() {
1620
+ this.searchDebounceTimer && (clearTimeout(this.searchDebounceTimer), this.searchDebounceTimer = null), this.liveRefreshTimer && (clearTimeout(this.liveRefreshTimer), this.liveRefreshTimer = null), this.statusResetTimer && (clearTimeout(this.statusResetTimer), this.statusResetTimer = null), this.clearHighlights(), this.searchUI && this.searchUI.parentNode && this.searchUI.parentNode.removeChild(this.searchUI), this.editor && this.editorChangeHandler && this.editor.off("change", this.editorChangeHandler), this.editorChangeHandler = null, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.searchUI = null;
1621
+ const e = document.getElementById(this.highlightStyleId);
1622
+ e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
1623
+ }
1624
+ };
1625
+ W.css = {
1626
+ root: "lce-search-ui",
1627
+ row: "lce-search-row",
1628
+ options: "lce-search-options",
1629
+ optionLabel: "lce-search-option",
1630
+ optionInput: "lce-search-option-input",
1631
+ caseSensitive: "search-case-sensitive",
1632
+ wholeWord: "search-whole-word",
1633
+ regex: "search-regex",
1634
+ meta: "lce-search-meta",
1635
+ findInput: "search-find-input",
1636
+ replaceInput: "search-replace-input",
1637
+ inputBase: "lce-search-input",
1638
+ replaceInputLayout: "lce-search-replace",
1639
+ prevButton: "search-prev",
1640
+ nextButton: "search-next",
1641
+ closeButton: "search-close",
1642
+ buttonBase: "lce-search-btn",
1643
+ status: "search-status",
1644
+ statusLayout: "lce-search-status",
1645
+ mode: "search-mode",
1646
+ modeLayout: "lce-search-mode"
1647
+ };
1648
+ let se = W;
1649
+ class ie {
1650
+ constructor() {
1651
+ this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
1652
+ "(": ")",
1653
+ "[": "]",
1654
+ "{": "}",
1655
+ "<": ">"
1656
+ }, this.reverseBracketPairs = {
1657
+ ")": "(",
1658
+ "]": "[",
1659
+ "}": "{",
1660
+ ">": "<"
1661
+ }, this.currentMatch = null;
1662
+ }
1663
+ setup(e) {
1664
+ this.editor = e, e.on("cursor", () => {
1665
+ this.updateBracketMatching();
1666
+ }), e.on("change", () => {
1667
+ this.updateBracketMatching();
1668
+ });
1669
+ }
1670
+ updateBracketMatching() {
1671
+ if (!this.editor) return;
1672
+ const e = this.editor.getCursor(), t = this.editor.getValue();
1673
+ this.clearBracketHighlighting();
1674
+ const s = this.getBracketAtPosition(t, e.position);
1675
+ if (!s) return;
1676
+ const i = this.findMatchingBracket(t, s);
1677
+ i && (this.currentMatch = i, this.highlightBrackets(i));
1678
+ }
1679
+ getBracketAtPosition(e, t) {
1680
+ const s = e.split(`
1681
+ `);
1682
+ if (t.line >= s.length) return null;
1683
+ const i = s[t.line];
1684
+ if (t.column >= i.length) return null;
1685
+ const n = i[t.column];
1686
+ return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
1687
+ }
1688
+ findMatchingBracket(e, t) {
1689
+ const s = e.split(`
1690
+ `), i = t.position.line, n = t.position.column, r = t.char;
1691
+ return this.bracketPairs[r] ? this.findClosingBracket(e, s, i, n, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(e, s, i, n, r) : null;
1692
+ }
1693
+ findClosingBracket(e, t, s, i, n) {
1694
+ const r = this.bracketPairs[n];
1695
+ let l = 0;
1696
+ for (let a = s; a < t.length; a++) {
1697
+ const h = t[a], o = a === s ? i : 0;
1698
+ for (let c = o; c < h.length; c++) {
1699
+ const d = h[c];
1700
+ if (d === n)
1701
+ l++;
1702
+ else if (d === r && (l--, l === 0))
1703
+ return {
1704
+ open: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1705
+ close: { start: { line: a, column: c }, end: { line: a, column: c + 1 } },
1706
+ type: n
1707
+ };
1708
+ }
1709
+ }
1710
+ return null;
1711
+ }
1712
+ findOpeningBracket(e, t, s, i, n) {
1713
+ const r = this.reverseBracketPairs[n];
1714
+ let l = 0;
1715
+ for (let a = s; a >= 0; a--) {
1716
+ const h = t[a], o = a === s ? i : h.length - 1;
1717
+ for (let c = o; c >= 0; c--) {
1718
+ const d = h[c];
1719
+ if (d === n)
1720
+ l++;
1721
+ else if (d === r && (l--, l === 0))
1722
+ return {
1723
+ open: { start: { line: a, column: c }, end: { line: a, column: c + 1 } },
1724
+ close: { start: { line: s, column: i }, end: { line: s, column: i + 1 } },
1725
+ type: r
1726
+ };
1727
+ }
1728
+ }
1729
+ return null;
1730
+ }
1731
+ highlightBrackets(e) {
1732
+ }
1733
+ clearBracketHighlighting() {
1734
+ this.currentMatch = null;
1735
+ }
1736
+ getCurrentMatch() {
1737
+ return this.currentMatch;
1738
+ }
1739
+ destroy() {
1740
+ this.clearBracketHighlighting(), this.editor = null;
1741
+ }
1742
+ }
1743
+ class ne {
1744
+ constructor() {
1745
+ this.name = "code-folding", this.editor = null, this.foldIndicators = [], this.foldingUI = null, this.pendingUpdateRaf = null, this.lastSnapshot = "", this.changeHandler = null;
1746
+ }
1747
+ setup(e) {
1748
+ this.editor = e, e.registerCommand("fold", () => {
1749
+ this.foldAtCursor();
1750
+ }), e.registerCommand("unfold", () => {
1751
+ this.unfoldAtCursor();
1752
+ }), e.registerCommand("foldAll", () => {
1753
+ this.foldAll();
1754
+ }), e.registerCommand("unfoldAll", () => {
1755
+ this.unfoldAll();
1756
+ }), this.changeHandler = () => {
1757
+ this.scheduleFoldIndicatorUpdate();
1758
+ }, e.on("change", this.changeHandler), this.createFoldingUI(), this.scheduleFoldIndicatorUpdate();
1759
+ }
1760
+ createFoldingUI() {
1761
+ if (!this.editor) return;
1762
+ const e = this.editor.getView().getContentElement(), t = e.closest(".rte-source-editor-modal") || e.parentElement;
1763
+ t && (this.foldingUI = document.createElement("div"), this.foldingUI.style.cssText = `
1764
+ position: absolute;
1765
+ left: 40px;
1766
+ top: 0;
1767
+ bottom: 0;
1768
+ width: 20px;
1769
+ pointer-events: none;
1770
+ z-index: 2;
1771
+ `, t.appendChild(this.foldingUI));
1772
+ }
1773
+ scheduleFoldIndicatorUpdate() {
1774
+ this.pendingUpdateRaf === null && (this.pendingUpdateRaf = requestAnimationFrame(() => {
1775
+ this.pendingUpdateRaf = null, this.updateFoldIndicators();
1776
+ }));
1777
+ }
1778
+ updateFoldIndicators() {
1779
+ if (!this.editor || !this.foldingUI) return;
1780
+ const e = this.editor.getValue();
1781
+ if (e === this.lastSnapshot) return;
1782
+ this.lastSnapshot = e, this.foldingUI.innerHTML = "", this.foldIndicators = [];
1783
+ const t = e.split(`
1784
+ `), s = this.findFoldableLines(t), i = document.createDocumentFragment();
1785
+ s.forEach((n) => {
1786
+ const r = this.createFoldIndicator(n);
1787
+ i.appendChild(r), this.foldIndicators.push(r);
1788
+ }), this.foldingUI.appendChild(i);
1789
+ }
1790
+ findFoldableLines(e) {
1791
+ const t = [];
1792
+ for (let s = 0; s < e.length; s++) {
1793
+ const i = e[s].trim();
1794
+ (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);
1795
+ }
1796
+ return t;
1797
+ }
1798
+ createFoldIndicator(e) {
1799
+ const t = document.createElement("div");
1800
+ return t.style.cssText = `
1801
+ position: absolute;
1802
+ left: 0;
1803
+ top: ${e * 21}px;
1804
+ width: 20px;
1805
+ height: 21px;
1806
+ display: flex;
1807
+ align-items: center;
1808
+ justify-content: center;
1809
+ cursor: pointer;
1810
+ pointer-events: auto;
1811
+ color: var(--editor-gutter-foreground, #858585);
1812
+ font-size: 10px;
1813
+ user-select: none;
1814
+ `, t.innerHTML = "▶", t.title = "Code folding not yet implemented - click shows fold indicators", t.addEventListener("click", () => {
1815
+ }), t;
1816
+ }
1817
+ foldAtCursor() {
1818
+ }
1819
+ unfoldAtCursor() {
1820
+ }
1821
+ foldAll() {
1822
+ }
1823
+ unfoldAll() {
1824
+ }
1825
+ destroy() {
1826
+ this.pendingUpdateRaf !== null && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.changeHandler = null, this.lastSnapshot = "", this.foldingUI = null, this.foldIndicators = [], this.editor = null;
1827
+ }
1828
+ }
1829
+ class re {
1830
+ constructor() {
1831
+ this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
1832
+ }
1833
+ setup(e) {
1834
+ 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) });
1835
+ }
1836
+ // Extension provides methods that can be called by the editor
1837
+ setTheme(e) {
1838
+ this.currentTheme = e;
1839
+ }
1840
+ setLanguage(e) {
1841
+ this.currentLanguage = e;
1842
+ }
1843
+ registerMode(e, t) {
1844
+ this.modes.set(e.toLowerCase(), t);
1845
+ }
1846
+ // Method to get syntax highlighting colors for a given theme
1847
+ getSyntaxColors() {
1848
+ return this.currentTheme === "dark" ? {
1849
+ tag: "#569cd6",
1850
+ // Blue
1851
+ comment: "#6a9955",
1852
+ // Green
1853
+ attrName: "#9cdcfe",
1854
+ // Light blue for attribute names
1855
+ attrValue: "#ce9178",
1856
+ // Orange for attribute values
1857
+ styleProp: "#c586c0",
1858
+ // Purple for CSS property names
1859
+ styleVal: "#dcdcaa",
1860
+ // Yellow-ish for CSS values
1861
+ doctype: "#808080",
1862
+ // Gray for doctype
1863
+ text: "#d4d4d4",
1864
+ // Light gray for normal text
1865
+ keyword: "#c586c0",
1866
+ // JS/PHP keywords (purple)
1867
+ string: "#ce9178",
1868
+ // JS strings
1869
+ number: "#b5cea8",
1870
+ // numbers
1871
+ variable: "#9cdcfe"
1872
+ // php variable color
1873
+ } : {
1874
+ tag: "#0000ff",
1875
+ // Blue
1876
+ comment: "#008000",
1877
+ // Green
1878
+ attrName: "#001080",
1879
+ attrValue: "#a31515",
1880
+ // Red
1881
+ styleProp: "#6a00a8",
1882
+ styleVal: "#804000",
1883
+ doctype: "#444444",
1884
+ text: "#000000",
1885
+ // Black
1886
+ keyword: "#000080",
1887
+ string: "#a31515",
1888
+ number: "#0086b3",
1889
+ variable: "#001080"
1890
+ };
1891
+ }
1892
+ // Public API: highlight a source string using the chosen mode (or detect html)
1893
+ highlight(e, t) {
1894
+ const s = this.getSyntaxColors(), i = (t || this.currentLanguage || "html").toLowerCase();
1895
+ return (this.modes.get(i) || this.modes.get("html")).highlight(e, s);
1896
+ }
1897
+ // Backwards-compatible method
1898
+ highlightHTML(e) {
1899
+ return this.highlight(e, "html");
1900
+ }
1901
+ // --- Internal mode implementations ---
1902
+ escapeHTML(e) {
1903
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;");
1904
+ }
1905
+ // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
1906
+ unescapeEntitiesRepeated(e) {
1907
+ let t = e || "";
1908
+ for (let s = 0; s < 5; s++) {
1909
+ const i = t;
1910
+ if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === i) break;
1911
+ }
1912
+ return t;
1913
+ }
1914
+ _highlightHTML(e, t) {
1915
+ const s = t, i = (h) => this.escapeHTML(h);
1916
+ let n = i(e);
1917
+ const r = (h) => {
1918
+ let o = h.replace(/&quot;/g, '"').replace(/&#39;/g, "'");
1919
+ return o = o.replace(/(\/\*[\s\S]*?\*\/)/g, `<span style="color: ${s.comment};">$1</span>`), o = o.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g, (c, d, f, u, g) => {
1920
+ const p = String(u).trim(), y = i(p);
1921
+ return `<span style="color: ${s.styleProp};">${d}</span>${f}<span style="color: ${s.styleVal};">${y}</span>${g}`;
1922
+ }), o;
1923
+ }, l = [];
1924
+ try {
1925
+ e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (h, o, c) => (l.push({ attrs: String(o || ""), inner: String(c || "") }), h));
1926
+ } catch (h) {
1927
+ }
1928
+ let a = 0;
1929
+ return n = n.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (h, o, c, d, f) => {
1930
+ var p, y, C;
1931
+ const u = (y = (p = l[a++]) == null ? void 0 : p.inner) != null ? y : this.unescapeEntitiesRepeated(d || "");
1932
+ (((C = l[a - 1]) == null ? void 0 : C.attrs) || c || "").toLowerCase();
1933
+ const g = this._highlightJS(u, s);
1934
+ return `${o}${g}${f}`;
1935
+ }), n = n.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (h, o, c, d) => {
1936
+ const f = r(c);
1937
+ return `${o}${f}${d}`;
1938
+ }), n = n.replace(/(&lt;!--[\s\S]*?--&gt;)/g, `<span style="color: ${s.comment};">$1</span>`), n = n.replace(/(&lt;!DOCTYPE[\s\S]*?&gt;)/i, `<span style="color: ${s.doctype};">$1</span>`), n = n.replace(/(&lt;\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?&gt;)/g, (h, o, c, d, f) => {
1939
+ const u = `<span style="color: ${s.tag};">${c}</span>`;
1940
+ let g = d;
1941
+ return g = g.replace(
1942
+ /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
1943
+ (p, y, C, v) => {
1944
+ const S = String(y).toLowerCase(), E = `<span style="color: ${s.attrName};">${y}</span>`;
1945
+ let M = v, b = "";
1946
+ v.startsWith("&quot;") && v.endsWith("&quot;") ? (M = v.slice(6, -6), b = "&quot;") : v.startsWith("&#39;") && v.endsWith("&#39;") && (M = v.slice(5, -5), b = "&#39;");
1947
+ let T = v;
1948
+ if (S === "style") {
1949
+ const I = M.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (B, $, A, O) => `<span style="color: ${s.styleProp};">${$}</span>:<span style="color: ${s.styleVal};">${A.trim()}</span>${O}`);
1950
+ b ? T = `${b}${I}${b}` : T = I, T = `<span style="color: ${s.attrValue};">${T}</span>`;
1951
+ } else
1952
+ b && (T = `${b}${M}${b}`), T = `<span style="color: ${s.attrValue};">${T}</span>`;
1953
+ return `${E}${C}${T}`;
1954
+ }
1955
+ ), `${o}${u}${g}${f}`;
1956
+ }), n;
1957
+ }
1958
+ _highlightJS(e, t) {
1959
+ const s = this.unescapeEntitiesRepeated(e);
1960
+ this.escapeHTML(s);
1961
+ const i = [], n = (d) => {
1962
+ let f = "", u = d;
1963
+ do
1964
+ f = String.fromCharCode(97 + u % 26) + f, u = Math.floor(u / 26) - 1;
1965
+ while (u >= 0);
1966
+ return f || "a";
1967
+ }, r = (d) => `\0${n(d)}\0`, l = (d) => {
1968
+ const f = i.length;
1969
+ return i.push(d), r(f);
1970
+ };
1971
+ let a;
1972
+ const h = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
1973
+ let o = 0, c = "";
1974
+ for (; a = h.exec(s); ) {
1975
+ const d = a.index;
1976
+ o < d && (c += this.escapeHTML(s.slice(o, d)));
1977
+ const f = a[0];
1978
+ /^\/\*/.test(f) || /^\/\//.test(f) ? c += l(`<span style="color: ${t.comment};">${this.escapeHTML(f)}</span>`) : c += l(`<span style="color: ${t.string};">${this.escapeHTML(f)}</span>`), o = h.lastIndex;
1979
+ }
1980
+ return o < s.length && (c += this.escapeHTML(s.slice(o))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (d, f, u) => {
1981
+ const g = c[u - 1] || "", p = c[u + d.length] || "";
1982
+ return g === "&" || g === "#" || p === ";" || p === "#" ? d : `<span style="color: ${t.number};">${d}</span>`;
1983
+ }), c = c.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), c.replace(/\u0000([a-z]+)\u0000/g, (d, f) => {
1984
+ let u = 0;
1985
+ for (let g = 0; g < f.length; g++)
1986
+ u = u * 26 + (f.charCodeAt(g) - 97 + 1);
1987
+ return u = u - 1, i[u] || "";
1988
+ });
1989
+ }
1990
+ _highlightPHP(e, t) {
1991
+ const s = this.unescapeEntitiesRepeated(e);
1992
+ let i = this.escapeHTML(s);
1993
+ const n = [], r = (u) => {
1994
+ let g = "", p = u;
1995
+ do
1996
+ g = String.fromCharCode(97 + p % 26) + g, p = Math.floor(p / 26) - 1;
1997
+ while (p >= 0);
1998
+ return g || "a";
1999
+ }, l = (u) => {
2000
+ const g = n.length;
2001
+ return n.push(u), `\0${r(g)}\0`;
2002
+ }, a = (u, g) => {
2003
+ const p = i.indexOf(u);
2004
+ return p === -1 ? !1 : (i = i.slice(0, p) + g + i.slice(p + u.length), !0);
2005
+ };
2006
+ let h;
2007
+ const o = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, f = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
2008
+ for (; h = o.exec(s); ) {
2009
+ const u = h[0];
2010
+ a(this.escapeHTML(u), l(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2011
+ }
2012
+ for (; h = c.exec(s); ) {
2013
+ const u = h[0];
2014
+ a(this.escapeHTML(u), l(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2015
+ }
2016
+ for (; h = d.exec(s); ) {
2017
+ const u = h[0];
2018
+ a(this.escapeHTML(u), l(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
2019
+ }
2020
+ for (; h = f.exec(s); ) {
2021
+ const u = h[0];
2022
+ a(this.escapeHTML(u), l(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
2023
+ }
2024
+ 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, (u, g) => {
2025
+ let p = 0;
2026
+ for (let y = 0; y < g.length; y++)
2027
+ p = p * 26 + (g.charCodeAt(y) - 97 + 1);
2028
+ return p = p - 1, n[p] || "";
2029
+ }), i;
2030
+ }
2031
+ // Method to check if content contains syntax that should be highlighted
2032
+ shouldHighlight(e) {
2033
+ return /<\/?[\w:-]+|<!--/.test(e);
2034
+ }
2035
+ destroy() {
2036
+ this.editor = null, this.modes.clear();
2037
+ }
2038
+ }
2039
+ function oe(w, e) {
2040
+ const t = { ...e };
2041
+ return t.extensions || (t.extensions = []), t.extensions.some((s) => s.name === "keymap") || t.extensions.unshift(new J(t.keymap)), t.extensions.some((s) => s.name === "transaction") || t.extensions.unshift(new Y()), new X(w, t);
2042
+ }
2043
+ const P = '[data-theme="dark"], .dark, .editora-theme-dark', le = `/* Source Editor Dialog Styles */
2044
+ .rte-source-editor-overlay {
2045
+ position: fixed !important;
2046
+ top: 0 !important;
2047
+ left: 0 !important;
2048
+ right: 0 !important;
2049
+ bottom: 0 !important;
2050
+ width: 100vw !important;
2051
+ height: 100vh !important;
2052
+ background-color: rgba(0, 0, 0, 0.6) !important;
2053
+ display: flex !important;
2054
+ align-items: center !important;
2055
+ justify-content: center !important;
2056
+ z-index: 10000 !important;
2057
+ padding: 20px !important;
2058
+ box-sizing: border-box !important;
2059
+ margin: 0 !important;
2060
+ }
2061
+
2062
+ .rte-source-editor-overlay.fullscreen {
2063
+ padding: 0 !important;
2064
+ }
2065
+
2066
+ .rte-source-editor-modal {
2067
+ background: white;
2068
+ border-radius: 8px;
2069
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
2070
+ width: 100%;
2071
+ max-width: 1200px;
2072
+ max-height: 90vh;
2073
+ display: flex;
2074
+ flex-direction: column;
2075
+ overflow: hidden;
2076
+ position: relative;
2077
+ }
2078
+
2079
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
2080
+ border-radius: 0;
2081
+ max-width: 100%;
2082
+ max-height: 100vh;
2083
+ width: 100%;
2084
+ height: 100vh;
2085
+ }
2086
+
2087
+ .rte-source-editor-header {
2088
+ display: flex;
2089
+ align-items: center;
2090
+ justify-content: space-between;
2091
+ padding: 16px 20px;
2092
+ border-bottom: 1px solid #e1e5e9;
2093
+ background: #f8f9fa;
2094
+ border-radius: 8px 8px 0 0;
2095
+ }
2096
+
2097
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-header {
2098
+ border-radius: 0;
2099
+ }
2100
+
2101
+ .rte-source-editor-header h2 {
2102
+ margin: 0;
2103
+ font-size: 18px;
2104
+ font-weight: 600;
2105
+ color: #1a1a1a;
2106
+ }
2107
+
2108
+ .rte-source-editor-header-toolbar {
2109
+ display: flex;
2110
+ gap: 8px;
2111
+ margin-left: auto;
2112
+ margin-right: 16px;
2113
+ }
2114
+
2115
+ .rte-source-editor-toolbar-btn {
2116
+ background: none;
2117
+ border: none;
2118
+ cursor: pointer;
2119
+ padding: 6px;
2120
+ border-radius: 4px;
2121
+ font-size: 16px;
2122
+ line-height: 1;
2123
+ transition: all 0.2s ease;
2124
+ color: #666;
2125
+ }
2126
+
2127
+ .rte-source-editor-toolbar-btn:hover:not(:disabled) {
2128
+ background: #e1e5e9;
2129
+ color: #1a1a1a;
2130
+ }
2131
+
2132
+ .rte-source-editor-toolbar-btn:disabled {
2133
+ opacity: 0.5;
2134
+ cursor: not-allowed;
2135
+ }
2136
+
2137
+ .rte-source-editor-toolbar-btn.active {
2138
+ background: #007acc;
2139
+ color: white;
2140
+ }
2141
+
2142
+ .rte-source-editor-toolbar-btn.active:hover {
2143
+ background: #0056b3;
2144
+ }
2145
+
2146
+ .rte-source-editor-header-actions {
2147
+ display: flex;
2148
+ gap: 8px;
2149
+ }
2150
+
2151
+ .rte-source-editor-fullscreen-btn,
2152
+ .rte-source-editor-close-btn {
2153
+ background: none;
2154
+ border: none;
2155
+ cursor: pointer;
2156
+ padding: 4px;
2157
+ border-radius: 4px;
2158
+ color: #666;
2159
+ font-size: 16px;
2160
+ line-height: 1;
2161
+ transition: all 0.2s ease;
2162
+ }
2163
+
2164
+ .rte-source-editor-fullscreen-btn:hover,
2165
+ .rte-source-editor-close-btn:hover {
2166
+ background: #e1e5e9;
2167
+ color: #1a1a1a;
2168
+ }
2169
+
2170
+ .rte-source-editor-body {
2171
+ flex: 1;
2172
+ overflow: hidden;
2173
+ display: flex;
2174
+ flex-direction: column;
2175
+ }
2176
+
2177
+ .rte-source-editor-loading {
2178
+ display: flex;
2179
+ flex-direction: column;
2180
+ align-items: center;
2181
+ justify-content: center;
2182
+ padding: 40px;
2183
+ color: #666;
2184
+ position: absolute;
2185
+ z-index: 9;
2186
+ margin: 0 auto;
2187
+ width: 100%;
2188
+ top: 44%;
2189
+ }
2190
+
2191
+ .rte-source-editor-spinner {
2192
+ width: 32px;
2193
+ height: 32px;
2194
+ border: 3px solid #e1e5e9;
2195
+ border-top: 3px solid #007acc;
2196
+ border-radius: 50%;
2197
+ animation: spin 1s linear infinite;
2198
+ margin-bottom: 16px;
2199
+ }
2200
+
2201
+ @keyframes spin {
2202
+ 0% { transform: rotate(0deg); }
2203
+ 100% { transform: rotate(360deg); }
2204
+ }
2205
+
2206
+ .rte-source-editor-error {
2207
+ background: #fee;
2208
+ color: #c53030;
2209
+ padding: 12px 16px;
2210
+ border-left: 4px solid #c53030;
2211
+ margin: 16px;
2212
+ border-radius: 4px;
2213
+ font-size: 14px;
2214
+ }
2215
+
2216
+ .rte-source-editor-content {
2217
+ flex: 1;
2218
+ display: flex;
2219
+ flex-direction: column;
2220
+ overflow: hidden;
2221
+ }
2222
+
2223
+ .rte-source-editor-warning {
2224
+ background: #fefcbf;
2225
+ color: #744210;
2226
+ padding: 8px 16px;
2227
+ font-size: 12px;
2228
+ font-weight: 500;
2229
+ border-bottom: 1px solid #f6e05e;
2230
+ }
2231
+
2232
+ .rte-source-editor-codemirror {
2233
+ flex: 1;
2234
+ overflow: auto;
2235
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
2236
+ font-size: 14px;
2237
+ line-height: 1.5;
2238
+ }
2239
+
2240
+ .rte-source-editor-codemirror .cm-editor {
2241
+ height: 100%;
2242
+ }
2243
+
2244
+ .rte-source-editor-codemirror .cm-focused {
2245
+ outline: none;
2246
+ }
2247
+
2248
+ .rte-source-editor-footer {
2249
+ display: flex;
2250
+ align-items: center;
2251
+ justify-content: space-between;
2252
+ padding: 16px 20px;
2253
+ border-top: 1px solid #e1e5e9;
2254
+ background: #f8f9fa;
2255
+ border-radius: 0 0 8px 8px;
2256
+ }
2257
+
2258
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
2259
+ border-radius: 0;
2260
+ }
2261
+
2262
+ .rte-source-editor-footer-info {
2263
+ font-size: 12px;
2264
+ color: #666;
2265
+ }
2266
+
2267
+ .unsaved-changes {
2268
+ color: #d69e2e;
2269
+ font-weight: 500;
2270
+ }
2271
+
2272
+ .rte-source-editor-footer-actions {
2273
+ display: flex;
2274
+ gap: 12px;
2275
+ }
2276
+
2277
+ .rte-source-editor-btn {
2278
+ padding: 8px 16px;
2279
+ border-radius: 4px;
2280
+ font-size: 14px;
2281
+ font-weight: 500;
2282
+ cursor: pointer;
2283
+ border: 1px solid transparent;
2284
+ transition: all 0.2s ease;
2285
+ }
2286
+
2287
+ .rte-source-editor-btn:disabled {
2288
+ opacity: 0.6;
2289
+ cursor: not-allowed;
2290
+ }
2291
+
2292
+ .rte-source-editor-btn-cancel {
2293
+ background: white;
2294
+ border-color: #d1d5db;
2295
+ color: #374151;
2296
+ }
2297
+
2298
+ .rte-source-editor-btn-cancel:hover:not(:disabled) {
2299
+ background: #f9fafb;
2300
+ border-color: #9ca3af;
2301
+ }
2302
+
2303
+ .rte-source-editor-btn-save {
2304
+ background: #007acc;
2305
+ color: white;
2306
+ }
2307
+
2308
+ .rte-source-editor-btn-save:hover:not(:disabled) {
2309
+ background: #0056b3;
2310
+ }
2311
+
2312
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
2313
+ background: #1e1e1e;
2314
+ color: #f8f9fa;
2315
+ border: 1px solid #434d5f;
2316
+ }
2317
+
2318
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
2319
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
2320
+ background: #2a3442;
2321
+ border-color: #434d5f;
2322
+ }
2323
+
2324
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
2325
+ color: #f8f9fa;
2326
+ }
2327
+
2328
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
2329
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
2330
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
2331
+ color: #c1cede;
2332
+ }
2333
+
2334
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
2335
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
2336
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
2337
+ background: #404a5a;
2338
+ color: #f8fafc;
2339
+ }
2340
+
2341
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
2342
+ background: #3b82f6;
2343
+ color: #ffffff;
2344
+ }
2345
+
2346
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
2347
+ background: #2563eb;
2348
+ }
2349
+
2350
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
2351
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
2352
+ color: #cbd5e1;
2353
+ }
2354
+
2355
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
2356
+ border-color: #3f4b60;
2357
+ border-top-color: #58a6ff;
2358
+ }
2359
+
2360
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
2361
+ background: #3f2124;
2362
+ color: #fecaca;
2363
+ border-color: #ef4444;
2364
+ }
2365
+
2366
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
2367
+ background: #3b3220;
2368
+ color: #fde68a;
2369
+ border-color: #f59e0b;
2370
+ }
2371
+
2372
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
2373
+ background: #334155;
2374
+ border-color: #475569;
2375
+ color: #f1f5f9;
2376
+ }
2377
+
2378
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
2379
+ background: #475569;
2380
+ border-color: #64748b;
2381
+ }
2382
+
2383
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
2384
+ background: #3b82f6;
2385
+ }
2386
+
2387
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
2388
+ background: #2563eb;
2389
+ }
2390
+
2391
+ /* Responsive design */
2392
+ @media (max-width: 768px) {
2393
+ .rte-source-editor-overlay {
2394
+ padding: 10px;
2395
+ }
2396
+
2397
+ .rte-source-editor-modal {
2398
+ max-height: 95vh;
2399
+ }
2400
+
2401
+ .rte-source-editor-header {
2402
+ padding: 12px 16px;
2403
+ }
2404
+
2405
+ .rte-source-editor-footer {
2406
+ padding: 12px 16px;
2407
+ flex-direction: column;
2408
+ gap: 12px;
2409
+ align-items: stretch;
2410
+ }
2411
+
2412
+ .rte-source-editor-footer-actions {
2413
+ justify-content: stretch;
2414
+ }
2415
+
2416
+ .rte-source-editor-btn {
2417
+ flex: 1;
2418
+ text-align: center;
2419
+ }
2420
+ }`, ae = () => ({
2421
+ name: "code",
2422
+ // Toolbar button configuration
2423
+ toolbar: [
2424
+ {
2425
+ label: "Source",
2426
+ command: "toggleSourceView",
2427
+ // type: "button",
2428
+ 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>',
2429
+ shortcut: "Mod-Shift-S"
2430
+ }
2431
+ ],
2432
+ // Native command implementations
2433
+ commands: {
2434
+ /**
2435
+ * Toggle HTML source view
2436
+ * Opens a dialog to edit raw HTML
2437
+ */
2438
+ toggleSourceView: () => {
2439
+ const e = (() => {
2440
+ var l, a, h;
2441
+ const n = window.getSelection();
2442
+ if (n && n.anchorNode) {
2443
+ let o = n.anchorNode instanceof HTMLElement ? n.anchorNode : n.anchorNode.parentElement;
2444
+ for (; o; ) {
2445
+ if ((l = o.classList) != null && l.contains("rte-content"))
2446
+ return o;
2447
+ o = o.parentElement;
2448
+ }
2449
+ }
2450
+ if (document.activeElement) {
2451
+ let o = document.activeElement;
2452
+ if ((a = o.classList) != null && a.contains("rte-content"))
2453
+ return o;
2454
+ for (; o && o !== document.body; ) {
2455
+ if ((h = o.classList) != null && h.contains("rte-content"))
2456
+ return o;
2457
+ const c = o.querySelector(
2458
+ ".rte-content"
2459
+ );
2460
+ if (c) return c;
2461
+ o = o.parentElement;
2462
+ }
2463
+ }
2464
+ const r = document.querySelector("[data-editora-editor]");
2465
+ if (r) {
2466
+ const o = r.querySelector(
2467
+ ".rte-content"
2468
+ );
2469
+ if (o) return o;
2470
+ }
2471
+ return document.querySelector(".rte-content");
2472
+ })();
2473
+ if (!e)
2474
+ return console.error("[CodePlugin] Editor content area not found"), alert(
2475
+ "Editor content area not found. Please click inside the editor first."
2476
+ ), !1;
2477
+ const t = e.innerHTML, s = (n) => {
2478
+ let r = "", l = 0;
2479
+ const a = 2, h = n.split(/(<\/?[a-zA-Z][^>]*>)/);
2480
+ for (const o of h)
2481
+ o.trim() && (o.match(/^<\/[a-zA-Z]/) ? (l = Math.max(0, l - 1), r += `
2482
+ ` + " ".repeat(l * a) + o) : o.match(/^<[a-zA-Z]/) && !o.match(/\/>$/) ? (r += `
2483
+ ` + " ".repeat(l * a) + o, l++) : o.match(/^<[a-zA-Z].*\/>$/) ? r += `
2484
+ ` + " ".repeat(l * a) + o : r += o.trim());
2485
+ return r.trim();
2486
+ };
2487
+ return (() => {
2488
+ const r = s(t);
2489
+ let l = null, a = "dark", h = !1, o = !1, c = !1, d = !1;
2490
+ const f = !!e.closest(P) || document.body.matches(P) || document.documentElement.matches(P), u = document.createElement("div");
2491
+ u.className = "rte-source-editor-overlay", f && u.classList.add("rte-theme-dark");
2492
+ const g = document.createElement("div");
2493
+ g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
2494
+ const p = document.createElement("div");
2495
+ p.className = "rte-source-editor-header", p.innerHTML = `
2496
+ <h2 id="source-editor-title">Source Editor</h2>
2497
+ <div class="rte-source-editor-header-toolbar">
2498
+ <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
2499
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2500
+ <circle cx="12" cy="12" r="5"/>
2501
+ <line x1="12" y1="1" x2="12" y2="3"/>
2502
+ <line x1="12" y1="21" x2="12" y2="23"/>
2503
+ <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
2504
+ <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
2505
+ <line x1="1" y1="12" x2="3" y2="12"/>
2506
+ <line x1="21" y1="12" x2="23" y2="12"/>
2507
+ <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
2508
+ <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
2509
+ </svg>
2510
+ </button>
2511
+ <button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
2512
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2513
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2514
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2515
+ </svg>
2516
+ </button>
2517
+ </div>
2518
+ <div class="rte-source-editor-header-actions">
2519
+ <button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
2520
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2521
+ <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2522
+ </svg>
2523
+ </button>
2524
+ <button class="rte-source-editor-close-btn" aria-label="Close source editor">
2525
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2526
+ <line x1="18" y1="6" x2="6" y2="18"/>
2527
+ <line x1="6" y1="6" x2="18" y2="18"/>
2528
+ </svg>
2529
+ </button>
2530
+ </div>
2531
+ `;
2532
+ const y = document.createElement("div");
2533
+ y.className = "rte-source-editor-body";
2534
+ const C = document.createElement("div");
2535
+ C.className = "rte-source-editor-content";
2536
+ const v = document.createElement("div");
2537
+ v.className = "rte-source-editor-warning", v.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
2538
+ const S = document.createElement("div");
2539
+ S.className = "rte-source-editor-light-editor", S.style.height = "400px", C.appendChild(v), C.appendChild(S), y.appendChild(C);
2540
+ const E = document.createElement("div");
2541
+ if (E.className = "rte-source-editor-footer", E.innerHTML = `
2542
+ <div class="rte-source-editor-footer-info">
2543
+ <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
2544
+ </div>
2545
+ <div class="rte-source-editor-footer-actions">
2546
+ <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
2547
+ <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
2548
+ </div>
2549
+ `, g.appendChild(p), g.appendChild(y), g.appendChild(E), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
2550
+ const x = document.createElement("style");
2551
+ x.id = "rte-source-editor-styles", x.textContent = le, document.head.appendChild(x);
2552
+ }
2553
+ const M = p.querySelector(
2554
+ ".theme-toggle-btn"
2555
+ ), b = p.querySelector(
2556
+ ".readonly-toggle-btn"
2557
+ ), T = p.querySelector(
2558
+ ".rte-source-editor-fullscreen-btn"
2559
+ ), I = p.querySelector(
2560
+ ".rte-source-editor-close-btn"
2561
+ ), B = E.querySelector(
2562
+ ".rte-source-editor-btn-cancel"
2563
+ ), $ = E.querySelector(
2564
+ ".rte-source-editor-btn-save"
2565
+ ), A = E.querySelector(
2566
+ ".unsaved-changes"
2567
+ ), O = [], R = (x, k, V, N) => {
2568
+ x.addEventListener(k, V, N), O.push(
2569
+ () => x.removeEventListener(k, V, N)
2570
+ );
2571
+ }, U = (x) => {
2572
+ c !== x && (c = x, A && (A.style.display = c ? "inline" : "none"));
2573
+ }, H = () => {
2574
+ if (!d) {
2575
+ for (d = !0; O.length; ) {
2576
+ const x = O.pop();
2577
+ x == null || x();
2578
+ }
2579
+ l && (l.destroy(), l = null), u.isConnected && u.remove();
2580
+ }
2581
+ }, K = () => {
2582
+ a = a === "dark" ? "light" : "dark", l == null || l.setTheme(a), M && (M.innerHTML = a === "light" ? `
2583
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2584
+ <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
2585
+ </svg>
2586
+ ` : `
2587
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2588
+ <circle cx="12" cy="12" r="5"/>
2589
+ <line x1="12" y1="1" x2="12" y2="3"/>
2590
+ <line x1="12" y1="21" x2="12" y2="23"/>
2591
+ <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
2592
+ <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
2593
+ <line x1="1" y1="12" x2="3" y2="12"/>
2594
+ <line x1="21" y1="12" x2="23" y2="12"/>
2595
+ <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
2596
+ <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
2597
+ </svg>
2598
+ `);
2599
+ }, z = () => {
2600
+ h = !h, l == null || l.setReadOnly(h), b && (b.classList.toggle("active", h), b.innerHTML = h ? `
2601
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2602
+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
2603
+ <circle cx="12" cy="16" r="1"/>
2604
+ <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
2605
+ </svg>
2606
+ ` : `
2607
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2608
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
2609
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
2610
+ </svg>
2611
+ `);
2612
+ }, q = () => {
2613
+ o = !o, u.classList.toggle("fullscreen", o), S.style.height = o ? "calc(100vh - 200px)" : "400px", T && (T.innerHTML = o ? `
2614
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2615
+ <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"/>
2616
+ </svg>
2617
+ ` : `
2618
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
2619
+ <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
2620
+ </svg>
2621
+ `);
2622
+ }, Q = () => {
2623
+ c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
2624
+ }, j = () => {
2625
+ try {
2626
+ const x = (l == null ? void 0 : l.getValue()) || "", k = document.createElement("div");
2627
+ k.innerHTML = x, k.querySelectorAll(
2628
+ 'script, iframe[src^="javascript:"], object, embed'
2629
+ ).forEach((N) => N.remove()), e.innerHTML = k.innerHTML;
2630
+ try {
2631
+ e.dispatchEvent(
2632
+ new InputEvent("input", {
2633
+ bubbles: !0,
2634
+ cancelable: !1,
2635
+ inputType: "insertReplacementText"
2636
+ })
2637
+ );
2638
+ } catch (N) {
2639
+ e.dispatchEvent(
2640
+ new Event("input", { bubbles: !0 })
2641
+ );
2642
+ }
2643
+ e.dispatchEvent(
2644
+ new Event("change", { bubbles: !0 })
2645
+ ), U(!1), H();
2646
+ } catch (x) {
2647
+ alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", x);
2648
+ }
2649
+ };
2650
+ M && R(M, "click", K), b && R(b, "click", z), T && R(T, "click", q), I && R(I, "click", H), B && R(B, "click", Q), $ && R($, "click", j), R(u, "click", (x) => {
2651
+ x.target === u && H();
2652
+ }), R(document, "keydown", (x) => {
2653
+ const k = x;
2654
+ k.key === "Escape" && (k.preventDefault(), H());
2655
+ }), document.body.appendChild(u), requestAnimationFrame(() => {
2656
+ if (!(d || !u.isConnected))
2657
+ try {
2658
+ l = oe(S, {
2659
+ value: r,
2660
+ theme: "dark",
2661
+ readOnly: !1,
2662
+ extensions: [
2663
+ new G(),
2664
+ new _(),
2665
+ new ee(),
2666
+ new ie(),
2667
+ new se(),
2668
+ new ne(),
2669
+ new re()
2670
+ ]
2671
+ }), l.on("change", () => {
2672
+ const x = (l == null ? void 0 : l.getValue()) || "";
2673
+ U(x !== r);
2674
+ }), requestAnimationFrame(() => l == null ? void 0 : l.focus());
2675
+ } catch (x) {
2676
+ console.error("Failed to initialize code editor:", x);
2677
+ }
2678
+ });
2679
+ })(), !0;
2680
+ }
2681
+ },
2682
+ // Keyboard shortcuts
2683
+ keymap: {
2684
+ "Mod-Shift-s": "toggleSourceView",
2685
+ "Mod-Shift-S": "toggleSourceView"
2686
+ }
2687
+ });
2688
+ export {
2689
+ ae as CodePlugin
2690
+ };
2691
+ //# sourceMappingURL=CodePlugin.native-DlpTPdkd.mjs.map