{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image",
  "title": "Image",
  "description": "A responsive image with a layout-stable box, srcset and sizes, focal point, placeholder and fallback, built on the native <img> and <picture> elements.",
  "dependencies": [
    "cn"
  ],
  "registryDependencies": [
    "litingyes/blocove/image-pipeline"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/image/image.tsx",
      "content": "import type { CSSProperties, ImgHTMLAttributes, ReactNode } from 'react'\nimport type { ImageFocalPoint, ImageTransform } from '@/lib/blocove/image-pipeline'\nimport { cn } from 'cn'\nimport { useEffect, useRef, useState } from 'react'\nimport {\n  buildImageSrcSet,\n  focalPointPosition,\n  placeholderBackground,\n} from '@/lib/blocove/image-pipeline'\n\nexport type { ImageFocalPoint, ImageTransform }\n\n/** One `<source>` of an art-directed picture. */\nexport interface ImageSource {\n  /** The srcset the source selects between. */\n  srcSet: string\n  /** Media condition the source applies to. */\n  media?: string\n  /** MIME type the source serves. */\n  type?: string\n}\n\nexport interface ImageProps extends Omit<\n  ImgHTMLAttributes<HTMLImageElement>,\n  | 'src'\n  | 'alt'\n  | 'width'\n  | 'height'\n  | 'srcSet'\n  | 'sizes'\n  | 'loading'\n  | 'decoding'\n  | 'fetchPriority'\n> {\n  /** The image URL, used as the fallback candidate of the srcset. */\n  src: string\n  /** Alternative text. Required: the component never renders a decorative image by accident. */\n  alt: string\n  /** Intrinsic width, forwarded to the element and used for the aspect ratio. */\n  width?: number\n  /** Intrinsic height, forwarded to the element and used for the aspect ratio. */\n  height?: number\n  /** Aspect ratio of the reserved box, for example `16 / 9`. Defaults to width / height. */\n  aspectRatio?: number | string\n  /** Widths the srcset requests. Requires `transform` to be useful. */\n  widths?: readonly number[]\n  /** Turns a source and a width into the URL that serves it. */\n  transform?: ImageTransform\n  /** An explicit srcset; it wins over `widths`. */\n  srcSet?: string\n  /** The layout sizes the browser picks a srcset candidate from. */\n  sizes?: string\n  /** Art-direction sources; when given the image renders inside a `<picture>`. */\n  sources?: readonly ImageSource[]\n  /**\n   * Marks the image as the largest contentful element: eager loading, synchronous\n   * decoding and a high fetch priority.\n   */\n  priority?: boolean\n  /** Where the image sits when it does not fill its box. */\n  focalPoint?: ImageFocalPoint\n  /** How the image fills its box. */\n  objectFit?: CSSProperties['objectFit']\n  /** A CSS color, or an image URL drawn behind the image while it loads. */\n  placeholder?: string\n  /** Rendered instead of a broken image when the source fails. */\n  fallback?: ReactNode\n  /** Extra classes for the box that reserves the space and paints the placeholder. */\n  containerClassName?: string\n  /** Extra classes for the `<img>` element itself. */\n  className?: string\n}\n\ntype ImageStatus = 'loading' | 'loaded' | 'error'\n\n/**\n * A responsive image with a layout-stable box, srcset support, a focal point, a\n * placeholder that fades into the picture and a fallback for broken sources.\n * It is a plain `<img>` (or `<picture>`), so it composes with any framework and\n * can be swapped for a framework image component without changing the API.\n */\nexport function Image({\n  src,\n  alt,\n  width,\n  height,\n  aspectRatio,\n  widths,\n  transform,\n  srcSet,\n  sizes,\n  sources,\n  priority = false,\n  focalPoint,\n  objectFit,\n  placeholder,\n  fallback,\n  containerClassName,\n  className,\n  style,\n  onLoad,\n  onError,\n  ...props\n}: ImageProps) {\n  const [status, setStatus] = useState<ImageStatus>('loading')\n  const imageRef = useRef<HTMLImageElement>(null)\n\n  // Changing the source must leave the previous error behind; otherwise the\n  // hidden element never mounts the new file and the fallback stays forever.\n  const sourceKey = `${src}|${srcSet ?? ''}|${sources?.map(source => `${source.media ?? ''}:${source.type ?? ''}:${source.srcSet}`).join('|') ?? ''}`\n  const [activeSource, setActiveSource] = useState(sourceKey)\n\n  if (activeSource !== sourceKey) {\n    setActiveSource(sourceKey)\n    setStatus('loading')\n  }\n\n  // A cached image can finish before React attaches onLoad, and a hydrated\n  // server render never fires one. The element itself is the source of truth.\n  useEffect(() => {\n    const image = imageRef.current\n\n    if (!image) {\n      return\n    }\n\n    if (image.complete && image.naturalWidth > 0) {\n      setStatus('loaded')\n      return\n    }\n\n    setStatus('loading')\n  }, [sourceKey])\n\n  const resolvedAspectRatio = aspectRatio\n    ?? (width && height\n      ? `${width} / ${height}`\n      : undefined)\n\n  const resolvedSrcSet = srcSet\n    ?? (widths?.length\n      ? buildImageSrcSet(src, { widths, transform })\n      : undefined)\n\n  const element = (\n    <img\n      {...props}\n      ref={imageRef}\n      alt={alt}\n      aria-hidden={status === 'error'\n        ? true\n        : undefined}\n      className={cn(\n        'relative z-10 h-full w-full transition-opacity duration-300 motion-reduce:transition-none',\n        status === 'loaded'\n          ? 'opacity-100'\n          : 'opacity-0',\n        className,\n      )}\n      data-state={status}\n      decoding={priority\n        ? 'sync'\n        : 'async'}\n      fetchPriority={priority\n        ? 'high'\n        : 'auto'}\n      height={height}\n      loading={priority\n        ? 'eager'\n        : 'lazy'}\n      onError={(event) => {\n        setStatus('error')\n        onError?.(event)\n      }}\n      onLoad={(event) => {\n        setStatus('loaded')\n        onLoad?.(event)\n      }}\n      sizes={sizes}\n      src={src}\n      srcSet={resolvedSrcSet}\n      style={{\n        objectFit: objectFit ?? 'cover',\n        objectPosition: focalPointPosition(focalPoint),\n        ...style,\n      }}\n      width={width}\n    />\n  )\n\n  return (\n    <span\n      data-slot=\"image\"\n      data-state={status}\n      className={cn('relative block overflow-hidden', containerClassName)}\n      style={{\n        ...(resolvedAspectRatio\n          ? { aspectRatio: resolvedAspectRatio }\n          : {}),\n        ...placeholderBackground(placeholder),\n      }}\n    >\n      {sources?.length\n        ? (\n            <picture className=\"contents\">\n              {sources.map(source => (\n                <source\n                  key={`${source.media ?? 'all'}-${source.type ?? 'any'}-${source.srcSet}`}\n                  media={source.media}\n                  sizes={sizes}\n                  srcSet={source.srcSet}\n                  type={source.type}\n                />\n              ))}\n              {element}\n            </picture>\n          )\n        : element}\n\n      {status === 'error'\n        ? fallback\n          ? (\n              <span\n                className=\"absolute inset-0 z-20 flex items-center justify-center bg-muted\"\n                data-slot=\"image-fallback\"\n              >\n                {fallback}\n              </span>\n            )\n          : (\n              <span\n                aria-hidden=\"true\"\n                className=\"absolute inset-0 z-20 bg-muted\"\n                data-slot=\"image-fallback\"\n              />\n            )\n        : null}\n    </span>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/image/image.tsx"
    }
  ],
  "categories": [
    "image"
  ],
  "type": "registry:ui"
}