{
  "name": "coverflow-gallery",
  "type": "registry:ui",
  "description": "Origin Kit 3D coverflow gallery adapted for Canadian AI surfaces",
  "files": [
    {
      "path": "components/origin-kit/coverflow-gallery.tsx",
      "content": "// Upstream: Originkit coverflowgallery (MIT). Adapted for CAI; preserve this provenance notice.\\n\"use client\";\n\nimport {\n    useState,\n    useEffect,\n    useCallback,\n    useRef,\n    type CSSProperties,\n} from \"react\"\n\n// In Next.js there is no static renderer — always returns false.\nfunction useIsStaticRenderer(): boolean {\n    return false\n}\n\ninterface Slide {\n    image?: { src?: string; srcSet?: string; alt?: string }\n    title?: string\n}\n\ntype AutoplayDir = \"leftToRight\" | \"rightToLeft\"\ntype TitleCorner = \"topLeft\" | \"topRight\" | \"bottomLeft\" | \"bottomRight\"\n\ninterface Smooth3DSlideshowProps {\n    slides?: Slide[]\n    cardWidth?: number\n    cardHeight?: number\n    radius?: number\n    tilt?: number\n    sideTilt?: number\n    gap?: number\n    opacity?: number\n    transition?: any\n    autoplay?: boolean\n    autoplayDirection?: AutoplayDir\n    showTitle?: boolean\n    titleFont?: CSSProperties\n    titleColor?: string\n    titlePosition?: {\n        position?: TitleCorner\n        paddingLeft?: number\n        paddingRight?: number\n        paddingTop?: number\n        paddingBottom?: number\n    }\n    style?: CSSProperties\n}\n\nconst DEFAULT_SLIDES: Slide[] = [\n    {\n        image: {\n            src: \"https://imagedelivery.net/IEUjvl3YUlxY-MrTpOAWDQ/316d1761-fd79-4ca9-b8d4-f2bb20521a00/w=800\",\n        },\n        title: \"For Sitting\\nMetal\\nMinimal\",\n    },\n    {\n        image: {\n            src: \"https://imagedelivery.net/IEUjvl3YUlxY-MrTpOAWDQ/aeaa0756-9647-4f6c-d900-204bd25e4a00/w=800\",\n        },\n        title: \"For Living\\nConcrete\\nForm\",\n    },\n    {\n        image: {\n            src: \"https://imagedelivery.net/IEUjvl3YUlxY-MrTpOAWDQ/34ce1842-4b7a-4d52-0302-38582c341700/w=800\",\n        },\n        title: \"For Working\\nSteel\\nClean\",\n    },\n]\n\nconst PERSPECTIVE = 1600\nconst SCALE_STEP = 0.16\nconst MAX_VISIBLE = 2\nconst DEPTH = 240\n\nfunction cssTransition(t: any): { dur: number; ease: string } {\n    const dur = t && typeof t.duration === \"number\" ? t.duration : 0.6\n    let ease = \"cubic-bezier(0.22, 1, 0.36, 1)\"\n    const e = t?.ease\n    if (Array.isArray(e) && e.length === 4) {\n        ease = `cubic-bezier(${e[0]}, ${e[1]}, ${e[2]}, ${e[3]})`\n    } else if (typeof e === \"string\") {\n        const map: Record<string, string> = {\n            linear: \"linear\",\n            easeIn: \"ease-in\",\n            easeOut: \"ease-out\",\n            easeInOut: \"ease-in-out\",\n        }\n        ease = map[e] || \"ease\"\n    }\n    return { dur, ease }\n}\n\nexport default function CoverflowGallery(props: Smooth3DSlideshowProps) {\n    const {\n        slides = DEFAULT_SLIDES,\n        cardWidth = 557,\n        cardHeight = 420,\n        radius = 0,\n        tilt = 7,\n        sideTilt = 7,\n        gap = 7,\n        opacity = 65,\n        transition,\n        autoplay = false,\n        autoplayDirection = \"rightToLeft\",\n        showTitle = true,\n        titleFont,\n        titleColor = \"#ffffff\",\n        titlePosition,\n        style,\n    } = props\n\n    const tp = titlePosition || {}\n    const corner: TitleCorner = tp.position || \"bottomLeft\"\n    const isTop = corner === \"topLeft\" || corner === \"topRight\"\n    const isRight = corner === \"topRight\" || corner === \"bottomRight\"\n    const padLeft = tp.paddingLeft ?? 22\n    const padRight = tp.paddingRight ?? 22\n    const padTop = tp.paddingTop ?? 24\n    const padBottom = tp.paddingBottom ?? 24\n\n    const isStatic = useIsStaticRenderer()\n    const list = slides && slides.length ? slides : DEFAULT_SLIDES\n    const n = list.length\n    const loop = true\n    const [active, setActive] = useState(0)\n\n    useEffect(() => {\n        setActive((a) => Math.max(0, Math.min(n - 1, a)))\n    }, [n])\n\n    const moveDur =\n        transition && typeof transition.duration === \"number\"\n            ? transition.duration\n            : 0.6\n    const lockRef = useRef(false)\n    const lock = useCallback(() => {\n        lockRef.current = true\n        window.setTimeout(\n            () => { lockRef.current = false },\n            Math.max(50, moveDur * 1000)\n        )\n    }, [moveDur])\n\n    const step = useCallback(\n        (dir: number) => {\n            if (lockRef.current) return\n            lock()\n            setActive((a) => (((a + dir) % n) + n) % n)\n        },\n        [n, lock]\n    )\n\n    const handleCardClick = useCallback(\n        (i: number) => {\n            if (isStatic || autoplay || lockRef.current) return\n            lock()\n            setActive((a) => (i === a ? (a + 1) % n : i))\n        },\n        [isStatic, autoplay, n, lock]\n    )\n\n    const delay =\n        transition && typeof transition.delay === \"number\"\n            ? transition.delay\n            : 2.5\n    useEffect(() => {\n        if (isStatic || !autoplay || n < 2) return\n        const ms = Math.max(0.3, delay) * 1000\n        const dir = autoplayDirection === \"leftToRight\" ? -1 : 1\n        const id = window.setInterval(() => step(dir), ms)\n        return () => window.clearInterval(id)\n    }, [isStatic, autoplay, autoplayDirection, delay, n, step])\n\n    const onKeyDown = useCallback(\n        (e: React.KeyboardEvent) => {\n            if (e.key === \"ArrowRight\") {\n                e.preventDefault()\n                step(1)\n            } else if (e.key === \"ArrowLeft\") {\n                e.preventDefault()\n                step(-1)\n            }\n        },\n        [step]\n    )\n\n    const { dur, ease } = cssTransition(transition)\n    const transitionCss = `transform ${dur}s ${ease}, opacity ${dur}s ${ease}`\n\n    const effectiveRadius =\n        (Math.max(0, Math.min(20, radius)) / 20) *\n        (Math.min(cardWidth, cardHeight) / 2)\n    const dim = 1 - Math.max(0, Math.min(100, opacity)) / 100\n\n    const rootStyle: CSSProperties = {\n        ...(style || {}),\n        position: \"relative\",\n        width: \"100%\",\n        height: \"100%\",\n        minWidth: 320,\n        minHeight: 360,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        perspective: `${PERSPECTIVE}px`,\n        overflow: \"hidden\",\n        outline: \"none\",\n    }\n\n    return (\n        <div\n            style={rootStyle}\n            tabIndex={0}\n            role=\"group\"\n            aria-roledescription=\"carousel\"\n            onKeyDown={isStatic ? undefined : onKeyDown}\n        >\n            <div\n                style={{\n                    position: \"relative\",\n                    width: cardWidth,\n                    height: cardHeight,\n                    transformStyle: \"preserve-3d\",\n                }}\n            >\n                {list.map((slide, i) => {\n                    let rel = i - active\n                    if (loop) {\n                        if (rel > n / 2) rel -= n\n                        if (rel < -n / 2) rel += n\n                    }\n                    const ax = Math.abs(rel)\n                    const visible = ax <= MAX_VISIBLE\n                    const isActive = rel === 0\n                    const sc = Math.max(0.4, 1 - ax * SCALE_STEP)\n                    const tx = rel * (gap * 30)\n                    const tz = -ax * DEPTH\n                    const ry = -rel * tilt\n                    const rz = rel * sideTilt\n                    const src = slide.image?.src || \"\"\n\n                    const cardStyle: CSSProperties = {\n                        position: \"absolute\",\n                        left: \"50%\",\n                        top: \"50%\",\n                        width: cardWidth,\n                        height: cardHeight,\n                        borderRadius: effectiveRadius,\n                        overflow: \"hidden\",\n                        transformStyle: \"preserve-3d\",\n                        transformOrigin: \"center center\",\n                        transform: `translate(-50%, -50%) translateX(${tx}px) translateZ(${tz}px) rotateY(${ry}deg) rotateZ(${rz}deg) scale(${sc})`,\n                        transition: transitionCss,\n                        opacity: visible ? 1 : 0,\n                        cursor: autoplay || isActive ? \"default\" : \"pointer\",\n                        pointerEvents:\n                            visible && !isStatic && !autoplay ? \"auto\" : \"none\",\n                        backgroundColor: \"#1a1a1a\",\n                    }\n\n                    return (\n                        <div\n                            key={i}\n                            style={cardStyle}\n                            onClick={isStatic ? undefined : () => handleCardClick(i)}\n                            aria-label={slide.title}\n                            aria-hidden={!visible}\n                        >\n                            {src ? (\n                                <img\n                                    src={src}\n                                    alt={slide.image?.alt || slide.title || \"\"}\n                                    draggable={false}\n                                    style={{\n                                        position: \"absolute\",\n                                        inset: 0,\n                                        width: \"100%\",\n                                        height: \"100%\",\n                                        objectFit: \"cover\",\n                                        display: \"block\",\n                                        userSelect: \"none\",\n                                    }}\n                                />\n                            ) : null}\n\n                            {showTitle && (\n                                <>\n                                    <div\n                                        style={{\n                                            position: \"absolute\",\n                                            inset: 0,\n                                            background: isTop\n                                                ? \"linear-gradient(0deg, rgba(0,0,0,0) 35%, rgba(0,0,0,0.7) 100%)\"\n                                                : \"linear-gradient(180deg, rgba(0,0,0,0) 35%, rgba(0,0,0,0.7) 100%)\",\n                                            pointerEvents: \"none\",\n                                        }}\n                                    />\n                                    <div\n                                        style={{\n                                            position: \"absolute\",\n                                            left: padLeft,\n                                            right: padRight,\n                                            [isTop ? \"top\" : \"bottom\"]: isTop ? padTop : padBottom,\n                                            textAlign: isRight ? \"right\" : \"left\",\n                                            pointerEvents: \"none\",\n                                        }}\n                                    >\n                                        <span\n                                            style={{\n                                                color: titleColor,\n                                                fontSize: 28,\n                                                fontWeight: 700,\n                                                lineHeight: \"1.1em\",\n                                                letterSpacing: \"-0.02em\",\n                                                whiteSpace: \"pre-line\",\n                                                textShadow: \"0 2px 10px rgba(0,0,0,0.4)\",\n                                                ...(titleFont || {}),\n                                            }}\n                                        >\n                                            {slide.title}\n                                        </span>\n                                    </div>\n                                </>\n                            )}\n\n                            <div\n                                style={{\n                                    position: \"absolute\",\n                                    inset: 0,\n                                    background: \"#000000\",\n                                    opacity: isActive ? 0 : dim,\n                                    transition: `opacity ${dur}s ${ease}`,\n                                    pointerEvents: \"none\",\n                                }}\n                            />\n                        </div>\n                    )\n                })}\n            </div>\n        </div>\n    )\n}\n",
      "type": "registry:ui"
    }
  ]
}