{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "live-captions",
  "title": "LiveCaptions",
  "description": "A caption band for a live call or video: what people are saying, as they say it.",
  "registryDependencies": [
    "@ouro/ax-component",
    "@ouro/lib-announce",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-reduced-motion"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/live-captions/live-captions-styles.ts",
      "content": "export {\n  ANNOUNCE_GAP_MS,\n  bandClass,\n  bandSizes,\n  firstName,\n  finalWordsClass,\n  interimWordsClass,\n  labelClass,\n  linesClass,\n  linesSizes,\n  liveCaptionsAx,\n  MAX_LINES_DEFAULT,\n  MAX_LINES_MAX,\n  MAX_LINES_MIN,\n  placeholderClass,\n  speakerClass,\n  spokenText,\n  trackClass,\n  unavailableClass,\n};\n\n// Class strings, values, helpers and the agent side for LiveCaptions, apart from the component so\n// its file exports only components and types (React Fast Refresh). Class strings are literal so\n// the app's Tailwind finds them when it compiles.\n\nimport { defineComponentAx } from \"@/registry/ouro/ax/component\";\n\n/** How many lines the band shows without `maxLines`. @internal */\nconst MAX_LINES_DEFAULT = 2;\n/**\n * The fewest lines a band shows. @internal\n * @claim \"The fewest lines a band shows.\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps 2 lines by default, or the nearest whole number from 1 to 6)\n */\nconst MAX_LINES_MIN = 1;\n/**\n * The most lines a band shows. @internal\n * @claim \"The most lines a band shows.\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps 2 lines by default, or the nearest whole number from 1 to 6)\n */\nconst MAX_LINES_MAX = 6;\n\n/**\n * The shortest gap between two announcements, in milliseconds. @internal\n * @claim \"The shortest gap between two announcements,\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > reads at most one announcement every 2 seconds, and batches the lines that finish in between into the next)\n */\nconst ANNOUNCE_GAP_MS = 2000;\n\n/**\n * The first word of a speaker's name, which the band shows: \"Mara\" for \"Mara Lind\". @internal\n * @claim \"The first word of a speaker's\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows each line as the speaker's first name in a tint of the brand colour, then their words)\n */\nfunction firstName(speaker: string): string {\n  return speaker.trim().split(/\\s/)[0]!;\n}\n\n/** A finished line, as an announcement reads it. @internal */\ninterface SpokenLine {\n  speaker: string;\n  text: string;\n}\n\n/**\n * What one announcement says for lines that finished together: each speaker's full name once,\n * then what they said, as \"Mara Lind: First. Second. Jonas Ek: Third.\" @internal\n * @claim \"What one announcement says for lines\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > reads at most one announcement every 2 seconds, and batches the lines that finish in between into the next)\n */\nfunction spokenText(lines: readonly SpokenLine[]): string {\n  const parts: string[] = [];\n  let previous: string | undefined;\n  for (const { speaker, text } of lines) {\n    parts.push(speaker === previous ? text : `${speaker}: ${text}`);\n    previous = speaker;\n  }\n  return parts.join(\" \");\n}\n\n/**\n * The band: a solid, translucent black fill with rounded corners, no blur, readable over any\n * picture. Solid black when the system asks for reduced transparency, solid black with a white\n * edge when it asks for more contrast, and Canvas with a CanvasText edge under forced colours.\n * @internal\n * @claim \"The band: a solid, translucent black\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > draws a solid translucent black band with rounded corners and no blur)\n * @claim \"Solid black when the system asks\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > goes solid black under reduced transparency, and white on solid black with an edge under more contrast)\n * @claim \"Canvas with a CanvasText edge under\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps its words and fill apart under forced colours, with an edge around the band)\n */\nconst bandClass =\n  \"box-border grid w-full gap-1 rounded-ouro-xl bg-black/80 text-start text-white \" +\n  \"[@media(prefers-reduced-transparency:reduce)]:bg-black \" +\n  \"contrast-more:bg-black contrast-more:border contrast-more:border-solid contrast-more:border-white \" +\n  \"forced-colors:border forced-colors:border-solid forced-colors:border-[CanvasText] forced-colors:bg-[Canvas]\";\n\n/**\n * The band's padding at each size. @internal\n * @claim \"The band's padding at each size.\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > sets its words at 14, 18 and 24px on 20, 28 and 32px lines, md by default)\n */\nconst bandSizes = { sm: \"px-3 py-1.5\", md: \"px-4 py-2\", lg: \"px-5 py-3\" } as const;\n\n/** The visible label, small and quiet over the lines. @internal */\nconst labelClass = \"m-0 text-xs font-medium text-white/75 contrast-more:text-white forced-colors:text-[CanvasText]\";\n\n/**\n * The window onto the lines: exactly `--ouro-live-captions-lines` lines of its own line height\n * tall, whatever the lines hold, so the band never changes height. @internal\n * @claim \"exactly `--ouro-live-captions-lines` lines of its own\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is exactly maxLines lines tall, empty, full and overflowing, so nothing around it moves)\n */\nconst linesClass = \"relative h-[calc(var(--ouro-live-captions-lines)*1lh)] overflow-hidden\";\n\n/**\n * The words' size and line height at each band size. @internal\n * @claim \"The words' size and line height\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > sets its words at 14, 18 and 24px on 20, 28 and 32px lines, md by default)\n */\nconst linesSizes = { sm: \"text-sm/5\", md: \"text-lg/7\", lg: \"text-2xl/8\" } as const;\n\n/**\n * The column of lines, held to the bottom of the window so the newest words sit on the last\n * line and older ones leave over the top edge. When a line pushes the others up, they slide\n * there over `--ouro-duration-base`; with reduced motion (the device's, or `OuroProvider`'s)\n * they jump. @internal\n * @claim \"The column of lines, held to\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is exactly maxLines lines tall, empty, full and overflowing, so nothing around it moves)\n * @claim \"they slide there over `--ouro-duration-base`; with\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions motion > slides older lines up and off the top as a new line comes, and with reduced motion moves them at once)\n */\nconst trackClass =\n  \"absolute inset-x-0 bottom-0 flex flex-col \" +\n  \"transition-[translate] duration-(--ouro-duration-base) ease-(--ouro-ease-out)\";\n\n/**\n * The speaker's first name: a light tint of the brand colour, which keeps 4.5:1 on the band\n * whatever the theme's primary. White under more contrast, CanvasText under forced colours.\n * @internal\n * @claim \"which keeps 4.5:1 on the band\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps names and words at 4.5:1 or more over a white picture, under stock shadcn and Ouro colours)\n */\nconst speakerClass =\n  \"font-semibold text-[color-mix(in_oklab,var(--primary)_35%,white)] contrast-more:text-white forced-colors:text-[CanvasText]\";\n\n/** Words that are final: white. @internal */\nconst finalWordsClass = \"text-white transition-colors duration-(--ouro-duration-fast) ease-[ease] forced-colors:text-[CanvasText]\";\n\n/**\n * Words that may still change: white at 70%, which keeps 4.5:1 on the band, and GrayText under\n * forced colours. They turn white in place when final: only their colour changes. @internal\n * @claim \"Words that may still change: white\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > turns interim words white in place when they become final, moving nothing)\n * @claim \"Words that may still change: white\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps names and words at 4.5:1 or more over a white picture, under stock shadcn and Ouro colours)\n * @claim \"They turn white in place when\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > turns interim words white in place when they become final, moving nothing)\n */\nconst interimWordsClass =\n  \"text-white/70 transition-colors duration-(--ouro-duration-fast) ease-[ease] contrast-more:text-white forced-colors:text-[GrayText]\";\n\n/**\n * The line before anyone speaks: on the last line, muted like words that may still change.\n * @internal\n * @claim \"The line before anyone speaks: on\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows a quiet placeholder line, never read aloud, until the first line comes)\n */\nconst placeholderClass = \"absolute inset-x-0 bottom-0 m-0 text-white/70 contrast-more:text-white forced-colors:text-[GrayText]\";\n\n/**\n * Why there are no captions, in white on the last lines. @internal\n * @claim \"Why there are no captions, in\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows why captions are unavailable in place of the lines, at the same height, and reads nothing)\n */\nconst unavailableClass = \"absolute inset-x-0 bottom-0 text-white forced-colors:text-[CanvasText]\";\n\n/**\n * LiveCaptions' agent side, declared with Ouro AX's `defineComponentAx`. Its one read, `captions`, is what people say (the\n * speaker and words from `lines`, and `at`, when they were said, from the app's caption feed), which\n * an agent may read only while the person has asked it to follow the meeting (`consent:\n * \"listening\"`), and only through a filtered watch (`push: \"filtered\"`). It declares no actions:\n * turning captions on and off is declared once, in a calling app's own controls.\n *\n * @example\n * liveCaptionsAx.reads[0].consent; // \"listening\"\n * @claim \"It declares no actions: turning captions\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > declares one agent read, the captions, behind listening consent and a filtered push, and no actions)\n * @claim \"Its one read, `captions`, is what\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > declares one agent read, the captions, behind listening consent and a filtered push, and no actions)\n */\nconst liveCaptionsAx = defineComponentAx({\n  component: \"LiveCaptions\",\n  reads: [\n    {\n      id: \"captions\",\n      summary: \"What people say, once the person asks you to follow the meeting.\",\n      fields: [\"speaker\", \"text\", \"at\"],\n      consent: \"listening\",\n      push: \"filtered\",\n    },\n  ],\n  actions: [],\n});\n",
      "type": "registry:ui",
      "target": "@components/ouro/live-captions/live-captions-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/live-captions/live-captions.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, type CSSProperties, type JSX, type ReactNode, type Ref } from \"react\";\nimport {\n  ANNOUNCE_GAP_MS,\n  bandClass,\n  bandSizes,\n  finalWordsClass,\n  firstName,\n  interimWordsClass,\n  labelClass,\n  linesClass,\n  linesSizes,\n  MAX_LINES_DEFAULT,\n  MAX_LINES_MAX,\n  MAX_LINES_MIN,\n  placeholderClass,\n  speakerClass,\n  spokenText,\n  trackClass,\n  unavailableClass,\n} from \"@/registry/ouro/components/ouro/live-captions/live-captions-styles\";\nimport { announce as speak } from \"@/registry/ouro/lib/ouro/announce\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\n\n/** One caption line: who is speaking and what they have said so far. */\nexport interface LiveCaptionLine {\n  /** Stays the same while the line firms up, so the app replaces an interim line by its id. */\n  id: string;\n  /** Who said it, in full: \"Mara Lind\". The band shows the first word; an announcement reads it whole. */\n  speaker: string;\n  /** What they said so far. */\n  text: string;\n  /**\n   * `true` once the words will not change. Words that are not final show muted and are never announced.\n   * @claim \"Words that are not final show\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > announces a line once, when it becomes final, and never its interim words)\n   */\n  final: boolean;\n  /** Not a field. A line says it is final with `final`: `{ id, speaker, text, final: true }`. */\n  isFinal?: { 'Use final: true': never };\n}\n\n/** Props for {@link LiveCaptions}. */\nexport interface LiveCaptionsProps {\n  /**\n   * The caption lines, in the order they were said. Feed it as the words come: add a line when\n   * someone starts speaking, replace it by its `id` as its words grow, and mark it `final` when\n   * they are settled. The band shows the newest lines and lets older ones go over its top. Pass\n   * the recent lines only (a few more than `maxLines`), not the meeting's whole history.\n   * @claim \"The band shows the newest lines\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is exactly maxLines lines tall, empty, full and overflowing, so nothing around it moves)\n   */\n  lines: readonly LiveCaptionLine[];\n  /** What the band is: \"Captions\". It names the band for screen readers. */\n  label: string;\n  /**\n   * Hides the label visually; screen readers still use it.\n   * @claim \"Hides the label visually; screen readers\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is a region named by its label, which hideLabel hides from sight only)\n   */\n  hideLabel?: boolean | undefined;\n  /**\n   * The words' size: 14, 18 or 24px. Let the person choose.\n   * @default \"md\"\n   * @claim \"The words' size: 14, 18 or\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > sets its words at 14, 18 and 24px on 20, 28 and 32px lines, md by default)\n   */\n  size?: \"sm\" | \"md\" | \"lg\" | (string & { 'Use \"sm\", \"md\" or \"lg\"': never }) | undefined;\n  /**\n   * How many lines tall the band is, a whole number from 1 to 6. The band is always that\n   * tall, empty or full, so nothing around it moves as captions come and go. In a narrow\n   * layout a long line wraps and takes more of the band, so give it a line more there.\n   * @default 2\n   * @claim \"How many lines tall the band\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > keeps 2 lines by default, or the nearest whole number from 1 to 6)\n   * @claim \"The band is always that tall,\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is exactly maxLines lines tall, empty, full and overflowing, so nothing around it moves)\n   */\n  maxLines?: number | undefined;\n  /**\n   * Reads final lines aloud to screen readers. Off by default, because captions read aloud talk\n   * over the call: turn it on when the person asks for captions read aloud.\n   * @default false\n   * @claim \"Reads final lines aloud to screen readers.\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > announces a line once, when it becomes final, and never its interim words)\n   * @claim \"Off by default, because captions read\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > announces nothing by default, nor once announce is turned off)\n   */\n  announce?: boolean | undefined;\n  /**\n   * The quiet line the band shows before anyone has spoken, so the person can see captions are\n   * on. Muted, and never read aloud. Translate it here.\n   * @default \"Waiting for someone to speak…\"\n   * @claim \"Muted, and never read aloud.\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows a quiet placeholder line, never read aloud, until the first line comes)\n   * @claim \"The quiet line the band shows\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows a quiet placeholder line, never read aloud, until the first line comes)\n   */\n  placeholder?: ReactNode;\n  /**\n   * Why captions are missing, when the meeting doesn't offer them: \"Captions aren't available\n   * in this meeting\". The band shows it in place of the lines, at the same height, and shows\n   * and reads no lines while it is set.\n   * @claim \"The band shows it in place\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows why captions are unavailable in place of the lines, at the same height, and reads nothing)\n   */\n  unavailable?: ReactNode;\n  /** Layout only: width, margins, placement (`max-w-3xl`, `mx-auto`). Appearance classes warn in development; use `size`. */\n  className?: string | undefined;\n  /** The band's id, for `aria-describedby` or `aria-controls` elsewhere on the page. */\n  id?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. The lines are `lines`: `<LiveCaptions lines={lines}>`. */\n  captions?: { 'Use <LiveCaptions lines={lines}>': never };\n  /** Not a prop. Ouro UI uses `announce`: `<LiveCaptions announce>`. */\n  readAloud?: { 'Use <LiveCaptions announce>': never };\n  /** Not a prop. Before anyone speaks the band shows `placeholder`; when the meeting doesn't offer captions, `unavailable`. */\n  status?: { 'Use placeholder, or unavailable when the meeting does not offer captions': never };\n}\n\n/**\n * Where the lines sit in the window, by layout (so a slide under way doesn't count). A line\n * wholly over the top edge is out of sight, so screen readers skip it too.\n */\nfunction place(track: HTMLElement): Map<string, number> {\n  const tops = new Map<string, number>();\n  for (const row of track.children as HTMLCollectionOf<HTMLElement>) {\n    const top = track.offsetTop + row.offsetTop;\n    tops.set(row.dataset[\"ouroLiveCaptionsLine\"]!, top);\n    if (top + row.offsetHeight <= 0) row.setAttribute(\"aria-hidden\", \"true\");\n    else row.removeAttribute(\"aria-hidden\");\n  }\n  return tops;\n}\n\n/**\n * A caption band for a live call or video: what people are saying, as they say it. Each line is\n * the speaker's first name in a light tint of the brand colour, then their words. Words that\n * may still change are muted and turn white when final, in place, without the line moving.\n *\n * The band is a solid, translucent black fill with rounded corners and no blur, so it reads\n * over any picture; put it in its own space under the pictures, never over a face. It is\n * always `maxLines` lines tall, two by default, so the layout never jumps as captions come and\n * go; the newest words sit on the last line, and older lines slide up and off the top (with\n * reduced motion they move at once). Resized, or given a new `size` or `maxLines`, the lines\n * take their new places without a slide. Lines wholly over the top edge are hidden from screen\n * readers too. Before anyone speaks it shows a quiet `placeholder` line, and when the meeting\n * doesn't offer captions it shows why, from `unavailable`, in place of the lines.\n *\n * It is a region named by its `label`. With `announce`, it reads each line aloud once, when it\n * becomes final, through one polite live region, never a line's interim words; it says at most\n * one announcement every 2 seconds and gathers the lines that finish in between into the next,\n * so a fast talker doesn't flood a screen reader. Lines that were already final when\n * announcing began are not read. `announce` is off by default, since captions read aloud would\n * talk over the call. Hidden (under a hidden `<Activity>`, say) and shown again, it reads only\n * the lines that become final from then on.\n *\n * Its agent side, `liveCaptionsAx` in `live-captions-styles.ts`, declares one read, `captions`\n * (the speaker, the words, and when they were said, which comes from the app's caption feed),\n * which an agent may read only while the person has asked it to follow the meeting (consent\n * `listening`), and only through a filtered watch, never every word pushed. It declares no\n * actions: turning captions on and off is the person's, declared once in a calling app's own\n * controls.\n *\n * Use `Toaster` instead for a passing notice, `Text` for subtitles that don't change, and\n * `MessageList` for a transcript the person can scroll back through.\n *\n * @claim \"Each line is the speaker's first\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows each line as the speaker's first name in a tint of the brand colour, then their words)\n * @claim \"Words that may still change are\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > turns interim words white in place when they become final, moving nothing)\n * @claim \"The band is a solid, translucent\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > draws a solid translucent black band with rounded corners and no blur)\n * @claim \"It is always `maxLines` lines tall,\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is exactly maxLines lines tall, empty, full and overflowing, so nothing around it moves)\n * @claim \"It is always `maxLines` lines tall,\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions motion > slides older lines up and off the top as a new line comes, and with reduced motion moves them at once)\n * @claim \"Resized, or given a new `size`\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions motion > takes new places without a slide after a resize, a new size or a new maxLines)\n * @claim \"Lines wholly over the top edge\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > hides lines wholly over the top edge from screen readers, as they leave and when a line wraps)\n * @claim \"Before anyone speaks it shows a\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows a quiet placeholder line, never read aloud, until the first line comes)\n * @claim \"when the meeting doesn't offer captions\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > shows why captions are unavailable in place of the lines, at the same height, and reads nothing)\n * @claim \"It is a region named by\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > is a region named by its label, which hideLabel hides from sight only)\n * @claim \"With `announce`, it reads each line\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > announces a line once, when it becomes final, and never its interim words)\n * @claim \"it says at most one announcement\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > reads at most one announcement every 2 seconds, and batches the lines that finish in between into the next)\n * @claim \"Hidden (under a hidden `<Activity>`, say)\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > hidden under an Activity and shown again, reads only the lines that become final after)\n * @claim \"Lines that were already final when\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > does not read lines that were final before announcing began)\n * @claim \"`announce` is off by default, since\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions announcements > announces nothing by default, nor once announce is turned off)\n * @claim \"It declares no actions: turning captions\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > declares one agent read, the captions, behind listening consent and a filtered push, and no actions)\n * @claim \"Its agent side, `liveCaptionsAx` in `live-captions-styles.ts`,\" registry/ouro/components/ouro/live-captions/live-captions.test.tsx verify:testExists(registry/ouro/components/ouro/live-captions/live-captions.test.tsx::LiveCaptions > declares one agent read, the captions, behind listening consent and a filtered push, and no actions)\n * @group Display\n * @see https://ui.ouroboros.bot/docs/live-captions\n *\n * @example\n * <LiveCaptions label=\"Captions\" hideLabel lines={[{ id: \"1\", speaker: \"Mara Lind\", text: \"Shall we start?\", final: true }]} />\n * <LiveCaptions label=\"Captions\" lines={lines} size=\"lg\" announce={readAloud} />\n * <LiveCaptions label=\"Captions\" lines={[]} unavailable=\"Captions aren't available in this meeting\" />\n */\nexport function LiveCaptions(props: LiveCaptionsProps): JSX.Element {\n  const {\n    lines,\n    label,\n    hideLabel,\n    size: sizeProp = \"md\",\n    maxLines: maxLinesProp = MAX_LINES_DEFAULT,\n    announce = false,\n    placeholder = \"Waiting for someone to speak…\",\n    unavailable,\n    className,\n    id,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    captions,\n    readAloud,\n    status,\n  } = props;\n  const size = Object.hasOwn(bandSizes, sizeProp) ? (sizeProp as keyof typeof bandSizes) : \"md\";\n  const maxLines = Math.min(Math.max(Math.round(maxLinesProp), MAX_LINES_MIN), MAX_LINES_MAX) || MAX_LINES_DEFAULT;\n  // An id of our own puts aria-labelledby in the server HTML too.\n  const labelId = `${useId()}-label`;\n  const reduced = useReducedMotion();\n  useAppearanceClassNameCheck(\n    \"LiveCaptions\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; the band keeps its own look over video, and size=\"lg\" makes the words larger`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"LiveCaptions\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          size !== sizeProp && [`size=\"${String(sizeProp)}\" is not a size; use \"sm\", \"md\", \"lg\"`, '<LiveCaptions size=\"md\">'],\n          maxLines !== maxLinesProp && [`maxLines={${String(maxLinesProp)}} is not a whole number from ${MAX_LINES_MIN} to ${MAX_LINES_MAX}`, `<LiveCaptions maxLines={${maxLines}}>`],\n          new Set(lines.map((line) => line.id)).size !== lines.length && [\"two lines share an id; give each line its own and keep it while the line firms up\", '<LiveCaptions lines={[{ id: \"a1\", speaker, text, final }]}>'],\n          lines.some((line) => \"isFinal\" in line) && [\"isFinal is not a line field\", \"{ id, speaker, text, final: true }\"],\n          captions !== undefined && [\"captions is not a prop\", \"<LiveCaptions lines={lines}>\"],\n          readAloud !== undefined && [\"readAloud is not a prop\", \"<LiveCaptions announce>\"],\n          status !== undefined && [\"status is not a prop; before anyone speaks the band shows placeholder, and unavailable says why there are no captions\", `<LiveCaptions placeholder=\"Waiting for someone to speak…\" unavailable=\"Captions aren't available in this meeting\">`],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // The newest lines, and one more above them, out of sight over the top edge until it leaves:\n  // a line that pushes the others up slides them there, and the one leaving goes over the edge.\n  // While the meeting has no captions, the band shows why, and no lines.\n  const off = unavailable !== undefined && unavailable !== null && typeof unavailable !== \"boolean\" && unavailable !== \"\";\n  const shown = off ? [] : lines.slice(-(maxLines + 1));\n\n  const trackRef = useRef<HTMLDivElement>(null);\n  const tops = useRef(new Map<string, number>());\n  // Stryker disable next-line ArrayDeclaration: the first layout effect has no line from before, so nothing slides whatever shape it starts from.\n  const shape = useRef([size, maxLines]);\n  useLayoutEffect(() => {\n    const track = trackRef.current!;\n    const now = place(track);\n    const kept = [...now.keys()].find((line) => tops.current.has(line));\n    // With no line kept from before, rise is NaN, and nothing slides.\n    const rise = tops.current.get(kept!)! - now.get(kept!)!;\n    tops.current = now;\n    // A new size or height moves the lines by a fraction of a line: they take their places at once.\n    const reshaped = shape.current[0] !== size || shape.current[1] !== maxLines;\n    shape.current = [size, maxLines];\n    if (reduced || reshaped || !(rise > 0)) return;\n    // Start the lines where they were drawn (with any slide still under way) and let them slide up.\n    const [, under = \"0\"] = getComputedStyle(track).translate.split(\" \");\n    track.style.transition = \"none\";\n    track.style.translate = `0 ${rise + parseFloat(under)}px`;\n    // Reading the style applies the start before the transition comes back.\n    void getComputedStyle(track).translate;\n    track.style.transition = \"\";\n    track.style.translate = \"\";\n  });\n\n  // Announcing: the ids that were final last time, the lines waiting to be read, and the gap timer.\n  const heard = useRef<Set<string> | null>(null);\n  const waiting = useRef<LiveCaptionLine[]>([]);\n  const gap = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const reading = announce && !off;\n  useEffect(() => {\n    const finals = new Set(lines.filter((line) => line.final).map((line) => line.id));\n    if (!reading) {\n      heard.current = null;\n      waiting.current = [];\n      clearTimeout(gap.current);\n      gap.current = undefined;\n      return;\n    }\n    // Announcing begins: what is already final has been seen, not just said.\n    const before = heard.current ?? finals;\n    heard.current = finals;\n    waiting.current.push(...lines.filter((line) => line.final && !before.has(line.id)));\n    const flush = () => {\n      if (waiting.current.length === 0) {\n        gap.current = undefined;\n        return;\n      }\n      speak(spokenText(waiting.current));\n      waiting.current = [];\n      gap.current = setTimeout(flush, ANNOUNCE_GAP_MS);\n    };\n    if (gap.current === undefined) flush();\n  }, [reading, lines]);\n  // Hidden (unmounted, under a hidden <Activity>, or by Fast Refresh), the band lets go of its timer,\n  // its queue, what it has heard and where its lines were, so shown again it starts like a new band:\n  // no slide, nothing read from before, and the next final line read at once.\n  useEffect(() => {\n    const track = trackRef.current!;\n    // A resize rewraps the lines without a render: they take their new places, without a slide.\n    const resize = new ResizeObserver(() => void (tops.current = place(track)));\n    resize.observe(track);\n    return () => {\n      resize.disconnect();\n      clearTimeout(gap.current);\n      gap.current = undefined;\n      waiting.current = [];\n      heard.current = null;\n      tops.current = new Map();\n    };\n  },\n  // Stryker disable next-line ArrayDeclaration: any constant dependency list runs the setup on show and the cleanup on hide, and nowhere else.\n  []);\n\n  return (\n    <div\n      ref={ref}\n      id={id}\n      role=\"region\"\n      aria-labelledby={labelId}\n      data-ouro=\"live-captions\"\n      data-size={size}\n      className={cn(bandClass, bandSizes[size], className)}\n      style={{ \"--ouro-live-captions-lines\": maxLines } as CSSProperties}\n    >\n      <p id={labelId} data-ouro-live-captions-label=\"\" className={hideLabel ? \"sr-only\" : labelClass}>\n        {label}\n      </p>\n      <div\n        data-ouro-live-captions-window=\"\"\n        data-ouro-allow=\"clipped-text\"\n        data-ouro-allow-why=\"The window scrolls older lines out of view on purpose\"\n        className={cn(linesClass, linesSizes[size])}\n      >\n        <div ref={trackRef} data-ouro-live-captions-track=\"\" className={trackClass}>\n          {shown.map((line) => (\n            <p key={line.id} data-ouro-live-captions-line={line.id} data-final={line.final ? \"\" : undefined} className=\"m-0\">\n              <span data-ouro-live-captions-speaker=\"\" className={speakerClass}>\n                {firstName(line.speaker)}\n              </span>\n              <span className=\"sr-only\">:</span>{\" \"}\n              <span data-ouro-live-captions-words=\"\" className={line.final ? finalWordsClass : interimWordsClass}>\n                {line.text}\n              </span>\n            </p>\n          ))}\n        </div>\n        {off ? (\n          <div data-ouro-live-captions-unavailable=\"\" className={unavailableClass}>\n            {unavailable}\n          </div>\n        ) : (\n          shown.length === 0 && (\n            <p data-ouro-live-captions-placeholder=\"\" className={placeholderClass}>\n              {placeholder}\n            </p>\n          )\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/live-captions/live-captions.tsx"
    }
  ],
  "docs": "A caption band for a live call or video: what people are saying, as they say it. Import: import { LiveCaptions } from \"@/components/ouro/live-captions/live-captions\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: ax-component, ax-effects, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/live-captions.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}