Word Stream
Voiceover-paced phrases that build word by word — the next word looms as a blurred ghost before it resolves, then the phrase cuts away.
Source
components/kuchi/word-stream.tsx
1"use client";23import { Easing, interpolate, useCurrentFrame } from "remotion";45export interface WordStreamProps {6 text?: string;7 fontSize?: number;8 color?: string;9 fontWeight?: number;10 wordGap?: number;11 hold?: number;12 drift?: number;13 speed?: number;14 className?: string;15}1617interface PhraseSchedule {18 words: string[];19 start: number;20 exitStart: number;21 last: boolean;22}2324const REVEAL_FRAMES = 3;25const ENTRY_FRAMES = 8;26const RUN_OUT_FRAMES = 5;27const SWAP_OVERLAP = 0;2829export function wordStreamLength(text: string, wordGap = 6, hold = 18): number {30 const schedule = schedulePhrases(text, wordGap, hold);31 const finalPhrase = schedule[schedule.length - 1];32 if (!finalPhrase) return 0;33 return (34 finalPhrase.start + (finalPhrase.words.length - 1) * wordGap + REVEAL_FRAMES35 );36}3738function schedulePhrases(39 text: string,40 wordGap: number,41 hold: number,42): PhraseSchedule[] {43 const phrases = text44 .split("|")45 .map((phrase) => phrase.trim())46 .filter(Boolean);47 let cursor = 0;48 return phrases.map((phrase, i) => {49 const words = phrase.split(/\s+/);50 const start = cursor;51 const complete = start + (words.length - 1) * wordGap + REVEAL_FRAMES;52 const exitStart = complete + hold;53 cursor = exitStart + SWAP_OVERLAP;54 return { words, start, exitStart, last: i === phrases.length - 1 };55 });56}5758const revealEasing = Easing.bezier(0.2, 0.8, 0.2, 1);59const entryEasing = Easing.bezier(0.2, 0.8, 0.3, 1);60const runOutEasing = Easing.bezier(0.7, 0, 0.9, 0.4);6162export function WordStream({63 text = "Every launch starts with a single frame",64 fontSize = 72,65 color = "#171717",66 fontWeight = 400,67 wordGap = 6,68 hold = 18,69 drift = 2,70 speed = 1,71 className,72}: WordStreamProps) {73 const frame = useCurrentFrame() * speed;7475 const schedule = schedulePhrases(text, wordGap, hold);7677 return (78 <div79 style={{80 position: "absolute",81 inset: 0,82 background: "transparent",83 }}84 >85 {schedule.map((phrase, i) => {86 if (frame < phrase.start) return null;87 if (!phrase.last && frame >= phrase.exitStart) return null;8889 const scale = fontSize / 72;90 const crawl = scale * drift;91 const life = phrase.exitStart - phrase.start;9293 const entryX = interpolate(94 frame,95 [phrase.start, phrase.start + ENTRY_FRAMES],96 [scale * 30, 0],97 {98 extrapolateLeft: "clamp",99 extrapolateRight: "clamp",100 easing: entryEasing,101 },102 );103 const crawlX =104 crawl *105 (life / 2 - (Math.min(frame, phrase.exitStart) - phrase.start));106 const runOutX = phrase.last107 ? 0108 : interpolate(109 frame,110 [phrase.exitStart - RUN_OUT_FRAMES, phrase.exitStart],111 [0, -scale * 80],112 {113 extrapolateLeft: "clamp",114 extrapolateRight: "clamp",115 easing: runOutEasing,116 },117 );118 const x = entryX + crawlX + runOutX;119120 return (121 <div122 key={i}123 style={{124 position: "absolute",125 inset: 0,126 display: "flex",127 alignItems: "center",128 justifyContent: "center",129 whiteSpace: "nowrap",130 translate: `${x}px 0`,131 }}132 >133 <span134 className={className}135 style={{136 fontSize,137 fontWeight,138 color,139 letterSpacing: "-0.02em",140 fontFamily:141 "var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)",142 }}143 >144 {phrase.words.map((word, j) => {145 const revealAt = phrase.start + j * wordGap;146147 const opacity = interpolate(148 frame,149 [revealAt, revealAt + REVEAL_FRAMES],150 [0, 1],151 {152 extrapolateLeft: "clamp",153 extrapolateRight: "clamp",154 easing: revealEasing,155 },156 );157158 return (159 <span160 key={j}161 style={{162 display: "inline-block",163 whiteSpace: "pre",164 marginRight:165 j < phrase.words.length - 1 ? "0.28em" : undefined,166 opacity,167 }}168 >169 {word}170 </span>171 );172 })}173 </span>174 </div>175 );176 })}177 </div>178 );179}









