{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "research-report",
  "title": "Research Report",
  "description": "A long-form report reader with a contents rail, reading progress, and sections that stream in as they are written.",
  "dependencies": [
    "cn@^0.3.0",
    "motion@^13.4.0"
  ],
  "registryDependencies": [
    "https://pastaui.com/r/pastaui-styles.json"
  ],
  "files": [
    {
      "path": "src/components/ai/research-report.tsx",
      "content": "import * as React from 'react'\nimport { MotionConfig, motion, useScroll, useSpring } from 'motion/react'\n\nimport { cn } from 'cn'\n\ninterface ResearchReportSection {\n  content: React.ReactNode\n  id: string\n  title: string\n  level?: 2 | 3\n}\n\ninterface ResearchReportSource {\n  id: string\n  label: string\n  url?: string\n}\n\ninterface ResearchReportProps extends React.ComponentProps<'article'> {\n  generatedAt?: string\n  onOpenSource?: (id: string) => void\n  sections: ResearchReportSection[]\n  sources?: ResearchReportSource[]\n  summary: string\n  summaryTitle?: string\n  title: string\n}\n\nfunction ResearchReport({\n  className,\n  generatedAt,\n  onOpenSource,\n  sections,\n  sources = [],\n  summary,\n  summaryTitle = 'Executive summary',\n  title,\n  ...props\n}: ResearchReportProps) {\n  const instanceId = React.useId()\n  const viewportRef = React.useRef<HTMLElement>(null)\n  const [activeIndex, setActiveIndex] = React.useState(0)\n  const [contentsOpen, setContentsOpen] = React.useState(false)\n  const contentsId = `${instanceId}-contents`\n  const { scrollYProgress } = useScroll({ container: viewportRef })\n  const readProgress = useSpring(scrollYProgress, { stiffness: 300, damping: 40 })\n  const entries = [\n    { title, level: 1 },\n    { title: summaryTitle, level: 2 },\n    ...sections.map((section) => ({ title: section.title, level: section.level ?? 2 })),\n    ...(sources.length ? [{ title: 'Sources', level: 2 }] : []),\n  ]\n\n  function jumpTo(index: number) {\n    const viewport = viewportRef.current\n    const target = viewport?.querySelector<HTMLElement>(`[data-report-heading=\"${index}\"]`)\n    if (!viewport || !target) return\n    viewport.scrollTo({\n      top:\n        target.getBoundingClientRect().top -\n        viewport.getBoundingClientRect().top +\n        viewport.scrollTop -\n        32,\n      behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches\n        ? 'instant'\n        : 'smooth',\n    })\n    setActiveIndex(index)\n    target.focus({ preventScroll: true })\n    setContentsOpen(false)\n  }\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <article\n        data-slot=\"research-report\"\n        className={cn(\n          'relative isolate overflow-hidden rounded-[16px] bg-background font-sans text-sm font-[450] tracking-[-0.05px] text-muted-foreground shadow-card',\n          className,\n        )}\n        {...props}\n      >\n        <div\n          className=\"absolute top-12 left-3 z-20\"\n          onMouseEnter={() => setContentsOpen(true)}\n          onMouseLeave={() => setContentsOpen(false)}\n          onBlur={(event) => {\n            if (!event.currentTarget.contains(event.relatedTarget)) setContentsOpen(false)\n          }}\n        >\n          <button\n            type=\"button\"\n            aria-label=\"Table of contents\"\n            aria-expanded={contentsOpen}\n            aria-controls={contentsId}\n            className=\"flex w-10 flex-col items-start gap-2.5 rounded px-2 py-3 focus-visible:outline-2 focus-visible:outline-ring\"\n            onClick={() => setContentsOpen((open) => !open)}\n          >\n            {entries.map((entry, index) => (\n              <span\n                key={index}\n                className={cn(\n                  'h-0.5 rounded-full transition-[width,background-color] duration-300 ease-[cubic-bezier(0.23,1,0.32,1)]',\n                  index === activeIndex\n                    ? 'w-6 bg-foreground'\n                    : cn(entry.level === 3 ? 'w-2.5' : 'w-4', 'bg-foreground/20'),\n                )}\n              />\n            ))}\n          </button>\n          {/* Escape dismisses the navigation from any of its buttons. */}\n          {/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}\n          <nav\n            onKeyDown={(event) => {\n              if (event.key === 'Escape') {\n                setContentsOpen(false)\n                event.currentTarget.parentElement?.querySelector('button')?.focus()\n              }\n            }}\n            id={contentsId}\n            aria-label=\"Table of contents\"\n            hidden={!contentsOpen}\n            className=\"absolute top-0 left-0 w-64 origin-top-left overflow-hidden rounded-[16px] bg-card shadow-card transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] sm:w-72 starting:scale-95 starting:opacity-0 motion-reduce:starting:scale-100\"\n          >\n            <div className=\"max-h-[min(32rem,70vh)] [scrollbar-width:none] overflow-y-auto overscroll-contain [mask-image:linear-gradient(to_bottom,transparent,#000_12px,#000_calc(100%-24px),transparent)] px-5 py-3 [&::-webkit-scrollbar]:hidden\">\n              <p className=\"mb-4 text-[11px] font-[450] text-muted-foreground\">Table of contents</p>\n              <ol className=\"space-y-3\">\n                {entries.map((entry, index) => (\n                  <li key={index}>\n                    <button\n                      type=\"button\"\n                      aria-current={index === activeIndex ? 'location' : undefined}\n                      onClick={() => jumpTo(index)}\n                      className={cn(\n                        'w-full rounded text-left text-sm leading-6 text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring',\n                        entry.level === 3 && 'pl-4',\n                        index === activeIndex && 'font-medium text-foreground',\n                      )}\n                    >\n                      {entry.title}\n                    </button>\n                  </li>\n                ))}\n              </ol>\n            </div>\n          </nav>\n        </div>\n        <section\n          ref={viewportRef}\n          // The scroll viewport must be keyboard-scrollable.\n          // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n          tabIndex={0}\n          aria-label={`${title} report`}\n          className=\"max-h-[36rem] [scrollbar-width:none] overflow-y-auto overscroll-contain focus-visible:outline-2 focus-visible:outline-ring [&::-webkit-scrollbar]:hidden\"\n          onScroll={() => {\n            const viewport = viewportRef.current\n            if (!viewport) return\n            const headings = Array.from(\n              viewport.querySelectorAll<HTMLElement>('[data-report-heading]'),\n            )\n            let current = 0\n            for (const [index, heading] of headings.entries()) {\n              if (heading.getBoundingClientRect().top <= viewport.getBoundingClientRect().top + 80)\n                current = index\n            }\n            setActiveIndex(current)\n          }}\n        >\n          <div className=\"sticky top-0 z-10 h-0.5 w-full\">\n            <motion.div\n              className=\"h-full origin-left bg-foreground/60\"\n              style={{ scaleX: readProgress }}\n            />\n          </div>\n          <div className=\"mx-auto box-content max-w-[42rem] px-14 py-12 sm:px-20\">\n            <h2\n              data-report-heading=\"0\"\n              tabIndex={-1}\n              className=\"mb-9 text-2xl leading-snug font-medium tracking-[-0.05px] text-foreground outline-none sm:text-[28px]\"\n            >\n              {title}\n            </h2>\n            <section className=\"mb-8\">\n              <h3\n                data-report-heading=\"1\"\n                tabIndex={-1}\n                className=\"mb-3 text-xl font-medium tracking-[-0.05px] text-foreground outline-none\"\n              >\n                {summaryTitle}\n              </h3>\n              <p className=\"text-sm leading-6 whitespace-pre-line text-muted-foreground\">\n                {summary}\n              </p>\n              {generatedAt && (\n                <p className=\"mt-3 text-xs leading-5 text-muted-foreground\">{generatedAt}</p>\n              )}\n            </section>\n            {sections.map((section, index) => {\n              const Heading = section.level === 3 ? 'h4' : 'h3'\n              return (\n                <motion.section\n                  key={section.id}\n                  className=\"mb-8\"\n                  initial={{ opacity: 0, y: 14, filter: 'blur(4px)' }}\n                  transition={{ duration: 0.5, ease: [0.23, 1, 0.32, 1] }}\n                  viewport={{ amount: 0.15, once: true, root: viewportRef }}\n                  whileInView={{ opacity: 1, y: 0, filter: 'blur(0px)' }}\n                >\n                  <Heading\n                    data-report-heading={index + 2}\n                    tabIndex={-1}\n                    className={cn(\n                      'mb-3 font-medium tracking-[-0.05px] text-foreground outline-none',\n                      section.level === 3 ? 'text-base' : 'text-xl',\n                    )}\n                  >\n                    {section.title}\n                  </Heading>\n                  <div className=\"text-sm leading-6 whitespace-pre-line text-muted-foreground [&_p+p]:mt-4 [&_strong]:font-medium [&_strong]:text-foreground\">\n                    {section.content}\n                  </div>\n                </motion.section>\n              )\n            })}\n            {sources.length > 0 && (\n              <section>\n                <h3\n                  data-report-heading={sections.length + 2}\n                  tabIndex={-1}\n                  className=\"mb-3 text-xl font-medium text-foreground outline-none\"\n                >\n                  Sources\n                </h3>\n                <ol className=\"list-inside list-decimal space-y-2 text-sm leading-6 text-muted-foreground\">\n                  {sources.map((source) => (\n                    <li key={source.id}>\n                      {onOpenSource ? (\n                        <button\n                          type=\"button\"\n                          className=\"text-left underline underline-offset-4 hover:text-foreground\"\n                          onClick={() => onOpenSource(source.id)}\n                        >\n                          {source.label}\n                        </button>\n                      ) : source.url ? (\n                        <a\n                          href={source.url}\n                          target=\"_blank\"\n                          rel=\"noreferrer\"\n                          className=\"underline underline-offset-4 hover:text-foreground\"\n                        >\n                          {source.label}\n                        </a>\n                      ) : (\n                        source.label\n                      )}\n                    </li>\n                  ))}\n                </ol>\n              </section>\n            )}\n          </div>\n        </section>\n      </article>\n    </MotionConfig>\n  )\n}\n\nexport { ResearchReport }\nexport type { ResearchReportSection, ResearchReportSource, ResearchReportProps }\nexport default ResearchReport\n",
      "type": "registry:component",
      "target": "@components/ai/research-report.tsx"
    }
  ],
  "type": "registry:component"
}