{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "commit-grove",
  "title": "Commit Grove",
  "type": "registry:component",
  "description": "Daily contribution calendar with a green intensity scale, keyboard day navigation and expanding workspace highlights",
  "dependencies": [
    "motion@^12.43.0"
  ],
  "files": [
    {
      "path": "src/kavyn/commit-grove.jsx",
      "type": "registry:file",
      "target": "@components/kavyn/commit-grove.jsx",
      "content": "'use client'\n\nimport { useId, useMemo, useRef, useState } from 'react'\nimport { AnimatePresence, motion, useReducedMotion } from 'motion/react'\n\nconst DAY = 86400000\nconst MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\nconst DEMO_WORKSPACES = [\n  { name: 'Cedar Forge', count: 286, mark: 'CF', color: '#6bbf8a' },\n  { name: 'Lumen Dock', count: 173, mark: 'LD', color: '#b8a0e3' },\n  { name: 'Drift Works', count: 94, mark: 'DW', color: '#e9b17d' },\n]\nfunction calendar(year, startMonth, endMonth, data) {\n  const start = Date.UTC(year, startMonth - 1, 1)\n  const end = Date.UTC(year, endMonth, 0)\n  const counts = new Map()\n  const records = data ?? Array.from({ length: Math.round((end - start) / DAY) + 1 }, (_, i) => ({\n    date: new Date(start + i * DAY).toISOString().slice(0, 10),\n    count: (i * 17 + Math.floor(i / 9) * 3) % 13 < 3 ? 0 : (i * 7 + 5) % 11 + 1,\n  }))\n  for (const entry of records) {\n    if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(entry.date ?? '')) continue\n    const time = Date.parse(`${entry.date}T00:00:00Z`)\n    if (!Number.isFinite(time) || new Date(time).toISOString().slice(0, 10) !== entry.date || time < start || time > end) continue\n    const count = Number(entry.count)\n    if (!Number.isFinite(count) || count < 0) continue\n    counts.set(entry.date, (counts.get(entry.date) ?? 0) + Math.floor(count))\n  }\n  const origin = start - new Date(start).getUTCDay() * DAY\n  const length = Math.ceil(((end - origin) / DAY + 1) / 7) * 7\n  const days = Array.from({ length }, (_, i) => {\n    const time = origin + i * DAY, date = new Date(time).toISOString().slice(0, 10)\n    return { date, count: counts.get(date) ?? 0, active: time >= start && time <= end }\n  })\n  const valid = days.filter((day) => day.active)\n  const max = Math.max(1, ...valid.map((day) => day.count))\n  const total = valid.reduce((sum, day) => sum + day.count, 0)\n  const months = Array.from({ length: endMonth - startMonth + 1 }, (_, i) => {\n    const month = startMonth + i\n    return { label: MONTHS[month - 1], column: Math.floor((Date.UTC(year, month - 1, 1) - origin) / DAY / 7) }\n  })\n  return { days, total, max, months, columns: length / 7 }\n}\n\n// Undefined data generates a labeled demo. Pass [] for a real empty calendar.\n// colors: { dark: [empty, low, medium, high, peak], light: [...] }.\n// dates are YYYY-MM-DD calendar days, interpreted in UTC, never local timezone.\n/** @param {{ year?: any, data?: any, workspaces?: any, startMonth?: any, endMonth?: any, theme?: any, colors?: any, defaultExpanded?: any, onExpandedChange?: any }} props */\nexport default function CommitGrove({ year = 2026, data = undefined, workspaces = undefined, startMonth = 6, endMonth = 12, theme = 'auto', colors = undefined, defaultExpanded = false, onExpandedChange = undefined }) {\n  const reduced = useReducedMotion()\n  const id = useId()\n  const [expanded, setExpanded] = useState(defaultExpanded)\n  const [focused, setFocused] = useState(null)\n  const [hovered, setHovered] = useState(null)\n  const cells = useRef([])\n  const y = Number.isInteger(year) && year >= 100 && year <= 9998 ? year : 2026\n  const first = Math.min(12, Math.max(1, Number.isFinite(startMonth) ? Math.floor(startMonth) : 6))\n  const last = Math.min(12, Math.max(first, Number.isFinite(endMonth) ? Math.floor(endMonth) : 12))\n  const graph = useMemo(() => calendar(y, first, last, Array.isArray(data) ? data : undefined), [y, first, last, data])\n  const orgs = (Array.isArray(workspaces) ? workspaces : data === undefined ? DEMO_WORKSPACES : []).map((org) => ({ ...org, count: Number.isFinite(Number(org.count)) ? Math.max(0, Math.floor(Number(org.count))) : 0 }))\n  const demo = data === undefined\n  const activeStart = graph.days.findIndex((d) => d.active)\n  const cursor = focused ?? activeStart\n  const pointed = hovered ?? focused\n  const selected = pointed !== null ? graph.days[pointed] : null\n  const summary = `${graph.total.toLocaleString('en-US')} contributions from ${MONTHS[first - 1]} to ${MONTHS[last - 1]} ${y}`\n  const style = { width: '100%', maxWidth: 520 }\n  for (const mode of ['dark', 'light']) {\n    if (!Array.isArray(colors?.[mode])) continue\n    colors[mode].slice(0, 5).forEach((color, i) => { if (typeof color === 'string') style[`--grove-${mode}-${i}`] = color })\n  }\n  const keys = (event, index) => {\n    const offset = { ArrowRight: 7, ArrowLeft: -7, ArrowDown: 1, ArrowUp: -1 }[event.key]\n    let next = offset !== undefined ? index + offset : event.key === 'Home' ? activeStart : event.key === 'End' ? graph.days.findLastIndex((d) => d.active) : null\n    if (next === null) return\n    event.preventDefault()\n    if (graph.days[next]?.active) { setFocused(next); cells.current[next]?.focus() }\n  }\n  return <section data-commit-grove data-theme={theme} style={style} className=\"grove-card rounded-[24px] border border-line2 bg-bg p-4 text-tx sm:p-5\">\n    <style>{`\n      .grove-card { --g0:var(--grove-dark-0,#17271e); --g1:var(--grove-dark-1,#244b34); --g2:var(--grove-dark-2,#377149); --g3:var(--grove-dark-3,#53a96a); --g4:var(--grove-dark-4,#8ae49d); }\n      .light .grove-card:not([data-theme=\"dark\"]), :root:not(.dark) .grove-card:not([data-theme=\"dark\"]), .grove-card[data-theme=\"light\"] { --g0:var(--grove-light-0,#e5eee7); --g1:var(--grove-light-1,#c4ddca); --g2:var(--grove-light-2,#8fbf9d); --g3:var(--grove-light-3,#579b6b); --g4:var(--grove-light-4,#267844); }\n      .grove-card[data-theme=\"light\"] { color:#19191e; background:#fafafa; border-color:#dedee5; }\n      .grove-card[data-theme=\"dark\"] { color:#ededf0; background:#09090a; border-color:#303036; }\n      .grove-muted { opacity:.62; }\n      .grove-cell:focus { outline:none; stroke:currentColor; stroke-width:1.4; }\n      .grove-toggle:focus-visible { outline:2px solid var(--g4); outline-offset:3px; }\n      .grove-cell:hover { stroke:currentColor; stroke-width:1; }\n    `}</style>\n    <header className=\"flex flex-wrap items-center justify-between gap-2\"><div><h3 className=\"text-sm font-medium\"><span>{graph.total.toLocaleString('en-US')}</span><span className=\"grove-muted\"> contributions · </span><span>{y}</span></h3><p className=\"grove-muted mt-1 text-[11px]\">{MONTHS[first - 1]} to {MONTHS[last - 1]}</p></div>{demo && <span className=\"grove-muted rounded-full border border-current/15 px-2 py-1 text-[10px]\">Sample activity</span>}</header>\n    <div className=\"mt-4\">\n      <svg className=\"block w-full\" viewBox={`0 0 ${graph.columns * 14} 116`} role=\"group\" aria-label={`${summary}. Use arrow keys to explore days.`}>\n        {graph.months.map((month) => <text key={month.label} x={month.column * 14 + 1} y={10} fontSize={8} fill=\"currentColor\" opacity={.55}>{month.label}</text>)}\n        {graph.days.map((day, i) => day.active && <motion.rect key={day.date} ref={(node) => { cells.current[i] = node }} role=\"img\" aria-label={`${day.date}: ${day.count} contributions`} tabIndex={i === cursor ? 0 : -1} className=\"grove-cell\" x={Math.floor(i / 7) * 14 + 1} y={18 + (i % 7) * 14} width={11} height={11} rx={2.5} fill={`var(--g${day.count === 0 ? 0 : Math.max(1, Math.ceil(day.count / graph.max * 4))})`} initial={reduced ? false : { opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: .2, delay: reduced ? 0 : Math.floor(i / 7) * .008 }} onFocus={() => setFocused(i)} onBlur={() => setFocused(null)} onMouseEnter={() => setHovered(i)} onMouseLeave={() => setHovered(null)} onKeyDown={(e) => keys(e, i)}><title>{`${day.date}: ${day.count} contributions`}</title></motion.rect>)}\n      </svg>\n      <div className=\"grove-muted mt-2 flex min-h-5 items-center justify-between gap-2 text-[10px]\"><span aria-live=\"polite\">{selected ? `${selected.date} · ${selected.count} contributions` : 'Each square is a day'}</span><div className=\"flex items-center gap-1\" aria-label=\"Color intensity from less to more activity\"><span className=\"mr-1\">Less</span>{[0, 1, 2, 3, 4].map((n) => <span key={n} className=\"size-2 rounded-[2px]\" style={{ background: `var(--g${n})` }} />)}<span className=\"ml-1\">More</span></div></div>\n    </div>\n    <div className=\"mt-4 overflow-hidden rounded-2xl border border-current/10 bg-current/[.025]\">\n      <button type=\"button\" style={{ outlineOffset: -3 }} className=\"grove-toggle flex min-h-14 w-full items-center justify-between gap-2 px-3.5 text-left\" aria-expanded={expanded} aria-controls={`${id}-workspaces`} onClick={() => { setExpanded(!expanded); onExpandedChange?.(!expanded) }}>\n        <span className=\"text-xs font-medium\">Workspace highlights</span><span className=\"flex items-center gap-3\">{!expanded && <span className=\"flex -space-x-1.5\" aria-hidden=\"true\">{orgs.slice(0, 3).map((org, index) => <span key={`${org.name}-${index}`} className=\"grid size-6 place-items-center rounded-full border-2 border-bg text-[8px] font-semibold text-black\" style={{ background: org.color ?? '#9fcab0' }}>{org.mark ?? org.name?.slice(0, 2).toUpperCase()}</span>)}</span>}<motion.svg animate={{ rotate: expanded ? 180 : 0 }} transition={{ duration: reduced ? 0 : .22 }} width={22} height={22} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} className=\"grove-muted rounded-full border border-current/20 p-1\" aria-hidden=\"true\"><path d=\"m6 9 6 6 6-6\" /></motion.svg></span>\n      </button>\n      <div id={`${id}-workspaces`}><AnimatePresence initial={false}>{expanded && <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: reduced ? 0 : .25, ease: [.22, 1, .36, 1] }}>\n        <ul className=\"space-y-1 px-3.5 pb-3\">{orgs.map((org, index) => <motion.li key={`${org.name}-${index}`} initial={reduced ? false : { opacity: 0, y: 7 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: .2, delay: reduced ? 0 : index * .045 }} className=\"flex min-h-11 items-center gap-3\"><span className=\"grid size-7 shrink-0 place-items-center overflow-hidden rounded-full text-[9px] font-semibold text-black\" style={{ background: org.color ?? '#9fcab0' }}>{org.avatar ? <><span className=\"col-start-1 row-start-1\">{org.mark ?? org.name?.slice(0, 2).toUpperCase()}</span><img src={org.avatar} alt=\"\" className=\"col-start-1 row-start-1 size-full object-cover\" onError={(e) => { e.currentTarget.style.display = 'none' }} /></> : org.mark ?? org.name?.slice(0, 2).toUpperCase()}</span><span className=\"min-w-0 flex-1 truncate text-xs\">{org.name}</span><span className=\"grove-muted text-xs tabular-nums\">{org.count.toLocaleString('en-US')}</span></motion.li>)}</ul>{orgs.length === 0 && <p className=\"grove-muted px-3.5 pb-4 text-xs\">No workspace activity supplied.</p>}\n      </motion.div>}</AnimatePresence></div>\n    </div>\n  </section>\n}\n"
    }
  ],
  "cssVars": {
    "theme": {
      "color-bg": "var(--bg)",
      "color-panel": "var(--panel)",
      "color-panel2": "var(--panel2)",
      "color-line": "var(--line)",
      "color-line2": "var(--line2)",
      "color-tx": "var(--tx)",
      "color-mute": "var(--mute)",
      "color-faint": "var(--faint)",
      "color-acc": "var(--acc)",
      "color-acc-fg": "var(--acc-fg)"
    },
    "light": {
      "bg": "#ffffff",
      "panel": "#f5f5f7",
      "panel2": "#e8e8ed",
      "line": "#e5e5ea",
      "line2": "#d2d2d7",
      "tx": "#1d1d1f",
      "mute": "#6e6e73",
      "faint": "#a1a1a6",
      "acc": "#1d1d1f",
      "acc-fg": "#ffffff"
    },
    "dark": {
      "bg": "#000000",
      "panel": "#141416",
      "panel2": "#1f1f22",
      "line": "#262628",
      "line2": "#3a3a3d",
      "tx": "#f5f5f7",
      "mute": "#a1a1a6",
      "faint": "#6e6e73",
      "acc": "#f5f5f7",
      "acc-fg": "#000000"
    }
  },
  "css": {
    ".light": {
      "--bg": "#ffffff",
      "--panel": "#f5f5f7",
      "--panel2": "#e8e8ed",
      "--line": "#e5e5ea",
      "--line2": "#d2d2d7",
      "--tx": "#1d1d1f",
      "--mute": "#6e6e73",
      "--faint": "#a1a1a6",
      "--acc": "#1d1d1f",
      "--acc-fg": "#ffffff"
    }
  }
}
