{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "elements-inline-citation",
  "type": "registry:component",
  "title": "Inline citation",
  "description": "Numbered references inside a sentence, each with a hover preview of its source.",
  "registryDependencies": [
    "https://r.assistant-ui.com/base/elements-surfaces.json",
    "https://r.assistant-ui.com/base/elements-href.json"
  ],
  "dependencies": [
    "@base-ui/react"
  ],
  "files": [
    {
      "type": "registry:component",
      "path": "components/assistant-ui/elements/inline-citation.tsx",
      "sourcePath": "packages/ui/src/components/react/assistant-ui/elements/inline-citation.tsx",
      "content": "\"use client\";\n\nimport type { ComponentProps } from \"react\";\nimport { PreviewCard } from \"@base-ui/react/preview-card\";\nimport { cn } from \"@/lib/utils\";\nimport { floating, mono } from \"./surfaces\";\nimport { hostOf, safeHref } from \"../utils/href\";\n\nexport interface Source {\n  domain?: string | undefined;\n  title: string;\n  snippet: string;\n  url?: string | undefined;\n  publishedAt?: string | undefined;\n}\n\nexport interface CitationProps extends Omit<\n  ComponentProps<\"button\">,\n  \"aria-label\" | \"children\" | \"className\" | \"type\"\n> {\n  index: number;\n  source: Source;\n  open?: boolean | undefined;\n  onOpenChange?: ((open: boolean) => void) | undefined;\n  className?: string | undefined;\n}\n\nconst dateFormatter = new Intl.DateTimeFormat(\"en-US\", {\n  month: \"short\",\n  year: \"numeric\",\n});\n\nfunction formatPublishedAt(publishedAt: string | undefined) {\n  if (publishedAt === undefined) return undefined;\n  const date = new Date(publishedAt);\n  return Number.isNaN(date.getTime()) ? undefined : dateFormatter.format(date);\n}\n\nexport function Citation({\n  index,\n  source,\n  open,\n  onOpenChange,\n  className,\n  ...props\n}: CitationProps) {\n  const domain = source.domain ?? hostOf(source.url);\n  const href = safeHref(source.url);\n  const publishedAt = formatPublishedAt(source.publishedAt);\n  const hasMetadata = domain !== undefined || publishedAt !== undefined;\n\n  return (\n    <PreviewCard.Root open={open} onOpenChange={onOpenChange}>\n      <PreviewCard.Trigger\n        delay={0}\n        render={<button type=\"button\" {...props} />}\n        aria-label={`Source ${index + 1}: ${source.title}`}\n        className={cn(\n          \"bg-foreground/[0.06] text-muted-foreground hover:text-foreground/90 data-[popup-open]:bg-foreground data-[popup-open]:text-background ms-0.5 inline-flex h-4 min-w-4 translate-y-[-2px] cursor-default items-center justify-center rounded-[5px] px-1 align-middle font-mono text-[10px] font-medium tabular-nums transition-colors motion-reduce:transition-none\",\n          className,\n        )}\n      >\n        {index + 1}\n      </PreviewCard.Trigger>\n      <PreviewCard.Portal>\n        <PreviewCard.Positioner side=\"top\" sideOffset={8}>\n          <PreviewCard.Popup\n            className={cn(\n              floating,\n              \"z-50 w-64 origin-(--transform-origin) rounded-2xl p-3.5 outline-none\",\n              \"transition-[opacity,scale] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none\",\n              \"data-[starting-style]:scale-[0.97] data-[starting-style]:opacity-0\",\n              \"data-[ending-style]:scale-[0.97] data-[ending-style]:opacity-0\",\n            )}\n          >\n            {hasMetadata ? (\n              <div className=\"flex items-center gap-1.5\">\n                {domain ? (\n                  <>\n                    <span className=\"bg-foreground/[0.06] text-muted-foreground flex size-4 items-center justify-center rounded text-[9px] font-medium\">\n                      {domain[0]?.toUpperCase()}\n                    </span>\n                    <span className={cn(mono, \"text-muted-foreground\")}>\n                      {domain}\n                    </span>\n                  </>\n                ) : null}\n                {publishedAt ? (\n                  <span className={cn(mono, \"text-muted-foreground\")}>\n                    {publishedAt}\n                  </span>\n                ) : null}\n              </div>\n            ) : null}\n            <p\n              className={cn(\n                \"text-[13px] leading-snug font-medium\",\n                hasMetadata && \"mt-2\",\n              )}\n            >\n              {source.title}\n            </p>\n            <p className=\"text-muted-foreground mt-1 text-[13px] leading-relaxed\">\n              {source.snippet}\n            </p>\n            {href ? (\n              <a\n                href={href}\n                target=\"_blank\"\n                rel=\"noopener noreferrer\"\n                className=\"text-muted-foreground hover:text-foreground mt-3 inline-flex text-xs underline-offset-2 transition-colors hover:underline motion-reduce:transition-none\"\n              >\n                Open source{\" \"}\n                <span className=\"sr-only\">(opens in a new tab)</span>\n              </a>\n            ) : null}\n          </PreviewCard.Popup>\n        </PreviewCard.Positioner>\n      </PreviewCard.Portal>\n    </PreviewCard.Root>\n  );\n}\n\nexport interface InlineCitationProps extends ComponentProps<\"p\"> {}\n\nexport function InlineCitation({\n  children,\n  className,\n  ...props\n}: InlineCitationProps) {\n  return (\n    <p\n      data-slot=\"inline-citation\"\n      className={cn(\n        \"text-foreground/90 max-w-sm text-sm leading-relaxed\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </p>\n  );\n}\n"
    }
  ]
}