{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gantt-chart",
  "type": "registry:component",
  "title": "Gantt chart",
  "description": "A project schedule with a grouped task list, zoomable time grid, progress bars, milestones, dependency arrows and a today line.",
  "categories": [
    "charts"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/gantt-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/gantt-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  IconAlertTriangle as AlertTriangle,\n  IconChevronDown as ChevronDown,\n  IconFocus2 as FocusIcon,\n} from \"@tabler/icons-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport type GanttZoom = \"day\" | \"week\" | \"month\";\n\nexport interface GanttTask {\n  id: string;\n  label: string;\n  /** First day of the task. Date-only strings such as \"2026-10-05\" are read as calendar days. */\n  start: Date | string;\n  /** Last day of the task, inclusive. A one-day task has the same start and end. */\n  end: Date | string;\n  /** Completion from 0 to 1. */\n  progress?: number;\n  /** Tasks sharing a group are listed together under a collapsible header. */\n  group?: string;\n  /** Person responsible, shown as initials. */\n  owner?: string;\n  /** Ids of tasks that must finish first. Drawn as arrows into this task. */\n  dependsOn?: string[];\n  /** Draw as a diamond on its start date instead of a bar. */\n  milestone?: boolean;\n  /** Any CSS color. Defaults to a chart color per group. */\n  color?: string;\n}\n\nexport interface GanttTaskChange {\n  /** New first day, at local midnight. */\n  start: Date;\n  /** New last day (inclusive), at local midnight. */\n  end: Date;\n}\n\n/** Geometry and state passed to `renderBar`. */\nexport interface GanttBarInfo {\n  start: Date;\n  end: Date;\n  /** Inclusive length in days. */\n  duration: number;\n  progress: number;\n  /** Bar width in pixels at the current zoom. */\n  width: number;\n  color: string;\n  zoom: GanttZoom;\n  milestone: boolean;\n  overdue: boolean;\n  /** Days past the end while unfinished; 0 when on time. */\n  overdueDays: number;\n  selected: boolean;\n  active: boolean;\n  dragging: boolean;\n}\n\nexport interface GanttChartProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"title\" | \"children\"\n> {\n  tasks: GanttTask[];\n  /** Time scale. Leave undefined to let the chart manage it. */\n  zoom?: GanttZoom;\n  defaultZoom?: GanttZoom;\n  onZoomChange?: (zoom: GanttZoom) => void;\n  /** Draws the today line and decides what is overdue. Defaults to the current date. */\n  today?: Date | string;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  /** Controls at the top right, before the zoom control. */\n  actions?: React.ReactNode;\n  /** The selected task. Pass null for none; leave undefined to let the chart manage it. */\n  selectedId?: string | null;\n  defaultSelectedId?: string | null;\n  onSelectedChange?: (id: string | null, task: GanttTask | null) => void;\n  /** Replaces the task name in the left column. */\n  renderTaskLabel?: (task: GanttTask) => React.ReactNode;\n  /** Replaces the inside of a bar. The wrapper keeps position, focus, and dragging. */\n  renderBar?: (task: GanttTask, info: GanttBarInfo) => React.ReactNode;\n  /** Drag bars to move them, drag their edges to resize, or use the arrow keys. */\n  editable?: boolean;\n  /** Called with the new dates when a task is moved or resized. */\n  onTaskChange?: (task: GanttTask, change: GanttTaskChange) => void;\n  /** Formats dates in the readout and accessible labels. Defaults to \"Oct 6\". */\n  dateFormatter?: (date: Date) => string;\n  /** Order groups explicitly. Unlisted groups follow in order of appearance. */\n  groupOrder?: string[];\n  defaultCollapsedGroups?: string[];\n  /** First day of the week for week columns and alignment. Defaults to Monday. */\n  weekStartsOn?: 0 | 1;\n  /** Readout content when no task is active, such as a status line. */\n  summary?: React.ReactNode;\n  /** Maximum height of the schedule in pixels. Taller schedules scroll under a sticky time header. */\n  height?: number;\n  showZoomControl?: boolean;\n  showLegend?: boolean;\n}\n\n/* ------------------------------------------------------------------------ */\n/* Calendar days                                                             */\n/* ------------------------------------------------------------------------ */\n\nconst DAY_MS = 86_400_000;\nconst ROW = 36;\nconst GROUP_ROW = 32;\nconst BAR = 22;\nconst HEADER = 50;\nconst ZOOMS: { value: GanttZoom; label: string; ppd: number }[] = [\n  { value: \"day\", label: \"Day\", ppd: 34 },\n  { value: \"week\", label: \"Week\", ppd: 10 },\n  { value: \"month\", label: \"Month\", ppd: 4 },\n];\nconst PALETTE = [\n  \"var(--color-chart-1)\",\n  \"var(--color-chart-4)\",\n  \"var(--color-chart-2)\",\n  \"var(--color-chart-5)\",\n  \"var(--color-chart-3)\",\n];\n\n/** Whole days since 1970-01-01 for the calendar date the input names. */\nfunction toDay(input: Date | string): number {\n  if (typeof input === \"string\") {\n    const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(input.trim());\n    if (match)\n      return Math.round(Date.UTC(+match[1], +match[2] - 1, +match[3]) / DAY_MS);\n    input = new Date(input);\n  }\n  const time = input.getTime();\n  if (!Number.isFinite(time)) return NaN;\n  return Math.round(\n    Date.UTC(input.getFullYear(), input.getMonth(), input.getDate()) / DAY_MS,\n  );\n}\n\n/** The calendar day as a local-midnight Date. */\nfunction fromDay(day: number) {\n  const d = new Date(day * DAY_MS);\n  return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());\n}\n\nfunction parts(day: number) {\n  const d = new Date(day * DAY_MS);\n  return {\n    year: d.getUTCFullYear(),\n    month: d.getUTCMonth(),\n    date: d.getUTCDate(),\n    weekday: d.getUTCDay(),\n  };\n}\n\nconst utc = (options: Intl.DateTimeFormatOptions) =>\n  new Intl.DateTimeFormat(\"en-US\", { timeZone: \"UTC\", ...options });\nconst monthYear = utc({ month: \"long\", year: \"numeric\" });\nconst monthShort = utc({ month: \"short\" });\nconst monthDay = utc({ month: \"short\", day: \"numeric\" });\nconst localMonthDay = new Intl.DateTimeFormat(\"en-US\", {\n  month: \"short\",\n  day: \"numeric\",\n});\nconst defaultDateFormatter = (date: Date) => localMonthDay.format(date);\n\nconst clamp01 = (value: number) => Math.min(1, Math.max(0, value));\nconst pct = (value: number) => `${Math.round(value * 100)}%`;\n\nfunction initials(name: string) {\n  const words = name.trim().split(/\\s+/).filter(Boolean);\n  if (!words.length) return \"?\";\n  return (\n    words.length === 1\n      ? words[0].slice(0, 2)\n      : words[0][0] + words[words.length - 1][0]\n  ).toUpperCase();\n}\n\nfunction hash(text: string) {\n  let h = 0;\n  for (let i = 0; i < text.length; i++) h = (h * 31 + text.charCodeAt(i)) | 0;\n  return Math.abs(h);\n}\n\n/** Orthogonal path through the points with softly rounded corners. */\nfunction roundedPath(points: [number, number][], radius = 4) {\n  let d = `M${points[0][0]} ${points[0][1]}`;\n  for (let i = 1; i < points.length - 1; i++) {\n    const [px, py] = points[i - 1];\n    const [x, y] = points[i];\n    const [nx, ny] = points[i + 1];\n    const r = Math.min(\n      radius,\n      Math.hypot(x - px, y - py) / 2,\n      Math.hypot(nx - x, ny - y) / 2,\n    );\n    const ax = x - Math.sign(x - px) * r;\n    const ay = y - Math.sign(y - py) * r;\n    const bx = x + Math.sign(nx - x) * r;\n    const by = y + Math.sign(ny - y) * r;\n    d += `L${ax} ${ay}Q${x} ${y} ${bx} ${by}`;\n  }\n  const last = points[points.length - 1];\n  return `${d}L${last[0]} ${last[1]}`;\n}\n\n/* ------------------------------------------------------------------------ */\n/* Model                                                                     */\n/* ------------------------------------------------------------------------ */\n\ninterface TaskModel {\n  task: GanttTask;\n  start: number;\n  end: number;\n  progress: number;\n  milestone: boolean;\n  color: string;\n  group: string;\n}\n\ntype Row =\n  | {\n      kind: \"group\";\n      key: string;\n      name: string;\n      color: string;\n      members: TaskModel[];\n      y: number;\n      h: number;\n    }\n  | { kind: \"task\"; key: string; model: TaskModel; y: number; h: number };\n\ninterface DragState {\n  id: string;\n  mode: \"move\" | \"start\" | \"end\";\n  originX: number;\n  from: [number, number];\n  start: number;\n  end: number;\n  moved: boolean;\n}\n\n/* ------------------------------------------------------------------------ */\n/* GanttChart                                                                */\n/* ------------------------------------------------------------------------ */\n\n/**\n * A project schedule: a grouped task list beside a zoomable time grid with progress\n * bars, milestones, dependency arrows, and a today line. Hover a bar to read it in the\n * footer; with `editable`, drag or use the arrow keys to reschedule.\n */\nfunction GanttChart({\n  tasks,\n  zoom: zoomProp,\n  defaultZoom = \"week\",\n  onZoomChange,\n  today: todayProp,\n  title,\n  description,\n  actions,\n  selectedId,\n  defaultSelectedId = null,\n  onSelectedChange,\n  renderTaskLabel,\n  renderBar,\n  editable = false,\n  onTaskChange,\n  dateFormatter = defaultDateFormatter,\n  groupOrder,\n  defaultCollapsedGroups,\n  weekStartsOn = 1,\n  summary,\n  height,\n  showZoomControl = true,\n  showLegend = true,\n  className,\n  ...props\n}: GanttChartProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [innerZoom, setInnerZoom] = React.useState<GanttZoom>(defaultZoom);\n  const zoom = zoomProp ?? innerZoom;\n  const ppd = ZOOMS.find((z) => z.value === zoom)?.ppd ?? 12;\n  const [now] = React.useState(() => new Date());\n  const today = toDay(todayProp ?? now);\n\n  const [innerSelected, setInnerSelected] = React.useState<string | null>(\n    defaultSelectedId,\n  );\n  const controlled = selectedId !== undefined;\n  const selected = controlled ? selectedId : innerSelected;\n  const [hoveredId, setHoveredId] = React.useState<string | null>(null);\n  const [focusedId, setFocusedId] = React.useState<string | null>(null);\n  const [tabStopId, setTabStopId] = React.useState<string | null>(null);\n  const [collapsed, setCollapsed] = React.useState<Set<string>>(\n    () => new Set(defaultCollapsedGroups ?? []),\n  );\n  const [drag, setDrag] = React.useState<DragState | null>(null);\n  const [announcement, setAnnouncement] = React.useState(\"\");\n  const [scrolled, setScrolled] = React.useState(false);\n  // Width of the visible timeline, so short schedules still fill the card.\n  const [available, setAvailable] = React.useState(0);\n  const scrollRef = React.useRef<HTMLDivElement>(null);\n  const labelRef = React.useRef<HTMLDivElement>(null);\n  const suppressClick = React.useRef(false);\n\n  const fmt = (day: number) => dateFormatter(fromDay(day));\n\n  /* Tasks → models and groups ------------------------------------------- */\n\n  const { models, groups, grouped } = React.useMemo(() => {\n    const order = new Map<string, number>();\n    for (const name of groupOrder ?? []) order.set(name, order.size);\n    for (const task of tasks) {\n      const name = task.group ?? \"\";\n      if (!order.has(name)) order.set(name, order.size);\n    }\n    const list: TaskModel[] = [];\n    for (const task of tasks) {\n      const a = toDay(task.start);\n      const b = toDay(task.end);\n      if (!Number.isFinite(a) || !Number.isFinite(b)) continue;\n      const group = task.group ?? \"\";\n      const milestone = task.milestone ?? false;\n      list.push({\n        task,\n        start: Math.min(a, b),\n        end: milestone ? Math.min(a, b) : Math.max(a, b),\n        progress: clamp01(task.progress ?? 0),\n        milestone,\n        color: task.color ?? PALETTE[(order.get(group) ?? 0) % PALETTE.length],\n        group,\n      });\n    }\n    const byGroup = new Map<string, TaskModel[]>();\n    for (const [name] of [...order.entries()].sort((x, y) => x[1] - y[1]))\n      byGroup.set(name, []);\n    for (const model of list) byGroup.get(model.group)!.push(model);\n    const groupList = [...byGroup.entries()]\n      .filter(([, members]) => members.length > 0)\n      .map(([name, members]) => ({\n        name,\n        members,\n        color: PALETTE[(order.get(name) ?? 0) % PALETTE.length],\n      }));\n    return {\n      models: list,\n      groups: groupList,\n      grouped: groupList.length > 1 || (groupList[0]?.name ?? \"\") !== \"\",\n    };\n  }, [tasks, groupOrder]);\n\n  // While dragging, the dragged task previews its new dates everywhere.\n  const live = React.useCallback(\n    (model: TaskModel): TaskModel =>\n      drag && drag.id === model.task.id\n        ? { ...model, start: drag.start, end: drag.end }\n        : model,\n    [drag],\n  );\n\n  const byId = React.useMemo(\n    () => new Map(models.map((m) => [m.task.id, m])),\n    [models],\n  );\n\n  /* Time range ------------------------------------------------------------ */\n\n  const range = React.useMemo(() => {\n    let lo = Infinity;\n    let hi = -Infinity;\n    for (const m of models) {\n      lo = Math.min(lo, m.start);\n      hi = Math.max(hi, m.end);\n    }\n    if (lo === Infinity) {\n      lo = today - 14;\n      hi = today + 28;\n    }\n    if (today >= lo - 60 && today <= hi + 60) {\n      lo = Math.min(lo, today);\n      hi = Math.max(hi, today);\n    }\n    const pad = zoom === \"day\" ? 7 : zoom === \"week\" ? 14 : 31;\n    lo -= pad;\n    hi += pad;\n    // Align to a week start in day and week zoom, and to a month start in month zoom.\n    if (zoom === \"month\") {\n      const p = parts(lo);\n      lo = Math.round(Date.UTC(p.year, p.month, 1) / DAY_MS);\n    } else {\n      lo -= (parts(lo).weekday - weekStartsOn + 7) % 7;\n    }\n    hi = Math.max(hi, lo + Math.ceil(available / ppd) - 1);\n    if (zoom === \"month\") {\n      const q = parts(hi);\n      hi = Math.round(Date.UTC(q.year, q.month + 1, 1) / DAY_MS) - 1;\n    } else {\n      hi += (weekStartsOn + 6 - parts(hi).weekday + 7) % 7;\n    }\n    return { lo, hi, days: hi - lo + 1 };\n  }, [models, today, zoom, weekStartsOn, available, ppd]);\n\n  const { lo, hi } = range;\n  const W = range.days * ppd;\n  const xOf = (day: number) => (day - lo) * ppd;\n\n  const ticks = React.useMemo(() => {\n    const major: { key: string; x: number; w: number; label: string }[] = [];\n    const minor: {\n      key: string;\n      x: number;\n      w: number;\n      label: string;\n      weekend: boolean;\n      day: number;\n    }[] = [];\n    const monthLines: number[] = [];\n    for (let day = lo; day <= hi; day++) {\n      const p = parts(day);\n      if (p.date === 1 && day !== lo) monthLines.push(xOf(day));\n      const startsMajor =\n        day === lo ||\n        (zoom === \"month\" ? p.date === 1 && p.month % 3 === 0 : p.date === 1);\n      if (startsMajor) {\n        if (major.length)\n          major[major.length - 1].w = xOf(day) - major[major.length - 1].x;\n        major.push({\n          key: `M${day}`,\n          x: xOf(day),\n          w: 0,\n          label:\n            zoom === \"month\"\n              ? `Q${Math.floor(p.month / 3) + 1} ${p.year}`\n              : monthYear.format(new Date(day * DAY_MS)),\n        });\n      }\n      const startsMinor =\n        zoom === \"day\"\n          ? true\n          : zoom === \"week\"\n            ? p.weekday === weekStartsOn\n            : p.date === 1 || day === lo;\n      if (startsMinor) {\n        if (minor.length)\n          minor[minor.length - 1].w = xOf(day) - minor[minor.length - 1].x;\n        minor.push({\n          key: `m${day}`,\n          x: xOf(day),\n          w: 0,\n          day,\n          weekend: zoom === \"day\" && (p.weekday === 0 || p.weekday === 6),\n          label:\n            zoom === \"day\"\n              ? String(p.date)\n              : zoom === \"week\"\n                ? monthDay.format(new Date(day * DAY_MS))\n                : monthShort.format(new Date(day * DAY_MS)),\n        });\n      }\n    }\n    if (major.length) major[major.length - 1].w = W - major[major.length - 1].x;\n    if (minor.length) minor[minor.length - 1].w = W - minor[minor.length - 1].x;\n    return { major, minor, monthLines };\n  }, [lo, hi, zoom, ppd, weekStartsOn, W]);\n\n  /* Rows ------------------------------------------------------------------ */\n\n  const rows = React.useMemo(() => {\n    const out: Row[] = [];\n    let y = 0;\n    for (const group of groups) {\n      if (grouped) {\n        out.push({\n          kind: \"group\",\n          key: `g:${group.name}`,\n          name: group.name,\n          color: group.color,\n          members: group.members,\n          y,\n          h: GROUP_ROW,\n        });\n        y += GROUP_ROW;\n        if (collapsed.has(group.name)) continue;\n      }\n      for (const model of group.members) {\n        out.push({ kind: \"task\", key: model.task.id, model, y, h: ROW });\n        y += ROW;\n      }\n    }\n    return { list: out, height: y };\n  }, [groups, grouped, collapsed]);\n\n  const taskRows = rows.list.filter(\n    (row): row is Extract<Row, { kind: \"task\" }> => row.kind === \"task\",\n  );\n  const rowOf = new Map(taskRows.map((row) => [row.model.task.id, row]));\n\n  const overdueDays = (m: TaskModel) =>\n    m.progress < 1 && m.end < today ? today - m.end : 0;\n\n  /* Selection, hover, focus ------------------------------------------------ */\n\n  const transientId = drag?.id ?? hoveredId ?? focusedId;\n  const activeId = transientId ?? selected ?? null;\n  const activeModel = activeId ? byId.get(activeId) : undefined;\n  const stopId =\n    tabStopId && rowOf.has(tabStopId)\n      ? tabStopId\n      : selected && rowOf.has(selected)\n        ? selected\n        : (taskRows[0]?.model.task.id ?? null);\n\n  const setSelected = (id: string | null) => {\n    if (!controlled) setInnerSelected(id);\n    onSelectedChange?.(id, id ? (byId.get(id)?.task ?? null) : null);\n  };\n  const toggle = (id: string) => setSelected(selected === id ? null : id);\n\n  const setZoom = (next: GanttZoom) => {\n    if (next === zoom) return;\n    if (zoomProp === undefined) setInnerZoom(next);\n    onZoomChange?.(next);\n  };\n\n  const toggleGroup = (name: string) =>\n    setCollapsed((current) => {\n      const next = new Set(current);\n      if (next.has(name)) next.delete(name);\n      else next.add(name);\n      return next;\n    });\n\n  /* Scrolling ------------------------------------------------------------- */\n\n  const view = React.useRef<{ lo: number; ppd: number } | null>(null);\n  const viewport = () => {\n    const el = scrollRef.current;\n    if (!el) return 0;\n    return el.clientWidth - (labelRef.current?.offsetWidth ?? 0);\n  };\n  const scrollToDay = (day: number, fraction: number, smooth = false) => {\n    const el = scrollRef.current;\n    if (!el) return;\n    const left = Math.max(0, (day - lo + 0.5) * ppd - viewport() * fraction);\n    el.scrollTo({ left, behavior: smooth ? \"smooth\" : \"auto\" });\n  };\n\n  React.useLayoutEffect(() => {\n    const el = scrollRef.current;\n    if (!el) return;\n    const measure = () =>\n      setAvailable(\n        Math.max(0, el.clientWidth - (labelRef.current?.offsetWidth ?? 0)),\n      );\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, []);\n\n  // First paint: open on today (or the first task). Zoom changes keep today where it\n  // was on screen when it was visible, and the center date otherwise.\n  React.useLayoutEffect(() => {\n    const el = scrollRef.current;\n    if (!el) return;\n    const previous = view.current;\n    if (previous && previous.ppd !== ppd) {\n      const width = viewport();\n      const todayAt =\n        (today - previous.lo + 0.5) * previous.ppd - el.scrollLeft;\n      if (today >= lo && today <= hi && todayAt >= 0 && todayAt <= width) {\n        scrollToDay(today, todayAt / (width || 1));\n      } else {\n        const center = previous.lo + (el.scrollLeft + width / 2) / previous.ppd;\n        scrollToDay(center - 0.5, 0.5);\n      }\n    } else if (!previous) {\n      const first = models.length\n        ? Math.min(...models.map((m) => m.start))\n        : today;\n      scrollToDay(\n        today >= lo && today <= hi ? today : first,\n        today >= lo && today <= hi ? 0.32 : 0.05,\n      );\n    }\n    view.current = { lo, ppd };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [ppd]);\n  React.useLayoutEffect(() => {\n    if (view.current) view.current.lo = lo;\n  }, [lo]);\n\n  /* Editing --------------------------------------------------------------- */\n\n  const commit = (model: TaskModel, start: number, end: number) => {\n    if (start === model.start && end === model.end) return;\n    onTaskChange?.(model.task, { start: fromDay(start), end: fromDay(end) });\n    setAnnouncement(\n      `${model.task.label}: ${fmt(start)}${model.milestone ? \"\" : ` to ${fmt(end)}`}`,\n    );\n  };\n\n  const onBarPointerDown = (\n    event: React.PointerEvent<HTMLElement>,\n    model: TaskModel,\n    mode: DragState[\"mode\"],\n  ) => {\n    if (!editable || event.button !== 0) return;\n    event.preventDefault();\n    event.stopPropagation();\n    (\n      event.currentTarget.closest(\n        '[data-slot=\"gantt-bar\"]',\n      ) as HTMLElement | null\n    )?.focus({ preventScroll: true });\n    event.currentTarget.setPointerCapture(event.pointerId);\n    setDrag({\n      id: model.task.id,\n      mode,\n      originX: event.clientX,\n      from: [model.start, model.end],\n      start: model.start,\n      end: model.end,\n      moved: false,\n    });\n  };\n\n  const onBarPointerMove = (event: React.PointerEvent<HTMLElement>) => {\n    if (!drag) return;\n    const dx = event.clientX - drag.originX;\n    const days = Math.round(dx / ppd);\n    let [start, end] = drag.from;\n    if (drag.mode === \"move\") {\n      const span = end - start;\n      start = Math.min(hi - span, Math.max(lo, start + days));\n      end = start + span;\n    } else if (drag.mode === \"start\") {\n      start = Math.min(end, Math.max(lo, start + days));\n    } else {\n      end = Math.max(start, Math.min(hi, end + days));\n    }\n    const moved = drag.moved || Math.abs(dx) > 3;\n    if (start !== drag.start || end !== drag.end || moved !== drag.moved)\n      setDrag({ ...drag, start, end, moved });\n  };\n\n  const onBarPointerUp = (model: TaskModel) => {\n    if (!drag) return;\n    if (drag.moved) {\n      suppressClick.current = true;\n      commit(model, drag.start, drag.end);\n    }\n    setDrag(null);\n  };\n\n  const onBarKeyDown = (\n    event: React.KeyboardEvent<HTMLElement>,\n    model: TaskModel,\n  ) => {\n    const index = taskRows.findIndex(\n      (row) => row.model.task.id === model.task.id,\n    );\n    const focusTask = (id: string | undefined) => {\n      if (!id) return;\n      setTabStopId(id);\n      const bar = scrollRef.current?.querySelector<HTMLElement>(\n        `[data-slot=\"gantt-bar\"][data-id=\"${CSS.escape(id)}\"]`,\n      );\n      bar?.focus({ preventScroll: true });\n      bar?.scrollIntoView({ block: \"nearest\", inline: \"nearest\" });\n    };\n    switch (event.key) {\n      case \"ArrowDown\":\n        event.preventDefault();\n        focusTask(taskRows[index + 1]?.model.task.id);\n        return;\n      case \"ArrowUp\":\n        event.preventDefault();\n        focusTask(taskRows[index - 1]?.model.task.id);\n        return;\n      case \"Home\":\n        event.preventDefault();\n        focusTask(taskRows[0]?.model.task.id);\n        return;\n      case \"End\":\n        event.preventDefault();\n        focusTask(taskRows[taskRows.length - 1]?.model.task.id);\n        return;\n      case \"Enter\":\n      case \" \":\n        event.preventDefault();\n        toggle(model.task.id);\n        return;\n      case \"Escape\":\n        if (selected != null) {\n          event.preventDefault();\n          setSelected(null);\n        }\n        return;\n      case \"ArrowLeft\":\n      case \"ArrowRight\": {\n        if (!editable) return;\n        event.preventDefault();\n        const step = event.key === \"ArrowRight\" ? 1 : -1;\n        if (event.shiftKey && !model.milestone) {\n          commit(\n            model,\n            model.start,\n            Math.max(model.start, Math.min(hi, model.end + step)),\n          );\n        } else {\n          const span = model.end - model.start;\n          const start = Math.min(hi - span, Math.max(lo, model.start + step));\n          commit(model, start, start + span);\n        }\n        return;\n      }\n    }\n  };\n\n  /* Readout --------------------------------------------------------------- */\n\n  const totalDays = models.reduce(\n    (sum, m) => sum + (m.milestone ? 0 : m.end - m.start + 1),\n    0,\n  );\n  const overall = totalDays\n    ? models.reduce(\n        (sum, m) =>\n          sum + (m.milestone ? 0 : (m.end - m.start + 1) * m.progress),\n        0,\n      ) / totalDays\n    : 0;\n  const overdueCount = models.filter((m) => overdueDays(m) > 0).length;\n  const nextMilestone = models\n    .filter((m) => m.milestone && m.start >= today && m.progress < 1)\n    .sort((a, b) => a.start - b.start)[0];\n\n  let readout: React.ReactNode;\n  if (activeModel) {\n    const m = live(activeModel);\n    const late = overdueDays(m);\n    readout = (\n      <>\n        <div className=\"flex min-w-14 flex-col\">\n          <span className=\"text-base leading-5 font-semibold tracking-tight tabular-nums\">\n            {m.milestone\n              ? m.progress >= 1\n                ? \"Done\"\n                : fmt(m.start)\n              : pct(m.progress)}\n          </span>\n          <span className=\"text-[10.5px] leading-4 text-muted-foreground\">\n            {m.milestone ? \"milestone\" : \"complete\"}\n          </span>\n        </div>\n        <div className=\"flex min-w-0 flex-col\">\n          <span className=\"flex min-w-0 items-center gap-1.5 text-xs leading-5\">\n            <span\n              aria-hidden=\"true\"\n              className=\"size-2 shrink-0 rounded-[3px]\"\n              style={{ background: m.color }}\n            />\n            <span className=\"truncate font-medium text-foreground\">\n              {m.task.label}\n            </span>\n            {m.task.owner ? (\n              <span className=\"shrink-0 text-muted-foreground\">\n                · {m.task.owner}\n              </span>\n            ) : null}\n          </span>\n          <span className=\"flex min-w-0 items-center gap-1.5 text-[10.5px] leading-4 text-muted-foreground\">\n            <span className=\"font-mono tabular-nums\">\n              {m.milestone ? fmt(m.start) : `${fmt(m.start)} → ${fmt(m.end)}`}\n            </span>\n            {!m.milestone ? (\n              <>\n                <span aria-hidden=\"true\">·</span>\n                <span className=\"tabular-nums\">{m.end - m.start + 1}d</span>\n              </>\n            ) : null}\n            {late ? (\n              <span className=\"inline-flex items-center gap-1 font-medium text-destructive\">\n                <AlertTriangle aria-hidden=\"true\" className=\"size-3\" />\n                {late}d overdue\n              </span>\n            ) : null}\n            {drag?.moved ? (\n              <span className=\"text-foreground\">· release to apply</span>\n            ) : null}\n          </span>\n        </div>\n      </>\n    );\n  } else if (summary != null) {\n    readout = summary;\n  } else {\n    readout = (\n      <>\n        <div className=\"flex min-w-14 flex-col\">\n          <span className=\"text-base leading-5 font-semibold tracking-tight tabular-nums\">\n            {pct(overall)}\n          </span>\n          <span className=\"text-[10.5px] leading-4 text-muted-foreground\">\n            complete\n          </span>\n        </div>\n        <div className=\"flex min-w-0 flex-col\">\n          <span className=\"truncate text-xs leading-5 text-foreground\">\n            {models.length} {models.length === 1 ? \"task\" : \"tasks\"}\n            {grouped\n              ? ` · ${groups.length} ${groups.length === 1 ? \"group\" : \"groups\"}`\n              : \"\"}\n          </span>\n          <span className=\"truncate text-[10.5px] leading-4 text-muted-foreground\">\n            {overdueCount ? (\n              <span className=\"text-destructive\">{overdueCount} overdue</span>\n            ) : (\n              \"On schedule\"\n            )}\n            {nextMilestone\n              ? ` · Next: ${nextMilestone.task.label}, ${fmt(nextMilestone.start)}`\n              : null}\n          </span>\n        </div>\n      </>\n    );\n  }\n\n  /* Render ---------------------------------------------------------------- */\n\n  const describe = (m: TaskModel) => {\n    const out = [m.task.label];\n    if (m.milestone) out.push(`milestone ${fmt(m.start)}`);\n    else\n      out.push(\n        `${fmt(m.start)} to ${fmt(m.end)}`,\n        `${m.end - m.start + 1} days`,\n        `${pct(m.progress)} complete`,\n      );\n    if (m.task.owner) out.push(m.task.owner);\n    const late = overdueDays(m);\n    if (late) out.push(`${late} days overdue`);\n    return out.join(\", \");\n  };\n\n  const todayX = today >= lo && today <= hi ? xOf(today) + ppd / 2 : null;\n  const hasHeader =\n    title != null || description != null || actions != null || showZoomControl;\n  const scheduleLabel = typeof title === \"string\" ? title : \"Schedule\";\n\n  // Dependency connectors between visible tasks.\n  const connectors: {\n    key: string;\n    d: string;\n    tone: \"idle\" | \"active\" | \"conflict\";\n  }[] = [];\n  for (const row of taskRows) {\n    const target = live(row.model);\n    for (const depId of row.model.task.dependsOn ?? []) {\n      const sourceRow = rowOf.get(depId);\n      if (!sourceRow) continue;\n      const source = live(sourceRow.model);\n      const x1 = source.milestone\n        ? xOf(source.start) + ppd / 2 + 6\n        : xOf(source.end + 1) - 1;\n      const y1 = sourceRow.y + ROW / 2;\n      const x2 = target.milestone\n        ? xOf(target.start) + ppd / 2 - 7\n        : xOf(target.start) + 1;\n      const y2 = row.y + ROW / 2;\n      const gap = 8;\n      const points: [number, number][] =\n        x2 - x1 >= gap * 2\n          ? [\n              [x1, y1],\n              [x1 + gap, y1],\n              [x1 + gap, y2],\n              [x2, y2],\n            ]\n          : [\n              [x1, y1],\n              [x1 + gap, y1],\n              [x1 + gap, y2 > y1 ? row.y : row.y + ROW],\n              [x2 - gap, y2 > y1 ? row.y : row.y + ROW],\n              [x2 - gap, y2],\n              [x2, y2],\n            ];\n      // A task may start the day after its predecessor ends; a milestone may land on that day.\n      const conflict = target.milestone\n        ? target.start < source.end\n        : target.start <= source.end;\n      connectors.push({\n        key: `${depId}>${row.model.task.id}`,\n        d: roundedPath(points),\n        tone: conflict\n          ? \"conflict\"\n          : activeId === depId || activeId === row.model.task.id\n            ? \"active\"\n            : \"idle\",\n      });\n    }\n  }\n  connectors.sort(\n    (a, b) => (a.tone === \"idle\" ? 0 : 1) - (b.tone === \"idle\" ? 0 : 1),\n  );\n\n  const gridBackground = (() => {\n    const line = \"color-mix(in oklab, var(--color-border) 70%, transparent)\";\n    if (zoom === \"day\") {\n      const firstSaturday = lo + ((6 - parts(lo).weekday + 7) % 7);\n      return {\n        backgroundImage: `linear-gradient(to right, var(--gantt-weekend) 0 ${2 * ppd}px, transparent ${2 * ppd}px), linear-gradient(to right, ${line} 0 1px, transparent 1px)`,\n        backgroundSize: `${7 * ppd}px 100%, ${ppd}px 100%`,\n        backgroundPosition: `${xOf(firstSaturday)}px 0, 0 0`,\n      };\n    }\n    if (zoom === \"week\")\n      return {\n        backgroundImage: `linear-gradient(to right, ${line} 0 1px, transparent 1px)`,\n        backgroundSize: `${7 * ppd}px 100%`,\n      };\n    return {};\n  })();\n\n  return (\n    <div\n      data-slot=\"gantt-chart\"\n      data-zoom={zoom}\n      data-editable={editable || undefined}\n      className={cn(\n        \"@container/gantt-chart flex min-w-0 flex-col overflow-hidden rounded-xl border bg-card text-card-foreground shadow-xs\",\n        \"[--gantt-weekend:var(--color-muted)] dark:[--gantt-weekend:color-mix(in_oklab,var(--color-muted)_75%,transparent)]\",\n        className,\n      )}\n      {...props}\n    >\n      {hasHeader ? (\n        <div\n          data-slot=\"gantt-chart-header\"\n          className=\"flex flex-col gap-1 px-5 pt-5 pb-4\"\n        >\n          <div className=\"flex flex-wrap items-center justify-between gap-x-3 gap-y-2\">\n            {title != null ? (\n              <h3 className=\"min-w-0 text-sm leading-7 font-semibold tracking-tight\">\n                {title}\n              </h3>\n            ) : null}\n            <div className=\"ml-auto flex shrink-0 items-center gap-2\">\n              {actions}\n              {showZoomControl ? (\n                <>\n                  {todayX != null ? (\n                    <button\n                      type=\"button\"\n                      aria-label=\"Scroll to today\"\n                      title=\"Today\"\n                      onClick={() => scrollToDay(today, 0.32, true)}\n                      className=\"inline-flex size-7 items-center justify-center rounded-md border text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 motion-reduce:transition-none\"\n                    >\n                      <FocusIcon aria-hidden=\"true\" className=\"size-3.5\" />\n                    </button>\n                  ) : null}\n                  <div\n                    role=\"group\"\n                    aria-label=\"Zoom\"\n                    data-slot=\"gantt-chart-zoom\"\n                    className=\"inline-flex h-7 items-center rounded-md border bg-muted/40 p-0.5\"\n                  >\n                    {ZOOMS.map((option) => (\n                      <button\n                        key={option.value}\n                        type=\"button\"\n                        aria-pressed={zoom === option.value}\n                        onClick={() => setZoom(option.value)}\n                        className={cn(\n                          \"h-6 rounded-[5px] px-2 text-[11px] font-medium text-muted-foreground outline-none transition-colors motion-reduce:transition-none\",\n                          \"hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\",\n                          \"aria-pressed:bg-card aria-pressed:text-foreground aria-pressed:shadow-xs\",\n                        )}\n                      >\n                        {option.label}\n                      </button>\n                    ))}\n                  </div>\n                </>\n              ) : null}\n            </div>\n          </div>\n          {description != null ? (\n            <p className=\"text-xs text-muted-foreground\">{description}</p>\n          ) : null}\n        </div>\n      ) : null}\n\n      <div\n        ref={scrollRef}\n        data-slot=\"gantt-chart-scroll\"\n        className=\"relative overflow-auto overscroll-x-contain border-t [--gantt-label:8.5rem] @sm/gantt-chart:[--gantt-label:10.5rem] @md/gantt-chart:[--gantt-label:12.5rem] @2xl/gantt-chart:[--gantt-label:14.5rem]\"\n        style={height != null ? { maxHeight: height } : undefined}\n        onScroll={(event) => {\n          const next = event.currentTarget.scrollLeft > 0;\n          if (next !== scrolled) setScrolled(next);\n        }}\n      >\n        <div\n          className=\"grid\"\n          style={{\n            gridTemplateColumns: `var(--gantt-label) ${W}px`,\n            width: `calc(var(--gantt-label) + ${W}px)`,\n          }}\n        >\n          {/* Corner */}\n          <div\n            className={cn(\n              \"sticky top-0 left-0 z-40 flex items-end justify-between border-r border-b bg-card px-3 pb-1.5 text-[11px] font-medium text-muted-foreground\",\n              scrolled && \"shadow-[6px_0_12px_-8px_rgb(0_0_0/0.25)]\",\n            )}\n            style={{ height: HEADER }}\n          >\n            <span>Task</span>\n            <span className=\"hidden @sm/gantt-chart:inline\">Owner</span>\n          </div>\n\n          {/* Time header */}\n          <div\n            data-slot=\"gantt-chart-timescale\"\n            aria-hidden=\"true\"\n            className=\"sticky top-0 z-30 border-b bg-card\"\n            style={{ height: HEADER, width: W }}\n          >\n            {ticks.major.map((tick) => (\n              <div\n                key={tick.key}\n                className=\"absolute top-0 flex h-[24px] items-center border-l px-2 first:border-l-0\"\n                style={{ left: tick.x, width: tick.w }}\n              >\n                <span className=\"sticky left-[calc(var(--gantt-label)+0.5rem)] truncate text-[11px] font-medium text-foreground\">\n                  {tick.label}\n                </span>\n              </div>\n            ))}\n            {ticks.minor.map((tick) => {\n              const isToday = zoom === \"day\" && tick.day === today;\n              // Make room for the today pill in week and month zoom.\n              const covered =\n                todayX != null &&\n                zoom !== \"day\" &&\n                tick.x + 6 < todayX + 26 &&\n                tick.x + 6 + tick.label.length * 6.2 > todayX - 26;\n              return (\n                <div\n                  key={tick.key}\n                  className={cn(\n                    \"absolute top-[24px] flex h-[26px] items-center border-t border-l border-l-border/60 font-mono text-[10px] text-muted-foreground tabular-nums\",\n                    zoom === \"day\" ? \"justify-center\" : \"px-1.5\",\n                    tick.weekend &&\n                      \"bg-(--gantt-weekend) text-muted-foreground/60\",\n                  )}\n                  style={{ left: tick.x, width: tick.w }}\n                >\n                  <span\n                    className={cn(\n                      \"truncate\",\n                      isToday &&\n                        \"rounded-full bg-primary px-1.5 text-primary-foreground\",\n                      covered && \"opacity-0\",\n                    )}\n                  >\n                    {tick.label}\n                  </span>\n                </div>\n              );\n            })}\n            {todayX != null && zoom !== \"day\" ? (\n              <span\n                className=\"absolute bottom-[3px] z-10 -translate-x-1/2 rounded-full bg-primary px-1.5 font-mono text-[9.5px] leading-4 font-medium text-primary-foreground\"\n                style={{ left: todayX }}\n              >\n                {monthDay.format(new Date(today * DAY_MS))}\n              </span>\n            ) : null}\n          </div>\n\n          {/* Task list */}\n          <div\n            ref={labelRef}\n            data-slot=\"gantt-chart-tasks\"\n            className={cn(\n              \"sticky left-0 z-[25] border-r bg-card\",\n              scrolled && \"shadow-[6px_0_12px_-8px_rgb(0_0_0/0.25)]\",\n            )}\n            style={{ height: rows.height }}\n          >\n            {rows.list.map((row) => {\n              if (row.kind === \"group\") {\n                const open = !collapsed.has(row.name);\n                const days = row.members.reduce(\n                  (s, m) => s + (m.milestone ? 0 : m.end - m.start + 1),\n                  0,\n                );\n                const done = days\n                  ? row.members.reduce(\n                      (s, m) =>\n                        s +\n                        (m.milestone ? 0 : (m.end - m.start + 1) * m.progress),\n                      0,\n                    ) / days\n                  : 0;\n                return (\n                  <button\n                    key={row.key}\n                    type=\"button\"\n                    aria-expanded={open}\n                    data-slot=\"gantt-group\"\n                    onClick={() => toggleGroup(row.name)}\n                    className=\"flex w-full items-center gap-1.5 border-b bg-muted/35 px-2.5 text-left text-xs font-medium outline-none transition-colors hover:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-inset motion-reduce:transition-none\"\n                    style={{ height: row.h }}\n                  >\n                    <ChevronDown\n                      aria-hidden=\"true\"\n                      className={cn(\n                        \"size-3.5 shrink-0 text-muted-foreground transition-transform motion-reduce:transition-none\",\n                        !open && \"-rotate-90\",\n                      )}\n                    />\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"size-2 shrink-0 rounded-[3px]\"\n                      style={{ background: row.color }}\n                    />\n                    <span className=\"truncate\">{row.name}</span>\n                    <span className=\"font-normal text-muted-foreground tabular-nums\">\n                      {row.members.length}\n                    </span>\n                    <span className=\"ml-auto font-mono text-[10.5px] font-normal text-muted-foreground tabular-nums\">\n                      {pct(done)}\n                    </span>\n                  </button>\n                );\n              }\n              const m = row.model;\n              const id = m.task.id;\n              const late = overdueDays(live(m)) > 0;\n              return (\n                <div\n                  key={row.key}\n                  data-slot=\"gantt-task\"\n                  data-id={id}\n                  data-selected={selected === id || undefined}\n                  data-active={activeId === id || undefined}\n                  onPointerEnter={() => setHoveredId(id)}\n                  onPointerLeave={() => setHoveredId(null)}\n                  onClick={() => toggle(id)}\n                  className={cn(\n                    \"flex cursor-pointer items-center gap-2 border-b border-border/50 pr-2.5 text-xs transition-colors motion-reduce:transition-none\",\n                    grouped ? \"pl-8\" : \"pl-3\",\n                    \"hover:bg-muted/40 data-[active]:bg-muted/40 data-[selected]:bg-primary/[0.07]\",\n                  )}\n                  style={{ height: row.h }}\n                >\n                  {renderTaskLabel ? (\n                    <div className=\"flex min-w-0 flex-1 items-center\">\n                      {renderTaskLabel(m.task)}\n                    </div>\n                  ) : (\n                    <span className=\"flex min-w-0 flex-1 items-center gap-1.5\">\n                      {m.milestone ? (\n                        <span\n                          aria-hidden=\"true\"\n                          className=\"size-2 shrink-0 rotate-45 rounded-[1px]\"\n                          style={{ background: m.color }}\n                        />\n                      ) : null}\n                      <span\n                        className={cn(\n                          \"truncate\",\n                          selected === id\n                            ? \"font-medium text-foreground\"\n                            : \"text-foreground/85\",\n                        )}\n                      >\n                        {m.task.label}\n                      </span>\n                      {late ? (\n                        <AlertTriangle\n                          aria-label=\"Overdue\"\n                          className=\"size-3.5 shrink-0 text-destructive\"\n                        />\n                      ) : null}\n                    </span>\n                  )}\n                  {m.task.owner ? (\n                    <span\n                      title={m.task.owner}\n                      data-slot=\"gantt-owner\"\n                      className=\"hidden size-5 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold tracking-tight ring-1 ring-card @sm/gantt-chart:inline-flex\"\n                      style={{\n                        background: `color-mix(in oklab, ${PALETTE[hash(m.task.owner) % PALETTE.length]} 22%, var(--color-card))`,\n                        color: `color-mix(in oklab, ${PALETTE[hash(m.task.owner) % PALETTE.length]} 75%, var(--color-foreground))`,\n                      }}\n                    >\n                      {initials(m.task.owner)}\n                    </span>\n                  ) : null}\n                </div>\n              );\n            })}\n          </div>\n\n          {/* Timeline */}\n          <div\n            role=\"group\"\n            aria-label={`${scheduleLabel}: ${models.length} tasks. Use the up and down arrow keys to move between tasks${editable ? \", left and right to move a task by a day, and Shift with left and right to change its length\" : \"\"}.`}\n            data-slot=\"gantt-chart-timeline\"\n            className=\"relative\"\n            style={{ width: W, height: rows.height, ...gridBackground }}\n            onPointerLeave={() => setHoveredId(null)}\n            onBlur={(event) => {\n              if (!event.currentTarget.contains(event.relatedTarget as Node))\n                setFocusedId(null);\n            }}\n          >\n            {ticks.monthLines.map((x) => (\n              <div\n                key={x}\n                aria-hidden=\"true\"\n                className=\"absolute inset-y-0 w-px bg-border\"\n                style={{ left: x }}\n              />\n            ))}\n\n            {rows.list.map((row) =>\n              row.kind === \"group\" ? (\n                <div\n                  key={row.key}\n                  aria-hidden=\"true\"\n                  className=\"absolute inset-x-0 border-b bg-muted/35\"\n                  style={{ top: row.y, height: row.h }}\n                />\n              ) : (\n                <div\n                  key={row.key}\n                  aria-hidden=\"true\"\n                  className={cn(\n                    \"absolute inset-x-0 border-b border-border/50 transition-colors motion-reduce:transition-none\",\n                    selected === row.model.task.id\n                      ? \"bg-primary/[0.07]\"\n                      : activeId === row.model.task.id\n                        ? \"bg-muted/40\"\n                        : \"\",\n                  )}\n                  style={{ top: row.y, height: row.h }}\n                />\n              ),\n            )}\n\n            {/* Group summaries */}\n            {rows.list.map((row) => {\n              if (row.kind !== \"group\") return null;\n              const members = row.members.map(live);\n              const start = Math.min(...members.map((m) => m.start));\n              const end = Math.max(...members.map((m) => m.end));\n              const days = members.reduce(\n                (s, m) => s + (m.milestone ? 0 : m.end - m.start + 1),\n                0,\n              );\n              const done = days\n                ? members.reduce(\n                    (s, m) =>\n                      s +\n                      (m.milestone ? 0 : (m.end - m.start + 1) * m.progress),\n                    0,\n                  ) / days\n                : 0;\n              return (\n                <div\n                  key={`s:${row.key}`}\n                  aria-hidden=\"true\"\n                  data-slot=\"gantt-group-summary\"\n                  className=\"absolute h-1.5 overflow-hidden rounded-full\"\n                  style={{\n                    top: row.y + row.h / 2 - 3,\n                    left: xOf(start),\n                    width: (end - start + 1) * ppd,\n                    background: `color-mix(in oklab, ${row.color} 22%, transparent)`,\n                  }}\n                >\n                  <div\n                    className=\"h-full rounded-full\"\n                    style={{ width: pct(done), background: row.color }}\n                  />\n                </div>\n              );\n            })}\n\n            {/* Overdue slip */}\n            {taskRows.map((row) => {\n              const m = live(row.model);\n              const late = overdueDays(m);\n              if (!late || m.milestone) return null;\n              return (\n                <div\n                  key={`late:${row.key}`}\n                  aria-hidden=\"true\"\n                  data-slot=\"gantt-overdue\"\n                  className=\"absolute rounded-r-[6px] border border-l-0 border-dashed border-destructive/50\"\n                  style={{\n                    top: row.y + (ROW - BAR) / 2,\n                    height: BAR,\n                    left: xOf(m.end + 1) - 4,\n                    width: (today - m.end) * ppd - ppd / 2 + 4,\n                    backgroundImage:\n                      \"repeating-linear-gradient(135deg, color-mix(in oklab, var(--color-destructive) 22%, transparent) 0 3px, transparent 3px 7px)\",\n                  }}\n                />\n              );\n            })}\n\n            {/* Dependencies */}\n            <svg\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute inset-0 overflow-visible\"\n              width={W}\n              height={rows.height}\n            >\n              <defs>\n                {([\"idle\", \"active\", \"conflict\"] as const).map((tone) => (\n                  <marker\n                    key={tone}\n                    id={`${uid}-arrow-${tone}`}\n                    viewBox=\"0 0 6 6\"\n                    refX=\"5.5\"\n                    refY=\"3\"\n                    markerWidth=\"6\"\n                    markerHeight=\"6\"\n                    orient=\"auto\"\n                  >\n                    <path\n                      d=\"M0 0.4L5.6 3L0 5.6z\"\n                      fill={\n                        tone === \"conflict\"\n                          ? \"var(--color-destructive)\"\n                          : tone === \"active\"\n                            ? \"var(--color-foreground)\"\n                            : \"var(--color-muted-foreground)\"\n                      }\n                    />\n                  </marker>\n                ))}\n              </defs>\n              {connectors.map((c) => (\n                <path\n                  key={c.key}\n                  data-slot=\"gantt-dependency\"\n                  data-tone={c.tone}\n                  d={c.d}\n                  fill=\"none\"\n                  stroke={\n                    c.tone === \"conflict\"\n                      ? \"var(--color-destructive)\"\n                      : c.tone === \"active\"\n                        ? \"var(--color-foreground)\"\n                        : \"var(--color-muted-foreground)\"\n                  }\n                  strokeOpacity={c.tone === \"idle\" ? 0.45 : 0.85}\n                  strokeWidth={c.tone === \"idle\" ? 1 : 1.5}\n                  strokeDasharray={c.tone === \"conflict\" ? \"3 2\" : undefined}\n                  markerEnd={`url(#${uid}-arrow-${c.tone})`}\n                  className=\"transition-[stroke-opacity] duration-200 motion-reduce:transition-none\"\n                />\n              ))}\n            </svg>\n\n            {/* Today */}\n            {todayX != null ? (\n              <div\n                aria-hidden=\"true\"\n                data-slot=\"gantt-today\"\n                className=\"pointer-events-none absolute inset-y-0 z-10 w-0\"\n                style={{ left: todayX }}\n              >\n                <div className=\"absolute inset-y-0 -left-px w-[2px] bg-primary/70\" />\n                <div className=\"absolute top-0 -left-[3px] size-1.5 rounded-full bg-primary\" />\n              </div>\n            ) : null}\n\n            {/* Bars */}\n            {taskRows.map((row) => {\n              const base = row.model;\n              const m = live(base);\n              const id = m.task.id;\n              const isDragging = drag?.id === id;\n              const duration = m.end - m.start + 1;\n              const isSelected = selected === id;\n              const isActive = activeId === id;\n              const late = overdueDays(m);\n              const width = m.milestone ? 18 : duration * ppd - 2;\n              const left = m.milestone\n                ? xOf(m.start) + ppd / 2 - 9\n                : xOf(m.start) + 1;\n              const info: GanttBarInfo = {\n                start: fromDay(m.start),\n                end: fromDay(m.end),\n                duration,\n                progress: m.progress,\n                width,\n                color: m.color,\n                zoom,\n                milestone: m.milestone,\n                overdue: late > 0,\n                overdueDays: late,\n                selected: isSelected,\n                active: isActive,\n                dragging: isDragging,\n              };\n              const inside = !m.milestone && width >= 72;\n              return (\n                <React.Fragment key={id}>\n                  {isDragging && drag?.moved ? (\n                    <div\n                      aria-hidden=\"true\"\n                      className=\"pointer-events-none absolute rounded-[6px] border border-dashed border-muted-foreground/50\"\n                      style={{\n                        top: row.y + (ROW - BAR) / 2,\n                        height: BAR,\n                        left: base.milestone\n                          ? xOf(base.start) + ppd / 2 - 9\n                          : xOf(base.start) + 1,\n                        width: base.milestone\n                          ? 18\n                          : (base.end - base.start + 1) * ppd - 2,\n                      }}\n                    />\n                  ) : null}\n                  <div\n                    role=\"button\"\n                    tabIndex={id === stopId ? 0 : -1}\n                    aria-label={describe(m)}\n                    aria-pressed={isSelected}\n                    data-slot=\"gantt-bar\"\n                    data-id={id}\n                    data-milestone={m.milestone || undefined}\n                    data-overdue={late > 0 || undefined}\n                    data-selected={isSelected || undefined}\n                    data-dragging={isDragging || undefined}\n                    className={cn(\n                      \"group/bar absolute z-[5] rounded-[6px] outline-none select-none\",\n                      \"focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-card\",\n                      isSelected &&\n                        \"ring-2 ring-primary/70 ring-offset-2 ring-offset-card\",\n                      editable\n                        ? isDragging\n                          ? \"cursor-grabbing\"\n                          : \"cursor-grab\"\n                        : \"cursor-pointer\",\n                      isDragging ? \"z-20 shadow-lg\" : \"\",\n                      !isDragging &&\n                        \"transition-[left,width] duration-200 ease-out motion-reduce:transition-none\",\n                    )}\n                    style={{\n                      top: row.y + (ROW - BAR) / 2,\n                      height: BAR,\n                      left,\n                      width,\n                    }}\n                    onPointerEnter={() => setHoveredId(id)}\n                    onPointerLeave={() => setHoveredId(null)}\n                    onFocus={() => {\n                      setFocusedId(id);\n                      setTabStopId(id);\n                    }}\n                    onPointerDown={(event) =>\n                      onBarPointerDown(event, base, \"move\")\n                    }\n                    onPointerMove={onBarPointerMove}\n                    onPointerUp={() => onBarPointerUp(base)}\n                    onPointerCancel={() => setDrag(null)}\n                    onClick={() => {\n                      if (suppressClick.current) {\n                        suppressClick.current = false;\n                        return;\n                      }\n                      toggle(id);\n                    }}\n                    onKeyDown={(event) => onBarKeyDown(event, base)}\n                  >\n                    {renderBar ? (\n                      renderBar(m.task, info)\n                    ) : m.milestone ? (\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"absolute top-1/2 left-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rotate-45 rounded-[2px] ring-2 ring-card\"\n                        style={{\n                          background:\n                            m.progress >= 1 ? m.color : \"var(--color-card)\",\n                          boxShadow: `inset 0 0 0 2px ${m.color}`,\n                        }}\n                      />\n                    ) : (\n                      <>\n                        <span\n                          aria-hidden=\"true\"\n                          className={cn(\n                            \"absolute inset-0 overflow-hidden rounded-[6px] border transition-[border-color,box-shadow] duration-150 motion-reduce:transition-none\",\n                            isActive && \"shadow-sm\",\n                          )}\n                          style={{\n                            background: `color-mix(in oklab, ${m.color} 14%, var(--color-card))`,\n                            borderColor:\n                              late > 0\n                                ? \"color-mix(in oklab, var(--color-destructive) 70%, transparent)\"\n                                : `color-mix(in oklab, ${m.color} ${isActive ? 70 : 42}%, transparent)`,\n                          }}\n                        >\n                          <span\n                            className=\"absolute inset-y-0 left-0\"\n                            style={{\n                              width: pct(m.progress),\n                              background: `color-mix(in oklab, ${m.color} 36%, var(--color-card))`,\n                            }}\n                          />\n                          <span\n                            className=\"absolute inset-y-0 left-0 w-[3px]\"\n                            style={{ background: m.color }}\n                          />\n                        </span>\n                        {inside ? (\n                          // The name sticks to the visible edge while a long bar scrolls past.\n                          <span\n                            aria-hidden=\"true\"\n                            className=\"absolute inset-0 flex items-center overflow-clip rounded-[6px] pr-2\"\n                          >\n                            <span className=\"sticky left-[calc(var(--gantt-label)+0.625rem)] ml-2.5 flex min-w-0 items-baseline gap-1.5\">\n                              <span className=\"truncate text-[11px] font-medium text-foreground\">\n                                {m.task.label}\n                              </span>\n                              {width >= 132 ? (\n                                <span className=\"shrink-0 font-mono text-[10px] text-foreground/55 tabular-nums\">\n                                  {pct(m.progress)}\n                                </span>\n                              ) : null}\n                            </span>\n                          </span>\n                        ) : null}\n                      </>\n                    )}\n                    {!renderBar && !inside ? (\n                      <span\n                        aria-hidden=\"true\"\n                        className={cn(\n                          \"pointer-events-none absolute top-1/2 left-full ml-1.5 -translate-y-1/2 truncate rounded-sm bg-card/85 px-1 text-[11px] whitespace-nowrap\",\n                          m.milestone\n                            ? \"font-medium text-foreground\"\n                            : \"text-muted-foreground\",\n                        )}\n                      >\n                        {m.task.label}\n                        {m.milestone ? (\n                          <span className=\"ml-1.5 font-mono text-[10px] font-normal text-muted-foreground\">\n                            {monthDay.format(new Date(m.start * DAY_MS))}\n                          </span>\n                        ) : null}\n                      </span>\n                    ) : null}\n                    {editable && !m.milestone ? (\n                      <>\n                        <span\n                          aria-hidden=\"true\"\n                          data-slot=\"gantt-bar-handle\"\n                          className=\"absolute inset-y-0 -left-1 w-2.5 cursor-ew-resize after:absolute after:inset-y-[5px] after:left-1 after:w-[3px] after:rounded-full after:bg-foreground/50 after:opacity-0 group-hover/bar:after:opacity-100\"\n                          onPointerDown={(event) =>\n                            onBarPointerDown(event, base, \"start\")\n                          }\n                        />\n                        <span\n                          aria-hidden=\"true\"\n                          data-slot=\"gantt-bar-handle\"\n                          className=\"absolute inset-y-0 -right-1 w-2.5 cursor-ew-resize after:absolute after:inset-y-[5px] after:right-1 after:w-[3px] after:rounded-full after:bg-foreground/50 after:opacity-0 group-hover/bar:after:opacity-100\"\n                          onPointerDown={(event) =>\n                            onBarPointerDown(event, base, \"end\")\n                          }\n                        />\n                      </>\n                    ) : null}\n                  </div>\n                </React.Fragment>\n              );\n            })}\n\n            {models.length === 0 ? (\n              <p className=\"sticky left-0 py-10 text-center text-xs text-muted-foreground\">\n                No tasks to show.\n              </p>\n            ) : null}\n          </div>\n        </div>\n      </div>\n\n      <div\n        data-slot=\"gantt-chart-footer\"\n        className=\"flex flex-wrap items-center justify-between gap-x-6 gap-y-3 border-t px-5 py-3\"\n      >\n        <div\n          data-slot=\"gantt-chart-readout\"\n          aria-hidden={activeModel ? true : undefined}\n          className=\"flex min-h-9 min-w-0 flex-1 basis-60 items-center gap-3\"\n        >\n          {readout}\n        </div>\n        {showLegend ? (\n          <div\n            data-slot=\"gantt-chart-legend\"\n            aria-hidden=\"true\"\n            className=\"flex flex-wrap items-center gap-x-3.5 gap-y-1 text-[11px] text-muted-foreground\"\n          >\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span className=\"relative h-2.5 w-5 overflow-hidden rounded-[3px] border border-primary/40 bg-primary/10\">\n                <span className=\"absolute inset-y-0 left-0 w-1/2 bg-primary/35\" />\n              </span>\n              Progress\n            </span>\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span className=\"size-2 rotate-45 rounded-[1px] bg-foreground/70\" />\n              Milestone\n            </span>\n            <span className=\"inline-flex items-center gap-1.5\">\n              <span className=\"h-3 w-[2px] rounded-full bg-primary/70\" />\n              Today\n            </span>\n            {overdueCount ? (\n              <span className=\"inline-flex items-center gap-1.5\">\n                <span\n                  className=\"h-2.5 w-4 rounded-[3px] border border-dashed border-destructive/60\"\n                  style={{\n                    backgroundImage:\n                      \"repeating-linear-gradient(135deg, color-mix(in oklab, var(--color-destructive) 30%, transparent) 0 2px, transparent 2px 5px)\",\n                  }}\n                />\n                Overdue\n              </span>\n            ) : null}\n          </div>\n        ) : null}\n      </div>\n\n      <div aria-live=\"polite\" className=\"sr-only\">\n        {announcement}\n      </div>\n    </div>\n  );\n}\n\nexport { GanttChart };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/gantt-chart. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
