Caption Highlight
framecn/caption-highlightFreeComponent
Word-by-word captions with an accent-colored highlight background that sweeps in behind each spoken word.
Install it
npx shadcn@latest add https://framecn.dev/r/caption-highlight.jsonSource
1"use client";23import { Timegroup } from "@editframe/react";4import type { CSSProperties } from "react";56export interface CaptionWord {7 text: string;8 start: number;9 end: number;10}1112export interface CaptionHighlightProps {13 words?: CaptionWord[];14 wordsPerGroup?: number;15 color?: string;16 highlightColor?: string;17 fontSize?: number;18 fontWeight?: number | string;19 background?: string;20 speed?: number;21 fps?: number;22 durationInFrames?: number;23 width?: number;24 height?: number;25 className?: string;26}2728const DEFAULT_WORDS: CaptionWord[] = [29 { end: 0.35, start: 0, text: "Every" },30 { end: 0.65, start: 0.35, text: "great" },31 { end: 1, start: 0.65, text: "video" },32 { end: 1.45, start: 1.1, text: "starts" },33 { end: 1.65, start: 1.45, text: "with" },34 { end: 1.8, start: 1.65, text: "a" },35 { end: 2.15, start: 1.8, text: "single" },36 { end: 2.7, start: 2.15, text: "frame." },37 { end: 3.2, start: 3, text: "No" },38 { end: 3.9, start: 3.2, text: "timelines." },39 { end: 4.2, start: 4, text: "No" },40 { end: 4.5, start: 4.2, text: "drag" },41 { end: 4.65, start: 4.5, text: "and" },42 { end: 5.1, start: 4.65, text: "drop." },43 { end: 5.55, start: 5.3, text: "Just" },44 { end: 6, start: 5.55, text: "code." },45];4647export const CaptionHighlight = ({48 words = DEFAULT_WORDS,49 wordsPerGroup = 3,50 color = "#ffffff",51 highlightColor = "#ff1745",52 fontSize = 72,53 fontWeight = 800,54 background = "#0a0a0a",55 speed = 1,56 fps = 30,57 durationInFrames = 180,58 width = 1280,59 height = 720,60 className,61}: CaptionHighlightProps) => {62 const safeSpeed = Math.max(0.01, speed);63 const durationMs = (durationInFrames / fps) * 1000;6465 const groups = [];66 for (let i = 0; i < words.length; i += wordsPerGroup) {67 const groupWords = words.slice(i, i + wordsPerGroup);68 groups.push({69 endMs: ((groupWords.at(-1)?.end ?? 0) * 1000) / safeSpeed + 180,70 startMs: (groupWords[0].start * 1000) / safeSpeed,71 words: groupWords,72 });73 }7475 const containerStyle: CSSProperties = {76 background,77 height,78 overflow: "hidden",79 position: "relative",80 width,81 };8283 return (84 <Timegroup85 className={className}86 duration={`${durationMs}ms`}87 mode="fixed"88 style={containerStyle}89 >90 <>91 <style>{`92 @keyframes framecn-ch-grp-in {93 from { opacity: 0; transform: translateY(14px); }94 to { opacity: 1; transform: translateY(0); }95 }96// … truncated
What it pulls in
npm packages
Files it writes
More from framecn
All 101 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Generate Overlayai-generate-overlay | framecn | Components | Free | 1 dep | |
| AI Generation Canvasai-generation-canvas | framecn | Components | Free | 1 dep | |
| Animated Bar Chartanimated-bar-chart | framecn | Components | Free | 1 dep | |
| Animated Line Chartanimated-line-chart | framecn | Components | Free | 1 dep | |
| Backdropbackdrop | framecn | Components | Free | 1 dep | |
| Blur Out Upblur-out-up | framecn | Components | Free | 1 dep | |
| Blur Revealblur-reveal | framecn | Components | Free | 1 dep | |
| Bounding Box Selectorbounding-box-selector | framecn | Components | Free | 1 dep |
