Strikethrough Replace
Draws a strike line across old text then reveals new text in its place.
Source
components/kuchi/strikethrough-replace.tsx
1"use client";23import { interpolate, useCurrentFrame, useVideoConfig } from "remotion";45export interface StrikethroughReplaceProps {6 from: string;7 to: string;8 lineColor?: string;9 fontSize?: number;10 color?: string;11 fontWeight?: number;12 speed?: number;13 className?: string;14}1516export function StrikethroughReplace({17 from,18 to,19 lineColor = "#ff5e3a",20 fontSize = 48,21 color = "#171717",22 fontWeight = 600,23 speed = 1,24 className,25}: StrikethroughReplaceProps) {26 const frame = useCurrentFrame() * speed;27 const { durationInFrames } = useVideoConfig();2829 // Phases:30 // 0 .. 40% -> draw strikethrough across `from`31 // 40% .. 60% -> fade out `from`, fade in `to`32 // 60% .. 100% -> hold33 const strikeEnd = durationInFrames * 0.4;34 const fadeStart = durationInFrames * 0.4;35 const fadeEnd = durationInFrames * 0.6;3637 const linePct = interpolate(frame, [0, strikeEnd], [0, 100], {38 extrapolateLeft: "clamp",39 extrapolateRight: "clamp",40 });4142 const fromOpacity = interpolate(frame, [fadeStart, fadeEnd], [1, 0], {43 extrapolateLeft: "clamp",44 extrapolateRight: "clamp",45 });4647 const toOpacity = interpolate(frame, [fadeStart, fadeEnd], [0, 1], {48 extrapolateLeft: "clamp",49 extrapolateRight: "clamp",50 });51 const toY = interpolate(frame, [fadeStart, fadeEnd], [8, 0], {52 extrapolateLeft: "clamp",53 extrapolateRight: "clamp",54 });5556 const textStyle: React.CSSProperties = {57 fontSize,58 fontWeight,59 color,60 letterSpacing: "-0.03em",61 fontFamily:62 "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",63 whiteSpace: "nowrap",64 };6566 return (67 <div68 style={{69 position: "absolute",70 inset: 0,71 display: "flex",72 alignItems: "center",73 justifyContent: "center",74 background: "white",75 }}76 >77 <div78 style={{79 position: "relative",80 display: "inline-flex",81 alignItems: "center",82 justifyContent: "center",83 }}84 >85 {/* from text with strikethrough line */}86 <span87 className={className}88 style={{89 ...textStyle,90 position: "absolute",91 opacity: fromOpacity,92 }}93 >94 {from}95 <span96 aria-hidden97 style={{98 position: "absolute",99 left: 0,100 top: "50%",101 height: Math.max(2, Math.round(fontSize * 0.08)),102 width: `${linePct}%`,103 background: lineColor,104 translate: "0 -50%",105 borderRadius: 2,106 }}107 />108 </span>109110 {/* to text */}111 <span112 className={className}113 style={{114 ...textStyle,115 opacity: toOpacity,116 translate: `0 ${toY}px`,117 }}118 >119 {to}120 </span>121 </div>122 </div>123 );124}









