code-diff-wipe
remotionui/code-diff-wipeFreeBlock
Diff patch landing line by line: an apply front travels the file, removals collapse, additions open and write in
Live preview
live · rendered by the registry
Rendered by remotionui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://remotionui.com/r/code-diff-wipe.jsonSource
1import { loadFont } from "@remotion/google-fonts/JetBrainsMono";2import {3 interpolate,4 spring,5 useCurrentFrame,6 useVideoConfig,7} from "remotion";8import { stageScale } from "@/remotion/lib/ai-composer-utils";9import { CODE_THEMES, CodeLine, tokenizeCode } from "@/remotion/lib/code-syntax";10import { EASING } from "@/remotion/lib/motion-tokens";1112const { fontFamily } = loadFont("normal", {13 weights: ["400", "500", "700"],14 subsets: ["latin"],15});1617/** Reference stage the window is laid out against, then uniformly scaled. */18const REF_WIDTH = 1280;19const REF_HEIGHT = 720;2021const WINDOW_WIDTH = 940;22const HEADER_HEIGHT = 46;23const BODY_PADDING = 22;24const ROW_HEIGHT = 34;25const FONT_SIZE = 20;26const GUTTER_WIDTH = 46;27const CODE_INSET = 18;2829export type CodeDiffWipeProps = {30 /** Source before the patch. */31 before?: string;32 /** Source after the patch. */33 after?: string;34 /** Filename on the window header. */35 title?: string;36 /** Seconds the patch front takes to travel the file. */37 wipeSeconds?: number;38 accentColor?: string;39 /** Overrides the page background behind the window. */40 backgroundColor?: string;41 theme?: "dark" | "light";42 /** Animation speed multiplier. */43 speed?: number;44};4546const DEFAULT_BEFORE = `export function render(scene) {47 const frames = scene.frames;48 return frames.map(draw);49}`;5051const DEFAULT_AFTER = `export function render(scene, options) {52 const frames = scene.frames;53 const scale = options.scale ?? 1;54 return frames.map((frame) => draw(frame, scale));55}`;5657type DiffKind = "context" | "remove" | "add";5859type DiffRow = {60 kind: DiffKind;61 text: string;62};6364/**65 * Line-level LCS diff. Snippets in a video are a handful of lines, so the66 * quadratic table is free and the result is the one a reader expects.67 */68function diffLines(before: string[], after: string[]): DiffRow[] {69 const table: number[][] = Array.from({ length: before.length + 1 }, () =>70 new Array(after.length + 1).fill(0),71 );7273 for (let i = before.length - 1; i >= 0; i -= 1) {74 for (let j = after.length - 1; j >= 0; j -= 1) {75 table[i][j] =76 before[i] === after[j]77 ? table[i + 1][j + 1] + 178 : Math.max(table[i + 1][j], table[i][j + 1]);79 }80 }8182 const rows: DiffRow[] = [];83 let i = 0;84 let j = 0;8586 while (i < before.length && j < after.length) {87 if (before[i] === after[j]) {88 rows.push({ kind: "context", text: before[i] });89 i += 1;90 j += 1;91// … truncated
More from remotionui
All 127 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-composer-showcaseai-composer-showcase | remotionui | Blocks | Free | no deps | |
| ai-generation-canvasai-generation-canvas | remotionui | Blocks | Free | no deps | |
| animated-bar-chartanimated-bar-chart | remotionui | Blocks | Free | no deps | |
| audiogram-sceneaudiogram-scene | remotionui | Blocks | Free | no deps | |
| auto-fit-titleauto-fit-title | remotionui | Blocks | Free | no deps | |
| b-roll-stackb-roll-stack | remotionui | Blocks | Free | no deps | |
| bento-panbento-pan | remotionui | Blocks | Free | no deps | |
| browser-flowbrowser-flow | remotionui | Blocks | Free | no deps |
