@editora/core 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CodePlugin.native-veDC_kx5.mjs → CodePlugin.native-knhM8NNo.mjs} +895 -895
- package/dist/{DocumentManagerPlugin.native-C2cs_1w4.mjs → DocumentManagerPlugin.native-D1YHQ2NN.mjs} +4 -4
- package/dist/{documentManager-vQ1VkbUY.mjs → documentManager-BcBIv5P-.mjs} +3 -3
- package/dist/{index-BslAFzmv.mjs → index-CavM-mEM.mjs} +6391 -6203
- package/dist/{index-B9MPiUAR.mjs → index-Cd9jEuZP.mjs} +7 -7
- package/dist/{index.es-BYD2KEo6.mjs → index.es-BK-4TPv8.mjs} +1562 -1546
- package/dist/index.esm.js +2 -2
- package/dist/{jspdf.es.min-BJGtOnRT.mjs → jspdf.es.min-BsnKYYHL.mjs} +4 -3
- package/dist/plugin-loader.js +1 -1
- package/dist/{purify.es-CKpwg8Tk.mjs → purify.es-DhWKBjsL.mjs} +3 -3
- package/dist/webcomponent-core.js +1 -1
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +40 -40
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +2 -2
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +877 -877
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class _ {
|
|
2
2
|
constructor(e = "") {
|
|
3
3
|
this._lines = [], this._version = 0, this.setText(e);
|
|
4
4
|
}
|
|
@@ -37,8 +37,8 @@ class V {
|
|
|
37
37
|
}
|
|
38
38
|
// Replace text in range
|
|
39
39
|
replaceRange(e, t) {
|
|
40
|
-
const i = this.normalizeRange(e),
|
|
41
|
-
return this.setText(l), { range: i, text: t, oldText:
|
|
40
|
+
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);
|
|
41
|
+
return this.setText(l), { range: i, text: t, oldText: n };
|
|
42
42
|
}
|
|
43
43
|
// Insert text at position
|
|
44
44
|
insertText(e, t) {
|
|
@@ -60,10 +60,10 @@ class V {
|
|
|
60
60
|
offsetToPosition(e) {
|
|
61
61
|
let t = e;
|
|
62
62
|
for (let i = 0; i < this.getLineCount(); i++) {
|
|
63
|
-
const
|
|
64
|
-
if (t <=
|
|
63
|
+
const n = this.getLine(i).length;
|
|
64
|
+
if (t <= n)
|
|
65
65
|
return { line: i, column: t };
|
|
66
|
-
t -=
|
|
66
|
+
t -= n + 1;
|
|
67
67
|
}
|
|
68
68
|
return {
|
|
69
69
|
line: this.getLineCount() - 1,
|
|
@@ -84,7 +84,7 @@ class V {
|
|
|
84
84
|
}
|
|
85
85
|
// Clone the model
|
|
86
86
|
clone() {
|
|
87
|
-
const e = new
|
|
87
|
+
const e = new _();
|
|
88
88
|
return e._lines = [...this._lines], e._version = this._version, e;
|
|
89
89
|
}
|
|
90
90
|
normalizeRange(e) {
|
|
@@ -207,14 +207,14 @@ class Q {
|
|
|
207
207
|
if (this.updateGutterWidth(e), e === this.lastLineCount)
|
|
208
208
|
return;
|
|
209
209
|
this.lastLineCount = e;
|
|
210
|
-
const t = Math.max(e, 1), i = Array.from({ length: t }, (
|
|
211
|
-
this.lineNumbersContentElement.innerHTML = i.map((
|
|
210
|
+
const t = Math.max(e, 1), i = Array.from({ length: t }, (n, s) => s + 1);
|
|
211
|
+
this.lineNumbersContentElement.innerHTML = i.map((n) => `<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px;">${n}</div>`).join("");
|
|
212
212
|
}
|
|
213
213
|
updateGutterWidth(e) {
|
|
214
|
-
const
|
|
215
|
-
|
|
214
|
+
const i = String(Math.max(e, 1)).length * this.gutterDigitWidth + this.gutterLineNumberPaddingLeft + this.gutterLineNumberPaddingRight, n = Math.ceil(
|
|
215
|
+
i + this.gutterFoldColumnGap + this.gutterFoldColumnWidth
|
|
216
216
|
);
|
|
217
|
-
|
|
217
|
+
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
218
|
}
|
|
219
219
|
setDecorations(e, t) {
|
|
220
220
|
this.renderLineDecorations(e), this.renderGutterDecorations(t);
|
|
@@ -245,17 +245,17 @@ class Q {
|
|
|
245
245
|
// Set inner HTML (used for syntax highlighted content)
|
|
246
246
|
setHTML(e) {
|
|
247
247
|
this.clearHighlightOverlay(), this.setFoldPlaceholderSources(/* @__PURE__ */ new Map());
|
|
248
|
-
const t = /\n$/.test(e), i = /<|>/.test(e),
|
|
249
|
-
i &&
|
|
250
|
-
const
|
|
248
|
+
const t = /\n$/.test(e), i = /<|>/.test(e), n = /<span\b/i.test(e), s = /<[^>]+>/.test(e);
|
|
249
|
+
i && n ? this.contentElement.innerHTML = e : s && !i ? this.contentElement.textContent = e : this.contentElement.innerHTML = e, this.syncTrailingNewlineMarker(t);
|
|
250
|
+
const o = (this.contentElement.textContent || "").split(`
|
|
251
251
|
`).length;
|
|
252
|
-
this.updateLineNumbers(
|
|
252
|
+
this.updateLineNumbers(o);
|
|
253
253
|
}
|
|
254
254
|
setHighlightHTML(e) {
|
|
255
255
|
e !== this.lastHighlightHTML && (this.highlightElement.innerHTML = e, this.lastHighlightHTML = e), this.highlightElement.style.visibility = "visible", this.highlightOverlayActive = !0, this.contentElement.style.color = "transparent", this.contentElement.style.WebkitTextFillColor = "transparent";
|
|
256
|
-
const
|
|
256
|
+
const i = (this.contentElement.textContent || "").split(`
|
|
257
257
|
`).length;
|
|
258
|
-
this.updateLineNumbers(
|
|
258
|
+
this.updateLineNumbers(i);
|
|
259
259
|
}
|
|
260
260
|
setLineWrapping(e) {
|
|
261
261
|
this.contentElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.contentElement.style.overflow = "visible", this.contentElement.style.minWidth = e ? "100%" : "max-content", this.contentSurface.style.minWidth = e ? "100%" : "max-content", this.contentElement.style.wordBreak = "normal", this.contentElement.style.overflowWrap = e ? "anywhere" : "normal", this.highlightElement.style.whiteSpace = e ? "pre-wrap" : "pre", this.highlightElement.style.wordBreak = "normal", this.highlightElement.style.overflowWrap = e ? "anywhere" : "normal";
|
|
@@ -280,10 +280,10 @@ class Q {
|
|
|
280
280
|
}
|
|
281
281
|
// Set cursor position
|
|
282
282
|
setCursorPosition(e) {
|
|
283
|
-
const t = this.getText(), i = this.positionToTextOffset(e, t),
|
|
284
|
-
if (
|
|
283
|
+
const t = this.getText(), i = this.positionToTextOffset(e, t), n = window.getSelection(), s = this.createDomRangeFromOffsets(i);
|
|
284
|
+
if (s)
|
|
285
285
|
try {
|
|
286
|
-
|
|
286
|
+
n == null || n.removeAllRanges(), n == null || n.addRange(s), this.ensureCaretVisible();
|
|
287
287
|
} catch (r) {
|
|
288
288
|
console.warn("Could not set cursor position:", r);
|
|
289
289
|
}
|
|
@@ -292,7 +292,7 @@ class Q {
|
|
|
292
292
|
`[${this.trailingNewlineMarkerAttr}]`
|
|
293
293
|
), o = document.createRange();
|
|
294
294
|
try {
|
|
295
|
-
r && r.parentNode === this.contentElement ? o.setStartBefore(r) : (o.selectNodeContents(this.contentElement), o.collapse(!1)), o.collapse(!0),
|
|
295
|
+
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
296
|
} catch (l) {
|
|
297
297
|
console.warn("Could not set fallback cursor position:", l);
|
|
298
298
|
}
|
|
@@ -322,7 +322,7 @@ class Q {
|
|
|
322
322
|
const i = e.anchorNode && this.isNodeInsideContent(e.anchorNode) ? this.sourceOffsetFromBoundary(
|
|
323
323
|
e.anchorNode,
|
|
324
324
|
e.anchorOffset
|
|
325
|
-
) : void 0,
|
|
325
|
+
) : void 0, n = e.focusNode && this.isNodeInsideContent(e.focusNode) ? this.sourceOffsetFromBoundary(
|
|
326
326
|
e.focusNode,
|
|
327
327
|
e.focusOffset
|
|
328
328
|
) : void 0;
|
|
@@ -338,7 +338,7 @@ class Q {
|
|
|
338
338
|
t.endOffset
|
|
339
339
|
),
|
|
340
340
|
anchorOffset: i,
|
|
341
|
-
focusOffset:
|
|
341
|
+
focusOffset: n
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
344
|
getSelectionState() {
|
|
@@ -354,10 +354,10 @@ class Q {
|
|
|
354
354
|
isInEditor: !1,
|
|
355
355
|
isCollapsed: e.isCollapsed
|
|
356
356
|
};
|
|
357
|
-
const i = this.getText(),
|
|
357
|
+
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
358
|
e.focusNode,
|
|
359
359
|
e.focusOffset
|
|
360
|
-
) :
|
|
360
|
+
) : s, o = this.offsetToPositionInText(n, i), l = this.offsetToPositionInText(s, i), a = this.offsetToPositionInText(r, i);
|
|
361
361
|
return {
|
|
362
362
|
isInEditor: !0,
|
|
363
363
|
isCollapsed: e.isCollapsed,
|
|
@@ -377,12 +377,12 @@ class Q {
|
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
createDomRangeFromOffsets(e, t = e) {
|
|
380
|
-
const [i,
|
|
381
|
-
if (!
|
|
380
|
+
const [i, n] = e <= t ? [e, t] : [t, e], s = this.resolveOffsetToDomPoint(i), r = this.resolveOffsetToDomPoint(n);
|
|
381
|
+
if (!s || !r)
|
|
382
382
|
return null;
|
|
383
383
|
const o = document.createRange();
|
|
384
384
|
try {
|
|
385
|
-
return o.setStart(
|
|
385
|
+
return o.setStart(s.node, s.offset), o.setEnd(r.node, r.offset), o;
|
|
386
386
|
} catch (l) {
|
|
387
387
|
return null;
|
|
388
388
|
}
|
|
@@ -398,43 +398,43 @@ class Q {
|
|
|
398
398
|
const i = this.getDomRangeFromClientPoint(e, t);
|
|
399
399
|
if (!i || !this.isNodeInsideContent(i.startContainer))
|
|
400
400
|
return null;
|
|
401
|
-
const
|
|
401
|
+
const n = this.sourceOffsetFromBoundary(
|
|
402
402
|
i.startContainer,
|
|
403
403
|
i.startOffset
|
|
404
404
|
);
|
|
405
|
-
return this.offsetToPositionInText(
|
|
405
|
+
return this.offsetToPositionInText(n, this.getText());
|
|
406
406
|
}
|
|
407
407
|
setSelectionOffsets(e, t = e) {
|
|
408
408
|
const i = this.createDomRangeFromOffsets(e, t);
|
|
409
409
|
if (i)
|
|
410
410
|
try {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
} catch (
|
|
414
|
-
console.warn("Could not set selection offsets:",
|
|
411
|
+
const n = window.getSelection();
|
|
412
|
+
n == null || n.removeAllRanges(), n == null || n.addRange(i), this.ensureCaretVisible();
|
|
413
|
+
} catch (n) {
|
|
414
|
+
console.warn("Could not set selection offsets:", n);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
setSelectionBoundaryOffsets(e, t) {
|
|
418
|
-
const i = this.resolveOffsetToDomPoint(e),
|
|
419
|
-
if (!i || !
|
|
418
|
+
const i = this.resolveOffsetToDomPoint(e), n = this.resolveOffsetToDomPoint(t), s = window.getSelection();
|
|
419
|
+
if (!i || !n || !s) {
|
|
420
420
|
this.setSelectionOffsets(e, t);
|
|
421
421
|
return;
|
|
422
422
|
}
|
|
423
423
|
try {
|
|
424
|
-
if (
|
|
424
|
+
if (s.removeAllRanges(), e === t) {
|
|
425
425
|
const o = document.createRange();
|
|
426
|
-
o.setStart(i.node, i.offset), o.collapse(!0),
|
|
426
|
+
o.setStart(i.node, i.offset), o.collapse(!0), s.addRange(o), this.ensureCaretVisible();
|
|
427
427
|
return;
|
|
428
428
|
}
|
|
429
|
-
if (typeof
|
|
429
|
+
if (typeof s.extend == "function") {
|
|
430
430
|
const o = document.createRange();
|
|
431
|
-
o.setStart(i.node, i.offset), o.collapse(!0),
|
|
431
|
+
o.setStart(i.node, i.offset), o.collapse(!0), s.addRange(o), s.extend(n.node, n.offset), this.ensureCaretVisible();
|
|
432
432
|
return;
|
|
433
433
|
}
|
|
434
434
|
const r = this.createDomRangeFromOffsets(e, t);
|
|
435
435
|
if (!r)
|
|
436
436
|
return;
|
|
437
|
-
|
|
437
|
+
s.addRange(r), this.ensureCaretVisible();
|
|
438
438
|
} catch (r) {
|
|
439
439
|
console.warn("Could not set selection boundary offsets:", r), this.setSelectionOffsets(e, t);
|
|
440
440
|
}
|
|
@@ -459,8 +459,8 @@ class Q {
|
|
|
459
459
|
}
|
|
460
460
|
// Scroll to position
|
|
461
461
|
scrollToPosition(e) {
|
|
462
|
-
const
|
|
463
|
-
this.editorContainer.scrollTop = Math.max(0,
|
|
462
|
+
const n = Math.max(0, Math.floor(e.line) || 0) * this.lineHeight - this.editorContainer.clientHeight / 2 + this.lineHeight / 2;
|
|
463
|
+
this.editorContainer.scrollTop = Math.max(0, n);
|
|
464
464
|
}
|
|
465
465
|
// Get scroll position
|
|
466
466
|
getScrollTop() {
|
|
@@ -491,39 +491,39 @@ class Q {
|
|
|
491
491
|
if (!e || e.rangeCount === 0) return;
|
|
492
492
|
const t = this.getCaretClientRect(e);
|
|
493
493
|
if (!t) return;
|
|
494
|
-
const i = this.editorContainer.getBoundingClientRect(),
|
|
495
|
-
t.bottom > i.bottom -
|
|
494
|
+
const i = this.editorContainer.getBoundingClientRect(), n = 12;
|
|
495
|
+
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
496
|
}
|
|
497
497
|
// Destroy the view
|
|
498
498
|
destroy() {
|
|
499
499
|
this.clearDecorations(), this.container && (this.container.innerHTML = ""), this._rafId && (cancelAnimationFrame(this._rafId), this._rafId = void 0);
|
|
500
500
|
}
|
|
501
501
|
resolveOffsetToDomPoint(e) {
|
|
502
|
-
var
|
|
502
|
+
var s;
|
|
503
503
|
const t = Math.max(0, e);
|
|
504
504
|
let i = 0;
|
|
505
|
-
const
|
|
506
|
-
for (let r = 0; r <
|
|
507
|
-
const o =
|
|
505
|
+
const n = Array.from(this.contentElement.childNodes);
|
|
506
|
+
for (let r = 0; r < n.length; r++) {
|
|
507
|
+
const o = n[r];
|
|
508
508
|
if (o instanceof Text) {
|
|
509
509
|
const l = o.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
|
|
510
510
|
if (i + h >= t) {
|
|
511
|
-
const
|
|
512
|
-
return { node: o, offset:
|
|
511
|
+
const c = Math.max(0, t - i), g = (s = a[c]) != null ? s : l.length;
|
|
512
|
+
return { node: o, offset: g };
|
|
513
513
|
}
|
|
514
514
|
i += h;
|
|
515
515
|
continue;
|
|
516
516
|
}
|
|
517
517
|
if (o instanceof HTMLElement && !o.hasAttribute(this.trailingNewlineMarkerAttr) && o.hasAttribute(this.foldPlaceholderAttr)) {
|
|
518
|
-
const
|
|
519
|
-
if (i +
|
|
520
|
-
const
|
|
518
|
+
const a = this.getFoldPlaceholderSource(o).length;
|
|
519
|
+
if (i + a >= t) {
|
|
520
|
+
const h = t - i;
|
|
521
521
|
return {
|
|
522
522
|
node: this.contentElement,
|
|
523
|
-
offset:
|
|
523
|
+
offset: h <= a / 2 ? r : r + 1
|
|
524
524
|
};
|
|
525
525
|
}
|
|
526
|
-
i +=
|
|
526
|
+
i += a;
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
return {
|
|
@@ -534,14 +534,14 @@ class Q {
|
|
|
534
534
|
getDomRangeFromClientPoint(e, t) {
|
|
535
535
|
const i = document;
|
|
536
536
|
if (typeof i.caretPositionFromPoint == "function") {
|
|
537
|
-
const
|
|
537
|
+
const n = i.caretPositionFromPoint(
|
|
538
538
|
e,
|
|
539
539
|
t
|
|
540
540
|
);
|
|
541
|
-
if (
|
|
542
|
-
const
|
|
541
|
+
if (n != null && n.offsetNode) {
|
|
542
|
+
const s = document.createRange();
|
|
543
543
|
try {
|
|
544
|
-
return
|
|
544
|
+
return s.setStart(n.offsetNode, n.offset), s.collapse(!0), s;
|
|
545
545
|
} catch (r) {
|
|
546
546
|
return null;
|
|
547
547
|
}
|
|
@@ -552,9 +552,9 @@ class Q {
|
|
|
552
552
|
buildVisibleToDomMap(e) {
|
|
553
553
|
const t = [0];
|
|
554
554
|
let i = 0;
|
|
555
|
-
for (let
|
|
556
|
-
const
|
|
557
|
-
this.virtualMarkerRegex.test(
|
|
555
|
+
for (let n = 0; n < e.length; n++) {
|
|
556
|
+
const s = e[n];
|
|
557
|
+
this.virtualMarkerRegex.test(s) || (i += 1, t[i] = n + 1);
|
|
558
558
|
}
|
|
559
559
|
return t;
|
|
560
560
|
}
|
|
@@ -568,23 +568,23 @@ class Q {
|
|
|
568
568
|
const i = this.getUsableRangeRect(t);
|
|
569
569
|
if (i)
|
|
570
570
|
return i;
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
573
|
-
const h = (l = (o =
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
578
|
-
return
|
|
571
|
+
const n = e.focusNode, s = e.focusOffset;
|
|
572
|
+
if (n instanceof Text) {
|
|
573
|
+
const h = (l = (o = n.textContent) == null ? void 0 : o.length) != null ? l : 0, c = document.createRange();
|
|
574
|
+
if (s < h) {
|
|
575
|
+
c.setStart(n, s), c.setEnd(n, Math.min(h, s + 1));
|
|
576
|
+
const g = this.getUsableRangeRect(c);
|
|
577
|
+
if (g)
|
|
578
|
+
return g;
|
|
579
579
|
}
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
if (
|
|
584
|
-
return
|
|
580
|
+
if (s > 0) {
|
|
581
|
+
c.setStart(n, s - 1), c.setEnd(n, s);
|
|
582
|
+
const g = this.getUsableRangeRect(c);
|
|
583
|
+
if (g)
|
|
584
|
+
return g;
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
-
const r =
|
|
587
|
+
const r = n instanceof Element ? n : (a = n == null ? void 0 : n.parentElement) != null ? a : null;
|
|
588
588
|
if (r && r !== this.contentElement && r !== this.editorContainer && this.contentElement.contains(r)) {
|
|
589
589
|
const h = r.getBoundingClientRect();
|
|
590
590
|
if (this.isUsableRect(h))
|
|
@@ -594,9 +594,9 @@ class Q {
|
|
|
594
594
|
}
|
|
595
595
|
getUsableRangeRect(e) {
|
|
596
596
|
const t = Array.from(e.getClientRects());
|
|
597
|
-
for (let
|
|
598
|
-
if (this.isUsableRect(t[
|
|
599
|
-
return t[
|
|
597
|
+
for (let n = 0; n < t.length; n++)
|
|
598
|
+
if (this.isUsableRect(t[n]))
|
|
599
|
+
return t[n];
|
|
600
600
|
const i = e.getBoundingClientRect();
|
|
601
601
|
return this.isUsableRect(i) ? i : null;
|
|
602
602
|
}
|
|
@@ -629,14 +629,14 @@ class Q {
|
|
|
629
629
|
}
|
|
630
630
|
sourceOffsetFromBoundary(e, t) {
|
|
631
631
|
let i = 0;
|
|
632
|
-
const
|
|
632
|
+
const n = Array.from(this.contentElement.childNodes);
|
|
633
633
|
if (e === this.contentElement) {
|
|
634
|
-
for (let
|
|
635
|
-
i += this.getSourceLength(s
|
|
634
|
+
for (let s = 0; s < Math.min(t, n.length); s++)
|
|
635
|
+
i += this.getSourceLength(n[s]);
|
|
636
636
|
return i;
|
|
637
637
|
}
|
|
638
|
-
for (let
|
|
639
|
-
const r = s
|
|
638
|
+
for (let s = 0; s < n.length; s++) {
|
|
639
|
+
const r = n[s];
|
|
640
640
|
if (r === e) {
|
|
641
641
|
if (r instanceof Text)
|
|
642
642
|
return i + this.stripVirtualMarkers((r.textContent || "").slice(0, t)).length;
|
|
@@ -664,40 +664,40 @@ class Q {
|
|
|
664
664
|
return i;
|
|
665
665
|
}
|
|
666
666
|
sourceOffsetWithinNode(e, t, i) {
|
|
667
|
-
let
|
|
668
|
-
const
|
|
667
|
+
let n = 0;
|
|
668
|
+
const s = Array.from(e.childNodes);
|
|
669
669
|
if (t === e) {
|
|
670
|
-
for (let r = 0; r < Math.min(i,
|
|
671
|
-
|
|
672
|
-
return
|
|
670
|
+
for (let r = 0; r < Math.min(i, s.length); r++)
|
|
671
|
+
n += this.getSourceLength(s[r]);
|
|
672
|
+
return n;
|
|
673
673
|
}
|
|
674
|
-
for (let r = 0; r <
|
|
675
|
-
const o =
|
|
674
|
+
for (let r = 0; r < s.length; r++) {
|
|
675
|
+
const o = s[r];
|
|
676
676
|
if (o === t) {
|
|
677
677
|
if (o instanceof Text)
|
|
678
|
-
return
|
|
678
|
+
return n + this.stripVirtualMarkers((o.textContent || "").slice(0, i)).length;
|
|
679
679
|
if (o instanceof HTMLElement) {
|
|
680
680
|
if (o.hasAttribute(this.foldPlaceholderAttr))
|
|
681
|
-
return
|
|
681
|
+
return n + this.getFoldPlaceholderBoundaryOffset(
|
|
682
682
|
o,
|
|
683
683
|
o,
|
|
684
684
|
i
|
|
685
685
|
);
|
|
686
686
|
const l = Array.from(o.childNodes);
|
|
687
687
|
for (let a = 0; a < Math.min(i, l.length); a++)
|
|
688
|
-
|
|
689
|
-
return
|
|
688
|
+
n += this.getSourceLength(l[a]);
|
|
689
|
+
return n;
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
692
|
if (o instanceof HTMLElement && o.contains(t))
|
|
693
|
-
return o.hasAttribute(this.foldPlaceholderAttr) ?
|
|
693
|
+
return o.hasAttribute(this.foldPlaceholderAttr) ? n + this.getFoldPlaceholderBoundaryOffset(
|
|
694
694
|
o,
|
|
695
695
|
t,
|
|
696
696
|
i
|
|
697
|
-
) :
|
|
698
|
-
|
|
697
|
+
) : n + this.sourceOffsetWithinNode(o, t, i);
|
|
698
|
+
n += this.getSourceLength(o);
|
|
699
699
|
}
|
|
700
|
-
return
|
|
700
|
+
return n;
|
|
701
701
|
}
|
|
702
702
|
getSourceLength(e) {
|
|
703
703
|
if (e instanceof Text)
|
|
@@ -712,44 +712,44 @@ class Q {
|
|
|
712
712
|
}), t;
|
|
713
713
|
}
|
|
714
714
|
renderLineDecorations(e) {
|
|
715
|
-
const t = [...e].filter((
|
|
716
|
-
(
|
|
715
|
+
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(
|
|
716
|
+
(s) => `${s.id}:${s.line}:${s.className || ""}:${this.serializeStyleObject(s.style)}`
|
|
717
717
|
).join("|");
|
|
718
718
|
if (i === this.lastLineDecorationSnapshot || (this.lineDecorationsElement.innerHTML = "", this.lastLineDecorationSnapshot = i, t.length === 0))
|
|
719
719
|
return;
|
|
720
|
-
const
|
|
721
|
-
for (const
|
|
720
|
+
const n = document.createDocumentFragment();
|
|
721
|
+
for (const s of t) {
|
|
722
722
|
const r = document.createElement("div");
|
|
723
723
|
r.className = this.joinClassNames(
|
|
724
724
|
"lce-decoration lce-decoration-line",
|
|
725
|
-
|
|
726
|
-
), r.setAttribute("data-decoration-id",
|
|
725
|
+
s.className
|
|
726
|
+
), r.setAttribute("data-decoration-id", s.id), r.setAttribute("data-decoration-line", String(s.line)), r.style.cssText = this.joinStyleFragments([
|
|
727
727
|
"position: absolute",
|
|
728
|
-
`top: ${
|
|
728
|
+
`top: ${s.line * this.lineHeight}px`,
|
|
729
729
|
`height: ${this.lineHeight}px`,
|
|
730
730
|
"left: 12px",
|
|
731
731
|
"right: 12px",
|
|
732
732
|
"border-radius: 3px",
|
|
733
|
-
this.serializeStyleObject(
|
|
734
|
-
]),
|
|
733
|
+
this.serializeStyleObject(s.style)
|
|
734
|
+
]), n.appendChild(r);
|
|
735
735
|
}
|
|
736
|
-
this.lineDecorationsElement.appendChild(
|
|
736
|
+
this.lineDecorationsElement.appendChild(n);
|
|
737
737
|
}
|
|
738
738
|
renderGutterDecorations(e) {
|
|
739
|
-
const t = [...e].filter((
|
|
740
|
-
(
|
|
739
|
+
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(
|
|
740
|
+
(s) => `${s.id}:${s.line}:${s.label || ""}:${s.title || ""}:${s.className || ""}:${this.serializeStyleObject(s.style)}`
|
|
741
741
|
).join("|");
|
|
742
742
|
if (i === this.lastGutterDecorationSnapshot || (this.gutterDecorationsElement.innerHTML = "", this.lastGutterDecorationSnapshot = i, t.length === 0))
|
|
743
743
|
return;
|
|
744
|
-
const
|
|
745
|
-
for (const
|
|
744
|
+
const n = document.createDocumentFragment();
|
|
745
|
+
for (const s of t) {
|
|
746
746
|
const r = document.createElement("div");
|
|
747
747
|
r.className = this.joinClassNames(
|
|
748
748
|
"lce-decoration lce-decoration-gutter",
|
|
749
|
-
|
|
750
|
-
), r.setAttribute("data-decoration-id",
|
|
749
|
+
s.className
|
|
750
|
+
), r.setAttribute("data-decoration-id", s.id), r.setAttribute("data-decoration-line", String(s.line)), r.style.cssText = this.joinStyleFragments([
|
|
751
751
|
"position: absolute",
|
|
752
|
-
`top: ${
|
|
752
|
+
`top: ${s.line * this.lineHeight}px`,
|
|
753
753
|
`height: ${this.lineHeight}px`,
|
|
754
754
|
"left: 0",
|
|
755
755
|
"right: 0",
|
|
@@ -758,10 +758,10 @@ class Q {
|
|
|
758
758
|
"justify-content: flex-end",
|
|
759
759
|
"padding-right: 4px",
|
|
760
760
|
"box-sizing: border-box",
|
|
761
|
-
this.serializeStyleObject(
|
|
762
|
-
]),
|
|
761
|
+
this.serializeStyleObject(s.style)
|
|
762
|
+
]), s.title && (r.title = s.title), r.textContent = s.label || "", n.appendChild(r);
|
|
763
763
|
}
|
|
764
|
-
this.gutterDecorationsElement.appendChild(
|
|
764
|
+
this.gutterDecorationsElement.appendChild(n);
|
|
765
765
|
}
|
|
766
766
|
joinClassNames(...e) {
|
|
767
767
|
return e.filter(Boolean).join(" ").trim();
|
|
@@ -789,14 +789,14 @@ class Q {
|
|
|
789
789
|
positionToTextOffset(e, t) {
|
|
790
790
|
var o;
|
|
791
791
|
const i = t.split(`
|
|
792
|
-
`),
|
|
792
|
+
`), n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(
|
|
793
793
|
0,
|
|
794
|
-
Math.min(e.column, ((o = i[
|
|
794
|
+
Math.min(e.column, ((o = i[n]) == null ? void 0 : o.length) || 0)
|
|
795
795
|
);
|
|
796
796
|
let r = 0;
|
|
797
|
-
for (let l = 0; l <
|
|
797
|
+
for (let l = 0; l < n; l++)
|
|
798
798
|
r += i[l].length + 1;
|
|
799
|
-
return r +
|
|
799
|
+
return r + s;
|
|
800
800
|
}
|
|
801
801
|
getFoldPlaceholderSource(e) {
|
|
802
802
|
const t = e.getAttribute(this.foldPlaceholderAttr), i = this.getFoldPlaceholderSources();
|
|
@@ -806,26 +806,26 @@ class Q {
|
|
|
806
806
|
return this.contentElement.__lceFoldPlaceholderSources || /* @__PURE__ */ new Map();
|
|
807
807
|
}
|
|
808
808
|
getFoldPlaceholderBoundaryOffset(e, t, i) {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
809
|
+
const n = this.getFoldPlaceholderSource(e).length, s = this.stripVirtualMarkers(e.textContent || "").length;
|
|
810
|
+
if (n === 0 || s === 0)
|
|
811
811
|
return 0;
|
|
812
812
|
const r = document.createRange();
|
|
813
813
|
r.selectNodeContents(e);
|
|
814
814
|
try {
|
|
815
815
|
r.setEnd(t, i);
|
|
816
|
-
} catch (
|
|
816
|
+
} catch (l) {
|
|
817
817
|
return 0;
|
|
818
818
|
}
|
|
819
|
-
return this.stripVirtualMarkers(r.toString()).length <=
|
|
819
|
+
return this.stripVirtualMarkers(r.toString()).length <= s / 2 ? 0 : n;
|
|
820
820
|
}
|
|
821
821
|
setFoldPlaceholderSources(e) {
|
|
822
822
|
this.contentElement.__lceFoldPlaceholderSources = e;
|
|
823
823
|
}
|
|
824
824
|
}
|
|
825
|
-
let
|
|
826
|
-
const
|
|
825
|
+
let Y = 0;
|
|
826
|
+
const L = class L {
|
|
827
827
|
constructor(e, t = {}) {
|
|
828
|
-
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.lastKnownCursor = { line: 0, column: 0 }, this.editorInstanceId = ++
|
|
828
|
+
this.extensions = /* @__PURE__ */ new Map(), this.commands = /* @__PURE__ */ new Map(), this.eventListeners = /* @__PURE__ */ new Map(), this.folds = [], this.currentTheme = "default", this.isDestroyed = !1, this.undoStack = [], this.redoStack = [], this.suppressHistory = !1, this.highlightTimeout = null, this.expectingProgrammaticCursor = !1, this.lastKnownCursor = { line: 0, column: 0 }, this.editorInstanceId = ++Y, 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
829
|
value: "",
|
|
830
830
|
theme: "default",
|
|
831
831
|
readOnly: !1,
|
|
@@ -833,7 +833,7 @@ const W = class O {
|
|
|
833
833
|
lineWrapping: !1,
|
|
834
834
|
lineNumbers: !0,
|
|
835
835
|
...t
|
|
836
|
-
}, this.textModel = new
|
|
836
|
+
}, this.textModel = new _(this.config.value), this.view = new Q(e), this.view.setTabSize(this.config.tabSize || 2), this.view.setLineWrapping(!!this.config.lineWrapping), this.view.setLineNumbersVisible(this.config.lineNumbers !== !1), this.hasCustomDecorationHighlightSupport = this.detectCustomHighlightSupport(), this.observeDecorationRelevantMutations(), this.setupEventHandlers(), this.config.extensions && this.config.extensions.forEach((i) => this.addExtension(i)), this.setTheme(this.config.theme), this.view.setReadOnly(this.config.readOnly || !1), this.renderTextWithHighlight(this.textModel.getText()), this.registerBuiltInCommands();
|
|
837
837
|
}
|
|
838
838
|
// Public accessors for extensions
|
|
839
839
|
getTextModel() {
|
|
@@ -864,10 +864,10 @@ const W = class O {
|
|
|
864
864
|
return;
|
|
865
865
|
}
|
|
866
866
|
if (t.inputType === "insertFromPaste" || t.inputType === "insertFromPasteAsQuotation" || t.inputType === "insertFromDrop") {
|
|
867
|
-
const i = t.dataTransfer,
|
|
868
|
-
if (
|
|
867
|
+
const i = t.dataTransfer, n = this.getPlainTextFromDataTransfer(i);
|
|
868
|
+
if (n.length === 0 || (t.preventDefault(), this.pendingInputSnapshot = void 0, Date.now() - this.lastProgrammaticClipboardInsertAt < 80))
|
|
869
869
|
return;
|
|
870
|
-
this.insertClipboardText(
|
|
870
|
+
this.insertClipboardText(n);
|
|
871
871
|
return;
|
|
872
872
|
}
|
|
873
873
|
if (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") {
|
|
@@ -903,29 +903,29 @@ const W = class O {
|
|
|
903
903
|
const i = this.getPlainTextFromDataTransfer(t.clipboardData);
|
|
904
904
|
i.length !== 0 && (t.preventDefault(), this.insertClipboardText(i));
|
|
905
905
|
}), e.addEventListener("input", () => {
|
|
906
|
-
var
|
|
906
|
+
var n;
|
|
907
907
|
const t = this.view.getText(), i = this.textModel.getText();
|
|
908
908
|
t !== i ? (this.suppressHistory || this.pushUndoSnapshot(
|
|
909
|
-
(
|
|
909
|
+
(n = this.pendingInputSnapshot) != null ? n : this.captureHistorySnapshot(i)
|
|
910
910
|
), this.pendingInputSnapshot = void 0, this.textModel.setText(t), this.view.syncTrailingNewlineMarkerForText(t), this.hasRenderedFoldPlaceholders() ? this.clearPendingHighlightRender() : (this.clearPendingHighlightRender(), this.highlightTimeout = setTimeout(() => {
|
|
911
|
-
const
|
|
912
|
-
|
|
911
|
+
const s = this.view.getText();
|
|
912
|
+
s !== this.textModel.getText() && this.textModel.setText(s), this.renderTextWithHighlight(this.textModel.getText(), !1), this.highlightTimeout = null;
|
|
913
913
|
}, 300)), this.updateLineNumbers(), this.emit("change", [{ range: this.getFullRange(), text: t, oldText: i }])) : this.pendingInputSnapshot = void 0;
|
|
914
914
|
}), this.documentSelectionChangeHandler = () => {
|
|
915
|
-
var
|
|
915
|
+
var n, s, r;
|
|
916
916
|
const t = this.syncSelectionCacheFromView();
|
|
917
917
|
if (!t.isInEditor)
|
|
918
918
|
return;
|
|
919
|
-
const i = (
|
|
919
|
+
const i = (n = t.cursor) != null ? n : this.lastKnownCursor;
|
|
920
920
|
this.emit("cursor", {
|
|
921
921
|
position: i,
|
|
922
|
-
anchor: (r = (
|
|
922
|
+
anchor: (r = (s = t.range) == null ? void 0 : s.start) != null ? r : i
|
|
923
923
|
}), this.emit("selection", t.isCollapsed ? void 0 : t.range);
|
|
924
924
|
}, document.addEventListener("selectionchange", this.documentSelectionChangeHandler), e.addEventListener("keydown", (t) => {
|
|
925
925
|
this.emit("keydown", t);
|
|
926
926
|
const i = Array.from(this.extensions.values()).reverse();
|
|
927
|
-
for (const
|
|
928
|
-
if (
|
|
927
|
+
for (const n of i)
|
|
928
|
+
if (n.onKeyDown && n.onKeyDown(t) === !1) {
|
|
929
929
|
t.preventDefault(), t.stopPropagation();
|
|
930
930
|
return;
|
|
931
931
|
}
|
|
@@ -948,16 +948,16 @@ const W = class O {
|
|
|
948
948
|
}), e.addEventListener("mousedown", (t) => {
|
|
949
949
|
this.emit("mousedown", t);
|
|
950
950
|
const i = Array.from(this.extensions.values()).reverse();
|
|
951
|
-
for (const
|
|
952
|
-
if (
|
|
951
|
+
for (const n of i)
|
|
952
|
+
if (n.onMouseDown && n.onMouseDown(t) === !1) {
|
|
953
953
|
t.preventDefault(), t.stopPropagation();
|
|
954
954
|
return;
|
|
955
955
|
}
|
|
956
956
|
}), e.addEventListener("contextmenu", (t) => {
|
|
957
957
|
this.emit("contextmenu", t);
|
|
958
958
|
const i = Array.from(this.extensions.values()).reverse();
|
|
959
|
-
for (const
|
|
960
|
-
if (
|
|
959
|
+
for (const n of i)
|
|
960
|
+
if (n.onContextMenu && n.onContextMenu(t) === !1) {
|
|
961
961
|
t.preventDefault(), t.stopPropagation();
|
|
962
962
|
return;
|
|
963
963
|
}
|
|
@@ -985,7 +985,7 @@ const W = class O {
|
|
|
985
985
|
// Emit events to listeners
|
|
986
986
|
emit(e, ...t) {
|
|
987
987
|
const i = this.eventListeners.get(e);
|
|
988
|
-
i && i.forEach((
|
|
988
|
+
i && i.forEach((n) => n(...t));
|
|
989
989
|
}
|
|
990
990
|
// State management
|
|
991
991
|
getValue() {
|
|
@@ -1006,16 +1006,16 @@ const W = class O {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
// Cursor & Selection
|
|
1008
1008
|
getCursor() {
|
|
1009
|
-
var i,
|
|
1009
|
+
var i, n, s;
|
|
1010
1010
|
const e = this.syncSelectionCacheFromView(), t = (i = e.cursor) != null ? i : this.lastKnownCursor;
|
|
1011
1011
|
return {
|
|
1012
1012
|
position: t,
|
|
1013
|
-
anchor: (
|
|
1013
|
+
anchor: (s = (n = e.range) == null ? void 0 : n.start) != null ? s : t
|
|
1014
1014
|
};
|
|
1015
1015
|
}
|
|
1016
1016
|
setCursor(e) {
|
|
1017
|
-
const t = this.textModel.getText(), i = this.clampPositionToText(e, t),
|
|
1018
|
-
this.lastKnownCursor = i, this.lastKnownSelection = void 0, this.view.setSelectionOffsets(
|
|
1017
|
+
const t = this.textModel.getText(), i = this.clampPositionToText(e, t), n = this.positionToOffsetInText(i, t);
|
|
1018
|
+
this.lastKnownCursor = i, this.lastKnownSelection = void 0, this.view.setSelectionOffsets(n), this.emit("cursor", this.getCursor());
|
|
1019
1019
|
}
|
|
1020
1020
|
getSelection() {
|
|
1021
1021
|
const e = this.syncSelectionCacheFromView();
|
|
@@ -1026,8 +1026,8 @@ const W = class O {
|
|
|
1026
1026
|
const t = this.textModel.getText(), i = this.normalizeRange({
|
|
1027
1027
|
start: this.clampPositionToText(e.start, t),
|
|
1028
1028
|
end: this.clampPositionToText(e.end, t)
|
|
1029
|
-
}),
|
|
1030
|
-
this.lastKnownSelection = i, this.lastKnownCursor = i.end, this.view.setSelectionOffsets(
|
|
1029
|
+
}), n = this.positionToOffsetInText(i.start, t), s = this.positionToOffsetInText(i.end, t);
|
|
1030
|
+
this.lastKnownSelection = i, this.lastKnownCursor = i.end, this.view.setSelectionOffsets(n, s), this.emit("selection", i);
|
|
1031
1031
|
}
|
|
1032
1032
|
// Configuration
|
|
1033
1033
|
setTheme(e) {
|
|
@@ -1044,8 +1044,8 @@ const W = class O {
|
|
|
1044
1044
|
if (i && typeof i.setTheme == "function")
|
|
1045
1045
|
try {
|
|
1046
1046
|
i.setTheme(e === "dark" ? "dark" : "light"), this.renderTextWithHighlight(this.textModel.getText());
|
|
1047
|
-
} catch (
|
|
1048
|
-
console.warn("Error applying theme to syntax-highlighting extension",
|
|
1047
|
+
} catch (n) {
|
|
1048
|
+
console.warn("Error applying theme to syntax-highlighting extension", n);
|
|
1049
1049
|
}
|
|
1050
1050
|
}
|
|
1051
1051
|
setReadOnly(e) {
|
|
@@ -1079,7 +1079,7 @@ const W = class O {
|
|
|
1079
1079
|
}
|
|
1080
1080
|
this.decorationLayers.set(
|
|
1081
1081
|
i,
|
|
1082
|
-
t.map((
|
|
1082
|
+
t.map((n) => this.cloneDecoration(n))
|
|
1083
1083
|
), this.scheduleDecorationRender();
|
|
1084
1084
|
}
|
|
1085
1085
|
clearDecorations(e) {
|
|
@@ -1093,7 +1093,7 @@ const W = class O {
|
|
|
1093
1093
|
const t = [];
|
|
1094
1094
|
for (const i of this.decorationLayers.values())
|
|
1095
1095
|
t.push(
|
|
1096
|
-
...i.map((
|
|
1096
|
+
...i.map((n) => this.cloneDecoration(n))
|
|
1097
1097
|
);
|
|
1098
1098
|
return t;
|
|
1099
1099
|
}
|
|
@@ -1107,68 +1107,68 @@ const W = class O {
|
|
|
1107
1107
|
wholeWord: !1,
|
|
1108
1108
|
regex: !1,
|
|
1109
1109
|
...t
|
|
1110
|
-
},
|
|
1110
|
+
}, 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
1111
|
if (i.regex) {
|
|
1112
|
-
let
|
|
1112
|
+
let c;
|
|
1113
1113
|
try {
|
|
1114
|
-
|
|
1115
|
-
} catch (
|
|
1114
|
+
c = new RegExp(e, i.caseSensitive ? "g" : "gi");
|
|
1115
|
+
} catch (f) {
|
|
1116
1116
|
return [];
|
|
1117
1117
|
}
|
|
1118
|
-
let
|
|
1119
|
-
for (; (
|
|
1120
|
-
const
|
|
1121
|
-
if (
|
|
1122
|
-
|
|
1118
|
+
let g;
|
|
1119
|
+
for (; (g = c.exec(r)) !== null; ) {
|
|
1120
|
+
const f = (h = g[0]) != null ? h : "";
|
|
1121
|
+
if (f.length === 0) {
|
|
1122
|
+
c.lastIndex = g.index + 1;
|
|
1123
1123
|
continue;
|
|
1124
1124
|
}
|
|
1125
|
-
const
|
|
1126
|
-
i.wholeWord && !this.isWholeWordBoundary(r,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1125
|
+
const d = g.index, u = g.index + f.length;
|
|
1126
|
+
i.wholeWord && !this.isWholeWordBoundary(r, d, u) || this.pushSearchResultFromOffsets(
|
|
1127
|
+
n,
|
|
1128
|
+
d,
|
|
1129
|
+
u,
|
|
1130
1130
|
r,
|
|
1131
1131
|
o
|
|
1132
1132
|
);
|
|
1133
1133
|
}
|
|
1134
1134
|
} else {
|
|
1135
|
-
let
|
|
1136
|
-
for (;
|
|
1137
|
-
const
|
|
1138
|
-
!i.wholeWord || this.isWholeWordBoundary(r,
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1135
|
+
let c = 0, g = l.indexOf(a, c);
|
|
1136
|
+
for (; g !== -1; ) {
|
|
1137
|
+
const f = g + a.length;
|
|
1138
|
+
!i.wholeWord || this.isWholeWordBoundary(r, g, f) ? (this.pushSearchResultFromOffsets(
|
|
1139
|
+
n,
|
|
1140
|
+
g,
|
|
1141
|
+
f,
|
|
1142
1142
|
r,
|
|
1143
1143
|
o
|
|
1144
|
-
),
|
|
1144
|
+
), c = f) : c = g + 1, g = l.indexOf(a, c);
|
|
1145
1145
|
}
|
|
1146
1146
|
}
|
|
1147
|
-
return
|
|
1147
|
+
return n;
|
|
1148
1148
|
}
|
|
1149
|
-
pushSearchResultFromOffsets(e, t, i,
|
|
1150
|
-
var h,
|
|
1151
|
-
const r = (h =
|
|
1149
|
+
pushSearchResultFromOffsets(e, t, i, n, s) {
|
|
1150
|
+
var h, c;
|
|
1151
|
+
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
1152
|
e.push({
|
|
1153
1153
|
range: { start: l, end: a },
|
|
1154
|
-
match:
|
|
1154
|
+
match: n.substring(t, i)
|
|
1155
1155
|
});
|
|
1156
1156
|
}
|
|
1157
1157
|
isWholeWordBoundary(e, t, i) {
|
|
1158
|
-
const
|
|
1159
|
-
return !this.isWordChar(
|
|
1158
|
+
const n = t > 0 ? e[t - 1] : "", s = i < e.length ? e[i] : "";
|
|
1159
|
+
return !this.isWordChar(n) && !this.isWordChar(s);
|
|
1160
1160
|
}
|
|
1161
1161
|
isWordChar(e) {
|
|
1162
1162
|
return /^[A-Za-z0-9_]$/.test(e);
|
|
1163
1163
|
}
|
|
1164
1164
|
buildSearchTextAndOffsetMap(e) {
|
|
1165
1165
|
const t = [], i = [0];
|
|
1166
|
-
let
|
|
1167
|
-
for (let
|
|
1168
|
-
const r = e[
|
|
1169
|
-
r === "" || r ===
|
|
1166
|
+
let n = 0;
|
|
1167
|
+
for (let s = 0; s < e.length; s++) {
|
|
1168
|
+
const r = e[s];
|
|
1169
|
+
r === "" || r === L.CURSOR_SENTINEL || (t.push(r), n += 1, i[n] = s + 1);
|
|
1170
1170
|
}
|
|
1171
|
-
return i[
|
|
1171
|
+
return i[n] = e.length, {
|
|
1172
1172
|
normalizedText: t.join(""),
|
|
1173
1173
|
normalizedToRawOffsets: i
|
|
1174
1174
|
};
|
|
@@ -1176,15 +1176,15 @@ const W = class O {
|
|
|
1176
1176
|
replace(e, t) {
|
|
1177
1177
|
const i = this.getValue();
|
|
1178
1178
|
this.suppressHistory || this.pushUndoSnapshot(this.captureHistorySnapshot(i));
|
|
1179
|
-
const
|
|
1180
|
-
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [
|
|
1179
|
+
const n = this.textModel.replaceRange(e, t);
|
|
1180
|
+
this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.getValue(), !1), this.expectingProgrammaticCursor = !1, this.emit("change", [n]);
|
|
1181
1181
|
}
|
|
1182
1182
|
replaceAll(e, t, i = {}) {
|
|
1183
|
-
const
|
|
1184
|
-
let
|
|
1185
|
-
for (let r =
|
|
1186
|
-
this.replace(
|
|
1187
|
-
return
|
|
1183
|
+
const n = this.search(e, i);
|
|
1184
|
+
let s = 0;
|
|
1185
|
+
for (let r = n.length - 1; r >= 0; r--)
|
|
1186
|
+
this.replace(n[r].range, t), s++;
|
|
1187
|
+
return s;
|
|
1188
1188
|
}
|
|
1189
1189
|
// Folding (basic implementation)
|
|
1190
1190
|
fold(e) {
|
|
@@ -1193,14 +1193,14 @@ const W = class O {
|
|
|
1193
1193
|
if (t.start.line === t.end.line && t.start.column === t.end.column)
|
|
1194
1194
|
return;
|
|
1195
1195
|
const i = this.folds.findIndex(
|
|
1196
|
-
(
|
|
1197
|
-
),
|
|
1196
|
+
(s) => this.isSameFoldRange(s, t)
|
|
1197
|
+
), n = {
|
|
1198
1198
|
start: t.start,
|
|
1199
1199
|
end: t.end,
|
|
1200
1200
|
collapsed: !0,
|
|
1201
1201
|
level: 0
|
|
1202
1202
|
};
|
|
1203
|
-
i !== -1 ? this.folds[i] =
|
|
1203
|
+
i !== -1 ? this.folds[i] = n : (this.folds.push(n), this.folds.sort((s, r) => this.comparePositions(s.start, r.start)));
|
|
1204
1204
|
}
|
|
1205
1205
|
unfold(e) {
|
|
1206
1206
|
this.clearPendingHighlightRender();
|
|
@@ -1228,38 +1228,38 @@ const W = class O {
|
|
|
1228
1228
|
if (i && typeof i.highlightHTML == "function")
|
|
1229
1229
|
try {
|
|
1230
1230
|
if (typeof this.view.setHighlightHTML == "function") {
|
|
1231
|
-
const
|
|
1232
|
-
(
|
|
1231
|
+
const u = this.view.getContentElement();
|
|
1232
|
+
(u.querySelector(
|
|
1233
1233
|
"[data-lce-fold-placeholder]"
|
|
1234
|
-
) ||
|
|
1235
|
-
const
|
|
1236
|
-
this.view.setHighlightHTML(
|
|
1234
|
+
) || u.textContent !== e) && this.view.setText(e);
|
|
1235
|
+
const m = typeof i.highlight == "function" ? i.highlight(e) : i.highlightHTML(e);
|
|
1236
|
+
this.view.setHighlightHTML(m), this.view.syncTrailingNewlineMarkerForText(e), this.scheduleDecorationRender();
|
|
1237
1237
|
return;
|
|
1238
1238
|
}
|
|
1239
1239
|
const s = !t && !this.expectingProgrammaticCursor;
|
|
1240
|
-
let
|
|
1241
|
-
const
|
|
1242
|
-
(t || s) &&
|
|
1243
|
-
const
|
|
1244
|
-
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(
|
|
1240
|
+
let r, o, l, a;
|
|
1241
|
+
const h = this.view.getSelectionState(), c = h.isInEditor && !!h.cursor;
|
|
1242
|
+
(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)));
|
|
1243
|
+
const g = c && (t || s) && !r && o !== void 0 && this.hasCollapsedSelectionInEditor(), f = g ? this.insertSentinelAtOffset(e, o) : e, d = typeof i.highlight == "function" ? i.highlight(f) : i.highlightHTML(f);
|
|
1244
|
+
typeof this.view.setHighlightHTML == "function" ? this.view.setHighlightHTML(d) : this.view.setHTML(d), this.view.syncTrailingNewlineMarkerForText(e), (t || s) && c && requestAnimationFrame(() => {
|
|
1245
1245
|
try {
|
|
1246
|
-
if (
|
|
1246
|
+
if (g && this.restoreCursorFromSentinel()) {
|
|
1247
1247
|
this.view.ensureCaretVisible();
|
|
1248
1248
|
return;
|
|
1249
1249
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
const
|
|
1252
|
-
this.view.setSelectionRange({ start:
|
|
1253
|
-
} else if (
|
|
1254
|
-
const
|
|
1255
|
-
this.view.setCursorPosition(
|
|
1250
|
+
if (r && (l !== void 0 || a !== void 0)) {
|
|
1251
|
+
const u = l !== void 0 ? l : o, p = a !== void 0 ? a : o, m = Math.min(u, p), x = Math.max(u, p), v = this.textModel.offsetToPosition(m), T = this.textModel.offsetToPosition(x);
|
|
1252
|
+
this.view.setSelectionRange({ start: v, end: T });
|
|
1253
|
+
} else if (o !== void 0) {
|
|
1254
|
+
const u = this.textModel.offsetToPosition(o);
|
|
1255
|
+
this.view.setCursorPosition(u);
|
|
1256
1256
|
}
|
|
1257
|
-
} catch (
|
|
1257
|
+
} catch (u) {
|
|
1258
1258
|
}
|
|
1259
1259
|
}), this.scheduleDecorationRender();
|
|
1260
1260
|
return;
|
|
1261
|
-
} catch (
|
|
1262
|
-
console.warn("Syntax highlighting failed, falling back to plain text",
|
|
1261
|
+
} catch (n) {
|
|
1262
|
+
console.warn("Syntax highlighting failed, falling back to plain text", n);
|
|
1263
1263
|
}
|
|
1264
1264
|
this.view.setText(e), this.scheduleDecorationRender();
|
|
1265
1265
|
}
|
|
@@ -1277,28 +1277,28 @@ const W = class O {
|
|
|
1277
1277
|
const t = e.getRangeAt(0), i = this.view.getContentElement();
|
|
1278
1278
|
if (!i.contains(t.commonAncestorContainer))
|
|
1279
1279
|
return;
|
|
1280
|
-
const
|
|
1281
|
-
return
|
|
1280
|
+
const n = t.cloneRange();
|
|
1281
|
+
return n.selectNodeContents(i), n.setEnd(t.endContainer, t.endOffset), this.stripVirtualMarkers(n.toString()).length;
|
|
1282
1282
|
}
|
|
1283
1283
|
stripVirtualMarkers(e) {
|
|
1284
|
-
return e.replace(/\u200B/g, "").split(
|
|
1284
|
+
return e.replace(/\u200B/g, "").split(L.CURSOR_SENTINEL).join("");
|
|
1285
1285
|
}
|
|
1286
1286
|
insertSentinelAtOffset(e, t) {
|
|
1287
1287
|
const i = Math.max(0, Math.min(t, e.length));
|
|
1288
|
-
return e.slice(0, i) +
|
|
1288
|
+
return e.slice(0, i) + L.CURSOR_SENTINEL + e.slice(i);
|
|
1289
1289
|
}
|
|
1290
1290
|
restoreCursorFromSentinel() {
|
|
1291
1291
|
var o;
|
|
1292
1292
|
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 && (
|
|
1293
|
+
let n = i.nextNode(), s = null, r = 0;
|
|
1294
|
+
for (; n; ) {
|
|
1295
|
+
const l = (o = n.textContent) != null ? o : "", a = l.indexOf(L.CURSOR_SENTINEL);
|
|
1296
|
+
a !== -1 && (s || (s = n, r = a), n.textContent = l.split(L.CURSOR_SENTINEL).join("")), n = i.nextNode();
|
|
1297
1297
|
}
|
|
1298
|
-
if (!
|
|
1298
|
+
if (!s || !t) return !1;
|
|
1299
1299
|
try {
|
|
1300
1300
|
const l = document.createRange();
|
|
1301
|
-
return l.setStart(
|
|
1301
|
+
return l.setStart(s, r), l.collapse(!0), t.removeAllRanges(), t.addRange(l), !0;
|
|
1302
1302
|
} catch (l) {
|
|
1303
1303
|
return !1;
|
|
1304
1304
|
}
|
|
@@ -1356,8 +1356,8 @@ const W = class O {
|
|
|
1356
1356
|
}
|
|
1357
1357
|
deleteSelection() {
|
|
1358
1358
|
if (this.config.readOnly) return;
|
|
1359
|
-
const e = this.textModel.getText(), { startOffset: t, endOffset: i } = this.getActiveSelectionOffsets(e),
|
|
1360
|
-
|
|
1359
|
+
const e = this.textModel.getText(), { startOffset: t, endOffset: i } = this.getActiveSelectionOffsets(e), n = Math.min(t, i), s = Math.max(t, i);
|
|
1360
|
+
n !== s && this.replaceOffsetsWithText(n, s, "");
|
|
1361
1361
|
}
|
|
1362
1362
|
// Events
|
|
1363
1363
|
on(e, t) {
|
|
@@ -1367,8 +1367,8 @@ const W = class O {
|
|
|
1367
1367
|
if (!this.eventListeners.has(e)) return;
|
|
1368
1368
|
const i = this.eventListeners.get(e);
|
|
1369
1369
|
if (t) {
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1370
|
+
const n = i.indexOf(t);
|
|
1371
|
+
n !== -1 && i.splice(n, 1);
|
|
1372
1372
|
} else
|
|
1373
1373
|
i.length = 0;
|
|
1374
1374
|
}
|
|
@@ -1379,12 +1379,12 @@ const W = class O {
|
|
|
1379
1379
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
1380
1380
|
}
|
|
1381
1381
|
captureHistorySnapshot(e = this.textModel.getText()) {
|
|
1382
|
-
const t = this.view.getSelectionState(), i = t.isInEditor && !t.isCollapsed ? t.range : void 0,
|
|
1382
|
+
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
1383
|
text: e,
|
|
1384
1384
|
cursorOffset: this.positionToOffsetInText(o, e)
|
|
1385
1385
|
};
|
|
1386
|
-
if (
|
|
1387
|
-
const a = this.clampPositionToText(
|
|
1386
|
+
if (s) {
|
|
1387
|
+
const a = this.clampPositionToText(s.start, e), h = this.clampPositionToText(s.end, e);
|
|
1388
1388
|
l.anchorOffset = this.positionToOffsetInText(a, e), l.focusOffset = this.positionToOffsetInText(h, e);
|
|
1389
1389
|
}
|
|
1390
1390
|
return l;
|
|
@@ -1393,10 +1393,10 @@ const W = class O {
|
|
|
1393
1393
|
this.setValue(e.text), requestAnimationFrame(() => {
|
|
1394
1394
|
try {
|
|
1395
1395
|
if (e.anchorOffset !== void 0 && e.focusOffset !== void 0 && e.anchorOffset !== e.focusOffset) {
|
|
1396
|
-
const
|
|
1396
|
+
const i = Math.min(e.anchorOffset, e.focusOffset), n = Math.max(e.anchorOffset, e.focusOffset);
|
|
1397
1397
|
this.setSelection({
|
|
1398
|
-
start: this.textModel.offsetToPosition(
|
|
1399
|
-
end: this.textModel.offsetToPosition(
|
|
1398
|
+
start: this.textModel.offsetToPosition(i),
|
|
1399
|
+
end: this.textModel.offsetToPosition(n)
|
|
1400
1400
|
});
|
|
1401
1401
|
return;
|
|
1402
1402
|
}
|
|
@@ -1414,23 +1414,23 @@ const W = class O {
|
|
|
1414
1414
|
clampPositionToText(e, t) {
|
|
1415
1415
|
var r, o;
|
|
1416
1416
|
const i = t.split(`
|
|
1417
|
-
`),
|
|
1417
|
+
`), n = Math.max(0, Math.min(e.line, i.length - 1)), s = Math.max(
|
|
1418
1418
|
0,
|
|
1419
|
-
Math.min(e.column, (o = (r = i[
|
|
1419
|
+
Math.min(e.column, (o = (r = i[n]) == null ? void 0 : r.length) != null ? o : 0)
|
|
1420
1420
|
);
|
|
1421
1421
|
return {
|
|
1422
|
-
line:
|
|
1423
|
-
column:
|
|
1422
|
+
line: n,
|
|
1423
|
+
column: s
|
|
1424
1424
|
};
|
|
1425
1425
|
}
|
|
1426
1426
|
positionToOffsetInText(e, t) {
|
|
1427
1427
|
var r, o;
|
|
1428
1428
|
const i = t.split(`
|
|
1429
|
-
`),
|
|
1430
|
-
let
|
|
1431
|
-
for (let l = 0; l <
|
|
1432
|
-
|
|
1433
|
-
return
|
|
1429
|
+
`), n = this.clampPositionToText(e, t);
|
|
1430
|
+
let s = 0;
|
|
1431
|
+
for (let l = 0; l < n.line; l++)
|
|
1432
|
+
s += ((o = (r = i[l]) == null ? void 0 : r.length) != null ? o : 0) + 1;
|
|
1433
|
+
return s + n.column;
|
|
1434
1434
|
}
|
|
1435
1435
|
clearPendingHighlightRender() {
|
|
1436
1436
|
this.highlightTimeout && (clearTimeout(this.highlightTimeout), this.highlightTimeout = null);
|
|
@@ -1440,7 +1440,7 @@ const W = class O {
|
|
|
1440
1440
|
}
|
|
1441
1441
|
replaceSelectionWithText(e) {
|
|
1442
1442
|
const t = e.replace(/\r\n?/g, `
|
|
1443
|
-
`), i = this.textModel.getText(), { startOffset:
|
|
1443
|
+
`), 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
1444
|
return this.replaceOffsetsWithText(r, o, t);
|
|
1445
1445
|
}
|
|
1446
1446
|
insertClipboardText(e) {
|
|
@@ -1493,7 +1493,7 @@ const W = class O {
|
|
|
1493
1493
|
"TABLE",
|
|
1494
1494
|
"TR",
|
|
1495
1495
|
"UL"
|
|
1496
|
-
]),
|
|
1496
|
+
]), n = (o) => {
|
|
1497
1497
|
var l;
|
|
1498
1498
|
for (let a = o.length - 1; a >= 0; a--) {
|
|
1499
1499
|
const h = (l = o[a]) != null ? l : "";
|
|
@@ -1502,13 +1502,13 @@ const W = class O {
|
|
|
1502
1502
|
`);
|
|
1503
1503
|
}
|
|
1504
1504
|
return !1;
|
|
1505
|
-
},
|
|
1505
|
+
}, s = (o, l) => {
|
|
1506
1506
|
if (o instanceof Text) {
|
|
1507
1507
|
l.push(o.data);
|
|
1508
1508
|
return;
|
|
1509
1509
|
}
|
|
1510
1510
|
if (!(o instanceof HTMLElement)) {
|
|
1511
|
-
o.childNodes.forEach((h) =>
|
|
1511
|
+
o.childNodes.forEach((h) => s(h, l));
|
|
1512
1512
|
return;
|
|
1513
1513
|
}
|
|
1514
1514
|
if (o.tagName === "BR") {
|
|
@@ -1517,11 +1517,11 @@ const W = class O {
|
|
|
1517
1517
|
return;
|
|
1518
1518
|
}
|
|
1519
1519
|
const a = i.has(o.tagName);
|
|
1520
|
-
a && l.length > 0 && !
|
|
1521
|
-
`), o.childNodes.forEach((h) =>
|
|
1520
|
+
a && l.length > 0 && !n(l) && l.push(`
|
|
1521
|
+
`), o.childNodes.forEach((h) => s(h, l)), a && !n(l) && l.push(`
|
|
1522
1522
|
`);
|
|
1523
1523
|
}, r = [];
|
|
1524
|
-
return t.body.childNodes.forEach((o) =>
|
|
1524
|
+
return t.body.childNodes.forEach((o) => s(o, r)), r.join("").replace(/\n{3,}/g, `
|
|
1525
1525
|
|
|
1526
1526
|
`).replace(/[ \t]+\n/g, `
|
|
1527
1527
|
`).trimEnd();
|
|
@@ -1545,35 +1545,35 @@ const W = class O {
|
|
|
1545
1545
|
};
|
|
1546
1546
|
}
|
|
1547
1547
|
deleteUsingDirection(e) {
|
|
1548
|
-
const t = this.textModel.getText(), { startOffset: i, endOffset:
|
|
1549
|
-
if (
|
|
1550
|
-
this.replaceOffsetsWithText(
|
|
1548
|
+
const t = this.textModel.getText(), { startOffset: i, endOffset: n } = this.getActiveSelectionOffsets(t), s = Math.min(i, n), r = Math.max(i, n);
|
|
1549
|
+
if (s !== r) {
|
|
1550
|
+
this.replaceOffsetsWithText(s, r, "");
|
|
1551
1551
|
return;
|
|
1552
1552
|
}
|
|
1553
1553
|
if (e === "backward") {
|
|
1554
|
-
if (
|
|
1554
|
+
if (s === 0)
|
|
1555
1555
|
return;
|
|
1556
|
-
this.replaceOffsetsWithText(
|
|
1556
|
+
this.replaceOffsetsWithText(s - 1, s, "");
|
|
1557
1557
|
return;
|
|
1558
1558
|
}
|
|
1559
1559
|
r >= t.length || this.replaceOffsetsWithText(r, r + 1, "");
|
|
1560
1560
|
}
|
|
1561
1561
|
replaceOffsetsWithText(e, t, i) {
|
|
1562
|
-
var
|
|
1562
|
+
var f;
|
|
1563
1563
|
this.ensureEditableSurfaceIsUnfolded();
|
|
1564
|
-
const
|
|
1565
|
-
`),
|
|
1564
|
+
const n = i.replace(/\r\n?/g, `
|
|
1565
|
+
`), 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
1566
|
{
|
|
1567
1567
|
start: this.textModel.offsetToPosition(a),
|
|
1568
1568
|
end: this.textModel.offsetToPosition(h)
|
|
1569
1569
|
},
|
|
1570
|
-
|
|
1570
|
+
n
|
|
1571
1571
|
);
|
|
1572
1572
|
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(
|
|
1573
|
+
const g = a + n.length;
|
|
1574
|
+
return this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), this.setCursor(this.textModel.offsetToPosition(g)), setTimeout(() => {
|
|
1575
1575
|
this.expectingProgrammaticCursor = !1;
|
|
1576
|
-
}, 20), this.emit("change", [
|
|
1576
|
+
}, 20), this.emit("change", [c]), c;
|
|
1577
1577
|
}
|
|
1578
1578
|
ensureEditableSurfaceIsUnfolded() {
|
|
1579
1579
|
!this.hasRenderedFoldPlaceholders() && this.folds.length === 0 || (this.clearPendingHighlightRender(), this.folds = [], this.expectingProgrammaticCursor = !0, this.renderTextWithHighlight(this.textModel.getText(), !1), setTimeout(() => {
|
|
@@ -1606,9 +1606,9 @@ const W = class O {
|
|
|
1606
1606
|
return;
|
|
1607
1607
|
}
|
|
1608
1608
|
const e = [], t = [], i = [];
|
|
1609
|
-
for (const [
|
|
1610
|
-
for (const r of
|
|
1611
|
-
const o = `${
|
|
1609
|
+
for (const [n, s] of this.decorationLayers.entries())
|
|
1610
|
+
for (const r of s) {
|
|
1611
|
+
const o = `${n}::${r.id}`;
|
|
1612
1612
|
if (r.type === "line") {
|
|
1613
1613
|
e.push({
|
|
1614
1614
|
...r,
|
|
@@ -1661,28 +1661,28 @@ const W = class O {
|
|
|
1661
1661
|
}
|
|
1662
1662
|
if (this.clearInlineDecorationHighlights(), e.length === 0)
|
|
1663
1663
|
return;
|
|
1664
|
-
const
|
|
1664
|
+
const n = this.textModel.getText(), s = [];
|
|
1665
1665
|
let r = 0;
|
|
1666
1666
|
for (const l of e) {
|
|
1667
1667
|
if (r >= this.decorationHighlightLimit)
|
|
1668
1668
|
break;
|
|
1669
|
-
const a = this.normalizeInlineDecoration(l,
|
|
1669
|
+
const a = this.normalizeInlineDecoration(l, n);
|
|
1670
1670
|
if (!a)
|
|
1671
1671
|
continue;
|
|
1672
1672
|
const h = this.view.createDomRangeFromRange(a.range);
|
|
1673
1673
|
if (!h)
|
|
1674
1674
|
continue;
|
|
1675
|
-
const
|
|
1675
|
+
const c = this.buildInlineDecorationHighlightName(
|
|
1676
1676
|
a.id
|
|
1677
1677
|
);
|
|
1678
|
-
t.highlights.set(
|
|
1679
|
-
::highlight(${
|
|
1678
|
+
t.highlights.set(c, new i(h)), this.inlineDecorationHighlightNames.add(c), s.push(`
|
|
1679
|
+
::highlight(${c}) {
|
|
1680
1680
|
${this.serializeInlineDecorationStyle(a.style)}
|
|
1681
1681
|
}
|
|
1682
1682
|
`), r += 1;
|
|
1683
1683
|
}
|
|
1684
1684
|
const o = this.ensureDecorationHighlightStyleNode();
|
|
1685
|
-
o.textContent =
|
|
1685
|
+
o.textContent = s.join(`
|
|
1686
1686
|
`);
|
|
1687
1687
|
}
|
|
1688
1688
|
normalizeInlineDecoration(e, t) {
|
|
@@ -1700,11 +1700,11 @@ const W = class O {
|
|
|
1700
1700
|
try {
|
|
1701
1701
|
const i = CSS;
|
|
1702
1702
|
if (i.highlights)
|
|
1703
|
-
for (const
|
|
1704
|
-
i.highlights.delete(
|
|
1703
|
+
for (const n of this.inlineDecorationHighlightNames)
|
|
1704
|
+
i.highlights.delete(n);
|
|
1705
1705
|
} catch (i) {
|
|
1706
1706
|
}
|
|
1707
|
-
if (this.inlineDecorationHighlightNames.clear(), typeof document
|
|
1707
|
+
if (this.inlineDecorationHighlightNames.clear(), typeof document == "undefined")
|
|
1708
1708
|
return;
|
|
1709
1709
|
const t = document.getElementById(this.decorationHighlightStyleId);
|
|
1710
1710
|
if (e) {
|
|
@@ -1720,7 +1720,7 @@ const W = class O {
|
|
|
1720
1720
|
return e || (e = document.createElement("style"), e.id = this.decorationHighlightStyleId, document.head.appendChild(e), e);
|
|
1721
1721
|
}
|
|
1722
1722
|
observeDecorationRelevantMutations() {
|
|
1723
|
-
typeof MutationObserver
|
|
1723
|
+
typeof MutationObserver != "undefined" && (this.decorationMutationObserver = new MutationObserver(() => {
|
|
1724
1724
|
this.decorationLayers.size !== 0 && this.scheduleDecorationRender();
|
|
1725
1725
|
}), this.decorationMutationObserver.observe(this.view.getContentElement(), {
|
|
1726
1726
|
childList: !0,
|
|
@@ -1730,7 +1730,7 @@ const W = class O {
|
|
|
1730
1730
|
}
|
|
1731
1731
|
detectCustomHighlightSupport() {
|
|
1732
1732
|
try {
|
|
1733
|
-
if (typeof CSS
|
|
1733
|
+
if (typeof CSS == "undefined" || typeof window == "undefined")
|
|
1734
1734
|
return !1;
|
|
1735
1735
|
const e = CSS, t = window.Highlight;
|
|
1736
1736
|
return !!e.highlights && !!t;
|
|
@@ -1745,7 +1745,8 @@ const W = class O {
|
|
|
1745
1745
|
return e.toLowerCase().replace(/[^a-z0-9_-]+/g, "-");
|
|
1746
1746
|
}
|
|
1747
1747
|
serializeInlineDecorationStyle(e) {
|
|
1748
|
-
|
|
1748
|
+
const t = this.serializeStyleObject(e);
|
|
1749
|
+
return t || "background-color: var(--lce-inline-decoration-bg, rgba(86, 156, 214, 0.18)); border-radius: 2px;";
|
|
1749
1750
|
}
|
|
1750
1751
|
serializeStyleObject(e) {
|
|
1751
1752
|
return e ? Object.entries(e).filter(([, t]) => typeof t == "string" && t.length > 0).map(([t, i]) => `${this.toKebabCase(t)}: ${i};`).join(" ") : "";
|
|
@@ -1767,9 +1768,9 @@ const W = class O {
|
|
|
1767
1768
|
};
|
|
1768
1769
|
}
|
|
1769
1770
|
};
|
|
1770
|
-
|
|
1771
|
-
let
|
|
1772
|
-
class
|
|
1771
|
+
L.CURSOR_SENTINEL = "";
|
|
1772
|
+
let V = L;
|
|
1773
|
+
class X {
|
|
1773
1774
|
constructor(e) {
|
|
1774
1775
|
this.name = "keymap", this.editor = null, this.keymap = {}, this.isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0, this.keymap = e || this.getDefaultKeymap();
|
|
1775
1776
|
}
|
|
@@ -1783,11 +1784,11 @@ class J {
|
|
|
1783
1784
|
return this.editor.executeCommand(t.command), e.preventDefault(), e.stopPropagation(), !1;
|
|
1784
1785
|
}
|
|
1785
1786
|
findMatchingBinding(e) {
|
|
1786
|
-
const { key: t, ctrlKey: i, altKey:
|
|
1787
|
+
const { key: t, ctrlKey: i, altKey: n, shiftKey: s, metaKey: r } = e, o = String(t).toLowerCase(), l = this.keymap[o];
|
|
1787
1788
|
if (!l) return null;
|
|
1788
1789
|
for (const a of l) {
|
|
1789
|
-
const h = a.ctrlKey === void 0 || a.ctrlKey === i,
|
|
1790
|
-
if (h &&
|
|
1790
|
+
const h = a.ctrlKey === void 0 || a.ctrlKey === i, c = a.altKey === void 0 || a.altKey === n, g = a.shiftKey === void 0 || a.shiftKey === s, f = a.metaKey === void 0 || a.metaKey === r;
|
|
1791
|
+
if (h && c && g && f)
|
|
1791
1792
|
return a;
|
|
1792
1793
|
}
|
|
1793
1794
|
return null;
|
|
@@ -1800,11 +1801,11 @@ class J {
|
|
|
1800
1801
|
const e = {};
|
|
1801
1802
|
return this.addBinding(e, "f", { ctrlKey: !this.isMac, metaKey: this.isMac }, "find"), this.addBinding(e, "h", { ctrlKey: !this.isMac, metaKey: this.isMac }, "replace"), this.addBinding(e, "f3", {}, "findNext"), this.addBinding(e, "f3", { shiftKey: !0 }, "findPrev"), this.addBinding(e, "g", { ctrlKey: !this.isMac, metaKey: this.isMac }, "findNext"), this.addBinding(e, "[", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "fold"), this.addBinding(e, "]", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "unfold"), this.addBinding(e, "s", { ctrlKey: !0 }, "save"), this.addBinding(e, "s", { metaKey: !0 }, "save"), this.addBinding(e, "z", { ctrlKey: !0 }, "undo"), this.addBinding(e, "z", { metaKey: !0 }, "undo"), this.addBinding(e, "y", { ctrlKey: !0 }, "redo"), this.addBinding(e, "y", { metaKey: !0 }, "redo"), this.addBinding(e, "z", { ctrlKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "z", { metaKey: !0, shiftKey: !0 }, "redo"), this.addBinding(e, "tab", {}, "insertTab"), this.addBinding(e, "t", { ctrlKey: !this.isMac, metaKey: this.isMac, shiftKey: !0 }, "toggleTheme"), this.addBinding(e, "f", { altKey: !0, shiftKey: !0 }, "formatDocument"), e;
|
|
1802
1803
|
}
|
|
1803
|
-
addBinding(e, t, i,
|
|
1804
|
-
const
|
|
1805
|
-
e[
|
|
1806
|
-
key:
|
|
1807
|
-
command:
|
|
1804
|
+
addBinding(e, t, i, n) {
|
|
1805
|
+
const s = t.toLowerCase();
|
|
1806
|
+
e[s] || (e[s] = []), e[s].push({
|
|
1807
|
+
key: s,
|
|
1808
|
+
command: n,
|
|
1808
1809
|
...i
|
|
1809
1810
|
});
|
|
1810
1811
|
}
|
|
@@ -1821,7 +1822,7 @@ class J {
|
|
|
1821
1822
|
}
|
|
1822
1823
|
removeKeyBinding(e, t) {
|
|
1823
1824
|
const i = e.toLowerCase();
|
|
1824
|
-
t ? this.keymap[i] && (this.keymap[i] = this.keymap[i].filter((
|
|
1825
|
+
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
1826
|
}
|
|
1826
1827
|
getKeymap() {
|
|
1827
1828
|
return { ...this.keymap };
|
|
@@ -1829,8 +1830,8 @@ class J {
|
|
|
1829
1830
|
getBindingsForCommand(e) {
|
|
1830
1831
|
const t = [];
|
|
1831
1832
|
for (const i in this.keymap)
|
|
1832
|
-
for (const
|
|
1833
|
-
|
|
1833
|
+
for (const n of this.keymap[i])
|
|
1834
|
+
n.command === e && t.push({ ...n });
|
|
1834
1835
|
return t;
|
|
1835
1836
|
}
|
|
1836
1837
|
getPlatformInfo() {
|
|
@@ -1843,7 +1844,7 @@ class J {
|
|
|
1843
1844
|
this.keymap = {}, this.editor = null;
|
|
1844
1845
|
}
|
|
1845
1846
|
}
|
|
1846
|
-
const
|
|
1847
|
+
const D = class D {
|
|
1847
1848
|
constructor() {
|
|
1848
1849
|
this.name = "transaction", this.transactions = [];
|
|
1849
1850
|
}
|
|
@@ -1855,9 +1856,9 @@ const U = class z {
|
|
|
1855
1856
|
effects: [],
|
|
1856
1857
|
annotations: []
|
|
1857
1858
|
};
|
|
1858
|
-
this.transactions.push(i), this.transactions.length >
|
|
1859
|
+
this.transactions.push(i), this.transactions.length > D.MAX_TRANSACTIONS && this.transactions.splice(
|
|
1859
1860
|
0,
|
|
1860
|
-
this.transactions.length -
|
|
1861
|
+
this.transactions.length - D.MAX_TRANSACTIONS
|
|
1861
1862
|
);
|
|
1862
1863
|
});
|
|
1863
1864
|
}
|
|
@@ -1868,9 +1869,9 @@ const U = class z {
|
|
|
1868
1869
|
this.transactions = [];
|
|
1869
1870
|
}
|
|
1870
1871
|
};
|
|
1871
|
-
|
|
1872
|
-
let
|
|
1873
|
-
class
|
|
1872
|
+
D.MAX_TRANSACTIONS = 200;
|
|
1873
|
+
let W = D;
|
|
1874
|
+
class J {
|
|
1874
1875
|
constructor() {
|
|
1875
1876
|
this.name = "line-numbers", this.editor = null, this.lineNumbersElement = null, this.isEnabled = !0;
|
|
1876
1877
|
}
|
|
@@ -1899,7 +1900,7 @@ class te {
|
|
|
1899
1900
|
this.lineNumbersElement = null, this.editor = null;
|
|
1900
1901
|
}
|
|
1901
1902
|
}
|
|
1902
|
-
class
|
|
1903
|
+
class ee {
|
|
1903
1904
|
constructor() {
|
|
1904
1905
|
this.name = "theme", this.editor = null, this.currentTheme = "dark";
|
|
1905
1906
|
}
|
|
@@ -1924,7 +1925,7 @@ class ie {
|
|
|
1924
1925
|
this.editor = null;
|
|
1925
1926
|
}
|
|
1926
1927
|
}
|
|
1927
|
-
class
|
|
1928
|
+
class te {
|
|
1928
1929
|
constructor() {
|
|
1929
1930
|
this.name = "read-only", this.editor = null, this.isReadOnly = !1;
|
|
1930
1931
|
}
|
|
@@ -1951,14 +1952,14 @@ class se {
|
|
|
1951
1952
|
this.editor = null;
|
|
1952
1953
|
}
|
|
1953
1954
|
}
|
|
1954
|
-
let
|
|
1955
|
-
const
|
|
1955
|
+
let ie = 0;
|
|
1956
|
+
const y = class y {
|
|
1956
1957
|
constructor(e = {}) {
|
|
1957
1958
|
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
1959
|
caseSensitive: !1,
|
|
1959
1960
|
wholeWord: !1,
|
|
1960
1961
|
regex: !1
|
|
1961
|
-
}, this.trailingMarkerAttr = "data-lce-trailing-newline-marker", this.editorContainerSelector = '[data-lce-editor-container="true"]', this.highlightId = ++
|
|
1962
|
+
}, this.trailingMarkerAttr = "data-lce-trailing-newline-marker", this.editorContainerSelector = '[data-lce-editor-container="true"]', this.highlightId = ++ie, this.highlightMatchName = `editora-search-match-${this.highlightId}`, this.highlightActiveName = `editora-search-active-${this.highlightId}`, this.highlightStyleId = `editora-search-highlight-style-${this.highlightId}`, this.maxCustomHighlightRanges = 2e3, this.virtualMarkerRegex = /[\u200B\uE000]/, this.hasCustomHighlightSupport = !1, this.config = {
|
|
1962
1963
|
replaceAndFindNext: !0,
|
|
1963
1964
|
...e
|
|
1964
1965
|
};
|
|
@@ -1991,9 +1992,9 @@ const K = class y {
|
|
|
1991
1992
|
if (!this.editor) return;
|
|
1992
1993
|
const e = this.editor.getView().getContentElement(), t = e.closest(
|
|
1993
1994
|
this.editorContainerSelector
|
|
1994
|
-
), i = t == null ? void 0 : t.parentElement,
|
|
1995
|
-
if (!
|
|
1996
|
-
window.getComputedStyle(
|
|
1995
|
+
), i = t == null ? void 0 : t.parentElement, n = e.closest(".rte-source-editor-modal") || i || t || e.parentElement;
|
|
1996
|
+
if (!n) return;
|
|
1997
|
+
window.getComputedStyle(n).position === "static" && (n.style.position = "relative"), this.searchUI = document.createElement("div"), this.searchUI.className = y.css.root, this.searchUI.style.display = "none", this.searchUI.innerHTML = `
|
|
1997
1998
|
<div class="${y.css.row}">
|
|
1998
1999
|
<input type="text" class="${y.css.findInput} ${y.css.inputBase}" placeholder="Find..." />
|
|
1999
2000
|
<button class="${y.css.prevButton} ${y.css.buttonBase}" type="button" aria-label="Previous match">↑</button>
|
|
@@ -2020,7 +2021,7 @@ const K = class y {
|
|
|
2020
2021
|
</div>
|
|
2021
2022
|
<input type="text" class="${y.css.replaceInput} ${y.css.inputBase} ${y.css.replaceInputLayout}" placeholder="Replace with..." />
|
|
2022
2023
|
`;
|
|
2023
|
-
const
|
|
2024
|
+
const s = this.searchUI.querySelector(
|
|
2024
2025
|
`.${y.css.findInput}`
|
|
2025
2026
|
), r = this.searchUI.querySelector(
|
|
2026
2027
|
`.${y.css.replaceInput}`
|
|
@@ -2032,32 +2033,32 @@ const K = class y {
|
|
|
2032
2033
|
`.${y.css.closeButton}`
|
|
2033
2034
|
), h = this.searchUI.querySelector(
|
|
2034
2035
|
`.${y.css.status}`
|
|
2035
|
-
), d = this.searchUI.querySelector(
|
|
2036
|
-
`.${y.css.mode}`
|
|
2037
2036
|
), c = this.searchUI.querySelector(
|
|
2037
|
+
`.${y.css.mode}`
|
|
2038
|
+
), g = this.searchUI.querySelector(
|
|
2038
2039
|
`.${y.css.caseSensitive}`
|
|
2039
|
-
),
|
|
2040
|
+
), f = this.searchUI.querySelector(
|
|
2040
2041
|
`.${y.css.wholeWord}`
|
|
2041
|
-
),
|
|
2042
|
+
), d = this.searchUI.querySelector(
|
|
2042
2043
|
`.${y.css.regex}`
|
|
2043
2044
|
);
|
|
2044
|
-
this.findInput =
|
|
2045
|
+
this.findInput = s, this.replaceInputEl = r, this.statusDiv = h, this.modeDiv = c, this.caseSensitiveInput = g, this.wholeWordInput = f, this.regexInput = d, g.checked = !!this.searchOptions.caseSensitive, f.checked = !!this.searchOptions.wholeWord, d.checked = !!this.searchOptions.regex, s.addEventListener("input", () => {
|
|
2045
2046
|
this.searchDebounceTimer && clearTimeout(this.searchDebounceTimer);
|
|
2046
|
-
const p =
|
|
2047
|
+
const p = s.value;
|
|
2047
2048
|
this.searchDebounceTimer = setTimeout(() => {
|
|
2048
2049
|
this.performSearch(p, !1, !1);
|
|
2049
2050
|
}, 120);
|
|
2050
2051
|
});
|
|
2051
|
-
const
|
|
2052
|
-
this.searchOptions.caseSensitive =
|
|
2053
|
-
const p =
|
|
2052
|
+
const u = () => {
|
|
2053
|
+
this.searchOptions.caseSensitive = g.checked, this.searchOptions.wholeWord = f.checked, this.searchOptions.regex = d.checked;
|
|
2054
|
+
const p = s.value;
|
|
2054
2055
|
p.trim() ? this.performSearch(p, !1, !1) : this.performSearch("", !1, !1);
|
|
2055
2056
|
};
|
|
2056
|
-
|
|
2057
|
+
g.addEventListener("change", u), f.addEventListener("change", u), d.addEventListener("change", u), s.addEventListener("keydown", (p) => {
|
|
2057
2058
|
p.key === "Enter" ? (p.preventDefault(), p.shiftKey ? this.findPrev() : this.findNext()) : p.key === "Escape" && (p.preventDefault(), this.hideSearch());
|
|
2058
2059
|
}), 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()),
|
|
2060
|
+
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());
|
|
2061
|
+
}), o.addEventListener("click", () => this.findPrev()), l.addEventListener("click", () => this.findNext()), a.addEventListener("click", () => this.hideSearch()), n.appendChild(this.searchUI);
|
|
2061
2062
|
}
|
|
2062
2063
|
updateModeHint(e) {
|
|
2063
2064
|
this.modeDiv && (this.modeDiv.textContent = e ? `Replace: move next ${this.config.replaceAndFindNext ? "ON" : "OFF"}` : "Find mode");
|
|
@@ -2072,12 +2073,12 @@ const K = class y {
|
|
|
2072
2073
|
return;
|
|
2073
2074
|
}
|
|
2074
2075
|
this.currentQuery = e;
|
|
2075
|
-
const
|
|
2076
|
-
if (this.currentResults =
|
|
2076
|
+
const n = this.currentIndex, s = this.editor.search(e, this.searchOptions);
|
|
2077
|
+
if (this.currentResults = s, s.length === 0) {
|
|
2077
2078
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("No matches");
|
|
2078
2079
|
return;
|
|
2079
2080
|
}
|
|
2080
|
-
t &&
|
|
2081
|
+
t && n >= 0 ? this.currentIndex = Math.min(n, s.length - 1) : this.currentIndex = 0, this.updateHighlights(i);
|
|
2081
2082
|
}
|
|
2082
2083
|
findNext() {
|
|
2083
2084
|
if (this.currentResults.length === 0) {
|
|
@@ -2097,17 +2098,17 @@ const K = class y {
|
|
|
2097
2098
|
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
2099
|
const i = this.currentResults[this.currentIndex];
|
|
2099
2100
|
if (!i) return;
|
|
2100
|
-
const
|
|
2101
|
+
const n = this.computeReplacementRange(i.range.start, t);
|
|
2101
2102
|
if (this.editor.replace(i.range, t), this.config.replaceAndFindNext) {
|
|
2102
2103
|
this.currentQuery = e;
|
|
2103
|
-
const
|
|
2104
|
-
if (this.currentResults =
|
|
2104
|
+
const s = this.editor.search(e, this.searchOptions);
|
|
2105
|
+
if (this.currentResults = s, s.length === 0) {
|
|
2105
2106
|
this.currentIndex = -1, this.clearHighlights(), this.updateStatus("Replaced current occurrence"), this.restoreReplaceInputFocus();
|
|
2106
2107
|
return;
|
|
2107
2108
|
}
|
|
2108
|
-
this.currentIndex = this.findNextResultIndexAfter(
|
|
2109
|
+
this.currentIndex = this.findNextResultIndexAfter(n.end, s), this.updateHighlights(!0);
|
|
2109
2110
|
} else
|
|
2110
|
-
this.scrollLogicalRangeIntoView(
|
|
2111
|
+
this.scrollLogicalRangeIntoView(n, !0), this.performSearch(e, !0, !1);
|
|
2111
2112
|
this.currentResults.length > 0 || this.showTransientStatus("Replaced current occurrence"), this.restoreReplaceInputFocus(), this.revealActiveResultAfterFocusRestore();
|
|
2112
2113
|
}
|
|
2113
2114
|
replaceAll(e, t) {
|
|
@@ -2126,10 +2127,10 @@ const K = class y {
|
|
|
2126
2127
|
}
|
|
2127
2128
|
navigateToResult(e, t) {
|
|
2128
2129
|
if (!this.editor) return;
|
|
2129
|
-
const i = document.activeElement,
|
|
2130
|
+
const i = document.activeElement, n = !!i && (i === this.findInput || i === this.replaceInputEl);
|
|
2130
2131
|
t ? (this.editor.setSelection(e.range), this.centerCurrentSelectionInView()) : this.scrollResultIntoView(e);
|
|
2131
|
-
const
|
|
2132
|
-
t && typeof
|
|
2132
|
+
const s = this.editor.getView();
|
|
2133
|
+
t && typeof s.ensureCaretVisible == "function" && s.ensureCaretVisible(), t && n && i && requestAnimationFrame(() => {
|
|
2133
2134
|
this.focusWithoutScrolling(i);
|
|
2134
2135
|
});
|
|
2135
2136
|
}
|
|
@@ -2147,18 +2148,18 @@ const K = class y {
|
|
|
2147
2148
|
}
|
|
2148
2149
|
scrollLogicalRangeIntoView(e, t) {
|
|
2149
2150
|
if (!this.editor) return;
|
|
2150
|
-
const i = this.editor.getView().getContentElement(),
|
|
2151
|
+
const i = this.editor.getView().getContentElement(), n = this.editor.getValue(), { lineStarts: s, lines: r } = this.buildLineStarts(n), o = this.buildTextNodeIndex(i);
|
|
2151
2152
|
if (o.length === 0) return;
|
|
2152
|
-
const l = this.toDomRange(e,
|
|
2153
|
+
const l = this.toDomRange(e, s, r, o);
|
|
2153
2154
|
if (!l) return;
|
|
2154
2155
|
const a = l.startContainer.nodeType === Node.TEXT_NODE ? l.startContainer.parentElement : l.startContainer, h = this.resolveScrollContainer(i);
|
|
2155
2156
|
if (h) {
|
|
2156
|
-
const
|
|
2157
|
-
let
|
|
2158
|
-
const
|
|
2159
|
-
|
|
2160
|
-
const
|
|
2161
|
-
if (
|
|
2157
|
+
const c = l.getClientRects()[0] || l.getBoundingClientRect(), g = h.getBoundingClientRect(), d = h.scrollTop + (c.top - g.top) - g.height / 2 + c.height / 2, u = 18;
|
|
2158
|
+
let p = t ? d : h.scrollTop, m = h.scrollLeft;
|
|
2159
|
+
const x = h.scrollLeft + (c.left - g.left), v = x + c.width;
|
|
2160
|
+
c.right > g.right - u ? m = v - g.width + u : c.left < g.left + u && (m = Math.max(0, x - u));
|
|
2161
|
+
const T = Math.max(0, h.scrollHeight - h.clientHeight), S = Math.max(0, h.scrollWidth - h.clientWidth);
|
|
2162
|
+
if (p = Math.min(T, Math.max(0, p)), m = Math.min(S, Math.max(0, m)), T === 0 && S === 0) {
|
|
2162
2163
|
a == null || a.scrollIntoView({
|
|
2163
2164
|
block: t ? "center" : "nearest",
|
|
2164
2165
|
inline: "nearest",
|
|
@@ -2166,9 +2167,9 @@ const K = class y {
|
|
|
2166
2167
|
});
|
|
2167
2168
|
return;
|
|
2168
2169
|
}
|
|
2169
|
-
(
|
|
2170
|
-
top:
|
|
2171
|
-
left:
|
|
2170
|
+
(p !== h.scrollTop || m !== h.scrollLeft) && h.scrollTo({
|
|
2171
|
+
top: p,
|
|
2172
|
+
left: m,
|
|
2172
2173
|
behavior: "smooth"
|
|
2173
2174
|
});
|
|
2174
2175
|
return;
|
|
@@ -2196,32 +2197,32 @@ const K = class y {
|
|
|
2196
2197
|
if (!t) return;
|
|
2197
2198
|
const i = window.getSelection();
|
|
2198
2199
|
if (!i || i.rangeCount === 0) return;
|
|
2199
|
-
const
|
|
2200
|
-
if (!
|
|
2201
|
-
const r = t.getBoundingClientRect(),
|
|
2202
|
-
|
|
2203
|
-
top:
|
|
2200
|
+
const n = i.getRangeAt(0).cloneRange(), s = n.getClientRects()[0] || n.getBoundingClientRect();
|
|
2201
|
+
if (!s) return;
|
|
2202
|
+
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));
|
|
2203
|
+
h !== t.scrollTop && t.scrollTo({
|
|
2204
|
+
top: h,
|
|
2204
2205
|
behavior: "smooth"
|
|
2205
2206
|
});
|
|
2206
2207
|
}
|
|
2207
2208
|
computeReplacementRange(e, t) {
|
|
2208
2209
|
const i = t.replace(/\r\n?/g, `
|
|
2209
|
-
`),
|
|
2210
|
+
`), n = i.split(`
|
|
2210
2211
|
`);
|
|
2211
|
-
let
|
|
2212
|
-
return
|
|
2212
|
+
let s;
|
|
2213
|
+
return n.length <= 1 ? (s = {
|
|
2213
2214
|
start: e,
|
|
2214
2215
|
end: {
|
|
2215
2216
|
line: e.line,
|
|
2216
2217
|
column: e.column + i.length
|
|
2217
2218
|
}
|
|
2218
|
-
}, this.clampRangeToDocument(
|
|
2219
|
+
}, this.clampRangeToDocument(s)) : (s = {
|
|
2219
2220
|
start: e,
|
|
2220
2221
|
end: {
|
|
2221
|
-
line: e.line +
|
|
2222
|
-
column:
|
|
2222
|
+
line: e.line + n.length - 1,
|
|
2223
|
+
column: n[n.length - 1].length
|
|
2223
2224
|
}
|
|
2224
|
-
}, this.clampRangeToDocument(
|
|
2225
|
+
}, this.clampRangeToDocument(s));
|
|
2225
2226
|
}
|
|
2226
2227
|
findNextResultIndexAfter(e, t) {
|
|
2227
2228
|
for (let i = 0; i < t.length; i++)
|
|
@@ -2237,15 +2238,15 @@ const K = class y {
|
|
|
2237
2238
|
const t = this.editor;
|
|
2238
2239
|
if (!t) return e;
|
|
2239
2240
|
const i = t.getValue().split(`
|
|
2240
|
-
`),
|
|
2241
|
+
`), 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
2242
|
0,
|
|
2242
|
-
Math.min(e.start.column, ((a = i[
|
|
2243
|
+
Math.min(e.start.column, ((a = i[s]) == null ? void 0 : a.length) || 0)
|
|
2243
2244
|
), l = Math.max(
|
|
2244
2245
|
0,
|
|
2245
2246
|
Math.min(e.end.column, ((h = i[r]) == null ? void 0 : h.length) || 0)
|
|
2246
2247
|
);
|
|
2247
2248
|
return {
|
|
2248
|
-
start: { line:
|
|
2249
|
+
start: { line: s, column: o },
|
|
2249
2250
|
end: { line: r, column: l }
|
|
2250
2251
|
};
|
|
2251
2252
|
}
|
|
@@ -2256,36 +2257,36 @@ const K = class y {
|
|
|
2256
2257
|
});
|
|
2257
2258
|
} catch (t) {
|
|
2258
2259
|
const i = [];
|
|
2259
|
-
let
|
|
2260
|
-
for (;
|
|
2261
|
-
this.canScroll(
|
|
2262
|
-
el:
|
|
2263
|
-
top:
|
|
2264
|
-
left:
|
|
2265
|
-
}),
|
|
2266
|
-
const
|
|
2260
|
+
let n = e.parentElement;
|
|
2261
|
+
for (; n; )
|
|
2262
|
+
this.canScroll(n) && i.push({
|
|
2263
|
+
el: n,
|
|
2264
|
+
top: n.scrollTop,
|
|
2265
|
+
left: n.scrollLeft
|
|
2266
|
+
}), n = n.parentElement;
|
|
2267
|
+
const s = window.scrollX, r = window.scrollY;
|
|
2267
2268
|
e.focus();
|
|
2268
2269
|
for (let o = 0; o < i.length; o++) {
|
|
2269
2270
|
const l = i[o];
|
|
2270
2271
|
l.el.scrollTop = l.top, l.el.scrollLeft = l.left;
|
|
2271
2272
|
}
|
|
2272
|
-
window.scrollTo(
|
|
2273
|
+
window.scrollTo(s, r);
|
|
2273
2274
|
}
|
|
2274
2275
|
}
|
|
2275
2276
|
findScrollContainer(e) {
|
|
2276
2277
|
let t = e;
|
|
2277
2278
|
for (; t; ) {
|
|
2278
|
-
const
|
|
2279
|
-
if ((
|
|
2279
|
+
const n = window.getComputedStyle(t).overflowY;
|
|
2280
|
+
if ((n === "auto" || n === "scroll") && t.scrollHeight > t.clientHeight)
|
|
2280
2281
|
return t;
|
|
2281
2282
|
t = t.parentElement;
|
|
2282
2283
|
}
|
|
2283
2284
|
return null;
|
|
2284
2285
|
}
|
|
2285
2286
|
resolveScrollContainer(e) {
|
|
2286
|
-
var
|
|
2287
|
-
const t = (
|
|
2288
|
-
return
|
|
2287
|
+
var n, s;
|
|
2288
|
+
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;
|
|
2289
|
+
return i && this.canScroll(i) ? i : this.findScrollContainer(e);
|
|
2289
2290
|
}
|
|
2290
2291
|
canScroll(e) {
|
|
2291
2292
|
return e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth;
|
|
@@ -2299,123 +2300,122 @@ const K = class y {
|
|
|
2299
2300
|
applyCustomHighlights() {
|
|
2300
2301
|
if (!this.editor || !this.hasCustomHighlightSupport || this.currentResults.length === 0)
|
|
2301
2302
|
return;
|
|
2302
|
-
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines:
|
|
2303
|
-
if (
|
|
2304
|
-
const r = this.buildVisibleDocumentText(
|
|
2303
|
+
const e = this.editor.getView().getContentElement(), t = this.editor.getValue(), { lineStarts: i, lines: n } = this.buildLineStarts(t), s = this.buildTextNodeIndex(e);
|
|
2304
|
+
if (s.length === 0) return;
|
|
2305
|
+
const r = this.buildVisibleDocumentText(s), o = [];
|
|
2305
2306
|
let l = null;
|
|
2306
2307
|
const a = Math.min(this.currentResults.length, this.maxCustomHighlightRanges);
|
|
2307
2308
|
for (let h = 0; h < a; h++) {
|
|
2308
|
-
const
|
|
2309
|
-
|
|
2309
|
+
const c = this.currentResults[h], g = this.searchOptions.regex ? c.match || this.currentQuery : this.currentQuery || c.match, f = this.toDomRange(
|
|
2310
|
+
c.range,
|
|
2310
2311
|
i,
|
|
2311
|
-
s,
|
|
2312
2312
|
n,
|
|
2313
|
+
s,
|
|
2313
2314
|
r,
|
|
2314
|
-
|
|
2315
|
+
g
|
|
2315
2316
|
);
|
|
2316
|
-
|
|
2317
|
+
f && (o.push(f), h === this.currentIndex && (l = f));
|
|
2317
2318
|
}
|
|
2318
2319
|
if (o.length !== 0)
|
|
2319
2320
|
try {
|
|
2320
|
-
const h = CSS,
|
|
2321
|
-
if (!h.highlights || !
|
|
2322
|
-
h.highlights.set(this.highlightMatchName, new
|
|
2321
|
+
const h = CSS, c = window.Highlight;
|
|
2322
|
+
if (!h.highlights || !c) return;
|
|
2323
|
+
h.highlights.set(this.highlightMatchName, new c(...o)), l && h.highlights.set(this.highlightActiveName, new c(l));
|
|
2323
2324
|
} catch (h) {
|
|
2324
2325
|
}
|
|
2325
2326
|
}
|
|
2326
2327
|
buildLineStarts(e) {
|
|
2327
2328
|
const t = e.split(`
|
|
2328
2329
|
`), i = new Array(t.length);
|
|
2329
|
-
let
|
|
2330
|
-
for (let
|
|
2331
|
-
i[
|
|
2330
|
+
let n = 0;
|
|
2331
|
+
for (let s = 0; s < t.length; s++)
|
|
2332
|
+
i[s] = n, n += t[s].length + 1;
|
|
2332
2333
|
return { lineStarts: i, lines: t };
|
|
2333
2334
|
}
|
|
2334
2335
|
positionToOffset(e, t, i) {
|
|
2335
2336
|
var r;
|
|
2336
|
-
const
|
|
2337
|
-
return t[
|
|
2337
|
+
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));
|
|
2338
|
+
return t[n] + s;
|
|
2338
2339
|
}
|
|
2339
2340
|
buildTextNodeIndex(e) {
|
|
2340
|
-
var r;
|
|
2341
2341
|
const t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, null), i = [];
|
|
2342
|
-
let
|
|
2343
|
-
for (;
|
|
2344
|
-
const o =
|
|
2345
|
-
if (
|
|
2342
|
+
let n = 0, s;
|
|
2343
|
+
for (; s = t.nextNode(); ) {
|
|
2344
|
+
const r = s, o = r.parentElement;
|
|
2345
|
+
if (o != null && o.hasAttribute(this.trailingMarkerAttr))
|
|
2346
2346
|
continue;
|
|
2347
|
-
const l =
|
|
2347
|
+
const l = r.textContent || "", a = this.buildVisibleToDomMap(l), h = Math.max(0, a.length - 1);
|
|
2348
2348
|
h === 0 && l.length === 0 || (i.push({
|
|
2349
|
-
node:
|
|
2350
|
-
start:
|
|
2351
|
-
end:
|
|
2349
|
+
node: r,
|
|
2350
|
+
start: n,
|
|
2351
|
+
end: n + h,
|
|
2352
2352
|
visibleToDom: a
|
|
2353
|
-
}),
|
|
2353
|
+
}), n += h);
|
|
2354
2354
|
}
|
|
2355
2355
|
return i;
|
|
2356
2356
|
}
|
|
2357
2357
|
resolveDomPoint(e, t) {
|
|
2358
|
-
var
|
|
2358
|
+
var s, r, o, l, a, h;
|
|
2359
2359
|
const i = Math.max(0, e);
|
|
2360
|
-
for (let
|
|
2361
|
-
const
|
|
2362
|
-
if (i <=
|
|
2363
|
-
const
|
|
2360
|
+
for (let c = 0; c < t.length; c++) {
|
|
2361
|
+
const g = t[c];
|
|
2362
|
+
if (i <= g.end) {
|
|
2363
|
+
const f = Math.max(0, i - g.start), d = (o = (r = g.visibleToDom[f]) != null ? r : (s = g.node.textContent) == null ? void 0 : s.length) != null ? o : 0;
|
|
2364
2364
|
return {
|
|
2365
|
-
node:
|
|
2366
|
-
offset:
|
|
2365
|
+
node: g.node,
|
|
2366
|
+
offset: d
|
|
2367
2367
|
};
|
|
2368
2368
|
}
|
|
2369
2369
|
}
|
|
2370
|
-
const
|
|
2371
|
-
return
|
|
2372
|
-
node:
|
|
2373
|
-
offset: (h = (a =
|
|
2370
|
+
const n = t[t.length - 1];
|
|
2371
|
+
return n ? {
|
|
2372
|
+
node: n.node,
|
|
2373
|
+
offset: (h = (a = n.visibleToDom[n.visibleToDom.length - 1]) != null ? a : (l = n.node.textContent) == null ? void 0 : l.length) != null ? h : 0
|
|
2374
2374
|
} : null;
|
|
2375
2375
|
}
|
|
2376
|
-
toDomRange(e, t, i,
|
|
2376
|
+
toDomRange(e, t, i, n, s, r) {
|
|
2377
2377
|
const o = this.positionToOffset(e.start, t, i), l = this.positionToOffset(e.end, t, i);
|
|
2378
2378
|
let a = Math.min(o, l), h = Math.max(o, l);
|
|
2379
|
-
if (
|
|
2380
|
-
const
|
|
2381
|
-
if (
|
|
2379
|
+
if (s && r) {
|
|
2380
|
+
const d = r, u = s.slice(a, h);
|
|
2381
|
+
if (u.length === d.length && u.toLowerCase() !== d.toLowerCase()) {
|
|
2382
2382
|
const p = this.findNearestMatchOffset(
|
|
2383
|
-
|
|
2384
|
-
|
|
2383
|
+
s,
|
|
2384
|
+
d,
|
|
2385
2385
|
a
|
|
2386
2386
|
);
|
|
2387
|
-
p !== -1 && (a = p, h = p +
|
|
2387
|
+
p !== -1 && (a = p, h = p + d.length);
|
|
2388
2388
|
}
|
|
2389
2389
|
}
|
|
2390
|
-
const
|
|
2391
|
-
if (!
|
|
2392
|
-
const
|
|
2390
|
+
const c = this.resolveDomPoint(a, n), g = this.resolveDomPoint(h, n);
|
|
2391
|
+
if (!c || !g) return null;
|
|
2392
|
+
const f = document.createRange();
|
|
2393
2393
|
try {
|
|
2394
|
-
return
|
|
2395
|
-
} catch (
|
|
2394
|
+
return f.setStart(c.node, c.offset), f.setEnd(g.node, g.offset), f;
|
|
2395
|
+
} catch (d) {
|
|
2396
2396
|
return null;
|
|
2397
2397
|
}
|
|
2398
2398
|
}
|
|
2399
2399
|
buildVisibleDocumentText(e) {
|
|
2400
2400
|
let t = "";
|
|
2401
2401
|
for (let i = 0; i < e.length; i++) {
|
|
2402
|
-
const
|
|
2403
|
-
for (let
|
|
2404
|
-
const r = s
|
|
2402
|
+
const n = e[i].node.textContent || "";
|
|
2403
|
+
for (let s = 0; s < n.length; s++) {
|
|
2404
|
+
const r = n[s];
|
|
2405
2405
|
this.virtualMarkerRegex.test(r) || (t += r);
|
|
2406
2406
|
}
|
|
2407
2407
|
}
|
|
2408
2408
|
return t;
|
|
2409
2409
|
}
|
|
2410
2410
|
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
|
-
|
|
2411
|
+
const n = t.toLowerCase();
|
|
2412
|
+
let s = e.toLowerCase().indexOf(n);
|
|
2413
|
+
if (s === -1) return -1;
|
|
2414
|
+
let r = s, o = Math.abs(s - i);
|
|
2415
|
+
for (; s !== -1; ) {
|
|
2416
|
+
const l = Math.abs(s - i);
|
|
2417
|
+
if (l < o && (o = l, r = s), l === 0) return s;
|
|
2418
|
+
s = e.toLowerCase().indexOf(n, s + 1);
|
|
2419
2419
|
}
|
|
2420
2420
|
return r;
|
|
2421
2421
|
}
|
|
@@ -2477,9 +2477,9 @@ const K = class y {
|
|
|
2477
2477
|
buildVisibleToDomMap(e) {
|
|
2478
2478
|
const t = [0];
|
|
2479
2479
|
let i = 0;
|
|
2480
|
-
for (let
|
|
2481
|
-
const
|
|
2482
|
-
this.virtualMarkerRegex.test(
|
|
2480
|
+
for (let n = 0; n < e.length; n++) {
|
|
2481
|
+
const s = e[n];
|
|
2482
|
+
this.virtualMarkerRegex.test(s) || (i += 1, t[i] = n + 1);
|
|
2483
2483
|
}
|
|
2484
2484
|
return t;
|
|
2485
2485
|
}
|
|
@@ -2503,7 +2503,7 @@ const K = class y {
|
|
|
2503
2503
|
e != null && e.parentNode && e.parentNode.removeChild(e), this.editor = null;
|
|
2504
2504
|
}
|
|
2505
2505
|
};
|
|
2506
|
-
|
|
2506
|
+
y.css = {
|
|
2507
2507
|
root: "lce-search-ui",
|
|
2508
2508
|
row: "lce-search-row",
|
|
2509
2509
|
options: "lce-search-options",
|
|
@@ -2526,8 +2526,8 @@ K.css = {
|
|
|
2526
2526
|
mode: "search-mode",
|
|
2527
2527
|
modeLayout: "lce-search-mode"
|
|
2528
2528
|
};
|
|
2529
|
-
let
|
|
2530
|
-
class
|
|
2529
|
+
let U = y, ne = 0;
|
|
2530
|
+
class se {
|
|
2531
2531
|
constructor() {
|
|
2532
2532
|
this.name = "bracket-matching", this.editor = null, this.bracketPairs = {
|
|
2533
2533
|
"(": ")",
|
|
@@ -2539,7 +2539,7 @@ class le {
|
|
|
2539
2539
|
"]": "[",
|
|
2540
2540
|
"}": "{",
|
|
2541
2541
|
">": "<"
|
|
2542
|
-
}, this.highlightId = ++
|
|
2542
|
+
}, this.highlightId = ++ne, 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
2543
|
}
|
|
2544
2544
|
setup(e) {
|
|
2545
2545
|
this.editor = e, this.hasCustomHighlightSupport = this.detectCustomHighlightSupport(), this.hasCustomHighlightSupport && (this.ensureHighlightStyles(), this.observeContentMutations()), this.cursorHandler = () => {
|
|
@@ -2569,17 +2569,17 @@ class le {
|
|
|
2569
2569
|
this.clearBracketHighlighting();
|
|
2570
2570
|
const i = this.getBracketNearPosition(t, e.position);
|
|
2571
2571
|
if (!i) return;
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2572
|
+
const n = this.findMatchingBracket(t, i);
|
|
2573
|
+
n && (this.currentMatch = n, this.highlightBrackets(n));
|
|
2574
2574
|
}
|
|
2575
2575
|
getBracketNearPosition(e, t) {
|
|
2576
2576
|
const i = e.split(`
|
|
2577
2577
|
`);
|
|
2578
2578
|
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,
|
|
2579
|
+
const n = [{ line: t.line, column: t.column }];
|
|
2580
|
+
t.column > 0 && n.push({ line: t.line, column: t.column - 1 });
|
|
2581
|
+
for (const s of n) {
|
|
2582
|
+
const r = this.getBracketAtPosition(i, s);
|
|
2583
2583
|
if (r)
|
|
2584
2584
|
return r;
|
|
2585
2585
|
}
|
|
@@ -2589,47 +2589,47 @@ class le {
|
|
|
2589
2589
|
if (t.line < 0 || t.line >= e.length) return null;
|
|
2590
2590
|
const i = e[t.line];
|
|
2591
2591
|
if (t.column < 0 || t.column >= i.length) return null;
|
|
2592
|
-
const
|
|
2593
|
-
return this.bracketPairs[
|
|
2592
|
+
const n = i[t.column];
|
|
2593
|
+
return this.bracketPairs[n] || this.reverseBracketPairs[n] ? { char: n, position: t } : null;
|
|
2594
2594
|
}
|
|
2595
2595
|
findMatchingBracket(e, t) {
|
|
2596
2596
|
const i = e.split(`
|
|
2597
|
-
`),
|
|
2598
|
-
return this.bracketPairs[r] ? this.findClosingBracket(i,
|
|
2597
|
+
`), n = t.position.line, s = t.position.column, r = t.char;
|
|
2598
|
+
return this.bracketPairs[r] ? this.findClosingBracket(i, n, s, r) : this.reverseBracketPairs[r] ? this.findOpeningBracket(i, n, s, r) : null;
|
|
2599
2599
|
}
|
|
2600
|
-
findClosingBracket(e, t, i,
|
|
2601
|
-
const
|
|
2600
|
+
findClosingBracket(e, t, i, n) {
|
|
2601
|
+
const s = this.bracketPairs[n];
|
|
2602
2602
|
let r = 0;
|
|
2603
2603
|
for (let o = t; o < e.length; o++) {
|
|
2604
2604
|
const l = e[o], a = o === t ? i : 0;
|
|
2605
2605
|
for (let h = a; h < l.length; h++) {
|
|
2606
|
-
const
|
|
2607
|
-
if (
|
|
2606
|
+
const c = l[h];
|
|
2607
|
+
if (c === n)
|
|
2608
2608
|
r++;
|
|
2609
|
-
else if (
|
|
2609
|
+
else if (c === s && (r--, r === 0))
|
|
2610
2610
|
return {
|
|
2611
2611
|
open: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
|
|
2612
2612
|
close: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
|
|
2613
|
-
type:
|
|
2613
|
+
type: n
|
|
2614
2614
|
};
|
|
2615
2615
|
}
|
|
2616
2616
|
}
|
|
2617
2617
|
return null;
|
|
2618
2618
|
}
|
|
2619
|
-
findOpeningBracket(e, t, i,
|
|
2620
|
-
const
|
|
2619
|
+
findOpeningBracket(e, t, i, n) {
|
|
2620
|
+
const s = this.reverseBracketPairs[n];
|
|
2621
2621
|
let r = 0;
|
|
2622
2622
|
for (let o = t; o >= 0; o--) {
|
|
2623
2623
|
const l = e[o], a = o === t ? i : l.length - 1;
|
|
2624
2624
|
for (let h = a; h >= 0; h--) {
|
|
2625
|
-
const
|
|
2626
|
-
if (
|
|
2625
|
+
const c = l[h];
|
|
2626
|
+
if (c === n)
|
|
2627
2627
|
r++;
|
|
2628
|
-
else if (
|
|
2628
|
+
else if (c === s && (r--, r === 0))
|
|
2629
2629
|
return {
|
|
2630
2630
|
open: { start: { line: o, column: h }, end: { line: o, column: h + 1 } },
|
|
2631
2631
|
close: { start: { line: t, column: i }, end: { line: t, column: i + 1 } },
|
|
2632
|
-
type:
|
|
2632
|
+
type: s
|
|
2633
2633
|
};
|
|
2634
2634
|
}
|
|
2635
2635
|
}
|
|
@@ -2637,13 +2637,13 @@ class le {
|
|
|
2637
2637
|
}
|
|
2638
2638
|
highlightBrackets(e) {
|
|
2639
2639
|
if (!this.editor || !this.hasCustomHighlightSupport) return;
|
|
2640
|
-
const t = this.editor.getView(), i = t.createDomRangeFromRange(e.open),
|
|
2641
|
-
if (!(!i || !
|
|
2640
|
+
const t = this.editor.getView(), i = t.createDomRangeFromRange(e.open), n = t.createDomRangeFromRange(e.close);
|
|
2641
|
+
if (!(!i || !n))
|
|
2642
2642
|
try {
|
|
2643
|
-
const
|
|
2644
|
-
if (!
|
|
2645
|
-
|
|
2646
|
-
} catch (
|
|
2643
|
+
const s = CSS, r = window.Highlight;
|
|
2644
|
+
if (!s.highlights || !r) return;
|
|
2645
|
+
s.highlights.set(this.highlightName, new r(i, n));
|
|
2646
|
+
} catch (s) {
|
|
2647
2647
|
}
|
|
2648
2648
|
}
|
|
2649
2649
|
clearBracketHighlighting() {
|
|
@@ -2655,7 +2655,7 @@ class le {
|
|
|
2655
2655
|
}
|
|
2656
2656
|
}
|
|
2657
2657
|
observeContentMutations() {
|
|
2658
|
-
if (!this.editor || typeof MutationObserver
|
|
2658
|
+
if (!this.editor || typeof MutationObserver == "undefined") return;
|
|
2659
2659
|
const e = this.editor.getView().getContentElement();
|
|
2660
2660
|
this.observer = new MutationObserver(() => {
|
|
2661
2661
|
this.clearBracketHighlighting(), this.scheduleBracketUpdate();
|
|
@@ -2667,7 +2667,7 @@ class le {
|
|
|
2667
2667
|
}
|
|
2668
2668
|
detectCustomHighlightSupport() {
|
|
2669
2669
|
try {
|
|
2670
|
-
if (typeof CSS
|
|
2670
|
+
if (typeof CSS == "undefined" || typeof window == "undefined")
|
|
2671
2671
|
return !1;
|
|
2672
2672
|
const e = CSS, t = window.Highlight;
|
|
2673
2673
|
return !!e.highlights && !!t;
|
|
@@ -2676,7 +2676,7 @@ class le {
|
|
|
2676
2676
|
}
|
|
2677
2677
|
}
|
|
2678
2678
|
ensureHighlightStyles() {
|
|
2679
|
-
if (typeof document
|
|
2679
|
+
if (typeof document == "undefined" || document.getElementById(this.highlightStyleId)) return;
|
|
2680
2680
|
const e = document.createElement("style");
|
|
2681
2681
|
e.id = this.highlightStyleId, e.textContent = `
|
|
2682
2682
|
::highlight(${this.highlightName}) {
|
|
@@ -2690,14 +2690,14 @@ class le {
|
|
|
2690
2690
|
}
|
|
2691
2691
|
destroy() {
|
|
2692
2692
|
var e;
|
|
2693
|
-
if (this.pendingUpdateRaf !== null && typeof cancelAnimationFrame == "function" && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.clearBracketHighlighting(), (e = this.observer) == null || e.disconnect(), this.observer = null, this.editor && this.cursorHandler && this.editor.off("cursor", this.cursorHandler), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), typeof document
|
|
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 != "undefined") {
|
|
2694
2694
|
const t = document.getElementById(this.highlightStyleId);
|
|
2695
2695
|
t != null && t.parentNode && t.parentNode.removeChild(t);
|
|
2696
2696
|
}
|
|
2697
2697
|
this.cursorHandler = null, this.changeHandler = null, this.editor = null;
|
|
2698
2698
|
}
|
|
2699
2699
|
}
|
|
2700
|
-
class
|
|
2700
|
+
class re {
|
|
2701
2701
|
constructor() {
|
|
2702
2702
|
this.name = "code-folding", this.lineHeight = 21, this.voidMarkupTags = /* @__PURE__ */ new Set([
|
|
2703
2703
|
"area",
|
|
@@ -2797,14 +2797,14 @@ class ae {
|
|
|
2797
2797
|
const e = this.editor.getValue(), t = this.getActiveFolds().map((r) => this.getFoldKey(r)).join("|"), i = `${e}::${t}`;
|
|
2798
2798
|
if (i === this.lastSnapshot) return;
|
|
2799
2799
|
this.lastSnapshot = i, this.foldingUI.innerHTML = "";
|
|
2800
|
-
const
|
|
2800
|
+
const n = this.getRenderableActiveFolds(), s = document.createDocumentFragment();
|
|
2801
2801
|
for (const r of this.foldRegions) {
|
|
2802
|
-
const o = this.toDisplayLine(r,
|
|
2802
|
+
const o = this.toDisplayLine(r, n);
|
|
2803
2803
|
if (o === null) continue;
|
|
2804
2804
|
const l = this.isFoldActive(r), a = this.createFoldIndicator(r, o, l);
|
|
2805
|
-
|
|
2805
|
+
s.appendChild(a);
|
|
2806
2806
|
}
|
|
2807
|
-
this.foldingUI.appendChild(
|
|
2807
|
+
this.foldingUI.appendChild(s);
|
|
2808
2808
|
}
|
|
2809
2809
|
buildFoldRegions(e) {
|
|
2810
2810
|
const t = this.buildBracketFoldRegions(e), i = this.shouldIncludeMarkupFolds(e) ? this.buildMarkupFoldRegions(e) : [];
|
|
@@ -2813,7 +2813,7 @@ class ae {
|
|
|
2813
2813
|
buildBracketFoldRegions(e) {
|
|
2814
2814
|
var o;
|
|
2815
2815
|
const t = e.split(`
|
|
2816
|
-
`), i = [],
|
|
2816
|
+
`), i = [], n = [], s = {
|
|
2817
2817
|
"{": "}",
|
|
2818
2818
|
"[": "]",
|
|
2819
2819
|
"(": ")"
|
|
@@ -2825,38 +2825,38 @@ class ae {
|
|
|
2825
2825
|
for (let l = 0; l < t.length; l++) {
|
|
2826
2826
|
const a = t[l];
|
|
2827
2827
|
for (let h = 0; h < a.length; h++) {
|
|
2828
|
-
const
|
|
2829
|
-
if (
|
|
2830
|
-
i.push({ char:
|
|
2828
|
+
const c = a[h];
|
|
2829
|
+
if (s[c]) {
|
|
2830
|
+
i.push({ char: c, line: l, column: h });
|
|
2831
2831
|
continue;
|
|
2832
2832
|
}
|
|
2833
|
-
const
|
|
2834
|
-
if (!
|
|
2835
|
-
let
|
|
2833
|
+
const g = r[c];
|
|
2834
|
+
if (!g) continue;
|
|
2835
|
+
let f = -1;
|
|
2836
2836
|
for (let m = i.length - 1; m >= 0; m--)
|
|
2837
|
-
if (i[m].char ===
|
|
2838
|
-
|
|
2837
|
+
if (i[m].char === g) {
|
|
2838
|
+
f = m;
|
|
2839
2839
|
break;
|
|
2840
2840
|
}
|
|
2841
|
-
if (
|
|
2842
|
-
const
|
|
2843
|
-
if (
|
|
2844
|
-
const
|
|
2845
|
-
start: { line:
|
|
2841
|
+
if (f === -1) continue;
|
|
2842
|
+
const d = i.splice(f, 1)[0];
|
|
2843
|
+
if (d.line >= l) continue;
|
|
2844
|
+
const u = ((o = t[d.line]) == null ? void 0 : o.length) || 0, p = {
|
|
2845
|
+
start: { line: d.line, column: u },
|
|
2846
2846
|
end: { line: l, column: 0 },
|
|
2847
2847
|
collapsed: !1,
|
|
2848
|
-
level:
|
|
2848
|
+
level: f
|
|
2849
2849
|
};
|
|
2850
|
-
this.isValidFoldRegion(p) &&
|
|
2850
|
+
this.isValidFoldRegion(p) && n.push(p);
|
|
2851
2851
|
}
|
|
2852
2852
|
}
|
|
2853
|
-
return
|
|
2853
|
+
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
2854
|
}
|
|
2855
2855
|
shouldIncludeMarkupFolds(e) {
|
|
2856
2856
|
return /<!DOCTYPE\b/i.test(e) || /<[A-Za-z][\w:-]*(?:\s|>)/.test(e) && /<\/[A-Za-z][\w:-]*\s*>/.test(e);
|
|
2857
2857
|
}
|
|
2858
2858
|
buildMarkupFoldRegions(e) {
|
|
2859
|
-
const { lineStarts: t, lines: i } = this.buildLineStarts(e),
|
|
2859
|
+
const { lineStarts: t, lines: i } = this.buildLineStarts(e), n = [], s = [];
|
|
2860
2860
|
let r = 0;
|
|
2861
2861
|
for (; r < e.length; ) {
|
|
2862
2862
|
if (e[r] !== "<") {
|
|
@@ -2879,15 +2879,15 @@ class ae {
|
|
|
2879
2879
|
continue;
|
|
2880
2880
|
}
|
|
2881
2881
|
if (r = o.endOffset, o.isClosing) {
|
|
2882
|
-
const l =
|
|
2882
|
+
const l = s.findIndex((c) => c.name === o.name);
|
|
2883
2883
|
if (l === -1)
|
|
2884
2884
|
continue;
|
|
2885
|
-
const a =
|
|
2885
|
+
const a = s.splice(l, 1)[0], h = this.createMarkupFoldRegion(
|
|
2886
2886
|
a.openEndLine,
|
|
2887
2887
|
o.startLine,
|
|
2888
2888
|
i
|
|
2889
2889
|
);
|
|
2890
|
-
h &&
|
|
2890
|
+
h && n.push(h);
|
|
2891
2891
|
continue;
|
|
2892
2892
|
}
|
|
2893
2893
|
if (!(o.isSelfClosing || this.voidMarkupTags.has(o.name))) {
|
|
@@ -2905,25 +2905,25 @@ class ae {
|
|
|
2905
2905
|
l.startLine,
|
|
2906
2906
|
i
|
|
2907
2907
|
);
|
|
2908
|
-
a &&
|
|
2908
|
+
a && n.push(a), r = l.endOffset;
|
|
2909
2909
|
}
|
|
2910
2910
|
continue;
|
|
2911
2911
|
}
|
|
2912
|
-
this.nonFoldableInlineMarkupTags.has(o.name) ||
|
|
2912
|
+
this.nonFoldableInlineMarkupTags.has(o.name) || s.unshift({
|
|
2913
2913
|
name: o.name,
|
|
2914
2914
|
openEndLine: o.endLine
|
|
2915
2915
|
});
|
|
2916
2916
|
}
|
|
2917
2917
|
}
|
|
2918
|
-
return
|
|
2918
|
+
return n;
|
|
2919
2919
|
}
|
|
2920
|
-
parseMarkupTag(e, t, i,
|
|
2920
|
+
parseMarkupTag(e, t, i, n) {
|
|
2921
2921
|
if (e[t] !== "<")
|
|
2922
2922
|
return null;
|
|
2923
|
-
const
|
|
2924
|
-
if (!
|
|
2923
|
+
const s = e[t + 1];
|
|
2924
|
+
if (!s || s !== "/" && !/[A-Za-z]/.test(s))
|
|
2925
2925
|
return null;
|
|
2926
|
-
const r =
|
|
2926
|
+
const r = s === "/";
|
|
2927
2927
|
let o = t + (r ? 2 : 1);
|
|
2928
2928
|
const l = o;
|
|
2929
2929
|
for (; o < e.length && /[A-Za-z0-9:-]/.test(e[o]); )
|
|
@@ -2933,39 +2933,39 @@ class ae {
|
|
|
2933
2933
|
return null;
|
|
2934
2934
|
let h = null;
|
|
2935
2935
|
for (; o < e.length; ) {
|
|
2936
|
-
const
|
|
2936
|
+
const u = e[o];
|
|
2937
2937
|
if (h) {
|
|
2938
|
-
|
|
2938
|
+
u === h && (h = null), o += 1;
|
|
2939
2939
|
continue;
|
|
2940
2940
|
}
|
|
2941
|
-
if (
|
|
2942
|
-
h =
|
|
2941
|
+
if (u === '"' || u === "'") {
|
|
2942
|
+
h = u, o += 1;
|
|
2943
2943
|
continue;
|
|
2944
2944
|
}
|
|
2945
|
-
if (
|
|
2945
|
+
if (u === ">")
|
|
2946
2946
|
break;
|
|
2947
2947
|
o += 1;
|
|
2948
2948
|
}
|
|
2949
2949
|
if (o >= e.length || e[o] !== ">")
|
|
2950
2950
|
return null;
|
|
2951
|
-
const
|
|
2952
|
-
if (!
|
|
2951
|
+
const c = e.slice(l, a).toLowerCase();
|
|
2952
|
+
if (!c)
|
|
2953
2953
|
return null;
|
|
2954
|
-
const
|
|
2954
|
+
const g = e.slice(t, o + 1), f = this.offsetToLine(t, i, n), d = this.offsetToLine(o, i, n);
|
|
2955
2955
|
return {
|
|
2956
|
-
name:
|
|
2956
|
+
name: c,
|
|
2957
2957
|
isClosing: r,
|
|
2958
|
-
isSelfClosing: !r && /\/\s*>$/.test(
|
|
2959
|
-
startLine:
|
|
2960
|
-
endLine:
|
|
2958
|
+
isSelfClosing: !r && /\/\s*>$/.test(g),
|
|
2959
|
+
startLine: f,
|
|
2960
|
+
endLine: d,
|
|
2961
2961
|
endOffset: o + 1
|
|
2962
2962
|
};
|
|
2963
2963
|
}
|
|
2964
|
-
findClosingMarkupTag(e, t, i,
|
|
2964
|
+
findClosingMarkupTag(e, t, i, n, s) {
|
|
2965
2965
|
const r = `</${i}`, o = e.toLowerCase();
|
|
2966
2966
|
let l = o.indexOf(r, t);
|
|
2967
2967
|
for (; l !== -1; ) {
|
|
2968
|
-
const a = this.parseMarkupTag(e, l,
|
|
2968
|
+
const a = this.parseMarkupTag(e, l, n, s);
|
|
2969
2969
|
if (a && a.isClosing && a.name === i)
|
|
2970
2970
|
return {
|
|
2971
2971
|
startLine: a.startLine,
|
|
@@ -2979,13 +2979,13 @@ class ae {
|
|
|
2979
2979
|
var o;
|
|
2980
2980
|
if (e >= t)
|
|
2981
2981
|
return null;
|
|
2982
|
-
const
|
|
2982
|
+
const n = Math.max(0, Math.min(e, i.length - 1)), s = Math.max(0, Math.min(t, i.length - 1)), r = {
|
|
2983
2983
|
start: {
|
|
2984
|
-
line:
|
|
2985
|
-
column: ((o = i[
|
|
2984
|
+
line: n,
|
|
2985
|
+
column: ((o = i[n]) == null ? void 0 : o.length) || 0
|
|
2986
2986
|
},
|
|
2987
2987
|
end: {
|
|
2988
|
-
line:
|
|
2988
|
+
line: s,
|
|
2989
2989
|
column: 0
|
|
2990
2990
|
},
|
|
2991
2991
|
collapsed: !1,
|
|
@@ -2997,11 +2997,11 @@ class ae {
|
|
|
2997
2997
|
const t = /* @__PURE__ */ new Map();
|
|
2998
2998
|
for (const i of e)
|
|
2999
2999
|
this.isValidFoldRegion(i) && t.set(this.getFoldKey(i), i);
|
|
3000
|
-
return [...t.values()].sort((i,
|
|
3000
|
+
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
3001
|
}
|
|
3002
3002
|
createFoldIndicator(e, t, i) {
|
|
3003
|
-
const
|
|
3004
|
-
return
|
|
3003
|
+
const n = document.createElement("button");
|
|
3004
|
+
return n.type = "button", n.style.cssText = `
|
|
3005
3005
|
position: absolute;
|
|
3006
3006
|
left: 0;
|
|
3007
3007
|
top: ${t * this.lineHeight}px;
|
|
@@ -3018,11 +3018,11 @@ class ae {
|
|
|
3018
3018
|
padding: 0;
|
|
3019
3019
|
font-size: 10px;
|
|
3020
3020
|
user-select: none;
|
|
3021
|
-
`,
|
|
3022
|
-
|
|
3023
|
-
}),
|
|
3024
|
-
|
|
3025
|
-
}),
|
|
3021
|
+
`, n.textContent = i ? "▶" : "▼", n.title = i ? "Expand folded region" : "Collapse region", n.setAttribute("aria-label", n.title), n.addEventListener("mousedown", (s) => {
|
|
3022
|
+
s.preventDefault();
|
|
3023
|
+
}), n.addEventListener("click", (s) => {
|
|
3024
|
+
s.preventDefault(), s.stopPropagation(), this.toggleFold(e);
|
|
3025
|
+
}), n;
|
|
3026
3026
|
}
|
|
3027
3027
|
toggleFold(e) {
|
|
3028
3028
|
this.editor && (this.isFoldActive(e) ? this.editor.unfold(e) : this.editor.fold(e), this.syncFoldingStatePreservingScroll());
|
|
@@ -3057,14 +3057,14 @@ class ae {
|
|
|
3057
3057
|
});
|
|
3058
3058
|
}
|
|
3059
3059
|
withPreservedScroll(e) {
|
|
3060
|
-
var
|
|
3061
|
-
const t = (
|
|
3060
|
+
var s;
|
|
3061
|
+
const t = (s = this.editor) == null ? void 0 : s.getView().getScrollElement();
|
|
3062
3062
|
if (!t) {
|
|
3063
3063
|
e();
|
|
3064
3064
|
return;
|
|
3065
3065
|
}
|
|
3066
|
-
const i = t.scrollLeft,
|
|
3067
|
-
e(), this.restoreScrollPosition(t, i,
|
|
3066
|
+
const i = t.scrollLeft, n = t.scrollTop;
|
|
3067
|
+
e(), this.restoreScrollPosition(t, i, n);
|
|
3068
3068
|
}
|
|
3069
3069
|
restoreScrollPosition(e, t, i) {
|
|
3070
3070
|
e.scrollLeft = t, e.scrollTop = i, requestAnimationFrame(() => {
|
|
@@ -3098,39 +3098,39 @@ class ae {
|
|
|
3098
3098
|
this.editor.getView().setText(e);
|
|
3099
3099
|
}
|
|
3100
3100
|
buildFoldedProjection(e, t) {
|
|
3101
|
-
const { lineStarts: i, lines:
|
|
3101
|
+
const { lineStarts: i, lines: n } = this.buildLineStarts(e), s = [...t].sort((h, c) => this.comparePositions(h.start, c.start));
|
|
3102
3102
|
let r = "";
|
|
3103
3103
|
const o = [];
|
|
3104
3104
|
let l = 0;
|
|
3105
|
-
for (const h of
|
|
3106
|
-
const
|
|
3107
|
-
r +=
|
|
3105
|
+
for (const h of s) {
|
|
3106
|
+
const c = this.positionToOffset(h.start, i, n), g = this.positionToOffset(h.end, i, n), f = e.slice(l, c), d = this.getFoldPlaceholder(h), u = e.slice(c, g);
|
|
3107
|
+
r += f, r += d, f && o.push({ type: "text", text: f }), o.push({
|
|
3108
3108
|
type: "placeholder",
|
|
3109
|
-
text:
|
|
3109
|
+
text: d,
|
|
3110
3110
|
fold: h,
|
|
3111
|
-
hiddenText:
|
|
3112
|
-
}), l =
|
|
3111
|
+
hiddenText: u
|
|
3112
|
+
}), l = g;
|
|
3113
3113
|
}
|
|
3114
3114
|
const a = e.slice(l);
|
|
3115
3115
|
return r += a, a && o.push({ type: "text", text: a }), { text: r, segments: o };
|
|
3116
3116
|
}
|
|
3117
3117
|
renderFoldPlaceholders(e) {
|
|
3118
3118
|
if (!this.editor) return;
|
|
3119
|
-
const t = this.editor.getView().getContentElement(), i = /* @__PURE__ */ new Map(),
|
|
3120
|
-
for (const
|
|
3121
|
-
if (
|
|
3122
|
-
|
|
3119
|
+
const t = this.editor.getView().getContentElement(), i = /* @__PURE__ */ new Map(), n = document.createDocumentFragment();
|
|
3120
|
+
for (const s of e.segments) {
|
|
3121
|
+
if (s.type === "text") {
|
|
3122
|
+
n.appendChild(document.createTextNode(s.text));
|
|
3123
3123
|
continue;
|
|
3124
3124
|
}
|
|
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,
|
|
3125
|
+
const r = document.createElement("span"), o = this.getFoldKey(s.fold);
|
|
3126
|
+
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
3127
|
cursor: text;
|
|
3128
3128
|
user-select: text;
|
|
3129
3129
|
pointer-events: auto;
|
|
3130
3130
|
white-space: pre;
|
|
3131
|
-
`, r.textContent =
|
|
3131
|
+
`, r.textContent = s.text, n.appendChild(r);
|
|
3132
3132
|
}
|
|
3133
|
-
t.replaceChildren(
|
|
3133
|
+
t.replaceChildren(n), t.__lceFoldPlaceholderSources = i, this.editor.getView().syncTrailingNewlineMarkerForText(e.text);
|
|
3134
3134
|
}
|
|
3135
3135
|
getFoldPlaceholder(e) {
|
|
3136
3136
|
const t = Math.max(1, e.end.line - e.start.line);
|
|
@@ -3138,7 +3138,7 @@ class ae {
|
|
|
3138
3138
|
}
|
|
3139
3139
|
pruneInvalidFolds(e, t) {
|
|
3140
3140
|
if (!this.editor) return;
|
|
3141
|
-
const i = this.editor.getFolds().filter((a) => a.collapsed !== !1),
|
|
3141
|
+
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
3142
|
for (const a of i) {
|
|
3143
3143
|
const h = this.findReplacementFold(
|
|
3144
3144
|
a,
|
|
@@ -3149,14 +3149,14 @@ class ae {
|
|
|
3149
3149
|
);
|
|
3150
3150
|
if (!h)
|
|
3151
3151
|
continue;
|
|
3152
|
-
const
|
|
3153
|
-
|
|
3152
|
+
const c = this.getFoldKey(h);
|
|
3153
|
+
s.push(h), r.add(c);
|
|
3154
3154
|
}
|
|
3155
|
-
const l = new Set(
|
|
3155
|
+
const l = new Set(s.map((a) => this.getFoldKey(a)));
|
|
3156
3156
|
for (const a of i)
|
|
3157
3157
|
l.has(this.getFoldKey(a)) || this.editor.unfold(a);
|
|
3158
|
-
for (const a of
|
|
3159
|
-
|
|
3158
|
+
for (const a of s)
|
|
3159
|
+
n.has(this.getFoldKey(a)) || this.editor.fold(a);
|
|
3160
3160
|
}
|
|
3161
3161
|
getActiveFolds() {
|
|
3162
3162
|
return this.editor ? this.editor.getFolds().filter((e) => e.collapsed !== !1) : [];
|
|
@@ -3168,80 +3168,80 @@ class ae {
|
|
|
3168
3168
|
return this.getTopLevelFoldRegions(this.getActiveFolds());
|
|
3169
3169
|
}
|
|
3170
3170
|
getTopLevelFoldRegions(e) {
|
|
3171
|
-
const t = [...e].sort((
|
|
3172
|
-
for (const
|
|
3173
|
-
const
|
|
3174
|
-
|
|
3171
|
+
const t = [...e].sort((n, s) => this.comparePositions(n.start, s.start)), i = [];
|
|
3172
|
+
for (const n of t) {
|
|
3173
|
+
const s = i[i.length - 1];
|
|
3174
|
+
s && this.containsRange(s, n) || i.push(n);
|
|
3175
3175
|
}
|
|
3176
3176
|
return i;
|
|
3177
3177
|
}
|
|
3178
3178
|
toDisplayLine(e, t) {
|
|
3179
3179
|
let i = 0;
|
|
3180
|
-
for (const
|
|
3181
|
-
if (this.isSameRange(
|
|
3180
|
+
for (const n of t) {
|
|
3181
|
+
if (this.isSameRange(n, e))
|
|
3182
3182
|
break;
|
|
3183
|
-
if (this.containsRange(
|
|
3183
|
+
if (this.containsRange(n, e))
|
|
3184
3184
|
return null;
|
|
3185
|
-
|
|
3185
|
+
n.end.line <= e.start.line && (i += n.end.line - n.start.line);
|
|
3186
3186
|
}
|
|
3187
3187
|
return e.start.line - i;
|
|
3188
3188
|
}
|
|
3189
3189
|
findBestRegionForLine(e, t) {
|
|
3190
|
-
const
|
|
3190
|
+
const n = (t ? this.getActiveFolds() : this.foldRegions).filter(
|
|
3191
3191
|
(s) => s.start.line <= e && s.end.line >= e
|
|
3192
3192
|
);
|
|
3193
|
-
return
|
|
3194
|
-
const
|
|
3195
|
-
return
|
|
3196
|
-
}),
|
|
3193
|
+
return n.length === 0 ? null : (n.sort((s, r) => {
|
|
3194
|
+
const o = s.end.line - s.start.line, l = r.end.line - r.start.line;
|
|
3195
|
+
return o !== l ? o - l : this.comparePositions(s.start, r.start);
|
|
3196
|
+
}), n[0]);
|
|
3197
3197
|
}
|
|
3198
|
-
findReplacementFold(e, t, i,
|
|
3198
|
+
findReplacementFold(e, t, i, n, s) {
|
|
3199
3199
|
const r = this.getFoldKey(e), o = this.foldRegions.find(
|
|
3200
|
-
(
|
|
3200
|
+
(d) => this.getFoldKey(d) === r && !i.has(r)
|
|
3201
3201
|
);
|
|
3202
3202
|
if (o)
|
|
3203
3203
|
return o;
|
|
3204
|
-
const l = e.end.line - e.start.line, a = t != null ? t : this.createFoldSnapshot(e,
|
|
3205
|
-
const u = this.createFoldSnapshot(
|
|
3204
|
+
const l = e.end.line - e.start.line, a = t != null ? t : this.createFoldSnapshot(e, n, s), c = this.foldRegions.filter((d) => !i.has(this.getFoldKey(d))).map((d) => {
|
|
3205
|
+
const u = this.createFoldSnapshot(d, n, s), p = a && (u == null ? void 0 : u.startLineText) === a.startLineText ? 1 : 0, m = a && (u == null ? void 0 : u.endLineText) === a.endLineText ? 1 : 0, x = a && (u == null ? void 0 : u.lineSpan) === a.lineSpan ? 1 : 0;
|
|
3206
3206
|
return {
|
|
3207
|
-
region:
|
|
3208
|
-
overlaps: this.lineRangeOverlap(e,
|
|
3209
|
-
lineDistance: Math.abs(
|
|
3207
|
+
region: d,
|
|
3208
|
+
overlaps: this.lineRangeOverlap(e, d),
|
|
3209
|
+
lineDistance: Math.abs(d.start.line - e.start.line) + Math.abs(d.end.line - e.end.line),
|
|
3210
3210
|
spanDistance: Math.abs(
|
|
3211
|
-
|
|
3211
|
+
d.end.line - d.start.line - l
|
|
3212
3212
|
),
|
|
3213
|
-
columnDistance: Math.abs(
|
|
3213
|
+
columnDistance: Math.abs(d.start.column - e.start.column) + Math.abs(d.end.column - e.end.column),
|
|
3214
3214
|
hiddenTextMatch: a && (u == null ? void 0 : u.hiddenText) === a.hiddenText ? 1 : 0,
|
|
3215
|
-
boundaryMatchScore:
|
|
3215
|
+
boundaryMatchScore: p + m + x
|
|
3216
3216
|
};
|
|
3217
|
-
}).sort((
|
|
3218
|
-
if (!
|
|
3217
|
+
}).sort((d, u) => d.hiddenTextMatch !== u.hiddenTextMatch ? u.hiddenTextMatch - d.hiddenTextMatch : d.boundaryMatchScore !== u.boundaryMatchScore ? u.boundaryMatchScore - d.boundaryMatchScore : d.overlaps !== u.overlaps ? u.overlaps - d.overlaps : d.lineDistance !== u.lineDistance ? d.lineDistance - u.lineDistance : d.spanDistance !== u.spanDistance ? d.spanDistance - u.spanDistance : d.columnDistance - u.columnDistance)[0];
|
|
3218
|
+
if (!c)
|
|
3219
3219
|
return null;
|
|
3220
|
-
const
|
|
3221
|
-
return !(
|
|
3220
|
+
const g = c.lineDistance <= 2 && c.spanDistance <= 1;
|
|
3221
|
+
return !(c.hiddenTextMatch === 1 || c.boundaryMatchScore >= 2) && !g ? null : c.region;
|
|
3222
3222
|
}
|
|
3223
3223
|
lineRangeOverlap(e, t) {
|
|
3224
|
-
const i = Math.max(e.start.line, t.start.line),
|
|
3225
|
-
return Math.max(0,
|
|
3224
|
+
const i = Math.max(e.start.line, t.start.line), n = Math.min(e.end.line, t.end.line);
|
|
3225
|
+
return Math.max(0, n - i);
|
|
3226
3226
|
}
|
|
3227
3227
|
rememberActiveFoldSnapshots(e) {
|
|
3228
3228
|
const t = /* @__PURE__ */ new Map(), i = this.getLineInfo(e);
|
|
3229
|
-
for (const
|
|
3230
|
-
const
|
|
3231
|
-
|
|
3229
|
+
for (const n of this.getActiveFolds()) {
|
|
3230
|
+
const s = this.createFoldSnapshot(n, e, i);
|
|
3231
|
+
s && t.set(this.getFoldKey(n), s);
|
|
3232
3232
|
}
|
|
3233
3233
|
this.foldSnapshots = t;
|
|
3234
3234
|
}
|
|
3235
3235
|
createFoldSnapshot(e, t, i = this.getLineInfo(t)) {
|
|
3236
|
-
var h,
|
|
3237
|
-
const { lineStarts:
|
|
3238
|
-
if (
|
|
3236
|
+
var h, c;
|
|
3237
|
+
const { lineStarts: n, lines: s } = i;
|
|
3238
|
+
if (s.length === 0)
|
|
3239
3239
|
return null;
|
|
3240
|
-
const r = this.positionToOffset(e.start,
|
|
3240
|
+
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
3241
|
return {
|
|
3242
3242
|
hiddenText: t.slice(r, o),
|
|
3243
|
-
startLineText: (h =
|
|
3244
|
-
endLineText: (
|
|
3243
|
+
startLineText: (h = s[l]) != null ? h : "",
|
|
3244
|
+
endLineText: (c = s[a]) != null ? c : "",
|
|
3245
3245
|
lineSpan: e.end.line - e.start.line
|
|
3246
3246
|
};
|
|
3247
3247
|
}
|
|
@@ -3251,22 +3251,22 @@ class ae {
|
|
|
3251
3251
|
e();
|
|
3252
3252
|
return;
|
|
3253
3253
|
}
|
|
3254
|
-
const t = this.editor.getView(), i = t.getContentElement(),
|
|
3254
|
+
const t = this.editor.getView(), i = t.getContentElement(), n = document.activeElement === i, s = t.getSelectionOffsets(), r = s.isInEditor;
|
|
3255
3255
|
if (e(), !r)
|
|
3256
3256
|
return;
|
|
3257
3257
|
const o = this.remapSelectionOffsetsForVisibleDisplay(
|
|
3258
|
-
(l =
|
|
3259
|
-
(a =
|
|
3258
|
+
(l = s.anchorOffset) != null ? l : s.startOffset,
|
|
3259
|
+
(a = s.focusOffset) != null ? a : s.endOffset
|
|
3260
3260
|
);
|
|
3261
3261
|
t.setSelectionBoundaryOffsets(
|
|
3262
3262
|
o.startOffset,
|
|
3263
3263
|
o.endOffset
|
|
3264
|
-
), (
|
|
3264
|
+
), (n || s.isInEditor) && this.editor.focus();
|
|
3265
3265
|
}
|
|
3266
3266
|
remapSelectionOffsetsForVisibleDisplay(e, t) {
|
|
3267
3267
|
if (!this.editor)
|
|
3268
3268
|
return { startOffset: e, endOffset: t };
|
|
3269
|
-
const i = this.editor.getValue(), { lineStarts:
|
|
3269
|
+
const i = this.editor.getValue(), { lineStarts: n, lines: s } = this.getLineInfo(i), r = this.getRenderableActiveFolds();
|
|
3270
3270
|
if (r.length === 0) {
|
|
3271
3271
|
const o = i.length;
|
|
3272
3272
|
return {
|
|
@@ -3278,36 +3278,36 @@ class ae {
|
|
|
3278
3278
|
startOffset: this.remapOffsetToVisibleBoundary(
|
|
3279
3279
|
e,
|
|
3280
3280
|
r,
|
|
3281
|
-
s,
|
|
3282
3281
|
n,
|
|
3282
|
+
s,
|
|
3283
3283
|
i.length
|
|
3284
3284
|
),
|
|
3285
3285
|
endOffset: this.remapOffsetToVisibleBoundary(
|
|
3286
3286
|
t,
|
|
3287
3287
|
r,
|
|
3288
|
-
s,
|
|
3289
3288
|
n,
|
|
3289
|
+
s,
|
|
3290
3290
|
i.length
|
|
3291
3291
|
)
|
|
3292
3292
|
};
|
|
3293
3293
|
}
|
|
3294
|
-
remapOffsetToVisibleBoundary(e, t, i,
|
|
3295
|
-
const r = Math.max(0, Math.min(e,
|
|
3294
|
+
remapOffsetToVisibleBoundary(e, t, i, n, s) {
|
|
3295
|
+
const r = Math.max(0, Math.min(e, s));
|
|
3296
3296
|
for (const o of t) {
|
|
3297
|
-
const l = this.positionToOffset(o.start, i,
|
|
3297
|
+
const l = this.positionToOffset(o.start, i, n), a = this.positionToOffset(o.end, i, n);
|
|
3298
3298
|
if (r <= l || r >= a)
|
|
3299
3299
|
continue;
|
|
3300
|
-
const h = r - l,
|
|
3301
|
-
return h <=
|
|
3300
|
+
const h = r - l, c = a - r;
|
|
3301
|
+
return h <= c ? l : a;
|
|
3302
3302
|
}
|
|
3303
3303
|
return r;
|
|
3304
3304
|
}
|
|
3305
3305
|
buildLineStarts(e) {
|
|
3306
3306
|
const t = e.split(`
|
|
3307
3307
|
`), i = new Array(t.length);
|
|
3308
|
-
let
|
|
3309
|
-
for (let
|
|
3310
|
-
i[
|
|
3308
|
+
let n = 0;
|
|
3309
|
+
for (let s = 0; s < t.length; s++)
|
|
3310
|
+
i[s] = n, n += t[s].length + 1;
|
|
3311
3311
|
return { lineStarts: i, lines: t };
|
|
3312
3312
|
}
|
|
3313
3313
|
getLineInfo(e) {
|
|
@@ -3322,15 +3322,15 @@ class ae {
|
|
|
3322
3322
|
}
|
|
3323
3323
|
offsetToLine(e, t, i) {
|
|
3324
3324
|
var l;
|
|
3325
|
-
const
|
|
3325
|
+
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
3326
|
let r = 0, o = t.length - 1;
|
|
3327
3327
|
for (; r <= o; ) {
|
|
3328
|
-
const a = Math.floor((r + o) / 2), h = t[a],
|
|
3329
|
-
if (
|
|
3328
|
+
const a = Math.floor((r + o) / 2), h = t[a], c = a + 1 < t.length ? t[a + 1] : Number.POSITIVE_INFINITY;
|
|
3329
|
+
if (s < h) {
|
|
3330
3330
|
o = a - 1;
|
|
3331
3331
|
continue;
|
|
3332
3332
|
}
|
|
3333
|
-
if (
|
|
3333
|
+
if (s >= c) {
|
|
3334
3334
|
r = a + 1;
|
|
3335
3335
|
continue;
|
|
3336
3336
|
}
|
|
@@ -3340,8 +3340,8 @@ class ae {
|
|
|
3340
3340
|
}
|
|
3341
3341
|
positionToOffset(e, t, i) {
|
|
3342
3342
|
var r;
|
|
3343
|
-
const
|
|
3344
|
-
return t[
|
|
3343
|
+
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));
|
|
3344
|
+
return t[n] + s;
|
|
3345
3345
|
}
|
|
3346
3346
|
comparePositions(e, t) {
|
|
3347
3347
|
return e.line !== t.line ? e.line - t.line : e.column - t.column;
|
|
@@ -3365,7 +3365,7 @@ class ae {
|
|
|
3365
3365
|
this.pendingUpdateRaf !== null && (cancelAnimationFrame(this.pendingUpdateRaf), this.pendingUpdateRaf = null), this.editor && this.changeHandler && this.editor.off("change", this.changeHandler), this.foldingUI && this.foldingUI.parentNode && this.foldingUI.parentNode.removeChild(this.foldingUI), this.restoreFullDisplay(), this.changeHandler = null, this.lastSnapshot = "", this.lastParsedText = null, this.foldingUI = null, this.foldRegions = [], this.cachedLineInfo = null, this.editor = null;
|
|
3366
3366
|
}
|
|
3367
3367
|
}
|
|
3368
|
-
class
|
|
3368
|
+
class oe {
|
|
3369
3369
|
constructor() {
|
|
3370
3370
|
this.name = "syntax-highlighting", this.editor = null, this.currentTheme = "dark", this.currentLanguage = null, this.modes = /* @__PURE__ */ new Map();
|
|
3371
3371
|
}
|
|
@@ -3432,10 +3432,10 @@ class he {
|
|
|
3432
3432
|
}
|
|
3433
3433
|
// Public API: highlight a source string using the chosen mode (or detect html)
|
|
3434
3434
|
highlight(e, t) {
|
|
3435
|
-
const i = this.getSyntaxColors(),
|
|
3435
|
+
const i = this.getSyntaxColors(), n = this.normalizeLanguageId(
|
|
3436
3436
|
t || this.currentLanguage || this.detectLanguage(e) || "html"
|
|
3437
3437
|
);
|
|
3438
|
-
return (this.modes.get(
|
|
3438
|
+
return (this.modes.get(n) || this.modes.get("html")).highlight(e, i);
|
|
3439
3439
|
}
|
|
3440
3440
|
// Backwards-compatible method
|
|
3441
3441
|
highlightHTML(e) {
|
|
@@ -3481,24 +3481,24 @@ class he {
|
|
|
3481
3481
|
}[t] || t || "html";
|
|
3482
3482
|
}
|
|
3483
3483
|
restoreHighlightTokens(e, t) {
|
|
3484
|
-
return e.replace(/\u0000([a-z]+)\u0000/g, (i,
|
|
3485
|
-
let
|
|
3486
|
-
for (let r = 0; r <
|
|
3487
|
-
|
|
3488
|
-
return
|
|
3484
|
+
return e.replace(/\u0000([a-z]+)\u0000/g, (i, n) => {
|
|
3485
|
+
let s = 0;
|
|
3486
|
+
for (let r = 0; r < n.length; r++)
|
|
3487
|
+
s = s * 26 + (n.charCodeAt(r) - 97 + 1);
|
|
3488
|
+
return s = s - 1, t[s] || "";
|
|
3489
3489
|
});
|
|
3490
3490
|
}
|
|
3491
3491
|
createTokenStore(e) {
|
|
3492
3492
|
const t = (i) => {
|
|
3493
|
-
let
|
|
3493
|
+
let n = "", s = i;
|
|
3494
3494
|
do
|
|
3495
|
-
|
|
3496
|
-
while (
|
|
3497
|
-
return
|
|
3495
|
+
n = String.fromCharCode(97 + s % 26) + n, s = Math.floor(s / 26) - 1;
|
|
3496
|
+
while (s >= 0);
|
|
3497
|
+
return n || "a";
|
|
3498
3498
|
};
|
|
3499
3499
|
return (i) => {
|
|
3500
|
-
const
|
|
3501
|
-
return e.push(i), `\0${t(
|
|
3500
|
+
const n = e.length;
|
|
3501
|
+
return e.push(i), `\0${t(n)}\0`;
|
|
3502
3502
|
};
|
|
3503
3503
|
}
|
|
3504
3504
|
refreshEditorHighlight() {
|
|
@@ -3509,8 +3509,8 @@ class he {
|
|
|
3509
3509
|
unescapeEntitiesRepeated(e) {
|
|
3510
3510
|
let t = e || "";
|
|
3511
3511
|
for (let i = 0; i < 5; i++) {
|
|
3512
|
-
const
|
|
3513
|
-
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t ===
|
|
3512
|
+
const n = t;
|
|
3513
|
+
if (t = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'"), t === n) break;
|
|
3514
3514
|
}
|
|
3515
3515
|
return t;
|
|
3516
3516
|
}
|
|
@@ -3523,9 +3523,9 @@ class he {
|
|
|
3523
3523
|
if (/^[\[{]/.test(t) && /[\]}]$/.test(t) || /"[^"]+"\s*:/.test(t))
|
|
3524
3524
|
try {
|
|
3525
3525
|
return JSON.parse(t), "json";
|
|
3526
|
-
} catch (
|
|
3526
|
+
} catch (a) {
|
|
3527
3527
|
}
|
|
3528
|
-
const i = /<\/?[A-Za-z][\w:-]*(?:\s|>|\/>)/.test(t),
|
|
3528
|
+
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
3529
|
if ([
|
|
3530
3530
|
/^---\s*\n[\s\S]*?\n---\s*(?:\n|$)/.test(t),
|
|
3531
3531
|
/^#{1,6}\s+\S/m.test(t),
|
|
@@ -3540,13 +3540,13 @@ class he {
|
|
|
3540
3540
|
/(^|\s)(?:\*\*|__)[^*_]+(?:\*\*|__)(?=\s|$|[.,;:!?])/m.test(t)
|
|
3541
3541
|
].filter(Boolean).length >= (i ? 2 : 1))
|
|
3542
3542
|
return "markdown";
|
|
3543
|
-
if (s)
|
|
3544
|
-
return "html";
|
|
3545
|
-
const n = this.detectProgrammingLanguage(t);
|
|
3546
3543
|
if (n)
|
|
3547
|
-
return
|
|
3548
|
-
const
|
|
3549
|
-
|
|
3544
|
+
return "html";
|
|
3545
|
+
const o = this.detectProgrammingLanguage(t);
|
|
3546
|
+
if (o)
|
|
3547
|
+
return o;
|
|
3548
|
+
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);
|
|
3549
|
+
return !i && l ? "css" : null;
|
|
3550
3550
|
}
|
|
3551
3551
|
detectProgrammingLanguage(e) {
|
|
3552
3552
|
const t = {
|
|
@@ -3566,156 +3566,156 @@ class he {
|
|
|
3566
3566
|
o.test(e) && (t[r] += l);
|
|
3567
3567
|
};
|
|
3568
3568
|
i("python", /^\s*(from\s+\w+\s+import|import\s+\w+|def\s+\w+\s*\(|class\s+\w+|for\s+\w+\s+in\s+.+:|if\s+.+:|while\s+.+:|print\s*\()/m, 2), i("python", /^\s*[A-Za-z_]\w*\s*=\s*(?:\[|\{|\(|["']|\d)/m), i("python", /\b(True|False|None|self|elif|lambda|yield)\b/), i("go", /^\s*package\s+\w+/m, 3), i("go", /\bfunc\s+\w+\s*\(/, 2), i("go", /\b(import|defer|goroutine|chan|struct|interface)\b/), i("cpp", /^\s*#include\s*<[^>]+>/m, 2), i("cpp", /\b(std::|template\s*<|namespace\s+\w+|cout\s*<<|cin\s*>>)\b/, 2), i("cpp", /\b(class|public|private|protected|virtual|typename)\b/), i("c", /^\s*#include\s*[<"][^>"]+[>"]/m), i("c", /\b(int|char|float|double|void)\s+\w+\s*\(/), i("c", /\bprintf\s*\(/), i("java", /^\s*(package|import)\s+[\w.]+;/m, 2), i("java", /\b(public|private|protected)\s+(class|interface|enum)\s+\w+/, 2), i("java", /\bSystem\.out\.println\s*\(/), i("csharp", /^\s*using\s+[\w.]+;/m, 2), i("csharp", /\b(namespace|record|var|string|Console\.WriteLine)\b/), i("csharp", /\b(public|private|protected)\s+(class|interface|struct)\s+\w+/), i("rust", /\bfn\s+\w+\s*\(/, 2), i("rust", /\b(let\s+mut|impl\s+\w+|use\s+[\w:]+|println!\s*\()/), i("rust", /\b(crate|trait|enum|match|Some|None|Ok|Err)\b/), i("ruby", /^\s*(def|class|module)\s+\w+/m, 2), i("ruby", /\b(puts|require|attr_reader|elsif|end)\b/), i("sql", /^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP)\b/im, 3), i("sql", /\bFROM\s+\w+|\bWHERE\s+/i), i("yaml", /^---\s*$/m), i("yaml", /^\s*[A-Za-z0-9_.-]+\s*:\s+\S/m, 2), i("yaml", /^\s*-\s+[A-Za-z0-9_.-]+\s*:/m), i("dockerfile", /^\s*FROM\s+\S+/im, 3), i("dockerfile", /^\s*(RUN|COPY|ADD|CMD|ENTRYPOINT|WORKDIR|ENV|ARG)\b/im, 2), i("php", /^<\?(?:php\b|=)/i, 3), i("php", /^\?php\b/i, 3), i("php", /\$[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*\s*=/, 2), i("php", /\b(echo|foreach|function|namespace|use|PHP_EOL)\b/, 2);
|
|
3569
|
-
const [
|
|
3570
|
-
return
|
|
3569
|
+
const [n, s] = Object.entries(t).sort((r, o) => o[1] - r[1])[0] || ["", 0];
|
|
3570
|
+
return s >= 2 ? n : null;
|
|
3571
3571
|
}
|
|
3572
3572
|
_highlightHTML(e, t) {
|
|
3573
|
-
const i = t,
|
|
3574
|
-
const
|
|
3575
|
-
return o.push(
|
|
3573
|
+
const i = t, n = (g) => this.escapeHTML(g), s = [], r = this.createTokenStore(s), o = [], l = (g) => {
|
|
3574
|
+
const f = o.length;
|
|
3575
|
+
return o.push(g), `ht${f}`;
|
|
3576
3576
|
};
|
|
3577
|
-
let a =
|
|
3577
|
+
let a = n(e);
|
|
3578
3578
|
a = a.replace(
|
|
3579
3579
|
/<\/?(?:(?!>)[^\n\r<])*?(?=$|[\n\r])/g,
|
|
3580
|
-
(
|
|
3580
|
+
(g) => l(g)
|
|
3581
3581
|
);
|
|
3582
3582
|
const h = [];
|
|
3583
3583
|
try {
|
|
3584
|
-
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (
|
|
3585
|
-
} catch (
|
|
3584
|
+
e.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi, (g, f, d) => (h.push({ attrs: String(f || ""), inner: String(d || "") }), g));
|
|
3585
|
+
} catch (g) {
|
|
3586
3586
|
}
|
|
3587
|
-
let
|
|
3588
|
-
return a = a.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (
|
|
3589
|
-
var v, T,
|
|
3590
|
-
const m = (T = (v = h[
|
|
3591
|
-
(((
|
|
3587
|
+
let c = 0;
|
|
3588
|
+
return a = a.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi, (g, f, d, u, p) => {
|
|
3589
|
+
var v, T, S;
|
|
3590
|
+
const m = (T = (v = h[c++]) == null ? void 0 : v.inner) != null ? T : this.unescapeEntitiesRepeated(u || "");
|
|
3591
|
+
(((S = h[c - 1]) == null ? void 0 : S.attrs) || d || "").toLowerCase();
|
|
3592
3592
|
const x = this._highlightJS(m, i);
|
|
3593
|
-
return `${
|
|
3594
|
-
}), a = a.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (
|
|
3595
|
-
const p = this._highlightCSS(this.unescapeEntitiesRepeated(
|
|
3596
|
-
return `${
|
|
3593
|
+
return `${f}${x}${p}`;
|
|
3594
|
+
}), a = a.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi, (g, f, d, u) => {
|
|
3595
|
+
const p = this._highlightCSS(this.unescapeEntitiesRepeated(d), i);
|
|
3596
|
+
return `${f}${p}${u}`;
|
|
3597
3597
|
}), a = a.replace(
|
|
3598
3598
|
/(<!--[\s\S]*?-->)/g,
|
|
3599
|
-
(
|
|
3599
|
+
(g) => r(`<span style="color: ${i.comment};">${g}</span>`)
|
|
3600
3600
|
), a = a.replace(
|
|
3601
3601
|
/(<!DOCTYPE[\s\S]*?>)/i,
|
|
3602
|
-
(
|
|
3603
|
-
), a = a.replace(/(<\/?\s*)([^\s&>\/]+)([^<]*?)(\/?>)/g, (
|
|
3604
|
-
const m = `<span style="color: ${i.tag};">${
|
|
3605
|
-
let x =
|
|
3602
|
+
(g) => r(`<span style="color: ${i.doctype};">${g}</span>`)
|
|
3603
|
+
), a = a.replace(/(<\/?\s*)([^\s&>\/]+)([^<]*?)(\/?>)/g, (g, f, d, u, p) => {
|
|
3604
|
+
const m = `<span style="color: ${i.tag};">${d}</span>`;
|
|
3605
|
+
let x = u;
|
|
3606
3606
|
return x = x.replace(
|
|
3607
3607
|
/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,
|
|
3608
|
-
(v, T,
|
|
3609
|
-
const
|
|
3610
|
-
let
|
|
3611
|
-
|
|
3612
|
-
let M =
|
|
3613
|
-
if (
|
|
3614
|
-
const
|
|
3615
|
-
C ? M = `${C}${
|
|
3608
|
+
(v, T, S, w) => {
|
|
3609
|
+
const O = String(T).toLowerCase(), $ = `<span style="color: ${i.attrName};">${T}</span>`;
|
|
3610
|
+
let I = w, C = "";
|
|
3611
|
+
w.startsWith(""") && w.endsWith(""") ? (I = w.slice(6, -6), C = """) : w.startsWith("'") && w.endsWith("'") && (I = w.slice(5, -5), C = "'");
|
|
3612
|
+
let M = w;
|
|
3613
|
+
if (O === "style") {
|
|
3614
|
+
const N = I.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g, (A, R, P, H) => `<span style="color: ${i.styleProp};">${R}</span>:<span style="color: ${i.styleVal};">${P}</span>${H}`);
|
|
3615
|
+
C ? M = `${C}${N}${C}` : M = N, M = `<span style="color: ${i.attrValue};">${M}</span>`;
|
|
3616
3616
|
} else
|
|
3617
|
-
C && (M = `${C}${
|
|
3618
|
-
return `${
|
|
3617
|
+
C && (M = `${C}${I}${C}`), M = `<span style="color: ${i.attrValue};">${M}</span>`;
|
|
3618
|
+
return `${$}${S}${M}`;
|
|
3619
3619
|
}
|
|
3620
|
-
), `${
|
|
3621
|
-
}), a = a.replace(/\u0002ht(\d+)\u0002/g, (
|
|
3620
|
+
), `${f}${m}${x}${p}`;
|
|
3621
|
+
}), a = a.replace(/\u0002ht(\d+)\u0002/g, (g, f) => o[Number(f)] || ""), this.restoreHighlightTokens(a, s);
|
|
3622
3622
|
}
|
|
3623
3623
|
_highlightCSS(e, t) {
|
|
3624
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3624
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n), r = /(\/\*[\s\S]*?\*\/)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
3625
3625
|
let o = 0, l = "", a;
|
|
3626
3626
|
for (; a = r.exec(i); ) {
|
|
3627
3627
|
o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
|
|
3628
|
-
const h = a[0],
|
|
3629
|
-
l +=
|
|
3628
|
+
const h = a[0], c = h.startsWith("/*") ? t.comment : t.string;
|
|
3629
|
+
l += s(`<span style="color: ${c};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
|
|
3630
3630
|
}
|
|
3631
3631
|
return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
|
|
3632
3632
|
/(@[\w-]+)/g,
|
|
3633
|
-
(h) =>
|
|
3633
|
+
(h) => s(`<span style="color: ${t.keyword};">${h}</span>`)
|
|
3634
3634
|
), l = l.replace(
|
|
3635
3635
|
/([A-Za-z_-][\w-]*)(\s*:)/g,
|
|
3636
|
-
(h,
|
|
3636
|
+
(h, c, g) => `${s(`<span style="color: ${t.styleProp};">${c}</span>`)}${g}`
|
|
3637
3637
|
), l = l.replace(
|
|
3638
3638
|
/(#(?:[0-9a-fA-F]{3,8})\b)/g,
|
|
3639
|
-
(h) =>
|
|
3639
|
+
(h) => s(`<span style="color: ${t.number};">${h}</span>`)
|
|
3640
3640
|
), l = l.replace(
|
|
3641
3641
|
/\b(-?\d*\.?\d+(?:px|em|rem|vh|vw|vmin|vmax|%|s|ms|deg|turn|fr)?)\b/g,
|
|
3642
|
-
(h) =>
|
|
3642
|
+
(h) => s(`<span style="color: ${t.number};">${h}</span>`)
|
|
3643
3643
|
), l = l.replace(
|
|
3644
3644
|
/\b(important|inherit|initial|unset|revert|auto|none|block|inline|flex|grid|absolute|relative|fixed|sticky)\b/g,
|
|
3645
|
-
(h) =>
|
|
3646
|
-
), this.restoreHighlightTokens(l,
|
|
3645
|
+
(h) => s(`<span style="color: ${t.styleVal};">${h}</span>`)
|
|
3646
|
+
), this.restoreHighlightTokens(l, n);
|
|
3647
3647
|
}
|
|
3648
3648
|
_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] || "",
|
|
3649
|
+
const i = this.unescapeEntitiesRepeated(e), n = /("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}\[\],:]/g;
|
|
3650
|
+
let s = 0, r = "", o;
|
|
3651
|
+
for (; o = n.exec(i); ) {
|
|
3652
|
+
s < o.index && (r += this.escapeHTML(i.slice(s, o.index)));
|
|
3653
|
+
const l = o[0], a = o[1], h = o[2] || "", c = o[3];
|
|
3654
3654
|
if (a) {
|
|
3655
|
-
const
|
|
3656
|
-
r += `<span style="color: ${
|
|
3657
|
-
} else
|
|
3658
|
-
|
|
3655
|
+
const g = h ? t.attrName : t.string;
|
|
3656
|
+
r += `<span style="color: ${g};">${this.escapeHTML(a)}</span>${this.escapeHTML(h)}`;
|
|
3657
|
+
} 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>`;
|
|
3658
|
+
s = n.lastIndex;
|
|
3659
3659
|
}
|
|
3660
|
-
return
|
|
3660
|
+
return s < i.length && (r += this.escapeHTML(i.slice(s))), r;
|
|
3661
3661
|
}
|
|
3662
3662
|
_highlightMarkdown(e, t) {
|
|
3663
|
-
var
|
|
3664
|
-
const
|
|
3663
|
+
var a;
|
|
3664
|
+
const n = this.unescapeEntitiesRepeated(e).split(`
|
|
3665
3665
|
`);
|
|
3666
|
-
let s = !1,
|
|
3667
|
-
return
|
|
3668
|
-
const
|
|
3669
|
-
if (
|
|
3670
|
-
const
|
|
3671
|
-
return
|
|
3666
|
+
let s = !1, r = "", o = "", l = ((a = n[0]) == null ? void 0 : a.trim()) === "---";
|
|
3667
|
+
return n.map((h, c) => {
|
|
3668
|
+
const g = [], f = this.createTokenStore(g);
|
|
3669
|
+
if (l) {
|
|
3670
|
+
const p = h.trim() === "---", x = `<span style="color: ${p ? t.keyword : t.attrName};">${this.escapeHTML(h)}</span>`;
|
|
3671
|
+
return c > 0 && p && (l = !1), x;
|
|
3672
3672
|
}
|
|
3673
|
-
const
|
|
3674
|
-
if (
|
|
3675
|
-
const
|
|
3676
|
-
return s = !(s &&
|
|
3677
|
-
this.escapeHTML(
|
|
3678
|
-
`<span style="color: ${t.keyword}; font-weight: 700;">${this.escapeHTML(
|
|
3679
|
-
`<span style="color: ${t.string};">${this.escapeHTML(
|
|
3673
|
+
const d = h.match(/^(\s*)(`{3,}|~{3,})(.*)$/);
|
|
3674
|
+
if (d) {
|
|
3675
|
+
const p = d[2];
|
|
3676
|
+
return s = !(s && p[0] === r[0]), r = s ? p : "", o = s ? this.extractMarkdownFenceLanguage(d[3] || "") : "", [
|
|
3677
|
+
this.escapeHTML(d[1]),
|
|
3678
|
+
`<span style="color: ${t.keyword}; font-weight: 700;">${this.escapeHTML(p)}</span>`,
|
|
3679
|
+
`<span style="color: ${t.string};">${this.escapeHTML(d[3] || "")}</span>`
|
|
3680
3680
|
].join("");
|
|
3681
3681
|
}
|
|
3682
3682
|
if (s)
|
|
3683
|
-
return this.highlightMarkdownFenceLine(
|
|
3684
|
-
let
|
|
3683
|
+
return this.highlightMarkdownFenceLine(h, o, t);
|
|
3684
|
+
let u = this.escapeHTML(h).replace(
|
|
3685
3685
|
/(`[^`]+`)/g,
|
|
3686
|
-
(
|
|
3686
|
+
(p) => f(`<span style="color: ${t.string}; background: rgba(148, 163, 184, 0.16); border-radius: 3px;">${p}</span>`)
|
|
3687
3687
|
).replace(
|
|
3688
3688
|
/(!?\[[^\]\n]*\])(\([^)]+\))/g,
|
|
3689
|
-
(
|
|
3689
|
+
(p, m, x) => f(`<span style="color: ${t.attrName};">${m}</span><span style="color: ${t.attrValue};">${x}</span>`)
|
|
3690
3690
|
).replace(
|
|
3691
3691
|
/(\*\*|__)(.+?)\1/g,
|
|
3692
|
-
(
|
|
3692
|
+
(p, m, x) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.tag}; font-weight: 700;">${x}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3693
3693
|
).replace(
|
|
3694
3694
|
/(~~)(.+?)\1/g,
|
|
3695
|
-
(
|
|
3695
|
+
(p, m, x) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.comment}; text-decoration: line-through;">${x}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3696
3696
|
).replace(
|
|
3697
3697
|
/(\*|_)([^*_]+?)\1/g,
|
|
3698
|
-
(
|
|
3698
|
+
(p, m, x) => f(`<span style="color: ${t.keyword};">${m}</span><span style="color: ${t.styleVal}; font-style: italic;">${x}</span><span style="color: ${t.keyword};">${m}</span>`)
|
|
3699
3699
|
);
|
|
3700
|
-
return
|
|
3700
|
+
return u = u.replace(
|
|
3701
3701
|
/^(\s{0,3}#{1,6})(\s+.*)?$/,
|
|
3702
|
-
(
|
|
3703
|
-
),
|
|
3702
|
+
(p, m, x = "") => `<span style="color: ${t.keyword}; font-weight: 700;">${m}</span><span style="color: ${t.tag}; font-weight: 700;">${x}</span>`
|
|
3703
|
+
), u = u.replace(
|
|
3704
3704
|
/^(\s{0,3})((?:-\s*){3,}|(?:\*\s*){3,}|(?:_\s*){3,})$/,
|
|
3705
|
-
(
|
|
3706
|
-
),
|
|
3705
|
+
(p, m, x) => `${m}<span style="color: ${t.comment};">${x}</span>`
|
|
3706
|
+
), u = u.replace(
|
|
3707
3707
|
/^(\s{0,3}>)(.*)$/,
|
|
3708
|
-
(
|
|
3709
|
-
),
|
|
3708
|
+
(p, m, x) => `<span style="color: ${t.comment};">${m}</span>${x}`
|
|
3709
|
+
), u = u.replace(
|
|
3710
3710
|
/^(\s*)([-*+])(\s+\[[ xX]\])(\s+)/,
|
|
3711
|
-
(
|
|
3712
|
-
),
|
|
3711
|
+
(p, m, x, v, T) => `${m}<span style="color: ${t.keyword};">${x}</span><span style="color: ${t.attrName};">${v}</span>${T}`
|
|
3712
|
+
), u = u.replace(
|
|
3713
3713
|
/^(\s*)([-*+]|\d+\.)(\s+)/,
|
|
3714
|
-
(
|
|
3715
|
-
),
|
|
3714
|
+
(p, m, x, v) => `${m}<span style="color: ${t.keyword};">${x}</span>${v}`
|
|
3715
|
+
), u = u.replace(
|
|
3716
3716
|
/^(\s*\|.*\|\s*)$/,
|
|
3717
|
-
(
|
|
3718
|
-
), this.restoreHighlightTokens(
|
|
3717
|
+
(p) => p.replace(/\|/g, (m) => `<span style="color: ${t.keyword};">${m}</span>`)
|
|
3718
|
+
), this.restoreHighlightTokens(u, g);
|
|
3719
3719
|
}).join(`
|
|
3720
3720
|
`);
|
|
3721
3721
|
}
|
|
@@ -3725,27 +3725,27 @@ class he {
|
|
|
3725
3725
|
return t ? this.normalizeLanguageId(t) : "";
|
|
3726
3726
|
}
|
|
3727
3727
|
highlightMarkdownFenceLine(e, t, i) {
|
|
3728
|
-
const
|
|
3729
|
-
return !
|
|
3728
|
+
const n = t ? this.modes.get(t) : void 0;
|
|
3729
|
+
return !n || n.name === "markdown" ? `<span style="color: ${i.text};">${this.escapeHTML(e)}</span>` : n.highlight(e, i);
|
|
3730
3730
|
}
|
|
3731
3731
|
_highlightShell(e, t) {
|
|
3732
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3732
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n), r = /(#[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|(\$\{?[A-Za-z_][\w]*\}?|\$[0-9@#?$*!])/g;
|
|
3733
3733
|
let o = 0, l = "", a;
|
|
3734
3734
|
for (; a = r.exec(i); ) {
|
|
3735
3735
|
o < a.index && (l += this.escapeHTML(i.slice(o, a.index)));
|
|
3736
|
-
const h = a[0],
|
|
3737
|
-
l +=
|
|
3736
|
+
const h = a[0], c = h.startsWith("#") ? t.comment : h.startsWith("$") ? t.variable : t.string;
|
|
3737
|
+
l += s(`<span style="color: ${c};">${this.escapeHTML(h)}</span>`), o = r.lastIndex;
|
|
3738
3738
|
}
|
|
3739
3739
|
return o < i.length && (l += this.escapeHTML(i.slice(o))), l = l.replace(
|
|
3740
3740
|
/(^|\s)(--?[A-Za-z0-9][\w-]*)(?=\s|=|$)/g,
|
|
3741
|
-
(h,
|
|
3741
|
+
(h, c, g) => `${c}${s(`<span style="color: ${t.attrName};">${g}</span>`)}`
|
|
3742
3742
|
), l = l.replace(
|
|
3743
3743
|
/\b(if|then|else|elif|fi|for|while|until|do|done|case|esac|function|export|unset|alias|source|return|in)\b/g,
|
|
3744
|
-
(h) =>
|
|
3744
|
+
(h) => s(`<span style="color: ${t.keyword};">${h}</span>`)
|
|
3745
3745
|
), l = l.replace(
|
|
3746
3746
|
/(^|\s)(npm|npx|pnpm|yarn|bun|node|git|cd|mkdir|touch|cp|mv|rm|cat|grep|rg|find|curl|wget|echo|printf|sudo|chmod|chown|docker|kubectl)(?=\s|$)/g,
|
|
3747
|
-
(h,
|
|
3748
|
-
), this.restoreHighlightTokens(l,
|
|
3747
|
+
(h, c, g) => `${c}${s(`<span style="color: ${t.tag};">${g}</span>`)}`
|
|
3748
|
+
), this.restoreHighlightTokens(l, n);
|
|
3749
3749
|
}
|
|
3750
3750
|
getLanguageKeywords(e) {
|
|
3751
3751
|
const t = ["true", "false", "null", "nil", "none"];
|
|
@@ -3762,101 +3762,101 @@ class he {
|
|
|
3762
3762
|
}[e] || [], ...t];
|
|
3763
3763
|
}
|
|
3764
3764
|
_highlightGenericCode(e, t, i) {
|
|
3765
|
-
const
|
|
3765
|
+
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
3766
|
`(${o})|("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`)`,
|
|
3767
3767
|
"g"
|
|
3768
3768
|
);
|
|
3769
|
-
let a = 0, h = "",
|
|
3770
|
-
for (;
|
|
3771
|
-
a <
|
|
3772
|
-
const
|
|
3773
|
-
h += r(`<span style="color: ${
|
|
3769
|
+
let a = 0, h = "", c;
|
|
3770
|
+
for (; c = l.exec(n); ) {
|
|
3771
|
+
a < c.index && (h += this.escapeHTML(n.slice(a, c.index)));
|
|
3772
|
+
const f = c[0], d = f.startsWith("//") || f.startsWith("/*") || f.startsWith("#") || f.startsWith("--") ? t.comment : t.string;
|
|
3773
|
+
h += r(`<span style="color: ${d};">${this.escapeHTML(f)}</span>`), a = l.lastIndex;
|
|
3774
3774
|
}
|
|
3775
|
-
a <
|
|
3776
|
-
const
|
|
3777
|
-
if (
|
|
3778
|
-
const
|
|
3779
|
-
`\\b(${
|
|
3775
|
+
a < n.length && (h += this.escapeHTML(n.slice(a)));
|
|
3776
|
+
const g = Array.from(new Set(this.getLanguageKeywords(i)));
|
|
3777
|
+
if (g.length > 0) {
|
|
3778
|
+
const f = new RegExp(
|
|
3779
|
+
`\\b(${g.map((d) => d.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b`,
|
|
3780
3780
|
i === "sql" ? "gi" : "g"
|
|
3781
3781
|
);
|
|
3782
3782
|
h = h.replace(
|
|
3783
|
-
|
|
3784
|
-
(
|
|
3783
|
+
f,
|
|
3784
|
+
(d) => r(`<span style="color: ${t.keyword};">${d}</span>`)
|
|
3785
3785
|
);
|
|
3786
3786
|
}
|
|
3787
3787
|
return h = h.replace(
|
|
3788
3788
|
/\b([A-Z][A-Za-z0-9_]*|[A-Za-z_][\w]*(?=\s*\())\b/g,
|
|
3789
|
-
(
|
|
3789
|
+
(f) => r(`<span style="color: ${t.tag};">${f}</span>`)
|
|
3790
3790
|
), h = h.replace(
|
|
3791
3791
|
/\b(-?0x[0-9a-fA-F]+|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:[uUlLfFdD]*)\b/g,
|
|
3792
|
-
(
|
|
3792
|
+
(f) => r(`<span style="color: ${t.number};">${f}</span>`)
|
|
3793
3793
|
), h = h.replace(
|
|
3794
3794
|
/(@[A-Za-z_][\w]*|#[A-Za-z_][\w]*|::[A-Za-z_][\w]*)/g,
|
|
3795
|
-
(
|
|
3796
|
-
), this.restoreHighlightTokens(h,
|
|
3795
|
+
(f) => r(`<span style="color: ${t.attrName};">${f}</span>`)
|
|
3796
|
+
), this.restoreHighlightTokens(h, s);
|
|
3797
3797
|
}
|
|
3798
3798
|
_highlightYAML(e, t) {
|
|
3799
|
-
const i = this.unescapeEntitiesRepeated(e),
|
|
3799
|
+
const i = this.unescapeEntitiesRepeated(e), n = [], s = this.createTokenStore(n);
|
|
3800
3800
|
let r = this.escapeHTML(i).replace(
|
|
3801
3801
|
/(#.*)$/gm,
|
|
3802
|
-
(o) =>
|
|
3802
|
+
(o) => s(`<span style="color: ${t.comment};">${o}</span>`)
|
|
3803
3803
|
).replace(
|
|
3804
3804
|
/^(\s*[-?]?\s*)([A-Za-z0-9_.-]+)(\s*:)/gm,
|
|
3805
|
-
(o, l, a, h) => `${l}${
|
|
3805
|
+
(o, l, a, h) => `${l}${s(`<span style="color: ${t.attrName};">${a}</span>`)}${h}`
|
|
3806
3806
|
).replace(
|
|
3807
3807
|
/\b(true|false|null|yes|no|on|off)\b/gi,
|
|
3808
|
-
(o) =>
|
|
3808
|
+
(o) => s(`<span style="color: ${t.keyword};">${o}</span>`)
|
|
3809
3809
|
).replace(
|
|
3810
3810
|
/\b(-?\d+(?:\.\d+)?)\b/g,
|
|
3811
|
-
(o) =>
|
|
3811
|
+
(o) => s(`<span style="color: ${t.number};">${o}</span>`)
|
|
3812
3812
|
);
|
|
3813
3813
|
return r = r.replace(
|
|
3814
3814
|
/("[^&]*?"|'[^&]*?')/g,
|
|
3815
|
-
(o) =>
|
|
3816
|
-
), this.restoreHighlightTokens(r,
|
|
3815
|
+
(o) => s(`<span style="color: ${t.string};">${o}</span>`)
|
|
3816
|
+
), this.restoreHighlightTokens(r, n);
|
|
3817
3817
|
}
|
|
3818
3818
|
_highlightXML(e, t) {
|
|
3819
3819
|
return this._highlightHTML(e, t);
|
|
3820
3820
|
}
|
|
3821
3821
|
_highlightJSX(e, t) {
|
|
3822
|
-
const i = [],
|
|
3822
|
+
const i = [], n = e.replace(
|
|
3823
3823
|
/<\/?[A-Za-z][\w.:-]*(?:\s+[^<>]*?)?\/?>/g,
|
|
3824
|
-
(
|
|
3825
|
-
const r = i.length, o = this.escapeHTML(
|
|
3824
|
+
(s) => {
|
|
3825
|
+
const r = i.length, o = this.escapeHTML(s).replace(
|
|
3826
3826
|
/(<\/?)([A-Za-z][\w.:-]*)([\s\S]*?)(\/?>)/,
|
|
3827
|
-
(l, a, h,
|
|
3828
|
-
const
|
|
3827
|
+
(l, a, h, c, g) => {
|
|
3828
|
+
const f = String(c || "").replace(
|
|
3829
3829
|
/([A-Za-z_:][\w:.-]*)(\s*=\s*)/g,
|
|
3830
3830
|
`<span style="color: ${t.attrName};">$1</span>$2`
|
|
3831
3831
|
);
|
|
3832
|
-
return `${a}<span style="color: ${t.tag};">${h}</span>${
|
|
3832
|
+
return `${a}<span style="color: ${t.tag};">${h}</span>${f}${g}`;
|
|
3833
3833
|
}
|
|
3834
3834
|
);
|
|
3835
3835
|
return i.push(o), `jsx${r}`;
|
|
3836
3836
|
}
|
|
3837
3837
|
);
|
|
3838
|
-
return this._highlightJS(
|
|
3838
|
+
return this._highlightJS(n, t).replace(
|
|
3839
3839
|
/\u0004jsx(\d+)\u0004/g,
|
|
3840
|
-
(
|
|
3840
|
+
(s, r) => i[Number(r)] || ""
|
|
3841
3841
|
);
|
|
3842
3842
|
}
|
|
3843
3843
|
_highlightEJS(e, t) {
|
|
3844
|
-
const i = [],
|
|
3844
|
+
const i = [], n = e.replace(/<%[\s\S]*?%>/g, (s) => {
|
|
3845
3845
|
const r = i.length;
|
|
3846
|
-
return i.push(`<span style="color: ${t.keyword};">${this.escapeHTML(
|
|
3846
|
+
return i.push(`<span style="color: ${t.keyword};">${this.escapeHTML(s)}</span>`), `ejs${r}`;
|
|
3847
3847
|
});
|
|
3848
|
-
return this._highlightHTML(
|
|
3848
|
+
return this._highlightHTML(n, t).replace(
|
|
3849
3849
|
/\u0003ejs(\d+)\u0003/g,
|
|
3850
|
-
(
|
|
3850
|
+
(s, r) => i[Number(r)] || ""
|
|
3851
3851
|
);
|
|
3852
3852
|
}
|
|
3853
3853
|
_highlightDockerfile(e, t) {
|
|
3854
3854
|
return this.unescapeEntitiesRepeated(e).split(`
|
|
3855
|
-
`).map((
|
|
3856
|
-
const s = this.escapeHTML(
|
|
3857
|
-
return /^\s*#/.test(
|
|
3855
|
+
`).map((n) => {
|
|
3856
|
+
const s = this.escapeHTML(n);
|
|
3857
|
+
return /^\s*#/.test(n) ? `<span style="color: ${t.comment};">${s}</span>` : s.replace(
|
|
3858
3858
|
/^(\s*)(FROM|RUN|CMD|LABEL|MAINTAINER|EXPOSE|ENV|ADD|COPY|ENTRYPOINT|VOLUME|USER|WORKDIR|ARG|ONBUILD|STOPSIGNAL|HEALTHCHECK|SHELL)(\b)/i,
|
|
3859
|
-
(
|
|
3859
|
+
(r, o, l, a) => `${o}<span style="color: ${t.keyword};">${l}</span>${a}`
|
|
3860
3860
|
);
|
|
3861
3861
|
}).join(`
|
|
3862
3862
|
`);
|
|
@@ -3864,78 +3864,78 @@ class he {
|
|
|
3864
3864
|
_highlightJS(e, t) {
|
|
3865
3865
|
const i = this.unescapeEntitiesRepeated(e);
|
|
3866
3866
|
this.escapeHTML(i);
|
|
3867
|
-
const
|
|
3868
|
-
let
|
|
3867
|
+
const n = [], s = (f) => {
|
|
3868
|
+
let d = "", u = f;
|
|
3869
3869
|
do
|
|
3870
|
-
|
|
3871
|
-
while (
|
|
3872
|
-
return
|
|
3873
|
-
}, r = (
|
|
3874
|
-
const
|
|
3875
|
-
return
|
|
3870
|
+
d = String.fromCharCode(97 + u % 26) + d, u = Math.floor(u / 26) - 1;
|
|
3871
|
+
while (u >= 0);
|
|
3872
|
+
return d || "a";
|
|
3873
|
+
}, r = (f) => `\0${s(f)}\0`, o = (f) => {
|
|
3874
|
+
const d = n.length;
|
|
3875
|
+
return n.push(f), r(d);
|
|
3876
3876
|
};
|
|
3877
3877
|
let l;
|
|
3878
3878
|
const a = /(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
3879
|
-
let h = 0,
|
|
3879
|
+
let h = 0, c = "";
|
|
3880
3880
|
for (; l = a.exec(i); ) {
|
|
3881
|
-
const
|
|
3882
|
-
h <
|
|
3883
|
-
const
|
|
3884
|
-
/^\/\*/.test(
|
|
3881
|
+
const f = l.index;
|
|
3882
|
+
h < f && (c += this.escapeHTML(i.slice(h, f)));
|
|
3883
|
+
const d = l[0];
|
|
3884
|
+
/^\/\*/.test(d) || /^\/\//.test(d) ? c += o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`) : c += o(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`), h = a.lastIndex;
|
|
3885
3885
|
}
|
|
3886
|
-
return h < i.length && (
|
|
3887
|
-
const
|
|
3888
|
-
return
|
|
3889
|
-
}),
|
|
3890
|
-
let
|
|
3891
|
-
for (let
|
|
3892
|
-
|
|
3893
|
-
return
|
|
3886
|
+
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, d, u) => {
|
|
3887
|
+
const p = c[u - 1] || "", m = c[u + f.length] || "";
|
|
3888
|
+
return p === "&" || p === "#" || m === ";" || m === "#" ? f : `<span style="color: ${t.number};">${f}</span>`;
|
|
3889
|
+
}), 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, d) => {
|
|
3890
|
+
let u = 0;
|
|
3891
|
+
for (let p = 0; p < d.length; p++)
|
|
3892
|
+
u = u * 26 + (d.charCodeAt(p) - 97 + 1);
|
|
3893
|
+
return u = u - 1, n[u] || "";
|
|
3894
3894
|
});
|
|
3895
3895
|
}
|
|
3896
3896
|
_highlightPHP(e, t) {
|
|
3897
3897
|
const i = this.unescapeEntitiesRepeated(e);
|
|
3898
|
-
let
|
|
3899
|
-
const
|
|
3900
|
-
let
|
|
3898
|
+
let n = this.escapeHTML(i);
|
|
3899
|
+
const s = [], r = (d) => {
|
|
3900
|
+
let u = "", p = d;
|
|
3901
3901
|
do
|
|
3902
|
-
|
|
3902
|
+
u = String.fromCharCode(97 + p % 26) + u, p = Math.floor(p / 26) - 1;
|
|
3903
3903
|
while (p >= 0);
|
|
3904
|
-
return
|
|
3905
|
-
}, o = (
|
|
3906
|
-
const
|
|
3907
|
-
return
|
|
3908
|
-
}, l = (
|
|
3909
|
-
const p =
|
|
3910
|
-
return p === -1 ? !1 : (
|
|
3904
|
+
return u || "a";
|
|
3905
|
+
}, o = (d) => {
|
|
3906
|
+
const u = s.length;
|
|
3907
|
+
return s.push(d), `\0${r(u)}\0`;
|
|
3908
|
+
}, l = (d, u) => {
|
|
3909
|
+
const p = n.indexOf(d);
|
|
3910
|
+
return p === -1 ? !1 : (n = n.slice(0, p) + u + n.slice(p + d.length), !0);
|
|
3911
3911
|
};
|
|
3912
3912
|
let a;
|
|
3913
|
-
const h = /\/\*[\s\S]*?\*\//g,
|
|
3913
|
+
const h = /\/\*[\s\S]*?\*\//g, c = /\/\/[^\n\r]*/g, g = /\#([^\n\r]*)/g, f = /("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;
|
|
3914
3914
|
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>`));
|
|
3915
|
+
const d = a[0];
|
|
3916
|
+
l(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
3921
3917
|
}
|
|
3922
3918
|
for (; a = c.exec(i); ) {
|
|
3923
|
-
const
|
|
3924
|
-
l(this.escapeHTML(
|
|
3919
|
+
const d = a[0];
|
|
3920
|
+
l(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
3921
|
+
}
|
|
3922
|
+
for (; a = g.exec(i); ) {
|
|
3923
|
+
const d = a[0];
|
|
3924
|
+
l(this.escapeHTML(d), o(`<span style="color: ${t.comment};">${this.escapeHTML(d)}</span>`));
|
|
3925
3925
|
}
|
|
3926
|
-
for (; a =
|
|
3927
|
-
const
|
|
3928
|
-
l(this.escapeHTML(
|
|
3926
|
+
for (; a = f.exec(i); ) {
|
|
3927
|
+
const d = a[0];
|
|
3928
|
+
l(this.escapeHTML(d), o(`<span style="color: ${t.string};">${this.escapeHTML(d)}</span>`));
|
|
3929
3929
|
}
|
|
3930
|
-
return
|
|
3930
|
+
return n = n.replace(
|
|
3931
3931
|
/(<\?(?:php\b|=)?|\?>)/gi,
|
|
3932
|
-
(
|
|
3933
|
-
),
|
|
3932
|
+
(d) => o(`<span style="color: ${t.keyword};">${d}</span>`)
|
|
3933
|
+
), 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, (d, u) => {
|
|
3934
3934
|
let p = 0;
|
|
3935
|
-
for (let m = 0; m <
|
|
3936
|
-
p = p * 26 + (
|
|
3937
|
-
return p = p - 1,
|
|
3938
|
-
}),
|
|
3935
|
+
for (let m = 0; m < u.length; m++)
|
|
3936
|
+
p = p * 26 + (u.charCodeAt(m) - 97 + 1);
|
|
3937
|
+
return p = p - 1, s[p] || "";
|
|
3938
|
+
}), n;
|
|
3939
3939
|
}
|
|
3940
3940
|
// Method to check if content contains syntax that should be highlighted
|
|
3941
3941
|
shouldHighlight(e) {
|
|
@@ -3945,11 +3945,11 @@ class he {
|
|
|
3945
3945
|
this.editor = null, this.modes.clear();
|
|
3946
3946
|
}
|
|
3947
3947
|
}
|
|
3948
|
-
function
|
|
3948
|
+
function le(E, e) {
|
|
3949
3949
|
const t = { ...e };
|
|
3950
|
-
return t.extensions || (t.extensions = []), t.extensions.some((
|
|
3950
|
+
return t.extensions || (t.extensions = []), t.extensions.some((s) => s.name === "keymap") || t.extensions.unshift(new X(t.keymap)), t.extensions.some((s) => s.name === "transaction") || t.extensions.unshift(new W()), new V(E, t);
|
|
3951
3951
|
}
|
|
3952
|
-
const
|
|
3952
|
+
const z = '[data-theme="dark"], .dark, .editora-theme-dark', ae = `/* Source Editor Dialog Styles */
|
|
3953
3953
|
.rte-source-editor-overlay {
|
|
3954
3954
|
position: fixed !important;
|
|
3955
3955
|
top: 0 !important;
|
|
@@ -4326,7 +4326,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4326
4326
|
flex: 1;
|
|
4327
4327
|
text-align: center;
|
|
4328
4328
|
}
|
|
4329
|
-
}`,
|
|
4329
|
+
}`, he = () => ({
|
|
4330
4330
|
name: "code",
|
|
4331
4331
|
// Toolbar button configuration
|
|
4332
4332
|
toolbar: [
|
|
@@ -4347,9 +4347,9 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4347
4347
|
toggleSourceView: () => {
|
|
4348
4348
|
const e = (() => {
|
|
4349
4349
|
var o, l, a;
|
|
4350
|
-
const
|
|
4351
|
-
if (
|
|
4352
|
-
let h =
|
|
4350
|
+
const s = window.getSelection();
|
|
4351
|
+
if (s && s.anchorNode) {
|
|
4352
|
+
let h = s.anchorNode instanceof HTMLElement ? s.anchorNode : s.anchorNode.parentElement;
|
|
4353
4353
|
for (; h; ) {
|
|
4354
4354
|
if ((o = h.classList) != null && o.contains("rte-content"))
|
|
4355
4355
|
return h;
|
|
@@ -4363,10 +4363,10 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4363
4363
|
for (; h && h !== document.body; ) {
|
|
4364
4364
|
if ((a = h.classList) != null && a.contains("rte-content"))
|
|
4365
4365
|
return h;
|
|
4366
|
-
const
|
|
4366
|
+
const c = h.querySelector(
|
|
4367
4367
|
".rte-content"
|
|
4368
4368
|
);
|
|
4369
|
-
if (
|
|
4369
|
+
if (c) return c;
|
|
4370
4370
|
h = h.parentElement;
|
|
4371
4371
|
}
|
|
4372
4372
|
}
|
|
@@ -4383,9 +4383,9 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4383
4383
|
return console.error("[CodePlugin] Editor content area not found"), alert(
|
|
4384
4384
|
"Editor content area not found. Please click inside the editor first."
|
|
4385
4385
|
), !1;
|
|
4386
|
-
const t = e.innerHTML, i = (
|
|
4386
|
+
const t = e.innerHTML, i = (s) => {
|
|
4387
4387
|
let r = "", o = 0;
|
|
4388
|
-
const l = 2, a =
|
|
4388
|
+
const l = 2, a = s.split(/(<\/?[a-zA-Z][^>]*>)/);
|
|
4389
4389
|
for (const h of a)
|
|
4390
4390
|
h.trim() && (h.match(/^<\/[a-zA-Z]/) ? (o = Math.max(0, o - 1), r += `
|
|
4391
4391
|
` + " ".repeat(o * l) + h) : h.match(/^<[a-zA-Z]/) && !h.match(/\/>$/) ? (r += `
|
|
@@ -4395,11 +4395,11 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4395
4395
|
};
|
|
4396
4396
|
return (() => {
|
|
4397
4397
|
const r = i(t);
|
|
4398
|
-
let o = null, l = "dark", a = !1, h = !1,
|
|
4399
|
-
const
|
|
4400
|
-
|
|
4401
|
-
const
|
|
4402
|
-
|
|
4398
|
+
let o = null, l = "dark", a = !1, h = !1, c = !1, g = !1;
|
|
4399
|
+
const f = !!e.closest(z) || document.body.matches(z) || document.documentElement.matches(z), d = document.createElement("div");
|
|
4400
|
+
d.className = "rte-source-editor-overlay", f && d.classList.add("rte-theme-dark");
|
|
4401
|
+
const u = document.createElement("div");
|
|
4402
|
+
u.className = "rte-source-editor-modal", u.setAttribute("role", "dialog"), u.setAttribute("aria-modal", "true"), u.setAttribute("aria-labelledby", "source-editor-title");
|
|
4403
4403
|
const p = document.createElement("div");
|
|
4404
4404
|
p.className = "rte-source-editor-header", p.innerHTML = `
|
|
4405
4405
|
<h2 id="source-editor-title">Source Editor</h2>
|
|
@@ -4446,8 +4446,8 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4446
4446
|
v.className = "rte-source-editor-warning", v.textContent = "⚠️ Advanced users only. Invalid HTML may break the editor.";
|
|
4447
4447
|
const T = document.createElement("div");
|
|
4448
4448
|
T.className = "rte-source-editor-light-editor", T.style.height = "400px", x.appendChild(v), x.appendChild(T), m.appendChild(x);
|
|
4449
|
-
const
|
|
4450
|
-
if (
|
|
4449
|
+
const S = document.createElement("div");
|
|
4450
|
+
if (S.className = "rte-source-editor-footer", S.innerHTML = `
|
|
4451
4451
|
<div class="rte-source-editor-footer-info">
|
|
4452
4452
|
<span class="unsaved-changes" style="display: none;">• Unsaved changes</span>
|
|
4453
4453
|
</div>
|
|
@@ -4455,40 +4455,40 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4455
4455
|
<button class="rte-source-editor-btn rte-source-editor-btn-cancel">Cancel</button>
|
|
4456
4456
|
<button class="rte-source-editor-btn rte-source-editor-btn-save">Save</button>
|
|
4457
4457
|
</div>
|
|
4458
|
-
`,
|
|
4458
|
+
`, u.appendChild(p), u.appendChild(m), u.appendChild(S), d.appendChild(u), !document.getElementById("rte-source-editor-styles")) {
|
|
4459
4459
|
const b = document.createElement("style");
|
|
4460
|
-
b.id = "rte-source-editor-styles", b.textContent =
|
|
4460
|
+
b.id = "rte-source-editor-styles", b.textContent = ae, document.head.appendChild(b);
|
|
4461
4461
|
}
|
|
4462
|
-
const
|
|
4462
|
+
const w = p.querySelector(
|
|
4463
4463
|
".theme-toggle-btn"
|
|
4464
|
-
),
|
|
4464
|
+
), O = p.querySelector(
|
|
4465
4465
|
".readonly-toggle-btn"
|
|
4466
|
-
), I = p.querySelector(
|
|
4467
|
-
".rte-source-editor-fullscreen-btn"
|
|
4468
4466
|
), $ = p.querySelector(
|
|
4467
|
+
".rte-source-editor-fullscreen-btn"
|
|
4468
|
+
), I = p.querySelector(
|
|
4469
4469
|
".rte-source-editor-close-btn"
|
|
4470
|
-
), C =
|
|
4470
|
+
), C = S.querySelector(
|
|
4471
4471
|
".rte-source-editor-btn-cancel"
|
|
4472
|
-
), M =
|
|
4472
|
+
), M = S.querySelector(
|
|
4473
4473
|
".rte-source-editor-btn-save"
|
|
4474
|
-
),
|
|
4474
|
+
), N = S.querySelector(
|
|
4475
4475
|
".unsaved-changes"
|
|
4476
|
-
),
|
|
4477
|
-
b.addEventListener(
|
|
4478
|
-
() => b.removeEventListener(
|
|
4476
|
+
), A = [], R = (b, k, B, F) => {
|
|
4477
|
+
b.addEventListener(k, B, F), A.push(
|
|
4478
|
+
() => b.removeEventListener(k, B, F)
|
|
4479
4479
|
);
|
|
4480
|
-
},
|
|
4481
|
-
|
|
4480
|
+
}, P = (b) => {
|
|
4481
|
+
c !== b && (c = b, N && (N.style.display = c ? "inline" : "none"));
|
|
4482
4482
|
}, H = () => {
|
|
4483
|
-
if (!
|
|
4484
|
-
for (
|
|
4485
|
-
const b =
|
|
4483
|
+
if (!g) {
|
|
4484
|
+
for (g = !0; A.length; ) {
|
|
4485
|
+
const b = A.pop();
|
|
4486
4486
|
b == null || b();
|
|
4487
4487
|
}
|
|
4488
|
-
o && (o.destroy(), o = null),
|
|
4488
|
+
o && (o.destroy(), o = null), d.isConnected && d.remove();
|
|
4489
4489
|
}
|
|
4490
|
-
},
|
|
4491
|
-
l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l),
|
|
4490
|
+
}, K = () => {
|
|
4491
|
+
l = l === "dark" ? "light" : "dark", o == null || o.setTheme(l), w && (w.innerHTML = l === "light" ? `
|
|
4492
4492
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4493
4493
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
4494
4494
|
</svg>
|
|
@@ -4506,7 +4506,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4506
4506
|
</svg>
|
|
4507
4507
|
`);
|
|
4508
4508
|
}, j = () => {
|
|
4509
|
-
a = !a, o == null || o.setReadOnly(a),
|
|
4509
|
+
a = !a, o == null || o.setReadOnly(a), O && (O.classList.toggle("active", a), O.innerHTML = a ? `
|
|
4510
4510
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4511
4511
|
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
|
|
4512
4512
|
<circle cx="12" cy="16" r="1"/>
|
|
@@ -4519,7 +4519,7 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4519
4519
|
</svg>
|
|
4520
4520
|
`);
|
|
4521
4521
|
}, q = () => {
|
|
4522
|
-
h = !h,
|
|
4522
|
+
h = !h, d.classList.toggle("fullscreen", h), T.style.height = h ? "calc(100vh - 200px)" : "400px", $ && ($.innerHTML = h ? `
|
|
4523
4523
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
4524
4524
|
<path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0 2-2h3M3 16h3a2 2 0 0 0 2 2v3"/>
|
|
4525
4525
|
</svg>
|
|
@@ -4529,13 +4529,13 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4529
4529
|
</svg>
|
|
4530
4530
|
`);
|
|
4531
4531
|
}, G = () => {
|
|
4532
|
-
|
|
4532
|
+
c && !confirm("You have unsaved changes. Are you sure you want to cancel?") || H();
|
|
4533
4533
|
}, Z = () => {
|
|
4534
4534
|
try {
|
|
4535
|
-
const b = (o == null ? void 0 : o.getValue()) || "",
|
|
4536
|
-
|
|
4535
|
+
const b = (o == null ? void 0 : o.getValue()) || "", k = document.createElement("div");
|
|
4536
|
+
k.innerHTML = b, k.querySelectorAll(
|
|
4537
4537
|
'script, iframe[src^="javascript:"], object, embed'
|
|
4538
|
-
).forEach((
|
|
4538
|
+
).forEach((F) => F.remove()), e.innerHTML = k.innerHTML;
|
|
4539
4539
|
try {
|
|
4540
4540
|
e.dispatchEvent(
|
|
4541
4541
|
new InputEvent("input", {
|
|
@@ -4544,42 +4544,42 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4544
4544
|
inputType: "insertReplacementText"
|
|
4545
4545
|
})
|
|
4546
4546
|
);
|
|
4547
|
-
} catch (
|
|
4547
|
+
} catch (F) {
|
|
4548
4548
|
e.dispatchEvent(
|
|
4549
4549
|
new Event("input", { bubbles: !0 })
|
|
4550
4550
|
);
|
|
4551
4551
|
}
|
|
4552
4552
|
e.dispatchEvent(
|
|
4553
4553
|
new Event("change", { bubbles: !0 })
|
|
4554
|
-
),
|
|
4554
|
+
), P(!1), H();
|
|
4555
4555
|
} catch (b) {
|
|
4556
4556
|
alert("Failed to update HTML. Please check your syntax."), console.error("HTML update error:", b);
|
|
4557
4557
|
}
|
|
4558
4558
|
};
|
|
4559
|
-
|
|
4560
|
-
b.target ===
|
|
4561
|
-
}),
|
|
4562
|
-
const
|
|
4563
|
-
|
|
4564
|
-
}), document.body.appendChild(
|
|
4565
|
-
if (!(
|
|
4559
|
+
w && R(w, "click", K), O && R(O, "click", j), $ && R($, "click", q), I && R(I, "click", H), C && R(C, "click", G), M && R(M, "click", Z), R(d, "click", (b) => {
|
|
4560
|
+
b.target === d && H();
|
|
4561
|
+
}), R(document, "keydown", (b) => {
|
|
4562
|
+
const k = b;
|
|
4563
|
+
k.key === "Escape" && (k.preventDefault(), H());
|
|
4564
|
+
}), document.body.appendChild(d), requestAnimationFrame(() => {
|
|
4565
|
+
if (!(g || !d.isConnected))
|
|
4566
4566
|
try {
|
|
4567
|
-
o =
|
|
4567
|
+
o = le(T, {
|
|
4568
4568
|
value: r,
|
|
4569
4569
|
theme: "dark",
|
|
4570
4570
|
readOnly: !1,
|
|
4571
4571
|
extensions: [
|
|
4572
|
+
new J(),
|
|
4573
|
+
new ee(),
|
|
4572
4574
|
new te(),
|
|
4573
|
-
new ie(),
|
|
4574
4575
|
new se(),
|
|
4575
|
-
new
|
|
4576
|
+
new U(),
|
|
4576
4577
|
new re(),
|
|
4577
|
-
new
|
|
4578
|
-
new he()
|
|
4578
|
+
new oe()
|
|
4579
4579
|
]
|
|
4580
4580
|
}), o.on("change", () => {
|
|
4581
4581
|
const b = (o == null ? void 0 : o.getValue()) || "";
|
|
4582
|
-
|
|
4582
|
+
P(b !== r);
|
|
4583
4583
|
}), requestAnimationFrame(() => o == null ? void 0 : o.focus());
|
|
4584
4584
|
} catch (b) {
|
|
4585
4585
|
console.error("Failed to initialize code editor:", b);
|
|
@@ -4595,6 +4595,6 @@ const B = '[data-theme="dark"], .dark, .editora-theme-dark', de = `/* Source Edi
|
|
|
4595
4595
|
}
|
|
4596
4596
|
});
|
|
4597
4597
|
export {
|
|
4598
|
-
|
|
4598
|
+
he as CodePlugin
|
|
4599
4599
|
};
|
|
4600
|
-
//# sourceMappingURL=CodePlugin.native-
|
|
4600
|
+
//# sourceMappingURL=CodePlugin.native-knhM8NNo.mjs.map
|