@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,65 @@
1
+ import "../styles.css";
2
+ import type { Metadata } from "next";
3
+ import type { ReactNode } from "react";
4
+ import type { DocsConfig } from "./config.js";
5
+ export { Live } from "../lib/live.js";
6
+ export { DocsSection } from "../shell.js";
7
+ export type { BuiltInPage, DocsConfig, EditorialPage, WorkbenchSetup } from "./config.js";
8
+ export { Markdown as Prose } from "./prose.js";
9
+ export { markdownFor } from "./markdown.js";
10
+ export { docsMatcher, docsProxy, prefersMarkdown } from "./proxy.js";
11
+ type SlugParams = {
12
+ params: Promise<{
13
+ slug?: string[];
14
+ }>;
15
+ };
16
+ /**
17
+ * A whole docs site from one config, for the Next App Router. Each export is
18
+ * what one route file re-exports, so a project's docs are a handful of
19
+ * one-line files:
20
+ *
21
+ * - `(docs)/layout.tsx`: `export default docs.Layout`
22
+ * - `(docs)/[[...slug]]/page.tsx`: `export default docs.Page`, with `generateStaticParams` and `generateMetadata`
23
+ * - `md/[[...path]]/route.ts`: `export const GET = docs.markdown`
24
+ * - `manifest/[file]/route.ts`: `export const GET = docs.manifest`, with `generateStaticParams = docs.manifestParams`
25
+ * - `preview/[slug]/[example]/page.tsx`: `export default docs.Preview`
26
+ *
27
+ * The same files serve the docs inside a product's app or as a standalone app.
28
+ */
29
+ export declare function createDocs(config: DocsConfig): {
30
+ site: import("./site.js").Site;
31
+ Layout: ({ children }: {
32
+ children: ReactNode;
33
+ }) => import("react").JSX.Element;
34
+ Page: ({ params }: SlugParams) => Promise<import("react").JSX.Element>;
35
+ generateMetadata: ({ params }: SlugParams) => Promise<Metadata>;
36
+ generateStaticParams: () => {
37
+ slug: string[];
38
+ }[];
39
+ Preview: ({ params, searchParams }: {
40
+ params: Promise<{
41
+ slug: string;
42
+ example: string;
43
+ }>;
44
+ searchParams: Promise<{
45
+ theme?: string;
46
+ }>;
47
+ }) => Promise<import("react").JSX.Element>;
48
+ previewParams: () => {
49
+ slug: string;
50
+ example: string;
51
+ }[];
52
+ markdown: (_: Request, { params }: {
53
+ params: Promise<{
54
+ path?: string[];
55
+ }>;
56
+ }) => Promise<Response>;
57
+ manifest: (_: Request, { params }: {
58
+ params: Promise<{
59
+ file: string;
60
+ }>;
61
+ }) => Promise<Response>;
62
+ manifestParams: () => {
63
+ file: string;
64
+ }[];
65
+ };
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import "../styles.css";
3
+ import { notFound } from "next/navigation";
4
+ import { findBySlug, slugOf } from "../lib/manifest.js";
5
+ import { PreviewExample, PreviewSurface } from "../preview-frame.js";
6
+ import { DocsShell } from "../shell.js";
7
+ import { manifestFiles, manifestRoute, markdownRoute } from "./markdown.js";
8
+ import { DocsPageView } from "./pages.js";
9
+ import { allSlugs, metaOf, navOf, resolve, siteOf } from "./site.js";
10
+ export { Live } from "../lib/live.js";
11
+ export { DocsSection } from "../shell.js";
12
+ export { Markdown as Prose } from "./prose.js";
13
+ export { markdownFor } from "./markdown.js";
14
+ export { docsMatcher, docsProxy, prefersMarkdown } from "./proxy.js";
15
+ /**
16
+ * A whole docs site from one config, for the Next App Router. Each export is
17
+ * what one route file re-exports, so a project's docs are a handful of
18
+ * one-line files:
19
+ *
20
+ * - `(docs)/layout.tsx`: `export default docs.Layout`
21
+ * - `(docs)/[[...slug]]/page.tsx`: `export default docs.Page`, with `generateStaticParams` and `generateMetadata`
22
+ * - `md/[[...path]]/route.ts`: `export const GET = docs.markdown`
23
+ * - `manifest/[file]/route.ts`: `export const GET = docs.manifest`, with `generateStaticParams = docs.manifestParams`
24
+ * - `preview/[slug]/[example]/page.tsx`: `export default docs.Preview`
25
+ *
26
+ * The same files serve the docs inside a product's app or as a standalone app.
27
+ */
28
+ export function createDocs(config) {
29
+ const site = siteOf(config);
30
+ const nav = navOf(site);
31
+ const Registry = config.registry;
32
+ function Layout({ children }) {
33
+ return (_jsx(Registry, { children: _jsx(DocsShell, { manifest: site.components, rules: site.rules, patterns: site.patterns, terms: site.taxonomy, title: site.title, logo: config.logo, basePath: site.base, brand: nav.brand, foundations: nav.foundations, standards: nav.standards, hero: config.hero, children: children }) }));
34
+ }
35
+ async function Page({ params }) {
36
+ const page = resolve(site, (await params).slug);
37
+ if (!page)
38
+ notFound();
39
+ return _jsx(DocsPageView, { site: site, page: page });
40
+ }
41
+ async function generateMetadata({ params }) {
42
+ const page = resolve(site, (await params).slug);
43
+ return page ? metaOf(site, page) : {};
44
+ }
45
+ /** One example on its own, outside the shell: what the preview frame shows, and the target for visual regression. */
46
+ async function Preview({ params, searchParams }) {
47
+ const { slug, example } = await params;
48
+ const { theme } = await searchParams;
49
+ const entry = findBySlug(site.components, slug);
50
+ if (!entry?.examples)
51
+ notFound();
52
+ return (_jsx(Registry, { children: _jsx(PreviewSurface, { theme: theme, children: _jsx(PreviewExample, { entry: entry, example: decodeURIComponent(example) }) }) }));
53
+ }
54
+ return {
55
+ site,
56
+ Layout,
57
+ Page,
58
+ generateMetadata,
59
+ generateStaticParams: () => allSlugs(site).map((slug) => ({ slug })),
60
+ Preview,
61
+ previewParams: () => site.components.components.flatMap((c) => c.examples ? [c.examples.canonical, ...c.examples.do, ...c.examples.dont, ...c.examples.other].filter(Boolean).map((e) => ({ slug: slugOf(c), example: e.name })) : []),
62
+ markdown: markdownRoute(site),
63
+ manifest: manifestRoute(site),
64
+ manifestParams: () => Object.keys(manifestFiles(site)).map((name) => ({ file: `${name}.json` })),
65
+ };
66
+ }
@@ -0,0 +1,20 @@
1
+ import { type Site } from "./site.js";
2
+ /**
3
+ * The markdown form of a docs page, generated from the manifest rather than
4
+ * converted from HTML, or nothing when there is no such page. `context` is the
5
+ * whole system in one file.
6
+ */
7
+ export declare function markdownFor(site: Site, path: string): string | undefined;
8
+ /** The route handler for `md/[[...path]]`: the page's markdown with `Vary: Accept` and its canonical link, or a markdown 404. */
9
+ export declare function markdownRoute(site: Site): (_: Request, { params }: {
10
+ params: Promise<{
11
+ path?: string[];
12
+ }>;
13
+ }) => Promise<Response>;
14
+ /** The route handler for `manifest/[file]`: each manifest file as JSON, so an agent outside the repo gets the exact data. */
15
+ export declare function manifestRoute(site: Site): (_: Request, { params }: {
16
+ params: Promise<{
17
+ file: string;
18
+ }>;
19
+ }) => Promise<Response>;
20
+ export declare function manifestFiles(site: Site): Record<string, unknown>;
@@ -0,0 +1,95 @@
1
+ import { groupByCategory, slugOf } from "../lib/manifest.js";
2
+ import { adherenceMarkdown, assetsMarkdown, coloursMarkdown, componentMarkdown, editorialHeader, generatedHeader, glossaryMarkdown, manifestLinks, patternMarkdown, ruleMarkdown, scaleMarkdown, standardsMarkdown, systemMarkdown, typeMarkdown, } from "../lib/markdown.js";
3
+ import { navOf, resolve } from "./site.js";
4
+ /**
5
+ * The markdown form of a docs page, generated from the manifest rather than
6
+ * converted from HTML, or nothing when there is no such page. `context` is the
7
+ * whole system in one file.
8
+ */
9
+ export function markdownFor(site, path) {
10
+ const { base, title, components, tokens, rules, patterns, taxonomy, assets, config } = site;
11
+ const generated = (md) => generatedHeader(config.provenance ?? "") + md;
12
+ if (path === "context")
13
+ return systemMarkdown({ components, tokens, rules: rules.rules, patterns: patterns.patterns, terms: taxonomy.terms }, title, config.provenance ?? "");
14
+ const page = resolve(site, path ? path.split("/") : []);
15
+ if (!page)
16
+ return undefined;
17
+ switch (page.kind) {
18
+ case "overview": {
19
+ const nav = navOf(site);
20
+ const links = (list) => list.map((l) => `[${l.label}](${l.href}.md)`).join(", ");
21
+ return generated([
22
+ `# ${title}`,
23
+ "",
24
+ "The brand and the design system in one place. Every page here has a markdown form: add `.md` to its URL.",
25
+ "",
26
+ "## Pages",
27
+ "",
28
+ ...(nav.brand.length ? [`- Brand: ${links(nav.brand)}`] : []),
29
+ `- Foundations: ${links(nav.foundations)}`,
30
+ ...(rules.rules.length ? [`- [Rules](${base}/rules.md)`] : []),
31
+ ...patterns.patterns.map((p) => `- Pattern: [${p.name}](${base}/patterns/${p.id}.md)`),
32
+ ...groupByCategory(components).flatMap((g) => g.components.map((c) => `- ${g.category}: [${c.name}](${base}/components/${slugOf(c)}.md), ${c.status ?? "status not set"}`)),
33
+ ...(nav.standards.length ? [`- Standards: ${links(nav.standards)}`] : []),
34
+ `- Everything in [one file](${base}/context.md)`,
35
+ "",
36
+ manifestLinks(`${base}/manifest`),
37
+ ].join("\n"));
38
+ }
39
+ case "editorial":
40
+ return `${editorialHeader(page.page.by)}# ${page.page.title}\n\n${page.page.lead ? `${page.page.lead}\n\n` : ""}${typeof page.page.body === "string" ? page.page.body : page.page.markdown}\n`;
41
+ case "logo":
42
+ return generated(assetsMarkdown(assets.assets.filter((a) => a.kind === "logo")) +
43
+ "\n" +
44
+ rules.rules
45
+ .filter((r) => r.kind === "brand")
46
+ .map(ruleMarkdown)
47
+ .join("\n"));
48
+ case "imagery":
49
+ return generated(assetsMarkdown(assets.assets.filter((a) => a.kind !== "logo")));
50
+ case "voice":
51
+ return generated(glossaryMarkdown(taxonomy.terms.filter((t) => t.kind === "product" || t.wrong?.length)));
52
+ case "colour":
53
+ return generated(coloursMarkdown(tokens));
54
+ case "type":
55
+ return generated(typeMarkdown(tokens));
56
+ case "scale":
57
+ return generated(scaleMarkdown(tokens));
58
+ case "rules":
59
+ return generated(["# Rules", "", ...rules.rules.map(ruleMarkdown)].join("\n"));
60
+ case "pattern":
61
+ return generated(patternMarkdown(page.pattern, 1));
62
+ case "component":
63
+ return generated(componentMarkdown(page.entry, 1));
64
+ case "standards":
65
+ return generated(`${config.baselines ? standardsMarkdown(config.baselines) : ""}\n${config.adherence ? adherenceMarkdown(config.adherence) : ""}`);
66
+ case "vocabulary":
67
+ return generated(glossaryMarkdown(taxonomy.terms));
68
+ }
69
+ }
70
+ /** The route handler for `md/[[...path]]`: the page's markdown with `Vary: Accept` and its canonical link, or a markdown 404. */
71
+ export function markdownRoute(site) {
72
+ return async function GET(_, { params }) {
73
+ const path = ((await params).path ?? []).join("/").replace(/\.md$/, "");
74
+ const page = markdownFor(site, path);
75
+ const canonical = `${site.base}${path ? `/${path}` : ""}`;
76
+ return new Response(page ?? `# Not found\n\nThere is no page at \`${canonical}\`. The index is at [${site.base}.md](${site.base}.md).\n`, {
77
+ status: page ? 200 : 404,
78
+ headers: { "content-type": "text/markdown; charset=utf-8", vary: "Accept", link: `<${canonical}>; rel="canonical"` },
79
+ });
80
+ };
81
+ }
82
+ /** The route handler for `manifest/[file]`: each manifest file as JSON, so an agent outside the repo gets the exact data. */
83
+ export function manifestRoute(site) {
84
+ const files = manifestFiles(site);
85
+ return async function GET(_, { params }) {
86
+ const { file } = await params;
87
+ const data = files[file.replace(/\.json$/, "")];
88
+ if (!data)
89
+ return new Response(`# Not found\n\nNo manifest file called ${file}.\n`, { status: 404, headers: { "content-type": "text/markdown; charset=utf-8" } });
90
+ return Response.json(data);
91
+ };
92
+ }
93
+ export function manifestFiles(site) {
94
+ return Object.fromEntries(Object.entries(site.config.manifest).filter(([, v]) => v !== undefined));
95
+ }
@@ -0,0 +1,6 @@
1
+ import { type PageRef, type Site } from "./site.js";
2
+ /** The page for a reference, composed of blocks. */
3
+ export declare function DocsPageView({ site, page }: {
4
+ site: Site;
5
+ page: PageRef;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,188 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowRight, ArrowUpRight } from "lucide-react";
3
+ import Link from "next/link";
4
+ import { cx, display } from "../lib/cx.js";
5
+ import { AdherenceSummary } from "../adherence-summary.js";
6
+ import { Anatomy } from "../anatomy.js";
7
+ import { Examples } from "../examples.js";
8
+ import { Glossary } from "../glossary.js";
9
+ import { Imagery } from "../imagery.js";
10
+ import { groupFamilies, slugOf } from "../lib/manifest.js";
11
+ import { StatusBadge } from "../lib/status.js";
12
+ import { LogoUsage } from "../logo-usage.js";
13
+ import { PageActions } from "../page-actions.js";
14
+ import { Pattern } from "../pattern.js";
15
+ import { PreviewFrame } from "../preview-frame.js";
16
+ import { PropsTable } from "../props-table.js";
17
+ import { Rule, RuleIndex } from "../rule.js";
18
+ import { Scale } from "../scale.js";
19
+ import { DocsFooter, DocsHeader, DocsSection } from "../shell.js";
20
+ import { Standards } from "../standards.js";
21
+ import { PageContrast, RampSwatches, SemanticSwatches } from "../swatches.js";
22
+ import { TypeRamp } from "../type-ramp.js";
23
+ import { Usage } from "../usage.js";
24
+ import { VariantMatrix } from "../variant-matrix.js";
25
+ import { VoiceTerms } from "../voice-terms.js";
26
+ import { Workbench } from "../workbench.js";
27
+ import { Markdown } from "./prose.js";
28
+ import { COPY } from "./site.js";
29
+ /** Every block a page renders, by the name `config.blocks` replaces it under. */
30
+ const DEFAULT_BLOCKS = {
31
+ AdherenceSummary,
32
+ Anatomy,
33
+ Examples,
34
+ Glossary,
35
+ Imagery,
36
+ LogoUsage,
37
+ PageContrast,
38
+ Pattern,
39
+ PreviewFrame,
40
+ PropsTable,
41
+ RampSwatches,
42
+ Rule,
43
+ RuleIndex,
44
+ Scale,
45
+ SemanticSwatches,
46
+ Standards,
47
+ TypeRamp,
48
+ Usage,
49
+ VariantMatrix,
50
+ VoiceTerms,
51
+ Workbench,
52
+ };
53
+ function blocksOf(site) {
54
+ return { ...DEFAULT_BLOCKS, ...site.config.blocks };
55
+ }
56
+ /** The page for a reference, composed of blocks. */
57
+ export function DocsPageView({ site, page }) {
58
+ const B = blocksOf(site);
59
+ const { base, config } = site;
60
+ const footer = _jsx(DocsFooter, { provenance: config.provenance });
61
+ const header = (title, lead) => (_jsx(DocsHeader, { title: title, lead: lead, children: _jsx(PageActions, { basePath: base }) }));
62
+ switch (page.kind) {
63
+ case "overview":
64
+ return _jsx(Overview, { site: site });
65
+ case "editorial":
66
+ return (_jsxs(_Fragment, { children: [header(page.page.title, page.page.lead), typeof page.page.body === "string" ? _jsx(Markdown, { text: page.page.body }) : page.page.body, _jsx(DocsFooter, { editorial: page.page.by })] }));
67
+ case "logo":
68
+ return (_jsxs(_Fragment, { children: [header(COPY.logo.title, COPY.logo.lead), _jsx(B.LogoUsage, { assets: site.assets.assets, rules: site.rules.rules, rulesHref: `${base}/rules` }), footer] }));
69
+ case "imagery":
70
+ return (_jsxs(_Fragment, { children: [header(COPY.imagery.title, COPY.imagery.lead), _jsx(B.Imagery, { assets: site.assets.assets }), footer] }));
71
+ case "voice":
72
+ return (_jsxs(_Fragment, { children: [header(COPY.voice.title, COPY.voice.lead), _jsx(B.VoiceTerms, { terms: site.taxonomy.terms }), footer] }));
73
+ case "colour":
74
+ return (_jsxs(_Fragment, { children: [header(COPY.colour.title, COPY.colour.lead), _jsx(DocsSection, { title: "Semantic colours", lead: "Each pair is measured on the colours the browser paints, in each mode.", children: _jsx(B.SemanticSwatches, { tokens: site.tokens }) }), _jsx(DocsSection, { title: "On the page", 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.", children: _jsx(B.PageContrast, { tokens: site.tokens }) }), _jsx(DocsSection, { title: "Ramps", children: _jsx(B.RampSwatches, { tokens: site.tokens }) }), footer] }));
75
+ case "type":
76
+ return (_jsxs(_Fragment, { children: [header(COPY.type.title, COPY.type.lead), _jsx(B.TypeRamp, { tokens: site.tokens }), footer] }));
77
+ case "scale":
78
+ return (_jsxs(_Fragment, { children: [header(COPY.scale.title, COPY.scale.lead), _jsx(B.Scale, { tokens: site.tokens }), footer] }));
79
+ case "rules":
80
+ return (_jsxs(_Fragment, { children: [header(COPY.rules.title, COPY.rules.lead), _jsx(DocsSection, { title: "Every rule", lead: "A line each: what it covers, how settled it is, and how it is checked.", children: _jsx(B.RuleIndex, { rules: [...site.rules.rules].sort((a, b) => a.kind.localeCompare(b.kind)) }) }), ["brand", "interface"].map((kind) => {
81
+ const rules = site.rules.rules.filter((r) => r.kind === kind);
82
+ return rules.length ? (_jsx(DocsSection, { title: kind === "brand" ? "Brand" : "Interface", children: rules.map((r) => (_jsx(B.Rule, { rule: r, children: config.demonstrations?.[r.id] }, r.id))) }, kind)) : null;
83
+ }), footer] }));
84
+ case "standards":
85
+ return (_jsxs(_Fragment, { children: [header(COPY.standards.title, COPY.standards.lead), config.baselines && (_jsx(DocsSection, { title: "Targets", children: _jsx(B.Standards, { baselines: config.baselines }) })), config.adherence && (_jsx(DocsSection, { title: "Adherence", lead: "How closely the product follows the system, from @designtools/adherence. It informs; it never blocks.", children: _jsx(B.AdherenceSummary, { report: config.adherence }) })), footer] }));
86
+ case "vocabulary":
87
+ return (_jsxs(_Fragment, { children: [header(COPY.vocabulary.title, COPY.vocabulary.lead), _jsx(B.Glossary, { terms: site.taxonomy.terms }), footer] }));
88
+ case "pattern":
89
+ return (_jsxs(_Fragment, { children: [_jsx(DocsHeader, { title: page.pattern.name, lead: page.pattern.description, status: page.pattern.status, children: _jsx(PageActions, { basePath: base }) }), _jsx(B.Pattern, { pattern: page.pattern, manifest: site.components, basePath: base }), _jsx(DocsFooter, { source: page.pattern.source, provenance: config.provenance })] }));
90
+ case "component":
91
+ return _jsx(ComponentPage, { site: site, blocks: B, entry: page.entry });
92
+ }
93
+ }
94
+ function ComponentPage({ site, blocks: B, entry }) {
95
+ const { base, config } = site;
96
+ // A part (TabsPanel, CardHeader) renders inside its family's root, so it is shown there, never alone:
97
+ // a part rendered on its own can throw for want of the root's context.
98
+ const head = entry.category ? undefined : site.components.components.find((c) => c.source === entry.source && c.category);
99
+ if (head)
100
+ return (_jsxs(_Fragment, { children: [_jsx(DocsHeader, { title: entry.name, lead: entry.description ?? `A part of ${head.name}, used inside it.`, children: _jsx(PageActions, { basePath: base }) }), _jsx(DocsSection, { title: "Part of", lead: `Its examples, variants and anatomy are on ${head.name}'s page, where it renders inside the whole.`, children: _jsxs(Link, { href: `${base}/components/${slugOf(head)}`, 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", children: [_jsxs("span", { className: "flex flex-col gap-1", children: [_jsx("span", { className: "text-xl tracking-tight underline-offset-4 group-hover:underline", children: head.name }), head.description && _jsx("span", { className: "line-clamp-2 text-sm text-muted-foreground", children: head.description })] }), _jsx(ArrowRight, { "aria-hidden": true, className: "size-5 shrink-0 text-muted-foreground" })] }) }), _jsx(DocsSection, { title: "Props", children: _jsx(B.PropsTable, { entry: entry }) }), _jsx(DocsFooter, { source: entry.source, provenance: config.provenance })] }));
101
+ const setup = config.workbench?.[entry.name] ?? {};
102
+ const preview = `${base}/preview/${slugOf(entry)}`;
103
+ const first = entry.examples?.canonical?.name;
104
+ // the brand's named backgrounds (--surface-<name>), offered on the workbench's stage
105
+ const backgrounds = site.tokens.tokens.map((t) => t.name.slice(2)).filter((n) => /^surface-[a-z]/.test(n) && !n.endsWith("-foreground"));
106
+ return (_jsxs(_Fragment, { children: [_jsx(DocsHeader, { title: entry.name, lead: entry.description, children: _jsx(PageActions, { basePath: base }) }), _jsx(DocsSection, { title: "Usage", children: _jsx(B.Usage, { entry: entry, manifest: site.components, basePath: base }) }), _jsx(B.Workbench, { entry: entry, props: setup.props, content: setup.content, wrap: setup.wrap, backgrounds: backgrounds, previewHref: first && `${preview}/${first}`, children: setup.children }), _jsx(DocsSection, { title: "Anatomy", children: _jsx(B.Anatomy, { entry: entry }) }), _jsx(DocsSection, { title: "Examples", lead: "The usual use first, then each do beside its don't. Every one is the real component.", children: _jsx(B.Examples, { entry: entry, previewHref: preview }) }), !!entry.variants?.axes.length && (_jsx(DocsSection, { title: "Variants", lead: `Every combination, from the ${entry.variants.from === "props" ? "props' types" : `${entry.variants.from}() config`}, then each state.`, children: _jsx(B.VariantMatrix, { entry: entry, props: setup.props, children: setup.children === "" ? undefined : (setup.content ?? entry.name) }) })), first && (_jsx(DocsSection, { title: "At each width", children: _jsx(B.PreviewFrame, { src: `${preview}/${first}`, title: `${entry.name}: ${first}` }) })), _jsx(DocsFooter, { source: entry.source, provenance: config.provenance })] }));
107
+ }
108
+ /** The overview, below the hero when there is one: each part of the system and why it exists, then why it is agentic. */
109
+ function Overview({ site }) {
110
+ const { base, config } = site;
111
+ const families = groupFamilies(site.components);
112
+ const count = families.reduce((n, g) => n + g.families.length, 0);
113
+ const brandPages = site.editorial.filter((p) => (p.section ?? "brand") === "brand");
114
+ const brandFirst = brandPages[0];
115
+ const products = site.taxonomy.terms.filter((t) => t.kind === "product" && t.wrong?.length);
116
+ const example = products[0] ?? site.taxonomy.terms.find((t) => t.wrong?.length);
117
+ const fills = ["--primary", "--neutral", "--success", "--warning", "--destructive"].filter((n) => site.tokens.tokens.some((t) => t.name === n));
118
+ const share = config.adherence?.summary.share;
119
+ // each section of the system, why it exists, how much is in it, and a glimpse of it, live from the manifest
120
+ const sections = [];
121
+ if (brandFirst || site.shows("logo"))
122
+ sections.push({
123
+ title: "Brand",
124
+ href: `${base}/${brandFirst?.slug ?? "brand/logo"}`,
125
+ why: "What the brand believes, how it sounds and how it looks, so every screen and sentence comes from the same place.",
126
+ count: `${brandPages.length + (site.assets.assets.some((a) => a.kind === "logo") ? 1 : 0)} pages`,
127
+ preview: config.logo ? _jsx("span", { className: "flex h-10 items-center [&_img]:h-8 [&_svg]:h-8", children: config.logo }) : null,
128
+ });
129
+ sections.push({
130
+ title: "Foundations",
131
+ href: `${base}/colour`,
132
+ why: "Colour, type and the scale, generated from the tokens and measured in both modes, so nothing is a guess.",
133
+ count: `${site.tokens.tokens.length} tokens`,
134
+ preview: (_jsxs("span", { className: "flex items-center gap-4", children: [_jsx("span", { className: "flex -space-x-1.5", children: fills.map((n) => (_jsx("span", { "aria-hidden": true, className: "size-8 rounded-full ring-2 ring-canvas", style: { background: `var(${n})` } }, n))) }), _jsx("span", { "aria-hidden": true, className: cx(display, "text-3xl leading-none tracking-tight"), children: "Aa" })] })),
135
+ });
136
+ if (site.rules.rules.length)
137
+ sections.push({
138
+ title: "Rules",
139
+ href: `${base}/rules`,
140
+ why: "The lines the brand and the interface hold, each written for people, with the check that proves it.",
141
+ count: `${site.rules.rules.length} rules, ${site.rules.rules.filter((r) => r.status === "confirmed").length} confirmed`,
142
+ preview: (_jsx("span", { className: "flex flex-col gap-1.5 text-sm", children: site.rules.rules
143
+ .filter((r) => r.kind === "brand")
144
+ .slice(0, 2)
145
+ .map((r) => (_jsxs("span", { className: "flex items-center gap-2", children: [_jsx(StatusBadge, { status: r.status }), _jsx("span", { className: "truncate", children: r.title })] }, r.id))) })),
146
+ });
147
+ if (site.shows("components") && count)
148
+ sections.push({
149
+ title: "Components",
150
+ href: `${base}/components/${slugOf(families[0].families[0].head)}`,
151
+ why: "The real components the product is built from, each with when to use it, a live workbench and an accessibility report.",
152
+ count: `${count} components`,
153
+ preview: (_jsx("span", { className: "flex flex-wrap gap-1.5", children: families.slice(0, 6).map((g) => (_jsxs("span", { className: "inline-flex min-h-7 items-center rounded-md bg-muted px-2 text-xs", children: [g.category, " ", _jsx("span", { className: "ml-1.5 text-muted-foreground tabular-nums", children: g.families.length })] }, g.category))) })),
154
+ });
155
+ if (site.patterns.patterns.length)
156
+ sections.push({
157
+ title: "Patterns",
158
+ href: `${base}/patterns/${site.patterns.patterns[0].id}`,
159
+ why: "The screens the product keeps making, composed of the components, so a recurring problem is solved once.",
160
+ count: `${site.patterns.patterns.length} patterns`,
161
+ preview: _jsx("span", { className: "text-sm text-muted-foreground", children: site.patterns.patterns.slice(0, 3).map((p) => p.name).join(" · ") }),
162
+ });
163
+ if (site.shows("standards") && (config.baselines || config.adherence))
164
+ sections.push({
165
+ title: "Standards",
166
+ href: `${base}/standards`,
167
+ why: "The bar the product is held to, and how closely it follows the system today, reported on every change.",
168
+ count: share == null ? "Baselines agreed" : `${Math.round(share * 100)}% of the product on the system`,
169
+ preview: share == null ? null : (_jsxs("span", { className: "flex w-full max-w-56 items-center gap-3", children: [_jsx("span", { className: "h-1.5 flex-1 overflow-hidden rounded-full bg-muted", children: _jsx("span", { className: "block h-full rounded-full bg-canvas-foreground", style: { width: `${Math.round(share * 100)}%` } }) }), _jsxs("span", { className: "text-sm tabular-nums", children: [Math.round(share * 100), "%"] })] })),
170
+ });
171
+ if (site.shows("vocabulary") && site.taxonomy.terms.length)
172
+ sections.push({
173
+ title: "Vocabulary",
174
+ href: `${base}/vocabulary`,
175
+ why: "One name for each thing, and the names people reach for instead, so people and agents mean the same thing.",
176
+ count: `${site.taxonomy.terms.length} terms`,
177
+ preview: example ? (_jsxs("span", { className: "text-sm", children: ["Say ", _jsx("strong", { className: "font-semibold", children: example.name }), ", ", _jsx("span", { className: "text-muted-foreground line-through decoration-current/40", children: example.wrong?.[0] })] })) : null,
178
+ });
179
+ const loop = [
180
+ ["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."],
181
+ ["Generated, never drifting", "This site is built from that code on every change, so it cannot fall out of date."],
182
+ ["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."],
183
+ ["Checked", "Each rule names the check that proves it. Stale docs stop a commit; everything else is reported."],
184
+ ["Measured", "A report on every change shows how closely the product follows the system. It informs the conversation; it never blocks the work."],
185
+ ];
186
+ return (_jsxs(_Fragment, { children: [!config.hero && (_jsx(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.", children: _jsx(PageActions, { basePath: base }) })), _jsx(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.", children: _jsx("ul", { "data-slot": "overview-sections", className: "grid gap-x-12 md:grid-cols-2", children: sections.map((sec) => (_jsx("li", { className: "border-t border-border", children: _jsxs(Link, { href: sec.href, className: "group flex h-full flex-col gap-4 py-7 focus-visible:outline-2 focus-visible:outline-ring", children: [_jsxs("span", { className: "flex items-baseline justify-between gap-4", children: [_jsx("span", { className: "text-2xl leading-tight tracking-tight underline-offset-[6px] group-hover:underline", children: sec.title }), _jsx("span", { className: "shrink-0 text-xs text-muted-foreground tabular-nums", children: sec.count })] }), _jsx("span", { className: "max-w-md text-base leading-relaxed text-muted-foreground", children: sec.why }), sec.preview && _jsx("span", { className: "mt-auto flex min-h-10 items-center pt-2", children: sec.preview })] }) }, sec.title))) }) }), config.overview?.agentic !== false && (_jsxs(DocsSection, { title: "Why this is agentic", lead: config.overview?.agenticLead ??
187
+ "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.", children: [_jsx("ol", { "data-slot": "overview-loop", className: "grid gap-x-6 gap-y-8 sm:grid-cols-2 xl:grid-cols-5", children: loop.map(([title, body], i) => (_jsxs("li", { className: "relative flex flex-col gap-3 xl:pr-2", children: [_jsxs("span", { className: "flex items-center gap-3", children: [_jsx("span", { className: "grid size-8 shrink-0 place-items-center rounded-full bg-canvas-foreground text-sm font-medium text-canvas tabular-nums", children: i + 1 }), i < loop.length - 1 && _jsx("span", { "aria-hidden": true, className: "hidden h-px flex-1 bg-border xl:block" })] }), _jsx("span", { className: "text-lg leading-snug tracking-tight", children: title }), _jsx("span", { className: "text-sm leading-relaxed text-muted-foreground", children: body })] }, title))) }), _jsxs("p", { className: "flex flex-wrap items-center gap-x-2 gap-y-1 text-sm text-muted-foreground", children: ["See it the way an agent does:", _jsxs("a", { href: `${base}.md`, className: "inline-flex items-center gap-1 font-medium text-canvas-foreground underline underline-offset-4 hover:decoration-2", children: ["this page as markdown ", _jsx(ArrowUpRight, { "aria-hidden": true, className: "size-3.5" })] })] })] })), _jsx(DocsFooter, { provenance: config.provenance })] }));
188
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The few markdown shapes editorial pages use: `##` sections, `###` headings, paragraphs and bullet
3
+ * lists, with bold, code and links. Each `##` is a docs section, so it reads at the same size as a generated page and is
4
+ * listed in "On this page". A list whose every item opens in bold ("**Say it plainly.** …") is a set
5
+ * of principles, numbered, each a heading over its sentence.
6
+ */
7
+ export declare function Markdown({ text }: {
8
+ text: string;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DocsSection } from "../shell.js";
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 }) {
10
+ const sections = [{ blocks: [] }];
11
+ for (const b of text.split(/\n{2,}/)) {
12
+ if (b.startsWith("## "))
13
+ sections.push({ title: b.slice(3), blocks: [] });
14
+ else
15
+ sections[sections.length - 1].blocks.push(b);
16
+ }
17
+ return (_jsx(_Fragment, { children: sections.map((s, i) => s.title ? (_jsx(DocsSection, { title: s.title, children: _jsx(Blocks, { blocks: s.blocks }) }, s.title)) : (s.blocks.length > 0 && _jsx(Blocks, { blocks: s.blocks }, i))) }));
18
+ }
19
+ function Blocks({ blocks }) {
20
+ return (_jsx("div", { className: "flex flex-col gap-5", children: blocks.map((b, i) => {
21
+ if (b.startsWith("### "))
22
+ return (_jsx("h3", { className: "mt-4 max-w-3xl text-2xl leading-snug tracking-tight first:mt-0", children: inline(b.slice(4)) }, i));
23
+ const lines = b.split("\n");
24
+ if (lines.every((l) => l.startsWith("- "))) {
25
+ const items = lines.map((l) => l.slice(2));
26
+ const principles = items.every((l) => /^\*\*[^*]+\*\*/.test(l));
27
+ if (principles)
28
+ return (_jsx("ol", { className: "flex max-w-3xl flex-col gap-12", children: items.map((l, n) => {
29
+ const [, head, rest] = /^\*\*([^*]+)\*\*\s*(.*)$/.exec(l) ?? [];
30
+ return (_jsxs("li", { className: "grid grid-cols-[3rem_minmax(0,1fr)] items-baseline gap-x-4 gap-y-3 sm:grid-cols-[4rem_minmax(0,1fr)]", children: [_jsx("span", { className: "text-lg text-muted-foreground tabular-nums", children: String(n + 1).padStart(2, "0") }), _jsxs("span", { className: "flex flex-col gap-3", children: [_jsx("span", { className: "text-2xl leading-snug tracking-tight md:text-3xl", children: head.replace(/\.$/, "") }), _jsx("span", { className: "text-lg leading-relaxed text-canvas-foreground/75", children: inline(rest) })] })] }, l));
31
+ }) }, i));
32
+ return (_jsx("ul", { className: "flex max-w-3xl list-disc flex-col gap-2 pl-5 text-lg leading-relaxed", children: items.map((l) => (_jsx("li", { children: inline(l) }, l))) }, i));
33
+ }
34
+ return (_jsx("p", { className: "max-w-3xl text-lg leading-relaxed text-canvas-foreground/80", children: inline(b) }, i));
35
+ }) }));
36
+ }
37
+ function inline(text) {
38
+ return text.split(/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)\s]+\))/).map((part, i) => part.startsWith("[") ? (_jsx("a", { href: /\(([^)]+)\)$/.exec(part)?.[1], className: "underline decoration-from-font underline-offset-4 hover:decoration-2", children: /^\[([^\]]+)\]/.exec(part)?.[1] }, i)) : part.startsWith("**") ? (_jsx("strong", { className: "font-semibold", children: part.slice(2, -2) }, i)) : part.startsWith("`") ? (_jsx("code", { className: "font-mono text-[0.9em]", children: part.slice(1, -1) }, i)) : (part));
39
+ }
@@ -0,0 +1,19 @@
1
+ import { type NextRequest, NextResponse } from "next/server";
2
+ /**
3
+ * One URL, two formats, and never public. A docs URL answers `Accept:
4
+ * text/markdown`, or the same path with `.md`, with markdown generated from the
5
+ * manifest; negotiation is on Accept only, never the user agent, so responses say
6
+ * `Vary: Accept` and the HTML links to its markdown. On a production deployment
7
+ * (`VERCEL_ENV`, or `production` you pass) every docs URL, in every format, is a
8
+ * 404, the route handlers included, which no layout wraps.
9
+ *
10
+ * In `proxy.ts`: `export const proxy = docsProxy(); export const config = { matcher: docsMatcher() };`
11
+ */
12
+ export declare function docsProxy({ basePath, production }?: {
13
+ basePath?: string;
14
+ production?: () => boolean;
15
+ }): (request: NextRequest) => NextResponse<unknown>;
16
+ /** The proxy's matcher for a base path. Next reads `config.matcher` statically, so write the result out where it must be a literal. */
17
+ export declare function docsMatcher(basePath?: string): string[];
18
+ /** text/markdown ranked above text/html in the Accept header. */
19
+ export declare function prefersMarkdown(accept: string | null): boolean;
@@ -0,0 +1,56 @@
1
+ import { NextResponse } from "next/server";
2
+ /**
3
+ * One URL, two formats, and never public. A docs URL answers `Accept:
4
+ * text/markdown`, or the same path with `.md`, with markdown generated from the
5
+ * manifest; negotiation is on Accept only, never the user agent, so responses say
6
+ * `Vary: Accept` and the HTML links to its markdown. On a production deployment
7
+ * (`VERCEL_ENV`, or `production` you pass) every docs URL, in every format, is a
8
+ * 404, the route handlers included, which no layout wraps.
9
+ *
10
+ * In `proxy.ts`: `export const proxy = docsProxy(); export const config = { matcher: docsMatcher() };`
11
+ */
12
+ export function docsProxy({ basePath = "/design/system", production } = {}) {
13
+ const base = basePath.replace(/\/$/, "");
14
+ const isProduction = production ?? (() => process.env.VERCEL_ENV === "production");
15
+ return function proxy(request) {
16
+ const { pathname } = request.nextUrl;
17
+ if (isProduction())
18
+ 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/`))
20
+ return NextResponse.next();
21
+ const page = pathname.replace(/\.md$/, "").replace(/\/$/, "");
22
+ if (pathname.endsWith(".md") || prefersMarkdown(request.headers.get("accept"))) {
23
+ const url = request.nextUrl.clone();
24
+ url.pathname = `${base}/md${page.slice(base.length)}`;
25
+ return NextResponse.rewrite(url, { headers: { vary: "Accept", "x-robots-tag": "noindex" } });
26
+ }
27
+ // Next 16 replaces Vary on page responses with its own, so this one does not survive on HTML;
28
+ // the markdown responses keep theirs.
29
+ const res = NextResponse.next();
30
+ res.headers.set("vary", "Accept");
31
+ res.headers.set("link", `<${page}.md>; rel="alternate"; type="text/markdown"`);
32
+ res.headers.set("x-robots-tag", "noindex");
33
+ return res;
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") {
38
+ const base = basePath.replace(/\/$/, "");
39
+ return [base, `${base}.md`, `${base}/:path*`];
40
+ }
41
+ /** text/markdown ranked above text/html in the Accept header. */
42
+ export function prefersMarkdown(accept) {
43
+ if (!accept)
44
+ return false;
45
+ const q = (type) => {
46
+ for (const part of accept.split(",")) {
47
+ const [name, ...params] = part.trim().split(";");
48
+ if (name.trim() !== type)
49
+ continue;
50
+ const weight = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
51
+ return weight ? Number(weight.slice(2)) : 1;
52
+ }
53
+ return 0;
54
+ };
55
+ return q("text/markdown") > 0 && q("text/markdown") >= q("text/html");
56
+ }
@@ -0,0 +1,53 @@
1
+ import type { DocsLink } from "../shell.js";
2
+ import type { AssetsManifest, ComponentEntry, ComponentsManifest, PatternEntry, PatternsManifest, RulesManifest, TaxonomyManifest, TokensManifest } from "../lib/manifest-types.js";
3
+ import type { BuiltInPage, DocsConfig, EditorialPage } from "./config.js";
4
+ /** The config, read once: the manifest typed and checked, and what is shown. */
5
+ export interface Site {
6
+ config: DocsConfig;
7
+ base: string;
8
+ title: string;
9
+ components: ComponentsManifest;
10
+ tokens: TokensManifest;
11
+ rules: RulesManifest;
12
+ patterns: PatternsManifest;
13
+ taxonomy: TaxonomyManifest;
14
+ assets: AssetsManifest;
15
+ editorial: EditorialPage[];
16
+ shows: (page: BuiltInPage) => boolean;
17
+ }
18
+ export declare function siteOf(config: DocsConfig): Site;
19
+ /** One page of the docs, by what it shows. */
20
+ export type PageRef = {
21
+ kind: "overview";
22
+ } | {
23
+ kind: "editorial";
24
+ page: EditorialPage;
25
+ } | {
26
+ kind: "logo" | "imagery" | "voice" | "colour" | "type" | "scale" | "rules" | "standards" | "vocabulary";
27
+ } | {
28
+ kind: "component";
29
+ entry: ComponentEntry;
30
+ } | {
31
+ kind: "pattern";
32
+ pattern: PatternEntry;
33
+ };
34
+ /** The page at a path under the docs, or nothing. */
35
+ export declare function resolve(site: Site, slug?: string[]): PageRef | undefined;
36
+ /** Every page's path, for static generation. */
37
+ export declare function allSlugs(site: Site): string[][];
38
+ /** The navigation's editorial and generated groups: brand, foundations, standards. Rules, patterns and components the shell adds from the manifest. */
39
+ export declare function navOf(site: Site): {
40
+ brand: DocsLink[];
41
+ foundations: DocsLink[];
42
+ standards: DocsLink[];
43
+ };
44
+ /** Each built-in page's title and lead: what the page says it is, which is also its description. */
45
+ export declare const COPY: Record<Exclude<PageRef["kind"], "overview" | "editorial" | "component" | "pattern">, {
46
+ title: string;
47
+ lead: string;
48
+ }>;
49
+ /** A page's title and description, for its metadata. */
50
+ export declare function metaOf(site: Site, ref: PageRef): {
51
+ title: string;
52
+ description?: string;
53
+ };