{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "snippet",
  "type": "registry:ui",
  "title": "Snippet",
  "description": "Read and copy complete code or text.",
  "dependencies": [
    "lucide-react@0.561.0",
    "react-syntax-highlighter@16.1.1"
  ],
  "devDependencies": [
    "@types/react-syntax-highlighter@15.5.13"
  ],
  "registryDependencies": [
    "https://ghost-ui.com/r/ghost-tokens.json",
    "https://ghost-ui.com/r/button.json",
    "https://ghost-ui.com/r/scroll-area.json",
    "https://ghost-ui.com/r/tabs.json",
    "https://ghost-ui.com/r/tooltip.json"
  ],
  "files": [
    {
      "path": "src/components/ui/snippet.tsx",
      "type": "registry:component",
      "target": "@ui/snippet.tsx",
      "content": "import * as React from \"react\";\nimport { Check, ChevronDown, ChevronUp, Copy, Download, Github } from \"lucide-react\";\nimport { Button, IconButton, buttonVariants } from \"./button\";\nimport { ScrollArea } from \"./scroll-area\";\nimport { Tabs } from \"./tabs\";\nimport { copySnippetValue } from \"./snippet-copy\";\nimport { logicalLineCount, SyntaxCode } from \"./syntax-code\";\nimport \"./snippet.css\";\nimport { TooltipHint } from \"./tooltip\";\n\nexport type SnippetVariant = \"basic\" | \"block\" | \"inline\";\nexport type SnippetAppearance = \"subtle\" | \"outline\";\nexport type SnippetContentType = \"code\" | \"text\";\nexport type SnippetCopyStatus = \"idle\" | \"copied\" | \"failed\";\nexport type SnippetCollapseMode = \"truncate\" | \"hide\";\n\nexport interface SnippetSource {\n  id: string;\n  label: string;\n  value: string;\n  language?: string;\n  icon?: React.ReactNode;\n  filename?: string;\n  copyLabel?: string;\n  copiedLabel?: string;\n  copyFailedLabel?: string;\n  emptyLabel?: string;\n}\n\nexport interface SnippetProps {\n  value: string;\n  /** Optional canonical content for the basic or block body. */\n  children?: React.ReactNode;\n  variant?: SnippetVariant;\n  /** Inline copy presentation; the complete value remains the copy target. */\n  inlineCopy?: \"value\" | \"inline\" | \"floating\";\n  /** Floating actions can stay visible or appear on hover, focus, or tap. */\n  copyVisibility?: \"always\" | \"hover\";\n  /** Surface treatment, independent of the content layout. */\n  appearance?: SnippetAppearance;\n  contentType?: SnippetContentType;\n  language?: string;\n  title?: string;\n  icon?: React.ReactNode;\n  /** Optional source repository link beside the source controls. */\n  sourceHref?: string;\n  /** Optional supporting assets; code and CSS remain copyable in place. */\n  assetsHref?: string;\n  sources?: SnippetSource[];\n  activeSource?: string;\n  defaultSource?: string;\n  onSourceChange?: (sourceId: string) => void;\n  expanded?: boolean;\n  defaultExpanded?: boolean;\n  onExpandedChange?: (expanded: boolean) => void;\n  collapsible?: boolean;\n  collapseMode?: SnippetCollapseMode;\n  expandLabel?: string;\n  collapseLabel?: string;\n  headerSeparator?: boolean;\n  sourceTabVariant?: \"line\" | \"segmented\";\n  sourceTabSize?: \"sm\" | \"base\";\n  sourceTabsActivateOnFocus?: boolean;\n  initialLines?: number;\n  maxExpandedLines?: number;\n  onCopy?: (value: string) => void | Promise<void>;\n  disabled?: boolean;\n  className?: string;\n}\n\nfunction normalizeSources(sources: SnippetSource[] | undefined, fallback: SnippetSource): SnippetSource[] {\n  if (!Array.isArray(sources) || sources.length === 0) return [fallback];\n  const used = new Set<string>();\n  const normalized = sources.flatMap((source, index) => {\n    if (!source || typeof source !== \"object\") return [];\n    const base = typeof source.id === \"string\" && source.id.trim() ? source.id.trim() : `source-${index + 1}`;\n    let id = base;\n    let suffix = 2;\n    while (used.has(id)) id = `${base}-${suffix++}`;\n    used.add(id);\n    return [{\n      ...source,\n      id,\n      label: typeof source.label === \"string\" && source.label.trim() ? source.label : id,\n      value: typeof source.value === \"string\" ? source.value : \"\",\n    }];\n  });\n  return normalized.length > 0 ? normalized : [fallback];\n}\n\nfunction lineLimit(value: number | undefined, fallback: number) {\n  if (value == null || !Number.isFinite(value)) return fallback;\n  return Math.max(1, Math.floor(value));\n}\n\nexport function Snippet({\n  value,\n  children,\n  variant = \"basic\",\n  inlineCopy = \"value\",\n  copyVisibility = \"always\",\n  appearance,\n  contentType = \"code\",\n  language = \"tsx\",\n  title,\n  icon,\n  sources,\n  sourceHref,\n  assetsHref,\n  activeSource,\n  defaultSource,\n  onSourceChange,\n  expanded,\n  defaultExpanded = false,\n  onExpandedChange,\n  collapsible = false,\n  collapseMode = \"truncate\",\n  expandLabel = \"Show more\",\n  collapseLabel = \"Show less\",\n  headerSeparator = true,\n  sourceTabVariant = \"segmented\",\n  sourceTabSize = \"sm\",\n  sourceTabsActivateOnFocus = false,\n  initialLines = 8,\n  maxExpandedLines = 24,\n  onCopy,\n  disabled = false,\n  className,\n}: SnippetProps) {\n  const fallbackSource = { id: \"default\", label: title ?? \"Source\", value: typeof value === \"string\" ? value : \"\", language, icon };\n  const availableSources = React.useMemo(() => normalizeSources(sources, fallbackSource), [sources, fallbackSource.id, fallbackSource.label, fallbackSource.value, fallbackSource.language, fallbackSource.icon]);\n  const [uncontrolledSource, setUncontrolledSource] = React.useState(defaultSource ?? availableSources[0].id);\n  const [uncontrolledExpanded, setUncontrolledExpanded] = React.useState(defaultExpanded);\n  const [status, setStatus] = React.useState<SnippetCopyStatus>(\"idle\");\n  const [copyRevealed, setCopyRevealed] = React.useState(false);\n  const contentId = React.useId();\n  const timer = React.useRef<number | null>(null);\n  const generation = React.useRef(0);\n  const latestAttempt = React.useRef(0);\n  const mounted = React.useRef(false);\n  const sourceIdCandidate = activeSource ?? uncontrolledSource;\n  const sourceId = availableSources.some((source) => source.id === sourceIdCandidate) ? sourceIdCandidate : availableSources[0].id;\n  const source = availableSources.find((item) => item.id === sourceId) ?? availableSources[0];\n  const isExpanded = expanded ?? uncontrolledExpanded;\n  const lines = logicalLineCount(source.value);\n  const initial = lineLimit(initialLines, 8);\n  const requestedMax = lineLimit(maxExpandedLines, 24);\n  const max = collapsible ? Math.max(initial, requestedMax) : requestedMax;\n  const scrollLines = collapsible && !isExpanded ? initial : max;\n  const hideMode = collapsible && collapseMode === \"hide\" && variant !== \"inline\";\n  const hasDisclosure = collapsible && (hideMode || (source.value.length > 0 && lines > initial && max > initial));\n  const canCopy = !disabled && source.value.length > 0;\n  const disclosureSize = \"xs\";\n  const hasHeader = Boolean(title || icon || sourceHref || assetsHref || (sources && availableSources.length > 0) || (hideMode && collapsible));\n\n  const headerHasActions = hasHeader && (variant === \"block\" || hideMode);\n  const copySize = \"icon-xs\";\n\n  const clearTimer = React.useCallback(() => {\n    if (timer.current !== null) {\n      window.clearTimeout(timer.current);\n      timer.current = null;\n    }\n  }, []);\n\n  React.useEffect(() => {\n    mounted.current = true;\n    return () => {\n      mounted.current = false;\n      generation.current += 1;\n      latestAttempt.current += 1;\n      clearTimer();\n    };\n  }, [clearTimer]);\n\n  React.useEffect(() => {\n    generation.current += 1;\n    latestAttempt.current += 1;\n    setStatus(\"idle\");\n    clearTimer();\n    return () => {\n      generation.current += 1;\n      clearTimer();\n    };\n  }, [sourceId, source.value, clearTimer]);\n\n  React.useEffect(() => {\n    if (hideMode && !isExpanded) {\n      generation.current += 1;\n      latestAttempt.current += 1;\n      setStatus(\"idle\");\n      clearTimer();\n    }\n  }, [hideMode, isExpanded, clearTimer]);\n\n  const setSource = (next: string) => {\n    if (activeSource === undefined) setUncontrolledSource(next);\n    onSourceChange?.(next);\n  };\n\n  const setExpanded = (next: boolean) => {\n    if (expanded === undefined) setUncontrolledExpanded(next);\n    onExpandedChange?.(next);\n  };\n\n  const handleCopy = async () => {\n    if (!canCopy) return;\n    const requestGeneration = generation.current;\n    const requestAttempt = ++latestAttempt.current;\n    try {\n      if (onCopy) await onCopy(source.value);\n      else await copySnippetValue(source.value);\n      if (!mounted.current || requestGeneration !== generation.current || requestAttempt !== latestAttempt.current) return;\n      setStatus(\"copied\");\n    } catch {\n      if (!mounted.current || requestGeneration !== generation.current || requestAttempt !== latestAttempt.current) return;\n      clearTimer();\n      setStatus(\"failed\");\n      return;\n    }\n    if (!mounted.current || requestGeneration !== generation.current || requestAttempt !== latestAttempt.current) return;\n    clearTimer();\n    timer.current = window.setTimeout(() => {\n      if (mounted.current && requestGeneration === generation.current && requestAttempt === latestAttempt.current) setStatus(\"idle\");\n    }, 2000);\n  };\n\n  const toggleExpanded = () => {\n    if (hideMode && isExpanded) {\n      generation.current += 1;\n      latestAttempt.current += 1;\n      setStatus(\"idle\");\n      clearTimer();\n    }\n    setExpanded(!isExpanded);\n  };\n\n  const copyLabel = status === \"copied\" ? (source.copiedLabel ?? \"Copied\") : status === \"failed\" ? (source.copyFailedLabel ?? \"Copy failed. Try again.\") : (source.copyLabel ?? \"Copy\");\n  const copyHint = status === \"idle\" ? (source.copyLabel ?? \"Click to copy\") : copyLabel;\n  const visibleValue = variant !== \"inline\" && hasDisclosure && !isExpanded && !hideMode\n    ? source.value.split(/\\r?\\n/).slice(0, initial).join(\"\\n\")\n    : source.value;\n  const rendered = source.value.length === 0\n    ? <span className=\"ui-snippet-empty\">{source.emptyLabel ?? \"No source.\"}</span>\n    : contentType === \"code\" ? <SyntaxCode value={visibleValue} totalLines={lines} language={source.language ?? language} inline={variant === \"inline\"} /> : <span className=\"ui-snippet-text\">{visibleValue}</span>;\n  const copyControl = <TooltipHint content={copyHint}><IconButton type=\"button\" variant={variant === \"inline\" || headerHasActions ? \"ghost\" : \"glass\"} size={copySize} icon={status === \"copied\" ? <Check /> : <Copy />} aria-label={copyLabel} disabled={!canCopy} onClick={handleCopy} /></TooltipHint>;\n  const disclosure = hasDisclosure ? <Button type=\"button\" variant=\"ghost\" size={disclosureSize} trailingIcon={isExpanded ? <ChevronUp /> : <ChevronDown />} onClick={toggleExpanded} aria-expanded={isExpanded} aria-controls={hideMode ? contentId : undefined}>{isExpanded ? collapseLabel : expandLabel}</Button> : null;\n  const sourceControl = sourceHref ? <TooltipHint content=\"View example on GitHub\"><a href={sourceHref} className={buttonVariants({variant:\"ghost\",size:\"icon-xs\"})} aria-label=\"View example on GitHub\"><Github aria-hidden=\"true\" /></a></TooltipHint> : null;\n  const assetControl = assetsHref ? <TooltipHint content=\"Download example assets\"><a href={assetsHref} download className={buttonVariants({variant:\"ghost\",size:\"icon-xs\"})} aria-label=\"Download example assets\"><Download aria-hidden=\"true\" /></a></TooltipHint> : null;\n  const headerContents = <>\n    <div className=\"ui-snippet-header-leading\">\n      {title || icon ? <div className=\"ui-snippet-heading\">{icon ? <span className=\"ui-snippet-heading-icon\" aria-hidden=\"true\">{icon}</span> : null}{title ? <span>{title}</span> : null}</div> : null}\n      {sources && availableSources.length > 0 ? <Tabs.Root value={sourceId} onValueChange={(next) => setSource(String(next))} variant={sourceTabVariant} size={sourceTabSize}><Tabs.List aria-label=\"Snippet sources\" activateOnFocus={sourceTabsActivateOnFocus}>{availableSources.map((item) => <TooltipHint key={item.id} content={item.filename}><Tabs.Tab className=\"ui-snippet-source-tab\" value={item.id} aria-label={item.filename ? `${item.label} source, ${item.filename}` : undefined}>{item.icon ? <span aria-hidden=\"true\">{item.icon}</span> : null}{item.label}</Tabs.Tab></TooltipHint>)}</Tabs.List></Tabs.Root> : null}\n    </div>\n    {headerHasActions ? <div className=\"ui-snippet-actions\">{sourceControl}{disclosure}{assetControl}{!hideMode || isExpanded ? copyControl : null}</div> : null}\n  </>;\n  const header = hasHeader ? <div className=\"ui-snippet-header\">{headerContents}</div> : null;\n\n  if (variant === \"inline\") {\n    return <span className={[\"ui-snippet\", \"ui-snippet--inline\", `ui-snippet--${contentType}`, className].filter(Boolean).join(\" \")} data-inline-copy={inlineCopy} data-copy-visibility={copyVisibility} data-copy-status={status} data-expanded={isExpanded || undefined}>\n      <TooltipHint content={copyHint}><Button type=\"button\" variant=\"text\" className=\"ui-snippet-inline-trigger\" disabled={!canCopy} onClick={handleCopy} aria-label={`${copyLabel}: ${source.value}`}>\n        <span className=\"ui-snippet-inline-value\">{rendered}</span>\n        {inlineCopy !== \"value\" ? <span className=\"ui-snippet-inline-icon\" aria-hidden=\"true\">{status === \"copied\" ? <Check /> : <Copy />}</span> : null}\n      </Button></TooltipHint>\n      <span className=\"ui-snippet-status\" role={status === \"failed\" ? \"alert\" : \"status\"} aria-live=\"polite\">{status === \"copied\" ? \"Copied.\" : status === \"failed\" ? \"Copy failed. Select and copy the text manually.\" : \"\"}</span>\n    </span>;\n  }\n\n  const bodyContents = <><ScrollArea.Root className=\"ui-snippet-scroll\"><ScrollArea.Viewport className=\"ui-snippet-viewport\"><ScrollArea.Content className=\"ui-snippet-content\">{children ?? rendered}</ScrollArea.Content></ScrollArea.Viewport><ScrollArea.Scrollbar orientation=\"vertical\" aria-hidden=\"true\"><ScrollArea.Thumb /></ScrollArea.Scrollbar></ScrollArea.Root>{!headerHasActions && !children ? <div className=\"ui-snippet-copy\">{copyControl}</div> : null}</>;\n  const body = <div className=\"ui-snippet-body\" data-expanded={isExpanded || undefined}>{bodyContents}</div>;\n\n  const rootClassName = [\"ui-snippet\", `ui-snippet--${variant}`, `ui-snippet--${contentType}`, className].filter(Boolean).join(\" \");\n  const rootStyle = { \"--snippet-scroll-lines\": scrollLines } as React.CSSProperties;\n  const renderedBody = hideMode ? <div id={contentId} hidden={!isExpanded}>{isExpanded ? body : null}</div> : body;\n  const contents = <>{header}{renderedBody}{!headerHasActions ? disclosure : null}<span className=\"ui-snippet-status\" role={status === \"failed\" ? \"alert\" : \"status\"} aria-live=\"polite\">{status === \"copied\" ? `${source.copiedLabel ?? \"Copied\"}.` : status === \"failed\" ? `${source.copyFailedLabel ?? \"Copy failed\"}. Select and copy the text manually.` : \"\"}</span></>;\n  return <div className={rootClassName} data-appearance={appearance} data-copy-visibility={copyVisibility} data-copy-revealed={copyRevealed || undefined} onPointerDown={() => { if (copyVisibility === \"hover\") setCopyRevealed(true); }} onPointerLeave={(event) => { if (event.pointerType === \"mouse\") setCopyRevealed(false); }} onBlur={(event) => { if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setCopyRevealed(false); }} data-header-separator={hasHeader ? headerSeparator : undefined} data-content-hidden={hideMode && !isExpanded || undefined} data-expanded={isExpanded || undefined} data-collapsed={hasDisclosure && !isExpanded || undefined} data-source-filename={source.filename || undefined} data-source-language={source.language ?? language} style={rootStyle}>{contents}</div>;\n}\n"
    },
    {
      "path": "src/components/ui/snippet.css",
      "type": "registry:file",
      "target": "@ui/snippet.css",
      "content": ".ui-snippet { --snippet-text-size: var(--font-size-mono-caption); --snippet-scroll-lines: 24; --snippet-copy-size: var(--space-6); position: relative; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; min-width: 0; overflow: hidden; color: var(--foreground); }\n.ui-snippet:not(.ui-snippet--inline) { border: var(--snippet-surface-border-width, 0px) solid var(--snippet-surface-border, var(--border)); border-radius: var(--radius-lg); background: var(--snippet-surface-background, var(--secondary)); }\n.ui-snippet[data-appearance=\"subtle\"]:not(.ui-snippet--inline) { border: 0; background: var(--secondary); }\n.ui-snippet[data-appearance=\"outline\"]:not(.ui-snippet--inline) { border: 1px solid var(--border); background: transparent; }\n.ui-snippet-header { display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: var(--space-3); min-width: 0; min-height: var(--space-8); padding: var(--space-2) var(--space-3); border-bottom: 0; background: transparent; font-family: var(--font-sans); }\n.ui-snippet-header-leading { display: inline-flex; align-items: center; flex-wrap: nowrap; flex: 1 1 auto; gap: var(--space-3); min-width: 0; }\n.ui-snippet-header-leading > .ui-snippet-heading { flex: none; }\n.ui-snippet-header-leading > .ui-tabs { flex: 0 1 auto; overflow: hidden; }\n.ui-snippet-header-leading .ui-tabs-list { min-width: 0; }\n.ui-snippet-heading, .ui-snippet-actions { display: inline-flex; align-items: center; gap: var(--space-2); min-width: 0; }\n.ui-snippet-heading { color: var(--muted-foreground); font-size: var(--font-size-caption); line-height: calc(var(--font-size-caption) * 1.5); font-weight: var(--font-weight-regular); }\n.ui-snippet-body { position: relative; min-width: 0; }\n/* Clip the content itself so viewport padding cannot reveal the next code line. */\n.ui-snippet[data-collapsed] .ui-snippet-content { max-height: calc(var(--snippet-scroll-lines) * var(--snippet-text-size) * var(--leading-copy)); overflow-y: clip; }\n.ui-snippet-scroll.ui-scroll { height: auto; min-width: 0; width: 100%; }\n/* Let page scrolling continue at the first and last code lines. */\n.ui-snippet-scroll > .ui-snippet-viewport { overscroll-behavior-y: auto; }\n.ui-snippet-viewport { box-sizing: border-box; max-height: calc(var(--snippet-scroll-lines) * var(--snippet-text-size) * var(--leading-copy) + var(--space-3) * 2); min-width: 0; padding: var(--space-3); overflow-x: auto; }\n.ui-snippet-text { display: block; min-width: max-content; font: var(--snippet-text-size)/var(--leading-copy) var(--font-mono); white-space: pre; }\n.ui-snippet-empty { display: block; color: var(--muted-foreground); font-family: var(--font-sans); font-size: var(--font-size-sm); line-height: calc(var(--font-size-caption) * var(--leading-copy)); font-style: italic; }\n.ui-snippet--text { --snippet-text-size: var(--font-size-caption); }\n.ui-snippet--text .ui-snippet-text { font-family: var(--font-sans); white-space: pre-wrap; min-width: 0; }\n.ui-snippet-copy { position: absolute; top: var(--space-2); inset-inline-end: var(--space-3); z-index: 1; display: inline-flex; }\n.ui-snippet-body > .ui-snippet-copy { top: max(0px, calc(var(--space-3) + (var(--snippet-text-size) * var(--leading-copy) - var(--snippet-copy-size)) / 2)); }\n.ui-snippet--inline { --snippet-text-size: var(--font-size-mono-inline); display: inline; vertical-align: baseline; max-width: 100%; overflow: visible; border: 0; border-radius: 0; background: transparent; font-family: var(--font-mono); }\n.ui-snippet-inline-value { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }\n.ui-snippet--inline .ui-snippet-text { display: inline; min-width: 0; white-space: pre-wrap; }\n.ui-snippet--inline .ui-button.ui-snippet-inline-trigger { position: relative; display: inline; width: auto; height: auto; min-height: 0; padding: 0; border: 0; border-radius: var(--radius-sm); overflow: visible; background: transparent; color: inherit; font: inherit; line-height: inherit; text-align: inherit; white-space: normal; vertical-align: baseline; transform: none; }\n.ui-snippet--inline .ui-button.ui-snippet-inline-trigger:is(:hover, :focus-visible, :active) { padding: 0; background: transparent; outline: none; transform: none; }\n.ui-snippet-inline-trigger:is(:hover, :focus-visible) .ui-snippet-inline-value { text-decoration-line: underline; text-decoration-thickness: var(--focus-border-width); text-underline-offset: 3px; }\n.ui-snippet-inline-icon { display: inline-flex; align-items: center; justify-content: center; width: var(--snippet-copy-size); height: var(--snippet-copy-size); margin-inline-start: var(--space-1); vertical-align: middle; line-height: 0; }\n.ui-snippet-inline-icon svg { width: var(--icon-size-sm); height: var(--icon-size-sm); stroke-width: var(--icon-stroke); }\n.ui-snippet[data-inline-copy=\"floating\"] .ui-snippet-inline-icon { position: absolute; inset-inline-start: 100%; top: 50%; transform: translateY(-50%); margin: 0; border-radius: var(--radius-control-xs); background: color-mix(in oklab, var(--secondary) 80%, transparent); color: var(--secondary-foreground); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }\n.ui-snippet[data-copy-visibility=\"hover\"] > .ui-snippet-body > .ui-snippet-copy,\n.ui-snippet[data-copy-visibility=\"hover\"][data-inline-copy=\"floating\"] .ui-snippet-inline-icon { opacity: 0; pointer-events: none; }\n.ui-snippet[data-copy-visibility=\"hover\"]:is(:focus-within, [data-copy-revealed=\"true\"]) > .ui-snippet-body > .ui-snippet-copy,\n.ui-snippet[data-copy-visibility=\"hover\"][data-inline-copy=\"floating\"]:is(:focus-within, [data-copy-status=\"copied\"]) .ui-snippet-inline-icon { opacity: 1; pointer-events: auto; }\n@media (hover: hover) and (pointer: fine) {\n  .ui-snippet[data-copy-visibility=\"hover\"]:hover > .ui-snippet-body > .ui-snippet-copy,\n  .ui-snippet[data-copy-visibility=\"hover\"][data-inline-copy=\"floating\"]:hover .ui-snippet-inline-icon { opacity: 1; pointer-events: auto; }\n}\n.ui-snippet-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }\n\n.ui-snippet-actions { margin-inline-start: auto; flex-shrink: 0; }\n.ui-snippet-actions > a.ui-button { color: var(--foreground); text-decoration: none; }\n\n.ui-snippet-heading svg, .ui-snippet-actions svg { width: var(--icon-size); height: var(--icon-size); stroke-width: var(--icon-stroke); flex: none; }\n\n\n.ui-snippet[data-header-separator=\"true\"]:not([data-content-hidden]) .ui-snippet-header { border-bottom: 1px solid var(--border); }\n.ui-snippet-source-tab { font-family: var(--font-mono); font-size: var(--font-size-mono-caption); font-weight: var(--font-weight-regular); }\n\n.ui-snippet-heading-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; line-height: 0; }\n\n/* Action feedback adapts to the snippet surface in both color modes. */\n.ui-snippet-actions > .ui-button,\n.ui-snippet-copy > .ui-button,\n.ui-snippet > .ui-button {\n  --quiet-hover: color-mix(in oklab, var(--foreground) 8%, transparent);\n  --quiet-active: color-mix(in oklab, var(--foreground) 12%, transparent);\n  --control-selected-background: transparent;\n}\n\n/* Glass copy controls need their own contrast against the Snippet surface. */\n@media (hover: hover) and (pointer: fine) {\n  .ui-snippet-copy > .ui-button--glass:hover:not(:disabled):not([data-disabled]) {\n    --ui-button-glass-fill: color-mix(in oklab, var(--foreground) 8%, var(--secondary));\n  }\n}\n.ui-snippet-copy > .ui-button--glass:active:not(:disabled):not([data-disabled]) {\n  --ui-button-glass-fill: color-mix(in oklab, var(--foreground) 12%, var(--secondary));\n}\n\n/* Disclosure stays unfilled when idle, including while expanded. */\n@media (hover: hover) {\n  .ui-snippet-actions > .ui-button:hover,\n  .ui-snippet > .ui-button:hover {\n    --control-selected-background: var(--quiet-hover);\n  }\n}\n\n.ui-snippet-actions > .ui-button:active,\n.ui-snippet > .ui-button:active {\n  --control-selected-background: var(--quiet-active);\n}\n\n.ui-snippet-status[role=\"alert\"] {\n  position: static;\n  width: auto;\n  height: auto;\n  overflow: visible;\n  clip: auto;\n  padding: var(--space-2) var(--space-3);\n  color: var(--destructive);\n  font: var(--font-size-caption)/var(--leading-copy) var(--font-sans);\n}\n.ui-snippet--inline:has(> .ui-snippet-status[role=\"alert\"]) { flex-wrap: wrap; }\n.ui-snippet--inline > .ui-snippet-status[role=\"alert\"] { flex-basis: 100%; padding: var(--space-1) 0 0; }\n"
    },
    {
      "path": "src/components/ui/snippet-copy.ts",
      "type": "registry:component",
      "target": "@ui/snippet-copy.ts",
      "content": "/** Copy a complete value and report only a verified write. */\nexport async function copySnippetValue(value: string | Promise<string>): Promise<void> {\n  if (typeof value !== \"string\") {\n    // Start the write inside the user gesture; Safari permits promised ClipboardItem data.\n    if (typeof ClipboardItem !== \"undefined\" && typeof navigator !== \"undefined\" && navigator.clipboard?.write) {\n      await navigator.clipboard.write([new ClipboardItem({ \"text/plain\": value.then(text => new Blob([text], { type: \"text/plain\" })) })]);\n      return;\n    }\n    return copySnippetValue(await value);\n  }\n  if (typeof navigator !== \"undefined\" && navigator.clipboard?.writeText) {\n    try { await navigator.clipboard.writeText(value); return; } catch { /* use the DOM fallback */ }\n  }\n  if (typeof document === \"undefined\") throw new Error(\"Clipboard unavailable\");\n  const textarea = document.createElement(\"textarea\");\n  const previousActive = document.activeElement as HTMLElement | null;\n  textarea.value = value;\n  textarea.setAttribute(\"readonly\", \"\");\n  textarea.style.position = \"fixed\";\n  textarea.style.opacity = \"0\";\n  textarea.style.fontSize = \"16px\";\n  document.body.appendChild(textarea);\n  textarea.select();\n  try {\n    if (!document.execCommand(\"copy\")) throw new Error(\"Copy failed\");\n  } finally {\n    textarea.remove();\n    if (previousActive && previousActive.isConnected) previousActive.focus();\n  }\n}\n"
    },
    {
      "path": "src/components/ui/syntax-code.tsx",
      "type": "registry:component",
      "target": "@ui/syntax-code.tsx",
      "content": "\"use client\";\nimport * as React from \"react\";\nimport \"./syntax-code.css\";\n\nfunction PlainCode({value}: {value:string}) { return <code className=\"ui-syntax-code__code\">{value}</code>; }\n// Highlighting is optional: a failed chunk must leave readable, copyable source.\nconst SyntaxHighlight = React.lazy(() => import(\"./syntax-highlight\").catch(() => ({default:PlainCode})));\n\nexport interface SyntaxCodeProps {\n  value: string;\n  language?: string;\n  inline?: boolean;\n  /** Original logical line count when value is a truncated source preview. */\n  totalLines?: number;\n}\n\n/** Count source lines without letting terminal delimiters create visual lines. */\nexport function logicalLineCount(value: string): number {\n  const withoutTerminalDelimiters = value.replace(/(?:\\r\\n|\\n)+$/, \"\");\n  return withoutTerminalDelimiters.length === 0 ? 0 : withoutTerminalDelimiters.split(/\\r\\n|\\n/).length;\n}\n\nexport function SyntaxCode({value,language,inline=false,totalLines=logicalLineCount(value)}: SyntaxCodeProps) {\n  const container = React.useRef<HTMLElement | null>(null);\n  const [visible, setVisible] = React.useState(false);\n  const lineNumbers = !inline && totalLines > 1;\n  const visibleLines = Math.min(totalLines, value.split(/\\r?\\n/).length);\n  React.useEffect(() => {\n    if (!container.current) return;\n    if (typeof IntersectionObserver === \"undefined\") { setVisible(true); return; }\n    const observer = new IntersectionObserver(entries => {\n      if (entries.some(entry => entry.isIntersecting)) {\n        setVisible(true);\n        observer.disconnect();\n      }\n    }, { rootMargin: \"200px\" });\n    observer.observe(container.current);\n    return () => observer.disconnect();\n  }, []);\n\n  const content = visible ? <React.Suspense fallback={<PlainCode value={value}/>}><SyntaxHighlight value={value} language={language}/></React.Suspense> : <PlainCode value={value}/>;\n  if (inline) return <span ref={node=>{container.current=node;}} className=\"ui-syntax-code ui-syntax-code--inline\">{content}</span>;\n  return <pre ref={node=>{container.current=node;}} className=\"ui-syntax-code\">\n    {lineNumbers && <span className=\"ui-syntax-code__numbers\" aria-hidden=\"true\">{Array.from({length:visibleLines},(_,index)=><span key={index}>{index+1}</span>)}</span>}\n    {content}\n  </pre>;\n}\n"
    },
    {
      "path": "src/components/ui/syntax-code.css",
      "type": "registry:file",
      "target": "@ui/syntax-code.css",
      "content": ".ui-syntax-code {\n  display: flow-root;\n  min-width: max-content;\n  margin: 0;\n  overflow: visible;\n  padding: 0;\n  color: var(--foreground);\n  font: var(--snippet-text-size, var(--font-size-mono-caption))/var(--leading-copy) var(--font-mono);\n  -webkit-text-size-adjust: 100%;\n  text-size-adjust: 100%;\n  white-space: pre;\n}\n\n.ui-syntax-code--inline {\n  font-size: var(--font-size-mono-inline);\n  display: inline;\n  min-width: 0;\n  white-space: pre-wrap;\n}\n\n.ui-syntax-code__code {\n  display: inline;\n  font: inherit;\n  white-space: inherit;\n}\n\n.ui-syntax-code__highlight {\n  display: inline;\n  font: inherit;\n  white-space: inherit;\n}\n\n.ui-syntax-code__numbers {\n  font: inherit;\n  display: inline-flex;\n  flex-direction: column;\n  float: inline-start;\n  min-width: 2ch;\n  padding-inline-end: var(--space-3);\n  color: var(--muted-foreground);\n  text-align: end;\n  user-select: none;\n}\n\n.ui-syntax-code__numbers span {\n  display: block;\n}\n\n.ui-syntax-code--inline .ui-syntax-code__code {\n  display: inline;\n}\n\n.ui-syntax-code .react-syntax-highlighter-line-number {\n  color: var(--muted-foreground);\n}\n"
    },
    {
      "path": "src/components/ui/syntax-highlight.tsx",
      "type": "registry:component",
      "target": "@ui/syntax-highlight.tsx",
      "content": "\"use client\";\nimport * as React from \"react\";\nimport type { SyntaxCodeProps } from \"./syntax-code\";\nimport { PrismLight as SyntaxHighlighter } from \"react-syntax-highlighter\";\n// react-syntax-highlighter ships these runtime grammar modules without declarations.\n// @ts-expect-error The package has no declaration for grammar modules.\nimport bash from \"react-syntax-highlighter/dist/esm/languages/prism/bash.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport css from \"react-syntax-highlighter/dist/esm/languages/prism/css.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport javascript from \"react-syntax-highlighter/dist/esm/languages/prism/javascript.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport json from \"react-syntax-highlighter/dist/esm/languages/prism/json.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport markup from \"react-syntax-highlighter/dist/esm/languages/prism/markup.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport tsx from \"react-syntax-highlighter/dist/esm/languages/prism/tsx.js\";\n// @ts-expect-error The package has no declaration for grammar modules.\nimport typescript from \"react-syntax-highlighter/dist/esm/languages/prism/typescript.js\";\n// The runtime package requires the explicit ESM extension; its type package omits it.\n// @ts-expect-error The package declaration omits the runtime .js subpath.\nimport oneDark from \"react-syntax-highlighter/dist/esm/styles/prism/one-dark.js\";\n// @ts-expect-error The package declaration omits the runtime .js subpath.\nimport oneLight from \"react-syntax-highlighter/dist/esm/styles/prism/one-light.js\";\n\nconst grammars = {\n  bash,\n  css,\n  html: markup,\n  javascript,\n  jsx: tsx,\n  json,\n  markdown: markup,\n  tsx,\n  typescript,\n} as const;\n\nconst aliases: Record<string, keyof typeof grammars> = { js: \"javascript\", ts: \"typescript\" };\nconst registeredLanguages = new Set(Object.keys(grammars));\n\nfor (const [language, grammar] of Object.entries(grammars)) {\n  SyntaxHighlighter.registerLanguage(language, grammar);\n}\nSyntaxHighlighter.alias(\"typescript\", \"ts\");\nSyntaxHighlighter.alias(\"javascript\", \"js\");\n\nfunction isDarkTheme() {\n  if (typeof document === \"undefined\") return false;\n  const root = document.documentElement;\n  return root.dataset.theme === \"dark\" || root.dataset.uiTheme === \"dark\" || root.classList.contains(\"dark\");\n}\n\nfunction languageId(language: string | undefined) {\n  const normalized = (language ?? \"\").trim().toLowerCase().replace(/^language-/, \"\");\n  return aliases[normalized] ?? normalized;\n}\n\nexport default function SyntaxHighlight({value,language}: SyntaxCodeProps) {\n  const [darkTheme, setDarkTheme] = React.useState(isDarkTheme);\n  const normalizedLanguage = languageId(language);\n  const highlightLanguage = registeredLanguages.has(normalizedLanguage) ? normalizedLanguage : \"text\";\n  const codeStyle: React.CSSProperties = {\n    background: \"transparent\",\n    fontFamily: \"var(--font-mono)\",\n    fontSize: \"inherit\",\n    lineHeight: \"var(--leading-copy)\",\n  };\n\n  React.useEffect(() => {\n    if (typeof document === \"undefined\") return undefined;\n    const root = document.documentElement;\n    const syncTheme = () => setDarkTheme(isDarkTheme());\n    const observer = new MutationObserver(syncTheme);\n    observer.observe(root, { attributes: true, attributeFilter: [\"class\", \"data-theme\", \"data-ui-theme\"] });\n    syncTheme();\n    return () => observer.disconnect();\n  }, []);\n\n  const highlighted = (\n    <SyntaxHighlighter\n      className=\"ui-syntax-code__highlight\"\n      language={highlightLanguage}\n      style={darkTheme ? oneDark : oneLight}\n      customStyle={{\n        background: \"transparent\",\n        fontFamily: \"var(--font-mono)\",\n        fontSize: \"inherit\",\n        lineHeight: \"var(--leading-copy)\",\n        color: \"inherit\",\n        margin: 0,\n        overflow: \"visible\",\n        padding: 0,\n        borderRadius: 0,\n      }}\n      codeTagProps={{ className: \"ui-syntax-code__code\", style: codeStyle }}\n      showLineNumbers={false}\n      PreTag=\"span\"\n      CodeTag=\"code\"\n    >\n      {value}\n    </SyntaxHighlighter>\n  );\n\n  return highlighted;\n}\n"
    }
  ]
}
