{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"aspect-ratio","type":"registry:ui","title":"Aspect Ratio","description":"Box locked to a width/height ratio, with a shimmer placeholder that dissolves into the image once it loads.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/aspect-ratio.tsx","type":"registry:ui","content":"\"use client\";\n/* eslint-disable @next/next/no-img-element */\n\nimport { useState, type HTMLAttributes } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nconst css = `\n@keyframes ui-ar-shimmer{from{translate:-100% 0}to{translate:100% 0}}\n.ui-ar-shimmer::after{content:\"\";position:absolute;inset:0;background:linear-gradient(90deg,transparent,color-mix(in oklab,currentColor 10%,transparent),transparent);animation:ui-ar-shimmer 1.4s ease-in-out infinite}\n@media (prefers-reduced-motion:reduce){.ui-ar-shimmer::after{animation:none}}\n`;\n\nexport interface AspectRatioProps extends HTMLAttributes<HTMLDivElement> {\n  /** Width divided by height, e.g. 16 / 9. */\n  ratio?: number;\n  /** Image to render inside, covering the box. Omit to use children instead. */\n  src?: string;\n  alt?: string;\n  /** Show an animated shimmer until the image has loaded. */\n  shimmer?: boolean;\n}\n\nexport function AspectRatio({\n  ratio = 16 / 9,\n  src,\n  alt = \"\",\n  shimmer = true,\n  className,\n  style,\n  children,\n  ...props\n}: AspectRatioProps) {\n  const [loadedSrc, setLoadedSrc] = useState<string | null>(null);\n  const loaded = !src || loadedSrc === src;\n\n  return (\n    <div\n      {...props}\n      className={cn(\"relative w-full overflow-hidden\", className)}\n      style={{ aspectRatio: String(ratio), ...style }}\n    >\n      {src && (\n        <>\n          <style href=\"ui-aspect-ratio\" precedence=\"default\">\n            {css}\n          </style>\n          {shimmer && (\n            <div\n              aria-hidden\n              className={cn(\n                \"absolute inset-0 bg-muted text-foreground transition-opacity duration-500\",\n                !loaded && \"ui-ar-shimmer\",\n                loaded && \"opacity-0\",\n              )}\n            />\n          )}\n          <img\n            src={src}\n            alt={alt}\n            decoding=\"async\"\n            // A cached image can finish before hydration attaches onLoad, so check on mount too.\n            ref={(img) => {\n              if (img?.complete && img.naturalWidth) setLoadedSrc(src);\n            }}\n            onLoad={() => setLoadedSrc(src)}\n            onError={() => setLoadedSrc(src)}\n            className={cn(\n              \"absolute inset-0 size-full object-cover transition-[opacity,scale,filter] duration-700 ease-out motion-reduce:transition-none\",\n              loaded ? \"scale-100 opacity-100 blur-0\" : \"scale-[1.04] opacity-0 blur-md\",\n            )}\n          />\n        </>\n      )}\n      {children}\n    </div>\n  );\n}\n"}]}