{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "inline-citation",
  "title": "Inline Citation",
  "description": "A marker in running text whose card shows the sources it points to, paging through several.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/inline-citation.tsx",
      "content": "\"use client\";\n\nimport { inlineCitationPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { Avatar, AvatarFallback, AvatarImage } from \"@ui-sdk/react/avatar\";\nimport {\n  Carousel,\n  CarouselContent,\n  CarouselItem,\n  CarouselNext,\n  CarouselPrevious,\n  CarouselViewport,\n} from \"@ui-sdk/react/carousel\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport type { ComponentProps, ReactNode } from \"react\";\n\n// Every part is a `span`, so a citation is valid inside a paragraph.\nconst parts = createParts(inlineCitationPrimitive, {\n  root: \"span\",\n  trigger: \"button\",\n  content: \"span\",\n  carousel: \"span\",\n  item: \"span\",\n  link: \"a\",\n  icon: \"span\",\n  host: \"span\",\n  \"source-title\": \"span\",\n  snippet: \"span\",\n  index: \"span\",\n});\n\n// Lucide \"chevron-left\" and \"chevron-right\", see THIRD_PARTY_NOTICES.md.\nconst CHEVRON_LEFT = (\n  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" aria-hidden=\"true\">\n    <path d=\"m15 18-6-6 6-6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n);\nconst CHEVRON_RIGHT = (\n  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" aria-hidden=\"true\">\n    <path d=\"m9 18 6-6-6-6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n);\n\nexport type InlineCitationProps = Omit<ComponentProps<typeof parts.Root>, \"children\"> & {\n  children?: ReactNode;\n};\n\n/**\n * A marker in running text for the sources a sentence came from, with a card that opens on hover, keyboard focus and\n * press. More than one source pages in the card. Any `children` replace the marker and the card.\n */\nexport function InlineCitation({ children, ...props }: InlineCitationProps) {\n  return (\n    <parts.Root {...props}>\n      {({ ids }) =>\n        children !== undefined ? (\n          children\n        ) : (\n          <>\n            <InlineCitationTrigger />\n            <InlineCitationContent>\n              {ids.length > 1 ? <InlineCitationCarousel /> : ids[0] && <InlineCitationItem value={ids[0]} />}\n            </InlineCitationContent>\n          </>\n        )\n      }\n    </parts.Root>\n  );\n}\n\nexport type InlineCitationTriggerProps = ComponentProps<typeof parts.Trigger>;\n\n/** The marker, which opens the card. Reads the `label` unless you pass children. */\nexport function InlineCitationTrigger({\n  children = ({ label }) => label,\n  ...props\n}: InlineCitationTriggerProps) {\n  return <parts.Trigger {...props}>{children}</parts.Trigger>;\n}\n\nexport type InlineCitationContentProps = ComponentProps<typeof parts.Content>;\n\n/** The card. Leaves focus on the marker when it opens. */\nexport function InlineCitationContent(props: InlineCitationContentProps) {\n  return <parts.Content initialFocus=\"none\" {...props} />;\n}\n\nexport type InlineCitationCarouselProps = Omit<ComponentProps<typeof parts.Carousel>, \"children\"> & {\n  children?: ReactNode;\n};\n\n/**\n * UI SDK's Carousel, a slide per source with Previous, the page and Next below. Rendered only for more than one\n * source. Any `children` replace the slides and controls, inside the Carousel.\n */\nexport function InlineCitationCarousel({ children, ...props }: InlineCitationCarouselProps) {\n  return (\n    <parts.Carousel {...props}>\n      {({ controller, defaultPage, ids }) => (\n        <Carousel\n          render={<span />}\n          controller={controller}\n          defaultPage={defaultPage}\n          drag={false}\n          aria-label=\"Sources\"\n        >\n          {children !== undefined ? (\n            children\n          ) : (\n            <>\n              <CarouselViewport render={<span />}>\n                <CarouselContent render={<span />}>\n                  {ids.map((id) => (\n                    <CarouselItem key={id} render={<span />}>\n                      <InlineCitationItem value={id} />\n                    </CarouselItem>\n                  ))}\n                </CarouselContent>\n              </CarouselViewport>\n              <span data-inline-citation-controls=\"\">\n                <InlineCitationPrevious />\n                <InlineCitationIndex />\n                <InlineCitationNext />\n              </span>\n            </>\n          )}\n        </Carousel>\n      )}\n    </parts.Carousel>\n  );\n}\n\nexport type InlineCitationItemProps = ComponentProps<typeof parts.Item>;\n\n/**\n * The source whose `id` is `value`. Without children, it shows its icon, title and host name, a link when its `url`\n * is safe, then its snippet.\n */\nexport function InlineCitationItem({ children, ...props }: InlineCitationItemProps) {\n  return <parts.Item {...props}>{children !== undefined ? children : DEFAULT_ITEM_PARTS}</parts.Item>;\n}\n\n/** Links to the source's `url` in a new tab; an `a` without `href`, which is text, when the URL isn't safe. */\nexport const InlineCitationLink = parts.Link;\n\nexport type InlineCitationIconProps = ComponentProps<typeof parts.Icon>;\n\n/** A UI SDK Avatar of the source's `favicon`, showing a link glyph until it loads or without one. */\nexport function InlineCitationIcon({\n  children = ({ favicon }) => (\n    <Avatar>\n      {favicon ? <AvatarImage src={favicon} alt=\"\" /> : null}\n      <AvatarFallback />\n    </Avatar>\n  ),\n  ...props\n}: InlineCitationIconProps) {\n  return <parts.Icon {...props}>{children}</parts.Icon>;\n}\n\nexport type InlineCitationHostProps = ComponentProps<typeof parts.Host>;\n\n/** The host name of the source's `url`, unless you pass children. Rendered only with a safe `url`. */\nexport function InlineCitationHost({ children = ({ host }) => host, ...props }: InlineCitationHostProps) {\n  return <parts.Host {...props}>{children}</parts.Host>;\n}\n\nexport type InlineCitationSourceTitleProps = ComponentProps<typeof parts.SourceTitle>;\n\n/** The source's `title`, unless you pass children. */\nexport function InlineCitationSourceTitle({\n  children = ({ title }) => title,\n  ...props\n}: InlineCitationSourceTitleProps) {\n  return <parts.SourceTitle {...props}>{children}</parts.SourceTitle>;\n}\n\nexport type InlineCitationSnippetProps = ComponentProps<typeof parts.Snippet>;\n\n/** The source's `snippet`, unless you pass children. Rendered only with a `snippet`. */\nexport function InlineCitationSnippet({\n  children = ({ snippet }) => snippet,\n  ...props\n}: InlineCitationSnippetProps) {\n  return <parts.Snippet {...props}>{children}</parts.Snippet>;\n}\n\nexport type InlineCitationIndexProps = ComponentProps<typeof parts.Index>;\n\n/** Which source the card shows, like \"1 of 3\", unless you pass children. */\nexport function InlineCitationIndex({ children = ({ text }) => text, ...props }: InlineCitationIndexProps) {\n  return <parts.Index {...props}>{children}</parts.Index>;\n}\n\n// Previous and Next are hidden from agents, which takes the Carousel out of their snapshot: an agent pages with the\n// citation's own `next` and `previous`.\n\n/** Shows the previous source. */\nexport function InlineCitationPrevious({\n  children = CHEVRON_LEFT,\n  ...props\n}: ComponentProps<typeof CarouselPrevious>) {\n  return (\n    <CarouselPrevious aria-label=\"Previous source\" data-agent-hidden=\"\" data-kind-icon-button=\"\" {...props}>\n      {children}\n    </CarouselPrevious>\n  );\n}\n\n/** Shows the next source. */\nexport function InlineCitationNext({\n  children = CHEVRON_RIGHT,\n  ...props\n}: ComponentProps<typeof CarouselNext>) {\n  return (\n    <CarouselNext aria-label=\"Next source\" data-agent-hidden=\"\" data-kind-icon-button=\"\" {...props}>\n      {children}\n    </CarouselNext>\n  );\n}\n\n// Shared, so an update to the sources doesn't render the default parts' wrappers again.\nconst DEFAULT_ITEM_PARTS = (\n  <>\n    <InlineCitationLink>\n      <InlineCitationIcon />\n      <InlineCitationSourceTitle />\n      <InlineCitationHost />\n    </InlineCitationLink>\n    <InlineCitationSnippet />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/inline-citation.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
