{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flow-gallery",
  "title": "Flow Gallery",
  "author": "AlgorizeTech",
  "description": "Horizontal and diagonal 3D cascading gallery stream with continuous downward auto-flow motion, drag inertia physics, and isometric perspective depth.",
  "dependencies": [
    "next-themes"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/flow-gallery.tsx",
      "content": "\"use client\";\n\nimport React, { useState, useRef, useEffect } from \"react\";\nimport { useTheme } from \"next-themes\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FlowGalleryItem {\n    id: string | number;\n    title?: string;\n    imageUrl: string;\n}\n\nexport interface FlowGalleryProps {\n    /** List of image items */\n    items?: FlowGalleryItem[];\n    /** Stream flow angle variant (default: \"top-left\") */\n    direction?: \"top-left\" | \"top-right\" | \"vertical-up\" | \"vertical-down\" | \"vertical\";\n    /** Auto-flow speed (default: 3.5) */\n    speed?: number;\n    /** Pause auto-flow on hover (default: true) */\n    pauseOnHover?: boolean;\n    /** Columns count in grid stream (default: 9) */\n    columns?: number;\n    /** Enable alternating column stream flow directions (default: true) */\n    reverseAlternatingColumns?: boolean;\n    /** Footer caption text */\n    footerCaption?: string;\n    /** Custom class name */\n    className?: string;\n}\n\nconst DEFAULT_ITEMS: FlowGalleryItem[] = [\n    {\n        id: \"1\",\n        title: \"Cyberpunk Officer\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790148864/photo-1618005182384-a83a8bd57fbe-1790148865111.jpg\",\n    },\n    {\n        id: \"2\",\n        title: \"Neon Cyberpunk Girl\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790150483/photo-1578632767115-351597cf2477-1790150482281.jpg\",\n    },\n    {\n        id: \"3\",\n        title: \"Ramen Bowl Art\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790148864/photo-1569718212165-3a8278d5f624-1790148865111.jpg\",\n    },\n    {\n        id: \"4\",\n        title: \"Suit Business Portrait\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790150480/photo-1507003211169-0a1dd7228f2d-1790150482276.jpg\",\n    },\n    {\n        id: \"5\",\n        title: \"Grizzly Bear Wildlife\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790150482/photo-1530595467537-0b5996c41f2d-1790150482280.jpg\",\n    },\n    {\n        id: \"6\",\n        title: \"Skateboard Graphic\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790150482/photo-1520045892732-304bc3ac5d8e-1790150482278.jpg\",\n    },\n    {\n        id: \"7\",\n        title: \"Abstract Fluid Ink\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790150483/photo-1541701494587-cb58502866ab-1790150482281.jpg\",\n    },\n    {\n        id: \"8\",\n        title: \"Deep Space Black Hole\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790145141/photo-1451187580459-43490279c0fa-1790145143491.jpg\",\n    },\n    {\n        id: \"9\",\n        title: \"Misty Pine Forest\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790146209/photo-1470071459604-3b5ec3a7fe05-1790146212205.jpg\",\n    },\n    {\n        id: \"10\",\n        title: \"Sunset Mountain Peak\",\n        imageUrl: \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_800,c_limit/v1790146210/photo-1506744038136-46273834b3fb-1790146212208.jpg\",\n    },\n];\n\nexport function FlowGallery({\n    items = DEFAULT_ITEMS,\n    direction = \"top-left\",\n    speed = 3.5,\n    pauseOnHover = true,\n    columns = 9,\n    reverseAlternatingColumns = true,\n    footerCaption = \"\",\n    className,\n}: FlowGalleryProps) {\n    const { resolvedTheme } = useTheme();\n    const isDark = resolvedTheme === \"dark\";\n\n    const containerRef = useRef<HTMLDivElement | null>(null);\n    const [isHovered, setIsHovered] = useState(false);\n    const [isDragging, setIsDragging] = useState(false);\n\n    // Flow Motion Physics State\n    const motionRef = useRef({\n        offset: 0,\n        velocity: 0,\n        lastY: 0,\n        lastTime: 0,\n        isDown: false,\n    });\n\n    const [renderOffset, setRenderOffset] = useState(0);\n\n    // Silky-Smooth 60fps Continuous Auto-Flow Loop\n    useEffect(() => {\n        let animId: number;\n\n        const updateLoop = () => {\n            const motion = motionRef.current;\n\n            if (!motion.isDown) {\n                const baseDirFactor = (direction === \"vertical-up\" || direction === \"vertical\") ? -1 : 1;\n\n                if (!isHovered || !pauseOnHover) {\n                    motion.offset += baseDirFactor * speed;\n                }\n\n                motion.velocity *= 0.94;\n                motion.offset += motion.velocity;\n            }\n\n            setRenderOffset(motion.offset);\n            animId = requestAnimationFrame(updateLoop);\n        };\n\n        updateLoop();\n\n        return () => {\n            cancelAnimationFrame(animId);\n        };\n    }, [speed, isHovered, pauseOnHover, direction]);\n\n    // Pointer Event Handlers for Drag\n    const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n        const motion = motionRef.current;\n        motion.isDown = true;\n        const dragAxis = direction === \"top-left\"\n            ? e.clientY - e.clientX * 0.4\n            : direction === \"top-right\"\n            ? e.clientY + e.clientX * 0.4\n            : e.clientY;\n        motion.lastY = dragAxis;\n        motion.lastTime = performance.now();\n        motion.velocity = 0;\n        setIsDragging(true);\n        e.currentTarget.setPointerCapture(e.pointerId);\n    };\n\n    const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n        const motion = motionRef.current;\n        if (!motion.isDown) return;\n\n        const now = performance.now();\n        const dragAxis = direction === \"top-left\"\n            ? e.clientY - e.clientX * 0.4\n            : direction === \"top-right\"\n            ? e.clientY + e.clientX * 0.4\n            : e.clientY;\n        const dy = dragAxis - motion.lastY;\n        const dt = Math.max(1, now - motion.lastTime);\n\n        motion.offset -= dy * 1.5;\n        motion.velocity = (-dy / dt) * 12;\n\n        motion.lastY = dragAxis;\n        motion.lastTime = now;\n    };\n\n    const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {\n        const motion = motionRef.current;\n        motion.isDown = false;\n        setIsDragging(false);\n        try {\n            e.currentTarget.releasePointerCapture(e.pointerId);\n        } catch {\n            // Ignore if pointer capture released\n        }\n    };\n\n    // Card dimensions & dense full stage 3D grid layout\n    const cardWidth = 140;\n    const cardHeight = 140;\n    const gapY = 20;\n    const strideY = cardHeight + gapY;\n\n    const totalItems = items.length;\n    const loopSpanHeight = totalItems * strideY;\n    const rowsPerCol = totalItems * 3;\n\n    const isVertical = direction === \"vertical\" || direction === \"vertical-up\" || direction === \"vertical-down\";\n\n    const planeTransform = direction === \"top-right\"\n        ? \"rotate(24deg) skewX(-8deg)\"\n        : isVertical\n        ? \"none\"\n        : \"rotate(-24deg) skewX(8deg)\";\n\n    const stageContent = (\n        <div\n            ref={containerRef}\n            onMouseEnter={() => setIsHovered(true)}\n            onMouseLeave={() => setIsHovered(false)}\n            onPointerDown={handlePointerDown}\n            onPointerMove={handlePointerMove}\n            onPointerUp={handlePointerUp}\n            onPointerCancel={handlePointerUp}\n            className={cn(\n                \"relative w-full h-[560px] rounded-[24px] overflow-hidden border border-border bg-background text-foreground select-none transition-all duration-300 flex items-center justify-center\",\n                isDragging ? \"cursor-grabbing\" : \"cursor-grab\",\n                className\n            )}\n        >\n            {/* Ambient Vignette & Vertical Top/Bottom Edge Overlays */}\n            {isVertical ? (\n                <>\n                    <div className=\"absolute top-0 inset-x-0 h-32 bg-gradient-to-b from-background via-background/85 to-transparent z-30 pointer-events-none\" />\n                    <div className=\"absolute bottom-0 inset-x-0 h-32 bg-gradient-to-t from-background via-background/85 to-transparent z-30 pointer-events-none\" />\n                </>\n            ) : (\n                <div\n                    className=\"absolute inset-0 pointer-events-none z-20 transition-opacity bg-[radial-gradient(ellipse_at_center,transparent_55%,color-mix(in_oklab,var(--background)_85%,transparent)_100%)]\"\n                />\n            )}\n\n            {/* Stream Plane */}\n            <div\n                className={cn(\n                    \"absolute pointer-events-none flex justify-center items-center\",\n                    isVertical ? \"w-[120%] h-[260%]\" : \"w-[240%] h-[260%]\"\n                )}\n                style={{\n                    transform: planeTransform,\n                }}\n            >\n                <div className=\"w-full h-full flex justify-center gap-4 sm:gap-5\">\n                    {Array.from({ length: columns }).map((_, colIdx) => {\n                        const colStagger = colIdx * 3;\n\n                        // Alternating column stream direction algorithm\n                        const colDirMultiplier = (reverseAlternatingColumns && colIdx % 2 === 1) ? -1 : 1;\n                        const colRawOffset = renderOffset * colDirMultiplier;\n                        const colOffset = ((colRawOffset % loopSpanHeight) + loopSpanHeight) % loopSpanHeight - loopSpanHeight;\n\n                        return (\n                            <div\n                                key={colIdx}\n                                className=\"flex flex-col gap-4 sm:gap-5\"\n                                style={{\n                                    transform: `translateY(${colOffset}px)`,\n                                }}\n                            >\n                                {Array.from({ length: rowsPerCol }).map((_, rowIdx) => {\n                                    const itemIdx = ((rowIdx + colStagger) % totalItems + totalItems) % totalItems;\n                                    const item = items[itemIdx] || items[0];\n\n                                    return (\n                                        <div\n                                            key={rowIdx}\n                                            className={cn(\n                                                \"relative rounded-[22px] overflow-hidden border shadow-md transition-all duration-200 flex-shrink-0 group\",\n                                                \"border-border bg-card\",\n                                                isDark ? \"shadow-black/60\" : \"shadow-slate-300/50\"\n                                            )}\n                                            style={{\n                                                width: `${cardWidth}px`,\n                                                height: `${cardHeight}px`,\n                                            }}\n                                        >\n                                            <img\n                                                src={item.imageUrl}\n                                                alt={item.title || \"Flow Gallery Item\"}\n                                                className=\"w-full h-full object-cover rounded-[20px] transition-transform duration-300 group-hover:scale-105 pointer-events-none\"\n                                                loading=\"lazy\"\n                                            />\n                                        </div>\n                                    );\n                                })}\n                            </div>\n                        );\n                    })}\n                </div>\n            </div>\n        </div>\n    );\n\n    if (!footerCaption) {\n        return stageContent;\n    }\n\n    return (\n        <div className=\"w-full space-y-2 select-none font-sans\">\n            {stageContent}\n            <p className=\"text-xs font-mono tracking-wide text-muted-foreground pt-1\">\n                {footerCaption}\n            </p>\n        </div>\n    );\n}\n\nexport default FlowGallery;\n",
      "type": "registry:component",
      "target": "components/custom/flow-gallery.tsx"
    }
  ],
  "docs": "Named export: FlowGallery. Interactive drag with grab cursor, continuous downward auto-flow, 3D isometric plane, and Next Themes adaptation.",
  "categories": [
    "media",
    "scroll"
  ],
  "type": "registry:component"
}
