Text Swap
snap-cn/text-swapFreeComponent
Replaces one line of text with another using exit-then-enter scheduling, with five transition presets: fade-through, crossfade, shared-axis-y, shared-axis-z, and cut.
Install it
npx shadcn@latest add https://snapcn.dev/r/text-swap.jsonSource
1"use client";23import { Easing, interpolate, useCurrentFrame } from "remotion";4import { type SnapCnTheme, useSnapCnTheme } from "@/lib/snap-cn-ui";56export type TextSwapTransition =7 | "fly-through"8 | "fade-through"9 | "crossfade"10 | "shared-axis-y"11 | "shared-axis-z"12 | "cut";1314export type TextSwapUnit = "word" | "block";1516export interface TextSwapTransitionDefaults {17 unit: TextSwapUnit;18 exitDuration: number;19 enterDuration: number;20}2122/**23 * Per-transition timing defaults. `unit` picks whether the line animates as a24 * whole block or word-by-word when the `unit` prop is omitted.25 */26export const TRANSITION_DEFAULTS: Record<27 TextSwapTransition,28 TextSwapTransitionDefaults29> = {30 // Always a block: the line has to rush the camera as one object. Per-word it31 // would be five objects each blowing up about its own centre, which is not a32 // camera move, it is a collision.33 "fly-through": { unit: "block", exitDuration: 20, enterDuration: 16 },34 "fade-through": { unit: "block", exitDuration: 8, enterDuration: 13 },35 crossfade: { unit: "word", exitDuration: 15, enterDuration: 21 },36 "shared-axis-y": { unit: "block", exitDuration: 10, enterDuration: 14 },37 "shared-axis-z": { unit: "block", exitDuration: 11, enterDuration: 16 },38 cut: { unit: "word", exitDuration: 8, enterDuration: 8 },39};4041export interface TextSwapMotion {42 /** Y offset (px) the outgoing text drifts to. */43 exitY: number;44 /** Scale the outgoing text ends at. */45 exitScale: number;46 /** Blur (px) the outgoing text ends at. */47 exitBlur: number;48 /** Y offset (px) the incoming text starts from. */49 enterY: number;50 /** Scale the incoming text starts from. */51 enterScale: number;52 /** Blur (px) the incoming text starts from. */53 enterBlur: number;5455 /**56 * Shape the exit's scale as a **perspective rush** instead of a plain ramp —57 * see `perspectiveScale`. Only worth it when the line is meant to pass the58 * camera rather than merely grow.59 */60 exitPerspective?: boolean;61 /**62 * Fraction of the exit that passes before the outgoing line starts to fade.63 * 0 (the default) fades across the whole exit. A line flying at your face does64 * not dim on the way in — it stays solid until it is on top of you and then it65 * is gone, so this holds the fade back until the very end.66 */67 exitFadeStart?: number;68 /**69 * Motion-blur samples for the exit. See `SHUTTER` below.70 *71// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from snap-cn
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Answer Streamanswer-stream | snap-cn | Components | Free | 2 deps | |
| UI Caretcaret | snap-cn | Components | Free | 1 dep | |
| Follower Rushfollower-rush | snap-cn | Components | Free | 2 deps | |
| Product Herohero-launch | snap-cn | Components | Free | 2 deps | |
| UI Inputinput | snap-cn | Components | Free | 2 deps · 2 files | |
| Karaoke Captionskaraoke-captions | snap-cn | Components | Free | 2 deps | |
| Laptop Framelaptop-frame | snap-cn | Components | Free | 1 dep | |
| Logo Assemblelogo-assemble | snap-cn | Components | Free | 1 dep |
