Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | 747x 747x 747x 747x 747x 358x 297x 358x 358x 348x 10x 358x 747x 747x 3x 747x 3x 37x 96x 3x 3x 30x 30x 30x 3x 14x 56x 3x 5x 22x 3x 31x 79x 197x 534x 3x 3x 3x 87x 3x 15x 41x 3x 45x 3x 16x 16x 61x 8x 3x 5x 17x 3x 7x 34x 3x 28x 5x 7x 16x 3x 22x 285x | import {
AlertTriangle,
Check,
ChevronRight,
Compass,
Copy,
Info,
Lightbulb,
} from "lucide-react";
import React, { useState } from "react";
// ─── Inline rich text (**bold** and `code`) ────────────────────────────────
function parseInline(text: string): React.ReactNode[] {
const parts: React.ReactNode[] = [];
const regex = /(\*\*[^*]+\*\*|`[^`]+`)/g;
let lastIndex = 0;
let match: RegExpExecArray | null;
let key = 0;
while ((match = regex.exec(text))) {
if (match.index > lastIndex) {
parts.push(text.slice(lastIndex, match.index));
}
const token = match[0];
if (token.startsWith("**")) {
parts.push(
<strong key={key++} className="font-semibold text-gray-900 dark:text-white">
{token.slice(2, -2)}
</strong>,
);
} else {
parts.push(
<code
key={key++}
className="px-1.5 py-0.5 rounded-md text-[0.85em] font-mono bg-blue-50 dark:bg-blue-950/40 text-blue-700 dark:text-blue-300"
>
{token.slice(1, -1)}
</code>,
);
}
lastIndex = match.index + token.length;
}
if (lastIndex < text.length) parts.push(text.slice(lastIndex));
return parts;
}
export const Rich: React.FC<{ text: string }> = ({ text }) => (
<>{parseInline(text)}</>
);
// ─── App path ───────────────────────────────────────────────────────────────
/**
* Where a feature lives in the signed-in app, as a breadcrumb trail. A guide
* that describes a screen should say how to reach it, in the same words the
* navigation uses.
*/
export const AppPath: React.FC<{ segments: string[]; accent: string }> = ({
segments,
accent,
}) => (
<div
className="inline-flex flex-wrap items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium"
style={{ background: `${accent}0d`, color: accent }}
aria-label={`In the app: ${segments.join(" › ")}`}
>
<Compass className="size-3.5 shrink-0" />
<span className="text-gray-500 dark:text-gray-400">In the app</span>
{segments.map((s, i) => (
<React.Fragment key={i}>
<ChevronRight className="size-3 shrink-0 opacity-60" />
<span className="font-semibold">{s}</span>
</React.Fragment>
))}
</div>
);
// ─── Callout ────────────────────────────────────────────────────────────────
export type CalloutTone = "info" | "tip" | "warning";
const CALLOUT_TONES: Record<
CalloutTone,
{ icon: React.ElementType; border: string; bg: string; fg: string }
> = {
info: {
icon: Info,
border: "#3b82f6",
bg: "rgba(59,130,246,0.07)",
fg: "#2563eb",
},
tip: {
icon: Lightbulb,
border: "#059669",
bg: "rgba(5,150,105,0.07)",
fg: "#059669",
},
warning: {
icon: AlertTriangle,
border: "#d97706",
bg: "rgba(217,119,6,0.08)",
fg: "#b45309",
},
};
export const Callout: React.FC<{
tone: CalloutTone;
title?: string;
text: string;
}> = ({ tone, title, text }) => {
const t = CALLOUT_TONES[tone];
const Icon = t.icon;
return (
<div
className="rounded-xl p-4 md:p-5 flex gap-3 items-start"
style={{ background: t.bg, borderLeft: `3px solid ${t.border}` }}
>
<Icon className="size-5 shrink-0 mt-0.5" style={{ color: t.fg }} />
<div>
{title && (
<div className="font-semibold text-sm mb-1" style={{ color: t.fg }}>
{title}
</div>
)}
<p className="text-sm leading-relaxed text-gray-600 dark:text-gray-300 m-0">
<Rich text={text} />
</p>
</div>
</div>
);
};
// ─── Concept cards ──────────────────────────────────────────────────────────
export interface DocCard {
title: string;
text: string;
/** A short label in the corner — a category, a page name, a status. */
tag?: string;
}
/**
* A grid of short cards. Two columns once the container is wide enough for
* both to stay readable, one below that — sized by the article column, not
* the viewport, so the layout is the same whether the sidebar is beside the
* article or above it.
*/
export const ConceptCards: React.FC<{ cards: DocCard[]; accent: string }> = ({
cards,
accent,
}) => (
<div className="@container">
<div className="grid grid-cols-1 @md:grid-cols-2 gap-3">
{cards.map((c, i) => (
<div
key={i}
className="rounded-xl p-4 border border-gray-200 dark:border-gray-700 bg-white/40 dark:bg-gray-900/30 min-w-0"
>
<div className="flex items-start justify-between gap-2 mb-1">
<div className="font-semibold text-sm text-gray-900 dark:text-white">
{c.title}
</div>
{c.tag && (
<span
className="shrink-0 text-[0.65rem] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full"
style={{ background: `${accent}14`, color: accent }}
>
{c.tag}
</span>
)}
</div>
<p className="text-sm text-gray-600 dark:text-gray-300 leading-relaxed m-0">
<Rich text={c.text} />
</p>
</div>
))}
</div>
</div>
);
// ─── Step list ──────────────────────────────────────────────────────────────
export interface DocStep {
title: string;
description: string;
}
export const StepList: React.FC<{ steps: DocStep[]; accent: string }> = ({
steps,
accent,
}) => (
<div className="flex flex-col">
{steps.map((s, i) => (
<div key={i} className="flex gap-4 relative pb-7 last:pb-0">
{i < steps.length - 1 && (
<div
className="absolute left-[15px] top-8 bottom-0 w-px"
style={{ background: `${accent}33` }}
/>
)}
<div
className="shrink-0 size-8 rounded-full flex items-center justify-center font-bold text-sm text-white z-10"
style={{ background: accent }}
>
{i + 1}
</div>
<div className="pt-0.5 min-w-0">
<div className="font-semibold text-sm mb-1">{s.title}</div>
<p className="text-sm text-gray-500 dark:text-gray-400 leading-relaxed m-0">
<Rich text={s.description} />
</p>
</div>
</div>
))}
</div>
);
// ─── Table ──────────────────────────────────────────────────────────────────
export const DocTable: React.FC<{
headers: string[];
rows: string[][];
plainFirstColumn?: boolean;
}> = ({ headers, rows, plainFirstColumn = false }) => (
<div className="overflow-x-auto rounded-xl border border-gray-200 dark:border-gray-700">
<table className="w-full text-sm border-collapse min-w-[32rem]">
<thead>
<tr className="bg-gray-50 dark:bg-gray-800/60">
{headers.map((h, i) => (
<th
key={i}
className="text-left font-semibold px-4 py-2.5 text-gray-600 dark:text-gray-300 whitespace-nowrap"
>
{h}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map((r, i) => (
<tr
key={i}
className="border-t border-gray-100 dark:border-gray-800 even:bg-gray-50/50 dark:even:bg-gray-800/20"
>
{r.map((c, j) => (
<td key={j} className="px-4 py-2.5 align-top text-gray-600 dark:text-gray-300">
{j === 0 && !plainFirstColumn ? (
<code className="text-xs font-mono px-1.5 py-0.5 rounded-md bg-blue-50 dark:bg-blue-950/40 text-blue-700 dark:text-blue-300 whitespace-nowrap">
{c}
</code>
) : j === 0 ? (
<span className="font-semibold text-gray-900 dark:text-white">
<Rich text={c} />
</span>
) : (
<Rich text={c} />
)}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
);
// ─── Code block ─────────────────────────────────────────────────────────────
export const CodeBlock: React.FC<{ code: string; label?: string }> = ({
code,
label,
}) => {
const [copied, setCopied] = useState(false);
const copy = async () => {
try {
await navigator.clipboard.writeText(code);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch {
// clipboard unavailable — ignore
}
};
return (
<div className="rounded-xl overflow-hidden border border-gray-200 dark:border-gray-700">
<div className="flex items-center justify-between px-4 py-2 bg-gray-100 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">
<span className="text-xs font-mono text-gray-500 dark:text-gray-400">
{label ?? "json"}
</span>
<button
onClick={() => void copy()}
className="text-xs font-semibold text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 flex items-center gap-1.5 transition-colors"
>
{copied ? (
<>
<Check className="size-3" /> Copied
</>
) : (
<>
<Copy className="size-3" /> Copy
</>
)}
</button>
</div>
<pre className="text-xs md:text-sm p-4 overflow-x-auto bg-gray-50 dark:bg-gray-900 m-0">
<code>{code}</code>
</pre>
</div>
);
};
// ─── Diagrams ───────────────────────────────────────────────────────────────
//
// Every diagram is laid out by the width of the box it is drawn in, not by
// the viewport. The article column is narrow next to the sidebar and wide on
// a phone (where the sidebar sits above it), so a viewport breakpoint picks
// the wrong orientation on tablets and mid-sized windows: a flow would go
// horizontal, run out of room and wrap, leaving a right-pointing arrow at
// the end of one line and the next step below-left of it. `@container` on
// the card and `@md:` / `@xl:` variants on the layout make orientation a
// function of the space actually available, and a horizontal flow never
// wraps — steps share the width with `flex-1` and their labels wrap instead.
// The horizontal threshold is `@xl` (36rem): the article column next to the
// table of contents is about 40rem, so anything larger never triggers.
export interface DocDiagramNode {
label: string;
sub?: string;
}
export type DocDiagram =
/** A left-to-right (or top-to-bottom) chain. An inner array is a group of
* steps that run side by side. */
| { kind: "flow"; nodes: (DocDiagramNode | DocDiagramNode[])[] }
/** One root over a row of branches, each with optional tags. */
| {
kind: "tree";
root: DocDiagramNode;
branches: { node: DocDiagramNode; tags?: string[] }[];
}
/** An ordered set of bands — stages of a pipeline, layers of a hierarchy —
* read top to bottom. Always vertical, so it fits at any width. */
| {
kind: "stack";
bands: { node: DocDiagramNode; tags?: string[] }[];
/** Draw arrows between bands (a sequence) rather than plain gaps (a
* hierarchy). */
arrows?: boolean;
};
/** A flow with more steps than this is always drawn top-to-bottom: the
* article column is about 40rem wide beside the table of contents, and five
* or more boxes side by side in it leave no room for a label. */
export const MAX_HORIZONTAL_FLOW_STEPS = 4;
const DiagramNodeBox: React.FC<{
node: DocDiagramNode;
accent: string;
className?: string;
}> = ({ node, accent, className = "" }) => (
<div
className={`rounded-xl px-3 py-3 text-center min-w-0 ${className}`}
style={{ background: `${accent}0d`, border: `1px solid ${accent}40` }}
>
<div
className="font-semibold text-sm leading-snug break-words"
style={{ color: accent }}
>
{node.label}
</div>
{node.sub && (
<div className="text-xs text-gray-500 dark:text-gray-400 mt-0.5 leading-snug break-words">
{node.sub}
</div>
)}
</div>
);
const TagRow: React.FC<{ tags: string[]; accent: string; className?: string }> = ({
tags,
accent,
className = "",
}) => (
<div className={`flex flex-wrap gap-1.5 ${className}`}>
{tags.map((t, j) => (
<span
key={j}
className="text-[0.7rem] px-2 py-0.5 rounded-full whitespace-nowrap"
style={{ background: `${accent}12`, color: accent }}
>
{t}
</span>
))}
</div>
);
/** An arrow that points down, and — when the flow may go horizontal — right
* once the container is wide enough for it to. */
const FlowArrow: React.FC<{ accent: string; horizontal: boolean }> = ({
accent,
horizontal,
}) => (
<svg
viewBox="0 0 24 24"
className={`size-5 shrink-0 self-center rotate-90 ${horizontal ? "@xl:rotate-0" : ""}`}
style={{ color: `${accent}90` }}
fill="none"
aria-hidden="true"
data-testid="flow-arrow"
>
<path
d="M4 12h15M13 6l6 6-6 6"
stroke="currentColor"
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
const FlowDiagram: React.FC<{
nodes: (DocDiagramNode | DocDiagramNode[])[];
accent: string;
}> = ({ nodes, accent }) => {
const horizontal = nodes.length <= MAX_HORIZONTAL_FLOW_STEPS;
return (
<div
className={`flex flex-col items-stretch gap-2 py-1 ${
horizontal ? "@xl:flex-row @xl:items-center" : ""
}`}
data-testid="flow"
data-orientation={horizontal ? "responsive" : "vertical"}
>
{nodes.map((n, i) => (
<React.Fragment key={i}>
{Array.isArray(n) ? (
<div
className={`flex flex-col gap-2 rounded-xl border border-dashed p-2 min-w-0 ${
horizontal ? "@xl:flex-1" : ""
}`}
style={{ borderColor: `${accent}50` }}
data-testid="flow-group"
>
<div
className="text-[0.65rem] font-semibold uppercase tracking-wide text-center"
style={{ color: `${accent}b0` }}
>
in parallel
</div>
{n.map((sub, j) => (
<DiagramNodeBox key={j} node={sub} accent={accent} />
))}
</div>
) : (
<DiagramNodeBox
node={n}
accent={accent}
className={horizontal ? "@xl:flex-1" : ""}
/>
)}
{i < nodes.length - 1 && (
<FlowArrow accent={accent} horizontal={horizontal} />
)}
</React.Fragment>
))}
</div>
);
};
const TreeDiagram: React.FC<{
root: DocDiagramNode;
branches: { node: DocDiagramNode; tags?: string[] }[];
accent: string;
}> = ({ root, branches, accent }) => (
<div className="flex flex-col items-center gap-0 py-1" data-testid="tree">
<DiagramNodeBox node={root} accent={accent} className="w-full max-w-[16rem]" />
<div className="w-px h-6" style={{ background: `${accent}40` }} />
{/* One row of connector, then the branches. `auto-fit` keeps every branch
the same width and reflows the row as the container narrows, so three
branches are three columns, then two, then one — never two and an
orphan hanging under them. */}
<div className="w-full grid grid-cols-[repeat(auto-fit,minmax(10rem,1fr))] gap-4 border-t pt-4" style={{ borderColor: `${accent}40` }}>
{branches.map((b, i) => (
<div key={i} className="flex flex-col items-center gap-2 min-w-0">
<DiagramNodeBox node={b.node} accent={accent} className="w-full" />
{b.tags && (
<TagRow tags={b.tags} accent={accent} className="justify-center" />
)}
</div>
))}
</div>
</div>
);
const StackDiagram: React.FC<{
bands: { node: DocDiagramNode; tags?: string[] }[];
arrows: boolean;
accent: string;
}> = ({ bands, arrows, accent }) => (
<div className="flex flex-col items-stretch gap-1.5 py-1" data-testid="stack">
{bands.map((b, i) => (
<React.Fragment key={i}>
<div
className="flex items-center gap-3 rounded-xl px-3 py-2.5 min-w-0"
style={{
background: `${accent}0d`,
border: `1px solid ${accent}40`,
// A hierarchy narrows as it goes down; a sequence keeps its width.
marginLeft: arrows ? 0 : `${i * 0.75}rem`,
}}
>
<div
className="shrink-0 size-6 rounded-full flex items-center justify-center text-[0.7rem] font-bold text-white"
style={{ background: accent }}
>
{i + 1}
</div>
<div className="min-w-0 flex-1">
<div
className="font-semibold text-sm leading-snug"
style={{ color: accent }}
>
{b.node.label}
</div>
{b.node.sub && (
<div className="text-xs text-gray-500 dark:text-gray-400 leading-snug">
{b.node.sub}
</div>
)}
{b.tags && <TagRow tags={b.tags} accent={accent} className="mt-1.5" />}
</div>
</div>
{arrows && i < bands.length - 1 && (
<svg
viewBox="0 0 24 24"
className="size-4 self-center rotate-90"
style={{ color: `${accent}90` }}
fill="none"
aria-hidden="true"
>
<path
d="M4 12h15M13 6l6 6-6 6"
stroke="currentColor"
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
)}
</React.Fragment>
))}
</div>
);
export const DiagramView: React.FC<{
diagram: DocDiagram;
accent: string;
}> = ({ diagram, accent }) => {
switch (diagram.kind) {
case "tree":
return (
<TreeDiagram
root={diagram.root}
branches={diagram.branches}
accent={accent}
/>
);
case "stack":
return (
<StackDiagram
bands={diagram.bands}
arrows={diagram.arrows ?? true}
accent={accent}
/>
);
case "flow":
return <FlowDiagram nodes={diagram.nodes} accent={accent} />;
}
};
export const DiagramCard: React.FC<{
diagram: DocDiagram;
accent: string;
caption?: string;
}> = ({ diagram, accent, caption }) => (
<figure
className="@container rounded-2xl p-4 @md:p-6 @2xl:p-8 m-0"
style={{
background: `linear-gradient(135deg, ${accent}08 0%, transparent 100%)`,
border: `1px solid ${accent}22`,
}}
>
<DiagramView diagram={diagram} accent={accent} />
{caption && (
<figcaption className="text-xs text-center text-gray-500 dark:text-gray-400 mt-4 mb-0 max-w-lg mx-auto leading-relaxed">
{caption}
</figcaption>
)}
</figure>
);
// ─── Heading id helper (shared by DocArticle content + TOC) ────────────────
export function slugify(text: string): string {
return text
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/(^-|-$)/g, "");
}
|