{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "before-after",
  "title": "Before / after",
  "description": "Drag to compare the original with the edit.",
  "dependencies": [
    "photocn@^0.1.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/blocks/before-after.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useRef, useState, type PointerEvent } from \"react\";\nimport { useImageEditorState, type AdjustLightValue } from \"photocn/react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface BeforeAfterProps {\n  src: string;\n  /** Filter preset label to apply, e.g. \"juno\". */\n  filter?: string;\n  /** Light adjustments to apply, -1..1. */\n  lights?: Partial<AdjustLightValue>;\n  className?: string;\n}\n\n/**\n * Drag the handle to compare the original with the edit. The original is a\n * plain <img>; the edit is the editor's canvas, clipped by the handle.\n */\nexport function BeforeAfter({ src, filter = \"juno\", lights, className }: BeforeAfterProps) {\n  const editor = useImageEditorState({ src, keyboardShortcuts: false });\n  const [split, setSplit] = useState(50);\n  const stage = useRef<HTMLDivElement | null>(null);\n  const applied = useRef(false);\n\n  useEffect(() => {\n    if (!editor.isReady || applied.current) return;\n    applied.current = true;\n    if (lights) editor.adjust.setLights({ ...editor.adjust.value.lights, ...lights });\n    void editor.filters.select(filter);\n  }, [editor, filter, lights]);\n\n  const size = editor.imageSize;\n  const move = (event: PointerEvent<HTMLDivElement>) => {\n    const box = stage.current?.getBoundingClientRect();\n    if (!box || (event.type === \"pointermove\" && event.buttons === 0)) return;\n    setSplit(Math.min(100, Math.max(0, ((event.clientX - box.left) / box.width) * 100)));\n  };\n\n  return (\n    <div\n      className={cn(\"relative mx-auto w-full touch-none select-none overflow-hidden rounded-xl bg-muted\", className)}\n      onPointerDown={(event) => {\n        event.currentTarget.setPointerCapture(event.pointerId);\n        move(event);\n      }}\n      onPointerMove={move}\n      ref={(node) => {\n        stage.current = node;\n        editor.rootRef.current = node;\n      }}\n      style={{ aspectRatio: size ? `${size.width} / ${size.height}` : \"4 / 3\" }}\n    >\n      {/* eslint-disable-next-line @next/next/no-img-element */}\n      <img alt=\"Before\" className=\"absolute inset-0 size-full object-cover\" draggable={false} src={src} />\n      <div className=\"absolute inset-0\" ref={editor.stageRef} style={{ clipPath: `inset(0 0 0 ${split}%)` }}>\n        {editor.imageSrc ? (\n          <canvas\n            aria-label=\"After\"\n            className=\"absolute inset-0 size-full\"\n            key={editor.canvasKey}\n            ref={editor.canvasRef}\n          />\n        ) : null}\n      </div>\n      <div aria-hidden className=\"absolute inset-y-0 w-0.5 bg-white shadow\" style={{ left: `${split}%` }}>\n        <div className=\"absolute top-1/2 left-1/2 flex size-9 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-white text-xs font-medium text-black shadow\">\n          ⇆\n        </div>\n      </div>\n      <span className=\"absolute top-3 left-3 rounded bg-black/50 px-2 py-0.5 text-xs text-white\">Before</span>\n      <span className=\"absolute top-3 right-3 rounded bg-black/50 px-2 py-0.5 text-xs text-white\">After</span>\n      <input\n        aria-label=\"Compare position\"\n        className=\"sr-only\"\n        max={100}\n        min={0}\n        onChange={(event) => setSplit(Number(event.target.value))}\n        type=\"range\"\n        value={Math.round(split)}\n      />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/before-after.tsx"
    }
  ],
  "categories": [
    "blocks"
  ],
  "type": "registry:block"
}