{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "show-more",
  "title": "ShowMore",
  "description": "\"Show more\" for a long list or a long text.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/collapsible",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-server-element",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/collapsible/show-more.tsx",
      "content": "\"use client\";\n\nimport { flushSync } from \"react-dom\";\nimport { isValidElement, useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type FocusEvent, type JSX, type MouseEvent, type ReactNode, type Ref } from \"react\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { serverElement } from \"@/registry/ouro/lib/ouro/server-element\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport {\n  foldClass,\n  itemClass,\n  listClass,\n  showMoreHint,\n  showMoreRootClass,\n  textClass,\n} from \"@/registry/ouro/components/ouro/collapsible/collapsible-styles\";\n\n/**\n * Props every ShowMore takes.\n *\n * @claim \"Props every ShowMore takes\" registry/ouro/components/ouro/collapsible/show-more.tsx verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.tsx, /export\\sinterface\\sShowMoreListProps\\sextends\\sShowMoreBaseProps/)\n * @claim \"Props every ShowMore takes\" registry/ouro/components/ouro/collapsible/show-more.tsx verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.tsx, /export\\stype\\sShowMoreLinesProps\\s=\\sShowMoreBaseProps\\s&/)\n */\nexport interface ShowMoreBaseProps {\n  /** The button's text while there is more to show. Translate it here. @default \"Show more\" */\n  showMoreLabel?: string | undefined;\n  /** Layout only: margins, width, grid placement (`mt-6`). Text classes go on a parent so the items inherit them. */\n  className?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n  /**\n   * A stable name for what this shows (a message id), for `lines` and `maxHeight`. A row that mounts again with the\n   * same key starts from its last measured fit, so it does not mount folded and then unfold. Without it, a mount measures afresh. The browser still measures and corrects it, so a changed width costs one write.\n   */\n  measureKey?: string | number | undefined;\n\n  /** Not a prop. Ouro UI uses `lines`: `<ShowMore lines={3}>`. */\n  maxLines?: { 'Use <ShowMore lines={3}>': never };\n  /** Not a prop. Ouro UI uses `initialCount`: `<ShowMore items={items} initialCount={5}>`. */\n  limit?: { 'Use <ShowMore items={items} initialCount={5}>': never };\n}\n\n/**\n * Whether the content shows in full, for a ShowMore that can show less again (text, height and a cut\n * list), when the app sets it: to reveal a match from find in page, or a linked anchor below the fold.\n */\nexport interface ShowMoreOpenProps {\n  /**\n   * Whether the content shows in full. With it, the app owns the state: \"Show more\" and \"Show less\"\n   * ask for the change through `onOpenChange`, and nothing changes until the app sets `open`.\n   * Without it, ShowMore keeps its own state, starting folded.\n   * @claim \"With it, the app owns the state\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore open > follows open in each mode, and its buttons ask onOpenChange without changing it)\n   */\n  open?: boolean | undefined;\n  /**\n   * Called with the new state when the button is pressed, or when keyboard focus moving below\n   * a `maxHeight` fold unfolds it, whether or not `open` is set.\n   * @claim \"Called with the new state when the button is pressed\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore open > follows open in each mode, and its buttons ask onOpenChange without changing it)\n   * @claim \"whether or not `open` is set\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore open > tells onOpenChange each change of its own state when open is not set)\n   */\n  onOpenChange?: ((open: boolean) => void) | undefined;\n}\n\n/**\n * What folded content holds. Not read: ShowMore decides from the browser's layout, and this leaves the first frame as\n * it is. Kept so an app that passes it still compiles.\n * @deprecated\n */\nexport interface ShowMoreEstimate {\n  /** Its plain text. Not read. */\n  text?: string | undefined;\n  /** The CSS pixels its pictures and cards take. Not read. */\n  height?: number | undefined;\n}\n\n/** Long text clamped to `lines` lines, with \"Show more\" and \"Show less\". */\nexport type ShowMoreLinesProps = ShowMoreBaseProps & ShowMoreOpenProps & {\n  /** How many lines show while collapsed. The button appears only when the text is longer. */\n  lines: number;\n  /**\n   * The text. Screen readers always read all of it.\n   *\n   * @claim \"Screen readers always read all of\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with lines > keeps the full text for screen readers and in server HTML)\n   */\n  children: ReactNode;\n  /**\n   * The button's text while everything shows. Translate it here. @default \"Show less\"\n   *\n   * @claim \"The button's text while everything shows\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items > takes translated labels)\n   */\n  showLessLabel?: string | undefined;\n  /**\n   * Not read: ShowMore does not guess whether content is longer than its fold, so this changes nothing. Kept so an app\n   * that passes it still compiles.\n   *\n   * @deprecated\n   */\n  estimate?: ShowMoreEstimate | undefined;\n  /** Not with `lines`: fold by height or by lines, not both. */\n  maxHeight?: never;\n  /** List modes only: not with `lines`. */\n  items?: never;\n  /**\n   * Only with `items` and no `onShowMore`.\n   *\n   * @claim \"Only with `items` and no `onShowMore`\" registry/ouro/components/ouro/collapsible/show-more.test-d.ts verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.test-d.ts, /initialCount:\\s3;\\sonShowMore:\\s\\(\\)\\s=>\\svoid;\\shasMore:\\strue\\s\\}>\\(\\)\\.not\\.toExtend/)\n   */\n  initialCount?: never;\n  /** List modes only: not with `lines`. */\n  ordered?: never;\n  /** Only for a list that loads more: with `items`, without `initialCount` or `lines`. */\n  onShowMore?: never;\n  /** Only with `onShowMore`. */\n  hasMore?: never;\n  /** Only with `onShowMore`. */\n  loading?: never;\n  /** Only with `onShowMore`. */\n  loadingLabel?: never;\n  /** Only with `onShowMore`. */\n  loadedLabel?: never;\n  /** Only with `onShowMore`. */\n  noMoreLabel?: never;\n  /** Only with `onShowMore`. */\n  href?: never;\n};\n\n/** Long content of any kind folded to `maxHeight` pixels under a fade, with \"Show more\" and \"Show less\". */\nexport type ShowMoreHeightProps = ShowMoreBaseProps & ShowMoreOpenProps & {\n  /**\n   * How tall the content shows while folded, in CSS pixels, with its last part fading out.\n   * Content at most a fifth taller shows whole, since a button that reveals a line or two\n   * helps nobody. The button appears only when the content is folded.\n   *\n   * @claim \"Content at most a fifth taller\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with maxHeight > shows content a little taller than maxHeight whole, with no button)\n   */\n  maxHeight: number;\n  /**\n   * The content: rich text, pictures, cards. Screen readers always read all of it, and\n   * moving keyboard focus into the folded part unfolds it, so nothing focusable is out of sight.\n   *\n   * @claim \"moving keyboard focus into the folded\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with maxHeight > unfolds when keyboard focus moves into the folded part)\n   */\n  children: ReactNode;\n  /**\n   * The button's text while everything shows. Translate it here. @default \"Show less\"\n   *\n   * @claim \"The button's text while everything shows\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with maxHeight > unfolds when keyboard focus moves into the folded part)\n   */\n  showLessLabel?: string | undefined;\n  /**\n   * Not read: ShowMore does not guess whether content is longer than its fold, so this changes nothing. Kept so an app\n   * that passes it still compiles.\n   *\n   * @deprecated\n   */\n  estimate?: ShowMoreEstimate | undefined;\n  /** Not with `maxHeight`: fold by height or by lines, not both. */\n  lines?: never;\n  /** List modes only: not with `maxHeight`. */\n  items?: never;\n  /**\n   * Only with `items` and no `onShowMore`.\n   *\n   * @claim \"Only with `items` and no `onShowMore`\" registry/ouro/components/ouro/collapsible/show-more.test-d.ts verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.test-d.ts, /initialCount:\\s3;\\sonShowMore:\\s\\(\\)\\s=>\\svoid;\\shasMore:\\strue\\s\\}>\\(\\)\\.not\\.toExtend/)\n   */\n  initialCount?: never;\n  /** List modes only: not with `maxHeight`. */\n  ordered?: never;\n  /** Only for a list that loads more: with `items`, without `initialCount` or `lines`. */\n  onShowMore?: never;\n  /** Only with `onShowMore`. */\n  hasMore?: never;\n  /** Only with `onShowMore`. */\n  loading?: never;\n  /** Only with `onShowMore`. */\n  loadingLabel?: never;\n  /** Only with `onShowMore`. */\n  loadedLabel?: never;\n  /** Only with `onShowMore`. */\n  noMoreLabel?: never;\n  /** Only with `onShowMore`. */\n  href?: never;\n};\n\n/** Props both list modes take. */\nexport interface ShowMoreListProps extends ShowMoreBaseProps {\n  /**\n   * Every item, in order. Each renders in its own list item; give elements a `key`. With\n   * `onShowMore`, append each new page here.\n   * @claim \"Every item, in order\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items > shows initialCount items and an ordered list with ordered)\n   * @claim \"Each renders in its own list\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items > shows initialCount items and an ordered list with ordered)\n   * @claim \"With `onShowMore`, append each new page\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items a Server Component passed > knows an appended page from a replaced list, and focuses the first new item)\n   */\n  items: readonly ReactNode[];\n  /** Renders an `<ol>`, for a ranked or numbered list. @default false (`<ul>`) */\n  ordered?: boolean | undefined;\n  /** Text mode only: not with `items`. */\n  /** Text and height modes only: a list shows its first items. */\n  estimate?: never;\n  lines?: never;\n  /** Height mode only: not with `items`. */\n  maxHeight?: never;\n  /** Text mode only: a list takes `items`. */\n  children?: never;\n}\n\n/** A list cut to its first `initialCount` items, with \"Show more\" and \"Show less\". */\nexport type ShowMoreItemsProps = ShowMoreListProps & ShowMoreOpenProps & {\n  /** How many items show while collapsed. @default 5 */\n  initialCount?: number | undefined;\n  /**\n   * The button's text while everything shows. Translate it here. @default \"Show less\"\n   *\n   * @claim \"The button's text while everything shows\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items > takes translated labels)\n   */\n  showLessLabel?: string | undefined;\n  /** Only for a list that loads more: with `items`, without `initialCount` or `lines`. */\n  onShowMore?: never;\n  /** Only with `onShowMore`. */\n  hasMore?: never;\n  /** Only with `onShowMore`. */\n  loading?: never;\n  /** Only with `onShowMore`. */\n  loadingLabel?: never;\n  /** Only with `onShowMore`. */\n  loadedLabel?: never;\n  /** Only with `onShowMore`. */\n  noMoreLabel?: never;\n  /** Only with `onShowMore`. */\n  href?: never;\n};\n\n/** A list the server grows a page at a time: \"Show more\" asks for the next page and appends it. */\nexport type ShowMoreLoadProps = ShowMoreListProps & {\n  /** Asks for the next page. The button is busy while `loading`, and focus moves to the first new item when it arrives. */\n  onShowMore: () => void;\n  /** Whether there is another page. Without one, the button goes away. */\n  hasMore: boolean;\n  /** Shows the button as busy, and keeps it from asking twice. */\n  loading?: boolean | undefined;\n  /** What screen readers hear when loading starts. Translate it here. @default \"Loading\" */\n  loadingLabel?: string | undefined;\n  /**\n   * What screen readers hear after each page, from the number of items now shown. Name the\n   * items and translate it here: `` (count) => `Showing ${count} recipes` ``.\n   * @default (count) => `Showing ${count} items`\n   * @claim \"What screen readers hear after each\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore announcements > says how many items show after each page, through a polite status region)\n   */\n  loadedLabel?: ((count: number) => string) | undefined;\n  /**\n   * What screen readers hear when a page comes back empty and there is no more. Translate it here. @default \"No more items\"\n   *\n   * @claim \"What screen readers hear when a\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore announcements > says there are no more items when a later page comes back empty, in the words of noMoreLabel)\n   */\n  noMoreLabel?: string | undefined;\n  /**\n   * The next page's URL, so the button is a link that works before JavaScript loads. With\n   * JavaScript, pressing it calls `onShowMore` instead.\n   */\n  href?: string | undefined;\n  /**\n   * Only with `items` and no `onShowMore`.\n   *\n   * @claim \"Only with `items` and no `onShowMore`\" registry/ouro/components/ouro/collapsible/show-more.test-d.ts verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.test-d.ts, /initialCount:\\s3;\\sonShowMore:\\s\\(\\)\\s=>\\svoid;\\shasMore:\\strue\\s\\}>\\(\\)\\.not\\.toExtend/)\n   */\n  initialCount?: never;\n  /** Not for a list that loads more, which only grows. */\n  open?: never;\n  /** Not for a list that loads more, which only grows. */\n  onOpenChange?: never;\n  /**\n   * A list that loads more never shrinks, so it has no \"Show less\".\n   *\n   * @claim \"A list that loads more never\" registry/ouro/components/ouro/collapsible/show-more.test-d.ts verify:fileLine(registry/ouro/components/ouro/collapsible/show-more.test-d.ts, /showLessLabel:\\s\"Less\"\\s\\}>\\(\\)\\.not\\.toExtend/)\n   */\n  showLessLabel?: never;\n};\n\n/**\n * Props for {@link ShowMore}: clamp text with `lines`, fold any content with `maxHeight`, cut a\n * list with `items`, or grow it from the server with `onShowMore`.\n */\nexport type ShowMoreProps = ShowMoreLinesProps | ShowMoreHeightProps | ShowMoreItemsProps | ShowMoreLoadProps;\n\nconst DEFAULT_COUNT = 5;\nconst DEFAULT_LINES = 3;\n\nconst FOCUSABLE =\n  'a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** Focuses the first focusable thing in a row, or the row itself. */\nfunction focusRow(row: Element): void {\n  (row.querySelector<HTMLElement>(FOCUSABLE) ?? (row as HTMLElement)).focus();\n}\n\n/** The first item of a list that was empty when \"Show more\" was pressed: any first page is new items. */\nconst EMPTY = Symbol(\"empty\");\n\n/**\n * What stays the same for an item across renders: an element's key, or a text or number item\n * itself. An element without a key is a new object every render, so it has none (null).\n * @claim \"An element without a key is\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items a Server Component passed > keys each row by its item's own key, so a row keeps its node when the order changes)\n */\nfunction identity(item: ReactNode): unknown {\n  // An item a Server Component passed can be a lazy wrapper, a new object on every payload.\n  const element = serverElement(item);\n  if (isValidElement(element)) return element.key;\n  return element;\n}\n\n/** The row's key: the item's own key, or its place in the list. */\nfunction rowKey(item: ReactNode, index: number): string | number {\n  const element = serverElement(item);\n  return isValidElement(element) && element.key !== null ? element.key : index;\n}\n\n/**\n * Whether the content shows in full: `open` when the app sets it, else ShowMore's own state, and\n * a setter that tells `onOpenChange` and keeps the asked-for state, which shows once `open` is unset.\n */\nfunction useOpen(open: boolean | undefined, onOpenChange: ((open: boolean) => void) | undefined): [boolean, (next: boolean) => void] {\n  const [own, setOwn] = useState(false);\n  const set = (next: boolean) => {\n    setOwn(next);\n    onOpenChange?.(next);\n  };\n  return [open ?? own, set];\n}\n\nconst isCount = (value: unknown): value is number => typeof value === \"number\" && Number.isInteger(value) && value > 0;\nconst isHeight = (value: unknown): value is number => Number.isFinite(value) && (value as number) > 0;\nconst DEFAULT_HEIGHT = 240;\n\n/**\n * \"Show more\" for a long list or a long text. It cuts a list to its first items, clamps text\n * to a number of lines, folds content of any kind (a long post with pictures) to a height\n * under a fade, or grows a list a page at a time from the server, and moves focus to\n * the first newly shown item, so keyboard and screen reader users land on what they asked\n * for. A list that loads more also says how many items now show. The button names what it\n * folds (`aria-controls`) and, unless it loads more, says whether it is open (`aria-expanded`).\n * Folded text and content are folded by CSS in the first commit and in server HTML, and the button comes after the\n * browser has laid them out: ShowMore does not guess whether they are longer than the fold. One ResizeObserver reads the\n * layout and adds the button to what overflows.\n * The visible items are in the server HTML. ShowMore draws the list itself: put a border\n * around the list on a wrapping element, and borders between rows on each item.\n *\n * Use `Collapsible` instead to hide a whole section behind its title. Use `Pagination`\n * instead when people need to jump to a page or share its URL.\n *\n * @group Lists\n * @see https://ui.ouroboros.bot/docs/show-more\n *\n * @example\n * <ShowMore items={reviews.map((review) => <Review key={review.id} {...review} />)} initialCount={3} />\n * <ShowMore lines={3}>{recipe.description}</ShowMore>\n * <ShowMore maxHeight={180}><Post body={post.body} /></ShowMore>\n * <ShowMore items={rows} hasMore={Boolean(nextCursor)} loading={loading} onShowMore={loadNext} href={nextHref} />\n * <ShowMore lines={3} open={open} onOpenChange={setOpen}>{recipe.description}</ShowMore>\n * @claim \"The button names what it folds\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore toggle semantics > names the list, the text or the fold it opens and says whether it is open, in every mode that folds)\n * @claim \"The button names what it folds\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore toggle semantics > names the list a load adds to, and claims no open state, since loading more never folds)\n * @claim \"folds content of any kind\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with maxHeight > folds long content to maxHeight under a fade, with Show more)\n * @claim \"ShowMore draws the list itself: put\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore with items > lets app layout classes win and keys rows by their own keys)\n */\nexport function ShowMore(props: ShowMoreProps): JSX.Element {\n  const { showMoreLabel = \"Show more\", className, ref, maxLines, limit } = props;\n  const { lines, initialCount, items, maxHeight } = props;\n  useAppearanceClassNameCheck(\n    \"ShowMore\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? showMoreHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ShowMore\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          maxLines !== undefined && [\"maxLines is not a prop\", `<ShowMore lines={${String(maxLines)}}>`],\n          limit !== undefined && [\"limit is not a prop\", `<ShowMore items={items} initialCount={${String(limit)}}>`],\n          initialCount !== undefined &&\n            !isCount(initialCount) && [\n              `initialCount={${String(initialCount)}} is not a whole number above 0`,\n              `<ShowMore items={items} initialCount={${DEFAULT_COUNT}}>`,\n            ],\n          lines !== undefined &&\n            !isCount(lines) && [`lines={${String(lines)}} is not a whole number above 0`, `<ShowMore lines={${DEFAULT_LINES}}>`],\n          maxHeight !== undefined &&\n            !isHeight(maxHeight) && [`maxHeight={${String(maxHeight)}} is not a number of pixels above 0`, `<ShowMore maxHeight={${DEFAULT_HEIGHT}}>`],\n          (props as ShowMoreOpenProps).open !== undefined &&\n            (props as ShowMoreOpenProps).onOpenChange === undefined && [\"open without onOpenChange: its button can't change it\", \"<ShowMore open={open} onOpenChange={setOpen}>\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  if (items === undefined && maxHeight !== undefined) {\n    const { children, showLessLabel = \"Show less\", open, onOpenChange } = props as ShowMoreHeightProps;\n    const { measureKey } = props;\n    return (\n      <ShowMoreHeight\n        open={open}\n        onOpenChange={onOpenChange}\n        maxHeight={isHeight(maxHeight) ? maxHeight : DEFAULT_HEIGHT}\n        showMoreLabel={showMoreLabel}\n        showLessLabel={showLessLabel}\n        className={className}\n        rootRef={ref}\n        measureKey={measureKey}\n      >\n        {children}\n      </ShowMoreHeight>\n    );\n  }\n  if (items === undefined) {\n    // Text mode. A guessed maxLines (a type error) still clamps, as lines would.\n    const { children, showLessLabel = \"Show less\", open, onOpenChange } = props as ShowMoreLinesProps;\n    const { measureKey } = props;\n    const clamp = [lines, maxLines].find(isCount) ?? DEFAULT_LINES;\n    return (\n      <ShowMoreText\n        open={open}\n        onOpenChange={onOpenChange}\n        lines={clamp}\n        showMoreLabel={showMoreLabel}\n        showLessLabel={showLessLabel}\n        className={className}\n        rootRef={ref}\n        measureKey={measureKey}\n      >\n        {children}\n      </ShowMoreText>\n    );\n  }\n  return <ShowMoreList {...(props as ShowMoreItemsProps | ShowMoreLoadProps)} showMoreLabel={showMoreLabel} />;\n}\n\n/**\n * What an instance last measured, by its `measureKey`, so a row that mounts again (a list that scrolls, a chat that\n * loads older messages) that has one starts with its last answer instead of folding and then undoing it. The resize\n * observer still measures and corrects it, so a wrong guess (a new width) costs one correction.\n */\nconst fitCache = new Map<string, boolean>();\nconst FIT_CACHE_SIZE = 1000;\n\nconst remember = (key: string | undefined, value: boolean): void => {\n  // Stryker disable next-line ConditionalExpression: an unkeyed instance never reads the cache, so a stray entry is not observable\n  if (key === undefined) return;\n  // Stryker disable next-line all: only moves a key to the newest place; it matters one eviction later and not by a line's worth of behaviour\n  fitCache.delete(key);\n  fitCache.set(key, value);\n  // Stryker disable next-line EqualityOperator: one entry more or fewer is not observable\n  if (fitCache.size > FIT_CACHE_SIZE) fitCache.delete(fitCache.keys().next().value!);\n};\n\n/**\n * One ResizeObserver for every ShowMore, and one animation-frame callback that measures them all. The observer only says\n * which ones changed size; the answers are read and committed in the next animation frame's callback, which the browser\n * runs before it lays the page out for that frame's observers and before it paints. So the button and the fade are in the\n * first frame the browser paints, a list of many folds costs one layout, and no read is forced while React commits.\n * Committing inside the observer's callback instead resizes elements the app watches above this one (its body, its shell),\n * and WebKit answers with the window error \"ResizeObserver loop completed with undelivered notifications\", which an\n * app's end-to-end fixture that fails on page errors counts as a failure.\n *\n * @claim \"One ResizeObserver for every ShowMore\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore in its first frame > measures many folds with one observer, every one's button in the same first painted frame)\n * @claim \"So the button and the fade are in the first frame the browser paints\" registry/ouro/components/ouro/collapsible/show-more.test.tsx verify:testExists(registry/ouro/components/ouro/collapsible/show-more.test.tsx::ShowMore in its first frame > has its button and fade in the first frame the browser paints, and nothing for what fits)\n */\ntype Fit = () => () => void;\n// Weak, so an element that is gone needs no clean-up: the observer delivers only the elements it watches.\nconst fitReaders = new WeakMap<Element, Fit>();\nconst pendingFits = new Set<Element>();\nlet fitFrame = 0;\nlet fitObserver: ResizeObserver | undefined;\nfunction scheduleFit(): void {\n  fitFrame ||= requestAnimationFrame(() => {\n    fitFrame = 0;\n    const targets = [...pendingFits];\n    pendingFits.clear();\n    // Every read first, then every write, so no read lays the page out again.\n    const answers = targets.map((target) => fitReaders.get(target)!());\n    flushSync(() => answers.forEach((answer) => answer()));\n  });\n}\nfunction observeFit(element: Element, fit: Fit): () => void {\n  fitObserver ??= new ResizeObserver((entries) => {\n    for (const entry of entries) pendingFits.add(entry.target);\n    scheduleFit();\n  });\n  fitReaders.set(element, fit);\n  // Measured in the next frame's callback, ahead of the observer's own first delivery, so the first painted frame has it.\n  pendingFits.add(element);\n  scheduleFit();\n  fitObserver.observe(element);\n  return () => {\n    pendingFits.delete(element);\n    fitObserver!.unobserve(element);\n  };\n}\n\nconst clampClass = \"line-clamp-(--ouro-show-more-lines)\";\n\nfunction ShowMoreText({\n  open,\n  onOpenChange,\n  lines,\n  children,\n  showMoreLabel,\n  showLessLabel,\n  className,\n  rootRef,\n  measureKey,\n}: {\n  lines: number;\n  children: ReactNode;\n  showMoreLabel: string;\n  showLessLabel: string;\n  className: string | undefined;\n  rootRef: Ref<HTMLDivElement> | undefined;\n  measureKey: string | number | undefined;\n} & ShowMoreOpenProps): JSX.Element {\n  const [expanded, setExpanded] = useOpen(open, onOpenChange);\n  // Folded by CSS in the first commit and in server HTML, with no button and no guess: a ResizeObserver reads after the\n  // browser lays the text out and adds the button to text that overflows, so no instance makes the page lay out again.\n  // It starts in a layout effect and commits with every other ShowMore's answer before paint (observeFit).\n  const fitKey = measureKey === undefined ? undefined : `text:${lines}:${measureKey}`;\n  // Stryker disable next-line ConditionalExpression: an unkeyed instance has nothing cached, so reading by an undefined key gives the same answer\n  const [overflowing, setOverflowing] = useState(() => (fitKey === undefined ? undefined : fitCache.get(fitKey)) ?? false);\n  const textRef = useRef<HTMLDivElement>(null);\n  const textId = useId();\n  useLayoutEffect(() => {\n    const text = textRef.current!;\n    return observeFit(text, () => {\n      // Clamped, whether it hides any; whole, whether it is taller than the lines it clamps to.\n      const clamped = !expanded;\n      const lineHeight = parseFloat(getComputedStyle(text).lineHeight);\n      if (clamped) {\n        // Stryker disable next-line EqualityOperator: a hidden line is many pixels, so > and >= differ only at a 1px rounding gap no text has\n        const over = text.scrollHeight > text.clientHeight + 1;\n        remember(fitKey, over);\n        return () => setOverflowing(over);\n      }\n      // A line height that is not a length (`normal`) cannot say, so the button stays: shown whole, it is the way back.\n      // Stryker disable next-line EqualityOperator: as above, a line is many pixels.\n      const over = lineHeight > 0 ? text.clientHeight > lineHeight * lines + 1 : true;\n      // Stryker disable next-line all: a mount is always folded and measures again, so what an expanded one remembers only changes whether a later remount writes\n      remember(fitKey, over);\n      return () => setOverflowing(over);\n    });\n  }, [expanded, lines, fitKey]);\n  return (\n    <div ref={rootRef} data-ouro=\"show-more\" className={cn(showMoreRootClass, className)}>\n      <div\n        ref={textRef}\n        id={textId}\n        data-ouro-show-more-text=\"\"\n        data-ouro-allow=\"clipped-text\"\n        data-ouro-allow-why=\"Clamped to its lines on purpose; Show more shows the rest\"\n        className={cn(textClass, !expanded && clampClass)}\n        style={{ \"--ouro-show-more-lines\": lines } as CSSProperties}\n      >\n        {children}\n      </div>\n      {overflowing && (\n        <Button\n          variant=\"plain\"\n          size=\"sm\"\n          className=\"-ms-(--ouro-button-px)\"\n          data-ouro-show-more-toggle=\"\"\n          data-ouro-control=\"show-more\"\n          data-ouro-part=\"toggle\"\n          aria-expanded={expanded}\n          aria-controls={textId}\n          onClick={() => setExpanded(!expanded)}\n        >\n          {expanded ? showLessLabel : showMoreLabel}\n        </Button>\n      )}\n    </div>\n  );\n}\n\nfunction ShowMoreHeight({\n  open,\n  onOpenChange,\n  maxHeight,\n  children,\n  showMoreLabel,\n  showLessLabel,\n  className,\n  rootRef,\n  measureKey,\n}: {\n  maxHeight: number;\n  children: ReactNode;\n  showMoreLabel: string;\n  showLessLabel: string;\n  className: string | undefined;\n  rootRef: Ref<HTMLDivElement> | undefined;\n  measureKey: string | number | undefined;\n} & ShowMoreOpenProps): JSX.Element {\n  const [expanded, setExpanded] = useOpen(open, onOpenChange);\n  // Unknown until the browser has laid the content out, so the first commit and server HTML are folded by CSS with no\n  // button and no guess: the ResizeObserver reads after layout and says whether it fits. It starts in a layout effect and\n  // commits with every other ShowMore's answer before paint (observeFit).\n  const fitKey = measureKey === undefined ? undefined : `height:${maxHeight}:${measureKey}`;\n  // Stryker disable next-line ConditionalExpression,LogicalOperator: an unkeyed instance has nothing cached; a cached answer is a boolean and `&& null` differs only by folding first, which the remount tests hold through the keyed path\n  const [fits, setFits] = useState<boolean | null>(() => (fitKey === undefined ? undefined : fitCache.get(fitKey)) ?? null);\n  const contentRef = useRef<HTMLDivElement>(null);\n  const buttonRef = useRef<HTMLButtonElement>(null);\n  const foldId = useId();\n  useLayoutEffect(() => {\n    const content = contentRef.current!;\n    // Measured once as it starts, and again on every change of size.\n    return observeFit(content, () => {\n      const fit = content.scrollHeight <= maxHeight * 1.2;\n      remember(fitKey, fit);\n      return () => setFits(fit);\n    });\n  }, [maxHeight, fitKey]);\n  const folded = !expanded && fits !== true;\n  const toggle = () => {\n    if (expanded) {\n      setExpanded(false);\n      // The content shrinks above the button; keep the button on screen.\n      requestAnimationFrame(() => buttonRef.current?.scrollIntoView({ block: \"nearest\" }));\n    } else setExpanded(true);\n  };\n  // Focus that lands below the fold (a link, a button in a card) unfolds the content.\n  const reveal = (event: FocusEvent<HTMLDivElement>) => {\n    // Unfolded, nothing is below the box's bottom, so this is folded content only.\n    const fold = event.currentTarget;\n    // The browser may already have scrolled the clipped box to the focused element, so measure\n    // from the box's unscrolled top.\n    const bottom = (event.target as HTMLElement).getBoundingClientRect().bottom - fold.getBoundingClientRect().top + fold.scrollTop;\n    if (bottom > fold.clientHeight) {\n      fold.scrollTop = 0;\n      setExpanded(true);\n    }\n  };\n  return (\n    <div ref={rootRef} data-ouro=\"show-more\" className={cn(showMoreRootClass, className)}>\n      <div\n        id={foldId}\n        data-ouro-show-more-fold=\"\"\n        data-folded={folded && fits === false ? \"\" : undefined}\n        data-ouro-allow=\"clipped-text\"\n        data-ouro-allow-why=\"Folded to its height on purpose; Show more shows the rest\"\n        onFocus={reveal}\n        className={cn(foldClass, folded && \"max-h-(--ouro-show-more-height) overflow-hidden\")}\n        style={{ \"--ouro-show-more-height\": `${maxHeight}px` } as CSSProperties}\n      >\n        <div ref={contentRef} className=\"flow-root\">\n          {children}\n        </div>\n      </div>\n      {fits === false && (\n        <Button\n          ref={buttonRef}\n          variant=\"plain\"\n          size=\"sm\"\n          className=\"-ms-(--ouro-button-px)\"\n          data-ouro-show-more-toggle=\"\"\n          data-ouro-control=\"show-more\"\n          data-ouro-part=\"toggle\"\n          aria-expanded={expanded}\n          aria-controls={foldId}\n          onClick={toggle}\n        >\n          {expanded ? showLessLabel : showMoreLabel}\n        </Button>\n      )}\n    </div>\n  );\n}\n\nfunction ShowMoreList(props: (ShowMoreItemsProps | ShowMoreLoadProps) & { showMoreLabel: string }): JSX.Element {\n  const { items, ordered, showMoreLabel, className, ref } = props;\n  const load = props.onShowMore !== undefined ? (props as ShowMoreLoadProps) : undefined;\n  const { initialCount, showLessLabel = \"Show less\", open, onOpenChange } = props as ShowMoreItemsProps;\n  const count = isCount(initialCount) ? initialCount : DEFAULT_COUNT;\n  const [expanded, setExpanded] = useOpen(open, onOpenChange);\n  // Rows from this index on are newly shown: they fade in.\n  const [freshFrom, setFreshFrom] = useState<number | null>(null);\n  // The index of the first row the last press asked for, until focus has moved there, and the\n  // first item when it was asked: a different first item means a new list, not the next page.\n  const pending = useRef<number | null>(null);\n  const pendingFirst = useRef<unknown>(undefined);\n  const listRef = useRef<HTMLUListElement & HTMLOListElement>(null);\n  const buttonRef = useRef<HTMLElement>(null);\n  const listId = useId();\n  const loading = load?.loading === true;\n  const visible = load || expanded ? items : items.slice(0, count);\n  const hasButton = load ? load.hasMore : items.length > count;\n\n  // What the status region says after a page loads (load mode only).\n  const [status, setStatus] = useState(\"\");\n  // Whether `loading` was true since the last press, so a load that ends with no new items is noticed.\n  const loaded = useRef(false);\n  const loadedLabel = load?.loadedLabel ?? ((shown: number) => `Showing ${shown} items`);\n  const noMoreLabel = load?.noMoreLabel ?? \"No more items\";\n\n  useEffect(() => {\n    const from = pending.current;\n    if (from === null) return;\n    if (loading) {\n      loaded.current = true;\n      return;\n    }\n    const rows = listRef.current!.children;\n    const stop = () => {\n      pending.current = null;\n      loaded.current = false;\n    };\n    const arrive = (row: Element | undefined, message: string) => {\n      stop();\n      // The button is gone. An empty list whose load found nothing has no row, so focus moves\n      // to the list itself (focusable and named by noMoreLabel while empty), never to the page.\n      if (row) focusRow(row);\n      else listRef.current!.focus();\n      if (load) setStatus(message);\n    };\n    const replaced = pendingFirst.current !== EMPTY && identity(items[0]) !== pendingFirst.current;\n    if (replaced || rows.length < from) {\n      // The list was replaced (a new first item, or fewer items: a new search). Stop waiting,\n      // so a later change to the list never moves focus.\n      stop();\n    } else if (rows.length > from) {\n      arrive(rows[from]!, loadedLabel(rows.length));\n    } else if (!hasButton) {\n      // The last page came back empty and the button is gone: keep focus in the list.\n      arrive(rows[rows.length - 1], noMoreLabel);\n    } else if (loaded.current) {\n      // The load ended with no new items (it failed): stop waiting, as above.\n      stop();\n    }\n  });\n\n  const press = (event: MouseEvent) => {\n    if (load) {\n      event.preventDefault();\n      pending.current = items.length;\n      pendingFirst.current = items.length === 0 ? EMPTY : identity(items[0]);\n      loaded.current = false;\n      setFreshFrom(items.length);\n      load.onShowMore();\n    } else if (expanded) {\n      setExpanded(false);\n      setFreshFrom(null);\n      // The list shrinks above the button; keep the button on screen.\n      requestAnimationFrame(() => buttonRef.current?.scrollIntoView({ block: \"nearest\" }));\n    } else {\n      pending.current = count;\n      // The button shows only when there are more items than count, so the list is not empty.\n      pendingFirst.current = identity(items[0]);\n      setFreshFrom(count);\n      setExpanded(true);\n    }\n  };\n\n  const List = ordered ? \"ol\" : \"ul\";\n  // An empty list with nothing more to load takes focus when the last load finds nothing, so it\n  // is named for that already when focus lands.\n  const emptyEnd = load !== undefined && items.length === 0 && !load.hasMore;\n  const button = !hasButton ? null : load ? (\n    <Button\n      ref={buttonRef as Ref<HTMLAnchorElement & HTMLButtonElement>}\n      variant=\"plain\"\n      size=\"sm\"\n      className=\"-ms-(--ouro-button-px)\"\n      data-ouro-show-more-toggle=\"\" data-ouro-control=\"show-more\" data-ouro-part=\"toggle\"\n      aria-controls={listId}\n      loading={loading}\n      loadingLabel={load.loadingLabel}\n      onClick={press}\n      {...(load.href !== undefined ? { href: load.href } : {})}\n    >\n      {showMoreLabel}\n    </Button>\n  ) : (\n    <Button\n      ref={buttonRef as Ref<HTMLButtonElement>}\n      variant=\"plain\"\n      size=\"sm\"\n      className=\"-ms-(--ouro-button-px)\"\n      data-ouro-show-more-toggle=\"\"\n      data-ouro-control=\"show-more\"\n      data-ouro-part=\"toggle\"\n      aria-expanded={expanded}\n      aria-controls={listId}\n      onClick={press}\n    >\n      {expanded ? showLessLabel : showMoreLabel}\n    </Button>\n  );\n  return (\n    <div ref={ref} data-ouro=\"show-more\" className={cn(showMoreRootClass, className)}>\n      {/* Safari drops list semantics from an unstyled list unless the role is explicit. */}\n      <List\n        ref={listRef}\n        id={listId}\n        role=\"list\"\n        tabIndex={emptyEnd ? -1 : undefined}\n        aria-label={emptyEnd ? noMoreLabel : undefined}\n        className={cn(listClass, emptyEnd && \"outline-none\")}\n      >\n        {visible.map((item, index) => (\n          <li\n            key={rowKey(item, index)}\n            tabIndex={-1}\n            className={cn(\n              itemClass,\n              freshFrom !== null && index >= freshFrom && \"transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) starting:opacity-0\",\n            )}\n          >\n            {item}\n          </li>\n        ))}\n      </List>\n      {button}\n      {/* Stays mounted after the last page, so the last count is still read. */}\n      {load && (\n        <p role=\"status\" data-ouro-show-more-status=\"\" className=\"sr-only\">\n          {status}\n        </p>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/collapsible/show-more.tsx"
    }
  ],
  "docs": "\"Show more\" for a long list or a long text. Import: import { ShowMore } from \"@/components/ouro/collapsible/show-more\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, collapsible, 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/show-more.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}