{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-compare",
  "type": "registry:component",
  "title": "Image Compare",
  "description": "Before and after slider. Drag the handle or use the arrow keys to reveal either side.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "compare",
    "before-after",
    "slider",
    "image",
    "drag"
  ],
  "docs": "https://hyperblur.dev/effects/image-compare",
  "files": [
    {
      "path": "registry/hyperblur/image-compare.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/image-compare.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ImageCompareLabels {\n  before: string;\n  after: string;\n}\n\nexport interface ImageCompareProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  before: React.ReactNode;\n  after: React.ReactNode;\n  initial?: number;\n  labels?: Partial<ImageCompareLabels>;\n  orientation?: \"horizontal\" | \"vertical\";\n}\n\nconst css = `\n.hb-ic {\n  position: relative;\n  width: 100%;\n  aspect-ratio: 16 / 9;\n  overflow: hidden;\n  border-radius: inherit;\n  background: #111;\n  color: #fff;\n  user-select: none;\n  -webkit-user-select: none;\n  cursor: ew-resize;\n}\n.hb-ic[data-o=\"horizontal\"] { touch-action: pan-y; }\n.hb-ic[data-o=\"vertical\"] { touch-action: pan-x; cursor: ns-resize; }\n.hb-ic-layer { position: absolute; inset: 0; pointer-events: none; }\n.hb-ic-layer > * { display: block; width: 100%; height: 100%; object-fit: cover; }\n.hb-ic-layer img { -webkit-user-drag: none; }\n.hb-ic[data-o=\"horizontal\"] .hb-ic-after { clip-path: inset(0 0 0 var(--hb-pos)); }\n.hb-ic[data-o=\"vertical\"] .hb-ic-after { clip-path: inset(var(--hb-pos) 0 0 0); }\n.hb-ic-chip {\n  position: absolute;\n  z-index: 1;\n  padding: 2px 8px;\n  border-radius: 999px;\n  background: rgba(10, 10, 10, .6);\n  color: #fff;\n  font-size: 11px;\n  letter-spacing: .05em;\n  line-height: 1.5;\n  text-transform: uppercase;\n  pointer-events: none;\n  backdrop-filter: blur(6px);\n}\n.hb-ic-chip[data-side=\"before\"] { top: 8px; left: 8px; }\n.hb-ic[data-o=\"horizontal\"] .hb-ic-chip[data-side=\"after\"] { top: 8px; right: 8px; }\n.hb-ic[data-o=\"vertical\"] .hb-ic-chip[data-side=\"after\"] { bottom: 8px; left: 8px; }\n.hb-ic-handle {\n  position: absolute;\n  z-index: 2;\n  outline: none;\n}\n.hb-ic[data-o=\"horizontal\"] .hb-ic-handle {\n  top: 0;\n  bottom: 0;\n  left: var(--hb-pos);\n  width: 32px;\n  margin-left: -16px;\n}\n.hb-ic[data-o=\"vertical\"] .hb-ic-handle {\n  left: 0;\n  right: 0;\n  top: var(--hb-pos);\n  height: 32px;\n  margin-top: -16px;\n}\n.hb-ic-handle::before {\n  content: \"\";\n  position: absolute;\n  background: #fff;\n  box-shadow: 0 0 8px rgba(0, 0, 0, .5);\n}\n.hb-ic[data-o=\"horizontal\"] .hb-ic-handle::before { top: 0; bottom: 0; left: 15px; width: 2px; }\n.hb-ic[data-o=\"vertical\"] .hb-ic-handle::before { left: 0; right: 0; top: 15px; height: 2px; }\n.hb-ic-knob {\n  position: absolute;\n  top: 50%;\n  left: 50%;\n  display: grid;\n  place-items: center;\n  width: 32px;\n  height: 32px;\n  margin: -16px 0 0 -16px;\n  border: 2px solid #fff;\n  border-radius: 50%;\n  background: rgba(10, 10, 10, .7);\n  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);\n  backdrop-filter: blur(6px);\n  transition: box-shadow .2s ease, background .2s ease;\n}\n.hb-ic[data-o=\"vertical\"] .hb-ic-knob { transform: rotate(90deg); }\n.hb-ic-handle:focus-visible .hb-ic-knob { box-shadow: 0 0 0 3px #2f7bff; }\n.hb-ic[data-drag=\"true\"] .hb-ic-knob { background: rgba(47, 123, 255, .85); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-ic-knob { transition: none; }\n}\n`;\n\nfunction clamp(value: number) {\n  return Math.min(100, Math.max(0, value));\n}\n\nexport function ImageCompare({\n  before,\n  after,\n  initial = 50,\n  labels,\n  orientation = \"horizontal\",\n  className = \"\",\n  style,\n  onPointerDown,\n  onPointerMove,\n  onPointerUp,\n  onPointerCancel,\n  ...rest\n}: ImageCompareProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const handleRef = React.useRef<HTMLDivElement>(null);\n  const draggingRef = React.useRef(false);\n  const [pos, setPos] = React.useState(() => clamp(initial));\n  const [dragging, setDragging] = React.useState(false);\n\n  const vertical = orientation === \"vertical\";\n  const text = { before: \"Before\", after: \"After\", ...labels };\n\n  function setFromPointer(e: React.PointerEvent<HTMLDivElement>) {\n    const el = rootRef.current;\n    if (!el) return;\n    const r = el.getBoundingClientRect();\n    const size = vertical ? r.height : r.width;\n    if (size <= 0) return;\n    const offset = vertical ? e.clientY - r.top : e.clientX - r.left;\n    setPos(clamp((offset / size) * 100));\n  }\n\n  function handleDown(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerDown?.(e);\n    if (e.defaultPrevented || (e.pointerType === \"mouse\" && e.button !== 0)) return;\n    draggingRef.current = true;\n    setDragging(true);\n    e.currentTarget.setPointerCapture(e.pointerId);\n    handleRef.current?.focus({ preventScroll: true });\n    setFromPointer(e);\n  }\n\n  function handleMove(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(e);\n    if (!draggingRef.current) return;\n    setFromPointer(e);\n  }\n\n  function endDrag() {\n    draggingRef.current = false;\n    setDragging(false);\n  }\n\n  function handleUp(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerUp?.(e);\n    endDrag();\n  }\n\n  function handleCancel(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerCancel?.(e);\n    endDrag();\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    const step = e.shiftKey ? 10 : 2;\n    let next: number | null = null;\n    if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") next = pos - step;\n    else if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") next = pos + step;\n    else if (e.key === \"PageUp\") next = pos - 10;\n    else if (e.key === \"PageDown\") next = pos + 10;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = 100;\n    if (next === null) return;\n    e.preventDefault();\n    setPos(clamp(next));\n  }\n\n  const vars = { \"--hb-pos\": `${pos}%`, ...style } as React.CSSProperties;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-ic ${className}`}\n      style={vars}\n      data-o={orientation}\n      data-drag={dragging}\n      onPointerDown={handleDown}\n      onPointerMove={handleMove}\n      onPointerUp={handleUp}\n      onPointerCancel={handleCancel}\n      {...rest}\n    >\n      <style href=\"hb-image-compare\" precedence=\"default\">{css}</style>\n      <div className=\"hb-ic-layer hb-ic-before\">{before}</div>\n      <div className=\"hb-ic-layer hb-ic-after\">{after}</div>\n      {text.before && (\n        <span className=\"hb-ic-chip\" data-side=\"before\">\n          {text.before}\n        </span>\n      )}\n      {text.after && (\n        <span className=\"hb-ic-chip\" data-side=\"after\">\n          {text.after}\n        </span>\n      )}\n      <div\n        ref={handleRef}\n        className=\"hb-ic-handle\"\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={`${text.before} and ${text.after} comparison`}\n        aria-orientation={orientation}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        aria-valuenow={Math.round(pos)}\n        onKeyDown={handleKeyDown}\n      >\n        <span className=\"hb-ic-knob\" aria-hidden=\"true\">\n          <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n            <path d=\"M8 6l-6 6 6 6M16 6l6 6-6 6\" />\n          </svg>\n        </span>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}