{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"brick-gallery","type":"registry:ui","title":"Brick Gallery","description":"Animated masonry image grid: tiles fly in with a staggered blur-to-focus, glide to new slots on resize and zoom on hover.","dependencies":["motion"],"registryDependencies":[],"files":[{"path":"registry/ui/brick-gallery.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\n\nexport interface BrickGalleryItem {\n  src: string;\n  /** Height / width of the image, e.g. 1.5 for a portrait photo. */\n  ratio: number;\n  alt?: string;\n  href?: string;\n}\n\nexport interface BrickGalleryProps {\n  items: BrickGalleryItem[];\n  /** Columns are as many as fit at this minimum width, in px. */\n  minColumnWidth?: number;\n  /** Px between tiles. */\n  gap?: number;\n  /** Seconds between each tile's entrance. */\n  stagger?: number;\n  /** Where tiles fly in from. */\n  animateFrom?: \"bottom\" | \"top\" | \"left\" | \"right\" | \"center\";\n  /** Tiles start blurred and come into focus. */\n  blurToFocus?: boolean;\n  /** Image zoom on hover (1 disables). */\n  hoverScale?: number;\n  className?: string;\n}\n\nconst OFFSETS = {\n  bottom: { x: 0, y: 80 },\n  top: { x: 0, y: -80 },\n  left: { x: -80, y: 0 },\n  right: { x: 80, y: 0 },\n  center: { x: 0, y: 0 },\n};\n\nexport function BrickGallery({\n  items,\n  minColumnWidth = 220,\n  gap = 16,\n  stagger = 0.05,\n  animateFrom = \"bottom\",\n  blurToFocus = true,\n  hoverScale = 1.08,\n  className,\n}: BrickGalleryProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const [width, setWidth] = useState(0);\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    const ro = new ResizeObserver(([e]) => setWidth(e.contentRect.width));\n    ro.observe(ref.current!);\n    return () => ro.disconnect();\n  }, []);\n\n  // Shortest-column-first placement. Recomputed on resize; tiles glide to their new slots.\n  const { tiles, height } = useMemo(() => {\n    if (!width) return { tiles: [], height: 0 };\n    const cols = Math.max(1, Math.floor((width + gap) / (minColumnWidth + gap)));\n    const colW = (width - gap * (cols - 1)) / cols;\n    const heights = new Array<number>(cols).fill(0);\n    const tiles = items.map((item) => {\n      const col = heights.indexOf(Math.min(...heights));\n      const h = colW * item.ratio;\n      const tile = { x: col * (colW + gap), y: heights[col], w: colW, h };\n      heights[col] += h + gap;\n      return tile;\n    });\n    return { tiles, height: Math.max(0, Math.max(...heights) - gap) };\n  }, [items, width, gap, minColumnWidth]);\n\n  const from = OFFSETS[animateFrom];\n\n  return (\n    <div ref={ref} className={`relative w-full ${className ?? \"\"}`} style={{ height }}>\n      {tiles.map((t, i) => {\n        const item = items[i];\n        const Tag = item.href ? \"a\" : \"div\";\n        return (\n          <div\n            key={item.src + i}\n            className=\"absolute left-0 top-0\"\n            style={{\n              width: t.w,\n              height: t.h,\n              transform: `translate3d(${t.x}px, ${t.y}px, 0)`,\n              transition: reduce ? undefined : \"transform .7s cubic-bezier(.2,.8,.2,1), width .7s cubic-bezier(.2,.8,.2,1), height .7s cubic-bezier(.2,.8,.2,1)\",\n            }}\n          >\n            <motion.div\n              className=\"size-full\"\n              initial={\n                reduce\n                  ? false\n                  : {\n                      opacity: 0,\n                      x: from.x,\n                      y: from.y,\n                      scale: animateFrom === \"center\" ? 0.6 : 0.92,\n                      filter: blurToFocus ? \"blur(12px)\" : \"blur(0px)\",\n                    }\n              }\n              animate={{ opacity: 1, x: 0, y: 0, scale: 1, filter: \"blur(0px)\" }}\n              transition={{ duration: 0.8, ease: [0.2, 0.8, 0.2, 1], delay: Math.min(i, 30) * stagger }}\n            >\n              <Tag\n                {...(item.href ? { href: item.href } : {})}\n                className=\"group relative block size-full overflow-hidden rounded-xl bg-muted shadow-[0_10px_30px_-12px_rgba(0,0,0,.6)] outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n              >\n                {/* eslint-disable-next-line @next/next/no-img-element */}\n                <img\n                  src={item.src}\n                  alt={item.alt ?? \"\"}\n                  loading=\"lazy\"\n                  draggable={false}\n                  className=\"size-full object-cover transition-transform duration-700 ease-[cubic-bezier(.2,.8,.2,1)] group-hover:scale-[var(--hs)] group-focus-visible:scale-[var(--hs)]\"\n                  style={{ [\"--hs\" as string]: hoverScale }}\n                />\n                <span\n                  aria-hidden\n                  className=\"pointer-events-none absolute inset-0 bg-gradient-to-t from-black/50 via-transparent to-transparent opacity-0 transition-opacity duration-500 group-hover:opacity-100\"\n                />\n                {item.alt && (\n                  <span\n                    aria-hidden\n                    className=\"pointer-events-none absolute bottom-3 left-3 translate-y-2 text-sm font-medium text-white opacity-0 transition-all duration-500 group-hover:translate-y-0 group-hover:opacity-100\"\n                  >\n                    {item.alt}\n                  </span>\n                )}\n              </Tag>\n            </motion.div>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n"}]}