{
  "name": "cai-blog-client",
  "type": "registry:ui",
  "description": "Interactive half of the CAI blog kit: brand duotone image filter, collapsible tag rail and reading progress (client components)",
  "files": [
    {
      "path": "components/ui/cai-blog-client.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport Link from \"next/link\"\n\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Interactive half of the CAI blog kit (hooks, event handlers). Import from\n * \"@/components/ui/cai-blog\", which re-exports these alongside the\n * server-safe layout pieces and helpers.\n */\n\nfunction sizedSrc(src: string, width: number) {\n  if (!src.includes(\"images.unsplash.com\")) return src\n  const [base] = src.split(\"?\")\n  return `${base}?auto=format&fit=crop&w=${width}&q=72`\n}\n\n// ─── Brand image filter ──────────────────────────────────────────────────\n\nexport type CaiImageTone = \"emerald\" | \"mono\" | \"natural\"\n\n// Duotone transfer tables, channel by channel: shadow (Void #161717) ->\n// mid (Emerald-500 #0f7b4e / Charcoal #2c2f2e) -> highlight (Mint / Pearl #eff0f0).\nconst TONE_TABLES: Record<Exclude<CaiImageTone, \"natural\">, { r: string; g: string; b: string }> = {\n  emerald: { r: \"0.086 0.059 0.82\", g: \"0.090 0.482 0.95\", b: \"0.090 0.306 0.88\" },\n  mono: { r: \"0.086 0.173 0.937\", g: \"0.090 0.184 0.941\", b: \"0.090 0.180 0.941\" },\n}\n\ntype CaiBrandImageProps = {\n  src: string\n  alt: string\n  tone?: CaiImageTone\n  /** Rendered width hint used for Unsplash sizing. */\n  width?: number\n  priority?: boolean\n  /** On hover of a `group` ancestor, fade the original colours back in. */\n  reveal?: boolean\n  fallbackSrc?: string\n  className?: string\n  imgClassName?: string\n}\n\nexport function CaiBrandImage({\n  src,\n  alt,\n  tone = \"emerald\",\n  width = 1200,\n  priority = false,\n  reveal = false,\n  fallbackSrc = \"/opengraph-image.png\",\n  className,\n  imgClassName,\n}: CaiBrandImageProps) {\n  const filterId = `cai-duotone-${React.useId().replace(/:/g, \"\")}`\n  const [current, setCurrent] = React.useState(() => sizedSrc(src, width))\n\n  React.useEffect(() => setCurrent(sizedSrc(src, width)), [src, width])\n\n  const imgBase = cn(\n    \"absolute inset-0 h-full w-full object-cover transition-transform duration-[1200ms] ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:scale-[1.045] motion-reduce:transition-none motion-reduce:group-hover:scale-100\",\n    imgClassName,\n  )\n  const imgProps = {\n    alt,\n    src: current,\n    loading: priority ? (\"eager\" as const) : (\"lazy\" as const),\n    fetchPriority: priority ? (\"high\" as const) : undefined,\n    decoding: \"async\" as const,\n    onError: () => setCurrent(fallbackSrc),\n  }\n  const table = tone === \"natural\" ? null : TONE_TABLES[tone]\n\n  return (\n    <div data-slot=\"cai-brand-image\" className={cn(\"relative overflow-hidden bg-[#161717]\", className)}>\n      {table ? (\n        <svg aria-hidden className=\"absolute h-0 w-0\" focusable=\"false\">\n          <filter id={filterId} colorInterpolationFilters=\"sRGB\">\n            <feColorMatrix type=\"matrix\" values=\"0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0\" />\n            <feComponentTransfer>\n              <feFuncR type=\"table\" tableValues={table.r} />\n              <feFuncG type=\"table\" tableValues={table.g} />\n              <feFuncB type=\"table\" tableValues={table.b} />\n            </feComponentTransfer>\n          </filter>\n        </svg>\n      ) : null}\n      <img {...imgProps} className={imgBase} style={table ? { filter: `url(#${filterId}) contrast(1.05)` } : undefined} />\n      {table && reveal ? (\n        <img\n          {...imgProps}\n          alt=\"\"\n          aria-hidden\n          loading=\"lazy\"\n          className={cn(imgBase, \"opacity-0 transition-[opacity,transform] duration-700 group-hover:opacity-100 motion-reduce:hidden\")}\n        />\n      ) : null}\n      {/* Film grain + vignette keep flat stock photos from looking flat. */}\n      <div aria-hidden className=\"pointer-events-none absolute inset-0 bg-[radial-gradient(120%_90%_at_50%_10%,transparent_40%,rgba(22,23,23,0.55))]\" />\n    </div>\n  )\n}\n\n/**\n * Tag filter rail. Shows the most-used tags first and collapses the long tail\n * behind a \"+N more\" toggle so the rail never becomes a wall of chips.\n */\nexport function CaiBlogTagRail({\n  tags,\n  activeTag,\n  tagHrefBase,\n  allHref,\n  initialVisible = 8,\n  className,\n}: {\n  tags: Array<{ label: string; count?: number }>\n  activeTag?: string\n  /** Prefix the URL-encoded tag is appended to, e.g. \"/blog?tag=\". Serializable, so server pages can pass it. */\n  tagHrefBase: string\n  allHref: string\n  initialVisible?: number\n  className?: string\n}) {\n  const [expanded, setExpanded] = React.useState(false)\n  const sorted = React.useMemo(\n    () => [...tags].sort((a, b) => (b.count ?? 0) - (a.count ?? 0) || a.label.localeCompare(b.label)),\n    [tags],\n  )\n  const active = activeTag?.toLowerCase()\n  const head = sorted.slice(0, initialVisible)\n  // Keep the active tag visible even when it lives in the collapsed tail.\n  const activeInTail = active ? sorted.slice(initialVisible).find((t) => t.label.toLowerCase() === active) : undefined\n  const visible = expanded ? sorted : activeInTail ? [...head, activeInTail] : head\n  const hidden = sorted.length - visible.length\n\n  const chip = (selected: boolean) =>\n    cn(\n      \"inline-flex items-center gap-1.5 whitespace-nowrap rounded-[2px] border px-3 py-1.5 text-xs font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-[#0f7b4e]\",\n      selected\n        ? \"border-foreground bg-foreground text-background\"\n        : \"border-foreground/15 text-muted-foreground hover:border-foreground/50 hover:text-foreground\",\n    )\n\n  return (\n    <nav aria-label=\"Filter articles by topic\" data-slot=\"cai-blog-tag-rail\" className={cn(\"-mx-1 flex flex-nowrap items-center gap-2 overflow-x-auto px-1 [scrollbar-width:none] md:flex-wrap md:overflow-visible [&::-webkit-scrollbar]:hidden\", className)}>\n      <Link href={allHref} className={chip(!active)} aria-current={!active ? \"page\" : undefined}>\n        All\n      </Link>\n      {visible.map((tag) => {\n        const selected = tag.label.toLowerCase() === active\n        return (\n          <Link key={tag.label} href={`${tagHrefBase}${encodeURIComponent(tag.label)}`} className={chip(selected)} aria-current={selected ? \"page\" : undefined}>\n            {tag.label}\n            {typeof tag.count === \"number\" ? <span className=\"font-mono text-[10px] opacity-50\">{tag.count}</span> : null}\n          </Link>\n        )\n      })}\n      {sorted.length > initialVisible ? (\n        <button\n          type=\"button\"\n          onClick={() => setExpanded((v) => !v)}\n          aria-expanded={expanded}\n          className=\"inline-flex shrink-0 items-center gap-1 whitespace-nowrap px-2 py-1.5 text-xs font-semibold text-foreground underline decoration-[#0f7b4e] underline-offset-4 outline-none focus-visible:ring-2 focus-visible:ring-[#0f7b4e]\"\n        >\n          {expanded ? \"Show fewer\" : `+${hidden} more`}\n        </button>\n      ) : null}\n    </nav>\n  )\n}\n\n/** Thin emerald bar pinned to the top of the viewport that tracks scroll. */\nexport function CaiReadingProgress({ className }: { className?: string }) {\n  const [progress, setProgress] = React.useState(0)\n\n  React.useEffect(() => {\n    let frame = 0\n    const update = () => {\n      cancelAnimationFrame(frame)\n      frame = requestAnimationFrame(() => {\n        const max = document.documentElement.scrollHeight - window.innerHeight\n        setProgress(max > 0 ? Math.min(1, window.scrollY / max) : 0)\n      })\n    }\n    update()\n    window.addEventListener(\"scroll\", update, { passive: true })\n    window.addEventListener(\"resize\", update)\n    return () => {\n      cancelAnimationFrame(frame)\n      window.removeEventListener(\"scroll\", update)\n      window.removeEventListener(\"resize\", update)\n    }\n  }, [])\n\n  return (\n    <div aria-hidden data-slot=\"cai-reading-progress\" className={cn(\"fixed inset-x-0 top-0 z-50 h-[2px] bg-transparent\", className)}>\n      <div className=\"h-full origin-left bg-[#0f7b4e] transition-transform duration-150 ease-out\" style={{ transform: `scaleX(${progress})` }} />\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ]
}