{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-pane",
  "type": "registry:ui",
  "title": "Split Pane",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "A fluid, accessible split pane component supporting horizontal and vertical orientations, pointer-capture dragging, double-click collapse, keyboard navigation, and localStorage persistence.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/split-pane.tsx",
      "content": "\"use client\";\n\nimport React, {\n  useState,\n  useRef,\n  useEffect,\n  useCallback,\n  useId,\n  forwardRef,\n  Children,\n  type ReactNode,\n  type PointerEvent as ReactPointerEvent,\n  type KeyboardEvent as ReactKeyboardEvent,\n} from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\n// ============================================================================\n// TYPES & PROPS\n// ============================================================================\n\nexport type SplitDirection = \"horizontal\" | \"vertical\";\n\nexport interface SplitPaneProps {\n  /**\n   * Layout orientation of the split panes.\n   * - \"horizontal\": Panes are placed side-by-side (left/right) with a vertical divider.\n   * - \"vertical\": Panes are stacked (top/bottom) with a horizontal divider.\n   * @default \"horizontal\"\n   */\n  direction?: SplitDirection;\n\n  /**\n   * Two child elements representing Pane A and Pane B, or an array of nodes.\n   */\n  children?: ReactNode;\n\n  /**\n   * Explicit array of pane nodes (alternative to children).\n   */\n  panes?: [ReactNode, ReactNode] | ReactNode[];\n\n  /**\n   * Initial size of the first pane (Pane A).\n   * Can be a pixel number (e.g. 300) or a percentage string (e.g. \"30%\").\n   * @default \"50%\"\n   */\n  defaultSize?: number | string;\n\n  /**\n   * Minimum allowable size for Pane A in pixels.\n   * @default 120\n   */\n  minSize?: number;\n\n  /**\n   * Maximum allowable size for Pane A.\n   * Can be a pixel number or percentage string (e.g. \"80%\").\n   */\n  maxSize?: number | string;\n\n  /**\n   * Minimum allowable size for Pane B in pixels.\n   * @default 120\n   */\n  minSizeB?: number;\n\n  /**\n   * Whether Pane A can be collapsed.\n   * Double-clicking the divider or pressing Enter will collapse or expand it.\n   * @default false\n   */\n  collapsible?: boolean;\n\n  /**\n   * Size of Pane A in pixels when collapsed.\n   * @default 0\n   */\n  collapsedSize?: number;\n\n  /**\n   * Container width breakpoint (in pixels) below which layout automatically\n   * stacks vertically for responsive mobile screens.\n   */\n  responsiveBreakpoint?: number;\n\n  /**\n   * Callback fired continuously during divider dragging with the new size in pixels.\n   */\n  onResize?: (size: number) => void;\n\n  /**\n   * Callback fired when dragging completes and the pointer is released.\n   */\n  onResizeEnd?: (size: number) => void;\n\n  /**\n   * LocalStorage key used to persist the Pane A size between page sessions.\n   */\n  persistKey?: string;\n\n  /**\n   * Additional CSS class names for the outer container.\n   */\n  className?: string;\n\n  /**\n   * Additional CSS class names for Pane A.\n   */\n  paneAClassName?: string;\n\n  /**\n   * Additional CSS class names for Pane B.\n   */\n  paneBClassName?: string;\n\n  /**\n   * Additional CSS class names for the divider gutter.\n   */\n  dividerClassName?: string;\n}\n\n// ============================================================================\n// HELPER UTILITIES\n// ============================================================================\n\nfunction parseDimension(\n  val: number | string | undefined,\n  containerTotal: number,\n  fallback: number\n): number {\n  if (val === undefined) return fallback;\n  if (typeof val === \"number\") return val;\n  if (typeof val === \"string\" && val.endsWith(\"%\")) {\n    const percent = parseFloat(val);\n    if (!isNaN(percent) && containerTotal > 0) {\n      return (percent / 100) * containerTotal;\n    }\n  }\n  const parsed = parseFloat(val);\n  return isNaN(parsed) ? fallback : parsed;\n}\n\n// ============================================================================\n// COMPONENT\n// ============================================================================\n\nexport const SplitPane = forwardRef<HTMLDivElement, SplitPaneProps>(\n  function SplitPane(\n    {\n      direction = \"horizontal\",\n      children,\n      panes,\n      defaultSize = \"50%\",\n      minSize = 120,\n      maxSize,\n      minSizeB = 120,\n      collapsible = false,\n      collapsedSize = 0,\n      responsiveBreakpoint,\n      onResize,\n      onResizeEnd,\n      persistKey,\n      className,\n      paneAClassName,\n      paneBClassName,\n      dividerClassName,\n    },\n    forwardedRef\n  ) {\n    const shouldReduceMotion = useReducedMotion();\n    const dividerId = useId();\n    const paneAId = useId();\n    const paneBId = useId();\n\n    const containerRef = useRef<HTMLDivElement | null>(null);\n    const [containerDimensions, setContainerDimensions] = useState<{\n      width: number;\n      height: number;\n    }>({ width: 0, height: 0 });\n\n    const [isDragging, setIsDragging] = useState(false);\n    const [isCollapsed, setIsCollapsed] = useState(false);\n\n    // Initial size ratio if specified as percentage\n    const initialRatio = useRef<number | null>(\n      typeof defaultSize === \"string\" && defaultSize.endsWith(\"%\")\n        ? parseFloat(defaultSize) / 100\n        : null\n    );\n\n    const [size, setSize] = useState<number>(() => {\n      if (typeof defaultSize === \"number\") return defaultSize;\n      return 300;\n    });\n\n    const prevSizeBeforeCollapse = useRef<number>(size);\n    const dragStartPos = useRef<number>(0);\n    const dragStartSize = useRef<number>(size);\n\n    // Responsive direction calculation\n    const isMobileStacked = Boolean(\n      responsiveBreakpoint &&\n        containerDimensions.width > 0 &&\n        containerDimensions.width < responsiveBreakpoint\n    );\n\n    const activeDirection: SplitDirection = isMobileStacked\n      ? \"vertical\"\n      : direction;\n    const isHorizontal = activeDirection === \"horizontal\";\n\n    const totalDimension = isHorizontal\n      ? containerDimensions.width\n      : containerDimensions.height;\n\n    // Measure container size with ResizeObserver\n    useEffect(() => {\n      const container = containerRef.current;\n      if (!container) return;\n\n      const observer = new ResizeObserver((entries) => {\n        for (const entry of entries) {\n          const { width, height } = entry.contentRect;\n          if (width > 0 && height > 0) {\n            setContainerDimensions({ width, height });\n          }\n        }\n      });\n\n      observer.observe(container);\n      return () => observer.disconnect();\n    }, []);\n\n    // Load persisted size on mount (SSR safe)\n    useEffect(() => {\n      if (!persistKey || typeof window === \"undefined\") return;\n      try {\n        const saved = localStorage.getItem(persistKey);\n        if (saved !== null) {\n          const parsed = parseFloat(saved);\n          if (!isNaN(parsed) && parsed > 0) {\n            setSize(parsed);\n            prevSizeBeforeCollapse.current = parsed;\n          }\n        }\n      } catch {\n        // Safe access in sandboxed / private modes\n      }\n    }, [persistKey]);\n\n    // Keep size proportional when container dimensions first initialize or resize\n    useEffect(() => {\n      if (totalDimension <= 0) return;\n\n      if (initialRatio.current !== null && !persistKey) {\n        const calculated = Math.round(totalDimension * initialRatio.current);\n        const effectiveMax = totalDimension - minSizeB;\n        const clamped = Math.max(minSize, Math.min(effectiveMax, calculated));\n        setSize(clamped);\n        prevSizeBeforeCollapse.current = clamped;\n        initialRatio.current = null; // initialized\n      }\n    }, [totalDimension, minSize, minSizeB, persistKey]);\n\n    // Calculate maximum allowable size for Pane A\n    const effectiveMaxSize = Math.max(\n      minSize,\n      Math.min(\n        maxSize !== undefined\n          ? parseDimension(maxSize, totalDimension, totalDimension - minSizeB)\n          : totalDimension - minSizeB,\n        totalDimension - minSizeB\n      )\n    );\n\n    // Save size to localStorage\n    const saveSize = useCallback(\n      (newSize: number) => {\n        if (!persistKey || typeof window === \"undefined\") return;\n        try {\n          localStorage.setItem(persistKey, String(newSize));\n        } catch {}\n      },\n      [persistKey]\n    );\n\n    // Clamp helper\n    const clampSize = useCallback(\n      (target: number): number => {\n        if (isCollapsed) return collapsedSize;\n        return Math.max(minSize, Math.min(effectiveMaxSize, target));\n      },\n      [isCollapsed, collapsedSize, minSize, effectiveMaxSize]\n    );\n\n    // Toggle collapse handler\n    const toggleCollapse = useCallback(() => {\n      if (!collapsible) return;\n\n      if (isCollapsed) {\n        // Expand\n        const restored = Math.max(minSize, prevSizeBeforeCollapse.current);\n        setIsCollapsed(false);\n        setSize(restored);\n        onResize?.(restored);\n        onResizeEnd?.(restored);\n        saveSize(restored);\n      } else {\n        // Collapse\n        prevSizeBeforeCollapse.current = size;\n        setIsCollapsed(true);\n        setSize(collapsedSize);\n        onResize?.(collapsedSize);\n        onResizeEnd?.(collapsedSize);\n        saveSize(collapsedSize);\n      }\n    }, [\n      collapsible,\n      isCollapsed,\n      minSize,\n      size,\n      collapsedSize,\n      onResize,\n      onResizeEnd,\n      saveSize,\n    ]);\n\n    // Pointer event handlers on divider\n    const handlePointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {\n      e.preventDefault();\n      e.currentTarget.setPointerCapture(e.pointerId);\n\n      setIsDragging(true);\n      dragStartPos.current = isHorizontal ? e.clientX : e.clientY;\n      dragStartSize.current = size;\n\n      if (isCollapsed) {\n        setIsCollapsed(false);\n      }\n    };\n\n    const handlePointerMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n      if (!isDragging || totalDimension <= 0) return;\n\n      const currentPos = isHorizontal ? e.clientX : e.clientY;\n      const delta = currentPos - dragStartPos.current;\n      const proposedSize = dragStartSize.current + delta;\n\n      // Handle collapse snap threshold\n      if (collapsible && proposedSize < minSize / 2) {\n        if (!isCollapsed) {\n          setIsCollapsed(true);\n          setSize(collapsedSize);\n          onResize?.(collapsedSize);\n        }\n        return;\n      }\n\n      if (isCollapsed && proposedSize >= minSize / 2) {\n        setIsCollapsed(false);\n      }\n\n      const clamped = Math.max(minSize, Math.min(effectiveMaxSize, proposedSize));\n      setSize(clamped);\n      onResize?.(clamped);\n    };\n\n    const handlePointerUp = (e: ReactPointerEvent<HTMLDivElement>) => {\n      if (!isDragging) return;\n      try {\n        e.currentTarget.releasePointerCapture(e.pointerId);\n      } catch {}\n\n      setIsDragging(false);\n      onResizeEnd?.(size);\n      saveSize(size);\n    };\n\n    // Keyboard accessibility navigation\n    const handleKeyDown = (e: ReactKeyboardEvent<HTMLDivElement>) => {\n      const step = e.shiftKey ? 50 : 10;\n      let nextSize = size;\n      let handled = false;\n\n      if (\n        (isHorizontal && e.key === \"ArrowLeft\") ||\n        (!isHorizontal && e.key === \"ArrowUp\")\n      ) {\n        nextSize = clampSize(size - step);\n        handled = true;\n      } else if (\n        (isHorizontal && e.key === \"ArrowRight\") ||\n        (!isHorizontal && e.key === \"ArrowDown\")\n      ) {\n        if (isCollapsed) {\n          setIsCollapsed(false);\n          nextSize = minSize;\n        } else {\n          nextSize = clampSize(size + step);\n        }\n        handled = true;\n      } else if (e.key === \"Home\") {\n        nextSize = minSize;\n        if (isCollapsed) setIsCollapsed(false);\n        handled = true;\n      } else if (e.key === \"End\") {\n        nextSize = effectiveMaxSize;\n        if (isCollapsed) setIsCollapsed(false);\n        handled = true;\n      } else if (e.key === \"Enter\") {\n        if (collapsible) {\n          toggleCollapse();\n          handled = true;\n        }\n      }\n\n      if (handled) {\n        e.preventDefault();\n        setSize(nextSize);\n        onResize?.(nextSize);\n        onResizeEnd?.(nextSize);\n        saveSize(nextSize);\n      }\n    };\n\n    // Extract exactly two panes from props.panes or children\n    const resolvedPanes = panes ?? Children.toArray(children);\n    const paneA = resolvedPanes[0] ?? (\n      <div className=\"flex h-full w-full items-center justify-center p-4 text-xs text-neutral-400\">\n        Pane A\n      </div>\n    );\n    const paneB = resolvedPanes[1] ?? (\n      <div className=\"flex h-full w-full items-center justify-center p-4 text-xs text-neutral-400\">\n        Pane B\n      </div>\n    );\n\n    // Compute display dimensions for Pane A\n    const paneAStyle: React.CSSProperties = isHorizontal\n      ? {\n          width: isCollapsed ? collapsedSize : size,\n          flexShrink: 0,\n        }\n      : {\n          height: isCollapsed ? collapsedSize : size,\n          flexShrink: 0,\n        };\n\n    return (\n      <div\n        ref={(el) => {\n          containerRef.current = el;\n          if (typeof forwardedRef === \"function\") forwardedRef(el);\n          else if (forwardedRef) forwardedRef.current = el;\n        }}\n        className={cn(\n          \"relative flex h-full w-full overflow-hidden select-none bg-neutral-50 dark:bg-neutral-950\",\n          isHorizontal ? \"flex-row\" : \"flex-col\",\n          isDragging &&\n            (isHorizontal ? \"cursor-col-resize\" : \"cursor-row-resize\"),\n          className\n        )}\n      >\n        {/* Full-screen drag overlay to prevent iframe / selection hijacking */}\n        {isDragging && (\n          <div\n            className={cn(\n              \"fixed inset-0 z-[9999] select-none\",\n              isHorizontal ? \"cursor-col-resize\" : \"cursor-row-resize\"\n            )}\n            style={{ userSelect: \"none\" }}\n            aria-hidden=\"true\"\n          />\n        )}\n\n        {/* PANE A */}\n        <div\n          id={paneAId}\n          style={paneAStyle}\n          className={cn(\n            \"min-h-0 min-w-0 overflow-auto bg-white dark:bg-neutral-900 select-auto\",\n            !isDragging &&\n              !shouldReduceMotion &&\n              \"transition-[width,height] duration-200 ease-out\",\n            isCollapsed && \"overflow-hidden\",\n            paneAClassName\n          )}\n        >\n          {paneA}\n        </div>\n\n        {/* DIVIDER GUTTER */}\n        <div\n          id={dividerId}\n          role=\"separator\"\n          tabIndex={0}\n          aria-orientation={isHorizontal ? \"vertical\" : \"horizontal\"}\n          aria-valuenow={Math.round(size)}\n          aria-valuemin={minSize}\n          aria-valuemax={Math.round(effectiveMaxSize)}\n          aria-controls={paneAId}\n          aria-label={\n            isHorizontal\n              ? \"Resize columns divider\"\n              : \"Resize rows divider\"\n          }\n          onPointerDown={handlePointerDown}\n          onPointerMove={handlePointerMove}\n          onPointerUp={handlePointerUp}\n          onPointerCancel={handlePointerUp}\n          onDoubleClick={collapsible ? toggleCollapse : undefined}\n          onKeyDown={handleKeyDown}\n          className={cn(\n            \"group relative flex shrink-0 items-center justify-center outline-hidden touch-none select-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-teal-500/70 focus-visible:ring-offset-1 dark:focus-visible:ring-offset-neutral-900\",\n            isHorizontal\n              ? \"w-2 -mx-0.5 cursor-col-resize flex-col py-1\"\n              : \"h-2 -my-0.5 cursor-row-resize flex-row px-1\",\n            isDragging && \"bg-teal-500/10 dark:bg-teal-400/10\",\n            dividerClassName\n          )}\n        >\n          {/* Subtle visible 1px line */}\n          <div\n            className={cn(\n              \"bg-neutral-200 dark:bg-neutral-800 transition-all duration-150 group-hover:bg-teal-500 dark:group-hover:bg-teal-400 group-focus-visible:bg-teal-500 dark:group-focus-visible:bg-teal-400\",\n              isHorizontal ? \"h-full w-px\" : \"w-full h-px\",\n              (isDragging || isCollapsed) &&\n                \"bg-teal-500 dark:bg-teal-400 shadow-[0_0_8px_rgba(20,184,166,0.5)]\"\n            )}\n          />\n\n          {/* Centered Grip Handle */}\n          <div\n            className={cn(\n              \"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 shadow-xs opacity-50 group-hover:opacity-100 group-focus-visible:opacity-100 transition-all duration-150 flex items-center justify-center pointer-events-none\",\n              isHorizontal\n                ? \"py-1.5 px-0.5 flex-col gap-0.5\"\n                : \"px-1.5 py-0.5 flex-row gap-0.5\",\n              isDragging &&\n                \"opacity-100 border-teal-500 text-teal-500 scale-105\"\n            )}\n            aria-hidden=\"true\"\n          >\n            <span\n              className={cn(\n                \"h-0.5 w-0.5 rounded-full bg-neutral-400 dark:bg-neutral-500 transition-colors group-hover:bg-teal-500 dark:group-hover:bg-teal-400\",\n                isDragging && \"bg-teal-500 dark:bg-teal-400\"\n              )}\n            />\n            <span\n              className={cn(\n                \"h-0.5 w-0.5 rounded-full bg-neutral-400 dark:bg-neutral-500 transition-colors group-hover:bg-teal-500 dark:group-hover:bg-teal-400\",\n                isDragging && \"bg-teal-500 dark:bg-teal-400\"\n              )}\n            />\n            <span\n              className={cn(\n                \"h-0.5 w-0.5 rounded-full bg-neutral-400 dark:bg-neutral-500 transition-colors group-hover:bg-teal-500 dark:group-hover:bg-teal-400\",\n                isDragging && \"bg-teal-500 dark:bg-teal-400\"\n              )}\n            />\n          </div>\n        </div>\n\n        {/* PANE B */}\n        <div\n          id={paneBId}\n          className={cn(\n            \"min-h-0 min-w-0 flex-1 overflow-auto bg-white dark:bg-neutral-900 select-auto\",\n            paneBClassName\n          )}\n        >\n          {paneB}\n        </div>\n      </div>\n    );\n  }\n);\n\nexport default SplitPane;\n",
      "type": "registry:ui",
      "target": "components/ui/split-pane.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
