Examples
Every card below is a working scenario in the playground, backed by the public controller API. Pick one, edit the source, and inspect the result.
Guarded API callAdd input validation and a typed error path, then accept or reject the hunk.
playground?sample=invoiceReact data hookShow cancellation, loading state, and a cleanup path in a word-level diff.playground?sample=hookCursor paginationReplace page offsets with a cursor, including a guard against repeated cursors.playground?sample=paginationFocus and motionA small CSS review with focus-visible styles and a reduced-motion branch.playground?sample=cssNew fileAn empty before side rendered as a complete addition with annotations.playground?sample=flagsDocs rewriteProse changes show word-level additions without losing line context.playground?sample=proseReview and edit
Merge conflictResolve current, incoming, or both in a rendered conflict file.
merge-conflictInline editingCall startEditing on the rendered diff, type, undo, then regenerate the diff.surface.startEditing()Stream then finalizeWatch plain text stream, then switch to an interactive file or diff.finalize({ view: 'diff' })markstream-vueKeep the existing MarkdownRender and CodeBlockNode contract.MarkdownRenderRun the local lab
The repository ships a standalone Vite lab that exercises every surface on one page.
bash
pnpm install
pnpm exampleThe page lives in examples/ and imports the source entry directly, so changes to the controller show up on reload.
ts
import { createCodeStream, createDiffSurface } from 'stream-diffs'
const stream = createCodeStream({ fileName: 'answer.ts', language: 'typescript' })
await stream.mount(document.querySelector('#output')!)
stream.append('export const answer = 42\n')
await stream.finalize({ view: 'diff', original: 'export const answer = 0\n' })Build your own preset
- Start from a
FileContentspair:{ name, contents, lang }. - Mount
createDiffSurface({ kind: 'diff', oldFile, newFile }). - Add annotations, token hooks, or line selection only when the review flow needs them.
- For streamed content, keep the host
<pre>mounted until finalization, then mount one final surface.
6diff presets in the playground
13languages available in the language picker
3review surfaces: file, diff, merge conflict
Need the full option list? Start with the API reference, then check diffs and review and streaming code.