{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "manifold-bleed",
  "title": "Manifold Bleed",
  "description": "A connected app's standing grants drawn as a valve manifold: each scope is a gate valve on a supply line from your account to the app, and revoking it drains the line backward toward you only after the server confirms, leaving a hairline ghost of what was once granted.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/manifold-bleed/component.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useId, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// ManifoldBleed — a connected app's standing grants drawn as a valve\n// manifold. Each scope is one gate valve sitting right at the header where\n// it branches off the account (the reservoir, left) toward the app (right):\n// granted means the valve stands open and its line runs full of ink;\n// revoking closes the valve and drains that line BACKWARD toward the valve\n// itself, because the branch downstream of a closed valve empties, not the\n// header behind it — authority returns to its source.\n//\n// The single governing scalar per row is `fill` (0 or 1, post-ack). Every\n// other visual fact is a pure, LINEAR function of it, so no rAF tween is\n// needed anywhere — one CSS transition on stroke-dashoffset/stroke-width/\n// transform reproduces exactly what animating the scalar itself and\n// re-deriving every frame would, because linear maps commute with easing:\n//   - stroke-dashoffset = 1 - fill   (pathLength=1 line; the retreating\n//     dash edge — rounded via strokeLinecap — IS the meniscus, no separate\n//     marker needed)\n//   - stroke-width       = 1 + 2*fill (a pressurized full line reads\n//     bolder than the hairline it drains down to)\n//   - valve-handle angle  = (1 - fill) * 90deg (0 = parallel to flow/open,\n//     90 = perpendicular/closed — how a real ball/gate valve handle reads)\n// The drained pipe never disappears: its --ns-muted hairline track is\n// always rendered underneath the ink, at full length, for every scope —\n// that hairline is the permanent record of what was once granted, and the\n// list never shortens or removes a row.\n//\n// Falsifiable constraint: fill changes ONLY after the caller's\n// onGrantChange (or, absent one, a short simulated network round trip)\n// resolves. Clicking a valve does not touch `fill` — it flips a `pending`\n// flag (aria-busy, a \"…\" status word) and waits; optimistic fill on grant\n// is the deliberately forbidden shortcut, because this is the one panel\n// whose entire job is telling the truth about what access exists right\n// now. A second click on a row already in flight is ignored rather than\n// queued or raced.\n//\n// A11y: each row is a real role=switch button (native <button>, click and\n// Space/Enter both work for free) whose accessible name is the scope's own\n// label via aria-labelledby, plus aria-describedby pointing at its\n// plain-language description and aria-checked mirroring the CONFIRMED\n// state (never the optimistic click). A single shared aria-live=polite\n// region announces \"{label} granted\" / \"{label} revoked\" once the server\n// actually confirms — never on the click itself. Every pipe/valve SVG is\n// aria-hidden; the graphics are redundant encoding of the real switch\n// state and the visible \"Active\"/\"Revoked\" status word beside each row,\n// never the only carrier of it. prefers-reduced-motion drops every\n// transition — fill, stroke-width and valve angle all land on their\n// target value in one step, no drain animation, still fully legible via\n// the status word and the valve's resting position.\n//\n// Distinct from transfer-list-siphon (which MOVES members between two\n// columns as a bulk transfer gesture with beads that travel and land) and\n// from envelope-window (the one-time consent/occlusion moment before a\n// grant exists): this is the standing state afterward — a persistent flow\n// diagram of continuing draw, where revocation has a direction and always\n// leaves a drained line behind rather than removing anything from view.\n// ---------------------------------------------------------------------------\n\nexport interface ManifoldScope {\n  /** stable id, also the value threaded through onGrantChange */\n  id: string;\n  /** short scope name, e.g. \"read:repos\" — becomes the switch's accessible name */\n  label: string;\n  /** plain-language description of what this scope allows */\n  description: string;\n  /** initial granted state. Default true (most rows on a grants page start granted). */\n  defaultGranted?: boolean;\n}\n\nexport interface ManifoldBleedProps {\n  /** the connected app these scopes belong to, e.g. \"Northlake CI\" */\n  appName: string;\n  /** the scopes/permissions, rendered top to bottom in this order */\n  scopes: ManifoldScope[];\n  /**\n   * Called with the scope id and the requested next state. Resolve to\n   * confirm the change (fill then updates and the row announces); reject\n   * (or throw) to leave the grant unchanged. Omit to use a built-in\n   * simulated ~320ms round trip, useful for demos without a real backend.\n   */\n  onGrantChange?: (scopeId: string, granted: boolean) => Promise<void> | void;\n  className?: string;\n}\n\nconst ACK_MS = 320;\nconst DRAIN_MS = 600;\nconst EASE = \"cubic-bezier(0.16, 1, 0.3, 1)\"; // ease-out-expo: fast off the valve, settles slow — draining under gravity, not a linear pour\n\nfunction simulateAck(): Promise<void> {\n  return new Promise((resolve) => {\n    setTimeout(resolve, ACK_MS);\n  });\n}\n\nexport function ManifoldBleed({ appName, scopes, onGrantChange, className = \"\" }: ManifoldBleedProps) {\n  const uid = useId();\n  const [granted, setGranted] = useState<Record<string, boolean>>(() => {\n    const init: Record<string, boolean> = {};\n    for (const scope of scopes) init[scope.id] = scope.defaultGranted ?? true;\n    return init;\n  });\n  const [pending, setPending] = useState<Record<string, boolean>>({});\n  const pendingRef = useRef(pending);\n  pendingRef.current = pending;\n  const [announce, setAnnounce] = useState(\"\");\n\n  const toggle = useCallback(\n    async (scope: ManifoldScope) => {\n      if (pendingRef.current[scope.id]) return; // already in flight — ignore, don't queue or race\n      const next = !(granted[scope.id] ?? true);\n      setPending((p) => ({ ...p, [scope.id]: true }));\n      try {\n        await (onGrantChange?.(scope.id, next) ?? simulateAck());\n        setGranted((g) => ({ ...g, [scope.id]: next }));\n        setAnnounce(`${scope.label} ${next ? \"granted\" : \"revoked\"}`);\n      } catch {\n        setAnnounce(`${scope.label} unchanged`);\n      } finally {\n        setPending((p) => {\n          const rest = { ...p };\n          delete rest[scope.id];\n          return rest;\n        });\n      }\n    },\n    [granted, onGrantChange]\n  );\n\n  return (\n    <div className={`w-full max-w-md ${className}`}>\n      <style>{CSS}</style>\n\n      <div className=\"flex items-center justify-between border-b border-border pb-2.5\">\n        <div className=\"flex items-center gap-1.5\">\n          <span aria-hidden className=\"h-2 w-2 rounded-full bg-foreground\" />\n          <span className=\"font-mono text-[11px] uppercase tracking-wide text-ns-muted\">Your account</span>\n        </div>\n        <div className=\"flex items-center gap-1.5\">\n          <span className=\"font-mono text-[11px] uppercase tracking-wide text-ns-muted\">{appName}</span>\n          <span aria-hidden className=\"h-2 w-2 rounded-full border border-border\" />\n        </div>\n      </div>\n\n      <ul className=\"flex flex-col\">\n        {scopes.map((scope) => {\n          const isGranted = granted[scope.id] ?? true;\n          const isPending = !!pending[scope.id];\n          const fill = isGranted ? 1 : 0;\n          const angle = (1 - fill) * 90;\n          const strokeW = 1 + 2 * fill;\n          const labelId = `${uid}-${scope.id}-label`;\n          const descId = `${uid}-${scope.id}-desc`;\n\n          return (\n            <li key={scope.id} className=\"flex items-center gap-3 border-b border-border/60 py-3 last:border-0\">\n              <button\n                type=\"button\"\n                role=\"switch\"\n                aria-checked={isGranted}\n                aria-labelledby={labelId}\n                aria-describedby={descId}\n                aria-busy={isPending || undefined}\n                data-manifold-scope={scope.id}\n                onClick={() => toggle(scope)}\n                className=\"ns-manifold-valve group relative grid h-7 w-7 shrink-0 place-items-center rounded-full outline-none transition-colors duration-150 hover:bg-border/40 focus-visible:ring-2 focus-visible:ring-ns-accent focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n              >\n                <svg viewBox=\"0 0 28 28\" width={28} height={28} aria-hidden focusable=\"false\" className=\"overflow-visible\">\n                  <circle\n                    cx={14}\n                    cy={14}\n                    r={9}\n                    fill=\"var(--background)\"\n                    stroke=\"var(--border)\"\n                    strokeWidth={1.25}\n                    className=\"ns-manifold-body\"\n                  />\n                  <line\n                    className=\"ns-manifold-handle\"\n                    x1={14 - 6.5}\n                    y1={14}\n                    x2={14 + 6.5}\n                    y2={14}\n                    stroke=\"var(--foreground)\"\n                    strokeWidth={2.5}\n                    strokeLinecap=\"round\"\n                    style={{ transform: `rotate(${angle}deg)` }}\n                  />\n                </svg>\n              </button>\n\n              <div className=\"flex min-w-[7.25rem] flex-col\">\n                <span id={labelId} className=\"font-mono text-xs text-foreground\">\n                  {scope.label}\n                </span>\n                <span id={descId} className=\"text-[11px] leading-snug text-ns-muted\">\n                  {scope.description}\n                </span>\n              </div>\n\n              <div className=\"flex flex-1 items-center gap-1.5\">\n                <svg\n                  className=\"h-4 flex-1\"\n                  viewBox=\"0 0 100 16\"\n                  preserveAspectRatio=\"none\"\n                  aria-hidden\n                  focusable=\"false\"\n                >\n                  {/* permanent hairline track — evidence of the line even once fully drained */}\n                  <line x1={0} y1={8} x2={100} y2={8} stroke=\"var(--ns-muted)\" strokeWidth={1} />\n                  {/* ink — the only thing this component ever animates */}\n                  <line\n                    className=\"ns-manifold-ink\"\n                    x1={0}\n                    y1={8}\n                    x2={100}\n                    y2={8}\n                    pathLength={1}\n                    stroke=\"var(--foreground)\"\n                    strokeLinecap=\"round\"\n                    strokeDasharray=\"1 1\"\n                    style={{ strokeWidth: strokeW, strokeDashoffset: 1 - fill }}\n                  />\n                </svg>\n                <span aria-hidden className=\"h-2 w-2 shrink-0 rounded-full border border-border\" />\n              </div>\n\n              <span\n                data-manifold-status={scope.id}\n                data-granted={isGranted}\n                className=\"w-14 shrink-0 text-right font-mono text-[10px] uppercase tracking-wide text-ns-muted\"\n              >\n                {isPending ? \"…\" : isGranted ? \"Active\" : \"Revoked\"}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n\n      <span role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n        {announce}\n      </span>\n    </div>\n  );\n}\n\nconst CSS = `\n.ns-manifold-ink { transition: stroke-dashoffset ${DRAIN_MS}ms ${EASE}, stroke-width ${DRAIN_MS}ms ${EASE}; }\n.ns-manifold-handle { transform-box: fill-box; transform-origin: center; transition: transform ${DRAIN_MS}ms ${EASE}; }\n.ns-manifold-body { transition: stroke 150ms ease-out; }\n.ns-manifold-valve:hover .ns-manifold-body { stroke: var(--foreground); }\n@media (prefers-reduced-motion: reduce) {\n  .ns-manifold-ink, .ns-manifold-handle { transition: none; }\n}\n`;\n",
      "type": "registry:ui",
      "target": "components/ui/manifold-bleed.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff"
    },
    "dark": {
      "ns-muted": "#8f8f8f"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "connected-apps",
      "oauth",
      "permissions",
      "switch",
      "svg",
      "valve",
      "async",
      "accessibility"
    ],
    "instruction": "Build `<ManifoldBleed appName scopes={ManifoldScope[]} onGrantChange? />` for a connected-app / standing-grants management page, where `scopes` is `{ id, label, description, defaultGranted? }[]` — each scope one row. Render each row as a horizontal supply line running from the account (implicit reservoir, left) to the app (right), with a real gate-valve switch sitting right at the header where the branch leaves the account, exactly like a real plumbing manifold clusters its valves at the supply header rather than partway down each line. The valve is a native `<button role=\"switch\" aria-checked>` (never a styled div) containing a small aria-hidden SVG: a circle body (stroke var(--border), fill var(--background)) with a straight handle line through it that rotates via CSS transform — 0deg (parallel to the pipe) when open/granted, 90deg (perpendicular, blocking) when closed/revoked, exactly how a real ball-valve handle reads. To the right of the valve, a second aria-hidden SVG draws the line itself as TWO overlapping strokes sharing one `pathLength=\"1\"` normalization: a permanent 1px var(--ns-muted) hairline track spanning the full line (rendered for every row, granted or not, forever — this is the evidence trail; the list never shortens or removes a row even after every scope in it has been revoked), and on top of it a var(--foreground) 'ink' stroke with `stroke-dasharray=\"1 1\"` whose `stroke-dashoffset` is set to `1 - fill` where `fill` is 1 when granted and 0 when revoked. Because the path runs left(valve)->right(app) and dasharray period equals the full path length, animating dashoffset from 0 to 1 retreats the painted portion from its FAR end (the app side) back toward its near end (the valve/account side) — the drain is structurally backward-toward-the-source, not a cosmetic reversal. `stroke-linecap=\"round\"` on the ink stroke means its own retreating edge doubles as the meniscus, so no separate marker element is needed. The governing scalar per row is that same `fill` (0 or 1): stroke-dashoffset (`1-fill`), stroke-width (`1 + 2*fill`, so a live line reads bolder than the hairline it eventually matches), and the valve-handle rotation (`(1-fill)*90deg`) are ALL pure linear functions of it and nothing else is choreographed — a single CSS transition (`stroke-dashoffset`, `stroke-width`, `transform`, ~600ms, ease-out-expo `cubic-bezier(0.16,1,0.3,1)`) on those three properties reproduces exactly what tweening the scalar itself and re-deriving every frame would, with zero rAF loop. FALSIFIABLE CONSTRAINT — fill may change ONLY after server acknowledgment: clicking a valve never touches `fill` directly. It sets a per-row `pending` flag (aria-busy on the button, the row's status word showing '…' instead of 'Active'/'Revoked'), calls `onGrantChange(scopeId, nextGranted)` (or, if that prop is omitted, an internal ~320ms `setTimeout`-based simulated round trip so the component is demoable with no backend), awaits it, and only on resolution flips the internal granted state that `fill` is derived from and fires the announcement. A second click on a row already pending is ignored, not queued or raced. Optimistic fill on grant — flipping the line before the promise resolves — is the explicitly forbidden shortcut: this is the one panel whose whole job is telling the truth about what access exists right now, and rendering authority that doesn't exist yet is a lie in exactly that panel. Every row also renders a small persistent status word to the right (`data-manifold-status={id}` `data-granted={granted}`, text 'Active' / 'Revoked' / '…' while pending) — plain text, never color-only, and present at rest so a caller (or a test) can read state without waiting for the SVG's transition to finish. Accessibility: each switch's accessible name comes from `aria-labelledby` pointing at the row's own visible label text (e.g. 'read:repos'), `aria-describedby` points at the visible plain-language description, `aria-checked` mirrors the CONFIRMED state only (never the optimistic click), and a single shared `role=\"status\" aria-live=\"polite\"` region announces exactly `\"{label} granted\"` / `\"{label} revoked\"` once the server actually confirms. All pipe/valve SVGs are `aria-hidden` — redundant encoding of the switch state and the visible status word, never the only carrier of it. `prefers-reduced-motion: reduce` removes every transition via a scoped `@media` rule so fill, stroke-width and the valve angle land on their target in one step — no drain animation plays, the row is still fully legible from the status word and the valve's resting angle alone. A hairline hover state (button background tint + valve body stroke brightening to var(--foreground)) is a plain CSS `:hover` rule, unaffected by the reduced-motion guard. Zero dependencies, no canvas."
  },
  "type": "registry:ui"
}