{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lightbox",
  "title": "Lightbox",
  "description": "Thumbnails that open a full-screen image viewer.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/carousel",
    "@ouro/dialog",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-page-scroll-hold",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-mounted-open",
    "@ouro/lib-use-ouro",
    "@ouro/lib-use-reduced-motion"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/lightbox/lightbox-styles.ts",
      "content": "export {\n  fullScreenClass,\n  mosaicCellClass,\n  mosaicClass,\n  mosaicFrameClass,\n  mosaicImageClass,\n  mosaicLayout,\n  mosaicMoreClass,\n  mosaicThumbnailClass,\n  captionClass,\n  counterClass,\n  figureClass,\n  gridClass,\n  headerClass,\n  imageClass,\n  popupClass,\n  stageClass,\n  thumbnailClass,\n  thumbnailImageClass,\n  titleClass,\n  zoomedImageClass,\n  zoomOrigin,\n  zoomViewClass,\n};\n\n// Class strings and helpers for Lightbox, apart from the component so its file exports only\n// components (React Fast Refresh). Class strings are literal so the app's Tailwind finds them.\n\n/**\n * The thumbnails: as many columns of at least 8rem as fit. @internal\n *\n * @claim \"as many columns of at least 8rem as fit\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox thumbnails > lays the thumbnails out in as many columns of at least 8rem as fit)\n */\nconst gridClass = \"m-0 grid list-none grid-cols-[repeat(auto-fill,minmax(min(100%,8rem),1fr))] gap-3 p-0\";\n\n/**\n * A thumbnail: a 4:3 button whose picture zooms a little under a mouse, and which presses in\n * like the other controls. Its border keeps an edge in forced colours. @internal\n *\n * @claim \"A thumbnail: a 4:3 button\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox thumbnails > lays the thumbnails out in as many columns of at least 8rem as fit)\n */\nconst thumbnailClass =\n  \"group press relative box-border block aspect-4/3 w-full m-0 p-0 overflow-hidden cursor-zoom-in \" +\n  \"rounded-ouro-lg border border-solid border-border bg-muted [-webkit-tap-highlight-color:transparent] \" +\n  \"motion-safe:active:scale-(--ouro-press-scale) \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\n/** @internal */\nconst thumbnailImageClass =\n  \"block size-full object-cover \" +\n  \"motion-safe:transition-transform motion-safe:duration-(--ouro-duration-slow) motion-safe:ease-(--ouro-ease-out) \" +\n  \"motion-safe:pointer-fine:group-hover:scale-[1.04]\";\n\n/**\n * The viewer fills the screen, less the dialog's margin, up to 72rem wide; below 640px it runs\n * edge to edge, so a wide image gets the phone's whole width. It grows from\n * the thumbnail that opened it, from 0.9 rather than the dialog's 0.96; with reduced\n * motion it only fades, by the dialog's own rule. @internal\n *\n * @claim \"up to 72rem wide\" registry/ouro/components/ouro/lightbox/lightbox-styles.ts verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox-styles.ts, /\"h-full max-w-\\[72rem\\]/)\n * @claim \"It grows from the thumbnail that\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox motion > grows from the thumbnail that opened it, and only fades with reduced motion)\n */\nconst popupClass =\n  \"h-full max-w-[72rem] data-starting-style:[transform:scale(0.9)] data-ending-style:[transform:scale(0.9)] \" +\n  \"max-sm:-mx-4 max-sm:w-[calc(100%+2rem)] max-sm:max-w-none max-sm:rounded-none\";\n\n/**\n * With `fullScreen`, the viewer covers the whole screen at every width: it steps over the\n * dialog's margin and drops its corners, hairline and shadow, so only the image and its bar show.\n * The viewport keeps the safe-area insets past that margin. Behind the image it is one solid,\n * quiet field in both themes, as picture viewers draw it: the backdrop colour, fully opaque, so\n * nothing of the page shows through, with the theme's dark palette inside (the `dark` class, Ouro's\n * dark mode), so the title, the position and the buttons read on it. In forced colours it is the\n * system's opaque Canvas. @internal\n *\n * @claim \"Behind the image it is one solid,\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > hides the page behind one solid field in the light theme too, with readable controls)\n * @claim \"In forced colours it is the\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx, /chromiumOnly\\(\\\"leaves forced colours to the system\\\"/)\n *\n * @claim \"With `fullScreen`, the viewer covers the\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > covers the whole screen with no frame, from the thumbnails or controlled)\n */\nconst fullScreenClass =\n  \"dark -m-4 h-[calc(100%+2rem)] max-h-none w-[calc(100%+2rem)] max-w-none rounded-none ring-0 shadow-none \" +\n  \"bg-(--ouro-backdrop-color) text-foreground forced-colors:bg-[Canvas]\";\n\n/**\n * Around a mosaic: as wide as its column, at most 25rem, and no wider than keeps it 17.5rem tall at\n * its shape (`--ouro-lightbox-ratio`, width over height), as big as a chat shows pictures. Where the\n * column takes its width from what is in it, as a chat bubble's does, an empty strut (`::before`)\n * asks for that size, so the mosaic has it from the first frame, before its pictures load and when\n * they fail, as wide as a loaded picture made it before its pictures were pinned to their cells, and\n * never wider than its column. @internal\n *\n * @claim \"so the mosaic has it from the first frame\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic in a chat message > holds %s at its final box from the first frame, before its pictures load and when they fail)\n * @claim \"as wide as a loaded picture made it before\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic in a chat message > is as big as before its pictures were pinned, in a column as wide as what is in it (%ipx, %s))\n *\n * @claim \"as big as a chat shows pictures\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > is at most 25rem wide and 17.5rem tall at its shape, never wider than its column, unless the app gives it another width)\n */\nconst mosaicFrameClass =\n  \"w-full min-w-0 max-w-[min(100%,25rem,calc(17.5rem*var(--ouro-lightbox-ratio)))] \" +\n  \"before:block before:h-0 before:w-[min(25rem,calc(17.5rem*var(--ouro-lightbox-ratio)))] before:max-w-full before:content-['']\";\n\n/** The mosaic's frame: rounded corners and a hairline, with the card colour in the gaps between its pictures. @internal */\nconst mosaicClass =\n  \"relative m-0 grid w-full list-none gap-0.5 overflow-hidden p-0 \" +\n  \"rounded-ouro-lg border border-solid border-border bg-card\";\n\n/**\n * A mosaic's cell; the first of three spans both rows. @internal\n *\n * @claim \"the first of three spans both rows\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws two side by side, three as one large and two small, and four or more as a 2 by 2 grid)\n */\nconst mosaicCellClass = \"relative m-0 min-h-0 min-w-0 p-0 [&:first-child:nth-last-child(3)]:row-span-2\";\n\n/**\n * A mosaic's picture fills its cell from its corners: the button is pinned to the cell, and the\n * picture stretches over the button's one grid cell, so no percentage height is resolved inside the\n * mosaic's grid, which WebKit does slowly within nested flex columns, as in a conversation. @internal\n *\n * @claim \"fills its cell from its corners\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > pins each picture to its cell's corners, with no percentage height to resolve, and fills it exactly)\n * @claim \"which WebKit does slowly within nested flex columns\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx, /it\\.skipIf\\(server\\.browser !== \"webkit\"\\)\\(\"lays out a conversation of many mosaics quickly in WebKit\"/)\n */\nconst mosaicThumbnailClass =\n  \"group press absolute inset-0 box-border grid grid-cols-1 grid-rows-1 m-0 p-0 overflow-hidden cursor-zoom-in border-0 bg-muted \" +\n  \"[-webkit-tap-highlight-color:transparent] motion-safe:active:scale-(--ouro-press-scale) \" +\n  \"outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\n/**\n * A mosaic's picture: stretched over its button's one grid cell, cropped to it, with no size of its own. @internal\n *\n * @claim \"with no size of its own\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > pins each picture to its cell's corners, with no percentage height to resolve, and fills it exactly)\n */\nconst mosaicImageClass =\n  \"block min-h-0 min-w-0 self-stretch justify-self-stretch object-cover \" +\n  \"motion-safe:transition-transform motion-safe:duration-(--ouro-duration-slow) motion-safe:ease-(--ouro-ease-out) \" +\n  \"motion-safe:pointer-fine:group-hover:scale-[1.04]\";\n\n/** \"+3\" over the last picture shown, when more follow it in the viewer. @internal */\nconst mosaicMoreClass =\n  \"pointer-events-none absolute inset-0 flex items-center justify-center \" +\n  \"bg-[color-mix(in_oklab,var(--foreground)_45%,transparent)] text-2xl font-semibold text-background\";\n\n/**\n * How a mosaic lays out `count` pictures, as Teams and other chat apps do: one at its own shape\n * (between 3:4 and 3:1, 4:3 when its size is unknown); two side by side in a 2:1 frame; three as\n * one large and two small in a 3:2 frame; four or more as a 2 by 2 grid in a 4:3 frame. @internal\n *\n * @claim \"How a mosaic lays out `count` pictures\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws one picture at its own shape, between 3:4 and 3:1, and 4:3 when its size is unknown)\n * @claim \"How a mosaic lays out `count` pictures\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws two side by side, three as one large and two small, and four or more as a 2 by 2 grid)\n */\nfunction mosaicLayout(count: number, width?: number, height?: number): { ratio: number; grid?: string } {\n  if (count === 1) {\n    const [w, h] = [width ?? 0, height ?? 0];\n    const own = w > 0 && h > 0 ? w / h : 4 / 3;\n    // One cell needs no tracks of its own: the grid's single implicit one fills the frame.\n    return { ratio: Math.min(3, Math.max(3 / 4, own)) };\n  }\n  if (count === 2) return { ratio: 2, grid: \"grid-cols-2 grid-rows-1\" };\n  if (count === 3) return { ratio: 3 / 2, grid: \"grid-cols-[3fr_2fr] grid-rows-2\" };\n  return { ratio: 4 / 3, grid: \"grid-cols-2 grid-rows-2\" };\n}\n\n/** The bar above the image: the gallery's name, the position, the original's link and Close. @internal */\nconst headerClass = \"box-border flex min-h-14 shrink-0 items-center gap-2 py-2 pe-2 ps-5\";\n\n/** @internal */\nconst titleClass = \"min-w-0 flex-1\";\n\n/** @internal */\nconst counterClass = \"shrink-0 text-sm tabular-nums text-muted-foreground\";\n\n/**\n * The carousel fills the rest: the image row takes what the buttons leave. Keyboard focus on the\n * images draws its ring around the image shown, not around the whole stage (imageClass); in forced colours the\n * stage keeps the system's ring as well. @internal\n *\n * @claim \"Keyboard focus on the images draws\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > rings the image shown, not the stage, when the images have keyboard focus)\n */\nconst stageClass =\n  \"min-h-0 flex-1 grid-rows-[minmax(0,1fr)_auto] px-3 pb-5 sm:px-5 \" +\n  \"[&_[data-ouro-carousel-viewport]]:not-forced-colors:focus-visible:outline-none\";\n\n/**\n * The image and its caption, centred together: the image's row takes what the caption leaves,\n * so the caption sits right under the image at any shape of screen. @internal\n *\n * @claim \"so the caption sits right under\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > fits the image to the screen, uncropped, with the caption right under it, on a phone and on a desktop)\n */\nconst figureClass =\n  \"relative m-0 grid h-full min-h-0 grid-rows-[minmax(0,auto)] auto-rows-auto content-center justify-items-center gap-3 \" +\n  \"touch-pan-x touch-pan-y\";\n\n/**\n * The image, as large as fits and never cropped, with rounded corners and a hairline. @internal\n *\n * @claim \"as large as fits and never cropped\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > fits the image to the screen, uncropped, with the caption right under it, on a phone and on a desktop)\n */\nconst imageClass =\n  \"block min-h-0 max-h-full max-w-full object-contain rounded-ouro-lg ring-1 ring-border/60 outline-ring outline-offset-2 \" +\n  \"in-[[data-ouro-carousel-viewport]:focus-visible]:outline-2 in-[[data-ouro-carousel-viewport]:focus-visible]:outline-solid\";\n\n/**\n * A zoomed image's scroller, over the whole slide: one finger, a trackpad or the arrow keys move\n * around the image, and a swipe that reaches its edge stops there rather than turning the page.\n * The browser's own pinch-zoom is off on the figure (it pans only), so a pinch zooms the image.\n * The image sits in the middle while it is smaller than the scroller. @internal\n *\n * @claim \"a swipe that reaches its edge\" registry/ouro/components/ouro/lightbox/lightbox-styles.ts verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox-styles.ts, /overflow-auto overscroll-contain/)\n */\nconst zoomViewClass =\n  \"absolute inset-0 flex overflow-auto overscroll-contain rounded-ouro-lg bg-popover \" +\n  \"outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"forced-colors:border forced-colors:border-solid\";\n\n/** @internal */\nconst zoomedImageClass = \"m-auto block max-w-none max-h-none shrink-0\";\n\n/** @internal */\nconst captionClass = \"m-0 grid max-w-prose shrink-0 gap-1 text-center text-sm leading-5 text-muted-foreground\";\n\n/**\n * Where the viewer grows from: the centre of the thumbnail that opened it, in the viewer's\n * own coordinates. Offsets leave out the viewer's starting scale. @internal\n */\nfunction zoomOrigin(thumbnail: Element, popup: HTMLElement): string {\n  const rect = thumbnail.getBoundingClientRect();\n  const x = rect.left + rect.width / 2 - popup.offsetLeft;\n  const y = rect.top + rect.height / 2 - popup.offsetTop;\n  return `${Math.round(x)}px ${Math.round(y)}px`;\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/lightbox/lightbox-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/lightbox/lightbox.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type HTMLAttributes, type JSX, type KeyboardEvent, type PointerEvent, type ReactNode, type RefObject, type SVGProps } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { holdPageAtPress } from \"@/registry/ouro/lib/ouro/page-scroll-hold\";\nimport { useDevWarnings, type DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useMountedOpen } from \"@/registry/ouro/lib/ouro/use-mounted-open\";\nimport { useOuro } from \"@/registry/ouro/lib/ouro/use-ouro\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { Carousel } from \"@/registry/ouro/components/ouro/carousel/carousel\";\nimport { fillTemplate } from \"@/registry/ouro/components/ouro/carousel/carousel-styles\";\nimport {\n  DialogBackdrop,\n  DialogClose,\n  DialogPopupUnchecked,\n  DialogPortal,\n  DialogRoot,\n  DialogTitle,\n  DialogViewport,\n} from \"@/registry/ouro/components/ouro/dialog/dialog-parts\";\nimport {\n  captionClass,\n  counterClass,\n  figureClass,\n  gridClass,\n  headerClass,\n  imageClass,\n  fullScreenClass,\n  mosaicCellClass,\n  mosaicClass,\n  mosaicFrameClass,\n  mosaicImageClass,\n  mosaicLayout,\n  mosaicMoreClass,\n  mosaicThumbnailClass,\n  popupClass,\n  stageClass,\n  thumbnailClass,\n  thumbnailImageClass,\n  titleClass,\n  zoomedImageClass,\n  zoomOrigin,\n  zoomViewClass,\n} from \"@/registry/ouro/components/ouro/lightbox/lightbox-styles\";\n\n/** One image in a {@link Lightbox}. */\nexport interface LightboxImage {\n  /** The full-size image's address, shown in the viewer. */\n  src: string;\n  /** Describes the image for screen readers, on its thumbnail and in the viewer. */\n  alt: string;\n  /** A smaller file for the thumbnail. @default src */\n  thumbnail?: string | undefined;\n  /** A short title under the image in the viewer, shown as given. */\n  title?: ReactNode;\n  /**\n   * A line under the title in the viewer, shown as given: Lightbox adds nothing to it.\n   *\n   * @claim \"Lightbox adds nothing to it\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > shows the title and caption with the image, exactly as given)\n   */\n  caption?: ReactNode;\n  /** The original file, or a page about the image: the viewer links to it in a new tab. */\n  href?: string | undefined;\n  /**\n   * The image's own width and height, in any unit. With `layout=\"mosaic\"` and one image, its\n   * thumbnail keeps this shape (between 3:4 and 3:1), so the page holds its place before it loads.\n   *\n   * @claim \"its thumbnail keeps this shape\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws one picture at its own shape, between 3:4 and 3:1, and 4:3 when its size is unknown)\n   */\n  width?: number | undefined;\n  /** The image's own height; see `width`. */\n  height?: number | undefined;\n  /**\n   * A still frame of an animated image (a GIF), which its thumbnail shows instead when the user\n   * asks for reduced motion. The viewer still plays the image, since opening it asks to see it.\n   */\n  still?: string | undefined;\n}\n\n/** Props shared by both ways of using a {@link Lightbox}. */\nexport interface LightboxBaseProps {\n  /**\n   * Names the viewer for screen readers, with the position (\"Kitchen photos, 2 of 4\"), and shows\n   * at its top, such as \"Kitchen photos\". With thumbnails it names their list too. It is always\n   * required.\n   *\n   * @claim \"It is always required\" registry/ouro/components/ouro/lightbox/lightbox.test-d.ts verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox.test-d.ts, /expectTypeOf<\\{\\simages:\\stypeof\\simages\\s\\}>\\(\\)\\.not\\.toExtend<LightboxProps>/)\n   * @claim \"Names the viewer for screen readers\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox opening and closing > opens on the image pressed, named by the label and the position)\n   */\n  label: string;\n  /** The images, in order. The viewer steps through them, and the thumbnails show them in a grid. */\n  images: readonly LightboxImage[];\n  /** Next on the last image goes back to the first, and Previous on the first goes to the last. */\n  loop?: boolean | undefined;\n  /** Called with the image's index when the user moves to another image in the viewer, once per change. */\n  onIndexChange?: ((index: number) => void) | undefined;\n  /** The close button's accessible name. @default \"Close\" */\n  closeLabel?: string | undefined;\n  /** The Previous button's accessible name. @default \"Previous image\" */\n  previousLabel?: string | undefined;\n  /** The Next button's accessible name. @default \"Next image\" */\n  nextLabel?: string | undefined;\n  /**\n   * The position the viewer shows and announces when it changes: `{n}` is the image's number\n   * and `{total}` the number of images. @default \"{n} of {total}\"\n   *\n   * @claim \"The position the viewer shows and\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > shows the position and announces it once when it changes)\n   */\n  positionLabel?: string | undefined;\n  /** The text of the link to an image's `href`. @default \"Open original\" */\n  originalLabel?: string | undefined;\n  /**\n   * The zoom button's accessible name. It shows while the image is drawn smaller than its own\n   * size, and zooms it to that size, as a double-tap or a pinch does. @default \"Zoom\"\n   *\n   * @claim \"It shows while the image is\" registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx::Lightbox zoom > offers the zoom button only while the image is drawn smaller than its own size)\n   */\n  zoomLabel?: string | undefined;\n\n  /**\n   * The viewer covers the whole screen at every width, with no frame around it, rather than\n   * sitting in a dialog with the page around it. Use it where pictures are the point, as in a\n   * chat's photos. Below an app's `--ouro-inset-top` bar it starts under the bar, as a dialog does.\n   *\n   * @claim \"The viewer covers the whole screen at\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > covers the whole screen with no frame, from the thumbnails or controlled)\n   * @claim \"Below an app's `--ouro-inset-top` bar it starts\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > starts below --ouro-inset-top and fills the rest of the window)\n   */\n  fullScreen?: boolean | undefined;\n\n  /** Not a prop. Pass the images as `images`: `<Lightbox images={[{ src, alt }]}>`. */\n  slides?: { 'Use images={[{ src, alt }]}': never };\n  /** Not a prop. Lightbox uses `fullScreen`: `<Lightbox fullScreen>`. */\n  fullscreen?: { \"Use <Lightbox fullScreen>\": never };\n}\n\n/** A Lightbox that draws its own thumbnails, which open the viewer. */\nexport type LightboxWithThumbnailsProps = LightboxBaseProps & {\n  /** Layout only, for the thumbnails: width and margins (`max-w-2xl`, `mt-6`). Appearance classes warn in development. */\n  className?: string | undefined;\n  /**\n   * How the thumbnails sit. `grid`: as many 4:3 thumbnails in a row as fit. `mosaic`: one frame,\n   * as a chat shows the pictures in a message: one picture at its own shape (`width` and\n   * `height`), two side by side, three as one large and two small, four or more as a 2 by 2 grid\n   * with \"+N\" on the last; the viewer still steps through them all. The frame is as big as a chat\n   * shows pictures: at most 25rem wide and 17.5rem tall, and never wider than its column, so a\n   * picture never crowds the words around it; `className` gives it another width\n   * (`max-w-none`). @default \"grid\"\n   *\n   * @claim \"at most 25rem wide and 17.5rem\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > is at most 25rem wide and 17.5rem tall at its shape, never wider than its column, unless the app gives it another width)\n   * @claim \"as many 4:3 thumbnails in a row\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox thumbnails > lays the thumbnails out in as many columns of at least 8rem as fit)\n   * @claim \"as a chat shows the pictures in\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws one picture at its own shape, between 3:4 and 3:1, and 4:3 when its size is unknown)\n   * @claim \"as a chat shows the pictures in\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws two side by side, three as one large and two small, and four or more as a 2 by 2 grid)\n   * @claim \"as a chat shows the pictures in\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > shows four of more pictures, the last saying how many more follow, to sight and to screen readers)\n   * @claim \"as a chat shows the pictures in\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > opens the viewer on the picture pressed, steps on past the four shown, and gives focus back to the last one shown)\n   */\n  layout?: \"grid\" | \"mosaic\" | (string & { 'Use \"grid\" or \"mosaic\"': never }) | undefined;\n  /** Not with thumbnails. Pass `open` and `onOpenChange` too to open the viewer from your own layout. */\n  open?: never;\n  /** Not with thumbnails. Pass `open` and `onOpenChange` too to open the viewer from your own layout. */\n  index?: never;\n  /** Not with thumbnails. Pass `open` and `onOpenChange` too to open the viewer from your own layout. */\n  onOpenChange?: never;\n  /** Not with thumbnails: focus goes to the thumbnail of the image last shown. */\n  returnFocus?: never;\n};\n\n/** A controlled Lightbox: the viewer alone, which you open from thumbnails you lay out yourself. */\nexport type LightboxControlledProps = LightboxBaseProps & {\n  /**\n   * Whether the viewer is open. Focus goes back to whatever had it when the viewer opened, unless\n   * `returnFocus` gives another element, and the viewer grows from that element. Keep the Lightbox\n   * mounted and change `open`: one that mounts already open after a press or a key appears and leaves\n   * without its transitions, and says so in development.\n   *\n   * @claim \"Keep the Lightbox mounted and change\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > says once in development that a viewer mounted already open runs no transitions)\n   * @claim \"Focus goes back to whatever had\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > gives focus back to what had it when the viewer opened, and grows from it)\n   */\n  open: boolean;\n  /**\n   * The image the viewer shows, by its place in `images`. It opens on it, and moves to it when you change it\n   * while open; update it in `onIndexChange` to follow the user. @default 0\n   *\n   * @claim \"moves to it when you change\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > moves to an index the app sets while the viewer is open)\n   */\n  index?: number | undefined;\n  /** Called with `false` when the user closes the viewer (Close, Escape, a press outside). */\n  onOpenChange: (open: boolean) => void;\n  /**\n   * Where focus goes as the viewer closes, given the index of the image last shown: return that\n   * image's thumbnail in your layout, so the user is back where they were looking. Return nothing\n   * to give focus back to what had it when the viewer opened.\n   *\n   * @claim \"Where focus goes as the viewer\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > gives focus to what returnFocus gives for the image last shown, or else back to what had it)\n   */\n  returnFocus?: ((index: number) => HTMLElement | null | undefined) | undefined;\n  /** Not with `open`: lay out your own thumbnails instead, since a controlled Lightbox draws the viewer alone. */\n  className?: never;\n  /**\n   * Not with `open`: a controlled Lightbox draws no thumbnails to lay out.\n   *\n   * @claim \"a controlled Lightbox draws no thumbnails\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > draws no thumbnails, and opens on index when open)\n   */\n  layout?: never;\n};\n\n/** Props for {@link Lightbox}: thumbnails of its own, or `open` with `onOpenChange` for the viewer alone. */\nexport type LightboxProps = LightboxWithThumbnailsProps | LightboxControlledProps;\n\nfunction ExternalIcon(props: SVGProps<SVGSVGElement>): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" {...props}>\n      <path d=\"M9 3h4v4M13 3L7.5 8.5M11 9.5V13H3V5h3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nfunction ZoomIcon({ out }: { out: boolean }): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4\">\n      <circle cx=\"7\" cy=\"7\" r=\"4.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n      <path d={out ? \"M5 7h4M10.5 10.5L14 14\" : \"M5 7h4M7 5v4M10.5 10.5L14 14\"} stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nfunction CloseIcon(): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4\">\n      <path d=\"M4 4l8 8M12 4l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\ninterface ViewerProps {\n  label: string;\n  images: readonly LightboxImage[];\n  loop: boolean;\n  index: number;\n  onIndexChange: ((index: number) => void) | undefined;\n  nameId: string;\n  closeLabel: string;\n  previousLabel: string;\n  nextLabel: string;\n  positionLabel: string;\n  originalLabel: string;\n  zoomLabel: string;\n  /** Where the viewer writes the index of the image it shows, for focus to go to as it closes. */\n  shownRef: { current: number };\n  /** Where the viewer puts the function that shows a position the keys chose (Home, End) before the scroll settles. */\n  chooseRef: { current: ((index: number) => void) | null };\n}\n\n/**\n * Steps the viewer with the arrow keys, in reading order, from anywhere in it, by pressing the\n * carousel's own Previous or Next, and goes to the first or the last image with Home or End,\n * showing that position at once (`choose`). A key with a modifier, or one typed into a field in a\n * caption, is left alone.\n */\nfunction stepWithKeys(event: KeyboardEvent<HTMLElement>, choose: (index: number) => void, reduced: boolean): void {\n  const { key } = event;\n  if (key !== \"ArrowLeft\" && key !== \"ArrowRight\" && key !== \"Home\" && key !== \"End\") return;\n  if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;\n  // A field in a caption moves its caret, and a zoomed image scrolls.\n  if ((event.target as Element).closest(\"input, textarea, select, [contenteditable], [data-ouro-lightbox-zoom-view]\")) return;\n  event.preventDefault();\n  if (key === \"Home\" || key === \"End\") {\n    // Scrolled to the start or the end, as the carousel's buttons scroll: the carousel reports and\n    // announces where it settles. Right to left, the end is the most negative scrollLeft.\n    const viewport = event.currentTarget.querySelector<HTMLElement>(\"[data-ouro-carousel-viewport]\")!;\n    const end = getComputedStyle(viewport).direction === \"rtl\" ? -viewport.scrollWidth : viewport.scrollWidth;\n    const behavior = reduced ? \"instant\" : \"smooth\";\n    // Stryker disable next-line ArithmeticOperator: the position stops at the last image, so one past it shows the same.\n    choose(key === \"Home\" ? 0 : viewport.children.length - 1);\n    viewport.scrollTo({ left: key === \"Home\" ? 0 : end, behavior });\n    return;\n  }\n  const rtl = getComputedStyle(event.currentTarget).direction === \"rtl\";\n  const part = (key === \"ArrowRight\") !== rtl ? \"next\" : \"previous\";\n  event.currentTarget.querySelector<HTMLButtonElement>(`[data-ouro-control=\"carousel\"][data-ouro-part=\"${part}\"]`)!.click();\n}\n\n/** Below this, zooming in would show almost nothing more. */\nconst minZoom = 1.05;\n/**\n * How long a double-tap's second tap may follow the first, in milliseconds: the longest of the\n * platforms' defaults, so an unhurried tapper and a busy device still double-tap.\n */\nconst doubleTapTime = 500;\n/** How far a tap may drift, and how far apart a double-tap's taps may be, in pixels. */\nconst tapSlop = 24;\n\ninterface FigureProps {\n  image: LightboxImage;\n  /** How many times larger than fitted the image is drawn, up to its own size. */\n  scale: number;\n  onScale: (scale: number) => void;\n  /** Reports how far the image can zoom: its own width over its fitted width. */\n  onMaxScale: (max: number) => void;\n  zoomLabel: string;\n  /** How soon its image is fetched: `high` for the image shown, `low` for those more than one step away. */\n  priority: \"high\" | \"low\" | undefined;\n}\n\n/** The image's fitted size, and its own width. */\ninterface Fitted {\n  width: number;\n  height: number;\n  natural: number;\n}\n\n/**\n * The fitted size, measured while the image is drawn in the slide (it stays there, hidden, while\n * zoomed), and its own width once it has loaded: another image of the same shape takes the same\n * space, so only its load tells its own size has changed.\n */\nfunction useFittedSize(picture: RefObject<HTMLImageElement | null>): Fitted {\n  // Stryker disable next-line ObjectLiteral: measured as the image mounts, before anything reads it; unmeasured, max is 1 either way.\n  const [fitted, setFitted] = useState<Fitted>({ width: 0, height: 0, natural: 0 });\n  useEffect(\n    () => {\n      const img = picture.current!;\n      const measure = () => setFitted({ width: img.offsetWidth, height: img.offsetHeight, natural: img.naturalWidth });\n      const observer = new ResizeObserver(measure);\n      observer.observe(img);\n      img.addEventListener(\"load\", measure);\n      return () => {\n        observer.disconnect();\n        img.removeEventListener(\"load\", measure);\n      };\n    },\n    // Stryker disable next-line ArrayDeclaration: a ref does not change, so the effect runs once whatever its dependencies.\n    [picture],\n  );\n  return fitted;\n}\n\n/** What the pinch reads as it happens: the scale drawn, how far it can go, and how to set it. */\ninterface Zoom {\n  scale: number;\n  max: number;\n  onScale: (scale: number) => void;\n}\n\n/**\n * A pinch on the figure: the fingers set the scale and hold the point between them still. Its\n * moves are the pinch's alone, so the carousel does not also turn the page (a non-passive\n * listener). `zoomTo` sets the scale, keeping the point at (x, y) still.\n */\nfunction usePinch(figure: RefObject<HTMLElement | null>, latest: RefObject<Zoom>, zoomTo: RefObject<(scale: number, x: number, y: number) => void>): void {\n  useEffect(\n    () => {\n      const node = figure.current!;\n      // The scale the pinch last set, kept here: a lift can come before React has drawn it.\n      let pinch: { distance: number; scale: number; last: number } | undefined;\n      const spread = (touches: TouchList) => Math.hypot(touches[0]!.clientX - touches[1]!.clientX, touches[0]!.clientY - touches[1]!.clientY);\n      const onStart = (event: TouchEvent) => {\n        // Stryker disable next-line EqualityOperator: no layout draws an image at exactly minZoom of its fitted size, so > and >= agree.\n        if (event.touches.length === 2 && latest.current.max > minZoom) pinch = { distance: spread(event.touches), scale: latest.current.scale, last: latest.current.scale };\n      };\n      const onMove = (event: TouchEvent) => {\n        if (!pinch || event.touches.length !== 2) return;\n        event.preventDefault();\n        const next = Math.min(latest.current.max, Math.max(1, (pinch.scale * spread(event.touches)) / pinch.distance));\n        pinch.last = next;\n        const [a, b] = [event.touches[0]!, event.touches[1]!];\n        zoomTo.current(next, (a.clientX + b.clientX) / 2, (a.clientY + b.clientY) / 2);\n      };\n      const onEnd = (event: TouchEvent) => {\n        if (!pinch || event.touches.length > 1) return;\n        // A pinch that ends nearly fitted settles fitted.\n        // Stryker disable next-line EqualityOperator: no pinch ends at exactly minZoom, so < and <= agree.\n        if (pinch.last < minZoom) latest.current.onScale(1);\n        pinch = undefined;\n      };\n      // Stryker disable next-line ObjectLiteral,BooleanLiteral: onStart never takes the default, so passive only spares the browser a wait.\n      node.addEventListener(\"touchstart\", onStart, { passive: true });\n      // Stryker disable next-line ObjectLiteral: an element's touchmove listener is not passive unless asked; this says so.\n      node.addEventListener(\"touchmove\", onMove, { passive: false });\n      node.addEventListener(\"touchend\", onEnd);\n      node.addEventListener(\"touchcancel\", onEnd);\n      return () => {\n        node.removeEventListener(\"touchstart\", onStart);\n        node.removeEventListener(\"touchmove\", onMove);\n        node.removeEventListener(\"touchend\", onEnd);\n        node.removeEventListener(\"touchcancel\", onEnd);\n      };\n    },\n    // Stryker disable next-line ArrayDeclaration: refs do not change, so the effect runs once whatever its dependencies.\n    [figure, latest, zoomTo],\n  );\n}\n\n/**\n * A double-tap, or a double-click: a short press soon after another, close to where it was. Returns\n * the pointer handlers for the element, which call `onDoubleTap` with the second press's point.\n */\nfunction useDoubleTap(onDoubleTap: (x: number, y: number) => void): Pick<HTMLAttributes<HTMLElement>, \"onPointerDown\" | \"onPointerUp\"> {\n  const pressed = useRef<{ x: number; y: number } | undefined>(undefined);\n  const lastTap = useRef<{ time: number; x: number; y: number } | undefined>(undefined);\n  const onPointerDown = (event: PointerEvent<HTMLElement>) => {\n    pressed.current = { x: event.clientX, y: event.clientY };\n    // A second finger is a pinch, not a tap.\n    if (!event.isPrimary) lastTap.current = undefined;\n  };\n  const onPointerUp = (event: PointerEvent<HTMLElement>) => {\n    const start = pressed.current;\n    pressed.current = undefined;\n    const previous = lastTap.current;\n    lastTap.current = undefined;\n    if (!start || !event.isPrimary || Math.hypot(event.clientX - start.x, event.clientY - start.y) > tapSlop) return;\n    if (\n      !previous ||\n      // Stryker disable next-line EqualityOperator: a test cannot time a press to the millisecond, and no person can tell one apart.\n      event.timeStamp - previous.time > doubleTapTime ||\n      Math.hypot(event.clientX - previous.x, event.clientY - previous.y) > tapSlop\n    ) {\n      lastTap.current = { time: event.timeStamp, x: event.clientX, y: event.clientY };\n      return;\n    }\n    onDoubleTap(event.clientX, event.clientY);\n  };\n  return { onPointerDown, onPointerUp };\n}\n\n/**\n * One image and its caption. Zoomed, the image is drawn larger in a scroller over the slide, so a\n * finger, a trackpad or the arrow keys move around it, and a swipe there pans instead of turning\n * the page. A double-tap zooms to the image's own size at the tap and back; a pinch zooms it too.\n */\nfunction LightboxFigure({ image, scale, onScale, onMaxScale, zoomLabel, priority }: FigureProps): JSX.Element {\n  const figure = useRef<HTMLElement>(null);\n  const picture = useRef<HTMLImageElement>(null);\n  const view = useRef<HTMLDivElement>(null);\n  const fitted = useFittedSize(picture);\n  // Never larger than the image's own size: a small image does not zoom at all.\n  // Stryker disable next-line ConditionalExpression,EqualityOperator: unmeasured, 0 / 0 makes max NaN, which zooms nothing, as 1 does.\n  const max = fitted.width > 0 ? Math.max(1, fitted.natural / fitted.width) : 1;\n  const zoomed = scale > 1;\n  // The point of the image to keep under the finger as the scale changes: a fraction of the\n  // image (fx, fy) and where it sits in the figure (px, py).\n  const focal = useRef<{ fx: number; fy: number; px: number; py: number } | null>(null);\n  // Stryker disable next-line ObjectLiteral: the layout effect below fills it before anything reads it.\n  const latest = useRef({ scale, max, onScale, onMaxScale });\n  useLayoutEffect(() => {\n    latest.current = { scale, max, onScale, onMaxScale };\n  });\n\n  const zoomTo = (next: number, x: number, y: number) => {\n    const box = figure.current!.getBoundingClientRect();\n    const drawn = (latest.current.scale > 1 ? view.current!.firstElementChild! : picture.current!).getBoundingClientRect();\n    // A point off the picture ends up off it too; the scroller's own bounds hold the edge.\n    focal.current = { fx: (x - drawn.left) / drawn.width, fy: (y - drawn.top) / drawn.height, px: x - box.left, py: y - box.top };\n    latest.current.onScale(next);\n  };\n  // For the pinch's listeners: zoomTo reads only refs, so the first is as good as any.\n  const zoomAt = useRef(zoomTo);\n  usePinch(figure, latest, zoomAt);\n  const taps = useDoubleTap((x, y) => {\n    if (zoomed) {\n      onScale(1);\n      return;\n    }\n    // Stryker disable next-line EqualityOperator: no layout draws an image at exactly minZoom of its fitted size, so > and >= agree.\n    if (max > minZoom) zoomTo(max, x, y);\n  });\n\n  useEffect(() => {\n    latest.current.onMaxScale(max);\n  }, [max]);\n\n  // After a zoom, scroll so the focal point is where it was, or to the middle.\n  useLayoutEffect(() => {\n    const point = focal.current;\n    focal.current = null;\n    if (!zoomed) return;\n    const scroller = view.current!;\n    const drawn = scroller.firstElementChild as HTMLElement;\n    const { fx, fy, px, py } = point ?? { fx: 0.5, fy: 0.5, px: scroller.clientWidth / 2, py: scroller.clientHeight / 2 };\n    scroller.scrollLeft = drawn.offsetLeft + fx * drawn.offsetWidth - px;\n    scroller.scrollTop = drawn.offsetTop + fy * drawn.offsetHeight - py;\n  }, [scale, zoomed]);\n\n  return (\n    <figure\n      ref={figure}\n      data-ouro-lightbox-figure=\"\"\n      data-zoomed={zoomed ? \"\" : undefined}\n      className={figureClass}\n      {...taps}\n    >\n      <img ref={picture} src={image.src} alt={image.alt} decoding=\"async\" fetchPriority={priority} data-ouro-lightbox-image=\"\" className={cn(imageClass, zoomed && \"invisible\")} />\n      {/* Zoomed, the image covers the caption, so the caption steps aside until it is fitted again. */}\n      {(image.title !== undefined || image.caption !== undefined) && (\n        <figcaption className={cn(captionClass, zoomed && \"invisible\")}>\n          {image.title !== undefined && <span className=\"font-medium text-foreground\">{image.title}</span>}\n          {image.caption !== undefined && <span>{image.caption}</span>}\n        </figcaption>\n      )}\n      {zoomed && (\n        <div\n          ref={view}\n          role=\"group\"\n          aria-label={zoomLabel}\n          tabIndex={0}\n          data-ouro-lightbox-zoom-view=\"\"\n          data-ouro-control=\"lightbox\"\n          data-ouro-part=\"zoom-view\"\n          className={zoomViewClass}\n        >\n          <img\n            src={image.src}\n            alt={image.alt}\n            className={zoomedImageClass}\n            style={{ width: fitted.width * scale, height: fitted.height * scale }}\n          />\n        </div>\n      )}\n    </figure>\n  );\n}\n\n/**\n * How soon the viewer fetches an image: the one shown first, then the ones a step either side\n * (around the ends with `loop`), at the browser's own priority, then the rest.\n */\nfunction priorityOf(position: number, shown: number, total: number, loop: boolean): \"high\" | \"low\" | undefined {\n  const away = Math.abs(position - shown);\n  const steps = loop ? Math.min(away, total - away) : away;\n  return steps === 0 ? \"high\" : steps > 1 ? \"low\" : undefined;\n}\n\n/** Starts fetching an image before it is drawn, as a thumbnail is pressed, so the viewer opens on it sooner. */\nfunction warm(src: string): void {\n  new Image().src = src;\n}\n\n/** How far a finger may move between press and release and still be a tap, not a scroll, in CSS pixels. */\nconst TAP_SLOP = 10;\n\n/**\n * The viewer's contents. It mounts when the viewer opens, so it starts on the image chosen; an\n * index the app changes while it is open starts the carousel again on that image.\n */\nfunction LightboxViewer({\n  label,\n  images,\n  loop,\n  index,\n  onIndexChange,\n  nameId,\n  closeLabel,\n  previousLabel,\n  nextLabel,\n  positionLabel,\n  originalLabel,\n  zoomLabel,\n  shownRef,\n  chooseRef,\n}: ViewerProps): JSX.Element {\n  const [start, setStart] = useState(index);\n  const [current, setCurrent] = useState(index);\n  // The image a key or button chose, shown in the position at once while the scroll gets there.\n  const [target, setTarget] = useState<number | null>(null);\n  const [requested, setRequested] = useState(index);\n  const [run, setRun] = useState(0);\n  // Only a change to `index` moves the viewer, so an app that does not follow onIndexChange\n  // leaves the user where they went.\n  if (index !== requested) {\n    setRequested(index);\n    if (index !== current) {\n      setStart(index);\n      setCurrent(index);\n      setTarget(null);\n      setRun(run + 1);\n    }\n  }\n  const header = useRef<HTMLDivElement>(null);\n  // Starting the carousel again takes away the scroller that had focus: give it to the new one.\n  useLayoutEffect(() => {\n    const viewer = header.current!.parentElement!;\n    if (run > 0 && !viewer.contains(document.activeElement)) viewer.querySelector<HTMLElement>(\"[data-ouro-carousel-viewport]\")!.focus();\n  }, [run]);\n  const total = images.length;\n  // The app may remove images while the viewer is open.\n  const shown = Math.min(current, total - 1);\n  useLayoutEffect(() => {\n    shownRef.current = shown;\n  });\n  useLayoutEffect(\n    () => {\n      chooseRef.current = setTarget;\n    },\n    // Stryker disable next-line ArrayDeclaration: chooseRef is the same object for the viewer's life, so it runs once either way.\n    [chooseRef],\n  );\n  // The position names the image chosen; the carousel announces it once the image has arrived.\n  const chosen = target === null ? shown : Math.min(target, total - 1);\n  const href = images[shown]?.href;\n  // Only the image in view is zoomed, and moving to another image draws it fitted again.\n  const [zoom, setZoom] = useState<{ index: number; scale: number } | null>(null);\n  const [maxima, setMaxima] = useState<Readonly<Record<number, number>>>({});\n  const scale = zoom?.index === shown ? zoom.scale : 1;\n  // Stryker disable next-line EqualityOperator: no layout draws an image at exactly minZoom of its fitted size, so > and >= agree.\n  const zoomable = (maxima[shown] ?? 1) > minZoom;\n  return (\n    <>\n      <div ref={header} data-ouro-lightbox-header=\"\" className={headerClass}>\n        <div className={titleClass}>\n          <DialogTitle>{label}</DialogTitle>\n          {/* The viewer's name: the label and the position, which the header shows apart. One image\n              has no position worth naming. */}\n          <span id={nameId} hidden>\n            {total > 1 ? `${label}, ${fillTemplate(positionLabel, chosen + 1, total)}` : label}\n          </span>\n        </div>\n        {total > 1 && (\n          <span data-ouro-lightbox-position=\"\" data-pending={chosen !== shown ? \"\" : undefined} className={counterClass}>\n            {fillTemplate(positionLabel, chosen + 1, total)}\n          </span>\n        )}\n        {href !== undefined && (\n          <Button\n            href={href}\n            target=\"_blank\"\n            reloadDocument\n            variant=\"outline\"\n            tone=\"secondary\"\n            size=\"sm\"\n            data-ouro-control=\"lightbox\"\n            data-ouro-part=\"original\"\n            startIcon={ExternalIcon}\n          >\n            {/* Below 640px only the icon shows; the text still names the link. */}\n            <span className=\"max-sm:sr-only\">{originalLabel}</span>\n          </Button>\n        )}\n        {zoomable && (\n          <Button\n            variant=\"outline\"\n            tone=\"secondary\"\n            size=\"sm\"\n            aria-label={zoomLabel}\n            aria-pressed={scale > 1}\n            data-ouro-control=\"lightbox\"\n            data-ouro-part=\"zoom\"\n            onClick={() => setZoom({ index: shown, scale: scale > 1 ? 1 : maxima[shown]! })}\n          >\n            <ZoomIcon out={scale > 1} />\n          </Button>\n        )}\n        <DialogClose\n          render={\n            <Button\n              variant=\"outline\"\n              tone=\"secondary\"\n              size=\"sm\"\n              aria-label={closeLabel}\n              data-ouro-control=\"lightbox\"\n              data-ouro-part=\"close\"\n            >\n              <CloseIcon />\n            </Button>\n          }\n        />\n      </div>\n      <Carousel\n        key={run}\n        label={label}\n        loop={loop}\n        defaultIndex={start}\n        onIndexChange={(next) => {\n          setCurrent(next);\n          setZoom(null);\n          onIndexChange?.(next);\n        }}\n        onTargetChange={setTarget}\n        previousLabel={previousLabel}\n        nextLabel={nextLabel}\n        slideLabel={positionLabel}\n        className={stageClass}\n      >\n        {images.map((image, position) => (\n          <LightboxFigure\n            key={position}\n            image={image}\n            scale={position === shown ? scale : 1}\n            onScale={(next) => setZoom({ index: position, scale: next })}\n            onMaxScale={(max) => setMaxima((list) => ({ ...list, [position]: max }))}\n            zoomLabel={zoomLabel}\n            priority={priorityOf(position, shown, total, loop)}\n          />\n        ))}\n      </Carousel>\n    </>\n  );\n}\n\n/**\n * Thumbnails that open a full-screen image viewer. Use it for proof screenshots, a listing's\n * photos or before-and-after pairs: pressing a thumbnail opens the viewer on that image. It shows\n * the image as large as the screen allows, uncropped, with its title and caption under it and\n * Close beside the position (\"2 of 4\") at its top. Step through the images with the arrow keys,\n * the Previous and Next buttons, a trackpad or a swipe, and go to the first or the last with Home\n * or End. The position changes as soon as a key or button chooses an image, and is announced\n * politely, once, when the image arrives. With one image the viewer shows neither\n * the position nor Previous and Next. Escape, Close or a press outside closes it, and focus goes\n * to the thumbnail of the image last shown. The viewer grows from the thumbnail pressed and\n * slides between images; with reduced motion it fades and jumps instead. The thumbnails are\n * fetched as they are drawn, not as they near the screen, so pictures below the fold are there\n * when the reader scrolls to them. Pressing a thumbnail starts fetching its full image before the\n * viewer opens (a finger's or pen's tap, as it lifts without having moved, so a scroll that starts\n * on a thumbnail fetches nothing), and the viewer fetches the image shown first, then the ones a\n * step either side, then the rest.\n * On a phone it runs edge to edge, and an image drawn smaller than its own size zooms to that\n * size with a double-tap or the zoom button, or as far as two fingers pinch it; zoomed, a swipe\n * moves around the image rather than to the next one.\n *\n * For a chat message's pictures, pass `layout=\"mosaic\"`: one frame that shows one picture at its\n * own shape, two side by side, three as one large and two small, and four or more as a 2 by 2\n * grid with \"+N\" on the last, at most 25rem wide and 17.5rem tall. Pass `fullScreen` for a viewer\n * that covers the whole screen with no frame. An animated image's `still` frame shows in its thumbnail when the user asks for reduced\n * motion.\n *\n * To open the viewer from thumbnails you lay out yourself (a before-and-after pair, a mark on a\n * map), pass `open` with `onOpenChange`, the image as `index`, and follow the user with\n * `onIndexChange`: it then draws no thumbnails, and focus goes back to whatever had it, or to\n * the element `returnFocus` gives for the image last shown, such as its thumbnail.\n *\n * Use `Carousel` instead to show the images in the page one at a time, and `Dialog`\n * when the viewer holds more than images.\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/lightbox\n *\n * @example\n * <Lightbox\n *   label=\"Kitchen photos\"\n *   images={[\n *     { src: \"/photos/before.jpg\", alt: \"The old kitchen, with dark cabinets\", title: \"Before\" },\n *     { src: \"/photos/after.jpg\", alt: \"The new kitchen, with white cabinets\", title: \"After\", caption: \"Six weeks later\" },\n *   ]}\n * />\n * <Lightbox\n *   label=\"Kitchen photos\"\n *   images={photos}\n *   open={open}\n *   index={index}\n *   onOpenChange={setOpen}\n *   onIndexChange={setIndex}\n * />\n * @claim \"so a scroll that starts on a\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox fetching > waits for a finger or pen to lift without moving, so a scroll that starts on a thumbnail fetches nothing)\n * @claim \"Pressing a thumbnail starts fetching its\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox fetching > starts fetching the full image as its thumbnail is pressed, before the viewer opens)\n * @claim \"the viewer fetches the image shown first\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox fetching > fetches the image shown first, then the ones a step either side, then the rest)\n * @claim \"The thumbnails are fetched as they\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox thumbnails > is a named list of thumbnail buttons, each named by its image and opening a dialog, fetched as they are drawn)\n * @claim \"Step through the images with the\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox navigation > steps with the arrow keys from anywhere in the viewer, in reading order)\n * @claim \"Step through the images with the\" registry/ouro/components/ouro/lightbox/lightbox.touch.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.touch.test.tsx::Lightbox on a touch screen > moves to the next image with a swipe)\n * @claim \"politely, once, when the image arrives\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > shows the position and announces it once when it changes)\n * @claim \"The position changes as soon as\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > shows the position a key or button chose before the scroll gets there, and announces it once it does)\n * @claim \"Step through the images with the\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox navigation > goes to the first and the last image with Home and End)\n * @claim \"focus goes to the thumbnail of\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox opening and closing > closes with Escape and gives focus to the thumbnail of the image last shown)\n * @claim \"it then draws no thumbnails, and\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > gives focus to what returnFocus gives for the image last shown, or else back to what had it)\n * @claim \"With one image the viewer shows\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox viewer > shows no position, Previous or Next for one image)\n * @claim \"it then draws no thumbnails, and\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > draws no thumbnails, and opens on index when open)\n * @claim \"it then draws no thumbnails, and\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox controlled > gives focus back to what had it when the viewer opened, and grows from it)\n * @claim \"an image drawn smaller than its\" registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx::Lightbox zoom > zooms at a double-tap's point and back with another)\n * @claim \"an image drawn smaller than its\" registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx verify:fileLine(registry/ouro/components/ouro/lightbox/lightbox.zoom.test.tsx, /chromiumOnly\\(\\\"pinches\\sbetween\\sthe\\sfitted\\ssize\\sand\\sthe\\simage's\\sown\\ssize,\\sholding\\sthe\\spoint\\sbetween\\sthe\\sfingers\\\"/)\n * @claim \"zoomed, a swipe moves around the\" registry/ouro/components/ouro/lightbox/lightbox.touch.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.touch.test.tsx::Lightbox zoom on a touch screen > zooms with a real double-tap, and then pans with a swipe instead of turning the page)\n * @claim \"one frame that shows one picture\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws one picture at its own shape, between 3:4 and 3:1, and 4:3 when its size is unknown)\n * @claim \"two side by side, three as\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > draws two side by side, three as one large and two small, and four or more as a 2 by 2 grid)\n * @claim \"four or more as a 2 by\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > shows four of more pictures, the last saying how many more follow, to sight and to screen readers)\n * @claim \"at most 25rem wide and 17.5rem\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox mosaic > is at most 25rem wide and 17.5rem tall at its shape, never wider than its column, unless the app gives it another width)\n * @claim \"Pass `fullScreen` for a viewer\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox full screen > covers the whole screen with no frame, from the thumbnails or controlled)\n * @claim \"An animated image's `still` frame shows\" registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.mosaic.test.tsx::Lightbox still frames > shows an animated image's still frame in its thumbnail when the user asks for reduced motion)\n * @claim \"The viewer grows from the thumbnail\" registry/ouro/components/ouro/lightbox/lightbox.test.tsx verify:testExists(registry/ouro/components/ouro/lightbox/lightbox.test.tsx::Lightbox motion > grows from the thumbnail that opened it, and only fades with reduced motion)\n */\nexport function Lightbox(props: LightboxProps): JSX.Element {\n  const { motion } = useOuro();\n  const reduced = useReducedMotion();\n  const {\n    label,\n    images,\n    loop = false,\n    closeLabel = \"Close\",\n    previousLabel = \"Previous image\",\n    nextLabel = \"Next image\",\n    positionLabel = \"{n} of {total}\",\n    originalLabel = \"Open original\",\n    zoomLabel = \"Zoom\",\n    onIndexChange,\n    className,\n    open: openProp,\n    index: indexProp,\n    onOpenChange,\n    returnFocus,\n    fullScreen = false,\n    layout: layoutProp = \"grid\",\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    slides,\n    fullscreen,\n  } = props as LightboxBaseProps & {\n    layout?: string;\n    className?: string;\n    open?: boolean;\n    index?: number;\n    onOpenChange?: (open: boolean) => void;\n    returnFocus?: (index: number) => HTMLElement | null | undefined;\n  };\n  const controlled = openProp !== undefined;\n  const mountedOpen = useMountedOpen(openProp);\n  // A layout that is not one of Ouro UI's (a type error) warns and renders the grid.\n  const mosaic = layoutProp === \"mosaic\";\n\n  useAppearanceClassNameCheck(\n    \"Lightbox\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; Lightbox draws its own thumbnails`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Lightbox\",\n    process.env.NODE_ENV !== \"production\"\n      ? (): DevWarning[] => [\n          !label && [\n            \"label is required; it names the thumbnails and the viewer for screen readers\",\n            '<Lightbox label=\"Kitchen photos\" images={images}>',\n          ],\n          images.length === 0 && [\"there are no images\", '<Lightbox label=\"Kitchen photos\" images={[{ src: \"/photos/a.jpg\", alt: \"…\" }]}>'],\n          ...images.map(\n            (image, position): DevWarning =>\n              !image.alt && [\n                `images[${position}] has no alt; describe the image for screen readers`,\n                `{ src: \"${image.src}\", alt: \"The new kitchen, with white cabinets\" }`,\n              ],\n          ),\n          slides !== undefined && [\"slides is not a prop\", '<Lightbox label=\"Kitchen photos\" images={[{ src, alt }]}>'],\n          fullscreen !== undefined && [\"fullscreen is not a prop\", '<Lightbox label=\"Kitchen photos\" images={images} fullScreen>'],\n          layoutProp !== \"grid\" && layoutProp !== \"mosaic\" && [`layout=\"${String(layoutProp)}\" is not a layout; use \"grid\", \"mosaic\"`, '<Lightbox layout=\"mosaic\">'],\n          controlled &&\n            typeof onOpenChange !== \"function\" && [\n              \"open needs onOpenChange, which closes the viewer\",\n              '<Lightbox label=\"Kitchen photos\" images={images} open={open} index={index} onOpenChange={setOpen}>',\n            ],\n          !controlled &&\n            (indexProp !== undefined || onOpenChange !== undefined || returnFocus !== undefined) && [\n              \"index, onOpenChange and returnFocus need open; without it Lightbox draws its own thumbnails\",\n              '<Lightbox label=\"Kitchen photos\" images={images} open={open} index={index} onOpenChange={setOpen}>',\n            ],\n          mountedOpen && [\n            \"mounted already open, so the viewer's open and close transitions don't run; mount it closed and change open\",\n            '<Lightbox label=\"Kitchen photos\" images={images} open={open} index={index} onOpenChange={setOpen}>',\n          ],\n          controlled &&\n            className !== undefined && [\n              \"className lays out the thumbnails, and a Lightbox with open draws none\",\n              '<div className=\"…\"><Lightbox open={open} … /></div>',\n            ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const [ownOpen, setOwnOpen] = useState(false);\n  // The viewer's dialog mounts once someone may open it, on a thumbnail's first hover or focus, or as one is pressed,\n  // so a page of pictures mounts none until then. It opens only once it has mounted closed, so a thumbnail pressed with\n  // neither first (a click from a script) still runs the viewer's opening.\n  const [armed, setArmed] = useState(false);\n  const [ready, setReady] = useState(false);\n  const arm = () => setArmed(true);\n  useEffect(() => {\n    // eslint-disable-next-line react-hooks/set-state-in-effect\n    if (armed) setReady(true);\n  }, [armed]);\n  const [start, setStart] = useState(0);\n  const open = controlled ? openProp : ownOpen;\n  const setOpen = controlled ? (onOpenChange ?? (() => {})) : setOwnOpen;\n  // What had focus as the app opened the viewer, read before Base UI makes the page inert.\n  const [wasOpen, setWasOpen] = useState(open);\n  const [opener, setOpener] = useState<Element | null>(null);\n  // Stryker disable next-line ConditionalExpression: read again while open, the opener changes nothing, since the origin is set once per opening.\n  if (open !== wasOpen) {\n    setWasOpen(open);\n    // Stryker disable next-line ConditionalExpression: an opener read as it closes is read again before the next opening uses it.\n    if (open) setOpener(document.activeElement);\n  }\n  const nameId = useId();\n  // Stryker disable next-line ArrayDeclaration: each thumbnail's ref writes its own place before the viewer can read it.\n  const thumbnails = useRef<(HTMLButtonElement | null)[]>([]);\n  // Where a finger or pen came down on a thumbnail, until it lifts or a scroll takes it.\n  const tapFrom = useRef<{ x: number; y: number } | null>(null);\n  const popup = useRef<HTMLDivElement | null>(null);\n  const shown = useRef(0);\n  // The open viewer's way to show a position the keys chose (LightboxViewer sets it).\n  const choose = useRef<((index: number) => void) | null>(null);\n\n  const viewer = (\n    <DialogRoot open={open && (controlled || ready)} onOpenChange={(next) => setOpen(next)}>\n      <DialogPortal>\n        <DialogBackdrop />\n        <DialogViewport>\n          <DialogPopupUnchecked\n            ref={(node: HTMLDivElement | null) => {\n              popup.current = node;\n              // Once per opening: the viewer grows from its opener, the thumbnail pressed or, when\n              // controlled, what had focus (nothing when the page had none).\n              if (!node || node.style.transformOrigin) return;\n              const from = controlled ? opener : thumbnails.current[start]!;\n              if (from && from !== document.body) node.style.transformOrigin = zoomOrigin(from, node);\n            }}\n            size=\"lg\"\n            className={fullScreen ? cn(popupClass, fullScreenClass) : popupClass}\n            data-full-screen={fullScreen ? \"\" : undefined}\n            aria-labelledby={nameId}\n            initialFocus={() => popup.current!.querySelector<HTMLElement>(\"[data-ouro-carousel-viewport]\")}\n            // Focus goes to the thumbnail of the image last shown. Controlled, that is what\n            // returnFocus gives, or else (true) Base UI gives focus back to what had it when the\n            // viewer opened. A pressed thumbnail need not have had focus (Safari does not focus a\n            // pressed button). A mosaic shows four: an image past them returns to the last, \"+N\".\n            finalFocus={controlled ? () => returnFocus?.(shown.current) ?? true : () => thumbnails.current[mosaic ? Math.min(shown.current, 3) : shown.current]}\n            onKeyDown={(event) => stepWithKeys(event, choose.current!, reduced)}\n          >\n            <LightboxViewer\n              label={label}\n              images={images}\n              loop={loop}\n              index={controlled ? (indexProp ?? 0) : start}\n              onIndexChange={onIndexChange}\n              nameId={nameId}\n              closeLabel={closeLabel}\n              previousLabel={previousLabel}\n              nextLabel={nextLabel}\n              positionLabel={positionLabel}\n              originalLabel={originalLabel}\n              zoomLabel={zoomLabel}\n              shownRef={shown}\n              chooseRef={choose}\n            />\n          </DialogPopupUnchecked>\n        </DialogViewport>\n      </DialogPortal>\n    </DialogRoot>\n  );\n  if (controlled) return viewer;\n\n  const thumbnail = (image: LightboxImage, position: number, more = 0) => (\n    <button\n      ref={(node) => {\n        thumbnails.current[position] = node;\n      }}\n      type=\"button\"\n      aria-haspopup=\"dialog\"\n      data-ouro-control=\"lightbox\"\n      data-ouro-part=\"thumbnail\"\n      {...holdPageAtPress.dialog}\n      onPointerEnter={arm}\n      onFocus={arm}\n      onPointerDown={(event) => {\n        // A mouse's press starts the image's fetch, ahead of the click that opens the viewer. A\n        // finger or a pen may be starting a scroll, so it waits for a release that has not moved.\n        if (event.pointerType === \"touch\" || event.pointerType === \"pen\") tapFrom.current = { x: event.clientX, y: event.clientY };\n        else warm(image.src);\n        holdPageAtPress.dialog.onPointerDown(event);\n      }}\n      onPointerUp={(event) => {\n        const from = tapFrom.current;\n        tapFrom.current = null;\n        if (from && Math.hypot(event.clientX - from.x, event.clientY - from.y) <= TAP_SLOP) warm(image.src);\n      }}\n      onPointerCancel={() => {\n        // A scroll took the finger.\n        tapFrom.current = null;\n      }}\n      className={mosaic ? mosaicThumbnailClass : thumbnailClass}\n      onClick={() => {\n        setStart(position);\n        arm();\n        setOwnOpen(true);\n      }}\n    >\n      {/* With reduced motion an animated image's thumbnail shows its still frame: chosen by the browser under the device's setting, always under OuroProvider's motion=\"reduced\", never under \"full\". */}\n      <picture className=\"contents\">\n        {image.still !== undefined && motion !== \"full\" && <source media={motion === \"reduced\" ? \"all\" : \"(prefers-reduced-motion: reduce)\"} srcSet={image.still} />}\n        <img src={image.thumbnail ?? image.src} alt={image.alt} decoding=\"async\" className={mosaic ? mosaicImageClass : thumbnailImageClass} />\n      </picture>\n      {more > 0 && (\n        <>\n          <span aria-hidden=\"true\" data-ouro-lightbox-more=\"\" className={mosaicMoreClass}>{`+${more}`}</span>\n          <span className=\"sr-only\">{`, and ${more} more`}</span>\n        </>\n      )}\n    </button>\n  );\n\n  if (mosaic) {\n    // Four at most show; the viewer steps through the rest from the last, which says how many follow.\n    const tiles = images.slice(0, 4);\n    const more = images.length - tiles.length;\n    const shape = mosaicLayout(tiles.length, images[0]?.width, images[0]?.height);\n    return (\n      <div data-ouro=\"lightbox\" data-layout=\"mosaic\" className={cn(mosaicFrameClass, className)} style={{ \"--ouro-lightbox-ratio\": shape.ratio } as CSSProperties}>\n        <ul role=\"list\" aria-label={label} className={cn(mosaicClass, shape.grid)} style={{ aspectRatio: shape.ratio }}>\n          {tiles.map((image, position) => (\n            <li key={position} className={mosaicCellClass}>\n              {thumbnail(image, position, position === tiles.length - 1 ? more : 0)}\n            </li>\n          ))}\n        </ul>\n        {armed && viewer}\n      </div>\n    );\n  }\n\n  return (\n    <div data-ouro=\"lightbox\" className={cn(\"min-w-0\", className)}>\n      <ul role=\"list\" aria-label={label} className={gridClass}>\n        {images.map((image, position) => (\n          <li key={position} className=\"m-0 p-0\">\n            {thumbnail(image, position)}\n          </li>\n        ))}\n      </ul>\n      {armed && viewer}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/lightbox/lightbox.tsx"
    }
  ],
  "docs": "Thumbnails that open a full-screen image viewer. Import: import { Lightbox } from \"@/components/ouro/lightbox/lightbox\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, carousel, dialog, sheet, 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/lightbox.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}