{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-compare",
  "title": "Image Compare",
  "description": "A before/after comparison on one layout-stable stage, driven by a native range input so it works with a mouse, a keyboard and a screen reader.",
  "dependencies": [
    "cn",
    "lucide-react"
  ],
  "registryDependencies": [
    "litingyes/blocove/image"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/image/compare.tsx",
      "content": "import type { ImageTransform } from '@/components/blocove/image/image'\nimport { cn } from 'cn'\nimport { MoveHorizontalIcon } from 'lucide-react'\nimport { useState } from 'react'\nimport { Image } from '@/components/blocove/image/image'\n\nexport interface ImageCompareSide {\n  /** The source of this side. */\n  src: string\n  /** Alternative text of this side. */\n  alt: string\n}\n\nexport interface ImageCompareProps {\n  /** The image revealed on the left. */\n  before: ImageCompareSide\n  /** The image revealed on the right. */\n  after: ImageCompareSide\n  /** Label under the left edge. */\n  beforeLabel?: string\n  /** Label under the right edge. */\n  afterLabel?: string\n  /** The split position on first render, from 0 to 100. */\n  defaultPosition?: number\n  /** Aspect ratio of the stage. */\n  aspectRatio?: number | string\n  /** Widths both images request. */\n  widths?: readonly number[]\n  /** Turns a source and a width into the URL that serves it. */\n  transform?: ImageTransform\n  /** Layout sizes, shared by both images. */\n  sizes?: string\n  /** Accessible name of the range input. */\n  rangeLabel?: string\n  /** Extra classes for the figure. */\n  className?: string\n}\n\nfunction clampPosition(value: number): number {\n  if (!Number.isFinite(value)) {\n    return 50\n  }\n\n  return Math.min(Math.max(value, 0), 100)\n}\n\n/**\n * A before/after comparison: the two images share one layout-stable stage, the\n * left one is clipped at the split, and a real range input drives the split, so\n * the control works with a mouse, a keyboard and a screen reader.\n */\nexport function ImageCompare({\n  before,\n  after,\n  beforeLabel = 'Before',\n  afterLabel = 'After',\n  defaultPosition = 50,\n  aspectRatio = '16 / 9',\n  widths,\n  transform,\n  sizes,\n  rangeLabel = 'Comparison position',\n  className,\n}: ImageCompareProps) {\n  const [position, setPosition] = useState(() => clampPosition(defaultPosition))\n\n  return (\n    <figure\n      data-slot=\"image-compare\"\n      className={cn('flex w-full flex-col gap-2', className)}\n    >\n      <div\n        className=\"relative w-full overflow-hidden rounded-lg border bg-muted\"\n        style={{ aspectRatio }}\n      >\n        <div\n          data-slot=\"image-compare-before\"\n          className=\"absolute inset-0 z-10\"\n          style={{ clipPath: `inset(0 ${100 - position}% 0 0)` }}\n        >\n          <Image\n            alt={before.alt}\n            src={before.src}\n            transform={transform}\n            widths={widths}\n            sizes={sizes}\n            containerClassName=\"h-full w-full\"\n          />\n        </div>\n\n        <div className=\"absolute inset-0\">\n          <Image\n            alt={after.alt}\n            src={after.src}\n            transform={transform}\n            widths={widths}\n            sizes={sizes}\n            containerClassName=\"h-full w-full\"\n          />\n        </div>\n\n        <div\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute inset-y-0 z-20 w-px -translate-x-1/2 bg-background shadow-[0_0_0_1px_var(--color-border)]\"\n          style={{ left: `${position}%` }}\n        >\n          <span className=\"absolute top-1/2 left-1/2 flex size-8 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm\">\n            <MoveHorizontalIcon className=\"size-4\" />\n          </span>\n        </div>\n      </div>\n\n      <div className=\"flex items-center justify-between text-xs text-muted-foreground\">\n        <span>{beforeLabel}</span>\n        <span>{afterLabel}</span>\n      </div>\n\n      <input\n        type=\"range\"\n        min={0}\n        max={100}\n        step={1}\n        value={position}\n        aria-label={rangeLabel}\n        aria-valuetext={`${position}%`}\n        onChange={event => setPosition(clampPosition(Number(event.target.value)))}\n        className=\"w-full cursor-ew-resize accent-foreground\"\n      />\n    </figure>\n  )\n}\n",
      "type": "registry:ui",
      "target": "components/blocove/image/compare.tsx"
    }
  ],
  "categories": [
    "image"
  ],
  "type": "registry:ui"
}