{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sparkline-thread",
  "title": "Sparkline Thread",
  "description": "A glowing sparkline climbs to a point while +212% counts up beside it.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/sparkline-thread/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadDisplay } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: mono } = loadMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: display } = loadDisplay(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\nexport interface SparklineThreadProps {\n  values?: number[];\n  metric?: string;\n  label?: string;\n  accent?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_VALUES = [20, 26, 24, 29, 35, 34, 41, 38, 49, 56, 53, 64, 70, 77];\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n// gradients.sh \"beam\" palette: bg #02030a, [#f4f7ff, #8fb4ff, #3d5bff, #1a1660].\n// It lives only in the hero series (stroke + area); everything else stays neutral.\nconst THEMES = {\n  dark: {\n    bg: \"#02030a\",\n    fg: \"#F3F2EF\",\n    muted: \"#8B8C96\",\n    axis: \"rgba(255,255,255,0.14)\",\n    thread: 0.78,\n    stroke: [\"#3d5bff\", \"#8fb4ff\", \"#f4f7ff\"],\n    area: [\n      [\"#8fb4ff\", 0.42],\n      [\"#3d5bff\", 0.26],\n      [\"#1a1660\", 0],\n    ],\n    wash: \"rgba(143,180,255,0.07)\",\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    muted: \"#6E6C67\",\n    axis: \"rgba(18,18,20,0.16)\",\n    thread: 0.7,\n    stroke: [\"#8fb4ff\", \"#3d5bff\", \"#1a1660\"],\n    area: [\n      [\"#3d5bff\", 0.3],\n      [\"#8fb4ff\", 0.2],\n      [\"#8fb4ff\", 0],\n    ],\n    wash: \"rgba(255,255,255,0.7)\",\n    grain: 0.045,\n  },\n} as const;\n\nconst POP = -6;\nconst POP_STAGGER = 2;\nconst THREAD = [22, 64] as const;\nconst THICKEN = [62, 84] as const;\nconst BLOOM = 82;\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={7}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\nfunction monotone(pts: Array<[number, number]>) {\n  const n = pts.length;\n  if (n < 2) return pts;\n  const dx = pts.slice(1).map((q, i) => q[0] - pts[i][0]);\n  const sl = pts.slice(1).map((q, i) => (q[1] - pts[i][1]) / dx[i]);\n  const m = pts.map((_, i) => {\n    if (i === 0) return sl[0];\n    if (i === n - 1) return sl[n - 2];\n    if (sl[i - 1] * sl[i] <= 0) return 0;\n    return (2 * sl[i - 1] * sl[i]) / (sl[i - 1] + sl[i]);\n  });\n  const out: Array<[number, number]> = [];\n  for (let i = 0; i < n - 1; i++) {\n    const [x0, y0] = pts[i];\n    const [, y1] = pts[i + 1];\n    const h = dx[i];\n    for (let k = 0; k < 16; k++) {\n      const s = k / 16;\n      const s2 = s * s;\n      const s3 = s2 * s;\n      const y =\n        (2 * s3 - 3 * s2 + 1) * y0 +\n        (s3 - 2 * s2 + s) * h * m[i] +\n        (-2 * s3 + 3 * s2) * y1 +\n        (s3 - s2) * h * m[i + 1];\n      out.push([x0 + s * h, y]);\n    }\n  }\n  out.push(pts[n - 1]);\n  return out;\n}\n\nfunction cut(curve: Array<[number, number]>, x: number) {\n  const pts: Array<[number, number]> = [];\n  for (let i = 0; i < curve.length; i++) {\n    const [cx, cy] = curve[i];\n    if (cx <= x) {\n      pts.push([cx, cy]);\n      continue;\n    }\n    if (i > 0) {\n      const [px, py] = curve[i - 1];\n      const k = (x - px) / (cx - px);\n      pts.push([x, py + (cy - py) * k]);\n    }\n    break;\n  }\n  return pts;\n}\n\nconst toD = (pts: Array<[number, number]>) =>\n  pts\n    .map(([x, y], i) => `${i ? \"L\" : \"M\"}${x.toFixed(2)} ${y.toFixed(2)}`)\n    .join(\" \");\n\nfunction splitMetric(metric: string) {\n  const m = metric.match(/^([^\\d]*)([\\d.,]+)(.*)$/);\n  if (!m) return null;\n  const n = Number.parseFloat(m[2].replace(/,/g, \"\"));\n  if (!Number.isFinite(n)) return null;\n  const decimals = (m[2].split(\".\")[1] ?? \"\").length;\n  return { pre: m[1], n, post: m[3], decimals, grouped: m[2].includes(\",\") };\n}\n\nconst lerp = (a: number, b: number, k: number) => a + (b - a) * k;\n\nexport function SparklineThread({\n  values = DEFAULT_VALUES,\n  metric = \"+212%\",\n  label = \"weekly renders\",\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: SparklineThreadProps) {\n  const t = useCurrentFrame() * speed;\n  const { width, height, fps } = useVideoConfig();\n  const u = height / 720;\n  const p = THEMES[theme];\n  const id = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n\n  const L = width * 0.07;\n  const R = width * 0.54;\n  const T = height * 0.3;\n  const B = height * 0.7;\n  const base = height * 0.8;\n\n  const data = values.length >= 2 ? values : DEFAULT_VALUES;\n  const lo = Math.min(...data);\n  const hi = Math.max(...data);\n  const pts = data.map(\n    (v, i) =>\n      [\n        lerp(L, R, i / (data.length - 1)),\n        lerp(B, T, hi === lo ? 0.5 : (v - lo) / (hi - lo)),\n      ] as [number, number],\n  );\n  const curve = monotone(pts);\n  const last = pts[pts.length - 1];\n\n  const threadX = interpolate(t, THREAD, [L, R], { ...CLAMP, easing: EASE_IO });\n  const thickX = interpolate(t, THICKEN, [L, R], { ...CLAMP, easing: EASE_IO });\n  const threadPts = cut(curve, threadX);\n  const thickPts = cut(curve, thickX);\n  const head = threadPts[threadPts.length - 1] ?? pts[0];\n  const headO =\n    interpolate(t, [THREAD[0], THREAD[0] + 4], [0, 1], CLAMP) *\n    interpolate(t, [THREAD[1] - 4, THREAD[1] + 2], [1, 0], CLAMP);\n\n  const bloom = spring({\n    frame: t - BLOOM,\n    fps,\n    config: { damping: 14, stiffness: 160, mass: 0.7 },\n  });\n  const ring = interpolate(t, [BLOOM, BLOOM + 28], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const leader = interpolate(t, [BLOOM + 2, BLOOM + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const numIn = interpolate(t, [BLOOM + 6, BLOOM + 24], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const count = interpolate(t, [BLOOM + 6, BLOOM + 30], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const labIn = interpolate(t, [BLOOM + 16, BLOOM + 34], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const fillIn = interpolate(\n    t,\n    [THICKEN[0] + 6, THICKEN[1] + 10],\n    [0, 1],\n    CLAMP,\n  );\n\n  const parts = splitMetric(metric);\n  const shown = parts\n    ? `${parts.pre}${(parts.n * count).toLocaleString(\"en-US\", {\n        minimumFractionDigits: parts.decimals,\n        maximumFractionDigits: parts.decimals,\n        useGrouping: parts.grouped,\n      })}${parts.post}`\n    : metric;\n\n  const metricX = R + width * 0.055;\n  const numSize = 136 * u;\n  const fillD =\n    thickPts.length > 1\n      ? `${toD(thickPts)} L${thickPts[thickPts.length - 1][0].toFixed(2)} ${base.toFixed(2)} L${L.toFixed(2)} ${base.toFixed(2)} Z`\n      : \"\";\n\n  return (\n    <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(circle ${height * 0.55}px at ${t < BLOOM ? head[0] : last[0]}px ${t < BLOOM ? head[1] : last[1]}px, ${p.wash}, transparent 100%)`,\n        }}\n      />\n      <svg\n        width={width}\n        height={height}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <linearGradient\n            id={`${id}f`}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={0}\n            y1={T}\n            x2={0}\n            y2={base}\n          >\n            {p.area.map(([c, o], i) => (\n              <stop\n                key={`${c}${i}`}\n                offset={i / (p.area.length - 1)}\n                stopColor={c}\n                stopOpacity={o}\n              />\n            ))}\n          </linearGradient>\n          <linearGradient\n            id={`${id}s`}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={L}\n            y1={B}\n            x2={R}\n            y2={T}\n          >\n            {p.stroke.map((c, i) => (\n              <stop\n                key={`${c}${i}`}\n                offset={i / (p.stroke.length - 1)}\n                stopColor={c}\n              />\n            ))}\n          </linearGradient>\n          <radialGradient id={`${id}h`}>\n            <stop offset=\"0\" stopColor={p.stroke[1]} stopOpacity={0.32} />\n            <stop offset=\"1\" stopColor={p.stroke[1]} stopOpacity={0} />\n          </radialGradient>\n        </defs>\n\n        <line\n          x1={L}\n          y1={base}\n          x2={interpolate(t, [0, 26], [lerp(L, R, 0.3), R], {\n            ...CLAMP,\n            easing: EASE_OUT,\n          })}\n          y2={base}\n          stroke={p.axis}\n          strokeWidth={Math.max(1, u)}\n        />\n        {pts.map(([x], i) => {\n          const a = interpolate(\n            t,\n            [POP + i * POP_STAGGER, POP + i * POP_STAGGER + 8],\n            [0, 1],\n            CLAMP,\n          );\n          return (\n            <line\n              key={`tick-${x}`}\n              x1={x}\n              y1={base}\n              x2={x}\n              y2={base + 7 * u}\n              stroke={p.axis}\n              strokeWidth={Math.max(1, u)}\n              opacity={a}\n            />\n          );\n        })}\n\n        {fillD && <path d={fillD} fill={`url(#${id}f)`} opacity={fillIn} />}\n\n        {threadPts.length > 1 && (\n          <path\n            d={toD(threadPts)}\n            fill=\"none\"\n            stroke={p.fg}\n            strokeOpacity={p.thread}\n            strokeWidth={1.3 * u}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n          />\n        )}\n        {thickPts.length > 1 && (\n          <path\n            d={toD(thickPts)}\n            fill=\"none\"\n            stroke={`url(#${id}s)`}\n            strokeWidth={3.6 * u}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n          />\n        )}\n\n        {pts.map(([x, y], i) => {\n          const isLast = i === pts.length - 1;\n          const pop = spring({\n            frame: t - POP - i * POP_STAGGER,\n            fps,\n            config: { damping: 12, stiffness: 200, mass: 0.6 },\n          });\n          const o = interpolate(\n            t,\n            [POP + i * POP_STAGGER, POP + i * POP_STAGGER + 5],\n            [0, 1],\n            CLAMP,\n          );\n          const threaded = interpolate(\n            threadX - x,\n            [0, 2 * u, 40 * u],\n            [0, 1, 0],\n            CLAMP,\n          );\n          const absorbed =\n            isLast || t < THICKEN[0]\n              ? 0\n              : interpolate(thickX - x, [-6 * u, 10 * u], [0, 1], CLAMP);\n          const r =\n            4 * u * (0.5 + 0.5 * pop) * (1 + 0.45 * threaded) * (1 - absorbed);\n          if (isLast && t >= BLOOM) return null;\n          return (\n            <circle\n              key={`dot-${x}`}\n              cx={x}\n              cy={y}\n              r={Math.max(0, r)}\n              fill={absorbed > 0 ? p.stroke[1] : p.fg}\n              opacity={o}\n            />\n          );\n        })}\n\n        <circle\n          cx={head[0]}\n          cy={head[1]}\n          r={16 * u}\n          fill={`url(#${id}h)`}\n          opacity={headO}\n        />\n        <circle\n          cx={head[0]}\n          cy={head[1]}\n          r={2.6 * u}\n          fill={p.fg}\n          opacity={headO}\n        />\n\n        {t >= BLOOM && (\n          <g>\n            <circle\n              cx={last[0]}\n              cy={last[1]}\n              r={30 * u}\n              fill={`url(#${id}h)`}\n              opacity={bloom}\n            />\n            <circle\n              cx={last[0]}\n              cy={last[1]}\n              r={lerp(8, 52, ring) * u}\n              fill=\"none\"\n              stroke={accent}\n              strokeWidth={1.4 * u}\n              opacity={(1 - ring) * 0.75}\n            />\n            <line\n              x1={last[0] + 14 * u}\n              y1={last[1]}\n              x2={lerp(last[0] + 14 * u, metricX - 18 * u, leader)}\n              y2={last[1]}\n              stroke={p.fg}\n              strokeOpacity={0.3}\n              strokeWidth={Math.max(1, u)}\n              strokeDasharray={`${2 * u} ${5 * u}`}\n              strokeLinecap=\"round\"\n            />\n            <circle\n              cx={last[0]}\n              cy={last[1]}\n              r={lerp(4, 8, bloom) * u}\n              fill={p.bg}\n              stroke={p.stroke[2]}\n              strokeWidth={3 * u}\n            />\n            <circle\n              cx={last[0]}\n              cy={last[1]}\n              r={lerp(0, 3, bloom) * u}\n              fill={p.stroke[2]}\n            />\n          </g>\n        )}\n      </svg>\n\n      <div\n        style={{\n          position: \"absolute\",\n          left: metricX,\n          top: last[1] - numSize * 0.52,\n          opacity: numIn,\n          transform: `translateX(${(1 - numIn) * -22 * u}px)`,\n        }}\n      >\n        <div\n          style={{\n            fontFamily: display,\n            fontWeight: 400,\n            fontSize: numSize,\n            lineHeight: 1,\n            letterSpacing: \"-0.05em\",\n            color: p.fg,\n            fontVariantNumeric: \"tabular-nums\",\n            whiteSpace: \"nowrap\",\n          }}\n        >\n          {shown}\n        </div>\n        <div\n          style={{\n            marginTop: 18 * u,\n            marginLeft: 6 * u,\n            fontFamily: mono,\n            fontWeight: 400,\n            fontSize: 18 * u,\n            letterSpacing: \"0.08em\",\n            textTransform: \"uppercase\",\n            color: p.muted,\n            opacity: labIn,\n            transform: `translateY(${(1 - labIn) * 8 * u}px)`,\n            whiteSpace: \"nowrap\",\n          }}\n        >\n          {label}\n        </div>\n      </div>\n\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(ellipse 80% 80% at 50% 50%, transparent 60%, ${p.bg} 100%)`,\n          opacity: 0.6,\n          pointerEvents: \"none\",\n        }}\n      />\n      <Grain opacity={p.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/sparkline-thread.tsx"
    }
  ],
  "type": "registry:component"
}
