{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message-list",
  "title": "MessageList",
  "description": "A conversation: `Message`s in a scrolling, labeled region that opens at the newest one.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-halve",
    "@ouro/lib-navigation-key",
    "@ouro/lib-refs",
    "@ouro/lib-row-hover",
    "@ouro/lib-spring",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-keyboard-scrollable",
    "@ouro/lib-use-ouro",
    "@ouro/message"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/message/message-list.tsx",
      "content": "\"use client\";\n\nimport { Children, isValidElement, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { HTMLAttributes, JSX, Key, KeyboardEvent, ReactNode, Ref } from \"react\";\nimport type { MessageBarData, MessageBarLayer } from \"@/registry/ouro/components/ouro/message/message-parts\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { halveShown } from \"@/registry/ouro/lib/ouro/halve\";\nimport { createRowLayer, RowLayerContext, type RowLayer } from \"@/registry/ouro/lib/ouro/row-hover\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { navigationKey } from \"@/registry/ouro/lib/ouro/navigation-key\";\nimport { springAt, type SpringState } from \"@/registry/ouro/lib/ouro/spring\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useKeyboardScrollable } from \"@/registry/ouro/lib/ouro/use-keyboard-scrollable\";\nimport { useOuro, type OuroMotion } from \"@/registry/ouro/lib/ouro/use-ouro\";\n\n/** The props MessageList adds to the `<div>` attributes it passes through. */\nexport interface MessageListOwnProps {\n  /** What the conversation is, for screen readers: \"Conversation with Ouro\". Required, so the region has a name. */\n  label: string;\n  /** The `Message`s, oldest first, or your own message components marked `data-ouro-message-list-item` (see {@link MessageList}). */\n  children: ReactNode;\n  /** The button that appears once the reader scrolls up, for other languages. @default \"Jump to latest\" */\n  jumpLabel?: string | undefined;\n  /**\n   * The `id` of the message to open at, such as one found by search or a link to it, or the `key` of the child that holds\n   * it (the message's own id, where a row component of yours takes no `id`). The list opens\n   * with that message in the middle of its view, before it first draws, so the newest is never shown\n   * first, and it follows new messages only once the reader reaches the end. The list reads it when\n   * it first has messages, so it can come with them; a message it does not hold, or the newest,\n   * opens at the end, and a later change moves nothing.\n   * @claim \"or the `key` of the child that holds it\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals a row component that takes no id by its key, and opens at one by its key, resolving once it is in place)\n   * @claim \"The list opens with that message in\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > opens at the message initialAnchor names, never drawing the newest first, and stops following new messages)\n   * @claim \"The list reads it when it first\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > opens at initialAnchor when it comes with the first messages, after the list mounted empty)\n   * @claim \"a message it does not hold\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > opens at the newest message when initialAnchor names no message in the list, or the newest itself)\n   */\n  initialAnchor?: string | undefined;\n  /**\n   * Which conversation the messages are, such as its id. Change it with the other conversation's messages, or before they\n   * come (as an app that keeps the last messages while it fetches does): the list opens that conversation at its newest\n   * message as they come, whatever keys they have, and moves nothing while the last one's still show. While it stays the\n   * same, nothing the messages do counts as a switch: keys swapped for the server's, the newest ones regenerated or removed.\n   * The first one named for messages the list already holds names them, and moves nothing. Messages that come before\n   * their conversation is named are taken for the last one's, and the name that follows them is taken for theirs, opening\n   * nothing; and a conversation whose\n   * messages carry exactly the last one's keys (keyed by place, as many of them) can't be told from it until they change,\n   * so key messages by their own ids. Without it, the list takes messages that share no `key` with the ones it held for\n   * another conversation, so it misses a switch between conversations whose messages share keys, and takes a short\n   * conversation whose every message gets a new key at once for another one.\n   * @claim \"While it stays the same, nothing the\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > takes a switch from conversation alone: one whose messages share keys with the last is a switch, and messages re-keyed in the same one are not)\n * @claim \"While it stays the same, nothing the\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > takes removing the newest five, as a regenerated turn does, for the same conversation)\n * @claim \"Change it with the other conversation's\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > switches when the conversation is named before its messages come, as an app that keeps the last messages while it fetches does)\n   * @claim \"Change it with the other conversation's\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > takes a switch from conversation alone: one whose messages share keys with the last is a switch, and messages re-keyed in the same one are not)\n   * @claim \"The first one named for messages the\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > adopts a conversation first named for the messages it holds, leaving a scrolled-up reader where they are)\n   * @claim \"Messages that come before their conversation\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > adopts a name that comes after its messages, so switching back in one commit opens the last conversation at its newest)\n   * @claim \"Messages that come before their conversation\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > takes messages that come before their conversation is named for the last one's, and opens nothing when it is named after them)\n   * @claim \"Without it, the list takes messages that\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > keeps the reader's place, the messages and focus when the newest three get new keys in place, while scrolled up)\n   */\n  conversation?: Key | undefined;\n  /**\n   * Whether older messages are loading above: a small \"Loading older messages\" shows over the\n   * top of the list, and screen readers hear it once. It sits over the messages, not among them,\n   * so starting and ending it moves no message. At the very top it covers the first message\n   * unless `hasOlder` keeps room for it. Fetch older pages ahead of the reader, not when they\n   * reach the top: the next older page as soon as the one before it has arrived, while they are\n   * still screens away. Then this shows only when they get to the top first.\n   * @claim \"Whether older messages are loading above\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > shows older messages loading over the top of the list, moving no message as it starts or ends)\n   * @claim \"It sits over the messages, not\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > shows older messages loading over the top of the list, moving no message as it starts or ends)\n   * @claim \"At the very top it covers\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps room above the first message while hasOlder, so loading older messages covers no message or focus ring and moves nothing)\n   */\n  loadingOlder?: boolean | undefined;\n  /**\n   * Whether older messages may still load above, until the reader reaches the start of the\n   * conversation. While it is true the list keeps room above the first message, where \"Loading\n   * older messages\" shows, so at the top it covers no message or focus ring, and nothing moves as\n   * loading starts. Set it to `false` once there is nothing older: the room stays until it has left\n   * the view, or the list is at its end, and then goes without moving a message, not even for\n   * the one frame the browser draws as it goes.\n   * @default false\n   * @claim \"not even for the one frame the browser draws as it goes\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > holds the reader's message still in every frame as the last older page comes and the room above it goes)\n   * @claim \"so at the top it covers\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps room above the first message while hasOlder, so loading older messages covers no message or focus ring and moves nothing)\n   * @claim \"the room stays until it has\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the room once hasOlder ends while it shows, and drops it without moving a message once it leaves the view)\n   * @claim \"the room stays until it has\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > drops the room at once when hasOlder ends at the list's end or with the room out of view, and adds it without moving a message)\n   */\n  hasOlder?: boolean | undefined;\n  /** What shows while older messages load, for other languages. @default \"Loading older messages\" */\n  loadingOlderLabel?: string | undefined;\n  /**\n   * What screen readers hear when a new message arrives, for other languages. It gets the\n   * author's name and the message's text. The user's own messages are not read back.\n   * @default (author, text) => `${author}: ${text}`\n   */\n  newMessageLabel?: ((author: string, text: string) => string) | undefined;\n  /**\n   * A key pressed while a message itself has focus, not a control inside it, before the list's\n   * own keys: shortcuts on the focused message, such as 1 to 6 for quick reactions. `message` is\n   * the message's element (its `id` or `data-*` attributes say which one it is). Call\n   * `event.preventDefault()` to keep the list from acting on the key as well.\n   * @claim \"A key pressed while a message itself has focus\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > hands the app a key pressed on the focused message, and not one pressed in a control inside it)\n   */\n  onMessageKeyDown?: ((message: HTMLElement, event: KeyboardEvent<HTMLElement>) => void) | undefined;\n  /**\n   * Whether Page Up and Page Down on a focused message move a page through the messages, as ⌥↑ and\n   * ⌥↓ do on a Mac. With `false` the list leaves those keys alone: it neither acts on them nor calls\n   * `preventDefault()`, so an app's own shortcut on them, such as ⌥↓ for the next conversation, gets\n   * them as pressed, and the browser scrolls the list. The other keys still move between messages.\n   * @default true\n   * @claim \"With `false` the list leaves those\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > leaves Page Up and Page Down, and ⌥↑ and ⌥↓ on a Mac, to the app with pageKeys={false}, and moves with the other keys)\n   * @claim \"The other keys still move between\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > leaves Page Up and Page Down, and ⌥↑ and ⌥↓ on a Mac, to the app with pageKeys={false}, and moves with the other keys)\n   */\n  pageKeys?: boolean | undefined;\n  /**\n   * Whether the messages spring as the reader scrolls, as in a phone's messages app: each one\n   * trails the scroll a little, the farther from where the reader scrolls (the finger, the\n   * pointer, the focused message) the more, and catches up on a spring. A fling, or a push past\n   * either end, spreads the messages apart and they settle back. It draws with `transform` alone:\n   * the list's scroll position never moves for it, and at rest, once the reader's scroll has ended, no message has a transform. Only the\n   * messages in or near view move, so a long conversation costs what a short one does. It runs for\n   * the reader's own wheel, trackpad, touch and keys, never for scrolling the list or your code\n   * does (following new messages, setting `scrollTop`), and never with reduced motion (`prefers-reduced-motion: reduce`, or `OuroProvider`'s `motion`).\n   * @default true\n   * @claim \"each one trails the scroll a little\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > trails the wheel the more the farther a message is from the pointer, and settles back to no transform)\n   * @claim \"A fling, or a push past\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > spreads the messages apart on a push past either end, and draws them back)\n   * @claim \"the list's scroll position never moves\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > never changes the scroll position, and keeps the reader's place by where messages are laid out)\n   * @claim \"Only the messages in or near\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > moves only the messages in or near view, reading as few in a thousand as in fifty, on one frame loop)\n   * @claim \"It runs for the reader's own\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > follows the keys, with the focused message where the scroll starts, and its focus ring moves with it)\n   * @claim \"never for scrolling the list or\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > never springs for scrolling the reader did not do: new messages it follows, or scrollTop set in code)\n   * @claim \"and never with reduced motion\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > moves nothing with reduced motion, or with springy={false})\n   */\n  springy?: boolean | undefined;\n  /**\n   * The widest the conversation gets, in CSS pixels, centred in a wider list (`960` is 60rem at\n   * the default font size), so in a wide window the user's own messages stay near the others'\n   * and the eye never crosses an empty field between them. The list itself still fills its\n   * place, so it scrolls from anywhere across it. Leave it out for messages as wide as the list.\n   * @claim \"centred in a wider list\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > centres the conversation at maxWidth in a wider list, the user's own messages with it, and fills a narrower one)\n   */\n  maxWidth?: number | undefined;\n  /**\n   * Whether a long conversation draws only the messages near its view. Above 20 children the list\n   * draws those within a screen or 800 pixels of the view, whichever is more, the newest, the one with focus, and any\n   * still streaming (as it opens, only those its view shows, and the rest once that frame is painted), each measured as it draws, with space for the rest kept above and below, so a long\n   * conversation opens and redraws in about the time a screenful does. The browser's find in page, and\n   * code that reads messages from the page, see only the messages drawn: search your own messages and\n   * call `actionsRef.current.reveal(id)` to show a match. Set `false` to keep every message in the page.\n   * A list the reader scrolled up in that takes older and newer messages in one commit renders no more than 20 of the\n   * children it drew before, and the 20 newest, before it finds the view; scrolling up through rows never drawn moves\n   * what the reader looks at by under a pixel in every frame; and a list opens at its end with no frame moving the row at the\n   * view's top by more than a pixel.\n   * @default true\n   * @claim \"renders no more than 20 of the\" test/message-list-windowing.bench.test.tsx verify:testExists(test/message-list-windowing.bench.test.tsx::MessageList older page > renders about a fifth of the rows, not the list again, when a short list the reader scrolled up in takes 200 older rows and 360 newer in one commit)\n   * @claim \"moves what the reader looks at by under a pixel\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > moves no row the reader looks at by a pixel in any frame, scrolling up through 100 rows never drawn whose heights differ from the estimate by up to 40px)\n   * @claim \"opens at its end with no frame moving the row\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > opens a conversation of 300 rows of varied heights at its end, moving the row at the view's top by no more than a pixel in any frame)\n   * @claim \"as it opens, only those its view shows\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > opens with no more rows than fill the window, and draws the rows past the view's edges only after the first paint)\n   * @claim \"Above 20 children the list draws\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > draws only the messages near the view of a long conversation, in a list as tall as all of them)\n   * @claim \"Above 20 children the list draws\" registry/ouro/components/ouro/message/message-list.tsx verify:fileLine(registry/ouro/components/ouro/message/message-list.tsx, /const OVERSCAN = 800;/) verify:fileLine(registry/ouro/components/ouro/message/message-list.tsx, /Math\\.max\\(OVERSCAN, scroller\\.clientHeight\\)/)\n   * @claim \"Set `false` to keep every message\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps every message in the page with windowing={false})\n   */\n  windowing?: boolean | undefined;\n  /**\n   * A map the list writes the heights of its children into, under a child's key and the list's width in CSS pixels, rounded\n   * to a multiple of `BUCKET`, and reads before it measures. Keep one in your app, by conversation, and hand it to each list that shows the conversation:\n   * a list that mounts again with it is as tall, from its first commit, as the list before it was, so it opens\n   * with no row moving. Leave it out and the list keeps its own for as long as it lives.\n   * @claim \"a list that mounts again with it is\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps the height of every row in a heightCache the app hands in, so a list that mounts again with it is as tall, in its first commit, as it was)\n   */\n  heightCache?: Map<string, number> | undefined;\n  /**\n   * Gets the list's actions: `reveal(id)` brings a message into view, drawing it first if it is not\n   * drawn, for a quote, a link to a message, or find in chat; `jumpToNewest()` goes to the end and\n   * follows new messages again. See {@link MessageListActions}.\n   */\n  actionsRef?: Ref<MessageListActions> | undefined;\n  /**\n   * Layout only: the list's height (`h-96`, `flex-1`), margins. It scrolls inside that\n   * height, so give it one. Appearance classes warn in development.\n   */\n  className?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /** Not a prop. The list follows new messages while the reader is at the bottom, and stops when they scroll up. */\n  autoScroll?: { 'Not a prop: the list follows new messages at the bottom. Use <MessageList label=\"Conversation\">': never };\n  /** Not a prop. The list follows new messages while the reader is at the bottom, and stops when they scroll up. */\n  stickToBottom?: { 'Not a prop: the list follows new messages at the bottom. Use <MessageList label=\"Conversation\">': never };\n}\n\n/** Props for {@link MessageList}: its own props and the `<div>` attributes it passes through. */\nexport type MessageListProps = Omit<HTMLAttributes<HTMLDivElement>, keyof MessageListOwnProps | \"role\"> & MessageListOwnProps;\n\n/** Where `reveal` puts a message: in the middle of the view, at its top, or scrolled only as far as it needs. */\nexport type MessageListRevealBlock = \"center\" | \"start\" | \"nearest\";\n\n/** How `reveal` shows a message. */\nexport interface MessageListRevealOptions {\n  /** Whether the message takes focus, as for a quote the reader pressed. @default false */\n  focus?: boolean | undefined;\n  /** Where in the view it goes. @default \"center\" */\n  block?: MessageListRevealBlock | undefined;\n}\n\n/**\n * What a MessageList does on request, through its `actionsRef`.\n *\n * @example\n * const actions = useRef<MessageListActions>(null);\n * <Message quote={{ author: \"Ana\", excerpt: \"Lunch?\", onActivate: () => void actions.current?.reveal(\"m-41\", { focus: true }) }}>Yes</Message>\n */\nexport interface MessageListActions {\n  /**\n   * Brings the message whose `id` is given into view, drawing it first if the list has not, and\n   * stops following new messages. A child is found by its `id` prop, or by its `key` (the message's\n   * own id, where a row component of yours takes no `id`), and once drawn by the `id` of any element\n   * in it. Resolves true once the message is in place (and focused, with `focus`), and false at once\n   * when no child has that `id` or `key`, or when another reveal or a key press takes its place. Find\n   * in chat searches your own messages, then reveals each match: the browser's find in page sees only\n   * what is drawn.\n   * @claim \"A child is found by its `id` prop, or by its `key`\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals a row component that takes no id by its key, and opens at one by its key, resolving once it is in place)\n   * @claim \"Brings the message whose `id` is given\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals a message that is not drawn, by its id, in the middle of the view, and focuses it when asked)\n   * @claim \"and false at once when no child has\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals nothing, and says so, for an id no message has)\n   */\n  reveal(id: string, options?: MessageListRevealOptions): Promise<boolean>;\n  /**\n   * Goes to the newest message and follows new messages again, as \"Jump to latest\" does, leaving focus where it is.\n   * @claim \"Goes to the newest message and follows\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > jumps to the newest message from far up, and follows new messages again)\n   */\n  jumpToNewest(): void;\n}\n\n/**\n * The messages in the list: Ouro's `Message`s, and an app's own message components, each marked\n * `data-ouro-message-list-item` on its root.\n * @claim \"and an app's own message components\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the reader's place among an app's own messages marked data-ouro-message-list-item, and announces them as it does Messages)\n */\nconst items = '[data-ouro=\"message\"], [data-ouro-message-list-item]';\n\n/** What Tab stops on, before the checks for a negative `tabindex`, `disabled`, `inert` and visibility. */\nconst tabbableSelector =\n  'a[href], area[href], button, input:not([type=\"hidden\"]), select, textarea, iframe, summary, audio[controls], video[controls], [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * Focus guards: the hidden sentinels an open menu puts around its button, in the Tab order. A guard\n * closes the menu as it takes focus and sends focus back the way it came, so Tab onto one from the\n * message would land on the message again.\n */\nconst guards = '[data-base-ui-focus-guard][tabindex=\"0\"], [data-floating-ui-focus-guard][tabindex=\"0\"]';\n\n/** The elements under `root` that Tab stops on, in document order. */\nfunction tabbables(root: Element): HTMLElement[] {\n  return [...root.querySelectorAll<HTMLElement>(tabbableSelector)].filter(\n    (element) => element.tabIndex >= 0 && !element.matches(\":disabled\") && element.closest(\"[inert]\") === null && element.checkVisibility({ visibilityProperty: true }),\n  );\n}\n\n// Whether a change is only the list's one action bar moving between messages or changing in place, which leaves the\n// messages as they were: the list skips placing, marking and announcing for it.\nfunction barOnly(record: MutationRecord): boolean {\n  if ((record.target as Element).closest(\"[data-ouro-message-bar-slot]\") !== null) return true;\n  // The bar's host going into a message or out of it. The lists read this only for records of children, each of which\n  // adds or removes a node, and the host moves alone.\n  // Stryker disable next-line MethodExpression: the host goes in and out by itself, so a record of it holds it alone; some and every agree.\n  return [...record.addedNodes, ...record.removedNodes].every((node) => node instanceof Element && node.matches(\"[data-ouro-message-bar-slot]\"));\n}\n\n/** Whether a change added or removed a message. */\nfunction touchesItems(record: MutationRecord): boolean {\n  return [...record.addedNodes, ...record.removedNodes].some((node) => node instanceof Element && (node.matches(items) || node.querySelector(items) !== null));\n}\n\n/**\n * Whether a change put in or took out a message, or the room kept above the first one: either moves the messages\n * after it. Read as the change happens, so the reader's place is held before the browser draws it.\n */\nfunction movesItems(record: MutationRecord): boolean {\n  return (\n    // Stryker disable next-line ConditionalExpression: holding for a change that moved nothing finds nothing moved, as the observer below says of its own check.\n    touchesItems(record) ||\n    // Stryker disable next-line MethodExpression,ConditionalExpression: the room goes in or out as a node of its own, never beside another in one record; and holding for a change that moved nothing finds nothing moved.\n    [...record.addedNodes, ...record.removedNodes].some((node) => node instanceof Element && node.hasAttribute(\"data-ouro-message-list-older-room\"))\n  );\n}\n\n/**\n * The messages, with each child of a slot that holds none (a day's heading), in page order: the children found slot by slot,\n * rather than with a `:has()` selector over the whole content, which a scroll landing where nothing is drawn yet would pay for.\n * @claim \"The messages, with each child of a slot that holds none\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps the reader's place over rows not drawn yet without a :has() selector over the whole conversation, which reads every element against every message)\n */\nfunction withBareChildren(content: Element, messages: readonly Element[]): Element[] {\n  const bare: Element[] = [];\n  for (const slot of content.children) {\n    for (const child of slot.children) {\n      // Stryker disable next-line ConditionalExpression,LogicalOperator,BooleanLiteral: a message listed twice, or a child of the app's listed with the messages it holds (it starts where the first does and moves with them), holds the place as the messages alone do.\n      if (!child.matches(items) && child.querySelector(items) === null) bare.push(child);\n    }\n  }\n  return [...messages, ...bare].sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));\n}\n\n/** Sets an attribute only when its value differs, so marking the messages again changes nothing in the page. */\nfunction mark(element: Element, name: string, value: string): void {\n  // Stryker disable next-line ConditionalExpression: setting the value an attribute already has changes nothing in the page.\n  if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n}\n\n/** Whether a child's key, as `Children.toArray` writes it (`.$m-41`, `.1:$m-41`, with `=` and `:` escaped), is `key`. */\nfunction keyIs(childKey: string, key: string): boolean {\n  return childKey.endsWith(`$${key.replace(/[=:]/g, (mark) => (mark === \"=\" ? \"=0\" : \"=2\"))}`);\n}\n\n/**\n * The child whose `id` prop, or else whose key, is `target`; -1 when none is.\n * @claim \"The child whose `id` prop, or else whose key\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals a row component that takes no id by its key, and opens at one by its key, resolving once it is in place) verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > reveals nothing, and says so, for an id no message has)\n */\nfunction childNamed(all: readonly ReactNode[], keys: readonly string[], target: string): number {\n  const byId = all.findIndex((child) => isValidElement(child) && (child.props as { id?: unknown }).id === target);\n  return byId >= 0 ? byId : keys.findIndex((key) => keyIs(key, target));\n}\n\n/** The key of the child a message is in, from its slot. */\nfunction slotKeyOf(item: Element): string {\n  return item.closest(`[${SLOT}]`)!.getAttribute(SLOT)!;\n}\n\n/** The messages in `content`, leaving out any message inside another one. */\nfunction topItems(content: Element): HTMLElement[] {\n  return [...content.querySelectorAll<HTMLElement>(items)].filter((item) => !content.contains(item.parentElement!.closest(items)));\n}\n\n/** Space kept between a message brought into view by the keyboard and the list's edge, so its focus ring shows. */\nconst EDGE = 8;\n/** How far an arrow key scrolls through a message taller than the list, in pixels. */\nconst LINE = 40;\n\n/** How close to the bottom, in pixels, counts as \"at the bottom\", where the list follows new messages (zoom leaves fractions). */\nconst AT_BOTTOM = 2;\n/**\n * \"Loading older messages\": a raised pill over the top of the list, fading in where motion is allowed, its ring\n * spinning (pulsing with reduced motion).\n */\nconst olderClass =\n  \"relative m-0 box-border inline-flex h-8 items-center gap-2 rounded-full border border-solid border-border bg-background px-3 \" +\n  \"text-sm text-muted-foreground shadow-(--shadow-md) whitespace-nowrap transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) starting:opacity-0\";\n\n/** How many older messages go into the list in a frame when a page of them comes at once, to keep the frame short. */\nconst CHUNK = 20;\n/**\n * How many of the newest children's keys, with the first child's, say the list's messages changed enough to look again for a switch.\n * @claim \"How many of the newest children's keys\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > switches a list %s to another conversation of a thousand at its newest, in its first frame, from anywhere in the one before)\n */\nconst RECENT = 3;\n\n/** How many announcements the live region keeps; older ones were already read. */\nconst KEEP_SPOKEN = 5;\n\n/**\n * Above this many children the list draws only the messages near its view.\n * @claim \"Above this many children the list\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps a conversation of 20 messages whole, and windows it once it grows past 20, leaving the view where it is)\n */\nconst WINDOW_ABOVE = 20;\n/** How far past the view's edges, in pixels, messages still draw: a page key, or a short scroll, finds them drawn. At least the view's height. */\nconst OVERSCAN = 800;\n/**\n * How soon after the reader's own input (a wheel, a finger, a key) a scroll is theirs, in milliseconds. It stays theirs until\n * the browser says it ended (`scrollend`), a fling's momentum included, and a press on the scrollbar keeps it theirs while held.\n */\nconst READER_GAP = 150;\n/** How much of the conversation the server HTML draws, in pixels: from its end, or around `initialAnchor`. */\nconst FIRST_VIEW = 1600;\n/**\n * The height of the last view a list measured, which a list that opens in the browser takes for its own, up to the window's:\n * the conversations an app opens one after another sit in the same pane. Before any, the window's.\n */\nlet lastView: number | null = null;\n// Stryker disable next-line ArrowFunction: the store never changes, so nothing calls this.\nconst noChange = () => () => {};\n/** A message's height, with its margins, before any is measured. */\nconst ESTIMATE = 96;\n/**\n * How many messages that arrive at once draw where the reader is not, so each is heard.\n * @claim \"How many messages that arrive at once\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > announces a new message once, and never a message drawn again as the reader scrolls)\n */\nconst KEEP_ARRIVED = 20;\n/**\n * What marks each child's slot, holding the child's key.\n * @claim \"What marks each child's slot\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > puts each child in a slot that draws no box, keeping a continued message's spacing, in a list of any length)\n */\nconst SLOT = \"data-ouro-message-list-slot\";\n\n/**\n * Each child's height as last measured, by key, with its margins and without the gap before it; the gap; and the height\n * taken for a child not measured yet, the average of the first measured, fixed from then on. Were it to follow every\n * measurement, the space for hundreds of children above the view would change at once, and near the end the browser\n * would pull the scroll down to a bottom that came up.\n * @claim \"Were it to follow every measurement\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > walks up past the messages first drawn with the Up arrow, each one drawn and shown as focus reaches it)\n * @claim \"Each child's height as last measured\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > draws only the messages near the view of a long conversation, in a list as tall as all of them)\n */\ninterface Measured {\n  heights: ReadonlyMap<string, number>;\n  gap: number;\n  estimate: number;\n  /** The list's width, rounded to a multiple of BUCKET, the heights are of; null before it is measured. */\n  bucket: number | null;\n}\n\n/** The entry of a `heightCache` that holds the width the heights in it were last measured at. */\n// Stryker disable next-line StringLiteral: the entry only has to differ from the `<key>\\0<width>` ones, as an empty string does.\nconst CACHED_WIDTH = \"\\0width\";\n/**\n * The width, in CSS pixels, rounded to a multiple of this, that a height is cached for.\n */\nconst BUCKET = 8;\n/** The children drawn around the view, by key: its first, its last and those it held when it was set (`id` joins them). */\ninterface Band {\n  id: string;\n  from: string;\n  to: string;\n  held: ReadonlySet<string>;\n}\n/** A message to draw and bring into view: by key, the element with `id` in it or its first or last message, and whether to focus it. */\ninterface Reach {\n  key: string;\n  id: string | null;\n  /** Whether to show the child itself, message or not, as `reveal` by key does; the keys step on to a message. */\n  child: boolean;\n  forward: boolean;\n  focus: boolean;\n  block: MessageListRevealBlock;\n}\n\n/** The average of the heights measured. */\nfunction averageOf(heights: ReadonlyMap<string, number>): number {\n  let sum = 0;\n  for (const height of heights.values()) sum += height;\n  return sum / heights.size;\n}\n\n/**\n * Where a slot's child sits, from the top of its first box's margin to the bottom of its last one's, in viewport pixels\n * (less the springs): a slot draws no box of its own (`display: contents`). One with nothing drawn has no size.\n * @claim \"a slot draws no box of its own\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > puts each child in a slot that draws no box, keeping a continued message's spacing, in a list of any length)\n * @claim \"One with nothing drawn has no size\" registry/ouro/components/ouro/message/message-list.tsx verify:fileLine(registry/ouro/components/ouro/message/message-list.tsx, /if \\(parts\\.length === 0\\) return \\{ top: 0, size: 0 \\};/)\n */\nfunction extentOf(slot: Element): { top: number; size: number } {\n  const parts = [...slot.children].filter((part) => part.getClientRects().length > 0);\n  if (parts.length === 0) return { top: 0, size: 0 };\n  const first = parts[0]!;\n  const last = parts.at(-1)!;\n  const top = boxOf(first).top - parseFloat(getComputedStyle(first).marginTop);\n  return { top, size: boxOf(last).bottom + parseFloat(getComputedStyle(last).marginBottom) - top };\n}\n\n/**\n * The children to draw before the view is known: those within `view` pixels of the end, or around the child at `anchor`.\n */\nfunction firstRange(count: number, size: (index: number) => number, anchor: number, view: number): [number, number] {\n  if (anchor < 0) {\n    let from = count - 1;\n    // Stryker disable next-line ConditionalExpression,EqualityOperator: a windowed list has more than 20 children, which the first view rarely all takes, and one that does draws them all either way.\n    for (let height = size(from); from > 0 && height < view; height += size(--from));\n    // Stryker disable next-line ArithmeticOperator: an end past the last child draws no more.\n    return [from, count - 1];\n  }\n  let from = anchor;\n  let to = anchor;\n  // Past either end, a range draws the same children (each size past them is the estimate, so it stops).\n  // Stryker disable next-line ConditionalExpression,EqualityOperator: past the first child a range draws the same children, and a child more at exactly half the view is one the window's first look settles.\n  for (let height = 0; from > 0 && height < view / 2; height += size(--from));\n  // Stryker disable next-line ConditionalExpression,EqualityOperator,ArithmeticOperator: past the last child a range draws the same children, and a child more at exactly half the view is one the window's first look settles.\n  for (let height = 0; to < count - 1 && height < view / 2; height += size(++to));\n  return [from, to];\n}\n\n// The springs (`springy`). Tuned to feel like a phone's messages app, subtle rather than wobbly:\n// a slow trackpad scroll opens the messages farthest from the pointer by a few pixels, a fling by\n// up to SPREAD, and they close again in about half a second with an overshoot of a pixel or less.\n/** Apple's response (seconds) and damping fraction: a little under critical, so a spread closes with a hint of overshoot. */\nconst SPRING = { response: 0.42, damping: 0.72 };\n/**\n * The share of each scroll a message trails by, once it is REACH px or more from where the reader scrolls.\n * @claim \"The share of each scroll a\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > trails the wheel the more the farther a message is from the pointer, and settles back to no transform)\n */\nconst LAG = 0.14;\n/**\n * How far from where the reader scrolls, in px, a message trails fully; nearer, it trails in proportion.\n * @claim \"How far from where the reader\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > trails the wheel the more the farther a message is from the pointer, and settles back to no transform)\n */\nconst REACH = 400;\n/**\n * The most a message trails by, in px: it eases into this limit and never passes it.\n * @claim \"The most a message trails by\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > trails the wheel the more the farther a message is from the pointer, and settles back to no transform)\n * @claim \"The most a message trails by\" registry/ouro/components/ouro/message/message-list.tsx verify:fileLine(registry/ouro/components/ouro/message/message-list.tsx, /SPREAD\\s\\*\\sMath\\.tanh\\(value\\s\\/\\sSPREAD\\)/)\n */\nconst SPREAD = 20;\n/** The share of a push past either end (a wheel or finger with nowhere left to scroll) that the messages follow. */\nconst STRETCH = 0.25;\n/**\n * How long a scroll counts as the reader's after their last wheel, touch, key or scroll, in ms: momentum keeps it going.\n * Once a scroll is theirs, so is the rest of it, until the browser says it ended (`scrollend`): a fling goes on off the main\n * thread, so a long frame between its scroll events never hands the rest of it to the list. Without `scrollend`, this alone decides.\n * @claim \"until the browser says it ended\" registry/ouro/components/ouro/message/message-list.springs.touch.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.touch.test.tsx::follows the whole of a fling through a long frame, and settles only once it stops)\n * @claim \"until the browser says it ended\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > keeps a scroll the reader's until the browser says it ended, however long a frame takes)\n */\nconst ARMED = 250;\n/** How long, in ms, after a wheel turn the list leaves the reader's place unwritten, and past the frame it turned in: a scroll position set meanwhile stops the wheel's own scroll. */\nconst WHEEL_REST = 80;\n/** A gap between a wheel's events shorter than this is the same turn of the wheel, its events waiting behind long frames; a longer one is a new turn. */\nconst WHEEL_GAP = 4 * WHEEL_REST;\n/** How long, in ms, after a wheel turn the browser's first scroll is still the wheel's: a loaded machine begins an animated wheel scroll a frame or more after the turn, past the rest. */\nconst WHEEL_START = 1000;\n/** A message this close to its place, in px, and this slow, in px/ms, is at rest, once the reader's scroll has ended. */\nconst REST = 0.25;\nconst REST_SPEED = 0.01;\n\n/**\n * How many messages the springs have drawn away from where they are laid out, in all lists: with none, a box is where it is laid out.\n * @claim \"How many messages the springs have\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > reads where messages are with no more work than before once they rest)\n */\nlet shifted = 0;\n\n/**\n * How far the springs draw each message from where it is laid out, in px, while it moves.\n * @claim \"How far the springs draw each\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > never changes the scroll position, and keeps the reader's place by where messages are laid out)\n */\nconst shifts = new WeakMap<Element, number>();\n\n// The list's one action bar and menu, loaded with the first message that has actions.\n// Once it has loaded, a list that mounts later starts with it, rather than getting it a commit after its first.\nlet layerModule: Promise<typeof MessageBarLayer> | undefined;\nlet loadedLayer: typeof MessageBarLayer | undefined;\nconst loadLayer = () =>\n  (layerModule ??= import(\"@/registry/ouro/components/ouro/message/message-parts\").then((module) => (loadedLayer = module.MessageBarLayer)));\n\n/** Where an element is laid out: its box, less the spring of the message it is in. */\n/** A child's key, from `Children.toArray`, or null for one that is not an element. */\nfunction keyOf(child: ReturnType<typeof Children.toArray>[number] | undefined): Key | null {\n  return isValidElement(child) ? child.key : null;\n}\n\n/** The children's keys as a set, built in render when the list's first or last children change. */\nfunction keySet(children: readonly ReturnType<typeof Children.toArray>[number][]): Set<Key | null> {\n  return new Set(children.map(keyOf));\n}\n\n// Each key's index, rebuilt only when the keys change; the keys are text, so they compare by what they say.\nfunction useIndexByKey(keys: readonly string[]): Map<string, number> {\n  // Joined by NUL, which no key holds.\n  const text = keys.join(\"\\0\");\n  return useMemo(() => new Map(text.split(\"\\0\").map((key, index) => [key, index])), [text]);\n}\n\nfunction boxOf(element: Element): { top: number; bottom: number; height: number } {\n  const box = element.getBoundingClientRect();\n  if (shifted === 0) return box;\n  let shift = 0;\n  for (let item = element.closest(items); item !== null; item = item.parentElement!.closest(items)) shift += shifts.get(item) ?? 0;\n  return { top: box.top - shift, bottom: box.bottom - shift, height: box.height };\n}\n\n/**\n * Whether an element has a box: one hidden (`display: none`, or inside such an element) has none, and reads as all zeros.\n * @claim \"one hidden (`display: none`, or inside\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList through a long conversation > never puts the Tab stop on a hidden message, the newest or one in view, as the view shows the messages around it)\n */\nfunction laidOut(element: Element): boolean {\n  return element.getClientRects().length > 0;\n}\n\n/**\n * Halves `list`, laid out down the page, for the first message whose box `before` says is not yet past the point it looks\n * for. A hidden message's zero box would break the halving, so a step that lands on one goes to the nearest message\n * with a box; none in the range means the point lies past it.\n * @claim \"A hidden message's zero box would\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList through a long conversation > keeps the reader's place as they scroll and older history loads, under a header, with a hidden message in view and one below it)\n * @claim \"A hidden message's zero box would\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList through a long conversation > never puts the Tab stop on a hidden message, the newest or one in view, as the view shows the messages around it)\n */\nfunction halve(list: readonly Element[], before: (box: { top: number; bottom: number }) => boolean): number {\n  return halveShown(list, laidOut, (element) => before(boxOf(element)));\n}\n\n/**\n * The springs of one list: `moved` tells them the list scrolled itself, so no message trails it.\n * @claim \"The springs of one list: `moved`\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > follows only the reader's part of a scroll the list adds to as it follows a new message)\n */\ninterface Springs {\n  moved(by: number): void;\n  stop(): void;\n}\n\n/** Whether to reduce motion under a provider's `motion`, asking the device now, so a frame loop sees a change of its setting at once. */\nfunction reducesMotion(motion: OuroMotion | undefined): boolean {\n  return motion === \"reduced\" || (motion !== \"full\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches);\n}\n\n/**\n * Springs the messages as the reader scrolls. One frame loop for the whole list, running only\n * while a message moves; each frame finds the messages in or near view by halving, so a long\n * conversation costs what a short one does, reads their boxes, then writes their transforms.\n * @claim \"One frame loop for the whole\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > moves only the messages in or near view, reading as few in a thousand as in fifty, on one frame loop)\n */\nfunction springs(scroller: HTMLElement, content: HTMLElement, reduced: () => boolean): Springs {\n  const moving = new Map<HTMLElement, SpringState>();\n  let list = topItems(content);\n  // The scroll position the springs last followed, less the list's own scrolling since.\n  let top = scroller.scrollTop;\n  // Where the list last put the scroll position itself, until its scroll event, which WebKit sends no scrollend after.\n  let own: number | null = null;\n  // How far the reader pushed past an end since the last frame.\n  let pushed = 0;\n  // Where the reader scrolls from: the pointer or finger, or, null, the focused message, for the keys.\n  let finger: number | null = null;\n  let armedUntil = Number.NEGATIVE_INFINITY;\n  // Whether the reader's scroll is still going, from their first scroll event until `scrollend`, where the browser has it.\n  let scrolling = false;\n  const ends = \"onscrollend\" in scroller;\n  // Whether a scroll since the last frame went on with a scroll of the reader's still going.\n  let going = false;\n  let touchY = 0;\n  let touchTop = 0;\n  let frame = 0;\n  let then = 0;\n  // The messages near view at the last frame.\n  let seen = new Set<HTMLElement>();\n\n  const draw = (item: HTMLElement, value: number) => {\n    if (!shifts.has(item)) {\n      shifted++;\n      item.style.willChange = \"transform\";\n      // Stryker disable next-line StringLiteral: the attribute's presence is what styles and tests read.\n      item.setAttribute(\"data-ouro-settling\", \"\");\n    }\n    shifts.set(item, value);\n    item.style.transform = `translateY(${value}px)`;\n  };\n  // At rest a message has no transform, and no layer of its own, so its text is drawn crisp.\n  const rest = (item: HTMLElement) => {\n    moving.delete(item);\n    if (shifts.delete(item)) shifted--;\n    item.style.removeProperty(\"transform\");\n    item.style.removeProperty(\"will-change\");\n    if (item.getAttribute(\"style\") === \"\") item.removeAttribute(\"style\");\n    item.removeAttribute(\"data-ouro-settling\");\n  };\n  const middle = (box: { top: number; bottom: number }) => (box.top + box.bottom) / 2;\n  // The messages within half the list's height of its view, found by halving the list.\n  const nearby = (view: DOMRect) => {\n    const above = view.top - view.height / 2;\n    const below = view.bottom + view.height / 2;\n    let low = 0;\n    let high = list.length;\n    while (low < high) {\n      const at = (low + high) >> 1;\n      // Stryker disable next-line EqualityOperator: a message whose edge meets the band's edge to the pixel is out of sight either way.\n      if (boxOf(list[at]!).bottom <= above) low = at + 1;\n      else high = at;\n    }\n    const band: { item: HTMLElement; box: { top: number; bottom: number } }[] = [];\n    for (let at = low; at < list.length; at++) {\n      const box = boxOf(list[at]!);\n      // Stryker disable next-line EqualityOperator: a message whose edge meets the band's edge to the pixel is out of sight either way.\n      if (box.top >= below) break;\n      band.push({ item: list[at]!, box });\n    }\n    return band;\n  };\n\n  const tick = (now: number) => {\n    frame = 0;\n    const elapsed = Math.max(now - then, 0);\n    then = now;\n    const view = scroller.getBoundingClientRect();\n    const scrolled = scroller.scrollTop - top;\n    top = scroller.scrollTop;\n    const push = pushed;\n    pushed = 0;\n    if (reduced()) return [...moving.keys()].forEach(rest);\n    // A move of a list's height or more is a jump (End from far up, a link to an old message), not a scroll, unless it goes on\n    // with the reader's scroll: a fling that a long frame gathered into one scroll event.\n    const kick = going || Math.abs(scrolled) < view.height ? scrolled : 0;\n    going = false;\n    const band = nearby(view);\n    const near = new Set(band.map(({ item }) => item));\n    // A message that leaves the band is out of sight: it rests at once.\n    for (const item of moving.keys()) if (!near.has(item)) rest(item);\n    if (kick !== 0 || push !== 0) {\n      // Where the scroll starts: the pointer or finger, or, for the keys, the focused message, which\n      // lands exactly where they put it while the others trail.\n      const held = finger === null ? scroller.ownerDocument.activeElement!.closest<HTMLElement>(items) : null;\n      const anchor = held === null ? { top: finger!, bottom: finger! } : boxOf(held);\n      const known = band.filter(({ item }) => moving.has(item)).map(({ item, box }) => ({ at: middle(box), state: moving.get(item)! }));\n      for (const { item, box } of band) {\n        if (item === held) {\n          rest(item);\n          continue;\n        }\n        const at = middle(box);\n        const reach = Math.min(Math.max(anchor.top - at, at - anchor.bottom, 0) / REACH, 1);\n        // A message that comes near mid-scroll starts where its nearest moving neighbour is, so no gap opens at the band's edge.\n        // Stryker disable next-line EqualityOperator: of two neighbours exactly as near, either is as near.\n        const neighbour = seen.has(item) ? undefined : known.reduce<(typeof known)[number] | undefined>((best, other) => (best === undefined || Math.abs(other.at - at) < Math.abs(best.at - at) ? other : best), undefined);\n        const state = moving.get(item) ?? neighbour?.state ?? { value: 0, velocity: 0 };\n        const value = state.value + kick * LAG * reach - push * (1 - reach);\n        moving.set(item, { value: SPREAD * Math.tanh(value / SPREAD), velocity: state.velocity });\n      }\n    }\n    seen = near;\n    let springing = false;\n    for (const [item, state] of moving) {\n      const next = springAt(state.value, 0, state.velocity, elapsed, SPRING);\n      // Stryker disable next-line EqualityOperator: a spring lands exactly on the rest speed only by chance, and a frame later it rests either way.\n      if (Math.abs(next.value) < REST && Math.abs(next.velocity) < REST_SPEED) {\n        // While the reader's scroll goes on, a message drawn away that comes back to its place waits there for the scroll's end,\n        // asking for no frames: the next scroll event of a fling may come only after a long frame, and moves it again.\n        if (scrolling && shifts.has(item)) {\n          moving.set(item, { value: 0, velocity: 0 });\n          draw(item, 0);\n        } else rest(item);\n      } else {\n        springing = true;\n        moving.set(item, next);\n        draw(item, next.value);\n      }\n    }\n    if (springing) frame = requestAnimationFrame(tick);\n  };\n  // A frame for the messages, when none is asked for yet.\n  const ask = () => {\n    if (frame !== 0) return;\n    then = performance.now();\n    frame = requestAnimationFrame(tick);\n  };\n  const run = () => {\n    if (!reduced()) ask();\n  };\n  const arm = () => {\n    armedUntil = performance.now() + ARMED;\n  };\n  // Whether the list is at the end it is being pushed toward: the top for `delta` up, the bottom for down.\n  const atEnd = (delta: number) => {\n    // Stryker disable next-line EqualityOperator: a push of 0 moves nothing, whichever end it is checked against.\n    if (delta < 0) return scroller.scrollTop <= 0;\n    return scroller.scrollTop >= scroller.scrollHeight - scroller.clientHeight - 1;\n  };\n\n  const onScroll = () => {\n    const mine = scroller.scrollTop === own;\n    own = null;\n    if (scrolling || performance.now() <= armedUntil) {\n      going ||= scrolling;\n      // Only a scroll of the reader's waits for its scrollend: WebKit sends none after the list's own.\n      if (!mine) scrolling = ends;\n      arm();\n      run();\n    } else top = scroller.scrollTop;\n  };\n  // The reader's scroll ended: the messages waiting at their places rest, in the next frame.\n  const onScrollEnd = () => {\n    scrolling = false;\n    if (moving.size > 0) ask();\n  };\n  const onWheel = (event: WheelEvent) => {\n    finger = event.clientY;\n    arm();\n    const delta = event.deltaMode === 0 ? event.deltaY : event.deltaY * LINE;\n    if (!atEnd(delta)) return;\n    pushed += delta * STRETCH;\n    run();\n  };\n  const onTouchStart = (event: TouchEvent) => {\n    finger = touchY = event.touches[0]!.clientY;\n    touchTop = scroller.scrollTop;\n    // Stryker disable next-line all: a finger scrolls only once it moves, and each move arms the list again.\n    arm();\n  };\n  const onTouchMove = (event: TouchEvent) => {\n    const y = event.touches[0]!.clientY;\n    // A finger moving up scrolls down, as a positive wheel does.\n    const delta = touchY - y;\n    finger = touchY = y;\n    // Pushing past an end, where the list did not scroll.\n    if (scroller.scrollTop === touchTop && atEnd(delta)) {\n      pushed += delta * STRETCH;\n      run();\n    }\n    touchTop = scroller.scrollTop;\n    arm();\n  };\n  const onKey = () => {\n    finger = null;\n    arm();\n  };\n  // A message the keys move focus to lands where they put it at once, its ring with it.\n  const onFocus = (event: FocusEvent) => {\n    const item = (event.target as Element).closest<HTMLElement>(items);\n    if (finger === null && item !== null) rest(item);\n  };\n  const observer = new MutationObserver((records) => {\n    // Stryker disable next-line ConditionalExpression: finding the messages again when none came or went finds the same ones.\n    if (records.some(touchesItems)) list = topItems(content);\n  });\n  observer.observe(content, { childList: true, subtree: true });\n  // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only lets the browser scroll without waiting for these listeners.\n  const passive = { passive: true };\n  scroller.addEventListener(\"scroll\", onScroll, passive);\n  scroller.addEventListener(\"scrollend\", onScrollEnd);\n  scroller.addEventListener(\"wheel\", onWheel, passive);\n  scroller.addEventListener(\"touchstart\", onTouchStart, passive);\n  scroller.addEventListener(\"touchmove\", onTouchMove, passive);\n  scroller.addEventListener(\"keydown\", onKey);\n  scroller.addEventListener(\"focusin\", onFocus);\n  // Stryker disable next-line all: with the scroll, wheel and touchmove listeners gone, nothing reads what these change, and stop() rests every message first, so a scrollend left behind finds none moving and asks for no frame; removing them frees memory only.\n  const forget = () => (observer.disconnect(), scroller.removeEventListener(\"scrollend\", onScrollEnd), scroller.removeEventListener(\"touchstart\", onTouchStart), scroller.removeEventListener(\"keydown\", onKey), scroller.removeEventListener(\"focusin\", onFocus));\n  return {\n    moved(by) {\n      top += by;\n      own = scroller.scrollTop;\n    },\n    stop() {\n      // Stryker disable next-line all: a frame left after this finds no message moving, and asks for none.\n      frame = (cancelAnimationFrame(frame), 0);\n      [...moving.keys()].forEach(rest);\n      scroller.removeEventListener(\"scroll\", onScroll);\n      scroller.removeEventListener(\"wheel\", onWheel);\n      scroller.removeEventListener(\"touchmove\", onTouchMove);\n      // Stryker disable next-line all: with the scroll, wheel and touchmove listeners gone, nothing reads what these change, and with no message moving a scrollend asks for no frame.\n      forget();\n    },\n  };\n}\n\n/**\n * The \"Jump to latest\" pill: a raised quiet button over the newest messages, 16px text and\n * a 44px target on a coarse pointer, fading in where motion is allowed.\n * @claim \"pill: a raised quiet button over the newest\" registry/ouro/components/ouro/message/message-list.touch.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.touch.test.tsx::keeps the reader's place on a phone once they swipe up, and jumps back with a 44px button)\n * @claim \"pill: a raised quiet button over the newest\" registry/ouro/components/ouro/message/message-list.touch.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.touch.test.tsx::keeps 16px message text on a landscape phone)\n */\nconst jumpClass =\n  \"press pointer-events-auto relative m-0 box-border inline-flex h-9 items-center gap-1.5 rounded-full border border-solid border-border \" +\n  \"bg-background px-3.5 text-base font-medium text-foreground shadow-(--shadow-md) pointer-fine:h-8 pointer-fine:text-sm whitespace-nowrap \" +\n  \"cursor-pointer touch-manipulation outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground motion-safe:active:scale-(--ouro-press-scale) \" +\n  \"transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) starting:opacity-0\";\n\ninterface Spoken {\n  id: number;\n  text: string;\n}\n\n/**\n * A conversation: `Message`s in a scrolling, labeled region that opens at the newest one.\n * A short conversation sits at the region's bottom, by the composer under it, as in a chat\n * app; put what starts it (who it is with, a way to older history) first among the children,\n * and it sits right above the first message. While the reader is at the bottom it follows new messages and streaming text; once they\n * scroll up, nothing moves their view, and a \"Jump to latest\" button appears. At the bottom it also\n * follows what reaches past its end without changing any message's size, such as the action bar\n * beside a reply's last line. Nor does something in a message that gets shorter for a moment and\n * longer again, such as a picture's placeholder swapped for the picture, pull it off its end. Each new\n * message from someone else is read to screen readers once, politely: a streamed reply\n * when it finishes, and a first reply in a list that mounted empty. History is never\n * announced: the messages it mounts with, several messages filling an empty list at once\n * (history fetched after mount), older messages loaded above, and a message whose `key` changes in place (a temporary id\n * swapped for the server's). Every message re-keyed at once is not held that way: the view moves a little, since windowing holds a place by a child's key. Older messages loaded above a scrolled-up reader leave the message\n * they are reading where it was, in every frame, and so does a message above them that moves, such\n * as a post a reply moves to the end. When the message they are on is the one that moves, the\n * messages around it keep their place. A page of many older messages goes in 20 a frame, those\n * nearest the reader first, so loading it never holds the page up for long (when the messages are\n * the list's own children, each with a `key`).\n * Switching to another conversation is opening one: key the list by the conversation, or give it\n * the other conversation's messages with its `conversation` (or, without one, messages that share no\n * `key` with those it held), even after it held none for a while. Either way it\n * opens at the other's newest message, wherever the reader was, with nothing announced; focus that\n * was on a message moves to the newest one in view. A scroll up from the end stops the list following\n * new messages at once, before the browser reports it. The list follows by how far it is from the\n * bottom, not which way it last scrolled, so your code going to a message (`scrollIntoView`) stops\n * it too, even as the first messages arrive. Scrolling is never announced.\n *\n * While older history may load, set `hasOlder`, and `loadingOlder` while it loads: the list keeps\n * room above the first message for \"Loading older messages\", so nothing moves as it shows. Fetch\n * older pages ahead of the reader, newer before older, rather than waiting for them to reach the\n * top, so they seldom see it.\n *\n * Give it a height (`className=\"h-96\"`, or `flex-1` in a column), since it scrolls inside it.\n * Nothing in it overflows the boxes around it, so moving focus or scrolling a message into view\n * scrolls the list, not the page around it.\n *\n * A conversation of more than 20 children draws only the messages near its view (`windowing`),\n * each measured as it draws, with space kept for the rest, so a long conversation opens and redraws\n * in about the time a screenful does. The reader's place holds as the messages above them are\n * measured and as older ones load above, in one frame. The newest message, the one with focus and\n * any still streaming stay drawn, and the arrow keys, Home and End reach every message, drawing the\n * one they reach. The browser's find in page sees only what is drawn: search your own messages and\n * call `actionsRef.current.reveal(id)` to show a match, as a quote does. Each child sits in an element\n * of its own that draws no box (`display: contents`, marked `data-ouro-message-list-slot`), so CSS\n * that selects the list's direct children selects those elements, in a list of any length.\n *\n * The messages spring as the reader scrolls, as in a phone's messages app: each trails the scroll a\n * little and catches up, the farther from the pointer, finger or focused message the more, and a\n * fling or a push past either end spreads them apart for a moment. The scroll position never moves\n * for it, and at rest, once the reader's scroll has ended, no message has a transform. `springy={false}` turns it off, and it is off with\n * reduced motion.\n *\n * The messages are one Tab stop. Tab lands on the newest message in view (or the one focused\n * last, while it shows), and the arrow keys, Home, End, Page Up and Page Down move between\n * messages, with a focus ring; a message taller than the list scrolls through first. The right\n * arrow (the left one, right to left) goes into the focused message's toolbar, such as its action\n * bar, else its first control, and Tab goes through its controls. Tab never stops on the other\n * messages' controls, so the next Tab after a message's own controls leaves the list. Nor does it\n * stop on the focus guards an open menu puts around its button, so Tab from a message whose menu\n * is open goes on through its controls rather than back to the message. A new\n * message never takes focus, and when the focused message goes, focus goes to the one now in its\n * place. Each message that is an article carries its place among them for screen readers\n * (`aria-posinset`, `aria-setsize`). `onMessageKeyDown` adds keys of your own on the focused\n * message, such as 1 to 6 for quick reactions.\n *\n * On a Mac the list reads ⌘↑, ⌘↓, ⌥↑ and ⌥↓ on a focused message as Home, End, Page Up and Page\n * Down, and calls `preventDefault()` on them. Listen for an app shortcut on those keys in the\n * capture phase (`window.addEventListener(\"keydown\", onKey, { capture: true })`), which runs\n * before the list: call `preventDefault()` there and the list leaves the key alone. Or set\n * `pageKeys={false}` to leave Page Up, Page Down, ⌥↑ and ⌥↓ to the app.\n *\n * Your own message components work too: mark each one's root `data-ouro-message-list-item`, the\n * reader's own with `data-role=\"user\"` and one still streaming with `aria-busy=\"true\"`, and put its\n * author's name and its text in elements marked `data-ouro-message-author` and\n * `data-ouro-message-content`, as `Message` does. The list keeps the reader's place among them and\n * announces them as it does `Message`s, and moves focus among them. Give your component a focus\n * ring (`focus-visible:outline-2`), as `Message` has. Leave `data-ouro=\"message\"` to Ouro's `Message`: it names\n * the element Ouro's Message, and X-ray outlines it as one.\n *\n * Use a plain list instead for messages that do not arrive live, such as an inbox.\n *\n * @group Chat\n * @see https://ui.ouroboros.bot/docs/message-list\n *\n * @example\n * <MessageList label=\"Conversation with Ouro\" className=\"h-[60dvh]\">\n *   {messages.map((message) => (\n *     <Message key={message.id} role={message.role} name={message.author} streaming={message.streaming}>\n *       {message.text}\n *     </Message>\n *   ))}\n * </MessageList>\n * <MessageList\n *   label=\"Team chat\"\n *   className=\"flex-1\"\n *   onMessageKeyDown={(message, event) => {\n *     const reaction = quickReactions[Number(event.key) - 1];\n *     if (reaction) react(message.id, reaction);\n *   }}\n * >\n *   {posts.map((post) => (\n *     <article key={post.id} id={post.id} data-ouro-message-list-item=\"\" data-role={post.mine ? \"user\" : \"assistant\"}>\n *       <span data-ouro-message-author=\"\">{post.author}</span>\n *       <p data-ouro-message-content=\"\">{post.text}</p>\n *     </article>\n *   ))}\n * </MessageList>\n * @claim \"Every message re-keyed at once is not held that way\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > keeps the reader's place, and opens nothing, when every message in view gets a new key in place and the rest keep theirs)\n * @claim \"The messages spring as the reader\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > trails the wheel the more the farther a message is from the pointer, and settles back to no transform)\n * @claim \"The messages spring as the reader\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > spreads the messages apart on a push past either end, and draws them back)\n * @claim \"The scroll position never moves\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > never changes the scroll position, and keeps the reader's place by where messages are laid out)\n * @claim \"`springy={false}` turns it off\" registry/ouro/components/ouro/message/message-list.springs.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.springs.test.tsx::MessageList springs > moves nothing with reduced motion, or with springy={false})\n * @claim \"the list keeps room above\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps room above the first message while hasOlder, so loading older messages covers no message or focus ring and moves nothing)\n * @claim \"Your own message components work too\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the reader's place among an app's own messages marked data-ouro-message-list-item, and announces them as it does Messages)\n * @claim \"A conversation: `Message`s in a scrolling\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > is a named region that opens at the newest message, which is its Tab stop)\n * @claim \"The messages are one Tab stop\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > is one Tab stop: Tab lands on the newest message, goes through its controls, and leaves the list)\n * @claim \"The messages are one Tab stop\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > keeps focus where it is when a message arrives, and the Tab stop on the message focused last while it shows)\n * @claim \"and the arrow keys, Home, End, Page Up\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > moves between messages with the arrow keys, Home, End, Page Up and Page Down, with a focus ring)\n * @claim \"and the arrow keys, Home, End, Page Up\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > moves a page at a time to the next message when the next starts more than a list's height away)\n * @claim \"a message taller than the list scrolls\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > scrolls through a message taller than the list, a line or a page at a time, before moving on)\n * @claim \"The right arrow (the left one, right to\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > goes into the focused message's toolbar with the right arrow, else its first control, and the left arrow right to left)\n * @claim \"Tab never stops on the other\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > reaches a control between messages in the Tab order, and passes over the other messages' controls)\n * @claim \"Nor does it stop on the focus guards\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > passes over the focus guards around an open menu's button, so Tab never bounces back to the message)\n * @claim \"A new message never takes focus\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > keeps focus where it is when a message arrives, and the Tab stop on the message focused last while it shows)\n * @claim \"and when the focused message goes\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > moves focus from a focused message replaced under a new key to its replacement, not to its old index, as older messages go in above)\n * @claim \"and when the focused message goes\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > moves focus to the message now in the place of a focused message that goes, and leaves a control that goes from a message to the app)\n * @claim \"Each message that is an article carries\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > gives each message its place among them for screen readers, and keeps an app's own)\n * @claim \"On a Mac the list reads\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > reads ⌘↑ and ⌘↓ as Home and End, and ⌥↑ and ⌥↓ as Page Up and Page Down, on a Mac)\n * @claim \"which runs before the list\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > leaves ⌘↑, ⌘↓, ⌥↑ and ⌥↓ alone on a Mac once an app's capture-phase shortcut prevented them)\n * @claim \"`onMessageKeyDown` adds keys of your own\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList keyboard > hands the app a key pressed on the focused message, and not one pressed in a control inside it)\n * @claim \"Each new message from someone else\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > announces a reply still streaming in the first messages to fill an empty list, once it finishes)\n * @claim \"Each new message from someone else\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > announces a reply that was streaming when the list mounted, once it finishes)\n * @claim \"Each new message from someone else\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > does not read back the user's own message)\n * @claim \"and so does a message above\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the reader's place when a message above them moves to the end and the list keeps its height)\n * @claim \"When the message they are on is the one that moves\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the reader's place by the messages around the one they are on when it moves to the end)\n * @claim \"When the message they are on is the one that moves\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps the reader's place by the other message in view when the one they are on moves to the end)\n * @claim \"The list follows by how far\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > stays at a message an app scrolls to as the first messages arrive, instead of following to the newest)\n * @claim \"A page of many older messages goes in 20\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > puts pages of older messages in a few at a time, holding the reader's message in place in every frame)\n * @claim \"A page of many older messages goes in 20\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > puts a few older messages in at once)\n * @claim \"Switching to another conversation is opening\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > switches a list %s to another conversation of a thousand at its newest, in its first frame, from anywhere in the one before)\n * @claim \"focus that was on a message moves\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > moves focus on a message of the conversation before to the newest in view of the next, without scrolling)\n * @claim \"A scroll up from the end\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > stops following the newest message once the list is scrolled up, even before the scroll event comes)\n * @claim \"History is never announced: the messages\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > never announces the first messages that fill an empty list, such as history fetched after mount)\n * @claim \"History is never announced: the messages\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > never announces older history loaded above, and keeps the reader's place while it loads)\n * @claim \"Nothing in it overflows the boxes around it\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > keeps its messages' parts inside its own scroll box, so focus and scrollIntoView never scroll a box around it)\n * @claim \"Scrolling is never announced\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > never announces while the reader scrolls)\n * @claim \"Nor does something in a message\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList switching conversations > stays at its end when a picture in a message shrinks and grows back between frames, as a placeholder swapped for its picture does)\n * @claim \"At the bottom it also follows\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > follows its end at the bottom when something in a message reaches past it, though no message changes size)\n * @claim \"A conversation of more than 20 children draws\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > draws only the messages near the view of a long conversation, in a list as tall as all of them)\n * @claim \"A conversation of more than 20 children draws\" test/message-list-windowing.bench.test.tsx verify:fileLine(test/message-list-windowing.bench.test.tsx, /expect\\(windowed\\.redraw\\)\\.toBeLessThan\\(whole\\.redraw \\/ 2\\)/)\n * @claim \"The reader's place holds as the messages above\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps the reader's place while messages above are measured, scrolling up through them)\n * @claim \"The reader's place holds as the messages above\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps the reader's place when a page of older messages loads above, putting it in at once)\n * @claim \"The newest message, the one with focus\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > keeps the message with focus drawn, and focus on it, as the reader scrolls far away)\n * @claim \"The newest message, the one with focus\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > follows new messages and streaming text at the bottom, and shows Jump to latest once the reader scrolls up)\n * @claim \"and the arrow keys, Home and End reach every message\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > moves focus to the first message with Home and back to the newest with End, drawing the message it reaches)\n * @claim \"and the arrow keys, Home and End reach every message\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > walks up past the messages first drawn with the Up arrow, each one drawn and shown as focus reaches it)\n * @claim \"The browser's find in page sees only\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > finds a message by its text among the app's messages, which the page does not hold, and reveals it)\n * @claim \"Each child sits in an element of its own\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > puts each child in a slot that draws no box, keeping a continued message's spacing, in a list of any length)\n * @claim \"as a quote does\" registry/ouro/components/ouro/message/message-list.windowing.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.windowing.test.tsx::MessageList windowing > shows the quoted message far up the conversation when the reader presses its quote)\n * @claim \"A short conversation sits at\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > sits a short conversation at its bottom, by the composer under it, with the room above it empty)\n * @claim \"put what starts it (who\" registry/ouro/components/ouro/message/message-list.test.tsx verify:testExists(registry/ouro/components/ouro/message/message-list.test.tsx::MessageList > sits what starts a short conversation, its first child, right above the first message)\n */\nexport function MessageList(props: MessageListProps): JSX.Element {\n  const {\n    label,\n    children,\n    jumpLabel = \"Jump to latest\",\n    initialAnchor,\n    conversation,\n    loadingOlder = false,\n    hasOlder = false,\n    loadingOlderLabel = \"Loading older messages\",\n    newMessageLabel = (author: string, text: string) => `${author}: ${text}`,\n    onMessageKeyDown,\n    pageKeys = true,\n    springy = true,\n    maxWidth,\n    windowing = true,\n    heightCache,\n    actionsRef,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    autoScroll,\n    stickToBottom,\n    ...rest\n  } = props;\n  useAppearanceClassNameCheck(\n    \"MessageList\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `<div className=\"${token}\"><MessageList /></div>`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"MessageList\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          label === undefined && [\"label is missing, so the conversation has no name\", '<MessageList label=\"Conversation\">'],\n          (autoScroll !== undefined || stickToBottom !== undefined) && [\n            `${autoScroll !== undefined ? \"autoScroll\" : \"stickToBottom\"} is not a prop; the list follows new messages while the reader is at the bottom`,\n            '<MessageList label=\"Conversation\">',\n          ],\n          Children.toArray(children).some((child) => !isValidElement(child)) && [\n            \"MessageList holds Messages\",\n            '<MessageList label=\"Conversation\"><Message role=\"user\" name=\"Ana\">Hi</Message></MessageList>',\n          ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const scrollerRef = useRef<HTMLDivElement | null>(null);\n  const contentRef = useRef<HTMLDivElement | null>(null);\n  // One action bar and one menu for every message, rather than one each: the messages give the layer what to show.\n  const [Layer, setLayer] = useState<typeof MessageBarLayer | undefined>(() => loadedLayer);\n  const [layer] = useState(() => createRowLayer<MessageBarData>(() => void loadLayer().then((Loaded) => setLayer(() => Loaded))));\n  // Whether the view follows new content: whether it was at the bottom before the content changed.\n  const pinned = useRef(true);\n  const [showJump, setShowJump] = useState(false);\n  const [spoken, setSpoken] = useState<Spoken[]>([]);\n  const nextId = useRef(0);\n  // The newest label function, for the observer set up once below.\n  const labelFor = useRef(newMessageLabel);\n  const keyFor = useRef(onMessageKeyDown);\n  const anchorFor = useRef(initialAnchor);\n  const pagesFor = useRef(pageKeys);\n  useLayoutEffect(() => {\n    labelFor.current = newMessageLabel;\n    keyFor.current = onMessageKeyDown;\n    anchorFor.current = initialAnchor;\n    pagesFor.current = pageKeys;\n  });\n  // The list's ends, which Tab passes through to leave the messages behind (see the keyboard effect).\n  const startRef = useRef<HTMLSpanElement | null>(null);\n  const endRef = useRef<HTMLSpanElement | null>(null);\n  // The mark that holds the scroll height while the list follows its end (see the layout effect).\n  const floorRef = useRef<HTMLSpanElement | null>(null);\n  // Moves focus to a message, making it the Tab stop; set by the keyboard effect.\n  const moveTo = useRef<(item: HTMLElement) => void>(undefined);\n  const keyHandler = useRef<(event: KeyboardEvent<HTMLElement>) => void>(undefined);\n  // With messages, a message is the Tab stop and the region is not; without, the region is while it scrolls.\n  // Stryker disable next-line ArrowFunction,ConditionalExpression,EqualityOperator: a first guess only; the keyboard effect counts the messages before the first paint.\n  const [hasItems, setHasItems] = useState(() => Children.count(children) > 0);\n\n  // A page of older messages that comes at once goes in a chunk a frame, those nearest the reader first: each frame's\n  // work stays short, and the reader's place is kept as each chunk goes in. A few go in at once.\n  // Read again only when the app hands in new children, not on the list's own renders as it measures and places them.\n  const all = useMemo(() => Children.toArray(children), [children]);\n  const top = keyOf(all[0]);\n  // Above WINDOW_ABOVE children, only the messages near the view draw; see \"The window\" below.\n  const windowed = windowing && all.length > WINDOW_ABOVE;\n  // The key of the first child, and of the first one drawn: a page of older ones above it waits.\n  // Stryker disable next-line ObjectLiteral: an empty start takes the first child's key in the first render instead; this only spares that render.\n  const [edge, setEdge] = useState(() => ({ first: top, drawn: top }));\n  // Whether the list drew every child until it grew long: until it finds its window it keeps those children where they are.\n  const [drewWhole, setDrewWhole] = useState(!windowed);\n  // A windowed list puts a page of older messages in at once, as space above the messages drawn, so it waits for none and\n  // spares the render this would cost. Should it become whole again, what it drew first stays the edge.\n  if (!windowed && top !== edge.first) setEdge({ first: top, drawn: all.findIndex((child) => keyOf(child) === edge.drawn) > CHUNK ? edge.drawn : top });\n  const shown = windowed ? all : all.slice(Math.max(0, all.findIndex((child) => keyOf(child) === edge.drawn)));\n  const keys = useMemo(() => all.map((child, index) => String(keyOf(child) ?? index)), [all]);\n\n  // The window: which children draw, and the space kept for the others. Each child sits in a slot of its own that draws\n  // no box, so the list's spacing and the continued messages' margins work as without one.\n  // The heights of every child measured, by key and width, kept for the life of the list or by the app (`heightCache`).\n  const [ownCache] = useState(() => new Map<string, number>());\n  const cache = heightCache ?? ownCache;\n  const [measured, setMeasured] = useState<Measured>(() => ({ heights: new Map(), gap: 16, estimate: ESTIMATE, bucket: cache.get(CACHED_WIDTH) ?? null }));\n  const cacheRef = useRef(cache);\n  useLayoutEffect(() => {\n    cacheRef.current = cache;\n  });\n  // The children drawn around the view, by key: the first, the last and every one between them when the band was set.\n  const [band, setBand] = useState<Band | null>(null);\n  const [reach, setReach] = useState<Reach | null>(null);\n  // What a `reveal` waits on: told whether its message came into view, once it has or another took its place.\n  const revealed = useRef<((found: boolean) => void) | null>(null);\n  const settleRef = useRef((found: boolean) => {\n    revealed.current?.(found);\n    revealed.current = null;\n    setReach(null);\n  });\n  // A new message to reach, in place of one still on its way.\n  const requestRef = useRef((next: Reach) => {\n    revealed.current?.(false);\n    revealed.current = null;\n    setReach(next);\n  });\n  if (!windowed && band !== null) setBand(null);\n  // Once long it stays set, as the band decides from then on; another conversation clears it.\n  if (!windowed && !drewWhole) setDrewWhole(true);\n  // The newest child's key the announcements last heard of, so the children after it, which just arrived, draw until they are heard.\n  const [heard, setHeard] = useState<string | null>(null);\n  // The keys of the messages the announcements wait on, kept drawn until a reply that streamed is heard.\n  // Stryker disable next-line StringLiteral: no child's key is any text before the announcements publish theirs; each begins with a dot.\n  const [waitingKeys, setWaitingKeys] = useState(\"\");\n  // The key of the child focus was last in, kept drawn so focus stays as the reader scrolls away.\n  const [focusKey, setFocusKey] = useState<string | null>(null);\n  // Each child's height, read again only when the children or the heights measured change: the window reads every child's on\n  // every scroll, and a cached height's key is text built from the child's key and the width.\n  const sizes = useMemo(() => keys.map((key) => measured.heights.get(key) ?? cache.get(`${key}\\0${measured.bucket}`) ?? measured.estimate), [keys, measured, cache]);\n  const sizeOf = (index: number) => sizes[index]!;\n  // Each child's index by its key, built when the keys change, not on every render (the keys are text, so they compare by what they say).\n  const indexes = useIndexByKey(keys);\n  // How much the first draw takes before the view is measured: in server HTML and as it hydrates, FIRST_VIEW, so the two\n  // match; in a list that opens in the browser, a view's height, so opening costs what the view shows.\n  // Stryker disable next-line ArrowFunction: a snapshot of undefined reads as false, as the client's does.\n  const hydrating = useSyncExternalStore(noChange, () => false, () => true);\n  const firstView = hydrating ? FIRST_VIEW : Math.min(lastView ?? Infinity, window.innerHeight);\n  let draws: (index: number) => boolean = () => true;\n  if (windowed) {\n    const last = keys.length - 1;\n    let range: readonly [number, number];\n    let held: ReadonlySet<string> | null = null;\n    if (band !== null) {\n      // A band whose edge was deleted draws none of it: the window finds itself again, from what is drawn, before the browser\n      // draws, and the space kept for what went keeps the rest where it was.\n      // Stryker disable next-line LogicalOperator,UnaryOperator: whatever range a band with a deleted edge draws, the window finds itself again before the browser draws.\n      range = [indexes.get(band.from) ?? last, indexes.get(band.to) ?? -1];\n      // Children that went in between its edges since (a page of older messages after a first child that is no message) draw as\n      // space, as above the band: the window then draws those the view reaches, before the browser draws. Children that took the\n      // place of ones that went (a message's key changed in place) draw.\n      // Stryker disable next-line ArithmeticOperator: a child more or less between the edges is one the window draws, or not, before the browser draws.\n      if (range[1] - range[0] + 1 > band.held.size) held = band.held;\n    } else if ((showJump || drewWhole) && indexes.has(String(edge.drawn))) {\n      // A list the reader scrolled up in that grows long (older history loading above, newer messages after), or any list that\n      // drew whole until now, draws, to begin with, no more than the WINDOW_ABOVE children it drew whole, from the first of them:\n      // the rest, and what came with the page, is space. The window then finds itself from where those children are, before the\n      // browser draws, so the view stays where it is, though code moved it before the browser reported the scroll.\n      const from = indexes.get(String(edge.drawn))!;\n      range = [from, Math.min(last, from + WINDOW_ABOVE)];\n    } else range = firstRange(keys.length, sizeOf, initialAnchor === undefined ? -1 : childNamed(all, keys, initialAnchor), firstView);\n    const kept: (number | undefined)[] = [last, indexes.get(focusKey!), reach === null ? undefined : indexes.get(reach.key)];\n    // What just arrived after the newest heard, so it is heard, and what still streams, so its end is.\n    const since = indexes.get(heard!) ?? last;\n    // Stryker disable next-line EqualityOperator: the newest is kept as the last child anyway.\n    for (let index = Math.max(since + 1, last + 1 - KEEP_ARRIVED); index <= last; index++) kept.push(index);\n    for (const key of waitingKeys.split(\"\\n\")) kept.push(indexes.get(key));\n    all.forEach((child, index) => {\n      if (!isValidElement(child)) return;\n      const props = child.props as { streaming?: unknown; \"aria-busy\"?: unknown };\n      if (props.streaming === true || props[\"aria-busy\"] === true || props[\"aria-busy\"] === \"true\") kept.push(index);\n    });\n    draws = (index) => (index >= range[0] && index <= range[1] && (held === null || held.has(keys[index]!))) || kept.includes(index);\n  }\n  // The slots, with space kept for each run of children not drawn: their heights and the gaps between them, less the gap the\n  // list puts before the space itself.\n  const slots: ReactNode[] = [];\n  let run: number | null = null;\n  const space = (end: number) => {\n    let height = 0;\n    for (let index = run!; index < end; index++) height += sizeOf(index) + (index > 0 && sizeOf(index) > 0 ? measured.gap : 0);\n    // Children that draw nothing take no space, and no gap either.\n    // Stryker disable next-line ConditionalExpression,EqualityOperator: a run of only such children lies between two kept children far from the view, which the window then draws together.\n    if (height > 0) slots.push(<div key={`space:${keys[run!]}`} aria-hidden=\"true\" data-ouro-message-list-space=\"\" className=\"shrink-0\" style={{ height: Math.max(0, height - (run! > 0 ? measured.gap : 0)) }} />);\n    run = null;\n  };\n  shown.forEach((child, at) => {\n    const index = at + all.length - shown.length;\n    if (!draws(index)) {\n      run ??= index;\n      return;\n    }\n    if (run !== null) space(index);\n    slots.push(\n      <div key={keys[index]} {...{ [SLOT]: keys[index] }} className=\"contents\">\n        {child}\n      </div>,\n    );\n  });\n  // The newest always draws, so no run is left after it.\n  // What the window's effects read: the latest render's.\n  const view = { windowed, all, keys, indexes, measured, band, reach, sizeOf };\n  const viewRef = useRef(view);\n  useLayoutEffect(() => {\n    viewRef.current = view;\n  });\n  // The keys of the newest few children: when they or the first child's change, the list looks again for a switch.\n  const recent = all.slice(-RECENT).map(keyOf);\n  // Every key the list held when its first or newest ones last changed, and the conversation they were: another conversation is a new\n  // `conversation`, or without one, messages that share no key with those. Whether the list has held messages, and how many times\n  // it has switched to another conversation since.\n  const [track, setTrack] = useState(() => ({\n    first: top,\n    recent,\n    keys: new Set(all.map(keyOf)),\n    conversation,\n    pending: null as { conversation: Key | undefined; keys: ReadonlySet<Key | null> } | null,\n    // The keys it held when its conversation was last confirmed: what a wholesale change under the same name leaves alone.\n    confirmed: new Set(all.map(keyOf)) as ReadonlySet<Key | null>,\n    // Stryker disable next-line ConditionalExpression,EqualityOperator: the first messages of a list that mounted empty, taken for a switch, reset only what it already holds (the edge, the band, no focus, no jump), and the keyboard effect's first sync clears `switched` before anything reads it.\n    held: all.length > 0,\n    switches: 0,\n  }));\n  // Messages that share no key with `keys`: another conversation's, or the first ones.\n  const strangers = (keys: ReadonlySet<Key | null>) => !all.some((child) => keyOf(child) !== null && keys.has(keyOf(child)));\n  const changed = top !== track.first || recent.length !== track.recent.length || recent.some((key, at) => key !== track.recent[at]);\n  const renamed = conversation !== track.conversation && (track.pending === null || conversation !== track.pending.conversation);\n  // Named back to the conversation it holds before another one's messages came: nothing waits.\n  const back = track.pending !== null && conversation === track.conversation;\n  if (changed || renamed || back) {\n    // A conversation is switched to when `conversation` changes with its messages, or, named before they come (as an app\n    // that keeps the last messages while it fetches does), when messages come that share no key with those it held then.\n    // One first named for messages the list holds names them. Without `conversation`, messages that share no key with\n    // those held are another conversation's.\n    let pending = renamed || back ? null : track.pending;\n    let fresh = false;\n    let named = track.conversation;\n    if (all.length === 0) {\n      // None to show: whatever is named waits for its messages.\n      if (renamed) pending = { conversation, keys: track.keys };\n    } else if (!track.held) {\n      fresh = true;\n      named = conversation;\n    } else if (renamed && track.conversation === undefined) {\n      fresh = changed && strangers(track.keys);\n      named = conversation;\n    } else if (renamed && changed) {\n      fresh = true;\n      named = conversation;\n    } else if (renamed) {\n      // Messages already another conversation's, come before their name, take the name with no switch; else it waits for them.\n      if (strangers(track.confirmed)) named = conversation;\n      else pending = { conversation, keys: track.keys };\n    } else if (pending !== null) {\n      if (strangers(pending.keys)) [fresh, named, pending] = [true, pending.conversation, null];\n    } else fresh = conversation === undefined && strangers(track.keys);\n    const opening = fresh && track.held;\n    if (opening) {\n      // The other conversation draws from its newest, whatever of the one before was drawn.\n      // Stryker disable next-line ObjectLiteral: an empty edge has no drawn key, so the slice starts at the first child, as drawn: top does; the next frame's step sets it to the first child's key. The same rows draw either way; on a non-windowed list the empty edge makes the render near line 1020 call setEdge again, one extra render before the commit and no extra commit.\n      setEdge({ first: top, drawn: top });\n      // Another conversation opens at its newest, not where the one before was drawn.\n      setDrewWhole(false);\n      setBand(null);\n      // The next opens at its newest, with no jump to offer and no focus kept on a message of the one before.\n      setFocusKey(null);\n      // Stryker disable next-line CallExpression: the layout effect on the switch count calls reopen, which clears the jump in the same commit before the browser draws.\n      setShowJump(false);\n    }\n    setTrack({\n      first: top,\n      recent,\n      keys: keySet(all),\n      conversation: named,\n      pending,\n      // Confirmed again by a new name or switch, and by any change under the same name but a wholesale one, which may be the\n      // next conversation's messages come ahead of its name.\n      confirmed:\n        // Stryker disable next-line ConditionalExpression,EqualityOperator,LogicalOperator: not equivalent for the two LogicalOperator mutants; \"confirms nothing for messages that come back to a list emptied under the same name\" and \"adopts a name that comes after its messages\" (message-list.test.tsx) fail on both, but per-test coverage attributes this expression to other tests, so the shard never runs them. A new name comes only with no pending name, so the last clause confirms it as well; with no keys held, or none now, every key is a stranger or nothing changes, so the set kept is the one that would be read.\n        named !== track.conversation || fresh || (pending === null && all.length > 0 && track.keys.size > 0 && !strangers(track.keys)) ? keySet(all) : track.confirmed,\n      // Stryker disable next-line ConditionalExpression,EqualityOperator: a list that holds nothing is empty at its first commit, and its first messages open it either way.\n      held: track.held || all.length > 0,\n      // Stryker disable next-line ArithmeticOperator: only a change of the count runs the layout effect, and a count that goes down by one each switch changes as a count that goes up does; it is never compared with another.\n      switches: track.switches + (opening ? 1 : 0),\n    });\n  }\n  const latest = useRef(all);\n  useLayoutEffect(() => {\n    latest.current = all;\n  });\n  useEffect(() => {\n    // Stryker disable next-line ConditionalExpression: with nothing waiting, a step draws from the first child, as now; this only spares a render.\n    if (edge.drawn === edge.first) return;\n    // A frame apart, the next chunk: the one above those drawn.\n    const frame = requestAnimationFrame(() =>\n      setEdge((now) => {\n        const list = latest.current;\n        return { ...now, drawn: keyOf(list[Math.max(0, list.findIndex((child) => keyOf(child) === now.drawn) - CHUNK)]) };\n      }),\n    );\n    // Stryker disable next-line all: a step left from before goes in the same render as the next one; cancelling it only spares the call.\n    return () => cancelAnimationFrame(frame);\n  }, [edge]);\n  // Another conversation opens at its newest message, wherever the reader was in the one before, before the browser draws it.\n  const reopen = useRef<() => void>(undefined);\n  // Set as the list switches, for the keyboard effect: focus on a message that went goes to the new conversation's Tab stop.\n  // Stryker disable next-line BooleanLiteral: the keyboard effect's first sync(true) sets it false, on mount, before any focus or switch can read it.\n  const switched = useRef(false);\n  useLayoutEffect(() => {\n    if (track.switches === 0) return;\n    switched.current = true;\n    // The next conversation opens as the list did: what its view shows, then the rest.\n    wide.current = false;\n    // A reveal on its way finds nothing in the conversation before.\n    settleRef.current(false);\n    reopen.current!();\n  }, [track.switches]);\n\n  // While older messages may load, room above the first message holds \"Loading older messages\". It outlasts `hasOlder`\n  // until it has left the view, or the list is at its end, so it goes without moving a message.\n  const [room, setRoom] = useState(hasOlder);\n  if (hasOlder && !room) setRoom(true);\n  const roomRef = useRef<HTMLDivElement | null>(null);\n  useLayoutEffect(() => {\n    if (hasOlder || !room) return;\n    const scroller = scrollerRef.current!;\n    const drop = () => {\n      // Stryker disable next-line EqualityOperator: room whose bottom meets the view's top to the pixel is out of view either way.\n      if (pinned.current || roomRef.current!.getBoundingClientRect().bottom <= scroller.getBoundingClientRect().top) setRoom(false);\n    };\n    drop();\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only lets the browser scroll without waiting for this listener.\n    scroller.addEventListener(\"scroll\", drop, { passive: true });\n    // Stryker disable next-line all: once the room is gone or wanted again, nothing reads what this listener would change; removing it frees memory only.\n    return () => scroller.removeEventListener(\"scroll\", drop);\n  }, [hasOlder, room]);\n\n  const keyboardRef = useKeyboardScrollable<HTMLDivElement>(!hasItems);\n  const setScroller = useMergedRef<HTMLDivElement | null>(keyboardRef, scrollerRef);\n\n  // The springs, while `springy`: told when the list scrolls itself, so no message trails that.\n  const springsRef = useRef<Springs | null>(null);\n  // Whether to reduce motion, asked afresh each time, so a change of the setting counts at once.\n  const { motion } = useOuro();\n  const motionRef = useRef(motion);\n  useLayoutEffect(() => {\n    motionRef.current = motion;\n  }, [motion]);\n  useLayoutEffect(() => {\n    if (!springy) return;\n    const handle = springs(scrollerRef.current!, contentRef.current!, () => reducesMotion(motionRef.current));\n    springsRef.current = handle;\n    return () => {\n      handle.stop();\n      // Stryker disable next-line all: a stopped handle's `moved` changes nothing in the page.\n      springsRef.current = null;\n    };\n  }, [springy]);\n\n  // Keeps the reader's place after messages came, went, moved or changed size: set by the effect below.\n  const holdRef = useRef<() => void>(undefined);\n  // How far the content is drawn up (a `translate`) to hold the reader's place while the wheel turns: what the scroll position\n  // takes once the wheel rests, or before the reader reaches an end. Set by the effect below.\n  const carriedRef = useRef(0);\n\n  const toBottom = useCallback(() => {\n    const scroller = scrollerRef.current!;\n    // At the end, nothing above is held: the carry goes with the scroll to the end.\n    // Stryker disable next-line ConditionalExpression: with nothing carried, removing no translate and setting the carry to 0 again change nothing.\n    if (carriedRef.current !== 0) {\n      carriedRef.current = 0;\n      contentRef.current!.style.removeProperty(\"translate\");\n    }\n    const before = scroller.scrollTop;\n    scroller.scrollTop = scroller.scrollHeight;\n    ownTop.current = scroller.scrollTop;\n    springsRef.current?.moved(scroller.scrollTop - before);\n  }, []);\n\n  // Goes to the end and follows it again: a message that arrives before the browser reports the scroll is followed too.\n  const toNewest = () => {\n    // Stryker disable next-line BooleanLiteral: the list holds where its end was when last measured, which is where this scrolls it, so it follows there anyway; this covers an end that moved since.\n    pinned.current = true;\n    toBottom();\n    setShowJump(false);\n  };\n\n  // Open at the newest message (or at `initialAnchor`), then follow growth (new messages, streaming text, images\n  // loading, the keyboard resizing the list) only while pinned. Layout effect and resize\n  // observer callbacks run before paint, so the view never flashes off the bottom.\n  // While unpinned, the first message whose top is in view stays where it is, so older history\n  // loading above it never moves the reader, even in the frame they scroll. This replaces the\n  // browser's scroll anchoring, which is off: Chrome's adjustment read as the reader scrolling\n  // up, and Safari has none. Where an app turns the browser's anchoring back on\n  // (`overflow-anchor: auto` on the scroller) and the browser has it, the browser corrects alone.\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current!;\n    const content = contentRef.current!;\n    // The messages whose top is in view (else the one filling it), each with where it sits in the\n    // content. Those still in the page are held in place, by the ones that moved together: one may\n    // itself have been replaced (a key change), or moved away on its own (a post that a reply moved\n    // to the end). Where a message sits in the content does not change as the list scrolls, so the\n    // reader's own scrolling in the same frame is never taken back.\n    // Stryker disable next-line ArrayDeclaration: keepAnchor fills it below, before the observer can first read it.\n    let anchors: { node: Element; at: number }[] = [];\n    // How far the list could scroll when the anchors were taken. A scroll event that finds it changed came\n    // after messages came, went or grew, and before the resize observer has kept the reader's place.\n    let end = 0;\n    // The scroll position then: the reader's scrolling since is what the correction leaves alone.\n    let taken = 0;\n    // The part of the corrections the scroll position could not take yet: WebKit keeps it in whole pixels, and a move under\n    // half a pixel is not made, so each correction's remainder goes into the next. Dropped, the remainders of a page of older\n    // messages drawn a row a frame would add up, and the reader's place would creep.\n    let owed = 0;\n    const keepAnchor = () => {\n      const view = scroller.getBoundingClientRect();\n      // Finds the anchors among the nodes, in the order they come in the page.\n      const find = (nodes: readonly Element[]) => {\n        const origin = content.getBoundingClientRect().top;\n        // Laid out, the messages' tops only grow down the page (one inside another starts within it), so the first whose top\n        // is in view is found by halving, and only the messages near the view are read: a long conversation, scrolled, costs\n        // what a short one does.\n        // Stryker disable next-line EqualityOperator: a message whose top meets the view's edge to the pixel is the same anchor either way.\n        const first = halve(nodes, (box) => box.top < view.top);\n        // The messages whose top is in view, so not one partly above the view, whose growth the reader is not reading. When none\n        // starts in view, the messages filling it, then those that start within a view's height below it.\n        const held: { node: Element; at: number }[] = [];\n        const take = (from: number, until: number) => {\n          for (let at = from; at < nodes.length; at++) {\n            if (!laidOut(nodes[at]!)) continue;\n            const top = boxOf(nodes[at]!).top;\n            // Stryker disable next-line EqualityOperator: a message whose top meets the edge to the pixel is out of the band either way.\n            if (top >= until) break;\n            held.push({ node: nodes[at]!, at: top - origin });\n          }\n        };\n        take(first, view.bottom);\n        if (held.length === 0) {\n          // Back from the first below the view's top, those that reach into the view, through to a message that is inside no other.\n          for (let at = first - 1; at >= 0; at--) {\n            if (!laidOut(nodes[at]!)) continue;\n            const box = boxOf(nodes[at]!);\n            // Stryker disable next-line EqualityOperator: a message that ends exactly at the view's top is out of view either way, and one below follows it.\n            if (box.bottom > view.top) held.unshift({ node: nodes[at]!, at: box.top - origin });\n            if (!content.contains(nodes[at]!.parentElement!.closest(items))) break;\n          }\n          take(first, view.bottom + view.height);\n          // A windowed list may draw only messages far below the view, as it is moved to a place not yet drawn: they hold it.\n          if (held.length === 0) take(first, Infinity);\n        }\n        return held;\n      };\n      const messages = [...content.querySelectorAll(items)];\n      anchors = find(messages);\n      // When no message shows, what a child draws that holds none (a day's heading) holds the place: it may be all the view\n      // shows, as when it is revealed in a windowed list, with the messages around it not drawn yet.\n      // An anchor is never wholly above the view (those that reach into it are the ones taken), so it shows when it starts above the view's end.\n      // Stryker disable next-line EqualityOperator,MethodExpression: a message whose edge meets the view's to the pixel shows none of itself either way; and where some anchors show, looking again with the children that hold no message finds those same messages showing, which hold the place alike.\n      if (!anchors.some(({ node }) => boxOf(node).top < view.bottom)) anchors = find(withBareChildren(content, messages));\n      end = farthest();\n      taken = scroller.scrollTop;\n    };\n    const farthest = () => scroller.scrollHeight - scroller.clientHeight;\n    // At the bottom as the list was before this change, or as it is now: growth at the end, or the\n    // view getting shorter, leaves a list that was at the bottom still there, and a scroll anywhere\n    // else (the reader's, a key's, or code going to a message) leaves it.\n    // Stryker disable next-line EqualityOperator: a list exactly as far from the bottom as counts as at it is at its end either way.\n    const atBottom = () => Math.abs(end - scroller.scrollTop) <= AT_BOTTOM || farthest() - scroller.scrollTop <= AT_BOTTOM;\n    // While the list follows its end, the scroll height keeps at least the content's height there, held by a 1px mark at that\n    // depth (`floorRef`), so a change that shortens the content for a moment and lengthens it again (a picture's placeholder\n    // swapped for the picture, with a layout read between) never lets the browser pull the scroll position up, which would\n    // stop the following with no one scrolling. The mark is placed absolutely, so moving it lays out nothing else. A real\n    // change of height resizes the content, and the resize observer moves the mark with it before the browser draws. Once\n    // the reader has left the end, the next change lets it go, which moves nothing, since what it holds is past the\n    // content's end; not the scroll itself, since moving the mark then stops WebKit's own scroll anchoring where an app has\n    // it on. While the wheel turns, it holds at least the content's height at each turn, and goes only once the wheel rests:\n    // a reader still within a change's height of the end would otherwise be pulled up as a row above comes in shorter, and\n    // the browser's pull, like any scroll position written, ends WebKit's wheel.\n    const floorMark = floorRef.current!;\n    let floor = 0;\n    const setFloor = (px: number) => {\n      // Stryker disable next-line ConditionalExpression: only spares writing the values the mark already holds.\n      if (px === floor) return;\n      floor = px;\n      // Out of the layout when it holds nothing, so moving it never stops the browser's own scroll anchoring.\n      floorMark.style.display = px > 0 ? \"block\" : \"\";\n      floorMark.style.top = `${Math.max(0, px - 1)}px`;\n    };\n    const followEnd = () => {\n      const height = content.offsetHeight;\n      setFloor(height > scroller.clientHeight ? height : 0);\n      toBottom();\n      // Content that settles at another height in a later render of the same task (long messages folding behind \"See more\"\n      // as a conversation opens) moves no node the mutation observer hears of, and the resize observer runs only after the\n      // frame's animation callbacks: until then the mark would hold the view past the messages. Once the task's work is\n      // done, the end is followed to where it settled.\n      if (floor !== 0) queueMicrotask(() => content.offsetHeight !== floor && hold());\n    };\n    // Whether the list has opened: at its first messages, at `initialAnchor` if it holds that message, else at the newest.\n    let opened = false;\n    const open = () => {\n      if (content.querySelector(items) === null) return;\n      opened = true;\n      const id = anchorFor.current;\n      // By id, else the first message of the child with that key.\n      const keyed = (name: string) => {\n        const slot = [...content.querySelectorAll(`:scope > [${SLOT}]`)].find((node) => keyIs(node.getAttribute(SLOT)!, name));\n        return slot && topItems(slot)[0];\n      };\n      const target = id ? (topItems(content).find((item) => item.id === id) ?? keyed(id)) : undefined;\n      // None: the list stays at the end, as it opened, and follows the messages there: it goes there now, with messages that came\n      // after it mounted empty, before the browser draws them, unless code already scrolled it to one of them.\n      if (!target) {\n        pinned.current = atBottom();\n        if (pinned.current) followEnd();\n        return keepAnchor();\n      }\n      const view = scroller.getBoundingClientRect();\n      const box = boxOf(target);\n      // In the middle of the view, or its top at the view's top when it is taller. The springs are at rest as it opens.\n      scroller.scrollTop += box.top - view.top - Math.max(0, (scroller.clientHeight - box.height) / 2);\n      ownTop.current = scroller.scrollTop;\n      // Held from here, so older messages loading before the browser reports this scroll leave it where it opened, and\n      // following only if it opened at the end (the anchor was the newest).\n      keepAnchor();\n      pinned.current = atBottom();\n    };\n    followEnd();\n    keepAnchor();\n    open();\n    // The window keeps the reader's place this way too, before it reads where the view is.\n    holdRef.current = () => hold();\n    reopen.current = () => {\n      // Stryker disable next-line BooleanLiteral: a switch adds messages, so the observer holds in the microtask after the commit, before any frame or event, and a hold with the list at its end pins it again.\n      pinned.current = true;\n      followEnd();\n      // Stryker disable next-line CallExpression: the observer's hold in the microtask after the commit takes the anchors and the end, before any frame or event; at the end of the new conversation, the next message is then followed.\n      keepAnchor();\n      setShowJump(false);\n    };\n    // After messages come, go, move or change size: follow the end while pinned, else hold the anchor in place.\n    // A scroll position written while the wheel turns stalls WebKit's own scroll, so whatever moves the reader's place then (older\n    // history drawn above a few a frame, a row drawn in place of the space kept for it, taller or shorter than the estimate) is held\n    // by drawing the content that far up or down instead, a `translate` the wheel's own scroll never meets, and the scroll\n    // position takes it in one move once the wheel rests, or as the reader nears an end, so what went in above is always in reach.\n    let wheelAt = Number.NEGATIVE_INFINITY;\n    // The gap before the wheel's last event, when it was short (under WHEEL_GAP). A page drawing slowly hands the wheel's events over a\n    // frame or more apart, so the wheel counts as still turning for twice that gap, not only the rest.\n    let wheelGap = 0;\n    // The frame the wheel last turned in. Where a frame takes longer than the rest (a slow machine drawing much), the wheel's next\n    // events wait behind it, so the wheel turns until the time has passed and a later frame has begun.\n    let wheelFrame: CSSNumberish | null = null;\n    // The scroll a wheel started goes on until the browser says it ended (`scrollend`): WebKit animates a wheel's scroll after\n    // its last event, over frames a loaded machine draws slowly, and a scroll position written meanwhile stops it.\n    let wheelScrolling = false;\n    // Whether the wheel turned since the last scroll that was not the list's own: the turn's scroll, which may not have begun yet.\n    // Stryker disable next-line BooleanLiteral: before any turn, the last turn is never under WHEEL_START ago, so no scroll counts as one's either way.\n    let wheelStarts = false;\n    const turning = () => wheelScrolling || performance.now() - wheelAt < Math.max(WHEEL_REST, 2 * wheelGap) || document.timeline.currentTime === wheelFrame;\n    let resting: ReturnType<typeof setTimeout> | undefined;\n    let restFrame = 0;\n    // How close to an end, in px, the reader comes before the scroll position takes what is carried: a few frames of a fast wheel.\n    const edge = () => scroller.clientHeight / 4;\n    // The end the wheel last turned toward: -1 the top, 1 the bottom, 0 either, before it turns.\n    let heading = 0;\n    // Whether what is carried goes into the scroll position now. Near an end where the content, drawn by what is carried, would\n    // leave space with nothing in it, whichever way the wheel turns. Near the end the wheel turns toward, so what is past it is\n    // in reach. Not near the other: a wheel turned up from the bottom is near the bottom for its first frames, and a scroll\n    // position written then stops it.\n    const nearEnd = () => {\n      const top = scroller.scrollTop;\n      const carried = carriedRef.current;\n      // Where the view's bottom meets the bottom of what is drawn, drawn up by what is carried.\n      const last = farthest() - carried;\n      // Stryker disable next-line EqualityOperator: a scroll position exactly at the margin pays a frame sooner or later, and moves nothing on screen either way.\n      const space = (carried > 0 && top > last - edge()) || (carried < 0 && top < edge() - carried);\n      // Stryker disable next-line EqualityOperator: a scroll position exactly at the margin pays a frame sooner or later, and moves nothing on screen either way.\n      return space || (heading <= 0 && top < edge()) || (heading >= 0 && top > last - edge());\n    };\n    const pay = () => {\n      // Stryker disable next-line CallExpression: a rest left waiting pays nothing once this has paid, and a carry since starts it again.\n      clearTimeout(resting);\n      const by = carriedRef.current;\n      // Once the wheel rests, the end the list is not following is held no more: what was carried goes first, so nothing is pulled.\n      const letGo = () => void (!pinned.current && !turning() && setFloor(0));\n      // Stryker disable next-line ConditionalExpression: paying nothing removes no translate and scrolls by 0, which moves nothing.\n      if (by === 0) return letGo();\n      carriedRef.current = 0;\n      content.style.removeProperty(\"translate\");\n      const before = scroller.scrollTop;\n      scroller.scrollTop += by;\n      ownTop.current = scroller.scrollTop;\n      const applied = scroller.scrollTop - before;\n      springsRef.current?.moved(applied);\n      // The anchors sit where they did in the content, which a scroll does not move: only the list's own scroll since they were\n      // taken is left out of the reader's, so a change waiting for the resize observer is still held.\n      taken += applied;\n      letGo();\n    };\n    // Pays once the wheel has rested: after the rest, in a frame, so a page drawing nothing still begins one to tell by.\n    const rest = () => {\n      // Stryker disable next-line CallExpression: a second rest left waiting pays once the wheel rests, as this one does, and the later of the two then pays nothing.\n      clearTimeout(resting);\n      resting = setTimeout(() => (restFrame = requestAnimationFrame(() => (turning() ? rest() : pay()))), WHEEL_REST);\n    };\n    const carry = (by: number) => {\n      carriedRef.current += by;\n      content.style.translate = `0 ${-carriedRef.current}px`;\n      if (nearEnd()) pay();\n      else rest();\n    };\n    const onWheel = (event: WheelEvent) => {\n      heading = Math.sign(event.deltaY) || heading;\n      const now = performance.now();\n      const gap = now - wheelAt;\n      wheelGap = gap < WHEEL_GAP ? gap : 0;\n      wheelAt = now;\n      wheelFrame = document.timeline.currentTime;\n      wheelStarts = true;\n      // The scroll range the wheel turns in holds until it rests (see setFloor): at least the content's height now.\n      const height = content.offsetHeight;\n      // Stryker disable next-line EqualityOperator: a floor set to the height it already holds writes nothing.\n      if (height > Math.max(floor, scroller.clientHeight)) setFloor(height);\n      rest();\n      // A wheel pushing at an end scrolls nothing, so no scroll event says the reader got there.\n      // Stryker disable next-line ConditionalExpression,LogicalOperator: with nothing carried, paying pays nothing; the check only spares reading the layout on every turn of the wheel.\n      if (carriedRef.current !== 0 && nearEnd()) pay();\n    };\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only tells the browser the listener never cancels the wheel; no test can observe it.\n    scroller.addEventListener(\"wheel\", onWheel, { passive: true });\n    const hold = () => {\n      // Away from the bottom, by a scroll the scroll event has not reported yet (code scrolled to a message, a key), stops the following.\n      // A list at the old bottom follows. One that was following keeps on when its end came up, though something grew below\n      // in the same frame: the browser pulled the scroll down, the reader did not scroll. One the bottom came up to that was\n      // not following starts only when the browser reports that scroll: in a windowed list the bottom may come up as heights\n      // replace estimates above the view, which holding the place below undoes first.\n      // Stryker disable next-line EqualityOperator: a list exactly as far from the bottom as counts as at it is at its end either way.\n      pinned.current = Math.abs(end - scroller.scrollTop) <= AT_BOTTOM || (pinned.current && farthest() < end - AT_BOTTOM);\n      // A scroll of the list's height or more since the anchors were taken (to the top, to a message far off) set its own place: the held message has left the view.\n      // Stryker disable next-line EqualityOperator: a scroll of exactly the list's height leaves the held message at the view's edge either way.\n      const near = Math.abs(scroller.scrollTop - taken) < scroller.clientHeight;\n      // Where an app turned the browser's own anchoring back on, the browser corrects.\n      // Stryker disable next-line ConditionalExpression,StringLiteral: Chrome gives up its own anchoring once the list scrolls in that frame, so whether a second correction lands depends on timing a test cannot hold.\n      const native = getComputedStyle(scroller).overflowAnchor === \"auto\";\n      if (pinned.current) {\n        owed = 0;\n        followEnd();\n      } else if (!turning()) setFloor(0);\n      if (!pinned.current && near && !native) {\n        // Each message held that is still in the page, with where it sat in the content and how far it moved since. With each, how many\n        // of the others it passed or fell behind: a message that moved on its own (a post that a reply moved to the end) passed them.\n        const origin = content.getBoundingClientRect().top;\n        const held = anchors.filter(({ node }) => node.isConnected).map(({ node, at }) => ({ at, moved: boxOf(node).top - origin - at }));\n        const ranked = held.map((message) => ({\n          moved: message.moved,\n          // Stryker disable next-line EqualityOperator: two messages never sit at one place, and a message compared with itself is alike either way.\n          passed: held.filter((other) => other.at < message.at !== other.at + other.moved < message.at + message.moved).length,\n        }));\n        // The place is held by the messages that moved together, not one that moved away: of those, the one that moved least (with only\n        // one other in view, the one that did not go), and the first of those that moved alike.\n        const moved = (ranked.sort((a, b) => a.passed - b.passed || Math.abs(a.moved) - Math.abs(b.moved))[0]?.moved ?? 0) + owed;\n        const wheeling = turning();\n        // Stryker disable next-line EqualityOperator: a move of exactly half a pixel is under what the scroll position keeps (whole pixels in WebKit), carried or not.\n        if (Math.abs(moved) >= 0.5 && wheeling) {\n          owed = 0;\n          carry(moved);\n          return keepAnchor();\n        }\n        owed = moved;\n        if (Math.abs(moved) >= 0.5) {\n          const before = scroller.scrollTop;\n          scroller.scrollTop += moved;\n          ownTop.current = scroller.scrollTop;\n          const applied = scroller.scrollTop - before;\n          springsRef.current?.moved(applied);\n          // What rounding left over, carried: under a pixel. A move the browser did not apply in full (the list's end or start stopped it, smooth scrolling or snapping took it) is not a debt a later write can pay.\n          owed = Math.abs(moved - applied) < 1 ? moved - applied : 0;\n        }\n      } else owed = 0;\n      keepAnchor();\n    };\n    const follow = new ResizeObserver(hold);\n    follow.observe(content);\n    follow.observe(scroller);\n    // Messages that move without the list changing size (a post moved to the end by a reply) resize nothing: while\n    // the reader is scrolled up, the anchor is held as they move, before the browser draws. A move that also resizes\n    // the list is held here first, and the resize observer then finds it held. At the end, the list follows wherever its end\n    // went: something put in a message that reaches past the end (a picture that loads beside its last line) moves the\n    // end without resizing anything, so the resize observer would not see it. The list's one action bar moving between\n    // messages is left out: it shows on hover, and following it would move the list under the pointer.\n    const moves = new MutationObserver((all) => {\n      const records = all.filter((record) => !barOnly(record));\n      if (records.length === 0) return;\n      const touched = records.some(movesItems);\n      // The first messages, which may come after the list mounted empty, open it, before the browser draws them.\n      if (!opened) return open();\n      // The mark holds the scroll height, so a committed change of the content's own height is looked for too.\n      // Stryker disable next-line ConditionalExpression,ArrowFunction: not equivalent; \"drops the room at once when hasOlder ends\" (message-list.test.tsx) fails on both mutants, but per-test coverage attributes this observer callback to another test, so the shard never runs it.\n      const floorMoved = () => floor !== 0 && content.offsetHeight !== floor;\n      // Stryker disable next-line ConditionalExpression,LogicalOperator: a change that resizes the list is followed or held by the resize observer in the same frame, and holding when nothing moved finds nothing moved; both only spare the work.\n      if (pinned.current ? farthest() !== end || floorMoved() : touched) hold();\n    });\n    moves.observe(content, { childList: true, subtree: true });\n    const onScroll = (event: Event) => {\n      // Only the browser's own scroll, where it says when it ends. The first scroll after a turn is the wheel's when it comes\n      // within WHEEL_START, which a loaded machine may take to begin it; judged by time alone, never by the frame the wheel turned\n      // in, as a scroll the page makes in that frame (a scrollbar, a jump) is none of the wheel's, and with no scrollend after it\n      // would keep the place held by drawing for good. The list's own write is none of the wheel's, and leaves the turn's start.\n      if (scroller.scrollTop !== ownTop.current) {\n        if (event.isTrusted && \"onscrollend\" in scroller && wheelStarts && performance.now() - wheelAt < WHEEL_START) wheelScrolling = true;\n        wheelStarts = false;\n      }\n      // Leaving the bottom, even by a few pixels, stops the following; reaching it again follows.\n      pinned.current = atBottom();\n      // What is carried goes into the scroll position before the reader reaches an end, so it never stops them there.\n      if (nearEnd()) pay();\n      // Messages changed since the anchors were taken: leave them for the resize observer, which comes next.\n      if (farthest() === end) keepAnchor();\n      setShowJump(!pinned.current);\n    };\n    scroller.addEventListener(\"scroll\", onScroll, { passive: true });\n    const onScrollEnd = () => void (wheelScrolling = false);\n    scroller.addEventListener(\"scrollend\", onScrollEnd);\n    // Stryker disable next-line all: once the list is gone, nothing reads what these would change; disconnecting frees memory only.\n    return () => (scroller.removeEventListener(\"scrollend\", onScrollEnd), clearTimeout(resting), cancelAnimationFrame(restFrame), (carriedRef.current = 0), content.style.removeProperty(\"translate\"), follow.disconnect(), moves.disconnect(), scroller.removeEventListener(\"scroll\", onScroll), scroller.removeEventListener(\"wheel\", onWheel));\n  }, [toBottom]);\n\n  // The window, after every render that changed what it draws, every scroll and every resize: measures the slots drawn,\n  // keeps the reader's place as their heights replace the estimates, brings a message asked for into view, and draws the\n  // children the view and OVERSCAN reach.\n  const windowSync = useRef<(scrolled: boolean) => void>(undefined);\n  // Whether the rows past the view's edges draw: from the frame after the list opens, or another conversation opens in it.\n  const wide = useRef(false);\n  // Whether the estimate is fixed: once the rows past the view's edges are first measured.\n  // Stryker disable next-line BooleanLiteral: not equivalent; \"takes a switch from conversation alone: one whose messages share keys with the last is a switch, and messages re-keyed in the same one are not\" (message-list.test.tsx) fails on it, but per-test coverage attributes the first measurement to another test, so the shard never runs it.\n  const estimated = useRef(false);\n  const widening = useRef<{ frame: number; timer?: ReturnType<typeof setTimeout> } | null>(null);\n  const widen = () => {\n    // Stryker disable next-line ConditionalExpression: a second request in the same frame draws the same rows a frame later.\n    if (widening.current !== null) return;\n    // A frame, then a task: the one after the browser paints the frame the list opened in.\n    // Stryker disable next-line ObjectLiteral: the frame is set on the next line, before anything reads it.\n    const pending: { frame: number; timer?: ReturnType<typeof setTimeout> } = { frame: 0 };\n    widening.current = pending;\n    pending.frame = requestAnimationFrame(() => {\n      pending.timer = setTimeout(() => {\n        widening.current = null;\n        // Stryker disable next-line BooleanLiteral: not equivalent; \"opens with no more rows than fill the window, and draws the rows past the view's edges only after the first paint\" (message-list.windowing.test.tsx) fails on it, but per-test coverage attributes this timer to another test, so the shard never runs it.\n        wide.current = true;\n        // Stryker disable next-line BooleanLiteral: measuring as it widens finds the heights the last sync measured, and changes nothing.\n        windowSync.current!(true);\n      });\n    });\n  };\n  // The reader's own scrolling: when they last gave input, whether a scroll of theirs is going on, and whether they hold the\n  // scrollbar. A scroll made by code (find in page, a screen reader, a test tool, the app) is none of these.\n  // `code` is whether the last scroll was neither theirs nor the list's own (`ownTop`, where it last put the scroll position).\n  // Stryker disable next-line ObjectLiteral: an empty start reads as no input, no scroll going and nothing held, as these do.\n  const reader = useRef({\n    // Stryker disable next-line UnaryOperator: at most the first scroll after the list mounts is taken for the reader's, and its scrollend hands the next to code.\n    at: -Infinity,\n    // Stryker disable next-line BooleanLiteral: at most the first scroll after the list mounts is taken for the reader's, and its scrollend hands the next to code.\n    going: false,\n    held: false,\n    code: false,\n  });\n  const ownTop = useRef<number | null>(null);\n  // Where each slot drawn sits in the content, and its size, as last measured.\n  const tops = useRef(new Map<string, { top: number; size: number }>());\n  // How many messages each child drawn holds: a child that starts the conversation holds none.\n  const counts = useRef(new Map<string, number>());\n  // What the window last read, so a render that changed none of it (the app drawing again as someone types) reads no layout.\n  const synced = useRef<{ keys: readonly string[]; band: Band | null; measured: Measured; reach: Reach | null; windowed: boolean } | null>(null);\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current!;\n    const content = contentRef.current!;\n    const slotOf = (key: string) => [...content.children].find((node) => node.getAttribute(SLOT) === key);\n    // Scrolls a message into view: to the middle, to the top, or as little as it takes.\n    const bring = (element: HTMLElement, block: MessageListRevealBlock) => {\n      const box = boxOf(element);\n      const top = scroller.getBoundingClientRect().top;\n      const room = scroller.clientHeight;\n      const before = scroller.scrollTop;\n      // Stryker disable next-line EqualityOperator: at the margin to the pixel, the message is where scrolling would put it.\n      const above = box.top < top + EDGE || box.height > room - 2 * EDGE;\n      // Stryker disable next-line EqualityOperator: at the margin to the pixel, the message is where scrolling would put it.\n      const below = box.bottom > top + room - EDGE;\n      const centred = box.top - top - Math.max(0, (room - box.height) / 2);\n      scroller.scrollTop += block === \"center\" ? centred : block === \"start\" || above ? box.top - top - EDGE : below ? box.bottom - top - room + EDGE : 0;\n      springsRef.current?.moved(scroller.scrollTop - before);\n    };\n    windowSync.current = (scrolled) => {\n      const { windowed, keys, indexes, measured, band, reach, sizeOf } = viewRef.current;\n      // A list inside a hidden panel draws nothing to measure or place; it does once it shows, and resizes.\n      if (windowed && content.getClientRects().length === 0) return;\n      if (windowed && !scrolled) {\n        const contentTop = content.getBoundingClientRect().top;\n        let heights: Map<string, number> | undefined;\n        const rounded = Math.round(scroller.clientWidth / BUCKET);\n        // Stryker disable next-line ArithmeticOperator: the bucket only keys the cache, and any one number for each rounded width keys it alike.\n        const bucket = rounded * BUCKET;\n        cacheRef.current.set(CACHED_WIDTH, bucket);\n        // At a new width the heights are those of the old: the rows not drawn keep them as estimates until they draw.\n        if (measured.bucket !== bucket) heights = new Map(measured.heights);\n        const found = new Map<string, { top: number; size: number }>();\n        for (const slot of content.querySelectorAll(`:scope > [${SLOT}]`)) {\n          const key = slot.getAttribute(SLOT)!;\n          const { top, size } = extentOf(slot);\n          // Only a child that draws a box has a place to find the others by.\n          if (size > 0) found.set(key, { top: top - contentTop, size });\n          counts.current.set(key, topItems(slot).length);\n          cacheRef.current.set(`${key}\\0${bucket}`, size);\n          if (measured.heights.get(key) !== size) (heights ??= new Map(measured.heights)).set(key, size);\n        }\n        tops.current = found;\n        if (heights !== undefined) {\n          // The heights of children gone are forgotten.\n          const present = new Set(keys);\n          // Stryker disable next-line ConditionalExpression,CallExpression: keeping a gone child's height only holds memory: a key that comes back is measured again as it draws.\n          for (const key of heights.keys()) if (!present.has(key)) heights.delete(key);\n          // A render follows at once, which comes back here with the space kept at its new size. The gap is 1rem, so it\n          // changes only with the font size, which changes the heights too.\n          // The estimate is the average of the rows the list first draws past its view: those it opened with, and those drawn\n          // after, as the view alone may hold a few.\n          setMeasured({ heights, gap: parseFloat(getComputedStyle(content).rowGap), estimate: estimated.current ? measured.estimate : averageOf(heights), bucket });\n          estimated.current = wide.current;\n          return;\n        }\n        holdRef.current!();\n      }\n      if (reach !== null && !scrolled) {\n        const slot = slotOf(reach.key);\n        if (slot === undefined) {\n          // Not drawn yet (a page of older messages going in a few at a time), or gone.\n          if (!keys.includes(reach.key)) settleRef.current(false);\n        } else {\n          const found = topItems(slot);\n          // By id: the message it is in, else what the child draws around it (what starts the conversation).\n          const named = [...slot.querySelectorAll<HTMLElement>(\"[id]\")].find((node) => node.id === reach.id);\n          const target =\n            reach.id === null\n              ? ((reach.forward ? found[0] : found.at(-1)) ?? (reach.child ? (slot.firstElementChild as HTMLElement) : undefined))\n              : named && named.closest<HTMLElement>(`${items}, [${SLOT}] > *`)!;\n          if (target === undefined) {\n            // A child with no message in it (a day's heading): by key, the next child, that way, past the ends to none, which\n            // settles. None with the id: settles.\n            // Stryker disable next-line ConditionalExpression: an id no element in its child has is had by none in the children after, so stepping on settles too, a render each later.\n            if (reach.id === null) setReach({ ...reach, key: keys[keys.indexOf(reach.key) + (reach.forward ? 1 : -1)]! });\n            else settleRef.current(false);\n          } else {\n            bring(target, reach.block);\n            if (reach.focus) {\n              // A message drawn in this frame is not focusable from code yet (the keyboard effect marks it after): setting the\n              // tab index it reports makes an element focusable from code, and leaves one that already is as it is.\n              target.setAttribute(\"tabindex\", String(target.tabIndex));\n              target.focus({ preventScroll: true });\n            }\n            settleRef.current(true);\n            // The place is now where the message went.\n            holdRef.current!();\n          }\n        }\n      }\n      // Stryker disable next-line ConditionalExpression: a list drawn whole measures no slot to place a band by, and draws every child whatever the band says.\n      if (!windowed) return;\n      // Where each child starts, with the gap before it, from a slot drawn, which is where it is: the space kept for the\n      // children not drawn is built from the heights this reads, so any slot drawn places all of them alike.\n      // The view as it is now, once the reader's place is kept.\n      const viewTop = scroller.getBoundingClientRect().top - content.getBoundingClientRect().top;\n      const viewBottom = viewTop + scroller.clientHeight;\n      // Stryker disable next-line ConditionalExpression,EqualityOperator: a list that measures no height draws nothing to remember.\n      if (scroller.clientHeight > 0) lastView = scroller.clientHeight;\n      // As it opens, only what the view shows draws, so the frame it opens in is short; the rows past its edges draw after\n      // that frame is painted.\n      const over = wide.current ? Math.max(OVERSCAN, scroller.clientHeight) : 0;\n      // Stryker disable next-line ConditionalExpression: widening a list already wide only draws the same band again, a frame later.\n      if (!wide.current) widen();\n      const placed = tops.current.entries().next().value;\n      // Every child drawn draws nothing (the app hid them all): nothing to place by, until one draws.\n      /* istanbul ignore if @preserve -- the newest message always draws; this only keeps a list whose messages are all hidden from drawing every child */\n      // Stryker disable next-line ConditionalExpression: the newest message always draws, so there is always a slot to place by.\n      if (placed === undefined) return;\n      const near = indexes.get(placed[0])!;\n      const nearTop = placed[1].top;\n      // Each child's height with the gap before it, read once for the walks below: on every scroll, for every child.\n      const extents = keys.map((key, index) => {\n        const size = tops.current.get(key)?.size ?? sizeOf(index);\n        // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator: a gap more or less moves the band's edges by the gap, against an overscan fifty times it.\n        return size + (index > 0 && size > 0 ? measured.gap : 0);\n      });\n      const extent = (index: number) => extents[index]!;\n      let sum = 0;\n      const sums = extents.map((each) => {\n        const at = sum;\n        sum += each;\n        return at;\n      });\n      // Stryker disable next-line ConditionalExpression,EqualityOperator: a gap more or less moves the band's edges by the gap, against an overscan fifty times it.\n      const shift = nearTop - (near > 0 ? measured.gap : 0) - sums[near]!;\n      // Stryker disable next-line ArithmeticOperator: the shift is the content's 16px padding, which moves the band's edges by twice that against an 800px overscan.\n      const starts = sums.map((at) => at + shift);\n      // The band: from the first child that ends below the overscan's top to the last that starts above its bottom. The child\n      // the band is placed by is in view, so both stop by it.\n      let from = 0;\n      // Stryker disable next-line EqualityOperator: a child that ends exactly at the overscan's edge draws or not, and the next scroll corrects it.\n      while (starts[from]! + extent(from) <= viewTop - over) from++;\n      let to = keys.length - 1;\n      // Stryker disable next-line EqualityOperator: a child that starts exactly at the overscan's edge draws or not, and the next scroll corrects it.\n      while (starts[to]! >= viewBottom + over) to--;\n      // The band drawn now, by index: NaN, which no keep range holds and no band meets, where there is none or its edge went.\n      const drawnFrom = band === null ? NaN : (indexes.get(band.from) ?? NaN);\n      const drawnTo = band === null ? NaN : (indexes.get(band.to) ?? NaN);\n      const code = reader.current.code;\n      // Children already drawn stay drawn until they are twice the overscan from the view: a scroll back and forth finds them\n      // still in the page. After a scroll made by code, eight times, while the band they are in meets the new one: code that\n      // brings one message after another into view (a contrast check measuring each) finds them all still there, and a jump\n      // past them lets them go.\n      const keep = (code ? 8 : 2) * over;\n      let keepFrom = 0;\n      // Stryker disable next-line EqualityOperator: a child that ends exactly at the keep distance stays or goes, and the next scroll settles it.\n      while (starts[keepFrom]! + extent(keepFrom) <= viewTop - keep) keepFrom++;\n      let keepTo = keys.length - 1;\n      // Stryker disable next-line EqualityOperator: a child that starts exactly at the keep distance stays or goes, and the next scroll settles it.\n      while (starts[keepTo]! >= viewBottom + keep) keepTo--;\n      // Stryker disable next-line EqualityOperator,ArithmeticOperator: a band that meets the new one only within a child draws that child or not, and the next scroll settles it.\n      const meets = !code || (drawnFrom <= to + 1 && drawnTo >= from - 1);\n      if (meets && drawnFrom >= keepFrom) from = Math.min(from, drawnFrom);\n      if (meets && drawnTo <= keepTo) to = Math.max(to, drawnTo);\n      const inBand = keys.slice(from, to + 1);\n      // Stryker disable next-line StringLiteral: keys joined with no separator tell two bands apart too, but for keys that run into each other.\n      const id = inBand.join(\"\\n\");\n      // The same band again changes nothing.\n      setBand((now) => (now?.id === id ? now : { id, from: keys[from]!, to: keys[to]!, held: new Set(inBand) }));\n    };\n    const now = viewRef.current;\n    const last = synced.current;\n    synced.current = now;\n    // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator,MethodExpression,OptionalChaining,ArrowFunction: this only spares reading the layout on a render that changed nothing the window reads, as the app draws again while someone types.\n    if (last?.windowed === now.windowed && last.band === now.band && last.measured === now.measured && last.reach === now.reach && last.keys.length === now.keys.length && last.keys.every((key, index) => key === now.keys[index])) return;\n    windowSync.current(false);\n  });\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current!;\n    const content = contentRef.current!;\n    const state = reader.current;\n    const byReader = () => void (state.at = performance.now());\n    const press = () => ((state.held = true), byReader());\n    const release = () => void (state.held = false);\n    const onScroll = () => {\n      // Stryker disable next-line EqualityOperator: a scroll exactly at the gap is the reader's or code's alike.\n      if (performance.now() - state.at <= READER_GAP) state.going = true;\n      // The list's own move (following the end, keeping the reader's place) leaves the last scroll's say.\n      if (scroller.scrollTop !== ownTop.current) state.code = !state.going && !state.held;\n      ownTop.current = null;\n      // Stryker disable next-line BooleanLiteral: a scroll moves nothing the window measures, so measuring again on it only costs the time.\n      windowSync.current!(true);\n    };\n    // The reader's scroll is over: a scroll after this is code's, unless they act again.\n    const onScrollEnd = () => void (state.going = false);\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only lets the browser scroll without waiting for this listener.\n    scroller.addEventListener(\"scroll\", onScroll, { passive: true });\n    scroller.addEventListener(\"scrollend\", onScrollEnd);\n    const reading = [\"wheel\", \"touchstart\", \"touchmove\", \"keydown\"] as const;\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only lets the browser scroll without waiting for this listener.\n    for (const type of reading) scroller.addEventListener(type, byReader, { passive: true });\n    scroller.addEventListener(\"pointerdown\", press);\n    const doc = scroller.ownerDocument;\n    // Stryker disable next-line BooleanLiteral: captured, so a release an app stops on its way still lets go; bubbling, it lets go alike where none does.\n    doc.addEventListener(\"pointerup\", release, true);\n    // Stryker disable next-line BooleanLiteral: captured, so a release an app stops on its way still lets go; bubbling, it lets go alike where none does.\n    doc.addEventListener(\"pointercancel\", release, true);\n    const resized = new ResizeObserver(() => windowSync.current!(false));\n    resized.observe(scroller);\n    resized.observe(content);\n    // Stryker disable next-line all: once the list is gone, nothing reads what these would change; disconnecting frees memory only.\n    return () => (resized.disconnect(), scroller.removeEventListener(\"scroll\", onScroll), scroller.removeEventListener(\"scrollend\", onScrollEnd), reading.forEach((type) => scroller.removeEventListener(type, byReader)), scroller.removeEventListener(\"pointerdown\", press), doc.removeEventListener(\"pointerup\", release, true), doc.removeEventListener(\"pointercancel\", release, true), cancelAnimationFrame(widening.current?.frame ?? 0), clearTimeout(widening.current?.timer));\n  },\n  // Stryker disable next-line ArrayDeclaration: any list that never changes runs it once, as this one does.\n  []);\n\n  useImperativeHandle(\n    actionsRef,\n    () => ({\n      reveal(id, options) {\n        const { all: children, keys: order } = viewRef.current;\n        // An element with the id, drawn; else the child with it as its `id` prop, or as its key.\n        const inside = [...contentRef.current!.querySelectorAll(\"[id]\")].find((node) => node.id === id);\n        const named = childNamed(children, order, id);\n        const index = inside !== undefined ? order.indexOf(slotKeyOf(inside)) : named;\n        if (index < 0) return Promise.resolve(false);\n        // By key, the child itself; by id, the element with it.\n        const byKey = inside === undefined && !(isValidElement(children[index]) && (children[index].props as { id?: unknown }).id === id);\n        return new Promise<boolean>((resolve) => {\n          requestRef.current({ key: order[index]!, id: byKey ? null : id, child: byKey, forward: true, focus: options?.focus ?? false, block: options?.block ?? \"center\" });\n          revealed.current = resolve;\n        });\n      },\n      jumpToNewest: toNewest,\n    }),\n  );\n\n  // Announce each message from someone else once: when it is appended after the last\n  // message already seen, when it replaces one with different text (a regenerated reply), or,\n  // if it is streaming, when streaming ends, including a message that streams again.\n  // Messages are known by their element, which React replaces exactly when the key changes.\n  // Never announced: the messages present on mount, several messages filling an empty list\n  // at once (history fetched after mount; a single one is a first reply), anything inserted above\n  // the last seen message (older history), and a message whose key changed in place with the\n  // same text (a temporary id swapped for the server's), and anything that arrives while the\n  // list is inside a `hidden` element (a closed panel), where its live region is not heard either.\n  //\n  // Telling messages apart reads `textContent`, which needs no layout. Only a message read out\n  // reads `innerText`, for its line breaks, and only outside a `hidden` element: run from this\n  // observer, right after React's commit, `innerText` forces a layout before the browser's own,\n  // and inside a closed `hidden=\"until-found\"` panel a layout of the content the browser skips.\n  // (So does `checkVisibility()` in Chromium, so the check is the attribute.)\n  useEffect(() => {\n    const content = contentRef.current!;\n    const messages = () => [...content.querySelectorAll<HTMLElement>(items)];\n    const busy = (message: Element) => message.getAttribute(\"aria-busy\") === \"true\";\n    const textOf = (message: Element) => message.querySelector(\"[data-ouro-message-content]\")?.textContent.trim();\n    const spokenTextOf = (message: Element) => message.querySelector<HTMLElement>(\"[data-ouro-message-content]\")!.innerText.trim();\n    let known = messages();\n    // Each known message's text when last checked, to tell a key swap from a new reply.\n    let texts = new Map(known.map((message) => [message, textOf(message)]));\n    // Messages to read once they stop streaming.\n    let waiting = new Set(known.filter(busy));\n    // The children's keys when last checked: in a windowed list, a message drawn again as the reader scrolls is one of\n    // them, not a new one. The newest of them is the last heard, and what comes after it is drawn until it is.\n    let keysHeard = new Set(viewRef.current.keys);\n    // Stryker disable next-line LogicalOperator: the check the list's first drawing runs, before any message arrives, sets the same.\n    setHeard(viewRef.current.keys.at(-1) ?? null);\n    // A reply that streams out of view stays drawn until it is heard, though it stops streaming.\n    const publish = () => setWaitingKeys([...waiting].map(slotKeyOf).join(\"\\n\"));\n    const redrawn = (message: Element) => viewRef.current.windowed && keysHeard.has(slotKeyOf(message));\n    const check = () => {\n      const now = messages();\n      const before = new Set(known);\n      let last = now.length - 1;\n      while (last >= 0 && !before.has(now[last]!)) last--;\n      if (known.length > 0 && last >= 0) {\n        // Messages after the last one still here replace the ones that were there before, and\n        // the rest are new. A replacement is the same message under a new key, so silent, only\n        // when it keeps the text and is not streaming; one replacing a message still waiting\n        // takes its place in the queue. A message that goes keeps its text, so only those that replace one read any:\n        // older messages going in above, a chunk at a time, read nothing.\n        const replaced = known.slice(known.indexOf(now[last]!) + 1);\n        now.slice(last + 1).forEach((message, index) => {\n          const old = replaced[index];\n          if (redrawn(message)) return;\n          if (old === undefined || waiting.has(old) || texts.get(old) !== textOf(message)) waiting.add(message);\n        });\n      } else if (known.length === 0 && now.length === 1) {\n        // One message into an empty list is a first reply or greeting. Several at once are\n        // history fetched after mount.\n        waiting.add(now[0]!);\n      }\n      // Anything streaming is read when it ends: the first messages' streaming reply, and a\n      // known message that starts streaming again.\n      for (const message of now) if (busy(message)) waiting.add(message);\n      known = now;\n      texts = new Map(now.map((message) => [message, textOf(message)]));\n      keysHeard = new Set(viewRef.current.keys);\n      setHeard(viewRef.current.keys.at(-1) ?? null);\n      if (content.closest(\"[hidden]\")) {\n        waiting = new Set(now.filter(busy));\n        return;\n      }\n      const fresh: string[] = [];\n      const still = new Set<HTMLElement>();\n      for (const message of now) {\n        if (!waiting.has(message)) continue;\n        if (busy(message)) {\n          still.add(message);\n          continue;\n        }\n        if (message.getAttribute(\"data-role\") === \"user\") continue;\n        const author = message.querySelector<HTMLElement>(\"[data-ouro-message-author]\")!.innerText;\n        const text = spokenTextOf(message);\n        fresh.push(labelFor.current(author, text));\n      }\n      waiting = still;\n      publish();\n      if (fresh.length === 0) return;\n      setSpoken((previous) => [...previous, ...fresh.map((text) => ({ id: nextId.current++, text }))].slice(-KEEP_SPOKEN));\n    };\n    // Only messages coming and going, and streaming ending, matter; each streamed token\n    // changes text, which is skipped without a scan.\n    const matters = (record: MutationRecord) => record.type === \"attributes\" || touchesItems(record);\n    const observer = new MutationObserver((records) => {\n      if (records.some(matters)) check();\n    });\n    observer.observe(content, { childList: true, subtree: true, attributes: true, attributeFilter: [\"aria-busy\"] });\n    return () => observer.disconnect();\n  }, []);\n\n  // The keyboard: the messages are one Tab stop (a roving tabindex). The current message is in the\n  // Tab order and the rest are not; the arrow keys, Home, End, Page Up and Page Down move between them, and the right\n  // arrow (the left one, right to left) goes into the focused message's toolbar or first control.\n  // Tab goes on through the current message's controls and any between the messages, never the\n  // other messages' controls, then leaves the list; arriving by Tab lands on the first of those\n  // stops, and arriving by Shift+Tab on the current message. While focus is elsewhere, the current\n  // message is the one focus was last in while it is in view, else the newest wholly in view, so\n  // arriving does not scroll, and a new message never takes focus. When the focused message goes,\n  // focus goes to the message now in its place.\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current!;\n    const content = contentRef.current!;\n    const doc = scroller.ownerDocument;\n    let current: HTMLElement | null = null;\n    // The message focus was last in, and its place among the messages.\n    let last: HTMLElement | null = null;\n    // And its child's key, with the children's keys then: when it goes, focus goes to the child now in its place.\n    let lastKey: string | undefined;\n    let lastKeys: readonly string[] | undefined;\n    const remember = (item: HTMLElement) => {\n      lastKey = slotKeyOf(item);\n      lastKeys = viewRef.current.keys;\n    };\n    // The message focus is in, until focus leaves it, and whether it went with nothing in its place, waiting for the next messages.\n    let focused: HTMLElement | null = null;\n    // Stryker disable next-line BooleanLiteral: the first sync(true), as this effect mounts, runs with `switched` false and sets it false.\n    let waiting = false;\n    // A Tab press in progress anywhere in the page (true for Shift+Tab), and where the list was\n    // scrolled to before it: the browser scrolls to what it focuses before the list sends focus on.\n    let tabbing: boolean | null = null;\n    let tabTop = 0;\n    // The positions this list wrote, so an app's own aria-posinset stands.\n    const written = new WeakMap<Element, string>();\n    // The list's own messages, as `sync` last found them.\n    // Stryker disable next-line ArrayDeclaration: sync(true) finds them below, before any scroll can read them.\n    let tops: HTMLElement[] = [];\n\n    // The message an element is in, or is, among this list's messages.\n    const itemOf = (node: Element, list = topItems(content)): HTMLElement | null => list.find((item) => item.contains(node)) ?? null;\n    // Whether any of a message shows in the list's view.\n    const shows = (item: Element) => {\n      const box = boxOf(item);\n      const view = scroller.getBoundingClientRect();\n      // Stryker disable next-line EqualityOperator: a message whose edge meets the list's edge to the pixel counts either way.\n      return box.bottom > view.top && box.top < view.bottom;\n    };\n    const setCurrent = (item: HTMLElement | null) => {\n      // Stryker disable next-line ConditionalExpression: the same message would take -1 and then 0 again, as it was.\n      if (current !== item) current?.setAttribute(\"tabindex\", \"-1\");\n      current = item;\n      item?.setAttribute(\"tabindex\", \"0\");\n    };\n    // Scrolls the list, and only the list, until the element shows, with room for its focus ring:\n    // its top when it is taller than the list.\n    const reveal = (element: Element) => {\n      const box = boxOf(element);\n      const view = scroller.getBoundingClientRect();\n      // Stryker disable next-line EqualityOperator: at the margin to the pixel, the message is where scrolling would put it.\n      const atTop = box.top < view.top + EDGE || box.height > view.height - 2 * EDGE;\n      // Stryker disable next-line EqualityOperator: at the margin to the pixel, the message is where scrolling would put it.\n      const atBottom = box.bottom > view.bottom - EDGE;\n      scroller.scrollTop += atTop ? box.top - view.top - EDGE : atBottom ? box.bottom - view.bottom + EDGE : 0;\n    };\n    // The message takes the Tab stop as it takes focus, in focusIn.\n    const focusOn = (item: HTMLElement) => item.focus({ preventScroll: true });\n    const move = (item: HTMLElement) => {\n      focusOn(item);\n      reveal(item);\n    };\n    moveTo.current = focusOn;\n    // What Tab stops on in the list: all but the controls of the messages that are not current.\n    const stops = () => {\n      const list = topItems(content);\n      return tabbables(scroller).filter((element) => [null, current].includes(itemOf(element, list)));\n    };\n\n    // The Tab stop, while focus is out of the list: the message focus was last in while it shows, else the last message\n    // the view shows whole, else the last it shows any of. Laid out, the messages only go down the list, so the last that\n    // starts above the view's bottom is found by halving, and only the few in view are read: a scroll through a long\n    // conversation costs what one through a short one does.\n    const place = (list: HTMLElement[]) => {\n      if (current?.isConnected && scroller.contains(doc.activeElement)) return;\n      if (last?.isConnected && shows(last)) return setCurrent(last);\n      const view = scroller.getBoundingClientRect();\n      // Stryker disable next-line EqualityOperator: a message whose top meets the list's bottom to the pixel shows none of itself either way.\n      const after = halve(list, (box) => box.top < view.bottom);\n      let showing: HTMLElement | null = null;\n      for (let at = after - 1; at >= 0; at--) {\n        // A hidden message shows nothing, so it is never the Tab stop the view puts focus on.\n        if (!laidOut(list[at]!)) continue;\n        const box = boxOf(list[at]!);\n        // Above the view: so is every message before it.\n        // Stryker disable next-line EqualityOperator: a message whose edge meets the list's edge to the pixel counts either way.\n        if (box.bottom <= view.top) break;\n        showing ??= list[at]!;\n        // Stryker disable next-line EqualityOperator: a message whose edge meets the list's edge to the pixel counts either way.\n        if (box.top >= view.top && box.bottom <= view.bottom) return setCurrent(list[at]!);\n      }\n      setCurrent(showing ?? list.at(-1) ?? null);\n    };\n    // After React's commit, so it reads no layout unless the Tab stop went: reading where messages\n    // are here would lay the page out before the browser does, at every new message.\n    const sync = (changed: boolean) => {\n      // Out of the Tab order, for the list's Tab and the browser's alike (`guards`).\n      // Stryker disable next-line StringLiteral: an empty or any other negative tabindex takes a span out of the Tab order too.\n      for (const guard of content.querySelectorAll(guards)) mark(guard, \"tabindex\", \"-1\");\n      // A message removed with nothing in its place waited for the next messages, another conversation's: other messages\n      // coming instead let it go, so they never take focus from wherever the reader went since.\n      // Stryker disable next-line ArrayDeclaration: undefined and null are alike to every read of `focused`.\n      if (waiting && changed && !switched.current) [focused, waiting] = [null, false];\n      // In another conversation, focus goes to its Tab stop, below, without scrolling: no message is in the old one's place.\n      // Stryker disable next-line ConditionalExpression: a focus that went elsewhere is reported by a focus event, which clears `focused` before this runs, so a message that went with `focused` still set left focus on the body.\n      const onBody = doc.activeElement === doc.body;\n      const lost = focused?.isConnected === false && onBody;\n      const refocus = lost && switched.current;\n      if (lost && !refocus) {\n        if (viewRef.current.keys.length === 0) {\n          // With no message left, the focus waits for the next ones: another conversation's, say, after the list emptied.\n          waiting = true;\n        } else {\n          focused = null;\n          // The child now in its place (the first after it still there, else the newest), which may not be drawn: drawn, then\n          // focused. Children that come and go elsewhere, drawn or not, move none of it.\n          const { keys } = viewRef.current;\n          const present = new Set(keys);\n          const was = lastKeys!.indexOf(lastKey!);\n          const after = lastKeys!.slice(was + 1).find((later) => present.has(later));\n          const kept = new Set(lastKeys);\n          // A child that came where the focused one was (its temporary key swapped for the server's) takes focus, not the one after it.\n          const before = lastKeys!.slice(0, was).findLast((earlier) => present.has(earlier));\n          // Stryker disable next-line ConditionalExpression: with none before it, `indexOf(undefined)` is -1, which also gives the first.\n          const next = keys[before === undefined ? 0 : keys.indexOf(before) + 1];\n          const key = next !== undefined && !kept.has(next) ? next : (after ?? keys.at(-1));\n          // Stryker disable next-line StringLiteral: any block but \"center\" or \"start\" scrolls only as far as it needs.\n          requestRef.current({ key: key!, id: null, child: false, forward: true, focus: true, block: \"nearest\" });\n        }\n      }\n      // Stryker disable next-line ArrayDeclaration: an empty pattern leaves both undefined, which every read of them (`?.`, a truthiness test) treats as null and false.\n      if (refocus) [focused, waiting] = [null, false];\n      switched.current = false;\n      if (!changed) return;\n      const list = (tops = topItems(content));\n      // In a windowed list a message's place counts the children not drawn: one message each, until one is drawn and\n      // found to hold none (what starts the conversation) or more.\n      const { windowed, keys } = viewRef.current;\n      const before = new Map<string, number>();\n      let size = list.length;\n      if (windowed) {\n        size = 0;\n        for (const key of keys) {\n          before.set(key, size);\n          size += counts.current.get(key) ?? 1;\n        }\n      }\n      // How many messages of each child came before, in order.\n      const within = new Map<string, number>();\n      list.forEach((item, index) => {\n        // Focusable from code and by a click, in the Tab order only as the current message.\n        if (item !== current) mark(item, \"tabindex\", \"-1\");\n        mark(item, \"data-ouro-control\", \"message-list\");\n        mark(item, \"data-ouro-part\", \"item\");\n        const key = slotKeyOf(item);\n        const place = within.get(key) ?? 0;\n        within.set(key, place + 1);\n        const position = String(windowed ? before.get(key)! + place + 1 : index + 1);\n        // Only an article takes a position (ARIA allows it there), and one the app set stands.\n        const own = item.getAttribute(\"aria-posinset\");\n        if (!item.matches('article:not([role]), [role=\"article\"]') || (own !== null && own !== written.get(item))) return;\n        written.set(item, position);\n        mark(item, \"aria-posinset\", position);\n        mark(item, \"aria-setsize\", String(size));\n      });\n      // Stryker disable next-line ConditionalExpression: placing it again picks the same message, since a scroll places it too; this only spares reading the layout.\n      if (!current?.isConnected) place(list);\n      // A switch has its messages in (an empty commit is not one: \"does not switch on an empty commit\"), so there is a Tab stop.\n      if (refocus) focusOn(current!);\n      setHasItems(list.length > 0);\n    };\n\n    const focusIn = (event: FocusEvent) => {\n      const target = event.target as HTMLElement;\n      if (tabbing !== null && current !== null && !scroller.contains(event.relatedTarget as Node | null)) {\n        // None when the current message cannot take focus (the app hid it): then where the browser put it.\n        const all = stops();\n        const end = all.at(-1) ?? null;\n        const goal = (tabbing ? (current.contains(end) ? current : end) : all[0]) ?? target;\n        if (goal !== target) {\n          scroller.scrollTop = tabTop;\n          // Stryker disable next-line ObjectLiteral,BooleanLiteral: reveal, next, scrolls the list to the same place.\n          goal.focus({ preventScroll: true });\n          reveal(goal);\n          return;\n        }\n      }\n      // Only a message that goes moves focus: a control that goes from a message (a menu's button\n      // swapped for its trigger) is its component's to put focus back.\n      const item = itemOf(target);\n      focused = item;\n      // Whatever child focus is in (a message, a button that loads older ones) stays drawn as the reader scrolls away.\n      const slot = target.closest(`[${SLOT}]`);\n      if (slot !== null) setFocusKey(slot.getAttribute(SLOT));\n      if (item === null) return;\n      setCurrent(item);\n      last = item;\n      remember(item);\n    };\n    // Focus that lands anywhere outside the list lets go of a message that went: the reader has moved on.\n    const elsewhere = (event: FocusEvent) => {\n      // Stryker disable next-line ArrayDeclaration: an empty pattern leaves both undefined, which every read of them treats as null and false.\n      if (!scroller.contains(event.target as Node)) [focused, waiting] = [null, false];\n    };\n    const focusOut = (event: FocusEvent) => {\n      if (scroller.contains(event.relatedTarget as Node | null)) return;\n      // Focus left. When it left because what had it was removed, `sync` has already moved it, as\n      // the mutation observer runs before this timer.\n      // A message that was removed keeps its place, for the next messages to take focus (another conversation's, after the list\n      // emptied); Chromium reports its removal as focus leaving.\n      const left = focused;\n      setTimeout(() => {\n        if (focused === left && left?.isConnected) focused = null;\n      });\n    };\n\n    const tab = (event: globalThis.KeyboardEvent) => {\n      const from = event.target as HTMLElement;\n      const back = event.shiftKey;\n      const ahead = (element: Element) => (from.compareDocumentPosition(element) & (back ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING)) !== 0;\n      const pick = (list: HTMLElement[]) => (back ? list.findLast(ahead) : list.find(ahead));\n      const next = pick(stops());\n      if (next === undefined) {\n        // Past the last stop: from the list's edge, the browser's own Tab goes on beyond the list.\n        // Stryker disable next-line ObjectLiteral,BooleanLiteral: the edges sit outside the scrolling content, so focusing one scrolls nothing.\n        (back ? startRef : endRef).current!.focus({ preventScroll: true });\n        return;\n      }\n      // The list moves focus itself, so each browser's own Tab order (WebKit's on a Mac, which can skip\n      // buttons; a popup's focus guards) never decides it. A radio is the browser's: Tab enters its group\n      // at the checked one.\n      // Stryker disable next-line ConditionalExpression,EqualityOperator,LogicalOperator: in Chromium the browser's Tab goes where the list's would; only WebKit's own Tab order differs.\n      if (next === pick(tabbables(scroller)) && next.matches('input[type=\"radio\"]')) return;\n      event.preventDefault();\n      // Stryker disable next-line ObjectLiteral,BooleanLiteral: reveal, next, scrolls the list to the same place.\n      next.focus({ preventScroll: true });\n      reveal(next);\n    };\n    // From React's onKeyDown, so it runs after the handlers of the controls inside, and sees what they took.\n    keyHandler.current = (reactEvent: KeyboardEvent<HTMLElement>) => {\n      const event = reactEvent.nativeEvent;\n      if (event.defaultPrevented || !scroller.contains(event.target as Node)) return;\n      if (event.key === \"Tab\") return tab(event);\n      const item = event.target as HTMLElement;\n      // A key in a control inside a message is the control's.\n      if (itemOf(item) !== item) return;\n      keyFor.current?.(item, reactEvent);\n      // ⌘↑, ⌘↓, ⌥↑ and ⌥↓ on a Mac are its Home, End, Page Up and Page Down.\n      const key = navigationKey(event);\n      if (event.defaultPrevented) return;\n      // Home and the arrow keys find the message among all the children, which a windowed list may not draw: drawn\n      // first, it then takes focus.\n      const { keys } = viewRef.current;\n      const slot = item.closest(`[${SLOT}]`)!;\n      const reachFor = (index: number, forward: boolean) => {\n        event.preventDefault();\n        // Stryker disable next-line StringLiteral: any block but \"center\" or \"start\" scrolls only as far as it needs.\n        requestRef.current({ key: keys[index]!, id: null, child: false, forward, focus: true, block: \"nearest\" });\n      };\n      const list = topItems(content);\n      const at = list.indexOf(item);\n      const box = boxOf(item);\n      const view = scroller.getBoundingClientRect();\n      let goal: HTMLElement | undefined;\n      switch (key) {\n        case getComputedStyle(item).direction === \"rtl\" ? \"ArrowLeft\" : \"ArrowRight\": {\n          const inside = tabbables(item);\n          goal = inside.find((element) => element.closest('[role=\"toolbar\"]') !== null) ?? inside[0];\n          if (goal === undefined) return;\n          // Stryker disable next-line all: the messages wrap, so the list has nothing to scroll sideways that the arrow could move.\n          event.preventDefault();\n          goal.focus();\n          return;\n        }\n        case \"Home\":\n          // The first message, which a windowed list may not draw.\n          return reachFor(0, true);\n        case \"End\":\n          // The newest, which every list draws.\n          goal = list.at(-1);\n          break;\n        case \"ArrowDown\":\n        case \"PageDown\":\n        case \"ArrowUp\":\n        case \"PageUp\": {\n          const forward = key.endsWith(\"Down\");\n          const paging = key.startsWith(\"Page\");\n          // The app's, with pageKeys={false}: not acted on, nor prevented.\n          if (paging && !pagesFor.current) return;\n          // A message taller than the list scrolls through first, a line or a page at a time.\n          const beyond = forward ? box.bottom - view.bottom + EDGE : view.top + EDGE - box.top;\n          // The scroll position is whole device pixels, so holding the place can put a message one device pixel past the edge, on top of the fraction it already sits at (under a pixel): that is a rounding, not more message.\n          // Stryker disable next-line EqualityOperator,ArithmeticOperator: a pixel more or less of tolerance is not told apart by any scroll the tests make.\n          if (beyond > 1 + 1 / devicePixelRatio) {\n            event.preventDefault();\n            scroller.scrollTop += (forward ? 1 : -1) * Math.min(beyond, paging ? view.height - LINE : LINE);\n            return;\n          }\n          const step = forward ? 1 : -1;\n          // The next message in the same child, else in the next child: drawn beside it, focus moves there at once, as the\n          // springs follow; else (a windowed list has not drawn it, or it holds none) the list draws and finds it.\n          if (!paging) {\n            const own = topItems(slot);\n            const sibling = forward ? slot.nextElementSibling : slot.previousElementSibling;\n            const beside = sibling === null ? [] : topItems(sibling);\n            goal = own[own.indexOf(item) + step] ?? (forward ? beside[0] : beside.at(-1));\n            if (goal === undefined) return reachFor(keys.indexOf(slot.getAttribute(SLOT)!) + step, forward);\n            break;\n          }\n          // A page away: the farthest message that starts within a list's height of this one, else the next.\n          const near = list.filter(\n            // Stryker disable next-line EqualityOperator: a message that starts exactly a list's height away counts either way.\n            (other, index) => (forward ? index > at : index < at) && Math.abs(boxOf(other).top - box.top) <= view.height,\n          );\n          goal = near.at(forward ? -1 : 0) ?? list[at + step];\n          break;\n        }\n        default:\n          return;\n      }\n      event.preventDefault();\n      if (goal !== undefined) move(goal);\n    };\n    const tabKey = (event: globalThis.KeyboardEvent) => {\n      if (event.key !== \"Tab\") return;\n      tabbing = event.shiftKey;\n      tabTop = scroller.scrollTop;\n      setTimeout(() => (tabbing = null));\n    };\n    // The messages, found again only when messages come or go (`sync`), not on every scroll.\n    const scrolled = () => place(tops);\n\n    sync(true);\n    const observer = new MutationObserver((records) => {\n      // Stryker disable next-line ConditionalExpression,MethodExpression,BooleanLiteral: after only the bar moved, syncing finds and marks the same messages again; skipping it only spares the work.\n      if (!records.every(barOnly)) sync(records.some(touchesItems));\n    });\n    observer.observe(content, { childList: true, subtree: true });\n    scroller.addEventListener(\"focusin\", focusIn);\n    scroller.addEventListener(\"focusout\", focusOut);\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: passive only lets the browser scroll without waiting for this listener.\n    scroller.addEventListener(\"scroll\", scrolled, { passive: true });\n    doc.addEventListener(\"keydown\", tabKey, true);\n    doc.addEventListener(\"focusin\", elsewhere);\n    // Stryker disable next-line all: once the list is gone, nothing reads what these listeners would change; removing them frees memory only.\n    return () => (observer.disconnect(), scroller.removeEventListener(\"focusin\", focusIn), scroller.removeEventListener(\"focusout\", focusOut), scroller.removeEventListener(\"scroll\", scrolled), doc.removeEventListener(\"keydown\", tabKey, true), doc.removeEventListener(\"focusin\", elsewhere));\n  },\n  // Stryker disable next-line ArrayDeclaration: any list that never changes runs it once, as this one does.\n  []);\n\n  // A list that gains its first message stops being a Tab stop itself; one with focus hands it to the message.\n  useLayoutEffect(() => {\n    const scroller = scrollerRef.current!;\n    if (!hasItems) return;\n    scroller.removeAttribute(\"tabindex\");\n    if (scroller.ownerDocument.activeElement === scroller) moveTo.current!(topItems(contentRef.current!).at(-1)!);\n  }, [hasItems]);\n\n  const jump = () => {\n    toNewest();\n    // The button goes, so focus goes to the newest message (or to the list, without messages), not to <body>.\n    const newest = topItems(contentRef.current!).at(-1);\n    if (newest) return moveTo.current!(newest);\n    // Stryker disable next-line ObjectLiteral,BooleanLiteral: the list is at the bottom already, so focusing it scrolls nothing.\n    scrollerRef.current!.focus({ preventScroll: true });\n  };\n\n  return (\n    <div {...rest} data-ouro=\"message-list\" className={cn(\"relative box-border flex min-h-0 flex-col\", className)}>\n      {/* Holds the scroller and its focus ring, drawn over it, so content that sticks to an edge never covers the ring. */}\n      <div className=\"relative flex min-h-0 flex-1 flex-col\">\n        {/* No browser scroll anchoring; the layout effect above keeps the reader's place instead. Positioned, so\n            parts placed absolutely inside it (screen-reader text, the list's edges) stay in its overflow, not its\n            ancestors': there they would let focus or scrollIntoView scroll the page around the list. */}\n        <div\n          ref={setScroller}\n          role=\"region\"\n          aria-label={label}\n          data-ouro-message-list-scroller=\"\"\n          data-ouro-control=\"message-list\"\n          data-ouro-part=\"scroller\"\n          onKeyDown={(event) => keyHandler.current!(event)}\n          // While focused, isolate keeps the content's own stacking (a sticky header's z-index) inside the scroller, under the ring.\n          className=\"peer relative min-h-0 flex-1 overflow-y-auto overscroll-contain [overflow-anchor:none] outline-none focus-visible:isolate forced-colors:[&[tabindex='0']]:outline-1 forced-colors:[&[tabindex='0']]:outline-solid forced-colors:[&[tabindex='0']]:-outline-offset-1\"\n        >\n          <span ref={startRef} tabIndex={-1} aria-hidden=\"true\" data-ouro-message-list-edge=\"\" className=\"absolute outline-none\" />\n          <div\n            ref={contentRef}\n            data-ouro-message-list-content=\"\"\n            className=\"box-border flex min-h-full flex-col justify-end gap-4 p-4 [&>[data-ouro-message-list-slot]>[data-continued]]:-mt-3\"\n            style={maxWidth === undefined ? undefined : { maxWidth, marginInline: \"auto\" }}\n          >\n            {/* With the content's own padding, keeps the first message below \"Loading older messages\", which sits over the list's top. */}\n            {room && <div ref={roomRef} aria-hidden=\"true\" data-ouro-message-list-older-room=\"\" className=\"-mb-4 h-11 shrink-0\" />}\n            <RowLayerContext.Provider value={layer as RowLayer<unknown>}>{slots}</RowLayerContext.Provider>\n          </div>\n          <span ref={endRef} tabIndex={-1} aria-hidden=\"true\" data-ouro-message-list-edge=\"\" className=\"absolute outline-none\" />\n          {/* The one bar and menu: portals, so nothing of theirs is here in the page; inside the scroller in React, so a key\n              in the bar (Tab, the arrows) reaches the list's keyboard handling as a key in its message would. */}\n          {Layer && <Layer scroller={scrollerRef} layer={layer} />}\n          <span ref={floorRef} aria-hidden=\"true\" data-ouro-message-list-floor=\"\" className=\"pointer-events-none absolute start-0 top-0 hidden size-px\" />\n        </div>\n        {/* There only while the scroller has focus: at rest nothing lies over the content, so a contrast check sees the text's own background. */}\n        <span\n          aria-hidden=\"true\"\n          data-ouro-message-list-focus-ring=\"\"\n          className=\"pointer-events-none absolute inset-0 hidden rounded-[inherit] outline-ring -outline-offset-2 peer-focus-visible:block peer-focus-visible:outline-2 peer-focus-visible:outline-solid\"\n        />\n      </div>\n      {/* Read politely, outside the scrolling content, so new messages are heard once. */}\n      <div data-ouro-message-list-live=\"\" aria-live=\"polite\" className=\"sr-only\">\n        {spoken.map((item) => (\n          <p key={item.id}>{item.text}</p>\n        ))}\n      </div>\n      {/* Over the list, never in it, so it moves no message. Always in the page, so screen readers hear it as it shows; a live region without the status role, so an app's own status stays the page's only one. Marked, so an app can set it lower, below a header of its own over the list. */}\n      <div data-ouro-message-list-older=\"\" className=\"pointer-events-none absolute inset-x-0 top-3 flex justify-center\">\n        <div aria-live=\"polite\">\n          {loadingOlder && (\n            <span className={olderClass}>\n              <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" fill=\"none\" className=\"size-4 animate-[ouro-spin_0.8s_linear_infinite] motion-reduce:animate-[ouro-pulse_1.6s_ease-in-out_infinite]\">\n                <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeWidth=\"2.5\" opacity=\"0.25\" />\n                <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n              </svg>\n              {loadingOlderLabel}\n            </span>\n          )}\n        </div>\n      </div>\n      {showJump && (\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-3 flex justify-center\">\n          <button type=\"button\" data-ouro-message-list-jump=\"\" data-ouro-control=\"message-list\" data-ouro-part=\"jump\" onClick={jump} className={jumpClass}>\n            <TouchTarget />\n            {jumpLabel}\n            <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\">\n              <path d=\"M8 3v10M4 9l4 4 4-4\" />\n            </svg>\n          </button>\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/message/message-list.tsx"
    }
  ],
  "docs": "A conversation: `Message`s in a scrolling, labeled region that opens at the newest one. Import: import { MessageList } from \"@/components/ouro/message/message-list\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: avatar, button, kbd, menu, message, skeleton, tooltip, 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/message-list.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}