{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"artifact-card","type":"registry:ui","title":"ArtifactCard","description":"A generated document as a tangible object: title, kind, a version navigator, and the first six lines of the text itself streaming in behind a fade","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["ai-agents"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-markdown.json","https://fancy-ui.rama.app/r/sound.json","https://fancy-ui.rama.app/r/streaming-text.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/artifact-card/ArtifactCard.tsx","content":"\"use client\";\n\nimport { forwardRef } from \"react\";\nimport type { MouseEvent, ReactNode } from \"react\";\nimport { cn } from \"../../utils\";\nimport type { StreamStatus } from \"../../internals/ai-types\";\nimport { StreamingText } from \"../streaming-text/StreamingText\";\nimport { useSoundCue } from \"../../sound/use-sound\";\nimport \"./artifact-card.css\";\n\n/**\n * Props for ArtifactCard\n */\nexport interface ArtifactCardProps {\n\t/** What the document is called. Required — it is the card's whole identity. */\n\ttitle: string;\n\t/** The kind of thing it is, on the muted line under the title. */\n\tkind?: string;\n\t/** Which revision is on screen, 1-based. Rendered as `v3`. */\n\tversion?: number;\n\t/** How many revisions exist. With `version`, the badge reads `v3/5`. */\n\tversionCount?: number;\n\t/**\n\t * Asked to show another revision, by 1-based version number. Supplying it\n\t * turns the badge into a navigator; the card holds no version state itself.\n\t */\n\tonVersionChange?: (version: number) => void;\n\t/** Where the document is in its life: waiting, being written, finished, failed. */\n\tstatus?: StreamStatus;\n\t/** The text so far — not the latest delta. Growing it is what streams. */\n\tpreview?: string;\n\t/** Asked to open the document. Supplying it adds an Open button to the header rail. */\n\tonOpen?: () => void;\n\t/** Buttons for the top-right rail: copy, download, delete. */\n\tactions?: ReactNode;\n\t/** Additional CSS classes */\n\tclassName?: string;\n\t/**\n\t * Plays the matching interface cue through the sound controller. Off by\n\t * default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\n/** Spoken beside the title, since the sweep and the tint say nothing out loud. */\nconst STATUS_LABELS = {\n\tidle: \"Not started\",\n\tstreaming: \"Writing\",\n\tdone: \"Ready\",\n\terror: \"Failed\",\n} as const;\n\n/** The footer a failed artifact grows, since no `error` string is carried here. */\nconst ERROR_TEXT = \"This document could not be generated.\";\n\n/**\n * Anything that has its own activation gets to keep it: a click on the version\n * navigator or on an action button must not also count as opening the card.\n * The two rails are named alongside the controls themselves, because the gaps\n * between their buttons belong to them too — a click that lands beside an arrow,\n * or on a disabled one, is aimed at the navigator, not at the document.\n */\nconst CONTROL_SELECTOR = \"a[href], button, input, select, textarea, [contenteditable='true']\";\nconst OPEN_GUARD_SELECTOR = `${CONTROL_SELECTOR}, .ft-artifact-versions, .ft-artifact-actions`;\n\n/*\n * No `disabled:pointer-events-none`: a disabled button already swallows its own\n * clicks, and taking it out of the event flow retargets the click at the card\n * behind it — which would open the document from the arrow that refused to move.\n */\nconst navButtonClass =\n\t\"text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:ring-ring inline-flex size-5 cursor-pointer items-center justify-center rounded transition-colors focus-visible:ring-1 focus-visible:outline-none disabled:opacity-40\";\n\n/**\n * A generated document rendered as a thing rather than a wall of text: a title,\n * what kind of thing it is, which draft is on screen, and a few lines of the\n * document itself dissolving into the card's edge.\n *\n * The root element arrives through the ref channel rather than a `ref` prop,\n * per PORTING.md — the Svelte source declares `ref = $bindable(null)`.\n */\nexport const ArtifactCard = forwardRef<HTMLDivElement, ArtifactCardProps>(function ArtifactCard(\n\t{\n\t\ttitle,\n\t\tkind = \"Document\",\n\t\tversion,\n\t\tversionCount,\n\t\tonVersionChange,\n\t\tstatus = \"done\",\n\t\tpreview,\n\t\tonOpen,\n\t\tactions,\n\t\tclassName,\n\t\tsound = false,\n\t},\n\tref,\n) {\n\tconst playCue = useSoundCue(sound);\n\n\tconst isStreaming = status === \"streaming\";\n\tconst isError = status === \"error\";\n\n\tconst hasPreview = preview !== undefined && preview !== \"\";\n\tconst hasVersion = version !== undefined;\n\tconst hasCount = hasVersion && versionCount !== undefined && versionCount > 0;\n\t// A navigator only makes sense when there is somewhere to navigate to *and*\n\t// somebody listening; otherwise the same numbers render as a plain badge.\n\tconst navigable = hasCount && onVersionChange !== undefined;\n\n\tconst versionLabel = hasCount ? `v${version}/${versionCount}` : hasVersion ? `v${version}` : \"\";\n\tconst atFirst = (version ?? 1) <= 1;\n\tconst atLast = (version ?? 1) >= (versionCount ?? 1);\n\n\tfunction fromControl(event: MouseEvent<HTMLDivElement>): boolean {\n\t\tconst target = event.target;\n\t\treturn target instanceof Element && target.closest(OPEN_GUARD_SELECTOR) !== null;\n\t}\n\n\t/**\n\t * Pointer-only convenience. The keyboard path is the Open button in the header\n\t * rail — a real `<button>`, so `Enter` and `Space` are the browser's job — and\n\t * the card itself stays a plain region rather than an ARIA button, which would\n\t * make its children presentational and swallow the navigator, the actions rail\n\t * and the spoken status.\n\t */\n\tfunction open(event: MouseEvent<HTMLDivElement>) {\n\t\tif (fromControl(event)) return;\n\t\tplayCue(\"press\");\n\t\tonOpen?.();\n\t}\n\n\t// The Open button's own click bubbles up to the card handler above, which\n\t// `fromControl()` sends home without playing anything — so the cue for that\n\t// path lives here instead, or a click on the button would play nothing at\n\t// all rather than playing twice.\n\tfunction openFromButton() {\n\t\tplayCue(\"press\");\n\t\tonOpen?.();\n\t}\n\n\tfunction step(delta: number) {\n\t\tconst current = version ?? 1;\n\t\tconst next = current + delta;\n\t\tif (next < 1 || next > (versionCount ?? 1)) return;\n\t\tplayCue(\"select\");\n\t\tonVersionChange?.(next);\n\t}\n\n\t/*\n\t * The card-wide click is a pointer shortcut for the Open button in the rail,\n\t * which is where the tab stop and the key handling live. The root deliberately\n\t * carries no role, no tabindex and no key handling.\n\t */\n\treturn (\n\t\t<div\n\t\t\tref={ref}\n\t\t\tclassName={cn(\n\t\t\t\t\"ft-artifact border-border bg-card relative w-full overflow-hidden rounded-lg border\",\n\t\t\t\tonOpen && \"hover:border-foreground/25 cursor-pointer transition-colors\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\tdata-status={status}\n\t\t\tonClick={onOpen ? open : undefined}\n\t\t>\n\t\t\t{/*\n\t\t\t\tThe sweep is parked off its own left edge, so reduced motion — which never\n\t\t\t\tstarts the animation — simply never sees it.\n\t\t\t*/}\n\t\t\t{isStreaming ? <span className=\"ft-artifact-sweep\" aria-hidden=\"true\" /> : null}\n\n\t\t\t<div className=\"flex items-start gap-2.5 px-3 py-2.5\">\n\t\t\t\t<span className=\"ft-artifact-icon text-muted-foreground mt-0.5 flex-none\" aria-hidden=\"true\">\n\t\t\t\t\t<svg\n\t\t\t\t\t\tclassName=\"size-4\"\n\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\tstrokeWidth=\"1.75\"\n\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<path d=\"M14 3v5h5\" />\n\t\t\t\t\t\t<path d=\"M19 8v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7z\" />\n\t\t\t\t\t</svg>\n\t\t\t\t</span>\n\n\t\t\t\t<div className=\"min-w-0 flex-1\">\n\t\t\t\t\t<div className=\"ft-artifact-title text-foreground truncate text-sm font-medium\">\n\t\t\t\t\t\t{title}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div className=\"ft-artifact-kind text-muted-foreground truncate text-xs\">{kind}</div>\n\t\t\t\t</div>\n\n\t\t\t\t<div className=\"flex flex-none items-center gap-1\">\n\t\t\t\t\t{navigable ? (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName=\"ft-artifact-versions text-muted-foreground flex items-center gap-0.5 text-xs\"\n\t\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\t\taria-label=\"Document versions\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tclassName={navButtonClass}\n\t\t\t\t\t\t\t\taria-label=\"Previous version\"\n\t\t\t\t\t\t\t\tdisabled={atFirst}\n\t\t\t\t\t\t\t\tonClick={() => step(-1)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\t\tclassName=\"size-3\"\n\t\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\t\tstrokeWidth=\"2.5\"\n\t\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<path d=\"m15 18-6-6 6-6\" />\n\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t<span className=\"ft-artifact-version tabular-nums\">{versionLabel}</span>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\tclassName={navButtonClass}\n\t\t\t\t\t\t\t\taria-label=\"Next version\"\n\t\t\t\t\t\t\t\tdisabled={atLast}\n\t\t\t\t\t\t\t\tonClick={() => step(1)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\t\tclassName=\"size-3\"\n\t\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\t\tstrokeWidth=\"2.5\"\n\t\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<path d=\"m9 6 6 6-6 6\" />\n\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : hasVersion ? (\n\t\t\t\t\t\t<span className=\"ft-artifact-version text-muted-foreground text-xs tabular-nums\">\n\t\t\t\t\t\t\t{versionLabel}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\n\t\t\t\t\t{actions ? (\n\t\t\t\t\t\t<div className=\"ft-artifact-actions flex items-center gap-1\">{actions}</div>\n\t\t\t\t\t) : null}\n\n\t\t\t\t\t{onOpen ? (\n\t\t\t\t\t\t/*\n\t\t\t\t\t\t\tThe visible affordance and the operable one are the same element: a\n\t\t\t\t\t\t\treal button, so it takes a tab stop and handles Enter and Space on the\n\t\t\t\t\t\t\tbrowser's terms, and it names the document rather than saying \"Open\"\n\t\t\t\t\t\t\tinto a list of identical cards.\n\t\t\t\t\t\t*/\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\tclassName=\"ft-artifact-open text-muted-foreground hover:text-foreground focus-visible:ring-ring ml-0.5 inline-flex cursor-pointer items-center gap-1 rounded text-xs transition-colors focus-visible:ring-1 focus-visible:outline-none\"\n\t\t\t\t\t\t\taria-label={`Open ${title}`}\n\t\t\t\t\t\t\tonClick={openFromButton}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\tOpen\n\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\tclassName=\"size-3\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\t\t\t\tstrokeWidth=\"2.5\"\n\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<path d=\"M5 12h14\" />\n\t\t\t\t\t\t\t\t<path d=\"m12 5 7 7-7 7\" />\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t<span className=\"sr-only\">{STATUS_LABELS[status]}</span>\n\n\t\t\t{hasPreview ? (\n\t\t\t\t<div className=\"ft-artifact-preview border-border border-t px-3 py-3 text-sm\">\n\t\t\t\t\t<div className=\"ft-artifact-clamp\">\n\t\t\t\t\t\t<StreamingText text={preview ?? \"\"} streaming={isStreaming} />\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\n\t\t\t{isError ? (\n\t\t\t\t<p className=\"ft-artifact-error border-border border-t px-3 py-2 text-xs\">{ERROR_TEXT}</p>\n\t\t\t) : null}\n\t\t</div>\n\t);\n});\n","type":"registry:ui","target":"@ui/fancy/components/artifact-card/ArtifactCard.tsx"},{"path":"react/src/components/artifact-card/artifact-card.css","content":"/*\n * Both colours are read at the point of use through the component's own\n * `--ft-artifact-*` hook, then the `--ft-status-*` vocabulary the whole AI\n * family shares, then the literal. Setting either anywhere up the tree retints\n * the card without having to out-specify these rules.\n */\n.ft-artifact-error {\n\tcolor: var(\n\t\t--ft-artifact-error,\n\t\tvar(--ft-status-error, light-dark(oklch(0.5 0.19 25), oklch(0.7 0.18 25)))\n\t);\n\tbackground: color-mix(\n\t\tin oklab,\n\t\tvar(\n\t\t\t\t--ft-artifact-error,\n\t\t\t\tvar(--ft-status-error, light-dark(oklch(0.5 0.19 25), oklch(0.7 0.18 25)))\n\t\t\t)\n\t\t\t7%,\n\t\ttransparent\n\t);\n}\n\n.ft-artifact-preview {\n\tbackground: var(--ft-artifact-preview-bg, color-mix(in oklab, currentColor 4%, transparent));\n}\n\n/*\n * A teaser, not the document: six lines of it, with the last one dissolving so\n * the cut never reads as the end of the text.\n */\n.ft-artifact-clamp {\n\tmax-height: var(--ft-artifact-preview-height, 9rem);\n\toverflow: hidden;\n\tline-height: 1.5;\n\t-webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);\n\tmask-image: linear-gradient(to bottom, #000 72%, transparent 100%);\n}\n\n.ft-artifact-sweep {\n\tposition: absolute;\n\tinset-inline: 0;\n\tinset-block-start: 0;\n\tblock-size: 2px;\n\toverflow: hidden;\n\tpointer-events: none;\n}\n\n.ft-artifact-sweep::after {\n\tcontent: \"\";\n\tposition: absolute;\n\tinset-block: 0;\n\tinline-size: 45%;\n\t/* Parked off the left edge: with no animation running, nothing shows. */\n\ttransform: translateX(-110%);\n\tbackground: linear-gradient(\n\t\t90deg,\n\t\ttransparent,\n\t\tvar(\n\t\t\t--ft-artifact-running,\n\t\t\tvar(--ft-status-running, light-dark(oklch(0.5 0.18 265), oklch(0.72 0.15 265)))\n\t\t),\n\t\ttransparent\n\t);\n}\n\n/*\n * The sweep is the only thing that moves, and it lives entirely behind the\n * query: reduced motion gets the same card with a still top edge, and the\n * cursor in the preview stops blinking on StreamingText's own terms.\n */\n@media (prefers-reduced-motion: no-preference) {\n\t.ft-artifact-sweep::after {\n\t\tanimation: ft-artifact-sweep var(--ft-artifact-sweep-duration, 1.9s) linear infinite;\n\t}\n\n\t/* 45% of the card wide, so 240% of itself is one full pass and a short beat. */\n\t@keyframes ft-artifact-sweep {\n\t\tfrom {\n\t\t\ttransform: translateX(-110%);\n\t\t}\n\t\tto {\n\t\t\ttransform: translateX(240%);\n\t\t}\n\t}\n}\n","type":"registry:ui","target":"@ui/fancy/components/artifact-card/artifact-card.css"},{"path":"react/src/components/artifact-card/index.ts","content":"\"use client\";\n\nexport { ArtifactCard } from \"./ArtifactCard\";\nexport type { ArtifactCardProps } from \"./ArtifactCard\";\n","type":"registry:ui","target":"@ui/fancy/components/artifact-card/index.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/artifact-card?framework=react"}}