AI Resource Pro / portrait-video · airesourcepro.com / src / scenes / HeadlineScene.tsx
| 1 | import React from "react"; |
| 2 | import { |
| 3 | AbsoluteFill, |
| 4 | Img, |
| 5 | OffthreadVideo, |
| 6 | interpolate, |
| 7 | spring, |
| 8 | staticFile, |
| 9 | useCurrentFrame, |
| 10 | useVideoConfig, |
| 11 | } from "remotion"; |
| 12 | import { fontFamily } from "../fonts"; |
| 13 | import { TikTokCaptions } from "../components/TikTokCaptions"; |
| 14 | import { ProgressDots } from "../components/ProgressDots"; |
| 15 | |
| 16 | interface HeadlineSceneProps { |
| 17 | title: string; |
| 18 | bullets: string[]; |
| 19 | category: string; |
| 20 | categoryColor: string; |
| 21 | bgFile: string; |
| 22 | clipFile?: string; |
| 23 | image?: string; |
| 24 | captionsFile?: string; |
| 25 | audioStartFrame?: number; |
| 26 | index: number; |
| 27 | totalStories: number; |
| 28 | durationInFrames: number; |
| 29 | } |
| 30 | |
| 31 | export const HeadlineScene: React.FC<HeadlineSceneProps> = ({ |
| 32 | title, |
| 33 | bullets, |
| 34 | category, |
| 35 | categoryColor, |
| 36 | bgFile, |
| 37 | clipFile, |
| 38 | image, |
| 39 | captionsFile, |
| 40 | audioStartFrame, |
| 41 | index, |
| 42 | totalStories, |
| 43 | durationInFrames, |
| 44 | }) => { |
| 45 | const frame = useCurrentFrame(); |
| 46 | const { fps } = useVideoConfig(); |
| 47 | |
| 48 | // Category pill |
| 49 | const categorySpring = spring({ |
| 50 | frame, |
| 51 | fps, |
| 52 | config: { damping: 35, mass: 0.6, stiffness: 100 }, |
| 53 | durationInFrames: 30, |
| 54 | }); |
| 55 | |
| 56 | // Story number |
| 57 | const numberSpring = spring({ |
| 58 | frame: frame - 5, |
| 59 | fps, |
| 60 | config: { damping: 22, mass: 0.6, stiffness: 100 }, |
| 61 | durationInFrames: 30, |
| 62 | }); |
| 63 | |
| 64 | // Headline |
| 65 | const headlineSpring = spring({ |
| 66 | frame: frame - 12, |
| 67 | fps, |
| 68 | config: { damping: 20, mass: 0.7, stiffness: 90 }, |
| 69 | durationInFrames: 40, |
| 70 | }); |
| 71 | |
| 72 | // Accent line under headline |
| 73 | const lineSpring = spring({ |
| 74 | frame: frame - 25, |
| 75 | fps, |
| 76 | config: { damping: 25, mass: 0.5, stiffness: 80 }, |
| 77 | durationInFrames: 40, |
| 78 | }); |
| 79 | |
| 80 | // Bullet animations (staggered) |
| 81 | const bulletSprings = bullets.map((_, i) => |
| 82 | spring({ |
| 83 | frame: frame - 35 - i * 10, |
| 84 | fps, |
| 85 | config: { damping: 20, mass: 0.6, stiffness: 90 }, |
| 86 | durationInFrames: 35, |
| 87 | }) |
| 88 | ); |
| 89 | |
| 90 | // Image fade in + fast pan movement |
| 91 | const imageOpacity = interpolate(frame, [0, 20], [0, 1], { |
| 92 | extrapolateRight: "clamp", |
| 93 | }); |
| 94 | const imageScale = interpolate(frame, [0, durationInFrames], [1.12, 1.04], { |
| 95 | extrapolateRight: "clamp", |
| 96 | }); |
| 97 | const imagePanX = interpolate( |
| 98 | frame, |
| 99 | [0, durationInFrames * 0.4, durationInFrames], |
| 100 | [-140, 60, 10], |
| 101 | { |
| 102 | extrapolateRight: "clamp", |
| 103 | } |
| 104 | ); |
| 105 | const imagePanY = interpolate( |
| 106 | frame, |
| 107 | [0, durationInFrames * 0.5, durationInFrames], |
| 108 | [-30, 20, -10], |
| 109 | { |
| 110 | extrapolateRight: "clamp", |
| 111 | } |
| 112 | ); |
| 113 | const imageRotate = interpolate(frame, [0, durationInFrames], [-1.2, 0.6], { |
| 114 | extrapolateRight: "clamp", |
| 115 | }); |
| 116 | |
| 117 | const headlineOpacity = headlineSpring; |
| 118 | const lineWidth = interpolate(lineSpring, [0, 1], [0, 300]); |
| 119 | const typedHeadlineLength = Math.min( |
| 120 | title.length, |
| 121 | Math.max(0, Math.floor((frame - 10) * 1.8)) |
| 122 | ); |
| 123 | const headlineRevealPercent = |
| 124 | title.length === 0 ? 100 : (typedHeadlineLength / title.length) * 100; |
| 125 | const showCursor = typedHeadlineLength < title.length && frame % 12 < 6; |
| 126 | const storyProgress = durationInFrames <= 0 ? 0 : frame / durationInFrames; |
| 127 | return ( |
| 128 | <AbsoluteFill style={{ backgroundColor: "#0a0a1a" }}> |
| 129 | {/* ===== TOP HALF: Story clip or image ===== */} |
| 130 | <div |
| 131 | style={{ |
| 132 | position: "absolute", |
| 133 | top: 0, |
| 134 | left: 0, |
| 135 | width: "100%", |
| 136 | height: "50%", |
| 137 | overflow: "hidden", |
| 138 | }} |
| 139 | > |
| 140 | {clipFile ? ( |
| 141 | <OffthreadVideo |
| 142 | src={staticFile(clipFile)} |
| 143 | volume={0} |
| 144 | style={{ |
| 145 | width: "100%", |
| 146 | height: "100%", |
| 147 | objectFit: "cover", |
| 148 | }} |
| 149 | /> |
| 150 | ) : image ? ( |
| 151 | <Img |
| 152 | src={staticFile(image)} |
| 153 | style={{ |
| 154 | width: "100%", |
| 155 | height: "100%", |
| 156 | objectFit: "cover", |
| 157 | opacity: imageOpacity, |
| 158 | transform: `translate(${imagePanX}px, ${imagePanY}px) scale(${imageScale}) rotate(${imageRotate}deg)`, |
| 159 | }} |
| 160 | /> |
| 161 | ) : null} |
| 162 | |
| 163 | {/* Gradient fade at bottom of top half */} |
| 164 | <div |
| 165 | style={{ |
| 166 | position: "absolute", |
| 167 | bottom: 0, |
| 168 | left: 0, |
| 169 | width: "100%", |
| 170 | height: 200, |
| 171 | background: |
| 172 | "linear-gradient(transparent, rgba(10,10,26,0.85))", |
| 173 | pointerEvents: "none", |
| 174 | }} |
| 175 | /> |
| 176 | </div> |
| 177 | |
| 178 | {/* ===== BOTTOM HALF: Background video + text ===== */} |
| 179 | <div |
| 180 | style={{ |
| 181 | position: "absolute", |
| 182 | top: "50%", |
| 183 | left: 0, |
| 184 | width: "100%", |
| 185 | height: "50%", |
| 186 | overflow: "hidden", |
| 187 | }} |
| 188 | > |
| 189 | {/* Background video */} |
| 190 | <OffthreadVideo |
| 191 | src={staticFile(bgFile)} |
| 192 | volume={0} |
| 193 | style={{ |
| 194 | position: "absolute", |
| 195 | top: 0, |
| 196 | left: 0, |
| 197 | width: "100%", |
| 198 | height: "100%", |
| 199 | objectFit: "cover", |
| 200 | }} |
| 201 | /> |
| 202 | |
| 203 | {/* Dark overlay */} |
| 204 | <div |
| 205 | style={{ |
| 206 | position: "absolute", |
| 207 | top: 0, |
| 208 | left: 0, |
| 209 | width: "100%", |
| 210 | height: "100%", |
| 211 | backgroundColor: "rgba(5,5,20,0.65)", |
| 212 | }} |
| 213 | /> |
| 214 | |
| 215 | {/* Gradient fade at top blending from top half */} |
| 216 | <div |
| 217 | style={{ |
| 218 | position: "absolute", |
| 219 | top: 0, |
| 220 | left: 0, |
| 221 | width: "100%", |
| 222 | height: 200, |
| 223 | background: |
| 224 | "linear-gradient(rgba(10,10,26,0.85), transparent)", |
| 225 | pointerEvents: "none", |
| 226 | }} |
| 227 | /> |
| 228 | |
| 229 | {/* Text content */} |
| 230 | <div |
| 231 | style={{ |
| 232 | position: "absolute", |
| 233 | top: 0, |
| 234 | left: 0, |
| 235 | width: "100%", |
| 236 | height: "100%", |
| 237 | display: "flex", |
| 238 | flexDirection: "column", |
| 239 | justifyContent: "flex-start", |
| 240 | padding: "0 72px", |
| 241 | paddingTop: 140, |
| 242 | }} |
| 243 | > |
| 244 | {/* Bullets (only when no captions) */} |
| 245 | {!captionsFile && |
| 246 | bullets.map((bullet, i) => { |
| 247 | const bSpring = bulletSprings[i]; |
| 248 | const bY = interpolate(bSpring, [0, 1], [20, 0]); |
| 249 | return ( |
| 250 | <div |
| 251 | key={i} |
| 252 | style={{ |
| 253 | display: "flex", |
| 254 | alignItems: "flex-start", |
| 255 | gap: 16, |
| 256 | marginBottom: 24, |
| 257 | opacity: bSpring, |
| 258 | transform: `translateY(${bY}px)`, |
| 259 | }} |
| 260 | > |
| 261 | <div |
| 262 | style={{ |
| 263 | width: 8, |
| 264 | height: 8, |
| 265 | borderRadius: "50%", |
| 266 | backgroundColor: categoryColor, |
| 267 | marginTop: 12, |
| 268 | flexShrink: 0, |
| 269 | }} |
| 270 | /> |
| 271 | <div |
| 272 | style={{ |
| 273 | fontFamily, |
| 274 | fontWeight: 500, |
| 275 | fontSize: 28, |
| 276 | color: "rgba(255, 255, 255, 0.85)", |
| 277 | lineHeight: 1.5, |
| 278 | }} |
| 279 | > |
| 280 | {bullet} |
| 281 | </div> |
| 282 | </div> |
| 283 | ); |
| 284 | })} |
| 285 | </div> |
| 286 | </div> |
| 287 | |
| 288 | {/* TikTok-style captions */} |
| 289 | {captionsFile && ( |
| 290 | <TikTokCaptions |
| 291 | captionsFile={captionsFile} |
| 292 | highlightColor={categoryColor} |
| 293 | audioStartFrame={audioStartFrame} |
| 294 | /> |
| 295 | )} |
| 296 | |
| 297 | {/* Top headline block */} |
| 298 | <div |
| 299 | style={{ |
| 300 | position: "absolute", |
| 301 | top: 120, |
| 302 | left: 40, |
| 303 | width: "calc(100% - 80px)", |
| 304 | }} |
| 305 | > |
| 306 | {/* Category pill */} |
| 307 | <div |
| 308 | style={{ |
| 309 | opacity: categorySpring, |
| 310 | marginBottom: 20, |
| 311 | alignSelf: "flex-start", |
| 312 | }} |
| 313 | > |
| 314 | <span |
| 315 | style={{ |
| 316 | fontFamily, |
| 317 | fontWeight: 700, |
| 318 | fontSize: 36, |
| 319 | color: "#ffffff", |
| 320 | letterSpacing: "0.12em", |
| 321 | background: `${categoryColor}CC`, |
| 322 | border: `2px solid ${categoryColor}`, |
| 323 | borderRadius: 8, |
| 324 | padding: "10px 24px", |
| 325 | display: "inline-block", |
| 326 | }} |
| 327 | > |
| 328 | #{category} |
| 329 | </span> |
| 330 | </div> |
| 331 | |
| 332 | {/* Headline */} |
| 333 | <div |
| 334 | style={{ |
| 335 | fontFamily, |
| 336 | fontWeight: 800, |
| 337 | fontSize: 52, |
| 338 | color: "#ffffff", |
| 339 | lineHeight: 1.2, |
| 340 | opacity: headlineOpacity, |
| 341 | marginBottom: 20, |
| 342 | WebkitTextStroke: "6px rgba(0,0,0,0.9)", |
| 343 | paintOrder: "stroke fill", |
| 344 | }} |
| 345 | > |
| 346 | <div |
| 347 | style={{ |
| 348 | position: "relative", |
| 349 | display: "inline-block", |
| 350 | width: "100%", |
| 351 | }} |
| 352 | > |
| 353 | {/* Reserve final layout immediately to avoid headline reflow */} |
| 354 | <div style={{ visibility: "hidden", whiteSpace: "pre-wrap" }}>{title}</div> |
| 355 | <div |
| 356 | style={{ |
| 357 | position: "absolute", |
| 358 | inset: 0, |
| 359 | whiteSpace: "pre-wrap", |
| 360 | clipPath: `inset(0 ${100 - headlineRevealPercent}% 0 0)`, |
| 361 | }} |
| 362 | > |
| 363 | {title} |
| 364 | </div> |
| 365 | {showCursor ? ( |
| 366 | <div |
| 367 | style={{ |
| 368 | position: "absolute", |
| 369 | top: "0.08em", |
| 370 | bottom: "0.08em", |
| 371 | left: `${headlineRevealPercent}%`, |
| 372 | width: 3, |
| 373 | backgroundColor: "#ffffff", |
| 374 | transform: "translateX(-50%)", |
| 375 | }} |
| 376 | /> |
| 377 | ) : null} |
| 378 | </div> |
| 379 | </div> |
| 380 | |
| 381 | {/* Accent line */} |
| 382 | <div |
| 383 | style={{ |
| 384 | width: lineWidth, |
| 385 | height: 3, |
| 386 | background: `linear-gradient(to right, ${categoryColor}, transparent)`, |
| 387 | marginBottom: 40, |
| 388 | }} |
| 389 | /> |
| 390 | </div> |
| 391 | |
| 392 | {/* Story number — top left */} |
| 393 | <div |
| 394 | style={{ |
| 395 | position: "absolute", |
| 396 | top: 40, |
| 397 | left: 40, |
| 398 | fontFamily, |
| 399 | fontWeight: 700, |
| 400 | fontSize: 36, |
| 401 | color: "#ffffff", |
| 402 | letterSpacing: "0.12em", |
| 403 | opacity: numberSpring, |
| 404 | background: `${categoryColor}CC`, |
| 405 | border: `2px solid ${categoryColor}`, |
| 406 | borderRadius: 8, |
| 407 | padding: "10px 24px", |
| 408 | lineHeight: 1, |
| 409 | display: "inline-block", |
| 410 | }} |
| 411 | > |
| 412 | {String(index + 1).padStart(2, "0")} |
| 413 | </div> |
| 414 | |
| 415 | {/* Story progress dots */} |
| 416 | <div |
| 417 | style={{ |
| 418 | position: "absolute", |
| 419 | top: 40, |
| 420 | left: "50%", |
| 421 | transform: "translateX(-50%)", |
| 422 | }} |
| 423 | > |
| 424 | <ProgressDots |
| 425 | total={totalStories} |
| 426 | current={index} |
| 427 | progress={storyProgress} |
| 428 | color={categoryColor} |
| 429 | /> |
| 430 | </div> |
| 431 | </AbsoluteFill> |
| 432 | ); |
| 433 | }; |