@editora/core 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/dist/{A11yCheckerPlugin.native-58d12bed.mjs → A11yCheckerPlugin.native-BRdGYMju.mjs} +12 -23
  3. package/dist/{AnchorPlugin.native-289a112a.mjs → AnchorPlugin.native-BcYGEtd9.mjs} +102 -112
  4. package/dist/{ApprovalWorkflowPlugin.native-449ce66c.mjs → ApprovalWorkflowPlugin.native-BZ6jO-Wj.mjs} +173 -209
  5. package/dist/{BackgroundColorPlugin.native-8aceb5cc.mjs → BackgroundColorPlugin.native-50iAT9xU.mjs} +9 -16
  6. package/dist/BlockquotePlugin.native-57_Xcjl1.mjs +212 -0
  7. package/dist/{BlocksLibraryPlugin.native-1cc51e63.mjs → BlocksLibraryPlugin.native-5sdsXsiE.mjs} +149 -205
  8. package/dist/{BoldPlugin.native-f9d7f8e4.mjs → BoldPlugin.native-CSh_LiIJ.mjs} +11 -7
  9. package/dist/CapitalizationPlugin.native-DLV4oPmB.mjs +159 -0
  10. package/dist/ChecklistPlugin.native-BS-kMz9O.mjs +371 -0
  11. package/dist/{CitationsPlugin.native-169fb1e8.mjs → CitationsPlugin.native-DQgoCd1B.mjs} +196 -261
  12. package/dist/ClearFormattingPlugin.native-DIS6AN2t.mjs +172 -0
  13. package/dist/CodePlugin.native-C5l1IeSS.mjs +4570 -0
  14. package/dist/{CodeSamplePlugin.native-6cc0148e.mjs → CodeSamplePlugin.native-CgGoH-X4.mjs} +10 -19
  15. package/dist/{CommentsPlugin.native-03659874.mjs → CommentsPlugin.native-DPSqTkiv.mjs} +28 -55
  16. package/dist/{ConditionalContentPlugin.native-4983143a.mjs → ConditionalContentPlugin.native-CfhY46rU.mjs} +51 -108
  17. package/dist/{ContentRulesPlugin.native-63ed405b.mjs → ContentRulesPlugin.native-vPx5nC73.mjs} +153 -200
  18. package/dist/{DataBindingPlugin.native-427e9d75.mjs → DataBindingPlugin.native-BoXwghTz.mjs} +88 -124
  19. package/dist/DirectionPlugin.native-Bl-QLFzO.mjs +153 -0
  20. package/dist/{DocSchemaPlugin.native-8e41eda0.mjs → DocSchemaPlugin.native-DUSVRHqT.mjs} +112 -166
  21. package/dist/{DocumentManagerPlugin.native-e69895ad.mjs → DocumentManagerPlugin.native-C2cs_1w4.mjs} +4 -4
  22. package/dist/EmbedIframePlugin.native-BF_-LjTq.mjs +740 -0
  23. package/dist/{EmojisPlugin.native-65c5ac47.mjs → EmojisPlugin.native-CitxxlWX.mjs} +6 -11
  24. package/dist/{FontFamilyPlugin.native-f9bc255a.mjs → FontFamilyPlugin.native-j8hMTbg4.mjs} +4 -7
  25. package/dist/{FontSizePlugin.native-f5647872.mjs → FontSizePlugin.native-B_jCh7dY.mjs} +10 -19
  26. package/dist/{FootnotePlugin.native-494657b3.mjs → FootnotePlugin.native-D730OGRm.mjs} +39 -77
  27. package/dist/{FullscreenPlugin.native-87ce92e9.mjs → FullscreenPlugin.native-ChXyxeNw.mjs} +1 -1
  28. package/dist/HeadingPlugin.native-DZdvubrQ.mjs +249 -0
  29. package/dist/{HistoryPlugin.native-92ed4be4.mjs → HistoryPlugin.native-D2wl32jV.mjs} +107 -143
  30. package/dist/{IndentPlugin.native-e4ee902b.mjs → IndentPlugin.native-BHixp8sP.mjs} +12 -23
  31. package/dist/{ItalicPlugin.native-7c95cfbc.mjs → ItalicPlugin.native-CmnlwFHB.mjs} +15 -11
  32. package/dist/{LineHeightPlugin.native-5668f78c.mjs → LineHeightPlugin.native-CM7iXdQj.mjs} +10 -19
  33. package/dist/{LinkPlugin.native-6df29111.mjs → LinkPlugin.native-DYCIcdTm.mjs} +5 -9
  34. package/dist/{ListPlugin.native-fe2e115a.mjs → ListPlugin.native-V7EZC1lM.mjs} +5 -9
  35. package/dist/MathPlugin.native-NwWPHVmj.mjs +369 -0
  36. package/dist/{MediaManagerPlugin.native-3cf48a00.mjs → MediaManagerPlugin.native-eOsTJFpw.mjs} +11 -21
  37. package/dist/{MentionPlugin.native-3b1e8c05.mjs → MentionPlugin.native-BMDlOqur.mjs} +45 -89
  38. package/dist/MergeTagPlugin.native-BzRVoD9-.mjs +580 -0
  39. package/dist/{PIIRedactionPlugin.native-7ab10b9f.mjs → PIIRedactionPlugin.native-g7j4jOmm.mjs} +210 -260
  40. package/dist/{PageBreakPlugin.native-1794c5fb.mjs → PageBreakPlugin.native-DijGuHJZ.mjs} +16 -31
  41. package/dist/{PreviewPlugin.native-f7b67cc0.mjs → PreviewPlugin.native-WuIwOAOR.mjs} +6 -11
  42. package/dist/{PrintPlugin.native-f6a168c2.mjs → PrintPlugin.native-7qt5v7L5.mjs} +3 -5
  43. package/dist/{SlashCommandsPlugin.native-8d45e511.mjs → SlashCommandsPlugin.native-BiN6ODw5.mjs} +36 -71
  44. package/dist/{SmartPastePlugin.native-a6c5efec.mjs → SmartPastePlugin.native-CZAEHkyt.mjs} +173 -219
  45. package/dist/{SpecialCharactersPlugin.native-7f06d4ba.mjs → SpecialCharactersPlugin.native-DaG4b19I.mjs} +101 -85
  46. package/dist/{SpellCheckPlugin.native-04e20834.mjs → SpellCheckPlugin.native-BZB9AewP.mjs} +21 -41
  47. package/dist/{StrikethroughPlugin.native-905e9501.mjs → StrikethroughPlugin.native-V0TL4F48.mjs} +12 -30
  48. package/dist/{TablePlugin.native-7d5458c1.mjs → TablePlugin.native-DrHX-efe.mjs} +30 -58
  49. package/dist/TemplatePlugin.native-DLjFUaPW.mjs +1150 -0
  50. package/dist/{TextAlignmentPlugin.native-9357b3ed.mjs → TextAlignmentPlugin.native-sM_1s00t.mjs} +6 -11
  51. package/dist/{TextColorPlugin.native-d53ed459.mjs → TextColorPlugin.native-Bwl_bSmc.mjs} +14 -26
  52. package/dist/{TrackChangesPlugin.native-e96da509.mjs → TrackChangesPlugin.native-Bghu2q4a.mjs} +58 -115
  53. package/dist/{TranslationWorkflowPlugin.native-4e711b1e.mjs → TranslationWorkflowPlugin.native-DdF16tgT.mjs} +191 -257
  54. package/dist/{UnderlinePlugin.native-8080c998.mjs → UnderlinePlugin.native-DZzg23rv.mjs} +8 -4
  55. package/dist/{VersionDiffPlugin.native-5bbeff85.mjs → VersionDiffPlugin.native-Bvxgy--t.mjs} +26 -51
  56. package/dist/_commonjsHelpers-DOllISpa.mjs +32 -0
  57. package/dist/{anchoredPopover-5cca53ba.mjs → anchoredPopover-Bxds0VoB.mjs} +1 -1
  58. package/dist/core.css +1 -0
  59. package/dist/documentManager-vQ1VkbUY.mjs +8418 -0
  60. package/dist/{editorContainerHelpers-69585c07.mjs → editorContainerHelpers-C7kdWnS0.mjs} +2 -3
  61. package/dist/editora.min.js +13 -14
  62. package/dist/editora.umd.js +13 -14
  63. package/dist/{html2canvas.esm-c51cb3b9.mjs → html2canvas.esm-AYkPY5LS.mjs} +894 -978
  64. package/dist/index-BslAFzmv.mjs +16544 -0
  65. package/dist/index-CPMGUZfB.js +10 -0
  66. package/dist/{index-7da30697.mjs → index-DBoj6QfW.mjs} +127 -164
  67. package/dist/index.cjs.js +1 -1
  68. package/dist/index.es-BYD2KEo6.mjs +6666 -0
  69. package/dist/index.esm.js +7 -12
  70. package/dist/inlineFormatting-DJ0-NZtx.mjs +97 -0
  71. package/dist/{jspdf.es.min-780c82db.mjs → jspdf.es.min-BJGtOnRT.mjs} +3784 -4808
  72. package/dist/plugin-loader.js +67 -67
  73. package/dist/{purify.es-3bdbcfc5.mjs → purify.es-CKpwg8Tk.mjs} +10 -20
  74. package/dist/webcomponent-core.js +131 -168
  75. package/dist/webcomponent-core.min.css +1 -1
  76. package/dist/webcomponent-core.min.js +139 -63
  77. package/dist/webcomponent.cjs.js +1 -1
  78. package/dist/webcomponent.esm.js +1 -1
  79. package/dist/webcomponent.js +191 -228
  80. package/dist/webcomponent.min.css +1 -1
  81. package/dist/webcomponent.min.js +1240 -1344
  82. package/package.json +1 -1
  83. package/dist/BlockquotePlugin.native-3541c714.mjs +0 -49
  84. package/dist/CapitalizationPlugin.native-42c135dc.mjs +0 -80
  85. package/dist/ChecklistPlugin.native-3b397ee9.mjs +0 -330
  86. package/dist/ClearFormattingPlugin.native-77baa514.mjs +0 -145
  87. package/dist/CodePlugin.native-989cf0aa.mjs +0 -2740
  88. package/dist/DirectionPlugin.native-4e742f42.mjs +0 -139
  89. package/dist/EmbedIframePlugin.native-55209c87.mjs +0 -568
  90. package/dist/HeadingPlugin.native-e38c4a16.mjs +0 -64
  91. package/dist/MathPlugin.native-735bbac2.mjs +0 -296
  92. package/dist/MergeTagPlugin.native-31cf7d48.mjs +0 -584
  93. package/dist/TemplatePlugin.native-580f0f63.mjs +0 -617
  94. package/dist/_commonjsHelpers-69d58be2.mjs +0 -31
  95. package/dist/documentManager-8327fb6e.mjs +0 -9166
  96. package/dist/index-072ef022.js +0 -11
  97. package/dist/index-49d31221.mjs +0 -16860
  98. package/dist/index.es-b47a189f.mjs +0 -5782
  99. package/dist/style.css +0 -1
@@ -0,0 +1,4570 @@
1
+ class z {
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 i = e.start.line + 1; i < e.end.line; i++)
34
+ t.push(this.getLine(i));
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 i = this.normalizeRange(e), s = this.getTextInRange(i), n = this.getText(), r = this.positionToOffset(i.start), o = this.positionToOffset(i.end), l = n.slice(0, r) + t + n.slice(o);
41
+ return this.setText(l), { range: i, text: t, oldText: s };
42
+ }
43
+ // Insert text at position
44
+ insertText(e, t) {
45
+ const i = { start: e, end: e };
46
+ return this.replaceRange(i, t);
47
+ }
48
+ // Delete text in range
49
+ deleteRange(e) {
50
+ return this.replaceRange(e, "");
51
+ }
52
+ // Convert position to offset
53
+ positionToOffset(e) {
54
+ let t = 0;
55
+ for (let i = 0; i < e.line; i++)
56
+ t += this.getLine(i).length + 1;
57
+ return t += e.column, t;
58
+ }
59
+ // Convert offset to position
60
+ offsetToPosition(e) {
61
+ let t = e;
62
+ for (let i = 0; i < this.getLineCount(); i++) {
63
+ const s = this.getLine(i).length;
64
+ if (t <= s)
65
+ return { line: i, column: t };
66
+ t -= s + 1;
67
+ }
68
+ return {
69
+ line: this.getLineCount() - 1,
70
+ column: this.getLine(this.getLineCount() - 1).length
71
+ };
72
+ }
73
+ // Validate position
74
+ isValidPosition(e) {
75
+ return !(e.line < 0 || e.line >= this.getLineCount() || e.column < 0 || e.column > this.getLine(e.line).length);
76
+ }
77
+ // Validate range
78
+ isValidRange(e) {
79
+ return this.isValidPosition(e.start) && this.isValidPosition(e.end);
80
+ }
81
+ // Get version for change tracking
82
+ getVersion() {
83
+ return this._version;
84
+ }
85
+ // Clone the model
86
+ clone() {
87
+ const e = new z();
88
+ return e._lines = [...this._lines], e._version = this._version, e;
89
+ }
90
+ normalizeRange(e) {
91
+ return this.comparePositions(e.start, e.end) <= 0 ? e : {
92
+ start: e.end,
93
+ end: e.start
94
+ };
95
+ }
96
+ comparePositions(e, t) {
97
+ return e.line !== t.line ? e.line - t.line : e.column - t.column;
98
+ }
99
+ }
100
+ class Q {
101
+ constructor(e) {
102
+ this.gutterWidth = 50, this.lineHeight = 21, this.trailingNewlineMarkerAttr = "data-lce-trailing-newline-marker", this.foldPlaceholderAttr = "data-lce-fold-placeholder", this.virtualMarkerRegex = /[\u200B\uE000]/, this.virtualMarkerGlobalRegex = /[\u200B\uE000]/g, this.lastLineCount = 0, this.lastHighlightHTML = "", this.highlightOverlayActive = !1, this.lastLineDecorationSnapshot = "", this.lastGutterDecorationSnapshot = "", this.container = e, this.createDOM();
103
+ }
104
+ createDOM() {
105
+ this.container.innerHTML = "";
106
+ const e = document.createElement("div");
107
+ this.editorContainer = e, e.setAttribute("data-lce-editor-container", "true"), e.style.cssText = `
108
+ position: relative;
109
+ display: flex;
110
+ width: 100%;
111
+ height: 100%;
112
+ background: var(--editor-background, #1e1e1e);
113
+ color: var(--editor-foreground, #f8f9fa);
114
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
115
+ font-size: 14px;
116
+ line-height: ${this.lineHeight}px;
117
+ /* vertical scrolling is shared; horizontal scrolling belongs to the code pane */
118
+ overflow-x: hidden;
119
+ overflow-y: auto;
120
+ `, this.lineNumbersElement = document.createElement("div"), this.lineNumbersElement.setAttribute("data-editor-gutter", "true"), this.lineNumbersElement.style.cssText = `
121
+ display: table-cell;
122
+ vertical-align: top;
123
+ position: sticky;
124
+ left: 0;
125
+ width: ${this.gutterWidth}px;
126
+ background: var(--editor-gutter-background, #252526);
127
+ color: var(--editor-gutter-foreground, #858585);
128
+ padding: 0 8px 0 0;
129
+ text-align: right;
130
+ border-right: 1px solid var(--editor-gutter-border, #3e3e42);
131
+ background-clip: padding-box;
132
+ user-select: none;
133
+ overflow: hidden;
134
+ z-index: 3;
135
+ `, this.lineNumbersContentElement = document.createElement("div"), this.lineNumbersContentElement.setAttribute("data-editor-gutter-content", "true"), this.lineNumbersContentElement.style.cssText = `
136
+ position: relative;
137
+ z-index: 1;
138
+ `, this.gutterDecorationsElement = document.createElement("div"), this.gutterDecorationsElement.setAttribute("data-editor-gutter-decorations", "true"), this.gutterDecorationsElement.setAttribute("aria-hidden", "true"), this.gutterDecorationsElement.style.cssText = `
139
+ position: absolute;
140
+ inset: 0;
141
+ z-index: 2;
142
+ pointer-events: none;
143
+ `;
144
+ const t = document.createElement("div");
145
+ this.contentSurface = t, t.setAttribute("data-editor-content-surface", "true"), t.style.cssText = `
146
+ display: table-cell;
147
+ vertical-align: top;
148
+ position: relative;
149
+ width: 100%;
150
+ min-height: 400px;
151
+ `, this.highlightElement = document.createElement("div"), this.highlightElement.setAttribute("data-editor-highlight", "true"), this.highlightElement.setAttribute("aria-hidden", "true"), this.highlightElement.style.cssText = `
152
+ position: absolute;
153
+ inset: 0;
154
+ padding: 0 12px;
155
+ white-space: pre;
156
+ overflow: hidden;
157
+ min-height: 400px;
158
+ font-family: inherit;
159
+ font-size: inherit;
160
+ line-height: inherit;
161
+ pointer-events: none;
162
+ user-select: none;
163
+ background: transparent;
164
+ visibility: hidden;
165
+ `, this.lineDecorationsElement = document.createElement("div"), this.lineDecorationsElement.setAttribute("data-editor-line-decorations", "true"), this.lineDecorationsElement.setAttribute("aria-hidden", "true"), this.lineDecorationsElement.style.cssText = `
166
+ position: absolute;
167
+ inset: 0;
168
+ pointer-events: none;
169
+ z-index: 0;
170
+ `, this.contentElement = document.createElement("div"), this.contentElement.style.cssText = `
171
+ position: relative;
172
+ z-index: 1;
173
+ padding: 0 12px;
174
+ background: transparent;
175
+ border: none;
176
+ outline: none;
177
+ white-space: pre;
178
+ overflow-x: auto;
179
+ overflow-y: visible;
180
+ width: 100%;
181
+ min-height: 400px;
182
+ font-family: inherit;
183
+ font-size: inherit;
184
+ line-height: inherit;
185
+ color: inherit;
186
+ caret-color: var(--editor-foreground, #f8f9fa);
187
+ tab-size: 2;
188
+ -moz-tab-size: 2;
189
+ `, this.contentElement.contentEditable = "true", this.contentElement.spellcheck = !1, this.contentElement.tabIndex = 0;
190
+ const i = document.createElement("div");
191
+ this.scrollWrapper = i, i.setAttribute("data-editora-editor", "true"), i.style.cssText = `
192
+ position: relative;
193
+ display: table;
194
+ table-layout: fixed;
195
+ width: 100%;
196
+ height: 100%;
197
+ `, this.lineNumbersElement.appendChild(this.lineNumbersContentElement), this.lineNumbersElement.appendChild(this.gutterDecorationsElement), i.appendChild(this.lineNumbersElement), t.appendChild(this.lineDecorationsElement), t.appendChild(this.highlightElement), t.appendChild(this.contentElement), i.appendChild(t), e.appendChild(i), this.container.appendChild(e), this.updateLineNumbers(1);
198
+ }
199
+ // Update line numbers
200
+ updateLineNumbers(e) {
201
+ if (e === this.lastLineCount)
202
+ return;
203
+ this.lastLineCount = e;
204
+ const t = Math.max(e, 1), i = Array.from({ length: t }, (s, n) => n + 1);
205
+ this.lineNumbersContentElement.innerHTML = i.map((s) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${s}</div>`).join("");
206
+ }
207
+ setDecorations(e, t) {
208
+ this.renderLineDecorations(e), this.renderGutterDecorations(t);
209
+ }
210
+ clearDecorations() {
211
+ this.lastLineDecorationSnapshot && (this.lineDecorationsElement.innerHTML = "", this.lastLineDecorationSnapshot = ""), this.lastGutterDecorationSnapshot && (this.gutterDecorationsElement.innerHTML = "", this.lastGutterDecorationSnapshot = "");
212
+ }
213
+ // Get content element
214
+ getContentElement() {
215
+ return this.contentElement;
216
+ }
217
+ // Get line numbers element
218
+ getLineNumbersElement() {
219
+ return this.lineNumbersElement;
220
+ }
221
+ // Get text content
222
+ getText() {
223
+ return this.serializeContentToSource();
224
+ }
225
+ // Set text content
226
+ setText(e) {
227
+ this.clearHighlightOverlay(), this.setFoldPlaceholderSources(/* @__PURE__ */ new Map()), this.contentElement.textContent !== e && (this.contentElement.textContent = e), this.syncTrailingNewlineMarker(e.endsWith(`
228
+ `));
229
+ const t = e.split(`
230
+ `).length;
231
+ this.updateLineNumbers(t);
232
+ }
233
+ // Set inner HTML (used for syntax highlighted content)
234
+ setHTML(e) {
235
+ this.clearHighlightOverlay(), this.setFoldPlaceholderSources(/* @__PURE__ */ new Map());
236
+ const t = /\n$/.test(e), i = /&lt;|&gt;/.test(e), s = /<span\b/i.test(e), n = /<[^>]+>/.test(e);
237
+ i && s ? this.contentElement.innerHTML = e : n && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
238
+ const r = (this.contentElement.textContent || "").split(`
239
+ `).length;
240
+ this.updateLineNumbers(r);
241
+ }
242
+ setHighlightHTML(e) {
243
+ e !== this.lastHighlightHTML && (this.highlightElement.innerHTML = e, this.lastHighlightHTML = e), this.highlightElement.style.visibility = "visible", this.highlightOverlayActive = !0, this.contentElement.style.color = "transparent", this.contentElement.style.WebkitTextFillColor = "transparent";
244
+ const t = (this.contentElement.textContent || "").split(`
245
+ `).length;
246
+ this.updateLineNumbers(t);
247
+ }
248
+ setLineWrapping(e) {
249
+ this.contentElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.contentElement.style.overflowX = e ? "hidden" : "auto", this.contentElement.style.overflowY = "visible", this.contentElement.style.wordBreak = "normal", this.contentElement.style.overflowWrap = e ? "anywhere" : "normal", this.highlightElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.highlightElement.style.wordBreak = "normal", this.highlightElement.style.overflowWrap = e ? "anywhere" : "normal";
250
+ }
251
+ setLineNumbersVisible(e) {
252
+ this.lineNumbersElement.style.display = e ? "table-cell" : "none", this.lineNumbersElement.style.width = e ? `${this.gutterWidth}px` : "0", this.lineNumbersElement.style.paddingRight = e ? "8px" : "0", this.lineNumbersElement.style.borderRightWidth = e ? "1px" : "0", this.scrollWrapper.style.width = e ? "100%" : "auto";
253
+ }
254
+ setTabSize(e) {
255
+ const t = Math.max(1, Math.floor(e) || 2);
256
+ this.contentElement.style.tabSize = String(t), this.contentElement.style.MozTabSize = String(t), this.highlightElement.style.tabSize = String(t), this.highlightElement.style.MozTabSize = String(t);
257
+ }
258
+ // Keep trailing-newline caret marker in sync for live contenteditable edits
259
+ // (without forcing a full setText/setHTML render).
260
+ syncTrailingNewlineMarkerForText(e) {
261
+ this.syncTrailingNewlineMarker(e.endsWith(`
262
+ `));
263
+ }
264
+ // Get cursor position from DOM selection
265
+ getCursorPosition() {
266
+ var e;
267
+ return (e = this.getSelectionState().cursor) != null ? e : { line: 0, column: 0 };
268
+ }
269
+ // Set cursor position
270
+ setCursorPosition(e) {
271
+ const t = this.getText(), i = this.positionToTextOffset(e, t), s = window.getSelection(), n = this.createDomRangeFromOffsets(i);
272
+ if (n)
273
+ try {
274
+ s == null || s.removeAllRanges(), s == null || s.addRange(n), this.ensureCaretVisible();
275
+ } catch (r) {
276
+ console.warn("Could not set cursor position:", r);
277
+ }
278
+ else {
279
+ const r = this.contentElement.querySelector(
280
+ `[${this.trailingNewlineMarkerAttr}]`
281
+ ), o = document.createRange();
282
+ try {
283
+ r && r.parentNode === this.contentElement ? o.setStartBefore(r) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), s == null || s.removeAllRanges(), s == null || s.addRange(o), this.ensureCaretVisible();
284
+ } catch (l) {
285
+ console.warn("Could not set fallback cursor position:", l);
286
+ }
287
+ }
288
+ }
289
+ // Get selection range
290
+ getSelectionRange() {
291
+ return this.getSelectionState().range;
292
+ }
293
+ getSelectionOffsets() {
294
+ const e = window.getSelection();
295
+ if (!e || e.rangeCount === 0)
296
+ return {
297
+ isInEditor: !1,
298
+ isCollapsed: !0,
299
+ startOffset: 0,
300
+ endOffset: 0
301
+ };
302
+ const t = e.getRangeAt(0);
303
+ if (!this.isNodeInsideContent(t.startContainer) || !this.isNodeInsideContent(t.endContainer))
304
+ return {
305
+ isInEditor: !1,
306
+ isCollapsed: e.isCollapsed,
307
+ startOffset: 0,
308
+ endOffset: 0
309
+ };
310
+ const i = e.anchorNode && this.isNodeInsideContent(e.anchorNode) ? this.sourceOffsetFromBoundary(
311
+ e.anchorNode,
312
+ e.anchorOffset
313
+ ) : void 0, s = e.focusNode && this.isNodeInsideContent(e.focusNode) ? this.sourceOffsetFromBoundary(
314
+ e.focusNode,
315
+ e.focusOffset
316
+ ) : void 0;
317
+ return {
318
+ isInEditor: !0,
319
+ isCollapsed: e.isCollapsed,
320
+ startOffset: this.sourceOffsetFromBoundary(
321
+ t.startContainer,
322
+ t.startOffset
323
+ ),
324
+ endOffset: this.sourceOffsetFromBoundary(
325
+ t.endContainer,
326
+ t.endOffset
327
+ ),
328
+ anchorOffset: i,
329
+ focusOffset: s
330
+ };
331
+ }
332
+ getSelectionState() {
333
+ const e = window.getSelection();
334
+ if (!e || e.rangeCount === 0)
335
+ return {
336
+ isInEditor: !1,
337
+ isCollapsed: !0
338
+ };
339
+ const t = e.getRangeAt(0);
340
+ if (!this.isNodeInsideContent(t.startContainer) || !this.isNodeInsideContent(t.endContainer))
341
+ return {
342
+ isInEditor: !1,
343
+ isCollapsed: e.isCollapsed
344
+ };
345
+ const i = this.getText(), s = this.sourceOffsetFromBoundary(t.startContainer, t.startOffset), n = this.sourceOffsetFromBoundary(t.endContainer, t.endOffset), r = e.focusNode && this.isNodeInsideContent(e.focusNode) ? this.sourceOffsetFromBoundary(
346
+ e.focusNode,
347
+ e.focusOffset
348
+ ) : n, o = this.offsetToPositionInText(s, i), l = this.offsetToPositionInText(n, i), a = this.offsetToPositionInText(r, i);
349
+ return {
350
+ isInEditor: !0,
351
+ isCollapsed: e.isCollapsed,
352
+ cursor: a,
353
+ range: e.isCollapsed ? void 0 : { start: o, end: l }
354
+ };
355
+ }
356
+ // Set selection range
357
+ setSelectionRange(e) {
358
+ const t = this.createDomRangeFromRange(e);
359
+ if (t)
360
+ try {
361
+ const i = window.getSelection();
362
+ i == null || i.removeAllRanges(), i == null || i.addRange(t), this.ensureCaretVisible();
363
+ } catch (i) {
364
+ console.warn("Could not set selection range:", i);
365
+ }
366
+ }
367
+ createDomRangeFromOffsets(e, t = e) {
368
+ const [i, s] = e <= t ? [e, t] : [t, e], n = this.resolveOffsetToDomPoint(i), r = this.resolveOffsetToDomPoint(s);
369
+ if (!n || !r)
370
+ return null;
371
+ const o = document.createRange();
372
+ try {
373
+ return o.setStart(n.node, n.offset), o.setEnd(r.node, r.offset), o;
374
+ } catch (l) {
375
+ return null;
376
+ }
377
+ }
378
+ createDomRangeFromRange(e) {
379
+ const t = this.getText();
380
+ return this.createDomRangeFromOffsets(
381
+ this.positionToTextOffset(e.start, t),
382
+ this.positionToTextOffset(e.end, t)
383
+ );
384
+ }
385
+ getPositionFromClientPoint(e, t) {
386
+ const i = this.getDomRangeFromClientPoint(e, t);
387
+ if (!i || !this.isNodeInsideContent(i.startContainer))
388
+ return null;
389
+ const s = this.sourceOffsetFromBoundary(
390
+ i.startContainer,
391
+ i.startOffset
392
+ );
393
+ return this.offsetToPositionInText(s, this.getText());
394
+ }
395
+ setSelectionOffsets(e, t = e) {
396
+ const i = this.createDomRangeFromOffsets(e, t);
397
+ if (i)
398
+ try {
399
+ const s = window.getSelection();
400
+ s == null || s.removeAllRanges(), s == null || s.addRange(i), this.ensureCaretVisible();
401
+ } catch (s) {
402
+ console.warn("Could not set selection offsets:", s);
403
+ }
404
+ }
405
+ setSelectionBoundaryOffsets(e, t) {
406
+ const i = this.resolveOffsetToDomPoint(e), s = this.resolveOffsetToDomPoint(t), n = window.getSelection();
407
+ if (!i || !s || !n) {
408
+ this.setSelectionOffsets(e, t);
409
+ return;
410
+ }
411
+ try {
412
+ if (n.removeAllRanges(), e === t) {
413
+ const o = document.createRange();
414
+ o.setStart(i.node, i.offset), o.collapse(!0), n.addRange(o), this.ensureCaretVisible();
415
+ return;
416
+ }
417
+ if (typeof n.extend == "function") {
418
+ const o = document.createRange();
419
+ o.setStart(i.node, i.offset), o.collapse(!0), n.addRange(o), n.extend(s.node, s.offset), this.ensureCaretVisible();
420
+ return;
421
+ }
422
+ const r = this.createDomRangeFromOffsets(e, t);
423
+ if (!r)
424
+ return;
425
+ n.addRange(r), this.ensureCaretVisible();
426
+ } catch (r) {
427
+ console.warn("Could not set selection boundary offsets:", r), this.setSelectionOffsets(e, t);
428
+ }
429
+ }
430
+ // Focus the editor
431
+ focus() {
432
+ this.contentElement.focus(), this.ensureCaretVisible();
433
+ }
434
+ // Blur the editor
435
+ blur() {
436
+ this.contentElement.blur();
437
+ }
438
+ // Set read-only mode
439
+ setReadOnly(e) {
440
+ this.contentElement.contentEditable = e ? "false" : "true";
441
+ }
442
+ // Apply theme
443
+ applyTheme(e) {
444
+ Object.entries(e).forEach(([t, i]) => {
445
+ this.container.style.setProperty(`--${t}`, i);
446
+ });
447
+ }
448
+ // Scroll to position
449
+ scrollToPosition(e) {
450
+ const t = this.lineNumbersElement.children[e.line];
451
+ t && t.scrollIntoView({ block: "center", behavior: "smooth" });
452
+ }
453
+ // Get scroll position
454
+ getScrollTop() {
455
+ return this.editorContainer.scrollTop;
456
+ }
457
+ // Get primary scroll element
458
+ getScrollElement() {
459
+ return this.editorContainer;
460
+ }
461
+ // Set scroll position
462
+ setScrollTop(e) {
463
+ this.editorContainer.scrollTop = e;
464
+ }
465
+ syncTrailingNewlineMarker(e) {
466
+ if (this.contentElement.querySelectorAll(`[${this.trailingNewlineMarkerAttr}]`).forEach((i) => i.remove()), !e) return;
467
+ const t = document.createElement("span");
468
+ t.setAttribute(this.trailingNewlineMarkerAttr, "true"), t.setAttribute("aria-hidden", "true"), t.contentEditable = "false", t.style.cssText = `
469
+ display: inline-block;
470
+ width: 0;
471
+ overflow: hidden;
472
+ pointer-events: none;
473
+ user-select: none;
474
+ `, t.appendChild(document.createTextNode("​")), this.contentElement.appendChild(t);
475
+ }
476
+ // Ensure caret is visible inside the editor scroll container
477
+ ensureCaretVisible() {
478
+ const e = window.getSelection();
479
+ if (!e || e.rangeCount === 0) return;
480
+ const t = this.getCaretClientRect(e);
481
+ if (!t) return;
482
+ const i = this.editorContainer.getBoundingClientRect(), s = 12;
483
+ t.bottom > i.bottom - s ? this.editorContainer.scrollTop += t.bottom - (i.bottom - s) : t.top < i.top + s && (this.editorContainer.scrollTop -= i.top + s - t.top);
484
+ }
485
+ // Destroy the view
486
+ destroy() {
487
+ this.clearDecorations(), this.container && (this.container.innerHTML = ""), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
488
+ }
489
+ resolveOffsetToDomPoint(e) {
490
+ var n;
491
+ const t = Math.max(0, e);
492
+ let i = 0;
493
+ const s = Array.from(this.contentElement.childNodes);
494
+ for (let r = 0; r < s.length; r++) {
495
+ const o = s[r];
496
+ if (o instanceof Text) {
497
+ const l = o.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
498
+ if (i + h >= t) {
499
+ const d = Math.max(0, t - i), c = (n = a[d]) != null ? n : l.length;
500
+ return { node: o, offset: c };
501
+ }
502
+ i += h;
503
+ continue;
504
+ }
505
+ if (o instanceof HTMLElement && !o.hasAttribute(this.trailingNewlineMarkerAttr) && o.hasAttribute(this.foldPlaceholderAttr)) {
506
+ const l = this.getFoldPlaceholderSource(o).length;
507
+ if (i + l >= t) {
508
+ const a = t - i;
509
+ return {
510
+ node: this.contentElement,
511
+ offset: a <= l / 2 ? r : r + 1
512
+ };
513
+ }
514
+ i += l;
515
+ }
516
+ }
517
+ return {
518
+ node: this.contentElement,
519
+ offset: this.contentElement.childNodes.length
520
+ };
521
+ }
522
+ getDomRangeFromClientPoint(e, t) {
523
+ const i = document;
524
+ if (typeof i.caretPositionFromPoint == "function") {
525
+ const s = i.caretPositionFromPoint(
526
+ e,
527
+ t
528
+ );
529
+ if (s != null && s.offsetNode) {
530
+ const n = document.createRange();
531
+ try {
532
+ return n.setStart(s.offsetNode, s.offset), n.collapse(!0), n;
533
+ } catch (r) {
534
+ return null;
535
+ }
536
+ }
537
+ }
538
+ return typeof i.caretRangeFromPoint == "function" ? i.caretRangeFromPoint(e, t) : null;
539
+ }
540
+ buildVisibleToDomMap(e) {
541
+ const t = [0];
542
+ let i = 0;
543
+ for (let s = 0; s < e.length; s++) {
544
+ const n = e[s];
545
+ this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
546
+ }
547
+ return t;
548
+ }
549
+ isNodeInsideContent(e) {
550
+ return e === this.contentElement || this.contentElement.contains(e);
551
+ }
552
+ getCaretClientRect(e) {
553
+ var o, l, a;
554
+ const t = e.getRangeAt(0).cloneRange();
555
+ t.collapse(!1);
556
+ const i = this.getUsableRangeRect(t);
557
+ if (i)
558
+ return i;
559
+ const s = e.focusNode, n = e.focusOffset;
560
+ if (s instanceof Text) {
561
+ const h = (l = (o = s.textContent) == null ? void 0 : o.length) != null ? l : 0, d = document.createRange();
562
+ if (n < h) {
563
+ d.setStart(s, n), d.setEnd(s, Math.min(h, n + 1));
564
+ const c = this.getUsableRangeRect(d);
565
+ if (c)
566
+ return c;
567
+ }
568
+ if (n > 0) {
569
+ d.setStart(s, n - 1), d.setEnd(s, n);
570
+ const c = this.getUsableRangeRect(d);
571
+ if (c)
572
+ return c;
573
+ }
574
+ }
575
+ const r = s instanceof Element ? s : (a = s == null ? void 0 : s.parentElement) != null ? a : null;
576
+ if (r && r !== this.contentElement && r !== this.editorContainer && this.contentElement.contains(r)) {
577
+ const h = r.getBoundingClientRect();
578
+ if (this.isUsableRect(h))
579
+ return h;
580
+ }
581
+ return null;
582
+ }
583
+ getUsableRangeRect(e) {
584
+ const t = Array.from(e.getClientRects());
585
+ for (let s = 0; s < t.length; s++)
586
+ if (this.isUsableRect(t[s]))
587
+ return t[s];
588
+ const i = e.getBoundingClientRect();
589
+ return this.isUsableRect(i) ? i : null;
590
+ }
591
+ isUsableRect(e) {
592
+ return !!e && Number.isFinite(e.top) && Number.isFinite(e.bottom) && (e.width > 0 || e.height > 0);
593
+ }
594
+ stripVirtualMarkers(e) {
595
+ return e.replace(this.virtualMarkerGlobalRegex, "");
596
+ }
597
+ clearHighlightOverlay() {
598
+ !this.highlightOverlayActive && !this.lastHighlightHTML || (this.highlightElement.innerHTML = "", this.highlightElement.style.visibility = "hidden", this.lastHighlightHTML = "", this.highlightOverlayActive = !1, this.contentElement.style.color = "inherit", this.contentElement.style.WebkitTextFillColor = "currentcolor");
599
+ }
600
+ serializeContentToSource() {
601
+ let e = "";
602
+ const t = Array.from(this.contentElement.childNodes);
603
+ for (const i of t) {
604
+ if (i instanceof Text) {
605
+ e += this.stripVirtualMarkers(i.textContent || "");
606
+ continue;
607
+ }
608
+ if (i instanceof HTMLElement && !i.hasAttribute(this.trailingNewlineMarkerAttr)) {
609
+ if (i.hasAttribute(this.foldPlaceholderAttr)) {
610
+ e += this.getFoldPlaceholderSource(i);
611
+ continue;
612
+ }
613
+ e += this.stripVirtualMarkers(i.textContent || "");
614
+ }
615
+ }
616
+ return e;
617
+ }
618
+ sourceOffsetFromBoundary(e, t) {
619
+ let i = 0;
620
+ const s = Array.from(this.contentElement.childNodes);
621
+ if (e === this.contentElement) {
622
+ for (let n = 0; n < Math.min(t, s.length); n++)
623
+ i += this.getSourceLength(s[n]);
624
+ return i;
625
+ }
626
+ for (let n = 0; n < s.length; n++) {
627
+ const r = s[n];
628
+ if (r === e) {
629
+ if (r instanceof Text)
630
+ return i + this.stripVirtualMarkers((r.textContent || "").slice(0, t)).length;
631
+ if (r instanceof HTMLElement) {
632
+ if (r.hasAttribute(this.foldPlaceholderAttr))
633
+ return i + this.getFoldPlaceholderBoundaryOffset(
634
+ r,
635
+ r,
636
+ t
637
+ );
638
+ const o = Array.from(r.childNodes);
639
+ for (let l = 0; l < Math.min(t, o.length); l++)
640
+ i += this.getSourceLength(o[l]);
641
+ return i;
642
+ }
643
+ }
644
+ if (r instanceof HTMLElement && r.contains(e))
645
+ return r.hasAttribute(this.foldPlaceholderAttr) ? i + this.getFoldPlaceholderBoundaryOffset(
646
+ r,
647
+ e,
648
+ t
649
+ ) : i + this.sourceOffsetWithinNode(r, e, t);
650
+ i += this.getSourceLength(r);
651
+ }
652
+ return i;
653
+ }
654
+ sourceOffsetWithinNode(e, t, i) {
655
+ let s = 0;
656
+ const n = Array.from(e.childNodes);
657
+ if (t === e) {
658
+ for (let r = 0; r < Math.min(i, n.length); r++)
659
+ s += this.getSourceLength(n[r]);
660
+ return s;
661
+ }
662
+ for (let r = 0; r < n.length; r++) {
663
+ const o = n[r];
664
+ if (o === t) {
665
+ if (o instanceof Text)
666
+ return s + this.stripVirtualMarkers((o.textContent || "").slice(0, i)).length;
667
+ if (o instanceof HTMLElement) {
668
+ if (o.hasAttribute(this.foldPlaceholderAttr))
669
+ return s + this.getFoldPlaceholderBoundaryOffset(
670
+ o,
671
+ o,
672
+ i
673
+ );
674
+ const l = Array.from(o.childNodes);
675
+ for (let a = 0; a < Math.min(i, l.length); a++)
676
+ s += this.getSourceLength(l[a]);
677
+ return s;
678
+ }
679
+ }
680
+ if (o instanceof HTMLElement && o.contains(t))
681
+ return o.hasAttribute(this.foldPlaceholderAttr) ? s + this.getFoldPlaceholderBoundaryOffset(
682
+ o,
683
+ t,
684
+ i
685
+ ) : s + this.sourceOffsetWithinNode(o, t, i);
686
+ s += this.getSourceLength(o);
687
+ }
688
+ return s;
689
+ }
690
+ getSourceLength(e) {
691
+ if (e instanceof Text)
692
+ return this.stripVirtualMarkers(e.textContent || "").length;
693
+ if (!(e instanceof HTMLElement) || e.hasAttribute(this.trailingNewlineMarkerAttr))
694
+ return 0;
695
+ if (e.hasAttribute(this.foldPlaceholderAttr))
696
+ return this.getFoldPlaceholderSource(e).length;
697
+ let t = 0;
698
+ return e.childNodes.forEach((i) => {
699
+ t += this.getSourceLength(i);
700
+ }), t;
701
+ }
702
+ renderLineDecorations(e) {
703
+ const t = [...e].filter((n) => Number.isFinite(n.line) && n.line >= 0).sort((n, r) => n.line - r.line || n.id.localeCompare(r.id)), i = t.map(
704
+ (n) => `${n.id}:${n.line}:${n.className || ""}:${this.serializeStyleObject(n.style)}`
705
+ ).join("|");
706
+ if (i === this.lastLineDecorationSnapshot || (this.lineDecorationsElement.innerHTML = "", this.lastLineDecorationSnapshot = i, t.length === 0))
707
+ return;
708
+ const s = document.createDocumentFragment();
709
+ for (const n of t) {
710
+ const r = document.createElement("div");
711
+ r.className = this.joinClassNames(
712
+ "lce-decoration lce-decoration-line",
713
+ n.className
714
+ ), r.setAttribute("data-decoration-id", n.id), r.setAttribute("data-decoration-line", String(n.line)), r.style.cssText = this.joinStyleFragments([
715
+ "position: absolute",
716
+ `top: ${n.line * this.lineHeight}px`,
717
+ `height: ${this.lineHeight}px`,
718
+ "left: 12px",
719
+ "right: 12px",
720
+ "border-radius: 3px",
721
+ this.serializeStyleObject(n.style)
722
+ ]), s.appendChild(r);
723
+ }
724
+ this.lineDecorationsElement.appendChild(s);
725
+ }
726
+ renderGutterDecorations(e) {
727
+ const t = [...e].filter((n) => Number.isFinite(n.line) && n.line >= 0).sort((n, r) => n.line - r.line || n.id.localeCompare(r.id)), i = t.map(
728
+ (n) => `${n.id}:${n.line}:${n.label || ""}:${n.title || ""}:${n.className || ""}:${this.serializeStyleObject(n.style)}`
729
+ ).join("|");
730
+ if (i === this.lastGutterDecorationSnapshot || (this.gutterDecorationsElement.innerHTML = "", this.lastGutterDecorationSnapshot = i, t.length === 0))
731
+ return;
732
+ const s = document.createDocumentFragment();
733
+ for (const n of t) {
734
+ const r = document.createElement("div");
735
+ r.className = this.joinClassNames(
736
+ "lce-decoration lce-decoration-gutter",
737
+ n.className
738
+ ), r.setAttribute("data-decoration-id", n.id), r.setAttribute("data-decoration-line", String(n.line)), r.style.cssText = this.joinStyleFragments([
739
+ "position: absolute",
740
+ `top: ${n.line * this.lineHeight}px`,
741
+ `height: ${this.lineHeight}px`,
742
+ "left: 0",
743
+ "right: 0",
744
+ "display: flex",
745
+ "align-items: center",
746
+ "justify-content: flex-end",
747
+ "padding-right: 4px",
748
+ "box-sizing: border-box",
749
+ this.serializeStyleObject(n.style)
750
+ ]), n.title && (r.title = n.title), r.textContent = n.label || "", s.appendChild(r);
751
+ }
752
+ this.gutterDecorationsElement.appendChild(s);
753
+ }
754
+ joinClassNames(...e) {
755
+ return e.filter(Boolean).join(" ").trim();
756
+ }
757
+ joinStyleFragments(e) {
758
+ return e.filter((t) => !!t && t.trim().length > 0).map((t) => {
759
+ const i = t.trim();
760
+ return i.endsWith(";") ? i : `${i};`;
761
+ }).join(" ");
762
+ }
763
+ serializeStyleObject(e) {
764
+ return e ? Object.entries(e).filter(([, t]) => typeof t == "string" && t.length > 0).map(([t, i]) => `${this.toKebabCase(t)}: ${i}`).join("; ") : "";
765
+ }
766
+ toKebabCase(e) {
767
+ return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
768
+ }
769
+ offsetToPositionInText(e, t) {
770
+ const i = Math.max(0, Math.min(e, t.length)), s = t.slice(0, i).split(`
771
+ `);
772
+ return {
773
+ line: s.length - 1,
774
+ column: s[s.length - 1].length
775
+ };
776
+ }
777
+ positionToTextOffset(e, t) {
778
+ var o;
779
+ const i = t.split(`
780
+ `), s = Math.max(0, Math.min(e.line, i.length - 1)), n = Math.max(
781
+ 0,
782
+ Math.min(e.column, ((o = i[s]) == null ? void 0 : o.length) || 0)
783
+ );
784
+ let r = 0;
785
+ for (let l = 0; l < s; l++)
786
+ r += i[l].length + 1;
787
+ return r + n;
788
+ }
789
+ getFoldPlaceholderSource(e) {
790
+ const t = e.getAttribute(this.foldPlaceholderAttr), i = this.getFoldPlaceholderSources();
791
+ return t && i.has(t) ? i.get(t) || "" : e.__lceFoldHiddenText || "";
792
+ }
793
+ getFoldPlaceholderSources() {
794
+ return this.contentElement.__lceFoldPlaceholderSources || /* @__PURE__ */ new Map();
795
+ }
796
+ getFoldPlaceholderBoundaryOffset(e, t, i) {
797
+ const s = this.getFoldPlaceholderSource(e).length, n = this.stripVirtualMarkers(e.textContent || "").length;
798
+ if (s === 0 || n === 0)
799
+ return 0;
800
+ const r = document.createRange();
801
+ r.selectNodeContents(e);
802
+ try {
803
+ r.setEnd(t, i);
804
+ } catch (o) {
805
+ return 0;
806
+ }
807
+ return this.stripVirtualMarkers(r.toString()).length <= n / 2 ? 0 : s;
808
+ }
809
+ setFoldPlaceholderSources(e) {
810
+ this.contentElement.__lceFoldPlaceholderSources = e;
811
+ }
812
+ }
813
+ let X = 0;
814
+ const U = class O {
815
+ constructor(e, t = {}) {
816
+ 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.lastKnownCursor = { line: 0, column: 0 }, this.editorInstanceId = ++X, this.decorationHighlightStyleId = `editora-decoration-style-${this.editorInstanceId}`, this.decorationHighlightLimit = 1e3, this.decorationLayers = /* @__PURE__ */ new Map(), this.inlineDecorationHighlightNames = /* @__PURE__ */ new Set(), this.decorationRenderRaf = null, this.decorationMutationObserver = null, this.hasCustomDecorationHighlightSupport = !1, this.lastProgrammaticClipboardInsertAt = 0, this.config = {
817
+ value: "",
818
+ theme: "default",
819
+ readOnly: !1,
820
+ tabSize: 2,
821
+ lineWrapping: !1,
822
+ lineNumbers: !0,
823
+ ...t
824
+ }, this.textModel = new z(this.config.value), this.view = new Q(e), this.view.setTabSize(this.config.tabSize || 2), this.view.setLineWrapping(!!this.config.lineWrapping), this.view.setLineNumbersVisible(this.config.lineNumbers !== !1), this.hasCustomDecorationHighlightSupport = this.detectCustomHighlightSupport(), this.observeDecorationRelevantMutations(), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
825
+ }
826
+ // Public accessors for extensions
827
+ getTextModel() {
828
+ return this.textModel;
829
+ }
830
+ getView() {
831
+ return this.view;
832
+ }
833
+ getConfig() {
834
+ return { ...this.config };
835
+ }
836
+ // Register built-in editor commands like undo/redo/insertTab
837
+ registerBuiltInCommands() {
838
+ this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("save", () => {
839
+ this.emit("save");
840
+ });
841
+ }
842
+ // Get keymap extension if available
843
+ getKeymapExtension() {
844
+ return this.extensions.get("keymap");
845
+ }
846
+ // Setup DOM event handlers
847
+ setupEventHandlers() {
848
+ const e = this.view.getContentElement();
849
+ e.addEventListener("beforeinput", (t) => {
850
+ if (this.suppressHistory || this.config.readOnly) {
851
+ this.pendingInputSnapshot = void 0;
852
+ return;
853
+ }
854
+ if (t.inputType === "insertFromPaste" || t.inputType === "insertFromPasteAsQuotation" || t.inputType === "insertFromDrop") {
855
+ const i = t.dataTransfer, s = this.getPlainTextFromDataTransfer(i);
856
+ if (s.length === 0 || (t.preventDefault(), this.pendingInputSnapshot = void 0, Date.now() - this.lastProgrammaticClipboardInsertAt < 80))
857
+ return;
858
+ this.insertClipboardText(s);
859
+ return;
860
+ }
861
+ if (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") {
862
+ t.preventDefault(), this.pendingInputSnapshot = void 0, this.insertNewLine();
863
+ return;
864
+ }
865
+ if (t.inputType === "deleteContentBackward" || t.inputType === "deleteWordBackward") {
866
+ t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteBackward();
867
+ return;
868
+ }
869
+ if (t.inputType === "deleteContentForward" || t.inputType === "deleteWordForward") {
870
+ t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteForward();
871
+ return;
872
+ }
873
+ if (t.inputType === "deleteByCut") {
874
+ t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteSelection();
875
+ return;
876
+ }
877
+ if (t.inputType === "insertText" && typeof t.data == "string" && !t.isComposing) {
878
+ t.preventDefault(), this.pendingInputSnapshot = void 0, this.replaceSelectionWithText(t.data);
879
+ return;
880
+ }
881
+ this.pendingInputSnapshot = this.captureHistorySnapshot();
882
+ }), e.addEventListener("paste", (t) => {
883
+ if (this.config.readOnly) {
884
+ t.preventDefault();
885
+ return;
886
+ }
887
+ if (Date.now() - this.lastProgrammaticClipboardInsertAt < 80) {
888
+ t.preventDefault();
889
+ return;
890
+ }
891
+ const i = this.getPlainTextFromDataTransfer(t.clipboardData);
892
+ i.length !== 0 && (t.preventDefault(), this.insertClipboardText(i));
893
+ }), e.addEventListener("input", () => {
894
+ var s;
895
+ const t = this.view.getText(), i = this.textModel.getText();
896
+ t !== i ? (this.suppressHistory || this.pushUndoSnapshot(
897
+ (s = this.pendingInputSnapshot) != null ? s : this.captureHistorySnapshot(i)
898
+ ), this.pendingInputSnapshot = void 0, this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.hasRenderedFoldPlaceholders() ? this.clearPendingHighlightRender() : (this.clearPendingHighlightRender(), this.highlightTimeout = setTimeout(() => {
899
+ const n = this.view.getText();
900
+ n !== this.textModel.getText() && this.textModel.setText(n), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
901
+ }, 300)), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }])) : this.pendingInputSnapshot = void 0;
902
+ }), this.documentSelectionChangeHandler = () => {
903
+ var s, n, r;
904
+ const t = this.syncSelectionCacheFromView();
905
+ if (!t.isInEditor)
906
+ return;
907
+ const i = (s = t.cursor) != null ? s : this.lastKnownCursor;
908
+ this.emit("cursor", {
909
+ position: i,
910
+ anchor: (r = (n = t.range) == null ? void 0 : n.start) != null ? r : i
911
+ }), this.emit("selection", t.isCollapsed ? void 0 : t.range);
912
+ }, document.addEventListener("selectionchange", this.documentSelectionChangeHandler), e.addEventListener("keydown", (t) => {
913
+ this.emit("keydown", t);
914
+ const i = Array.from(this.extensions.values()).reverse();
915
+ for (const s of i)
916
+ if (s.onKeyDown && s.onKeyDown(t) === !1) {
917
+ t.preventDefault(), t.stopPropagation();
918
+ return;
919
+ }
920
+ if (t.key === "Tab" && !this.config.readOnly) {
921
+ this.insertTab(), t.preventDefault(), t.stopPropagation();
922
+ return;
923
+ }
924
+ if (t.key === "Backspace" && !this.config.readOnly) {
925
+ this.deleteBackward(), t.preventDefault(), t.stopPropagation();
926
+ return;
927
+ }
928
+ if (t.key === "Delete" && !this.config.readOnly) {
929
+ this.deleteForward(), t.preventDefault(), t.stopPropagation();
930
+ return;
931
+ }
932
+ if (t.key === "Enter" && !this.config.readOnly) {
933
+ this.insertNewLine(), t.preventDefault(), t.stopPropagation();
934
+ return;
935
+ }
936
+ }), e.addEventListener("mousedown", (t) => {
937
+ this.emit("mousedown", t);
938
+ const i = Array.from(this.extensions.values()).reverse();
939
+ for (const s of i)
940
+ if (s.onMouseDown && s.onMouseDown(t) === !1) {
941
+ t.preventDefault(), t.stopPropagation();
942
+ return;
943
+ }
944
+ }), e.addEventListener("contextmenu", (t) => {
945
+ this.emit("contextmenu", t);
946
+ const i = Array.from(this.extensions.values()).reverse();
947
+ for (const s of i)
948
+ if (s.onContextMenu && s.onContextMenu(t) === !1) {
949
+ t.preventDefault(), t.stopPropagation();
950
+ return;
951
+ }
952
+ }), e.addEventListener("focus", () => {
953
+ this.emit("focus");
954
+ }), e.addEventListener("blur", () => {
955
+ this.emit("blur");
956
+ });
957
+ }
958
+ // Update line numbers display
959
+ updateLineNumbers() {
960
+ const e = this.textModel.getLineCount();
961
+ this.view.updateLineNumbers(e);
962
+ }
963
+ // Get full range of document
964
+ getFullRange() {
965
+ return {
966
+ start: { line: 0, column: 0 },
967
+ end: {
968
+ line: this.textModel.getLineCount() - 1,
969
+ column: this.textModel.getLine(this.textModel.getLineCount() - 1).length
970
+ }
971
+ };
972
+ }
973
+ // Emit events to listeners
974
+ emit(e, ...t) {
975
+ const i = this.eventListeners.get(e);
976
+ i && i.forEach((s) => s(...t));
977
+ }
978
+ // State management
979
+ getValue() {
980
+ return this.textModel.getText();
981
+ }
982
+ setValue(e) {
983
+ const t = this.textModel.getText();
984
+ this.textModel.setText(e), this.renderTextWithHighlight(e, !1), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: e, oldText: t }]);
985
+ }
986
+ getState() {
987
+ return {
988
+ text: this.getValue(),
989
+ cursor: this.getCursor(),
990
+ selection: this.getSelection(),
991
+ readOnly: this.config.readOnly || !1,
992
+ theme: this.currentTheme
993
+ };
994
+ }
995
+ // Cursor & Selection
996
+ getCursor() {
997
+ var i, s, n;
998
+ const e = this.syncSelectionCacheFromView(), t = (i = e.cursor) != null ? i : this.lastKnownCursor;
999
+ return {
1000
+ position: t,
1001
+ anchor: (n = (s = e.range) == null ? void 0 : s.start) != null ? n : t
1002
+ };
1003
+ }
1004
+ setCursor(e) {
1005
+ const t = this.textModel.getText(), i = this.clampPositionToText(e, t), s = this.positionToOffsetInText(i, t);
1006
+ this.lastKnownCursor = i, this.lastKnownSelection = void 0, this.view.setSelectionOffsets(s), this.emit("cursor", this.getCursor());
1007
+ }
1008
+ getSelection() {
1009
+ const e = this.syncSelectionCacheFromView();
1010
+ if (!(!e.isInEditor || e.isCollapsed))
1011
+ return e.range;
1012
+ }
1013
+ setSelection(e) {
1014
+ const t = this.textModel.getText(), i = this.normalizeRange({
1015
+ start: this.clampPositionToText(e.start, t),
1016
+ end: this.clampPositionToText(e.end, t)
1017
+ }), s = this.positionToOffsetInText(i.start, t), n = this.positionToOffsetInText(i.end, t);
1018
+ this.lastKnownSelection = i, this.lastKnownCursor = i.end, this.view.setSelectionOffsets(s, n), this.emit("selection", i);
1019
+ }
1020
+ // Configuration
1021
+ setTheme(e) {
1022
+ this.currentTheme = e;
1023
+ const t = {
1024
+ "editor-background": e === "dark" ? "#1e1e1e" : "#ffffff",
1025
+ "editor-foreground": e === "dark" ? "#f8f9fa" : "#1a1a1a",
1026
+ "editor-gutter-background": e === "dark" ? "#252526" : "#f8f9fa",
1027
+ "editor-gutter-foreground": e === "dark" ? "#858585" : "#666666",
1028
+ "editor-gutter-border": e === "dark" ? "#3e3e42" : "#e1e5e9"
1029
+ };
1030
+ this.view.applyTheme(t);
1031
+ const i = this.extensions.get("syntax-highlighting");
1032
+ if (i && typeof i.setTheme == "function")
1033
+ try {
1034
+ i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
1035
+ } catch (s) {
1036
+ console.warn("Error applying theme to syntax-highlighting extension", s);
1037
+ }
1038
+ }
1039
+ setReadOnly(e) {
1040
+ this.config.readOnly = e, this.view.setReadOnly(e);
1041
+ }
1042
+ // Extensions & Commands
1043
+ addExtension(e) {
1044
+ if (this.extensions.has(e.name))
1045
+ throw new Error(`Extension '${e.name}' already exists`);
1046
+ this.extensions.set(e.name, e), e.setup(this), e.name === "syntax-highlighting" && typeof e.highlightHTML == "function" && this.renderTextWithHighlight(this.textModel.getText());
1047
+ }
1048
+ removeExtension(e) {
1049
+ const t = this.extensions.get(e);
1050
+ t && t.destroy && t.destroy(), this.extensions.delete(e);
1051
+ }
1052
+ executeCommand(e, ...t) {
1053
+ const i = this.commands.get(e);
1054
+ i ? i(...t) : console.warn(`Command '${e}' not found`);
1055
+ }
1056
+ // Register a command
1057
+ registerCommand(e, t) {
1058
+ this.commands.set(e, t);
1059
+ }
1060
+ setDecorations(e, t) {
1061
+ const i = e.trim();
1062
+ if (!i)
1063
+ throw new Error("Decoration layer name must not be empty");
1064
+ if (!Array.isArray(t) || t.length === 0) {
1065
+ this.decorationLayers.delete(i), this.scheduleDecorationRender();
1066
+ return;
1067
+ }
1068
+ this.decorationLayers.set(
1069
+ i,
1070
+ t.map((s) => this.cloneDecoration(s))
1071
+ ), this.scheduleDecorationRender();
1072
+ }
1073
+ clearDecorations(e) {
1074
+ typeof e == "string" ? this.decorationLayers.delete(e.trim()) : this.decorationLayers.clear(), this.scheduleDecorationRender();
1075
+ }
1076
+ getDecorations(e) {
1077
+ if (typeof e == "string")
1078
+ return (this.decorationLayers.get(e.trim()) || []).map(
1079
+ (i) => this.cloneDecoration(i)
1080
+ );
1081
+ const t = [];
1082
+ for (const i of this.decorationLayers.values())
1083
+ t.push(
1084
+ ...i.map((s) => this.cloneDecoration(s))
1085
+ );
1086
+ return t;
1087
+ }
1088
+ // Search & Navigation
1089
+ search(e, t = {}) {
1090
+ var h;
1091
+ if (!e) return [];
1092
+ const i = {
1093
+ query: e,
1094
+ caseSensitive: !1,
1095
+ wholeWord: !1,
1096
+ regex: !1,
1097
+ ...t
1098
+ }, s = [], n = this.textModel.getText(), { normalizedText: r, normalizedToRawOffsets: o } = this.buildSearchTextAndOffsetMap(n), l = i.caseSensitive ? r : r.toLowerCase(), a = i.caseSensitive ? e : e.toLowerCase();
1099
+ if (i.regex) {
1100
+ let d;
1101
+ try {
1102
+ d = new RegExp(e, i.caseSensitive ? "g" : "gi");
1103
+ } catch (u) {
1104
+ return [];
1105
+ }
1106
+ let c;
1107
+ for (; (c = d.exec(r)) !== null; ) {
1108
+ const u = (h = c[0]) != null ? h : "";
1109
+ if (u.length === 0) {
1110
+ d.lastIndex = c.index + 1;
1111
+ continue;
1112
+ }
1113
+ const g = c.index, f = c.index + u.length;
1114
+ i.wholeWord && !this.isWholeWordBoundary(r, g, f) || this.pushSearchResultFromOffsets(
1115
+ s,
1116
+ g,
1117
+ f,
1118
+ r,
1119
+ o
1120
+ );
1121
+ }
1122
+ } else {
1123
+ let d = 0, c = l.indexOf(a, d);
1124
+ for (; c !== -1; ) {
1125
+ const u = c + a.length;
1126
+ !i.wholeWord || this.isWholeWordBoundary(r, c, u) ? (this.pushSearchResultFromOffsets(
1127
+ s,
1128
+ c,
1129
+ u,
1130
+ r,
1131
+ o
1132
+ ), d = u) : d = c + 1, c = l.indexOf(a, d);
1133
+ }
1134
+ }
1135
+ return s;
1136
+ }
1137
+ pushSearchResultFromOffsets(e, t, i, s, n) {
1138
+ var h, d;
1139
+ const r = (h = n[t]) != null ? h : t, o = (d = n[i]) != null ? d : r, l = this.textModel.offsetToPosition(r), a = this.textModel.offsetToPosition(o);
1140
+ e.push({
1141
+ range: { start: l, end: a },
1142
+ match: s.substring(t, i)
1143
+ });
1144
+ }
1145
+ isWholeWordBoundary(e, t, i) {
1146
+ const s = t > 0 ? e[t - 1] : "", n = i < e.length ? e[i] : "";
1147
+ return !this.isWordChar(s) && !this.isWordChar(n);
1148
+ }
1149
+ isWordChar(e) {
1150
+ return /^[A-Za-z0-9_]$/.test(e);
1151
+ }
1152
+ buildSearchTextAndOffsetMap(e) {
1153
+ const t = [], i = [0];
1154
+ let s = 0;
1155
+ for (let n = 0; n < e.length; n++) {
1156
+ const r = e[n];
1157
+ r === "​" || r === O.CURSOR_SENTINEL || (t.push(r), s += 1, i[s] = n + 1);
1158
+ }
1159
+ return i[s] = e.length, {
1160
+ normalizedText: t.join(""),
1161
+ normalizedToRawOffsets: i
1162
+ };
1163
+ }
1164
+ replace(e, t) {
1165
+ const i = this.getValue();
1166
+ this.suppressHistory || this.pushUndoSnapshot(this.captureHistorySnapshot(i));
1167
+ const s = this.textModel.replaceRange(e, t);
1168
+ this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [s]);
1169
+ }
1170
+ replaceAll(e, t, i = {}) {
1171
+ const s = this.search(e, i);
1172
+ let n = 0;
1173
+ for (let r = s.length - 1; r >= 0; r--)
1174
+ this.replace(s[r].range, t), n++;
1175
+ return n;
1176
+ }
1177
+ // Folding (basic implementation)
1178
+ fold(e) {
1179
+ this.clearPendingHighlightRender();
1180
+ const t = this.normalizeRange(e);
1181
+ if (t.start.line === t.end.line && t.start.column === t.end.column)
1182
+ return;
1183
+ const i = this.folds.findIndex(
1184
+ (n) => this.isSameFoldRange(n, t)
1185
+ ), s = {
1186
+ start: t.start,
1187
+ end: t.end,
1188
+ collapsed: !0,
1189
+ level: 0
1190
+ };
1191
+ i !== -1 ? this.folds[i] = s : (this.folds.push(s), this.folds.sort((n, r) => this.comparePositions(n.start, r.start)));
1192
+ }
1193
+ unfold(e) {
1194
+ this.clearPendingHighlightRender();
1195
+ const t = this.normalizeRange(e);
1196
+ this.folds = this.folds.filter(
1197
+ (i) => !this.isSameFoldRange(i, t)
1198
+ );
1199
+ }
1200
+ getFolds() {
1201
+ return [...this.folds];
1202
+ }
1203
+ // Utilities
1204
+ focus() {
1205
+ this.view.focus();
1206
+ }
1207
+ blur() {
1208
+ this.view.blur();
1209
+ }
1210
+ // Render text using syntax highlighting extension if available
1211
+ // If `restoreSelection` is true (default), the method captures current selection/caret
1212
+ // and restores it after updating the DOM. Callers that will explicitly set the caret
1213
+ // should pass `false` to avoid stomping programmatic cursor changes.
1214
+ renderTextWithHighlight(e, t = !0) {
1215
+ const i = this.extensions.get("syntax-highlighting");
1216
+ if (i && typeof i.highlightHTML == "function")
1217
+ try {
1218
+ if (typeof this.view.setHighlightHTML == "function") {
1219
+ const g = this.view.getContentElement();
1220
+ (g.querySelector(
1221
+ "[data-lce-fold-placeholder]"
1222
+ ) || g.textContent !== e) && this.view.setText(e);
1223
+ const f = typeof i.highlight == "function" ? i.highlight(e) : i.highlightHTML(e);
1224
+ this.view.setHighlightHTML(f), this.view.syncTrailingNewlineMarkerForText(e), this.scheduleDecorationRender();
1225
+ return;
1226
+ }
1227
+ const s = !t && !this.expectingProgrammaticCursor;
1228
+ let n, r, o, l;
1229
+ const a = this.view.getSelectionState(), h = a.isInEditor && !!a.cursor;
1230
+ (t || s) && h && (n = a.isCollapsed ? void 0 : a.range, r = this.textModel.positionToOffset(a.cursor), n && (o = this.textModel.positionToOffset(n.start), l = this.textModel.positionToOffset(n.end)));
1231
+ const d = h && (t || s) && !n && r !== void 0 && this.hasCollapsedSelectionInEditor(), c = d ? this.insertSentinelAtOffset(e, r) : e, u = typeof i.highlight == "function" ? i.highlight(c) : i.highlightHTML(c);
1232
+ typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && h && requestAnimationFrame(() => {
1233
+ try {
1234
+ if (d && this.restoreCursorFromSentinel()) {
1235
+ this.view.ensureCaretVisible();
1236
+ return;
1237
+ }
1238
+ if (n && (o !== void 0 || l !== void 0)) {
1239
+ const g = o !== void 0 ? o : r, f = l !== void 0 ? l : r, p = Math.min(g, f), m = Math.max(g, f), x = this.textModel.offsetToPosition(p), v = this.textModel.offsetToPosition(m);
1240
+ this.view.setSelectionRange({ start: x, end: v });
1241
+ } else if (r !== void 0) {
1242
+ const g = this.textModel.offsetToPosition(r);
1243
+ this.view.setCursorPosition(g);
1244
+ }
1245
+ } catch (g) {
1246
+ }
1247
+ }), this.scheduleDecorationRender();
1248
+ return;
1249
+ } catch (s) {
1250
+ console.warn("Syntax highlighting failed, falling back to plain text", s);
1251
+ }
1252
+ this.view.setText(e), this.scheduleDecorationRender();
1253
+ }
1254
+ hasCollapsedSelectionInEditor() {
1255
+ const e = window.getSelection();
1256
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
1257
+ return !1;
1258
+ const t = e.getRangeAt(0);
1259
+ return this.view.getContentElement().contains(t.commonAncestorContainer);
1260
+ }
1261
+ getCollapsedSelectionOffsetInEditor() {
1262
+ const e = window.getSelection();
1263
+ if (!e || e.rangeCount === 0 || !e.isCollapsed)
1264
+ return;
1265
+ const t = e.getRangeAt(0), i = this.view.getContentElement();
1266
+ if (!i.contains(t.commonAncestorContainer))
1267
+ return;
1268
+ const s = t.cloneRange();
1269
+ return s.selectNodeContents(i), s.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(s.toString()).length;
1270
+ }
1271
+ stripVirtualMarkers(e) {
1272
+ return e.replace(/\u200B/g, "").split(O.CURSOR_SENTINEL).join("");
1273
+ }
1274
+ insertSentinelAtOffset(e, t) {
1275
+ const i = Math.max(0, Math.min(t, e.length));
1276
+ return e.slice(0, i) + O.CURSOR_SENTINEL + e.slice(i);
1277
+ }
1278
+ restoreCursorFromSentinel() {
1279
+ var o;
1280
+ const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
1281
+ let s = i.nextNode(), n = null, r = 0;
1282
+ for (; s; ) {
1283
+ const l = (o = s.textContent) != null ? o : "", a = l.indexOf(O.CURSOR_SENTINEL);
1284
+ a !== -1 && (n || (n = s, r = a), s.textContent = l.split(O.CURSOR_SENTINEL).join("")), s = i.nextNode();
1285
+ }
1286
+ if (!n || !t) return !1;
1287
+ try {
1288
+ const l = document.createRange();
1289
+ return l.setStart(n, r), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
1290
+ } catch (l) {
1291
+ return !1;
1292
+ }
1293
+ }
1294
+ destroy() {
1295
+ var e;
1296
+ if (!this.isDestroyed) {
1297
+ this.isDestroyed = !0, this.highlightTimeout && (clearTimeout(this.highlightTimeout), this.highlightTimeout = null), this.pendingInputSnapshot = void 0, this.documentSelectionChangeHandler && (document.removeEventListener("selectionchange", this.documentSelectionChangeHandler), this.documentSelectionChangeHandler = void 0), this.decorationRenderRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.decorationRenderRaf), this.decorationRenderRaf = null), (e = this.decorationMutationObserver) == null || e.disconnect(), this.decorationMutationObserver = null, this.clearInlineDecorationHighlights(!0), this.decorationLayers.clear(), this.view.clearDecorations();
1298
+ for (const t of this.extensions.values())
1299
+ t.destroy && t.destroy();
1300
+ this.extensions.clear(), this.view.destroy(), this.commands.clear(), this.eventListeners.clear();
1301
+ }
1302
+ }
1303
+ // History: undo/redo
1304
+ undo() {
1305
+ if (this.undoStack.length === 0) return;
1306
+ const e = this.undoStack.pop(), t = this.captureHistorySnapshot();
1307
+ this.pushSnapshot(this.redoStack, t);
1308
+ try {
1309
+ this.suppressHistory = !0, this.expectingProgrammaticCursor = !0, this.restoreHistorySnapshot(e), setTimeout(() => {
1310
+ this.expectingProgrammaticCursor = !1;
1311
+ }, 30);
1312
+ } finally {
1313
+ this.suppressHistory = !1;
1314
+ }
1315
+ }
1316
+ redo() {
1317
+ if (this.redoStack.length === 0) return;
1318
+ const e = this.redoStack.pop(), t = this.captureHistorySnapshot();
1319
+ this.pushSnapshot(this.undoStack, t);
1320
+ try {
1321
+ this.suppressHistory = !0, this.expectingProgrammaticCursor = !0, this.restoreHistorySnapshot(e), setTimeout(() => {
1322
+ this.expectingProgrammaticCursor = !1;
1323
+ }, 30);
1324
+ } finally {
1325
+ this.suppressHistory = !1;
1326
+ }
1327
+ }
1328
+ // Insert a tab character or spaces at current cursor
1329
+ insertTab() {
1330
+ if (this.config.readOnly) return;
1331
+ const e = " ".repeat(this.config.tabSize || 2);
1332
+ this.replaceSelectionWithText(e);
1333
+ }
1334
+ // Insert a newline at current cursor position
1335
+ insertNewLine() {
1336
+ this.config.readOnly || this.replaceSelectionWithText(`
1337
+ `);
1338
+ }
1339
+ deleteBackward() {
1340
+ this.config.readOnly || this.deleteUsingDirection("backward");
1341
+ }
1342
+ deleteForward() {
1343
+ this.config.readOnly || this.deleteUsingDirection("forward");
1344
+ }
1345
+ deleteSelection() {
1346
+ if (this.config.readOnly) return;
1347
+ const e = this.textModel.getText(), { startOffset: t, endOffset: i } = this.getActiveSelectionOffsets(e), s = Math.min(t, i), n = Math.max(t, i);
1348
+ s !== n && this.replaceOffsetsWithText(s, n, "");
1349
+ }
1350
+ // Events
1351
+ on(e, t) {
1352
+ this.eventListeners.has(e) || this.eventListeners.set(e, []), this.eventListeners.get(e).push(t);
1353
+ }
1354
+ off(e, t) {
1355
+ if (!this.eventListeners.has(e)) return;
1356
+ const i = this.eventListeners.get(e);
1357
+ if (t) {
1358
+ const s = i.indexOf(t);
1359
+ s !== -1 && i.splice(s, 1);
1360
+ } else
1361
+ i.length = 0;
1362
+ }
1363
+ normalizeRange(e) {
1364
+ return this.comparePositions(e.start, e.end) <= 0 ? e : { start: e.end, end: e.start };
1365
+ }
1366
+ comparePositions(e, t) {
1367
+ return e.line !== t.line ? e.line - t.line : e.column - t.column;
1368
+ }
1369
+ captureHistorySnapshot(e = this.textModel.getText()) {
1370
+ const t = this.view.getSelectionState(), i = t.isInEditor && !t.isCollapsed ? t.range : void 0, s = t.isInEditor && t.cursor ? t.cursor : void 0, n = i != null ? i : this.lastKnownSelection, r = s != null ? s : this.lastKnownCursor, o = this.clampPositionToText(r, e), l = {
1371
+ text: e,
1372
+ cursorOffset: this.positionToOffsetInText(o, e)
1373
+ };
1374
+ if (n) {
1375
+ const a = this.clampPositionToText(n.start, e), h = this.clampPositionToText(n.end, e);
1376
+ l.anchorOffset = this.positionToOffsetInText(a, e), l.focusOffset = this.positionToOffsetInText(h, e);
1377
+ }
1378
+ return l;
1379
+ }
1380
+ restoreHistorySnapshot(e) {
1381
+ this.setValue(e.text), requestAnimationFrame(() => {
1382
+ try {
1383
+ if (e.anchorOffset !== void 0 && e.focusOffset !== void 0 && e.anchorOffset !== e.focusOffset) {
1384
+ const t = Math.min(e.anchorOffset, e.focusOffset), i = Math.max(e.anchorOffset, e.focusOffset);
1385
+ this.setSelection({
1386
+ start: this.textModel.offsetToPosition(t),
1387
+ end: this.textModel.offsetToPosition(i)
1388
+ });
1389
+ return;
1390
+ }
1391
+ this.setCursor(this.textModel.offsetToPosition(e.cursorOffset));
1392
+ } catch (t) {
1393
+ }
1394
+ });
1395
+ }
1396
+ pushUndoSnapshot(e) {
1397
+ this.pushSnapshot(this.undoStack, e), this.redoStack.length = 0;
1398
+ }
1399
+ pushSnapshot(e, t) {
1400
+ e.push(t), e.length > 100 && e.shift();
1401
+ }
1402
+ clampPositionToText(e, t) {
1403
+ var r, o;
1404
+ const i = t.split(`
1405
+ `), s = Math.max(0, Math.min(e.line, i.length - 1)), n = Math.max(
1406
+ 0,
1407
+ Math.min(e.column, (o = (r = i[s]) == null ? void 0 : r.length) != null ? o : 0)
1408
+ );
1409
+ return {
1410
+ line: s,
1411
+ column: n
1412
+ };
1413
+ }
1414
+ positionToOffsetInText(e, t) {
1415
+ var r, o;
1416
+ const i = t.split(`
1417
+ `), s = this.clampPositionToText(e, t);
1418
+ let n = 0;
1419
+ for (let l = 0; l < s.line; l++)
1420
+ n += ((o = (r = i[l]) == null ? void 0 : r.length) != null ? o : 0) + 1;
1421
+ return n + s.column;
1422
+ }
1423
+ clearPendingHighlightRender() {
1424
+ this.highlightTimeout && (clearTimeout(this.highlightTimeout), this.highlightTimeout = null);
1425
+ }
1426
+ hasRenderedFoldPlaceholders() {
1427
+ return !!this.view.getContentElement().querySelector("[data-lce-fold-placeholder]");
1428
+ }
1429
+ replaceSelectionWithText(e) {
1430
+ const t = e.replace(/\r\n?/g, `
1431
+ `), i = this.textModel.getText(), { startOffset: s, endOffset: n } = this.getActiveSelectionOffsets(i), r = Math.max(0, Math.min(s, n)), o = Math.max(0, Math.max(s, n));
1432
+ return this.replaceOffsetsWithText(r, o, t);
1433
+ }
1434
+ insertClipboardText(e) {
1435
+ this.pendingInputSnapshot = this.captureHistorySnapshot(), this.lastProgrammaticClipboardInsertAt = Date.now(), this.replaceSelectionWithText(this.normalizeClipboardText(e));
1436
+ }
1437
+ normalizeClipboardText(e) {
1438
+ return e.replace(/\r\n?/g, `
1439
+ `).replace(/\u00a0/g, " ");
1440
+ }
1441
+ getPlainTextFromDataTransfer(e) {
1442
+ if (!e)
1443
+ return "";
1444
+ const t = e.getData("text/plain");
1445
+ if (t)
1446
+ return t;
1447
+ const i = e.getData("text/html");
1448
+ return i ? this.htmlClipboardToPlainText(i) : "";
1449
+ }
1450
+ htmlClipboardToPlainText(e) {
1451
+ const t = document.implementation.createHTMLDocument("");
1452
+ t.body.innerHTML = e;
1453
+ const i = /* @__PURE__ */ new Set([
1454
+ "ADDRESS",
1455
+ "ARTICLE",
1456
+ "ASIDE",
1457
+ "BLOCKQUOTE",
1458
+ "BR",
1459
+ "DD",
1460
+ "DIV",
1461
+ "DL",
1462
+ "DT",
1463
+ "FIGCAPTION",
1464
+ "FIGURE",
1465
+ "FOOTER",
1466
+ "H1",
1467
+ "H2",
1468
+ "H3",
1469
+ "H4",
1470
+ "H5",
1471
+ "H6",
1472
+ "HEADER",
1473
+ "HR",
1474
+ "LI",
1475
+ "MAIN",
1476
+ "NAV",
1477
+ "OL",
1478
+ "P",
1479
+ "PRE",
1480
+ "SECTION",
1481
+ "TABLE",
1482
+ "TR",
1483
+ "UL"
1484
+ ]), s = (o) => {
1485
+ var l;
1486
+ for (let a = o.length - 1; a >= 0; a--) {
1487
+ const h = (l = o[a]) != null ? l : "";
1488
+ if (h.length !== 0)
1489
+ return h.endsWith(`
1490
+ `);
1491
+ }
1492
+ return !1;
1493
+ }, n = (o, l) => {
1494
+ if (o instanceof Text) {
1495
+ l.push(o.data);
1496
+ return;
1497
+ }
1498
+ if (!(o instanceof HTMLElement)) {
1499
+ o.childNodes.forEach((h) => n(h, l));
1500
+ return;
1501
+ }
1502
+ if (o.tagName === "BR") {
1503
+ l.push(`
1504
+ `);
1505
+ return;
1506
+ }
1507
+ const a = i.has(o.tagName);
1508
+ a && l.length > 0 && !s(l) && l.push(`
1509
+ `), o.childNodes.forEach((h) => n(h, l)), a && !s(l) && l.push(`
1510
+ `);
1511
+ }, r = [];
1512
+ return t.body.childNodes.forEach((o) => n(o, r)), r.join("").replace(/\n{3,}/g, `
1513
+
1514
+ `).replace(/[ \t]+\n/g, `
1515
+ `).trimEnd();
1516
+ }
1517
+ getActiveSelectionOffsets(e) {
1518
+ const t = this.view.getSelectionOffsets();
1519
+ if (t.isInEditor)
1520
+ return {
1521
+ startOffset: t.startOffset,
1522
+ endOffset: t.endOffset
1523
+ };
1524
+ if (this.lastKnownSelection)
1525
+ return {
1526
+ startOffset: this.positionToOffsetInText(this.lastKnownSelection.start, e),
1527
+ endOffset: this.positionToOffsetInText(this.lastKnownSelection.end, e)
1528
+ };
1529
+ const i = this.positionToOffsetInText(this.lastKnownCursor, e);
1530
+ return {
1531
+ startOffset: i,
1532
+ endOffset: i
1533
+ };
1534
+ }
1535
+ deleteUsingDirection(e) {
1536
+ const t = this.textModel.getText(), { startOffset: i, endOffset: s } = this.getActiveSelectionOffsets(t), n = Math.min(i, s), r = Math.max(i, s);
1537
+ if (n !== r) {
1538
+ this.replaceOffsetsWithText(n, r, "");
1539
+ return;
1540
+ }
1541
+ if (e === "backward") {
1542
+ if (n === 0)
1543
+ return;
1544
+ this.replaceOffsetsWithText(n - 1, n, "");
1545
+ return;
1546
+ }
1547
+ r >= t.length || this.replaceOffsetsWithText(r, r + 1, "");
1548
+ }
1549
+ replaceOffsetsWithText(e, t, i) {
1550
+ var u;
1551
+ this.ensureEditableSurfaceIsUnfolded();
1552
+ const s = i.replace(/\r\n?/g, `
1553
+ `), n = this.textModel.getText(), r = (u = this.pendingInputSnapshot) != null ? u : this.captureHistorySnapshot(n), o = Math.max(0, Math.min(e, n.length)), l = Math.max(0, Math.min(t, n.length)), a = Math.min(o, l), h = Math.max(o, l), d = this.textModel.replaceRange(
1554
+ {
1555
+ start: this.textModel.offsetToPosition(a),
1556
+ end: this.textModel.offsetToPosition(h)
1557
+ },
1558
+ s
1559
+ );
1560
+ this.pendingInputSnapshot = void 0, this.suppressHistory || this.pushUndoSnapshot(r);
1561
+ const c = a + s.length;
1562
+ return this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), this.setCursor(this.textModel.offsetToPosition(c)), setTimeout(() => {
1563
+ this.expectingProgrammaticCursor = !1;
1564
+ }, 20), this.emit("change", [d]), d;
1565
+ }
1566
+ ensureEditableSurfaceIsUnfolded() {
1567
+ !this.hasRenderedFoldPlaceholders() && this.folds.length === 0 || (this.clearPendingHighlightRender(), this.folds = [], this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), setTimeout(() => {
1568
+ this.expectingProgrammaticCursor = !1;
1569
+ }, 20));
1570
+ }
1571
+ syncSelectionCacheFromView() {
1572
+ const e = this.view.getSelectionState();
1573
+ return e.isInEditor && e.cursor && (this.lastKnownCursor = e.cursor, this.lastKnownSelection = e.isCollapsed ? void 0 : e.range), e;
1574
+ }
1575
+ isSameFoldRange(e, t) {
1576
+ return e.start.line === t.start.line && e.start.column === t.start.column && e.end.line === t.end.line && e.end.column === t.end.column;
1577
+ }
1578
+ scheduleDecorationRender() {
1579
+ if (!this.isDestroyed) {
1580
+ if (typeof requestAnimationFrame != "function") {
1581
+ this.applyDecorations();
1582
+ return;
1583
+ }
1584
+ this.decorationRenderRaf === null && (this.decorationRenderRaf = requestAnimationFrame(() => {
1585
+ this.decorationRenderRaf = null, this.applyDecorations();
1586
+ }));
1587
+ }
1588
+ }
1589
+ applyDecorations() {
1590
+ if (this.isDestroyed)
1591
+ return;
1592
+ if (this.decorationLayers.size === 0) {
1593
+ this.view.clearDecorations(), this.clearInlineDecorationHighlights();
1594
+ return;
1595
+ }
1596
+ const e = [], t = [], i = [];
1597
+ for (const [s, n] of this.decorationLayers.entries())
1598
+ for (const r of n) {
1599
+ const o = `${s}::${r.id}`;
1600
+ if (r.type === "line") {
1601
+ e.push({
1602
+ ...r,
1603
+ id: o
1604
+ });
1605
+ continue;
1606
+ }
1607
+ if (r.type === "gutter") {
1608
+ t.push({
1609
+ ...r,
1610
+ id: o
1611
+ });
1612
+ continue;
1613
+ }
1614
+ i.push({
1615
+ ...r,
1616
+ id: o
1617
+ });
1618
+ }
1619
+ this.view.setDecorations(
1620
+ this.normalizeLineDecorations(e),
1621
+ this.normalizeGutterDecorations(t)
1622
+ ), this.renderInlineDecorations(i);
1623
+ }
1624
+ normalizeLineDecorations(e) {
1625
+ const t = Math.max(0, this.textModel.getLineCount() - 1);
1626
+ return e.filter((i) => Number.isFinite(i.line)).map((i) => ({
1627
+ ...i,
1628
+ line: Math.max(0, Math.min(t, Math.floor(i.line))),
1629
+ style: i.style ? { ...i.style } : void 0
1630
+ }));
1631
+ }
1632
+ normalizeGutterDecorations(e) {
1633
+ const t = Math.max(0, this.textModel.getLineCount() - 1);
1634
+ return e.filter((i) => Number.isFinite(i.line)).map((i) => ({
1635
+ ...i,
1636
+ line: Math.max(0, Math.min(t, Math.floor(i.line))),
1637
+ style: i.style ? { ...i.style } : void 0
1638
+ }));
1639
+ }
1640
+ renderInlineDecorations(e) {
1641
+ if (!this.hasCustomDecorationHighlightSupport) {
1642
+ this.clearInlineDecorationHighlights();
1643
+ return;
1644
+ }
1645
+ const t = CSS, i = window.Highlight;
1646
+ if (!t.highlights || !i) {
1647
+ this.clearInlineDecorationHighlights();
1648
+ return;
1649
+ }
1650
+ if (this.clearInlineDecorationHighlights(), e.length === 0)
1651
+ return;
1652
+ const s = this.textModel.getText(), n = [];
1653
+ let r = 0;
1654
+ for (const l of e) {
1655
+ if (r >= this.decorationHighlightLimit)
1656
+ break;
1657
+ const a = this.normalizeInlineDecoration(l, s);
1658
+ if (!a)
1659
+ continue;
1660
+ const h = this.view.createDomRangeFromRange(a.range);
1661
+ if (!h)
1662
+ continue;
1663
+ const d = this.buildInlineDecorationHighlightName(
1664
+ a.id
1665
+ );
1666
+ t.highlights.set(d, new i(h)), this.inlineDecorationHighlightNames.add(d), n.push(`
1667
+ ::highlight(${d}) {
1668
+ ${this.serializeInlineDecorationStyle(a.style)}
1669
+ }
1670
+ `), r += 1;
1671
+ }
1672
+ const o = this.ensureDecorationHighlightStyleNode();
1673
+ o.textContent = n.join(`
1674
+ `);
1675
+ }
1676
+ normalizeInlineDecoration(e, t) {
1677
+ const i = this.normalizeRange({
1678
+ start: this.clampPositionToText(e.range.start, t),
1679
+ end: this.clampPositionToText(e.range.end, t)
1680
+ });
1681
+ return i.start.line === i.end.line && i.start.column === i.end.column ? null : {
1682
+ ...e,
1683
+ range: i,
1684
+ style: e.style ? { ...e.style } : void 0
1685
+ };
1686
+ }
1687
+ clearInlineDecorationHighlights(e = !1) {
1688
+ try {
1689
+ const i = CSS;
1690
+ if (i.highlights)
1691
+ for (const s of this.inlineDecorationHighlightNames)
1692
+ i.highlights.delete(s);
1693
+ } catch (i) {
1694
+ }
1695
+ if (this.inlineDecorationHighlightNames.clear(), typeof document > "u")
1696
+ return;
1697
+ const t = document.getElementById(this.decorationHighlightStyleId);
1698
+ if (e) {
1699
+ t != null && t.parentNode && t.parentNode.removeChild(t);
1700
+ return;
1701
+ }
1702
+ t && (t.textContent = "");
1703
+ }
1704
+ ensureDecorationHighlightStyleNode() {
1705
+ let e = document.getElementById(
1706
+ this.decorationHighlightStyleId
1707
+ );
1708
+ return e || (e = document.createElement("style"), e.id = this.decorationHighlightStyleId, document.head.appendChild(e), e);
1709
+ }
1710
+ observeDecorationRelevantMutations() {
1711
+ typeof MutationObserver > "u" || (this.decorationMutationObserver = new MutationObserver(() => {
1712
+ this.decorationLayers.size !== 0 && this.scheduleDecorationRender();
1713
+ }), this.decorationMutationObserver.observe(this.view.getContentElement(), {
1714
+ childList: !0,
1715
+ subtree: !0,
1716
+ characterData: !0
1717
+ }));
1718
+ }
1719
+ detectCustomHighlightSupport() {
1720
+ try {
1721
+ if (typeof CSS > "u" || typeof window > "u")
1722
+ return !1;
1723
+ const e = CSS, t = window.Highlight;
1724
+ return !!e.highlights && !!t;
1725
+ } catch (e) {
1726
+ return !1;
1727
+ }
1728
+ }
1729
+ buildInlineDecorationHighlightName(e) {
1730
+ return `editora-decoration-${this.editorInstanceId}-${this.sanitizeHighlightIdentifier(e)}`;
1731
+ }
1732
+ sanitizeHighlightIdentifier(e) {
1733
+ return e.toLowerCase().replace(/[^a-z0-9_-]+/g, "-");
1734
+ }
1735
+ serializeInlineDecorationStyle(e) {
1736
+ return this.serializeStyleObject(e) || "background-color: var(--lce-inline-decoration-bg, rgba(86, 156, 214, 0.18)); border-radius: 2px;";
1737
+ }
1738
+ serializeStyleObject(e) {
1739
+ return e ? Object.entries(e).filter(([, t]) => typeof t == "string" && t.length > 0).map(([t, i]) => `${this.toKebabCase(t)}: ${i};`).join(" ") : "";
1740
+ }
1741
+ toKebabCase(e) {
1742
+ return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
1743
+ }
1744
+ cloneDecoration(e) {
1745
+ return e.type === "inline" ? {
1746
+ ...e,
1747
+ range: {
1748
+ start: { ...e.range.start },
1749
+ end: { ...e.range.end }
1750
+ },
1751
+ style: e.style ? { ...e.style } : void 0
1752
+ } : {
1753
+ ...e,
1754
+ style: e.style ? { ...e.style } : void 0
1755
+ };
1756
+ }
1757
+ };
1758
+ U.CURSOR_SENTINEL = "";
1759
+ let Y = U;
1760
+ class J {
1761
+ constructor(e) {
1762
+ this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
1763
+ }
1764
+ setup(e) {
1765
+ this.editor = e;
1766
+ }
1767
+ handleKeyDown(e) {
1768
+ if (!this.editor) return;
1769
+ const t = this.findMatchingBinding(e);
1770
+ if (t)
1771
+ return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
1772
+ }
1773
+ findMatchingBinding(e) {
1774
+ const { key: t, ctrlKey: i, altKey: s, shiftKey: n, metaKey: r } = e, o = String(t).toLowerCase(), l = this.keymap[o];
1775
+ if (!l) return null;
1776
+ for (const a of l) {
1777
+ const h = a.ctrlKey === void 0 || a.ctrlKey === i, d = a.altKey === void 0 || a.altKey === s, c = a.shiftKey === void 0 || a.shiftKey === n, u = a.metaKey === void 0 || a.metaKey === r;
1778
+ if (h && d && c && u)
1779
+ return a;
1780
+ }
1781
+ return null;
1782
+ }
1783
+ // Allow EditorCore to call this directly when checking extension.onKeyDown
1784
+ onKeyDown(e) {
1785
+ return this.handleKeyDown(e);
1786
+ }
1787
+ getDefaultKeymap() {
1788
+ const e = {};
1789
+ 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"), this.addBinding(e, "f", { altKey: !0, shiftKey: !0 }, "formatDocument"), e;
1790
+ }
1791
+ addBinding(e, t, i, s) {
1792
+ const n = t.toLowerCase();
1793
+ e[n] || (e[n] = []), e[n].push({
1794
+ key: n,
1795
+ command: s,
1796
+ ...i
1797
+ });
1798
+ }
1799
+ // Public API for customizing keymap
1800
+ setKeymap(e) {
1801
+ this.keymap = { ...e };
1802
+ }
1803
+ addKeyBinding(e) {
1804
+ const t = e.key.toLowerCase();
1805
+ this.keymap[t] || (this.keymap[t] = []), this.keymap[t] = this.keymap[t].filter((i) => i.command !== e.command), this.keymap[t].push({
1806
+ ...e,
1807
+ key: t
1808
+ });
1809
+ }
1810
+ removeKeyBinding(e, t) {
1811
+ const i = e.toLowerCase();
1812
+ t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((s) => s.command !== t), this.keymap[i].length === 0 && delete this.keymap[i]) : delete this.keymap[i];
1813
+ }
1814
+ getKeymap() {
1815
+ return { ...this.keymap };
1816
+ }
1817
+ getBindingsForCommand(e) {
1818
+ const t = [];
1819
+ for (const i in this.keymap)
1820
+ for (const s of this.keymap[i])
1821
+ s.command === e && t.push({ ...s });
1822
+ return t;
1823
+ }
1824
+ getPlatformInfo() {
1825
+ return {
1826
+ isMac: this.isMac,
1827
+ platform: navigator.platform
1828
+ };
1829
+ }
1830
+ destroy() {
1831
+ this.keymap = {}, this.editor = null;
1832
+ }
1833
+ }
1834
+ const W = class V {
1835
+ constructor() {
1836
+ this.name = "transaction", this.transactions = [];
1837
+ }
1838
+ setup(e) {
1839
+ e.on("change", (t) => {
1840
+ const i = {
1841
+ changes: t,
1842
+ selection: e.getSelection(),
1843
+ effects: [],
1844
+ annotations: []
1845
+ };
1846
+ this.transactions.push(i), this.transactions.length > V.MAX_TRANSACTIONS && this.transactions.splice(
1847
+ 0,
1848
+ this.transactions.length - V.MAX_TRANSACTIONS
1849
+ );
1850
+ });
1851
+ }
1852
+ getTransactions() {
1853
+ return this.transactions;
1854
+ }
1855
+ destroy() {
1856
+ this.transactions = [];
1857
+ }
1858
+ };
1859
+ W.MAX_TRANSACTIONS = 200;
1860
+ let ee = W;
1861
+ class te {
1862
+ constructor() {
1863
+ this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
1864
+ }
1865
+ setup(e) {
1866
+ this.editor = e, this.isEnabled = e.getConfig().lineNumbers !== !1, this.createLineNumbers(), e.registerCommand("toggleLineNumbers", () => {
1867
+ this.toggle();
1868
+ }), e.on("change", () => {
1869
+ this.updateLineNumbers();
1870
+ }), this.updateLineNumbers();
1871
+ }
1872
+ createLineNumbers() {
1873
+ if (!this.editor) return;
1874
+ const e = this.editor.getView(), t = e.getLineNumbersElement();
1875
+ t && (this.lineNumbersElement = t, e.setLineNumbersVisible(this.isEnabled));
1876
+ }
1877
+ updateLineNumbers() {
1878
+ if (!this.lineNumbersElement || !this.editor || !this.isEnabled) return;
1879
+ const e = this.editor.getValue().split(`
1880
+ `).length;
1881
+ this.editor.getView().updateLineNumbers(e);
1882
+ }
1883
+ toggle() {
1884
+ this.editor && (this.isEnabled = !this.isEnabled, this.editor.getView().setLineNumbersVisible(this.isEnabled), this.lineNumbersElement && (this.lineNumbersElement.style.display = this.isEnabled ? "table-cell" : "none"), this.updateLineNumbers());
1885
+ }
1886
+ destroy() {
1887
+ this.lineNumbersElement = null, this.editor = null;
1888
+ }
1889
+ }
1890
+ class ie {
1891
+ constructor() {
1892
+ this.name = "theme", this.editor = null, this.currentTheme = "dark";
1893
+ }
1894
+ setup(e) {
1895
+ this.editor = e, e.registerCommand("setTheme", (t) => {
1896
+ this.setTheme(t);
1897
+ }), e.registerCommand("toggleTheme", () => {
1898
+ this.toggleTheme();
1899
+ }), this.setTheme(this.currentTheme);
1900
+ }
1901
+ setTheme(e) {
1902
+ this.editor && (this.currentTheme = e, this.editor.setTheme(e));
1903
+ }
1904
+ toggleTheme() {
1905
+ const e = this.currentTheme === "dark" ? "light" : "dark";
1906
+ this.setTheme(e);
1907
+ }
1908
+ getCurrentTheme() {
1909
+ return this.currentTheme;
1910
+ }
1911
+ destroy() {
1912
+ this.editor = null;
1913
+ }
1914
+ }
1915
+ class se {
1916
+ constructor() {
1917
+ this.name = "read-only", this.editor = null, this.isReadOnly = !1;
1918
+ }
1919
+ setup(e) {
1920
+ this.editor = e, e.registerCommand("setReadOnly", (t) => {
1921
+ this.setReadOnly(t);
1922
+ }), e.registerCommand("toggleReadOnly", () => {
1923
+ this.toggleReadOnly();
1924
+ }), e.on("keydown", (t) => {
1925
+ if (t.ctrlKey && t.key === "r")
1926
+ return t.preventDefault(), this.toggleReadOnly(), !1;
1927
+ });
1928
+ }
1929
+ setReadOnly(e) {
1930
+ this.editor && (this.isReadOnly = e, this.editor.setReadOnly(e));
1931
+ }
1932
+ toggleReadOnly() {
1933
+ this.setReadOnly(!this.isReadOnly);
1934
+ }
1935
+ isCurrentlyReadOnly() {
1936
+ return this.isReadOnly;
1937
+ }
1938
+ destroy() {
1939
+ this.editor = null;
1940
+ }
1941
+ }
1942
+ let ne = 0;
1943
+ const K = class y {
1944
+ constructor(e = {}) {
1945
+ 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 = {
1946
+ caseSensitive: !1,
1947
+ wholeWord: !1,
1948
+ regex: !1
1949
+ }, this.trailingMarkerAttr = "data-lce-trailing-newline-marker", this.editorContainerSelector = '[data-lce-editor-container="true"]', this.highlightId = ++ne, 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 = {
1950
+ replaceAndFindNext: !0,
1951
+ ...e
1952
+ };
1953
+ }
1954
+ setup(e) {
1955
+ this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && this.ensureHighlightStyles(), e.registerCommand("find", () => {
1956
+ this.showSearch();
1957
+ }), e.registerCommand("findNext", () => {
1958
+ this.findNext();
1959
+ }), e.registerCommand("findPrev", () => {
1960
+ this.findPrev();
1961
+ }), e.registerCommand("replace", () => {
1962
+ this.showReplace();
1963
+ }), e.registerCommand("replaceAll", (t, i) => {
1964
+ this.replaceAll(t, i);
1965
+ }), this.editorChangeHandler = () => {
1966
+ !this.isVisible || !this.currentQuery || this.scheduleLiveRefresh(!0);
1967
+ }, e.on("change", this.editorChangeHandler);
1968
+ }
1969
+ showSearch() {
1970
+ 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));
1971
+ }
1972
+ showReplace() {
1973
+ this.showSearch(), this.replaceInputEl && (this.replaceInputEl.style.display = "block", this.replaceInputEl.focus()), this.updateModeHint(!0), this.currentQuery && this.performSearch(this.currentQuery, !1, !0);
1974
+ }
1975
+ hideSearch() {
1976
+ 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();
1977
+ }
1978
+ createSearchUI() {
1979
+ if (!this.editor) return;
1980
+ const e = this.editor.getView().getContentElement(), t = e.closest(
1981
+ this.editorContainerSelector
1982
+ ), i = t == null ? void 0 : t.parentElement, s = e.closest(".rte-source-editor-modal") || i || t || e.parentElement;
1983
+ if (!s) return;
1984
+ window.getComputedStyle(s).position === "static" && (s.style.position = "relative"), this.searchUI = document.createElement("div"), this.searchUI.className = y.css.root, this.searchUI.style.display = "none", this.searchUI.innerHTML = `
1985
+ <div class="${y.css.row}">
1986
+ <input type="text" class="${y.css.findInput} ${y.css.inputBase}" placeholder="Find..." />
1987
+ <button class="${y.css.prevButton} ${y.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
1988
+ <button class="${y.css.nextButton} ${y.css.buttonBase}" type="button" aria-label="Next match">↓</button>
1989
+ <button class="${y.css.closeButton} ${y.css.buttonBase}" type="button" aria-label="Close search">×</button>
1990
+ </div>
1991
+ <div class="${y.css.options}">
1992
+ <label class="${y.css.optionLabel}" title="Case sensitive">
1993
+ <input type="checkbox" class="${y.css.optionInput} ${y.css.caseSensitive}" />
1994
+ <span>Aa</span>
1995
+ </label>
1996
+ <label class="${y.css.optionLabel}" title="Whole word">
1997
+ <input type="checkbox" class="${y.css.optionInput} ${y.css.wholeWord}" />
1998
+ <span>Whole</span>
1999
+ </label>
2000
+ <label class="${y.css.optionLabel}" title="Regular expression">
2001
+ <input type="checkbox" class="${y.css.optionInput} ${y.css.regex}" />
2002
+ <span>.*</span>
2003
+ </label>
2004
+ </div>
2005
+ <div class="${y.css.meta}">
2006
+ <div class="${y.css.status} ${y.css.statusLayout}"></div>
2007
+ <div class="${y.css.mode} ${y.css.modeLayout}" aria-live="polite"></div>
2008
+ </div>
2009
+ <input type="text" class="${y.css.replaceInput} ${y.css.inputBase} ${y.css.replaceInputLayout}" placeholder="Replace with..." />
2010
+ `;
2011
+ const n = this.searchUI.querySelector(
2012
+ `.${y.css.findInput}`
2013
+ ), r = this.searchUI.querySelector(
2014
+ `.${y.css.replaceInput}`
2015
+ ), o = this.searchUI.querySelector(
2016
+ `.${y.css.prevButton}`
2017
+ ), l = this.searchUI.querySelector(
2018
+ `.${y.css.nextButton}`
2019
+ ), a = this.searchUI.querySelector(
2020
+ `.${y.css.closeButton}`
2021
+ ), h = this.searchUI.querySelector(
2022
+ `.${y.css.status}`
2023
+ ), d = this.searchUI.querySelector(
2024
+ `.${y.css.mode}`
2025
+ ), c = this.searchUI.querySelector(
2026
+ `.${y.css.caseSensitive}`
2027
+ ), u = this.searchUI.querySelector(
2028
+ `.${y.css.wholeWord}`
2029
+ ), g = this.searchUI.querySelector(
2030
+ `.${y.css.regex}`
2031
+ );
2032
+ this.findInput = n, this.replaceInputEl = r, this.statusDiv = h, this.modeDiv = d, this.caseSensitiveInput = c, this.wholeWordInput = u, this.regexInput = g, c.checked = !!this.searchOptions.caseSensitive, u.checked = !!this.searchOptions.wholeWord, g.checked = !!this.searchOptions.regex, n.addEventListener("input", () => {
2033
+ this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
2034
+ const p = n.value;
2035
+ this.searchDebounceTimer = setTimeout(() => {
2036
+ this.performSearch(p, !1, !1);
2037
+ }, 120);
2038
+ });
2039
+ const f = () => {
2040
+ this.searchOptions.caseSensitive = c.checked, this.searchOptions.wholeWord = u.checked, this.searchOptions.regex = g.checked;
2041
+ const p = n.value;
2042
+ p.trim() ? this.performSearch(p, !1, !1) : this.performSearch("", !1, !1);
2043
+ };
2044
+ c.addEventListener("change", f), u.addEventListener("change", f), g.addEventListener("change", f), n.addEventListener("keydown", (p) => {
2045
+ p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.findPrev() : this.findNext()) : p.key === "Escape" && (p.preventDefault(), this.hideSearch());
2046
+ }), r.addEventListener("keydown", (p) => {
2047
+ p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.replaceAll(n.value, r.value) : this.replaceCurrent(n.value, r.value)) : p.key === "Escape" && (p.preventDefault(), this.hideSearch());
2048
+ }), o.addEventListener("click", () => this.findPrev()), l.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()), s.appendChild(this.searchUI);
2049
+ }
2050
+ updateModeHint(e) {
2051
+ this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
2052
+ }
2053
+ performSearch(e, t, i) {
2054
+ if (!this.editor || !e.trim()) {
2055
+ this.currentQuery = "", this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("");
2056
+ return;
2057
+ }
2058
+ if (this.searchOptions.regex && !this.isValidRegex(e)) {
2059
+ this.currentQuery = e, this.currentResults = [], this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Invalid regular expression");
2060
+ return;
2061
+ }
2062
+ this.currentQuery = e;
2063
+ const s = this.currentIndex, n = this.editor.search(e, this.searchOptions);
2064
+ if (this.currentResults = n, n.length === 0) {
2065
+ this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
2066
+ return;
2067
+ }
2068
+ t && s >= 0 ? this.currentIndex = Math.min(s, n.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
2069
+ }
2070
+ findNext() {
2071
+ if (this.currentResults.length === 0) {
2072
+ this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
2073
+ return;
2074
+ }
2075
+ this.currentIndex = (this.currentIndex + 1) % this.currentResults.length, this.updateHighlights(!0);
2076
+ }
2077
+ findPrev() {
2078
+ if (this.currentResults.length === 0) {
2079
+ this.currentQuery && this.performSearch(this.currentQuery, !0, !0);
2080
+ return;
2081
+ }
2082
+ this.currentIndex = this.currentIndex <= 0 ? this.currentResults.length - 1 : this.currentIndex - 1, this.updateHighlights(!0);
2083
+ }
2084
+ replaceCurrent(e, t) {
2085
+ 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;
2086
+ const i = this.currentResults[this.currentIndex];
2087
+ if (!i) return;
2088
+ const s = this.computeReplacementRange(i.range.start, t);
2089
+ if (this.editor.replace(i.range, t), this.config.replaceAndFindNext) {
2090
+ this.currentQuery = e;
2091
+ const n = this.editor.search(e, this.searchOptions);
2092
+ if (this.currentResults = n, n.length === 0) {
2093
+ this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
2094
+ return;
2095
+ }
2096
+ this.currentIndex = this.findNextResultIndexAfter(s.end, n), this.updateHighlights(!0);
2097
+ } else
2098
+ this.scrollLogicalRangeIntoView(s, !0), this.performSearch(e, !0, !1);
2099
+ this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
2100
+ }
2101
+ replaceAll(e, t) {
2102
+ if (!this.editor || !e.trim()) return;
2103
+ const i = this.editor.replaceAll(e, t, this.searchOptions);
2104
+ this.performSearch(e, !1, !1), this.showTransientStatus(`Replaced ${i} occurrence${i === 1 ? "" : "s"}`), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
2105
+ }
2106
+ updateHighlights(e) {
2107
+ if (this.clearHighlights(), this.currentResults.length === 0 || this.currentIndex === -1 || !this.editor)
2108
+ return;
2109
+ this.applyCustomHighlights();
2110
+ const t = this.currentResults[this.currentIndex];
2111
+ t && ((e || !this.hasCustomHighlightSupport) && this.navigateToResult(t, !this.hasCustomHighlightSupport), this.updateStatus(
2112
+ `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`
2113
+ ));
2114
+ }
2115
+ navigateToResult(e, t) {
2116
+ if (!this.editor) return;
2117
+ const i = document.activeElement, s = !!i && (i === this.findInput || i === this.replaceInputEl);
2118
+ t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
2119
+ const n = this.editor.getView();
2120
+ t && typeof n.ensureCaretVisible == "function" && n.ensureCaretVisible(), t && s && i && requestAnimationFrame(() => {
2121
+ this.focusWithoutScrolling(i);
2122
+ });
2123
+ }
2124
+ clearHighlights() {
2125
+ var e, t;
2126
+ if (this.hasCustomHighlightSupport)
2127
+ try {
2128
+ const i = CSS;
2129
+ (e = i.highlights) == null || e.delete(this.highlightMatchName), (t = i.highlights) == null || t.delete(this.highlightActiveName);
2130
+ } catch (i) {
2131
+ }
2132
+ }
2133
+ scrollResultIntoView(e) {
2134
+ this.scrollLogicalRangeIntoView(e.range, !0);
2135
+ }
2136
+ scrollLogicalRangeIntoView(e, t) {
2137
+ if (!this.editor) return;
2138
+ const i = this.editor.getView().getContentElement(), s = this.editor.getValue(), { lineStarts: n, lines: r } = this.buildLineStarts(s), o = this.buildTextNodeIndex(i);
2139
+ if (o.length === 0) return;
2140
+ const l = this.toDomRange(e, n, r, o);
2141
+ if (!l) return;
2142
+ const a = l.startContainer.nodeType === Node.TEXT_NODE ? l.startContainer.parentElement : l.startContainer, h = this.resolveScrollContainer(i);
2143
+ if (h) {
2144
+ const d = l.getClientRects()[0] || l.getBoundingClientRect(), c = h.getBoundingClientRect(), u = h.scrollTop + (d.top - c.top) - c.height / 2 + d.height / 2, g = 18;
2145
+ let f = t ? u : h.scrollTop, p = h.scrollLeft;
2146
+ const m = h.scrollLeft + (d.left - c.left), x = m + d.width;
2147
+ d.right > c.right - g ? p = x - c.width + g : d.left < c.left + g && (p = Math.max(0, m - g));
2148
+ const v = Math.max(0, h.scrollHeight - h.clientHeight), T = Math.max(0, h.scrollWidth - h.clientWidth);
2149
+ if (f = Math.min(v, Math.max(0, f)), p = Math.min(T, Math.max(0, p)), v === 0 && T === 0) {
2150
+ a == null || a.scrollIntoView({
2151
+ block: t ? "center" : "nearest",
2152
+ inline: "nearest",
2153
+ behavior: "smooth"
2154
+ });
2155
+ return;
2156
+ }
2157
+ (f !== h.scrollTop || p !== h.scrollLeft) && h.scrollTo({
2158
+ top: f,
2159
+ left: p,
2160
+ behavior: "smooth"
2161
+ });
2162
+ return;
2163
+ }
2164
+ a == null || a.scrollIntoView({
2165
+ block: t ? "center" : "nearest",
2166
+ inline: "nearest",
2167
+ behavior: "smooth"
2168
+ });
2169
+ }
2170
+ restoreReplaceInputFocus() {
2171
+ const e = this.replaceInputEl;
2172
+ !e || e.style.display === "none" || requestAnimationFrame(() => {
2173
+ this.focusWithoutScrolling(e);
2174
+ const t = e.value.length;
2175
+ try {
2176
+ e.setSelectionRange(t, t);
2177
+ } catch (i) {
2178
+ }
2179
+ });
2180
+ }
2181
+ centerCurrentSelectionInView() {
2182
+ if (!this.editor) return;
2183
+ const e = this.editor.getView().getContentElement(), t = this.resolveScrollContainer(e);
2184
+ if (!t) return;
2185
+ const i = window.getSelection();
2186
+ if (!i || i.rangeCount === 0) return;
2187
+ const s = i.getRangeAt(0).cloneRange(), n = s.getClientRects()[0] || s.getBoundingClientRect();
2188
+ if (!n) return;
2189
+ const r = t.getBoundingClientRect(), o = t.scrollTop + (n.top - r.top) - r.height / 2 + n.height / 2, l = Math.max(0, t.scrollHeight - t.clientHeight), a = Math.min(l, Math.max(0, o));
2190
+ a !== t.scrollTop && t.scrollTo({
2191
+ top: a,
2192
+ behavior: "smooth"
2193
+ });
2194
+ }
2195
+ computeReplacementRange(e, t) {
2196
+ const i = t.replace(/\r\n?/g, `
2197
+ `), s = i.split(`
2198
+ `);
2199
+ let n;
2200
+ return s.length <= 1 ? (n = {
2201
+ start: e,
2202
+ end: {
2203
+ line: e.line,
2204
+ column: e.column + i.length
2205
+ }
2206
+ }, this.clampRangeToDocument(n)) : (n = {
2207
+ start: e,
2208
+ end: {
2209
+ line: e.line + s.length - 1,
2210
+ column: s[s.length - 1].length
2211
+ }
2212
+ }, this.clampRangeToDocument(n));
2213
+ }
2214
+ findNextResultIndexAfter(e, t) {
2215
+ for (let i = 0; i < t.length; i++)
2216
+ if (this.comparePositions(t[i].range.start, e) >= 0)
2217
+ return i;
2218
+ return 0;
2219
+ }
2220
+ comparePositions(e, t) {
2221
+ return e.line !== t.line ? e.line - t.line : e.column - t.column;
2222
+ }
2223
+ clampRangeToDocument(e) {
2224
+ var a, h;
2225
+ const t = this.editor;
2226
+ if (!t) return e;
2227
+ const i = t.getValue().split(`
2228
+ `), s = Math.max(0, i.length - 1), n = Math.max(0, Math.min(e.start.line, s)), r = Math.max(0, Math.min(e.end.line, s)), o = Math.max(
2229
+ 0,
2230
+ Math.min(e.start.column, ((a = i[n]) == null ? void 0 : a.length) || 0)
2231
+ ), l = Math.max(
2232
+ 0,
2233
+ Math.min(e.end.column, ((h = i[r]) == null ? void 0 : h.length) || 0)
2234
+ );
2235
+ return {
2236
+ start: { line: n, column: o },
2237
+ end: { line: r, column: l }
2238
+ };
2239
+ }
2240
+ focusWithoutScrolling(e) {
2241
+ try {
2242
+ e.focus({
2243
+ preventScroll: !0
2244
+ });
2245
+ } catch (t) {
2246
+ const i = [];
2247
+ let s = e.parentElement;
2248
+ for (; s; )
2249
+ this.canScroll(s) && i.push({
2250
+ el: s,
2251
+ top: s.scrollTop,
2252
+ left: s.scrollLeft
2253
+ }), s = s.parentElement;
2254
+ const n = window.scrollX, r = window.scrollY;
2255
+ e.focus();
2256
+ for (let o = 0; o < i.length; o++) {
2257
+ const l = i[o];
2258
+ l.el.scrollTop = l.top, l.el.scrollLeft = l.left;
2259
+ }
2260
+ window.scrollTo(n, r);
2261
+ }
2262
+ }
2263
+ findScrollContainer(e) {
2264
+ let t = e;
2265
+ for (; t; ) {
2266
+ const i = window.getComputedStyle(t).overflowY;
2267
+ if ((i === "auto" || i === "scroll") && t.scrollHeight > t.clientHeight)
2268
+ return t;
2269
+ t = t.parentElement;
2270
+ }
2271
+ return null;
2272
+ }
2273
+ resolveScrollContainer(e) {
2274
+ var i, s, n;
2275
+ const t = ((n = (s = (i = this.editor) == null ? void 0 : i.getView()) == null ? void 0 : s.getScrollElement) == null ? void 0 : n.call(s)) || null;
2276
+ return t && this.canScroll(t) ? t : this.findScrollContainer(e);
2277
+ }
2278
+ canScroll(e) {
2279
+ return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
2280
+ }
2281
+ revealActiveResultAfterFocusRestore() {
2282
+ !this.currentResults.length || this.currentIndex < 0 || requestAnimationFrame(() => {
2283
+ const e = this.currentResults[this.currentIndex];
2284
+ e && this.scrollResultIntoView(e);
2285
+ });
2286
+ }
2287
+ applyCustomHighlights() {
2288
+ if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
2289
+ return;
2290
+ const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines: s } = this.buildLineStarts(t), n = this.buildTextNodeIndex(e);
2291
+ if (n.length === 0) return;
2292
+ const r = this.buildVisibleDocumentText(n), o = [];
2293
+ let l = null;
2294
+ const a = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
2295
+ for (let h = 0; h < a; h++) {
2296
+ const d = this.currentResults[h], c = this.searchOptions.regex ? d.match || this.currentQuery : this.currentQuery || d.match, u = this.toDomRange(
2297
+ d.range,
2298
+ i,
2299
+ s,
2300
+ n,
2301
+ r,
2302
+ c
2303
+ );
2304
+ u && (o.push(u), h === this.currentIndex && (l = u));
2305
+ }
2306
+ if (o.length !== 0)
2307
+ try {
2308
+ const h = CSS, d = window.Highlight;
2309
+ if (!h.highlights || !d) return;
2310
+ h.highlights.set(this.highlightMatchName, new d(...o)), l && h.highlights.set(this.highlightActiveName, new d(l));
2311
+ } catch (h) {
2312
+ }
2313
+ }
2314
+ buildLineStarts(e) {
2315
+ const t = e.split(`
2316
+ `), i = new Array(t.length);
2317
+ let s = 0;
2318
+ for (let n = 0; n < t.length; n++)
2319
+ i[n] = s, s += t[n].length + 1;
2320
+ return { lineStarts: i, lines: t };
2321
+ }
2322
+ positionToOffset(e, t, i) {
2323
+ var r;
2324
+ const s = Math.max(0, Math.min(e.line, i.length - 1)), n = Math.max(0, Math.min(e.column, ((r = i[s]) == null ? void 0 : r.length) || 0));
2325
+ return t[s] + n;
2326
+ }
2327
+ buildTextNodeIndex(e) {
2328
+ var r;
2329
+ const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
2330
+ let s = 0, n;
2331
+ for (; n = t.nextNode(); ) {
2332
+ const o = n;
2333
+ if ((r = o.parentElement) != null && r.hasAttribute(this.trailingMarkerAttr))
2334
+ continue;
2335
+ const l = o.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
2336
+ h === 0 && l.length === 0 || (i.push({
2337
+ node: o,
2338
+ start: s,
2339
+ end: s + h,
2340
+ visibleToDom: a
2341
+ }), s += h);
2342
+ }
2343
+ return i;
2344
+ }
2345
+ resolveDomPoint(e, t) {
2346
+ var n, r, o, l, a, h;
2347
+ const i = Math.max(0, e);
2348
+ for (let d = 0; d < t.length; d++) {
2349
+ const c = t[d];
2350
+ if (i <= c.end) {
2351
+ const u = Math.max(0, i - c.start), g = (o = (r = c.visibleToDom[u]) != null ? r : (n = c.node.textContent) == null ? void 0 : n.length) != null ? o : 0;
2352
+ return {
2353
+ node: c.node,
2354
+ offset: g
2355
+ };
2356
+ }
2357
+ }
2358
+ const s = t[t.length - 1];
2359
+ return s ? {
2360
+ node: s.node,
2361
+ offset: (h = (a = s.visibleToDom[s.visibleToDom.length - 1]) != null ? a : (l = s.node.textContent) == null ? void 0 : l.length) != null ? h : 0
2362
+ } : null;
2363
+ }
2364
+ toDomRange(e, t, i, s, n, r) {
2365
+ const o = this.positionToOffset(e.start, t, i), l = this.positionToOffset(e.end, t, i);
2366
+ let a = Math.min(o, l), h = Math.max(o, l);
2367
+ if (n && r) {
2368
+ const g = r, f = n.slice(a, h);
2369
+ if (f.length === g.length && f.toLowerCase() !== g.toLowerCase()) {
2370
+ const p = this.findNearestMatchOffset(
2371
+ n,
2372
+ g,
2373
+ a
2374
+ );
2375
+ p !== -1 && (a = p, h = p + g.length);
2376
+ }
2377
+ }
2378
+ const d = this.resolveDomPoint(a, s), c = this.resolveDomPoint(h, s);
2379
+ if (!d || !c) return null;
2380
+ const u = document.createRange();
2381
+ try {
2382
+ return u.setStart(d.node, d.offset), u.setEnd(c.node, c.offset), u;
2383
+ } catch (g) {
2384
+ return null;
2385
+ }
2386
+ }
2387
+ buildVisibleDocumentText(e) {
2388
+ let t = "";
2389
+ for (let i = 0; i < e.length; i++) {
2390
+ const s = e[i].node.textContent || "";
2391
+ for (let n = 0; n < s.length; n++) {
2392
+ const r = s[n];
2393
+ this.virtualMarkerRegex.test(r) || (t += r);
2394
+ }
2395
+ }
2396
+ return t;
2397
+ }
2398
+ findNearestMatchOffset(e, t, i) {
2399
+ const s = t.toLowerCase();
2400
+ let n = e.toLowerCase().indexOf(s);
2401
+ if (n === -1) return -1;
2402
+ let r = n, o = Math.abs(n - i);
2403
+ for (; n !== -1; ) {
2404
+ const l = Math.abs(n - i);
2405
+ if (l < o && (o = l, r = n), l === 0) return n;
2406
+ n = e.toLowerCase().indexOf(s, n + 1);
2407
+ }
2408
+ return r;
2409
+ }
2410
+ scheduleLiveRefresh(e) {
2411
+ this.liveRefreshTimer && clearTimeout(this.liveRefreshTimer);
2412
+ const t = this.currentQuery;
2413
+ this.liveRefreshTimer = setTimeout(() => {
2414
+ !this.isVisible || !t || this.performSearch(t, e, !1);
2415
+ }, 90);
2416
+ }
2417
+ updateStatus(e, t = !1) {
2418
+ if (this.statusDiv) {
2419
+ if (!t && Date.now() < this.statusFreezeUntil)
2420
+ return;
2421
+ this.statusDiv.textContent = e;
2422
+ }
2423
+ }
2424
+ showTransientStatus(e, t = 900) {
2425
+ this.statusFreezeUntil = Date.now() + t, this.updateStatus(e, !0), this.statusResetTimer && clearTimeout(this.statusResetTimer), this.statusResetTimer = setTimeout(() => {
2426
+ this.statusFreezeUntil = 0, this.syncMatchStatus();
2427
+ }, t);
2428
+ }
2429
+ syncMatchStatus() {
2430
+ if (!this.currentQuery) {
2431
+ this.updateStatus("", !0);
2432
+ return;
2433
+ }
2434
+ if (this.currentResults.length === 0 || this.currentIndex < 0) {
2435
+ this.updateStatus("No matches", !0);
2436
+ return;
2437
+ }
2438
+ this.updateStatus(
2439
+ `${this.currentResults.length} matches (showing ${this.currentIndex + 1}/${this.currentResults.length})`,
2440
+ !0
2441
+ );
2442
+ }
2443
+ isValidRegex(e) {
2444
+ try {
2445
+ const t = this.searchOptions.caseSensitive ? "g" : "gi";
2446
+ return new RegExp(e, t), !0;
2447
+ } catch (t) {
2448
+ return !1;
2449
+ }
2450
+ }
2451
+ captureSelectionState() {
2452
+ this.editor && (this.savedSelection = this.editor.getSelection(), this.savedCursor = this.editor.getCursor().position);
2453
+ }
2454
+ restoreSelectionState() {
2455
+ this.editor && (this.savedSelection ? this.editor.setSelection(this.savedSelection) : this.savedCursor && this.editor.setCursor(this.savedCursor), this.savedSelection = void 0, this.savedCursor = null);
2456
+ }
2457
+ detectCustomHighlightSupport() {
2458
+ try {
2459
+ const e = CSS, t = window.Highlight;
2460
+ return !!e.highlights && !!t;
2461
+ } catch (e) {
2462
+ return !1;
2463
+ }
2464
+ }
2465
+ buildVisibleToDomMap(e) {
2466
+ const t = [0];
2467
+ let i = 0;
2468
+ for (let s = 0; s < e.length; s++) {
2469
+ const n = e[s];
2470
+ this.virtualMarkerRegex.test(n) || (i += 1, t[i] = s + 1);
2471
+ }
2472
+ return t;
2473
+ }
2474
+ ensureHighlightStyles() {
2475
+ if (document.getElementById(this.highlightStyleId)) return;
2476
+ const e = document.createElement("style");
2477
+ e.id = this.highlightStyleId, e.textContent = `
2478
+ ::highlight(${this.highlightMatchName}) {
2479
+ background: var(--lce-search-match-bg, rgba(255, 214, 10, 0.34));
2480
+ border-radius: 2px;
2481
+ }
2482
+ ::highlight(${this.highlightActiveName}) {
2483
+ background: var(--lce-search-active-bg, rgba(255, 154, 0, 0.45));
2484
+ border-radius: 2px;
2485
+ }
2486
+ `, document.head.appendChild(e);
2487
+ }
2488
+ destroy() {
2489
+ 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;
2490
+ const e = document.getElementById(this.highlightStyleId);
2491
+ e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
2492
+ }
2493
+ };
2494
+ K.css = {
2495
+ root: "lce-search-ui",
2496
+ row: "lce-search-row",
2497
+ options: "lce-search-options",
2498
+ optionLabel: "lce-search-option",
2499
+ optionInput: "lce-search-option-input",
2500
+ caseSensitive: "search-case-sensitive",
2501
+ wholeWord: "search-whole-word",
2502
+ regex: "search-regex",
2503
+ meta: "lce-search-meta",
2504
+ findInput: "search-find-input",
2505
+ replaceInput: "search-replace-input",
2506
+ inputBase: "lce-search-input",
2507
+ replaceInputLayout: "lce-search-replace",
2508
+ prevButton: "search-prev",
2509
+ nextButton: "search-next",
2510
+ closeButton: "search-close",
2511
+ buttonBase: "lce-search-btn",
2512
+ status: "search-status",
2513
+ statusLayout: "lce-search-status",
2514
+ mode: "search-mode",
2515
+ modeLayout: "lce-search-mode"
2516
+ };
2517
+ let re = K, oe = 0;
2518
+ class le {
2519
+ constructor() {
2520
+ this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
2521
+ "(": ")",
2522
+ "[": "]",
2523
+ "{": "}",
2524
+ "<": ">"
2525
+ }, this.reverseBracketPairs = {
2526
+ ")": "(",
2527
+ "]": "[",
2528
+ "}": "{",
2529
+ ">": "<"
2530
+ }, this.highlightId = ++oe, this.highlightName = `editora-bracket-match-${this.highlightId}`, this.highlightStyleId = `editora-bracket-match-style-${this.highlightId}`, this.currentMatch = null, this.hasCustomHighlightSupport = !1, this.observer = null, this.pendingUpdateRaf = null, this.updateRequestVersion = 0, this.cursorHandler = null, this.changeHandler = null;
2531
+ }
2532
+ setup(e) {
2533
+ this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && (this.ensureHighlightStyles(), this.observeContentMutations()), this.cursorHandler = () => {
2534
+ this.scheduleBracketUpdate();
2535
+ }, this.changeHandler = () => {
2536
+ this.scheduleBracketUpdate();
2537
+ }, e.on("cursor", this.cursorHandler), e.on("change", this.changeHandler), this.scheduleBracketUpdate();
2538
+ }
2539
+ scheduleBracketUpdate() {
2540
+ this.updateRequestVersion += 1;
2541
+ const e = this.updateRequestVersion;
2542
+ this.pendingUpdateRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null);
2543
+ const t = () => {
2544
+ e === this.updateRequestVersion && (this.pendingUpdateRaf = null, this.updateBracketMatching());
2545
+ };
2546
+ if (typeof requestAnimationFrame == "function") {
2547
+ this.pendingUpdateRaf = requestAnimationFrame(() => {
2548
+ this.pendingUpdateRaf = requestAnimationFrame(t);
2549
+ });
2550
+ return;
2551
+ }
2552
+ t();
2553
+ }
2554
+ updateBracketMatching() {
2555
+ if (!this.editor) return;
2556
+ const e = this.editor.getCursor(), t = this.editor.getValue();
2557
+ this.clearBracketHighlighting();
2558
+ const i = this.getBracketNearPosition(t, e.position);
2559
+ if (!i) return;
2560
+ const s = this.findMatchingBracket(t, i);
2561
+ s && (this.currentMatch = s, this.highlightBrackets(s));
2562
+ }
2563
+ getBracketNearPosition(e, t) {
2564
+ const i = e.split(`
2565
+ `);
2566
+ if (t.line < 0 || t.line >= i.length) return null;
2567
+ const s = [{ line: t.line, column: t.column }];
2568
+ t.column > 0 && s.push({ line: t.line, column: t.column - 1 });
2569
+ for (const n of s) {
2570
+ const r = this.getBracketAtPosition(i, n);
2571
+ if (r)
2572
+ return r;
2573
+ }
2574
+ return null;
2575
+ }
2576
+ getBracketAtPosition(e, t) {
2577
+ if (t.line < 0 || t.line >= e.length) return null;
2578
+ const i = e[t.line];
2579
+ if (t.column < 0 || t.column >= i.length) return null;
2580
+ const s = i[t.column];
2581
+ return this.bracketPairs[s] || this.reverseBracketPairs[s] ? { char: s, position: t } : null;
2582
+ }
2583
+ findMatchingBracket(e, t) {
2584
+ const i = e.split(`
2585
+ `), s = t.position.line, n = t.position.column, r = t.char;
2586
+ return this.bracketPairs[r] ? this.findClosingBracket(i, s, n, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(i, s, n, r) : null;
2587
+ }
2588
+ findClosingBracket(e, t, i, s) {
2589
+ const n = this.bracketPairs[s];
2590
+ let r = 0;
2591
+ for (let o = t; o < e.length; o++) {
2592
+ const l = e[o], a = o === t ? i : 0;
2593
+ for (let h = a; h < l.length; h++) {
2594
+ const d = l[h];
2595
+ if (d === s)
2596
+ r++;
2597
+ else if (d === n && (r--, r === 0))
2598
+ return {
2599
+ open: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
2600
+ close: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
2601
+ type: s
2602
+ };
2603
+ }
2604
+ }
2605
+ return null;
2606
+ }
2607
+ findOpeningBracket(e, t, i, s) {
2608
+ const n = this.reverseBracketPairs[s];
2609
+ let r = 0;
2610
+ for (let o = t; o >= 0; o--) {
2611
+ const l = e[o], a = o === t ? i : l.length - 1;
2612
+ for (let h = a; h >= 0; h--) {
2613
+ const d = l[h];
2614
+ if (d === s)
2615
+ r++;
2616
+ else if (d === n && (r--, r === 0))
2617
+ return {
2618
+ open: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
2619
+ close: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
2620
+ type: n
2621
+ };
2622
+ }
2623
+ }
2624
+ return null;
2625
+ }
2626
+ highlightBrackets(e) {
2627
+ if (!this.editor || !this.hasCustomHighlightSupport) return;
2628
+ const t = this.editor.getView(), i = t.createDomRangeFromRange(e.open), s = t.createDomRangeFromRange(e.close);
2629
+ if (!(!i || !s))
2630
+ try {
2631
+ const n = CSS, r = window.Highlight;
2632
+ if (!n.highlights || !r) return;
2633
+ n.highlights.set(this.highlightName, new r(i, s));
2634
+ } catch (n) {
2635
+ }
2636
+ }
2637
+ clearBracketHighlighting() {
2638
+ var e;
2639
+ if (this.currentMatch = null, !!this.hasCustomHighlightSupport)
2640
+ try {
2641
+ (e = CSS.highlights) == null || e.delete(this.highlightName);
2642
+ } catch (t) {
2643
+ }
2644
+ }
2645
+ observeContentMutations() {
2646
+ if (!this.editor || typeof MutationObserver > "u") return;
2647
+ const e = this.editor.getView().getContentElement();
2648
+ this.observer = new MutationObserver(() => {
2649
+ this.clearBracketHighlighting(), this.scheduleBracketUpdate();
2650
+ }), this.observer.observe(e, {
2651
+ childList: !0,
2652
+ subtree: !0,
2653
+ characterData: !0
2654
+ });
2655
+ }
2656
+ detectCustomHighlightSupport() {
2657
+ try {
2658
+ if (typeof CSS > "u" || typeof window > "u")
2659
+ return !1;
2660
+ const e = CSS, t = window.Highlight;
2661
+ return !!e.highlights && !!t;
2662
+ } catch (e) {
2663
+ return !1;
2664
+ }
2665
+ }
2666
+ ensureHighlightStyles() {
2667
+ if (typeof document > "u" || document.getElementById(this.highlightStyleId)) return;
2668
+ const e = document.createElement("style");
2669
+ e.id = this.highlightStyleId, e.textContent = `
2670
+ ::highlight(${this.highlightName}) {
2671
+ background-color: var(--lce-bracket-match-bg, rgba(86, 156, 214, 0.4));
2672
+ text-decoration: underline solid var(--lce-bracket-match-border, rgba(156, 220, 254, 0.95)) 2px;
2673
+ }
2674
+ `, document.head.appendChild(e);
2675
+ }
2676
+ getCurrentMatch() {
2677
+ return this.currentMatch;
2678
+ }
2679
+ destroy() {
2680
+ var e;
2681
+ if (this.pendingUpdateRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.clearBracketHighlighting(), (e = this.observer) == null || e.disconnect(), this.observer = null, this.editor && this.cursorHandler && this.editor.off("cursor", this.cursorHandler), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), typeof document < "u") {
2682
+ const t = document.getElementById(this.highlightStyleId);
2683
+ t != null && t.parentNode && t.parentNode.removeChild(t);
2684
+ }
2685
+ this.cursorHandler = null, this.changeHandler = null, this.editor = null;
2686
+ }
2687
+ }
2688
+ class ae {
2689
+ constructor() {
2690
+ this.name = "code-folding", this.lineHeight = 21, this.voidMarkupTags = /* @__PURE__ */ new Set([
2691
+ "area",
2692
+ "base",
2693
+ "br",
2694
+ "col",
2695
+ "embed",
2696
+ "hr",
2697
+ "img",
2698
+ "input",
2699
+ "link",
2700
+ "meta",
2701
+ "param",
2702
+ "source",
2703
+ "track",
2704
+ "wbr"
2705
+ ]), this.nonFoldableInlineMarkupTags = /* @__PURE__ */ new Set([
2706
+ "a",
2707
+ "abbr",
2708
+ "b",
2709
+ "bdi",
2710
+ "bdo",
2711
+ "button",
2712
+ "cite",
2713
+ "code",
2714
+ "data",
2715
+ "del",
2716
+ "dfn",
2717
+ "em",
2718
+ "i",
2719
+ "ins",
2720
+ "kbd",
2721
+ "label",
2722
+ "mark",
2723
+ "output",
2724
+ "q",
2725
+ "ruby",
2726
+ "s",
2727
+ "samp",
2728
+ "small",
2729
+ "span",
2730
+ "strong",
2731
+ "sub",
2732
+ "sup",
2733
+ "time",
2734
+ "u",
2735
+ "var"
2736
+ ]), this.rawTextMarkupTags = /* @__PURE__ */ new Set([
2737
+ "script",
2738
+ "style",
2739
+ "textarea",
2740
+ "title"
2741
+ ]), this.editor = null, this.foldingUI = null, this.pendingUpdateRaf = null, this.lastSnapshot = "", this.lastParsedText = null, this.changeHandler = null, this.foldRegions = [], this.foldSnapshots = /* @__PURE__ */ new Map(), this.isDisplayingFolded = !1, this.cachedLineInfo = null;
2742
+ }
2743
+ setup(e) {
2744
+ this.editor = e, e.registerCommand("fold", () => {
2745
+ this.foldAtCursor();
2746
+ }), e.registerCommand("unfold", () => {
2747
+ this.unfoldAtCursor();
2748
+ }), e.registerCommand("foldAll", () => {
2749
+ this.foldAll();
2750
+ }), e.registerCommand("unfoldAll", () => {
2751
+ this.unfoldAll();
2752
+ }), this.changeHandler = () => {
2753
+ this.syncFoldingState();
2754
+ }, e.on("change", this.changeHandler), this.createFoldingUI(), this.syncFoldingState();
2755
+ }
2756
+ onKeyDown(e) {
2757
+ }
2758
+ onMouseDown(e) {
2759
+ }
2760
+ createFoldingUI() {
2761
+ if (!this.editor) return;
2762
+ const e = this.editor.getView().getContentElement().closest(
2763
+ '[data-lce-editor-container="true"]'
2764
+ );
2765
+ e && (this.foldingUI = document.createElement("div"), this.foldingUI.setAttribute("data-lce-folding-ui", "true"), this.foldingUI.style.cssText = `
2766
+ position: absolute;
2767
+ left: 0;
2768
+ top: 0;
2769
+ bottom: 0;
2770
+ width: 20px;
2771
+ pointer-events: none;
2772
+ z-index: 3;
2773
+ `, e.appendChild(this.foldingUI));
2774
+ }
2775
+ syncFoldingState() {
2776
+ if (!this.editor) return;
2777
+ const e = this.editor.getValue(), t = this.foldSnapshots;
2778
+ e !== this.lastParsedText && (this.foldRegions = this.buildFoldRegions(e), this.pruneInvalidFolds(e, t), this.lastParsedText = e), this.hasActiveFolds() ? this.applyFoldedDisplay() : this.restoreFullDisplay(), this.rememberActiveFoldSnapshots(e), this.scheduleFoldIndicatorUpdate();
2779
+ }
2780
+ scheduleFoldIndicatorUpdate() {
2781
+ this.pendingUpdateRaf === null && (this.pendingUpdateRaf = requestAnimationFrame(() => {
2782
+ this.pendingUpdateRaf = null, this.updateFoldIndicators();
2783
+ }));
2784
+ }
2785
+ updateFoldIndicators() {
2786
+ if (!this.editor || !this.foldingUI) return;
2787
+ const e = this.editor.getValue(), t = this.getActiveFolds().map((r) => this.getFoldKey(r)).join("|"), i = `${e}::${t}`;
2788
+ if (i === this.lastSnapshot) return;
2789
+ this.lastSnapshot = i, this.foldingUI.innerHTML = "";
2790
+ const s = this.getRenderableActiveFolds(), n = document.createDocumentFragment();
2791
+ for (const r of this.foldRegions) {
2792
+ const o = this.toDisplayLine(r, s);
2793
+ if (o === null) continue;
2794
+ const l = this.isFoldActive(r), a = this.createFoldIndicator(r, o, l);
2795
+ n.appendChild(a);
2796
+ }
2797
+ this.foldingUI.appendChild(n);
2798
+ }
2799
+ buildFoldRegions(e) {
2800
+ const t = this.buildBracketFoldRegions(e), i = this.shouldIncludeMarkupFolds(e) ? this.buildMarkupFoldRegions(e) : [];
2801
+ return this.mergeFoldRegions([...t, ...i]);
2802
+ }
2803
+ buildBracketFoldRegions(e) {
2804
+ var o;
2805
+ const t = e.split(`
2806
+ `), i = [], s = [], n = {
2807
+ "{": "}",
2808
+ "[": "]",
2809
+ "(": ")"
2810
+ }, r = {
2811
+ "}": "{",
2812
+ "]": "[",
2813
+ ")": "("
2814
+ };
2815
+ for (let l = 0; l < t.length; l++) {
2816
+ const a = t[l];
2817
+ for (let h = 0; h < a.length; h++) {
2818
+ const d = a[h];
2819
+ if (n[d]) {
2820
+ i.push({ char: d, line: l, column: h });
2821
+ continue;
2822
+ }
2823
+ const c = r[d];
2824
+ if (!c) continue;
2825
+ let u = -1;
2826
+ for (let m = i.length - 1; m >= 0; m--)
2827
+ if (i[m].char === c) {
2828
+ u = m;
2829
+ break;
2830
+ }
2831
+ if (u === -1) continue;
2832
+ const g = i.splice(u, 1)[0];
2833
+ if (g.line >= l) continue;
2834
+ const f = ((o = t[g.line]) == null ? void 0 : o.length) || 0, p = {
2835
+ start: { line: g.line, column: f },
2836
+ end: { line: l, column: 0 },
2837
+ collapsed: !1,
2838
+ level: u
2839
+ };
2840
+ this.isValidFoldRegion(p) && s.push(p);
2841
+ }
2842
+ }
2843
+ return s.sort((l, a) => l.start.line !== a.start.line ? l.start.line - a.start.line : l.end.line !== a.end.line ? l.end.line - a.end.line : l.start.column - a.start.column), s;
2844
+ }
2845
+ shouldIncludeMarkupFolds(e) {
2846
+ return /<!DOCTYPE\b/i.test(e) || /<[A-Za-z][\w:-]*(?:\s|>)/.test(e) && /<\/[A-Za-z][\w:-]*\s*>/.test(e);
2847
+ }
2848
+ buildMarkupFoldRegions(e) {
2849
+ const { lineStarts: t, lines: i } = this.buildLineStarts(e), s = [], n = [];
2850
+ let r = 0;
2851
+ for (; r < e.length; ) {
2852
+ if (e[r] !== "<") {
2853
+ r += 1;
2854
+ continue;
2855
+ }
2856
+ if (e.startsWith("<!--", r)) {
2857
+ const l = e.indexOf("-->", r + 4);
2858
+ r = l === -1 ? e.length : l + 3;
2859
+ continue;
2860
+ }
2861
+ if (e.startsWith("<![CDATA[", r)) {
2862
+ const l = e.indexOf("]]>", r + 9);
2863
+ r = l === -1 ? e.length : l + 3;
2864
+ continue;
2865
+ }
2866
+ const o = this.parseMarkupTag(e, r, t, i);
2867
+ if (!o) {
2868
+ r += 1;
2869
+ continue;
2870
+ }
2871
+ if (r = o.endOffset, o.isClosing) {
2872
+ const l = n.findIndex((d) => d.name === o.name);
2873
+ if (l === -1)
2874
+ continue;
2875
+ const a = n.splice(l, 1)[0], h = this.createMarkupFoldRegion(
2876
+ a.openEndLine,
2877
+ o.startLine,
2878
+ i
2879
+ );
2880
+ h && s.push(h);
2881
+ continue;
2882
+ }
2883
+ if (!(o.isSelfClosing || this.voidMarkupTags.has(o.name))) {
2884
+ if (this.rawTextMarkupTags.has(o.name)) {
2885
+ const l = this.findClosingMarkupTag(
2886
+ e,
2887
+ o.endOffset,
2888
+ o.name,
2889
+ t,
2890
+ i
2891
+ );
2892
+ if (l) {
2893
+ const a = this.createMarkupFoldRegion(
2894
+ o.endLine,
2895
+ l.startLine,
2896
+ i
2897
+ );
2898
+ a && s.push(a), r = l.endOffset;
2899
+ }
2900
+ continue;
2901
+ }
2902
+ this.nonFoldableInlineMarkupTags.has(o.name) || n.unshift({
2903
+ name: o.name,
2904
+ openEndLine: o.endLine
2905
+ });
2906
+ }
2907
+ }
2908
+ return s;
2909
+ }
2910
+ parseMarkupTag(e, t, i, s) {
2911
+ if (e[t] !== "<")
2912
+ return null;
2913
+ const n = e[t + 1];
2914
+ if (!n || n !== "/" && !/[A-Za-z]/.test(n))
2915
+ return null;
2916
+ const r = n === "/";
2917
+ let o = t + (r ? 2 : 1);
2918
+ const l = o;
2919
+ for (; o < e.length && /[A-Za-z0-9:-]/.test(e[o]); )
2920
+ o += 1;
2921
+ const a = o;
2922
+ if (o === l)
2923
+ return null;
2924
+ let h = null;
2925
+ for (; o < e.length; ) {
2926
+ const f = e[o];
2927
+ if (h) {
2928
+ f === h && (h = null), o += 1;
2929
+ continue;
2930
+ }
2931
+ if (f === '"' || f === "'") {
2932
+ h = f, o += 1;
2933
+ continue;
2934
+ }
2935
+ if (f === ">")
2936
+ break;
2937
+ o += 1;
2938
+ }
2939
+ if (o >= e.length || e[o] !== ">")
2940
+ return null;
2941
+ const d = e.slice(l, a).toLowerCase();
2942
+ if (!d)
2943
+ return null;
2944
+ const c = e.slice(t, o + 1), u = this.offsetToLine(t, i, s), g = this.offsetToLine(o, i, s);
2945
+ return {
2946
+ name: d,
2947
+ isClosing: r,
2948
+ isSelfClosing: !r && /\/\s*>$/.test(c),
2949
+ startLine: u,
2950
+ endLine: g,
2951
+ endOffset: o + 1
2952
+ };
2953
+ }
2954
+ findClosingMarkupTag(e, t, i, s, n) {
2955
+ const r = `</${i}`, o = e.toLowerCase();
2956
+ let l = o.indexOf(r, t);
2957
+ for (; l !== -1; ) {
2958
+ const a = this.parseMarkupTag(e, l, s, n);
2959
+ if (a && a.isClosing && a.name === i)
2960
+ return {
2961
+ startLine: a.startLine,
2962
+ endOffset: a.endOffset
2963
+ };
2964
+ l = o.indexOf(r, l + r.length);
2965
+ }
2966
+ return null;
2967
+ }
2968
+ createMarkupFoldRegion(e, t, i) {
2969
+ var o;
2970
+ if (e >= t)
2971
+ return null;
2972
+ const s = Math.max(0, Math.min(e, i.length - 1)), n = Math.max(0, Math.min(t, i.length - 1)), r = {
2973
+ start: {
2974
+ line: s,
2975
+ column: ((o = i[s]) == null ? void 0 : o.length) || 0
2976
+ },
2977
+ end: {
2978
+ line: n,
2979
+ column: 0
2980
+ },
2981
+ collapsed: !1,
2982
+ level: 0
2983
+ };
2984
+ return this.isValidFoldRegion(r) ? r : null;
2985
+ }
2986
+ mergeFoldRegions(e) {
2987
+ const t = /* @__PURE__ */ new Map();
2988
+ for (const i of e)
2989
+ this.isValidFoldRegion(i) && t.set(this.getFoldKey(i), i);
2990
+ return [...t.values()].sort((i, s) => i.start.line !== s.start.line ? i.start.line - s.start.line : i.end.line !== s.end.line ? i.end.line - s.end.line : i.start.column - s.start.column);
2991
+ }
2992
+ createFoldIndicator(e, t, i) {
2993
+ const s = document.createElement("button");
2994
+ return s.type = "button", s.style.cssText = `
2995
+ position: absolute;
2996
+ left: 0;
2997
+ top: ${t * this.lineHeight}px;
2998
+ width: 20px;
2999
+ height: ${this.lineHeight}px;
3000
+ display: flex;
3001
+ align-items: center;
3002
+ justify-content: center;
3003
+ cursor: pointer;
3004
+ pointer-events: auto;
3005
+ color: var(--editor-gutter-foreground, #858585);
3006
+ background: transparent;
3007
+ border: none;
3008
+ padding: 0;
3009
+ font-size: 10px;
3010
+ user-select: none;
3011
+ `, s.textContent = i ? "▶" : "▼", s.title = i ? "Expand folded region" : "Collapse region", s.setAttribute("aria-label", s.title), s.addEventListener("mousedown", (n) => {
3012
+ n.preventDefault();
3013
+ }), s.addEventListener("click", (n) => {
3014
+ n.preventDefault(), n.stopPropagation(), this.toggleFold(e);
3015
+ }), s;
3016
+ }
3017
+ toggleFold(e) {
3018
+ this.editor && (this.isFoldActive(e) ? this.editor.unfold(e) : this.editor.fold(e), this.syncFoldingState());
3019
+ }
3020
+ foldAtCursor() {
3021
+ if (!this.editor) return;
3022
+ const e = this.editor.getCursor().position.line, t = this.findBestRegionForLine(e, !1);
3023
+ t && (this.editor.fold(t), this.syncFoldingState());
3024
+ }
3025
+ unfoldAtCursor() {
3026
+ if (!this.editor) return;
3027
+ const e = this.editor.getCursor().position.line, t = this.findBestRegionForLine(e, !0);
3028
+ t && (this.editor.unfold(t), this.syncFoldingState());
3029
+ }
3030
+ foldAll() {
3031
+ if (!this.editor) return;
3032
+ const e = this.getTopLevelFoldRegions(this.foldRegions);
3033
+ for (const t of e)
3034
+ this.editor.fold(t);
3035
+ this.syncFoldingState();
3036
+ }
3037
+ unfoldAll() {
3038
+ if (!this.editor) return;
3039
+ const e = this.getActiveFolds();
3040
+ for (const t of e)
3041
+ this.editor.unfold(t);
3042
+ this.syncFoldingState();
3043
+ }
3044
+ applyFoldedDisplay() {
3045
+ if (!this.editor) return;
3046
+ const e = this.getRenderableActiveFolds();
3047
+ if (e.length === 0) {
3048
+ this.restoreFullDisplay();
3049
+ return;
3050
+ }
3051
+ const t = this.buildFoldedProjection(this.editor.getValue(), e);
3052
+ this.withPreservedSelection(() => {
3053
+ this.renderEditorText(t.text), this.renderFoldPlaceholders(t), this.isDisplayingFolded = !0;
3054
+ });
3055
+ }
3056
+ restoreFullDisplay() {
3057
+ this.editor && (this.isDisplayingFolded && this.withPreservedSelection(() => {
3058
+ this.renderEditorText(this.editor.getValue());
3059
+ }), this.isDisplayingFolded = !1);
3060
+ }
3061
+ renderEditorText(e) {
3062
+ if (!this.editor) return;
3063
+ const t = this.editor;
3064
+ if (typeof t.renderTextWithHighlight == "function") {
3065
+ t.expectingProgrammaticCursor = !0, t.renderTextWithHighlight(e, !1), t.expectingProgrammaticCursor = !1;
3066
+ return;
3067
+ }
3068
+ this.editor.getView().setText(e);
3069
+ }
3070
+ buildFoldedProjection(e, t) {
3071
+ const { lineStarts: i, lines: s } = this.buildLineStarts(e), n = [...t].sort((h, d) => this.comparePositions(h.start, d.start));
3072
+ let r = "";
3073
+ const o = [];
3074
+ let l = 0;
3075
+ for (const h of n) {
3076
+ const d = this.positionToOffset(h.start, i, s), c = this.positionToOffset(h.end, i, s), u = e.slice(l, d), g = this.getFoldPlaceholder(h), f = e.slice(d, c);
3077
+ r += u, r += g, u && o.push({ type: "text", text: u }), o.push({
3078
+ type: "placeholder",
3079
+ text: g,
3080
+ fold: h,
3081
+ hiddenText: f
3082
+ }), l = c;
3083
+ }
3084
+ const a = e.slice(l);
3085
+ return r += a, a && o.push({ type: "text", text: a }), { text: r, segments: o };
3086
+ }
3087
+ renderFoldPlaceholders(e) {
3088
+ if (!this.editor) return;
3089
+ const t = this.editor.getView().getContentElement(), i = /* @__PURE__ */ new Map(), s = document.createDocumentFragment();
3090
+ for (const n of e.segments) {
3091
+ if (n.type === "text") {
3092
+ s.appendChild(document.createTextNode(n.text));
3093
+ continue;
3094
+ }
3095
+ const r = document.createElement("span"), o = this.getFoldKey(n.fold);
3096
+ r.setAttribute("data-lce-fold-placeholder", o), r.setAttribute("aria-label", "Folded region"), r.contentEditable = "false", i.set(o, n.hiddenText), r.style.cssText = `
3097
+ cursor: text;
3098
+ user-select: text;
3099
+ pointer-events: auto;
3100
+ white-space: pre;
3101
+ `, r.textContent = n.text, s.appendChild(r);
3102
+ }
3103
+ t.replaceChildren(s), t.__lceFoldPlaceholderSources = i, this.editor.getView().syncTrailingNewlineMarkerForText(e.text);
3104
+ }
3105
+ getFoldPlaceholder(e) {
3106
+ const t = Math.max(1, e.end.line - e.start.line);
3107
+ return ` … ${t} ${t === 1 ? "line" : "lines"} … `;
3108
+ }
3109
+ pruneInvalidFolds(e, t) {
3110
+ if (!this.editor) return;
3111
+ const i = this.editor.getFolds().filter((a) => a.collapsed !== !1), s = new Set(i.map((a) => this.getFoldKey(a))), n = [], r = /* @__PURE__ */ new Set(), o = this.getLineInfo(e);
3112
+ for (const a of i) {
3113
+ const h = this.findReplacementFold(
3114
+ a,
3115
+ t.get(this.getFoldKey(a)),
3116
+ r,
3117
+ e,
3118
+ o
3119
+ );
3120
+ if (!h)
3121
+ continue;
3122
+ const d = this.getFoldKey(h);
3123
+ n.push(h), r.add(d);
3124
+ }
3125
+ const l = new Set(n.map((a) => this.getFoldKey(a)));
3126
+ for (const a of i)
3127
+ l.has(this.getFoldKey(a)) || this.editor.unfold(a);
3128
+ for (const a of n)
3129
+ s.has(this.getFoldKey(a)) || this.editor.fold(a);
3130
+ }
3131
+ getActiveFolds() {
3132
+ return this.editor ? this.editor.getFolds().filter((e) => e.collapsed !== !1) : [];
3133
+ }
3134
+ hasActiveFolds() {
3135
+ return this.getActiveFolds().length > 0;
3136
+ }
3137
+ getRenderableActiveFolds() {
3138
+ return this.getTopLevelFoldRegions(this.getActiveFolds());
3139
+ }
3140
+ getTopLevelFoldRegions(e) {
3141
+ const t = [...e].sort((s, n) => this.comparePositions(s.start, n.start)), i = [];
3142
+ for (const s of t) {
3143
+ const n = i[i.length - 1];
3144
+ n && this.containsRange(n, s) || i.push(s);
3145
+ }
3146
+ return i;
3147
+ }
3148
+ toDisplayLine(e, t) {
3149
+ let i = 0;
3150
+ for (const s of t) {
3151
+ if (this.isSameRange(s, e))
3152
+ break;
3153
+ if (this.containsRange(s, e))
3154
+ return null;
3155
+ s.end.line <= e.start.line && (i += s.end.line - s.start.line);
3156
+ }
3157
+ return e.start.line - i;
3158
+ }
3159
+ findBestRegionForLine(e, t) {
3160
+ const i = (t ? this.getActiveFolds() : this.foldRegions).filter(
3161
+ (s) => s.start.line <= e && s.end.line >= e
3162
+ );
3163
+ return i.length === 0 ? null : (i.sort((s, n) => {
3164
+ const r = s.end.line - s.start.line, o = n.end.line - n.start.line;
3165
+ return r !== o ? r - o : this.comparePositions(s.start, n.start);
3166
+ }), i[0]);
3167
+ }
3168
+ findReplacementFold(e, t, i, s, n) {
3169
+ const r = this.getFoldKey(e), o = this.foldRegions.find(
3170
+ (c) => this.getFoldKey(c) === r && !i.has(r)
3171
+ );
3172
+ if (o)
3173
+ return o;
3174
+ const l = e.end.line - e.start.line, a = t != null ? t : this.createFoldSnapshot(e, s, n), h = this.foldRegions.filter((c) => !i.has(this.getFoldKey(c))).map((c) => {
3175
+ const u = this.createFoldSnapshot(c, s, n), g = a && (u == null ? void 0 : u.startLineText) === a.startLineText ? 1 : 0, f = a && (u == null ? void 0 : u.endLineText) === a.endLineText ? 1 : 0, p = a && (u == null ? void 0 : u.lineSpan) === a.lineSpan ? 1 : 0;
3176
+ return {
3177
+ region: c,
3178
+ overlaps: this.lineRangeOverlap(e, c),
3179
+ lineDistance: Math.abs(c.start.line - e.start.line) + Math.abs(c.end.line - e.end.line),
3180
+ spanDistance: Math.abs(
3181
+ c.end.line - c.start.line - l
3182
+ ),
3183
+ columnDistance: Math.abs(c.start.column - e.start.column) + Math.abs(c.end.column - e.end.column),
3184
+ hiddenTextMatch: a && (u == null ? void 0 : u.hiddenText) === a.hiddenText ? 1 : 0,
3185
+ boundaryMatchScore: g + f + p
3186
+ };
3187
+ }).sort((c, u) => c.hiddenTextMatch !== u.hiddenTextMatch ? u.hiddenTextMatch - c.hiddenTextMatch : c.boundaryMatchScore !== u.boundaryMatchScore ? u.boundaryMatchScore - c.boundaryMatchScore : c.overlaps !== u.overlaps ? u.overlaps - c.overlaps : c.lineDistance !== u.lineDistance ? c.lineDistance - u.lineDistance : c.spanDistance !== u.spanDistance ? c.spanDistance - u.spanDistance : c.columnDistance - u.columnDistance)[0];
3188
+ if (!h)
3189
+ return null;
3190
+ const d = h.lineDistance <= 2 && h.spanDistance <= 1;
3191
+ return !(h.hiddenTextMatch === 1 || h.boundaryMatchScore >= 2) && !d ? null : h.region;
3192
+ }
3193
+ lineRangeOverlap(e, t) {
3194
+ const i = Math.max(e.start.line, t.start.line), s = Math.min(e.end.line, t.end.line);
3195
+ return Math.max(0, s - i);
3196
+ }
3197
+ rememberActiveFoldSnapshots(e) {
3198
+ const t = /* @__PURE__ */ new Map(), i = this.getLineInfo(e);
3199
+ for (const s of this.getActiveFolds()) {
3200
+ const n = this.createFoldSnapshot(s, e, i);
3201
+ n && t.set(this.getFoldKey(s), n);
3202
+ }
3203
+ this.foldSnapshots = t;
3204
+ }
3205
+ createFoldSnapshot(e, t, i = this.getLineInfo(t)) {
3206
+ var h, d;
3207
+ const { lineStarts: s, lines: n } = i;
3208
+ if (n.length === 0)
3209
+ return null;
3210
+ const r = this.positionToOffset(e.start, s, n), o = this.positionToOffset(e.end, s, n), l = Math.max(0, Math.min(e.start.line, n.length - 1)), a = Math.max(0, Math.min(e.end.line, n.length - 1));
3211
+ return {
3212
+ hiddenText: t.slice(r, o),
3213
+ startLineText: (h = n[l]) != null ? h : "",
3214
+ endLineText: (d = n[a]) != null ? d : "",
3215
+ lineSpan: e.end.line - e.start.line
3216
+ };
3217
+ }
3218
+ withPreservedSelection(e) {
3219
+ var l, a;
3220
+ if (!this.editor) {
3221
+ e();
3222
+ return;
3223
+ }
3224
+ const t = this.editor.getView(), i = t.getContentElement(), s = document.activeElement === i, n = t.getSelectionOffsets(), r = n.isInEditor;
3225
+ if (e(), !r)
3226
+ return;
3227
+ const o = this.remapSelectionOffsetsForVisibleDisplay(
3228
+ (l = n.anchorOffset) != null ? l : n.startOffset,
3229
+ (a = n.focusOffset) != null ? a : n.endOffset
3230
+ );
3231
+ t.setSelectionBoundaryOffsets(
3232
+ o.startOffset,
3233
+ o.endOffset
3234
+ ), (s || n.isInEditor) && this.editor.focus();
3235
+ }
3236
+ remapSelectionOffsetsForVisibleDisplay(e, t) {
3237
+ if (!this.editor)
3238
+ return { startOffset: e, endOffset: t };
3239
+ const i = this.editor.getValue(), { lineStarts: s, lines: n } = this.getLineInfo(i), r = this.getRenderableActiveFolds();
3240
+ if (r.length === 0) {
3241
+ const o = i.length;
3242
+ return {
3243
+ startOffset: Math.max(0, Math.min(e, o)),
3244
+ endOffset: Math.max(0, Math.min(t, o))
3245
+ };
3246
+ }
3247
+ return {
3248
+ startOffset: this.remapOffsetToVisibleBoundary(
3249
+ e,
3250
+ r,
3251
+ s,
3252
+ n,
3253
+ i.length
3254
+ ),
3255
+ endOffset: this.remapOffsetToVisibleBoundary(
3256
+ t,
3257
+ r,
3258
+ s,
3259
+ n,
3260
+ i.length
3261
+ )
3262
+ };
3263
+ }
3264
+ remapOffsetToVisibleBoundary(e, t, i, s, n) {
3265
+ const r = Math.max(0, Math.min(e, n));
3266
+ for (const o of t) {
3267
+ const l = this.positionToOffset(o.start, i, s), a = this.positionToOffset(o.end, i, s);
3268
+ if (r <= l || r >= a)
3269
+ continue;
3270
+ const h = r - l, d = a - r;
3271
+ return h <= d ? l : a;
3272
+ }
3273
+ return r;
3274
+ }
3275
+ buildLineStarts(e) {
3276
+ const t = e.split(`
3277
+ `), i = new Array(t.length);
3278
+ let s = 0;
3279
+ for (let n = 0; n < t.length; n++)
3280
+ i[n] = s, s += t[n].length + 1;
3281
+ return { lineStarts: i, lines: t };
3282
+ }
3283
+ getLineInfo(e) {
3284
+ var i;
3285
+ if (((i = this.cachedLineInfo) == null ? void 0 : i.text) === e)
3286
+ return this.cachedLineInfo;
3287
+ const t = {
3288
+ text: e,
3289
+ ...this.buildLineStarts(e)
3290
+ };
3291
+ return this.cachedLineInfo = t, t;
3292
+ }
3293
+ offsetToLine(e, t, i) {
3294
+ var l;
3295
+ const s = t.length > 0 ? t[t.length - 1] + (((l = i[i.length - 1]) == null ? void 0 : l.length) || 0) : 0, n = Math.max(0, Math.min(e, s));
3296
+ let r = 0, o = t.length - 1;
3297
+ for (; r <= o; ) {
3298
+ const a = Math.floor((r + o) / 2), h = t[a], d = a + 1 < t.length ? t[a + 1] : Number.POSITIVE_INFINITY;
3299
+ if (n < h) {
3300
+ o = a - 1;
3301
+ continue;
3302
+ }
3303
+ if (n >= d) {
3304
+ r = a + 1;
3305
+ continue;
3306
+ }
3307
+ return a;
3308
+ }
3309
+ return Math.max(0, Math.min(r, t.length - 1));
3310
+ }
3311
+ positionToOffset(e, t, i) {
3312
+ var r;
3313
+ const s = Math.max(0, Math.min(e.line, i.length - 1)), n = Math.max(0, Math.min(e.column, ((r = i[s]) == null ? void 0 : r.length) || 0));
3314
+ return t[s] + n;
3315
+ }
3316
+ comparePositions(e, t) {
3317
+ return e.line !== t.line ? e.line - t.line : e.column - t.column;
3318
+ }
3319
+ containsRange(e, t) {
3320
+ return this.comparePositions(e.start, t.start) <= 0 && this.comparePositions(e.end, t.end) >= 0 && !this.isSameRange(e, t);
3321
+ }
3322
+ isSameRange(e, t) {
3323
+ return e.start.line === t.start.line && e.start.column === t.start.column && e.end.line === t.end.line && e.end.column === t.end.column;
3324
+ }
3325
+ isFoldActive(e) {
3326
+ return this.getActiveFolds().some((t) => this.isSameRange(t, e));
3327
+ }
3328
+ isValidFoldRegion(e) {
3329
+ return e.start.line < e.end.line && (e.start.line !== e.end.line || e.start.column !== e.end.column);
3330
+ }
3331
+ getFoldKey(e) {
3332
+ return `${e.start.line}:${e.start.column}-${e.end.line}:${e.end.column}`;
3333
+ }
3334
+ destroy() {
3335
+ 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.restoreFullDisplay(), this.changeHandler = null, this.lastSnapshot = "", this.lastParsedText = null, this.foldingUI = null, this.foldRegions = [], this.cachedLineInfo = null, this.editor = null;
3336
+ }
3337
+ }
3338
+ class he {
3339
+ constructor() {
3340
+ this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
3341
+ }
3342
+ setup(e) {
3343
+ this.editor = e, this.registerMode("html", { name: "html", highlight: (t, i) => this._highlightHTML(t, i) }), this.registerMode("css", { name: "css", highlight: (t, i) => this._highlightCSS(t, i) }), this.registerMode("javascript", { name: "javascript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("js", { name: "javascript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("jsx", { name: "jsx", highlight: (t, i) => this._highlightJSX(t, i) }), this.registerMode("typescript", { name: "typescript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("ts", { name: "typescript", highlight: (t, i) => this._highlightJS(t, i) }), this.registerMode("tsx", { name: "tsx", highlight: (t, i) => this._highlightJSX(t, i) }), this.registerMode("json", { name: "json", highlight: (t, i) => this._highlightJSON(t, i) }), this.registerMode("markdown", { name: "markdown", highlight: (t, i) => this._highlightMarkdown(t, i) }), this.registerMode("md", { name: "markdown", highlight: (t, i) => this._highlightMarkdown(t, i) }), this.registerMode("bash", { name: "bash", highlight: (t, i) => this._highlightShell(t, i) }), this.registerMode("shell", { name: "bash", highlight: (t, i) => this._highlightShell(t, i) }), this.registerMode("sh", { name: "bash", highlight: (t, i) => this._highlightShell(t, i) }), this.registerMode("zsh", { name: "bash", highlight: (t, i) => this._highlightShell(t, i) }), this.registerMode("python", { name: "python", highlight: (t, i) => this._highlightGenericCode(t, i, "python") }), this.registerMode("py", { name: "python", highlight: (t, i) => this._highlightGenericCode(t, i, "python") }), this.registerMode("go", { name: "go", highlight: (t, i) => this._highlightGenericCode(t, i, "go") }), this.registerMode("golang", { name: "go", highlight: (t, i) => this._highlightGenericCode(t, i, "go") }), this.registerMode("c", { name: "c", highlight: (t, i) => this._highlightGenericCode(t, i, "c") }), this.registerMode("cpp", { name: "cpp", highlight: (t, i) => this._highlightGenericCode(t, i, "cpp") }), this.registerMode("c++", { name: "cpp", highlight: (t, i) => this._highlightGenericCode(t, i, "cpp") }), this.registerMode("cc", { name: "cpp", highlight: (t, i) => this._highlightGenericCode(t, i, "cpp") }), this.registerMode("cxx", { name: "cpp", highlight: (t, i) => this._highlightGenericCode(t, i, "cpp") }), this.registerMode("java", { name: "java", highlight: (t, i) => this._highlightGenericCode(t, i, "java") }), this.registerMode("csharp", { name: "csharp", highlight: (t, i) => this._highlightGenericCode(t, i, "csharp") }), this.registerMode("cs", { name: "csharp", highlight: (t, i) => this._highlightGenericCode(t, i, "csharp") }), this.registerMode("rust", { name: "rust", highlight: (t, i) => this._highlightGenericCode(t, i, "rust") }), this.registerMode("rs", { name: "rust", highlight: (t, i) => this._highlightGenericCode(t, i, "rust") }), this.registerMode("ruby", { name: "ruby", highlight: (t, i) => this._highlightGenericCode(t, i, "ruby") }), this.registerMode("rb", { name: "ruby", highlight: (t, i) => this._highlightGenericCode(t, i, "ruby") }), this.registerMode("sql", { name: "sql", highlight: (t, i) => this._highlightGenericCode(t, i, "sql") }), this.registerMode("yaml", { name: "yaml", highlight: (t, i) => this._highlightYAML(t, i) }), this.registerMode("yml", { name: "yaml", highlight: (t, i) => this._highlightYAML(t, i) }), this.registerMode("xml", { name: "xml", highlight: (t, i) => this._highlightXML(t, i) }), this.registerMode("svg", { name: "xml", highlight: (t, i) => this._highlightXML(t, i) }), this.registerMode("vue", { name: "vue", highlight: (t, i) => this._highlightHTML(t, i) }), this.registerMode("ejs", { name: "ejs", highlight: (t, i) => this._highlightEJS(t, i) }), this.registerMode("dockerfile", { name: "dockerfile", highlight: (t, i) => this._highlightDockerfile(t, i) }), this.registerMode("docker", { name: "dockerfile", highlight: (t, i) => this._highlightDockerfile(t, i) }), this.registerMode("php", { name: "php", highlight: (t, i) => this._highlightPHP(t, i) }), e.registerCommand("setSyntaxLanguage", (t) => {
3344
+ this.setLanguage(t), this.refreshEditorHighlight();
3345
+ });
3346
+ }
3347
+ // Extension provides methods that can be called by the editor
3348
+ setTheme(e) {
3349
+ this.currentTheme = e;
3350
+ }
3351
+ setLanguage(e) {
3352
+ this.currentLanguage = e;
3353
+ }
3354
+ registerMode(e, t) {
3355
+ this.modes.set(e.toLowerCase(), t);
3356
+ }
3357
+ // Method to get syntax highlighting colors for a given theme
3358
+ getSyntaxColors() {
3359
+ return this.currentTheme === "dark" ? {
3360
+ tag: "#569cd6",
3361
+ // Blue
3362
+ comment: "#6a9955",
3363
+ // Green
3364
+ attrName: "#9cdcfe",
3365
+ // Light blue for attribute names
3366
+ attrValue: "#ce9178",
3367
+ // Orange for attribute values
3368
+ styleProp: "#c586c0",
3369
+ // Purple for CSS property names
3370
+ styleVal: "#dcdcaa",
3371
+ // Yellow-ish for CSS values
3372
+ doctype: "#808080",
3373
+ // Gray for doctype
3374
+ text: "#d4d4d4",
3375
+ // Light gray for normal text
3376
+ keyword: "#c586c0",
3377
+ // JS/PHP keywords (purple)
3378
+ string: "#ce9178",
3379
+ // JS strings
3380
+ number: "#b5cea8",
3381
+ // numbers
3382
+ variable: "#9cdcfe"
3383
+ // php variable color
3384
+ } : {
3385
+ tag: "#0000ff",
3386
+ // Blue
3387
+ comment: "#008000",
3388
+ // Green
3389
+ attrName: "#001080",
3390
+ attrValue: "#a31515",
3391
+ // Red
3392
+ styleProp: "#6a00a8",
3393
+ styleVal: "#804000",
3394
+ doctype: "#444444",
3395
+ text: "#000000",
3396
+ // Black
3397
+ keyword: "#000080",
3398
+ string: "#a31515",
3399
+ number: "#0086b3",
3400
+ variable: "#001080"
3401
+ };
3402
+ }
3403
+ // Public API: highlight a source string using the chosen mode (or detect html)
3404
+ highlight(e, t) {
3405
+ const i = this.getSyntaxColors(), s = this.normalizeLanguageId(
3406
+ t || this.currentLanguage || this.detectLanguage(e) || "html"
3407
+ );
3408
+ return (this.modes.get(s) || this.modes.get("html")).highlight(e, i);
3409
+ }
3410
+ // Backwards-compatible method
3411
+ highlightHTML(e) {
3412
+ return this.highlight(e, "html");
3413
+ }
3414
+ // --- Internal mode implementations ---
3415
+ escapeHTML(e) {
3416
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;");
3417
+ }
3418
+ normalizeLanguageId(e) {
3419
+ const t = e.trim().toLowerCase().replace(/^\./, "");
3420
+ return {
3421
+ cjs: "javascript",
3422
+ js: "javascript",
3423
+ javascriptreact: "javascript",
3424
+ jsx: "jsx",
3425
+ mjs: "javascript",
3426
+ mts: "typescript",
3427
+ ts: "typescript",
3428
+ tsx: "tsx",
3429
+ typescriptreact: "tsx",
3430
+ md: "markdown",
3431
+ mdx: "markdown",
3432
+ shell: "bash",
3433
+ sh: "bash",
3434
+ zsh: "bash",
3435
+ console: "bash",
3436
+ terminal: "bash",
3437
+ docker: "dockerfile",
3438
+ dockerfile: "dockerfile",
3439
+ golang: "go",
3440
+ py: "python",
3441
+ cxx: "cpp",
3442
+ cc: "cpp",
3443
+ "c++": "cpp",
3444
+ cs: "csharp",
3445
+ rs: "rust",
3446
+ rb: "ruby",
3447
+ yml: "yaml",
3448
+ svg: "xml",
3449
+ vue: "vue",
3450
+ ejs: "ejs"
3451
+ }[t] || t || "html";
3452
+ }
3453
+ restoreHighlightTokens(e, t) {
3454
+ return e.replace(/\u0000([a-z]+)\u0000/g, (i, s) => {
3455
+ let n = 0;
3456
+ for (let r = 0; r < s.length; r++)
3457
+ n = n * 26 + (s.charCodeAt(r) - 97 + 1);
3458
+ return n = n - 1, t[n] || "";
3459
+ });
3460
+ }
3461
+ createTokenStore(e) {
3462
+ const t = (i) => {
3463
+ let s = "", n = i;
3464
+ do
3465
+ s = String.fromCharCode(97 + n % 26) + s, n = Math.floor(n / 26) - 1;
3466
+ while (n >= 0);
3467
+ return s || "a";
3468
+ };
3469
+ return (i) => {
3470
+ const s = e.length;
3471
+ return e.push(i), `\0${t(s)}\0`;
3472
+ };
3473
+ }
3474
+ refreshEditorHighlight() {
3475
+ const e = this.editor;
3476
+ e != null && e.renderTextWithHighlight && e.renderTextWithHighlight(e.getValue(), !0);
3477
+ }
3478
+ // Robustly unescape common HTML entities, repeating a few times to handle nested encoding like &amp;amp;...
3479
+ unescapeEntitiesRepeated(e) {
3480
+ let t = e || "";
3481
+ for (let i = 0; i < 5; i++) {
3482
+ const s = t;
3483
+ if (t = t.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'"), t === s) break;
3484
+ }
3485
+ return t;
3486
+ }
3487
+ detectLanguage(e) {
3488
+ const t = e.trim();
3489
+ if (!t)
3490
+ return null;
3491
+ if (/^<\?(?:php\b|=)/i.test(t) || /^\?php\b/i.test(t))
3492
+ return "php";
3493
+ if (/^[\[{]/.test(t) && /[\]}]$/.test(t) || /"[^"]+"\s*:/.test(t))
3494
+ try {
3495
+ return JSON.parse(t), "json";
3496
+ } catch (o) {
3497
+ }
3498
+ const i = /<\/?[A-Za-z][\w:-]*(?:\s|>|\/>)/.test(t), s = /^<!DOCTYPE\s+html\b/i.test(t) || /<\/?(html|head|body|meta|title|style|script)\b/i.test(t);
3499
+ if ([
3500
+ /^---\s*\n[\s\S]*?\n---\s*(?:\n|$)/.test(t),
3501
+ /^#{1,6}\s+\S/m.test(t),
3502
+ /^\s*```/m.test(t),
3503
+ /^\s*~~~/m.test(t),
3504
+ /^\s{0,3}>\s+/m.test(t),
3505
+ /^\s{0,3}(?:[-*+]|\d+\.)\s+\S/m.test(t),
3506
+ /^\s{0,3}[-*+]\s+\[[ xX]\]\s+\S/m.test(t),
3507
+ /\[[^\]\n]+\]\([^)]+\)/.test(t),
3508
+ /!\[[^\]\n]*\]\([^)]+\)/.test(t),
3509
+ /(^|\n)\s*\|.+\|\s*\n\s*\|[\s:-]+\|/m.test(t),
3510
+ /(^|\s)(?:\*\*|__)[^*_]+(?:\*\*|__)(?=\s|$|[.,;:!?])/m.test(t)
3511
+ ].filter(Boolean).length >= (i ? 2 : 1))
3512
+ return "markdown";
3513
+ if (s)
3514
+ return "html";
3515
+ const n = this.detectProgrammingLanguage(t);
3516
+ if (n)
3517
+ return n;
3518
+ const r = /[{][\s\S]*[}]/.test(t) && /[A-Za-z_-][\w-]*\s*:\s*[^;{}]+;?/.test(t) && !/\b(function|const|let|var|return|class|interface|type)\b/.test(t);
3519
+ return !i && r ? "css" : null;
3520
+ }
3521
+ detectProgrammingLanguage(e) {
3522
+ const t = {
3523
+ php: 0,
3524
+ python: 0,
3525
+ go: 0,
3526
+ cpp: 0,
3527
+ c: 0,
3528
+ java: 0,
3529
+ csharp: 0,
3530
+ rust: 0,
3531
+ ruby: 0,
3532
+ sql: 0,
3533
+ yaml: 0,
3534
+ dockerfile: 0
3535
+ }, i = (r, o, l = 1) => {
3536
+ o.test(e) && (t[r] += l);
3537
+ };
3538
+ i("python", /^\s*(from\s+\w+\s+import|import\s+\w+|def\s+\w+\s*\(|class\s+\w+|for\s+\w+\s+in\s+.+:|if\s+.+:|while\s+.+:|print\s*\()/m, 2), i("python", /^\s*[A-Za-z_]\w*\s*=\s*(?:\[|\{|\(|["']|\d)/m), i("python", /\b(True|False|None|self|elif|lambda|yield)\b/), i("go", /^\s*package\s+\w+/m, 3), i("go", /\bfunc\s+\w+\s*\(/, 2), i("go", /\b(import|defer|goroutine|chan|struct|interface)\b/), i("cpp", /^\s*#include\s*<[^>]+>/m, 2), i("cpp", /\b(std::|template\s*<|namespace\s+\w+|cout\s*<<|cin\s*>>)\b/, 2), i("cpp", /\b(class|public|private|protected|virtual|typename)\b/), i("c", /^\s*#include\s*[<"][^>"]+[>"]/m), i("c", /\b(int|char|float|double|void)\s+\w+\s*\(/), i("c", /\bprintf\s*\(/), i("java", /^\s*(package|import)\s+[\w.]+;/m, 2), i("java", /\b(public|private|protected)\s+(class|interface|enum)\s+\w+/, 2), i("java", /\bSystem\.out\.println\s*\(/), i("csharp", /^\s*using\s+[\w.]+;/m, 2), i("csharp", /\b(namespace|record|var|string|Console\.WriteLine)\b/), i("csharp", /\b(public|private|protected)\s+(class|interface|struct)\s+\w+/), i("rust", /\bfn\s+\w+\s*\(/, 2), i("rust", /\b(let\s+mut|impl\s+\w+|use\s+[\w:]+|println!\s*\()/), i("rust", /\b(crate|trait|enum|match|Some|None|Ok|Err)\b/), i("ruby", /^\s*(def|class|module)\s+\w+/m, 2), i("ruby", /\b(puts|require|attr_reader|elsif|end)\b/), i("sql", /^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\b/im, 3), i("sql", /\bFROM\s+\w+|\bWHERE\s+/i), i("yaml", /^---\s*$/m), i("yaml", /^\s*[A-Za-z0-9_.-]+\s*:\s+\S/m, 2), i("yaml", /^\s*-\s+[A-Za-z0-9_.-]+\s*:/m), i("dockerfile", /^\s*FROM\s+\S+/im, 3), i("dockerfile", /^\s*(RUN|COPY|ADD|CMD|ENTRYPOINT|WORKDIR|ENV|ARG)\b/im, 2), i("php", /^<\?(?:php\b|=)/i, 3), i("php", /^\?php\b/i, 3), i("php", /\$[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*\s*=/, 2), i("php", /\b(echo|foreach|function|namespace|use|PHP_EOL)\b/, 2);
3539
+ const [s, n] = Object.entries(t).sort((r, o) => o[1] - r[1])[0] || ["", 0];
3540
+ return n >= 2 ? s : null;
3541
+ }
3542
+ _highlightHTML(e, t) {
3543
+ const i = t, s = (c) => this.escapeHTML(c), n = [], r = this.createTokenStore(n), o = [], l = (c) => {
3544
+ const u = o.length;
3545
+ return o.push(c), `ht${u}`;
3546
+ };
3547
+ let a = s(e);
3548
+ a = a.replace(
3549
+ /&lt;\/?(?:(?!&gt;)[^\n\r<])*?(?=$|[\n\r])/g,
3550
+ (c) => l(c)
3551
+ );
3552
+ const h = [];
3553
+ try {
3554
+ e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (c, u, g) => (h.push({ attrs: String(u || ""), inner: String(g || "") }), c));
3555
+ } catch (c) {
3556
+ }
3557
+ let d = 0;
3558
+ return a = a.replace(/(&lt;script\b([^&>]*)&gt;)([\s\S]*?)(&lt;\/script&gt;)/gi, (c, u, g, f, p) => {
3559
+ var v, T, w;
3560
+ const m = (T = (v = h[d++]) == null ? void 0 : v.inner) != null ? T : this.unescapeEntitiesRepeated(f || "");
3561
+ (((w = h[d - 1]) == null ? void 0 : w.attrs) || g || "").toLowerCase();
3562
+ const x = this._highlightJS(m, i);
3563
+ return `${u}${x}${p}`;
3564
+ }), a = a.replace(/(&lt;style\b[^&]*&gt;)([\s\S]*?)(&lt;\/style&gt;)/gi, (c, u, g, f) => {
3565
+ const p = this._highlightCSS(this.unescapeEntitiesRepeated(g), i);
3566
+ return `${u}${p}${f}`;
3567
+ }), a = a.replace(
3568
+ /(&lt;!--[\s\S]*?--&gt;)/g,
3569
+ (c) => r(`<span style="color: ${i.comment};">${c}</span>`)
3570
+ ), a = a.replace(
3571
+ /(&lt;!DOCTYPE[\s\S]*?&gt;)/i,
3572
+ (c) => r(`<span style="color: ${i.doctype};">${c}</span>`)
3573
+ ), a = a.replace(/(&lt;\/?\s*)([^\s&>\/]+)([^<]*?)(\/?&gt;)/g, (c, u, g, f, p) => {
3574
+ const m = `<span style="color: ${i.tag};">${g}</span>`;
3575
+ let x = f;
3576
+ return x = x.replace(
3577
+ /([\w:-]+)(\s*=\s*)((&quot;[\s\S]*?&quot;|&#39;[\s\S]*?&#39;|[^\s&>]+))/g,
3578
+ (v, T, w, S) => {
3579
+ const L = String(T).toLowerCase(), H = `<span style="color: ${i.attrName};">${T}</span>`;
3580
+ let I = S, C = "";
3581
+ S.startsWith("&quot;") && S.endsWith("&quot;") ? (I = S.slice(6, -6), C = "&quot;") : S.startsWith("&#39;") && S.endsWith("&#39;") && (I = S.slice(5, -5), C = "&#39;");
3582
+ let M = S;
3583
+ if (L === "style") {
3584
+ const D = I.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (A, k, F, $) => `<span style="color: ${i.styleProp};">${k}</span>:<span style="color: ${i.styleVal};">${F}</span>${$}`);
3585
+ C ? M = `${C}${D}${C}` : M = D, M = `<span style="color: ${i.attrValue};">${M}</span>`;
3586
+ } else
3587
+ C && (M = `${C}${I}${C}`), M = `<span style="color: ${i.attrValue};">${M}</span>`;
3588
+ return `${H}${w}${M}`;
3589
+ }
3590
+ ), `${u}${m}${x}${p}`;
3591
+ }), a = a.replace(/\u0002ht(\d+)\u0002/g, (c, u) => o[Number(u)] || ""), this.restoreHighlightTokens(a, n);
3592
+ }
3593
+ _highlightCSS(e, t) {
3594
+ const i = this.unescapeEntitiesRepeated(e), s = [], n = this.createTokenStore(s), r = /(\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
3595
+ let o = 0, l = "", a;
3596
+ for (; a = r.exec(i); ) {
3597
+ o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
3598
+ const h = a[0], d = h.startsWith("/*") ? t.comment : t.string;
3599
+ l += n(`<span style="color: ${d};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
3600
+ }
3601
+ return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
3602
+ /(@[\w-]+)/g,
3603
+ (h) => n(`<span style="color: ${t.keyword};">${h}</span>`)
3604
+ ), l = l.replace(
3605
+ /([A-Za-z_-][\w-]*)(\s*:)/g,
3606
+ (h, d, c) => `${n(`<span style="color: ${t.styleProp};">${d}</span>`)}${c}`
3607
+ ), l = l.replace(
3608
+ /(#(?:[0-9a-fA-F]{3,8})\b)/g,
3609
+ (h) => n(`<span style="color: ${t.number};">${h}</span>`)
3610
+ ), l = l.replace(
3611
+ /\b(-?\d*\.?\d+(?:px|em|rem|vh|vw|vmin|vmax|%|s|ms|deg|turn|fr)?)\b/g,
3612
+ (h) => n(`<span style="color: ${t.number};">${h}</span>`)
3613
+ ), l = l.replace(
3614
+ /\b(important|inherit|initial|unset|revert|auto|none|block|inline|flex|grid|absolute|relative|fixed|sticky)\b/g,
3615
+ (h) => n(`<span style="color: ${t.styleVal};">${h}</span>`)
3616
+ ), this.restoreHighlightTokens(l, s);
3617
+ }
3618
+ _highlightJSON(e, t) {
3619
+ const i = this.unescapeEntitiesRepeated(e), s = /("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}\[\],:]/g;
3620
+ let n = 0, r = "", o;
3621
+ for (; o = s.exec(i); ) {
3622
+ n < o.index && (r += this.escapeHTML(i.slice(n, o.index)));
3623
+ const l = o[0], a = o[1], h = o[2] || "", d = o[3];
3624
+ if (a) {
3625
+ const c = h ? t.attrName : t.string;
3626
+ r += `<span style="color: ${c};">${this.escapeHTML(a)}</span>${this.escapeHTML(h)}`;
3627
+ } else d ? r += `<span style="color: ${t.keyword};">${l}</span>` : /^-?\d/.test(l) ? r += `<span style="color: ${t.number};">${l}</span>` : r += `<span style="color: ${t.tag};">${this.escapeHTML(l)}</span>`;
3628
+ n = s.lastIndex;
3629
+ }
3630
+ return n < i.length && (r += this.escapeHTML(i.slice(n))), r;
3631
+ }
3632
+ _highlightMarkdown(e, t) {
3633
+ var l;
3634
+ const i = this.unescapeEntitiesRepeated(e).split(`
3635
+ `);
3636
+ let s = !1, n = "", r = "", o = ((l = i[0]) == null ? void 0 : l.trim()) === "---";
3637
+ return i.map((a, h) => {
3638
+ const d = [], c = this.createTokenStore(d);
3639
+ if (o) {
3640
+ const f = a.trim() === "---", p = `<span style="color: ${f ? t.keyword : t.attrName};">${this.escapeHTML(a)}</span>`;
3641
+ return h > 0 && f && (o = !1), p;
3642
+ }
3643
+ const u = a.match(/^(\s*)(`{3,}|~{3,})(.*)$/);
3644
+ if (u) {
3645
+ const f = u[2];
3646
+ return s = !(s && f[0] === n[0]), n = s ? f : "", r = s ? this.extractMarkdownFenceLanguage(u[3] || "") : "", [
3647
+ this.escapeHTML(u[1]),
3648
+ `<span style="color: ${t.keyword}; font-weight: 700;">${this.escapeHTML(f)}</span>`,
3649
+ `<span style="color: ${t.string};">${this.escapeHTML(u[3] || "")}</span>`
3650
+ ].join("");
3651
+ }
3652
+ if (s)
3653
+ return this.highlightMarkdownFenceLine(a, r, t);
3654
+ let g = this.escapeHTML(a).replace(
3655
+ /(`[^`]+`)/g,
3656
+ (f) => c(`<span style="color: ${t.string}; background: rgba(148, 163, 184, 0.16); border-radius: 3px;">${f}</span>`)
3657
+ ).replace(
3658
+ /(!?\[[^\]\n]*\])(\([^)]+\))/g,
3659
+ (f, p, m) => c(`<span style="color: ${t.attrName};">${p}</span><span style="color: ${t.attrValue};">${m}</span>`)
3660
+ ).replace(
3661
+ /(\*\*|__)(.+?)\1/g,
3662
+ (f, p, m) => c(`<span style="color: ${t.keyword};">${p}</span><span style="color: ${t.tag}; font-weight: 700;">${m}</span><span style="color: ${t.keyword};">${p}</span>`)
3663
+ ).replace(
3664
+ /(~~)(.+?)\1/g,
3665
+ (f, p, m) => c(`<span style="color: ${t.keyword};">${p}</span><span style="color: ${t.comment}; text-decoration: line-through;">${m}</span><span style="color: ${t.keyword};">${p}</span>`)
3666
+ ).replace(
3667
+ /(\*|_)([^*_]+?)\1/g,
3668
+ (f, p, m) => c(`<span style="color: ${t.keyword};">${p}</span><span style="color: ${t.styleVal}; font-style: italic;">${m}</span><span style="color: ${t.keyword};">${p}</span>`)
3669
+ );
3670
+ return g = g.replace(
3671
+ /^(\s{0,3}#{1,6})(\s+.*)?$/,
3672
+ (f, p, m = "") => `<span style="color: ${t.keyword}; font-weight: 700;">${p}</span><span style="color: ${t.tag}; font-weight: 700;">${m}</span>`
3673
+ ), g = g.replace(
3674
+ /^(\s{0,3})((?:-\s*){3,}|(?:\*\s*){3,}|(?:_\s*){3,})$/,
3675
+ (f, p, m) => `${p}<span style="color: ${t.comment};">${m}</span>`
3676
+ ), g = g.replace(
3677
+ /^(\s{0,3}&gt;)(.*)$/,
3678
+ (f, p, m) => `<span style="color: ${t.comment};">${p}</span>${m}`
3679
+ ), g = g.replace(
3680
+ /^(\s*)([-*+])(\s+\[[ xX]\])(\s+)/,
3681
+ (f, p, m, x, v) => `${p}<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.attrName};">${x}</span>${v}`
3682
+ ), g = g.replace(
3683
+ /^(\s*)([-*+]|\d+\.)(\s+)/,
3684
+ (f, p, m, x) => `${p}<span style="color: ${t.keyword};">${m}</span>${x}`
3685
+ ), g = g.replace(
3686
+ /^(\s*\|.*\|\s*)$/,
3687
+ (f) => f.replace(/\|/g, (p) => `<span style="color: ${t.keyword};">${p}</span>`)
3688
+ ), this.restoreHighlightTokens(g, d);
3689
+ }).join(`
3690
+ `);
3691
+ }
3692
+ extractMarkdownFenceLanguage(e) {
3693
+ var i;
3694
+ const t = ((i = e.trim().match(/^([A-Za-z0-9_+.#-]+)/)) == null ? void 0 : i[1]) || "";
3695
+ return t ? this.normalizeLanguageId(t) : "";
3696
+ }
3697
+ highlightMarkdownFenceLine(e, t, i) {
3698
+ const s = t ? this.modes.get(t) : void 0;
3699
+ return !s || s.name === "markdown" ? `<span style="color: ${i.text};">${this.escapeHTML(e)}</span>` : s.highlight(e, i);
3700
+ }
3701
+ _highlightShell(e, t) {
3702
+ const i = this.unescapeEntitiesRepeated(e), s = [], n = this.createTokenStore(s), r = /(#[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|(\$\{?[A-Za-z_][\w]*\}?|\$[0-9@#?$*!])/g;
3703
+ let o = 0, l = "", a;
3704
+ for (; a = r.exec(i); ) {
3705
+ o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
3706
+ const h = a[0], d = h.startsWith("#") ? t.comment : h.startsWith("$") ? t.variable : t.string;
3707
+ l += n(`<span style="color: ${d};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
3708
+ }
3709
+ return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
3710
+ /(^|\s)(--?[A-Za-z0-9][\w-]*)(?=\s|=|$)/g,
3711
+ (h, d, c) => `${d}${n(`<span style="color: ${t.attrName};">${c}</span>`)}`
3712
+ ), l = l.replace(
3713
+ /\b(if|then|else|elif|fi|for|while|until|do|done|case|esac|function|export|unset|alias|source|return|in)\b/g,
3714
+ (h) => n(`<span style="color: ${t.keyword};">${h}</span>`)
3715
+ ), l = l.replace(
3716
+ /(^|\s)(npm|npx|pnpm|yarn|bun|node|git|cd|mkdir|touch|cp|mv|rm|cat|grep|rg|find|curl|wget|echo|printf|sudo|chmod|chown|docker|kubectl)(?=\s|$)/g,
3717
+ (h, d, c) => `${d}${n(`<span style="color: ${t.tag};">${c}</span>`)}`
3718
+ ), this.restoreHighlightTokens(l, s);
3719
+ }
3720
+ getLanguageKeywords(e) {
3721
+ const t = ["true", "false", "null", "nil", "none"];
3722
+ return [...{
3723
+ python: ["and", "as", "assert", "async", "await", "break", "class", "continue", "def", "del", "elif", "else", "except", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return", "try", "while", "with", "yield", "self", "True", "False", "None"],
3724
+ go: ["break", "case", "chan", "const", "continue", "defer", "default", "else", "fallthrough", "for", "func", "go", "goto", "if", "import", "interface", "map", "package", "range", "return", "select", "struct", "switch", "type", "var"],
3725
+ c: ["auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while"],
3726
+ cpp: ["alignas", "alignof", "auto", "bool", "break", "case", "catch", "char", "class", "concept", "const", "constexpr", "continue", "decltype", "default", "delete", "do", "double", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "if", "inline", "int", "long", "namespace", "new", "noexcept", "nullptr", "operator", "private", "protected", "public", "requires", "return", "short", "signed", "sizeof", "static", "struct", "switch", "template", "this", "throw", "true", "try", "typedef", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "while"],
3727
+ java: ["abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "if", "implements", "import", "instanceof", "int", "interface", "long", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile", "while"],
3728
+ csharp: ["abstract", "as", "async", "await", "base", "bool", "break", "case", "catch", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "get", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "out", "override", "params", "private", "protected", "public", "readonly", "record", "ref", "return", "sealed", "set", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "using", "var", "virtual", "void", "volatile", "while", "yield"],
3729
+ rust: ["as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", "while"],
3730
+ ruby: ["BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while", "yield"],
3731
+ sql: ["ADD", "ALTER", "AND", "AS", "ASC", "BETWEEN", "BY", "CASE", "CREATE", "DELETE", "DESC", "DISTINCT", "DROP", "ELSE", "END", "EXISTS", "FROM", "GROUP", "HAVING", "IN", "INDEX", "INNER", "INSERT", "INTO", "IS", "JOIN", "LEFT", "LIKE", "LIMIT", "NOT", "NULL", "ON", "OR", "ORDER", "OUTER", "PRIMARY", "RIGHT", "SELECT", "SET", "TABLE", "THEN", "UNION", "UPDATE", "VALUES", "WHEN", "WHERE"]
3732
+ }[e] || [], ...t];
3733
+ }
3734
+ _highlightGenericCode(e, t, i) {
3735
+ const s = this.unescapeEntitiesRepeated(e), n = [], r = this.createTokenStore(n), o = i === "python" || i === "ruby" || i === "sql" ? "#[^\\n\\r]*|--[^\\n\\r]*" : "\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n\\r]*", l = new RegExp(
3736
+ `(${o})|("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`)`,
3737
+ "g"
3738
+ );
3739
+ let a = 0, h = "", d;
3740
+ for (; d = l.exec(s); ) {
3741
+ a < d.index && (h += this.escapeHTML(s.slice(a, d.index)));
3742
+ const u = d[0], g = u.startsWith("//") || u.startsWith("/*") || u.startsWith("#") || u.startsWith("--") ? t.comment : t.string;
3743
+ h += r(`<span style="color: ${g};">${this.escapeHTML(u)}</span>`), a = l.lastIndex;
3744
+ }
3745
+ a < s.length && (h += this.escapeHTML(s.slice(a)));
3746
+ const c = Array.from(new Set(this.getLanguageKeywords(i)));
3747
+ if (c.length > 0) {
3748
+ const u = new RegExp(
3749
+ `\\b(${c.map((g) => g.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b`,
3750
+ i === "sql" ? "gi" : "g"
3751
+ );
3752
+ h = h.replace(
3753
+ u,
3754
+ (g) => r(`<span style="color: ${t.keyword};">${g}</span>`)
3755
+ );
3756
+ }
3757
+ return h = h.replace(
3758
+ /\b([A-Z][A-Za-z0-9_]*|[A-Za-z_][\w]*(?=\s*\())\b/g,
3759
+ (u) => r(`<span style="color: ${t.tag};">${u}</span>`)
3760
+ ), h = h.replace(
3761
+ /\b(-?0x[0-9a-fA-F]+|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:[uUlLfFdD]*)\b/g,
3762
+ (u) => r(`<span style="color: ${t.number};">${u}</span>`)
3763
+ ), h = h.replace(
3764
+ /(@[A-Za-z_][\w]*|#[A-Za-z_][\w]*|::[A-Za-z_][\w]*)/g,
3765
+ (u) => r(`<span style="color: ${t.attrName};">${u}</span>`)
3766
+ ), this.restoreHighlightTokens(h, n);
3767
+ }
3768
+ _highlightYAML(e, t) {
3769
+ const i = this.unescapeEntitiesRepeated(e), s = [], n = this.createTokenStore(s);
3770
+ let r = this.escapeHTML(i).replace(
3771
+ /(#.*)$/gm,
3772
+ (o) => n(`<span style="color: ${t.comment};">${o}</span>`)
3773
+ ).replace(
3774
+ /^(\s*[-?]?\s*)([A-Za-z0-9_.-]+)(\s*:)/gm,
3775
+ (o, l, a, h) => `${l}${n(`<span style="color: ${t.attrName};">${a}</span>`)}${h}`
3776
+ ).replace(
3777
+ /\b(true|false|null|yes|no|on|off)\b/gi,
3778
+ (o) => n(`<span style="color: ${t.keyword};">${o}</span>`)
3779
+ ).replace(
3780
+ /\b(-?\d+(?:\.\d+)?)\b/g,
3781
+ (o) => n(`<span style="color: ${t.number};">${o}</span>`)
3782
+ );
3783
+ return r = r.replace(
3784
+ /(&quot;[^&]*?&quot;|&#39;[^&]*?&#39;)/g,
3785
+ (o) => n(`<span style="color: ${t.string};">${o}</span>`)
3786
+ ), this.restoreHighlightTokens(r, s);
3787
+ }
3788
+ _highlightXML(e, t) {
3789
+ return this._highlightHTML(e, t);
3790
+ }
3791
+ _highlightJSX(e, t) {
3792
+ const i = [], s = e.replace(
3793
+ /<\/?[A-Za-z][\w.:-]*(?:\s+[^<>]*?)?\/?>/g,
3794
+ (n) => {
3795
+ const r = i.length, o = this.escapeHTML(n).replace(
3796
+ /(&lt;\/?)([A-Za-z][\w.:-]*)([\s\S]*?)(\/?&gt;)/,
3797
+ (l, a, h, d, c) => {
3798
+ const u = String(d || "").replace(
3799
+ /([A-Za-z_:][\w:.-]*)(\s*=\s*)/g,
3800
+ `<span style="color: ${t.attrName};">$1</span>$2`
3801
+ );
3802
+ return `${a}<span style="color: ${t.tag};">${h}</span>${u}${c}`;
3803
+ }
3804
+ );
3805
+ return i.push(o), `jsx${r}`;
3806
+ }
3807
+ );
3808
+ return this._highlightJS(s, t).replace(
3809
+ /\u0004jsx(\d+)\u0004/g,
3810
+ (n, r) => i[Number(r)] || ""
3811
+ );
3812
+ }
3813
+ _highlightEJS(e, t) {
3814
+ const i = [], s = e.replace(/<%[\s\S]*?%>/g, (n) => {
3815
+ const r = i.length;
3816
+ return i.push(`<span style="color: ${t.keyword};">${this.escapeHTML(n)}</span>`), `ejs${r}`;
3817
+ });
3818
+ return this._highlightHTML(s, t).replace(
3819
+ /\u0003ejs(\d+)\u0003/g,
3820
+ (n, r) => i[Number(r)] || ""
3821
+ );
3822
+ }
3823
+ _highlightDockerfile(e, t) {
3824
+ return this.unescapeEntitiesRepeated(e).split(`
3825
+ `).map((i) => {
3826
+ const s = this.escapeHTML(i);
3827
+ return /^\s*#/.test(i) ? `<span style="color: ${t.comment};">${s}</span>` : s.replace(
3828
+ /^(\s*)(FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ARG|ONBUILD|STOPSIGNAL|HEALTHCHECK|SHELL)(\b)/i,
3829
+ (n, r, o, l) => `${r}<span style="color: ${t.keyword};">${o}</span>${l}`
3830
+ );
3831
+ }).join(`
3832
+ `);
3833
+ }
3834
+ _highlightJS(e, t) {
3835
+ const i = this.unescapeEntitiesRepeated(e);
3836
+ this.escapeHTML(i);
3837
+ const s = [], n = (c) => {
3838
+ let u = "", g = c;
3839
+ do
3840
+ u = String.fromCharCode(97 + g % 26) + u, g = Math.floor(g / 26) - 1;
3841
+ while (g >= 0);
3842
+ return u || "a";
3843
+ }, r = (c) => `\0${n(c)}\0`, o = (c) => {
3844
+ const u = s.length;
3845
+ return s.push(c), r(u);
3846
+ };
3847
+ let l;
3848
+ const a = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
3849
+ let h = 0, d = "";
3850
+ for (; l = a.exec(i); ) {
3851
+ const c = l.index;
3852
+ h < c && (d += this.escapeHTML(i.slice(h, c)));
3853
+ const u = l[0];
3854
+ /^\/\*/.test(u) || /^\/\//.test(u) ? d += o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`) : d += o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`), h = a.lastIndex;
3855
+ }
3856
+ return h < i.length && (d += this.escapeHTML(i.slice(h))), d = d.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (c, u, g) => {
3857
+ const f = d[g - 1] || "", p = d[g + c.length] || "";
3858
+ return f === "&" || f === "#" || p === ";" || p === "#" ? c : `<span style="color: ${t.number};">${c}</span>`;
3859
+ }), d = d.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>`), d.replace(/\u0000([a-z]+)\u0000/g, (c, u) => {
3860
+ let g = 0;
3861
+ for (let f = 0; f < u.length; f++)
3862
+ g = g * 26 + (u.charCodeAt(f) - 97 + 1);
3863
+ return g = g - 1, s[g] || "";
3864
+ });
3865
+ }
3866
+ _highlightPHP(e, t) {
3867
+ const i = this.unescapeEntitiesRepeated(e);
3868
+ let s = this.escapeHTML(i);
3869
+ const n = [], r = (g) => {
3870
+ let f = "", p = g;
3871
+ do
3872
+ f = String.fromCharCode(97 + p % 26) + f, p = Math.floor(p / 26) - 1;
3873
+ while (p >= 0);
3874
+ return f || "a";
3875
+ }, o = (g) => {
3876
+ const f = n.length;
3877
+ return n.push(g), `\0${r(f)}\0`;
3878
+ }, l = (g, f) => {
3879
+ const p = s.indexOf(g);
3880
+ return p === -1 ? !1 : (s = s.slice(0, p) + f + s.slice(p + g.length), !0);
3881
+ };
3882
+ let a;
3883
+ const h = /\/\*[\s\S]*?\*\//g, d = /\/\/[^\n\r]*/g, c = /\#([^\n\r]*)/g, u = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
3884
+ for (; a = h.exec(i); ) {
3885
+ const g = a[0];
3886
+ l(this.escapeHTML(g), o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`));
3887
+ }
3888
+ for (; a = d.exec(i); ) {
3889
+ const g = a[0];
3890
+ l(this.escapeHTML(g), o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`));
3891
+ }
3892
+ for (; a = c.exec(i); ) {
3893
+ const g = a[0];
3894
+ l(this.escapeHTML(g), o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`));
3895
+ }
3896
+ for (; a = u.exec(i); ) {
3897
+ const g = a[0];
3898
+ l(this.escapeHTML(g), o(`<span style="color: ${t.string};">${this.escapeHTML(g)}</span>`));
3899
+ }
3900
+ return s = s.replace(
3901
+ /(&lt;\?(?:php\b|=)?|\?&gt;)/gi,
3902
+ (g) => o(`<span style="color: ${t.keyword};">${g}</span>`)
3903
+ ), s = s.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), s = s.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g, `<span style="color: ${t.keyword};">$1</span>`), s = s.replace(/\u0000([a-z]+)\u0000/g, (g, f) => {
3904
+ let p = 0;
3905
+ for (let m = 0; m < f.length; m++)
3906
+ p = p * 26 + (f.charCodeAt(m) - 97 + 1);
3907
+ return p = p - 1, n[p] || "";
3908
+ }), s;
3909
+ }
3910
+ // Method to check if content contains syntax that should be highlighted
3911
+ shouldHighlight(e) {
3912
+ return /<\/?[\w:-]+|<!--/.test(e);
3913
+ }
3914
+ destroy() {
3915
+ this.editor = null, this.modes.clear();
3916
+ }
3917
+ }
3918
+ function ce(E, e) {
3919
+ const t = { ...e };
3920
+ return t.extensions || (t.extensions = []), t.extensions.some((i) => i.name === "keymap") || t.extensions.unshift(new J(t.keymap)), t.extensions.some((i) => i.name === "transaction") || t.extensions.unshift(new ee()), new Y(E, t);
3921
+ }
3922
+ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Editor Dialog Styles */
3923
+ .rte-source-editor-overlay {
3924
+ position: fixed !important;
3925
+ top: 0 !important;
3926
+ left: 0 !important;
3927
+ right: 0 !important;
3928
+ bottom: 0 !important;
3929
+ width: 100vw !important;
3930
+ height: 100vh !important;
3931
+ background-color: rgba(0, 0, 0, 0.6) !important;
3932
+ display: flex !important;
3933
+ align-items: center !important;
3934
+ justify-content: center !important;
3935
+ z-index: 10000 !important;
3936
+ padding: 20px !important;
3937
+ box-sizing: border-box !important;
3938
+ margin: 0 !important;
3939
+ }
3940
+
3941
+ .rte-source-editor-overlay.fullscreen {
3942
+ padding: 0 !important;
3943
+ }
3944
+
3945
+ .rte-source-editor-modal {
3946
+ background: white;
3947
+ border-radius: 8px;
3948
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
3949
+ width: 100%;
3950
+ max-width: 1200px;
3951
+ max-height: 90vh;
3952
+ display: flex;
3953
+ flex-direction: column;
3954
+ overflow: hidden;
3955
+ position: relative;
3956
+ }
3957
+
3958
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-modal {
3959
+ border-radius: 0;
3960
+ max-width: 100%;
3961
+ max-height: 100vh;
3962
+ width: 100%;
3963
+ height: 100vh;
3964
+ }
3965
+
3966
+ .rte-source-editor-header {
3967
+ display: flex;
3968
+ align-items: center;
3969
+ justify-content: space-between;
3970
+ padding: 16px 20px;
3971
+ border-bottom: 1px solid #e1e5e9;
3972
+ background: #f8f9fa;
3973
+ border-radius: 8px 8px 0 0;
3974
+ }
3975
+
3976
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-header {
3977
+ border-radius: 0;
3978
+ }
3979
+
3980
+ .rte-source-editor-header h2 {
3981
+ margin: 0;
3982
+ font-size: 18px;
3983
+ font-weight: 600;
3984
+ color: #1a1a1a;
3985
+ }
3986
+
3987
+ .rte-source-editor-header-toolbar {
3988
+ display: flex;
3989
+ gap: 8px;
3990
+ margin-left: auto;
3991
+ margin-right: 16px;
3992
+ }
3993
+
3994
+ .rte-source-editor-toolbar-btn {
3995
+ background: none;
3996
+ border: none;
3997
+ cursor: pointer;
3998
+ padding: 6px;
3999
+ border-radius: 4px;
4000
+ font-size: 16px;
4001
+ line-height: 1;
4002
+ transition: all 0.2s ease;
4003
+ color: #666;
4004
+ }
4005
+
4006
+ .rte-source-editor-toolbar-btn:hover:not(:disabled) {
4007
+ background: #e1e5e9;
4008
+ color: #1a1a1a;
4009
+ }
4010
+
4011
+ .rte-source-editor-toolbar-btn:disabled {
4012
+ opacity: 0.5;
4013
+ cursor: not-allowed;
4014
+ }
4015
+
4016
+ .rte-source-editor-toolbar-btn.active {
4017
+ background: #007acc;
4018
+ color: white;
4019
+ }
4020
+
4021
+ .rte-source-editor-toolbar-btn.active:hover {
4022
+ background: #0056b3;
4023
+ }
4024
+
4025
+ .rte-source-editor-header-actions {
4026
+ display: flex;
4027
+ gap: 8px;
4028
+ }
4029
+
4030
+ .rte-source-editor-fullscreen-btn,
4031
+ .rte-source-editor-close-btn {
4032
+ background: none;
4033
+ border: none;
4034
+ cursor: pointer;
4035
+ padding: 4px;
4036
+ border-radius: 4px;
4037
+ color: #666;
4038
+ font-size: 16px;
4039
+ line-height: 1;
4040
+ transition: all 0.2s ease;
4041
+ }
4042
+
4043
+ .rte-source-editor-fullscreen-btn:hover,
4044
+ .rte-source-editor-close-btn:hover {
4045
+ background: #e1e5e9;
4046
+ color: #1a1a1a;
4047
+ }
4048
+
4049
+ .rte-source-editor-body {
4050
+ flex: 1;
4051
+ overflow: hidden;
4052
+ display: flex;
4053
+ flex-direction: column;
4054
+ }
4055
+
4056
+ .rte-source-editor-loading {
4057
+ display: flex;
4058
+ flex-direction: column;
4059
+ align-items: center;
4060
+ justify-content: center;
4061
+ padding: 40px;
4062
+ color: #666;
4063
+ position: absolute;
4064
+ z-index: 9;
4065
+ margin: 0 auto;
4066
+ width: 100%;
4067
+ top: 44%;
4068
+ }
4069
+
4070
+ .rte-source-editor-spinner {
4071
+ width: 32px;
4072
+ height: 32px;
4073
+ border: 3px solid #e1e5e9;
4074
+ border-top: 3px solid #007acc;
4075
+ border-radius: 50%;
4076
+ animation: spin 1s linear infinite;
4077
+ margin-bottom: 16px;
4078
+ }
4079
+
4080
+ @keyframes spin {
4081
+ 0% { transform: rotate(0deg); }
4082
+ 100% { transform: rotate(360deg); }
4083
+ }
4084
+
4085
+ .rte-source-editor-error {
4086
+ background: #fee;
4087
+ color: #c53030;
4088
+ padding: 12px 16px;
4089
+ border-left: 4px solid #c53030;
4090
+ margin: 16px;
4091
+ border-radius: 4px;
4092
+ font-size: 14px;
4093
+ }
4094
+
4095
+ .rte-source-editor-content {
4096
+ flex: 1;
4097
+ display: flex;
4098
+ flex-direction: column;
4099
+ overflow: hidden;
4100
+ }
4101
+
4102
+ .rte-source-editor-warning {
4103
+ background: #fefcbf;
4104
+ color: #744210;
4105
+ padding: 8px 16px;
4106
+ font-size: 12px;
4107
+ font-weight: 500;
4108
+ border-bottom: 1px solid #f6e05e;
4109
+ }
4110
+
4111
+ .rte-source-editor-codemirror {
4112
+ flex: 1;
4113
+ overflow: auto;
4114
+ font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
4115
+ font-size: 14px;
4116
+ line-height: 1.5;
4117
+ }
4118
+
4119
+ .rte-source-editor-codemirror .cm-editor {
4120
+ height: 100%;
4121
+ }
4122
+
4123
+ .rte-source-editor-codemirror .cm-focused {
4124
+ outline: none;
4125
+ }
4126
+
4127
+ .rte-source-editor-footer {
4128
+ display: flex;
4129
+ align-items: center;
4130
+ justify-content: space-between;
4131
+ padding: 16px 20px;
4132
+ border-top: 1px solid #e1e5e9;
4133
+ background: #f8f9fa;
4134
+ border-radius: 0 0 8px 8px;
4135
+ }
4136
+
4137
+ .rte-source-editor-overlay.fullscreen .rte-source-editor-footer {
4138
+ border-radius: 0;
4139
+ }
4140
+
4141
+ .rte-source-editor-footer-info {
4142
+ font-size: 12px;
4143
+ color: #666;
4144
+ }
4145
+
4146
+ .unsaved-changes {
4147
+ color: #d69e2e;
4148
+ font-weight: 500;
4149
+ }
4150
+
4151
+ .rte-source-editor-footer-actions {
4152
+ display: flex;
4153
+ gap: 12px;
4154
+ }
4155
+
4156
+ .rte-source-editor-btn {
4157
+ padding: 8px 16px;
4158
+ border-radius: 4px;
4159
+ font-size: 14px;
4160
+ font-weight: 500;
4161
+ cursor: pointer;
4162
+ border: 1px solid transparent;
4163
+ transition: all 0.2s ease;
4164
+ }
4165
+
4166
+ .rte-source-editor-btn:disabled {
4167
+ opacity: 0.6;
4168
+ cursor: not-allowed;
4169
+ }
4170
+
4171
+ .rte-source-editor-btn-cancel {
4172
+ background: white;
4173
+ border-color: #d1d5db;
4174
+ color: #374151;
4175
+ }
4176
+
4177
+ .rte-source-editor-btn-cancel:hover:not(:disabled) {
4178
+ background: #f9fafb;
4179
+ border-color: #9ca3af;
4180
+ }
4181
+
4182
+ .rte-source-editor-btn-save {
4183
+ background: #007acc;
4184
+ color: white;
4185
+ }
4186
+
4187
+ .rte-source-editor-btn-save:hover:not(:disabled) {
4188
+ background: #0056b3;
4189
+ }
4190
+
4191
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-modal {
4192
+ background: #1e1e1e;
4193
+ color: #f8f9fa;
4194
+ border: 1px solid #434d5f;
4195
+ }
4196
+
4197
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header,
4198
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer {
4199
+ background: #2a3442;
4200
+ border-color: #434d5f;
4201
+ }
4202
+
4203
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-header h2 {
4204
+ color: #f8f9fa;
4205
+ }
4206
+
4207
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn,
4208
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn,
4209
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn {
4210
+ color: #c1cede;
4211
+ }
4212
+
4213
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn:hover:not(:disabled),
4214
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-fullscreen-btn:hover,
4215
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-close-btn:hover {
4216
+ background: #404a5a;
4217
+ color: #f8fafc;
4218
+ }
4219
+
4220
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active {
4221
+ background: #3b82f6;
4222
+ color: #ffffff;
4223
+ }
4224
+
4225
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-toolbar-btn.active:hover {
4226
+ background: #2563eb;
4227
+ }
4228
+
4229
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-loading,
4230
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-footer-info {
4231
+ color: #cbd5e1;
4232
+ }
4233
+
4234
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-spinner {
4235
+ border-color: #3f4b60;
4236
+ border-top-color: #58a6ff;
4237
+ }
4238
+
4239
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-error {
4240
+ background: #3f2124;
4241
+ color: #fecaca;
4242
+ border-color: #ef4444;
4243
+ }
4244
+
4245
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-warning {
4246
+ background: #3b3220;
4247
+ color: #fde68a;
4248
+ border-color: #f59e0b;
4249
+ }
4250
+
4251
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel {
4252
+ background: #334155;
4253
+ border-color: #475569;
4254
+ color: #f1f5f9;
4255
+ }
4256
+
4257
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-cancel:hover:not(:disabled) {
4258
+ background: #475569;
4259
+ border-color: #64748b;
4260
+ }
4261
+
4262
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save {
4263
+ background: #3b82f6;
4264
+ }
4265
+
4266
+ .rte-source-editor-overlay.rte-theme-dark .rte-source-editor-btn-save:hover:not(:disabled) {
4267
+ background: #2563eb;
4268
+ }
4269
+
4270
+ /* Responsive design */
4271
+ @media (max-width: 768px) {
4272
+ .rte-source-editor-overlay {
4273
+ padding: 10px;
4274
+ }
4275
+
4276
+ .rte-source-editor-modal {
4277
+ max-height: 95vh;
4278
+ }
4279
+
4280
+ .rte-source-editor-header {
4281
+ padding: 12px 16px;
4282
+ }
4283
+
4284
+ .rte-source-editor-footer {
4285
+ padding: 12px 16px;
4286
+ flex-direction: column;
4287
+ gap: 12px;
4288
+ align-items: stretch;
4289
+ }
4290
+
4291
+ .rte-source-editor-footer-actions {
4292
+ justify-content: stretch;
4293
+ }
4294
+
4295
+ .rte-source-editor-btn {
4296
+ flex: 1;
4297
+ text-align: center;
4298
+ }
4299
+ }`, ue = () => ({
4300
+ name: "code",
4301
+ // Toolbar button configuration
4302
+ toolbar: [
4303
+ {
4304
+ label: "Source",
4305
+ command: "toggleSourceView",
4306
+ // type: "button",
4307
+ 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>',
4308
+ shortcut: "Mod-Shift-S"
4309
+ }
4310
+ ],
4311
+ // Native command implementations
4312
+ commands: {
4313
+ /**
4314
+ * Toggle HTML source view
4315
+ * Opens a dialog to edit raw HTML
4316
+ */
4317
+ toggleSourceView: () => {
4318
+ const e = (() => {
4319
+ var o, l, a;
4320
+ const n = window.getSelection();
4321
+ if (n && n.anchorNode) {
4322
+ let h = n.anchorNode instanceof HTMLElement ? n.anchorNode : n.anchorNode.parentElement;
4323
+ for (; h; ) {
4324
+ if ((o = h.classList) != null && o.contains("rte-content"))
4325
+ return h;
4326
+ h = h.parentElement;
4327
+ }
4328
+ }
4329
+ if (document.activeElement) {
4330
+ let h = document.activeElement;
4331
+ if ((l = h.classList) != null && l.contains("rte-content"))
4332
+ return h;
4333
+ for (; h && h !== document.body; ) {
4334
+ if ((a = h.classList) != null && a.contains("rte-content"))
4335
+ return h;
4336
+ const d = h.querySelector(
4337
+ ".rte-content"
4338
+ );
4339
+ if (d) return d;
4340
+ h = h.parentElement;
4341
+ }
4342
+ }
4343
+ const r = document.querySelector("[data-editora-editor]");
4344
+ if (r) {
4345
+ const h = r.querySelector(
4346
+ ".rte-content"
4347
+ );
4348
+ if (h) return h;
4349
+ }
4350
+ return document.querySelector(".rte-content");
4351
+ })();
4352
+ if (!e)
4353
+ return console.error("[CodePlugin] Editor content area not found"), alert(
4354
+ "Editor content area not found. Please click inside the editor first."
4355
+ ), !1;
4356
+ const t = e.innerHTML, i = (n) => {
4357
+ let r = "", o = 0;
4358
+ const l = 2, a = n.split(/(<\/?[a-zA-Z][^>]*>)/);
4359
+ for (const h of a)
4360
+ h.trim() && (h.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), r += `
4361
+ ` + " ".repeat(o * l) + h) : h.match(/^<[a-zA-Z]/) && !h.match(/\/>$/) ? (r += `
4362
+ ` + " ".repeat(o * l) + h, o++) : h.match(/^<[a-zA-Z].*\/>$/) ? r += `
4363
+ ` + " ".repeat(o * l) + h : r += h.trim());
4364
+ return r.trim();
4365
+ };
4366
+ return (() => {
4367
+ const r = i(t);
4368
+ let o = null, l = "dark", a = !1, h = !1, d = !1, c = !1;
4369
+ const u = !!e.closest(B) || document.body.matches(B) || document.documentElement.matches(B), g = document.createElement("div");
4370
+ g.className = "rte-source-editor-overlay", u && g.classList.add("rte-theme-dark");
4371
+ const f = document.createElement("div");
4372
+ f.className = "rte-source-editor-modal", f.setAttribute("role", "dialog"), f.setAttribute("aria-modal", "true"), f.setAttribute("aria-labelledby", "source-editor-title");
4373
+ const p = document.createElement("div");
4374
+ p.className = "rte-source-editor-header", p.innerHTML = `
4375
+ <h2 id="source-editor-title">Source Editor</h2>
4376
+ <div class="rte-source-editor-header-toolbar">
4377
+ <button class="rte-source-editor-toolbar-btn theme-toggle-btn" title="Switch theme">
4378
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4379
+ <circle cx="12" cy="12" r="5"/>
4380
+ <line x1="12" y1="1" x2="12" y2="3"/>
4381
+ <line x1="12" y1="21" x2="12" y2="23"/>
4382
+ <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
4383
+ <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
4384
+ <line x1="1" y1="12" x2="3" y2="12"/>
4385
+ <line x1="21" y1="12" x2="23" y2="12"/>
4386
+ <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
4387
+ <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
4388
+ </svg>
4389
+ </button>
4390
+ <button class="rte-source-editor-toolbar-btn readonly-toggle-btn" title="Toggle read-only">
4391
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4392
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
4393
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
4394
+ </svg>
4395
+ </button>
4396
+ </div>
4397
+ <div class="rte-source-editor-header-actions">
4398
+ <button class="rte-source-editor-fullscreen-btn" title="Toggle fullscreen">
4399
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4400
+ <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
4401
+ </svg>
4402
+ </button>
4403
+ <button class="rte-source-editor-close-btn" aria-label="Close source editor">
4404
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4405
+ <line x1="18" y1="6" x2="6" y2="18"/>
4406
+ <line x1="6" y1="6" x2="18" y2="18"/>
4407
+ </svg>
4408
+ </button>
4409
+ </div>
4410
+ `;
4411
+ const m = document.createElement("div");
4412
+ m.className = "rte-source-editor-body";
4413
+ const x = document.createElement("div");
4414
+ x.className = "rte-source-editor-content";
4415
+ const v = document.createElement("div");
4416
+ v.className = "rte-source-editor-warning", v.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
4417
+ const T = document.createElement("div");
4418
+ T.className = "rte-source-editor-light-editor", T.style.height = "400px", x.appendChild(v), x.appendChild(T), m.appendChild(x);
4419
+ const w = document.createElement("div");
4420
+ if (w.className = "rte-source-editor-footer", w.innerHTML = `
4421
+ <div class="rte-source-editor-footer-info">
4422
+ <span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
4423
+ </div>
4424
+ <div class="rte-source-editor-footer-actions">
4425
+ <button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
4426
+ <button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
4427
+ </div>
4428
+ `, f.appendChild(p), f.appendChild(m), f.appendChild(w), g.appendChild(f), !document.getElementById("rte-source-editor-styles")) {
4429
+ const b = document.createElement("style");
4430
+ b.id = "rte-source-editor-styles", b.textContent = de, document.head.appendChild(b);
4431
+ }
4432
+ const S = p.querySelector(
4433
+ ".theme-toggle-btn"
4434
+ ), L = p.querySelector(
4435
+ ".readonly-toggle-btn"
4436
+ ), H = p.querySelector(
4437
+ ".rte-source-editor-fullscreen-btn"
4438
+ ), I = p.querySelector(
4439
+ ".rte-source-editor-close-btn"
4440
+ ), C = w.querySelector(
4441
+ ".rte-source-editor-btn-cancel"
4442
+ ), M = w.querySelector(
4443
+ ".rte-source-editor-btn-save"
4444
+ ), D = w.querySelector(
4445
+ ".unsaved-changes"
4446
+ ), A = [], k = (b, R, P, N) => {
4447
+ b.addEventListener(R, P, N), A.push(
4448
+ () => b.removeEventListener(R, P, N)
4449
+ );
4450
+ }, F = (b) => {
4451
+ d !== b && (d = b, D && (D.style.display = d ? "inline" : "none"));
4452
+ }, $ = () => {
4453
+ if (!c) {
4454
+ for (c = !0; A.length; ) {
4455
+ const b = A.pop();
4456
+ b == null || b();
4457
+ }
4458
+ o && (o.destroy(), o = null), g.isConnected && g.remove();
4459
+ }
4460
+ }, _ = () => {
4461
+ l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l), S && (S.innerHTML = l === "light" ? `
4462
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4463
+ <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
4464
+ </svg>
4465
+ ` : `
4466
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4467
+ <circle cx="12" cy="12" r="5"/>
4468
+ <line x1="12" y1="1" x2="12" y2="3"/>
4469
+ <line x1="12" y1="21" x2="12" y2="23"/>
4470
+ <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
4471
+ <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
4472
+ <line x1="1" y1="12" x2="3" y2="12"/>
4473
+ <line x1="21" y1="12" x2="23" y2="12"/>
4474
+ <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
4475
+ <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
4476
+ </svg>
4477
+ `);
4478
+ }, j = () => {
4479
+ a = !a, o == null || o.setReadOnly(a), L && (L.classList.toggle("active", a), L.innerHTML = a ? `
4480
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4481
+ <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
4482
+ <circle cx="12" cy="16" r="1"/>
4483
+ <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
4484
+ </svg>
4485
+ ` : `
4486
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4487
+ <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
4488
+ <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
4489
+ </svg>
4490
+ `);
4491
+ }, q = () => {
4492
+ h = !h, g.classList.toggle("fullscreen", h), T.style.height = h ? "calc(100vh - 200px)" : "400px", H && (H.innerHTML = h ? `
4493
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4494
+ <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"/>
4495
+ </svg>
4496
+ ` : `
4497
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
4498
+ <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>
4499
+ </svg>
4500
+ `);
4501
+ }, G = () => {
4502
+ d && !confirm("You have unsaved changes. Are you sure you want to cancel?") || $();
4503
+ }, Z = () => {
4504
+ try {
4505
+ const b = (o == null ? void 0 : o.getValue()) || "", R = document.createElement("div");
4506
+ R.innerHTML = b, R.querySelectorAll(
4507
+ 'script, iframe[src^="javascript:"], object, embed'
4508
+ ).forEach((N) => N.remove()), e.innerHTML = R.innerHTML;
4509
+ try {
4510
+ e.dispatchEvent(
4511
+ new InputEvent("input", {
4512
+ bubbles: !0,
4513
+ cancelable: !1,
4514
+ inputType: "insertReplacementText"
4515
+ })
4516
+ );
4517
+ } catch (N) {
4518
+ e.dispatchEvent(
4519
+ new Event("input", { bubbles: !0 })
4520
+ );
4521
+ }
4522
+ e.dispatchEvent(
4523
+ new Event("change", { bubbles: !0 })
4524
+ ), F(!1), $();
4525
+ } catch (b) {
4526
+ alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", b);
4527
+ }
4528
+ };
4529
+ S && k(S, "click", _), L && k(L, "click", j), H && k(H, "click", q), I && k(I, "click", $), C && k(C, "click", G), M && k(M, "click", Z), k(g, "click", (b) => {
4530
+ b.target === g && $();
4531
+ }), k(document, "keydown", (b) => {
4532
+ const R = b;
4533
+ R.key === "Escape" && (R.preventDefault(), $());
4534
+ }), document.body.appendChild(g), requestAnimationFrame(() => {
4535
+ if (!(c || !g.isConnected))
4536
+ try {
4537
+ o = ce(T, {
4538
+ value: r,
4539
+ theme: "dark",
4540
+ readOnly: !1,
4541
+ extensions: [
4542
+ new te(),
4543
+ new ie(),
4544
+ new se(),
4545
+ new le(),
4546
+ new re(),
4547
+ new ae(),
4548
+ new he()
4549
+ ]
4550
+ }), o.on("change", () => {
4551
+ const b = (o == null ? void 0 : o.getValue()) || "";
4552
+ F(b !== r);
4553
+ }), requestAnimationFrame(() => o == null ? void 0 : o.focus());
4554
+ } catch (b) {
4555
+ console.error("Failed to initialize code editor:", b);
4556
+ }
4557
+ });
4558
+ })(), !0;
4559
+ }
4560
+ },
4561
+ // Keyboard shortcuts
4562
+ keymap: {
4563
+ "Mod-Shift-s": "toggleSourceView",
4564
+ "Mod-Shift-S": "toggleSourceView"
4565
+ }
4566
+ });
4567
+ export {
4568
+ ue as CodePlugin
4569
+ };
4570
+ //# sourceMappingURL=CodePlugin.native-C5l1IeSS.mjs.map