{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "resizable",
  "title": "Resizable",
  "author": "AlgorizeTech",
  "description": "Draggable split panes in horizontal or vertical layout, with min and max size constraints. Use it for editor and preview layouts users can rebalance.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/ResizableBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { GripHorizontal, GripVertical } from \"lucide-react\";\nimport React, { createContext, useContext, useRef } from \"react\";\n\n// ==========================================\n// 1. CONTEXT\n// ==========================================\ninterface ResizableContextType {\n  direction: \"horizontal\" | \"vertical\";\n}\nconst ResizableContext = createContext<ResizableContextType | null>(null);\n\nfunction useResizable() {\n  const context = useContext(ResizableContext);\n  if (!context) throw new Error(\"Must be used within a ResizablePanelGroup\");\n  return context;\n}\n\n// ==========================================\n// 2. PANEL GROUP\n// ==========================================\nexport interface ResizablePanelGroupProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  direction?: \"horizontal\" | \"vertical\";\n}\n\nexport function ResizablePanelGroup({\n  direction = \"horizontal\",\n  className,\n  children,\n  ...props\n}: ResizablePanelGroupProps) {\n  return (\n    <ResizableContext.Provider value={{ direction }}>\n      <div\n        className={cn(\n          \"flex h-full w-full overflow-hidden\",\n          direction === \"horizontal\" ? \"flex-row\" : \"flex-col\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </div>\n    </ResizableContext.Provider>\n  );\n}\n\n// ==========================================\n// 3. PANEL\n// ==========================================\nexport interface ResizablePanelProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  defaultSize?: number; // Percentage (0-100)\n  minSize?: number; // Percentage (0-100)\n  maxSize?: number; // Percentage (0-100)\n}\n\nexport function ResizablePanel({\n  defaultSize = 50,\n  minSize = 0,\n  maxSize = 100,\n  className,\n  children,\n  ...props\n}: ResizablePanelProps) {\n  return (\n    <div\n      className={cn(\n        \"relative flex h-full w-full flex-col overflow-hidden\",\n        className,\n      )}\n      style={{\n        // Use flex-basis to control relative sizing seamlessly\n        flex: `${defaultSize} ${defaultSize} 0%`,\n      }}\n      // Store constraints in dataset so the Handle can read them without React renders\n      data-panel\n      data-flex-size={defaultSize}\n      data-min-size={minSize}\n      data-max-size={maxSize}\n      {...props}\n    >\n      {children}\n    </div>\n  );\n}\n\n// ==========================================\n// 4. RESIZE HANDLE\n// ==========================================\nexport interface ResizableHandleProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  withHandle?: boolean;\n}\n\nexport function ResizableHandle({\n  withHandle = false,\n  className,\n  ...props\n}: ResizableHandleProps) {\n  const { direction } = useResizable();\n  const isHorizontal = direction === \"horizontal\";\n  const handleRef = useRef<HTMLDivElement>(null);\n\n  // --- DIRECT DOM DRAG ENGINE (60FPS Smooth) ---\n  const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    e.preventDefault();\n    const handle = handleRef.current;\n    if (!handle) return;\n\n    // Resolve the document/window the handle actually lives in (supports iframe rendering).\n    const doc = handle.ownerDocument;\n    const win = doc.defaultView ?? window;\n\n    const prev = handle.previousElementSibling as HTMLElement;\n    const next = handle.nextElementSibling as HTMLElement;\n    if (\n      !prev ||\n      !next ||\n      !prev.hasAttribute(\"data-panel\") ||\n      !next.hasAttribute(\"data-panel\")\n    )\n      return;\n\n    const startPos = isHorizontal ? e.clientX : e.clientY;\n    const prevStartFlex = parseFloat(\n      prev.getAttribute(\"data-flex-size\") || \"50\",\n    );\n    const nextStartFlex = parseFloat(\n      next.getAttribute(\"data-flex-size\") || \"50\",\n    );\n    const totalFlex = prevStartFlex + nextStartFlex;\n\n    const prevRect = prev.getBoundingClientRect();\n    const nextRect = next.getBoundingClientRect();\n    const totalPixels = isHorizontal\n      ? prevRect.width + nextRect.width\n      : prevRect.height + nextRect.height;\n\n    const prevMin = parseFloat(prev.getAttribute(\"data-min-size\") || \"0\");\n    const prevMax = parseFloat(prev.getAttribute(\"data-max-size\") || \"100\");\n    const nextMin = parseFloat(next.getAttribute(\"data-min-size\") || \"0\");\n    const nextMax = parseFloat(next.getAttribute(\"data-max-size\") || \"100\");\n\n    doc.body.style.cursor = isHorizontal ? \"col-resize\" : \"row-resize\";\n    doc.body.style.userSelect = \"none\";\n\n    const onPointerMove = (moveEvent: PointerEvent) => {\n      const currentPos = isHorizontal ? moveEvent.clientX : moveEvent.clientY;\n      const deltaPixels = currentPos - startPos;\n      const deltaPercentage = (deltaPixels / totalPixels) * totalFlex;\n\n      let newPrevFlex = prevStartFlex + deltaPercentage;\n\n      // Apply constraints\n      newPrevFlex = Math.max(prevMin, Math.min(newPrevFlex, prevMax));\n      newPrevFlex = Math.max(newPrevFlex, totalFlex - nextMax);\n      newPrevFlex = Math.min(newPrevFlex, totalFlex - nextMin);\n\n      // The next pane takes whatever the clamped previous pane leaves.\n      const newNextFlex = totalFlex - newPrevFlex;\n\n      // Direct DOM manipulation bypasses React render cycle for zero latency\n      prev.style.flex = `${newPrevFlex} ${newPrevFlex} 0%`;\n      prev.setAttribute(\"data-flex-size\", newPrevFlex.toString());\n\n      next.style.flex = `${newNextFlex} ${newNextFlex} 0%`;\n      next.setAttribute(\"data-flex-size\", newNextFlex.toString());\n    };\n\n    const onPointerUp = () => {\n      doc.body.style.cursor = \"\";\n      doc.body.style.userSelect = \"\";\n      win.removeEventListener(\"pointermove\", onPointerMove);\n      win.removeEventListener(\"pointerup\", onPointerUp);\n    };\n\n    win.addEventListener(\"pointermove\", onPointerMove);\n    win.addEventListener(\"pointerup\", onPointerUp);\n  };\n\n  // --- ACCESSIBILITY: KEYBOARD NAVIGATION ---\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const handle = handleRef.current;\n    if (!handle) return;\n\n    const prev = handle.previousElementSibling as HTMLElement;\n    const next = handle.nextElementSibling as HTMLElement;\n    if (!prev || !next) return;\n\n    let delta = 0;\n    const step = 5; // Move by 5% on each keystroke\n\n    if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") delta = -step;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") delta = step;\n\n    if (delta !== 0) {\n      e.preventDefault();\n\n      const prevStartFlex = parseFloat(\n        prev.getAttribute(\"data-flex-size\") || \"50\",\n      );\n      const nextStartFlex = parseFloat(\n        next.getAttribute(\"data-flex-size\") || \"50\",\n      );\n      const totalFlex = prevStartFlex + nextStartFlex;\n\n      const prevMin = parseFloat(prev.getAttribute(\"data-min-size\") || \"0\");\n      const prevMax = parseFloat(prev.getAttribute(\"data-max-size\") || \"100\");\n      const nextMin = parseFloat(next.getAttribute(\"data-min-size\") || \"0\");\n      const nextMax = parseFloat(next.getAttribute(\"data-max-size\") || \"100\");\n\n      let newPrevFlex = prevStartFlex + delta;\n\n      newPrevFlex = Math.max(prevMin, Math.min(newPrevFlex, prevMax));\n      newPrevFlex = Math.max(newPrevFlex, totalFlex - nextMax);\n      newPrevFlex = Math.min(newPrevFlex, totalFlex - nextMin);\n      const newNextFlex = totalFlex - newPrevFlex;\n\n      prev.style.flex = `${newPrevFlex} ${newPrevFlex} 0%`;\n      prev.setAttribute(\"data-flex-size\", newPrevFlex.toString());\n\n      next.style.flex = `${newNextFlex} ${newNextFlex} 0%`;\n      next.setAttribute(\"data-flex-size\", newNextFlex.toString());\n    }\n  };\n\n  return (\n    <div\n      ref={handleRef}\n      role=\"separator\"\n      tabIndex={0}\n      aria-orientation={direction}\n      onPointerDown={handlePointerDown}\n      onKeyDown={handleKeyDown}\n      className={cn(\n        \"relative flex shrink-0 items-center justify-center bg-border/80 hover:bg-primary/60 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary\",\n        isHorizontal ? \"w-1.5 cursor-col-resize\" : \"h-1.5 cursor-row-resize\",\n        className,\n      )}\n      {...props}\n    >\n      {/* Invisible wider grab area for easier touch and drag clicking */}\n      <div\n        className={cn(\n          \"absolute z-10\",\n          isHorizontal ? \"inset-y-0 -inset-x-3\" : \"inset-x-0 -inset-y-3\",\n        )}\n      />\n\n      {withHandle && (\n        <div\n          className={cn(\n            \"z-20 flex items-center justify-center rounded-md border border-border bg-card shadow-xs text-muted-foreground hover:text-primary hover:border-primary/50 transition-colors\",\n            isHorizontal ? \"h-6 w-3.5\" : \"h-3.5 w-6\",\n          )}\n        >\n          {isHorizontal ? (\n            <GripVertical className=\"h-3 w-3\" />\n          ) : (\n            <GripHorizontal className=\"h-3 w-3\" />\n          )}\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/ResizableBlock.tsx"
    }
  ],
  "docs": "Named exports: ResizablePanelGroup, ResizablePanel, ResizableHandle. Sizes are percentages — `defaultSize`, `minSize` and `maxSize` per panel. Set `withHandle` to render a visible grip. Groups nest, so a horizontal split can contain a vertical one.",
  "categories": [
    "layout"
  ],
  "type": "registry:component"
}
