CodeDiff.svelte

view source

Declarations
#

CodeDiff
#

CodeDiff.svelte view source

accepts children

import CodeDiff from '@fuzdev/fuz_code/CodeDiff.svelte';

a?

The original version of the source.

type string
optional

b?

The updated version of the source.

type string
optional

source?

optional

hunks?

type readonly DiffHunk[]
optional

dangerous_raw_html?

type string
optional

lang?

Language identifier for syntax styling. null or an unregistered id disables styling (rows render as plain text with the diff chrome, and an unregistered id logs an error in DEV); undefined falls back to the default ('svelte'). With source, the data-lang attribute takes the source's language instead (a DiffModel's b side's), absent when it has none. With hunks, it lexes the snippets.

type string | null
optional default 'svelte'

split?

Whether to render the two versions side by side instead of as one unified column. The split view always wraps long lines.

type boolean
optional default false

context_lines?

Unchanged lines of context around changes.

type number
optional default 3

elide?

How elided unchanged regions render — see RenderDiffOptions.elide. With 'expand', each region is a count row whose controls reveal its lines (expand_step at a time, or all), rendering only the rows they reveal; what's revealed is expanded.

type "none" | "details" | "omit" | "expand"
optional default 'details'

intraline?

Whether paired remove/add lines get intra-line emphasis.

type boolean
optional default true

line_numbers?

Whether to render line-number gutters.

type boolean
optional default true

max_cost?

Cost cap for the line diff — see RenderDiffOptions.max_cost.

type number
optional

a_line_count?

With hunks, how many lines the original text has, when known — see DiffPatchSourceOptions.a_line_count. Ignored otherwise, so it can stay set when the full diff replaces the hunks. A count the hunks contradict (one meant for the previous hunks, say, while new ones arrive) is treated as unknown, with an error logged in DEV.

type number | null
optional

b_line_count?

With hunks, how many lines the updated text has, when known — it counts the unchanged lines after the last hunk, rendered as unchanged lines without a number otherwise. As a_line_count.

type number | null
optional

patch_context?

With hunks, the context the patch was made with (git diff -U3 is 3), which proves where a file ends when its last change is near the end — see DiffPatchSourceOptions.patch_context. Ignored without hunks.

type number | null
optional

highlight?

Lines whose rows get the diff_highlight class — see RenderDiffRowsOptions.highlight. A change toggles classes on the rendered rows rather than re-rendering them.

optional

expanded?

With elide: 'expand', the unchanged lines shown as rows: b line ranges (see DiffExpandedRange). Internal state unless bound — bind:expanded lets a consumer persist and restore it. An expansion writes it normalized and clamped to the current diff's elided regions; a value set from outside renders clamped and stays as set, so a new source of the same diff (or one holding more of its lines) shows the same lines.

optional bindable

expand_step?

With elide: 'expand', how many lines an expand-up or expand-down control reveals — see RenderDiffModelOptions.expand_step.

type number
optional default DIFF_EXPAND_STEP

wrap?

Whether to wrap long lines in the unified view (pre-wrap instead of pre, breaking a long unbroken token where it would overflow). The split view wraps regardless.

type boolean
optional default false

nomargin?

Whether to disable the default margin-bottom.

type boolean
optional default false

syntax_styler?

Custom SyntaxStyler instance.

optional default syntax_styler_global

children?

Optional snippet to customize how the diff rows are rendered. Receives the generated HTML string as a parameter.

type Snippet<[]> & Snippet<[markup: string]>
optional

external types

SvelteHTMLElements['div']

Depends on
#