@dou-ui/code 0.1.0-alpha.0 → 0.1.0-alpha.10

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,20 @@ 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
+ /**
144
+ * The lines with a marker or widget on each side, which collapsing leaves in
145
+ * view. A marker shown only on hover is out of sight, so it doesn't count.
146
+ */
147
+ const annotatedLines = computed(() => {
148
+ const out = {
149
+ a: /* @__PURE__ */ new Set(),
150
+ b: /* @__PURE__ */ new Set()
151
+ };
152
+ const add = (side, line) => out[side === "original" ? "a" : "b"].add(line);
153
+ for (const gutter of props.gutters ?? []) for (const marker of gutter.markers ?? []) if (marker.visible !== "hover") add(marker.side, marker.line);
154
+ for (const widget of props.widgets ?? []) add(widget.side, widget.line);
155
+ return out;
156
+ });
130
157
  const unchanged = computed(() => {
131
158
  const list = hunks.value;
132
159
  const total = originalLines.value.length;
@@ -153,15 +180,25 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
153
180
  key: a
154
181
  });
155
182
  };
183
+ const kept = annotatedLines.value;
184
+ const cut = (a, b, count, before, after) => {
185
+ let from = 0;
186
+ for (let i = 0; i < count; i++) {
187
+ if (!kept.a.has(a + i) && !kept.b.has(b + i)) continue;
188
+ if (i > from) push(a + from, b + from, i - from, from > 0 || before, true);
189
+ from = Math.max(from, i);
190
+ }
191
+ push(a + from, b + from, count - from, from > 0 || before, after);
192
+ };
156
193
  let a = 1;
157
194
  let b = 1;
158
195
  for (let i = 0; i < list.length; i++) {
159
196
  const hunk = list[i];
160
- push(a, b, hunk.originalStart - a, i > 0, true);
197
+ cut(a, b, hunk.originalStart - a, i > 0, true);
161
198
  a = hunk.originalStart + hunk.originalCount;
162
199
  b = hunk.modifiedStart + hunk.modifiedCount;
163
200
  }
164
- push(a, b, total - a + 1, list.length > 0, false);
201
+ cut(a, b, total - a + 1, list.length > 0, false);
165
202
  return out;
166
203
  });
167
204
  const hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0));
@@ -251,21 +288,20 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
251
288
  }],
252
289
  widgets() {
253
290
  const out = [];
291
+ const fills = splitPlan.value[side].fills;
254
292
  hunks.value.forEach((hunk, i) => {
255
293
  const missing = otherCountOf(hunk) - countOf(hunk);
256
294
  if (missing <= 0) return;
257
295
  const last = startOf(hunk) - 1 + countOf(hunk);
296
+ const blanks = fills.get(i) ?? [];
258
297
  out.push({
259
- id: `fill-${i}`,
298
+ id: `fill-${i}-${missing}-${blanks.map((blank) => blank.height).join(".")}`,
260
299
  ...last >= 1 ? { line: last } : {
261
300
  line: 1,
262
301
  position: "above"
263
302
  },
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
- })
303
+ height: missing * LINE + blanks.reduce((sum, blank) => sum + blank.height, 0),
304
+ render: () => filler(missing, blanks)
269
305
  });
270
306
  });
271
307
  const total = side === "a" ? originalLines.value.length : modifiedLines.value.length;
@@ -299,16 +335,45 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
299
335
  }
300
336
  });
301
337
  }
338
+ /** Rows of filler, or rows split by the blanks of widgets on the other side. */
339
+ const block = (count) => h("div", {
340
+ class: ns.e("filler"),
341
+ style: { height: `calc(${count} * var(--dou-code-editor-line-height))` }
342
+ });
343
+ function filler(rows, blanks) {
344
+ if (!blanks.length) return block(rows);
345
+ const children = [];
346
+ let at = 0;
347
+ for (const blank of [...blanks].sort((x, y) => x.offset - y.offset || +x.above - +y.above)) {
348
+ if (blank.offset > at) children.push(block(blank.offset - at));
349
+ children.push(spacer(blank.height, blank.span)());
350
+ at = Math.max(at, blank.offset);
351
+ }
352
+ if (rows > at) children.push(block(rows - at));
353
+ return h("div", children);
354
+ }
302
355
  const modifiedOwn = sideExtension("b");
303
- const modifiedExtensions = computed(() => [modifiedOwn, ...props.extensions ?? []]);
356
+ const modifiedExtensions = computed(() => [
357
+ annotationsB,
358
+ modifiedOwn,
359
+ annotationsEndB,
360
+ ...props.extensions ?? []
361
+ ]);
304
362
  const editorA = ref();
305
363
  const editorB = ref();
306
364
  const sideA = ref();
307
365
  const sideB = ref();
308
- const extensionsA = [sideExtension("a")];
366
+ const extensionsA = [
367
+ annotations("a"),
368
+ sideExtension("a"),
369
+ annotations("a", true)
370
+ ];
371
+ const annotationsB = annotations("b");
372
+ const annotationsEndB = annotations("b", true);
309
373
  const link = createScrollLink();
310
374
  function onScroll(event) {
311
375
  if (view.value !== "split") return;
376
+ if (spans.value.length) schedulePlace();
312
377
  const from = event.target.closest(`.${ns.e("side")}`);
313
378
  const source = from?.querySelector(".dou-code-editor__scroller");
314
379
  if (!source || source !== event.target) return;
@@ -326,12 +391,16 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
326
391
  const hunkLines = [];
327
392
  const runLines = /* @__PURE__ */ new Map();
328
393
  const marks = [];
394
+ const aRows = new Int32Array(a.length + 1);
395
+ const bRows = new Int32Array(b.length + 1);
329
396
  let pos = 0;
330
397
  const push = (text, kind, an, bn) => {
331
398
  lines.push(text);
332
399
  kinds.push(kind);
333
400
  aNums.push(an);
334
401
  bNums.push(bn);
402
+ if (an) aRows[an] = lines.length;
403
+ if (bn) bRows[bn] = lines.length;
335
404
  pos += text.length + 1;
336
405
  };
337
406
  const runs = unchanged.value;
@@ -373,6 +442,8 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
373
442
  kinds: Uint8Array.from(kinds),
374
443
  aNums: Int32Array.from(aNums),
375
444
  bNums: Int32Array.from(bNums),
445
+ aRows,
446
+ bRows,
376
447
  hunkLines,
377
448
  runLines,
378
449
  marks
@@ -398,7 +469,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
398
469
  }
399
470
  return out;
400
471
  };
401
- const inlineExtensions = [defineCodeExtension({
472
+ const inlineExtension = defineCodeExtension({
402
473
  name: "diff",
403
474
  decorations({ visible }) {
404
475
  const u = unified.value;
@@ -499,9 +570,382 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
499
570
  }
500
571
  return out;
501
572
  }
502
- })];
573
+ });
574
+ const inlineExtensions = [
575
+ inlineAnnotations(),
576
+ inlineExtension,
577
+ inlineAnnotations(true)
578
+ ];
503
579
  const editorInline = ref();
504
580
  const inlineBox = ref();
581
+ /** One line's height, before the editors have measured theirs. */
582
+ const sideName = (side) => side === "a" ? "original" : "modified";
583
+ /** The widgets' measured heights, by id, for the blank left beside each. */
584
+ const heights = reactive(/* @__PURE__ */ new Map());
585
+ let heightObserver;
586
+ /** The element each widget's content is drawn in now, by id, and back. */
587
+ const measuredEls = /* @__PURE__ */ new Map();
588
+ const measuredIds = /* @__PURE__ */ new Map();
589
+ function readHeight(box, entry) {
590
+ const id = measuredIds.get(box);
591
+ const size = entry?.borderBoxSize?.[0]?.blockSize ?? entry?.contentRect.height;
592
+ const height = size === void 0 ? box.offsetHeight : Math.round(size);
593
+ if (id && height && heights.get(id) !== height) heights.set(id, height);
594
+ }
595
+ function forget(box) {
596
+ heightObserver?.unobserve(box);
597
+ measuredIds.delete(box);
598
+ }
599
+ /** Measures a widget across both sides as drawn, now and whenever it resizes; `null` once it is gone. */
600
+ function measure(el, id) {
601
+ const had = measuredEls.get(id);
602
+ if (!el) {
603
+ if (had && !had.isConnected) {
604
+ forget(had);
605
+ measuredEls.delete(id);
606
+ }
607
+ return;
608
+ }
609
+ if (had === el) return;
610
+ if (had) forget(had);
611
+ measuredEls.set(id, el);
612
+ measuredIds.set(el, id);
613
+ readHeight(el);
614
+ if (typeof ResizeObserver === "undefined") return;
615
+ heightObserver ??= new ResizeObserver((entries) => {
616
+ for (const entry of entries) readHeight(entry.target, entry);
617
+ });
618
+ heightObserver.observe(el);
619
+ }
620
+ onBeforeUnmount(() => heightObserver?.disconnect());
621
+ const heightOf = (widget) => heights.get(widget.id) ?? widget.height ?? LINE;
622
+ const widgetIds = computed(() => new Set((props.widgets ?? []).map((widget) => widget.id)));
623
+ provide(WIDGET_HEIGHT_KEY, (key, height) => {
624
+ if (!key.startsWith("diff-widgets")) return;
625
+ const id = key.slice(key.indexOf("/") + 1);
626
+ if (widgetIds.value.has(id) && heights.get(id) !== height) heights.set(id, height);
627
+ });
628
+ /** A widget's own content. */
629
+ const content = (widget) => () => h("div", { class: ns.e("widget") }, [widget.render()]);
630
+ /** The blank across from a widget; `span` marks where a widget across both sides is drawn. */
631
+ const spacer = (height, span) => () => h("div", {
632
+ class: ns.e("spacer"),
633
+ style: { height: `${height}px` },
634
+ "data-diff-span": span
635
+ });
636
+ /** A blank inside a filler: `offset` rows into it. */
637
+ function across(side, line, above) {
638
+ const list = hunks.value;
639
+ for (let i = 0; i < list.length; i++) {
640
+ const hunk = list[i];
641
+ const start = side === "a" ? hunk.originalStart : hunk.modifiedStart;
642
+ const count = side === "a" ? hunk.originalCount : hunk.modifiedCount;
643
+ if (line < start) break;
644
+ if (line >= start + count) continue;
645
+ const otherStart = side === "a" ? hunk.modifiedStart : hunk.originalStart;
646
+ const otherCount = side === "a" ? hunk.modifiedCount : hunk.originalCount;
647
+ const index = line - start;
648
+ if (index < otherCount) return { line: otherStart + index };
649
+ return {
650
+ fill: i,
651
+ offset: index - otherCount + (above ? 0 : 1)
652
+ };
653
+ }
654
+ for (const run of unchanged.value) {
655
+ const start = side === "a" ? run.a : run.b;
656
+ if (line >= start && line < start + run.count) return { line: line - start + (side === "a" ? run.b : run.a) };
657
+ }
658
+ return null;
659
+ }
660
+ /** Side by side: each widget on its side, a blank of its height on the other. */
661
+ if (process.env.NODE_ENV !== "production") {
662
+ const warned = /* @__PURE__ */ new Set();
663
+ watch(() => props.widgets, (widgets) => {
664
+ const seen = /* @__PURE__ */ new Set();
665
+ for (const widget of widgets ?? []) {
666
+ if (seen.has(widget.id) && !warned.has(widget.id)) {
667
+ warned.add(widget.id);
668
+ console.warn(`[@dou-ui/code] DouCodeDiff: widget id "${widget.id}" is used more than once; ids must be unique across both sides.`);
669
+ }
670
+ seen.add(widget.id);
671
+ }
672
+ }, { immediate: true });
673
+ }
674
+ const splitPlan = computed(() => {
675
+ const plan = {
676
+ a: {
677
+ below: [],
678
+ above: [],
679
+ fills: /* @__PURE__ */ new Map()
680
+ },
681
+ b: {
682
+ below: [],
683
+ above: [],
684
+ fills: /* @__PURE__ */ new Map()
685
+ }
686
+ };
687
+ if (view.value !== "split") return plan;
688
+ for (const widget of props.widgets ?? []) {
689
+ const own = widget.side === "original" ? "a" : "b";
690
+ const other = own === "a" ? "b" : "a";
691
+ const lines = own === "a" ? originalLines.value.length : modifiedLines.value.length;
692
+ if (!(widget.line >= 1 && widget.line <= lines)) continue;
693
+ const above = widget.position === "above";
694
+ const height = heightOf(widget);
695
+ const span = widget.span === "both" ? widget.id : void 0;
696
+ const put = (side, line, render, label, blank = false) => plan[side][above ? "above" : "below"].push({
697
+ id: blank ? `${widget.id}~${height}` : widget.id,
698
+ line,
699
+ position: above ? "above" : "below",
700
+ height,
701
+ label,
702
+ render
703
+ });
704
+ if (span) put(own, widget.line, spacer(height, span), widget.label, true);
705
+ else put(own, widget.line, content(widget), widget.label);
706
+ const spot = across(own, widget.line, above);
707
+ if (!spot) continue;
708
+ if ("fill" in spot) {
709
+ const fills = plan[other].fills;
710
+ const blanks = fills.get(spot.fill) ?? [];
711
+ blanks.push({
712
+ offset: spot.offset,
713
+ above,
714
+ height,
715
+ span
716
+ });
717
+ fills.set(spot.fill, blanks);
718
+ } else put(other, spot.line, spacer(height, span), void 0, true);
719
+ }
720
+ return plan;
721
+ });
722
+ /** The widgets drawn across both sides, over them. */
723
+ const spans = computed(() => view.value === "split" ? (props.widgets ?? []).filter((widget) => widget.span === "both") : []);
724
+ /** Whether a column's `hoverMarker` goes on the lines of `side`. */
725
+ function hoversOn(gutter, side) {
726
+ return !!gutter.hoverMarker && (!gutter.hoverMarker.side || gutter.hoverMarker.side === side);
727
+ }
728
+ /** Whether a column has a marker of its own on line `line` of `side`. */
729
+ function ownMarkerOn(gutter, side, line) {
730
+ return line > 0 && (gutter.markers ?? []).some((m) => m.side === side && m.line === line);
731
+ }
732
+ /**
733
+ * Which line of which side a press on a column goes to, or `null` for none.
734
+ * A column whose `hoverMarker` is on one side only answers presses on the
735
+ * other side's own markers, not on its empty cells.
736
+ */
737
+ function pressedOn(gutter, side, line) {
738
+ if (!gutter.hoverMarker || hoversOn(gutter, side) || ownMarkerOn(gutter, side, line)) return side;
739
+ return null;
740
+ }
741
+ /** The column's `hoverMarker` as the editor of one side takes it, named for that side. */
742
+ function hoverMarkerOf(hover, side) {
743
+ const { title } = hover;
744
+ return {
745
+ icon: hover.icon,
746
+ text: hover.text,
747
+ class: hover.class,
748
+ title: typeof title === "function" ? (line) => title(line, side) : title
749
+ };
750
+ }
751
+ /** A column of `gutters` as one side's editor draws it. */
752
+ function sideGutter(gutter, side) {
753
+ const name = sideName(side);
754
+ return {
755
+ name: gutter.name,
756
+ width: gutter.width,
757
+ markers: ({ visible }) => (gutter.markers ?? []).filter((marker) => marker.side === name && marker.line >= visible.from && marker.line <= visible.to),
758
+ hoverMarker: hoversOn(gutter, name) ? hoverMarkerOf(gutter.hoverMarker, name) : void 0,
759
+ pressOn: gutter.hoverMarker?.side ? "markers" : gutter.pressOn,
760
+ onPress: gutter.onPress && ((line, event) => {
761
+ if (pressedOn(gutter, name, line)) gutter.onPress(line, event, name);
762
+ })
763
+ };
764
+ }
765
+ /**
766
+ * The `gutters` and `widgets` of one side. Two of them go around the
767
+ * diff's own: widgets below a line come before its filler or bar, those
768
+ * above a line after them.
769
+ */
770
+ function annotations(side, end = false) {
771
+ return defineCodeExtension({
772
+ name: end ? "diff-widgets-end" : "diff-widgets",
773
+ get gutters() {
774
+ return end ? [] : (props.gutters ?? []).map((gutter) => sideGutter(gutter, side));
775
+ },
776
+ widgets: () => splitPlan.value[side][end ? "above" : "below"]
777
+ });
778
+ }
779
+ /** Where line `line` of `side` is inline, from 1; 0 when it isn't there. */
780
+ function inlineRow(u, side, line) {
781
+ const rows = side === "original" ? u.aRows : u.bRows;
782
+ return line >= 1 && line < rows.length ? rows[line] : 0;
783
+ }
784
+ /** The `gutters` and `widgets` inline, on the rows of their lines. */
785
+ function inlineAnnotations(end = false) {
786
+ return defineCodeExtension({
787
+ name: end ? "diff-widgets-end" : "diff-widgets",
788
+ get gutters() {
789
+ if (end) return [];
790
+ return (props.gutters ?? []).map((gutter) => ({
791
+ name: gutter.name,
792
+ width: gutter.width,
793
+ pressOn: gutter.hoverMarker?.side ? "markers" : gutter.pressOn,
794
+ markers: ({ visible }) => {
795
+ const u = unified.value;
796
+ if (!u) return [];
797
+ const out = [];
798
+ const taken = /* @__PURE__ */ new Set();
799
+ for (const side of ["modified", "original"]) for (const marker of gutter.markers ?? []) {
800
+ if (marker.side !== side) continue;
801
+ const row = inlineRow(u, side, marker.line);
802
+ if (!row || row < visible.from || row > visible.to || taken.has(row)) continue;
803
+ out.push({
804
+ ...marker,
805
+ line: row
806
+ });
807
+ taken.add(row);
808
+ }
809
+ if (gutter.hoverMarker) for (let row = visible.from; row <= visible.to && row <= u.kinds.length; row++) {
810
+ if (taken.has(row)) continue;
811
+ const b = u.bNums[row - 1] ?? 0;
812
+ const a = u.aNums[row - 1] ?? 0;
813
+ const at = b && hoversOn(gutter, "modified") ? [b, "modified"] : a && hoversOn(gutter, "original") ? [a, "original"] : null;
814
+ if (!at) continue;
815
+ const { icon, text, class: className, title } = gutter.hoverMarker;
816
+ out.push({
817
+ icon,
818
+ text,
819
+ class: className,
820
+ title: typeof title === "function" ? title(at[0], at[1]) : title,
821
+ line: row,
822
+ visible: "hover"
823
+ });
824
+ }
825
+ return out;
826
+ },
827
+ onPress: gutter.onPress && ((row, event) => {
828
+ const u = unified.value;
829
+ if (!u) return;
830
+ const a = u.aNums[row - 1] ?? 0;
831
+ const b = u.bNums[row - 1] ?? 0;
832
+ const press = (side, line) => gutter.onPress(line, event, side);
833
+ if (ownMarkerOn(gutter, "modified", b)) return press("modified", b);
834
+ if (ownMarkerOn(gutter, "original", a)) return press("original", a);
835
+ if (!gutter.hoverMarker) return b ? press("modified", b) : press("original", a);
836
+ if (b && hoversOn(gutter, "modified")) press("modified", b);
837
+ else if (a && hoversOn(gutter, "original")) press("original", a);
838
+ })
839
+ }));
840
+ },
841
+ widgets() {
842
+ const u = unified.value;
843
+ if (!u) return [];
844
+ const out = [];
845
+ for (const widget of props.widgets ?? []) {
846
+ if (widget.position === "above" !== end) continue;
847
+ const row = inlineRow(u, widget.side, widget.line);
848
+ if (!row) continue;
849
+ out.push({
850
+ id: widget.id,
851
+ line: row,
852
+ position: widget.position,
853
+ height: heightOf(widget),
854
+ label: widget.label,
855
+ render: content(widget)
856
+ });
857
+ }
858
+ return out;
859
+ }
860
+ });
861
+ }
862
+ const spanLayer = ref();
863
+ /** Where the layer of widgets across both sides is: over the text of the sides. */
864
+ const spanBox = ref({
865
+ top: 0,
866
+ height: 0
867
+ });
868
+ /** Each widget's y in the layer, by id; left out while its blank isn't drawn. */
869
+ const spanTops = ref({});
870
+ let placeFrame = 0;
871
+ function schedulePlace() {
872
+ if (!placeFrame && typeof requestAnimationFrame !== "undefined") placeFrame = requestAnimationFrame(placeSpans);
873
+ }
874
+ /** Puts each widget across both sides over its blank. */
875
+ function placeSpans() {
876
+ placeFrame = 0;
877
+ const body = spanLayer.value?.parentElement;
878
+ const scroller = sideA.value?.querySelector(".dou-code-editor__scroller");
879
+ if (!body || !scroller) return;
880
+ const frame = scroller.getBoundingClientRect();
881
+ const top = frame.top - body.getBoundingClientRect().top;
882
+ if (spanBox.value.top !== top || spanBox.value.height !== frame.height) spanBox.value = {
883
+ top,
884
+ height: frame.height
885
+ };
886
+ const tops = {};
887
+ for (const box of [sideA.value, sideB.value]) for (const el of box?.querySelectorAll("[data-diff-span]") ?? []) {
888
+ const id = el.dataset.diffSpan;
889
+ if (!(id in tops)) tops[id] = el.getBoundingClientRect().top - frame.top;
890
+ }
891
+ const had = spanTops.value;
892
+ const keys = Object.keys(tops);
893
+ if (keys.length !== Object.keys(had).length || keys.some((id) => had[id] !== tops[id])) spanTops.value = tops;
894
+ }
895
+ let stopPlacing;
896
+ function startPlacing() {
897
+ stopPlacing?.();
898
+ stopPlacing = void 0;
899
+ if (!spans.value.length || !sideA.value) return;
900
+ placeSpans();
901
+ const moved = typeof MutationObserver === "undefined" ? null : new MutationObserver(schedulePlace);
902
+ for (const side of [sideA.value, sideB.value]) if (side) moved?.observe(side, {
903
+ subtree: true,
904
+ childList: true,
905
+ attributeFilter: ["style"]
906
+ });
907
+ const resized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedulePlace);
908
+ if (root.value) resized?.observe(root.value);
909
+ stopPlacing = () => {
910
+ moved?.disconnect();
911
+ resized?.disconnect();
912
+ if (placeFrame) cancelAnimationFrame(placeFrame);
913
+ placeFrame = 0;
914
+ };
915
+ }
916
+ watch(() => spans.value.length > 0 && view.value, startPlacing, { flush: "post" });
917
+ onMounted(startPlacing);
918
+ onBeforeUnmount(() => stopPlacing?.());
919
+ /**
920
+ * While the text scrolls, the widgets across both sides are hidden: placed a
921
+ * frame late, they would trail behind it. They come back once it rests.
922
+ */
923
+ const spansScrolling = ref(false);
924
+ let restTimer;
925
+ function onSideScroll() {
926
+ if (!spans.value.length) return;
927
+ spansScrolling.value = true;
928
+ clearTimeout(restTimer);
929
+ restTimer = setTimeout(() => {
930
+ spansScrolling.value = false;
931
+ placeSpans();
932
+ }, 120);
933
+ }
934
+ onBeforeUnmount(() => clearTimeout(restTimer));
935
+ /** A wheel over a widget across both sides scrolls the text under it. */
936
+ function onSpanWheel(event) {
937
+ const scroller = sideB.value?.querySelector(".dou-code-editor__scroller");
938
+ if (!scroller) return;
939
+ const unit = event.deltaMode === 1 ? LINE : event.deltaMode === 2 ? scroller.clientHeight : 1;
940
+ const dy = event.deltaY * unit;
941
+ const dx = event.deltaX * unit;
942
+ const canY = dy < 0 ? scroller.scrollTop > 0 : dy > 0 && scroller.scrollTop + scroller.clientHeight < scroller.scrollHeight - 1;
943
+ const canX = dx < 0 ? scroller.scrollLeft > 0 : dx > 0 && scroller.scrollLeft + scroller.clientWidth < scroller.scrollWidth - 1;
944
+ if (!canY && !canX) return;
945
+ event.preventDefault();
946
+ if (canY) scroller.scrollTop += dy;
947
+ if (canX) scroller.scrollLeft += dx;
948
+ }
505
949
  /** Shows the run of hidden lines a cursor moved into, e.g. with search. */
506
950
  function revealAt(side, result) {
507
951
  if (!hiddenCount.value) return;
@@ -608,7 +1052,11 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
608
1052
  return openBlock(), createElementBlock("div", {
609
1053
  ref_key: "root",
610
1054
  ref: root,
611
- class: normalizeClass([unref(ns).b(), unref(ns).m(view.value)]),
1055
+ class: normalizeClass([
1056
+ unref(ns).b(),
1057
+ unref(ns).m(view.value),
1058
+ unref(ns).is("bordered", __props.bordered)
1059
+ ]),
612
1060
  role: "group",
613
1061
  "aria-label": unref(messages).diff
614
1062
  }, [
@@ -700,6 +1148,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
700
1148
  createElementVNode("div", {
701
1149
  ref_key: "sideA",
702
1150
  ref: sideA,
1151
+ onScrollCapturePassive: onSideScroll,
703
1152
  class: normalizeClass([unref(ns).e("side"), "is-original"])
704
1153
  }, [createVNode(code_editor_default, {
705
1154
  ref_key: "editorA",
@@ -713,6 +1162,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
713
1162
  "aria-label": unref(messages).diffOriginal,
714
1163
  foldable: false,
715
1164
  "active-line": false,
1165
+ bordered: false,
716
1166
  readonly: "",
717
1167
  onTransaction: _cache[0] || (_cache[0] = ($event) => revealAt("a", $event))
718
1168
  }, null, 8, [
@@ -721,10 +1171,11 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
721
1171
  "tab-size",
722
1172
  "messages",
723
1173
  "aria-label"
724
- ])], 2),
1174
+ ])], 34),
725
1175
  createElementVNode("div", {
726
1176
  ref_key: "sideB",
727
1177
  ref: sideB,
1178
+ onScrollCapturePassive: onSideScroll,
728
1179
  class: normalizeClass([unref(ns).e("side"), "is-modified"])
729
1180
  }, [createVNode(code_editor_default, {
730
1181
  ref_key: "editorB",
@@ -738,6 +1189,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
738
1189
  "aria-label": unref(messages).diffModified,
739
1190
  foldable: false,
740
1191
  "active-line": false,
1192
+ bordered: false,
741
1193
  readonly: !__props.editable,
742
1194
  "onUpdate:modelValue": onModifiedInput,
743
1195
  onTransaction: _cache[1] || (_cache[1] = ($event) => revealAt("b", $event))
@@ -749,7 +1201,28 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
749
1201
  "messages",
750
1202
  "aria-label",
751
1203
  "readonly"
752
- ])], 2)
1204
+ ])], 34),
1205
+ spans.value.length ? (openBlock(), createElementBlock("div", {
1206
+ key: 0,
1207
+ ref_key: "spanLayer",
1208
+ ref: spanLayer,
1209
+ class: normalizeClass(unref(ns).e("spans")),
1210
+ style: normalizeStyle({
1211
+ top: `${spanBox.value.top}px`,
1212
+ height: `${spanBox.value.height}px`
1213
+ })
1214
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(spans.value, (widget) => {
1215
+ return openBlock(), createElementBlock("div", {
1216
+ key: widget.id,
1217
+ ref_for: true,
1218
+ ref: (el) => measure(el, widget.id),
1219
+ class: normalizeClass([unref(ns).e("span"), unref(ns).is("placed", widget.id in spanTops.value && !spansScrolling.value)]),
1220
+ style: normalizeStyle({ transform: `translateY(${spanTops.value[widget.id] ?? 0}px)` }),
1221
+ role: widget.label ? "group" : void 0,
1222
+ "aria-label": widget.label,
1223
+ onWheel: onSpanWheel
1224
+ }, [createVNode(unref(render_part_default), { render: widget.render }, null, 8, ["render"])], 46, _hoisted_2);
1225
+ }), 128))], 6)) : createCommentVNode("", true)
753
1226
  ], 34)) : (openBlock(), createElementBlock("div", {
754
1227
  key: 2,
755
1228
  ref_key: "inlineBox",
@@ -768,6 +1241,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
768
1241
  "line-numbers": false,
769
1242
  foldable: false,
770
1243
  "active-line": false,
1244
+ bordered: false,
771
1245
  wrap: __props.wrap,
772
1246
  readonly: "",
773
1247
  onTransaction: _cache[2] || (_cache[2] = ($event) => revealAt("inline", $event))