{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink-progress",
  "title": "Ink progress",
  "description": "A value plotted as it is reached: a bar hatched in to the value, a ring with an accent band, or a ticked gauge with a needle. role=\"progressbar\".",
  "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-progress.tsx",
      "content": "'use client';\n\n/**\n * ink-progress — a value plotted as the reader reaches it: a bar whose fill a\n * pen hatches in from the left and stops at the value, a ring with a band in\n * the accent pen out to it, or an instrument gauge ticked clockwise with a\n * needle on it.\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 with shadcn/ui tokens; figures in `font-serif`.\n *\n * The label and the value are in the server HTML (role=\"progressbar\", with\n * aria-valuenow); the drawing is made in the browser and goes as far as the\n * value. Reduced motion shows it drawn.\n */\n\nimport { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';\nimport { ScrollCounter } from 'svg-scroll-draw/react';\nimport 'svg-scroll-draw/no-flash.css';\nimport { dial, gauge, hatch, scrollWindow, seedOf, sketchRect, type Stroke } from '@/lib/plotter';\nimport { useInk, useSize, type InkTrigger } from '@/lib/ink';\n\nexport type InkProgressVariant = 'bar' | 'ring' | 'gauge';\n\nexport interface InkProgressProps {\n  value: number;\n  max?: number;\n  variant?: InkProgressVariant;\n  /** What the value is of, shown with it and read out with it. */\n  label?: string;\n  /** Show the value as a figure. */\n  showValue?: boolean;\n  /** Show the figure as a percentage of max (the default), or as the value itself. */\n  display?: 'percent' | 'value';\n  /** Set before and after the figure; after a percentage, `%` unless you pass one. */\n  prefix?: string;\n  suffix?: string;\n  decimals?: number;\n  /** The ring's or gauge's width and height, in px. */\n  size?: number;\n  /** The ink's colour. */\n  color?: string;\n  /** The accent pen's colour: the fill, the band. */\n  accent?: string;\n  strokeWidth?: number;\n  /** Shapes the strokes; by default taken from the label. */\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\n/** The figure: counted up with the drawing on scroll, plain otherwise. Its final number is in the server HTML either way. */\ntype FigureProps = Pick<InkProgressProps, 'display' | 'prefix' | 'suffix' | 'decimals'> & { value: number; max: number; trigger: InkTrigger; className: string; style?: CSSProperties };\n\nfunction Figure({ value, max, display = 'percent', prefix = '', suffix, decimals = 0, trigger, className, style }: FigureProps) {\n  const f = display === 'percent' ? { value: (value / max) * 100, prefix, suffix: suffix ?? '%', decimals } : { value, prefix, suffix: suffix ?? '', decimals };\n  return (\n    <span className={`tabular-nums ${className}`} style={style}>\n      {f.prefix}\n      {trigger === 'scroll' ? <ScrollCounter to={f.value} decimals={f.decimals ?? 0} trigger={scrollWindow()} /> : f.value.toFixed(f.decimals ?? 0)}\n      {f.suffix}\n    </span>\n  );\n}\n\nfunction Drawing({ strokes, w, h, view, spread, color, accent, strokeWidth, trigger, duration, className = '', style }: { strokes: Stroke[]; w: number; h: number; view?: string; spread: number; color: string; accent: string; strokeWidth: number; trigger: InkTrigger; duration: number; className?: string; style?: CSSProperties }) {\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={`block overflow-visible ${className}`} style={style} fill=\"none\" stroke={color} strokeWidth={strokeWidth} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      {strokes.map((s, i) => <path key={i} d={s.d} stroke={s.pen ? accent : undefined} strokeWidth={s.pen ? strokeWidth * 1.15 : undefined} />)}\n    </svg>\n  );\n}\n\nconst BAR_H = 18;\n\n/** The bar's strokes: its outline, a scale under it, the hatching out to the value, and a mark at the value. */\nfunction barStrokes(w: number, share: number, seed: number): Stroke[] {\n  const out: Stroke[] = [sketchRect({ w, h: BAR_H, seed, wobble: 0.7, r: 2 })[0]];\n  for (let i = 0; i <= 10; i++) {\n    const x = 1 + ((w - 2) * i) / 10;\n    out.push({ d: `M${x.toFixed(1)} ${BAR_H + 5}L${x.toFixed(1)} ${BAR_H + (i % 5 === 0 ? 11 : 8)}`, pen: 0 });\n  }\n  const fill = Math.max(0, (w - 6) * share);\n  if (fill > 1) {\n    // hatch() draws from the box's corner; each of its strokes is `Mx yLx y`, moved in 3 px here.\n    const shift = (d: string) => d.replace(/(-?[\\d.]+) (-?[\\d.]+)/g, (_, x, y) => `${(+x + 3).toFixed(1)} ${(+y + 3).toFixed(1)}`);\n    for (const h of hatch({ w: fill, h: BAR_H - 6, gap: 3.4, angle: 58 })) out.push({ d: shift(h.d), pen: 1 });\n  }\n  const x = 3 + fill;\n  out.push({ d: `M${x.toFixed(1)} -4L${(x + 0.4).toFixed(1)} ${BAR_H + 4}`, pen: 0 });\n  return out;\n}\n\nexport function InkProgress({\n  value,\n  max = 100,\n  variant = 'bar',\n  label,\n  showValue = true,\n  display = 'percent',\n  prefix,\n  suffix,\n  decimals,\n  size = 128,\n  color = 'currentColor',\n  accent = '#e0482a',\n  strokeWidth = 1.1,\n  seed,\n  trigger = 'scroll',\n  duration = 1600,\n  className = '',\n}: InkProgressProps) {\n  const share = Math.max(0, Math.min(1, value / max));\n  const s = seed ?? seedOf(label ?? `${variant}`);\n  const pen = { color, accent, strokeWidth, trigger, duration };\n  const figure = { value, max, display, prefix, suffix, decimals, trigger };\n  const aria = { role: 'progressbar', 'aria-valuenow': value, 'aria-valuemin': 0, 'aria-valuemax': max, 'aria-label': label } as const;\n\n  const bar = useRef<HTMLDivElement>(null);\n  const barSize = useSize(bar);\n  const [round, setRound] = useState<Stroke[] | null>(null);\n  useEffect(() => {\n    if (variant === 'ring') setRound(dial({ size: 100, seed: s, share }));\n    else if (variant === 'gauge') setRound(gauge({ seed: s, size: 100, share }));\n  }, [variant, s, share]);\n\n  const strokes = useMemo(() => (variant === 'bar' && barSize && barSize.w > 10 ? barStrokes(barSize.w, share, s) : null), [variant, barSize, share, s]);\n\n  if (variant === 'bar') {\n    return (\n      <div {...aria} className={`w-full ${className}`}>\n        {(label || showValue) && (\n          <div className=\"mb-3 flex items-baseline justify-between gap-4\">\n            {label && <span className=\"font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground\">{label}</span>}\n            {showValue && <Figure {...figure} className=\"font-serif text-2xl tracking-[-0.02em]\" />}\n          </div>\n        )}\n        <div ref={bar} className=\"relative h-[30px] w-full\">\n          {/* The outline and the scale first, then the fill hatched in to the value. */}\n          {strokes && <Drawing key={barSize!.w} {...pen} strokes={strokes} w={barSize!.w} h={BAR_H + 12} spread={1} className=\"absolute inset-0\" />}\n        </div>\n      </div>\n    );\n  }\n\n  return (\n    <div {...aria} className={`inline-flex flex-col items-center ${className}`}>\n      <div className=\"relative\" style={{ width: size, height: size }}>\n        {round && <Drawing {...pen} strokes={round} w={size} h={size} view=\"0 0 100 100\" spread={variant === 'gauge' ? 0.8 : 0.6} strokeWidth={strokeWidth * (100 / size)} className=\"absolute inset-0\" />}\n        {showValue && (\n          <Figure\n            {...figure}\n            className={`absolute inset-x-0 text-center font-serif leading-none tracking-[-0.03em] ${variant === 'gauge' ? 'bottom-[4%]' : 'top-1/2 -translate-y-1/2'}`}\n            style={{ fontSize: Math.round(size * (variant === 'gauge' ? 0.2 : 0.24)) }}\n          />\n        )}\n      </div>\n      {label && <span className=\"mt-4 max-w-[16rem] text-center font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground\">{label}</span>}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/scrollfx/ink-progress.tsx"
    }
  ],
  "type": "registry:ui"
}