{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "splitter",
  "title": "Splitter",
  "description": "Resizable panels divided by draggable handles, with min/max size constraints, keyboard resizing, double-click reset, and horizontal or vertical layout.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/splitter/splitter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\n/** Fixed pixel thickness of each handle's hit area, shared between the\n * handle's own sizing and the drag math below — panels only ever get the\n * container's width/height *minus* this many px per handle, so computing\n * a percentage against the raw container size (rather than that reduced\n * span) would make the handle trail behind the cursor while dragging. */\nconst HANDLE_SIZE = 13;\n\nexport type SplitterDirection = \"horizontal\" | \"vertical\";\n\nexport interface SplitterPanel {\n  id: string;\n  content: React.ReactNode;\n  /** Percentage (0-100). Panel defaults are normalized to sum to 100 if they don't already. */\n  defaultSize?: number;\n  minSize?: number;\n  maxSize?: number;\n}\n\nexport interface SplitterProps {\n  panels: SplitterPanel[];\n  direction?: SplitterDirection;\n  /** Percentages summing to 100, one per panel. */\n  sizes?: number[];\n  onSizesChange?: (sizes: number[]) => void;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\n  height?: number | string;\n  width?: number | string;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0E0E0E\", border: \"rgba(255,255,255,0.09)\", handle: \"rgba(255,255,255,0.12)\", handleHover: \"rgba(255,255,255,0.22)\", grip: \"rgba(245,244,241,0.55)\", panelBg: \"transparent\" },\n  light: { bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", handle: \"rgba(10,10,10,0.12)\", handleHover: \"rgba(10,10,10,0.24)\", grip: \"rgba(10,10,10,0.5)\", panelBg: \"transparent\" },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst clamp = (n: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, n));\n\n/** Panels with an explicit defaultSize keep it; panels without one split\n * whatever percentage is left over *those* panels evenly — not a plain\n * \"100 / panel count\" placeholder folded into the same normalization pass,\n * which would silently shrink an explicit size (e.g. a 25/[unset] pair\n * would land on 33/67 instead of the intended 25/75, since the unset\n * panel's placeholder of 50 gets normalized against the explicit 25 as if\n * both were equally deliberate). A final normalize only kicks in to fix up\n * explicit sizes that don't themselves sum to 100. */\nfunction normalizeSizes(panels: SplitterPanel[]): number[] {\n  const explicitSum = panels.reduce((sum, p) => sum + (p.defaultSize ?? 0), 0);\n  const unspecifiedCount = panels.filter((p) => p.defaultSize === undefined).length;\n  const share = unspecifiedCount > 0 ? Math.max(0, 100 - explicitSum) / unspecifiedCount : 0;\n  const raw = panels.map((p) => p.defaultSize ?? share);\n  const total = raw.reduce((a, b) => a + b, 0) || 1;\n  return raw.map((v) => (v / total) * 100);\n}\n\n/** Resize the pair at (index, index+1) by deltaPct, redistributing between\n * just those two and clamping each to its own min/max — the classic\n * two-pane splitter behavior, so a resize never ripples into panels the\n * user isn't dragging next to. */\nfunction resizePair(sizes: number[], panels: SplitterPanel[], index: number, deltaPct: number): number[] {\n  const leftMin = panels[index].minSize ?? 10;\n  const leftMax = panels[index].maxSize ?? 90;\n  const rightMin = panels[index + 1].minSize ?? 10;\n  const rightMax = panels[index + 1].maxSize ?? 90;\n\n  let left = sizes[index] + deltaPct;\n  let right = sizes[index + 1] - deltaPct;\n\n  if (left < leftMin) {\n    right -= leftMin - left;\n    left = leftMin;\n  } else if (left > leftMax) {\n    right += left - leftMax;\n    left = leftMax;\n  }\n  if (right < rightMin) {\n    left -= rightMin - right;\n    right = rightMin;\n  } else if (right > rightMax) {\n    left += right - rightMax;\n    right = rightMax;\n  }\n  left = clamp(left, leftMin, leftMax);\n  right = clamp(right, rightMin, rightMax);\n\n  const next = [...sizes];\n  next[index] = left;\n  next[index + 1] = right;\n  return next;\n}\n\ninterface HandleProps {\n  direction: SplitterDirection;\n  p: Palette;\n  accent: string;\n  index: number;\n  sizes: number[];\n  panels: SplitterPanel[];\n  containerRef: React.RefObject<HTMLDivElement | null>;\n  onResize: (index: number, deltaPct: number) => void;\n  onReset: (index: number) => void;\n}\n\nfunction Handle({ direction, p, accent, index, sizes, panels, containerRef, onResize, onReset }: HandleProps) {\n  const horizontal = direction === \"horizontal\";\n  const [hovered, setHovered] = React.useState(false);\n  const [dragging, setDragging] = React.useState(false);\n  const startRef = React.useRef(0);\n\n  const onPointerDown = (e: React.PointerEvent) => {\n    e.preventDefault();\n    (e.target as HTMLElement).setPointerCapture(e.pointerId);\n    startRef.current = horizontal ? e.clientX : e.clientY;\n    setDragging(true);\n  };\n\n  const onPointerMove = (e: React.PointerEvent) => {\n    if (!dragging) return;\n    const el = containerRef.current;\n    if (!el) return;\n    const rect = el.getBoundingClientRect();\n    const total = (horizontal ? rect.width : rect.height) - HANDLE_SIZE * (panels.length - 1);\n    if (total === 0) return;\n    const pos = horizontal ? e.clientX : e.clientY;\n    const deltaPct = ((pos - startRef.current) / total) * 100;\n    startRef.current = pos;\n    onResize(index, deltaPct);\n  };\n\n  const endDrag = () => setDragging(false);\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    const forward = horizontal ? \"ArrowRight\" : \"ArrowDown\";\n    const backward = horizontal ? \"ArrowLeft\" : \"ArrowUp\";\n    const step = e.shiftKey ? 10 : 2;\n    if (e.key === forward) {\n      e.preventDefault();\n      onResize(index, step);\n    } else if (e.key === backward) {\n      e.preventDefault();\n      onResize(index, -step);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      onResize(index, -1000);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      onResize(index, 1000);\n    } else if (e.key === \"Enter\") {\n      e.preventDefault();\n      onReset(index);\n    }\n  };\n\n  const active = hovered || dragging;\n  const min = panels[index].minSize ?? 10;\n  const max = panels[index].maxSize ?? 90;\n\n  return (\n    <div\n      role=\"separator\"\n      aria-orientation={horizontal ? \"vertical\" : \"horizontal\"}\n      aria-label={`Resize ${panels[index].id} and ${panels[index + 1].id}`}\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={Math.round(sizes[index])}\n      tabIndex={0}\n      className=\"relative shrink-0 touch-none outline-none\"\n      style={{\n        width: horizontal ? HANDLE_SIZE : \"100%\",\n        height: horizontal ? \"100%\" : HANDLE_SIZE,\n        cursor: horizontal ? \"col-resize\" : \"row-resize\",\n        zIndex: 2,\n      }}\n      onMouseEnter={() => setHovered(true)}\n      onMouseLeave={() => setHovered(false)}\n      onPointerDown={onPointerDown}\n      onPointerMove={onPointerMove}\n      onPointerUp={endDrag}\n      onPointerCancel={endDrag}\n      onLostPointerCapture={endDrag}\n      onDoubleClick={() => onReset(index)}\n      onKeyDown={onKeyDown}\n    >\n      <div\n        className=\"absolute top-1/2 left-1/2\"\n        style={{\n          width: horizontal ? 1.5 : \"100%\",\n          height: horizontal ? \"100%\" : 1.5,\n          background: active ? accent : p.handle,\n          transform: \"translate(-50%, -50%)\",\n          transition: \"background 0.12s ease\",\n        }}\n      />\n      <motion.div\n        className=\"absolute top-1/2 left-1/2 flex items-center justify-center rounded-full\"\n        style={{\n          width: horizontal ? 16 : 22,\n          height: horizontal ? 22 : 16,\n          background: p.bg,\n          border: `1px solid ${active ? accent : p.handle}`,\n          transform: \"translate(-50%, -50%)\",\n        }}\n        animate={{ opacity: active ? 1 : 0, scale: active ? 1 : 0.7 }}\n        transition={{ duration: 0.14 }}\n      >\n        <div className=\"flex\" style={{ gap: 2, flexDirection: horizontal ? \"column\" : \"row\" }}>\n          {[0, 1, 2].map((i) => (\n            <span key={i} className=\"rounded-full\" style={{ width: 2.5, height: 2.5, background: active ? accent : p.grip }} />\n          ))}\n        </div>\n      </motion.div>\n    </div>\n  );\n}\n\nexport function Splitter({ panels, direction = \"horizontal\", sizes: sizesProp, onSizesChange, theme = \"dark\", accentColor = \"#F2A841\", height = 320, width, className }: SplitterProps) {\n  const p = PALETTES[theme];\n  const horizontal = direction === \"horizontal\";\n  const containerRef = React.useRef<HTMLDivElement>(null);\n\n  const [internalSizes, setInternalSizes] = React.useState(() => normalizeSizes(panels));\n  const isControlled = sizesProp !== undefined;\n  const sizes = isControlled ? sizesProp : internalSizes;\n\n  const defaultSizes = React.useMemo(() => normalizeSizes(panels), [panels]);\n\n  const setSizes = (next: number[]) => {\n    if (!isControlled) setInternalSizes(next);\n    onSizesChange?.(next);\n  };\n\n  const handleResize = (index: number, deltaPct: number) => {\n    setSizes(resizePair(sizes, panels, index, deltaPct));\n  };\n\n  const handleReset = (index: number) => {\n    const next = [...sizes];\n    next[index] = defaultSizes[index];\n    next[index + 1] = defaultSizes[index + 1];\n    setSizes(next);\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\"flex overflow-hidden\", horizontal ? \"flex-row\" : \"flex-col\", className)}\n      style={{ width, maxWidth: \"100%\", height, borderRadius: 14, border: `1px solid ${p.border}`, background: p.bg, fontFamily: \"Inter, sans-serif\" }}\n    >\n      {panels.map((panel, i) => (\n        <React.Fragment key={panel.id}>\n          <div\n            className=\"min-h-0 min-w-0 overflow-auto\"\n            // Sizes are ratios fed straight into flex-grow (basis 0), not a\n            // literal percentage of the container width/height — that lets\n            // the fixed-width handles between panels claim their own space\n            // first, with panels sharing exactly what's left in these\n            // proportions, instead of every panel's percentage-of-container\n            // width adding up past 100% and overflowing past the handles.\n            style={{ flex: `${sizes[i]} 1 0%` }}\n          >\n            {panel.content}\n          </div>\n          {i < panels.length - 1 && (\n            <Handle direction={direction} p={p} accent={accentColor} index={i} sizes={sizes} panels={panels} containerRef={containerRef} onResize={handleResize} onReset={handleReset} />\n          )}\n        </React.Fragment>\n      ))}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}