{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnifier-loupe",
  "title": "Magnifier Loupe",
  "author": "VenusUI",
  "description": "A magnifying glass that follows the pointer over a photo and enlarges what's under it.",
  "files": [
    {
      "path": "registry/default/ui/magnifier-loupe.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface MagnifierLoupeProps extends React.ComponentProps<\"figure\"> {\n  src: string\n  alt: string\n  /** How much the lens enlarges. */\n  zoom?: number\n  /** Lens diameter in pixels. */\n  lens?: number\n  caption?: string\n}\n\n/**\n * A magnifying glass over a photo. Move the pointer (or a finger) across the\n * image to inspect it; with the keyboard, focus the image and use the arrow\n * keys. Escape puts the glass down.\n */\nfunction MagnifierLoupe({ src, alt, zoom = 2.5, lens = 168, caption, className, ...props }: MagnifierLoupeProps) {\n  const frame = React.useRef<HTMLDivElement>(null)\n  const [point, setPoint] = React.useState<{ x: number; y: number; w: number; h: number } | null>(null)\n\n  const place = (clientX: number, clientY: number) => {\n    const box = frame.current?.getBoundingClientRect()\n    if (!box) return\n    setPoint({ x: Math.min(Math.max(clientX - box.left, 0), box.width), y: Math.min(Math.max(clientY - box.top, 0), box.height), w: box.width, h: box.height })\n  }\n\n  const nudge = (dx: number, dy: number) => {\n    const box = frame.current?.getBoundingClientRect()\n    if (!box) return\n    setPoint((current) => {\n      const start = current ?? { x: box.width / 2, y: box.height / 2, w: box.width, h: box.height }\n      return { x: Math.min(Math.max(start.x + dx, 0), box.width), y: Math.min(Math.max(start.y + dy, 0), box.height), w: box.width, h: box.height }\n    })\n  }\n\n  return (\n    <figure data-slot=\"magnifier-loupe\" className={cn(\"w-full max-w-lg\", className)} {...props}>\n      <div\n        ref={frame}\n        role=\"img\"\n        aria-label={`${alt}. Move over the image, or use the arrow keys, to magnify.`}\n        tabIndex={0}\n        onPointerMove={(event) => place(event.clientX, event.clientY)}\n        onPointerDown={(event) => place(event.clientX, event.clientY)}\n        onPointerLeave={(event) => event.pointerType === \"mouse\" && setPoint(null)}\n        onFocus={() => nudge(0, 0)}\n        onBlur={() => setPoint(null)}\n        onKeyDown={(event) => {\n          const step = event.shiftKey ? 40 : 12\n          const moves: Record<string, [number, number]> = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] }\n          if (event.key === \"Escape\") return setPoint(null)\n          const move = moves[event.key]\n          if (!move) return\n          event.preventDefault()\n          nudge(...move)\n        }}\n        className={cn(\"relative touch-none overflow-hidden rounded-xl bg-muted outline-none select-none focus-visible:ring-3 focus-visible:ring-ring/50\", point && \"cursor-none\")}\n      >\n        <img src={src} alt=\"\" draggable={false} className=\"block aspect-[4/3] w-full object-cover\" />\n        {point ? (\n          <div aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ left: point.x - lens / 2, top: point.y - lens / 2, width: lens, height: lens }}>\n            {/* Handle, angled down and to the right like a real glass. */}\n            <span className=\"absolute top-[86%] left-[86%] h-24 w-5 origin-top -rotate-45 rounded-b-full bg-linear-to-r from-neutral-800 via-neutral-600 to-neutral-900 shadow-lg\" />\n            <span className=\"absolute top-[82%] left-[82%] h-5 w-6 origin-top -rotate-45 rounded-sm bg-linear-to-r from-neutral-400 via-neutral-200 to-neutral-500\" />\n            <span\n              className=\"absolute inset-0 rounded-full shadow-[0_10px_30px_rgb(0_0_0/0.4),inset_0_0_0_5px_#d4d4d8,inset_0_0_0_7px_#52525b,inset_0_0_22px_rgb(0_0_0/0.35)]\"\n              style={{\n                backgroundImage: `url(\"${src}\")`,\n                backgroundRepeat: \"no-repeat\",\n                backgroundSize: `${point.w * zoom}px ${point.h * zoom}px`,\n                backgroundPosition: `${-(point.x * zoom - lens / 2)}px ${-(point.y * zoom - lens / 2)}px`,\n              }}\n            />\n            <span className=\"absolute top-[14%] left-[18%] h-8 w-12 -rotate-30 rounded-full bg-white/25 blur-[2px]\" />\n          </div>\n        ) : null}\n      </div>\n      {caption ? <figcaption className=\"mt-2 text-sm text-muted-foreground\">{caption}</figcaption> : null}\n    </figure>\n  )\n}\n\nexport { MagnifierLoupe }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "cards"
  ],
  "type": "registry:ui"
}