@designtools/docs 0.0.0-stage → 0.1.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 (167) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +133 -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 +38 -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 +14 -0
  21. package/dist/imagery.d.ts +6 -0
  22. package/dist/imagery.js +17 -0
  23. package/dist/index.d.ts +34 -0
  24. package/dist/index.js +33 -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/lookup.d.ts +35 -0
  36. package/dist/lib/lookup.js +41 -0
  37. package/dist/lib/manifest-types.d.ts +253 -0
  38. package/dist/lib/manifest-types.js +14 -0
  39. package/dist/lib/manifest.d.ts +98 -0
  40. package/dist/lib/manifest.js +173 -0
  41. package/dist/lib/markdown.d.ts +50 -0
  42. package/dist/lib/markdown.js +286 -0
  43. package/dist/lib/measure.d.ts +12 -0
  44. package/dist/lib/measure.js +62 -0
  45. package/dist/lib/pseudo.d.ts +11 -0
  46. package/dist/lib/pseudo.js +71 -0
  47. package/dist/lib/registry.d.ts +21 -0
  48. package/dist/lib/registry.js +11 -0
  49. package/dist/lib/search.d.ts +44 -0
  50. package/dist/lib/search.js +62 -0
  51. package/dist/lib/standards.d.ts +17 -0
  52. package/dist/lib/standards.js +81 -0
  53. package/dist/lib/status.d.ts +7 -0
  54. package/dist/lib/status.js +17 -0
  55. package/dist/lib/text.d.ts +8 -0
  56. package/dist/lib/text.js +9 -0
  57. package/dist/lib/ui.d.ts +100 -0
  58. package/dist/lib/ui.js +89 -0
  59. package/dist/lib/vision.d.ts +18 -0
  60. package/dist/lib/vision.js +27 -0
  61. package/dist/logo-usage.d.ts +14 -0
  62. package/dist/logo-usage.js +45 -0
  63. package/dist/next/config.d.ts +85 -0
  64. package/dist/next/config.js +1 -0
  65. package/dist/next/index.d.ts +62 -0
  66. package/dist/next/index.js +63 -0
  67. package/dist/next/markdown.d.ts +20 -0
  68. package/dist/next/markdown.js +95 -0
  69. package/dist/next/pages.d.ts +6 -0
  70. package/dist/next/pages.js +122 -0
  71. package/dist/next/prose.d.ts +9 -0
  72. package/dist/next/prose.js +37 -0
  73. package/dist/next/proxy.d.ts +19 -0
  74. package/dist/next/proxy.js +56 -0
  75. package/dist/next/site.d.ts +53 -0
  76. package/dist/next/site.js +136 -0
  77. package/dist/page-actions.d.ts +9 -0
  78. package/dist/page-actions.js +32 -0
  79. package/dist/pattern.d.ts +8 -0
  80. package/dist/pattern.js +19 -0
  81. package/dist/playground.d.ts +62 -0
  82. package/dist/playground.js +111 -0
  83. package/dist/preview-frame.d.ts +31 -0
  84. package/dist/preview-frame.js +63 -0
  85. package/dist/props-table.d.ts +10 -0
  86. package/dist/props-table.js +45 -0
  87. package/dist/rule.d.ts +12 -0
  88. package/dist/rule.js +32 -0
  89. package/dist/scale.d.ts +9 -0
  90. package/dist/scale.js +58 -0
  91. package/dist/search.d.ts +16 -0
  92. package/dist/search.js +46 -0
  93. package/dist/shell.d.ts +89 -0
  94. package/dist/shell.js +199 -0
  95. package/dist/standards.d.ts +13 -0
  96. package/dist/standards.js +19 -0
  97. package/dist/styles.css +3519 -0
  98. package/dist/swatches.d.ts +28 -0
  99. package/dist/swatches.js +94 -0
  100. package/dist/theme-switch.d.ts +20 -0
  101. package/dist/theme-switch.js +68 -0
  102. package/dist/type-ramp.d.ts +10 -0
  103. package/dist/type-ramp.js +31 -0
  104. package/dist/usage.d.ts +13 -0
  105. package/dist/usage.js +55 -0
  106. package/dist/variant-matrix.d.ts +15 -0
  107. package/dist/variant-matrix.js +53 -0
  108. package/dist/voice-terms.d.ts +5 -0
  109. package/dist/voice-terms.js +13 -0
  110. package/dist/workbench.d.ts +33 -0
  111. package/dist/workbench.js +273 -0
  112. package/package.json +107 -3
  113. package/src/a11y-panel.tsx +297 -0
  114. package/src/adherence-summary.tsx +134 -0
  115. package/src/agent-view.tsx +54 -0
  116. package/src/anatomy.tsx +114 -0
  117. package/src/ask-claude.tsx +90 -0
  118. package/src/code-view.tsx +112 -0
  119. package/src/css.d.ts +1 -0
  120. package/src/examples.tsx +141 -0
  121. package/src/glossary.tsx +71 -0
  122. package/src/imagery.tsx +64 -0
  123. package/src/index.ts +34 -0
  124. package/src/lib/adherence-types.ts +181 -0
  125. package/src/lib/boundary.tsx +21 -0
  126. package/src/lib/contrast.ts +44 -0
  127. package/src/lib/cx.ts +30 -0
  128. package/src/lib/jsx.ts +29 -0
  129. package/src/lib/lookup.tsx +49 -0
  130. package/src/lib/manifest-types.ts +284 -0
  131. package/src/lib/manifest.ts +228 -0
  132. package/src/lib/markdown.ts +288 -0
  133. package/src/lib/measure.tsx +101 -0
  134. package/src/lib/pseudo.ts +74 -0
  135. package/src/lib/registry.tsx +29 -0
  136. package/src/lib/search.ts +99 -0
  137. package/src/lib/standards.ts +82 -0
  138. package/src/lib/status.tsx +32 -0
  139. package/src/lib/text.tsx +27 -0
  140. package/src/lib/ui.tsx +291 -0
  141. package/src/lib/vision.tsx +44 -0
  142. package/src/logo-usage.tsx +140 -0
  143. package/src/next/config.ts +80 -0
  144. package/src/next/index.tsx +100 -0
  145. package/src/next/markdown.ts +119 -0
  146. package/src/next/pages.tsx +370 -0
  147. package/src/next/prose.tsx +87 -0
  148. package/src/next/proxy.ts +55 -0
  149. package/src/next/site.ts +173 -0
  150. package/src/page-actions.tsx +92 -0
  151. package/src/pattern.tsx +67 -0
  152. package/src/playground.tsx +352 -0
  153. package/src/preview-frame.tsx +131 -0
  154. package/src/props-table.tsx +154 -0
  155. package/src/rule.tsx +116 -0
  156. package/src/scale.tsx +175 -0
  157. package/src/search.tsx +155 -0
  158. package/src/shell.tsx +555 -0
  159. package/src/standards.tsx +58 -0
  160. package/src/styles.css +155 -0
  161. package/src/swatches.tsx +287 -0
  162. package/src/theme-switch.tsx +90 -0
  163. package/src/type-ramp.tsx +150 -0
  164. package/src/usage.tsx +148 -0
  165. package/src/variant-matrix.tsx +195 -0
  166. package/src/voice-terms.tsx +46 -0
  167. package/src/workbench.tsx +584 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * The adherence report: what `designtools-adherence` writes with `--json`, and
3
+ * what the "Adherence summary" docs block renders.
4
+ *
5
+ * This file has no imports on purpose, so @designtools/docs can carry a copy
6
+ * and read the report through the same types the tool wrote it with.
7
+ *
8
+ * Every path is relative to the project root, with forward slashes. Lines and
9
+ * columns start at 1. Every array is sorted (files and routes by path, findings
10
+ * by line then column, components and elements by name), and there are no
11
+ * timestamps, so the same source gives the same bytes.
12
+ */
13
+
14
+ export const ADHERENCE_SCHEMA = "designtools.adherence/1";
15
+
16
+ export interface AdherenceReport {
17
+ /** `@designtools/adherence@<version>`. */
18
+ generator: string;
19
+ schema: string;
20
+ /** The components.json the system was read from. */
21
+ manifest: string;
22
+ /** The system folder, which is never scanned as product. */
23
+ system: string;
24
+ /** The globs that chose the product files, as given or defaulted. */
25
+ include: string[];
26
+ exclude: string[];
27
+ summary: Summary;
28
+ /** One per Next app router page (`app/**\/page.tsx`), sorted by route. */
29
+ routes: RouteEntry[];
30
+ /** Every scanned file with at least one use, raw element or finding, sorted by path. */
31
+ files: FileEntry[];
32
+ /** Every system component, used or not, sorted by name. */
33
+ components: ComponentUsage[];
34
+ /** Every raw element some component `replaces`, sorted by selector. */
35
+ elements: ElementUsage[];
36
+ /** Files a scanner could not parse, sorted by path. Their numbers are missing from the report. */
37
+ skipped: SkippedFile[];
38
+ }
39
+
40
+ /** The numbers every level of the report shares: the whole product, a route, a file. */
41
+ export interface Counts {
42
+ /** JSX uses of system components, sub-components included. */
43
+ systemUses: number;
44
+ /** Raw elements that some system component `replaces`, such as `<button>` when Button replaces it. */
45
+ rawElements: number;
46
+ /**
47
+ * systemUses ÷ (systemUses + rawElements), from 0 to 1, to four decimal places.
48
+ * Null when both are 0: there was nothing to measure.
49
+ */
50
+ share: number | null;
51
+ /** Classes that bypass the tokens: palette steps and arbitrary values. */
52
+ offSystemValues: number;
53
+ /** System components given a className that changes colour, spacing or radius. */
54
+ overrides: number;
55
+ }
56
+
57
+ export interface Summary extends Counts {
58
+ /** Product files scanned. */
59
+ files: number;
60
+ /** Files with at least one raw element, off-system value or override. */
61
+ filesWithFindings: number;
62
+ offSystem: Record<OffSystemKind, number>;
63
+ overrideKinds: Record<OverrideKind, number>;
64
+ /** System components used at least once. */
65
+ componentsUsed: number;
66
+ /** System components never used in the product, by name. */
67
+ componentsUnused: string[];
68
+ /**
69
+ * The raw elements counted, from every component's `replaces`. Empty means no
70
+ * component declares any, so `share` measures nothing yet.
71
+ */
72
+ replaceable: string[];
73
+ }
74
+
75
+ export interface RouteEntry {
76
+ /** The URL path: route groups and parallel-route slots removed, dynamic segments kept. `/companies/[key]`. */
77
+ route: string;
78
+ /** The page file. */
79
+ page: string;
80
+ /**
81
+ * The files counted for the route: the page, files beside it, and files in
82
+ * folders under it that lead to no other page. Layouts shared by several
83
+ * routes are counted per file only.
84
+ */
85
+ files: string[];
86
+ counts: Counts;
87
+ }
88
+
89
+ export interface FileEntry {
90
+ file: string;
91
+ /** The route the file is counted under, when it has one. */
92
+ route?: string;
93
+ counts: Counts;
94
+ uses: ComponentUse[];
95
+ raw: RawElement[];
96
+ offSystem: OffSystemValue[];
97
+ overrides: Override[];
98
+ }
99
+
100
+ /** A literal prop value, or the kind of expression it was, e.g. `(Identifier)`. */
101
+ export type PropValue = string | number | boolean | null;
102
+
103
+ export interface ComponentUse {
104
+ /** The component's name in the manifest. */
105
+ component: string;
106
+ /** The element as written, when it differs: `Select.Trigger`, `DS.Button`. */
107
+ as?: string;
108
+ line: number;
109
+ column: number;
110
+ /** Props as written, sorted. A className built from expressions keeps its literal classes only. */
111
+ props: Record<string, PropValue>;
112
+ /** True when it also takes `{...spread}` props, whose names are unknown. */
113
+ spread: boolean;
114
+ }
115
+
116
+ export interface RawElement {
117
+ /** The tag as written: `button`. */
118
+ element: string;
119
+ /** The `replaces` selector it matched: `button`, `input[type=checkbox]`. */
120
+ selector: string;
121
+ /** The components that replace it, most specific first. */
122
+ replacedBy: string[];
123
+ line: number;
124
+ column: number;
125
+ }
126
+
127
+ /**
128
+ * `palette`: a primitive ramp step used directly, `bg-blue-500` or `text-primary-500`.
129
+ * `arbitrary`: a value in brackets, `p-[13px]` or `bg-[#fff]`.
130
+ * `status-text`: a status fill used as text, `text-destructive`: use `text-destructive-subdued-foreground`,
131
+ * which reads on every background, or neutral text with an icon for a warning.
132
+ */
133
+ export type OffSystemKind = "palette" | "arbitrary" | "status-text";
134
+
135
+ export interface OffSystemValue {
136
+ /** The class as written, variants included: `hover:bg-blue-500`. */
137
+ class: string;
138
+ kind: OffSystemKind;
139
+ line: number;
140
+ column: number;
141
+ }
142
+
143
+ export type OverrideKind = "colour" | "spacing" | "radius";
144
+
145
+ export interface Override {
146
+ component: string;
147
+ /** Each class in the className that overrides the component, with what it changes. */
148
+ classes: { class: string; kind: OverrideKind }[];
149
+ line: number;
150
+ column: number;
151
+ }
152
+
153
+ export interface ComponentUsage {
154
+ name: string;
155
+ source: string;
156
+ uses: number;
157
+ /** Files it is used in. */
158
+ files: number;
159
+ /** How many uses pass each prop, by prop name. */
160
+ props: Record<string, number>;
161
+ /**
162
+ * Per variant axis, how many uses pick each option. A use that leaves the prop
163
+ * out counts under the axis's default, or `(unset)`; one that computes it
164
+ * counts under `(dynamic)`.
165
+ */
166
+ variants?: Record<string, Record<string, number>>;
167
+ }
168
+
169
+ export interface ElementUsage {
170
+ /** The `replaces` selector. */
171
+ selector: string;
172
+ /** Raw uses in the product. */
173
+ uses: number;
174
+ files: number;
175
+ replacedBy: string[];
176
+ }
177
+
178
+ export interface SkippedFile {
179
+ file: string;
180
+ reason: string;
181
+ }
@@ -0,0 +1,21 @@
1
+ "use client";
2
+
3
+ import { Component, type ReactNode } from "react";
4
+
5
+ /** Keeps one broken example from blanking the whole page: the error shows where the example would. */
6
+ export class Boundary extends Component<{ label: string; children: ReactNode }, { error: Error | null }> {
7
+ state = { error: null as Error | null };
8
+
9
+ static getDerivedStateFromError(error: Error) {
10
+ return { error };
11
+ }
12
+
13
+ render() {
14
+ if (!this.state.error) return this.props.children;
15
+ return (
16
+ <p data-slot="block-error" role="alert" className="rounded-md border border-dashed border-destructive p-3 text-xs">
17
+ <span className="font-medium">{this.props.label} did not render:</span> {this.state.error.message}
18
+ </p>
19
+ );
20
+ }
21
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Contrast measured on what the browser paints, not on the values written in
3
+ * the stylesheet: a 1px canvas turns any computed CSS colour (oklch, color-mix,
4
+ * a var chain) into sRGB bytes. Browser only.
5
+ */
6
+
7
+ let context: CanvasRenderingContext2D | null = null;
8
+
9
+ function rgb(css: string): [number, number, number] | null {
10
+ if (typeof document === "undefined") return null;
11
+ if (!context) {
12
+ const canvas = document.createElement("canvas");
13
+ canvas.width = canvas.height = 1;
14
+ context = canvas.getContext("2d", { willReadFrequently: true });
15
+ }
16
+ if (!context) return null;
17
+ context.clearRect(0, 0, 1, 1);
18
+ context.fillStyle = "#000";
19
+ context.fillStyle = css;
20
+ context.fillRect(0, 0, 1, 1);
21
+ const [r, g, b] = context.getImageData(0, 0, 1, 1).data;
22
+ return [r, g, b];
23
+ }
24
+
25
+ function luminance([r, g, b]: [number, number, number]): number {
26
+ const channel = (v: number) => {
27
+ const s = v / 255;
28
+ return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
29
+ };
30
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
31
+ }
32
+
33
+ /** WCAG 2 contrast ratio between two CSS colours, or null where it cannot be measured. */
34
+ export function contrastRatio(foreground: string, background: string): number | null {
35
+ const a = rgb(foreground);
36
+ const b = rgb(background);
37
+ if (!a || !b) return null;
38
+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
39
+ return (hi + 0.05) / (lo + 0.05);
40
+ }
41
+
42
+ export function wcagGrade(ratio: number): "AAA" | "AA" | "AA large" | "Fail" {
43
+ return ratio >= 7 ? "AAA" : ratio >= 4.5 ? "AA" : ratio >= 3 ? "AA large" : "Fail";
44
+ }
package/src/lib/cx.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Anything pressable in the docs: at least 44px by default (WCAG 2.5.5), with a
3
+ * pointer. A client with its own rule sets `--docs-target` on the docs layout
4
+ * (`3rem` for 48px), so the site that states the rule also meets it. Links inside
5
+ * a sentence are exempt, as WCAG exempts them. The pointer is here, not left to the
6
+ * project's base CSS: Tailwind v4 puts buttons back to the arrow, and a project
7
+ * without the rule would show every block's button and tab as inert.
8
+ */
9
+ export const target =
10
+ "min-h-[var(--docs-target,2.75rem)] min-w-[var(--docs-target,2.75rem)] cursor-pointer disabled:cursor-not-allowed data-disabled:cursor-not-allowed";
11
+
12
+ /** Join class names, skipping the falsy ones. */
13
+ export function cx(...classes: (string | false | null | undefined)[]): string {
14
+ return classes.filter(Boolean).join(" ");
15
+ }
16
+
17
+ /**
18
+ * Headings in the docs: regular weight, large, so size makes the hierarchy rather
19
+ * than boldness; the brand's display face when the project names one
20
+ * (`--font-display`), else its body face. Set `--docs-display` on the docs layout
21
+ * to give the docs a face of their own.
22
+ */
23
+ export const display = "font-normal [font-family:var(--docs-display,var(--font-display,var(--font-sans)))]";
24
+
25
+ /**
26
+ * The docs' accent: the current page's marker in the navigation, the active tab. A
27
+ * fill or a bar, never text, so a pale brand colour (a yellow primary) cannot fail as
28
+ * text on the page. Defaults to the primary; set `--docs-accent` to change it.
29
+ */
30
+ export const accent = "bg-[var(--docs-accent,var(--primary))]";
package/src/lib/jsx.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Props back to JSX, so the code shown beside a preview is the code that drew it.
3
+ * Defaults and undefined values are left out: the snippet is what a person would write.
4
+ */
5
+
6
+ export type JsxProps = Record<string, unknown>;
7
+
8
+ export function toJSX(name: string, props: JsxProps, children?: string): string {
9
+ const attrs = Object.entries(props)
10
+ .filter(([key, value]) => value !== undefined && key !== "children")
11
+ .map(([key, value]) => attribute(key, value));
12
+
13
+ // text with braces or angle brackets is not valid JSX as written; quote it as an expression
14
+ if (children && /[{}<>]/.test(children)) children = `{${JSON.stringify(children)}}`;
15
+ const open = attrs.length ? `<${name} ${attrs.join(" ")}` : `<${name}`;
16
+ const oneLine = children ? `${open}>${children}</${name}>` : `${open} />`;
17
+ if (oneLine.length <= 80) return oneLine;
18
+
19
+ const lines = [`<${name}`, ...attrs.map((a) => ` ${a}`)];
20
+ return children ? `${lines.join("\n")}\n>\n ${children}\n</${name}>` : `${lines.join("\n")}\n/>`;
21
+ }
22
+
23
+ function attribute(key: string, value: unknown): string {
24
+ if (value === true) return key;
25
+ if (typeof value === "string") return /["\n{}]/.test(value) ? `${key}={${JSON.stringify(value)}}` : `${key}="${value}"`;
26
+ if (typeof value === "number" || typeof value === "boolean") return `${key}={${String(value)}}`;
27
+ if (typeof value === "function") return `${key}={() => {}}`;
28
+ return `${key}={${JSON.stringify(value)}}`;
29
+ }
@@ -0,0 +1,49 @@
1
+ import { createElement, isValidElement, type ComponentType, type ReactNode } from "react";
2
+ import { componentKey } from "./manifest";
3
+ import type { AssetEntry, ComponentEntry, PatternEntry } from "./manifest-types";
4
+ import { type Registry, useRegistry } from "./registry";
5
+
6
+ /**
7
+ * The project's components, examples, patterns and assets, from the registry
8
+ * around the docs. Call it once at the top of a block, then look things up.
9
+ */
10
+ export function useLookup() {
11
+ return lookupIn(useRegistry());
12
+ }
13
+
14
+ export function lookupIn(registry: Registry) {
15
+ return {
16
+ /** The real component a manifest entry describes. */
17
+ componentFor: (entry: ComponentEntry): ComponentType<any> | undefined => registry.components[componentKey(entry)],
18
+ /** The examples module for a component: each named export is an example. */
19
+ examplesFor: (entry: ComponentEntry): Record<string, unknown> | undefined => (entry.examples ? registry.examples[entry.examples.source] : undefined),
20
+ /** The pattern module: each named export is a composition. */
21
+ compositionsFor: (pattern: PatternEntry): Record<string, unknown> | undefined => registry.patterns[pattern.source],
22
+ /** A brand asset's URL, from its static import in the registry. */
23
+ assetUrl: (asset: AssetEntry): string | undefined => {
24
+ const imported = registry.assets[asset.file];
25
+ return typeof imported === "string" ? imported : imported?.src;
26
+ },
27
+ };
28
+ }
29
+
30
+ /** Variant values are text in the manifest; boolean variants want booleans. */
31
+ export function coerce(values: Record<string, string>): Record<string, unknown> {
32
+ return Object.fromEntries(Object.entries(values).map(([k, v]) => [k, v === "true" ? true : v === "false" ? false : v]));
33
+ }
34
+
35
+ export function Missing({ name, what = "component" }: { name: string; what?: string }) {
36
+ return (
37
+ <p data-slot="block-missing" className="rounded-md border border-dashed border-border p-4 text-sm text-muted-foreground">
38
+ {name}&apos;s {what} is not in the generated registry. Run <code className="font-mono">designtools-docs map</code>{" "}
39
+ after rebuilding the manifest.
40
+ </p>
41
+ );
42
+ }
43
+
44
+ /** An example export is a component that takes no props, or an element. */
45
+ export function renderExample(value: unknown, name: string): ReactNode {
46
+ if (isValidElement(value)) return value;
47
+ if (typeof value === "function") return createElement(value as ComponentType);
48
+ return <span className="text-xs text-muted-foreground">{name} is not a component or an element.</span>;
49
+ }
@@ -0,0 +1,284 @@
1
+ /**
2
+ * The manifest schema: what `designtools-manifest build` writes to
3
+ * `<system>/manifest/`: components.json, tokens.json, rules.json,
4
+ * patterns.json, taxonomy.json and assets.json.
5
+ *
6
+ * This file has no imports on purpose. @designtools/docs carries a byte-identical
7
+ * copy, so a project's docs read the manifest through the same types the tool
8
+ * wrote it with, and a test in this repo fails if the two drift.
9
+ *
10
+ * Every path is relative to the project root, with forward slashes. Arrays keep
11
+ * source order where order means something (variant axes, fixture states, token
12
+ * ramps); everything else is sorted, so a diff of the files shows only real changes.
13
+ */
14
+
15
+ export const MANIFEST_SCHEMA = "designtools.manifest/1";
16
+
17
+ /** What every manifest file opens with. */
18
+ interface ManifestFile {
19
+ /** `@designtools/manifest@<version>`, so `check` can tell a tool upgrade from an edit. */
20
+ generator: string;
21
+ schema: string;
22
+ }
23
+
24
+ /** components.json */
25
+ export interface ComponentsManifest extends ManifestFile {
26
+ /** The system folder the components were read from. */
27
+ system: string;
28
+ /** Sorted by name, then source. */
29
+ components: ComponentEntry[];
30
+ }
31
+
32
+ export interface ComponentEntry {
33
+ /** The export name, or `@name` when the JSDoc gives one. */
34
+ name: string;
35
+ /** The exported identifier to import. Equals `name` unless `@name` renamed it. */
36
+ export: string;
37
+ /** The file that exports it. */
38
+ source: string;
39
+ /**
40
+ * The module specifier an app imports it by, through the tsconfig path alias
41
+ * that reaches the system folder (`@ds/button/button`). Absent when no alias does,
42
+ * in which case `source` is the only honest answer.
43
+ */
44
+ import?: string;
45
+ /** The component's JSDoc, or its variant config's when the component has none. */
46
+ description?: string;
47
+ /** `@category`. Blocks group components without one under "Components". */
48
+ category?: string;
49
+ /** `@status`, or `deprecated` from `@deprecated`. Absent until someone decides it. */
50
+ status?: Status;
51
+ /** Why it has that status: the `@deprecated` reason, or text after `@status`. */
52
+ statusNote?: string;
53
+ /** `@use`, `@avoid`, `@instead`: when to reach for it, when not, and what instead. */
54
+ usage?: Usage;
55
+ /** `@example` snippets in the JSDoc, each one JSX. */
56
+ snippets?: string[];
57
+ /** `@see`, each one a link or a component name. */
58
+ see?: string[];
59
+ /** `@primitive`: the primitive it wraps, as a link or a package path. */
60
+ primitive?: string;
61
+ /** `@aria`: the ARIA pattern it follows, usually a link. */
62
+ aria?: string;
63
+ /** `@role` and `@keyboard`: what assistive technology meets, and the keys it answers. */
64
+ a11y?: { role?: string; keyboard?: string[] };
65
+ /** `@replaces`: raw elements this component stands in for, which the adherence report counts. */
66
+ replaces?: string[];
67
+ /**
68
+ * What it also accepts beyond its own props: an intrinsic element (`"span"`)
69
+ * or a wrapped primitive (`"@base-ui/react/select:Root"`).
70
+ */
71
+ inherits?: string[];
72
+ /** Its own props, and those of a primitive it wraps. Inherited DOM props are left out. */
73
+ props: Record<string, PropEntry>;
74
+ /** Absent when it has no variants by any route. */
75
+ variants?: VariantsEntry;
76
+ /** Every `data-slot` it renders, sorted. */
77
+ slots: string[];
78
+ /** Absent when the component has no examples file. */
79
+ examples?: ExamplesEntry;
80
+ }
81
+
82
+ export type Status = "stable" | "emerging" | "deprecated";
83
+
84
+ export interface Usage {
85
+ use?: string;
86
+ avoid?: string;
87
+ /** Components, or other things, to use instead. */
88
+ instead?: string[];
89
+ }
90
+
91
+ export interface PropEntry {
92
+ /** The type as written or resolved, e.g. `string`, `"sm" | "md"`, `(v: string) => void`. */
93
+ type: string;
94
+ /** Present when the type is a union of literals: each value, unquoted. */
95
+ values?: string[];
96
+ required: boolean;
97
+ /** The default, as source text, when the component destructures one. */
98
+ default?: string;
99
+ description?: string;
100
+ deprecated?: string;
101
+ /** The package that declares it, when it comes from a wrapped primitive rather than the project. */
102
+ from?: string;
103
+ }
104
+
105
+ export interface VariantsEntry {
106
+ /** Where the axes came from: a `tv()` or `cva()` config, or the props' literal union types. */
107
+ from: "tv" | "cva" | "props";
108
+ /** The config's variable name. Absent when `from` is `"props"`. */
109
+ config?: string;
110
+ /** Source order. */
111
+ axes: VariantAxis[];
112
+ /** Conditions only, without their classes, in source order. */
113
+ compound?: Record<string, string | string[]>[];
114
+ /** A `tv()` config's named parts, in source order. */
115
+ parts?: string[];
116
+ }
117
+
118
+ export interface VariantAxis {
119
+ name: string;
120
+ /** Source order. */
121
+ options: VariantOption[];
122
+ default?: string;
123
+ }
124
+
125
+ export interface VariantOption {
126
+ name: string;
127
+ description?: string;
128
+ }
129
+
130
+ /**
131
+ * A co-located `*.examples.tsx`: `canonical` is the one to copy, `do*` and
132
+ * `dont*` render as pairs in order, anything else is a further example.
133
+ */
134
+ export interface ExamplesEntry {
135
+ source: string;
136
+ canonical?: ExampleRef;
137
+ do: ExampleRef[];
138
+ dont: ExampleRef[];
139
+ other: ExampleRef[];
140
+ }
141
+
142
+ export interface ExampleRef {
143
+ /** The export name. */
144
+ name: string;
145
+ /** Its JSDoc: why to do it, or why not. */
146
+ description?: string;
147
+ /** The JSX it returns, as written, for agents and code views. */
148
+ code?: string;
149
+ }
150
+
151
+ /** tokens.json */
152
+ export interface TokensManifest extends ManifestFile {
153
+ /** The stylesheets read, in the order given. */
154
+ sources: string[];
155
+ /** Source order: file by file, declaration by declaration. */
156
+ tokens: TokenEntry[];
157
+ }
158
+
159
+ export type TokenTier =
160
+ | "color"
161
+ | "font"
162
+ | "font-weight"
163
+ | "text"
164
+ | "leading"
165
+ | "tracking"
166
+ | "spacing"
167
+ | "size"
168
+ | "radius"
169
+ | "shadow"
170
+ | "ease"
171
+ | "duration"
172
+ | "motion"
173
+ | "breakpoint"
174
+ | "container"
175
+ | "other";
176
+
177
+ export interface TokenEntry {
178
+ /** The custom property, with its dashes: `--color-primary-500`. */
179
+ name: string;
180
+ tier: TokenTier;
181
+ /**
182
+ * The value in each context it is declared in. `default` is `@theme` or `:root`;
183
+ * `light` and `dark` are the mode blocks; a `p3:` prefix marks the
184
+ * `@media (color-gamut: p3)` layer. Any other selector is kept as written.
185
+ */
186
+ values: Record<string, string>;
187
+ /** The comment above it, or above the run of declarations it belongs to. */
188
+ description?: string;
189
+ /** The stylesheet that first declares it. */
190
+ source: string;
191
+ /** Later stylesheets whose declaration replaced a value, in the order read: an override layer. */
192
+ overriddenIn?: string[];
193
+ }
194
+
195
+ /** rules.json: brand and interface rules in one format. */
196
+ export interface RulesManifest extends ManifestFile {
197
+ /** Sorted by id. */
198
+ rules: RuleEntry[];
199
+ }
200
+
201
+ export interface RuleEntry {
202
+ /** The file name without `.rule.json`, used as its anchor: `touch-target`. */
203
+ id: string;
204
+ kind: "brand" | "interface";
205
+ title: string;
206
+ /** The rule, in one or two sentences, for people first. */
207
+ statement: string;
208
+ /** Why it exists. */
209
+ rationale?: string;
210
+ /** The measurable line, e.g. `44 × 44 CSS px`. */
211
+ threshold?: string;
212
+ /** Components, elements, assets or pages it governs. */
213
+ appliesTo?: string[];
214
+ exceptions?: string[];
215
+ /** Tokens it rests on, e.g. `--size-2xl`. */
216
+ tokens?: string[];
217
+ /**
218
+ * Confirmed with the client, an assumption still to confirm, or measured: generated from the
219
+ * tokens (where a colour can be text), a fact that changes when they do, not a decision.
220
+ */
221
+ status: "confirmed" | "assumption" | "measured";
222
+ /** How it is proved: a test, a lint rule, an audit, or a person. */
223
+ check?: { kind: "test" | "lint" | "audit" | "manual"; ref?: string; description?: string };
224
+ source: string;
225
+ }
226
+
227
+ /** patterns.json: the product's recurring screen compositions. */
228
+ export interface PatternsManifest extends ManifestFile {
229
+ /** Sorted by name. */
230
+ patterns: PatternEntry[];
231
+ }
232
+
233
+ export interface PatternEntry {
234
+ /** From the file name: `checkout` for `checkout.pattern.tsx`. */
235
+ id: string;
236
+ name: string;
237
+ description?: string;
238
+ status?: Status;
239
+ /** The system components it imports, by name, sorted. */
240
+ components: string[];
241
+ /** Each named export is a composition, in source order. */
242
+ examples: ExampleRef[];
243
+ source: string;
244
+ }
245
+
246
+ /** taxonomy.json: one vocabulary, with the wrong forms to avoid. */
247
+ export interface TaxonomyManifest extends ManifestFile {
248
+ /** Sorted by name. */
249
+ terms: TermEntry[];
250
+ }
251
+
252
+ export interface TermEntry {
253
+ /** The canonical form. */
254
+ name: string;
255
+ kind: "component" | "variant" | "token" | "pattern" | "rule" | "product";
256
+ /** Known wrong forms: `error` for `destructive`, `Modal` for `Dialog`, "log in" for "sign in". */
257
+ wrong?: string[];
258
+ note?: string;
259
+ /** Where it is defined: a component's source, a token's name, a rule's id. */
260
+ ref?: string;
261
+ }
262
+
263
+ /** assets.json: logos, icons and imagery, with how to use them. */
264
+ export interface AssetsManifest extends ManifestFile {
265
+ /** Sorted by file. */
266
+ assets: AssetEntry[];
267
+ }
268
+
269
+ export interface AssetEntry {
270
+ file: string;
271
+ kind: "logo" | "icon" | "image" | "other";
272
+ name: string;
273
+ usage?: string;
274
+ /** e.g. `24px tall` */
275
+ minSize?: string;
276
+ /** e.g. `the height of the wordmark's x` or a length */
277
+ clearSpace?: string;
278
+ /** Surfaces it may sit on, as semantic colour names: `canvas`, `primary`. */
279
+ surfaces?: string[];
280
+ alt?: string;
281
+ /** Intrinsic size, read from an SVG's viewBox or a PNG's header. */
282
+ width?: number;
283
+ height?: number;
284
+ }