@dou-ui/code 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
@@ -1,13 +1,15 @@
1
1
  import { splitLines } from "./core/text.js";
2
2
  import { format, useCodeMessages } from "./locale.js";
3
- import { defineCodeExtension } from "./extension.js";
3
+ import { WIDGET_HEIGHT_KEY, defineCodeExtension } from "./extension.js";
4
+ import render_part_default from "./render-part.js";
4
5
  import code_editor_default from "./code-editor.js";
5
6
  import { diffText, lineStarts } from "./core/diff.js";
6
7
  import { DouButton, DouTooltip, createScrollLink, useNamespace } from "dou-ui";
7
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, onBeforeUnmount, onMounted, openBlock, reactive, ref, toDisplayString, unref, watch, withCtx } from "vue";
8
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, h, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, provide, reactive, ref, renderList, toDisplayString, unref, watch, withCtx } from "vue";
8
9
  import { ArrowDownIcon, ArrowUpIcon, DiffSplitIcon, DiffUnifiedIcon, FoldVerticalIcon, UnfoldVerticalIcon } from "@dou-ui/icons";
9
10
  // src/code-diff.vue?vue&type=script&setup=true&lang.ts
10
11
  var _hoisted_1 = ["aria-label"];
12
+ var _hoisted_2 = ["role", "aria-label"];
11
13
  /**
12
14
  * Two texts compared: side by side, or the changes in one column. Changed
13
15
  * lines are tinted, the words that changed inside them marked, and long
@@ -22,6 +24,11 @@ var Kind = /* @__PURE__ */ function(Kind) {
22
24
  Kind[Kind["Added"] = 2] = "Added";
23
25
  return Kind;
24
26
  }(Kind || {});
27
+ var LINE = 20;
28
+ /**
29
+ * Where a spot beside line `line` of `side` is on the other side: beside
30
+ * a line there, or inside the filler of a change.
31
+ */
25
32
  var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
26
33
  name: "DouCodeDiff",
27
34
  __name: "code-diff",
@@ -51,11 +58,17 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
51
58
  default: false
52
59
  },
53
60
  extensions: { default: void 0 },
61
+ gutters: { default: void 0 },
62
+ widgets: { default: void 0 },
54
63
  tabSize: { default: 2 },
55
64
  toolbar: {
56
65
  type: Boolean,
57
66
  default: true
58
67
  },
68
+ bordered: {
69
+ type: Boolean,
70
+ default: true
71
+ },
59
72
  messages: { default: void 0 }
60
73
  },
61
74
  emits: ["update:modelValue", "update:mode"],
@@ -127,6 +140,17 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
127
140
  /** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */
128
141
  const opened = reactive(/* @__PURE__ */ new Set());
129
142
  const allOpen = ref(false);
143
+ /** The lines with a marker or widget on each side, which collapsing leaves in view. */
144
+ const annotatedLines = computed(() => {
145
+ const out = {
146
+ a: /* @__PURE__ */ new Set(),
147
+ b: /* @__PURE__ */ new Set()
148
+ };
149
+ const add = (side, line) => out[side === "original" ? "a" : "b"].add(line);
150
+ for (const gutter of props.gutters ?? []) for (const marker of gutter.markers) add(marker.side, marker.line);
151
+ for (const widget of props.widgets ?? []) add(widget.side, widget.line);
152
+ return out;
153
+ });
130
154
  const unchanged = computed(() => {
131
155
  const list = hunks.value;
132
156
  const total = originalLines.value.length;
@@ -153,15 +177,25 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
153
177
  key: a
154
178
  });
155
179
  };
180
+ const kept = annotatedLines.value;
181
+ const cut = (a, b, count, before, after) => {
182
+ let from = 0;
183
+ for (let i = 0; i < count; i++) {
184
+ if (!kept.a.has(a + i) && !kept.b.has(b + i)) continue;
185
+ if (i > from) push(a + from, b + from, i - from, from > 0 || before, true);
186
+ from = Math.max(from, i);
187
+ }
188
+ push(a + from, b + from, count - from, from > 0 || before, after);
189
+ };
156
190
  let a = 1;
157
191
  let b = 1;
158
192
  for (let i = 0; i < list.length; i++) {
159
193
  const hunk = list[i];
160
- push(a, b, hunk.originalStart - a, i > 0, true);
194
+ cut(a, b, hunk.originalStart - a, i > 0, true);
161
195
  a = hunk.originalStart + hunk.originalCount;
162
196
  b = hunk.modifiedStart + hunk.modifiedCount;
163
197
  }
164
- push(a, b, total - a + 1, list.length > 0, false);
198
+ cut(a, b, total - a + 1, list.length > 0, false);
165
199
  return out;
166
200
  });
167
201
  const hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0));
@@ -251,21 +285,20 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
251
285
  }],
252
286
  widgets() {
253
287
  const out = [];
288
+ const fills = splitPlan.value[side].fills;
254
289
  hunks.value.forEach((hunk, i) => {
255
290
  const missing = otherCountOf(hunk) - countOf(hunk);
256
291
  if (missing <= 0) return;
257
292
  const last = startOf(hunk) - 1 + countOf(hunk);
293
+ const blanks = fills.get(i) ?? [];
258
294
  out.push({
259
- id: `fill-${i}`,
295
+ id: `fill-${i}-${missing}-${blanks.map((blank) => blank.height).join(".")}`,
260
296
  ...last >= 1 ? { line: last } : {
261
297
  line: 1,
262
298
  position: "above"
263
299
  },
264
- height: missing * 20,
265
- render: () => h("div", {
266
- class: ns.e("filler"),
267
- style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` }
268
- })
300
+ height: missing * LINE + blanks.reduce((sum, blank) => sum + blank.height, 0),
301
+ render: () => filler(missing, blanks)
269
302
  });
270
303
  });
271
304
  const total = side === "a" ? originalLines.value.length : modifiedLines.value.length;
@@ -299,16 +332,45 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
299
332
  }
300
333
  });
301
334
  }
335
+ /** Rows of filler, or rows split by the blanks of widgets on the other side. */
336
+ const block = (count) => h("div", {
337
+ class: ns.e("filler"),
338
+ style: { height: `calc(${count} * var(--dou-code-editor-line-height))` }
339
+ });
340
+ function filler(rows, blanks) {
341
+ if (!blanks.length) return block(rows);
342
+ const children = [];
343
+ let at = 0;
344
+ for (const blank of [...blanks].sort((x, y) => x.offset - y.offset || +x.above - +y.above)) {
345
+ if (blank.offset > at) children.push(block(blank.offset - at));
346
+ children.push(spacer(blank.height, blank.span)());
347
+ at = Math.max(at, blank.offset);
348
+ }
349
+ if (rows > at) children.push(block(rows - at));
350
+ return h("div", children);
351
+ }
302
352
  const modifiedOwn = sideExtension("b");
303
- const modifiedExtensions = computed(() => [modifiedOwn, ...props.extensions ?? []]);
353
+ const modifiedExtensions = computed(() => [
354
+ annotationsB,
355
+ modifiedOwn,
356
+ annotationsEndB,
357
+ ...props.extensions ?? []
358
+ ]);
304
359
  const editorA = ref();
305
360
  const editorB = ref();
306
361
  const sideA = ref();
307
362
  const sideB = ref();
308
- const extensionsA = [sideExtension("a")];
363
+ const extensionsA = [
364
+ annotations("a"),
365
+ sideExtension("a"),
366
+ annotations("a", true)
367
+ ];
368
+ const annotationsB = annotations("b");
369
+ const annotationsEndB = annotations("b", true);
309
370
  const link = createScrollLink();
310
371
  function onScroll(event) {
311
372
  if (view.value !== "split") return;
373
+ if (spans.value.length) schedulePlace();
312
374
  const from = event.target.closest(`.${ns.e("side")}`);
313
375
  const source = from?.querySelector(".dou-code-editor__scroller");
314
376
  if (!source || source !== event.target) return;
@@ -326,12 +388,16 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
326
388
  const hunkLines = [];
327
389
  const runLines = /* @__PURE__ */ new Map();
328
390
  const marks = [];
391
+ const aRows = new Int32Array(a.length + 1);
392
+ const bRows = new Int32Array(b.length + 1);
329
393
  let pos = 0;
330
394
  const push = (text, kind, an, bn) => {
331
395
  lines.push(text);
332
396
  kinds.push(kind);
333
397
  aNums.push(an);
334
398
  bNums.push(bn);
399
+ if (an) aRows[an] = lines.length;
400
+ if (bn) bRows[bn] = lines.length;
335
401
  pos += text.length + 1;
336
402
  };
337
403
  const runs = unchanged.value;
@@ -373,6 +439,8 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
373
439
  kinds: Uint8Array.from(kinds),
374
440
  aNums: Int32Array.from(aNums),
375
441
  bNums: Int32Array.from(bNums),
442
+ aRows,
443
+ bRows,
376
444
  hunkLines,
377
445
  runLines,
378
446
  marks
@@ -398,7 +466,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
398
466
  }
399
467
  return out;
400
468
  };
401
- const inlineExtensions = [defineCodeExtension({
469
+ const inlineExtension = defineCodeExtension({
402
470
  name: "diff",
403
471
  decorations({ visible }) {
404
472
  const u = unified.value;
@@ -499,9 +567,328 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
499
567
  }
500
568
  return out;
501
569
  }
502
- })];
570
+ });
571
+ const inlineExtensions = [
572
+ inlineAnnotations(),
573
+ inlineExtension,
574
+ inlineAnnotations(true)
575
+ ];
503
576
  const editorInline = ref();
504
577
  const inlineBox = ref();
578
+ /** One line's height, before the editors have measured theirs. */
579
+ const sideName = (side) => side === "a" ? "original" : "modified";
580
+ /** The widgets' measured heights, by id, for the blank left beside each. */
581
+ const heights = reactive(/* @__PURE__ */ new Map());
582
+ let heightObserver;
583
+ /** The element each widget's content is drawn in now, by id, and back. */
584
+ const measuredEls = /* @__PURE__ */ new Map();
585
+ const measuredIds = /* @__PURE__ */ new Map();
586
+ function readHeight(box, entry) {
587
+ const id = measuredIds.get(box);
588
+ const size = entry?.borderBoxSize?.[0]?.blockSize ?? entry?.contentRect.height;
589
+ const height = size === void 0 ? box.offsetHeight : Math.round(size);
590
+ if (id && height && heights.get(id) !== height) heights.set(id, height);
591
+ }
592
+ function forget(box) {
593
+ heightObserver?.unobserve(box);
594
+ measuredIds.delete(box);
595
+ }
596
+ /** Measures a widget across both sides as drawn, now and whenever it resizes; `null` once it is gone. */
597
+ function measure(el, id) {
598
+ const had = measuredEls.get(id);
599
+ if (!el) {
600
+ if (had && !had.isConnected) {
601
+ forget(had);
602
+ measuredEls.delete(id);
603
+ }
604
+ return;
605
+ }
606
+ if (had === el) return;
607
+ if (had) forget(had);
608
+ measuredEls.set(id, el);
609
+ measuredIds.set(el, id);
610
+ readHeight(el);
611
+ if (typeof ResizeObserver === "undefined") return;
612
+ heightObserver ??= new ResizeObserver((entries) => {
613
+ for (const entry of entries) readHeight(entry.target, entry);
614
+ });
615
+ heightObserver.observe(el);
616
+ }
617
+ onBeforeUnmount(() => heightObserver?.disconnect());
618
+ const heightOf = (widget) => heights.get(widget.id) ?? widget.height ?? LINE;
619
+ const widgetIds = computed(() => new Set((props.widgets ?? []).map((widget) => widget.id)));
620
+ provide(WIDGET_HEIGHT_KEY, (key, height) => {
621
+ if (!key.startsWith("diff-widgets")) return;
622
+ const id = key.slice(key.indexOf("/") + 1);
623
+ if (widgetIds.value.has(id) && heights.get(id) !== height) heights.set(id, height);
624
+ });
625
+ /** A widget's own content. */
626
+ const content = (widget) => () => h("div", { class: ns.e("widget") }, [widget.render()]);
627
+ /** The blank across from a widget; `span` marks where a widget across both sides is drawn. */
628
+ const spacer = (height, span) => () => h("div", {
629
+ class: ns.e("spacer"),
630
+ style: { height: `${height}px` },
631
+ "data-diff-span": span
632
+ });
633
+ /** A blank inside a filler: `offset` rows into it. */
634
+ function across(side, line, above) {
635
+ const list = hunks.value;
636
+ for (let i = 0; i < list.length; i++) {
637
+ const hunk = list[i];
638
+ const start = side === "a" ? hunk.originalStart : hunk.modifiedStart;
639
+ const count = side === "a" ? hunk.originalCount : hunk.modifiedCount;
640
+ if (line < start) break;
641
+ if (line >= start + count) continue;
642
+ const otherStart = side === "a" ? hunk.modifiedStart : hunk.originalStart;
643
+ const otherCount = side === "a" ? hunk.modifiedCount : hunk.originalCount;
644
+ const index = line - start;
645
+ if (index < otherCount) return { line: otherStart + index };
646
+ return {
647
+ fill: i,
648
+ offset: index - otherCount + (above ? 0 : 1)
649
+ };
650
+ }
651
+ for (const run of unchanged.value) {
652
+ const start = side === "a" ? run.a : run.b;
653
+ if (line >= start && line < start + run.count) return { line: line - start + (side === "a" ? run.b : run.a) };
654
+ }
655
+ return null;
656
+ }
657
+ /** Side by side: each widget on its side, a blank of its height on the other. */
658
+ if (process.env.NODE_ENV !== "production") {
659
+ const warned = /* @__PURE__ */ new Set();
660
+ watch(() => props.widgets, (widgets) => {
661
+ const seen = /* @__PURE__ */ new Set();
662
+ for (const widget of widgets ?? []) {
663
+ if (seen.has(widget.id) && !warned.has(widget.id)) {
664
+ warned.add(widget.id);
665
+ console.warn(`[@dou-ui/code] DouCodeDiff: widget id "${widget.id}" is used more than once; ids must be unique across both sides.`);
666
+ }
667
+ seen.add(widget.id);
668
+ }
669
+ }, { immediate: true });
670
+ }
671
+ const splitPlan = computed(() => {
672
+ const plan = {
673
+ a: {
674
+ below: [],
675
+ above: [],
676
+ fills: /* @__PURE__ */ new Map()
677
+ },
678
+ b: {
679
+ below: [],
680
+ above: [],
681
+ fills: /* @__PURE__ */ new Map()
682
+ }
683
+ };
684
+ if (view.value !== "split") return plan;
685
+ for (const widget of props.widgets ?? []) {
686
+ const own = widget.side === "original" ? "a" : "b";
687
+ const other = own === "a" ? "b" : "a";
688
+ const lines = own === "a" ? originalLines.value.length : modifiedLines.value.length;
689
+ if (!(widget.line >= 1 && widget.line <= lines)) continue;
690
+ const above = widget.position === "above";
691
+ const height = heightOf(widget);
692
+ const span = widget.span === "both" ? widget.id : void 0;
693
+ const put = (side, line, render, label, blank = false) => plan[side][above ? "above" : "below"].push({
694
+ id: blank ? `${widget.id}~${height}` : widget.id,
695
+ line,
696
+ position: above ? "above" : "below",
697
+ height,
698
+ label,
699
+ render
700
+ });
701
+ if (span) put(own, widget.line, spacer(height, span), widget.label, true);
702
+ else put(own, widget.line, content(widget), widget.label);
703
+ const spot = across(own, widget.line, above);
704
+ if (!spot) continue;
705
+ if ("fill" in spot) {
706
+ const fills = plan[other].fills;
707
+ const blanks = fills.get(spot.fill) ?? [];
708
+ blanks.push({
709
+ offset: spot.offset,
710
+ above,
711
+ height,
712
+ span
713
+ });
714
+ fills.set(spot.fill, blanks);
715
+ } else put(other, spot.line, spacer(height, span), void 0, true);
716
+ }
717
+ return plan;
718
+ });
719
+ /** The widgets drawn across both sides, over them. */
720
+ const spans = computed(() => view.value === "split" ? (props.widgets ?? []).filter((widget) => widget.span === "both") : []);
721
+ /** A column of `gutters` as one side's editor draws it. */
722
+ function sideGutter(gutter, side) {
723
+ const name = sideName(side);
724
+ return {
725
+ name: gutter.name,
726
+ width: gutter.width,
727
+ markers: ({ visible }) => gutter.markers.filter((marker) => marker.side === name && marker.line >= visible.from && marker.line <= visible.to),
728
+ onPress: gutter.onPress && ((line, event) => gutter.onPress(line, event, name))
729
+ };
730
+ }
731
+ /**
732
+ * The `gutters` and `widgets` of one side. Two of them go around the
733
+ * diff's own: widgets below a line come before its filler or bar, those
734
+ * above a line after them.
735
+ */
736
+ function annotations(side, end = false) {
737
+ return defineCodeExtension({
738
+ name: end ? "diff-widgets-end" : "diff-widgets",
739
+ get gutters() {
740
+ return end ? [] : (props.gutters ?? []).map((gutter) => sideGutter(gutter, side));
741
+ },
742
+ widgets: () => splitPlan.value[side][end ? "above" : "below"]
743
+ });
744
+ }
745
+ /** Where line `line` of `side` is inline, from 1; 0 when it isn't there. */
746
+ function inlineRow(u, side, line) {
747
+ const rows = side === "original" ? u.aRows : u.bRows;
748
+ return line >= 1 && line < rows.length ? rows[line] : 0;
749
+ }
750
+ /** The `gutters` and `widgets` inline, on the rows of their lines. */
751
+ function inlineAnnotations(end = false) {
752
+ return defineCodeExtension({
753
+ name: end ? "diff-widgets-end" : "diff-widgets",
754
+ get gutters() {
755
+ if (end) return [];
756
+ return (props.gutters ?? []).map((gutter) => ({
757
+ name: gutter.name,
758
+ width: gutter.width,
759
+ markers: ({ visible }) => {
760
+ const u = unified.value;
761
+ if (!u) return [];
762
+ const out = [];
763
+ for (const side of ["original", "modified"]) for (const marker of gutter.markers) {
764
+ if (marker.side !== side) continue;
765
+ const row = inlineRow(u, side, marker.line);
766
+ if (row && row >= visible.from && row <= visible.to) out.push({
767
+ ...marker,
768
+ line: row
769
+ });
770
+ }
771
+ return out;
772
+ },
773
+ onPress: gutter.onPress && ((row, event) => {
774
+ const u = unified.value;
775
+ if (!u) return;
776
+ const a = u.aNums[row - 1] ?? 0;
777
+ const b = u.bNums[row - 1] ?? 0;
778
+ const has = (side, line) => line > 0 && gutter.markers.some((m) => m.side === side && m.line === line);
779
+ if (has("modified", b) || b && !has("original", a)) gutter.onPress(b, event, "modified");
780
+ else gutter.onPress(a, event, "original");
781
+ })
782
+ }));
783
+ },
784
+ widgets() {
785
+ const u = unified.value;
786
+ if (!u) return [];
787
+ const out = [];
788
+ for (const widget of props.widgets ?? []) {
789
+ if (widget.position === "above" !== end) continue;
790
+ const row = inlineRow(u, widget.side, widget.line);
791
+ if (!row) continue;
792
+ out.push({
793
+ id: widget.id,
794
+ line: row,
795
+ position: widget.position,
796
+ height: heightOf(widget),
797
+ label: widget.label,
798
+ render: content(widget)
799
+ });
800
+ }
801
+ return out;
802
+ }
803
+ });
804
+ }
805
+ const spanLayer = ref();
806
+ /** Where the layer of widgets across both sides is: over the text of the sides. */
807
+ const spanBox = ref({
808
+ top: 0,
809
+ height: 0
810
+ });
811
+ /** Each widget's y in the layer, by id; left out while its blank isn't drawn. */
812
+ const spanTops = ref({});
813
+ let placeFrame = 0;
814
+ function schedulePlace() {
815
+ if (!placeFrame && typeof requestAnimationFrame !== "undefined") placeFrame = requestAnimationFrame(placeSpans);
816
+ }
817
+ /** Puts each widget across both sides over its blank. */
818
+ function placeSpans() {
819
+ placeFrame = 0;
820
+ const body = spanLayer.value?.parentElement;
821
+ const scroller = sideA.value?.querySelector(".dou-code-editor__scroller");
822
+ if (!body || !scroller) return;
823
+ const frame = scroller.getBoundingClientRect();
824
+ const top = frame.top - body.getBoundingClientRect().top;
825
+ if (spanBox.value.top !== top || spanBox.value.height !== frame.height) spanBox.value = {
826
+ top,
827
+ height: frame.height
828
+ };
829
+ const tops = {};
830
+ for (const box of [sideA.value, sideB.value]) for (const el of box?.querySelectorAll("[data-diff-span]") ?? []) {
831
+ const id = el.dataset.diffSpan;
832
+ if (!(id in tops)) tops[id] = el.getBoundingClientRect().top - frame.top;
833
+ }
834
+ const had = spanTops.value;
835
+ const keys = Object.keys(tops);
836
+ if (keys.length !== Object.keys(had).length || keys.some((id) => had[id] !== tops[id])) spanTops.value = tops;
837
+ }
838
+ let stopPlacing;
839
+ function startPlacing() {
840
+ stopPlacing?.();
841
+ stopPlacing = void 0;
842
+ if (!spans.value.length || !sideA.value) return;
843
+ placeSpans();
844
+ const moved = typeof MutationObserver === "undefined" ? null : new MutationObserver(schedulePlace);
845
+ for (const side of [sideA.value, sideB.value]) if (side) moved?.observe(side, {
846
+ subtree: true,
847
+ childList: true,
848
+ attributeFilter: ["style"]
849
+ });
850
+ const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedulePlace);
851
+ if (root.value) resized?.observe(root.value);
852
+ stopPlacing = () => {
853
+ moved?.disconnect();
854
+ resized?.disconnect();
855
+ if (placeFrame) cancelAnimationFrame(placeFrame);
856
+ placeFrame = 0;
857
+ };
858
+ }
859
+ watch(() => spans.value.length > 0 && view.value, startPlacing, { flush: "post" });
860
+ onMounted(startPlacing);
861
+ onBeforeUnmount(() => stopPlacing?.());
862
+ /**
863
+ * While the text scrolls, the widgets across both sides are hidden: placed a
864
+ * frame late, they would trail behind it. They come back once it rests.
865
+ */
866
+ const spansScrolling = ref(false);
867
+ let restTimer;
868
+ function onSideScroll() {
869
+ if (!spans.value.length) return;
870
+ spansScrolling.value = true;
871
+ clearTimeout(restTimer);
872
+ restTimer = setTimeout(() => {
873
+ spansScrolling.value = false;
874
+ placeSpans();
875
+ }, 120);
876
+ }
877
+ onBeforeUnmount(() => clearTimeout(restTimer));
878
+ /** A wheel over a widget across both sides scrolls the text under it. */
879
+ function onSpanWheel(event) {
880
+ const scroller = sideB.value?.querySelector(".dou-code-editor__scroller");
881
+ if (!scroller) return;
882
+ const unit = event.deltaMode === 1 ? LINE : event.deltaMode === 2 ? scroller.clientHeight : 1;
883
+ const dy = event.deltaY * unit;
884
+ const dx = event.deltaX * unit;
885
+ const canY = dy < 0 ? scroller.scrollTop > 0 : dy > 0 && scroller.scrollTop + scroller.clientHeight < scroller.scrollHeight - 1;
886
+ const canX = dx < 0 ? scroller.scrollLeft > 0 : dx > 0 && scroller.scrollLeft + scroller.clientWidth < scroller.scrollWidth - 1;
887
+ if (!canY && !canX) return;
888
+ event.preventDefault();
889
+ if (canY) scroller.scrollTop += dy;
890
+ if (canX) scroller.scrollLeft += dx;
891
+ }
505
892
  /** Shows the run of hidden lines a cursor moved into, e.g. with search. */
506
893
  function revealAt(side, result) {
507
894
  if (!hiddenCount.value) return;
@@ -608,7 +995,11 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
608
995
  return openBlock(), createElementBlock("div", {
609
996
  ref_key: "root",
610
997
  ref: root,
611
- class: normalizeClass([unref(ns).b(), unref(ns).m(view.value)]),
998
+ class: normalizeClass([
999
+ unref(ns).b(),
1000
+ unref(ns).m(view.value),
1001
+ unref(ns).is("bordered", __props.bordered)
1002
+ ]),
612
1003
  role: "group",
613
1004
  "aria-label": unref(messages).diff
614
1005
  }, [
@@ -700,6 +1091,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
700
1091
  createElementVNode("div", {
701
1092
  ref_key: "sideA",
702
1093
  ref: sideA,
1094
+ onScrollCapturePassive: onSideScroll,
703
1095
  class: normalizeClass([unref(ns).e("side"), "is-original"])
704
1096
  }, [createVNode(code_editor_default, {
705
1097
  ref_key: "editorA",
@@ -713,6 +1105,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
713
1105
  "aria-label": unref(messages).diffOriginal,
714
1106
  foldable: false,
715
1107
  "active-line": false,
1108
+ bordered: false,
716
1109
  readonly: "",
717
1110
  onTransaction: _cache[0] || (_cache[0] = ($event) => revealAt("a", $event))
718
1111
  }, null, 8, [
@@ -721,10 +1114,11 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
721
1114
  "tab-size",
722
1115
  "messages",
723
1116
  "aria-label"
724
- ])], 2),
1117
+ ])], 34),
725
1118
  createElementVNode("div", {
726
1119
  ref_key: "sideB",
727
1120
  ref: sideB,
1121
+ onScrollCapturePassive: onSideScroll,
728
1122
  class: normalizeClass([unref(ns).e("side"), "is-modified"])
729
1123
  }, [createVNode(code_editor_default, {
730
1124
  ref_key: "editorB",
@@ -738,6 +1132,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
738
1132
  "aria-label": unref(messages).diffModified,
739
1133
  foldable: false,
740
1134
  "active-line": false,
1135
+ bordered: false,
741
1136
  readonly: !__props.editable,
742
1137
  "onUpdate:modelValue": onModifiedInput,
743
1138
  onTransaction: _cache[1] || (_cache[1] = ($event) => revealAt("b", $event))
@@ -749,7 +1144,28 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
749
1144
  "messages",
750
1145
  "aria-label",
751
1146
  "readonly"
752
- ])], 2)
1147
+ ])], 34),
1148
+ spans.value.length ? (openBlock(), createElementBlock("div", {
1149
+ key: 0,
1150
+ ref_key: "spanLayer",
1151
+ ref: spanLayer,
1152
+ class: normalizeClass(unref(ns).e("spans")),
1153
+ style: normalizeStyle({
1154
+ top: `${spanBox.value.top}px`,
1155
+ height: `${spanBox.value.height}px`
1156
+ })
1157
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(spans.value, (widget) => {
1158
+ return openBlock(), createElementBlock("div", {
1159
+ key: widget.id,
1160
+ ref_for: true,
1161
+ ref: (el) => measure(el, widget.id),
1162
+ class: normalizeClass([unref(ns).e("span"), unref(ns).is("placed", widget.id in spanTops.value && !spansScrolling.value)]),
1163
+ style: normalizeStyle({ transform: `translateY(${spanTops.value[widget.id] ?? 0}px)` }),
1164
+ role: widget.label ? "group" : void 0,
1165
+ "aria-label": widget.label,
1166
+ onWheel: onSpanWheel
1167
+ }, [createVNode(unref(render_part_default), { render: widget.render }, null, 8, ["render"])], 46, _hoisted_2);
1168
+ }), 128))], 6)) : createCommentVNode("", true)
753
1169
  ], 34)) : (openBlock(), createElementBlock("div", {
754
1170
  key: 2,
755
1171
  ref_key: "inlineBox",
@@ -768,6 +1184,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
768
1184
  "line-numbers": false,
769
1185
  foldable: false,
770
1186
  "active-line": false,
1187
+ bordered: false,
771
1188
  wrap: __props.wrap,
772
1189
  readonly: "",
773
1190
  onTransaction: _cache[2] || (_cache[2] = ($event) => revealAt("inline", $event))