{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "resizable",
  "title": "Resizable",
  "description": "Astro panels with pointer and keyboard size controls.",
  "dependencies": [
    "@data-slot/core",
    "@data-slot/resizable",
    "cn"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "packages/ui/src/components/ui/resizable/index.ts",
      "content": "export { default as ResizableHandle } from './resizable-handle.astro'\nexport { default as ResizablePanel } from './resizable-panel.astro'\nexport { default as ResizablePanelGroup } from './resizable-panel-group.astro'\nexport type {\n    ResizableHandleProps,\n    ResizablePanelProps,\n    ResizableProps,\n} from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/resizable/resizable-handle.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport type { ResizableHandleProps } from \"./types.ts\"\nimport { cn } from \"cn\"\n\n/**\n * Separator between two resizable panels.\n *\n * `@data-slot/resizable` sets `aria-orientation` on the handle after startup.\n * The parent `data-direction` classes paint the correct axis before that runs.\n * A horizontal group uses a vertical separator.\n * A vertical group uses a horizontal separator.\n */\n\ntype Props = HTMLAttributes<\"div\"> & ResizableHandleProps\n\nconst {\n  class: className,\n  withHandle = false,\n  snapPoints,\n  \"aria-label\": ariaLabel = \"Resize panels\",\n  ...props\n} = Astro.props\n---\n\n{/* The handle is really a panel separator */}\n<div\n  data-slot=\"resizable-handle\"\n  data-snap-points={snapPoints?.length ? snapPoints.join(\",\") : undefined}\n  role=\"separator\"\n  tabindex=\"0\"\n  aria-label={ariaLabel}\n  class={cn(\n    \"bg-border ring-offset-background relative flex w-px shrink-0 cursor-col-resize touch-none items-center justify-center select-none after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-hidden\",\n    \"aria-[orientation=horizontal]:h-px aria-[orientation=horizontal]:w-full aria-[orientation=horizontal]:cursor-row-resize aria-[orientation=horizontal]:after:left-0 aria-[orientation=horizontal]:after:h-1 aria-[orientation=horizontal]:after:w-full aria-[orientation=horizontal]:after:translate-x-0 aria-[orientation=horizontal]:after:-translate-y-1/2 [&[aria-orientation=horizontal]>div]:rotate-90\",\n    \"[[data-direction=vertical]>&]:h-px [[data-direction=vertical]>&]:w-full [[data-direction=vertical]>&]:cursor-row-resize [[data-direction=vertical]>&]:after:left-0 [[data-direction=vertical]>&]:after:h-1 [[data-direction=vertical]>&]:after:w-full [[data-direction=vertical]>&]:after:translate-x-0 [[data-direction=vertical]>&]:after:-translate-y-1/2 [[data-direction=vertical]>&]:[&>div]:rotate-90\",\n    className,\n  )}\n  {...props}\n>\n  {/* Small handle in the center of the separator */}\n  {withHandle && (\n    <div class=\"bg-border z-10 flex h-6 w-1 shrink-0 rounded-lg\" data-slot=\"resizable-handle-handle\" />\n  )}\n  <slot />\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/resizable-handle.astro"
    },
    {
      "path": "packages/ui/src/components/ui/resizable/resizable-panel-group.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\nimport type { ResizableProps } from \"./types.ts\"\n\n/**\n * Group of panels that share space.\n *\n * `@data-slot/resizable` binds `data-slot=\"resizable\"`.\n * The public component name stays `ResizablePanelGroup`.\n */\n\ntype Props = HTMLAttributes<\"div\"> & ResizableProps\n\nconst {\n  class: className,\n  direction = \"horizontal\",\n  keyboardResizeBy,\n  ...props\n} = Astro.props\n\n/**\n * Keep a numeric 0 in the attribute.\n * Astro can omit a bare 0.\n */\nconst dataNumber = (value: number | undefined) =>\n  value === undefined ? undefined : String(value)\n---\n\n<div\n  data-slot=\"resizable\"\n  data-direction={direction}\n  data-keyboard-resize-by={dataNumber(keyboardResizeBy)}\n  class={cn(\n    \"flex h-full w-full min-h-0 min-w-0 overflow-hidden data-[direction=vertical]:flex-col\",\n    className,\n  )}\n  {...props}\n>\n  <slot />\n</div>\n\n<script>\n  import { create } from \"./snap-points.ts\"\n  // Destroy bindings before a view transition so the next page-load binds once.\n  const controllers: ReturnType<typeof create> = []\n  const initialize = () => controllers.push(...create())\n  initialize()\n  document.addEventListener(\"astro:page-load\", initialize)\n  document.addEventListener(\"astro:before-swap\", () => {\n    for (const controller of controllers) controller.destroy()\n    controllers.length = 0\n  })\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/resizable-panel-group.astro"
    },
    {
      "path": "packages/ui/src/components/ui/resizable/resizable-panel.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\nimport type { ResizablePanelProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & ResizablePanelProps\n\nconst {\n  class: className,\n  defaultSize,\n  minSize,\n  maxSize,\n  collapsible,\n  collapsedSize,\n  style,\n  ...props\n} = Astro.props\n\n/**\n * Keep a numeric 0 in the attribute.\n * Astro can omit a bare 0.\n */\nconst dataNumber = (value: number | undefined) =>\n  value === undefined ? undefined : String(value)\n\nconst layoutStyle = defaultSize === undefined ? \"\" : `flex-grow:${defaultSize}`\nconst userStyle = typeof style === \"string\" ? style : \"\"\nconst mergedStyle =\n  [layoutStyle, userStyle].filter(Boolean).join(\";\") || undefined\n---\n\n<div\n  data-slot=\"resizable-panel\"\n  data-default-size={dataNumber(defaultSize)}\n  data-min-size={dataNumber(minSize)}\n  data-max-size={dataNumber(maxSize)}\n  data-collapsible={collapsible ? \"\" : undefined}\n  data-collapsed-size={dataNumber(collapsedSize)}\n  class={cn(\"min-h-0 min-w-0 flex-1 overflow-hidden\", className)}\n  style={mergedStyle}\n  {...props}\n>\n  <slot />\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/resizable-panel.astro"
    },
    {
      "path": "packages/ui/src/components/ui/resizable/snap-points.ts",
      "content": "import {\n    getDataBool,\n    getParts,\n    getRoots,\n    hasRootBinding,\n    on,\n} from '@data-slot/core'\nimport { createResizable, type ResizableController } from '@data-slot/resizable'\n\n/** Check the two panes beside the handle so a snap never moves another pane. */\nfunction allows(panel: HTMLElement, size: number) {\n    const { minSize = 0, maxSize = 100, collapsedSize = 0 } = panel.dataset\n    return (\n        (size >= Number(minSize) && size <= Number(maxSize)) ||\n        (getDataBool(panel, 'collapsible') && size === Number(collapsedSize))\n    )\n}\n\nfunction bindStops(\n    root: HTMLElement,\n    controller: ResizableController,\n    handle: HTMLElement,\n    index: number,\n    panels: HTMLElement[],\n) {\n    const points = (handle.dataset.snapPoints ?? '')\n        .split(',')\n        .filter((point) => point.trim() !== '')\n        .map(Number)\n        .filter((point) => Number.isFinite(point) && point >= 0 && point <= 100)\n        .sort((a, b) => a - b)\n    if (!points.length) return []\n    const before = panels[index]!\n    const after = panels[index + 1]!\n    const view = root.ownerDocument.defaultView!\n    const available = () => {\n        const sum = controller.getSize(index) + controller.getSize(index + 1)\n        return points.filter(\n            (point) =>\n                allows(before, point) &&\n                allows(after, Number((sum - point).toFixed(10))),\n        )\n    }\n\n    // The primitive starts the drag at the handle. Finish a snap only on release.\n    // Cancel, blur, a programmatic resize, and teardown discard the pending snap.\n    let stopRelease: (() => void) | undefined\n    function clearRelease() {\n        stopRelease?.()\n        stopRelease = undefined\n    }\n    function start(event: MouseEvent | TouchEvent) {\n        if (handle.dataset.active !== 'pointer') return\n        if (\n            'touches' in event ? event.touches.length !== 1 : event.button !== 0\n        )\n            return\n        clearRelease()\n        const startSize = controller.getSize(index)\n        const snap = () => {\n            const size = controller.getSize(index)\n            if (size === startSize) return\n            const nearest = available().reduce<number | undefined>(\n                (best, point) =>\n                    best === undefined ||\n                    Math.abs(size - point) < Math.abs(size - best)\n                        ? point\n                        : best,\n                undefined,\n            )\n            if (nearest !== undefined) controller.resizePane(index, nearest)\n        }\n        if ('touches' in event) {\n            const id = event.touches[0]?.identifier\n            stopRelease = on(\n                view,\n                'touchend',\n                (end) => {\n                    if (\n                        Array.from(end.changedTouches).some(\n                            (touch) => touch.identifier === id,\n                        )\n                    )\n                        snap()\n                },\n                { capture: true },\n            )\n        } else {\n            stopRelease = on(view, 'mouseup', snap, { capture: true })\n        }\n    }\n    function keydown(event: KeyboardEvent) {\n        if (\n            event.defaultPrevented ||\n            event.shiftKey ||\n            handle.dataset.disabled === 'true'\n        )\n            return\n        const vertical = root.dataset.direction === 'vertical'\n        const keys = vertical\n            ? ['ArrowUp', 'ArrowDown']\n            : ['ArrowLeft', 'ArrowRight']\n        if (!keys.includes(event.key)) return\n        const stops = available()\n        if (!stops.length) return\n        let forward = event.key === keys[1]\n        if (!vertical && root.ownerDocument.dir === 'rtl') forward = !forward\n        const size = controller.getSize(index)\n        const next = forward\n            ? stops.find((point) => point > size)\n            : stops.reverse().find((point) => point < size)\n        event.preventDefault()\n        if (next !== undefined) controller.resizePane(index, next)\n    }\n    return [\n        on(handle, 'mousedown', start),\n        on(handle, 'touchstart', start),\n        on(handle, 'keydown', keydown, { capture: true }),\n        on(root, 'resizable:dragging', (event) => {\n            if (\n                event.target === root &&\n                !(event as CustomEvent).detail.dragging\n            )\n                clearRelease()\n        }),\n        clearRelease,\n    ]\n}\n\n/** Bind each new group once, with its own handles and native resize controller. */\nexport function create(scope: ParentNode = document) {\n    return getRoots<HTMLElement>(scope, 'resizable')\n        .filter((root) => !hasRootBinding(root, '@data-slot/resizable'))\n        .map((root) => {\n            const controller = createResizable(root)\n            const panels = getParts<HTMLElement>(root, 'resizable-panel')\n            const cleanups = getParts<HTMLElement>(\n                root,\n                'resizable-handle',\n            ).flatMap((handle, index) =>\n                bindStops(root, controller, handle, index, panels),\n            )\n            return {\n                destroy() {\n                    cleanups.splice(0).forEach((cleanup) => cleanup())\n                    controller.destroy()\n                },\n            }\n        })\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/snap-points.ts"
    },
    {
      "path": "packages/ui/src/components/ui/resizable/types.ts",
      "content": "import type { ResizableDirection } from '@data-slot/resizable'\n\n/** Configuration for a group of resizable panels. */\nexport type ResizableProps = {\n    /**\n     * Layout axis for the panels.\n     * `horizontal` places panels side by side.\n     * `vertical` stacks the panels.\n     * @default \"horizontal\"\n     */\n    direction?: ResizableDirection\n    /**\n     * Percent added or removed for each arrow key press.\n     * Shift with an arrow key moves to the limit.\n     * @default 10\n     */\n    keyboardResizeBy?: number\n}\n\nexport type ResizablePanelProps = {\n    /**\n     * Initial size as a percentage of the group.\n     * Panels without a size share the remaining space.\n     */\n    defaultSize?: number\n    /**\n     * Minimum size as a percentage.\n     * @default 0\n     */\n    minSize?: number\n    /**\n     * Maximum size as a percentage.\n     * @default 100\n     */\n    maxSize?: number\n    /**\n     * Allow this panel to collapse past `minSize`.\n     * Press Enter on the preceding handle to collapse and expand it.\n     * @default false\n     */\n    collapsible?: boolean\n    /**\n     * Size as a percentage when the panel is collapsed.\n     * This value must not exceed `minSize`.\n     * @default 0\n     */\n    collapsedSize?: number\n}\n\nexport type ResizableHandleProps = {\n    /**\n     * Optional sizes for the panel before this handle, as percentages of the group.\n     * Release a drag to select the nearest available size. Arrow keys select\n     * the previous or next size. Both adjacent panels must allow that size.\n     */\n    snapPoints?: readonly number[]\n    /**\n     * Show a grip in the center of the handle.\n     * @default false\n     */\n    withHandle?: boolean\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/resizable/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "@data-slot/core": "^1.0.2",
      "@data-slot/resizable": "^1.1.2",
      "cn": "0.5.2"
    }
  },
  "docs": "https://gnosticai.com/ui/components/resizable",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
