Zoom Words
A close-up word reveal: huge words fade into a long line while the camera rides the write head, the line streaming off-frame as the shot eases into focus.
Source
components/kuchi/zoom-words.tsx
1"use client";23import { Easing, interpolate, useCurrentFrame } from "remotion";45export interface ZoomWordsProps {6 text?: string;7 fontSize?: number;8 zoom?: number;9 color?: string;10 fontWeight?: number;11 wordGap?: number;12 anchor?: number;13 blur?: number;14 blurFrames?: number;15 speed?: number;16 className?: string;17}1819const CHAR_WIDTH_EM = 0.52;20const SPACE_WIDTH_EM = 0.3;21const WORD_BLUR_EM = 0.05;22const phraseEasing = Easing.bezier(0.5, 0, 0.7, 0.7);23const FADE_EARLY = 0.5;24const FADE_SLOTS = 2;2526function smoothstep(t: number): number {27 const x = Math.min(Math.max(t, 0), 1);28 return x * x * (3 - 2 * x);29}30const WORD_SHIFT_X_EM = 0.16;31const WORD_SHIFT_Y_EM = 0.12;3233function wordWidthEm(word: string): number {34 return Array.from(word).length * CHAR_WIDTH_EM + SPACE_WIDTH_EM;35}3637export function zoomWordsLength(text: string, wordGap = 12): number {38 const words = text.trim().split(/\s+/).filter(Boolean);39 return words.length * wordGap;40}4142export function ZoomWords({43 text = "Ship the launch video today",44 fontSize = 64,45 zoom = 2.2,46 color = "#cfc2ff",47 fontWeight = 400,48 wordGap = 12,49 anchor = 0.5,50 blur = 0.04,51 blurFrames = 60,52 speed = 1,53 className,54}: ZoomWordsProps) {55 const frame = useCurrentFrame() * speed;5657 const words = text.trim().split(/\s+/).filter(Boolean);5859 const phraseFrames = words.length * wordGap;60 const wordProgress =61 words.length *62 interpolate(frame, [0, phraseFrames], [0, 1], {63 extrapolateLeft: "clamp",64 extrapolateRight: "clamp",65 easing: phraseEasing,66 });6768 const totalEm = words.reduce((sum, w) => sum + wordWidthEm(w), 0);69 const firstHalfEm = words.length > 0 ? wordWidthEm(words[0]) / 2 : 0;70 const lastHalfEm =71 words.length > 0 ? wordWidthEm(words[words.length - 1]) / 2 : 0;72 let revealedEm = 0;73 for (let i = 0; i < words.length; i++) {74 revealedEm +=75 wordWidthEm(words[i]) *76 smoothstep((wordProgress - i + FADE_EARLY) / FADE_SLOTS);77 }78 const travelMax = Math.max(totalEm - lastHalfEm - firstHalfEm, 0.001);79 const raw = Math.min(Math.max(revealedEm, 0), travelMax);80 const cameraEm = firstHalfEm + travelMax * smoothstep(raw / travelMax);81 const cameraPct = totalEm > 0 ? (cameraEm / totalEm) * 100 : 0;8283 const blurNow =84 blur *85 fontSize *86 zoom *87 interpolate(frame, [0, blurFrames], [1, 0], {88 extrapolateLeft: "clamp",89 extrapolateRight: "clamp",90 });9192 return (93 <div94 style={{95 position: "absolute",96 inset: 0,97 overflow: "hidden",98 background: "transparent",99 }}100 >101 <div102 style={{103 position: "absolute",104 inset: 0,105 scale: `${zoom}`,106 filter: blurNow > 0.05 ? `blur(${blurNow}px)` : undefined,107 }}108 >109 <div110 style={{111 position: "absolute",112 top: "50%",113 left: `${anchor * 100}%`,114 transform: "translateY(-50%)",115 whiteSpace: "pre",116 }}117 >118 <span119 className={className}120 style={{121 display: "inline-flex",122 alignItems: "baseline",123 transform: `translateX(-${cameraPct.toFixed(3)}%)`,124 fontSize,125 fontWeight,126 color,127 letterSpacing: "-0.02em",128 lineHeight: 1.15,129 whiteSpace: "pre",130 fontFamily:131 "var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)",132 }}133 >134 {words.map((word, i) => {135 const p = smoothstep(136 (wordProgress - i + FADE_EARLY) / FADE_SLOTS,137 );138 const opacity = smoothstep(p * 1.2);139 const wordBlur = WORD_BLUR_EM * fontSize * (1 - p);140 const arrive = 1 - smoothstep(p * 1.6);141 return (142 <span143 key={i}144 style={{145 display: "inline-block",146 whiteSpace: "pre",147 opacity,148 filter: wordBlur > 0.05 ? `blur(${wordBlur}px)` : undefined,149 translate: `${(WORD_SHIFT_X_EM * fontSize * arrive).toFixed(1)}px ${(WORD_SHIFT_Y_EM * fontSize * arrive).toFixed(1)}px`,150 }}151 >152 {word}153 {i < words.length - 1 && " "}154 </span>155 );156 })}157 </span>158 </div>159 </div>160 </div>161 );162}









