Skip to content
Eskais UI

Diff

Diff engine

Line diffs with histogram (default, git's most readable for code) or linear-space Myers with a cost cut, git's slider placement, hunks with context and the enclosing-definition heading, whitespace options, binary and size guards; changed words or characters within a line; and diffTextAsync, which runs in a Web Worker past 200k characters. The unified-diff parser and printer is the diff-patch item. No dependencies.

Example

+2 −1
@@ -1,4 +1,5 @@ alpha-beta+beta two gamma delta+epsilon

Installation

npx shadcn@latest add @eskais/diff

The example also uses the diff-patch adapters:

Example adapters
npx shadcn@latest add @eskais/diff-patch

Adapters

Each adapter is an item of its own that brings diff along. Install only the ones your backend needs.

  • Diff Patch

    diff-patch
    npx shadcn@latest add @eskais/diff-patch

Usage

Import
import { createSequenceDiff, sequenceDiff } from "@/lib/diff-sequence"import { createLineDiff, diffFile, diffText, lineDiff, splitLines, toFileDiff } from "@/lib/diff-lines"import { intraline, pairLines } from "@/lib/diff-intraline"import { diffsInWorker, diffTextAsync, WORKER_THRESHOLD } from "@/lib/diff-async"

The diff engine on its own: diffText for line hunks (histogram or Myers, matching git's output), intraline for changed words and diffTextAsync to diff off the main thread. Add the diff-patch adapter for parsePatch, which reads git patches, and formatHunks, which prints hunks back.

API reference

This item exports functions and types rather than components.

Other exports

createSequenceDiffsequenceDiffcreateLineDiffdiffFilediffTextlineDiffsplitLinestoFileDiffintralinepairLinesdiffsInWorkerdiffTextAsyncWORKER_THRESHOLDtype DiffAlgorithmtype DiffHunktype DiffLinetype DiffLineKindtype DiffOptionstype DiffStatustype FileDifftype FileStatustype IgnoreWhitespacetype IntralineModetype IntralineRangestype TextDifftype SequenceAlgorithmtype SequenceDifftype FilePathstype LineDifftype Intralinetype IntralineOptionstype AsyncDiffOptions

Accessibility

  • No interface: render its output with DiffView, TextDiff or GitDiff, or a CodeBlock in diff language.

Agent actions

Not a component; agents act on the views that render it.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.