{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sketch-pad",
  "title": "Sketch Pad",
  "author": "VenusUI",
  "description": "A two-knob drawing toy: one knob draws across, the other up and down; shake to clear.",
  "files": [
    {
      "path": "registry/default/ui/sketch-pad.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SketchPadProps extends React.ComponentProps<\"div\"> {\n  width?: number\n  height?: number\n}\n\n/**\n * A knob-drawing toy. The left knob moves the stylus across, the right one\n * up and down; drag them (or focus the screen and use the arrow keys) to\n * draw one continuous line. Shake to clear.\n */\nfunction SketchPad({ width = 300, height = 200, className, ...props }: SketchPadProps) {\n  const canvas = React.useRef<HTMLCanvasElement>(null)\n  const pen = React.useRef({ x: width / 2, y: height / 2 })\n  const [turns, setTurns] = React.useState({ x: 0, y: 0 })\n  const [shakes, setShakes] = React.useState(0)\n  const [moves, setMoves] = React.useState(0)\n  const lastY = React.useRef(0)\n\n  React.useEffect(() => {\n    const element = canvas.current\n    if (!element) return\n    const ratio = window.devicePixelRatio || 1\n    element.width = width * ratio\n    element.height = height * ratio\n    element.getContext(\"2d\")?.scale(ratio, ratio)\n  }, [width, height])\n\n  const move = (dx: number, dy: number) => {\n    const context = canvas.current?.getContext(\"2d\")\n    if (!context) return\n    const from = pen.current\n    const to = { x: Math.min(width - 2, Math.max(2, from.x + dx)), y: Math.min(height - 2, Math.max(2, from.y + dy)) }\n    context.strokeStyle = \"#3f3f46\"\n    context.lineWidth = 1.6\n    context.lineCap = \"round\"\n    context.beginPath()\n    context.moveTo(from.x, from.y)\n    context.lineTo(to.x, to.y)\n    context.stroke()\n    pen.current = to\n    setTurns((value) => ({ x: value.x + dx * 3, y: value.y + dy * 3 }))\n    setMoves((value) => value + 1)\n  }\n\n  const shake = () => {\n    const context = canvas.current?.getContext(\"2d\")\n    context?.clearRect(0, 0, width, height)\n    setShakes((value) => value + 1)\n    setMoves(0)\n  }\n\n  const knob = (axis: \"x\" | \"y\", label: string) => {\n    return (\n      <button\n        type=\"button\"\n        aria-label={`${label} knob. Drag up or down to draw.`}\n        onPointerDown={(event) => {\n          event.currentTarget.setPointerCapture(event.pointerId)\n          lastY.current = event.clientY\n        }}\n        onPointerMove={(event) => {\n          if (!event.currentTarget.hasPointerCapture(event.pointerId)) return\n          const delta = (lastY.current - event.clientY) / 2\n          lastY.current = event.clientY\n          if (delta) move(axis === \"x\" ? delta : 0, axis === \"y\" ? -delta : 0)\n        }}\n        onKeyDown={(event) => {\n          const step = event.key === \"ArrowUp\" || event.key === \"ArrowRight\" ? 4 : event.key === \"ArrowDown\" || event.key === \"ArrowLeft\" ? -4 : 0\n          if (!step) return\n          event.preventDefault()\n          move(axis === \"x\" ? step : 0, axis === \"y\" ? -step : 0)\n        }}\n        style={{ rotate: `${turns[axis]}deg` }}\n        className=\"grid size-14 cursor-ns-resize touch-none place-items-center rounded-full bg-[radial-gradient(circle_at_35%_30%,#fafafa,#d4d4d8_55%,#a1a1aa)] shadow-[0_4px_8px_rgb(0_0_0/0.35),inset_0_0_0_3px_#e4e4e7] outline-none focus-visible:ring-3 focus-visible:ring-ring/60\"\n      >\n        <span aria-hidden=\"true\" className=\"h-5 w-1 -translate-y-3 rounded-full bg-zinc-500\" />\n      </button>\n    )\n  }\n\n  return (\n    <div data-slot=\"sketch-pad\" className={cn(\"w-fit max-w-full\", className)} {...props}>\n      <div key={shakes} className={cn(\"rounded-[1.75rem] bg-linear-to-b from-teal-500 to-teal-700 p-5 pb-4 shadow-[0_18px_30px_-14px_rgb(0_0_0/0.6),inset_0_2px_0_rgb(255_255_255/0.3)]\", shakes > 0 && \"animate-sketch-pad-shake motion-reduce:animate-none\")}>\n        <canvas\n          ref={canvas}\n          tabIndex={0}\n          role=\"img\"\n          aria-label={`Drawing screen. Use the arrow keys to draw. ${moves} strokes.`}\n          onKeyDown={(event) => {\n            const moves: Record<string, [number, number]> = { ArrowLeft: [-4, 0], ArrowRight: [4, 0], ArrowUp: [0, -4], ArrowDown: [0, 4] }\n            const step = moves[event.key]\n            if (!step) return\n            event.preventDefault()\n            move(...step)\n          }}\n          style={{ width, height }}\n          className=\"block max-w-full rounded-lg bg-[#c9cbc4] shadow-[inset_0_2px_8px_rgb(0_0_0/0.35)] outline-none focus-visible:ring-3 focus-visible:ring-white/70\"\n        />\n        <div className=\"mt-4 flex items-center justify-between\">\n          {knob(\"x\", \"Left-right\")}\n          <button type=\"button\" onClick={shake} className=\"rounded-full bg-teal-900/50 px-4 py-1.5 font-mono text-xs font-bold tracking-widest text-teal-50 uppercase outline-none hover:bg-teal-900/70 focus-visible:ring-3 focus-visible:ring-white/70\">\n            Shake\n          </button>\n          {knob(\"y\", \"Up-down\")}\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { SketchPad }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-sketch-pad-shake": "sketch-pad-shake 0.5s ease-in-out"
    }
  },
  "css": {
    "@keyframes sketch-pad-shake": {
      "0%, 100%": {
        "transform": "translateX(0) rotate(0)"
      },
      "20%": {
        "transform": "translateX(-10px) rotate(-2deg)"
      },
      "40%": {
        "transform": "translateX(10px) rotate(2deg)"
      },
      "60%": {
        "transform": "translateX(-6px) rotate(-1deg)"
      },
      "80%": {
        "transform": "translateX(6px) rotate(1deg)"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "inputs"
  ],
  "type": "registry:ui"
}