{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "table-of-contents",
  "title": "Table Of Contents",
  "author": "AlgorizeTech",
  "description": "An interactive Table of Contents navigation block with sticky right-side positioning, real-time scroll-spy, animated Motion indicators, and section search filtering.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://avaraui.com/r/ui-codeblocks.json",
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/TableOfContentsBlock.tsx",
      "content": "\"use client\";\n\nimport { CodeBlocks } from \"@/components/custom/ui/codeblocks\";\nimport { cn } from \"@/lib/utils\";\nimport {\n\tArrowUp,\n\tBookmark,\n\tCheck,\n\tListFilter,\n\tSparkles,\n\tX,\n} from \"lucide-react\";\nimport React, {\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { springLinear } from \"./motion-curves\";\n\n// The active pill glides between rows on a spring (stiffness 350, damping 30),\n// as a CSS `linear()` curve generated from the same numbers.\nconst PILL_SPRING = springLinear({ stiffness: 350, damping: 30 });\n\nexport interface TOCHeading {\n\tid: string;\n\ttitle: string;\n\tlevel: 1 | 2 | 3;\n}\n\nexport interface TOCItem {\n\tid: string;\n\ttitle: string;\n\tlevel?: 1 | 2 | 3;\n\t/** One paragraph, or several rendered in order. */\n\tdescription?: string | string[];\n\tcodeSnippet?: string;\n\tbadge?: string;\n}\n\nexport interface TableOfContentsProps\n\textends React.HTMLAttributes<HTMLDivElement> {\n\titems?: TOCItem[];\n\theadings?: TOCHeading[];\n\tactiveId?: string;\n\tonSelectHeading?: (id: string) => void;\n\t/** Custom theme accent color (hex, rgb, oklch, or var(--token)) */\n\tcolor?: string;\n\tshowProgress?: boolean;\n\tshowSearch?: boolean;\n\tchildren?: React.ReactNode;\n\tsidebarTitle?: string;\n}\n\n/**\n * The nearest scrollable ancestor, or the window. The block is often mounted\n * inside a scroll container (docs previews, dashboard panes), and every scroll\n * action — spy, jump-to-heading, back to top — has to target the same box.\n */\nconst findScrollParent = (node: HTMLElement | null): HTMLElement | Window => {\n\tif (!node) return window;\n\tlet parent = node.parentElement;\n\twhile (parent) {\n\t\tconst style = window.getComputedStyle(parent);\n\t\tif (\n\t\t\t(style.overflowY === \"auto\" || style.overflowY === \"scroll\") &&\n\t\t\tparent.scrollHeight > parent.clientHeight\n\t\t) {\n\t\t\treturn parent;\n\t\t}\n\t\tparent = parent.parentElement;\n\t}\n\treturn window;\n};\n\nconst DEFAULT_ITEMS: TOCItem[] = [\n\t{\n\t\tid: \"overview\",\n\t\ttitle: \"Overview & Features\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"The Table of Contents component parses document structure and renders a sticky navigation panel with real-time active section indicators. The active indicator pill glides across items on a spring as you scroll, with no animation library behind it. Includes a top scroll progress bar and section search filter out of the box.\",\n\t\t\t\"Long-form pages — documentation, changelogs, legal text, knowledge-base articles — are hard to navigate once they pass a couple of screens. The reader loses track of where they are and how much is left. A persistent outline solves both: the highlighted entry answers \\\"where am I\\\", the progress bar answers \\\"how far to go\\\", and every entry is a one-click jump.\",\n\t\t\t\"The component is deliberately layout-agnostic. It works against the window scroll on a normal page, but it also detects the nearest scrollable ancestor, so it behaves identically inside a dashboard pane, a modal body, or a documentation preview with its own overflow container.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"installation\",\n\t\ttitle: \"Installation & Setup\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"Integrate the component into your Next.js App Router or React application in seconds using the shadcn CLI registry command below. The one peer dependency, Lucide React, is handled automatically during installation.\",\n\t\t\t\"The CLI copies the source into your project rather than adding a package, so the block is yours to edit. Rename the sidebar title, swap the icons, or change the spacing scale — nothing is hidden behind an abstraction you cannot reach.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"prerequisites\",\n\t\ttitle: \"Prerequisites\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"Requires Node.js 18+, React 18 or 19, Next.js 14+ (App Router), and Tailwind CSS v4. No animation library is needed.\",\n\t\t\t\"The block is a client component: it reads scroll position and element geometry, neither of which exists on the server. Keep it out of server-only files and give it a \\\"use client\\\" boundary — the shipped file already declares one.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"package-install\",\n\t\ttitle: \"Package Installation\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"Run the official shadcn CLI command to add the Table of Contents component directly to your component registry.\",\n\t\t\t\"The command writes the block, its theme helper, and any missing utilities, then reports which files it touched so you can review them before committing.\",\n\t\t],\n\t\tcodeSnippet:\n\t\t\t\"npx shadcn@latest add @avara-ui/table-of-contents\",\n\t},\n\t{\n\t\tid: \"configuration\",\n\t\ttitle: \"Configuration & Customization\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"Customize sidebar placement, scroll offsets, progress bar visibility, and search filter behavior via props. The component inherits your site's global CSS theme tokens and primary color variables seamlessly.\",\n\t\t\t\"Every visual choice is expressed through a single CSS variable, --toc-primary, which is derived from the color prop. Because the pill, the progress bar, the active row tint, and the section markers all read that one token, a theme change is a one-line change and the pieces can never drift out of sync.\",\n\t\t\t\"When the outline is driven by an external source of truth — a router, a scroll library, a CMS — pass activeId and onSelectHeading and the built-in scroll spy steps aside entirely.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"tailwind-setup\",\n\t\ttitle: \"Tailwind CSS v4 Setup\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"Ensure headings include offset classes like scroll-m-24 to prevent fixed site headers from overlapping heading targets during anchor link navigation.\",\n\t\t\t\"The offset should match the height of whatever is pinned above the content. A 64px header wants roughly scroll-m-20; a two-row header with a tab bar wants scroll-m-32. The block's own click handler applies a matching offset, so keyboard users, deep links, and sidebar clicks all land in the same place.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"theme-tokens\",\n\t\ttitle: \"Theme Tokens & Variables\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"Seamlessly binds to var(--primary) accent colors or custom color props for dynamic theme switching in light and dark modes.\",\n\t\t\t\"The color prop accepts a design-token name such as \\\"emerald\\\", any CSS color (hex, rgb, hsl, oklch), or a var(--token) reference. Tints are produced with color-mix(), so a single opaque color yields the 10–15% washes used for backgrounds without a second value being supplied.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"scroll-behavior\",\n\t\ttitle: \"Scroll Spy & Progress\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"The active entry is the last heading whose top has crossed a reading line a little below the top edge of the scroll box. Reading the outline this way matches how people actually scan a page: the section you are in is the one whose heading you most recently passed.\",\n\t\t\t\"Two edge cases get special handling. At the very end of the scroll range the final heading becomes active, even though its top may never reach the reading line. And after a click-initiated jump the spy pauses until the smooth scroll settles, so a heading that the box cannot scroll far enough to reach still keeps the highlight the reader chose.\",\n\t\t\t\"Progress is the scroll offset expressed as a share of the total scrollable distance, so it reaches 100% precisely when the box hits its end rather than a screen early.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"usage-examples\",\n\t\ttitle: \"Usage & Code Examples\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"Pass a structured items array containing section titles, descriptions, and code snippets to generate structured document layouts effortlessly.\",\n\t\t\t\"Each item carries an id, a title, and an optional level from 1 to 3. Level-two and level-three entries indent in the sidebar and render as subsections in the body, so a single flat array is enough to describe a nested outline — no tree structure to build or keep in sync.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"custom-content\",\n\t\ttitle: \"Bringing Your Own Content\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"When the page already has its own markup, pass it as children and supply a headings array instead of items. The sidebar still spies, filters, and jumps; it simply stops rendering the body for you. The only contract is that each heading id exists on an element in the document.\",\n\t\t\t\"This is the mode to reach for with MDX, CMS output, or any content pipeline that produces HTML: generate the heading list from the same source and hand both to the block.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"controlled-mode\",\n\t\ttitle: \"Controlled Active State\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"Supply activeId to take over the highlight entirely. The scroll spy is skipped while the prop is set, and onSelectHeading reports every click so the parent can update its own state, push a route, or record analytics before deciding what becomes active.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"accessibility\",\n\t\ttitle: \"Accessibility & ARIA\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"Built with WCAG 2.1 compliance using semantic <nav> landmarks, ARIA labels, full keyboard navigation focus states, and screen reader announcements.\",\n\t\t\t\"Every entry is a real button, so it is reachable with Tab and activated with Enter or Space without any custom key handling. The sidebar is wrapped in a labelled <nav> landmark, which lets screen-reader users jump straight to it from the landmark list and skip past it just as easily.\",\n\t\t\t\"Motion is limited to the indicator pill and the progress bar. Both are decorative — the active state is also conveyed by weight and color — so the outline stays fully usable when animations are reduced or unavailable.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"performance\",\n\t\ttitle: \"Performance & Bundle Size\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"The block adds a single scroll listener, registered as passive so it never blocks the compositor, and the listener does nothing more than a handful of getBoundingClientRect reads and one state update. Heading elements are looked up by id on each pass, which keeps the component correct when content is added or removed at runtime without requiring a resize observer.\",\n\t\t\t\"There is no animation library to ship. The indicator pill's glide is a single Web Animations API call per move, eased along a spring curve precomputed as CSS linear(), so the block costs nothing beyond its own code and Lucide's icons.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"ssr-hydration\",\n\t\ttitle: \"Server Rendering & Hydration\",\n\t\tlevel: 2,\n\t\tdescription: [\n\t\t\t\"On the server the block renders its full markup — sidebar, progress bar, body sections — with the first heading marked active and progress at 0%. Nothing depends on window at render time, so there is no hydration mismatch and the outline is present in the initial HTML for crawlers and for readers on slow connections.\",\n\t\t\t\"Once hydrated, the first scroll pass runs immediately and corrects the active heading if the page loaded part-way down, for example from a deep link with a hash fragment.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"troubleshooting\",\n\t\ttitle: \"Troubleshooting\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"If the highlight never moves, the heading ids in the sidebar do not match ids in the document; open the inspector and compare them character for character. If jumps land a little too high or low, the scroll-margin on the headings and the offset in the click handler disagree. If Back to Top appears to do nothing, the block is inside a scroll container the parent page cannot see — the component resolves that container itself, so check that the container really is the element with overflow set.\",\n\t\t],\n\t},\n\t{\n\t\tid: \"faq\",\n\t\ttitle: \"Frequently Asked Questions\",\n\t\tlevel: 1,\n\t\tdescription: [\n\t\t\t\"Can the sidebar sit on the right? Yes — the layout is a 12-column grid, so swapping the column order of the two children moves it. Can it collapse on desktop? Wrap the sidebar in your own disclosure; the block does not impose one. Does it work with hash links? A deep link scrolls the browser to the heading, and the first spy pass then highlights it.\",\n\t\t\t\"Does search filter the body too? No — the filter narrows the sidebar only, so the reader's place on the page is never disturbed while they look for a section. Clearing the field restores the full outline.\",\n\t\t],\n\t},\n];\n\nexport function TableOfContentsBlock({\n\titems,\n\theadings: rawHeadings,\n\tactiveId: externalActiveId,\n\tonSelectHeading,\n\tcolor = \"var(--primary)\",\n\tshowProgress = true,\n\tshowSearch = true,\n\tchildren,\n\tsidebarTitle = \"On this page\",\n\tclassName,\n\t...props\n}: TableOfContentsProps) {\n\t// Normalize items array or fall back to default items\n\tconst displayItems = useMemo<TOCItem[]>(() => {\n\t\tif (items && items.length > 0) return items;\n\t\tif (rawHeadings && rawHeadings.length > 0) {\n\t\t\treturn rawHeadings.map((h) => ({\n\t\t\t\tid: h.id,\n\t\t\t\ttitle: h.title,\n\t\t\t\tlevel: h.level,\n\t\t\t}));\n\t\t}\n\t\treturn DEFAULT_ITEMS;\n\t}, [items, rawHeadings]);\n\n\tconst headings = useMemo(() => {\n\t\treturn displayItems.map((item) => ({\n\t\t\tid: item.id,\n\t\t\ttitle: item.title,\n\t\t\tlevel: item.level || 1,\n\t\t}));\n\t}, [displayItems]);\n\n\tconst [spiedActiveId, setActiveId] = useState<string>(\n\t\theadings[0]?.id || \"\"\n\t);\n\t// A supplied `activeId` takes precedence; otherwise the scroll spy decides.\n\tconst activeId = externalActiveId || spiedActiveId;\n\tconst [scrollProgress, setScrollProgress] = useState(0);\n\tconst [searchQuery, setSearchQuery] = useState(\"\");\n\tconst [copiedId, setCopiedId] = useState<string | null>(null);\n\tconst contentRef = useRef<HTMLDivElement>(null);\n\tconst navRef = useRef<HTMLElement>(null);\n\t// Set while a click-initiated smooth scroll is in flight. The spy stays\n\t// quiet until it lands, so a heading near the end of the page — where the\n\t// scroll can stop short of it — keeps the highlight the user just chose.\n\tconst scrollLockRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n\t// Auto scroll-spy & progress calculation (supports window scroll & container scroll)\n\tuseEffect(() => {\n\t\tconst scrollContainer = findScrollParent(contentRef.current);\n\n\t\tconst handleScroll = () => {\n\t\t\tlet scrollTop: number;\n\t\t\tlet totalHeight: number;\n\n\t\t\tif (scrollContainer === window) {\n\t\t\t\tscrollTop = window.scrollY;\n\t\t\t\ttotalHeight = document.documentElement.scrollHeight - window.innerHeight;\n\t\t\t} else {\n\t\t\t\tconst containerEl = scrollContainer as HTMLElement;\n\t\t\t\tscrollTop = containerEl.scrollTop;\n\t\t\t\ttotalHeight = containerEl.scrollHeight - containerEl.clientHeight;\n\t\t\t}\n\n\t\t\tif (totalHeight > 0) {\n\t\t\t\tconst currentProgress = (scrollTop / totalHeight) * 100;\n\t\t\t\tsetScrollProgress(Math.min(100, Math.max(0, currentProgress)));\n\t\t\t}\n\n\t\t\t// Scroll spy headings\n\t\t\tif (!externalActiveId && headings.length > 0 && !scrollLockRef.current) {\n\t\t\t\tconst headingElements = headings\n\t\t\t\t\t.map((h) => document.getElementById(h.id))\n\t\t\t\t\t.filter(Boolean) as HTMLElement[];\n\t\t\t\tif (headingElements.length === 0) return;\n\n\t\t\t\t// Once the box is scrolled to the end, the remaining headings all sit\n\t\t\t\t// inside the last viewport and their tops can never cross the\n\t\t\t\t// activation line — so the highlight would stall a few items short\n\t\t\t\t// of the bottom. At the end, the last heading is the one being read.\n\t\t\t\tconst atBottom = totalHeight > 0 && scrollTop >= totalHeight - 2;\n\t\t\t\tif (atBottom) {\n\t\t\t\t\tsetActiveId(headingElements[headingElements.length - 1].id);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst scrollPosition = scrollTop + 120;\n\t\t\t\tlet nextId = headingElements[0].id;\n\t\t\t\tfor (let i = headingElements.length - 1; i >= 0; i--) {\n\t\t\t\t\tconst el = headingElements[i];\n\t\t\t\t\tconst elementTop =\n\t\t\t\t\t\tscrollContainer === window\n\t\t\t\t\t\t\t? el.offsetTop\n\t\t\t\t\t\t\t: el.getBoundingClientRect().top -\n\t\t\t\t\t\t\t  (scrollContainer as HTMLElement).getBoundingClientRect().top +\n\t\t\t\t\t\t\t  (scrollContainer as HTMLElement).scrollTop;\n\n\t\t\t\t\tif (elementTop <= scrollPosition) {\n\t\t\t\t\t\tnextId = el.id;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetActiveId(nextId);\n\t\t\t}\n\t\t};\n\n\t\tscrollContainer.addEventListener(\"scroll\", handleScroll as EventListener, {\n\t\t\tpassive: true,\n\t\t});\n\t\thandleScroll();\n\t\treturn () =>\n\t\t\tscrollContainer.removeEventListener(\n\t\t\t\t\"scroll\",\n\t\t\t\thandleScroll as EventListener\n\t\t\t);\n\t}, [headings, externalActiveId]);\n\n\t// Smooth-scroll the box to `top`, holding the spy off until it lands.\n\t// `scrollend` releases the hold as soon as the scroll settles; the timeout\n\t// covers browsers without the event. When the box is already there (or the\n\t// target is past the end and it can't move) nothing is armed, so a manual\n\t// scroll right after the click is not ignored.\n\tconst smoothScrollTo = (scrollContainer: HTMLElement | Window, top: number) => {\n\t\tconst current =\n\t\t\tscrollContainer === window\n\t\t\t\t? window.scrollY\n\t\t\t\t: (scrollContainer as HTMLElement).scrollTop;\n\t\tconst max =\n\t\t\tscrollContainer === window\n\t\t\t\t? document.documentElement.scrollHeight - window.innerHeight\n\t\t\t\t: (scrollContainer as HTMLElement).scrollHeight -\n\t\t\t\t  (scrollContainer as HTMLElement).clientHeight;\n\t\tconst target = Math.min(Math.max(top, 0), Math.max(max, 0));\n\n\t\tif (scrollLockRef.current) clearTimeout(scrollLockRef.current);\n\t\tconst release = () => {\n\t\t\tif (scrollLockRef.current) clearTimeout(scrollLockRef.current);\n\t\t\tscrollLockRef.current = null;\n\t\t\tscrollContainer.removeEventListener(\"scrollend\", release);\n\t\t};\n\t\tif (Math.abs(target - current) >= 1) {\n\t\t\tscrollContainer.addEventListener(\"scrollend\", release, { once: true });\n\t\t\tscrollLockRef.current = setTimeout(release, 1000);\n\t\t}\n\t\tscrollContainer.scrollTo({ top: target, behavior: \"smooth\" });\n\t};\n\n\tuseEffect(\n\t\t() => () => {\n\t\t\tif (scrollLockRef.current) clearTimeout(scrollLockRef.current);\n\t\t},\n\t\t[],\n\t);\n\n\t// The sidebar list has its own scroll box. As the reader moves down the\n\t// page the highlight can drift out of that box; nudge the list so the active\n\t// entry stays in view. Only the list is scrolled — scrollIntoView would also\n\t// move every scrollable ancestor, including the page itself.\n\tuseEffect(() => {\n\t\tconst nav = navRef.current;\n\t\tif (!nav || !activeId) return;\n\t\tconst item = nav.querySelector<HTMLElement>(\n\t\t\t`[data-toc-id=\"${CSS.escape(activeId)}\"]`,\n\t\t);\n\t\tif (!item) return;\n\n\t\tconst navRect = nav.getBoundingClientRect();\n\t\tconst itemRect = item.getBoundingClientRect();\n\t\tconst itemTop = itemRect.top - navRect.top + nav.scrollTop;\n\t\tconst itemBottom = itemTop + itemRect.height;\n\t\tconst padding = 12;\n\n\t\tif (itemTop < nav.scrollTop + padding) {\n\t\t\tnav.scrollTo({ top: itemTop - padding, behavior: \"smooth\" });\n\t\t} else if (itemBottom > nav.scrollTop + nav.clientHeight - padding) {\n\t\t\tnav.scrollTo({\n\t\t\t\ttop: itemBottom - nav.clientHeight + padding,\n\t\t\t\tbehavior: \"smooth\",\n\t\t\t});\n\t\t}\n\t}, [activeId]);\n\n\t// Filter headings by search query\n\tconst filteredHeadings = useMemo(() => {\n\t\tif (!searchQuery.trim()) return headings;\n\t\treturn headings.filter((h) =>\n\t\t\th.title.toLowerCase().includes(searchQuery.toLowerCase())\n\t\t);\n\t}, [headings, searchQuery]);\n\n\t// The pill lives in the active row, so it is always where it belongs; when\n\t// that row changes (or moves, as the filter adds and removes rows) it is\n\t// drawn from where it was and springs home. Positions are in px from the top\n\t// of the nav's scroll content, which scrolling never changes.\n\tconst pillRef = useRef<HTMLDivElement>(null);\n\t// Where the pill last came to rest — the \"from\" of the next move.\n\tconst pillRestRef = useRef<number | null>(null);\n\tconst pillMotionRef = useRef<{ animation: Animation; offset: number } | null>(\n\t\tnull,\n\t);\n\tuseLayoutEffect(() => {\n\t\tconst pill = pillRef.current;\n\t\tconst row = pill?.parentElement;\n\t\tif (!pill || !row) {\n\t\t\t// Filtered out: the pill reappears in place, without a glide.\n\t\t\tpillRestRef.current = null;\n\t\t\tpillMotionRef.current = null;\n\t\t\treturn;\n\t\t}\n\t\tconst restingTop = () => row.offsetTop + pill.offsetTop;\n\t\tconst rest = restingTop();\n\t\tconst before = pillRestRef.current;\n\t\tpillRestRef.current = rest;\n\n\t\tif (before !== null) {\n\t\t\t// Where the pill is on screen right now: its last resting place,\n\t\t\t// plus whatever is left of a glide still in flight.\n\t\t\tlet shown = before;\n\t\t\tconst inFlight = pillMotionRef.current;\n\t\t\tif (inFlight) {\n\t\t\t\tconst progress = inFlight.animation.effect?.getComputedTiming().progress;\n\t\t\t\tif (progress != null) shown += inFlight.offset * (1 - progress);\n\t\t\t\tinFlight.animation.cancel();\n\t\t\t}\n\t\t\tconst offset = shown - rest;\n\t\t\tpillMotionRef.current =\n\t\t\t\tMath.abs(offset) < 0.5\n\t\t\t\t\t? null\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tanimation: pill.animate(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t{ transform: `translateY(${offset}px)` },\n\t\t\t\t\t\t\t\t\t{ transform: \"translateY(0px)\" },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t{ duration: PILL_SPRING.duration, easing: PILL_SPRING.easing },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\toffset,\n\t\t\t\t\t\t};\n\t\t}\n\n\t\t// Layout can also move without a render — the sidebar appearing at the\n\t\t// lg breakpoint, a web font swapping in. Keep the resting place current.\n\t\tconst observer = new ResizeObserver(() => {\n\t\t\tpillRestRef.current = restingTop();\n\t\t});\n\t\tif (navRef.current) observer.observe(navRef.current);\n\t\tobserver.observe(row);\n\t\treturn () => observer.disconnect();\n\t}, [activeId, filteredHeadings]);\n\n\t// Smooth scroll to heading (handles both Window & Container Scroll)\n\tconst scrollToHeading = (id: string) => {\n\t\tsetActiveId(id);\n\t\tonSelectHeading?.(id);\n\n\t\tconst el = document.getElementById(id);\n\t\tif (!el) return;\n\n\t\tconst scrollContainer = findScrollParent(contentRef.current);\n\t\tif (scrollContainer === window) {\n\t\t\tconst yOffset = -90;\n\t\t\tconst y =\n\t\t\t\tel.getBoundingClientRect().top + window.pageYOffset + yOffset;\n\t\t\tsmoothScrollTo(window, y);\n\t\t} else {\n\t\t\tconst container = scrollContainer as HTMLElement;\n\t\t\tconst containerRect = container.getBoundingClientRect();\n\t\t\tconst elRect = el.getBoundingClientRect();\n\t\t\tconst relativeTop = elRect.top - containerRect.top + container.scrollTop;\n\t\t\tsmoothScrollTo(container, relativeTop - 20);\n\t\t}\n\t};\n\n\t// Scroll whichever box actually scrolls — `window.scrollTo` is a no-op when\n\t// the block sits inside an overflow container.\n\tconst scrollToTop = () => {\n\t\tsmoothScrollTo(findScrollParent(contentRef.current), 0);\n\t\tsetActiveId(headings[0]?.id || \"\");\n\t\tif (headings[0]) onSelectHeading?.(headings[0].id);\n\t};\n\n\tconst copyHeadingLink = (id: string, e: React.MouseEvent) => {\n\t\te.stopPropagation();\n\t\tconst url = `${window.location.origin}${window.location.pathname}#${id}`;\n\t\tnavigator.clipboard.writeText(url);\n\t\tsetCopiedId(id);\n\t\tsetTimeout(() => setCopiedId(null), 2000);\n\t};\n\n\t// Resolve accent color token or custom color string\n\tconst resolvedColor = useMemo(() => {\n\t\tif (!color) return \"var(--primary)\";\n\t\tif (\n\t\t\tcolor === \"primary\" ||\n\t\t\tcolor.startsWith(\"var(\") ||\n\t\t\tcolor.startsWith(\"#\") ||\n\t\t\tcolor.startsWith(\"rgb\") ||\n\t\t\tcolor.startsWith(\"hsl\") ||\n\t\t\tcolor.startsWith(\"oklch\")\n\t\t) {\n\t\t\treturn color === \"primary\" ? \"var(--primary)\" : color;\n\t\t}\n\t\t// If named color like \"blue\", \"emerald\", \"violet\" etc., resolve to hex or CSS variable\n\t\tconst colorMap: Record<string, string> = {\n\t\t\tblue: \"#3b82f6\",\n\t\t\tindigo: \"#6366f1\",\n\t\t\tviolet: \"#8b5cf6\",\n\t\t\tpurple: \"#a855f7\",\n\t\t\tpink: \"#ec4899\",\n\t\t\trose: \"#f43f5e\",\n\t\t\tred: \"#ef4444\",\n\t\t\torange: \"#f97316\",\n\t\t\tamber: \"#f59e0b\",\n\t\t\tyellow: \"#eab308\",\n\t\t\temerald: \"#10b981\",\n\t\t\tgreen: \"#22c55e\",\n\t\t\tteal: \"#14b8a6\",\n\t\t\tcyan: \"#06b6d4\",\n\t\t\tsky: \"#0ea5e9\",\n\t\t};\n\t\treturn colorMap[color] || color;\n\t}, [color]);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={cn(\n\t\t\t\t\"w-full grid grid-cols-1 lg:grid-cols-12 gap-8 items-start relative\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tstyle={{ \"--toc-primary\": resolvedColor } as React.CSSProperties}\n\t\t\t{...props}\n\t\t>\n\t\t\t{/* MOBILE TOP BAR (DYNAMIC ACTIVE HEADING TITLE ON SCROLL) */}\n\t\t\t<div className=\"lg:hidden col-span-1 border border-border/80 bg-card/95 rounded-2xl px-4 py-3 shadow-sm flex items-center justify-between sticky top-2 z-30 backdrop-blur-md transition-all\">\n\t\t\t\t<div className=\"flex items-center gap-2.5 min-w-0\">\n\t\t\t\t\t<ListFilter className=\"w-4 h-4 shrink-0\" style={{ color: \"var(--toc-primary)\" }} />\n\t\t\t\t\t<div className=\"flex flex-col min-w-0\">\n\t\t\t\t\t\t<span className=\"text-[10px] font-extrabold uppercase tracking-wider text-muted-foreground\">\n\t\t\t\t\t\t\t{sidebarTitle}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span className=\"text-xs font-semibold text-foreground truncate transition-all\">\n\t\t\t\t\t\t\t{headings.find((h) => h.id === activeId)?.title || headings[0]?.title}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<span\n\t\t\t\t\tclassName=\"text-[11px] font-semibold font-mono tabular-nums px-2 py-0.5 rounded-full shrink-0\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tcolor: \"var(--toc-primary)\",\n\t\t\t\t\t\tbackgroundColor: \"color-mix(in srgb, var(--toc-primary) 15%, transparent)\",\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{Math.round(scrollProgress)}%\n\t\t\t\t</span>\n\t\t\t</div>\n\n\t\t\t{/* STICKY LEFT-SIDE TABLE OF CONTENTS SIDEBAR */}\n\t\t\t<div className=\"hidden lg:block lg:col-span-4 sticky top-4 shrink-0\">\n\t\t\t\t<div className=\"w-full rounded-2xl border border-border/80 bg-card p-5 shadow-sm flex flex-col gap-4\">\n\t\t\t\t\t{/* Header Title & Progress Bar */}\n\t\t\t\t\t<div className=\"flex flex-col gap-2.5 pb-3 border-b border-border/60\">\n\t\t\t\t\t\t<div className=\"flex items-center justify-between\">\n\t\t\t\t\t\t\t<span className=\"text-xs font-extrabold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5\">\n\t\t\t\t\t\t\t\t<Bookmark className=\"w-3.5 h-3.5\" style={{ color: \"var(--toc-primary)\" }} />\n\t\t\t\t\t\t\t\t{sidebarTitle}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t<span className=\"text-[11px] font-semibold font-mono tabular-nums\" style={{ color: \"var(--toc-primary)\" }}>\n\t\t\t\t\t\t\t\t{Math.round(scrollProgress)}%\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t{showProgress && (\n\t\t\t\t\t\t\t<div className=\"w-full h-1.5 rounded-full bg-muted overflow-hidden relative\">\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName=\"h-full rounded-full origin-left\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\twidth: `${scrollProgress}%`,\n\t\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--toc-primary)\",\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\n\t\t\t\t\t{/* Optional Search Filter Input */}\n\t\t\t\t\t{showSearch && (\n\t\t\t\t\t\t<div className=\"relative\">\n\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\tplaceholder=\"Filter sections...\"\n\t\t\t\t\t\t\t\tvalue={searchQuery}\n\t\t\t\t\t\t\t\tonChange={(e) => setSearchQuery(e.target.value)}\n\t\t\t\t\t\t\t\tclassName=\"w-full h-8 px-3 rounded-xl bg-muted/60 border border-border/60 text-xs text-foreground placeholder:text-muted-foreground outline-none transition-all focus:border-[var(--toc-primary)]\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{searchQuery && (\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\tonClick={() => setSearchQuery(\"\")}\n\t\t\t\t\t\t\t\t\tclassName=\"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground text-xs\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<X className=\"w-3 h-3\" />\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\n\t\t\t\t\t{/* Navigation List */}\n\t\t\t\t\t<nav ref={navRef} aria-label=\"Table of contents\" className=\"relative py-1 flex flex-col gap-1 max-h-[calc(100vh-280px)] overflow-y-auto pr-1\">\n\t\t\t\t\t\t{/* Vertical Track Line */}\n\t\t\t\t\t\t<div className=\"absolute left-[11px] top-2 bottom-2 w-0.5 bg-border/60 rounded-full pointer-events-none\" />\n\n\t\t\t\t\t\t{filteredHeadings.map((heading) => {\n\t\t\t\t\t\t\tconst isActive = activeId === heading.id;\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={heading.id}\n\t\t\t\t\t\t\t\t\tdata-toc-id={heading.id}\n\t\t\t\t\t\t\t\t\tclassName=\"relative flex items-center group\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{/* Active Indicator Pill */}\n\t\t\t\t\t\t\t\t\t{isActive && (\n\t\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\t\tref={pillRef}\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"absolute left-[10px] w-1 h-5 rounded-full z-20\"\n\t\t\t\t\t\t\t\t\t\t\tstyle={{ backgroundColor: \"var(--toc-primary)\" }}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t)}\n\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonClick={() => scrollToHeading(heading.id)}\n\t\t\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\t\t\"w-full text-left pl-6 pr-8 py-1.5 rounded-xl text-xs font-semibold transition-all duration-200 cursor-pointer relative z-10 flex items-center justify-between group\",\n\t\t\t\t\t\t\t\t\t\t\theading.level === 2 && \"pl-9 text-[11.5px] font-medium\",\n\t\t\t\t\t\t\t\t\t\t\theading.level === 3 && \"pl-12 text-[11px] font-normal\",\n\t\t\t\t\t\t\t\t\t\t\tisActive\n\t\t\t\t\t\t\t\t\t\t\t\t? \"font-semibold\"\n\t\t\t\t\t\t\t\t\t\t\t\t: \"text-muted-foreground hover:text-foreground hover:bg-muted/40\"\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\t\t\t\t\tisActive\n\t\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcolor: \"var(--toc-primary)\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbackgroundColor: \"color-mix(in srgb, var(--toc-primary) 12%, transparent)\",\n\t\t\t\t\t\t\t\t\t\t\t\t  }\n\t\t\t\t\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<span className=\"truncate\">{heading.title}</span>\n\n\t\t\t\t\t\t\t\t\t\t{/* Quick Link Copy Button on Hover */}\n\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\tonClick={(e) => copyHeadingLink(heading.id, e)}\n\t\t\t\t\t\t\t\t\t\t\ttitle=\"Copy link to heading\"\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"opacity-0 group-hover:opacity-100 text-[10px] text-muted-foreground transition-opacity shrink-0 ml-2\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{copiedId === heading.id ? (\n\t\t\t\t\t\t\t\t\t\t\t\t<Check className=\"w-3 h-3 text-emerald-500\" />\n\t\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t\t\"#\"\n\t\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})}\n\t\t\t\t\t</nav>\n\n\t\t\t\t\t{/* Back to Top Quick Action */}\n\t\t\t\t\t<div className=\"pt-2 border-t border-border/60 flex items-center justify-between text-[11px] font-semibold text-muted-foreground\">\n\t\t\t\t\t\t<span>{filteredHeadings.length} Sections</span>\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tonClick={scrollToTop}\n\t\t\t\t\t\t\tclassName=\"flex items-center gap-1 hover:underline transition-all cursor-pointer\"\n\t\t\t\t\t\t\tstyle={{ color: \"var(--toc-primary)\" }}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ArrowUp className=\"w-3 h-3\" /> Back to Top\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t{/* MAIN RIGHT CONTENT AREA */}\n\t\t\t<div\n\t\t\t\tref={contentRef}\n\t\t\t\tclassName=\"lg:col-span-8 flex flex-col gap-6 min-w-0\"\n\t\t\t>\n\t\t\t\t{children || (\n\t\t\t\t\t<div className=\"prose prose-zinc dark:prose-invert max-w-none space-y-10\">\n\t\t\t\t\t\t{displayItems.map((item) => {\n\t\t\t\t\t\t\tconst level = item.level || 1;\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<section\n\t\t\t\t\t\t\t\t\tkey={item.id}\n\t\t\t\t\t\t\t\t\tid={item.id}\n\t\t\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\t\t\"scroll-m-24 space-y-3\",\n\t\t\t\t\t\t\t\t\t\tlevel === 2 && \"pl-4 border-l-2 space-y-2\"\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\tstyle={level === 2 ? { borderColor: \"color-mix(in srgb, var(--toc-primary) 40%, transparent)\" } : {}}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{level === 1 ? (\n\t\t\t\t\t\t\t\t\t\t<h2 className=\"text-lg sm:text-2xl font-extrabold text-foreground tracking-tight flex items-center gap-2.5 sm:gap-3\">\n\t\t\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"p-1.5 sm:p-2 rounded-xl border flex items-center justify-center shrink-0 shadow-xs\"\n\t\t\t\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\t\t\t\tborderColor: \"color-mix(in srgb, var(--toc-primary) 30%, transparent)\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tbackgroundColor: \"color-mix(in srgb, var(--toc-primary) 10%, transparent)\",\n\t\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<Sparkles className=\"w-3.5 h-3.5 sm:w-4 sm:h-4\" style={{ color: \"var(--toc-primary)\" }} />\n\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t\t{item.title}\n\t\t\t\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t<h3 className=\"text-base sm:text-lg font-semibold text-foreground\">\n\t\t\t\t\t\t\t\t\t\t\t{item.title}\n\t\t\t\t\t\t\t\t\t\t</h3>\n\t\t\t\t\t\t\t\t\t)}\n\n\t\t\t\t\t\t\t\t\t{item.description &&\n\t\t\t\t\t\t\t\t\t\t(Array.isArray(item.description)\n\t\t\t\t\t\t\t\t\t\t\t? item.description\n\t\t\t\t\t\t\t\t\t\t\t: [item.description]\n\t\t\t\t\t\t\t\t\t\t).map((paragraph, i) => (\n\t\t\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\t\t\tkey={i}\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"text-sm text-muted-foreground leading-relaxed\"\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{paragraph}\n\t\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t\t))}\n\n\t\t\t\t\t\t\t\t\t{item.codeSnippet && (\n\t\t\t\t\t\t\t\t\t\t<div className=\"rounded-2xl border border-border bg-muted/70 overflow-hidden shadow-xs [&>div]:border-t-0\">\n\t\t\t\t\t\t\t\t\t\t\t<CodeBlocks code={item.codeSnippet} language=\"bash\" />\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t</section>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t})}\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default TableOfContentsBlock;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/TableOfContentsBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/motion-curves.ts",
      "content": "/**\n * Motion curves with no animation library behind them.\n *\n * The components here ship as CSS, GSAP or Motion builds that must move\n * identically, so the curves are computed once, from the same numbers, and\n * handed to whichever engine runs them:\n *\n *   - `cubicBezier(x1, y1, x2, y2)` → an easing function (GSAP accepts any\n *     `(progress) => value` as `ease`), exact for Motion's `ease: [..]` arrays\n *     and for CSS `cubic-bezier()`.\n *   - `spring({ stiffness, damping, mass })` → the analytic solution Motion\n *     Motion uses, as an easing function plus the time it takes to settle, or\n *     as a CSS `linear()` string for a fixed start and end.\n *   - `createSpringFollower` → a value that chases a moving target through the\n *     same spring every frame, like Motion's `useSpring`, for pointer-driven\n *     motion that no fixed curve can describe.\n */\n\n// ---------------------------------------------------------------------------\n// Cubic bezier\n// ---------------------------------------------------------------------------\n\n/**\n * The CSS / Motion cubic-bezier as a function of progress. Newton-Raphson\n * with a bisection fallback, the same solver browsers use.\n */\nexport function cubicBezier(x1: number, y1: number, x2: number, y2: number) {\n  if (x1 === y1 && x2 === y2) return (t: number) => t;\n\n  const a = (p1: number, p2: number) => 1 - 3 * p2 + 3 * p1;\n  const b = (p1: number, p2: number) => 3 * p2 - 6 * p1;\n  const c = (p1: number) => 3 * p1;\n  const at = (t: number, p1: number, p2: number) =>\n    ((a(p1, p2) * t + b(p1, p2)) * t + c(p1)) * t;\n  const slope = (t: number, p1: number, p2: number) =>\n    3 * a(p1, p2) * t * t + 2 * b(p1, p2) * t + c(p1);\n\n  const solveX = (x: number) => {\n    let t = x;\n    for (let i = 0; i < 8; i++) {\n      const s = slope(t, x1, x2);\n      if (Math.abs(s) < 1e-6) break;\n      const err = at(t, x1, x2) - x;\n      if (Math.abs(err) < 1e-7) return t;\n      t -= err / s;\n    }\n    let lo = 0;\n    let hi = 1;\n    t = x;\n    for (let i = 0; i < 30 && hi - lo > 1e-7; i++) {\n      const value = at(t, x1, x2);\n      if (value < x) lo = t;\n      else hi = t;\n      t = (lo + hi) / 2;\n    }\n    return t;\n  };\n\n  return (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : at(solveX(x), y1, y2));\n}\n\n/** Motion's named eases, as the cubic-beziers they are. */\nexport const MOTION_EASE = {\n  linear: [0, 0, 1, 1],\n  easeIn: [0.42, 0, 1, 1],\n  easeOut: [0, 0, 0.58, 1],\n  easeInOut: [0.42, 0, 0.58, 1],\n  circIn: [0.55, 0, 1, 0.45],\n  circOut: [0.55, 0, 0.45, 1],\n  circInOut: [0.85, 0, 0.15, 1],\n  backIn: [0.31, 0.01, 0.66, -0.59],\n  backOut: [0.33, 1.53, 0.69, 0.99],\n  anticipate: [0.66, -0.56, 0.34, 1.35],\n} as const;\n\n/**\n * Motion's default layout transition (`layout` / `layoutId`):\n * `{ duration: 0.45, ease: [0.4, 0, 0.1, 1] }`.\n */\nexport const LAYOUT_TRANSITION = { duration: 0.45, ease: [0.4, 0, 0.1, 1] as const };\n\n// ---------------------------------------------------------------------------\n// Spring\n// ---------------------------------------------------------------------------\n\nexport interface SpringOptions {\n  /** Motion default 100. */\n  stiffness?: number;\n  /** Motion default 10. */\n  damping?: number;\n  /** Motion default 1. */\n  mass?: number;\n  /** Starting velocity, in units of the whole distance per second. */\n  velocity?: number;\n  /** How close to the end counts as settled, as a fraction of the distance. */\n  restDelta?: number;\n}\n\n/**\n * Normalised position (0 → 1) of a spring released from 0 towards 1, at time\n * `t` seconds. The closed-form solution Motion's `spring()` generator\n * uses for the under-, critically and over-damped cases.\n */\nexport function springAt(options: SpringOptions = {}) {\n  const { stiffness = 100, damping = 10, mass = 1, velocity = 0 } = options;\n  const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n  const omega0 = Math.sqrt(stiffness / mass);\n  // Motion's convention: distance still to cover, velocity toward it negated.\n  const delta = 1;\n  const v0 = -velocity;\n\n  if (zeta < 1) {\n    const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);\n    return (t: number) => {\n      const envelope = Math.exp(-zeta * omega0 * t);\n      return (\n        1 -\n        envelope *\n          (((v0 + zeta * omega0 * delta) / omegaD) * Math.sin(omegaD * t) +\n            delta * Math.cos(omegaD * t))\n      );\n    };\n  }\n  if (zeta === 1) {\n    return (t: number) => 1 - Math.exp(-omega0 * t) * (delta + (v0 + omega0 * delta) * t);\n  }\n  const omegaD = omega0 * Math.sqrt(zeta * zeta - 1);\n  return (t: number) => {\n    const envelope = Math.exp(-zeta * omega0 * t);\n    const freq = Math.min(omegaD * t, 300);\n    return (\n      1 -\n      (envelope *\n        ((v0 + zeta * omega0 * delta) * Math.sinh(freq) + omegaD * delta * Math.cosh(freq))) /\n        omegaD\n    );\n  };\n}\n\n/** Seconds until the spring stays within `restDelta` of its end. */\nexport function springDuration(options: SpringOptions = {}) {\n  const at = springAt(options);\n  const restDelta = options.restDelta ?? 0.001;\n  const step = 1 / 240;\n  let lastOutside = 0;\n  for (let t = 0; t <= 10; t += step) {\n    if (Math.abs(1 - at(t)) > restDelta) lastOutside = t;\n    else if (t - lastOutside > 0.1) break;\n  }\n  return Math.max(lastOutside + step, step);\n}\n\n/**\n * A spring as a duration and an easing function over it — what GSAP takes:\n *\n *   const { duration, ease } = springEase({ stiffness: 300, damping: 20 });\n *   gsap.to(el, { y: 0, duration, ease });\n *\n * Exact for a fixed start and end; a spring that has to react mid-flight to a\n * new target needs `createSpringFollower` instead.\n */\nexport function springEase(options: SpringOptions = {}) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  return {\n    duration,\n    ease: (progress: number) => (progress >= 1 ? 1 : at(progress * duration)),\n  };\n}\n\n/**\n * A spring as a CSS `linear()` easing and its duration in ms, for\n * `transition` / `animation` with a fixed start and end.\n *\n *   const { easing, duration } = springLinear({ stiffness: 400, damping: 30 });\n *   el.style.transition = `transform ${duration}ms ${easing}`;\n */\nexport function springLinear(options: SpringOptions = {}, pointsPerSecond = 60) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  const count = Math.max(Math.ceil(duration * pointsPerSecond), 8);\n  const points: string[] = [];\n  for (let i = 0; i <= count; i++) {\n    const t = (i / count) * duration;\n    points.push(String(Math.round((i === count ? 1 : at(t)) * 10000) / 10000));\n  }\n  return { easing: `linear(${points.join(\", \")})`, duration: Math.round(duration * 1000) };\n}\n\n// ---------------------------------------------------------------------------\n// Spring follower (useSpring equivalent)\n// ---------------------------------------------------------------------------\n\n/** Something that calls back once per frame with the time since the last, in ms. */\nexport interface FrameTicker {\n  add: (callback: (deltaMs: number) => void) => () => void;\n}\n\n/** requestAnimationFrame as a ticker — the library-free default. */\nexport const rafTicker: FrameTicker = {\n  add(callback) {\n    let last = performance.now();\n    let frame = requestAnimationFrame(function tick(now) {\n      callback(now - last);\n      last = now;\n      frame = requestAnimationFrame(tick);\n    });\n    return () => cancelAnimationFrame(frame);\n  },\n};\n\nexport interface SpringFollower {\n  /** Chase a new target from wherever the value is now, keeping its velocity. */\n  set: (target: number) => void;\n  /** Move to a value instantly, with no motion. */\n  jump: (value: number) => void;\n  get: () => number;\n  destroy: () => void;\n}\n\n/**\n * A value that follows its target through a spring, integrating the same\n * equation of motion Motion's `useSpring` solves — so a pointer-driven spring\n * reads the same in every build. Runs only while moving; `onUpdate` receives\n * each new value.\n */\nexport function createSpringFollower(\n  initial: number,\n  onUpdate: (value: number) => void,\n  options: SpringOptions & { restSpeed?: number; ticker?: FrameTicker } = {},\n): SpringFollower {\n  const { stiffness = 100, damping = 10, mass = 1, ticker = rafTicker } = options;\n  const restDelta = options.restDelta ?? 0.01;\n  const restSpeed = options.restSpeed ?? 0.01;\n  let value = initial;\n  let target = initial;\n  let velocity = 0;\n  let stop: (() => void) | null = null;\n\n  const step = (deltaMs: number) => {\n    // Fixed 1ms sub-steps keep the integration stable for stiff springs and\n    // independent of the frame rate.\n    const steps = Math.min(Math.max(Math.round(deltaMs), 1), 250);\n    for (let i = 0; i < steps; i++) {\n      const force = -stiffness * (value - target) - damping * velocity;\n      velocity += (force / mass) * 0.001;\n      value += velocity * 0.001;\n    }\n    if (Math.abs(target - value) < restDelta && Math.abs(velocity) < restSpeed) {\n      value = target;\n      velocity = 0;\n      stop?.();\n      stop = null;\n    }\n    onUpdate(value);\n  };\n\n  return {\n    set(next) {\n      target = next;\n      if (!stop && value !== target) stop = ticker.add(step);\n    },\n    jump(next) {\n      stop?.();\n      stop = null;\n      value = target = next;\n      velocity = 0;\n      onUpdate(value);\n    },\n    get: () => value,\n    destroy() {\n      stop?.();\n      stop = null;\n    },\n  };\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/motion-curves.ts"
    }
  ],
  "docs": "Named export: TableOfContentsBlock. Accepts `headings` array of ({ id, title, level }) objects, `showProgress`, `showSearch`, and `color` props. Wraps document content on the left while keeping the TOC sticky on the right.",
  "categories": [
    "navigation",
    "scroll"
  ],
  "type": "registry:component"
}
