{
  "schemaVersion": 1,
  "target": "react",
  "name": "aspect-ratio",
  "version": "0.1.0",
  "category": "data",
  "title": "Aspect Ratio",
  "description": "A box that keeps a width-to-height ratio as it resizes, so images, video, and embeds fill it without shifting the layout.",
  "tags": [
    "layout",
    "media",
    "image",
    "video",
    "ratio"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {},
  "registryDependencies": [],
  "docsPath": "/components/aspect-ratio",
  "props": [
    {
      "name": "ratio",
      "type": "number | string",
      "default": "16 / 9",
      "description": "Width over height: 16 / 9, 1, or a CSS ratio string such as \"4 / 3\"."
    },
    {
      "name": "...props",
      "type": "ComponentProps<\"div\">",
      "description": "Any div attribute. Direct img, video, picture, iframe, and svg children fill the box with object-cover."
    }
  ],
  "accessibility": [
    "Purely presentational: it adds no role, so the media inside keeps its own alt text or title.",
    "Reserving the box's height before media loads prevents layout shift for every reader."
  ],
  "states": [],
  "files": [
    {
      "path": "ui/aspect-ratio.tsx",
      "content": "import type { ComponentProps, CSSProperties } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nexport interface AspectRatioProps extends ComponentProps<\"div\"> {\n  /**\n   * Width divided by height: a number (`16 / 9`, `1`) or a CSS ratio string (`\"4 / 3\"`).\n   * Defaults to 16 / 9.\n   */\n  ratio?: number | string;\n}\n\n/**\n * A box that keeps its width-to-height ratio as it resizes, so media does not shift the layout\n * while it loads. Direct `img`, `video`, `iframe`, `picture`, and `svg` children fill the box\n * and crop with `object-cover`; anything else is laid out normally inside it.\n */\nexport function AspectRatio({ ratio = 16 / 9, className, style, ...props }: AspectRatioProps) {\n  return (\n    <div\n      data-slot=\"aspect-ratio\"\n      style={{ aspectRatio: typeof ratio === \"number\" ? String(ratio) : ratio, ...style } as CSSProperties}\n      className={cx(\n        \"relative w-full overflow-hidden\",\n        \"[&>img]:absolute [&>img]:inset-0 [&>img]:size-full [&>img]:object-cover\",\n        \"[&>video]:absolute [&>video]:inset-0 [&>video]:size-full [&>video]:object-cover\",\n        \"[&>picture]:absolute [&>picture]:inset-0 [&>picture]:size-full [&>picture>img]:size-full [&>picture>img]:object-cover\",\n        \"[&>iframe]:absolute [&>iframe]:inset-0 [&>iframe]:size-full [&>iframe]:border-0\",\n        \"[&>svg]:absolute [&>svg]:inset-0 [&>svg]:size-full\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { AspectRatio } from \"@/components/shaken/ui/aspect-ratio\";\n\n// A drawn preview stands in for a screenshot so the example has no network dependency.\nfunction PreviewArt() {\n  return (\n    <svg viewBox=\"0 0 320 180\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\" className=\"text-zinc-950 dark:text-white\">\n      <rect width=\"320\" height=\"180\" className=\"fill-zinc-50 dark:fill-black\" />\n      <rect x=\"0\" y=\"0\" width=\"320\" height=\"22\" className=\"fill-white dark:fill-black\" />\n      <line x1=\"0\" y1=\"22.5\" x2=\"320\" y2=\"22.5\" stroke=\"currentColor\" strokeOpacity=\"0.1\" />\n      <circle cx=\"12\" cy=\"11\" r=\"3\" fill=\"currentColor\" fillOpacity=\"0.15\" />\n      <circle cx=\"22\" cy=\"11\" r=\"3\" fill=\"currentColor\" fillOpacity=\"0.15\" />\n      <circle cx=\"32\" cy=\"11\" r=\"3\" fill=\"currentColor\" fillOpacity=\"0.15\" />\n      <rect x=\"16\" y=\"38\" width=\"72\" height=\"6\" rx=\"3\" fill=\"currentColor\" fillOpacity=\"0.7\" />\n      <rect x=\"16\" y=\"52\" width=\"120\" height=\"4\" rx=\"2\" fill=\"currentColor\" fillOpacity=\"0.2\" />\n      <path d=\"M16 150 L56 128 L96 136 L136 104 L176 112 L216 80 L256 90 L304 58\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinejoin=\"round\" strokeLinecap=\"round\" />\n      <path d=\"M16 150 L56 128 L96 136 L136 104 L176 112 L216 80 L256 90 L304 58 L304 164 L16 164 Z\" fill=\"currentColor\" fillOpacity=\"0.05\" />\n      <line x1=\"16\" y1=\"164.5\" x2=\"304\" y2=\"164.5\" stroke=\"currentColor\" strokeOpacity=\"0.15\" />\n    </svg>\n  );\n}\n\nexport default function AspectRatioExample() {\n  return (\n    <div className=\"grid w-full max-w-xl gap-4 sm:grid-cols-[2fr_1fr]\">\n      <figure className=\"m-0 grid gap-2\">\n        <AspectRatio ratio={16 / 9} className=\"rounded-xl border border-zinc-950/10 dark:border-white/10\">\n          <PreviewArt />\n        </AspectRatio>\n        <figcaption className=\"text-xs text-zinc-500\">Deploy preview, 16 by 9</figcaption>\n      </figure>\n      <figure className=\"m-0 grid content-start gap-2\">\n        <AspectRatio ratio={1} className=\"rounded-xl border border-zinc-950/10 dark:border-white/10\">\n          <PreviewArt />\n        </AspectRatio>\n        <figcaption className=\"text-xs text-zinc-500\">Thumbnail, square crop</figcaption>\n      </figure>\n    </div>\n  );\n}\n"
  }
}
