{"version":3,"file":"Drawer-Akd5AJ9h.cjs","sources":["../src/components/Drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useRef } from 'react';\nimport type { PointerEvent as ReactPointerEvent } from 'react';\nimport type { FC, ReactNode } from 'react';\nimport type { TriggerProps } from '../../utils/primitiveProps';\nimport * as RadixDialog from '@radix-ui/react-dialog';\nimport { X } from 'lucide-react';\nimport { withSx } from '../../utils/withSx';\nimport type { SxProp } from '../Layout/sx';\nimport type { CSSProperties } from 'react';\nimport { useCloseGuard } from '../../utils/useCloseGuard';\nimport { ReturnFocus, focusFirstField } from '../../utils/overlayFocus';\n\nexport type DrawerSide = 'left' | 'right' | 'top' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg' | 'xl';\n\n// Control props are declared explicitly (rather than `extends\n// ComponentPropsWithoutRef<typeof RadixDialog.Root>`) so the published .d.ts\n// stays self-contained and does not import `@radix-ui/react-dialog`.\nexport interface DrawerProps {\n  /** Controlled open state. */\n  open?: boolean;\n  /** Uncontrolled initial open state. */\n  defaultOpen?: boolean;\n  /** Fires when the open state changes (Esc, backdrop, or close button). */\n  onOpenChange?: (open: boolean) => void;\n  /** Whether the drawer blocks interaction with the rest of the page. Default: true. */\n  modal?: boolean;\n  /** Visible heading for the drawer. Required for AT. */\n  title: ReactNode;\n  /** Optional subhead under the title. */\n  description?: ReactNode;\n  /** Body content. */\n  children?: ReactNode;\n  /** Footer (typically Buttons). */\n  footer?: ReactNode;\n  /** Edge the drawer slides in from. Default: `right`. */\n  side?: DrawerSide;\n  /** Width preset (for left/right) or height preset (for top/bottom). Default: `md`. */\n  size?: DrawerSize;\n  /** Hide the built-in X close button. */\n  hideClose?: boolean;\n  /** Unsaved changes. While true, close attempts go through `onBeforeClose` (or are blocked if it is absent). */\n  dirty?: boolean;\n  /** Guard for close attempts (Esc, backdrop, X, swipe). Return `false` (or resolve `false`) to keep the drawer open. */\n  onBeforeClose?: () => boolean | Promise<boolean>;\n  /** Fires when focus moves into the drawer on open; call `preventDefault()` to place focus yourself. Default: first form field in the body, else the Close button. */\n  onOpenAutoFocus?: (event: Event) => void;\n  /** Drag the panel toward its edge on touch to close it. Default: false. */\n  swipeToClose?: boolean;\n  /** Extra className on the drawer content. */\n  className?: string;\n  /** Inline style on the drawer content panel. */\n  style?: CSSProperties;\n  /**\n   * One-off CSS for the drawer content panel, same as `Box`'s `sx`: each value\n   * may be a scalar or a responsive breakpoint map (`{ base, sm, md, lg, xl }`).\n   * Scalar-only sx merges into inline style; responsive sx injects a scoped class.\n   */\n  sx?: SxProp;\n}\n\n/**\n * Off-canvas drawer / sheet. Slides in from any edge. Built on\n * @radix-ui/react-dialog so it gets focus trapping, Esc-to-close, scroll\n * lock, and accessibility for free.\n *\n * @example\n *   <Drawer open={open} onOpenChange={setOpen} side=\"right\" title=\"Settings\">\n *     <SettingsForm />\n *   </Drawer>\n */\nexport const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(\n  { title, description, children, footer, side = 'right', size = 'md', hideClose, className, style, sx, dirty, onBeforeClose, onOpenAutoFocus, swipeToClose, open, defaultOpen, onOpenChange, ...rootProps },\n  ref,\n) {\n  const { className: classes, style: mergedStyle, styleTag } = withSx(\n    sx, style, 'cny-drawer-content', `side-${side}`, `size-${size}`, className,\n  );\n  const guard = useCloseGuard({ open, defaultOpen, onOpenChange, dirty, onBeforeClose });\n  const drag = useRef<{ x: number; y: number; id: number } | null>(null);\n  const axis = side === 'left' || side === 'right' ? 'x' : 'y';\n  // Positive = toward the closing edge.\n  const sign = side === 'right' || side === 'bottom' ? 1 : -1;\n  const delta = (e: ReactPointerEvent<HTMLElement>) =>\n    sign * (axis === 'x' ? e.clientX - drag.current!.x : e.clientY - drag.current!.y);\n  const setOffset = (el: HTMLElement, px: number) => {\n    el.style.transform = px ? `translate${axis.toUpperCase()}(${sign * px}px)` : '';\n    el.style.transition = px ? 'none' : '';\n  };\n  const swipe = swipeToClose ? {\n    onPointerDown: (e: ReactPointerEvent<HTMLElement>) => {\n      if (e.pointerType !== 'touch') return;\n      const body = (e.target as HTMLElement).closest('.cny-drawer-body');\n      if (body && axis === 'y' && body.scrollTop > 0) return;\n      drag.current = { x: e.clientX, y: e.clientY, id: e.pointerId };\n    },\n    onPointerMove: (e: ReactPointerEvent<HTMLElement>) => {\n      if (!drag.current || drag.current.id !== e.pointerId) return;\n      setOffset(e.currentTarget, Math.max(0, delta(e)));\n    },\n    onPointerUp: (e: ReactPointerEvent<HTMLElement>) => {\n      if (!drag.current || drag.current.id !== e.pointerId) return;\n      const size = axis === 'x' ? e.currentTarget.offsetWidth : e.currentTarget.offsetHeight;\n      const d = delta(e);\n      drag.current = null;\n      setOffset(e.currentTarget, 0);\n      if (d > Math.min(80, size * 0.3)) guard.onOpenChange(false);\n    },\n    onPointerCancel: (e: ReactPointerEvent<HTMLElement>) => {\n      drag.current = null;\n      setOffset(e.currentTarget, 0);\n    },\n  } : undefined;\n  return (\n    <RadixDialog.Root {...rootProps} open={guard.open} onOpenChange={guard.onOpenChange}>\n      <RadixDialog.Portal>\n        <RadixDialog.Overlay className=\"cny-drawer-overlay\" />\n        <RadixDialog.Content ref={ref} className={classes} style={mergedStyle} onOpenAutoFocus={(e) => { onOpenAutoFocus?.(e); focusFirstField(e, '.cny-drawer-body'); }} {...swipe}>\n          <ReturnFocus />\n          {styleTag}\n          <header className=\"cny-drawer-header\">\n            <div className=\"cny-drawer-titles\">\n              <RadixDialog.Title className=\"cny-drawer-title\">{title}</RadixDialog.Title>\n              {description && (\n                <RadixDialog.Description className=\"cny-drawer-description\">{description}</RadixDialog.Description>\n              )}\n            </div>\n            {!hideClose && (\n              <RadixDialog.Close className=\"cny-drawer-close\" aria-label=\"Close drawer\">\n                <X size={16} aria-hidden=\"true\" />\n              </RadixDialog.Close>\n            )}\n          </header>\n          {children != null && <div className=\"cny-drawer-body\">{children}</div>}\n          {footer != null && <footer className=\"cny-drawer-footer\">{footer}</footer>}\n        </RadixDialog.Content>\n      </RadixDialog.Portal>\n    </RadixDialog.Root>\n  );\n});\n\n// Re-exported Radix primitives are annotated with explicit prop types so the\n// emitted .d.ts does not import `@radix-ui/react-dialog`.\nexport type DrawerTriggerProps = TriggerProps;\nexport const DrawerTrigger = RadixDialog.Trigger as FC<DrawerTriggerProps>;\nexport type DrawerCloseProps = TriggerProps;\nexport const DrawerClose = RadixDialog.Close as FC<DrawerCloseProps>;\n"],"names":["Drawer","forwardRef","title","description","children","footer","side","size","hideClose","className","style","sx","dirty","onBeforeClose","onOpenAutoFocus","swipeToClose","open","defaultOpen","onOpenChange","rootProps","ref","classes","mergedStyle","styleTag","withSx","guard","useCloseGuard","drag","useRef","axis","sign","delta","e","setOffset","el","px","swipe","body","d","jsx","RadixDialog.Root","jsxs","RadixDialog.Portal","RadixDialog.Overlay","RadixDialog.Content","focusFirstField","ReturnFocus","RadixDialog.Title","RadixDialog.Description","RadixDialog.Close","X","DrawerTrigger","RadixDialog.Trigger","DrawerClose"],"mappings":"wQAyEaA,EAASC,EAAAA,WAAwC,SAC5D,CAAE,MAAAC,EAAO,YAAAC,EAAa,SAAAC,EAAU,OAAAC,EAAQ,KAAAC,EAAO,QAAS,KAAAC,EAAO,KAAM,UAAAC,EAAW,UAAAC,EAAW,MAAAC,EAAO,GAAAC,EAAI,MAAAC,EAAO,cAAAC,EAAe,gBAAAC,EAAiB,aAAAC,EAAc,KAAAC,EAAM,YAAAC,EAAa,aAAAC,EAAc,GAAGC,CAAA,EAC/LC,EACA,CACA,KAAM,CAAE,UAAWC,EAAS,MAAOC,EAAa,SAAAC,GAAaC,EAAAA,OAC3Db,EAAID,EAAO,qBAAsB,QAAQJ,CAAI,GAAI,QAAQC,CAAI,GAAIE,CAAA,EAE7DgB,EAAQC,EAAAA,cAAc,CAAE,KAAAV,EAAM,YAAAC,EAAa,aAAAC,EAAc,MAAAN,EAAO,cAAAC,EAAe,EAC/Ec,EAAOC,EAAAA,OAAoD,IAAI,EAC/DC,EAAOvB,IAAS,QAAUA,IAAS,Q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