{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "resizable",
  "title": "Resizable",
  "description": "Panels a person resizes by dragging the handle between them, or by keyboard, on ui-sdk’s Resizable, with a grip on the line that stretches while dragged. A panel folds away and back on Enter or a double click, and every change that isn’t the pointer’s own movement glides. The gutter variant makes each panel a surface of its own.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/grip.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/resizable.tsx",
      "content": "'use client'\n\n/*\n * Panels a person resizes by dragging the handle between them, or by keyboard\n * on it: ui-sdk's Resizable holds the layout, the pointer and the keys\n * (arrows, Shift for a large step, Home and End, Enter and a double click to\n * collapse and restore, Escape to put a drag back). Kino draws them: a grip\n * on the hairline between them shows where to grab, as the Drawer's handle\n * does, darkening under the pointer and stretching along the line while it's\n * dragged. The `gutter` variant makes each panel a surface of its own on a\n * muted ground, with the gap between them as the handle and the grip showing\n * in it under the pointer.\n */\n\nimport { gripClassName } from '@/registry/lib/grip'\nimport { markMounted, mergeRefs } from '@/registry/lib/refs'\nimport { markResizing, transitionsSettled } from '@/registry/lib/resize'\nimport {\n  edgeFadeClassName,\n  followEdges,\n  scrollRegionRingClassName,\n  useScrollRegion,\n} from '@/registry/lib/scroll'\nimport {\n  Resizable as ResizablePrimitive,\n  ResizableHandle as ResizableHandlePrimitive,\n  ResizablePanel as ResizablePanelPrimitive,\n} from '@ui-sdk/react/resizable'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  use,\n  useEffect,\n  useMemo,\n  useRef,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A change that isn't the pointer's own movement (Enter, Home or End, a\n * double click, a step by arrow, `collapse()` from a controller, a panel\n * folding away as a drag passes half its smallest size) moves the panels on\n * the layout role, on the flex basis ui-sdk writes from\n * `--resizable-panel-size`. While a handle is dragged (`data-dragging`), and\n * while the group itself changes size (`data-resizing`), they follow with no\n * transition, unless a drag has just folded one (`data-folding`). Nothing\n * moves before `data-mounted`, so the first layout doesn't play on load.\n */\nconst panelMotionClassName =\n  'motion-safe:data-mounted:*:data-[slot=resizable-panel]:transition-[flex-basis] motion-safe:data-mounted:*:data-[slot=resizable-panel]:duration-(--motion-layout-duration) motion-safe:data-mounted:*:data-[slot=resizable-panel]:ease-(--motion-layout-easing) motion-safe:data-mounted:not-data-folding:data-dragging:*:data-[slot=resizable-panel]:transition-none motion-safe:data-mounted:data-resizing:*:data-[slot=resizable-panel]:transition-none'\n\n// It fills the box it is in, as its panels' percentages are of its own size.\nconst resizableVariants = cva(\n  cn('size-full min-h-0 min-w-0 overflow-hidden', panelMotionClassName),\n  {\n    variants: {\n      variant: {\n        default: '',\n        // Half the surface gap around the panels, as between them; beside an end\n        // panel folded away, the gutter is the edge. A group in a panel sits on its panel's ground.\n        gutter:\n          'bg-muted/50 p-[calc(var(--surface-gap)/2)] in-data-[slot=resizable-panel]:bg-transparent in-data-[slot=resizable-panel]:p-0 data-[orientation=horizontal]:has-[>[data-slot=resizable-panel][inert]:first-child]:ps-0 data-[orientation=horizontal]:has-[>[data-slot=resizable-panel][inert]:not(:has(~[data-slot=resizable-panel]))]:pe-0 data-[orientation=vertical]:has-[>[data-slot=resizable-panel][inert]:first-child]:pt-0 data-[orientation=vertical]:has-[>[data-slot=resizable-panel][inert]:not(:has(~[data-slot=resizable-panel]))]:pb-0',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  },\n)\n\ntype ResizableVariant = NonNullable<VariantProps<typeof resizableVariants>['variant']>\n\n/** The variant of the group a panel or handle is in; a group inside a panel takes its panel's. */\nconst VariantContext = createContext<ResizableVariant>('default')\n\nfunction Resizable({\n  className,\n  variant: ownVariant,\n  ref,\n  onLayoutChange,\n  ...props\n}: Omit<ComponentProps<typeof ResizablePrimitive>, 'className'> &\n  VariantProps<typeof resizableVariants> & { className?: string }) {\n  const variant = ownVariant ?? use(VariantContext)\n  const groupRef = useRef<HTMLDivElement>(null)\n  const refs = useMemo(\n    () => mergeRefs<HTMLDivElement>(ref, groupRef, markMounted, markResizing),\n    [ref],\n  )\n  return (\n    <VariantContext value={variant}>\n      <ResizablePrimitive\n        ref={refs}\n        data-variant={variant}\n        onLayoutChange={(layout, details) => {\n          onLayoutChange?.(layout, details)\n          const group = groupRef.current\n          if (!group || details.reason !== 'drag' || group.hasAttribute('data-folding'))\n            return\n          // A drag that passes half a panel's smallest size folds it or brings it back, and\n          // the fold glides. ui-sdk writes the sizes and which panel is collapsed together\n          // once this returns, so the glide is turned on first, and off again before the\n          // frame draws unless a panel's collapsed state changed.\n          const before = collapsedOf(group)\n          group.dataset.folding = ''\n          queueMicrotask(() => {\n            if (collapsedOf(group) === before) {\n              delete group.dataset.folding\n              return\n            }\n            void transitionsSettled(group, {\n              property: 'flex-basis',\n              subtree: true,\n            }).then(() => delete group.dataset.folding)\n          })\n        }}\n        className={cn(resizableVariants({ variant }), className)}\n        {...props}\n      />\n    </VariantContext>\n  )\n}\n\n/** Which of a group's own panels are collapsed, as a key that changes when one folds. */\nfunction collapsedOf(group: HTMLElement) {\n  return [...group.children]\n    .map((child) =>\n      child.matches('[data-slot=resizable-panel][data-collapsed]') ? 1 : 0,\n    )\n    .join('')\n}\n\n/** The id of the first heading inside a panel that has one, to name it while it scrolls. */\nfunction headingIdOf(scroller: HTMLElement) {\n  return scroller.querySelector('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]')?.id\n}\n\n/** The handle beside a panel, for focus to go to when the panel stops scrolling. */\nfunction handleBeside(scroller: HTMLElement) {\n  const panel = scroller.closest('[data-slot=resizable-panel]')\n  for (const beside of [panel?.nextElementSibling, panel?.previousElementSibling]) {\n    if (beside instanceof HTMLElement && beside.role === 'separator') return beside\n  }\n  return null\n}\n\nconst resizablePanelVariants = cva(cn(scrollRegionRingClassName, 'flex'), {\n  variants: {\n    variant: {\n      default: '',\n      // A panel that holds a group lends its surface to that group's panels; folded away to nothing, it draws nothing.\n      gutter:\n        'bg-card text-card-foreground rounded-(--surface-radius) border inert:border-0 has-[>*>[data-slot=resizable]]:rounded-none has-[>*>[data-slot=resizable]]:border-0 has-[>*>[data-slot=resizable]]:bg-transparent',\n    },\n  },\n  defaultVariants: { variant: 'default' },\n})\n\ntype ResizablePanelProps = Omit<\n  ComponentProps<typeof ResizablePanelPrimitive>,\n  'className' | 'children'\n> & {\n  children?: ReactNode\n  /** For the content's layout: padding, gaps. */\n  className?: string\n  /** Names the panel while its content scrolls, when no heading with an id inside does. */\n  'aria-label'?: string\n}\n\n/**\n * A panel whose content scrolls in a box of its own, which takes focus as a\n * region while there is more than fits, so the keyboard can scroll it. While\n * it is folded away to nothing ui-sdk makes it `inert`, so Tab skips what\n * can't be seen.\n */\nfunction ResizablePanel({\n  className,\n  children,\n  'aria-label': label,\n  ...props\n}: ResizablePanelProps) {\n  const variant = use(VariantContext)\n  const scrollerRef = useRef<HTMLDivElement>(null)\n  const region = useScrollRegion(scrollerRef, {\n    axis: 'both',\n    labelledBy: headingIdOf,\n    refocus: handleBeside,\n  })\n  useEffect(() => {\n    const scroller = scrollerRef.current\n    if (!scroller) return\n    return followEdges(scroller, '--scroll-fade')\n  }, [])\n  return (\n    <ResizablePanelPrimitive className={resizablePanelVariants({ variant })} {...props}>\n      <div\n        ref={scrollerRef}\n        data-resizable-panel-content=''\n        {...region}\n        aria-label={region ? label : undefined}\n        className={cn(\n          'scrollbar-thin min-h-0 min-w-0 flex-1 overflow-auto focus-visible:outline-hidden',\n          edgeFadeClassName,\n          className,\n        )}\n      >\n        {children}\n      </div>\n    </ResizablePanelPrimitive>\n  )\n}\n\n/*\n * ui-sdk grabs a handle within its own box, or 10px (24px by touch) around\n * a thinner one, so the handle is the quality bar's 24px target by mouse\n * and 40px by touch, drawn over the panels beside it with margins that give\n * that room back, and the line or gutter it shows is a layer in its middle.\n */\nconst resizableHandleVariants = cva(\n  'group/handle group/grip relative z-10 flex items-center justify-center focus-visible:outline-hidden before:pointer-events-none before:absolute focus-visible:before:ring-3 focus-visible:before:ring-ring/50 aria-[orientation=horizontal]:h-6 aria-[orientation=horizontal]:-my-[calc((1.5rem-var(--resizable-line))/2)] aria-[orientation=horizontal]:before:inset-x-0 aria-[orientation=horizontal]:before:inset-y-[calc((1.5rem-var(--resizable-line))/2)] aria-[orientation=vertical]:w-6 aria-[orientation=vertical]:-mx-[calc((1.5rem-var(--resizable-line))/2)] aria-[orientation=vertical]:before:inset-y-0 aria-[orientation=vertical]:before:inset-x-[calc((1.5rem-var(--resizable-line))/2)] pointer-coarse:aria-[orientation=horizontal]:h-10 pointer-coarse:aria-[orientation=horizontal]:-my-[calc((2.5rem-var(--resizable-line))/2)] pointer-coarse:aria-[orientation=horizontal]:before:inset-y-[calc((2.5rem-var(--resizable-line))/2)] pointer-coarse:aria-[orientation=vertical]:w-10 pointer-coarse:aria-[orientation=vertical]:-mx-[calc((2.5rem-var(--resizable-line))/2)] pointer-coarse:aria-[orientation=vertical]:before:inset-x-[calc((2.5rem-var(--resizable-line))/2)]',\n  {\n    variants: {\n      variant: {\n        default:\n          '[--resizable-line:1px] before:bg-border data-dragging:before:bg-muted-foreground/40 before:transition-colors before:duration-(--motion-press-duration) before:ease-(--motion-press-fade-easing) forced-colors:before:bg-[CanvasText]!',\n        // The gutter is the surface gap halved, as the group's edge is.\n        gutter: '[--resizable-line:calc(var(--surface-gap)/2)] before:rounded-full',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  },\n)\n\nconst resizableGripVariants = cva(\n  cn(\n    gripClassName,\n    'group-data-dragging/handle:bg-muted-foreground/70 group-data-hovering/handle:bg-muted-foreground/50 pointer-events-none group-aria-[orientation=horizontal]/handle:w-10 group-aria-[orientation=vertical]/handle:h-10 motion-safe:group-aria-[orientation=horizontal]/handle:group-data-dragging/handle:scale-x-125 motion-safe:group-aria-[orientation=vertical]/handle:group-data-dragging/handle:scale-y-125',\n  ),\n  {\n    variants: {\n      variant: {\n        default:\n          'group-data-disabled/handle:opacity-50 group-aria-[orientation=horizontal]/handle:h-1.25 group-aria-[orientation=vertical]/handle:w-1.25',\n        // Shown only under the pointer or focus, so a disabled gutter shows none.\n        gutter:\n          'opacity-0 transition-[opacity,background-color,scale] duration-(--motion-press-duration) ease-[var(--motion-press-fade-easing),var(--motion-press-fade-easing),var(--motion-press-easing)] group-focus-visible/handle:opacity-100 group-data-dragging/handle:opacity-100 group-data-hovering/handle:opacity-100 group-aria-[orientation=horizontal]/handle:h-1 group-aria-[orientation=vertical]/handle:w-1 group-data-disabled/handle:opacity-0 motion-reduce:transition-[opacity,background-color] motion-reduce:ease-(--motion-press-fade-easing) forced-colors:opacity-100',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  },\n)\n\n/*\n * The grip is 5px across a 1px line, so it centres on whole pixels; in a\n * gutter, whose width is even, it is 4px.\n */\nfunction ResizableHandle({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof ResizableHandlePrimitive>, 'className' | 'children'> & {\n  className?: string\n}) {\n  const variant = use(VariantContext)\n  return (\n    <ResizableHandlePrimitive\n      data-variant={variant}\n      className={cn(resizableHandleVariants({ variant }), className)}\n      {...props}\n    >\n      <span aria-hidden className={resizableGripVariants({ variant })} />\n    </ResizableHandlePrimitive>\n  )\n}\n\nexport {\n  Resizable,\n  ResizableHandle,\n  ResizablePanel,\n  resizableGripVariants,\n  resizableHandleVariants,\n  resizablePanelVariants,\n  resizableVariants,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/resizable.tsx"
    }
  ],
  "type": "registry:component"
}