@editora/core 1.0.14 → 1.0.16
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/{A11yCheckerPlugin.native-BRdGYMju.mjs → A11yCheckerPlugin.native-DIKuCeFw.mjs} +82 -79
- package/dist/{AnchorPlugin.native-BcYGEtd9.mjs → AnchorPlugin.native-DXZdK3zr.mjs} +72 -71
- package/dist/{ApprovalWorkflowPlugin.native-BZ6jO-Wj.mjs → ApprovalWorkflowPlugin.native-ZsS_2xmn.mjs} +239 -238
- package/dist/{BackgroundColorPlugin.native-50iAT9xU.mjs → BackgroundColorPlugin.native-H3XyYD7_.mjs} +2 -2
- package/dist/{BlocksLibraryPlugin.native-5sdsXsiE.mjs → BlocksLibraryPlugin.native-CownM6Rk.mjs} +140 -116
- package/dist/{CapitalizationPlugin.native-DLV4oPmB.mjs → CapitalizationPlugin.native-C-HRbXGh.mjs} +10 -5
- package/dist/{ChecklistPlugin.native-BS-kMz9O.mjs → ChecklistPlugin.native-NVrBUkaL.mjs} +141 -103
- package/dist/{CitationsPlugin.native-DQgoCd1B.mjs → CitationsPlugin.native-C_7wWQ-k.mjs} +441 -422
- package/dist/{ClearFormattingPlugin.native-B6ro3a1h.mjs → ClearFormattingPlugin.native-Pp0O-SBf.mjs} +24 -23
- package/dist/{CodePlugin.native-veDC_kx5.mjs → CodePlugin.native-BH-K4xmW.mjs} +1049 -917
- package/dist/CodePlugin.native-hNgfXlfS.mjs +4767 -0
- package/dist/CodeSamplePlugin.native-svbAFWh_.mjs +501 -0
- package/dist/CollaborationPlugin.native-oSybCGPW.mjs +7468 -0
- package/dist/{CommentsPlugin.native-DPSqTkiv.mjs → CommentsPlugin.native-CLip9wAO.mjs} +233 -185
- package/dist/{ConditionalContentPlugin.native-CfhY46rU.mjs → ConditionalContentPlugin.native-Bf7XgRSW.mjs} +401 -351
- package/dist/{DataBindingPlugin.native-BoXwghTz.mjs → DataBindingPlugin.native-B7lpI_0c.mjs} +29 -28
- package/dist/{DocumentManagerPlugin.native-C2cs_1w4.mjs → DocumentManagerPlugin.native-iFip6s4Q.mjs} +94 -45
- package/dist/{EmbedIframePlugin.native-BF_-LjTq.mjs → EmbedIframePlugin.native-BfZ_HGlV.mjs} +231 -186
- package/dist/{EmojisPlugin.native-CitxxlWX.mjs → EmojisPlugin.native-D92aaOKi.mjs} +288 -76
- package/dist/{FontFamilyPlugin.native-j8hMTbg4.mjs → FontFamilyPlugin.native-M3cNQ0KA.mjs} +57 -50
- package/dist/{FontSizePlugin.native-B_jCh7dY.mjs → FontSizePlugin.native-DsLrH8eq.mjs} +41 -34
- package/dist/{FormatPainterPlugin.native-CsMrKfFU.mjs → FormatPainterPlugin.native-BhjzsiVq.mjs} +3 -2
- package/dist/{HistoryPlugin.native-D2wl32jV.mjs → HistoryPlugin.native-DPvhks6h.mjs} +36 -32
- package/dist/LinkPlugin.native-BsQXYsK6.mjs +352 -0
- package/dist/{ListPlugin.native-V7EZC1lM.mjs → ListPlugin.native-Bt0LANbO.mjs} +68 -35
- package/dist/{MathPlugin.native-NwWPHVmj.mjs → MathPlugin.native-Byo3WL0f.mjs} +211 -115
- package/dist/{MediaManagerPlugin.native-eOsTJFpw.mjs → MediaManagerPlugin.native-BT1NZIJS.mjs} +139 -134
- package/dist/{MentionPlugin.native-BMDlOqur.mjs → MentionPlugin.native-S_lwGZQO.mjs} +23 -18
- package/dist/{MergeTagPlugin.native-BzRVoD9-.mjs → MergeTagPlugin.native-7-6F3S1Y.mjs} +44 -43
- package/dist/{PreviewPlugin.native-WuIwOAOR.mjs → PreviewPlugin.native-CiR51jql.mjs} +31 -28
- package/dist/{SlashCommandsPlugin.native-BiN6ODw5.mjs → SlashCommandsPlugin.native-BDIIwGNs.mjs} +90 -79
- package/dist/{SmartPastePlugin.native-CZAEHkyt.mjs → SmartPastePlugin.native-BATLCds5.mjs} +89 -85
- package/dist/{SpecialCharactersPlugin.native-DaG4b19I.mjs → SpecialCharactersPlugin.native-CdZoc1GB.mjs} +73 -26
- package/dist/SpellCheckPlugin.native-Bef2oTLB.mjs +10935 -0
- package/dist/TablePlugin.native-BjIxYZ2X.mjs +772 -0
- package/dist/{TemplatePlugin.native-DLjFUaPW.mjs → TemplatePlugin.native-D6n5RUnC.mjs} +288 -262
- package/dist/{TextColorPlugin.native-Bwl_bSmc.mjs → TextColorPlugin.native-KMZ2uzlq.mjs} +2 -2
- package/dist/{TranslationWorkflowPlugin.native-DdF16tgT.mjs → TranslationWorkflowPlugin.native-CZtG--06.mjs} +67 -65
- package/dist/{VersionDiffPlugin.native-Bvxgy--t.mjs → VersionDiffPlugin.native-Ca1fMWUJ.mjs} +42 -42
- package/dist/anchoredPopover-DJFD2oAP.mjs +116 -0
- package/dist/core.css +1 -1
- package/dist/dialogHelpers-DBf7WqYH.mjs +40 -0
- package/dist/{documentManager-vQ1VkbUY.mjs → documentManager-BcBIv5P-.mjs} +3 -3
- package/dist/editora.min.js +26 -24
- package/dist/editora.umd.js +26 -24
- package/dist/escapeHtml-CX8RelZ1.mjs +7 -0
- package/dist/historyHelpers-B0-4mq1E.mjs +15 -0
- package/dist/index-B1_vtXRz.mjs +3910 -0
- package/dist/index-C6BoNR2t.js +12 -0
- package/dist/{index-BslAFzmv.mjs → index-CavM-mEM.mjs} +6391 -6203
- package/dist/index.cjs.js +3 -3
- package/dist/{index.es-BYD2KEo6.mjs → index.es-BK-4TPv8.mjs} +1562 -1546
- package/dist/index.esm.js +17 -14
- package/dist/{jspdf.es.min-BJGtOnRT.mjs → jspdf.es.min-BsnKYYHL.mjs} +4 -3
- package/dist/plugin-loader.js +53 -52
- package/dist/{purify.es-CKpwg8Tk.mjs → purify.es-DhWKBjsL.mjs} +3 -3
- package/dist/webcomponent-core.js +2039 -473
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +100 -70
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +2208 -641
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +1575 -1209
- package/index.d.ts +32 -0
- package/package.json +10 -3
- package/dist/CodeSamplePlugin.native-CgGoH-X4.mjs +0 -384
- package/dist/LinkPlugin.native-DYCIcdTm.mjs +0 -283
- package/dist/SpellCheckPlugin.native-BZB9AewP.mjs +0 -1039
- package/dist/TablePlugin.native-DrHX-efe.mjs +0 -495
- package/dist/anchoredPopover-Bxds0VoB.mjs +0 -110
- package/dist/index-B9MPiUAR.mjs +0 -2341
- package/dist/index-BLm1MtzH.js +0 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { i as Q } from "./dialogHelpers-DBf7WqYH.mjs";
|
|
2
|
+
class K {
|
|
2
3
|
constructor(e = "") {
|
|
3
4
|
this._lines = [], this._version = 0, this.setText(e);
|
|
4
5
|
}
|
|
@@ -37,8 +38,8 @@ class V {
|
|
|
37
38
|
}
|
|
38
39
|
// Replace text in range
|
|
39
40
|
replaceRange(e, t) {
|
|
40
|
-
const i = this.normalizeRange(e),
|
|
41
|
-
return this.setText(l), { range: i, text: t, oldText:
|
|
41
|
+
const i = this.normalizeRange(e), n = this.getTextInRange(i), s = this.getText(), r = this.positionToOffset(i.start), o = this.positionToOffset(i.end), l = s.slice(0, r) + t + s.slice(o);
|
|
42
|
+
return this.setText(l), { range: i, text: t, oldText: n };
|
|
42
43
|
}
|
|
43
44
|
// Insert text at position
|
|
44
45
|
insertText(e, t) {
|
|
@@ -60,10 +61,10 @@ class V {
|
|
|
60
61
|
offsetToPosition(e) {
|
|
61
62
|
let t = e;
|
|
62
63
|
for (let i = 0; i < this.getLineCount(); i++) {
|
|
63
|
-
const
|
|
64
|
-
if (t <=
|
|
64
|
+
const n = this.getLine(i).length;
|
|
65
|
+
if (t <= n)
|
|
65
66
|
return { line: i, column: t };
|
|
66
|
-
t -=
|
|
67
|
+
t -= n + 1;
|
|
67
68
|
}
|
|
68
69
|
return {
|
|
69
70
|
line: this.getLineCount() - 1,
|
|
@@ -84,7 +85,7 @@ class V {
|
|
|
84
85
|
}
|
|
85
86
|
// Clone the model
|
|
86
87
|
clone() {
|
|
87
|
-
const e = new
|
|
88
|
+
const e = new K();
|
|
88
89
|
return e._lines = [...this._lines], e._version = this._version, e;
|
|
89
90
|
}
|
|
90
91
|
normalizeRange(e) {
|
|
@@ -97,7 +98,7 @@ class V {
|
|
|
97
98
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
class
|
|
101
|
+
class Y {
|
|
101
102
|
constructor(e) {
|
|
102
103
|
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
|
}
|
|
@@ -207,14 +208,14 @@ class Q {
|
|
|
207
208
|
if (this.updateGutterWidth(e), e === this.lastLineCount)
|
|
208
209
|
return;
|
|
209
210
|
this.lastLineCount = e;
|
|
210
|
-
const t = Math.max(e, 1), i = Array.from({ length: t }, (
|
|
211
|
-
this.lineNumbersContentElement.innerHTML = i.map((
|
|
211
|
+
const t = Math.max(e, 1), i = Array.from({ length: t }, (n, s) => s + 1);
|
|
212
|
+
this.lineNumbersContentElement.innerHTML = i.map((n) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px;">${n}</div>`).join("");
|
|
212
213
|
}
|
|
213
214
|
updateGutterWidth(e) {
|
|
214
|
-
const
|
|
215
|
-
|
|
215
|
+
const i = String(Math.max(e, 1)).length * this.gutterDigitWidth + this.gutterLineNumberPaddingLeft + this.gutterLineNumberPaddingRight, n = Math.ceil(
|
|
216
|
+
i + this.gutterFoldColumnGap + this.gutterFoldColumnWidth
|
|
216
217
|
);
|
|
217
|
-
|
|
218
|
+
n !== this.gutterWidth && (this.gutterWidth = n, this.lineNumbersElement.style.display !== "none" && (this.lineNumbersElement.style.width = `${this.gutterWidth}px`, this.lineNumbersElement.style.minWidth = `${this.gutterWidth}px`));
|
|
218
219
|
}
|
|
219
220
|
setDecorations(e, t) {
|
|
220
221
|
this.renderLineDecorations(e), this.renderGutterDecorations(t);
|
|
@@ -245,17 +246,17 @@ class Q {
|
|
|
245
246
|
// Set inner HTML (used for syntax highlighted content)
|
|
246
247
|
setHTML(e) {
|
|
247
248
|
this.clearHighlightOverlay(), this.setFoldPlaceholderSources(/* @__PURE__ */ new Map());
|
|
248
|
-
const t = /\n$/.test(e), i = /<|>/.test(e),
|
|
249
|
-
i &&
|
|
250
|
-
const
|
|
249
|
+
const t = /\n$/.test(e), i = /<|>/.test(e), n = /<span\b/i.test(e), s = /<[^>]+>/.test(e);
|
|
250
|
+
i && n ? this.contentElement.innerHTML = e : s && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
|
|
251
|
+
const o = (this.contentElement.textContent || "").split(`
|
|
251
252
|
`).length;
|
|
252
|
-
this.updateLineNumbers(
|
|
253
|
+
this.updateLineNumbers(o);
|
|
253
254
|
}
|
|
254
255
|
setHighlightHTML(e) {
|
|
255
256
|
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
|
|
257
|
+
const i = (this.contentElement.textContent || "").split(`
|
|
257
258
|
`).length;
|
|
258
|
-
this.updateLineNumbers(
|
|
259
|
+
this.updateLineNumbers(i);
|
|
259
260
|
}
|
|
260
261
|
setLineWrapping(e) {
|
|
261
262
|
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";
|
|
@@ -280,10 +281,10 @@ class Q {
|
|
|
280
281
|
}
|
|
281
282
|
// Set cursor position
|
|
282
283
|
setCursorPosition(e) {
|
|
283
|
-
const t = this.getText(), i = this.positionToTextOffset(e, t),
|
|
284
|
-
if (
|
|
284
|
+
const t = this.getText(), i = this.positionToTextOffset(e, t), n = window.getSelection(), s = this.createDomRangeFromOffsets(i);
|
|
285
|
+
if (s)
|
|
285
286
|
try {
|
|
286
|
-
|
|
287
|
+
n == null || n.removeAllRanges(), n == null || n.addRange(s), this.ensureCaretVisible();
|
|
287
288
|
} catch (r) {
|
|
288
289
|
console.warn("Could not set cursor position:", r);
|
|
289
290
|
}
|
|
@@ -292,7 +293,7 @@ class Q {
|
|
|
292
293
|
`[${this.trailingNewlineMarkerAttr}]`
|
|
293
294
|
), o = document.createRange();
|
|
294
295
|
try {
|
|
295
|
-
r && r.parentNode === this.contentElement ? o.setStartBefore(r) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0),
|
|
296
|
+
r && r.parentNode === this.contentElement ? o.setStartBefore(r) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0), n == null || n.removeAllRanges(), n == null || n.addRange(o), this.ensureCaretVisible();
|
|
296
297
|
} catch (l) {
|
|
297
298
|
console.warn("Could not set fallback cursor position:", l);
|
|
298
299
|
}
|
|
@@ -322,7 +323,7 @@ class Q {
|
|
|
322
323
|
const i = e.anchorNode && this.isNodeInsideContent(e.anchorNode) ? this.sourceOffsetFromBoundary(
|
|
323
324
|
e.anchorNode,
|
|
324
325
|
e.anchorOffset
|
|
325
|
-
) : void 0,
|
|
326
|
+
) : void 0, n = e.focusNode && this.isNodeInsideContent(e.focusNode) ? this.sourceOffsetFromBoundary(
|
|
326
327
|
e.focusNode,
|
|
327
328
|
e.focusOffset
|
|
328
329
|
) : void 0;
|
|
@@ -338,7 +339,7 @@ class Q {
|
|
|
338
339
|
t.endOffset
|
|
339
340
|
),
|
|
340
341
|
anchorOffset: i,
|
|
341
|
-
focusOffset:
|
|
342
|
+
focusOffset: n
|
|
342
343
|
};
|
|
343
344
|
}
|
|
344
345
|
getSelectionState() {
|
|
@@ -354,10 +355,10 @@ class Q {
|
|
|
354
355
|
isInEditor: !1,
|
|
355
356
|
isCollapsed: e.isCollapsed
|
|
356
357
|
};
|
|
357
|
-
const i = this.getText(),
|
|
358
|
+
const i = this.getText(), n = this.sourceOffsetFromBoundary(t.startContainer, t.startOffset), s = this.sourceOffsetFromBoundary(t.endContainer, t.endOffset), r = e.focusNode && this.isNodeInsideContent(e.focusNode) ? this.sourceOffsetFromBoundary(
|
|
358
359
|
e.focusNode,
|
|
359
360
|
e.focusOffset
|
|
360
|
-
) :
|
|
361
|
+
) : s, o = this.offsetToPositionInText(n, i), l = this.offsetToPositionInText(s, i), a = this.offsetToPositionInText(r, i);
|
|
361
362
|
return {
|
|
362
363
|
isInEditor: !0,
|
|
363
364
|
isCollapsed: e.isCollapsed,
|
|
@@ -377,12 +378,12 @@ class Q {
|
|
|
377
378
|
}
|
|
378
379
|
}
|
|
379
380
|
createDomRangeFromOffsets(e, t = e) {
|
|
380
|
-
const [i,
|
|
381
|
-
if (!
|
|
381
|
+
const [i, n] = e <= t ? [e, t] : [t, e], s = this.resolveOffsetToDomPoint(i), r = this.resolveOffsetToDomPoint(n);
|
|
382
|
+
if (!s || !r)
|
|
382
383
|
return null;
|
|
383
384
|
const o = document.createRange();
|
|
384
385
|
try {
|
|
385
|
-
return o.setStart(
|
|
386
|
+
return o.setStart(s.node, s.offset), o.setEnd(r.node, r.offset), o;
|
|
386
387
|
} catch (l) {
|
|
387
388
|
return null;
|
|
388
389
|
}
|
|
@@ -398,43 +399,43 @@ class Q {
|
|
|
398
399
|
const i = this.getDomRangeFromClientPoint(e, t);
|
|
399
400
|
if (!i || !this.isNodeInsideContent(i.startContainer))
|
|
400
401
|
return null;
|
|
401
|
-
const
|
|
402
|
+
const n = this.sourceOffsetFromBoundary(
|
|
402
403
|
i.startContainer,
|
|
403
404
|
i.startOffset
|
|
404
405
|
);
|
|
405
|
-
return this.offsetToPositionInText(
|
|
406
|
+
return this.offsetToPositionInText(n, this.getText());
|
|
406
407
|
}
|
|
407
408
|
setSelectionOffsets(e, t = e) {
|
|
408
409
|
const i = this.createDomRangeFromOffsets(e, t);
|
|
409
410
|
if (i)
|
|
410
411
|
try {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
} catch (
|
|
414
|
-
console.warn("Could not set selection offsets:",
|
|
412
|
+
const n = window.getSelection();
|
|
413
|
+
n == null || n.removeAllRanges(), n == null || n.addRange(i), this.ensureCaretVisible();
|
|
414
|
+
} catch (n) {
|
|
415
|
+
console.warn("Could not set selection offsets:", n);
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
418
|
setSelectionBoundaryOffsets(e, t) {
|
|
418
|
-
const i = this.resolveOffsetToDomPoint(e),
|
|
419
|
-
if (!i || !
|
|
419
|
+
const i = this.resolveOffsetToDomPoint(e), n = this.resolveOffsetToDomPoint(t), s = window.getSelection();
|
|
420
|
+
if (!i || !n || !s) {
|
|
420
421
|
this.setSelectionOffsets(e, t);
|
|
421
422
|
return;
|
|
422
423
|
}
|
|
423
424
|
try {
|
|
424
|
-
if (
|
|
425
|
+
if (s.removeAllRanges(), e === t) {
|
|
425
426
|
const o = document.createRange();
|
|
426
|
-
o.setStart(i.node, i.offset), o.collapse(!0),
|
|
427
|
+
o.setStart(i.node, i.offset), o.collapse(!0), s.addRange(o), this.ensureCaretVisible();
|
|
427
428
|
return;
|
|
428
429
|
}
|
|
429
|
-
if (typeof
|
|
430
|
+
if (typeof s.extend == "function") {
|
|
430
431
|
const o = document.createRange();
|
|
431
|
-
o.setStart(i.node, i.offset), o.collapse(!0),
|
|
432
|
+
o.setStart(i.node, i.offset), o.collapse(!0), s.addRange(o), s.extend(n.node, n.offset), this.ensureCaretVisible();
|
|
432
433
|
return;
|
|
433
434
|
}
|
|
434
435
|
const r = this.createDomRangeFromOffsets(e, t);
|
|
435
436
|
if (!r)
|
|
436
437
|
return;
|
|
437
|
-
|
|
438
|
+
s.addRange(r), this.ensureCaretVisible();
|
|
438
439
|
} catch (r) {
|
|
439
440
|
console.warn("Could not set selection boundary offsets:", r), this.setSelectionOffsets(e, t);
|
|
440
441
|
}
|
|
@@ -459,8 +460,8 @@ class Q {
|
|
|
459
460
|
}
|
|
460
461
|
// Scroll to position
|
|
461
462
|
scrollToPosition(e) {
|
|
462
|
-
const
|
|
463
|
-
this.editorContainer.scrollTop = Math.max(0,
|
|
463
|
+
const n = Math.max(0, Math.floor(e.line) || 0) * this.lineHeight - this.editorContainer.clientHeight / 2 + this.lineHeight / 2;
|
|
464
|
+
this.editorContainer.scrollTop = Math.max(0, n);
|
|
464
465
|
}
|
|
465
466
|
// Get scroll position
|
|
466
467
|
getScrollTop() {
|
|
@@ -491,39 +492,39 @@ class Q {
|
|
|
491
492
|
if (!e || e.rangeCount === 0) return;
|
|
492
493
|
const t = this.getCaretClientRect(e);
|
|
493
494
|
if (!t) return;
|
|
494
|
-
const i = this.editorContainer.getBoundingClientRect(),
|
|
495
|
-
t.bottom > i.bottom -
|
|
495
|
+
const i = this.editorContainer.getBoundingClientRect(), n = 12;
|
|
496
|
+
t.bottom > i.bottom - n ? this.editorContainer.scrollTop += t.bottom - (i.bottom - n) : t.top < i.top + n && (this.editorContainer.scrollTop -= i.top + n - t.top), t.right > i.right - n ? this.editorContainer.scrollLeft += t.right - (i.right - n) : t.left < i.left + n && (this.editorContainer.scrollLeft -= i.left + n - t.left);
|
|
496
497
|
}
|
|
497
498
|
// Destroy the view
|
|
498
499
|
destroy() {
|
|
499
500
|
this.clearDecorations(), this.container && (this.container.innerHTML = ""), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
500
501
|
}
|
|
501
502
|
resolveOffsetToDomPoint(e) {
|
|
502
|
-
var
|
|
503
|
+
var s;
|
|
503
504
|
const t = Math.max(0, e);
|
|
504
505
|
let i = 0;
|
|
505
|
-
const
|
|
506
|
-
for (let r = 0; r <
|
|
507
|
-
const o =
|
|
506
|
+
const n = Array.from(this.contentElement.childNodes);
|
|
507
|
+
for (let r = 0; r < n.length; r++) {
|
|
508
|
+
const o = n[r];
|
|
508
509
|
if (o instanceof Text) {
|
|
509
510
|
const l = o.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
|
|
510
511
|
if (i + h >= t) {
|
|
511
|
-
const
|
|
512
|
-
return { node: o, offset:
|
|
512
|
+
const c = Math.max(0, t - i), d = (s = a[c]) != null ? s : l.length;
|
|
513
|
+
return { node: o, offset: d };
|
|
513
514
|
}
|
|
514
515
|
i += h;
|
|
515
516
|
continue;
|
|
516
517
|
}
|
|
517
518
|
if (o instanceof HTMLElement && !o.hasAttribute(this.trailingNewlineMarkerAttr) && o.hasAttribute(this.foldPlaceholderAttr)) {
|
|
518
|
-
const
|
|
519
|
-
if (i +
|
|
520
|
-
const
|
|
519
|
+
const a = this.getFoldPlaceholderSource(o).length;
|
|
520
|
+
if (i + a >= t) {
|
|
521
|
+
const h = t - i;
|
|
521
522
|
return {
|
|
522
523
|
node: this.contentElement,
|
|
523
|
-
offset:
|
|
524
|
+
offset: h <= a / 2 ? r : r + 1
|
|
524
525
|
};
|
|
525
526
|
}
|
|
526
|
-
i +=
|
|
527
|
+
i += a;
|
|
527
528
|
}
|
|
528
529
|
}
|
|
529
530
|
return {
|
|
@@ -534,14 +535,14 @@ class Q {
|
|
|
534
535
|
getDomRangeFromClientPoint(e, t) {
|
|
535
536
|
const i = document;
|
|
536
537
|
if (typeof i.caretPositionFromPoint == "function") {
|
|
537
|
-
const
|
|
538
|
+
const n = i.caretPositionFromPoint(
|
|
538
539
|
e,
|
|
539
540
|
t
|
|
540
541
|
);
|
|
541
|
-
if (
|
|
542
|
-
const
|
|
542
|
+
if (n != null && n.offsetNode) {
|
|
543
|
+
const s = document.createRange();
|
|
543
544
|
try {
|
|
544
|
-
return
|
|
545
|
+
return s.setStart(n.offsetNode, n.offset), s.collapse(!0), s;
|
|
545
546
|
} catch (r) {
|
|
546
547
|
return null;
|
|
547
548
|
}
|
|
@@ -552,9 +553,9 @@ class Q {
|
|
|
552
553
|
buildVisibleToDomMap(e) {
|
|
553
554
|
const t = [0];
|
|
554
555
|
let i = 0;
|
|
555
|
-
for (let
|
|
556
|
-
const
|
|
557
|
-
this.virtualMarkerRegex.test(
|
|
556
|
+
for (let n = 0; n < e.length; n++) {
|
|
557
|
+
const s = e[n];
|
|
558
|
+
this.virtualMarkerRegex.test(s) || (i += 1, t[i] = n + 1);
|
|
558
559
|
}
|
|
559
560
|
return t;
|
|
560
561
|
}
|
|
@@ -568,23 +569,23 @@ class Q {
|
|
|
568
569
|
const i = this.getUsableRangeRect(t);
|
|
569
570
|
if (i)
|
|
570
571
|
return i;
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
573
|
-
const h = (l = (o =
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
578
|
-
return
|
|
572
|
+
const n = e.focusNode, s = e.focusOffset;
|
|
573
|
+
if (n instanceof Text) {
|
|
574
|
+
const h = (l = (o = n.textContent) == null ? void 0 : o.length) != null ? l : 0, c = document.createRange();
|
|
575
|
+
if (s < h) {
|
|
576
|
+
c.setStart(n, s), c.setEnd(n, Math.min(h, s + 1));
|
|
577
|
+
const d = this.getUsableRangeRect(c);
|
|
578
|
+
if (d)
|
|
579
|
+
return d;
|
|
579
580
|
}
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
if (
|
|
584
|
-
return
|
|
581
|
+
if (s > 0) {
|
|
582
|
+
c.setStart(n, s - 1), c.setEnd(n, s);
|
|
583
|
+
const d = this.getUsableRangeRect(c);
|
|
584
|
+
if (d)
|
|
585
|
+
return d;
|
|
585
586
|
}
|
|
586
587
|
}
|
|
587
|
-
const r =
|
|
588
|
+
const r = n instanceof Element ? n : (a = n == null ? void 0 : n.parentElement) != null ? a : null;
|
|
588
589
|
if (r && r !== this.contentElement && r !== this.editorContainer && this.contentElement.contains(r)) {
|
|
589
590
|
const h = r.getBoundingClientRect();
|
|
590
591
|
if (this.isUsableRect(h))
|
|
@@ -594,9 +595,9 @@ class Q {
|
|
|
594
595
|
}
|
|
595
596
|
getUsableRangeRect(e) {
|
|
596
597
|
const t = Array.from(e.getClientRects());
|
|
597
|
-
for (let
|
|
598
|
-
if (this.isUsableRect(t[
|
|
599
|
-
return t[
|
|
598
|
+
for (let n = 0; n < t.length; n++)
|
|
599
|
+
if (this.isUsableRect(t[n]))
|
|
600
|
+
return t[n];
|
|
600
601
|
const i = e.getBoundingClientRect();
|
|
601
602
|
return this.isUsableRect(i) ? i : null;
|
|
602
603
|
}
|
|
@@ -629,14 +630,14 @@ class Q {
|
|
|
629
630
|
}
|
|
630
631
|
sourceOffsetFromBoundary(e, t) {
|
|
631
632
|
let i = 0;
|
|
632
|
-
const
|
|
633
|
+
const n = Array.from(this.contentElement.childNodes);
|
|
633
634
|
if (e === this.contentElement) {
|
|
634
|
-
for (let
|
|
635
|
-
i += this.getSourceLength(s
|
|
635
|
+
for (let s = 0; s < Math.min(t, n.length); s++)
|
|
636
|
+
i += this.getSourceLength(n[s]);
|
|
636
637
|
return i;
|
|
637
638
|
}
|
|
638
|
-
for (let
|
|
639
|
-
const r = s
|
|
639
|
+
for (let s = 0; s < n.length; s++) {
|
|
640
|
+
const r = n[s];
|
|
640
641
|
if (r === e) {
|
|
641
642
|
if (r instanceof Text)
|
|
642
643
|
return i + this.stripVirtualMarkers((r.textContent || "").slice(0, t)).length;
|
|
@@ -664,40 +665,40 @@ class Q {
|
|
|
664
665
|
return i;
|
|
665
666
|
}
|
|
666
667
|
sourceOffsetWithinNode(e, t, i) {
|
|
667
|
-
let
|
|
668
|
-
const
|
|
668
|
+
let n = 0;
|
|
669
|
+
const s = Array.from(e.childNodes);
|
|
669
670
|
if (t === e) {
|
|
670
|
-
for (let r = 0; r < Math.min(i,
|
|
671
|
-
|
|
672
|
-
return
|
|
671
|
+
for (let r = 0; r < Math.min(i, s.length); r++)
|
|
672
|
+
n += this.getSourceLength(s[r]);
|
|
673
|
+
return n;
|
|
673
674
|
}
|
|
674
|
-
for (let r = 0; r <
|
|
675
|
-
const o =
|
|
675
|
+
for (let r = 0; r < s.length; r++) {
|
|
676
|
+
const o = s[r];
|
|
676
677
|
if (o === t) {
|
|
677
678
|
if (o instanceof Text)
|
|
678
|
-
return
|
|
679
|
+
return n + this.stripVirtualMarkers((o.textContent || "").slice(0, i)).length;
|
|
679
680
|
if (o instanceof HTMLElement) {
|
|
680
681
|
if (o.hasAttribute(this.foldPlaceholderAttr))
|
|
681
|
-
return
|
|
682
|
+
return n + this.getFoldPlaceholderBoundaryOffset(
|
|
682
683
|
o,
|
|
683
684
|
o,
|
|
684
685
|
i
|
|
685
686
|
);
|
|
686
687
|
const l = Array.from(o.childNodes);
|
|
687
688
|
for (let a = 0; a < Math.min(i, l.length); a++)
|
|
688
|
-
|
|
689
|
-
return
|
|
689
|
+
n += this.getSourceLength(l[a]);
|
|
690
|
+
return n;
|
|
690
691
|
}
|
|
691
692
|
}
|
|
692
693
|
if (o instanceof HTMLElement && o.contains(t))
|
|
693
|
-
return o.hasAttribute(this.foldPlaceholderAttr) ?
|
|
694
|
+
return o.hasAttribute(this.foldPlaceholderAttr) ? n + this.getFoldPlaceholderBoundaryOffset(
|
|
694
695
|
o,
|
|
695
696
|
t,
|
|
696
697
|
i
|
|
697
|
-
) :
|
|
698
|
-
|
|
698
|
+
) : n + this.sourceOffsetWithinNode(o, t, i);
|
|
699
|
+
n += this.getSourceLength(o);
|
|
699
700
|
}
|
|
700
|
-
return
|
|
701
|
+
return n;
|
|
701
702
|
}
|
|
702
703
|
getSourceLength(e) {
|
|
703
704
|
if (e instanceof Text)
|
|
@@ -712,44 +713,44 @@ class Q {
|
|
|
712
713
|
}), t;
|
|
713
714
|
}
|
|
714
715
|
renderLineDecorations(e) {
|
|
715
|
-
const t = [...e].filter((
|
|
716
|
-
(
|
|
716
|
+
const t = [...e].filter((s) => Number.isFinite(s.line) && s.line >= 0).sort((s, r) => s.line - r.line || s.id.localeCompare(r.id)), i = t.map(
|
|
717
|
+
(s) => `${s.id}:${s.line}:${s.className || ""}:${this.serializeStyleObject(s.style)}`
|
|
717
718
|
).join("|");
|
|
718
719
|
if (i === this.lastLineDecorationSnapshot || (this.lineDecorationsElement.innerHTML = "", this.lastLineDecorationSnapshot = i, t.length === 0))
|
|
719
720
|
return;
|
|
720
|
-
const
|
|
721
|
-
for (const
|
|
721
|
+
const n = document.createDocumentFragment();
|
|
722
|
+
for (const s of t) {
|
|
722
723
|
const r = document.createElement("div");
|
|
723
724
|
r.className = this.joinClassNames(
|
|
724
725
|
"lce-decoration lce-decoration-line",
|
|
725
|
-
|
|
726
|
-
), r.setAttribute("data-decoration-id",
|
|
726
|
+
s.className
|
|
727
|
+
), r.setAttribute("data-decoration-id", s.id), r.setAttribute("data-decoration-line", String(s.line)), r.style.cssText = this.joinStyleFragments([
|
|
727
728
|
"position: absolute",
|
|
728
|
-
`top: ${
|
|
729
|
+
`top: ${s.line * this.lineHeight}px`,
|
|
729
730
|
`height: ${this.lineHeight}px`,
|
|
730
731
|
"left: 12px",
|
|
731
732
|
"right: 12px",
|
|
732
733
|
"border-radius: 3px",
|
|
733
|
-
this.serializeStyleObject(
|
|
734
|
-
]),
|
|
734
|
+
this.serializeStyleObject(s.style)
|
|
735
|
+
]), n.appendChild(r);
|
|
735
736
|
}
|
|
736
|
-
this.lineDecorationsElement.appendChild(
|
|
737
|
+
this.lineDecorationsElement.appendChild(n);
|
|
737
738
|
}
|
|
738
739
|
renderGutterDecorations(e) {
|
|
739
|
-
const t = [...e].filter((
|
|
740
|
-
(
|
|
740
|
+
const t = [...e].filter((s) => Number.isFinite(s.line) && s.line >= 0).sort((s, r) => s.line - r.line || s.id.localeCompare(r.id)), i = t.map(
|
|
741
|
+
(s) => `${s.id}:${s.line}:${s.label || ""}:${s.title || ""}:${s.className || ""}:${this.serializeStyleObject(s.style)}`
|
|
741
742
|
).join("|");
|
|
742
743
|
if (i === this.lastGutterDecorationSnapshot || (this.gutterDecorationsElement.innerHTML = "", this.lastGutterDecorationSnapshot = i, t.length === 0))
|
|
743
744
|
return;
|
|
744
|
-
const
|
|
745
|
-
for (const
|
|
745
|
+
const n = document.createDocumentFragment();
|
|
746
|
+
for (const s of t) {
|
|
746
747
|
const r = document.createElement("div");
|
|
747
748
|
r.className = this.joinClassNames(
|
|
748
749
|
"lce-decoration lce-decoration-gutter",
|
|
749
|
-
|
|
750
|
-
), r.setAttribute("data-decoration-id",
|
|
750
|
+
s.className
|
|
751
|
+
), r.setAttribute("data-decoration-id", s.id), r.setAttribute("data-decoration-line", String(s.line)), r.style.cssText = this.joinStyleFragments([
|
|
751
752
|
"position: absolute",
|
|
752
|
-
`top: ${
|
|
753
|
+
`top: ${s.line * this.lineHeight}px`,
|
|
753
754
|
`height: ${this.lineHeight}px`,
|
|
754
755
|
"left: 0",
|
|
755
756
|
"right: 0",
|
|
@@ -758,10 +759,10 @@ class Q {
|
|
|
758
759
|
"justify-content: flex-end",
|
|
759
760
|
"padding-right: 4px",
|
|
760
761
|
"box-sizing: border-box",
|
|
761
|
-
this.serializeStyleObject(
|
|
762
|
-
]),
|
|
762
|
+
this.serializeStyleObject(s.style)
|
|
763
|
+
]), s.title && (r.title = s.title), r.textContent = s.label || "", n.appendChild(r);
|
|
763
764
|
}
|
|
764
|
-
this.gutterDecorationsElement.appendChild(
|
|
765
|
+
this.gutterDecorationsElement.appendChild(n);
|
|
765
766
|
}
|
|
766
767
|
joinClassNames(...e) {
|
|
767
768
|
return e.filter(Boolean).join(" ").trim();
|
|
@@ -789,14 +790,14 @@ class Q {
|
|
|
789
790
|
positionToTextOffset(e, t) {
|
|
790
791
|
var o;
|
|
791
792
|
const i = t.split(`
|
|
792
|
-
`),
|
|
793
|
+
`), n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(
|
|
793
794
|
0,
|
|
794
|
-
Math.min(e.column, ((o = i[
|
|
795
|
+
Math.min(e.column, ((o = i[n]) == null ? void 0 : o.length) || 0)
|
|
795
796
|
);
|
|
796
797
|
let r = 0;
|
|
797
|
-
for (let l = 0; l <
|
|
798
|
+
for (let l = 0; l < n; l++)
|
|
798
799
|
r += i[l].length + 1;
|
|
799
|
-
return r +
|
|
800
|
+
return r + s;
|
|
800
801
|
}
|
|
801
802
|
getFoldPlaceholderSource(e) {
|
|
802
803
|
const t = e.getAttribute(this.foldPlaceholderAttr), i = this.getFoldPlaceholderSources();
|
|
@@ -806,24 +807,24 @@ class Q {
|
|
|
806
807
|
return this.contentElement.__lceFoldPlaceholderSources || /* @__PURE__ */ new Map();
|
|
807
808
|
}
|
|
808
809
|
getFoldPlaceholderBoundaryOffset(e, t, i) {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
810
|
+
const n = this.getFoldPlaceholderSource(e).length, s = this.stripVirtualMarkers(e.textContent || "").length;
|
|
811
|
+
if (n === 0 || s === 0)
|
|
811
812
|
return 0;
|
|
812
813
|
const r = document.createRange();
|
|
813
814
|
r.selectNodeContents(e);
|
|
814
815
|
try {
|
|
815
816
|
r.setEnd(t, i);
|
|
816
|
-
} catch (
|
|
817
|
+
} catch (l) {
|
|
817
818
|
return 0;
|
|
818
819
|
}
|
|
819
|
-
return this.stripVirtualMarkers(r.toString()).length <=
|
|
820
|
+
return this.stripVirtualMarkers(r.toString()).length <= s / 2 ? 0 : n;
|
|
820
821
|
}
|
|
821
822
|
setFoldPlaceholderSources(e) {
|
|
822
823
|
this.contentElement.__lceFoldPlaceholderSources = e;
|
|
823
824
|
}
|
|
824
825
|
}
|
|
825
826
|
let X = 0;
|
|
826
|
-
const
|
|
827
|
+
const w = class w {
|
|
827
828
|
constructor(e, t = {}) {
|
|
828
829
|
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.lastKnownCursor = { line: 0, column: 0 }, this.editorInstanceId = ++X, this.decorationHighlightStyleId = `editora-decoration-style-${this.editorInstanceId}`, this.decorationHighlightLimit = 1e3, this.decorationLayers = /* @__PURE__ */ new Map(), this.inlineDecorationHighlightNames = /* @__PURE__ */ new Set(), this.decorationRenderRaf = null, this.decorationMutationObserver = null, this.hasCustomDecorationHighlightSupport = !1, this.lastProgrammaticClipboardInsertAt = 0, this.config = {
|
|
829
830
|
value: "",
|
|
@@ -833,7 +834,7 @@ const W = class O {
|
|
|
833
834
|
lineWrapping: !1,
|
|
834
835
|
lineNumbers: !0,
|
|
835
836
|
...t
|
|
836
|
-
}, this.textModel = new
|
|
837
|
+
}, this.textModel = new K(this.config.value), this.view = new Y(e), this.view.setTabSize(this.config.tabSize || 2), this.view.setLineWrapping(!!this.config.lineWrapping), this.view.setLineNumbersVisible(this.config.lineNumbers !== !1), this.hasCustomDecorationHighlightSupport = this.detectCustomHighlightSupport(), this.observeDecorationRelevantMutations(), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
|
|
837
838
|
}
|
|
838
839
|
// Public accessors for extensions
|
|
839
840
|
getTextModel() {
|
|
@@ -847,7 +848,9 @@ const W = class O {
|
|
|
847
848
|
}
|
|
848
849
|
// Register built-in editor commands like undo/redo/insertTab
|
|
849
850
|
registerBuiltInCommands() {
|
|
850
|
-
this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("
|
|
851
|
+
this.registerCommand("undo", () => this.undo()), this.registerCommand("redo", () => this.redo()), this.registerCommand("insertTab", () => this.insertTab()), this.registerCommand("outdent", () => {
|
|
852
|
+
this.shiftSelectedLines(!0);
|
|
853
|
+
}), this.registerCommand("save", () => {
|
|
851
854
|
this.emit("save");
|
|
852
855
|
});
|
|
853
856
|
}
|
|
@@ -864,23 +867,27 @@ const W = class O {
|
|
|
864
867
|
return;
|
|
865
868
|
}
|
|
866
869
|
if (t.inputType === "insertFromPaste" || t.inputType === "insertFromPasteAsQuotation" || t.inputType === "insertFromDrop") {
|
|
867
|
-
const i = t.dataTransfer,
|
|
868
|
-
if (
|
|
870
|
+
const i = t.dataTransfer, n = this.getPlainTextFromDataTransfer(i);
|
|
871
|
+
if (n.length === 0 || (t.preventDefault(), this.pendingInputSnapshot = void 0, Date.now() - this.lastProgrammaticClipboardInsertAt < 80))
|
|
869
872
|
return;
|
|
870
|
-
this.insertClipboardText(
|
|
873
|
+
this.insertClipboardText(n);
|
|
871
874
|
return;
|
|
872
875
|
}
|
|
873
876
|
if (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") {
|
|
874
877
|
t.preventDefault(), this.pendingInputSnapshot = void 0, this.insertNewLine();
|
|
875
878
|
return;
|
|
876
879
|
}
|
|
877
|
-
if (t.
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
880
|
+
if (!t.isComposing) {
|
|
881
|
+
const i = w.deletionUnit(t.inputType, "Backward");
|
|
882
|
+
if (i) {
|
|
883
|
+
t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteBackward(i);
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const n = w.deletionUnit(t.inputType, "Forward");
|
|
887
|
+
if (n) {
|
|
888
|
+
t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteForward(n);
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
884
891
|
}
|
|
885
892
|
if (t.inputType === "deleteByCut") {
|
|
886
893
|
t.preventDefault(), this.pendingInputSnapshot = void 0, this.deleteSelection();
|
|
@@ -903,41 +910,42 @@ const W = class O {
|
|
|
903
910
|
const i = this.getPlainTextFromDataTransfer(t.clipboardData);
|
|
904
911
|
i.length !== 0 && (t.preventDefault(), this.insertClipboardText(i));
|
|
905
912
|
}), e.addEventListener("input", () => {
|
|
906
|
-
var
|
|
913
|
+
var n;
|
|
907
914
|
const t = this.view.getText(), i = this.textModel.getText();
|
|
908
915
|
t !== i ? (this.suppressHistory || this.pushUndoSnapshot(
|
|
909
|
-
(
|
|
916
|
+
(n = this.pendingInputSnapshot) != null ? n : this.captureHistorySnapshot(i)
|
|
910
917
|
), this.pendingInputSnapshot = void 0, this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.hasRenderedFoldPlaceholders() ? this.clearPendingHighlightRender() : (this.clearPendingHighlightRender(), this.highlightTimeout = setTimeout(() => {
|
|
911
|
-
const
|
|
912
|
-
|
|
918
|
+
const s = this.view.getText();
|
|
919
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
913
920
|
}, 300)), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }])) : this.pendingInputSnapshot = void 0;
|
|
914
921
|
}), this.documentSelectionChangeHandler = () => {
|
|
915
|
-
var
|
|
922
|
+
var n, s, r;
|
|
916
923
|
const t = this.syncSelectionCacheFromView();
|
|
917
924
|
if (!t.isInEditor)
|
|
918
925
|
return;
|
|
919
|
-
const i = (
|
|
926
|
+
const i = (n = t.cursor) != null ? n : this.lastKnownCursor;
|
|
920
927
|
this.emit("cursor", {
|
|
921
928
|
position: i,
|
|
922
|
-
anchor: (r = (
|
|
929
|
+
anchor: (r = (s = t.range) == null ? void 0 : s.start) != null ? r : i
|
|
923
930
|
}), this.emit("selection", t.isCollapsed ? void 0 : t.range);
|
|
924
931
|
}, document.addEventListener("selectionchange", this.documentSelectionChangeHandler), e.addEventListener("keydown", (t) => {
|
|
925
932
|
this.emit("keydown", t);
|
|
926
933
|
const i = Array.from(this.extensions.values()).reverse();
|
|
927
|
-
for (const
|
|
928
|
-
if (
|
|
934
|
+
for (const r of i)
|
|
935
|
+
if (r.onKeyDown && r.onKeyDown(t) === !1) {
|
|
929
936
|
t.preventDefault(), t.stopPropagation();
|
|
930
937
|
return;
|
|
931
938
|
}
|
|
932
939
|
if (t.key === "Tab" && !this.config.readOnly) {
|
|
933
|
-
this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
940
|
+
t.shiftKey ? this.shiftSelectedLines(!0) : this.insertTab(), t.preventDefault(), t.stopPropagation();
|
|
934
941
|
return;
|
|
935
942
|
}
|
|
936
|
-
|
|
943
|
+
const n = t.altKey || t.ctrlKey || t.metaKey, s = t.isComposing || t.keyCode === 229;
|
|
944
|
+
if (t.key === "Backspace" && !this.config.readOnly && !n && !s) {
|
|
937
945
|
this.deleteBackward(), t.preventDefault(), t.stopPropagation();
|
|
938
946
|
return;
|
|
939
947
|
}
|
|
940
|
-
if (t.key === "Delete" && !this.config.readOnly) {
|
|
948
|
+
if (t.key === "Delete" && !this.config.readOnly && !n && !s) {
|
|
941
949
|
this.deleteForward(), t.preventDefault(), t.stopPropagation();
|
|
942
950
|
return;
|
|
943
951
|
}
|
|
@@ -948,16 +956,16 @@ const W = class O {
|
|
|
948
956
|
}), e.addEventListener("mousedown", (t) => {
|
|
949
957
|
this.emit("mousedown", t);
|
|
950
958
|
const i = Array.from(this.extensions.values()).reverse();
|
|
951
|
-
for (const
|
|
952
|
-
if (
|
|
959
|
+
for (const n of i)
|
|
960
|
+
if (n.onMouseDown && n.onMouseDown(t) === !1) {
|
|
953
961
|
t.preventDefault(), t.stopPropagation();
|
|
954
962
|
return;
|
|
955
963
|
}
|
|
956
964
|
}), e.addEventListener("contextmenu", (t) => {
|
|
957
965
|
this.emit("contextmenu", t);
|
|
958
966
|
const i = Array.from(this.extensions.values()).reverse();
|
|
959
|
-
for (const
|
|
960
|
-
if (
|
|
967
|
+
for (const n of i)
|
|
968
|
+
if (n.onContextMenu && n.onContextMenu(t) === !1) {
|
|
961
969
|
t.preventDefault(), t.stopPropagation();
|
|
962
970
|
return;
|
|
963
971
|
}
|
|
@@ -985,7 +993,7 @@ const W = class O {
|
|
|
985
993
|
// Emit events to listeners
|
|
986
994
|
emit(e, ...t) {
|
|
987
995
|
const i = this.eventListeners.get(e);
|
|
988
|
-
i && i.forEach((
|
|
996
|
+
i && i.forEach((n) => n(...t));
|
|
989
997
|
}
|
|
990
998
|
// State management
|
|
991
999
|
getValue() {
|
|
@@ -1006,16 +1014,16 @@ const W = class O {
|
|
|
1006
1014
|
}
|
|
1007
1015
|
// Cursor & Selection
|
|
1008
1016
|
getCursor() {
|
|
1009
|
-
var i,
|
|
1017
|
+
var i, n, s;
|
|
1010
1018
|
const e = this.syncSelectionCacheFromView(), t = (i = e.cursor) != null ? i : this.lastKnownCursor;
|
|
1011
1019
|
return {
|
|
1012
1020
|
position: t,
|
|
1013
|
-
anchor: (
|
|
1021
|
+
anchor: (s = (n = e.range) == null ? void 0 : n.start) != null ? s : t
|
|
1014
1022
|
};
|
|
1015
1023
|
}
|
|
1016
1024
|
setCursor(e) {
|
|
1017
|
-
const t = this.textModel.getText(), i = this.clampPositionToText(e, t),
|
|
1018
|
-
this.lastKnownCursor = i, this.lastKnownSelection = void 0, this.view.setSelectionOffsets(
|
|
1025
|
+
const t = this.textModel.getText(), i = this.clampPositionToText(e, t), n = this.positionToOffsetInText(i, t);
|
|
1026
|
+
this.lastKnownCursor = i, this.lastKnownSelection = void 0, this.view.setSelectionOffsets(n), this.emit("cursor", this.getCursor());
|
|
1019
1027
|
}
|
|
1020
1028
|
getSelection() {
|
|
1021
1029
|
const e = this.syncSelectionCacheFromView();
|
|
@@ -1026,8 +1034,8 @@ const W = class O {
|
|
|
1026
1034
|
const t = this.textModel.getText(), i = this.normalizeRange({
|
|
1027
1035
|
start: this.clampPositionToText(e.start, t),
|
|
1028
1036
|
end: this.clampPositionToText(e.end, t)
|
|
1029
|
-
}),
|
|
1030
|
-
this.lastKnownSelection = i, this.lastKnownCursor = i.end, this.view.setSelectionOffsets(
|
|
1037
|
+
}), n = this.positionToOffsetInText(i.start, t), s = this.positionToOffsetInText(i.end, t);
|
|
1038
|
+
this.lastKnownSelection = i, this.lastKnownCursor = i.end, this.view.setSelectionOffsets(n, s), this.emit("selection", i);
|
|
1031
1039
|
}
|
|
1032
1040
|
// Configuration
|
|
1033
1041
|
setTheme(e) {
|
|
@@ -1044,8 +1052,8 @@ const W = class O {
|
|
|
1044
1052
|
if (i && typeof i.setTheme == "function")
|
|
1045
1053
|
try {
|
|
1046
1054
|
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
1047
|
-
} catch (
|
|
1048
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
1055
|
+
} catch (n) {
|
|
1056
|
+
console.warn("Error applying theme to syntax-highlighting extension", n);
|
|
1049
1057
|
}
|
|
1050
1058
|
}
|
|
1051
1059
|
setReadOnly(e) {
|
|
@@ -1079,7 +1087,7 @@ const W = class O {
|
|
|
1079
1087
|
}
|
|
1080
1088
|
this.decorationLayers.set(
|
|
1081
1089
|
i,
|
|
1082
|
-
t.map((
|
|
1090
|
+
t.map((n) => this.cloneDecoration(n))
|
|
1083
1091
|
), this.scheduleDecorationRender();
|
|
1084
1092
|
}
|
|
1085
1093
|
clearDecorations(e) {
|
|
@@ -1093,7 +1101,7 @@ const W = class O {
|
|
|
1093
1101
|
const t = [];
|
|
1094
1102
|
for (const i of this.decorationLayers.values())
|
|
1095
1103
|
t.push(
|
|
1096
|
-
...i.map((
|
|
1104
|
+
...i.map((n) => this.cloneDecoration(n))
|
|
1097
1105
|
);
|
|
1098
1106
|
return t;
|
|
1099
1107
|
}
|
|
@@ -1107,68 +1115,68 @@ const W = class O {
|
|
|
1107
1115
|
wholeWord: !1,
|
|
1108
1116
|
regex: !1,
|
|
1109
1117
|
...t
|
|
1110
|
-
},
|
|
1118
|
+
}, n = [], s = this.textModel.getText(), { normalizedText: r, normalizedToRawOffsets: o } = this.buildSearchTextAndOffsetMap(s), l = i.caseSensitive ? r : r.toLowerCase(), a = i.caseSensitive ? e : e.toLowerCase();
|
|
1111
1119
|
if (i.regex) {
|
|
1112
|
-
let
|
|
1120
|
+
let c;
|
|
1113
1121
|
try {
|
|
1114
|
-
|
|
1115
|
-
} catch (
|
|
1122
|
+
c = new RegExp(e, i.caseSensitive ? "g" : "gi");
|
|
1123
|
+
} catch (f) {
|
|
1116
1124
|
return [];
|
|
1117
1125
|
}
|
|
1118
|
-
let
|
|
1119
|
-
for (; (
|
|
1120
|
-
const
|
|
1121
|
-
if (
|
|
1122
|
-
|
|
1126
|
+
let d;
|
|
1127
|
+
for (; (d = c.exec(r)) !== null; ) {
|
|
1128
|
+
const f = (h = d[0]) != null ? h : "";
|
|
1129
|
+
if (f.length === 0) {
|
|
1130
|
+
c.lastIndex = d.index + 1;
|
|
1123
1131
|
continue;
|
|
1124
1132
|
}
|
|
1125
|
-
const
|
|
1126
|
-
i.wholeWord && !this.isWholeWordBoundary(r,
|
|
1127
|
-
|
|
1133
|
+
const u = d.index, g = d.index + f.length;
|
|
1134
|
+
i.wholeWord && !this.isWholeWordBoundary(r, u, g) || this.pushSearchResultFromOffsets(
|
|
1135
|
+
n,
|
|
1136
|
+
u,
|
|
1128
1137
|
g,
|
|
1129
|
-
f,
|
|
1130
1138
|
r,
|
|
1131
1139
|
o
|
|
1132
1140
|
);
|
|
1133
1141
|
}
|
|
1134
1142
|
} else {
|
|
1135
|
-
let
|
|
1136
|
-
for (;
|
|
1137
|
-
const
|
|
1138
|
-
!i.wholeWord || this.isWholeWordBoundary(r,
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1143
|
+
let c = 0, d = l.indexOf(a, c);
|
|
1144
|
+
for (; d !== -1; ) {
|
|
1145
|
+
const f = d + a.length;
|
|
1146
|
+
!i.wholeWord || this.isWholeWordBoundary(r, d, f) ? (this.pushSearchResultFromOffsets(
|
|
1147
|
+
n,
|
|
1148
|
+
d,
|
|
1149
|
+
f,
|
|
1142
1150
|
r,
|
|
1143
1151
|
o
|
|
1144
|
-
),
|
|
1152
|
+
), c = f) : c = d + 1, d = l.indexOf(a, c);
|
|
1145
1153
|
}
|
|
1146
1154
|
}
|
|
1147
|
-
return
|
|
1155
|
+
return n;
|
|
1148
1156
|
}
|
|
1149
|
-
pushSearchResultFromOffsets(e, t, i,
|
|
1150
|
-
var h,
|
|
1151
|
-
const r = (h =
|
|
1157
|
+
pushSearchResultFromOffsets(e, t, i, n, s) {
|
|
1158
|
+
var h, c;
|
|
1159
|
+
const r = (h = s[t]) != null ? h : t, o = (c = s[i]) != null ? c : r, l = this.textModel.offsetToPosition(r), a = this.textModel.offsetToPosition(o);
|
|
1152
1160
|
e.push({
|
|
1153
1161
|
range: { start: l, end: a },
|
|
1154
|
-
match:
|
|
1162
|
+
match: n.substring(t, i)
|
|
1155
1163
|
});
|
|
1156
1164
|
}
|
|
1157
1165
|
isWholeWordBoundary(e, t, i) {
|
|
1158
|
-
const
|
|
1159
|
-
return !this.isWordChar(
|
|
1166
|
+
const n = t > 0 ? e[t - 1] : "", s = i < e.length ? e[i] : "";
|
|
1167
|
+
return !this.isWordChar(n) && !this.isWordChar(s);
|
|
1160
1168
|
}
|
|
1161
1169
|
isWordChar(e) {
|
|
1162
1170
|
return /^[A-Za-z0-9_]$/.test(e);
|
|
1163
1171
|
}
|
|
1164
1172
|
buildSearchTextAndOffsetMap(e) {
|
|
1165
1173
|
const t = [], i = [0];
|
|
1166
|
-
let
|
|
1167
|
-
for (let
|
|
1168
|
-
const r = e[
|
|
1169
|
-
r === "" || r ===
|
|
1174
|
+
let n = 0;
|
|
1175
|
+
for (let s = 0; s < e.length; s++) {
|
|
1176
|
+
const r = e[s];
|
|
1177
|
+
r === "" || r === w.CURSOR_SENTINEL || (t.push(r), n += 1, i[n] = s + 1);
|
|
1170
1178
|
}
|
|
1171
|
-
return i[
|
|
1179
|
+
return i[n] = e.length, {
|
|
1172
1180
|
normalizedText: t.join(""),
|
|
1173
1181
|
normalizedToRawOffsets: i
|
|
1174
1182
|
};
|
|
@@ -1176,15 +1184,17 @@ const W = class O {
|
|
|
1176
1184
|
replace(e, t) {
|
|
1177
1185
|
const i = this.getValue();
|
|
1178
1186
|
this.suppressHistory || this.pushUndoSnapshot(this.captureHistorySnapshot(i));
|
|
1179
|
-
const
|
|
1180
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [
|
|
1187
|
+
const n = this.textModel.replaceRange(e, t);
|
|
1188
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [n]);
|
|
1181
1189
|
}
|
|
1182
1190
|
replaceAll(e, t, i = {}) {
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1191
|
+
const n = this.search(e, i);
|
|
1192
|
+
if (n.length === 0) return 0;
|
|
1193
|
+
this.suppressHistory || this.pushUndoSnapshot(this.captureHistorySnapshot(this.getValue()));
|
|
1194
|
+
const s = [];
|
|
1195
|
+
for (let r = n.length - 1; r >= 0; r--)
|
|
1196
|
+
s.push(this.textModel.replaceRange(n[r].range, t));
|
|
1197
|
+
return this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", s), n.length;
|
|
1188
1198
|
}
|
|
1189
1199
|
// Folding (basic implementation)
|
|
1190
1200
|
fold(e) {
|
|
@@ -1193,14 +1203,14 @@ const W = class O {
|
|
|
1193
1203
|
if (t.start.line === t.end.line && t.start.column === t.end.column)
|
|
1194
1204
|
return;
|
|
1195
1205
|
const i = this.folds.findIndex(
|
|
1196
|
-
(
|
|
1197
|
-
),
|
|
1206
|
+
(s) => this.isSameFoldRange(s, t)
|
|
1207
|
+
), n = {
|
|
1198
1208
|
start: t.start,
|
|
1199
1209
|
end: t.end,
|
|
1200
1210
|
collapsed: !0,
|
|
1201
1211
|
level: 0
|
|
1202
1212
|
};
|
|
1203
|
-
i !== -1 ? this.folds[i] =
|
|
1213
|
+
i !== -1 ? this.folds[i] = n : (this.folds.push(n), this.folds.sort((s, r) => this.comparePositions(s.start, r.start)));
|
|
1204
1214
|
}
|
|
1205
1215
|
unfold(e) {
|
|
1206
1216
|
this.clearPendingHighlightRender();
|
|
@@ -1232,34 +1242,34 @@ const W = class O {
|
|
|
1232
1242
|
(g.querySelector(
|
|
1233
1243
|
"[data-lce-fold-placeholder]"
|
|
1234
1244
|
) || g.textContent !== e) && this.view.setText(e);
|
|
1235
|
-
const
|
|
1236
|
-
this.view.setHighlightHTML(
|
|
1245
|
+
const m = typeof i.highlight == "function" ? i.highlight(e) : i.highlightHTML(e);
|
|
1246
|
+
this.view.setHighlightHTML(m), this.view.syncTrailingNewlineMarkerForText(e), this.scheduleDecorationRender();
|
|
1237
1247
|
return;
|
|
1238
1248
|
}
|
|
1239
1249
|
const s = !t && !this.expectingProgrammaticCursor;
|
|
1240
|
-
let
|
|
1241
|
-
const
|
|
1242
|
-
(t || s) &&
|
|
1243
|
-
const d =
|
|
1244
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) &&
|
|
1250
|
+
let r, o, l, a;
|
|
1251
|
+
const h = this.view.getSelectionState(), c = h.isInEditor && !!h.cursor;
|
|
1252
|
+
(t || s) && c && (r = h.isCollapsed ? void 0 : h.range, o = this.textModel.positionToOffset(h.cursor), r && (l = this.textModel.positionToOffset(r.start), a = this.textModel.positionToOffset(r.end)));
|
|
1253
|
+
const d = c && (t || s) && !r && o !== void 0 && this.hasCollapsedSelectionInEditor(), f = d ? this.insertSentinelAtOffset(e, o) : e, u = typeof i.highlight == "function" ? i.highlight(f) : i.highlightHTML(f);
|
|
1254
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(u) : this.view.setHTML(u), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && c && requestAnimationFrame(() => {
|
|
1245
1255
|
try {
|
|
1246
1256
|
if (d && this.restoreCursorFromSentinel()) {
|
|
1247
1257
|
this.view.ensureCaretVisible();
|
|
1248
1258
|
return;
|
|
1249
1259
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
const g =
|
|
1252
|
-
this.view.setSelectionRange({ start:
|
|
1253
|
-
} else if (
|
|
1254
|
-
const g = this.textModel.offsetToPosition(
|
|
1260
|
+
if (r && (l !== void 0 || a !== void 0)) {
|
|
1261
|
+
const g = l !== void 0 ? l : o, p = a !== void 0 ? a : o, m = Math.min(g, p), y = Math.max(g, p), T = this.textModel.offsetToPosition(m), S = this.textModel.offsetToPosition(y);
|
|
1262
|
+
this.view.setSelectionRange({ start: T, end: S });
|
|
1263
|
+
} else if (o !== void 0) {
|
|
1264
|
+
const g = this.textModel.offsetToPosition(o);
|
|
1255
1265
|
this.view.setCursorPosition(g);
|
|
1256
1266
|
}
|
|
1257
1267
|
} catch (g) {
|
|
1258
1268
|
}
|
|
1259
1269
|
}), this.scheduleDecorationRender();
|
|
1260
1270
|
return;
|
|
1261
|
-
} catch (
|
|
1262
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
1271
|
+
} catch (n) {
|
|
1272
|
+
console.warn("Syntax highlighting failed, falling back to plain text", n);
|
|
1263
1273
|
}
|
|
1264
1274
|
this.view.setText(e), this.scheduleDecorationRender();
|
|
1265
1275
|
}
|
|
@@ -1277,28 +1287,28 @@ const W = class O {
|
|
|
1277
1287
|
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
1278
1288
|
if (!i.contains(t.commonAncestorContainer))
|
|
1279
1289
|
return;
|
|
1280
|
-
const
|
|
1281
|
-
return
|
|
1290
|
+
const n = t.cloneRange();
|
|
1291
|
+
return n.selectNodeContents(i), n.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(n.toString()).length;
|
|
1282
1292
|
}
|
|
1283
1293
|
stripVirtualMarkers(e) {
|
|
1284
|
-
return e.replace(/\u200B/g, "").split(
|
|
1294
|
+
return e.replace(/\u200B/g, "").split(w.CURSOR_SENTINEL).join("");
|
|
1285
1295
|
}
|
|
1286
1296
|
insertSentinelAtOffset(e, t) {
|
|
1287
1297
|
const i = Math.max(0, Math.min(t, e.length));
|
|
1288
|
-
return e.slice(0, i) +
|
|
1298
|
+
return e.slice(0, i) + w.CURSOR_SENTINEL + e.slice(i);
|
|
1289
1299
|
}
|
|
1290
1300
|
restoreCursorFromSentinel() {
|
|
1291
1301
|
var o;
|
|
1292
1302
|
const e = this.view.getContentElement(), t = window.getSelection(), i = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
|
|
1293
|
-
let
|
|
1294
|
-
for (;
|
|
1295
|
-
const l = (o =
|
|
1296
|
-
a !== -1 && (
|
|
1303
|
+
let n = i.nextNode(), s = null, r = 0;
|
|
1304
|
+
for (; n; ) {
|
|
1305
|
+
const l = (o = n.textContent) != null ? o : "", a = l.indexOf(w.CURSOR_SENTINEL);
|
|
1306
|
+
a !== -1 && (s || (s = n, r = a), n.textContent = l.split(w.CURSOR_SENTINEL).join("")), n = i.nextNode();
|
|
1297
1307
|
}
|
|
1298
|
-
if (!
|
|
1308
|
+
if (!s || !t) return !1;
|
|
1299
1309
|
try {
|
|
1300
1310
|
const l = document.createRange();
|
|
1301
|
-
return l.setStart(
|
|
1311
|
+
return l.setStart(s, r), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
|
|
1302
1312
|
} catch (l) {
|
|
1303
1313
|
return !1;
|
|
1304
1314
|
}
|
|
@@ -1339,25 +1349,68 @@ const W = class O {
|
|
|
1339
1349
|
}
|
|
1340
1350
|
// Insert a tab character or spaces at current cursor
|
|
1341
1351
|
insertTab() {
|
|
1342
|
-
if (this.config.readOnly) return;
|
|
1352
|
+
if (this.config.readOnly || this.shiftSelectedLines(!1)) return;
|
|
1343
1353
|
const e = " ".repeat(this.config.tabSize || 2);
|
|
1344
1354
|
this.replaceSelectionWithText(e);
|
|
1345
1355
|
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Tab / Shift+Tab over whole lines. Tab only applies when the selection spans lines (a caret
|
|
1358
|
+
* or single-line selection keeps the plain "insert a tab" behaviour); Shift+Tab always
|
|
1359
|
+
* outdents the line(s) it touches. Returns false when the caller should fall back to inserting.
|
|
1360
|
+
* The edit is one replace, so it is one undo step, and the selection is kept on the same text.
|
|
1361
|
+
*/
|
|
1362
|
+
shiftSelectedLines(e) {
|
|
1363
|
+
if (this.config.readOnly) return !1;
|
|
1364
|
+
const t = this.textModel.getText(), { startOffset: i, endOffset: n } = this.getActiveSelectionOffsets(t), s = Math.min(i, n), r = Math.max(i, n);
|
|
1365
|
+
if (!e && !t.slice(s, r).includes(`
|
|
1366
|
+
`)) return !1;
|
|
1367
|
+
const o = " ".repeat(this.config.tabSize || 2), l = t.lastIndexOf(`
|
|
1368
|
+
`, s - 1) + 1, a = r > s && t[r - 1] === `
|
|
1369
|
+
` ? r - 1 : r, h = t.indexOf(`
|
|
1370
|
+
`, a), c = h === -1 ? t.length : h, d = t.slice(l, c).split(`
|
|
1371
|
+
`);
|
|
1372
|
+
let f = 0, u = 0;
|
|
1373
|
+
const g = d.map((y, T) => {
|
|
1374
|
+
let S = y;
|
|
1375
|
+
if (!e)
|
|
1376
|
+
S = y.length === 0 ? y : o + y;
|
|
1377
|
+
else if (y.startsWith(" "))
|
|
1378
|
+
S = y.slice(1);
|
|
1379
|
+
else {
|
|
1380
|
+
const C = /^ */.exec(y)[0].length;
|
|
1381
|
+
S = y.slice(Math.min(C, o.length));
|
|
1382
|
+
}
|
|
1383
|
+
const v = S.length - y.length;
|
|
1384
|
+
return T === 0 && (f = v), u += v, S;
|
|
1385
|
+
});
|
|
1386
|
+
if (u === 0) return !0;
|
|
1387
|
+
this.replaceOffsetsWithText(l, c, g.join(`
|
|
1388
|
+
`));
|
|
1389
|
+
const p = Math.max(l, s + f), m = Math.max(p, r + u);
|
|
1390
|
+
return s === r ? this.setCursor(this.textModel.offsetToPosition(p)) : this.setSelection({
|
|
1391
|
+
start: this.textModel.offsetToPosition(p),
|
|
1392
|
+
end: this.textModel.offsetToPosition(m)
|
|
1393
|
+
}), !0;
|
|
1394
|
+
}
|
|
1346
1395
|
// Insert a newline at current cursor position
|
|
1347
1396
|
insertNewLine() {
|
|
1348
1397
|
this.config.readOnly || this.replaceSelectionWithText(`
|
|
1349
1398
|
`);
|
|
1350
1399
|
}
|
|
1351
|
-
deleteBackward() {
|
|
1352
|
-
this.config.readOnly || this.deleteUsingDirection("backward");
|
|
1400
|
+
deleteBackward(e = "char") {
|
|
1401
|
+
this.config.readOnly || this.deleteUsingDirection("backward", e);
|
|
1353
1402
|
}
|
|
1354
|
-
deleteForward() {
|
|
1355
|
-
this.config.readOnly || this.deleteUsingDirection("forward");
|
|
1403
|
+
deleteForward(e = "char") {
|
|
1404
|
+
this.config.readOnly || this.deleteUsingDirection("forward", e);
|
|
1405
|
+
}
|
|
1406
|
+
/** Map an InputEvent.inputType to the unit it deletes, or null when it isn't a delete in that direction. */
|
|
1407
|
+
static deletionUnit(e, t) {
|
|
1408
|
+
return e === `deleteContent${t}` ? "char" : e === `deleteWord${t}` ? "word" : e === `deleteSoftLine${t}` || e === `deleteHardLine${t}` ? "line" : null;
|
|
1356
1409
|
}
|
|
1357
1410
|
deleteSelection() {
|
|
1358
1411
|
if (this.config.readOnly) return;
|
|
1359
|
-
const e = this.textModel.getText(), { startOffset: t, endOffset: i } = this.getActiveSelectionOffsets(e),
|
|
1360
|
-
|
|
1412
|
+
const e = this.textModel.getText(), { startOffset: t, endOffset: i } = this.getActiveSelectionOffsets(e), n = Math.min(t, i), s = Math.max(t, i);
|
|
1413
|
+
n !== s && this.replaceOffsetsWithText(n, s, "");
|
|
1361
1414
|
}
|
|
1362
1415
|
// Events
|
|
1363
1416
|
on(e, t) {
|
|
@@ -1367,8 +1420,8 @@ const W = class O {
|
|
|
1367
1420
|
if (!this.eventListeners.has(e)) return;
|
|
1368
1421
|
const i = this.eventListeners.get(e);
|
|
1369
1422
|
if (t) {
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1423
|
+
const n = i.indexOf(t);
|
|
1424
|
+
n !== -1 && i.splice(n, 1);
|
|
1372
1425
|
} else
|
|
1373
1426
|
i.length = 0;
|
|
1374
1427
|
}
|
|
@@ -1379,12 +1432,12 @@ const W = class O {
|
|
|
1379
1432
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
1380
1433
|
}
|
|
1381
1434
|
captureHistorySnapshot(e = this.textModel.getText()) {
|
|
1382
|
-
const t = this.view.getSelectionState(), i = t.isInEditor && !t.isCollapsed ? t.range : void 0,
|
|
1435
|
+
const t = this.view.getSelectionState(), i = t.isInEditor && !t.isCollapsed ? t.range : void 0, n = t.isInEditor && t.cursor ? t.cursor : void 0, s = i != null ? i : this.lastKnownSelection, r = n != null ? n : this.lastKnownCursor, o = this.clampPositionToText(r, e), l = {
|
|
1383
1436
|
text: e,
|
|
1384
1437
|
cursorOffset: this.positionToOffsetInText(o, e)
|
|
1385
1438
|
};
|
|
1386
|
-
if (
|
|
1387
|
-
const a = this.clampPositionToText(
|
|
1439
|
+
if (s) {
|
|
1440
|
+
const a = this.clampPositionToText(s.start, e), h = this.clampPositionToText(s.end, e);
|
|
1388
1441
|
l.anchorOffset = this.positionToOffsetInText(a, e), l.focusOffset = this.positionToOffsetInText(h, e);
|
|
1389
1442
|
}
|
|
1390
1443
|
return l;
|
|
@@ -1393,10 +1446,10 @@ const W = class O {
|
|
|
1393
1446
|
this.setValue(e.text), requestAnimationFrame(() => {
|
|
1394
1447
|
try {
|
|
1395
1448
|
if (e.anchorOffset !== void 0 && e.focusOffset !== void 0 && e.anchorOffset !== e.focusOffset) {
|
|
1396
|
-
const
|
|
1449
|
+
const i = Math.min(e.anchorOffset, e.focusOffset), n = Math.max(e.anchorOffset, e.focusOffset);
|
|
1397
1450
|
this.setSelection({
|
|
1398
|
-
start: this.textModel.offsetToPosition(
|
|
1399
|
-
end: this.textModel.offsetToPosition(
|
|
1451
|
+
start: this.textModel.offsetToPosition(i),
|
|
1452
|
+
end: this.textModel.offsetToPosition(n)
|
|
1400
1453
|
});
|
|
1401
1454
|
return;
|
|
1402
1455
|
}
|
|
@@ -1414,23 +1467,23 @@ const W = class O {
|
|
|
1414
1467
|
clampPositionToText(e, t) {
|
|
1415
1468
|
var r, o;
|
|
1416
1469
|
const i = t.split(`
|
|
1417
|
-
`),
|
|
1470
|
+
`), n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(
|
|
1418
1471
|
0,
|
|
1419
|
-
Math.min(e.column, (o = (r = i[
|
|
1472
|
+
Math.min(e.column, (o = (r = i[n]) == null ? void 0 : r.length) != null ? o : 0)
|
|
1420
1473
|
);
|
|
1421
1474
|
return {
|
|
1422
|
-
line:
|
|
1423
|
-
column:
|
|
1475
|
+
line: n,
|
|
1476
|
+
column: s
|
|
1424
1477
|
};
|
|
1425
1478
|
}
|
|
1426
1479
|
positionToOffsetInText(e, t) {
|
|
1427
1480
|
var r, o;
|
|
1428
1481
|
const i = t.split(`
|
|
1429
|
-
`),
|
|
1430
|
-
let
|
|
1431
|
-
for (let l = 0; l <
|
|
1432
|
-
|
|
1433
|
-
return
|
|
1482
|
+
`), n = this.clampPositionToText(e, t);
|
|
1483
|
+
let s = 0;
|
|
1484
|
+
for (let l = 0; l < n.line; l++)
|
|
1485
|
+
s += ((o = (r = i[l]) == null ? void 0 : r.length) != null ? o : 0) + 1;
|
|
1486
|
+
return s + n.column;
|
|
1434
1487
|
}
|
|
1435
1488
|
clearPendingHighlightRender() {
|
|
1436
1489
|
this.highlightTimeout && (clearTimeout(this.highlightTimeout), this.highlightTimeout = null);
|
|
@@ -1440,7 +1493,7 @@ const W = class O {
|
|
|
1440
1493
|
}
|
|
1441
1494
|
replaceSelectionWithText(e) {
|
|
1442
1495
|
const t = e.replace(/\r\n?/g, `
|
|
1443
|
-
`), i = this.textModel.getText(), { startOffset:
|
|
1496
|
+
`), i = this.textModel.getText(), { startOffset: n, endOffset: s } = this.getActiveSelectionOffsets(i), r = Math.max(0, Math.min(n, s)), o = Math.max(0, Math.max(n, s));
|
|
1444
1497
|
return this.replaceOffsetsWithText(r, o, t);
|
|
1445
1498
|
}
|
|
1446
1499
|
insertClipboardText(e) {
|
|
@@ -1493,7 +1546,7 @@ const W = class O {
|
|
|
1493
1546
|
"TABLE",
|
|
1494
1547
|
"TR",
|
|
1495
1548
|
"UL"
|
|
1496
|
-
]),
|
|
1549
|
+
]), n = (o) => {
|
|
1497
1550
|
var l;
|
|
1498
1551
|
for (let a = o.length - 1; a >= 0; a--) {
|
|
1499
1552
|
const h = (l = o[a]) != null ? l : "";
|
|
@@ -1502,13 +1555,13 @@ const W = class O {
|
|
|
1502
1555
|
`);
|
|
1503
1556
|
}
|
|
1504
1557
|
return !1;
|
|
1505
|
-
},
|
|
1558
|
+
}, s = (o, l) => {
|
|
1506
1559
|
if (o instanceof Text) {
|
|
1507
1560
|
l.push(o.data);
|
|
1508
1561
|
return;
|
|
1509
1562
|
}
|
|
1510
1563
|
if (!(o instanceof HTMLElement)) {
|
|
1511
|
-
o.childNodes.forEach((h) =>
|
|
1564
|
+
o.childNodes.forEach((h) => s(h, l));
|
|
1512
1565
|
return;
|
|
1513
1566
|
}
|
|
1514
1567
|
if (o.tagName === "BR") {
|
|
@@ -1517,11 +1570,11 @@ const W = class O {
|
|
|
1517
1570
|
return;
|
|
1518
1571
|
}
|
|
1519
1572
|
const a = i.has(o.tagName);
|
|
1520
|
-
a && l.length > 0 && !
|
|
1521
|
-
`), o.childNodes.forEach((h) =>
|
|
1573
|
+
a && l.length > 0 && !n(l) && l.push(`
|
|
1574
|
+
`), o.childNodes.forEach((h) => s(h, l)), a && !n(l) && l.push(`
|
|
1522
1575
|
`);
|
|
1523
1576
|
}, r = [];
|
|
1524
|
-
return t.body.childNodes.forEach((o) =>
|
|
1577
|
+
return t.body.childNodes.forEach((o) => s(o, r)), r.join("").replace(/\n{3,}/g, `
|
|
1525
1578
|
|
|
1526
1579
|
`).replace(/[ \t]+\n/g, `
|
|
1527
1580
|
`).trimEnd();
|
|
@@ -1544,36 +1597,114 @@ const W = class O {
|
|
|
1544
1597
|
endOffset: i
|
|
1545
1598
|
};
|
|
1546
1599
|
}
|
|
1547
|
-
deleteUsingDirection(e) {
|
|
1548
|
-
const
|
|
1549
|
-
if (
|
|
1550
|
-
this.replaceOffsetsWithText(
|
|
1600
|
+
deleteUsingDirection(e, t = "char") {
|
|
1601
|
+
const i = this.textModel.getText(), { startOffset: n, endOffset: s } = this.getActiveSelectionOffsets(i), r = Math.min(n, s), o = Math.max(n, s);
|
|
1602
|
+
if (r !== o) {
|
|
1603
|
+
this.replaceOffsetsWithText(r, o, "");
|
|
1551
1604
|
return;
|
|
1552
1605
|
}
|
|
1553
1606
|
if (e === "backward") {
|
|
1554
|
-
if (
|
|
1607
|
+
if (r === 0)
|
|
1555
1608
|
return;
|
|
1556
|
-
|
|
1609
|
+
const a = w.deletionBoundary(i, r, "backward", t);
|
|
1610
|
+
this.replaceOffsetsWithText(a, r, "");
|
|
1557
1611
|
return;
|
|
1558
1612
|
}
|
|
1559
|
-
|
|
1613
|
+
if (o >= i.length)
|
|
1614
|
+
return;
|
|
1615
|
+
const l = w.deletionBoundary(i, o, "forward", t);
|
|
1616
|
+
this.replaceOffsetsWithText(o, l, "");
|
|
1617
|
+
}
|
|
1618
|
+
static getGraphemeSegmenter() {
|
|
1619
|
+
if (w.graphemeSegmenter === void 0) {
|
|
1620
|
+
const e = Intl.Segmenter;
|
|
1621
|
+
w.graphemeSegmenter = e ? new e(void 0, { granularity: "grapheme" }) : null;
|
|
1622
|
+
}
|
|
1623
|
+
return w.graphemeSegmenter;
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Where a deletion of `unit` starting at `offset` ends. Characters are whole grapheme
|
|
1627
|
+
* clusters (an emoji is two UTF-16 units, a flag or ZWJ sequence several), so Backspace
|
|
1628
|
+
* never leaves half a surrogate pair behind - that used to turn "a😀b" into "a\uD83Db",
|
|
1629
|
+
* which is invalid text once saved.
|
|
1630
|
+
*/
|
|
1631
|
+
static deletionBoundary(e, t, i, n) {
|
|
1632
|
+
const s = (d) => /[A-Za-z0-9_]/.test(d), r = (d) => d === " " || d === " ";
|
|
1633
|
+
if (n === "line") {
|
|
1634
|
+
if (i === "backward") {
|
|
1635
|
+
const u = e.lastIndexOf(`
|
|
1636
|
+
`, t - 1) + 1;
|
|
1637
|
+
return u === t ? t - 1 : u;
|
|
1638
|
+
}
|
|
1639
|
+
const d = e.indexOf(`
|
|
1640
|
+
`, t), f = d === -1 ? e.length : d;
|
|
1641
|
+
return f === t ? Math.min(e.length, t + 1) : f;
|
|
1642
|
+
}
|
|
1643
|
+
if (n === "word") {
|
|
1644
|
+
let d = t;
|
|
1645
|
+
if (i === "backward") {
|
|
1646
|
+
if (e[d - 1] === `
|
|
1647
|
+
`) return d - 1;
|
|
1648
|
+
for (; d > 0 && r(e[d - 1]); ) d--;
|
|
1649
|
+
if (d > 0 && e[d - 1] !== `
|
|
1650
|
+
`) {
|
|
1651
|
+
const f = s(e[d - 1]);
|
|
1652
|
+
for (; d > 0 && e[d - 1] !== `
|
|
1653
|
+
` && !r(e[d - 1]) && s(e[d - 1]) === f; ) d--;
|
|
1654
|
+
}
|
|
1655
|
+
return d;
|
|
1656
|
+
}
|
|
1657
|
+
if (e[d] === `
|
|
1658
|
+
`) return d + 1;
|
|
1659
|
+
for (; d < e.length && r(e[d]); ) d++;
|
|
1660
|
+
if (d < e.length && e[d] !== `
|
|
1661
|
+
`) {
|
|
1662
|
+
const f = s(e[d]);
|
|
1663
|
+
for (; d < e.length && e[d] !== `
|
|
1664
|
+
` && !r(e[d]) && s(e[d]) === f; ) d++;
|
|
1665
|
+
}
|
|
1666
|
+
return d;
|
|
1667
|
+
}
|
|
1668
|
+
if (i === "backward") {
|
|
1669
|
+
const d = e.lastIndexOf(`
|
|
1670
|
+
`, t - 1) + 1;
|
|
1671
|
+
if (d === t) return t - 1;
|
|
1672
|
+
const f = w.getGraphemeSegmenter();
|
|
1673
|
+
if (f) {
|
|
1674
|
+
let p = 1;
|
|
1675
|
+
for (const { segment: m } of f.segment(e.slice(d, t))) p = m.length;
|
|
1676
|
+
return t - p;
|
|
1677
|
+
}
|
|
1678
|
+
const u = e.charCodeAt(t - 1), g = t >= 2 ? e.charCodeAt(t - 2) : 0;
|
|
1679
|
+
return u >= 56320 && u <= 57343 && g >= 55296 && g <= 56319 ? t - 2 : t - 1;
|
|
1680
|
+
}
|
|
1681
|
+
if (e[t] === `
|
|
1682
|
+
`) return t + 1;
|
|
1683
|
+
const o = e.indexOf(`
|
|
1684
|
+
`, t), l = o === -1 ? e.length : o, a = w.getGraphemeSegmenter();
|
|
1685
|
+
if (a) {
|
|
1686
|
+
for (const { segment: d } of a.segment(e.slice(t, l))) return t + d.length;
|
|
1687
|
+
return t + 1;
|
|
1688
|
+
}
|
|
1689
|
+
const h = e.charCodeAt(t), c = t + 1 < e.length ? e.charCodeAt(t + 1) : 0;
|
|
1690
|
+
return h >= 55296 && h <= 56319 && c >= 56320 && c <= 57343 ? t + 2 : t + 1;
|
|
1560
1691
|
}
|
|
1561
1692
|
replaceOffsetsWithText(e, t, i) {
|
|
1562
|
-
var
|
|
1693
|
+
var f;
|
|
1563
1694
|
this.ensureEditableSurfaceIsUnfolded();
|
|
1564
|
-
const
|
|
1565
|
-
`),
|
|
1695
|
+
const n = i.replace(/\r\n?/g, `
|
|
1696
|
+
`), s = this.textModel.getText(), r = (f = this.pendingInputSnapshot) != null ? f : this.captureHistorySnapshot(s), o = Math.max(0, Math.min(e, s.length)), l = Math.max(0, Math.min(t, s.length)), a = Math.min(o, l), h = Math.max(o, l), c = this.textModel.replaceRange(
|
|
1566
1697
|
{
|
|
1567
1698
|
start: this.textModel.offsetToPosition(a),
|
|
1568
1699
|
end: this.textModel.offsetToPosition(h)
|
|
1569
1700
|
},
|
|
1570
|
-
|
|
1701
|
+
n
|
|
1571
1702
|
);
|
|
1572
1703
|
this.pendingInputSnapshot = void 0, this.suppressHistory || this.pushUndoSnapshot(r);
|
|
1573
|
-
const
|
|
1574
|
-
return this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), this.setCursor(this.textModel.offsetToPosition(
|
|
1704
|
+
const d = a + n.length;
|
|
1705
|
+
return this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), this.setCursor(this.textModel.offsetToPosition(d)), setTimeout(() => {
|
|
1575
1706
|
this.expectingProgrammaticCursor = !1;
|
|
1576
|
-
}, 20), this.emit("change", [
|
|
1707
|
+
}, 20), this.emit("change", [c]), c;
|
|
1577
1708
|
}
|
|
1578
1709
|
ensureEditableSurfaceIsUnfolded() {
|
|
1579
1710
|
!this.hasRenderedFoldPlaceholders() && this.folds.length === 0 || (this.clearPendingHighlightRender(), this.folds = [], this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), setTimeout(() => {
|
|
@@ -1606,9 +1737,9 @@ const W = class O {
|
|
|
1606
1737
|
return;
|
|
1607
1738
|
}
|
|
1608
1739
|
const e = [], t = [], i = [];
|
|
1609
|
-
for (const [
|
|
1610
|
-
for (const r of
|
|
1611
|
-
const o = `${
|
|
1740
|
+
for (const [n, s] of this.decorationLayers.entries())
|
|
1741
|
+
for (const r of s) {
|
|
1742
|
+
const o = `${n}::${r.id}`;
|
|
1612
1743
|
if (r.type === "line") {
|
|
1613
1744
|
e.push({
|
|
1614
1745
|
...r,
|
|
@@ -1661,28 +1792,28 @@ const W = class O {
|
|
|
1661
1792
|
}
|
|
1662
1793
|
if (this.clearInlineDecorationHighlights(), e.length === 0)
|
|
1663
1794
|
return;
|
|
1664
|
-
const
|
|
1795
|
+
const n = this.textModel.getText(), s = [];
|
|
1665
1796
|
let r = 0;
|
|
1666
1797
|
for (const l of e) {
|
|
1667
1798
|
if (r >= this.decorationHighlightLimit)
|
|
1668
1799
|
break;
|
|
1669
|
-
const a = this.normalizeInlineDecoration(l,
|
|
1800
|
+
const a = this.normalizeInlineDecoration(l, n);
|
|
1670
1801
|
if (!a)
|
|
1671
1802
|
continue;
|
|
1672
1803
|
const h = this.view.createDomRangeFromRange(a.range);
|
|
1673
1804
|
if (!h)
|
|
1674
1805
|
continue;
|
|
1675
|
-
const
|
|
1806
|
+
const c = this.buildInlineDecorationHighlightName(
|
|
1676
1807
|
a.id
|
|
1677
1808
|
);
|
|
1678
|
-
t.highlights.set(
|
|
1679
|
-
::highlight(${
|
|
1809
|
+
t.highlights.set(c, new i(h)), this.inlineDecorationHighlightNames.add(c), s.push(`
|
|
1810
|
+
::highlight(${c}) {
|
|
1680
1811
|
${this.serializeInlineDecorationStyle(a.style)}
|
|
1681
1812
|
}
|
|
1682
1813
|
`), r += 1;
|
|
1683
1814
|
}
|
|
1684
1815
|
const o = this.ensureDecorationHighlightStyleNode();
|
|
1685
|
-
o.textContent =
|
|
1816
|
+
o.textContent = s.join(`
|
|
1686
1817
|
`);
|
|
1687
1818
|
}
|
|
1688
1819
|
normalizeInlineDecoration(e, t) {
|
|
@@ -1700,11 +1831,11 @@ const W = class O {
|
|
|
1700
1831
|
try {
|
|
1701
1832
|
const i = CSS;
|
|
1702
1833
|
if (i.highlights)
|
|
1703
|
-
for (const
|
|
1704
|
-
i.highlights.delete(
|
|
1834
|
+
for (const n of this.inlineDecorationHighlightNames)
|
|
1835
|
+
i.highlights.delete(n);
|
|
1705
1836
|
} catch (i) {
|
|
1706
1837
|
}
|
|
1707
|
-
if (this.inlineDecorationHighlightNames.clear(), typeof document
|
|
1838
|
+
if (this.inlineDecorationHighlightNames.clear(), typeof document == "undefined")
|
|
1708
1839
|
return;
|
|
1709
1840
|
const t = document.getElementById(this.decorationHighlightStyleId);
|
|
1710
1841
|
if (e) {
|
|
@@ -1720,7 +1851,7 @@ const W = class O {
|
|
|
1720
1851
|
return e || (e = document.createElement("style"), e.id = this.decorationHighlightStyleId, document.head.appendChild(e), e);
|
|
1721
1852
|
}
|
|
1722
1853
|
observeDecorationRelevantMutations() {
|
|
1723
|
-
typeof MutationObserver
|
|
1854
|
+
typeof MutationObserver != "undefined" && (this.decorationMutationObserver = new MutationObserver(() => {
|
|
1724
1855
|
this.decorationLayers.size !== 0 && this.scheduleDecorationRender();
|
|
1725
1856
|
}), this.decorationMutationObserver.observe(this.view.getContentElement(), {
|
|
1726
1857
|
childList: !0,
|
|
@@ -1730,7 +1861,7 @@ const W = class O {
|
|
|
1730
1861
|
}
|
|
1731
1862
|
detectCustomHighlightSupport() {
|
|
1732
1863
|
try {
|
|
1733
|
-
if (typeof CSS
|
|
1864
|
+
if (typeof CSS == "undefined" || typeof window == "undefined")
|
|
1734
1865
|
return !1;
|
|
1735
1866
|
const e = CSS, t = window.Highlight;
|
|
1736
1867
|
return !!e.highlights && !!t;
|
|
@@ -1745,7 +1876,8 @@ const W = class O {
|
|
|
1745
1876
|
return e.toLowerCase().replace(/[^a-z0-9_-]+/g, "-");
|
|
1746
1877
|
}
|
|
1747
1878
|
serializeInlineDecorationStyle(e) {
|
|
1748
|
-
|
|
1879
|
+
const t = this.serializeStyleObject(e);
|
|
1880
|
+
return t || "background-color: var(--lce-inline-decoration-bg, rgba(86, 156, 214, 0.18)); border-radius: 2px;";
|
|
1749
1881
|
}
|
|
1750
1882
|
serializeStyleObject(e) {
|
|
1751
1883
|
return e ? Object.entries(e).filter(([, t]) => typeof t == "string" && t.length > 0).map(([t, i]) => `${this.toKebabCase(t)}: ${i};`).join(" ") : "";
|
|
@@ -1767,8 +1899,8 @@ const W = class O {
|
|
|
1767
1899
|
};
|
|
1768
1900
|
}
|
|
1769
1901
|
};
|
|
1770
|
-
|
|
1771
|
-
let
|
|
1902
|
+
w.CURSOR_SENTINEL = "";
|
|
1903
|
+
let V = w;
|
|
1772
1904
|
class J {
|
|
1773
1905
|
constructor(e) {
|
|
1774
1906
|
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
|
|
@@ -1783,11 +1915,11 @@ class J {
|
|
|
1783
1915
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
1784
1916
|
}
|
|
1785
1917
|
findMatchingBinding(e) {
|
|
1786
|
-
const { key: t, ctrlKey: i, altKey:
|
|
1918
|
+
const { key: t, ctrlKey: i, altKey: n, shiftKey: s, metaKey: r } = e, o = String(t).toLowerCase(), l = this.keymap[o];
|
|
1787
1919
|
if (!l) return null;
|
|
1788
1920
|
for (const a of l) {
|
|
1789
|
-
const h = a.ctrlKey === void 0 || a.ctrlKey === i,
|
|
1790
|
-
if (h &&
|
|
1921
|
+
const h = a.ctrlKey === void 0 || a.ctrlKey === i, c = a.altKey === void 0 || a.altKey === n, d = a.shiftKey === void 0 || a.shiftKey === s, f = a.metaKey === void 0 || a.metaKey === r;
|
|
1922
|
+
if (h && c && d && f)
|
|
1791
1923
|
return a;
|
|
1792
1924
|
}
|
|
1793
1925
|
return null;
|
|
@@ -1798,13 +1930,13 @@ class J {
|
|
|
1798
1930
|
}
|
|
1799
1931
|
getDefaultKeymap() {
|
|
1800
1932
|
const e = {};
|
|
1801
|
-
return this.addBinding(e, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(e, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(e, "f3", {}, "findNext"), this.addBinding(e, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(e, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(e, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(e, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(e, "s", { ctrlKey: !0 }, "save"), this.addBinding(e, "s", { metaKey: !0 }, "save"), this.addBinding(e, "z", { ctrlKey: !0 }, "undo"), this.addBinding(e, "z", { metaKey: !0 }, "undo"), this.addBinding(e, "y", { ctrlKey: !0 }, "redo"), this.addBinding(e, "y", { metaKey: !0 }, "redo"), this.addBinding(e, "z", { ctrlKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "z", { metaKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "tab", {}, "insertTab"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), this.addBinding(e, "f", { altKey: !0, shiftKey: !0 }, "formatDocument"), e;
|
|
1933
|
+
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", { shiftKey: !0 }, "outdent"), this.addBinding(e, "tab", { shiftKey: !1, ctrlKey: !1, altKey: !1, metaKey: !1 }, "insertTab"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), this.addBinding(e, "f", { altKey: !0, shiftKey: !0 }, "formatDocument"), e;
|
|
1802
1934
|
}
|
|
1803
|
-
addBinding(e, t, i,
|
|
1804
|
-
const
|
|
1805
|
-
e[
|
|
1806
|
-
key:
|
|
1807
|
-
command:
|
|
1935
|
+
addBinding(e, t, i, n) {
|
|
1936
|
+
const s = t.toLowerCase();
|
|
1937
|
+
e[s] || (e[s] = []), e[s].push({
|
|
1938
|
+
key: s,
|
|
1939
|
+
command: n,
|
|
1808
1940
|
...i
|
|
1809
1941
|
});
|
|
1810
1942
|
}
|
|
@@ -1821,7 +1953,7 @@ class J {
|
|
|
1821
1953
|
}
|
|
1822
1954
|
removeKeyBinding(e, t) {
|
|
1823
1955
|
const i = e.toLowerCase();
|
|
1824
|
-
t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((
|
|
1956
|
+
t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((n) => n.command !== t), this.keymap[i].length === 0 && delete this.keymap[i]) : delete this.keymap[i];
|
|
1825
1957
|
}
|
|
1826
1958
|
getKeymap() {
|
|
1827
1959
|
return { ...this.keymap };
|
|
@@ -1829,8 +1961,8 @@ class J {
|
|
|
1829
1961
|
getBindingsForCommand(e) {
|
|
1830
1962
|
const t = [];
|
|
1831
1963
|
for (const i in this.keymap)
|
|
1832
|
-
for (const
|
|
1833
|
-
|
|
1964
|
+
for (const n of this.keymap[i])
|
|
1965
|
+
n.command === e && t.push({ ...n });
|
|
1834
1966
|
return t;
|
|
1835
1967
|
}
|
|
1836
1968
|
getPlatformInfo() {
|
|
@@ -1843,7 +1975,7 @@ class J {
|
|
|
1843
1975
|
this.keymap = {}, this.editor = null;
|
|
1844
1976
|
}
|
|
1845
1977
|
}
|
|
1846
|
-
const
|
|
1978
|
+
const A = class A {
|
|
1847
1979
|
constructor() {
|
|
1848
1980
|
this.name = "transaction", this.transactions = [];
|
|
1849
1981
|
}
|
|
@@ -1855,9 +1987,9 @@ const U = class z {
|
|
|
1855
1987
|
effects: [],
|
|
1856
1988
|
annotations: []
|
|
1857
1989
|
};
|
|
1858
|
-
this.transactions.push(i), this.transactions.length >
|
|
1990
|
+
this.transactions.push(i), this.transactions.length > A.MAX_TRANSACTIONS && this.transactions.splice(
|
|
1859
1991
|
0,
|
|
1860
|
-
this.transactions.length -
|
|
1992
|
+
this.transactions.length - A.MAX_TRANSACTIONS
|
|
1861
1993
|
);
|
|
1862
1994
|
});
|
|
1863
1995
|
}
|
|
@@ -1868,9 +2000,9 @@ const U = class z {
|
|
|
1868
2000
|
this.transactions = [];
|
|
1869
2001
|
}
|
|
1870
2002
|
};
|
|
1871
|
-
|
|
1872
|
-
let
|
|
1873
|
-
class
|
|
2003
|
+
A.MAX_TRANSACTIONS = 200;
|
|
2004
|
+
let W = A;
|
|
2005
|
+
class ee {
|
|
1874
2006
|
constructor() {
|
|
1875
2007
|
this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
|
|
1876
2008
|
}
|
|
@@ -1899,7 +2031,7 @@ class te {
|
|
|
1899
2031
|
this.lineNumbersElement = null, this.editor = null;
|
|
1900
2032
|
}
|
|
1901
2033
|
}
|
|
1902
|
-
class
|
|
2034
|
+
class te {
|
|
1903
2035
|
constructor() {
|
|
1904
2036
|
this.name = "theme", this.editor = null, this.currentTheme = "dark";
|
|
1905
2037
|
}
|
|
@@ -1924,7 +2056,7 @@ class ie {
|
|
|
1924
2056
|
this.editor = null;
|
|
1925
2057
|
}
|
|
1926
2058
|
}
|
|
1927
|
-
class
|
|
2059
|
+
class ie {
|
|
1928
2060
|
constructor() {
|
|
1929
2061
|
this.name = "read-only", this.editor = null, this.isReadOnly = !1;
|
|
1930
2062
|
}
|
|
@@ -1952,7 +2084,7 @@ class se {
|
|
|
1952
2084
|
}
|
|
1953
2085
|
}
|
|
1954
2086
|
let ne = 0;
|
|
1955
|
-
const
|
|
2087
|
+
const x = class x {
|
|
1956
2088
|
constructor(e = {}) {
|
|
1957
2089
|
this.name = "search", this.editor = null, this.searchUI = null, this.isVisible = !1, this.currentResults = [], this.currentIndex = -1, this.searchDebounceTimer = null, this.liveRefreshTimer = null, this.statusResetTimer = null, this.statusFreezeUntil = 0, this.findInput = null, this.replaceInputEl = null, this.statusDiv = null, this.modeDiv = null, this.caseSensitiveInput = null, this.wholeWordInput = null, this.regexInput = null, this.currentQuery = "", this.savedCursor = null, this.editorChangeHandler = null, this.searchOptions = {
|
|
1958
2090
|
caseSensitive: !1,
|
|
@@ -1991,73 +2123,73 @@ const K = class y {
|
|
|
1991
2123
|
if (!this.editor) return;
|
|
1992
2124
|
const e = this.editor.getView().getContentElement(), t = e.closest(
|
|
1993
2125
|
this.editorContainerSelector
|
|
1994
|
-
), i = t == null ? void 0 : t.parentElement,
|
|
1995
|
-
if (!
|
|
1996
|
-
window.getComputedStyle(
|
|
1997
|
-
<div class="${
|
|
1998
|
-
<input type="text" class="${
|
|
1999
|
-
<button class="${
|
|
2000
|
-
<button class="${
|
|
2001
|
-
<button class="${
|
|
2126
|
+
), i = t == null ? void 0 : t.parentElement, n = e.closest(".rte-source-editor-modal") || i || t || e.parentElement;
|
|
2127
|
+
if (!n) return;
|
|
2128
|
+
window.getComputedStyle(n).position === "static" && (n.style.position = "relative"), this.searchUI = document.createElement("div"), this.searchUI.className = x.css.root, this.searchUI.style.display = "none", this.searchUI.innerHTML = `
|
|
2129
|
+
<div class="${x.css.row}">
|
|
2130
|
+
<input type="text" class="${x.css.findInput} ${x.css.inputBase}" placeholder="Find..." />
|
|
2131
|
+
<button class="${x.css.prevButton} ${x.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
2132
|
+
<button class="${x.css.nextButton} ${x.css.buttonBase}" type="button" aria-label="Next match">↓</button>
|
|
2133
|
+
<button class="${x.css.closeButton} ${x.css.buttonBase}" type="button" aria-label="Close search">×</button>
|
|
2002
2134
|
</div>
|
|
2003
|
-
<div class="${
|
|
2004
|
-
<label class="${
|
|
2005
|
-
<input type="checkbox" class="${
|
|
2135
|
+
<div class="${x.css.options}">
|
|
2136
|
+
<label class="${x.css.optionLabel}" title="Case sensitive">
|
|
2137
|
+
<input type="checkbox" class="${x.css.optionInput} ${x.css.caseSensitive}" />
|
|
2006
2138
|
<span>Aa</span>
|
|
2007
2139
|
</label>
|
|
2008
|
-
<label class="${
|
|
2009
|
-
<input type="checkbox" class="${
|
|
2140
|
+
<label class="${x.css.optionLabel}" title="Whole word">
|
|
2141
|
+
<input type="checkbox" class="${x.css.optionInput} ${x.css.wholeWord}" />
|
|
2010
2142
|
<span>Whole</span>
|
|
2011
2143
|
</label>
|
|
2012
|
-
<label class="${
|
|
2013
|
-
<input type="checkbox" class="${
|
|
2144
|
+
<label class="${x.css.optionLabel}" title="Regular expression">
|
|
2145
|
+
<input type="checkbox" class="${x.css.optionInput} ${x.css.regex}" />
|
|
2014
2146
|
<span>.*</span>
|
|
2015
2147
|
</label>
|
|
2016
2148
|
</div>
|
|
2017
|
-
<div class="${
|
|
2018
|
-
<div class="${
|
|
2019
|
-
<div class="${
|
|
2149
|
+
<div class="${x.css.meta}">
|
|
2150
|
+
<div class="${x.css.status} ${x.css.statusLayout}"></div>
|
|
2151
|
+
<div class="${x.css.mode} ${x.css.modeLayout}" aria-live="polite"></div>
|
|
2020
2152
|
</div>
|
|
2021
|
-
<input type="text" class="${
|
|
2153
|
+
<input type="text" class="${x.css.replaceInput} ${x.css.inputBase} ${x.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
2022
2154
|
`;
|
|
2023
|
-
const
|
|
2024
|
-
`.${
|
|
2155
|
+
const s = this.searchUI.querySelector(
|
|
2156
|
+
`.${x.css.findInput}`
|
|
2025
2157
|
), r = this.searchUI.querySelector(
|
|
2026
|
-
`.${
|
|
2158
|
+
`.${x.css.replaceInput}`
|
|
2027
2159
|
), o = this.searchUI.querySelector(
|
|
2028
|
-
`.${
|
|
2160
|
+
`.${x.css.prevButton}`
|
|
2029
2161
|
), l = this.searchUI.querySelector(
|
|
2030
|
-
`.${
|
|
2162
|
+
`.${x.css.nextButton}`
|
|
2031
2163
|
), a = this.searchUI.querySelector(
|
|
2032
|
-
`.${
|
|
2164
|
+
`.${x.css.closeButton}`
|
|
2033
2165
|
), h = this.searchUI.querySelector(
|
|
2034
|
-
`.${
|
|
2035
|
-
), d = this.searchUI.querySelector(
|
|
2036
|
-
`.${y.css.mode}`
|
|
2166
|
+
`.${x.css.status}`
|
|
2037
2167
|
), c = this.searchUI.querySelector(
|
|
2038
|
-
`.${
|
|
2168
|
+
`.${x.css.mode}`
|
|
2169
|
+
), d = this.searchUI.querySelector(
|
|
2170
|
+
`.${x.css.caseSensitive}`
|
|
2171
|
+
), f = this.searchUI.querySelector(
|
|
2172
|
+
`.${x.css.wholeWord}`
|
|
2039
2173
|
), u = this.searchUI.querySelector(
|
|
2040
|
-
`.${
|
|
2041
|
-
), g = this.searchUI.querySelector(
|
|
2042
|
-
`.${y.css.regex}`
|
|
2174
|
+
`.${x.css.regex}`
|
|
2043
2175
|
);
|
|
2044
|
-
this.findInput =
|
|
2176
|
+
this.findInput = s, this.replaceInputEl = r, this.statusDiv = h, this.modeDiv = c, this.caseSensitiveInput = d, this.wholeWordInput = f, this.regexInput = u, d.checked = !!this.searchOptions.caseSensitive, f.checked = !!this.searchOptions.wholeWord, u.checked = !!this.searchOptions.regex, s.addEventListener("input", () => {
|
|
2045
2177
|
this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
|
|
2046
|
-
const p =
|
|
2178
|
+
const p = s.value;
|
|
2047
2179
|
this.searchDebounceTimer = setTimeout(() => {
|
|
2048
2180
|
this.performSearch(p, !1, !1);
|
|
2049
2181
|
}, 120);
|
|
2050
2182
|
});
|
|
2051
|
-
const
|
|
2052
|
-
this.searchOptions.caseSensitive =
|
|
2053
|
-
const p =
|
|
2183
|
+
const g = () => {
|
|
2184
|
+
this.searchOptions.caseSensitive = d.checked, this.searchOptions.wholeWord = f.checked, this.searchOptions.regex = u.checked;
|
|
2185
|
+
const p = s.value;
|
|
2054
2186
|
p.trim() ? this.performSearch(p, !1, !1) : this.performSearch("", !1, !1);
|
|
2055
2187
|
};
|
|
2056
|
-
|
|
2188
|
+
d.addEventListener("change", g), f.addEventListener("change", g), u.addEventListener("change", g), s.addEventListener("keydown", (p) => {
|
|
2057
2189
|
p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.findPrev() : this.findNext()) : p.key === "Escape" && (p.preventDefault(), this.hideSearch());
|
|
2058
2190
|
}), r.addEventListener("keydown", (p) => {
|
|
2059
|
-
p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.replaceAll(
|
|
2060
|
-
}), o.addEventListener("click", () => this.findPrev()), l.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()),
|
|
2191
|
+
p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.replaceAll(s.value, r.value) : this.replaceCurrent(s.value, r.value)) : p.key === "Escape" && (p.preventDefault(), this.hideSearch());
|
|
2192
|
+
}), o.addEventListener("click", () => this.findPrev()), l.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()), n.appendChild(this.searchUI);
|
|
2061
2193
|
}
|
|
2062
2194
|
updateModeHint(e) {
|
|
2063
2195
|
this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
|
|
@@ -2072,12 +2204,12 @@ const K = class y {
|
|
|
2072
2204
|
return;
|
|
2073
2205
|
}
|
|
2074
2206
|
this.currentQuery = e;
|
|
2075
|
-
const
|
|
2076
|
-
if (this.currentResults =
|
|
2207
|
+
const n = this.currentIndex, s = this.editor.search(e, this.searchOptions);
|
|
2208
|
+
if (this.currentResults = s, s.length === 0) {
|
|
2077
2209
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
|
|
2078
2210
|
return;
|
|
2079
2211
|
}
|
|
2080
|
-
t &&
|
|
2212
|
+
t && n >= 0 ? this.currentIndex = Math.min(n, s.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
|
|
2081
2213
|
}
|
|
2082
2214
|
findNext() {
|
|
2083
2215
|
if (this.currentResults.length === 0) {
|
|
@@ -2097,17 +2229,17 @@ const K = class y {
|
|
|
2097
2229
|
if (!this.editor || !e.trim() || ((this.currentQuery !== e || this.currentResults.length === 0) && this.performSearch(e, !1, !0), this.currentIndex < 0 || this.currentResults.length === 0)) return;
|
|
2098
2230
|
const i = this.currentResults[this.currentIndex];
|
|
2099
2231
|
if (!i) return;
|
|
2100
|
-
const
|
|
2232
|
+
const n = this.computeReplacementRange(i.range.start, t);
|
|
2101
2233
|
if (this.editor.replace(i.range, t), this.config.replaceAndFindNext) {
|
|
2102
2234
|
this.currentQuery = e;
|
|
2103
|
-
const
|
|
2104
|
-
if (this.currentResults =
|
|
2235
|
+
const s = this.editor.search(e, this.searchOptions);
|
|
2236
|
+
if (this.currentResults = s, s.length === 0) {
|
|
2105
2237
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
|
|
2106
2238
|
return;
|
|
2107
2239
|
}
|
|
2108
|
-
this.currentIndex = this.findNextResultIndexAfter(
|
|
2240
|
+
this.currentIndex = this.findNextResultIndexAfter(n.end, s), this.updateHighlights(!0);
|
|
2109
2241
|
} else
|
|
2110
|
-
this.scrollLogicalRangeIntoView(
|
|
2242
|
+
this.scrollLogicalRangeIntoView(n, !0), this.performSearch(e, !0, !1);
|
|
2111
2243
|
this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
2112
2244
|
}
|
|
2113
2245
|
replaceAll(e, t) {
|
|
@@ -2126,10 +2258,10 @@ const K = class y {
|
|
|
2126
2258
|
}
|
|
2127
2259
|
navigateToResult(e, t) {
|
|
2128
2260
|
if (!this.editor) return;
|
|
2129
|
-
const i = document.activeElement,
|
|
2261
|
+
const i = document.activeElement, n = !!i && (i === this.findInput || i === this.replaceInputEl);
|
|
2130
2262
|
t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
|
|
2131
|
-
const
|
|
2132
|
-
t && typeof
|
|
2263
|
+
const s = this.editor.getView();
|
|
2264
|
+
t && typeof s.ensureCaretVisible == "function" && s.ensureCaretVisible(), t && n && i && requestAnimationFrame(() => {
|
|
2133
2265
|
this.focusWithoutScrolling(i);
|
|
2134
2266
|
});
|
|
2135
2267
|
}
|
|
@@ -2147,18 +2279,18 @@ const K = class y {
|
|
|
2147
2279
|
}
|
|
2148
2280
|
scrollLogicalRangeIntoView(e, t) {
|
|
2149
2281
|
if (!this.editor) return;
|
|
2150
|
-
const i = this.editor.getView().getContentElement(),
|
|
2282
|
+
const i = this.editor.getView().getContentElement(), n = this.editor.getValue(), { lineStarts: s, lines: r } = this.buildLineStarts(n), o = this.buildTextNodeIndex(i);
|
|
2151
2283
|
if (o.length === 0) return;
|
|
2152
|
-
const l = this.toDomRange(e,
|
|
2284
|
+
const l = this.toDomRange(e, s, r, o);
|
|
2153
2285
|
if (!l) return;
|
|
2154
2286
|
const a = l.startContainer.nodeType === Node.TEXT_NODE ? l.startContainer.parentElement : l.startContainer, h = this.resolveScrollContainer(i);
|
|
2155
2287
|
if (h) {
|
|
2156
|
-
const
|
|
2157
|
-
let
|
|
2158
|
-
const
|
|
2159
|
-
|
|
2160
|
-
const
|
|
2161
|
-
if (
|
|
2288
|
+
const c = l.getClientRects()[0] || l.getBoundingClientRect(), d = h.getBoundingClientRect(), u = h.scrollTop + (c.top - d.top) - d.height / 2 + c.height / 2, g = 18;
|
|
2289
|
+
let p = t ? u : h.scrollTop, m = h.scrollLeft;
|
|
2290
|
+
const y = h.scrollLeft + (c.left - d.left), T = y + c.width;
|
|
2291
|
+
c.right > d.right - g ? m = T - d.width + g : c.left < d.left + g && (m = Math.max(0, y - g));
|
|
2292
|
+
const S = Math.max(0, h.scrollHeight - h.clientHeight), v = Math.max(0, h.scrollWidth - h.clientWidth);
|
|
2293
|
+
if (p = Math.min(S, Math.max(0, p)), m = Math.min(v, Math.max(0, m)), S === 0 && v === 0) {
|
|
2162
2294
|
a == null || a.scrollIntoView({
|
|
2163
2295
|
block: t ? "center" : "nearest",
|
|
2164
2296
|
inline: "nearest",
|
|
@@ -2166,9 +2298,9 @@ const K = class y {
|
|
|
2166
2298
|
});
|
|
2167
2299
|
return;
|
|
2168
2300
|
}
|
|
2169
|
-
(
|
|
2170
|
-
top:
|
|
2171
|
-
left:
|
|
2301
|
+
(p !== h.scrollTop || m !== h.scrollLeft) && h.scrollTo({
|
|
2302
|
+
top: p,
|
|
2303
|
+
left: m,
|
|
2172
2304
|
behavior: "smooth"
|
|
2173
2305
|
});
|
|
2174
2306
|
return;
|
|
@@ -2196,32 +2328,32 @@ const K = class y {
|
|
|
2196
2328
|
if (!t) return;
|
|
2197
2329
|
const i = window.getSelection();
|
|
2198
2330
|
if (!i || i.rangeCount === 0) return;
|
|
2199
|
-
const
|
|
2200
|
-
if (!
|
|
2201
|
-
const r = t.getBoundingClientRect(),
|
|
2202
|
-
|
|
2203
|
-
top:
|
|
2331
|
+
const n = i.getRangeAt(0).cloneRange(), s = n.getClientRects()[0] || n.getBoundingClientRect();
|
|
2332
|
+
if (!s) return;
|
|
2333
|
+
const r = t.getBoundingClientRect(), l = t.scrollTop + (s.top - r.top) - r.height / 2 + s.height / 2, a = Math.max(0, t.scrollHeight - t.clientHeight), h = Math.min(a, Math.max(0, l));
|
|
2334
|
+
h !== t.scrollTop && t.scrollTo({
|
|
2335
|
+
top: h,
|
|
2204
2336
|
behavior: "smooth"
|
|
2205
2337
|
});
|
|
2206
2338
|
}
|
|
2207
2339
|
computeReplacementRange(e, t) {
|
|
2208
2340
|
const i = t.replace(/\r\n?/g, `
|
|
2209
|
-
`),
|
|
2341
|
+
`), n = i.split(`
|
|
2210
2342
|
`);
|
|
2211
|
-
let
|
|
2212
|
-
return
|
|
2343
|
+
let s;
|
|
2344
|
+
return n.length <= 1 ? (s = {
|
|
2213
2345
|
start: e,
|
|
2214
2346
|
end: {
|
|
2215
2347
|
line: e.line,
|
|
2216
2348
|
column: e.column + i.length
|
|
2217
2349
|
}
|
|
2218
|
-
}, this.clampRangeToDocument(
|
|
2350
|
+
}, this.clampRangeToDocument(s)) : (s = {
|
|
2219
2351
|
start: e,
|
|
2220
2352
|
end: {
|
|
2221
|
-
line: e.line +
|
|
2222
|
-
column:
|
|
2353
|
+
line: e.line + n.length - 1,
|
|
2354
|
+
column: n[n.length - 1].length
|
|
2223
2355
|
}
|
|
2224
|
-
}, this.clampRangeToDocument(
|
|
2356
|
+
}, this.clampRangeToDocument(s));
|
|
2225
2357
|
}
|
|
2226
2358
|
findNextResultIndexAfter(e, t) {
|
|
2227
2359
|
for (let i = 0; i < t.length; i++)
|
|
@@ -2237,15 +2369,15 @@ const K = class y {
|
|
|
2237
2369
|
const t = this.editor;
|
|
2238
2370
|
if (!t) return e;
|
|
2239
2371
|
const i = t.getValue().split(`
|
|
2240
|
-
`),
|
|
2372
|
+
`), n = Math.max(0, i.length - 1), s = Math.max(0, Math.min(e.start.line, n)), r = Math.max(0, Math.min(e.end.line, n)), o = Math.max(
|
|
2241
2373
|
0,
|
|
2242
|
-
Math.min(e.start.column, ((a = i[
|
|
2374
|
+
Math.min(e.start.column, ((a = i[s]) == null ? void 0 : a.length) || 0)
|
|
2243
2375
|
), l = Math.max(
|
|
2244
2376
|
0,
|
|
2245
2377
|
Math.min(e.end.column, ((h = i[r]) == null ? void 0 : h.length) || 0)
|
|
2246
2378
|
);
|
|
2247
2379
|
return {
|
|
2248
|
-
start: { line:
|
|
2380
|
+
start: { line: s, column: o },
|
|
2249
2381
|
end: { line: r, column: l }
|
|
2250
2382
|
};
|
|
2251
2383
|
}
|
|
@@ -2256,36 +2388,36 @@ const K = class y {
|
|
|
2256
2388
|
});
|
|
2257
2389
|
} catch (t) {
|
|
2258
2390
|
const i = [];
|
|
2259
|
-
let
|
|
2260
|
-
for (;
|
|
2261
|
-
this.canScroll(
|
|
2262
|
-
el:
|
|
2263
|
-
top:
|
|
2264
|
-
left:
|
|
2265
|
-
}),
|
|
2266
|
-
const
|
|
2391
|
+
let n = e.parentElement;
|
|
2392
|
+
for (; n; )
|
|
2393
|
+
this.canScroll(n) && i.push({
|
|
2394
|
+
el: n,
|
|
2395
|
+
top: n.scrollTop,
|
|
2396
|
+
left: n.scrollLeft
|
|
2397
|
+
}), n = n.parentElement;
|
|
2398
|
+
const s = window.scrollX, r = window.scrollY;
|
|
2267
2399
|
e.focus();
|
|
2268
2400
|
for (let o = 0; o < i.length; o++) {
|
|
2269
2401
|
const l = i[o];
|
|
2270
2402
|
l.el.scrollTop = l.top, l.el.scrollLeft = l.left;
|
|
2271
2403
|
}
|
|
2272
|
-
window.scrollTo(
|
|
2404
|
+
window.scrollTo(s, r);
|
|
2273
2405
|
}
|
|
2274
2406
|
}
|
|
2275
2407
|
findScrollContainer(e) {
|
|
2276
2408
|
let t = e;
|
|
2277
2409
|
for (; t; ) {
|
|
2278
|
-
const
|
|
2279
|
-
if ((
|
|
2410
|
+
const n = window.getComputedStyle(t).overflowY;
|
|
2411
|
+
if ((n === "auto" || n === "scroll") && t.scrollHeight > t.clientHeight)
|
|
2280
2412
|
return t;
|
|
2281
2413
|
t = t.parentElement;
|
|
2282
2414
|
}
|
|
2283
2415
|
return null;
|
|
2284
2416
|
}
|
|
2285
2417
|
resolveScrollContainer(e) {
|
|
2286
|
-
var
|
|
2287
|
-
const t = (
|
|
2288
|
-
return
|
|
2418
|
+
var n, s;
|
|
2419
|
+
const t = (n = this.editor) == null ? void 0 : n.getView(), i = ((s = t == null ? void 0 : t.getScrollElement) == null ? void 0 : s.call(t)) || null;
|
|
2420
|
+
return i && this.canScroll(i) ? i : this.findScrollContainer(e);
|
|
2289
2421
|
}
|
|
2290
2422
|
canScroll(e) {
|
|
2291
2423
|
return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
|
|
@@ -2299,123 +2431,122 @@ const K = class y {
|
|
|
2299
2431
|
applyCustomHighlights() {
|
|
2300
2432
|
if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
|
|
2301
2433
|
return;
|
|
2302
|
-
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines:
|
|
2303
|
-
if (
|
|
2304
|
-
const r = this.buildVisibleDocumentText(
|
|
2434
|
+
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines: n } = this.buildLineStarts(t), s = this.buildTextNodeIndex(e);
|
|
2435
|
+
if (s.length === 0) return;
|
|
2436
|
+
const r = this.buildVisibleDocumentText(s), o = [];
|
|
2305
2437
|
let l = null;
|
|
2306
2438
|
const a = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
|
|
2307
2439
|
for (let h = 0; h < a; h++) {
|
|
2308
|
-
const
|
|
2309
|
-
|
|
2440
|
+
const c = this.currentResults[h], d = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, f = this.toDomRange(
|
|
2441
|
+
c.range,
|
|
2310
2442
|
i,
|
|
2311
|
-
s,
|
|
2312
2443
|
n,
|
|
2444
|
+
s,
|
|
2313
2445
|
r,
|
|
2314
|
-
|
|
2446
|
+
d
|
|
2315
2447
|
);
|
|
2316
|
-
|
|
2448
|
+
f && (o.push(f), h === this.currentIndex && (l = f));
|
|
2317
2449
|
}
|
|
2318
2450
|
if (o.length !== 0)
|
|
2319
2451
|
try {
|
|
2320
|
-
const h = CSS,
|
|
2321
|
-
if (!h.highlights || !
|
|
2322
|
-
h.highlights.set(this.highlightMatchName, new
|
|
2452
|
+
const h = CSS, c = window.Highlight;
|
|
2453
|
+
if (!h.highlights || !c) return;
|
|
2454
|
+
h.highlights.set(this.highlightMatchName, new c(...o)), l && h.highlights.set(this.highlightActiveName, new c(l));
|
|
2323
2455
|
} catch (h) {
|
|
2324
2456
|
}
|
|
2325
2457
|
}
|
|
2326
2458
|
buildLineStarts(e) {
|
|
2327
2459
|
const t = e.split(`
|
|
2328
2460
|
`), i = new Array(t.length);
|
|
2329
|
-
let
|
|
2330
|
-
for (let
|
|
2331
|
-
i[
|
|
2461
|
+
let n = 0;
|
|
2462
|
+
for (let s = 0; s < t.length; s++)
|
|
2463
|
+
i[s] = n, n += t[s].length + 1;
|
|
2332
2464
|
return { lineStarts: i, lines: t };
|
|
2333
2465
|
}
|
|
2334
2466
|
positionToOffset(e, t, i) {
|
|
2335
2467
|
var r;
|
|
2336
|
-
const
|
|
2337
|
-
return t[
|
|
2468
|
+
const n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(0, Math.min(e.column, ((r = i[n]) == null ? void 0 : r.length) || 0));
|
|
2469
|
+
return t[n] + s;
|
|
2338
2470
|
}
|
|
2339
2471
|
buildTextNodeIndex(e) {
|
|
2340
|
-
var r;
|
|
2341
2472
|
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
|
|
2342
|
-
let
|
|
2343
|
-
for (;
|
|
2344
|
-
const o =
|
|
2345
|
-
if (
|
|
2473
|
+
let n = 0, s;
|
|
2474
|
+
for (; s = t.nextNode(); ) {
|
|
2475
|
+
const r = s, o = r.parentElement;
|
|
2476
|
+
if (o != null && o.hasAttribute(this.trailingMarkerAttr))
|
|
2346
2477
|
continue;
|
|
2347
|
-
const l =
|
|
2478
|
+
const l = r.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
|
|
2348
2479
|
h === 0 && l.length === 0 || (i.push({
|
|
2349
|
-
node:
|
|
2350
|
-
start:
|
|
2351
|
-
end:
|
|
2480
|
+
node: r,
|
|
2481
|
+
start: n,
|
|
2482
|
+
end: n + h,
|
|
2352
2483
|
visibleToDom: a
|
|
2353
|
-
}),
|
|
2484
|
+
}), n += h);
|
|
2354
2485
|
}
|
|
2355
2486
|
return i;
|
|
2356
2487
|
}
|
|
2357
2488
|
resolveDomPoint(e, t) {
|
|
2358
|
-
var
|
|
2489
|
+
var s, r, o, l, a, h;
|
|
2359
2490
|
const i = Math.max(0, e);
|
|
2360
|
-
for (let
|
|
2361
|
-
const
|
|
2362
|
-
if (i <=
|
|
2363
|
-
const
|
|
2491
|
+
for (let c = 0; c < t.length; c++) {
|
|
2492
|
+
const d = t[c];
|
|
2493
|
+
if (i <= d.end) {
|
|
2494
|
+
const f = Math.max(0, i - d.start), u = (o = (r = d.visibleToDom[f]) != null ? r : (s = d.node.textContent) == null ? void 0 : s.length) != null ? o : 0;
|
|
2364
2495
|
return {
|
|
2365
|
-
node:
|
|
2366
|
-
offset:
|
|
2496
|
+
node: d.node,
|
|
2497
|
+
offset: u
|
|
2367
2498
|
};
|
|
2368
2499
|
}
|
|
2369
2500
|
}
|
|
2370
|
-
const
|
|
2371
|
-
return
|
|
2372
|
-
node:
|
|
2373
|
-
offset: (h = (a =
|
|
2501
|
+
const n = t[t.length - 1];
|
|
2502
|
+
return n ? {
|
|
2503
|
+
node: n.node,
|
|
2504
|
+
offset: (h = (a = n.visibleToDom[n.visibleToDom.length - 1]) != null ? a : (l = n.node.textContent) == null ? void 0 : l.length) != null ? h : 0
|
|
2374
2505
|
} : null;
|
|
2375
2506
|
}
|
|
2376
|
-
toDomRange(e, t, i,
|
|
2507
|
+
toDomRange(e, t, i, n, s, r) {
|
|
2377
2508
|
const o = this.positionToOffset(e.start, t, i), l = this.positionToOffset(e.end, t, i);
|
|
2378
2509
|
let a = Math.min(o, l), h = Math.max(o, l);
|
|
2379
|
-
if (
|
|
2380
|
-
const
|
|
2381
|
-
if (
|
|
2510
|
+
if (s && r) {
|
|
2511
|
+
const u = r, g = s.slice(a, h);
|
|
2512
|
+
if (g.length === u.length && g.toLowerCase() !== u.toLowerCase()) {
|
|
2382
2513
|
const p = this.findNearestMatchOffset(
|
|
2383
|
-
|
|
2384
|
-
|
|
2514
|
+
s,
|
|
2515
|
+
u,
|
|
2385
2516
|
a
|
|
2386
2517
|
);
|
|
2387
|
-
p !== -1 && (a = p, h = p +
|
|
2518
|
+
p !== -1 && (a = p, h = p + u.length);
|
|
2388
2519
|
}
|
|
2389
2520
|
}
|
|
2390
|
-
const
|
|
2391
|
-
if (!
|
|
2392
|
-
const
|
|
2521
|
+
const c = this.resolveDomPoint(a, n), d = this.resolveDomPoint(h, n);
|
|
2522
|
+
if (!c || !d) return null;
|
|
2523
|
+
const f = document.createRange();
|
|
2393
2524
|
try {
|
|
2394
|
-
return
|
|
2395
|
-
} catch (
|
|
2525
|
+
return f.setStart(c.node, c.offset), f.setEnd(d.node, d.offset), f;
|
|
2526
|
+
} catch (u) {
|
|
2396
2527
|
return null;
|
|
2397
2528
|
}
|
|
2398
2529
|
}
|
|
2399
2530
|
buildVisibleDocumentText(e) {
|
|
2400
2531
|
let t = "";
|
|
2401
2532
|
for (let i = 0; i < e.length; i++) {
|
|
2402
|
-
const
|
|
2403
|
-
for (let
|
|
2404
|
-
const r = s
|
|
2533
|
+
const n = e[i].node.textContent || "";
|
|
2534
|
+
for (let s = 0; s < n.length; s++) {
|
|
2535
|
+
const r = n[s];
|
|
2405
2536
|
this.virtualMarkerRegex.test(r) || (t += r);
|
|
2406
2537
|
}
|
|
2407
2538
|
}
|
|
2408
2539
|
return t;
|
|
2409
2540
|
}
|
|
2410
2541
|
findNearestMatchOffset(e, t, i) {
|
|
2411
|
-
const
|
|
2412
|
-
let
|
|
2413
|
-
if (
|
|
2414
|
-
let r =
|
|
2415
|
-
for (;
|
|
2416
|
-
const l = Math.abs(
|
|
2417
|
-
if (l < o && (o = l, r =
|
|
2418
|
-
|
|
2542
|
+
const n = t.toLowerCase();
|
|
2543
|
+
let s = e.toLowerCase().indexOf(n);
|
|
2544
|
+
if (s === -1) return -1;
|
|
2545
|
+
let r = s, o = Math.abs(s - i);
|
|
2546
|
+
for (; s !== -1; ) {
|
|
2547
|
+
const l = Math.abs(s - i);
|
|
2548
|
+
if (l < o && (o = l, r = s), l === 0) return s;
|
|
2549
|
+
s = e.toLowerCase().indexOf(n, s + 1);
|
|
2419
2550
|
}
|
|
2420
2551
|
return r;
|
|
2421
2552
|
}
|
|
@@ -2477,9 +2608,9 @@ const K = class y {
|
|
|
2477
2608
|
buildVisibleToDomMap(e) {
|
|
2478
2609
|
const t = [0];
|
|
2479
2610
|
let i = 0;
|
|
2480
|
-
for (let
|
|
2481
|
-
const
|
|
2482
|
-
this.virtualMarkerRegex.test(
|
|
2611
|
+
for (let n = 0; n < e.length; n++) {
|
|
2612
|
+
const s = e[n];
|
|
2613
|
+
this.virtualMarkerRegex.test(s) || (i += 1, t[i] = n + 1);
|
|
2483
2614
|
}
|
|
2484
2615
|
return t;
|
|
2485
2616
|
}
|
|
@@ -2503,7 +2634,7 @@ const K = class y {
|
|
|
2503
2634
|
e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
|
|
2504
2635
|
}
|
|
2505
2636
|
};
|
|
2506
|
-
|
|
2637
|
+
x.css = {
|
|
2507
2638
|
root: "lce-search-ui",
|
|
2508
2639
|
row: "lce-search-row",
|
|
2509
2640
|
options: "lce-search-options",
|
|
@@ -2526,8 +2657,8 @@ K.css = {
|
|
|
2526
2657
|
mode: "search-mode",
|
|
2527
2658
|
modeLayout: "lce-search-mode"
|
|
2528
2659
|
};
|
|
2529
|
-
let
|
|
2530
|
-
class
|
|
2660
|
+
let U = x, se = 0;
|
|
2661
|
+
class re {
|
|
2531
2662
|
constructor() {
|
|
2532
2663
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
2533
2664
|
"(": ")",
|
|
@@ -2539,7 +2670,7 @@ class le {
|
|
|
2539
2670
|
"]": "[",
|
|
2540
2671
|
"}": "{",
|
|
2541
2672
|
">": "<"
|
|
2542
|
-
}, this.highlightId = ++
|
|
2673
|
+
}, this.highlightId = ++se, this.highlightName = `editora-bracket-match-${this.highlightId}`, this.highlightStyleId = `editora-bracket-match-style-${this.highlightId}`, this.currentMatch = null, this.hasCustomHighlightSupport = !1, this.observer = null, this.pendingUpdateRaf = null, this.updateRequestVersion = 0, this.cursorHandler = null, this.changeHandler = null;
|
|
2543
2674
|
}
|
|
2544
2675
|
setup(e) {
|
|
2545
2676
|
this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && (this.ensureHighlightStyles(), this.observeContentMutations()), this.cursorHandler = () => {
|
|
@@ -2569,17 +2700,17 @@ class le {
|
|
|
2569
2700
|
this.clearBracketHighlighting();
|
|
2570
2701
|
const i = this.getBracketNearPosition(t, e.position);
|
|
2571
2702
|
if (!i) return;
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2703
|
+
const n = this.findMatchingBracket(t, i);
|
|
2704
|
+
n && (this.currentMatch = n, this.highlightBrackets(n));
|
|
2574
2705
|
}
|
|
2575
2706
|
getBracketNearPosition(e, t) {
|
|
2576
2707
|
const i = e.split(`
|
|
2577
2708
|
`);
|
|
2578
2709
|
if (t.line < 0 || t.line >= i.length) return null;
|
|
2579
|
-
const
|
|
2580
|
-
t.column > 0 &&
|
|
2581
|
-
for (const
|
|
2582
|
-
const r = this.getBracketAtPosition(i,
|
|
2710
|
+
const n = [{ line: t.line, column: t.column }];
|
|
2711
|
+
t.column > 0 && n.push({ line: t.line, column: t.column - 1 });
|
|
2712
|
+
for (const s of n) {
|
|
2713
|
+
const r = this.getBracketAtPosition(i, s);
|
|
2583
2714
|
if (r)
|
|
2584
2715
|
return r;
|
|
2585
2716
|
}
|
|
@@ -2589,47 +2720,47 @@ class le {
|
|
|
2589
2720
|
if (t.line < 0 || t.line >= e.length) return null;
|
|
2590
2721
|
const i = e[t.line];
|
|
2591
2722
|
if (t.column < 0 || t.column >= i.length) return null;
|
|
2592
|
-
const
|
|
2593
|
-
return this.bracketPairs[
|
|
2723
|
+
const n = i[t.column];
|
|
2724
|
+
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
|
|
2594
2725
|
}
|
|
2595
2726
|
findMatchingBracket(e, t) {
|
|
2596
2727
|
const i = e.split(`
|
|
2597
|
-
`),
|
|
2598
|
-
return this.bracketPairs[r] ? this.findClosingBracket(i,
|
|
2728
|
+
`), n = t.position.line, s = t.position.column, r = t.char;
|
|
2729
|
+
return this.bracketPairs[r] ? this.findClosingBracket(i, n, s, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(i, n, s, r) : null;
|
|
2599
2730
|
}
|
|
2600
|
-
findClosingBracket(e, t, i,
|
|
2601
|
-
const
|
|
2731
|
+
findClosingBracket(e, t, i, n) {
|
|
2732
|
+
const s = this.bracketPairs[n];
|
|
2602
2733
|
let r = 0;
|
|
2603
2734
|
for (let o = t; o < e.length; o++) {
|
|
2604
2735
|
const l = e[o], a = o === t ? i : 0;
|
|
2605
2736
|
for (let h = a; h < l.length; h++) {
|
|
2606
|
-
const
|
|
2607
|
-
if (
|
|
2737
|
+
const c = l[h];
|
|
2738
|
+
if (c === n)
|
|
2608
2739
|
r++;
|
|
2609
|
-
else if (
|
|
2740
|
+
else if (c === s && (r--, r === 0))
|
|
2610
2741
|
return {
|
|
2611
2742
|
open: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
|
|
2612
2743
|
close: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
|
|
2613
|
-
type:
|
|
2744
|
+
type: n
|
|
2614
2745
|
};
|
|
2615
2746
|
}
|
|
2616
2747
|
}
|
|
2617
2748
|
return null;
|
|
2618
2749
|
}
|
|
2619
|
-
findOpeningBracket(e, t, i,
|
|
2620
|
-
const
|
|
2750
|
+
findOpeningBracket(e, t, i, n) {
|
|
2751
|
+
const s = this.reverseBracketPairs[n];
|
|
2621
2752
|
let r = 0;
|
|
2622
2753
|
for (let o = t; o >= 0; o--) {
|
|
2623
2754
|
const l = e[o], a = o === t ? i : l.length - 1;
|
|
2624
2755
|
for (let h = a; h >= 0; h--) {
|
|
2625
|
-
const
|
|
2626
|
-
if (
|
|
2756
|
+
const c = l[h];
|
|
2757
|
+
if (c === n)
|
|
2627
2758
|
r++;
|
|
2628
|
-
else if (
|
|
2759
|
+
else if (c === s && (r--, r === 0))
|
|
2629
2760
|
return {
|
|
2630
2761
|
open: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
|
|
2631
2762
|
close: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
|
|
2632
|
-
type:
|
|
2763
|
+
type: s
|
|
2633
2764
|
};
|
|
2634
2765
|
}
|
|
2635
2766
|
}
|
|
@@ -2637,13 +2768,13 @@ class le {
|
|
|
2637
2768
|
}
|
|
2638
2769
|
highlightBrackets(e) {
|
|
2639
2770
|
if (!this.editor || !this.hasCustomHighlightSupport) return;
|
|
2640
|
-
const t = this.editor.getView(), i = t.createDomRangeFromRange(e.open),
|
|
2641
|
-
if (!(!i || !
|
|
2771
|
+
const t = this.editor.getView(), i = t.createDomRangeFromRange(e.open), n = t.createDomRangeFromRange(e.close);
|
|
2772
|
+
if (!(!i || !n))
|
|
2642
2773
|
try {
|
|
2643
|
-
const
|
|
2644
|
-
if (!
|
|
2645
|
-
|
|
2646
|
-
} catch (
|
|
2774
|
+
const s = CSS, r = window.Highlight;
|
|
2775
|
+
if (!s.highlights || !r) return;
|
|
2776
|
+
s.highlights.set(this.highlightName, new r(i, n));
|
|
2777
|
+
} catch (s) {
|
|
2647
2778
|
}
|
|
2648
2779
|
}
|
|
2649
2780
|
clearBracketHighlighting() {
|
|
@@ -2655,7 +2786,7 @@ class le {
|
|
|
2655
2786
|
}
|
|
2656
2787
|
}
|
|
2657
2788
|
observeContentMutations() {
|
|
2658
|
-
if (!this.editor || typeof MutationObserver
|
|
2789
|
+
if (!this.editor || typeof MutationObserver == "undefined") return;
|
|
2659
2790
|
const e = this.editor.getView().getContentElement();
|
|
2660
2791
|
this.observer = new MutationObserver(() => {
|
|
2661
2792
|
this.clearBracketHighlighting(), this.scheduleBracketUpdate();
|
|
@@ -2667,7 +2798,7 @@ class le {
|
|
|
2667
2798
|
}
|
|
2668
2799
|
detectCustomHighlightSupport() {
|
|
2669
2800
|
try {
|
|
2670
|
-
if (typeof CSS
|
|
2801
|
+
if (typeof CSS == "undefined" || typeof window == "undefined")
|
|
2671
2802
|
return !1;
|
|
2672
2803
|
const e = CSS, t = window.Highlight;
|
|
2673
2804
|
return !!e.highlights && !!t;
|
|
@@ -2676,7 +2807,7 @@ class le {
|
|
|
2676
2807
|
}
|
|
2677
2808
|
}
|
|
2678
2809
|
ensureHighlightStyles() {
|
|
2679
|
-
if (typeof document
|
|
2810
|
+
if (typeof document == "undefined" || document.getElementById(this.highlightStyleId)) return;
|
|
2680
2811
|
const e = document.createElement("style");
|
|
2681
2812
|
e.id = this.highlightStyleId, e.textContent = `
|
|
2682
2813
|
::highlight(${this.highlightName}) {
|
|
@@ -2690,14 +2821,14 @@ class le {
|
|
|
2690
2821
|
}
|
|
2691
2822
|
destroy() {
|
|
2692
2823
|
var e;
|
|
2693
|
-
if (this.pendingUpdateRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.clearBracketHighlighting(), (e = this.observer) == null || e.disconnect(), this.observer = null, this.editor && this.cursorHandler && this.editor.off("cursor", this.cursorHandler), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), typeof document
|
|
2824
|
+
if (this.pendingUpdateRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.clearBracketHighlighting(), (e = this.observer) == null || e.disconnect(), this.observer = null, this.editor && this.cursorHandler && this.editor.off("cursor", this.cursorHandler), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), typeof document != "undefined") {
|
|
2694
2825
|
const t = document.getElementById(this.highlightStyleId);
|
|
2695
2826
|
t != null && t.parentNode && t.parentNode.removeChild(t);
|
|
2696
2827
|
}
|
|
2697
2828
|
this.cursorHandler = null, this.changeHandler = null, this.editor = null;
|
|
2698
2829
|
}
|
|
2699
2830
|
}
|
|
2700
|
-
class
|
|
2831
|
+
class oe {
|
|
2701
2832
|
constructor() {
|
|
2702
2833
|
this.name = "code-folding", this.lineHeight = 21, this.voidMarkupTags = /* @__PURE__ */ new Set([
|
|
2703
2834
|
"area",
|
|
@@ -2797,14 +2928,14 @@ class ae {
|
|
|
2797
2928
|
const e = this.editor.getValue(), t = this.getActiveFolds().map((r) => this.getFoldKey(r)).join("|"), i = `${e}::${t}`;
|
|
2798
2929
|
if (i === this.lastSnapshot) return;
|
|
2799
2930
|
this.lastSnapshot = i, this.foldingUI.innerHTML = "";
|
|
2800
|
-
const
|
|
2931
|
+
const n = this.getRenderableActiveFolds(), s = document.createDocumentFragment();
|
|
2801
2932
|
for (const r of this.foldRegions) {
|
|
2802
|
-
const o = this.toDisplayLine(r,
|
|
2933
|
+
const o = this.toDisplayLine(r, n);
|
|
2803
2934
|
if (o === null) continue;
|
|
2804
2935
|
const l = this.isFoldActive(r), a = this.createFoldIndicator(r, o, l);
|
|
2805
|
-
|
|
2936
|
+
s.appendChild(a);
|
|
2806
2937
|
}
|
|
2807
|
-
this.foldingUI.appendChild(
|
|
2938
|
+
this.foldingUI.appendChild(s);
|
|
2808
2939
|
}
|
|
2809
2940
|
buildFoldRegions(e) {
|
|
2810
2941
|
const t = this.buildBracketFoldRegions(e), i = this.shouldIncludeMarkupFolds(e) ? this.buildMarkupFoldRegions(e) : [];
|
|
@@ -2813,7 +2944,7 @@ class ae {
|
|
|
2813
2944
|
buildBracketFoldRegions(e) {
|
|
2814
2945
|
var o;
|
|
2815
2946
|
const t = e.split(`
|
|
2816
|
-
`), i = [],
|
|
2947
|
+
`), i = [], n = [], s = {
|
|
2817
2948
|
"{": "}",
|
|
2818
2949
|
"[": "]",
|
|
2819
2950
|
"(": ")"
|
|
@@ -2825,38 +2956,38 @@ class ae {
|
|
|
2825
2956
|
for (let l = 0; l < t.length; l++) {
|
|
2826
2957
|
const a = t[l];
|
|
2827
2958
|
for (let h = 0; h < a.length; h++) {
|
|
2828
|
-
const
|
|
2829
|
-
if (
|
|
2830
|
-
i.push({ char:
|
|
2959
|
+
const c = a[h];
|
|
2960
|
+
if (s[c]) {
|
|
2961
|
+
i.push({ char: c, line: l, column: h });
|
|
2831
2962
|
continue;
|
|
2832
2963
|
}
|
|
2833
|
-
const
|
|
2834
|
-
if (!
|
|
2835
|
-
let
|
|
2964
|
+
const d = r[c];
|
|
2965
|
+
if (!d) continue;
|
|
2966
|
+
let f = -1;
|
|
2836
2967
|
for (let m = i.length - 1; m >= 0; m--)
|
|
2837
|
-
if (i[m].char ===
|
|
2838
|
-
|
|
2968
|
+
if (i[m].char === d) {
|
|
2969
|
+
f = m;
|
|
2839
2970
|
break;
|
|
2840
2971
|
}
|
|
2841
|
-
if (
|
|
2842
|
-
const
|
|
2843
|
-
if (
|
|
2844
|
-
const
|
|
2845
|
-
start: { line:
|
|
2972
|
+
if (f === -1) continue;
|
|
2973
|
+
const u = i.splice(f, 1)[0];
|
|
2974
|
+
if (u.line >= l) continue;
|
|
2975
|
+
const g = ((o = t[u.line]) == null ? void 0 : o.length) || 0, p = {
|
|
2976
|
+
start: { line: u.line, column: g },
|
|
2846
2977
|
end: { line: l, column: 0 },
|
|
2847
2978
|
collapsed: !1,
|
|
2848
|
-
level:
|
|
2979
|
+
level: f
|
|
2849
2980
|
};
|
|
2850
|
-
this.isValidFoldRegion(p) &&
|
|
2981
|
+
this.isValidFoldRegion(p) && n.push(p);
|
|
2851
2982
|
}
|
|
2852
2983
|
}
|
|
2853
|
-
return
|
|
2984
|
+
return n.sort((l, a) => l.start.line !== a.start.line ? l.start.line - a.start.line : l.end.line !== a.end.line ? l.end.line - a.end.line : l.start.column - a.start.column), n;
|
|
2854
2985
|
}
|
|
2855
2986
|
shouldIncludeMarkupFolds(e) {
|
|
2856
2987
|
return /<!DOCTYPE\b/i.test(e) || /<[A-Za-z][\w:-]*(?:\s|>)/.test(e) && /<\/[A-Za-z][\w:-]*\s*>/.test(e);
|
|
2857
2988
|
}
|
|
2858
2989
|
buildMarkupFoldRegions(e) {
|
|
2859
|
-
const { lineStarts: t, lines: i } = this.buildLineStarts(e),
|
|
2990
|
+
const { lineStarts: t, lines: i } = this.buildLineStarts(e), n = [], s = [];
|
|
2860
2991
|
let r = 0;
|
|
2861
2992
|
for (; r < e.length; ) {
|
|
2862
2993
|
if (e[r] !== "<") {
|
|
@@ -2879,15 +3010,15 @@ class ae {
|
|
|
2879
3010
|
continue;
|
|
2880
3011
|
}
|
|
2881
3012
|
if (r = o.endOffset, o.isClosing) {
|
|
2882
|
-
const l =
|
|
3013
|
+
const l = s.findIndex((c) => c.name === o.name);
|
|
2883
3014
|
if (l === -1)
|
|
2884
3015
|
continue;
|
|
2885
|
-
const a =
|
|
3016
|
+
const a = s.splice(l, 1)[0], h = this.createMarkupFoldRegion(
|
|
2886
3017
|
a.openEndLine,
|
|
2887
3018
|
o.startLine,
|
|
2888
3019
|
i
|
|
2889
3020
|
);
|
|
2890
|
-
h &&
|
|
3021
|
+
h && n.push(h);
|
|
2891
3022
|
continue;
|
|
2892
3023
|
}
|
|
2893
3024
|
if (!(o.isSelfClosing || this.voidMarkupTags.has(o.name))) {
|
|
@@ -2905,25 +3036,25 @@ class ae {
|
|
|
2905
3036
|
l.startLine,
|
|
2906
3037
|
i
|
|
2907
3038
|
);
|
|
2908
|
-
a &&
|
|
3039
|
+
a && n.push(a), r = l.endOffset;
|
|
2909
3040
|
}
|
|
2910
3041
|
continue;
|
|
2911
3042
|
}
|
|
2912
|
-
this.nonFoldableInlineMarkupTags.has(o.name) ||
|
|
3043
|
+
this.nonFoldableInlineMarkupTags.has(o.name) || s.unshift({
|
|
2913
3044
|
name: o.name,
|
|
2914
3045
|
openEndLine: o.endLine
|
|
2915
3046
|
});
|
|
2916
3047
|
}
|
|
2917
3048
|
}
|
|
2918
|
-
return
|
|
3049
|
+
return n;
|
|
2919
3050
|
}
|
|
2920
|
-
parseMarkupTag(e, t, i,
|
|
3051
|
+
parseMarkupTag(e, t, i, n) {
|
|
2921
3052
|
if (e[t] !== "<")
|
|
2922
3053
|
return null;
|
|
2923
|
-
const
|
|
2924
|
-
if (!
|
|
3054
|
+
const s = e[t + 1];
|
|
3055
|
+
if (!s || s !== "/" && !/[A-Za-z]/.test(s))
|
|
2925
3056
|
return null;
|
|
2926
|
-
const r =
|
|
3057
|
+
const r = s === "/";
|
|
2927
3058
|
let o = t + (r ? 2 : 1);
|
|
2928
3059
|
const l = o;
|
|
2929
3060
|
for (; o < e.length && /[A-Za-z0-9:-]/.test(e[o]); )
|
|
@@ -2933,39 +3064,39 @@ class ae {
|
|
|
2933
3064
|
return null;
|
|
2934
3065
|
let h = null;
|
|
2935
3066
|
for (; o < e.length; ) {
|
|
2936
|
-
const
|
|
3067
|
+
const g = e[o];
|
|
2937
3068
|
if (h) {
|
|
2938
|
-
|
|
3069
|
+
g === h && (h = null), o += 1;
|
|
2939
3070
|
continue;
|
|
2940
3071
|
}
|
|
2941
|
-
if (
|
|
2942
|
-
h =
|
|
3072
|
+
if (g === '"' || g === "'") {
|
|
3073
|
+
h = g, o += 1;
|
|
2943
3074
|
continue;
|
|
2944
3075
|
}
|
|
2945
|
-
if (
|
|
3076
|
+
if (g === ">")
|
|
2946
3077
|
break;
|
|
2947
3078
|
o += 1;
|
|
2948
3079
|
}
|
|
2949
3080
|
if (o >= e.length || e[o] !== ">")
|
|
2950
3081
|
return null;
|
|
2951
|
-
const
|
|
2952
|
-
if (!
|
|
3082
|
+
const c = e.slice(l, a).toLowerCase();
|
|
3083
|
+
if (!c)
|
|
2953
3084
|
return null;
|
|
2954
|
-
const
|
|
3085
|
+
const d = e.slice(t, o + 1), f = this.offsetToLine(t, i, n), u = this.offsetToLine(o, i, n);
|
|
2955
3086
|
return {
|
|
2956
|
-
name:
|
|
3087
|
+
name: c,
|
|
2957
3088
|
isClosing: r,
|
|
2958
|
-
isSelfClosing: !r && /\/\s*>$/.test(
|
|
2959
|
-
startLine:
|
|
2960
|
-
endLine:
|
|
3089
|
+
isSelfClosing: !r && /\/\s*>$/.test(d),
|
|
3090
|
+
startLine: f,
|
|
3091
|
+
endLine: u,
|
|
2961
3092
|
endOffset: o + 1
|
|
2962
3093
|
};
|
|
2963
3094
|
}
|
|
2964
|
-
findClosingMarkupTag(e, t, i,
|
|
3095
|
+
findClosingMarkupTag(e, t, i, n, s) {
|
|
2965
3096
|
const r = `</${i}`, o = e.toLowerCase();
|
|
2966
3097
|
let l = o.indexOf(r, t);
|
|
2967
3098
|
for (; l !== -1; ) {
|
|
2968
|
-
const a = this.parseMarkupTag(e, l,
|
|
3099
|
+
const a = this.parseMarkupTag(e, l, n, s);
|
|
2969
3100
|
if (a && a.isClosing && a.name === i)
|
|
2970
3101
|
return {
|
|
2971
3102
|
startLine: a.startLine,
|
|
@@ -2979,13 +3110,13 @@ class ae {
|
|
|
2979
3110
|
var o;
|
|
2980
3111
|
if (e >= t)
|
|
2981
3112
|
return null;
|
|
2982
|
-
const
|
|
3113
|
+
const n = Math.max(0, Math.min(e, i.length - 1)), s = Math.max(0, Math.min(t, i.length - 1)), r = {
|
|
2983
3114
|
start: {
|
|
2984
|
-
line:
|
|
2985
|
-
column: ((o = i[
|
|
3115
|
+
line: n,
|
|
3116
|
+
column: ((o = i[n]) == null ? void 0 : o.length) || 0
|
|
2986
3117
|
},
|
|
2987
3118
|
end: {
|
|
2988
|
-
line:
|
|
3119
|
+
line: s,
|
|
2989
3120
|
column: 0
|
|
2990
3121
|
},
|
|
2991
3122
|
collapsed: !1,
|
|
@@ -2997,11 +3128,11 @@ class ae {
|
|
|
2997
3128
|
const t = /* @__PURE__ */ new Map();
|
|
2998
3129
|
for (const i of e)
|
|
2999
3130
|
this.isValidFoldRegion(i) && t.set(this.getFoldKey(i), i);
|
|
3000
|
-
return [...t.values()].sort((i,
|
|
3131
|
+
return [...t.values()].sort((i, n) => i.start.line !== n.start.line ? i.start.line - n.start.line : i.end.line !== n.end.line ? i.end.line - n.end.line : i.start.column - n.start.column);
|
|
3001
3132
|
}
|
|
3002
3133
|
createFoldIndicator(e, t, i) {
|
|
3003
|
-
const
|
|
3004
|
-
return
|
|
3134
|
+
const n = document.createElement("button");
|
|
3135
|
+
return n.type = "button", n.style.cssText = `
|
|
3005
3136
|
position: absolute;
|
|
3006
3137
|
left: 0;
|
|
3007
3138
|
top: ${t * this.lineHeight}px;
|
|
@@ -3018,11 +3149,11 @@ class ae {
|
|
|
3018
3149
|
padding: 0;
|
|
3019
3150
|
font-size: 10px;
|
|
3020
3151
|
user-select: none;
|
|
3021
|
-
`,
|
|
3022
|
-
|
|
3023
|
-
}),
|
|
3024
|
-
|
|
3025
|
-
}),
|
|
3152
|
+
`, n.textContent = i ? "▶" : "▼", n.title = i ? "Expand folded region" : "Collapse region", n.setAttribute("aria-label", n.title), n.addEventListener("mousedown", (s) => {
|
|
3153
|
+
s.preventDefault();
|
|
3154
|
+
}), n.addEventListener("click", (s) => {
|
|
3155
|
+
s.preventDefault(), s.stopPropagation(), this.toggleFold(e);
|
|
3156
|
+
}), n;
|
|
3026
3157
|
}
|
|
3027
3158
|
toggleFold(e) {
|
|
3028
3159
|
this.editor && (this.isFoldActive(e) ? this.editor.unfold(e) : this.editor.fold(e), this.syncFoldingStatePreservingScroll());
|
|
@@ -3057,14 +3188,14 @@ class ae {
|
|
|
3057
3188
|
});
|
|
3058
3189
|
}
|
|
3059
3190
|
withPreservedScroll(e) {
|
|
3060
|
-
var
|
|
3061
|
-
const t = (
|
|
3191
|
+
var s;
|
|
3192
|
+
const t = (s = this.editor) == null ? void 0 : s.getView().getScrollElement();
|
|
3062
3193
|
if (!t) {
|
|
3063
3194
|
e();
|
|
3064
3195
|
return;
|
|
3065
3196
|
}
|
|
3066
|
-
const i = t.scrollLeft,
|
|
3067
|
-
e(), this.restoreScrollPosition(t, i,
|
|
3197
|
+
const i = t.scrollLeft, n = t.scrollTop;
|
|
3198
|
+
e(), this.restoreScrollPosition(t, i, n);
|
|
3068
3199
|
}
|
|
3069
3200
|
restoreScrollPosition(e, t, i) {
|
|
3070
3201
|
e.scrollLeft = t, e.scrollTop = i, requestAnimationFrame(() => {
|
|
@@ -3098,39 +3229,39 @@ class ae {
|
|
|
3098
3229
|
this.editor.getView().setText(e);
|
|
3099
3230
|
}
|
|
3100
3231
|
buildFoldedProjection(e, t) {
|
|
3101
|
-
const { lineStarts: i, lines:
|
|
3232
|
+
const { lineStarts: i, lines: n } = this.buildLineStarts(e), s = [...t].sort((h, c) => this.comparePositions(h.start, c.start));
|
|
3102
3233
|
let r = "";
|
|
3103
3234
|
const o = [];
|
|
3104
3235
|
let l = 0;
|
|
3105
|
-
for (const h of
|
|
3106
|
-
const
|
|
3107
|
-
r +=
|
|
3236
|
+
for (const h of s) {
|
|
3237
|
+
const c = this.positionToOffset(h.start, i, n), d = this.positionToOffset(h.end, i, n), f = e.slice(l, c), u = this.getFoldPlaceholder(h), g = e.slice(c, d);
|
|
3238
|
+
r += f, r += u, f && o.push({ type: "text", text: f }), o.push({
|
|
3108
3239
|
type: "placeholder",
|
|
3109
|
-
text:
|
|
3240
|
+
text: u,
|
|
3110
3241
|
fold: h,
|
|
3111
|
-
hiddenText:
|
|
3112
|
-
}), l =
|
|
3242
|
+
hiddenText: g
|
|
3243
|
+
}), l = d;
|
|
3113
3244
|
}
|
|
3114
3245
|
const a = e.slice(l);
|
|
3115
3246
|
return r += a, a && o.push({ type: "text", text: a }), { text: r, segments: o };
|
|
3116
3247
|
}
|
|
3117
3248
|
renderFoldPlaceholders(e) {
|
|
3118
3249
|
if (!this.editor) return;
|
|
3119
|
-
const t = this.editor.getView().getContentElement(), i = /* @__PURE__ */ new Map(),
|
|
3120
|
-
for (const
|
|
3121
|
-
if (
|
|
3122
|
-
|
|
3250
|
+
const t = this.editor.getView().getContentElement(), i = /* @__PURE__ */ new Map(), n = document.createDocumentFragment();
|
|
3251
|
+
for (const s of e.segments) {
|
|
3252
|
+
if (s.type === "text") {
|
|
3253
|
+
n.appendChild(document.createTextNode(s.text));
|
|
3123
3254
|
continue;
|
|
3124
3255
|
}
|
|
3125
|
-
const r = document.createElement("span"), o = this.getFoldKey(
|
|
3126
|
-
r.setAttribute("data-lce-fold-placeholder", o), r.setAttribute("aria-label", "Folded region"), r.contentEditable = "false", i.set(o,
|
|
3256
|
+
const r = document.createElement("span"), o = this.getFoldKey(s.fold);
|
|
3257
|
+
r.setAttribute("data-lce-fold-placeholder", o), r.setAttribute("aria-label", "Folded region"), r.contentEditable = "false", i.set(o, s.hiddenText), r.style.cssText = `
|
|
3127
3258
|
cursor: text;
|
|
3128
3259
|
user-select: text;
|
|
3129
3260
|
pointer-events: auto;
|
|
3130
3261
|
white-space: pre;
|
|
3131
|
-
`, r.textContent =
|
|
3262
|
+
`, r.textContent = s.text, n.appendChild(r);
|
|
3132
3263
|
}
|
|
3133
|
-
t.replaceChildren(
|
|
3264
|
+
t.replaceChildren(n), t.__lceFoldPlaceholderSources = i, this.editor.getView().syncTrailingNewlineMarkerForText(e.text);
|
|
3134
3265
|
}
|
|
3135
3266
|
getFoldPlaceholder(e) {
|
|
3136
3267
|
const t = Math.max(1, e.end.line - e.start.line);
|
|
@@ -3138,7 +3269,7 @@ class ae {
|
|
|
3138
3269
|
}
|
|
3139
3270
|
pruneInvalidFolds(e, t) {
|
|
3140
3271
|
if (!this.editor) return;
|
|
3141
|
-
const i = this.editor.getFolds().filter((a) => a.collapsed !== !1),
|
|
3272
|
+
const i = this.editor.getFolds().filter((a) => a.collapsed !== !1), n = new Set(i.map((a) => this.getFoldKey(a))), s = [], r = /* @__PURE__ */ new Set(), o = this.getLineInfo(e);
|
|
3142
3273
|
for (const a of i) {
|
|
3143
3274
|
const h = this.findReplacementFold(
|
|
3144
3275
|
a,
|
|
@@ -3149,14 +3280,14 @@ class ae {
|
|
|
3149
3280
|
);
|
|
3150
3281
|
if (!h)
|
|
3151
3282
|
continue;
|
|
3152
|
-
const
|
|
3153
|
-
|
|
3283
|
+
const c = this.getFoldKey(h);
|
|
3284
|
+
s.push(h), r.add(c);
|
|
3154
3285
|
}
|
|
3155
|
-
const l = new Set(
|
|
3286
|
+
const l = new Set(s.map((a) => this.getFoldKey(a)));
|
|
3156
3287
|
for (const a of i)
|
|
3157
3288
|
l.has(this.getFoldKey(a)) || this.editor.unfold(a);
|
|
3158
|
-
for (const a of
|
|
3159
|
-
|
|
3289
|
+
for (const a of s)
|
|
3290
|
+
n.has(this.getFoldKey(a)) || this.editor.fold(a);
|
|
3160
3291
|
}
|
|
3161
3292
|
getActiveFolds() {
|
|
3162
3293
|
return this.editor ? this.editor.getFolds().filter((e) => e.collapsed !== !1) : [];
|
|
@@ -3168,80 +3299,80 @@ class ae {
|
|
|
3168
3299
|
return this.getTopLevelFoldRegions(this.getActiveFolds());
|
|
3169
3300
|
}
|
|
3170
3301
|
getTopLevelFoldRegions(e) {
|
|
3171
|
-
const t = [...e].sort((
|
|
3172
|
-
for (const
|
|
3173
|
-
const
|
|
3174
|
-
|
|
3302
|
+
const t = [...e].sort((n, s) => this.comparePositions(n.start, s.start)), i = [];
|
|
3303
|
+
for (const n of t) {
|
|
3304
|
+
const s = i[i.length - 1];
|
|
3305
|
+
s && this.containsRange(s, n) || i.push(n);
|
|
3175
3306
|
}
|
|
3176
3307
|
return i;
|
|
3177
3308
|
}
|
|
3178
3309
|
toDisplayLine(e, t) {
|
|
3179
3310
|
let i = 0;
|
|
3180
|
-
for (const
|
|
3181
|
-
if (this.isSameRange(
|
|
3311
|
+
for (const n of t) {
|
|
3312
|
+
if (this.isSameRange(n, e))
|
|
3182
3313
|
break;
|
|
3183
|
-
if (this.containsRange(
|
|
3314
|
+
if (this.containsRange(n, e))
|
|
3184
3315
|
return null;
|
|
3185
|
-
|
|
3316
|
+
n.end.line <= e.start.line && (i += n.end.line - n.start.line);
|
|
3186
3317
|
}
|
|
3187
3318
|
return e.start.line - i;
|
|
3188
3319
|
}
|
|
3189
3320
|
findBestRegionForLine(e, t) {
|
|
3190
|
-
const
|
|
3321
|
+
const n = (t ? this.getActiveFolds() : this.foldRegions).filter(
|
|
3191
3322
|
(s) => s.start.line <= e && s.end.line >= e
|
|
3192
3323
|
);
|
|
3193
|
-
return
|
|
3194
|
-
const
|
|
3195
|
-
return
|
|
3196
|
-
}),
|
|
3324
|
+
return n.length === 0 ? null : (n.sort((s, r) => {
|
|
3325
|
+
const o = s.end.line - s.start.line, l = r.end.line - r.start.line;
|
|
3326
|
+
return o !== l ? o - l : this.comparePositions(s.start, r.start);
|
|
3327
|
+
}), n[0]);
|
|
3197
3328
|
}
|
|
3198
|
-
findReplacementFold(e, t, i,
|
|
3329
|
+
findReplacementFold(e, t, i, n, s) {
|
|
3199
3330
|
const r = this.getFoldKey(e), o = this.foldRegions.find(
|
|
3200
|
-
(
|
|
3331
|
+
(u) => this.getFoldKey(u) === r && !i.has(r)
|
|
3201
3332
|
);
|
|
3202
3333
|
if (o)
|
|
3203
3334
|
return o;
|
|
3204
|
-
const l = e.end.line - e.start.line, a = t != null ? t : this.createFoldSnapshot(e,
|
|
3205
|
-
const
|
|
3335
|
+
const l = e.end.line - e.start.line, a = t != null ? t : this.createFoldSnapshot(e, n, s), c = this.foldRegions.filter((u) => !i.has(this.getFoldKey(u))).map((u) => {
|
|
3336
|
+
const g = this.createFoldSnapshot(u, n, s), p = a && (g == null ? void 0 : g.startLineText) === a.startLineText ? 1 : 0, m = a && (g == null ? void 0 : g.endLineText) === a.endLineText ? 1 : 0, y = a && (g == null ? void 0 : g.lineSpan) === a.lineSpan ? 1 : 0;
|
|
3206
3337
|
return {
|
|
3207
|
-
region:
|
|
3208
|
-
overlaps: this.lineRangeOverlap(e,
|
|
3209
|
-
lineDistance: Math.abs(
|
|
3338
|
+
region: u,
|
|
3339
|
+
overlaps: this.lineRangeOverlap(e, u),
|
|
3340
|
+
lineDistance: Math.abs(u.start.line - e.start.line) + Math.abs(u.end.line - e.end.line),
|
|
3210
3341
|
spanDistance: Math.abs(
|
|
3211
|
-
|
|
3342
|
+
u.end.line - u.start.line - l
|
|
3212
3343
|
),
|
|
3213
|
-
columnDistance: Math.abs(
|
|
3214
|
-
hiddenTextMatch: a && (
|
|
3215
|
-
boundaryMatchScore:
|
|
3344
|
+
columnDistance: Math.abs(u.start.column - e.start.column) + Math.abs(u.end.column - e.end.column),
|
|
3345
|
+
hiddenTextMatch: a && (g == null ? void 0 : g.hiddenText) === a.hiddenText ? 1 : 0,
|
|
3346
|
+
boundaryMatchScore: p + m + y
|
|
3216
3347
|
};
|
|
3217
|
-
}).sort((
|
|
3218
|
-
if (!
|
|
3348
|
+
}).sort((u, g) => u.hiddenTextMatch !== g.hiddenTextMatch ? g.hiddenTextMatch - u.hiddenTextMatch : u.boundaryMatchScore !== g.boundaryMatchScore ? g.boundaryMatchScore - u.boundaryMatchScore : u.overlaps !== g.overlaps ? g.overlaps - u.overlaps : u.lineDistance !== g.lineDistance ? u.lineDistance - g.lineDistance : u.spanDistance !== g.spanDistance ? u.spanDistance - g.spanDistance : u.columnDistance - g.columnDistance)[0];
|
|
3349
|
+
if (!c)
|
|
3219
3350
|
return null;
|
|
3220
|
-
const d =
|
|
3221
|
-
return !(
|
|
3351
|
+
const d = c.lineDistance <= 2 && c.spanDistance <= 1;
|
|
3352
|
+
return !(c.hiddenTextMatch === 1 || c.boundaryMatchScore >= 2) && !d ? null : c.region;
|
|
3222
3353
|
}
|
|
3223
3354
|
lineRangeOverlap(e, t) {
|
|
3224
|
-
const i = Math.max(e.start.line, t.start.line),
|
|
3225
|
-
return Math.max(0,
|
|
3355
|
+
const i = Math.max(e.start.line, t.start.line), n = Math.min(e.end.line, t.end.line);
|
|
3356
|
+
return Math.max(0, n - i);
|
|
3226
3357
|
}
|
|
3227
3358
|
rememberActiveFoldSnapshots(e) {
|
|
3228
3359
|
const t = /* @__PURE__ */ new Map(), i = this.getLineInfo(e);
|
|
3229
|
-
for (const
|
|
3230
|
-
const
|
|
3231
|
-
|
|
3360
|
+
for (const n of this.getActiveFolds()) {
|
|
3361
|
+
const s = this.createFoldSnapshot(n, e, i);
|
|
3362
|
+
s && t.set(this.getFoldKey(n), s);
|
|
3232
3363
|
}
|
|
3233
3364
|
this.foldSnapshots = t;
|
|
3234
3365
|
}
|
|
3235
3366
|
createFoldSnapshot(e, t, i = this.getLineInfo(t)) {
|
|
3236
|
-
var h,
|
|
3237
|
-
const { lineStarts:
|
|
3238
|
-
if (
|
|
3367
|
+
var h, c;
|
|
3368
|
+
const { lineStarts: n, lines: s } = i;
|
|
3369
|
+
if (s.length === 0)
|
|
3239
3370
|
return null;
|
|
3240
|
-
const r = this.positionToOffset(e.start,
|
|
3371
|
+
const r = this.positionToOffset(e.start, n, s), o = this.positionToOffset(e.end, n, s), l = Math.max(0, Math.min(e.start.line, s.length - 1)), a = Math.max(0, Math.min(e.end.line, s.length - 1));
|
|
3241
3372
|
return {
|
|
3242
3373
|
hiddenText: t.slice(r, o),
|
|
3243
|
-
startLineText: (h =
|
|
3244
|
-
endLineText: (
|
|
3374
|
+
startLineText: (h = s[l]) != null ? h : "",
|
|
3375
|
+
endLineText: (c = s[a]) != null ? c : "",
|
|
3245
3376
|
lineSpan: e.end.line - e.start.line
|
|
3246
3377
|
};
|
|
3247
3378
|
}
|
|
@@ -3251,22 +3382,22 @@ class ae {
|
|
|
3251
3382
|
e();
|
|
3252
3383
|
return;
|
|
3253
3384
|
}
|
|
3254
|
-
const t = this.editor.getView(), i = t.getContentElement(),
|
|
3385
|
+
const t = this.editor.getView(), i = t.getContentElement(), n = document.activeElement === i, s = t.getSelectionOffsets(), r = s.isInEditor;
|
|
3255
3386
|
if (e(), !r)
|
|
3256
3387
|
return;
|
|
3257
3388
|
const o = this.remapSelectionOffsetsForVisibleDisplay(
|
|
3258
|
-
(l =
|
|
3259
|
-
(a =
|
|
3389
|
+
(l = s.anchorOffset) != null ? l : s.startOffset,
|
|
3390
|
+
(a = s.focusOffset) != null ? a : s.endOffset
|
|
3260
3391
|
);
|
|
3261
3392
|
t.setSelectionBoundaryOffsets(
|
|
3262
3393
|
o.startOffset,
|
|
3263
3394
|
o.endOffset
|
|
3264
|
-
), (
|
|
3395
|
+
), (n || s.isInEditor) && this.editor.focus();
|
|
3265
3396
|
}
|
|
3266
3397
|
remapSelectionOffsetsForVisibleDisplay(e, t) {
|
|
3267
3398
|
if (!this.editor)
|
|
3268
3399
|
return { startOffset: e, endOffset: t };
|
|
3269
|
-
const i = this.editor.getValue(), { lineStarts:
|
|
3400
|
+
const i = this.editor.getValue(), { lineStarts: n, lines: s } = this.getLineInfo(i), r = this.getRenderableActiveFolds();
|
|
3270
3401
|
if (r.length === 0) {
|
|
3271
3402
|
const o = i.length;
|
|
3272
3403
|
return {
|
|
@@ -3278,36 +3409,36 @@ class ae {
|
|
|
3278
3409
|
startOffset: this.remapOffsetToVisibleBoundary(
|
|
3279
3410
|
e,
|
|
3280
3411
|
r,
|
|
3281
|
-
s,
|
|
3282
3412
|
n,
|
|
3413
|
+
s,
|
|
3283
3414
|
i.length
|
|
3284
3415
|
),
|
|
3285
3416
|
endOffset: this.remapOffsetToVisibleBoundary(
|
|
3286
3417
|
t,
|
|
3287
3418
|
r,
|
|
3288
|
-
s,
|
|
3289
3419
|
n,
|
|
3420
|
+
s,
|
|
3290
3421
|
i.length
|
|
3291
3422
|
)
|
|
3292
3423
|
};
|
|
3293
3424
|
}
|
|
3294
|
-
remapOffsetToVisibleBoundary(e, t, i,
|
|
3295
|
-
const r = Math.max(0, Math.min(e,
|
|
3425
|
+
remapOffsetToVisibleBoundary(e, t, i, n, s) {
|
|
3426
|
+
const r = Math.max(0, Math.min(e, s));
|
|
3296
3427
|
for (const o of t) {
|
|
3297
|
-
const l = this.positionToOffset(o.start, i,
|
|
3428
|
+
const l = this.positionToOffset(o.start, i, n), a = this.positionToOffset(o.end, i, n);
|
|
3298
3429
|
if (r <= l || r >= a)
|
|
3299
3430
|
continue;
|
|
3300
|
-
const h = r - l,
|
|
3301
|
-
return h <=
|
|
3431
|
+
const h = r - l, c = a - r;
|
|
3432
|
+
return h <= c ? l : a;
|
|
3302
3433
|
}
|
|
3303
3434
|
return r;
|
|
3304
3435
|
}
|
|
3305
3436
|
buildLineStarts(e) {
|
|
3306
3437
|
const t = e.split(`
|
|
3307
3438
|
`), i = new Array(t.length);
|
|
3308
|
-
let
|
|
3309
|
-
for (let
|
|
3310
|
-
i[
|
|
3439
|
+
let n = 0;
|
|
3440
|
+
for (let s = 0; s < t.length; s++)
|
|
3441
|
+
i[s] = n, n += t[s].length + 1;
|
|
3311
3442
|
return { lineStarts: i, lines: t };
|
|
3312
3443
|
}
|
|
3313
3444
|
getLineInfo(e) {
|
|
@@ -3322,15 +3453,15 @@ class ae {
|
|
|
3322
3453
|
}
|
|
3323
3454
|
offsetToLine(e, t, i) {
|
|
3324
3455
|
var l;
|
|
3325
|
-
const
|
|
3456
|
+
const n = t.length > 0 ? t[t.length - 1] + (((l = i[i.length - 1]) == null ? void 0 : l.length) || 0) : 0, s = Math.max(0, Math.min(e, n));
|
|
3326
3457
|
let r = 0, o = t.length - 1;
|
|
3327
3458
|
for (; r <= o; ) {
|
|
3328
|
-
const a = Math.floor((r + o) / 2), h = t[a],
|
|
3329
|
-
if (
|
|
3459
|
+
const a = Math.floor((r + o) / 2), h = t[a], c = a + 1 < t.length ? t[a + 1] : Number.POSITIVE_INFINITY;
|
|
3460
|
+
if (s < h) {
|
|
3330
3461
|
o = a - 1;
|
|
3331
3462
|
continue;
|
|
3332
3463
|
}
|
|
3333
|
-
if (
|
|
3464
|
+
if (s >= c) {
|
|
3334
3465
|
r = a + 1;
|
|
3335
3466
|
continue;
|
|
3336
3467
|
}
|
|
@@ -3340,8 +3471,8 @@ class ae {
|
|
|
3340
3471
|
}
|
|
3341
3472
|
positionToOffset(e, t, i) {
|
|
3342
3473
|
var r;
|
|
3343
|
-
const
|
|
3344
|
-
return t[
|
|
3474
|
+
const n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(0, Math.min(e.column, ((r = i[n]) == null ? void 0 : r.length) || 0));
|
|
3475
|
+
return t[n] + s;
|
|
3345
3476
|
}
|
|
3346
3477
|
comparePositions(e, t) {
|
|
3347
3478
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
@@ -3365,7 +3496,7 @@ class ae {
|
|
|
3365
3496
|
this.pendingUpdateRaf !== null && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.restoreFullDisplay(), this.changeHandler = null, this.lastSnapshot = "", this.lastParsedText = null, this.foldingUI = null, this.foldRegions = [], this.cachedLineInfo = null, this.editor = null;
|
|
3366
3497
|
}
|
|
3367
3498
|
}
|
|
3368
|
-
class
|
|
3499
|
+
class le {
|
|
3369
3500
|
constructor() {
|
|
3370
3501
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
3371
3502
|
}
|
|
@@ -3432,10 +3563,10 @@ class he {
|
|
|
3432
3563
|
}
|
|
3433
3564
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
3434
3565
|
highlight(e, t) {
|
|
3435
|
-
const i = this.getSyntaxColors(),
|
|
3566
|
+
const i = this.getSyntaxColors(), n = this.normalizeLanguageId(
|
|
3436
3567
|
t || this.currentLanguage || this.detectLanguage(e) || "html"
|
|
3437
3568
|
);
|
|
3438
|
-
return (this.modes.get(
|
|
3569
|
+
return (this.modes.get(n) || this.modes.get("html")).highlight(e, i);
|
|
3439
3570
|
}
|
|
3440
3571
|
// Backwards-compatible method
|
|
3441
3572
|
highlightHTML(e) {
|
|
@@ -3481,24 +3612,24 @@ class he {
|
|
|
3481
3612
|
}[t] || t || "html";
|
|
3482
3613
|
}
|
|
3483
3614
|
restoreHighlightTokens(e, t) {
|
|
3484
|
-
return e.replace(/\u0000([a-z]+)\u0000/g, (i,
|
|
3485
|
-
let
|
|
3486
|
-
for (let r = 0; r <
|
|
3487
|
-
|
|
3488
|
-
return
|
|
3615
|
+
return e.replace(/\u0000([a-z]+)\u0000/g, (i, n) => {
|
|
3616
|
+
let s = 0;
|
|
3617
|
+
for (let r = 0; r < n.length; r++)
|
|
3618
|
+
s = s * 26 + (n.charCodeAt(r) - 97 + 1);
|
|
3619
|
+
return s = s - 1, t[s] || "";
|
|
3489
3620
|
});
|
|
3490
3621
|
}
|
|
3491
3622
|
createTokenStore(e) {
|
|
3492
3623
|
const t = (i) => {
|
|
3493
|
-
let
|
|
3624
|
+
let n = "", s = i;
|
|
3494
3625
|
do
|
|
3495
|
-
|
|
3496
|
-
while (
|
|
3497
|
-
return
|
|
3626
|
+
n = String.fromCharCode(97 + s % 26) + n, s = Math.floor(s / 26) - 1;
|
|
3627
|
+
while (s >= 0);
|
|
3628
|
+
return n || "a";
|
|
3498
3629
|
};
|
|
3499
3630
|
return (i) => {
|
|
3500
|
-
const
|
|
3501
|
-
return e.push(i), `\0${t(
|
|
3631
|
+
const n = e.length;
|
|
3632
|
+
return e.push(i), `\0${t(n)}\0`;
|
|
3502
3633
|
};
|
|
3503
3634
|
}
|
|
3504
3635
|
refreshEditorHighlight() {
|
|
@@ -3509,8 +3640,8 @@ class he {
|
|
|
3509
3640
|
unescapeEntitiesRepeated(e) {
|
|
3510
3641
|
let t = e || "";
|
|
3511
3642
|
for (let i = 0; i < 5; i++) {
|
|
3512
|
-
const
|
|
3513
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
3643
|
+
const n = t;
|
|
3644
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === n) break;
|
|
3514
3645
|
}
|
|
3515
3646
|
return t;
|
|
3516
3647
|
}
|
|
@@ -3523,9 +3654,9 @@ class he {
|
|
|
3523
3654
|
if (/^[\[{]/.test(t) && /[\]}]$/.test(t) || /"[^"]+"\s*:/.test(t))
|
|
3524
3655
|
try {
|
|
3525
3656
|
return JSON.parse(t), "json";
|
|
3526
|
-
} catch (
|
|
3657
|
+
} catch (a) {
|
|
3527
3658
|
}
|
|
3528
|
-
const i = /<\/?[A-Za-z][\w:-]*(?:\s|>|\/>)/.test(t),
|
|
3659
|
+
const i = /<\/?[A-Za-z][\w:-]*(?:\s|>|\/>)/.test(t), n = /^<!DOCTYPE\s+html\b/i.test(t) || /<\/?(html|head|body|meta|title|style|script)\b/i.test(t);
|
|
3529
3660
|
if ([
|
|
3530
3661
|
/^---\s*\n[\s\S]*?\n---\s*(?:\n|$)/.test(t),
|
|
3531
3662
|
/^#{1,6}\s+\S/m.test(t),
|
|
@@ -3540,13 +3671,13 @@ class he {
|
|
|
3540
3671
|
/(^|\s)(?:\*\*|__)[^*_]+(?:\*\*|__)(?=\s|$|[.,;:!?])/m.test(t)
|
|
3541
3672
|
].filter(Boolean).length >= (i ? 2 : 1))
|
|
3542
3673
|
return "markdown";
|
|
3543
|
-
if (s)
|
|
3544
|
-
return "html";
|
|
3545
|
-
const n = this.detectProgrammingLanguage(t);
|
|
3546
3674
|
if (n)
|
|
3547
|
-
return
|
|
3548
|
-
const
|
|
3549
|
-
|
|
3675
|
+
return "html";
|
|
3676
|
+
const o = this.detectProgrammingLanguage(t);
|
|
3677
|
+
if (o)
|
|
3678
|
+
return o;
|
|
3679
|
+
const l = /[{][\s\S]*[}]/.test(t) && /[A-Za-z_-][\w-]*\s*:\s*[^;{}]+;?/.test(t) && !/\b(function|const|let|var|return|class|interface|type)\b/.test(t);
|
|
3680
|
+
return !i && l ? "css" : null;
|
|
3550
3681
|
}
|
|
3551
3682
|
detectProgrammingLanguage(e) {
|
|
3552
3683
|
const t = {
|
|
@@ -3566,155 +3697,155 @@ class he {
|
|
|
3566
3697
|
o.test(e) && (t[r] += l);
|
|
3567
3698
|
};
|
|
3568
3699
|
i("python", /^\s*(from\s+\w+\s+import|import\s+\w+|def\s+\w+\s*\(|class\s+\w+|for\s+\w+\s+in\s+.+:|if\s+.+:|while\s+.+:|print\s*\()/m, 2), i("python", /^\s*[A-Za-z_]\w*\s*=\s*(?:\[|\{|\(|["']|\d)/m), i("python", /\b(True|False|None|self|elif|lambda|yield)\b/), i("go", /^\s*package\s+\w+/m, 3), i("go", /\bfunc\s+\w+\s*\(/, 2), i("go", /\b(import|defer|goroutine|chan|struct|interface)\b/), i("cpp", /^\s*#include\s*<[^>]+>/m, 2), i("cpp", /\b(std::|template\s*<|namespace\s+\w+|cout\s*<<|cin\s*>>)\b/, 2), i("cpp", /\b(class|public|private|protected|virtual|typename)\b/), i("c", /^\s*#include\s*[<"][^>"]+[>"]/m), i("c", /\b(int|char|float|double|void)\s+\w+\s*\(/), i("c", /\bprintf\s*\(/), i("java", /^\s*(package|import)\s+[\w.]+;/m, 2), i("java", /\b(public|private|protected)\s+(class|interface|enum)\s+\w+/, 2), i("java", /\bSystem\.out\.println\s*\(/), i("csharp", /^\s*using\s+[\w.]+;/m, 2), i("csharp", /\b(namespace|record|var|string|Console\.WriteLine)\b/), i("csharp", /\b(public|private|protected)\s+(class|interface|struct)\s+\w+/), i("rust", /\bfn\s+\w+\s*\(/, 2), i("rust", /\b(let\s+mut|impl\s+\w+|use\s+[\w:]+|println!\s*\()/), i("rust", /\b(crate|trait|enum|match|Some|None|Ok|Err)\b/), i("ruby", /^\s*(def|class|module)\s+\w+/m, 2), i("ruby", /\b(puts|require|attr_reader|elsif|end)\b/), i("sql", /^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\b/im, 3), i("sql", /\bFROM\s+\w+|\bWHERE\s+/i), i("yaml", /^---\s*$/m), i("yaml", /^\s*[A-Za-z0-9_.-]+\s*:\s+\S/m, 2), i("yaml", /^\s*-\s+[A-Za-z0-9_.-]+\s*:/m), i("dockerfile", /^\s*FROM\s+\S+/im, 3), i("dockerfile", /^\s*(RUN|COPY|ADD|CMD|ENTRYPOINT|WORKDIR|ENV|ARG)\b/im, 2), i("php", /^<\?(?:php\b|=)/i, 3), i("php", /^\?php\b/i, 3), i("php", /\$[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*\s*=/, 2), i("php", /\b(echo|foreach|function|namespace|use|PHP_EOL)\b/, 2);
|
|
3569
|
-
const [
|
|
3570
|
-
return
|
|
3700
|
+
const [n, s] = Object.entries(t).sort((r, o) => o[1] - r[1])[0] || ["", 0];
|
|
3701
|
+
return s >= 2 ? n : null;
|
|
3571
3702
|
}
|
|
3572
3703
|
_highlightHTML(e, t) {
|
|
3573
|
-
const i = t,
|
|
3574
|
-
const
|
|
3575
|
-
return o.push(
|
|
3704
|
+
const i = t, n = (d) => this.escapeHTML(d), s = [], r = this.createTokenStore(s), o = [], l = (d) => {
|
|
3705
|
+
const f = o.length;
|
|
3706
|
+
return o.push(d), `ht${f}`;
|
|
3576
3707
|
};
|
|
3577
|
-
let a =
|
|
3708
|
+
let a = n(e);
|
|
3578
3709
|
a = a.replace(
|
|
3579
3710
|
/<\/?(?:(?!>)[^\n\r<])*?(?=$|[\n\r])/g,
|
|
3580
|
-
(
|
|
3711
|
+
(d) => l(d)
|
|
3581
3712
|
);
|
|
3582
3713
|
const h = [];
|
|
3583
3714
|
try {
|
|
3584
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (
|
|
3585
|
-
} catch (
|
|
3715
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (d, f, u) => (h.push({ attrs: String(f || ""), inner: String(u || "") }), d));
|
|
3716
|
+
} catch (d) {
|
|
3586
3717
|
}
|
|
3587
|
-
let
|
|
3588
|
-
return a = a.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (
|
|
3589
|
-
var
|
|
3590
|
-
const m = (
|
|
3591
|
-
(((
|
|
3592
|
-
const
|
|
3593
|
-
return `${
|
|
3594
|
-
}), a = a.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (
|
|
3595
|
-
const p = this._highlightCSS(this.unescapeEntitiesRepeated(
|
|
3596
|
-
return `${
|
|
3718
|
+
let c = 0;
|
|
3719
|
+
return a = a.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (d, f, u, g, p) => {
|
|
3720
|
+
var T, S, v;
|
|
3721
|
+
const m = (S = (T = h[c++]) == null ? void 0 : T.inner) != null ? S : this.unescapeEntitiesRepeated(g || "");
|
|
3722
|
+
(((v = h[c - 1]) == null ? void 0 : v.attrs) || u || "").toLowerCase();
|
|
3723
|
+
const y = this._highlightJS(m, i);
|
|
3724
|
+
return `${f}${y}${p}`;
|
|
3725
|
+
}), a = a.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (d, f, u, g) => {
|
|
3726
|
+
const p = this._highlightCSS(this.unescapeEntitiesRepeated(u), i);
|
|
3727
|
+
return `${f}${p}${g}`;
|
|
3597
3728
|
}), a = a.replace(
|
|
3598
3729
|
/(<!--[\s\S]*?-->)/g,
|
|
3599
|
-
(
|
|
3730
|
+
(d) => r(`<span style="color: ${i.comment};">${d}</span>`)
|
|
3600
3731
|
), a = a.replace(
|
|
3601
3732
|
/(<!DOCTYPE[\s\S]*?>)/i,
|
|
3602
|
-
(
|
|
3603
|
-
), a = a.replace(/(<\/?\s*)([^\s&>\/]+)([^<]*?)(\/?>)/g, (
|
|
3604
|
-
const m = `<span style="color: ${i.tag};">${
|
|
3605
|
-
let
|
|
3606
|
-
return
|
|
3733
|
+
(d) => r(`<span style="color: ${i.doctype};">${d}</span>`)
|
|
3734
|
+
), a = a.replace(/(<\/?\s*)([^\s&>\/]+)([^<]*?)(\/?>)/g, (d, f, u, g, p) => {
|
|
3735
|
+
const m = `<span style="color: ${i.tag};">${u}</span>`;
|
|
3736
|
+
let y = g;
|
|
3737
|
+
return y = y.replace(
|
|
3607
3738
|
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
3608
|
-
(
|
|
3609
|
-
const
|
|
3610
|
-
let
|
|
3611
|
-
|
|
3612
|
-
let
|
|
3613
|
-
if (
|
|
3614
|
-
const
|
|
3615
|
-
|
|
3739
|
+
(T, S, v, C) => {
|
|
3740
|
+
const O = String(S).toLowerCase(), $ = `<span style="color: ${i.attrName};">${S}</span>`;
|
|
3741
|
+
let I = C, M = "";
|
|
3742
|
+
C.startsWith(""") && C.endsWith(""") ? (I = C.slice(6, -6), M = """) : C.startsWith("'") && C.endsWith("'") && (I = C.slice(5, -5), M = "'");
|
|
3743
|
+
let E = C;
|
|
3744
|
+
if (O === "style") {
|
|
3745
|
+
const N = I.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (F, k, P, H) => `<span style="color: ${i.styleProp};">${k}</span>:<span style="color: ${i.styleVal};">${P}</span>${H}`);
|
|
3746
|
+
M ? E = `${M}${N}${M}` : E = N, E = `<span style="color: ${i.attrValue};">${E}</span>`;
|
|
3616
3747
|
} else
|
|
3617
|
-
|
|
3618
|
-
return `${
|
|
3748
|
+
M && (E = `${M}${I}${M}`), E = `<span style="color: ${i.attrValue};">${E}</span>`;
|
|
3749
|
+
return `${$}${v}${E}`;
|
|
3619
3750
|
}
|
|
3620
|
-
), `${
|
|
3621
|
-
}), a = a.replace(/\u0002ht(\d+)\u0002/g, (
|
|
3751
|
+
), `${f}${m}${y}${p}`;
|
|
3752
|
+
}), a = a.replace(/\u0002ht(\d+)\u0002/g, (d, f) => o[Number(f)] || ""), this.restoreHighlightTokens(a, s);
|
|
3622
3753
|
}
|
|
3623
3754
|
_highlightCSS(e, t) {
|
|
3624
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3755
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n), r = /(\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
3625
3756
|
let o = 0, l = "", a;
|
|
3626
3757
|
for (; a = r.exec(i); ) {
|
|
3627
3758
|
o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
|
|
3628
|
-
const h = a[0],
|
|
3629
|
-
l +=
|
|
3759
|
+
const h = a[0], c = h.startsWith("/*") ? t.comment : t.string;
|
|
3760
|
+
l += s(`<span style="color: ${c};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
|
|
3630
3761
|
}
|
|
3631
3762
|
return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
|
|
3632
3763
|
/(@[\w-]+)/g,
|
|
3633
|
-
(h) =>
|
|
3764
|
+
(h) => s(`<span style="color: ${t.keyword};">${h}</span>`)
|
|
3634
3765
|
), l = l.replace(
|
|
3635
3766
|
/([A-Za-z_-][\w-]*)(\s*:)/g,
|
|
3636
|
-
(h,
|
|
3767
|
+
(h, c, d) => `${s(`<span style="color: ${t.styleProp};">${c}</span>`)}${d}`
|
|
3637
3768
|
), l = l.replace(
|
|
3638
3769
|
/(#(?:[0-9a-fA-F]{3,8})\b)/g,
|
|
3639
|
-
(h) =>
|
|
3770
|
+
(h) => s(`<span style="color: ${t.number};">${h}</span>`)
|
|
3640
3771
|
), l = l.replace(
|
|
3641
3772
|
/\b(-?\d*\.?\d+(?:px|em|rem|vh|vw|vmin|vmax|%|s|ms|deg|turn|fr)?)\b/g,
|
|
3642
|
-
(h) =>
|
|
3773
|
+
(h) => s(`<span style="color: ${t.number};">${h}</span>`)
|
|
3643
3774
|
), l = l.replace(
|
|
3644
3775
|
/\b(important|inherit|initial|unset|revert|auto|none|block|inline|flex|grid|absolute|relative|fixed|sticky)\b/g,
|
|
3645
|
-
(h) =>
|
|
3646
|
-
), this.restoreHighlightTokens(l,
|
|
3776
|
+
(h) => s(`<span style="color: ${t.styleVal};">${h}</span>`)
|
|
3777
|
+
), this.restoreHighlightTokens(l, n);
|
|
3647
3778
|
}
|
|
3648
3779
|
_highlightJSON(e, t) {
|
|
3649
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3650
|
-
let
|
|
3651
|
-
for (; o =
|
|
3652
|
-
|
|
3653
|
-
const l = o[0], a = o[1], h = o[2] || "",
|
|
3780
|
+
const i = this.unescapeEntitiesRepeated(e), n = /("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}\[\],:]/g;
|
|
3781
|
+
let s = 0, r = "", o;
|
|
3782
|
+
for (; o = n.exec(i); ) {
|
|
3783
|
+
s < o.index && (r += this.escapeHTML(i.slice(s, o.index)));
|
|
3784
|
+
const l = o[0], a = o[1], h = o[2] || "", c = o[3];
|
|
3654
3785
|
if (a) {
|
|
3655
|
-
const
|
|
3656
|
-
r += `<span style="color: ${
|
|
3657
|
-
} else
|
|
3658
|
-
|
|
3786
|
+
const d = h ? t.attrName : t.string;
|
|
3787
|
+
r += `<span style="color: ${d};">${this.escapeHTML(a)}</span>${this.escapeHTML(h)}`;
|
|
3788
|
+
} else c ? 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>`;
|
|
3789
|
+
s = n.lastIndex;
|
|
3659
3790
|
}
|
|
3660
|
-
return
|
|
3791
|
+
return s < i.length && (r += this.escapeHTML(i.slice(s))), r;
|
|
3661
3792
|
}
|
|
3662
3793
|
_highlightMarkdown(e, t) {
|
|
3663
|
-
var
|
|
3664
|
-
const
|
|
3794
|
+
var a;
|
|
3795
|
+
const n = this.unescapeEntitiesRepeated(e).split(`
|
|
3665
3796
|
`);
|
|
3666
|
-
let s = !1,
|
|
3667
|
-
return
|
|
3668
|
-
const d = [],
|
|
3669
|
-
if (
|
|
3670
|
-
const
|
|
3671
|
-
return
|
|
3797
|
+
let s = !1, r = "", o = "", l = ((a = n[0]) == null ? void 0 : a.trim()) === "---";
|
|
3798
|
+
return n.map((h, c) => {
|
|
3799
|
+
const d = [], f = this.createTokenStore(d);
|
|
3800
|
+
if (l) {
|
|
3801
|
+
const p = h.trim() === "---", y = `<span style="color: ${p ? t.keyword : t.attrName};">${this.escapeHTML(h)}</span>`;
|
|
3802
|
+
return c > 0 && p && (l = !1), y;
|
|
3672
3803
|
}
|
|
3673
|
-
const u =
|
|
3804
|
+
const u = h.match(/^(\s*)(`{3,}|~{3,})(.*)$/);
|
|
3674
3805
|
if (u) {
|
|
3675
|
-
const
|
|
3676
|
-
return s = !(s &&
|
|
3806
|
+
const p = u[2];
|
|
3807
|
+
return s = !(s && p[0] === r[0]), r = s ? p : "", o = s ? this.extractMarkdownFenceLanguage(u[3] || "") : "", [
|
|
3677
3808
|
this.escapeHTML(u[1]),
|
|
3678
|
-
`<span style="color: ${t.keyword}; font-weight: 700;">${this.escapeHTML(
|
|
3809
|
+
`<span style="color: ${t.keyword}; font-weight: 700;">${this.escapeHTML(p)}</span>`,
|
|
3679
3810
|
`<span style="color: ${t.string};">${this.escapeHTML(u[3] || "")}</span>`
|
|
3680
3811
|
].join("");
|
|
3681
3812
|
}
|
|
3682
3813
|
if (s)
|
|
3683
|
-
return this.highlightMarkdownFenceLine(
|
|
3684
|
-
let g = this.escapeHTML(
|
|
3814
|
+
return this.highlightMarkdownFenceLine(h, o, t);
|
|
3815
|
+
let g = this.escapeHTML(h).replace(
|
|
3685
3816
|
/(`[^`]+`)/g,
|
|
3686
|
-
(
|
|
3817
|
+
(p) => f(`<span style="color: ${t.string}; background: rgba(148, 163, 184, 0.16); border-radius: 3px;">${p}</span>`)
|
|
3687
3818
|
).replace(
|
|
3688
3819
|
/(!?\[[^\]\n]*\])(\([^)]+\))/g,
|
|
3689
|
-
(
|
|
3820
|
+
(p, m, y) => f(`<span style="color: ${t.attrName};">${m}</span><span style="color: ${t.attrValue};">${y}</span>`)
|
|
3690
3821
|
).replace(
|
|
3691
3822
|
/(\*\*|__)(.+?)\1/g,
|
|
3692
|
-
(
|
|
3823
|
+
(p, m, y) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.tag}; font-weight: 700;">${y}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3693
3824
|
).replace(
|
|
3694
3825
|
/(~~)(.+?)\1/g,
|
|
3695
|
-
(
|
|
3826
|
+
(p, m, y) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.comment}; text-decoration: line-through;">${y}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3696
3827
|
).replace(
|
|
3697
3828
|
/(\*|_)([^*_]+?)\1/g,
|
|
3698
|
-
(
|
|
3829
|
+
(p, m, y) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.styleVal}; font-style: italic;">${y}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3699
3830
|
);
|
|
3700
3831
|
return g = g.replace(
|
|
3701
3832
|
/^(\s{0,3}#{1,6})(\s+.*)?$/,
|
|
3702
|
-
(
|
|
3833
|
+
(p, m, y = "") => `<span style="color: ${t.keyword}; font-weight: 700;">${m}</span><span style="color: ${t.tag}; font-weight: 700;">${y}</span>`
|
|
3703
3834
|
), g = g.replace(
|
|
3704
3835
|
/^(\s{0,3})((?:-\s*){3,}|(?:\*\s*){3,}|(?:_\s*){3,})$/,
|
|
3705
|
-
(
|
|
3836
|
+
(p, m, y) => `${m}<span style="color: ${t.comment};">${y}</span>`
|
|
3706
3837
|
), g = g.replace(
|
|
3707
3838
|
/^(\s{0,3}>)(.*)$/,
|
|
3708
|
-
(
|
|
3839
|
+
(p, m, y) => `<span style="color: ${t.comment};">${m}</span>${y}`
|
|
3709
3840
|
), g = g.replace(
|
|
3710
3841
|
/^(\s*)([-*+])(\s+\[[ xX]\])(\s+)/,
|
|
3711
|
-
(
|
|
3842
|
+
(p, m, y, T, S) => `${m}<span style="color: ${t.keyword};">${y}</span><span style="color: ${t.attrName};">${T}</span>${S}`
|
|
3712
3843
|
), g = g.replace(
|
|
3713
3844
|
/^(\s*)([-*+]|\d+\.)(\s+)/,
|
|
3714
|
-
(
|
|
3845
|
+
(p, m, y, T) => `${m}<span style="color: ${t.keyword};">${y}</span>${T}`
|
|
3715
3846
|
), g = g.replace(
|
|
3716
3847
|
/^(\s*\|.*\|\s*)$/,
|
|
3717
|
-
(
|
|
3848
|
+
(p) => p.replace(/\|/g, (m) => `<span style="color: ${t.keyword};">${m}</span>`)
|
|
3718
3849
|
), this.restoreHighlightTokens(g, d);
|
|
3719
3850
|
}).join(`
|
|
3720
3851
|
`);
|
|
@@ -3725,27 +3856,27 @@ class he {
|
|
|
3725
3856
|
return t ? this.normalizeLanguageId(t) : "";
|
|
3726
3857
|
}
|
|
3727
3858
|
highlightMarkdownFenceLine(e, t, i) {
|
|
3728
|
-
const
|
|
3729
|
-
return !
|
|
3859
|
+
const n = t ? this.modes.get(t) : void 0;
|
|
3860
|
+
return !n || n.name === "markdown" ? `<span style="color: ${i.text};">${this.escapeHTML(e)}</span>` : n.highlight(e, i);
|
|
3730
3861
|
}
|
|
3731
3862
|
_highlightShell(e, t) {
|
|
3732
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3863
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n), r = /(#[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|(\$\{?[A-Za-z_][\w]*\}?|\$[0-9@#?$*!])/g;
|
|
3733
3864
|
let o = 0, l = "", a;
|
|
3734
3865
|
for (; a = r.exec(i); ) {
|
|
3735
3866
|
o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
|
|
3736
|
-
const h = a[0],
|
|
3737
|
-
l +=
|
|
3867
|
+
const h = a[0], c = h.startsWith("#") ? t.comment : h.startsWith("$") ? t.variable : t.string;
|
|
3868
|
+
l += s(`<span style="color: ${c};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
|
|
3738
3869
|
}
|
|
3739
3870
|
return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
|
|
3740
3871
|
/(^|\s)(--?[A-Za-z0-9][\w-]*)(?=\s|=|$)/g,
|
|
3741
|
-
(h,
|
|
3872
|
+
(h, c, d) => `${c}${s(`<span style="color: ${t.attrName};">${d}</span>`)}`
|
|
3742
3873
|
), l = l.replace(
|
|
3743
3874
|
/\b(if|then|else|elif|fi|for|while|until|do|done|case|esac|function|export|unset|alias|source|return|in)\b/g,
|
|
3744
|
-
(h) =>
|
|
3875
|
+
(h) => s(`<span style="color: ${t.keyword};">${h}</span>`)
|
|
3745
3876
|
), l = l.replace(
|
|
3746
3877
|
/(^|\s)(npm|npx|pnpm|yarn|bun|node|git|cd|mkdir|touch|cp|mv|rm|cat|grep|rg|find|curl|wget|echo|printf|sudo|chmod|chown|docker|kubectl)(?=\s|$)/g,
|
|
3747
|
-
(h,
|
|
3748
|
-
), this.restoreHighlightTokens(l,
|
|
3878
|
+
(h, c, d) => `${c}${s(`<span style="color: ${t.tag};">${d}</span>`)}`
|
|
3879
|
+
), this.restoreHighlightTokens(l, n);
|
|
3749
3880
|
}
|
|
3750
3881
|
getLanguageKeywords(e) {
|
|
3751
3882
|
const t = ["true", "false", "null", "nil", "none"];
|
|
@@ -3762,101 +3893,101 @@ class he {
|
|
|
3762
3893
|
}[e] || [], ...t];
|
|
3763
3894
|
}
|
|
3764
3895
|
_highlightGenericCode(e, t, i) {
|
|
3765
|
-
const
|
|
3896
|
+
const n = this.unescapeEntitiesRepeated(e), s = [], r = this.createTokenStore(s), o = i === "python" || i === "ruby" || i === "sql" ? "#[^\\n\\r]*|--[^\\n\\r]*" : "\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n\\r]*", l = new RegExp(
|
|
3766
3897
|
`(${o})|("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`)`,
|
|
3767
3898
|
"g"
|
|
3768
3899
|
);
|
|
3769
|
-
let a = 0, h = "",
|
|
3770
|
-
for (;
|
|
3771
|
-
a <
|
|
3772
|
-
const
|
|
3773
|
-
h += r(`<span style="color: ${
|
|
3900
|
+
let a = 0, h = "", c;
|
|
3901
|
+
for (; c = l.exec(n); ) {
|
|
3902
|
+
a < c.index && (h += this.escapeHTML(n.slice(a, c.index)));
|
|
3903
|
+
const f = c[0], u = f.startsWith("//") || f.startsWith("/*") || f.startsWith("#") || f.startsWith("--") ? t.comment : t.string;
|
|
3904
|
+
h += r(`<span style="color: ${u};">${this.escapeHTML(f)}</span>`), a = l.lastIndex;
|
|
3774
3905
|
}
|
|
3775
|
-
a <
|
|
3776
|
-
const
|
|
3777
|
-
if (
|
|
3778
|
-
const
|
|
3779
|
-
`\\b(${
|
|
3906
|
+
a < n.length && (h += this.escapeHTML(n.slice(a)));
|
|
3907
|
+
const d = Array.from(new Set(this.getLanguageKeywords(i)));
|
|
3908
|
+
if (d.length > 0) {
|
|
3909
|
+
const f = new RegExp(
|
|
3910
|
+
`\\b(${d.map((u) => u.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b`,
|
|
3780
3911
|
i === "sql" ? "gi" : "g"
|
|
3781
3912
|
);
|
|
3782
3913
|
h = h.replace(
|
|
3783
|
-
|
|
3784
|
-
(
|
|
3914
|
+
f,
|
|
3915
|
+
(u) => r(`<span style="color: ${t.keyword};">${u}</span>`)
|
|
3785
3916
|
);
|
|
3786
3917
|
}
|
|
3787
3918
|
return h = h.replace(
|
|
3788
3919
|
/\b([A-Z][A-Za-z0-9_]*|[A-Za-z_][\w]*(?=\s*\())\b/g,
|
|
3789
|
-
(
|
|
3920
|
+
(f) => r(`<span style="color: ${t.tag};">${f}</span>`)
|
|
3790
3921
|
), h = h.replace(
|
|
3791
3922
|
/\b(-?0x[0-9a-fA-F]+|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:[uUlLfFdD]*)\b/g,
|
|
3792
|
-
(
|
|
3923
|
+
(f) => r(`<span style="color: ${t.number};">${f}</span>`)
|
|
3793
3924
|
), h = h.replace(
|
|
3794
3925
|
/(@[A-Za-z_][\w]*|#[A-Za-z_][\w]*|::[A-Za-z_][\w]*)/g,
|
|
3795
|
-
(
|
|
3796
|
-
), this.restoreHighlightTokens(h,
|
|
3926
|
+
(f) => r(`<span style="color: ${t.attrName};">${f}</span>`)
|
|
3927
|
+
), this.restoreHighlightTokens(h, s);
|
|
3797
3928
|
}
|
|
3798
3929
|
_highlightYAML(e, t) {
|
|
3799
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3930
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n);
|
|
3800
3931
|
let r = this.escapeHTML(i).replace(
|
|
3801
3932
|
/(#.*)$/gm,
|
|
3802
|
-
(o) =>
|
|
3933
|
+
(o) => s(`<span style="color: ${t.comment};">${o}</span>`)
|
|
3803
3934
|
).replace(
|
|
3804
3935
|
/^(\s*[-?]?\s*)([A-Za-z0-9_.-]+)(\s*:)/gm,
|
|
3805
|
-
(o, l, a, h) => `${l}${
|
|
3936
|
+
(o, l, a, h) => `${l}${s(`<span style="color: ${t.attrName};">${a}</span>`)}${h}`
|
|
3806
3937
|
).replace(
|
|
3807
3938
|
/\b(true|false|null|yes|no|on|off)\b/gi,
|
|
3808
|
-
(o) =>
|
|
3939
|
+
(o) => s(`<span style="color: ${t.keyword};">${o}</span>`)
|
|
3809
3940
|
).replace(
|
|
3810
3941
|
/\b(-?\d+(?:\.\d+)?)\b/g,
|
|
3811
|
-
(o) =>
|
|
3942
|
+
(o) => s(`<span style="color: ${t.number};">${o}</span>`)
|
|
3812
3943
|
);
|
|
3813
3944
|
return r = r.replace(
|
|
3814
3945
|
/("[^&]*?"|'[^&]*?')/g,
|
|
3815
|
-
(o) =>
|
|
3816
|
-
), this.restoreHighlightTokens(r,
|
|
3946
|
+
(o) => s(`<span style="color: ${t.string};">${o}</span>`)
|
|
3947
|
+
), this.restoreHighlightTokens(r, n);
|
|
3817
3948
|
}
|
|
3818
3949
|
_highlightXML(e, t) {
|
|
3819
3950
|
return this._highlightHTML(e, t);
|
|
3820
3951
|
}
|
|
3821
3952
|
_highlightJSX(e, t) {
|
|
3822
|
-
const i = [],
|
|
3953
|
+
const i = [], n = e.replace(
|
|
3823
3954
|
/<\/?[A-Za-z][\w.:-]*(?:\s+[^<>]*?)?\/?>/g,
|
|
3824
|
-
(
|
|
3825
|
-
const r = i.length, o = this.escapeHTML(
|
|
3955
|
+
(s) => {
|
|
3956
|
+
const r = i.length, o = this.escapeHTML(s).replace(
|
|
3826
3957
|
/(<\/?)([A-Za-z][\w.:-]*)([\s\S]*?)(\/?>)/,
|
|
3827
|
-
(l, a, h,
|
|
3828
|
-
const
|
|
3958
|
+
(l, a, h, c, d) => {
|
|
3959
|
+
const f = String(c || "").replace(
|
|
3829
3960
|
/([A-Za-z_:][\w:.-]*)(\s*=\s*)/g,
|
|
3830
3961
|
`<span style="color: ${t.attrName};">$1</span>$2`
|
|
3831
3962
|
);
|
|
3832
|
-
return `${a}<span style="color: ${t.tag};">${h}</span>${
|
|
3963
|
+
return `${a}<span style="color: ${t.tag};">${h}</span>${f}${d}`;
|
|
3833
3964
|
}
|
|
3834
3965
|
);
|
|
3835
3966
|
return i.push(o), `jsx${r}`;
|
|
3836
3967
|
}
|
|
3837
3968
|
);
|
|
3838
|
-
return this._highlightJS(
|
|
3969
|
+
return this._highlightJS(n, t).replace(
|
|
3839
3970
|
/\u0004jsx(\d+)\u0004/g,
|
|
3840
|
-
(
|
|
3971
|
+
(s, r) => i[Number(r)] || ""
|
|
3841
3972
|
);
|
|
3842
3973
|
}
|
|
3843
3974
|
_highlightEJS(e, t) {
|
|
3844
|
-
const i = [],
|
|
3975
|
+
const i = [], n = e.replace(/<%[\s\S]*?%>/g, (s) => {
|
|
3845
3976
|
const r = i.length;
|
|
3846
|
-
return i.push(`<span style="color: ${t.keyword};">${this.escapeHTML(
|
|
3977
|
+
return i.push(`<span style="color: ${t.keyword};">${this.escapeHTML(s)}</span>`), `ejs${r}`;
|
|
3847
3978
|
});
|
|
3848
|
-
return this._highlightHTML(
|
|
3979
|
+
return this._highlightHTML(n, t).replace(
|
|
3849
3980
|
/\u0003ejs(\d+)\u0003/g,
|
|
3850
|
-
(
|
|
3981
|
+
(s, r) => i[Number(r)] || ""
|
|
3851
3982
|
);
|
|
3852
3983
|
}
|
|
3853
3984
|
_highlightDockerfile(e, t) {
|
|
3854
3985
|
return this.unescapeEntitiesRepeated(e).split(`
|
|
3855
|
-
`).map((
|
|
3856
|
-
const s = this.escapeHTML(
|
|
3857
|
-
return /^\s*#/.test(
|
|
3986
|
+
`).map((n) => {
|
|
3987
|
+
const s = this.escapeHTML(n);
|
|
3988
|
+
return /^\s*#/.test(n) ? `<span style="color: ${t.comment};">${s}</span>` : s.replace(
|
|
3858
3989
|
/^(\s*)(FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ARG|ONBUILD|STOPSIGNAL|HEALTHCHECK|SHELL)(\b)/i,
|
|
3859
|
-
(
|
|
3990
|
+
(r, o, l, a) => `${o}<span style="color: ${t.keyword};">${l}</span>${a}`
|
|
3860
3991
|
);
|
|
3861
3992
|
}).join(`
|
|
3862
3993
|
`);
|
|
@@ -3864,78 +3995,78 @@ class he {
|
|
|
3864
3995
|
_highlightJS(e, t) {
|
|
3865
3996
|
const i = this.unescapeEntitiesRepeated(e);
|
|
3866
3997
|
this.escapeHTML(i);
|
|
3867
|
-
const
|
|
3868
|
-
let u = "", g =
|
|
3998
|
+
const n = [], s = (f) => {
|
|
3999
|
+
let u = "", g = f;
|
|
3869
4000
|
do
|
|
3870
4001
|
u = String.fromCharCode(97 + g % 26) + u, g = Math.floor(g / 26) - 1;
|
|
3871
4002
|
while (g >= 0);
|
|
3872
4003
|
return u || "a";
|
|
3873
|
-
}, r = (
|
|
3874
|
-
const u =
|
|
3875
|
-
return
|
|
4004
|
+
}, r = (f) => `\0${s(f)}\0`, o = (f) => {
|
|
4005
|
+
const u = n.length;
|
|
4006
|
+
return n.push(f), r(u);
|
|
3876
4007
|
};
|
|
3877
4008
|
let l;
|
|
3878
4009
|
const a = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
3879
|
-
let h = 0,
|
|
4010
|
+
let h = 0, c = "";
|
|
3880
4011
|
for (; l = a.exec(i); ) {
|
|
3881
|
-
const
|
|
3882
|
-
h <
|
|
4012
|
+
const f = l.index;
|
|
4013
|
+
h < f && (c += this.escapeHTML(i.slice(h, f)));
|
|
3883
4014
|
const u = l[0];
|
|
3884
|
-
/^\/\*/.test(u) || /^\/\//.test(u) ?
|
|
4015
|
+
/^\/\*/.test(u) || /^\/\//.test(u) ? c += o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`) : c += o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`), h = a.lastIndex;
|
|
3885
4016
|
}
|
|
3886
|
-
return h < i.length && (
|
|
3887
|
-
const
|
|
3888
|
-
return
|
|
3889
|
-
}),
|
|
4017
|
+
return h < i.length && (c += this.escapeHTML(i.slice(h))), c = c.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g, (f, u, g) => {
|
|
4018
|
+
const p = c[g - 1] || "", m = c[g + f.length] || "";
|
|
4019
|
+
return p === "&" || p === "#" || m === ";" || m === "#" ? f : `<span style="color: ${t.number};">${f}</span>`;
|
|
4020
|
+
}), c = c.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g, `<span style="color: ${t.keyword};">$1</span>`), c.replace(/\u0000([a-z]+)\u0000/g, (f, u) => {
|
|
3890
4021
|
let g = 0;
|
|
3891
|
-
for (let
|
|
3892
|
-
g = g * 26 + (u.charCodeAt(
|
|
3893
|
-
return g = g - 1,
|
|
4022
|
+
for (let p = 0; p < u.length; p++)
|
|
4023
|
+
g = g * 26 + (u.charCodeAt(p) - 97 + 1);
|
|
4024
|
+
return g = g - 1, n[g] || "";
|
|
3894
4025
|
});
|
|
3895
4026
|
}
|
|
3896
4027
|
_highlightPHP(e, t) {
|
|
3897
4028
|
const i = this.unescapeEntitiesRepeated(e);
|
|
3898
|
-
let
|
|
3899
|
-
const
|
|
3900
|
-
let
|
|
4029
|
+
let n = this.escapeHTML(i);
|
|
4030
|
+
const s = [], r = (u) => {
|
|
4031
|
+
let g = "", p = u;
|
|
3901
4032
|
do
|
|
3902
|
-
|
|
4033
|
+
g = String.fromCharCode(97 + p % 26) + g, p = Math.floor(p / 26) - 1;
|
|
3903
4034
|
while (p >= 0);
|
|
3904
|
-
return
|
|
3905
|
-
}, o = (
|
|
3906
|
-
const
|
|
3907
|
-
return
|
|
3908
|
-
}, l = (
|
|
3909
|
-
const p =
|
|
3910
|
-
return p === -1 ? !1 : (
|
|
4035
|
+
return g || "a";
|
|
4036
|
+
}, o = (u) => {
|
|
4037
|
+
const g = s.length;
|
|
4038
|
+
return s.push(u), `\0${r(g)}\0`;
|
|
4039
|
+
}, l = (u, g) => {
|
|
4040
|
+
const p = n.indexOf(u);
|
|
4041
|
+
return p === -1 ? !1 : (n = n.slice(0, p) + g + n.slice(p + u.length), !0);
|
|
3911
4042
|
};
|
|
3912
4043
|
let a;
|
|
3913
|
-
const h = /\/\*[\s\S]*?\*\//g,
|
|
4044
|
+
const h = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, d = /\#([^\n\r]*)/g, f = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
3914
4045
|
for (; a = h.exec(i); ) {
|
|
3915
|
-
const
|
|
3916
|
-
l(this.escapeHTML(
|
|
3917
|
-
}
|
|
3918
|
-
for (; a = d.exec(i); ) {
|
|
3919
|
-
const g = a[0];
|
|
3920
|
-
l(this.escapeHTML(g), o(`<span style="color: ${t.comment};">${this.escapeHTML(g)}</span>`));
|
|
4046
|
+
const u = a[0];
|
|
4047
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
3921
4048
|
}
|
|
3922
4049
|
for (; a = c.exec(i); ) {
|
|
3923
|
-
const
|
|
3924
|
-
l(this.escapeHTML(
|
|
4050
|
+
const u = a[0];
|
|
4051
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
4052
|
+
}
|
|
4053
|
+
for (; a = d.exec(i); ) {
|
|
4054
|
+
const u = a[0];
|
|
4055
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.comment};">${this.escapeHTML(u)}</span>`));
|
|
3925
4056
|
}
|
|
3926
|
-
for (; a =
|
|
3927
|
-
const
|
|
3928
|
-
l(this.escapeHTML(
|
|
4057
|
+
for (; a = f.exec(i); ) {
|
|
4058
|
+
const u = a[0];
|
|
4059
|
+
l(this.escapeHTML(u), o(`<span style="color: ${t.string};">${this.escapeHTML(u)}</span>`));
|
|
3929
4060
|
}
|
|
3930
|
-
return
|
|
4061
|
+
return n = n.replace(
|
|
3931
4062
|
/(<\?(?:php\b|=)?|\?>)/gi,
|
|
3932
|
-
(
|
|
3933
|
-
),
|
|
4063
|
+
(u) => o(`<span style="color: ${t.keyword};">${u}</span>`)
|
|
4064
|
+
), n = n.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g, `<span style="color: ${t.variable};">$1</span>`), n = n.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>`), n = n.replace(/\u0000([a-z]+)\u0000/g, (u, g) => {
|
|
3934
4065
|
let p = 0;
|
|
3935
|
-
for (let m = 0; m <
|
|
3936
|
-
p = p * 26 + (
|
|
3937
|
-
return p = p - 1,
|
|
3938
|
-
}),
|
|
4066
|
+
for (let m = 0; m < g.length; m++)
|
|
4067
|
+
p = p * 26 + (g.charCodeAt(m) - 97 + 1);
|
|
4068
|
+
return p = p - 1, s[p] || "";
|
|
4069
|
+
}), n;
|
|
3939
4070
|
}
|
|
3940
4071
|
// Method to check if content contains syntax that should be highlighted
|
|
3941
4072
|
shouldHighlight(e) {
|
|
@@ -3945,11 +4076,11 @@ class he {
|
|
|
3945
4076
|
this.editor = null, this.modes.clear();
|
|
3946
4077
|
}
|
|
3947
4078
|
}
|
|
3948
|
-
function
|
|
4079
|
+
function ae(R, e) {
|
|
3949
4080
|
const t = { ...e };
|
|
3950
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
4081
|
+
return t.extensions || (t.extensions = []), t.extensions.some((s) => s.name === "keymap") || t.extensions.unshift(new J(t.keymap)), t.extensions.some((s) => s.name === "transaction") || t.extensions.unshift(new W()), new V(R, t);
|
|
3951
4082
|
}
|
|
3952
|
-
const
|
|
4083
|
+
const z = '[data-theme="dark"], .dark, .editora-theme-dark', he = `/* Source Editor Dialog Styles */
|
|
3953
4084
|
.rte-source-editor-overlay {
|
|
3954
4085
|
position: fixed !important;
|
|
3955
4086
|
top: 0 !important;
|
|
@@ -4326,7 +4457,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4326
4457
|
flex: 1;
|
|
4327
4458
|
text-align: center;
|
|
4328
4459
|
}
|
|
4329
|
-
}`,
|
|
4460
|
+
}`, de = () => ({
|
|
4330
4461
|
name: "code",
|
|
4331
4462
|
// Toolbar button configuration
|
|
4332
4463
|
toolbar: [
|
|
@@ -4347,9 +4478,9 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4347
4478
|
toggleSourceView: () => {
|
|
4348
4479
|
const e = (() => {
|
|
4349
4480
|
var o, l, a;
|
|
4350
|
-
const
|
|
4351
|
-
if (
|
|
4352
|
-
let h =
|
|
4481
|
+
const s = window.getSelection();
|
|
4482
|
+
if (s && s.anchorNode) {
|
|
4483
|
+
let h = s.anchorNode instanceof HTMLElement ? s.anchorNode : s.anchorNode.parentElement;
|
|
4353
4484
|
for (; h; ) {
|
|
4354
4485
|
if ((o = h.classList) != null && o.contains("rte-content"))
|
|
4355
4486
|
return h;
|
|
@@ -4363,10 +4494,10 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4363
4494
|
for (; h && h !== document.body; ) {
|
|
4364
4495
|
if ((a = h.classList) != null && a.contains("rte-content"))
|
|
4365
4496
|
return h;
|
|
4366
|
-
const
|
|
4497
|
+
const c = h.querySelector(
|
|
4367
4498
|
".rte-content"
|
|
4368
4499
|
);
|
|
4369
|
-
if (
|
|
4500
|
+
if (c) return c;
|
|
4370
4501
|
h = h.parentElement;
|
|
4371
4502
|
}
|
|
4372
4503
|
}
|
|
@@ -4383,9 +4514,9 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4383
4514
|
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
4384
4515
|
"Editor content area not found. Please click inside the editor first."
|
|
4385
4516
|
), !1;
|
|
4386
|
-
const t = e.innerHTML, i = (
|
|
4517
|
+
const t = e.innerHTML, i = (s) => {
|
|
4387
4518
|
let r = "", o = 0;
|
|
4388
|
-
const l = 2, a =
|
|
4519
|
+
const l = 2, a = s.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
4389
4520
|
for (const h of a)
|
|
4390
4521
|
h.trim() && (h.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), r += `
|
|
4391
4522
|
` + " ".repeat(o * l) + h) : h.match(/^<[a-zA-Z]/) && !h.match(/\/>$/) ? (r += `
|
|
@@ -4394,12 +4525,13 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4394
4525
|
return r.trim();
|
|
4395
4526
|
};
|
|
4396
4527
|
return (() => {
|
|
4528
|
+
document.querySelectorAll(".rte-source-editor-overlay").forEach((b) => b.remove());
|
|
4397
4529
|
const r = i(t);
|
|
4398
|
-
let o = null, l = "dark", a = !1, h = !1,
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
const
|
|
4402
|
-
|
|
4530
|
+
let o = null, l = "dark", a = !1, h = !1, c = !1, d = !1;
|
|
4531
|
+
const f = !!e.closest(z) || document.body.matches(z) || document.documentElement.matches(z), u = document.createElement("div");
|
|
4532
|
+
Q(u), u.className = "rte-source-editor-overlay", f && u.classList.add("rte-theme-dark");
|
|
4533
|
+
const g = document.createElement("div");
|
|
4534
|
+
g.className = "rte-source-editor-modal", g.setAttribute("role", "dialog"), g.setAttribute("aria-modal", "true"), g.setAttribute("aria-labelledby", "source-editor-title");
|
|
4403
4535
|
const p = document.createElement("div");
|
|
4404
4536
|
p.className = "rte-source-editor-header", p.innerHTML = `
|
|
4405
4537
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
@@ -4440,14 +4572,14 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4440
4572
|
`;
|
|
4441
4573
|
const m = document.createElement("div");
|
|
4442
4574
|
m.className = "rte-source-editor-body";
|
|
4443
|
-
const
|
|
4444
|
-
|
|
4445
|
-
const v = document.createElement("div");
|
|
4446
|
-
v.className = "rte-source-editor-warning", v.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
4575
|
+
const y = document.createElement("div");
|
|
4576
|
+
y.className = "rte-source-editor-content";
|
|
4447
4577
|
const T = document.createElement("div");
|
|
4448
|
-
T.className = "rte-source-editor-
|
|
4449
|
-
const
|
|
4450
|
-
|
|
4578
|
+
T.className = "rte-source-editor-warning", T.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
4579
|
+
const S = document.createElement("div");
|
|
4580
|
+
S.className = "rte-source-editor-light-editor", S.style.height = "400px", y.appendChild(T), y.appendChild(S), m.appendChild(y);
|
|
4581
|
+
const v = document.createElement("div");
|
|
4582
|
+
if (v.className = "rte-source-editor-footer", v.innerHTML = `
|
|
4451
4583
|
<div class="rte-source-editor-footer-info">
|
|
4452
4584
|
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
4453
4585
|
</div>
|
|
@@ -4455,40 +4587,40 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4455
4587
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
4456
4588
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
4457
4589
|
</div>
|
|
4458
|
-
`,
|
|
4590
|
+
`, g.appendChild(p), g.appendChild(m), g.appendChild(v), u.appendChild(g), !document.getElementById("rte-source-editor-styles")) {
|
|
4459
4591
|
const b = document.createElement("style");
|
|
4460
|
-
b.id = "rte-source-editor-styles", b.textContent =
|
|
4592
|
+
b.id = "rte-source-editor-styles", b.textContent = he, document.head.appendChild(b);
|
|
4461
4593
|
}
|
|
4462
|
-
const
|
|
4594
|
+
const C = p.querySelector(
|
|
4463
4595
|
".theme-toggle-btn"
|
|
4464
|
-
),
|
|
4596
|
+
), O = p.querySelector(
|
|
4465
4597
|
".readonly-toggle-btn"
|
|
4466
|
-
), I = p.querySelector(
|
|
4467
|
-
".rte-source-editor-fullscreen-btn"
|
|
4468
4598
|
), $ = p.querySelector(
|
|
4599
|
+
".rte-source-editor-fullscreen-btn"
|
|
4600
|
+
), I = p.querySelector(
|
|
4469
4601
|
".rte-source-editor-close-btn"
|
|
4470
|
-
),
|
|
4602
|
+
), M = v.querySelector(
|
|
4471
4603
|
".rte-source-editor-btn-cancel"
|
|
4472
|
-
),
|
|
4604
|
+
), E = v.querySelector(
|
|
4473
4605
|
".rte-source-editor-btn-save"
|
|
4474
|
-
),
|
|
4606
|
+
), N = v.querySelector(
|
|
4475
4607
|
".unsaved-changes"
|
|
4476
|
-
), F = [], k = (b,
|
|
4477
|
-
b.addEventListener(
|
|
4478
|
-
() => b.removeEventListener(
|
|
4608
|
+
), F = [], k = (b, L, B, D) => {
|
|
4609
|
+
b.addEventListener(L, B, D), F.push(
|
|
4610
|
+
() => b.removeEventListener(L, B, D)
|
|
4479
4611
|
);
|
|
4480
|
-
},
|
|
4481
|
-
|
|
4612
|
+
}, P = (b) => {
|
|
4613
|
+
c !== b && (c = b, N && (N.style.display = c ? "inline" : "none"));
|
|
4482
4614
|
}, H = () => {
|
|
4483
|
-
if (!
|
|
4484
|
-
for (
|
|
4615
|
+
if (!d) {
|
|
4616
|
+
for (d = !0; F.length; ) {
|
|
4485
4617
|
const b = F.pop();
|
|
4486
4618
|
b == null || b();
|
|
4487
4619
|
}
|
|
4488
|
-
o && (o.destroy(), o = null),
|
|
4620
|
+
o && (o.destroy(), o = null), u.isConnected && u.remove();
|
|
4489
4621
|
}
|
|
4490
4622
|
}, _ = () => {
|
|
4491
|
-
l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l),
|
|
4623
|
+
l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l), C && (C.innerHTML = l === "light" ? `
|
|
4492
4624
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4493
4625
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
4494
4626
|
</svg>
|
|
@@ -4506,7 +4638,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4506
4638
|
</svg>
|
|
4507
4639
|
`);
|
|
4508
4640
|
}, j = () => {
|
|
4509
|
-
a = !a, o == null || o.setReadOnly(a),
|
|
4641
|
+
a = !a, o == null || o.setReadOnly(a), O && (O.classList.toggle("active", a), O.innerHTML = a ? `
|
|
4510
4642
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4511
4643
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
4512
4644
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -4519,7 +4651,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4519
4651
|
</svg>
|
|
4520
4652
|
`);
|
|
4521
4653
|
}, q = () => {
|
|
4522
|
-
h = !h,
|
|
4654
|
+
h = !h, u.classList.toggle("fullscreen", h), S.style.height = h ? "calc(100vh - 200px)" : "400px", $ && ($.innerHTML = h ? `
|
|
4523
4655
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4524
4656
|
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
|
|
4525
4657
|
</svg>
|
|
@@ -4529,13 +4661,13 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4529
4661
|
</svg>
|
|
4530
4662
|
`);
|
|
4531
4663
|
}, G = () => {
|
|
4532
|
-
|
|
4664
|
+
c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
|
|
4533
4665
|
}, Z = () => {
|
|
4534
4666
|
try {
|
|
4535
|
-
const b = (o == null ? void 0 : o.getValue()) || "",
|
|
4536
|
-
|
|
4667
|
+
const b = (o == null ? void 0 : o.getValue()) || "", L = document.createElement("div");
|
|
4668
|
+
L.innerHTML = b, L.querySelectorAll(
|
|
4537
4669
|
'script, iframe[src^="javascript:"], object, embed'
|
|
4538
|
-
).forEach((
|
|
4670
|
+
).forEach((D) => D.remove()), e.innerHTML = L.innerHTML;
|
|
4539
4671
|
try {
|
|
4540
4672
|
e.dispatchEvent(
|
|
4541
4673
|
new InputEvent("input", {
|
|
@@ -4544,42 +4676,42 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4544
4676
|
inputType: "insertReplacementText"
|
|
4545
4677
|
})
|
|
4546
4678
|
);
|
|
4547
|
-
} catch (
|
|
4679
|
+
} catch (D) {
|
|
4548
4680
|
e.dispatchEvent(
|
|
4549
4681
|
new Event("input", { bubbles: !0 })
|
|
4550
4682
|
);
|
|
4551
4683
|
}
|
|
4552
4684
|
e.dispatchEvent(
|
|
4553
4685
|
new Event("change", { bubbles: !0 })
|
|
4554
|
-
),
|
|
4686
|
+
), P(!1), H();
|
|
4555
4687
|
} catch (b) {
|
|
4556
4688
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", b);
|
|
4557
4689
|
}
|
|
4558
4690
|
};
|
|
4559
|
-
|
|
4560
|
-
b.target ===
|
|
4691
|
+
C && k(C, "click", _), O && k(O, "click", j), $ && k($, "click", q), I && k(I, "click", H), M && k(M, "click", G), E && k(E, "click", Z), k(u, "click", (b) => {
|
|
4692
|
+
b.target === u && H();
|
|
4561
4693
|
}), k(document, "keydown", (b) => {
|
|
4562
|
-
const
|
|
4563
|
-
|
|
4564
|
-
}), document.body.appendChild(
|
|
4565
|
-
if (!(
|
|
4694
|
+
const L = b;
|
|
4695
|
+
L.key === "Escape" && (L.preventDefault(), H());
|
|
4696
|
+
}), document.body.appendChild(u), requestAnimationFrame(() => {
|
|
4697
|
+
if (!(d || !u.isConnected))
|
|
4566
4698
|
try {
|
|
4567
|
-
o =
|
|
4699
|
+
o = ae(S, {
|
|
4568
4700
|
value: r,
|
|
4569
4701
|
theme: "dark",
|
|
4570
4702
|
readOnly: !1,
|
|
4571
4703
|
extensions: [
|
|
4704
|
+
new ee(),
|
|
4572
4705
|
new te(),
|
|
4573
4706
|
new ie(),
|
|
4574
|
-
new se(),
|
|
4575
|
-
new le(),
|
|
4576
4707
|
new re(),
|
|
4577
|
-
new
|
|
4578
|
-
new
|
|
4708
|
+
new U(),
|
|
4709
|
+
new oe(),
|
|
4710
|
+
new le()
|
|
4579
4711
|
]
|
|
4580
4712
|
}), o.on("change", () => {
|
|
4581
4713
|
const b = (o == null ? void 0 : o.getValue()) || "";
|
|
4582
|
-
|
|
4714
|
+
P(b !== r);
|
|
4583
4715
|
}), requestAnimationFrame(() => o == null ? void 0 : o.focus());
|
|
4584
4716
|
} catch (b) {
|
|
4585
4717
|
console.error("Failed to initialize code editor:", b);
|
|
@@ -4595,6 +4727,6 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4595
4727
|
}
|
|
4596
4728
|
});
|
|
4597
4729
|
export {
|
|
4598
|
-
|
|
4730
|
+
de as CodePlugin
|
|
4599
4731
|
};
|
|
4600
|
-
//# sourceMappingURL=CodePlugin.native-
|
|
4732
|
+
//# sourceMappingURL=CodePlugin.native-BH-K4xmW.mjs.map
|