@zentauri-ui/zentauri-components 2.1.8 → 2.1.9

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 (77) hide show
  1. package/README.md +5 -4
  2. package/cli/props.json +161 -0
  3. package/cli/registry.json +2 -0
  4. package/dist/{chunk-D7ZTSAA6.mjs → chunk-3HBC34NF.mjs} +4 -4
  5. package/dist/{chunk-D7ZTSAA6.mjs.map → chunk-3HBC34NF.mjs.map} +1 -1
  6. package/dist/{chunk-UVP3MUBU.mjs → chunk-3RC5IG6O.mjs} +18 -6
  7. package/dist/chunk-3RC5IG6O.mjs.map +1 -0
  8. package/dist/{chunk-DPNTQ4AK.js → chunk-4TPE5DEG.js} +18 -6
  9. package/dist/chunk-4TPE5DEG.js.map +1 -0
  10. package/dist/{chunk-L5QORCUO.js → chunk-7CZDJTPD.js} +12 -12
  11. package/dist/{chunk-L5QORCUO.js.map → chunk-7CZDJTPD.js.map} +1 -1
  12. package/dist/{chunk-BAAXQPZ7.js → chunk-7DGPRPWM.js} +6 -6
  13. package/dist/{chunk-BAAXQPZ7.js.map → chunk-7DGPRPWM.js.map} +1 -1
  14. package/dist/chunk-GP3FUS2H.mjs +26 -0
  15. package/dist/chunk-GP3FUS2H.mjs.map +1 -0
  16. package/dist/chunk-MWG7LHAK.js +19 -0
  17. package/dist/{chunk-6OVDBAMI.js.map → chunk-MWG7LHAK.js.map} +1 -1
  18. package/dist/{chunk-OWVQVAOY.mjs → chunk-OLT7P7JO.mjs} +3 -3
  19. package/dist/{chunk-OWVQVAOY.mjs.map → chunk-OLT7P7JO.mjs.map} +1 -1
  20. package/dist/chunk-PAISX7YL.js +38 -0
  21. package/dist/chunk-PAISX7YL.js.map +1 -0
  22. package/dist/{chunk-4PAHLHYF.mjs → chunk-VN7FE5RR.mjs} +3 -3
  23. package/dist/{chunk-4PAHLHYF.mjs.map → chunk-VN7FE5RR.mjs.map} +1 -1
  24. package/dist/design-system/code-diff.d.ts +18 -0
  25. package/dist/design-system/code-diff.d.ts.map +1 -0
  26. package/dist/design-system/facade.js +7 -6
  27. package/dist/design-system/facade.js.map +1 -1
  28. package/dist/design-system/facade.mjs +6 -5
  29. package/dist/design-system/facade.mjs.map +1 -1
  30. package/dist/design-system/index.d.ts +1 -0
  31. package/dist/design-system/index.d.ts.map +1 -1
  32. package/dist/ui/buttons/animated.js +9 -8
  33. package/dist/ui/buttons/animated.js.map +1 -1
  34. package/dist/ui/buttons/animated.mjs +7 -6
  35. package/dist/ui/buttons/animated.mjs.map +1 -1
  36. package/dist/ui/buttons.js +10 -9
  37. package/dist/ui/buttons.mjs +8 -7
  38. package/dist/ui/code-diff/code-diff-base.d.ts +6 -0
  39. package/dist/ui/code-diff/code-diff-base.d.ts.map +1 -0
  40. package/dist/ui/code-diff/code-diff.d.ts +6 -0
  41. package/dist/ui/code-diff/code-diff.d.ts.map +1 -0
  42. package/dist/ui/code-diff/index.d.ts +4 -0
  43. package/dist/ui/code-diff/index.d.ts.map +1 -0
  44. package/dist/ui/code-diff/types.d.ts +26 -0
  45. package/dist/ui/code-diff/types.d.ts.map +1 -0
  46. package/dist/ui/code-diff/variants.d.ts +11 -0
  47. package/dist/ui/code-diff/variants.d.ts.map +1 -0
  48. package/dist/ui/code-diff.js +302 -0
  49. package/dist/ui/code-diff.js.map +1 -0
  50. package/dist/ui/code-diff.mjs +297 -0
  51. package/dist/ui/code-diff.mjs.map +1 -0
  52. package/dist/ui/data-table.js +21 -20
  53. package/dist/ui/data-table.js.map +1 -1
  54. package/dist/ui/data-table.mjs +11 -10
  55. package/dist/ui/data-table.mjs.map +1 -1
  56. package/dist/ui/dynamic-stepper.js +19 -18
  57. package/dist/ui/dynamic-stepper.js.map +1 -1
  58. package/dist/ui/dynamic-stepper.mjs +8 -7
  59. package/dist/ui/dynamic-stepper.mjs.map +1 -1
  60. package/dist/ui/pagination.js +11 -10
  61. package/dist/ui/pagination.mjs +8 -7
  62. package/dist/ui/split-button.js +21 -20
  63. package/dist/ui/split-button.js.map +1 -1
  64. package/dist/ui/split-button.mjs +8 -7
  65. package/dist/ui/split-button.mjs.map +1 -1
  66. package/package.json +4 -1
  67. package/src/design-system/code-diff.ts +37 -0
  68. package/src/design-system/index.ts +1 -0
  69. package/src/ui/code-diff/code-diff-base.tsx +284 -0
  70. package/src/ui/code-diff/code-diff.test.tsx +50 -0
  71. package/src/ui/code-diff/code-diff.tsx +8 -0
  72. package/src/ui/code-diff/index.ts +15 -0
  73. package/src/ui/code-diff/types.ts +31 -0
  74. package/src/ui/code-diff/variants.ts +49 -0
  75. package/dist/chunk-6OVDBAMI.js +0 -19
  76. package/dist/chunk-DPNTQ4AK.js.map +0 -1
  77. package/dist/chunk-UVP3MUBU.mjs.map +0 -1
@@ -0,0 +1,302 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var chunkPAISX7YL_js = require('../chunk-PAISX7YL.js');
5
+ var chunkZS5756ZC_js = require('../chunk-ZS5756ZC.js');
6
+ require('../chunk-PZ5AY32C.js');
7
+ var diff = require('diff');
8
+ var react = require('react');
9
+ var classVarianceAuthority = require('class-variance-authority');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ var codeDiffVariants = classVarianceAuthority.cva(chunkPAISX7YL_js.zuiCodeDiffBase, {
13
+ variants: {
14
+ appearance: chunkPAISX7YL_js.zuiCodeDiffAppearances,
15
+ size: chunkPAISX7YL_js.zuiCodeDiffSizes
16
+ },
17
+ defaultVariants: {
18
+ appearance: "default",
19
+ size: "md"
20
+ }
21
+ });
22
+ var codeDiffLineNumberVariants = classVarianceAuthority.cva(chunkPAISX7YL_js.zuiCodeDiffLineNumberBase, {
23
+ variants: {
24
+ type: {
25
+ added: chunkPAISX7YL_js.zuiCodeDiffLineAdded,
26
+ removed: chunkPAISX7YL_js.zuiCodeDiffLineRemoved,
27
+ unchanged: chunkPAISX7YL_js.zuiCodeDiffLineUnchanged
28
+ }
29
+ },
30
+ defaultVariants: {
31
+ type: "unchanged"
32
+ }
33
+ });
34
+ var codeDiffLineContentVariants = classVarianceAuthority.cva(chunkPAISX7YL_js.zuiCodeDiffLineContentBase, {
35
+ variants: {
36
+ type: {
37
+ added: chunkPAISX7YL_js.zuiCodeDiffLineAdded,
38
+ removed: chunkPAISX7YL_js.zuiCodeDiffLineRemoved,
39
+ unchanged: chunkPAISX7YL_js.zuiCodeDiffLineUnchanged
40
+ }
41
+ },
42
+ defaultVariants: {
43
+ type: "unchanged"
44
+ }
45
+ });
46
+ function computeDiff(oldCode, newCode) {
47
+ const changes = diff.diffLines(oldCode, newCode);
48
+ const lines = [];
49
+ let oldLineNum = 1;
50
+ let newLineNum = 1;
51
+ for (const change of changes) {
52
+ const changeLines = change.value.replace(/\n$/, "").split("\n");
53
+ for (const content of changeLines) {
54
+ if (change.added) {
55
+ lines.push({
56
+ type: "added",
57
+ content,
58
+ oldLineNumber: null,
59
+ newLineNumber: newLineNum++
60
+ });
61
+ } else if (change.removed) {
62
+ lines.push({
63
+ type: "removed",
64
+ content,
65
+ oldLineNumber: oldLineNum++,
66
+ newLineNumber: null
67
+ });
68
+ } else {
69
+ lines.push({
70
+ type: "unchanged",
71
+ content,
72
+ oldLineNumber: oldLineNum++,
73
+ newLineNumber: newLineNum++
74
+ });
75
+ }
76
+ }
77
+ }
78
+ return lines;
79
+ }
80
+ function toSplitRows(lines) {
81
+ const rows = [];
82
+ let i = 0;
83
+ while (i < lines.length) {
84
+ const current = lines[i];
85
+ if (current.type === "unchanged") {
86
+ rows.push({ oldLine: current, newLine: current });
87
+ i++;
88
+ } else if (current.type === "removed") {
89
+ const removedBlock = [];
90
+ while (i < lines.length && lines[i].type === "removed") {
91
+ removedBlock.push(lines[i]);
92
+ i++;
93
+ }
94
+ const addedBlock = [];
95
+ while (i < lines.length && lines[i].type === "added") {
96
+ addedBlock.push(lines[i]);
97
+ i++;
98
+ }
99
+ const maxLen = Math.max(removedBlock.length, addedBlock.length);
100
+ for (let j = 0; j < maxLen; j++) {
101
+ rows.push({
102
+ oldLine: j < removedBlock.length ? removedBlock[j] : null,
103
+ newLine: j < addedBlock.length ? addedBlock[j] : null
104
+ });
105
+ }
106
+ } else if (current.type === "added") {
107
+ const addedBlock = [];
108
+ while (i < lines.length && lines[i].type === "added") {
109
+ addedBlock.push(lines[i]);
110
+ i++;
111
+ }
112
+ for (const added of addedBlock) {
113
+ rows.push({ oldLine: null, newLine: added });
114
+ }
115
+ } else {
116
+ i++;
117
+ }
118
+ }
119
+ return rows;
120
+ }
121
+ function LineNumberCell({
122
+ lineNumber,
123
+ type,
124
+ showLineNumbers
125
+ }) {
126
+ return /* @__PURE__ */ jsxRuntime.jsx(
127
+ "td",
128
+ {
129
+ className: codeDiffLineNumberVariants({ type }),
130
+ style: { width: showLineNumbers ? "4.5rem" : "2rem" },
131
+ children: showLineNumbers && lineNumber !== null ? lineNumber : ""
132
+ }
133
+ );
134
+ }
135
+ function LineContentCell({
136
+ line,
137
+ type,
138
+ showGutterMarkers
139
+ }) {
140
+ return /* @__PURE__ */ jsxRuntime.jsxs("td", { className: codeDiffLineContentVariants({ type }), children: [
141
+ showGutterMarkers ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-block w-4 select-none text-center", children: type === "added" ? "+" : type === "removed" ? "-" : " " }) : null,
142
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: line || " " })
143
+ ] });
144
+ }
145
+ function UnifiedView({
146
+ lines,
147
+ showLineNumbers,
148
+ showGutterMarkers
149
+ }) {
150
+ return /* @__PURE__ */ jsxRuntime.jsx("table", { className: "w-full border-collapse table-fixed", children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: lines.map((line, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
151
+ /* @__PURE__ */ jsxRuntime.jsx(
152
+ LineNumberCell,
153
+ {
154
+ lineNumber: line.oldLineNumber,
155
+ type: line.type,
156
+ showLineNumbers
157
+ }
158
+ ),
159
+ /* @__PURE__ */ jsxRuntime.jsx(
160
+ LineNumberCell,
161
+ {
162
+ lineNumber: line.newLineNumber,
163
+ type: line.type,
164
+ showLineNumbers
165
+ }
166
+ ),
167
+ /* @__PURE__ */ jsxRuntime.jsx(
168
+ LineContentCell,
169
+ {
170
+ line: line.content,
171
+ type: line.type,
172
+ showGutterMarkers
173
+ }
174
+ )
175
+ ] }, idx)) }) });
176
+ }
177
+ function SplitView({
178
+ lines,
179
+ showLineNumbers,
180
+ showGutterMarkers
181
+ }) {
182
+ const rows = toSplitRows(lines);
183
+ return /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full border-collapse table-fixed", children: [
184
+ /* @__PURE__ */ jsxRuntime.jsxs("colgroup", { children: [
185
+ /* @__PURE__ */ jsxRuntime.jsx("col", { style: { width: showLineNumbers ? "4.5rem" : "2rem" } }),
186
+ /* @__PURE__ */ jsxRuntime.jsx("col", {}),
187
+ /* @__PURE__ */ jsxRuntime.jsx("col", { style: { width: showLineNumbers ? "4.5rem" : "2rem" } }),
188
+ /* @__PURE__ */ jsxRuntime.jsx("col", {})
189
+ ] }),
190
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.map((row, idx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
191
+ /* @__PURE__ */ jsxRuntime.jsx(
192
+ LineNumberCell,
193
+ {
194
+ lineNumber: row.oldLine?.oldLineNumber ?? null,
195
+ type: row.oldLine?.type ?? "unchanged",
196
+ showLineNumbers
197
+ }
198
+ ),
199
+ /* @__PURE__ */ jsxRuntime.jsx(
200
+ LineContentCell,
201
+ {
202
+ line: row.oldLine?.content ?? "",
203
+ type: row.oldLine?.type ?? "unchanged",
204
+ showGutterMarkers
205
+ }
206
+ ),
207
+ /* @__PURE__ */ jsxRuntime.jsx(
208
+ LineNumberCell,
209
+ {
210
+ lineNumber: row.newLine?.newLineNumber ?? null,
211
+ type: row.newLine?.type ?? "unchanged",
212
+ showLineNumbers
213
+ }
214
+ ),
215
+ /* @__PURE__ */ jsxRuntime.jsx(
216
+ LineContentCell,
217
+ {
218
+ line: row.newLine?.content ?? "",
219
+ type: row.newLine?.type ?? "unchanged",
220
+ showGutterMarkers
221
+ }
222
+ )
223
+ ] }, idx)) })
224
+ ] });
225
+ }
226
+ function CodeDiffBase({
227
+ className,
228
+ appearance,
229
+ size,
230
+ oldCode,
231
+ newCode,
232
+ viewType = "unified",
233
+ showLineNumbers = true,
234
+ showGutterMarkers = true,
235
+ oldTitle = "Old",
236
+ newTitle = "New",
237
+ ref,
238
+ as: Wrapper = "div",
239
+ ...rest
240
+ }) {
241
+ const lines = react.useMemo(
242
+ () => computeDiff(oldCode ?? "", newCode ?? ""),
243
+ [oldCode, newCode]
244
+ );
245
+ const hasChanges = lines.some(
246
+ (l) => l.type === "added" || l.type === "removed"
247
+ );
248
+ return /* @__PURE__ */ jsxRuntime.jsxs(
249
+ Wrapper,
250
+ {
251
+ ref,
252
+ "data-slot": "code-diff",
253
+ className: chunkZS5756ZC_js.cn(codeDiffVariants({ appearance, size }), className),
254
+ ...rest,
255
+ children: [
256
+ hasChanges ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "sticky top-0 flex items-center justify-between border-b border-[color:var(--zui-code-diff-border,var(--zui-border,#0000001a))] dark:border-[color:var(--zui-code-diff-border-dark,var(--zui-border-dark,#ffffff1a))] bg-[var(--zui-code-diff-header-bg,var(--zui-surface-muted,oklch(92.9%_0.013_255.508)))] dark:bg-[var(--zui-code-diff-header-bg-dark,var(--zui-surface-muted-dark,oklch(27.9%_0.041_260.031)))] px-4 py-2", children: [
257
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs font-medium", children: [
258
+ lines.filter((l) => l.type === "added").length,
259
+ " additions",
260
+ " ",
261
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mx-1", children: "\u2022" }),
262
+ " ",
263
+ lines.filter((l) => l.type === "removed").length,
264
+ " deletions"
265
+ ] }),
266
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-[color:var(--zui-code-diff-header-fg,var(--zui-fg-muted,oklch(55.2%_0.046_257.417)))] dark:text-[color:var(--zui-code-diff-header-fg-dark,var(--zui-fg-muted-dark,oklch(70.8%_0.015_256.243)))]", children: [
267
+ oldTitle,
268
+ " \u2192 ",
269
+ newTitle
270
+ ] })
271
+ ] }) : null,
272
+ viewType === "split" ? /* @__PURE__ */ jsxRuntime.jsx(
273
+ SplitView,
274
+ {
275
+ lines,
276
+ showLineNumbers,
277
+ showGutterMarkers
278
+ }
279
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
280
+ UnifiedView,
281
+ {
282
+ lines,
283
+ showLineNumbers,
284
+ showGutterMarkers
285
+ }
286
+ )
287
+ ]
288
+ }
289
+ );
290
+ }
291
+ CodeDiffBase.displayName = "CodeDiff";
292
+ function CodeDiff(props) {
293
+ return /* @__PURE__ */ jsxRuntime.jsx(CodeDiffBase, { ...props });
294
+ }
295
+ CodeDiff.displayName = "CodeDiff";
296
+
297
+ exports.CodeDiff = CodeDiff;
298
+ exports.codeDiffLineContentVariants = codeDiffLineContentVariants;
299
+ exports.codeDiffLineNumberVariants = codeDiffLineNumberVariants;
300
+ exports.codeDiffVariants = codeDiffVariants;
301
+ //# sourceMappingURL=code-diff.js.map
302
+ //# sourceMappingURL=code-diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ui/code-diff/variants.ts","../../src/ui/code-diff/code-diff-base.tsx","../../src/ui/code-diff/code-diff.tsx"],"names":["cva","zuiCodeDiffBase","zuiCodeDiffAppearances","zuiCodeDiffSizes","zuiCodeDiffLineNumberBase","zuiCodeDiffLineAdded","zuiCodeDiffLineRemoved","zuiCodeDiffLineUnchanged","zuiCodeDiffLineContentBase","diffLines","jsx","jsxs","useMemo","cn"],"mappings":";;;;;;;;;;AAaO,IAAM,gBAAA,GAAmBA,2BAAIC,gCAAA,EAAiB;AAAA,EACnD,QAAA,EAAU;AAAA,IACR,UAAA,EAAYC,uCAAA;AAAA,IACZ,IAAA,EAAMC;AAA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A;AAAA;AACF;AAAA;AAAA,GAEJ;AAEJ;AAEA,YAAA,CAAa,WAAA,GAAc,UAAA;ACxRpB,SAAS,SAAS,KAAA,EAAsB;AAC7C,EAAA,uBAAOA,cAAAA,CAAC,YAAA,EAAA,EAAc,GAAG,KAAA,EAAO,CAAA;AAClC;AAEA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"code-diff.js","sourcesContent":["import { cva } from \"class-variance-authority\";\n\nimport {\n zuiCodeDiffAppearances,\n zuiCodeDiffBase,\n zuiCodeDiffLineAdded,\n zuiCodeDiffLineContentBase,\n zuiCodeDiffLineNumberBase,\n zuiCodeDiffLineRemoved,\n zuiCodeDiffLineUnchanged,\n zuiCodeDiffSizes,\n} from \"../../design-system/code-diff\";\n\nexport const codeDiffVariants = cva(zuiCodeDiffBase, {\n variants: {\n appearance: zuiCodeDiffAppearances,\n size: zuiCodeDiffSizes,\n },\n defaultVariants: {\n appearance: \"default\",\n size: \"md\",\n },\n});\n\nexport const codeDiffLineNumberVariants = cva(zuiCodeDiffLineNumberBase, {\n variants: {\n type: {\n added: zuiCodeDiffLineAdded,\n removed: zuiCodeDiffLineRemoved,\n unchanged: zuiCodeDiffLineUnchanged,\n },\n },\n defaultVariants: {\n type: \"unchanged\",\n },\n});\n\nexport const codeDiffLineContentVariants = cva(zuiCodeDiffLineContentBase, {\n variants: {\n type: {\n added: zuiCodeDiffLineAdded,\n removed: zuiCodeDiffLineRemoved,\n unchanged: zuiCodeDiffLineUnchanged,\n },\n },\n defaultVariants: {\n type: \"unchanged\",\n },\n});\n","\"use client\";\n\nimport { diffLines } from \"diff\";\nimport { useMemo } from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nimport type { CodeDiffBaseProps, DiffLine } from \"./types\";\nimport {\n codeDiffLineContentVariants,\n codeDiffLineNumberVariants,\n codeDiffVariants,\n} from \"./variants\";\n\nfunction computeDiff(oldCode: string, newCode: string): DiffLine[] {\n const changes = diffLines(oldCode, newCode);\n const lines: DiffLine[] = [];\n let oldLineNum = 1;\n let newLineNum = 1;\n\n for (const change of changes) {\n const changeLines = change.value.replace(/\\n$/, \"\").split(\"\\n\");\n for (const content of changeLines) {\n if (change.added) {\n lines.push({\n type: \"added\",\n content,\n oldLineNumber: null,\n newLineNumber: newLineNum++,\n });\n } else if (change.removed) {\n lines.push({\n type: \"removed\",\n content,\n oldLineNumber: oldLineNum++,\n newLineNumber: null,\n });\n } else {\n lines.push({\n type: \"unchanged\",\n content,\n oldLineNumber: oldLineNum++,\n newLineNumber: newLineNum++,\n });\n }\n }\n }\n return lines;\n}\n\ninterface SplitRow {\n oldLine: DiffLine | null;\n newLine: DiffLine | null;\n}\n\nfunction toSplitRows(lines: DiffLine[]): SplitRow[] {\n const rows: SplitRow[] = [];\n let i = 0;\n\n while (i < lines.length) {\n const current = lines[i]!;\n\n if (current.type === \"unchanged\") {\n rows.push({ oldLine: current, newLine: current });\n i++;\n } else if (current.type === \"removed\") {\n const removedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"removed\") {\n removedBlock.push(lines[i]!);\n i++;\n }\n const addedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"added\") {\n addedBlock.push(lines[i]!);\n i++;\n }\n const maxLen = Math.max(removedBlock.length, addedBlock.length);\n for (let j = 0; j < maxLen; j++) {\n rows.push({\n oldLine: j < removedBlock.length ? removedBlock[j]! : null,\n newLine: j < addedBlock.length ? addedBlock[j]! : null,\n });\n }\n } else if (current.type === \"added\") {\n const addedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"added\") {\n addedBlock.push(lines[i]!);\n i++;\n }\n for (const added of addedBlock) {\n rows.push({ oldLine: null, newLine: added });\n }\n } else {\n i++;\n }\n }\n return rows;\n}\n\nfunction LineNumberCell({\n lineNumber,\n type,\n showLineNumbers,\n}: {\n lineNumber: number | null;\n type: DiffLine[\"type\"];\n showLineNumbers: boolean;\n}) {\n return (\n <td\n className={codeDiffLineNumberVariants({ type })}\n style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }}\n >\n {showLineNumbers && lineNumber !== null ? lineNumber : \"\"}\n </td>\n );\n}\n\nfunction LineContentCell({\n line,\n type,\n showGutterMarkers,\n}: {\n line: string;\n type: DiffLine[\"type\"];\n showGutterMarkers: boolean;\n}) {\n return (\n <td className={codeDiffLineContentVariants({ type })}>\n {showGutterMarkers ? (\n <span className=\"inline-block w-4 select-none text-center\">\n {type === \"added\" ? \"+\" : type === \"removed\" ? \"-\" : \" \"}\n </span>\n ) : null}\n <span>{line || \" \"}</span>\n </td>\n );\n}\n\nfunction UnifiedView({\n lines,\n showLineNumbers,\n showGutterMarkers,\n}: {\n lines: DiffLine[];\n showLineNumbers: boolean;\n showGutterMarkers: boolean;\n}) {\n return (\n <table className=\"w-full border-collapse table-fixed\">\n <tbody>\n {lines.map((line, idx) => (\n <tr key={idx}>\n <LineNumberCell\n lineNumber={line.oldLineNumber}\n type={line.type}\n showLineNumbers={showLineNumbers}\n />\n <LineNumberCell\n lineNumber={line.newLineNumber}\n type={line.type}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={line.content}\n type={line.type}\n showGutterMarkers={showGutterMarkers}\n />\n </tr>\n ))}\n </tbody>\n </table>\n );\n}\n\nfunction SplitView({\n lines,\n showLineNumbers,\n showGutterMarkers,\n}: {\n lines: DiffLine[];\n showLineNumbers: boolean;\n showGutterMarkers: boolean;\n}) {\n const rows = toSplitRows(lines);\n\n return (\n <table className=\"w-full border-collapse table-fixed\">\n <colgroup>\n <col style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }} />\n <col />\n <col style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }} />\n <col />\n </colgroup>\n <tbody>\n {rows.map((row, idx) => (\n <tr key={idx}>\n <LineNumberCell\n lineNumber={row.oldLine?.oldLineNumber ?? null}\n type={row.oldLine?.type ?? \"unchanged\"}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={row.oldLine?.content ?? \"\"}\n type={row.oldLine?.type ?? \"unchanged\"}\n showGutterMarkers={showGutterMarkers}\n />\n <LineNumberCell\n lineNumber={row.newLine?.newLineNumber ?? null}\n type={row.newLine?.type ?? \"unchanged\"}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={row.newLine?.content ?? \"\"}\n type={row.newLine?.type ?? \"unchanged\"}\n showGutterMarkers={showGutterMarkers}\n />\n </tr>\n ))}\n </tbody>\n </table>\n );\n}\n\nexport function CodeDiffBase({\n className,\n appearance,\n size,\n oldCode,\n newCode,\n viewType = \"unified\",\n showLineNumbers = true,\n showGutterMarkers = true,\n oldTitle = \"Old\",\n newTitle = \"New\",\n ref,\n as: Wrapper = \"div\",\n ...rest\n}: CodeDiffBaseProps) {\n const lines = useMemo(\n () => computeDiff(oldCode ?? \"\", newCode ?? \"\"),\n [oldCode, newCode],\n );\n const hasChanges = lines.some(\n (l) => l.type === \"added\" || l.type === \"removed\",\n );\n\n return (\n <Wrapper\n ref={ref}\n data-slot=\"code-diff\"\n className={cn(codeDiffVariants({ appearance, size }), className)}\n {...rest}\n >\n {hasChanges ? (\n <div className=\"sticky top-0 flex items-center justify-between border-b border-[color:var(--zui-code-diff-border,var(--zui-border,#0000001a))] dark:border-[color:var(--zui-code-diff-border-dark,var(--zui-border-dark,#ffffff1a))] bg-[var(--zui-code-diff-header-bg,var(--zui-surface-muted,oklch(92.9%_0.013_255.508)))] dark:bg-[var(--zui-code-diff-header-bg-dark,var(--zui-surface-muted-dark,oklch(27.9%_0.041_260.031)))] px-4 py-2\">\n <span className=\"text-xs font-medium\">\n {lines.filter((l) => l.type === \"added\").length} additions{\" \"}\n <span className=\"mx-1\">&bull;</span>{\" \"}\n {lines.filter((l) => l.type === \"removed\").length} deletions\n </span>\n <span className=\"text-xs text-[color:var(--zui-code-diff-header-fg,var(--zui-fg-muted,oklch(55.2%_0.046_257.417)))] dark:text-[color:var(--zui-code-diff-header-fg-dark,var(--zui-fg-muted-dark,oklch(70.8%_0.015_256.243)))]\">\n {oldTitle} &rarr; {newTitle}\n </span>\n </div>\n ) : null}\n {viewType === \"split\" ? (\n <SplitView\n lines={lines}\n showLineNumbers={showLineNumbers}\n showGutterMarkers={showGutterMarkers}\n />\n ) : (\n <UnifiedView\n lines={lines}\n showLineNumbers={showLineNumbers}\n showGutterMarkers={showGutterMarkers}\n />\n )}\n </Wrapper>\n );\n}\n\nCodeDiffBase.displayName = \"CodeDiff\";\n","import { CodeDiffBase } from \"./code-diff-base\";\nimport type { CodeDiffProps } from \"./types\";\n\nexport function CodeDiff(props: CodeDiffProps) {\n return <CodeDiffBase {...props} />;\n}\n\nCodeDiff.displayName = \"CodeDiff\";\n"]}
@@ -0,0 +1,297 @@
1
+ "use client";
2
+ import { zuiCodeDiffBase, zuiCodeDiffSizes, zuiCodeDiffAppearances, zuiCodeDiffLineNumberBase, zuiCodeDiffLineUnchanged, zuiCodeDiffLineRemoved, zuiCodeDiffLineAdded, zuiCodeDiffLineContentBase } from '../chunk-GP3FUS2H.mjs';
3
+ import { cn } from '../chunk-4D54YOL6.mjs';
4
+ import '../chunk-J5LGTIGS.mjs';
5
+ import { diffLines } from 'diff';
6
+ import { useMemo } from 'react';
7
+ import { cva } from 'class-variance-authority';
8
+ import { jsx, jsxs } from 'react/jsx-runtime';
9
+
10
+ var codeDiffVariants = cva(zuiCodeDiffBase, {
11
+ variants: {
12
+ appearance: zuiCodeDiffAppearances,
13
+ size: zuiCodeDiffSizes
14
+ },
15
+ defaultVariants: {
16
+ appearance: "default",
17
+ size: "md"
18
+ }
19
+ });
20
+ var codeDiffLineNumberVariants = cva(zuiCodeDiffLineNumberBase, {
21
+ variants: {
22
+ type: {
23
+ added: zuiCodeDiffLineAdded,
24
+ removed: zuiCodeDiffLineRemoved,
25
+ unchanged: zuiCodeDiffLineUnchanged
26
+ }
27
+ },
28
+ defaultVariants: {
29
+ type: "unchanged"
30
+ }
31
+ });
32
+ var codeDiffLineContentVariants = cva(zuiCodeDiffLineContentBase, {
33
+ variants: {
34
+ type: {
35
+ added: zuiCodeDiffLineAdded,
36
+ removed: zuiCodeDiffLineRemoved,
37
+ unchanged: zuiCodeDiffLineUnchanged
38
+ }
39
+ },
40
+ defaultVariants: {
41
+ type: "unchanged"
42
+ }
43
+ });
44
+ function computeDiff(oldCode, newCode) {
45
+ const changes = diffLines(oldCode, newCode);
46
+ const lines = [];
47
+ let oldLineNum = 1;
48
+ let newLineNum = 1;
49
+ for (const change of changes) {
50
+ const changeLines = change.value.replace(/\n$/, "").split("\n");
51
+ for (const content of changeLines) {
52
+ if (change.added) {
53
+ lines.push({
54
+ type: "added",
55
+ content,
56
+ oldLineNumber: null,
57
+ newLineNumber: newLineNum++
58
+ });
59
+ } else if (change.removed) {
60
+ lines.push({
61
+ type: "removed",
62
+ content,
63
+ oldLineNumber: oldLineNum++,
64
+ newLineNumber: null
65
+ });
66
+ } else {
67
+ lines.push({
68
+ type: "unchanged",
69
+ content,
70
+ oldLineNumber: oldLineNum++,
71
+ newLineNumber: newLineNum++
72
+ });
73
+ }
74
+ }
75
+ }
76
+ return lines;
77
+ }
78
+ function toSplitRows(lines) {
79
+ const rows = [];
80
+ let i = 0;
81
+ while (i < lines.length) {
82
+ const current = lines[i];
83
+ if (current.type === "unchanged") {
84
+ rows.push({ oldLine: current, newLine: current });
85
+ i++;
86
+ } else if (current.type === "removed") {
87
+ const removedBlock = [];
88
+ while (i < lines.length && lines[i].type === "removed") {
89
+ removedBlock.push(lines[i]);
90
+ i++;
91
+ }
92
+ const addedBlock = [];
93
+ while (i < lines.length && lines[i].type === "added") {
94
+ addedBlock.push(lines[i]);
95
+ i++;
96
+ }
97
+ const maxLen = Math.max(removedBlock.length, addedBlock.length);
98
+ for (let j = 0; j < maxLen; j++) {
99
+ rows.push({
100
+ oldLine: j < removedBlock.length ? removedBlock[j] : null,
101
+ newLine: j < addedBlock.length ? addedBlock[j] : null
102
+ });
103
+ }
104
+ } else if (current.type === "added") {
105
+ const addedBlock = [];
106
+ while (i < lines.length && lines[i].type === "added") {
107
+ addedBlock.push(lines[i]);
108
+ i++;
109
+ }
110
+ for (const added of addedBlock) {
111
+ rows.push({ oldLine: null, newLine: added });
112
+ }
113
+ } else {
114
+ i++;
115
+ }
116
+ }
117
+ return rows;
118
+ }
119
+ function LineNumberCell({
120
+ lineNumber,
121
+ type,
122
+ showLineNumbers
123
+ }) {
124
+ return /* @__PURE__ */ jsx(
125
+ "td",
126
+ {
127
+ className: codeDiffLineNumberVariants({ type }),
128
+ style: { width: showLineNumbers ? "4.5rem" : "2rem" },
129
+ children: showLineNumbers && lineNumber !== null ? lineNumber : ""
130
+ }
131
+ );
132
+ }
133
+ function LineContentCell({
134
+ line,
135
+ type,
136
+ showGutterMarkers
137
+ }) {
138
+ return /* @__PURE__ */ jsxs("td", { className: codeDiffLineContentVariants({ type }), children: [
139
+ showGutterMarkers ? /* @__PURE__ */ jsx("span", { className: "inline-block w-4 select-none text-center", children: type === "added" ? "+" : type === "removed" ? "-" : " " }) : null,
140
+ /* @__PURE__ */ jsx("span", { children: line || " " })
141
+ ] });
142
+ }
143
+ function UnifiedView({
144
+ lines,
145
+ showLineNumbers,
146
+ showGutterMarkers
147
+ }) {
148
+ return /* @__PURE__ */ jsx("table", { className: "w-full border-collapse table-fixed", children: /* @__PURE__ */ jsx("tbody", { children: lines.map((line, idx) => /* @__PURE__ */ jsxs("tr", { children: [
149
+ /* @__PURE__ */ jsx(
150
+ LineNumberCell,
151
+ {
152
+ lineNumber: line.oldLineNumber,
153
+ type: line.type,
154
+ showLineNumbers
155
+ }
156
+ ),
157
+ /* @__PURE__ */ jsx(
158
+ LineNumberCell,
159
+ {
160
+ lineNumber: line.newLineNumber,
161
+ type: line.type,
162
+ showLineNumbers
163
+ }
164
+ ),
165
+ /* @__PURE__ */ jsx(
166
+ LineContentCell,
167
+ {
168
+ line: line.content,
169
+ type: line.type,
170
+ showGutterMarkers
171
+ }
172
+ )
173
+ ] }, idx)) }) });
174
+ }
175
+ function SplitView({
176
+ lines,
177
+ showLineNumbers,
178
+ showGutterMarkers
179
+ }) {
180
+ const rows = toSplitRows(lines);
181
+ return /* @__PURE__ */ jsxs("table", { className: "w-full border-collapse table-fixed", children: [
182
+ /* @__PURE__ */ jsxs("colgroup", { children: [
183
+ /* @__PURE__ */ jsx("col", { style: { width: showLineNumbers ? "4.5rem" : "2rem" } }),
184
+ /* @__PURE__ */ jsx("col", {}),
185
+ /* @__PURE__ */ jsx("col", { style: { width: showLineNumbers ? "4.5rem" : "2rem" } }),
186
+ /* @__PURE__ */ jsx("col", {})
187
+ ] }),
188
+ /* @__PURE__ */ jsx("tbody", { children: rows.map((row, idx) => /* @__PURE__ */ jsxs("tr", { children: [
189
+ /* @__PURE__ */ jsx(
190
+ LineNumberCell,
191
+ {
192
+ lineNumber: row.oldLine?.oldLineNumber ?? null,
193
+ type: row.oldLine?.type ?? "unchanged",
194
+ showLineNumbers
195
+ }
196
+ ),
197
+ /* @__PURE__ */ jsx(
198
+ LineContentCell,
199
+ {
200
+ line: row.oldLine?.content ?? "",
201
+ type: row.oldLine?.type ?? "unchanged",
202
+ showGutterMarkers
203
+ }
204
+ ),
205
+ /* @__PURE__ */ jsx(
206
+ LineNumberCell,
207
+ {
208
+ lineNumber: row.newLine?.newLineNumber ?? null,
209
+ type: row.newLine?.type ?? "unchanged",
210
+ showLineNumbers
211
+ }
212
+ ),
213
+ /* @__PURE__ */ jsx(
214
+ LineContentCell,
215
+ {
216
+ line: row.newLine?.content ?? "",
217
+ type: row.newLine?.type ?? "unchanged",
218
+ showGutterMarkers
219
+ }
220
+ )
221
+ ] }, idx)) })
222
+ ] });
223
+ }
224
+ function CodeDiffBase({
225
+ className,
226
+ appearance,
227
+ size,
228
+ oldCode,
229
+ newCode,
230
+ viewType = "unified",
231
+ showLineNumbers = true,
232
+ showGutterMarkers = true,
233
+ oldTitle = "Old",
234
+ newTitle = "New",
235
+ ref,
236
+ as: Wrapper = "div",
237
+ ...rest
238
+ }) {
239
+ const lines = useMemo(
240
+ () => computeDiff(oldCode ?? "", newCode ?? ""),
241
+ [oldCode, newCode]
242
+ );
243
+ const hasChanges = lines.some(
244
+ (l) => l.type === "added" || l.type === "removed"
245
+ );
246
+ return /* @__PURE__ */ jsxs(
247
+ Wrapper,
248
+ {
249
+ ref,
250
+ "data-slot": "code-diff",
251
+ className: cn(codeDiffVariants({ appearance, size }), className),
252
+ ...rest,
253
+ children: [
254
+ hasChanges ? /* @__PURE__ */ jsxs("div", { className: "sticky top-0 flex items-center justify-between border-b border-[color:var(--zui-code-diff-border,var(--zui-border,#0000001a))] dark:border-[color:var(--zui-code-diff-border-dark,var(--zui-border-dark,#ffffff1a))] bg-[var(--zui-code-diff-header-bg,var(--zui-surface-muted,oklch(92.9%_0.013_255.508)))] dark:bg-[var(--zui-code-diff-header-bg-dark,var(--zui-surface-muted-dark,oklch(27.9%_0.041_260.031)))] px-4 py-2", children: [
255
+ /* @__PURE__ */ jsxs("span", { className: "text-xs font-medium", children: [
256
+ lines.filter((l) => l.type === "added").length,
257
+ " additions",
258
+ " ",
259
+ /* @__PURE__ */ jsx("span", { className: "mx-1", children: "\u2022" }),
260
+ " ",
261
+ lines.filter((l) => l.type === "removed").length,
262
+ " deletions"
263
+ ] }),
264
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-[color:var(--zui-code-diff-header-fg,var(--zui-fg-muted,oklch(55.2%_0.046_257.417)))] dark:text-[color:var(--zui-code-diff-header-fg-dark,var(--zui-fg-muted-dark,oklch(70.8%_0.015_256.243)))]", children: [
265
+ oldTitle,
266
+ " \u2192 ",
267
+ newTitle
268
+ ] })
269
+ ] }) : null,
270
+ viewType === "split" ? /* @__PURE__ */ jsx(
271
+ SplitView,
272
+ {
273
+ lines,
274
+ showLineNumbers,
275
+ showGutterMarkers
276
+ }
277
+ ) : /* @__PURE__ */ jsx(
278
+ UnifiedView,
279
+ {
280
+ lines,
281
+ showLineNumbers,
282
+ showGutterMarkers
283
+ }
284
+ )
285
+ ]
286
+ }
287
+ );
288
+ }
289
+ CodeDiffBase.displayName = "CodeDiff";
290
+ function CodeDiff(props) {
291
+ return /* @__PURE__ */ jsx(CodeDiffBase, { ...props });
292
+ }
293
+ CodeDiff.displayName = "CodeDiff";
294
+
295
+ export { CodeDiff, codeDiffLineContentVariants, codeDiffLineNumberVariants, codeDiffVariants };
296
+ //# sourceMappingURL=code-diff.mjs.map
297
+ //# sourceMappingURL=code-diff.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ui/code-diff/variants.ts","../../src/ui/code-diff/code-diff-base.tsx","../../src/ui/code-diff/code-diff.tsx"],"names":["jsx"],"mappings":";;;;;;;;AAaO,IAAM,gBAAA,GAAmB,IAAI,eAAA,EAAiB;AAAA,EACnD,QAAA,EAAU;AAAA,IACR,UAAA,EAAY,sBAAA;AAAA,IACZ,IAAA,EAAM;AAAA,GACR;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,UAAA,EAAY,SAAA;AAAA,IACZ,IAAA,EAAM;AAAA;AAEV,CAAC;AAEM,IAAM,0BAAA,GAA6B,IAAI,yBAAA,EAA2B;AAAA,EACvE,QAAA,EAAU;AAAA,IACR,IAAA,EAAM;AAAA,MACJ,KAAA,EAAO,oBAAA;AAAA,MACP,OAAA,EAAS,sBAAA;AAAA,MACT,SAAA,EAAW;AAAA;AACb,GACF;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,IAAA,EAAM;AAAA;AAEV,CAAC;AAEM,IAAM,2BAAA,GAA8B,IAAI,0BAAA,EAA4B;AAAA,EACzE,QAAA,EAAU;AAAA,IACR,IAAA,EAAM;AAAA,MACJ,KAAA,EAAO,oBAAA;AAAA,MACP,OAAA,EAAS,sBAAA;AAAA,MACT,SAAA,EAAW;AAAA;AACb,GACF;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,IAAA,EAAM;AAAA;AAEV,CAAC;AClCD,SAAS,WAAA,CAAY,SAAiB,OAAA,EAA6B;AACjE,EAAA,MAAM,OAAA,GAAU,SAAA,CAAU,OA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CAAA,CAAE,IAAA,KAAS,SAAS,CAAA,CAAE,MAAA;AAAA,YAAO;AAAA,WAAA,EACpD,CAAA;AAAA,0BACA,IAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,8MAAA,EACb,QAAA,EAAA;AAAA,YAAA,QAAA;AAAA,YAAS,UAAA;AAAA,YAAS;AAAA,WAAA,EACrB;AAAA,SAAA,EACF,CAAA,GACE,IAAA;AAAA,QACH,aAAa,OAAA,mBACZ,GAAA;AAAA,UAAC,SAAA;AAAA,UAAA;AAAA,YACC,KAAA;AAAA,YACA,eAAA;AAAA,YACA;AAAA;AAAA,SACF,mBAEA,GAAA;AAAA,UAAC,WAAA;AAAA,UAAA;AAAA,YACC,KAAA;AAAA,YACA,eAAA;AAAA,YACA;AAAA;AAAA;AACF;AAAA;AAAA,GAEJ;AAEJ;AAEA,YAAA,CAAa,WAAA,GAAc,UAAA;ACxRpB,SAAS,SAAS,KAAA,EAAsB;AAC7C,EAAA,uBAAOA,GAAAA,CAAC,YAAA,EAAA,EAAc,GAAG,KAAA,EAAO,CAAA;AAClC;AAEA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"code-diff.mjs","sourcesContent":["import { cva } from \"class-variance-authority\";\n\nimport {\n zuiCodeDiffAppearances,\n zuiCodeDiffBase,\n zuiCodeDiffLineAdded,\n zuiCodeDiffLineContentBase,\n zuiCodeDiffLineNumberBase,\n zuiCodeDiffLineRemoved,\n zuiCodeDiffLineUnchanged,\n zuiCodeDiffSizes,\n} from \"../../design-system/code-diff\";\n\nexport const codeDiffVariants = cva(zuiCodeDiffBase, {\n variants: {\n appearance: zuiCodeDiffAppearances,\n size: zuiCodeDiffSizes,\n },\n defaultVariants: {\n appearance: \"default\",\n size: \"md\",\n },\n});\n\nexport const codeDiffLineNumberVariants = cva(zuiCodeDiffLineNumberBase, {\n variants: {\n type: {\n added: zuiCodeDiffLineAdded,\n removed: zuiCodeDiffLineRemoved,\n unchanged: zuiCodeDiffLineUnchanged,\n },\n },\n defaultVariants: {\n type: \"unchanged\",\n },\n});\n\nexport const codeDiffLineContentVariants = cva(zuiCodeDiffLineContentBase, {\n variants: {\n type: {\n added: zuiCodeDiffLineAdded,\n removed: zuiCodeDiffLineRemoved,\n unchanged: zuiCodeDiffLineUnchanged,\n },\n },\n defaultVariants: {\n type: \"unchanged\",\n },\n});\n","\"use client\";\n\nimport { diffLines } from \"diff\";\nimport { useMemo } from \"react\";\n\nimport { cn } from \"../../lib/utils\";\n\nimport type { CodeDiffBaseProps, DiffLine } from \"./types\";\nimport {\n codeDiffLineContentVariants,\n codeDiffLineNumberVariants,\n codeDiffVariants,\n} from \"./variants\";\n\nfunction computeDiff(oldCode: string, newCode: string): DiffLine[] {\n const changes = diffLines(oldCode, newCode);\n const lines: DiffLine[] = [];\n let oldLineNum = 1;\n let newLineNum = 1;\n\n for (const change of changes) {\n const changeLines = change.value.replace(/\\n$/, \"\").split(\"\\n\");\n for (const content of changeLines) {\n if (change.added) {\n lines.push({\n type: \"added\",\n content,\n oldLineNumber: null,\n newLineNumber: newLineNum++,\n });\n } else if (change.removed) {\n lines.push({\n type: \"removed\",\n content,\n oldLineNumber: oldLineNum++,\n newLineNumber: null,\n });\n } else {\n lines.push({\n type: \"unchanged\",\n content,\n oldLineNumber: oldLineNum++,\n newLineNumber: newLineNum++,\n });\n }\n }\n }\n return lines;\n}\n\ninterface SplitRow {\n oldLine: DiffLine | null;\n newLine: DiffLine | null;\n}\n\nfunction toSplitRows(lines: DiffLine[]): SplitRow[] {\n const rows: SplitRow[] = [];\n let i = 0;\n\n while (i < lines.length) {\n const current = lines[i]!;\n\n if (current.type === \"unchanged\") {\n rows.push({ oldLine: current, newLine: current });\n i++;\n } else if (current.type === \"removed\") {\n const removedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"removed\") {\n removedBlock.push(lines[i]!);\n i++;\n }\n const addedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"added\") {\n addedBlock.push(lines[i]!);\n i++;\n }\n const maxLen = Math.max(removedBlock.length, addedBlock.length);\n for (let j = 0; j < maxLen; j++) {\n rows.push({\n oldLine: j < removedBlock.length ? removedBlock[j]! : null,\n newLine: j < addedBlock.length ? addedBlock[j]! : null,\n });\n }\n } else if (current.type === \"added\") {\n const addedBlock: DiffLine[] = [];\n while (i < lines.length && lines[i]!.type === \"added\") {\n addedBlock.push(lines[i]!);\n i++;\n }\n for (const added of addedBlock) {\n rows.push({ oldLine: null, newLine: added });\n }\n } else {\n i++;\n }\n }\n return rows;\n}\n\nfunction LineNumberCell({\n lineNumber,\n type,\n showLineNumbers,\n}: {\n lineNumber: number | null;\n type: DiffLine[\"type\"];\n showLineNumbers: boolean;\n}) {\n return (\n <td\n className={codeDiffLineNumberVariants({ type })}\n style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }}\n >\n {showLineNumbers && lineNumber !== null ? lineNumber : \"\"}\n </td>\n );\n}\n\nfunction LineContentCell({\n line,\n type,\n showGutterMarkers,\n}: {\n line: string;\n type: DiffLine[\"type\"];\n showGutterMarkers: boolean;\n}) {\n return (\n <td className={codeDiffLineContentVariants({ type })}>\n {showGutterMarkers ? (\n <span className=\"inline-block w-4 select-none text-center\">\n {type === \"added\" ? \"+\" : type === \"removed\" ? \"-\" : \" \"}\n </span>\n ) : null}\n <span>{line || \" \"}</span>\n </td>\n );\n}\n\nfunction UnifiedView({\n lines,\n showLineNumbers,\n showGutterMarkers,\n}: {\n lines: DiffLine[];\n showLineNumbers: boolean;\n showGutterMarkers: boolean;\n}) {\n return (\n <table className=\"w-full border-collapse table-fixed\">\n <tbody>\n {lines.map((line, idx) => (\n <tr key={idx}>\n <LineNumberCell\n lineNumber={line.oldLineNumber}\n type={line.type}\n showLineNumbers={showLineNumbers}\n />\n <LineNumberCell\n lineNumber={line.newLineNumber}\n type={line.type}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={line.content}\n type={line.type}\n showGutterMarkers={showGutterMarkers}\n />\n </tr>\n ))}\n </tbody>\n </table>\n );\n}\n\nfunction SplitView({\n lines,\n showLineNumbers,\n showGutterMarkers,\n}: {\n lines: DiffLine[];\n showLineNumbers: boolean;\n showGutterMarkers: boolean;\n}) {\n const rows = toSplitRows(lines);\n\n return (\n <table className=\"w-full border-collapse table-fixed\">\n <colgroup>\n <col style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }} />\n <col />\n <col style={{ width: showLineNumbers ? \"4.5rem\" : \"2rem\" }} />\n <col />\n </colgroup>\n <tbody>\n {rows.map((row, idx) => (\n <tr key={idx}>\n <LineNumberCell\n lineNumber={row.oldLine?.oldLineNumber ?? null}\n type={row.oldLine?.type ?? \"unchanged\"}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={row.oldLine?.content ?? \"\"}\n type={row.oldLine?.type ?? \"unchanged\"}\n showGutterMarkers={showGutterMarkers}\n />\n <LineNumberCell\n lineNumber={row.newLine?.newLineNumber ?? null}\n type={row.newLine?.type ?? \"unchanged\"}\n showLineNumbers={showLineNumbers}\n />\n <LineContentCell\n line={row.newLine?.content ?? \"\"}\n type={row.newLine?.type ?? \"unchanged\"}\n showGutterMarkers={showGutterMarkers}\n />\n </tr>\n ))}\n </tbody>\n </table>\n );\n}\n\nexport function CodeDiffBase({\n className,\n appearance,\n size,\n oldCode,\n newCode,\n viewType = \"unified\",\n showLineNumbers = true,\n showGutterMarkers = true,\n oldTitle = \"Old\",\n newTitle = \"New\",\n ref,\n as: Wrapper = \"div\",\n ...rest\n}: CodeDiffBaseProps) {\n const lines = useMemo(\n () => computeDiff(oldCode ?? \"\", newCode ?? \"\"),\n [oldCode, newCode],\n );\n const hasChanges = lines.some(\n (l) => l.type === \"added\" || l.type === \"removed\",\n );\n\n return (\n <Wrapper\n ref={ref}\n data-slot=\"code-diff\"\n className={cn(codeDiffVariants({ appearance, size }), className)}\n {...rest}\n >\n {hasChanges ? (\n <div className=\"sticky top-0 flex items-center justify-between border-b border-[color:var(--zui-code-diff-border,var(--zui-border,#0000001a))] dark:border-[color:var(--zui-code-diff-border-dark,var(--zui-border-dark,#ffffff1a))] bg-[var(--zui-code-diff-header-bg,var(--zui-surface-muted,oklch(92.9%_0.013_255.508)))] dark:bg-[var(--zui-code-diff-header-bg-dark,var(--zui-surface-muted-dark,oklch(27.9%_0.041_260.031)))] px-4 py-2\">\n <span className=\"text-xs font-medium\">\n {lines.filter((l) => l.type === \"added\").length} additions{\" \"}\n <span className=\"mx-1\">&bull;</span>{\" \"}\n {lines.filter((l) => l.type === \"removed\").length} deletions\n </span>\n <span className=\"text-xs text-[color:var(--zui-code-diff-header-fg,var(--zui-fg-muted,oklch(55.2%_0.046_257.417)))] dark:text-[color:var(--zui-code-diff-header-fg-dark,var(--zui-fg-muted-dark,oklch(70.8%_0.015_256.243)))]\">\n {oldTitle} &rarr; {newTitle}\n </span>\n </div>\n ) : null}\n {viewType === \"split\" ? (\n <SplitView\n lines={lines}\n showLineNumbers={showLineNumbers}\n showGutterMarkers={showGutterMarkers}\n />\n ) : (\n <UnifiedView\n lines={lines}\n showLineNumbers={showLineNumbers}\n showGutterMarkers={showGutterMarkers}\n />\n )}\n </Wrapper>\n );\n}\n\nCodeDiffBase.displayName = \"CodeDiff\";\n","import { CodeDiffBase } from \"./code-diff-base\";\nimport type { CodeDiffProps } from \"./types\";\n\nexport function CodeDiff(props: CodeDiffProps) {\n return <CodeDiffBase {...props} />;\n}\n\nCodeDiff.displayName = \"CodeDiff\";\n"]}