{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink-stamp",
  "title": "Ink stamp",
  "description": "A short word or two inside a plotted stamp: a circle with text round its rim, a rectangle ruled twice, or a scalloped seal, set a little askew.",
  "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-stamp.tsx",
      "content": "'use client';\n\n/**\n * ink-stamp — a short word or two set inside a stamp a pen plots round it: a\n * round stamp with a line of text running round its rim, a rectangle ruled\n * twice, or a seal with a scalloped edge. Set a little askew, as a stamp\n * lands.\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 whole stamp is in the one `accent` colour, as a\n * stamp is in one ink.\n *\n * The words, and the rim's text on its circle, are in the server HTML; the\n * rings and the frame are made in the browser. Reduced motion shows them\n * drawn.\n */\n\nimport { useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react';\nimport 'svg-scroll-draw/no-flash.css';\nimport { seedOf, sketchRect, stampRings, type Stroke } from '@/lib/plotter';\nimport { useInk, useSize, type InkTrigger } from '@/lib/ink';\n\nexport type InkStampVariant = 'circle' | 'rectangle' | 'seal';\n\nexport interface InkStampProps {\n  /** The words in the middle: keep them short. */\n  children: ReactNode;\n  variant?: InkStampVariant;\n  /** A line of text round the rim, for `circle` and `seal`. It is spaced to go once round. */\n  rim?: string;\n  /** The width and height of `circle` and `seal`, in px. */\n  size?: number;\n  /** How far the stamp is turned, in degrees. */\n  rotate?: number;\n  /** The stamp's ink. */\n  accent?: string;\n  strokeWidth?: number;\n  seed?: number;\n  /** `scroll`: drawn as it rises, done at mid-screen. `view`: played once as it comes into view. */\n  trigger?: InkTrigger;\n  /** With `view`, the drawing's length in ms. */\n  duration?: number;\n  className?: string;\n}\n\nfunction Strokes({ strokes, w, h, view, accent, strokeWidth, trigger, duration, spread }: { strokes: Stroke[]; w: number; h: number; view?: string; accent: string; strokeWidth: number; trigger: InkTrigger; duration: number; spread: number }) {\n  const ref = useRef<SVGSVGElement>(null);\n  useInk(ref, { paths: strokes.length, spread, trigger, duration, version: strokes });\n  return (\n    <svg ref={ref} data-scroll-draw-pending=\"\" data-ink={trigger} aria-hidden width={w} height={h} viewBox={view ?? `0 0 ${w} ${h}`} className=\"pointer-events-none absolute inset-0 overflow-visible\" fill=\"none\" stroke={accent} strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      {strokes.map((s, i) => <path key={i} d={s.d} />)}\n    </svg>\n  );\n}\n\nexport function InkStamp({\n  children,\n  variant = 'circle',\n  rim,\n  size = 148,\n  rotate = -8,\n  accent = '#e0482a',\n  strokeWidth = 1.4,\n  seed,\n  trigger = 'scroll',\n  duration = 1400,\n  className = '',\n}: InkStampProps) {\n  const id = useId();\n  const s = seed ?? seedOf(`${variant}${rim ?? ''}`);\n  const pen = { accent, trigger, duration };\n  const box = useRef<HTMLSpanElement>(null);\n  const measured = useSize(box);\n  const [rings, setRings] = useState<Stroke[] | null>(null);\n  useEffect(() => {\n    if (variant !== 'rectangle') setRings(stampRings({ size: 100, seed: s, kind: variant }));\n  }, [variant, s]);\n\n  // Ruled twice round the edge, then once more, finer, inside.\n  const frame = useMemo(\n    () => (variant === 'rectangle' && measured ? [...sketchRect({ w: measured.w, h: measured.h, seed: s, wobble: 1, r: 3 }), shift(sketchRect({ w: measured.w - 10, h: measured.h - 10, seed: s + 3, wobble: 0.7, r: 2 })[0], 5)] : null),\n    [variant, measured, s],\n  );\n\n  if (variant === 'rectangle') {\n    const strokes = frame;\n    return (\n      <span ref={box} className={`relative inline-flex items-center justify-center px-7 py-4 ${className}`} style={{ rotate: `${rotate}deg`, color: accent }}>\n        <span className=\"font-mono text-[15px] font-semibold uppercase leading-none tracking-[0.28em]\">{children}</span>\n        {measured && strokes && <RectFrame key={`${measured.w}x${measured.h}`} strokes={strokes} w={measured.w} h={measured.h} {...pen} strokeWidth={strokeWidth} />}\n      </span>\n    );\n  }\n\n  // The rim's text sits in the band between the outer rings and the inner one.\n  const r = size * (variant === 'seal' ? 0.36 : 0.38);\n  const rimFont = Math.max(7, size * (variant === 'seal' ? 0.056 : 0.066));\n  // The words fit inside the inner ring: a monospaced letter here is about 0.8 em wide with its tracking.\n  const longest = typeof children === 'string' ? Math.max(...children.split(/\\s+/).map((w) => w.length)) : 6;\n  const wordFont = Math.max(9, Math.min(size * 0.1, (size * 0.48) / (longest * 0.8)));\n  const circle = `M${size / 2 - r} ${size / 2}a${r} ${r} 0 1 1 ${r * 2} 0a${r} ${r} 0 1 1 ${-r * 2} 0`;\n  return (\n    <span className={`relative inline-grid shrink-0 place-items-center ${className}`} style={{ width: size, height: size, rotate: `${rotate}deg`, color: accent }}>\n      {rim && (\n        <svg aria-hidden width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"absolute inset-0 overflow-visible\">\n          <defs>\n            <path id={`${id}-rim`} d={circle} />\n          </defs>\n          <text fill=\"currentColor\" className=\"font-mono uppercase\" style={{ fontSize: rimFont, letterSpacing: '0.12em' }} dominantBaseline=\"central\">\n            <textPath href={`#${id}-rim`} textLength={Math.PI * 2 * r - size * 0.04} lengthAdjust=\"spacing\">{rim}</textPath>\n          </text>\n        </svg>\n      )}\n      <span className=\"max-w-[60%] text-center font-mono font-semibold uppercase leading-tight tracking-[0.2em]\" style={{ fontSize: wordFont }}>\n        {children}\n        {rim && <span className=\"sr-only\"> — {rim}</span>}\n      </span>\n      {rings && <Strokes strokes={rings} w={size} h={size} view=\"0 0 100 100\" spread={0.6} {...pen} strokeWidth={strokeWidth * (100 / size)} />}\n    </span>\n  );\n}\n\n/** A stroke moved `by` px right and down (its numbers are x y pairs). */\nconst shift = (k: Stroke, by: number): Stroke => ({ ...k, d: k.d.replace(/(-?[\\d.]+) (-?[\\d.]+)/g, (_, x, y) => `${(+x + by).toFixed(1)} ${(+y + by).toFixed(1)}`) });\n\nfunction RectFrame(props: { strokes: Stroke[]; w: number; h: number; accent: string; strokeWidth: number; trigger: InkTrigger; duration: number }) {\n  return <Strokes {...props} spread={0.6} />;\n}\n",
      "type": "registry:ui",
      "target": "components/scrollfx/ink-stamp.tsx"
    }
  ],
  "type": "registry:ui"
}