react-diff-viewer-continued 4.2.2 → 4.4.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.
@@ -10,69 +10,74 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import createEmotion from "@emotion/css/create-instance";
13
+ export const defaultLightThemeVariables = Object.freeze({
14
+ diffViewerBackground: "#fff",
15
+ diffViewerColor: "#212529",
16
+ addedBackground: "#e6ffed",
17
+ addedColor: "#24292e",
18
+ removedBackground: "#ffeef0",
19
+ removedColor: "#24292e",
20
+ changedBackground: "#fffbdd",
21
+ wordAddedBackground: "#acf2bd",
22
+ wordRemovedBackground: "#fdb8c0",
23
+ addedGutterBackground: "#cdffd8",
24
+ removedGutterBackground: "#ffdce0",
25
+ gutterBackground: "#f7f7f7",
26
+ gutterBackgroundDark: "#f3f1f1",
27
+ highlightBackground: "#fffbdd",
28
+ highlightGutterBackground: "#fff5b1",
29
+ codeFoldGutterBackground: "#dbedff",
30
+ codeFoldBackground: "#f1f8ff",
31
+ emptyLineBackground: "#fafbfc",
32
+ gutterColor: "#212529",
33
+ addedGutterColor: "#212529",
34
+ removedGutterColor: "#212529",
35
+ codeFoldContentColor: "#212529",
36
+ diffViewerTitleBackground: "#fafbfc",
37
+ diffViewerTitleColor: "#212529",
38
+ diffViewerTitleBorderColor: "#eee",
39
+ });
40
+ export const defaultDarkThemeVariables = Object.freeze({
41
+ diffViewerBackground: "#2e303c",
42
+ diffViewerColor: "#FFF",
43
+ addedBackground: "#2ea04326",
44
+ addedColor: "white",
45
+ removedBackground: "#f851491a",
46
+ removedColor: "white",
47
+ changedBackground: "#3e302c",
48
+ wordAddedBackground: "#2ea04366",
49
+ wordRemovedBackground: "#f8514966",
50
+ addedGutterBackground: "#3fb9504d",
51
+ removedGutterBackground: "#f851494d",
52
+ gutterBackground: "#2c2f3a",
53
+ gutterBackgroundDark: "#262933",
54
+ highlightBackground: "#2a3967",
55
+ highlightGutterBackground: "#2d4077",
56
+ codeFoldGutterBackground: "#262831",
57
+ codeFoldBackground: "#262831",
58
+ emptyLineBackground: "#363946",
59
+ gutterColor: "#f0f6fc",
60
+ addedGutterColor: "#f0f6fc",
61
+ removedGutterColor: "#f0f6fc",
62
+ codeFoldContentColor: "#9198a1",
63
+ diffViewerTitleBackground: "#2f323e",
64
+ diffViewerTitleColor: "#f0f6fc",
65
+ diffViewerTitleBorderColor: "#353846",
66
+ });
13
67
  export default (styleOverride, useDarkTheme = false, nonce = "") => {
14
68
  const { variables: overrideVariables = {} } = styleOverride, styles = __rest(styleOverride, ["variables"]);
15
69
  const themeVariables = {
16
- light: Object.assign({
17
- diffViewerBackground: "#fff",
18
- diffViewerColor: "#212529",
19
- addedBackground: "#e6ffed",
20
- addedColor: "#24292e",
21
- removedBackground: "#ffeef0",
22
- removedColor: "#24292e",
23
- changedBackground: "#fffbdd",
24
- wordAddedBackground: "#acf2bd",
25
- wordRemovedBackground: "#fdb8c0",
26
- addedGutterBackground: "#cdffd8",
27
- removedGutterBackground: "#ffdce0",
28
- gutterBackground: "#f7f7f7",
29
- gutterBackgroundDark: "#f3f1f1",
30
- highlightBackground: "#fffbdd",
31
- highlightGutterBackground: "#fff5b1",
32
- codeFoldGutterBackground: "#dbedff",
33
- codeFoldBackground: "#f1f8ff",
34
- emptyLineBackground: "#fafbfc",
35
- gutterColor: "#212529",
36
- addedGutterColor: "#212529",
37
- removedGutterColor: "#212529",
38
- codeFoldContentColor: "#212529",
39
- diffViewerTitleBackground: "#fafbfc",
40
- diffViewerTitleColor: "#212529",
41
- diffViewerTitleBorderColor: "#eee",
42
- }, (overrideVariables.light || {})),
43
- dark: Object.assign({
44
- diffViewerBackground: "#2e303c",
45
- diffViewerColor: "#FFF",
46
- addedBackground: "#2ea04326",
47
- addedColor: "white",
48
- removedBackground: "#f851491a",
49
- removedColor: "white",
50
- changedBackground: "#3e302c",
51
- wordAddedBackground: "#2ea04366",
52
- wordRemovedBackground: "#f8514966",
53
- addedGutterBackground: "#3fb9504d",
54
- removedGutterBackground: "#f851494d",
55
- gutterBackground: "#2c2f3a",
56
- gutterBackgroundDark: "#262933",
57
- highlightBackground: "#2a3967",
58
- highlightGutterBackground: "#2d4077",
59
- codeFoldGutterBackground: "#262831",
60
- codeFoldBackground: "#262831",
61
- emptyLineBackground: "#363946",
62
- gutterColor: "#f0f6fc",
63
- addedGutterColor: "#f0f6fc",
64
- removedGutterColor: "#f0f6fc",
65
- codeFoldContentColor: "#9198a1",
66
- diffViewerTitleBackground: "#2f323e",
67
- diffViewerTitleColor: "#f0f6fc",
68
- diffViewerTitleBorderColor: "#353846",
69
- }, (overrideVariables.dark || {})),
70
+ light: Object.assign(Object.assign({}, defaultLightThemeVariables), (overrideVariables.light || {})),
71
+ dark: Object.assign(Object.assign({}, defaultDarkThemeVariables), (overrideVariables.dark || {})),
70
72
  };
71
73
  const variables = useDarkTheme ? themeVariables.dark : themeVariables.light;
72
74
  const { css, cx } = createEmotion({ key: "react-diff", nonce });
73
75
  const content = css({
74
76
  width: "auto",
75
77
  overflow: "hidden",
78
+ // Host `:where(th,td){ padding }` (daisyui `.table`) would indent the code
79
+ // column; we own horizontal spacing via gutter/marker instead.
80
+ padding: 0,
76
81
  label: "content",
77
82
  });
78
83
  const splitView = css({
@@ -114,6 +119,18 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
114
119
  },
115
120
  label: "diff-container",
116
121
  borderCollapse: "collapse",
122
+ borderRadius: 0,
123
+ // Isolate from host table CSS (e.g. daisyui `.table` / `.table-zebra`, Bootstrap,
124
+ // etc.). Such frameworks emit their table rules inside `@layer` with `:where()`
125
+ // selectors, so these unlayered declarations win regardless of specificity. We
126
+ // only reset properties a host injects onto our rows/cells that we do NOT set
127
+ // ourselves per-cell — background, font-size and padding are pinned on the
128
+ // individual line/gutter/marker/content classes instead, so this container rule
129
+ // never outranks and clobbers our own diff colouring.
130
+ "& td, & th": {
131
+ border: 0,
132
+ verticalAlign: "baseline",
133
+ },
117
134
  "@media (max-width: 768px)": {
118
135
  minWidth: "unset",
119
136
  },
@@ -130,6 +147,30 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
130
147
  textDecoration: "none",
131
148
  label: "content-text",
132
149
  });
150
+ // Line content is laid out as two flex items: a fixed indent column carrying the
151
+ // line's leading whitespace, and a flexible body that wraps. This gives wrapped
152
+ // continuation lines a hanging indent — they align under the first character of
153
+ // the line's content instead of falling back to the cell's left edge.
154
+ const contentFlex = css({
155
+ display: "flex",
156
+ alignItems: "baseline",
157
+ label: "content-flex",
158
+ });
159
+ // The indent column. `pre` + `flex-shrink: 0` keep the whitespace intact and
160
+ // prevent it from ever collapsing or wrapping, so it sizes exactly to the indent.
161
+ const lineIndent = css({
162
+ whiteSpace: "pre",
163
+ wordBreak: "keep-all",
164
+ flex: "0 0 auto",
165
+ label: "line-indent",
166
+ });
167
+ // The wrapping body. `min-width: 0` is required so a long unbreakable run wraps
168
+ // within the flex item instead of overflowing the row.
169
+ const lineBody = css({
170
+ flex: "1 1 auto",
171
+ minWidth: 0,
172
+ label: "line-body",
173
+ });
133
174
  const unselectable = css({
134
175
  userSelect: "none",
135
176
  label: "unselectable",
@@ -232,18 +273,38 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
232
273
  label: "code-fold-gutter",
233
274
  minWidth: "50px",
234
275
  width: "50px",
276
+ // Neutralize host `:where(th,td){ padding }` on the fold gutter cell.
277
+ padding: 0,
235
278
  textAlign: "center",
236
279
  fill: variables.codeFoldContentColor,
237
280
  });
238
281
  const codeFoldContentContainer = css({
239
- padding: "",
282
+ // Neutralize host `:where(th,td){ padding }` on the fold content cell.
283
+ padding: 0,
284
+ // Clip the button to the cell box so any residual misalignment can't bleed into the row flow.
285
+ overflow: "hidden",
286
+ // `diffContainer`'s `& td` isolation reset pins vertical-align:baseline at specificity
287
+ // (0,2,0), which out-ranks this single class and drags the fold cell back onto the row
288
+ // baseline (the ~2-3px offset). Self-chain the selector to (0,3,0) so the fold cell's
289
+ // middle alignment wins over that reset.
290
+ "&&&": {
291
+ verticalAlign: "middle",
292
+ },
293
+ label: "code-fold-content-container",
240
294
  });
241
295
  const codeFoldExpandButton = css({
242
296
  background: variables.codeFoldBackground,
243
297
  cursor: "pointer",
244
- display: "inline",
298
+ // `display: inline` puts the button in the cell's line box, so baseline/line-height
299
+ // metrics nudge it ~2-3px down from the cell top and it spills past the bottom.
300
+ // A block box leaves the inline formatting context and sits flush.
301
+ display: "block",
245
302
  margin: 0,
303
+ padding: 0,
246
304
  border: "none",
305
+ font: "inherit",
306
+ lineHeight: "inherit",
307
+ textAlign: "left",
247
308
  fill: variables.codeFoldContentColor,
248
309
  label: "code-fold-expand-button",
249
310
  });
@@ -275,6 +336,14 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
275
336
  fontWeight: 700,
276
337
  cursor: "pointer",
277
338
  label: "code-fold",
339
+ // The fold row has empty/classless placeholder cells (spacer gutters, line-number
340
+ // stand-ins) that pin no padding of their own. Host `:where(th,td){ padding }`
341
+ // (daisyui `.table`) inflates their vertical padding and stretches the fold row
342
+ // out of line with the code rows. Zero block padding on every cell in the row.
343
+ "& td": {
344
+ paddingTop: 0,
345
+ paddingBottom: 0,
346
+ },
278
347
  "&:hover": {
279
348
  color: variables.diffViewerColor,
280
349
  fill: variables.diffViewerColor,
@@ -299,6 +368,10 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
299
368
  width: 28,
300
369
  paddingLeft: 10,
301
370
  paddingRight: 10,
371
+ // Host `padding-block` (daisyui `:where(th,td){ padding }`) would misalign the
372
+ // +/- marker against its line; pin the vertical padding to zero.
373
+ paddingTop: 0,
374
+ paddingBottom: 0,
302
375
  userSelect: "none",
303
376
  label: "marker",
304
377
  [`&.${diffAdded}`]: {
@@ -368,6 +441,11 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
368
441
  verticalAlign: "baseline",
369
442
  label: "line",
370
443
  textDecoration: "none",
444
+ // Neutralize host row styling (e.g. daisyui `.table-zebra` striping and the
445
+ // `tr { font-size }` set by `.table-*` size variants). Cell-level diff colours
446
+ // are painted on the td, so a transparent row lets them show through.
447
+ backgroundColor: "transparent",
448
+ fontSize: 12,
371
449
  });
372
450
  const column = css({});
373
451
  const defaultStyles = {
@@ -399,6 +477,9 @@ export default (styleOverride, useDarkTheme = false, nonce = "") => {
399
477
  emptyLine,
400
478
  lineNumber,
401
479
  contentText,
480
+ contentFlex,
481
+ lineIndent,
482
+ lineBody,
402
483
  content,
403
484
  column,
404
485
  codeFoldContent,