{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"punch-lines","type":"registry:component","title":"Punch Lines","description":"Kinetic typography title cards: bold statements that cut hard between beats. A run of full-frame title cards that cut hard between beats.","dependencies":["remotion","@remotion/google-fonts"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>. Pass mode=\"dark\" for dark frames.","registryDependencies":["https://kuchi.kalarislabs.com/r/kuchi-ui.json"],"files":[{"path":"components/kuchi/punch-lines.tsx","type":"registry:component","target":"components/kuchi/punch-lines.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Inter\";\r\nimport { Fragment, useEffect, useMemo, useRef, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  Item,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * A run of full-frame title cards that cut hard between beats.\r\n *\r\n * Two looks, and the sequence alternates them:\r\n *\r\n * - **slide** — the statement card. Its lines are already at full size when the\r\n *   card opens, sitting left of centre; each one is flicked right and settles\r\n *   home on a critically damped curve, one line behind the last. It leaves by\r\n *   rushing past the camera.\r\n * - **punch** — the hero line. Every word starts a third of its size and swells\r\n *   into place in a wave, while the whole line pushes slowly forward for as long\r\n *   as it is on screen. It leaves on a cut.\r\n *\r\n * It paints a whole page rather than a control, so it takes the design system's\r\n * two page colours — `background` and `foreground` — and inverts with `mode`.\r\n * Only the accent is a bare prop, because an accent that is supposed to shout is\r\n * the design and not a token.\r\n *\r\n * ## Where the numbers come from\r\n *\r\n * Every curve here was fitted to a reference recording, frame by frame, not\r\n * eyeballed. The recording is 24fps variable-rate, so each fit is against the\r\n * frames' real timestamps and the results are stored in **seconds** — a frame\r\n * index is not a clock.\r\n *\r\n * | beat | signal | fit |\r\n * | --- | --- | --- |\r\n * | slide | each line's ink centroid, 37 frames, both lines at once | `(A + Bt)·e^(-λt)`, **rms 0.42px** |\r\n * | punch | per-word ink width, 27 frames | scale `0.32 → 1` on an in-out cubic |\r\n * | push | per-word ink width once the wave has landed | linear, `+20.5%/s` |\r\n * | rush | ink second moment (`rmsX`/`rmsY` agreed to 0.02%, so it is a pure scale) | `1/(1 − travel)`, travel on a hard ease-in |\r\n *\r\n * Two of those are worth keeping because they are the sort of thing you cannot\r\n * see and would never guess:\r\n *\r\n * - **The slide is not a spring.** A damped sinusoid fits the overshoot and then\r\n *   demands an undershoot that is not there; a spring released from rest cannot\r\n *   overshoot 36px without starting 2,000px out. What actually fits, to under\r\n *   half a pixel over 37 frames, is a **critically damped** system given an\r\n *   initial kick: `(A + Bt)·e^(-λt)`. It starts 0.74em left of centre, sails\r\n *   0.71em past it, and comes home without ever crossing back.\r\n * - **The rush is a scale about the frame centre, not the type's own centre.**\r\n *   Solving the ink centroid for the pivot lands on the middle of the frame in\r\n *   both axes, which is why the lower line dives *down* out of shot while the\r\n *   upper one climbs out of the top.\r\n *\r\n * ## The cadence, and why a card is already moving when you first see it\r\n *\r\n * `holds` is time **on screen**, one entry per card, so the rhythm is exactly\r\n * what you wrote and no card can ever bleed over the one in front of it. The\r\n * cards are a straight run of hard cuts.\r\n *\r\n * The one thing that happens off screen is `lead`: a card's clock starts a few\r\n * frames before its cut, so it is caught mid-entrance rather than starting from\r\n * nothing. That is the reference's own trick — its third card is at 87% of its\r\n * size on the first frame you can see it, with not one coloured pixel on the\r\n * frame before — and it is most of what makes a cut read as expensive rather\r\n * than abrupt. `lead: 0` plays every entrance in full.\r\n */\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"400\", \"500\", \"600\", \"700\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\n/** How a card arrives, and how it leaves. */\r\nexport type PunchLineStyle = \"slide\" | \"punch\";\r\n\r\nexport interface PunchLinesProps {\r\n  /**\r\n   * The whole script in one string. `|` starts a new card, `/` starts a new\r\n   * line inside a card:\r\n   *\r\n   * ```\r\n   * \"Ready-made scenes / for Remotion. | One command. Own it. | kuchi.\"\r\n   * ```\r\n   */\r\n  script?: string;\r\n  /**\r\n   * Per-card look — `slide` or `punch` — comma separated. The last value repeats,\r\n   * so `\"slide,punch\"` gives the first card the statement look and every card\r\n   * after it the hero look.\r\n   */\r\n  styles?: string;\r\n  /**\r\n   * Per-card type size, as a multiple of `fontSize`, comma separated; the last\r\n   * value repeats. A one-word payoff wants to be much bigger than the sentence\r\n   * that set it up — that is the whole point of the beat.\r\n   */\r\n  sizes?: string;\r\n  /**\r\n   * Per-card length in frames, comma separated; the last value repeats. Measured\r\n   * from the frame the card's own clock starts, so it includes the entrance and\r\n   * the exit.\r\n   */\r\n  holds?: string;\r\n  /** Which card is painted in `accentColor`, counting from 1. `0` = none. */\r\n  accentBeat?: number;\r\n\r\n  /**\r\n   * Frames of a card's entrance that run before it is cut to — it arrives\r\n   * already moving instead of from nothing. `0` plays every entrance in full.\r\n   */\r\n  lead?: number;\r\n\r\n  /** Type size of a `size = 1` card, in px. */\r\n  fontSize?: number;\r\n  fontWeight?: number | string;\r\n  /**\r\n   * Baseline-to-baseline distance inside a card, in em. Tight on purpose — a\r\n   * statement card is a lockup, not a paragraph — but a face's descender depth\r\n   * and ascender height both eat into the gap, so a number carried over from\r\n   * another face will collide rather than kiss.\r\n   */\r\n  lineHeight?: number;\r\n  /** Resting letter-spacing. */\r\n  letterSpacing?: string;\r\n  /**\r\n   * Resting word-spacing. The reference crushes it almost to nothing — measured,\r\n   * its word gaps are 0.17em where the face's own space is 0.26em — which is what\r\n   * makes a line read as one block of type rather than four words.\r\n   */\r\n  wordSpacing?: string;\r\n\r\n  /** The ground the cards are cut on. Defaults to the design system's page. */\r\n  ground?: string;\r\n  /** The type. Defaults to the design system's foreground. */\r\n  ink?: string;\r\n  /**\r\n   * The one card that is not the type colour.\r\n   *\r\n   * A prop and not `theme.primary` on purpose: an accent that is *supposed* to\r\n   * shout is the design, not a token — see the design system's note on burned-in\r\n   * video type. Swap it for your brand's and the rest of the card still follows\r\n   * whatever palette it was dropped into.\r\n   */\r\n  accentColor?: string;\r\n\r\n  /** Design-system token overrides. */\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  /**\r\n   * The face the cards are set in — a label from `fonts.ts` (\"Geist\", \"Outfit\",\r\n   * \"Montserrat\") or a CSS family you have loaded yourself. Unset, the cards are\r\n   * set in Inter, the same face the rest of the text tier uses.\r\n   */\r\n  fontFamily?: string;\r\n\r\n  /** How far left of centre a slide card's line starts, in em. */\r\n  slideFrom?: number;\r\n  /** The kick that throws it right, in em per second. */\r\n  slideKick?: number;\r\n  /** How fast the slide settles. Higher is tighter. */\r\n  slideSettle?: number;\r\n  /** Frames between one line of a slide card leaving and the next. */\r\n  lineStagger?: number;\r\n  /**\r\n   * How far below the optical centre a slide card hangs, in em. The reference's\r\n   * two-line statement sits low so the eye lands on the first line rather than\r\n   * in the gap between them.\r\n   */\r\n  slideDrop?: number;\r\n  /**\r\n   * Shutter angle for the slide's motion blur, as a fraction of the frame — `1`\r\n   * is a fully open shutter, `0` turns it off.\r\n   *\r\n   * A browser animating `translate` draws every frame perfectly sharp. Film, and\r\n   * anything rendered with a shutter, does not: a line travelling 30px in a\r\n   * frame is smeared across those 30px, and its absence is most of what makes a\r\n   * fast move read as \"computer graphics\". The reference has it — measured, its\r\n   * first frame's ink is spread by exactly the frame's own travel — so this\r\n   * smears the line horizontally by the distance it covered, and by nothing at\r\n   * all once it has stopped.\r\n   */\r\n  motionBlur?: number;\r\n\r\n  /** The size a punch card's word starts at, relative to its final size. */\r\n  punchFrom?: number;\r\n  /** Frames a word takes to swell into place. */\r\n  punchFrames?: number;\r\n  /** Frames between one word starting to swell and the next. */\r\n  wordStagger?: number;\r\n  /** The size a punch card's line opens at, relative to its final size. */\r\n  pushFrom?: number;\r\n  /** How fast the line keeps growing while it holds, per second. */\r\n  pushRate?: number;\r\n\r\n  /** Frames before a rushing card ends that it starts to rush. */\r\n  rushLead?: number;\r\n  /** Frames the rush would take to run its whole travel. */\r\n  rushFrames?: number;\r\n  /**\r\n   * How far the card travels toward the camera, as a fraction of its distance.\r\n   * `0.85` ends at 6.7× — long gone off every edge.\r\n   */\r\n  rushTravel?: number;\r\n\r\n  /** Fraction of the frame width a line may occupy before it is scaled down. */\r\n  fit?: number;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\n/**\r\n * A word swelling into place. Symmetric in-out cubic: it leaves and arrives at a\r\n * standstill, and spends its frames in the middle where you can see them.\r\n *\r\n * Fitted twice — on the last word of the second beat and on the single word of\r\n * the third — and both landed on 11 frames at 30fps, which is the check that it\r\n * is the real curve and not one that happened to fit one sample.\r\n */\r\nconst PUNCH_EASE = Easing.bezier(0.65, 0, 0.35, 1);\r\n\r\n/**\r\n * The card's travel toward the camera on the way out.\r\n *\r\n * Brutally eased in: 28% of the travel in the first 60% of the time, and the\r\n * rest in the last 40%. That is what makes the exit read as a *rush* rather than\r\n * a zoom — nothing appears to happen, and then the type is past you.\r\n */\r\nconst RUSH_EASE = Easing.bezier(1, 0, 0.48, 1);\r\n\r\n/**\r\n * The furthest a slide card's line ever gets from centre, in em — its start, or\r\n * the far side of its overshoot, whichever is bigger. Needed to fit a card: the\r\n * line has to be inside the frame at both ends of the swing, not just at rest.\r\n */\r\nexport function slideSwing(from: number, kick: number, settle: number): number {\r\n  // (A + Bt)·e^(-λt) turns over where B = λ(A + Bt). No kick, no turn — and the\r\n  // division would be an infinity that comes back as NaN and quietly disables\r\n  // the fit for the one card that most needs it.\r\n  const peakAt = kick > 0 ? Math.max(0, 1 / settle - from / kick) : 0;\r\n  const peak = (from + kick * peakAt) * Math.exp(-settle * peakAt);\r\n  return Math.max(Math.abs(from), Math.abs(peak));\r\n}\r\n\r\n/** Split a comma list, trimmed, empties dropped. */\r\nconst list = (s: string | undefined): string[] =>\r\n  (s ?? \"\")\r\n    .split(\",\")\r\n    .map((v) => v.trim())\r\n    .filter(Boolean);\r\n\r\n/** Read index `i` out of a list, repeating the last value forever. */\r\nconst at = <T,>(values: T[], i: number, fallback: T): T =>\r\n  values.length === 0\r\n    ? fallback\r\n    : (values[Math.min(i, values.length - 1)] as T);\r\n\r\nexport interface PunchBeat {\r\n  lines: string[][];\r\n  style: PunchLineStyle;\r\n  size: number;\r\n  accent: boolean;\r\n  /** Frame the card's own clock starts — `lead` frames before it is revealed. */\r\n  start: number;\r\n  /** Frame the card leaves the screen. */\r\n  end: number;\r\n  /** Frame the card is cut to, which is the frame the card in front of it ends. */\r\n  revealAt: number;\r\n}\r\n\r\n/**\r\n * Parse the script and lay the cards out on the timeline.\r\n *\r\n * `holds[i]` is time **on screen**, so the cards are a straight run of hard cuts\r\n * and the cadence is exactly what you wrote — no card can bleed over the one in\r\n * front of it, whichever way that one leaves.\r\n *\r\n * `lead` is the only thing that happens off screen: a card's clock starts that\r\n * many frames before its cut, so it arrives already moving rather than from\r\n * nothing. Raise it and the cut lands harder; set it to 0 and every card plays\r\n * its entrance in full.\r\n */\r\nexport function planPunchLines(\r\n  script: string,\r\n  styles: string,\r\n  sizes: string,\r\n  holds: string,\r\n  accentBeat: number,\r\n  lead: number,\r\n): PunchBeat[] {\r\n  const texts = script\r\n    .split(\"|\")\r\n    .map((s) => s.trim())\r\n    .filter(Boolean);\r\n  const styleList = list(styles) as PunchLineStyle[];\r\n  const sizeList = list(sizes).map(Number).filter(Number.isFinite);\r\n  const holdList = list(holds).map(Number).filter(Number.isFinite);\r\n\r\n  const beats: PunchBeat[] = [];\r\n  let revealAt = 0;\r\n  for (let i = 0; i < texts.length; i++) {\r\n    const style = at(styleList, i, \"punch\");\r\n    const hold = Math.max(1, at(holdList, i, 48));\r\n    beats.push({\r\n      lines: (texts[i] as string)\r\n        .split(\"/\")\r\n        .map((l) => l.trim())\r\n        .filter(Boolean)\r\n        .map((l) => l.split(/\\s+/)),\r\n      style: style === \"slide\" ? \"slide\" : \"punch\",\r\n      size: at(sizeList, i, 1),\r\n      accent: i + 1 === accentBeat,\r\n      // Nothing is behind the first card, so there is nothing for it to arrive\r\n      // out of — it starts where it is revealed.\r\n      start: i === 0 ? 0 : revealAt - lead,\r\n      revealAt,\r\n      end: revealAt + hold,\r\n    });\r\n    revealAt += hold;\r\n  }\r\n  return beats;\r\n}\r\n\r\n/** Total frames a script needs, so the config and the component cannot drift. */\r\nexport function punchLinesDuration(script: string, holds: string): number {\r\n  const n = script\r\n    .split(\"|\")\r\n    .map((s) => s.trim())\r\n    .filter(Boolean).length;\r\n  const holdList = list(holds).map(Number).filter(Number.isFinite);\r\n  let total = 0;\r\n  for (let i = 0; i < n; i++) total += Math.max(1, at(holdList, i, 48));\r\n  return total;\r\n}\r\n\r\ninterface FaceMetrics {\r\n  /** Top of the line box down to the baseline, at `fontSize` 100. */\r\n  baseline: number;\r\n  /**\r\n   * Per card, at `fontSize` 100: how far its first line's *ink* rises above the\r\n   * baseline, and how far its last line's ink falls below one.\r\n   *\r\n   * Both measured from the copy actually passed, because a card is centred on\r\n   * the ink you can see and nothing else knows where that is. A face's cap\r\n   * height is the wrong number twice over: some faces draw their ascenders\r\n   * taller than their caps, so a line with an ascender sits high; and a word\r\n   * with no ascender at all but a descender in it — a lowercase wordmark, say —\r\n   * is not a cap band, and centring it as one drops it half a descender low.\r\n   */\r\n  inkAscent: number[];\r\n  inkDescent: number[];\r\n}\r\n\r\nexport function PunchLines({\r\n  script = \"Ready-made scenes / for Remotion. | One command. Own it. | kuchi.\",\r\n  styles = \"slide,punch\",\r\n  sizes = \"1,0.945,2.7\",\r\n  holds = \"48\",\r\n  accentBeat = 3,\r\n  lead = 4,\r\n\r\n  fontSize = 93,\r\n  fontWeight = 600,\r\n  lineHeight = 0.89,\r\n  letterSpacing = \"-0.022em\",\r\n  wordSpacing = \"-0.02em\",\r\n\r\n  ground,\r\n  ink,\r\n  accentColor = \"#ff1c8e\",\r\n\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n\r\n  slideFrom = -0.737,\r\n  slideKick = 7.34,\r\n  slideSettle = 2.846,\r\n  lineStagger = 3.5,\r\n  slideDrop = 0.313,\r\n  motionBlur = 1,\r\n\r\n  punchFrom = 0.32,\r\n  punchFrames = 15,\r\n  wordStagger = 2.8,\r\n  pushFrom = 0.778,\r\n  pushRate = 0.205,\r\n\r\n  rushLead = 12.2,\r\n  rushFrames = 18,\r\n  rushTravel = 0.85,\r\n\r\n  fit = 0.92,\r\n  speed = 1,\r\n  className,\r\n}: PunchLinesProps) {\r\n  const frame = useCurrentFrame() * speed;\r\n  const { width, fps } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS;\r\n  // A card is a full-bleed page, so it takes the page's own two colours rather\r\n  // than inventing a pair. Pass `mode=\"dark\"` and the whole run inverts.\r\n  const paper = ground ?? t.background;\r\n  const type = ink ?? t.foreground;\r\n\r\n  const beats = useMemo(\r\n    () => planPunchLines(script, styles, sizes, holds, accentBeat, lead),\r\n    [script, styles, sizes, holds, accentBeat, lead],\r\n  );\r\n\r\n  // Two things have to be measured rather than assumed, both constant across\r\n  // every frame: where the baseline sits inside a line box, and how far each\r\n  // card's own first line rises above it. Together they place the block — a card\r\n  // is centred on its *ink*, not on its line boxes, which is what keeps a\r\n  // one-line hero optically centred while a two-line statement hangs from the\r\n  // same rule.\r\n  const probeRef = useRef<HTMLSpanElement>(null);\r\n  const baselineRef = useRef<HTMLSpanElement>(null);\r\n  const lineRefs = useRef<(HTMLSpanElement | null)[]>([]);\r\n  const [handle] = useState(() => delayRender(\"punch-lines: measure the face\"));\r\n  const [metrics, setMetrics] = useState<FaceMetrics | null>(null);\r\n  const [lineWidths, setLineWidths] = useState<number[] | null>(null);\r\n\r\n  useEffect(() => {\r\n    const probe = probeRef.current;\r\n    if (!probe) {\r\n      continueRender(handle);\r\n      return;\r\n    }\r\n    // An empty, zero-sized inline-block sits with its bottom edge on the text\r\n    // baseline, so its offsetTop *is* the baseline — read off the real font\r\n    // metrics instead of guessed from a line-height ratio.\r\n    const baseline = baselineRef.current?.offsetTop ?? 88;\r\n    const firstLines = beats.map((b) => (b.lines[0] ?? []).join(\" \"));\r\n    const lastLines = beats.map((b) =>\r\n      (b.lines[b.lines.length - 1] ?? []).join(\" \"),\r\n    );\r\n    let inkAscent = firstLines.map(() => 70);\r\n    let inkDescent = lastLines.map(() => 0);\r\n    try {\r\n      const ctx = document.createElement(\"canvas\").getContext(\"2d\");\r\n      if (ctx) {\r\n        ctx.font = `${fontWeight} 100px ${face}`;\r\n        inkAscent = firstLines.map((text) => {\r\n          const a = ctx.measureText(text).actualBoundingBoxAscent;\r\n          return a > 0 ? a : 70;\r\n        });\r\n        inkDescent = lastLines.map((text) =>\r\n          Math.max(0, ctx.measureText(text).actualBoundingBoxDescent),\r\n        );\r\n      }\r\n    } catch {\r\n      // A context can be refused (a headless tab with no GPU, a hardened\r\n      // browser). 0.70em is a sane cap height for any grotesque.\r\n    }\r\n    const lineCount = beats.reduce((n, b) => n + b.lines.length, 0);\r\n    setLineWidths(\r\n      lineRefs.current\r\n        .slice(0, lineCount)\r\n        .map((el) => (el ? el.offsetWidth : 0)),\r\n    );\r\n    setMetrics({ baseline, inkAscent, inkDescent });\r\n  }, [handle, face, fontWeight, beats]);\r\n\r\n  // Release the render only once the measurement has re-rendered, so the very\r\n  // first captured frame already carries the correct geometry.\r\n  useEffect(() => {\r\n    if (metrics) continueRender(handle);\r\n  }, [metrics, handle]);\r\n\r\n  const M: FaceMetrics = metrics ?? {\r\n    baseline: 88,\r\n    inkAscent: beats.map(() => 70),\r\n    inkDescent: beats.map(() => 0),\r\n  };\r\n\r\n  // Index every line of every card into one flat list, so one hidden probe row\r\n  // measures them all and each card can look its own lines up by offset.\r\n  const lineIndex: number[] = [];\r\n  {\r\n    let n = 0;\r\n    for (const beat of beats) {\r\n      lineIndex.push(n);\r\n      n += beat.lines.length;\r\n    }\r\n  }\r\n  // `concat(...map)`, not `flatMap` (ES2019): stock Remotion types ES2015.\r\n  const allLines = ([] as { words: string[]; size: number }[]).concat(\r\n    ...beats.map((beat) =>\r\n      beat.lines.map((words) => ({ words, size: beat.size })),\r\n    ),\r\n  );\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      className={className}\r\n      style={{\r\n        backgroundColor: paper,\r\n        fontFamily: face,\r\n        fontWeight,\r\n        // Hinting re-snaps every stem as a size slides, and the letterforms\r\n        // literally change shape frame to frame. This turns it off and renders\r\n        // the outline as it is — 15× steadier under a scale, measured. The\r\n        // slight softness is the absence of a lie, not blur.\r\n        textRendering: \"geometricPrecision\",\r\n        WebkitFontSmoothing: \"antialiased\",\r\n      }}\r\n    >\r\n      {/*\r\n        Two measuring rows, laid out and never painted, and separate on purpose:\r\n        the baseline probe reads a line box, and a line box grows to fit the\r\n        tallest thing on it. Share a row with a 250px card title and the baseline\r\n        it reports is that title's, not the type's.\r\n      */}\r\n      <div\r\n        aria-hidden\r\n        style={{\r\n          position: \"absolute\",\r\n          top: 0,\r\n          left: 0,\r\n          visibility: \"hidden\",\r\n          pointerEvents: \"none\",\r\n          whiteSpace: \"nowrap\",\r\n        }}\r\n      >\r\n        <span\r\n          ref={probeRef}\r\n          style={{ fontSize: 100, lineHeight: `${lineHeight * 100}px` }}\r\n        >\r\n          Hxg\r\n          <span\r\n            ref={baselineRef}\r\n            style={{ display: \"inline-block\", width: 0, height: 0 }}\r\n          />\r\n        </span>\r\n      </div>\r\n      <div\r\n        aria-hidden\r\n        style={{\r\n          position: \"absolute\",\r\n          top: 0,\r\n          left: 0,\r\n          visibility: \"hidden\",\r\n          pointerEvents: \"none\",\r\n          whiteSpace: \"nowrap\",\r\n        }}\r\n      >\r\n        {allLines.map((line, i) => (\r\n          <span\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: the probe row is positional\r\n            key={i}\r\n            ref={(el) => {\r\n              lineRefs.current[i] = el;\r\n            }}\r\n            style={{\r\n              // inline-block, NOT block. A block-level child of a shrink-to-fit\r\n              // absolutely positioned box fills that box, so every probe reported\r\n              // the *widest line in the whole script* as its own width — and one\r\n              // long card quietly took a size off every other card.\r\n              display: \"inline-block\",\r\n              fontSize: fontSize * line.size,\r\n              lineHeight: `${lineHeight}em`,\r\n              letterSpacing,\r\n              wordSpacing,\r\n            }}\r\n          >\r\n            {line.words.join(\" \")}\r\n          </span>\r\n        ))}\r\n      </div>\r\n\r\n      {beats.map((beat, i) => (\r\n        <Card\r\n          // biome-ignore lint/suspicious/noArrayIndexKey: cards are positional\r\n          key={i}\r\n          beat={beat}\r\n          frame={frame}\r\n          fps={fps}\r\n          width={width}\r\n          fontSize={fontSize}\r\n          lineHeight={lineHeight}\r\n          letterSpacing={letterSpacing}\r\n          wordSpacing={wordSpacing}\r\n          metrics={M}\r\n          beatIndex={i}\r\n          widths={\r\n            lineWidths\r\n              ? lineWidths.slice(\r\n                  lineIndex[i] as number,\r\n                  (lineIndex[i] as number) + beat.lines.length,\r\n                )\r\n              : null\r\n          }\r\n          color={beat.accent ? accentColor : type}\r\n          fit={fit}\r\n          slideFrom={slideFrom}\r\n          slideKick={slideKick}\r\n          slideSettle={slideSettle}\r\n          lineStagger={lineStagger}\r\n          slideDrop={slideDrop}\r\n          motionBlur={motionBlur}\r\n          punchFrom={punchFrom}\r\n          punchFrames={punchFrames}\r\n          wordStagger={wordStagger}\r\n          pushFrom={pushFrom}\r\n          pushRate={pushRate}\r\n          rushLead={rushLead}\r\n          rushFrames={rushFrames}\r\n          rushTravel={rushTravel}\r\n        />\r\n      ))}\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n\r\n/**\r\n * One card.\r\n *\r\n * Nothing here reflows: the type is laid out once at its resting size and every\r\n * beat of the animation is a `scale` or a `translate` on top of it.\r\n */\r\nfunction Card({\r\n  beat,\r\n  frame,\r\n  fps,\r\n  width,\r\n  fontSize,\r\n  lineHeight,\r\n  letterSpacing,\r\n  wordSpacing,\r\n  metrics,\r\n  beatIndex,\r\n  widths,\r\n  color,\r\n  fit,\r\n  slideFrom,\r\n  slideKick,\r\n  slideSettle,\r\n  lineStagger,\r\n  slideDrop,\r\n  motionBlur,\r\n  punchFrom,\r\n  punchFrames,\r\n  wordStagger,\r\n  pushFrom,\r\n  pushRate,\r\n  rushLead,\r\n  rushFrames,\r\n  rushTravel,\r\n}: {\r\n  beat: PunchBeat;\r\n  frame: number;\r\n  fps: number;\r\n  width: number;\r\n  fontSize: number;\r\n  lineHeight: number;\r\n  letterSpacing: string;\r\n  wordSpacing: string;\r\n  metrics: FaceMetrics;\r\n  beatIndex: number;\r\n  widths: number[] | null;\r\n  color: string;\r\n  fit: number;\r\n  slideFrom: number;\r\n  slideKick: number;\r\n  slideSettle: number;\r\n  lineStagger: number;\r\n  slideDrop: number;\r\n  motionBlur: number;\r\n  punchFrom: number;\r\n  punchFrames: number;\r\n  wordStagger: number;\r\n  pushFrom: number;\r\n  pushRate: number;\r\n  rushLead: number;\r\n  rushFrames: number;\r\n  rushTravel: number;\r\n}) {\r\n  if (frame < beat.revealAt || frame >= beat.end) return null;\r\n\r\n  // The card's own clock, in seconds. Everything below is fitted in seconds\r\n  // because the reference is variable-rate and a frame index is not a clock.\r\n  const t = (frame - beat.start) / fps;\r\n\r\n  // Longest line decides whether the whole card has to come down a size, so the\r\n  // block never changes shape when one line happens to be the long one — and it\r\n  // is fitted against the widest the card will ever be, not the width it is laid\r\n  // out at. A punch card keeps growing for its whole life and a slide card swings\r\n  // most of an em either side of centre; a fit that ignores both passes at frame\r\n  // one and runs off the stage later, which is the worst way to find out. The\r\n  // rush is left out on purpose: leaving the frame is what it is for.\r\n  const natural = widths?.length ? Math.max(...widths) : 0;\r\n  const maxPush =\r\n    beat.style === \"punch\"\r\n      ? pushFrom + pushRate * ((beat.end - beat.start) / fps)\r\n      : 1;\r\n  const swing =\r\n    beat.style === \"slide\"\r\n      ? slideSwing(slideFrom, slideKick, slideSettle) * fontSize * beat.size\r\n      : 0;\r\n  const need = natural * maxPush + 2 * swing;\r\n  const shrink = need > width * fit && need > 0 ? (width * fit) / need : 1;\r\n  const em = fontSize * beat.size * shrink;\r\n  const L = lineHeight * em;\r\n\r\n  // A card is centred on its *ink*: the top of its first line's tallest letter\r\n  // down to the bottom of its last line's lowest one. Flexbox centres the *line\r\n  // boxes* instead, and `dy` is the difference — one number, the same for every\r\n  // line of a card.\r\n  const baseline = (metrics.baseline / 100) * em;\r\n  const rise = ((metrics.inkAscent[beatIndex] ?? 70) / 100) * em;\r\n  const fall = ((metrics.inkDescent[beatIndex] ?? 0) / 100) * em;\r\n  const dy =\r\n    L / 2 -\r\n    baseline +\r\n    (rise - fall) / 2 +\r\n    (beat.style === \"slide\" ? slideDrop * em : 0);\r\n\r\n  // The push, and the rush, are both scales about the middle of the frame. The\r\n  // rush's pivot is not a guess: solving the ink centroid across the exit for\r\n  // the fixed point of the scale puts it within a couple of pixels of the frame\r\n  // centre in both axes.\r\n  const push =\r\n    beat.style === \"punch\" ? pushFrom + pushRate * Math.max(0, t) : 1;\r\n  const rushT = (frame - (beat.end - rushLead)) / fps;\r\n  const rush =\r\n    beat.style === \"slide\" && rushT > 0\r\n      ? 1 /\r\n        (1 - rushTravel * RUSH_EASE(Math.min(1, rushT / (rushFrames / fps))))\r\n      : 1;\r\n\r\n  let wordIndex = 0;\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      style={{\r\n        alignItems: \"center\",\r\n        justifyContent: \"center\",\r\n        color,\r\n        transform: `scale(${push * rush})`,\r\n        transformOrigin: \"50% 50%\",\r\n        // The compositor resampling a bitmap is the right trade in a live\r\n        // Player, where a line of type reshaped at a brand-new size every frame\r\n        // will not fit an 8ms budget — and the wrong one in a render, where\r\n        // parallel tabs inherit each other's stale rasters and a still frame\r\n        // shimmers. So it is on in one and off in the other.\r\n        ...(getRemotionEnvironment().isRendering\r\n          ? null\r\n          : { willChange: \"transform\" as const }),\r\n      }}\r\n    >\r\n      {/* The card Studio selects is its block of lines, not the full-frame\r\n          fill around it; it sits inside the push, so the outline scales too. */}\r\n      <Item index={beatIndex}>\r\n        <div\r\n          style={{\r\n            display: \"flex\",\r\n            flexDirection: \"column\",\r\n            alignItems: \"center\",\r\n            transform: `translateY(${dy}px)`,\r\n          }}\r\n        >\r\n          {beat.lines.map((words, li) => {\r\n            // Each line of a slide card leaves after the one above it, and the\r\n            // whole travel is one critically damped move: out at speed, past the\r\n            // mark by 0.71em, home without ever crossing back.\r\n            const lt = t - (li * lineStagger) / fps;\r\n            const slide = (u: number) =>\r\n              beat.style !== \"slide\"\r\n                ? 0\r\n                : u <= 0\r\n                  ? slideFrom * em\r\n                  : (slideFrom * em + slideKick * em * u) *\r\n                    Math.exp(-slideSettle * u);\r\n            const x = slide(lt);\r\n            // The smear is the travel: a box blur one frame wide has a Gaussian\r\n            // equivalent of width/√12, and the reference measures at exactly that.\r\n            const sigma =\r\n              (motionBlur * Math.abs(x - slide(lt - 1 / fps))) / Math.sqrt(12);\r\n            const blurId = `punch-lines-${beatIndex}-${li}`;\r\n\r\n            return (\r\n              <div\r\n                // biome-ignore lint/suspicious/noArrayIndexKey: lines are positional\r\n                key={li}\r\n                style={{\r\n                  whiteSpace: \"nowrap\",\r\n                  fontSize: em,\r\n                  lineHeight: `${L}px`,\r\n                  letterSpacing,\r\n                  wordSpacing,\r\n                  transform: `translateX(${x}px)`,\r\n                  // Under a fifth of a pixel there is nothing to smear, and a\r\n                  // filter that is on for a still frame only costs it sharpness.\r\n                  filter: sigma > 0.2 ? `url(#${blurId})` : undefined,\r\n                }}\r\n              >\r\n                {sigma > 0.2 ? (\r\n                  <svg\r\n                    aria-hidden\r\n                    width={0}\r\n                    height={0}\r\n                    style={{ position: \"absolute\" }}\r\n                  >\r\n                    <title>motion blur</title>\r\n                    <filter\r\n                      id={blurId}\r\n                      x=\"-25%\"\r\n                      y=\"-25%\"\r\n                      width=\"150%\"\r\n                      height=\"150%\"\r\n                      colorInterpolationFilters=\"sRGB\"\r\n                    >\r\n                      <feGaussianBlur stdDeviation={`${sigma} 0`} />\r\n                    </filter>\r\n                  </svg>\r\n                ) : null}\r\n                {words.map((word, wi) => {\r\n                  const w = wordIndex++;\r\n                  const wt = t - (w * wordStagger) / fps;\r\n                  const p =\r\n                    beat.style === \"punch\"\r\n                      ? PUNCH_EASE(\r\n                          Math.max(0, Math.min(1, wt / (punchFrames / fps))),\r\n                        )\r\n                      : 1;\r\n                  const s =\r\n                    beat.style === \"punch\"\r\n                      ? punchFrom + (1 - punchFrom) * p\r\n                      : 1;\r\n                  return (\r\n                    // A trailing space inside an inline-block is stripped — it\r\n                    // sits at the end of that box's line and CSS removes it — so\r\n                    // the separator goes *between* the spans, never inside one.\r\n                    <Fragment key={w}>\r\n                      {wi > 0 ? \" \" : null}\r\n                      <span\r\n                        style={{\r\n                          display: \"inline-block\",\r\n                          transform: `scale(${s})`,\r\n                          // Not the baseline. The reference's words plainly grow\r\n                          // about their own middles — at a third of their size\r\n                          // they sit on a shared centre line, with their baselines\r\n                          // nowhere near each other — and half the line box is\r\n                          // that middle for a face whose ascent and descent\r\n                          // straddle it evenly.\r\n                          transformOrigin: `50% ${L / 2}px`,\r\n                        }}\r\n                      >\r\n                        {word}\r\n                      </span>\r\n                    </Fragment>\r\n                  );\r\n                })}\r\n              </div>\r\n            );\r\n          })}\r\n        </div>\r\n      </Item>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}