{"$schema":"https://ui.shadcn.com/schema/registry.json","author":"Kaiyu Hsu <uicapsule@kyh.io>","categories":["data","colorful"],"dependencies":["@tanstack/charts","d3-shape","lucide-react","motion"],"description":"Sixty-two fintech dashboard cards — highlighted bars, scrubbable areas, range bands, radials, flows and more — drawn with TanStack Charts and sprung in with motion as the wall scrolls past.","devDependencies":["@types/d3-shape"],"files":[{"content":"\"use client\";\n\nimport { barY, defineChart, dot, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { CalendarDays } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useMemo, useState } from \"react\";\n\nimport { rng, WEEKDAYS } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, Delta, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, MUTED, SPRING, THEME } from \"../lib/tokens\";\nimport { stripes } from \"./net-worth-stripes\";\n\nconst TABS = [\n  { name: \"Technical\", total: 56_754.08, values: [52, 68, 43, 100, 52, 83, 31] },\n  { name: \"Account\", total: 48_210.4, values: [61, 47, 88, 55, 72, 40, 58] },\n  { name: \"Billing\", total: 39_877.13, values: [35, 58, 49, 66, 92, 54, 44] },\n  { name: \"Product\", total: 61_302.95, values: [74, 96, 62, 70, 48, 57, 39] },\n] as const;\n\nconst DAY_INDEX = new Map(WEEKDAYS.map((d, i) => [String(d), i]));\nconst PAD = 0.2;\nconst TOP = 108;\nconst HEIGHT = 250;\nconst LABEL_SPACE = 24;\nconst MARGIN = { bottom: LABEL_SPACE, left: 0, right: 0, top: 0 };\nconst PLOT_H = HEIGHT - LABEL_SPACE;\nconst BAR_W = 39;\n\nconst SPARKS = (() => {\n  const r = rng(77);\n\n  return Array.from({ length: 14 }, (_, i) => ({\n    id: i,\n    r: 0.8 + r() * 1.1,\n    u: 0.12 + r() * 0.76,\n    v: 0.04 + r() * 0.9,\n  }));\n})();\n\nexport const Analytics = () => {\n  const [tab, pinTab] = useCycle(TABS.length, 3200);\n  const [hover, setHover] = useState<number | null>(null);\n  const meta = TABS[tab] ?? TABS[0];\n  const values = meta?.values ?? TABS[0].values;\n  let peak = 0;\n\n  for (const [i, v] of values.entries()) {\n    if (v > (values[peak] ?? 0)) {\n      peak = i;\n    }\n  }\n\n  const lit = hover ?? peak;\n\n  const definition = useMemo(() => {\n    const rows = WEEKDAYS.map((day, i) => ({ day, i, value: values[i] ?? 0 }));\n    const hot = rows[lit] ?? rows[0];\n\n    return defineChart({\n      gradients: [\n        ...rows.map((r) =>\n          stripes({\n            base: \"#f2f2f4\",\n            height: (r.value / TOP) * PLOT_H,\n            id: `an-idle-${r.i}`,\n            line: \"#eaeaed\",\n            pitch: 9,\n            width: BAR_W,\n          }),\n        ),\n        {\n          id: \"an-hot\",\n          stops: [\n            { color: \"#1366e8\", offset: 0 },\n            { color: \"#1aa3ff\", offset: 0.5 },\n            { color: \"#1366e8\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n      ],\n      margin: MARGIN,\n      marks: [\n        barY(rows, {\n          fill: (d) => (d.i === lit ? \"url(#an-hot)\" : `url(#an-idle-${d.i})`),\n          key: \"day\",\n          radius: [14, 14, 0, 0],\n          stroke: (d) => (d.i === lit ? \"#0f5fd6\" : \"#dcdce0\"),\n          strokeWidth: 1.2,\n          x: \"day\",\n          y: \"value\",\n        }),\n        dot(\n          SPARKS.map((s) => ({\n            ...s,\n            sx: (hot?.i ?? 0) + s.u * (1 - PAD),\n            sy: s.v * (hot?.value ?? 0),\n          })),\n          {\n            fill: \"#bfe9ff\",\n            fillOpacity: 0.85,\n            key: \"id\",\n            r: \"r\",\n            x: \"sx\",\n            xScale: \"sx\",\n            y: \"sy\",\n          },\n        ),\n        text(rows, {\n          dy: 15,\n          fill: (d) => (d.i === lit ? BLUE : \"#a1a1aa\"),\n          fontSize: 12,\n          fontWeight: 500,\n          key: \"day\",\n          text: \"day\",\n          x: \"day\",\n          y: () => 0,\n        }),\n      ],\n      scales: {\n        sx: {\n          axis: false,\n          channel: \"x\",\n          scale: scaleLinear().domain([0, WEEKDAYS.length - PAD]),\n        },\n        x: {\n          axis: false,\n          scale: scaleBand<string>()\n            .domain([...WEEKDAYS])\n            .paddingInner(PAD)\n            .paddingOuter(0),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, TOP]) },\n      },\n      theme: THEME,\n    });\n  }, [values, lit]);\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between\">\n        <h3 className=\"text-[18px] font-semibold tracking-[-0.01em]\">Analytics</h3>\n        <Chip icon={CalendarDays} chevron>\n          Weekly\n        </Chip>\n      </div>\n      <p className=\"mt-4 text-[12px]\" style={{ color: MUTED }}>\n        Total portfolio value\n      </p>\n      <div className=\"mt-0.5 flex items-end gap-2\">\n        <Num value={meta?.total ?? 0} className=\"text-[30px] font-bold tracking-[-0.03em]\" />\n        <p className=\"pb-1.5 text-[11px]\" style={{ color: MUTED }}>\n          <Delta value={1.16} className=\"text-[11px]\" /> Vs Last week\n        </p>\n      </div>\n      <div className=\"mt-3 grid grid-cols-4 gap-1.5\">\n        {TABS.map((t, i) => (\n          <button\n            key={t.name}\n            type=\"button\"\n            onClick={() => pinTab(i)}\n            className=\"relative rounded-full py-1.5 text-[12px] font-medium ring-1 ring-black/[0.08]\"\n            style={{ color: i === tab ? \"#ffffff\" : \"#55555c\" }}\n          >\n            {i === tab ? (\n              <motion.span\n                layoutId=\"analytics-tab\"\n                transition={SPRING}\n                className=\"absolute inset-0 rounded-full\"\n                style={{\n                  background: \"linear-gradient(180deg, #2f8cff, #1570ef)\",\n                  boxShadow:\n                    \"inset 0 1px 0 rgba(255,255,255,0.35), 0 6px 14px -6px rgba(21,112,239,0.85)\",\n                }}\n              />\n            ) : null}\n            <span className=\"relative\">{t.name}</span>\n          </button>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div\n          onMouseLeave={() => {\n            setHover(null);\n            pinTab(null);\n          }}\n        >\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel={`${meta?.name} activity by weekday`}\n            onFocusChange={(p) => {\n              const i = DAY_INDEX.get(String(p?.xValue)) ?? -1;\n\n              if (i !== -1) {\n                setHover(i);\n                pinTab(tab);\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/analytics.tsx","target":"uicapsule/finance-charts/charts/analytics.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, link, rect, text } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { sankeyDiagram } from \"@tanstack/charts/network/sankey\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { curveBumpX } from \"d3-shape\";\nimport { ChartPie, ChevronDown } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Caption,\n  Legend,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { MUTED, THEME } from \"../lib/tokens\";\n\ninterface Node {\n  id: string;\n  label: string;\n  color: string;\n}\n\ninterface Flow {\n  id: string;\n  source: string;\n  target: string;\n  value: number;\n}\n\nconst NODES: Node[] = [\n  { color: \"#93c5fd\", id: \"eq\", label: \"Equities\" },\n  { color: \"#fdba8c\", id: \"cash\", label: \"Cash Equivalents\" },\n  { color: \"#0a84ff\", id: \"fi\", label: \"Fixed Income\" },\n  { color: \"#f97316\", id: \"re\", label: \"Real estate\" },\n  { color: \"#fbbf24\", id: \"co\", label: \"Commodities\" },\n];\n\nconst FLOWS: Flow[] = [\n  { id: \"cash-re\", source: \"cash\", target: \"re\", value: 107.7 },\n  { id: \"eq-fi-a\", source: \"eq\", target: \"fi\", value: 165.7 },\n  { id: \"eq-re\", source: \"eq\", target: \"re\", value: 101.5 },\n  { id: \"eq-co\", source: \"eq\", target: \"co\", value: 64.2 },\n  { id: \"eq-fi-b\", source: \"eq\", target: \"fi\", value: 186.4 },\n  { id: \"cash-co\", source: \"cash\", target: \"co\", value: 62.1 },\n];\n\nconst TOTAL = FLOWS.reduce((s, f) => s + f.value, 0);\nconst nodeOf = new Map(NODES.map((n) => [n.id, n]));\n\nconst totalOf = (id: string, side: \"source\" | \"target\") =>\n  FLOWS.filter((f) => f[side] === id).reduce((s, f) => s + f.value, 0);\n\nconst HEIGHT = 270;\nconst MARGIN = { bottom: 0, left: 0, right: 0, top: 0 };\nconst NODE_W = 34;\nconst curve = d3Curve(curveBumpX);\n\nconst ORDER = [\"eq-re\", \"cash-re\", \"eq-co\", \"eq-fi-b\", \"cash-co\", \"eq-fi-a\"];\n\nexport const AssetAllocation = () => {\n  const [hi, pin] = useCycle(ORDER.length, 2300);\n  const focus = FLOWS.find((f) => f.id === ORDER[hi]) ?? FLOWS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        color: { domain: NODES.map((n) => n.id), range: NODES.map((n) => n.color) },\n        gradients: NODES.map((n) => ({\n          id: `aa-${n.id}`,\n          stops: [\n            { color: n.color, offset: 0, opacity: 0.12 },\n            { color: n.color, offset: 1, opacity: 0.62 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        })),\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          sankeyDiagram({\n            align: \"justify\",\n            iterations: 0,\n            linkKey: \"id\",\n            linkSort: null,\n            links: FLOWS,\n            marks: ({ nodes, links }) =>\n              [\n                link(links, {\n                  curve,\n                  key: \"key\",\n                  lineCap: \"butt\",\n                  stroke: (l) => `url(#aa-${l.targetKey})`,\n                  strokeOpacity: (l) => (l.key === focus?.id ? 1 : 0.55),\n                  strokeWidth: (l) => Math.max(1, l.width - 1.5),\n                  x1: \"x1\",\n                  x2: \"x2\",\n                  y1: \"y1\",\n                  y2: (l) => l.y2 + 0.01,\n                }),\n                rect(nodes, {\n                  color: (n) => n.data.id,\n                  inset: 0,\n                  key: \"key\",\n                  radius: 6,\n                  x1: \"x0\",\n                  x2: \"x1\",\n                  y1: \"y0\",\n                  y2: \"y1\",\n                }),\n                rect(nodes, {\n                  fill: \"#000000\",\n                  fillOpacity: 0.16,\n                  inset: 0,\n                  key: \"key\",\n                  radius: 4,\n                  x1: (n) => n.x0 + 3,\n                  x2: (n) => n.x1 - 3,\n                  y1: (n) => n.y0 + 4,\n                  y2: (n) => n.y0 + 20,\n                }),\n                text(nodes, {\n                  fill: \"#ffffff\",\n                  fontSize: 10.5,\n                  fontWeight: 600,\n                  key: \"key\",\n                  text: (n) => `${Math.round((n.value / TOTAL) * 100)}%`,\n                  x: \"x\",\n                  y: (n) => n.y0 + 12,\n                }),\n                text(links, {\n                  anchor: \"start\",\n                  fill: \"#3a3a42\",\n                  fontSize: 11,\n                  key: \"key\",\n                  text: (l) => `$${l.value}M`,\n                  x: (l) => l.x1 + 6,\n                  y: (l) => l.y1,\n                }),\n                text(links, {\n                  anchor: \"end\",\n                  fill: \"#55555e\",\n                  fontSize: 11,\n                  key: \"key\",\n                  text: (l) =>\n                    `${Math.round((l.value / totalOf(String(l.targetKey), \"target\")) * 100)}%`,\n                  x: (l) => l.x2 - 6,\n                  y: (l) => l.y2,\n                }),\n              ] as const,\n            nodeKey: \"id\",\n            nodePadding: 6,\n            nodeSort: null,\n            nodeWidth: NODE_W,\n            nodes: NODES,\n            source: \"source\",\n            target: \"target\",\n            value: \"value\",\n          }),\n        ],\n        scales: { x: null, y: null },\n        theme: THEME,\n      }),\n    [focus],\n  );\n\n  const src = nodeOf.get(focus?.source ?? \"\");\n  const dst = nodeOf.get(focus?.target ?? \"\");\n  const outShare = focus ? (focus.value / totalOf(focus.source, \"source\")) * 100 : 0;\n  const inShare = focus ? (focus.value / totalOf(focus.target, \"target\")) * 100 : 0;\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"flex min-w-0 gap-2.5\">\n          <span\n            className=\"inline-flex size-9 shrink-0 items-center justify-center rounded-[11px] text-white\"\n            style={{\n              background: \"linear-gradient(160deg, #3b9bff, #0a6cff)\",\n              boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.35), 0 4px 10px -4px #0a6cff\",\n            }}\n          >\n            <ChartPie className=\"size-[18px]\" strokeWidth={2.6} />\n          </span>\n          <div className=\"min-w-0\">\n            <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">\n              Asset allocation <span style={{ color: MUTED }}>/ $M</span>\n            </h3>\n            <p className=\"mt-0.5 text-[12px] leading-snug\" style={{ color: MUTED }}>\n              Strategic asset allocation approach to optimize portfolio distribution\n            </p>\n          </div>\n        </div>\n        <MoreButton />\n      </div>\n\n      <div className=\"mt-4 grid grid-cols-2 gap-3\">\n        <div>\n          <Caption>Allocated</Caption>\n          <Num\n            value={687.6}\n            format={(n) => `$${n.toFixed(2)}M`}\n            className=\"text-[24px] font-bold tracking-[-0.03em]\"\n          />\n        </div>\n        <div>\n          <Caption>Total value locked</Caption>\n          <Num\n            value={687.6}\n            format={(n) => `$${n.toFixed(2)}M`}\n            className=\"text-[24px] font-bold tracking-[-0.03em]\"\n          />\n        </div>\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Asset allocation flows from equities and cash into fixed income, real estate and commodities\"\n            onFocusChange={(p) => {\n              const i = p ? ORDER.findIndex((id) => p.key.endsWith(id)) : -1;\n\n              if (i !== -1) {\n                pin(i);\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble left={50} top={30} dark className=\"!rounded-2xl !px-3 !py-2 text-[11px]\">\n            <div className=\"flex items-center justify-between gap-5\">\n              <span className=\"inline-flex items-center gap-1.5 text-white/80\">\n                <span className=\"size-2 rounded-full\" style={{ backgroundColor: src?.color }} />\n                {src?.label}\n              </span>\n              <span className=\"font-semibold tabular-nums\">-{outShare.toFixed(0)}%</span>\n            </div>\n            <div className=\"my-1 flex items-center gap-1.5 pl-0.5 text-white/70\">\n              <ChevronDown className=\"size-3\" />\n              <span className=\"tabular-nums\">${focus?.value}M</span>\n            </div>\n            <div className=\"flex items-center justify-between gap-5\">\n              <span className=\"inline-flex items-center gap-1.5 text-white/80\">\n                <span className=\"size-2 rounded-full\" style={{ backgroundColor: dst?.color }} />\n                {dst?.label}\n              </span>\n              <span className=\"font-semibold tabular-nums\">+{inShare.toFixed(0)}%</span>\n            </div>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n\n      <Legend\n        className=\"mt-4\"\n        items={[\n          { color: \"#0a84ff\", label: \"Fixed Income\" },\n          { color: \"#f97316\", label: \"Real estate\" },\n          { color: \"#93c5fd\", label: \"Equities\" },\n          { color: \"#fdba8c\", label: \"Cash Equivalents\" },\n          { color: \"#fbbf24\", label: \"Commodities\" },\n        ]}\n      />\n    </Card>\n  );\n};\n","path":"/charts/asset-allocation.tsx","target":"uicapsule/finance-charts/charts/asset-allocation.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, stack } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, Sparkles } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng, usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst BARS = 42;\nconst HEIGHT = 168;\nconst DAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"] as const;\nconst PER_DAY = BARS / DAYS.length;\nconst RANGES = [\"Week\", \"Month\", \"Year\"] as const;\n\nconst TOTALS: [number, number][] = [\n  [12_350, 4761],\n  [48_920, 17_305],\n  [563_180, 208_442],\n];\n\nconst BLUE_BAR = \"#2f8cf7\";\nconst ORANGE_BAR = \"#fb8c5a\";\n\ninterface Row {\n  i: number;\n  kind: \"funds\" | \"stocks\";\n  value: number;\n}\n\nconst build = (seed: number) => {\n  const r = rng(seed);\n  const rows: Row[] = [];\n\n  for (let i = 0; i < BARS; i += 1) {\n    const day = i / PER_DAY;\n    const pulse = 0.35 + 0.65 * Math.exp(-day * 0.55);\n    const spike = Math.exp(-((day - 2.2 - r() * 0.4) ** 2) * 6) * 0.5;\n    const funds = Math.max(0.08, (pulse * 0.75 + spike) * (0.45 + r() * 0.7));\n    const stocks = 0.05 + r() * (r() < 0.25 ? 0.22 : 0.07);\n    rows.push({ i, kind: \"funds\", value: funds }, { i, kind: \"stocks\", value: stocks });\n  }\n\n  const peak = Math.max(\n    ...Array.from({ length: BARS }, (_, i) =>\n      rows.filter((row) => row.i === i).reduce((sum, row) => sum + row.value, 0),\n    ),\n  );\n\n  return rows.map((row) => ({ ...row, value: row.value / peak }));\n};\n\nconst DATA = [build(91), build(92), build(93)];\nconst EMPTY: Row[] = [];\nconst TOP = 1.02;\n\nexport const AssetOverviewBar = () => {\n  const [range, pin] = useCycle(RANGES.length, 3000);\n  const rows = DATA[range] ?? EMPTY;\n  const [funds, stocks] = TOTALS[range] ?? [0, 0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"aob-funds\",\n            stops: [\n              { color: \"#cfe5ff\", offset: 0 },\n              { color: \"#0f74f0\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"aob-stocks\",\n            stops: [\n              { color: \"#fdb48c\", offset: 0 },\n              { color: \"#fde1cf\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        margin: { bottom: 26, left: 0, right: 0, top: 4 },\n        marks: [\n          barY(rows, {\n            fill: (d) => (d.kind === \"funds\" ? \"url(#aob-funds)\" : \"url(#aob-stocks)\"),\n            inset: 0.5,\n            key: (d) => `${d.kind}-${d.i}`,\n            layout: stack({ order: [\"funds\", \"stocks\"] }),\n            radius: { end: 2.5, stack: \"each\" },\n            x: \"i\",\n            y: \"value\",\n            z: \"kind\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => DAYS[Math.floor(v / PER_DAY)] ?? \"\",\n                size: 0,\n                values: DAYS.map((_, d) => Math.floor(d * PER_DAY + PER_DAY / 2)),\n              },\n            },\n            scale: scaleBand<number>()\n              .domain(Array.from({ length: BARS }, (_, i) => i))\n              .paddingInner(0.28)\n              .paddingOuter(0),\n          },\n          y: { axis: false, scale: scaleLinear().domain([0, TOP]) },\n        },\n        theme: { ...THEME, muted: \"#a1a1aa\" },\n      }),\n    [rows],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Asset Overview</h3>\n        <MoreButton />\n      </div>\n      <Segmented options={RANGES} value={range} onChange={pin} className=\"mt-4\" />\n      <div className=\"mt-4 grid grid-cols-2 gap-3\">\n        <div>\n          <p className=\"flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n            <span className=\"h-1 w-3.5 rounded-full\" style={{ backgroundColor: BLUE_BAR }} />\n            Mutual Funds\n          </p>\n          <Num\n            value={funds}\n            format={(n) => usd(n, true)}\n            className=\"text-[24px] font-bold tracking-[-0.03em]\"\n          />\n        </div>\n        <div>\n          <p className=\"flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n            <span className=\"h-1 w-3.5 rounded-full\" style={{ backgroundColor: ORANGE_BAR }} />\n            Stocks\n          </p>\n          <Num\n            value={stocks}\n            format={(n) => usd(n, true)}\n            className=\"text-[24px] font-bold tracking-[-0.03em]\"\n          />\n        </div>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel=\"Mutual funds and stocks activity across the week\"\n        />\n      </ChartSlot>\n      <div className=\"mt-3 flex items-center gap-2 rounded-xl border border-[#fbd5c0] bg-[#fff6f1] px-3 py-2.5 text-[12px]\">\n        <Sparkles className=\"size-3.5 shrink-0\" style={{ color: ORANGE_BAR }} fill={ORANGE_BAR} />\n        <p className=\"text-[#55555e]\">\n          <span className=\"font-semibold text-[#0b0b0f]\">Insights:</span> High market activity\n          driven by tech stocks.\n        </p>\n      </div>\n      <button\n        type=\"button\"\n        className=\"mt-3 flex w-full items-center justify-center gap-1.5 rounded-xl border py-2 text-[13px] text-[#3a3a42]\"\n        style={{ borderColor: GRID }}\n      >\n        See insight <ArrowUpRight className=\"size-3.5\" style={{ color: MUTED }} />\n      </button>\n    </Card>\n  );\n};\n","path":"/charts/asset-overview-bar.tsx","target":"uicapsule/finance-charts/charts/asset-overview-bar.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { polar, radialBarRadius } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { motion } from \"motion/react\";\nimport { useMemo } from \"react\";\n\nimport { uniform, usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, ORANGE, PURPLE, SPRING } from \"../lib/tokens\";\n\nconst SPOKES = 20;\nconst HEIGHT = 300;\nconst RING = 0.5;\n\ninterface Region {\n  name: string;\n  color: string;\n  light: string;\n  deep: string;\n  tint: string;\n  gain: number;\n  revenue: number;\n  seed: number;\n}\n\nconst REGIONS: Region[] = [\n  {\n    color: BLUE,\n    deep: \"#0b63d6\",\n    gain: 2100,\n    light: \"#4ea3ff\",\n    name: \"Los Angeles\",\n    revenue: 3900,\n    seed: 5,\n    tint: \"#e5f0fd\",\n  },\n  {\n    color: ORANGE,\n    deep: \"#e2600c\",\n    gain: 1250,\n    light: \"#ffa45c\",\n    name: \"Brooklyn\",\n    revenue: 2480,\n    seed: 17,\n    tint: \"#fff0e4\",\n  },\n  {\n    color: PURPLE,\n    deep: \"#8b31e0\",\n    gain: 550,\n    light: \"#c98bff\",\n    name: \"New York\",\n    revenue: 1630,\n    seed: 29,\n    tint: \"#f4eafe\",\n  },\n];\n\nconst spokes = Array.from({ length: SPOKES }, (_, i) => i);\n\nconst lengths = (seed: number) => {\n  const base = uniform(SPOKES, seed, 0.035, 0.07);\n  const spikes = uniform(5, seed + 1, 0, SPOKES);\n\n  for (const [k, s] of spikes.entries()) {\n    const i = Math.floor(s);\n    base[i] = 0.11 + k * 0.035;\n  }\n\n  return base;\n};\n\nexport const AssetOverviewRadial = () => {\n  const [active, pin] = useCycle(REGIONS.length, 3000);\n  const region = REGIONS[active] ?? REGIONS[0];\n\n  const definition = useMemo(() => {\n    const r = region ?? REGIONS[0];\n    const ls = lengths(r?.seed ?? 0);\n    const outer = spokes.map((i) => ({ i, r1: RING, r2: 0.96 + ((i * 7) % 5) * 0.01 }));\n    const inner = spokes.map((i) => ({ i, r1: RING - 0.13, r2: RING - 0.13 + (ls[i] ?? 0) }));\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"aor-gloss\",\n          stops: [\n            { color: r?.light ?? BLUE, offset: 0 },\n            { color: r?.color ?? BLUE, offset: 0.55 },\n            { color: r?.deep ?? BLUE, offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: 0,\n      marks: [\n        polar({\n          marks: [\n            radialBarRadius(outer, {\n              angle: \"i\",\n              cornerRadius: 6,\n              fill: r?.tint ?? \"#e5f0fd\",\n              id: \"wedges\",\n              key: \"i\",\n              radius1: \"r1\",\n              radius2: \"r2\",\n            }),\n            radialBarRadius(inner, {\n              angle: \"i\",\n              angleScale: \"halo\",\n              cornerRadius: \"full\",\n              fill: r?.color ?? BLUE,\n              fillOpacity: 0.16,\n              id: \"halo\",\n              key: \"i\",\n              radius1: (d) => d.r1 - 0.015,\n              radius2: (d) => d.r2 + 0.02,\n            }),\n            radialBarRadius(inner, {\n              angle: \"i\",\n              angleScale: \"stub\",\n              cornerRadius: 4,\n              fill: \"url(#aor-gloss)\",\n              id: \"stubs\",\n              key: \"i\",\n              radius1: \"r1\",\n              radius2: \"r2\",\n              stroke: r?.deep ?? BLUE,\n              strokeOpacity: 0.35,\n              strokeWidth: 0.75,\n            }),\n          ],\n          scales: {\n            angle: { scale: scaleBand<number>().domain(spokes).paddingInner(0.14) },\n            halo: {\n              channel: \"angle\",\n              scale: scaleBand<number>().domain(spokes).paddingInner(0.28),\n            },\n            radius: { scale: scaleLinear().domain([0, 1]) },\n            stub: {\n              channel: \"angle\",\n              scale: scaleBand<number>().domain(spokes).paddingInner(0.42),\n            },\n          },\n        }),\n      ],\n      scales: { x: null, y: null },\n    });\n  }, [region]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Asset Overview</h3>\n        <MoreButton />\n      </div>\n      <div className=\"mt-3 grid grid-cols-2\">\n        <div>\n          <p className=\"text-[12px] text-[#5b5b63]\">Mutual Funds</p>\n          <Num\n            value={12_350}\n            format={(n) => usd(n, true)}\n            className=\"text-[24px] font-semibold tracking-[-0.02em]\"\n          />\n        </div>\n        <div>\n          <p className=\"text-[12px] text-[#5b5b63]\">Stocks</p>\n          <Num\n            value={1820}\n            format={(n) => usd(n, true)}\n            className=\"text-[24px] font-semibold tracking-[-0.02em]\"\n          />\n        </div>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel={`Revenue by month for ${region?.name ?? \"\"}`}\n        />\n        <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center\">\n          <p className=\"text-[12px] text-[#5b5b63]\">Revenue</p>\n          <Num value={region?.revenue ?? 0} className=\"text-[18px] font-semibold\" />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-3 space-y-2\" onMouseLeave={() => pin(null)}>\n        {REGIONS.map((r, i) => (\n          <button\n            key={r.name}\n            type=\"button\"\n            onMouseEnter={() => pin(i)}\n            className=\"relative flex w-full items-center gap-2.5 rounded-2xl bg-[#f6f6f7] px-3.5 py-2.5 text-left ring-1 ring-black/[0.05]\"\n          >\n            {i === active ? (\n              <motion.span\n                layoutId=\"aor-row\"\n                transition={SPRING}\n                className=\"absolute inset-0 rounded-2xl bg-white shadow-[0_4px_14px_-6px_rgba(0,0,0,0.18)] ring-1 ring-black/[0.06]\"\n              />\n            ) : null}\n            <span className=\"relative size-2.5 rounded-full\" style={{ backgroundColor: r.color }} />\n            <span className=\"relative flex-1 text-[13px] text-[#5b5b63]\">{r.name}</span>\n            <span className=\"relative text-[13px] font-medium tabular-nums\">\n              +{usd(r.gain, true)}\n            </span>\n          </button>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/asset-overview-radial.tsx","target":"uicapsule/finance-charts/charts/asset-overview-radial.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, lineY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, CalendarDays } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst REVENUE = [1680, 3340, 2610, 2891.12, 2560, 2580] as const;\nconst GROWTH = [6.2, 21.4, 9.8, 14, 4.1, 5.3] as const;\nconst GOAL = 6000;\nconst TOP = 3700;\nconst W = 0.37;\nconst D = TOP * 0.05;\n\nconst MARGIN = { bottom: 26, left: 2, right: 2, top: 6 };\nconst HEIGHT = 210;\n\ninterface Pt {\n  g: string;\n  k: string;\n  x: number;\n  y: number;\n}\n\ninterface Face {\n  k: string;\n  x: number;\n  y1: number;\n  y2: number;\n}\n\nconst wire = (i: number, h: number) => {\n  const cx = i + 0.5;\n\n  const outline: [number, number][] = [\n    [cx - W, D],\n    [cx - W, h],\n    [cx, h + D],\n    [cx + W, h],\n    [cx + W, D],\n    [cx, 0],\n    [cx - W, D],\n  ];\n\n  const ridge: [number, number][] = [\n    [cx - W, h],\n    [cx, h - D],\n    [cx + W, h],\n  ];\n\n  const spine: [number, number][] = [\n    [cx, h - D],\n    [cx, 0],\n  ];\n\n  return [\n    ...outline.map(([x, y], j) => ({ g: `${i}-o`, k: `${i}-o${j}`, x, y })),\n    ...ridge.map(([x, y], j) => ({ g: `${i}-r`, k: `${i}-r${j}`, x, y })),\n    ...spine.map(([x, y], j) => ({ g: `${i}-s`, k: `${i}-s${j}`, x, y })),\n  ] satisfies Pt[];\n};\n\nexport const AverageSales = () => {\n  const [hi, pin] = useCycle(REVENUE.length, 2400, 3);\n  const revenue = REVENUE[hi] ?? 0;\n  const growth = GROWTH[hi] ?? 0;\n\n  const definition = useMemo(() => {\n    const h = REVENUE[hi] ?? 0;\n    const cx = hi + 0.5;\n    const wires = REVENUE.flatMap((v, i) => (i === hi ? [] : wire(i, v)));\n\n    const left: Face[] = [\n      { k: \"l0\", x: cx - W, y1: D, y2: h },\n      { k: \"l1\", x: cx, y1: 0, y2: h - D },\n    ];\n\n    const right: Face[] = [\n      { k: \"r0\", x: cx, y1: 0, y2: h - D },\n      { k: \"r1\", x: cx + W, y1: D, y2: h },\n    ];\n\n    const top: Face[] = [\n      { k: \"t0\", x: cx - W, y1: h, y2: h },\n      { k: \"t1\", x: cx, y1: h - D, y2: h + D },\n      { k: \"t2\", x: cx + W, y1: h, y2: h },\n    ];\n\n    const face = (rows: Face[], fill: string, id: string) =>\n      areaY(rows, { fill, fillOpacity: 1, id, key: \"k\", x: \"x\", y1: \"y1\", y2: \"y2\" });\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"as-left\",\n          stops: [\n            { color: \"#16a34a\", offset: 0 },\n            { color: \"#a7e5bb\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"as-right\",\n          stops: [\n            { color: \"#b4ebc6\", offset: 0 },\n            { color: \"#1fae4f\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"as-top\",\n          stops: [\n            { color: \"#9be3b1\", offset: 0 },\n            { color: \"#22b455\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n      ],\n      margin: MARGIN,\n      marks: [\n        lineY(wires, {\n          key: \"k\",\n          stroke: \"#a1a1aa\",\n          strokeDasharray: \"4 4\",\n          strokeWidth: 1,\n          x: \"x\",\n          y: \"y\",\n          z: \"g\",\n        }),\n        face(left, \"url(#as-left)\", \"as-face-left\"),\n        face(right, \"url(#as-right)\", \"as-face-right\"),\n        face(top, \"url(#as-top)\", \"as-face-top\"),\n      ],\n      motion: { path: \"morph\" },\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12, fontWeight: (c) => (c.value === cx ? 600 : 400) },\n            ticks: {\n              format: (v: number) => MONTHS[Math.floor(v)] ?? \"\",\n              size: 0,\n              values: REVENUE.map((_, i) => i + 0.5),\n            },\n          },\n          scale: scaleLinear().domain([0, REVENUE.length]),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, TOP + D]) },\n      },\n      theme: THEME,\n    });\n  }, [hi]);\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between gap-2\">\n        <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">Average Sales</h3>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            6 months\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <p className=\"mt-4 text-[13px]\" style={{ color: MUTED }}>\n        Total revenue\n      </p>\n      <Num value={revenue} className=\"mt-0.5 block text-[30px] font-bold tracking-[-0.03em]\" />\n      <div className=\"mt-1.5 flex items-center gap-2 text-[12px]\">\n        <span\n          className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-semibold\"\n          style={{ color: GREEN }}\n        >\n          <span className=\"inline-flex size-3.5 items-center justify-center rounded-full bg-[#16a34a] text-white\">\n            <ArrowUp className=\"size-2.5\" strokeWidth={3} />\n          </span>\n          <Num value={growth} format={(n) => `${n.toFixed(0)}%`} />\n        </span>\n        <span style={{ color: \"#52525b\" }}>\n          <Num value={(revenue / GOAL) * 100} format={(n) => `${n.toFixed(0)}%`} /> of $6K goal met\n        </span>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Monthly revenue, January to June\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.min(REVENUE.length - 1, Math.max(0, Math.floor(x))));\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n      <p className=\"mt-2 text-[12px] leading-snug\" style={{ color: \"#52525b\" }}>\n        This week revenue increased due to a 4.4 promo\n      </p>\n    </Card>\n  );\n};\n","path":"/charts/average-sales.tsx","target":"uicapsule/finance-charts/charts/average-sales.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { bandX, defineChart, dot, link, lineY, ruleX, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ChartNoAxesColumnIncreasing, EyeOff } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  Delta,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { FAINT, GREEN, MUTED, RED } from \"../lib/tokens\";\n\nconst PURPLE = \"#9333ea\";\nconst LILAC = \"#dcc2fb\";\n\nconst POINTS = [\n  { i: -0.45, value: 64_000 },\n  { i: 0, value: 71_500 },\n  { i: 1, value: 84_200 },\n  { i: 2, value: 71_600 },\n  { i: 3, value: 80_900 },\n  { i: 4, value: 72_900 },\n  { i: 5, value: 88_300 },\n  { i: 6, value: 103_400 },\n  { i: 7, value: 113_600 },\n] as const;\n\nconst MONTH_POINTS = POINTS.filter((p) => p.i >= 0);\nconst BAND = 36;\nconst MIN = 0;\nconst MAX = 158_000;\nconst X0 = -0.45;\nconst X1 = 7.3;\n\nconst MARGIN = { bottom: 26, left: 0, right: 0, top: 0 };\nconst HEIGHT = 230;\n\nexport const Balance = () => {\n  const [hi, pin] = useCycle(MONTH_POINTS.length, 2000, 3);\n  const picked = MONTH_POINTS[hi] ?? MONTH_POINTS[0];\n  const at = picked?.i ?? 0;\n  const prev = POINTS.find((p) => p.i === at - 1) ?? POINTS[0];\n  const change = ((picked?.value ?? 0) / (prev?.value ?? 1) - 1) * 100;\n\n  const definition = useMemo(() => {\n    const past = POINTS.filter((p) => p.i <= at);\n    const future = POINTS.filter((p) => p.i >= at);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"bal-band\",\n          stops: [\n            { color: \"#c084fc\", offset: 0, opacity: 0.55 },\n            { color: \"#e9d5ff\", offset: 0.65, opacity: 0.35 },\n            { color: \"#f5f3ff\", offset: 1, opacity: 0 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: MARGIN,\n      marks: [\n        ruleX(\n          MONTH_POINTS.map((p) => p.i),\n          { stroke: FAINT, strokeDasharray: \"4 4\", strokeOpacity: 0.6 },\n        ),\n        bandX([{ i: at }], {\n          fill: \"url(#bal-band)\",\n          fillOpacity: 1,\n          key: () => \"band\",\n          radius: 8,\n          width: BAND,\n          x: \"i\",\n        }),\n        link([{ i: at }], {\n          key: () => \"band-top\",\n          stroke: \"#c084fc\",\n          strokeWidth: 1,\n          x1: (d) => d.i - 0.25,\n          x2: (d) => d.i + 0.25,\n          y1: () => MAX,\n          y2: () => MAX,\n        }),\n        link([{ i: at }], {\n          key: () => \"band-mid\",\n          stroke: PURPLE,\n          strokeDasharray: \"3 3\",\n          strokeWidth: 1.25,\n          x1: \"i\",\n          x2: \"i\",\n          y1: () => MIN,\n          y2: () => MAX,\n        }),\n        lineY(future, { id: \"future\", stroke: LILAC, strokeWidth: 2, x: \"i\", y: \"value\" }),\n        lineY(past, { id: \"past\", stroke: PURPLE, strokeWidth: 2, x: \"i\", y: \"value\" }),\n        dot(\n          future.filter((p) => p.i > at),\n          { fill: LILAC, id: \"future-dots\", key: \"i\", r: 3.5, x: \"i\", y: \"value\" },\n        ),\n        dot(\n          past.filter((p) => p.i >= 0),\n          {\n            fill: PURPLE,\n            id: \"past-dots\",\n            key: \"i\",\n            r: 3.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 1.25,\n            x: \"i\",\n            y: \"value\",\n          },\n        ),\n        text(\n          MONTH_POINTS.filter((p) => p.i !== at),\n          {\n            dy: 16,\n            fill: MUTED,\n            fontSize: 11.5,\n            id: \"months\",\n            key: \"i\",\n            text: (p) => MONTHS[Math.round(p.i)] ?? \"\",\n            x: \"i\",\n            y: () => MIN,\n          },\n        ),\n        text([{ i: at }], {\n          dy: 16,\n          fill: PURPLE,\n          fontSize: 11.5,\n          fontWeight: 600,\n          id: \"month-on\",\n          key: () => \"on\",\n          text: (p) => MONTHS[Math.round(p.i)] ?? \"\",\n          x: \"i\",\n          y: () => MIN,\n        }),\n      ],\n      scales: {\n        x: { scale: scaleLinear().domain([X0, X1]) },\n        y: { scale: scaleLinear().domain([MIN, MAX]) },\n      },\n    });\n  }, [at]);\n\n  const left = ((at - X0) / (X1 - X0)) * 100;\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between gap-3\">\n        <div className=\"flex items-center gap-3\">\n          <span className=\"inline-flex size-9 items-center justify-center rounded-[11px] bg-[#f3e8ff] ring-1 ring-[#e9d5ff]\">\n            <ChartNoAxesColumnIncreasing\n              className=\"size-4.5\"\n              style={{ color: PURPLE }}\n              strokeWidth={2.6}\n            />\n          </span>\n          <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Balance</h3>\n        </div>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip chevron className=\"!rounded-[10px]\">\n            2025\n          </Chip>\n          <MoreButton className=\"!rounded-[10px]\" />\n        </div>\n      </div>\n\n      <div className=\"mt-4 flex items-end justify-between gap-2\">\n        <div className=\"flex gap-3\">\n          <span className=\"w-1 rounded-full bg-[linear-gradient(180deg,#c084fc,#9333ea)] shadow-[0_2px_6px_-1px_rgba(147,51,234,0.5)]\" />\n          <div>\n            <p className=\"inline-flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n              Total Balance <EyeOff className=\"size-3.5\" />\n            </p>\n            <Num\n              value={320_418.16}\n              className=\"block text-[28px] leading-tight font-bold tracking-[-0.03em]\"\n            />\n          </div>\n        </div>\n        <p className=\"pb-1 text-[11.5px]\" style={{ color: MUTED }}>\n          <Delta value={-120.62} prefix=\"$\" suffix=\"\" /> vs Last year\n        </p>\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Monthly balance\"\n            onFocusChange={(p) => {\n              if (p) {\n                const k = MONTH_POINTS.findIndex((m) => m.i === p.xValue);\n\n                if (k !== -1) {\n                  pin(k);\n                }\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left > 62 ? left - 7 : left + 7}\n            top={8}\n            align={left > 62 ? \"right\" : \"left\"}\n            className=\"!rounded-2xl !px-3 !py-2 text-[12px]\"\n          >\n            <p>\n              <Num value={picked?.value ?? 0} className=\"text-[14px] font-medium\" />{\" \"}\n              <span style={{ color: MUTED }}>Income</span>\n            </p>\n            <p className=\"mt-0.5\">\n              <span className=\"font-medium\" style={{ color: change >= 0 ? GREEN : RED }}>\n                {change >= 0 ? \"+\" : \"\"}\n                {change.toFixed(2)}%\n              </span>{\" \"}\n              <span style={{ color: MUTED }}>Last month</span>\n            </p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/balance.tsx","target":"uicapsule/finance-charts/charts/balance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { pie, polar, radialArc } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { CalendarDays } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, MoreButton, Num, muted, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN } from \"../lib/tokens\";\n\nconst SEGMENTS = 16;\nconst HALF = 178;\n\ninterface Period {\n  label: string;\n  saved: number;\n  target: number;\n  total: number;\n  delta: number;\n}\n\nconst PERIODS: Period[] = [\n  { delta: 12, label: \"Weekly\", saved: 1820, target: 3185, total: 167_350.2 },\n  { delta: 9, label: \"Monthly\", saved: 7420, target: 9800, total: 171_204.6 },\n  { delta: 16, label: \"Yearly\", saved: 41_380, target: 112_000, total: 182_915.4 },\n];\n\nconst STOPS: [number, [number, number, number]][] = [\n  [0, [10, 69, 32]],\n  [0.3, [22, 163, 74]],\n  [0.62, [178, 230, 196]],\n  [1, [214, 243, 223]],\n];\n\nconst mix = (a: number, b: number, t: number) => Math.round(a + (b - a) * t);\n\nconst shade = (i: number) => {\n  const t = i / (SEGMENTS - 1);\n  const upper = STOPS.findIndex(([at]) => at >= t);\n  const [a0, ca] = STOPS[Math.max(0, upper - 1)] ?? STOPS[0] ?? [0, [0, 0, 0]];\n  const [a1, cb] = STOPS[upper] ?? [1, ca];\n  const k = a1 === a0 ? 0 : (t - a0) / (a1 - a0);\n\n  return `rgb(${mix(ca[0], cb[0], k)}, ${mix(ca[1], cb[1], k)}, ${mix(ca[2], cb[2], k)})`;\n};\n\nconst slices = pie(\n  Array.from({ length: SEGMENTS }, (_, i) => ({ id: `seg-${i}`, index: i, value: 1 })),\n  {\n    endAngle: Math.PI / 2,\n    gapAngle: 0.045,\n    startAngle: -Math.PI / 2,\n    value: \"value\",\n  },\n);\n\nexport const BudgetAllocation = () => {\n  const [period, pin] = useCycle(PERIODS.length, 3600);\n  const data = PERIODS[period] ?? PERIODS[0];\n  const saved = data?.saved ?? 0;\n  const target = data?.target ?? 1;\n  const filled = Math.round((saved / target) * SEGMENTS);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        guides: false,\n        margin: 0,\n        marks: [\n          polar({\n            marks: [\n              radialArc(slices, {\n                cornerRadius: 7,\n                fill: \"#ededef\",\n                id: \"track\",\n                innerRadius: ({ radius }) => radius * 0.66,\n                key: \"id\",\n                outerRadius: ({ radius }) => radius,\n              }),\n              radialArc(\n                slices.filter((s) => s.index < filled),\n                {\n                  cornerRadius: 7,\n                  fill: (d) => shade(d.index),\n                  id: \"saved\",\n                  innerRadius: ({ radius }) => radius * 0.66,\n                  key: \"id\",\n                  outerRadius: ({ radius }) => radius,\n                },\n              ),\n            ],\n            scales: { angle: null, radius: null },\n          }),\n        ],\n        scales: { x: null, y: null },\n      }),\n    [filled],\n  );\n\n  return (\n    <Card className=\"!pb-0\">\n      <div className=\"flex items-center justify-between gap-2\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Budget Allocation</h3>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            {data?.label}\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <div className=\"mt-4 grid grid-cols-2 text-center\">\n        <div>\n          <p className=\"inline-flex items-center gap-1.5 text-[12px]\" style={muted}>\n            <span className=\"h-1.5 w-3 rounded-full\" style={{ backgroundColor: GREEN }} />\n            Current Saved\n          </p>\n          <Num\n            value={saved}\n            format={(n) => usd(n, true)}\n            className=\"block text-[24px] font-semibold tracking-[-0.02em]\"\n          />\n        </div>\n        <div>\n          <p className=\"inline-flex items-center gap-1.5 text-[12px]\" style={muted}>\n            <span className=\"h-1.5 w-3 rounded-full bg-[#ececf0]\" />\n            Target Amount\n          </p>\n          <Num\n            value={target}\n            format={(n) => usd(n, true)}\n            className=\"block text-[24px] font-semibold tracking-[-0.02em]\"\n          />\n        </div>\n      </div>\n      <ChartSlot height={HALF} className=\"mt-3 overflow-hidden\">\n        <div onMouseEnter={() => pin(period)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HALF * 2}\n            ariaLabel={`${usd(saved, true)} saved of ${usd(target, true)}`}\n          />\n        </div>\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-3 text-center\">\n          <p className=\"text-[12px]\" style={muted}>\n            Total Saved\n          </p>\n          <Num\n            value={data?.total ?? 0}\n            className=\"block text-[22px] font-semibold tracking-[-0.02em]\"\n          />\n          <p className=\"text-[12px]\" style={muted}>\n            <span style={{ color: GREEN }}>+{data?.delta}%</span> than last month.\n          </p>\n        </div>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/budget-allocation.tsx","target":"uicapsule/finance-charts/charts/budget-allocation.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, rect } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Car, House, ShieldPlus, ShoppingBag } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, Delta, Caption, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED, THEME } from \"../lib/tokens\";\n\nconst PURPLE_BAR = \"#a12ff5\";\n\nconst STEPS = [\n  { delta: 1.16, used: 59 },\n  { delta: 2.84, used: 71.6 },\n  { delta: -3.42, used: 46.2 },\n  { delta: 4.05, used: 82.4 },\n] as const;\n\nconst STRIPES = Array.from({ length: 80 }, (_, i) => ({ id: i, x: (i + 0.5) * 1.25 }));\n\nconst MARGIN = { bottom: 28, left: 0, right: 0, top: 0 };\nconst HEIGHT = 66;\n\nconst CATEGORY_ICONS = [\n  { icon: ShoppingBag, label: \"Shopping\" },\n  { icon: Car, label: \"Transport\" },\n  { icon: House, label: \"Housing\" },\n  { icon: ShieldPlus, label: \"Insurance\" },\n] as const;\n\nconst pctFormat = (n: number) => `${n.toFixed(1)}%`;\n\nexport const BudgetHealth = () => {\n  const [step, pin] = useCycle(STEPS.length, 2600, 0);\n  const { used, delta } = STEPS[step] ?? STEPS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        focusRing: false,\n        margin: MARGIN,\n        marks: [\n          barY(STRIPES, {\n            fill: \"#e7e7ea\",\n            inset: 0.7,\n            key: \"id\",\n            x: \"x\",\n            y1: 0,\n            y2: 1,\n          }),\n          rect([{ id: \"used\", used }], {\n            fill: PURPLE_BAR,\n            inset: 0,\n            key: \"id\",\n            radius: [6, 0, 0, 6],\n            x1: () => 0,\n            x2: \"used\",\n            y1: () => 0,\n            y2: () => 1,\n          }),\n          rect([{ id: \"marker\", used }], {\n            fill: \"#8f1ee6\",\n            inset: 0,\n            key: \"id\",\n            radius: 1.5,\n            x1: (d) => d.used - 0.35,\n            x2: (d) => d.used + 0.35,\n            y1: () => -0.16,\n            y2: () => 1.16,\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                anchor: ({ index }) => {\n                  if (index === 0) {\n                    return \"start\";\n                  }\n\n                  return index === 4 ? \"end\" : \"middle\";\n                },\n                fontSize: 12,\n              },\n              ticks: { format: (v) => `${v}%`, padding: 14, size: 0, values: [0, 25, 50, 75, 100] },\n            },\n            scale: scaleLinear().domain([0, 100]),\n          },\n          y: { axis: false, scale: scaleLinear().domain([-0.18, 1.18]) },\n        },\n        theme: THEME,\n      }),\n    [used],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <h3 className=\"flex items-center gap-2 text-[17px] font-semibold tracking-[-0.01em]\">\n          <span style={{ color: \"#a4a4ab\" }}>Threshold</span>\n          <span className=\"font-normal\" style={{ color: \"#cfcfd4\" }}>\n            /\n          </span>\n          Budget Health\n        </h3>\n        <span\n          className=\"rounded-full px-2.5 py-1 text-[12px] font-medium\"\n          style={{ backgroundColor: \"#f6e9fe\", color: PURPLE_BAR }}\n        >\n          26.4%\n        </span>\n      </div>\n      <div className=\"mt-4 flex items-end justify-between\">\n        <div>\n          <Caption>Budget Utilization</Caption>\n          <p className=\"mt-0.5 flex items-end gap-1.5\">\n            <Num\n              value={used}\n              format={pctFormat}\n              className=\"text-[28px] leading-none font-semibold tracking-[-0.03em]\"\n            />\n            <Delta value={delta} className=\"text-[11px]\" />\n          </p>\n        </div>\n        <div className=\"text-right\">\n          <Caption>Saving rate</Caption>\n          <Num\n            value={98.3 - used}\n            format={pctFormat}\n            className=\"mt-0.5 block text-[28px] leading-none font-semibold tracking-[-0.03em]\"\n          />\n        </div>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Budget utilization against the full budget\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(step);\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-4 flex items-end justify-between\">\n        <div>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Budget categories\n          </p>\n          <div className=\"mt-1.5 flex gap-1.5\">\n            {CATEGORY_ICONS.map(({ icon: Icon, label }) => (\n              <span\n                key={label}\n                title={label}\n                className=\"inline-flex size-8 items-center justify-center rounded-full bg-[#ececee] text-[#4a4a52]\"\n              >\n                <Icon className=\"size-3.5\" strokeWidth={2.4} />\n              </span>\n            ))}\n          </div>\n        </div>\n        <span\n          className=\"rounded-full px-3 py-1.5 text-[12px] font-medium\"\n          style={{ backgroundColor: \"#f6e9fe\", color: PURPLE_BAR }}\n        >\n          4 Categories\n        </span>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/budget-health.tsx","target":"uicapsule/finance-charts/charts/budget-health.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, hexagon } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Car, House, ShoppingBag, Utensils } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { rng } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GRID, INK, MUTED, ORANGE, PURPLE } from \"../lib/tokens\";\n\nconst COLS = 13;\nconst ROWS = 14;\nconst HEIGHT = 300;\nconst SQRT3 = Math.sqrt(3);\n\ntype Kind = 0 | 1 | 2;\n\ninterface Cell {\n  id: string;\n  col: number;\n  row: number;\n  kind: Kind;\n  color: string;\n}\n\nconst SHADES: Record<Kind, readonly string[]> = {\n  0: [\"#fb8c3c\", \"#fdbe8e\", \"#fca765\"],\n  1: [\"#b862f5\", \"#d49bf8\", \"#c47ff6\"],\n  2: [\"#3b8ff0\", \"#8cbff5\", \"#b2d4f8\", \"#d6e8fb\", \"#e6f1fc\"],\n};\n\nconst LEGEND = [\n  { color: ORANGE, label: \"Spent\", value: 10 },\n  { color: PURPLE, label: \"Remaining\", value: 15 },\n  { color: \"#5aa3f5\", label: \"Saved\", value: 75 },\n] as const;\n\nconst CATEGORIES: { icon: LucideIcon; label: string; tint: string; value: number }[] = [\n  { icon: ShoppingBag, label: \"Shopping\", tint: ORANGE, value: 2100 },\n  { icon: Utensils, label: \"Dining\", tint: PURPLE, value: 1250 },\n  { icon: Car, label: \"Transport\", tint: BLUE, value: 550 },\n  { icon: House, label: \"Bills & Utilities\", tint: BLUE, value: 550 },\n];\n\nconst CELLS: Cell[] = (() => {\n  const r = rng(8080);\n  const out: Cell[] = [];\n  const cx = (COLS - 1) / 2;\n  const cy = (ROWS - 1) / 2;\n\n  for (let row = 0; row < ROWS; row += 1) {\n    for (let col = 0; col < COLS; col += 1) {\n      const x = col + (row % 2 === 1 ? 0.5 : 0);\n      const d = Math.hypot(x - cx - 0.25, ((row - cy) * 1.5) / SQRT3) + (r() - 0.5) * 1.1;\n      const keep = d < 4.6 || r() > (d - 4.6) / 2.2;\n\n      if (keep) {\n        let kind: Kind = 2;\n\n        if (d < 2) {\n          kind = 0;\n        } else if (d < 3.4) {\n          kind = 1;\n        }\n\n        const shades = SHADES[kind];\n        let shade = Math.floor(r() * Math.min(shades.length, 3));\n\n        if (kind === 2) {\n          shade = Math.min(shades.length - 1, Math.max(0, Math.floor(d - 3.6 + r() * 1.8)));\n        }\n\n        out.push({ col, color: shades[shade] ?? INK, id: `${row}-${col}`, kind, row });\n      }\n    }\n  }\n\n  return out;\n})();\n\nconst fade = (hex: string, t: number) => {\n  const n = Number.parseInt(hex.slice(1), 16);\n  const ch = [16, 8, 0].map((s) => Math.floor(n / 2 ** s) % 256);\n\n  return `rgb(${ch.map((c) => Math.round(c + (255 - c) * t)).join(\",\")})`;\n};\n\nconst useWidth = () => {\n  const ref = useRef<HTMLDivElement>(null);\n  const [width, setWidth] = useState(0);\n  useEffect(() => {\n    const el = ref.current;\n\n    if (!el) {\n      return;\n    }\n\n    const ro = new ResizeObserver(([entry]) => setWidth(entry?.contentRect.width ?? 0));\n    ro.observe(el);\n\n    return () => ro.disconnect();\n  }, []);\n\n  return [ref, width] as const;\n};\n\nexport const BudgetOverview = () => {\n  const [active, pin] = useCycle(3, 2400, 0);\n  const [ref, width] = useWidth();\n\n  const definition = useMemo(() => {\n    const w = Math.max(1, width);\n    const radius = Math.min(w / ((COLS + 0.5) * SQRT3), HEIGHT / ((ROWS - 1) * 1.5 + 2));\n    const gridW = (COLS + 0.5) * SQRT3 * radius;\n    const gridH = ((ROWS - 1) * 1.5 + 2) * radius;\n    const ox = (w - gridW) / 2 + (SQRT3 * radius) / 2;\n    const oy = (HEIGHT - gridH) / 2 + radius;\n\n    const rows = CELLS.map((c) => ({\n      ...c,\n      px: ox + (c.col + (c.row % 2 === 1 ? 0.5 : 0)) * SQRT3 * radius,\n      py: oy + c.row * 1.5 * radius,\n    }));\n\n    return defineChart({\n      focusRing: false,\n      guides: false,\n      margin: 0,\n      marks: [\n        hexagon(rows, {\n          fill: (d) => (d.kind === active ? d.color : fade(d.color, 0.5)),\n          key: \"id\",\n          r: radius,\n          stroke: \"#ffffff\",\n          strokeWidth: 2,\n          x: \"px\",\n          y: \"py\",\n        }),\n      ],\n      scales: {\n        x: { scale: scaleLinear().domain([0, w]) },\n        y: { reverse: true, scale: scaleLinear().domain([0, HEIGHT]) },\n      },\n    });\n  }, [active, width]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <div>\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Budget overview</h3>\n          <p className=\"mt-0.5 flex items-center gap-2 text-[12px]\">\n            <span style={{ color: MUTED }}>All accounts</span>\n            <span className=\"h-3 w-px\" style={{ backgroundColor: GRID }} />\n            <span className=\"font-medium\">From last 7 days</span>\n          </p>\n        </div>\n        <MoreButton />\n      </div>\n      <div ref={ref} className=\"mt-4\">\n        <ChartSlot height={HEIGHT}>\n          {width > 0 ? (\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Budget split into spent, remaining and saved, as a hexagon field\"\n              onFocusChange={(p) => {\n                const kind = CELLS.find((c) => `${c.row}-${c.col}` === p?.datum.id)?.kind;\n                pin(kind ?? null);\n              }}\n            />\n          ) : null}\n        </ChartSlot>\n      </div>\n      <div className=\"mt-4 grid grid-cols-3\">\n        {LEGEND.map((l, i) => (\n          <button\n            key={l.label}\n            type=\"button\"\n            onMouseEnter={() => pin(i)}\n            onMouseLeave={() => pin(null)}\n            className=\"flex flex-col items-center border-black/[0.06] transition-opacity [&:not(:first-child)]:border-l\"\n            style={{ opacity: i === active ? 1 : 0.55 }}\n          >\n            <span className=\"inline-flex items-center gap-1.5 text-[13px]\" style={{ color: MUTED }}>\n              <span className=\"h-1 w-3 rounded-full\" style={{ backgroundColor: l.color }} />\n              {l.label}\n            </span>\n            <Num\n              value={l.value}\n              format={(n) => `${Math.round(n)}%`}\n              className=\"mt-1 text-[20px] font-semibold\"\n            />\n          </button>\n        ))}\n      </div>\n      <div className=\"mt-4 flex flex-col gap-2\">\n        {CATEGORIES.map(({ icon: Icon, label, tint, value }) => (\n          <div\n            key={label}\n            className=\"flex items-center gap-3 rounded-2xl bg-[#f6f6f7] px-3 py-2.5 ring-1 ring-black/[0.04]\"\n          >\n            <span\n              className=\"inline-flex size-8 items-center justify-center rounded-full\"\n              style={{\n                backgroundColor: fade(tint, 0.88),\n                boxShadow: `inset 0 0 0 1px ${fade(tint, 0.7)}`,\n                color: tint,\n              }}\n            >\n              <Icon className=\"size-4\" strokeWidth={2.4} />\n            </span>\n            <span className=\"flex-1 text-[13px]\" style={{ color: \"#4a4a52\" }}>\n              {label}\n            </span>\n            <Num\n              value={value}\n              format={(n) => `$${Math.round(n).toLocaleString(\"en-US\")}`}\n              className=\"text-[13px] font-medium\"\n            />\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/budget-overview.tsx","target":"uicapsule/finance-charts/charts/budget-overview.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, hexagon, rect } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ChevronRight, Wallet } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst STEPS = [32.5, 47.8, 24.1, 61.3] as const;\nconst BUDGET = 5064.52;\nconst COLS = 52;\nconst DOT_ROWS = 7;\nconst HEIGHT = 128;\nconst BAND = 86;\nconst MARGIN = { bottom: HEIGHT - BAND, left: 0, right: 0, top: 0 };\nconst TRACK = 4 / BAND;\nconst PAD = 14;\n\nconst DOTS = Array.from({ length: COLS * DOT_ROWS }, (_, i) => {\n  const col = i % COLS;\n  const row = Math.floor(i / COLS);\n\n  return {\n    col,\n    id: i,\n    row,\n    x: ((col + 0.5) / COLS) * 100,\n    y: 0.14 + (row / (DOT_ROWS - 1)) * 0.78,\n  };\n});\n\nexport const BudgetPlan = () => {\n  const [step, pin] = useCycle(STEPS.length, 2600, 0);\n  const pct = STEPS[step] ?? STEPS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        focusRing: false,\n        margin: MARGIN,\n        marks: [\n          hexagon(DOTS, {\n            fill: (d) => {\n              if (d.x <= pct) {\n                return d.row < 3 ? \"#d5e5fb\" : \"#c3d9f8\";\n              }\n\n              return d.row < 3 ? \"#eeeef1\" : \"#e4e4e8\";\n            },\n            key: \"id\",\n            r: 1.7,\n            x: \"x\",\n            y: \"y\",\n          }),\n          rect([{ id: \"track\" }], {\n            fill: \"#cfcfd4\",\n            inset: 0,\n            key: \"id\",\n            x1: () => 0,\n            x2: () => 100,\n            y1: () => 0,\n            y2: () => TRACK,\n          }),\n          rect([{ id: \"fill\", pct }], {\n            fill: BLUE,\n            inset: 0,\n            key: \"id\",\n            radius: [0, 2, 2, 0],\n            x1: () => 0,\n            x2: \"pct\",\n            y1: () => 0,\n            y2: () => TRACK,\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                anchor: ({ index }) => {\n                  if (index === 0) {\n                    return \"start\";\n                  }\n\n                  return index === 4 ? \"end\" : \"middle\";\n                },\n                dx: ({ index }) => {\n                  if (index === 0) {\n                    return PAD;\n                  }\n\n                  return index === 4 ? -PAD : 0;\n                },\n                fontSize: 12,\n              },\n              ticks: { format: (v) => `${v}%`, padding: 14, size: 0, values: [0, 25, 50, 75, 100] },\n            },\n            scale: scaleLinear().domain([0, 100]),\n          },\n          y: { axis: false, scale: scaleLinear().domain([0, 1]) },\n        },\n        theme: { ...THEME, background: \"transparent\" },\n      }),\n    [pct],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <div>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Step 2/2\n          </p>\n          <h3 className=\"mt-0.5 flex items-center gap-1.5 text-[17px] font-semibold tracking-[-0.01em]\">\n            <span style={{ color: \"#a4a4ab\" }}>Budget Plan</span>\n            <ChevronRight className=\"size-4\" style={{ color: \"#a4a4ab\" }} />\n            Expense Ratio\n          </h3>\n        </div>\n        <MoreButton />\n      </div>\n      <div\n        className=\"relative mt-4 overflow-hidden rounded-2xl ring-1 ring-black/[0.06]\"\n        style={{ background: `linear-gradient(180deg, #ffffff 0 ${BAND}px, #ececee ${BAND}px)` }}\n      >\n        <ChartSlot height={HEIGHT}>\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Expenses as a share of the monthly budget\"\n              onFocusChange={(p) => {\n                if (p) {\n                  pin(step);\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n        <div\n          className=\"pointer-events-none absolute inset-x-0 flex items-center justify-between gap-2\"\n          style={{ paddingInline: PAD, top: 18 }}\n        >\n          <p className=\"flex items-baseline gap-1.5 text-[12px]\">\n            <span style={{ color: MUTED }}>Expenses</span>\n            <Num value={(BUDGET * pct) / 100} className=\"text-[13px] font-medium\" />\n          </p>\n          <div className=\"flex items-center gap-1.5\">\n            <Num\n              value={pct}\n              format={(n) => `${n.toFixed(1)}%`}\n              className=\"rounded-full bg-[#e7f8ec] px-2 py-1 text-[11px] font-medium\"\n              style={{ color: GREEN }}\n            />\n            <span className=\"inline-flex h-8 items-center gap-1.5 rounded-full bg-white px-3 text-[12px] font-medium shadow-[0_1px_3px_rgba(0,0,0,0.08)] ring-1 ring-black/[0.06]\">\n              <Wallet className=\"size-3.5\" style={{ color: BLUE }} strokeWidth={2.6} />\n              Saving\n            </span>\n          </div>\n        </div>\n      </div>\n      <div className=\"mt-4 flex items-center justify-between gap-2\">\n        <div className=\"flex items-center gap-1\">\n          <span className=\"h-1.5 w-4 rounded-full bg-[#e6e6ea]\" />\n          <span className=\"h-1.5 w-8 rounded-full bg-[#b8d6fb]\" />\n        </div>\n        <div className=\"flex items-center gap-1.5\">\n          <button\n            type=\"button\"\n            className=\"h-9 rounded-full border border-black/[0.08] px-3.5 text-[13px] font-medium text-[#3a3a42]\"\n          >\n            Adjust budget\n          </button>\n          <button\n            type=\"button\"\n            className=\"h-9 rounded-full px-3.5 text-[13px] font-medium text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.3),0_4px_12px_-4px_rgba(29,124,242,0.7)]\"\n            style={{ background: \"linear-gradient(180deg, #3b93f7, #1572ec)\" }}\n          >\n            Save plan\n          </button>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/budget-plan.tsx","target":"uicapsule/finance-charts/charts/budget-plan.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { cell, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst SPENT = 1657;\nconst LIMIT = 5000;\nconst COLS = 30;\nconst ROWS = 2;\nconst FILLED = Math.floor((SPENT / LIMIT) * COLS);\nconst HEIGHT = 23;\n\nconst COL_IDS = Array.from({ length: COLS }, (_, i) => i);\nconst ROW_IDS = Array.from({ length: ROWS }, (_, i) => i);\nconst CELLS = ROW_IDS.flatMap((row) => COL_IDS.map((col) => ({ col, id: `${row}:${col}`, row })));\n\nexport const Budget = () => {\n  const [glint, pin] = useCycle(FILLED + 4, 170);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        color: { domain: [\"on\", \"glint\", \"off\"], range: [ORANGE, \"#fdba74\", \"#f3f3f5\"] },\n        guides: false,\n        margin: 0,\n        marks: [\n          cell(CELLS, {\n            color: (d) => {\n              if (d.col >= FILLED) {\n                return \"off\";\n              }\n\n              return d.col === glint ? \"glint\" : \"on\";\n            },\n            inset: 1.3,\n            key: \"id\",\n            radius: 2.2,\n            x: \"col\",\n            y: \"row\",\n          }),\n        ],\n        scales: {\n          x: { scale: scaleBand<number>().domain(COL_IDS) },\n          y: { scale: scaleBand<number>().domain(ROW_IDS) },\n        },\n        theme: THEME,\n      }),\n    [glint],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between\">\n        <h3 className=\"text-[18px] font-semibold tracking-[-0.01em]\">Budget</h3>\n        <MoreButton />\n      </div>\n      <div className=\"mt-4 flex items-baseline justify-between text-[13px]\">\n        <p>\n          <span style={{ color: MUTED }}>Spent : </span>\n          <Num value={SPENT} format={(n) => usd(n, true)} className=\"font-medium\" />\n        </p>\n        <p>\n          <span style={{ color: MUTED }}>Limit : </span>\n          <span className=\"font-medium tabular-nums\">{usd(LIMIT, true)}</span>\n        </p>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-2\">\n        <div onMouseEnter={() => pin(FILLED + 3)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel={`Budget used: ${usd(SPENT, true)} of ${usd(LIMIT, true)}`}\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-4 flex items-end justify-between gap-3\">\n        <div className=\"text-[13px] leading-snug text-[#55555c]\">\n          <p>You’re well within your limit</p>\n          <p>\n            <Num value={LIMIT - SPENT} format={(n) => usd(n, true)} /> left to spend\n          </p>\n        </div>\n        <button\n          type=\"button\"\n          className=\"rounded-full px-4 py-2 text-[14px] font-medium text-white ring-1 ring-[#e0620c]\"\n          style={{\n            background: \"linear-gradient(180deg, #fb923c, #f97316 55%, #ea6a0c)\",\n            boxShadow:\n              \"inset 0 1px 0 rgba(255,255,255,0.45), inset 0 -2px 4px rgba(194,65,12,0.35), 0 6px 14px -6px rgba(249,115,22,0.8)\",\n          }}\n        >\n          Details\n        </button>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/budget.tsx","target":"uicapsule/finance-charts/charts/budget.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barX, defineChart, dot, link, lineY, ruleY, tickX } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { CreditCard, PiggyBank, Salad, ShoppingBag, TrendingUp } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useMemo } from \"react\";\n\nimport { compact, rng, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  CardHeader,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN, GRID, MUTED, PURPLE, SPRING, THEME } from \"../lib/tokens\";\n\nconst START = 6;\nconst END = 17;\nconst LO = 4000;\nconst HI = 21_000;\n\nconst ANCHORS: [number, number][] = [\n  [6, 13_900],\n  [6.3, 12_900],\n  [7, 13_300],\n  [7.6, 13_900],\n  [8.1, 13_000],\n  [8.8, 14_400],\n  [9.4, 13_700],\n  [10, 14_500],\n  [10.6, 12_500],\n  [11.1, 12_100],\n  [11.7, 12_900],\n  [12.2, 15_400],\n  [12.8, 16_400],\n  [13.15, 15_900],\n  [13.4, 12_000],\n  [14, 12_000],\n  [14.6, 12_800],\n  [15, 11_800],\n  [15.4, 10_300],\n  [15.9, 10_800],\n  [16.2, 10_200],\n  [16.5, 11_500],\n  [16.8, 12_400],\n  [17, 11_300],\n];\n\nconst lerpAnchors = (h: number) => {\n  const i = ANCHORS.findIndex(([x]) => x >= h);\n\n  if (i <= 0) {\n    return ANCHORS[0]?.[1] ?? 0;\n  }\n\n  const [x0, y0] = ANCHORS[i - 1] ?? [START, 0];\n  const [x1, y1] = ANCHORS[i] ?? [END, 0];\n\n  return y0 + ((h - x0) / (x1 - x0)) * (y1 - y0);\n};\n\nconst POINTS = (() => {\n  const r = rng(41);\n  const n = 72;\n\n  return Array.from({ length: n }, (_, i) => {\n    const hour = START + (i / (n - 1)) * (END - START);\n\n    return { hour, value: lerpAnchors(hour) + (r() - 0.5) * 380 };\n  });\n})();\n\nconst valueAt = (hour: number) => {\n  let [best] = POINTS;\n\n  for (const p of POINTS) {\n    if (best === undefined || Math.abs(p.hour - hour) < Math.abs(best.hour - hour)) {\n      best = p;\n    }\n  }\n\n  return best ?? { hour, value: 0 };\n};\n\nconst HATCH = Array.from({ length: 60 }, (_, i) => {\n  const x = START - 1 + i * 0.22;\n\n  return { id: i, x1: x, x2: x + 0.42, y1: 10_000, y2: 15_000 };\n});\n\ninterface Event {\n  hour: number;\n  label: string;\n  icon: LucideIcon;\n  color: string;\n}\n\nconst EVENTS: Event[] = [\n  { color: \"#f5b82e\", hour: 9, icon: CreditCard, label: \"Card top-up\" },\n  { color: GREEN, hour: 12.2, icon: Salad, label: \"Lunch\" },\n  { color: BLUE, hour: 13.4, icon: ShoppingBag, label: \"Shopping\" },\n  { color: PURPLE, hour: 16.2, icon: PiggyBank, label: \"Savings\" },\n];\n\nconst TIME_LABELS = [\n  { hour: 6, label: \"6 AM\" },\n  { hour: 9, label: \"9 AM\" },\n  { hour: 12, label: \"12 PM\" },\n  { hour: 15, label: \"3 PM\" },\n  { hour: 17, label: \"5 PM\" },\n];\n\nconst TICKS = Array.from({ length: 22 }, (_, i) => START + 0.5 + i * 0.5).filter((h) => h <= END);\n\nconst MARGIN = { bottom: 8, left: 46, right: 4, top: 8 };\nconst HEIGHT = 200;\nconst TRACK_MARGIN = { bottom: 0, left: 0, right: 0, top: 0 };\n\nconst pct = (hour: number) => ((hour - START) / (END - START)) * 100;\n\nconst clock = (hour: number) => {\n  const h = Math.floor(hour);\n  const m = Math.round((hour - h) * 60);\n  const suffix = h >= 12 ? \"PM\" : \"AM\";\n  const h12 = h % 12 === 0 ? 12 : h % 12;\n\n  return `${h12}:${String(m).padStart(2, \"0\")} ${suffix}`;\n};\n\nconst Stat = ({ label, value, delta }: { label: string; value: number; delta: number }) => (\n  <div>\n    <p className=\"text-[12px]\" style={{ color: MUTED }}>\n      {label}\n    </p>\n    <Num\n      value={value}\n      format={(n) => usd(n, true)}\n      className=\"mt-0.5 block text-[24px] font-bold tracking-[-0.03em]\"\n    />\n    <p className=\"mt-0.5 inline-flex items-center gap-1 text-[12px]\" style={{ color: MUTED }}>\n      <span className=\"inline-flex items-center gap-0.5 font-semibold\" style={{ color: GREEN }}>\n        <TrendingUp className=\"size-3.5\" strokeWidth={2.5} />\n        {delta}%\n      </span>\n      vs Yesterday\n    </p>\n  </div>\n);\n\nexport const CashBalance = () => {\n  const [active, pin] = useCycle(EVENTS.length, 2300);\n  const event = EVENTS[active] ?? EVENTS[0];\n  const hour = event?.hour ?? START;\n  const point = valueAt(hour);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        clip: true,\n        margin: MARGIN,\n        marks: [\n          link(HATCH, {\n            key: \"id\",\n            lineCap: \"butt\",\n            stroke: \"#dbeafe\",\n            strokeOpacity: 0.9,\n            strokeWidth: 3,\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: \"y1\",\n            y2: \"y2\",\n          }),\n          ruleY([20_000, 5000], {\n            stroke: \"#d4d4da\",\n            strokeDasharray: \"6 6\",\n            strokeOpacity: 1,\n            strokeWidth: 1,\n          }),\n          lineY(POINTS, {\n            curve: d3Curve(curveMonotoneX),\n            stroke: BLUE,\n            strokeWidth: 2.5,\n            x: \"hour\",\n            y: \"value\",\n          }),\n          dot([point], {\n            fill: \"#ffffff\",\n            key: () => \"cursor\",\n            r: 5,\n            stroke: BLUE,\n            strokeWidth: 2.5,\n            x: \"hour\",\n            y: \"value\",\n          }),\n        ],\n        scales: {\n          x: { axis: false, scale: scaleLinear().domain([START, END]) },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => compact(v),\n                size: 0,\n                values: [5000, 10_000, 15_000, 20_000],\n              },\n            },\n            scale: scaleLinear().domain([LO, HI]),\n          },\n        },\n        theme: THEME,\n      }),\n    [point],\n  );\n\n  const track = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"cb-progress\",\n            stops: [\n              { color: BLUE, offset: 0, opacity: 0.04 },\n              { color: BLUE, offset: 0.55, opacity: 0.35 },\n              { color: BLUE, offset: 1, opacity: 0.85 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n        ],\n        guides: false,\n        margin: TRACK_MARGIN,\n        marks: [\n          tickX(\n            TICKS.filter((t) => t > hour + 0.2),\n            {\n              key: (t) => t,\n              length: 10,\n              stroke: \"#dcdce2\",\n              strokeWidth: 2.5,\n              x: (t) => t,\n              y: () => 0,\n            },\n          ),\n          barX([{ id: \"progress\", to: hour }], {\n            fill: \"url(#cb-progress)\",\n            key: \"id\",\n            radius: 6,\n            x1: START,\n            x2: \"to\",\n            y: () => 0,\n          }),\n        ],\n        scales: {\n          x: { scale: scaleLinear().domain([START, END]) },\n          y: { scale: scaleLinear().domain([-1, 1]) },\n        },\n        theme: THEME,\n      }),\n    [hour],\n  );\n\n  return (\n    <Card>\n      <CardHeader icon={CreditCard} color={BLUE} title=\"Cash Balance\" actions={<MoreButton />} />\n      <div className=\"mt-5 grid grid-cols-2 gap-3\">\n        <Stat label=\"Total Balance\" value={13_791} delta={8.6} />\n        <Stat label=\"Income today\" value={2350} delta={15.3} />\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Cash balance through the day\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (!p || !Number.isFinite(x)) {\n                return;\n              }\n\n              let nearest = 0;\n\n              for (const [i, e] of EVENTS.entries()) {\n                if (Math.abs(e.hour - x) < Math.abs((EVENTS[nearest]?.hour ?? 0) - x)) {\n                  nearest = i;\n                }\n              }\n\n              pin(nearest);\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={pct(hour)}\n            top={100 - ((point.value - LO) / (HI - LO)) * 100 - 9}\n            dark\n            align={hour > 15 ? \"right\" : \"center\"}\n            className=\"-translate-y-full\"\n          >\n            <p className=\"text-[11px] text-white/60\">\n              {clock(hour)} · {event?.label}\n            </p>\n            <p className=\"font-semibold tabular-nums\">{usd(point.value, true)}</p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n\n      <div className=\"relative mt-3 h-8\">\n        {EVENTS.map((e, i) => {\n          const Icon = e.icon;\n          const on = i === active;\n\n          return (\n            <motion.span\n              key={e.label}\n              className=\"absolute top-0 inline-flex size-7 items-center justify-center rounded-full ring-2 ring-white\"\n              style={{\n                background: `linear-gradient(160deg, color-mix(in oklab, ${e.color} 65%, white), ${e.color})`,\n                boxShadow: `0 4px 10px -4px ${e.color}`,\n                left: `calc(${pct(e.hour)}% - 14px)`,\n              }}\n              animate={{ scale: on ? 1.12 : 0.92, y: on ? -2 : 0 }}\n              transition={SPRING}\n            >\n              <Icon className=\"size-3.5 text-white\" strokeWidth={2.4} />\n            </motion.span>\n          );\n        })}\n      </div>\n      <ChartSlot height={12} className=\"mt-1\">\n        <Chart\n          definition={track}\n          renderer={renderer}\n          height={12}\n          ariaLabel=\"Time of day progress\"\n        />\n      </ChartSlot>\n      <div className=\"relative mt-1.5 h-4 text-[12px]\" style={{ color: MUTED }}>\n        {TIME_LABELS.map((t, i) => {\n          let shift = \"-50%\";\n\n          if (i === 0) {\n            shift = \"0%\";\n          } else if (i === TIME_LABELS.length - 1) {\n            shift = \"-100%\";\n          }\n\n          return (\n            <span\n              key={t.label}\n              className=\"absolute top-0 whitespace-nowrap\"\n              style={{ left: `${pct(t.hour)}%`, transform: `translateX(${shift})` }}\n            >\n              {t.label}\n            </span>\n          );\n        })}\n      </div>\n\n      <div\n        className=\"mt-5 grid grid-cols-3 gap-2 rounded-2xl px-3.5 py-3\"\n        style={{ backgroundColor: \"#f6f6f8\", borderColor: GRID }}\n      >\n        {[\n          { label: \"Expenses today\", value: 1240 },\n          { label: \"Net cash flow\", value: 3780 },\n          { label: \"Savings goal\", value: 25_000 },\n        ].map((s) => (\n          <div key={s.label} className=\"min-w-0\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              {s.label}\n            </p>\n            <Num\n              value={s.value}\n              format={(n) => usd(n, true)}\n              className=\"mt-0.5 block text-[16px] font-bold tracking-[-0.02em]\"\n            />\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/cash-balance.tsx","target":"uicapsule/finance-charts/charts/cash-balance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, link, lineY, ruleX, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ChartNoAxesColumnIncreasing, CircleArrowDown, CircleArrowUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, MONTHS, uniform, usd, walk } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, FAINT, GREEN, GRID, MUTED, RED } from \"../lib/tokens\";\n\nconst PER_MONTH = 13;\nconst LAST = PER_MONTH * 7;\n\nconst jagged = (seed: number, mean: number, amp: number) => {\n  const noise = uniform(LAST + 1, seed, -1, 1);\n  const swell = walk(LAST + 1, seed + 1, { max: amp, min: -amp, start: 0, vol: amp * 0.18 });\n\n  return noise.map((n, i) => mean + (swell[i] ?? 0) + n * amp * 0.35);\n};\n\nconst CURRENT = jagged(41, 16_600, 2200);\nconst PREVIOUS = jagged(77, 19_600, 2900);\nconst ROWS = CURRENT.map((value, i) => ({ i, prev: PREVIOUS[i] ?? value, value }));\n\nconst MIN = 2500;\nconst MAX = 26_500;\nconst TICKS = [5000, 10_000, 15_000, 20_000, 25_000] as const;\nconst STOPS = Array.from({ length: 14 }, (_, k) => Math.round(k * 6.5 + 3));\nconst GRID_X = Array.from({ length: 15 }, (_, k) => k * 6.5);\n\nconst MARGIN = { bottom: 28, left: 0, right: 40, top: 10 };\nconst HEIGHT = 230;\n\nconst nearestIndex = (list: readonly number[], target: number) => {\n  let best = 0;\n\n  for (const [k, v] of list.entries()) {\n    if (Math.abs(v - target) < Math.abs((list[best] ?? 0) - target)) {\n      best = k;\n    }\n  }\n\n  return best;\n};\n\nconst monthOf = (i: number) => MONTHS[Math.min(7, Math.round(i / PER_MONTH))] ?? \"Jan\";\n\nexport const CashFlowArea = () => {\n  const [stop, pin] = useCycle(STOPS.length, 1800, 6);\n  const at = STOPS[stop] ?? 0;\n  const picked = ROWS[at] ?? ROWS[0];\n  const current = picked?.value ?? 0;\n  const previous = picked?.prev ?? 0;\n  const diff = current - previous;\n  const nearest = TICKS[nearestIndex(TICKS, current)];\n\n  const definition = useMemo(() => {\n    const labels = [\n      { i: 0, key: \"start\", label: \"Jan\" },\n      { i: at, key: \"cursor\", label: monthOf(at) },\n      { i: LAST, key: \"end\", label: \"Aug\" },\n    ].filter((l) => l.key === \"cursor\" || Math.abs(l.i - at) > 14);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"cfa-fill\",\n          stops: [\n            { color: BLUE, offset: 0, opacity: 0.26 },\n            { color: BLUE, offset: 0.85, opacity: 0 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: MARGIN,\n      marks: [\n        ruleX(GRID_X, { stroke: FAINT, strokeDasharray: \"4 4\", strokeOpacity: 0.7 }),\n        link([{ x1: 0, x2: LAST, y: MIN }], {\n          stroke: GRID,\n          strokeWidth: 1.25,\n          x1: \"x1\",\n          x2: \"x2\",\n          y1: \"y\",\n          y2: \"y\",\n        }),\n        areaY(ROWS, { fill: \"url(#cfa-fill)\", fillOpacity: 1, x: \"i\", y1: MIN, y2: \"value\" }),\n        lineY(ROWS, { stroke: \"#cfcfd4\", strokeWidth: 1.5, x: \"i\", y: \"prev\" }),\n        lineY(ROWS, { stroke: BLUE, strokeWidth: 2, x: \"i\", y: \"value\" }),\n        link([{ i: at }], {\n          key: () => \"scrub\",\n          stroke: BLUE,\n          strokeDasharray: \"3 3\",\n          strokeWidth: 1.25,\n          x1: \"i\",\n          x2: \"i\",\n          y1: () => MIN,\n          y2: () => MAX,\n        }),\n        text([{ i: at, y: MAX }], {\n          dy: 2,\n          fill: BLUE,\n          fontSize: 8,\n          key: () => \"cap-top\",\n          text: () => \"▼\",\n          x: \"i\",\n          y: \"y\",\n        }),\n        text([{ i: at, y: MIN }], {\n          dy: -2,\n          fill: BLUE,\n          fontSize: 8,\n          key: () => \"cap-bottom\",\n          text: () => \"▲\",\n          x: \"i\",\n          y: \"y\",\n        }),\n        dot(picked ? [picked] : [], {\n          fill: \"#d4d4d8\",\n          key: () => \"prev-dot\",\n          r: 4,\n          stroke: \"#ffffff\",\n          strokeWidth: 2,\n          x: \"i\",\n          y: \"prev\",\n        }),\n        dot(picked ? [picked] : [], {\n          fill: BLUE,\n          key: () => \"cur-dot\",\n          r: 4.5,\n          stroke: \"#ffffff\",\n          strokeWidth: 2,\n          x: \"i\",\n          y: \"value\",\n        }),\n        ...[false, true].map((hot) =>\n          text(\n            TICKS.filter((v) => (v === nearest) === hot),\n            {\n              anchor: \"start\",\n              dx: 10,\n              fill: hot ? BLUE : MUTED,\n              fontSize: 11,\n              fontWeight: hot ? 600 : 500,\n              id: hot ? \"y-hot\" : \"y-cold\",\n              text: (v) => compact(v),\n              x: () => LAST,\n              y: (v) => v,\n            },\n          ),\n        ),\n        ...[false, true].map((hot) =>\n          text(\n            labels.filter((l) => (l.key === \"cursor\") === hot),\n            {\n              anchor: (l) => {\n                if (l.key === \"start\") {\n                  return \"start\";\n                }\n\n                return l.key === \"end\" ? \"end\" : \"middle\";\n              },\n              dy: 20,\n              fill: hot ? BLUE : MUTED,\n              fontSize: 11,\n              fontWeight: hot ? 600 : 500,\n              id: hot ? \"x-hot\" : \"x-cold\",\n              key: \"key\",\n              text: \"label\",\n              x: \"i\",\n              y: () => MIN,\n            },\n          ),\n        ),\n      ],\n      scales: {\n        x: { scale: scaleLinear().domain([0, LAST]) },\n        y: { scale: scaleLinear().domain([MIN, MAX]) },\n      },\n    });\n  }, [at, picked, nearest]);\n\n  const left = (at / LAST) * 100;\n  const DiffIcon = diff >= 0 ? CircleArrowUp : CircleArrowDown;\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div>\n          <h3 className=\"flex items-center gap-2 text-[16px] font-semibold tracking-[-0.01em]\">\n            <ChartNoAxesColumnIncreasing\n              className=\"size-4.5\"\n              style={{ color: BLUE }}\n              strokeWidth={2.6}\n            />\n            Cash Flow\n          </h3>\n          <p className=\"mt-1 text-[12px]\" style={{ color: MUTED }}>\n            Track money moving in and out across all accounts\n          </p>\n        </div>\n        <MoreButton className=\"!rounded-[10px]\" />\n      </div>\n\n      <div className=\"mt-4 grid grid-cols-2 text-center\">\n        <div className=\"border-r\" style={{ borderColor: GRID }}>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Total cash flow\n          </p>\n          <Num value={14_345.09} className=\"mt-1 block text-[22px] font-bold tracking-[-0.02em]\" />\n        </div>\n        <div>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Last month\n          </p>\n          <Num\n            value={2456}\n            format={(n) => `+${usd(n)}`}\n            className=\"mt-1 block text-[22px] font-bold tracking-[-0.02em]\"\n            style={{ color: GREEN }}\n          />\n        </div>\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Cash flow this year against last year\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(nearestIndex(STOPS, Number(p.xValue)));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left > 50 ? Math.max(0, left - 49) : left + 3}\n            top={22}\n            align=\"left\"\n            className=\"!rounded-2xl !px-2.5 !py-2 text-[11px]\"\n          >\n            <p className=\"flex items-center gap-1.5\">\n              <span className=\"h-4 w-1 rounded-full\" style={{ backgroundColor: BLUE }} />\n              <Num value={current} className=\"font-semibold\" />\n              <span style={{ color: MUTED }}>{monthOf(at)}</span>\n            </p>\n            <p className=\"mt-1 flex items-center gap-1.5\">\n              <span className=\"h-4 w-1 rounded-full bg-[#d4d4d8]\" />\n              <Num value={previous} className=\"font-semibold\" />\n              <span style={{ color: MUTED }}>Last yr</span>\n            </p>\n            <p\n              className=\"mt-1.5 flex items-center gap-1 border-t border-dashed pt-1.5 font-semibold\"\n              style={{ borderColor: FAINT, color: diff >= 0 ? GREEN : RED }}\n            >\n              <DiffIcon className=\"size-3.5\" />\n              <Num value={Math.abs(diff)} />\n            </p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/cash-flow-area.tsx","target":"uicapsule/finance-charts/charts/cash-flow-area.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { Calendar } from \"lucide-react\";\n\nimport { Chip } from \"../lib/kit\";\n\nconst UsFlag = () => (\n  <span\n    aria-hidden\n    className=\"relative inline-block size-4 shrink-0 overflow-hidden rounded-full ring-1 ring-black/[0.06]\"\n    style={{\n      background: \"repeating-linear-gradient(180deg, #e0303a 0 2px, #ffffff 2px 4px)\",\n    }}\n  >\n    <span className=\"absolute top-0 left-0 h-[9px] w-[8px] bg-[#2b3f8f]\" />\n  </span>\n);\n\n/** The \"USD\" currency select shared by the cash-flow style headers. `compact`\n * keeps only the flag, for headers with a long title. */\nexport const UsdChip = ({ compact = false }: { compact?: boolean }) => (\n  <Chip chevron className={compact ? \"gap-1 px-2\" : undefined}>\n    <UsFlag />\n    {compact ? <span className=\"sr-only\">USD</span> : \"USD\"}\n  </Chip>\n);\n\n/** The \"Monthly\" / \"Weekly\" period select; `compact` drops the calendar glyph. */\nexport const PeriodChip = ({ label, compact = false }: { label: string; compact?: boolean }) => (\n  <Chip chevron icon={compact ? undefined : Calendar}>\n    {label}\n  </Chip>\n);\n","path":"/charts/cash-flow-daily-bar-chrome.tsx","target":"uicapsule/finance-charts/charts/cash-flow-daily-bar-chrome.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, RefreshCcw } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, uniform, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  CardHeader,\n  ChartSlot,\n  Caption,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { DASHED_GRID, GRID, GREEN, THEME } from \"../lib/tokens\";\nimport { PeriodChip, UsdChip } from \"./cash-flow-daily-bar-chrome\";\n\nconst DAYS = Array.from({ length: 17 }, (_, i) => `May ${i + 1}`);\nconst TOTALS = uniform(DAYS.length, 311, 11_500, 28_500);\nconst SHARES = uniform(DAYS.length, 977, 0.12, 0.62);\n\nconst ROWS = DAYS.map((day, i) => {\n  const total = Math.round(TOTALS[i] ?? 0);\n\n  return { day, flow: Math.round(total * (SHARES[i] ?? 0)), total };\n});\n\nconst LABELED = DAYS.filter((_, i) => i % 4 === 0);\nconst GRID_LINES = { ...DASHED_GRID, stroke: \"#e2e2e7\", strokeOpacity: 1 };\n\nconst MARGIN = { bottom: 30, left: 38, right: 0, top: 10 };\nconst HEIGHT = 210;\nconst TOP = 30_000;\n\nexport const CashFlowDailyBar = () => {\n  const [hi, pin] = useCycle(ROWS.length, 1700, 5);\n  const picked = ROWS[hi] ?? ROWS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          ruleY([0], { stroke: GRID, strokeOpacity: 1, strokeWidth: 1 }),\n          barY(ROWS, {\n            fill: (d) => (d.day === picked?.day ? \"#e6e6ea\" : \"#f1f1f3\"),\n            key: (d) => `${d.day}-total`,\n            radius: [7, 7, 0, 0],\n            x: \"day\",\n            y1: 0,\n            y2: \"total\",\n          }),\n          barY(ROWS, {\n            fill: (d) => (d.day === picked?.day ? \"#0f8a3a\" : GREEN),\n            key: (d) => `${d.day}-flow`,\n            radius: [7, 7, 0, 0],\n            x: \"day\",\n            y1: 0,\n            y2: \"flow\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === picked?.day ? 600 : 400),\n              },\n              ticks: { padding: 10, size: 0, values: LABELED },\n            },\n            scale: scaleBand<string>().domain(DAYS).paddingInner(0.3).paddingOuter(0),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: { format: (v) => compact(v), size: 0, values: [0, 10_000, 20_000, 30_000] },\n            },\n            grid: GRID_LINES,\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [picked],\n  );\n\n  const total = ROWS.reduce((s, r) => s + r.flow, 0) + 0.34;\n\n  return (\n    <Card>\n      <CardHeader\n        icon={RefreshCcw}\n        color={GREEN}\n        title=\"Cash flow\"\n        actions={\n          <>\n            <UsdChip />\n            <PeriodChip label=\"Monthly\" />\n          </>\n        }\n      />\n      <div className=\"mt-5 grid grid-cols-2 gap-3\">\n        <div>\n          <Caption>Total cash flow</Caption>\n          <Num value={total} className=\"mt-0.5 block text-[22px] font-bold tracking-[-0.03em]\" />\n        </div>\n        <div>\n          <Caption>Daily average</Caption>\n          <Num\n            value={total / ROWS.length}\n            className=\"mt-0.5 block text-[22px] font-bold tracking-[-0.03em]\"\n          />\n        </div>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Daily cash flow against total volume, May 1 to May 17\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(ROWS.findIndex((r) => r.day === p.xValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            dark\n            left={((hi + 0.5) / ROWS.length) * 100}\n            top={100 - ((picked?.total ?? 0) / TOP) * 100}\n            className=\"-translate-y-[calc(100%+8px)] text-center leading-tight\"\n          >\n            <span className=\"block text-[10px] text-white/60\">{picked?.day}</span>\n            <span className=\"font-semibold\">{usd(picked?.flow ?? 0, true)}</span>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <button\n        type=\"button\"\n        className=\"mt-4 inline-flex h-9 items-center gap-1.5 rounded-full border border-black/[0.08] px-3.5 text-[13px] font-medium text-[#3a3a42]\"\n      >\n        See insight <ArrowUpRight className=\"size-3.5\" />\n      </button>\n    </Card>\n  );\n};\n","path":"/charts/cash-flow-daily-bar.tsx","target":"uicapsule/finance-charts/charts/cash-flow-daily-bar.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, dot } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\n\nimport { compact, MONTHS, rng } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  CardHeader,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GRID } from \"../lib/tokens\";\n\nconst PAIRS = [\n  [13_500, 19_700],\n  [7400, 17_500],\n  [22_628.05, 27_874.93],\n  [7400, 12_800],\n  [15_600, 19_500],\n  [17_900, 13_500],\n] as const;\n\nconst SIDES = [\"out\", \"in\"] as const;\n\ntype Side = (typeof SIDES)[number];\n\ninterface Bar {\n  id: string;\n  m: number;\n  side: Side;\n  value: number;\n  x: number;\n}\n\nconst BARS: Bar[] = PAIRS.flatMap((pair, m) =>\n  SIDES.map((side, k) => ({\n    id: `${m}-${side}`,\n    m,\n    side,\n    value: pair[k] ?? 0,\n    x: m + (k === 0 ? -0.2 : 0.2),\n  })),\n);\n\nconst FLECKS = BARS.flatMap((b) => {\n  const r = rng(b.m * 7 + (b.side === \"in\" ? 3 : 1));\n\n  return Array.from({ length: 6 }, (_, k) => ({\n    bar: b.id,\n    id: `${b.id}-${k}`,\n    m: b.m,\n    r: 0.6 + r() * 1.1,\n    x: b.x + (r() - 0.5) * 0.16,\n    y: b.value * (0.06 + 0.88 * r()),\n  }));\n});\n\nconst PAINT: Record<Side, { fill: string; stroke: string; swatch: string }> = {\n  in: { fill: \"url(#cfm-in)\", stroke: \"#1d7cf2\", swatch: \"linear-gradient(#7cc4ff,#1d7cf2)\" },\n  out: { fill: \"url(#cfm-out)\", stroke: \"#9333ea\", swatch: \"linear-gradient(#d78bff,#9333ea)\" },\n};\n\nconst MAX = 30_000;\nconst TICKS = [0, 6000, 12_000, 18_000, 24_000, 30_000] as const;\nconst MARGIN = { bottom: 28, left: 0, right: 40, top: 8 };\nconst HEIGHT = 230;\nconst X0 = -0.5;\nconst X1 = 5.5;\n\nexport const CashFlowMonthlyBar = () => {\n  const [hi, pin] = useCycle(PAIRS.length, 2100, 2);\n  const pair = PAIRS[hi] ?? PAIRS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"cfm-idle\",\n            stops: [\n              { color: \"#f7f7f8\", offset: 0 },\n              { color: \"#dedee2\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"cfm-out\",\n            stops: [\n              { color: \"#a855f7\", offset: 0 },\n              { color: \"#e15cf6\", offset: 0.5 },\n              { color: \"#8b2fd6\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"cfm-in\",\n            stops: [\n              { color: \"#6aaefc\", offset: 0 },\n              { color: \"#2ad4f5\", offset: 0.5 },\n              { color: \"#1f7cf0\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"cfm-gloss\",\n            stops: [\n              { color: \"#ffffff\", offset: 0, opacity: 0.05 },\n              { color: \"#ffffff\", offset: 0.28, opacity: 0.4 },\n              { color: \"#ffffff\", offset: 0.62, opacity: 0.06 },\n              { color: \"#000000\", offset: 1, opacity: 0.06 },\n            ],\n            x1: 0,\n            x2: 1,\n          },\n        ],\n        margin: MARGIN,\n        marks: [\n          barY(BARS, {\n            fill: (b) => (b.m === hi ? PAINT[b.side].fill : \"url(#cfm-idle)\"),\n            key: \"id\",\n            radius: 5,\n            stroke: (b) => (b.m === hi ? PAINT[b.side].stroke : \"#e4e4e7\"),\n            strokeWidth: 1,\n            x: \"x\",\n            y1: 0,\n            y2: \"value\",\n          }),\n          barY(BARS, {\n            fill: \"url(#cfm-gloss)\",\n            fillOpacity: 1,\n            id: \"gloss\",\n            key: \"id\",\n            radius: 5,\n            x: \"x\",\n            y1: 0,\n            y2: \"value\",\n          }),\n          dot(\n            FLECKS.filter((f) => f.m === hi),\n            {\n              fill: \"#ffffff\",\n              fillOpacity: 0.75,\n              key: \"id\",\n              r: \"r\",\n              x: \"x\",\n              y: \"y\",\n            },\n          ),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: { stroke: GRID, strokeOpacity: 1 },\n              tickLabels: { fontSize: 11.5 },\n              ticks: {\n                format: (v) => MONTHS[Math.round(Number(v))] ?? \"\",\n                size: 0,\n                values: [0, 1, 2, 3, 4, 5],\n              },\n            },\n            scale: scaleLinear().domain([X0, X1]),\n          },\n          y: {\n            axis: {\n              line: { stroke: GRID, strokeOpacity: 1 },\n              tickLabels: { fontSize: 11.5 },\n              ticks: { format: (v) => compact(v), padding: 8, size: 0, values: [...TICKS] },\n            },\n            grid: { stroke: GRID, strokeOpacity: 1 },\n            scale: scaleLinear().domain([0, MAX]),\n            side: \"right\",\n          },\n        },\n        theme: { muted: \"#a1a1aa\" },\n      }),\n    [hi],\n  );\n\n  const flip = hi >= 4;\n  const left = ((hi + (flip ? -0.45 : 0.45) - X0) / (X1 - X0)) * 100;\n\n  return (\n    <Card>\n      <CardHeader\n        title=\"Cash Flow\"\n        subtitle=\"Track money moving in and out across all accounts\"\n        actions={<MoreButton className=\"!rounded-[10px]\" />}\n      />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Monthly money in and out\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(Math.round(Number(p.xValue)));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left}\n            top={100 - (Math.max(...pair) / MAX) * 100}\n            align={flip ? \"right\" : \"left\"}\n            className=\"!rounded-2xl !px-2.5 !py-2 text-[12.5px]\"\n          >\n            {[pair[1], pair[0]].map((v, k) => (\n              <p\n                key={SIDES[1 - k]}\n                className={`flex items-center gap-2 ${k === 1 ? \"mt-1.5 border-t border-[#dbe7fb] pt-1.5\" : \"\"}`}\n              >\n                <span\n                  className=\"h-4 w-1.5 rounded-full\"\n                  style={{ background: PAINT[SIDES[1 - k] ?? \"in\"].swatch }}\n                />\n                <Num value={v} className=\"font-medium\" />\n              </p>\n            ))}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/cash-flow-monthly-bar.tsx","target":"uicapsule/finance-charts/charts/cash-flow-monthly-bar.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, Settings } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, Caption, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, INK, MUTED, THEME } from \"../lib/tokens\";\n\nconst CATEGORIES = [\n  { color: \"#a43ff2\", label: \"Rent & Utilities\", pct: 32, ticks: 19 },\n  { color: \"#1f82ee\", label: \"Groceries\", pct: 24, ticks: 14 },\n  { color: \"#f7802a\", label: \"Subscription\", pct: 20, ticks: 12 },\n  { color: \"#1fae4f\", label: \"Saving account\", pct: 24, ticks: 14 },\n] as const;\n\nconst tint = (hex: string, t: number) => {\n  const n = Number.parseInt(hex.slice(1), 16);\n  const ch = [16, 8, 0].map((s) => Math.floor(n / 2 ** s) % 256);\n\n  return `rgb(${ch.map((c) => Math.round(c + (255 - c) * t)).join(\",\")})`;\n};\n\ninterface Slot {\n  id: string;\n  cat: number;\n  marker: boolean;\n  tier: number;\n}\n\nconst SLOTS: Slot[] = CATEGORIES.flatMap((c, cat) => [\n  { cat, id: `${cat}-m`, marker: true, tier: 0 },\n  ...Array.from({ length: c.ticks }, (_, i) => ({\n    cat,\n    id: `${cat}-${i}`,\n    marker: false,\n    tier: Math.min(2, Math.floor((i / c.ticks) * 3)),\n  })),\n]);\n\nconst TIER_MIX = [0.68, 0.38, 0] as const;\n\nconst HEIGHT = 140;\n\nconst Stat = ({ label, value, change }: { label: string; value: number; change: number }) => (\n  <div className=\"min-w-0\">\n    <Caption>{label}</Caption>\n    <Num value={value} className=\"mt-0.5 block text-[22px] font-bold tracking-[-0.03em]\" />\n    <p className=\"mt-1.5 flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n      <span\n        className=\"inline-flex items-center gap-1 rounded-full bg-[#e7f8ec] px-1.5 py-0.5 font-semibold\"\n        style={{ color: GREEN }}\n      >\n        <span\n          className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n          style={{ backgroundColor: GREEN }}\n        >\n          <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n        </span>\n        <Num value={change} format={(n) => `$${Math.round(n).toLocaleString(\"en-US\")}`} />\n      </span>\n      This month\n    </p>\n  </div>\n);\n\nexport const CategoryBreakdown = () => {\n  const [active, pin] = useCycle(CATEGORIES.length, 2200, 0);\n\n  const definition = useMemo(() => {\n    const color = (d: Slot) => {\n      const base = CATEGORIES[d.cat]?.color ?? INK;\n\n      if (d.marker) {\n        return tint(base, 0.7);\n      }\n\n      const mix = TIER_MIX[d.tier] ?? 0;\n\n      return tint(base, d.cat === active ? mix : 0.55 + mix * 0.45);\n    };\n\n    const labels = CATEGORIES.map((c, cat) => ({ ...c, cat, slot: `${cat}-m` }));\n\n    return defineChart({\n      focusRing: false,\n      guides: false,\n      margin: 0,\n      marks: [\n        barY(SLOTS, {\n          fill: color,\n          key: \"id\",\n          radius: 2,\n          x: \"id\",\n          y1: 0,\n          y2: (d) => {\n            if (d.marker) {\n              return 1;\n            }\n\n            return d.cat === active ? 0.64 : 0.56;\n          },\n        }),\n        text(labels, {\n          anchor: \"start\",\n          dx: 6,\n          fill: MUTED,\n          fontSize: 10.5,\n          key: (d) => `${d.cat}-label`,\n          text: \"label\",\n          x: \"slot\",\n          y: () => 0.9,\n        }),\n        text(labels, {\n          anchor: \"start\",\n          dx: 6,\n          fill: (d) => (d.cat === active ? INK : \"#6b6b73\"),\n          fontSize: 13,\n          fontWeight: 500,\n          key: (d) => `${d.cat}-pct`,\n          text: (d) => `${d.pct}%`,\n          x: \"slot\",\n          y: () => 0.76,\n        }),\n      ],\n      scales: {\n        x: {\n          scale: scaleBand<string>()\n            .domain(SLOTS.map((s) => s.id))\n            .paddingInner(0.42)\n            .paddingOuter(0),\n        },\n        y: { scale: scaleLinear().domain([0, 1]) },\n      },\n      theme: THEME,\n    });\n  }, [active]);\n\n  return (\n    <Card>\n      <div className=\"grid grid-cols-2 gap-3\">\n        <Stat label=\"Total revenue\" value={18_645.16} change={1637} />\n        <Stat label=\"Monthly expenses\" value={6364.81} change={343} />\n      </div>\n      <div className=\"mt-4 border-t border-black/[0.06] pt-4\">\n        <ChartSlot height={HEIGHT}>\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Monthly spending split by category\"\n              onFocusChange={(p) => {\n                if (p) {\n                  pin(Number(String(p.xValue).split(\"-\")[0]));\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n      </div>\n      <div className=\"mt-4 flex justify-end\">\n        <button\n          type=\"button\"\n          className=\"inline-flex h-9 items-center gap-1.5 rounded-full border border-black/[0.08] px-3.5 text-[13px] font-medium text-[#3a3a42]\"\n        >\n          <Settings className=\"size-4 text-[#8a8a93]\" />\n          Manage balance\n        </button>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/category-breakdown.tsx","target":"uicapsule/finance-charts/charts/category-breakdown.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, lineY, ruleX } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ChartPie, Clock } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, MONTHS, walk } from \"../lib/data\";\nimport { Bubble, Card, ChartSlot, IconTile, PlotOverlay, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID } from \"../lib/tokens\";\n\nconst ASSET = \"#16a34a\";\nconst LIABILITY = \"#ef4444\";\nconst LIABILITY_FILL = \"#fde4e4\";\n\nconst LAST = 75;\nconst RAW = walk(LAST + 1, 23, { drift: 2.6, start: 0, vol: 9 });\nconst RAW_MIN = Math.min(...RAW);\nconst RAW_MAX = Math.max(...RAW);\nconst ASSETS = RAW.map((v) => 40_000 + ((v - RAW_MIN) / (RAW_MAX - RAW_MIN)) * 210_000);\n\nconst LIABILITY_KNOTS = [\n  [0, 40_000],\n  [4, 52_000],\n  [9, 53_000],\n  [15, 50_000],\n  [20, 58_000],\n  [25, 56_000],\n  [31, 55_000],\n  [39, 60_000],\n  [47, 68_000],\n  [52, 70_000],\n  [56, 64_000],\n  [58, 65_000],\n  [61, 98_000],\n  [66, 110_000],\n  [69, 128_000],\n  [72, 175_000],\n  [75, 252_000],\n] as const;\n\nconst liabilityAt = (x: number) => {\n  for (let k = 1; k < LIABILITY_KNOTS.length; k += 1) {\n    const a = LIABILITY_KNOTS[k - 1];\n    const b = LIABILITY_KNOTS[k];\n\n    if (a && b && x <= b[0]) {\n      return a[1] + ((b[1] - a[1]) * (x - a[0])) / (b[0] - a[0]);\n    }\n  }\n\n  return 252_000;\n};\n\nconst KNOT_ROWS = LIABILITY_KNOTS.map(([i, liability]) => ({ i, liability }));\nconst ROWS = ASSETS.map((asset, i) => ({ asset, i, liability: liabilityAt(i) }));\n\nconst MONTH_X = [0, 12.5, 25, 37.5, 50, 62.5, 75] as const;\nconst TICKS = [50_000, 100_000, 150_000, 200_000, 250_000] as const;\nconst MIN = 38_000;\nconst MAX = 262_000;\nconst STOPS = [6, 19, 31, 44, 56, 68, 74] as const;\n\nconst MARGIN = { bottom: 28, left: 0, right: 46, top: 8 };\nconst HEIGHT = 240;\nconst smooth = d3Curve(curveMonotoneX);\n\nexport const CumulativeAssetsAndLiabilities = () => {\n  const [stop, pin] = useCycle(STOPS.length, 2000, 4);\n  const at = STOPS[stop] ?? 0;\n  const picked = ROWS[at] ?? ROWS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          areaY(KNOT_ROWS, {\n            curve: smooth,\n            fill: LIABILITY_FILL,\n            fillOpacity: 0.85,\n            x: \"i\",\n            y1: MIN,\n            y2: \"liability\",\n          }),\n          ruleX([at], { stroke: \"#a1a1aa\", strokeDasharray: \"3 3\", strokeOpacity: 0.7 }),\n          lineY(ROWS, {\n            id: \"glow\",\n            stroke: ASSET,\n            strokeOpacity: 0.16,\n            strokeWidth: 7,\n            x: \"i\",\n            y: \"asset\",\n          }),\n          lineY(ROWS, { stroke: ASSET, strokeWidth: 2.25, x: \"i\", y: \"asset\" }),\n          dot(picked ? [picked] : [], {\n            fill: LIABILITY,\n            key: () => \"liability\",\n            r: 4,\n            stroke: \"#ffffff\",\n            strokeWidth: 2,\n            x: \"i\",\n            y: \"liability\",\n          }),\n          dot(picked ? [picked] : [], {\n            fill: ASSET,\n            key: () => \"asset\",\n            r: 4.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 2,\n            x: \"i\",\n            y: \"asset\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                anchor: ({ index }) => {\n                  if (index === 0) {\n                    return \"start\";\n                  }\n\n                  return index === MONTH_X.length - 1 ? \"end\" : \"middle\";\n                },\n                fontSize: 11.5,\n              },\n              ticks: {\n                format: (v) => MONTHS[Math.round(Number(v) / 12.5)] ?? \"\",\n                size: 0,\n                values: [...MONTH_X],\n              },\n            },\n            scale: scaleLinear().domain([0, LAST]),\n          },\n          y: {\n            axis: {\n              line: { stroke: GRID, strokeOpacity: 1 },\n              tickLabels: { fontSize: 11.5 },\n              ticks: { format: (v) => compact(v), padding: 10, size: 0, values: [...TICKS] },\n            },\n            grid: { stroke: \"#e4e4e7\", strokeDasharray: \"4 4\", strokeOpacity: 1 },\n            scale: scaleLinear().domain([MIN, MAX]),\n            side: \"right\",\n          },\n        },\n        theme: { muted: \"#a1a1aa\" },\n      }),\n    [at, picked],\n  );\n\n  const left = (at / LAST) * 100;\n  const top = 100 - (((picked?.asset ?? MIN) - MIN) / (MAX - MIN)) * 100;\n\n  return (\n    <Card className=\"!bg-[#f4f4f6] !p-1.5\">\n      <div className=\"flex items-center justify-between gap-2 px-3 pt-2.5 pb-3\">\n        <div className=\"flex items-center gap-2.5\">\n          <IconTile icon={ChartPie} color=\"#3b82f6\" size={30} />\n          <h3 className=\"text-[14.5px] leading-tight font-semibold tracking-[-0.01em]\">\n            Cumulative Assets and Liabilities\n          </h3>\n        </div>\n        <span className=\"shrink-0 rounded-full bg-[#e8e8eb] px-2.5 py-1 text-[9.5px] font-medium tracking-wide text-[#55555e]\">\n          FINANCE OVERVIEW\n        </span>\n      </div>\n      <div className=\"rounded-[18px] bg-white p-4 ring-1 ring-black/[0.05]\">\n        <div className=\"flex items-center justify-between gap-2\">\n          <div className=\"flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-[#55555e]\">\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span\n                className=\"size-3 rounded-[4px] shadow-[0_1px_4px_rgba(22,163,74,0.5)]\"\n                style={{ backgroundColor: ASSET }}\n              />\n              Cumulative Assets\n            </span>\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span\n                className=\"size-3 rounded-[4px] shadow-[0_1px_4px_rgba(239,68,68,0.5)]\"\n                style={{ backgroundColor: LIABILITY }}\n              />\n              Cumulative Liabilities\n            </span>\n          </div>\n          <span\n            className=\"inline-flex shrink-0 items-center gap-1 rounded-full bg-[#e7f8ee] px-2 py-1 text-[11px] font-semibold\"\n            style={{ color: GREEN }}\n          >\n            <Clock className=\"size-3\" strokeWidth={2.6} /> YTD\n          </span>\n        </div>\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Cumulative assets and liabilities, year to date\"\n              onFocusChange={(p) => {\n                if (p) {\n                  const x = Number(p.xValue);\n                  let best = 0;\n\n                  for (const [k, s] of STOPS.entries()) {\n                    if (Math.abs(s - x) < Math.abs((STOPS[best] ?? 0) - x)) {\n                      best = k;\n                    }\n                  }\n\n                  pin(best);\n                }\n              }}\n            />\n          </div>\n          <PlotOverlay margin={MARGIN}>\n            <Bubble\n              left={left}\n              top={top}\n              align={left > 55 ? \"right\" : \"left\"}\n              dark\n              className={`text-[11px] ${top < 40 ? \"translate-y-3\" : \"-translate-y-[calc(100%+12px)]\"} ${left > 55 ? \"ml-2\" : \"-ml-2\"}`}\n            >\n              <p className=\"flex items-center gap-1.5\">\n                <span className=\"size-2 rounded-[3px]\" style={{ backgroundColor: ASSET }} />\n                Assets{\" \"}\n                <span className=\"ml-auto pl-2 font-semibold\">{compact(picked?.asset ?? 0)}</span>\n              </p>\n              <p className=\"flex items-center gap-1.5\">\n                <span className=\"size-2 rounded-[3px]\" style={{ backgroundColor: LIABILITY }} />\n                Liabilities{\" \"}\n                <span className=\"ml-auto pl-2 font-semibold\">\n                  {compact(picked?.liability ?? 0)}\n                </span>\n              </p>\n            </Bubble>\n          </PlotOverlay>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/cumulative-assets-and-liabilities.tsx","target":"uicapsule/finance-charts/charts/cumulative-assets-and-liabilities.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, ruleX } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\n\nimport { Bubble, Card, ChartSlot, PlotOverlay, renderer, useCycle } from \"../lib/kit\";\nimport {\n  ChannelRows,\n  SalesHeader,\n  SquareLegend,\n  X_DOMAIN,\n  clockLabel,\n  hourlyAxes,\n  valueAt,\n} from \"./total-sales-parts\";\n\nconst AMBER = \"#fbbf24\";\nconst AMBER_DEEP = \"#f59e0b\";\nconst GREY = \"#ebebee\";\n\nconst FIRST_TIME = [\n  [17.6, 0],\n  [18, 7.5],\n  [18.6, 6.5],\n  [19.2, 14.5],\n  [19.7, 18],\n  [20.2, 4.2],\n  [20.7, 11],\n  [21.1, 8.5],\n  [21.5, 13],\n  [22.1, 14.5],\n  [22.6, 9.2],\n  [23.1, 5.3],\n  [23.6, 2.6],\n  [24.5, 0.8],\n  [25.1, 0],\n  [26.4, 0],\n] as const;\n\nconst RETURNING = [\n  [17.6, 0],\n  [18, 2.6],\n  [18.8, 2.9],\n  [19.5, 13.5],\n  [20, 5],\n  [20.6, 3.6],\n  [21.2, 9.8],\n  [21.8, 4.6],\n  [22.7, 6.5],\n  [23.3, 1.8],\n  [23.8, 0],\n  [26.4, 0],\n] as const;\n\nconst GRID_H = [...new Set([...FIRST_TIME, ...RETURNING].map(([h]) => h))].toSorted(\n  (a, b) => a - b,\n);\n\nconst ROWS = GRID_H.map((h) => ({\n  first: valueAt(FIRST_TIME, h),\n  h,\n  returning: valueAt(RETURNING, h),\n}));\n\nconst STOPS = [19.5, 19.7, 21.2, 22.1, 22.7, 23.6, 18.4] as const;\nconst TICKS = [0, 10, 20, 30] as const;\nconst MAX = 30;\n\nconst CHANNELS = [\n  { change: 4.82, name: \"Online store\", value: 10.24 },\n  { change: 2.64, name: \"Facebook\", value: 6.37 },\n  { change: -1.64, name: \"Offline store\", value: 9.58 },\n] as const;\n\nconst MARGIN = { bottom: 28, left: 44, right: 4, top: 10 };\nconst HEIGHT = 210;\nconst pct = (n: number) => `${n.toFixed(2)}%`;\n\nexport const CustomerRate = () => {\n  const [stop, pin] = useCycle(STOPS.length, 1900);\n  const h = STOPS[stop] ?? 19.5;\n  const first = valueAt(FIRST_TIME, h);\n  const returning = valueAt(RETURNING, h);\n\n  const definition = useMemo(() => {\n    const axes = hourlyAxes(TICKS, (v) => `${v}%`);\n    const at = [{ first, h, returning }];\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        areaY(ROWS, { fill: GREY, fillOpacity: 1, x: \"h\", y1: 0, y2: \"first\" }),\n        areaY(ROWS, { fill: AMBER, fillOpacity: 1, x: \"h\", y1: 0, y2: \"returning\" }),\n        ruleX([h], { stroke: \"#71717a\", strokeDasharray: \"3 3\", strokeOpacity: 0.6 }),\n        dot(at, {\n          fill: \"#ffffff\",\n          key: () => \"first\",\n          r: 4,\n          stroke: \"#a1a1aa\",\n          strokeWidth: 2,\n          x: \"h\",\n          y: \"first\",\n        }),\n        dot(at, {\n          fill: \"#ffffff\",\n          key: () => \"returning\",\n          r: 4.5,\n          stroke: AMBER_DEEP,\n          strokeWidth: 2.5,\n          x: \"h\",\n          y: \"returning\",\n        }),\n      ],\n      scales: {\n        x: { ...axes.x, scale: scaleLinear().domain([...X_DOMAIN]) },\n        y: { ...axes.y, scale: scaleLinear().domain([0, MAX]) },\n      },\n      theme: { muted: \"#a1a1aa\" },\n    });\n  }, [h, first, returning]);\n\n  const left = ((h - X_DOMAIN[0]) / (X_DOMAIN[1] - X_DOMAIN[0])) * 100;\n\n  return (\n    <Card>\n      <SalesHeader label=\"Customer rate\" value={8.73} format={pct} change={2.51} />\n      <ChannelRows rows={CHANNELS} format={pct} />\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Returning and first-time customer rate by hour\"\n            onFocusChange={(p) => {\n              if (p) {\n                const x = Number(p.xValue);\n                let best = 0;\n\n                for (const [k, s] of STOPS.entries()) {\n                  if (Math.abs(s - x) < Math.abs((STOPS[best] ?? 0) - x)) {\n                    best = k;\n                  }\n                }\n\n                pin(best);\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left}\n            top={100 - (Math.max(first, returning) / MAX) * 100}\n            align={left > 60 ? \"right\" : \"left\"}\n            className={`-translate-y-[calc(100%+10px)] text-[11px] ${left > 60 ? \"\" : \"-ml-3\"}`}\n          >\n            <p className=\"font-semibold\">{clockLabel(h)}</p>\n            <p className=\"mt-0.5 flex items-center gap-1.5\">\n              <span className=\"size-2 rounded-[3px]\" style={{ backgroundColor: AMBER }} />\n              Returning <span className=\"ml-auto pl-2 font-semibold\">{pct(returning)}</span>\n            </p>\n            <p className=\"flex items-center gap-1.5\">\n              <span className=\"size-2 rounded-[3px] bg-[#d4d4d8]\" />\n              First time <span className=\"ml-auto pl-2 font-semibold\">{pct(first)}</span>\n            </p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <SquareLegend\n        items={[\n          { color: AMBER, label: \"Returning\" },\n          { color: GREY, label: \"First time\" },\n        ]}\n      />\n    </Card>\n  );\n};\n","path":"/charts/customer-rate.tsx","target":"uicapsule/finance-charts/charts/customer-rate.tsx","type":"registry:file"},{"content":"import type { ComponentType } from \"react\";\n\nexport interface ChartEntry {\n  id: string;\n  Chart: ComponentType;\n}\n","path":"/charts/entry.ts","target":"uicapsule/finance-charts/charts/entry.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, link } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, Diamond, Sparkles } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng, usd } from \"../lib/data\";\nimport { Card, ChartSlot, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { DASHED_GRID, GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst N = 49;\nconst UP = \"#1fa64a\";\nconst DOWN = \"#f0442c\";\nconst VOL_UP = \"#b8e6c6\";\nconst VOL_DOWN = \"#fbbdb3\";\n\ninterface Candle {\n  id: string;\n  i: number;\n  open: number;\n  close: number;\n  high: number;\n  low: number;\n  vol: number;\n  up: boolean;\n}\n\nconst candles = (seed: number, center: number) => {\n  const r = rng(seed);\n  const out: Candle[] = [];\n  let prev = center;\n\n  for (let i = 0; i < N; i += 1) {\n    const open = Math.min(19_000, Math.max(6500, prev + (r() - 0.5) * 2200));\n    const pull = (center - open) * 0.25;\n    let close = Math.min(20_000, Math.max(5500, open + pull + (r() - 0.5) * 7600));\n\n    if (Math.abs(close - open) < 300) {\n      close = open + (r() > 0.5 ? 300 : -300);\n    }\n\n    const high = Math.max(open, close) + r() * 1300;\n    const low = Math.min(open, close) - r() * 1300;\n    out.push({\n      close,\n      high,\n      i,\n      id: `c${i}`,\n      low,\n      open,\n      up: close >= open,\n      vol: 0.4 + r() * r() * 2,\n    });\n    prev = close;\n  }\n\n  return out;\n};\n\nconst RANGES = [\n  {\n    change: 339,\n    data: candles(31, 13_000),\n    labels: [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"],\n    value: 10_974.58,\n  },\n  {\n    change: 912,\n    data: candles(58, 12_200),\n    labels: [\"1\", \"5\", \"9\", \"13\", \"17\", \"21\", \"25\"],\n    value: 10_412.2,\n  },\n  {\n    change: 2764,\n    data: candles(97, 11_000),\n    labels: [\"Jan\", \"Feb\", \"Apr\", \"Jun\", \"Aug\", \"Oct\", \"Dec\"],\n    value: 8240.67,\n  },\n] as const;\n\nconst MARGIN = { bottom: 28, left: 0, right: 40, top: 8 };\nconst HEIGHT = 250;\n\nconst kFormat = (v: number) => (v === 0 ? \"$0\" : `$${v / 1000}K`);\n\nconst Stat = ({\n  color,\n  label,\n  value,\n  down,\n}: {\n  color: string;\n  label: string;\n  value: string;\n  down?: boolean;\n}) => (\n  <p className=\"flex items-center gap-1.5 whitespace-nowrap\">\n    <span className=\"size-2 rounded-[2px]\" style={{ backgroundColor: color }} />\n    <span style={{ color: MUTED }}>{label}</span>\n    <span\n      className=\"text-[12px] font-medium normal-case\"\n      style={{ color: down ? DOWN : \"#0b0b0f\" }}\n    >\n      {value}\n    </span>\n  </p>\n);\n\nexport const Ethereum = () => {\n  const [range, pin] = useCycle(RANGES.length, 3600);\n  const current = RANGES[range] ?? RANGES[0];\n  const rows = current.data;\n\n  const definition = useMemo(() => {\n    const maxVol = Math.max(...rows.map((d) => d.vol));\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        barY(rows, {\n          fill: (d) => (d.up ? VOL_UP : VOL_DOWN),\n          id: \"volume\",\n          key: \"id\",\n          maxThickness: 5,\n          x: \"i\",\n          y: \"vol\",\n          yScale: \"vol\",\n        }),\n        link(rows, {\n          id: \"wicks\",\n          key: \"id\",\n          stroke: (d) => (d.up ? UP : DOWN),\n          strokeWidth: 1.1,\n          x1: \"i\",\n          x2: \"i\",\n          y1: \"low\",\n          y2: \"high\",\n        }),\n        barY(rows, {\n          fill: (d) => (d.up ? UP : DOWN),\n          id: \"bodies\",\n          key: \"id\",\n          maxThickness: 4.5,\n          radius: 1,\n          x: \"i\",\n          y1: \"open\",\n          y2: \"close\",\n        }),\n      ],\n      scales: {\n        vol: {\n          axis: false,\n          channel: \"y\",\n          scale: scaleLinear().domain([0, maxVol * 5.2]),\n        },\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (v: number) => current.labels[Math.round((v - 3) / 7)] ?? \"\",\n              padding: 8,\n              size: 0,\n              values: current.labels.map((_, k) => k * 7 + 3),\n            },\n          },\n          scale: scaleLinear().domain([-0.8, N - 0.2]),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: kFormat,\n              padding: 6,\n              size: 0,\n              values: [0, 5000, 10_000, 15_000, 20_000, 25_000],\n            },\n          },\n          grid: DASHED_GRID,\n          scale: scaleLinear().domain([0, 25_000]),\n          side: \"right\",\n        },\n      },\n      theme: THEME,\n    });\n  }, [rows, current]);\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between\">\n        <div className=\"flex items-center gap-2.5\">\n          <span\n            className=\"inline-flex size-8 items-center justify-center rounded-full\"\n            style={{ background: \"linear-gradient(160deg, #8ea2f5, #5a6fe0)\" }}\n          >\n            <Diamond className=\"size-4 text-white\" strokeWidth={2.4} />\n          </span>\n          <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Ethereum</h3>\n        </div>\n        <button\n          type=\"button\"\n          aria-label=\"Insights\"\n          className=\"inline-flex size-8 items-center justify-center rounded-full border border-black/[0.08]\"\n        >\n          <Sparkles className=\"size-4 text-[#5b5ef0]\" />\n        </button>\n      </div>\n      <div className=\"mt-3 flex items-center justify-between gap-2\">\n        <div className=\"flex items-center gap-2\">\n          <Num value={current.value} className=\"text-[26px] font-bold tracking-[-0.03em]\" />\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[12px] font-medium\"\n            style={{ backgroundColor: \"#e3f6e9\", color: GREEN }}\n          >\n            <span\n              className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n            </span>\n            <Num value={current.change} format={(n) => usd(n, true)} />\n          </span>\n        </div>\n        <Segmented options={[\"W\", \"M\", \"Y\"]} value={range} onChange={pin} size=\"sm\" />\n      </div>\n      <div className=\"mt-3 grid grid-cols-[1fr_auto] gap-x-3 gap-y-1.5 text-[10px] tracking-[0.02em] uppercase\">\n        <Stat color=\"#a23cf0\" label=\"NAV:\" value=\"$11.0K\" />\n        <Stat color=\"#3d5af1\" label=\"Market price:\" value=\"$11.0K\" />\n        <Stat color=\"#a23cf0\" label=\"NAV change:\" value=\"-$836.5\" down />\n        <Stat color=\"#3d5af1\" label=\"Mkt price change:\" value=\"-$847.5\" down />\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel=\"Ethereum candlesticks with volume\"\n        />\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/ethereum.tsx","target":"uicapsule/finance-charts/charts/ethereum.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { pie, polar, radialArc, radialGrid, radialRule } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst RANGES = [\"Week\", \"Month\", \"Year\"] as const;\n\nconst CATEGORIES = [\n  { color: \"#f7863a\", id: \"Debt\" },\n  { color: \"#22b25a\", id: \"Investment\" },\n  { color: \"#fbcd66\", id: \"Asset\" },\n] as const;\n\ninterface Period {\n  values: [number, number, number];\n  budget: number;\n  change: number;\n}\n\nconst PERIODS: Period[] = [\n  { budget: 12_600, change: 4.52, values: [2033.29, 3168.13, 3671.74] },\n  { budget: 41_000, change: 2.81, values: [9120.4, 11_240.95, 8870.22] },\n  { budget: 420_000, change: 6.07, values: [86_510.18, 131_302.4, 98_215.63] },\n];\n\nconst ZERO: Period[\"values\"] = [0, 0, 0];\nconst HEIGHT = 230;\nconst INNER = 0.68;\nconst TAU = Math.PI * 2;\nconst HATCH = Array.from({ length: 120 }, (_, i) => (i / 120) * TAU);\n\nexport const Expenses = () => {\n  const [range, pin] = useCycle(RANGES.length, 3000);\n  const period = PERIODS[range] ?? PERIODS[0];\n  const values = period?.values ?? ZERO;\n  const total = values.reduce((s, v) => s + v, 0);\n  const budget = period?.budget ?? total;\n\n  const definition = useMemo(() => {\n    const rows = [\n      ...CATEGORIES.map((c, i) => ({ id: c.id, value: values[i] ?? 0 })),\n      { id: \"rest\", value: Math.max(0, budget - total) },\n    ];\n\n    const slices = pie(rows, { gapAngle: 0.025, value: \"value\" });\n    const rest = slices.find((s) => s.id === \"rest\");\n\n    const open = HATCH.filter(\n      (a) => rest && a > rest.startAngle + 0.03 && a < rest.endAngle - 0.03,\n    );\n\n    return defineChart({\n      color: {\n        domain: CATEGORIES.map((c) => c.id),\n        range: CATEGORIES.map((c) => c.color),\n      },\n      guides: false,\n      margin: 0,\n      marks: [\n        polar({\n          guides: [\n            radialGrid({\n              stroke: \"#f7863a\",\n              strokeOpacity: 0.55,\n              strokeWidth: 1,\n              values: [INNER, 1],\n            }),\n          ],\n          inset: 4,\n          marks: [\n            radialRule(\n              open.map((a) => ({ a })),\n              {\n                angle: \"a\",\n                key: \"a\",\n                radius1: INNER + 0.05,\n                radius2: 0.97,\n                stroke: \"#fde3d1\",\n                strokeWidth: 2.2,\n              },\n            ),\n            radialArc(\n              slices.filter((s) => s.id !== \"rest\"),\n              {\n                color: \"id\",\n                cornerRadius: 7,\n                innerRadius: ({ radius }) => radius * INNER,\n                key: \"id\",\n                outerRadius: ({ radius }) => radius,\n                stroke: \"#ffffff\",\n                strokeOpacity: 0.35,\n                strokeWidth: 1,\n              },\n            ),\n          ],\n          scales: {\n            angle: { scale: scaleLinear().domain([0, TAU]) },\n            radius: { scale: scaleLinear().domain([0, 1]) },\n          },\n        }),\n      ],\n      scales: { x: null, y: null },\n      theme: THEME,\n    });\n  }, [values, budget, total]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Expenses</h3>\n        <MoreButton />\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: MUTED }}>\n        Total Expenses\n      </p>\n      <div className=\"flex flex-wrap items-center gap-2\">\n        <Num value={total} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n        <span className=\"flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-semibold\"\n            style={{ color: GREEN }}\n          >\n            <span\n              className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n            </span>\n            <Num value={period?.change ?? 0} format={(n) => `${n.toFixed(2)}%`} />\n          </span>\n          vs last {RANGES[range]?.toLowerCase()}\n        </span>\n      </div>\n      <Segmented options={RANGES} value={range} onChange={pin} className=\"mt-4\" />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel=\"Expenses by category against budget\"\n        />\n      </ChartSlot>\n      <ul className=\"mt-4 flex flex-col gap-2\">\n        {CATEGORIES.map((c, i) => (\n          <li\n            key={c.id}\n            className=\"flex items-center gap-2 rounded-xl border bg-[#f7f7f8] px-3 py-2.5 text-[13px]\"\n            style={{ borderColor: GRID }}\n          >\n            <span className=\"size-2.5 rounded-full\" style={{ backgroundColor: c.color }} />\n            <span className=\"flex-1 text-[#3a3a42]\">{c.id}</span>\n            <Num value={values[i] ?? 0} format={(n) => usd(n)} className=\"font-medium\" />\n          </li>\n        ))}\n      </ul>\n    </Card>\n  );\n};\n","path":"/charts/expenses.tsx","target":"uicapsule/finance-charts/charts/expenses.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, tickY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { CalendarDays } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  MoreButton,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { DASHED_GRID, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst INCOME = [4080, 4700, 5380, 5102.87, 4980, 4890, 5190, 5510, 5900, 5080, 4720, 4220] as const;\n\nconst EXPENSES = [\n  3580, 3200, 2780, 4151.99, 3060, 3450, 2560, 3850, 4480, 3400, 3700, 2150,\n] as const;\n\nconst FULL = [\n  \"January\",\n  \"February\",\n  \"March\",\n  \"April\",\n  \"May\",\n  \"June\",\n  \"July\",\n  \"August\",\n  \"September\",\n  \"October\",\n  \"November\",\n  \"December\",\n] as const;\n\nconst rows = MONTHS.map((m, i) => ({\n  expenses: EXPENSES[i] ?? 0,\n  income: INCOME[i] ?? 0,\n  m,\n}));\n\nconst MARGIN = { bottom: 26, left: 44, right: 0, top: 8 };\nconst HEIGHT = 250;\nconst TOP = 7000;\nconst PAD = 0.16;\n\nconst bandFrac = (i: number, at: number) => (i + at * (1 - PAD)) / (MONTHS.length - PAD);\n\nconst Pill = ({ hot }: { hot?: boolean }) => (\n  <span\n    className=\"inline-block h-3.5 w-1.5 rounded-full\"\n    style={{\n      background: hot\n        ? \"linear-gradient(180deg, #fdba74, #ea580c)\"\n        : \"linear-gradient(180deg, #f4f4f6, #d4d4d8)\",\n      boxShadow: \"inset 0 0 0 0.5px rgba(0,0,0,0.08)\",\n    }}\n  />\n);\n\nexport const FinanceAnalytics = () => {\n  const [hi, pin] = useCycle(MONTHS.length, 2000, 3);\n  const picked = rows[hi] ?? rows[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"fa-glow\",\n            stops: [\n              { color: \"#fdba74\", offset: 0, opacity: 0.95 },\n              { color: \"#fed7aa\", offset: 0.45, opacity: 0.6 },\n              { color: \"#ffedd5\", offset: 1, opacity: 0 },\n            ],\n            x1: 0,\n            x2: 0,\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        margin: MARGIN,\n        marks: [\n          barY([{ id: \"glow\", m: picked?.m ?? \"Jan\", v: picked?.income ?? 0 }], {\n            fill: \"url(#fa-glow)\",\n            id: \"glow\",\n            key: \"id\",\n            x: \"m\",\n            y: \"v\",\n          }),\n          tickY(rows, {\n            id: \"expenses\",\n            key: \"m\",\n            stroke: (d) => (d.m === picked?.m ? \"#d4d4d8\" : \"#e8e8ec\"),\n            strokeWidth: 4,\n            x: \"m\",\n            y: \"expenses\",\n          }),\n          tickY(rows, {\n            id: \"income\",\n            key: \"m\",\n            stroke: (d) => (d.m === picked?.m ? ORANGE : \"#fcd3b6\"),\n            strokeWidth: 4,\n            x: \"m\",\n            y: \"income\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 10,\n                fontWeight: (c) => (c.value === picked?.m ? 600 : 400),\n                thin: false,\n              },\n              ticks: { padding: 8, size: 0 },\n            },\n            scale: scaleBand<string>()\n              .domain([...MONTHS])\n              .paddingInner(PAD)\n              .paddingOuter(0),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v: number) => `$${v}`,\n                padding: 8,\n                size: 0,\n                values: [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000],\n              },\n            },\n            grid: DASHED_GRID,\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [picked],\n  );\n\n  const right = hi < 5;\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Finance Analytics</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n            Track recurring income and expenses.\n          </p>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            Yearly\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <div className=\"mt-3 flex items-center gap-3 text-[12px] text-[#3a3a42]\">\n        <span className=\"inline-flex items-center gap-1.5\">\n          <Pill hot />\n          Income\n        </span>\n        <span className=\"inline-flex items-center gap-1.5\">\n          <Pill />\n          Expenses\n        </span>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-2\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Monthly income and expenses\"\n            onFocusChange={(p) => {\n              if (p) {\n                const i = rows.findIndex((r) => r.m === p.xValue);\n\n                if (i !== -1) {\n                  pin(i);\n                }\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={bandFrac(hi, right ? 1 : 0) * 100}\n            top={100 - ((picked?.income ?? 0) / TOP) * 100}\n            align={right ? \"left\" : \"right\"}\n            className={`${right ? \"ml-1.5\" : \"-ml-1.5\"} -mt-4 !rounded-[12px] !p-0 text-[11px]`}\n          >\n            <p className=\"border-b border-black/[0.06] px-2.5 py-1.5 font-medium text-[#3a3a42]\">\n              {`${FULL[hi] ?? \"\"} 2026`}\n            </p>\n            <div className=\"space-y-1 px-2.5 py-1.5\">\n              <div className=\"flex items-center justify-between gap-4\">\n                <span className=\"inline-flex items-center gap-1.5\" style={{ color: MUTED }}>\n                  <Pill hot /> Income\n                </span>\n                <span className=\"text-[13px] font-semibold tabular-nums\">\n                  {usd(picked?.income ?? 0)}\n                </span>\n              </div>\n              <div className=\"flex items-center justify-between gap-4\">\n                <span className=\"inline-flex items-center gap-1.5\" style={{ color: MUTED }}>\n                  <Pill /> Expenses\n                </span>\n                <span className=\"text-[13px] font-semibold tabular-nums\">\n                  {usd(picked?.expenses ?? 0)}\n                </span>\n              </div>\n            </div>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/finance-analytics.tsx","target":"uicapsule/finance-charts/charts/finance-analytics.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, lineY, ruleX, ruleY } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ArrowUp, Settings } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS, rng, usd, WEEKDAYS } from \"../lib/data\";\nimport { Card, ChartSlot, Caption, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst LINE = \"#a034f0\";\nconst N = 85;\nconst HEIGHT = 210;\nconst MARGIN = { bottom: 26, left: 0, right: 8, top: 8 };\n\nconst SLOTS = Array.from({ length: 7 }, (_, i) => 6 + i * 12);\n\ninterface Range {\n  name: string;\n  labels: readonly string[];\n  anchors: [number, number][];\n  seed: number;\n  delta: number;\n  pct: number;\n}\n\nconst RANGES: Range[] = [\n  {\n    anchors: [\n      [0, 46],\n      [6, 41],\n      [14, 41],\n      [18, 50],\n      [30, 46],\n      [36, 53],\n      [42, 64],\n      [48, 61],\n      [54, 75],\n      [60, 79],\n      [66, 81],\n      [72, 80],\n      [84, 83],\n    ],\n    delta: 1083.47,\n    labels: WEEKDAYS,\n    name: \"Week\",\n    pct: 4.82,\n    seed: 7,\n  },\n  {\n    anchors: [\n      [0, 34],\n      [10, 40],\n      [20, 37],\n      [30, 52],\n      [40, 48],\n      [50, 62],\n      [58, 57],\n      [68, 70],\n      [76, 74],\n      [84, 85],\n    ],\n    delta: 2316.9,\n    labels: [\"1\", \"5\", \"10\", \"15\", \"20\", \"25\", \"30\"],\n    name: \"Month\",\n    pct: 10.91,\n    seed: 19,\n  },\n  {\n    anchors: [\n      [0, 22],\n      [12, 30],\n      [24, 28],\n      [36, 44],\n      [48, 52],\n      [56, 49],\n      [66, 66],\n      [76, 72],\n      [84, 86],\n    ],\n    delta: 6904.12,\n    labels: MONTHS.filter((_, i) => i % 2 === 0),\n    name: \"Year\",\n    pct: 41.44,\n    seed: 23,\n  },\n];\n\nconst series = (range: Range) => {\n  const r = rng(range.seed);\n  const { anchors } = range;\n\n  return Array.from({ length: N }, (_, i) => {\n    const k = anchors.findIndex(([x]) => x >= i);\n    const [x0, y0] = anchors[Math.max(0, k - 1)] ?? [0, 0];\n    const [x1, y1] = anchors[Math.max(0, k)] ?? [N, 0];\n    const t = x1 === x0 ? 0 : (i - x0) / (x1 - x0);\n    const flat = y0 === y1;\n\n    return { i, value: y0 + t * (y1 - y0) + (flat ? 0 : (r() - 0.5) * 5) };\n  });\n};\n\nconst DATA = RANGES.map(series);\n\nexport const FinanceOverviewArea = () => {\n  const [range, pin] = useCycle(RANGES.length, 3400);\n  const meta = RANGES[range] ?? RANGES[0];\n\n  const definition = useMemo(() => {\n    const rows = DATA[range] ?? [];\n    const last = rows.at(-1);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"foa-fill\",\n          stops: [\n            { color: LINE, offset: 0, opacity: 0.32 },\n            { color: LINE, offset: 1, opacity: 0.02 },\n          ],\n          x1: 0,\n          x2: 0,\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      margin: MARGIN,\n      marks: [\n        ruleX(SLOTS, {\n          stroke: \"#d4d4da\",\n          strokeDasharray: \"5 5\",\n          strokeOpacity: 1,\n          strokeWidth: 1,\n        }),\n        ruleY([0], { stroke: \"#e2e2e6\", strokeOpacity: 1, strokeWidth: 1.5 }),\n        areaY(rows, {\n          curve: d3Curve(curveMonotoneX),\n          fill: \"url(#foa-fill)\",\n          fillOpacity: 1,\n          key: \"i\",\n          x: \"i\",\n          y1: 0,\n          y2: \"value\",\n        }),\n        lineY(rows, {\n          curve: d3Curve(curveMonotoneX),\n          key: \"i\",\n          stroke: LINE,\n          strokeWidth: 2.5,\n          x: \"i\",\n          y: \"value\",\n        }),\n        dot(last ? [last] : [], {\n          fill: LINE,\n          key: () => \"end\",\n          r: 4.5,\n          stroke: \"#ffffff\",\n          strokeWidth: 2,\n          x: \"i\",\n          y: \"value\",\n        }),\n      ],\n      motion: { path: \"morph\" },\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (v: number) => meta?.labels[SLOTS.indexOf(v)] ?? \"\",\n              size: 0,\n              values: SLOTS,\n            },\n          },\n          scale: scaleLinear().domain([0, N - 1]),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, 100]) },\n      },\n      theme: THEME,\n    });\n  }, [range, meta]);\n\n  return (\n    <Card\n      style={{\n        backgroundImage:\n          \"radial-gradient(120% 70% at 105% -8%, rgba(168,85,247,0.5), rgba(196,140,255,0.22) 38%, rgba(255,255,255,0) 66%)\",\n      }}\n    >\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Finance Overview</h3>\n        <button\n          type=\"button\"\n          aria-label=\"Settings\"\n          className=\"inline-flex size-9 items-center justify-center rounded-[12px] bg-white/45 text-[#a034f0] shadow-[inset_0_1px_0_rgba(255,255,255,0.8),0_4px_12px_-6px_rgba(124,58,237,0.5)] ring-1 ring-white/70 backdrop-blur\"\n        >\n          <Settings className=\"size-4\" strokeWidth={2.4} />\n        </button>\n      </div>\n      <div className=\"mt-4 flex items-center gap-1.5 text-[11.5px] whitespace-nowrap\">\n        <span style={{ color: MUTED }}>Metric Category</span>\n        <span className=\"rounded-full bg-[#dcfce7] px-2 py-1 font-medium text-[#16a34a]\">\n          All Investment\n        </span>\n        <span className=\"rounded-full bg-[#f3e8ff] px-2 py-1 font-medium text-[#a034f0]\">\n          Total portfolio value\n        </span>\n      </div>\n      <Segmented\n        options={RANGES.map((r) => r.name)}\n        value={range}\n        onChange={pin}\n        className=\"mt-4\"\n      />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel={`Total portfolio value over the ${meta?.name.toLowerCase()}`}\n        />\n      </ChartSlot>\n      <div className=\"mt-3 flex items-end justify-between gap-3\">\n        <div>\n          <Caption info className=\"!text-[13px]\">\n            Total portfolio value\n          </Caption>\n          <Num value={23_563.01} className=\"mt-1 block text-[30px] font-bold tracking-[-0.03em]\" />\n          <Num\n            value={meta?.delta ?? 0}\n            format={(n) => `+${usd(n)}`}\n            className=\"mt-1 inline-block rounded-full bg-[#dcfce7] px-2 py-0.5 text-[12px] font-semibold text-[#16a34a]\"\n          />\n        </div>\n        <div className=\"pb-0.5 text-right\">\n          <p\n            className=\"inline-flex items-center gap-1.5 text-[20px] font-bold tracking-[-0.02em]\"\n            style={{ color: GREEN }}\n          >\n            <span\n              className=\"inline-flex size-5 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-3.5\" strokeWidth={3} />\n            </span>\n            <Num value={meta?.pct ?? 0} format={(n) => `${n.toFixed(2)}%`} />\n          </p>\n          <p className=\"text-[11px]\" style={{ color: MUTED }}>\n            Vs Previous period\n          </p>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/finance-overview-area.tsx","target":"uicapsule/finance-charts/charts/finance-overview-area.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barX, barY, defineChart, ruleX, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ChartColumn, DollarSign, ShoppingBag } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { uniform, usd } from \"../lib/data\";\nimport {\n  CardHeader,\n  Card,\n  ChartSlot,\n  Delta,\n  Num,\n  Segmented,\n  muted,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN, INK, ORANGE } from \"../lib/tokens\";\n\nconst BARS = 20;\nconst GAP = 3;\nconst HEIGHT = 196;\nconst RANGE_HEIGHT = 16;\nconst PEACH = \"#fdd5bb\";\n\ninterface Period {\n  label: string;\n  today: number[];\n  yesterday: number[];\n  totals: [number, number];\n  deltas: [number, number];\n  low: number;\n  high: number;\n  rows: { yesterday: string; today: string; delta: number }[];\n}\n\nconst DAY: Period = {\n  deltas: [11.19, 2.43],\n  high: 165.81,\n  label: \"Day\",\n  low: 57.11,\n  rows: [\n    { delta: 11.19, today: \"$2,747\", yesterday: \"$2,471\" },\n    { delta: -2.21, today: \"$33.10\", yesterday: \"$33.84\" },\n    { delta: 13.7, today: \"83\", yesterday: \"73\" },\n  ],\n  today: uniform(BARS, 11, 38, 100),\n  totals: [2747, 2471],\n  yesterday: uniform(BARS, 12, 28, 92),\n};\n\nconst PERIODS: Period[] = [\n  DAY,\n  {\n    deltas: [8.42, 5.1],\n    high: 192.4,\n    label: \"Week\",\n    low: 48.2,\n    rows: [\n      { delta: 8.42, today: \"$18,904\", yesterday: \"$17,436\" },\n      { delta: 1.64, today: \"$34.02\", yesterday: \"$33.47\" },\n      { delta: 6.8, today: \"556\", yesterday: \"521\" },\n    ],\n    today: uniform(BARS, 21, 30, 100),\n    totals: [18_904, 17_436],\n    yesterday: uniform(BARS, 22, 30, 96),\n  },\n  {\n    deltas: [14.06, 3.92],\n    high: 214.6,\n    label: \"Month\",\n    low: 41.75,\n    rows: [\n      { delta: 14.06, today: \"$80,218\", yesterday: \"$70,331\" },\n      { delta: -0.88, today: \"$32.71\", yesterday: \"$33.00\" },\n      { delta: 15.2, today: \"2,452\", yesterday: \"2,128\" },\n    ],\n    today: uniform(BARS, 31, 34, 100),\n    totals: [80_218, 70_331],\n    yesterday: uniform(BARS, 32, 26, 90),\n  },\n];\n\nconst METRICS: { label: string; icon: LucideIcon; color: string; tint: string }[] = [\n  { color: BLUE, icon: DollarSign, label: \"Total Revenue\", tint: \"#e8f1fe\" },\n  { color: ORANGE, icon: ChartColumn, label: \"Avg. order value\", tint: \"#fff1e6\" },\n  { color: GREEN, icon: ShoppingBag, label: \"Transactions\", tint: \"#e7f7ed\" },\n];\n\nconst hours = Array.from({ length: BARS }, (_, i) => i);\n\nexport const FinanceOverviewDivergingBar = () => {\n  const [period, pinPeriod] = useCycle(PERIODS.length, 7200);\n  const [hi, pin] = useCycle(BARS, 900, 12);\n  const data = PERIODS[period] ?? DAY;\n  const { today, yesterday, low, high } = data;\n\n  const definition = useMemo(() => {\n    const up = hours.map((h) => ({ h, v: today[h] ?? 0 }));\n    const down = hours.map((h) => ({ h, v: -(yesterday[h] ?? 0) }));\n    const fill = (d: { h: number }) => (d.h === hi ? \"url(#fodb-hot)\" : PEACH);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"fodb-hot\",\n          stops: [\n            { color: \"#fb923c\", offset: 0 },\n            { color: \"#f97316\", offset: 0.5 },\n            { color: \"#ea580c\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: 0,\n      marks: [\n        ruleY([0], { stroke: PEACH, strokeOpacity: 0.7, strokeWidth: 2 }),\n        barY(up, {\n          fill,\n          id: \"today\",\n          key: \"h\",\n          radius: [5, 5, 0, 0],\n          x: \"h\",\n          y1: GAP,\n          y2: \"v\",\n        }),\n        barY(down, {\n          fill,\n          id: \"yesterday\",\n          key: \"h\",\n          radius: [0, 0, 5, 5],\n          x: \"h\",\n          y1: -GAP,\n          y2: \"v\",\n        }),\n      ],\n      scales: {\n        x: {\n          axis: false,\n          scale: scaleBand<number>().domain(hours).paddingInner(0.32).paddingOuter(0),\n        },\n        y: { axis: false, scale: scaleLinear().domain([-112, 112]) },\n      },\n    });\n  }, [today, yesterday, hi]);\n\n  const price = low + ((today[hi] ?? 0) / 100) * (high - low);\n  const t = (price - low) / (high - low);\n\n  const rangeDef = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"fodb-range\",\n            stops: [\n              { color: ORANGE, offset: 0, opacity: 0.05 },\n              { color: ORANGE, offset: 1, opacity: 0.95 },\n            ],\n            x1: 0,\n            x2: 1,\n          },\n        ],\n        guides: false,\n        margin: { bottom: 0, left: 0, right: 4, top: 0 },\n        marks: [\n          barX(\n            [\n              { id: \"a\", x1: 0, x2: 0.33 },\n              { id: \"b\", x1: 0.335, x2: 1 },\n            ],\n            { fill: \"#f3f3f5\", key: \"id\", radius: 4, x1: \"x1\", x2: \"x2\", y: () => \"r\" },\n          ),\n          barX([{ id: \"fill\", x1: 0.335, x2: t }], {\n            fill: \"url(#fodb-range)\",\n            key: \"id\",\n            radius: 4,\n            x1: \"x1\",\n            x2: \"x2\",\n            y: () => \"r\",\n          }),\n          ruleX([t], { stroke: INK, strokeOpacity: 1, strokeWidth: 2 }),\n        ],\n        scales: {\n          x: { axis: false, scale: scaleLinear().domain([0, 1]) },\n          y: { axis: false, scale: scaleBand<string>().domain([\"r\"]).padding(0) },\n        },\n      }),\n    [t],\n  );\n\n  return (\n    <Card>\n      <CardHeader\n        title=\"Finance Overview\"\n        subtitle=\"Track your Finance\"\n        actions={\n          <Segmented\n            options={PERIODS.map((p) => p.label)}\n            value={period}\n            onChange={pinPeriod}\n            size=\"sm\"\n          />\n        }\n      />\n      <div className=\"mt-5 flex gap-3\">\n        <div className=\"flex w-[92px] shrink-0 flex-col justify-between py-1\">\n          <div>\n            <p className=\"text-[12px]\" style={muted}>\n              Today\n            </p>\n            <Num\n              value={data.totals[0]}\n              format={(n) => usd(n, true)}\n              className=\"block text-[22px] font-semibold tracking-[-0.02em]\"\n            />\n            <Delta value={data.deltas[0]} variant=\"trend\" className=\"text-[12px]\" />\n          </div>\n          <div className=\"h-px\" style={{ backgroundColor: \"#fdeee4\" }} />\n          <div>\n            <p className=\"text-[12px]\" style={muted}>\n              Yesterday\n            </p>\n            <Num\n              value={data.totals[1]}\n              format={(n) => usd(n, true)}\n              className=\"block text-[22px] font-semibold tracking-[-0.02em]\"\n            />\n            <Delta value={data.deltas[1]} variant=\"trend\" className=\"text-[12px]\" />\n          </div>\n        </div>\n        <ChartSlot height={HEIGHT} className=\"min-w-0 flex-1\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Hourly revenue, today above the line and yesterday below\"\n              onFocusChange={(p) => {\n                if (p) {\n                  const i = Number(p.xValue);\n\n                  if (Number.isInteger(i) && i >= 0 && i < BARS) {\n                    pin(i);\n                  }\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n      </div>\n      <div className=\"mt-4 rounded-2xl border border-black/[0.08] px-3.5 pt-3 pb-3.5\">\n        <div className=\"flex items-center justify-between text-[12px] tabular-nums\">\n          <span>{usd(low)}</span>\n          <span className=\"tracking-[0.04em] uppercase\" style={muted}>\n            Day&rsquo;s range\n          </span>\n          <span>{usd(high)}</span>\n        </div>\n        <ChartSlot height={RANGE_HEIGHT} className=\"mt-2.5\">\n          <Chart\n            definition={rangeDef}\n            renderer={renderer}\n            height={RANGE_HEIGHT}\n            ariaLabel={`Price ${usd(price)} within the day's range`}\n          />\n        </ChartSlot>\n      </div>\n      <div className=\"mt-4 grid grid-cols-[1fr_72px_72px] px-1 text-[12px]\" style={muted}>\n        <span />\n        <span className=\"text-center\">Yesterday</span>\n        <span className=\"text-center\">Today</span>\n      </div>\n      <div className=\"mt-2 space-y-2\">\n        {METRICS.map((m, i) => {\n          const row = data.rows[i];\n\n          return (\n            <div\n              key={m.label}\n              className=\"grid grid-cols-[1fr_72px_72px] items-center rounded-2xl bg-[#f7f7f8] p-2.5 ring-1 ring-black/[0.05]\"\n            >\n              <div className=\"flex min-w-0 items-center gap-2.5\">\n                <span\n                  className=\"inline-flex size-9 shrink-0 items-center justify-center rounded-full\"\n                  style={{\n                    backgroundColor: m.tint,\n                    boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${m.color} 25%, transparent)`,\n                    color: m.color,\n                  }}\n                >\n                  <m.icon className=\"size-4\" strokeWidth={2.4} />\n                </span>\n                <div className=\"min-w-0\">\n                  <p className=\"truncate text-[13px]\">{m.label}</p>\n                  <Delta value={row?.delta ?? 0} variant=\"trend\" className=\"text-[12px]\" />\n                </div>\n              </div>\n              <span className=\"text-center text-[14px] tabular-nums\">{row?.yesterday}</span>\n              <span className=\"text-center text-[14px] tabular-nums\">{row?.today}</span>\n            </div>\n          );\n        })}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/finance-overview-diverging-bar.tsx","target":"uicapsule/finance-charts/charts/finance-overview-diverging-bar.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, rect, ruleX } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ArrowUp, Sparkles } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useId, useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  muted,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, GRID, INK, SPRING, VIOLET } from \"../lib/tokens\";\n\nconst HEIGHT = 230;\nconst MARGIN = { bottom: 0, left: 0, right: 0, top: 0 };\nconst SAMPLES = 48;\nconst CHECKPOINTS = [0.24, 0.52, 0.79] as const;\nconst curve = d3Curve(curveMonotoneX);\n\ninterface Region {\n  name: string;\n  values: [number, number, number];\n  p1: number;\n  p2: number;\n  core: number;\n}\n\nconst REGIONS: Region[] = [\n  { core: 0.42, name: \"North America\", p1: 0.6, p2: 0.98, values: [2746.26, 4075, 7192] },\n  { core: 0.36, name: \"Europe\", p1: 0.52, p2: 0.86, values: [2411.04, 3577, 6314] },\n  { core: 0.39, name: \"Asia Pacific\", p1: 0.56, p2: 0.91, values: [2552.86, 3788, 6685] },\n];\n\nconst STATS = [\n  { delta: 612, label: \"Weekly\", value: 7710.16, vs: \"vs last week\" },\n  { delta: 1055, label: \"Monthly\", value: 11_440, vs: \"vs last month\" },\n  { delta: 2345, label: \"Yearly\", value: 20_191, vs: \"vs last year\" },\n] as const;\n\nconst smooth = (a: number, b: number, x: number) => {\n  const t = Math.min(1, Math.max(0, (x - a) / (b - a)));\n\n  return t * t * (3 - 2 * t);\n};\n\nconst thickness = (r: Region, x: number) =>\n  0.07 + (r.p1 - 0.07) * smooth(0.13, 0.33, x) + (r.p2 - r.p1) * smooth(0.58, 0.74, x);\n\ninterface Slice {\n  x: number;\n  core: number;\n  sky: number;\n  edge: number;\n}\n\nconst slicesFor = (r: Region) =>\n  Array.from({ length: SAMPLES }, (_, i) => {\n    const x = i / (SAMPLES - 1);\n    const t = thickness(r, x);\n    const core = t * r.core;\n    const sky = core + t * 0.26;\n\n    return { core, edge: t, sky, x };\n  });\n\nconst fade = (id: string, stops: [number, string, number][]) => ({\n  id,\n  stops: stops.map(([offset, color, opacity]) => ({ color, offset, opacity })),\n  x1: 0,\n  x2: 1,\n});\n\nconst GRADIENTS = [\n  fade(\"fof-blue\", [\n    [0, \"#93c5fd\", 0],\n    [0.14, \"#93c5fd\", 0.55],\n    [0.4, \"#4b98f7\", 1],\n    [0.66, \"#0b7cf0\", 1],\n    [1, \"#0a5cc0\", 1],\n  ]),\n  fade(\"fof-sky\", [\n    [0, \"#bae6fd\", 0],\n    [0.16, \"#9fd4fb\", 0.75],\n    [0.5, \"#58c8f5\", 1],\n    [0.62, \"#5bd3f6\", 1],\n    [1, \"#3c9fc6\", 1],\n  ]),\n  fade(\"fof-core\", [\n    [0, \"#a5d8e6\", 0],\n    [0.18, \"#7fd0d2\", 0.85],\n    [0.5, \"#86d3c6\", 1],\n    [0.62, \"#9cdcae\", 1],\n    [1, \"#16ad4c\", 1],\n  ]),\n  {\n    cx: 0.5,\n    cy: 0.5,\n    id: \"fof-glow\",\n    r: 0.5,\n    stops: [\n      { color: \"#3b82f6\", offset: 0, opacity: 0.2 },\n      { color: \"#60a5fa\", offset: 0.6, opacity: 0.08 },\n      { color: \"#93c5fd\", offset: 1, opacity: 0 },\n    ],\n    type: \"radial\" as const,\n  },\n];\n\nconst UpPill = ({ value }: { value: number }) => (\n  <span\n    className=\"inline-flex items-center gap-1 rounded-full bg-[#e7f7ed] px-1.5 py-0.5 text-[11px] font-semibold tabular-nums\"\n    style={{ color: GREEN }}\n  >\n    <span\n      className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n      style={{ backgroundColor: GREEN }}\n    >\n      <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n    </span>\n    {usd(value, true)}\n  </span>\n);\n\nexport const FinanceOverviewFlow = () => {\n  const [active, pin] = useCycle(REGIONS.length, 3200);\n  const region = REGIONS[active] ?? REGIONS[0];\n  const id = useId();\n\n  const definition = useMemo(() => {\n    const rows = slicesFor(\n      region ?? REGIONS[0] ?? { core: 0.4, name: \"\", p1: 0.6, p2: 1, values: [0, 0, 0] },\n    );\n\n    const band = (key: string, fill: string, y1: (s: Slice) => number, y2: (s: Slice) => number) =>\n      areaY(rows, { curve, fill, fillOpacity: 1, id: key, key: \"x\", x: \"x\", y1, y2 });\n\n    return defineChart({\n      gradients: GRADIENTS,\n      guides: false,\n      margin: MARGIN,\n      marks: [\n        rect([{ id: \"glow\" }], {\n          fill: \"url(#fof-glow)\",\n          inset: 0,\n          key: \"id\",\n          x1: () => 0.08,\n          x2: () => 0.98,\n          y1: () => -1.25,\n          y2: () => 1.25,\n        }),\n        band(\n          \"blue-top\",\n          \"url(#fof-blue)\",\n          (s) => s.sky,\n          (s) => s.edge,\n        ),\n        band(\n          \"blue-bottom\",\n          \"url(#fof-blue)\",\n          (s) => -s.edge,\n          (s) => -s.sky,\n        ),\n        band(\n          \"sky-top\",\n          \"url(#fof-sky)\",\n          (s) => s.core,\n          (s) => s.sky,\n        ),\n        band(\n          \"sky-bottom\",\n          \"url(#fof-sky)\",\n          (s) => -s.sky,\n          (s) => -s.core,\n        ),\n        band(\n          \"core\",\n          \"url(#fof-core)\",\n          (s) => -s.core,\n          (s) => s.core,\n        ),\n        ruleX([...CHECKPOINTS], { stroke: INK, strokeOpacity: 1, strokeWidth: 2 }),\n      ],\n      scales: {\n        x: { axis: false, scale: scaleLinear().domain([0, 1]) },\n        y: { axis: false, scale: scaleLinear().domain([-1.12, 1.12]) },\n      },\n    });\n  }, [region]);\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Finance Overview</h3>\n        <div className=\"flex items-center gap-1.5\">\n          <button\n            type=\"button\"\n            aria-label=\"Insights\"\n            className=\"inline-flex size-8 items-center justify-center rounded-full border border-black/[0.08]\"\n          >\n            <Sparkles\n              className=\"size-4\"\n              style={{ color: VIOLET }}\n              fill=\"#6366f1\"\n              strokeWidth={1.5}\n            />\n          </button>\n          <MoreButton />\n        </div>\n      </div>\n      <div className=\"mt-4 grid grid-cols-3 gap-2\">\n        {STATS.map((s) => (\n          <div key={s.label} className=\"min-w-0\">\n            <p className=\"min-h-[2.5em] text-[11px] leading-tight\" style={muted}>\n              {s.label} net cash flow\n            </p>\n            <Num\n              value={s.value}\n              className=\"mt-1 block text-[17px] font-semibold tracking-[-0.02em]\"\n            />\n            <div className=\"mt-1 flex flex-wrap items-center gap-x-1 gap-y-0.5\">\n              <UpPill value={s.delta} />\n              <span className=\"text-[10px]\" style={muted}>\n                {s.vs}\n              </span>\n            </div>\n          </div>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"-mx-5 mt-2\">\n        <Chart\n          definition={definition}\n          renderer={renderer}\n          height={HEIGHT}\n          ariaLabel={`Net cash flow for ${region?.name ?? \"\"}, widening from weekly to yearly`}\n        />\n        <PlotOverlay margin={MARGIN}>\n          {CHECKPOINTS.map((x, i) => (\n            <Bubble\n              key={x}\n              left={x * 100}\n              top={50}\n              dark\n              className=\"-translate-y-1/2 !rounded-full !px-2.5 !py-1 text-[12px] font-medium\"\n            >\n              <Num value={region?.values[i] ?? 0} />\n            </Bubble>\n          ))}\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-3 text-[12px]\" onMouseLeave={() => pin(null)}>\n        <div\n          className=\"grid grid-cols-[1.25fr_1fr_1fr_1fr] border-b pb-2\"\n          style={{ borderColor: GRID, ...muted }}\n        >\n          <span>Region</span>\n          <span>Weekly</span>\n          <span>Monthly</span>\n          <span>Yearly</span>\n        </div>\n        {REGIONS.map((r, i) => (\n          <button\n            key={r.name}\n            type=\"button\"\n            onMouseEnter={() => pin(i)}\n            className=\"relative grid w-full grid-cols-[1.25fr_1fr_1fr_1fr] border-b py-2.5 text-left tabular-nums last:border-b-0\"\n            style={{ borderColor: GRID, color: i === active ? INK : \"#55555d\" }}\n          >\n            {i === active ? (\n              <motion.span\n                layoutId={`${id}-row`}\n                transition={SPRING}\n                className=\"absolute inset-y-1 -inset-x-2 rounded-lg bg-[#f4f6fb]\"\n              />\n            ) : null}\n            <span className=\"relative truncate pr-1\">{r.name}</span>\n            {r.values.map((v) => (\n              <span key={v} className={`relative ${i === active ? \"font-semibold\" : \"\"}`}>\n                {usd(v)}\n              </span>\n            ))}\n          </button>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/finance-overview-flow.tsx","target":"uicapsule/finance-charts/charts/finance-overview-flow.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, rect, ruleX, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd, WEEKDAYS } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst SERIES = [\n  { bg: \"#e6f1fe\", color: \"#0f7ff0\", id: \"needs\", label: \"Needs\" },\n  { bg: \"#f6e9fe\", color: \"#a335f5\", id: \"wants\", label: \"Wants\" },\n  { bg: \"#fff1e7\", color: \"#fb7417\", id: \"saving\", label: \"Saving\" },\n] as const;\n\nconst SPEND = [\n  [85, 85, 35],\n  [55, 35, 65],\n  [215, 100, 0],\n  [0, 125, 60],\n  [48, 0, 0],\n  [130, 65, 125],\n  [0, 56, 90],\n] as const;\n\nconst TOTALS = SERIES.map((_, s) => SPEND.reduce((sum, day) => sum + (day[s] ?? 0), 0));\nconst WEEK = TOTALS.reduce((a, b) => a + b, 0);\nconst TOP = 620;\nconst HEIGHT = 220;\nconst MARGIN = { bottom: 26, left: 40, right: 2, top: 4 };\nconst PAD = 0.22;\n\ninterface Seg {\n  day: number;\n  y1: number;\n  y2: number;\n}\n\nexport const FinanceOverviewStackedBar = () => {\n  const [hi, pin] = useCycle(WEEKDAYS.length, 2200, 5);\n  const dayTotal = (SPEND[hi] ?? []).reduce((a: number, b) => a + b, 0);\n\n  const definition = useMemo(() => {\n    const segs = SERIES.map((_, s) =>\n      SPEND.flatMap<Seg>((day, d) => {\n        const v = day[s] ?? 0;\n\n        if (v === 0) {\n          return [];\n        }\n\n        const y1 = day.slice(0, s).reduce((a: number, b) => a + b, 0);\n\n        return [{ day: d, y1, y2: y1 + v }];\n      }),\n    );\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        rect([{ id: \"hl\", x: hi }], {\n          fill: \"#f4f6fa\",\n          inset: 0,\n          key: \"id\",\n          radius: 8,\n          x1: (d) => d.x + 0.04,\n          x2: (d) => d.x + 0.96,\n          y1: () => 0,\n          y2: () => TOP,\n        }),\n        ruleX([0, 1, 2, 3, 4, 5, 6, 7], { stroke: GRID, strokeOpacity: 1 }),\n        ruleY([200, 400, 600], { stroke: GRID, strokeOpacity: 1 }),\n        ruleY([100, 300, 500], { stroke: GRID, strokeDasharray: \"4 4\", strokeOpacity: 1 }),\n        ruleY([0], { stroke: \"#d4d4d8\", strokeOpacity: 1 }),\n        ...SERIES.map((s, i) =>\n          rect(segs[i] ?? [], {\n            fill: s.color,\n            id: `fo-${s.id}`,\n            inset: 0,\n            key: \"day\",\n            radius: 1.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 1.25,\n            x: (d) => d.day + 0.5,\n            x1: (d) => d.day + PAD,\n            x2: (d) => d.day + 1 - PAD,\n            y1: \"y1\",\n            y2: \"y2\",\n          }),\n        ),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12, fontWeight: (c) => (c.value === hi + 0.5 ? 600 : 400) },\n            ticks: {\n              format: (v: number) => WEEKDAYS[Math.floor(v)] ?? \"\",\n              size: 0,\n              values: WEEKDAYS.map((_, i) => i + 0.5),\n            },\n          },\n          scale: scaleLinear().domain([0, WEEKDAYS.length]),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: { format: (v: number) => `$${v}`, size: 0, values: [0, 200, 400, 600] },\n          },\n          scale: scaleLinear().domain([0, TOP]),\n        },\n      },\n      theme: THEME,\n    });\n  }, [hi]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"pt-1 text-[16px] font-semibold tracking-[-0.01em]\">Finance Overview</h3>\n        <MoreButton />\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: \"#52525b\" }}>\n        Daily spending\n      </p>\n      <div className=\"flex items-end justify-between gap-2\">\n        <Num value={WEEK / 7} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n        <p className=\"inline-flex items-center gap-1.5 pb-1.5 text-[11px]\">\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-medium\"\n            style={{ color: GREEN }}\n          >\n            <span className=\"inline-flex size-3 items-center justify-center rounded-full bg-[#16a34a] text-white\">\n              <ArrowUp className=\"size-2\" strokeWidth={3} />\n            </span>\n            8.34%\n          </span>\n          <span style={{ color: MUTED }}>vs last week</span>\n        </p>\n      </div>\n      <div className=\"mt-3 grid grid-cols-3 gap-1.5\">\n        {SERIES.map((s, i) => (\n          <div key={s.id} className=\"rounded-xl px-2.5 py-2\" style={{ backgroundColor: s.bg }}>\n            <p className=\"text-[12px] font-medium\" style={{ color: s.color }}>\n              {s.label}\n            </p>\n            <Num\n              value={TOTALS[i] ?? 0}\n              format={(n) => usd(n, true)}\n              className=\"mt-0.5 block text-[17px] font-semibold tracking-[-0.02em]\"\n            />\n          </div>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Daily spending by needs, wants and saving\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.min(6, Math.max(0, Math.floor(x))));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={((hi + 0.5) / WEEKDAYS.length) * 100}\n            top={100 - (dayTotal / TOP) * 100}\n            dark\n            className=\"-translate-y-[calc(100%+8px)] !px-2 !py-1 text-[11px] font-semibold\"\n          >\n            {WEEKDAYS[hi]} · {usd(dayTotal, true)}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-4 flex items-center justify-between rounded-xl border-[1.5px] border-[#3b8ef3] bg-[#e8f2fe] px-3.5 py-2.5\">\n        <span className=\"text-[12px] font-semibold\">Total Spending:</span>\n        <span className=\"text-[12px]\" style={{ color: MUTED }}>\n          <Num\n            value={WEEK}\n            format={(n) => usd(n, true)}\n            className=\"text-[16px] font-semibold text-[#0b0b0f]\"\n          />{\" \"}\n          /week\n        </span>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/finance-overview-stacked-bar.tsx","target":"uicapsule/finance-charts/charts/finance-overview-stacked-bar.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, rect } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Download, PieChart, Share } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng, usd, WEEKDAYS } from \"../lib/data\";\nimport { CardHeader, Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED, THEME, VIOLET } from \"../lib/tokens\";\n\nconst TIER_FILL = { dark: \"#c470fb\", light: \"#e4c2fc\", mid: \"#d59cf9\" } as const;\n\ntype Tier = keyof typeof TIER_FILL;\n\nconst BASE: readonly (readonly [number, number, Tier])[] = [\n  [2.31, 0.12, \"light\"],\n  [2.82, 0.13, \"mid\"],\n  [3.13, 0.36, \"light\"],\n  [3.49, 0.1, \"dark\"],\n  [3.9, 0.86, \"light\"],\n  [5, 0.38, \"dark\"],\n  [5.56, 0.56, \"light\"],\n  [6.42, 0.2, \"dark\"],\n  [6.66, 0.07, \"dark\"],\n];\n\ninterface Session {\n  id: number;\n  tier: Tier;\n  x1: number;\n  x2: number;\n}\n\nconst deal = (seed: number) => {\n  const r = rng(seed);\n  let cursor = 0.4 + r() * 1.4;\n\n  const raw = BASE.map(([, len, tier], id) => {\n    const x1 = cursor + 0.06 + r() * 0.4;\n    const x2 = x1 + len * (0.6 + r() * 0.9);\n    cursor = x2;\n\n    return { id, tier, x1, x2 };\n  });\n\n  const end = raw.at(-1)?.x2 ?? 7;\n  const fit = end > 6.9 ? 6.9 / end : 1;\n\n  return raw.map<Session>((s) => ({ ...s, x1: s.x1 * fit, x2: s.x2 * fit }));\n};\n\nconst WEEKS = [\n  {\n    avg: 124.99,\n    budget: 64,\n    sessions: BASE.map(([x1, len, tier], id) => ({ id, tier, x1, x2: x1 + len })),\n    total: 874.92,\n  },\n  { avg: 108.91, budget: 56, sessions: deal(7), total: 762.37 },\n  { avg: 135.9, budget: 70, sessions: deal(19), total: 951.3 },\n] as const;\n\nconst TIERS: Tier[] = [\"light\", \"mid\", \"dark\"];\nconst HEIGHT = 150;\nconst MARGIN = { bottom: 26, left: 0, right: 0, top: 0 };\n\nexport const FinanceOverviewTimeline = () => {\n  const [w, pin] = useCycle(WEEKS.length, 3000);\n  const week = WEEKS[w] ?? WEEKS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          rect([{ id: \"base\" }], {\n            fill: \"#f5e9fe\",\n            inset: 0,\n            key: \"id\",\n            x1: () => 0,\n            x2: () => WEEKDAYS.length,\n            y1: () => 0,\n            y2: () => 0.75,\n          }),\n          ...TIERS.map((tier) =>\n            rect(\n              week.sessions.filter((s) => s.tier === tier),\n              {\n                fill: TIER_FILL[tier],\n                id: `fot-${tier}`,\n                inset: 0,\n                key: \"id\",\n                x: (d) => (d.x1 + d.x2) / 2,\n                x1: \"x1\",\n                x2: \"x2\",\n                y1: () => 0,\n                y2: () => 1,\n              },\n            ),\n          ),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => WEEKDAYS[Math.floor(v)] ?? \"\",\n                size: 0,\n                values: WEEKDAYS.map((_, i) => i + 0.5),\n              },\n            },\n            scale: scaleLinear().domain([0, WEEKDAYS.length]),\n          },\n          y: { axis: false, scale: scaleLinear().domain([0, 1.04]) },\n        },\n        theme: THEME,\n      }),\n    [week],\n  );\n\n  const stats = [\n    { format: (n: number) => usd(n), label: \"Total spending\", value: week.total },\n    { format: (n: number) => usd(n), label: \"Avg daily spending\", value: week.avg },\n    { format: (n: number) => `${Math.round(n)}%`, label: \"Budget status\", value: week.budget },\n  ];\n\n  return (\n    <Card>\n      <CardHeader\n        icon={PieChart}\n        color={VIOLET}\n        title=\"Finance overview\"\n        subtitle=\"Track your income and expenses.\"\n        actions={<MoreButton />}\n      />\n      <div className=\"mt-5 grid grid-cols-3 gap-2\">\n        {stats.map((s) => (\n          <div key={s.label} className=\"min-w-0\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              {s.label}\n            </p>\n            <Num\n              value={s.value}\n              format={s.format}\n              className=\"mt-0.5 block text-[19px] font-bold tracking-[-0.03em]\"\n            />\n          </div>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseEnter={() => pin(w)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Spending sessions across the week\"\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-4 flex items-center justify-between gap-2\">\n        <button\n          type=\"button\"\n          className=\"inline-flex h-8 items-center gap-1.5 rounded-full border border-black/[0.08] px-3 text-[12px] font-medium text-[#3a3a42]\"\n        >\n          <Download className=\"size-3.5\" style={{ color: MUTED }} />\n          Export report\n        </button>\n        <button\n          type=\"button\"\n          className=\"inline-flex h-8 items-center gap-1.5 rounded-full border border-black/[0.08] px-3 text-[12px] font-medium text-[#3a3a42]\"\n        >\n          <Share className=\"size-3.5\" style={{ color: MUTED }} />\n          Share with friends\n        </button>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/finance-overview-timeline.tsx","target":"uicapsule/finance-charts/charts/finance-overview-timeline.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { bandX, barY, defineChart, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, ChartPie } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  CardHeader,\n  ChartSlot,\n  Chip,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst VIVID_PURPLE = \"#a43cf5\";\n\nconst SERIES = [\n  { color: GREEN, label: \"Assets\", total: 643_867.09 },\n  { color: ORANGE, label: \"Debt\", total: 138_645.16 },\n  { color: BLUE, label: \"Investments\", total: 264_864.86 },\n  { color: VIVID_PURPLE, label: \"Cash\", total: 79_742.92 },\n] as const;\n\nconst TABLE: [number, number, number, number][] = [\n  [9460, 1520, 4480, 5600],\n  [7420, 2560, 7010, 2140],\n  [4180, 0, 4560, 8640],\n  [9080, 0, 0, 8520],\n  [0, 5540, 7120, 17_960],\n  [4363.64, 5181.82, 3000, 22_909.09],\n  [17_820, 980, 3640, 8420],\n  [14_130, 4120, 5060, 6280],\n  [9620, 6040, 1980, 3840],\n  [4470, 4980, 0, 3060],\n  [1660, 2480, 1520, 2460],\n  [12_480, 4960, 5120, 8640],\n  [1480, 2060, 0, 0],\n];\n\nconst WEEKDAY = [\"Fri\", \"Sat\", \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\"] as const;\nconst DAYS = TABLE.map((_, i) => i + 1);\n\nconst ROWS = TABLE.flatMap((vals, i) =>\n  SERIES.map((s, j) => ({\n    day: i + 1,\n    id: `${i + 1}-${s.label}`,\n    series: s.label,\n    value: vals[j] ?? 0,\n  })),\n);\n\nconst TOP = 60_000;\nconst HEIGHT = 220;\nconst MARGIN = { bottom: 26, left: 40, right: 0, top: 8 };\n\nexport const FinancialBreakdown = () => {\n  const [hi, pin] = useCycle(DAYS.length, 2000, 5);\n  const day = hi + 1;\n  const vals = TABLE[hi] ?? TABLE[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        color: { domain: SERIES.map((s) => s.label), range: SERIES.map((s) => s.color) },\n        margin: MARGIN,\n        marks: [\n          bandX([day], {\n            fill: VIVID_PURPLE,\n            fillOpacity: 0.1,\n            inset: -3,\n            key: () => \"band\",\n            x: (d) => d,\n          }),\n          ruleY([0], { stroke: \"#e4e4e8\", strokeOpacity: 1, strokeWidth: 1 }),\n          ruleY([20_000, 40_000, 60_000], {\n            stroke: \"#dcdce2\",\n            strokeDasharray: \"5 5\",\n            strokeOpacity: 1,\n            strokeWidth: 1,\n          }),\n          barY(ROWS, {\n            color: \"series\",\n            key: \"id\",\n            radius: { end: 4 },\n            stroke: \"#ffffff\",\n            strokeWidth: 1.25,\n            x: \"day\",\n            y: \"value\",\n            z: \"series\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === day ? 600 : 400),\n                thin: false,\n              },\n              ticks: { format: (d: number) => `${d}`, size: 0 },\n            },\n            scale: scaleBand<number>().domain(DAYS).paddingInner(0.34).paddingOuter(0.1),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v: number) => compact(v),\n                size: 0,\n                values: [0, 20_000, 40_000, 60_000],\n              },\n            },\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [day],\n  );\n\n  const center = ((hi + 0.1 + 0.33) / (DAYS.length - 0.34 + 0.2)) * 100;\n  const flip = hi > 6;\n  const align = flip ? \"right\" : \"left\";\n  const left = flip ? center - 3.5 : center + 3.5;\n\n  return (\n    <Card>\n      <CardHeader\n        icon={ChartPie}\n        color={VIVID_PURPLE}\n        title=\"Financial Breakdown\"\n        actions={\n          <Chip>\n            View data <ArrowUpRight className=\"size-3.5\" />\n          </Chip>\n        }\n      />\n      <div className=\"mt-5 grid grid-cols-2 gap-x-4 gap-y-3\">\n        {SERIES.map((s) => (\n          <div key={s.label}>\n            <p className=\"inline-flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n              <span className=\"h-1 w-3 rounded-full\" style={{ backgroundColor: s.color }} />\n              {s.label}\n            </p>\n            <Num\n              value={s.total}\n              className=\"mt-0.5 block text-[18px] font-bold tracking-[-0.02em]\"\n            />\n          </div>\n        ))}\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Assets, debt, investments and cash by day, May 1 to May 13\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(DAYS.indexOf(Number(p.xValue)));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left}\n            top={0}\n            dark\n            align={align}\n            className=\"w-[142px] !rounded-[12px] !px-2.5 !py-2\"\n          >\n            <p className=\"mb-1 text-[11px] text-white/70\">\n              {WEEKDAY[hi % 7]}, May {day}\n            </p>\n            {SERIES.map((s, j) => (\n              <p key={s.label} className=\"flex items-center gap-1.5 py-0.5 text-[10.5px]\">\n                <span className=\"h-1 w-2.5 rounded-full\" style={{ backgroundColor: s.color }} />\n                <span className=\"text-white/70\">{s.label}</span>\n                <span className=\"ml-auto font-semibold tabular-nums\">{usd(vals?.[j] ?? 0)}</span>\n              </p>\n            ))}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <p className=\"mt-1 text-center text-[11px] text-[#a1a1aa]\">May 2026</p>\n    </Card>\n  );\n};\n","path":"/charts/financial-breakdown.tsx","target":"uicapsule/finance-charts/charts/financial-breakdown.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, rect, ruleX } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Ellipsis } from \"lucide-react\";\nimport { useMemo, useState } from \"react\";\n\nimport { compact, MONTHS, rng, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Legend,\n  Num,\n  PlotOverlay,\n  Segmented,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, INK, MUTED, THEME } from \"../lib/tokens\";\n\nconst ROWS = 12;\nconst HEIGHT = 196;\nconst MARGIN = { bottom: 26, left: 40, right: 0, top: 6 };\nconst IN_COLOR = \"#e5e5e9\";\nconst EMPTY = \"#f5f5f7\";\nconst MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst WEEK = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\ninterface Range {\n  name: string;\n  cols: number;\n  step: number;\n  seed: number;\n  total: number;\n  ticks: [number, string][];\n  period: (col: number) => string;\n}\n\nconst RANGES: Range[] = [\n  {\n    cols: 7,\n    name: \"Week\",\n    period: (c) => `${WEEK[c]}, Oct ${19 + c}, 2026`,\n    seed: 3,\n    step: 500,\n    ticks: WEEK.map((d, i) => [i, d]),\n    total: 1742.18,\n  },\n  {\n    cols: 15,\n    name: \"Month\",\n    period: (c) => `Oct ${1 + c * 2} – ${Math.min(31, 2 + c * 2)}, 2026`,\n    seed: 11,\n    step: 1000,\n    ticks: [0, 3, 6, 9, 12].map((c) => [c, `Oct ${1 + c * 2}`]),\n    total: 9408.66,\n  },\n  {\n    cols: 24,\n    name: \"Year\",\n    period: (c) => {\n      const m = Math.floor(c / 2);\n      const month = MONTHS[m] ?? \"\";\n\n      return c % 2 === 0 ? `${month} 1 – 15, 2026` : `${month} 16 – ${MONTH_DAYS[m] ?? 30}, 2026`;\n    },\n    seed: 29,\n    step: 50_000 / ROWS,\n    ticks: MONTHS.map((m, i) => [i * 2, m]),\n    total: 63_984.02,\n  },\n];\n\nconst flows = (range: Range) => {\n  const r = rng(range.seed);\n\n  return Array.from({ length: range.cols }, (_, col) => {\n    const out = range.step * (0.7 + r() * 3.1);\n    const swell = Math.sin((col / range.cols) * Math.PI) * 4;\n    const inflow = range.step * (1.2 + swell + r() * 4.2);\n\n    return { col, inflow, out };\n  });\n};\n\nconst DATA = RANGES.map(flows);\n\nexport const FinancialTrends = () => {\n  const [range, setRange] = useState(2);\n  const meta = RANGES[range] ?? RANGES[2];\n  const cols = meta?.cols ?? 24;\n  const step = meta?.step ?? 1;\n  const [hi, pin] = useCycle(cols, 1500, Math.min(cols - 1, 9));\n  const col = Math.min(hi, cols - 1);\n  const picked = DATA[range]?.[col];\n\n  const definition = useMemo(() => {\n    const data = DATA[range] ?? [];\n\n    const cells = data.flatMap((d) => {\n      const outRows = Math.max(1, Math.round(d.out / step));\n      const inRows = Math.round(d.inflow / step);\n\n      return Array.from({ length: ROWS }, (_, row) => {\n        let kind = \"empty\";\n\n        if (row < outRows) {\n          kind = \"out\";\n        } else if (row < outRows + inRows) {\n          kind = \"in\";\n        }\n\n        return { col: d.col, id: `${d.col}:${row}`, kind, row };\n      });\n    });\n\n    const colIds = data.map((d) => d.col);\n    const ticks = meta?.ticks ?? [];\n\n    return defineChart({\n      color: { domain: [\"out\", \"in\", \"empty\"], range: [BLUE, IN_COLOR, EMPTY] },\n      margin: MARGIN,\n      marks: [\n        rect(cells, {\n          color: \"kind\",\n          inset: 1.4,\n          key: \"id\",\n          radius: 2.5,\n          x: \"col\",\n          y1: (d) => d.row * step,\n          y2: (d) => (d.row + 1) * step,\n        }),\n        ruleX([col], {\n          stroke: INK,\n          strokeDasharray: \"3 3\",\n          strokeOpacity: 0.55,\n          strokeWidth: 1,\n        }),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: {\n              format: (v: number) => ticks.find(([c]) => c === v)?.[1] ?? \"\",\n              size: 0,\n              values: ticks.map(([c]) => c),\n            },\n          },\n          scale: scaleBand<number>().domain(colIds).padding(0),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: {\n              format: (v: number) => compact(v),\n              size: 0,\n              values: [0, 1, 2, 3, 4, 5].map((k) => (k * step * ROWS) / 5),\n            },\n          },\n          scale: scaleLinear().domain([0, step * ROWS]),\n        },\n      },\n      theme: THEME,\n    });\n  }, [range, step, col, meta]);\n\n  const center = ((col + 0.5) / cols) * 100;\n  const right = center < 50;\n  const outTop = picked ? Math.max(1, Math.round(picked.out / step)) / ROWS : 0;\n\n  return (\n    <Card className=\"!bg-[#f3f3f5] !p-1.5\">\n      <div className=\"flex items-center justify-between px-3 pt-2 pb-2.5\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Financial Trends</h3>\n        <button\n          type=\"button\"\n          aria-label=\"More\"\n          className=\"inline-flex size-8 items-center justify-center rounded-[10px] bg-white text-[#8a8a93] shadow-[0_1px_2px_rgba(0,0,0,0.06)]\"\n        >\n          <Ellipsis className=\"size-4\" />\n        </button>\n      </div>\n      <div className=\"rounded-[18px] bg-white p-4 ring-1 ring-black/[0.05]\">\n        <div className=\"flex items-start justify-between gap-2\">\n          <div>\n            <p className=\"text-[12px]\" style={{ color: MUTED }}>\n              Total net cash flow\n            </p>\n            <Num\n              value={meta?.total ?? 0}\n              className=\"mt-0.5 block text-[24px] font-bold tracking-[-0.03em]\"\n            />\n          </div>\n          <Segmented\n            options={RANGES.map((r) => r.name)}\n            value={range}\n            onChange={setRange}\n            size=\"sm\"\n            className=\"shrink-0\"\n          />\n        </div>\n        <Legend\n          swatch=\"square\"\n          items={[\n            { color: \"#dedee3\", label: \"Cash inflow\" },\n            { color: BLUE, label: \"Cash outflow\" },\n          ]}\n          className=\"mt-3\"\n        />\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel={`Cash inflow and outflow by period, ${meta?.name.toLowerCase()}`}\n              onFocusChange={(p) => {\n                const c = Number(p?.xValue);\n\n                if (p && Number.isInteger(c)) {\n                  pin(c);\n                }\n              }}\n            />\n          </div>\n          <PlotOverlay margin={MARGIN}>\n            <Bubble\n              left={right ? center + 3 : center - 3}\n              top={Math.max(4, 100 - outTop * 100 - 52)}\n              align={right ? \"left\" : \"right\"}\n              className=\"!rounded-[14px] !p-1.5\"\n            >\n              <p className=\"rounded-[9px] bg-[#f4f4f6] px-2 py-1 text-[11px] font-medium\">\n                {meta?.period(col)}\n              </p>\n              <div className=\"px-1.5 pt-1 pb-0.5\">\n                {[\n                  { color: \"#dedee3\", label: \"Cash inflow\", value: picked?.inflow ?? 0 },\n                  { color: BLUE, label: \"Cash outflow\", value: picked?.out ?? 0 },\n                ].map((row) => (\n                  <p key={row.label} className=\"flex items-center gap-1.5 py-0.5 text-[11px]\">\n                    <span className=\"size-2 rounded-[2px]\" style={{ backgroundColor: row.color }} />\n                    <span style={{ color: MUTED }}>{row.label}</span>\n                    <span className=\"ml-auto pl-3 font-semibold tabular-nums\">\n                      {usd(row.value)}\n                    </span>\n                  </p>\n                ))}\n              </div>\n            </Bubble>\n          </PlotOverlay>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/financial-trends.tsx","target":"uicapsule/finance-charts/charts/financial-trends.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { cell, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { THEME } from \"../lib/tokens\";\n\nconst FIRST = 2023;\nconst YEARS = 8;\nconst PER_YEAR = 4;\nconst COLS = YEARS * PER_YEAR;\nconst ROWS = 22;\nconst MILESTONES = new Set([1, 5, 8, 10, 12, 17, 21, 25, 28, 29, 31]);\n\nconst level = (c: number) => {\n  const t = c / (COLS - 1);\n  const g = 1.46 ** (t * (YEARS - 1));\n  const span = 1.46 ** (YEARS - 1) - 1;\n\n  return Math.round(2 + (ROWS - 3) * ((g - 1) / span));\n};\n\ninterface Cell {\n  c: number;\n  id: string;\n  r: number;\n}\n\nconst cellAt = (c: number, r: number) => ({ c, id: `${c}-${r}`, r });\n\nconst ALL: Cell[] = [];\n\nfor (let c = 0; c < COLS; c += 1) {\n  for (let r = 0; r < ROWS; r += 1) {\n    ALL.push(cellAt(c, r));\n  }\n}\n\nconst HEIGHT = 200;\nconst MARGIN = { bottom: 22, left: 0, right: 0, top: 0 };\nconst STEPS = YEARS + 2;\n\nexport const GlobalDefi = () => {\n  const [step, pin] = useCycle(STEPS, 900, STEPS - 1);\n  const years = Math.min(YEARS, step + 1);\n\n  const definition = useMemo(() => {\n    const filled: Cell[] = [];\n    const lit: Cell[] = [];\n\n    for (let c = 0; c < years * PER_YEAR; c += 1) {\n      const top = level(c);\n\n      for (let r = 0; r < top; r += 1) {\n        if (r === top - 1 && MILESTONES.has(c)) {\n          lit.push(cellAt(c, r));\n        } else {\n          filled.push(cellAt(c, r));\n        }\n      }\n    }\n\n    const grid = (rows: Cell[], fill: string, id: string) =>\n      cell(rows, { fill, id, inset: 1.1, key: \"id\", radius: 2, x: \"c\", y: \"r\" });\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        grid(ALL, \"#f4f4f5\", \"defi-empty\"),\n        grid(filled, \"#fde8b4\", \"defi-fill\"),\n        grid(lit, \"#fbbf24\", \"defi-lit\"),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: {\n              dx: ({ bandwidth }) => -bandwidth / 2,\n              fontSize: 11,\n              opacity: ({ index }) => (index < years ? 1 : 0.45),\n            },\n            ticks: {\n              format: (v: number) => String(FIRST + Math.floor(v / PER_YEAR)),\n              size: 0,\n              values: Array.from({ length: YEARS }, (_, y) => y * PER_YEAR + 2),\n            },\n          },\n          scale: scaleBand<number>()\n            .domain(Array.from({ length: COLS }, (_, i) => i))\n            .padding(0),\n        },\n        y: {\n          axis: false,\n          reverse: true,\n          scale: scaleBand<number>()\n            .domain(Array.from({ length: ROWS }, (_, i) => i))\n            .padding(0),\n        },\n      },\n      theme: THEME,\n    });\n  }, [years]);\n\n  return (\n    <Card className=\"!bg-[#f6f6f7] !p-1.5\">\n      <div className=\"flex items-center justify-between px-3 pt-2 pb-2.5\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Global DeFi</h3>\n        <MoreButton className=\"bg-white\" />\n      </div>\n      <div className=\"rounded-[16px] border border-black/[0.06] bg-white p-3.5\">\n        <p className=\"text-[11px] leading-[1.55] tracking-[0.01em] text-[#52525b] uppercase\">\n          The global <span className=\"normal-case\">DeFi</span> market is currently valued at{\" \"}\n          <Num\n            value={13.92}\n            format={(n) => `$${n.toFixed(2)} billion`}\n            className=\"font-semibold text-[#0b0b0f]\"\n          />\n          , and is expected to grow at a{\" \"}\n          <span className=\"font-semibold text-[#0b0b0f]\">CAGR of 46%</span> between{\" \"}\n          <span className=\"font-semibold text-[#0b0b0f]\">2023-2030</span>.\n        </p>\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseEnter={() => pin(STEPS - 1)} onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"DeFi market size by quarter, 2023 to 2030\"\n            />\n          </div>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/global-defi.tsx","target":"uicapsule/finance-charts/charts/global-defi.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, d3Curve, defineChart, dot, lineY, ruleX } from \"@tanstack/charts\";\nimport type { ChartGradient } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveBasis } from \"d3-shape\";\nimport { CalendarDays, Download, List, Package } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS, walk } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  Delta,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { DASHED_GRID, GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst SPAN = MONTHS.slice(0, 7);\nconst PER = 28;\nconst N = SPAN.length * PER;\nconst TOP = 80;\n\nconst MARGIN = { bottom: 28, left: 42, right: 4, top: 8 };\nconst HEIGHT = 236;\n\nconst throughAnchors = (anchors: readonly number[], seed: number, vol: number) => {\n  const noise = walk(N, seed, { max: vol * 1.6, min: -vol * 1.6, start: 0, vol: vol * 0.45 });\n\n  return Array.from({ length: N }, (_, i) => {\n    const t = (i / (N - 1)) * (anchors.length - 1);\n    const k = Math.min(anchors.length - 2, Math.floor(t));\n    const lo = anchors[k] ?? 0;\n    const hi = anchors[k + 1] ?? lo;\n\n    return { i, v: lo + (hi - lo) * (t - k) + (noise[i] ?? 0) };\n  });\n};\n\nconst actual = throughAnchors([16, 29, 24, 31, 44, 52, 46, 50, 48, 59, 50, 42, 50, 60], 4207, 3.4);\nconst forecast = throughAnchors([18, 13, 24, 21, 20, 26, 19, 22, 28, 34, 40, 38, 42, 54], 77, 1.6);\n\nconst TIGHT = \"!h-6 !gap-1 !px-2 !text-[11px] [&>svg]:!size-3\";\n\nconst BAR_VALUES = [15, 9, -7, 13, -10, -5, 18.5, 13, -10, -5, 7, 13, -11.5] as const;\n\nconst bars = BAR_VALUES.map((v, k) => ({\n  id: `b${k}`,\n  up: v >= 0,\n  v: Math.abs(v),\n  x: ((k + 0.5) * N) / BAR_VALUES.length,\n}));\n\nconst stripes = (id: string, base: string, line: string, count = 9) =>\n  ({\n    id,\n    stops: Array.from({ length: count }, (_, k) => {\n      const a = k / count;\n      const b = (k + 0.5) / count;\n      const c = (k + 1) / count;\n\n      return [\n        { color: base, offset: a },\n        { color: base, offset: b },\n        { color: line, offset: b },\n        { color: line, offset: c },\n      ];\n    }).flat(),\n    x1: 0,\n    x2: 1,\n    y1: 0,\n    y2: 0.35,\n  }) satisfies ChartGradient;\n\nconst STATS = [\n  { delta: 8.05, format: (n: number) => `$${n.toFixed(1)}M`, label: \"Global AUM’26\", value: 59.6 },\n  { delta: 3.13, format: (n: number) => `${Math.round(n)}%`, label: \"Market growth\", value: 23 },\n  { delta: 6.82, format: (n: number) => `$${n.toFixed(1)}M`, label: \"2027 Forecast\", value: 63.6 },\n] as const;\n\nexport const GlobalFinanceMarketCombo = () => {\n  const [hi, pin] = useCycle(SPAN.length, 2200, 4);\n  const at = Math.min(N - 1, Math.round((hi + 0.5) * PER));\n  const picked = actual[at] ?? actual[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          stripes(\"gf-up\", \"#d3f3dd\", \"#c0ebcf\"),\n          stripes(\"gf-down\", \"#fde0e0\", \"#fbcdcd\"),\n        ],\n        margin: MARGIN,\n        marks: [\n          barY(bars, {\n            fill: (d) => (d.up ? \"url(#gf-up)\" : \"url(#gf-down)\"),\n            id: \"bars\",\n            key: \"id\",\n            maxThickness: 20,\n            radius: [7, 7, 0, 0],\n            stroke: (d) => (d.up ? \"#8fdcaa\" : \"#f6a5a5\"),\n            strokeWidth: 1,\n            x: \"x\",\n            y: \"v\",\n          }),\n          lineY(forecast, {\n            curve: d3Curve(curveBasis),\n            id: \"forecast\",\n            stroke: \"#c9c9cf\",\n            strokeDasharray: \"5 4\",\n            strokeWidth: 1.6,\n            x: \"i\",\n            y: \"v\",\n          }),\n          ruleX([{ id: \"scrub\", x: picked?.i ?? 0 }], {\n            id: \"scrub\",\n            stroke: GREEN,\n            strokeDasharray: \"3 3\",\n            strokeOpacity: 0.5,\n            x: \"x\",\n          }),\n          lineY(actual, {\n            curve: d3Curve(curveBasis),\n            id: \"actual\",\n            stroke: GREEN,\n            strokeWidth: 2.2,\n            x: \"i\",\n            y: \"v\",\n          }),\n          dot([{ i: picked?.i ?? 0, id: \"head\", v: picked?.v ?? 0 }], {\n            fill: GREEN,\n            id: \"head\",\n            key: \"id\",\n            r: 5,\n            stroke: \"#ffffff\",\n            strokeWidth: 2.5,\n            x: \"i\",\n            y: \"v\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: { stroke: GRID },\n              tickLabels: {\n                fontSize: 12,\n                fontWeight: (c) => (Math.floor(c.value / PER) === hi ? 600 : 400),\n              },\n              ticks: {\n                format: (v: number) => SPAN[Math.floor(v / PER)] ?? \"\",\n                padding: 8,\n                size: 0,\n                values: SPAN.map((_, i) => (i + 0.5) * PER),\n              },\n            },\n            scale: scaleLinear().domain([0, N - 1]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => `$${v}M`,\n                padding: 8,\n                size: 0,\n                values: [0, 20, 40, 60, 80],\n              },\n            },\n            grid: DASHED_GRID,\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [picked, hi],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[16px] leading-tight font-semibold tracking-[-0.01em]\">\n            Global finance market overview\n          </h3>\n          <p className=\"mt-1 text-[12px]\" style={{ color: MUTED }}>\n            2020-2027\n          </p>\n        </div>\n        <Chip icon={Download}>Export CSV</Chip>\n      </div>\n      <div className=\"-mx-5 mt-4 h-px\" style={{ backgroundColor: GRID }} />\n      <div className=\"mt-4 grid grid-cols-3 gap-2\">\n        {STATS.map((s) => (\n          <div key={s.label} className=\"rounded-[14px] bg-[#f6f6f7] px-2.5 py-2.5\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              {s.label}\n            </p>\n            <Num\n              value={s.value}\n              format={s.format}\n              className=\"mt-1 block text-[19px] font-semibold tracking-[-0.02em]\"\n            />\n            <Delta value={s.delta} variant=\"trend\" className=\"mt-1 text-[11px]\" />\n          </div>\n        ))}\n      </div>\n      <div className=\"mt-4 flex items-center gap-1\">\n        <Chip icon={Package} chevron className={TIGHT}>\n          All products\n        </Chip>\n        <Chip icon={List} chevron className={TIGHT}>\n          All category\n        </Chip>\n        <Chip icon={CalendarDays} chevron className={`${TIGHT} ml-auto`}>\n          Monthly\n        </Chip>\n      </div>\n      <div className=\"mt-3 flex items-center gap-4 text-[12px] text-[#3a3a42]\">\n        <span className=\"inline-flex items-center gap-1.5\">\n          <span className=\"h-1 w-4 rounded-full\" style={{ backgroundColor: GREEN }} />\n          Total AUM (Actual)\n        </span>\n        <span className=\"inline-flex items-center gap-1.5\">\n          <span className=\"h-0 w-4 border-t-[3px] border-dotted border-[#c9c9cf]\" />\n          Forecast\n        </span>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-2\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Total assets under management, actual against forecast, with monthly net flows\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.max(0, Math.min(SPAN.length - 1, Math.floor(x / PER))));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={((picked?.i ?? 0) / (N - 1)) * 100}\n            top={100 - ((picked?.v ?? 0) / TOP) * 100}\n            align={hi >= SPAN.length - 2 ? \"right\" : \"center\"}\n            dark\n            className=\"-mt-10 !px-2 !py-1 text-[11px]\"\n          >\n            <span className=\"text-white/60\">{SPAN[hi]}</span>{\" \"}\n            <span className=\"font-semibold tabular-nums\">{`$${(picked?.v ?? 0).toFixed(1)}M`}</span>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/global-finance-market-combo.tsx","target":"uicapsule/finance-charts/charts/global-finance-market-combo.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, dot, lineY, rect, ruleX, ruleY } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { CalendarDays, TrendingDown, TrendingUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, Chip, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, ORANGE, RED, THEME } from \"../lib/tokens\";\n\nconst FIRST = 2020;\nconst YEARS = 8;\nconst TOP = 80;\nconst STOPS = [3.5, 4.5, 5.5, 6.5, 7.5] as const;\nconst START = 3;\n\nconst SERIES = [\n  { id: \"aum\", plateau: 70 },\n  { id: \"mid\", plateau: 47 },\n  { id: \"low\", plateau: 32 },\n] as const;\n\ntype SeriesId = (typeof SERIES)[number][\"id\"];\n\nconst smooth = (t: number) => {\n  const c = Math.min(1, Math.max(0, t));\n\n  return c * c * (3 - 2 * c);\n};\n\nconst valueAt = (id: SeriesId, plateau: number, x: number) => {\n  const dip = -0.6 * Math.sin(Math.min(1, x / 1.4) * Math.PI);\n  const lift = id === \"aum\" ? smooth((x - 1.2) / 3.1) : smooth((x - 1.3) / 3.5);\n  const forecast = id === \"aum\" ? smooth(x - 6.5) * 4.8 : 0;\n\n  return 10 + dip + (plateau - 10) * lift + forecast;\n};\n\nconst MARGIN = { bottom: 26, left: 40, right: 6, top: 8 };\nconst HEIGHT = 240;\nconst curve = d3Curve(curveMonotoneX);\nconst yearLabel = (x: number) => String(FIRST + Math.floor(x));\nconst millions = (n: number) => `$${n.toFixed(1)}M`;\n\nexport const GlobalFinanceMarketForecast = () => {\n  const [stop, pin] = useCycle(STOPS.length, 2400, START);\n  const sx = STOPS[stop] ?? 6.5;\n  const year = FIRST + Math.floor(sx);\n  const headline = valueAt(\"aum\", 70, sx);\n\n  const definition = useMemo(() => {\n    const rows = SERIES.flatMap(({ id, plateau }) => {\n      const xs: number[] = [];\n\n      for (let x = 0; x < sx; x += 0.125) {\n        xs.push(x);\n      }\n\n      xs.push(sx);\n\n      return xs.map((x) => ({ key: `${id}-${x}`, s: id, v: valueAt(id, plateau, x), x }));\n    });\n\n    const heads = SERIES.map(({ id, plateau }) => ({ s: id, v: valueAt(id, plateau, sx), x: sx }));\n    const columns = Array.from({ length: YEARS + 1 }, (_, i) => i);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"gfm-line\",\n          stops: [\n            { color: \"#4ade80\", offset: 0 },\n            { color: \"#fbbf24\", offset: 0.3 },\n            { color: \"#fb923c\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n        {\n          id: \"gfm-band\",\n          stops: [\n            { color: ORANGE, offset: 0, opacity: 0.04 },\n            { color: ORANGE, offset: 1, opacity: 0.14 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n        {\n          id: \"gfm-scrub\",\n          stops: [\n            { color: ORANGE, offset: 0, opacity: 0.25 },\n            { color: ORANGE, offset: 0.12, opacity: 1 },\n            { color: ORANGE, offset: 0.7, opacity: 1 },\n            { color: ORANGE, offset: 1, opacity: 0 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      margin: MARGIN,\n      marks: [\n        ruleX(columns, { stroke: GRID, strokeOpacity: 1 }),\n        ruleY([20, 40, 60, 80], { stroke: GRID, strokeOpacity: 1 }),\n        ruleY([10, 30, 50, 70], { stroke: GRID, strokeDasharray: \"4 4\", strokeOpacity: 1 }),\n        rect([{ id: \"band\", v: headline }], {\n          fill: \"url(#gfm-band)\",\n          inset: 0,\n          key: \"id\",\n          x1: () => 0,\n          x2: () => sx,\n          y1: \"v\",\n          y2: () => TOP,\n        }),\n        lineY(\n          rows.filter((r) => r.s !== \"aum\"),\n          {\n            curve,\n            key: \"key\",\n            stroke: \"#d4d4d8\",\n            strokeWidth: 2.5,\n            x: \"x\",\n            y: \"v\",\n            z: \"s\",\n          },\n        ),\n        lineY(\n          rows.filter((r) => r.s === \"aum\"),\n          {\n            curve,\n            key: \"key\",\n            stroke: \"url(#gfm-line)\",\n            strokeWidth: 3,\n            x: \"x\",\n            y: \"v\",\n            z: \"s\",\n          },\n        ),\n        rect([{ id: \"scrub\", x: sx }], {\n          fill: \"url(#gfm-scrub)\",\n          inset: 0,\n          key: \"id\",\n          x1: (d) => d.x - 0.04,\n          x2: (d) => d.x + 0.04,\n          y1: () => 0,\n          y2: () => TOP + 2,\n        }),\n        dot(heads, {\n          fill: \"#ffffff\",\n          key: \"s\",\n          r: 5,\n          stroke: ORANGE,\n          strokeWidth: 2.5,\n          x: \"x\",\n          y: \"v\",\n        }),\n      ],\n      motion: { path: \"morph\" },\n      scales: {\n        x: {\n          axis: {\n            line: { stroke: \"#d4d4d8\" },\n            tickLabels: { fontSize: 11, fontWeight: (c) => (c.value === sx ? 600 : 400) },\n            ticks: {\n              format: yearLabel,\n              size: 0,\n              values: Array.from({ length: YEARS }, (_, i) => i + 0.5),\n            },\n          },\n          scale: scaleLinear().domain([0, YEARS]),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: {\n              format: (v: number) => (v === 0 ? \"$0\" : `$${v}M`),\n              size: 0,\n              values: [0, 20, 40, 60, 80],\n            },\n          },\n          scale: scaleLinear().domain([0, TOP + 2]),\n        },\n      },\n      theme: THEME,\n    });\n  }, [sx, headline]);\n\n  return (\n    <Card className=\"!p-0\">\n      <div className=\"p-5 pb-4\">\n        <div className=\"flex items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">\n              Global finance market overview\n            </h3>\n            <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n              2020-2027\n            </p>\n          </div>\n          <Chip icon={CalendarDays} chevron>\n            7 Years\n          </Chip>\n        </div>\n        <div className=\"mt-3 flex flex-wrap gap-1.5 text-[11px] font-medium\">\n          <span className=\"rounded-full border border-[#bbf7d0] bg-[#f0fdf4] px-2 py-0.5 text-[#16a34a]\">\n            0% YoY Growth\n          </span>\n          <span className=\"rounded-full border border-[#bfdbfe] bg-[#eff6ff] px-2 py-0.5 text-[#1d7cf2]\">\n            $70.0M AUM&apos;26\n          </span>\n          <span className=\"rounded-full border border-[#e9d5ff] bg-[#faf5ff] px-2 py-0.5 text-[#9333ea]\">\n            $74.8M AUM&apos;27\n          </span>\n        </div>\n      </div>\n      <div className=\"border-t px-5 pt-4 pb-4\" style={{ borderColor: GRID }}>\n        <div className=\"grid grid-cols-3 gap-2\">\n          <div className=\"rounded-xl bg-[#f6f6f7] px-2.5 py-2.5\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              Global AUM&apos;{String(year).slice(2)}\n            </p>\n            <Num\n              value={headline}\n              format={millions}\n              className=\"mt-1 block text-[18px] font-bold tracking-[-0.02em]\"\n            />\n            <p\n              className=\"mt-1 inline-flex items-center gap-1 text-[11px] font-medium\"\n              style={{ color: GREEN }}\n            >\n              <TrendingUp className=\"size-3\" />\n              <Num value={0} format={(n) => `${n.toFixed(2)}%`} />\n            </p>\n          </div>\n          <div className=\"rounded-xl bg-[#f6f6f7] px-2.5 py-2.5\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              Market growth\n            </p>\n            <Num\n              value={34}\n              format={(n) => `${Math.round(n)}%`}\n              className=\"mt-1 block text-[18px] font-bold tracking-[-0.02em]\"\n            />\n            <p\n              className=\"mt-1 inline-flex items-center gap-1 text-[11px] font-medium\"\n              style={{ color: RED }}\n            >\n              <TrendingDown className=\"size-3\" />\n              7.19%\n            </p>\n          </div>\n          <div className=\"rounded-xl bg-[#f6f6f7] px-2.5 py-2.5\">\n            <p className=\"truncate text-[11px]\" style={{ color: MUTED }}>\n              2027 Forecast\n            </p>\n            <Num\n              value={74.8}\n              format={millions}\n              className=\"mt-1 block text-[18px] font-bold tracking-[-0.02em]\"\n            />\n            <p\n              className=\"mt-1 inline-flex items-center gap-1 text-[11px] font-medium\"\n              style={{ color: GREEN }}\n            >\n              <TrendingUp className=\"size-3\" />\n              6.82%\n            </p>\n          </div>\n        </div>\n        <ChartSlot height={HEIGHT} className=\"mt-4\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Global assets under management, 2020 to 2027\"\n              onFocusChange={(p) => {\n                const x = Number(p?.xValue);\n\n                if (p && Number.isFinite(x)) {\n                  let best = 0;\n\n                  for (const [i, s] of STOPS.entries()) {\n                    if (Math.abs(s - x) < Math.abs((STOPS[best] ?? 0) - x)) {\n                      best = i;\n                    }\n                  }\n\n                  pin(best);\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/global-finance-market-forecast.tsx","target":"uicapsule/finance-charts/charts/global-finance-market-forecast.tsx","type":"registry:file"},{"content":"import { Balance } from \"./balance\";\nimport { CashFlowArea } from \"./cash-flow-area\";\nimport { CashFlowMonthlyBar } from \"./cash-flow-monthly-bar\";\nimport { CumulativeAssetsAndLiabilities } from \"./cumulative-assets-and-liabilities\";\nimport { CustomerRate } from \"./customer-rate\";\nimport type { ChartEntry } from \"./entry\";\nimport { Overview } from \"./overview\";\nimport { PriceRange } from \"./price-range\";\nimport { TotalExpenses } from \"./total-expenses\";\nimport { TotalSales } from \"./total-sales\";\n\nexport const GROUP_1: ChartEntry[] = [\n  { Chart: TotalExpenses, id: \"total-expenses\" },\n  { Chart: CashFlowArea, id: \"cash-flow-area\" },\n  { Chart: Overview, id: \"overview\" },\n  { Chart: PriceRange, id: \"price-range\" },\n  { Chart: Balance, id: \"balance\" },\n  { Chart: TotalSales, id: \"total-sales\" },\n  { Chart: CustomerRate, id: \"customer-rate\" },\n  { Chart: CumulativeAssetsAndLiabilities, id: \"cumulative-assets-and-liabilities\" },\n  { Chart: CashFlowMonthlyBar, id: \"cash-flow-monthly-bar\" },\n];\n","path":"/charts/group-1.ts","target":"uicapsule/finance-charts/charts/group-1.ts","type":"registry:file"},{"content":"import { Analytics } from \"./analytics\";\nimport { Budget } from \"./budget\";\nimport { CashBalance } from \"./cash-balance\";\nimport type { ChartEntry } from \"./entry\";\nimport { FinanceOverviewArea } from \"./finance-overview-area\";\nimport { FinancialBreakdown } from \"./financial-breakdown\";\nimport { FinancialTrends } from \"./financial-trends\";\nimport { InvestmentPerformance } from \"./investment-performance\";\nimport { NetWorth } from \"./net-worth\";\nimport { TotalBalance } from \"./total-balance\";\n\nexport const GROUP_2: ChartEntry[] = [\n  { Chart: CashBalance, id: \"cash-balance\" },\n  { Chart: NetWorth, id: \"net-worth\" },\n  { Chart: FinancialBreakdown, id: \"financial-breakdown\" },\n  { Chart: FinanceOverviewArea, id: \"finance-overview-area\" },\n  { Chart: TotalBalance, id: \"total-balance\" },\n  { Chart: Budget, id: \"budget\" },\n  { Chart: InvestmentPerformance, id: \"investment-performance\" },\n  { Chart: FinancialTrends, id: \"financial-trends\" },\n  { Chart: Analytics, id: \"analytics\" },\n];\n","path":"/charts/group-2.ts","target":"uicapsule/finance-charts/charts/group-2.ts","type":"registry:file"},{"content":"import { BudgetHealth } from \"./budget-health\";\nimport { BudgetOverview } from \"./budget-overview\";\nimport { BudgetPlan } from \"./budget-plan\";\nimport { CashFlowDailyBar } from \"./cash-flow-daily-bar\";\nimport { CategoryBreakdown } from \"./category-breakdown\";\nimport type { ChartEntry } from \"./entry\";\nimport { SalesTarget } from \"./sales-target\";\nimport { SpendingOverviewCylinder } from \"./spending-overview-cylinder\";\nimport { SpendingOverviewRange } from \"./spending-overview-range\";\nimport { YourAsset } from \"./your-asset\";\n\nexport const GROUP_3: ChartEntry[] = [\n  { Chart: CashFlowDailyBar, id: \"cash-flow-daily-bar\" },\n  { Chart: SpendingOverviewRange, id: \"spending-overview-range\" },\n  { Chart: BudgetOverview, id: \"budget-overview\" },\n  { Chart: SalesTarget, id: \"sales-target\" },\n  { Chart: YourAsset, id: \"your-asset\" },\n  { Chart: BudgetPlan, id: \"budget-plan\" },\n  { Chart: SpendingOverviewCylinder, id: \"spending-overview-cylinder\" },\n  { Chart: BudgetHealth, id: \"budget-health\" },\n  { Chart: CategoryBreakdown, id: \"category-breakdown\" },\n];\n","path":"/charts/group-3.ts","target":"uicapsule/finance-charts/charts/group-3.ts","type":"registry:file"},{"content":"import type { ChartEntry } from \"./entry\";\nimport { AssetOverviewRadial } from \"./asset-overview-radial\";\nimport { BudgetAllocation } from \"./budget-allocation\";\nimport { FinanceOverviewDivergingBar } from \"./finance-overview-diverging-bar\";\nimport { FinanceOverviewFlow } from \"./finance-overview-flow\";\nimport { InvestmentAppAdoptionByCountry } from \"./investment-app-adoption-by-country\";\nimport { OptionsPortfolio } from \"./options-portfolio\";\nimport { RevenueGrowth } from \"./revenue-growth\";\nimport { SavingProgress } from \"./saving-progress\";\nimport { ValueLocked } from \"./value-locked\";\n\nexport const GROUP_4: ChartEntry[] = [\n  { Chart: FinanceOverviewFlow, id: \"finance-overview-flow\" },\n  { Chart: ValueLocked, id: \"value-locked\" },\n  { Chart: SavingProgress, id: \"saving-progress\" },\n  { Chart: FinanceOverviewDivergingBar, id: \"finance-overview-diverging-bar\" },\n  { Chart: BudgetAllocation, id: \"budget-allocation\" },\n  { Chart: AssetOverviewRadial, id: \"asset-overview-radial\" },\n  { Chart: OptionsPortfolio, id: \"options-portfolio\" },\n  { Chart: RevenueGrowth, id: \"revenue-growth\" },\n  { Chart: InvestmentAppAdoptionByCountry, id: \"investment-app-adoption-by-country\" },\n];\n","path":"/charts/group-4.ts","target":"uicapsule/finance-charts/charts/group-4.ts","type":"registry:file"},{"content":"import { AverageSales } from \"./average-sales\";\nimport type { ChartEntry } from \"./entry\";\nimport { FinanceOverviewStackedBar } from \"./finance-overview-stacked-bar\";\nimport { FinanceOverviewTimeline } from \"./finance-overview-timeline\";\nimport { GlobalDefi } from \"./global-defi\";\nimport { GlobalFinanceMarketForecast } from \"./global-finance-market-forecast\";\nimport { InvestmentAppUserAge } from \"./investment-app-user-age\";\nimport { InvestmentGrowth } from \"./investment-growth\";\nimport { Performance } from \"./performance\";\nimport { RevenueByProductLine } from \"./revenue-by-product-line\";\n\nexport const GROUP_5: ChartEntry[] = [\n  { Chart: GlobalFinanceMarketForecast, id: \"global-finance-market-forecast\" },\n  { Chart: AverageSales, id: \"average-sales\" },\n  { Chart: Performance, id: \"performance\" },\n  { Chart: InvestmentGrowth, id: \"investment-growth\" },\n  { Chart: GlobalDefi, id: \"global-defi\" },\n  { Chart: InvestmentAppUserAge, id: \"investment-app-user-age\" },\n  { Chart: FinanceOverviewStackedBar, id: \"finance-overview-stacked-bar\" },\n  { Chart: FinanceOverviewTimeline, id: \"finance-overview-timeline\" },\n  { Chart: RevenueByProductLine, id: \"revenue-by-product-line\" },\n];\n","path":"/charts/group-5.ts","target":"uicapsule/finance-charts/charts/group-5.ts","type":"registry:file"},{"content":"import type { ChartEntry } from \"./entry\";\nimport { AssetAllocation } from \"./asset-allocation\";\nimport { AssetOverviewBar } from \"./asset-overview-bar\";\nimport { Expenses } from \"./expenses\";\nimport { GrowthTrends } from \"./growth-trends\";\nimport { MonthlyIncome } from \"./monthly-income\";\nimport { ProfitMarginAnalysis } from \"./profit-margin-analysis\";\nimport { ProjectBudgetAllocation } from \"./project-budget-allocation\";\nimport { SalesPerformance } from \"./sales-performance\";\nimport { TotalRevenue } from \"./total-revenue\";\n\nexport const GROUP_6: ChartEntry[] = [\n  { Chart: GrowthTrends, id: \"growth-trends\" },\n  { Chart: AssetAllocation, id: \"asset-allocation\" },\n  { Chart: ProfitMarginAnalysis, id: \"profit-margin-analysis\" },\n  { Chart: MonthlyIncome, id: \"monthly-income\" },\n  { Chart: AssetOverviewBar, id: \"asset-overview-bar\" },\n  { Chart: SalesPerformance, id: \"sales-performance\" },\n  { Chart: Expenses, id: \"expenses\" },\n  { Chart: TotalRevenue, id: \"total-revenue\" },\n  { Chart: ProjectBudgetAllocation, id: \"project-budget-allocation\" },\n];\n","path":"/charts/group-6.ts","target":"uicapsule/finance-charts/charts/group-6.ts","type":"registry:file"},{"content":"import type { ChartEntry } from \"./entry\";\nimport { Ethereum } from \"./ethereum\";\nimport { FinanceAnalytics } from \"./finance-analytics\";\nimport { GlobalFinanceMarketCombo } from \"./global-finance-market-combo\";\nimport { IncomeOverview } from \"./income-overview\";\nimport { PortfolioAllocation } from \"./portfolio-allocation\";\nimport { RevenueOverview } from \"./revenue-overview\";\nimport { SpendingOverviewScatter } from \"./spending-overview-scatter\";\n\nexport const GROUP_7: ChartEntry[] = [\n  { Chart: IncomeOverview, id: \"income-overview\" },\n  { Chart: SpendingOverviewScatter, id: \"spending-overview-scatter\" },\n  { Chart: GlobalFinanceMarketCombo, id: \"global-finance-market-combo\" },\n  { Chart: FinanceAnalytics, id: \"finance-analytics\" },\n  { Chart: Ethereum, id: \"ethereum\" },\n  { Chart: RevenueOverview, id: \"revenue-overview\" },\n  { Chart: PortfolioAllocation, id: \"portfolio-allocation\" },\n];\n","path":"/charts/group-7.ts","target":"uicapsule/finance-charts/charts/group-7.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, tickY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowDown, ArrowUp, ArrowUpRight } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, ORANGE, PURPLE, RED, THEME } from \"../lib/tokens\";\n\nconst WINDOW = 10;\nconst STEPS = 7;\nconst HEIGHT = 96;\n\ninterface Metric {\n  id: string;\n  title: string;\n  color: string;\n  series: number[];\n  change: number[];\n  amounts: number[];\n}\n\nconst METRICS: Metric[] = [\n  {\n    amounts: [163_747, 171_204, 168_930, 176_412, 181_055, 179_320, 186_904],\n    change: [48.45, 49.1, 47.82, 50.31, 51.2, 50.64, 52.4],\n    color: GREEN,\n    id: \"rev\",\n    series: [10, 20, 30, 42, 54, 62, 72, 82, 90, 100, 108, 118, 124, 134, 142, 150, 160],\n    title: \"Revenue growth\",\n  },\n  {\n    amounts: [48_975, 51_220, 46_310, 49_870, 44_905, 47_660, 50_120],\n    change: [-13.55, -11.2, -14.83, -12.1, -15.32, -13.04, -10.9],\n    color: PURPLE,\n    id: \"profit\",\n    series: [12, 72, 42, 82, 20, 28, 62, 88, 100, 52, 64, 30, 78, 46, 90, 58, 70],\n    title: \"Profit trend\",\n  },\n  {\n    amounts: [863, 912, 788, 845, 901, 760, 830],\n    change: [-14.29, -12.71, -15.1, -13.42, -11.8, -14.93, -12.2],\n    color: ORANGE,\n    id: \"expense\",\n    series: [86, 82, 64, 10, 18, 98, 70, 26, 60, 40, 72, 34, 88, 52, 20, 76, 58],\n    title: \"Expense efficiency\",\n  },\n];\n\nconst pct = (n: number) => `${n >= 0 ? \"+\" : \"-\"}${Math.abs(n).toFixed(2)}%`;\n\nconst Row = ({ metric, step }: { metric: Metric; step: number }) => {\n  const rows = useMemo(\n    () =>\n      metric.series.slice(step, step + WINDOW).map((value, i) => ({ id: `m${step + i}`, value })),\n    [metric, step],\n  );\n\n  const change = metric.change[step] ?? 0;\n  const top = Math.max(...rows.map((r) => r.value));\n  const amount = metric.amounts[step] ?? 0;\n  const up = change >= 0;\n  const gradient = `gt-${metric.id}`;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: gradient,\n            stops: [\n              { color: metric.color, offset: 0, opacity: 0.42 },\n              { color: metric.color, offset: 1, opacity: 0 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        guides: false,\n        margin: { bottom: 0, left: 0, right: 0, top: 2 },\n        marks: [\n          barY(rows, {\n            fill: `url(#${gradient})`,\n            key: \"id\",\n            x: \"id\",\n            y: \"value\",\n          }),\n          tickY(rows, {\n            key: \"id\",\n            stroke: metric.color,\n            strokeWidth: 2.5,\n            x: \"id\",\n            y: \"value\",\n          }),\n        ],\n        scales: {\n          x: {\n            scale: scaleBand<string>()\n              .domain(rows.map((r) => r.id))\n              .paddingInner(0.14)\n              .paddingOuter(0),\n          },\n          y: { scale: scaleLinear().domain([0, top]) },\n        },\n        theme: THEME,\n      }),\n    [rows, metric, gradient, top],\n  );\n\n  return (\n    <section className=\"py-4 first:pt-0 last:pb-0\" style={{ borderColor: GRID }}>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">{metric.title}</h3>\n        <span className=\"inline-flex size-7 items-center justify-center rounded-full border border-black/[0.08] text-[#8a8a93]\">\n          <ArrowUpRight className=\"size-3.5\" />\n        </span>\n      </div>\n      <div className=\"mt-1 flex items-end gap-4\">\n        <div className=\"w-[150px] shrink-0\">\n          <Num value={change} format={pct} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Vs last 6 months\n          </p>\n          <p\n            className=\"mt-3 flex items-center gap-1.5 whitespace-nowrap text-[11px]\"\n            style={{ color: MUTED }}\n          >\n            <span\n              className=\"inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-semibold\"\n              style={{\n                backgroundColor: up ? \"#dcfce7\" : \"#fee2e2\",\n                color: up ? GREEN : RED,\n              }}\n            >\n              <span\n                className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n                style={{ backgroundColor: up ? GREEN : RED }}\n              >\n                {up ? (\n                  <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n                ) : (\n                  <ArrowDown className=\"size-2\" strokeWidth={3.5} />\n                )}\n              </span>\n              <Num value={amount} format={(n) => usd(n, true)} />\n            </span>\n            This month\n          </p>\n        </div>\n        <ChartSlot height={HEIGHT} className=\"min-w-0 flex-1\">\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel={`${metric.title}, last ten months`}\n          />\n        </ChartSlot>\n      </div>\n    </section>\n  );\n};\n\nexport const GrowthTrends = () => {\n  const [step] = useCycle(STEPS, 2600);\n\n  return (\n    <Card className=\"divide-y divide-[#ececf0]\">\n      {METRICS.map((m) => (\n        <Row key={m.id} metric={m} step={step} />\n      ))}\n    </Card>\n  );\n};\n","path":"/charts/growth-trends.tsx","target":"uicapsule/finance-charts/charts/growth-trends.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barX, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, ArrowUpRight } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst QUARTERS = [\"Q1\", \"Q2\", \"Q3\", \"Q4\"] as const;\nconst VALUES = [76_400, 39_200, 32_300, 40_100] as const;\nconst TARGET = 100_000;\n\nconst MARGIN = { bottom: 30, left: 30, right: 2, top: 0 };\nconst HEIGHT = 228;\nconst PADDING = 0.26;\n\nconst rows = QUARTERS.map((q, i) => ({ q, target: TARGET, value: VALUES[i] ?? 0 }));\n\nconst bandCenter = (i: number) => (i + (1 - PADDING) / 2) / (QUARTERS.length - PADDING);\n\nconst wholeUsd = (n: number) => usd(n, true);\n\nexport const IncomeOverview = () => {\n  const [hi, pin] = useCycle(QUARTERS.length, 2100);\n  const picked = rows[hi] ?? rows[0];\n  const share = (picked?.value ?? 0) / TARGET;\n  const inside = share > 0.6;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"io-bar\",\n            stops: [\n              { color: \"#4b97f2\", offset: 0 },\n              { color: \"#62a7f6\", offset: 0.72 },\n              { color: \"#b9d8fc\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n          {\n            id: \"io-hot\",\n            stops: [\n              { color: \"#1f7ced\", offset: 0 },\n              { color: \"#3e93f4\", offset: 0.75 },\n              { color: \"#9cc9fb\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n        ],\n        margin: MARGIN,\n        marks: [\n          barX(rows, {\n            fill: \"#fafafa\",\n            id: \"track\",\n            key: \"q\",\n            radius: 9,\n            stroke: GRID,\n            strokeWidth: 1,\n            x: \"target\",\n            y: \"q\",\n          }),\n          barX(rows, {\n            fill: (d) => (d.q === picked?.q ? \"url(#io-hot)\" : \"url(#io-bar)\"),\n            id: \"value\",\n            key: \"q\",\n            radius: 9,\n            x: \"value\",\n            y: \"q\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => compact(v, \"\"),\n                padding: 10,\n                size: 0,\n                values: [0, 20_000, 40_000, 60_000, 80_000, 100_000],\n              },\n            },\n            scale: scaleLinear().domain([0, TARGET]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 13,\n                fontWeight: (c) => (c.value === picked?.q ? 600 : 400),\n              },\n              ticks: { padding: 8, size: 0 },\n            },\n            scale: scaleBand<string>()\n              .domain([...QUARTERS])\n              .paddingInner(PADDING)\n              .paddingOuter(0),\n          },\n        },\n        theme: THEME,\n      }),\n    [picked],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Income Overview</h3>\n        <MoreButton />\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: MUTED }}>\n        Total Revenue\n      </p>\n      <Num value={189_000} className=\"block text-[30px] font-bold tracking-[-0.03em]\" />\n      <div className=\"mt-1.5 flex items-center gap-2 text-[13px]\">\n        <span\n          className=\"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 font-medium\"\n          style={{ backgroundColor: \"#e3f6e9\", color: GREEN }}\n        >\n          <span\n            className=\"inline-flex size-3.5 items-center justify-center rounded-full text-white\"\n            style={{ backgroundColor: GREEN }}\n          >\n            <ArrowUp className=\"size-2.5\" strokeWidth={3} />\n          </span>\n          <Num value={163_747} format={wholeUsd} />\n        </span>\n        <span style={{ color: MUTED }}>vs last year</span>\n      </div>\n      <div className=\"my-4 h-px\" style={{ backgroundColor: GRID }} />\n      <p className=\"text-[14px] font-semibold\">Income Breakdown</p>\n      <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n        Tracking progress toward $100K quarterly targets\n      </p>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Quarterly income against a $100K target\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(rows.findIndex((r) => r.q === p.yValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={share * 100}\n            top={bandCenter(hi) * 100}\n            align={inside ? \"right\" : \"left\"}\n            dark={!inside}\n            className={`${inside ? \"-ml-1.5\" : \"ml-2\"} -translate-y-1/2 !rounded-full !px-2 !py-0.5 text-[11px] font-semibold`}\n          >\n            {`${compact(picked?.value ?? 0)} · ${Math.round(share * 100)}%`}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <button\n        type=\"button\"\n        className=\"mt-3 flex h-10 w-full items-center justify-center gap-1.5 rounded-full border text-[14px] font-medium text-[#3a3a42] transition-colors hover:bg-black/[0.02]\"\n        style={{ borderColor: GRID }}\n      >\n        See insight <ArrowUpRight className=\"size-4\" style={{ color: MUTED }} />\n      </button>\n    </Card>\n  );\n};\n","path":"/charts/income-overview.tsx","target":"uicapsule/finance-charts/charts/income-overview.tsx","type":"registry:file"},{"content":"import type { ChartEntry } from \"./entry\";\nimport { GROUP_1 } from \"./group-1\";\nimport { GROUP_2 } from \"./group-2\";\nimport { GROUP_3 } from \"./group-3\";\nimport { GROUP_4 } from \"./group-4\";\nimport { GROUP_5 } from \"./group-5\";\nimport { GROUP_6 } from \"./group-6\";\nimport { GROUP_7 } from \"./group-7\";\nimport { TotalValue } from \"./total-value\";\n\n/** Page order of the source kit. */\nexport const CHARTS: ChartEntry[] = [\n  { Chart: TotalValue, id: \"total-value\" },\n  ...GROUP_1,\n  ...GROUP_2,\n  ...GROUP_3,\n  ...GROUP_4,\n  ...GROUP_5,\n  ...GROUP_6,\n  ...GROUP_7,\n];\n","path":"/charts/index.ts","target":"uicapsule/finance-charts/charts/index.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, rect, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Earth } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  IconTile,\n  Legend,\n  MoreButton,\n  PlotOverlay,\n  muted,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN, MUTED, ORANGE, PURPLE, YELLOW } from \"../lib/tokens\";\n\nconst COUNTRIES = [\n  { color: ORANGE, deep: \"#e5600f\", label: \"USA\", light: \"#fb8a3c\" },\n  { color: PURPLE, deep: \"#9233ea\", label: \"India\", light: \"#bd7cfb\" },\n  { color: BLUE, deep: \"#0f67d8\", label: \"UK\", light: \"#4a9bf6\" },\n  { color: GREEN, deep: \"#13863d\", label: \"Canada\", light: \"#34c06a\" },\n  { color: YELLOW, deep: \"#e9a514\", label: \"Other\", light: \"#fcd05c\" },\n] as const;\n\nconst YEARS = [\n  { mix: [1.78, 1.6, 1.22, 1.03, 0.57], year: 2023 },\n  { mix: [3.42, 3.04, 2.38, 2, 1.56], year: 2024 },\n  { mix: [5.32, 3.99, 3.28, 2.93, 3.28], year: 2025 },\n] as const;\n\nconst CENTERS = [0.8, 5, 9.2] as const;\nconst HALF = 0.8;\nconst Y_MAX = 20.5;\nconst HEIGHT = 230;\nconst MARGIN = { bottom: 30, left: 0, right: 0, top: 4 };\n\ninterface Block {\n  country: number;\n  col: number;\n  c: number;\n  x1: number;\n  x2: number;\n  y1: number;\n  y2: number;\n}\n\nconst blocks: Block[] = YEARS.flatMap((y, col) => {\n  let acc = 0;\n\n  return y.mix.map((v, country) => {\n    const c = CENTERS[col] ?? 0;\n    const block = { c, col, country, x1: c - HALF, x2: c + HALF, y1: acc, y2: acc + v };\n    acc += v;\n\n    return block;\n  });\n});\n\nconst totals = YEARS.map((y, col) => ({\n  c: CENTERS[col] ?? 0,\n  col,\n  total: y.mix.reduce((a, b) => a + b, 0),\n  year: y.year,\n}));\n\nconst ribbon = (country: number) =>\n  blocks.flatMap((b) =>\n    b.country === country\n      ? [\n          { id: `${b.col}l`, x: b.x1, y1: b.y1, y2: b.y2 },\n          { id: `${b.col}r`, x: b.x2, y1: b.y1, y2: b.y2 },\n        ]\n      : [],\n  );\n\nconst gradients = COUNTRIES.map((c, i) => ({\n  id: `iaac-${i}`,\n  stops: [\n    { color: c.light, offset: 0 },\n    { color: c.color, offset: 0.45 },\n    { color: c.color, offset: 1 },\n  ],\n  y1: 0,\n  y2: 1,\n}));\n\nexport const InvestmentAppAdoptionByCountry = () => {\n  const [hi, pin] = useCycle(YEARS.length, 2400, 2);\n  const picked = totals[hi] ?? totals[2];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients,\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          ...COUNTRIES.map((c, i) =>\n            areaY(ribbon(i), {\n              fill: c.color,\n              fillOpacity: 0.09,\n              id: `ribbon-${i}`,\n              key: \"id\",\n              stroke: \"#ffffff\",\n              strokeWidth: 1.5,\n              x: \"x\",\n              y1: \"y1\",\n              y2: \"y2\",\n            }),\n          ),\n          ...COUNTRIES.map((c, i) =>\n            rect(\n              blocks.filter((b) => b.country === i),\n              {\n                fill: `url(#iaac-${i})`,\n                id: `bar-${i}`,\n                inset: 1.5,\n                key: \"col\",\n                radius: 6,\n                stroke: c.deep,\n                strokeWidth: 0.75,\n                x: \"c\",\n                x1: \"x1\",\n                x2: \"x2\",\n                y1: \"y1\",\n                y2: \"y2\",\n              },\n            ),\n          ),\n          text(totals, {\n            dy: -10,\n            fill: (d) => (d.col === hi ? ORANGE : MUTED),\n            fontSize: 14,\n            fontWeight: 600,\n            id: \"years\",\n            key: \"col\",\n            text: (d) => `${d.year}`,\n            x: \"c\",\n            y: \"total\",\n          }),\n          text(totals, {\n            dy: 18,\n            fill: (d) => (d.col === hi ? \"transparent\" : MUTED),\n            fontSize: 12,\n            id: \"totals\",\n            key: \"col\",\n            text: (d) => `${d.total.toFixed(1)}M`,\n            x: \"c\",\n            y: () => 0,\n          }),\n        ],\n        scales: {\n          x: { axis: false, scale: scaleLinear().domain([0, 10]) },\n          y: { axis: false, scale: scaleLinear().domain([0, Y_MAX]) },\n        },\n      }),\n    [hi],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start gap-3\">\n        <IconTile icon={Earth} color={ORANGE} size={40} className=\"!rounded-[12px]\" />\n        <div className=\"min-w-0 flex-1\">\n          <h3 className=\"text-[15px] leading-snug font-semibold tracking-[-0.01em]\">\n            Which country leads investment app adoption?\n          </h3>\n          <p className=\"mt-0.5 text-[12px]\" style={muted}>\n            Active investor\n          </p>\n        </div>\n        <MoreButton />\n      </div>\n      <Legend\n        items={COUNTRIES.map((c) => ({ color: c.color, label: c.label }))}\n        className=\"mt-4 [&_span>span]:size-2.5\"\n      />\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Active investors by country, 2023 to 2025\"\n            onFocusChange={(p) => {\n              if (p) {\n                const i = totals.findIndex((t) => t.c === p.xValue);\n\n                if (i !== -1) {\n                  pin(i);\n                }\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={((picked?.c ?? 0) / 10) * 100}\n            top={100}\n            dark\n            className=\"mt-1.5 !rounded-lg !px-2 !py-0.5 text-[12px] font-semibold\"\n          >\n            {`${(picked?.total ?? 0).toFixed(1)}M`}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/investment-app-adoption-by-country.tsx","target":"uicapsule/finance-charts/charts/investment-app-adoption-by-country.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { PiggyBank } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useId, useMemo } from \"react\";\n\nimport { Card, ChartSlot, IconTile, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED, ORANGE, SPRING, THEME } from \"../lib/tokens\";\n\nconst GROUPS = [\n  { born: [2002, 2008], label: \"18-24\", share: 22.6 },\n  { born: [1992, 2001], label: \"25-34\", share: 34.6 },\n  { born: [1982, 1991], label: \"35-44\", share: 19 },\n  { born: [1971, 1981], label: \"45-55\", share: 27.7 },\n  { born: [1961, 1970], label: \"56-65\", share: 23.7 },\n  { born: [1940, 1960], label: \"66+\", share: 12.2 },\n] as const;\n\nconst TOP = 40;\nconst HALF = 0.33;\nconst DEPTH = 0.9;\nconst HEIGHT = 200;\nconst MARGIN = { bottom: 0, left: 0, right: 0, top: 26 };\n\ntype Face = \"l\" | \"r\" | \"t\";\n\ninterface Pt {\n  face: Face;\n  g: string;\n  hot: boolean;\n  k: string;\n  x: number;\n  y1: number;\n  y2: number;\n}\n\nconst box = (i: number, v: number, id: string) => {\n  const l = i + 0.5 - HALF;\n  const c = i + 0.5;\n  const r = i + 0.5 + HALF;\n\n  const faces: [Face, number, number, number][] = [\n    [\"l\", l, 0, v],\n    [\"l\", c, 0, v - DEPTH],\n    [\"r\", c, 0, v - DEPTH],\n    [\"r\", r, 0, v],\n    [\"t\", l, v, v],\n    [\"t\", c, v - DEPTH, v + DEPTH],\n    [\"t\", r, v, v],\n  ];\n\n  return faces.map(([face, x, y1, y2], j) => ({\n    face,\n    g: `${id}-${face}`,\n    hot: id === \"hl\",\n    k: `${id}-${j}`,\n    x,\n    y1,\n    y2,\n  }));\n};\n\nconst COLD_FILL = { l: \"url(#ua-cold-l)\", r: \"url(#ua-cold-r)\", t: \"#ececee\" } as const;\nconst HOT_FILL = { l: \"url(#ua-hot-l)\", r: \"url(#ua-hot-r)\", t: \"#ffd8bd\" } as const;\nconst fillOf = (d: Pt) => (d.hot ? HOT_FILL : COLD_FILL)[d.face];\n\nconst fade = (id: string, color: string, top: number) => ({\n  id,\n  stops: [\n    { color, offset: 0, opacity: top },\n    { color, offset: 0.7, opacity: top * 0.55 },\n    { color, offset: 1, opacity: 0 },\n  ],\n  y1: 0,\n  y2: 1,\n});\n\nexport const InvestmentAppUserAge = () => {\n  const id = useId();\n  const [hi, pin] = useCycle(GROUPS.length, 2300, 1);\n  const group = GROUPS[hi] ?? GROUPS[1];\n\n  const definition = useMemo(() => {\n    const cold = GROUPS.flatMap((g, i) => box(i, g.share, `b${i}`));\n    const hot = box(hi, GROUPS[hi]?.share ?? 0, \"hl\");\n    const labels = GROUPS.map((g, i) => ({ i, label: `${g.share.toFixed(1)}%`, v: g.share }));\n\n    return defineChart({\n      gradients: [\n        fade(\"ua-cold-l\", \"#e4e4e7\", 0.75),\n        fade(\"ua-cold-r\", \"#ededef\", 0.6),\n        fade(\"ua-hot-l\", \"#fdba8c\", 1),\n        fade(\"ua-hot-r\", \"#fb8a3c\", 1),\n      ],\n      margin: MARGIN,\n      marks: [\n        areaY(cold, {\n          fill: fillOf,\n          fillOpacity: 1,\n          key: \"k\",\n          x: \"x\",\n          y1: \"y1\",\n          y2: \"y2\",\n          z: \"g\",\n        }),\n        areaY(hot, {\n          fill: fillOf,\n          fillOpacity: 1,\n          id: \"ua-hot\",\n          key: \"k\",\n          x: \"x\",\n          y1: \"y1\",\n          y2: \"y2\",\n          z: \"g\",\n        }),\n        text(labels, {\n          dy: -14,\n          fill: (d) => (d.i === hi ? ORANGE : \"#a1a1aa\"),\n          fontSize: 14,\n          fontWeight: 500,\n          key: \"i\",\n          text: \"label\",\n          x: (d) => d.i + 0.5,\n          y: \"v\",\n        }),\n      ],\n      motion: { path: \"morph\" },\n      scales: {\n        x: { axis: false, scale: scaleLinear().domain([0, GROUPS.length]) },\n        y: { axis: false, scale: scaleLinear().domain([0, TOP]) },\n      },\n      theme: THEME,\n    });\n  }, [hi]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"flex items-center gap-3\">\n          <IconTile icon={PiggyBank} color={ORANGE} size={40} className=\"!rounded-[12px]\" />\n          <div>\n            <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">\n              Age of investment app user?\n            </h3>\n            <p className=\"text-[12px]\" style={{ color: MUTED }}>\n              in 2026\n            </p>\n          </div>\n        </div>\n        <MoreButton />\n      </div>\n      <p className=\"mt-4 text-[12px]\" style={{ color: \"#a1a1aa\" }}>\n        People born between\n      </p>\n      <p className=\"mt-0.5 text-[28px] font-bold tracking-[-0.03em]\">\n        <Num value={group.born[0]} format={(n) => String(Math.round(n))} /> -{\" \"}\n        <Num value={group.born[1]} format={(n) => String(Math.round(n))} />\n      </p>\n      <div onMouseLeave={() => pin(null)}>\n        <ChartSlot height={HEIGHT} className=\"mt-2\">\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Share of investment app users by age group\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.min(GROUPS.length - 1, Math.max(0, Math.floor(x))));\n              }\n            }}\n          />\n        </ChartSlot>\n        <div className=\"mt-2 flex\">\n          {GROUPS.map((g, i) => (\n            <button\n              key={g.label}\n              type=\"button\"\n              onMouseEnter={() => pin(i)}\n              className=\"relative flex-1 py-1 text-[12px] font-medium\"\n              style={{ color: i === hi ? \"#ffffff\" : \"#a1a1aa\" }}\n            >\n              {i === hi ? (\n                <motion.span\n                  layoutId={`${id}-age`}\n                  transition={SPRING}\n                  className=\"absolute inset-x-0.5 inset-y-0 rounded-lg bg-[#262626]\"\n                />\n              ) : null}\n              <span className=\"relative\">{g.label}</span>\n            </button>\n          ))}\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/investment-app-user-age.tsx","target":"uicapsule/finance-charts/charts/investment-app-user-age.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Sparkles, TrendingUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, THEME } from \"../lib/tokens\";\n\nconst DAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"] as const;\nconst PER_DAY = 7;\nconst BARS = DAYS.length * PER_DAY;\nconst MID = [46, 60, 60, 41, 50] as const;\nconst PEAK = [48, 86, 104, 122, 86, 58, 104] as const;\nconst TIER_FILL = { dark: \"#16a34a\", light: \"#b9ebc9\", mid: \"#5fc683\" } as const;\n\ntype Tier = keyof typeof TIER_FILL;\n\nconst week = (seed: number, midAt: number, peakAt: number) => {\n  const r = rng(seed);\n\n  return Array.from({ length: BARS }, (_, i) => {\n    const m = MID[i - midAt];\n    const p = PEAK[i - peakAt];\n    let tier: Tier = \"light\";\n    let v = 6 + r() * 17;\n\n    if (p !== undefined) {\n      tier = \"dark\";\n      v = p;\n    } else if (m !== undefined) {\n      tier = \"mid\";\n      v = m;\n    }\n\n    return { i, tier, v };\n  });\n};\n\nconst WEEKS = [\n  { delta: 15.3, rows: week(41, 18, 31), total: 2350 },\n  { delta: 9.8, rows: week(42, 8, 22), total: 2085 },\n  { delta: 21.6, rows: week(43, 26, 38), total: 2712 },\n] as const;\n\nconst HEIGHT = 150;\nconst MARGIN = { bottom: 26, left: 0, right: 0, top: 4 };\n\nexport const InvestmentGrowth = () => {\n  const [w, pin] = useCycle(WEEKS.length, 3200);\n  const current = WEEKS[w] ?? WEEKS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          barY(current.rows, {\n            fill: (d) => TIER_FILL[d.tier],\n            key: \"i\",\n            radius: [2.5, 2.5, 0, 0],\n            x: \"i\",\n            y: \"v\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => DAYS[Math.floor(v / PER_DAY)] ?? \"\",\n                size: 0,\n                values: DAYS.map((_, d) => d * PER_DAY + 3),\n              },\n            },\n            scale: scaleBand<number>()\n              .domain(Array.from({ length: BARS }, (_, i) => i))\n              .paddingInner(0.32)\n              .paddingOuter(0),\n          },\n          y: { axis: false, scale: scaleLinear().domain([0, 126]) },\n        },\n        theme: THEME,\n      }),\n    [current],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"pt-1 text-[16px] font-semibold tracking-[-0.01em]\">Investment Growth</h3>\n        <MoreButton />\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: \"#52525b\" }}>\n        Total invested this week\n      </p>\n      <Num\n        value={current.total}\n        format={(n) => `$${Math.round(n).toLocaleString(\"en-US\")}`}\n        className=\"block text-[28px] font-bold tracking-[-0.03em]\"\n      />\n      <p className=\"mt-0.5 inline-flex items-center gap-1 text-[12px]\">\n        <TrendingUp className=\"size-3.5\" style={{ color: GREEN }} strokeWidth={2.4} />\n        <Num\n          value={current.delta}\n          format={(n) => `${n.toFixed(1)}%`}\n          className=\"font-medium\"\n          style={{ color: GREEN }}\n        />\n        <span style={{ color: \"#52525b\" }}>Last Week</span>\n      </p>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseEnter={() => pin(w)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Amount invested through the week\"\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-3 flex items-center gap-2 rounded-xl border border-black/[0.07] bg-[#fafafa] px-3 py-2.5 text-[12px]\">\n        <Sparkles className=\"size-4 shrink-0 fill-[#f97316] text-[#f97316]\" />\n        <p className=\"leading-snug\">\n          <span className=\"font-semibold\">Insights:</span>{\" \"}\n          <span className=\"text-[#52525b]\">Portfolio grew steadily towards the weekend</span>\n        </p>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/investment-growth.tsx","target":"uicapsule/finance-charts/charts/investment-growth.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { arrow, defineChart, dot, lineY, ruleX } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ArrowUp, CreditCard } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, MONTHS, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  IconTile,\n  Legend,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, INK, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst STOCK = \"#a334fa\";\n\nconst SERIES = [\n  {\n    color: STOCK,\n    label: \"Stock portfolio\",\n    values: [\n      28_520, 28_540, 32_180, 35_369.72, 38_100, 40_050, 41_200, 43_350, 43_300, 46_250, 46_820,\n      44_800,\n    ],\n  },\n  {\n    color: BLUE,\n    label: \"Bonds portfolio\",\n    values: [\n      25_010, 23_050, 26_980, 25_006.34, 23_620, 24_050, 26_020, 31_100, 36_050, 36_120, 37_600,\n      40_600,\n    ],\n  },\n  {\n    color: ORANGE,\n    label: \"Cash portfolio\",\n    values: [\n      20_620, 24_180, 23_640, 21_981.52, 20_780, 20_640, 24_020, 23_240, 27_380, 25_640, 30_600,\n      32_700,\n    ],\n  },\n] as const;\n\nconst ROWS = SERIES.flatMap((s) =>\n  s.values.map((value, m) => ({ id: `${s.label}-${m}`, m, series: s.label, value })),\n);\n\nconst MONTH_IDX = MONTHS.map((_, i) => i);\n\nconst LONG_MONTHS = [\n  \"January\",\n  \"February\",\n  \"March\",\n  \"April\",\n  \"May\",\n  \"June\",\n  \"July\",\n  \"August\",\n  \"September\",\n  \"October\",\n  \"November\",\n  \"December\",\n];\n\nconst FIRST_WEEKDAY = [\n  \"Thursday\",\n  \"Sunday\",\n  \"Sunday\",\n  \"Wednesday\",\n  \"Friday\",\n  \"Monday\",\n  \"Wednesday\",\n  \"Saturday\",\n  \"Tuesday\",\n  \"Thursday\",\n  \"Sunday\",\n  \"Tuesday\",\n];\n\nconst TOP = 60_000;\nconst HEIGHT = 260;\nconst MARGIN = { bottom: 28, left: 46, right: 6, top: 6 };\nconst GRID_STYLE = { stroke: \"#e6e6ea\", strokeOpacity: 1, strokeWidth: 1 };\n\nexport const InvestmentPerformance = () => {\n  const [month, pin] = useCycle(12, 2100, 3);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        color: { domain: SERIES.map((s) => s.label), range: SERIES.map((s) => s.color) },\n        margin: MARGIN,\n        marks: [\n          ruleX([month], {\n            stroke: INK,\n            strokeDasharray: \"3 3\",\n            strokeOpacity: 0.85,\n            strokeWidth: 1.2,\n          }),\n          arrow(\n            [\n              { id: \"top\", y1: TOP + 600, y2: TOP - 1600 },\n              { id: \"bottom\", y1: -600, y2: 1600 },\n            ],\n            {\n              headAngle: 38,\n              headLength: 5,\n              key: \"id\",\n              stroke: INK,\n              strokeWidth: 1.2,\n              x1: () => month,\n              x2: () => month,\n              y1: \"y1\",\n              y2: \"y2\",\n            },\n          ),\n          lineY(ROWS, {\n            color: \"series\",\n            curve: d3Curve(curveMonotoneX),\n            key: \"id\",\n            strokeWidth: 2.4,\n            x: \"m\",\n            y: \"value\",\n            z: \"series\",\n          }),\n          dot(\n            ROWS.filter((r) => r.m === month),\n            {\n              color: \"series\",\n              key: \"series\",\n              r: 4,\n              stroke: \"#ffffff\",\n              strokeWidth: 2,\n              x: \"m\",\n              y: \"value\",\n            },\n          ),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: { stroke: \"#d4d4da\" },\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === month ? 600 : 400),\n              },\n              ticks: {\n                format: (v: number) => MONTHS[v] ?? \"\",\n                line: { stroke: \"#3f3f46\" },\n                size: 5,\n                values: MONTH_IDX,\n              },\n            },\n            grid: GRID_STYLE,\n            scale: scaleLinear().domain([0, 11]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v: number) => compact(v),\n                line: { stroke: \"#3f3f46\" },\n                size: 5,\n                values: [0, 10_000, 20_000, 30_000, 40_000, 50_000, 60_000],\n              },\n            },\n            grid: GRID_STYLE,\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [month],\n  );\n\n  const right = month < 6;\n  const x = (month / 11) * 100;\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between\">\n        <div className=\"flex items-center gap-2.5\">\n          <IconTile icon={CreditCard} color={STOCK} className=\"!rounded-full\" />\n          <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">Investment performance</h3>\n        </div>\n        <MoreButton />\n      </div>\n      <p className=\"mt-5 text-[12px]\" style={{ color: MUTED }}>\n        Total balance\n      </p>\n      <Num value={118_008.37} className=\"mt-0.5 block text-[30px] font-bold tracking-[-0.03em]\" />\n      <div className=\"mt-1.5 flex flex-wrap items-center justify-between gap-2\">\n        <span className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 text-[12px] font-medium text-[#16a34a]\">\n          <span className=\"inline-flex size-3.5 items-center justify-center rounded-full bg-[#16a34a] text-white\">\n            <ArrowUp className=\"size-2.5\" strokeWidth={3.2} />\n          </span>\n          2.71%\n        </span>\n        <Legend\n          items={SERIES.map((s) => ({ color: s.color, label: s.label.replace(\" portfolio\", \"\") }))}\n          className=\"!gap-x-2.5 text-[11.5px]\"\n        />\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Stock, bonds and cash portfolio value by month\"\n            onFocusChange={(p) => {\n              const m = Number(p?.xValue);\n\n              if (p && Number.isInteger(m)) {\n                pin(m);\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={right ? x + 2.5 : x - 2.5}\n            top={15}\n            dark\n            align={right ? \"left\" : \"right\"}\n            className=\"!rounded-[12px] !p-0\"\n          >\n            <p className=\"border-b border-white/10 px-3 py-1.5 text-[11px] text-white/80\">\n              {FIRST_WEEKDAY[month]}, {LONG_MONTHS[month]} 1\n            </p>\n            <div className=\"px-3 py-1.5\">\n              {SERIES.map((s) => (\n                <p key={s.label} className=\"flex items-center gap-1.5 py-0.5 text-[11px]\">\n                  <span className=\"size-2 rounded-full\" style={{ backgroundColor: s.color }} />\n                  <span className=\"text-white/70\">{s.label.replace(\" portfolio\", \"\")}</span>\n                  <span className=\"ml-auto pl-3 font-semibold tabular-nums\">\n                    {usd(s.values[month] ?? 0)}\n                  </span>\n                </p>\n              ))}\n            </div>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/investment-performance.tsx","target":"uicapsule/finance-charts/charts/investment-performance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { polar, radialArc, radialDot } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, Briefcase, Package, Palette } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst HEIGHT = 150;\nconst SIZE = 480;\nconst TOP = 24;\nconst SWEEP = 1;\nconst GAP = 0.1;\nconst TRACK_W = 13;\n\ninterface Month {\n  progress: number;\n  sources: [number, number, number];\n}\n\nconst MONTHS: Month[] = [\n  { progress: 0.5, sources: [2100, 1250, 550] },\n  { progress: 0.62, sources: [2650, 1250, 940] },\n  { progress: 0.41, sources: [1500, 1250, 420] },\n  { progress: 0.56, sources: [2300, 1250, 780] },\n];\n\nconst SOURCES: { label: string; icon: LucideIcon; color: string }[] = [\n  { color: \"#ea4c89\", icon: Palette, label: \"UI/UX Freelance Project\" },\n  { color: \"#0a66c2\", icon: Briefcase, label: \"Retainer Design Studio\" },\n  { color: \"#e3242b\", icon: Package, label: \"Digital Asset Sales\" },\n];\n\nexport const MonthlyIncome = () => {\n  const [m] = useCycle(MONTHS.length, 2800);\n  const month = MONTHS[m] ?? MONTHS[0];\n  const progress = month?.progress ?? 0;\n  const total = (month?.sources ?? [0, 0, 0]).reduce((s, v) => s + v, 0);\n  const knob = -SWEEP + progress * 2 * SWEEP;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"mi-fill\",\n            stops: [\n              { color: \"#bbf7d0\", offset: 0 },\n              { color: \"#22c55e\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n          {\n            id: \"mi-knob\",\n            stops: [\n              { color: \"#86efac\", offset: 0 },\n              { color: \"#16a34a\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 0,\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        guides: false,\n        margin: 0,\n        marks: [\n          polar({\n            endAngle: Math.PI,\n            marks: [\n              radialArc(\n                [\n                  { endAngle: knob - GAP, id: \"done\", startAngle: -SWEEP - 0.6 },\n                  { endAngle: SWEEP + 0.6, id: \"left\", startAngle: knob + GAP },\n                ],\n                {\n                  cornerRadius: TRACK_W / 2,\n                  fill: (d) => (d.id === \"done\" ? \"url(#mi-fill)\" : \"#dcdcdf\"),\n                  innerRadius: ({ radius }) => radius - TOP - TRACK_W,\n                  key: \"id\",\n                  outerRadius: ({ radius }) => radius - TOP,\n                },\n              ),\n              radialDot([{ a: knob, id: \"knob\", r: 1 }], {\n                angle: \"a\",\n                fill: \"#ffffff\",\n                key: \"id\",\n                r: 13,\n                radius: \"r\",\n                stroke: \"url(#mi-knob)\",\n                strokeWidth: 6,\n              }),\n            ],\n            scales: {\n              angle: { scale: scaleLinear().domain([-Math.PI, Math.PI]) },\n              radius: {\n                range: [0, ({ radius }) => radius - TOP - TRACK_W / 2],\n                scale: scaleLinear().domain([0, 1]),\n              },\n            },\n            startAngle: -Math.PI,\n          }),\n        ],\n        scales: { x: null, y: null },\n        theme: THEME,\n      }),\n    [knob],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Monthly Income</h3>\n        <MoreButton />\n      </div>\n      <ChartSlot height={HEIGHT} className=\"-mx-5 mt-1 overflow-hidden\">\n        <div className=\"absolute top-0 left-1/2 -translate-x-1/2\" style={{ width: SIZE }}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            width={SIZE}\n            height={SIZE}\n            ariaLabel=\"Monthly income progress toward target\"\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"relative -mt-[78px] text-center\">\n        <Num\n          value={total}\n          format={(n) => compact(n)}\n          className=\"text-[34px] font-bold tracking-[-0.03em]\"\n        />\n        <p className=\"mt-0.5 text-[13px]\">\n          <Num\n            value={progress * 100}\n            format={(n) => `+${Math.round(n)}%`}\n            className=\"font-semibold\"\n            style={{ color: GREEN }}\n          />{\" \"}\n          of monthly target\n        </p>\n      </div>\n      <div className=\"mt-7 border-t pt-4\" style={{ borderColor: GRID }}>\n        <p className=\"text-[14px] font-semibold\">Income Sources</p>\n        <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n          Monthly recurring revenue and freelance project mockups.\n        </p>\n        <ul className=\"mt-3 flex flex-col gap-2\">\n          {SOURCES.map((s, i) => (\n            <li\n              key={s.label}\n              className=\"flex items-center gap-2.5 rounded-xl border bg-[#fafafa] px-3 py-2.5 text-[13px]\"\n              style={{ borderColor: GRID }}\n            >\n              <span\n                className=\"inline-flex size-5 items-center justify-center rounded-md text-white\"\n                style={{ backgroundColor: s.color }}\n              >\n                <s.icon className=\"size-3\" strokeWidth={2.5} />\n              </span>\n              <span className=\"flex-1 text-[#3a3a42]\">{s.label}</span>\n              <Num\n                value={month?.sources[i] ?? 0}\n                format={(n) => `+${usd(n, true)}`}\n                className=\"text-[#3a3a42]\"\n              />\n            </li>\n          ))}\n        </ul>\n        <button\n          type=\"button\"\n          className=\"mt-2 flex w-full items-center justify-center gap-1.5 rounded-xl border py-2 text-[13px] text-[#3a3a42]\"\n          style={{ borderColor: GRID }}\n        >\n          See insight <ArrowUpRight className=\"size-3.5\" style={{ color: MUTED }} />\n        </button>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/monthly-income.tsx","target":"uicapsule/finance-charts/charts/monthly-income.tsx","type":"registry:file"},{"content":"import type { ChartGradient } from \"@tanstack/charts\";\n\n/**\n * Chart specs declare gradients but not patterns, so a hatch is a linear\n * gradient of hard stops. Gradients use the painted box as their unit square;\n * passing the box's expected pixel size keeps the stripes leaning at one angle\n * (and one pitch) whatever the bar's height.\n */\nexport const stripes = ({\n  id,\n  base,\n  line,\n  width,\n  height,\n  pitch = 7,\n  lean = 1.6,\n  duty = 0.4,\n}: {\n  id: string;\n  /** Ground color between stripes. */\n  base: string;\n  /** Stripe color. */\n  line: string;\n  /** Expected painted width in px. */\n  width: number;\n  /** Expected painted height in px. */\n  height: number;\n  /** Stripe period in px. */\n  pitch?: number;\n  /** Stripe slope: rise per px of run. */\n  lean?: number;\n  /** Fraction of each period painted `line`. */\n  duty?: number;\n}) => {\n  const w = Math.max(1, width);\n  const h = Math.max(1, height);\n  const gx = (lean * w) / h;\n  const span = (lean * gx * w + h) / ((gx * gx + 1) * Math.sqrt(1 + lean * lean));\n  const periods = Math.max(1, Math.round(span / pitch));\n  const stops: { color: string; offset: number }[] = [];\n\n  for (let i = 0; i < periods; i += 1) {\n    const a = i / periods;\n    const b = (i + duty) / periods;\n    const c = (i + 1) / periods;\n    stops.push(\n      { color: line, offset: a },\n      { color: line, offset: b },\n      { color: base, offset: b },\n      { color: base, offset: c },\n    );\n  }\n\n  return { id, stops, x1: 0, x2: gx, y1: 0, y2: 1 } satisfies ChartGradient;\n};\n","path":"/charts/net-worth-stripes.ts","target":"uicapsule/finance-charts/charts/net-worth-stripes.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { bandX, barY, defineChart, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, CircleArrowOutUpRight } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  CardHeader,\n  ChartSlot,\n  Chip,\n  Caption,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, THEME } from \"../lib/tokens\";\nimport { stripes } from \"./net-worth-stripes\";\n\nconst VALUES = [\n  2650, 3700, 8500, 13_450, 19_400, 16_600, 25_833.33, 23_300, 17_200, 2700, 3400, 4700, 11_800,\n];\n\nconst WEEKDAY = [\"Fri\", \"Sat\", \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\"] as const;\n\nconst ROWS = VALUES.map((value, i) => ({\n  day: i + 1,\n  value,\n  weekday: WEEKDAY[i % 7] ?? \"Mon\",\n}));\n\nconst DAYS = ROWS.map((r) => r.day);\n\nconst TOP = 30_000;\nconst HEIGHT = 230;\nconst MARGIN = { bottom: 26, left: 40, right: 0, top: 8 };\nconst PLOT_H = HEIGHT - MARGIN.top - MARGIN.bottom;\nconst BAR_W = 14;\n\nconst GRADIENTS = ROWS.flatMap((r) => {\n  const height = (r.value / TOP) * PLOT_H;\n\n  return [\n    stripes({\n      base: \"#e0e0e4\",\n      height,\n      id: `nw-idle-${r.day}`,\n      line: \"#d5d5da\",\n      width: BAR_W,\n    }),\n    stripes({\n      base: \"#16a34a\",\n      height,\n      id: `nw-hot-${r.day}`,\n      line: \"#22c55e\",\n      width: BAR_W,\n    }),\n  ];\n});\n\nexport const NetWorth = () => {\n  const [hi, pin] = useCycle(ROWS.length, 1900, 6);\n  const picked = ROWS[hi] ?? ROWS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: GRADIENTS,\n        margin: MARGIN,\n        marks: [\n          bandX([picked], {\n            fill: GREEN,\n            fillOpacity: 0.1,\n            inset: -3,\n            key: () => \"band\",\n            x: (d) => d?.day ?? 1,\n          }),\n          ruleY([0], { stroke: \"#e4e4e8\", strokeOpacity: 1, strokeWidth: 1 }),\n          ruleY([10_000, 20_000, 30_000], {\n            stroke: \"#dcdce2\",\n            strokeDasharray: \"5 5\",\n            strokeOpacity: 1,\n            strokeWidth: 1,\n          }),\n          barY(ROWS, {\n            fill: (d) =>\n              d.day === picked?.day ? `url(#nw-hot-${d.day})` : `url(#nw-idle-${d.day})`,\n            key: \"day\",\n            radius: [5, 5, 0, 0],\n            x: \"day\",\n            y: \"value\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === picked?.day ? 600 : 400),\n                thin: false,\n              },\n              ticks: { format: (d: number) => `${d}`, size: 0 },\n            },\n            scale: scaleBand<number>().domain(DAYS).paddingInner(0.38).paddingOuter(0.1),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v: number) => compact(v),\n                size: 0,\n                values: [0, 10_000, 20_000, 30_000],\n              },\n            },\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [picked],\n  );\n\n  const center = ((hi + 0.1 + 0.31) / (ROWS.length - 0.38 + 0.2)) * 100;\n  let align: \"center\" | \"left\" | \"right\" = \"center\";\n\n  if (hi <= 1) {\n    align = \"left\";\n  } else if (hi >= ROWS.length - 2) {\n    align = \"right\";\n  }\n\n  const barTop = 100 - ((picked?.value ?? 0) / TOP) * 100;\n\n  return (\n    <Card>\n      <CardHeader\n        icon={CircleArrowOutUpRight}\n        color={GREEN}\n        title=\"Net worth\"\n        actions={\n          <Chip>\n            View data <ArrowUpRight className=\"size-3.5\" />\n          </Chip>\n        }\n      />\n      <Num value={18_645.16} className=\"mt-5 block text-[30px] font-bold tracking-[-0.03em]\" />\n      <Caption info className=\"mt-0.5 !text-[13px]\">\n        Total net worth\n      </Caption>\n\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Net worth by day, May 1 to May 13\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(ROWS.findIndex((r) => r.day === p.xValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={center}\n            top={barTop < 55 ? Math.min(70, barTop + 28) : barTop - 32}\n            dark\n            align={align}\n            className=\"!rounded-[10px] !px-3 !py-2\"\n          >\n            <p className=\"text-[11px] text-white/70\">\n              {picked?.weekday}, May {picked?.day}\n            </p>\n            <p className=\"text-[14px] font-semibold tabular-nums\">{usd(picked?.value ?? 0)}</p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <p className=\"mt-1 text-center text-[11px] text-[#a1a1aa]\">May 2026</p>\n    </Card>\n  );\n};\n","path":"/charts/net-worth.tsx","target":"uicapsule/finance-charts/charts/net-worth.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Activity, ChartColumnBig, ChartLine, ChartPie, Coins } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useId, useMemo } from \"react\";\n\nimport { usd, walk } from \"../lib/data\";\nimport { Card, ChartSlot, IconTile, Num, muted, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GREEN, INK, MUTED, PURPLE, SPRING } from \"../lib/tokens\";\n\nconst BARS = 48;\nconst HEIGHT = 200;\nconst REST = 0.72;\n\nconst GROUPS = [\n  { fill: \"#e7f1fd\", label: \"Cash & equivalents\", share: 42, stroke: \"#b9d7f8\" },\n  { fill: \"#7db6f6\", label: \"Equities\", share: 31, stroke: \"#5c9fef\" },\n  { fill: \"#2f88f1\", label: \"Fixed income\", share: 27, stroke: \"#196ed9\" },\n] as const;\n\nconst STARTS = (() => {\n  const out: number[] = [];\n  let acc = 0;\n\n  for (const g of GROUPS) {\n    out.push(Math.round((acc / 100) * BARS));\n    acc += g.share;\n  }\n\n  return out;\n})();\n\nconst groupOf = (i: number) => {\n  let g = 0;\n\n  for (const [k, s] of STARTS.entries()) {\n    if (i >= s) {\n      g = k;\n    }\n  }\n\n  return g;\n};\n\nconst TREND = walk(BARS, 9, { drift: 0.004, max: 0.74, min: 0.3, start: 0.45, vol: 0.06 });\nconst bars = Array.from({ length: BARS }, (_, i) => i);\n\nconst STATS: {\n  label: string;\n  value: number;\n  format: (n: number) => string;\n  icon: LucideIcon;\n  color: string;\n}[] = [\n  { color: PURPLE, format: (n) => usd(n), icon: Coins, label: \"Cash balance\", value: 10_472.95 },\n  {\n    color: BLUE,\n    format: (n) => `${n.toFixed(2)}%`,\n    icon: Activity,\n    label: \"Total return\",\n    value: 5.86,\n  },\n  { color: GREEN, format: (n) => `${Math.round(n)}`, icon: ChartPie, label: \"Assets\", value: 16 },\n];\n\nconst MODES: LucideIcon[] = [ChartColumnBig, ChartLine];\n\nexport const OptionsPortfolio = () => {\n  const [mode, pin] = useCycle(MODES.length, 3400);\n  const id = useId();\n\n  const definition = useMemo(() => {\n    const rows = bars.map((i) => {\n      const group = groupOf(i);\n      const marker = STARTS[group] === i;\n      let h = mode === 0 ? REST : (TREND[i] ?? REST);\n\n      if (marker) {\n        h = 1;\n      }\n\n      return { group, h, i };\n    });\n\n    const labels = GROUPS.map((g, k) => ({ ...g, i: STARTS[k] ?? 0, k }));\n\n    return defineChart({\n      guides: false,\n      margin: { bottom: 1, left: 1, right: 1, top: 1 },\n      marks: [\n        barY(rows, {\n          fill: (d) => GROUPS[d.group]?.fill ?? \"#e7f1fd\",\n          key: \"i\",\n          radius: 3,\n          stroke: (d) => GROUPS[d.group]?.stroke ?? \"#b9d7f8\",\n          strokeWidth: 1,\n          x: \"i\",\n          y: \"h\",\n        }),\n        text(labels, {\n          anchor: \"start\",\n          dx: 5,\n          fill: MUTED,\n          fontSize: 11,\n          key: \"k\",\n          text: \"label\",\n          x: \"i\",\n          y: () => 0.94,\n        }),\n        text(labels, {\n          anchor: \"start\",\n          dx: 5,\n          fill: INK,\n          fontSize: 12,\n          fontWeight: 500,\n          id: \"shares\",\n          key: \"k\",\n          text: (d) => `${d.share}%`,\n          x: \"i\",\n          y: () => 0.84,\n        }),\n      ],\n      scales: {\n        x: {\n          axis: false,\n          scale: scaleBand<number>().domain(bars).paddingInner(0.38).paddingOuter(0),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, 1]) },\n      },\n    });\n  }, [mode]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div>\n          <p className=\"text-[12px] font-medium tracking-[0.02em] uppercase\" style={muted}>\n            Options portfolio\n          </p>\n          <Num\n            value={24_835.58}\n            className=\"mt-0.5 block text-[28px] font-semibold tracking-[-0.03em]\"\n          />\n        </div>\n        <div className=\"flex rounded-full bg-[#f2f2f5] p-0.5\">\n          {MODES.map((Icon, i) => (\n            <button\n              key={Icon.displayName ?? i}\n              type=\"button\"\n              aria-label={i === 0 ? \"Bar view\" : \"Trend view\"}\n              onClick={() => pin(i)}\n              className=\"relative inline-flex h-7 w-10 items-center justify-center rounded-full\"\n              style={{ color: i === mode ? INK : MUTED }}\n            >\n              {i === mode ? (\n                <motion.span\n                  layoutId={`${id}-thumb`}\n                  transition={SPRING}\n                  className=\"absolute inset-0 rounded-full bg-white shadow-[0_1px_3px_rgba(0,0,0,0.1)] ring-1 ring-black/[0.04]\"\n                />\n              ) : null}\n              <Icon className=\"relative size-4\" strokeWidth={2.4} />\n            </button>\n          ))}\n        </div>\n      </div>\n      <div className=\"mt-4 grid grid-cols-3 gap-2\">\n        {STATS.map((s) => (\n          <div key={s.label} className=\"min-w-0\">\n            <IconTile icon={s.icon} color={s.color} size={30} className=\"!rounded-full\" />\n            <div className=\"mt-2 min-w-0\">\n              <p className=\"truncate text-[12px]\" style={muted}>\n                {s.label}\n              </p>\n              <Num\n                value={s.value}\n                format={s.format}\n                className=\"block truncate text-[15px] font-semibold\"\n              />\n            </div>\n          </div>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)} onMouseEnter={() => pin(mode)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Allocation: cash 42%, equities 31%, fixed income 27%\"\n          />\n        </div>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/options-portfolio.tsx","target":"uicapsule/finance-charts/charts/options-portfolio.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, link, rect } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Info, Plus, X } from \"lucide-react\";\nimport { useMemo, useState } from \"react\";\n\nimport { MONTHS, usd, uniform } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  Delta,\n  Num,\n  PlotOverlay,\n  Segmented,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, MUTED } from \"../lib/tokens\";\n\nconst N = 60;\nconst WINDOW = 16;\nconst QUARTERS = [\"Q1\", \"Q2\", \"Q3\"] as const;\nconst DAYS_PER_BAR = 1.5;\n\nconst SERIES = QUARTERS.map((_, q) => {\n  const noise = uniform(N, 90 + q * 13, 0, 1);\n\n  return noise.map((n, i) => ({\n    i,\n    value: 520 + 190 * Math.sin(i / 6.5 + q * 1.7) + 120 * Math.sin(i / 2.3 + q) + 260 * n,\n  }));\n});\n\nconst FIRST = SERIES[0] ?? [];\nconst MAX = 1120;\nconst BRUSH_TOP = -90;\nconst BRUSH_BOTTOM = -190;\nconst MIN = -205;\nconst STARTS = [24, 36, 44, 8, 16] as const;\nconst MONTH_TICKS = [10, 30, 50] as const;\n\nconst MARGIN = { bottom: 26, left: 0, right: 0, top: 8 };\nconst HEIGHT = 230;\n\nconst dateFor = (q: number, i: number) => {\n  const d = new Date(2026, q * 3, 1);\n  d.setDate(d.getDate() + Math.round(i * DAYS_PER_BAR));\n\n  return d;\n};\n\nconst fmtDay = (d: Date) => d.toLocaleString(\"en-US\", { day: \"numeric\", month: \"short\" });\n\nexport const Overview = () => {\n  const [quarter, setQuarter] = useState(0);\n  const [slot, pin] = useCycle(STARTS.length, 2400);\n  const start = STARTS[slot] ?? 24;\n  const end = start + WINDOW - 1;\n  const mid = start + WINDOW / 2;\n  const rows = SERIES[quarter] ?? FIRST;\n\n  let total = 0;\n  let before = 0;\n\n  for (const r of rows) {\n    if (r.i >= start && r.i <= end) {\n      total += r.value;\n    } else if (r.i >= start - WINDOW && r.i < start) {\n      before += r.value;\n    }\n  }\n\n  const change = before > 0 ? (total / before - 1) * 100 : 0;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"ov-soft\",\n            stops: [\n              { color: \"#4ade80\", offset: 0, opacity: 0.85 },\n              { color: \"#86efac\", offset: 0.75, opacity: 0.45 },\n              { color: \"#bbf7d0\", offset: 1, opacity: 0.12 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"ov-deep\",\n            stops: [\n              { color: \"#16a34a\", offset: 0 },\n              { color: \"#22c55e\", offset: 0.7 },\n              { color: \"#bbf7d0\", offset: 1, opacity: 0.25 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"ov-brush\",\n            stops: [\n              { color: \"#fb923c\", offset: 0 },\n              { color: \"#f97316\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        guides: true,\n        margin: MARGIN,\n        marks: [\n          barY(rows, {\n            fill: (r) => {\n              if (r.i < start || r.i > end) {\n                return \"#ececee\";\n              }\n\n              return r.i < mid ? \"url(#ov-soft)\" : \"url(#ov-deep)\";\n            },\n            inset: 0.4,\n            key: \"i\",\n            radius: [1.5, 1.5, 0, 0],\n            x: \"i\",\n            y1: 0,\n            y2: \"value\",\n          }),\n          rect([{ x1: -0.5, x2: N - 0.5 }], {\n            fill: \"#efeff2\",\n            inset: 0,\n            radius: 3,\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: () => BRUSH_BOTTOM,\n            y2: () => BRUSH_TOP,\n          }),\n          rect([{ x1: start - 0.5, x2: end + 0.5 }], {\n            fill: \"url(#ov-brush)\",\n            inset: 0,\n            key: () => \"brush\",\n            radius: 3,\n            stroke: \"#ea580c\",\n            strokeWidth: 1,\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: () => BRUSH_BOTTOM,\n            y2: () => BRUSH_TOP,\n          }),\n          link(\n            [\n              { id: \"l\", x: start + 0.1 },\n              { id: \"r\", x: end - 0.1 },\n            ],\n            {\n              key: \"id\",\n              stroke: \"#ffffff\",\n              strokeOpacity: 0.9,\n              strokeWidth: 1.5,\n              x1: \"x\",\n              x2: \"x\",\n              y1: () => BRUSH_BOTTOM + 25,\n              y2: () => BRUSH_TOP - 25,\n            },\n          ),\n          link([{ x: mid - 0.5 }], {\n            key: () => \"split\",\n            stroke: \"#18181b\",\n            strokeWidth: 1.5,\n            x1: \"x\",\n            x2: \"x\",\n            y1: () => BRUSH_BOTTOM - 12,\n            y2: () => BRUSH_TOP + 12,\n          }),\n          link([{ x1: -0.5, x2: N - 0.5 }], {\n            stroke: \"#e4e4e7\",\n            strokeWidth: 1,\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: () => 0,\n            y2: () => 0,\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11.5 },\n              ticks: {\n                format: (v) => MONTHS[quarter * 3 + Math.floor(Number(v) / 20)] ?? \"\",\n                size: 0,\n                values: [...MONTH_TICKS],\n              },\n            },\n            scale: scaleLinear().domain([-0.5, N - 0.5]),\n          },\n          y: { axis: false, scale: scaleLinear().domain([MIN, MAX]) },\n        },\n        theme: { muted: \"#a1a1aa\" },\n      }),\n    [rows, start, end, mid, quarter],\n  );\n\n  const center = ((mid - 0.5 + 0.5) / N) * 100;\n  const left = Math.min(70, Math.max(30, center));\n\n  return (\n    <Card className=\"!bg-[#f4f4f6] !p-1.5\">\n      <div className=\"rounded-[18px] bg-white px-4 py-3.5 ring-1 ring-black/[0.04]\">\n        <div className=\"flex items-center justify-between gap-2\">\n          <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Overview</h3>\n          <div className=\"flex items-center gap-1.5\">\n            <Chip chevron>Revenue</Chip>\n            <button\n              type=\"button\"\n              className=\"inline-flex h-7 items-center gap-1 rounded-full bg-[linear-gradient(180deg,#fb923c,#f97316)] px-3 text-[12px] font-semibold text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.35),0_4px_10px_-4px_#f97316] ring-1 ring-[#ea580c]\"\n            >\n              <Plus className=\"size-3.5\" strokeWidth={2.6} /> Create\n            </button>\n          </div>\n        </div>\n        <p className=\"mt-1 text-[12px] leading-snug\" style={{ color: MUTED }}>\n          Track revenue, payouts, and affiliate performance in a single powerful chart.\n        </p>\n      </div>\n\n      <div className=\"mt-1.5 rounded-[18px] bg-white p-4 ring-1 ring-black/[0.04]\">\n        <div className=\"flex items-start justify-between gap-2\">\n          <div>\n            <p className=\"inline-flex items-center gap-1.5 text-[12.5px]\" style={{ color: MUTED }}>\n              Total revenue <Info className=\"size-3.5\" />\n            </p>\n            <Num\n              value={18_645.16 + quarter * 1312.4}\n              className=\"block text-[26px] leading-tight font-bold tracking-[-0.03em]\"\n            />\n            <p className=\"mt-0.5 text-[11.5px]\" style={{ color: MUTED }}>\n              <Delta value={4.82} variant=\"circle\" /> vs last quarter\n            </p>\n          </div>\n          <Segmented options={QUARTERS} value={quarter} onChange={setQuarter} size=\"sm\" />\n        </div>\n\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Daily revenue with a selected range\"\n              onFocusChange={(p) => {\n                if (p) {\n                  const x = Number(p.xValue) - WINDOW / 2;\n                  let best = 0;\n\n                  for (const [k, s] of STARTS.entries()) {\n                    if (Math.abs(s - x) < Math.abs((STARTS[best] ?? 0) - x)) {\n                      best = k;\n                    }\n                  }\n\n                  pin(best);\n                }\n              }}\n            />\n          </div>\n          <PlotOverlay margin={MARGIN}>\n            <Bubble left={left} top={57} className=\"!rounded-xl !px-2.5 !py-1.5 text-[10.5px]\">\n              <p className=\"flex items-center gap-1.5\">\n                <span className=\"font-semibold\">Revenue</span>\n                <span style={{ color: MUTED }}>\n                  {fmtDay(dateFor(quarter, start))} – {fmtDay(dateFor(quarter, end))}\n                </span>\n                <X className=\"ml-auto size-3\" style={{ color: MUTED }} />\n              </p>\n              <p className=\"mt-0.5 flex items-baseline justify-between gap-3\">\n                <Num value={total} format={(n) => usd(n)} className=\"text-[13px] font-semibold\" />\n                <span>\n                  <span className=\"font-medium\" style={{ color: change >= 0 ? GREEN : \"#ef4444\" }}>\n                    {change >= 0 ? \"+\" : \"\"}\n                    {change.toFixed(2)}%\n                  </span>{\" \"}\n                  <span style={{ color: MUTED }}>{change >= 0 ? \"Increase\" : \"Decrease\"}</span>\n                </span>\n              </p>\n            </Bubble>\n          </PlotOverlay>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/overview.tsx","target":"uicapsule/finance-charts/charts/overview.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, rect, ruleX, ruleY, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, CircleHelp, RefreshCw } from \"lucide-react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GREEN, GRID, INK, MUTED, ORANGE, PURPLE, SPRING, THEME } from \"../lib/tokens\";\n\nconst KPIS = [\n  { color: ORANGE, delta: 8.34, format: (n: number) => usd(n), label: \"Revenue\", value: 23_561.16 },\n  {\n    color: BLUE,\n    delta: 8.13,\n    format: (n: number) => Math.round(n).toLocaleString(\"en-US\"),\n    label: \"Orders\",\n    value: 266,\n  },\n  {\n    color: PURPLE,\n    delta: 8.34,\n    format: (n: number) => `${n.toFixed(2)}%`,\n    label: \"Conversion rate\",\n    value: 88.83,\n  },\n  {\n    color: ORANGE,\n    delta: 0.19,\n    format: (n: number) => usd(n),\n    label: \"Avg Order value\",\n    value: 88.58,\n  },\n] as const;\n\nconst DAYS = [\n  { conv: 44, convCap: 61, day: \"June 15\", rev: 36, revCap: 49 },\n  { conv: 52, convCap: 66, day: \"June 16\", rev: 47, revCap: 60 },\n  { conv: 38, convCap: 55, day: \"June 17\", rev: 31, revCap: 52 },\n  { conv: 57, convCap: 74, day: \"June 18\", rev: 52, revCap: 63 },\n  { conv: 50, convCap: 67, day: \"June 19\", rev: 43, revCap: 58 },\n  { conv: 61, convCap: 78, day: \"June 20\", rev: 55, revCap: 70 },\n  { conv: 47, convCap: 62, day: \"June 21\", rev: 40, revCap: 54 },\n] as const;\n\nconst MARGIN = { bottom: 4, left: 34, right: 38, top: 14 };\nconst HEIGHT = 210;\nconst TICKS = [0, 25, 50, 75, 100];\nconst GAP = 0.035;\nconst BAR = 1;\n\nexport const Performance = () => {\n  const [day, pin] = useCycle(DAYS.length, 2300, 4);\n  const today = DAYS[day] ?? DAYS[4];\n\n  const definition = useMemo(() => {\n    const bar = (id: string, x1: number, x2: number, y: number, fill: string) =>\n      rect([{ id, x1, x2, y }], {\n        fill,\n        inset: 0,\n        key: \"id\",\n        radius: [5, 5, 0, 0],\n        x1: \"x1\",\n        x2: \"x2\",\n        y1: () => 0,\n        y2: \"y\",\n      });\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        ruleY(TICKS, { stroke: (v) => (v === 0 ? \"#d4d4d8\" : GRID), strokeOpacity: 1 }),\n        bar(\"rev-cap\", -BAR - GAP, -GAP, today.revCap, \"#fdeee4\"),\n        bar(\"conv-cap\", GAP, BAR + GAP, today.convCap, \"#f3e5fd\"),\n        bar(\"rev\", -BAR - GAP, -GAP, today.rev, \"#fba46a\"),\n        bar(\"conv\", GAP, BAR + GAP, today.conv, \"#c172fb\"),\n        ruleX([0], { stroke: INK, strokeDasharray: \"3 3\", strokeOpacity: 1, strokeWidth: 1.5 }),\n        text([{ id: \"caret\" }], {\n          dy: 2,\n          fill: INK,\n          fontSize: 12,\n          key: \"id\",\n          text: () => \"▼\",\n          x: () => 0,\n          y: () => 100,\n        }),\n      ],\n      scales: {\n        x: { axis: false, scale: scaleLinear().domain([-3.4, 3.4]) },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: { format: (v: number) => `${v}%`, size: 0, values: TICKS },\n          },\n          scale: scaleLinear().domain([0, 100]),\n        },\n        yMoney: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 11 },\n            ticks: {\n              format: (v: number) => (v >= 1000 ? `$${v / 1000}K` : `$${v}`),\n              size: 0,\n              values: [0, 500, 1000, 1500, 2000],\n            },\n          },\n          channel: \"y\",\n          scale: scaleLinear().domain([0, 2000]),\n          side: \"right\",\n        },\n      },\n      theme: THEME,\n    });\n  }, [today]);\n\n  return (\n    <Card className=\"!bg-[#f6f6f7] !p-2\">\n      <div className=\"rounded-[16px] bg-white p-3\">\n        <h3 className=\"inline-flex items-center gap-1.5 px-1 text-[15px] font-semibold tracking-[-0.01em]\">\n          Performance <CircleHelp className=\"size-3.5\" style={{ color: MUTED }} />\n        </h3>\n        <div className=\"mt-2.5 grid grid-cols-2 gap-2\">\n          {KPIS.map((k) => (\n            <div key={k.label} className=\"rounded-xl border border-black/[0.07] p-2.5\">\n              <p className=\"inline-flex items-center gap-1.5 text-[11px] text-[#3a3a42]\">\n                <span className=\"size-2 rounded-full\" style={{ backgroundColor: k.color }} />\n                {k.label}\n              </p>\n              <Num\n                value={k.value}\n                format={k.format}\n                className=\"mt-1 block text-[18px] font-bold tracking-[-0.02em]\"\n              />\n              <p className=\"mt-1 inline-flex items-center gap-1 text-[10.5px]\">\n                <span\n                  className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n                  style={{ backgroundColor: GREEN }}\n                >\n                  <ArrowUp className=\"size-2\" strokeWidth={3} />\n                </span>\n                <span className=\"font-semibold\" style={{ color: GREEN }}>\n                  {k.delta.toFixed(2)}%\n                </span>\n                <span style={{ color: MUTED }}>vs last month</span>\n              </p>\n            </div>\n          ))}\n        </div>\n      </div>\n      <div className=\"mt-2 rounded-[16px] bg-white p-3\">\n        <div className=\"flex items-center justify-between px-1\">\n          <h3 className=\"inline-flex items-center gap-1.5 text-[17px] font-semibold tracking-[-0.01em]\">\n            Daily <CircleHelp className=\"size-3.5\" style={{ color: MUTED }} />\n          </h3>\n          <button\n            type=\"button\"\n            aria-label=\"Refresh\"\n            className=\"inline-flex size-8 items-center justify-center rounded-full border border-black/[0.08] text-[#52525b]\"\n          >\n            <RefreshCw className=\"size-3.5\" />\n          </button>\n        </div>\n        <ChartSlot height={HEIGHT} className=\"mt-2\">\n          <div onMouseLeave={() => pin(null)} onMouseEnter={() => pin(day)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Daily revenue and conversion\"\n            />\n          </div>\n        </ChartSlot>\n        <div className=\"mx-auto mt-2 flex h-7 w-[46%] items-center justify-center overflow-hidden rounded-lg bg-[#262626] text-[12px] font-semibold text-white\">\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            <motion.span\n              key={today.day}\n              initial={{ opacity: 0, y: 10 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={{ opacity: 0, y: -10 }}\n              transition={SPRING}\n            >\n              {today.day}\n            </motion.span>\n          </AnimatePresence>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/performance.tsx","target":"uicapsule/finance-charts/charts/performance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { pie, polar, radialArc, radialDot, radialText } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED } from \"../lib/tokens\";\n\nconst TAU = Math.PI * 2;\nconst START = -0.5;\nconst INNER = 0.6;\nconst HEIGHT = 270;\nconst TOTAL = 248_600;\n\nconst SLICES = [\n  { color: \"#0b74e5\", id: \"Equities\", ink: \"#ffffff\", outer: 0.9, swatch: \"#1d7cf2\", value: 51 },\n  { color: \"#b65cfb\", id: \"Other\", ink: \"#1b1030\", outer: 0.86, swatch: \"#a43cf5\", value: 16 },\n  { color: \"#f7751e\", id: \"Bonds\", ink: \"#2a1405\", outer: 0.86, swatch: \"#f97316\", value: 15 },\n  { color: \"#e5f0fd\", id: \"Cash\", ink: \"#0b0b0f\", outer: 0.82, swatch: \"#9ec8fa\", value: 18 },\n] as const;\n\nconst arcs = pie(SLICES, { endAngle: START + TAU, startAngle: START, value: \"value\" });\n\nconst LEGEND_ORDER = [\"Equities\", \"Cash\", \"Bonds\", \"Other\"] as const;\n\nexport const PortfolioAllocation = () => {\n  const [hi, pin] = useCycle(SLICES.length, 2400);\n  const activeId = SLICES[hi]?.id ?? \"Equities\";\n  const active = arcs.find((a) => a.id === activeId) ?? arcs[0];\n\n  const definition = useMemo(() => {\n    const outerOf = (id: string, base: number) => (id === activeId ? 1 : base);\n\n    return defineChart({\n      guides: false,\n      margin: 0,\n      marks: [\n        polar({\n          marks: [\n            ...arcs.map((a) =>\n              radialArc([a], {\n                fill: a.color,\n                fillOpacity: a.id === activeId ? 0.16 : 0,\n                id: `glow-${a.id}`,\n                innerRadius: ({ radius }) => radius * (INNER - 0.03),\n                key: \"id\",\n                outerRadius: ({ radius }) => radius * (outerOf(a.id, a.outer) + 0.035),\n              }),\n            ),\n            ...arcs.map((a) =>\n              radialArc([a], {\n                fill: a.color,\n                id: `arc-${a.id}`,\n                innerRadius: ({ radius }) => radius * INNER,\n                key: \"id\",\n                outerRadius: ({ radius }) => radius * outerOf(a.id, a.outer),\n                stroke: a.id === \"Cash\" ? \"#d6e7fb\" : \"#ffffff\",\n                strokeOpacity: a.id === \"Cash\" ? 1 : 0.25,\n                strokeWidth: 1,\n              }),\n            ),\n            radialDot(arcs, {\n              angle: \"angle\",\n              fill: \"#ffffff\",\n              fillOpacity: 0.2,\n              key: \"id\",\n              r: 18,\n              radius: (d) => (INNER + outerOf(d.id, d.outer)) / 2,\n              stroke: \"#ffffff\",\n              strokeOpacity: 0.65,\n              strokeWidth: 1,\n            }),\n            ...arcs.map((a) =>\n              radialText([a], {\n                angle: \"angle\",\n                dy: 0,\n                fill: a.ink,\n                fontSize: 13,\n                fontWeight: 500,\n                id: `label-${a.id}`,\n                key: \"id\",\n                radius: (d) => (INNER + outerOf(d.id, d.outer)) / 2,\n                text: (d) => `${d.value}%`,\n              }),\n            ),\n          ],\n          scales: {\n            angle: { scale: scaleLinear().domain([0, TAU]) },\n            radius: { scale: scaleLinear().domain([0, 1]) },\n          },\n        }),\n      ],\n      scales: { x: null, y: null },\n    });\n  }, [activeId]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Portfolio allocation</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n            Track your spending pattern and stay in control\n          </p>\n        </div>\n        <MoreButton />\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Portfolio allocation by asset class\"\n            onFocusChange={(p) => {\n              if (p) {\n                const i = SLICES.findIndex((s) => s.id === p.key || s.id === p.datum?.id);\n\n                if (i !== -1) {\n                  pin(i);\n                }\n              }\n            }}\n          />\n        </div>\n        <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center\">\n          <span className=\"text-[12px]\" style={{ color: MUTED }}>\n            {activeId}\n          </span>\n          <Num\n            value={(TOTAL * (active?.value ?? 0)) / 100}\n            format={(n) => usd(n, true)}\n            className=\"text-[20px] font-semibold tracking-[-0.02em]\"\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-3 flex items-center justify-between text-[13px] text-[#3a3a42]\">\n        {LEGEND_ORDER.map((id) => {\n          const s = SLICES.find((x) => x.id === id);\n\n          return (\n            <span key={id} className=\"inline-flex items-center gap-1.5\">\n              <span\n                className=\"size-3 rounded-full\"\n                style={{\n                  background: `radial-gradient(circle at 35% 30%, color-mix(in oklab, ${s?.swatch ?? \"#000\"} 55%, white), ${s?.swatch ?? \"#000\"})`,\n                  boxShadow: `0 1px 3px -1px ${s?.swatch ?? \"#000\"}`,\n                }}\n              />\n              {id}\n            </span>\n          );\n        })}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/portfolio-allocation.tsx","target":"uicapsule/finance-charts/charts/portfolio-allocation.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barX, defineChart, dot, lineY, rect, ruleY } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { CircleHelp, EllipsisVertical, Info, Maximize, Minus, Plus, RefreshCw } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { useMemo, useState } from \"react\";\n\nimport { compact, rng, walk } from \"../lib/data\";\nimport { Card, ChartSlot, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED, RED } from \"../lib/tokens\";\n\nconst LINE = \"#16a34a\";\nconst N = 120;\nconst LINE_END = 92;\nconst DAYS = [\"Fri\", \"Sat\", \"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\"] as const;\nconst RANGES = [\"Week\", \"Month\", \"Year\"] as const;\n\ninterface Range {\n  current: number;\n  floor: number;\n  high: number;\n  low: number;\n  peak: number;\n  seed: number;\n}\n\nconst SPECS: readonly Range[] = [\n  { current: 15_000, floor: 10_600, high: 20_000, low: 10_000, peak: 21_600, seed: 5 },\n  { current: 13_400, floor: 8200, high: 17_500, low: 9000, peak: 19_200, seed: 17 },\n  { current: 16_800, floor: 6400, high: 22_500, low: 7500, peak: 23_400, seed: 29 },\n];\n\nconst priceLine = ({ current, floor, peak, seed }: Range) => {\n  const raw = walk(N, seed, { start: 0, vol: 6 });\n  const lo = Math.min(...raw);\n  const hi = Math.max(...raw);\n  const end = raw.at(-1) ?? 0;\n\n  return raw.map((v, i) => {\n    const scaled = floor + ((v - lo) / (hi - lo || 1)) * (peak - floor);\n    const pull = Math.max(0, (i - (N - 18)) / 17);\n    const target = floor + ((end - lo) / (hi - lo || 1)) * (peak - floor);\n\n    return { i, value: scaled + (current - target) * pull, x: (i / (N - 1)) * LINE_END };\n  });\n};\n\nconst LEVEL_STEP = 300;\nconst LEVELS = Array.from({ length: 72 }, (_, k) => 3600 + k * LEVEL_STEP);\n\nconst depth = ({ current, seed }: Range) => {\n  const r = rng(seed * 31);\n\n  return LEVELS.map((y) => {\n    const near = Math.exp(-(((y - current + 2200) / 4200) ** 2));\n\n    return { len: (0.12 + 0.88 * near) * (0.35 + 0.65 * r()) * 9, y };\n  });\n};\n\nconst DATA = SPECS.map((spec) => ({ depth: depth(spec), line: priceLine(spec), spec }));\nconst [FIRST] = DATA;\n\nconst MIN = 3000;\nconst MAX = 26_000;\nconst MARGIN = { bottom: 26, left: 0, right: 40, top: 6 };\nconst HEIGHT = 210;\nconst smooth = d3Curve(curveMonotoneX);\n\nconst RoundButton = ({ icon: Icon, size = 30 }: { icon: LucideIcon; size?: number }) => (\n  <button\n    type=\"button\"\n    aria-label=\"Chart control\"\n    className=\"inline-flex shrink-0 items-center justify-center rounded-full bg-white text-[#3a3a42] ring-1 ring-black/[0.08]\"\n    style={{ height: size, width: size }}\n  >\n    <Icon className=\"size-3.5\" />\n  </button>\n);\n\nconst Coin = ({\n  glyph,\n  color,\n  className,\n}: {\n  glyph: string;\n  color: string;\n  className?: string;\n}) => (\n  <span\n    className={`inline-flex size-7 items-center justify-center rounded-full text-[14px] font-bold text-white ring-2 ring-white ${className ?? \"\"}`}\n    style={{ background: color }}\n  >\n    {glyph}\n  </span>\n);\n\nconst PriceBox = ({ label, value, change }: { label: string; value: number; change: number }) => (\n  <div className=\"flex-1 rounded-[14px] bg-[#f4f4f6] p-3\">\n    <p className=\"text-[11.5px]\" style={{ color: MUTED }}>\n      {label}\n    </p>\n    <p className=\"mt-1 flex items-baseline gap-1\">\n      <Num value={value} className=\"text-[16px] font-bold tracking-[-0.02em]\" />\n    </p>\n    <div className=\"mt-1.5 flex items-center justify-between\">\n      <span className=\"text-[11px] font-medium\" style={{ color: change >= 0 ? GREEN : RED }}>\n        {change >= 0 ? \"+\" : \"\"}\n        {change.toFixed(2)}%\n      </span>\n      <span className=\"flex gap-1\">\n        <RoundButton icon={Plus} size={24} />\n        <RoundButton icon={Minus} size={24} />\n      </span>\n    </div>\n  </div>\n);\n\nexport const PriceRange = () => {\n  const [pair, setPair] = useState(0);\n  const [range, pin] = useCycle(RANGES.length, 3200);\n\n  const {\n    depth: levels,\n    line,\n    spec,\n  } = DATA[range] ?? FIRST ?? { depth: [], line: [], spec: SPECS[0] };\n\n  const { current = 0, high = 0, low = 0 } = spec ?? {};\n  const last = line.at(-1);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          ruleY([MAX - 1000, MIN + 800], { stroke: \"#ececf0\", strokeOpacity: 1 }),\n          rect([{ high, low }], {\n            fill: LINE,\n            fillOpacity: 0.08,\n            inset: 0,\n            key: () => \"band\",\n            x1: () => 0,\n            x2: () => 100,\n            y1: \"low\",\n            y2: \"high\",\n          }),\n          ruleY([current], { stroke: \"#b4b4bb\", strokeDasharray: \"4 4\", strokeOpacity: 1 }),\n          barX(levels, {\n            fill: (d) => (d.y >= low && d.y <= high ? LINE : \"#dcdce0\"),\n            key: \"y\",\n            x1: (d) => 100 - d.len,\n            x2: () => 100,\n            y: \"y\",\n          }),\n          lineY(line, {\n            curve: smooth,\n            key: \"i\",\n            stroke: LINE,\n            strokeWidth: 2,\n            x: \"x\",\n            y: \"value\",\n          }),\n          dot(last ? [last] : [], {\n            fill: LINE,\n            fillOpacity: 0.18,\n            key: () => \"halo\",\n            r: 8,\n            x: \"x\",\n            y: \"value\",\n          }),\n          dot(last ? [last] : [], {\n            fill: LINE,\n            key: () => \"now\",\n            r: 3.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 1.5,\n            x: \"x\",\n            y: \"value\",\n          }),\n        ],\n        motion: { path: \"morph\" },\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v) => DAYS[Math.round((Number(v) - 4) / 13)] ?? \"\",\n                size: 0,\n                values: DAYS.map((_, k) => 4 + k * 13),\n              },\n            },\n            scale: scaleLinear().domain([0, 100]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v) => compact(v),\n                padding: 8,\n                size: 0,\n                values: [5000, 10_000, 15_000, 20_000, 25_000],\n              },\n            },\n            scale: scaleLinear().domain([MIN, MAX]),\n            side: \"right\",\n          },\n        },\n        theme: { muted: \"#a1a1aa\" },\n      }),\n    [levels, line, last, current, high, low],\n  );\n\n  return (\n    <Card className=\"!bg-[#f4f4f6] !p-1.5\">\n      <div className=\"rounded-[18px] bg-white px-3.5 py-3 ring-1 ring-black/[0.04]\">\n        <div className=\"flex items-center justify-between gap-2\">\n          <div className=\"flex items-center gap-2\">\n            <span className=\"flex\">\n              <Coin glyph=\"Ξ\" color=\"linear-gradient(160deg,#8a9cf5,#5b6fe6)\" />\n              <Coin glyph=\"₿\" color=\"linear-gradient(160deg,#fbb44a,#f7931a)\" className=\"-ml-2\" />\n            </span>\n            <h3 className=\"text-[15px] font-semibold\">ETH/BTC</h3>\n            <Info className=\"size-3.5\" style={{ color: MUTED }} />\n          </div>\n          <Segmented options={[\"ETH\", \"BTC\"]} value={pair} onChange={setPair} size=\"sm\" />\n        </div>\n        <div className=\"mt-2 flex gap-1.5 text-[11px] text-[#55555e]\">\n          {[\"0.3% fee\", \"Version 4\", \"79% select\"].map((t) => (\n            <span key={t} className=\"rounded-full bg-[#f0f0f2] px-2 py-0.5\">\n              {t}\n            </span>\n          ))}\n        </div>\n      </div>\n\n      <div className=\"mt-1.5 rounded-[18px] bg-white ring-1 ring-black/[0.04]\">\n        <div className=\"flex items-center justify-between gap-2 border-b border-[#ececf0] px-3.5 py-3\">\n          <h3 className=\"flex items-center gap-1.5 text-[16px] font-semibold tracking-[-0.01em]\">\n            Price range <CircleHelp className=\"size-3.5\" style={{ color: MUTED }} />\n          </h3>\n          <div className=\"flex items-center gap-1.5\">\n            <Segmented options={RANGES} value={range} onChange={pin} size=\"sm\" />\n            <RoundButton icon={RefreshCw} size={26} />\n          </div>\n        </div>\n        <div className=\"px-3.5 pt-3 pb-3.5\">\n          <div className=\"flex items-center justify-between\">\n            <span className=\"flex gap-1\">\n              <RoundButton icon={Plus} size={26} />\n              <RoundButton icon={Minus} size={26} />\n            </span>\n            <span className=\"text-[11px] font-medium tracking-[0.06em] text-[#55555e]\">\n              EXPONENTA\n            </span>\n            <span className=\"flex gap-1\">\n              <RoundButton icon={Maximize} size={26} />\n              <RoundButton icon={EllipsisVertical} size={26} />\n            </span>\n          </div>\n          <ChartSlot height={HEIGHT} className=\"mt-2\">\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"ETH/BTC price with the selected range and liquidity depth\"\n            />\n          </ChartSlot>\n          <div className=\"mt-3 flex gap-2\">\n            <PriceBox label=\"Low price\" value={low} change={(low / current - 1) * 100} />\n            <PriceBox label=\"High price\" value={high} change={(high / current - 1) * 100} />\n          </div>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/price-range.tsx","target":"uicapsule/finance-charts/charts/price-range.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, frame, lineY, link, rect, ruleX, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { CalendarDays, Sparkles } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { walk } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, Legend, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GRID, MUTED, PURPLE, THEME } from \"../lib/tokens\";\n\nconst N = 60;\nconst HEIGHT = 108;\nconst MARGIN = { bottom: 1, left: 1, right: 1, top: 1 };\nconst COLUMNS = Array.from({ length: 10 }, (_, i) => ((i + 1) * (N - 1)) / 11);\n\ninterface Series {\n  id: string;\n  label: string;\n  color: string;\n  wash: string;\n  fill: string;\n  domain: [number, number];\n  values: number[];\n  stops: number[];\n}\n\nconst SERIES: Series[] = [\n  {\n    color: PURPLE,\n    domain: [40, 80],\n    fill: \"#e2b8fb\",\n    id: \"gross\",\n    label: \"Gross Margin\",\n    stops: [40, 37, 33, 29, 25, 21, 18, 23, 28, 33, 37, 41],\n    values: walk(N, 71, { max: 74, min: 50, start: 57, vol: 3.4 }),\n    wash: \"#f6e8fe\",\n  },\n  {\n    color: BLUE,\n    domain: [6, 30],\n    fill: \"#acd2f8\",\n    id: \"net\",\n    label: \"Net Margin\",\n    stops: [22, 18, 14, 19, 25, 30, 35, 40, 42, 37, 32, 27],\n    values: walk(N, 74, { max: 25, min: 11, start: 18, vol: 3 }),\n    wash: \"#e6f1fd\",\n  },\n];\n\nconst Panel = ({ series, step }: { series: Series; step: number }) => {\n  const at = series.stops[step % series.stops.length] ?? 0;\n  const value = series.values[at] ?? 0;\n  const rows = useMemo(() => series.values.map((v, i) => ({ i, v })), [series]);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        clip: true,\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          rect([{ hi: series.domain[1], id: \"wash\", lo: series.domain[0], x1: 0, x2: at }], {\n            fill: series.wash,\n            inset: 0,\n            key: \"id\",\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: \"lo\",\n            y2: \"hi\",\n          }),\n          areaY(rows, {\n            fill: series.fill,\n            fillOpacity: 1,\n            x: \"i\",\n            y1: series.domain[0],\n            y2: \"v\",\n          }),\n          lineY(rows, { stroke: series.color, strokeWidth: 1.25, x: \"i\", y: \"v\" }),\n          rect([{ hi: series.domain[1], id: \"sheet\", lo: series.domain[0], x1: at, x2: N - 1 }], {\n            fill: \"#ffffff\",\n            inset: 0,\n            key: \"id\",\n            x1: \"x1\",\n            x2: \"x2\",\n            y1: \"lo\",\n            y2: \"hi\",\n          }),\n          ruleX(COLUMNS, { stroke: GRID, strokeDasharray: \"4 4\", strokeWidth: 1 }),\n          ruleY([(series.domain[0] + series.domain[1]) / 2], {\n            stroke: GRID,\n            strokeDasharray: \"4 4\",\n            strokeWidth: 1,\n          }),\n          frame({ stroke: GRID, strokeOpacity: 1 }),\n          link([{ hi: series.domain[1], id: \"cursor\", lo: series.domain[0], x: at }], {\n            key: \"id\",\n            lineCap: \"butt\",\n            stroke: series.color,\n            strokeWidth: 2,\n            x1: \"x\",\n            x2: \"x\",\n            y1: \"lo\",\n            y2: \"hi\",\n          }),\n          dot([{ id: \"cursor\", v: value, x: at }], {\n            fill: \"#ffffff\",\n            key: \"id\",\n            r: 6,\n            stroke: series.color,\n            strokeWidth: 2.5,\n            x: \"x\",\n            y: \"v\",\n          }),\n        ],\n        scales: {\n          x: { scale: scaleLinear().domain([0, N - 1]) },\n          y: { scale: scaleLinear().domain(series.domain) },\n        },\n        theme: THEME,\n      }),\n    [rows, series, at, value],\n  );\n\n  return (\n    <ChartSlot height={HEIGHT}>\n      <Chart\n        definition={definition}\n        renderer={renderer}\n        height={HEIGHT}\n        ariaLabel={`${series.label} over the period`}\n      />\n      <div className=\"pointer-events-none absolute top-1/2 right-3 -translate-y-1/2 text-right\">\n        <p className=\"text-[12px]\" style={{ color: MUTED }}>\n          {series.label}\n        </p>\n        <Num\n          value={value}\n          format={(n) => `${n.toFixed(2)}%`}\n          className=\"text-[17px] font-semibold tracking-[-0.02em]\"\n        />\n      </div>\n    </ChartSlot>\n  );\n};\n\nexport const ProfitMarginAnalysis = () => {\n  const [step] = useCycle(12, 1600);\n  const [gross] = SERIES;\n  const grossNow = gross ? (gross.values[gross.stops[step] ?? 0] ?? 0) : 0;\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[15px] font-semibold tracking-[-0.01em]\">Profit Margin Analysis</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n            Comparison of Gross vs Net Profit Margin\n          </p>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            Weekly\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <div className=\"mt-4 border-t pt-4\" style={{ borderColor: GRID }}>\n        <Legend\n          items={[\n            { color: PURPLE, label: \"Gross Profit Margin\" },\n            { color: BLUE, label: \"Net Profit Margin\" },\n          ]}\n        />\n      </div>\n      <div className=\"mt-3 flex flex-col gap-2.5\">\n        {SERIES.map((s) => (\n          <Panel key={s.id} series={s} step={step} />\n        ))}\n      </div>\n      <div\n        className=\"mt-3 flex items-center gap-2 rounded-xl border bg-[#fafafa] px-3 py-2.5 text-[12px]\"\n        style={{ borderColor: GRID }}\n      >\n        <Sparkles className=\"size-3.5 shrink-0\" style={{ color: PURPLE }} fill={PURPLE} />\n        <p className=\"text-[#55555e]\">\n          <span className=\"font-semibold text-[#0b0b0f]\">Insights:</span> Lower supplier costs\n          pushed Gross Margin to {grossNow.toFixed(2)}%.\n        </p>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/profit-margin-analysis.tsx","target":"uicapsule/finance-charts/charts/profit-margin-analysis.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, link, rect, ruleX } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ArrowUp } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst PHASES = [\n  { amount: 27_600, label: \"Research & UI/UX\" },\n  { amount: 17_650, label: \"Frontend Dev\" },\n  { amount: 10_700, label: \"Backend & Infra\" },\n  { amount: 3300, label: \"QA & Deployment\" },\n] as const;\n\nconst TOTAL = PHASES.reduce((s, p) => s + p.amount, 0);\n\nconst HEIGHT = 180;\nconst MARGIN = { bottom: 0, left: 0, right: 0, top: 6 };\nconst curve = d3Curve(curveMonotoneX);\n\nconst LAYERS = [\n  { id: \"ceiling\", levels: [0.95, 0.66, 0.4, 0.06], opacity: 0.26 },\n  { id: \"forecast\", levels: [0.75, 0.53, 0.31, 0.06], opacity: 0.5 },\n  { id: \"committed\", levels: [0.54, 0.39, 0.23, 0.06], opacity: 1 },\n] as const;\n\nconst smooth = (t: number) => {\n  const c = Math.min(1, Math.max(0, t));\n\n  return c * c * (3 - 2 * c);\n};\n\nconst envelope = (levels: readonly number[], x: number) => {\n  let y = levels[0] ?? 0;\n\n  for (let k = 0; k < levels.length - 1; k += 1) {\n    y += ((levels[k + 1] ?? 0) - (levels[k] ?? 0)) * smooth((x - (k + 0.55)) / 0.7);\n  }\n\n  return y;\n};\n\nconst SAMPLES = Array.from({ length: 81 }, (_, i) => (i / 80) * PHASES.length);\n\nconst ROWS = LAYERS.flatMap((layer) =>\n  SAMPLES.map((x) => ({ layer: layer.id, x, y: envelope(layer.levels, x) })),\n);\n\nexport const ProjectBudgetAllocation = () => {\n  const [hi, pin] = useCycle(PHASES.length, 2200);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: LAYERS.map((layer) => ({\n          id: `pba-${layer.id}`,\n          stops: [\n            { color: \"#fb8c45\", offset: 0, opacity: layer.opacity },\n            { color: \"#fba25c\", offset: 0.35, opacity: layer.opacity },\n            { color: \"#f9c87a\", offset: 0.58, opacity: layer.opacity },\n            { color: \"#c9bfa6\", offset: 0.78, opacity: layer.opacity },\n            { color: \"#86bdf8\", offset: 1, opacity: layer.opacity },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        })),\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          ...LAYERS.map((layer) =>\n            areaY(\n              ROWS.filter((r) => r.layer === layer.id),\n              {\n                curve,\n                fill: `url(#pba-${layer.id})`,\n                fillOpacity: 1,\n                x: \"x\",\n                y1: 0,\n                y2: \"y\",\n              },\n            ),\n          ),\n          rect(\n            PHASES.flatMap((p, i) =>\n              i === hi ? [] : [{ id: p.label, x1: i, x2: i + 1, y1: 0, y2: 1 }],\n            ),\n            {\n              fill: \"#ffffff\",\n              fillOpacity: 0.42,\n              inset: 0,\n              key: \"id\",\n              x1: \"x1\",\n              x2: \"x2\",\n              y1: \"y1\",\n              y2: \"y2\",\n            },\n          ),\n          ruleX([1, 2, 3], { stroke: \"#ffffff\", strokeOpacity: 1, strokeWidth: 3 }),\n          link(\n            [\n              { base: 0, color: \"#fb8c45\", id: \"start\", x: 0.012, y: 1.04 },\n              { base: 0, color: \"#2f7ff0\", id: \"end\", x: PHASES.length - 0.012, y: 0.11 },\n            ],\n            {\n              key: \"id\",\n              lineCap: \"butt\",\n              stroke: (d) => d.color,\n              strokeWidth: 2,\n              x1: \"x\",\n              x2: \"x\",\n              y1: \"base\",\n              y2: \"y\",\n            },\n          ),\n        ],\n        scales: {\n          x: { scale: scaleLinear().domain([0, PHASES.length]) },\n          y: { scale: scaleLinear().domain([0, 1.04]) },\n        },\n        theme: THEME,\n      }),\n    [hi],\n  );\n\n  const phase = PHASES[hi] ?? PHASES[0];\n  const peak = envelope(LAYERS[0].levels, hi + 0.3);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Project Budget Allocation</h3>\n        <MoreButton />\n      </div>\n      <div className=\"mt-4 border-t pt-4\" style={{ borderColor: GRID }}>\n        <p className=\"text-[13px]\" style={{ color: MUTED }}>\n          Total Project Expenses\n        </p>\n        <Num value={TOTAL} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n        <p className=\"mt-1 flex items-center gap-2 text-[12px]\" style={{ color: MUTED }}>\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-semibold\"\n            style={{ color: GREEN }}\n          >\n            <span\n              className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n            </span>\n            $16,375\n          </span>\n          vs last month\n        </p>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Project budget by phase\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.min(PHASES.length - 1, Math.max(0, Math.floor(x))));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={((hi + 0.5) / PHASES.length) * 100}\n            top={Math.max(4, (1 - peak / 1.04) * 100 - 22)}\n            className=\"!rounded-full !px-2 !py-0.5 text-[11px] font-semibold\"\n          >\n            {(((phase?.amount ?? 0) / TOTAL) * 100).toFixed(1)}%\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-4 grid grid-cols-2 gap-x-4 gap-y-3\">\n        {PHASES.map((p, i) => (\n          <div key={p.label}>\n            <p\n              className=\"text-[12px] transition-colors\"\n              style={{ color: i === hi ? \"#3a3a42\" : MUTED }}\n            >\n              {p.label}\n            </p>\n            <Num\n              value={p.amount}\n              format={(n) => usd(n)}\n              className=\"text-[17px] font-semibold tracking-[-0.02em]\"\n            />\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/project-budget-allocation.tsx","target":"uicapsule/finance-charts/charts/project-budget-allocation.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, ruleX, ruleY, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUpRight, ChartLine, Info } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, Legend, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst LINES = [\n  { avg: 31.1, label: \"Subscription\", top: 17.5 },\n  { avg: 37.8, label: \"Expenses\", top: 23.2 },\n  { avg: 32.7, label: \"Investment\", top: 31 },\n] as const;\n\nconst DEEP = \"#1279ee\";\nconst PALE = \"#8fc3f8\";\nconst HEIGHT = 220;\nconst MARGIN = { bottom: 26, left: 34, right: 0, top: 22 };\n\ninterface Bar {\n  c: number;\n  series: \"avg\" | \"top\";\n  v: number;\n  x: number;\n}\n\nconst BARS: Bar[] = LINES.flatMap((l, c) => [\n  { c, series: \"avg\" as const, v: l.avg, x: c + 0.335 },\n  { c, series: \"top\" as const, v: l.top, x: c + 0.665 },\n]);\n\nconst gradient = (id: string, top: string, bottom: string, opacity: number) => ({\n  id,\n  stops: [\n    { color: top, offset: 0, opacity },\n    { color: bottom, offset: 1, opacity },\n  ],\n  y1: 0,\n  y2: 1,\n});\n\nexport const RevenueByProductLine = () => {\n  const [hi, pin] = useCycle(LINES.length, 2600, 0);\n  const line = LINES[hi] ?? LINES[0];\n  const gap = (1 - line.top / line.avg) * 100;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          gradient(\"rp-avg\", \"#4ea2fb\", \"#0e73ea\", 1),\n          gradient(\"rp-top\", \"#eef6ff\", \"#a5cffa\", 1),\n          gradient(\"rp-avg-dim\", \"#4ea2fb\", \"#0e73ea\", 0.6),\n          gradient(\"rp-top-dim\", \"#eef6ff\", \"#a5cffa\", 0.6),\n        ],\n        margin: MARGIN,\n        marks: [\n          ruleX([0, 1, 2], { stroke: GRID, strokeOpacity: 1 }),\n          ruleY([10, 20, 30, 40, 50], { stroke: GRID, strokeDasharray: \"5 5\", strokeOpacity: 1 }),\n          ruleY([0], { stroke: \"#d4d4d8\", strokeOpacity: 1 }),\n          barY(BARS, {\n            fill: (d) => `url(#rp-${d.series}${d.c === hi ? \"\" : \"-dim\"})`,\n            key: (d) => `${d.c}-${d.series}`,\n            radius: [9, 9, 3, 3],\n            stroke: (d) => (d.series === \"avg\" ? \"#1a6fd6\" : \"#a9d0f8\"),\n            strokeWidth: 1,\n            x: \"x\",\n            y1: () => 0,\n            y2: \"v\",\n          }),\n          text(BARS, {\n            dx: (d) => (d.series === \"avg\" ? -3 : 3),\n            dy: -9,\n            fill: (d) => (d.series === \"avg\" ? DEEP : PALE),\n            fontSize: 11.5,\n            fontWeight: 600,\n            key: (d) => `${d.c}-${d.series}`,\n            text: (d) => `${d.v.toFixed(1)}%`,\n            x: \"x\",\n            y: \"v\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12, fontWeight: (c) => (c.value === hi + 0.5 ? 600 : 400) },\n              ticks: {\n                format: (v: number) => LINES[Math.floor(v)]?.label ?? \"\",\n                size: 0,\n                values: LINES.map((_, i) => i + 0.5),\n              },\n            },\n            scale: scaleLinear().domain([0, LINES.length]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: { format: (v: number) => `${v}%`, size: 0, values: [0, 10, 20, 30, 40, 50] },\n            },\n            scale: scaleLinear().domain([0, 50]),\n          },\n        },\n        theme: THEME,\n      }),\n    [hi],\n  );\n\n  return (\n    <Card className=\"!p-0\">\n      <div className=\"px-5 pt-5 pb-4\">\n        <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Revenue by product line</h3>\n        <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n          Churn rate comparison across revenue streams\n        </p>\n        <p className=\"mt-2 inline-flex items-center gap-1.5 text-[12px]\" style={{ color: MUTED }}>\n          Data source:\n          <span className=\"font-medium text-[#1279ee] underline underline-offset-2\">Stripe</span>\n          <Info className=\"size-3.5\" />\n        </p>\n      </div>\n      <div className=\"border-t px-5 pt-4 pb-5\" style={{ borderColor: GRID }}>\n        <div className=\"flex flex-wrap items-center justify-between gap-2\">\n          <p className=\"text-[12px] text-[#3a3a42]\">Churn rate %</p>\n          <Legend\n            items={[\n              { color: DEEP, label: \"Industry Avg. churn\" },\n              { color: PALE, label: \"Top Quartile churn\" },\n            ]}\n            className=\"!text-[11px]\"\n          />\n        </div>\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Churn rate by product line, industry average against top quartile\"\n              onFocusChange={(p) => {\n                const x = Number(p?.xValue);\n\n                if (p && Number.isFinite(x)) {\n                  pin(Math.min(LINES.length - 1, Math.max(0, Math.floor(x))));\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n        <div className=\"mt-4 flex items-center gap-3\">\n          <span className=\"inline-flex size-9 shrink-0 items-center justify-center rounded-full bg-[#e8f2fe] text-[#1279ee]\">\n            <ChartLine className=\"size-4\" />\n          </span>\n          <p className=\"text-[12.5px] leading-snug text-[#3a3a42]\">\n            Top quartile companies achieve up to{\" \"}\n            <Num\n              value={gap}\n              format={(n) => `${Math.round(n)}%`}\n              className=\"text-[15px] font-semibold text-[#1279ee]\"\n            />{\" \"}\n            lower churn than industry averages in {line.label.toLowerCase()}.\n          </p>\n        </div>\n        <div\n          className=\"mt-3 flex items-center justify-between border-t pt-3\"\n          style={{ borderColor: GRID }}\n        >\n          <p className=\"text-[12.5px] text-[#3a3a42]\">Retain customers, grow revenue.</p>\n          <button\n            type=\"button\"\n            aria-label=\"Open\"\n            className=\"inline-flex size-8 items-center justify-center rounded-full border border-black/[0.08] text-[#52525b]\"\n          >\n            <ArrowUpRight className=\"size-4\" />\n          </button>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/revenue-by-product-line.tsx","target":"uicapsule/finance-charts/charts/revenue-by-product-line.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, lineY, link, text } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { CalendarDays } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  Num,\n  PlotOverlay,\n  muted,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { DASHED_GRID, GRID, INK, MUTED, ORANGE, PURPLE } from \"../lib/tokens\";\n\nconst YEARS = [0, 1, 2, 3, 4, 5] as const;\nconst ANNUAL = [0.6, 4.5, 10.2, 15, 19.6, 24.4] as const;\nconst MRR = [0.1, 3.4, 5, 6.6, 8.3, 9.8] as const;\nconst X_MAX = 7;\nconst Y_MAX = 25;\nconst HEIGHT = 250;\nconst MARGIN = { bottom: 26, left: 40, right: 6, top: 14 };\nconst curve = d3Curve(curveMonotoneX);\n\nconst rows = YEARS.map((year) => ({ annual: ANNUAL[year], mrr: MRR[year], year }));\n\nexport const RevenueGrowth = () => {\n  const [step, pin] = useCycle(5, 2400, 4);\n  const year = step + 1;\n  const picked = rows[year] ?? rows[5];\n  const annual = picked?.annual ?? 0;\n  const mrr = picked?.mrr ?? 0;\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"rg-purple\",\n            stops: [\n              { color: PURPLE, offset: 0, opacity: 0.2 },\n              { color: PURPLE, offset: 1, opacity: 0.02 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"rg-orange\",\n            stops: [\n              { color: ORANGE, offset: 0, opacity: 0.2 },\n              { color: ORANGE, offset: 1, opacity: 0.02 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        margin: MARGIN,\n        marks: [\n          areaY(rows, {\n            curve,\n            fill: \"url(#rg-purple)\",\n            fillOpacity: 1,\n            id: \"annual-area\",\n            key: \"year\",\n            x: \"year\",\n            y1: \"mrr\",\n            y2: \"annual\",\n          }),\n          areaY(rows, {\n            curve,\n            fill: \"url(#rg-orange)\",\n            fillOpacity: 1,\n            id: \"mrr-area\",\n            key: \"year\",\n            x: \"year\",\n            y1: 0,\n            y2: \"mrr\",\n          }),\n          link([picked], {\n            id: \"gap\",\n            key: () => \"gap\",\n            stroke: INK,\n            strokeDasharray: \"2 3\",\n            strokeWidth: 1.5,\n            x1: (d) => d?.year ?? 0,\n            x2: (d) => d?.year ?? 0,\n            y1: () => 0,\n            y2: (d) => d?.annual ?? 0,\n          }),\n          text([picked], {\n            dy: -11,\n            fill: INK,\n            fontSize: 10,\n            id: \"cap-top\",\n            key: () => \"top\",\n            text: () => \"▼\",\n            x: (d) => d?.year ?? 0,\n            y: (d) => d?.annual ?? 0,\n          }),\n          text([picked], {\n            dy: -4,\n            fill: INK,\n            fontSize: 10,\n            id: \"cap-bottom\",\n            key: () => \"bottom\",\n            text: () => \"▲\",\n            x: (d) => d?.year ?? 0,\n            y: () => 0,\n          }),\n          lineY(rows, { curve, id: \"annual\", key: \"year\", stroke: PURPLE, x: \"year\", y: \"annual\" }),\n          lineY(rows, { curve, id: \"mrr\", key: \"year\", stroke: ORANGE, x: \"year\", y: \"mrr\" }),\n          dot(rows, {\n            fill: PURPLE,\n            id: \"annual-dots\",\n            key: \"year\",\n            r: 4.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 1.75,\n            x: \"year\",\n            y: \"annual\",\n          }),\n          dot(rows, {\n            fill: ORANGE,\n            id: \"mrr-dots\",\n            key: \"year\",\n            r: 4.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 1.75,\n            x: \"year\",\n            y: \"mrr\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === year ? 600 : 400),\n              },\n              ticks: { format: (v) => `Year ${v}`, size: 0, values: [...YEARS] },\n            },\n            scale: scaleLinear().domain([0, X_MAX]),\n          },\n          y: {\n            axis: {\n              line: { stroke: GRID },\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v) => (v === 0 ? \"$0\" : `$${v}M`),\n                size: 0,\n                values: [0, 5, 10, 15, 20, 25],\n              },\n            },\n            grid: { ...DASHED_GRID, stroke: \"#e4e4e7\", strokeOpacity: 1 },\n            scale: scaleLinear().domain([0, Y_MAX]),\n          },\n        },\n        theme: { foreground: INK, grid: GRID, muted: MUTED },\n      }),\n    [picked, year],\n  );\n\n  const ratio = mrr > 0 ? annual / mrr : 0;\n  const left = (5.2 / X_MAX) * 100;\n  const mid = 100 - ((annual + mrr) / 2 / Y_MAX) * 100;\n\n  return (\n    <Card className=\"!px-0\">\n      <div className=\"flex items-start justify-between gap-3 px-5\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Revenue Growth</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={muted}>\n            Track recurring revenue growth with compounding.\n          </p>\n        </div>\n        <Chip icon={CalendarDays} chevron>\n          5 Years\n        </Chip>\n      </div>\n      <div className=\"mt-4 border-t px-5 pt-4\" style={{ borderColor: GRID }}>\n        <div className=\"grid grid-cols-2 gap-2.5\">\n          <div className=\"rounded-2xl bg-[#f6f6f7] px-3 py-2.5\">\n            <p\n              className=\"inline-flex items-center gap-1.5 text-[11px] whitespace-nowrap\"\n              style={muted}\n            >\n              <span className=\"size-2.5 rounded-full\" style={{ backgroundColor: PURPLE }} />\n              Annual Revenue\n            </p>\n            <p className=\"mt-1 flex items-baseline gap-1.5\">\n              <Num\n                value={annual}\n                format={(n) => `$${n.toFixed(1)}M`}\n                className=\"text-[20px] font-semibold tracking-[-0.02em]\"\n              />\n              <span className=\"text-[11px]\" style={muted}>\n                Year {year}\n              </span>\n            </p>\n          </div>\n          <div className=\"rounded-2xl bg-[#f6f6f7] px-3 py-2.5\">\n            <p\n              className=\"inline-flex items-center gap-1.5 text-[11px] whitespace-nowrap\"\n              style={muted}\n            >\n              <span className=\"size-2.5 rounded-full\" style={{ backgroundColor: ORANGE }} />\n              Monthly Recurring (MRR)\n            </p>\n            <p className=\"mt-1 flex items-baseline gap-1.5\">\n              <Num\n                value={mrr}\n                format={(n) => `$${n.toFixed(1)}M`}\n                className=\"text-[20px] font-semibold tracking-[-0.02em]\"\n              />\n              <span className=\"text-[11px]\" style={muted}>\n                Year {year}\n              </span>\n            </p>\n          </div>\n        </div>\n        <p className=\"mt-5 text-[12px] text-[#3a3a42]\">Revenue</p>\n        <ChartSlot height={HEIGHT} className=\"mt-2\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Annual revenue and MRR over five years\"\n              onFocusChange={(p) => {\n                if (p) {\n                  const y = Number(p.xValue);\n\n                  if (Number.isInteger(y) && y >= 1 && y <= 5) {\n                    pin(y - 1);\n                  }\n                }\n              }}\n            />\n          </div>\n          <PlotOverlay margin={MARGIN}>\n            <Bubble\n              left={left}\n              top={mid}\n              align=\"left\"\n              className=\"-translate-y-1/2 !bg-transparent !px-0 !py-0 !shadow-none !ring-0\"\n            >\n              <Num\n                value={ratio}\n                format={(n) => `${n.toFixed(1)}x`}\n                className=\"block text-[24px] leading-none font-semibold\"\n                style={{ color: PURPLE }}\n              />\n              <p className=\"mt-1 w-[78px] text-[11px] leading-snug\" style={muted}>\n                more revenue with compounding\n              </p>\n            </Bubble>\n          </PlotOverlay>\n        </ChartSlot>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/revenue-growth.tsx","target":"uicapsule/finance-charts/charts/revenue-growth.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart } from \"@tanstack/charts\";\nimport { polar, radialArc, radialDot, radialLine } from \"@tanstack/charts/polar\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveCatmullRom } from \"d3-shape\";\nimport { ArrowUp, ArrowUpRight, Sparkle, Wallet } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, MoreButton, Num, renderer, useActive, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED } from \"../lib/tokens\";\n\nconst HALF = Math.PI / 2;\nconst SIZE = 340;\nconst VISIBLE = 182;\n\nconst BLUE = \"#1d7cf2\";\nconst PURPLE = \"#a43cf5\";\n\nconst PATH = [\n  { a: -HALF, r: 0.745, v: 0 },\n  { a: -1.42, r: 0.75, v: 212.4 },\n  { a: -1.25, r: 0.762, v: 318.9 },\n  { a: -0.62, r: 0.775, v: 512.06 },\n  { a: -0.35, r: 0.785, v: 618.4 },\n  { a: -0.1, r: 0.79, v: 702.33 },\n  { a: 0.16, r: 0.79, v: 781.5 },\n  { a: 0.42, r: 0.775, v: 874.92 },\n] as const;\n\nconst STOPS = PATH.slice(1).map((p, k) => ({ ...p, id: `p${k}`, k }));\nconst FIRST_ACTIVE = 2;\n\nconst ring = (inner: number, outer: number) => ({\n  innerRadius: ({ radius }: { radius: number }) => radius * inner,\n  outerRadius: ({ radius }: { radius: number }) => radius * outer,\n});\n\nexport const RevenueOverview = () => {\n  const active = useActive();\n  const [step, pin] = useCycle(STOPS.length - FIRST_ACTIVE, 1700, STOPS.length - FIRST_ACTIVE - 1);\n  const hi = step + FIRST_ACTIVE;\n  const head = STOPS[hi] ?? STOPS.at(-1);\n  const end = (head?.a ?? 0) + 0.24;\n\n  const definition = useMemo(() => {\n    const trail = PATH.filter((p) => p.a <= (head?.a ?? 0));\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"ro-band\",\n          stops: [\n            { color: \"#e9f3fe\", offset: 0 },\n            { color: \"#a9cff9\", offset: 0.45 },\n            { color: \"#3a92f3\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0.6,\n          y2: 0,\n        },\n        {\n          id: \"ro-rim\",\n          stops: [\n            { color: BLUE, offset: 0, opacity: 0 },\n            { color: \"#69aef7\", offset: 0.4, opacity: 0.8 },\n            { color: BLUE, offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 1,\n          y2: 0,\n        },\n        {\n          id: \"ro-line\",\n          stops: [\n            { color: BLUE, offset: 0 },\n            { color: \"#dbe6fd\", offset: 0.35 },\n            { color: \"#c39bf8\", offset: 0.6 },\n            { color: PURPLE, offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 1,\n          y2: 0,\n        },\n      ],\n      guides: false,\n      margin: 0,\n      marks: [\n        polar({\n          endAngle: HALF,\n          marks: [\n            radialArc([{ endAngle: HALF, id: \"rim-track\", startAngle: -HALF }], {\n              ...ring(0.972, 0.985),\n              fill: \"#f1f1f4\",\n              key: \"id\",\n            }),\n            radialArc([{ endAngle: end - 0.1, id: \"rim\", startAngle: -HALF }], {\n              ...ring(0.966, 0.99),\n              cornerRadius: 3,\n              fill: \"url(#ro-rim)\",\n              key: \"id\",\n            }),\n            radialArc([{ endAngle: HALF, id: \"track\", startAngle: -HALF }], {\n              ...ring(0.58, 0.905),\n              cornerRadius: 10,\n              fill: \"#f6f6f8\",\n              key: \"id\",\n            }),\n            radialArc([{ endAngle: end, id: \"fill\", startAngle: -HALF }], {\n              ...ring(0.58, 0.905),\n              cornerRadius: 10,\n              fill: \"url(#ro-band)\",\n              key: \"id\",\n            }),\n            radialLine(trail, {\n              angle: \"a\",\n              curve: curveCatmullRom,\n              radius: \"r\",\n              stroke: \"url(#ro-line)\",\n              strokeWidth: 6,\n            }),\n            radialDot(\n              STOPS.filter((p) => p.k < hi),\n              {\n                angle: \"a\",\n                fill: \"#ffffff\",\n                key: \"id\",\n                r: 7.5,\n                radius: \"r\",\n              },\n            ),\n            radialDot(\n              STOPS.filter((p) => p.k < hi),\n              {\n                angle: \"a\",\n                fill: PURPLE,\n                key: \"id\",\n                r: 6,\n                radius: \"r\",\n                stroke: \"#c084fc\",\n                strokeWidth: 1.5,\n              },\n            ),\n            radialDot(\n              STOPS.filter((p) => p.k < 2),\n              {\n                angle: \"a\",\n                fill: BLUE,\n                key: \"id\",\n                r: 6,\n                radius: \"r\",\n                stroke: \"#60a5fa\",\n                strokeWidth: 1.5,\n              },\n            ),\n            radialDot([{ a: head?.a ?? 0, id: \"head\", r: head?.r ?? 0.78 }], {\n              angle: \"a\",\n              fill: \"#ffffff\",\n              key: \"id\",\n              r: 7.5,\n              radius: \"r\",\n              stroke: PURPLE,\n              strokeWidth: 4,\n            }),\n          ],\n          scales: {\n            angle: { scale: scaleLinear().domain([-HALF, HALF]) },\n            radius: { scale: scaleLinear().domain([0, 1]) },\n          },\n          startAngle: -HALF,\n        }),\n      ],\n      scales: { x: null, y: null },\n    });\n  }, [head, hi, end]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Revenue Overview</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n            Track your Revenue pattern and stay in control\n          </p>\n        </div>\n        <MoreButton />\n      </div>\n      <div\n        className=\"relative mt-4 overflow-hidden\"\n        style={{ height: VISIBLE }}\n        onMouseEnter={() => pin(STOPS.length - FIRST_ACTIVE - 1)}\n        onMouseLeave={() => pin(null)}\n      >\n        {active ? (\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={SIZE}\n            ariaLabel=\"Revenue gauge toward the monthly target\"\n          />\n        ) : null}\n        <div className=\"pointer-events-none absolute inset-x-0 bottom-1 flex flex-col items-center\">\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[12px] font-medium\"\n            style={{ backgroundColor: \"#e8f7ed\", borderColor: \"#bfe8cc\", color: GREEN }}\n          >\n            <Wallet className=\"size-3.5\" /> Revenue\n          </span>\n          <Num value={head?.v ?? 0} className=\"mt-1 text-[30px] font-bold tracking-[-0.03em]\" />\n          <p className=\"flex items-center gap-1 text-[12px]\" style={{ color: MUTED }}>\n            <span\n              className=\"inline-flex size-3.5 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-2.5\" strokeWidth={3} />\n            </span>\n            <span className=\"font-medium\" style={{ color: GREEN }}>\n              8.34%\n            </span>\n            vs last month\n          </p>\n        </div>\n      </div>\n      <div\n        className=\"mt-4 flex items-center justify-between gap-2 rounded-[14px] border px-3 py-2.5\"\n        style={{ backgroundColor: \"#e9f7ee\", borderColor: \"#bfe8cc\" }}\n      >\n        <div className=\"min-w-0\">\n          <p className=\"flex items-center gap-1.5 text-[13px] font-semibold\">\n            <Sparkle className=\"size-3.5\" style={{ color: GREEN, fill: GREEN }} />\n            Great Progress!\n          </p>\n          <p className=\"mt-0.5 text-[11px] text-[#3a3a42]\">\n            You&rsquo;re on track to exceed your monthly revenue target\n          </p>\n        </div>\n        <span\n          className=\"inline-flex shrink-0 items-center gap-0.5 text-[12px] font-medium\"\n          style={{ color: GREEN }}\n        >\n          View details <ArrowUpRight className=\"size-3.5\" />\n        </span>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/revenue-overview.tsx","target":"uicapsule/finance-charts/charts/revenue-overview.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, lineY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, CalendarDays, Sparkles } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, GRID, MUTED, THEME } from \"../lib/tokens\";\n\nconst DAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"] as const;\nconst ACTUAL = [7820, 10_410, 12_330, 16_120, 1790, 11_020, 12_449];\nconst TARGET = [18_600, 17_200, 17_900, 26_000, 12_600, 16_100, 18_400];\n\nconst FULL = [\n  \"Monday\",\n  \"Tuesday\",\n  \"Wednesday\",\n  \"Thursday\",\n  \"Friday\",\n  \"Saturday\",\n  \"Sunday\",\n] as const;\n\nconst DAY_INDEX = new Map<string, number>(DAYS.map((d, i) => [d, i]));\nconst TOTAL = ACTUAL.reduce((s, v) => s + v, 0) - 0.22;\n\nconst HEIGHT = 230;\nconst TOP = 26_000;\nconst FRONT = 0.74;\nconst DEPTH = 0.26;\nconst SLANT = 1500;\nconst ORANGE_BAR = \"#fb8c45\";\n\ninterface Vertex {\n  day: string;\n  x: number;\n  lo: number;\n  hi: number;\n}\n\nconst face = (day: string, x1: number, x2: number, lo: [number, number], hi: [number, number]) => [\n  { day, hi: hi[0], lo: lo[0], x: x1 },\n  { day, hi: hi[1], lo: lo[1], x: x2 },\n];\n\nexport const SalesPerformance = () => {\n  const [hi, pin] = useCycle(DAYS.length, 2200, 3);\n  const picked = DAYS[hi] ?? \"Thu\";\n\n  const definition = useMemo(() => {\n    const fronts: Vertex[] = [];\n    const sides: Vertex[] = [];\n    const ghosts: Vertex[] = [];\n    const ghostSides: Vertex[] = [];\n    const outlines: { day: string; id: string; x: number; y: number }[] = [];\n\n    for (const [i, day] of DAYS.entries()) {\n      const a = ACTUAL[i] ?? 0;\n      const t = TARGET[i] ?? 0;\n      const x1 = i;\n      const x2 = i + FRONT;\n      const x3 = x2 + DEPTH;\n      fronts.push(...face(day, x1, x2, [0, 0], [a, a]));\n      sides.push(...face(day, x2, x3, [0, 0], [a, Math.max(0, a - SLANT)]));\n      ghosts.push(...face(day, x1, x2, [a, a], [t, t]));\n      ghostSides.push(...face(day, x2, x3, [a, Math.max(0, a - SLANT)], [t, t - SLANT]));\n      outlines.push(\n        { day, id: `${day}-0`, x: x1, y: a },\n        { day, id: `${day}-1`, x: x1, y: t },\n        { day, id: `${day}-2`, x: x2, y: t },\n        { day, id: `${day}-3`, x: x3, y: t - SLANT },\n        { day, id: `${day}-4`, x: x3, y: Math.max(0, a - SLANT) },\n      );\n    }\n\n    const paint = (on: string, off: string) => (d: Vertex) => (d.day === picked ? on : off);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"sp-front\",\n          stops: [\n            { color: \"#e6e6e9\", offset: 0 },\n            { color: \"#fbfbfb\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"sp-side\",\n          stops: [\n            { color: \"#fafafa\", offset: 0 },\n            { color: \"#ececee\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n        {\n          id: \"sp-hot\",\n          stops: [\n            { color: \"#fb8c45\", offset: 0 },\n            { color: \"#fdc8a4\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"sp-hot-side\",\n          stops: [\n            { color: \"#fdf0e6\", offset: 0 },\n            { color: \"#fb9a5c\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n        {\n          id: \"sp-ghost\",\n          stops: [\n            { color: \"#fbfbfb\", offset: 0 },\n            { color: \"#ffffff\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"sp-hot-ghost\",\n          stops: [\n            { color: \"#fde6d6\", offset: 0 },\n            { color: \"#fff7f1\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      margin: { bottom: 26, left: 40, right: 0, top: 6 },\n      marks: [\n        areaY(ghosts, {\n          fill: paint(\"url(#sp-hot-ghost)\", \"url(#sp-ghost)\"),\n          fillOpacity: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"day\",\n        }),\n        areaY(ghostSides, {\n          fill: paint(\"url(#sp-hot-ghost)\", \"url(#sp-ghost)\"),\n          fillOpacity: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"day\",\n        }),\n        lineY(outlines, {\n          key: \"id\",\n          stroke: (d) => (d.day === picked ? \"#fbc9a6\" : \"#d4d4d8\"),\n          strokeDasharray: \"4 4\",\n          strokeWidth: 1,\n          x: \"x\",\n          y: \"y\",\n          z: \"day\",\n        }),\n        areaY(sides, {\n          fill: paint(\"url(#sp-hot-side)\", \"url(#sp-side)\"),\n          fillOpacity: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"day\",\n        }),\n        areaY(fronts, {\n          fill: paint(\"url(#sp-hot)\", \"url(#sp-front)\"),\n          fillOpacity: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"day\",\n        }),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (v: number) => DAYS[Math.round(v - (FRONT + DEPTH) / 2)] ?? \"\",\n              size: 0,\n              values: DAYS.map((_, i) => i + (FRONT + DEPTH) / 2),\n            },\n          },\n          scale: scaleLinear().domain([0, DAYS.length]),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (v: number) => compact(v),\n              size: 0,\n              values: [0, 5000, 10_000, 15_000, 20_000, 25_000],\n            },\n          },\n          scale: scaleLinear().domain([0, TOP]),\n        },\n      },\n      theme: { ...THEME, muted: \"#a1a1aa\" },\n    });\n  }, [picked]);\n\n  const lift = Math.round(((ACTUAL[hi] ?? 0) / Math.max(1, ACTUAL[(hi + 6) % 7] ?? 1)) * 100 - 100);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Sales Performance</h3>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            Weekly\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: MUTED }}>\n        Total revenue\n      </p>\n      <Num value={TOTAL} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n      <div className=\"mt-1 flex flex-wrap items-center justify-between gap-2\">\n        <p className=\"flex items-center gap-2 text-[12px]\" style={{ color: MUTED }}>\n          <span\n            className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-semibold\"\n            style={{ color: GREEN }}\n          >\n            <span\n              className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n              style={{ backgroundColor: GREEN }}\n            >\n              <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n            </span>\n            12.4%\n          </span>\n          vs last week\n        </p>\n        <div className=\"flex items-center gap-3 text-[11px] text-[#3a3a42]\">\n          <span className=\"inline-flex items-center gap-1.5\">\n            <span className=\"h-1 w-3 rounded-full\" style={{ backgroundColor: ORANGE_BAR }} />\n            Actual Revenue\n          </span>\n          <span className=\"inline-flex items-center gap-1.5\">\n            <span className=\"h-1 w-3.5 rounded-full bg-[repeating-linear-gradient(90deg,#fbc9a6_0_3px,transparent_3px_5px)]\" />\n            Daily Target\n          </span>\n        </div>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Daily revenue against daily target\"\n            onFocusChange={(p) => {\n              const day = p?.datum && \"day\" in p.datum ? p.datum.day : null;\n              const i = day === null ? -1 : (DAY_INDEX.get(day) ?? -1);\n\n              if (i !== -1) {\n                pin(i);\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n      <div\n        className=\"mt-3 flex items-center gap-2 rounded-xl border bg-[#fafafa] px-3 py-2.5 text-[12px]\"\n        style={{ borderColor: GRID }}\n      >\n        <Sparkles className=\"size-3.5 shrink-0\" style={{ color: ORANGE_BAR }} fill={ORANGE_BAR} />\n        <p className=\"text-[#55555e]\">\n          <span className=\"font-semibold text-[#0b0b0f]\">Insights:</span> {FULL[hi]}&apos;s revenue{\" \"}\n          {lift >= 0 ? \"rose\" : \"fell\"} {Math.abs(lift)}% from the day before.\n        </p>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/sales-performance.tsx","target":"uicapsule/finance-charts/charts/sales-performance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport { Card, ChartSlot, Legend, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { MUTED, THEME } from \"../lib/tokens\";\n\nconst VIOLET_BAR = \"#a12ff5\";\nconst IDLE = \"#ebebee\";\nconst COUNT = 40;\nconst PROGRESS = [27.5, 46.2, 71.8, 38.4, 88.6] as const;\nconst TARGET = 39_673;\n\nconst MARGIN = { bottom: 26, left: 0, right: 0, top: 0 };\nconst HEIGHT = 64;\n\nexport const SalesTarget = () => {\n  const [step, pin] = useCycle(PROGRESS.length, 2600, 0);\n  const pct = PROGRESS[step] ?? PROGRESS[0];\n  const filled = Math.round((pct / 100) * COUNT);\n\n  const definition = useMemo(() => {\n    const rows = Array.from({ length: COUNT }, (_, i) => ({\n      i,\n      on: i < filled,\n      x: ((i + 0.5) / COUNT) * 100,\n    }));\n\n    return defineChart({\n      focusRing: false,\n      margin: MARGIN,\n      marks: [\n        barY(rows, {\n          fill: (d) => (d.on ? VIOLET_BAR : IDLE),\n          key: \"i\",\n          radius: 2.5,\n          x: \"x\",\n          y1: (d) => (d.on ? 0 : 0.17),\n          y2: (d) => (d.on ? 1 : 0.83),\n        }),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: {\n              anchor: ({ index }) => {\n                if (index === 0) {\n                  return \"start\";\n                }\n\n                return index === 4 ? \"end\" : \"middle\";\n              },\n              fontSize: 12,\n            },\n            ticks: { format: (v) => `${v}%`, padding: 10, size: 0, values: [0, 25, 50, 75, 100] },\n          },\n          scale: scaleLinear().domain([0, 100]),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, 1]) },\n      },\n      theme: THEME,\n    });\n  }, [filled]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Sales Target</h3>\n        <MoreButton />\n      </div>\n      <div className=\"mt-3 flex items-end justify-between gap-3\">\n        <div>\n          <Num\n            value={(TARGET * pct) / 100}\n            format={(n) => usd(n, true)}\n            className=\"block text-[28px] font-bold tracking-[-0.03em]\"\n          />\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Project Earnings\n          </p>\n        </div>\n        <Legend\n          swatch=\"bar\"\n          className=\"justify-end pb-0.5 !text-[11px]\"\n          items={[\n            { color: VIOLET_BAR, label: \"Actual Revenue\" },\n            { color: \"#e2e2e6\", label: \"Monthly Target\" },\n          ]}\n        />\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Sales progress toward the monthly target\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(step);\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/sales-target.tsx","target":"uicapsule/finance-charts/charts/sales-target.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { PiggyBank } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd } from \"../lib/data\";\nimport {\n  CardHeader,\n  Card,\n  ChartSlot,\n  Delta,\n  MoreButton,\n  Num,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN, GRID, MUTED } from \"../lib/tokens\";\n\nconst SLOTS = 42;\nconst GOAL = 20_000;\nconst BASE_FILLED = 11;\nconst BASE_SAVED = 5238.1;\nconst STEP = GOAL / SLOTS;\nconst DEPOSITS = 4;\nconst HEIGHT = 92;\n\nconst slots = Array.from({ length: SLOTS }, (_, i) => ({ id: `s${i}`, slot: i }));\n\nexport const SavingProgress = () => {\n  const [step, pin] = useCycle(DEPOSITS, 1800);\n  const filled = BASE_FILLED + step;\n  const saved = BASE_SAVED + step * STEP;\n  const percent = Math.round((saved / GOAL) * 100);\n  const projected = filled + 2;\n\n  const definition = useMemo(() => {\n    const done = slots.filter((s) => s.slot < filled);\n    const ahead = slots.filter((s) => s.slot >= filled && s.slot < projected);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"sp-green\",\n          stops: [\n            { color: \"#22c55e\", offset: 0 },\n            { color: GREEN, offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: 0,\n      marks: [\n        barY(slots, {\n          fill: \"#f5f5f7\",\n          id: \"track\",\n          key: \"id\",\n          radius: 3,\n          x: \"slot\",\n          y: () => 1,\n        }),\n        barY(ahead, {\n          fill: BLUE,\n          fillOpacity: 0.16,\n          id: \"ahead\",\n          key: \"id\",\n          radius: 3,\n          x: \"slot\",\n          y: () => 1,\n        }),\n        barY(done, {\n          fill: \"url(#sp-green)\",\n          id: \"done\",\n          key: \"id\",\n          radius: 3,\n          x: \"slot\",\n          y: () => 1,\n        }),\n      ],\n      scales: {\n        x: {\n          axis: false,\n          scale: scaleBand<number>()\n            .domain(slots.map((s) => s.slot))\n            .paddingInner(0.18)\n            .paddingOuter(0),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, 1]) },\n      },\n    });\n  }, [filled, projected]);\n\n  return (\n    <Card>\n      <CardHeader icon={PiggyBank} color={GREEN} title=\"Saving progress\" actions={<MoreButton />} />\n      <p className=\"mt-1.5 text-[12px]\" style={{ color: MUTED }}>\n        You&rsquo;re on track to reach your saving target{\" \"}\n        <span style={{ color: GREEN }}>3 days early</span>\n      </p>\n      <div className=\"mt-4 border-t pt-4\" style={{ borderColor: GRID }}>\n        <div className=\"flex items-center gap-3\">\n          <Num\n            value={percent}\n            format={(n) => `${Math.round(n)}%`}\n            className=\"text-[36px] font-semibold tracking-[-0.03em]\"\n          />\n          <span className=\"inline-flex items-center rounded-full bg-[#dcfce7] px-2 py-0.5 text-[12px]\">\n            <Delta value={2.64} variant=\"circle\" />\n          </span>\n          <span className=\"text-[12px]\" style={{ color: MUTED }}>\n            Vs last month\n          </span>\n        </div>\n        <p className=\"text-[12px]\" style={{ color: MUTED }}>\n          Of monthly saving goals\n        </p>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseEnter={() => pin(step)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel={`${filled} of ${SLOTS} saving slots filled`}\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-4 grid grid-cols-3 text-[11px] whitespace-nowrap\">\n        <div className=\"pr-2\">\n          <p className=\"inline-flex items-center gap-1.5\" style={{ color: MUTED }}>\n            <span className=\"h-1.5 w-3 rounded-full bg-[#ececf0]\" />\n            Monthly goals\n          </p>\n          <p className=\"mt-1 text-[15px] font-semibold tabular-nums\">{usd(GOAL, true)}</p>\n        </div>\n        <div className=\"border-l px-3\" style={{ borderColor: GRID }}>\n          <p className=\"inline-flex items-center gap-1.5\" style={{ color: MUTED }}>\n            <span className=\"h-1.5 w-3 rounded-full\" style={{ backgroundColor: GREEN }} />\n            Saved so far\n          </p>\n          <Num value={saved} className=\"mt-1 block text-[15px] font-semibold\" />\n        </div>\n        <div className=\"border-l pl-3\" style={{ borderColor: GRID }}>\n          <p className=\"inline-flex items-center gap-1.5\" style={{ color: MUTED }}>\n            <span className=\"h-1.5 w-3 rounded-full\" style={{ backgroundColor: BLUE }} />\n            Est completion\n          </p>\n          <p className=\"mt-1 text-[15px] font-semibold\" style={{ color: GREEN }}>\n            3 days early\n          </p>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/saving-progress.tsx","target":"uicapsule/finance-charts/charts/saving-progress.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { bandX, barY, defineChart, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { Car, ShoppingBag, Wallet } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng, WEEKDAYS } from \"../lib/data\";\nimport { Card, ChartSlot, MoreButton, Num, Segmented, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE, GREEN, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst HEIGHT = 250;\nconst BASE = 30;\nconst TOP = HEIGHT - 14;\nconst CAP = 13;\nconst LABEL_Y = 12;\n\nconst RANGES = [\n  [0.22, 0.47, 0.36, 0.69, 0.22, 0.36, 0.47],\n  [0.41, 0.3, 0.58, 0.52, 0.66, 0.27, 0.44],\n  [0.62, 0.55, 0.31, 0.78, 0.48, 0.58, 0.38],\n] as const;\n\nconst HOT_DAY = [3, 4, 3] as const;\n\nconst DAY_LIST: readonly string[] = WEEKDAYS;\n\nconst level = (v: number) => BASE + v * (TOP - BASE);\n\nconst SPARKS = (() => {\n  const r = rng(515);\n\n  return Array.from({ length: 14 }, (_, i) => ({\n    dx: (r() - 0.5) * 0.7,\n    id: i,\n    size: 3 + r() * 4,\n    t: 0.08 + r() * 0.84,\n  }));\n})();\n\nconst TRANSACTIONS: {\n  amount: number;\n  icon: LucideIcon;\n  time: string;\n  tint: string;\n  title: string;\n}[] = [\n  { amount: 2764, icon: Wallet, time: \"9:24 AM\", tint: BLUE, title: \"Salary Deposit\" },\n  { amount: 67.93, icon: Car, time: \"12:24 PM\", tint: ORANGE, title: \"Fuel\" },\n  { amount: 320.63, icon: ShoppingBag, time: \"10:05 AM\", tint: GREEN, title: \"Groceries\" },\n];\n\nexport const SpendingOverviewCylinder = () => {\n  const [range, setRange] = useCycle(RANGES.length, 9000, 0);\n  const [hi, pin] = useCycle(WEEKDAYS.length, 1800, HOT_DAY[0]);\n  const values = RANGES[range] ?? RANGES[0];\n\n  const definition = useMemo(() => {\n    const days = WEEKDAYS.map((day, i) => ({ day, hot: i === hi, level: level(values[i] ?? 0) }));\n    const hot = days[hi] ?? days[0];\n\n    const sparks = SPARKS.map((s) => ({\n      ...s,\n      day: hot?.day ?? \"Sun\",\n      y: BASE + s.t * ((hot?.level ?? BASE) - BASE - CAP),\n    }));\n\n    return defineChart({\n      focusRing: false,\n      gradients: [\n        {\n          id: \"soc-glow\",\n          stops: [\n            { color: \"#e3efff\", offset: 0, opacity: 0 },\n            { color: \"#e3efff\", offset: 0.55, opacity: 1 },\n            { color: \"#e3efff\", offset: 0.9, opacity: 0 },\n          ],\n          x1: 0,\n          x2: 0,\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"soc-gray\",\n          stops: [\n            { color: \"#ebebed\", offset: 0 },\n            { color: \"#e2e2e5\", offset: 0.55 },\n            { color: \"#d3d3d7\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 1,\n          y1: 0,\n          y2: 0,\n        },\n        {\n          id: \"soc-hot\",\n          stops: [\n            { color: \"#d47bf8\", offset: 0 },\n            { color: \"#b9a6fb\", offset: 0.3 },\n            { color: \"#a6f6f6\", offset: 0.62 },\n            { color: \"#46a6ff\", offset: 1 },\n          ],\n          x1: 0,\n          x2: 0,\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: 0,\n      marks: [\n        bandX(\n          days.filter((d) => d.hot),\n          {\n            fill: \"url(#soc-glow)\",\n            inset: -7,\n            key: () => \"glow\",\n            x: \"day\",\n          },\n        ),\n        barY(days, {\n          fill: \"#f7f7f8\",\n          key: (d) => `${d.day}-tube`,\n          radius: [0, 0, 14, 14],\n          stroke: \"#ebebee\",\n          strokeWidth: 1,\n          x: \"day\",\n          y1: BASE - CAP / 2,\n          y2: TOP,\n        }),\n        barY(days, {\n          fill: \"#f9f9fa\",\n          key: (d) => `${d.day}-rim`,\n          radius: 999,\n          stroke: \"#e6e6e9\",\n          strokeWidth: 1,\n          x: \"day\",\n          y1: TOP - CAP / 2,\n          y2: TOP + CAP / 2,\n        }),\n        barY(days, {\n          fill: (d) => (d.hot ? \"url(#soc-hot)\" : \"url(#soc-gray)\"),\n          key: (d) => `${d.day}-body`,\n          radius: [0, 0, 14, 14],\n          x: \"day\",\n          y1: BASE - CAP / 2,\n          y2: \"level\",\n        }),\n        text(sparks, {\n          dx: (d) => d.dx * 40,\n          fill: \"rgba(255,255,255,0.85)\",\n          fontSize: 6,\n          key: \"id\",\n          text: () => \"•\",\n          x: \"day\",\n          y: \"y\",\n        }),\n        barY(days, {\n          fill: (d) => (d.hot ? \"#ffffff\" : \"#d9d9dd\"),\n          key: (d) => `${d.day}-lip`,\n          radius: 999,\n          x: \"day\",\n          y1: (d) => d.level - CAP / 2,\n          y2: (d) => d.level + CAP / 2,\n        }),\n        barY(days, {\n          fill: (d) => (d.hot ? \"#c069f6\" : \"#a2a2a7\"),\n          inset: 6,\n          key: (d) => `${d.day}-surface`,\n          radius: 999,\n          x: \"day\",\n          y1: (d) => d.level - CAP * 0.3,\n          y2: (d) => d.level + CAP * 0.3,\n        }),\n        text(days, {\n          fill: (d) => (d.hot ? BLUE : \"#a4a4ab\"),\n          fontSize: 12,\n          fontWeight: 500,\n          key: (d) => `${d.day}-label`,\n          text: \"day\",\n          x: \"day\",\n          y: () => LABEL_Y,\n        }),\n      ],\n      scales: {\n        x: {\n          scale: scaleBand<string>()\n            .domain([...WEEKDAYS])\n            .paddingInner(0.2)\n            .paddingOuter(0.05),\n        },\n        y: { scale: scaleLinear().domain([0, HEIGHT]) },\n      },\n      theme: THEME,\n    });\n  }, [values, hi]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <h3 className=\"truncate pt-1 text-[16px] font-semibold tracking-[-0.01em]\">\n          Spending Overview\n        </h3>\n        <div className=\"flex shrink-0 items-center gap-1.5\">\n          <span\n            className=\"inline-flex h-8 items-center gap-1 rounded-full px-2 text-[11px] font-medium\"\n            style={{\n              backgroundColor: \"#e8f8ed\",\n              boxShadow: \"inset 0 0 0 1px #bfe9cc\",\n              color: GREEN,\n            }}\n          >\n            <Wallet className=\"size-3\" strokeWidth={2.6} />\n            Balance <Num value={2653.87} className=\"font-semibold\" />\n          </span>\n          <MoreButton />\n        </div>\n      </div>\n      <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n        Track your spending pattern and stay in control\n      </p>\n      <Segmented\n        options={[\"Week\", \"Month\", \"Year\"]}\n        value={range}\n        onChange={setRange}\n        className=\"mt-4\"\n      />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Spending by weekday, drawn as filling cylinders\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(DAY_LIST.indexOf(String(p.xValue)));\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-4 flex flex-col gap-2\">\n        {TRANSACTIONS.map(({ amount, icon: Icon, time, tint, title }) => (\n          <div\n            key={title}\n            className=\"flex items-center gap-3 rounded-2xl bg-[#f6f6f7] px-3 py-2.5 ring-1 ring-black/[0.04]\"\n          >\n            <span\n              className=\"inline-flex size-9 items-center justify-center rounded-full\"\n              style={{\n                backgroundColor: `color-mix(in oklab, ${tint} 12%, white)`,\n                boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${tint} 28%, white)`,\n                color: tint,\n              }}\n            >\n              <Icon className=\"size-4\" strokeWidth={2.4} />\n            </span>\n            <div className=\"min-w-0 flex-1\">\n              <p className=\"text-[13px] font-medium\">{title}</p>\n              <p className=\"text-[11px]\" style={{ color: MUTED }}>\n                June 17, 2026 · {time}\n              </p>\n            </div>\n            <Num value={amount} className=\"text-[14px] font-semibold\" />\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/spending-overview-cylinder.tsx","target":"uicapsule/finance-charts/charts/spending-overview-cylinder.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { PieChart } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { compact, rng, usd } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  IconTile,\n  Caption,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { DASHED_GRID, GRID, ORANGE, THEME } from \"../lib/tokens\";\nimport { PeriodChip, UsdChip } from \"./cash-flow-daily-bar-chrome\";\n\nconst DAYS = [\"May 1\", \"May 2\", \"May 3\", \"May 4\", \"May 5\", \"May 6\", \"May 7\"];\nconst PER_DAY = 7;\nconst LO = 5000;\nconst HI = 20_000;\n\ninterface Segment {\n  id: string;\n  slot: string;\n  day: number;\n  y1: number;\n  y2: number;\n}\n\nconst SEGMENTS: Segment[] = (() => {\n  const r = rng(4242);\n  const out: Segment[] = [];\n\n  for (let day = 0; day < DAYS.length; day += 1) {\n    const base = day === 2 ? 7000 : 9500;\n\n    for (let k = 0; k < PER_DAY; k += 1) {\n      const slot = `${day}-${k}`;\n      const low = base + r() * 6500;\n      const len = 1200 + r() * 4200;\n      out.push({ day, id: `${slot}-a`, slot, y1: low, y2: Math.min(HI - 800, low + len) });\n\n      if (r() < 0.45) {\n        const above = r() < 0.5;\n        const y1 = above ? low + len + 500 : low - 1100;\n\n        if (y1 + 600 > HI - 300) {\n          continue;\n        }\n\n        out.push({ day, id: `${slot}-b`, slot, y1, y2: y1 + 600 });\n      }\n    }\n  }\n\n  return out;\n})();\n\nconst SLOTS = [...new Set(SEGMENTS.map((s) => s.slot))];\nconst MIDDLES = DAYS.map((_, d) => `${d}-${Math.floor(PER_DAY / 2)}`);\nconst GRID_LINES = { ...DASHED_GRID, stroke: \"#e2e2e7\", strokeOpacity: 1 };\n\nconst DAY_LOWS = DAYS.map((_, d) =>\n  Math.min(...SEGMENTS.flatMap((s) => (s.day === d ? [s.y1] : []))),\n);\n\nconst MARGIN = { bottom: 30, left: 36, right: 0, top: 10 };\nconst HEIGHT = 210;\n\nexport const SpendingOverviewRange = () => {\n  const [hi, pin] = useCycle(DAYS.length, 2000, 2);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        margin: MARGIN,\n        marks: [\n          ruleY([LO], { stroke: GRID, strokeOpacity: 1, strokeWidth: 1 }),\n          barY(SEGMENTS, {\n            fill: (d) => (d.day === hi ? ORANGE : \"#ededf0\"),\n            key: \"id\",\n            radius: 4,\n            x: \"slot\",\n            y1: \"y1\",\n            y2: \"y2\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 11,\n                fontWeight: (c) => (c.value === MIDDLES[hi] ? 600 : 400),\n              },\n              ticks: {\n                format: (v) => DAYS[Number(v.split(\"-\")[0])] ?? \"\",\n                padding: 10,\n                size: 0,\n                values: MIDDLES,\n              },\n            },\n            scale: scaleBand<string>().domain(SLOTS).paddingInner(0.45).paddingOuter(0.3),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: { format: (v) => compact(v), size: 0, values: [5000, 10_000, 15_000, 20_000] },\n            },\n            grid: GRID_LINES,\n            scale: scaleLinear().domain([LO, HI]),\n          },\n        },\n        theme: THEME,\n      }),\n    [hi],\n  );\n\n  const low = DAY_LOWS[hi] ?? LO;\n\n  return (\n    <Card>\n      <div className=\"flex items-center justify-between gap-2\">\n        <div className=\"flex min-w-0 items-center gap-2\">\n          <IconTile icon={PieChart} color={ORANGE} size={30} />\n          <h3 className=\"truncate text-[14px] font-semibold tracking-[-0.01em]\">\n            Spending Overview\n          </h3>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-1\">\n          <UsdChip compact />\n          <PeriodChip compact label=\"Weekly\" />\n        </div>\n      </div>\n      <div className=\"mt-5 grid grid-cols-3 gap-2\">\n        {[\n          { label: \"Total spending\", value: 151_083.4 },\n          { label: \"Daily average\", value: 21_583.34 },\n          { label: \"Lowest day\", value: 13_916.67 },\n        ].map((s) => (\n          <div key={s.label} className=\"min-w-0\">\n            <Caption className=\"truncate\">{s.label}</Caption>\n            <Num\n              value={s.value}\n              className=\"mt-0.5 block text-[16px] font-bold tracking-[-0.03em]\"\n            />\n          </div>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Intraday spending ranges for each day of the week\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(Number(String(p.xValue).split(\"-\")[0]));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            dark\n            left={(hi === DAYS.length - 1 ? hi : hi + 1) * (100 / DAYS.length)}\n            top={Math.min(80, 100 - ((low - LO) / (HI - LO)) * 100)}\n            align={hi === DAYS.length - 1 ? \"right\" : \"left\"}\n            className=\"-translate-y-1/2 text-center leading-tight\"\n          >\n            <span className=\"block text-[10px] text-white/60\">Low · {DAYS[hi]}</span>\n            <span className=\"font-semibold\">{usd(low, true)}</span>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n    </Card>\n  );\n};\n","path":"/charts/spending-overview-range.tsx","target":"uicapsule/finance-charts/charts/spending-overview-range.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { d3Curve, defineChart, lineY, rect } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { curveMonotoneX } from \"d3-shape\";\nimport { ArrowUpRight } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { MONTHS, rng, usd } from \"../lib/data\";\nimport { Bubble, Card, ChartSlot, Num, PlotOverlay, renderer, useCycle } from \"../lib/kit\";\nimport { GRID, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst COLS = 24;\nconst ROWS = 16;\nconst TOP = 4000;\nconst STEP = TOP / ROWS;\nconst SPAN = MONTHS.slice(0, 7);\nconst PER = COLS / SPAN.length;\n\nconst MARGIN = { bottom: 26, left: 44, right: 0, top: 4 };\nconst HEIGHT = 228;\n\nconst SERIES = [\n  { color: \"#bcdcfd\", id: \"income\", label: \"Income\" },\n  { color: \"#5ea8f7\", id: \"expenses\", label: \"Expenses\" },\n  { color: \"#0a6edb\", id: \"investment\", label: \"Investment\" },\n] as const;\n\ntype SeriesId = (typeof SERIES)[number][\"id\"];\n\nconst trend = (x: number) => 400 * 10 ** (x / COLS);\n\ninterface Cell {\n  id: string;\n  c: number;\n  r: number;\n}\n\nconst grid: Cell[] = [];\n\nfor (let c = 0; c < COLS; c += 1) {\n  for (let r = 0; r < ROWS; r += 1) {\n    grid.push({ c, id: `${c}-${r}`, r });\n  }\n}\n\ninterface Hit extends Cell {\n  series: SeriesId;\n}\n\nconst hits: Hit[] = (() => {\n  const rand = rng(712);\n  const out: Hit[] = [];\n  const seen = new Set<string>();\n\n  for (let c = 0; c < COLS; c += 1) {\n    const count = rand() > 0.4 ? 2 : 1;\n\n    for (let k = 0; k < count; k += 1) {\n      const base = trend(c + 0.5) / STEP;\n      const r = Math.max(0, Math.min(ROWS - 1, Math.round(base + (rand() - 0.5) * 6)));\n      const id = `${c}-${r}`;\n\n      if (!seen.has(id)) {\n        seen.add(id);\n        out.push({ c, id, r, series: SERIES[Math.floor(rand() * 3)]?.id ?? \"income\" });\n      }\n    }\n  }\n\n  return out;\n})();\n\nconst curve = Array.from({ length: COLS * 2 + 1 }, (_, i) => ({ x: i / 2, y: trend(i / 2) }));\n\nconst totals = SPAN.map((_, i) => {\n  const rand = rng(90 + i);\n  const scale = 0.55 + i * 0.12;\n\n  return {\n    expenses: (900 + rand() * 500) * scale,\n    income: (1400 + rand() * 600) * scale,\n    investment: (650 + rand() * 400) * scale,\n  };\n});\n\nconst FULL = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\"] as const;\n\nexport const SpendingOverviewScatter = () => {\n  const [month, pin] = useCycle(SPAN.length, 2300, 2);\n  const values = totals[month] ?? totals[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        clip: true,\n        margin: MARGIN,\n        marks: [\n          rect([{ id: \"hl\", m: month }], {\n            fill: \"#fff1e6\",\n            id: \"highlight\",\n            inset: 0,\n            key: \"id\",\n            radius: 4,\n            x1: (d) => d.m * PER,\n            x2: (d) => (d.m + 1) * PER,\n            y1: () => 0,\n            y2: () => TOP,\n          }),\n          rect(grid, {\n            fill: \"#14141f\",\n            fillOpacity: 0.04,\n            id: \"grid\",\n            inset: 1.6,\n            key: \"id\",\n            radius: 3,\n            x: (d) => d.c + 0.5,\n            x1: \"c\",\n            x2: (d) => d.c + 1,\n            y1: (d) => d.r * STEP,\n            y2: (d) => (d.r + 1) * STEP,\n          }),\n          ...SERIES.map((s) =>\n            rect(\n              hits.filter((h) => h.series === s.id),\n              {\n                fill: s.color,\n                id: s.id,\n                inset: 1.6,\n                key: \"id\",\n                radius: 3,\n                x: (d) => d.c + 0.5,\n                x1: \"c\",\n                x2: (d) => d.c + 1,\n                y1: (d) => d.r * STEP,\n                y2: (d) => (d.r + 1) * STEP,\n              },\n            ),\n          ),\n          lineY(curve, {\n            curve: d3Curve(curveMonotoneX),\n            id: \"trend\",\n            stroke: ORANGE,\n            strokeDasharray: \"5 5\",\n            strokeWidth: 2,\n            x: \"x\",\n            y: \"y\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 12,\n                fontWeight: (c) => (Math.floor(c.value / PER) === month ? 700 : 400),\n              },\n              ticks: {\n                format: (v: number) => SPAN[Math.floor(v / PER)] ?? \"\",\n                padding: 8,\n                size: 0,\n                values: SPAN.map((_, i) => (i + 0.5) * PER),\n              },\n            },\n            scale: scaleLinear().domain([0, COLS]),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 12 },\n              ticks: {\n                format: (v: number) => `$${v}`,\n                padding: 8,\n                size: 0,\n                values: [0, 1000, 2000, 3000, 4000],\n              },\n            },\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [month],\n  );\n\n  const right = month <= 2;\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Spending Overview</h3>\n          <p className=\"mt-0.5 text-[12px]\" style={{ color: MUTED }}>\n            Track your spending pattern and stay in control\n          </p>\n        </div>\n        <button\n          type=\"button\"\n          aria-label=\"Open\"\n          className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full border border-black/[0.08] text-[#8a8a93]\"\n        >\n          <ArrowUpRight className=\"size-4\" />\n        </button>\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Monthly income, expenses and investment as a dot grid\"\n            onFocusChange={(p) => {\n              const x = Number(p?.xValue);\n\n              if (p && Number.isFinite(x)) {\n                pin(Math.min(SPAN.length - 1, Math.floor(x / PER)));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={((right ? month + 1 : month) / SPAN.length) * 100}\n            top={6}\n            align={right ? \"left\" : \"right\"}\n            dark\n            className={`${right ? \"ml-1\" : \"-ml-1\"} !rounded-[12px] !p-0 text-[11px]`}\n          >\n            <p className=\"border-b border-white/10 px-2.5 py-1.5 text-white/80\">\n              {`${FULL[month] ?? \"\"}, 2026`}\n            </p>\n            <div className=\"space-y-1 px-2.5 py-1.5\">\n              {SERIES.map((s) => (\n                <div key={s.id} className=\"flex items-center justify-between gap-4\">\n                  <span className=\"inline-flex items-center gap-1.5 text-white/70\">\n                    <span className=\"size-2 rounded-full\" style={{ backgroundColor: s.color }} />\n                    {s.label}\n                  </span>\n                  <span className=\"font-semibold tabular-nums\">{usd(values?.[s.id] ?? 0)}</span>\n                </div>\n              ))}\n            </div>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-4 grid grid-cols-3 gap-2\">\n        {SERIES.map((s) => (\n          <div\n            key={s.id}\n            className=\"rounded-[14px] border bg-[#f7f7f8] px-2.5 py-2\"\n            style={{ borderColor: GRID }}\n          >\n            <p className=\"inline-flex items-center gap-1.5 text-[11px]\" style={{ color: MUTED }}>\n              <span className=\"size-2 rounded-full\" style={{ backgroundColor: s.color }} />\n              {s.label}\n            </p>\n            <Num\n              value={values?.[s.id] ?? 0}\n              className=\"mt-0.5 block text-[14px] font-semibold tracking-[-0.01em]\"\n            />\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/spending-overview-scatter.tsx","target":"uicapsule/finance-charts/charts/spending-overview-scatter.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, text } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, Ellipsis, Lock } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { Card, ChartSlot, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst COUNT = 25;\n\nconst MARKERS = new Map([\n  [0, \"0\"],\n  [12, \"50\"],\n  [24, \"100\"],\n]);\n\nconst FILLED = 9;\nconst HOLD = 8;\nconst HEIGHT = 150;\nconst MARGIN = { bottom: 2, left: 0, right: 0, top: 22 };\n\nconst BARS = Array.from({ length: COUNT }, (_, i) => ({\n  i,\n  marker: MARKERS.has(i),\n}));\n\nconst LABELS = BARS.filter((b) => b.marker);\n\nexport const TotalBalance = () => {\n  const [frame, pin] = useCycle(FILLED + HOLD, 210, FILLED + HOLD - 1);\n  const lit = Math.min(FILLED, frame + 1);\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"tb-on\",\n            stops: [\n              { color: \"#139443\", offset: 0 },\n              { color: \"#22c55e\", offset: 0.42 },\n              { color: \"#16a34a\", offset: 0.62 },\n              { color: \"#117f37\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n          {\n            id: \"tb-off\",\n            stops: [\n              { color: \"#d4d4d8\", offset: 0 },\n              { color: \"#ececef\", offset: 0.42 },\n              { color: \"#e2e2e5\", offset: 0.62 },\n              { color: \"#cdcdd1\", offset: 1 },\n            ],\n            x1: 0,\n            x2: 1,\n            y1: 0,\n            y2: 0,\n          },\n        ],\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          barY(BARS, {\n            fill: (d) => (d.i < lit ? \"url(#tb-on)\" : \"url(#tb-off)\"),\n            key: \"i\",\n            radius: 4,\n            stroke: (d) => (d.i < lit ? \"#15803d\" : \"#cacace\"),\n            strokeWidth: 1,\n            x: \"i\",\n            y1: 0,\n            y2: (d) => (d.marker ? 1 : 0.84),\n          }),\n          text(LABELS, {\n            anchor: (d) => {\n              if (d.i === 0) {\n                return \"start\";\n              }\n\n              return d.i === COUNT - 1 ? \"end\" : \"middle\";\n            },\n            dx: (d) => {\n              if (d.i === 0) {\n                return -4;\n              }\n\n              return d.i === COUNT - 1 ? 4 : 0;\n            },\n            dy: -11,\n            fill: (d) => (d.i === 0 ? GREEN : \"#a1a1aa\"),\n            fontSize: 12,\n            key: \"i\",\n            text: (d) => MARKERS.get(d.i) ?? \"\",\n            x: \"i\",\n            y: () => 1,\n          }),\n        ],\n        scales: {\n          x: {\n            scale: scaleBand<number>()\n              .domain(BARS.map((b) => b.i))\n              .paddingInner(0.42)\n              .paddingOuter(0),\n          },\n          y: { scale: scaleLinear().domain([0, 1]) },\n        },\n        theme: THEME,\n      }),\n    [lit],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <p className=\"text-[13px]\" style={{ color: MUTED }}>\n          Total balance\n        </p>\n        <Ellipsis className=\"size-5 text-[#a1a1aa]\" />\n      </div>\n      <div className=\"mt-1 flex items-center gap-2.5\">\n        <Num value={357_835.58} className=\"text-[30px] font-bold tracking-[-0.03em]\" />\n        <span className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 text-[12px] font-medium text-[#16a34a]\">\n          <span className=\"inline-flex size-3.5 items-center justify-center rounded-full bg-[#16a34a] text-white\">\n            <ArrowUp className=\"size-2.5\" strokeWidth={3.2} />\n          </span>\n          2.64%\n        </span>\n      </div>\n      <div className=\"mt-2 flex gap-1.5\">\n        {[\"min 8.6% APR\", \"earned +457.97\"].map((c) => (\n          <span\n            key={c}\n            className=\"rounded-full bg-[#ededf0] px-2.5 py-1 text-[12px] font-medium text-[#55555c]\"\n          >\n            {c}\n          </span>\n        ))}\n      </div>\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseEnter={() => pin(FILLED + HOLD - 1)} onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Lock-up maturity: 35% of 100\"\n          />\n        </div>\n      </ChartSlot>\n      <div className=\"mt-5 flex items-end justify-between\">\n        <div>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Unlock at\n          </p>\n          <p className=\"mt-0.5 text-[20px] font-bold tracking-[-0.02em]\">May 20, 2026</p>\n        </div>\n        <p\n          className=\"inline-flex items-center gap-1.5 pb-0.5 text-[14px] font-medium\"\n          style={{ color: GREEN }}\n        >\n          <Lock className=\"size-4\" strokeWidth={2.4} fill=\"currentColor\" fillOpacity={0.2} />\n          <Num value={35} format={(n) => `${Math.round(n)}% maturity`} />\n        </p>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/total-balance.tsx","target":"uicapsule/finance-charts/charts/total-balance.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot, lineY, ruleX, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { CreditCard } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { usd, WEEKDAYS } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Chip,\n  Delta,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GRID, MUTED, ORANGE, PURPLE } from \"../lib/tokens\";\n\nconst VALUES = [\n  31_200, 35_400, 33_100, 33_800, 32_900, 32_100, 33_700, 37_300, 36_500, 38_400, 40_300, 42_900,\n  46_200,\n] as const;\n\nconst ROWS = VALUES.map((value, i) => ({ i, value }));\nconst LAST = ROWS.length - 1;\nconst TOP = 52_000;\nconst BOTTOM = 8000;\n\nconst CATEGORIES = [\n  { amount: 4250, change: 4.82, color: BLUE, label: \"Shopping\" },\n  { amount: 846.85, change: 2.64, color: ORANGE, label: \"Subscriptions\" },\n  { amount: 2753.04, change: -1.64, color: PURPLE, label: \"Investment\" },\n] as const;\n\nconst MARGIN = { bottom: 0, left: 0, right: 0, top: 6 };\nconst HEIGHT = 168;\n\nconst dayFor = (i: number) => WEEKDAYS[Math.min(6, Math.round((i / LAST) * 6))] ?? \"Sun\";\n\nexport const TotalExpenses = () => {\n  const [hi, pin] = useCycle(ROWS.length, 1500, 8);\n  const picked = ROWS[hi] ?? ROWS[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"te-fill\",\n            stops: [\n              { color: BLUE, offset: 0, opacity: 0.2 },\n              { color: BLUE, offset: 1, opacity: 0 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        guides: false,\n        margin: MARGIN,\n        marks: [\n          ruleY([TOP], { stroke: GRID, strokeDasharray: \"4 4\", strokeOpacity: 1 }),\n          areaY(ROWS, { fill: \"url(#te-fill)\", fillOpacity: 1, x: \"i\", y1: BOTTOM, y2: \"value\" }),\n          ruleX([picked?.i ?? 0], {\n            stroke: BLUE,\n            strokeDasharray: \"3 3\",\n            strokeOpacity: 0.45,\n          }),\n          lineY(ROWS, { stroke: BLUE, strokeWidth: 2.5, x: \"i\", y: \"value\" }),\n          dot(picked ? [picked] : [], {\n            fill: \"#ffffff\",\n            key: () => \"focus\",\n            r: 5,\n            stroke: BLUE,\n            strokeWidth: 2.5,\n            x: \"i\",\n            y: \"value\",\n          }),\n        ],\n        scales: {\n          x: { scale: scaleLinear().domain([0, LAST]) },\n          y: { scale: scaleLinear().domain([BOTTOM, TOP]) },\n        },\n      }),\n    [picked],\n  );\n\n  const left = ((picked?.i ?? 0) / LAST) * 100;\n  let align: \"center\" | \"left\" | \"right\" = \"center\";\n\n  if (left < 18) {\n    align = \"left\";\n  } else if (left > 82) {\n    align = \"right\";\n  }\n\n  return (\n    <Card className=\"bg-[linear-gradient(180deg,#a9c8fb_0%,#dce8fd_26%,#ffffff_48%)]\">\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"flex items-center gap-3\">\n          <span className=\"inline-flex size-10 items-center justify-center rounded-[12px] bg-[#8db8fb] shadow-[inset_0_1px_0_rgba(255,255,255,0.5)] ring-1 ring-white/60\">\n            <CreditCard className=\"size-5 text-white\" strokeWidth={2.4} />\n          </span>\n          <div>\n            <p className=\"text-[12px] text-[#5f6672]\">Spending</p>\n            <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Total Expenses</h3>\n          </div>\n        </div>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip chevron className=\"!border-white/80 !bg-white/50 backdrop-blur\">\n            Monthly\n          </Chip>\n          <MoreButton className=\"!rounded-[10px] !border-white/80 bg-white/40\" />\n        </div>\n      </div>\n\n      <div className=\"mt-4 flex items-end justify-between gap-2\">\n        <p className=\"flex items-start gap-1\">\n          <span className=\"mt-1 text-[18px] font-semibold\" style={{ color: MUTED }}>\n            $\n          </span>\n          <Num\n            value={320_418.16}\n            format={(n) => usd(n).slice(1)}\n            className=\"text-[34px] leading-none font-bold tracking-[-0.03em]\"\n          />\n        </p>\n        <p className=\"pb-0.5 text-[12px]\" style={{ color: MUTED }}>\n          <Delta value={1.16} variant=\"trend\" /> Today\n        </p>\n      </div>\n\n      <div className=\"mt-4 space-y-2.5\">\n        {CATEGORIES.map((c) => (\n          <div key={c.label} className=\"flex items-center text-[13px]\">\n            <span className=\"mr-2 h-1.5 w-3.5 rounded-full\" style={{ backgroundColor: c.color }} />\n            <span className=\"flex-1 text-[#3a3a42]\">{c.label}</span>\n            <Num value={c.amount} className=\"w-[78px] font-semibold\" />\n            <span className=\"w-[120px] text-right text-[11.5px]\" style={{ color: MUTED }}>\n              <Delta value={c.change} variant=\"trend\" /> this month\n            </span>\n          </div>\n        ))}\n      </div>\n\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Spending across the week\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(ROWS.findIndex((r) => r.i === p.xValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left}\n            top={((TOP - (picked?.value ?? 0)) / (TOP - BOTTOM)) * 100}\n            align={align}\n            dark\n            className=\"-translate-y-[calc(100%+12px)] font-semibold\"\n          >\n            <span className=\"opacity-60\">{dayFor(picked?.i ?? 0)}</span> {usd(picked?.value ?? 0)}\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div\n        className=\"mt-2 grid grid-cols-7 text-center text-[11px] tracking-wide\"\n        style={{ color: MUTED }}\n      >\n        {WEEKDAYS.map((d) => (\n          <span key={d} style={{ color: dayFor(picked?.i ?? 0) === d ? BLUE : undefined }}>\n            {d.toUpperCase()}\n          </span>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/total-expenses.tsx","target":"uicapsule/finance-charts/charts/total-expenses.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, defineChart, dot } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowUp, CalendarDays, Info } from \"lucide-react\";\nimport { useMemo } from \"react\";\n\nimport { rng } from \"../lib/data\";\nimport { Card, ChartSlot, Chip, MoreButton, Num, renderer, useCycle } from \"../lib/kit\";\nimport { GREEN, MUTED, THEME } from \"../lib/tokens\";\n\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\"] as const;\nconst REVENUE = [17.9, 13.3, 20.3, 14.7, 10, 15.7];\nconst CASH = [19_842.4, 15_210.92, 23_561.16, 16_904.7, 11_387.25, 18_115.3];\nconst MONTH_INDEX = new Map<string, number>(MONTHS.map((m, i) => [m, i]));\n\nconst HEIGHT = 230;\nconst TOP = 25;\nconst PAD = 0.14;\nconst LID = 2.25;\nconst LID_IN = 0.07;\n\ninterface Vertex {\n  month: string;\n  x: number;\n  lo: number;\n  hi: number;\n}\n\nconst SPARKS = (() => {\n  const r = rng(117);\n\n  return Array.from({ length: 14 }, (_, i) => ({\n    fx: 0.12 + r() * 0.76,\n    fy: 0.04 + r() * 0.9,\n    i,\n    o: 0.35 + r() * 0.6,\n    r: 0.6 + r() * 1.3,\n  }));\n})();\n\nexport const TotalRevenue = () => {\n  const [hi, pin] = useCycle(MONTHS.length, 2200, 2);\n  const picked = MONTHS[hi] ?? \"Mar\";\n\n  const definition = useMemo(() => {\n    const fronts: Vertex[] = [];\n    const lids: Vertex[] = [];\n\n    for (const [i, month] of MONTHS.entries()) {\n      const v = REVENUE[i] ?? 0;\n      const x1 = i + PAD;\n      const x2 = i + 1 - PAD;\n      fronts.push({ hi: v, lo: 0, month, x: x1 }, { hi: v, lo: 0, month, x: x2 });\n      lids.push(\n        { hi: v, lo: v, month, x: x1 },\n        { hi: v + LID, lo: v, month, x: x1 + LID_IN },\n        { hi: v + LID, lo: v, month, x: x2 - LID_IN },\n        { hi: v, lo: v, month, x: x2 },\n      );\n    }\n\n    const v = REVENUE[hi] ?? 0;\n\n    const sparks = SPARKS.map((s) => ({\n      ...s,\n      key: `${picked}-${s.i}`,\n      x: hi + PAD + s.fx * (1 - 2 * PAD),\n      y: s.fy * v,\n    }));\n\n    const paint = (on: string, off: string) => (d: Vertex) => (d.month === picked ? on : off);\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"tr-front\",\n          stops: [\n            { color: \"#f7f7f8\", offset: 0 },\n            { color: \"#ebebed\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"tr-lid\",\n          stops: [\n            { color: \"#f2f2f4\", offset: 0 },\n            { color: \"#e6e6e9\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"tr-hot\",\n          stops: [\n            { color: \"#e6f1fe\", offset: 0 },\n            { color: \"#8cc1fb\", offset: 0.45 },\n            { color: \"#0a7cff\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n        {\n          id: \"tr-hot-lid\",\n          stops: [\n            { color: \"#f4f9ff\", offset: 0 },\n            { color: \"#d4e7fd\", offset: 1 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      margin: { bottom: 26, left: 40, right: 0, top: 6 },\n      marks: [\n        areaY(fronts, {\n          fill: paint(\"url(#tr-hot)\", \"url(#tr-front)\"),\n          fillOpacity: 1,\n          stroke: paint(\"#a9cdf6\", \"#e4e4e7\"),\n          strokeWidth: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"month\",\n        }),\n        areaY(lids, {\n          fill: paint(\"url(#tr-hot-lid)\", \"url(#tr-lid)\"),\n          fillOpacity: 1,\n          stroke: paint(\"#a9cdf6\", \"#e4e4e7\"),\n          strokeWidth: 1,\n          x: \"x\",\n          y1: \"lo\",\n          y2: \"hi\",\n          z: \"month\",\n        }),\n        dot(sparks, {\n          fill: \"#ffffff\",\n          fillOpacity: 0.85,\n          key: \"key\",\n          r: \"r\",\n          x: \"x\",\n          y: \"y\",\n        }),\n      ],\n      scales: {\n        x: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (n: number) => MONTHS[Math.floor(n)] ?? \"\",\n              size: 0,\n              values: MONTHS.map((_, i) => i + 0.5),\n            },\n          },\n          scale: scaleLinear().domain([0, MONTHS.length]),\n        },\n        y: {\n          axis: {\n            line: false,\n            tickLabels: { fontSize: 12 },\n            ticks: {\n              format: (n: number) => (n === 0 ? \"$0\" : `$${n}M`),\n              size: 0,\n              values: [0, 5, 10, 15, 20, 25],\n            },\n          },\n          grid: { stroke: \"#e2e2e6\", strokeDasharray: \"5 5\", strokeWidth: 1 },\n          scale: scaleLinear().domain([0, TOP]),\n        },\n      },\n      theme: { ...THEME, muted: \"#a1a1aa\" },\n    });\n  }, [hi, picked]);\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Total Revenue</h3>\n        <div className=\"flex items-center gap-1.5\">\n          <Chip icon={CalendarDays} chevron>\n            6 months\n          </Chip>\n          <MoreButton />\n        </div>\n      </div>\n      <p className=\"mt-3 text-[13px]\" style={{ color: MUTED }}>\n        Monthly net cash flow\n      </p>\n      <Num value={CASH[hi] ?? 0} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n      <p className=\"mt-1 flex items-center gap-2 text-[12px]\" style={{ color: MUTED }}>\n        <span\n          className=\"inline-flex items-center gap-1 rounded-full bg-[#dcfce7] px-2 py-0.5 font-semibold\"\n          style={{ color: GREEN }}\n        >\n          <span\n            className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n            style={{ backgroundColor: GREEN }}\n          >\n            <ArrowUp className=\"size-2\" strokeWidth={3.5} />\n          </span>\n          $163,747\n        </span>\n        vs last month\n      </p>\n      <ChartSlot height={HEIGHT} className=\"mt-3\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Total revenue by month for the last six months\"\n            onFocusChange={(p) => {\n              const month = p?.datum && \"month\" in p.datum ? p.datum.month : null;\n              const i = month === null ? -1 : (MONTH_INDEX.get(month) ?? -1);\n\n              if (i !== -1) {\n                pin(i);\n              }\n            }}\n          />\n        </div>\n      </ChartSlot>\n      <p className=\"mt-3 flex items-center gap-1.5 text-[12px] text-[#55555e]\">\n        <Info className=\"size-3.5 shrink-0\" style={{ color: MUTED }} />\n        Total revenue and monthly net cash flow for the last 6 months.\n      </p>\n    </Card>\n  );\n};\n","path":"/charts/total-revenue.tsx","target":"uicapsule/finance-charts/charts/total-revenue.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { Info } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\n\nimport { Delta, Num } from \"../lib/kit\";\nimport { FAINT, GRID, MUTED } from \"../lib/tokens\";\n\nexport const HOURS = [18, 20, 22, 24, 26] as const;\nexport const X_DOMAIN = [17.35, 26.6] as const;\n\nexport const hourLabel = (h: number) => {\n  const hour = Math.round(h) % 24;\n  const twelve = hour % 12 === 0 ? 12 : hour % 12;\n\n  return `${twelve} ${hour >= 12 ? \"PM\" : \"AM\"}`;\n};\n\n/** Precise clock label for fractional hours, e.g. 20.5 → 8:30 PM. */\nexport const clockLabel = (h: number) => {\n  const minutes = Math.round((h % 1) * 60);\n  const hour = Math.floor(h) % 24;\n  const twelve = hour % 12 === 0 ? 12 : hour % 12;\n\n  return `${twelve}:${String(minutes).padStart(2, \"0\")} ${hour >= 12 ? \"PM\" : \"AM\"}`;\n};\n\n/** Linear interpolation of a polyline at `x`. */\nexport const valueAt = (points: readonly (readonly [number, number])[], x: number) => {\n  for (let k = 1; k < points.length; k += 1) {\n    const a = points[k - 1];\n    const b = points[k];\n\n    if (a && b && x <= b[0]) {\n      const t = (x - a[0]) / (b[0] - a[0] || 1);\n\n      return a[1] + (b[1] - a[1]) * Math.max(0, Math.min(1, t));\n    }\n  }\n\n  return points.at(-1)?.[1] ?? 0;\n};\n\n/** Axes for the hourly plot: dashed hour verticals, solid value rules. */\nexport const hourlyAxes = (ticks: readonly number[], format: (v: number) => string) => ({\n  x: {\n    axis: {\n      line: false,\n      tickLabels: { fontSize: 11.5 },\n      ticks: { format: hourLabel, size: 0, values: [...HOURS] },\n    },\n    grid: { stroke: FAINT, strokeDasharray: \"4 4\", strokeOpacity: 0.7 },\n  },\n  y: {\n    axis: {\n      line: false,\n      tickLabels: { fontSize: 11.5 },\n      ticks: { format, padding: 14, size: 0, values: [...ticks] },\n    },\n    grid: { stroke: GRID, strokeOpacity: 1 },\n  },\n});\n\nexport const SalesHeader = ({\n  label,\n  value,\n  format,\n  change,\n}: {\n  label: string;\n  value: number;\n  format: (n: number) => string;\n  change: number;\n}) => (\n  <div className=\"flex items-start justify-between gap-3\">\n    <div>\n      <p className=\"inline-flex items-center gap-1.5 text-[13px]\" style={{ color: MUTED }}>\n        {label} <Info className=\"size-3.5\" />\n      </p>\n      <div className=\"mt-1 flex items-center gap-2\">\n        <Num value={value} format={format} className=\"text-[28px] font-bold tracking-[-0.03em]\" />\n        <span className=\"rounded-full bg-[#dcfce7] px-2 py-0.5 text-[11px] font-medium text-[#16a34a]\">\n          +{change.toFixed(2)}%\n        </span>\n      </div>\n    </div>\n    <button\n      type=\"button\"\n      className=\"mt-1 h-9 shrink-0 rounded-full border border-black/[0.08] px-3.5 text-[12.5px] font-medium text-[#3a3a42] shadow-[0_1px_2px_rgba(0,0,0,0.04)]\"\n    >\n      View Report\n    </button>\n  </div>\n);\n\nexport const ChannelRows = ({\n  rows,\n  format,\n}: {\n  rows: readonly { name: string; value: number; change: number }[];\n  format: (n: number) => string;\n}) => (\n  <div className=\"mt-4 space-y-3\">\n    {rows.map((r) => (\n      <div key={r.name} className=\"flex items-center text-[13px]\">\n        <span className=\"flex-1 font-medium\">{r.name}</span>\n        <Num\n          value={r.value}\n          format={format}\n          className=\"w-[86px] font-semibold\"\n          style={{ color: \"#55555e\" }}\n        />\n        <span className=\"w-[72px] text-right text-[12.5px]\">\n          <Delta value={r.change} variant=\"circle\" />\n        </span>\n      </div>\n    ))}\n  </div>\n);\n\nexport const SquareLegend = ({ items }: { items: readonly { label: string; color: string }[] }) => (\n  <div\n    className=\"mt-2 flex items-center justify-center gap-5 text-[12.5px]\"\n    style={{ color: \"#55555e\" }}\n  >\n    {items.map((it) => (\n      <span key={it.label} className=\"inline-flex items-center gap-1.5\">\n        <span\n          className=\"size-3.5 rounded-[4px] ring-1 ring-black/10\"\n          style={{ backgroundColor: it.color }}\n        />\n        {it.label}\n      </span>\n    ))}\n  </div>\n);\n\nexport const Readout = ({ children }: { children: ReactNode }) => (\n  <span className=\"flex items-center gap-1.5 whitespace-nowrap\">{children}</span>\n);\n","path":"/charts/total-sales-parts.tsx","target":"uicapsule/finance-charts/charts/total-sales-parts.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { defineChart, dot, lineY, ruleX } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\n\nimport { compact, usd } from \"../lib/data\";\nimport { Bubble, Card, ChartSlot, PlotOverlay, renderer, useCycle } from \"../lib/kit\";\nimport { BLUE } from \"../lib/tokens\";\nimport {\n  ChannelRows,\n  SalesHeader,\n  SquareLegend,\n  X_DOMAIN,\n  clockLabel,\n  hourlyAxes,\n  valueAt,\n} from \"./total-sales-parts\";\n\nconst TODAY = [\n  [18, 0],\n  [19.76, 0],\n  [20.54, 21_400],\n  [21.17, 0],\n  [22.13, 0],\n  [22.5, 8100],\n  [22.9, 0],\n  [24.78, 0],\n  [26, 17_800],\n] as const;\n\nconst YESTERDAY = [\n  [18, 0],\n  [18.69, 7000],\n  [19.38, 0],\n  [20.57, 0],\n  [20.9, 4500],\n  [21.78, 6000],\n  [22.13, 12_700],\n  [22.7, 0],\n  [26, 0],\n] as const;\n\nconst toRows = (pts: readonly (readonly [number, number])[]) =>\n  pts.map(([h, value]) => ({ h, value }));\n\nconst TODAY_ROWS = toRows(TODAY);\nconst YESTERDAY_ROWS = toRows(YESTERDAY);\n\nconst STOPS = [20.54, 21.6, 22.5, 23.8, 26, 18.9] as const;\nconst TICKS = [0, 10_000, 20_000, 30_000] as const;\nconst MAX = 30_000;\n\nconst CHANNELS = [\n  { change: 4.82, name: \"Online store\", value: 4250 },\n  { change: 2.64, name: \"Facebook\", value: 846.85 },\n  { change: -1.64, name: \"Offline store\", value: 2753.04 },\n] as const;\n\nconst MARGIN = { bottom: 28, left: 44, right: 4, top: 10 };\nconst HEIGHT = 210;\nconst YESTERDAY_GREY = \"#e4e4e7\";\n\nexport const TotalSales = () => {\n  const [stop, pin] = useCycle(STOPS.length, 1900);\n  const h = STOPS[stop] ?? 20.54;\n  const value = valueAt(TODAY, h);\n  const before = valueAt(YESTERDAY, h);\n\n  const definition = useMemo(() => {\n    const axes = hourlyAxes(TICKS, (v) => compact(v));\n\n    return defineChart({\n      margin: MARGIN,\n      marks: [\n        ruleX([h], { stroke: BLUE, strokeDasharray: \"3 3\", strokeOpacity: 0.5 }),\n        lineY(YESTERDAY_ROWS, { stroke: YESTERDAY_GREY, strokeWidth: 2, x: \"h\", y: \"value\" }),\n        lineY(TODAY_ROWS, {\n          id: \"glow\",\n          stroke: BLUE,\n          strokeOpacity: 0.1,\n          strokeWidth: 8,\n          x: \"h\",\n          y: \"value\",\n        }),\n        lineY(TODAY_ROWS, { stroke: BLUE, strokeWidth: 2.5, x: \"h\", y: \"value\" }),\n        dot([{ h, value }], {\n          fill: \"#ffffff\",\n          key: () => \"focus\",\n          r: 4.5,\n          stroke: BLUE,\n          strokeWidth: 2.5,\n          x: \"h\",\n          y: \"value\",\n        }),\n      ],\n      scales: {\n        x: { ...axes.x, scale: scaleLinear().domain([...X_DOMAIN]) },\n        y: { ...axes.y, scale: scaleLinear().domain([0, MAX]) },\n      },\n      theme: { muted: \"#a1a1aa\" },\n    });\n  }, [h, value]);\n\n  const left = ((h - X_DOMAIN[0]) / (X_DOMAIN[1] - X_DOMAIN[0])) * 100;\n  let align: \"center\" | \"left\" | \"right\" = \"center\";\n\n  if (left < 22) {\n    align = \"left\";\n  } else if (left > 75) {\n    align = \"right\";\n  }\n\n  return (\n    <Card>\n      <SalesHeader label=\"Total Sales\" value={18_645.16} format={(n) => usd(n)} change={1.16} />\n      <ChannelRows rows={CHANNELS} format={(n) => usd(n)} />\n      <ChartSlot height={HEIGHT} className=\"mt-5\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Sales by hour, today against yesterday\"\n            onFocusChange={(p) => {\n              if (p) {\n                const x = Number(p.xValue);\n                let best = 0;\n\n                for (const [k, s] of STOPS.entries()) {\n                  if (Math.abs(s - x) < Math.abs((STOPS[best] ?? 0) - x)) {\n                    best = k;\n                  }\n                }\n\n                pin(best);\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={left}\n            top={Math.min(62, 100 - (value / MAX) * 100)}\n            align={align}\n            dark\n            className=\"-translate-y-[calc(100%+12px)] text-[11px]\"\n          >\n            <p className=\"font-semibold\">{usd(value)}</p>\n            <p className=\"opacity-60\">\n              {clockLabel(h)} · {usd(before, true)} yday\n            </p>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <SquareLegend\n        items={[\n          { color: BLUE, label: \"Today\" },\n          { color: YESTERDAY_GREY, label: \"Yesterday\" },\n        ]}\n      />\n    </Card>\n  );\n};\n","path":"/charts/total-sales.tsx","target":"uicapsule/finance-charts/charts/total-sales.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { EyeOff, Wallet } from \"lucide-react\";\nimport { useMemo, useState } from \"react\";\n\nimport { usd, WEEKDAYS } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Delta,\n  IconTile,\n  MoreButton,\n  Num,\n  PlotOverlay,\n  Segmented,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { GRID, MUTED, ORANGE, THEME } from \"../lib/tokens\";\n\nconst RANGES = [\n  [2860, 3410, 2480, 4200.91, 2870, 3420, 2350],\n  [3120, 2940, 3880, 3310, 4020.44, 2760, 3050],\n  [3650, 4105.2, 3200, 2980, 3340, 3900, 2710],\n] as const;\n\nconst MARGIN = { bottom: 28, left: 0, right: 0, top: 36 };\nconst HEIGHT = 220;\nconst TOP = 4800;\n\nexport const TotalValue = () => {\n  const [range, setRange] = useState(0);\n  const values = RANGES[range] ?? RANGES[0];\n  const [hi, pin] = useCycle(WEEKDAYS.length, 2000, 3);\n  const rows = useMemo(() => WEEKDAYS.map((day, i) => ({ day, value: values[i] ?? 0 })), [values]);\n  const picked = rows[hi] ?? rows[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        gradients: [\n          {\n            id: \"tv-hot\",\n            stops: [\n              { color: \"#fb923c\", offset: 0 },\n              { color: \"#ea580c\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n          {\n            id: \"tv-cold\",\n            stops: [\n              { color: \"#f4f4f6\", offset: 0 },\n              { color: \"#ececef\", offset: 1 },\n            ],\n            y1: 0,\n            y2: 1,\n          },\n        ],\n        margin: MARGIN,\n        marks: [\n          barY(rows, {\n            fill: (d) => (d.day === picked?.day ? \"url(#tv-hot)\" : \"url(#tv-cold)\"),\n            key: \"day\",\n            radius: [16, 16, 0, 0],\n            x: \"day\",\n            y: \"value\",\n          }),\n          ruleY([picked?.value ?? 0], {\n            stroke: ORANGE,\n            strokeDasharray: \"4 4\",\n            strokeOpacity: 1,\n            strokeWidth: 1.5,\n          }),\n        ],\n        scales: {\n          x: {\n            axis: {\n              line: false,\n              tickLabels: {\n                fontSize: 13,\n                fontWeight: (c) => (c.value === picked?.day ? 600 : 400),\n              },\n              ticks: { size: 0 },\n            },\n            scale: scaleBand<string>()\n              .domain([...WEEKDAYS])\n              .paddingInner(0.22)\n              .paddingOuter(0),\n          },\n          y: { axis: false, scale: scaleLinear().domain([0, TOP]) },\n        },\n        theme: THEME,\n      }),\n    [rows, picked],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between\">\n        <p className=\"inline-flex items-center gap-1.5 text-[14px]\" style={{ color: MUTED }}>\n          Total value <EyeOff className=\"size-3.5\" />\n        </p>\n        <MoreButton />\n      </div>\n      <div className=\"mt-1 flex items-end gap-3\">\n        <Num value={320_418.16} className=\"text-[32px] font-bold tracking-[-0.03em]\" />\n        <div className=\"pb-1.5 text-[12px] leading-tight\">\n          <Delta value={-120.62} prefix=\"$\" suffix=\"\" />{\" \"}\n          <Delta value={-1.16} className=\"opacity-90\" />\n          <p style={{ color: MUTED }}>Today</p>\n        </div>\n      </div>\n      <Segmented\n        options={[\"Week\", \"Month\", \"Year\"]}\n        value={range}\n        onChange={setRange}\n        className=\"mt-4\"\n      />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Total value by weekday\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(rows.findIndex((r) => r.day === p.xValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            left={100}\n            top={100 - ((picked?.value ?? 0) / TOP) * 100}\n            align=\"right\"\n            className=\"flex -translate-y-1/2 gap-1.5 !rounded-full !bg-[#f97316] !px-2.5 !py-1 font-semibold !text-white\"\n          >\n            <span>{picked?.day}</span>\n            <span className=\"opacity-60\">|</span>\n            <span>{usd(picked?.value ?? 0)}</span>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-4 flex items-center gap-3 border-t pt-3\" style={{ borderColor: GRID }}>\n        <IconTile icon={Wallet} color=\"#3b82f6\" size={36} />\n        <div className=\"flex-1\">\n          <p className=\"text-[14px] font-semibold\">Main Pocket</p>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            Today\n          </p>\n        </div>\n        <div className=\"text-right\">\n          <p className=\"text-[14px] font-semibold tabular-nums\">$4,250.00</p>\n          <p className=\"text-[12px]\" style={{ color: MUTED }}>\n            <Delta value={12} suffix=\"%\" className=\"text-[12px]\" /> this month\n          </p>\n        </div>\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/total-value.tsx","target":"uicapsule/finance-charts/charts/total-value.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { areaY, barY, defineChart, dot, lineY, ruleX } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport { walk } from \"../lib/data\";\nimport {\n  Card,\n  ChartSlot,\n  Delta,\n  MoreButton,\n  Num,\n  Segmented,\n  muted,\n  renderer,\n  useCycle,\n} from \"../lib/kit\";\nimport { BLUE, GREEN } from \"../lib/tokens\";\n\nconst POINTS = 9;\nconst LAST = POINTS - 1;\nconst TOP = 100;\nconst COLS = 40;\nconst ROW_STEP = 4.2;\nconst HEIGHT = 210;\nconst MINI_HEIGHT = 64;\n\ninterface Range {\n  line: number[];\n  inflow: number;\n  outflow: number;\n  bars: number[];\n  tx: number;\n}\n\nconst WEEK: Range = {\n  bars: [4, 7, 6, 2, 4, 3, 6],\n  inflow: 526.2,\n  line: [40, 47, 54, 46, 52, 48, 52, 75, 82],\n  outflow: 264.8,\n  tx: 26.8,\n};\n\nconst RANGES: Range[] = [\n  WEEK,\n  {\n    bars: [3, 5, 7, 6, 3, 5, 4],\n    inflow: 1984.6,\n    line: walk(POINTS, 41, { drift: 4, max: 88, min: 30, start: 36, vol: 9 }),\n    outflow: 1120.4,\n    tx: 104.2,\n  },\n  {\n    bars: [2, 3, 4, 4, 5, 6, 7],\n    inflow: 6120.9,\n    line: walk(POINTS, 77, { drift: 5, max: 90, min: 22, start: 28, vol: 7 }),\n    outflow: 3410.3,\n    tx: 391.5,\n  },\n];\n\nconst SHADES = [\"#7fb5f2\", \"#a3caf6\", \"#c2dcf9\", \"#dbeafc\"] as const;\n\nconst sample = (line: readonly number[], x: number) => {\n  const i = Math.min(LAST - 1, Math.floor(x));\n  const t = x - i;\n\n  return (line[i] ?? 0) * (1 - t) + (line[i + 1] ?? 0) * t;\n};\n\nconst dotGrid = (line: readonly number[]) => {\n  const bands: { id: string; x: number; y: number }[][] = [[], [], [], []];\n\n  for (let c = 0; c < COLS; c += 1) {\n    const x = (c / (COLS - 1)) * LAST;\n    const ceiling = sample(line, x) - ROW_STEP * 0.8;\n\n    for (let y = ROW_STEP * 0.5; y < ceiling; y += ROW_STEP) {\n      const band = Math.min(3, Math.floor((y / TOP) * 4));\n      bands[band]?.push({ id: `${c}-${Math.round(y * 10)}`, x, y });\n    }\n  }\n\n  return bands;\n};\n\nconst BAND_OPACITY = [0.14, 0.28, 0.48, 0.72] as const;\n\nconst Corners = () => (\n  <>\n    <span className=\"absolute top-0 left-0 size-2.5 border-t border-l border-[#c4c4cb]\" />\n    <span className=\"absolute top-0 right-0 size-2.5 border-t border-r border-[#c4c4cb]\" />\n    <span className=\"absolute bottom-0 left-0 size-2.5 border-b border-l border-[#c4c4cb]\" />\n    <span className=\"absolute right-0 bottom-0 size-2.5 border-r border-b border-[#c4c4cb]\" />\n  </>\n);\n\nconst Panel = ({ children, className }: { children: ReactNode; className?: string }) => (\n  <div className={`relative bg-white p-4 ${className ?? \"\"}`}>\n    <Corners />\n    {children}\n  </div>\n);\n\nconst UpPill = ({ value }: { value: number }) => (\n  <span className=\"inline-flex items-center rounded-full bg-[#dcfce7] px-2 py-0.5 text-[12px]\">\n    <Delta value={value} variant=\"circle\" />\n  </span>\n);\n\nconst millions = (n: number) =>\n  `$${n.toLocaleString(\"en-US\", { maximumFractionDigits: 1, minimumFractionDigits: 1 })}M`;\n\nexport const ValueLocked = () => {\n  const [range, pinRange] = useCycle(RANGES.length, 6400);\n  const [hi, pin] = useCycle(POINTS, 1100, 4);\n  const data = RANGES[range] ?? WEEK;\n  const { line, bars, inflow, outflow } = data;\n\n  const definition = useMemo(() => {\n    const rows = line.map((value, x) => ({ value, x }));\n    const bands = dotGrid(line);\n    const picked = rows[hi] ?? rows[0];\n\n    return defineChart({\n      gradients: [\n        {\n          id: \"vl-wash\",\n          stops: [\n            { color: BLUE, offset: 0, opacity: 0.08 },\n            { color: BLUE, offset: 1, opacity: 0 },\n          ],\n          y1: 0,\n          y2: 1,\n        },\n      ],\n      guides: false,\n      margin: { bottom: 0, left: 1, right: 1, top: 8 },\n      marks: [\n        areaY(rows, { fill: \"url(#vl-wash)\", fillOpacity: 1, key: \"x\", x: \"x\", y: \"value\" }),\n        ...bands.map((band, i) =>\n          dot(band, {\n            fill: BLUE,\n            fillOpacity: BAND_OPACITY[i],\n            id: `dots-${i}`,\n            key: \"id\",\n            r: 1.1,\n            x: \"x\",\n            y: \"y\",\n          }),\n        ),\n        ruleX([picked?.x ?? 0], { stroke: BLUE, strokeOpacity: 0.7, strokeWidth: 1.5 }),\n        lineY(rows, { key: \"x\", stroke: BLUE, strokeWidth: 2.25, x: \"x\", y: \"value\" }),\n        dot([picked], {\n          fill: \"#ffffff\",\n          id: \"marker\",\n          key: () => \"marker\",\n          r: 4,\n          stroke: BLUE,\n          strokeWidth: 1.75,\n          x: (d) => d?.x ?? 0,\n          y: (d) => d?.value ?? 0,\n        }),\n      ],\n      scales: {\n        x: { axis: false, scale: scaleLinear().domain([0, LAST]) },\n        y: { axis: false, scale: scaleLinear().domain([0, TOP]) },\n      },\n    });\n  }, [line, hi]);\n\n  const mini = useMemo(() => {\n    const segments = bars.flatMap((count, col) =>\n      Array.from({ length: count }, (_, k) => ({\n        col,\n        id: `${col}-${k}`,\n        level: count - 1 - k,\n        y1: k,\n        y2: k + 0.62,\n      })),\n    );\n\n    return defineChart({\n      guides: false,\n      margin: 0,\n      marks: [\n        barY(segments, {\n          fill: (d) => SHADES[Math.min(3, d.level)] ?? SHADES[3],\n          key: \"id\",\n          radius: 2,\n          x: \"col\",\n          y1: \"y1\",\n          y2: \"y2\",\n        }),\n      ],\n      scales: {\n        x: {\n          axis: false,\n          scale: scaleBand<number>()\n            .domain(bars.map((_, i) => i))\n            .paddingInner(0.18)\n            .paddingOuter(0),\n        },\n        y: { axis: false, scale: scaleLinear().domain([0, 7]) },\n      },\n    });\n  }, [bars]);\n\n  return (\n    <Card className=\"!bg-[#f6f6f7] !p-2\">\n      <Panel className=\"px-4 pt-5 pb-5\">\n        <div className=\"flex items-start justify-between\">\n          <h3 className=\"text-[16px] font-semibold tracking-[-0.01em]\">Value Locked</h3>\n          <MoreButton className=\"!rounded-none\" />\n        </div>\n        <p className=\"mt-3 text-[13px]\" style={muted}>\n          Total value locked\n        </p>\n        <div className=\"mt-1 flex items-center gap-2.5\">\n          <Num\n            value={23.56}\n            format={(n) => `$${n.toFixed(2)}B`}\n            className=\"text-[30px] font-semibold tracking-[-0.03em]\"\n          />\n          <UpPill value={8.34} />\n          <span className=\"text-[12px]\" style={muted}>\n            vs last month\n          </span>\n        </div>\n        <Segmented\n          options={[\"Week\", \"Month\", \"Year\"]}\n          value={range}\n          onChange={pinRange}\n          className=\"mt-4 !rounded-none [&_button]:!rounded-none [&_span]:!rounded-none\"\n        />\n        <ChartSlot height={HEIGHT} className=\"mt-3\">\n          <div onMouseLeave={() => pin(null)}>\n            <Chart\n              definition={definition}\n              renderer={renderer}\n              height={HEIGHT}\n              ariaLabel=\"Total value locked over the selected range\"\n              onFocusChange={(p) => {\n                if (p) {\n                  const i = line.findIndex((_, x) => x === p.xValue);\n\n                  if (i !== -1) {\n                    pin(i);\n                  }\n                }\n              }}\n            />\n          </div>\n        </ChartSlot>\n        <div className=\"mt-4 grid grid-cols-3 gap-2\">\n          <div>\n            <p className=\"text-[12px]\" style={muted}>\n              Inflow\n            </p>\n            <Num value={inflow} format={millions} className=\"text-[18px] font-semibold\" />\n          </div>\n          <div>\n            <p className=\"text-[12px]\" style={muted}>\n              Outflow\n            </p>\n            <Num value={outflow} format={millions} className=\"text-[18px] font-semibold\" />\n          </div>\n          <div>\n            <p className=\"text-[12px]\" style={muted}>\n              Net flow\n            </p>\n            <Num\n              value={inflow - outflow}\n              format={(n) => `+${millions(n)}`}\n              className=\"text-[18px] font-semibold\"\n              style={{ color: GREEN }}\n            />\n          </div>\n        </div>\n      </Panel>\n      <Panel className=\"mt-2 flex items-end justify-between gap-3 px-4 py-4\">\n        <div className=\"shrink-0\">\n          <p className=\"text-[13px]\" style={muted}>\n            Transactions\n          </p>\n          <div className=\"mt-1 flex items-center gap-2\">\n            <Num\n              value={data.tx}\n              format={(n) => `+${n.toFixed(1)}M`}\n              className=\"text-[26px] font-semibold tracking-[-0.03em]\"\n            />\n            <UpPill value={8.34} />\n          </div>\n        </div>\n        <ChartSlot height={MINI_HEIGHT} className=\"w-full max-w-[120px] flex-1\">\n          <Chart\n            definition={mini}\n            renderer={renderer}\n            height={MINI_HEIGHT}\n            ariaLabel=\"Transactions by day\"\n          />\n        </ChartSlot>\n      </Panel>\n    </Card>\n  );\n};\n","path":"/charts/value-locked.tsx","target":"uicapsule/finance-charts/charts/value-locked.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { barY, defineChart, dot, ruleY } from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react/core\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { ArrowDown, ArrowUp, Bitcoin, RefreshCw } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport { compact } from \"../lib/data\";\nimport {\n  Bubble,\n  Card,\n  ChartSlot,\n  Num,\n  PlotOverlay,\n  renderer,\n  useActive,\n  useCycle,\n} from \"../lib/kit\";\nimport { GREEN, MUTED, ORANGE, RED, SPRING, THEME } from \"../lib/tokens\";\n\ninterface Coin {\n  id: string;\n  color: string;\n  glyph: ReactNode;\n  value: number;\n}\n\nconst COINS: Coin[] = [\n  {\n    color: \"#f7931a\",\n    glyph: <Bitcoin className=\"size-3.5\" strokeWidth={2.6} />,\n    id: \"BTC\",\n    value: 8.1,\n  },\n  { color: \"#627eea\", glyph: \"Ξ\", id: \"ETH\", value: 6.9 },\n  { color: \"#0d1e30\", glyph: \"₳\", id: \"ADA\", value: 9 },\n  { color: \"#26a17b\", glyph: \"₮\", id: \"USDT\", value: 5.7 },\n  { color: \"#2775ca\", glyph: \"$\", id: \"USDC\", value: 13.4 },\n  { color: \"#f3ba2f\", glyph: \"◆\", id: \"BNB\", value: 10.6 },\n  { color: \"#eb0029\", glyph: \"▽\", id: \"TRX\", value: 15.4 },\n  { color: \"#e6007a\", glyph: \"P\", id: \"DOT\", value: 5.7 },\n];\n\nconst TICKER = [\n  { change: 13, price: \"$1,249.00\", sym: \"ETH\" },\n  { change: 10, price: \"$1,985.00\", sym: \"BNB\" },\n  { change: -0.9, price: \"$0.9720\", sym: \"USDT\" },\n  { change: 4.2, price: \"$0.1040\", sym: \"XRP\" },\n  { change: -2.4, price: \"$0.3810\", sym: \"ADA\" },\n  { change: 6.1, price: \"$64,210.00\", sym: \"BTC\" },\n] as const;\n\nconst HOLDINGS = [\n  { amount: \"0.00836 BTC\", coin: COINS[0], name: \"Bitcoin\", sym: \"BTC\" },\n  { amount: \"2.7368 USDT\", coin: COINS[3], name: \"Tether\", sym: \"USDT\" },\n  { amount: \"6.8375 ETH\", coin: COINS[1], name: \"Ethereum\", sym: \"ETH\" },\n] as const;\n\nconst MARGIN = { bottom: 2, left: 40, right: 0, top: 14 };\nconst HEIGHT = 200;\nconst TOP = 20_000_000;\nconst BAR = \"#fdd9bf\";\n\nconst CoinBadge = ({ coin, size = 24 }: { coin: Coin | undefined; size?: number }) => (\n  <span\n    className=\"inline-flex shrink-0 items-center justify-center rounded-full text-[12px] font-bold text-white\"\n    style={{ backgroundColor: coin?.color, height: size, width: size }}\n  >\n    {coin?.glyph}\n  </span>\n);\n\nconst Ticker = () => {\n  const active = useActive();\n  const items = [...TICKER, ...TICKER];\n\n  return (\n    <div className=\"relative -mx-5 mt-3 overflow-hidden border-b border-black/[0.06] pb-3 [mask-image:linear-gradient(90deg,transparent,black_8%,black_92%,transparent)]\">\n      <motion.div\n        className=\"flex w-max gap-2 pl-5\"\n        animate={active ? { x: [\"0%\", \"-50%\"] } : undefined}\n        transition={{ duration: 22, ease: \"linear\", repeat: Infinity }}\n      >\n        {items.map((t, i) => {\n          const up = t.change >= 0;\n          const Arrow = up ? ArrowUp : ArrowDown;\n\n          return (\n            <span\n              key={`${t.sym}-${i}`}\n              className=\"inline-flex h-7 shrink-0 items-center gap-1 rounded-full border border-black/[0.08] bg-white px-2.5 text-[11px] tabular-nums\"\n            >\n              <span className=\"font-medium text-[#3a3a42]\">{t.sym}:</span>\n              <span style={{ color: MUTED }}>{t.price}</span>\n              <span\n                className=\"inline-flex items-center font-medium\"\n                style={{ color: up ? GREEN : RED }}\n              >\n                <Arrow className=\"size-3\" strokeWidth={3} />({up ? \"+\" : \"\"}\n                {t.change}%)\n              </span>\n            </span>\n          );\n        })}\n      </motion.div>\n    </div>\n  );\n};\n\nconst Flow = ({ label, value, change }: { label: string; value: number; change: number }) => {\n  const up = change >= 0;\n  const Arrow = up ? ArrowUp : ArrowDown;\n\n  return (\n    <div className=\"rounded-2xl bg-[#f6f6f7] p-3.5\">\n      <p className=\"text-[12px]\" style={{ color: MUTED }}>\n        {label}\n      </p>\n      <Num value={value} className=\"mt-1 block text-[19px] font-bold tracking-[-0.03em]\" />\n      <p className=\"mt-2 flex flex-wrap items-center gap-1.5 text-[11px]\" style={{ color: MUTED }}>\n        <span\n          className=\"inline-flex items-center gap-1 rounded-full px-1.5 py-0.5 font-semibold\"\n          style={{ backgroundColor: up ? \"#dcfce7\" : \"#fee2e2\", color: up ? GREEN : RED }}\n        >\n          <span\n            className=\"inline-flex size-3 items-center justify-center rounded-full text-white\"\n            style={{ backgroundColor: up ? GREEN : RED }}\n          >\n            <Arrow className=\"size-2\" strokeWidth={3.5} />\n          </span>\n          {Math.abs(change).toFixed(2)}%\n        </span>\n        vs last month\n      </p>\n    </div>\n  );\n};\n\nexport const YourAsset = () => {\n  const [hi, pin] = useCycle(COINS.length, 1900, 4);\n  const [lap] = useCycle(1000, 1900 * COINS.length, 0);\n\n  const rows = useMemo(\n    () =>\n      COINS.map((c, i) => ({\n        id: c.id,\n        value: c.value * 1_000_000 * (1 + 0.09 * Math.sin(lap * 1.7 + i * 2.3)),\n      })),\n    [lap],\n  );\n\n  const picked = rows[hi] ?? rows[0];\n\n  const definition = useMemo(\n    () =>\n      defineChart({\n        focusRing: false,\n        margin: MARGIN,\n        marks: [\n          barY(rows, {\n            fill: (d) => (d.id === picked?.id ? \"#fcc59c\" : BAR),\n            key: \"id\",\n            radius: 8,\n            stroke: \"#f7bf96\",\n            strokeWidth: 1,\n            x: \"id\",\n            y1: 0,\n            y2: \"value\",\n          }),\n          ruleY([0], { stroke: \"#d9d9de\", strokeOpacity: 1, strokeWidth: 1 }),\n          dot(rows, {\n            fill: ORANGE,\n            key: \"id\",\n            r: 6.5,\n            stroke: \"#ffffff\",\n            strokeWidth: 2,\n            x: \"id\",\n            y: \"value\",\n          }),\n        ],\n        scales: {\n          x: {\n            axis: false,\n            scale: scaleBand<string>()\n              .domain(COINS.map((c) => c.id))\n              .paddingInner(0.76)\n              .paddingOuter(0.38),\n          },\n          y: {\n            axis: {\n              line: false,\n              tickLabels: { fontSize: 11 },\n              ticks: {\n                format: (v) => compact(v),\n                size: 0,\n                values: [0, 5_000_000, 10_000_000, 15_000_000, 20_000_000],\n              },\n            },\n            grid: { stroke: \"#e2e2e7\", strokeDasharray: \"4 4\", strokeOpacity: 1, strokeWidth: 1 },\n            scale: scaleLinear().domain([0, TOP]),\n          },\n        },\n        theme: THEME,\n      }),\n    [rows, picked],\n  );\n\n  return (\n    <Card>\n      <div className=\"flex items-start justify-between gap-2\">\n        <div className=\"min-w-0\">\n          <h3 className=\"text-[17px] font-semibold tracking-[-0.01em]\">Your Asset</h3>\n          <p className=\"mt-0.5 truncate text-[12px]\" style={{ color: MUTED }}>\n            Live asset performance tracking\n          </p>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-1.5\">\n          <span className=\"text-[11px]\" style={{ color: MUTED }}>\n            Updating in 5 min\n          </span>\n          <span className=\"inline-flex size-8 items-center justify-center rounded-full border border-black/[0.08] text-[#8a8a93]\">\n            <motion.span\n              animate={{ rotate: lap * 360 }}\n              transition={SPRING}\n              className=\"inline-flex\"\n            >\n              <RefreshCw className=\"size-3.5\" />\n            </motion.span>\n          </span>\n        </div>\n      </div>\n      <Ticker />\n      <ChartSlot height={HEIGHT} className=\"mt-4\">\n        <div onMouseLeave={() => pin(null)}>\n          <Chart\n            definition={definition}\n            renderer={renderer}\n            height={HEIGHT}\n            ariaLabel=\"Holdings value by asset\"\n            onFocusChange={(p) => {\n              if (p) {\n                pin(COINS.findIndex((c) => c.id === p.xValue));\n              }\n            }}\n          />\n        </div>\n        <PlotOverlay margin={MARGIN}>\n          <Bubble\n            dark\n            left={((hi + 0.5) / COINS.length) * 100}\n            top={100 - ((picked?.value ?? 0) / TOP) * 100}\n            className=\"-translate-y-[calc(100%+12px)] text-center leading-tight\"\n          >\n            <span className=\"block text-[10px] text-white/60\">{picked?.id}</span>\n            <span className=\"font-semibold\">{compact(picked?.value ?? 0)}</span>\n          </Bubble>\n        </PlotOverlay>\n      </ChartSlot>\n      <div className=\"mt-2.5 flex\" style={{ paddingLeft: MARGIN.left }}>\n        {COINS.map((c, i) => (\n          <motion.span\n            key={c.id}\n            animate={{ scale: i === hi ? 1.15 : 1 }}\n            transition={SPRING}\n            className=\"flex flex-1 justify-center\"\n          >\n            <CoinBadge coin={c} size={22} />\n          </motion.span>\n        ))}\n      </div>\n      <div className=\"mt-5 grid grid-cols-2 gap-2.5\">\n        <Flow label=\"Deposit\" value={8937.08} change={4.52} />\n        <Flow label=\"Withdrawal\" value={3746.91} change={-0.64} />\n      </div>\n      <div className=\"mt-3 flex flex-col gap-2\">\n        {HOLDINGS.map((h) => (\n          <div\n            key={h.sym}\n            className=\"flex items-center gap-2.5 rounded-2xl bg-[#f6f6f7] px-3 py-2.5 ring-1 ring-black/[0.04]\"\n          >\n            <CoinBadge coin={h.coin} size={22} />\n            <span className=\"flex-1 text-[13px]\">\n              {h.name} <span style={{ color: MUTED }}>({h.sym})</span>\n            </span>\n            <span className=\"text-[13px] tabular-nums\">{h.amount}</span>\n          </div>\n        ))}\n      </div>\n    </Card>\n  );\n};\n","path":"/charts/your-asset.tsx","target":"uicapsule/finance-charts/charts/your-asset.tsx","type":"registry:file"},{"content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { CHARTS } from \"./charts\";\nimport { ChartCell } from \"./lib/kit\";\n\nconst DRIFT = 42;\nconst YIELD_MS = 3000;\n\n/**\n * Sixty-two dashboard cards in a masonry wall. Each card springs in and mounts\n * its chart only once it scrolls into view, so the wall reads as a stream of\n * entrances; the wall drifts on its own and yields to any hover or scroll.\n */\nexport const FinanceCharts = ({ autoScroll = true }: { autoScroll?: boolean }) => {\n  const scroller = useRef<HTMLDivElement>(null);\n  const hovered = useRef(false);\n  const holdUntil = useRef(0);\n\n  const release = () => {\n    holdUntil.current = Math.min(holdUntil.current, performance.now() + YIELD_MS);\n  };\n\n  useEffect(() => {\n    const el = scroller.current;\n\n    if (!el || !autoScroll || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      return;\n    }\n\n    let raf = 0;\n    let last = performance.now();\n    let yieldUntil = 0;\n    let y = el.scrollTop;\n    let written = el.scrollTop;\n\n    const step = (t: number) => {\n      const dt = Math.min(64, t - last);\n      last = t;\n\n      if (Math.abs(el.scrollTop - written) > 1) {\n        yieldUntil = t + YIELD_MS;\n      }\n\n      const end = el.scrollHeight - el.clientHeight;\n\n      if (hovered.current || t < holdUntil.current || t < yieldUntil || y >= end - 1) {\n        y = el.scrollTop;\n      } else {\n        y += (DRIFT * dt) / 1000;\n        el.scrollTop = y;\n      }\n\n      written = el.scrollTop;\n      raf = requestAnimationFrame(step);\n    };\n\n    raf = requestAnimationFrame(step);\n\n    return () => cancelAnimationFrame(raf);\n  }, [autoScroll]);\n\n  return (\n    <div\n      ref={scroller}\n      onPointerMove={(e) => {\n        if (e.pointerType === \"mouse\") {\n          hovered.current = true;\n        }\n      }}\n      onPointerLeave={() => {\n        hovered.current = false;\n        release();\n      }}\n      onPointerDown={() => {\n        holdUntil.current = Infinity;\n      }}\n      onPointerUp={release}\n      onPointerCancel={release}\n      className=\"size-full overflow-y-auto bg-[#f3f4f7] [font-family:Inter,ui-sans-serif,system-ui,sans-serif] [scrollbar-width:none]\"\n    >\n      <div className=\"mx-auto max-w-[1680px] columns-[340px] gap-4 px-4 py-6\">\n        {CHARTS.map(({ id, Chart }) => (\n          <ChartCell key={id} id={id}>\n            <Chart />\n          </ChartCell>\n        ))}\n      </div>\n    </div>\n  );\n};\n","path":"/finance-charts.tsx","target":"uicapsule/finance-charts/finance-charts.tsx","type":"registry:file"},{"content":"/* oxlint-disable no-bitwise -- mulberry32 needs unsigned 32-bit wraparound */\nexport const rng = (seed: number) => {\n  let a = seed >>> 0;\n\n  return () => {\n    a = (a + 0x6d_2b_79_f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n\n    return ((t ^ (t >>> 14)) >>> 0) / 4_294_967_296;\n  };\n};\n/* oxlint-enable no-bitwise */\n\n/** A bounded random walk: `n` points starting at `start`. */\nexport const walk = (\n  n: number,\n  seed: number,\n  { start = 50, vol = 5, drift = 0, min = -Infinity, max = Infinity } = {},\n) => {\n  const r = rng(seed);\n  const out: number[] = [];\n  let v = start;\n\n  for (let i = 0; i < n; i += 1) {\n    out.push(v);\n    v = Math.min(max, Math.max(min, v + drift + (r() - 0.5) * 2 * vol));\n  }\n\n  return out;\n};\n\n/** `n` uniform values in [lo, hi]. */\nexport const uniform = (n: number, seed: number, lo: number, hi: number) => {\n  const r = rng(seed);\n\n  return Array.from({ length: n }, () => lo + r() * (hi - lo));\n};\n\nexport const WEEKDAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"] as const;\n\nexport const MONTHS = [\n  \"Jan\",\n  \"Feb\",\n  \"Mar\",\n  \"Apr\",\n  \"May\",\n  \"Jun\",\n  \"Jul\",\n  \"Aug\",\n  \"Sep\",\n  \"Oct\",\n  \"Nov\",\n  \"Dec\",\n] as const;\n\nconst usdFormat = new Intl.NumberFormat(\"en-US\", {\n  currency: \"USD\",\n  maximumFractionDigits: 2,\n  minimumFractionDigits: 2,\n  style: \"currency\",\n});\n\nconst usdWhole = new Intl.NumberFormat(\"en-US\", {\n  currency: \"USD\",\n  maximumFractionDigits: 0,\n  style: \"currency\",\n});\n\n/** `$1,234.56`, or `$1,235` with `whole`. */\nexport const usd = (n: number, whole = false) => (whole ? usdWhole : usdFormat).format(n);\n\n/** `$25K`, `$1.2M` — axis labels. */\nexport const compact = (n: number, prefix = \"$\") => {\n  const abs = Math.abs(n);\n\n  if (abs >= 1_000_000) {\n    return `${prefix}${+(n / 1_000_000).toFixed(1)}M`;\n  }\n\n  if (abs >= 1000) {\n    return `${prefix}${+(n / 1000).toFixed(1)}K`;\n  }\n\n  return `${prefix}${Math.round(n)}`;\n};\n","path":"/lib/data.ts","target":"uicapsule/finance-charts/lib/data.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { motion as chartMotion } from \"@tanstack/charts/motion\";\nimport {\n  ArrowDown,\n  ArrowUp,\n  ChevronDown,\n  Ellipsis,\n  Info,\n  TrendingDown,\n  TrendingUp,\n} from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { animate, motion, useInView, useMotionValue, useMotionValueEvent } from \"motion/react\";\nimport { createContext, use, useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\n\nimport { usd } from \"./data\";\nimport { GREEN, INK, MUTED, RED, SPRING } from \"./tokens\";\n\n/** The one renderer every chart shares: keyed springs, entrance on mount. */\nexport const renderer = chartMotion({ initial: \"always\", transition: SPRING });\n\nconst cx = (...parts: (string | false | null | undefined)[]) => parts.filter(Boolean).join(\" \");\n\nconst ActiveContext = createContext(false);\n\n/** True once the surrounding card has scrolled into view. Charts mount then, so\n * every entrance plays where someone can see it. */\nexport const useActive = () => use(ActiveContext);\n\n/** Wraps one card in the wall and owns its in-view state. It sits ABOVE the\n * chart component, so hooks in a chart's own body (`useCycle`) see it too. */\nexport const ChartCell = ({ children, id }: { children: ReactNode; id: string }) => {\n  const ref = useRef<HTMLDivElement>(null);\n  const active = useInView(ref, { margin: \"0px 0px -12% 0px\", once: true });\n\n  return (\n    <div ref={ref} data-chart={id} className=\"break-inside-avoid\">\n      <ActiveContext value={active}>{children}</ActiveContext>\n    </div>\n  );\n};\n\nexport const Card = ({\n  children,\n  className,\n  style,\n}: {\n  children: ReactNode;\n  className?: string;\n  style?: CSSProperties;\n}) => {\n  const active = useActive();\n\n  return (\n    <motion.article\n      initial={{ opacity: 0, scale: 0.97, y: 28 }}\n      animate={active ? { opacity: 1, scale: 1, y: 0 } : undefined}\n      transition={SPRING}\n      className={cx(\n        \"relative mb-4 overflow-hidden rounded-[22px] bg-white p-5 text-[#0b0b0f] shadow-[0_1px_2px_rgba(16,16,24,0.04),0_8px_24px_-12px_rgba(16,16,24,0.12)] ring-1 ring-black/[0.04]\",\n        className,\n      )}\n      style={style}\n    >\n      {children}\n    </motion.article>\n  );\n};\n\n/** Holds a chart's height until its card is active, then mounts it. */\nexport const ChartSlot = ({\n  height,\n  children,\n  className,\n}: {\n  height: number;\n  children: ReactNode;\n  className?: string;\n}) => {\n  const active = useActive();\n\n  return (\n    <div className={cx(\"relative\", className)} style={{ height }}>\n      {active ? children : null}\n    </div>\n  );\n};\n\n/** An absolutely-positioned layer matching a chart's locked plot margins, so\n * HTML callouts can sit at percentages of the plot area. */\nexport const PlotOverlay = ({\n  margin,\n  children,\n}: {\n  margin: { top: number; right: number; bottom: number; left: number };\n  children: ReactNode;\n}) => (\n  <div\n    className=\"pointer-events-none absolute\"\n    style={{ bottom: margin.bottom, left: margin.left, right: margin.right, top: margin.top }}\n  >\n    {children}\n  </div>\n);\n\n/** Auto-advancing index while the card is visible. Hover (via `pin`) holds it. */\nexport const useCycle = (count: number, ms = 2200, start = 0) => {\n  const active = useActive();\n  const [index, setIndex] = useState(start);\n  const [held, setHeld] = useState(false);\n  useEffect(() => {\n    if (!active || held || count < 2) {\n      return;\n    }\n\n    const t = setInterval(() => setIndex((i) => (i + 1) % count), ms);\n\n    return () => clearInterval(t);\n  }, [active, held, count, ms]);\n\n  const pin = (i: number | null) => {\n    if (i === null) {\n      setHeld(false);\n\n      return;\n    }\n\n    if (!Number.isInteger(i) || i < 0 || i >= count) {\n      return;\n    }\n\n    setHeld(true);\n    setIndex(i);\n  };\n\n  return [index, pin] as const;\n};\n\nconst defaultFormat = (n: number) => usd(n);\n\nexport const Num = ({\n  value,\n  format = defaultFormat,\n  className,\n  style,\n}: {\n  value: number;\n  format?: (n: number) => string;\n  className?: string;\n  style?: CSSProperties;\n}) => {\n  const active = useActive();\n  const mv = useMotionValue(0);\n  const [text, setText] = useState(() => format(0));\n  useMotionValueEvent(mv, \"change\", (v) => setText(format(v)));\n  useEffect(() => {\n    if (!active) {\n      return;\n    }\n\n    const controls = animate(mv, value, { duration: 1.1, ease: [0.16, 1, 0.3, 1] });\n\n    return () => controls.stop();\n  }, [active, value, mv]);\n\n  return (\n    <span className={cx(\"tabular-nums\", className)} style={style}>\n      {text}\n    </span>\n  );\n};\n\n/** A signed change. `text`: colored inline; `pill`: tinted chip; `circle`:\n * arrow-in-a-dot then value; `trend`: trend arrow then value. */\nexport const Delta = ({\n  value,\n  suffix = \"%\",\n  prefix = \"\",\n  variant = \"text\",\n  className,\n  showSign = true,\n}: {\n  value: number;\n  suffix?: string;\n  prefix?: string;\n  variant?: \"text\" | \"pill\" | \"circle\" | \"trend\";\n  className?: string;\n  showSign?: boolean;\n}) => {\n  const up = value >= 0;\n  const color = up ? GREEN : RED;\n  let sign = \"\";\n\n  if (showSign) {\n    sign = up ? \"+\" : \"-\";\n  }\n\n  const body = `${sign}${prefix}${Math.abs(value).toLocaleString(\"en-US\", {\n    maximumFractionDigits: 2,\n    minimumFractionDigits: 2,\n  })}${suffix}`;\n\n  if (variant === \"pill\") {\n    return (\n      <span\n        className={cx(\n          \"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[12px] font-semibold tabular-nums\",\n          className,\n        )}\n        style={{ backgroundColor: up ? \"#dcfce7\" : \"#fee2e2\", color }}\n      >\n        {body}\n      </span>\n    );\n  }\n\n  if (variant === \"circle\" || variant === \"trend\") {\n    const icons: Record<\"circle\" | \"trend\", [LucideIcon, LucideIcon]> = {\n      circle: [ArrowUp, ArrowDown],\n      trend: [TrendingUp, TrendingDown],\n    };\n\n    const Icon = icons[variant][up ? 0 : 1];\n\n    return (\n      <span\n        className={cx(\"inline-flex items-center gap-1 font-semibold tabular-nums\", className)}\n        style={{ color }}\n      >\n        {variant === \"circle\" ? (\n          <span\n            className=\"inline-flex size-[1.05em] items-center justify-center rounded-full text-white\"\n            style={{ backgroundColor: color }}\n          >\n            <Icon className=\"size-[0.75em]\" strokeWidth={3} />\n          </span>\n        ) : (\n          <Icon className=\"size-[1em]\" strokeWidth={2.5} />\n        )}\n        {`${prefix}${Math.abs(value).toFixed(2)}${suffix}`}\n      </span>\n    );\n  }\n\n  return (\n    <span className={cx(\"font-semibold tabular-nums\", className)} style={{ color }}>\n      {body}\n    </span>\n  );\n};\n\n/** Rounded square holding a white glyph on a tinted gradient. */\nexport const IconTile = ({\n  icon: Icon,\n  color,\n  size = 32,\n  className,\n}: {\n  icon: LucideIcon;\n  color: string;\n  size?: number;\n  className?: string;\n}) => (\n  <span\n    className={cx(\"inline-flex shrink-0 items-center justify-center rounded-[10px]\", className)}\n    style={{\n      background: `linear-gradient(160deg, color-mix(in oklab, ${color} 70%, white), ${color})`,\n      boxShadow: `inset 0 1px 0 rgba(255,255,255,0.35), 0 4px 10px -4px ${color}`,\n      height: size,\n      width: size,\n    }}\n  >\n    <Icon\n      className=\"text-white\"\n      style={{ height: size * 0.5, width: size * 0.5 }}\n      strokeWidth={2.4}\n    />\n  </span>\n);\n\nexport const MoreButton = ({ className }: { className?: string }) => (\n  <button\n    type=\"button\"\n    aria-label=\"More\"\n    className={cx(\n      \"inline-flex size-8 shrink-0 items-center justify-center rounded-full border border-black/[0.08] text-[#8a8a93] transition-colors hover:bg-black/[0.03]\",\n      className,\n    )}\n  >\n    <Ellipsis className=\"size-4\" />\n  </button>\n);\n\n/** Outline chip: a select, a filter, a \"View data\" link. */\nexport const Chip = ({\n  children,\n  icon: Icon,\n  chevron,\n  className,\n  style,\n}: {\n  children: ReactNode;\n  icon?: LucideIcon;\n  chevron?: boolean;\n  className?: string;\n  style?: CSSProperties;\n}) => (\n  <span\n    className={cx(\n      \"inline-flex h-7 shrink-0 items-center gap-1.5 rounded-full border border-black/[0.08] bg-white px-2.5 text-[12px] font-medium text-[#3a3a42]\",\n      className,\n    )}\n    style={style}\n  >\n    {Icon ? <Icon className=\"size-3.5\" /> : null}\n    {children}\n    {chevron ? <ChevronDown className=\"size-3.5 text-[#8a8a93]\" /> : null}\n  </span>\n);\n\n/** Card title row: optional icon tile, title + subtitle, trailing actions. */\nexport const CardHeader = ({\n  icon,\n  color,\n  title,\n  subtitle,\n  actions,\n  className,\n}: {\n  icon?: LucideIcon;\n  color?: string;\n  title: ReactNode;\n  subtitle?: ReactNode;\n  actions?: ReactNode;\n  className?: string;\n}) => (\n  <div className={cx(\"flex items-start justify-between gap-3\", className)}>\n    <div className=\"flex min-w-0 items-center gap-2.5\">\n      {icon ? <IconTile icon={icon} color={color ?? INK} /> : null}\n      <div className=\"min-w-0\">\n        <h3 className=\"truncate text-[15px] font-semibold tracking-[-0.01em]\">{title}</h3>\n        {subtitle ? (\n          <p className=\"mt-0.5 truncate text-[12px]\" style={{ color: MUTED }}>\n            {subtitle}\n          </p>\n        ) : null}\n      </div>\n    </div>\n    {actions ? <div className=\"flex shrink-0 items-center gap-1.5\">{actions}</div> : null}\n  </div>\n);\n\n/** Small muted label with an optional info glyph. */\nexport const Caption = ({\n  children,\n  info,\n  className,\n}: {\n  children: ReactNode;\n  info?: boolean;\n  className?: string;\n}) => (\n  <p\n    className={cx(\"inline-flex items-center gap-1 text-[12px]\", className)}\n    style={{ color: MUTED }}\n  >\n    {children}\n    {info ? <Info className=\"size-3\" /> : null}\n  </p>\n);\n\n/** Pill tabs with a sprung thumb. Drive `value`/`onChange` from `useCycle` to auto-advance. */\nexport const Segmented = ({\n  options,\n  value,\n  onChange,\n  className,\n  size = \"md\",\n}: {\n  options: readonly string[];\n  value: number;\n  onChange?: (i: number) => void;\n  className?: string;\n  size?: \"sm\" | \"md\";\n}) => {\n  const id = useId();\n\n  return (\n    <div\n      className={cx(\n        \"flex rounded-full bg-[#f2f2f5] p-0.5\",\n        size === \"sm\" ? \"text-[11px]\" : \"text-[13px]\",\n        className,\n      )}\n    >\n      {options.map((o, i) => (\n        <button\n          key={o}\n          type=\"button\"\n          onClick={() => onChange?.(i)}\n          className={cx(\n            \"relative flex-1 rounded-full font-medium transition-colors\",\n            size === \"sm\" ? \"px-2.5 py-1\" : \"px-3 py-1.5\",\n          )}\n          style={{ color: i === value ? INK : MUTED }}\n        >\n          {i === value ? (\n            <motion.span\n              layoutId={`${id}-thumb`}\n              transition={SPRING}\n              className=\"absolute inset-0 rounded-full bg-white shadow-[0_1px_3px_rgba(0,0,0,0.1)] ring-1 ring-black/[0.04]\"\n            />\n          ) : null}\n          <span className=\"relative\">{o}</span>\n        </button>\n      ))}\n    </div>\n  );\n};\n\n/** Inline legend: swatch + label. */\nexport const Legend = ({\n  items,\n  className,\n  swatch = \"dot\",\n}: {\n  items: readonly { label: string; color: string }[];\n  className?: string;\n  swatch?: \"dot\" | \"square\" | \"bar\";\n}) => (\n  <div className={cx(\"flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px]\", className)}>\n    {items.map((it) => (\n      <span key={it.label} className=\"inline-flex items-center gap-1.5 text-[#3a3a42]\">\n        <span\n          className={cx(\n            swatch === \"dot\" && \"size-2 rounded-full\",\n            swatch === \"square\" && \"size-2.5 rounded-[3px]\",\n            swatch === \"bar\" && \"h-1 w-3 rounded-full\",\n          )}\n          style={{ backgroundColor: it.color }}\n        />\n        {it.label}\n      </span>\n    ))}\n  </div>\n);\n\n/** A floating callout that springs to wherever `left`/`top` (percent of its\n * positioned parent) point. `dark` matches the black tooltips. */\nexport const Bubble = ({\n  left,\n  top,\n  children,\n  dark,\n  align = \"center\",\n  className,\n}: {\n  left: number;\n  top: number;\n  children: ReactNode;\n  dark?: boolean;\n  align?: \"center\" | \"left\" | \"right\";\n  className?: string;\n}) => {\n  const shift = { center: \"-50%\", left: \"0%\", right: \"-100%\" }[align];\n\n  return (\n    <motion.div\n      initial={false}\n      animate={{ left: `${left}%`, top: `${top}%` }}\n      transition={SPRING}\n      className=\"pointer-events-none absolute z-10\"\n    >\n      <motion.div\n        initial={{ opacity: 0, scale: 0.9 }}\n        animate={{ opacity: 1, scale: 1 }}\n        transition={SPRING}\n        style={{ x: shift }}\n        className={cx(\n          \"w-max rounded-xl px-2.5 py-1.5 text-[12px] shadow-[0_8px_24px_-8px_rgba(0,0,0,0.25)]\",\n          dark ? \"bg-[#18181b] text-white\" : \"bg-white text-[#0b0b0f] ring-1 ring-black/[0.06]\",\n          className,\n        )}\n      >\n        {children}\n      </motion.div>\n    </motion.div>\n  );\n};\n\n/** Muted sub-row text helper. */\nexport const muted = { color: MUTED } as const;\n","path":"/lib/kit.tsx","target":"uicapsule/finance-charts/lib/kit.tsx","type":"registry:file"},{"content":"export const INK = \"#0b0b0f\";\nexport const MUTED = \"#8a8a93\";\nexport const FAINT = \"#c4c4cb\";\nexport const GRID = \"#ececf0\";\nexport const TRACK = \"#efeff2\";\nexport const CARD = \"#ffffff\";\n\nexport const GREEN = \"#16a34a\";\nexport const GREEN_SOFT = \"#22c55e\";\nexport const RED = \"#ef4444\";\nexport const ORANGE = \"#f97316\";\nexport const BLUE = \"#1d7cf2\";\nexport const SKY = \"#38bdf8\";\nexport const PURPLE = \"#a855f7\";\nexport const VIOLET = \"#7c3aed\";\nexport const YELLOW = \"#fbbf24\";\nexport const PINK = \"#ec4899\";\nexport const TEAL = \"#14b8a6\";\n\nexport const SPRING = {\n  damping: 22,\n  mass: 1,\n  stiffness: 170,\n  type: \"spring\",\n} as const;\n\nexport const THEME = {\n  background: CARD,\n  foreground: INK,\n  grid: GRID,\n  muted: MUTED,\n  palette: [BLUE, PURPLE, ORANGE, GREEN, YELLOW, PINK, TEAL],\n};\n\n/** Dashed horizontal grid rules, the house style for value axes. */\nexport const DASHED_GRID = {\n  stroke: \"#e2e2e7\",\n  strokeDasharray: \"4 4\",\n  strokeOpacity: 1,\n  strokeWidth: 1,\n} as const;\n","path":"/lib/tokens.ts","target":"uicapsule/finance-charts/lib/tokens.ts","type":"registry:file"},{"content":"\"use client\";\n\nimport { FinanceCharts } from \"./finance-charts\";\n\nconst Preview = () => (\n  <main className=\"flex h-dvh items-center justify-center overflow-hidden bg-[#f3f4f7]\">\n    <FinanceCharts />\n  </main>\n);\n\nexport default Preview;\n","path":"/preview.tsx","target":"uicapsule/finance-charts/preview.tsx","type":"registry:file"}],"homepage":"https://www.uicapsule.com/ui/finance-charts","name":"finance-charts","registryDependencies":[],"title":"Finance Charts","type":"registry:block"}