Diff-viewer HTML generation: syntax-highlighted diffs with CSS classes, as
unified rows or side-by-side cells, composed from @fuzdev/fuz_util's diff
data and the lexer substrate's per-line renderer. The returned HTML is the
rows only — the caller owns the wrapper element (CodeDiff.svelte renders
<div class="code_diff">, with split added for the side-by-side view,
styled by theme_diff.css).
The pipeline is three cacheable stages. A DiffSide is one lexed text,
reusable across any number of diffs (a consumer caches it by content). A
DiffModel is two sides plus their DiffLines, computed by diff_lines
or supplied by the caller, with the pairing of changed lines and their
emphasis worked out lazily, one change at a time. The renderers draw any
DiffRowSource — the narrower surface a model implements — as a range
of rows (render_diff_unified_rows_html, render_diff_split_rows_html)
or the whole document with its unchanged regions elided
(render_diff_model_unified_html, render_diff_model_split_html);
render_diff_unified_html and render_diff_split_html do all three
stages from two strings.
Every row carries its line numbers as data-a / data-b (absent on the
side it lacks) and, inside a hunk, the hunk's index as data-hunk, so a
consumer maps an element to its line by event delegation;
apply_diff_highlight restyles highlighted rows in place.
A diff known only by a patch's hunks renders through
create_diff_patch_source, highlighted approximately — each run of hunks
lexed on its own — with the lines between hunks counted, until the texts
arrive and a DiffModel replaces it.
elide: 'expand' bounds the DOM of a big diff with a way back: elided
regions render as count rows with expand controls, and the lines in
expanded (b line numbers) as rows. render_diff_segments renders the
document in keyed pieces, so a component re-renders only the pieces an
expansion changes.