{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "draggable-card-list",
  "title": "Draggable Card List",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 2 draggable card list variants: https://avaraui.com/view/draggable-card-list. This item holds 2 of them as looks of one component (classic, modern). Skip the question if the user already named one. An interactive reorderable card list with 60fps Motion spring physics, right-side grip handles, and custom card metadata.",
  "dependencies": [
    "gsap",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/draggable-card-list.tsx",
      "content": "\"use client\";\n\nimport { Component, useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport gsap from \"gsap\";\nimport { cn } from \"@/lib/utils\";\nimport { GripVertical, Calendar, ExternalLink, CheckCircle2, Circle } from \"lucide-react\";\nimport { gsapTicker } from \"@/components/custom/blocks/gsap-motion\";\nimport { createSpringFollower, springEase, type SpringFollower } from \"@/components/custom/blocks/motion-curves\";\n\nexport interface DraggableCardItem {\n    id: string | number;\n    title: string;\n    description?: string;\n    date?: string;\n    badge?: string;\n    badgeStyle?: string;\n    accentColor?: string;\n    hoverBorderColor?: string;\n    linkText?: string;\n    linkUrl?: string;\n    completed?: boolean;\n    category?: string;\n}\n\nexport interface DraggableCardListProps {\n    /** List of draggable card items */\n    items?: DraggableCardItem[];\n    /** Card style variant: \"classic\" | \"modern\" (default: \"classic\") */\n    variant?: \"classic\" | \"modern\";\n    /** Callback fired when items are reordered */\n    onReorder?: (newItems: DraggableCardItem[]) => void;\n    /** Callback fired when an item's completion status is toggled */\n    onToggleComplete?: (id: string | number, completed: boolean) => void;\n    /** Optional title heading text above the list */\n    title?: string;\n    /** Optional subtitle text under the heading */\n    subtitle?: string;\n    /** Drag handle position: \"right\" or \"left\" (default: \"right\") */\n    dragHandlePosition?: \"right\" | \"left\";\n    /** Enable interactive completion checkboxes (default: false) */\n    enableCheckboxes?: boolean;\n    /** Enable category badges (default: true) */\n    enableBadges?: boolean;\n    /** Container class name */\n    className?: string;\n    /** Card container class name */\n    cardClassName?: string;\n}\n\nconst DEFAULT_ITEMS: DraggableCardItem[] = [\n    {\n        id: \"1\",\n        title: \"System Performance Audit\",\n        description: \"Optimize bundle splitting, reduce LCP to 0.8s, and tree-shake unused assets\",\n        date: \"2026-08-30\",\n        badge: \"PERFORMANCE\",\n        badgeStyle: \"bg-amber-500/10 text-amber-700 dark:text-amber-300 border border-amber-500/30\",\n        accentColor: \"from-amber-400 via-orange-500 to-yellow-500\",\n        hoverBorderColor: \"hover:border-amber-500/80 dark:hover:border-amber-400/80\",\n        completed: false,\n    },\n    {\n        id: \"2\",\n        title: \"Security Vulnerability Patch\",\n        description: \"Upgrade dependencies, sanitize input payloads, and rotate API tokens\",\n        date: \"2026-08-30\",\n        badge: \"SECURITY\",\n        badgeStyle: \"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border border-emerald-500/30\",\n        accentColor: \"from-emerald-400 via-teal-500 to-cyan-500\",\n        hoverBorderColor: \"hover:border-emerald-500/80 dark:hover:border-emerald-400/80\",\n        completed: false,\n    },\n    {\n        id: \"3\",\n        title: \"UI Component Library Release\",\n        description: \"Publish version 2.4 with dark mode token updates and accessible aria roles\",\n        date: \"2026-08-30\",\n        badge: \"LIBRARY\",\n        badgeStyle: \"bg-purple-500/10 text-purple-700 dark:text-purple-300 border border-purple-500/30\",\n        accentColor: \"from-purple-400 via-indigo-500 to-violet-500\",\n        hoverBorderColor: \"hover:border-purple-500/80 dark:hover:border-purple-400/80\",\n        completed: false,\n    },\n    {\n        id: \"4\",\n        title: \"Database Schema Migration\",\n        description: \"Execute zero-downtime PostgreSQL indexing and partition query optimization\",\n        date: \"2026-08-30\",\n        badge: \"DATABASE\",\n        badgeStyle: \"bg-blue-500/10 text-blue-700 dark:text-blue-300 border border-blue-500/30\",\n        accentColor: \"from-blue-400 via-indigo-500 to-cyan-500\",\n        hoverBorderColor: \"hover:border-blue-500/80 dark:hover:border-blue-400/80\",\n        linkText: \"View database migration logs\",\n        linkUrl: \"#\",\n        completed: false,\n    },\n];\n\n/** Lift while dragging, and the glide of cards moving out of the way. */\nconst CARD_SPRING = { stiffness: 350, damping: 25 };\nconst LAYOUT = springEase(CARD_SPRING);\n/** The spring that pulls a released card home. */\nconst RETURN_SPRING = { stiffness: 200, damping: 40 };\n\n/** Drag and reorder only answer the primary pointer. */\nconst isPrimaryPointer = (e: PointerEvent) =>\n    e.pointerType === \"mouse\" ? e.button === 0 : e.isPrimary !== false;\n\n/** Pointer velocity (px/s) over the last 100ms, sampled like Motion's pan gesture. */\nfunction panVelocity(history: { y: number; t: number }[]) {\n    if (history.length < 2) return 0;\n    const last = history[history.length - 1];\n    let from = history[0];\n    for (let i = history.length - 1; i >= 0; i--) {\n        from = history[i];\n        if (last.t - from.t > 100) break;\n    }\n    const time = (last.t - from.t) / 1000;\n    if (time === 0) return 0;\n    const v = (last.y - from.y) / time;\n    return Number.isFinite(v) ? v : 0;\n}\n\n/** What each card element needs from the list: to be known, and to start a drag. */\ninterface Reorderer {\n    register: (id: string, el: HTMLLIElement | null) => void;\n    press: (id: string, e: PointerEvent) => void;\n}\n\n/** A card's motion: drag offset, layout-glide offset and lift, painted as one transform. */\ninterface CardMotion {\n    el: HTMLLIElement;\n    y: number;\n    layoutY: number;\n    scale: number;\n    lift: SpringFollower;\n}\n\nfunction paintCard(m: CardMotion) {\n    const offset = m.y + m.layoutY;\n    m.el.style.transform = offset || m.scale !== 1 ? `translateY(${offset}px) scale(${m.scale})` : \"none\";\n    // Above its neighbours while displaced by a drag, as Reorder.Item does.\n    m.el.style.zIndex = m.y ? \"1\" : \"unset\";\n}\n\n/** Styles every card carries; a card that drags from anywhere also blocks\n *  text selection and the ghost image, and leaves horizontal pans to the page. */\nconst CARD_STYLE: React.CSSProperties = { zIndex: \"unset\" };\nconst WHOLE_CARD_DRAG_STYLE: React.CSSProperties = {\n    ...CARD_STYLE,\n    userSelect: \"none\",\n    WebkitUserSelect: \"none\",\n    WebkitTouchCallout: \"none\",\n    touchAction: \"pan-x\",\n};\n\ninterface SingleCardItemProps {\n    reorder: Reorderer;\n    item: DraggableCardItem;\n    variant: \"classic\" | \"modern\";\n    dragHandlePosition: \"right\" | \"left\";\n    enableCheckboxes: boolean;\n    enableBadges: boolean;\n    cardClassName?: string;\n    onToggle?: (id: string | number) => void;\n}\n\nfunction SingleCardItem({\n    reorder,\n    item,\n    variant,\n    dragHandlePosition,\n    enableCheckboxes,\n    enableBadges,\n    cardClassName,\n    onToggle,\n}: SingleCardItemProps) {\n    const id = String(item.id);\n    const ref = useCallback((el: HTMLLIElement | null) => reorder.register(id, el), [reorder, id]);\n\n    const renderDragHandle = () => (\n        <div\n            onPointerDown={(e) => reorder.press(id, e.nativeEvent)}\n            aria-label=\"Drag to reorder\"\n            className={cn(\n                // touch-none: the handle's vertical drag must not scroll the page instead.\n                \"p-2.5 rounded-2xl text-muted-foreground/60 cursor-grab active:cursor-grabbing shrink-0 touch-none bg-muted/60 border border-border/50 hover:bg-primary hover:text-primary-foreground hover:border-primary/30 transition-all duration-200\"\n            )}\n        >\n            <GripVertical className=\"w-5 h-5\" />\n        </div>\n    );\n\n    // VARIANT 1: Modern (Glass-Glow Card + Left Accent Color Border Shift on Hover)\n    if (variant === \"modern\") {\n        return (\n            <li\n                ref={ref}\n                id={id}\n                style={CARD_STYLE}\n                className={cn(\n                    \"relative w-full overflow-hidden rounded-2xl border border-border/80 bg-gradient-to-r from-card via-card to-primary/5 dark:to-primary/10 backdrop-blur-2xl p-4 sm:p-5 shadow-none transition-colors select-none group flex items-start justify-between gap-3\",\n                    item.hoverBorderColor || \"hover:border-primary/80\",\n                    item.completed && \"opacity-60 bg-muted/40\",\n                    cardClassName\n                )}\n            >\n                {/* Glowing Left Side Gradient Bar */}\n                <div\n                    className={cn(\n                        \"absolute left-0 top-0 bottom-0 w-1.5 bg-gradient-to-b\",\n                        item.accentColor || \"from-primary via-primary/80 to-primary/40\"\n                    )}\n                />\n\n                {dragHandlePosition === \"left\" && renderDragHandle()}\n\n                {/* Main Card Content */}\n                <div className=\"flex-1 min-w-0 space-y-1.5 pl-2\">\n                    {/* Header Row: Title & Right-Aligned Badge */}\n                    <div className=\"flex items-start justify-between gap-2\">\n                        <div className=\"flex items-center gap-2 min-w-0 flex-1\">\n                            {enableCheckboxes && (\n                                <button\n                                    type=\"button\"\n                                    onClick={() => onToggle?.(item.id)}\n                                    className=\"text-muted-foreground hover:text-primary transition-colors cursor-pointer shrink-0\"\n                                >\n                                    {item.completed ? (\n                                        <CheckCircle2 className=\"w-4 h-4 text-emerald-500 fill-emerald-500/20\" />\n                                    ) : (\n                                        <Circle className=\"w-4 h-4\" />\n                                    )}\n                                </button>\n                            )}\n                            <h3 className={cn(\"text-base font-semibold tracking-tight text-foreground leading-tight\", item.completed && \"line-through text-muted-foreground\")}>\n                                {item.title}\n                            </h3>\n                        </div>\n\n                        {enableBadges && item.badge && (\n                            <span\n                                className={cn(\n                                    \"px-2.5 py-0.5 rounded-md text-[9px] font-extrabold uppercase tracking-wider shrink-0 shadow-2xs ml-auto\",\n                                    item.badgeStyle || \"bg-primary/10 text-primary border border-primary/30\"\n                                )}\n                            >\n                                {item.badge}\n                            </span>\n                        )}\n                    </div>\n\n                    {item.description && (\n                        <p className=\"text-xs font-medium text-muted-foreground leading-relaxed\">\n                            {item.description}\n                        </p>\n                    )}\n\n                    {/* Footer Row */}\n                    <div className=\"pt-2 border-t border-border/40 flex items-center justify-between gap-2 flex-wrap text-xs text-muted-foreground/80 font-mono\">\n                        {item.date && (\n                            <div className=\"flex items-center gap-1.5 text-[11px] font-semibold\">\n                                <Calendar className=\"w-3.5 h-3.5 text-primary\" />\n                                <span>{item.date}</span>\n                            </div>\n                        )}\n\n                        {item.linkText && (\n                            <a\n                                href={item.linkUrl || \"#\"}\n                                onClick={(e) => {\n                                    if (!item.linkUrl || item.linkUrl === \"#\") e.preventDefault();\n                                }}\n                                className=\"inline-flex items-center gap-1 text-[11px] font-sans font-semibold text-primary hover:underline hover:text-primary/80 transition-colors ml-auto\"\n                            >\n                                <span>{item.linkText}</span>\n                                <ExternalLink className=\"w-3 h-3\" />\n                            </a>\n                        )}\n                    </div>\n                </div>\n\n                {dragHandlePosition === \"right\" && renderDragHandle()}\n            </li>\n        );\n    }\n\n    // VARIANT 2: Classic (Left Accent Color Border Shift on Hover, Zero Shadow)\n    return (\n        <li\n            ref={ref}\n            id={id}\n            draggable={false}\n            style={WHOLE_CARD_DRAG_STYLE}\n            onPointerDown={(e) => reorder.press(id, e.nativeEvent)}\n            className={cn(\n                \"relative w-full rounded-2xl border border-border/80 bg-card backdrop-blur-xl p-4 sm:p-5 shadow-none transition-colors select-none group flex items-start justify-between gap-3 cursor-grab active:cursor-grabbing\",\n                item.hoverBorderColor || \"hover:border-primary/80\",\n                item.completed && \"opacity-60 bg-muted/40\",\n                cardClassName\n            )}\n        >\n            {dragHandlePosition === \"left\" && renderDragHandle()}\n\n            {/* Main Card Content */}\n            <div className=\"flex-1 min-w-0 space-y-1.5\">\n                <div className=\"flex items-center gap-2 flex-wrap\">\n                    {enableCheckboxes && (\n                        <button\n                            type=\"button\"\n                            onClick={() => onToggle?.(item.id)}\n                            className=\"text-muted-foreground hover:text-primary transition-colors cursor-pointer shrink-0\"\n                        >\n                            {item.completed ? (\n                                <CheckCircle2 className=\"w-4 h-4 text-emerald-500 fill-emerald-500/20\" />\n                            ) : (\n                                <Circle className=\"w-4 h-4\" />\n                            )}\n                        </button>\n                    )}\n                    <h3 className={cn(\"text-base font-semibold tracking-tight text-foreground leading-tight\", item.completed && \"line-through text-muted-foreground\")}>\n                        {item.title}\n                    </h3>\n\n                    {enableBadges && item.badge && (\n                        <span\n                            className={cn(\n                                \"px-2.5 py-0.5 rounded-md text-[9px] font-extrabold uppercase tracking-wider ml-auto sm:ml-0 shadow-2xs\",\n                                item.badgeStyle || \"bg-primary/10 text-primary border border-primary/30\"\n                            )}\n                        >\n                            {item.badge}\n                        </span>\n                    )}\n                </div>\n\n                {item.description && (\n                    <p className=\"text-xs font-medium text-muted-foreground leading-relaxed\">\n                        {item.description}\n                    </p>\n                )}\n\n                <div className=\"pt-1 flex items-center justify-between gap-2 flex-wrap text-xs text-muted-foreground/80 font-mono\">\n                    {item.date && (\n                        <div className=\"flex items-center gap-1 text-[11px]\">\n                            <Calendar className=\"w-3.5 h-3.5 opacity-70\" />\n                            <span>{item.date}</span>\n                        </div>\n                    )}\n\n                    {item.linkText && (\n                        <a\n                            href={item.linkUrl || \"#\"}\n                            onClick={(e) => {\n                                if (!item.linkUrl || item.linkUrl === \"#\") e.preventDefault();\n                            }}\n                            className=\"inline-flex items-center gap-1 text-[11px] font-sans font-semibold text-primary hover:underline hover:text-primary/80 transition-colors ml-auto\"\n                        >\n                            <span>{item.linkText}</span>\n                            <ExternalLink className=\"w-3 h-3\" />\n                        </a>\n                    )}\n                </div>\n            </div>\n\n            {dragHandlePosition === \"right\" && renderDragHandle()}\n        </li>\n    );\n}\n\ninterface DragSession {\n    id: string;\n    event: PointerEvent;\n    pointerId: number;\n    startX: number;\n    startY: number;\n    /** The card's drag offset when the drag began (plus any layout jump since). */\n    origin: number;\n    started: boolean;\n    history: { y: number; t: number }[];\n    /** Rendered size over layout size, so a list inside a scaled parent still\n     *  follows the pointer 1:1 (pointer moves are in page pixels, the card\n     *  moves in its own). */\n    scale: number;\n}\n\n/**\n * Vertical drag-to-reorder, on the rules Motion's Reorder uses: a press stops\n * the card where it is; it starts following the pointer 1:1 once the pointer\n * has moved 3px; while moving down it swaps with the next card as soon as its\n * bottom edge passes that card's middle (moving up: its top edge, the previous\n * card's middle), one swap per move. The dragged card keeps its place under\n * the pointer across a swap, the others glide to their new slots, and on\n * release it springs home.\n */\nfunction createReorderer() {\n    // The reorderer owns its mutable state, so the component never touches it\n    // during render; the list and callback are synced in after each commit.\n    const cards = { current: new Map<string, CardMotion>() };\n    const drag = { current: null as DragSession | null };\n    const list = { current: [] as DraggableCardItem[] };\n    const reorder = { current: (() => {}) as (items: DraggableCardItem[]) => void };\n\n    const goHome = (m: CardMotion) => {\n        gsap.killTweensOf(m, \"y\");\n        const from = m.y;\n        if (!from) return;\n        // Settles once within 1px of home, where Motion's release spring stops.\n        if (Math.abs(from) <= 1) {\n            m.y = 0;\n            paintCard(m);\n            return;\n        }\n        const { duration, ease } = springEase({ ...RETURN_SPRING, restDelta: 1 / Math.abs(from) });\n        gsap.to(m, { y: 0, duration, ease, onUpdate: () => paintCard(m) });\n    };\n\n    const swapIfPast = (id: string, offset: number, velocity: number) => {\n        const items = list.current;\n        const index = items.findIndex((i) => String(i.id) === id);\n        if (index === -1) return;\n        const dir = velocity > 0 ? 1 : -1;\n        const next = items[index + dir];\n        const card = cards.current.get(id)?.el;\n        const other = next && cards.current.get(String(next.id))?.el;\n        if (!card || !other) return;\n        const otherCentre = other.offsetTop + other.offsetHeight / 2;\n        const past =\n            dir === 1\n                ? card.offsetTop + card.offsetHeight + offset > otherCentre\n                : card.offsetTop + offset < otherCentre;\n        if (!past) return;\n        const reordered = [...items];\n        const [moved] = reordered.splice(index, 1);\n        reordered.splice(index + dir, 0, moved);\n        // Commit now, so the layout effect re-anchors the dragged card before\n        // the next frame paints it one slot off.\n        flushSync(() => reorder.current(reordered));\n    };\n\n    const move = (e: PointerEvent) => {\n        const s = drag.current;\n        if (!s || e.pointerId !== s.pointerId) return;\n        const m = cards.current.get(s.id);\n        if (!m) return;\n        s.history.push({ y: e.pageY, t: performance.now() });\n        const dy = (e.pageY - s.startY) / s.scale;\n        if (!s.started) {\n            if (Math.hypot(e.pageX - s.startX, dy) < 3) return;\n            s.started = true;\n            s.origin = m.y;\n            m.lift.set(1.02);\n        }\n        m.y = s.origin + dy;\n        paintCard(m);\n        const velocity = panVelocity(s.history);\n        if (velocity) swapIfPast(s.id, m.y, velocity);\n    };\n\n    const end = (e: PointerEvent) => {\n        const s = drag.current;\n        if (!s || e.pointerId !== s.pointerId) return;\n        finish();\n    };\n\n    const detach = () => {\n        window.removeEventListener(\"pointermove\", move);\n        window.removeEventListener(\"pointerup\", end);\n        window.removeEventListener(\"pointercancel\", end);\n    };\n\n    const finish = () => {\n        const s = drag.current;\n        drag.current = null;\n        detach();\n        const m = s && cards.current.get(s.id);\n        if (!s || !m) return;\n        if (s.started) m.lift.set(1);\n        goHome(m);\n    };\n\n    const reorderer: Reorderer & {\n        sync: (items: DraggableCardItem[], onReorder: (items: DraggableCardItem[]) => void) => void;\n        snapshot: () => Map<string, number>;\n        settle: (before: Map<string, number>) => void;\n        destroy: () => void;\n    } = {\n        /** Latest list and reorder callback, for the next pointer move. */\n        sync(items, onReorder) {\n            list.current = items;\n            reorder.current = onReorder;\n        },\n        /** Where each card's layout box sits right now. */\n        snapshot() {\n            return new Map(\n                Array.from(cards.current, ([id, m]) => [id, m.el.offsetTop] as const),\n            );\n        },\n        /** After a commit: animate every card from its `before` slot to its new one. */\n        settle(before) {\n            cards.current.forEach((m, id) => {\n                const was = before.get(id);\n                if (was === undefined) return;\n                const delta = was - m.el.offsetTop;\n                if (!delta) return;\n                const s = drag.current;\n                if (s?.started && s.id === id) {\n                    // The dragged card stays under the pointer: its jump to the\n                    // new slot is folded into the drag offset.\n                    s.origin += delta;\n                    m.y += delta;\n                    paintCard(m);\n                    return;\n                }\n                // Everyone else glides from where they were to their new slot.\n                gsap.killTweensOf(m, \"layoutY\");\n                m.layoutY += delta;\n                paintCard(m);\n                gsap.to(m, {\n                    layoutY: 0,\n                    duration: LAYOUT.duration,\n                    ease: LAYOUT.ease,\n                    onUpdate: () => paintCard(m),\n                });\n            });\n        },\n        register(id, el) {\n            const old = cards.current.get(id);\n            if (old && old.el === el) return;\n            if (old) {\n                old.lift.destroy();\n                gsap.killTweensOf(old);\n                cards.current.delete(id);\n            }\n            if (!el) return;\n            const m: CardMotion = { el, y: 0, layoutY: 0, scale: 1, lift: null as unknown as SpringFollower };\n            m.lift = createSpringFollower(\n                1,\n                (v) => {\n                    m.scale = v;\n                    paintCard(m);\n                },\n                { ...CARD_SPRING, ticker: gsapTicker },\n            );\n            cards.current.set(id, m);\n        },\n        press(id, e) {\n            // The modern handle and the card both report the same press.\n            if (drag.current?.event === e || !isPrimaryPointer(e)) return;\n            if (drag.current) finish();\n            const m = cards.current.get(id);\n            if (!m) return;\n            gsap.killTweensOf(m, \"y\");\n            const scale = m.el.offsetHeight ? m.el.getBoundingClientRect().height / m.el.offsetHeight : 1;\n            drag.current = {\n                id,\n                event: e,\n                pointerId: e.pointerId,\n                startX: e.pageX,\n                startY: e.pageY,\n                origin: m.y,\n                started: false,\n                history: [{ y: e.pageY, t: performance.now() }],\n                scale: scale || 1,\n            };\n            window.addEventListener(\"pointermove\", move);\n            window.addEventListener(\"pointerup\", end);\n            window.addEventListener(\"pointercancel\", end);\n        },\n        destroy() {\n            drag.current = null;\n            detach();\n        },\n    };\n    return reorderer;\n}\n\nexport function DraggableCardList({\n    items: initialItems = DEFAULT_ITEMS,\n    variant = \"classic\",\n    onReorder,\n    onToggleComplete,\n    title,\n    subtitle,\n    dragHandlePosition = \"right\",\n    enableCheckboxes = false,\n    enableBadges = true,\n    className,\n    cardClassName,\n}: DraggableCardListProps) {\n    const [itemList, setItemList] = useState<DraggableCardItem[]>(initialItems);\n    // Re-seed when the caller hands over a different array. Doing it here\n    // rather than in an effect avoids rendering the previous list first.\n    const [seededFrom, setSeededFrom] = useState(initialItems);\n    if (seededFrom !== initialItems) {\n        setSeededFrom(initialItems);\n        setItemList(initialItems);\n    }\n\n    const handleReorder = (newItems: DraggableCardItem[]) => {\n        setItemList(newItems);\n        if (onReorder) {\n            onReorder(newItems);\n        }\n    };\n\n    // ── Drag-to-reorder ──────────────────────────────────────────────────\n    const [reorder] = useState(createReorderer);\n    useEffect(() => () => reorder.destroy(), [reorder]);\n\n    // Where each card's layout box sat before this render commits — the\n    // snapshot a layout animation starts from. Taken by <BeforeCommit> just\n    // before React mutates the DOM.\n    const before = useRef(new Map<string, number>());\n    const captureBefore = () => {\n        before.current = reorder.snapshot();\n    };\n    useLayoutEffect(() => {\n        reorder.sync(itemList, handleReorder);\n        reorder.settle(before.current);\n    });\n\n    const handleToggleComplete = (id: string | number) => {\n        const updated = itemList.map((item) =>\n            item.id === id ? { ...item, completed: !item.completed } : item\n        );\n        setItemList(updated);\n        const target = updated.find((i) => i.id === id);\n        if (onToggleComplete && target) {\n            onToggleComplete(id, target.completed || false);\n        }\n    };\n\n    return (\n        <BeforeCommit capture={captureBefore}>\n            <div className={cn(\"w-full max-w-xl mx-auto space-y-4 py-2 select-none\", className)}>\n                {/* Optional Title Header */}\n                {title && (\n                    <div className=\"text-center space-y-1 mb-6\">\n                        <h2 className=\"text-xl sm:text-2xl font-bold tracking-tight text-foreground\">\n                            {title}\n                        </h2>\n                        {subtitle && (\n                            <p className=\"text-xs sm:text-sm font-medium text-muted-foreground\">\n                                {subtitle}\n                            </p>\n                        )}\n                    </div>\n                )}\n\n                {/* Reorder Group Container */}\n                <ul className=\"space-y-3\">\n                    {itemList.map((item) => (\n                        <SingleCardItem\n                            key={item.id}\n                            reorder={reorder}\n                            item={item}\n                            variant={variant}\n                            dragHandlePosition={dragHandlePosition}\n                            enableCheckboxes={enableCheckboxes}\n                            enableBadges={enableBadges}\n                            cardClassName={cardClassName}\n                            onToggle={handleToggleComplete}\n                        />\n                    ))}\n                </ul>\n            </div>\n        </BeforeCommit>\n    );\n}\n\n/**\n * Runs `capture` on every update, just before React touches the DOM (the\n * commit's before-mutation phase), so the list can record where its cards sat\n * before the new order lands. Renders nothing of its own.\n */\nclass BeforeCommit extends Component<{\n    capture: () => void;\n    children: React.ReactNode;\n}> {\n    getSnapshotBeforeUpdate() {\n        this.props.capture();\n        return null;\n    }\n\n    // Required alongside getSnapshotBeforeUpdate; the work happens in the list's layout effect.\n    componentDidUpdate() {}\n\n    render() {\n        return this.props.children;\n    }\n}\n\nexport default DraggableCardList;\n",
      "type": "registry:component",
      "target": "components/custom/draggable-card-list.tsx"
    },
    {
      "path": "src/components/custom/blocks/gsap-motion.ts",
      "content": "import gsap from \"gsap\";\nimport { cubicBezier, type FrameTicker } from \"./motion-curves\";\n\n/**\n * GSAP-side glue for the GSAP builds of components that also ship a Motion\n * Motion twin. Kept apart from motion-curves.ts so the library-free curves\n * never pull GSAP into a CSS or Motion build.\n */\n\n/** `gsap.ticker` as a FrameTicker, so spring followers run on GSAP's loop. */\nexport const gsapTicker: FrameTicker = {\n  add(callback) {\n    const tick = (_time: number, deltaTime: number) => callback(deltaTime);\n    gsap.ticker.add(tick);\n    return () => gsap.ticker.remove(tick);\n  },\n};\n\n/** A Motion / CSS cubic-bezier array as a GSAP ease. */\nexport const bezierEase = (curve: readonly [number, number, number, number] | readonly number[]) =>\n  cubicBezier(curve[0], curve[1], curve[2], curve[3]);\n\n/** `(prefers-reduced-motion: reduce)` right now. */\nexport const prefersReducedMotion = () =>\n  typeof window !== \"undefined\" &&\n  window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/gsap-motion.ts"
    },
    {
      "path": "src/components/custom/blocks/motion-curves.ts",
      "content": "/**\n * Motion curves with no animation library behind them.\n *\n * The components here ship as CSS, GSAP or Motion builds that must move\n * identically, so the curves are computed once, from the same numbers, and\n * handed to whichever engine runs them:\n *\n *   - `cubicBezier(x1, y1, x2, y2)` → an easing function (GSAP accepts any\n *     `(progress) => value` as `ease`), exact for Motion's `ease: [..]` arrays\n *     and for CSS `cubic-bezier()`.\n *   - `spring({ stiffness, damping, mass })` → the analytic solution Motion\n *     Motion uses, as an easing function plus the time it takes to settle, or\n *     as a CSS `linear()` string for a fixed start and end.\n *   - `createSpringFollower` → a value that chases a moving target through the\n *     same spring every frame, like Motion's `useSpring`, for pointer-driven\n *     motion that no fixed curve can describe.\n */\n\n// ---------------------------------------------------------------------------\n// Cubic bezier\n// ---------------------------------------------------------------------------\n\n/**\n * The CSS / Motion cubic-bezier as a function of progress. Newton-Raphson\n * with a bisection fallback, the same solver browsers use.\n */\nexport function cubicBezier(x1: number, y1: number, x2: number, y2: number) {\n  if (x1 === y1 && x2 === y2) return (t: number) => t;\n\n  const a = (p1: number, p2: number) => 1 - 3 * p2 + 3 * p1;\n  const b = (p1: number, p2: number) => 3 * p2 - 6 * p1;\n  const c = (p1: number) => 3 * p1;\n  const at = (t: number, p1: number, p2: number) =>\n    ((a(p1, p2) * t + b(p1, p2)) * t + c(p1)) * t;\n  const slope = (t: number, p1: number, p2: number) =>\n    3 * a(p1, p2) * t * t + 2 * b(p1, p2) * t + c(p1);\n\n  const solveX = (x: number) => {\n    let t = x;\n    for (let i = 0; i < 8; i++) {\n      const s = slope(t, x1, x2);\n      if (Math.abs(s) < 1e-6) break;\n      const err = at(t, x1, x2) - x;\n      if (Math.abs(err) < 1e-7) return t;\n      t -= err / s;\n    }\n    let lo = 0;\n    let hi = 1;\n    t = x;\n    for (let i = 0; i < 30 && hi - lo > 1e-7; i++) {\n      const value = at(t, x1, x2);\n      if (value < x) lo = t;\n      else hi = t;\n      t = (lo + hi) / 2;\n    }\n    return t;\n  };\n\n  return (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : at(solveX(x), y1, y2));\n}\n\n/** Motion's named eases, as the cubic-beziers they are. */\nexport const MOTION_EASE = {\n  linear: [0, 0, 1, 1],\n  easeIn: [0.42, 0, 1, 1],\n  easeOut: [0, 0, 0.58, 1],\n  easeInOut: [0.42, 0, 0.58, 1],\n  circIn: [0.55, 0, 1, 0.45],\n  circOut: [0.55, 0, 0.45, 1],\n  circInOut: [0.85, 0, 0.15, 1],\n  backIn: [0.31, 0.01, 0.66, -0.59],\n  backOut: [0.33, 1.53, 0.69, 0.99],\n  anticipate: [0.66, -0.56, 0.34, 1.35],\n} as const;\n\n/**\n * Motion's default layout transition (`layout` / `layoutId`):\n * `{ duration: 0.45, ease: [0.4, 0, 0.1, 1] }`.\n */\nexport const LAYOUT_TRANSITION = { duration: 0.45, ease: [0.4, 0, 0.1, 1] as const };\n\n// ---------------------------------------------------------------------------\n// Spring\n// ---------------------------------------------------------------------------\n\nexport interface SpringOptions {\n  /** Motion default 100. */\n  stiffness?: number;\n  /** Motion default 10. */\n  damping?: number;\n  /** Motion default 1. */\n  mass?: number;\n  /** Starting velocity, in units of the whole distance per second. */\n  velocity?: number;\n  /** How close to the end counts as settled, as a fraction of the distance. */\n  restDelta?: number;\n}\n\n/**\n * Normalised position (0 → 1) of a spring released from 0 towards 1, at time\n * `t` seconds. The closed-form solution Motion's `spring()` generator\n * uses for the under-, critically and over-damped cases.\n */\nexport function springAt(options: SpringOptions = {}) {\n  const { stiffness = 100, damping = 10, mass = 1, velocity = 0 } = options;\n  const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n  const omega0 = Math.sqrt(stiffness / mass);\n  // Motion's convention: distance still to cover, velocity toward it negated.\n  const delta = 1;\n  const v0 = -velocity;\n\n  if (zeta < 1) {\n    const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);\n    return (t: number) => {\n      const envelope = Math.exp(-zeta * omega0 * t);\n      return (\n        1 -\n        envelope *\n          (((v0 + zeta * omega0 * delta) / omegaD) * Math.sin(omegaD * t) +\n            delta * Math.cos(omegaD * t))\n      );\n    };\n  }\n  if (zeta === 1) {\n    return (t: number) => 1 - Math.exp(-omega0 * t) * (delta + (v0 + omega0 * delta) * t);\n  }\n  const omegaD = omega0 * Math.sqrt(zeta * zeta - 1);\n  return (t: number) => {\n    const envelope = Math.exp(-zeta * omega0 * t);\n    const freq = Math.min(omegaD * t, 300);\n    return (\n      1 -\n      (envelope *\n        ((v0 + zeta * omega0 * delta) * Math.sinh(freq) + omegaD * delta * Math.cosh(freq))) /\n        omegaD\n    );\n  };\n}\n\n/** Seconds until the spring stays within `restDelta` of its end. */\nexport function springDuration(options: SpringOptions = {}) {\n  const at = springAt(options);\n  const restDelta = options.restDelta ?? 0.001;\n  const step = 1 / 240;\n  let lastOutside = 0;\n  for (let t = 0; t <= 10; t += step) {\n    if (Math.abs(1 - at(t)) > restDelta) lastOutside = t;\n    else if (t - lastOutside > 0.1) break;\n  }\n  return Math.max(lastOutside + step, step);\n}\n\n/**\n * A spring as a duration and an easing function over it — what GSAP takes:\n *\n *   const { duration, ease } = springEase({ stiffness: 300, damping: 20 });\n *   gsap.to(el, { y: 0, duration, ease });\n *\n * Exact for a fixed start and end; a spring that has to react mid-flight to a\n * new target needs `createSpringFollower` instead.\n */\nexport function springEase(options: SpringOptions = {}) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  return {\n    duration,\n    ease: (progress: number) => (progress >= 1 ? 1 : at(progress * duration)),\n  };\n}\n\n/**\n * A spring as a CSS `linear()` easing and its duration in ms, for\n * `transition` / `animation` with a fixed start and end.\n *\n *   const { easing, duration } = springLinear({ stiffness: 400, damping: 30 });\n *   el.style.transition = `transform ${duration}ms ${easing}`;\n */\nexport function springLinear(options: SpringOptions = {}, pointsPerSecond = 60) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  const count = Math.max(Math.ceil(duration * pointsPerSecond), 8);\n  const points: string[] = [];\n  for (let i = 0; i <= count; i++) {\n    const t = (i / count) * duration;\n    points.push(String(Math.round((i === count ? 1 : at(t)) * 10000) / 10000));\n  }\n  return { easing: `linear(${points.join(\", \")})`, duration: Math.round(duration * 1000) };\n}\n\n// ---------------------------------------------------------------------------\n// Spring follower (useSpring equivalent)\n// ---------------------------------------------------------------------------\n\n/** Something that calls back once per frame with the time since the last, in ms. */\nexport interface FrameTicker {\n  add: (callback: (deltaMs: number) => void) => () => void;\n}\n\n/** requestAnimationFrame as a ticker — the library-free default. */\nexport const rafTicker: FrameTicker = {\n  add(callback) {\n    let last = performance.now();\n    let frame = requestAnimationFrame(function tick(now) {\n      callback(now - last);\n      last = now;\n      frame = requestAnimationFrame(tick);\n    });\n    return () => cancelAnimationFrame(frame);\n  },\n};\n\nexport interface SpringFollower {\n  /** Chase a new target from wherever the value is now, keeping its velocity. */\n  set: (target: number) => void;\n  /** Move to a value instantly, with no motion. */\n  jump: (value: number) => void;\n  get: () => number;\n  destroy: () => void;\n}\n\n/**\n * A value that follows its target through a spring, integrating the same\n * equation of motion Motion's `useSpring` solves — so a pointer-driven spring\n * reads the same in every build. Runs only while moving; `onUpdate` receives\n * each new value.\n */\nexport function createSpringFollower(\n  initial: number,\n  onUpdate: (value: number) => void,\n  options: SpringOptions & { restSpeed?: number; ticker?: FrameTicker } = {},\n): SpringFollower {\n  const { stiffness = 100, damping = 10, mass = 1, ticker = rafTicker } = options;\n  const restDelta = options.restDelta ?? 0.01;\n  const restSpeed = options.restSpeed ?? 0.01;\n  let value = initial;\n  let target = initial;\n  let velocity = 0;\n  let stop: (() => void) | null = null;\n\n  const step = (deltaMs: number) => {\n    // Fixed 1ms sub-steps keep the integration stable for stiff springs and\n    // independent of the frame rate.\n    const steps = Math.min(Math.max(Math.round(deltaMs), 1), 250);\n    for (let i = 0; i < steps; i++) {\n      const force = -stiffness * (value - target) - damping * velocity;\n      velocity += (force / mass) * 0.001;\n      value += velocity * 0.001;\n    }\n    if (Math.abs(target - value) < restDelta && Math.abs(velocity) < restSpeed) {\n      value = target;\n      velocity = 0;\n      stop?.();\n      stop = null;\n    }\n    onUpdate(value);\n  };\n\n  return {\n    set(next) {\n      target = next;\n      if (!stop && value !== target) stop = ticker.add(step);\n    },\n    jump(next) {\n      stop?.();\n      stop = null;\n      value = target = next;\n      velocity = 0;\n      onUpdate(value);\n    },\n    get: () => value,\n    destroy() {\n      stop?.();\n      stop = null;\n    },\n  };\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/motion-curves.ts"
    }
  ],
  "docs": "Named exports: DraggableCardList, DraggableCardItem. Accepts `items` ({ id, title, description, date, badge, linkText, linkUrl, completed }), `onReorder`, `title`, `dragHandlePosition` ('right' | 'left'), `enableCheckboxes`, and `enableBadges`.",
  "categories": [
    "data-display",
    "layout"
  ],
  "type": "registry:component"
}
