{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "redline-handoff-demo",
  "type": "registry:block",
  "title": "Redline: Dev Handoff",
  "description": "Spacing Inspector Overlay example, Dev Handoff: A design tool's handoff mode. `onSelect` fills the panel on the right with the CSS and the Tailwind classes of whatever layer is selected, and it swaps as you move. A take on the annotation (arrow). Fits features and docs sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "features",
    "docs",
    "annotation",
    "tooltip",
    "inspector",
    "hover",
    "design"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/redline#redline-handoff-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/redline.json"
  ],
  "files": [
    {
      "path": "components/redline-handoff-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Redline, type RedlineSelection } from \"@/components/ui/redline\";\n\nconst features = [\"Unlimited projects\", \"Version history\", \"Priority support\"];\n\ntype Layer = { name: string; size: string; css: [string, string][]; classes: string[] };\n\nlet paint: CanvasRenderingContext2D | null | undefined;\n\n/** Computed colors come back as oklch from Tailwind; handoff wants hex. */\nfunction hex(color: string) {\n  paint ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true });\n  if (!paint) return color;\n  paint.clearRect(0, 0, 1, 1);\n  paint.fillStyle = color;\n  paint.fillRect(0, 0, 1, 1);\n  const [r, g, b, a] = paint.getImageData(0, 0, 1, 1).data;\n  if (a === 0) return null;\n  const pair = (n: number) => n.toString(16).padStart(2, \"0\");\n  return `#${pair(r)}${pair(g)}${pair(b)}${a < 255 ? pair(a) : \"\"}`.toUpperCase();\n}\n\nconst px = (value: number) => (value ? `${value}px` : \"0\");\n\n/** The CSS a developer needs for one layer, from its measurements and computed style. */\nfunction layerOf(selection: RedlineSelection): Layer {\n  const { element, width, height, padding, gap, text } = selection;\n  const cs = getComputedStyle(element);\n  const css: [string, string][] = [\n    [\"width\", `${width}px`],\n    [\"height\", `${height}px`],\n  ];\n  if (gap) {\n    css.push([\"display\", cs.display]);\n    if (cs.display.endsWith(\"flex\") && cs.flexDirection !== \"row\") {\n      css.push([\"flex-direction\", cs.flexDirection]);\n    }\n    if (cs.alignItems !== \"normal\" && cs.alignItems !== \"stretch\") css.push([\"align-items\", cs.alignItems]);\n    const both = gap.row === gap.column ? [gap.row] : [gap.row, gap.column];\n    if (gap.row || gap.column) css.push([\"gap\", both.map(px).join(\" \")]);\n  }\n  const { top, right, bottom, left } = padding;\n  if (top || right || bottom || left) {\n    const sides =\n      top === bottom && left === right\n        ? top === left\n          ? [top]\n          : [top, right]\n        : [top, right, bottom, left];\n    css.push([\"padding\", sides.map(px).join(\" \")]);\n  }\n  if (parseFloat(cs.borderTopLeftRadius)) css.push([\"border-radius\", cs.borderTopLeftRadius]);\n  const background = hex(cs.backgroundColor);\n  if (background) css.push([\"background\", background]);\n  if (text) {\n    const leading = text.lineHeight ? `/${text.lineHeight}px` : \"\";\n    css.push([\"font\", `${text.weight} ${text.size}px${leading} ${text.font}`]);\n    if (text.letterSpacing) css.push([\"letter-spacing\", `${Math.round(text.letterSpacing * 10) / 1000}em`]);\n    css.push([\"color\", text.color]);\n  }\n  return {\n    name: selection.name ?? element.tagName.toLowerCase(),\n    size: `${width} × ${height}`,\n    css,\n    classes: (element.getAttribute(\"class\") ?? \"\").split(/\\s+/).filter(Boolean),\n  };\n}\n\nexport function RedlineHandoffDemo() {\n  const [layer, setLayer] = React.useState<Layer | null>(null);\n  const [copied, setCopied] = React.useState(false);\n\n  React.useEffect(() => {\n    if (!copied) return;\n    const timer = window.setTimeout(() => setCopied(false), 1400);\n    return () => window.clearTimeout(timer);\n  }, [copied]);\n\n  const copy = () => {\n    if (!layer) return;\n    const text = layer.css.map(([property, value]) => `${property}: ${value};`).join(\"\\n\");\n    navigator.clipboard?.writeText(text).then(() => setCopied(true), () => {});\n  };\n\n  return (\n    <div className=\"w-full max-w-4xl overflow-hidden rounded-2xl border border-zinc-200 bg-white text-zinc-900 shadow-sm dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50\">\n      <div className=\"flex h-11 items-center justify-between gap-4 border-b border-zinc-200 px-4 text-xs dark:border-zinc-800\">\n        <p className=\"truncate text-zinc-500\">\n          Pricing <span className=\"px-1 text-zinc-300 dark:text-zinc-700\">/</span>\n          <span className=\"font-medium text-zinc-900 dark:text-zinc-100\">Pro plan</span>\n        </p>\n        <div className=\"flex shrink-0 rounded-md bg-zinc-100 p-0.5 font-medium dark:bg-zinc-900\">\n          <span className=\"px-2.5 py-1 text-zinc-500\">Design</span>\n          <span className=\"rounded-[5px] bg-white px-2.5 py-1 shadow-sm dark:bg-zinc-800\">Dev Mode</span>\n        </div>\n      </div>\n\n      <div className=\"grid md:grid-cols-[minmax(0,1fr)_18rem]\">\n        <Redline\n          tour={[\"Plan\", \"Price\", \"Features\", \"Button\"]}\n          selector=\"[data-redline]\"\n          onSelect={(selection) => selection && setLayer(layerOf(selection))}\n          aria-label=\"Pro plan card\"\n          className=\"flex items-center justify-center bg-zinc-100 bg-[radial-gradient(circle,rgb(0_0_0/0.07)_1px,transparent_1px)] bg-size-[16px_16px] px-6 py-12 dark:bg-zinc-900/60 dark:bg-[radial-gradient(circle,rgb(255_255_255/0.06)_1px,transparent_1px)]\"\n        >\n          <div\n            data-redline=\"Plan\"\n            className=\"flex w-64 flex-col gap-6 rounded-2xl bg-white p-6 shadow-sm ring-1 ring-zinc-950/5 dark:bg-zinc-950 dark:ring-white/10\"\n          >\n            <div data-redline=\"Header\" className=\"flex flex-col gap-2\">\n              <span\n                data-redline=\"Badge\"\n                className=\"w-fit rounded-full bg-violet-100 px-2 py-0.5 text-xs font-medium text-violet-700 dark:bg-violet-500/15 dark:text-violet-300\"\n              >\n                Pro\n              </span>\n              <p data-redline=\"Price\" className=\"text-4xl/10 font-semibold tracking-tight\">\n                $24\n                <span className=\"text-sm font-normal tracking-normal text-zinc-500\"> / month</span>\n              </p>\n              <p data-redline=\"Blurb\" className=\"text-sm/5 text-zinc-500 dark:text-zinc-400\">\n                For teams that ship every week.\n              </p>\n            </div>\n            <ul data-redline=\"Features\" className=\"flex flex-col gap-2.5 text-sm/5\">\n              {features.map((feature) => (\n                <li key={feature} data-redline={feature} className=\"flex items-center gap-2\">\n                  <svg\n                    viewBox=\"0 0 16 16\"\n                    aria-hidden\n                    className=\"size-4 fill-none stroke-violet-600 stroke-2 dark:stroke-violet-400\"\n                    strokeLinecap=\"round\"\n                    strokeLinejoin=\"round\"\n                  >\n                    <path d=\"m3.5 8.5 3 3 6-7\" />\n                  </svg>\n                  {feature}\n                </li>\n              ))}\n            </ul>\n            <button\n              data-redline=\"Button\"\n              type=\"button\"\n              className=\"h-11 rounded-[10px] bg-zinc-900 px-4 text-sm font-medium text-white dark:bg-zinc-50 dark:text-zinc-900\"\n            >\n              Start free trial\n            </button>\n          </div>\n        </Redline>\n\n        <aside className=\"flex min-h-80 flex-col border-t border-zinc-200 text-xs md:border-t-0 md:border-l dark:border-zinc-800\">\n          {layer ? (\n            <>\n              <div className=\"flex items-baseline justify-between gap-3 border-b border-zinc-200 px-4 py-3 dark:border-zinc-800\">\n                <p className=\"truncate text-sm font-medium\">{layer.name}</p>\n                <p className=\"shrink-0 font-mono text-zinc-500 tabular-nums\">{layer.size}</p>\n              </div>\n\n              <div className=\"border-b border-zinc-200 px-4 py-3 dark:border-zinc-800\">\n                <div className=\"flex items-center justify-between\">\n                  <p className=\"font-medium text-zinc-500\">CSS</p>\n                  <button\n                    type=\"button\"\n                    onClick={copy}\n                    className=\"rounded px-1.5 py-0.5 font-medium text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 focus-visible:ring-2 focus-visible:ring-zinc-400 focus-visible:outline-none dark:hover:bg-zinc-900 dark:hover:text-zinc-100\"\n                  >\n                    {copied ? \"Copied\" : \"Copy\"}\n                  </button>\n                </div>\n                <pre className=\"mt-2 overflow-x-auto font-mono text-[12px]/5\">\n                  {layer.css.map(([property, value]) => (\n                    <div key={property}>\n                      <span className=\"text-sky-700 dark:text-sky-300\">{property}</span>\n                      <span className=\"text-zinc-400\">: </span>\n                      <span>{value}</span>\n                      <span className=\"text-zinc-400\">;</span>\n                    </div>\n                  ))}\n                </pre>\n              </div>\n\n              <div className=\"px-4 py-3\">\n                <p className=\"font-medium text-zinc-500\">Tailwind</p>\n                <div className=\"mt-2 flex flex-wrap gap-1\">\n                  {layer.classes.map((name) => (\n                    <code\n                      key={name}\n                      className=\"rounded bg-zinc-100 px-1.5 py-0.5 font-mono text-[11px] text-zinc-700 dark:bg-zinc-900 dark:text-zinc-300\"\n                    >\n                      {name}\n                    </code>\n                  ))}\n                </div>\n              </div>\n            </>\n          ) : (\n            <p className=\"m-auto px-6 text-center text-zinc-500\">\n              Point at a layer to see its CSS and Tailwind classes.\n            </p>\n          )}\n        </aside>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}