{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "signature-pad",
  "title": "Signature Pad",
  "description": "Signature Pad from the Get IT Done design system.",
  "dependencies": [
    "lucide-react@^0.379.0"
  ],
  "registryDependencies": [
    "https://zero-design.itdone.de/r/button.json",
    "https://zero-design.itdone.de/r/labels-context.json",
    "https://zero-design.itdone.de/r/recipes.json",
    "https://zero-design.itdone.de/r/utils.json",
    "https://zero-design.itdone.de/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/ui/signature-pad.tsx",
      "content": "'use client';\n\nimport { Eraser } from 'lucide-react';\nimport * as React from 'react';\n\nimport { focusRing } from '@/lib/recipes';\nimport { cn } from '@/lib/utils';\nimport { Button } from '@/components/ui/button';\nimport { useLabels } from '@/components/ui/labels-context';\n\nexport interface SignaturePadHandle {\n  clear: () => void;\n  // PNG data URL of the drawn signature, or null while the pad is empty.\n  toDataURL: () => string | null;\n  isEmpty: () => boolean;\n}\n\nexport interface SignaturePadProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {\n  // Called with the PNG data URL after each finished stroke, and with null after clearing.\n  onChange?: (dataUrl: string | null) => void;\n  // Accessible name of the drawing area. Defaults to the provider text for `signature`.\n  label?: string;\n  // Hint shown while the pad is empty.\n  placeholder?: string;\n  disabled?: boolean;\n  invalid?: boolean;\n}\n\n// Freehand signature field on a canvas (mouse, finger, stylus). Drawing is a pointer gesture, so offer a typed alternative such as a name field next to it. Ink uses the current text colour.\nconst SignaturePad = React.forwardRef<SignaturePadHandle, SignaturePadProps>(\n  ({ className, onChange, label: labelProp, placeholder: placeholderProp, disabled = false, invalid = false, ...props }, ref) => {\n    const l = useLabels();\n    const label = labelProp ?? l.signature;\n    const placeholder = placeholderProp ?? l.signHere;\n    const canvasRef = React.useRef<HTMLCanvasElement>(null);\n    const drawing = React.useRef(false);\n    const moved = React.useRef(false);\n    const [empty, setEmpty] = React.useState(true);\n\n    // Match the bitmap to the displayed size and the device pixel ratio.\n    React.useEffect(() => {\n      const canvas = canvasRef.current;\n      if (!canvas) return;\n      const ratio = window.devicePixelRatio || 1;\n      canvas.width = canvas.offsetWidth * ratio;\n      canvas.height = canvas.offsetHeight * ratio;\n      canvas.getContext('2d')?.scale(ratio, ratio);\n    }, []);\n\n    const clear = React.useCallback(() => {\n      const canvas = canvasRef.current;\n      canvas?.getContext('2d')?.clearRect(0, 0, canvas.width, canvas.height);\n      setEmpty(true);\n      onChange?.(null);\n    }, [onChange]);\n\n    React.useImperativeHandle(\n      ref,\n      () => ({\n        clear,\n        toDataURL: () => (empty ? null : (canvasRef.current?.toDataURL('image/png') ?? null)),\n        isEmpty: () => empty,\n      }),\n      [clear, empty],\n    );\n\n    const position = (event: React.PointerEvent<HTMLCanvasElement>) => {\n      const rect = event.currentTarget.getBoundingClientRect();\n      return { x: event.clientX - rect.left, y: event.clientY - rect.top };\n    };\n\n    const start = (event: React.PointerEvent<HTMLCanvasElement>) => {\n      if (disabled) return;\n      const ctx = canvasRef.current?.getContext('2d');\n      if (!ctx) return;\n      event.currentTarget.setPointerCapture?.(event.pointerId);\n      drawing.current = true;\n      moved.current = false;\n      ctx.lineWidth = 2;\n      ctx.lineCap = 'round';\n      ctx.lineJoin = 'round';\n      ctx.strokeStyle = getComputedStyle(event.currentTarget).color;\n      const { x, y } = position(event);\n      ctx.beginPath();\n      ctx.moveTo(x, y);\n    };\n\n    const move = (event: React.PointerEvent<HTMLCanvasElement>) => {\n      if (!drawing.current) return;\n      const ctx = canvasRef.current?.getContext('2d');\n      if (!ctx) return;\n      const { x, y } = position(event);\n      ctx.lineTo(x, y);\n      ctx.stroke();\n      moved.current = true;\n      setEmpty(false);\n    };\n\n    const end = () => {\n      if (!drawing.current) return;\n      drawing.current = false;\n      if (moved.current) onChange?.(canvasRef.current?.toDataURL('image/png') ?? null);\n    };\n\n    return (\n      <div\n        data-state={empty ? 'empty' : 'signed'}\n        data-invalid={invalid || undefined}\n        data-disabled={disabled || undefined}\n        className={cn(\n          'relative w-full rounded-dialog border border-dashed border-border-default bg-background',\n          invalid && 'border-border-destructive',\n          disabled && 'opacity-disabled',\n          className,\n        )}\n        {...props}\n      >\n        <canvas\n          ref={canvasRef}\n          role=\"img\"\n          aria-label={label}\n          tabIndex={disabled ? -1 : 0}\n          className={cn('block h-40 w-full touch-none rounded-dialog text-foreground', ...focusRing, disabled ? 'cursor-not-allowed' : 'cursor-crosshair')}\n          onPointerDown={start}\n          onPointerMove={move}\n          onPointerUp={end}\n          onPointerCancel={end}\n        />\n        {empty ? (\n          <span className=\"pointer-events-none absolute inset-0 flex items-center justify-center typography-ui text-text-subtle\">{placeholder}</span>\n        ) : null}\n        {!empty && !disabled ? (\n          <Button type=\"button\" variant=\"ghost\" size=\"control-sm\" icon={<Eraser aria-hidden=\"true\" />} className=\"absolute right-2 top-2\" onClick={() => {\n              clear();\n              // The button unmounts with the signature, so hand focus to the drawing surface instead of dropping it to the page or dialog.\n              canvasRef.current?.focus();\n            }}\n          >\n            {l.clear}\n          </Button>\n        ) : null}\n      </div>\n    );\n  },\n);\nSignaturePad.displayName = 'SignaturePad';\n\nexport { SignaturePad };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}