import { AbsoluteFill, interpolate, Series, useCurrentFrame, useVideoConfig, } from 'remotion'; import { RecordingPlayer, stepAt, type RecordingClip, } from './RecordingVideo.js'; import { useEnter } from './theme.js'; import { clipFrames, type ManifestStep } from './zoom.js'; /** The help-centre article a walkthrough illustrates. */ export type Article = { title: string; /** Shown on the outro as where to read the full guide. */ url?: string; /** The article's opening line, on the title card. */ intro?: string; /** Small line above the title, e.g. "Help centre". */ kicker?: string; }; /** A table shown before the recording, e.g. the spreadsheet an import uploads. */ export type ArticleTable = { label: string; columns: string[]; rows: string[][]; }; export type ArticleVideoProps = { article: Article; /** The article section this recording illustrates. */ heading: string; clip: RecordingClip; /** * The article's wording for a step, keyed by the step's text or its number from 1 ("2"), which * survives rewording the step. A step without one shows its own text, so a scenario whose steps * already use the article's wording needs none. `unmatchedQuotes` finds keys no step has. */ quotes?: Record; /** Shown before the recording, beside the first step's wording. */ table?: ArticleTable; /** Brand colour for the kicker, step numbers and highlight. */ accent?: string; zoom?: number; cursor?: boolean; }; const SECONDS = { title: 3, table: 4, outro: 3 }; /** Row `r` of a table fades in over [ROW_START + r·ROW_GAP, +ROW_FADE] seconds. */ const ROW_START = 0.6; const ROW_GAP = 0.7; const ROW_FADE = 0.3; /** Long enough for every row to appear and hold for a second, never under SECONDS.table. */ const tableSeconds = (table: ArticleTable) => Math.max( SECONDS.table, ROW_START + (table.rows.length - 1) * ROW_GAP + ROW_FADE + 1, ); const PAPER = '#f5f5f7'; const INK = '#111827'; const MUTED = '#6b7280'; const FONT = 'Inter, ui-sans-serif, system-ui, -apple-system, sans-serif'; const ACCENT = '#4f46e5'; /** What each step reads as: the article's wording for it, by text or number, or the step's own text. */ export const articleSteps = ( steps: ManifestStep[], quotes: Record = {}, ) => steps.map((s, i) => quotes[s.text] ?? quotes[String(i + 1)] ?? s.text); /** * Quote keys that match no step: a step was reworded or removed, and its quote is not shown. * Check them in `calculateMetadata` or a test, so a renamed step fails loudly. */ export const unmatchedQuotes = ( steps: ManifestStep[], quotes: Record = {}, ) => Object.keys(quotes).filter( (key) => !steps.some((s, i) => s.text === key || String(i + 1) === key), ); /** * A help-centre walkthrough: a title card with the article's opening line, an optional table, * the recording beside the article's steps (the one being performed highlighted, the camera on * each click and typed field), then an outro pointing at the full article. * Length: `articleVideoFrames(props, fps)`. */ export function ArticleVideo(props: ArticleVideoProps) { const { fps } = useVideoConfig(); const { article, heading, clip, table, accent = ACCENT } = props; const lines = articleSteps(clip.steps ?? [], props.quotes); return ( {table && ( )} ); } /** Total length in frames, for `calculateMetadata`. */ export const articleVideoFrames = ( { clip, table }: Pick, fps: number, ) => (SECONDS.title + SECONDS.outro) * fps + (table ? Math.round(tableSeconds(table) * fps) : 0) + clipFrames(clip, fps); function ArticleTitle({ article, heading, accent, }: { article: Article; heading: string; accent: string; }) { const entered = { 0: useEnter(0), 6: useEnter(6), 15: useEnter(15), 27: useEnter(27), }; const rise = (delay: keyof typeof entered) => ({ opacity: entered[delay], transform: `translateY(${(1 - entered[delay]) * 24}px)`, }); return ( {article.kicker && (
{article.kicker}
)}

{article.title}

{article.intro && (

{article.intro}

)}
{heading}
); } function TableScene({ table, quote }: { table: ArticleTable; quote: string }) { const frame = useCurrentFrame(); const { fps } = useVideoConfig(); const line = { padding: '18px 24px', borderBottom: '1px solid #e5e7eb', borderRight: '1px solid #e5e7eb', }; return (

{quote}

{table.label}
{['', ...table.columns].map((c, i) => (
{c}
))} {table.rows.flatMap((row, r) => [String(r + 2), ...row].map((cell, c) => (
{cell}
)), )}
); } const PANEL = 620; function Walkthrough({ article, heading, clip, lines, accent, zoom = 1.35, cursor, }: ArticleVideoProps & { lines: string[]; accent: string }) { const frame = useCurrentFrame(); const { fps, width, height } = useVideoConfig(); const steps = clip.steps ?? []; const current = stepAt(steps, (frame / fps) * 1000); const appear = useEnter(Math.round(((steps[current]?.t ?? 0) / 1000) * fps)); const fit = Math.min( (width - PANEL - 3 * 60) / clip.width, (height - 2 * 80) / clip.height, ); return (
{article.title}
{heading}
    {lines.map((text, i) => (
  1. {i + 1} {text}
  2. ))}
); } function Outro({ article, accent }: { article: Article; accent: string }) { return (

Read the full guide

{article.title}

{article.url && (

{article.url}

)}
); }