{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "streak-grid",
  "type": "registry:item",
  "title": "Streak Grid",
  "description": "A habit's last weeks as a grid of days (a column per week, Monday at the top), shaded by how much of the goal was done. Choosing a day toggles it; arrow keys move between days. `log` maps \"YYYY-MM-DD\" to a count; `today` is \"YYYY-MM-DD\".",
  "dependencies": [
    "@zubra/runtime@^5.13.1"
  ],
  "categories": [
    "display"
  ],
  "registryDependencies": [
    "https://zubra-js.github.io/zubra-ui/r/theme.json"
  ],
  "files": [
    {
      "path": "components/streak-grid.js",
      "type": "registry:file",
      "target": "~/src/components/zubra/streak-grid.js",
      "content": "// Generated by zubra from streak-grid.zb. Do not edit.\nimport { $define, $r, $t } from \"@zubra/runtime\";\nimport { emit } from '@zubra/runtime';\nimport { state as __zubraState, computed as __zubraComputed } from \"@zubra/runtime\";\n\nexport const tag = \"streak-grid\";\n\nexport default $define(tag, {\n  props: {\n    \"log\": { attribute: \"log\", default: {}, required: false },\n    \"goal\": { attribute: \"goal\", default: 1, required: false },\n    \"today\": { attribute: \"today\", default: \"\", required: false },\n    \"weeks\": { attribute: \"weeks\", default: 12, required: false },\n    \"label\": { attribute: \"label\", default: \"History\", required: false },\n  },\n  abi: 3,\n  shadow: false,\n  form: false,\n  slots: [],\n  events: [\"daytoggle\"],\n  styled: true,\n  styles: \"@layer theme, base, components, utilities;\\n@layer components {\\n@scope (streak-grid) to ([data-zb-slotted=\\\"streak-grid\\\"]) {\\n  :scope { display: block; overflow-x: auto; }\\n  .grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, var(--cell, 0.85rem)); grid-auto-columns: var(--cell, 0.85rem); gap: 3px; width: max-content; }\\n  button { width: 100%; height: 100%; padding: 0; border: 0; border-radius: 3px; background: var(--level-0, var(--muted, #ebedf0)); cursor: pointer; }\\n  button:focus-visible { outline: 2px solid var(--foreground, #1d2130); outline-offset: 1px; }\\n  button[data-level=\\\"1\\\"] { background: color-mix(in srgb, var(--habit, #16a34a) 30%, var(--level-0, var(--muted, #ebedf0))); }\\n  button[data-level=\\\"2\\\"] { background: color-mix(in srgb, var(--habit, #16a34a) 55%, var(--level-0, var(--muted, #ebedf0))); }\\n  button[data-level=\\\"3\\\"] { background: color-mix(in srgb, var(--habit, #16a34a) 78%, var(--level-0, var(--muted, #ebedf0))); }\\n  button[data-level=\\\"4\\\"] { background: var(--habit, #16a34a); }\\n  button[data-today] { box-shadow: 0 0 0 1.5px var(--foreground, #1d2130); }\\n  button:disabled { visibility: hidden; }\\n}\\n}\\n\",\n  template: \"\\n  <div class=\\\"grid\\\" role=\\\"group\\\">\\n    <!--[--><!--]-->\\n  </div>\\n\",\n  setup($p, $emit) {\n    const emit = $emit;\nfunction __zubraAssign(signal, value) { signal.set(value); return value }\nfunction __zubraUpdate(signal, delta, prefix) { const old = signal.get(); signal.set(old + delta); return prefix ? old + delta : old }\n                                       \n\n  const grid = __zubraState(null)\n  const day = (date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, \"0\")}-${String(date.getDate()).padStart(2, \"0\")}`\n  const parse = (text) => new Date(`${text}T12:00`)\n  const names = new Intl.DateTimeFormat(\"en-US\", { weekday: \"short\", month: \"short\", day: \"numeric\" })\n  // `today` defaults to the real today, so the grid has an end and a day to tab to.\n  const anchor = __zubraComputed(() => ($p.today || day(new Date())))\n  const end = __zubraComputed(() => (parse(anchor.get())))\n  // Start on the Monday `weeks` weeks before this week's. One expression, so it follows `today`\n  // and `weeks` when they change (a statement after it would run only once).\n  const addDays = (date, days) => { const next = new Date(date); next.setDate(next.getDate() + days); return next }\n  const start = __zubraComputed(() => (addDays(end.get(), -((end.get().getDay() + 6) % 7) - ($p.weeks - 1) * 7)))\n  const columns = __zubraComputed(() => (Array.from({ length: $p.weeks }, (_, week) => ({\n    week,\n    days: Array.from({ length: 7 }, (_, weekday) => {\n      const date = new Date(start.get())\n      date.setDate(start.get().getDate() + week * 7 + weekday)\n      const key = day(date)\n      const count = $p.log[key] ?? 0\n      const level = date > end.get() ? -1 : count === 0 ? 0 : Math.min(4, Math.ceil((count / $p.goal) * 4))\n      return { key, level, count, label: `${names.format(date)}: ${count}/${$p.goal}` }\n    }),\n  }))))\n\n  // Arrow keys: a day up or down, a week left or right.\n  function move(key, step) {\n    const date = parse(key)\n    date.setDate(date.getDate() + step)\n    grid.get().querySelector(`[data-day=\"${day(date)}\"]:not([disabled])`)?.focus()\n  }\n    return [\n      { path: [0], attribute: \"aria-label\", value: () => $p.label },\n      { path: [0], ref: () => (($el) => (__zubraAssign(grid, $el))) },\n      { path: [0, 0], each: () => $r(columns), key: (column, $index) => $r(column).week, block: { template: \"\\n      <!--[--><!--]-->\\n    \", parts: (column, $index) => [{ path: [0], each: () => $r(column).days, key: (cell, $index) => $r(cell).key, block: { template: \"\\n        <button type=\\\"button\\\"></button>\\n      \", parts: (cell, $index) => [{ path: [0], attribute: \"data-day\", value: () => $r(cell).key }, { path: [0], attribute: \"data-level\", value: () => $r(cell).level }, { path: [0], attribute: \"data-today\", value: () => (($r(cell).key === $r(anchor)) ? \"\" : null) }, { path: [0], attribute: \"disabled\", boolean: true, value: () => ($r(cell).level < 0) }, { path: [0], attribute: \"title\", value: () => $r(cell).label }, { path: [0], attribute: \"aria-label\", value: () => $r(cell).label }, { path: [0], attribute: \"aria-pressed\", value: () => (($r(cell).count >= $p.goal) ? \"true\" : \"false\") }, { path: [0], attribute: \"tabindex\", value: () => (($r(cell).key === $r(anchor)) ? \"0\" : \"-1\") }, { path: [0], on: \"click\", handler: () => (() => emit('daytoggle', $r(cell).key)) }, { path: [0], on: \"keydown\", handler: () => (() => move($r(cell).key, -1)), modifiers: { prevent: true, keys: [\"ArrowUp\"] } }, { path: [0], on: \"keydown\", handler: () => (() => move($r(cell).key, 1)), modifiers: { prevent: true, keys: [\"ArrowDown\"] } }, { path: [0], on: \"keydown\", handler: () => (() => move($r(cell).key, -7)), modifiers: { prevent: true, keys: [\"ArrowLeft\"] } }, { path: [0], on: \"keydown\", handler: () => (() => move($r(cell).key, 7)), modifiers: { prevent: true, keys: [\"ArrowRight\"] } }] } }] } },\n    ];\n  },\n});\n"
    }
  ]
}
