@crewlethq/ui 0.152.0 → 0.154.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.
Files changed (118) hide show
  1. package/README.md +9 -1
  2. package/dist/AgentHandoffPanel/index.js +9 -9
  3. package/dist/AppShell/index.js +3 -3
  4. package/dist/ArrangeList/index.js +2 -2
  5. package/dist/ArtifactBar/index.js +1 -1
  6. package/dist/ArtifactCard/index.js +2 -2
  7. package/dist/AuthLayout/index.js +1 -1
  8. package/dist/BriefCard/index.js +1 -1
  9. package/dist/ChangeList/index.js +2 -2
  10. package/dist/ChatThread/index.js +3 -3
  11. package/dist/Combobox/index.js +2 -2
  12. package/dist/CommandPalette/index.js +5 -5
  13. package/dist/CommentThread/index.js +9 -9
  14. package/dist/Composer/index.js +5 -5
  15. package/dist/DataGrid/index.js +6 -6
  16. package/dist/DataTable/index.js +4 -4
  17. package/dist/DataView/index.js +6 -6
  18. package/dist/DatasetSource/index.js +1 -1
  19. package/dist/DeepWorkCard/index.js +1 -1
  20. package/dist/DiffList/index.js +1 -1
  21. package/dist/{DiffList-3JNPLQ2E.css → DiffList-57M6YCNS.css} +6 -7
  22. package/dist/DiffView/DiffView.d.ts +60 -35
  23. package/dist/DiffView/diff.d.ts +9 -41
  24. package/dist/DiffView/index.d.ts +7 -3
  25. package/dist/DiffView/index.js +1 -1
  26. package/dist/DiffView/lineDiff.d.ts +58 -0
  27. package/dist/DiffView/wordDiff.d.ts +47 -0
  28. package/dist/DiffView-J55CPJDX.css +224 -0
  29. package/dist/DocTabsEditor/index.js +6 -6
  30. package/dist/DockColumn/index.js +1 -1
  31. package/dist/DurationField/index.js +5 -5
  32. package/dist/EditingStatus/index.js +2 -2
  33. package/dist/EntityList/index.js +1 -1
  34. package/dist/InlineEditor/index.js +3 -3
  35. package/dist/KeyValueRows/index.js +3 -3
  36. package/dist/ListInput/index.js +6 -6
  37. package/dist/NumberField/index.js +3 -3
  38. package/dist/OpenInAppCard/index.js +2 -2
  39. package/dist/OrgTable/index.js +8 -8
  40. package/dist/PrincipalPicker/index.js +3 -3
  41. package/dist/ProposalCard/index.js +6 -6
  42. package/dist/RailList/index.js +5 -5
  43. package/dist/RefusalCard/index.js +1 -1
  44. package/dist/ResultTableCard/index.js +1 -1
  45. package/dist/RichEditor/index.js +1 -1
  46. package/dist/SectionFrame/index.js +3 -3
  47. package/dist/Select/index.js +2 -2
  48. package/dist/SendKeys/index.js +2 -2
  49. package/dist/SettingForm/index.js +3 -3
  50. package/dist/SettingsTable/index.js +1 -1
  51. package/dist/SetupWizard/index.js +1 -1
  52. package/dist/ShareDialog/index.js +5 -5
  53. package/dist/SheetColumnEditor/index.js +7 -7
  54. package/dist/SidebarNav/index.js +2 -2
  55. package/dist/SlideFilmstrip/index.js +4 -4
  56. package/dist/StatusCard/index.js +1 -1
  57. package/dist/Switcher/index.js +5 -5
  58. package/dist/TableCells/index.js +1 -1
  59. package/dist/TimeRangePicker/index.js +4 -4
  60. package/dist/TimeWindowPicker/index.js +5 -5
  61. package/dist/ToolCallLog/ToolCallLog.d.ts +97 -0
  62. package/dist/ToolCallLog/index.d.ts +3 -0
  63. package/dist/ToolCallLog/index.js +22 -0
  64. package/dist/ToolCallLog-WSK6TEGH.css +288 -0
  65. package/dist/TreeCanvas/index.js +2 -2
  66. package/dist/TreeGrid/index.js +7 -7
  67. package/dist/ValueField/index.js +4 -4
  68. package/dist/VersionCompare/VersionCompare.d.ts +3 -4
  69. package/dist/VersionCompare/index.js +2 -2
  70. package/dist/{chunk-5DLBGF6I.js → chunk-2YAK37D6.js} +1 -1
  71. package/dist/chunk-4U5ATJPP.js +194 -0
  72. package/dist/chunk-4YLN5QVL.js +803 -0
  73. package/dist/{chunk-DWXTJWCJ.js → chunk-5V2DNF3F.js} +3 -3
  74. package/dist/{chunk-6BGD32C5.js → chunk-7DLIVPK4.js} +2 -2
  75. package/dist/{chunk-RGJB34YN.js → chunk-7XUP32RY.js} +1 -1
  76. package/dist/{chunk-D33K2BCZ.js → chunk-C6F5HISC.js} +1 -1
  77. package/dist/{chunk-CJAPAIJG.js → chunk-CFVKNEGM.js} +2 -2
  78. package/dist/{chunk-3Q5USPLM.js → chunk-CSLONHHB.js} +1 -1
  79. package/dist/{chunk-ITZAWYRG.js → chunk-DBXXJOGQ.js} +1 -1
  80. package/dist/{chunk-F6OYNO7O.js → chunk-E6STS4FD.js} +2 -2
  81. package/dist/{chunk-QRUQOITJ.js → chunk-GMHP5KXF.js} +1 -1
  82. package/dist/{chunk-M4VA76JF.js → chunk-MTJ7KNHZ.js} +3 -3
  83. package/dist/{chunk-NB53SAL4.js → chunk-NOZD547E.js} +1 -1
  84. package/dist/{chunk-GFNCMSYS.js → chunk-PPQ3VJUE.js} +1 -1
  85. package/dist/{chunk-S4ADDFRT.js → chunk-S53XH4SS.js} +1 -1
  86. package/dist/{chunk-OX332RI7.js → chunk-SZU2JNJN.js} +1 -1
  87. package/dist/{chunk-OMVGWZ3V.js → chunk-V3HP2HOI.js} +24 -19
  88. package/dist/{chunk-RUKSDKG5.js → chunk-WA4BKMRI.js} +1 -1
  89. package/dist/{chunk-CA62YCFK.js → chunk-WTWYN7Z5.js} +1 -1
  90. package/dist/{chunk-U3ZUZ7VU.js → chunk-Z2YOBQHX.js} +2 -2
  91. package/dist/{chunk-ECYA6XZL.js → chunk-ZPD4XF4H.js} +2 -2
  92. package/dist/generated/index.d.ts +1 -0
  93. package/dist/generated/index.js +77 -76
  94. package/dist/index.js +77 -76
  95. package/dist/styles.css +466 -42
  96. package/package.json +3 -3
  97. package/dist/DiffView-ZI5C25Q3.css +0 -90
  98. package/dist/chunk-F4CM5KD3.js +0 -187
  99. package/dist/{Editor-FXREHINI.js → Editor-VMQ5DK6H.js} +2 -2
  100. package/dist/{chunk-N3R2POGO.js → chunk-2E4MAF6Z.js} +1 -1
  101. package/dist/{chunk-7FY7L6WD.js → chunk-46YFRLA2.js} +1 -1
  102. package/dist/{chunk-KRF3GQ63.js → chunk-6N53ZWRM.js} +1 -1
  103. package/dist/{chunk-Q3SHCEXN.js → chunk-77J2YS55.js} +1 -1
  104. package/dist/{chunk-VXTRPLNB.js → chunk-BFJE3C7Q.js} +1 -1
  105. package/dist/{chunk-657WR3MX.js → chunk-D5UVJL4I.js} +1 -1
  106. package/dist/{chunk-TTUFOH2Y.js → chunk-FNX3YS55.js} +1 -1
  107. package/dist/{chunk-O2J5PSWI.js → chunk-FYJAWS4E.js} +1 -1
  108. package/dist/{chunk-7CVV3DQC.js → chunk-GTJR4APZ.js} +1 -1
  109. package/dist/{chunk-RXHY5T2Z.js → chunk-KJBDOWG7.js} +1 -1
  110. package/dist/{chunk-EDQHZOU3.js → chunk-LPTQN7RS.js} +1 -1
  111. package/dist/{chunk-2DASEYUG.js → chunk-MC5JMA2T.js} +0 -0
  112. package/dist/{chunk-PW6QXVIX.js → chunk-STYJH473.js} +2 -2
  113. package/dist/{chunk-WAF36OFS.js → chunk-T3BIW52Y.js} +1 -1
  114. package/dist/{chunk-7FWYJCKT.js → chunk-WCV44AYD.js} +1 -1
  115. package/dist/{chunk-YWPUT6JQ.js → chunk-YBUUPA5R.js} +1 -1
  116. package/dist/{chunk-5ORAUELE.js → chunk-YGMCXWRA.js} +1 -1
  117. package/dist/{chunk-NG6GEBSJ.js → chunk-YRMDDNFY.js} +1 -1
  118. package/dist/{chunk-UZMXC5T6.js → chunk-YUVQUJND.js} +1 -1
@@ -0,0 +1,803 @@
1
+ import { VisuallyHidden } from './chunk-RRRK2KB6.js';
2
+ import { cx } from './chunk-ODEQTPFM.js';
3
+ import './DiffView-J55CPJDX.css';
4
+ import { useMemo, useRef, useState, useLayoutEffect, useReducer, useEffect, Fragment as Fragment$1 } from 'react';
5
+ import { breakpoint } from '@crewlethq/tokens';
6
+ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
7
+
8
+ // src/DiffView/diff.ts
9
+ function splitLines(text) {
10
+ if (!text) return [];
11
+ const out = text.split(/\r\n|\n|\r/);
12
+ if (out[out.length - 1] === "") out.pop();
13
+ return out;
14
+ }
15
+ function diffStat(diff) {
16
+ let added = 0;
17
+ let removed = 0;
18
+ for (const line of diff) {
19
+ if (line.kind === "add") added++;
20
+ if (line.kind === "remove") removed++;
21
+ }
22
+ return { added, removed, identical: added === 0 && removed === 0 };
23
+ }
24
+ function collapseDiff(diff, context = 3) {
25
+ const keep = new Array(diff.length).fill(false);
26
+ diff.forEach((line, i) => {
27
+ if (line.kind === "same") return;
28
+ for (let k = Math.max(0, i - context); k <= Math.min(diff.length - 1, i + context); k++) {
29
+ keep[k] = true;
30
+ }
31
+ });
32
+ const out = [];
33
+ let skipped = 0;
34
+ let current = null;
35
+ diff.forEach((line, i) => {
36
+ if (keep[i]) {
37
+ if (!current) {
38
+ current = [];
39
+ out.push({ lines: current, skipped });
40
+ skipped = 0;
41
+ }
42
+ current.push(line);
43
+ return;
44
+ }
45
+ skipped++;
46
+ current = null;
47
+ });
48
+ return out;
49
+ }
50
+ function firstChangedLines(sections, max) {
51
+ const out = [];
52
+ let shown = 0;
53
+ let more = 0;
54
+ for (const section of sections) {
55
+ const kept = [];
56
+ for (const line of section.lines) {
57
+ const changed = line.kind !== "same";
58
+ if (shown >= max) {
59
+ if (changed) more++;
60
+ continue;
61
+ }
62
+ if (changed) shown++;
63
+ kept.push(line);
64
+ }
65
+ if (kept.length > 0) out.push({ lines: kept, skipped: section.skipped });
66
+ }
67
+ return { sections: out, more };
68
+ }
69
+
70
+ // src/DiffView/lineDiff.ts
71
+ var MAX_COMPARE_LINES = 2e4;
72
+ var MAX_EDITS = 4e3;
73
+ var CONTEXT_LINES = 3;
74
+ function compareLines(before, after, context = CONTEXT_LINES) {
75
+ const a = splitLines(before);
76
+ const b = splitLines(after);
77
+ const compared = compareSequences(a, b);
78
+ if (compared.kind !== "compared") return compared;
79
+ return { kind: "compared", sections: sectionsOf(compared.runs, a, b, context) };
80
+ }
81
+ function compareSequences(a, b) {
82
+ const shortest = Math.min(a.length, b.length);
83
+ let start = 0;
84
+ while (start < shortest && a[start] === b[start]) start++;
85
+ let end = 0;
86
+ while (end < shortest - start && a[a.length - 1 - end] === b[b.length - 1 - end]) end++;
87
+ const longest = Math.max(a.length - start - end, b.length - start - end);
88
+ if (longest > MAX_COMPARE_LINES) return { kind: "too-large", lines: longest };
89
+ const middle = shortestEdit(a, b, start, end);
90
+ if (middle === null) return { kind: "too-different" };
91
+ const runs = new Runs();
92
+ runs.same(start);
93
+ runs.append(middle);
94
+ runs.same(end);
95
+ return { kind: "compared", runs: runs.all };
96
+ }
97
+ function notComparedReason(why) {
98
+ return why.kind === "too-large" ? `what changed spans ${why.lines.toLocaleString()} lines, more than the ${MAX_COMPARE_LINES.toLocaleString()} a comparison reads` : `more than ${MAX_EDITS.toLocaleString()} lines were removed or added`;
99
+ }
100
+ function distanceFloor(a, b) {
101
+ const held = /* @__PURE__ */ new Map();
102
+ for (let i = 0; i < a.length; i++) held.set(a[i], (held.get(a[i]) ?? 0) + 1);
103
+ let common = 0;
104
+ for (let j = 0; j < b.length; j++) {
105
+ const left = held.get(b[j]) ?? 0;
106
+ if (left === 0) continue;
107
+ held.set(b[j], left - 1);
108
+ common++;
109
+ }
110
+ return a.length + b.length - 2 * common;
111
+ }
112
+ var Runs = class {
113
+ all = [];
114
+ same(count) {
115
+ if (count === 0) return;
116
+ const last = this.all[this.all.length - 1];
117
+ if (last?.kind === "same") last.count += count;
118
+ else this.all.push({ kind: "same", count });
119
+ }
120
+ change(removed, added) {
121
+ if (removed + added === 0) return;
122
+ const last = this.all[this.all.length - 1];
123
+ if (last?.kind === "change") {
124
+ last.removed += removed;
125
+ last.added += added;
126
+ } else {
127
+ this.all.push({ kind: "change", removed, added });
128
+ }
129
+ }
130
+ append(other) {
131
+ for (const run of other.all) {
132
+ if (run.kind === "same") this.same(run.count);
133
+ else this.change(run.removed, run.added);
134
+ }
135
+ }
136
+ };
137
+ function shortestEdit(a, b, start, end) {
138
+ const n = a.length - start - end;
139
+ const m = b.length - start - end;
140
+ const runs = new Runs();
141
+ if (n === 0 || m === 0) {
142
+ if (n + m > MAX_EDITS) return null;
143
+ runs.change(n, m);
144
+ return runs;
145
+ }
146
+ const ids = /* @__PURE__ */ new Map();
147
+ const intern = (line) => {
148
+ let id = ids.get(line);
149
+ if (id === void 0) {
150
+ id = ids.size;
151
+ ids.set(line, id);
152
+ }
153
+ return id;
154
+ };
155
+ const x = new Int32Array(n);
156
+ const y = new Int32Array(m);
157
+ for (let i = 0; i < n; i++) x[i] = intern(a[start + i]);
158
+ for (let j = 0; j < m; j++) y[j] = intern(b[start + j]);
159
+ if (distanceFloor(x, y) > MAX_EDITS) return null;
160
+ return edit(x, y, 0, n, 0, m, runs, MAX_EDITS) ? runs : null;
161
+ }
162
+ function edit(a, b, x0, x1, y0, y1, runs, budget) {
163
+ let start = 0;
164
+ while (x0 + start < x1 && y0 + start < y1 && a[x0 + start] === b[y0 + start]) start++;
165
+ let end = 0;
166
+ while (x1 - end > x0 + start && y1 - end > y0 + start && a[x1 - 1 - end] === b[y1 - 1 - end]) end++;
167
+ const fromX = x0 + start;
168
+ const toX = x1 - end;
169
+ const fromY = y0 + start;
170
+ const toY = y1 - end;
171
+ const n = toX - fromX;
172
+ const m = toY - fromY;
173
+ const cut = n === 0 || m === 0 ? n + m > budget ? null : "nothing in common" : middleSnake(a, b, fromX, toX, fromY, toY, budget);
174
+ if (cut === null) return false;
175
+ runs.same(start);
176
+ if (cut === "nothing in common") {
177
+ runs.change(n, m);
178
+ } else {
179
+ edit(a, b, fromX, cut.x, fromY, cut.y, runs, Infinity);
180
+ edit(a, b, cut.x, toX, cut.y, toY, runs, Infinity);
181
+ }
182
+ runs.same(end);
183
+ return true;
184
+ }
185
+ function middleSnake(a, b, x0, x1, y0, y1, budget) {
186
+ const n = x1 - x0;
187
+ const m = y1 - y0;
188
+ const most = Math.ceil((n + m) / 2);
189
+ const rounds = Math.min(most, Math.ceil(budget / 2) + 1);
190
+ const offset = rounds;
191
+ const size = 2 * rounds + 2;
192
+ const forward = new Int32Array(size).fill(-1);
193
+ const reverse = new Int32Array(size).fill(-1);
194
+ forward[offset + 1] = 0;
195
+ reverse[offset + 1] = 0;
196
+ const delta = n - m;
197
+ const odd = (delta & 1) !== 0;
198
+ let forwardFrom = 0;
199
+ let forwardTo = 0;
200
+ let reverseFrom = 0;
201
+ let reverseTo = 0;
202
+ const within = (distance, cut) => distance > budget ? null : cut;
203
+ for (let d = 0; d < rounds; d++) {
204
+ for (let k = -d + forwardFrom; k <= d - forwardTo; k += 2) {
205
+ const at = offset + k;
206
+ let x = k === -d || k !== d && forward[at - 1] < forward[at + 1] ? forward[at + 1] : forward[at - 1] + 1;
207
+ let y = x - k;
208
+ while (x < n && y < m && a[x0 + x] === b[y0 + y]) {
209
+ x++;
210
+ y++;
211
+ }
212
+ forward[at] = x;
213
+ if (x > n) forwardTo += 2;
214
+ else if (y > m) forwardFrom += 2;
215
+ else if (odd) {
216
+ const mirror = offset + delta - k;
217
+ if (mirror >= 0 && mirror < size && reverse[mirror] !== -1 && x >= n - reverse[mirror]) {
218
+ return within(2 * d - 1, { x: x0 + x, y: y0 + y });
219
+ }
220
+ }
221
+ }
222
+ for (let k = -d + reverseFrom; k <= d - reverseTo; k += 2) {
223
+ const at = offset + k;
224
+ let x = k === -d || k !== d && reverse[at - 1] < reverse[at + 1] ? reverse[at + 1] : reverse[at - 1] + 1;
225
+ let y = x - k;
226
+ while (x < n && y < m && a[x1 - 1 - x] === b[y1 - 1 - y]) {
227
+ x++;
228
+ y++;
229
+ }
230
+ reverse[at] = x;
231
+ if (x > n) reverseTo += 2;
232
+ else if (y > m) reverseFrom += 2;
233
+ else if (!odd) {
234
+ const mirror = offset + delta - k;
235
+ if (mirror >= 0 && mirror < size && forward[mirror] !== -1) {
236
+ const fx = forward[mirror];
237
+ if (fx >= n - x) return within(2 * d, { x: x0 + fx, y: y0 + fx - (mirror - offset) });
238
+ }
239
+ }
240
+ }
241
+ }
242
+ return rounds === most && n + m <= budget ? "nothing in common" : null;
243
+ }
244
+ function sectionsOf(runs, a, b, context) {
245
+ const out = [];
246
+ let x = 0;
247
+ let y = 0;
248
+ let open = null;
249
+ let skipped = 0;
250
+ const section = () => {
251
+ if (open) return open;
252
+ const lines = [];
253
+ out.push({ lines, skipped });
254
+ skipped = 0;
255
+ open = lines;
256
+ return lines;
257
+ };
258
+ const keep = (count) => {
259
+ const lines = section();
260
+ for (let i = 0; i < count; i++, x++, y++) lines.push({ kind: "same", text: a[x], before: x + 1, after: y + 1 });
261
+ };
262
+ runs.forEach((run, r) => {
263
+ if (run.kind === "change") {
264
+ const lines = section();
265
+ for (let i = 0; i < run.removed; i++, x++) lines.push({ kind: "remove", text: a[x], before: x + 1, after: null });
266
+ for (let i = 0; i < run.added; i++, y++) lines.push({ kind: "add", text: b[y], before: null, after: y + 1 });
267
+ return;
268
+ }
269
+ const after = r > 0 ? Math.min(context, run.count) : 0;
270
+ const before = r < runs.length - 1 ? Math.min(context, run.count - after) : 0;
271
+ if (after > 0) keep(after);
272
+ const gap = run.count - after - before;
273
+ if (gap > 0) {
274
+ x += gap;
275
+ y += gap;
276
+ skipped += gap;
277
+ open = null;
278
+ }
279
+ if (before > 0) keep(before);
280
+ });
281
+ return out;
282
+ }
283
+
284
+ // src/DiffView/wordDiff.ts
285
+ var NONE = { before: null, after: null };
286
+ var TOKEN = /[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}]|(?:(?![\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}])[\p{L}\p{N}\p{M}_])+|\s+|[^]/gu;
287
+ var WORD = /[\p{L}\p{N}]/u;
288
+ function lineTokens(text) {
289
+ const out = [];
290
+ for (const m of text.matchAll(TOKEN)) {
291
+ const start = m.index;
292
+ out.push({ text: m[0], start, end: start + m[0].length, word: WORD.test(m[0]) });
293
+ }
294
+ return out;
295
+ }
296
+ function span(all, from, to) {
297
+ if (from >= to) return null;
298
+ return { start: all[from].start, end: all[to - 1].end };
299
+ }
300
+ function changedRuns(before, after) {
301
+ const a = lineTokens(before);
302
+ const b = lineTokens(after);
303
+ let head = 0;
304
+ while (head < a.length && head < b.length && a[head].text === b[head].text) head++;
305
+ let tail = 0;
306
+ while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail].text === b[b.length - 1 - tail].text) {
307
+ tail++;
308
+ }
309
+ const shared = a.slice(0, head).concat(a.slice(a.length - tail));
310
+ if (!shared.some((t) => t.word)) return NONE;
311
+ return { before: span(a, head, a.length - tail), after: span(b, head, b.length - tail) };
312
+ }
313
+ function segments(text, spans, run) {
314
+ const length = text.length;
315
+ const from = run ? Math.min(Math.max(run.start, 0), length) : 0;
316
+ const to = run ? Math.min(Math.max(run.end, from), length) : 0;
317
+ const out = [];
318
+ let ran = false;
319
+ const push = (start, end, className) => {
320
+ if (end <= start) return;
321
+ const last = out[out.length - 1];
322
+ if (className === null && last && !last.run && last.className === null && last.end === start) {
323
+ last.end = end;
324
+ } else {
325
+ out.push({ start, end, className, run: false });
326
+ }
327
+ };
328
+ const piece = (start, end, className) => {
329
+ if (!run || end <= from || start >= to) {
330
+ if (run && !ran && start >= to) {
331
+ out.push({ start: from, end: to, className: null, run: true });
332
+ ran = true;
333
+ }
334
+ push(start, end, className);
335
+ return;
336
+ }
337
+ push(start, from, className);
338
+ if (!ran) out.push({ start: from, end: to, className: null, run: true });
339
+ ran = true;
340
+ push(to, end, className);
341
+ };
342
+ let at = 0;
343
+ for (const span2 of spans ?? []) {
344
+ const end = Math.min(span2.end, length);
345
+ if (end <= at) continue;
346
+ piece(at, end, span2.className);
347
+ at = end;
348
+ }
349
+ piece(at, length, null);
350
+ if (run && !ran) out.push({ start: from, end: to, className: null, run: true });
351
+ if (out.length === 0) out.push({ start: 0, end: 0, className: null, run: false });
352
+ return out;
353
+ }
354
+ var DIFF_SUMMARY_LABELS = {
355
+ spoken: (added, removed) => `${added === 1 ? "1 line" : `${added.toLocaleString()} lines`} added, ${removed.toLocaleString()} removed`,
356
+ against: (what) => `against ${what}`
357
+ };
358
+ var DIFF_VIEW_LABELS = {
359
+ ...DIFF_SUMMARY_LABELS,
360
+ skipped: (count) => count === 1 ? "1 unchanged line" : `${count.toLocaleString()} unchanged lines`,
361
+ added: "Added",
362
+ removed: "Removed",
363
+ region: "Line changes",
364
+ empty: "Nothing changed.",
365
+ notCompared: (why) => `The two versions were not compared line by line: ${notComparedReason(why)}.`,
366
+ pick: (line) => `${line.after !== null ? "Line" : "Removed line"} ${line.after ?? line.before}: pick it`
367
+ };
368
+ var WINDOW_FROM_ROWS = 1e3;
369
+ var WINDOW_BLOCK_ROWS = 100;
370
+ var ROW_ESTIMATE_PX = 21;
371
+ var PHONE_PX = Number.parseFloat(breakpoint.phone);
372
+ var Pair = class {
373
+ constructor(removed, added) {
374
+ this.removed = removed;
375
+ this.added = added;
376
+ }
377
+ removed;
378
+ added;
379
+ runs;
380
+ runOf(kind) {
381
+ this.runs ??= changedRuns(this.removed, this.added);
382
+ return kind === "remove" ? this.runs.before : this.runs.after;
383
+ }
384
+ };
385
+ function pairsOf(sections, keyed) {
386
+ const pairs = /* @__PURE__ */ new Map();
387
+ const join = (removed, added) => {
388
+ const pair = new Pair(removed.text, added.text);
389
+ pairs.set(removed, pair);
390
+ pairs.set(added, pair);
391
+ };
392
+ for (const section of sections) {
393
+ const lines = section.lines;
394
+ for (let i = 0; i < lines.length; ) {
395
+ if (lines[i].kind === "same") {
396
+ i++;
397
+ continue;
398
+ }
399
+ const removed = [];
400
+ const added = [];
401
+ for (; i < lines.length && lines[i].kind !== "same"; i++) {
402
+ const line = lines[i];
403
+ (line.kind === "remove" ? removed : added).push(line);
404
+ }
405
+ if (keyed) pairByPath(removed, added, join);
406
+ else pairByPosition(removed, added, join);
407
+ }
408
+ }
409
+ return pairs;
410
+ }
411
+ function pairByPosition(removed, added, join) {
412
+ if (removed.length !== added.length && Math.min(removed.length, added.length) !== 1) return;
413
+ for (let k = 0; k < Math.min(removed.length, added.length); k++) join(removed[k], added[k]);
414
+ }
415
+ function pairByPath(removed, added, join) {
416
+ const sides = /* @__PURE__ */ new Map();
417
+ const sideOf = (path) => {
418
+ let side = sides.get(path);
419
+ if (!side) sides.set(path, side = { removed: [], added: [] });
420
+ return side;
421
+ };
422
+ for (const line of removed) if (line.path !== void 0) sideOf(line.path).removed.push(line);
423
+ for (const line of added) if (line.path !== void 0) sideOf(line.path).added.push(line);
424
+ for (const side of sides.values()) pairByPosition(side.removed, side.added, join);
425
+ }
426
+ function rowsOf(sections, split) {
427
+ const rows = [];
428
+ for (const section of sections) {
429
+ if (section.skipped > 0) rows.push({ kind: "skip", count: section.skipped });
430
+ const lines = section.lines;
431
+ if (!split) {
432
+ lines.forEach((line, i) => rows.push({ kind: "line", line, continues: continuesAbove(line, lines[i - 1]) }));
433
+ continue;
434
+ }
435
+ for (let i = 0; i < lines.length; ) {
436
+ const line = lines[i];
437
+ if (line.kind === "same") {
438
+ rows.push({ kind: "pair", left: line, right: line });
439
+ i++;
440
+ continue;
441
+ }
442
+ const removed = [];
443
+ const added = [];
444
+ for (; i < lines.length && lines[i].kind !== "same"; i++) {
445
+ const changed = lines[i];
446
+ (changed.kind === "remove" ? removed : added).push(changed);
447
+ }
448
+ for (let k = 0; k < Math.max(removed.length, added.length); k++) {
449
+ rows.push({ kind: "pair", left: removed[k] ?? null, right: added[k] ?? null });
450
+ }
451
+ }
452
+ }
453
+ return rows;
454
+ }
455
+ function continuesAbove(line, above) {
456
+ return line.path !== void 0 && above !== void 0 && above.path === line.path && above.kind === line.kind;
457
+ }
458
+ function underlineOf(pairs, line) {
459
+ return line.kind === "same" ? null : pairs.get(line)?.runOf(line.kind) ?? null;
460
+ }
461
+ function shapeOf(sections) {
462
+ let keyed = false;
463
+ let numbered = false;
464
+ let widest = 1;
465
+ let path = 0;
466
+ let added = 0;
467
+ let removed = 0;
468
+ for (const section of sections) {
469
+ for (const line of section.lines) {
470
+ if (line.path !== void 0) {
471
+ keyed = true;
472
+ path = Math.max(path, line.path.length);
473
+ }
474
+ for (const n of [line.before, line.after]) {
475
+ if (n === null) continue;
476
+ numbered = true;
477
+ widest = Math.max(widest, n);
478
+ }
479
+ if (line.kind === "add") added++;
480
+ if (line.kind === "remove") removed++;
481
+ }
482
+ }
483
+ return { keyed, numbered: numbered && !keyed, digits: String(widest).length, path, added, removed };
484
+ }
485
+ function blocksOf(rows) {
486
+ const out = [];
487
+ for (let at = 0; at < rows.length; at += WINDOW_BLOCK_ROWS) out.push(rows.slice(at, at + WINDOW_BLOCK_ROWS));
488
+ return out;
489
+ }
490
+ var NO_SECTIONS = [];
491
+ var FIRST = /* @__PURE__ */ new Set([0]);
492
+ function scrollerOf(el) {
493
+ for (let at = el.parentElement; at; at = at.parentElement) {
494
+ const { overflowY } = getComputedStyle(at);
495
+ if (overflowY === "auto" || overflowY === "scroll") return at;
496
+ }
497
+ return null;
498
+ }
499
+ function useNarrowerThan(node, below, ready) {
500
+ const [width, setWidth] = useState(0);
501
+ useLayoutEffect(() => {
502
+ const el = node.current;
503
+ if (!el || !ready) return void 0;
504
+ const measure = () => setWidth(el.clientWidth);
505
+ measure();
506
+ if (typeof ResizeObserver === "undefined") return void 0;
507
+ const watch = new ResizeObserver(measure);
508
+ watch.observe(el);
509
+ return () => watch.disconnect();
510
+ }, [node, ready]);
511
+ return width > 0 && width < below;
512
+ }
513
+ function useWindow(body, blocks, windowed) {
514
+ const [near, setNear] = useState(FIRST);
515
+ const { heights } = useMemo(() => ({ of: blocks, heights: /* @__PURE__ */ new Map() }), [blocks]);
516
+ const [, measuredNew] = useReducer((n) => n + 1, 0);
517
+ const observing = windowed && typeof IntersectionObserver !== "undefined";
518
+ const drawn = useRef(FIRST);
519
+ useLayoutEffect(() => {
520
+ drawn.current = near;
521
+ const el = body.current;
522
+ if (!observing || !el) return;
523
+ let changed = false;
524
+ for (const block of el.querySelectorAll("[data-block]")) {
525
+ const at = Number(block.dataset.block);
526
+ const height2 = block.getBoundingClientRect().height;
527
+ if (!near.has(at) || height2 <= 0 || heights.get(at) === height2) continue;
528
+ heights.set(at, height2);
529
+ changed = true;
530
+ }
531
+ if (changed) measuredNew();
532
+ }, [body, heights, near, observing]);
533
+ useEffect(() => {
534
+ const el = body.current;
535
+ if (!observing || !el) return void 0;
536
+ const watch = new IntersectionObserver(
537
+ (entries) => {
538
+ const said = entries.map((entry) => ({
539
+ at: Number(entry.target.dataset.block),
540
+ near: entry.isIntersecting,
541
+ height: entry.boundingClientRect.height
542
+ }));
543
+ for (const { at, near: near2, height: height2 } of said) {
544
+ if (!near2 && height2 > 0 && drawn.current.has(at)) heights.set(at, height2);
545
+ }
546
+ setNear((was) => {
547
+ let now = null;
548
+ for (const { at, near: near2 } of said) {
549
+ if (near2 === (now ?? was).has(at)) continue;
550
+ now ??= new Set(was);
551
+ if (near2) now.add(at);
552
+ else now.delete(at);
553
+ }
554
+ return now ?? was;
555
+ });
556
+ },
557
+ { root: scrollerOf(el), rootMargin: "100% 0px" }
558
+ );
559
+ for (const block of el.querySelectorAll("[data-block]")) watch.observe(block);
560
+ return () => watch.disconnect();
561
+ }, [body, heights, observing]);
562
+ let rows = 0;
563
+ let height = 0;
564
+ for (const [at, h] of heights) {
565
+ rows += blocks[at]?.length ?? 0;
566
+ height += h;
567
+ }
568
+ const perRow = rows > 0 ? height / rows : ROW_ESTIMATE_PX;
569
+ return {
570
+ holds: (at) => !observing || near.has(at),
571
+ height: (at) => heights.get(at) ?? (blocks[at]?.length ?? 0) * perRow
572
+ };
573
+ }
574
+ function rowDraws(row, accepts) {
575
+ switch (row.kind) {
576
+ case "skip":
577
+ return false;
578
+ case "line":
579
+ return accepts(row.line);
580
+ case "pair":
581
+ return row.left !== null && accepts(row.left) || row.right !== null && accepts(row.right);
582
+ }
583
+ }
584
+ function useReveal(body, blocks, reveal, holds) {
585
+ const at = useMemo(() => reveal ? blocks.findIndex((block) => block.some((row) => rowDraws(row, reveal))) : -1, [blocks, reveal]);
586
+ const held = at >= 0 && holds(at);
587
+ const done = useRef(null);
588
+ useLayoutEffect(() => {
589
+ if (!reveal || at < 0) return;
590
+ const was = done.current?.reveal === reveal ? done.current : null;
591
+ if (was?.line) return;
592
+ const box = body.current?.querySelector(`[data-block="${at}"]`);
593
+ if (!box) return;
594
+ if (held) {
595
+ const line = box.querySelector(".crewlet-diff-view__line[data-revealed]");
596
+ if (!line) return;
597
+ done.current = { reveal, line: true };
598
+ line.scrollIntoView?.({ block: "center" });
599
+ return;
600
+ }
601
+ if (was) return;
602
+ done.current = { reveal, line: false };
603
+ box.scrollIntoView?.({ block: "center" });
604
+ }, [body, at, held, reveal]);
605
+ }
606
+ function Text({ text, run, spans }) {
607
+ if (!text) return /* @__PURE__ */ jsx("span", { className: "crewlet-diff-view__text", children: " " });
608
+ return /* @__PURE__ */ jsx("span", { className: "crewlet-diff-view__text", children: segments(text, spans, run).map((s, i) => {
609
+ const piece = text.slice(s.start, s.end);
610
+ if (s.run) {
611
+ return /* @__PURE__ */ jsx("span", { className: "crewlet-diff-view__run", children: piece }, i);
612
+ }
613
+ return s.className ? /* @__PURE__ */ jsx("span", { className: s.className, children: piece }, i) : piece;
614
+ }) });
615
+ }
616
+ function Mark({ kind, labels }) {
617
+ return /* @__PURE__ */ jsxs("span", { className: "crewlet-diff-view__mark", children: [
618
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: kind === "add" ? "+" : kind === "remove" ? "\u2212" : " " }),
619
+ kind === "add" && /* @__PURE__ */ jsx(VisuallyHidden, { children: labels.added }),
620
+ kind === "remove" && /* @__PURE__ */ jsx(VisuallyHidden, { children: labels.removed })
621
+ ] });
622
+ }
623
+ function spansReader(tokens) {
624
+ return (line, side) => {
625
+ if (line.path !== void 0) return null;
626
+ const older = line.kind === "remove" || line.kind === "same" && side === "left";
627
+ const n = older ? line.before : line.after;
628
+ return n === null ? null : tokens(older ? "before" : "after", n);
629
+ };
630
+ }
631
+ function SlotNumber({ line, slot, side, tracks }) {
632
+ const n = slot === "after" ? line.after : line.before;
633
+ const own = side === "left" ? true : side === "right" ? line.kind !== "same" : slot === (line.after !== null ? "after" : "before");
634
+ const pick = tracks.onPick;
635
+ if (!pick || n === null || !own) {
636
+ return /* @__PURE__ */ jsx("span", { className: "crewlet-diff-view__number", "aria-hidden": "true", children: n ?? "" });
637
+ }
638
+ return /* @__PURE__ */ jsx(
639
+ "button",
640
+ {
641
+ type: "button",
642
+ className: "crewlet-diff-view__number crewlet-diff-view__pick",
643
+ "aria-label": tracks.labels.pick(line),
644
+ onClick: (event) => pick(line, event.shiftKey),
645
+ children: n
646
+ }
647
+ );
648
+ }
649
+ function Notes({ lines, tracks }) {
650
+ if (!tracks.notes) return null;
651
+ const drawn = lines.flatMap((line, i) => {
652
+ if (!line || i > 0 && line === lines[0]) return [];
653
+ const note = tracks.notes(line);
654
+ return note === null || note === void 0 || note === false ? [] : [/* @__PURE__ */ jsx(Fragment$1, { children: note }, i)];
655
+ });
656
+ if (drawn.length === 0) return null;
657
+ return /* @__PURE__ */ jsx("div", { className: "crewlet-diff-view__notes", children: drawn });
658
+ }
659
+ function Line({
660
+ line,
661
+ run,
662
+ tracks,
663
+ side,
664
+ hidden = false,
665
+ continues = false
666
+ }) {
667
+ const reader = tracks.spans;
668
+ const spans = useMemo(() => reader?.(line, side) ?? null, [reader, line, side]);
669
+ return /* @__PURE__ */ jsxs(
670
+ "div",
671
+ {
672
+ className: cx(
673
+ "crewlet-diff-view__line",
674
+ line.kind === "add" && "crewlet-diff-view__line--add",
675
+ line.kind === "remove" && "crewlet-diff-view__line--remove",
676
+ tracks.picked?.(line) && "crewlet-diff-view__line--picked"
677
+ ),
678
+ "data-kind": line.kind,
679
+ "data-revealed": tracks.reveal?.(line) || void 0,
680
+ "aria-hidden": hidden || void 0,
681
+ children: [
682
+ tracks.numbered && side !== "right" && /* @__PURE__ */ jsx(SlotNumber, { line, slot: "before", side, tracks }),
683
+ tracks.numbered && side !== "left" && /* @__PURE__ */ jsx(SlotNumber, { line, slot: "after", side, tracks }),
684
+ /* @__PURE__ */ jsx(Mark, { kind: line.kind, labels: tracks.labels }),
685
+ tracks.keyed && !continues && /* @__PURE__ */ jsx("span", { className: "crewlet-diff-view__path", children: line.path ?? "" }),
686
+ /* @__PURE__ */ jsx(Text, { text: line.text, run, spans })
687
+ ]
688
+ }
689
+ );
690
+ }
691
+ function RowView({ row, tracks, pairs }) {
692
+ switch (row.kind) {
693
+ case "skip":
694
+ return /* @__PURE__ */ jsx("div", { className: "crewlet-diff-view__skip", children: tracks.labels.skipped(row.count) });
695
+ case "line":
696
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
697
+ /* @__PURE__ */ jsx(Line, { line: row.line, run: underlineOf(pairs, row.line), tracks, continues: row.continues }),
698
+ /* @__PURE__ */ jsx(Notes, { lines: [row.line], tracks })
699
+ ] });
700
+ case "pair": {
701
+ const same = row.left?.kind === "same";
702
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
703
+ /* @__PURE__ */ jsxs("div", { className: "crewlet-diff-view__pair", children: [
704
+ row.left ? /* @__PURE__ */ jsx(Line, { line: row.left, run: underlineOf(pairs, row.left), tracks, side: "left" }) : /* @__PURE__ */ jsx("div", { "aria-hidden": "true" }),
705
+ row.right ? (
706
+ // An unchanged line is read once: its newer copy is the same words.
707
+ /* @__PURE__ */ jsx(Line, { line: row.right, run: underlineOf(pairs, row.right), tracks, side: "right", hidden: same })
708
+ ) : /* @__PURE__ */ jsx("div", { "aria-hidden": "true" })
709
+ ] }),
710
+ /* @__PURE__ */ jsx(Notes, { lines: [row.left, row.right], tracks })
711
+ ] });
712
+ }
713
+ }
714
+ }
715
+ function DiffView(props) {
716
+ const {
717
+ sections: given,
718
+ before,
719
+ after,
720
+ context,
721
+ layout = "unified",
722
+ against,
723
+ empty,
724
+ notes,
725
+ onPick,
726
+ picked,
727
+ reveal,
728
+ tokens,
729
+ labels: overrides,
730
+ className,
731
+ style,
732
+ "aria-label": ariaLabel,
733
+ ...rest
734
+ } = props;
735
+ const labels = overrides ? { ...DIFF_VIEW_LABELS, ...overrides } : DIFF_VIEW_LABELS;
736
+ const compared = useMemo(
737
+ () => given ? null : compareLines(before ?? "", after ?? "", context),
738
+ [given, before, after, context]
739
+ );
740
+ const sections = given ?? (compared?.kind === "compared" ? compared.sections : NO_SECTIONS);
741
+ const shape = useMemo(() => shapeOf(sections), [sections]);
742
+ const changed = shape.added > 0 || shape.removed > 0;
743
+ const root = useRef(null);
744
+ const body = useRef(null);
745
+ const narrow = useNarrowerThan(root, PHONE_PX, changed);
746
+ const split = layout === "split" && !shape.keyed && !narrow;
747
+ const pairs = useMemo(() => pairsOf(sections, shape.keyed), [sections, shape.keyed]);
748
+ const rows = useMemo(() => rowsOf(sections, split), [sections, split]);
749
+ const blocks = useMemo(() => blocksOf(rows), [rows]);
750
+ const shown = useWindow(body, blocks, rows.length > WINDOW_FROM_ROWS);
751
+ useReveal(body, blocks, reveal, shown.holds);
752
+ const spans = useMemo(() => tokens ? spansReader(tokens) : void 0, [tokens]);
753
+ if (compared && compared.kind !== "compared") {
754
+ return /* @__PURE__ */ jsx("p", { className: "crewlet-diff-view__said", children: labels.notCompared(compared) });
755
+ }
756
+ if (!changed) {
757
+ return /* @__PURE__ */ jsx(Fragment, { children: empty ?? /* @__PURE__ */ jsx("p", { className: "crewlet-diff-view__said crewlet-diff-view__said--quiet", children: labels.empty }) });
758
+ }
759
+ const tracks = { numbered: shape.numbered, keyed: shape.keyed, labels, notes, onPick, picked, reveal, spans };
760
+ return /* @__PURE__ */ jsxs(
761
+ "div",
762
+ {
763
+ ...rest,
764
+ ref: root,
765
+ role: "group",
766
+ "aria-label": ariaLabel ?? labels.region,
767
+ className: cx(
768
+ "crewlet-diff-view",
769
+ shape.numbered && "crewlet-diff-view--numbered",
770
+ shape.keyed && "crewlet-diff-view--keyed",
771
+ split && "crewlet-diff-view--split",
772
+ className
773
+ ),
774
+ style: { ...style, "--crewlet-diff-digits": String(shape.digits), "--crewlet-diff-path": String(shape.path) },
775
+ children: [
776
+ against !== void 0 && /* @__PURE__ */ jsx(DiffSummary, { added: shape.added, removed: shape.removed, against, labels }),
777
+ /* @__PURE__ */ jsx("div", { ref: body, className: "crewlet-diff-view__body", children: blocks.map(
778
+ (block, at) => shown.holds(at) ? /* @__PURE__ */ jsx("div", { className: "crewlet-diff-view__block", "data-block": at, children: block.map((row, i) => /* @__PURE__ */ jsx(RowView, { row, tracks, pairs }, i)) }, at) : /* @__PURE__ */ jsx("div", { className: "crewlet-diff-view__block", "data-block": at, "aria-hidden": "true", style: { height: `${shown.height(at)}px` } }, at)
779
+ ) })
780
+ ]
781
+ }
782
+ );
783
+ }
784
+ function DiffSummary({ added, removed, against, labels: overrides, className, ...rest }) {
785
+ const labels = overrides ? { ...DIFF_SUMMARY_LABELS, ...overrides } : DIFF_SUMMARY_LABELS;
786
+ return /* @__PURE__ */ jsxs("p", { ...rest, className: cx("crewlet-diff-summary", className), children: [
787
+ /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", children: [
788
+ /* @__PURE__ */ jsxs("span", { className: "crewlet-diff-summary__added", children: [
789
+ "+",
790
+ added.toLocaleString()
791
+ ] }),
792
+ " ",
793
+ /* @__PURE__ */ jsx("span", { className: "crewlet-diff-summary__removed", children: `\u2212${removed.toLocaleString()}` })
794
+ ] }),
795
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: labels.spoken(added, removed) }),
796
+ against !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
797
+ " ",
798
+ labels.against(against)
799
+ ] })
800
+ ] });
801
+ }
802
+
803
+ export { CONTEXT_LINES, DIFF_SUMMARY_LABELS, DIFF_VIEW_LABELS, DiffSummary, DiffView, MAX_COMPARE_LINES, MAX_EDITS, WINDOW_BLOCK_ROWS, WINDOW_FROM_ROWS, changedRuns, collapseDiff, compareLines, compareSequences, diffStat, distanceFloor, firstChangedLines, lineTokens, notComparedReason, segments, splitLines };