Diff Swap

Code-diff text animation for Remotion: an old painful line is marked as a deletion and rewritten into the new one, with the changed part highlighted.

In Remotion, Diff Swap animates a code-diff style edit: the old, painful line is marked with a minus and struck as a deletion, the new line rises in as an addition with a plus, and the changed part is highlighted in the accent color. Use it in a dev-tool video to show the old way replaced by the new one.

Installation
$ pnpm dlx shadcn@latest add @remocn/diff-swap

How to build this in Remotion

You don't need Shiki, Code Hike or a diff library for a one-line rewrite. Install the component and pass both lines:

bash
npx shadcn@latest add @remocn/diff-swap

One scene with a schedule in timeline.ts: the removed row is marked, the added row rises, and at foldAt the removed row folds away and the added one grows. Motion uses interpolate() with Easing curves; lines are measured before the first frame, held with delayRender.

Good to know

  • Length: 102 frames of motion at 30 fps (204 at 60 fps) with the default props. That is the minimum for its Sequence; add your own hold on top (the demo plays 125 frames). The Usage example below is a 60 fps composition, so the numbers it hands to Remotion are doubled, see Frame rate.
  • Only the after line gets the highlight; the before line is shown whole as the removed text.
  • The lines are set in Instrument Sans; Geist Mono is used only for the minus and plus signs, so the layout is not a monospace code block.
  • foldAt is a frame on the 30 fps scene timeline and plays faster or slower with speed, like every other timing in the scene.
  • Installs: remotion, @remotion/google-fonts from npm, plus the remocn helpers glide, frame-rate, timeline. The shadcn CLI copies the source into your project.
  • Font: loads Instrument Sans and Geist Mono itself through @remotion/google-fonts. Pass fontFamily to use your own face, and load that font in your project.

Usage

tsx
// src/Root.tsx
import { Composition } from "remotion";
import { DiffSwap } from "@/components/remocn/diff-swap";
 
const DiffSwapScene = () => (
  <DiffSwap before="Keyframe every frame by hand." after="Install the scene. Edit the props." highlight="Edit the props." />
);
 
export const RemotionRoot = () => (
  <Composition
    id="DiffSwap"
    component={DiffSwapScene}
    durationInFrames={250}
    fps={60}
    width={1280}
    height={720}
  />
);

The before line is struck through as a deletion while the after line appears as an addition, with highlight marked in the accent color. Pass before, after and highlight. It ships in light and dark through the theme prop.

Props13

PropTypeDefault
before
string"Keyframe every frame by hand."

Line shown as the removed text.

after
string"Install the scene. Edit the props."

Line shown as the added text.

highlight
string"Edit the props."

Part of `after` marked in the accent color.

accent
string"#3B5BFD"

Accent color override; falls back to the theme accent.

ink
string—

Text color; overrides the theme ink.

background
string—

Background color override; falls back to the theme background.

fontFamily
string"Instrument Sans"

Typeface for the copy. The default is loaded for you; load any other font in your project first.

fontWeight
number500

Weight of the lines.

foldAt
number72

Frame the removed line folds away and the added one grows.

scale
number1

Size of the foreground around the frame's center; the background stays put.

delay
number0

Frames to hold the first frame before anything moves.

speed
number1

Playback speed multiplier for the whole timeline.

theme
"dark" | "light""dark"

Ships light and dark; picks the palette.

  • beforestring

    Line shown as the removed text.

    Default"Keyframe every frame by hand."

  • afterstring

    Line shown as the added text.

    Default"Install the scene. Edit the props."

  • highlightstring

    Part of `after` marked in the accent color.

    Default"Edit the props."

  • accentstring

    Accent color override; falls back to the theme accent.

    Default"#3B5BFD"

  • inkstring

    Text color; overrides the theme ink.

  • backgroundstring

    Background color override; falls back to the theme background.

  • fontFamilystring

    Typeface for the copy. The default is loaded for you; load any other font in your project first.

    Default"Instrument Sans"

  • fontWeightnumber

    Weight of the lines.

    Default500

  • foldAtnumber

    Frame the removed line folds away and the added one grows.

    Default72

  • scalenumber

    Size of the foreground around the frame's center; the background stays put.

    Default1

  • delaynumber

    Frames to hold the first frame before anything moves.

    Default0

  • speednumber

    Playback speed multiplier for the whole timeline.

    Default1

  • theme"dark" | "light"

    Ships light and dark; picks the palette.

    Default"dark"

Common questions

How do I animate a code-diff style edit in Remotion?

Install Diff Swap with npx shadcn@latest add @remocn/diff-swap and pass before, after and the highlight part of after.

I need to animate real code blocks, not one line.

Use Code Morph for code that morphs between versions.

  • Strikethrough Replace: draws a strike line through the old text, then fades the new text in beneath it for an editorial correction.
  • Code Morph: a code panel morphs between versions of a file, with surviving tokens gliding to their new line and column while removed code dissolves and new code fades in.
  • Select Replace: a phrase is selected like text in an editor, deleted, and replaced with new styled words.
  • Typo Fix: a misspelled word is caught and corrected in place inside a short line.