@designtools/docs 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +155 -2
  4. package/dist/a11y-panel.d.ts +58 -0
  5. package/dist/a11y-panel.js +75 -0
  6. package/dist/adherence-summary.d.ts +9 -0
  7. package/dist/adherence-summary.js +27 -0
  8. package/dist/agent-view.d.ts +19 -0
  9. package/dist/agent-view.js +23 -0
  10. package/dist/anatomy.d.ts +12 -0
  11. package/dist/anatomy.js +39 -0
  12. package/dist/ask-claude.d.ts +14 -0
  13. package/dist/ask-claude.js +40 -0
  14. package/dist/cli.js +322 -0
  15. package/dist/code-view.d.ts +17 -0
  16. package/dist/code-view.js +42 -0
  17. package/dist/examples.d.ts +25 -0
  18. package/dist/examples.js +48 -0
  19. package/dist/glossary.d.ts +5 -0
  20. package/dist/glossary.js +21 -0
  21. package/dist/imagery.d.ts +6 -0
  22. package/dist/imagery.js +17 -0
  23. package/dist/index.d.ts +35 -0
  24. package/dist/index.js +34 -0
  25. package/dist/lib/adherence-types.d.ts +168 -0
  26. package/dist/lib/adherence-types.js +13 -0
  27. package/dist/lib/boundary.d.ts +16 -0
  28. package/dist/lib/boundary.js +15 -0
  29. package/dist/lib/contrast.d.ts +8 -0
  30. package/dist/lib/contrast.js +42 -0
  31. package/dist/lib/cx.d.ts +24 -0
  32. package/dist/lib/cx.js +26 -0
  33. package/dist/lib/jsx.d.ts +6 -0
  34. package/dist/lib/jsx.js +29 -0
  35. package/dist/lib/live.d.ts +10 -0
  36. package/dist/lib/live.js +10 -0
  37. package/dist/lib/lookup.d.ts +35 -0
  38. package/dist/lib/lookup.js +42 -0
  39. package/dist/lib/manifest-types.d.ts +253 -0
  40. package/dist/lib/manifest-types.js +14 -0
  41. package/dist/lib/manifest.d.ts +98 -0
  42. package/dist/lib/manifest.js +173 -0
  43. package/dist/lib/markdown.d.ts +50 -0
  44. package/dist/lib/markdown.js +286 -0
  45. package/dist/lib/measure.d.ts +12 -0
  46. package/dist/lib/measure.js +62 -0
  47. package/dist/lib/pseudo.d.ts +11 -0
  48. package/dist/lib/pseudo.js +71 -0
  49. package/dist/lib/registry.d.ts +21 -0
  50. package/dist/lib/registry.js +11 -0
  51. package/dist/lib/search.d.ts +44 -0
  52. package/dist/lib/search.js +62 -0
  53. package/dist/lib/standards.d.ts +17 -0
  54. package/dist/lib/standards.js +81 -0
  55. package/dist/lib/status.d.ts +6 -0
  56. package/dist/lib/status.js +17 -0
  57. package/dist/lib/terms.d.ts +15 -0
  58. package/dist/lib/terms.js +20 -0
  59. package/dist/lib/text.d.ts +8 -0
  60. package/dist/lib/text.js +9 -0
  61. package/dist/lib/ui.d.ts +100 -0
  62. package/dist/lib/ui.js +89 -0
  63. package/dist/lib/vision.d.ts +18 -0
  64. package/dist/lib/vision.js +27 -0
  65. package/dist/logo-usage.d.ts +14 -0
  66. package/dist/logo-usage.js +45 -0
  67. package/dist/next/config.d.ts +105 -0
  68. package/dist/next/config.js +1 -0
  69. package/dist/next/index.d.ts +65 -0
  70. package/dist/next/index.js +66 -0
  71. package/dist/next/markdown.d.ts +20 -0
  72. package/dist/next/markdown.js +95 -0
  73. package/dist/next/pages.d.ts +6 -0
  74. package/dist/next/pages.js +188 -0
  75. package/dist/next/prose.d.ts +9 -0
  76. package/dist/next/prose.js +39 -0
  77. package/dist/next/proxy.d.ts +19 -0
  78. package/dist/next/proxy.js +56 -0
  79. package/dist/next/site.d.ts +53 -0
  80. package/dist/next/site.js +136 -0
  81. package/dist/page-actions.d.ts +9 -0
  82. package/dist/page-actions.js +32 -0
  83. package/dist/pattern.d.ts +11 -0
  84. package/dist/pattern.js +22 -0
  85. package/dist/playground.d.ts +62 -0
  86. package/dist/playground.js +111 -0
  87. package/dist/preview-frame.d.ts +31 -0
  88. package/dist/preview-frame.js +63 -0
  89. package/dist/props-table.d.ts +10 -0
  90. package/dist/props-table.js +45 -0
  91. package/dist/rule.d.ts +16 -0
  92. package/dist/rule.js +37 -0
  93. package/dist/scale.d.ts +9 -0
  94. package/dist/scale.js +58 -0
  95. package/dist/search.d.ts +16 -0
  96. package/dist/search.js +46 -0
  97. package/dist/shell.d.ts +92 -0
  98. package/dist/shell.js +201 -0
  99. package/dist/standards.d.ts +13 -0
  100. package/dist/standards.js +19 -0
  101. package/dist/styles.css +3708 -0
  102. package/dist/swatches.d.ts +28 -0
  103. package/dist/swatches.js +100 -0
  104. package/dist/theme-switch.d.ts +20 -0
  105. package/dist/theme-switch.js +68 -0
  106. package/dist/type-ramp.d.ts +10 -0
  107. package/dist/type-ramp.js +31 -0
  108. package/dist/usage.d.ts +13 -0
  109. package/dist/usage.js +55 -0
  110. package/dist/variant-matrix.d.ts +15 -0
  111. package/dist/variant-matrix.js +58 -0
  112. package/dist/voice-terms.d.ts +5 -0
  113. package/dist/voice-terms.js +14 -0
  114. package/dist/workbench.d.ts +33 -0
  115. package/dist/workbench.js +274 -0
  116. package/package.json +107 -3
  117. package/src/a11y-panel.tsx +297 -0
  118. package/src/adherence-summary.tsx +134 -0
  119. package/src/agent-view.tsx +54 -0
  120. package/src/anatomy.tsx +119 -0
  121. package/src/ask-claude.tsx +90 -0
  122. package/src/code-view.tsx +112 -0
  123. package/src/css.d.ts +1 -0
  124. package/src/examples.tsx +141 -0
  125. package/src/glossary.tsx +70 -0
  126. package/src/imagery.tsx +64 -0
  127. package/src/index.ts +35 -0
  128. package/src/lib/adherence-types.ts +181 -0
  129. package/src/lib/boundary.tsx +21 -0
  130. package/src/lib/contrast.ts +44 -0
  131. package/src/lib/cx.ts +30 -0
  132. package/src/lib/jsx.ts +29 -0
  133. package/src/lib/live.tsx +15 -0
  134. package/src/lib/lookup.tsx +50 -0
  135. package/src/lib/manifest-types.ts +284 -0
  136. package/src/lib/manifest.ts +228 -0
  137. package/src/lib/markdown.ts +288 -0
  138. package/src/lib/measure.tsx +101 -0
  139. package/src/lib/pseudo.ts +74 -0
  140. package/src/lib/registry.tsx +29 -0
  141. package/src/lib/search.ts +99 -0
  142. package/src/lib/standards.ts +82 -0
  143. package/src/lib/status.tsx +32 -0
  144. package/src/lib/terms.tsx +53 -0
  145. package/src/lib/text.tsx +27 -0
  146. package/src/lib/ui.tsx +291 -0
  147. package/src/lib/vision.tsx +44 -0
  148. package/src/logo-usage.tsx +140 -0
  149. package/src/next/config.ts +101 -0
  150. package/src/next/index.tsx +103 -0
  151. package/src/next/markdown.ts +119 -0
  152. package/src/next/pages.tsx +483 -0
  153. package/src/next/prose.tsx +97 -0
  154. package/src/next/proxy.ts +55 -0
  155. package/src/next/site.ts +173 -0
  156. package/src/page-actions.tsx +92 -0
  157. package/src/pattern.tsx +72 -0
  158. package/src/playground.tsx +357 -0
  159. package/src/preview-frame.tsx +131 -0
  160. package/src/props-table.tsx +154 -0
  161. package/src/rule.tsx +165 -0
  162. package/src/scale.tsx +175 -0
  163. package/src/search.tsx +155 -0
  164. package/src/shell.tsx +569 -0
  165. package/src/standards.tsx +58 -0
  166. package/src/styles.css +157 -0
  167. package/src/swatches.tsx +298 -0
  168. package/src/theme-switch.tsx +90 -0
  169. package/src/type-ramp.tsx +150 -0
  170. package/src/usage.tsx +148 -0
  171. package/src/variant-matrix.tsx +178 -0
  172. package/src/voice-terms.tsx +37 -0
  173. package/src/workbench.tsx +587 -0
@@ -0,0 +1,483 @@
1
+ import { ArrowRight, ArrowUpRight } from "lucide-react";
2
+ import Link from "next/link";
3
+ import type { ReactNode } from "react";
4
+ import { cx, display } from "../lib/cx";
5
+ import { AdherenceSummary } from "../adherence-summary";
6
+ import { Anatomy } from "../anatomy";
7
+ import { Examples } from "../examples";
8
+ import { Glossary } from "../glossary";
9
+ import { Imagery } from "../imagery";
10
+ import { groupFamilies, slugOf } from "../lib/manifest";
11
+ import { StatusBadge } from "../lib/status";
12
+ import { LogoUsage } from "../logo-usage";
13
+ import { PageActions } from "../page-actions";
14
+ import { Pattern } from "../pattern";
15
+ import { PreviewFrame } from "../preview-frame";
16
+ import { PropsTable } from "../props-table";
17
+ import { Rule, RuleIndex } from "../rule";
18
+ import { Scale } from "../scale";
19
+ import { DocsFooter, DocsHeader, DocsSection } from "../shell";
20
+ import { Standards } from "../standards";
21
+ import { PageContrast, RampSwatches, SemanticSwatches } from "../swatches";
22
+ import { TypeRamp } from "../type-ramp";
23
+ import { Usage } from "../usage";
24
+ import { VariantMatrix } from "../variant-matrix";
25
+ import { VoiceTerms } from "../voice-terms";
26
+ import { Workbench } from "../workbench";
27
+ import { Markdown } from "./prose";
28
+ import { COPY, type PageRef, type Site } from "./site";
29
+
30
+ /** Every block a page renders, by the name `config.blocks` replaces it under. */
31
+ const DEFAULT_BLOCKS = {
32
+ AdherenceSummary,
33
+ Anatomy,
34
+ Examples,
35
+ Glossary,
36
+ Imagery,
37
+ LogoUsage,
38
+ PageContrast,
39
+ Pattern,
40
+ PreviewFrame,
41
+ PropsTable,
42
+ RampSwatches,
43
+ Rule,
44
+ RuleIndex,
45
+ Scale,
46
+ SemanticSwatches,
47
+ Standards,
48
+ TypeRamp,
49
+ Usage,
50
+ VariantMatrix,
51
+ VoiceTerms,
52
+ Workbench,
53
+ };
54
+ type Blocks = typeof DEFAULT_BLOCKS;
55
+
56
+ function blocksOf(site: Site): Blocks {
57
+ return { ...DEFAULT_BLOCKS, ...(site.config.blocks as Partial<Blocks> | undefined) };
58
+ }
59
+
60
+ /** The page for a reference, composed of blocks. */
61
+ export function DocsPageView({ site, page }: { site: Site; page: PageRef }) {
62
+ const B = blocksOf(site);
63
+ const { base, config } = site;
64
+ const footer = <DocsFooter provenance={config.provenance} />;
65
+ const header = (title: string, lead?: string) => (
66
+ <DocsHeader title={title} lead={lead}>
67
+ <PageActions basePath={base} />
68
+ </DocsHeader>
69
+ );
70
+
71
+ switch (page.kind) {
72
+ case "overview":
73
+ return <Overview site={site} />;
74
+
75
+ case "editorial":
76
+ return (
77
+ <>
78
+ {header(page.page.title, page.page.lead)}
79
+ {typeof page.page.body === "string" ? <Markdown text={page.page.body} /> : page.page.body}
80
+ <DocsFooter editorial={page.page.by} />
81
+ </>
82
+ );
83
+
84
+ case "logo":
85
+ return (
86
+ <>
87
+ {header(COPY.logo.title, COPY.logo.lead)}
88
+ <B.LogoUsage assets={site.assets.assets} rules={site.rules.rules} rulesHref={`${base}/rules`} />
89
+ {footer}
90
+ </>
91
+ );
92
+
93
+ case "imagery":
94
+ return (
95
+ <>
96
+ {header(COPY.imagery.title, COPY.imagery.lead)}
97
+ <B.Imagery assets={site.assets.assets} />
98
+ {footer}
99
+ </>
100
+ );
101
+
102
+ case "voice":
103
+ return (
104
+ <>
105
+ {header(COPY.voice.title, COPY.voice.lead)}
106
+ <B.VoiceTerms terms={site.taxonomy.terms} />
107
+ {footer}
108
+ </>
109
+ );
110
+
111
+ case "colour":
112
+ return (
113
+ <>
114
+ {header(COPY.colour.title, COPY.colour.lead)}
115
+ <DocsSection title="Semantic colours" lead="Each pair is measured on the colours the browser paints, in each mode.">
116
+ <B.SemanticSwatches tokens={site.tokens} />
117
+ </DocsSection>
118
+ <DocsSection
119
+ title="On the page"
120
+ lead="Each colour on each background. A label is measured on its own fill above; this is the rest: a colour used as text on the page needs 4.5:1, as a shape (a meter fill, an icon without words) 3:1."
121
+ >
122
+ <B.PageContrast tokens={site.tokens} />
123
+ </DocsSection>
124
+ <DocsSection title="Ramps">
125
+ <B.RampSwatches tokens={site.tokens} />
126
+ </DocsSection>
127
+ {footer}
128
+ </>
129
+ );
130
+
131
+ case "type":
132
+ return (
133
+ <>
134
+ {header(COPY.type.title, COPY.type.lead)}
135
+ <B.TypeRamp tokens={site.tokens} />
136
+ {footer}
137
+ </>
138
+ );
139
+
140
+ case "scale":
141
+ return (
142
+ <>
143
+ {header(COPY.scale.title, COPY.scale.lead)}
144
+ <B.Scale tokens={site.tokens} />
145
+ {footer}
146
+ </>
147
+ );
148
+
149
+ case "rules":
150
+ return (
151
+ <>
152
+ {header(COPY.rules.title, COPY.rules.lead)}
153
+ <DocsSection title="Every rule" lead="A line each: what it covers, how settled it is, and how it is checked.">
154
+ <B.RuleIndex rules={[...site.rules.rules].sort((a, b) => a.kind.localeCompare(b.kind))} />
155
+ </DocsSection>
156
+ {(["brand", "interface"] as const).map((kind) => {
157
+ const rules = site.rules.rules.filter((r) => r.kind === kind);
158
+ return rules.length ? (
159
+ <DocsSection key={kind} title={kind === "brand" ? "Brand" : "Interface"}>
160
+ {rules.map((r) => (
161
+ <B.Rule key={r.id} rule={r}>
162
+ {config.demonstrations?.[r.id]}
163
+ </B.Rule>
164
+ ))}
165
+ </DocsSection>
166
+ ) : null;
167
+ })}
168
+ {footer}
169
+ </>
170
+ );
171
+
172
+ case "standards":
173
+ return (
174
+ <>
175
+ {header(COPY.standards.title, COPY.standards.lead)}
176
+ {config.baselines && (
177
+ <DocsSection title="Targets">
178
+ <B.Standards baselines={config.baselines} />
179
+ </DocsSection>
180
+ )}
181
+ {config.adherence && (
182
+ <DocsSection title="Adherence" lead="How closely the product follows the system, from @designtools/adherence. It informs; it never blocks.">
183
+ <B.AdherenceSummary report={config.adherence} />
184
+ </DocsSection>
185
+ )}
186
+ {footer}
187
+ </>
188
+ );
189
+
190
+ case "vocabulary":
191
+ return (
192
+ <>
193
+ {header(COPY.vocabulary.title, COPY.vocabulary.lead)}
194
+ <B.Glossary terms={site.taxonomy.terms} />
195
+ {footer}
196
+ </>
197
+ );
198
+
199
+ case "pattern":
200
+ return (
201
+ <>
202
+ <DocsHeader title={page.pattern.name} lead={page.pattern.description} status={page.pattern.status}>
203
+ <PageActions basePath={base} />
204
+ </DocsHeader>
205
+ <B.Pattern pattern={page.pattern} manifest={site.components} basePath={base} />
206
+ <DocsFooter source={page.pattern.source} provenance={config.provenance} />
207
+ </>
208
+ );
209
+
210
+ case "component":
211
+ return <ComponentPage site={site} blocks={B} entry={page.entry} />;
212
+ }
213
+ }
214
+
215
+ function ComponentPage({ site, blocks: B, entry }: { site: Site; blocks: Blocks; entry: Extract<PageRef, { kind: "component" }>["entry"] }) {
216
+ const { base, config } = site;
217
+ // A part (TabsPanel, CardHeader) renders inside its family's root, so it is shown there, never alone:
218
+ // a part rendered on its own can throw for want of the root's context.
219
+ const head = entry.category ? undefined : site.components.components.find((c) => c.source === entry.source && c.category);
220
+ if (head)
221
+ return (
222
+ <>
223
+ <DocsHeader title={entry.name} lead={entry.description ?? `A part of ${head.name}, used inside it.`}>
224
+ <PageActions basePath={base} />
225
+ </DocsHeader>
226
+ <DocsSection title="Part of" lead={`Its examples, variants and anatomy are on ${head.name}'s page, where it renders inside the whole.`}>
227
+ <Link
228
+ href={`${base}/components/${slugOf(head)}`}
229
+ className="group flex max-w-md items-center justify-between gap-3 border-t border-border py-5 focus-visible:outline-2 focus-visible:outline-ring"
230
+ >
231
+ <span className="flex flex-col gap-1">
232
+ <span className="text-xl tracking-tight underline-offset-4 group-hover:underline">{head.name}</span>
233
+ {head.description && <span className="line-clamp-2 text-sm text-muted-foreground">{head.description}</span>}
234
+ </span>
235
+ <ArrowRight aria-hidden className="size-5 shrink-0 text-muted-foreground" />
236
+ </Link>
237
+ </DocsSection>
238
+ <DocsSection title="Props">
239
+ <B.PropsTable entry={entry} />
240
+ </DocsSection>
241
+ <DocsFooter source={entry.source} provenance={config.provenance} />
242
+ </>
243
+ );
244
+
245
+ const setup = config.workbench?.[entry.name] ?? {};
246
+ const preview = `${base}/preview/${slugOf(entry)}`;
247
+ const first = entry.examples?.canonical?.name;
248
+ // the brand's named backgrounds (--surface-<name>), offered on the workbench's stage
249
+ const backgrounds = site.tokens.tokens.map((t) => t.name.slice(2)).filter((n) => /^surface-[a-z]/.test(n) && !n.endsWith("-foreground"));
250
+
251
+ return (
252
+ <>
253
+ <DocsHeader title={entry.name} lead={entry.description}>
254
+ <PageActions basePath={base} />
255
+ </DocsHeader>
256
+
257
+ <DocsSection title="Usage">
258
+ <B.Usage entry={entry} manifest={site.components} basePath={base} />
259
+ </DocsSection>
260
+
261
+ {/* the component's one main area: live, with its properties, code, props, actions, agent view and accessibility */}
262
+ <B.Workbench
263
+ entry={entry}
264
+ props={setup.props}
265
+ content={setup.content}
266
+ wrap={setup.wrap}
267
+ backgrounds={backgrounds}
268
+ previewHref={first && `${preview}/${first}`}
269
+ >
270
+ {setup.children}
271
+ </B.Workbench>
272
+
273
+ <DocsSection title="Anatomy">
274
+ <B.Anatomy entry={entry} />
275
+ </DocsSection>
276
+
277
+ <DocsSection title="Examples" lead="The usual use first, then each do beside its don't. Every one is the real component.">
278
+ <B.Examples entry={entry} previewHref={preview} />
279
+ </DocsSection>
280
+
281
+ {!!entry.variants?.axes.length && (
282
+ <DocsSection
283
+ title="Variants"
284
+ lead={`Every combination, from the ${entry.variants.from === "props" ? "props' types" : `${entry.variants.from}() config`}, then each state.`}
285
+ >
286
+ <B.VariantMatrix entry={entry} props={setup.props}>
287
+ {setup.children === "" ? undefined : (setup.content ?? entry.name)}
288
+ </B.VariantMatrix>
289
+ </DocsSection>
290
+ )}
291
+
292
+ {first && (
293
+ <DocsSection title="At each width">
294
+ <B.PreviewFrame src={`${preview}/${first}`} title={`${entry.name}: ${first}`} />
295
+ </DocsSection>
296
+ )}
297
+
298
+ <DocsFooter source={entry.source} provenance={config.provenance} />
299
+ </>
300
+ );
301
+ }
302
+
303
+ /** The overview, below the hero when there is one: each part of the system and why it exists, then why it is agentic. */
304
+ function Overview({ site }: { site: Site }) {
305
+ const { base, config } = site;
306
+ const families = groupFamilies(site.components);
307
+ const count = families.reduce((n, g) => n + g.families.length, 0);
308
+ const brandPages = site.editorial.filter((p) => (p.section ?? "brand") === "brand");
309
+ const brandFirst = brandPages[0];
310
+ const products = site.taxonomy.terms.filter((t) => t.kind === "product" && t.wrong?.length);
311
+ const example = products[0] ?? site.taxonomy.terms.find((t) => t.wrong?.length);
312
+ const fills = ["--primary", "--neutral", "--success", "--warning", "--destructive"].filter((n) =>
313
+ site.tokens.tokens.some((t) => t.name === n),
314
+ );
315
+ const share = config.adherence?.summary.share;
316
+
317
+ // each section of the system, why it exists, how much is in it, and a glimpse of it, live from the manifest
318
+ const sections: { title: string; href: string; why: string; count: string; preview: ReactNode }[] = [];
319
+ if (brandFirst || site.shows("logo"))
320
+ sections.push({
321
+ title: "Brand",
322
+ href: `${base}/${brandFirst?.slug ?? "brand/logo"}`,
323
+ why: "What the brand believes, how it sounds and how it looks, so every screen and sentence comes from the same place.",
324
+ count: `${brandPages.length + (site.assets.assets.some((a) => a.kind === "logo") ? 1 : 0)} pages`,
325
+ preview: config.logo ? <span className="flex h-10 items-center [&_img]:h-8 [&_svg]:h-8">{config.logo}</span> : null,
326
+ });
327
+ sections.push({
328
+ title: "Foundations",
329
+ href: `${base}/colour`,
330
+ why: "Colour, type and the scale, generated from the tokens and measured in both modes, so nothing is a guess.",
331
+ count: `${site.tokens.tokens.length} tokens`,
332
+ preview: (
333
+ <span className="flex items-center gap-4">
334
+ <span className="flex -space-x-1.5">
335
+ {fills.map((n) => (
336
+ <span key={n} aria-hidden className="size-8 rounded-full ring-2 ring-canvas" style={{ background: `var(${n})` }} />
337
+ ))}
338
+ </span>
339
+ <span aria-hidden className={cx(display, "text-3xl leading-none tracking-tight")}>
340
+ Aa
341
+ </span>
342
+ </span>
343
+ ),
344
+ });
345
+ if (site.rules.rules.length)
346
+ sections.push({
347
+ title: "Rules",
348
+ href: `${base}/rules`,
349
+ why: "The lines the brand and the interface hold, each written for people, with the check that proves it.",
350
+ count: `${site.rules.rules.length} rules, ${site.rules.rules.filter((r) => r.status === "confirmed").length} confirmed`,
351
+ preview: (
352
+ <span className="flex flex-col gap-1.5 text-sm">
353
+ {site.rules.rules
354
+ .filter((r) => r.kind === "brand")
355
+ .slice(0, 2)
356
+ .map((r) => (
357
+ <span key={r.id} className="flex items-center gap-2">
358
+ <StatusBadge status={r.status} />
359
+ <span className="truncate">{r.title}</span>
360
+ </span>
361
+ ))}
362
+ </span>
363
+ ),
364
+ });
365
+ if (site.shows("components") && count)
366
+ sections.push({
367
+ title: "Components",
368
+ href: `${base}/components/${slugOf(families[0].families[0].head)}`,
369
+ why: "The real components the product is built from, each with when to use it, a live workbench and an accessibility report.",
370
+ count: `${count} components`,
371
+ preview: (
372
+ <span className="flex flex-wrap gap-1.5">
373
+ {families.slice(0, 6).map((g) => (
374
+ <span key={g.category} className="inline-flex min-h-7 items-center rounded-md bg-muted px-2 text-xs">
375
+ {g.category} <span className="ml-1.5 text-muted-foreground tabular-nums">{g.families.length}</span>
376
+ </span>
377
+ ))}
378
+ </span>
379
+ ),
380
+ });
381
+ if (site.patterns.patterns.length)
382
+ sections.push({
383
+ title: "Patterns",
384
+ href: `${base}/patterns/${site.patterns.patterns[0].id}`,
385
+ why: "The screens the product keeps making, composed of the components, so a recurring problem is solved once.",
386
+ count: `${site.patterns.patterns.length} patterns`,
387
+ preview: <span className="text-sm text-muted-foreground">{site.patterns.patterns.slice(0, 3).map((p) => p.name).join(" · ")}</span>,
388
+ });
389
+ if (site.shows("standards") && (config.baselines || config.adherence))
390
+ sections.push({
391
+ title: "Standards",
392
+ href: `${base}/standards`,
393
+ why: "The bar the product is held to, and how closely it follows the system today, reported on every change.",
394
+ count: share == null ? "Baselines agreed" : `${Math.round(share * 100)}% of the product on the system`,
395
+ preview:
396
+ share == null ? null : (
397
+ <span className="flex w-full max-w-56 items-center gap-3">
398
+ <span className="h-1.5 flex-1 overflow-hidden rounded-full bg-muted">
399
+ <span className="block h-full rounded-full bg-canvas-foreground" style={{ width: `${Math.round(share * 100)}%` }} />
400
+ </span>
401
+ <span className="text-sm tabular-nums">{Math.round(share * 100)}%</span>
402
+ </span>
403
+ ),
404
+ });
405
+ if (site.shows("vocabulary") && site.taxonomy.terms.length)
406
+ sections.push({
407
+ title: "Vocabulary",
408
+ href: `${base}/vocabulary`,
409
+ why: "One name for each thing, and the names people reach for instead, so people and agents mean the same thing.",
410
+ count: `${site.taxonomy.terms.length} terms`,
411
+ preview: example ? (
412
+ <span className="text-sm">
413
+ Say <strong className="font-semibold">{example.name}</strong>, <span className="text-muted-foreground line-through decoration-current/40">{example.wrong?.[0]}</span>
414
+ </span>
415
+ ) : null,
416
+ });
417
+
418
+ const loop = [
419
+ ["Written once", "The components, tokens and rules live in the product's own code. Nobody keeps a second copy in a slide deck or a wiki."],
420
+ ["Generated, never drifting", "This site is built from that code on every change, so it cannot fall out of date."],
421
+ ["Read by people and agents", "Every page is also plain markdown, and coding agents are pointed at the same source, so they build with the real components and rules."],
422
+ ["Checked", "Each rule names the check that proves it. Stale docs stop a commit; everything else is reported."],
423
+ ["Measured", "A report on every change shows how closely the product follows the system. It informs the conversation; it never blocks the work."],
424
+ ];
425
+
426
+ return (
427
+ <>
428
+ {!config.hero && (
429
+ <DocsHeader title={site.title} lead={config.lead ?? "The brand and the design system in one place, for the people who make the product and the agents that build it with them."}>
430
+ <PageActions basePath={base} />
431
+ </DocsHeader>
432
+ )}
433
+
434
+ <DocsSection title="What's here, and why" lead="Each part of the system has one job. Together they mean the product, its people and its agents work from the same source.">
435
+ <ul data-slot="overview-sections" className="grid gap-x-12 md:grid-cols-2">
436
+ {sections.map((sec) => (
437
+ <li key={sec.title} className="border-t border-border">
438
+ <Link href={sec.href} className="group flex h-full flex-col gap-4 py-7 focus-visible:outline-2 focus-visible:outline-ring">
439
+ <span className="flex items-baseline justify-between gap-4">
440
+ <span className="text-2xl leading-tight tracking-tight underline-offset-[6px] group-hover:underline">{sec.title}</span>
441
+ <span className="shrink-0 text-xs text-muted-foreground tabular-nums">{sec.count}</span>
442
+ </span>
443
+ <span className="max-w-md text-base leading-relaxed text-muted-foreground">{sec.why}</span>
444
+ {sec.preview && <span className="mt-auto flex min-h-10 items-center pt-2">{sec.preview}</span>}
445
+ </Link>
446
+ </li>
447
+ ))}
448
+ </ul>
449
+ </DocsSection>
450
+
451
+ {config.overview?.agentic !== false && (
452
+ <DocsSection
453
+ title="Why this is agentic"
454
+ lead={
455
+ config.overview?.agenticLead ??
456
+ "A design system used to be a document people were asked to follow. This one is the source the product, its people and its AI agents all work from, and it checks itself."
457
+ }
458
+ >
459
+ <ol data-slot="overview-loop" className="grid gap-x-6 gap-y-8 sm:grid-cols-2 xl:grid-cols-5">
460
+ {loop.map(([title, body], i) => (
461
+ <li key={title} className="relative flex flex-col gap-3 xl:pr-2">
462
+ <span className="flex items-center gap-3">
463
+ <span className="grid size-8 shrink-0 place-items-center rounded-full bg-canvas-foreground text-sm font-medium text-canvas tabular-nums">{i + 1}</span>
464
+ {i < loop.length - 1 && <span aria-hidden className="hidden h-px flex-1 bg-border xl:block" />}
465
+ </span>
466
+ <span className="text-lg leading-snug tracking-tight">{title}</span>
467
+ <span className="text-sm leading-relaxed text-muted-foreground">{body}</span>
468
+ </li>
469
+ ))}
470
+ </ol>
471
+ <p className="flex flex-wrap items-center gap-x-2 gap-y-1 text-sm text-muted-foreground">
472
+ See it the way an agent does:
473
+ <a href={`${base}.md`} className="inline-flex items-center gap-1 font-medium text-canvas-foreground underline underline-offset-4 hover:decoration-2">
474
+ this page as markdown <ArrowUpRight aria-hidden className="size-3.5" />
475
+ </a>
476
+ </p>
477
+ </DocsSection>
478
+ )}
479
+ <DocsFooter provenance={config.provenance} />
480
+ </>
481
+ );
482
+ }
483
+
@@ -0,0 +1,97 @@
1
+ import { DocsSection } from "../shell";
2
+
3
+ /**
4
+ * The few markdown shapes editorial pages use: `##` sections, `###` headings, paragraphs and bullet
5
+ * lists, with bold, code and links. Each `##` is a docs section, so it reads at the same size as a generated page and is
6
+ * listed in "On this page". A list whose every item opens in bold ("**Say it plainly.** …") is a set
7
+ * of principles, numbered, each a heading over its sentence.
8
+ */
9
+ export function Markdown({ text }: { text: string }) {
10
+ const sections: { title?: string; blocks: string[] }[] = [{ blocks: [] }];
11
+ for (const b of text.split(/\n{2,}/)) {
12
+ if (b.startsWith("## ")) sections.push({ title: b.slice(3), blocks: [] });
13
+ else sections[sections.length - 1].blocks.push(b);
14
+ }
15
+ return (
16
+ <>
17
+ {sections.map((s, i) =>
18
+ s.title ? (
19
+ <DocsSection key={s.title} title={s.title}>
20
+ <Blocks blocks={s.blocks} />
21
+ </DocsSection>
22
+ ) : (
23
+ s.blocks.length > 0 && <Blocks key={i} blocks={s.blocks} />
24
+ ),
25
+ )}
26
+ </>
27
+ );
28
+ }
29
+
30
+ function Blocks({ blocks }: { blocks: string[] }) {
31
+ return (
32
+ <div className="flex flex-col gap-5">
33
+ {blocks.map((b, i) => {
34
+ if (b.startsWith("### "))
35
+ return (
36
+ <h3 key={i} className="mt-4 max-w-3xl text-2xl leading-snug tracking-tight first:mt-0">
37
+ {inline(b.slice(4))}
38
+ </h3>
39
+ );
40
+ const lines = b.split("\n");
41
+ if (lines.every((l) => l.startsWith("- "))) {
42
+ const items = lines.map((l) => l.slice(2));
43
+ const principles = items.every((l) => /^\*\*[^*]+\*\*/.test(l));
44
+ if (principles)
45
+ return (
46
+ <ol key={i} className="flex max-w-3xl flex-col gap-12">
47
+ {items.map((l, n) => {
48
+ const [, head, rest] = /^\*\*([^*]+)\*\*\s*(.*)$/.exec(l) ?? [];
49
+ return (
50
+ <li key={l} className="grid grid-cols-[3rem_minmax(0,1fr)] items-baseline gap-x-4 gap-y-3 sm:grid-cols-[4rem_minmax(0,1fr)]">
51
+ <span className="text-lg text-muted-foreground tabular-nums">{String(n + 1).padStart(2, "0")}</span>
52
+ <span className="flex flex-col gap-3">
53
+ <span className="text-2xl leading-snug tracking-tight md:text-3xl">{head.replace(/\.$/, "")}</span>
54
+ <span className="text-lg leading-relaxed text-canvas-foreground/75">{inline(rest)}</span>
55
+ </span>
56
+ </li>
57
+ );
58
+ })}
59
+ </ol>
60
+ );
61
+ return (
62
+ <ul key={i} className="flex max-w-3xl list-disc flex-col gap-2 pl-5 text-lg leading-relaxed">
63
+ {items.map((l) => (
64
+ <li key={l}>{inline(l)}</li>
65
+ ))}
66
+ </ul>
67
+ );
68
+ }
69
+ return (
70
+ <p key={i} className="max-w-3xl text-lg leading-relaxed text-canvas-foreground/80">
71
+ {inline(b)}
72
+ </p>
73
+ );
74
+ })}
75
+ </div>
76
+ );
77
+ }
78
+
79
+ function inline(text: string) {
80
+ return text.split(/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)\s]+\))/).map((part, i) =>
81
+ part.startsWith("[") ? (
82
+ <a key={i} href={/\(([^)]+)\)$/.exec(part)?.[1]} className="underline decoration-from-font underline-offset-4 hover:decoration-2">
83
+ {/^\[([^\]]+)\]/.exec(part)?.[1]}
84
+ </a>
85
+ ) : part.startsWith("**") ? (
86
+ <strong key={i} className="font-semibold">
87
+ {part.slice(2, -2)}
88
+ </strong>
89
+ ) : part.startsWith("`") ? (
90
+ <code key={i} className="font-mono text-[0.9em]">
91
+ {part.slice(1, -1)}
92
+ </code>
93
+ ) : (
94
+ part
95
+ ),
96
+ );
97
+ }
@@ -0,0 +1,55 @@
1
+ import { type NextRequest, NextResponse } from "next/server";
2
+
3
+ /**
4
+ * One URL, two formats, and never public. A docs URL answers `Accept:
5
+ * text/markdown`, or the same path with `.md`, with markdown generated from the
6
+ * manifest; negotiation is on Accept only, never the user agent, so responses say
7
+ * `Vary: Accept` and the HTML links to its markdown. On a production deployment
8
+ * (`VERCEL_ENV`, or `production` you pass) every docs URL, in every format, is a
9
+ * 404, the route handlers included, which no layout wraps.
10
+ *
11
+ * In `proxy.ts`: `export const proxy = docsProxy(); export const config = { matcher: docsMatcher() };`
12
+ */
13
+ export function docsProxy({ basePath = "/design/system", production }: { basePath?: string; production?: () => boolean } = {}) {
14
+ const base = basePath.replace(/\/$/, "");
15
+ const isProduction = production ?? (() => process.env.VERCEL_ENV === "production");
16
+ return function proxy(request: NextRequest) {
17
+ const { pathname } = request.nextUrl;
18
+ if (isProduction()) return new NextResponse("Not found\n", { status: 404, headers: { "x-robots-tag": "noindex" } });
19
+ if (pathname.startsWith(`${base}/md`) || pathname.startsWith(`${base}/manifest/`) || pathname.startsWith(`${base}/preview/`)) return NextResponse.next();
20
+ const page = pathname.replace(/\.md$/, "").replace(/\/$/, "");
21
+ if (pathname.endsWith(".md") || prefersMarkdown(request.headers.get("accept"))) {
22
+ const url = request.nextUrl.clone();
23
+ url.pathname = `${base}/md${page.slice(base.length)}`;
24
+ return NextResponse.rewrite(url, { headers: { vary: "Accept", "x-robots-tag": "noindex" } });
25
+ }
26
+ // Next 16 replaces Vary on page responses with its own, so this one does not survive on HTML;
27
+ // the markdown responses keep theirs.
28
+ const res = NextResponse.next();
29
+ res.headers.set("vary", "Accept");
30
+ res.headers.set("link", `<${page}.md>; rel="alternate"; type="text/markdown"`);
31
+ res.headers.set("x-robots-tag", "noindex");
32
+ return res;
33
+ };
34
+ }
35
+
36
+ /** The proxy's matcher for a base path. Next reads `config.matcher` statically, so write the result out where it must be a literal. */
37
+ export function docsMatcher(basePath = "/design/system"): string[] {
38
+ const base = basePath.replace(/\/$/, "");
39
+ return [base, `${base}.md`, `${base}/:path*`];
40
+ }
41
+
42
+ /** text/markdown ranked above text/html in the Accept header. */
43
+ export function prefersMarkdown(accept: string | null): boolean {
44
+ if (!accept) return false;
45
+ const q = (type: string) => {
46
+ for (const part of accept.split(",")) {
47
+ const [name, ...params] = part.trim().split(";");
48
+ if (name.trim() !== type) continue;
49
+ const weight = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
50
+ return weight ? Number(weight.slice(2)) : 1;
51
+ }
52
+ return 0;
53
+ };
54
+ return q("text/markdown") > 0 && q("text/markdown") >= q("text/html");
55
+ }