svelte-highlight 7.23.2 → 7.25.0
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/AnsiOutput.svelte +33 -6
- package/AnsiOutput.svelte.d.ts +8 -0
- package/CodeToolbar.svelte +144 -0
- package/CodeToolbar.svelte.d.ts +125 -0
- package/CodeWindow.svelte +19 -0
- package/CodeWindow.svelte.d.ts +10 -0
- package/CopyButton.svelte +107 -3
- package/CopyButton.svelte.d.ts +17 -1
- package/DiffFileList.svelte +523 -0
- package/DiffFileList.svelte.d.ts +94 -0
- package/DiffFileListItem.svelte +44 -0
- package/DiffMinimap.svelte +99 -0
- package/DiffMinimap.svelte.d.ts +17 -0
- package/DiffStats.svelte +43 -0
- package/DiffStats.svelte.d.ts +17 -0
- package/DiffView.svelte +1213 -0
- package/DiffView.svelte.d.ts +76 -0
- package/FileTabs.svelte +2 -5
- package/Highlight.svelte +158 -2
- package/Highlight.svelte.d.ts +50 -2
- package/HighlightAuto.svelte.d.ts +3 -2
- package/HighlightAutoLazy.svelte +112 -0
- package/HighlightAutoLazy.svelte.d.ts +66 -0
- package/HighlightDiff.svelte +162 -0
- package/HighlightDiff.svelte.d.ts +102 -0
- package/HighlightEditable.svelte +65 -756
- package/HighlightEditable.svelte.d.ts +15 -5
- package/HighlightStream.svelte +117 -218
- package/HighlightStream.svelte.d.ts +8 -0
- package/HighlightSvelte.svelte.d.ts +3 -2
- package/HighlightVirtual.svelte +41 -8
- package/HighlightVirtual.svelte.d.ts +8 -0
- package/LangTag.svelte +33 -4
- package/LangTag.svelte.d.ts +6 -2
- package/LineNumbers.svelte +25 -4
- package/LineNumbers.svelte.d.ts +8 -0
- package/MarkdownStream.svelte +1 -0
- package/README.md +735 -18
- package/ToolbarButton.svelte +90 -0
- package/ToolbarButton.svelte.d.ts +106 -0
- package/Typewriter.svelte +59 -10
- package/Typewriter.svelte.d.ts +7 -0
- package/WrapToggle.svelte +34 -0
- package/WrapToggle.svelte.d.ts +39 -0
- package/action.js +7 -3
- package/ansi.d.ts +1 -3
- package/auto-detect.d.ts +52 -0
- package/auto-detect.js +208 -0
- package/code-region.d.ts +7 -0
- package/code-region.js +20 -0
- package/css-highlights.js +115 -0
- package/css-walk.js +50 -0
- package/diff-controller.d.ts +120 -0
- package/diff-controller.js +721 -0
- package/diff-edits.d.ts +101 -0
- package/diff-edits.js +890 -0
- package/diff-html.d.ts +8 -0
- package/diff-html.js +60 -0
- package/diff-languages.d.ts +4 -0
- package/diff-languages.js +73 -0
- package/diff.d.ts +161 -0
- package/diff.js +1111 -0
- package/editable-commands.js +81 -0
- package/editable-css-paint.js +5 -3
- package/editable-dom-paint.js +1 -1
- package/editable-history.js +199 -0
- package/editable-line-dom.js +176 -1
- package/editable-painter.js +356 -0
- package/editable.d.ts +118 -0
- package/editable.js +513 -0
- package/engine.d.ts +1 -1
- package/fence.js +1 -1
- package/highlight-cascade.js +679 -0
- package/highlight-theme.js +6 -47
- package/incremental-tokenize.js +1 -1
- package/index.d.ts +39 -6
- package/index.js +30 -0
- package/languages/abap.d.ts +2 -0
- package/languages/abap.js +2 -0
- package/languages/aliases.js +1 -1
- package/languages/all.js +18 -1
- package/languages/angular.js +1 -1
- package/languages/antlr.d.ts +2 -0
- package/languages/antlr.js +2 -0
- package/languages/apex.d.ts +2 -0
- package/languages/apex.js +2 -0
- package/languages/bash.js +1 -1
- package/languages/cobol.d.ts +2 -0
- package/languages/cobol.js +2 -0
- package/languages/coq.js +1 -1
- package/languages/cpp.js +1 -1
- package/languages/csharp.js +1 -1
- package/languages/css.js +1 -1
- package/languages/cython.d.ts +2 -0
- package/languages/cython.js +2 -0
- package/languages/dart.js +1 -1
- package/languages/detect-index.d.ts +16 -0
- package/languages/detect-index.js +6 -0
- package/languages/fluent.d.ts +2 -0
- package/languages/fluent.js +2 -0
- package/languages/freemarker.d.ts +2 -0
- package/languages/freemarker.js +3 -0
- package/languages/handlebars.js +1 -1
- package/languages/httpfile.d.ts +2 -0
- package/languages/httpfile.js +3 -0
- package/languages/index.d.ts +34 -0
- package/languages/index.js +17 -0
- package/languages/jinja.js +1 -1
- package/languages/json.js +1 -1
- package/languages/kotlin.js +1 -1
- package/languages/lex.d.ts +2 -0
- package/languages/lex.js +3 -0
- package/languages/lisp.js +1 -1
- package/languages/loaders.d.ts +8 -0
- package/languages/loaders.js +387 -0
- package/languages/mathematica.js +1 -1
- package/languages/meson.d.ts +2 -0
- package/languages/meson.js +2 -0
- package/languages/metal.d.ts +2 -0
- package/languages/metal.js +2 -0
- package/languages/mlir.d.ts +2 -0
- package/languages/mlir.js +2 -0
- package/languages/mojo.js +1 -1
- package/languages/nextflow.js +1 -1
- package/languages/objectivec.js +1 -1
- package/languages/pgsql.js +1 -1
- package/languages/php.js +1 -1
- package/languages/po.d.ts +2 -0
- package/languages/po.js +2 -0
- package/languages/riscv.d.ts +2 -0
- package/languages/riscv.js +2 -0
- package/languages/robotframework.d.ts +2 -0
- package/languages/robotframework.js +2 -0
- package/languages/roc.js +1 -1
- package/languages/solidity.js +1 -1
- package/languages/sshconfig.d.ts +2 -0
- package/languages/sshconfig.js +2 -0
- package/languages/svelte.js +1 -1
- package/languages/uiua.js +1 -1
- package/languages/verilog.js +1 -1
- package/languages/vim.js +1 -1
- package/languages/yacc.d.ts +2 -0
- package/languages/yacc.js +3 -0
- package/languages/zig.js +1 -1
- package/package.json +50 -2
- package/preprocessor.js +20 -5
- package/search.js +2 -2
- package/stream-highlighter.js +198 -0
- package/stream.css +16 -0
- package/stream.d.ts +60 -0
- package/stream.js +283 -0
- package/style-registry.js +34 -3
- package/themes/_base-css.d.ts +1 -0
- package/themes/_base-css.js +1 -0
- package/typewriter-units.d.ts +3 -0
- package/typewriter-units.js +43 -0
- package/virtual-window.js +9 -4
package/DiffView.svelte
ADDED
|
@@ -0,0 +1,1213 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A controller from `createDiffController`.
|
|
4
|
+
* @type {import("./diff-controller.js").DiffController}
|
|
5
|
+
*/
|
|
6
|
+
export let diff;
|
|
7
|
+
|
|
8
|
+
/** While streaming, keep the newest row in view. */
|
|
9
|
+
export let follow = true;
|
|
10
|
+
|
|
11
|
+
/** Show accept/reject controls per change (or fill the `actions` slot). */
|
|
12
|
+
export let review = false;
|
|
13
|
+
|
|
14
|
+
/** Wrap long lines instead of scrolling sideways. */
|
|
15
|
+
export let wrap = false;
|
|
16
|
+
|
|
17
|
+
/** @type {"default" | "colorblind"} */
|
|
18
|
+
export let palette = "default";
|
|
19
|
+
|
|
20
|
+
/** Extra rows rendered above and below the viewport. */
|
|
21
|
+
export let overscan = 10;
|
|
22
|
+
|
|
23
|
+
/** Handle n/p/e/c/v (and a/r/u with `review`) when focused. */
|
|
24
|
+
export let keyboard = true;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Render only the rows in view. `"auto"` virtualizes past 500 rows, so
|
|
28
|
+
* small diffs keep browser find, printing, and server rendering.
|
|
29
|
+
* @type {"auto" | boolean}
|
|
30
|
+
*/
|
|
31
|
+
export let virtualize = "auto";
|
|
32
|
+
|
|
33
|
+
import { afterUpdate, onMount, tick } from "svelte";
|
|
34
|
+
import { watchLineHeight } from "./virtual-window.js";
|
|
35
|
+
|
|
36
|
+
$: ({ class: _class, style: _style, ...rest } = $$restProps);
|
|
37
|
+
|
|
38
|
+
/** @type {HTMLElement} */
|
|
39
|
+
let container;
|
|
40
|
+
/** @type {HTMLElement} */
|
|
41
|
+
let windowEl;
|
|
42
|
+
/** @type {HTMLElement} */
|
|
43
|
+
let probe;
|
|
44
|
+
/** @type {HTMLElement} */
|
|
45
|
+
let charProbe;
|
|
46
|
+
/** @type {HTMLElement | undefined} */
|
|
47
|
+
let hbarOld;
|
|
48
|
+
/** @type {HTMLElement | undefined} */
|
|
49
|
+
let hbarNew;
|
|
50
|
+
|
|
51
|
+
let lineHeight = 18;
|
|
52
|
+
let charWidth = 8;
|
|
53
|
+
let codeWidth = 0;
|
|
54
|
+
let scrollTop = 0;
|
|
55
|
+
let clientHeight = 600;
|
|
56
|
+
let clientWidth = 0;
|
|
57
|
+
let scrollOld = 0;
|
|
58
|
+
let scrollNew = 0;
|
|
59
|
+
let hydrated = false;
|
|
60
|
+
let userScrolled = false;
|
|
61
|
+
|
|
62
|
+
/** @type {"old" | "new" | null} */
|
|
63
|
+
let selectSide = null;
|
|
64
|
+
|
|
65
|
+
$: options = $diff.options();
|
|
66
|
+
$: view = options.view;
|
|
67
|
+
$: state = $diff.state();
|
|
68
|
+
$: rows = $diff.rows();
|
|
69
|
+
$: columns = $diff.columns();
|
|
70
|
+
$: decisions = $diff.decisions();
|
|
71
|
+
$: current = $diff.current();
|
|
72
|
+
|
|
73
|
+
// --- row heights ---
|
|
74
|
+
//
|
|
75
|
+
// Rows are estimated, then measured once rendered. Measured heights are
|
|
76
|
+
// cached by row key until something that changes them does: wrapping,
|
|
77
|
+
// the view, the width, notes, or a new (not just grown) document.
|
|
78
|
+
|
|
79
|
+
/** @type {Map<string, number>} */
|
|
80
|
+
let measured = new Map();
|
|
81
|
+
let layoutVersion = 0;
|
|
82
|
+
|
|
83
|
+
function resetHeights() {
|
|
84
|
+
measured = new Map();
|
|
85
|
+
layoutVersion++;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @type {unknown[]} */
|
|
89
|
+
let heightDeps = [];
|
|
90
|
+
$: {
|
|
91
|
+
const next = [
|
|
92
|
+
wrap,
|
|
93
|
+
view,
|
|
94
|
+
options.annotations,
|
|
95
|
+
lineHeight,
|
|
96
|
+
state.streaming ? null : state,
|
|
97
|
+
];
|
|
98
|
+
if (wrap) next.push(clientWidth);
|
|
99
|
+
if (next.some((v, i) => v !== heightDeps[i])) {
|
|
100
|
+
heightDeps = next;
|
|
101
|
+
resetHeights();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @param {import("./diff-controller.js").ViewRow} row */
|
|
106
|
+
function textLength(row) {
|
|
107
|
+
const oldLen =
|
|
108
|
+
row.old === undefined ? 0 : (state.beforeLines[row.old]?.length ?? 0);
|
|
109
|
+
const newLen =
|
|
110
|
+
row.new === undefined
|
|
111
|
+
? 0
|
|
112
|
+
: row.kind === "incoming"
|
|
113
|
+
? (state.partial?.length ?? 0)
|
|
114
|
+
: (state.afterLines[row.new]?.length ?? 0);
|
|
115
|
+
if (view === "split") return Math.max(oldLen, newLen);
|
|
116
|
+
return row.kind === "del" ? oldLen : newLen;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @param {import("./diff-controller.js").ViewRow} row */
|
|
120
|
+
function estimate(row) {
|
|
121
|
+
if (row.note)
|
|
122
|
+
return (row.note.body.split("\n").length + 1) * lineHeight + 6;
|
|
123
|
+
if (!wrap || row.kind === "fold" || row.kind === "pending")
|
|
124
|
+
return lineHeight;
|
|
125
|
+
const perLine = Math.max(1, Math.floor((codeWidth || 600) / charWidth));
|
|
126
|
+
return lineHeight * Math.max(1, Math.ceil(textLength(row) / perLine));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
$: offsets = (() => {
|
|
130
|
+
void layoutVersion;
|
|
131
|
+
const out = new Float64Array(rows.length + 1);
|
|
132
|
+
for (let i = 0; i < rows.length; i++) {
|
|
133
|
+
const row = /** @type {import("./diff-controller.js").ViewRow} */ (
|
|
134
|
+
rows[i]
|
|
135
|
+
);
|
|
136
|
+
out[i + 1] =
|
|
137
|
+
/** @type {number} */ (out[i]) +
|
|
138
|
+
(measured.get(row.key) ?? estimate(row));
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
})();
|
|
142
|
+
$: total = /** @type {number} */ (offsets[rows.length] ?? 0);
|
|
143
|
+
|
|
144
|
+
/** Last row whose top is at or above `px`. */
|
|
145
|
+
function indexAt(
|
|
146
|
+
/** @type {number} */ px,
|
|
147
|
+
/** @type {Float64Array} */ table = offsets,
|
|
148
|
+
) {
|
|
149
|
+
let lo = 0;
|
|
150
|
+
let hi = rows.length - 1;
|
|
151
|
+
let found = 0;
|
|
152
|
+
while (lo <= hi) {
|
|
153
|
+
const mid = (lo + hi) >> 1;
|
|
154
|
+
if (/** @type {number} */ (table[mid]) <= px) {
|
|
155
|
+
found = mid;
|
|
156
|
+
lo = mid + 1;
|
|
157
|
+
} else {
|
|
158
|
+
hi = mid - 1;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return found;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
$: virtualized = virtualize === "auto" ? rows.length > 500 : virtualize;
|
|
165
|
+
$: start = virtualized
|
|
166
|
+
? Math.max(0, indexAt(scrollTop, offsets) - overscan)
|
|
167
|
+
: 0;
|
|
168
|
+
$: end = virtualized
|
|
169
|
+
? Math.min(
|
|
170
|
+
rows.length,
|
|
171
|
+
indexAt(scrollTop + clientHeight, offsets) + 1 + overscan,
|
|
172
|
+
)
|
|
173
|
+
: rows.length;
|
|
174
|
+
$: visible = $diff.renderRows(start, end);
|
|
175
|
+
$: windowTop = /** @type {number} */ (offsets[start] ?? 0);
|
|
176
|
+
|
|
177
|
+
$: if (hydrated) {
|
|
178
|
+
void offsets;
|
|
179
|
+
diff.setViewport(indexAt(scrollTop), indexAt(scrollTop + clientHeight) + 1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Measure rendered rows. Growth above the first visible row shifts
|
|
183
|
+
// scrollTop by the same amount, so the content under the reader stays put.
|
|
184
|
+
afterUpdate(() => {
|
|
185
|
+
if (!windowEl || !container) return;
|
|
186
|
+
const anchor = indexAt(container.scrollTop);
|
|
187
|
+
let changed = false;
|
|
188
|
+
let shift = 0;
|
|
189
|
+
for (const el of /** @type {HTMLElement[]} */ ([...windowEl.children])) {
|
|
190
|
+
const key = el.dataset.key;
|
|
191
|
+
const index = Number(el.dataset.index);
|
|
192
|
+
if (key === undefined || Number.isNaN(index)) continue;
|
|
193
|
+
const height = el.getBoundingClientRect().height;
|
|
194
|
+
const used =
|
|
195
|
+
/** @type {number} */ (offsets[index + 1]) -
|
|
196
|
+
/** @type {number} */ (offsets[index]);
|
|
197
|
+
if (Math.abs(height - used) > 0.5) {
|
|
198
|
+
measured.set(key, height);
|
|
199
|
+
changed = true;
|
|
200
|
+
if (index < anchor) shift += height - used;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const cell = /** @type {HTMLElement | null} */ (
|
|
204
|
+
windowEl.querySelector(".shl-diff-code")
|
|
205
|
+
);
|
|
206
|
+
if (cell && cell.clientWidth > 0) codeWidth = cell.clientWidth;
|
|
207
|
+
if (!changed) return;
|
|
208
|
+
layoutVersion++;
|
|
209
|
+
if (shift !== 0) setScrollTop(container.scrollTop + shift);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
/** @param {number} row @param {"start" | "center" | "third"} align */
|
|
213
|
+
function scrollToRow(row, align) {
|
|
214
|
+
if (!container) return;
|
|
215
|
+
const top = /** @type {number} */ (
|
|
216
|
+
offsets[Math.max(0, Math.min(row, rows.length))] ?? 0
|
|
217
|
+
);
|
|
218
|
+
const offset =
|
|
219
|
+
align === "center"
|
|
220
|
+
? container.clientHeight / 2
|
|
221
|
+
: align === "third"
|
|
222
|
+
? container.clientHeight / 3
|
|
223
|
+
: 0;
|
|
224
|
+
setScrollTop(Math.max(0, top - offset));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Where DiffView last put the scroll position. A scroll that lands
|
|
228
|
+
// anywhere else came from the reader: a scrollbar drag, a key, a swipe.
|
|
229
|
+
let ownScrollTop = -1;
|
|
230
|
+
/** @param {number} value */
|
|
231
|
+
function setScrollTop(value) {
|
|
232
|
+
container.scrollTop = value;
|
|
233
|
+
scrollTop = ownScrollTop = container.scrollTop;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** @type {number | undefined} */
|
|
237
|
+
let frame;
|
|
238
|
+
function onScroll() {
|
|
239
|
+
if (
|
|
240
|
+
state.streaming &&
|
|
241
|
+
container &&
|
|
242
|
+
Math.abs(container.scrollTop - ownScrollTop) > 1
|
|
243
|
+
) {
|
|
244
|
+
// If the content shrank under our position, the browser clamped it.
|
|
245
|
+
const max = container.scrollHeight - container.clientHeight;
|
|
246
|
+
if (ownScrollTop > max + 1) ownScrollTop = container.scrollTop;
|
|
247
|
+
else userScrolled = true;
|
|
248
|
+
}
|
|
249
|
+
if (frame !== undefined) return;
|
|
250
|
+
frame = requestAnimationFrame(() => {
|
|
251
|
+
frame = undefined;
|
|
252
|
+
if (container) scrollTop = container.scrollTop;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** @param {WheelEvent} event */
|
|
257
|
+
function onWheel(event) {
|
|
258
|
+
const dx =
|
|
259
|
+
event.shiftKey && event.deltaX === 0 ? event.deltaY : event.deltaX;
|
|
260
|
+
if (
|
|
261
|
+
dx === 0 ||
|
|
262
|
+
(Math.abs(dx) < Math.abs(event.deltaY) && !event.shiftKey)
|
|
263
|
+
) {
|
|
264
|
+
userScrolled = true;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (wrap) return;
|
|
268
|
+
const side = /** @type {HTMLElement} */ (event.target)
|
|
269
|
+
.closest?.("[data-side]")
|
|
270
|
+
?.getAttribute("data-side");
|
|
271
|
+
const bar = view === "split" && side === "old" ? hbarOld : hbarNew;
|
|
272
|
+
if (!bar) return;
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
bar.scrollLeft += dx;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** @param {KeyboardEvent} event */
|
|
278
|
+
function onKeydown(event) {
|
|
279
|
+
if (!keyboard || event.metaKey || event.ctrlKey || event.altKey) return;
|
|
280
|
+
if (
|
|
281
|
+
/** @type {HTMLElement} */ (event.target).closest(
|
|
282
|
+
"button, input, textarea",
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
return;
|
|
286
|
+
const key = event.key;
|
|
287
|
+
if (key === "n" || key === "]" || key === "j") diff.nextChange();
|
|
288
|
+
else if (key === "p" || key === "[" || key === "k") diff.prevChange();
|
|
289
|
+
else if (key === "e") diff.expandAll();
|
|
290
|
+
else if (key === "c") diff.collapseAll();
|
|
291
|
+
else if (key === "v")
|
|
292
|
+
diff.setOptions({ view: view === "split" ? "unified" : "split" });
|
|
293
|
+
else if (review && current >= 0 && key === "a")
|
|
294
|
+
diff.decide(current, "accepted");
|
|
295
|
+
else if (review && current >= 0 && key === "r")
|
|
296
|
+
diff.decide(current, "rejected");
|
|
297
|
+
else if (review && current >= 0 && key === "u")
|
|
298
|
+
diff.decide(current, undefined);
|
|
299
|
+
else return;
|
|
300
|
+
event.preventDefault();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** @param {MouseEvent} event */
|
|
304
|
+
function onMousedown(event) {
|
|
305
|
+
const side = /** @type {HTMLElement} */ (event.target)
|
|
306
|
+
.closest?.("[data-side]")
|
|
307
|
+
?.getAttribute("data-side");
|
|
308
|
+
selectSide =
|
|
309
|
+
view === "split" && (side === "old" || side === "new") ? side : null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// --- copy ---
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Copies one file's text: in split view, the side the selection started
|
|
316
|
+
* on; in unified view, the new text, or the old text if only removed lines
|
|
317
|
+
* are selected. Fully selected lines come from the source, so tabs and
|
|
318
|
+
* carriage returns survive.
|
|
319
|
+
* @param {ClipboardEvent} event
|
|
320
|
+
*/
|
|
321
|
+
function onCopy(event) {
|
|
322
|
+
const selection = window.getSelection();
|
|
323
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed)
|
|
324
|
+
return;
|
|
325
|
+
const range = selection.getRangeAt(0);
|
|
326
|
+
/** @type {Array<{ row: import("./diff-controller.js").ViewRow, el: HTMLElement }>} */
|
|
327
|
+
const picked = [];
|
|
328
|
+
for (const el of /** @type {HTMLElement[]} */ ([...windowEl.children])) {
|
|
329
|
+
const item = visible[Number(el.dataset.index) - start];
|
|
330
|
+
if (!item || !range.intersectsNode(el)) continue;
|
|
331
|
+
const kind = item.row.kind;
|
|
332
|
+
if (kind === "fold" || kind === "pending" || item.row.note) continue;
|
|
333
|
+
picked.push({ row: item.row, el });
|
|
334
|
+
}
|
|
335
|
+
if (picked.length < 2) return;
|
|
336
|
+
|
|
337
|
+
/** @type {"old" | "new"} */
|
|
338
|
+
let side = "new";
|
|
339
|
+
if (view === "split") side = selectSide ?? "new";
|
|
340
|
+
else if (picked.every(({ row }) => row.kind === "del")) side = "old";
|
|
341
|
+
|
|
342
|
+
/** @type {string[]} */
|
|
343
|
+
const lines = [];
|
|
344
|
+
for (const { row, el } of picked) {
|
|
345
|
+
if (
|
|
346
|
+
view === "unified" &&
|
|
347
|
+
(side === "new" ? row.kind === "del" : row.kind !== "del")
|
|
348
|
+
)
|
|
349
|
+
continue;
|
|
350
|
+
const index = side === "old" ? row.old : row.new;
|
|
351
|
+
if (index === undefined) continue;
|
|
352
|
+
const cell = el.querySelector(
|
|
353
|
+
view === "split"
|
|
354
|
+
? `.shl-diff-code[data-side="${side}"] .shl-diff-text`
|
|
355
|
+
: ".shl-diff-code .shl-diff-text",
|
|
356
|
+
);
|
|
357
|
+
if (!cell) continue;
|
|
358
|
+
const whole = document.createRange();
|
|
359
|
+
whole.selectNodeContents(cell);
|
|
360
|
+
const startsInside =
|
|
361
|
+
range.compareBoundaryPoints(Range.START_TO_START, whole) > 0;
|
|
362
|
+
const endsInside =
|
|
363
|
+
range.compareBoundaryPoints(Range.END_TO_END, whole) < 0;
|
|
364
|
+
if (!startsInside && !endsInside) {
|
|
365
|
+
const source =
|
|
366
|
+
side === "old"
|
|
367
|
+
? state.beforeLines[index]
|
|
368
|
+
: row.kind === "incoming"
|
|
369
|
+
? state.partial
|
|
370
|
+
: state.afterLines[index];
|
|
371
|
+
lines.push(source ?? "");
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const part = whole.cloneRange();
|
|
375
|
+
if (startsInside) part.setStart(range.startContainer, range.startOffset);
|
|
376
|
+
if (endsInside) part.setEnd(range.endContainer, range.endOffset);
|
|
377
|
+
lines.push(part.toString().replace(/\u200b/g, ""));
|
|
378
|
+
}
|
|
379
|
+
if (lines.length === 0 || !event.clipboardData) return;
|
|
380
|
+
event.clipboardData.setData("text/plain", lines.join("\n"));
|
|
381
|
+
event.preventDefault();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Follow the streaming frontier unless the reader scrolled away.
|
|
385
|
+
let followQueued = false;
|
|
386
|
+
function followFrontier() {
|
|
387
|
+
if (
|
|
388
|
+
followQueued ||
|
|
389
|
+
!hydrated ||
|
|
390
|
+
!state.streaming ||
|
|
391
|
+
!follow ||
|
|
392
|
+
userScrolled
|
|
393
|
+
)
|
|
394
|
+
return;
|
|
395
|
+
followQueued = true;
|
|
396
|
+
requestAnimationFrame(() => {
|
|
397
|
+
followQueued = false;
|
|
398
|
+
if (!container || userScrolled) return;
|
|
399
|
+
const frontier = rows.findIndex(
|
|
400
|
+
(r) => r.kind === "incoming" || r.kind === "pending",
|
|
401
|
+
);
|
|
402
|
+
const index = frontier === -1 ? rows.length - 1 : frontier;
|
|
403
|
+
const top = /** @type {number} */ (offsets[index] ?? 0);
|
|
404
|
+
const max = Math.max(0, total - container.clientHeight);
|
|
405
|
+
const target = Math.min(
|
|
406
|
+
max,
|
|
407
|
+
Math.max(0, top - container.clientHeight * 0.6),
|
|
408
|
+
);
|
|
409
|
+
if (Math.abs(container.scrollTop - target) > lineHeight)
|
|
410
|
+
setScrollTop(target);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
$: if (rows) followFrontier();
|
|
414
|
+
$: if (!state.streaming) userScrolled = false;
|
|
415
|
+
|
|
416
|
+
/** @param {import("./diff-controller.js").ViewRow} row */
|
|
417
|
+
function rowLabel(row) {
|
|
418
|
+
if (row.kind === "del") return `Removed line ${(row.old ?? 0) + 1}`;
|
|
419
|
+
if (row.kind === "add") return `Added line ${(row.new ?? 0) + 1}`;
|
|
420
|
+
if (row.kind === "change") {
|
|
421
|
+
const parts = [];
|
|
422
|
+
if (row.old !== undefined) parts.push(`removed line ${row.old + 1}`);
|
|
423
|
+
if (row.new !== undefined) parts.push(`added line ${row.new + 1}`);
|
|
424
|
+
return parts.join(", ");
|
|
425
|
+
}
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** @param {import("./diff-controller.js").ViewRow} row */
|
|
430
|
+
function moveTitle(row) {
|
|
431
|
+
if (row.movedTo !== undefined) return `Moved to line ${row.movedTo + 1}`;
|
|
432
|
+
if (row.movedFrom !== undefined)
|
|
433
|
+
return `Moved from line ${row.movedFrom + 1}`;
|
|
434
|
+
return undefined;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Without `wrap`, code rows are exactly one line tall.
|
|
439
|
+
* @param {import("./diff-controller.js").ViewRow} row
|
|
440
|
+
* @param {boolean} wrapped
|
|
441
|
+
* @param {number} height
|
|
442
|
+
*/
|
|
443
|
+
function rowStyle(row, wrapped, height) {
|
|
444
|
+
return wrapped || row.note
|
|
445
|
+
? `min-height: ${height}px;`
|
|
446
|
+
: `height: ${height}px;`;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
onMount(() => {
|
|
450
|
+
watchLineHeight(
|
|
451
|
+
() => probe,
|
|
452
|
+
() => lineHeight,
|
|
453
|
+
(height) => (lineHeight = height),
|
|
454
|
+
);
|
|
455
|
+
tick().then(() => {
|
|
456
|
+
if (charProbe)
|
|
457
|
+
charWidth = charProbe.getBoundingClientRect().width / 10 || charWidth;
|
|
458
|
+
});
|
|
459
|
+
hydrated = true;
|
|
460
|
+
clientHeight = container.clientHeight;
|
|
461
|
+
clientWidth = container.clientWidth;
|
|
462
|
+
const observer = new ResizeObserver(() => {
|
|
463
|
+
if (!container) return;
|
|
464
|
+
clientHeight = container.clientHeight;
|
|
465
|
+
clientWidth = container.clientWidth;
|
|
466
|
+
});
|
|
467
|
+
observer.observe(container);
|
|
468
|
+
const offReveal = diff.on("reveal", ({ row, align }) =>
|
|
469
|
+
scrollToRow(row, align),
|
|
470
|
+
);
|
|
471
|
+
return () => {
|
|
472
|
+
observer.disconnect();
|
|
473
|
+
offReveal();
|
|
474
|
+
if (frame !== undefined) cancelAnimationFrame(frame);
|
|
475
|
+
};
|
|
476
|
+
});
|
|
477
|
+
</script>
|
|
478
|
+
|
|
479
|
+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
480
|
+
<section
|
|
481
|
+
class="shl-diff shl-diff-theme {_class ?? ''}"
|
|
482
|
+
class:shl-diff-split={view === "split"}
|
|
483
|
+
class:shl-diff-colorblind={palette === "colorblind"}
|
|
484
|
+
class:shl-diff-streaming={state.streaming}
|
|
485
|
+
class:shl-diff-wrap={wrap}
|
|
486
|
+
data-select={selectSide}
|
|
487
|
+
aria-label="Diff: {$diff.stats().additions} additions, {$diff.stats()
|
|
488
|
+
.deletions} deletions"
|
|
489
|
+
tabindex="0"
|
|
490
|
+
{...rest}
|
|
491
|
+
style="--shl-diff-gutter: {columns.gutter}ch; --shl-diff-line: {lineHeight}px; tab-size: {options.tabSize}; {_style ??
|
|
492
|
+
''}"
|
|
493
|
+
on:keydown={onKeydown}
|
|
494
|
+
on:mousedown={onMousedown}
|
|
495
|
+
on:copy={onCopy}
|
|
496
|
+
>
|
|
497
|
+
<div class="shl-diff-frame hljs">
|
|
498
|
+
<div
|
|
499
|
+
class="shl-diff-body"
|
|
500
|
+
bind:this={container}
|
|
501
|
+
on:scroll={onScroll}
|
|
502
|
+
on:wheel={onWheel}
|
|
503
|
+
role="table"
|
|
504
|
+
aria-rowcount={rows.length}
|
|
505
|
+
>
|
|
506
|
+
<div
|
|
507
|
+
class="shl-diff-sizer"
|
|
508
|
+
style={virtualized ? `height: ${total}px;` : undefined}
|
|
509
|
+
>
|
|
510
|
+
<div
|
|
511
|
+
bind:this={windowEl}
|
|
512
|
+
class="shl-diff-window"
|
|
513
|
+
class:shl-diff-window-flat={!virtualized}
|
|
514
|
+
style={virtualized
|
|
515
|
+
? `transform: translateY(${windowTop}px);`
|
|
516
|
+
: undefined}
|
|
517
|
+
>
|
|
518
|
+
{#each visible as item (item.row.key)}
|
|
519
|
+
{@const row = item.row}
|
|
520
|
+
{@const decision =
|
|
521
|
+
row.change === undefined ? undefined : decisions.get(row.change)}
|
|
522
|
+
<div
|
|
523
|
+
class="shl-diff-row shl-diff-{row.kind}"
|
|
524
|
+
class:shl-diff-moved={row.moved !== undefined}
|
|
525
|
+
class:shl-diff-current={row.change !== undefined &&
|
|
526
|
+
row.change === current}
|
|
527
|
+
class:shl-diff-accepted={decision === "accepted"}
|
|
528
|
+
class:shl-diff-rejected={decision === "rejected"}
|
|
529
|
+
class:shl-diff-unpaired-old={row.kind === "change" &&
|
|
530
|
+
row.old === undefined}
|
|
531
|
+
class:shl-diff-unpaired-new={row.kind === "change" &&
|
|
532
|
+
row.new === undefined}
|
|
533
|
+
style={rowStyle(row, wrap, lineHeight)}
|
|
534
|
+
data-key={row.key}
|
|
535
|
+
data-index={item.index}
|
|
536
|
+
role="row"
|
|
537
|
+
aria-rowindex={item.index + 1}
|
|
538
|
+
aria-label={rowLabel(row)}
|
|
539
|
+
title={moveTitle(row)}
|
|
540
|
+
>
|
|
541
|
+
{#if row.kind === "fold" && row.fold}
|
|
542
|
+
<span class="shl-diff-fold-cell" role="cell">
|
|
543
|
+
<slot
|
|
544
|
+
name="fold"
|
|
545
|
+
fold={row.fold}
|
|
546
|
+
count={row.count}
|
|
547
|
+
toggle={() => diff.toggleFold(row.key)}
|
|
548
|
+
>
|
|
549
|
+
{#if row.fold.unknown}
|
|
550
|
+
<span class="shl-diff-fold-label">
|
|
551
|
+
<span class="shl-diff-fold-icon" aria-hidden="true"
|
|
552
|
+
>⋯</span
|
|
553
|
+
>
|
|
554
|
+
{`${row.count} lines not in patch`}
|
|
555
|
+
<span class="shl-diff-hunk">{row.fold.header}</span>
|
|
556
|
+
</span>
|
|
557
|
+
{:else}
|
|
558
|
+
<button
|
|
559
|
+
type="button"
|
|
560
|
+
class="shl-diff-fold-label"
|
|
561
|
+
on:click={() => diff.toggleFold(row.key)}
|
|
562
|
+
>
|
|
563
|
+
<span class="shl-diff-fold-icon" aria-hidden="true"
|
|
564
|
+
>↕</span
|
|
565
|
+
>
|
|
566
|
+
{`Expand ${row.count} unchanged ${row.count === 1 ? "line" : "lines"}`}
|
|
567
|
+
<span class="shl-diff-hunk">{row.fold.header}</span>
|
|
568
|
+
</button>
|
|
569
|
+
{/if}
|
|
570
|
+
</slot>
|
|
571
|
+
</span>
|
|
572
|
+
{:else if row.kind === "pending"}
|
|
573
|
+
<span class="shl-diff-fold-label" role="cell">
|
|
574
|
+
<span class="shl-diff-spinner" aria-hidden="true"></span>
|
|
575
|
+
{`${row.count} ${row.count === 1 ? "line" : "lines"} not reached yet`}
|
|
576
|
+
</span>
|
|
577
|
+
{:else if row.note}
|
|
578
|
+
<div class="shl-diff-note-slot" role="cell">
|
|
579
|
+
<slot name="note" note={row.note}>
|
|
580
|
+
<div
|
|
581
|
+
class="shl-diff-note-card shl-diff-note-{row.note.tone ??
|
|
582
|
+
'info'}"
|
|
583
|
+
>
|
|
584
|
+
{#if row.note.author}
|
|
585
|
+
<strong>{row.note.author}</strong>
|
|
586
|
+
{/if}
|
|
587
|
+
<span>{row.note.body}</span>
|
|
588
|
+
</div>
|
|
589
|
+
</slot>
|
|
590
|
+
</div>
|
|
591
|
+
{:else if view === "split"}
|
|
592
|
+
<span class="shl-diff-num" aria-hidden="true"
|
|
593
|
+
>{row.old === undefined ? "" : row.old + 1}</span
|
|
594
|
+
>
|
|
595
|
+
<span
|
|
596
|
+
class="shl-diff-marker shl-diff-side-old"
|
|
597
|
+
data-side="old"
|
|
598
|
+
role="cell"
|
|
599
|
+
>{row.kind === "change" && row.old !== undefined
|
|
600
|
+
? "-"
|
|
601
|
+
: ""}</span
|
|
602
|
+
>
|
|
603
|
+
<span
|
|
604
|
+
class="shl-diff-code shl-diff-side-old"
|
|
605
|
+
data-side="old"
|
|
606
|
+
role="cell"
|
|
607
|
+
><span
|
|
608
|
+
class="shl-diff-text"
|
|
609
|
+
style={wrap
|
|
610
|
+
? undefined
|
|
611
|
+
: `transform: translateX(${-scrollOld}px);`}
|
|
612
|
+
>{@html row.old === undefined
|
|
613
|
+
? ""
|
|
614
|
+
: item.oldHtml || ""}</span
|
|
615
|
+
></span
|
|
616
|
+
>
|
|
617
|
+
<span class="shl-diff-num shl-diff-num-new" aria-hidden="true"
|
|
618
|
+
>{row.new === undefined ? "" : row.new + 1}</span
|
|
619
|
+
>
|
|
620
|
+
<span
|
|
621
|
+
class="shl-diff-marker shl-diff-side-new"
|
|
622
|
+
data-side="new"
|
|
623
|
+
role="cell"
|
|
624
|
+
>{row.kind === "change" && row.new !== undefined
|
|
625
|
+
? "+"
|
|
626
|
+
: ""}</span
|
|
627
|
+
>
|
|
628
|
+
<span
|
|
629
|
+
class="shl-diff-code shl-diff-side-new"
|
|
630
|
+
data-side="new"
|
|
631
|
+
role="cell"
|
|
632
|
+
><span
|
|
633
|
+
class="shl-diff-text"
|
|
634
|
+
style={wrap
|
|
635
|
+
? undefined
|
|
636
|
+
: `transform: translateX(${-scrollNew}px);`}
|
|
637
|
+
>{@html row.new === undefined
|
|
638
|
+
? ""
|
|
639
|
+
: item.newHtml || ""}</span
|
|
640
|
+
>
|
|
641
|
+
{#if row.kind === "incoming"}
|
|
642
|
+
<span class="shl-diff-caret" aria-hidden="true"></span>
|
|
643
|
+
{/if}</span
|
|
644
|
+
>
|
|
645
|
+
{:else}
|
|
646
|
+
<span class="shl-diff-num" aria-hidden="true"
|
|
647
|
+
>{row.old === undefined ? "" : row.old + 1}</span
|
|
648
|
+
>
|
|
649
|
+
<span class="shl-diff-num" aria-hidden="true"
|
|
650
|
+
>{row.new === undefined ? "" : row.new + 1}</span
|
|
651
|
+
>
|
|
652
|
+
<span class="shl-diff-marker" role="cell"
|
|
653
|
+
>{row.kind === "del"
|
|
654
|
+
? "-"
|
|
655
|
+
: row.kind === "add" || row.kind === "incoming"
|
|
656
|
+
? "+"
|
|
657
|
+
: ""}</span
|
|
658
|
+
>
|
|
659
|
+
<span class="shl-diff-code" data-side="new" role="cell"
|
|
660
|
+
><span
|
|
661
|
+
class="shl-diff-text"
|
|
662
|
+
style={wrap
|
|
663
|
+
? undefined
|
|
664
|
+
: `transform: translateX(${-scrollNew}px);`}
|
|
665
|
+
>{@html (row.kind === "del"
|
|
666
|
+
? item.oldHtml
|
|
667
|
+
: item.newHtml) || ""}</span
|
|
668
|
+
>
|
|
669
|
+
{#if row.kind === "incoming"}
|
|
670
|
+
<span class="shl-diff-caret" aria-hidden="true"></span>
|
|
671
|
+
{/if}</span
|
|
672
|
+
>
|
|
673
|
+
{/if}
|
|
674
|
+
{#if row.first && row.change !== undefined && (review || $$slots.actions)}
|
|
675
|
+
{@const change = row.change}
|
|
676
|
+
<span class="shl-diff-actions" role="cell">
|
|
677
|
+
<slot
|
|
678
|
+
name="actions"
|
|
679
|
+
{change}
|
|
680
|
+
{decision}
|
|
681
|
+
decide={(
|
|
682
|
+
/** @type {"accepted" | "rejected" | undefined} */ d,
|
|
683
|
+
) => diff.decide(change, d)}
|
|
684
|
+
>
|
|
685
|
+
{#if decision}
|
|
686
|
+
<span class="shl-diff-decision">{decision}</span>
|
|
687
|
+
<button
|
|
688
|
+
type="button"
|
|
689
|
+
on:click={() => diff.decide(change, undefined)}
|
|
690
|
+
>
|
|
691
|
+
Undo
|
|
692
|
+
</button>
|
|
693
|
+
{:else}
|
|
694
|
+
<button
|
|
695
|
+
type="button"
|
|
696
|
+
class="shl-diff-accept"
|
|
697
|
+
on:click={() => diff.decide(change, "accepted")}
|
|
698
|
+
>
|
|
699
|
+
Accept
|
|
700
|
+
</button>
|
|
701
|
+
<button
|
|
702
|
+
type="button"
|
|
703
|
+
class="shl-diff-reject"
|
|
704
|
+
on:click={() => diff.decide(change, "rejected")}
|
|
705
|
+
>
|
|
706
|
+
Reject
|
|
707
|
+
</button>
|
|
708
|
+
{/if}
|
|
709
|
+
</slot>
|
|
710
|
+
</span>
|
|
711
|
+
{/if}
|
|
712
|
+
</div>
|
|
713
|
+
{/each}
|
|
714
|
+
</div>
|
|
715
|
+
</div>
|
|
716
|
+
</div>
|
|
717
|
+
{#if !wrap}
|
|
718
|
+
<div class="shl-diff-hbar-row" aria-hidden="true">
|
|
719
|
+
{#if view === "split"}
|
|
720
|
+
<span></span><span></span>
|
|
721
|
+
<div
|
|
722
|
+
class="shl-diff-hbar"
|
|
723
|
+
bind:this={hbarOld}
|
|
724
|
+
on:scroll={() => (scrollOld = hbarOld?.scrollLeft ?? 0)}
|
|
725
|
+
>
|
|
726
|
+
<div
|
|
727
|
+
style="width: {(columns.old + 2) * charWidth}px; height: 1px;"
|
|
728
|
+
></div>
|
|
729
|
+
</div>
|
|
730
|
+
<span></span><span></span>
|
|
731
|
+
<div
|
|
732
|
+
class="shl-diff-hbar"
|
|
733
|
+
bind:this={hbarNew}
|
|
734
|
+
on:scroll={() => (scrollNew = hbarNew?.scrollLeft ?? 0)}
|
|
735
|
+
>
|
|
736
|
+
<div
|
|
737
|
+
style="width: {(columns.new + 2) * charWidth}px; height: 1px;"
|
|
738
|
+
></div>
|
|
739
|
+
</div>
|
|
740
|
+
{:else}
|
|
741
|
+
<span></span><span></span><span></span>
|
|
742
|
+
<div
|
|
743
|
+
class="shl-diff-hbar"
|
|
744
|
+
bind:this={hbarNew}
|
|
745
|
+
on:scroll={() => (scrollNew = hbarNew?.scrollLeft ?? 0)}
|
|
746
|
+
>
|
|
747
|
+
<div
|
|
748
|
+
style="width: {(Math.max(columns.old, columns.new) + 2) *
|
|
749
|
+
charWidth}px; height: 1px;"
|
|
750
|
+
></div>
|
|
751
|
+
</div>
|
|
752
|
+
{/if}
|
|
753
|
+
</div>
|
|
754
|
+
{/if}
|
|
755
|
+
<span
|
|
756
|
+
class="shl-diff-probe shl-diff-row"
|
|
757
|
+
bind:this={probe}
|
|
758
|
+
aria-hidden="true"><span class="shl-diff-code"> </span></span
|
|
759
|
+
>
|
|
760
|
+
<span class="shl-diff-char-probe" bind:this={charProbe} aria-hidden="true"
|
|
761
|
+
>0000000000</span
|
|
762
|
+
>
|
|
763
|
+
</div>
|
|
764
|
+
</section>
|
|
765
|
+
|
|
766
|
+
<style>
|
|
767
|
+
:global(.shl-diff-theme) {
|
|
768
|
+
--shl-diff-add: rgba(46, 160, 67, 0.16);
|
|
769
|
+
--shl-diff-add-word: rgba(46, 160, 67, 0.45);
|
|
770
|
+
--shl-diff-add-accent: #3fb950;
|
|
771
|
+
--shl-diff-del: rgba(248, 81, 73, 0.16);
|
|
772
|
+
--shl-diff-del-word: rgba(248, 81, 73, 0.45);
|
|
773
|
+
--shl-diff-del-accent: #f85149;
|
|
774
|
+
--shl-diff-move: rgba(163, 113, 247, 0.18);
|
|
775
|
+
--shl-diff-move-accent: #a371f7;
|
|
776
|
+
--shl-diff-muted: color-mix(in srgb, currentColor 45%, transparent);
|
|
777
|
+
--shl-diff-rule: color-mix(in srgb, currentColor 12%, transparent);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
:global(.shl-diff-theme.shl-diff-colorblind) {
|
|
781
|
+
--shl-diff-add: rgba(56, 139, 253, 0.18);
|
|
782
|
+
--shl-diff-add-word: rgba(56, 139, 253, 0.5);
|
|
783
|
+
--shl-diff-add-accent: #58a6ff;
|
|
784
|
+
--shl-diff-del: rgba(219, 109, 40, 0.18);
|
|
785
|
+
--shl-diff-del-word: rgba(219, 109, 40, 0.5);
|
|
786
|
+
--shl-diff-del-accent: #db6d28;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
.shl-diff {
|
|
790
|
+
position: relative;
|
|
791
|
+
display: flex;
|
|
792
|
+
flex-direction: column;
|
|
793
|
+
height: 400px;
|
|
794
|
+
min-width: 0;
|
|
795
|
+
outline: none;
|
|
796
|
+
font-family: var(
|
|
797
|
+
--shl-diff-font,
|
|
798
|
+
ui-monospace,
|
|
799
|
+
SFMono-Regular,
|
|
800
|
+
Menlo,
|
|
801
|
+
Consolas,
|
|
802
|
+
monospace
|
|
803
|
+
);
|
|
804
|
+
font-size: var(--shl-diff-font-size, 13px);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
.shl-diff:focus-visible {
|
|
808
|
+
box-shadow: 0 0 0 2px var(--shl-diff-move-accent);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
.shl-diff-frame {
|
|
812
|
+
position: relative;
|
|
813
|
+
display: flex;
|
|
814
|
+
flex: 1;
|
|
815
|
+
flex-direction: column;
|
|
816
|
+
min-height: 0;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/* Beat a theme's `.hljs` padding without `!important`. */
|
|
820
|
+
.shl-diff .shl-diff-frame.hljs {
|
|
821
|
+
padding: 0;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
.shl-diff-body {
|
|
825
|
+
overflow-anchor: none;
|
|
826
|
+
position: relative;
|
|
827
|
+
flex: 1;
|
|
828
|
+
min-height: 0;
|
|
829
|
+
overflow-x: hidden;
|
|
830
|
+
overflow-y: auto;
|
|
831
|
+
scrollbar-gutter: stable;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
.shl-diff-sizer {
|
|
835
|
+
position: relative;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
.shl-diff-window {
|
|
839
|
+
position: absolute;
|
|
840
|
+
top: 0;
|
|
841
|
+
left: 0;
|
|
842
|
+
right: 0;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
.shl-diff-window-flat {
|
|
846
|
+
position: static;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
.shl-diff-row,
|
|
850
|
+
.shl-diff-hbar-row {
|
|
851
|
+
display: grid;
|
|
852
|
+
grid-template-columns:
|
|
853
|
+
var(--shl-diff-gutter) var(--shl-diff-gutter)
|
|
854
|
+
2ch minmax(0, 1fr);
|
|
855
|
+
align-items: start;
|
|
856
|
+
line-height: var(--shl-diff-line);
|
|
857
|
+
white-space: pre;
|
|
858
|
+
position: relative;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
.shl-diff-hbar-row {
|
|
862
|
+
scrollbar-gutter: stable;
|
|
863
|
+
overflow-y: hidden;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
.shl-diff-split .shl-diff-row,
|
|
867
|
+
.shl-diff-split .shl-diff-hbar-row {
|
|
868
|
+
grid-template-columns:
|
|
869
|
+
var(--shl-diff-gutter) 2ch minmax(0, 1fr)
|
|
870
|
+
var(--shl-diff-gutter) 2ch minmax(0, 1fr);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
.shl-diff-hbar {
|
|
874
|
+
overflow-x: auto;
|
|
875
|
+
overflow-y: hidden;
|
|
876
|
+
height: 10px;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
.shl-diff-num {
|
|
880
|
+
padding-right: 1ch;
|
|
881
|
+
text-align: right;
|
|
882
|
+
color: var(--shl-diff-muted);
|
|
883
|
+
user-select: none;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
.shl-diff-num-new {
|
|
887
|
+
border-left: 1px solid var(--shl-diff-rule);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
.shl-diff-marker {
|
|
891
|
+
color: var(--shl-diff-muted);
|
|
892
|
+
user-select: none;
|
|
893
|
+
text-align: center;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
.shl-diff-code {
|
|
897
|
+
overflow: hidden;
|
|
898
|
+
padding-right: 2ch;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
.shl-diff-text {
|
|
902
|
+
display: inline-block;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
.shl-diff-wrap .shl-diff-row {
|
|
906
|
+
white-space: pre-wrap;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
.shl-diff-wrap .shl-diff-row .shl-diff-code {
|
|
910
|
+
overflow-wrap: anywhere;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
.shl-diff-wrap .shl-diff-text {
|
|
914
|
+
display: inline;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/* Unified */
|
|
918
|
+
.shl-diff-del {
|
|
919
|
+
background: var(--shl-diff-del);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
.shl-diff-add,
|
|
923
|
+
.shl-diff-incoming {
|
|
924
|
+
background: var(--shl-diff-add);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
.shl-diff-del .shl-diff-marker {
|
|
928
|
+
color: var(--shl-diff-del-accent);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
.shl-diff-add .shl-diff-marker,
|
|
932
|
+
.shl-diff-incoming .shl-diff-marker {
|
|
933
|
+
color: var(--shl-diff-add-accent);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
.shl-diff-del :global(.shl-diff-word) {
|
|
937
|
+
background: var(--shl-diff-del-word);
|
|
938
|
+
border-radius: 2px;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
.shl-diff-add :global(.shl-diff-word),
|
|
942
|
+
.shl-diff-side-new :global(.shl-diff-word) {
|
|
943
|
+
background: var(--shl-diff-add-word);
|
|
944
|
+
border-radius: 2px;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/* Split: color each side on its own. */
|
|
948
|
+
.shl-diff-split .shl-diff-change > .shl-diff-side-old {
|
|
949
|
+
background: var(--shl-diff-del);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
.shl-diff-split .shl-diff-change > .shl-diff-side-new {
|
|
953
|
+
background: var(--shl-diff-add);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
.shl-diff-split .shl-diff-change > .shl-diff-marker.shl-diff-side-old {
|
|
957
|
+
color: var(--shl-diff-del-accent);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
.shl-diff-split .shl-diff-change > .shl-diff-marker.shl-diff-side-new {
|
|
961
|
+
color: var(--shl-diff-add-accent);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
.shl-diff-split .shl-diff-side-old :global(.shl-diff-word) {
|
|
965
|
+
background: var(--shl-diff-del-word);
|
|
966
|
+
border-radius: 2px;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
.shl-diff-split .shl-diff-unpaired-old > .shl-diff-side-old,
|
|
970
|
+
.shl-diff-split .shl-diff-unpaired-new > .shl-diff-side-new {
|
|
971
|
+
background: repeating-linear-gradient(
|
|
972
|
+
-45deg,
|
|
973
|
+
transparent 0 4px,
|
|
974
|
+
var(--shl-diff-rule) 4px 5px
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
.shl-diff-split .shl-diff-incoming > .shl-diff-side-new {
|
|
979
|
+
background: var(--shl-diff-add);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
.shl-diff-split .shl-diff-incoming {
|
|
983
|
+
background: none;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/* Moved blocks */
|
|
987
|
+
.shl-diff-row.shl-diff-moved,
|
|
988
|
+
.shl-diff-split .shl-diff-moved > .shl-diff-code,
|
|
989
|
+
.shl-diff-split .shl-diff-moved > .shl-diff-marker {
|
|
990
|
+
background: var(--shl-diff-move);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
.shl-diff .shl-diff-row.shl-diff-moved .shl-diff-marker {
|
|
994
|
+
color: var(--shl-diff-move-accent);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
.shl-diff-moved::after {
|
|
998
|
+
content: "";
|
|
999
|
+
position: absolute;
|
|
1000
|
+
left: 0;
|
|
1001
|
+
top: 0;
|
|
1002
|
+
bottom: 0;
|
|
1003
|
+
width: 2px;
|
|
1004
|
+
background: var(--shl-diff-move-accent);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/* Folds and status rows */
|
|
1008
|
+
.shl-diff-fold,
|
|
1009
|
+
.shl-diff-pending {
|
|
1010
|
+
display: flex;
|
|
1011
|
+
overflow: hidden;
|
|
1012
|
+
white-space: nowrap;
|
|
1013
|
+
background: color-mix(in srgb, var(--shl-diff-move-accent) 8%, transparent);
|
|
1014
|
+
color: var(--shl-diff-muted);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
.shl-diff-fold-cell {
|
|
1018
|
+
display: flex;
|
|
1019
|
+
flex: 1;
|
|
1020
|
+
min-width: 0;
|
|
1021
|
+
height: 100%;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
.shl-diff-fold-label {
|
|
1025
|
+
font: inherit;
|
|
1026
|
+
height: 100%;
|
|
1027
|
+
margin: 0;
|
|
1028
|
+
padding: 0 0 0 1ch;
|
|
1029
|
+
display: flex;
|
|
1030
|
+
gap: 1ch;
|
|
1031
|
+
align-items: center;
|
|
1032
|
+
color: inherit;
|
|
1033
|
+
background: none;
|
|
1034
|
+
border: 0;
|
|
1035
|
+
cursor: default;
|
|
1036
|
+
width: 100%;
|
|
1037
|
+
text-align: left;
|
|
1038
|
+
user-select: none;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
button.shl-diff-fold-label {
|
|
1042
|
+
cursor: pointer;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
button.shl-diff-fold-label:hover {
|
|
1046
|
+
color: var(--shl-diff-move-accent);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
.shl-diff-hunk {
|
|
1050
|
+
opacity: 0.8;
|
|
1051
|
+
margin-left: auto;
|
|
1052
|
+
padding-right: 2ch;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
.shl-diff-spinner {
|
|
1056
|
+
width: 0.8em;
|
|
1057
|
+
height: 0.8em;
|
|
1058
|
+
border: 2px solid currentColor;
|
|
1059
|
+
border-right-color: transparent;
|
|
1060
|
+
border-radius: 50%;
|
|
1061
|
+
animation: shl-diff-spin 0.8s linear infinite;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
@keyframes shl-diff-spin {
|
|
1065
|
+
to {
|
|
1066
|
+
transform: rotate(360deg);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
.shl-diff-caret {
|
|
1071
|
+
display: inline-block;
|
|
1072
|
+
width: 0.55em;
|
|
1073
|
+
height: 1.1em;
|
|
1074
|
+
vertical-align: text-bottom;
|
|
1075
|
+
background: var(--shl-diff-add-accent);
|
|
1076
|
+
animation: shl-diff-blink 1s steps(1) infinite;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
@keyframes shl-diff-blink {
|
|
1080
|
+
50% {
|
|
1081
|
+
opacity: 0;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1086
|
+
.shl-diff-caret,
|
|
1087
|
+
.shl-diff-spinner {
|
|
1088
|
+
animation: none;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/* Review */
|
|
1093
|
+
.shl-diff-current {
|
|
1094
|
+
box-shadow: inset 3px 0 0 var(--shl-diff-move-accent);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
.shl-diff-rejected {
|
|
1098
|
+
opacity: 0.45;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
.shl-diff-row.shl-diff-rejected.shl-diff-add .shl-diff-code,
|
|
1102
|
+
.shl-diff-split .shl-diff-rejected > .shl-diff-side-new {
|
|
1103
|
+
text-decoration: line-through;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
.shl-diff-row.shl-diff-accepted.shl-diff-del .shl-diff-code,
|
|
1107
|
+
.shl-diff-split .shl-diff-accepted > .shl-diff-side-old {
|
|
1108
|
+
text-decoration: line-through;
|
|
1109
|
+
opacity: 0.6;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
.shl-diff-actions {
|
|
1113
|
+
position: absolute;
|
|
1114
|
+
right: 1ch;
|
|
1115
|
+
top: 0;
|
|
1116
|
+
display: flex;
|
|
1117
|
+
gap: 4px;
|
|
1118
|
+
z-index: 1;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
.shl-diff-actions button {
|
|
1122
|
+
font: inherit;
|
|
1123
|
+
font-size: 0.85em;
|
|
1124
|
+
line-height: 1.4;
|
|
1125
|
+
padding: 0 0.6em;
|
|
1126
|
+
border-radius: 3px;
|
|
1127
|
+
border: 1px solid var(--shl-diff-rule);
|
|
1128
|
+
background: color-mix(in srgb, Canvas 85%, transparent);
|
|
1129
|
+
color: CanvasText;
|
|
1130
|
+
cursor: pointer;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
.shl-diff-accept:hover {
|
|
1134
|
+
border-color: var(--shl-diff-add-accent);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
.shl-diff-reject:hover {
|
|
1138
|
+
border-color: var(--shl-diff-del-accent);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
.shl-diff-decision {
|
|
1142
|
+
font-size: 0.85em;
|
|
1143
|
+
text-transform: uppercase;
|
|
1144
|
+
letter-spacing: 0.05em;
|
|
1145
|
+
color: var(--shl-diff-muted);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/* Notes */
|
|
1149
|
+
.shl-diff-note-slot {
|
|
1150
|
+
grid-column: 1 / -1;
|
|
1151
|
+
white-space: normal;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
.shl-diff-note-card {
|
|
1155
|
+
margin: 2px 2ch 2px calc(var(--shl-diff-gutter) * 2);
|
|
1156
|
+
padding: 0 1ch;
|
|
1157
|
+
border-left: 3px solid var(--shl-diff-move-accent);
|
|
1158
|
+
background: color-mix(
|
|
1159
|
+
in srgb,
|
|
1160
|
+
var(--shl-diff-move-accent) 10%,
|
|
1161
|
+
transparent
|
|
1162
|
+
);
|
|
1163
|
+
white-space: pre-wrap;
|
|
1164
|
+
overflow: hidden;
|
|
1165
|
+
font-family: system-ui, sans-serif;
|
|
1166
|
+
font-size: 0.92em;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
.shl-diff-note-card strong {
|
|
1170
|
+
margin-right: 1ch;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
.shl-diff-note-card.shl-diff-note-warning {
|
|
1174
|
+
border-color: #d29922;
|
|
1175
|
+
background: rgba(210, 153, 34, 0.12);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
.shl-diff-note-card.shl-diff-note-error {
|
|
1179
|
+
border-color: var(--shl-diff-del-accent);
|
|
1180
|
+
background: var(--shl-diff-del);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
.shl-diff-note-card.shl-diff-note-suggestion {
|
|
1184
|
+
border-color: var(--shl-diff-add-accent);
|
|
1185
|
+
background: var(--shl-diff-add);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/* Split selection: copy from one side only. */
|
|
1189
|
+
.shl-diff[data-select="old"] [data-side="new"],
|
|
1190
|
+
.shl-diff[data-select="new"] [data-side="old"] {
|
|
1191
|
+
user-select: none;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
.shl-diff-code :global(.shl-diff-cr)::after {
|
|
1195
|
+
content: "␍";
|
|
1196
|
+
opacity: 0.6;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
.shl-diff-code :global(.shl-diff-noeol)::after {
|
|
1200
|
+
content: " ⊘ no newline at end of file";
|
|
1201
|
+
color: var(--shl-diff-muted);
|
|
1202
|
+
font-style: italic;
|
|
1203
|
+
user-select: none;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
.shl-diff-probe,
|
|
1207
|
+
.shl-diff-char-probe {
|
|
1208
|
+
position: absolute;
|
|
1209
|
+
visibility: hidden;
|
|
1210
|
+
pointer-events: none;
|
|
1211
|
+
white-space: pre;
|
|
1212
|
+
}
|
|
1213
|
+
</style>
|