{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink-signature",
  "title": "Ink signature",
  "description": "A name written stroke by stroke at one steady speed in Hershey's single-stroke script, underlined with a flourish; or your own signature as SVG paths.",
  "dependencies": [
    "svg-scroll-draw@^2.29.0"
  ],
  "registryDependencies": [
    "https://scrollfx-ui.vercel.app/r/plotter.json",
    "https://scrollfx-ui.vercel.app/r/ink.json"
  ],
  "files": [
    {
      "path": "registry/ui/ink-signature.tsx",
      "content": "'use client';\n\n/**\n * ink-signature — a name written out by a pen, stroke by stroke, in writing\n * order and at one steady speed, then underlined with a flourish in the\n * accent pen. The name is set in Hershey's script, a single-stroke\n * handwriting font, so every line is drawn once, as a hand draws it. Or pass\n * your own signature as SVG paths.\n *\n * Built on svg-scroll-draw (MIT): https://github.com/DhruvilChauahan0210/scrollfx\n * Needs: react, svg-scroll-draw, lib/plotter and lib/ink (installed with it).\n * Styling: Tailwind CSS. The ink is `currentColor` unless you pass `color`.\n *\n * The name is in the server HTML (as the drawing's accessible name) and the\n * drawing's box is laid out there too, so nothing moves when it is drawn; the\n * strokes are made in the browser. Reduced motion shows the name written.\n */\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport 'svg-scroll-draw/no-flash.css';\nimport { paced, random, type Line, type Point, type Stroke } from '@/lib/plotter';\nimport { script, useInk, type InkTrigger } from '@/lib/ink';\n\nexport interface InkSignatureProps {\n  /** The name to write. Letters outside ASCII lose their accents; others are left out. */\n  name?: string;\n  /** The size of the writing: px to the em. */\n  size?: number;\n  /** How far the writing leans: x moved right per unit up. */\n  slant?: number;\n  /** Underline the name with a flourish in the accent pen. */\n  flourish?: boolean;\n  /**\n   * Your own signature instead: SVG path data, one string per stroke, in the\n   * order they were written, inside `viewBox`. Each stroke takes one beat.\n   */\n  paths?: string[];\n  /** The box `paths` are drawn in, as an SVG viewBox (\"0 0 w h\"). */\n  viewBox?: string;\n  /** The ink's colour. */\n  color?: string;\n  /** The flourish's colour. */\n  accent?: string;\n  strokeWidth?: number;\n  /** Shapes the flourish. */\n  seed?: number;\n  /** `scroll`: written as it rises, done at mid-screen. `view`: written once as it comes into view. */\n  trigger?: InkTrigger;\n  /** With `view`, how long the writing takes, in ms. */\n  duration?: number;\n  className?: string;\n}\n\n/** A swash under the writing: in from below the first letters, a long shallow curve, and a lift at the end. */\nfunction swash(w: number, baseline: number, size: number, seed: number): Point[] {\n  const rand = random(seed);\n  const x0 = w * (0.04 + rand() * 0.06), x1 = w * (0.97 + rand() * 0.02);\n  const y = baseline + size * 0.16;\n  const sag = size * (0.07 + rand() * 0.05);\n  const pts: Point[] = [];\n  const n = Math.max(30, Math.round((x1 - x0) / 3));\n  for (let i = 0; i <= n; i++) {\n    const t = i / n;\n    // Down into the stroke, a long sag, then up and away at the end.\n    pts.push([x0 + (x1 - x0) * t, y + sag * Math.sin(Math.PI * t * 0.92) - size * 0.12 * t ** 6 + (1 - t) ** 8 * -size * 0.06]);\n  }\n  return pts;\n}\n\nexport function InkSignature({\n  name = 'Ada Marlow',\n  size = 56,\n  slant = 0.2,\n  flourish = true,\n  paths,\n  viewBox,\n  color = 'currentColor',\n  accent = '#e0482a',\n  strokeWidth = 1.7,\n  seed = 1,\n  trigger = 'scroll',\n  duration = 2600,\n  className = '',\n}: InkSignatureProps) {\n  const ref = useRef<SVGSVGElement>(null);\n  // Laid out on the server as well, so the box is the right size from the first paint.\n  const laid = useMemo(() => script(name, { size, slant, pad: Math.ceil(strokeWidth * 2) }), [name, size, slant, strokeWidth]);\n  const extra = flourish && !paths ? Math.round(size * 0.32) : 0;\n  const box = paths ? viewBox ?? '0 0 300 120' : `0 0 ${laid.w} ${laid.h + extra}`;\n  const [, , bw, bh] = box.split(/[\\s,]+/).map(Number);\n\n  const [strokes, setStrokes] = useState<Stroke[] | null>(null);\n  useEffect(() => {\n    if (paths) return setStrokes(paths.map((d) => ({ d, pen: 0 })));\n    // Even pieces, one after another: the pen writes at one speed.\n    const lines: Line[] = laid.lines.map((pts) => ({ pts, pen: 0 }));\n    if (flourish) lines.push({ pts: swash(laid.w, laid.baseline, size, seed), pen: 1 });\n    setStrokes(paced(lines, Math.max(4, size / 9)));\n  }, [paths, laid, flourish, size, seed]);\n\n  const n = strokes?.length ?? 0;\n  useInk(ref, { paths: n, spread: Math.max(0, n - 1), trigger, duration, version: strokes });\n\n  return (\n    <span role=\"img\" aria-label={paths ? `Signature: ${name}` : name} className={`inline-block align-middle ${className}`}>\n      <svg\n        ref={ref}\n        key={strokes ? 'drawn' : 'empty'}\n        data-scroll-draw-pending=\"\"\n        data-ink={trigger}\n        aria-hidden\n        width={bw}\n        height={bh}\n        viewBox={box}\n        className=\"block h-auto max-w-full overflow-visible\"\n        fill=\"none\"\n        stroke={color}\n        strokeWidth={strokeWidth}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      >\n        {strokes?.map((s, i) => <path key={i} d={s.d} stroke={s.pen ? accent : undefined} />)}\n      </svg>\n    </span>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/scrollfx/ink-signature.tsx"
    }
  ],
  "type": "registry:ui"
}