Skip to content

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.

Review and edit ​

Run the local lab ​

The repository ships a standalone Vite lab that exercises every surface on one page.

bash
pnpm install
pnpm example

The 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 ​

  1. Start from a FileContents pair: { name, contents, lang }.
  2. Mount createDiffSurface({ kind: 'diff', oldFile, newFile }).
  3. Add annotations, token hooks, or line selection only when the review flow needs them.
  4. 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.

Released under the MIT License.