{
  "title": "Test 2",
  "description": "A dynamic bento image showcase that progressively subdivides into multi-pane cells with smooth rolling slide transitions and ease settling.",
  "name": "craft-test-2",
  "dependencies": [],
  "registryDependencies": [],
  "type": "registry:block",
  "files": [
    {
      "path": "components/paceui/crafts/test-2/index.tsx",
      "type": "registry:block",
      "content": "import { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport NumberFlow from \"@number-flow/react\";\nimport { ChevronLeftIcon, ChevronRightIcon } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\ntype Frame = {\n    id: string;\n    src: string;\n    year: number;\n    title: string;\n};\n\nconst photo = (id: string) => `https://images.unsplash.com/${id}?q=80&w=1200&auto=format&fit=crop`;\n\nconst SCENES: Array<[string, number, string]> = [\n    [\"photo-1506905925346-21bda4d32df4\", 1996, \"Alpine Dawn\"],\n    [\"photo-1469474968028-56623f02e42e\", 1997, \"Emerald Valley\"],\n    [\"photo-1441974231531-c6227db76b6e\", 1998, \"Redwood Silence\"],\n    [\"photo-1470071459604-3b5ec3a7fe05\", 1999, \"Fog Line\"],\n    [\"photo-1501594907352-04cda38ebc29\", 2000, \"Stillwater Lake\"],\n    [\"photo-1519681393784-d120267933ba\", 2001, \"Midnight Ascent\"],\n    [\"photo-1507525428034-b723cf961d3e\", 2002, \"Coral Shore\"],\n    [\"photo-1518837695005-2083093ee35b\", 2003, \"Breaker\"],\n    [\"photo-1476514525535-07fb3b4ae5f1\", 2004, \"North Canoe\"],\n    [\"photo-1493246507139-91e8fad9978e\", 2005, \"Mirror Tarn\"],\n    [\"photo-1472214103451-9374bd1c798e\", 2006, \"Golden Meadow\"],\n    [\"photo-1433086966358-54859d0ed716\", 2007, \"Falls Crossing\"],\n    [\"photo-1504893524553-b855bce32c67\", 2008, \"Rapids\"],\n    [\"photo-1419242902214-272b3f66ee7a\", 2009, \"Starfield\"],\n    [\"photo-1475924156734-496f6cac6ec1\", 2010, \"Low Tide\"],\n    [\"photo-1500530855697-b586d89ba3ee\", 2011, \"Cabin Road\"],\n    [\"photo-1501785888041-af3ef285b470\", 2012, \"Ember Lake\"],\n    [\"photo-1508739773434-c26b3d09e071\", 2013, \"Solar Bloom\"],\n    [\"photo-1493976040374-85c8e12f0c0e\", 2014, \"Kyoto Lanterns\"],\n    [\"photo-1570077188670-e3a8d69ac5ff\", 2015, \"Aegean Blue\"],\n    [\"photo-1530122037265-a5f1f91d3b99\", 2016, \"High Alps\"],\n    [\"photo-1495616811223-4d98c6e9c869\", 2017, \"Cloud Sea\"],\n    [\"photo-1514565131-fce0801e5785\", 2018, \"Metro Grid\"],\n    [\"photo-1449824913935-59a10b8d2000\", 2019, \"Fifth Avenue\"],\n    [\"photo-1480714378408-67cf0d13bc1b\", 2020, \"Skyline Rush\"],\n    [\"photo-1519501025264-65ba15a82390\", 2021, \"Neon District\"],\n    [\"photo-1502602898657-3e91760cbb34\", 2022, \"Paris Lights\"],\n    [\"photo-1513635269975-59663e0ac1ad\", 2023, \"London Rain\"],\n    [\"photo-1542931287-023b922fa89b\", 2024, \"Tokyo Drift\"],\n    [\"photo-1499092346589-b9b6be3e94b2\", 2025, \"Times Square\"],\n];\n\nconst FRAMES: Frame[] = SCENES.map(([id, year, title]) => ({ id, src: photo(id), year, title }));\n\nconst LAST = FRAMES.length - 1;\nconst START = Math.round(LAST / 2);\n// Frames kept mounted on either side of the current still, so the dolly\n// has a real before/after pose to transition between.\nconst DEPTH = 4;\n// Outer thirds are the sustained direction. The center holds.\nconst EDGE = 0.33;\nconst PX_PER_FRAME = 48;\nconst GRAIN = `url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"180\" height=\"180\"><filter id=\"n\"><feTurbulence type=\"fractalNoise\" baseFrequency=\"0.85\" numOctaves=\"2\" stitchTiles=\"stitch\"/></filter><rect width=\"180\" height=\"180\" filter=\"url(%23n)\" opacity=\"0.55\"/></svg>')`;\nconst EASE = \"cubic-bezier(0.32, 0.72, 0, 1)\";\nconst TRANSITION = `transform 0.52s ${EASE}, opacity 0.52s ${EASE}`;\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\nconst clampFrame = (value: number) => clamp(value, 0, LAST);\n\n// Negative offset has already passed the camera (larger). Positive offset\n// is still ahead, down the tunnel (smaller). Offset 0 fills the frame.\nconst pose = (offset: number) => {\n    const away = Math.abs(offset);\n    const scale = offset > 0 ? Math.max(0.7, 1 - away * 0.14) : Math.min(1.28, 1 + away * 0.16);\n    let zIndex = 20;\n    if (offset < 0) zIndex = 30 - away;\n    if (offset > 0) zIndex = 10 - away;\n    return {\n        transform: `scale(${scale.toFixed(4)})`,\n        opacity: offset === 0 ? 1 : 0,\n        zIndex,\n    };\n};\n\n// Right is the future, left is the past. Magnitude grows toward the edge.\nconst cruiseRate = (t: number) => {\n    if (t >= 1 - EDGE) return 1 + ((t - (1 - EDGE)) / EDGE) * 1.35;\n    if (t <= EDGE) return -(1 + ((EDGE - t) / EDGE) * 1.35);\n    return 0;\n};\n\nexport const Demo = () => {\n    const [index, setIndex] = useState(START);\n    const [hovering, setHovering] = useState(false);\n    const [indicated, setIndicated] = useState(0);\n    const [ready, setReady] = useState(false);\n    const [reduce, setReduce] = useState(false);\n    const [engaged, setEngaged] = useState(false);\n\n    const indexRef = useRef(START);\n    const pendingRef = useRef(0);\n    const cruiseRef = useRef(0);\n    const hoveringRef = useRef(false);\n    const indicatedRef = useRef(0);\n    const engagedRef = useRef(false);\n    const lastXRef = useRef<number | null>(null);\n    const lastMoveRef = useRef(0);\n    const lastKeyRef = useRef(0);\n\n    const frame = FRAMES[index];\n\n    const showDirection = (dir: number) => {\n        if (dir === indicatedRef.current) return;\n        indicatedRef.current = dir;\n        setIndicated(dir);\n    };\n\n    const kick = () => {\n        if (engagedRef.current) return;\n        engagedRef.current = true;\n        setEngaged(true);\n    };\n\n    const step = useCallback((dir: 1 | -1) => {\n        const next = clampFrame(indexRef.current + dir);\n        if (next === indexRef.current) return false;\n        indexRef.current = next;\n        setIndex(next);\n        return true;\n    }, []);\n\n    useEffect(() => {\n        const id = requestAnimationFrame(() => setReady(true));\n        return () => cancelAnimationFrame(id);\n    }, []);\n\n    useEffect(() => {\n        const media = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n        const apply = () => setReduce(media.matches);\n        apply();\n        media.addEventListener(\"change\", apply);\n        return () => media.removeEventListener(\"change\", apply);\n    }, []);\n\n    useEffect(() => {\n        if (!engaged || reduce) return;\n\n        let raf = 0;\n        let alive = true;\n        let last = performance.now();\n        let since = 0;\n\n        const tick = (now: number) => {\n            if (!alive) return;\n            const dt = Math.min(0.05, (now - last) / 1000);\n            last = now;\n\n            const still = now - lastMoveRef.current > 140;\n            if (hoveringRef.current && still && Math.abs(pendingRef.current) < 1) {\n                pendingRef.current = clamp(pendingRef.current + cruiseRef.current * dt, -12, 12);\n            }\n\n            const pending = pendingRef.current;\n            if (Math.abs(pending) >= 1) {\n                since += dt;\n                const backlog = Math.abs(pending);\n                const interval = backlog > 5 ? 0.2 : backlog > 2 ? 0.3 : 0.46;\n                if (since >= interval) {\n                    since = 0;\n                    const dir = pending > 0 ? 1 : -1;\n                    if (step(dir)) pendingRef.current -= dir;\n                    else pendingRef.current = 0;\n                }\n            } else {\n                since = 0;\n            }\n\n            const nextPending = pendingRef.current;\n            const dirNow =\n                Math.abs(nextPending) >= 0.75\n                    ? Math.sign(nextPending)\n                    : hoveringRef.current\n                      ? Math.sign(cruiseRef.current)\n                      : 0;\n            showDirection(dirNow);\n\n            if (hoveringRef.current || Math.abs(pendingRef.current) >= 1) {\n                raf = requestAnimationFrame(tick);\n                return;\n            }\n\n            engagedRef.current = false;\n            setEngaged(false);\n        };\n\n        raf = requestAnimationFrame(tick);\n        return () => {\n            alive = false;\n            cancelAnimationFrame(raf);\n        };\n    }, [engaged, reduce, step]);\n\n    const readPointer = (event: React.PointerEvent<HTMLDivElement>) => {\n        const rect = event.currentTarget.getBoundingClientRect();\n        const x = event.clientX - rect.left;\n        const t = clamp(rect.width > 0 ? x / rect.width : 0.5, 0, 1);\n        const previous = lastXRef.current;\n        lastXRef.current = x;\n\n        if (previous !== null) {\n            const dx = x - previous;\n            // Left → right queues the future. Right → left queues the past.\n            if (Math.abs(dx) > 0.5) {\n                pendingRef.current = clamp(pendingRef.current + dx / PX_PER_FRAME, -12, 12);\n                lastMoveRef.current = performance.now();\n            }\n        }\n\n        cruiseRef.current = reduce ? 0 : cruiseRate(t);\n        const dir = Math.abs(pendingRef.current) >= 0.75 ? Math.sign(pendingRef.current) : Math.sign(cruiseRef.current);\n        showDirection(dir);\n        if (!reduce) kick();\n    };\n\n    const onPointerEnter = (event: React.PointerEvent<HTMLDivElement>) => {\n        hoveringRef.current = true;\n        lastXRef.current = null;\n        lastMoveRef.current = performance.now();\n        setHovering(true);\n        readPointer(event);\n    };\n\n    const onPointerLeave = () => {\n        hoveringRef.current = false;\n        cruiseRef.current = 0;\n        lastXRef.current = null;\n        setHovering(false);\n        if (Math.abs(pendingRef.current) < 1) showDirection(0);\n    };\n\n    const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n        if (event.key !== \"ArrowRight\" && event.key !== \"ArrowLeft\") return;\n        event.preventDefault();\n        const now = performance.now();\n        if (now - lastKeyRef.current < 260) return;\n        lastKeyRef.current = now;\n        const dir = event.key === \"ArrowRight\" ? 1 : -1;\n        if (!step(dir)) return;\n        showDirection(dir);\n        window.setTimeout(() => {\n            if (!hoveringRef.current && Math.abs(pendingRef.current) < 1) showDirection(0);\n        }, 640);\n    };\n\n    const onPointerUp = (event: React.PointerEvent<HTMLDivElement>) => {\n        if (!reduce) return;\n        const rect = event.currentTarget.getBoundingClientRect();\n        const t = clamp((event.clientX - rect.left) / (rect.width || 1), 0, 1);\n        const dir = t < 0.5 ? -1 : 1;\n        if (!step(dir)) return;\n        showDirection(dir);\n    };\n\n    const hintsOn = hovering || indicated !== 0;\n    const pastStrength = !hintsOn ? 0 : indicated < 0 ? 1 : indicated > 0 ? 0.28 : index > 0 ? 0.72 : 0.32;\n    const futureStrength = !hintsOn ? 0 : indicated > 0 ? 1 : indicated < 0 ? 0.28 : index < LAST ? 0.72 : 0.32;\n\n    const stills = [];\n    for (let i = index - DEPTH; i <= index + DEPTH; i++) {\n        if (i < 0 || i > LAST) continue;\n        const offset = i - index;\n        const shot = FRAMES[i];\n        stills.push(\n            <div\n                key={shot.id}\n                className={cn(\"absolute inset-0\", Math.abs(offset) <= 1 && \"will-change-transform\")}\n                style={{\n                    ...pose(offset),\n                    transition: ready && !reduce ? TRANSITION : \"none\",\n                }}>\n                <img\n                    src={shot.src}\n                    alt={offset === 0 ? `${shot.title}, ${shot.year}` : \"\"}\n                    aria-hidden={offset !== 0}\n                    width={1200}\n                    height={750}\n                    draggable={false}\n                    decoding=\"async\"\n                    fetchPriority={offset === 0 ? \"high\" : \"auto\"}\n                    loading={Math.abs(offset) <= 2 ? \"eager\" : \"lazy\"}\n                    className=\"h-full w-full object-cover\"\n                />\n            </div>,\n        );\n    }\n\n    return (\n        <div className=\"mx-auto w-full max-w-3xl\">\n            <div\n                role=\"slider\"\n                tabIndex={0}\n                aria-label=\"Photo timeline. Move right for the future, left for the past.\"\n                aria-valuemin={FRAMES[0].year}\n                aria-valuemax={FRAMES[LAST].year}\n                aria-valuenow={frame.year}\n                aria-valuetext={`${frame.title}, ${frame.year}`}\n                aria-orientation=\"horizontal\"\n                data-year={frame.year}\n                onPointerEnter={onPointerEnter}\n                onPointerMove={readPointer}\n                onPointerLeave={onPointerLeave}\n                onPointerUp={onPointerUp}\n                onKeyDown={onKeyDown}\n                className={cn(\n                    \"relative aspect-[16/10] w-full touch-none overflow-hidden rounded-md bg-black select-none\",\n                    \"ring-foreground/10 ring-1 outline-none\",\n                    \"focus-visible:ring-2 focus-visible:ring-white/80 focus-visible:ring-offset-2 focus-visible:ring-offset-black\",\n                    hovering ? \"cursor-ew-resize\" : \"cursor-default\",\n                )}>\n                {stills}\n\n                <div\n                    className=\"pointer-events-none absolute inset-0 z-40 opacity-[0.1] mix-blend-overlay\"\n                    style={{ backgroundImage: GRAIN }}\n                />\n                <div className=\"pointer-events-none absolute inset-0 z-40 bg-[radial-gradient(ellipse_at_center,transparent_50%,rgba(0,0,0,0.42)_100%)]\" />\n\n                <div\n                    className=\"pointer-events-none absolute inset-y-0 left-0 z-40 w-2/5 bg-gradient-to-r from-black/55 to-transparent transition-opacity duration-300\"\n                    style={{ opacity: pastStrength }}\n                />\n                <div\n                    className=\"pointer-events-none absolute inset-y-0 right-0 z-40 w-2/5 bg-gradient-to-l from-black/55 to-transparent transition-opacity duration-300\"\n                    style={{ opacity: futureStrength }}\n                />\n\n                <div\n                    className=\"pointer-events-none absolute top-1/2 left-3 z-50 flex -translate-y-1/2 items-center gap-1 text-white drop-shadow-[0_1px_8px_rgba(0,0,0,0.65)] transition-opacity duration-300 sm:left-4\"\n                    style={{ opacity: pastStrength }}>\n                    <ChevronLeftIcon\n                        className={cn(\"size-4 transition-transform duration-500\", indicated < 0 && \"-translate-x-1\")}\n                        aria-hidden\n                    />\n                    <span className=\"text-[10px] font-medium tracking-[0.22em] uppercase sm:text-[11px]\">Past</span>\n                </div>\n                <div\n                    className=\"pointer-events-none absolute top-1/2 right-3 z-50 flex -translate-y-1/2 items-center gap-1 text-white drop-shadow-[0_1px_8px_rgba(0,0,0,0.65)] transition-opacity duration-300 sm:right-4\"\n                    style={{ opacity: futureStrength }}>\n                    <span className=\"text-[10px] font-medium tracking-[0.22em] uppercase sm:text-[11px]\">Future</span>\n                    <ChevronRightIcon\n                        className={cn(\"size-4 transition-transform duration-500\", indicated > 0 && \"translate-x-1\")}\n                        aria-hidden\n                    />\n                </div>\n\n                <div className=\"pointer-events-none absolute inset-x-0 bottom-0 z-50 bg-gradient-to-t from-black/75 via-black/30 to-transparent px-4 pt-16 pb-3 text-white\">\n                    <div className=\"flex items-end justify-between gap-4\">\n                        <p className=\"truncate text-sm font-medium tracking-wide\">{frame.title}</p>\n                        <NumberFlow\n                            value={frame.year}\n                            format={{ useGrouping: false }}\n                            className=\"font-mono text-2xl font-semibold tabular-nums\"\n                        />\n                    </div>\n                    <div className=\"relative mt-2.5 h-px w-full bg-white/25\">\n                        <div\n                            className=\"absolute top-1/2 size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-white shadow-[0_0_10px_rgba(255,255,255,0.85)]\"\n                            style={{\n                                left: `${(index / LAST) * 100}%`,\n                                transition: ready && !reduce ? `left 0.46s ${EASE}` : \"none\",\n                            }}\n                        />\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};\n"
    }
  ]
}