{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "signature-pad",
  "title": "Signature Pad",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/signature-pad/SignaturePad.tsx",
      "content": "import * as React from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler'\nimport Svg, { Path } from 'react-native-svg'\nimport { Button } from '@/components/ui/button'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { useThemeColors } from '@/lib/theme'\nimport { cn } from '@/lib/utils'\n\nexport interface SignaturePoint {\n  readonly x: number\n  readonly y: number\n}\nexport type SignatureStroke = readonly SignaturePoint[]\nexport type SignatureValue = readonly SignatureStroke[]\n\nexport interface SignaturePadProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  /** Saved strokes use coordinates in the range 0 to 1, relative to the canvas. */\n  value?: SignatureValue\n  defaultValue?: SignatureValue\n  onValueChange?: (value: SignatureValue) => void\n  disabled?: boolean\n  label?: string\n  undoLabel?: string\n  clearLabel?: string\n  emptyLabel?: string\n  drawnLabel?: string\n  /** A caller-owned way to confirm without a freehand gesture. */\n  alternative?: React.ReactNode\n}\n\nconst empty: SignatureValue = []\nconst clamp = (value: number) => Math.max(0, Math.min(1, value))\n\ninterface CanvasSize {\n  width: number\n  height: number\n}\n\nfunction coordinates(x: number, y: number, { width, height }: CanvasSize): SignaturePoint {\n  return { x: clamp(x / width), y: clamp(y / height) }\n}\n\nfunction addPoint(stroke: SignatureStroke, point: SignaturePoint) {\n  const last = stroke.at(-1)\n  if (last && Math.hypot(last.x - point.x, last.y - point.y) < 0.003) return stroke\n  return [...stroke, point]\n}\n\nfunction pathOf(stroke: SignatureStroke, { width, height }: CanvasSize) {\n  return stroke\n    .filter(({ x, y }) => Number.isFinite(x) && Number.isFinite(y))\n    .map(({ x, y }, index) => `${index ? 'L' : 'M'} ${clamp(x) * width} ${clamp(y) * height}`)\n    .join(' ')\n}\n\nexport function SignaturePad({\n  className,\n  value,\n  defaultValue = empty,\n  onValueChange,\n  disabled = false,\n  label = 'Signature',\n  undoLabel = 'Undo stroke',\n  clearLabel = 'Clear signature',\n  emptyLabel = 'Draw your signature in the box.',\n  drawnLabel = 'Signature drawn.',\n  alternative,\n  ...props\n}: SignaturePadProps) {\n  const colors = useThemeColors()\n  const [canvas, setCanvas] = React.useState<CanvasSize>({ width: 0, height: 0 })\n  const [internal, setInternal] = React.useState(defaultValue)\n  const [draft, setDraft] = React.useState<SignatureStroke>([])\n  const [edited, setEdited] = React.useState(false)\n  const strokes = value ?? internal\n  const status = strokes.length ? drawnLabel : emptyLabel\n  useAnnouncement(edited ? status : undefined)\n  const enabled = !disabled && canvas.width > 0 && canvas.height > 0\n  const active = React.useRef<{ canvas: CanvasSize; points: SignatureStroke } | null>(null)\n  const latest = React.useRef({ canvas, enabled, strokes, value, onValueChange })\n  latest.current = { canvas, enabled, strokes, value, onValueChange }\n\n  function change(next: SignatureValue) {\n    const state = latest.current\n    if (!state.enabled) return\n    setEdited(true)\n    if (state.value === undefined) {\n      state.strokes = next\n      setInternal(next)\n    }\n    state.onValueChange?.(next)\n  }\n\n  function cancelDraft() {\n    active.current = null\n    setDraft([])\n  }\n\n  const pan = Gesture.Pan()\n    .minDistance(0)\n    .maxPointers(1)\n    .enabled(enabled)\n    .runOnJS(true)\n    .onStart(({ x, y }) => {\n      const state = latest.current\n      if (!state.enabled) return\n      const points = [coordinates(x, y, state.canvas)]\n      active.current = { canvas: state.canvas, points }\n      setDraft(points)\n    })\n    .onUpdate(({ x, y, numberOfPointers }) => {\n      const stroke = active.current\n      if (numberOfPointers > 1) {\n        cancelDraft()\n      } else if (stroke && stroke.canvas === latest.current.canvas && latest.current.enabled) {\n        const points = addPoint(stroke.points, coordinates(x, y, stroke.canvas))\n        if (points !== stroke.points) {\n          stroke.points = points\n          setDraft(points)\n        }\n      }\n    })\n    .onEnd(({ x, y }, success) => {\n      const stroke = active.current\n      const state = latest.current\n      if (!success || !stroke || stroke.canvas !== state.canvas || !state.enabled) return\n      const points = addPoint(stroke.points, coordinates(x, y, stroke.canvas))\n      if (points.length >= 2) change([...state.strokes, points])\n    })\n    .onFinalize(cancelDraft)\n\n  return (\n    <View {...props} className={cn('gap-2', className)}>\n      <Text className=\"font-semibold\" accessibilityRole=\"header\">\n        {label}\n      </Text>\n      <GestureHandlerRootView style={{ flexGrow: 0 }}>\n        <GestureDetector gesture={pan}>\n          <View\n            collapsable={false}\n            accessible={false}\n            className=\"h-[168px] overflow-hidden rounded-lg border border-muted-foreground bg-muted\"\n            onLayout={({ nativeEvent: { layout } }) => {\n              setCanvas((size) =>\n                size.width === layout.width && size.height === layout.height\n                  ? size\n                  : { width: layout.width, height: layout.height },\n              )\n            }}\n          >\n            <View pointerEvents=\"none\" aria-hidden className=\"absolute inset-0\">\n              <Svg width={canvas.width} height={canvas.height}>\n                {[...strokes, draft]\n                  .filter((line) => line.length > 1)\n                  .map((line, index) => (\n                    <Path\n                      key={index}\n                      d={pathOf(line, canvas)}\n                      fill=\"none\"\n                      stroke={colors.foreground}\n                      strokeWidth={2.5}\n                      strokeLinecap=\"round\"\n                      strokeLinejoin=\"round\"\n                    />\n                  ))}\n              </Svg>\n            </View>\n          </View>\n        </GestureDetector>\n      </GestureHandlerRootView>\n      <Text size=\"sm\" variant=\"muted\">\n        {status}\n      </Text>\n      <View className=\"flex-row flex-wrap gap-2\">\n        <Button\n          variant=\"outline\"\n          disabled={!enabled || !strokes.length}\n          onPress={() => {\n            cancelDraft()\n            change(latest.current.strokes.slice(0, -1))\n          }}\n        >\n          {undoLabel}\n        </Button>\n        <Button\n          variant=\"ghost\"\n          disabled={!enabled || !strokes.length}\n          onPress={() => {\n            cancelDraft()\n            change(empty)\n          }}\n        >\n          {clearLabel}\n        </Button>\n      </View>\n      {alternative}\n    </View>\n  )\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/signature-pad/SignaturePad.tsx"
    },
    {
      "path": "packages/registry-native/components/signature-pad/index.ts",
      "content": "export {\n  SignaturePad,\n  type SignaturePadProps,\n  type SignaturePoint,\n  type SignatureStroke,\n  type SignatureValue,\n} from './SignaturePad'\n",
      "type": "registry:ui",
      "target": "~/components/ui/signature-pad/index.ts"
    }
  ],
  "dependencies": [
    "react-native-gesture-handler",
    "react-native-svg"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/theme.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "A freehand drawing field with normalized signature strokes, undo, clear, and an alternate input slot.",
  "categories": [
    "control"
  ]
}