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