{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spiral-progress-chart",
  "title": "Spiral Progress Chart",
  "description": "A long project as one spiral path: progress winds out from the centre, milestones sit along the way, and a second marker shows where the plan says you should be.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/spiral-progress-chart/spiral-progress-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SpiralMilestone {\n  label: string;\n  /** Where it sits on the path, from 0 to 1. */\n  at: number;\n  /** Small text beside it, e.g. a date. */\n  note?: string;\n}\n\nexport interface SpiralView {\n  label: string;\n  /** How far along the path you are, from 0 to 1. */\n  progress: number;\n  /** Where the plan says you should be, from 0 to 1. */\n  pace?: number;\n  milestones: SpiralMilestone[];\n}\n\nexport interface SpiralProgressChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  views?: SpiralView[];\n  /** Index of the view shown first. */\n  defaultView?: number;\n  /** Colour of the finished part of the path. */\n  color?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    surface: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    tip: \"#161718\",\n    tipShadow: \"0 4px 24px rgba(0,0,0,0.4)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    chipOn: \"rgba(255,255,255,0.1)\",\n    accent: \"#5E6AD2\",\n    track: \"rgba(255,255,255,0.05)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    surface: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    tip: \"#FFFFFF\",\n    tipShadow: \"0 3px 12px rgba(8,9,10,0.09)\",\n    chip: \"rgba(8,9,10,0.04)\",\n    chipOn: \"#FFFFFF\",\n    accent: \"#5E6AD2\",\n    track: \"rgba(8,9,10,0.05)\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst CARD_FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction Stat({\n  value,\n  label,\n  pal,\n}: {\n  value: string;\n  label: string;\n  pal: Palette;\n}) {\n  return (\n    <div className=\"text-left sm:text-right\">\n      <p className=\"m-0 text-[18px] leading-[1.2] font-[510] tracking-[-0.018em] tabular-nums\">\n        {value}\n      </p>\n      <p\n        className=\"m-0 mt-0.5 text-[12px] tracking-[-0.011em]\"\n        style={{ color: pal.sub }}\n      >\n        {label}\n      </p>\n    </div>\n  );\n}\n\nfunction Pills({\n  label,\n  options,\n  value,\n  onChange,\n  pal,\n}: {\n  label: string;\n  options: string[];\n  value: number;\n  onChange: (index: number) => void;\n  pal: Palette;\n}) {\n  return (\n    <div\n      className=\"flex rounded-full p-0.5\"\n      style={{ background: pal.chip }}\n      role=\"radiogroup\"\n      aria-label={label}\n    >\n      {options.map((option, i) => (\n        <button\n          key={option}\n          type=\"button\"\n          role=\"radio\"\n          aria-checked={i === value}\n          onClick={() => onChange(i)}\n          className=\"h-7 cursor-pointer rounded-full px-3 text-[13px] font-[510] tracking-[-0.011em] transition-colors outline-none focus-visible:ring-2\"\n          style={{\n            background: i === value ? pal.chipOn : \"transparent\",\n            color: i === value ? pal.text : pal.sub,\n          }}\n        >\n          {option}\n        </button>\n      ))}\n    </div>\n  );\n}\n\nconst VIEWS: SpiralView[] = [\n  {\n    label: \"Launch\",\n    progress: 0.64,\n    pace: 0.58,\n    milestones: [\n      { label: \"Research\", at: 0.12, note: \"Feb 3\" },\n      { label: \"Prototype\", at: 0.3, note: \"Mar 18\" },\n      { label: \"Private beta\", at: 0.52, note: \"May 6\" },\n      { label: \"Public beta\", at: 0.74, note: \"Jul 1\" },\n      { label: \"General release\", at: 1, note: \"Sep 9\" },\n    ],\n  },\n  {\n    label: \"Migration\",\n    progress: 0.38,\n    pace: 0.46,\n    milestones: [\n      { label: \"Audit\", at: 0.1, note: \"Jan 20\" },\n      { label: \"Schema\", at: 0.28, note: \"Mar 2\" },\n      { label: \"Dual writes\", at: 0.55, note: \"Apr 28\" },\n      { label: \"Cutover\", at: 0.82, note: \"Jul 14\" },\n      { label: \"Clean-up\", at: 1, note: \"Aug 25\" },\n    ],\n  },\n];\n\nconst SIZE = 264;\nconst CENTRE = SIZE / 2;\nconst INNER = 14;\nconst OUTER = 122;\nconst TURNS = 3.4;\nconst SAMPLES = 420;\nconst THICK = 9;\n\n/** Sine and cosine can differ in the last digit between server and browser, so positions are rounded first. */\nconst round = (n: number) => Math.round(n * 100) / 100;\n\n/** The spiral, sampled once. Positions are worked out by distance along it, so shares match the drawn stroke. */\nconst POINTS = Array.from({ length: SAMPLES + 1 }, (_, i) => {\n  const t = i / SAMPLES;\n  const angle = t * TURNS * Math.PI * 2 - Math.PI / 2;\n  const radius = INNER + (OUTER - INNER) * t;\n  return [\n    round(CENTRE + Math.cos(angle) * radius),\n    round(CENTRE + Math.sin(angle) * radius),\n  ] as [number, number];\n});\n\nconst DISTANCE = POINTS.reduce<number[]>((list, p, i) => {\n  const prev = POINTS[i - 1];\n  list.push(\n    i === 0 ? 0 : list[i - 1] + Math.hypot(p[0] - prev[0], p[1] - prev[1]),\n  );\n  return list;\n}, []);\n\nconst LENGTH = DISTANCE[SAMPLES];\n\nconst SPIRAL_PATH = POINTS.map(\n  (p, i) => `${i ? \"L\" : \"M\"}${p[0].toFixed(1)} ${p[1].toFixed(1)}`,\n).join(\"\");\n\nfunction pointAt(share: number) {\n  const goal = Math.max(0, Math.min(1, share)) * LENGTH;\n  let i = 1;\n  while (i < SAMPLES && DISTANCE[i] < goal) i++;\n  const span = DISTANCE[i] - DISTANCE[i - 1] || 1;\n  const k = (goal - DISTANCE[i - 1]) / span;\n  const [a, b] = [POINTS[i - 1], POINTS[i]];\n  return {\n    x: round(a[0] + (b[0] - a[0]) * k),\n    y: round(a[1] + (b[1] - a[1]) * k),\n  };\n}\n\nexport function SpiralProgressChart({\n  theme = \"dark\",\n  title = \"Road to launch\",\n  subtitle = \"From the first idea at the centre to the release at the edge.\",\n  views = VIEWS,\n  defaultView = 0,\n  color,\n  className,\n  style,\n  ...props\n}: SpiralProgressChartProps) {\n  const pal = PALETTES[theme];\n  const accent = color ?? pal.accent;\n  const reduce = useReducedMotion();\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const haloRef = React.useRef<SVGCircleElement>(null);\n  const [view, setView] = React.useState(defaultView);\n  const [active, setActive] = React.useState<number | null>(null);\n  const [seen, setSeen] = React.useState(false);\n  const data = views[view] ?? views[0];\n  const progress = data?.progress ?? 0;\n  const pace = data?.pace ?? progress;\n  const milestones = data?.milestones ?? [];\n  const [shown, setShown] = React.useState({ progress: 0, pace: 0 });\n  const liveRef = React.useRef({ progress: 0, pace: 0 });\n\n  React.useEffect(() => {\n    const el = boxRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        setSeen(true);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  // The fill and both markers ride one eased value, so the head always sits on the end of the stroke.\n  React.useEffect(() => {\n    if (!seen) return;\n    const from = liveRef.current;\n    let raf = 0;\n    let start = 0;\n    const frame = (now: number) => {\n      start = start || now;\n      const k = reduce ? 1 : Math.min(1, (now - start) / 1000);\n      const e = 1 - Math.pow(1 - k, 3);\n      liveRef.current = {\n        progress: from.progress + (progress - from.progress) * e,\n        pace: from.pace + (pace - from.pace) * e,\n      };\n      setShown(liveRef.current);\n      if (k < 1) raf = requestAnimationFrame(frame);\n    };\n    raf = requestAnimationFrame(frame);\n    return () => cancelAnimationFrame(raf);\n  }, [seen, progress, pace, reduce]);\n\n  React.useEffect(() => {\n    if (reduce) return;\n    const run = haloRef.current?.animate(\n      [{ opacity: 0.45 }, { opacity: 0.1 }, { opacity: 0.45 }],\n      { duration: 2000, iterations: Infinity },\n    );\n    return () => run?.cancel();\n  }, [reduce]);\n\n  const head = pointAt(shown.progress);\n  const planned = pointAt(shown.pace);\n  const ahead = Math.round((progress - pace) * 100);\n  const next = milestones.find((m) => m.at > progress);\n\n  return (\n    <section\n      className={`w-full rounded-2xl p-5 sm:p-6 ${className ?? \"\"}`}\n      style={{\n        background: pal.card,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily: CARD_FONT,\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-x-8 gap-y-3\">\n        <div>\n          <h3 className=\"m-0 text-[17px] leading-[1.33] font-[590] tracking-[-0.012em]\">\n            {title}\n          </h3>\n          <p\n            className=\"m-0 mt-0.5 text-[13px] tracking-[-0.011em]\"\n            style={{ color: pal.sub }}\n          >\n            {subtitle}\n          </p>\n        </div>\n        <div className=\"flex gap-7\">\n          <Stat\n            value={`${Math.round(progress * 100)}%`}\n            label=\"Complete\"\n            pal={pal}\n          />\n          <Stat\n            value={`${ahead >= 0 ? \"+\" : \"−\"}${Math.abs(ahead)} pts`}\n            label={ahead >= 0 ? \"Ahead of plan\" : \"Behind plan\"}\n            pal={pal}\n          />\n          <Stat value={next?.label ?? \"Done\"} label=\"Next up\" pal={pal} />\n        </div>\n      </div>\n\n      <div\n        ref={boxRef}\n        className=\"mt-5 flex flex-col items-center gap-6 sm:flex-row sm:gap-10\"\n        onPointerLeave={() => setActive(null)}\n      >\n        <svg\n          viewBox={`0 0 ${SIZE} ${SIZE}`}\n          width={SIZE}\n          height={SIZE}\n          className=\"shrink-0\"\n          role=\"img\"\n          aria-label={`${Math.round(progress * 100)}% complete${next ? `, next: ${next.label}` : \"\"}`}\n        >\n          <path\n            d={SPIRAL_PATH}\n            fill=\"none\"\n            stroke={pal.track}\n            strokeWidth={THICK}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n          />\n          <path\n            d={SPIRAL_PATH}\n            fill=\"none\"\n            stroke={accent}\n            strokeWidth={THICK}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            pathLength={100}\n            strokeDasharray={`${(shown.progress * 100).toFixed(2)} 100`}\n          />\n          {milestones.map((m, i) => {\n            const p = pointAt(m.at);\n            const reached = m.at <= shown.progress;\n            const on = active === i;\n            return (\n              <g key={m.label} onPointerEnter={() => setActive(i)}>\n                <circle cx={p.x} cy={p.y} r=\"12\" fill=\"transparent\" />\n                <circle\n                  cx={p.x}\n                  cy={p.y}\n                  r={on ? 6 : 4.5}\n                  fill={reached ? pal.text : pal.card}\n                  stroke={reached ? pal.card : pal.sub}\n                  strokeWidth=\"1.5\"\n                  className=\"motion-safe:transition-[r] motion-safe:duration-150\"\n                />\n              </g>\n            );\n          })}\n          <circle\n            cx={planned.x}\n            cy={planned.y}\n            r=\"3.5\"\n            fill=\"none\"\n            stroke={pal.text}\n            strokeWidth=\"1.5\"\n            strokeDasharray=\"2 2\"\n          />\n          <circle\n            ref={haloRef}\n            cx={head.x}\n            cy={head.y}\n            r=\"11\"\n            fill={accent}\n            opacity=\"0.3\"\n          />\n          <circle cx={head.x} cy={head.y} r=\"4\" fill={pal.text} />\n        </svg>\n\n        <ol className=\"m-0 flex w-full min-w-0 flex-1 list-none flex-col gap-0.5 p-0\">\n          {milestones.map((m, i) => {\n            const reached = m.at <= progress;\n            return (\n              <li key={m.label}>\n                <button\n                  type=\"button\"\n                  onPointerEnter={() => setActive(i)}\n                  onFocus={() => setActive(i)}\n                  onBlur={() => setActive(null)}\n                  className=\"flex h-10 w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 text-left transition-colors outline-none focus-visible:ring-2\"\n                  style={{\n                    background: active === i ? pal.chip : \"transparent\",\n                  }}\n                >\n                  <svg\n                    width=\"14\"\n                    height=\"14\"\n                    viewBox=\"0 0 14 14\"\n                    aria-hidden=\"true\"\n                    className=\"shrink-0\"\n                  >\n                    {reached ? (\n                      <>\n                        <circle cx=\"7\" cy=\"7\" r=\"7\" fill={pal.soft} />\n                        <path\n                          d=\"m4.2 7.2 1.9 1.9 3.7-4\"\n                          fill=\"none\"\n                          stroke={pal.card}\n                          strokeWidth=\"1.5\"\n                          strokeLinecap=\"round\"\n                          strokeLinejoin=\"round\"\n                        />\n                      </>\n                    ) : (\n                      <circle\n                        cx=\"7\"\n                        cy=\"7\"\n                        r=\"6.25\"\n                        fill=\"none\"\n                        stroke={pal.faint}\n                        strokeWidth=\"1.5\"\n                      />\n                    )}\n                  </svg>\n                  <span\n                    className=\"min-w-0 flex-1 truncate text-[13px] font-[510] tracking-[-0.011em]\"\n                    style={{ color: reached ? pal.text : pal.sub }}\n                  >\n                    {m.label}\n                  </span>\n                  <span\n                    className=\"text-[12px] tabular-nums\"\n                    style={{ color: pal.sub }}\n                  >\n                    {m.note}\n                  </span>\n                  <span\n                    className=\"w-9 text-right text-[12px] tabular-nums\"\n                    style={{ color: pal.faint }}\n                  >\n                    {Math.round(m.at * 100)}%\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ol>\n      </div>\n\n      <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2\">\n        <Pills\n          label=\"Project\"\n          options={views.map((v) => v.label)}\n          value={view}\n          onChange={setView}\n          pal={pal}\n        />\n        <div\n          className=\"flex items-center gap-4 text-[12px]\"\n          style={{ color: pal.sub }}\n        >\n          <span className=\"flex items-center gap-1.5\">\n            <span\n              className=\"size-2.5 rounded-full\"\n              style={{ background: pal.text }}\n            />\n            Today\n          </span>\n          <span className=\"flex items-center gap-1.5\">\n            <span\n              className=\"size-2.5 rounded-full border border-dashed\"\n              style={{ borderColor: pal.text }}\n            />\n            Plan\n          </span>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}