{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-signature-pad",
  "type": "registry:component",
  "title": "Signature Pad",
  "description": "A signature pad whose line thins with speed and thickens when you slow down, drawn as smooth curves at full screen resolution. It has ink colors, undo, a typed alternative and a signed stamp with the time.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "forms",
    "signature",
    "canvas",
    "draw",
    "contract",
    "e-sign",
    "input"
  ],
  "docs": "https://hyperblur.dev/effects/input-signature-pad",
  "files": [
    {
      "path": "registry/hyperblur/input-signature-pad.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/input-signature-pad.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type InputSignaturePoint = { x: number; y: number; w?: number };\n\nexport interface InputSignaturePadProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  label?: string;\n  signer?: string;\n  height?: number;\n  inks?: string[];\n  minWidth?: number;\n  maxWidth?: number;\n  defaultStrokes?: InputSignaturePoint[][];\n  onChange?: (dataUrl: string | null) => void;\n  onConfirm?: (result: { dataUrl: string | null; typed: string | null; signedAt: string }) => void;\n  confirmLabel?: string;\n  accent?: string;\n}\n\nconst css = `\n.hb-xg12 {\n  --hb-xg12-c: #2f7bff;\n  --hb-xg12-h: 160px;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xg12 *, .hb-xg12 *::before, .hb-xg12 *::after { box-sizing: border-box; }\n.hb-xg12-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 7px; }\n.hb-xg12-label { font-size: 12.5px; font-weight: 500; color: #a1a1a1; }\n.hb-xg12-mode {\n  margin: 0;\n  padding: 0;\n  border: 0;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 11.5px;\n  cursor: pointer;\n  box-shadow: inset 0 -1px 0 #3a3a3a;\n}\n.hb-xg12-mode:hover { color: #ededed; }\n.hb-xg12-mode:focus-visible { outline: 2px solid var(--hb-xg12-c); outline-offset: 2px; }\n.hb-xg12-pad {\n  position: relative;\n  height: var(--hb-xg12-h);\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background:\n    radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.03), transparent 60%),\n    repeating-linear-gradient(0deg, transparent 0 23px, rgba(255, 255, 255, 0.018) 23px 24px),\n    linear-gradient(180deg, #131313, #0d0d0d);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.045), inset 0 -20px 40px -30px rgba(0, 0, 0, 0.8), 0 1px 2px rgba(0, 0, 0, 0.5);\n  overflow: hidden;\n  transition: border-color 0.25s ease, box-shadow 0.25s ease;\n}\n.hb-xg12[data-active=\"true\"] .hb-xg12-pad { border-color: #3a3a3a; }\n.hb-xg12-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; outline: 0; }\n.hb-xg12-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--hb-xg12-c); border-radius: 13px; }\n.hb-xg12-base {\n  position: absolute;\n  left: 18px;\n  right: 18px;\n  bottom: 30%;\n  display: flex;\n  align-items: flex-end;\n  gap: 8px;\n  pointer-events: none;\n}\n.hb-xg12-base span { font-size: 15px; line-height: 1; color: #4a4a4a; transform: translateY(5px); }\n.hb-xg12-base i { flex: 1; height: 1px; background: repeating-linear-gradient(90deg, #333 0 6px, transparent 6px 10px); }\n.hb-xg12-ph {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 30%;\n  text-align: center;\n  font-size: 12.5px;\n  color: #5a5a5a;\n  pointer-events: none;\n  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-xg12[data-empty=\"false\"] .hb-xg12-ph { opacity: 0; transform: translateY(-6px); }\n.hb-xg12-typed {\n  position: absolute;\n  left: 34px;\n  right: 18px;\n  bottom: calc(30% + 2px);\n  margin: 0;\n  padding: 0;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: var(--hb-xg12-ink);\n  font-family: var(--font-grotesk), var(--font-sans), sans-serif;\n  font-size: clamp(22px, 9cqi, 34px);\n  font-weight: 500;\n  letter-spacing: -0.02em;\n  line-height: 1.1;\n  caret-color: var(--hb-xg12-c);\n}\n.hb-xg12-typed::placeholder { color: #3a3a3a; }\n.hb-xg12-pad { container-type: inline-size; }\n.hb-xg12-stamp {\n  position: absolute;\n  right: 12px;\n  top: 12px;\n  display: flex;\n  align-items: center;\n  gap: 7px;\n  padding: 5px 10px 5px 6px;\n  border: 1px solid rgba(63, 191, 127, 0.35);\n  border-radius: 999px;\n  background: rgba(16, 40, 28, 0.85);\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n  font-size: 11.5px;\n  color: #8fe3b4;\n  animation: hb-xg12-stamp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xg12-stamp svg { width: 16px; height: 16px; }\n.hb-xg12-stamp path { stroke-dasharray: 16; stroke-dashoffset: 16; animation: hb-xg12-draw 0.45s cubic-bezier(0.65, 0, 0.35, 1) 0.2s forwards; }\n.hb-xg12[data-done=\"true\"] .hb-xg12-canvas, .hb-xg12[data-done=\"true\"] .hb-xg12-typed { pointer-events: none; }\n.hb-xg12[data-done=\"true\"] .hb-xg12-base i { background: rgba(63, 191, 127, 0.4); }\n.hb-xg12-bar { display: flex; align-items: center; gap: 8px; margin-top: 9px; }\n.hb-xg12-inks { display: flex; gap: 5px; padding: 3px; border: 1px solid #222; border-radius: 999px; background: #0f0f0f; }\n.hb-xg12-ink {\n  position: relative;\n  width: 20px;\n  height: 20px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: var(--hb-xg12-sw);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), inset 0 -3px 5px rgba(0, 0, 0, 0.3);\n  cursor: pointer;\n  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xg12-ink[aria-pressed=\"true\"] { transform: scale(0.82); box-shadow: 0 0 0 2px #0f0f0f, 0 0 0 3.5px var(--hb-xg12-sw); }\n.hb-xg12-ink:focus-visible { outline: 2px solid var(--hb-xg12-c); outline-offset: 3px; }\n.hb-xg12-tool {\n  display: grid;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  margin: 0;\n  padding: 0;\n  border: 1px solid #262626;\n  border-radius: 9px;\n  background: linear-gradient(180deg, #1a1a1a, #131313);\n  color: #a1a1a1;\n  cursor: pointer;\n  transition: color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;\n}\n.hb-xg12-tool:hover:not(:disabled) { color: #ededed; border-color: #3a3a3a; }\n.hb-xg12-tool:disabled { opacity: 0.35; cursor: not-allowed; }\n.hb-xg12-tool:focus-visible { outline: 2px solid var(--hb-xg12-c); outline-offset: 2px; }\n.hb-xg12-tool svg { width: 14px; height: 14px; }\n.hb-xg12-sp { flex: 1; }\n.hb-xg12-go {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  height: 32px;\n  margin: 0;\n  padding: 0 14px;\n  border: 0;\n  border-radius: 999px;\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xg12-c) 80%, #fff), var(--hb-xg12-c));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 8px 18px -10px var(--hb-xg12-c);\n  color: #fff;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 600;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;\n}\n.hb-xg12-go:active:not(:disabled) { transform: scale(0.96); }\n.hb-xg12-go:disabled { opacity: 0.35; cursor: not-allowed; }\n.hb-xg12-go:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-xg12[data-done=\"true\"] .hb-xg12-go { background: #1a1a1a; box-shadow: inset 0 0 0 1px #2e2e2e; color: #ededed; }\n@keyframes hb-xg12-stamp { from { opacity: 0; transform: scale(1.4) rotate(-6deg); } }\n@keyframes hb-xg12-draw { to { stroke-dashoffset: 0; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xg12 *, .hb-xg12 path { transition: none !important; animation: none !important; }\n  .hb-xg12-stamp path { stroke-dashoffset: 0; }\n}\n`;\n\ntype P = { x: number; y: number; w: number };\ntype Stroke = { ink: string; pts: P[] };\n\nfunction withWidths(pts: InputSignaturePoint[], minW: number, maxW: number): P[] {\n  let prev = (minW + maxW) / 2;\n  return pts.map((p, i) => {\n    if (p.w !== undefined) return { x: p.x, y: p.y, w: p.w };\n    const q = pts[i - 1] ?? p;\n    const d = Math.hypot(p.x - q.x, p.y - q.y) * 400;\n    const target = Math.max(minW, maxW - d * 0.18);\n    prev = prev + (target - prev) * 0.4;\n    return { x: p.x, y: p.y, w: prev };\n  });\n}\n\nexport function InputSignaturePad({\n  label = \"Signature\",\n  signer = \"Jordan Ellis\",\n  height = 160,\n  inks = [\"#ededed\", \"#7fb3ff\", \"#f5c542\"],\n  minWidth = 0.9,\n  maxWidth = 3.4,\n  defaultStrokes,\n  onChange,\n  onConfirm,\n  confirmLabel = \"Adopt and sign\",\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: InputSignaturePadProps) {\n  const id = React.useId();\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const strokes = React.useRef<Stroke[]>([]);\n  const seeded = React.useRef(false);\n  const live = React.useRef<{ last: number; w: number } | null>(null);\n  const [ink, setInk] = React.useState(inks[0]);\n  const [count, setCount] = React.useState(defaultStrokes?.length ?? 0);\n  const [active, setActive] = React.useState(false);\n  const [typedMode, setTypedMode] = React.useState(false);\n  const [typed, setTyped] = React.useState(\"\");\n  const [signedAt, setSignedAt] = React.useState<string | null>(null);\n\n  const paint = React.useCallback(() => {\n    const c = canvasRef.current;\n    if (!c) return;\n    const ctx = c.getContext(\"2d\");\n    if (!ctx) return;\n    const W = c.clientWidth;\n    const H = c.clientHeight;\n    const dpr = window.devicePixelRatio || 1;\n    if (c.width !== Math.round(W * dpr) || c.height !== Math.round(H * dpr)) {\n      c.width = Math.round(W * dpr);\n      c.height = Math.round(H * dpr);\n    }\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    ctx.clearRect(0, 0, W, H);\n    ctx.lineCap = \"round\";\n    ctx.lineJoin = \"round\";\n    for (const s of strokes.current) {\n      ctx.strokeStyle = s.ink;\n      ctx.fillStyle = s.ink;\n      const pts = s.pts;\n      if (pts.length === 1) {\n        ctx.beginPath();\n        ctx.arc(pts[0].x * W, pts[0].y * H, pts[0].w / 2, 0, Math.PI * 2);\n        ctx.fill();\n        continue;\n      }\n      for (let i = 1; i < pts.length; i++) {\n        const a = pts[i - 1];\n        const b = pts[i];\n        const p0 = i === 1 ? a : { x: (pts[i - 2].x + a.x) / 2, y: (pts[i - 2].y + a.y) / 2 };\n        const p1 = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };\n        ctx.beginPath();\n        ctx.lineWidth = (a.w + b.w) / 2;\n        ctx.moveTo(p0.x * W, p0.y * H);\n        ctx.quadraticCurveTo(a.x * W, a.y * H, p1.x * W, p1.y * H);\n        ctx.stroke();\n      }\n    }\n  }, []);\n\n  React.useEffect(() => {\n    if (!seeded.current && defaultStrokes) {\n      seeded.current = true;\n      strokes.current = defaultStrokes.map((s) => ({ ink: inks[0], pts: withWidths(s, minWidth, maxWidth) }));\n    }\n    paint();\n    const c = canvasRef.current;\n    if (!c) return;\n    const ro = new ResizeObserver(() => paint());\n    ro.observe(c);\n    return () => ro.disconnect();\n  }, [paint, defaultStrokes, inks, minWidth, maxWidth, typedMode]);\n\n  function emit() {\n    const c = canvasRef.current;\n    onChange?.(strokes.current.length && c ? c.toDataURL(\"image/png\") : null);\n  }\n\n  function point(e: React.PointerEvent<HTMLCanvasElement> | PointerEvent) {\n    const c = canvasRef.current!;\n    const r = c.getBoundingClientRect();\n    return { x: (e.clientX - r.left) / r.width, y: (e.clientY - r.top) / r.height, t: e.timeStamp };\n  }\n\n  function onDown(e: React.PointerEvent<HTMLCanvasElement>) {\n    if (e.button !== 0 || signedAt) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    const p = point(e);\n    const w = (minWidth + maxWidth) / 2;\n    strokes.current.push({ ink, pts: [{ x: p.x, y: p.y, w }] });\n    live.current = { last: p.t, w };\n    setActive(true);\n    setCount(strokes.current.length);\n    paint();\n  }\n\n  function onMove(e: React.PointerEvent<HTMLCanvasElement>) {\n    const l = live.current;\n    if (!l) return;\n    const c = canvasRef.current!;\n    const s = strokes.current[strokes.current.length - 1];\n    const events = typeof e.nativeEvent.getCoalescedEvents === \"function\" ? e.nativeEvent.getCoalescedEvents() : [e.nativeEvent];\n    for (const ev of events.length ? events : [e.nativeEvent]) {\n      const p = point(ev);\n      const prev = s.pts[s.pts.length - 1];\n      const dist = Math.hypot((p.x - prev.x) * c.clientWidth, (p.y - prev.y) * c.clientHeight);\n      if (dist < 1.2) continue;\n      const dt = Math.max(1, p.t - l.last);\n      const v = dist / dt;\n      const target = Math.max(minWidth, Math.min(maxWidth, maxWidth - v * 1.6));\n      l.w = l.w + (target - l.w) * 0.32;\n      l.last = p.t;\n      s.pts.push({ x: p.x, y: p.y, w: l.w });\n    }\n    paint();\n  }\n\n  function onUp() {\n    if (!live.current) return;\n    live.current = null;\n    setActive(false);\n    emit();\n  }\n\n  function undo() {\n    strokes.current.pop();\n    setCount(strokes.current.length);\n    paint();\n    emit();\n  }\n\n  function clear() {\n    strokes.current = [];\n    setCount(0);\n    setTyped(\"\");\n    paint();\n    emit();\n  }\n\n  function confirm() {\n    if (signedAt) {\n      setSignedAt(null);\n      return;\n    }\n    const stamp = new Intl.DateTimeFormat(\"en-US\", { month: \"short\", day: \"numeric\", hour: \"numeric\", minute: \"2-digit\" }).format();\n    setSignedAt(stamp);\n    const c = canvasRef.current;\n    onConfirm?.({\n      dataUrl: !typedMode && strokes.current.length && c ? c.toDataURL(\"image/png\") : null,\n      typed: typedMode ? typed.trim() : null,\n      signedAt: stamp,\n    });\n  }\n\n  const empty = typedMode ? typed.trim() === \"\" : count === 0;\n  const vars = { \"--hb-xg12-c\": accent, \"--hb-xg12-h\": `${height}px`, \"--hb-xg12-ink\": ink, ...style } as React.CSSProperties;\n\n  return (\n    <div\n      className={`hb-xg12 ${className}`}\n      style={vars}\n      data-empty={empty}\n      data-active={active}\n      data-done={!!signedAt}\n      role=\"group\"\n      aria-labelledby={`${id}-l`}\n      {...rest}\n    >\n      <style href=\"hb-input-signature-pad\" precedence=\"default\">{css}</style>\n      <div className=\"hb-xg12-top\">\n        <span className=\"hb-xg12-label\" id={`${id}-l`}>\n          {label}\n        </span>\n        <button type=\"button\" className=\"hb-xg12-mode\" onClick={() => setTypedMode((t) => !t)} disabled={!!signedAt}>\n          {typedMode ? \"Draw instead\" : \"Type instead\"}\n        </button>\n      </div>\n      <div className=\"hb-xg12-pad\">\n        <div className=\"hb-xg12-base\" aria-hidden=\"true\">\n          <span>×</span>\n          <i />\n        </div>\n        {typedMode ? (\n          <input\n            className=\"hb-xg12-typed\"\n            value={typed}\n            placeholder={signer}\n            aria-label=\"Type your full name\"\n            onChange={(e) => setTyped(e.target.value)}\n            readOnly={!!signedAt}\n          />\n        ) : (\n          <>\n            <span className=\"hb-xg12-ph\" aria-hidden=\"true\">\n              Sign with your mouse, finger or stylus\n            </span>\n            <canvas\n              ref={canvasRef}\n              className=\"hb-xg12-canvas\"\n              role=\"img\"\n              aria-label={count ? `Signature with ${count} stroke${count === 1 ? \"\" : \"s\"}` : \"Empty signature area\"}\n              onPointerDown={onDown}\n              onPointerMove={onMove}\n              onPointerUp={onUp}\n              onPointerCancel={onUp}\n            />\n          </>\n        )}\n        {signedAt && (\n          <span className=\"hb-xg12-stamp\" role=\"status\">\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" aria-hidden=\"true\">\n              <path d=\"M3.5 8.4l3 3 6-6.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n            Signed by {typedMode && typed.trim() ? typed.trim() : signer} · {signedAt}\n          </span>\n        )}\n      </div>\n      <div className=\"hb-xg12-bar\">\n        <div className=\"hb-xg12-inks\" role=\"group\" aria-label=\"Ink color\">\n          {inks.map((c) => (\n            <button\n              key={c}\n              type=\"button\"\n              className=\"hb-xg12-ink\"\n              style={{ \"--hb-xg12-sw\": c } as React.CSSProperties}\n              aria-pressed={ink === c}\n              aria-label={`Ink ${c}`}\n              disabled={!!signedAt}\n              onClick={() => setInk(c)}\n            />\n          ))}\n        </div>\n        <button type=\"button\" className=\"hb-xg12-tool\" aria-label=\"Undo last stroke\" onClick={undo} disabled={typedMode || count === 0 || !!signedAt}>\n          <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M4.5 3L2 5.5 4.5 8\" />\n            <path d=\"M2 5.5h6.2a3.3 3.3 0 0 1 0 6.6H6\" />\n          </svg>\n        </button>\n        <button type=\"button\" className=\"hb-xg12-tool\" aria-label=\"Clear signature\" onClick={clear} disabled={empty || !!signedAt}>\n          <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M2.5 4h9M5.5 4V2.6h3V4M3.6 4l.6 7.6a1 1 0 0 0 1 .9h3.6a1 1 0 0 0 1-.9l.6-7.6\" />\n          </svg>\n        </button>\n        <span className=\"hb-xg12-sp\" />\n        <button type=\"button\" className=\"hb-xg12-go\" onClick={confirm} disabled={empty && !signedAt}>\n          {signedAt ? \"Edit signature\" : confirmLabel}\n        </button>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}