{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-area",
  "title": "TextArea",
  "description": "A labeled multi-line text field on the Field contract, a native `<textarea>`: pass `label`, and `error` from your server action or client check.",
  "registryDependencies": [
    "@ouro/field",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-refs",
    "@ouro/lib-tones",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field",
    "@ouro/text-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/text-field/text-area-styles.ts",
      "content": "import type { TextAreaHighlight } from \"@/registry/ouro/components/ouro/text-field/text-area\";\nimport type { DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { renamedTones } from \"@/registry/ouro/lib/ouro/tones\";\n\nexport {\n  describeHighlights,\n  fitHeight,\n  fitHeightNative,\n  supportsFieldSizing,\n  canFieldSize,\n  highlightLayerClass,\n  highlightRuns,\n  highlightTone,\n  highlightTones,\n  highlightWarnings,\n  highlightsKey,\n  mirroredStyles,\n  moveHighlights,\n  normalizeHighlights,\n  textAreaClass,\n  textAreaSizes,\n  textAreaVariants,\n};\nexport type { HighlightEdit, HighlightRun };\n\n// Class strings and the autoGrow measurement for TextArea, apart from the component so its\n// file exports only components (React Fast Refresh). Class strings are literal so the app's\n// Tailwind finds them when it compiles.\n\n/**\n * The textarea, whatever its variant and size. The user can drag its height unless it grows\n * by itself.\n *\n * @internal\n */\nconst textAreaClass =\n  \"m-0 box-border block w-full min-w-0 rounded-ouro-md text-foreground \" +\n  \"font-[inherit] placeholder:text-muted-foreground \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"disabled:cursor-not-allowed disabled:opacity-50\";\n\n/**\n * The textarea's frame. `outline` is Field's control look. `plain` draws no border,\n * background or padding, for a textarea inside a frame the app draws (a chat composer); it\n * keeps the corner radius, which only the focus outline shows.\n *\n * @internal\n * @claim \"`plain` draws no border, background or\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > draws no frame of its own with variant plain, and still outlines on keyboard focus)\n */\nconst textAreaVariants = {\n  outline:\n    \"px-3 py-2 border border-solid border-input bg-transparent \" +\n    \"transition-[border-color] duration-(--ouro-duration-fast) ease-[ease] \" +\n    \"aria-invalid:border-destructive dark:bg-input/30\",\n  plain: \"p-0 border-0 bg-transparent\",\n} as const;\n\n/**\n * The textarea's font size. `md` is a 16px font on 24px lines on phones (iOS zooms into\n * smaller text on focus), stepping down to 14px on 20px lines from the `sm` breakpoint with a\n * fine pointer, so a landscape phone keeps the phone size. `lg` is 20px on 28px lines at\n * every width.\n *\n * @internal\n * @claim \"`lg` is 20px on 28px lines\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > sets 20px text on 28px lines with size lg, at phone and desktop widths)\n * @claim \"`md` is a 16px font on\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea > uses a 16px font on phones, so iOS does not zoom on focus)\n */\nconst textAreaSizes = {\n  md: \"text-base leading-6 sm:pointer-fine:text-sm sm:pointer-fine:leading-5\",\n  lg: \"text-xl leading-7\",\n} as const;\n\n/**\n * Whether the browser sizes a textarea to its content itself (`field-sizing: content`). WebKit\n * answers yes but leaves a wrapped textarea at its old height when its width changes, so it measures.\n *\n * @internal\n */\nfunction supportsFieldSizing(): boolean {\n  // Stryker disable next-line ConditionalExpression,OptionalChaining: a server render has no CSS or navigator.supports to ask, and every browser that runs the effect has both.\n  return canFieldSize(navigator.userAgent, globalThis.CSS?.supports?.(\"field-sizing\", \"content\") === true);\n}\n\n/**\n * The decision behind `supportsFieldSizing`, from the user agent and whether the browser parses the property.\n *\n * @internal\n */\nfunction canFieldSize(userAgent: string, parses: boolean): boolean {\n  const webkit = /AppleWebKit/.test(userAgent) && !/Chrome|Chromium|Edg/.test(userAgent);\n  return !webkit && parses;\n}\n\n/**\n * Where the browser grows the textarea itself, sets only the bounds: `rows` and `maxRows`\n * lines in `lh` units, plus the padding and border, and measures nothing as the text or the\n * width changes. The browser scrolls it once it passes the cap.\n *\n * @internal\n */\nfunction fitHeightNative(textarea: HTMLTextAreaElement, rows: number, maxRows: number | undefined): void {\n  const style = getComputedStyle(textarea);\n  const extra = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom) + parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);\n  textarea.style.setProperty(\"field-sizing\", \"content\");\n  textarea.style.height = \"\";\n  textarea.style.overflowY = \"\";\n  textarea.style.minHeight = `calc(${rows}lh + ${extra}px)`;\n  textarea.style.maxHeight = maxRows === undefined ? \"\" : `calc(${Math.max(rows, maxRows)}lh + ${extra}px)`;\n}\n\n/**\n * Sizes a textarea to its content, between `rows` and `maxRows` lines, and lets it scroll\n * only once it is capped. What scrolls around it stays where it was while it measures. Only an `autoGrow` TextArea calls it; without `autoGrow` the\n * inline height belongs to the user's resize handle.\n *\n * @internal\n */\nfunction fitHeight(textarea: HTMLTextAreaElement, rows: number, maxRows: number | undefined): void {\n  const style = getComputedStyle(textarea);\n  const line = parseFloat(style.lineHeight);\n  const padding = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);\n  const border = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);\n  const min = rows * line + padding + border;\n  const max = maxRows === undefined ? Infinity : Math.max(min, maxRows * line + padding + border);\n  // Collapse first so scrollHeight measures the content, not the current height. Collapsing can\n  // pull up the end of what scrolls around it (a conversation it sits at the end of), and the\n  // browser then scrolls that back into range, so each of those is put back where it was.\n  const scrolled: [Element, number][] = [];\n  // Stryker disable next-line EqualityOperator,ConditionalExpression: at 0 nothing can pull it further up, and putting 0 back changes nothing.\n  for (let around = textarea.parentElement; around !== null; around = around.parentElement) if (around.scrollTop > 0) scrolled.push([around, around.scrollTop]);\n  textarea.style.height = `${min}px`;\n  const needed = textarea.scrollHeight + border;\n  textarea.style.height = `${Math.min(Math.max(needed, min), max)}px`;\n  textarea.style.overflowY = needed > max + 0.5 ? \"auto\" : \"hidden\";\n  for (const [around, top] of scrolled) around.scrollTop = top;\n}\n\n/**\n * The layer that draws the marks: the textarea's text again, transparent, in the same box,\n * so a mark wraps as its words do. It sits over the textarea, and the pointer passes through\n * it. Its text keeps the textarea's colour, so contrast checkers read it as they read the\n * textarea's, but is filled transparent. Forced colours leave it alone, so its text stays\n * transparent and the underlines show, in the system's text colour.\n *\n * @internal\n */\nconst highlightLayerClass =\n  \"pointer-events-none absolute inset-0 box-border overflow-hidden border-solid border-transparent \" +\n  \"[-webkit-text-fill-color:transparent] whitespace-pre-wrap break-words select-none forced-color-adjust-none\";\n\n/**\n * The marks' looks, by tone. `destructive` and `warning` draw a wavy underline, as spelling and\n * grammar checkers do; the others a dotted underline on a faint tint of the tone. The line's\n * style says it is a mark, so colour is not the only sign of it.\n *\n * @internal\n */\nconst highlightTones = {\n  primary: \"bg-primary/10 underline decoration-primary decoration-dotted decoration-2 underline-offset-4\",\n  secondary: \"bg-muted underline decoration-muted-foreground decoration-dotted decoration-2 underline-offset-4\",\n  success: \"bg-success/10 underline decoration-success decoration-dotted decoration-2 underline-offset-4\",\n  destructive: \"underline decoration-destructive decoration-wavy decoration-[1.5px] underline-offset-4\",\n  warning: \"underline decoration-warning decoration-wavy decoration-[1.5px] underline-offset-4\",\n} as const;\n\n/**\n * The textarea's computed styles the layer copies, so its text sits exactly on the\n * textarea's. Paddings and border widths place it; the rest lay the text out.\n *\n * @internal\n */\nconst mirroredStyles = [\n  \"color\",\n  \"boxSizing\",\n  \"paddingTop\",\n  \"paddingRight\",\n  \"paddingBottom\",\n  \"paddingLeft\",\n  \"borderTopWidth\",\n  \"borderRightWidth\",\n  \"borderBottomWidth\",\n  \"borderLeftWidth\",\n  \"fontFamily\",\n  \"fontSize\",\n  \"fontWeight\",\n  \"fontStyle\",\n  \"fontStretch\",\n  \"fontVariant\",\n  \"fontFeatureSettings\",\n  \"lineHeight\",\n  \"letterSpacing\",\n  \"wordSpacing\",\n  \"textIndent\",\n  \"textTransform\",\n  \"textAlign\",\n  \"tabSize\",\n  \"direction\",\n  \"wordBreak\",\n  \"overflowWrap\",\n  \"hyphens\",\n] as const;\n\n/** Where an edit happened: the selection when it began, and the caret after it. @internal */\ninterface HighlightEdit {\n  before: { start: number; end: number };\n  caret: number;\n}\n\n/** A run of the text, marked by the highlight at index `mark`, or unmarked. @internal */\ninterface HighlightRun {\n  text: string;\n  mark: number | undefined;\n}\n\n/**\n * The highlights that fit the text, in order, clamped into it, without the ones that end up\n * empty or are not numbers.\n *\n * @internal\n */\nfunction normalizeHighlights(highlights: readonly TextAreaHighlight[] | undefined, length: number): TextAreaHighlight[] {\n  const kept: TextAreaHighlight[] = [];\n  // Stryker disable next-line ArrayDeclaration: anything in the fallback has no start or end, so it is left out as a mark that is not a number.\n  for (const highlight of highlights ?? []) {\n    const start = Math.max(0, Math.min(length, Math.trunc(highlight.start)));\n    const end = Math.max(0, Math.min(length, Math.trunc(highlight.end)));\n    if (end > start) kept.push({ ...highlight, start, end });\n  }\n  return kept;\n}\n\n/** A string that changes exactly when the highlights do, whatever array holds them. @internal */\nfunction highlightsKey(highlights: readonly TextAreaHighlight[] | undefined): string {\n  // Stryker disable next-line ArrayDeclaration: no highlights need only a key of their own, whatever it reads.\n  return JSON.stringify((highlights ?? []).map(({ start, end, tone, label, id }) => [start, end, tone, label, id]));\n}\n\n/**\n * The lengths of the unchanged start and end around an edit: the longest unchanged start,\n * then the longest unchanged end. When the new text matches its neighbours, the change could\n * sit in more than one place; the selection says where the person made it.\n */\nfunction unchanged(before: string, after: string, edit: HighlightEdit | null): [number, number] {\n  let start = 0;\n  const shortest = Math.min(before.length, after.length);\n  // Past the shorter text's end its character reads undefined, unequal to the other's, since the texts differ: the bound only stops the scan sooner.\n  // Stryker disable next-line ConditionalExpression,EqualityOperator: as above.\n  while (start < shortest && before[start] === after[start]) start++;\n  let end = 0;\n  while (end < shortest - start && before[before.length - 1 - end] === after[after.length - 1 - end]) end++;\n  if (edit) {\n    const at = Math.min(edit.before.start, edit.caret);\n    const rest = after.length - edit.caret;\n    if (at + rest === start + end && before.slice(0, at) === after.slice(0, at) && before.endsWith(after.slice(edit.caret))) return [at, rest];\n  }\n  return [start, end];\n}\n\n/**\n * The highlights after the text changes from `before` to `after`. A mark keeps the characters\n * it marked: typed or pasted text is left unmarked, a mark the edit falls inside splits around\n * it, and a mark whose characters are gone is dropped.\n *\n * @internal\n */\nfunction moveHighlights(highlights: readonly TextAreaHighlight[], before: string, after: string, edit: HighlightEdit | null): TextAreaHighlight[] {\n  const [head, tail] = unchanged(before, after, edit);\n  const removedEnd = before.length - tail;\n  const shift = after.length - before.length;\n  const moved: TextAreaHighlight[] = [];\n  for (const highlight of highlights) {\n    // The part before the edit stays where it was, and the part after it moves with the text.\n    const before = Math.min(highlight.end, head);\n    if (highlight.start < before) moved.push({ ...highlight, end: before });\n    const after = Math.max(highlight.start, removedEnd);\n    if (after < highlight.end) moved.push({ ...highlight, start: after + shift, end: highlight.end + shift });\n  }\n  return moved;\n}\n\n/**\n * The text cut where a mark starts or ends, with the mark that shows on a run: where marks\n * overlap, the later one in the array.\n *\n * @internal\n */\nfunction highlightRuns(text: string, highlights: readonly TextAreaHighlight[]): HighlightRun[] {\n  const points = [...new Set([0, text.length, ...highlights.flatMap((highlight) => [highlight.start, highlight.end])])].sort((a, b) => a - b);\n  const runs: HighlightRun[] = [];\n  points.slice(1).forEach((to, index) => {\n    const from = points[index]!;\n    let mark: number | undefined;\n    highlights.forEach((highlight, at) => {\n      if (highlight.start <= from && highlight.end >= to) mark = at;\n    });\n    // A mark split only by another mark's edge stays one run, so its tint has no seam.\n    const last = runs.at(-1);\n    if (last && last.mark === mark) last.text += text.slice(from, to);\n    else runs.push({ text: text.slice(from, to), mark });\n  });\n  return runs;\n}\n\n/** How many words the description quotes from a mark before it shortens it. */\nconst quotedWords = 8;\n\n/** A mark's text as the description quotes it: spaces folded, and long ones shortened. */\nfunction quote(text: string): string {\n  const words = text.trim().split(/\\s+/);\n  return `\\u201c${words.length > quotedWords ? `${words.slice(0, quotedWords).join(\" \")}\\u2026` : words.join(\" \")}\\u201d`;\n}\n\n/**\n * What screen readers hear about the marks, after the field's own description: the labels in\n * the order they first appear, with the words they mark. \"Suggested by your assistant: “Thanks\n * for the notes”, “see you Tuesday”.\"\n *\n * @internal\n */\nfunction describeHighlights(text: string, highlights: readonly TextAreaHighlight[]): string {\n  const byLabel = new Map<string, string[]>();\n  for (const highlight of highlights) {\n    const words = text.slice(highlight.start, highlight.end);\n    if (words.trim() === \"\") continue;\n    const quotes = byLabel.get(highlight.label) ?? [];\n    quotes.push(quote(words));\n    byLabel.set(highlight.label, quotes);\n  }\n  return [...byLabel].map(([label, quotes]) => `${label}: ${quotes.join(\", \")}.`).join(\" \");\n}\n\n/** A highlight's tone, or `primary` for one that is not a tone. @internal */\nfunction highlightTone(highlight: TextAreaHighlight): keyof typeof highlightTones {\n  // Stryker disable next-line StringLiteral: a tone that is not one renders primary anyway.\n  const tone = highlight.tone ?? \"primary\";\n  return Object.hasOwn(highlightTones, tone) ? (tone as keyof typeof highlightTones) : \"primary\";\n}\n\n/**\n * The dev messages for `highlights`: the first unlabelled mark, the first that marks\n * nothing and the first with an unknown tone. Development only.\n *\n * @internal\n */\nfunction highlightWarnings(highlights: readonly TextAreaHighlight[] | undefined): DevWarning[] {\n  const list = highlights ?? [];\n  const unlabeled = list.findIndex((highlight) => typeof highlight.label !== \"string\" || highlight.label.trim() === \"\");\n  const empty = list.findIndex((highlight) => !(highlight.end > highlight.start));\n  const untoned = list.findIndex((highlight) => highlightTone(highlight) !== (highlight.tone ?? \"primary\"));\n  const tone = String(list[untoned]?.tone);\n  const renamed = Object.hasOwn(renamedTones, tone) ? renamedTones[tone] : undefined;\n  return [\n    unlabeled >= 0 && [\n      `highlights[${unlabeled}] has no label, so screen readers cannot say what it marks`,\n      '<TextArea highlights={[{ start: 0, end: 5, label: \"Suggested by your assistant\" }]}>',\n    ],\n    empty >= 0 && [\n      `highlights[${empty}] ends where it starts or before, so it marks nothing`,\n      \"<TextArea highlights={[{ start: 0, end: 5, label }]}> with end after start\",\n    ],\n    untoned >= 0 && [\n      `highlights[${untoned}] has tone=\"${tone}\", which is not a tone${renamed ? \"\" : `; use ${Object.keys(highlightTones).map((name) => `\"${name}\"`).join(\", \")}`}`,\n      `<TextArea highlights={[{ start: 0, end: 5, label: \"Possible spelling mistake\", tone: \"${renamed ?? \"destructive\"}\" }]}>`,\n    ],\n  ];\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/text-field/text-area-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/text-field/text-area.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport type { ChangeEvent, JSX, ReactNode, Ref, TextareaHTMLAttributes } from \"react\";\nimport { Field } from \"@/registry/ouro/components/ouro/field/field\";\nimport { FieldControl, type FieldControlProps } from \"@/registry/ouro/components/ouro/field/field-parts\";\nimport { contractWarnings } from \"@/registry/ouro/components/ouro/field/field-styles\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { FieldOwnerContext, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport {\n  describeHighlights,\n  fitHeight,\n  fitHeightNative,\n  supportsFieldSizing,\n  highlightLayerClass,\n  highlightRuns,\n  highlightTone,\n  highlightTones,\n  highlightWarnings,\n  highlightsKey,\n  mirroredStyles,\n  moveHighlights,\n  normalizeHighlights,\n  textAreaClass,\n  textAreaSizes,\n  textAreaVariants,\n  type HighlightEdit,\n} from \"@/registry/ouro/components/ouro/text-field/text-area-styles\";\nimport { controlSizeWarning, controlVariantWarning } from \"@/registry/ouro/components/ouro/text-field/text-field-styles\";\n\n/**\n * A range of a TextArea's text that it marks: words an assistant suggested in the person's\n * draft, a possible spelling mistake. `start` and `end` are JavaScript string indexes, and\n * `end` is exclusive, so a mark covers `text.slice(start, end)`.\n */\nexport interface TextAreaHighlight {\n  /** Where the mark starts: the index of its first character in the text. */\n  start: number;\n  /** Where it ends: the index just after its last character. */\n  end: number;\n  /**\n   * What the mark means, which screen readers hear with the words it marks: \"Suggested by\n   * your assistant\", \"Possible spelling mistake\". Required, so no mark is shown only to sighted people.\n   * @claim \"Required, so no mark is shown\" registry/ouro/components/ouro/text-field/text-area.test-d.ts verify:fileLine(registry/ouro/components/ouro/text-field/text-area.test-d.ts, /expectTypeOf<\\{\\sstart:\\s0;\\send:\\s5\\s\\}>\\(\\)\\.not\\.toExtend<TextAreaHighlight>/)\n   */\n  label: string;\n  /**\n   * The mark's colour, a theme tone. `destructive` and `warning` draw a wavy underline, as\n   * spelling and grammar checkers do; the others a dotted underline on a faint tint.\n   * @default \"primary\"\n   */\n  tone?: \"primary\" | \"secondary\" | \"destructive\" | \"success\" | \"warning\" | (string & { 'danger is \"destructive\"; accent is \"primary\"; neutral is \"secondary\"': never }) | undefined;\n  /** Your own id for the mark. An edit inside a mark splits it, and both pieces keep its id. */\n  id?: string | undefined;\n}\n\n/** The props TextArea adds to the textarea attributes it passes through. */\nexport interface TextAreaOwnProps {\n  /**\n   * What the field is for, shown above it and read as its name. Required: every control\n   * needs a name. To hide it visually, keep it and add `hideLabel`. A placeholder is not a label.\n   * @claim \"Required: every control needs a name\" registry/ouro/components/ouro/text-field/text-area.test-d.ts verify:fileLine(registry/ouro/components/ouro/text-field/text-area.test-d.ts, /expectTypeOf<\\{\\srows:\\s3\\s\\}>\\(\\)\\.not\\.toExtend<TextAreaProps>/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the field's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after the label through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * What is wrong, from your server action or client check. The message (or several, as a\n   * list) shows under the field, which gets `aria-invalid`. A message is text or a React node (one with a link); an empty string or array means valid.\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** The field must be filled: it gets `required` and `aria-required`, and the label a marker. */\n  required?: boolean | undefined;\n  /** Disables the field and fades it. */\n  disabled?: boolean | undefined;\n  /** The form field name the text submits under. */\n  name?: string | undefined;\n  /**\n   * An example of what to write, shown while the field is empty. It is not a label; pass\n   * `label`, which stays visible.\n   */\n  placeholder?: string | undefined;\n  /**\n   * The frame. `outline` draws the bordered box. `plain` draws no border, background or\n   * padding, for a textarea inside a frame your app draws (a chat composer with its send\n   * button in the same box); it keeps the focus outline, and the error message still shows\n   * under it, but with no border to turn red, color your own frame for an invalid field.\n   * Any other string is a type error whose message names the fix. @default \"outline\"\n   * @claim \"`plain` draws no border, background or\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > draws no frame of its own with variant plain, and still outlines on keyboard focus)\n   */\n  variant?: \"outline\" | \"plain\" | (string & { 'default is \"outline\"; ghost, unstyled and borderless are \"plain\"': never }) | undefined;\n  /**\n   * Text size. `md` is 16px on phones and steps down to 14px from the `sm` breakpoint (640px).\n   * `lg` is 20px at every width. The font family is inherited, so set a display font on a\n   * parent. @default \"md\"\n   * @claim \"`md` is 16px on phones and\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea > uses a 16px font on phones, so iOS does not zoom on focus)\n   * @claim \"`lg` is 20px at every width\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > sets 20px text on 28px lines with size lg, at phone and desktop widths)\n   */\n  size?: \"md\" | \"lg\" | (string & { 'default is \"md\"; \"lg\" is 20px text': never }) | undefined;\n  /**\n   * Lines of text it shows; with `autoGrow`, the fewest it shows. @default 3\n   *\n   * @claim \"Lines of text it shows; with\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea > shows three rows by default, or rows, and the user can resize it)\n   * @claim \"Lines of text it shows; with\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea autoGrow > never caps below rows)\n   */\n  rows?: number | undefined;\n  /**\n   * Grows with the content, from `rows` lines up to `maxRows`, instead of scrolling. Use it\n   * for messages and notes, so people see what they wrote.\n   */\n  autoGrow?: boolean | undefined;\n  /**\n   * With `autoGrow`, the most lines it grows to before it scrolls. Unset, it keeps growing.\n   *\n   * @claim \"With `autoGrow`, the most lines it\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea autoGrow > grows with the content and stops at maxRows, then scrolls)\n   * @claim \"With `autoGrow`, the most lines it\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea autoGrow > grows without a cap when maxRows is not set)\n   */\n  maxRows?: number | undefined;\n  /** The current text, for a controlled field; pair it with `onValueChange` or `onChange`. */\n  value?: string | undefined;\n  /** The starting text, for an uncontrolled field. */\n  defaultValue?: string | undefined;\n  /**\n   * Called with the new text on every change.\n   *\n   * @claim \"Called with the new text on\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea > passes textarea attributes, value and change handlers through)\n   */\n  onValueChange?: FieldControlProps[\"onValueChange\"];\n  /**\n   * Ranges of the text to mark in place, each with a tone and a label: words an assistant\n   * wrote in the person's draft, or spelling and grammar notes. The marks wrap with the words\n   * and scroll with them, and screen readers hear each label with the words it marks in the\n   * field's description. As the person types, pastes or undoes, the marks follow their\n   * words: what the person types is never marked, an edit inside a mark splits it, and undo\n   * brings back the marks the text had. Pass `[]` for none, rather than switching the prop\n   * off and on, which remounts the textarea: with no marks the layer draws nothing and costs\n   * nothing as the person types.\n   * @claim \"with no marks the layer draws nothing\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights' cost > copies nothing and draws no text with no marks, as the person types or the parent renders, and stays hidden)\n   * @claim \"Ranges of the text to mark in\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights > marks each range over its words, in a layer with the textarea's box and type, and lets the pointer through)\n   * @claim \"The marks wrap with the words\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights > wraps a mark with its words onto the next line)\n   * @claim \"The marks wrap with the words\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights layout > scrolls the marks with the text once autoGrow stops at maxRows)\n   * @claim \"The marks wrap with the words\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights > describes the marks after the field's own description: each label once, with the words it marks)\n   * @claim \"As the person types, pastes or\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights as the person edits > never marks what the person types, before, after or inside a mark, and splits a mark they type inside)\n   * @claim \"As the person types, pastes or\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights as the person edits > brings the marks back when the person undoes an edit, and takes them away again on redo)\n   */\n  highlights?: readonly TextAreaHighlight[] | undefined;\n  /**\n   * Called with the highlights moved to fit the text after the person edits it. Store them\n   * and pass them back as `highlights`, or recompute your own from your data.\n   */\n  onHighlightsChange?: ((highlights: TextAreaHighlight[]) => void) | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style fields in your theme.\n   */\n  className?: string | undefined;\n  /** The textarea element. */\n  ref?: Ref<HTMLTextAreaElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `highlights`: `<TextArea highlights={[{ start: 0, end: 5, label: \"Suggested\" }]}>`. */\n  marks?: { 'Use <TextArea highlights={[{ start: 0, end: 5, label: \"Suggested\" }]}>': never };\n\n  /** Not a prop. Ouro UI uses `error`: `<TextArea error=\"Required.\">`. */\n  errorMessage?: { 'Use <TextArea error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<TextArea description=\"Only you see these.\">`. */\n  helperText?: { 'Use <TextArea description=\"...\">': never };\n  /** Not a prop. `error` marks the field invalid: `<TextArea error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <TextArea error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the field invalid: `<TextArea error=\"What is wrong\">`. */\n  invalid?: { 'Use <TextArea error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<TextArea required>`. */\n  isRequired?: { 'Use <TextArea required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<TextArea disabled>`. */\n  isDisabled?: { 'Use <TextArea disabled>': never };\n  /** Not a prop. `rows` is the minimum: `<TextArea autoGrow rows={2} maxRows={8}>`. */\n  minRows?: { 'Use <TextArea autoGrow rows={2} maxRows={8}>': never };\n  /** Not a prop. Ouro UI uses `autoGrow`: `<TextArea autoGrow>`. */\n  autoResize?: { 'Use <TextArea autoGrow>': never };\n  /** Not a prop. Ouro UI uses `autoGrow`: `<TextArea autoGrow>`. */\n  autosize?: { 'Use <TextArea autoGrow>': never };\n}\n\n/** Props for {@link TextArea}: its own props and the textarea attributes it passes through. */\nexport type TextAreaProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof TextAreaOwnProps> & TextAreaOwnProps;\n\n/** Field's messages and root name TextArea. */\nconst owner = { name: \"TextArea\", data: \"text-area\" };\n\n/**\n * A labeled multi-line text field on the Field contract, a native `<textarea>`: pass\n * `label`, and `error` from your server action or client check. `autoGrow` makes it grow\n * with the text from `rows` lines up to `maxRows`.\n *\n * `variant=\"plain\"` draws no frame, for a textarea inside a box your app draws, and\n * `size=\"lg\"` sets 20px text. `highlights` marks ranges of the text in place, each with a\n * tone and a label screen readers hear, and the marks follow their words as the person edits.\n *\n * Use `TextField` instead for one line, `Composer` for a chat message box with its send\n * button, and `Field` with `FieldControl` for a control that is not text.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/text-area\n *\n * @example\n * <TextArea label=\"Notes\" name=\"notes\" description=\"Only you see these.\" />\n * <TextArea label=\"Message\" name=\"message\" autoGrow rows={2} maxRows={8} required error={errors?.message} />\n *\n * @example\n * // Words an assistant suggested, marked in the person's draft; the marks follow edits.\n * <TextArea\n *   label=\"Reply\"\n *   value={text}\n *   onValueChange={setText}\n *   highlights={[{ start: 0, end: 22, label: \"Suggested by your assistant\" }]}\n *   onHighlightsChange={setHighlights}\n * />\n *\n * @example\n * // A chat composer: the box is the app's, and the textarea inside it has no frame.\n * <form className=\"flex items-end gap-2 rounded-ouro-xl border border-border p-2 focus-within:border-ring\">\n *   <TextArea label=\"Message\" hideLabel name=\"message\" placeholder=\"Ask anything\" variant=\"plain\" autoGrow rows={1} maxRows={8} className=\"flex-1\" />\n *   <Button type=\"submit\">Send</Button>\n * </form>\n * @claim \"marks ranges of the text in place\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights > describes the marks after the field's own description: each label once, with the words it marks)\n * @claim \"marks ranges of the text in place\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights as the person edits > never marks what the person types, before, after or inside a mark, and splits a mark they type inside)\n * @claim \"` draws no frame, for a textarea inside\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > sets 20px text on 28px lines with size lg, at phone and desktop widths)\n * @claim \"` draws no frame, for a textarea inside\" registry/ouro/components/ouro/text-field/text-area.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.test.tsx::TextArea variant and size > draws no frame of its own with variant plain, and still outlines on keyboard focus)\n */\nexport function TextArea(props: TextAreaProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    variant: variantProp = \"outline\",\n    size: sizeProp = \"md\",\n    rows = 3,\n    autoGrow = false,\n    maxRows,\n    className,\n    ref,\n    onChange,\n    highlights,\n    onHighlightsChange,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid,\n    isRequired,\n    isDisabled,\n    minRows,\n    autoResize,\n    autosize,\n    marks,\n    ...rest\n  } = props;\n  const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n  const variant = Object.hasOwn(textAreaVariants, variantProp) ? (variantProp as keyof typeof textAreaVariants) : \"outline\";\n  const size = Object.hasOwn(textAreaSizes, sizeProp) ? (sizeProp as keyof typeof textAreaSizes) : \"md\";\n\n  useDevWarnings(\n    \"TextArea\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          ...contractWarnings(\"TextArea\", { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled }),\n          variant !== variantProp && controlVariantWarning(\"TextArea\", String(variantProp)),\n          size !== sizeProp && controlSizeWarning(\"TextArea\", sizeProp),\n          minRows !== undefined && [\"minRows is not a prop; rows is the minimum\", `<TextArea autoGrow rows={${String(minRows)}} maxRows={8}>`],\n          autoResize !== undefined && [\"autoResize is not a prop\", \"<TextArea autoGrow>\"],\n          autosize !== undefined && [\"autosize is not a prop\", \"<TextArea autoGrow>\"],\n          maxRows !== undefined && !autoGrow && [\"maxRows only applies with autoGrow\", `<TextArea autoGrow maxRows={${maxRows}}>`],\n          marks !== undefined && [\"marks is not a prop\", '<TextArea highlights={[{ start: 0, end: 5, label: \"Suggested\" }]}>'],\n          ...highlightWarnings(highlights),\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const highlighting = highlights !== undefined;\n  const marked = useHighlights(textareaRef, highlights, rest.value, rest.defaultValue);\n\n  // With autoGrow, fit once per change of the text and when a prop that sets the height changes:\n  // an uncontrolled field as the person types, a controlled one once its value arrives. A render\n  // that changes neither (a parent's, as a message arrives beside a composer) measures nothing,\n  // since each fit reads the textarea's style and lays out the page. Without autoGrow, measure\n  // nothing: the inline height is the user's resize handle. Turning autoGrow off once clears the\n  // height autoGrow set, so `rows` applies again.\n  const controlled = rest.value !== undefined;\n  const grew = useRef(autoGrow);\n  const native = autoGrow && supportsFieldSizing();\n  const fit = () => {\n    const textarea = textareaRef.current!;\n    if (autoGrow && native) fitHeightNative(textarea, rows, maxRows);\n    else if (autoGrow) fitHeight(textarea, rows, maxRows);\n    // Stryker disable next-line ConditionalExpression: clearing styles that were never set changes nothing.\n    else if (grew.current) {\n      textarea.style.height = \"\";\n      textarea.style.overflowY = \"\";\n      textarea.style.removeProperty(\"field-sizing\");\n      textarea.style.minHeight = \"\";\n      textarea.style.maxHeight = \"\";\n    }\n    grew.current = autoGrow;\n  };\n  const watched = native ? undefined : rest.value;\n  // The browser sizes a native field itself; the fit only sets its floor and cap from the padding,\n  // which can wait for the frame after the first paint. Measuring does not fit before the paint.\n  // Stryker disable next-line BooleanLiteral: the first fit's timing shows only in test/mount-reads.test.tsx.\n  const placed = useRef(false);\n  /* eslint-disable react-hooks/exhaustive-deps -- fit is rebuilt each render; the lists name what it reads that should trigger a fit */\n  useLayoutEffect(() => {\n    // Stryker disable next-line ConditionalExpression,LogicalOperator: as above; a later fit follows in the frame.\n    if (!native || placed.current) fit();\n  }, [autoGrow, native, rows, maxRows, size, variant, watched]);\n  useEffect(() => {\n    // Stryker disable next-line ConditionalExpression: a refit in the frame gives a non-native field the height the layout effect already gave it.\n    if (!native) return;\n    const frame = requestAnimationFrame(() => {\n      // Stryker disable next-line BooleanLiteral: as above.\n      placed.current = true;\n      fit();\n    });\n    return () => cancelAnimationFrame(frame);\n    // Stryker disable next-line ArrayDeclaration: the frame refits with the same inputs the layout effect did.\n  }, [autoGrow, native, rows, maxRows, size, variant]);\n  /* eslint-enable react-hooks/exhaustive-deps */\n  const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {\n    // A controlled field fits once its value arrives, in the effect above.\n    if (autoGrow && !native && !controlled) fitHeight(event.currentTarget, rows, maxRows);\n    // Without highlights there is nothing to move, so this only skips the work.\n    // Stryker disable next-line ConditionalExpression: as above.\n    if (highlights !== undefined) {\n      const moved = marked.edit(event.currentTarget.value, event.currentTarget.selectionStart, (event.nativeEvent as InputEvent).inputType);\n      if (moved) onHighlightsChange?.(moved);\n    }\n    onChange?.(event);\n  };\n  // The text rewraps when the width changes (a rotated phone, a resized window). The refit\n  // runs in the next frame, never inside the observer's callback: a height set there is a new\n  // observation the browser cannot deliver in the same frame, which it reports on the window\n  // as \"ResizeObserver loop completed with undelivered notifications\".\n  useEffect(() => {\n    // Stryker disable next-line ConditionalExpression: observing on the native path only refits to the same height.\n    if (!autoGrow || native) return;\n    const textarea = textareaRef.current!;\n    let width = textarea.offsetWidth;\n    let frame = 0;\n    const observer = new ResizeObserver(() => {\n      if (textarea.offsetWidth === width) return;\n      width = textarea.offsetWidth;\n      cancelAnimationFrame(frame);\n      frame = requestAnimationFrame(() => fitHeight(textarea, rows, maxRows));\n    });\n    observer.observe(textarea);\n    return () => {\n      cancelAnimationFrame(frame);\n      observer.disconnect();\n    };\n  },\n  // Stryker disable next-line ArrayDeclaration: an empty list keeps the first rows and maxRows, which the width refit tests change.\n  [autoGrow, native, rows, maxRows]);\n\n  const setRef = useMergedRef(ref, textareaRef);\n  const descriptionId = useId();\n  const marksDescription = highlighting ? describeHighlights(marked.text, marked.ranges) : \"\";\n  const describedBy = [rest[\"aria-describedby\"], marksDescription ? descriptionId : undefined].filter(Boolean).join(\" \") || undefined;\n\n  return (\n    <FieldOwnerContext.Provider value={owner}>\n      <Field\n        label={label}\n        hideLabel={hideLabel}\n        description={description}\n        error={error}\n        required={required}\n        disabled={disabled}\n        name={name}\n        className={className}\n      >\n        <FieldControl\n          {...(rest as Omit<FieldControlProps, \"className\">)}\n          aria-describedby={describedBy}\n          ref={setRef as Ref<HTMLInputElement>}\n          onChange={handleChange as unknown as FieldControlProps[\"onChange\"]}\n          render={(controlProps) => {\n            const textarea = (\n              <textarea\n                {...(controlProps as TextareaHTMLAttributes<HTMLTextAreaElement>)}\n                rows={rows}\n                data-ouro-control=\"text-area\"\n                data-ouro-part=\"input\"\n                data-variant={variant}\n                data-size={size}\n                className={cn(textAreaClass, textAreaVariants[variant], textAreaSizes[size], autoGrow ? \"resize-none\" : \"resize-y\")}\n              />\n            );\n            if (!highlighting) return textarea;\n            // The marks are drawn over the textarea in a layer the same size, so they need a box around both.\n            return (\n              <div data-ouro-highlights=\"\" className=\"relative min-w-0\">\n                {textarea}\n                <HighlightLayer textareaRef={textareaRef} text={marked.text} highlights={marked.ranges} styleKey={`${size} ${variant}`} />\n                {marksDescription && (\n                  <span id={descriptionId} hidden>\n                    {marksDescription}\n                  </span>\n                )}\n              </div>\n            );\n          }}\n        />\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n\n/** What `useHighlights` gives TextArea: the text, the marks that fit it, and the edit handler. */\ninterface Highlighted {\n  text: string;\n  ranges: TextAreaHighlight[];\n  /** Moves the marks for the text after an edit of the input type given; returns them when they changed. */\n  edit: (next: string, caret: number, inputType: string | undefined) => TextAreaHighlight[] | undefined;\n}\n\n/** The marks undo can bring back, at most this many texts. */\nconst historyLength = 100;\n\n/**\n * The marks that fit the text now. New `highlights` (by content, not by array) are taken as\n * given; otherwise, when the text changes, the marks move with it: by the person's edit when\n * they made one, and by comparing the texts when the app changed the value.\n */\nfunction useHighlights(textareaRef: { current: HTMLTextAreaElement | null }, highlights: readonly TextAreaHighlight[] | undefined, value: unknown, defaultValue: unknown): Highlighted {\n  const controlled = value !== undefined;\n  const [ownText, setOwnText] = useState(() => (defaultValue === undefined ? \"\" : String(defaultValue)));\n  const text = controlled ? String(value) : ownText;\n  const key = highlightsKey(highlights);\n  // Stryker disable next-line ObjectLiteral: an empty start differs from the first render's key, which then takes the highlights as given all the same.\n  const [track, setTrack] = useState(() => ({ key, text, ranges: normalizeHighlights(highlights, text.length) }));\n  // The marks the person's last edit gave, for the text it made.\n  const [edited, setEdited] = useState<{ text: string; ranges: TextAreaHighlight[] } | null>(null);\n  // The selection when the input in progress began (the native beforeinput), so an edit is placed where it was made.\n  const input = useRef<HighlightEdit[\"before\"] | null>(null);\n  const history = useRef(new Map<string, TextAreaHighlight[]>());\n\n  let ranges = track.ranges;\n  if (track.key !== key || track.text !== text) {\n    if (track.key !== key) ranges = normalizeHighlights(highlights, text.length);\n    else if (edited?.text === text) ranges = edited.ranges;\n    else ranges = moveHighlights(track.ranges, track.text, text, null);\n    setTrack({ key, text, ranges });\n  }\n\n  useEffect(() => {\n    const seen = history.current;\n    // A text seen before keeps its first place, so undo reaches back about historyLength texts.\n    if (!seen.has(track.text)) seen.set(track.text, track.ranges);\n    if (seen.size > historyLength) seen.delete(seen.keys().next().value!);\n  }, [track]);\n\n  useEffect(() => {\n    const textarea = textareaRef.current!;\n    const record = () => {\n      input.current = { start: textarea.selectionStart, end: textarea.selectionEnd };\n    };\n    textarea.addEventListener(\"beforeinput\", record);\n    // Stryker disable next-line ArrowFunction,StringLiteral: an unmounted textarea's listener records a selection nothing reads.\n    return () => textarea.removeEventListener(\"beforeinput\", record);\n  },\n  // Stryker disable next-line ArrayDeclaration: the textarea is the same for the field's life, so once is enough with any fixed list.\n  [textareaRef]);\n\n  const edit = (next: string, caret: number, inputType: string | undefined) => {\n    const before = input.current;\n    input.current = null;\n    // Undo and redo bring back the marks the text had, when it had any.\n    const restored = inputType?.startsWith(\"history\") ? history.current.get(next) : undefined;\n    const moved = restored ?? moveHighlights(ranges, text, next, before && { before, caret });\n    setEdited({ text: next, ranges: moved });\n    // A controlled field reads its text from value, so its own copy is never read.\n    // Stryker disable next-line ConditionalExpression: as above.\n    if (!controlled) setOwnText(next);\n    return highlightsKey(moved) === highlightsKey(ranges) ? undefined : moved;\n  };\n  return { text, ranges, edit };\n}\n\n/** Copies the textarea's box and type onto the layer and scrolls the layer's text with it. */\nfunction syncLayer(textarea: HTMLTextAreaElement, layer: HTMLDivElement): void {\n  const style = getComputedStyle(textarea);\n  const target = layer.style;\n  for (const name of mirroredStyles) target[name] = style[name];\n  // A classic scrollbar takes width from the text, at the inline end.\n  const borders = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);\n  const scrollbar = Math.max(0, textarea.offsetWidth - textarea.clientWidth - borders);\n  const side = style.direction === \"rtl\" ? \"paddingLeft\" : \"paddingRight\";\n  target[side] = `${parseFloat(style[side]) + scrollbar}px`;\n  (layer.firstElementChild as HTMLElement).style.transform = `translateY(${-textarea.scrollTop}px)`;\n  target.visibility = \"visible\";\n}\n\n/**\n * The marks, drawn over the textarea: the same text, transparent, with the marked runs\n * underlined in their tones. It is measured after mount, so the server writes it hidden.\n *\n * Copying the textarea's box and type reads its computed style and lays out the page, so it runs\n * only when that can change: when marks appear, when a prop that styles the textarea changes\n * (`styleKey`), when the textarea's size changes (a breakpoint's type, a scrollbar) and when it\n * scrolls. Not as the person types: the layer's text changes with the textarea's, in the same\n * box. With no marks it draws no text and copies nothing, and stays hidden.\n *\n * @claim \"With no marks it draws no text\" registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx verify:testExists(registry/ouro/components/ouro/text-field/text-area.highlights.test.tsx::TextArea highlights' cost > copies nothing and draws no text with no marks, as the person types or the parent renders, and stays hidden)\n */\nfunction HighlightLayer({ textareaRef, text, highlights, styleKey }: { textareaRef: { current: HTMLTextAreaElement | null }; text: string; highlights: readonly TextAreaHighlight[]; styleKey: string }): JSX.Element {\n  const layerRef = useRef<HTMLDivElement>(null);\n  const marking = highlights.length > 0;\n  const live = useRef(marking);\n  useLayoutEffect(() => {\n    live.current = marking;\n    const layer = layerRef.current!;\n    if (marking) syncLayer(textareaRef.current!, layer);\n    // Without marks the class hides it again.\n    else layer.style.visibility = \"\";\n  }, [textareaRef, marking, styleKey]);\n  useEffect(() => {\n    const textarea = textareaRef.current!;\n    const layer = layerRef.current!;\n    const sync = () => {\n      if (live.current) syncLayer(textarea, layer);\n    };\n    textarea.addEventListener(\"scroll\", sync);\n    // The type can change with the size (a breakpoint's font size). As in autoGrow, the sync runs in the next frame, never inside the observer's callback.\n    let frame = 0;\n    const observer = new ResizeObserver(() => {\n      // Stryker disable next-line CallExpression: a second sync in the same frame copies the same styles.\n      cancelAnimationFrame(frame);\n      frame = requestAnimationFrame(sync);\n    });\n    observer.observe(textarea);\n    // Stryker disable next-line ArrowFunction,CallExpression,StringLiteral: an unmounted layer is gone, so its syncs change nothing shown.\n    return () => (cancelAnimationFrame(frame), observer.disconnect(), textarea.removeEventListener(\"scroll\", sync));\n  },\n  // Stryker disable next-line ArrayDeclaration: the textarea is the same for the field's life, so once is enough with any fixed list.\n  [textareaRef]);\n  return (\n    <div ref={layerRef} aria-hidden=\"true\" data-ouro-highlights-layer=\"\" className={cn(highlightLayerClass, \"invisible\")}>\n      <div>\n        {marking &&\n          highlightRuns(text, highlights).map((run, index) => {\n            if (run.mark === undefined) return run.text;\n            const tone = highlightTone(highlights[run.mark]!);\n            return (\n              <span key={index} data-ouro-highlight={tone} className={cn(\"rounded-xs box-decoration-clone forced-colors:decoration-[CanvasText]\", highlightTones[tone])}>\n                {run.text}\n              </span>\n            );\n          })}\n        {/* The textarea keeps a line under a last line break; so does the layer. */}\n        {\"\\n\\u200b\"}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/text-field/text-area.tsx"
    }
  ],
  "docs": "A labeled multi-line text field on the Field contract, a native `<textarea>`: pass `label`, and `error` from your server action or client check. Import: import { TextArea } from \"@/components/ouro/text-field/text-area\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, field, text-field, 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/text-area.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}