{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "signature-pad",
  "title": "Signature Pad",
  "description": "Sign with a finger, pen or mouse in smooth strokes, with undo, SVG and PNG export, and a typed name for anyone using a keyboard.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/button.json",
    "https://miseui.junsu4621.workers.dev/r/input.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/signature-pad.tsx",
      "content": "import type * as React from \"react\"\nimport { useImperativeHandle } from \"react\"\nimport { DEFAULT_STROKE_WIDTH, signatureToPng, signatureToSvg } from \"@/registry/miseui/ui/signature-pad-export\"\nimport { strokesToPath, type SignatureBox, type SignatureStroke } from \"@/registry/miseui/ui/signature-pad-math\"\nimport { CompactActions, PadInk, SignatureActions, SigningRule, type SignatureLabels } from \"@/registry/miseui/ui/signature-pad-parts\"\nimport { usePadDrawing, useSignature, type SignatureValue } from \"@/registry/miseui/ui/signature-pad-state\"\nimport { Input } from \"@/registry/miseui/ui/input\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype SignaturePadVariant = \"plain\" | \"line\" | \"card\" | \"compact\"\n\n/** Strokes live in this fixed box, and the SVG scales it: resizing the pad can never lose or redraw ink. */\nconst BOX: Record<SignaturePadVariant, SignatureBox> = {\n  plain: { width: 500, height: 200 },\n  line: { width: 500, height: 200 },\n  card: { width: 500, height: 200 },\n  compact: { width: 400, height: 100 },\n}\n\nconst PAD_CLASS: Record<SignaturePadVariant, string> = {\n  plain: \"aspect-[5/2] rounded-lg border bg-background\",\n  line: \"aspect-[5/2]\",\n  card: \"aspect-[5/2] rounded-lg bg-muted\",\n  compact: \"aspect-[4/1] rounded-md border bg-background\",\n}\n\nconst DEFAULT_LABELS: SignatureLabels = {\n  pad: \"Signature\",\n  placeholder: \"Sign here\",\n  lineHint: \"Sign above the line\",\n  undo: \"Undo\",\n  clear: \"Clear\",\n  typeInstead: \"Type instead\",\n  drawInstead: \"Draw instead\",\n  typedName: \"Your full name\",\n  strokes: (count) => (count === 0 ? \"empty\" : `${count} ${count === 1 ? \"stroke\" : \"strokes\"}`),\n}\n\ninterface SignaturePadHandle {\n  clear: () => void\n  undo: () => void\n  isEmpty: () => boolean\n  toSvgPath: () => string\n  toSvg: (options?: { color?: string; background?: string }) => string\n  toPng: (options?: { color?: string; background?: string; scale?: number }) => string\n}\n\ninterface SignaturePadProps extends Omit<React.ComponentProps<\"div\">, \"onChange\" | \"defaultValue\" | \"title\" | \"ref\"> {\n  /** `plain` a bordered box, `line` a signing rule with no box, `card` a titled surface, `compact` one short strip with its controls inside. */\n  variant?: SignaturePadVariant\n  defaultStrokes?: readonly SignatureStroke[]\n  onChange?: (value: SignatureValue) => void\n  /** `card`: the heading. */\n  title?: React.ReactNode\n  /** `card`: one line under the heading, a good place for what the signature agrees to. */\n  description?: React.ReactNode\n  /** A way to sign without a pointer. Turn it off only if a drawn signature is a legal requirement and you offer another route. */\n  allowTyped?: boolean\n  disabled?: boolean\n  /** Posts the path, or the typed name, with a form. */\n  name?: string\n  strokeWidth?: number\n  labels?: Partial<SignatureLabels>\n  ref?: React.Ref<SignaturePadHandle>\n}\n\nfunction CardHeading({ title, description }: Pick<SignaturePadProps, \"title\" | \"description\">) {\n  if (!title && !description) return null\n  return (\n    <div className=\"grid gap-1\">\n      {title ? <p className=\"text-[15px] font-medium\">{title}</p> : null}\n      {description ? <p className=\"text-[13px] text-muted-foreground\">{description}</p> : null}\n    </div>\n  )\n}\n\nfunction SignaturePad({ variant = \"plain\", defaultStrokes, onChange, title, description, allowTyped = true, disabled = false, name, strokeWidth = DEFAULT_STROKE_WIDTH, labels: labelOverrides, ref, className, ...props }: SignaturePadProps) {\n  const labels = { ...DEFAULT_LABELS, ...labelOverrides }\n  const box = BOX[variant]\n  const signature = useSignature(defaultStrokes, onChange)\n  const { strokes, typing, empty } = signature\n  const { svg, drawing, surface } = usePadDrawing(box, disabled || typing, signature.dispatch)\n  const content = { strokes, typed: signature.name }\n  useImperativeHandle(ref, () => ({\n    clear: signature.clear,\n    undo: signature.undo,\n    isEmpty: () => empty,\n    toSvgPath: () => (signature.name ? \"\" : strokesToPath(strokes)),\n    toSvg: (options) => signatureToSvg(content, { box, strokeWidth, ...options }),\n    toPng: (options) => signatureToPng(content, { box, strokeWidth, ...options }),\n  }))\n  const actions = { labels, typing, allowTyped, canUndo: signature.canUndo, canClear: !empty, disabled, onUndo: signature.undo, onClear: signature.clear, onToggleMode: signature.toggleMode }\n  const pad = (\n    <div\n      data-slot=\"signature-pad-surface\"\n      role=\"img\"\n      aria-label={`${labels.pad}, ${signature.name || labels.strokes(strokes.length)}`}\n      className={cn(\"relative w-full min-w-0 touch-none overflow-hidden select-none\", PAD_CLASS[variant], !disabled && !typing && \"cursor-crosshair\", disabled && \"opacity-50\")}\n      {...surface}\n    >\n      <PadInk strokes={strokes} drawing={drawing} typed={signature.name} box={box} strokeWidth={strokeWidth} svg={svg} />\n      {variant === \"line\" ? <SigningRule hint={labels.lineHint} empty={empty && !drawing} /> : null}\n      {variant !== \"line\" && empty && !drawing ? <p className=\"pointer-events-none absolute inset-0 grid place-items-center text-[13px] text-muted-foreground\">{labels.placeholder}</p> : null}\n    </div>\n  )\n  return (\n    <div data-slot=\"signature-pad\" data-variant={variant} data-mode={typing ? \"typed\" : \"drawn\"} className={cn(\"grid w-full min-w-0 grid-cols-[minmax(0,1fr)] gap-2\", variant === \"card\" && \"gap-3 rounded-xl border bg-card p-4\", className)} {...props}>\n      {variant === \"card\" ? <CardHeading title={title} description={description} /> : null}\n      {variant === \"compact\" ? (\n        <div className=\"relative min-w-0\">\n          {pad}\n          <CompactActions {...actions} />\n        </div>\n      ) : (\n        pad\n      )}\n      {/* Mounted only by pressing the toggle, so taking focus here is what that press asked for. */}\n      {typing ? <Input autoFocus aria-label={labels.typedName} placeholder={labels.typedName} disabled={disabled} value={signature.typed} autoComplete=\"name\" onChange={(event) => signature.typeName(event.target.value)} /> : null}\n      {variant === \"compact\" ? null : <SignatureActions {...actions} />}\n      {name ? <input type=\"hidden\" name={name} value={signature.name || strokesToPath(strokes)} /> : null}\n    </div>\n  )\n}\n\nexport { SignaturePad, signatureToPng, signatureToSvg, type SignaturePadHandle, type SignaturePadProps, type SignaturePadVariant, type SignatureStroke, type SignatureValue }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/signature-pad-export.ts",
      "content": "import { strokesToPath, typedFontSize, type SignatureBox, type SignatureStroke } from \"@/registry/miseui/ui/signature-pad-math\"\n\nconst SCRIPT_FONT = '\"Snell Roundhand\", \"Segoe Script\", \"Brush Script MT\", cursive'\nconst DEFAULT_STROKE_WIDTH = 2.5\n/** A signature leaves the app for a document, so it exports in dark ink even when the pad is in dark mode. */\nconst DEFAULT_INK = \"#111111\"\n\ninterface SignatureContent {\n  strokes: readonly SignatureStroke[]\n  /** A typed name. It wins over strokes when it has text. */\n  typed?: string\n}\n\ninterface SignatureExportOptions {\n  box: SignatureBox\n  color?: string\n  strokeWidth?: number\n  background?: string\n}\n\nconst escapeXml = (text: string) => text.replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\").replace(/\"/g, \"&quot;\").replace(/'/g, \"&apos;\")\n\nfunction signatureToSvg({ strokes, typed }: SignatureContent, { box, color = DEFAULT_INK, strokeWidth = DEFAULT_STROKE_WIDTH, background }: SignatureExportOptions) {\n  const fill = background ? `<rect width=\"${box.width}\" height=\"${box.height}\" fill=\"${escapeXml(background)}\"/>` : \"\"\n  const ink = typed?.trim()\n    ? `<text x=\"${box.width / 2}\" y=\"${box.height / 2}\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"${escapeXml(SCRIPT_FONT)}\" font-size=\"${typedFontSize(typed, box)}\" fill=\"${escapeXml(color)}\">${escapeXml(typed.trim())}</text>`\n    : `<path d=\"${strokesToPath(strokes)}\" fill=\"none\" stroke=\"${escapeXml(color)}\" stroke-width=\"${strokeWidth}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`\n  return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${box.width} ${box.height}\" width=\"${box.width}\" height=\"${box.height}\">${fill}${ink}</svg>`\n}\n\n/** Scale 2 by default: a document prints this far sharper than it shows on screen. */\nfunction signatureToPng({ strokes, typed }: SignatureContent, { box, color = DEFAULT_INK, strokeWidth = DEFAULT_STROKE_WIDTH, background, scale = 2 }: SignatureExportOptions & { scale?: number }) {\n  const canvas = document.createElement(\"canvas\")\n  canvas.width = box.width * scale\n  canvas.height = box.height * scale\n  const context = canvas.getContext(\"2d\")\n  if (!context) throw new Error(\"This browser cannot draw to a canvas.\")\n  context.scale(scale, scale)\n  if (background) {\n    context.fillStyle = background\n    context.fillRect(0, 0, box.width, box.height)\n  }\n  if (typed?.trim()) {\n    context.fillStyle = color\n    context.font = `${typedFontSize(typed, box)}px ${SCRIPT_FONT}`\n    context.textAlign = \"center\"\n    context.textBaseline = \"middle\"\n    context.fillText(typed.trim(), box.width / 2, box.height / 2)\n  } else {\n    context.strokeStyle = color\n    context.lineWidth = strokeWidth\n    context.lineCap = \"round\"\n    context.lineJoin = \"round\"\n    context.stroke(new Path2D(strokesToPath(strokes)))\n  }\n  return canvas.toDataURL(\"image/png\")\n}\n\nexport { DEFAULT_STROKE_WIDTH, SCRIPT_FONT, signatureToPng, signatureToSvg, type SignatureContent, type SignatureExportOptions }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/signature-pad-math.ts",
      "content": "interface SignaturePoint {\n  x: number\n  y: number\n}\n\ntype SignatureStroke = readonly SignaturePoint[]\n\ninterface SignatureBox {\n  width: number\n  height: number\n}\n\ninterface SignatureHistory {\n  strokes: readonly SignatureStroke[]\n  /** Every earlier state, so undo can also bring back a page someone cleared by accident. */\n  past: readonly (readonly SignatureStroke[])[]\n}\n\ntype SignatureAction = { type: \"add\"; stroke: SignatureStroke } | { type: \"clear\" } | { type: \"undo\" }\n\nconst MIN_POINT_DISTANCE = 1.5\nconst round = (value: number) => Math.round(value * 10) / 10\nconst at = (point: SignaturePoint) => `${round(point.x)} ${round(point.y)}`\nconst middle = (a: SignaturePoint, b: SignaturePoint) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 })\n\n/** Pointers report faster than a hand moves; points this close only add jitter to the curve. */\nfunction addPoint(stroke: SignatureStroke, next: SignaturePoint, minDistance = MIN_POINT_DISTANCE): SignatureStroke {\n  const last = stroke[stroke.length - 1]\n  if (last && Math.hypot(next.x - last.x, next.y - last.y) < minDistance) return stroke\n  return [...stroke, next]\n}\n\n/**\n * Each sampled point becomes a control point and the curve passes through the midpoints between them.\n * Neighbouring curves then share a tangent, so a hand's corners come out as ink, not as a polygon.\n */\nfunction smoothPath(stroke: SignatureStroke) {\n  if (stroke.length === 0) return \"\"\n  const [first, ...rest] = stroke\n  // A tap is still a mark: a zero-length line with a round cap paints a dot.\n  if (rest.length === 0) return `M${at(first)}h0`\n  if (rest.length === 1) return `M${at(first)}L${at(rest[0])}`\n  const curves = rest\n    .slice(0, -1)\n    .map((point, index) => `Q${at(point)} ${at(middle(point, rest[index + 1]))}`)\n    .join(\"\")\n  return `M${at(first)}L${at(middle(first, rest[0]))}${curves}L${at(rest[rest.length - 1])}`\n}\n\nconst strokesToPath = (strokes: readonly SignatureStroke[]) => strokes.map(smoothPath).join(\"\")\n\n/** Matches the SVG's own \"meet\" fit, so the ink lands under the pen even if a page stretches the pad to another shape. */\nfunction toBoxPoint(clientX: number, clientY: number, rect: Pick<DOMRect, \"left\" | \"top\" | \"width\" | \"height\">, box: SignatureBox): SignaturePoint {\n  if (rect.width <= 0 || rect.height <= 0) return { x: 0, y: 0 }\n  const scale = Math.min(rect.width / box.width, rect.height / box.height)\n  const offsetX = (rect.width - box.width * scale) / 2\n  const offsetY = (rect.height - box.height * scale) / 2\n  return {\n    x: Math.min(box.width, Math.max(0, (clientX - rect.left - offsetX) / scale)),\n    y: Math.min(box.height, Math.max(0, (clientY - rect.top - offsetY) / scale)),\n  }\n}\n\nfunction signatureReducer(state: SignatureHistory, action: SignatureAction): SignatureHistory {\n  if (action.type === \"add\") {\n    if (action.stroke.length === 0) return state\n    return { strokes: [...state.strokes, action.stroke], past: [...state.past, state.strokes] }\n  }\n  if (action.type === \"clear\") {\n    if (state.strokes.length === 0) return state\n    return { strokes: [], past: [...state.past, state.strokes] }\n  }\n  if (state.past.length === 0) return state\n  return { strokes: state.past[state.past.length - 1], past: state.past.slice(0, -1) }\n}\n\n/** Long names shrink to stay inside the pad. The factor is an average glyph width for script faces. */\nfunction typedFontSize(name: string, box: SignatureBox) {\n  const glyphs = Math.max(1, name.trim().length)\n  return Math.min(box.height * 0.32, (box.width * 0.88) / (glyphs * 0.48))\n}\n\nexport { addPoint, signatureReducer, smoothPath, strokesToPath, toBoxPoint, typedFontSize, type SignatureAction, type SignatureBox, type SignatureHistory, type SignaturePoint, type SignatureStroke }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/signature-pad-parts.tsx",
      "content": "import type * as React from \"react\"\r\nimport { Eraser, Keyboard, PenLine, Undo2 } from \"lucide-react\"\r\nimport { Button } from \"@/registry/miseui/ui/button\"\r\nimport { SCRIPT_FONT } from \"@/registry/miseui/ui/signature-pad-export\"\r\nimport { smoothPath, typedFontSize, type SignatureBox, type SignatureStroke } from \"@/registry/miseui/ui/signature-pad-math\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\n\r\ninterface SignatureLabels {\r\n  /** Names the drawing area. */\r\n  pad: string\r\n  placeholder: string\r\n  lineHint: string\r\n  undo: string\r\n  clear: string\r\n  typeInstead: string\r\n  drawInstead: string\r\n  typedName: string\r\n  strokes: (count: number) => string\r\n}\r\n\r\ninterface SignatureActionsProps {\r\n  labels: SignatureLabels\r\n  typing: boolean\r\n  allowTyped: boolean\r\n  canUndo: boolean\r\n  canClear: boolean\r\n  disabled: boolean\r\n  onUndo: () => void\r\n  onClear: () => void\r\n  onToggleMode: () => void\r\n}\r\n\r\n/** Undo stays a real control while it has nothing to do, so the row keeps its shape. */\r\nfunction SignatureActions({ labels, typing, allowTyped, canUndo, canClear, disabled, onUndo, onClear, onToggleMode }: SignatureActionsProps) {\r\n  return (\r\n    <div data-slot=\"signature-pad-actions\" className=\"flex flex-wrap items-center gap-1\">\r\n      {allowTyped ? (\r\n        <Button type=\"button\" variant=\"ghost\" size=\"sm\" disabled={disabled} className=\"pointer-coarse:h-10\" onClick={onToggleMode}>\r\n          {typing ? <PenLine aria-hidden=\"true\" /> : <Keyboard aria-hidden=\"true\" />}\r\n          {typing ? labels.drawInstead : labels.typeInstead}\r\n        </Button>\r\n      ) : null}\r\n      <div className=\"ms-auto flex items-center gap-1\">\r\n        {typing ? null : (\r\n          <Button type=\"button\" variant=\"ghost\" size=\"sm\" disabled={disabled || !canUndo} className=\"pointer-coarse:h-10\" onClick={onUndo}>\r\n            <Undo2 aria-hidden=\"true\" />\r\n            {labels.undo}\r\n          </Button>\r\n        )}\r\n        <Button type=\"button\" variant=\"ghost\" size=\"sm\" disabled={disabled || !canClear} className=\"pointer-coarse:h-10\" onClick={onClear}>\r\n          <Eraser aria-hidden=\"true\" />\r\n          {labels.clear}\r\n        </Button>\r\n      </div>\r\n    </div>\r\n  )\r\n}\r\n\r\nconst ICON_BUTTON_CLASS = \"size-8 pointer-coarse:size-10\"\r\n\r\n/** Compact has no row to spare, so the controls sit in the corner of the pad, out of the way of most signatures. */\r\nfunction CompactActions({ labels, typing, allowTyped, canUndo, canClear, disabled, onUndo, onClear, onToggleMode }: SignatureActionsProps) {\r\n  return (\r\n    <div data-slot=\"signature-pad-actions\" className=\"absolute top-0 right-0 flex items-center\">\r\n      {canUndo && !typing ? (\r\n        <Button type=\"button\" variant=\"ghost\" size=\"icon\" aria-label={labels.undo} disabled={disabled} className={ICON_BUTTON_CLASS} onClick={onUndo}>\r\n          <Undo2 aria-hidden=\"true\" />\r\n        </Button>\r\n      ) : null}\r\n      {canClear ? (\r\n        <Button type=\"button\" variant=\"ghost\" size=\"icon\" aria-label={labels.clear} disabled={disabled} className={ICON_BUTTON_CLASS} onClick={onClear}>\r\n          <Eraser aria-hidden=\"true\" />\r\n        </Button>\r\n      ) : null}\r\n      {allowTyped ? (\r\n        <Button type=\"button\" variant=\"ghost\" size=\"icon\" aria-label={typing ? labels.drawInstead : labels.typeInstead} disabled={disabled} className={ICON_BUTTON_CLASS} onClick={onToggleMode}>\r\n          {typing ? <PenLine aria-hidden=\"true\" /> : <Keyboard aria-hidden=\"true\" />}\r\n        </Button>\r\n      ) : null}\r\n    </div>\r\n  )\r\n}\r\n\r\n/** Anchored from the bottom in px, not a share of the height, so the room above the line grows with the pad. */\r\nfunction SigningRule({ hint, empty }: { hint: string; empty: boolean }) {\r\n  return (\r\n    <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-4 bottom-2\">\r\n      <div className=\"relative\">\r\n        <span className=\"absolute bottom-1 left-0 text-[13px] text-muted-foreground\">x</span>\r\n        <div data-slot=\"signature-pad-rule\" className=\"h-px bg-foreground/40\" />\r\n      </div>\r\n      <p className={cn(\"mt-1 text-[13px] text-muted-foreground\", !empty && \"invisible\")}>{hint}</p>\r\n    </div>\r\n  )\r\n}\r\n\r\ninterface PadInkProps {\r\n  strokes: readonly SignatureStroke[]\r\n  drawing: SignatureStroke | null\r\n  typed: string\r\n  box: SignatureBox\r\n  strokeWidth: number\r\n  svg: React.RefObject<SVGSVGElement | null>\r\n}\r\n\r\nfunction PadInk({ strokes, drawing, typed, box, strokeWidth, svg }: PadInkProps) {\r\n  return (\r\n    <svg ref={svg} aria-hidden=\"true\" viewBox={`0 0 ${box.width} ${box.height}`} className=\"block size-full\">\r\n      {typed ? (\r\n        <text x={box.width / 2} y={box.height / 2} textAnchor=\"middle\" dominantBaseline=\"central\" fontFamily={SCRIPT_FONT} fontSize={typedFontSize(typed, box)} className=\"fill-foreground\">\r\n          {typed}\r\n        </text>\r\n      ) : (\r\n        <g fill=\"none\" strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"stroke-foreground\">\r\n          {strokes.map((stroke, index) => (\r\n            <path key={index} data-slot=\"signature-pad-stroke\" d={smoothPath(stroke)} />\r\n          ))}\r\n          {drawing ? <path data-slot=\"signature-pad-stroke\" d={smoothPath(drawing)} /> : null}\r\n        </g>\r\n      )}\r\n    </svg>\r\n  )\r\n}\r\n\r\nexport { CompactActions, PadInk, SignatureActions, SigningRule, type SignatureActionsProps, type SignatureLabels }\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/signature-pad-state.ts",
      "content": "import type * as React from \"react\"\nimport { useRef, useState } from \"react\"\nimport { addPoint, signatureReducer, strokesToPath, toBoxPoint, type SignatureAction, type SignatureBox, type SignatureStroke } from \"@/registry/miseui/ui/signature-pad-math\"\n\ninterface SignatureValue {\n  /** The stored strokes. Hand these back through `defaultStrokes` to edit later. */\n  strokes: readonly SignatureStroke[]\n  /** The SVG path of the drawing. Empty when typed. */\n  path: string\n  /** The typed name, when someone chose to type. */\n  typed: string\n  empty: boolean\n}\n\nfunction usePadDrawing(box: SignatureBox, disabled: boolean, dispatch: (action: SignatureAction) => void) {\n  const svg = useRef<SVGSVGElement>(null)\n  const inProgress = useRef<SignatureStroke | null>(null)\n  const [drawing, setDrawing] = useState<SignatureStroke | null>(null)\n  const pointFrom = (event: { clientX: number; clientY: number }) => {\n    const rect = svg.current?.getBoundingClientRect()\n    return rect ? toBoxPoint(event.clientX, event.clientY, rect, box) : { x: 0, y: 0 }\n  }\n  const finish = (keep: boolean) => {\n    const stroke = inProgress.current\n    inProgress.current = null\n    setDrawing(null)\n    if (keep && stroke) dispatch({ type: \"add\", stroke })\n  }\n  const surface = {\n    onPointerDown: (event: React.PointerEvent<HTMLElement>) => {\n      if (disabled || event.button !== 0 || !event.isPrimary) return\n      // Capture keeps the stroke alive when the pen leaves the pad and comes back.\n      event.currentTarget.setPointerCapture(event.pointerId)\n      inProgress.current = [pointFrom(event)]\n      setDrawing(inProgress.current)\n    },\n    onPointerMove: (event: React.PointerEvent<HTMLElement>) => {\n      if (!inProgress.current) return\n      // A fast hand outruns the frame rate; these are the samples the browser merged in between.\n      const native = event.nativeEvent\n      const samples = native.getCoalescedEvents?.() ?? []\n      const points = (samples.length > 0 ? samples : [native]).map(pointFrom)\n      inProgress.current = points.reduce<SignatureStroke>((stroke, point) => addPoint(stroke, point), inProgress.current)\n      setDrawing(inProgress.current)\n    },\n    onPointerUp: () => finish(true),\n    onPointerCancel: () => finish(false),\n  }\n  return { svg, drawing, surface }\n}\n\nfunction useSignature(defaultStrokes: readonly SignatureStroke[] | undefined, onChange: ((value: SignatureValue) => void) | undefined) {\n  const [history, setHistory] = useState(() => ({ strokes: defaultStrokes ?? [], past: [] as readonly (readonly SignatureStroke[])[] }))\n  const [typing, setTyping] = useState(false)\n  const [typed, setTyped] = useState(\"\")\n  /** The name counts only while typing is the chosen way to sign. */\n  const name = typing ? typed.trim() : \"\"\n  const report = (strokes: readonly SignatureStroke[], nextName: string) => {\n    const trimmed = nextName.trim()\n    onChange?.({ strokes, path: trimmed ? \"\" : strokesToPath(strokes), typed: trimmed, empty: trimmed === \"\" && strokes.length === 0 })\n  }\n  const dispatch = (action: SignatureAction) => {\n    const next = signatureReducer(history, action)\n    setHistory(next)\n    report(next.strokes, name)\n  }\n  return {\n    strokes: history.strokes,\n    canUndo: history.past.length > 0,\n    typing,\n    typed,\n    name,\n    empty: history.strokes.length === 0 && name === \"\",\n    dispatch,\n    undo: () => dispatch({ type: \"undo\" }),\n    clear: () => {\n      if (!typing) {\n        dispatch({ type: \"clear\" })\n        return\n      }\n      setTyped(\"\")\n      report(history.strokes, \"\")\n    },\n    toggleMode: () => {\n      setTyping(!typing)\n      report(history.strokes, typing ? \"\" : typed)\n    },\n    typeName: (next: string) => {\n      setTyped(next)\n      report(history.strokes, next)\n    },\n  }\n}\n\nexport { usePadDrawing, useSignature, type SignatureValue }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "forms"
  ],
  "type": "registry:ui"
}