import React from "react"; import { AbsoluteFill, Sequence, useCurrentFrame, useVideoConfig, spring, interpolate, } from "remotion"; import type { HookConfig } from "../lib/types"; import { notoSerifFontFace, montserratFontFace, antonFontFace, HOOK_FONTS, } from "../lib/fonts"; interface HookOverlayProps { config: HookConfig; } const SIZE_SCALE: Record = { S: 0.8, M: 1.0, L: 1.3, }; // Percentages must match clipwright/media/hooks.py's overlay_y math (top 20% / bottom 70%), // or the preview drifts from what the server path renders. const POSITION_STYLE: Record = { top: { top: "20%", bottom: "auto" }, center: { top: "50%", bottom: "auto", transform: "translateY(-50%)" }, bottom: { top: "70%", bottom: "auto" }, }; // Must mirror clipwright/media/hooks.py HOOK_STYLES (the server-side FFmpeg fallback). interface HookLook { box: string | null; text: string; outlinePx: number; shadow: boolean; /** One rounded box per line (clipwright/media/hooks.py _draw_pills) instead of one card. */ pills?: boolean; } const HOOK_LOOKS: Record = { pill: { box: "rgba(255, 255, 255, 0.98)", text: "#000000", outlinePx: 0, shadow: false, pills: true }, classic: { box: "rgba(255, 255, 255, 0.94)", text: "#000000", outlinePx: 0, shadow: true }, dark: { box: "rgba(18, 18, 20, 0.92)", text: "#FFFFFF", outlinePx: 0, shadow: true }, yellow: { box: "rgba(255, 214, 0, 0.96)", text: "#000000", outlinePx: 0, shadow: true }, red: { box: "rgba(220, 38, 38, 0.96)", text: "#FFFFFF", outlinePx: 0, shadow: true }, outline: { box: null, text: "#FFFFFF", outlinePx: 8, shadow: false }, outline_yellow: { box: null, text: "#FFD600", outlinePx: 8, shadow: false }, }; export const HookOverlay: React.FC = ({ config }) => { const { fps } = useVideoConfig(); const displayFrames = Math.round(config.displayDurationSec * fps); return ( ); }; interface HookBoxProps { config: HookConfig; displayFrames: number; } const HookBox: React.FC = ({ config, displayFrames }) => { const frame = useCurrentFrame(); const { fps } = useVideoConfig(); const scale = SIZE_SCALE[config.size] ?? 1.0; // Entrance animation let animOpacity = 1; let animScale = 1; let animTranslateY = 0; switch (config.entranceAnimation) { case "spring": { const prog = spring({ frame, fps, config: { mass: 0.8, stiffness: 200, damping: 15 }, durationInFrames: 20, }); animScale = interpolate(prog, [0, 1], [0.7, 1]); animOpacity = interpolate(prog, [0, 1], [0, 1]); break; } case "fade": { animOpacity = interpolate(frame, [0, 15], [0, 1], { extrapolateRight: "clamp", }); break; } case "slide-up": { const prog = spring({ frame, fps, config: { mass: 1, stiffness: 150, damping: 18 }, durationInFrames: 20, }); animTranslateY = interpolate(prog, [0, 1], [60, 0]); animOpacity = interpolate(prog, [0, 1], [0, 1]); break; } default: break; } // Exit fade (last 15 frames) const fadeOutStart = displayFrames - 15; if (frame > fadeOutStart) { animOpacity *= interpolate(frame, [fadeOutStart, displayFrames], [1, 0], { extrapolateLeft: "clamp", extrapolateRight: "clamp", }); } const positionStyle = POSITION_STYLE[config.position] ?? POSITION_STYLE.top; const look = HOOK_LOOKS[config.style ?? "pill"] ?? HOOK_LOOKS.pill; // Typeface and size as clipwright/media/hooks.py: the chosen font, else the style's own; // font size = factor x the 90%-of-width box. const typeface = HOOK_FONTS[config.font ?? (look.pills ? "montserrat" : "serif")] ?? HOOK_FONTS.serif; const fontSize = Math.round(1080 * 0.9 * typeface.factor * scale); const outlinePx = Math.round(look.outlinePx * scale); if (look.pills) { // box-decoration-break: clone gives every wrapped line its own padded, // rounded box, the same stack clipwright/media/hooks.py draws for the FFmpeg path. return (
{config.text}
); } return (
0 ? { WebkitTextStroke: `${outlinePx}px #000000`, paintOrder: "stroke fill", } : {}), }} > {config.text}
); };