File Diff
A unified diff viewer with a file top bar, change counts, and highlighted rows.
export function getToken() { return localStorage.token; const t = cookies.get("session"); if (!t) throw new Error("no session"); return t;}Installation
Copy the command below and run it in your terminal.
The component depends on highlight.js. Install it if your project
doesn't have it yet:
Copy the command below and run it in your terminal.
Usage
Pass a diff array for the high-level
form, or compose TopBar, Content, and Row by hand. A bare TopBar renders filename and counts; pass children to take over the row with Filename, PlusMinus, and your own actions. Addition
and deletion counts are derived from the diff unless you pass them explicitly.
Examples
From a single high-level diff to fully composed rows and stacked files.
Compound API
Drop down to rows when you need a custom top-bar action or explicit counts.
Recompose the header from Filename and PlusMinus parts.
export function getToken() { return localStorage.token; const t = cookies.get("session"); if (!t) throw new Error("no session"); return t;}Without line numbers
Hide both gutters for compact embeds. The sign column stays so additions and deletions remain distinguishable without color.
color: var(--color-foreground); background: #f4f4f0; background: var(--color-card); border: 1px solid var(--color-border);Stacked files
Render one Root per file for pull-request style views. Each diff keeps its own language and counts.
export function getToken() { return localStorage.token; const t = cookies.get("session"); if (!t) throw new Error("no session"); return t;} color: var(--color-foreground); background: #f4f4f0; background: var(--color-card); border: 1px solid var(--color-border);Anatomy
FileDiff.Root - Provides diff state and layout.
FileDiff.TopBar - Renders the file path and change counts.
FileDiff.Content - Contains the scrollable diff rows.
FileDiff.Row - Renders one highlighted diff row.
FileDiff.LineNumber - Renders one gutter line number.
bunx @sivir-ui/svelte add file-diff