{
  "schemaVersion": 1,
  "target": "react",
  "name": "inline-citation",
  "version": "0.1.1",
  "category": "ai-elements",
  "title": "Inline Citation",
  "description": "A numbered citation chip inside a sentence that opens a card with the source title, snippet, and URL, paging between several sources.",
  "tags": [
    "ai",
    "agent",
    "citation",
    "sources",
    "hover-card",
    "popover"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {},
  "registryDependencies": [
    {
      "name": "popover",
      "version": "0.2.2"
    }
  ],
  "docsPath": "/components/inline-citation",
  "props": [
    {
      "name": "index",
      "type": "number",
      "description": "The number on the chip, matching the Sources list."
    },
    {
      "name": "sources",
      "type": "{ title, url, snippet?, domain? }[]",
      "description": "One or more sources behind the claim. With more than one the chip reads 2 +2 and the card pages between them."
    },
    {
      "name": "delay",
      "type": "number",
      "default": "250",
      "description": "Hover delay in milliseconds before the card opens. Click, Enter, and Space open it at once."
    }
  ],
  "accessibility": [
    "The chip is a button (Base UI Popover trigger) with an aria-label such as Source 2: WebKit features in Safari 18.2, and 2 more.",
    "The card opens on hover and on click or Enter; focus moves into it, Escape closes it and returns focus to the chip.",
    "With several sources, Previous and Next buttons are labelled, the 1 of 3 counter is a polite live region, and Left and Right arrow keys page without animation.",
    "The source link in the card notes that it opens in a new tab. The card scales in from the chip in 160ms; instant with reduced motion."
  ],
  "states": [
    "closed",
    "open",
    "multiple sources"
  ],
  "files": [
    {
      "path": "agent/inline-citation.tsx",
      "content": "\"use client\";\n\nimport { type KeyboardEvent, useState } from \"react\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../ui/popover\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nexport interface CitationSource {\n  /** Page title. */\n  title: string;\n  /** Full URL. */\n  url: string;\n  /** The passage the claim rests on. Clamped to four lines. */\n  snippet?: string;\n  /** Shown above the title. Defaults to the URL's host without `www.`. */\n  domain?: string;\n}\n\nexport interface InlineCitationProps {\n  /** One or more sources behind the claim. Several sources page inside one card. */\n  sources: CitationSource[];\n  /** The number on the chip, matching the Sources list. */\n  index: number;\n  /** Hover delay before the card opens, in milliseconds. Click, Enter, and Space open it at once. */\n  delay?: number;\n  className?: string;\n}\n\nfunction domainOf(source: CitationSource): string {\n  if (source.domain) return source.domain;\n  try {\n    return new URL(source.url).hostname.replace(/^www\\./, \"\");\n  } catch {\n    return source.url;\n  }\n}\n\n/**\n * A numbered chip that sits inside a sentence and opens a card with the source title, snippet,\n * and URL. It opens on hover and on click or Enter; a citation with several sources pages\n * between them with buttons or the arrow keys.\n */\nexport function InlineCitation({ sources, index, delay = 250, className }: InlineCitationProps) {\n  const [page, setPage] = useState(0);\n  const total = sources.length;\n  const current = sources[Math.min(page, total - 1)];\n  if (!current) return null;\n  const extra = total - 1;\n\n  function go(step: number) {\n    setPage((value) => (value + step + total) % total);\n  }\n\n  function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n    if (total < 2) return;\n    if (event.key === \"ArrowRight\") {\n      event.preventDefault();\n      go(1);\n    } else if (event.key === \"ArrowLeft\") {\n      event.preventDefault();\n      go(-1);\n    }\n  }\n\n  return (\n    <Popover onOpenChange={(open) => !open && setPage(0)}>\n      <PopoverTrigger\n        openOnHover\n        delay={delay}\n        closeDelay={120}\n        aria-label={`Source ${index}: ${sources[0]?.title ?? \"\"}${extra > 0 ? `, and ${extra} more` : \"\"}`}\n        className={cx(\n          \"relative -top-px mx-0.5 inline-flex h-[18px] cursor-pointer items-center gap-1 rounded-md px-1.5 align-middle font-mono text-[11px] leading-none font-medium tabular-nums\",\n          \"border border-zinc-950/10 text-zinc-600 transition-[background-color,border-color,color] duration-150 ease-out motion-reduce:transition-none\",\n          \"hover:border-zinc-950/20 hover:bg-zinc-950/[0.04] hover:text-zinc-950 data-popup-open:border-zinc-950/20 data-popup-open:bg-zinc-950/[0.06] data-popup-open:text-zinc-950\",\n          \"dark:border-white/15 dark:text-zinc-400 dark:hover:border-white/25 dark:hover:bg-white/[0.06] dark:hover:text-white dark:data-popup-open:border-white/25 dark:data-popup-open:bg-white/[0.09] dark:data-popup-open:text-white\",\n          \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n          className,\n        )}\n      >\n        {index}\n        {extra > 0 ? <span className=\"text-zinc-500\">+{extra}</span> : null}\n      </PopoverTrigger>\n      <PopoverContent side=\"top\" sideOffset={6} className=\"w-80 p-0!\" onKeyDown={onKeyDown} aria-label={`Source ${index}`}>\n        {total > 1 ? (\n          <div className=\"flex items-center justify-between gap-3 border-b border-zinc-950/[0.07] py-1.5 pr-1.5 pl-3.5 dark:border-white/[0.08]\">\n            <p className=\"font-mono text-xs text-zinc-500 tabular-nums\" aria-live=\"polite\">\n              {page + 1} of {total}\n            </p>\n            <div className=\"flex items-center gap-0.5\">\n              <PageButton label=\"Previous source\" onClick={() => go(-1)} direction=\"previous\" />\n              <PageButton label=\"Next source\" onClick={() => go(1)} direction=\"next\" />\n            </div>\n          </div>\n        ) : null}\n        <a\n          href={current.url}\n          target=\"_blank\"\n          rel=\"noreferrer\"\n          className={cx(\n            \"group/source block p-3.5\",\n            \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n            \"hover:bg-zinc-950/[0.025] dark:hover:bg-white/[0.04]\",\n            \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n            total > 1 ? \"rounded-b-xl\" : \"rounded-xl\",\n          )}\n        >\n          <span className=\"flex items-center gap-2 text-xs text-zinc-500\">\n            <span\n              aria-hidden=\"true\"\n              className=\"inline-flex size-4 shrink-0 items-center justify-center rounded-full text-[9px] font-semibold text-zinc-600 shadow-[inset_0_0_0_1px_rgb(9_9_11/0.1)] dark:text-zinc-300 dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.16)]\"\n            >\n              {domainOf(current).charAt(0).toUpperCase()}\n            </span>\n            <span className=\"min-w-0 truncate\">{domainOf(current)}</span>\n          </span>\n          <span className=\"mt-2 block text-sm leading-5 font-semibold text-zinc-950 group-hover/source:underline group-hover/source:decoration-zinc-950/30 group-hover/source:underline-offset-2 dark:text-white dark:group-hover/source:decoration-white/40\">\n            {current.title}\n          </span>\n          {current.snippet ? (\n            <span className=\"mt-1 line-clamp-4 block text-[13px] leading-5 text-zinc-600 dark:text-zinc-400\">{current.snippet}</span>\n          ) : null}\n          <span className=\"mt-2.5 block truncate font-mono text-[11px] text-zinc-500\">{current.url.replace(/^https?:\\/\\//, \"\")}</span>\n          <span className=\"sr-only\">(opens in a new tab)</span>\n        </a>\n      </PopoverContent>\n    </Popover>\n  );\n}\n\nfunction PageButton({ label, onClick, direction }: { label: string; onClick: () => void; direction: \"previous\" | \"next\" }) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      onClick={onClick}\n      className={cx(\n        \"inline-flex size-7 cursor-pointer items-center justify-center rounded-md text-zinc-500\",\n        \"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n        \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n        \"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n      )}\n    >\n      <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className={cx(\"size-4\", direction === \"previous\" && \"rotate-180\")}>\n        <path d=\"m6.25 4.5 3.5 3.5-3.5 3.5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n      </svg>\n    </button>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { InlineCitation } from \"@/components/shaken/agent/inline-citation\";\n\nexport default function InlineCitationExample() {\n  return (\n    <p className=\"w-full max-w-lg text-sm leading-7 text-zinc-800 dark:text-zinc-200\">\n      The View Transitions API now works across documents in Chromium browsers, so a multi-page site can animate between\n      routes without a client router\n      <InlineCitation\n        index={1}\n        sources={[\n          {\n            title: \"Cross-document view transitions\",\n            url: \"https://developer.chrome.com/docs/web-platform/view-transitions/cross-document\",\n            snippet:\n              \"Opt in on both pages with the @view-transition at-rule. The browser captures the old page, loads the new one, and animates between the two snapshots.\",\n          },\n        ]}\n      />\n      . Safari shipped same-document transitions first and added cross-document support a release later\n      <InlineCitation\n        index={2}\n        sources={[\n          {\n            title: \"WebKit features in Safari 18.2\",\n            url: \"https://webkit.org/blog/16301/webkit-features-in-safari-18-2/\",\n            snippet: \"Safari 18.2 adds support for cross-document view transitions, matching the at-rule syntax used in other engines.\",\n          },\n          {\n            title: \"View Transition API browser support\",\n            url: \"https://caniuse.com/view-transitions\",\n            snippet: \"Same-document view transitions are supported in Chrome 111+, Edge 111+, and Safari 18+. Firefox support is in development.\",\n          },\n          {\n            title: \"Smooth transitions with the View Transition API\",\n            url: \"https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API\",\n            snippet: \"The API lets you capture the current state, update the DOM, and then animate from the old state to the new one with CSS.\",\n          },\n        ]}\n      />\n      .\n    </p>\n  );\n}\n"
  }
}
