Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/assets/text-animations-word-highlight.tsx
1import {loadFont} from '@remotion/google-fonts/Inter';2import React from 'react';3import {AbsoluteFill, spring, useCurrentFrame, useVideoConfig} from 'remotion';45/*6* Highlight a word in a sentence with a spring-animated wipe effect.7*/89// Ideal composition size: 1280x7201011const COLOR_BG = '#ffffff';12const COLOR_TEXT = '#000000';13const COLOR_HIGHLIGHT = '#A7C7E7';14const FULL_TEXT = 'This is Remotion.';15const HIGHLIGHT_WORD = 'Remotion';16const FONT_SIZE = 72;17const FONT_WEIGHT = 700;18const HIGHLIGHT_START_FRAME = 30;19const HIGHLIGHT_WIPE_DURATION = 18;2021const {fontFamily} = loadFont();2223const Highlight: React.FC<{24word: string;25color: string;26delay: number;27durationInFrames: number;28}> = ({word, color, delay, durationInFrames}) => {29const frame = useCurrentFrame();30const {fps} = useVideoConfig();3132const highlightProgress = spring({33fps,34frame,35config: {damping: 200},36delay,37durationInFrames,38});39const scaleX = Math.max(0, Math.min(1, highlightProgress));4041return (42<span style={{position: 'relative', display: 'inline-block'}}>43<span44style={{45position: 'absolute',46left: 0,47right: 0,48top: '50%',49height: '1.05em',50transform: `translateY(-50%) scaleX(${scaleX})`,51transformOrigin: 'left center',52backgroundColor: color,53borderRadius: '0.18em',54zIndex: 0,55}}56/>57<span style={{position: 'relative', zIndex: 1}}>{word}</span>58</span>59);60};6162export const MyAnimation = () => {63const highlightIndex = FULL_TEXT.indexOf(HIGHLIGHT_WORD);64const hasHighlight = highlightIndex >= 0;65const preText = hasHighlight ? FULL_TEXT.slice(0, highlightIndex) : FULL_TEXT;66const postText = hasHighlight67? FULL_TEXT.slice(highlightIndex + HIGHLIGHT_WORD.length)68: '';6970return (71<AbsoluteFill72style={{73backgroundColor: COLOR_BG,74alignItems: 'center',75justifyContent: 'center',76fontFamily,77}}78>79<div80style={{81color: COLOR_TEXT,82fontSize: FONT_SIZE,83fontWeight: FONT_WEIGHT,84}}85>86{hasHighlight ? (87<>88<span>{preText}</span>89<Highlight90word={HIGHLIGHT_WORD}91color={COLOR_HIGHLIGHT}92delay={HIGHLIGHT_START_FRAME}93durationInFrames={HIGHLIGHT_WIPE_DURATION}94/>95<span>{postText}</span>96</>97) : (98<span>{FULL_TEXT}</span>99)}100</div>101</AbsoluteFill>102);103};104