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