{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "compare-slider",
  "title": "Compare Slider",
  "description": "A theme-aware before/after image comparison slider with horizontal or vertical drag direction, keyboard support, and before/after labels.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/compare-slider/compare-slider.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type CompareSliderTheme = \"paper\" | \"glass\";\nexport type CompareSliderDirection = \"horizontal\" | \"vertical\";\n\nexport interface CompareSliderProps {\n  theme?: CompareSliderTheme;\n  direction?: CompareSliderDirection;\n  beforeImage?: string;\n  afterImage?: string;\n  beforeImagePosition?: string;\n  afterImagePosition?: string;\n  showLabels?: boolean;\n  beforeLabel?: string;\n  afterLabel?: string;\n  initialPosition?: number;\n  accentColor?: string;\n  className?: string;\n}\n\nfunction clamp(v: number) {\n  return Math.min(100, Math.max(0, v));\n}\n\nexport function CompareSlider({\n  theme = \"paper\",\n  direction = \"horizontal\",\n  beforeImage,\n  afterImage,\n  beforeImagePosition = \"50% 50%\",\n  afterImagePosition = \"50% 50%\",\n  showLabels = true,\n  beforeLabel = \"Before\",\n  afterLabel = \"After\",\n  initialPosition = 50,\n  accentColor = \"#c44b2b\",\n  className,\n}: CompareSliderProps) {\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const isGlass = theme === \"glass\";\n  const isVertical = direction === \"vertical\";\n\n  const [position, setPosition] = React.useState(() => clamp(initialPosition));\n  const [dragging, setDragging] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const draggingRef = React.useRef(false);\n\n  React.useEffect(() => {\n    if (!draggingRef.current) setPosition(clamp(initialPosition));\n  }, [initialPosition]);\n\n  const positionFromEvent = React.useCallback(\n    (clientX: number, clientY: number) => {\n      const track = trackRef.current;\n      if (!track) return 0;\n      const rect = track.getBoundingClientRect();\n      const pct = isVertical ? ((clientY - rect.top) / rect.height) * 100 : ((clientX - rect.left) / rect.width) * 100;\n      return clamp(pct);\n    },\n    [isVertical],\n  );\n\n  const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    e.preventDefault();\n    draggingRef.current = true;\n    setDragging(true);\n    setPosition(positionFromEvent(e.clientX, e.clientY));\n    e.currentTarget.setPointerCapture?.(e.pointerId);\n  };\n\n  const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (!draggingRef.current) return;\n    setPosition(positionFromEvent(e.clientX, e.clientY));\n  };\n\n  const endDrag = (e: React.PointerEvent<HTMLDivElement>) => {\n    draggingRef.current = false;\n    setDragging(false);\n    e.currentTarget.releasePointerCapture?.(e.pointerId);\n  };\n\n  React.useEffect(() => {\n    if (!dragging) return;\n    const handleUp = () => {\n      draggingRef.current = false;\n      setDragging(false);\n    };\n    document.addEventListener(\"pointerup\", handleUp);\n    document.addEventListener(\"pointercancel\", handleUp);\n    return () => {\n      document.removeEventListener(\"pointerup\", handleUp);\n      document.removeEventListener(\"pointercancel\", handleUp);\n    };\n  }, [dragging]);\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const step = e.shiftKey ? 10 : 2;\n    if (isVertical) {\n      if (e.key === \"ArrowUp\") {\n        e.preventDefault();\n        setPosition((p) => clamp(p - step));\n      } else if (e.key === \"ArrowDown\") {\n        e.preventDefault();\n        setPosition((p) => clamp(p + step));\n      }\n    } else {\n      if (e.key === \"ArrowLeft\") {\n        e.preventDefault();\n        setPosition((p) => clamp(p - step));\n      } else if (e.key === \"ArrowRight\") {\n        e.preventDefault();\n        setPosition((p) => clamp(p + step));\n      }\n    }\n    if (e.key === \"Home\") {\n      e.preventDefault();\n      setPosition(0);\n    }\n    if (e.key === \"End\") {\n      e.preventDefault();\n      setPosition(100);\n    }\n  };\n\n  const safePosition = Math.max(2, position);\n  const clipTransition = dragging ? \"none\" : `${isVertical ? \"height\" : \"width\"} 150ms ease`;\n\n  return (\n    <div\n      className={cn(\n        \"relative flex w-full items-center justify-center p-6 sm:p-12\",\n        !isGlass && \"bg-[#0e0e0e] text-[#f5f4f1]\",\n        isGlass && \"text-[#f5f4f1]\",\n        className,\n      )}\n      style={{\n        fontFamily: \"'Helvetica Neue', Arial, sans-serif\",\n        ...(isGlass && {\n          backgroundColor: \"rgba(14,14,14,0.6)\",\n          backdropFilter: \"blur(20px)\",\n          WebkitBackdropFilter: \"blur(20px)\",\n          border: \"1px solid rgba(245,244,241,0.08)\",\n        }),\n      }}\n    >\n      <div\n        ref={trackRef}\n        role=\"slider\"\n        aria-label=\"Before/after comparison position\"\n        aria-valuenow={Math.round(position)}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        tabIndex={0}\n        onPointerDown={handlePointerDown}\n        onPointerMove={handlePointerMove}\n        onPointerUp={endDrag}\n        onKeyDown={handleKeyDown}\n        onFocus={() => setFocused(true)}\n        onBlur={() => setFocused(false)}\n        className={cn(\n          \"relative h-full w-full max-w-[900px] touch-none overflow-hidden rounded border border-[#f5f4f1]/8 bg-[#f5f4f1]/[0.04] outline-none select-none\",\n          dragging ? \"cursor-grabbing\" : isVertical ? \"cursor-ns-resize\" : \"cursor-ew-resize\",\n        )}\n      >\n        {afterImage ? (\n          // eslint-disable-next-line @next/next/no-img-element\n          <img\n            src={afterImage}\n            alt=\"After\"\n            draggable={false}\n            className=\"pointer-events-none absolute inset-0 h-full w-full object-cover\"\n            style={{ objectPosition: afterImagePosition }}\n          />\n        ) : (\n          <div className=\"absolute inset-0 flex items-center justify-center text-xs opacity-30\">After</div>\n        )}\n\n        {/* Before — clipped to the slider position. The image is scaled beyond\n            the clip boundary so the visible region never distorts as the\n            divider moves. */}\n        <div\n          className=\"absolute inset-0 overflow-hidden\"\n          style={{ ...(isVertical ? { height: `${position}%`, width: \"100%\" } : { width: `${position}%`, height: \"100%\" }), transition: clipTransition }}\n        >\n          {beforeImage ? (\n            // eslint-disable-next-line @next/next/no-img-element\n            <img\n              src={beforeImage}\n              alt=\"Before\"\n              draggable={false}\n              className=\"pointer-events-none absolute inset-0 max-w-none object-cover\"\n              style={{\n                objectPosition: beforeImagePosition,\n                ...(isVertical\n                  ? { width: \"100%\", height: position > 0 ? `${(100 / safePosition) * 100}%` : \"100%\" }\n                  : { width: position > 0 ? `${(100 / safePosition) * 100}%` : \"100%\", height: \"100%\" }),\n              }}\n            />\n          ) : (\n            <div\n              className=\"absolute inset-0 flex items-center justify-center bg-[#f5f4f1]/[0.04] text-xs opacity-30\"\n              style={isVertical ? { height: position > 0 ? `${(100 / safePosition) * 100}%` : \"100%\" } : { width: position > 0 ? `${(100 / safePosition) * 100}%` : \"100%\" }}\n            >\n              Before\n            </div>\n          )}\n        </div>\n\n        <div\n          className=\"pointer-events-none absolute bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.15)]\"\n          style={isVertical ? { left: 0, right: 0, top: `${position}%`, height: 2, marginTop: -1 } : { top: 0, bottom: 0, left: `${position}%`, width: 2, marginLeft: -1 }}\n        />\n\n        <div\n          className=\"pointer-events-none absolute flex h-9 w-9 items-center justify-center rounded-full bg-white shadow-[0_2px_10px_rgba(0,0,0,0.25)] transition-transform duration-200\"\n          style={{\n            ...(isVertical ? { top: `${position}%`, left: \"50%\", marginTop: -18, marginLeft: -18 } : { top: \"50%\", left: `${position}%`, marginLeft: -18, marginTop: -18 }),\n            border: focused ? `2px solid ${accentColor}` : \"1px solid rgba(0,0,0,0.1)\",\n            transform: dragging ? \"scale(1.08)\" : \"scale(1)\",\n          }}\n        >\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" stroke=\"#0d0d0d\" strokeWidth={1.8} strokeLinecap=\"round\" strokeLinejoin=\"round\" fill=\"none\" style={{ transform: isVertical ? \"rotate(90deg)\" : \"none\" }}>\n            <path d=\"M9 6 L4 12 L9 18 M15 6 L20 12 L15 18\" />\n          </svg>\n        </div>\n\n        {showLabels && beforeLabel && (\n          <div\n            className=\"absolute top-3 left-3 z-10 rounded-full border border-[#f5f4f1]/8 px-2.5 py-1 text-[11px] font-semibold tracking-widest uppercase backdrop-blur-sm\"\n            style={{ background: isGlass ? \"rgba(0,0,0,0.55)\" : \"rgba(255,255,255,0.72)\", color: isGlass ? \"#fff\" : \"#0d0d0d\", fontFamily: \"'Helvetica Neue', Arial, sans-serif\" }}\n          >\n            {beforeLabel}\n          </div>\n        )}\n        {showLabels && afterLabel && (\n          <div\n            className={cn(\"absolute z-10 rounded-full border border-[#f5f4f1]/8 px-2.5 py-1 text-[11px] font-semibold tracking-widest uppercase backdrop-blur-sm\", isVertical ? \"bottom-3 left-3\" : \"top-3 right-3\")}\n            style={{ background: isGlass ? \"rgba(0,0,0,0.55)\" : \"rgba(255,255,255,0.72)\", color: isGlass ? \"#fff\" : \"#0d0d0d\", fontFamily: \"'Helvetica Neue', Arial, sans-serif\" }}\n          >\n            {afterLabel}\n          </div>\n        )}\n      </div>\n\n          </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}