import { Fragment } from 'react'; import { interpolate, spring, useCurrentFrame, useVideoConfig } from 'remotion'; import { COLOR, EASE, FONT, SPRING, STAGE } from '../theme'; export type KeyCapProps = { // Keys of one chord, e.g. ['Ctrl', '1'], ['Tab'], ['右键']. keys: string[]; // Section-local frames: pops in at `from`, gone by `to`. from: number; to: number; // Section-local frames at which the chord is pressed. press?: number[]; // Centre in composition pixels; default: bottom-right corner of the stage. x?: number; y?: number; }; const MOUSE: Record = { 右键: 'right', 左键: 'left', 点击: 'left', 滚轮: 'wheel' }; const clamp = { extrapolateLeft: 'clamp', extrapolateRight: 'clamp' } as const; const Mouse: React.FC<{ part: 'left' | 'right' | 'wheel'; lit: number }> = ({ part, lit }) => { const on = `rgba(61,127,229,${(0.55 + 0.45 * lit).toFixed(3)})`; return ( {part === 'left' ? : null} {part === 'right' ? : null} ); }; // A keyboard chord or mouse button that pops in, presses on cue, and leaves. export const KeyCap: React.FC = ({ keys, from, to, press = [], x, y }) => { const frame = useCurrentFrame(); const { fps } = useVideoConfig(); if (frame < from || frame >= to) return null; const pop = spring({ frame: frame - from, fps, config: SPRING, durationInFrames: 24 }); const out = interpolate(frame, [to - 14, to], [0, 1], { ...clamp, easing: EASE.in }); // Down in 4 frames, back up over 12. const down = press.reduce((acc, at) => { const t = frame - at; const v = t < 0 ? 0 : t < 4 ? EASE.out(t / 4) : 1 - EASE.inOut(Math.min(1, (t - 4) / 12)); return Math.max(acc, v); }, 0); const anchored = x === undefined || y === undefined; const blur = (1 - pop) * 5 + out * 4; return (
0.05 ? `blur(${blur.toFixed(2)}px)` : undefined, display: 'flex', alignItems: 'center', gap: 10, }} > {keys.map((key, i) => { const mouse = MOUSE[key]; return ( {i > 0 ? ( + ) : null}
{mouse ? : null} {key}
); })}
); };