{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "table-of-contents",
  "title": "Table Of Contents",
  "description": "Table Of Contents from the Get IT Done design system.",
  "dependencies": [],
  "registryDependencies": [
    "https://zero-design.itdone.de/r/labels-context.json",
    "https://zero-design.itdone.de/r/recipes.json",
    "https://zero-design.itdone.de/r/utils.json",
    "https://zero-design.itdone.de/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/ui/table-of-contents.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\n\nimport { focusRing } from '@/lib/recipes';\nimport { cn } from '@/lib/utils';\nimport { useLabels } from '@/components/ui/labels-context';\n\nexport interface TableOfContentsItem {\n  // Id of the heading element in the page.\n  id: string;\n  label: React.ReactNode;\n  // Heading depth for the indent. Default 1.\n  level?: 1 | 2 | 3;\n}\n\nexport interface TableOfContentsProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {\n  items: TableOfContentsItem[];\n  // Controlled active id. Without it the active heading is tracked while scrolling.\n  activeId?: string;\n  onActiveChange?: (id: string) => void;\n  // Accessible name of the navigation landmark. Defaults to the provider text.\n  label?: string;\n  // Root margin of the observer. The default activates a heading once it reaches the upper third of the viewport.\n  rootMargin?: string;\n  // Scroll container when the page does not scroll the window.\n  scrollRoot?: Element | null;\n  // Space kept above a heading after a jump, so a sticky header does not cover it. `topbar` and `topbar-lg` follow the\n  // topbar size tokens (default `topbar`), a number is a pixel offset for custom headers, `none` disables it.\n  scrollOffset?: 'topbar' | 'topbar-lg' | 'none' | number;\n  // `brand` also colours the active entry with the brand text role. The marker and weight stay, so colour is never the only cue.\n  activeTone?: 'default' | 'brand';\n}\n\nconst offsetValue = (offset: NonNullable<TableOfContentsProps['scrollOffset']>) => {\n  if (offset === 'none') return '';\n  if (offset === 'topbar') return 'var(--size-topbar)';\n  if (offset === 'topbar-lg') return 'var(--size-topbar-lg)';\n  return `${offset}px`;\n};\n\nconst indent = { 1: 'pl-3', 2: 'pl-6', 3: 'pl-9' } as const;\n\n// Table of contents with scroll tracking. The active link carries aria-current=\"location\" and a bold weight plus a marker, not color alone.\nconst TableOfContents = React.forwardRef<HTMLElement, TableOfContentsProps>(\n  ({ className, items, activeId: activeIdProp, onActiveChange, label: labelProp, rootMargin = '0px 0px -66% 0px', scrollRoot, scrollOffset = 'topbar', activeTone = 'default', ...props }, ref) => {\n    const l = useLabels(labelProp ? { tableOfContents: labelProp } : undefined);\n    const [tracked, setTracked] = React.useState<string | undefined>(items[0]?.id);\n    const active = activeIdProp ?? tracked;\n    const onChangeRef = React.useRef(onActiveChange);\n    onChangeRef.current = onActiveChange;\n    const idsKey = items.map((item) => item.id).join('|');\n\n    React.useEffect(() => {\n      if (activeIdProp !== undefined || typeof IntersectionObserver === 'undefined') return undefined;\n      const ids = idsKey ? idsKey.split('|') : [];\n      const visible = new Set<string>();\n      const observer = new IntersectionObserver(\n        (entries) => {\n          entries.forEach((entry) => {\n            if (entry.isIntersecting) visible.add(entry.target.id);\n            else visible.delete(entry.target.id);\n          });\n          const next = ids.find((id) => visible.has(id));\n          if (next) {\n            setTracked(next);\n            onChangeRef.current?.(next);\n          }\n        },\n        { root: scrollRoot ?? null, rootMargin },\n      );\n      ids.forEach((id) => {\n        const el = document.getElementById(id);\n        if (el) observer.observe(el);\n      });\n      return () => observer.disconnect();\n    }, [idsKey, activeIdProp, rootMargin, scrollRoot]);\n\n    // The native anchor jump honours scroll-margin, so the offset also applies to deep links and keyboard activation.\n    React.useEffect(() => {\n      const value = offsetValue(scrollOffset);\n      if (!value) return undefined;\n      const targets = (idsKey ? idsKey.split('|') : []).map((id) => document.getElementById(id)).filter((el): el is HTMLElement => el !== null);\n      const previous = targets.map((el) => el.style.scrollMarginTop);\n      targets.forEach((el) => {\n        el.style.scrollMarginTop = value;\n      });\n      return () => {\n        targets.forEach((el, index) => {\n          el.style.scrollMarginTop = previous[index];\n        });\n      };\n    }, [idsKey, scrollOffset]);\n\n    return (\n      <nav ref={ref} aria-label={l.tableOfContents} className={cn('text-text-default', className)} {...props}>\n        <ul className=\"m-0 flex list-none flex-col border-0 border-l border-solid border-hairline p-0\">\n          {items.map((item) => {\n            const current = item.id === active;\n            return (\n              <li key={item.id} className=\"flex\">\n                <a\n                  href={`#${item.id}`}\n                  aria-current={current ? 'location' : undefined}\n                  onClick={() => {\n                    if (activeIdProp === undefined) setTracked(item.id);\n                    onActiveChange?.(item.id);\n                  }}\n                  className={cn(\n                    '-ml-px flex-1 rounded-item border-0 border-l-2 border-solid py-1 pr-3 underline-offset-4 hover:underline',\n                    !current && 'hover:text-foreground',\n                    indent[item.level ?? 1],\n                    current ? cn('typography-ui-semibold border-border-brand', activeTone === 'brand' ? 'text-text-brand' : 'text-foreground') : 'typography-ui border-transparent text-text-subtle',\n                    focusRing,\n                  )}\n                >\n                  {item.label}\n                </a>\n              </li>\n            );\n          })}\n        </ul>\n      </nav>\n    );\n  },\n);\nTableOfContents.displayName = 'TableOfContents';\n\nexport { TableOfContents };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}