@editora/core 1.0.9 → 1.0.11

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