|
| 1 | +import { useCurrentFrame, useVideoConfig, interpolate, Easing } from 'remotion'; |
| 2 | +import type { Effect } from '../lib/schema'; |
| 3 | +import type { Palette } from '../lib/palettes'; |
| 4 | + |
| 5 | +type Callout = Extract<Effect, { fx: 'callout' }>; |
| 6 | + |
| 7 | +const CalloutPill: React.FC<{ |
| 8 | + callout: Callout; |
| 9 | + palette: Palette; |
| 10 | + enterFrame: number; |
| 11 | + exitFrame: number; |
| 12 | +}> = ({ callout, palette, enterFrame, exitFrame }) => { |
| 13 | + const frame = useCurrentFrame(); |
| 14 | + const { fps } = useVideoConfig(); |
| 15 | + |
| 16 | + const isVisible = frame >= enterFrame && frame < exitFrame; |
| 17 | + if (!isVisible) return null; |
| 18 | + |
| 19 | + const localFrame = frame - enterFrame; |
| 20 | + |
| 21 | + // Pop-in animation over 0.25s (same overshoot bezier as KeystrokePill) |
| 22 | + const enterProgress = interpolate(localFrame, [0, 0.25 * fps], [0, 1], { |
| 23 | + easing: Easing.bezier(0.34, 1.56, 0.64, 1), |
| 24 | + extrapolateLeft: 'clamp', |
| 25 | + extrapolateRight: 'clamp', |
| 26 | + }); |
| 27 | + |
| 28 | + // Fade out over last 0.2s |
| 29 | + const totalFrames = exitFrame - enterFrame; |
| 30 | + const fadeOutStart = totalFrames - 0.2 * fps; |
| 31 | + const exitOpacity = interpolate( |
| 32 | + localFrame, |
| 33 | + [fadeOutStart, totalFrames], |
| 34 | + [1, 0], |
| 35 | + { |
| 36 | + extrapolateLeft: 'clamp', |
| 37 | + extrapolateRight: 'clamp', |
| 38 | + } |
| 39 | + ); |
| 40 | + |
| 41 | + const scale = interpolate(enterProgress, [0, 1], [0.85, 1]); |
| 42 | + |
| 43 | + return ( |
| 44 | + <div |
| 45 | + style={{ |
| 46 | + position: 'absolute', |
| 47 | + left: callout.at.x, |
| 48 | + top: callout.at.y, |
| 49 | + transform: `translate(-50%, -50%) scale(${scale})`, |
| 50 | + opacity: Math.min(enterProgress, exitOpacity), |
| 51 | + backgroundColor: `${palette.surface}E6`, |
| 52 | + color: palette.text, |
| 53 | + fontSize: 24, |
| 54 | + fontFamily: "'Geist', 'Inter', sans-serif", |
| 55 | + fontWeight: 500, |
| 56 | + lineHeight: 1.4, |
| 57 | + padding: '12px 24px', |
| 58 | + borderRadius: 12, |
| 59 | + border: `1px solid ${palette.border}`, |
| 60 | + borderLeft: `3px solid ${palette.accent}`, |
| 61 | + backdropFilter: 'blur(12px)', |
| 62 | + boxShadow: '0 8px 32px rgba(0, 0, 0, 0.35)', |
| 63 | + maxWidth: '40%', |
| 64 | + textAlign: 'center', |
| 65 | + zIndex: 90, |
| 66 | + pointerEvents: 'none', |
| 67 | + }} |
| 68 | + > |
| 69 | + {callout.text} |
| 70 | + </div> |
| 71 | + ); |
| 72 | +}; |
| 73 | + |
| 74 | +export const CalloutOverlay: React.FC<{ |
| 75 | + callouts: Callout[]; |
| 76 | + palette: Palette; |
| 77 | +}> = ({ callouts, palette }) => { |
| 78 | + const { fps } = useVideoConfig(); |
| 79 | + |
| 80 | + return ( |
| 81 | + <> |
| 82 | + {callouts.map((callout) => ( |
| 83 | + <CalloutPill |
| 84 | + key={`${callout.t}-${callout.text}`} |
| 85 | + callout={callout} |
| 86 | + palette={palette} |
| 87 | + enterFrame={Math.round(callout.t * fps)} |
| 88 | + exitFrame={Math.round((callout.t + callout.dur) * fps)} |
| 89 | + /> |
| 90 | + ))} |
| 91 | + </> |
| 92 | + ); |
| 93 | +}; |
0 commit comments