{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "skeleton",
  "title": "Skeleton",
  "description": "A placeholder that breathes after a second in the shape and size of content that is still loading, so the content takes its place without moving anything.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/skeleton/skeleton.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport type { HTMLAttributes, JSX, Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** Avatar's sizes, for `<Skeleton shape=\"circle\" size>`. */\nexport type SkeletonAvatarSize = \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\" | \"3xl\";\n\n/** Skeleton's layout props, ref and hint props, whatever its shape. */\ninterface SkeletonCommonProps {\n  /** Layout only: size, margins and placement (`h-32`, `w-1/2`). The color and corners come from the theme and `shape`. */\n  className?: string | undefined;\n  ref?: Ref<HTMLSpanElement> | undefined;\n  /**\n   * Whether the placeholder breathes once it has been loading for a second. `false` draws it still, as reduced motion does.\n   * Only the first placeholders mounted at once breathe; the rest of a long list hold still, which keeps WebKit's wheel scrolling smooth.\n   * Choose it for a long list of pictures loading at once, where animating each may slow scrolling.\n   * @default true\n   */\n  shimmer?: boolean | undefined;\n\n  /** Not a prop. Ouro UI uses `shape`: `<Skeleton shape=\"circle\">`. */\n  variant?: { 'Use <Skeleton shape=\"circle\">': never };\n  /** Not a prop. Skeleton breathes, and holds still with reduced motion. */\n  animation?: { 'Not a prop: Skeleton breathes, and holds still with reduced motion': never };\n  /** Not a prop. Size it with a layout class: `<Skeleton className=\"w-32\">`. */\n  width?: { 'Use <Skeleton className=\"w-32\">': never };\n  /** Not a prop. Size it with a layout class, or give `shape=\"text\"` its `lines`: `<Skeleton className=\"h-6\">`. */\n  height?: { 'Use <Skeleton className=\"h-6\">, or <Skeleton shape=\"text\" lines={3}>': never };\n}\n\n/** A block, such as an image or a chart: `<Skeleton className=\"h-32\" />`. */\nexport interface SkeletonRectShape {\n  /**\n   * The outline of what is loading: `rect` (a block), `text` (lines), `circle` (an avatar), `row` (a list row) or `card`.\n   * @default \"rect\"\n   */\n  shape?: \"rect\" | undefined;\n  /** Only with `shape=\"text\"`, `\"circle\"`, `\"row\"` or `\"card\"`. Size a block with a layout class. */\n  size?: never;\n  /** Only with `shape=\"text\"`. */\n  lines?: never;\n  /** Only with `shape=\"row\"` or `\"card\"`. */\n  count?: never;\n}\n\n/** Lines of text: `<Skeleton shape=\"text\" size=\"sm\" lines={3} />`. */\nexport interface SkeletonTextShape {\n  /** The outline of what is loading: `rect` (a block), `text` (lines), `circle` (an avatar), `row` (a list row) or `card`. */\n  shape: \"text\";\n  /**\n   * Text's size, so each line is one line box of that text. Leave it out to inherit the surrounding text's size.\n   * @claim \"Text's size, so each line is one line box\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > takes the space of the text it stands in for at each of Text's sizes, the last of several lines shorter)\n   */\n  size?: \"sm\" | \"md\" | \"lg\" | (string & { 'Use \"sm\", \"md\" or \"lg\", Text\\'s sizes': never }) | undefined;\n  /**\n   * How many lines of text it stands in for; the last of several is shorter, like a paragraph's.\n   * @default 1\n   */\n  lines?: number | undefined;\n  /** Only with `shape=\"row\"` or `\"card\"`. For several lines use `lines`. */\n  count?: never;\n}\n\n/** An avatar: `<Skeleton shape=\"circle\" size=\"lg\" />`. */\nexport interface SkeletonCircleShape {\n  /** The outline of what is loading: `rect` (a block), `text` (lines), `circle` (an avatar), `row` (a list row) or `card`. */\n  shape: \"circle\";\n  /**\n   * Avatar's size, so it is the avatar's exact box. A layout class (`size-12`) sizes it instead.\n   * @default \"md\"\n   */\n  size?: SkeletonAvatarSize | (string & { 'Use Avatar\\'s sizes: \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\" or \"3xl\"': never }) | undefined;\n  /** Only with `shape=\"text\"`. */\n  lines?: never;\n  /** Only with `shape=\"row\"` or `\"card\"`. */\n  count?: never;\n}\n\n/** List rows or Cards: `<Skeleton shape=\"row\" count={6} />`. */\nexport interface SkeletonRowOrCardShape {\n  /** The outline of what is loading: `rect` (a block), `text` (lines), `circle` (an avatar), `row` (a list row) or `card`. */\n  shape: \"row\" | \"card\";\n  /**\n   * Item's or Card's size, so each placeholder is that component's exact height.\n   * @claim \"Item's or Card's size, so each placeholder\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > is the exact height of an Item row and an outline Card, at each size, so nothing moves when they arrive)\n   * @default \"md\"\n   */\n  size?: \"sm\" | \"md\" | (string & { 'Use \"sm\" or \"md\", Item\\'s and Card\\'s sizes': never }) | undefined;\n  /**\n   * How many rows or cards to show. Each is its own element, so they sit in the grid or the\n   * `div` the content will fill (not directly in a `ul`: the rows are `span`s with `display: grid`).\n   * @claim \"Each is its own element, so they sit\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > repeats rows and cards count times, each its own element, with the ref and the id on the first)\n   * @default 1\n   */\n  count?: number | undefined;\n  /** Only with `shape=\"text\"`. */\n  lines?: never;\n}\n\n/**\n * The outline of what is loading, and the sizes that make it take the content's exact space.\n * `rect` is a block (an image, a chart); `text` is lines of text, each one line box tall in\n * Text's `size`; `circle` is an avatar at Avatar's `size`; `row` is a list row the height of\n * an Item with a title, a description and 40px media; `card` is an outline Card with a title,\n * a description and two lines of body text. `row` and `card` repeat `count` times.\n * @claim \"`rect` is a block (an image, a chart)\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > is the exact height of an Item row and an outline Card, at each size, so nothing moves when they arrive)\n * @claim \"`rect` is a block (an image, a chart)\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > takes the space of the text it stands in for at each of Text's sizes, the last of several lines shorter)\n * @claim \"`rect` is a block (an image, a chart)\" registry/ouro/components/ouro/skeleton/skeleton.test.tsx verify:testExists(registry/ouro/components/ouro/skeleton/skeleton.test.tsx::Skeleton > is the exact box of an Avatar at each of its sizes)\n */\nexport type SkeletonShapeProps = SkeletonRectShape | SkeletonTextShape | SkeletonCircleShape | SkeletonRowOrCardShape;\n\n/** The props Skeleton adds to the `<span>` attributes it passes through. */\nexport type SkeletonOwnProps = SkeletonCommonProps & SkeletonShapeProps;\n\n/** The `<span>` attributes Skeleton passes through, and its props shared by the shapes. */\ntype SkeletonBaseProps = Omit<HTMLAttributes<HTMLSpanElement>, keyof SkeletonCommonProps | \"shape\" | \"size\" | \"lines\" | \"count\" | \"children\"> &\n  SkeletonCommonProps;\n/** Skeleton's props for a block. */\nexport type SkeletonRectProps = SkeletonBaseProps & SkeletonRectShape;\n/** Skeleton's props for lines of text. */\nexport type SkeletonTextProps = SkeletonBaseProps & SkeletonTextShape;\n/** Skeleton's props for an avatar. */\nexport type SkeletonCircleProps = SkeletonBaseProps & SkeletonCircleShape;\n/** Skeleton's props for list rows or Cards. */\nexport type SkeletonRowOrCardProps = SkeletonBaseProps & SkeletonRowOrCardShape;\n\n/** Props for {@link Skeleton}: its own props and the `<span>` attributes it passes through, by shape. */\nexport type SkeletonProps = SkeletonRectProps | SkeletonTextProps | SkeletonCircleProps | SkeletonRowOrCardProps;\n\n// Class strings are literal so the app's Tailwind finds them when it compiles. The placeholder holds still for its\n// first second, since most loads end sooner, then breathes: its opacity eases down and back, so the loop has no seam.\n// Opacity runs on the compositor and nothing repaints. With reduced motion it holds still.\nconst fill =\n  \"relative block overflow-hidden bg-muted \" +\n  \"animate-[ouro-skeleton-breathe_2.4s_ease-in-out_1s_infinite] motion-reduce:animate-none \" +\n  // Forced colours paint the fill as the page's own Canvas, so an outline in the text colour keeps the shape.\n  \"forced-colors:outline forced-colors:outline-1 forced-colors:-outline-offset-1 forced-colors:outline-[CanvasText]\";\n\n// `shimmer={false}`: no breathing at all.\nconst still = \"animate-none\";\n\n// WebKit drops wheel-scroll frames once a hundred or so placeholders animate at once, each its own compositing layer.\n// So only the first few mounted placeholders breathe; the rest hold still. A short list still shows life, and a long\n// one costs nothing. A placeholder that goes away hands its place to the next one that mounts.\nconst breatheLimit = 24;\nlet breathing = 0;\n\nfunction useBreathes(shimmer: boolean): boolean {\n  const [breathes, setBreathes] = useState(true);\n  useEffect(() => {\n    if (!shimmer) return;\n    const place = breathing < breatheLimit;\n    breathing += place ? 1 : 0;\n    // Claiming a place is shared module state, so it can only be read once mounted.\n    // eslint-disable-next-line react-hooks/set-state-in-effect\n    setBreathes(place);\n    return () => {\n      breathing -= place ? 1 : 0;\n    };\n  }, [shimmer]);\n  return shimmer && breathes;\n}\n\nconst shapes = {\n  rect: \"h-4 w-full rounded-ouro-md\",\n  circle: \"aspect-square rounded-full\",\n} as const;\n\nconst avatarSizes = { xs: \"w-6\", sm: \"w-8\", md: \"w-10\", lg: \"w-12\", xl: \"w-16\", \"2xl\": \"w-18\", \"3xl\": \"w-28\" } as const;\nconst textSizes = { sm: \"text-sm\", md: \"text-base\", lg: \"text-lg\" } as const;\n\n// A line is one line box of its text (`1lh`), with a bar the height of the letters in the middle,\n// so the text that replaces it takes the same space.\nconst line = \"flex h-[1lh] items-center\";\nconst bar = \"h-[0.75em] rounded-ouro-sm\";\n\n// Item's row (item.tsx): a 40px media lined up with the title, a medium title and a small description.\nconst rowSizes = { md: \"py-3\", sm: \"py-2\" } as const;\n// Card's outline frame (card.tsx): its gap, padding and the heading's size.\nconst cardSizes = {\n  md: { root: \"gap-6 py-6\", pad: \"px-6\", title: \"text-lg\" },\n  sm: { root: \"gap-4 py-4\", pad: \"px-4\", title: \"text-base\" },\n} as const;\n\n// Widths that vary from row to row, the same on the server and in the browser.\nconst titleWidths = [\"w-2/3\", \"w-1/2\", \"w-3/4\", \"w-1/3\", \"w-1/2\"] as const;\nconst detailWidths = [\"w-full\", \"w-3/4\", \"w-full\", \"w-2/3\", \"w-3/4\"] as const;\n\ntype Shape = \"rect\" | \"text\" | \"circle\" | \"row\" | \"card\";\nconst sizesFor = { rect: {}, text: textSizes, circle: avatarSizes, row: rowSizes, card: cardSizes } as const;\nconst shapeNames = Object.keys(sizesFor);\n\nconst muiVariants: Readonly<Record<string, Shape>> = { circular: \"circle\", text: \"text\", rectangular: \"rect\", rounded: \"rect\" };\n\nfunction skeletonHint(token: string): string {\n  if (token.startsWith(\"rounded\")) return token === \"rounded-full\" ? 'shape=\"circle\"' : 'shape=\"rect\"';\n  return \"remove it; Skeleton takes its color from the theme's --muted\";\n}\n\n/** The class for a guessed `width` or `height` value, for a development message. */\nfunction sizeClass(prefix: \"w\" | \"h\", value: unknown): string {\n  return `${prefix}-[${typeof value === \"number\" ? `${value}px` : String(value)}]`;\n}\n\n/** A whole number of at least one, or one. */\nfunction atLeastOne(value: number | undefined): number {\n  return Math.max(1, Number.isInteger(value) ? (value as number) : 1);\n}\n\nfunction Bar({ className, shimmer }: { className: string | undefined; shimmer: boolean }): JSX.Element {\n  return <span className={cn(fill, !shimmer && still, bar, className)} />;\n}\n\n/**\n * A placeholder that breathes after a second in the shape and size of content that is still loading, so the\n * content takes its place without moving anything. Screen readers skip it, so mark the region\n * that is loading with `aria-busy` while it shows. With reduced motion, or `shimmer={false}`, it holds still.\n *\n * Pick the shape of what is coming: `shape=\"text\"` with `lines` and Text's `size` for a\n * paragraph, `shape=\"circle\"` with Avatar's `size` for an avatar, `shape=\"row\"` with `count`\n * for a list of Items, `shape=\"card\"` for Cards, and `rect` sized with a layout class for an\n * image or a chart. A placeholder stands in for content; a spinner does not, so an app shows\n * a Skeleton wherever content loads.\n *\n * Use `Button`'s `loading` instead for an action in progress, and `Progress` when you know how\n * far along the work is.\n *\n * @group Display\n * @see https://ui.ouroboros.bot/docs/skeleton\n *\n * @example\n * <>\n *   <div aria-busy=\"true\" aria-label=\"Messages\" role=\"group\">\n *     <Skeleton shape=\"row\" count={6} />\n *   </div>\n *   <Skeleton shape=\"text\" size=\"sm\" lines={3} />\n *   <Skeleton shape=\"circle\" size=\"lg\" />\n * </>\n */\nexport function Skeleton(props: SkeletonProps): JSX.Element {\n  const { shape: shapeProp = \"rect\", size: sizeProp, lines: linesProp, count: countProp, className, shimmer: shimmerProp = true, variant, animation, width, height, ref, ...rest } =\n    props as SkeletonCommonProps &\n      Omit<HTMLAttributes<HTMLSpanElement>, \"children\"> & { shape?: string; size?: string; lines?: number; count?: number };\n  const shimmer = useBreathes(shimmerProp);\n  // A shape that is not one of Ouro UI's (a type error) warns and renders the default.\n  const shape: Shape = shapeNames.includes(shapeProp) ? (shapeProp as Shape) : \"rect\";\n  const sizes: object = sizesFor[shape];\n  const sizeKnown = sizeProp === undefined || Object.hasOwn(sizes, sizeProp);\n  const size = sizeKnown ? sizeProp : undefined;\n  useAppearanceClassNameCheck(\n    \"Skeleton\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? skeletonHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Skeleton\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          shape !== shapeProp && [\n            `shape=\"${shapeProp}\" is not a shape; use \"rect\", \"text\", \"circle\", \"row\", \"card\"`,\n            shapeProp === \"avatar\"\n              ? `<Skeleton shape=\"circle\"${Object.hasOwn(avatarSizes, String(sizeProp)) ? ` size=\"${sizeProp}\"` : \"\"}>`\n              : '<Skeleton shape=\"rect\">',\n          ],\n          // A size for a shape that isn't one says nothing more: the shape's fix comes first.\n          !sizeKnown &&\n            shape === shapeProp && [\n              `size=\"${String(sizeProp)}\" is not a size for shape=\"${shape}\"; use ${Object.keys(sizes).length ? Object.keys(sizes).map((name) => `\"${name}\"`).join(\", \") : \"a layout class\"}`,\n              Object.keys(sizes).length ? `<Skeleton shape=\"${shape}\" size=\"${Object.keys(sizes)[0]}\">` : '<Skeleton className=\"h-32\">',\n            ],\n          variant !== undefined && [\n            \"variant is not a prop\",\n            `<Skeleton shape=\"${Object.hasOwn(muiVariants, String(variant)) ? muiVariants[String(variant)] : \"rect\"}\">`,\n          ],\n          animation !== undefined && [\"animation is not a prop; Skeleton breathes, and holds still with reduced motion\", \"<Skeleton>\"],\n          width !== undefined && [\"width is not a prop\", `<Skeleton className=\"${sizeClass(\"w\", width)}\">`],\n          height !== undefined && [\"height is not a prop\", `<Skeleton className=\"${sizeClass(\"h\", height)}\">`],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const common = { \"aria-hidden\": true, \"data-ouro\": \"skeleton\", \"data-shape\": shape } as const;\n\n  if (shape === \"rect\" || shape === \"circle\") {\n    const shapeClass = shape === \"circle\" ? cn(shapes.circle, avatarSizes[(size ?? \"md\") as SkeletonAvatarSize]) : shapes.rect;\n    return <span {...rest} {...common} ref={ref} className={cn(fill, !shimmer && still, shapeClass, className)} />;\n  }\n  if (shape === \"text\") {\n    const lines = atLeastOne(linesProp);\n    return (\n      <span {...rest} {...common} ref={ref} className={cn(\"block w-full\", size && textSizes[size as keyof typeof textSizes], className)}>\n        {Array.from({ length: lines }, (_, index) => (\n          <span key={index} className={line}>\n            <Bar shimmer={shimmer} className={lines > 1 && index === lines - 1 ? \"w-2/3\" : \"w-full\"} />\n          </span>\n        ))}\n      </span>\n    );\n  }\n  const frame = (size ?? \"md\") as keyof typeof rowSizes;\n  const count = atLeastOne(countProp);\n  return (\n    <>\n      {Array.from({ length: count }, (_, index) => {\n        const own = index === 0 ? { ...rest, ref } : { ...rest, id: undefined };\n        const title = titleWidths[index % titleWidths.length];\n        const detail = detailWidths[index % detailWidths.length];\n        if (shape === \"row\") {\n          return (\n            <span key={index} {...own} {...common} className={cn(\"grid min-w-0 grid-cols-[auto_minmax(0,1fr)] items-center gap-x-4\", rowSizes[frame], className)}>\n              <Bar shimmer={shimmer} className=\"mt-0.75 size-10 self-start rounded-ouro-md\" />\n              <span className=\"flex min-w-0 flex-col gap-0.5\">\n                <span className={cn(line, \"text-base\")}>\n                  <Bar shimmer={shimmer} className={title} />\n                </span>\n                <span className={cn(line, \"text-sm\")}>\n                  <Bar shimmer={shimmer} className={detail} />\n                </span>\n              </span>\n            </span>\n          );\n        }\n        const card = cardSizes[frame];\n        return (\n          <span\n            key={index}\n            {...own}\n            {...common}\n            className={cn(\"flex min-w-0 flex-col overflow-hidden rounded-ouro-xl border border-border bg-card\", card.root, className)}\n          >\n            <span className={cn(\"flex min-w-0 flex-col gap-1\", card.pad)}>\n              <span className={cn(line, card.title)}>\n                <Bar shimmer={shimmer} className={title} />\n              </span>\n              <span className={cn(line, \"text-sm\")}>\n                <Bar shimmer={shimmer} className={detail} />\n              </span>\n            </span>\n            <span className={cn(\"block min-w-0 text-sm\", card.pad)}>\n              <span className={line}>\n                <Bar shimmer={shimmer} className=\"w-full\" />\n              </span>\n              <span className={line}>\n                <Bar shimmer={shimmer} className=\"w-2/3\" />\n              </span>\n            </span>\n          </span>\n        );\n      })}\n    </>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/skeleton/skeleton.tsx"
    }
  ],
  "docs": "A placeholder that breathes after a second in the shape and size of content that is still loading, so the content takes its place without moving anything. Import: import { Skeleton } from \"@/components/ouro/skeleton/skeleton\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports 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/skeleton.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}